Subversion Repositories Kolibri OS

Rev

Rev 4443 | Rev 4591 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
205 heavyiron 1
format binary
542 diamond 2
include '../../macros.inc'
205 heavyiron 3
use32
3675 GerdtR 4
        db      'MENUET01'
5
        dd      1
6
        dd      start
7
        dd      i_end
8
        dd      used_mem
9
        dd      used_mem
10
        dd      i_param
11
        dd      0
205 heavyiron 12
 
3675 GerdtR 13
;-----------------------------------------------------------------------------
14
 
15
REG_MODE_CPU equ 1
16
REG_MODE_MMX equ 2
17
REG_MODE_SSE equ 3
18
REG_MODE_AVX equ 4
19
 
20
;-----------------------------------------------------------------------------
21
 
22
include 'gui.inc' ; GUI routines
23
 
24
;-----------------------------------------------------------------------------
25
;                          Find command in list
26
 
27
find_cmd:
28
; all commands are case-insensitive
29
        push    edi
30
 
31
    .x4:
32
        mov     al, [edi]
33
        cmp     al, 0
34
        jz      .x5
35
        cmp     al, 'A'
36
        jb      @f
37
        cmp     al, 'Z'
38
        ja      @f
39
        or      al, 20h
40
 
41
    @@:
42
        stosb
43
        jmp     .x4
44
 
45
    ; find command
46
    .x5:
47
        pop     edi
48
 
49
    .x6:
50
        cmp     dword [esi], 0
51
        jz      .x7
52
        push    esi
53
        mov     esi, [esi]
54
        lodsb
55
        movzx   ecx, al
56
        push    edi
57
        repz cmpsb
58
        pop     edi
59
        pop     esi
60
        jz      .x8
61
        add     esi, 17
62
        jmp     .x6
63
 
64
    .x7:
65
        stc
66
 
67
    .x8:
68
        ret
69
 
205 heavyiron 70
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3675 GerdtR 71
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEBUGGING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
205 heavyiron 72
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73
 
3675 GerdtR 74
;-----------------------------------------------------------------------------
75
;                                 Help event
205 heavyiron 76
 
3675 GerdtR 77
OnHelp:
78
        mov     esi, help_msg
79
        mov     edi, [curarg]
80
        cmp     byte [edi], 0
81
        jz      .x
82
        mov     esi, help_groups
83
        call    find_cmd
84
        jc      .nocmd
85
        mov     esi, [esi+12]
205 heavyiron 86
 
3675 GerdtR 87
    .x:
88
        jmp     put_message
205 heavyiron 89
 
3675 GerdtR 90
    .nocmd:
91
        mov     esi, aUnknownCommand
92
        jmp     .x
205 heavyiron 93
 
3675 GerdtR 94
;-----------------------------------------------------------------------------
95
;                                Quit event
96
OnQuit:
97
        mcall  -1
205 heavyiron 98
 
3675 GerdtR 99
;-----------------------------------------------------------------------------
100
;                        Working with debug context
205 heavyiron 101
 
3675 GerdtR 102
get_new_context:
103
        mov     esi, context
104
        mov     edi, oldcontext
105
        mov     ecx, 10
106
        rep movsd
205 heavyiron 107
 
3675 GerdtR 108
get_context:
109
        ;push    1
110
        ;pop     ebx
111
        ;push    69
112
        ;pop     eax
113
        ;mov     ecx, [debuggee_pid]
114
        ;mov     esi, context
115
        ;push    28h
116
        ;pop     edx
117
        mcall    69, 1, [debuggee_pid], 28h, context
118
        ret
205 heavyiron 119
 
3675 GerdtR 120
set_context:
121
        ;push    2
122
        ;pop     ebx
123
        ;push    69
124
        ;pop     eax
125
        ;mov     ecx, [debuggee_pid]
126
        ;mov     esi, context
127
        ;push    28h
128
        ;pop     edx
129
        mcall    69, 2, [debuggee_pid], 28h, context
130
        ret
205 heavyiron 131
 
3675 GerdtR 132
get_dump:
133
        mov     edi, dumpdata
134
        mov     esi, [edi-4]
135
        mov     edx, dump_height*10h
136
        mov     ecx, edx
137
        xor     eax, eax
138
        push    edi
139
        rep stosb
140
        pop     edi
141
        ;mov     ecx, [debuggee_pid]
142
        ;mov     al, 69
143
        ;push    6
144
        ;pop     ebx
145
        mcall    69, 6, [debuggee_pid]
146
        cmp     eax, -1
147
        jnz     @f
148
        mov     esi, read_mem_err
149
        call    put_message
150
        xor     eax, eax
205 heavyiron 151
 
3675 GerdtR 152
    @@:
153
        mov     [edi-8], eax
154
;       call    restore_from_breaks
155
;       ret
205 heavyiron 156
 
3675 GerdtR 157
; in: edi=buffer,eax=size,esi=address
158
restore_from_breaks:
159
        mov     ebx, breakpoints
205 heavyiron 160
 
3675 GerdtR 161
    @@:
162
        test    byte [ebx+4], 1
163
        jz      .cont           ; ignore invalid
164
        test    byte [ebx+4], 2 or 8
165
        jnz     .cont           ; ignore disabled and memory breaks
166
        mov     ecx, [ebx]
167
        sub     ecx, esi
168
        cmp     ecx, eax
169
        jae     .cont
170
        mov     dl, [ebx+5]
171
        mov     [edi+ecx], dl
205 heavyiron 172
 
3675 GerdtR 173
    .cont:
174
        add     ebx, 6
175
        cmp     ebx, breakpoints+breakpoints_n*6
176
        jb      @b
177
        ret
205 heavyiron 178
 
3675 GerdtR 179
;-----------------------------------------------------------------------------
180
;                           Load executable event
205 heavyiron 181
 
3675 GerdtR 182
OnLoad:
183
        mov     esi, [curarg]
205 heavyiron 184
 
3675 GerdtR 185
OnLoadInit:
186
        mov     edi, loadname
187
        or      [prgname_len], -1
188
        mov     [prgname_ptr], edi
205 heavyiron 189
 
3675 GerdtR 190
    .copyname:
191
        lodsb
192
        stosb
193
        inc     [prgname_len]
194
        cmp     al, '/'
195
        jnz     @f
196
        or      [prgname_len], -1
197
        mov     [prgname_ptr], edi
205 heavyiron 198
 
3675 GerdtR 199
    @@:
200
        cmp     al, ' '
201
        ja      .copyname
202
        mov     byte [edi-1], 0
203
        and     [load_params], 0
204
        dec     esi
205
        call    get_arg.skip_spaces
206
        cmp     al, 0
207
        jz      @f
208
        mov     [load_params], esi
205 heavyiron 209
 
3675 GerdtR 210
    @@:
211
        and     [dumppos], 0
212
        mov     ecx, [symbols]
213
        jecxz   do_reload
214
        mcall   68, 13
215
        and     [symbols], 0
216
        and     [num_symbols], 0
205 heavyiron 217
 
3675 GerdtR 218
; TODO: make it local
219
do_reload:
220
        ;push    18
221
        ;pop     eax
222
        ;push    7
223
        ;pop     ebx
224
        mcall    18, 7
225
        mov     [dbgwnd], eax
226
        xchg    ecx, eax
227
        ;push    70
228
        ;pop     eax
229
        ;mov     ebx, fn70_load_block
230
        mcall    70, fn70_load_block
231
        test    eax, eax
232
        jns     .load_ok
205 heavyiron 233
 
3675 GerdtR 234
    .load_err:
235
        push    eax
236
        mov     esi, load_err_msg
237
        call    put_message
238
        pop     eax
239
        not     eax
240
        cmp     eax, 0x20
241
        jae     .unk_err
242
        mov     esi, [load_err_msgs+eax*4]
243
        test    esi, esi
244
        jnz     put_message
205 heavyiron 245
 
3675 GerdtR 246
    .unk_err:
247
        mov     esi, unk_err_msg
248
        inc     eax
249
        push    eax
250
        call    put_message_nodraw
251
        jmp     draw_messages
205 heavyiron 252
 
3675 GerdtR 253
    .load_ok:
254
        mov     [debuggee_pid], eax
255
        mov     [bSuspended], 1
256
        push    ecx
257
        call    get_context
258
        mov     edi, oldcontext
259
        mov     ecx, 10
260
        rep movsd
205 heavyiron 261
 
3675 GerdtR 262
    ; activate debugger window
263
        pop     ecx
264
        ;mov     bl, 3
265
        ;push    18
266
        ;pop     eax
267
        mcall    18, 3
268
        call    redraw_title
269
        call    draw_registers.redraw
270
    ; read and draw dump of memory
271
        call    get_dump
272
        call    draw_dump.redraw
273
        call    update_disasm_eip_force
274
        mov     esi, load_succ_msg
275
        push    [debuggee_pid]
276
        call    put_message_nodraw
277
        call    draw_messages
278
    ; try to load symbols
279
        mov     esi, loadname
280
        mov     edi, symbolsfile
281
        push    edi
205 heavyiron 282
 
3675 GerdtR 283
    @@:
284
        lodsb
285
        stosb
286
        test    al, al
287
        jnz     @b
288
        lea     ecx, [edi-1]
205 heavyiron 289
 
3675 GerdtR 290
    @@:
291
        dec     edi
292
        cmp     edi, symbolsfile
293
        jb      @f
294
        cmp     byte [edi], '/'
295
        jz      @f
296
        cmp     byte [edi], '.'
297
        jnz     @b
298
        mov     ecx, edi
205 heavyiron 299
 
3675 GerdtR 300
    @@:
301
        mov     dword [ecx], '.dbg'
302
        mov     byte [ecx+4], 0
303
        pop     esi
304
        mov     ebp, esi
305
        call    OnLoadSymbols.silent
306
 
307
    ; now test for packed progs
308
        cmp     [disasm_buf_size], 100h
309
        jz      @f
310
        ret
205 heavyiron 311
 
3675 GerdtR 312
    @@:
313
        mov     esi, mxp_nrv_sig
314
        mov     ebp, disasm_buffer
315
        mov     edi, ebp
316
        push    3
317
        pop     ecx
318
        repz cmpsb
319
        jnz     .not_mxp_nrv
320
        cmpsb
321
        mov     cl, mxp_nrv_sig_size-4
322
        repz cmpsb
323
        mov     esi, mxp_nrv_name
324
        jz      .packed
205 heavyiron 325
 
3675 GerdtR 326
    .not_mxp_nrv:
327
        mov     esi, mxp_sig
328
        mov     edi, ebp
329
        mov     cl, mxp_sig_size
330
        repz cmpsb
331
        mov     esi, mxp_name
332
        jz      .packed
205 heavyiron 333
 
3675 GerdtR 334
    .not_mxp:
335
        mov     esi, mxp_lzo_sig1
336
        mov     edi, ebp
337
        mov     cl, mxp_lzo_sig1_size
338
        repz cmpsb
339
        mov     esi, mxp_lzo_name
340
        jz      .packed
341
        mov     esi, mxp_lzo_sig2
342
        mov     edi, ebp
343
        mov     cl, 8
344
        repz cmpsb
345
        jnz     .not_mxp_lzo
346
        cmpsb
347
        mov     cl, mxp_lzo_sig2_size - 9
348
        repz cmpsb
349
        mov     esi, mxp_lzo_name
350
        jz      .packed
205 heavyiron 351
 
3675 GerdtR 352
    .not_mxp_lzo:
353
        mov     esi, mtappack_name
354
        cmp     dword [ebp], 0xBF5E246A
355
        jnz     .not_mtappack
356
        cmp     dword [ebp+8], 0xEC4E8B57
357
        jnz     .not_mtappack1
358
        cmp     dword [ebp+12], 0x8D5EA4F3
359
        jnz     .not_mtappack1
360
        cmp     byte [ebp+12h], 0xE9
361
        jz      .packed
362
 
363
    .not_mtappack1:
364
        cmp     word [ebp+8], 0xB957
365
        jnz     .not_mtappack
366
        cmp     dword [ebp+14], 0x575EA4F3
367
        jnz     .not_mtappack2
368
        cmp     byte [ebp+17h], 0xE9
369
        jz      .packed
370
 
371
    .not_mtappack2:
372
        cmp     dword [ebp+14], 0x5F8DA4F3
373
        jnz     .not_mtappack3
374
        cmp     word [ebp+18], 0xE9FC
375
        jz      .packed
376
 
377
    .not_mtappack3:
378
        cmp     word [ebp+14], 0xA4F3
379
        jnz     .not_mtappack
380
        cmp     byte [ebp+15h], 0xE9
381
        jz      .packed
382
 
383
    .not_mtappack:
384
        ret
385
 
386
    .packed:
387
        push    esi
388
        mov     esi, aPacked1
389
        call    put_message_nodraw
390
        pop     esi
391
        call    put_message_nodraw
392
        mov     esi, aPacked2
393
        call    put_message
394
        call    hide_cursor
395
        ;push    40
396
        ;pop     eax
397
        ;push    7
398
        ;pop     ebx
399
        mcall    40, 7
400
 
401
    .wait:
402
        ;push    10
403
        ;pop     eax
404
        mcall    10
405
        dec     eax
406
        jz      .redraw
407
        dec     eax
408
        jz      .key
409
        or      eax, -1
410
        mcall
411
 
412
    .redraw:
413
        call    draw_window
414
        call    hide_cursor
415
        jmp     .wait
416
 
417
    .key:
418
        mov     al, 2
419
        mcall
420
        cmp     ah, 'y'
421
        jz      .yes
422
        cmp     ah, 'Y'
423
        jz      .yes
424
        cmp     ah, 0xD
425
        jz      .yes
426
        cmp     ah, 'n'
427
        jz      .no
428
        cmp     ah, 'N'
429
        jnz     .wait
430
 
431
    .no:
432
        ;push    40
433
        ;pop     eax
434
        ;mov     ebx, 0x107
435
        mcall    40, 0x107
436
        call    draw_cursor
437
        mov     esi, aN_str
438
        jmp     put_message
439
 
440
    .yes:
441
        ;push    40
442
        ;pop     eax
443
        ;mov     ebx, 0x107
444
        mcall    40, 0x107
445
        call    draw_cursor
446
        mov     esi, aY_str
447
        call    put_message
448
        call    OnUnpack
449
        ret
450
 
451
;-----------------------------------------------------------------------------
452
;                       Searching signatures
453
 
205 heavyiron 454
mxp_nrv_sig:
3675 GerdtR 455
        xor     eax, eax
456
        mov     ecx, 0x95       ; 0xA1 for programs with parameters
457
        mov     [eax], ecx
458
        add     ecx, [eax+24h]
459
        push    40h
460
        pop     esi
461
        mov     edi, [eax+20h]
462
        push    edi
463
        rep movsb
464
        jmp     dword [esp]
465
        pop     esi
466
        add     esi, [eax]
467
        xor     edi, edi
468
 
205 heavyiron 469
mxp_nrv_sig_size = $ - mxp_nrv_sig
470
 
471
mxp_sig:
3675 GerdtR 472
        mov     ecx, 1CBh
473
        push    46h
474
        pop     esi
475
        mov     edi, [20h]
476
        rep movsb
477
        mov     ecx, [24h]
478
        rep movsb
479
        jmp     dword [20h]
480
        mov     eax, [20h]
481
        add     eax, 1CBh
482
        push    eax
483
        push    dword [24h]
484
        push    0
485
        push    8
486
        call    $+0x25
487
 
205 heavyiron 488
mxp_sig_size = $ - mxp_sig
489
 
490
mxp_lzo_sig1:
3675 GerdtR 491
        xor     eax, eax
492
        mov     ebp, 0FFh
493
        mov     ecx, 175h
494
        mov     [eax], ecx
495
        add     ecx, [eax+24h]
496
        push    45h
497
        pop     esi
498
        mov     edi, [eax+20h]
499
        push    edi
500
        rep movsb
501
        jmp     dword [esp]
502
        pop     ebx
503
        add     ebx, [eax]
504
        xor     edi, edi
505
        cmp     byte [ebx], 11h
506
        jbe     $+0x1A
507
 
205 heavyiron 508
mxp_lzo_sig1_size = $ - mxp_lzo_sig1
3675 GerdtR 509
 
205 heavyiron 510
mxp_lzo_sig2:
3675 GerdtR 511
        xor     eax, eax
512
        mov     ebp, 0FFh
513
        mov     ecx, 188h       ; or 177h
514
        mov     [eax], ecx
515
        add     ecx, [eax+24h]
516
        push    44h
517
        pop     esi
518
        mov     edi, [eax+20h]
519
        rep movsb
520
        jmp     dword [eax+20h]
521
        mov     ebx, [eax+20h]
522
        add     ebx, [eax]
523
 
205 heavyiron 524
mxp_lzo_sig2_size = $ - mxp_lzo_sig2
525
 
3675 GerdtR 526
;-----------------------------------------------------------------------------
527
;                         Reload executable event
528
 
205 heavyiron 529
OnReload:
3675 GerdtR 530
        cmp     [debuggee_pid], 0
531
        jnz     terminate_reload
532
        mov     esi, need_debuggee
533
        cmp     byte [loadname], 0
534
        jnz     do_reload
535
        jz      put_message
536
 
537
; TODO: make it local
205 heavyiron 538
terminate_reload:
3675 GerdtR 539
        mov     [bReload], 1
540
 
541
;-----------------------------------------------------------------------------
542
;                        Terminate process event
543
 
205 heavyiron 544
OnTerminate:
3675 GerdtR 545
        ;mov     ecx, [debuggee_pid]
546
        ;push    8
547
        ;pop     ebx
548
        ;push    69
549
        ;pop     eax
550
        mcall    69, 8, [debuggee_pid]
551
        ret
552
;-----------------------------------------------------------------------------
553
;                         Suspend process event
205 heavyiron 554
 
555
AfterSuspend:
3675 GerdtR 556
        mov     [bSuspended], 1
557
        call    get_new_context
558
        call    get_dump
559
        call    redraw_title
560
        call    draw_registers.redraw
561
        call    draw_dump.redraw
562
        call    update_disasm_eip
563
        ret
205 heavyiron 564
 
565
OnSuspend:
3675 GerdtR 566
        ;mov     ecx, [debuggee_pid]
567
        ;push    4
568
        ;pop     ebx
569
        ;push    69
570
        ;pop     eax
571
        mcall    69, 4, [debuggee_pid]
572
        call    AfterSuspend
573
        mov     esi, aSuspended
574
        jmp     put_message
575
 
576
;-----------------------------------------------------------------------------
577
;                        Resume process event
578
 
205 heavyiron 579
DoResume:
3675 GerdtR 580
        ;mov     ecx, [debuggee_pid]
581
        ;push    5
582
        ;pop     ebx
583
        ;push    69
584
        ;pop     eax
585
        mcall    69, 5, [debuggee_pid]
586
        mov     [bSuspended], 0
587
        ret
588
 
205 heavyiron 589
OnResume:
3675 GerdtR 590
        mov     esi, [curarg]
591
        cmp     byte [esi], 0
592
        jz      GoOn
593
        call    calc_expression
594
        jc      .ret
595
        mov     eax, ebp
596
        push    eax
597
        call    find_enabled_breakpoint
598
        pop     eax
599
        jz      GoOn
600
        mov     bl, 5   ; valid enabled one-shot
601
        call    add_breakpoint
602
        jnc     GoOn
603
        mov     esi, aBreakpointLimitExceeded
604
        call    put_message
605
 
606
    .ret:
607
        ret
608
 
205 heavyiron 609
GoOn:
3675 GerdtR 610
    ; test for enabled breakpoint at eip
611
        mov     eax, [_eip]
612
        call    find_enabled_breakpoint
613
        jnz     .nobreak
614
    ; temporarily disable breakpoint, make step, enable breakpoint, continue
615
        inc     eax
616
        mov     [temp_break], eax
617
        mov     [bAfterGo], 1
618
        dec     eax
619
        call    disable_breakpoint
620
        call    get_context
621
        or      byte [_eflags+1], 1             ; set TF
622
        call    set_context
623
        and     byte [_eflags+1], not 1
624
        call    DoResume
625
        ret
626
 
627
    .nobreak:
628
        call    DoResume
629
        call    redraw_title
630
        call    draw_registers.redraw
631
        call    draw_dump.redraw
632
        ret
633
 
634
;-----------------------------------------------------------------------------
635
;                        Detach process event
636
 
205 heavyiron 637
OnDetach:
3675 GerdtR 638
        ;mov     ecx, [debuggee_pid]
639
        ;push    3
640
        ;pop     ebx
641
        ;push    69
642
        ;pop     eax
643
        mcall    69, 3, [debuggee_pid]
644
        and     [debuggee_pid], 0
645
        call    redraw_title
646
        call    draw_registers.redraw
647
        call    draw_dump.redraw
648
        call    free_symbols
649
        mov     esi, aContinued
650
        jmp     put_message
205 heavyiron 651
 
652
after_go_exception:
3675 GerdtR 653
        push    eax
654
        mov     eax, [temp_break]
655
        dec     eax
656
        push    esi
657
        call    enable_breakpoint
658
    ; in any case, clear TF and RF
659
        call    get_new_context
660
        and     [_eflags], not 10100h           ; clear TF,RF
661
        call    set_context
662
        xor     edx, edx
663
        mov     [temp_break], edx
664
        xchg    dl, [bAfterGo]
665
        pop     esi
666
        pop     eax
667
        cmp     dl, 2
668
        jnz     @f
669
        lodsd
670
        push    esi
671
        call    get_dump
672
        jmp     exception.done
205 heavyiron 673
 
3675 GerdtR 674
    @@:
675
        test    eax, eax
676
        jz      .notint1
677
    ; if exception is result of single step, simply ignore it and continue
678
        test    dword [esi], 0xF
679
        jnz     dbgmsgstart.5
680
        lodsd
681
        push    esi
682
        mov     esi, oldcontext
683
        mov     edi, context
684
        mov     ecx, 28h/4
685
        rep movsd
686
        call    DoResume
687
        jmp     dbgmsgend
688
 
689
    .notint1:
690
    ; in other case, work as without temp_break
691
        lodsd
692
        push    esi
693
        push    eax
694
        jmp     exception.4
695
 
696
    .notour:
697
 
698
; TODO: split it out
205 heavyiron 699
debugmsg:
3675 GerdtR 700
        neg     [dbgbufsize]
701
        mov     esi, dbgbuf
702
 
703
; TODO: make it local
205 heavyiron 704
dbgmsgstart:
3675 GerdtR 705
        lodsd
706
;       push    eax esi
707
;       push    dword [esi]
708
;       mov     esi, dbgmsg_str
709
;       call    put_message_nodraw
710
;       pop     esi eax
711
        add     esi, 4
712
        dec     eax
713
        jz      exception
714
        dec     eax
715
        jz      terminated
716
        mov     [bSuspended], 1
717
        cmp     [bAfterGo], 0
718
        jnz     after_go_exception
719
        push    esi
720
        call    get_new_context
721
        and     [_eflags], not 10100h           ; clear TF,RF
722
        call    set_context
723
        pop     esi
724
 
725
    ; TODO: WTF? Need for meaning label names
726
    .5:
727
        push    esi
728
        call    get_dump
729
        pop     esi
730
        lodsd
731
        xor     ecx, ecx
732
 
733
    .6:
734
        bt      eax, ecx
735
        jnc     .7
736
        mov     ebx, [drx_break+ecx*4]
737
        test    ebx, ebx
738
        jz      .7
739
        pushad
740
        dec     ebx
741
        push    ebx
742
        mov     esi, aBreakStop
743
        call    put_message_nodraw
744
        popad
745
 
746
    .7:
747
        inc     ecx
748
        cmp     cl, 4
749
        jb      .6
750
        push    esi
751
        jmp     exception.done_draw
752
 
753
; TODO: make it local
205 heavyiron 754
terminated:
3675 GerdtR 755
        push    esi
756
        mov     esi, terminated_msg
757
        call    put_message
758
        and     [debuggee_pid], 0
759
        and     [temp_break], 0
760
        mov     [bAfterGo], 0
761
        xor     eax, eax
762
        mov     ecx, breakpoints_n*6/4+4
763
        mov     edi, breakpoints
764
        rep stosd
765
        cmp     [bReload], 1
766
        sbb     [bReload], -1
767
        jnz     exception.done
768
        call    free_symbols
769
        jmp     exception.done
770
 
205 heavyiron 771
exception:
3675 GerdtR 772
        mov     [bSuspended], 1
773
        cmp     [bAfterGo], 0
774
        jnz     after_go_exception
775
        lodsd
776
        push    esi
777
        push    eax
778
        call    get_new_context
779
        and     [_eflags], not 10100h           ; clear TF,RF
780
        call    set_context
781
 
782
    ; TODO: fix for useful name
783
    .4:
784
        call    get_dump
785
        pop     eax
786
    ; int3 command generates exception 0D, #GP
787
        push    eax
788
        cmp     al, 0Dh
789
        jnz     .notdbg
790
    ; check for 0xCC byte at eip
791
        push    0
792
        ;push    69
793
        ;pop     eax
794
        ;push    6
795
        ;pop     ebx
796
        ;mov     ecx, [debuggee_pid]
797
        ;mov     edi, esp
798
        ;mov     esi, [_eip]
799
        ;push    1
800
        ;pop     edx
801
        mcall    69, 6, [debuggee_pid], 1, [_eip], esp
802
        pop     eax
803
        cmp     al, 0xCC
804
        jnz     .notdbg
805
    ; this is either dbg breakpoint or int3 cmd in debuggee
806
        mov     eax, [_eip]
807
        call    find_enabled_breakpoint
808
        jnz     .user_int3
809
    ; dbg breakpoint; clear if one-shot
810
        pop     ecx
811
        push    eax
812
        mov     esi, aBreakStop
813
        test    byte [edi+4], 4
814
        jz      .put_msg_eax
815
        pop     ecx
816
        call    clear_breakpoint
817
        jmp     .done
818
 
819
    .user_int3:
820
        mov     eax, [_eip]
821
        inc     [_eip]
822
        pop     ecx
823
        push    eax
824
        call    set_context
825
        mov     esi, aUserBreak
826
        jmp     .put_msg_eax
827
 
828
    .notdbg:
829
        mov     esi, aException
830
 
831
    .put_msg_eax:
832
        call    put_message_nodraw
833
 
834
    .done_draw:
835
        call    draw_messages
836
 
837
    .done:
838
        ;push    18
839
        ;pop     eax
840
        ;push    3
841
        ;pop     ebx
842
        ;mov     ecx, [dbgwnd]
843
        mcall    18, 3, [dbgwnd]    ; activate dbg window
844
        call    redraw_title
845
        call    draw_registers.redraw
846
        call    draw_dump.redraw
847
        call    update_disasm_eip
848
 
205 heavyiron 849
dbgmsgend:
3675 GerdtR 850
        pop     esi
851
        mov     ecx, [dbgbuflen]
852
        add     ecx, dbgbuf
853
        cmp     esi, ecx
854
        jnz     dbgmsgstart
855
        and     [dbgbuflen], 0
856
        neg     [dbgbufsize]
857
        cmp     [bReload], 2
858
        jnz     @f
859
        mov     [bReload], 0
860
        call    do_reload
205 heavyiron 861
 
3675 GerdtR 862
    @@:
863
        jmp     waitevent
864
 
865
; TODO: make it local
4590 clevermous 866
F7:
3675 GerdtR 867
        cmp     [debuggee_pid], 0
868
        jz      .no
869
        call    OnStep
870
 
871
    .no:
872
        jmp     waitevent
873
 
874
; TODO: make it local
4590 clevermous 875
F8:
3675 GerdtR 876
        cmp     [debuggee_pid], 0
4590 clevermous 877
        jz      F7.no
3675 GerdtR 878
        call    OnProceed
4590 clevermous 879
        jmp     F7.no
205 heavyiron 880
 
3675 GerdtR 881
;-----------------------------------------------------------------------------
882
;                       Step execution event
883
 
884
;Here we get [] argument at do step  times
4443 clevermous 885
OnStepMultiple:
3675 GerdtR 886
        cmp     [bSuspended], 0
4443 clevermous 887
        jz      OnStep.running
888
        mov     [step_num], 1
3675 GerdtR 889
        mov     esi, [curarg]
4443 clevermous 890
        test    esi, esi
891
        jz      .do
3675 GerdtR 892
        cmp     byte [esi], 0
4443 clevermous 893
        jz      .do
3675 GerdtR 894
        call    get_hex_number
895
        jc      .ret
896
        cmp     eax, 0 ; check if lesser or equal than 0
897
        jle     .ret
898
        mov     [step_num], eax
4443 clevermous 899
.do:
900
        call    OnStep
901
        dec     [step_num]
902
        jnz     .do
903
.ret:
904
        ret
205 heavyiron 905
 
4443 clevermous 906
OnStep:
907
        cmp     [bSuspended], 0
908
        jz      .running
3675 GerdtR 909
        call    get_context
910
        or      byte [_eflags+1], 1             ; set TF
911
        call    set_context
912
        and     byte [_eflags+1], not 1
913
    ; if instruction at eip is "int xx", set one-shot breakpoint immediately after
914
        mov     eax, [_eip]
915
        call    find_enabled_breakpoint
916
        jnz     @f
917
        cmp     byte [edi+5], 0xCD
918
        jz      .int
919
 
920
     @@:
921
        push    0
922
        ;push    69
923
        ;pop     eax
924
        ;push    6
925
        ;pop     ebx
926
        ;mov     ecx, [debuggee_pid]
927
        ;push    3
928
        ;pop     edx
929
        ;mov     edi, esp
930
        ;mov     esi, [_eip]
931
        mcall    69, 6, [debuggee_pid], 3, [_eip], esp
932
        cmp     eax, edx
933
        pop     eax
934
        jnz     .doit
935
        cmp     al, 0xCD
936
        jz      .int
937
        cmp     ax, 0x050F
938
        jz      .syscall
939
        cmp     ax, 0x340F
940
        jz      .sysenter
941
 
942
    ; resume process
943
    .doit:
944
        call    GoOn
945
        cmp     [bAfterGo], 0
946
        jz      @f
947
        mov     [bAfterGo], 2
948
 
949
    @@:
950
        ret
951
 
952
    ; return address is [ebp-4]
953
    .sysenter:
954
        push    0
955
        ;push    69
956
        ;pop     eax
957
        inc     edx     ; read 4 bytes
958
        mov     esi, [_ebp]
959
        sub     esi, 4
960
        mcall    69
961
        cmp     eax, edx
962
        pop     eax
963
        jnz     .syscall
964
        push    eax
965
        and     byte [_eflags+1], not 1
966
        call    set_context
967
        pop     eax
968
        jmp     @f
969
 
970
    .syscall:
971
        and     byte [_eflags+1], not 1 ; clear TF - avoid system halt (!)
972
        call    set_context
973
 
974
    .int:
975
        mov     eax, [_eip]
976
        inc     eax
977
        inc     eax
978
 
979
    @@:
980
        push    eax
981
        call    find_enabled_breakpoint
982
        pop     eax
983
        jz      .doit
984
    ; there is no enabled breakpoint yet; set temporary breakpoint
985
        mov     bl, 5
986
        call    add_breakpoint
987
        jmp     .doit
988
 
989
    .running:
990
        mov     esi, aRunningErr
991
        jmp     put_message
992
 
993
;-----------------------------------------------------------------------------
994
;                       Proceed process event
995
 
205 heavyiron 996
OnProceed:
3675 GerdtR 997
        cmp     [bSuspended], 0
998
        jz      OnStep.running
999
        cmp     [proc_num], 0
1000
        jg      .procone
1001
        mov     esi, [curarg]
4285 tserj 1002
        cmp     esi, 0
1003
        jz      .procone
3675 GerdtR 1004
        cmp     byte [esi], 0
1005
        jz      .procone
1006
        call    get_hex_number
1007
        jc      .ret
1008
        cmp     eax, 0 ; check if lesser than 0
1009
        jle     .ret
1010
        mov     [proc_num], eax
1011
        mov     [curarg], 0
205 heavyiron 1012
 
3675 GerdtR 1013
    .procone:
1014
        mov     esi, [_eip]
205 heavyiron 1015
 
3675 GerdtR 1016
    @@:
1017
        call    get_byte_nobreak
4443 clevermous 1018
        jc      OnStep
3675 GerdtR 1019
        inc     esi
1020
    ; skip prefixes
1021
        call    is_prefix
1022
        jz      @b
1023
        cmp     al, 0xE8        ; call
1024
        jnz     @f
1025
        add     esi, 4
1026
        jmp     .doit
205 heavyiron 1027
 
3675 GerdtR 1028
    ; A4,A5 = movs; A6,A7 = cmps
1029
    @@:
1030
        cmp     al, 0xA4
1031
        jb      @f
1032
        cmp     al, 0xA8
1033
        jb      .doit
205 heavyiron 1034
 
3675 GerdtR 1035
    ; AA,AB = stos; AC,AD = lods; AE,AF = scas
1036
    @@:
1037
        cmp     al, 0xAA
1038
        jb      @f
1039
        cmp     al, 0xB0
1040
        jb      .doit
205 heavyiron 1041
 
3675 GerdtR 1042
    ; E0 = loopnz; E1 = loopz; E2 = loop
1043
    @@:
1044
        cmp     al, 0xE0
1045
        jb      .noloop
1046
        cmp     al, 0xE2
1047
        ja      .noloop
1048
        inc     esi
1049
        jmp     .doit
205 heavyiron 1050
 
3675 GerdtR 1051
    ; FF /2 = call
1052
    .noloop:
1053
        cmp     al, 0xFF
4443 clevermous 1054
        jnz     OnStep
3675 GerdtR 1055
        call    get_byte_nobreak
4443 clevermous 1056
        jc      OnStep
3675 GerdtR 1057
        inc     esi
1058
        mov     cl, al
1059
        and     al, 00111000b
1060
        cmp     al, 00010000b
4443 clevermous 1061
        jnz     OnStep
3675 GerdtR 1062
    ; skip instruction
1063
        mov     al, cl
1064
        and     eax, 7
1065
        shr     cl, 6
1066
        jz      .mod0
1067
        jp      .doit
1068
        cmp     al, 4
1069
        jnz     @f
1070
        inc     esi
205 heavyiron 1071
 
3675 GerdtR 1072
    @@:
1073
        inc     esi
1074
        dec     cl
1075
        jz      @f
1076
        add     esi, 3
205 heavyiron 1077
 
3675 GerdtR 1078
    @@:
1079
        jmp     .doit
205 heavyiron 1080
 
3675 GerdtR 1081
    .mod0:
1082
        cmp     al, 4
1083
        jnz     @f
1084
        call    get_byte_nobreak
4443 clevermous 1085
        jc      OnStep
3675 GerdtR 1086
        inc     esi
1087
        and     al, 7
205 heavyiron 1088
 
3675 GerdtR 1089
    @@:
1090
        cmp     al, 5
1091
        jnz     .doit
1092
        add     esi, 4
205 heavyiron 1093
 
3675 GerdtR 1094
    .doit:
1095
    ; insert one-shot breakpoint at esi and resume
1096
        call    get_byte_nobreak
4443 clevermous 1097
        jc      OnStep
3675 GerdtR 1098
        mov     eax, esi
1099
        call    find_enabled_breakpoint
1100
        jz      @f
1101
        mov     eax, esi
1102
        mov     bl, 5
1103
        call    add_breakpoint
1104
        jmp     OnStep.doit
1105
 
1106
    @@:
1107
        mov     eax, [proc_num]
1108
        dec     eax
1109
        cmp     eax, 0
1110
        jle     .ret
1111
        mov     [proc_num], eax
1112
        jmp     .procone
1113
 
1114
    .ret:
1115
        mov     [proc_num], 0
1116
        ret
1117
 
1118
;-----------------------------------------------------------------------------
1119
;                        Read next byte of machine code
1120
 
1121
get_byte_nobreak:
1122
        mov     eax, esi
1123
        call    find_enabled_breakpoint
1124
        jnz     .nobreak
1125
        mov     al, [edi+5]
1126
        clc
1127
        ret
1128
 
1129
    .nobreak:
1130
        ;push    69
1131
        ;pop     eax
1132
        ;push    6
1133
        ;pop     ebx
1134
        ;mov     ecx, [debuggee_pid]
1135
        xor     edx, edx
1136
        push    edx
1137
        inc     edx
1138
        mov     edi, esp
1139
        mcall    69, 6, [debuggee_pid]
1140
        dec     eax
1141
        clc
1142
        jz      @f
1143
        stc
1144
 
1145
    @@:
1146
        pop     eax
1147
        ret
1148
 
1149
include 'parser.inc'
1150
 
1151
;-----------------------------------------------------------------------------
1152
;                        Calculate expression event
1153
 
205 heavyiron 1154
OnCalc:
3675 GerdtR 1155
        mov     esi, [curarg]
1156
        call    calc_expression
1157
        jc      .ret
1158
        push    ebp
1159
        mov     esi, calc_string
1160
        call    put_message_nodraw
1161
        jmp     draw_messages
1162
 
1163
    .ret:
1164
        ret
205 heavyiron 1165
 
3675 GerdtR 1166
;-----------------------------------------------------------------------------
1167
;                            Dump memory event
1168
 
205 heavyiron 1169
OnDump:
3675 GerdtR 1170
        mov     esi, [curarg]
1171
        cmp     byte [esi], 0
1172
        jnz     .param
1173
        add     [dumppos], dump_height*10h
1174
        jmp     .doit
1175
 
1176
    .param:
1177
        call    calc_expression
1178
        jc      .ret
1179
        mov     [dumppos], ebp
205 heavyiron 1180
 
3675 GerdtR 1181
    .doit:
1182
        call    get_dump
1183
        call    draw_dump.redraw
1184
 
1185
    .ret:
1186
        ret
1187
 
1188
;-----------------------------------------------------------------------------
1189
;                   Dissassemble block of executable event
1190
 
205 heavyiron 1191
OnUnassemble:
3675 GerdtR 1192
        mov     esi, [curarg]
1193
        cmp     byte [esi], 0
1194
        jnz     .param
1195
        mov     eax, [disasm_start_pos]
1196
        mov     ecx, disasm_height
1197
        mov     [disasm_cur_pos], eax
205 heavyiron 1198
 
3675 GerdtR 1199
    .l:
1200
        mov     eax, [disasm_cur_pos]
1201
        call    find_symbol
1202
        jc      @f
1203
        dec     ecx
1204
        jz      .m
1205
 
1206
    @@:
1207
        push    ecx
1208
        call    disasm_instr
1209
        pop     ecx
1210
        jc      .err
1211
        loop    .l
1212
 
1213
    .m:
1214
        mov     eax, [disasm_cur_pos]
1215
        jmp     .doit
1216
 
1217
    .param:
1218
        call    calc_expression
1219
        jc      .ret
1220
        mov     eax, ebp
1221
 
1222
    .doit:
1223
        push    eax
1224
        push    [disasm_start_pos]
1225
        mov     [disasm_start_pos], eax
1226
        call    update_disasm
1227
        pop     [disasm_start_pos]
1228
        pop     eax
1229
        cmp     [disasm_cur_str], 0
1230
        jz      @f
1231
        mov     [disasm_start_pos], eax
1232
 
1233
    .ret:
1234
        ret
1235
 
1236
    @@:
1237
        call    update_disasm
1238
 
1239
    .err:
1240
        mov     esi, aInvAddr
1241
        jmp     put_message
1242
 
1243
;-----------------------------------------------------------------------------
1244
;                       Access to register value event
1245
 
205 heavyiron 1246
OnReg:
3675 GerdtR 1247
        mov     esi, [curarg]
1248
        call    get_arg.skip_spaces
1249
        call    find_reg
1250
        jnc     @f
205 heavyiron 1251
 
3675 GerdtR 1252
    .err:
1253
        mov     esi, RSyntax
1254
        jmp     put_message
1255
 
1256
    @@:
1257
        call    get_arg.skip_spaces
1258
        test    al, al
1259
        jz      .err
1260
        cmp     al, '='
1261
        jnz     @f
1262
        inc     esi
1263
        call    get_arg.skip_spaces
1264
        test    al, al
1265
        jz      .err
1266
 
1267
    @@:
1268
        push    edi
1269
        call    calc_expression
1270
        pop     edi
1271
        jc      .ret
1272
    ; now edi=register id, ebp=value
1273
        cmp     [bSuspended], 0
1274
        mov     esi, aRunningErr
1275
        jz      put_message
1276
        xchg    eax, ebp
1277
        cmp     edi, 24
1278
        jz      .eip
1279
        sub     edi, 4
1280
        jb      .8lo
1281
        sub     edi, 4
1282
        jb      .8hi
1283
        sub     edi, 8
1284
        jb      .16
1285
        mov     [_eax+edi*4], eax
1286
        jmp     .ret
1287
 
1288
    .16:
1289
        mov     word [_eax+(edi+8)*4], ax
1290
        jmp     .ret
1291
 
1292
    .8lo:
1293
        mov     byte [_eax+(edi+4)*4], al
1294
        jmp     .ret
1295
 
1296
    .8hi:
1297
        mov     byte [_eax+(edi+4)*4+1], al
1298
        jmp     .ret
1299
 
1300
    .eip:
1301
        mov     [_eip], eax
1302
        call    update_disasm_eip
1303
 
1304
    .ret:
1305
        call    set_context
1306
        jmp     draw_registers.redraw
1307
 
1308
;-----------------------------------------------------------------------------
1309
;                        Breakpoints manipulation
205 heavyiron 1310
OnBp:
3675 GerdtR 1311
        mov     esi, [curarg]
1312
        call    calc_expression
1313
        jc      .ret
1314
        xchg    eax, ebp
1315
        push    eax
1316
        call    find_breakpoint
1317
        inc     eax
1318
        pop     eax
1319
        jz      .notfound
1320
        mov     esi, aDuplicateBreakpoint
1321
        jmp     .sayerr
205 heavyiron 1322
 
3675 GerdtR 1323
    .notfound:
1324
        mov     bl, 1
1325
        call    add_breakpoint
1326
        jnc     .ret
1327
        mov     esi, aBreakpointLimitExceeded
1328
 
1329
    .sayerr:
1330
        call    put_message
1331
 
1332
    .ret:
1333
        jmp     draw_disasm.redraw
1334
 
205 heavyiron 1335
OnBpmb:
3675 GerdtR 1336
        mov     dh, 0011b
1337
        jmp     DoBpm
1338
 
205 heavyiron 1339
OnBpmw:
3675 GerdtR 1340
        mov     dh, 0111b
1341
        jmp     DoBpm
1342
 
205 heavyiron 1343
OnBpmd:
3675 GerdtR 1344
        mov     dh, 1111b
1345
 
205 heavyiron 1346
DoBpm:
3675 GerdtR 1347
        mov     esi, [curarg]
1348
        cmp     byte [esi], 'w'
1349
        jnz     @f
1350
        and     dh, not 2
1351
        inc     esi
205 heavyiron 1352
 
3675 GerdtR 1353
    @@:
1354
        push    edx
1355
        call    calc_expression
1356
        pop     edx
1357
        jnc     @f
1358
        ret
1359
 
1360
    ; ebp = expression, dh = flags
1361
    @@:
1362
        movzx   eax, dh
1363
        shr     eax, 2
1364
        test    ebp, eax
1365
        jz      @f
1366
        mov     esi, aUnaligned
1367
        jmp     put_message
1368
 
1369
    @@:
1370
        mov     eax, ebp
1371
        mov     bl, 0Bh
1372
        call    add_breakpoint
1373
        jnc     @f
1374
        mov     esi, aBreakpointLimitExceeded
1375
        jmp     put_message
1376
 
1377
    ; now find index
1378
    @@:
1379
        push    eax
1380
        xor     ecx, ecx
1381
 
1382
    .l1:
1383
        cmp     [drx_break+ecx*4], 0
1384
        jnz     .l2
1385
        ;push    69
1386
        ;pop     eax
1387
        push    ecx
1388
        mov     dl, cl
1389
        ;mov     ecx, [debuggee_pid]
1390
        mov     esi, ebp
1391
        ;push    9
1392
        ;pop     ebx
1393
        mcall    69, 9, [debuggee_pid]
1394
        test    eax, eax
1395
        jz      .ok
1396
        pop     ecx
1397
 
1398
    .l2:
1399
        inc     ecx
1400
        cmp     ecx, 4
1401
        jb      .l1
1402
        pop     eax
1403
        call    clear_breakpoint
1404
        mov     esi, aBreakpointLimitExceeded
1405
        jmp     put_message
1406
 
1407
    .ok:
1408
        pop     ecx
1409
        pop     eax
1410
        and     byte [edi], not 2       ; breakpoint is enabled
1411
        shl     dl, 6
1412
        or      dl, dh
1413
        mov     byte [edi+1], dl
1414
        inc     eax
1415
        mov     [drx_break+ecx*4], eax
1416
        ret
1417
 
205 heavyiron 1418
OnBc:
3675 GerdtR 1419
        mov     esi, [curarg]
205 heavyiron 1420
 
3675 GerdtR 1421
    @@:
1422
        call    get_hex_number
1423
        jc      OnBp.ret
1424
        call    clear_breakpoint
1425
        jmp     @b
1426
 
205 heavyiron 1427
OnBd:
3675 GerdtR 1428
        mov     esi, [curarg]
205 heavyiron 1429
 
3675 GerdtR 1430
    @@:
1431
        call    get_hex_number
1432
        jc      OnBp.ret
1433
        call    disable_breakpoint
1434
        jmp     @b
1435
 
205 heavyiron 1436
OnBe:
3675 GerdtR 1437
        mov     esi, [curarg]
205 heavyiron 1438
 
3675 GerdtR 1439
    @@:
1440
        call    get_hex_number
1441
        jc      OnBp.ret
1442
        push    eax
1443
        call    find_enabled_breakpoint
1444
        pop     eax
1445
        jz      .err
1446
        call    enable_breakpoint
1447
        jmp     @b
1448
 
1449
    .err:
1450
        mov     esi, OnBeErrMsg
1451
        jmp     put_message
1452
 
1453
; TODO: split it out in parser.inc
205 heavyiron 1454
get_hex_number:
3675 GerdtR 1455
        call    get_arg.skip_spaces
1456
        xor     ecx, ecx
1457
        xor     edx, edx
205 heavyiron 1458
 
3675 GerdtR 1459
    @@:
1460
        lodsb
1461
        call    is_hex_digit
1462
        jc      .ret
1463
        shl     edx, 4
1464
        or      dl, al
1465
        inc     ecx
1466
        jmp     @b
1467
 
1468
    .ret:
1469
        dec     esi
1470
        cmp     ecx, 1
1471
        xchg    eax, edx
1472
        ret
1473
 
1474
;-----------------------------------------------------------------------------
1475
;                       Breakpoints list event
1476
 
205 heavyiron 1477
OnBl:
3675 GerdtR 1478
        mov     esi, [curarg]
1479
        cmp     byte [esi], 0
1480
        jz      .listall
1481
        call    get_hex_number
1482
        jc      .ret
1483
        cmp     eax, breakpoints_n
1484
        jae     .err
1485
        push    eax
1486
        add     eax, eax
1487
        lea     edi, [breakpoints + eax + eax*2]
1488
        pop     eax
1489
        test    byte [edi+4], 1
1490
        jz      .err
1491
        call    show_break_info
205 heavyiron 1492
 
3675 GerdtR 1493
    .ret:
1494
        ret
1495
 
1496
    .err:
1497
        mov     esi, aInvalidBreak
1498
        jmp     put_message
1499
 
1500
    .listall:
1501
        mov     edi, breakpoints
1502
        xor     eax, eax
1503
 
1504
    @@:
1505
        test    byte [edi+4], 1
1506
        jz      .cont
1507
        push    edi eax
1508
        call    show_break_info
1509
        pop     eax edi
1510
 
1511
    .cont:
1512
        add     edi, 6
1513
        inc     eax
1514
        cmp     eax, breakpoints_n
1515
        jb      @b
1516
        ret
1517
 
1518
;-----------------------------------------------------------------------------
1519
 
205 heavyiron 1520
show_break_info:
3675 GerdtR 1521
        push    edi
1522
        test    byte [edi+4], 8
1523
        jnz     .dr
1524
        push    dword [edi]
1525
        push    eax
1526
        mov     esi, aBreakNum
1527
        call    put_message_nodraw
1528
        jmp     .cmn
205 heavyiron 1529
 
3675 GerdtR 1530
    .dr:
1531
        push    eax
1532
        mov     esi, aMemBreak1
1533
        call    put_message_nodraw
1534
        pop     edi
1535
        push    edi
1536
        mov     esi, aMemBreak2
1537
        test    byte [edi+5], 2
1538
        jz      @f
1539
        mov     esi, aMemBreak3
1540
 
1541
    @@:
1542
        call    put_message_nodraw
1543
        pop     edi
1544
        push    edi
1545
        mov     esi, aMemBreak6
1546
        test    byte [edi+5], 8
1547
        jnz     @f
1548
        mov     esi, aMemBreak5
1549
        test    byte [edi+5], 4
1550
        jnz     @f
1551
        mov     esi, aMemBreak4
1552
 
1553
    @@:
1554
        call    put_message_nodraw
1555
        pop     edi
1556
        push    edi
1557
        push    dword [edi]
1558
        mov     esi, aMemBreak7
1559
        call    put_message_nodraw
1560
 
1561
    .cmn:
1562
        pop     edi
1563
        test    byte [edi+4], 2
1564
        jz      @f
1565
        push    edi
1566
        mov     esi, aDisabled
1567
        call    put_message_nodraw
1568
        pop     edi
1569
 
1570
    @@:
1571
        test    byte [edi+4], 4
1572
        jz      @f
1573
        mov     esi, aOneShot
1574
        call    put_message_nodraw
1575
 
1576
    @@:
1577
        mov     esi, newline
1578
        jmp     put_message
1579
 
1580
;-----------------------------------------------------------------------------
1581
;                        Add breakpoint
1582
; in: EAX = address; BL = flags
1583
; out: CF = 1 => error
1584
;      CF = 0 and EAX = breakpoint number
1585
 
205 heavyiron 1586
add_breakpoint:
3675 GerdtR 1587
        xor     ecx, ecx
1588
        mov     edi, breakpoints
205 heavyiron 1589
 
3675 GerdtR 1590
    @@:
1591
        test    byte [edi+4], 1
1592
        jz      .found
1593
        add     edi, 6
1594
        inc     ecx
1595
        cmp     ecx, breakpoints_n
1596
        jb      @b
1597
        stc
1598
        ret
1599
 
1600
    .found:
1601
        stosd
1602
        xchg    eax, ecx
1603
        mov     [edi], bl
1604
        test    bl, 2
1605
        jnz     @f
1606
        or      byte [edi], 2
1607
        push    eax
1608
        call    enable_breakpoint
1609
        pop     eax
1610
 
1611
    @@:
1612
        clc
1613
        ret
1614
 
1615
;-----------------------------------------------------------------------------
1616
;                         Remove breakpoint
1617
 
205 heavyiron 1618
clear_breakpoint:
3675 GerdtR 1619
        cmp     eax, breakpoints_n
1620
        jae     .ret
1621
        mov     ecx, 4
1622
        inc     eax
205 heavyiron 1623
 
3675 GerdtR 1624
    .1:
1625
        cmp     [drx_break-4+ecx*4], eax
1626
        jnz     @f
1627
        and     [drx_break-4+ecx*4], 0
1628
 
1629
    @@:
1630
        loop    .1
1631
        dec     eax
1632
        push    eax
1633
        add     eax, eax
1634
        lea     edi, [breakpoints + eax + eax*2 + 4]
1635
        test    byte [edi], 1
1636
        pop     eax
1637
        jz      .ret
1638
        push    edi
1639
        call    disable_breakpoint
1640
        pop     edi
1641
        mov     byte [edi], 0
1642
 
1643
    .ret:
1644
        ret
1645
 
1646
;-----------------------------------------------------------------------------
1647
;                          Disable breakpoint
1648
 
205 heavyiron 1649
disable_breakpoint:
3675 GerdtR 1650
        cmp     eax, breakpoints_n
1651
        jae     .ret
1652
        add     eax, eax
1653
        lea     edi, [breakpoints + eax + eax*2 + 5]
1654
        test    byte [edi-1], 1
1655
        jz      .ret
1656
        test    byte [edi-1], 2
1657
        jnz     .ret
1658
        or      byte [edi-1], 2
1659
        test    byte [edi-1], 8
1660
        jnz     .dr
1661
        push    esi
1662
        ;push    7
1663
        ;pop     ebx
1664
        ;push    69
1665
        ;pop     eax
1666
        ;mov     ecx, [debuggee_pid]
1667
        ;xor     edx, edx
1668
        ;inc     edx
1669
        ;mov     esi, [edi-5]
1670
        mcall    69, 7, [debuggee_pid], 1, [edi-5]
1671
        pop     esi
205 heavyiron 1672
 
3675 GerdtR 1673
    .ret:
1674
        ret
1675
 
1676
    .dr:
1677
        mov     dl, [edi]
1678
        shr     dl, 6
1679
        mov     dh, 80h
1680
        ;push    69
1681
        ;pop     eax
1682
        ;push    9
1683
        ;pop     ebx
1684
        ;mov     ecx, [debuggee_pid]
1685
        mcall    69, 9, [debuggee_pid]
1686
        ret
1687
 
1688
;-----------------------------------------------------------------------------
1689
;                           Enable breakpoint
1690
 
205 heavyiron 1691
enable_breakpoint:
3675 GerdtR 1692
        push    esi
1693
        cmp     eax, breakpoints_n
1694
        jae     .ret
1695
        add     eax, eax
1696
        lea     edi, [breakpoints + eax + eax*2 + 5]
1697
        test    byte [edi-1], 1
1698
        jz      .ret
1699
        test    byte [edi-1], 2
1700
        jz      .ret
1701
        and     byte [edi-1], not 2
1702
        test    byte [edi-1], 8
1703
        jnz     .dr
1704
        ;push    6
1705
        ;pop     ebx
1706
        ;push    69
1707
        ;pop     eax
1708
        ;mov     esi, [edi-5]
1709
        ;mov     ecx, [debuggee_pid]
1710
        ;xor     edx, edx
1711
        ;inc     edx
1712
        mcall    69, 6, [debuggee_pid], 1, [edi-5]
1713
        dec     eax
1714
        jnz     .err
1715
        ;mov     al, 69
1716
        push    0xCC
1717
        mov     edi, esp
1718
        inc     ebx
1719
        mcall    69
1720
        pop     eax
205 heavyiron 1721
 
3675 GerdtR 1722
    .ret:
1723
        pop     esi
1724
        ret
205 heavyiron 1725
 
3675 GerdtR 1726
    .err:
1727
        or      byte [edi-1], 2
1728
        mov     esi, aBreakErr
1729
        call    put_message
1730
        pop     esi
1731
        ret
205 heavyiron 1732
 
3675 GerdtR 1733
    .dr:
1734
        ;push    9
1735
        ;pop     ebx
1736
        ;push    69
1737
        ;pop     eax
1738
        mov     esi, [edi-5]
1739
        ;mov     ecx, [debuggee_pid]
1740
        mov     dl, [edi]
1741
        shr     dl, 6
1742
        mov     dh, [edi]
1743
        and     dh, 0xF
1744
        mcall    69, 9, [debuggee_pid]
1745
        test    eax, eax
1746
        jnz     .err
1747
        pop     esi
1748
        ret
205 heavyiron 1749
 
3675 GerdtR 1750
;-----------------------------------------------------------------------------
1751
;                             Find breakpoint
542 diamond 1752
 
3675 GerdtR 1753
find_breakpoint:
1754
        xor     ecx, ecx
1755
        xchg    eax, ecx
1756
        mov     edi, breakpoints
542 diamond 1757
 
3675 GerdtR 1758
    @@:
1759
        test    byte [edi+4], 1
1760
        jz      .cont
1761
        test    byte [edi+4], 8
1762
        jnz     .cont
1763
        cmp     [edi], ecx
1764
        jz      .found
542 diamond 1765
 
3675 GerdtR 1766
    .cont:
1767
        add     edi, 6
1768
        inc     eax
1769
        cmp     eax, breakpoints_n
1770
        jb      @b
1771
        or      eax, -1
542 diamond 1772
 
3675 GerdtR 1773
    .found:
1774
        ret
542 diamond 1775
 
3675 GerdtR 1776
;-----------------------------------------------------------------------------
1777
;
542 diamond 1778
 
3675 GerdtR 1779
find_enabled_breakpoint:
1780
        xor     ecx, ecx
1781
        xchg    eax, ecx
1782
        mov     edi, breakpoints
542 diamond 1783
 
3675 GerdtR 1784
    @@:
1785
        test    byte [edi+4], 1
1786
        jz      .cont
1787
        test    byte [edi+4], 2 or 8
1788
        jnz     .cont
1789
        cmp     [edi], ecx
1790
        jz      .found
542 diamond 1791
 
3675 GerdtR 1792
    .cont:
1793
        add     edi, 6
1794
        inc     eax
1795
        cmp     eax, breakpoints_n
1796
        jb      @b
1797
        or      eax, -1
205 heavyiron 1798
 
3675 GerdtR 1799
    .found:
1800
        ret
205 heavyiron 1801
 
3675 GerdtR 1802
; TODO: add find_disabled_breakpoint
205 heavyiron 1803
 
3675 GerdtR 1804
;-----------------------------------------------------------------------------
1805
;                       Unpack executable event
205 heavyiron 1806
 
3675 GerdtR 1807
OnUnpack:
1808
    ; program must be loaded - checked when command was parsed
1809
    ; program must be stopped
1810
        mov     esi, aRunningErr
1811
        cmp     [bSuspended], 0
1812
        jz      put_message
1813
   ; all breakpoints must be disabled
1814
        mov     edi, breakpoints
205 heavyiron 1815
 
3675 GerdtR 1816
    @@:
1817
        test    byte [edi+4], 1
1818
        jz      .cont
1819
        test    byte [edi+4], 2
1820
        jnz     .cont
1821
        mov     esi, aEnabledBreakErr
1822
        jmp     put_message
205 heavyiron 1823
 
3675 GerdtR 1824
    .cont:
1825
        add     edi, 6
1826
        cmp     edi, breakpoints+breakpoints_n*6
1827
        jb      @b
1828
    ; ok, now do it
1829
    ; set breakpoint on 0xC dword access
1830
        push    9
1831
        pop     ebx
1832
        mov     ecx, [debuggee_pid]
1833
        mov     dx, 1111b*256
1834
        push    0xC
1835
        pop     esi
205 heavyiron 1836
 
3675 GerdtR 1837
    @@:
1838
        ;push    69
1839
        ;pop     eax
1840
        mcall    69
1841
        test    eax, eax
1842
        jz      .breakok
1843
        inc     edx
1844
        cmp     dl, 4
1845
        jb      @b
809 diamond 1846
 
3675 GerdtR 1847
    .breakok:
1848
        call    GoOn
809 diamond 1849
 
3675 GerdtR 1850
    ; now wait for event
1851
    .wait:
1852
        ;push    10
1853
        ;pop     eax
1854
        mcall    10
1855
        dec     eax
1856
        jz      .redraw
1857
        dec     eax
1858
        jz      .key
1859
        dec     eax
1860
        jnz     .debug
1861
    ; button; we have only one button, close
1862
        or      eax, -1
1863
        mcall
205 heavyiron 1864
 
3675 GerdtR 1865
    .redraw:
1866
        call    draw_window
1867
        jmp     .wait
205 heavyiron 1868
 
3675 GerdtR 1869
    .key:
1870
        mov     al, 2
1871
        mcall
1872
        cmp     ah, 3   ; Ctrl+C
1873
        jnz     .wait
205 heavyiron 1874
 
3675 GerdtR 1875
    .userbreak:
1876
        mov     esi, aInterrupted
205 heavyiron 1877
 
3675 GerdtR 1878
    .x1:
1879
        push    edx esi
1880
        call    put_message
1881
        pop     esi edx
1882
        or      dh, 80h
1883
        ;push    69
1884
        ;pop     eax
1885
        ;push    9
1886
        ;pop     ebx
1887
        ;mov     ecx, [debuggee_pid]
1888
        mcall    69, 9, [debuggee_pid]
1889
        cmp     esi, aUnpacked
1890
        jnz     OnSuspend
1891
        jmp     AfterSuspend
205 heavyiron 1892
 
3675 GerdtR 1893
    .debug:
1894
        cmp     [dbgbuflen], 4*3
1895
        jnz     .notour
1896
        cmp     dword [dbgbuf], 3
1897
        jnz     .notour
1898
        test    byte [dbgbuf+8], 1
1899
        jnz     .our
205 heavyiron 1900
 
3675 GerdtR 1901
    .notour:
1902
        mov     esi, aInterrupted
1903
        push    edx
1904
        call    put_message
1905
        pop     edx
1906
        or      dh, 80h
1907
        ;push    69
1908
        ;pop     eax
1909
        ;push    9
1910
        ;pop     ebx
1911
        ;mov     ecx, [debuggee_pid]
1912
        mcall    69, 9, [debuggee_pid]
1913
        jmp     debugmsg
205 heavyiron 1914
 
3675 GerdtR 1915
    .our:
1916
        and     [dbgbuflen], 0
1917
        push    edx
1918
        call    get_context
1919
        push    eax
1920
        ;mov     al, 69
1921
        ;mov     bl, 6
1922
        ;mov     ecx, [debuggee_pid]
1923
        ;mov     edi, esp
1924
        ;push    4
1925
        ;pop     edx
1926
        ;push    0xC
1927
        ;pop     esi
1928
        mcall    69, 6, [debuggee_pid], 4, 0xC, esp
1929
        pop     eax
1930
        pop     edx
1931
        cmp     eax, [_eip]
1932
        jz      .done
1933
        call    DoResume
1934
        jmp     .wait
205 heavyiron 1935
 
3675 GerdtR 1936
    .done:
1937
        mov     esi, aUnpacked
1938
        jmp     .x1
809 diamond 1939
 
3675 GerdtR 1940
;-----------------------------------------------------------------------------
1941
;                  Working with program symbols
1942
;
1943
;  TODO: split to symbols.inc
205 heavyiron 1944
 
3675 GerdtR 1945
include 'sort.inc'
205 heavyiron 1946
 
3675 GerdtR 1947
; compare what? Add context-relative comment and name
1948
compare:
1949
        cmpsd
1950
        jnz     @f
1951
        cmp     esi, edi
205 heavyiron 1952
 
3675 GerdtR 1953
    @@:
1954
        ret
205 heavyiron 1955
 
3675 GerdtR 1956
; purpose of this function?
1957
compare2:
1958
        cmpsd
205 heavyiron 1959
 
3675 GerdtR 1960
    @@:
1961
        cmpsb
1962
        jnz     @f
1963
        cmp     byte [esi-1], 0
1964
        jnz     @b
1965
        cmp     esi, edi
205 heavyiron 1966
 
3675 GerdtR 1967
    @@:
1968
        ret
205 heavyiron 1969
 
3675 GerdtR 1970
free_symbols:
1971
        mov     ecx, [symbols]
1972
        jecxz   @f
1973
        mcall   68, 13
1974
        and     [symbols], 0
1975
        and     [num_symbols], 0
205 heavyiron 1976
 
3675 GerdtR 1977
    @@:
1978
        ret
1979
;-----------------------------------------------------------------------------
1980
;                        Load symbols event
205 heavyiron 1981
 
3675 GerdtR 1982
OnLoadSymbols.fileerr:
1983
        test    ebp, ebp
1984
        jz      @f
1985
        mcall   68, 13, edi
1986
        ret
205 heavyiron 1987
 
3675 GerdtR 1988
    @@:
1989
        push    eax
1990
        mcall   68, 13, edi
1991
        mov     esi, aCannotLoadFile
1992
        call    put_message_nodraw
1993
        pop     eax
1994
        cmp     eax, 0x20
1995
        jae     .unk
1996
        mov     esi, [load_err_msgs + eax*4]
1997
        test    esi, esi
1998
        jnz     put_message
205 heavyiron 1999
 
3675 GerdtR 2000
    .unk:
2001
        mov     esi, unk_err_msg2
2002
        jmp     put_message
205 heavyiron 2003
 
3675 GerdtR 2004
OnLoadSymbols:
2005
        xor     ebp, ebp
2006
   ; load input file
2007
        mov     esi, [curarg]
2008
        call    free_symbols
809 diamond 2009
 
3675 GerdtR 2010
    .silent:
2011
        xor     edi, edi
2012
        cmp     [num_symbols], edi
2013
        jz      @f
2014
 
2015
        call    free_symbols
2016
        ;ret
2017
 
2018
    @@:
2019
        mov     ebx, fn70_attr_block
2020
        mov     [ebx+21], esi
2021
        mcall   70
2022
        test    eax, eax
2023
        jnz     .fileerr
2024
        cmp     dword [fileattr+36], edi
2025
        jnz     .memerr
2026
        mov     ecx, dword [fileattr+32]
2027
        mcall   68, 12
2028
        test    eax, eax
2029
        jz      .memerr
2030
        mov     edi, eax
2031
        mov     ebx, fn70_read_block
2032
        mov     [ebx+12], ecx
2033
        mov     [ebx+16], edi
2034
        mov     [ebx+21], esi
2035
        mcall   70
2036
        test    eax, eax
2037
        jnz     .fileerr
2038
    ; calculate memory requirements
2039
        lea     edx, [ecx+edi-1]        ; edx = EOF-1
2040
        mov     esi, edi
2041
        xor     ecx, ecx
809 diamond 2042
 
3675 GerdtR 2043
    .calcloop:
2044
        cmp     esi, edx
2045
        jae     .calcdone
2046
        cmp     word [esi], '0x'
2047
        jnz     .skipline
2048
        inc     esi
2049
        inc     esi
809 diamond 2050
 
3675 GerdtR 2051
    @@:
2052
        cmp     esi, edx
2053
        jae     .calcdone
2054
        lodsb
2055
        or      al, 20h
2056
        sub     al, '0'
2057
        cmp     al, 9
2058
        jbe     @b
2059
        sub     al, 'a'-'0'-10
2060
        cmp     al, 15
2061
        jbe     @b
2062
        dec     esi
205 heavyiron 2063
 
3675 GerdtR 2064
    @@:
2065
        cmp     esi, edx
2066
        ja      .calcdone
2067
        lodsb
2068
        cmp     al, 20h
2069
        jz      @b
2070
        jb      .calcloop
2071
        cmp     al, 9
2072
        jz      @b
2073
        add     ecx, 12+1
2074
        inc     [num_symbols]
809 diamond 2075
 
3675 GerdtR 2076
    @@:
2077
        inc     ecx
2078
        cmp     esi, edx
2079
        ja      .calcdone
2080
        lodsb
2081
        cmp     al, 0xD
2082
        jz      .calcloop
2083
        cmp     al, 0xA
2084
        jz      .calcloop
2085
        jmp     @b
205 heavyiron 2086
 
3675 GerdtR 2087
    .skipline:
2088
        cmp     esi, edx
2089
        jae     .calcdone
2090
        lodsb
2091
        cmp     al, 0xD
2092
        jz      .calcloop
2093
        cmp     al, 0xA
2094
        jz      .calcloop
2095
        jmp     .skipline
542 diamond 2096
 
3675 GerdtR 2097
    .calcdone:
2098
        mcall   68, 12
2099
        test    eax, eax
2100
        jnz     .memok
2101
        inc     ebx
2102
        mov     ecx, edi
2103
        mov     al, 68
2104
        mcall
205 heavyiron 2105
 
3675 GerdtR 2106
    .memerr:
2107
        mov     esi, aNoMemory
2108
        jmp     put_message
205 heavyiron 2109
 
3675 GerdtR 2110
    .memok:
2111
        mov     [symbols], eax
2112
        mov     ebx, eax
2113
        push    edi
2114
        mov     esi, edi
2115
        mov     edi, [num_symbols]
2116
        lea     ebp, [eax+edi*4]
2117
        lea     edi, [eax+edi*8]
205 heavyiron 2118
 
3675 GerdtR 2119
    ; parse input data,
2120
    ; esi->input, edx->EOF, ebx->ptrs, edi->names
2121
    .readloop:
2122
        cmp     esi, edx
2123
        jae     .readdone
2124
        cmp     word [esi], '0x'
2125
        jnz     .readline
2126
        inc     esi
2127
        inc     esi
2128
        xor     eax, eax
2129
        xor     ecx, ecx
205 heavyiron 2130
 
3675 GerdtR 2131
    @@:
2132
        shl     ecx, 4
2133
        add     ecx, eax
2134
        cmp     esi, edx
2135
        jae     .readdone
2136
        lodsb
2137
        or      al, 20h
2138
        sub     al, '0'
2139
        cmp     al, 9
2140
        jbe     @b
2141
        sub     al, 'a'-'0'-10
2142
        cmp     al, 15
2143
        jbe     @b
2144
        dec     esi
809 diamond 2145
 
3675 GerdtR 2146
    @@:
2147
        cmp     esi, edx
2148
        ja      .readdone
2149
        lodsb
2150
        cmp     al, 20h
2151
        jz      @b
2152
        jb      .readloop
2153
        cmp     al, 9
2154
        jz      @b
2155
        mov     dword [ebx], edi
2156
        add     ebx, 4
2157
        mov     dword [ebp], edi
2158
        add     ebp, 4
2159
        mov     dword [edi], ecx
2160
        add     edi, 4
2161
        stosb
205 heavyiron 2162
 
3675 GerdtR 2163
    @@:
2164
        xor     eax, eax
2165
        stosb
2166
        cmp     esi, edx
2167
        ja      .readdone
2168
        lodsb
2169
        cmp     al, 0xD
2170
        jz      .readloop
2171
        cmp     al, 0xA
2172
        jz      .readloop
2173
        mov     byte [edi-1], al
2174
        jmp     @b
205 heavyiron 2175
 
3675 GerdtR 2176
    .readline:
2177
        cmp     esi, edx
2178
        jae     .readdone
2179
        lodsb
2180
        cmp     al, 0xD
2181
        jz      .readloop
2182
        cmp     al, 0xA
2183
        jz      .readloop
2184
        jmp     .readline
205 heavyiron 2185
 
3675 GerdtR 2186
    .readdone:
2187
        pop     ecx
2188
        mcall   68, 13
2189
        mov     ecx, [num_symbols]
2190
        mov     edx, [symbols]
2191
        mov     ebx, compare
2192
        call    sort
2193
        mov     ecx, [num_symbols]
2194
        lea     edx, [edx+ecx*4]
2195
        mov     ebx, compare2
2196
        call    sort
2197
        mov     esi, aSymbolsLoaded
2198
        call    put_message
2199
        jmp     draw_disasm.redraw
205 heavyiron 2200
 
3675 GerdtR 2201
;-----------------------------------------------------------------------------
2202
;
2203
; in: EAX = address
2204
; out: ESI, CF
205 heavyiron 2205
 
3675 GerdtR 2206
find_symbol:
2207
        cmp     [num_symbols], 0
2208
        jnz     @f
205 heavyiron 2209
 
3675 GerdtR 2210
    .ret0:
2211
        xor     esi, esi
2212
        stc
2213
        ret
205 heavyiron 2214
 
3675 GerdtR 2215
    @@:
2216
        push    ebx ecx edx
2217
        xor     edx, edx
2218
        mov     esi, [symbols]
2219
        mov     ecx, [num_symbols]
2220
        mov     ebx, [esi]
2221
        cmp     [ebx], eax
2222
        jz      .donez
2223
        jb      @f
2224
        pop     edx ecx ebx
2225
        jmp     .ret0
809 diamond 2226
 
3675 GerdtR 2227
    @@:
2228
    ; invariant: symbols_addr[edx] < eax < symbols_addr[ecx]
2229
    ; TODO: add meaningful label names
2230
    .0:
2231
        push    edx
205 heavyiron 2232
 
3675 GerdtR 2233
    .1:
2234
        add     edx, ecx
2235
        sar     edx, 1
2236
        cmp     edx, [esp]
2237
        jz      .done2
2238
        mov     ebx, [esi+edx*4]
2239
        cmp     [ebx], eax
2240
        jz      .done
2241
        ja      .2
2242
        mov     [esp], edx
2243
        jmp     .1
205 heavyiron 2244
 
3675 GerdtR 2245
    .2:
2246
        mov     ecx, edx
2247
        pop     edx
2248
        jmp     .0
205 heavyiron 2249
 
3675 GerdtR 2250
    .donecont:
2251
        dec     edx
205 heavyiron 2252
 
3675 GerdtR 2253
    .done:
2254
        test    edx, edx
2255
        jz      @f
2256
        mov     ebx, [esi+edx*4-4]
2257
        cmp     [ebx], eax
2258
        jz      .donecont
205 heavyiron 2259
 
3675 GerdtR 2260
    @@:
2261
        pop     ecx
205 heavyiron 2262
 
3675 GerdtR 2263
    .donez:
2264
        mov     esi, [esi+edx*4]
2265
        add     esi, 4
2266
        pop     edx ecx ebx
2267
        clc
2268
        ret
205 heavyiron 2269
 
3675 GerdtR 2270
    .done2:
2271
        lea     esi, [esi+edx*4]
2272
        pop     ecx edx ecx ebx
2273
        stc
2274
        ret
205 heavyiron 2275
 
3675 GerdtR 2276
;-----------------------------------------------------------------------------
2277
;
2278
; in: esi->name
2279
; out: if found: CF = 0, EAX = value
2280
;      otherwise CF = 1
2281
find_symbol_name:
2282
        cmp     [num_symbols], 0
2283
        jnz     @f
205 heavyiron 2284
 
3675 GerdtR 2285
    .stc_ret:
2286
        stc
2287
        ret
205 heavyiron 2288
 
3675 GerdtR 2289
    @@:
2290
        push    ebx ecx edx edi
2291
        push    -1
2292
        pop     edx
2293
        mov     ebx, [symbols]
2294
        mov     ecx, [num_symbols]
2295
        lea     ebx, [ebx+ecx*4]
2296
 
2297
    ; invariant: symbols_name[edx] < name < symbols_name[ecx]
2298
    .0:
2299
        push    edx
542 diamond 2300
 
3675 GerdtR 2301
    .1:
2302
        add     edx, ecx
2303
        sar     edx, 1
2304
        cmp     edx, [esp]
2305
        jz      .done2
2306
        call    .cmp
2307
        jz      .done
2308
        jb      .2
2309
        mov     [esp], edx
2310
        jmp     .1
542 diamond 2311
 
3675 GerdtR 2312
    .2:
2313
        mov     ecx, edx
2314
        pop     edx
2315
        jmp     .0
542 diamond 2316
 
3675 GerdtR 2317
    .done:
2318
        pop     ecx
542 diamond 2319
 
3675 GerdtR 2320
    .donez:
2321
        mov     eax, [ebx+edx*4]
2322
        mov     eax, [eax]
2323
        pop     edi edx ecx ebx
2324
        clc
2325
        ret
542 diamond 2326
 
3675 GerdtR 2327
    .done2:
2328
        pop     edx edi edx ecx ebx
2329
        stc
2330
        ret
809 diamond 2331
 
3675 GerdtR 2332
    .cmp:
2333
        mov     edi, [ebx+edx*4]
2334
        push    esi
2335
        add     edi, 4
809 diamond 2336
 
3675 GerdtR 2337
    @@:
2338
        cmpsb
2339
        jnz     @f
2340
        cmp     byte [esi-1], 0
2341
        jnz     @b
542 diamond 2342
 
3675 GerdtR 2343
    @@:
2344
        pop     esi
2345
        ret
809 diamond 2346
 
3675 GerdtR 2347
;-----------------------------------------------------------------------------
2348
;                        Include disassembler engine
2349
 
2350
include 'disasm.inc'
2351
 
205 heavyiron 2352
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2353
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2354
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2355
 
2356
caption_str db 'Kolibri Debugger',0
2357
caption_len = $ - caption_str
2358
 
4285 tserj 2359
begin_str db    'Kolibri Debugger, version 0.33',10
3675 GerdtR 2360
        db      'Hint: type "help" for help, "quit" for quit'
2361
newline db      10,0
2362
prompt  db      '> ',0
2363
 
205 heavyiron 2364
help_groups:
3675 GerdtR 2365
        dd      aControl, 0, 0, help_control_msg
2366
        db      0
2367
        dd      aData, 0, 0, help_data_msg
2368
        db      0
2369
        dd      aBreakpoints, 0, 0, help_breaks_msg
2370
        db      0
2371
 
2372
;-----------------------------------------------------------------------------
2373
;                   Commands format definitions
2374
 
2375
; TODO: make it with macros
2376
 
205 heavyiron 2377
; flags field:
2378
; &1: command may be called without parameters
2379
; &2: command may be called with parameters
2380
; &4: command may be called without loaded program
2381
; &8: command may be called with loaded program
2382
commands:
3675 GerdtR 2383
        dd      _aH, OnHelp, HelpSyntax, HelpHelp
2384
        db      0Fh
2385
        dd      aHelp, OnHelp, HelpSyntax, HelpHelp
2386
        db      0Fh
2387
        dd      aQuit, OnQuit, QuitSyntax, QuitHelp
2388
        db      0Dh
2389
        dd      aLoad, OnLoad, LoadSyntax, LoadHelp
2390
        db      6
2391
        dd      aReload, OnReload, ReloadSyntax, ReloadHelp
2392
        db      0Dh
2393
        dd      aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
2394
        db      9
2395
        dd      aDetach, OnDetach, DetachSyntax, DetachHelp
2396
        db      9
2397
        dd      aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
2398
        db      9
2399
        dd      aResume, OnResume, ResumeSyntax, ResumeHelp
2400
        db      0Bh
4443 clevermous 2401
        dd      aStep, OnStepMultiple, StepSyntax, StepHelp
3675 GerdtR 2402
        db      0Bh
2403
        dd      aProceed, OnProceed, ProceedSyntax, ProceedHelp
2404
        db      0Bh
2405
        dd      aCalc, OnCalc, CalcSyntax, CalcHelp
2406
        db      0Eh
2407
        dd      aDump, OnDump, DumpSyntax, DumpHelp
2408
        db      0Bh
2409
        dd      aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
2410
        db      0Bh
2411
        dd      aBp, OnBp, BpSyntax, BpHelp
2412
        db      0Ah
2413
        dd      aBpm, OnBpmb, BpmSyntax, BpmHelp
2414
        db      0Ah
2415
        dd      aBpmb, OnBpmb, BpmSyntax, BpmHelp
2416
        db      0Ah
2417
        dd      aBpmw, OnBpmw, BpmSyntax, BpmHelp
2418
        db      0Ah
2419
        dd      aBpmd, OnBpmd, BpmSyntax, BpmHelp
2420
        db      0Ah
2421
        dd      aBl, OnBl, BlSyntax, BlHelp
2422
        db      0Bh
2423
        dd      aBc, OnBc, BcSyntax, BcHelp
2424
        db      0Ah
2425
        dd      aBd, OnBd, BdSyntax, BdHelp
2426
        db      0Ah
2427
        dd      aBe, OnBe, BeSyntax, BeHelp
2428
        db      0Ah
2429
        dd      aReg, OnReg, RSyntax, RHelp
2430
        db      0Ah
2431
        dd      aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
2432
        db      9
2433
        dd      aLoadSymbols, OnLoadSymbols, LoadSymbolsSyntax, LoadSymbolsHelp
2434
        db      0Ah
2435
        dd      0
205 heavyiron 2436
 
3675 GerdtR 2437
;-----------------------------------------------------------------------------
2438
;                   Help messages for commands groups
2439
 
2440
aHelp   db      5,'help',0
2441
_aH     db      2,'h',0
2442
HelpHelp db     'Help on specified function',10
2443
HelpSyntax db   'Usage: h or help [group | command]',10,0
2444
 
2445
help_msg db     'List of known command groups:',10
2446
        db      '"help control"     - display list of control commands',10
2447
        db      '"help data"        - display list of commands concerning data',10
2448
        db      '"help breakpoints" - display list of commands concerning breakpoints',10,0
2449
 
2450
;               Control commands group
2451
 
2452
aControl db     8,'control',0
2453
help_control_msg db     'List of control commands:',10
2454
        db      'h = help             - help',10
2455
        db      'quit                 - exit from debugger',10
2456
        db      'load  [params] - load program for debugging',10
2457
        db      'reload               - reload debugging program',10
2458
        db      'load-symbols   - load information on symbols for program',10
2459
        db      'terminate            - terminate loaded program',10
2460
        db      'detach               - detach from debugging program',10
2461
        db      'stop                 - suspend execution of debugging program',10
2462
        db      'g []     - go on (resume execution of debugging program)',10
4590 clevermous 2463
        db      's []            - program step, also ',10
2464
        db      'p []            - program wide step, also ',10
3675 GerdtR 2465
        db      'unpack               - try to bypass unpacker code (heuristic)',10,0
2466
 
2467
;               Data commands group
2468
 
2469
aData   db      5,'data',0
2470
help_data_msg db        'List of data commands:',10
2471
        db      '?        - calculate value of expression',10
2472
        db      'd []     - dump data at given address',10
2473
        db      'u []     - unassemble instructions at given address',10
2474
        db      'r   or',10
2475
        db      'r = - set register value',10,0
2476
 
2477
;               Breakpoints commands group
2478
 
205 heavyiron 2479
aBreakpoints db 12,'breakpoints',0
3675 GerdtR 2480
help_breaks_msg db      'List of breakpoints commands:',10
2481
        db      'bp       - set breakpoint on execution',10
2482
        db      'bpm[b|w|d]   - set breakpoint on memory access',10
2483
        db      'bl []        - breakpoint(s) info',10
2484
        db      'bc ...       - clear breakpoint',10
2485
        db      'bd ...       - disable breakpoint',10
2486
        db      'be ...       - enable breakpoint',10,0
205 heavyiron 2487
 
3675 GerdtR 2488
;-----------------------------------------------------------------------------
2489
;                    Individual command help messages
205 heavyiron 2490
 
3675 GerdtR 2491
aQuit   db      5,'quit',0
2492
QuitHelp db     'Quit from debugger',10
2493
QuitSyntax db   'Usage: quit',10,0
205 heavyiron 2494
 
3675 GerdtR 2495
aLoad   db      5,'load',0
2496
LoadHelp db     'Load program for debugging',10
2497
LoadSyntax db   'Usage: load  [parameters]',10,0
205 heavyiron 2498
 
3675 GerdtR 2499
aReload db      7,'reload',0
2500
ReloadHelp db   'Reload debugging program (restart debug session)',10
2501
ReloadSyntax db 'Usage: reload',10,0
2502
 
2503
aTerminate db   10,'terminate',0
205 heavyiron 2504
TerminateHelp db 'Terminate debugged program',10
2505
TerminateSyntax db 'Usage: terminate',10,0
2506
 
3675 GerdtR 2507
aDetach db      7,'detach',0
2508
DetachHelp db   'Detach from debugged program',10
2509
DetachSyntax db 'Usage: detach',10,0
205 heavyiron 2510
 
3675 GerdtR 2511
aSuspend db     5,'stop',0
2512
SuspendHelp db  'Suspend execution of debugged program',10
205 heavyiron 2513
SuspendSyntax db 'Usage: stop',10,0
2514
 
3675 GerdtR 2515
aResume db      2,'g',0
2516
ResumeHelp db   'Go (resume execution of debugged program)',10
2517
ResumeSyntax db 'Usage: g',10
2518
        db      '   or: g  - wait until specified address is reached',10,0
205 heavyiron 2519
 
3675 GerdtR 2520
aStep   db      2,'s',0
2521
StepHelp db     'Make step in debugged program',10
2522
StepSyntax db   'Usage: s []',10,0
205 heavyiron 2523
 
3675 GerdtR 2524
aProceed db     2,'p',0
2525
ProceedHelp db  'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10
2526
ProceedSyntax db 'Usage: p []',10,0
205 heavyiron 2527
 
3675 GerdtR 2528
aDump   db      2,'d',0
2529
DumpHelp db     'Dump data of debugged program',10
2530
DumpSyntax db   'Usage: d  - dump data at specified address',10
2531
        db      '   or: d              - continue current dump',10,0
205 heavyiron 2532
 
3675 GerdtR 2533
aCalc   db      2,'?',0
2534
CalcHelp db     'Calculate value of expression',10
2535
CalcSyntax db   'Usage: ? ',10,0
205 heavyiron 2536
 
3675 GerdtR 2537
aUnassemble db  2,'u',0
205 heavyiron 2538
UnassembleHelp db 'Unassemble',10
3675 GerdtR 2539
UnassembleSyntax db      'Usage: u  - unassemble instructions at specified address',10
2540
                 db      '   or: u              - continue current unassemble screen',10,0
205 heavyiron 2541
 
3675 GerdtR 2542
aReg    db      2,'r',0
2543
RHelp   db      'Set register value',10
2544
RSyntax db      'Usage: r  ',10
2545
        db      '   or: r = - set value of  to ',10,0
205 heavyiron 2546
 
3675 GerdtR 2547
aBp     db      3,'bp',0
2548
BpHelp  db      'set BreakPoint on execution',10
2549
BpSyntax db     'Usage: bp ',10,0
205 heavyiron 2550
 
3675 GerdtR 2551
aBpm    db      4,'bpm',0
2552
aBpmb   db      5,'bpmb',0
2553
aBpmw   db      5,'bpmw',0
2554
aBpmd   db      5,'bpmd',0
2555
BpmHelp db      'set BreakPoint on Memory access',10
2556
        db      'Maximum 4 breakpoints of this type are allowed',10
2557
        db      'Note that for this breaks debugger is activated after access',10
2558
BpmSyntax db    'Usage: bpmb [w] ',10
2559
        db      '       bpmw [w] ',10
2560
        db      '       bpmd [w] ',10
2561
        db      '       bpm is synonym for bpmd',10
2562
        db      '"w" means break only on writes (default is on read/write)',10,0
205 heavyiron 2563
 
3675 GerdtR 2564
aBl     db      3,'bl',0
2565
BlHelp  db      'Breakpoint List',10
2566
BlSyntax db     'Usage: bl          - list all breakpoints',10
2567
        db      '       bl  - display info on particular breakpoint',10,0
205 heavyiron 2568
 
3675 GerdtR 2569
aBc     db      3,'bc',0
2570
BcHelp  db      'Breakpoint Clear',10
2571
BcSyntax db     'Usage: bc ',10
2572
        db      'Examples: bc 2',10
2573
        db      '          bc 1 3 4 A',10,0
205 heavyiron 2574
 
3675 GerdtR 2575
aBd     db      3,'bd',0
2576
BdHelp  db      'Breakpoint Disable',10
2577
BdSyntax db     'Usage: bd ',10
2578
        db      'Examples: bd 2',10
2579
        db      '          bd 1 3 4 A',10,0
205 heavyiron 2580
 
3675 GerdtR 2581
aBe     db      3,'be',0
2582
BeHelp  db      'Breakpoint Enable',10
2583
BeSyntax db     'Usage: be ',10
2584
        db      'Examples: be 2',10
2585
        db      '          be 1 3 4 A',10,0
205 heavyiron 2586
 
3675 GerdtR 2587
aUnpack db      7,'unpack',0
2588
UnpackHelp db   'Try to bypass unpacker code',10
2589
UnpackSyntax db 'Usage: unpack',10,0
205 heavyiron 2590
 
3675 GerdtR 2591
aLoadSymbols db 13,'load-symbols',0
542 diamond 2592
LoadSymbolsHelp db 'Load symbolic information for executable',10
2593
LoadSymbolsSyntax db 'Usage: load-symbols ',10,0
2594
 
205 heavyiron 2595
aUnknownCommand db 'Unknown command',10,0
2596
 
3675 GerdtR 2597
;-----------------------------------------------------------------------------
2598
;                             Error messages
2599
 
2600
load_err_msg    db      'Cannot load program. ',0
2601
unk_err_msg     db      'Unknown error code -%4X',10,0
2602
aCannotLoadFile db      'Cannot load file. ',0
2603
unk_err_msg2    db      'Unknown error code %4X.',10,0
205 heavyiron 2604
load_err_msgs:
3675 GerdtR 2605
        dd      .1, 0, .3, 0, .5, .6, 0, 0, .9, .A, 0, 0, 0, 0, 0, 0
2606
        dd      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .1E, .1F, .20
2607
.1              db      'HD undefined.',10,0
2608
.3              db      'Unknown FS.',10,0
2609
.5              db      'File not found.',10,0
2610
.6              db      'Unexpected EOF.',10,0
2611
.9              db      'FAT table corrupted.',10,0
2612
.A              db      'Access denied.',10,0
2613
.1E             db      'No memory.',10,0
2614
.1F             db      'Not Menuet/Kolibri executable.',10,0
2615
.20             db      'Too many processes.',10,0
2616
load_succ_msg   db      'Program loaded successfully! PID=%4X. Use "g" to run.',10,0
2617
need_debuggee   db      'No program loaded. Use "load" command.',10,0
2618
aAlreadyLoaded  db      'Program is already loaded. Use "terminate" or "detach" commands',10,0
2619
terminated_msg  db      'Program terminated.',10,0
2620
aException      db      'Debugged program caused an exception %2X. '
2621
aSuspended      db      'Suspended',10,0
2622
aContinued      db      'Continuing',10,0
2623
aRunningErr     db      'Program is running',10,0
2624
read_mem_err    db      'ERROR: cannot read process memory!!!',10,0
205 heavyiron 2625
aBreakpointLimitExceeded db 'Breakpoint limit exceeded',10,0
3675 GerdtR 2626
aBreakErr       db      'Cannot activate breakpoint, it will be disabled',10,0
2627
aDuplicateBreakpoint db 'Duplicate breakpoint',10,0
2628
aInvalidBreak   db      'Invalid breakpoint number',10,0
2629
OnBeErrMsg      db      'There is already enabled breakpoint on this address',10,0
2630
aBreakNum       db      '%2X: at %8X',0
2631
aMemBreak1      db      '%2X: on ',0
2632
aMemBreak2      db      'read from ',0
2633
aMemBreak3      db      'access of ',0
2634
aMemBreak4      db      'byte',0
2635
aMemBreak5      db      'word',0
2636
aMemBreak6      db      'dword',0
2637
aMemBreak7      db      ' at %8X',0
2638
aOneShot        db      ', one-shot',0
2639
aDisabled       db      ', disabled',0
2640
aBreakStop      db      'Breakpoint #%2X',10,0
2641
aUserBreak      db      'int3 command at %8X',10,0
2642
;dbgmsg_str     db      'Debug message for process %4X.',10,0
2643
aInvAddr        db      'Invalid address',10,0
2644
NoPrgLoaded_str db      'No program loaded'
205 heavyiron 2645
NoPrgLoaded_len = $ - NoPrgLoaded_str
3675 GerdtR 2646
aRunning        db      'Running'
2647
aPaused         db      'Paused'
2648
aMain            db        '[ CPU ]'
2649
aSSE            db        '[ SSE ]'
2650
aAVX            db        '[ AVX ]'
2651
aMSR            db        '[ MSR ]'
2652
aPoint          db      0x1C
2653
aMinus          db      '-'
2654
aColon          db      ':'
2655
aSpace          db      ' '
2656
aQuests         db      '??'
2657
aDots           db      '...'
2658
aParseError     db      'Parse error',10,0
2659
aDivByZero      db      'Division by 0',10,0
2660
calc_string     db      '%8X',10,0
2661
aNoMemory       db      'No memory',10,0
2662
aSymbolsLoaded  db      'Symbols loaded',10,0
2663
aUnaligned      db      'Unaligned address',10,0
2664
aEnabledBreakErr db     'Enabled breakpoints are not allowed',10,0
2665
aInterrupted    db      'Interrupted',10,0
2666
aUnpacked       db      'Unpacked successful!',10,0
2667
aPacked1        db      'Program is probably packed with ',0
2668
aPacked2        db      '.',10,'Try to unpack automatically? [y/n]: ',0
2669
aY_str          db      'y',10,0
2670
aN_str          db      'n',10,0
2671
mxp_nrv_name    db      'mxp_nrv',0
2672
mxp_name        db      'mxp',0
2673
mxp_lzo_name    db      'mxp_lzo',0
2674
mtappack_name   db      'mtappack',0
2675
flags           db      'CPAZSDO'
2676
flags_bits      db      0,2,4,6,7,10,11
2677
 
2678
;-----------------------------------------------------------------------------
2679
;                         Registers strings
2680
 
205 heavyiron 2681
regs_strs:
3675 GerdtR 2682
        db      'EAX='
2683
        db      'EBX='
2684
        db      'ECX='
2685
        db      'EDX='
2686
        db      'ESI='
2687
        db      'EDI='
2688
        db      'EBP='
2689
        db      'ESP='
2690
        db      'EIP='
2691
        db      'EFLAGS='
2692
fpu_strs:
2693
        db        'ST0='
2694
        db        'ST1='
2695
        db        'ST2='
2696
        db        'ST3='
2697
        db        'ST4='
2698
        db        'ST5='
2699
        db        'ST6='
2700
        db        'ST7='
2701
mmx_strs:
2702
        db        'MM0='
2703
        db        'MM1='
2704
        db        'MM2='
2705
        db        'MM3='
2706
        db        'MM4='
2707
        db        'MM5='
2708
        db        'MM6='
2709
        db        'MM7='
2710
sse_strs:
2711
        db        '-XMM0-'
2712
        db      '-XMM1-'
2713
        db      '-XMM2-'
2714
        db      '-XMM3-'
2715
        db      '-XMM4-'
2716
        db      '-XMM5-'
2717
        db      '-XMM6-'
2718
        db      '-XMM7-'
2719
avx_strs:
2720
        db      '-YMM0-'
2721
        db      '-YMM1-'
2722
        db      '-YMM2-'
2723
        db      '-YMM3-'
2724
        db      '-YMM4-'
2725
        db      '-YMM5-'
2726
        db      '-YMM6-'
2727
        db      '-YMM7-'
205 heavyiron 2728
 
3675 GerdtR 2729
debuggee_pid    dd      0
2730
bSuspended      db      0
2731
bAfterGo        db      0
2732
temp_break      dd      0
2733
reg_mode        db        1
205 heavyiron 2734
 
3675 GerdtR 2735
include 'disasm_tbl.inc'
205 heavyiron 2736
 
2737
reg_table:
3675 GerdtR 2738
        db      2,'al',0
2739
        db      2,'cl',1
2740
        db      2,'dl',2
2741
        db      2,'bl',3
2742
        db      2,'ah',4
2743
        db      2,'ch',5
2744
        db      2,'dh',6
2745
        db      2,'bh',7
2746
        db      2,'ax',8
2747
        db      2,'cx',9
2748
        db      2,'dx',10
2749
        db      2,'bx',11
2750
        db      2,'sp',12
2751
        db      2,'bp',13
2752
        db      2,'si',14
2753
        db      2,'di',15
2754
        db      3,'eax',16
2755
        db      3,'ecx',17
2756
        db      3,'edx',18
2757
        db      3,'ebx',19
2758
        db      3,'esp',20
2759
        db      3,'ebp',21
2760
        db      3,'esi',22
2761
        db      3,'edi',23
2762
        db      3,'eip',24
2763
        db      0
205 heavyiron 2764
 
542 diamond 2765
IncludeIGlobals
2766
 
2767
fn70_read_block:
3675 GerdtR 2768
        dd      0
2769
        dq      0
2770
        dd      ?
2771
        dd      ?
2772
        db      0
2773
        dd      ?
542 diamond 2774
 
2775
fn70_attr_block:
3675 GerdtR 2776
        dd      5
2777
        dd      0,0,0
2778
        dd      fileattr
2779
        db      0
2780
        dd      ?
542 diamond 2781
 
205 heavyiron 2782
fn70_load_block:
3675 GerdtR 2783
        dd      7
2784
        dd      1
2785
load_params dd  0
2786
        dd      0
2787
        dd      0
205 heavyiron 2788
i_end:
2789
loadname:
3675 GerdtR 2790
        db      0
2791
        rb      255
205 heavyiron 2792
 
3675 GerdtR 2793
symbolsfile     rb      260
542 diamond 2794
 
205 heavyiron 2795
prgname_ptr dd ?
2796
prgname_len dd ?
2797
 
542 diamond 2798
IncludeUGlobals
2799
 
3675 GerdtR 2800
dbgwnd          dd      ?
205 heavyiron 2801
 
3675 GerdtR 2802
messages        rb      messages_height*messages_width
2803
messages_pos    dd      ?
205 heavyiron 2804
 
3675 GerdtR 2805
cmdline         rb      cmdline_width+1
2806
cmdline_len     dd      ?
2807
cmdline_pos     dd      ?
2808
curarg          dd      ?
205 heavyiron 2809
 
3675 GerdtR 2810
cmdline_prev    rb      cmdline_width+1
205 heavyiron 2811
 
3675 GerdtR 2812
was_temp_break  db      ?
205 heavyiron 2813
 
3675 GerdtR 2814
dbgbufsize      dd      ?
2815
dbgbuflen       dd      ?
2816
dbgbuf          rb      256
542 diamond 2817
 
3675 GerdtR 2818
fileattr        rb      40
2819
 
205 heavyiron 2820
needzerostart:
2821
 
2822
context:
2823
 
3675 GerdtR 2824
_eip    dd      ?
2825
_eflags dd      ?
2826
_eax    dd      ?
2827
_ecx    dd      ?
2828
_edx    dd      ?
2829
_ebx    dd      ?
2830
_esp    dd      ?
2831
_ebp    dd      ?
2832
_esi    dd      ?
2833
_edi    dd      ?
205 heavyiron 2834
oldcontext rb $-context
2835
 
3675 GerdtR 2836
mmx_context:
2837
_mm0    dq        ?
2838
_mm1    dq        ?
2839
_mm2    dq        ?
2840
_mm3    dq        ?
2841
_mm4    dq        ?
2842
_mm5    dq        ?
2843
_mm6    dq        ?
2844
_mm7    dq        ?
2845
oldmmxcontext rb $-mmx_context
205 heavyiron 2846
 
3675 GerdtR 2847
fpu_context:
2848
_st0    dq      ?
2849
_st1    dq      ?
2850
_st2    dq      ?
2851
_st3    dq      ?
2852
_st4    dq      ?
2853
_st5    dq      ?
2854
_st6    dq      ?
2855
_st7    dq      ?
2856
oldfpucontext rb $-fpu_context
2857
 
2858
sse_context:
2859
_xmm0    dq        2 dup ?
2860
_xmm1   dq        2 dup ?
2861
_xmm2   dq      2 dup ?
2862
_xmm3   dq      2 dup ?
2863
_xmm4   dq      2 dup ?
2864
_xmm5   dq      2 dup ?
2865
_xmm6   dq      2 dup ?
2866
_xmm7   dq      2 dup ?
2867
oldssecontext rb $-sse_context
2868
 
2869
avx_context:
2870
_ymm0   dq      4 dup ?
2871
_ymm1   dq      4 dup ?
2872
_ymm2   dq      4 dup ?
2873
_ymm3   dq      4 dup ?
2874
_ymm4   dq      4 dup ?
2875
_ymm5   dq      4 dup ?
2876
_ymm6   dq      4 dup ?
2877
_ymm7   dq      4 dup ?
2878
oldavxcontext rb $-avx_context
2879
 
2880
step_num dd 0
2881
proc_num dd 0
2882
dumpread dd     ?
2883
dumppos dd      ?
2884
dumpdata rb     dump_height*10h
2885
 
205 heavyiron 2886
; breakpoint structure:
2887
; dword +0: address
2888
; byte +4: flags
2889
; bit 0: 1 <=> breakpoint valid
2890
; bit 1: 1 <=> breakpoint disabled
2891
; bit 2: 1 <=> one-shot breakpoint
2892
; bit 3: 1 <=> DRx breakpoint
2893
; byte +5: overwritten byte
2894
;          for DRx breaks: flags + (index shl 6)
2895
breakpoints_n = 256
3675 GerdtR 2896
breakpoints     rb      breakpoints_n*6
2897
drx_break       rd      4
205 heavyiron 2898
 
3675 GerdtR 2899
disasm_buf_size         dd      ?
205 heavyiron 2900
 
3675 GerdtR 2901
symbols         dd      ?
2902
num_symbols     dd      ?
542 diamond 2903
 
3675 GerdtR 2904
bReload                 db      ?
205 heavyiron 2905
 
2906
needzeroend:
2907
 
3675 GerdtR 2908
disasm_buffer           rb      256
2909
disasm_start_pos        dd      ?
2910
disasm_cur_pos          dd      ?
2911
disasm_cur_str          dd      ?
2912
disasm_string           rb      256
205 heavyiron 2913
 
3675 GerdtR 2914
i_param         rb      256
205 heavyiron 2915
 
2916
; stack
3675 GerdtR 2917
        align   400h
2918
        rb      400h
205 heavyiron 2919
used_mem:
3675 GerdtR 2920
 
2921
; vim: ft=fasm tabstop=4
2922