Page 1 of 1

Relocation Question

Posted: Tue Sep 16, 2003 11:25 am
by one
I've written the code describing the different descriptors for the GDT and IDT, the individual selectors are identified using the EQU directive as shown below
VIDEOSEL   EQU   $ - gdt_start

before loading the GDT however I relocate this table to some other address say 0x0:0x700
Now look at this code fragment

MOV   eax,VIDEOSEL
MOV   gs,eax
MOV   [gs:0x0],'P'

This works fine but i wanted to know if the VIDEOSEL will be pointing to the address before it was relocated or the one after(i.e with the 0x0:0x700 address).
Please let me know and thanx for your time.

Re:Relocation Question

Posted: Tue Sep 16, 2003 5:14 pm
by Curufir
It's not an address, it's a simple numeric constant.
GDT/IDT selectors are loaded using their offset from the start of the GDT.

So for example if the VIDEOSEL selector was the 4th selector in the GDT the actual value of VIDEOSEL would be 32 (4*0x8) which, when loaded into a selector register, causes the CPU to load the descriptor starting at 32 bits offset into the GDT table.

This is why when setting up those labels you define them as offsets to the start of the GDT (VIDEOSEL EQU $ - gdt_start).

Moving the GDT/IDT makes no difference. So long as the GDT/IDT itself hasn't altered the offsets into it will be the same. Only thing is making sure the GDTR/IDTR is loaded with the correct base address.

Re:Relocation Question

Posted: Wed Sep 17, 2003 11:10 am
by one
thanks pal for the info it was just bugging me :)