12,21 → 12,16 |
|
DEBUG_SHOW_IO = 0 |
|
struc V86_machine |
{ |
struct V86_machine |
; page directory |
.pagedir dd ? |
pagedir dd ? |
; translation table: V86 address -> flat linear address |
.pages dd ? |
pages dd ? |
; mutex to protect all data from writing by multiple threads at one time |
.mutex dd ? |
mutex dd ? |
; i/o permission map |
.iopm dd ? |
.size = $ |
} |
virtual at 0 |
V86_machine V86_machine |
end virtual |
iopm dd ? |
ends |
|
; Create V86 machine |
; in: nothing |
35,7 → 30,7 |
; destroys: ebx, ecx, edx (due to malloc) |
v86_create: |
; allocate V86_machine structure |
mov eax, V86_machine.size |
mov eax, sizeof.V86_machine |
call malloc |
test eax, eax |
jz .fail |
245,31 → 240,26 |
.ret: |
ret |
|
struc v86_regs |
{ |
struct v86_regs |
; don't change the order, it is important |
.edi dd ? |
.esi dd ? |
.ebp dd ? |
edi dd ? |
esi dd ? |
ebp dd ? |
dd ? ; ignored |
.ebx dd ? |
.edx dd ? |
.ecx dd ? |
.eax dd ? |
.eip dd ? |
.cs dd ? |
.eflags dd ? ; VM flag must be set! |
.esp dd ? |
.ss dd ? |
.es dd ? |
.ds dd ? |
.fs dd ? |
.gs dd ? |
.size = $ |
} |
virtual at 0 |
v86_regs v86_regs |
end virtual |
ebx dd ? |
edx dd ? |
ecx dd ? |
eax dd ? |
eip dd ? |
cs dd ? |
eflags dd ? ; VM flag must be set! |
esp dd ? |
ss dd ? |
es dd ? |
ds dd ? |
fs dd ? |
gs dd ? |
ends |
|
; Run V86 machine |
; in: ebx -> registers for V86 (two structures: in and out) |
319,10 → 309,10 |
; sti |
|
mov eax, esi |
sub esp, v86_regs.size |
sub esp, sizeof.v86_regs |
mov esi, ebx |
mov edi, esp |
mov ecx, v86_regs.size/4 |
mov ecx, sizeof.v86_regs/4 |
rep movsd |
|
cmp edx, -1 |
372,7 → 362,7 |
xor eax, eax |
mov dr6, eax |
@@: |
mov eax, [esp+v86_regs.size+10h+18h] |
mov eax, [esp+sizeof.v86_regs+10h+18h] |
cmp word [esp+v86_regs.eip], ax |
jnz @f |
shr eax, 16 |
444,7 → 434,7 |
sub eax, 6 |
add edx, eax |
mov eax, edx |
mov esi, [esp+4+v86_regs.size+10h+4] |
mov esi, [esp+4+sizeof.v86_regs+10h+4] |
call v86_get_lin_addr |
cmp eax, 0x1000 |
jae @f |
492,7 → 482,7 |
movzx eax, word [esp+v86_regs.esp] |
add edx, eax |
mov eax, edx |
mov esi, [esp+v86_regs.size+10h+4] |
mov esi, [esp+sizeof.v86_regs+10h+4] |
call v86_get_lin_addr |
cmp eax, 0x1000 |
jae @f |
528,7 → 518,7 |
movzx eax, ax |
add edx, eax |
mov eax, edx |
mov esi, [esp+v86_regs.size+10h+4] |
mov esi, [esp+sizeof.v86_regs+10h+4] |
call v86_get_lin_addr |
cmp eax, 0x1000 |
jae @f |
560,7 → 550,7 |
sub eax, 4 |
add edx, eax |
mov eax, edx |
mov esi, [esp+v86_regs.size+10h+4] |
mov esi, [esp+sizeof.v86_regs+10h+4] |
call v86_get_lin_addr |
cmp eax, 0x1000 |
jae @f |
591,7 → 581,7 |
movzx eax, word [esp+v86_regs.esp] |
add edx, eax |
mov eax, edx |
mov esi, [esp+v86_regs.size+10h+4] |
mov esi, [esp+sizeof.v86_regs+10h+4] |
call v86_get_lin_addr |
cmp eax, 0x1000 |
jae @f |
622,7 → 612,7 |
movzx eax, word [esp+v86_regs.esp] |
add edx, eax |
mov eax, edx |
mov esi, [esp+v86_regs.size+10h+4] |
mov esi, [esp+sizeof.v86_regs+10h+4] |
call v86_get_lin_addr |
cmp eax, 0x1000 |
jae @f |
748,7 → 738,7 |
shl edx, 4 |
add edx, [esp+32] |
@@: |
mov esi, [esp+v86_regs.size+10h+4] |
mov esi, [esp+sizeof.v86_regs+10h+4] |
mov eax, edx |
call v86_get_lin_addr |
cmp eax, 0x1000 |
773,10 → 763,10 |
xor eax, eax |
|
.exit: |
mov [esp+v86_regs.size+10h+1Ch], eax |
mov [esp+v86_regs.size+10h+18h], ebx |
mov [esp+sizeof.v86_regs+10h+1Ch], eax |
mov [esp+sizeof.v86_regs+10h+18h], ebx |
|
mov edx, [esp+v86_regs.size+10h+14h] |
mov edx, [esp+sizeof.v86_regs+10h+14h] |
cmp edx, -1 |
jz @f |
dec [v86_irqhooks+edx*8+4] |
785,9 → 775,9 |
@@: |
|
mov esi, esp |
mov edi, [esi+v86_regs.size+10h+10h] |
add edi, v86_regs.size |
mov ecx, v86_regs.size/4 |
mov edi, [esi+sizeof.v86_regs+10h+10h] |
add edi, sizeof.v86_regs |
mov ecx, sizeof.v86_regs/4 |
rep movsd |
mov esp, esi |
|
874,12 → 864,12 |
jnz .cont |
push ecx |
mov ecx, [ebx+APPDATA.saved_esp0] |
cmp word [ecx-v86_regs.size+v86_regs.esp], 6 |
cmp word [ecx-sizeof.v86_regs+v86_regs.esp], 6 |
jb .cont2 |
movzx edx, word [ecx-v86_regs.size+v86_regs.ss] |
movzx edx, word [ecx-sizeof.v86_regs+v86_regs.ss] |
shl edx, 4 |
push eax |
movzx eax, word [ecx-v86_regs.size+v86_regs.esp] |
movzx eax, word [ecx-sizeof.v86_regs+v86_regs.esp] |
sub eax, 6 |
add edx, eax |
mov eax, edx |
905,12 → 895,12 |
iretd |
.found: |
mov cr3, eax |
sub word [esi-v86_regs.size+v86_regs.esp], 6 |
mov ecx, [esi-v86_regs.size+v86_regs.eip] |
sub word [esi-sizeof.v86_regs+v86_regs.esp], 6 |
mov ecx, [esi-sizeof.v86_regs+v86_regs.eip] |
mov word [edx], cx |
mov ecx, [esi-v86_regs.size+v86_regs.cs] |
mov ecx, [esi-sizeof.v86_regs+v86_regs.cs] |
mov word [edx+2], cx |
mov ecx, [esi-v86_regs.size+v86_regs.eflags] |
mov ecx, [esi-sizeof.v86_regs+v86_regs.eflags] |
mov word [edx+4], cx |
lea eax, [edi+8] |
cmp al, 10h |
918,10 → 908,10 |
add al, 60h |
@@: |
mov cx, [eax*4] |
mov word [esi-v86_regs.size+v86_regs.eip], cx |
mov word [esi-sizeof.v86_regs+v86_regs.eip], cx |
mov cx, [eax*4+2] |
mov word [esi-v86_regs.size+v86_regs.cs], cx |
and byte [esi-v86_regs.size+v86_regs.eflags+1], not 3 |
mov word [esi-sizeof.v86_regs+v86_regs.cs], cx |
and byte [esi-sizeof.v86_regs+v86_regs.eflags+1], not 3 |
call update_counters |
lea edi, [ebx + 0x100000000 - SLOT_BASE] |
shr edi, 3 |