Subversion Repositories Kolibri OS

Rev

Rev 1269 | Rev 4285 | 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
205 heavyiron 866
CtrlF7:
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
205 heavyiron 875
CtrlF8:
3675 GerdtR 876
        cmp     [debuggee_pid], 0
877
        jz      CtrlF7.no
878
        call    OnProceed
879
        jmp     CtrlF7.no
205 heavyiron 880
 
3675 GerdtR 881
;-----------------------------------------------------------------------------
882
;                       Step execution event
883
 
884
;Here we get [] argument at do step  times
205 heavyiron 885
OnStep:
3675 GerdtR 886
        cmp     [bSuspended], 0
887
        jz      .running
888
        cmp     [step_num], 0
889
        jg      .stepone
890
        mov     esi, [curarg]
891
        cmp     byte [esi], 0
892
        jz      .stepone
893
        call    get_hex_number
894
        jc      .ret
895
        cmp     eax, 0 ; check if lesser or equal than 0
896
        jle     .ret
897
        mov     [step_num], eax
898
        mov     [curarg], 0
205 heavyiron 899
 
3675 GerdtR 900
    .stepone:
901
        call    get_context
902
        or      byte [_eflags+1], 1             ; set TF
903
        call    set_context
904
        and     byte [_eflags+1], not 1
905
    ; if instruction at eip is "int xx", set one-shot breakpoint immediately after
906
        mov     eax, [_eip]
907
        call    find_enabled_breakpoint
908
        jnz     @f
909
        cmp     byte [edi+5], 0xCD
910
        jz      .int
911
 
912
     @@:
913
        push    0
914
        ;push    69
915
        ;pop     eax
916
        ;push    6
917
        ;pop     ebx
918
        ;mov     ecx, [debuggee_pid]
919
        ;push    3
920
        ;pop     edx
921
        ;mov     edi, esp
922
        ;mov     esi, [_eip]
923
        mcall    69, 6, [debuggee_pid], 3, [_eip], esp
924
        cmp     eax, edx
925
        pop     eax
926
        jnz     .doit
927
        cmp     al, 0xCD
928
        jz      .int
929
        cmp     ax, 0x050F
930
        jz      .syscall
931
        cmp     ax, 0x340F
932
        jz      .sysenter
933
 
934
    ; resume process
935
    .doit:
936
        call    GoOn
937
        cmp     [bAfterGo], 0
938
        jz      @f
939
        mov     [bAfterGo], 2
940
 
941
    @@:
942
        mov     eax, [step_num]
943
        dec     eax
944
        cmp     eax, 0
945
        jle     .ret
946
        mov     [step_num], eax
947
        jmp     .stepone
948
 
949
    .ret:
950
        mov     [step_num], 0
951
        ret
952
 
953
    ; return address is [ebp-4]
954
    .sysenter:
955
        push    0
956
        ;push    69
957
        ;pop     eax
958
        inc     edx     ; read 4 bytes
959
        mov     esi, [_ebp]
960
        sub     esi, 4
961
        mcall    69
962
        cmp     eax, edx
963
        pop     eax
964
        jnz     .syscall
965
        push    eax
966
        and     byte [_eflags+1], not 1
967
        call    set_context
968
        pop     eax
969
        jmp     @f
970
 
971
    .syscall:
972
        and     byte [_eflags+1], not 1 ; clear TF - avoid system halt (!)
973
        call    set_context
974
 
975
    .int:
976
        mov     eax, [_eip]
977
        inc     eax
978
        inc     eax
979
 
980
    @@:
981
        push    eax
982
        call    find_enabled_breakpoint
983
        pop     eax
984
        jz      .doit
985
    ; there is no enabled breakpoint yet; set temporary breakpoint
986
        mov     bl, 5
987
        call    add_breakpoint
988
        jmp     .doit
989
 
990
    .running:
991
        mov     esi, aRunningErr
992
        jmp     put_message
993
 
994
;-----------------------------------------------------------------------------
995
;                       Proceed process event
996
 
205 heavyiron 997
OnProceed:
3675 GerdtR 998
        cmp     [bSuspended], 0
999
        jz      OnStep.running
1000
        cmp     [proc_num], 0
1001
        jg      .procone
1002
        mov     esi, [curarg]
1003
        cmp     byte [esi], 0
1004
        jz      .procone
1005
        call    get_hex_number
1006
        jc      .ret
1007
        cmp     eax, 0 ; check if lesser than 0
1008
        jle     .ret
1009
        mov     [proc_num], eax
1010
        mov     [curarg], 0
205 heavyiron 1011
 
3675 GerdtR 1012
    .procone:
1013
        mov     esi, [_eip]
205 heavyiron 1014
 
3675 GerdtR 1015
    @@:
1016
        call    get_byte_nobreak
1017
        jc      OnStep.stepone
1018
        inc     esi
1019
    ; skip prefixes
1020
        call    is_prefix
1021
        jz      @b
1022
        cmp     al, 0xE8        ; call
1023
        jnz     @f
1024
        add     esi, 4
1025
        jmp     .doit
205 heavyiron 1026
 
3675 GerdtR 1027
    ; A4,A5 = movs; A6,A7 = cmps
1028
    @@:
1029
        cmp     al, 0xA4
1030
        jb      @f
1031
        cmp     al, 0xA8
1032
        jb      .doit
205 heavyiron 1033
 
3675 GerdtR 1034
    ; AA,AB = stos; AC,AD = lods; AE,AF = scas
1035
    @@:
1036
        cmp     al, 0xAA
1037
        jb      @f
1038
        cmp     al, 0xB0
1039
        jb      .doit
205 heavyiron 1040
 
3675 GerdtR 1041
    ; E0 = loopnz; E1 = loopz; E2 = loop
1042
    @@:
1043
        cmp     al, 0xE0
1044
        jb      .noloop
1045
        cmp     al, 0xE2
1046
        ja      .noloop
1047
        inc     esi
1048
        jmp     .doit
205 heavyiron 1049
 
3675 GerdtR 1050
    ; FF /2 = call
1051
    .noloop:
1052
        cmp     al, 0xFF
1053
        jnz     OnStep.stepone
1054
        call    get_byte_nobreak
1055
        jc      OnStep.stepone
1056
        inc     esi
1057
        mov     cl, al
1058
        and     al, 00111000b
1059
        cmp     al, 00010000b
1060
        jnz     OnStep.stepone
1061
    ; skip instruction
1062
        mov     al, cl
1063
        and     eax, 7
1064
        shr     cl, 6
1065
        jz      .mod0
1066
        jp      .doit
1067
        cmp     al, 4
1068
        jnz     @f
1069
        inc     esi
205 heavyiron 1070
 
3675 GerdtR 1071
    @@:
1072
        inc     esi
1073
        dec     cl
1074
        jz      @f
1075
        add     esi, 3
205 heavyiron 1076
 
3675 GerdtR 1077
    @@:
1078
        jmp     .doit
205 heavyiron 1079
 
3675 GerdtR 1080
    .mod0:
1081
        cmp     al, 4
1082
        jnz     @f
1083
        call    get_byte_nobreak
1084
        jc      OnStep.stepone
1085
        inc     esi
1086
        and     al, 7
205 heavyiron 1087
 
3675 GerdtR 1088
    @@:
1089
        cmp     al, 5
1090
        jnz     .doit
1091
        add     esi, 4
205 heavyiron 1092
 
3675 GerdtR 1093
    .doit:
1094
    ; insert one-shot breakpoint at esi and resume
1095
        call    get_byte_nobreak
1096
        jc      OnStep.stepone
1097
        mov     eax, esi
1098
        call    find_enabled_breakpoint
1099
        jz      @f
1100
        mov     eax, esi
1101
        mov     bl, 5
1102
        call    add_breakpoint
1103
        jmp     OnStep.doit
1104
 
1105
    @@:
1106
        mov     eax, [proc_num]
1107
        dec     eax
1108
        cmp     eax, 0
1109
        jle     .ret
1110
        mov     [proc_num], eax
1111
        jmp     .procone
1112
 
1113
    .ret:
1114
        mov     [proc_num], 0
1115
        ret
1116
 
1117
;-----------------------------------------------------------------------------
1118
;                        Read next byte of machine code
1119
 
1120
get_byte_nobreak:
1121
        mov     eax, esi
1122
        call    find_enabled_breakpoint
1123
        jnz     .nobreak
1124
        mov     al, [edi+5]
1125
        clc
1126
        ret
1127
 
1128
    .nobreak:
1129
        ;push    69
1130
        ;pop     eax
1131
        ;push    6
1132
        ;pop     ebx
1133
        ;mov     ecx, [debuggee_pid]
1134
        xor     edx, edx
1135
        push    edx
1136
        inc     edx
1137
        mov     edi, esp
1138
        mcall    69, 6, [debuggee_pid]
1139
        dec     eax
1140
        clc
1141
        jz      @f
1142
        stc
1143
 
1144
    @@:
1145
        pop     eax
1146
        ret
1147
 
1148
include 'parser.inc'
1149
 
1150
;-----------------------------------------------------------------------------
1151
;                        Calculate expression event
1152
 
205 heavyiron 1153
OnCalc:
3675 GerdtR 1154
        mov     esi, [curarg]
1155
        call    calc_expression
1156
        jc      .ret
1157
        push    ebp
1158
        mov     esi, calc_string
1159
        call    put_message_nodraw
1160
        jmp     draw_messages
1161
 
1162
    .ret:
1163
        ret
205 heavyiron 1164
 
3675 GerdtR 1165
;-----------------------------------------------------------------------------
1166
;                            Dump memory event
1167
 
205 heavyiron 1168
OnDump:
3675 GerdtR 1169
        mov     esi, [curarg]
1170
        cmp     byte [esi], 0
1171
        jnz     .param
1172
        add     [dumppos], dump_height*10h
1173
        jmp     .doit
1174
 
1175
    .param:
1176
        call    calc_expression
1177
        jc      .ret
1178
        mov     [dumppos], ebp
205 heavyiron 1179
 
3675 GerdtR 1180
    .doit:
1181
        call    get_dump
1182
        call    draw_dump.redraw
1183
 
1184
    .ret:
1185
        ret
1186
 
1187
;-----------------------------------------------------------------------------
1188
;                   Dissassemble block of executable event
1189
 
205 heavyiron 1190
OnUnassemble:
3675 GerdtR 1191
        mov     esi, [curarg]
1192
        cmp     byte [esi], 0
1193
        jnz     .param
1194
        mov     eax, [disasm_start_pos]
1195
        mov     ecx, disasm_height
1196
        mov     [disasm_cur_pos], eax
205 heavyiron 1197
 
3675 GerdtR 1198
    .l:
1199
        mov     eax, [disasm_cur_pos]
1200
        call    find_symbol
1201
        jc      @f
1202
        dec     ecx
1203
        jz      .m
1204
 
1205
    @@:
1206
        push    ecx
1207
        call    disasm_instr
1208
        pop     ecx
1209
        jc      .err
1210
        loop    .l
1211
 
1212
    .m:
1213
        mov     eax, [disasm_cur_pos]
1214
        jmp     .doit
1215
 
1216
    .param:
1217
        call    calc_expression
1218
        jc      .ret
1219
        mov     eax, ebp
1220
 
1221
    .doit:
1222
        push    eax
1223
        push    [disasm_start_pos]
1224
        mov     [disasm_start_pos], eax
1225
        call    update_disasm
1226
        pop     [disasm_start_pos]
1227
        pop     eax
1228
        cmp     [disasm_cur_str], 0
1229
        jz      @f
1230
        mov     [disasm_start_pos], eax
1231
 
1232
    .ret:
1233
        ret
1234
 
1235
    @@:
1236
        call    update_disasm
1237
 
1238
    .err:
1239
        mov     esi, aInvAddr
1240
        jmp     put_message
1241
 
1242
;-----------------------------------------------------------------------------
1243
;                       Access to register value event
1244
 
205 heavyiron 1245
OnReg:
3675 GerdtR 1246
        mov     esi, [curarg]
1247
        call    get_arg.skip_spaces
1248
        call    find_reg
1249
        jnc     @f
205 heavyiron 1250
 
3675 GerdtR 1251
    .err:
1252
        mov     esi, RSyntax
1253
        jmp     put_message
1254
 
1255
    @@:
1256
        call    get_arg.skip_spaces
1257
        test    al, al
1258
        jz      .err
1259
        cmp     al, '='
1260
        jnz     @f
1261
        inc     esi
1262
        call    get_arg.skip_spaces
1263
        test    al, al
1264
        jz      .err
1265
 
1266
    @@:
1267
        push    edi
1268
        call    calc_expression
1269
        pop     edi
1270
        jc      .ret
1271
    ; now edi=register id, ebp=value
1272
        cmp     [bSuspended], 0
1273
        mov     esi, aRunningErr
1274
        jz      put_message
1275
        xchg    eax, ebp
1276
        cmp     edi, 24
1277
        jz      .eip
1278
        sub     edi, 4
1279
        jb      .8lo
1280
        sub     edi, 4
1281
        jb      .8hi
1282
        sub     edi, 8
1283
        jb      .16
1284
        mov     [_eax+edi*4], eax
1285
        jmp     .ret
1286
 
1287
    .16:
1288
        mov     word [_eax+(edi+8)*4], ax
1289
        jmp     .ret
1290
 
1291
    .8lo:
1292
        mov     byte [_eax+(edi+4)*4], al
1293
        jmp     .ret
1294
 
1295
    .8hi:
1296
        mov     byte [_eax+(edi+4)*4+1], al
1297
        jmp     .ret
1298
 
1299
    .eip:
1300
        mov     [_eip], eax
1301
        call    update_disasm_eip
1302
 
1303
    .ret:
1304
        call    set_context
1305
        jmp     draw_registers.redraw
1306
 
1307
;-----------------------------------------------------------------------------
1308
;                        Breakpoints manipulation
205 heavyiron 1309
OnBp:
3675 GerdtR 1310
        mov     esi, [curarg]
1311
        call    calc_expression
1312
        jc      .ret
1313
        xchg    eax, ebp
1314
        push    eax
1315
        call    find_breakpoint
1316
        inc     eax
1317
        pop     eax
1318
        jz      .notfound
1319
        mov     esi, aDuplicateBreakpoint
1320
        jmp     .sayerr
205 heavyiron 1321
 
3675 GerdtR 1322
    .notfound:
1323
        mov     bl, 1
1324
        call    add_breakpoint
1325
        jnc     .ret
1326
        mov     esi, aBreakpointLimitExceeded
1327
 
1328
    .sayerr:
1329
        call    put_message
1330
 
1331
    .ret:
1332
        jmp     draw_disasm.redraw
1333
 
205 heavyiron 1334
OnBpmb:
3675 GerdtR 1335
        mov     dh, 0011b
1336
        jmp     DoBpm
1337
 
205 heavyiron 1338
OnBpmw:
3675 GerdtR 1339
        mov     dh, 0111b
1340
        jmp     DoBpm
1341
 
205 heavyiron 1342
OnBpmd:
3675 GerdtR 1343
        mov     dh, 1111b
1344
 
205 heavyiron 1345
DoBpm:
3675 GerdtR 1346
        mov     esi, [curarg]
1347
        cmp     byte [esi], 'w'
1348
        jnz     @f
1349
        and     dh, not 2
1350
        inc     esi
205 heavyiron 1351
 
3675 GerdtR 1352
    @@:
1353
        push    edx
1354
        call    calc_expression
1355
        pop     edx
1356
        jnc     @f
1357
        ret
1358
 
1359
    ; ebp = expression, dh = flags
1360
    @@:
1361
        movzx   eax, dh
1362
        shr     eax, 2
1363
        test    ebp, eax
1364
        jz      @f
1365
        mov     esi, aUnaligned
1366
        jmp     put_message
1367
 
1368
    @@:
1369
        mov     eax, ebp
1370
        mov     bl, 0Bh
1371
        call    add_breakpoint
1372
        jnc     @f
1373
        mov     esi, aBreakpointLimitExceeded
1374
        jmp     put_message
1375
 
1376
    ; now find index
1377
    @@:
1378
        push    eax
1379
        xor     ecx, ecx
1380
 
1381
    .l1:
1382
        cmp     [drx_break+ecx*4], 0
1383
        jnz     .l2
1384
        ;push    69
1385
        ;pop     eax
1386
        push    ecx
1387
        mov     dl, cl
1388
        ;mov     ecx, [debuggee_pid]
1389
        mov     esi, ebp
1390
        ;push    9
1391
        ;pop     ebx
1392
        mcall    69, 9, [debuggee_pid]
1393
        test    eax, eax
1394
        jz      .ok
1395
        pop     ecx
1396
 
1397
    .l2:
1398
        inc     ecx
1399
        cmp     ecx, 4
1400
        jb      .l1
1401
        pop     eax
1402
        call    clear_breakpoint
1403
        mov     esi, aBreakpointLimitExceeded
1404
        jmp     put_message
1405
 
1406
    .ok:
1407
        pop     ecx
1408
        pop     eax
1409
        and     byte [edi], not 2       ; breakpoint is enabled
1410
        shl     dl, 6
1411
        or      dl, dh
1412
        mov     byte [edi+1], dl
1413
        inc     eax
1414
        mov     [drx_break+ecx*4], eax
1415
        ret
1416
 
205 heavyiron 1417
OnBc:
3675 GerdtR 1418
        mov     esi, [curarg]
205 heavyiron 1419
 
3675 GerdtR 1420
    @@:
1421
        call    get_hex_number
1422
        jc      OnBp.ret
1423
        call    clear_breakpoint
1424
        jmp     @b
1425
 
205 heavyiron 1426
OnBd:
3675 GerdtR 1427
        mov     esi, [curarg]
205 heavyiron 1428
 
3675 GerdtR 1429
    @@:
1430
        call    get_hex_number
1431
        jc      OnBp.ret
1432
        call    disable_breakpoint
1433
        jmp     @b
1434
 
205 heavyiron 1435
OnBe:
3675 GerdtR 1436
        mov     esi, [curarg]
205 heavyiron 1437
 
3675 GerdtR 1438
    @@:
1439
        call    get_hex_number
1440
        jc      OnBp.ret
1441
        push    eax
1442
        call    find_enabled_breakpoint
1443
        pop     eax
1444
        jz      .err
1445
        call    enable_breakpoint
1446
        jmp     @b
1447
 
1448
    .err:
1449
        mov     esi, OnBeErrMsg
1450
        jmp     put_message
1451
 
1452
; TODO: split it out in parser.inc
205 heavyiron 1453
get_hex_number:
3675 GerdtR 1454
        call    get_arg.skip_spaces
1455
        xor     ecx, ecx
1456
        xor     edx, edx
205 heavyiron 1457
 
3675 GerdtR 1458
    @@:
1459
        lodsb
1460
        call    is_hex_digit
1461
        jc      .ret
1462
        shl     edx, 4
1463
        or      dl, al
1464
        inc     ecx
1465
        jmp     @b
1466
 
1467
    .ret:
1468
        dec     esi
1469
        cmp     ecx, 1
1470
        xchg    eax, edx
1471
        ret
1472
 
1473
;-----------------------------------------------------------------------------
1474
;                       Breakpoints list event
1475
 
205 heavyiron 1476
OnBl:
3675 GerdtR 1477
        mov     esi, [curarg]
1478
        cmp     byte [esi], 0
1479
        jz      .listall
1480
        call    get_hex_number
1481
        jc      .ret
1482
        cmp     eax, breakpoints_n
1483
        jae     .err
1484
        push    eax
1485
        add     eax, eax
1486
        lea     edi, [breakpoints + eax + eax*2]
1487
        pop     eax
1488
        test    byte [edi+4], 1
1489
        jz      .err
1490
        call    show_break_info
205 heavyiron 1491
 
3675 GerdtR 1492
    .ret:
1493
        ret
1494
 
1495
    .err:
1496
        mov     esi, aInvalidBreak
1497
        jmp     put_message
1498
 
1499
    .listall:
1500
        mov     edi, breakpoints
1501
        xor     eax, eax
1502
 
1503
    @@:
1504
        test    byte [edi+4], 1
1505
        jz      .cont
1506
        push    edi eax
1507
        call    show_break_info
1508
        pop     eax edi
1509
 
1510
    .cont:
1511
        add     edi, 6
1512
        inc     eax
1513
        cmp     eax, breakpoints_n
1514
        jb      @b
1515
        ret
1516
 
1517
;-----------------------------------------------------------------------------
1518
 
205 heavyiron 1519
show_break_info:
3675 GerdtR 1520
        push    edi
1521
        test    byte [edi+4], 8
1522
        jnz     .dr
1523
        push    dword [edi]
1524
        push    eax
1525
        mov     esi, aBreakNum
1526
        call    put_message_nodraw
1527
        jmp     .cmn
205 heavyiron 1528
 
3675 GerdtR 1529
    .dr:
1530
        push    eax
1531
        mov     esi, aMemBreak1
1532
        call    put_message_nodraw
1533
        pop     edi
1534
        push    edi
1535
        mov     esi, aMemBreak2
1536
        test    byte [edi+5], 2
1537
        jz      @f
1538
        mov     esi, aMemBreak3
1539
 
1540
    @@:
1541
        call    put_message_nodraw
1542
        pop     edi
1543
        push    edi
1544
        mov     esi, aMemBreak6
1545
        test    byte [edi+5], 8
1546
        jnz     @f
1547
        mov     esi, aMemBreak5
1548
        test    byte [edi+5], 4
1549
        jnz     @f
1550
        mov     esi, aMemBreak4
1551
 
1552
    @@:
1553
        call    put_message_nodraw
1554
        pop     edi
1555
        push    edi
1556
        push    dword [edi]
1557
        mov     esi, aMemBreak7
1558
        call    put_message_nodraw
1559
 
1560
    .cmn:
1561
        pop     edi
1562
        test    byte [edi+4], 2
1563
        jz      @f
1564
        push    edi
1565
        mov     esi, aDisabled
1566
        call    put_message_nodraw
1567
        pop     edi
1568
 
1569
    @@:
1570
        test    byte [edi+4], 4
1571
        jz      @f
1572
        mov     esi, aOneShot
1573
        call    put_message_nodraw
1574
 
1575
    @@:
1576
        mov     esi, newline
1577
        jmp     put_message
1578
 
1579
;-----------------------------------------------------------------------------
1580
;                        Add breakpoint
1581
; in: EAX = address; BL = flags
1582
; out: CF = 1 => error
1583
;      CF = 0 and EAX = breakpoint number
1584
 
205 heavyiron 1585
add_breakpoint:
3675 GerdtR 1586
        xor     ecx, ecx
1587
        mov     edi, breakpoints
205 heavyiron 1588
 
3675 GerdtR 1589
    @@:
1590
        test    byte [edi+4], 1
1591
        jz      .found
1592
        add     edi, 6
1593
        inc     ecx
1594
        cmp     ecx, breakpoints_n
1595
        jb      @b
1596
        stc
1597
        ret
1598
 
1599
    .found:
1600
        stosd
1601
        xchg    eax, ecx
1602
        mov     [edi], bl
1603
        test    bl, 2
1604
        jnz     @f
1605
        or      byte [edi], 2
1606
        push    eax
1607
        call    enable_breakpoint
1608
        pop     eax
1609
 
1610
    @@:
1611
        clc
1612
        ret
1613
 
1614
;-----------------------------------------------------------------------------
1615
;                         Remove breakpoint
1616
 
205 heavyiron 1617
clear_breakpoint:
3675 GerdtR 1618
        cmp     eax, breakpoints_n
1619
        jae     .ret
1620
        mov     ecx, 4
1621
        inc     eax
205 heavyiron 1622
 
3675 GerdtR 1623
    .1:
1624
        cmp     [drx_break-4+ecx*4], eax
1625
        jnz     @f
1626
        and     [drx_break-4+ecx*4], 0
1627
 
1628
    @@:
1629
        loop    .1
1630
        dec     eax
1631
        push    eax
1632
        add     eax, eax
1633
        lea     edi, [breakpoints + eax + eax*2 + 4]
1634
        test    byte [edi], 1
1635
        pop     eax
1636
        jz      .ret
1637
        push    edi
1638
        call    disable_breakpoint
1639
        pop     edi
1640
        mov     byte [edi], 0
1641
 
1642
    .ret:
1643
        ret
1644
 
1645
;-----------------------------------------------------------------------------
1646
;                          Disable breakpoint
1647
 
205 heavyiron 1648
disable_breakpoint:
3675 GerdtR 1649
        cmp     eax, breakpoints_n
1650
        jae     .ret
1651
        add     eax, eax
1652
        lea     edi, [breakpoints + eax + eax*2 + 5]
1653
        test    byte [edi-1], 1
1654
        jz      .ret
1655
        test    byte [edi-1], 2
1656
        jnz     .ret
1657
        or      byte [edi-1], 2
1658
        test    byte [edi-1], 8
1659
        jnz     .dr
1660
        push    esi
1661
        ;push    7
1662
        ;pop     ebx
1663
        ;push    69
1664
        ;pop     eax
1665
        ;mov     ecx, [debuggee_pid]
1666
        ;xor     edx, edx
1667
        ;inc     edx
1668
        ;mov     esi, [edi-5]
1669
        mcall    69, 7, [debuggee_pid], 1, [edi-5]
1670
        pop     esi
205 heavyiron 1671
 
3675 GerdtR 1672
    .ret:
1673
        ret
1674
 
1675
    .dr:
1676
        mov     dl, [edi]
1677
        shr     dl, 6
1678
        mov     dh, 80h
1679
        ;push    69
1680
        ;pop     eax
1681
        ;push    9
1682
        ;pop     ebx
1683
        ;mov     ecx, [debuggee_pid]
1684
        mcall    69, 9, [debuggee_pid]
1685
        ret
1686
 
1687
;-----------------------------------------------------------------------------
1688
;                           Enable breakpoint
1689
 
205 heavyiron 1690
enable_breakpoint:
3675 GerdtR 1691
        push    esi
1692
        cmp     eax, breakpoints_n
1693
        jae     .ret
1694
        add     eax, eax
1695
        lea     edi, [breakpoints + eax + eax*2 + 5]
1696
        test    byte [edi-1], 1
1697
        jz      .ret
1698
        test    byte [edi-1], 2
1699
        jz      .ret
1700
        and     byte [edi-1], not 2
1701
        test    byte [edi-1], 8
1702
        jnz     .dr
1703
        ;push    6
1704
        ;pop     ebx
1705
        ;push    69
1706
        ;pop     eax
1707
        ;mov     esi, [edi-5]
1708
        ;mov     ecx, [debuggee_pid]
1709
        ;xor     edx, edx
1710
        ;inc     edx
1711
        mcall    69, 6, [debuggee_pid], 1, [edi-5]
1712
        dec     eax
1713
        jnz     .err
1714
        ;mov     al, 69
1715
        push    0xCC
1716
        mov     edi, esp
1717
        inc     ebx
1718
        mcall    69
1719
        pop     eax
205 heavyiron 1720
 
3675 GerdtR 1721
    .ret:
1722
        pop     esi
1723
        ret
205 heavyiron 1724
 
3675 GerdtR 1725
    .err:
1726
        or      byte [edi-1], 2
1727
        mov     esi, aBreakErr
1728
        call    put_message
1729
        pop     esi
1730
        ret
205 heavyiron 1731
 
3675 GerdtR 1732
    .dr:
1733
        ;push    9
1734
        ;pop     ebx
1735
        ;push    69
1736
        ;pop     eax
1737
        mov     esi, [edi-5]
1738
        ;mov     ecx, [debuggee_pid]
1739
        mov     dl, [edi]
1740
        shr     dl, 6
1741
        mov     dh, [edi]
1742
        and     dh, 0xF
1743
        mcall    69, 9, [debuggee_pid]
1744
        test    eax, eax
1745
        jnz     .err
1746
        pop     esi
1747
        ret
205 heavyiron 1748
 
3675 GerdtR 1749
;-----------------------------------------------------------------------------
1750
;                             Find breakpoint
542 diamond 1751
 
3675 GerdtR 1752
find_breakpoint:
1753
        xor     ecx, ecx
1754
        xchg    eax, ecx
1755
        mov     edi, breakpoints
542 diamond 1756
 
3675 GerdtR 1757
    @@:
1758
        test    byte [edi+4], 1
1759
        jz      .cont
1760
        test    byte [edi+4], 8
1761
        jnz     .cont
1762
        cmp     [edi], ecx
1763
        jz      .found
542 diamond 1764
 
3675 GerdtR 1765
    .cont:
1766
        add     edi, 6
1767
        inc     eax
1768
        cmp     eax, breakpoints_n
1769
        jb      @b
1770
        or      eax, -1
542 diamond 1771
 
3675 GerdtR 1772
    .found:
1773
        ret
542 diamond 1774
 
3675 GerdtR 1775
;-----------------------------------------------------------------------------
1776
;
542 diamond 1777
 
3675 GerdtR 1778
find_enabled_breakpoint:
1779
        xor     ecx, ecx
1780
        xchg    eax, ecx
1781
        mov     edi, breakpoints
542 diamond 1782
 
3675 GerdtR 1783
    @@:
1784
        test    byte [edi+4], 1
1785
        jz      .cont
1786
        test    byte [edi+4], 2 or 8
1787
        jnz     .cont
1788
        cmp     [edi], ecx
1789
        jz      .found
542 diamond 1790
 
3675 GerdtR 1791
    .cont:
1792
        add     edi, 6
1793
        inc     eax
1794
        cmp     eax, breakpoints_n
1795
        jb      @b
1796
        or      eax, -1
205 heavyiron 1797
 
3675 GerdtR 1798
    .found:
1799
        ret
205 heavyiron 1800
 
3675 GerdtR 1801
; TODO: add find_disabled_breakpoint
205 heavyiron 1802
 
3675 GerdtR 1803
;-----------------------------------------------------------------------------
1804
;                       Unpack executable event
205 heavyiron 1805
 
3675 GerdtR 1806
OnUnpack:
1807
    ; program must be loaded - checked when command was parsed
1808
    ; program must be stopped
1809
        mov     esi, aRunningErr
1810
        cmp     [bSuspended], 0
1811
        jz      put_message
1812
   ; all breakpoints must be disabled
1813
        mov     edi, breakpoints
205 heavyiron 1814
 
3675 GerdtR 1815
    @@:
1816
        test    byte [edi+4], 1
1817
        jz      .cont
1818
        test    byte [edi+4], 2
1819
        jnz     .cont
1820
        mov     esi, aEnabledBreakErr
1821
        jmp     put_message
205 heavyiron 1822
 
3675 GerdtR 1823
    .cont:
1824
        add     edi, 6
1825
        cmp     edi, breakpoints+breakpoints_n*6
1826
        jb      @b
1827
    ; ok, now do it
1828
    ; set breakpoint on 0xC dword access
1829
        push    9
1830
        pop     ebx
1831
        mov     ecx, [debuggee_pid]
1832
        mov     dx, 1111b*256
1833
        push    0xC
1834
        pop     esi
205 heavyiron 1835
 
3675 GerdtR 1836
    @@:
1837
        ;push    69
1838
        ;pop     eax
1839
        mcall    69
1840
        test    eax, eax
1841
        jz      .breakok
1842
        inc     edx
1843
        cmp     dl, 4
1844
        jb      @b
809 diamond 1845
 
3675 GerdtR 1846
    .breakok:
1847
        call    GoOn
809 diamond 1848
 
3675 GerdtR 1849
    ; now wait for event
1850
    .wait:
1851
        ;push    10
1852
        ;pop     eax
1853
        mcall    10
1854
        dec     eax
1855
        jz      .redraw
1856
        dec     eax
1857
        jz      .key
1858
        dec     eax
1859
        jnz     .debug
1860
    ; button; we have only one button, close
1861
        or      eax, -1
1862
        mcall
205 heavyiron 1863
 
3675 GerdtR 1864
    .redraw:
1865
        call    draw_window
1866
        jmp     .wait
205 heavyiron 1867
 
3675 GerdtR 1868
    .key:
1869
        mov     al, 2
1870
        mcall
1871
        cmp     ah, 3   ; Ctrl+C
1872
        jnz     .wait
205 heavyiron 1873
 
3675 GerdtR 1874
    .userbreak:
1875
        mov     esi, aInterrupted
205 heavyiron 1876
 
3675 GerdtR 1877
    .x1:
1878
        push    edx esi
1879
        call    put_message
1880
        pop     esi edx
1881
        or      dh, 80h
1882
        ;push    69
1883
        ;pop     eax
1884
        ;push    9
1885
        ;pop     ebx
1886
        ;mov     ecx, [debuggee_pid]
1887
        mcall    69, 9, [debuggee_pid]
1888
        cmp     esi, aUnpacked
1889
        jnz     OnSuspend
1890
        jmp     AfterSuspend
205 heavyiron 1891
 
3675 GerdtR 1892
    .debug:
1893
        cmp     [dbgbuflen], 4*3
1894
        jnz     .notour
1895
        cmp     dword [dbgbuf], 3
1896
        jnz     .notour
1897
        test    byte [dbgbuf+8], 1
1898
        jnz     .our
205 heavyiron 1899
 
3675 GerdtR 1900
    .notour:
1901
        mov     esi, aInterrupted
1902
        push    edx
1903
        call    put_message
1904
        pop     edx
1905
        or      dh, 80h
1906
        ;push    69
1907
        ;pop     eax
1908
        ;push    9
1909
        ;pop     ebx
1910
        ;mov     ecx, [debuggee_pid]
1911
        mcall    69, 9, [debuggee_pid]
1912
        jmp     debugmsg
205 heavyiron 1913
 
3675 GerdtR 1914
    .our:
1915
        and     [dbgbuflen], 0
1916
        push    edx
1917
        call    get_context
1918
        push    eax
1919
        ;mov     al, 69
1920
        ;mov     bl, 6
1921
        ;mov     ecx, [debuggee_pid]
1922
        ;mov     edi, esp
1923
        ;push    4
1924
        ;pop     edx
1925
        ;push    0xC
1926
        ;pop     esi
1927
        mcall    69, 6, [debuggee_pid], 4, 0xC, esp
1928
        pop     eax
1929
        pop     edx
1930
        cmp     eax, [_eip]
1931
        jz      .done
1932
        call    DoResume
1933
        jmp     .wait
205 heavyiron 1934
 
3675 GerdtR 1935
    .done:
1936
        mov     esi, aUnpacked
1937
        jmp     .x1
809 diamond 1938
 
3675 GerdtR 1939
;-----------------------------------------------------------------------------
1940
;                  Working with program symbols
1941
;
1942
;  TODO: split to symbols.inc
205 heavyiron 1943
 
3675 GerdtR 1944
include 'sort.inc'
205 heavyiron 1945
 
3675 GerdtR 1946
; compare what? Add context-relative comment and name
1947
compare:
1948
        cmpsd
1949
        jnz     @f
1950
        cmp     esi, edi
205 heavyiron 1951
 
3675 GerdtR 1952
    @@:
1953
        ret
205 heavyiron 1954
 
3675 GerdtR 1955
; purpose of this function?
1956
compare2:
1957
        cmpsd
205 heavyiron 1958
 
3675 GerdtR 1959
    @@:
1960
        cmpsb
1961
        jnz     @f
1962
        cmp     byte [esi-1], 0
1963
        jnz     @b
1964
        cmp     esi, edi
205 heavyiron 1965
 
3675 GerdtR 1966
    @@:
1967
        ret
205 heavyiron 1968
 
3675 GerdtR 1969
free_symbols:
1970
        mov     ecx, [symbols]
1971
        jecxz   @f
1972
        mcall   68, 13
1973
        and     [symbols], 0
1974
        and     [num_symbols], 0
205 heavyiron 1975
 
3675 GerdtR 1976
    @@:
1977
        ret
1978
;-----------------------------------------------------------------------------
1979
;                        Load symbols event
205 heavyiron 1980
 
3675 GerdtR 1981
OnLoadSymbols.fileerr:
1982
        test    ebp, ebp
1983
        jz      @f
1984
        mcall   68, 13, edi
1985
        ret
205 heavyiron 1986
 
3675 GerdtR 1987
    @@:
1988
        push    eax
1989
        mcall   68, 13, edi
1990
        mov     esi, aCannotLoadFile
1991
        call    put_message_nodraw
1992
        pop     eax
1993
        cmp     eax, 0x20
1994
        jae     .unk
1995
        mov     esi, [load_err_msgs + eax*4]
1996
        test    esi, esi
1997
        jnz     put_message
205 heavyiron 1998
 
3675 GerdtR 1999
    .unk:
2000
        mov     esi, unk_err_msg2
2001
        jmp     put_message
205 heavyiron 2002
 
3675 GerdtR 2003
OnLoadSymbols:
2004
        xor     ebp, ebp
2005
   ; load input file
2006
        mov     esi, [curarg]
2007
        call    free_symbols
809 diamond 2008
 
3675 GerdtR 2009
    .silent:
2010
        xor     edi, edi
2011
        cmp     [num_symbols], edi
2012
        jz      @f
2013
 
2014
        call    free_symbols
2015
        ;ret
2016
 
2017
    @@:
2018
        mov     ebx, fn70_attr_block
2019
        mov     [ebx+21], esi
2020
        mcall   70
2021
        test    eax, eax
2022
        jnz     .fileerr
2023
        cmp     dword [fileattr+36], edi
2024
        jnz     .memerr
2025
        mov     ecx, dword [fileattr+32]
2026
        mcall   68, 12
2027
        test    eax, eax
2028
        jz      .memerr
2029
        mov     edi, eax
2030
        mov     ebx, fn70_read_block
2031
        mov     [ebx+12], ecx
2032
        mov     [ebx+16], edi
2033
        mov     [ebx+21], esi
2034
        mcall   70
2035
        test    eax, eax
2036
        jnz     .fileerr
2037
    ; calculate memory requirements
2038
        lea     edx, [ecx+edi-1]        ; edx = EOF-1
2039
        mov     esi, edi
2040
        xor     ecx, ecx
809 diamond 2041
 
3675 GerdtR 2042
    .calcloop:
2043
        cmp     esi, edx
2044
        jae     .calcdone
2045
        cmp     word [esi], '0x'
2046
        jnz     .skipline
2047
        inc     esi
2048
        inc     esi
809 diamond 2049
 
3675 GerdtR 2050
    @@:
2051
        cmp     esi, edx
2052
        jae     .calcdone
2053
        lodsb
2054
        or      al, 20h
2055
        sub     al, '0'
2056
        cmp     al, 9
2057
        jbe     @b
2058
        sub     al, 'a'-'0'-10
2059
        cmp     al, 15
2060
        jbe     @b
2061
        dec     esi
205 heavyiron 2062
 
3675 GerdtR 2063
    @@:
2064
        cmp     esi, edx
2065
        ja      .calcdone
2066
        lodsb
2067
        cmp     al, 20h
2068
        jz      @b
2069
        jb      .calcloop
2070
        cmp     al, 9
2071
        jz      @b
2072
        add     ecx, 12+1
2073
        inc     [num_symbols]
809 diamond 2074
 
3675 GerdtR 2075
    @@:
2076
        inc     ecx
2077
        cmp     esi, edx
2078
        ja      .calcdone
2079
        lodsb
2080
        cmp     al, 0xD
2081
        jz      .calcloop
2082
        cmp     al, 0xA
2083
        jz      .calcloop
2084
        jmp     @b
205 heavyiron 2085
 
3675 GerdtR 2086
    .skipline:
2087
        cmp     esi, edx
2088
        jae     .calcdone
2089
        lodsb
2090
        cmp     al, 0xD
2091
        jz      .calcloop
2092
        cmp     al, 0xA
2093
        jz      .calcloop
2094
        jmp     .skipline
542 diamond 2095
 
3675 GerdtR 2096
    .calcdone:
2097
        mcall   68, 12
2098
        test    eax, eax
2099
        jnz     .memok
2100
        inc     ebx
2101
        mov     ecx, edi
2102
        mov     al, 68
2103
        mcall
205 heavyiron 2104
 
3675 GerdtR 2105
    .memerr:
2106
        mov     esi, aNoMemory
2107
        jmp     put_message
205 heavyiron 2108
 
3675 GerdtR 2109
    .memok:
2110
        mov     [symbols], eax
2111
        mov     ebx, eax
2112
        push    edi
2113
        mov     esi, edi
2114
        mov     edi, [num_symbols]
2115
        lea     ebp, [eax+edi*4]
2116
        lea     edi, [eax+edi*8]
205 heavyiron 2117
 
3675 GerdtR 2118
    ; parse input data,
2119
    ; esi->input, edx->EOF, ebx->ptrs, edi->names
2120
    .readloop:
2121
        cmp     esi, edx
2122
        jae     .readdone
2123
        cmp     word [esi], '0x'
2124
        jnz     .readline
2125
        inc     esi
2126
        inc     esi
2127
        xor     eax, eax
2128
        xor     ecx, ecx
205 heavyiron 2129
 
3675 GerdtR 2130
    @@:
2131
        shl     ecx, 4
2132
        add     ecx, eax
2133
        cmp     esi, edx
2134
        jae     .readdone
2135
        lodsb
2136
        or      al, 20h
2137
        sub     al, '0'
2138
        cmp     al, 9
2139
        jbe     @b
2140
        sub     al, 'a'-'0'-10
2141
        cmp     al, 15
2142
        jbe     @b
2143
        dec     esi
809 diamond 2144
 
3675 GerdtR 2145
    @@:
2146
        cmp     esi, edx
2147
        ja      .readdone
2148
        lodsb
2149
        cmp     al, 20h
2150
        jz      @b
2151
        jb      .readloop
2152
        cmp     al, 9
2153
        jz      @b
2154
        mov     dword [ebx], edi
2155
        add     ebx, 4
2156
        mov     dword [ebp], edi
2157
        add     ebp, 4
2158
        mov     dword [edi], ecx
2159
        add     edi, 4
2160
        stosb
205 heavyiron 2161
 
3675 GerdtR 2162
    @@:
2163
        xor     eax, eax
2164
        stosb
2165
        cmp     esi, edx
2166
        ja      .readdone
2167
        lodsb
2168
        cmp     al, 0xD
2169
        jz      .readloop
2170
        cmp     al, 0xA
2171
        jz      .readloop
2172
        mov     byte [edi-1], al
2173
        jmp     @b
205 heavyiron 2174
 
3675 GerdtR 2175
    .readline:
2176
        cmp     esi, edx
2177
        jae     .readdone
2178
        lodsb
2179
        cmp     al, 0xD
2180
        jz      .readloop
2181
        cmp     al, 0xA
2182
        jz      .readloop
2183
        jmp     .readline
205 heavyiron 2184
 
3675 GerdtR 2185
    .readdone:
2186
        pop     ecx
2187
        mcall   68, 13
2188
        mov     ecx, [num_symbols]
2189
        mov     edx, [symbols]
2190
        mov     ebx, compare
2191
        call    sort
2192
        mov     ecx, [num_symbols]
2193
        lea     edx, [edx+ecx*4]
2194
        mov     ebx, compare2
2195
        call    sort
2196
        mov     esi, aSymbolsLoaded
2197
        call    put_message
2198
        jmp     draw_disasm.redraw
205 heavyiron 2199
 
3675 GerdtR 2200
;-----------------------------------------------------------------------------
2201
;
2202
; in: EAX = address
2203
; out: ESI, CF
205 heavyiron 2204
 
3675 GerdtR 2205
find_symbol:
2206
        cmp     [num_symbols], 0
2207
        jnz     @f
205 heavyiron 2208
 
3675 GerdtR 2209
    .ret0:
2210
        xor     esi, esi
2211
        stc
2212
        ret
205 heavyiron 2213
 
3675 GerdtR 2214
    @@:
2215
        push    ebx ecx edx
2216
        xor     edx, edx
2217
        mov     esi, [symbols]
2218
        mov     ecx, [num_symbols]
2219
        mov     ebx, [esi]
2220
        cmp     [ebx], eax
2221
        jz      .donez
2222
        jb      @f
2223
        pop     edx ecx ebx
2224
        jmp     .ret0
809 diamond 2225
 
3675 GerdtR 2226
    @@:
2227
    ; invariant: symbols_addr[edx] < eax < symbols_addr[ecx]
2228
    ; TODO: add meaningful label names
2229
    .0:
2230
        push    edx
205 heavyiron 2231
 
3675 GerdtR 2232
    .1:
2233
        add     edx, ecx
2234
        sar     edx, 1
2235
        cmp     edx, [esp]
2236
        jz      .done2
2237
        mov     ebx, [esi+edx*4]
2238
        cmp     [ebx], eax
2239
        jz      .done
2240
        ja      .2
2241
        mov     [esp], edx
2242
        jmp     .1
205 heavyiron 2243
 
3675 GerdtR 2244
    .2:
2245
        mov     ecx, edx
2246
        pop     edx
2247
        jmp     .0
205 heavyiron 2248
 
3675 GerdtR 2249
    .donecont:
2250
        dec     edx
205 heavyiron 2251
 
3675 GerdtR 2252
    .done:
2253
        test    edx, edx
2254
        jz      @f
2255
        mov     ebx, [esi+edx*4-4]
2256
        cmp     [ebx], eax
2257
        jz      .donecont
205 heavyiron 2258
 
3675 GerdtR 2259
    @@:
2260
        pop     ecx
205 heavyiron 2261
 
3675 GerdtR 2262
    .donez:
2263
        mov     esi, [esi+edx*4]
2264
        add     esi, 4
2265
        pop     edx ecx ebx
2266
        clc
2267
        ret
205 heavyiron 2268
 
3675 GerdtR 2269
    .done2:
2270
        lea     esi, [esi+edx*4]
2271
        pop     ecx edx ecx ebx
2272
        stc
2273
        ret
205 heavyiron 2274
 
3675 GerdtR 2275
;-----------------------------------------------------------------------------
2276
;
2277
; in: esi->name
2278
; out: if found: CF = 0, EAX = value
2279
;      otherwise CF = 1
2280
find_symbol_name:
2281
        cmp     [num_symbols], 0
2282
        jnz     @f
205 heavyiron 2283
 
3675 GerdtR 2284
    .stc_ret:
2285
        stc
2286
        ret
205 heavyiron 2287
 
3675 GerdtR 2288
    @@:
2289
        push    ebx ecx edx edi
2290
        push    -1
2291
        pop     edx
2292
        mov     ebx, [symbols]
2293
        mov     ecx, [num_symbols]
2294
        lea     ebx, [ebx+ecx*4]
2295
 
2296
    ; invariant: symbols_name[edx] < name < symbols_name[ecx]
2297
    .0:
2298
        push    edx
542 diamond 2299
 
3675 GerdtR 2300
    .1:
2301
        add     edx, ecx
2302
        sar     edx, 1
2303
        cmp     edx, [esp]
2304
        jz      .done2
2305
        call    .cmp
2306
        jz      .done
2307
        jb      .2
2308
        mov     [esp], edx
2309
        jmp     .1
542 diamond 2310
 
3675 GerdtR 2311
    .2:
2312
        mov     ecx, edx
2313
        pop     edx
2314
        jmp     .0
542 diamond 2315
 
3675 GerdtR 2316
    .done:
2317
        pop     ecx
542 diamond 2318
 
3675 GerdtR 2319
    .donez:
2320
        mov     eax, [ebx+edx*4]
2321
        mov     eax, [eax]
2322
        pop     edi edx ecx ebx
2323
        clc
2324
        ret
542 diamond 2325
 
3675 GerdtR 2326
    .done2:
2327
        pop     edx edi edx ecx ebx
2328
        stc
2329
        ret
809 diamond 2330
 
3675 GerdtR 2331
    .cmp:
2332
        mov     edi, [ebx+edx*4]
2333
        push    esi
2334
        add     edi, 4
809 diamond 2335
 
3675 GerdtR 2336
    @@:
2337
        cmpsb
2338
        jnz     @f
2339
        cmp     byte [esi-1], 0
2340
        jnz     @b
542 diamond 2341
 
3675 GerdtR 2342
    @@:
2343
        pop     esi
2344
        ret
809 diamond 2345
 
3675 GerdtR 2346
;-----------------------------------------------------------------------------
2347
;                        Include disassembler engine
2348
 
2349
include 'disasm.inc'
2350
 
205 heavyiron 2351
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2352
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2353
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2354
 
2355
caption_str db 'Kolibri Debugger',0
2356
caption_len = $ - caption_str
2357
 
3675 GerdtR 2358
begin_str db    'Kolibri Debugger, version 0.32',10
2359
        db      'Hint: type "help" for help, "quit" for quit'
2360
newline db      10,0
2361
prompt  db      '> ',0
2362
 
205 heavyiron 2363
help_groups:
3675 GerdtR 2364
        dd      aControl, 0, 0, help_control_msg
2365
        db      0
2366
        dd      aData, 0, 0, help_data_msg
2367
        db      0
2368
        dd      aBreakpoints, 0, 0, help_breaks_msg
2369
        db      0
2370
 
2371
;-----------------------------------------------------------------------------
2372
;                   Commands format definitions
2373
 
2374
; TODO: make it with macros
2375
 
205 heavyiron 2376
; flags field:
2377
; &1: command may be called without parameters
2378
; &2: command may be called with parameters
2379
; &4: command may be called without loaded program
2380
; &8: command may be called with loaded program
2381
commands:
3675 GerdtR 2382
        dd      _aH, OnHelp, HelpSyntax, HelpHelp
2383
        db      0Fh
2384
        dd      aHelp, OnHelp, HelpSyntax, HelpHelp
2385
        db      0Fh
2386
        dd      aQuit, OnQuit, QuitSyntax, QuitHelp
2387
        db      0Dh
2388
        dd      aLoad, OnLoad, LoadSyntax, LoadHelp
2389
        db      6
2390
        dd      aReload, OnReload, ReloadSyntax, ReloadHelp
2391
        db      0Dh
2392
        dd      aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
2393
        db      9
2394
        dd      aDetach, OnDetach, DetachSyntax, DetachHelp
2395
        db      9
2396
        dd      aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
2397
        db      9
2398
        dd      aResume, OnResume, ResumeSyntax, ResumeHelp
2399
        db      0Bh
2400
        dd      aStep, OnStep, StepSyntax, StepHelp
2401
        db      0Bh
2402
        dd      aProceed, OnProceed, ProceedSyntax, ProceedHelp
2403
        db      0Bh
2404
        dd      aCalc, OnCalc, CalcSyntax, CalcHelp
2405
        db      0Eh
2406
        dd      aDump, OnDump, DumpSyntax, DumpHelp
2407
        db      0Bh
2408
        dd      aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
2409
        db      0Bh
2410
        dd      aBp, OnBp, BpSyntax, BpHelp
2411
        db      0Ah
2412
        dd      aBpm, OnBpmb, BpmSyntax, BpmHelp
2413
        db      0Ah
2414
        dd      aBpmb, OnBpmb, BpmSyntax, BpmHelp
2415
        db      0Ah
2416
        dd      aBpmw, OnBpmw, BpmSyntax, BpmHelp
2417
        db      0Ah
2418
        dd      aBpmd, OnBpmd, BpmSyntax, BpmHelp
2419
        db      0Ah
2420
        dd      aBl, OnBl, BlSyntax, BlHelp
2421
        db      0Bh
2422
        dd      aBc, OnBc, BcSyntax, BcHelp
2423
        db      0Ah
2424
        dd      aBd, OnBd, BdSyntax, BdHelp
2425
        db      0Ah
2426
        dd      aBe, OnBe, BeSyntax, BeHelp
2427
        db      0Ah
2428
        dd      aReg, OnReg, RSyntax, RHelp
2429
        db      0Ah
2430
        dd      aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
2431
        db      9
2432
        dd      aLoadSymbols, OnLoadSymbols, LoadSymbolsSyntax, LoadSymbolsHelp
2433
        db      0Ah
2434
        dd      0
205 heavyiron 2435
 
3675 GerdtR 2436
;-----------------------------------------------------------------------------
2437
;                   Help messages for commands groups
2438
 
2439
aHelp   db      5,'help',0
2440
_aH     db      2,'h',0
2441
HelpHelp db     'Help on specified function',10
2442
HelpSyntax db   'Usage: h or help [group | command]',10,0
2443
 
2444
help_msg db     'List of known command groups:',10
2445
        db      '"help control"     - display list of control commands',10
2446
        db      '"help data"        - display list of commands concerning data',10
2447
        db      '"help breakpoints" - display list of commands concerning breakpoints',10,0
2448
 
2449
;               Control commands group
2450
 
2451
aControl db     8,'control',0
2452
help_control_msg db     'List of control commands:',10
2453
        db      'h = help             - help',10
2454
        db      'quit                 - exit from debugger',10
2455
        db      'load  [params] - load program for debugging',10
2456
        db      'reload               - reload debugging program',10
2457
        db      'load-symbols   - load information on symbols for program',10
2458
        db      'terminate            - terminate loaded program',10
2459
        db      'detach               - detach from debugging program',10
2460
        db      'stop                 - suspend execution of debugging program',10
2461
        db      'g []     - go on (resume execution of debugging program)',10
2462
        db      's []            - program step, also ',10
2463
        db      'p []            - program wide step, also ',10
2464
        db      'unpack               - try to bypass unpacker code (heuristic)',10,0
2465
 
2466
;               Data commands group
2467
 
2468
aData   db      5,'data',0
2469
help_data_msg db        'List of data commands:',10
2470
        db      '?        - calculate value of expression',10
2471
        db      'd []     - dump data at given address',10
2472
        db      'u []     - unassemble instructions at given address',10
2473
        db      'r   or',10
2474
        db      'r = - set register value',10,0
2475
 
2476
;               Breakpoints commands group
2477
 
205 heavyiron 2478
aBreakpoints db 12,'breakpoints',0
3675 GerdtR 2479
help_breaks_msg db      'List of breakpoints commands:',10
2480
        db      'bp       - set breakpoint on execution',10
2481
        db      'bpm[b|w|d]   - set breakpoint on memory access',10
2482
        db      'bl []        - breakpoint(s) info',10
2483
        db      'bc ...       - clear breakpoint',10
2484
        db      'bd ...       - disable breakpoint',10
2485
        db      'be ...       - enable breakpoint',10,0
205 heavyiron 2486
 
3675 GerdtR 2487
;-----------------------------------------------------------------------------
2488
;                    Individual command help messages
205 heavyiron 2489
 
3675 GerdtR 2490
aQuit   db      5,'quit',0
2491
QuitHelp db     'Quit from debugger',10
2492
QuitSyntax db   'Usage: quit',10,0
205 heavyiron 2493
 
3675 GerdtR 2494
aLoad   db      5,'load',0
2495
LoadHelp db     'Load program for debugging',10
2496
LoadSyntax db   'Usage: load  [parameters]',10,0
205 heavyiron 2497
 
3675 GerdtR 2498
aReload db      7,'reload',0
2499
ReloadHelp db   'Reload debugging program (restart debug session)',10
2500
ReloadSyntax db 'Usage: reload',10,0
2501
 
2502
aTerminate db   10,'terminate',0
205 heavyiron 2503
TerminateHelp db 'Terminate debugged program',10
2504
TerminateSyntax db 'Usage: terminate',10,0
2505
 
3675 GerdtR 2506
aDetach db      7,'detach',0
2507
DetachHelp db   'Detach from debugged program',10
2508
DetachSyntax db 'Usage: detach',10,0
205 heavyiron 2509
 
3675 GerdtR 2510
aSuspend db     5,'stop',0
2511
SuspendHelp db  'Suspend execution of debugged program',10
205 heavyiron 2512
SuspendSyntax db 'Usage: stop',10,0
2513
 
3675 GerdtR 2514
aResume db      2,'g',0
2515
ResumeHelp db   'Go (resume execution of debugged program)',10
2516
ResumeSyntax db 'Usage: g',10
2517
        db      '   or: g  - wait until specified address is reached',10,0
205 heavyiron 2518
 
3675 GerdtR 2519
aStep   db      2,'s',0
2520
StepHelp db     'Make step in debugged program',10
2521
StepSyntax db   'Usage: s []',10,0
205 heavyiron 2522
 
3675 GerdtR 2523
aProceed db     2,'p',0
2524
ProceedHelp db  'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10
2525
ProceedSyntax db 'Usage: p []',10,0
205 heavyiron 2526
 
3675 GerdtR 2527
aDump   db      2,'d',0
2528
DumpHelp db     'Dump data of debugged program',10
2529
DumpSyntax db   'Usage: d  - dump data at specified address',10
2530
        db      '   or: d              - continue current dump',10,0
205 heavyiron 2531
 
3675 GerdtR 2532
aCalc   db      2,'?',0
2533
CalcHelp db     'Calculate value of expression',10
2534
CalcSyntax db   'Usage: ? ',10,0
205 heavyiron 2535
 
3675 GerdtR 2536
aUnassemble db  2,'u',0
205 heavyiron 2537
UnassembleHelp db 'Unassemble',10
3675 GerdtR 2538
UnassembleSyntax db      'Usage: u  - unassemble instructions at specified address',10
2539
                 db      '   or: u              - continue current unassemble screen',10,0
205 heavyiron 2540
 
3675 GerdtR 2541
aReg    db      2,'r',0
2542
RHelp   db      'Set register value',10
2543
RSyntax db      'Usage: r  ',10
2544
        db      '   or: r = - set value of  to ',10,0
205 heavyiron 2545
 
3675 GerdtR 2546
aBp     db      3,'bp',0
2547
BpHelp  db      'set BreakPoint on execution',10
2548
BpSyntax db     'Usage: bp ',10,0
205 heavyiron 2549
 
3675 GerdtR 2550
aBpm    db      4,'bpm',0
2551
aBpmb   db      5,'bpmb',0
2552
aBpmw   db      5,'bpmw',0
2553
aBpmd   db      5,'bpmd',0
2554
BpmHelp db      'set BreakPoint on Memory access',10
2555
        db      'Maximum 4 breakpoints of this type are allowed',10
2556
        db      'Note that for this breaks debugger is activated after access',10
2557
BpmSyntax db    'Usage: bpmb [w] ',10
2558
        db      '       bpmw [w] ',10
2559
        db      '       bpmd [w] ',10
2560
        db      '       bpm is synonym for bpmd',10
2561
        db      '"w" means break only on writes (default is on read/write)',10,0
205 heavyiron 2562
 
3675 GerdtR 2563
aBl     db      3,'bl',0
2564
BlHelp  db      'Breakpoint List',10
2565
BlSyntax db     'Usage: bl          - list all breakpoints',10
2566
        db      '       bl  - display info on particular breakpoint',10,0
205 heavyiron 2567
 
3675 GerdtR 2568
aBc     db      3,'bc',0
2569
BcHelp  db      'Breakpoint Clear',10
2570
BcSyntax db     'Usage: bc ',10
2571
        db      'Examples: bc 2',10
2572
        db      '          bc 1 3 4 A',10,0
205 heavyiron 2573
 
3675 GerdtR 2574
aBd     db      3,'bd',0
2575
BdHelp  db      'Breakpoint Disable',10
2576
BdSyntax db     'Usage: bd ',10
2577
        db      'Examples: bd 2',10
2578
        db      '          bd 1 3 4 A',10,0
205 heavyiron 2579
 
3675 GerdtR 2580
aBe     db      3,'be',0
2581
BeHelp  db      'Breakpoint Enable',10
2582
BeSyntax db     'Usage: be ',10
2583
        db      'Examples: be 2',10
2584
        db      '          be 1 3 4 A',10,0
205 heavyiron 2585
 
3675 GerdtR 2586
aUnpack db      7,'unpack',0
2587
UnpackHelp db   'Try to bypass unpacker code',10
2588
UnpackSyntax db 'Usage: unpack',10,0
205 heavyiron 2589
 
3675 GerdtR 2590
aLoadSymbols db 13,'load-symbols',0
542 diamond 2591
LoadSymbolsHelp db 'Load symbolic information for executable',10
2592
LoadSymbolsSyntax db 'Usage: load-symbols ',10,0
2593
 
205 heavyiron 2594
aUnknownCommand db 'Unknown command',10,0
2595
 
3675 GerdtR 2596
;-----------------------------------------------------------------------------
2597
;                             Error messages
2598
 
2599
load_err_msg    db      'Cannot load program. ',0
2600
unk_err_msg     db      'Unknown error code -%4X',10,0
2601
aCannotLoadFile db      'Cannot load file. ',0
2602
unk_err_msg2    db      'Unknown error code %4X.',10,0
205 heavyiron 2603
load_err_msgs:
3675 GerdtR 2604
        dd      .1, 0, .3, 0, .5, .6, 0, 0, .9, .A, 0, 0, 0, 0, 0, 0
2605
        dd      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .1E, .1F, .20
2606
.1              db      'HD undefined.',10,0
2607
.3              db      'Unknown FS.',10,0
2608
.5              db      'File not found.',10,0
2609
.6              db      'Unexpected EOF.',10,0
2610
.9              db      'FAT table corrupted.',10,0
2611
.A              db      'Access denied.',10,0
2612
.1E             db      'No memory.',10,0
2613
.1F             db      'Not Menuet/Kolibri executable.',10,0
2614
.20             db      'Too many processes.',10,0
2615
load_succ_msg   db      'Program loaded successfully! PID=%4X. Use "g" to run.',10,0
2616
need_debuggee   db      'No program loaded. Use "load" command.',10,0
2617
aAlreadyLoaded  db      'Program is already loaded. Use "terminate" or "detach" commands',10,0
2618
terminated_msg  db      'Program terminated.',10,0
2619
aException      db      'Debugged program caused an exception %2X. '
2620
aSuspended      db      'Suspended',10,0
2621
aContinued      db      'Continuing',10,0
2622
aRunningErr     db      'Program is running',10,0
2623
read_mem_err    db      'ERROR: cannot read process memory!!!',10,0
205 heavyiron 2624
aBreakpointLimitExceeded db 'Breakpoint limit exceeded',10,0
3675 GerdtR 2625
aBreakErr       db      'Cannot activate breakpoint, it will be disabled',10,0
2626
aDuplicateBreakpoint db 'Duplicate breakpoint',10,0
2627
aInvalidBreak   db      'Invalid breakpoint number',10,0
2628
OnBeErrMsg      db      'There is already enabled breakpoint on this address',10,0
2629
aBreakNum       db      '%2X: at %8X',0
2630
aMemBreak1      db      '%2X: on ',0
2631
aMemBreak2      db      'read from ',0
2632
aMemBreak3      db      'access of ',0
2633
aMemBreak4      db      'byte',0
2634
aMemBreak5      db      'word',0
2635
aMemBreak6      db      'dword',0
2636
aMemBreak7      db      ' at %8X',0
2637
aOneShot        db      ', one-shot',0
2638
aDisabled       db      ', disabled',0
2639
aBreakStop      db      'Breakpoint #%2X',10,0
2640
aUserBreak      db      'int3 command at %8X',10,0
2641
;dbgmsg_str     db      'Debug message for process %4X.',10,0
2642
aInvAddr        db      'Invalid address',10,0
2643
NoPrgLoaded_str db      'No program loaded'
205 heavyiron 2644
NoPrgLoaded_len = $ - NoPrgLoaded_str
3675 GerdtR 2645
aRunning        db      'Running'
2646
aPaused         db      'Paused'
2647
aMain            db        '[ CPU ]'
2648
aSSE            db        '[ SSE ]'
2649
aAVX            db        '[ AVX ]'
2650
aMSR            db        '[ MSR ]'
2651
aPoint          db      0x1C
2652
aMinus          db      '-'
2653
aColon          db      ':'
2654
aSpace          db      ' '
2655
aQuests         db      '??'
2656
aDots           db      '...'
2657
aParseError     db      'Parse error',10,0
2658
aDivByZero      db      'Division by 0',10,0
2659
calc_string     db      '%8X',10,0
2660
aNoMemory       db      'No memory',10,0
2661
aSymbolsLoaded  db      'Symbols loaded',10,0
2662
aUnaligned      db      'Unaligned address',10,0
2663
aEnabledBreakErr db     'Enabled breakpoints are not allowed',10,0
2664
aInterrupted    db      'Interrupted',10,0
2665
aUnpacked       db      'Unpacked successful!',10,0
2666
aPacked1        db      'Program is probably packed with ',0
2667
aPacked2        db      '.',10,'Try to unpack automatically? [y/n]: ',0
2668
aY_str          db      'y',10,0
2669
aN_str          db      'n',10,0
2670
mxp_nrv_name    db      'mxp_nrv',0
2671
mxp_name        db      'mxp',0
2672
mxp_lzo_name    db      'mxp_lzo',0
2673
mtappack_name   db      'mtappack',0
2674
flags           db      'CPAZSDO'
2675
flags_bits      db      0,2,4,6,7,10,11
2676
 
2677
;-----------------------------------------------------------------------------
2678
;                         Registers strings
2679
 
205 heavyiron 2680
regs_strs:
3675 GerdtR 2681
        db      'EAX='
2682
        db      'EBX='
2683
        db      'ECX='
2684
        db      'EDX='
2685
        db      'ESI='
2686
        db      'EDI='
2687
        db      'EBP='
2688
        db      'ESP='
2689
        db      'EIP='
2690
        db      'EFLAGS='
2691
fpu_strs:
2692
        db        'ST0='
2693
        db        'ST1='
2694
        db        'ST2='
2695
        db        'ST3='
2696
        db        'ST4='
2697
        db        'ST5='
2698
        db        'ST6='
2699
        db        'ST7='
2700
mmx_strs:
2701
        db        'MM0='
2702
        db        'MM1='
2703
        db        'MM2='
2704
        db        'MM3='
2705
        db        'MM4='
2706
        db        'MM5='
2707
        db        'MM6='
2708
        db        'MM7='
2709
sse_strs:
2710
        db        '-XMM0-'
2711
        db      '-XMM1-'
2712
        db      '-XMM2-'
2713
        db      '-XMM3-'
2714
        db      '-XMM4-'
2715
        db      '-XMM5-'
2716
        db      '-XMM6-'
2717
        db      '-XMM7-'
2718
avx_strs:
2719
        db      '-YMM0-'
2720
        db      '-YMM1-'
2721
        db      '-YMM2-'
2722
        db      '-YMM3-'
2723
        db      '-YMM4-'
2724
        db      '-YMM5-'
2725
        db      '-YMM6-'
2726
        db      '-YMM7-'
205 heavyiron 2727
 
3675 GerdtR 2728
debuggee_pid    dd      0
2729
bSuspended      db      0
2730
bAfterGo        db      0
2731
temp_break      dd      0
2732
reg_mode        db        1
205 heavyiron 2733
 
3675 GerdtR 2734
include 'disasm_tbl.inc'
205 heavyiron 2735
 
2736
reg_table:
3675 GerdtR 2737
        db      2,'al',0
2738
        db      2,'cl',1
2739
        db      2,'dl',2
2740
        db      2,'bl',3
2741
        db      2,'ah',4
2742
        db      2,'ch',5
2743
        db      2,'dh',6
2744
        db      2,'bh',7
2745
        db      2,'ax',8
2746
        db      2,'cx',9
2747
        db      2,'dx',10
2748
        db      2,'bx',11
2749
        db      2,'sp',12
2750
        db      2,'bp',13
2751
        db      2,'si',14
2752
        db      2,'di',15
2753
        db      3,'eax',16
2754
        db      3,'ecx',17
2755
        db      3,'edx',18
2756
        db      3,'ebx',19
2757
        db      3,'esp',20
2758
        db      3,'ebp',21
2759
        db      3,'esi',22
2760
        db      3,'edi',23
2761
        db      3,'eip',24
2762
        db      0
205 heavyiron 2763
 
542 diamond 2764
IncludeIGlobals
2765
 
2766
fn70_read_block:
3675 GerdtR 2767
        dd      0
2768
        dq      0
2769
        dd      ?
2770
        dd      ?
2771
        db      0
2772
        dd      ?
542 diamond 2773
 
2774
fn70_attr_block:
3675 GerdtR 2775
        dd      5
2776
        dd      0,0,0
2777
        dd      fileattr
2778
        db      0
2779
        dd      ?
542 diamond 2780
 
205 heavyiron 2781
fn70_load_block:
3675 GerdtR 2782
        dd      7
2783
        dd      1
2784
load_params dd  0
2785
        dd      0
2786
        dd      0
205 heavyiron 2787
i_end:
2788
loadname:
3675 GerdtR 2789
        db      0
2790
        rb      255
205 heavyiron 2791
 
3675 GerdtR 2792
symbolsfile     rb      260
542 diamond 2793
 
205 heavyiron 2794
prgname_ptr dd ?
2795
prgname_len dd ?
2796
 
542 diamond 2797
IncludeUGlobals
2798
 
3675 GerdtR 2799
dbgwnd          dd      ?
205 heavyiron 2800
 
3675 GerdtR 2801
messages        rb      messages_height*messages_width
2802
messages_pos    dd      ?
205 heavyiron 2803
 
3675 GerdtR 2804
cmdline         rb      cmdline_width+1
2805
cmdline_len     dd      ?
2806
cmdline_pos     dd      ?
2807
curarg          dd      ?
205 heavyiron 2808
 
3675 GerdtR 2809
cmdline_prev    rb      cmdline_width+1
205 heavyiron 2810
 
3675 GerdtR 2811
was_temp_break  db      ?
205 heavyiron 2812
 
3675 GerdtR 2813
dbgbufsize      dd      ?
2814
dbgbuflen       dd      ?
2815
dbgbuf          rb      256
542 diamond 2816
 
3675 GerdtR 2817
fileattr        rb      40
2818
 
205 heavyiron 2819
needzerostart:
2820
 
2821
context:
2822
 
3675 GerdtR 2823
_eip    dd      ?
2824
_eflags dd      ?
2825
_eax    dd      ?
2826
_ecx    dd      ?
2827
_edx    dd      ?
2828
_ebx    dd      ?
2829
_esp    dd      ?
2830
_ebp    dd      ?
2831
_esi    dd      ?
2832
_edi    dd      ?
205 heavyiron 2833
oldcontext rb $-context
2834
 
3675 GerdtR 2835
mmx_context:
2836
_mm0    dq        ?
2837
_mm1    dq        ?
2838
_mm2    dq        ?
2839
_mm3    dq        ?
2840
_mm4    dq        ?
2841
_mm5    dq        ?
2842
_mm6    dq        ?
2843
_mm7    dq        ?
2844
oldmmxcontext rb $-mmx_context
205 heavyiron 2845
 
3675 GerdtR 2846
fpu_context:
2847
_st0    dq      ?
2848
_st1    dq      ?
2849
_st2    dq      ?
2850
_st3    dq      ?
2851
_st4    dq      ?
2852
_st5    dq      ?
2853
_st6    dq      ?
2854
_st7    dq      ?
2855
oldfpucontext rb $-fpu_context
2856
 
2857
sse_context:
2858
_xmm0    dq        2 dup ?
2859
_xmm1   dq        2 dup ?
2860
_xmm2   dq      2 dup ?
2861
_xmm3   dq      2 dup ?
2862
_xmm4   dq      2 dup ?
2863
_xmm5   dq      2 dup ?
2864
_xmm6   dq      2 dup ?
2865
_xmm7   dq      2 dup ?
2866
oldssecontext rb $-sse_context
2867
 
2868
avx_context:
2869
_ymm0   dq      4 dup ?
2870
_ymm1   dq      4 dup ?
2871
_ymm2   dq      4 dup ?
2872
_ymm3   dq      4 dup ?
2873
_ymm4   dq      4 dup ?
2874
_ymm5   dq      4 dup ?
2875
_ymm6   dq      4 dup ?
2876
_ymm7   dq      4 dup ?
2877
oldavxcontext rb $-avx_context
2878
 
2879
step_num dd 0
2880
proc_num dd 0
2881
dumpread dd     ?
2882
dumppos dd      ?
2883
dumpdata rb     dump_height*10h
2884
 
205 heavyiron 2885
; breakpoint structure:
2886
; dword +0: address
2887
; byte +4: flags
2888
; bit 0: 1 <=> breakpoint valid
2889
; bit 1: 1 <=> breakpoint disabled
2890
; bit 2: 1 <=> one-shot breakpoint
2891
; bit 3: 1 <=> DRx breakpoint
2892
; byte +5: overwritten byte
2893
;          for DRx breaks: flags + (index shl 6)
2894
breakpoints_n = 256
3675 GerdtR 2895
breakpoints     rb      breakpoints_n*6
2896
drx_break       rd      4
205 heavyiron 2897
 
3675 GerdtR 2898
disasm_buf_size         dd      ?
205 heavyiron 2899
 
3675 GerdtR 2900
symbols         dd      ?
2901
num_symbols     dd      ?
542 diamond 2902
 
3675 GerdtR 2903
bReload                 db      ?
205 heavyiron 2904
 
2905
needzeroend:
2906
 
3675 GerdtR 2907
disasm_buffer           rb      256
2908
disasm_start_pos        dd      ?
2909
disasm_cur_pos          dd      ?
2910
disasm_cur_str          dd      ?
2911
disasm_string           rb      256
205 heavyiron 2912
 
3675 GerdtR 2913
i_param         rb      256
205 heavyiron 2914
 
2915
; stack
3675 GerdtR 2916
        align   400h
2917
        rb      400h
205 heavyiron 2918
used_mem:
3675 GerdtR 2919
 
2920
; vim: ft=fasm tabstop=4
2921