Page 2 of 2

Re: Protected Mode Hello world.

Posted: Mon Jul 27, 2009 11:04 am
by Troy Martin
raghuk wrote:
Troy Martin wrote:Okay, but here's the odd thing: 0x16!? Well thar's a problem, it should be 0x18. Selectors are usually multiples of 8, as that's the size of a selector...
Small correction there. Size of a selector is 16 bits. Selector needs not be multiples of 8. Usually they are multiples of 8 because bits 0-1 represent requested privilege level and bit 2 represents table indicator (GDT = 0, LDT = 1). For kernel code/data segments we have RPL = 0 and TI = 0. Hence they are multiples of 8.
I mean the selector entries in the GDT. They're 8 bytes long, which makes 0x16 incorrect. (0x16 == 22)

Re: Protected Mode Hello world.

Posted: Mon Jul 27, 2009 11:31 am
by raghuk
Troy Martin wrote:I mean the selector entries in the GDT. They're 8 bytes long, which makes 0x16 incorrect. (0x16 == 22)
You mean "descriptor" entries. 0x16 is incorrect because 0x16 = 00010110 and bit 2 is set. That means the selector is pointing to LDT and not GDT. It has nothing to with the fact that a descriptor is 8 bytes. For e.g. selector 0x13 is not divisible by 8 but still points at GDT.

This is how a selector is structured:

Index to GDT/LDT (Bits 3-15)
TI (Bit 2)
RPL (Bits 0-1)