Page 1 of 1

GDT problem: brans kernel

Posted: Sun Oct 23, 2005 3:06 pm
by vibhory2j
i have a problem in bran's kernel tutorial on osdever.net. i am sorry if it has been posted earlier but i was unable search the desired links despite several tries.

my problem is in the GDT code :-
global _gdt_flush
extern _gp
_gdt_flush:
lgdt [_gp]
mov ax, 0x10 ; here is my problem
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
jmp 0x08:flush2
flush2:
ret


the tutorial says that 0x10 is the offset of the data segment in the GDT. i just want to know how this offset is calculated.
the question may sound stupid but please help me as i am new to kernel development.
thanks in advance for all help.

Re:GDT problem: brans kernel

Posted: Sun Oct 23, 2005 3:30 pm
by Cjmovie
It's actually rather simple. The offset is actually, if you look at it in binary, like this:

0x10 == 0001 0000 (binary) == 16

As you can see, the lower 4 bits are 0. This contains some stuff (flags) which define the code privelage level, etc.

So the upper nibble is the actual segment. Remember the NULL segment? That's 0. And the data would be 8, becuase it's the second one. And the code is 16. Simply add 8 each time.

Then, when/if you want to, you can binary OR it with flags to get other affects.

Hope I was of some help