Subversion Repositories Kolibri OS

Rev

Rev 129 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 129 Rev 384
Line 17... Line 17...
17
	dd	debug_set_drx
17
	dd	debug_set_drx
Line 18... Line 18...
18
 
18
 
19
debug_set_event_data:
19
debug_set_event_data:
20
; in: ebx = pointer
20
; in: ebx = pointer
21
; destroys eax
21
; destroys eax
22
	mov	eax, [0x3000]
22
        mov     eax, [CURRENT_TASK]
23
	shl	eax, 8
23
	shl	eax, 8
24
	mov	[eax+0x80000+APPDATA.dbg_event_mem], ebx
24
        mov     [eax+SLOT_BASE+APPDATA.dbg_event_mem], ebx
Line 25... Line 25...
25
	ret
25
	ret
26
 
26
 
27
get_debuggee_slot:
27
get_debuggee_slot:
Line 34... Line 34...
34
	call	pid_to_slot
34
	call	pid_to_slot
35
	test	eax, eax
35
	test	eax, eax
36
	jz	.ret_bad
36
	jz	.ret_bad
37
	shl	eax, 5
37
	shl	eax, 5
38
	push	ebx
38
	push	ebx
39
	mov	ebx, [0x3000]
39
        mov     ebx, [CURRENT_TASK]
40
	cmp	[0x80000+eax*8+APPDATA.debugger_slot], ebx
40
        cmp     [SLOT_BASE+eax*8+APPDATA.debugger_slot], ebx
41
	pop	ebx
41
	pop	ebx
42
	jnz	.ret_bad
42
	jnz	.ret_bad
43
;	clc	; automatically
43
;	clc	; automatically
44
	ret
44
	ret
45
.ret_bad:
45
.ret_bad:
Line 49... Line 49...
49
debug_detach:
49
debug_detach:
50
; in: ebx=pid
50
; in: ebx=pid
51
; destroys eax,ebx
51
; destroys eax,ebx
52
	call	get_debuggee_slot
52
	call	get_debuggee_slot
53
	jc	.ret
53
	jc	.ret
54
	and	dword [eax*8+0x80000+APPDATA.debugger_slot], 0
54
        and     dword [eax*8+SLOT_BASE+APPDATA.debugger_slot], 0
55
	call	do_resume
55
	call	do_resume
56
.ret:
56
.ret:
57
	sti
57
	sti
58
	ret
58
	ret
Line 70... Line 70...
70
debug_suspend:
70
debug_suspend:
71
; in: ebx=pid
71
; in: ebx=pid
72
; destroys eax,ebx
72
; destroys eax,ebx
73
	call	get_debuggee_slot
73
	call	get_debuggee_slot
74
	jc	.ret
74
	jc	.ret
75
	mov	bl, [0x3000+eax+TASKDATA.state]	; process state
75
        mov     bl, [CURRENT_TASK+eax+TASKDATA.state] ; process state
76
	test	bl, bl
76
	test	bl, bl
77
	jz	.1
77
	jz	.1
78
	cmp	bl, 5
78
	cmp	bl, 5
79
	jnz	.ret
79
	jnz	.ret
80
	mov	bl, 2
80
	mov	bl, 2
81
.2:	mov	[0x3000+eax+TASKDATA.state], bl
81
.2:     mov     [CURRENT_TASK+eax+TASKDATA.state], bl
82
.ret:
82
.ret:
83
	sti
83
	sti
84
	ret
84
	ret
85
.1:
85
.1:
86
	inc	ebx
86
	inc	ebx
87
	jmp	.2
87
	jmp	.2
Line 88... Line 88...
88
 
88
 
89
do_resume:
89
do_resume:
90
	mov	bl, [0x3000+eax+TASKDATA.state]
90
        mov     bl, [CURRENT_TASK+eax+TASKDATA.state]
91
	cmp	bl, 1
91
	cmp	bl, 1
92
	jz	.1
92
	jz	.1
93
	cmp	bl, 2
93
	cmp	bl, 2
94
	jnz	.ret
94
	jnz	.ret
95
	mov	bl, 5
95
	mov	bl, 5
96
.2:	mov	[0x3000+eax+TASKDATA.state], bl
96
.2:     mov     [CURRENT_TASK+eax+TASKDATA.state], bl
97
.ret:	ret
97
.ret:	ret
98
.1:	dec	ebx
98
.1:	dec	ebx
Line 99... Line 99...
99
	jmp	.2
99
	jmp	.2
Line 125... Line 125...
125
	call	get_debuggee_slot
125
	call	get_debuggee_slot
126
	jc	.ret
126
	jc	.ret
127
	imul	eax, tss_step/32
127
	imul	eax, tss_step/32
128
	add	eax, tss_data
128
	add	eax, tss_data
129
	mov	edi, edx
129
	mov	edi, edx
130
	cmp	[l.cs - tss_sceleton + eax], app_code
130
        cmp     [eax+TSS._cs], app_code
131
	jnz	.ring0
131
	jnz	.ring0
132
	lea	esi, [l.eip - tss_sceleton + eax]
132
        lea     esi, [eax+TSS._eip]
133
	shr	ecx, 2
133
	shr	ecx, 2
134
	rep	movsd
134
	rep	movsd
135
	jmp	.ret
135
	jmp	.ret
136
.ring0:
136
.ring0:
137
; note that following code assumes that all interrupt/exception handlers
137
; note that following code assumes that all interrupt/exception handlers
138
; saves ring-3 context by push ds es, pushad in this order
138
; saves ring-3 context by push ds es, pushad in this order
139
	mov	esi, [l.esp0 - tss_sceleton + eax]
139
        mov     esi, [eax+TSS._esp0]
140
; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), ds, es, pushad
140
; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), ds, es, pushad
141
	sub	esi, 8+12+8+20h
141
	sub	esi, 8+12+8+20h
142
	lodsd
142
	lodsd
143
	mov	[edi+24h], eax
143
	mov	[edi+24h], eax
144
	lodsd
144
	lodsd
Line 184... Line 184...
184
	call	get_debuggee_slot
184
	call	get_debuggee_slot
185
	jc	.stiret
185
	jc	.stiret
186
	imul	eax, tss_step/32
186
	imul	eax, tss_step/32
187
	add	eax, tss_data
187
	add	eax, tss_data
188
	mov	esi, edx
188
	mov	esi, edx
189
	cmp	[l.cs - tss_sceleton + eax], app_code
189
        cmp     [eax+TSS._cs], app_code
190
	jnz	.ring0
190
	jnz	.ring0
191
	lea	edi, [l.eip - tss_sceleton + eax]
191
        lea     edi, [eax+TSS._eip]
192
	shr	ecx, 2
192
	shr	ecx, 2
193
	rep	movsd
193
	rep	movsd
194
	jmp	.stiret
194
	jmp	.stiret
195
.ring0:
195
.ring0:
196
	mov	edi, [l.esp0 - tss_sceleton + eax]
196
        mov     edi, [eax+TSS._esp0]
197
	sub	edi, 8+12+8+20h
197
	sub	edi, 8+12+8+20h
198
	mov	eax, [esi+24h]
198
	mov	eax, [esi+24h]
199
	stosd
199
	stosd
200
	mov	eax, [esi+20h]
200
	mov	eax, [esi+20h]
201
	stosd
201
	stosd
Line 225... Line 225...
225
 
225
 
226
debug_set_drx:
226
debug_set_drx:
227
	call	get_debuggee_slot
227
	call	get_debuggee_slot
228
	jc	.errret
228
	jc	.errret
229
	mov	ebp, eax
229
	mov	ebp, eax
230
	lea	eax, [eax*8+0x80000+APPDATA.dbg_regs]
230
        lea     eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs]
231
; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3
231
; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3
232
; [eax+10]=dr7
232
; [eax+10]=dr7
233
	add	edx, std_application_base_address
233
	add	edx, std_application_base_address
234
	jc	.errret
234
	jc	.errret
Line 247... Line 247...
247
	and	dword [eax+ecx*2], 0	; clear DR
247
	and	dword [eax+ecx*2], 0	; clear DR
248
	btr	dword [eax+10h], ecx	; clear L bit
248
	btr	dword [eax+10h], ecx	; clear L bit
249
	test	byte [eax+10h], 55h
249
	test	byte [eax+10h], 55h
250
	jnz	.okret
250
	jnz	.okret
251
	imul	eax, ebp, tss_step/32
251
	imul	eax, ebp, tss_step/32
252
	and	byte [eax + tss_data + l.trap - tss_sceleton], not 1
252
        and     byte [eax + tss_data + TSS._trap], not 1
253
.okret:
253
.okret:
254
	and	dword [esp+36], 0
254
	and	dword [esp+36], 0
255
	sti
255
	sti
256
	ret
256
	ret
257
.errret:
257
.errret:
Line 289... Line 289...
289
	shl	edx, cl
289
	shl	edx, cl
290
	not	edx
290
	not	edx
291
	and	[eax+10h+2], dx
291
	and	[eax+10h+2], dx
292
	or	[eax+10h+2], bx		; set R/W and LEN fields
292
	or	[eax+10h+2], bx		; set R/W and LEN fields
293
	imul	eax, ebp, tss_step/32
293
	imul	eax, ebp, tss_step/32
294
	or	byte [eax + tss_data + l.trap - tss_sceleton], 1
294
        or      byte [eax + tss_data + TSS._trap], 1
295
	jmp	.okret
295
	jmp	.okret
Line 296... Line 296...
296
 
296
 
297
debug_read_process_memory:
297
debug_read_process_memory:
298
; in:
298
; in:
Line 356... Line 356...
356
	mov	edi, [timer_ticks]
356
	mov	edi, [timer_ticks]
357
	add	edi, 500	; 5 sec timeout
357
	add	edi, 500	; 5 sec timeout
358
.1:
358
.1:
359
	mov	eax, ebp
359
	mov	eax, ebp
360
	shl	eax, 8
360
	shl	eax, 8
361
	mov	edx, [0x80000+eax+APPDATA.dbg_event_mem]
361
        mov     edx, [SLOT_BASE+eax+APPDATA.dbg_event_mem]
362
	test	edx, edx
362
	test	edx, edx
363
	jz	.ret
363
	jz	.ret
364
; read buffer header
364
; read buffer header
365
	push	ecx
365
	push	ecx
366
	push	eax
366
	push	eax
Line 378... Line 378...
378
	jg	@f
378
	jg	@f
379
.2:
379
.2:
380
	pop	ecx
380
	pop	ecx
381
	pop	ecx
381
	pop	ecx
382
	pop	ecx
382
	pop	ecx
383
	cmp	dword [0x3000], 1
383
        cmp     dword [CURRENT_TASK], 1
384
	jnz	.notos
384
	jnz	.notos
385
	cmp	[timer_ticks], edi
385
	cmp	[timer_ticks], edi
386
	jae	.ret
386
	jae	.ret
387
.notos:
387
.notos:
388
	sti
388
	sti
Line 412... Line 412...
412
	pop	ecx
412
	pop	ecx
413
	call	write_process_memory
413
	call	write_process_memory
414
; new debug event
414
; new debug event
415
	mov	eax, ebp
415
	mov	eax, ebp
416
	shl	eax, 8
416
	shl	eax, 8
417
	or	byte [0x80000+eax+APPDATA.event_mask+1], 1	; set flag 100h
417
        or      byte [SLOT_BASE+eax+APPDATA.event_mask+1], 1      ; set flag 100h
418
.ret:
418
.ret:
419
	ret
419
	ret
Line 420... Line 420...
420
 
420
 
421
debug_exc:
421
debug_exc:
Line 428... Line 428...
428
	mov	eax, dr6
428
	mov	eax, dr6
429
	test	ax, ax
429
	test	ax, ax
430
	jns	@f
430
	jns	@f
431
; this is exception from task switch
431
; this is exception from task switch
432
; set DRx registers for task and continue
432
; set DRx registers for task and continue
433
	mov	eax, [0x3000]
433
        mov     eax, [CURRENT_TASK]
434
	shl	eax, 8
434
	shl	eax, 8
435
	add	eax, 0x80000+APPDATA.dbg_regs
435
        add     eax, SLOT_BASE+APPDATA.dbg_regs
436
	mov	ecx, [eax+0]
436
	mov	ecx, [eax+0]
437
	mov	dr0, ecx
437
	mov	dr0, ecx
438
	mov	ecx, [eax+4]
438
	mov	ecx, [eax+4]
439
	mov	dr1, ecx
439
	mov	dr1, ecx
440
	mov	ecx, [eax+8]
440
	mov	ecx, [eax+8]
Line 451... Line 451...
451
	push	eax
451
	push	eax
452
	xor	eax, eax
452
	xor	eax, eax
453
	mov	dr6, eax
453
	mov	dr6, eax
454
; test if debugging
454
; test if debugging
455
	cli
455
	cli
456
	mov	eax, [0x3000]
456
        mov     eax, [CURRENT_TASK]
457
	shl	eax, 8
457
	shl	eax, 8
458
	mov	eax, [0x80000+eax+APPDATA.debugger_slot]
458
        mov     eax, [SLOT_BASE+eax+APPDATA.debugger_slot]
459
	test	eax, eax
459
	test	eax, eax
460
	jnz	.debug
460
	jnz	.debug
461
	sti
461
	sti
462
; not debuggee => say error and terminate
462
; not debuggee => say error and terminate
463
	add	esp, 28h+4
463
	add	esp, 28h+4
464
	mov	[error_interrupt], 1
464
	mov	[error_interrupt], 1
465
	call	show_error_parameters
465
	call	show_error_parameters
466
	mov	edx, [0x3010]
466
        mov     edx, [TASK_BASE]
467
	mov	byte [edx+TASKDATA.state], 4
467
	mov	byte [edx+TASKDATA.state], 4
468
	jmp	change_task
468
	jmp	change_task
469
.debug:
469
.debug:
470
; we are debugged process, notify debugger and suspend ourself
470
; we are debugged process, notify debugger and suspend ourself
471
; eax=debugger PID
471
; eax=debugger PID
Line 481... Line 481...
481
	add	cl, cl
481
	add	cl, cl
482
	inc	ecx
482
	inc	ecx
483
	cmp	cl, not 10h
483
	cmp	cl, not 10h
484
	jnz	.l1
484
	jnz	.l1
485
	push	edx	; DR6 image
485
	push	edx	; DR6 image
486
	mov	ecx, [0x3010]
486
        mov     ecx, [TASK_BASE]
487
	push	dword [ecx+TASKDATA.pid]	; PID
487
	push	dword [ecx+TASKDATA.pid]	; PID
488
	push	12
488
	push	12
489
	pop	ecx
489
	pop	ecx
490
	push	3	; 3 = debug exception
490
	push	3	; 3 = debug exception
491
	call	debugger_notify
491
	call	debugger_notify
492
	pop	ecx
492
	pop	ecx
493
	pop	ecx
493
	pop	ecx
494
	pop	ecx
494
	pop	ecx
495
	mov	edx, [0x3010]
495
        mov     edx, [TASK_BASE]
496
	mov	byte [edx+TASKDATA.state], 1	; suspended
496
	mov	byte [edx+TASKDATA.state], 1	; suspended
497
	call	change_task
497
	call	change_task
498
	restore_ring3_context
498
	restore_ring3_context
499
	iretd
499
	iretd