OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:04 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: switching from long mode to compatibility mode
PostPosted: Mon Jun 09, 2008 3:04 pm 
Offline

Joined: Mon Jun 09, 2008 2:55 pm
Posts: 3
Location: Bay Area
Hello,

I am writing small code that boots, jumps to 32bit protected mode (no-paging enabled) --> 64bit mode (pml4 paging) --> perform some 64bit test --> jump back to 32bit protected mode (no-paging enabled).

I got successful getting into 64bit mode and I'm trying to switch out of it to 32bit protected mode.

According to Intel document the first step is to "Switch to compatibility mode" which after several efforts, I'm not able to do successfully. (Although I was successful in jumping in and out of compatibility mode (without ever jumping into 64bit mode) from 32bit protected mode (no-paging enabled).)

Only diff. betwn 64bit paged-protected mode and compatibility mode is L and D bit in code segment. In other words, (according to my understanding) if I'm in 64bit mode and if I want to jump to compatibility mode, all I'm suppose to do is to make far jump to compatibility mode Code-Segment (please correct me if I'm wrong). The CPU freezes when I make the jump.

While making jump,
1) PML4 paging is still in place (hence, IA32_EFER.LMA = 1)
2) PAE and PE is still enabled
3) IA32_EFER.LME = 1

I'm not sure if I can make a far jump/call while I'm in 64bit mode to switch to compatibility mode. And I can't think of any other way to switch CS. Can somebody please help me with this? Am I suppose to re-arrange paging or do something about gdt?

Thanks,
/tejas

NOTE: When I jump back to 32bit protected mode, I want to keep paging disabled.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 3:59 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Have you tried running your code in bochs (preferrably with debugger) to see what it complains about?

_________________
"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:
PostPosted: Mon Jun 09, 2008 4:24 pm 
Offline

Joined: Mon Jun 09, 2008 2:55 pm
Posts: 3
Location: Bay Area
Combuster wrote:
Have you tried running your code in bochs (preferrably with debugger) to see what it complains about?


This code is part of BIOS development. So I can get state of registers at a time when freeze (most likely a GP fault) happens at next reboot. But I know exactly when it freezes:

After jumping into 64bit mode from 32bit mode, I push CS for compat mode and push address of 64bit code and make far return. At this point it (suppose to) switch to compatibility mode, instead it freezes.

/tejas


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 6:33 pm 
Offline
Member
Member

Joined: Tue Apr 15, 2008 6:37 pm
Posts: 191
Location: Gotham, Batmanistan
You aren't trying to switch segment privelege levels while jumping to compatability mode perchance are you?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 10, 2008 2:32 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
tejuwala wrote:
Combuster wrote:
Have you tried running your code in bochs (preferrably with debugger) to see what it complains about?


This code is part of BIOS development. So I can get state of registers at a time when freeze (most likely a GP fault) happens at next reboot. But I know exactly when it freezes:


Which is exactly why you should use bochs - first of all it prints error messages when something unusual happens, which usually tells you your exact problem in case of a reboot. And second you can use the debugger to break before faulting instruction and analyse all the CPU's registers without having them clobbered by a reset.

_________________
"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:
PostPosted: Tue Jun 10, 2008 1:29 pm 
Offline

Joined: Mon Jun 09, 2008 2:55 pm
Posts: 3
Location: Bay Area
I got it fixed. As I said earlier, the difference between compatibility and 64bit mode is L/D bits in CS descriptor. However, while making far jump in 64bit mode, the operand size _must_ be set to 64bit (which is, by default, 32bit unless explicitly specified). So I had to put a "operand size prefix" in front of "retf" ("o64 retf" in NASM) and it worked fine.

Thanks guys,
/tejas


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Amazonbot [bot], Google [Bot] and 58 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