Page 1 of 1
changing GDT Segmant
Posted: Thu Sep 06, 2007 5:45 am
by HJED
hi
could anyone tell me how to jump GDT segments and how?
because i would like to jump to a different GDT segment when i switch to long mode. my GDT is the one from
this tutorial whith an extra GDT segment for long mode
Code: Select all
gdt_set_gate(3, 0x04000000, 0xFFFFFFFF, 0x9A, 0xAF);
if any1 could help i would be relay great fulll
Posted: Thu Sep 06, 2007 6:20 am
by JamesM
What do you mean? A code segment or data segment?
Code segment:
Code: Select all
jmp <segment selector>:.hello
.hello:
<rest of code>
data segment:
Code: Select all
mov ax, <segment selector>
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
JamesM
Posted: Thu Sep 06, 2007 4:47 pm
by HJED
i mean a code segment and the bellow code dose not work assemble
also i din`t know u could give segments names the compiler regonized
prehaps i have misuderstood GDT?
i thought that when you change segmants it protects it from other segments?
Posted: Thu Sep 06, 2007 5:30 pm
by vhg119
HJED wrote:i mean a code segment and the bellow code dose not work assemble
also i din`t know u could give segments names the compiler regonized
prehaps i have misuderstood GDT?
i thought that when you change segmants it protects it from other segments?
You specify the segment descriptor index.
For instance, if you wanted to jump to the segment specified by descriptor 3: jmp 0x18:<offset>
This is because a descriptor is 8 bytes long so 3*8 = 24 == 0x18 in hex.
you may need to use the far version of jmp.
Posted: Fri Sep 07, 2007 1:36 am
by JamesM
And remember to use the correct RPL (requested privilege level) when using segment selectors. That's the last 2 bits of the number. Check the intel manuals.
If you're using AT&T syntax btw, the code looks a little more something like this (Although im pretty sure the syntax is wrong somewhere, I don't use it!)
Code: Select all
jmpl .here, <segment selector>
.here: <code>
[solved]gdt segment switching?
Posted: Fri Sep 07, 2007 2:53 am
by HJED
thanks 4 the help