Subversion Repositories Kolibri OS

Rev

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

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