Subversion Repositories Kolibri OS

Rev

Rev 6344 | Rev 7677 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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