OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Oct 22, 2019 8:18 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Setting up the stack after the switch to long mode
PostPosted: Mon Mar 29, 2010 1:26 pm 
Offline
Member
Member

Joined: Mon Sep 07, 2009 12:01 pm
Posts: 149
I've been playing about with switching to long mode (which now works :D), using mainly the AMD manuals and http://wiki.osdev.org/User:Stephanvansc ... _Long_Mode for reference. But at the end of the wiki page, it says "It is very important that you don't set the stack segment and that you don't enable the interrupts (unless you have set up a 64-bit IDT of course)." with no reason given - why shouldn't you set the stack segment without a 64-bit IDT?


Top
 Profile  
 
 Post subject: Re: Setting up the stack after the switch to long mode
PostPosted: Mon Mar 29, 2010 2:21 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9285
Location: On the balcony, watching the Swedish Chef
You're reading an userspace page, which usually is an indication that it's not ready for everybody to read (and I think you just found out why).

Truth is, you'll need an GDT before reloading segment registers, and you need an IDT (and GDT) before enabling interrupts. A write to a segment register causes the CPU to look it up in the current GDT. If that doesn't exist, or is broken, then the CPU tries to fix that problem by invoking an exception and ends up causing another segment load, which ends up in a reboot because it'd otherwise go around in circles.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Setting up the stack after the switch to long mode
PostPosted: Mon Mar 29, 2010 2:46 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 13, 2008 3:21 pm
Posts: 1700
Location: Cambridge, United Kingdom
Combuster wrote:
You're reading an userspace page, which usually is an indication that it's not ready for everybody to read (and I think you just found out why).

Truth is, you'll need an GDT before reloading segment registers, and you need an IDT (and GDT) before enabling interrupts. A write to a segment register causes the CPU to look it up in the current GDT. If that doesn't exist, or is broken, then the CPU tries to fix that problem by invoking an exception and ends up causing another segment load, which ends up in a reboot because it'd otherwise go around in circles.


Actually, Long Mode doesn't care about your SS selector; on an interrupt, it loads a zero into it (!). In fact, it's generally best to load a zero SS for consistency with the rest of the system


Top
 Profile  
 
 Post subject: Re: Setting up the stack after the switch to long mode
PostPosted: Tue Mar 30, 2010 8:16 am 
Offline
Member
Member

Joined: Sat Sep 29, 2007 5:43 pm
Posts: 127
Location: Amsterdam, The Netherlands
madanra wrote:
I've been playing about with switching to long mode (which now works :D), using mainly the AMD manuals and http://wiki.osdev.org/User:Stephanvansc ... _Long_Mode for reference. But at the end of the wiki page, it says "It is very important that you don't set the stack segment and that you don't enable the interrupts (unless you have set up a 64-bit IDT of course)." with no reason given - why shouldn't you set the stack segment without a 64-bit IDT?

The 64-bit IDT was about the interrupts, not the stack segment. As for setting the stack segment, I'm not entirely sure why I actually wrote that note. Probably because "mov ss, ax" caused a triple fault here, but if what Owen said is true, then I probably know why it did.


Regards,
Stephan J.R. van Schaik.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: MSN [Bot] and 13 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