null selector
Posted: Fri Aug 09, 2002 10:05 am
I have read in this forum that the null selector must be all zeroes, and i wants to say that "it is not true". You can use the null selector to other things, the most common is to point the GDT, here one example(the numbers in gdt1 and gdt2 (0xabcd and oxab) are there only to put something instead of 0):
gdt:
dw 24 ;size of gdt
dd gdt ; linear pointer to gdt
dw 0; nothing here
gdt1:
dw 0xabcd ; some data of selector
dw 0xabcd ; some data of selector
db 0xab
db 0xab
db 0xab
db 0xab
gdt2:
dw 0xabcd ; some data of selector
dw 0xabcd ; some data of selector
db 0xab
db 0xab
db 0xab
db 0xab
The "dd gdt" needs to be a linear pointer and like in the example may not be linear(because ds points to a segment diferent than 0, or because the compiler doesnt start to count at 0) and it may need that you change it by hand, if you know that it will be correct just dont chage it.
load it with
lgdt [gdt]
and you are done, and doesnt waste some bytes.
gdt:
dw 24 ;size of gdt
dd gdt ; linear pointer to gdt
dw 0; nothing here
gdt1:
dw 0xabcd ; some data of selector
dw 0xabcd ; some data of selector
db 0xab
db 0xab
db 0xab
db 0xab
gdt2:
dw 0xabcd ; some data of selector
dw 0xabcd ; some data of selector
db 0xab
db 0xab
db 0xab
db 0xab
The "dd gdt" needs to be a linear pointer and like in the example may not be linear(because ds points to a segment diferent than 0, or because the compiler doesnt start to count at 0) and it may need that you change it by hand, if you know that it will be correct just dont chage it.
load it with
lgdt [gdt]
and you are done, and doesnt waste some bytes.