2011-10-14 23:38:50 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2022-02-12 18:27:41 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2007-2022. All rights reserved. ;;
|
2011-10-14 23:38:50 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
; Virtual-8086 mode manager
|
|
|
|
; diamond, 2007, 2008
|
|
|
|
|
|
|
|
DEBUG_SHOW_IO = 0
|
|
|
|
|
2012-02-23 19:52:13 +01:00
|
|
|
struct V86_machine
|
2011-10-14 23:38:50 +02:00
|
|
|
; page directory
|
2014-09-18 09:58:56 +02:00
|
|
|
process dd ?
|
2011-10-14 23:38:50 +02:00
|
|
|
; mutex to protect all data from writing by multiple threads at one time
|
2012-02-23 19:52:13 +01:00
|
|
|
mutex dd ?
|
2011-10-14 23:38:50 +02:00
|
|
|
; i/o permission map
|
2012-02-23 19:52:13 +01:00
|
|
|
iopm dd ?
|
|
|
|
ends
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
; Create V86 machine
|
|
|
|
; in: nothing
|
|
|
|
; out: eax = handle (pointer to struc V86_machine)
|
|
|
|
; eax = NULL => failure
|
|
|
|
; destroys: ebx, ecx, edx (due to malloc)
|
|
|
|
v86_create:
|
|
|
|
; allocate V86_machine structure
|
2012-02-23 19:52:13 +01:00
|
|
|
mov eax, sizeof.V86_machine
|
2011-10-14 23:38:50 +02:00
|
|
|
call malloc
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
; initialize mutex
|
2022-02-12 18:27:41 +01:00
|
|
|
and dword [eax + V86_machine.mutex], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
; allocate tables
|
|
|
|
mov ebx, eax
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2016-03-13 07:08:07 +01:00
|
|
|
stdcall create_process, 4096
|
2014-09-18 09:58:56 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .fail2
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [eax + PROC.mem_used], 4096
|
|
|
|
mov [ebx + V86_machine.process], eax
|
2014-09-18 09:58:56 +02:00
|
|
|
|
|
|
|
push 2000h
|
2011-10-14 23:38:50 +02:00
|
|
|
call kernel_alloc
|
|
|
|
test eax, eax
|
|
|
|
jz .fail2
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ebx + V86_machine.iopm], eax
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
; initialize tables
|
2014-09-18 09:58:56 +02:00
|
|
|
push edi
|
|
|
|
mov edi, eax
|
|
|
|
mov eax, -1
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ecx, 2000h/4
|
|
|
|
rep stosd
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [ebx + V86_machine.process]
|
|
|
|
mov eax, [eax + PROC.pdt_0_phys]
|
2014-09-18 09:58:56 +02:00
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
mov cr3, eax
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
; now V86 specific: initialize known addresses in first Mb
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
; first page - BIOS data (shared between all machines!)
|
|
|
|
; physical address = 0
|
|
|
|
; linear address = OS_BASE
|
|
|
|
; page before 0xA0000 - Extended BIOS Data Area (shared between all machines!)
|
|
|
|
; physical address = 0x9C000
|
|
|
|
; linear address = 0x8009C000
|
|
|
|
; (I have seen one computer with EBDA segment = 0x9D80,
|
|
|
|
; all other computers use less memory)
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2015-01-06 15:53:54 +01:00
|
|
|
mov eax, PG_UWR
|
2014-09-18 09:58:56 +02:00
|
|
|
mov [page_tabs], eax
|
|
|
|
invlpg [eax]
|
|
|
|
|
|
|
|
mov byte [0x500], 0xCD
|
|
|
|
mov byte [0x501], 0x13
|
|
|
|
mov byte [0x502], 0xF4
|
|
|
|
mov byte [0x503], 0xCD
|
|
|
|
mov byte [0x504], 0x10
|
|
|
|
mov byte [0x505], 0xF4
|
|
|
|
|
2015-12-30 18:04:32 +01:00
|
|
|
mov eax, 0x98000+PG_UWR
|
|
|
|
mov edi, page_tabs+0x98*4
|
2014-09-18 09:58:56 +02:00
|
|
|
mov edx, 0x1000
|
2015-12-30 18:04:32 +01:00
|
|
|
mov ecx, 8
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
stosd
|
2014-09-18 09:58:56 +02:00
|
|
|
add eax, edx
|
2011-10-14 23:38:50 +02:00
|
|
|
loop @b
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
; addresses 0xC0000 - 0xFFFFF - BIOS code (shared between all machines!)
|
|
|
|
; physical address = 0xC0000
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2015-01-06 15:53:54 +01:00
|
|
|
mov eax, 0xC0000+PG_UWR
|
2014-09-18 09:58:56 +02:00
|
|
|
mov edi, page_tabs+0xC0*4
|
|
|
|
mov ecx, 64
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
2014-09-18 09:58:56 +02:00
|
|
|
stosd
|
|
|
|
add eax, edx
|
|
|
|
loop @b
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [sys_proc + PROC.pdt_0_phys]
|
2016-03-13 07:08:07 +01:00
|
|
|
mov cr3, eax
|
2014-09-18 09:58:56 +02:00
|
|
|
popfd
|
|
|
|
|
|
|
|
pop edi
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
mov eax, ebx
|
|
|
|
ret
|
|
|
|
.fail2:
|
|
|
|
mov eax, ebx
|
|
|
|
call free
|
|
|
|
.fail:
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
2014-09-18 09:58:56 +02:00
|
|
|
;not used
|
2011-10-14 23:38:50 +02:00
|
|
|
; Destroy V86 machine
|
|
|
|
; in: eax = handle
|
|
|
|
; out: nothing
|
|
|
|
; destroys: eax, ebx, ecx, edx (due to free)
|
2014-09-18 09:58:56 +02:00
|
|
|
;v86_destroy:
|
|
|
|
; push eax
|
|
|
|
; stdcall kernel_free, [eax+V86_machine.pagedir]
|
|
|
|
; pop eax
|
|
|
|
; jmp free
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
; Translate V86-address to linear address
|
|
|
|
; in: eax=V86 address
|
|
|
|
; esi=handle
|
|
|
|
; out: eax=linear address
|
|
|
|
; destroys: nothing
|
|
|
|
v86_get_lin_addr:
|
|
|
|
push ecx edx
|
|
|
|
mov ecx, eax
|
|
|
|
shr ecx, 12
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edx, [page_tabs + ecx*4]
|
2011-10-14 23:38:50 +02:00
|
|
|
and eax, 0xFFF
|
2014-09-18 09:58:56 +02:00
|
|
|
and edx, 0xFFFFF000
|
|
|
|
or eax, edx
|
2011-10-14 23:38:50 +02:00
|
|
|
pop edx ecx
|
|
|
|
ret
|
|
|
|
|
2014-09-18 09:58:56 +02:00
|
|
|
;not used
|
2011-10-14 23:38:50 +02:00
|
|
|
; Sets linear address for V86-page
|
|
|
|
; in: eax=linear address (must be page-aligned)
|
|
|
|
; ecx=V86 page (NOT address!)
|
|
|
|
; esi=handle
|
|
|
|
; out: nothing
|
|
|
|
; destroys: nothing
|
2014-09-18 09:58:56 +02:00
|
|
|
;v86_set_page:
|
|
|
|
; push eax ebx
|
|
|
|
; mov ebx, [esi+V86_machine.pagedir]
|
|
|
|
; mov [ebx+ecx*4+0x1800], eax
|
|
|
|
; call get_pg_addr
|
|
|
|
; or al, 111b
|
|
|
|
; mov [ebx+ecx*4+0x1000], eax
|
|
|
|
; pop ebx eax
|
|
|
|
; ret
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
; Allocate memory in V86 machine
|
|
|
|
; in: eax=size (in bytes)
|
|
|
|
; esi=handle
|
|
|
|
; out: eax=V86 address, para-aligned (0x10 multiple)
|
|
|
|
; destroys: nothing
|
2013-05-28 00:16:00 +02:00
|
|
|
; недописана!!!
|
2011-10-14 23:38:50 +02:00
|
|
|
;v86_alloc:
|
|
|
|
; push ebx ecx edx edi
|
|
|
|
; lea ebx, [esi+V86_machine.mutex]
|
|
|
|
; call wait_mutex
|
|
|
|
; add eax, 0x1F
|
|
|
|
; shr eax, 4
|
|
|
|
; mov ebx, 0x1000 ; start with address 0x1000 (second page)
|
|
|
|
; mov edi, [esi+V86_machine.tables]
|
|
|
|
;.l:
|
|
|
|
; mov ecx, ebx
|
|
|
|
; shr ecx, 12
|
|
|
|
; mov edx, [edi+0x1000+ecx*4] ; get linear address
|
|
|
|
; test edx, edx ; page allocated?
|
|
|
|
; jz .unalloc
|
|
|
|
; mov ecx, ebx
|
|
|
|
; and ecx, 0xFFF
|
|
|
|
; add edx, ecx
|
|
|
|
; cmp dword [edx], 0 ; free block?
|
|
|
|
; jnz .n
|
|
|
|
; cmp dword [edx+4],
|
|
|
|
; and [esi+V86_machine.mutex], 0
|
|
|
|
; pop edi edx ecx ebx
|
|
|
|
; ret
|
|
|
|
|
|
|
|
uglobal
|
|
|
|
sys_v86_machine dd ?
|
|
|
|
endg
|
|
|
|
|
|
|
|
; Called from kernel.asm at first stages of loading
|
|
|
|
; Initialize system V86 machine (used to simulate BIOS int 13h)
|
|
|
|
init_sys_v86:
|
|
|
|
call v86_create
|
|
|
|
mov [sys_v86_machine], eax
|
|
|
|
test eax, eax
|
|
|
|
jz .ret
|
|
|
|
mov esi, eax
|
|
|
|
if ~DEBUG_SHOW_IO
|
|
|
|
; allow access to all ports
|
2022-02-12 18:27:41 +01:00
|
|
|
mov ecx, [esi + V86_machine.iopm]
|
2011-10-14 23:38:50 +02:00
|
|
|
xor eax, eax
|
|
|
|
mov edi, ecx
|
|
|
|
mov ecx, 10000h/8/4
|
|
|
|
rep stosd
|
|
|
|
end if
|
|
|
|
.ret:
|
|
|
|
ret
|
|
|
|
|
2012-02-23 19:52:13 +01:00
|
|
|
struct v86_regs
|
2011-10-14 23:38:50 +02:00
|
|
|
; don't change the order, it is important
|
2012-02-23 19:52:13 +01:00
|
|
|
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 ?
|
|
|
|
ends
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
; Run V86 machine
|
|
|
|
; in: ebx -> registers for V86 (two structures: in and out)
|
|
|
|
; esi = handle
|
|
|
|
; ecx = expected end address (CS:IP)
|
|
|
|
; edx = IRQ to hook or -1 if not required
|
|
|
|
; out: structure pointed to by ebx is filled with new values
|
|
|
|
; eax = 1 - exception has occured, cl contains code
|
|
|
|
; eax = 2 - access to disabled i/o port, ecx contains port address
|
|
|
|
; eax = 3 - IRQ is already hooked by another VM
|
|
|
|
; destroys: nothing
|
|
|
|
v86_start:
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
pushad
|
|
|
|
|
|
|
|
cli
|
|
|
|
|
2014-09-18 09:58:56 +02:00
|
|
|
mov ecx, [current_slot]
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
push dword [ecx + APPDATA.io_map]
|
|
|
|
push dword [ecx + APPDATA.io_map+4]
|
|
|
|
push [ecx + APPDATA.process]
|
|
|
|
push [ecx + APPDATA.saved_esp0]
|
|
|
|
mov [ecx + APPDATA.saved_esp0], esp
|
2014-09-18 09:58:56 +02:00
|
|
|
mov [tss._esp0], esp
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [esi + V86_machine.iopm]
|
2011-10-14 23:38:50 +02:00
|
|
|
call get_pg_addr
|
|
|
|
inc eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov dword [ecx + APPDATA.io_map], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
mov dword [page_tabs + (tss._io_map_0 shr 10)], eax
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [esi + V86_machine.iopm]
|
2011-10-14 23:38:50 +02:00
|
|
|
add eax, 0x1000
|
2014-09-18 09:58:56 +02:00
|
|
|
call get_pg_addr
|
|
|
|
inc eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov dword [ecx + APPDATA.io_map + 4], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
mov dword [page_tabs + (tss._io_map_1 shr 10)], eax
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [esi + V86_machine.process]
|
|
|
|
mov [ecx + APPDATA.process], eax
|
2014-09-18 09:58:56 +02:00
|
|
|
mov [current_process], eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [eax + PROC.pdt_0_phys]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov cr3, eax
|
|
|
|
|
|
|
|
; We do not enable interrupts, because V86 IRQ redirector assumes that
|
|
|
|
; machine is running
|
|
|
|
; They will be enabled by IRET.
|
|
|
|
; sti
|
|
|
|
|
|
|
|
mov eax, esi
|
2012-02-23 19:52:13 +01:00
|
|
|
sub esp, sizeof.v86_regs
|
2011-10-14 23:38:50 +02:00
|
|
|
mov esi, ebx
|
|
|
|
mov edi, esp
|
2012-02-23 19:52:13 +01:00
|
|
|
mov ecx, sizeof.v86_regs/4
|
2011-10-14 23:38:50 +02:00
|
|
|
rep movsd
|
|
|
|
|
|
|
|
cmp edx, -1
|
|
|
|
jz .noirqhook
|
|
|
|
uglobal
|
|
|
|
v86_irqhooks rd IRQ_RESERVED * 2
|
|
|
|
endg
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp [v86_irqhooks + edx*8], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
jz @f
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp [v86_irqhooks + edx*8], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
jz @f
|
|
|
|
mov esi, v86_irqerr
|
|
|
|
call sys_msg_board_str
|
2022-02-12 18:27:41 +01:00
|
|
|
inc [v86_irqhooks + edx*8 + 4]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov eax, 3
|
|
|
|
jmp v86_exc_c.exit
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [v86_irqhooks + edx*8], eax
|
|
|
|
inc [v86_irqhooks + edx*8 + 4]
|
2011-10-14 23:38:50 +02:00
|
|
|
.noirqhook:
|
|
|
|
|
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
|
|
|
|
; It is only possible to leave virtual-8086 mode by faulting to
|
|
|
|
; a protected-mode interrupt handler (typically the general-protection
|
|
|
|
; exception handler, which in turn calls the virtual 8086-mode monitor).
|
|
|
|
|
|
|
|
iglobal
|
|
|
|
v86_exc_str1 db 'V86 : unexpected exception ',0
|
|
|
|
v86_exc_str2 db ' at ',0
|
|
|
|
v86_exc_str3 db ':',0
|
|
|
|
v86_exc_str4 db 13,10,'V86 : faulted code:',0
|
|
|
|
v86_exc_str5 db ' (unavailable)',0
|
|
|
|
v86_newline db 13,10,0
|
|
|
|
v86_io_str1 db 'V86 : access to disabled i/o port ',0
|
|
|
|
v86_io_byte db ' (byte)',13,10,0
|
|
|
|
v86_io_word db ' (word)',13,10,0
|
|
|
|
v86_io_dword db ' (dword)',13,10,0
|
|
|
|
v86_irqerr db 'V86 : IRQ already hooked',13,10,0
|
|
|
|
endg
|
|
|
|
|
|
|
|
v86_exc_c:
|
|
|
|
; Did we all that we have wanted to do?
|
|
|
|
cmp bl, 1
|
|
|
|
jne @f
|
|
|
|
xor eax, eax
|
|
|
|
mov dr6, eax
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [esp + sizeof.v86_regs + 10h+18h]
|
|
|
|
cmp word [esp + v86_regs.eip], ax
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz @f
|
|
|
|
shr eax, 16
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.cs], ax
|
2011-10-14 23:38:50 +02:00
|
|
|
jz .done
|
|
|
|
@@:
|
|
|
|
; Various system events, which must be handled, result in #GP
|
|
|
|
cmp bl, 13
|
|
|
|
jnz .nogp
|
|
|
|
; If faulted EIP exceeds 0xFFFF, we have #GP and it is an error
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.eip+2], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .nogp
|
|
|
|
; Otherwise we can safely access byte at CS:IP
|
|
|
|
; (because it is #GP, not #PF handler)
|
2020-07-16 15:51:29 +02:00
|
|
|
; If we could get an exception just because of reading code bytes,
|
|
|
|
; we would have got it already and it wouldn't be #GP
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx esi, word [esp + v86_regs.cs]
|
2011-10-14 23:38:50 +02:00
|
|
|
shl esi, 4
|
2022-02-12 18:27:41 +01:00
|
|
|
add esi, [esp + v86_regs.eip]
|
2011-10-14 23:38:50 +02:00
|
|
|
lodsb
|
|
|
|
cmp al, 0xCD ; int xx command = CD xx
|
|
|
|
jz .handle_int
|
|
|
|
cmp al, 0xCF
|
|
|
|
jz .handle_iret
|
|
|
|
cmp al, 0xF3
|
|
|
|
jz .handle_rep
|
|
|
|
cmp al, 0xEC
|
|
|
|
jz .handle_in
|
|
|
|
cmp al, 0xED
|
|
|
|
jz .handle_in_word
|
|
|
|
cmp al, 0xEE
|
|
|
|
jz .handle_out
|
|
|
|
cmp al, 0xEF
|
|
|
|
jz .handle_out_word
|
|
|
|
cmp al, 0xE4
|
|
|
|
jz .handle_in_imm
|
|
|
|
cmp al, 0xE6
|
|
|
|
jz .handle_out_imm
|
|
|
|
cmp al, 0x9C
|
|
|
|
jz .handle_pushf
|
|
|
|
cmp al, 0x9D
|
|
|
|
jz .handle_popf
|
|
|
|
cmp al, 0xFA
|
|
|
|
jz .handle_cli
|
|
|
|
cmp al, 0xFB
|
|
|
|
jz .handle_sti
|
|
|
|
cmp al, 0x66
|
|
|
|
jz .handle_66
|
|
|
|
jmp .nogp
|
|
|
|
.handle_int:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.eip], 0xFFFF
|
2011-10-14 23:38:50 +02:00
|
|
|
jae .nogp
|
|
|
|
xor eax, eax
|
|
|
|
lodsb
|
|
|
|
; call sys_msg_board_byte
|
|
|
|
; simulate INT command
|
|
|
|
; N.B. It is possible that some checks need to be corrected,
|
|
|
|
; but at least in case of normal execution the code works.
|
|
|
|
.simulate_int:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.esp], 6
|
2011-10-14 23:38:50 +02:00
|
|
|
jae @f
|
|
|
|
mov bl, 12 ; #SS exception
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx edx, word [esp + v86_regs.ss]
|
2011-10-14 23:38:50 +02:00
|
|
|
shl edx, 4
|
|
|
|
push eax
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx eax, word [esp + 4 + v86_regs.esp]
|
2011-10-14 23:38:50 +02:00
|
|
|
sub eax, 6
|
|
|
|
add edx, eax
|
|
|
|
mov eax, edx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [esp + 4 + sizeof.v86_regs + 10h+4]
|
2011-10-14 23:38:50 +02:00
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14 ; #PF exception
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
lea eax, [edx+5]
|
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14 ; #PF exception
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
sub word [esp+4+v86_regs.esp], 6
|
|
|
|
mov eax, [esp+4+v86_regs.eip]
|
|
|
|
cmp byte [esp+1], 0
|
|
|
|
jnz @f
|
|
|
|
inc eax
|
|
|
|
inc eax
|
|
|
|
@@:
|
|
|
|
mov word [edx], ax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [esp + 4 + v86_regs.cs]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov word [edx+2], ax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [esp + 4 + v86_regs.eflags]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov word [edx+4], ax
|
|
|
|
pop eax
|
|
|
|
mov ah, 0
|
|
|
|
mov cx, [eax*4]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov word [esp + v86_regs.eip], cx
|
2011-10-14 23:38:50 +02:00
|
|
|
mov cx, [eax*4+2]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov word [esp + v86_regs.cs], cx
|
2011-10-14 23:38:50 +02:00
|
|
|
; note that interrupts will be disabled globally at IRET
|
2022-02-12 18:27:41 +01:00
|
|
|
and byte [esp + v86_regs.eflags+1], not 3 ; clear IF and TF flags
|
2011-10-14 23:38:50 +02:00
|
|
|
; continue V86 execution
|
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
.handle_iret:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.esp], 0x10000 - 6
|
2011-10-14 23:38:50 +02:00
|
|
|
jbe @f
|
|
|
|
mov bl, 12
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx edx, word [esp + v86_regs.ss]
|
2011-10-14 23:38:50 +02:00
|
|
|
shl edx, 4
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx eax, word [esp + v86_regs.esp]
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, eax
|
|
|
|
mov eax, edx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [esp + sizeof.v86_regs + 10h+4]
|
2011-10-14 23:38:50 +02:00
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
lea eax, [edx+5]
|
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
mov ax, [edx]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov word [esp + v86_regs.eip], ax
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ax, [edx+2]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov word [esp + v86_regs.cs], ax
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ax, [edx+4]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov word [esp + v86_regs.eflags], ax
|
|
|
|
add word [esp + v86_regs.esp], 6
|
2011-10-14 23:38:50 +02:00
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
.handle_pushf:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.esp], 1
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz @f
|
|
|
|
mov bl, 12
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx edx, word [esp + v86_regs.ss]
|
2011-10-14 23:38:50 +02:00
|
|
|
shl edx, 4
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [esp + v86_regs.esp]
|
2011-10-14 23:38:50 +02:00
|
|
|
sub eax, 2
|
|
|
|
movzx eax, ax
|
|
|
|
add edx, eax
|
|
|
|
mov eax, edx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [esp + sizeof.v86_regs + 10h+4]
|
2011-10-14 23:38:50 +02:00
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14 ; #PF exception
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
lea eax, [edx+1]
|
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
sub word [esp + v86_regs.esp], 2
|
|
|
|
mov eax, [esp + v86_regs.eflags]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [edx], ax
|
2022-02-12 18:27:41 +01:00
|
|
|
inc word [esp + v86_regs.eip]
|
2011-10-14 23:38:50 +02:00
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
.handle_pushfd:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.esp], 4
|
2011-10-14 23:38:50 +02:00
|
|
|
jae @f
|
|
|
|
mov bl, 12 ; #SS exception
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx edx, word [esp + v86_regs.ss]
|
2011-10-14 23:38:50 +02:00
|
|
|
shl edx, 4
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx eax, word [esp + v86_regs.esp]
|
2011-10-14 23:38:50 +02:00
|
|
|
sub eax, 4
|
|
|
|
add edx, eax
|
|
|
|
mov eax, edx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [esp + sizeof.v86_regs + 10h+4]
|
2011-10-14 23:38:50 +02:00
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14 ; #PF exception
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
lea eax, [edx+3]
|
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14 ; #PF exception
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
sub word [esp + v86_regs.esp], 4
|
|
|
|
movzx eax, word [esp + v86_regs.eflags]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [edx], eax
|
2022-02-12 18:27:41 +01:00
|
|
|
add word [esp + v86_regs.eip], 2
|
2011-10-14 23:38:50 +02:00
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
.handle_popf:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.esp], 0xFFFF
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz @f
|
|
|
|
mov bl, 12
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx edx, word [esp + v86_regs.ss]
|
2011-10-14 23:38:50 +02:00
|
|
|
shl edx, 4
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx eax, word [esp + v86_regs.esp]
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, eax
|
|
|
|
mov eax, edx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [esp + sizeof.v86_regs+10h+4]
|
2011-10-14 23:38:50 +02:00
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14 ; #PF exception
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
lea eax, [edx+1]
|
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
mov ax, [edx]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov word [esp + v86_regs.eflags], ax
|
|
|
|
add word [esp + v86_regs.esp], 2
|
|
|
|
inc word [esp + v86_regs.eip]
|
2011-10-14 23:38:50 +02:00
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
.handle_popfd:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.esp], 0x10000 - 4
|
2011-10-14 23:38:50 +02:00
|
|
|
jbe @f
|
|
|
|
mov bl, 12
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx edx, word [esp + v86_regs.ss]
|
2011-10-14 23:38:50 +02:00
|
|
|
shl edx, 4
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx eax, word [esp + v86_regs.esp]
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, eax
|
|
|
|
mov eax, edx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [esp + sizeof.v86_regs + 10h+4]
|
2011-10-14 23:38:50 +02:00
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
lea eax, [edx+3]
|
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jae @f
|
|
|
|
mov bl, 14
|
|
|
|
jmp .nogp
|
|
|
|
@@:
|
|
|
|
mov eax, [edx]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov word [esp + v86_regs.eflags], ax
|
|
|
|
add word [esp + v86_regs.esp], 4
|
|
|
|
add word [esp + v86_regs.eip], 2
|
2011-10-14 23:38:50 +02:00
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
.handle_cli:
|
2022-02-12 18:27:41 +01:00
|
|
|
and byte [esp + v86_regs.eflags+1], not 2
|
|
|
|
inc word [esp + v86_regs.eip]
|
2011-10-14 23:38:50 +02:00
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
.handle_sti:
|
2022-02-12 18:27:41 +01:00
|
|
|
or byte [esp + v86_regs.eflags+1], 2
|
|
|
|
inc word [esp + v86_regs.eip]
|
2011-10-14 23:38:50 +02:00
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
.handle_rep:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.eip], 0xFFFF
|
2011-10-14 23:38:50 +02:00
|
|
|
jae .nogp
|
|
|
|
lodsb
|
|
|
|
cmp al, 6Eh
|
|
|
|
jz .handle_rep_outsb
|
|
|
|
jmp .nogp
|
|
|
|
.handle_rep_outsb:
|
|
|
|
.handle_in:
|
|
|
|
.handle_out:
|
|
|
|
.invalid_io_byte:
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx ebx, word [esp + v86_regs.edx]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ecx, 1
|
|
|
|
jmp .invalid_io
|
|
|
|
.handle_in_imm:
|
|
|
|
.handle_out_imm:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.eip], 0xFFFF
|
2011-10-14 23:38:50 +02:00
|
|
|
jae .nogp
|
|
|
|
lodsb
|
|
|
|
movzx ebx, al
|
|
|
|
mov ecx, 1
|
|
|
|
jmp .invalid_io
|
|
|
|
.handle_66:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp word [esp + v86_regs.eip], 0xFFFF
|
2011-10-14 23:38:50 +02:00
|
|
|
jae .nogp
|
|
|
|
lodsb
|
|
|
|
cmp al, 0x9C
|
|
|
|
jz .handle_pushfd
|
|
|
|
cmp al, 0x9D
|
|
|
|
jz .handle_popfd
|
|
|
|
cmp al, 0xEF
|
|
|
|
jz .handle_out_dword
|
|
|
|
cmp al, 0xED
|
|
|
|
jz .handle_in_dword
|
|
|
|
jmp .nogp
|
|
|
|
.handle_in_word:
|
|
|
|
.handle_out_word:
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx ebx, word [esp + v86_regs.edx]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ecx, 2
|
|
|
|
jmp .invalid_io
|
|
|
|
.handle_in_dword:
|
|
|
|
.handle_out_dword:
|
|
|
|
.invalid_io_dword:
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx ebx, word [esp + v86_regs.edx]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ecx, 4
|
|
|
|
.invalid_io:
|
|
|
|
mov esi, v86_io_str1
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov eax, ebx
|
|
|
|
call sys_msg_board_dword
|
|
|
|
mov esi, v86_io_byte
|
|
|
|
cmp ecx, 1
|
|
|
|
jz @f
|
|
|
|
mov esi, v86_io_word
|
|
|
|
cmp ecx, 2
|
|
|
|
jz @f
|
|
|
|
mov esi, v86_io_dword
|
|
|
|
@@:
|
|
|
|
call sys_msg_board_str
|
|
|
|
if DEBUG_SHOW_IO
|
|
|
|
mov edx, ebx
|
|
|
|
mov ebx, 200
|
|
|
|
call delay_hs
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [esp + v86_regs.size + 10h+4]
|
|
|
|
mov eax, [esi + V86_machine.iopm]
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
btr [eax], edx
|
|
|
|
inc edx
|
|
|
|
loop @b
|
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
else
|
|
|
|
mov eax, 2
|
|
|
|
jmp .exit
|
|
|
|
end if
|
|
|
|
.nogp:
|
|
|
|
|
|
|
|
mov esi, v86_exc_str1
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov al, bl
|
|
|
|
call sys_msg_board_byte
|
|
|
|
mov esi, v86_exc_str2
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov ax, [esp+32+4]
|
|
|
|
call sys_msg_board_word
|
|
|
|
mov esi, v86_exc_str3
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov ax, [esp+32]
|
|
|
|
call sys_msg_board_word
|
|
|
|
mov esi, v86_exc_str4
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov ecx, 8
|
|
|
|
movzx edx, word [esp+32+4]
|
|
|
|
shl edx, 4
|
|
|
|
add edx, [esp+32]
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [esp+sizeof.v86_regs + 10h+4]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov eax, edx
|
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jb .nopage
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, v86_exc_str3 - 2
|
2011-10-14 23:38:50 +02:00
|
|
|
call sys_msg_board_str
|
|
|
|
mov al, [edx]
|
|
|
|
call sys_msg_board_byte
|
|
|
|
inc edx
|
|
|
|
loop @b
|
|
|
|
jmp @f
|
|
|
|
.nopage:
|
|
|
|
mov esi, v86_exc_str5
|
|
|
|
call sys_msg_board_str
|
|
|
|
@@:
|
|
|
|
mov esi, v86_newline
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov eax, 1
|
|
|
|
jmp .exit
|
|
|
|
|
|
|
|
.done:
|
|
|
|
xor eax, eax
|
|
|
|
|
|
|
|
.exit:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [esp + sizeof.v86_regs + 10h+1Ch], eax
|
|
|
|
mov [esp + sizeof.v86_regs + 10h+18h], ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edx, [esp + sizeof.v86_regs + 10h+14h]
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp edx, -1
|
|
|
|
jz @f
|
2022-02-12 18:27:41 +01:00
|
|
|
dec [v86_irqhooks + edx*8 + 4]
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz @f
|
2022-02-12 18:27:41 +01:00
|
|
|
and [v86_irqhooks + edx*8], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
|
|
|
|
mov esi, esp
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edi, [esi + sizeof.v86_regs + 10h+10h]
|
2012-02-23 19:52:13 +01:00
|
|
|
add edi, sizeof.v86_regs
|
|
|
|
mov ecx, sizeof.v86_regs/4
|
2011-10-14 23:38:50 +02:00
|
|
|
rep movsd
|
|
|
|
mov esp, esi
|
|
|
|
|
|
|
|
cli
|
2014-09-18 09:58:56 +02:00
|
|
|
mov ecx, [current_slot]
|
2011-10-14 23:38:50 +02:00
|
|
|
pop eax
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ecx + APPDATA.saved_esp0], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [tss._esp0], eax
|
|
|
|
pop eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ecx + APPDATA.process], eax
|
2014-09-18 09:58:56 +02:00
|
|
|
mov [current_process], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
pop ebx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov dword [ecx + APPDATA.io_map+4], ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
mov dword [page_tabs + (tss._io_map_1 shr 10)], ebx
|
|
|
|
pop ebx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov dword [ecx + APPDATA.io_map], ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
mov dword [page_tabs + (tss._io_map_0 shr 10)], ebx
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [eax+PROC.pdt_0_phys]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov cr3, eax
|
|
|
|
sti
|
|
|
|
|
|
|
|
popad
|
|
|
|
ret
|
|
|
|
|
|
|
|
;my05:
|
|
|
|
; mov dx, 30C2h
|
|
|
|
; mov cx, 4
|
|
|
|
;.0:
|
|
|
|
; in al, dx
|
|
|
|
; cmp al, 0FFh
|
|
|
|
; jz @f
|
|
|
|
; test al, 4
|
|
|
|
; jnz .1
|
|
|
|
;@@:
|
|
|
|
; add dx, 8
|
|
|
|
; in al, dx
|
|
|
|
; cmp al, 0FFh
|
|
|
|
; jz @f
|
|
|
|
; test al, 4
|
|
|
|
; jnz .1
|
|
|
|
;@@:
|
|
|
|
; loop .0
|
|
|
|
; ret
|
|
|
|
;.1:
|
|
|
|
; or al, 84h
|
|
|
|
; out dx, al
|
|
|
|
;.2:
|
|
|
|
; mov dx, 30F7h
|
|
|
|
; in al, dx
|
|
|
|
; mov byte [BOOT_VAR + 48Eh], 0FFh
|
|
|
|
; ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
v86_irq:
|
|
|
|
; push irq/pushad/jmp v86_irq
|
|
|
|
; ebp = irq
|
2022-02-12 18:27:41 +01:00
|
|
|
lea esi, [esp + 1Ch]
|
2011-10-14 23:38:50 +02:00
|
|
|
lea edi, [esi+4]
|
|
|
|
mov ecx, 8
|
|
|
|
std
|
|
|
|
rep movsd
|
|
|
|
cld
|
|
|
|
mov edi, ebp
|
|
|
|
pop eax
|
|
|
|
v86_irq2:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [v86_irqhooks + edi*8] ; get VM handle
|
|
|
|
mov eax, [esi + V86_machine.process]
|
2021-06-17 11:41:16 +02:00
|
|
|
mov ecx, [current_slot_idx]
|
2022-02-12 18:27:41 +01:00
|
|
|
shl ecx, BSF sizeof.APPDATA
|
|
|
|
cmp [SLOT_BASE + ecx + APPDATA.process], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .notcurrent
|
|
|
|
lea eax, [edi+8]
|
|
|
|
cmp al, 10h
|
|
|
|
mov ah, 1
|
|
|
|
jb @f
|
|
|
|
add al, 60h
|
|
|
|
@@:
|
|
|
|
jmp v86_exc_c.simulate_int
|
|
|
|
.notcurrent:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov ebx, SLOT_BASE + sizeof.APPDATA
|
2021-06-16 12:04:10 +02:00
|
|
|
mov ecx, [thread_count]
|
2011-10-14 23:38:50 +02:00
|
|
|
.scan:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp [ebx + APPDATA.process], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .cont
|
|
|
|
push ecx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov ecx, [ebx + APPDATA.saved_esp0]
|
|
|
|
cmp word [ecx - sizeof.v86_regs + v86_regs.esp], 6
|
2011-10-14 23:38:50 +02:00
|
|
|
jb .cont2
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx edx, word [ecx - sizeof.v86_regs + v86_regs.ss]
|
2011-10-14 23:38:50 +02:00
|
|
|
shl edx, 4
|
|
|
|
push eax
|
2022-02-12 18:27:41 +01:00
|
|
|
movzx eax, word [ecx - sizeof.v86_regs + v86_regs.esp]
|
2011-10-14 23:38:50 +02:00
|
|
|
sub eax, 6
|
|
|
|
add edx, eax
|
|
|
|
mov eax, edx
|
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jb .cont3
|
|
|
|
lea eax, [edx+5]
|
|
|
|
call v86_get_lin_addr
|
|
|
|
cmp eax, 0x1000
|
|
|
|
jb .cont3
|
|
|
|
pop eax
|
|
|
|
pop ecx
|
|
|
|
jmp .found
|
|
|
|
.cont3:
|
|
|
|
pop eax
|
|
|
|
.cont2:
|
|
|
|
pop ecx
|
|
|
|
.cont:
|
2013-03-21 07:51:48 +01:00
|
|
|
add ebx, 0x100
|
2011-10-14 23:38:50 +02:00
|
|
|
loop .scan
|
|
|
|
mov ecx, edi
|
|
|
|
call irq_eoi
|
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
.found:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [eax + PROC.pdt_0_phys]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov cr3, eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov esi, [ebx + APPDATA.saved_esp0]
|
|
|
|
sub word [esi - sizeof.v86_regs + v86_regs.esp], 6
|
|
|
|
mov ecx, [esi - sizeof.v86_regs + v86_regs.eip]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov word [edx], cx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov ecx, [esi - sizeof.v86_regs + v86_regs.cs]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov word [edx+2], cx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov ecx, [esi - sizeof.v86_regs + v86_regs.eflags]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov word [edx+4], cx
|
|
|
|
lea eax, [edi+8]
|
|
|
|
cmp al, 10h
|
|
|
|
jb @f
|
|
|
|
add al, 60h
|
|
|
|
@@:
|
|
|
|
mov cx, [eax*4]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov word [esi - sizeof.v86_regs + v86_regs.eip], cx
|
2011-10-14 23:38:50 +02:00
|
|
|
mov cx, [eax*4+2]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov word [esi - sizeof.v86_regs + v86_regs.cs], cx
|
|
|
|
and byte [esi - sizeof.v86_regs + v86_regs.eflags + 1], not 3
|
2011-10-14 23:38:50 +02:00
|
|
|
call update_counters
|
|
|
|
call find_next_task.found
|
|
|
|
call do_change_task
|
|
|
|
popad
|
|
|
|
iretd
|