It's actually an 8-byte entry in the global descriptor table. It creates a descriptor addressing the entire 4G address space as a selector.
The equ $-gdt
sets up a value in the assembler equal to the difference between this location ($
) and the gdt
label. In other words, it's the offset of this entry within the GDT itself.
The structure of a GDT entry is as follows:
where the individual parts are explained below.
For your specific values:
(a) dw FFFFh
(b) dw 0
(c) db 0
(d) db 92h ; present, ring 0, data, expand-up, writable
(e) db CFh ; page-granular (4 gig limit), 32-bit
(f) db 0
The base address is calculated from the f
, c
and b
fields, from most significant to least - because these are all zero, the base is at zero.
The selector limit is calculated from the rightmost 4 bits of e
and all of a
, to give 0xfffff
in this case. This has 1 added to it to give 0x100000
. See point 3 below for what this means.
The top 4 bits of e
(the flags) set the granularity (4K rather than 1 byte) and the operand size (32-bit). With a granularity of 4K (12 bits) and page count of 0x100000
(20 bits), that gives you your full 32-bit (4G) address space.
The d
field is the access byte and sets the following properties based on 0x92
:
Pr
present (in-memory) bit to true.
Privl
privelege level to 0 (need to be ring 0 to get access).
Ex
executable bit 0 (data selector).
DC
, direction bit is 0, segment grows up.
RW
of 1, memory is writable.
Ac
accessed bit set to 0.