forked from KolibriOS/kolibrios
sys32 - concentration all (except #NM) exception handlers in ecx_c for optimization purpose
debug - moved handler to sys32::exc_c fpu - moved except_16/19 to sys32::exc_c memory - changing interface for page_fault_handler v86 - changing interface for handler v86_exc_c kernel - small optimization git-svn-id: svn://kolibrios.org@1056 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
3be0aa5c21
commit
82da211b9b
@ -10,71 +10,71 @@ $Revision$
|
|||||||
|
|
||||||
; diamond, 2006
|
; diamond, 2006
|
||||||
sys_debug_services:
|
sys_debug_services:
|
||||||
cmp eax, 9
|
cmp eax, 9
|
||||||
ja @f
|
ja @f
|
||||||
jmp dword [sys_debug_services_table+eax*4]
|
jmp dword [sys_debug_services_table+eax*4]
|
||||||
@@: ret
|
@@: ret
|
||||||
sys_debug_services_table:
|
sys_debug_services_table:
|
||||||
dd debug_set_event_data
|
dd debug_set_event_data
|
||||||
dd debug_getcontext
|
dd debug_getcontext
|
||||||
dd debug_setcontext
|
dd debug_setcontext
|
||||||
dd debug_detach
|
dd debug_detach
|
||||||
dd debug_suspend
|
dd debug_suspend
|
||||||
dd debug_resume
|
dd debug_resume
|
||||||
dd debug_read_process_memory
|
dd debug_read_process_memory
|
||||||
dd debug_write_process_memory
|
dd debug_write_process_memory
|
||||||
dd debug_terminate
|
dd debug_terminate
|
||||||
dd debug_set_drx
|
dd debug_set_drx
|
||||||
|
|
||||||
debug_set_event_data:
|
debug_set_event_data:
|
||||||
; in: ebx = pointer
|
; in: ebx = pointer
|
||||||
; destroys eax
|
; destroys eax
|
||||||
mov eax, [current_slot]
|
mov eax, [current_slot]
|
||||||
mov [eax+APPDATA.dbg_event_mem], ebx
|
mov [eax+APPDATA.dbg_event_mem], ebx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
get_debuggee_slot:
|
get_debuggee_slot:
|
||||||
; in: ebx=PID
|
; in: ebx=PID
|
||||||
; out: CF=1 if error
|
; out: CF=1 if error
|
||||||
; CF=0 and eax=slot*0x20 if ok
|
; CF=0 and eax=slot*0x20 if ok
|
||||||
; out: interrupts disabled
|
; out: interrupts disabled
|
||||||
cli
|
cli
|
||||||
mov eax, ebx
|
mov eax, ebx
|
||||||
call pid_to_slot
|
call pid_to_slot
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .ret_bad
|
jz .ret_bad
|
||||||
shl eax, 5
|
shl eax, 5
|
||||||
push ebx
|
push ebx
|
||||||
mov ebx, [CURRENT_TASK]
|
mov ebx, [CURRENT_TASK]
|
||||||
cmp [SLOT_BASE+eax*8+APPDATA.debugger_slot], ebx
|
cmp [SLOT_BASE+eax*8+APPDATA.debugger_slot], ebx
|
||||||
pop ebx
|
pop ebx
|
||||||
jnz .ret_bad
|
jnz .ret_bad
|
||||||
; clc ; automatically
|
; clc ; automatically
|
||||||
ret
|
ret
|
||||||
.ret_bad:
|
.ret_bad:
|
||||||
stc
|
stc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
debug_detach:
|
debug_detach:
|
||||||
; in: ebx=pid
|
; in: ebx=pid
|
||||||
; destroys eax,ebx
|
; destroys eax,ebx
|
||||||
call get_debuggee_slot
|
call get_debuggee_slot
|
||||||
jc .ret
|
jc .ret
|
||||||
and dword [eax*8+SLOT_BASE+APPDATA.debugger_slot], 0
|
and dword [eax*8+SLOT_BASE+APPDATA.debugger_slot], 0
|
||||||
call do_resume
|
call do_resume
|
||||||
.ret:
|
.ret:
|
||||||
sti
|
sti
|
||||||
ret
|
ret
|
||||||
|
|
||||||
debug_terminate:
|
debug_terminate:
|
||||||
; in: ebx=pid
|
; in: ebx=pid
|
||||||
call get_debuggee_slot
|
call get_debuggee_slot
|
||||||
jc debug_detach.ret
|
jc debug_detach.ret
|
||||||
mov ecx, eax
|
mov ecx, eax
|
||||||
shr ecx, 5
|
shr ecx, 5
|
||||||
push 2
|
push 2
|
||||||
pop ebx
|
pop ebx
|
||||||
jmp sys_system
|
jmp sys_system
|
||||||
|
|
||||||
debug_suspend:
|
debug_suspend:
|
||||||
; in: ebx=pid
|
; in: ebx=pid
|
||||||
@ -85,30 +85,30 @@ debug_suspend:
|
|||||||
shl eax, 5
|
shl eax, 5
|
||||||
jz .ret
|
jz .ret
|
||||||
mov bl, [CURRENT_TASK+eax+TASKDATA.state] ; process state
|
mov bl, [CURRENT_TASK+eax+TASKDATA.state] ; process state
|
||||||
test bl, bl
|
test bl, bl
|
||||||
jz .1
|
jz .1
|
||||||
cmp bl, 5
|
cmp bl, 5
|
||||||
jnz .ret
|
jnz .ret
|
||||||
mov bl, 2
|
mov bl, 2
|
||||||
.2: mov [CURRENT_TASK+eax+TASKDATA.state], bl
|
.2: mov [CURRENT_TASK+eax+TASKDATA.state], bl
|
||||||
.ret:
|
.ret:
|
||||||
sti
|
sti
|
||||||
ret
|
ret
|
||||||
.1:
|
.1:
|
||||||
inc ebx
|
inc ebx
|
||||||
jmp .2
|
jmp .2
|
||||||
|
|
||||||
do_resume:
|
do_resume:
|
||||||
mov bl, [CURRENT_TASK+eax+TASKDATA.state]
|
mov bl, [CURRENT_TASK+eax+TASKDATA.state]
|
||||||
cmp bl, 1
|
cmp bl, 1
|
||||||
jz .1
|
jz .1
|
||||||
cmp bl, 2
|
cmp bl, 2
|
||||||
jnz .ret
|
jnz .ret
|
||||||
mov bl, 5
|
mov bl, 5
|
||||||
.2: mov [CURRENT_TASK+eax+TASKDATA.state], bl
|
.2: mov [CURRENT_TASK+eax+TASKDATA.state], bl
|
||||||
.ret: ret
|
.ret: ret
|
||||||
.1: dec ebx
|
.1: dec ebx
|
||||||
jmp .2
|
jmp .2
|
||||||
|
|
||||||
debug_resume:
|
debug_resume:
|
||||||
; in: ebx=pid
|
; in: ebx=pid
|
||||||
@ -119,8 +119,8 @@ debug_resume:
|
|||||||
shl eax, 5
|
shl eax, 5
|
||||||
jz .ret
|
jz .ret
|
||||||
call do_resume
|
call do_resume
|
||||||
.ret: sti
|
.ret: sti
|
||||||
ret
|
ret
|
||||||
|
|
||||||
debug_getcontext:
|
debug_getcontext:
|
||||||
; in:
|
; in:
|
||||||
@ -128,16 +128,16 @@ debug_getcontext:
|
|||||||
; ecx=sizeof(CONTEXT)
|
; ecx=sizeof(CONTEXT)
|
||||||
; edx->CONTEXT
|
; edx->CONTEXT
|
||||||
; destroys eax,ecx,edx,esi,edi
|
; destroys eax,ecx,edx,esi,edi
|
||||||
cmp ecx, 28h
|
cmp ecx, 28h
|
||||||
jnz .ret
|
jnz .ret
|
||||||
push ebx
|
push ebx
|
||||||
mov ebx, edx
|
mov ebx, edx
|
||||||
call check_region
|
call check_region
|
||||||
pop ebx
|
pop ebx
|
||||||
dec eax
|
dec eax
|
||||||
jnz .ret
|
jnz .ret
|
||||||
call get_debuggee_slot
|
call get_debuggee_slot
|
||||||
jc .ret
|
jc .ret
|
||||||
mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack]
|
mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack]
|
||||||
lea esi, [eax+RING0_STACK_SIZE]
|
lea esi, [eax+RING0_STACK_SIZE]
|
||||||
mov edi, edx
|
mov edi, edx
|
||||||
@ -147,30 +147,30 @@ debug_getcontext:
|
|||||||
; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), pushad
|
; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), pushad
|
||||||
sub esi, 8+12+20h
|
sub esi, 8+12+20h
|
||||||
lodsd ;edi
|
lodsd ;edi
|
||||||
mov [edi+24h], eax
|
mov [edi+24h], eax
|
||||||
lodsd ;esi
|
lodsd ;esi
|
||||||
mov [edi+20h], eax
|
mov [edi+20h], eax
|
||||||
lodsd ; ebp
|
lodsd ; ebp
|
||||||
mov [edi+1Ch], eax
|
mov [edi+1Ch], eax
|
||||||
lodsd ;esp
|
lodsd ;esp
|
||||||
lodsd ;ebx
|
lodsd ;ebx
|
||||||
mov [edi+14h], eax
|
mov [edi+14h], eax
|
||||||
lodsd ;edx
|
lodsd ;edx
|
||||||
mov [edi+10h], eax
|
mov [edi+10h], eax
|
||||||
lodsd ;ecx
|
lodsd ;ecx
|
||||||
mov [edi+0Ch], eax
|
mov [edi+0Ch], eax
|
||||||
lodsd ;eax
|
lodsd ;eax
|
||||||
mov [edi+8], eax
|
mov [edi+8], eax
|
||||||
lodsd ;eip
|
lodsd ;eip
|
||||||
mov [edi], eax
|
mov [edi], eax
|
||||||
lodsd ;cs
|
lodsd ;cs
|
||||||
lodsd ;eflags
|
lodsd ;eflags
|
||||||
mov [edi+4], eax
|
mov [edi+4], eax
|
||||||
lodsd ;esp
|
lodsd ;esp
|
||||||
mov [edi+18h], eax
|
mov [edi+18h], eax
|
||||||
.ret:
|
.ret:
|
||||||
sti
|
sti
|
||||||
ret
|
ret
|
||||||
|
|
||||||
debug_setcontext:
|
debug_setcontext:
|
||||||
; in:
|
; in:
|
||||||
@ -178,120 +178,120 @@ debug_setcontext:
|
|||||||
; ecx=sizeof(CONTEXT)
|
; ecx=sizeof(CONTEXT)
|
||||||
; edx->CONTEXT
|
; edx->CONTEXT
|
||||||
; destroys eax,ecx,edx,esi,edi
|
; destroys eax,ecx,edx,esi,edi
|
||||||
cmp ecx, 28h
|
cmp ecx, 28h
|
||||||
jnz .ret
|
jnz .ret
|
||||||
push ebx
|
push ebx
|
||||||
mov ebx, edx
|
mov ebx, edx
|
||||||
call check_region
|
call check_region
|
||||||
pop ebx
|
pop ebx
|
||||||
dec eax
|
dec eax
|
||||||
jnz .ret
|
jnz .ret
|
||||||
call get_debuggee_slot
|
call get_debuggee_slot
|
||||||
jc .stiret
|
jc .stiret
|
||||||
mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack]
|
mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack]
|
||||||
lea edi, [eax+RING0_STACK_SIZE]
|
lea edi, [eax+RING0_STACK_SIZE]
|
||||||
mov esi, edx
|
mov esi, edx
|
||||||
.ring0:
|
.ring0:
|
||||||
sub edi, 8+12+20h
|
sub edi, 8+12+20h
|
||||||
mov eax, [esi+24h] ;edi
|
mov eax, [esi+24h] ;edi
|
||||||
stosd
|
stosd
|
||||||
mov eax, [esi+20h] ;esi
|
mov eax, [esi+20h] ;esi
|
||||||
stosd
|
stosd
|
||||||
mov eax, [esi+1Ch] ;ebp
|
mov eax, [esi+1Ch] ;ebp
|
||||||
stosd
|
stosd
|
||||||
scasd
|
scasd
|
||||||
mov eax, [esi+14h] ;ebx
|
mov eax, [esi+14h] ;ebx
|
||||||
stosd
|
stosd
|
||||||
mov eax, [esi+10h] ;edx
|
mov eax, [esi+10h] ;edx
|
||||||
stosd
|
stosd
|
||||||
mov eax, [esi+0Ch] ;ecx
|
mov eax, [esi+0Ch] ;ecx
|
||||||
stosd
|
stosd
|
||||||
mov eax, [esi+8] ;eax
|
mov eax, [esi+8] ;eax
|
||||||
stosd
|
stosd
|
||||||
mov eax, [esi] ;eip
|
mov eax, [esi] ;eip
|
||||||
stosd
|
stosd
|
||||||
scasd
|
scasd
|
||||||
mov eax, [esi+4] ;eflags
|
mov eax, [esi+4] ;eflags
|
||||||
stosd
|
stosd
|
||||||
mov eax, [esi+18h] ;esp
|
mov eax, [esi+18h] ;esp
|
||||||
stosd
|
stosd
|
||||||
.stiret:
|
.stiret:
|
||||||
sti
|
sti
|
||||||
.ret:
|
.ret:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
debug_set_drx:
|
debug_set_drx:
|
||||||
call get_debuggee_slot
|
call get_debuggee_slot
|
||||||
jc .errret
|
jc .errret
|
||||||
mov ebp, eax
|
mov ebp, eax
|
||||||
lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs]
|
lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs]
|
||||||
; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3
|
; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3
|
||||||
; [eax+10]=dr7
|
; [eax+10]=dr7
|
||||||
cmp edx, OS_BASE
|
cmp edx, OS_BASE
|
||||||
jae .errret
|
jae .errret
|
||||||
cmp cl, 3
|
cmp cl, 3
|
||||||
ja .errret
|
ja .errret
|
||||||
mov ebx, dr7
|
mov ebx, dr7
|
||||||
shr ebx, cl
|
shr ebx, cl
|
||||||
shr ebx, cl
|
shr ebx, cl
|
||||||
test ebx, 2 ; bit 1+2*index = G0..G3, global break enable
|
test ebx, 2 ; bit 1+2*index = G0..G3, global break enable
|
||||||
jnz .errret2
|
jnz .errret2
|
||||||
test ch, ch
|
test ch, ch
|
||||||
jns .new
|
jns .new
|
||||||
; clear breakpoint
|
; clear breakpoint
|
||||||
movzx ecx, cl
|
movzx ecx, cl
|
||||||
add ecx, ecx
|
add ecx, ecx
|
||||||
and dword [eax+ecx*2], 0 ; clear DR<i>
|
and dword [eax+ecx*2], 0 ; clear DR<i>
|
||||||
btr dword [eax+10h], ecx ; clear L<i> bit
|
btr dword [eax+10h], ecx ; clear L<i> bit
|
||||||
test byte [eax+10h], 55h
|
test byte [eax+10h], 55h
|
||||||
jnz .okret
|
jnz .okret
|
||||||
; imul eax, ebp, tss_step/32
|
; imul eax, ebp, tss_step/32
|
||||||
; and byte [eax + tss_data + TSS._trap], not 1
|
; and byte [eax + tss_data + TSS._trap], not 1
|
||||||
and [ebp*8 + SLOT_BASE+APPDATA.dbg_state], not 1
|
and [ebp*8 + SLOT_BASE+APPDATA.dbg_state], not 1
|
||||||
.okret:
|
.okret:
|
||||||
and dword [esp+36], 0
|
and dword [esp+36], 0
|
||||||
sti
|
sti
|
||||||
ret
|
ret
|
||||||
.errret:
|
.errret:
|
||||||
sti
|
sti
|
||||||
mov dword [esp+36], 1
|
mov dword [esp+36], 1
|
||||||
ret
|
ret
|
||||||
.errret2:
|
.errret2:
|
||||||
sti
|
sti
|
||||||
mov dword [esp+36], 2
|
mov dword [esp+36], 2
|
||||||
ret
|
ret
|
||||||
.new:
|
.new:
|
||||||
; add new breakpoint
|
; add new breakpoint
|
||||||
; cl=index; ch=flags; edx=address
|
; cl=index; ch=flags; edx=address
|
||||||
test ch, 0xF0
|
test ch, 0xF0
|
||||||
jnz .errret
|
jnz .errret
|
||||||
mov bl, ch
|
mov bl, ch
|
||||||
and bl, 3
|
and bl, 3
|
||||||
cmp bl, 2
|
cmp bl, 2
|
||||||
jz .errret
|
jz .errret
|
||||||
mov bl, ch
|
mov bl, ch
|
||||||
shr bl, 2
|
shr bl, 2
|
||||||
cmp bl, 2
|
cmp bl, 2
|
||||||
jz .errret
|
jz .errret
|
||||||
test dl, bl
|
test dl, bl
|
||||||
jnz .errret
|
jnz .errret
|
||||||
or byte [eax+10h+1], 3 ; set GE and LE flags
|
or byte [eax+10h+1], 3 ; set GE and LE flags
|
||||||
movzx ebx, ch
|
movzx ebx, ch
|
||||||
movzx ecx, cl
|
movzx ecx, cl
|
||||||
add ecx, ecx
|
add ecx, ecx
|
||||||
bts dword [eax+10h], ecx ; set L<i> flag
|
bts dword [eax+10h], ecx ; set L<i> flag
|
||||||
add ecx, ecx
|
add ecx, ecx
|
||||||
mov [eax+ecx], edx ; set DR<i>
|
mov [eax+ecx], edx ; set DR<i>
|
||||||
shl ebx, cl
|
shl ebx, cl
|
||||||
mov edx, 0xF
|
mov edx, 0xF
|
||||||
shl edx, cl
|
shl edx, cl
|
||||||
not edx
|
not edx
|
||||||
and [eax+10h+2], dx
|
and [eax+10h+2], dx
|
||||||
or [eax+10h+2], bx ; set R/W and LEN fields
|
or [eax+10h+2], bx ; set R/W and LEN fields
|
||||||
; imul eax, ebp, tss_step/32
|
; imul eax, ebp, tss_step/32
|
||||||
; or byte [eax + tss_data + TSS._trap], 1
|
; or byte [eax + tss_data + TSS._trap], 1
|
||||||
or [ebp*8 + SLOT_BASE+APPDATA.dbg_state], 1
|
or [ebp*8 + SLOT_BASE+APPDATA.dbg_state], 1
|
||||||
jmp .okret
|
jmp .okret
|
||||||
|
|
||||||
debug_read_process_memory:
|
debug_read_process_memory:
|
||||||
; in:
|
; in:
|
||||||
@ -301,23 +301,23 @@ debug_read_process_memory:
|
|||||||
; edx=address in debuggee
|
; edx=address in debuggee
|
||||||
; out: [esp+36]=sizeof(read)
|
; out: [esp+36]=sizeof(read)
|
||||||
; destroys all
|
; destroys all
|
||||||
push ebx
|
push ebx
|
||||||
mov ebx, esi
|
mov ebx, esi
|
||||||
call check_region
|
call check_region
|
||||||
pop ebx
|
pop ebx
|
||||||
dec eax
|
dec eax
|
||||||
jnz .err
|
jnz .err
|
||||||
call get_debuggee_slot
|
call get_debuggee_slot
|
||||||
jc .err
|
jc .err
|
||||||
shr eax, 5
|
shr eax, 5
|
||||||
mov ebx, esi
|
mov ebx, esi
|
||||||
call read_process_memory
|
call read_process_memory
|
||||||
sti
|
sti
|
||||||
mov dword [esp+36], eax
|
mov dword [esp+36], eax
|
||||||
ret
|
ret
|
||||||
.err:
|
.err:
|
||||||
or dword [esp+36], -1
|
or dword [esp+36], -1
|
||||||
ret
|
ret
|
||||||
|
|
||||||
debug_write_process_memory:
|
debug_write_process_memory:
|
||||||
; in:
|
; in:
|
||||||
@ -327,20 +327,20 @@ debug_write_process_memory:
|
|||||||
; edx=address in debuggee
|
; edx=address in debuggee
|
||||||
; out: [esp+36]=sizeof(write)
|
; out: [esp+36]=sizeof(write)
|
||||||
; destroys all
|
; destroys all
|
||||||
push ebx
|
push ebx
|
||||||
mov ebx, esi
|
mov ebx, esi
|
||||||
call check_region
|
call check_region
|
||||||
pop ebx
|
pop ebx
|
||||||
dec eax
|
dec eax
|
||||||
jnz debug_read_process_memory.err
|
jnz debug_read_process_memory.err
|
||||||
call get_debuggee_slot
|
call get_debuggee_slot
|
||||||
jc debug_read_process_memory.err
|
jc debug_read_process_memory.err
|
||||||
shr eax, 5
|
shr eax, 5
|
||||||
mov ebx, esi
|
mov ebx, esi
|
||||||
call write_process_memory
|
call write_process_memory
|
||||||
sti
|
sti
|
||||||
mov [esp+36], eax
|
mov [esp+36], eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
debugger_notify:
|
debugger_notify:
|
||||||
; in: eax=debugger slot
|
; in: eax=debugger slot
|
||||||
@ -349,127 +349,96 @@ debugger_notify:
|
|||||||
; interrupts must be disabled!
|
; interrupts must be disabled!
|
||||||
; destroys all general registers
|
; destroys all general registers
|
||||||
; interrupts remain disabled
|
; interrupts remain disabled
|
||||||
xchg ebp, eax
|
xchg ebp, eax
|
||||||
mov edi, [timer_ticks]
|
mov edi, [timer_ticks]
|
||||||
add edi, 500 ; 5 sec timeout
|
add edi, 500 ; 5 sec timeout
|
||||||
.1:
|
.1:
|
||||||
mov eax, ebp
|
mov eax, ebp
|
||||||
shl eax, 8
|
shl eax, 8
|
||||||
mov edx, [SLOT_BASE+eax+APPDATA.dbg_event_mem]
|
mov edx, [SLOT_BASE+eax+APPDATA.dbg_event_mem]
|
||||||
test edx, edx
|
test edx, edx
|
||||||
jz .ret
|
jz .ret
|
||||||
; read buffer header
|
; read buffer header
|
||||||
push ecx
|
push ecx
|
||||||
push eax
|
push eax
|
||||||
push eax
|
push eax
|
||||||
mov eax, ebp
|
mov eax, ebp
|
||||||
mov ebx, esp
|
mov ebx, esp
|
||||||
mov ecx, 8
|
mov ecx, 8
|
||||||
call read_process_memory
|
call read_process_memory
|
||||||
cmp eax, ecx
|
cmp eax, ecx
|
||||||
jz @f
|
jz @f
|
||||||
add esp, 12
|
add esp, 12
|
||||||
jmp .ret
|
jmp .ret
|
||||||
@@:
|
@@:
|
||||||
cmp dword [ebx], 0
|
cmp dword [ebx], 0
|
||||||
jg @f
|
jg @f
|
||||||
.2:
|
.2:
|
||||||
pop ecx
|
pop ecx
|
||||||
pop ecx
|
pop ecx
|
||||||
pop ecx
|
pop ecx
|
||||||
cmp dword [CURRENT_TASK], 1
|
cmp dword [CURRENT_TASK], 1
|
||||||
jnz .notos
|
jnz .notos
|
||||||
cmp [timer_ticks], edi
|
cmp [timer_ticks], edi
|
||||||
jae .ret
|
jae .ret
|
||||||
.notos:
|
.notos:
|
||||||
sti
|
sti
|
||||||
call change_task
|
call change_task
|
||||||
cli
|
cli
|
||||||
jmp .1
|
jmp .1
|
||||||
@@:
|
@@:
|
||||||
mov ecx, [ebx+8]
|
mov ecx, [ebx+8]
|
||||||
add ecx, [ebx+4]
|
add ecx, [ebx+4]
|
||||||
cmp ecx, [ebx]
|
cmp ecx, [ebx]
|
||||||
ja .2
|
ja .2
|
||||||
; advance buffer position
|
; advance buffer position
|
||||||
push ecx
|
push ecx
|
||||||
mov ecx, 4
|
mov ecx, 4
|
||||||
sub ebx, ecx
|
sub ebx, ecx
|
||||||
mov eax, ebp
|
mov eax, ebp
|
||||||
add edx, ecx
|
add edx, ecx
|
||||||
call write_process_memory
|
call write_process_memory
|
||||||
pop eax
|
pop eax
|
||||||
; write message
|
; write message
|
||||||
mov eax, ebp
|
mov eax, ebp
|
||||||
add edx, ecx
|
add edx, ecx
|
||||||
add edx, [ebx+8]
|
add edx, [ebx+8]
|
||||||
add ebx, 20
|
add ebx, 20
|
||||||
pop ecx
|
pop ecx
|
||||||
pop ecx
|
pop ecx
|
||||||
pop ecx
|
pop ecx
|
||||||
call write_process_memory
|
call write_process_memory
|
||||||
; new debug event
|
; new debug event
|
||||||
mov eax, ebp
|
mov eax, ebp
|
||||||
shl eax, 8
|
shl eax, 8
|
||||||
or byte [SLOT_BASE+eax+APPDATA.event_mask+1], 1 ; set flag 100h
|
or byte [SLOT_BASE+eax+APPDATA.event_mask+1], 1 ; set flag 100h
|
||||||
.ret:
|
.ret:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
debug_exc:
|
debug_ex:
|
||||||
test byte [esp+8+2], 2
|
|
||||||
jnz v86_debug_exc
|
|
||||||
; int 1 = #DB
|
|
||||||
save_ring3_context
|
|
||||||
cld
|
|
||||||
mov ax, app_data ;os_data
|
|
||||||
mov ds, ax
|
|
||||||
mov es, ax
|
|
||||||
mov eax, dr6
|
|
||||||
push eax
|
|
||||||
xor eax, eax
|
|
||||||
mov dr6, eax
|
|
||||||
; test if debugging
|
|
||||||
cli
|
|
||||||
mov eax, [current_slot]
|
|
||||||
mov eax, [eax+APPDATA.debugger_slot]
|
|
||||||
test eax, eax
|
|
||||||
jnz .debug
|
|
||||||
sti
|
|
||||||
; not debuggee => say error and terminate
|
|
||||||
add esp, 0x20+4
|
|
||||||
mov [error_interrupt], 1
|
|
||||||
call show_error_parameters
|
|
||||||
mov edx, [TASK_BASE]
|
|
||||||
mov byte [edx+TASKDATA.state], 4
|
|
||||||
jmp change_task
|
|
||||||
.debug:
|
|
||||||
; we are debugged process, notify debugger and suspend ourself
|
; we are debugged process, notify debugger and suspend ourself
|
||||||
; eax=debugger PID
|
; eax=debugger PID
|
||||||
pop edx
|
mov edx, dr6 ; debug_message data=DR6_image
|
||||||
mov ebx, dr7
|
xor ebx, ebx
|
||||||
mov cl, not 1
|
mov dr6, ebx
|
||||||
.l1:
|
mov ebx, dr7
|
||||||
test bl, 1
|
mov cl, not 8
|
||||||
jnz @f
|
.l1: shl bl,2
|
||||||
and dl, cl
|
jc @f
|
||||||
@@:
|
and dl, cl
|
||||||
shr ebx, 2
|
@@: sar cl,1
|
||||||
add cl, cl
|
jc .l1
|
||||||
inc ecx
|
mov ecx,3 ; debug_message code=debug_exception
|
||||||
cmp cl, not 10h
|
.notify:
|
||||||
jnz .l1
|
push edx ; debug_message data
|
||||||
push edx ; DR6 image
|
mov ebx, [TASK_BASE]
|
||||||
mov ecx, [TASK_BASE]
|
push [ebx+TASKDATA.pid] ; PID
|
||||||
push dword [ecx+TASKDATA.pid] ; PID
|
push ecx ; debug_message code
|
||||||
push 12
|
mov ecx,12 ; debug_message size
|
||||||
pop ecx
|
call debugger_notify ;; only ONE using, inline ???
|
||||||
push 3 ; 3 = debug exception
|
add esp,12
|
||||||
call debugger_notify
|
|
||||||
pop ecx
|
|
||||||
pop ecx
|
|
||||||
pop ecx
|
|
||||||
mov edx, [TASK_BASE]
|
mov edx, [TASK_BASE]
|
||||||
mov byte [edx+TASKDATA.state], 1 ; suspended
|
mov byte [edx+TASKDATA.state], 1 ; suspended
|
||||||
call change_task
|
call change_task
|
||||||
restore_ring3_context
|
restore_ring3_context
|
||||||
iretd
|
iretd
|
||||||
|
@ -142,7 +142,7 @@ fpu_restore:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
e7: ;#NM exception handler
|
except_7: ;#NM exception handler
|
||||||
save_ring3_context
|
save_ring3_context
|
||||||
clts
|
clts
|
||||||
mov ax, app_data ;
|
mov ax, app_data ;
|
||||||
@ -180,7 +180,7 @@ e7: ;#NM exception handler
|
|||||||
|
|
||||||
iglobal
|
iglobal
|
||||||
fpu_owner dd 0
|
fpu_owner dd 0
|
||||||
endg
|
endg
|
||||||
|
|
||||||
reg_eip equ ebp+4
|
reg_eip equ ebp+4
|
||||||
reg_cs equ ebp+8
|
reg_cs equ ebp+8
|
||||||
@ -188,8 +188,8 @@ reg_eflags equ ebp+12
|
|||||||
reg_esp equ ebp+16
|
reg_esp equ ebp+16
|
||||||
reg_ss equ ebp+20
|
reg_ss equ ebp+20
|
||||||
|
|
||||||
align 4
|
align 4 ;not used now
|
||||||
except_16: ;fpu native exceptions handler
|
proc except_16 ;fpu native exceptions handler
|
||||||
test byte [esp+8+2], 2
|
test byte [esp+8+2], 2
|
||||||
jnz v86_except_16
|
jnz v86_except_16
|
||||||
push ebp
|
push ebp
|
||||||
@ -233,9 +233,10 @@ except_16: ;fpu native exceptions handler
|
|||||||
|
|
||||||
mov bl, 16
|
mov bl, 16
|
||||||
jmp exc_c
|
jmp exc_c
|
||||||
|
endp
|
||||||
|
|
||||||
align 4
|
align 4 ;not used now
|
||||||
except_19: ;sse exceptions handler
|
proc except_19 ;sse exceptions handler
|
||||||
test byte [esp+8+2], 2
|
test byte [esp+8+2], 2
|
||||||
jnz v86_except_19
|
jnz v86_except_19
|
||||||
push ebp
|
push ebp
|
||||||
@ -278,6 +279,7 @@ except_19: ;sse exceptions handler
|
|||||||
|
|
||||||
mov bl, 19
|
mov bl, 19
|
||||||
jmp exc_c
|
jmp exc_c
|
||||||
|
endp
|
||||||
|
|
||||||
restore reg_eip
|
restore reg_eip
|
||||||
restore reg_cs
|
restore reg_cs
|
||||||
|
@ -544,24 +544,15 @@ get_pg_addr:
|
|||||||
|
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
|
; Now it is called from sys32::exc_c (see stack frame there)
|
||||||
proc page_fault_handler
|
proc page_fault_handler
|
||||||
|
|
||||||
test byte [esp+12+2], 2
|
.err_addr equ ebp-4
|
||||||
jnz v86_page_fault
|
|
||||||
|
|
||||||
.err_code equ ebp+32
|
mov ebp, esp
|
||||||
.err_addr equ ebp-4
|
mov ebx, cr2
|
||||||
|
push ebx ; that is locals: .err_addr = cr2
|
||||||
pushad
|
inc [pg_data.pages_faults]
|
||||||
mov ebp, esp
|
|
||||||
mov eax, cr2
|
|
||||||
push eax
|
|
||||||
|
|
||||||
mov ax, app_data
|
|
||||||
mov ds, ax
|
|
||||||
mov es, ax
|
|
||||||
|
|
||||||
inc [pg_data.pages_faults]
|
|
||||||
|
|
||||||
; push eax
|
; push eax
|
||||||
; push edx
|
; push edx
|
||||||
@ -571,129 +562,115 @@ proc page_fault_handler
|
|||||||
; pop edx
|
; pop edx
|
||||||
; pop eax
|
; pop eax
|
||||||
|
|
||||||
mov ebx, [.err_addr]
|
mov eax, [pf_err_code]
|
||||||
mov eax, [.err_code]
|
|
||||||
|
|
||||||
cmp ebx, OS_BASE
|
cmp ebx, OS_BASE ;ebx == .err_addr
|
||||||
jb .user_space ;страница в памяти приложения ;
|
jb .user_space ;ñòðàíèöà â ïàìÿòè ïðèëîæåíèÿ ;
|
||||||
|
|
||||||
cmp ebx, page_tabs
|
cmp ebx, page_tabs
|
||||||
jb .kernel_space ;страница в памяти ядра
|
jb .kernel_space ;ñòðàíèöà â ïàìÿòè ÿäðà
|
||||||
|
|
||||||
cmp ebx, kernel_tabs
|
cmp ebx, kernel_tabs
|
||||||
jb .alloc;.app_tabs ;таблицы страниц приложения ;
|
jb .alloc;.app_tabs ;òàáëèöû ñòðàíèö ïðèëîæåíèÿ ;
|
||||||
;просто создадим одну
|
;ïðîñòî ñîçäàäèì îäíó
|
||||||
|
if 0 ;ïîêà ýòî ïðîñòî ëèøíåå
|
||||||
|
cmp ebx, LFB_BASE
|
||||||
|
jb .core_tabs ;òàáëèöû ñòðàíèö ÿäðà
|
||||||
|
;Îøèáêà
|
||||||
|
.lfb:
|
||||||
|
;îáëàñòü LFB
|
||||||
|
;Îøèáêà
|
||||||
|
jmp .fail
|
||||||
|
end if
|
||||||
|
.core_tabs:
|
||||||
|
.fail: ;simply return to caller
|
||||||
|
mov esp, ebp
|
||||||
|
mov bl, 14 ;#PF
|
||||||
|
ret
|
||||||
|
|
||||||
cmp ebx, LFB_BASE
|
|
||||||
jb .core_tabs ;таблицы страниц ядра
|
|
||||||
;Ошибка
|
|
||||||
.lfb:
|
|
||||||
;область LFB
|
|
||||||
;Ошибка
|
|
||||||
jmp .fail
|
|
||||||
|
|
||||||
align 4
|
|
||||||
.user_space:
|
.user_space:
|
||||||
test eax, PG_MAP
|
test eax, PG_MAP
|
||||||
jnz .err_access ;Страница присутствует
|
jnz .err_access ;Ñòðàíèöà ïðèñóòñòâóåò
|
||||||
;Ошибка доступа ?
|
;Îøèáêà äîñòóïà ?
|
||||||
|
|
||||||
shr ebx, 12
|
shr ebx, 12
|
||||||
mov ecx, ebx
|
mov ecx, ebx
|
||||||
shr ecx, 10
|
shr ecx, 10
|
||||||
mov edx, [master_tab+ecx*4]
|
mov edx, [master_tab+ecx*4]
|
||||||
test edx, PG_MAP
|
test edx, PG_MAP
|
||||||
jz .fail ;таблица страниц не создана
|
jz .fail ;òàáëèöà ñòðàíèö íå ñîçäàíà
|
||||||
;неверный адрес в программе
|
;íåâåðíûé àäðåñ â ïðîãðàììå
|
||||||
|
|
||||||
mov eax, [page_tabs+ebx*4]
|
mov eax, [page_tabs+ebx*4]
|
||||||
test eax, 2
|
test eax, 2
|
||||||
jz .fail ;адрес не зарезервирован для ;
|
jz .fail ;àäðåñ íå çàðåçåðâèðîâàí äëÿ ;
|
||||||
;использования. Ошибка
|
;èñïîëüçîâàíèÿ. Îøèáêà
|
||||||
.alloc:
|
.alloc:
|
||||||
call alloc_page
|
call alloc_page
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .fail
|
jz .fail
|
||||||
|
|
||||||
stdcall map_page,[ebp-4],eax,dword PG_UW
|
stdcall map_page,[.err_addr],eax,dword PG_UW
|
||||||
|
|
||||||
mov edi, [ebp-4]
|
mov edi, [.err_addr]
|
||||||
and edi, 0xFFFFF000
|
and edi, 0xFFFFF000
|
||||||
mov ecx, 1024
|
mov ecx, 1024
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
cld
|
;cld ;caller is duty for this
|
||||||
rep stosd
|
rep stosd
|
||||||
.exit:
|
.exit: ;iret with repeat fault instruction
|
||||||
mov esp, ebp
|
add esp,8 ; clear in stack: locals(.err_addr) + ret_to_caller
|
||||||
popad
|
restore_ring3_context
|
||||||
add esp, 4
|
iretd
|
||||||
iretd
|
|
||||||
|
|
||||||
.err_access:
|
.err_access = .fail
|
||||||
;íèêîãäà íå ïðîèñõîäèò
|
;íèêîãäà íå ïðîèñõîäèò
|
||||||
jmp .fail
|
;jmp .fail
|
||||||
|
|
||||||
.kernel_space:
|
.kernel_space:
|
||||||
test eax, PG_MAP
|
test eax, PG_MAP
|
||||||
jz .fail ;страница не присутствует
|
jz .fail ;ñòðàíèöà íå ïðèñóòñòâóåò
|
||||||
|
|
||||||
test eax, 4 ;U/S
|
test eax,12 ;U/S (+below)
|
||||||
jnz .fail ;приложение обратилось к памяти
|
jnz .fail ;ïðèëîæåíèå îáðàòèëîñü ê ïàìÿòè
|
||||||
;ядра
|
;ÿäðà
|
||||||
test eax, 8
|
;test eax, 8
|
||||||
jnz .fail ;установлен зарезервированный бит
|
;jnz .fail ;óñòàíîâëåí çàðåçåðâèðîâàííûé áèò
|
||||||
;в таблицах страниц. добавлено в P4/Xeon
|
;â òàáëèöàõ ñòðàíèö. äîáàâëåíî â P4/Xeon
|
||||||
|
|
||||||
;ïîïûòêà çàïèñè â çàùèù¸ííóþ ñòðàíèöó ÿäðà
|
;ïîïûòêà çàïèñè â çàùèù¸ííóþ ñòðàíèöó ÿäðà
|
||||||
|
|
||||||
cmp ebx, tss._io_map_0
|
cmp ebx, tss._io_map_0
|
||||||
jb .fail
|
jb .fail
|
||||||
|
|
||||||
cmp ebx, tss._io_map_0+8192
|
cmp ebx, tss._io_map_0+8192
|
||||||
jae .fail
|
jae .fail
|
||||||
|
|
||||||
; io permission map
|
; io permission map
|
||||||
; copy-on-write protection
|
; copy-on-write protection
|
||||||
|
|
||||||
call alloc_page
|
call alloc_page
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .fail
|
jz .fail
|
||||||
|
|
||||||
push eax
|
push eax
|
||||||
stdcall map_page,[ebp-4],eax,dword PG_SW
|
stdcall map_page,[.err_addr],eax,dword PG_SW
|
||||||
pop eax
|
pop eax
|
||||||
mov edi, [.err_addr]
|
mov edi, [.err_addr]
|
||||||
and edi, -4096
|
and edi, -4096
|
||||||
lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0
|
lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0
|
||||||
|
|
||||||
mov ebx, esi
|
mov ebx, esi
|
||||||
shr ebx, 12
|
shr ebx, 12
|
||||||
mov edx, [current_slot]
|
mov edx, [current_slot]
|
||||||
or eax, PG_SW
|
or eax, PG_SW
|
||||||
mov [edx+APPDATA.io_map+ebx*4], eax
|
mov [edx+APPDATA.io_map+ebx*4], eax
|
||||||
|
|
||||||
add esi, [default_io_map]
|
add esi, [default_io_map]
|
||||||
mov ecx, 4096/4
|
mov ecx, 4096/4
|
||||||
cld
|
;cld ;caller is duty for this
|
||||||
rep movsd
|
rep movsd
|
||||||
jmp .exit
|
jmp .exit
|
||||||
|
|
||||||
|
|
||||||
;не обрабатываем. Ошибка
|
|
||||||
|
|
||||||
.core_tabs:
|
|
||||||
.fail:
|
|
||||||
mov esp, ebp
|
|
||||||
popad
|
|
||||||
add esp, 4
|
|
||||||
|
|
||||||
; iretd
|
|
||||||
|
|
||||||
save_ring3_context ;debugger support
|
|
||||||
|
|
||||||
mov bl, 14
|
|
||||||
jmp exc_c
|
|
||||||
iretd
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
@ -1346,6 +1323,3 @@ proc create_ring_buffer stdcall, size:dword, flags:dword
|
|||||||
.fail:
|
.fail:
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -351,47 +351,27 @@ endg
|
|||||||
; a protected-mode interrupt handler (typically the general-protection
|
; a protected-mode interrupt handler (typically the general-protection
|
||||||
; exception handler, which in turn calls the virtual 8086-mode monitor).
|
; exception handler, which in turn calls the virtual 8086-mode monitor).
|
||||||
|
|
||||||
v86_debug_exc:
|
|
||||||
pushad
|
|
||||||
xor eax, eax
|
|
||||||
mov dr6, eax
|
|
||||||
mov bl, 1
|
|
||||||
jmp v86_exc_c
|
|
||||||
|
|
||||||
v86_page_fault:
|
|
||||||
add esp, 4
|
|
||||||
pushad
|
|
||||||
mov bl, 14
|
|
||||||
jmp v86_exc_c
|
|
||||||
|
|
||||||
v86_except_16:
|
|
||||||
pushad
|
|
||||||
mov bl, 16
|
|
||||||
jmp v86_exc_c
|
|
||||||
v86_except_19:
|
|
||||||
pushad
|
|
||||||
mov bl, 19
|
|
||||||
|
|
||||||
iglobal
|
iglobal
|
||||||
v86_exc_str1 db 'V86 : unexpected exception ',0
|
v86_exc_str1 db 'V86 : unexpected exception ',0
|
||||||
v86_exc_str2 db ' at ',0
|
v86_exc_str2 db ' at ',0
|
||||||
v86_exc_str3 db ':',0
|
v86_exc_str3 db ':',0
|
||||||
v86_exc_str4 db 13,10,'V86 : faulted code:',0
|
v86_exc_str4 db 13,10,'V86 : faulted code:',0
|
||||||
v86_exc_str5 db ' (unavailable)',0
|
v86_exc_str5 db ' (unavailable)',0
|
||||||
v86_newline db 13,10,0
|
v86_newline db 13,10,0
|
||||||
v86_io_str1 db 'V86 : access to disabled i/o port ',0
|
v86_io_str1 db 'V86 : access to disabled i/o port ',0
|
||||||
v86_io_byte db ' (byte)',13,10,0
|
v86_io_byte db ' (byte)',13,10,0
|
||||||
v86_io_word db ' (word)',13,10,0
|
v86_io_word db ' (word)',13,10,0
|
||||||
v86_io_dword db ' (dword)',13,10,0
|
v86_io_dword db ' (dword)',13,10,0
|
||||||
v86_irqerr db 'V86 : IRQ already hooked',13,10,0
|
v86_irqerr db 'V86 : IRQ already hooked',13,10,0
|
||||||
endg
|
endg
|
||||||
|
|
||||||
v86_exc_c:
|
v86_exc_c:
|
||||||
mov ax, app_data
|
|
||||||
mov ds, ax
|
|
||||||
mov es, ax
|
|
||||||
; Did we all that we have wanted to do?
|
; Did we all that we have wanted to do?
|
||||||
mov eax, [esp+v86_regs.size+10h+18h]
|
cmp bl,1
|
||||||
|
jne @f
|
||||||
|
xor eax, eax
|
||||||
|
mov dr6, eax
|
||||||
|
@@: mov eax, [esp+v86_regs.size+10h+18h]
|
||||||
cmp word [esp+v86_regs.eip], ax
|
cmp word [esp+v86_regs.eip], ax
|
||||||
jnz @f
|
jnz @f
|
||||||
shr eax, 16
|
shr eax, 16
|
||||||
|
@ -454,8 +454,8 @@ high_code:
|
|||||||
|
|
||||||
; LOAD IDT
|
; LOAD IDT
|
||||||
|
|
||||||
call build_interrupt_table
|
call build_interrupt_table ;lidt is executed
|
||||||
lidt [idtreg]
|
;lidt [idtreg]
|
||||||
|
|
||||||
call init_kernel_heap
|
call init_kernel_heap
|
||||||
stdcall kernel_alloc, RING0_STACK_SIZE+512
|
stdcall kernel_alloc, RING0_STACK_SIZE+512
|
||||||
@ -1296,6 +1296,7 @@ display_number_force:
|
|||||||
xor edx,edx
|
xor edx,edx
|
||||||
call division_64_bits
|
call division_64_bits
|
||||||
div ebx
|
div ebx
|
||||||
|
hexletters = __fdo_hexdigits
|
||||||
add edx,hexletters
|
add edx,hexletters
|
||||||
mov dl,[edx]
|
mov dl,[edx]
|
||||||
mov [edi],dl
|
mov [edi],dl
|
||||||
|
@ -70,9 +70,9 @@
|
|||||||
;
|
;
|
||||||
; A400 -> B0FF free
|
; A400 -> B0FF free
|
||||||
|
|
||||||
; B100 -> B2FF IDT
|
; B100 -> B307 IDT for int_0x00..int_0x40
|
||||||
|
|
||||||
; B300 -> BFFF free
|
; B308 -> BFFF free
|
||||||
|
|
||||||
; C000 -> C3FF window stack C000 no of windows - all in words
|
; C000 -> C3FF window stack C000 no of windows - all in words
|
||||||
; C402 -> C7FF window position in stack
|
; C402 -> C7FF window position in stack
|
||||||
|
Loading…
x
Reference in New Issue
Block a user