Confused about selectors

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

Confused about selectors

Post 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.
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: Confused about selectors

Post 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.
Post Reply