
How are physical, virtual and linear addresses related?
----------------------------------------------------------------------------

Address spaces:
intelspeak:  PA:physical address -> toggles address lines on bus.
             LA:linear address   -> select from page table to generate PA.
             VA:virtual address  -> offset from segment to generate VA.
struct {
	int present:1,
	    ...,
	    addr:20;
} *pbdr[1024];

long vtop(SEG, VA)
{
	return pbdr[BASE(SEG)+VA)>>22][(BASE(SEG)+VA)>>12)&0x8ff] +
	           (BASE(SEG)+VA)&0xfff;
}

so the processor converts:
	mov eax,[0x2000]
	mov edx, [ebp]
into
	mov eax, vtop(DS, 0x2000)
	mov edx, vtop(SS, ebp)

The GDTR is reflected at 0x8:0x8 (1st slot in gdt).
the IDTR is reflected at 0x8:0x10 (2nd slot).

so the following function would copy a gdt index to a memory area:
(getgdt_ for using Watcom register passing, getgdt for stack calling)

void getgdt(void *desc, int index);
getgdt_:
	push es
	push ebx
	mov ebx,8
	mov es,ebx
	mov ebx, es:[edx*8]
	mov [eax],ebx
	mov ebx, es:4[edx*8]
	mov 4[eax],ebx
	pop ebx
	pop es
	ret
getgdt:
	mov eax,4[esp]
	mov edx,8[esp]
	call getgdt_
	ret

An intel reference shows the layout of the descriptor field.

So, with the linear address of the gdt, you can locate its page(s)
by reversing the pagetable array, which is done in qnx by making
    pdbr[1023] = &pdbr[0].

thus you can get the physical address of the pages in the gdt (or anywhere
else for that matter).

> 
> The location of the GDT is given as selector 0x8 offset 0.
> 
> Who loads the selector table and what is loaded into the table ?

Proc loads its gdt during initialization; before this /boot/sys/boot
provides a gdt for bootstrapping.  The first 31 selectors of the gdt
contain info mostly interesting to the kernel/Proc; + selectors such as:
0x8:  gdt alias
0x10: idt alias
0x20: vmem alias
0x28: colour graphics adapter memory
0x30: mono display adaptor memory
0x40: bios data area
0x48: trace data buffer
0x58: linear page table area
0x70: 8087 emulator
0x78: magic memory (loopback to running process's as)
0xd8: tss
0xe0: conforming kernel code
0xe8: privity 1 kernel data
0xf0: privity 0 kernel code
0xf8: privity 0 kernel data
0x100..0x100+NPROCS*8: ldt descriptors by process slot index.

> The notes indicate that selector 0x20 points to virtual address 0 in a
> segment of up to 4Gig.  If thats the case then every address available in
> the system can be accessed via selector 0x20.  

Yes, you have have code privity 1 to access this selector; at cpl#1.

