Virtual 8086 Mode: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
mNo edit summary
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(15 intermediate revisions by 11 users not shown)
Line 1:
Virtual 8086 mode is a sub-mode of [[Protected mode]]. In short, virtualVirtual 8086 mode is whereby the CPU (in protected mode) is running a "Emulated" 16bit 'segmented'Real model (real mode)Mode machine.
 
==Entering V86==
 
The CPU is executing in virtual 86 mode when the VM bit (bit 17) is set in the ''EFLAGS'' register. If you want to enter virtual 86 mode you must set this bit to 1.
A way of modifying the EFLAGS register is to use the ''PUSHF'' and ''POPF'' instructions, but these instructions are for user space and cannot modify supervisor flags. The only way to set the VM flag is to use the iret instruction. This instruction is normally used to return from an interrupt. When ''IRET'' is called with the VM=1 in the stack ''EFLAGS'' (the context being returned to is V86), the interrupt stack frame will contain segments ''ES'', ''DS'', ''FS'', and ''GS'', so that they can be set before entry.
 
A task gate can also be used to enter V86. This allows setting the segment registers. It is probably not necessary to do it this way unless the OS is using hardware multitasking.
 
[[File:Fig15-3.gif]]
 
==V86 Problem==
Line 11 ⟶ 20:
EFLAGS.VM is NEVER pushed onto the stack if the V86 task uses PUSHFD. You should check if CR0.PE=1 and then assume it's V86 if that bit is set.
 
<syntaxhighlight lang="asm">
<pre>
detect_v86:
smsw ax
and eax,1 ;CR0.PE bit
ret
</syntaxhighlight>
</pre>
 
VM mode detection is mainly useful when writing DOS extenders or other programs that could be started either in plain real mode or in virtual mode from a protected mode system. An 'ordinary' bootloader shouldn't worry about this since the BIOS will not set up VM86 to read the bootsector ;)
Line 45 ⟶ 54:
===External Links===
*{{IntelManualLink|15}}
*http://osdev.berlios.de/v86.html - by Tim Robinson ([https://web.archive.org/web/20140111115023/http://osdev.berlios.de/v86.html Wayback Machine Link])
*[http://my.execpc.com/~geezer/osd/pmode/v86mm.zip A virtual-8086 mode monitor] - by Chris Giese
*[http://126.sytes.net/tmp/x86emu.zip x86emu] - a BSD style licensed vitual-8086 mode ''emulator'' - very different from a ''monitor''.
*[http://gitorious.org/x86emu/] - x86emu and several other projects. See mdt for code getting VBE modes.
*[http://www.rohitab.com/discuss/topic/35103-switch-between-real-mode-and-protected-mode/ Protected Mode BIOS Call Functionailty v2.0] - by Napalm
 
[[Category:X86 CPU]]
[[Category:Operating Modes]]