Exit from Virtual 8086 Mode in Protected 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.
User avatar
Neo92
Member
Member
Posts: 28
Joined: Tue Jun 24, 2014 9:41 am

Exit from Virtual 8086 Mode in Protected Mode

Post 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.
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Exit from Virtual 8086 Mode in Protected Mode

Post 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.
User avatar
Neo92
Member
Member
Posts: 28
Joined: Tue Jun 24, 2014 9:41 am

Re: Exit from Virtual 8086 Mode in Protected Mode

Post 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?
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: Exit from Virtual 8086 Mode in Protected Mode

Post 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.
"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 ]
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Exit from Virtual 8086 Mode in Protected Mode

Post 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.
User avatar
Neo92
Member
Member
Posts: 28
Joined: Tue Jun 24, 2014 9:41 am

Re: Exit from Virtual 8086 Mode in Protected Mode

Post 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
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: Exit from Virtual 8086 Mode in Protected Mode

Post 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.
"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
Neo92
Member
Member
Posts: 28
Joined: Tue Jun 24, 2014 9:41 am

Re: Exit from Virtual 8086 Mode in Protected Mode

Post 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
User avatar
Neo92
Member
Member
Posts: 28
Joined: Tue Jun 24, 2014 9:41 am

Re: Exit from Virtual 8086 Mode in Protected Mode

Post by Neo92 »

I'm blocked into v86 task and i want kill it, how can i to exit? Please help me.
User avatar
iansjack
Member
Member
Posts: 4709
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Exit from Virtual 8086 Mode in Protected Mode

Post by iansjack »

Section 20.2.6 "Leaving Virtual-8086 Mode" of the Intel Programmer's Manual.
User avatar
Neo92
Member
Member
Posts: 28
Joined: Tue Jun 24, 2014 9:41 am

Re: Exit from Virtual 8086 Mode in Protected Mode

Post 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...
User avatar
iansjack
Member
Member
Posts: 4709
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Exit from Virtual 8086 Mode in Protected Mode

Post 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.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Exit from Virtual 8086 Mode in Protected Mode

Post 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.
User avatar
Neo92
Member
Member
Posts: 28
Joined: Tue Jun 24, 2014 9:41 am

Re: Exit from Virtual 8086 Mode in Protected Mode

Post 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? :mrgreen:
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Exit from Virtual 8086 Mode in Protected Mode

Post by Gigasoft »

I thought also to another thing... maybe i have to check the gpf handler, what do you think? :mrgreen:
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).
Locked