Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- virtual8086:
- push eax
- push ebx
- push ecx
- push edx
- push esi
- push edi
- push ebp
- %define .oldEBP esp
- %define .oldEDI esp+4
- %define .oldESI esp+8
- %define .oldEDX esp+12
- %define .oldECX esp+16
- %define .oldEBX esp+20
- %define .oldEAX esp+24
- %define .errorCode esp+28
- %define .oldEIP esp+32
- %define .oldCS esp+36
- %define .oldEFLAGS esp+40
- %define .oldESP esp+44
- %define .oldSS esp+48
- %define .oldES esp+52
- %define .oldDS esp+56
- %define .oldFS esp+60
- %define .oldGS esp+64
- mov eax,0x10;KERNEL_DATA_SEG
- mov ds,eax
- mov es,eax
- movzx eax,word [.oldCS]
- movzx ebx,word [.oldEIP]
- shl eax,4
- add ebx,eax ;ebx = address of instruction that caused GPF
- mov dl,[ebx] ;dl = first byte of instruction that caused GPF
- cmp dl, 0xcd ;Was it a software interrupt?
- jz .vm8086_monitor_int ; yes
- cmp dl, 0x9c ;Was it a PUSHF?
- jz .vm8086_monitor_pushf ; yes
- ;Need to do an error message and abort (can't continue running
- ; virtual8086 code because we can't handle whatever caused the
- ; GPF).
- .abortV86:
- ; sti
- cli
- .die:
- hlt
- jmp .die
- .vm8086_monitor_int:
- movzx eax,word [.oldSS]
- movzx edi,word [.oldESP]
- shl eax,4
- add edi,eax ;edi = address of interrupted code's SS:SP
- mov ax,[.oldCS]
- sub edi,2
- mov [edi],ax ;Put original CS on interrupted code's stack
- mov ax,[.oldEIP]
- sub edi,2
- add ax, 2
- mov [edi],ax ;Put original IP on interrupted code's stack
- sub word [.oldESP],4 ;Decrease original SP
- movzx eax,byte [ebx+1] ;eax = interrupt number
- movzx ecx,word [eax*4] ;ecx = IP for interrupt
- movzx eax,word [eax*4+2] ;eax = CS for interrupt
- mov [.oldEIP],ecx ;Set new return EIP
- mov [.oldCS],eax ;Set new return CS
- or dword [.oldEFLAGS],(1<<9) ;Set IF flag in original EFLAGS
- btc dword [.oldEFLAGS], 9
- jmp .vm8086_monitor_return ;Return to the requested interrupt handler
- ; (which will return to the original code)
- .vm8086_monitor_pushf:
- jmp .abortV86 ;Until this code is written...
- .vm8086_monitor_return:
- pop ebp
- pop edi
- pop esi
- pop edx
- pop ecx
- pop ebx
- pop eax
- add esp,4 ;Skip over error code
- iret
Add Comment
Please, Sign In to add comment