changing GDT Segmant

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
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

changing GDT Segmant

Post 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
.................................. um what should i put here .............................?..........................................
..... :D................
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

Post 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?
.................................. um what should i put here .............................?..........................................
..... :D................
vhg119
Member
Member
Posts: 71
Joined: Fri Aug 24, 2007 5:56 pm
Location: CA, USA

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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>
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

[solved]gdt segment switching?

Post by HJED »

thanks 4 the help
.................................. um what should i put here .............................?..........................................
..... :D................
Post Reply