Setting up the stack after the switch to long mode
Setting up the stack after the switch to long mode
I've been playing about with switching to long mode (which now works ), 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?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Setting up the stack after the switch to long mode
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.
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.
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: Setting up the stack after the switch to long mode
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 systemCombuster 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.
-
- Member
- Posts: 127
- Joined: Sat Sep 29, 2007 5:43 pm
- Location: Amsterdam, The Netherlands
Re: Setting up the stack after the switch to long mode
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.madanra wrote:I've been playing about with switching to long mode (which now works ), 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?
Regards,
Stephan J.R. van Schaik.