Subversion Repositories Kolibri OS

Rev

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

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