Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 39 → Rev 40

/kernel/trunk/core/debug.inc
0,0 → 1,344
; this code uses following additions to system structures:
; in additional app info at 80000..8FFFF:
; AC (dword) 0 or debugger slot
; BC (dword) address of debug event memory
; new process slot state:
; 1 = suspended
; 2 = suspended waiting for event
; new event: 8 (and new possible bitflag for A8 in additional app info)
; diamond, 2006
sys_debug_services:
cmp eax, 8
ja @f
jmp dword [sys_debug_services_table+eax*4]
@@: ret
sys_debug_services_table:
dd debug_set_event_data
dd debug_getcontext
dd debug_setcontext
dd debug_detach
dd debug_suspend
dd debug_resume
dd debug_read_process_memory
dd debug_write_process_memory
dd debug_terminate
 
debug_set_event_data:
; in: ebx = pointer
; destroys eax
mov eax, [0x3000]
shl eax, 8
mov [eax+0x80000+0xBC], ebx
ret
 
get_debuggee_slot:
; in: ebx=PID
; out: CF=1 if error
; CF=0 and eax=slot*0x20 if ok
; out: interrupts disabled
cli
mov eax, ebx
call pid_to_slot
test eax, eax
jz .ret_bad
shl eax, 5
push ebx
mov ebx, [0x3000]
cmp [0x80000+eax*8+0xAC], ebx
pop ebx
jnz .ret_bad
; clc ; automatically
ret
.ret_bad:
stc
ret
 
debug_detach:
; in: ebx=pid
; destroys eax,ebx
call get_debuggee_slot
jc .ret
and dword [eax*8+0x80000+0xAC], 0
call do_resume
.ret:
sti
ret
 
debug_terminate:
; in: ebx=pid
call get_debuggee_slot
jc debug_detach.ret
mov ebx, eax
shr ebx, 5
push 2
pop eax
jmp sys_system
 
debug_suspend:
; in: ebx=pid
; destroys eax,ebx
call get_debuggee_slot
jc .ret
mov bl, [0x3000+eax+0xA] ; process state
test bl, bl
jz .1
cmp bl, 5
jnz .ret
mov bl, 2
.2: mov [0x3000+eax+0xA], bl
.ret:
sti
ret
.1:
inc ebx
jmp .2
 
do_resume:
mov bl, [0x3000+eax+0xA]
cmp bl, 1
jz .1
cmp bl, 2
jnz .ret
mov bl, 5
.2: mov [0x3000+eax+0xA], bl
.ret: ret
.1: dec ebx
jmp .2
 
debug_resume:
; in: ebx=pid
; destroys eax,ebx
call get_debuggee_slot
jc .ret
call do_resume
.ret: sti
ret
 
debug_getcontext:
; in:
; ebx=pid
; ecx=sizeof(CONTEXT)
; edx->CONTEXT
; destroys eax,ecx,edx,esi,edi
cmp ecx, 28h
jnz .ret
add edx, std_application_base_address
push ebx
mov ebx, edx
call check_region
pop ebx
dec eax
jnz .ret
call get_debuggee_slot
jc .ret
imul eax, tss_step/32
add eax, tss_data
mov edi, edx
cmp [l.cs - tss_sceleton + eax], app_code
jnz .ring0
lea esi, [l.eip - tss_sceleton + eax]
shr ecx, 2
rep movsd
jmp .ret
.ring0:
; note that following code assumes that all interrupt/exception handlers
; saves ring-3 context by push ds es, pushad in this order
mov esi, [l.esp0 - tss_sceleton + eax]
; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), ds, es, pushad
sub esi, 8+12+8+20h
lodsd
mov [edi+24h], eax
lodsd
mov [edi+20h], eax
lodsd
mov [edi+1Ch], eax
lodsd
lodsd
mov [edi+14h], eax
lodsd
mov [edi+10h], eax
lodsd
mov [edi+0Ch], eax
lodsd
mov [edi+8], eax
add esi, 8
lodsd
mov [edi], eax
lodsd
lodsd
mov [edi+4], eax
lodsd
mov [edi+18h], eax
.ret:
sti
ret
 
debug_setcontext:
; in:
; ebx=pid
; ecx=sizeof(CONTEXT)
; edx->CONTEXT
; destroys eax,ecx,edx,esi,edi
cmp ecx, 28h
jnz .ret
add edx, std_application_base_address
push ebx
mov ebx, edx
call check_region
pop ebx
dec eax
jnz .ret
call get_debuggee_slot
jc .stiret
imul eax, tss_step/32
add eax, tss_data
mov esi, edx
cmp [l.cs - tss_sceleton + eax], app_code
jnz .ring0
lea edi, [l.eip - tss_sceleton + eax]
shr ecx, 2
rep movsd
jmp .stiret
.ring0:
mov edi, [l.esp0 - tss_sceleton + eax]
sub edi, 8+12+8+20h
mov eax, [esi+24h]
stosd
mov eax, [esi+20h]
stosd
mov eax, [esi+1Ch]
stosd
scasd
mov eax, [esi+14h]
stosd
mov eax, [esi+10h]
stosd
mov eax, [esi+0Ch]
stosd
mov eax, [esi+8]
stosd
add edi, 8
mov eax, [esi]
stosd
scasd
mov eax, [esi+4]
stosd
mov eax, [esi+18h]
stosd
.stiret:
sti
.ret:
ret
 
debug_read_process_memory:
; in:
; ebx=pid
; ecx=length
; esi->buffer in debugger
; edx=address in debuggee
; out: [esp+36]=eax=sizeof(read)
; destroys all
add esi, std_application_base_address
push ebx
mov ebx, esi
call check_region
pop ebx
dec eax
jnz .ret
call get_debuggee_slot
jc .stiret
mov ebx, esi
call read_process_memory
.stiret:
sti
.ret:
ret
 
debug_write_process_memory:
; in:
; ebx=pid
; ecx=length
; esi->buffer in debugger
; edx=address in debuggee
; out: [esp+36]=eax=sizeof(write)
; destroys all
add esi, std_application_base_address
push ebx
mov ebx, esi
call check_region
pop ebx
dec eax
jnz .ret
call get_debuggee_slot
jc .stiret
mov ebx, esi
call write_process_memory
.stiret:
sti
.ret:
ret
 
debugger_notify:
; in: eax=debugger slot
; ecx=size of debug message
; [esp+4]..[esp+4+ecx]=message
; interrupts must be disabled!
; destroys all general registers
; interrupts remain disabled
mov ebp, eax
shl eax, 8
.1:
mov edx, [0x80000+eax+0xBC]
test edx, edx
jz .ret
; read buffer header
push ecx
push eax
push eax
mov eax, ebp
mov ebx, esp
mov ecx, 8
call read_process_memory
cmp eax, ecx
jz @f
add esp, 12
jmp .ret
@@:
cmp dword [ebx], 0
jg @f
.2:
pop ecx
pop ecx
pop ecx
sti
call change_task
cli
jmp .1
@@:
mov ecx, [ebx+8]
add ecx, [ebx+4]
cmp ecx, [ebx]
ja .2
; advance buffer position
push ecx
mov ecx, 4
sub ebx, ecx
mov eax, ebp
add edx, ecx
call write_process_memory
pop eax
; write message
mov eax, ebp
add edx, ecx
add edx, [ebx+8]
add ebx, 20
pop ecx
pop ecx
pop ecx
call write_process_memory
; new debug event
mov eax, ebp
shl eax, 8
or byte [0x80000+eax+0xA8+1], 1 ; set flag 100h
.ret:
ret
/kernel/trunk/core/newproce.inc
60,6 → 60,7
;input:
; eax - pointer to filename
; ebx - parameters to pass
; edx - flags
;result:
; eax - pid of new process
; or 0 if call fails.
231,6 → 232,7
;input:
; eax - pointer to filename
; ebx - parameters to pass
; edx - flags
;result:
; eax - pid of new process
; or 0 if call fails.
546,6 → 548,13
mov ebx,[new_process_place]
shl ebx,5
mov [0x3000+ebx+0xa],byte 0 ;set process state - running
; set if debuggee
test byte [esp+28], 1
jz .no_debug
mov [0x3000+ebx+0xa],byte 1 ;set process state - suspended
mov eax,[0x3000]
mov [0x80000+ebx*8+0xac],eax ;set debugger PID - current
.no_debug:
mov esi,new_process_running
call sys_msg_board_str ;output information about succefull startup
563,6 → 572,7
; ecx=thread stack value
;result:
; eax=pid
xor edx,edx ; flags=0
pushad
cmp eax,1
1165,6 → 1175,7
;eax - file name (kernel address)
;ebx - file name length
;ecx - work area (kernel address)
;edx - flags
;ebp - parameters
mov [appl_path],edi
pushad
1355,3 → 1366,5
sti
ret
end if
 
include 'debug.inc'
/kernel/trunk/core/sched.inc
4,8 → 4,7
 
align 32
irq0:
pushad
push ds es
save_ring3_context
mov ax, os_data
mov ds, ax
mov es, ax
45,6 → 44,7
.waiting_for_termination:
.waiting_for_reuse:
.waiting_for_event:
.suspended:
cmp ebx, [0x3004]
jb @f
mov edi, 0x3000
55,6 → 55,10
inc ebx
 
mov al, byte [edi+0xA]
cmp al, 1
jz .suspended
cmp al, 2
jz .suspended
cmp al, 3
je .waiting_for_termination
cmp al, 4
101,8 → 105,7
inc [context_counter] ;noname & halyavin
@@:
pop es ds
popad
restore_ring3_context
iret
 
 
/kernel/trunk/core/sys32.inc
164,6 → 164,17
dd i40
endg
 
macro save_ring3_context
{
push ds es
pushad
}
macro restore_ring3_context
{
popad
pop es ds
}
 
; simply return control to interrupted process
unknown_interrupt:
iret
172,6 → 183,7
{
forward
e#num :
save_ring3_context
mov bl, num
jmp exc_c
}
181,6 → 193,7
forward
e#num :
add esp, 4
save_ring3_context
mov bl, num
jmp exc_c
}
193,6 → 206,16
mov ds, ax
mov es, ax
 
; test if debugging
cli
mov eax, [0x3000]
shl eax, 8
mov eax, [0x80000+eax+0xAC]
test eax, eax
jnz .debug
sti
; not debuggee => say error and terminate
add esp, 28h
movzx eax, bl
mov [error_interrupt], eax
call show_error_parameters
202,6 → 225,25
jmp change_task
 
.debug:
; we are debugged process, notify debugger and suspend ourself
; eax=debugger PID
movzx ecx, bl
push ecx
mov ecx, [0x3010]
push dword [ecx+4] ; PID of current process
push 12
pop ecx
push 1 ; 1=exception
call debugger_notify
pop ecx
pop ecx
pop ecx
mov edx, [0x3010]
mov byte [edx+0xA], 1 ; suspended
call change_task
restore_ring3_context
iretd
 
;;;;;;;;;;;;;;;;;;;;;;;
;; FPU ERROR HANDLER ;;
209,11 → 251,8
 
align 4
e7:
save_ring3_context
clts
push eax
push ds es
mov ax, os_data
mov ds, ax
mov es, ax
232,10 → 271,7
frstor [eax+0x10]
@@:
mov [eax + 0x7f], byte 1
pop es ds
pop eax
restore_ring3_context
iret
iglobal
320,7 → 356,7
{
forward
p_irq#num :
pushad
save_ring3_context
mov edi, num
jmp irq_c
}
328,58 → 364,48
irqh 2,5,7,8,9,10,11,14,15
 
irq_c:
push ds es
mov ax, os_data
mov ds, ax
mov es, ax
call irqhandler
pop es ds
popad
restore_ring3_context
iret
 
p_irq6:
pushad
push ds es
save_ring3_context
mov ax, os_data
mov ds, ax
mov es, ax
call fdc_irq
call ready_for_next_irq
pop es ds
popad
restore_ring3_context
iret
 
p_irq3:
pushad
push ds es
save_ring3_context
mov ax, os_data
mov ds, ax
mov es, ax
call check_mouse_data_com2
pop es ds
popad
restore_ring3_context
iret
 
p_irq4:
pushad
push ds es
save_ring3_context
mov ax, os_data
mov ds, ax
mov es, ax
call check_mouse_data_com1
pop es ds
popad
restore_ring3_context
iret
 
p_irq12:
pushad
push ds es
save_ring3_context
mov ax, os_data
mov ds, ax
mov es, ax
call check_mouse_data_ps2
pop es ds
popad
restore_ring3_context
iret
 
ready_for_next_irq:
396,8 → 422,7
ret
 
irqD:
pushad
push ds es
save_ring3_context
mov ax, os_data
mov ds, ax
mov es, ax
412,8 → 437,8
mov dx,0x20
out dx,al
pop es ds
popad
restore_ring3_context
iret
 
 
650,12 → 675,13
call sys_msg_board_str
pop esi
 
@@:
cli
cmp [application_table_status],0
je term9
sti
call change_task
jmp terminate
jmp @b
term9:
 
call set_application_table_status
752,6 → 778,23
rep stosd
popa
 
; debuggee test
pushad
mov edi, esi
shl edi, 5
mov eax, [0x80000+edi*8+0xAC]
test eax, eax
jz .nodebug
push 8
pop ecx
push dword [0x3000+edi+0x4] ; PID
push 2
call debugger_notify
pop ecx
pop ecx
.nodebug:
popad
 
pusha ; at 0x80000+
mov edi,esi
shl edi,8
863,6 → 906,25
mov edi,esi ; do not run this process slot
shl edi, 5
mov [edi+0x300A],byte 9
; debugger test - terminate all debuggees
mov eax, 2
mov ecx, 0x80000+2*0x100+0xAC
.xd0:
cmp eax, [0x3004]
ja .xd1
cmp dword [ecx], esi
jnz @f
and dword [ecx], 0
pushad
xchg eax, ebx
mov eax, 2
call sys_system
popad
@@:
inc eax
add ecx, 0x100
jmp .xd0
.xd1:
; call systest
sti ; .. and life goes on
 
/kernel/trunk/core/syscall.inc
8,6 → 8,7
i40:
push ds es
pushad
cld
 
mov ax,word os_data
mov ds,ax
136,9 → 137,9
dd sys_process_def ; 66-Process definitions - keyboard
dd sys_window_move ; 67-Window move or resize
dd sys_internal_services ; 68-Some internal services
dd sys_debug_services ; 69-Debug
 
times 255 - ( ($-servetable) /4 ) dd undefined_syscall
 
dd sys_end ; -1-end application
endg