Virtual 8086 Mode: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(Major edit. The original was incorrect. In order to enter V86, the data segment registers must be pushed onto the stack, otherwise there would be no way to set the before entry. Removed the code sample and abridged the intro.)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(2 intermediate revisions by 2 users not shown)
Line 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.
 
<sourcesyntaxhighlight lang="asm">
detect_v86:
smsw ax
and eax,1 ;CR0.PE bit
ret
</syntaxhighlight>
</source>
 
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 ;)