Rev 63 | Rev 113 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 63 | Rev 66 | ||
---|---|---|---|
Line 1... | Line -... | ||
1 | ; this code uses following additions to system structures: |
- | |
2 | ; in additional app info at 80000..8FFFF: |
- | |
3 | ; AC (dword) 0 or debugger slot |
- | |
4 | ; BC (dword) address of debug event memory |
- | |
5 | ; new process slot state: |
- | |
6 | ; 1 = suspended |
- | |
7 | ; 2 = suspended waiting for event |
- | |
8 | ; new event: 8 (and new possible bitflag for A8 in additional app info) |
- | |
9 | ; diamond, 2006 |
1 | ; diamond, 2006 |
10 | sys_debug_services: |
2 | sys_debug_services: |
11 | cmp eax, 8 |
3 | cmp eax, 9 |
12 | ja @f |
4 | ja @f |
13 | jmp dword [sys_debug_services_table+eax*4] |
5 | jmp dword [sys_debug_services_table+eax*4] |
14 | @@: ret |
6 | @@: ret |
15 | sys_debug_services_table: |
7 | sys_debug_services_table: |
16 | dd debug_set_event_data |
8 | dd debug_set_event_data |
Line 20... | Line 12... | ||
20 | dd debug_suspend |
12 | dd debug_suspend |
21 | dd debug_resume |
13 | dd debug_resume |
22 | dd debug_read_process_memory |
14 | dd debug_read_process_memory |
23 | dd debug_write_process_memory |
15 | dd debug_write_process_memory |
24 | dd debug_terminate |
16 | dd debug_terminate |
- | 17 | dd debug_set_drx |
|
Line 25... | Line 18... | ||
25 | 18 | ||
26 | debug_set_event_data: |
19 | debug_set_event_data: |
27 | ; in: ebx = pointer |
20 | ; in: ebx = pointer |
28 | ; destroys eax |
21 | ; destroys eax |
Line 228... | Line 221... | ||
228 | .stiret: |
221 | .stiret: |
229 | sti |
222 | sti |
230 | .ret: |
223 | .ret: |
231 | ret |
224 | ret |
Line -... | Line 225... | ||
- | 225 | ||
- | 226 | debug_set_drx: |
|
- | 227 | call get_debuggee_slot |
|
- | 228 | jc .errret |
|
- | 229 | mov ebp, eax |
|
- | 230 | lea eax, [eax*8+0x80000+0xC0] |
|
- | 231 | ; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 |
|
- | 232 | ; [eax+10]=dr7 |
|
- | 233 | add edx, std_application_base_address |
|
- | 234 | jc .errret |
|
- | 235 | cmp cl, 3 |
|
- | 236 | ja .errret |
|
- | 237 | mov ebx, dr7 |
|
- | 238 | shr ebx, cl |
|
- | 239 | shr ebx, cl |
|
- | 240 | test ebx, 2 ; bit 1+2*index = G0..G3, global break enable |
|
- | 241 | jnz .errret2 |
|
- | 242 | test ch, ch |
|
- | 243 | jns .new |
|
- | 244 | ; clear breakpoint |
|
- | 245 | movzx ecx, cl |
|
- | 246 | add ecx, ecx |
|
- | 247 | and dword [eax+ecx*2], 0 ; clear DR |
|
- | 248 | btr dword [eax+10h], ecx ; clear L bit |
|
- | 249 | test byte [eax+10h], 55h |
|
- | 250 | jnz .okret |
|
- | 251 | imul eax, ebp, tss_step/32 |
|
- | 252 | and byte [eax + tss_data + l.trap - tss_sceleton], not 1 |
|
- | 253 | .okret: |
|
- | 254 | and dword [esp+36], 0 |
|
- | 255 | sti |
|
- | 256 | ret |
|
- | 257 | .errret: |
|
- | 258 | sti |
|
- | 259 | mov dword [esp+36], 1 |
|
- | 260 | ret |
|
- | 261 | .errret2: |
|
- | 262 | sti |
|
- | 263 | mov dword [esp+36], 2 |
|
- | 264 | ret |
|
- | 265 | .new: |
|
- | 266 | ; add new breakpoint |
|
- | 267 | ; cl=index; ch=flags; edx=address |
|
- | 268 | test ch, 0xF0 |
|
- | 269 | jnz .errret |
|
- | 270 | mov bl, ch |
|
- | 271 | and bl, 3 |
|
- | 272 | cmp bl, 2 |
|
- | 273 | jz .errret |
|
- | 274 | mov bl, ch |
|
- | 275 | shr bl, 2 |
|
- | 276 | cmp bl, 2 |
|
- | 277 | jz .errret |
|
- | 278 | test dl, bl |
|
- | 279 | jnz .errret |
|
- | 280 | or byte [eax+10h+1], 3 ; set GE and LE flags |
|
- | 281 | movzx ebx, ch |
|
- | 282 | movzx ecx, cl |
|
- | 283 | add ecx, ecx |
|
- | 284 | bts dword [eax+10h], ecx ; set L flag |
|
- | 285 | add ecx, ecx |
|
- | 286 | mov [eax+ecx], edx ; set DR |
|
- | 287 | shl ebx, cl |
|
- | 288 | mov edx, 0xF |
|
- | 289 | shl edx, cl |
|
- | 290 | not edx |
|
- | 291 | and [eax+10h+2], dx |
|
- | 292 | or [eax+10h+2], bx ; set R/W and LEN fields |
|
- | 293 | imul eax, ebp, tss_step/32 |
|
- | 294 | or byte [eax + tss_data + l.trap - tss_sceleton], 1 |
|
- | 295 | jmp .okret |
|
232 | 296 | ||
233 | debug_read_process_memory: |
297 | debug_read_process_memory: |
234 | ; in: |
298 | ; in: |
235 | ; ebx=pid |
299 | ; ebx=pid |
236 | ; ecx=length |
300 | ; ecx=length |
Line 286... | Line 350... | ||
286 | ; ecx=size of debug message |
350 | ; ecx=size of debug message |
287 | ; [esp+4]..[esp+4+ecx]=message |
351 | ; [esp+4]..[esp+4+ecx]=message |
288 | ; interrupts must be disabled! |
352 | ; interrupts must be disabled! |
289 | ; destroys all general registers |
353 | ; destroys all general registers |
290 | ; interrupts remain disabled |
354 | ; interrupts remain disabled |
291 | mov ebp, eax |
355 | xchg ebp, eax |
292 | shl eax, 8 |
- | |
293 | mov edi, [timer_ticks] |
356 | mov edi, [timer_ticks] |
294 | add edi, 500 ; 5 sec timeout |
357 | add edi, 500 ; 5 sec timeout |
295 | .1: |
358 | .1: |
- | 359 | mov eax, ebp |
|
- | 360 | shl eax, 8 |
|
296 | mov edx, [0x80000+eax+0xBC] |
361 | mov edx, [0x80000+eax+0xBC] |
297 | test edx, edx |
362 | test edx, edx |
298 | jz .ret |
363 | jz .ret |
299 | ; read buffer header |
364 | ; read buffer header |
300 | push ecx |
365 | push ecx |
Line 313... | Line 378... | ||
313 | jg @f |
378 | jg @f |
314 | .2: |
379 | .2: |
315 | pop ecx |
380 | pop ecx |
316 | pop ecx |
381 | pop ecx |
317 | pop ecx |
382 | pop ecx |
- | 383 | cmp dword [0x3000], 1 |
|
- | 384 | jnz .notos |
|
318 | cmp [timer_ticks], edi |
385 | cmp [timer_ticks], edi |
319 | jae .ret |
386 | jae .ret |
- | 387 | .notos: |
|
320 | sti |
388 | sti |
321 | call change_task |
389 | call change_task |
322 | cli |
390 | cli |
323 | jmp .1 |
391 | jmp .1 |
324 | @@: |
392 | @@: |
Line 347... | Line 415... | ||
347 | mov eax, ebp |
415 | mov eax, ebp |
348 | shl eax, 8 |
416 | shl eax, 8 |
349 | or byte [0x80000+eax+0xA8+1], 1 ; set flag 100h |
417 | or byte [0x80000+eax+0xA8+1], 1 ; set flag 100h |
350 | .ret: |
418 | .ret: |
351 | ret |
419 | ret |
- | 420 | ||
- | 421 | debug_exc: |
|
- | 422 | ; int 1 = #DB |
|
- | 423 | save_ring3_context |
|
- | 424 | mov ax, os_data |
|
- | 425 | mov ds, ax |
|
- | 426 | mov es, ax |
|
- | 427 | mov eax, dr6 |
|
- | 428 | test ax, ax |
|
- | 429 | jns @f |
|
- | 430 | ; this is exception from task switch |
|
- | 431 | ; set DRx registers for task and continue |
|
- | 432 | mov eax, [0x3000] |
|
- | 433 | shl eax, 8 |
|
- | 434 | add eax, 0x80000+0xC0 |
|
- | 435 | mov ecx, [eax+0] |
|
- | 436 | mov dr0, ecx |
|
- | 437 | mov ecx, [eax+4] |
|
- | 438 | mov dr1, ecx |
|
- | 439 | mov ecx, [eax+8] |
|
- | 440 | mov dr2, ecx |
|
- | 441 | mov ecx, [eax+0Ch] |
|
- | 442 | mov dr3, ecx |
|
- | 443 | xor ecx, ecx |
|
- | 444 | mov dr6, ecx |
|
- | 445 | mov ecx, [eax+10h] |
|
- | 446 | mov dr7, ecx |
|
- | 447 | restore_ring3_context |
|
- | 448 | iretd |
|
- | 449 | @@: |
|
- | 450 | push eax |
|
- | 451 | xor eax, eax |
|
- | 452 | mov dr6, eax |
|
- | 453 | ; test if debugging |
|
- | 454 | cli |
|
- | 455 | mov eax, [0x3000] |
|
- | 456 | shl eax, 8 |
|
- | 457 | mov eax, [0x80000+eax+0xAC] |
|
- | 458 | test eax, eax |
|
- | 459 | jnz .debug |
|
- | 460 | sti |
|
- | 461 | ; not debuggee => say error and terminate |
|
- | 462 | add esp, 28h+4 |
|
- | 463 | mov [error_interrupt], 1 |
|
- | 464 | call show_error_parameters |
|
- | 465 | mov edx, [0x3010] |
|
- | 466 | mov byte [edx+0xA], 4 |
|
- | 467 | jmp change_task |
|
- | 468 | .debug: |
|
- | 469 | ; we are debugged process, notify debugger and suspend ourself |
|
- | 470 | ; eax=debugger PID |
|
- | 471 | pop edx |
|
- | 472 | mov ebx, dr7 |
|
- | 473 | mov cl, not 1 |
|
- | 474 | .l1: |
|
- | 475 | test bl, 1 |
|
- | 476 | jnz @f |
|
- | 477 | and dl, cl |
|
- | 478 | @@: |
|
- | 479 | shr ebx, 2 |
|
- | 480 | add cl, cl |
|
- | 481 | inc ecx |
|
- | 482 | cmp cl, not 10h |
|
- | 483 | jnz .l1 |
|
- | 484 | push edx ; DR6 image |
|
- | 485 | mov ecx, [0x3010] |
|
- | 486 | push dword [ecx+4] ; PID |
|
- | 487 | push 12 |
|
- | 488 | pop ecx |
|
- | 489 | push 3 ; 3 = debug exception |
|
- | 490 | call debugger_notify |
|
- | 491 | pop ecx |
|
- | 492 | pop ecx |
|
- | 493 | pop ecx |
|
- | 494 | mov edx, [0x3010] |
|
- | 495 | mov byte [edx+0xA], 1 ; suspended |
|
- | 496 | call change_task |
|
- | 497 | restore_ring3_context |
|
- | 498 | iretd |