00001 ; ndk - [ vm86.asm ] 00002 ; 00003 ; The assembly language portion of the vm86 00004 ; task handler. Currently being revamped 00005 ; (does not work). 00006 ; 00007 ; Please see: 00008 ; /src/vm86.{c,h} 00009 ; 00010 ; (c)2002 dcipher / neuraldk 00011 ; www.neuraldk.org 00012 00013 global vm86IntHandler 00014 global vm86Test 00015 global iretInstruction 00016 00017 ;extern kprintf 00018 00019 [bits 32] 00020 00021 ;section .data 00022 intMsg db 'back from int',0 00023 00024 ;section .code 00025 00026 ; top 16 bits of eax = real mode interrupt 00027 ; all other registers must be preserved and sent to real mode int 00028 vm86IntHandler: 00029 ; create new vm86 stack frame 00030 push dword 0 ;gs 00031 push dword 0 ;fs 00032 push dword 0 ;ds 00033 push dword 0 ;es 00034 push dword 0x7000 ; vm86 stack space (ss) 00035 push dword 0xffff ; esp 00036 pushfd 00037 ; ** new 00038 pop edx 00039 or edx, 0x20000 00040 push edx 00041 ; enable vm86 bit 00042 ;or dword [ss:esp+4], 0x20000 00043 ; ** end new -> clobbered edx!!! 00044 00045 ; save eax and ebx below where vm86 stack will end 00046 mov [ss:esp-12], eax 00047 mov [ss:esp-16], ebx 00048 00049 ; calculate offset of real mode idt vector 00050 shr eax, 16 00051 shl eax, 2 00052 add eax, 0x00001000 ; real mode idt is stored at 1kb (boot loader put it there) 00053 ; save the offset in ebx 00054 mov ebx, eax 00055 ; and read in the real mode code segment 00056 xor eax, eax 00057 ;** mov ax, [ebx+2] 00058 mov eax, 0x0000c000 00059 and eax, 0x0000ffff 00060 ; and put it to the stack 00061 push eax 00062 00063 ; read in the real mode ip 00064 ;** mov ax, [ebx] 00065 mov eax, 0x00000d98 00066 and eax, 0x0000ffff 00067 ; and put it on the stack 00068 push eax 00069 00070 00071 ; now restore eax and ebx (remember, we've push 8 bytes, so they're 00072 ; 8 bytes closer to esp) 00073 mov eax, [ss:esp-4] 00074 mov ebx, [ss:esp-8] 00075 00076 ; remove the high order bits from eax (no longer needed) 00077 and eax, 0x0000ffff 00078 00079 ; iret to the real mode interrupt, in vm86 mode!!! 00080 iretInstruction: 00081 ;jmp iretInstruction 00082 iret 00083 ;push intMsg 00084 ;call printf 00085 ;iret 00086 00087 vm86Test: 00088 ; mov eax, 0x10 00089 ; shl eax, 16 00090 ; mov ax, 0x13 00091 mov eax, 0x16 00092 shl eax, 16 00093 mov ax, 0x0 00094 mov ebx, 0x11111111 00095 mov ecx, 0x22222222 00096 mov edx, 0x33333333 00097 int 0x81 00098 ret