Page 1 of 2
Exit from Virtual 8086 Mode in Protected Mode
Posted: Tue Aug 12, 2014 10:59 am
by Neo92
Hi, i post a simple code in protected mode that goes in virtual 8086 mode:
Code: Select all
use16
vm86:
mov ax,0e41h
mov bx,7
int 10h ;this here we go. Print a character 'A' as in real mode.
;here i problems to use a task switch return in protected mode.
use32
pmode:
push 0
push 0
push 0
push 0
push 0
push 0fffeh
push 20000h
push 0
push vm86
iret
How can i return in protected mode from a task virtual 8086 mode? Thanks all.
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Tue Aug 12, 2014 1:03 pm
by alexfru
Any hardware interrupt or software exception will switch the CPU from virtual 8086 mode into protected mode in order to execute the appropriate interrupt or exception handler.
Unless you're using virtual 8086 mode extensions, the int instruction will also cause a #GP (exception) and a transition from v86 into protected mode.
I've written a set of
tutorials on protected mode and you're interested in tutorials 13 through 17 (briefly explained
here).
Please read the CPU documentation from Intel and/or AMD for the details of the CPU operation in these (and all) modes.
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Wed Aug 13, 2014 8:06 am
by Neo92
Thanks for reply alexfru, i switch the VME bit in CR4 to make it work in VM86 otherwise doesn't work. I try use 'pop' with 'iretd' to return in pmode but nothing, infact cause a triple fault
problem return v86 task
What do you advise me to do?
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Wed Aug 13, 2014 10:00 am
by Combuster
An exception or interrupt is the only way out of v8086 mode. For that, you need an IDT. You don't have one.
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Wed Aug 13, 2014 10:14 am
by Gigasoft
Thanks for reply alexfru, i switch the VME bit in CR4 to make it work in VM86 otherwise doesn't work. I try use 'pop' with 'iretd' to return in pmode but nothing, infact cause a triple fault
That's because you have no clue about what you are doing, and are doing random silly things which of course won't work. You have obviously never looked at the manual. There is an announcement at the top here called FORUM RULES -
REQUIRED READING, which you have also obviously never read. Rule 3 is not intended as a joke.
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Wed Aug 13, 2014 10:20 am
by Neo92
Ok Combuster, but how do I execute an interrupt to terminate the virtual 8086 mode? I post the update code.
The new code
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Wed Aug 13, 2014 11:40 am
by Combuster
Gigasoft wrote:Rule 3 is not intended as a joke.
QFT
List 5 chapters in intel 3A that do not mention interrupts in any way.
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Thu Aug 14, 2014 5:08 am
by Neo92
Combuster... i used a 32 bit interrupt in v86, precisely 'int 49' for floppy controller. Why doesn't work in virtual mode if i fixed the IDT?
N.B.:
Manual
Details on Entering Virtual-8086 Mode
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Thu Aug 14, 2014 7:44 am
by Neo92
I'm blocked into v86 task and i want kill it, how can i to exit? Please help me.
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Thu Aug 14, 2014 8:07 am
by iansjack
Section 20.2.6 "Leaving Virtual-8086 Mode" of the Intel Programmer's Manual.
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Fri Aug 15, 2014 4:33 am
by Neo92
Okay come on! A last question. How do i set VM flag to zero? I ask because have seen, in the intel manual, a graphic diagram about the task switch...
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Fri Aug 15, 2014 4:59 am
by iansjack
Section 20.2.6 "Leaving Virtual-8086 Mode" of the Intel Programmer's Manual.
A task switch from a virtual-8086 task to another task loads the EFLAGS register from the TSS of the new task. The value of the VM flag in the new EFLAGS determines if the new task executes in virtual-8086 mode or not.
You clear it in the EFLAGS stored in the TSS.
Read the manual - carefully - and make sure that you understand it.
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Fri Aug 15, 2014 12:28 pm
by Gigasoft
I don't think there is a need to complicate things by using HW task switching. No operating system that I know of uses it for much besides double fault handling. For exiting VM86 mode, any exception will suffice. Usually one would use an INT instruction (thus invoking the GPF handler), or an invalid opcode.
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Fri Aug 15, 2014 1:16 pm
by Neo92
I had thought using 'hlt' instruction, obviously causes a GPF in v8086 and the Bochs emulator restarts. I thought also to another thing... maybe i have to check the gpf handler, what do you think?
Re: Exit from Virtual 8086 Mode in Protected Mode
Posted: Sat Aug 16, 2014 12:53 am
by Gigasoft
I thought also to another thing... maybe i have to check the gpf handler, what do you think?
You don't even
HAVE a GPF handler! There is nothing to check! You need to write one first! And your "TSS" starts at address 0 and is actually your IVT. You need to have a real TSS somewhere, with the ESP0 and SS0 fields set up properly, as well as the IO Permission Map and Interrupt Redirection Map (if using VME).