OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 4:56 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: GDT in Long Mode
PostPosted: Wed Feb 20, 2008 4:38 pm 
Offline
Member
Member
User avatar

Joined: Mon Feb 11, 2008 4:43 pm
Posts: 149
Location: Limbo City,Afterlife
I realize that there are changes in long mode when it comes to the GDT. I just want to make sure that all the descriptors are 4 bytes and there is a 4 byte null descriptor at the beginning of the GDT:

Code:
GDTR64:;what is loaded into the GDTR when entering long mode
limit dw gdtend64-gdtbeg64;size of the GDT
offset dq gdtbeg64;start address of the 64 bit gdt


gdtbeg64:;beginning of 64 bit gdt
dd 0
;etc...


gdtend64:;end of 64 bit gdt


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 5:06 pm 
Offline
Member
Member

Joined: Wed May 23, 2007 9:38 pm
Posts: 111
it has always been 8 bytes, same as protected, but tss for instance is 16bytes
Nice pictures in Intel manual Vol 3a (May 2007), sections 3.4.5, 6.2.3


Last edited by exkor on Wed Feb 20, 2008 5:09 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 5:08 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 22, 2007 12:47 pm
Posts: 1598
Location: New Hampshire, USA
you need to have your 32-bit GDT descriptors, and then your 64-bit one as well. The descriptor for the 64-bit cs is almost identical to the 32-bit one except that it has the L flag set.

Code:
GDTR:               ; Global Descriptors Table Register
    dw 4*8-1            ; limit of GDT (size minus one)
    dq GDT            ; linear address of GDT

GDT:
    dw 0,0,0,0           ; null desciptor
    dw 0FFFFh,0,9200h,08Fh      ; flat data desciptor
    dw 0FFFFh,0,9A00h,0CFh      ; 32-bit code desciptor
    dw 0FFFFh,0,9A00h,0AFh      ; 64-bit code desciptor


then the GDT table gets loaded with the lgdt command before entering PMode, and then can be re-used when enterring 64-bit mode because the 64-bit descriptor is already there.

Code:
lgdt [cs:GDTR]


when you jump into 64-bit mode, just make sure you use the correct descriptor (0x18) for the far jump.

_________________
Website: https://Joscor.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 98 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group