question about ia-32e compatibility mode

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
noodlezh
Posts: 7
Joined: Mon Nov 21, 2011 10:54 pm

question about ia-32e compatibility mode

Post by noodlezh »

In x86-64, there are 2 sub-modes for ia-32e mode:
1> the compatibility mode
2> the 64-bit mode
My questions are:
1> why should we use a compatibility mode? Can't we just use ia32 protected mode if we wanna run 32-bit apps?
2> when transferring from 64-bit mode back to real mode, we must first enter the compatibility mode, why?
3> the intel manual says that in 64-bit mode, segmentation is generally disabled(for cs, ds, ss, gs), but in the structure of segment descriptor, there's a bit - bit21, and in 3.4.5 of Software Developer’s Manual 3A, description of this bit is: "In IA-32e mode, bit 21 of the second doubleword of the segment descriptor indicates whether a code segment contains native 64-bit code. A value of 1 indicates instructions in this code segment are executed in 64-bit mode. A value of 0 indicates the instructions in this code segment are executed in compatibility mode." So, if we do not use segment in 64-bit mode, why we need a segment descriptor like this?
Well, I'm muddled, and hope someone may help.
Thanks a lot!
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: question about ia-32e compatibility mode

Post by AJ »

Hi,

1) You use compatibility mode so that you can have 32 bit and 64 bit tasks running alongside one another.
2) Because that's how the manuals say you should do the mode swich ;) On the wiki, you will see a method of switching directly from real to long mode, though. Once in long mode, why would you want to switch back anyway?


Cheers,
Adam
noodlezh
Posts: 7
Joined: Mon Nov 21, 2011 10:54 pm

Re: question about ia-32e compatibility mode

Post by noodlezh »

Thanks AJ,
1> Here's my interpretation about your "32 bit and 64 bit tasks running alongside one another":
Once we turned on the LME bit of IA32_EFER MSR, the ia32-e mode is entered. But whether we are running in 64-bit sub-mode or in compatibility mode is decided by the L-bit of the code segment descriptor (which is indexed by %cs). So, we can run a task(e.g. a 32-bit app) in compatibility sub-mode, and another(e.g. a 64-bit kernel thread) in 64-bit sub-mode, as long as we use different %cs values when task switch.
Am I right?
If so, here's another question: since 64-bit uses flat memory model, what kind of segment descriptor is appropriate for the 64-bit mode?

2> Do you know any particular reason for the manual to say so? Besides, we wanna transfer from the long mode back to real mode to invoke some bios routines. :-(
User avatar
Combuster
Member
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: question about ia-32e compatibility mode

Post by Combuster »

noodlezh wrote:we wanna transfer from the long mode back to real mode to invoke some bios routines
Which is the best way to break your OS in the long run.
"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 ]
noodlezh
Posts: 7
Joined: Mon Nov 21, 2011 10:54 pm

Re: question about ia-32e compatibility mode

Post by noodlezh »

Well, this is invoked once at the intitial process.
But, I wonder why you said so. :)
Also, could you please help me with my questions about the ia32-e mode?
Thanks!:)
User avatar
Combuster
Member
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: question about ia-32e compatibility mode

Post by Combuster »

You could also have read the manuals and the wiki...
"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 ]
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: question about ia-32e compatibility mode

Post by bluemoon »

It's better to do all required BIOS call at early boot stage, since returning from long mode to real mode has not been extensively tested by the world.
noodlezh
Posts: 7
Joined: Mon Nov 21, 2011 10:54 pm

Re: question about ia-32e compatibility mode

Post by noodlezh »

Ok, thanks :oops:
Post Reply