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.
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.
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.
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?
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 ]
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.
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 ]
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.
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.
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?
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).