Page 1 of 1

Confused about selectors

Posted: Sat Mar 28, 2009 5:15 pm
by instance
Hey,
I've entered into protected mode, and was just setting the selectors. On osdev wiki, I saw:

Code: Select all

   ; Reload data segment registers:
   MOV   AX, 0x10 ; 0x10 points at the new data selector
   MOV   DS, AX
   MOV   ES, AX
   MOV   FS, AX
   MOV   GS, AX
   MOV   SS, AX
   RET
But according to a few other websites, such as http://www.internals.com/articles/protmode/protmode.htm and http://members.tripod.com/protected_mod ... tmode.html , the selectors jsut have their higher 13 bits to the offset. The lower 3 bits are for other tasks... So why shouldn't the above code be-

Code: Select all

mov ax,0x10
mov cl,3
shl ax,cl    ; Should zero out the lower bits
mov ds,ax
.....

um... don't get me wrong, the wiki is right, but I'd just like to know why.

Re: Confused about selectors

Posted: Sat Mar 28, 2009 6:36 pm
by ru2aqare

Code: Select all

   ; Reload data segment registers:
   MOV   AX, 0x10 ; 0x10 points at the new data selector
   MOV   DS, AX
Here, the selector value is 2. It selects the third entry in the GDT (or the LDT). Shift left this by three bits (which are the RPL - requestors privilege level - and the TI - table index - bits), and you get 10h, which is the correct value to load into the segment registers.