* [ToDo] Real Mode Support
@ 2008-02-06 7:33 Guillaume Thouvenin
2008-02-06 8:52 ` Izik Eidus
2008-02-06 17:32 ` Anthony Liguori
0 siblings, 2 replies; 11+ messages in thread
From: Guillaume Thouvenin @ 2008-02-06 7:33 UTC (permalink / raw)
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Hello,
I read on the kvmwiki/TODO that there is a work in progress for
extending x86 emulator to support more instructions in real mode and for
changing the execution loop to call the emulator for real mode.
As I'm interested to work on this part I'd like to know what was
already done.
I'd like to have more information about how the execution loop need to
be changed. Currently we enter/leave real mode through a call to
enter_rmode()/enter_pmode(). The function sets a variable
"arch.rmode.active" and also sets the bit X86_EFLAGS_VM of
GUEST_RFLAGS. That means that we are using the VM mode to virtualize
the real mode. I know that in virtual mode some instructions can not be
used as they are in full real mode (that would have been too easy). So
these instructions generate a protection fault and need to be emulated.
So we handle this kind of exception in handle_exception() and we call
the x86 emulator. From the emulator we read the eflags
(kvm_x86_ops->get_rflags(vcpu)) and we can know if we are in real mode
or not. It's the current scheme, right?
My question is why the execution loop needs to be changed here. I mean
isn't it possible to just extend x86 emulator to support more
instructions in real mode? I think that I'm missing something here so
any help, hint, advice, link are welcome.
Best Regards,
--
Guillaume Thouvenin
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [ToDo] Real Mode Support
2008-02-06 7:33 [ToDo] Real Mode Support Guillaume Thouvenin
@ 2008-02-06 8:52 ` Izik Eidus
[not found] ` <1202287974.23342.8.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-02-06 17:32 ` Anthony Liguori
1 sibling, 1 reply; 11+ messages in thread
From: Izik Eidus @ 2008-02-06 8:52 UTC (permalink / raw)
To: Guillaume Thouvenin; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
On Wed, 2008-02-06 at 08:33 +0100, Guillaume Thouvenin wrote:
> Hello,
>
> I read on the kvmwiki/TODO that there is a work in progress for
> extending x86 emulator to support more instructions in real mode and for
> changing the execution loop to call the emulator for real mode.
>
> As I'm interested to work on this part I'd like to know what was
> already done.
cool!
>
> I'd like to have more information about how the execution loop need to
> be changed. Currently we enter/leave real mode through a call to
> enter_rmode()/enter_pmode(). The function sets a variable
> "arch.rmode.active" and also sets the bit X86_EFLAGS_VM of
> GUEST_RFLAGS. That means that we are using the VM mode to virtualize
> the real mode. I know that in virtual mode some instructions can not be
> used as they are in full real mode (that would have been too easy). So
> these instructions generate a protection fault and need to be emulated.
> So we handle this kind of exception in handle_exception() and we call
> the x86 emulator. From the emulator we read the eflags
> (kvm_x86_ops->get_rflags(vcpu)) and we can know if we are in real mode
> or not. It's the current scheme, right?
>
> My question is why the execution loop needs to be changed here. I mean
> isn't it possible to just extend x86 emulator to support more
> instructions in real mode? I think that I'm missing something here so
> any help, hint, advice, link are welcome.
>
> Best Regards,
>
i am not expert for the emulator area, but as far as i remember:
virtual 8086 have some checks related to segments (the big mode
problem), it mean that for some addresses it wont be able to execute
anything, you will just get vmexit right away, therefor you need a full
functional emulator that will handle everything there.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [ToDo] Real Mode Support
2008-02-06 7:33 [ToDo] Real Mode Support Guillaume Thouvenin
2008-02-06 8:52 ` Izik Eidus
@ 2008-02-06 17:32 ` Anthony Liguori
[not found] ` <47A9EF21.3050103-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-02-10 11:44 ` Avi Kivity
1 sibling, 2 replies; 11+ messages in thread
From: Anthony Liguori @ 2008-02-06 17:32 UTC (permalink / raw)
To: Guillaume Thouvenin; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Guillaume Thouvenin wrote:
> Hello,
>
> I read on the kvmwiki/TODO that there is a work in progress for
> extending x86 emulator to support more instructions in real mode and for
> changing the execution loop to call the emulator for real mode.
>
Yes, Nitin has done some work in this area.
> As I'm interested to work on this part I'd like to know what was
> already done.
>
> I'd like to have more information about how the execution loop need to
> be changed. Currently we enter/leave real mode through a call to
> enter_rmode()/enter_pmode(). The function sets a variable
> "arch.rmode.active" and also sets the bit X86_EFLAGS_VM of
> GUEST_RFLAGS. That means that we are using the VM mode to virtualize
> the real mode. I know that in virtual mode some instructions can not be
> used as they are in full real mode (that would have been too easy). So
> these instructions generate a protection fault and need to be emulated.
> So we handle this kind of exception in handle_exception() and we call
> the x86 emulator. From the emulator we read the eflags
> (kvm_x86_ops->get_rflags(vcpu)) and we can know if we are in real mode
> or not. It's the current scheme, right?
>
Sort of. Right now we put the guest into vm86 mode and use that to
execute real mode code. There are a number of problems with using vm86
(some due to VT restrictions on vm86). The biggest problem is Big Real
Mode.
In real mode, the x86 uses segmentation only. Normally, the segment
limits are setup to be 0xffff and since the translation for segment mode
is 16-bit segment register * 16, you can address 2^20 work of address space.
However, if you switch to protected mode, you can setup the GDT to have
4G segments. If you then switch back to real mode, you can use 32-bit
address overrides to access the full 32-bit address space in 16-bit mode.
vm86 does not support this trick though. To further complicate matters,
there are certain gotcha's when using vm86 with VT that are less easy to
detect.
So what we would like to do, is instead of setting up vm86 mode for the
guest to execute real mode, use x86_emulate() to just emulate the code.
This means that we wouldn't be using the "vmlaunch" instruction when in
real mode and instead would be doing an x86_emulate() loop.
Regards,
Anthony Liguori
> My question is why the execution loop needs to be changed here. I mean
> isn't it possible to just extend x86 emulator to support more
> instructions in real mode? I think that I'm missing something here so
> any help, hint, advice, link are welcome.
>
> Best Regards,
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread[parent not found: <47A9EF21.3050103-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>]
* Re: [ToDo] Real Mode Support
[not found] ` <47A9EF21.3050103-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2008-02-06 17:47 ` Izik Eidus
0 siblings, 0 replies; 11+ messages in thread
From: Izik Eidus @ 2008-02-06 17:47 UTC (permalink / raw)
To: Anthony Liguori
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Guillaume Thouvenin
On Wed, 2008-02-06 at 11:32 -0600, Anthony Liguori wrote:
> Guillaume Thouvenin wrote:
> > Hello,
> >
> > I read on the kvmwiki/TODO that there is a work in progress for
> > extending x86 emulator to support more instructions in real mode and for
> > changing the execution loop to call the emulator for real mode.
> >
>
> Yes, Nitin has done some work in this area.
>
> > As I'm interested to work on this part I'd like to know what was
> > already done.
> >
> > I'd like to have more information about how the execution loop need to
> > be changed. Currently we enter/leave real mode through a call to
> > enter_rmode()/enter_pmode(). The function sets a variable
> > "arch.rmode.active" and also sets the bit X86_EFLAGS_VM of
> > GUEST_RFLAGS. That means that we are using the VM mode to virtualize
> > the real mode. I know that in virtual mode some instructions can not be
> > used as they are in full real mode (that would have been too easy). So
> > these instructions generate a protection fault and need to be emulated.
> > So we handle this kind of exception in handle_exception() and we call
> > the x86 emulator. From the emulator we read the eflags
> > (kvm_x86_ops->get_rflags(vcpu)) and we can know if we are in real mode
> > or not. It's the current scheme, right?
> >
>
> Sort of. Right now we put the guest into vm86 mode and use that to
> execute real mode code. There are a number of problems with using vm86
> (some due to VT restrictions on vm86). The biggest problem is Big Real
> Mode.
>
> In real mode, the x86 uses segmentation only. Normally, the segment
> limits are setup to be 0xffff and since the translation for segment mode
> is 16-bit segment register * 16, you can address 2^20 work of address space.
>
> However, if you switch to protected mode, you can setup the GDT to have
> 4G segments. If you then switch back to real mode, you can use 32-bit
> address overrides to access the full 32-bit address space in 16-bit mode.
>
> vm86 does not support this trick though. To further complicate matters,
> there are certain gotcha's when using vm86 with VT that are less easy to
> detect.
>
> So what we would like to do, is instead of setting up vm86 mode for the
> guest to execute real mode, use x86_emulate() to just emulate the code.
> This means that we wouldn't be using the "vmlaunch" instruction when in
> real mode and instead would be doing an x86_emulate() loop.
and for the matter of fact there are not too many instructions that
needed to be emulated in oreder to make it work as that the vm86
instructions are very limited anyway
(15.1.3 in the intel manual list them)
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [ToDo] Real Mode Support
2008-02-06 17:32 ` Anthony Liguori
[not found] ` <47A9EF21.3050103-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2008-02-10 11:44 ` Avi Kivity
2008-02-11 13:39 ` Guillaume Thouvenin
1 sibling, 1 reply; 11+ messages in thread
From: Avi Kivity @ 2008-02-10 11:44 UTC (permalink / raw)
To: Anthony Liguori; +Cc: kvm-devel, Guillaume Thouvenin
Anthony Liguori wrote:
> So what we would like to do, is instead of setting up vm86 mode for the
> guest to execute real mode, use x86_emulate() to just emulate the code.
> This means that we wouldn't be using the "vmlaunch" instruction when in
> real mode and instead would be doing an x86_emulate() loop.
>
As using the emulator is likely to be slower than VT, we can call the
emulator only if we are in a "VT unfriendly" state, so the code might
look like
if (vmx->rmode.active && big_real_mode(vmx))
...
In addition, there are some protected-mode states that VT can't handle
(cs.rpl != ss.rpl IIRC) so we can emulate those cases as well.
To improve speed, we may want to emulate >1 instruction per iteration.
--
error compiling committee.c: too many arguments to function
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [ToDo] Real Mode Support
2008-02-10 11:44 ` Avi Kivity
@ 2008-02-11 13:39 ` Guillaume Thouvenin
2008-02-11 14:20 ` Avi Kivity
0 siblings, 1 reply; 11+ messages in thread
From: Guillaume Thouvenin @ 2008-02-11 13:39 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel
On Sun, 10 Feb 2008 13:44:05 +0200
Avi Kivity <avi@qumranet.com> wrote:
> Anthony Liguori wrote:
> > So what we would like to do, is instead of setting up vm86 mode for the
> > guest to execute real mode, use x86_emulate() to just emulate the code.
> > This means that we wouldn't be using the "vmlaunch" instruction when in
> > real mode and instead would be doing an x86_emulate() loop.
> >
>
> As using the emulator is likely to be slower than VT, we can call the
> emulator only if we are in a "VT unfriendly" state, so the code might
> look like
>
> if (vmx->rmode.active && big_real_mode(vmx))
> ...
>
> In addition, there are some protected-mode states that VT can't handle
> (cs.rpl != ss.rpl IIRC) so we can emulate those cases as well.
>
> To improve speed, we may want to emulate >1 instruction per iteration.
So the plan is to keep the usage of vm86 mode until we detect a "VT
unfriendly" state. I think about a VMentry failure to detect this kind
of state?
Then, when we are in big_real_mode state, we emulate the code as
suggested by Avi with the optimisation that consists to emulate more
than one instruction per iteration.
Best regards,
Guillaume
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [ToDo] Real Mode Support
2008-02-11 13:39 ` Guillaume Thouvenin
@ 2008-02-11 14:20 ` Avi Kivity
0 siblings, 0 replies; 11+ messages in thread
From: Avi Kivity @ 2008-02-11 14:20 UTC (permalink / raw)
To: Guillaume Thouvenin; +Cc: kvm-devel
Guillaume Thouvenin wrote:
>>>
>>>
>> As using the emulator is likely to be slower than VT, we can call the
>> emulator only if we are in a "VT unfriendly" state, so the code might
>> look like
>>
>> if (vmx->rmode.active && big_real_mode(vmx))
>> ...
>>
>> In addition, there are some protected-mode states that VT can't handle
>> (cs.rpl != ss.rpl IIRC) so we can emulate those cases as well.
>>
>> To improve speed, we may want to emulate >1 instruction per iteration.
>>
>
> So the plan is to keep the usage of vm86 mode until we detect a "VT
> unfriendly" state. I think about a VMentry failure to detect this kind
> of state?
>
Yes, that's a good way.
> Then, when we are in big_real_mode state, we emulate the code as
> suggested by Avi with the optimisation that consists to emulate more
> than one instruction per iteration.
>
>
Yes. Note we sometimes need to emulate in protected mode as well.
--
error compiling committee.c: too many arguments to function
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-02-11 14:20 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-06 7:33 [ToDo] Real Mode Support Guillaume Thouvenin
2008-02-06 8:52 ` Izik Eidus
[not found] ` <1202287974.23342.8.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-02-06 12:07 ` Guillaume Thouvenin
2008-02-06 12:52 ` Izik Eidus
2008-02-06 23:52 ` Kamble, Nitin A
2008-02-07 18:36 ` Alexey Eremenko
2008-02-06 17:32 ` Anthony Liguori
[not found] ` <47A9EF21.3050103-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-02-06 17:47 ` Izik Eidus
2008-02-10 11:44 ` Avi Kivity
2008-02-11 13:39 ` Guillaume Thouvenin
2008-02-11 14:20 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox