vm86, iret and TSS
Posted: Thu Mar 08, 2007 3:06 am
I have the code, to enter in vm86:
vm86_bios:
;B+ Call bios interrupt in virtual 86 mode
push dword 0x1000 ;gs
push dword 0x1000 ;fs
push dword 0x1000 ;ds
push dword 0x1000 ;es
push dword 0x1000 ;ss
push dword 0xffff ;esp
;===EFLAGS=== pushfd with vm86 bit = 1
push dword 0x23202 ;0x20200 ;0x23202
push dword 0x1000 ;cs
push dword vm86-0x10000 ;eip
iret ;<--################################
.exit:
;pop stack ...
add esp,9*4
ret
use16
vm86:
;B+ Test
; end only...
; int 0x40
jmp $ ;<--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;E:.
use32
;E:.
If I start this code, than I receive the error:
interrupt(): SS is not writable data segment
Wath is wrong???
Debugging this code with bochs, I found, that:
BEFORE:
esp:0x0007ff94 eip:0x000190a0
eflags:0x00000297 = IF+SF+AF+PF+CF
cs:s=0x0008, dl=0x0000ffff, dh=0x00df9a00, valid=1
ss:s=0x08b0, dl=0x000000ff, dh=0x01d09308, valid=7
ds:s=0x0010, dl=0x0000ffff, dh=0x00df9300, valid=3
es:s=0x0010, dl=0x0000ffff, dh=0x00df9300, valid=1
tr:s=0x0090, dl=0x07800080, dh=0x00108904, valid=1
gdtr:base=0x00019e61, limit=0xc47
idtr:base=0x0001aab1, limit=0x807
AFTER:
esp:0x0000fffd eip:0x000090a6
eflags:0x00023202 = 100011001000000010 = VM+IOPL=3+IF
cs:s=0x1000, dl=0x0000ffff, dh=0x0000fb01, valid=1
ss:s=0x1000, dl=0x0000ffff, dh=0x0000f301, valid=5
ds:s=0x1000, dl=0x0000ffff, dh=0x0000f301, valid=1
es:s=0x1000, dl=0x0000ffff, dh=0x0000f301, valid=1
tr:s=0x0090, dl=0x07800080, dh=0x00108904, valid=1
gdtr:base=0x00019e61, limit=0xc47
idtr:base=0x0001aab1, limit=0x807
This is only for additional information.
vm86_bios:
;B+ Call bios interrupt in virtual 86 mode
push dword 0x1000 ;gs
push dword 0x1000 ;fs
push dword 0x1000 ;ds
push dword 0x1000 ;es
push dword 0x1000 ;ss
push dword 0xffff ;esp
;===EFLAGS=== pushfd with vm86 bit = 1
push dword 0x23202 ;0x20200 ;0x23202
push dword 0x1000 ;cs
push dword vm86-0x10000 ;eip
iret ;<--################################
.exit:
;pop stack ...
add esp,9*4
ret
use16
vm86:
;B+ Test
; end only...
; int 0x40
jmp $ ;<--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;E:.
use32
;E:.
If I start this code, than I receive the error:
interrupt(): SS is not writable data segment
Wath is wrong???
Debugging this code with bochs, I found, that:
BEFORE:
esp:0x0007ff94 eip:0x000190a0
eflags:0x00000297 = IF+SF+AF+PF+CF
cs:s=0x0008, dl=0x0000ffff, dh=0x00df9a00, valid=1
ss:s=0x08b0, dl=0x000000ff, dh=0x01d09308, valid=7
ds:s=0x0010, dl=0x0000ffff, dh=0x00df9300, valid=3
es:s=0x0010, dl=0x0000ffff, dh=0x00df9300, valid=1
tr:s=0x0090, dl=0x07800080, dh=0x00108904, valid=1
gdtr:base=0x00019e61, limit=0xc47
idtr:base=0x0001aab1, limit=0x807
AFTER:
esp:0x0000fffd eip:0x000090a6
eflags:0x00023202 = 100011001000000010 = VM+IOPL=3+IF
cs:s=0x1000, dl=0x0000ffff, dh=0x0000fb01, valid=1
ss:s=0x1000, dl=0x0000ffff, dh=0x0000f301, valid=5
ds:s=0x1000, dl=0x0000ffff, dh=0x0000f301, valid=1
es:s=0x1000, dl=0x0000ffff, dh=0x0000f301, valid=1
tr:s=0x0090, dl=0x07800080, dh=0x00108904, valid=1
gdtr:base=0x00019e61, limit=0xc47
idtr:base=0x0001aab1, limit=0x807
This is only for additional information.