Subversion Repositories Kolibri OS

Rev

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

Rev 485 Rev 542
1
format binary
1
format binary
2
include '..\..\macros.inc'
2
include '../../macros.inc'
3
use32
3
use32
4
	db	'MENUET01'
4
	db	'MENUET01'
5
	dd	1
5
	dd	1
6
	dd	start
6
	dd	start
7
	dd	i_end
7
	dd	i_end
8
	dd	used_mem
8
	dd	used_mem
9
	dd	used_mem
9
	dd	used_mem
10
	dd	i_param
10
	dd	i_param
11
	dd	0
11
	dd	0
12
 
12
 
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
 
16
 
17
data_width equ 80
17
data_width equ 80
18
data_x_pos equ 12
18
data_x_pos equ 12
19
data_x_size equ data_width*6
19
data_x_size equ data_width*6
20
 
20
 
21
title_x_pos equ 30
21
title_x_pos equ 30
22
title_y_pos equ 32
22
title_y_pos equ 32
23
title_y_size equ 10
23
title_y_size equ 10
24
 
24
 
25
registers_x_pos equ data_x_pos
25
registers_x_pos equ data_x_pos
26
registers_y_pos equ (title_y_pos + title_y_size)
26
registers_y_pos equ (title_y_pos + title_y_size)
27
registers_y_size equ 30
27
registers_y_size equ 30
28
 
28
 
29
dump_y_pos equ (registers_y_pos + registers_y_size + 5)
29
dump_y_pos equ (registers_y_pos + registers_y_size + 5)
30
dump_height equ 4
30
dump_height equ 4
31
dump_y_size equ (dump_height*10)
31
dump_y_size equ (dump_height*10)
32
 
32
 
33
disasm_y_pos equ (dump_y_pos + dump_y_size + 4)
33
disasm_y_pos equ (dump_y_pos + dump_y_size + 4)
34
disasm_height equ 16
34
disasm_height equ 16
35
disasm_y_size equ (disasm_height*10)
35
disasm_y_size equ (disasm_height*10)
36
 
36
 
37
messages_width equ data_width
37
messages_width equ data_width
38
messages_height equ 12
38
messages_height equ 12
39
messages_x_pos equ data_x_pos
39
messages_x_pos equ data_x_pos
40
messages_y_pos equ (disasm_y_pos + disasm_y_size + 4)
40
messages_y_pos equ (disasm_y_pos + disasm_y_size + 4)
41
messages_x_size equ messages_width*6
41
messages_x_size equ messages_width*6
42
messages_y_size equ messages_height*10
42
messages_y_size equ messages_height*10
43
 
43
 
44
cmdline_width equ data_width
44
cmdline_width equ data_width
45
cmdline_x_pos equ data_x_pos
45
cmdline_x_pos equ data_x_pos
46
cmdline_y_pos equ (messages_y_pos + messages_y_size + 10)
46
cmdline_y_pos equ (messages_y_pos + messages_y_size + 10)
47
cmdline_x_size equ messages_x_size
47
cmdline_x_size equ messages_x_size
48
cmdline_y_size equ 10
48
cmdline_y_size equ 10
49
 
49
 
50
wnd_x_size equ (data_x_pos + messages_x_size + data_x_pos)
50
wnd_x_size equ (data_x_pos + messages_x_size + data_x_pos)
51
wnd_y_size equ (cmdline_y_pos + cmdline_y_size + data_x_pos)
51
wnd_y_size equ (cmdline_y_pos + cmdline_y_size + data_x_pos)
52
 
52
 
53
start:
53
start:
-
 
54
	mcall	68, 11
54
	mov	edi, messages
55
	mov	edi, messages
55
	mov	ecx, messages_width*messages_height
56
	mov	ecx, messages_width*messages_height
56
	mov	al, ' '
57
	mov	al, ' '
57
	rep	stosb
58
	rep	stosb
58
	xor	eax, eax
59
	xor	eax, eax
59
	mov	[messages_pos], eax
60
	mov	[messages_pos], eax
60
	mov	[cmdline_len], eax
61
	mov	[cmdline_len], eax
61
	mov	[cmdline_pos], eax
62
	mov	[cmdline_pos], eax
62
	mov	edi, needzerostart
63
	mov	edi, needzerostart
63
	mov	ecx, (needzeroend-needzerostart+3)/4
64
	mov	ecx, (needzeroend-needzerostart+3)/4
64
	rep	stosd
65
	rep	stosd
65
	mov	esi, begin_str
66
	mov	esi, begin_str
66
	call	put_message_nodraw
67
	call	put_message_nodraw
67
; set event mask - default events and debugging events
68
; set event mask - default events and debugging events
68
	push	40
69
	push	40
69
	pop	eax
70
	pop	eax
70
	mov	ebx, 0x107
71
	mov	ebx, 0x107
71
	mcall
72
	mcall
72
; set debug messages buffer
73
; set debug messages buffer
73
	mov	ecx, dbgbufsize
74
	mov	ecx, dbgbufsize
74
	mov	dword [ecx], 256
75
	mov	dword [ecx], 256
75
	xor	ebx, ebx
76
	xor	ebx, ebx
76
	mov	[ecx+4], ebx
77
	mov	[ecx+4], ebx
77
	mov	al, 69
78
	mov	al, 69
78
	mcall
79
	mcall
79
	mov	esi, i_param
80
	mov	esi, i_param
80
	call	skip_spaces
81
	call	skip_spaces
81
	test	al, al
82
	test	al, al
82
	jz	dodraw
83
	jz	dodraw
83
	push	esi
84
	push	esi
84
	call	draw_window
85
	call	draw_window
85
	pop	esi
86
	pop	esi
86
	call	OnLoadInit
87
	call	OnLoadInit
87
	jmp	waitevent
88
	jmp	waitevent
88
dodraw:
89
dodraw:
89
	call	draw_window
90
	call	draw_window
90
waitevent:
91
waitevent:
91
	push	10
92
	push	10
92
	pop	eax
93
	pop	eax
93
	mcall
94
	mcall
94
	cmp	al, 9
95
	cmp	al, 9
95
	jz	debugmsg
96
	jz	debugmsg
96
	dec	eax
97
	dec	eax
97
	jz	dodraw
98
	jz	dodraw
98
	dec	eax
99
	dec	eax
99
	jz	keypressed
100
	jz	keypressed
100
	dec	eax
101
	dec	eax
101
	jnz	waitevent
102
	jnz	waitevent
102
; button pressed - we have only one button (close)
103
; button pressed - we have only one button (close)
103
	push	-1
104
	push	-1
104
	pop	eax
105
	pop	eax
105
	mcall
106
	mcall
106
keypressed:
107
keypressed:
107
	mov	al, 2
108
	mov	al, 2
108
	mcall
109
	mcall
109
	shr	eax, 8
110
	shr	eax, 8
110
	cmp	al, 8
111
	cmp	al, 8
111
	jz	.backspace
112
	jz	.backspace
112
	cmp	al, 0xB0
113
	cmp	al, 0xB0
113
	jz	.left
114
	jz	.left
114
	cmp	al, 0xB3
115
	cmp	al, 0xB3
115
	jz	.right
116
	jz	.right
116
	cmp	al, 0x0D
117
	cmp	al, 0x0D
117
	jz	.enter
118
	jz	.enter
118
	cmp	al, 0xB6
119
	cmp	al, 0xB6
119
	jz	.del
120
	jz	.del
120
	cmp	al, 0xB4
121
	cmp	al, 0xB4
121
	jz	.home
122
	jz	.home
122
	cmp	al, 0xB5
123
	cmp	al, 0xB5
123
	jz	.end
124
	jz	.end
124
	cmp	al, 0xB1
125
	cmp	al, 0xB1
125
	jz	.down
126
	jz	.down
126
	cmp	al, 0xB2
127
	cmp	al, 0xB2
127
	jz	.up
128
	jz	.up
128
	cmp	al, 0xD8
129
	cmp	al, 0xD8
129
	jz	CtrlF7
130
	jz	CtrlF7
130
	cmp	al, 0xD9
131
	cmp	al, 0xD9
131
	jz	CtrlF8
132
	jz	CtrlF8
132
	cmp	[cmdline_len], cmdline_width
133
	cmp	[cmdline_len], cmdline_width
133
	jae	waitevent
134
	jae	waitevent
134
	push	eax
135
	push	eax
135
	call	clear_cmdline_end
136
	call	clear_cmdline_end
136
	pop	eax
137
	pop	eax
137
	mov	edi, cmdline
138
	mov	edi, cmdline
138
	mov	ecx, [cmdline_len]
139
	mov	ecx, [cmdline_len]
139
	add	edi, ecx
140
	add	edi, ecx
140
	lea	esi, [edi-1]
141
	lea	esi, [edi-1]
141
	sub	ecx, [cmdline_pos]
142
	sub	ecx, [cmdline_pos]
142
	std
143
	std
143
	rep	movsb
144
	rep	movsb
144
	cld
145
	cld
145
	stosb
146
	stosb
146
	inc	[cmdline_len]
147
	inc	[cmdline_len]
147
	call	draw_cmdline_end
148
	call	draw_cmdline_end
148
	inc	[cmdline_pos]
149
	inc	[cmdline_pos]
149
	call	draw_cursor
150
	call	draw_cursor
150
	jmp	waitevent
151
	jmp	waitevent
151
.backspace:
152
.backspace:
152
	cmp	[cmdline_pos], 0
153
	cmp	[cmdline_pos], 0
153
	jz	waitevent
154
	jz	waitevent
154
	dec	[cmdline_pos]
155
	dec	[cmdline_pos]
155
.delchar:
156
.delchar:
156
	call	clear_cmdline_end
157
	call	clear_cmdline_end
157
	mov	edi, [cmdline_pos]
158
	mov	edi, [cmdline_pos]
158
	dec	[cmdline_len]
159
	dec	[cmdline_len]
159
	mov	ecx, [cmdline_len]
160
	mov	ecx, [cmdline_len]
160
	sub	ecx, edi
161
	sub	ecx, edi
161
	add	edi, cmdline
162
	add	edi, cmdline
162
	lea	esi, [edi+1]
163
	lea	esi, [edi+1]
163
	rep	movsb
164
	rep	movsb
164
	call	draw_cmdline_end
165
	call	draw_cmdline_end
165
	call	draw_cursor
166
	call	draw_cursor
166
	jmp	waitevent
167
	jmp	waitevent
167
.del:
168
.del:
168
	mov	eax, [cmdline_pos]
169
	mov	eax, [cmdline_pos]
169
	cmp	eax, [cmdline_len]
170
	cmp	eax, [cmdline_len]
170
	jae	waitevent
171
	jae	waitevent
171
	jmp	.delchar
172
	jmp	.delchar
172
.left:
173
.left:
173
	cmp	[cmdline_pos], 0
174
	cmp	[cmdline_pos], 0
174
	jz	waitevent
175
	jz	waitevent
175
	call	hide_cursor
176
	call	hide_cursor
176
	dec	[cmdline_pos]
177
	dec	[cmdline_pos]
177
	call	draw_cursor
178
	call	draw_cursor
178
	jmp	waitevent
179
	jmp	waitevent
179
.right:
180
.right:
180
	mov	eax, [cmdline_pos]
181
	mov	eax, [cmdline_pos]
181
	cmp	eax, [cmdline_len]
182
	cmp	eax, [cmdline_len]
182
	jae	waitevent
183
	jae	waitevent
183
	call	hide_cursor
184
	call	hide_cursor
184
	inc	[cmdline_pos]
185
	inc	[cmdline_pos]
185
	call	draw_cursor
186
	call	draw_cursor
186
	jmp	waitevent
187
	jmp	waitevent
187
.home:
188
.home:
188
	call	hide_cursor
189
	call	hide_cursor
189
	and	[cmdline_pos], 0
190
	and	[cmdline_pos], 0
190
	call	draw_cursor
191
	call	draw_cursor
191
	jmp	waitevent
192
	jmp	waitevent
192
.end:
193
.end:
193
	call	hide_cursor
194
	call	hide_cursor
194
	mov	eax, [cmdline_len]
195
	mov	eax, [cmdline_len]
195
	mov	[cmdline_pos], eax
196
	mov	[cmdline_pos], eax
196
	call	draw_cursor
197
	call	draw_cursor
197
.up:
198
.up:
198
.down:
199
.down:
199
	jmp	waitevent
200
	jmp	waitevent
200
.enter:
201
.enter:
201
	mov	ecx, [cmdline_len]
202
	mov	ecx, [cmdline_len]
202
	test	ecx, ecx
203
	test	ecx, ecx
203
	jz	waitevent
204
	jz	waitevent
204
	mov	esi, cmdline
205
	mov	esi, cmdline
205
	mov	byte [esi+ecx], 0
206
	mov	byte [esi+ecx], 0
206
	and	[cmdline_pos], 0
207
	and	[cmdline_pos], 0
207
	push	esi
208
	push	esi
208
	call	clear_cmdline_end
209
	call	clear_cmdline_end
209
	call	draw_cursor
210
	call	draw_cursor
210
	pop	esi
211
	pop	esi
211
	and	[cmdline_len], 0
212
	and	[cmdline_len], 0
212
; skip leading spaces
213
; skip leading spaces
213
	call	skip_spaces
214
	call	skip_spaces
214
	cmp	al, 0
215
	cmp	al, 0
215
	jz	waitevent
216
	jz	waitevent
216
; now esi points to command
217
; now esi points to command
217
	push	esi
218
	push	esi
218
	mov	esi, prompt
219
	mov	esi, prompt
219
	call	put_message_nodraw
220
	call	put_message_nodraw
220
	pop	esi
221
	pop	esi
221
	push	esi
222
	push	esi
222
	call	put_message_nodraw
223
	call	put_message_nodraw
223
z1:	mov	esi, newline
224
z1:	mov	esi, newline
224
	call	put_message
225
	call	put_message
225
	pop	esi
226
	pop	esi
226
	push	esi
227
	push	esi
227
	call	get_arg
228
	call	get_arg
228
	mov	[curarg], esi
229
	mov	[curarg], esi
229
	pop	edi
230
	pop	edi
230
	mov	esi, commands
231
	mov	esi, commands
231
	call	find_cmd
232
	call	find_cmd
232
	mov	eax, aUnknownCommand
233
	mov	eax, aUnknownCommand
233
	jc	.x11
234
	jc	.x11
234
; check command requirements
235
; check command requirements
235
; flags field:
236
; flags field:
236
; &1: command may be called without parameters
237
; &1: command may be called without parameters
237
; &2: command may be called with parameters
238
; &2: command may be called with parameters
238
; &4: command may be called without loaded program
239
; &4: command may be called without loaded program
239
; &8: command may be called with loaded program
240
; &8: command may be called with loaded program
240
	mov	eax, [esi+8]
241
	mov	eax, [esi+8]
241
	mov	ecx, [curarg]
242
	mov	ecx, [curarg]
242
	cmp	byte [ecx], 0
243
	cmp	byte [ecx], 0
243
	jz	.noargs
244
	jz	.noargs
244
	test	byte [esi+16], 2
245
	test	byte [esi+16], 2
245
	jz	.x11
246
	jz	.x11
246
	jmp	@f
247
	jmp	@f
247
.noargs:
248
.noargs:
248
	test	byte [esi+16], 1
249
	test	byte [esi+16], 1
249
	jz	.x11
250
	jz	.x11
250
@@:
251
@@:
251
	cmp	[debuggee_pid], 0
252
	cmp	[debuggee_pid], 0
252
	jz	.nodebuggee
253
	jz	.nodebuggee
253
	mov	eax, aAlreadyLoaded
254
	mov	eax, aAlreadyLoaded
254
	test	byte [esi+16], 8
255
	test	byte [esi+16], 8
255
	jz	.x11
256
	jz	.x11
256
	jmp	.x9
257
	jmp	.x9
257
.nodebuggee:
258
.nodebuggee:
258
	mov	eax, need_debuggee
259
	mov	eax, need_debuggee
259
	test	byte [esi+16], 4
260
	test	byte [esi+16], 4
260
	jnz	.x9
261
	jnz	.x9
261
.x11:
262
.x11:
262
	xchg	esi, eax
263
	xchg	esi, eax
263
	call	put_message
264
	call	put_message
264
.x10:
265
.x10:
265
	jmp	waitevent
266
	jmp	waitevent
266
.x9:
267
.x9:
267
	call	dword [esi+4]
268
	call	dword [esi+4]
268
	jmp	.x10
269
	jmp	.x10
269
 
270
 
270
find_cmd:
271
find_cmd:
271
; all commands are case-insensitive
272
; all commands are case-insensitive
272
	push	edi
273
	push	edi
273
.x4:
274
.x4:
274
	mov	al, [edi]
275
	mov	al, [edi]
275
	cmp	al, 0
276
	cmp	al, 0
276
	jz	.x5
277
	jz	.x5
277
	cmp	al, 'A'
278
	cmp	al, 'A'
278
	jb	@f
279
	jb	@f
279
	cmp	al, 'Z'
280
	cmp	al, 'Z'
280
	ja	@f
281
	ja	@f
281
	or	al, 20h
282
	or	al, 20h
282
@@:
283
@@:
283
	stosb
284
	stosb
284
	jmp	.x4
285
	jmp	.x4
285
.x5:
286
.x5:
286
; find command
287
; find command
287
	pop	edi
288
	pop	edi
288
.x6:
289
.x6:
289
	cmp	dword [esi], 0
290
	cmp	dword [esi], 0
290
	jz	.x7
291
	jz	.x7
291
	push	esi
292
	push	esi
292
	mov	esi, [esi]
293
	mov	esi, [esi]
293
	lodsb
294
	lodsb
294
	movzx	ecx, al
295
	movzx	ecx, al
295
	push	edi
296
	push	edi
296
	repz	cmpsb
297
	repz	cmpsb
297
	pop	edi
298
	pop	edi
298
	pop	esi
299
	pop	esi
299
	jz	.x8
300
	jz	.x8
300
	add	esi, 17
301
	add	esi, 17
301
	jmp	.x6
302
	jmp	.x6
302
.x7:
303
.x7:
303
	stc
304
	stc
304
.x8:
305
.x8:
305
	ret
306
	ret
306
 
307
 
307
get_arg:
308
get_arg:
308
	lodsb
309
	lodsb
309
	cmp	al, ' '
310
	cmp	al, ' '
310
	ja	get_arg
311
	ja	get_arg
311
	mov	byte [esi-1], 0
312
	mov	byte [esi-1], 0
312
	cmp	al, 0
313
	cmp	al, 0
313
	jnz	skip_spaces
314
	jnz	skip_spaces
314
	dec	esi
315
	dec	esi
315
skip_spaces:
316
skip_spaces:
316
	lodsb
317
	lodsb
317
	cmp	al, 0
318
	cmp	al, 0
318
	jz	@f
319
	jz	@f
319
	cmp	al, ' '
320
	cmp	al, ' '
320
	jbe	skip_spaces
321
	jbe	skip_spaces
321
@@:	dec	esi
322
@@:	dec	esi
322
	ret
323
	ret
323
 
324
 
324
clear_cmdline_end:
325
clear_cmdline_end:
325
	mov	ebx, [cmdline_pos]
326
	mov	ebx, [cmdline_pos]
326
	mov	ecx, [cmdline_len]
327
	mov	ecx, [cmdline_len]
327
	sub	ecx, ebx
328
	sub	ecx, ebx
328
	push	13
329
	push	13
329
	pop	eax
330
	pop	eax
330
	imul	ebx, 6
331
	imul	ebx, 6
331
	imul	ecx, 6
332
	imul	ecx, 6
332
	inc	ecx
333
	inc	ecx
333
	add	ebx, cmdline_x_pos
334
	add	ebx, cmdline_x_pos
334
	shl	ebx, 16
335
	shl	ebx, 16
335
	or	ebx, ecx
336
	or	ebx, ecx
336
	mov	ecx, cmdline_y_pos*10000h + cmdline_y_size
337
	mov	ecx, cmdline_y_pos*10000h + cmdline_y_size
337
	mov	edx, 0xFFFFFF
338
	mov	edx, 0xFFFFFF
338
	mcall
339
	mcall
339
	ret
340
	ret
340
 
341
 
341
draw_cmdline:
342
draw_cmdline:
342
	xor	ebx, ebx
343
	xor	ebx, ebx
343
	jmp	@f
344
	jmp	@f
344
draw_cmdline_end:
345
draw_cmdline_end:
345
	mov	ebx, [cmdline_pos]
346
	mov	ebx, [cmdline_pos]
346
@@:
347
@@:
347
	mov	esi, [cmdline_len]
348
	mov	esi, [cmdline_len]
348
	sub	esi, ebx
349
	sub	esi, ebx
349
	push	4
350
	push	4
350
	pop	eax
351
	pop	eax
351
	xor	ecx, ecx
352
	xor	ecx, ecx
352
	lea	edx, [cmdline+ebx]
353
	lea	edx, [cmdline+ebx]
353
	imul	ebx, 6
354
	imul	ebx, 6
354
	add	ebx, cmdline_x_pos
355
	add	ebx, cmdline_x_pos
355
	shl	ebx, 16
356
	shl	ebx, 16
356
	or	ebx, cmdline_y_pos+1
357
	or	ebx, cmdline_y_pos+1
357
	mcall
358
	mcall
358
	ret
359
	ret
359
 
360
 
360
put_message_nodraw:
361
put_message_nodraw:
361
; in: esi->ASCIZ message
362
; in: esi->ASCIZ message
362
	mov	edx, [messages_pos]
363
	mov	edx, [messages_pos]
363
.m:
364
.m:
364
	lea	edi, [messages+edx]
365
	lea	edi, [messages+edx]
365
.l:
366
.l:
366
	lodsb
367
	lodsb
367
	cmp	al, 0
368
	cmp	al, 0
368
	jz	.done
369
	jz	.done
369
	call	test_scroll
370
	call	test_scroll
370
	cmp	al, 10
371
	cmp	al, 10
371
	jz	.newline
372
	jz	.newline
372
	cmp	al, '%'
373
	cmp	al, '%'
373
	jnz	@f
374
	jnz	@f
374
	cmp	dword [esp], z1
375
	cmp	dword [esp], z1
375
	jnz	.format
376
	jnz	.format
376
@@:
377
@@:
377
	stosb
378
	stosb
378
	inc	edx
379
	inc	edx
379
	jmp	.l
380
	jmp	.l
380
.newline:
381
.newline:
381
	push	edx
382
	push	edx
382
	mov	ecx, messages_width
383
	mov	ecx, messages_width
383
	xor	eax, eax
384
	xor	eax, eax
384
	xchg	eax, edx
385
	xchg	eax, edx
385
	div	ecx
386
	div	ecx
386
	xchg	eax, edx
387
	xchg	eax, edx
387
	pop	edx
388
	pop	edx
388
	test	eax, eax
389
	test	eax, eax
389
	jz	.m
390
	jz	.m
390
	sub	edx, eax
391
	sub	edx, eax
391
	add	edx, ecx
392
	add	edx, ecx
392
	jmp	.m
393
	jmp	.m
393
.done:
394
.done:
394
	mov	[messages_pos], edx
395
	mov	[messages_pos], edx
395
	ret
396
	ret
396
.format:
397
.format:
397
; at moment all format specs must be %X
398
; at moment all format specs must be %X
398
	lodsb	; get 
399
	lodsb	; get 
399
	sub	al, '0'
400
	sub	al, '0'
400
	movzx	ecx, al
401
	movzx	ecx, al
401
	lodsb
402
	lodsb
402
	pop	eax
403
	pop	eax
403
	pop	ebp
404
	pop	ebp
404
	push	eax
405
	push	eax
405
; write number in ebp with ecx digits
406
; write number in ebp with ecx digits
406
	dec	ecx
407
	dec	ecx
407
	shl	ecx, 2
408
	shl	ecx, 2
408
.writenibble:
409
.writenibble:
409
	push	ecx
410
	push	ecx
410
	call	test_scroll
411
	call	test_scroll
411
	pop	ecx
412
	pop	ecx
412
	mov	eax, ebp
413
	mov	eax, ebp
413
	shr	eax, cl
414
	shr	eax, cl
414
	and	al, 0xF
415
	and	al, 0xF
415
	cmp	al, 10
416
	cmp	al, 10
416
	sbb	al, 69h
417
	sbb	al, 69h
417
	das
418
	das
418
	stosb
419
	stosb
419
	inc	edx
420
	inc	edx
420
	sub	ecx, 4
421
	sub	ecx, 4
421
	jns	.writenibble
422
	jns	.writenibble
422
	jmp	.l
423
	jmp	.l
423
 
424
 
424
test_scroll:
425
test_scroll:
425
	cmp	edx, messages_width*messages_height
426
	cmp	edx, messages_width*messages_height
426
	jnz	.ret
427
	jnz	.ret
427
	push	esi
428
	push	esi
428
	mov	edi, messages
429
	mov	edi, messages
429
	lea	esi, [edi+messages_width]
430
	lea	esi, [edi+messages_width]
430
	mov	ecx, (messages_height-1)*messages_width/4
431
	mov	ecx, (messages_height-1)*messages_width/4
431
	rep	movsd
432
	rep	movsd
432
	push	eax
433
	push	eax
433
	mov	al, ' '
434
	mov	al, ' '
434
	push	edi
435
	push	edi
435
	push	messages_width
436
	push	messages_width
436
	pop	ecx
437
	pop	ecx
437
	sub	edx, ecx
438
	sub	edx, ecx
438
	rep	stosb
439
	rep	stosb
439
	pop	edi
440
	pop	edi
440
	pop	eax
441
	pop	eax
441
	pop	esi
442
	pop	esi
442
.ret:	ret
443
.ret:	ret
443
 
444
 
444
put_message:
445
put_message:
445
	call	put_message_nodraw
446
	call	put_message_nodraw
446
 
447
 
447
draw_messages:
448
draw_messages:
448
	push	13
449
	push	13
449
	pop	eax
450
	pop	eax
450
	mov	edx, 0xFFFFFF
451
	mov	edx, 0xFFFFFF
451
	mov	ebx, messages_x_pos*10000h+messages_x_size
452
	mov	ebx, messages_x_pos*10000h+messages_x_size
452
	mov	ecx, messages_y_pos*10000h+messages_y_size
453
	mov	ecx, messages_y_pos*10000h+messages_y_size
453
	mcall
454
	mcall
454
	mov	edx, messages
455
	mov	edx, messages
455
	push	messages_width
456
	push	messages_width
456
	pop	esi
457
	pop	esi
457
	xor	ecx, ecx
458
	xor	ecx, ecx
458
	mov	al, 4
459
	mov	al, 4
459
	mov	ebx, messages_x_pos*10000h+messages_y_pos
460
	mov	ebx, messages_x_pos*10000h+messages_y_pos
460
@@:
461
@@:
461
	mcall
462
	mcall
462
	add	edx, esi
463
	add	edx, esi
463
	add	ebx, 10
464
	add	ebx, 10
464
	cmp	edx, messages+messages_width*messages_height
465
	cmp	edx, messages+messages_width*messages_height
465
	jb	@b
466
	jb	@b
466
	ret
467
	ret
467
 
468
 
468
draw_cursor:
469
draw_cursor:
469
	push	38
470
	push	38
470
	pop	eax
471
	pop	eax
471
	mov	ecx, cmdline_y_pos*10001h+cmdline_y_size-1
472
	mov	ecx, cmdline_y_pos*10001h+cmdline_y_size-1
472
	mov	ebx, [cmdline_pos]
473
	mov	ebx, [cmdline_pos]
473
	imul	ebx, 6
474
	imul	ebx, 6
474
	add	ebx, cmdline_x_pos
475
	add	ebx, cmdline_x_pos
475
	mov	edx, ebx
476
	mov	edx, ebx
476
	shl	ebx, 16
477
	shl	ebx, 16
477
	or	ebx, edx
478
	or	ebx, edx
478
	xor	edx, edx
479
	xor	edx, edx
479
	mcall
480
	mcall
480
	ret
481
	ret
481
hide_cursor:
482
hide_cursor:
482
	mov	ebx, [cmdline_pos]
483
	mov	ebx, [cmdline_pos]
483
	push	13
484
	push	13
484
	pop	eax
485
	pop	eax
485
	imul	ebx, 6
486
	imul	ebx, 6
486
	add	ebx, cmdline_x_pos
487
	add	ebx, cmdline_x_pos
487
	shl	ebx, 16
488
	shl	ebx, 16
488
	inc	ebx
489
	inc	ebx
489
	mov	ecx, cmdline_y_pos*10000h + cmdline_y_size
490
	mov	ecx, cmdline_y_pos*10000h + cmdline_y_size
490
	mov	edx, 0xFFFFFF
491
	mov	edx, 0xFFFFFF
491
	mcall
492
	mcall
492
	mov	ebx, [cmdline_pos]
493
	mov	ebx, [cmdline_pos]
493
	cmp	ebx, [cmdline_len]
494
	cmp	ebx, [cmdline_len]
494
	jae	.ret
495
	jae	.ret
495
	mov	al, 4
496
	mov	al, 4
496
	xor	ecx, ecx
497
	xor	ecx, ecx
497
	lea	edx, [cmdline+ebx]
498
	lea	edx, [cmdline+ebx]
498
	imul	ebx, 6
499
	imul	ebx, 6
499
	add	ebx, cmdline_x_pos
500
	add	ebx, cmdline_x_pos
500
	shl	ebx, 16
501
	shl	ebx, 16
501
	or	ebx, cmdline_y_pos+1
502
	or	ebx, cmdline_y_pos+1
502
	push	1
503
	push	1
503
	pop	esi
504
	pop	esi
504
	mcall
505
	mcall
505
.ret:
506
.ret:
506
	ret
507
	ret
507
 
508
 
508
redraw_title:
509
redraw_title:
509
	push	13
510
	push	13
510
	pop	eax
511
	pop	eax
511
	mov	edx, 0xFFFFFF
512
	mov	edx, 0xFFFFFF
512
	mov	ebx, title_x_pos*10000h + data_x_pos+data_x_size-title_x_pos
513
	mov	ebx, title_x_pos*10000h + data_x_pos+data_x_size-title_x_pos
513
	mov	ecx, title_y_pos*10000h + title_y_size
514
	mov	ecx, title_y_pos*10000h + title_y_size
514
	mcall
515
	mcall
515
draw_title:
516
draw_title:
516
	mov	al, 38
517
	mov	al, 38
517
	mov	ebx, (data_x_pos-2)*10000h + title_x_pos-5
518
	mov	ebx, (data_x_pos-2)*10000h + title_x_pos-5
518
	mov	ecx, (title_y_pos+5)*10001h
519
	mov	ecx, (title_y_pos+5)*10001h
519
	xor	edx, edx
520
	xor	edx, edx
520
	mcall
521
	mcall
521
	push	NoPrgLoaded_len
522
	push	NoPrgLoaded_len
522
	pop	esi
523
	pop	esi
523
	cmp	[debuggee_pid], 0
524
	cmp	[debuggee_pid], 0
524
	jz	@f
525
	jz	@f
525
	mov	esi, [prgname_len]
526
	mov	esi, [prgname_len]
526
@@:	imul	ebx, esi, 6
527
@@:	imul	ebx, esi, 6
527
	add	ebx, title_x_pos+4
528
	add	ebx, title_x_pos+4
528
	shl	ebx, 16
529
	shl	ebx, 16
529
	mov	bx, data_x_pos+data_x_size-10-5-6*7
530
	mov	bx, data_x_pos+data_x_size-10-5-6*7
530
	cmp	[bSuspended], 0
531
	cmp	[bSuspended], 0
531
	jz	@f
532
	jz	@f
532
	add	ebx, 6
533
	add	ebx, 6
533
@@:
534
@@:
534
	mcall
535
	mcall
535
	mov	ebx, (data_x_pos+data_x_size-10+4)*0x10000 + data_x_pos+data_x_size+2
536
	mov	ebx, (data_x_pos+data_x_size-10+4)*0x10000 + data_x_pos+data_x_size+2
536
	mcall
537
	mcall
537
	mov	al, 4
538
	mov	al, 4
538
	mov	ebx, title_x_pos*10000h+title_y_pos
539
	mov	ebx, title_x_pos*10000h+title_y_pos
539
	xor	ecx, ecx
540
	xor	ecx, ecx
540
	mov	edx, NoPrgLoaded_str
541
	mov	edx, NoPrgLoaded_str
541
	cmp	[debuggee_pid], 0
542
	cmp	[debuggee_pid], 0
542
	jz	@f
543
	jz	@f
543
	mov	edx, [prgname_ptr]
544
	mov	edx, [prgname_ptr]
544
@@:
545
@@:
545
	mcall
546
	mcall
546
	cmp	[debuggee_pid], 0
547
	cmp	[debuggee_pid], 0
547
	jz	.nodebuggee
548
	jz	.nodebuggee
548
	mov	ebx, (data_x_pos+data_x_size-10-6*7)*10000h + title_y_pos
549
	mov	ebx, (data_x_pos+data_x_size-10-6*7)*10000h + title_y_pos
549
	mov	edx, aRunning
550
	mov	edx, aRunning
550
	push	7
551
	push	7
551
	pop	esi
552
	pop	esi
552
	cmp	[bSuspended], 0
553
	cmp	[bSuspended], 0
553
	jz	@f
554
	jz	@f
554
	add	ebx, 6*10000h
555
	add	ebx, 6*10000h
555
	mov	edx, aPaused
556
	mov	edx, aPaused
556
	dec	esi
557
	dec	esi
557
@@:
558
@@:
558
	mcall
559
	mcall
559
	ret
560
	ret
560
.nodebuggee:
561
.nodebuggee:
561
	mov	al, 38
562
	mov	al, 38
562
	mov	ebx, (data_x_pos+data_x_size-10-6*7-5)*0x10000 + data_x_pos+data_x_size+2
563
	mov	ebx, (data_x_pos+data_x_size-10-6*7-5)*0x10000 + data_x_pos+data_x_size+2
563
	mov	ecx, (title_y_pos+5)*10001h
564
	mov	ecx, (title_y_pos+5)*10001h
564
	xor	edx, edx
565
	xor	edx, edx
565
	jmp	@b
566
	jmp	@b
566
 
567
 
567
draw_register:
568
draw_register:
568
; in: esi->value, edx->string, ecx=string len, ebx=coord
569
; in: esi->value, edx->string, ecx=string len, ebx=coord
569
	push	edx
570
	push	edx
570
	push	ecx
571
	push	ecx
571
	push	esi
572
	push	esi
572
	mov	eax, esi
573
	mov	eax, esi
573
	mov	esi, ecx
574
	mov	esi, ecx
574
; color
575
; color
575
	mov	ecx, 808080h
576
	mov	ecx, 808080h
576
	cmp	[debuggee_pid], 0
577
	cmp	[debuggee_pid], 0
577
	jz	.cd
578
	jz	.cd
578
	cmp	[bSuspended], 0
579
	cmp	[bSuspended], 0
579
	jz	.cd
580
	jz	.cd
580
	xor	ecx, ecx
581
	xor	ecx, ecx
581
	mov	edi, [eax]
582
	mov	edi, [eax]
582
	cmp	dword [eax+oldcontext-context], edi
583
	cmp	dword [eax+oldcontext-context], edi
583
	jz	.cd
584
	jz	.cd
584
	mov	ecx, 0x00AA00
585
	mov	ecx, 0x00AA00
585
.cd:
586
.cd:
586
	push	4
587
	push	4
587
	pop	eax
588
	pop	eax
588
	mcall
589
	mcall
589
	imul	esi, 60000h
590
	imul	esi, 60000h
590
	lea	edx, [ebx+esi]
591
	lea	edx, [ebx+esi]
591
	mov	al, 47
592
	mov	al, 47
592
	mov	ebx, 80101h
593
	mov	ebx, 80101h
593
	mov	esi, ecx
594
	mov	esi, ecx
594
	pop	ecx
595
	pop	ecx
595
	mcall
596
	mcall
596
	lea	ebx, [edx+60000h*18]
597
	lea	ebx, [edx+60000h*18]
597
	mov	esi, ecx
598
	mov	esi, ecx
598
	pop	ecx
599
	pop	ecx
599
	pop	edx
600
	pop	edx
600
	add	edx, ecx
601
	add	edx, ecx
601
	ret
602
	ret
602
draw_flag:
603
draw_flag:
603
	movzx	edi, byte [edx+7]
604
	movzx	edi, byte [edx+7]
604
	bt	[_eflags], edi
605
	bt	[_eflags], edi
605
	jc	.on
606
	jc	.on
606
	or	byte [edx], 20h
607
	or	byte [edx], 20h
607
	jmp	.onoff
608
	jmp	.onoff
608
.on:
609
.on:
609
	and	byte [edx], not 20h
610
	and	byte [edx], not 20h
610
.onoff:
611
.onoff:
611
	mov	ecx, 808080h
612
	mov	ecx, 808080h
612
	cmp	[debuggee_pid], 0
613
	cmp	[debuggee_pid], 0
613
	jz	.doit
614
	jz	.doit
614
	cmp	[bSuspended], 0
615
	cmp	[bSuspended], 0
615
	jz	.doit
616
	jz	.doit
616
	xor	ecx, ecx
617
	xor	ecx, ecx
617
	bt	[_eflags], edi
618
	bt	[_eflags], edi
618
	lahf
619
	lahf
619
	bt	dword [_eflags + oldcontext - context], edi
620
	bt	dword [_eflags + oldcontext - context], edi
620
	rcl	ah, 1
621
	rcl	ah, 1
621
	test	ah, 3
622
	test	ah, 3
622
	jp	.doit
623
	jp	.doit
623
	mov	ecx, 0x00AA00
624
	mov	ecx, 0x00AA00
624
.doit:
625
.doit:
625
	mov	ah, 0
626
	mov	ah, 0
626
	mcall
627
	mcall
627
	ret
628
	ret
628
 
629
 
629
redraw_registers:
630
redraw_registers:
630
	push	13
631
	push	13
631
	pop	eax
632
	pop	eax
632
	mov	edx, 0xFFFFFF
633
	mov	edx, 0xFFFFFF
633
	mov	ebx, data_x_pos*10000h + data_x_size
634
	mov	ebx, data_x_pos*10000h + data_x_size
634
	mov	ecx, registers_y_pos*10000h + registers_y_size
635
	mov	ecx, registers_y_pos*10000h + registers_y_size
635
	mcall
636
	mcall
636
draw_registers:
637
draw_registers:
637
	mov	esi, _eax
638
	mov	esi, _eax
638
	push	4
639
	push	4
639
	pop	ecx
640
	pop	ecx
640
	mov	edx, regs_strs
641
	mov	edx, regs_strs
641
	mov	ebx, registers_x_pos*10000h+registers_y_pos
642
	mov	ebx, registers_x_pos*10000h+registers_y_pos
642
	call	draw_register
643
	call	draw_register
643
	add	esi, _ebx-_eax
644
	add	esi, _ebx-_eax
644
	call	draw_register
645
	call	draw_register
645
	add	esi, _ecx-_ebx
646
	add	esi, _ecx-_ebx
646
	call	draw_register
647
	call	draw_register
647
	add	esi, _edx-_ecx
648
	add	esi, _edx-_ecx
648
	call	draw_register
649
	call	draw_register
649
	mov	ebx, registers_x_pos*10000h+registers_y_pos+10
650
	mov	ebx, registers_x_pos*10000h+registers_y_pos+10
650
	add	esi, _esi-_edx
651
	add	esi, _esi-_edx
651
	call	draw_register
652
	call	draw_register
652
	add	esi, _edi-_esi
653
	add	esi, _edi-_esi
653
	call	draw_register
654
	call	draw_register
654
	add	esi, _ebp-_edi
655
	add	esi, _ebp-_edi
655
	call	draw_register
656
	call	draw_register
656
	add	esi, _esp-_ebp
657
	add	esi, _esp-_ebp
657
	call	draw_register
658
	call	draw_register
658
	mov	ebx, registers_x_pos*10000h+registers_y_pos+20
659
	mov	ebx, registers_x_pos*10000h+registers_y_pos+20
659
	add	esi, _eip-_esp
660
	add	esi, _eip-_esp
660
	call	draw_register
661
	call	draw_register
661
	mov	cl, 7
662
	mov	cl, 7
662
	add	esi, _eflags-_eip
663
	add	esi, _eflags-_eip
663
	call	draw_register
664
	call	draw_register
664
	mov	al, 4
665
	mov	al, 4
665
	mov	ecx, 808080h
666
	mov	ecx, 808080h
666
	cmp	[debuggee_pid], 0
667
	cmp	[debuggee_pid], 0
667
	jz	@f
668
	jz	@f
668
	cmp	[bSuspended], 0
669
	cmp	[bSuspended], 0
669
	jz	@f
670
	jz	@f
670
	xor	ecx, ecx
671
	xor	ecx, ecx
671
@@:
672
@@:
672
	mov	edx, aColon
673
	mov	edx, aColon
673
	xor	esi, esi
674
	xor	esi, esi
674
	inc	esi
675
	inc	esi
675
	mov	ebx, (registers_x_pos+37*6)*10000h + registers_y_pos+20
676
	mov	ebx, (registers_x_pos+37*6)*10000h + registers_y_pos+20
676
	mcall
677
	mcall
677
	mov	edx, flags
678
	mov	edx, flags
678
@@:
679
@@:
679
	add	ebx, 2*6*10000h
680
	add	ebx, 2*6*10000h
680
	call	draw_flag
681
	call	draw_flag
681
	inc	edx
682
	inc	edx
682
	cmp	dl, flags_bits and 0xFF
683
	cmp	dl, flags_bits and 0xFF
683
	jnz	@b
684
	jnz	@b
684
	ret
685
	ret
685
 
686
 
686
redraw_dump:
687
redraw_dump:
687
	push	13
688
	push	13
688
	pop	eax
689
	pop	eax
689
	mov	edx, 0xFFFFFF
690
	mov	edx, 0xFFFFFF
690
	mov	ebx, data_x_pos*10000h + data_x_size
691
	mov	ebx, data_x_pos*10000h + data_x_size
691
	mov	ecx, dump_y_pos*10000h + dump_y_size
692
	mov	ecx, dump_y_pos*10000h + dump_y_size
692
	mcall
693
	mcall
693
draw_dump:
694
draw_dump:
694
; addresses
695
; addresses
695
	mov	al, 47
696
	mov	al, 47
696
	mov	ebx, 80100h
697
	mov	ebx, 80100h
697
	mov	edx, data_x_pos*10000h + dump_y_pos
698
	mov	edx, data_x_pos*10000h + dump_y_pos
698
	mov	ecx, [dumppos]
699
	mov	ecx, [dumppos]
699
	mov	esi, 808080h
700
	mov	esi, 808080h
700
	cmp	[debuggee_pid], 0
701
	cmp	[debuggee_pid], 0
701
	jz	@f
702
	jz	@f
702
	cmp	[bSuspended], 0
703
	cmp	[bSuspended], 0
703
	jz	@f
704
	jz	@f
704
	xor	esi, esi
705
	xor	esi, esi
705
@@:
706
@@:
706
	mcall
707
	mcall
707
	add	ecx, 10h
708
	add	ecx, 10h
708
	add	edx, 10
709
	add	edx, 10
709
	cmp	dl, dump_y_pos + dump_y_size
710
	cmp	dl, dump_y_pos + dump_y_size
710
	jb	@b
711
	jb	@b
711
; hex dump of data
712
; hex dump of data
712
	mov	ebx, 20101h
713
	mov	ebx, 20101h
713
	mov	ecx, dumpdata
714
	mov	ecx, dumpdata
714
	push	ecx
715
	push	ecx
715
	xor	edi, edi
716
	xor	edi, edi
716
	mov	edx, (data_x_pos+12*6)*10000h + dump_y_pos
717
	mov	edx, (data_x_pos+12*6)*10000h + dump_y_pos
717
	cmp	[dumpread], edi
718
	cmp	[dumpread], edi
718
	jz	.hexdumpdone1
719
	jz	.hexdumpdone1
719
.hexdumploop1:
720
.hexdumploop1:
720
	mcall
721
	mcall
721
	add	edx, 3*6*10000h
722
	add	edx, 3*6*10000h
722
	inc	ecx
723
	inc	ecx
723
	inc	edi
724
	inc	edi
724
	test	edi, 15
725
	test	edi, 15
725
	jz	.16
726
	jz	.16
726
	test	edi, 7
727
	test	edi, 7
727
	jnz	@f
728
	jnz	@f
728
	add	edx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
729
	add	edx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
729
.16:
730
.16:
730
	add	edx, 10 - 6*(3*10h+2)*10000h
731
	add	edx, 10 - 6*(3*10h+2)*10000h
731
@@:
732
@@:
732
	cmp	edi, [dumpread]
733
	cmp	edi, [dumpread]
733
	jb	.hexdumploop1
734
	jb	.hexdumploop1
734
.hexdumpdone1:
735
.hexdumpdone1:
735
	mov	al, 4
736
	mov	al, 4
736
	mov	ecx, esi
737
	mov	ecx, esi
737
	mov	ebx, edx
738
	mov	ebx, edx
738
	push	2
739
	push	2
739
	pop	esi
740
	pop	esi
740
	mov	edx, aQuests
741
	mov	edx, aQuests
741
.hexdumploop2:
742
.hexdumploop2:
742
	cmp	edi, dump_height*10h
743
	cmp	edi, dump_height*10h
743
	jae	.hexdumpdone2
744
	jae	.hexdumpdone2
744
	mcall
745
	mcall
745
	add	ebx, 3*6*10000h
746
	add	ebx, 3*6*10000h
746
	inc	edi
747
	inc	edi
747
	test	edi, 15
748
	test	edi, 15
748
	jz	.16x
749
	jz	.16x
749
	test	edi, 7
750
	test	edi, 7
750
	jnz	.hexdumploop2
751
	jnz	.hexdumploop2
751
	add	ebx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
752
	add	ebx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
752
.16x:
753
.16x:
753
	add	ebx, 10 - 6*(3*10h+2)*10000h
754
	add	ebx, 10 - 6*(3*10h+2)*10000h
754
	jmp	.hexdumploop2
755
	jmp	.hexdumploop2
755
.hexdumpdone2:
756
.hexdumpdone2:
756
	dec	esi
757
	dec	esi
757
; colon, minus signs
758
; colon, minus signs
758
	mov	ebx, (data_x_pos+8*6)*10000h + dump_y_pos
759
	mov	ebx, (data_x_pos+8*6)*10000h + dump_y_pos
759
	mov	edx, aColon
760
	mov	edx, aColon
760
@@:
761
@@:
761
	mcall
762
	mcall
762
	add	ebx, 10
763
	add	ebx, 10
763
	cmp	bl, dump_y_pos+dump_height*10
764
	cmp	bl, dump_y_pos+dump_height*10
764
	jb	@b
765
	jb	@b
765
	mov	ebx, (data_x_pos+(12+3*8)*6)*10000h + dump_y_pos
766
	mov	ebx, (data_x_pos+(12+3*8)*6)*10000h + dump_y_pos
766
	mov	edx, aMinus
767
	mov	edx, aMinus
767
@@:
768
@@:
768
	mcall
769
	mcall
769
	add	ebx, 10
770
	add	ebx, 10
770
	cmp	bl, dump_y_pos+dump_height*10
771
	cmp	bl, dump_y_pos+dump_height*10
771
	jb	@b
772
	jb	@b
772
; ASCII data
773
; ASCII data
773
	mov	ebx, (data_x_pos+(12+3*10h+2+2)*6)*10000h + dump_y_pos
774
	mov	ebx, (data_x_pos+(12+3*10h+2+2)*6)*10000h + dump_y_pos
774
	mov	edi, dump_height*10h
775
	mov	edi, dump_height*10h
775
	pop	edx
776
	pop	edx
776
.asciiloop:
777
.asciiloop:
777
	push	edx
778
	push	edx
778
	cmp	byte [edx], 20h
779
	cmp	byte [edx], 20h
779
	jae	@f
780
	jae	@f
780
	mov	edx, aPoint
781
	mov	edx, aPoint
781
@@:
782
@@:
782
	mcall
783
	mcall
783
	pop	edx
784
	pop	edx
784
	inc	edx
785
	inc	edx
785
	add	ebx, 6*10000h
786
	add	ebx, 6*10000h
786
	dec	edi
787
	dec	edi
787
	jz	.asciidone
788
	jz	.asciidone
788
	test	edi, 15
789
	test	edi, 15
789
	jnz	.asciiloop
790
	jnz	.asciiloop
790
	add	ebx, 10 - 6*10h*10000h
791
	add	ebx, 10 - 6*10h*10000h
791
	jmp	.asciiloop
792
	jmp	.asciiloop
792
.asciidone:
793
.asciidone:
793
	ret
794
	ret
794
 
795
 
795
redraw_disasm:
796
redraw_disasm:
796
	push	13
797
	push	13
797
	pop	eax
798
	pop	eax
798
	mov	edx, 0xFFFFFF
799
	mov	edx, 0xFFFFFF
799
	mov	ebx, data_x_pos*10000h + data_x_size
800
	mov	ebx, data_x_pos*10000h + data_x_size
800
	mov	ecx, (disasm_y_pos-1)*10000h + (disasm_y_size+1)
801
	mov	ecx, (disasm_y_pos-1)*10000h + (disasm_y_size+1)
801
	mcall
802
	mcall
802
draw_disasm:
803
draw_disasm:
803
	mov	eax, [disasm_start_pos]
804
	mov	eax, [disasm_start_pos]
804
	mov	[disasm_cur_pos], eax
805
	mov	[disasm_cur_pos], eax
805
	and	[disasm_cur_str], 0
806
	and	[disasm_cur_str], 0
806
.loop:
807
.loop:
-
 
808
	mov	eax, [disasm_cur_pos]
-
 
809
	call	find_symbol
-
 
810
	jc	.nosymb
-
 
811
	mov	ebx, [disasm_cur_str]
-
 
812
	imul	ebx, 10
-
 
813
	add	ebx, (data_x_pos+6*2)*10000h + disasm_y_pos
-
 
814
	mov	edx, esi
-
 
815
@@:	lodsb
-
 
816
	test	al, al
-
 
817
	jnz	@b
-
 
818
	mov	byte [esi-1], ':'
-
 
819
	sub	esi, edx
-
 
820
	xor	ecx, ecx
-
 
821
	push	4
-
 
822
	pop	eax
-
 
823
	mcall
-
 
824
	mov	byte [esi+edx-1], 0
-
 
825
	inc	[disasm_cur_str]
-
 
826
	cmp	[disasm_cur_str], disasm_height
-
 
827
	jae	.loopend
-
 
828
.nosymb:
807
	push	[disasm_cur_pos]
829
	push	[disasm_cur_pos]
808
	call	disasm_instr
830
	call	disasm_instr
809
	pop	ebp
831
	pop	ebp
810
	jc	.loopend
832
	jc	.loopend
811
	xor	esi, esi	; default color: black
833
	xor	esi, esi	; default color: black
812
	mov	ebx, data_x_pos*10000h + data_x_size
834
	mov	ebx, data_x_pos*10000h + data_x_size
813
	mov	ecx, [disasm_cur_str]
835
	mov	ecx, [disasm_cur_str]
814
	imul	ecx, 10*10000h
836
	imul	ecx, 10*10000h
815
	add	ecx, (disasm_y_pos-1)*10000h + 10
837
	add	ecx, (disasm_y_pos-1)*10000h + 10
816
	mov	eax, ebp
838
	mov	eax, ebp
817
	pushad
839
	pushad
818
	call	find_enabled_breakpoint
840
	call	find_enabled_breakpoint
819
	popad
841
	popad
820
	jnz	.nored
842
	jnz	.nored
821
	push	13
843
	push	13
822
	pop	eax
844
	pop	eax
823
	mov	edx, 0xFF0000
845
	mov	edx, 0xFF0000
824
	mcall
846
	mcall
825
.nored:
847
.nored:
826
	mov	eax, [_eip]
848
	mov	eax, [_eip]
827
	cmp	eax, ebp
849
	cmp	eax, ebp
828
	jnz	.noblue
850
	jnz	.noblue
829
	push	13
851
	push	13
830
	pop	eax
852
	pop	eax
831
	mov	edx, 0x0000FF
853
	mov	edx, 0x0000FF
832
	mcall
854
	mcall
833
	mov	esi, 0xFFFFFF	; on blue bgr, use white color
855
	mov	esi, 0xFFFFFF	; on blue bgr, use white color
834
.noblue:
856
.noblue:
835
	push	47
857
	push	47
836
	pop	eax
858
	pop	eax
837
	mov	ebx, 80100h
859
	mov	ebx, 80100h
838
	mov	edx, [disasm_cur_str]
860
	mov	edx, [disasm_cur_str]
839
	imul	edx, 10
861
	imul	edx, 10
840
	add	edx, data_x_pos*10000h + disasm_y_pos
862
	add	edx, data_x_pos*10000h + disasm_y_pos
841
	mov	ecx, ebp
863
	mov	ecx, ebp
842
	mcall
864
	mcall
843
	mov	al, 4
865
	mov	al, 4
844
	lea	ebx, [edx+8*6*10000h]
866
	lea	ebx, [edx+8*6*10000h]
845
	mov	ecx, esi
867
	mov	ecx, esi
846
	push	1
868
	push	1
847
	pop	esi
869
	pop	esi
848
	mov	edx, aColon
870
	mov	edx, aColon
849
	mcall
871
	mcall
850
	push	9
872
	push	9
851
	pop	edi
873
	pop	edi
852
	lea	edx, [ebx+2*6*10000h]
874
	lea	edx, [ebx+2*6*10000h]
853
	mov	esi, ecx
875
	mov	esi, ecx
854
	mov	al, 47
876
	mov	al, 47
855
	mov	ebx, 20101h
877
	mov	ebx, 20101h
856
	mov	ecx, ebp
878
	mov	ecx, ebp
857
	sub	ecx, [disasm_start_pos]
879
	sub	ecx, [disasm_start_pos]
858
	add	ecx, disasm_buffer
880
	add	ecx, disasm_buffer
859
.drawhex:
881
.drawhex:
860
	mcall
882
	mcall
861
	add	edx, 6*3*10000h
883
	add	edx, 6*3*10000h
862
	inc	ecx
884
	inc	ecx
863
	inc	ebp
885
	inc	ebp
864
	cmp	ebp, [disasm_cur_pos]
886
	cmp	ebp, [disasm_cur_pos]
865
	jae	.hexdone
887
	jae	.hexdone
866
	dec	edi
888
	dec	edi
867
	jnz	.drawhex
889
	jnz	.drawhex
868
	push	esi
890
	push	esi
869
	mov	esi, [disasm_cur_pos]
891
	mov	esi, [disasm_cur_pos]
870
	dec	esi
892
	dec	esi
871
	cmp	esi, ebp
893
	cmp	esi, ebp
872
	pop	esi
894
	pop	esi
873
	jbe	.drawhex
895
	jbe	.drawhex
874
	mov	al, 4
896
	mov	al, 4
875
	lea	ebx, [edx-6*10000h]
897
	lea	ebx, [edx-6*10000h]
876
	mov	ecx, esi
898
	mov	ecx, esi
877
	push	3
899
	push	3
878
	pop	esi
900
	pop	esi
879
	mov	edx, aDots
901
	mov	edx, aDots
880
	mcall
902
	mcall
881
	mov	esi, ecx
903
	mov	esi, ecx
882
.hexdone:
904
.hexdone:
883
	xor	eax, eax
905
	xor	eax, eax
884
	mov	edi, disasm_string
906
	mov	edi, disasm_string
885
	mov	edx, edi
907
	mov	edx, edi
886
	or	ecx, -1
908
	or	ecx, -1
887
	repnz	scasb
909
	repnz	scasb
888
	not	ecx
910
	not	ecx
889
	dec	ecx
911
	dec	ecx
890
	xchg	ecx, esi
912
	xchg	ecx, esi
891
	mov	ebx, [disasm_cur_str]
913
	mov	ebx, [disasm_cur_str]
892
	imul	ebx, 10
914
	imul	ebx, 10
893
	add	ebx, (data_x_pos+6*40)*10000h+disasm_y_pos
915
	add	ebx, (data_x_pos+6*40)*10000h+disasm_y_pos
894
	mov	al, 4
916
	mov	al, 4
895
	mcall
917
	mcall
896
	inc	[disasm_cur_str]
918
	inc	[disasm_cur_str]
897
	cmp	[disasm_cur_str], disasm_height
919
	cmp	[disasm_cur_str], disasm_height
898
	jb	.loop
920
	jb	.loop
899
.loopend:
921
.loopend:
900
	ret
922
	ret
901
 
923
 
902
update_disasm_eip:
924
update_disasm_eip:
903
; test if instruction at eip is showed
925
; test if instruction at eip is showed
904
	mov	ecx, disasm_height
926
	mov	ecx, disasm_height
905
	mov	eax, [disasm_start_pos]
927
	mov	eax, [disasm_start_pos]
906
	mov	[disasm_cur_pos], eax
928
	mov	[disasm_cur_pos], eax
-
 
929
.l:
-
 
930
	mov	eax, [disasm_cur_pos]
-
 
931
	call	find_symbol
-
 
932
	jc	@f
-
 
933
	dec	ecx
-
 
934
	jz	.m
907
@@:
935
@@:
908
	mov	eax, [_eip]
-
 
909
	cmp	[disasm_cur_pos], eax
936
	cmp	[_eip], eax
910
	jz	redraw_disasm
937
	jz	redraw_disasm
911
	push	ecx
938
	push	ecx
912
	call	disasm_instr
939
	call	disasm_instr
913
	pop	ecx
940
	pop	ecx
914
	jc	@f
941
	jc	.m
915
	loop	@b
942
	loop	.l
916
@@:
943
.m:
917
update_disasm_eip_force:
944
update_disasm_eip_force:
918
	mov	eax, [_eip]
945
	mov	eax, [_eip]
919
	mov	[disasm_start_pos], eax
946
	mov	[disasm_start_pos], eax
920
update_disasm:
947
update_disasm:
921
	cmp	[debuggee_pid], 0
948
	cmp	[debuggee_pid], 0
922
	jz	.no
949
	jz	.no
923
	push	69
950
	push	69
924
	pop	eax
951
	pop	eax
925
	push	6
952
	push	6
926
	pop	ebx
953
	pop	ebx
927
	mov	ecx, [debuggee_pid]
954
	mov	ecx, [debuggee_pid]
928
	mov	edi, disasm_buffer
955
	mov	edi, disasm_buffer
929
	mov	edx, 256
956
	mov	edx, 256
930
	mov	esi, [disasm_start_pos]
957
	mov	esi, [disasm_start_pos]
931
	mcall
958
	mcall
932
	cmp	eax, -1
959
	cmp	eax, -1
933
	jnz	@f
960
	jnz	@f
934
	mov	esi, read_mem_err
961
	mov	esi, read_mem_err
935
	call	put_message
962
	call	put_message
936
.no:
963
.no:
937
	xor	eax, eax
964
	xor	eax, eax
938
@@:
965
@@:
939
	mov	[disasm_buf_size], eax
966
	mov	[disasm_buf_size], eax
940
	call	restore_from_breaks
967
	call	restore_from_breaks
941
	jmp	redraw_disasm
968
	jmp	redraw_disasm
942
 
969
 
943
draw_window:
970
draw_window:
944
; start redraw
971
; start redraw
945
	push	12
972
	push	12
946
	pop	eax
973
	pop	eax
947
	push	1
974
	push	1
948
	pop	ebx
975
	pop	ebx
949
	mcall
976
	mcall
950
; define window
977
; define window
951
	xor	eax, eax
978
	xor	eax, eax
952
	mov	ebx, wnd_x_size
979
	mov	ebx, wnd_x_size
953
	mov	ecx, wnd_y_size
980
	mov	ecx, wnd_y_size
954
	mov	edx, 3FFFFFFh
981
	mov	edx, 13FFFFFFh
955
	mcall
-
 
956
; caption
-
 
957
	mov	al, 4
-
 
958
	mov	ecx, 0xFFFFFF
-
 
959
	mov	ebx, 80008h
-
 
960
	mov	edx, caption_str
982
	mov	edi, caption_str
961
	push	caption_len
-
 
962
	pop	esi
-
 
963
	mcall
983
	mcall
964
; messages frame
984
; messages frame
965
	mov	al, 38
985
	mov	al, 38
966
	mov	ebx, (messages_x_pos-2)*10000h + (messages_x_pos+messages_x_size+2)
986
	mov	ebx, (messages_x_pos-2)*10000h + (messages_x_pos+messages_x_size+2)
967
	push	ebx
987
	push	ebx
968
	mov	ecx, (messages_y_pos-2)*10001h
988
	mov	ecx, (messages_y_pos-2)*10001h
969
	xor	edx, edx
989
	xor	edx, edx
970
	mcall
990
	mcall
971
	mov	ecx, (messages_y_pos+messages_y_size+2)*10001h
991
	mov	ecx, (messages_y_pos+messages_y_size+2)*10001h
972
	mcall
992
	mcall
973
	mov	ebx, (messages_x_pos-2)*10001h
993
	mov	ebx, (messages_x_pos-2)*10001h
974
	push	ebx
994
	push	ebx
975
	mov	ecx, (messages_y_pos-2)*10000h + (messages_y_pos+messages_y_size+2)
995
	mov	ecx, (messages_y_pos-2)*10000h + (messages_y_pos+messages_y_size+2)
976
	mcall
996
	mcall
977
	mov	ebx, (messages_x_pos+messages_x_size+2)*10001h
997
	mov	ebx, (messages_x_pos+messages_x_size+2)*10001h
978
	push	ebx
998
	push	ebx
979
	mcall
999
	mcall
980
; command line frame
1000
; command line frame
981
	mov	ecx, (cmdline_y_pos-2)*10000h + (cmdline_y_pos+cmdline_y_size+2)
1001
	mov	ecx, (cmdline_y_pos-2)*10000h + (cmdline_y_pos+cmdline_y_size+2)
982
	pop	ebx
1002
	pop	ebx
983
	mcall
1003
	mcall
984
	pop	ebx
1004
	pop	ebx
985
	mcall
1005
	mcall
986
	pop	ebx
1006
	pop	ebx
987
	mov	ecx, (cmdline_y_pos+cmdline_y_size+2)*10001h
1007
	mov	ecx, (cmdline_y_pos+cmdline_y_size+2)*10001h
988
	mcall
1008
	mcall
989
	mov	ecx, (cmdline_y_pos-2)*10001h
1009
	mov	ecx, (cmdline_y_pos-2)*10001h
990
	mcall
1010
	mcall
991
; messages
1011
; messages
992
	call	draw_messages
1012
	call	draw_messages
993
; command line & cursor
1013
; command line & cursor
994
	call	draw_cmdline
1014
	call	draw_cmdline
995
	call	draw_cursor
1015
	call	draw_cursor
996
; title & registers & dump & disasm
1016
; title & registers & dump & disasm
997
	mov	al, 38
1017
	mov	al, 38
998
	mov	ebx, (data_x_pos-2)*10001h
1018
	mov	ebx, (data_x_pos-2)*10001h
999
	mov	ecx, (title_y_pos+5)*10000h + (messages_y_pos-2)
1019
	mov	ecx, (title_y_pos+5)*10000h + (messages_y_pos-2)
1000
	mcall
1020
	mcall
1001
	mov	ebx, (data_x_pos+data_x_size+2)*10001h
1021
	mov	ebx, (data_x_pos+data_x_size+2)*10001h
1002
	mcall
1022
	mcall
1003
	mov	ebx, (data_x_pos-2)*10000h + (data_x_pos+data_x_size+2)
1023
	mov	ebx, (data_x_pos-2)*10000h + (data_x_pos+data_x_size+2)
1004
	mov	ecx, (dump_y_pos-3)*10001h
1024
	mov	ecx, (dump_y_pos-3)*10001h
1005
	mcall
1025
	mcall
1006
	mov	ecx, (disasm_y_pos-4)*10001h
1026
	mov	ecx, (disasm_y_pos-4)*10001h
1007
	mcall
1027
	mcall
1008
	call	draw_title
1028
	call	draw_title
1009
	call	draw_registers
1029
	call	draw_registers
1010
	call	draw_dump
1030
	call	draw_dump
1011
	call	draw_disasm
1031
	call	draw_disasm
1012
; end redraw
1032
; end redraw
1013
	mov	al, 12
1033
	mov	al, 12
1014
	push	2
1034
	push	2
1015
	pop	ebx
1035
	pop	ebx
1016
	mcall
1036
	mcall
1017
	ret
1037
	ret
1018
 
1038
 
1019
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1039
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1020
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEBUGGING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1040
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEBUGGING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1021
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1041
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1022
 
1042
 
1023
OnHelp:
1043
OnHelp:
1024
	mov	esi, help_msg
1044
	mov	esi, help_msg
1025
	mov	edi, [curarg]
1045
	mov	edi, [curarg]
1026
	cmp	byte [edi], 0
1046
	cmp	byte [edi], 0
1027
	jz	.x
1047
	jz	.x
1028
	mov	esi, help_groups
1048
	mov	esi, help_groups
1029
	call	find_cmd
1049
	call	find_cmd
1030
	jc	.nocmd
1050
	jc	.nocmd
1031
	mov	esi, [esi+12]
1051
	mov	esi, [esi+12]
1032
.x:
1052
.x:
1033
	jmp	put_message
1053
	jmp	put_message
1034
.nocmd:
1054
.nocmd:
1035
	mov	esi, aUnknownCommand
1055
	mov	esi, aUnknownCommand
1036
	jmp	.x
1056
	jmp	.x
1037
 
1057
 
1038
OnQuit:
1058
OnQuit:
1039
	xor	eax, eax
1059
	push	-1
1040
	dec	eax
1060
	pop	eax
1041
	mcall
1061
	mcall
1042
 
1062
 
1043
get_new_context:
1063
get_new_context:
1044
	mov	esi, context
1064
	mov	esi, context
1045
	mov	edi, oldcontext
1065
	mov	edi, oldcontext
1046
	mov	ecx, 10
1066
	mov	ecx, 10
1047
	rep	movsd
1067
	rep	movsd
1048
get_context:
1068
get_context:
1049
	push	1
1069
	push	1
1050
	pop	ebx
1070
	pop	ebx
1051
	push	69
1071
	push	69
1052
	pop	eax
1072
	pop	eax
1053
	mov	ecx, [debuggee_pid]
1073
	mov	ecx, [debuggee_pid]
1054
	mov	esi, context
1074
	mov	esi, context
1055
	push	28h
1075
	push	28h
1056
	pop	edx
1076
	pop	edx
1057
	mcall
1077
	mcall
1058
	ret
1078
	ret
1059
set_context:
1079
set_context:
1060
	push	2
1080
	push	2
1061
	pop	ebx
1081
	pop	ebx
1062
	push	69
1082
	push	69
1063
	pop	eax
1083
	pop	eax
1064
	mov	ecx, [debuggee_pid]
1084
	mov	ecx, [debuggee_pid]
1065
	mov	esi, context
1085
	mov	esi, context
1066
	push	28h
1086
	push	28h
1067
	pop	edx
1087
	pop	edx
1068
	mcall
1088
	mcall
1069
	ret
1089
	ret
1070
 
1090
 
1071
get_dump:
1091
get_dump:
1072
	mov	edi, dumpdata
1092
	mov	edi, dumpdata
1073
	mov	esi, [edi-4]
1093
	mov	esi, [edi-4]
1074
	mov	edx, dump_height*10h
1094
	mov	edx, dump_height*10h
1075
	mov	ecx, edx
1095
	mov	ecx, edx
1076
	xor	eax, eax
1096
	xor	eax, eax
1077
	push	edi
1097
	push	edi
1078
	rep	stosb
1098
	rep	stosb
1079
	pop	edi
1099
	pop	edi
1080
	mov	ecx, [debuggee_pid]
1100
	mov	ecx, [debuggee_pid]
1081
	mov	al, 69
1101
	mov	al, 69
1082
	push	6
1102
	push	6
1083
	pop	ebx
1103
	pop	ebx
1084
	mcall
1104
	mcall
1085
	cmp	eax, -1
1105
	cmp	eax, -1
1086
	jnz	@f
1106
	jnz	@f
1087
	mov	esi, read_mem_err
1107
	mov	esi, read_mem_err
1088
	call	put_message
1108
	call	put_message
1089
	xor	eax, eax
1109
	xor	eax, eax
1090
@@:
1110
@@:
1091
	mov	[edi-8], eax
1111
	mov	[edi-8], eax
1092
;	call	restore_from_breaks
1112
;	call	restore_from_breaks
1093
;	ret
1113
;	ret
1094
restore_from_breaks:
1114
restore_from_breaks:
1095
; in: edi=buffer,eax=size,esi=address
1115
; in: edi=buffer,eax=size,esi=address
1096
	mov	ebx, breakpoints
1116
	mov	ebx, breakpoints
1097
@@:
1117
@@:
1098
	test	byte [ebx+4], 1
1118
	test	byte [ebx+4], 1
1099
	jz	.cont		; ignore invalid
1119
	jz	.cont		; ignore invalid
1100
	test	byte [ebx+4], 2 or 8
1120
	test	byte [ebx+4], 2 or 8
1101
	jnz	.cont		; ignore disabled and memory breaks
1121
	jnz	.cont		; ignore disabled and memory breaks
1102
	mov	ecx, [ebx]
1122
	mov	ecx, [ebx]
1103
	sub	ecx, esi
1123
	sub	ecx, esi
1104
	cmp	ecx, eax
1124
	cmp	ecx, eax
1105
	jae	.cont
1125
	jae	.cont
1106
	mov	dl, [ebx+5]
1126
	mov	dl, [ebx+5]
1107
	mov	[edi+ecx], dl
1127
	mov	[edi+ecx], dl
1108
.cont:
1128
.cont:
1109
	add	ebx, 6
1129
	add	ebx, 6
1110
	cmp	ebx, breakpoints+breakpoints_n*6
1130
	cmp	ebx, breakpoints+breakpoints_n*6
1111
	jb	@b
1131
	jb	@b
1112
	ret
1132
	ret
1113
 
1133
 
1114
OnLoad:
1134
OnLoad:
1115
	mov	esi, [curarg]
1135
	mov	esi, [curarg]
1116
OnLoadInit:
1136
OnLoadInit:
1117
	mov	edi, loadname
1137
	mov	edi, loadname
1118
	or	[prgname_len], -1
1138
	or	[prgname_len], -1
1119
	mov	[prgname_ptr], edi
1139
	mov	[prgname_ptr], edi
1120
.copyname:
1140
.copyname:
1121
	lodsb
1141
	lodsb
1122
	stosb
1142
	stosb
1123
	inc	[prgname_len]
1143
	inc	[prgname_len]
1124
	cmp	al, '/'
1144
	cmp	al, '/'
1125
	jnz	@f
1145
	jnz	@f
1126
	or	[prgname_len], -1
1146
	or	[prgname_len], -1
1127
	mov	[prgname_ptr], edi
1147
	mov	[prgname_ptr], edi
1128
@@:
1148
@@:
1129
	cmp	al, ' '
1149
	cmp	al, ' '
1130
	ja	.copyname
1150
	ja	.copyname
1131
	mov	byte [edi-1], 0
1151
	mov	byte [edi-1], 0
1132
	and	[load_params], 0
1152
	and	[load_params], 0
1133
	dec	esi
1153
	dec	esi
1134
	call	skip_spaces
1154
	call	skip_spaces
1135
	cmp	al, 0
1155
	cmp	al, 0
1136
	jz	@f
1156
	jz	@f
1137
	mov	[load_params], esi
1157
	mov	[load_params], esi
1138
@@:
1158
@@:
1139
	and	[dumppos], 0
1159
	and	[dumppos], 0
-
 
1160
	mov	ecx, [symbols]
-
 
1161
	jecxz	do_reload
-
 
1162
	mcall	68, 13
-
 
1163
	and	[symbols], 0
-
 
1164
	and	[num_symbols], 0
1140
do_reload:
1165
do_reload:
1141
	push	18
1166
	push	18
1142
	pop	eax
1167
	pop	eax
1143
	push	7
1168
	push	7
1144
	pop	ebx
1169
	pop	ebx
1145
	mcall
1170
	mcall
1146
	mov	[dbgwnd], eax
1171
	mov	[dbgwnd], eax
1147
	xchg	ecx, eax
1172
	xchg	ecx, eax
1148
	push	70
1173
	push	70
1149
	pop	eax
1174
	pop	eax
1150
	mov	ebx, fn70_load_block
1175
	mov	ebx, fn70_load_block
1151
	mcall
1176
	mcall
1152
	test	eax, eax
1177
	test	eax, eax
1153
	jns	.load_ok
1178
	jns	.load_ok
1154
.load_err:
1179
.load_err:
1155
	push	eax
1180
	push	eax
1156
	mov	esi, load_err_msg
1181
	mov	esi, load_err_msg
1157
	call	put_message
1182
	call	put_message
1158
	pop	eax
1183
	pop	eax
1159
	not	eax
1184
	not	eax
1160
	cmp	eax, 0x20
1185
	cmp	eax, 0x20
1161
	jae	.unk_err
1186
	jae	.unk_err
1162
	mov	esi, [load_err_msgs+eax*4]
1187
	mov	esi, [load_err_msgs+eax*4]
1163
	test	esi, esi
1188
	test	esi, esi
1164
	jnz	put_message
1189
	jnz	put_message
1165
.unk_err:
1190
.unk_err:
1166
	mov	esi, unk_err_msg
1191
	mov	esi, unk_err_msg
1167
	inc	eax
1192
	inc	eax
1168
	push	eax
1193
	push	eax
1169
	call	put_message_nodraw
1194
	call	put_message_nodraw
1170
	jmp	draw_messages
1195
	jmp	draw_messages
1171
.load_ok:
1196
.load_ok:
1172
	mov	[debuggee_pid], eax
1197
	mov	[debuggee_pid], eax
1173
	mov	[bSuspended], 1
1198
	mov	[bSuspended], 1
1174
	push	ecx
1199
	push	ecx
1175
	call	get_context
1200
	call	get_context
1176
	mov	edi, oldcontext
1201
	mov	edi, oldcontext
1177
	mov	ecx, 10
1202
	mov	ecx, 10
1178
	rep	movsd
1203
	rep	movsd
1179
; activate debugger window
1204
; activate debugger window
1180
	pop	ecx
1205
	pop	ecx
1181
	mov	bl, 3
1206
	mov	bl, 3
1182
	push	18
1207
	push	18
1183
	pop	eax
1208
	pop	eax
1184
	mcall
1209
	mcall
1185
	call	redraw_title
1210
	call	redraw_title
1186
	call	redraw_registers
1211
	call	redraw_registers
1187
	call	get_dump
1212
	call	get_dump
1188
	call	redraw_dump
1213
	call	redraw_dump
1189
	call	update_disasm_eip_force
1214
	call	update_disasm_eip_force
1190
	mov	esi, load_succ_msg
1215
	mov	esi, load_succ_msg
1191
	push	[debuggee_pid]
1216
	push	[debuggee_pid]
1192
	call	put_message_nodraw
1217
	call	put_message_nodraw
1193
	call	draw_messages
1218
	call	draw_messages
-
 
1219
; try to load symbols
-
 
1220
	mov	esi, loadname
-
 
1221
	mov	edi, symbolsfile
-
 
1222
	push	edi
-
 
1223
@@:
-
 
1224
	lodsb
-
 
1225
	stosb
-
 
1226
	test	al, al
-
 
1227
	jnz	@b
-
 
1228
	lea	ecx, [edi-1]
-
 
1229
@@:
-
 
1230
	dec	edi
-
 
1231
	cmp	edi, symbolsfile
-
 
1232
	jb	@f
-
 
1233
	cmp	byte [edi], '/'
-
 
1234
	jz	@f
-
 
1235
	cmp	byte [edi], '.'
-
 
1236
	jnz	@b
-
 
1237
	mov	ecx, edi
-
 
1238
@@:
-
 
1239
	mov	dword [ecx], '.dbg'
-
 
1240
	mov	byte [ecx+4], 0
-
 
1241
	pop	esi
-
 
1242
	mov	ebp, esi
-
 
1243
	call	OnLoadSymbols.silent
1194
; now test for packed progs
1244
; now test for packed progs
1195
	cmp	[disasm_buf_size], 100h
1245
	cmp	[disasm_buf_size], 100h
1196
	jz	@f
1246
	jz	@f
1197
	ret
1247
	ret
1198
@@:
1248
@@:
1199
	mov	esi, mxp_nrv_sig
1249
	mov	esi, mxp_nrv_sig
1200
	mov	ebp, disasm_buffer
1250
	mov	ebp, disasm_buffer
1201
	mov	edi, ebp
1251
	mov	edi, ebp
1202
	push	3
1252
	push	3
1203
	pop	ecx
1253
	pop	ecx
1204
	repz	cmpsb
1254
	repz	cmpsb
1205
	jnz	.not_mxp_nrv
1255
	jnz	.not_mxp_nrv
1206
	cmpsb
1256
	cmpsb
1207
	mov	cl, mxp_nrv_sig_size-4
1257
	mov	cl, mxp_nrv_sig_size-4
1208
	repz	cmpsb
1258
	repz	cmpsb
1209
	mov	esi, mxp_nrv_name
1259
	mov	esi, mxp_nrv_name
1210
	jz	.packed
1260
	jz	.packed
1211
.not_mxp_nrv:
1261
.not_mxp_nrv:
1212
	mov	esi, mxp_sig
1262
	mov	esi, mxp_sig
1213
	mov	edi, ebp
1263
	mov	edi, ebp
1214
	mov	cl, mxp_sig_size
1264
	mov	cl, mxp_sig_size
1215
	repz	cmpsb
1265
	repz	cmpsb
1216
	mov	esi, mxp_name
1266
	mov	esi, mxp_name
1217
	jz	.packed
1267
	jz	.packed
1218
.not_mxp:
1268
.not_mxp:
1219
	mov	esi, mxp_lzo_sig1
1269
	mov	esi, mxp_lzo_sig1
1220
	mov	edi, ebp
1270
	mov	edi, ebp
1221
	mov	cl, mxp_lzo_sig1_size
1271
	mov	cl, mxp_lzo_sig1_size
1222
	repz	cmpsb
1272
	repz	cmpsb
1223
	mov	esi, mxp_lzo_name
1273
	mov	esi, mxp_lzo_name
1224
	jz	.packed
1274
	jz	.packed
1225
	mov	esi, mxp_lzo_sig2
1275
	mov	esi, mxp_lzo_sig2
1226
	mov	edi, ebp
1276
	mov	edi, ebp
1227
	mov	cl, 8
1277
	mov	cl, 8
1228
	repz	cmpsb
1278
	repz	cmpsb
1229
	jnz	.not_mxp_lzo
1279
	jnz	.not_mxp_lzo
1230
	cmpsb
1280
	cmpsb
1231
	mov	cl, mxp_lzo_sig2_size - 9
1281
	mov	cl, mxp_lzo_sig2_size - 9
1232
	repz	cmpsb
1282
	repz	cmpsb
1233
	mov	esi, mxp_lzo_name
1283
	mov	esi, mxp_lzo_name
1234
	jz	.packed
1284
	jz	.packed
1235
.not_mxp_lzo:
1285
.not_mxp_lzo:
1236
	mov	esi, mtappack_name
1286
	mov	esi, mtappack_name
1237
	cmp	dword [ebp], 0xBF5E246A
1287
	cmp	dword [ebp], 0xBF5E246A
1238
	jnz	.not_mtappack
1288
	jnz	.not_mtappack
1239
	cmp	dword [ebp+8], 0xEC4E8B57
1289
	cmp	dword [ebp+8], 0xEC4E8B57
1240
	jnz	.not_mtappack1
1290
	jnz	.not_mtappack1
1241
	cmp	dword [ebp+12], 0x8D5EA4F3
1291
	cmp	dword [ebp+12], 0x8D5EA4F3
1242
	jnz	.not_mtappack1
1292
	jnz	.not_mtappack1
1243
	cmp	byte [ebp+12h], 0xE9
1293
	cmp	byte [ebp+12h], 0xE9
1244
	jz	.packed
1294
	jz	.packed
1245
.not_mtappack1:
1295
.not_mtappack1:
1246
	cmp	word [ebp+8], 0xB957
1296
	cmp	word [ebp+8], 0xB957
1247
	jnz	.not_mtappack
1297
	jnz	.not_mtappack
1248
	cmp	dword [ebp+14], 0x575EA4F3
1298
	cmp	dword [ebp+14], 0x575EA4F3
1249
	jnz	.not_mtappack2
1299
	jnz	.not_mtappack2
1250
	cmp	byte [ebp+17h], 0xE9
1300
	cmp	byte [ebp+17h], 0xE9
1251
	jz	.packed
1301
	jz	.packed
1252
.not_mtappack2:
1302
.not_mtappack2:
1253
	cmp	dword [ebp+14], 0x5F8DA4F3
1303
	cmp	dword [ebp+14], 0x5F8DA4F3
1254
	jnz	.not_mtappack3
1304
	jnz	.not_mtappack3
1255
	cmp	word [ebp+18], 0xE9FC
1305
	cmp	word [ebp+18], 0xE9FC
1256
	jz	.packed
1306
	jz	.packed
1257
.not_mtappack3:
1307
.not_mtappack3:
1258
	cmp	word [ebp+14], 0xA4F3
1308
	cmp	word [ebp+14], 0xA4F3
1259
	jnz	.not_mtappack
1309
	jnz	.not_mtappack
1260
	cmp	byte [ebp+15h], 0xE9
1310
	cmp	byte [ebp+15h], 0xE9
1261
	jz	.packed
1311
	jz	.packed
1262
.not_mtappack:
1312
.not_mtappack:
1263
	ret
1313
	ret
1264
.packed:
1314
.packed:
1265
	push	esi
1315
	push	esi
1266
	mov	esi, aPacked1
1316
	mov	esi, aPacked1
1267
	call	put_message_nodraw
1317
	call	put_message_nodraw
1268
	pop	esi
1318
	pop	esi
1269
	call	put_message_nodraw
1319
	call	put_message_nodraw
1270
	mov	esi, aPacked2
1320
	mov	esi, aPacked2
1271
	call	put_message
1321
	call	put_message
1272
	call	hide_cursor
1322
	call	hide_cursor
1273
	push	40
1323
	push	40
1274
	pop	eax
1324
	pop	eax
1275
	push	7
1325
	push	7
1276
	pop	ebx
1326
	pop	ebx
1277
	mcall
1327
	mcall
1278
.wait:
1328
.wait:
1279
	push	10
1329
	push	10
1280
	pop	eax
1330
	pop	eax
1281
	mcall
1331
	mcall
1282
	dec	eax
1332
	dec	eax
1283
	jz	.redraw
1333
	jz	.redraw
1284
	dec	eax
1334
	dec	eax
1285
	jz	.key
1335
	jz	.key
1286
	or	eax, -1
1336
	or	eax, -1
1287
	mcall
1337
	mcall
1288
.redraw:
1338
.redraw:
1289
	call	draw_window
1339
	call	draw_window
1290
	call	hide_cursor
1340
	call	hide_cursor
1291
	jmp	.wait
1341
	jmp	.wait
1292
.key:
1342
.key:
1293
	mov	al, 2
1343
	mov	al, 2
1294
	mcall
1344
	mcall
1295
	cmp	ah, 'y'
1345
	cmp	ah, 'y'
1296
	jz	.yes
1346
	jz	.yes
1297
	cmp	ah, 'Y'
1347
	cmp	ah, 'Y'
1298
	jz	.yes
1348
	jz	.yes
1299
	cmp	ah, 0xD
1349
	cmp	ah, 0xD
1300
	jz	.yes
1350
	jz	.yes
1301
	cmp	ah, 'n'
1351
	cmp	ah, 'n'
1302
	jz	.no
1352
	jz	.no
1303
	cmp	ah, 'N'
1353
	cmp	ah, 'N'
1304
	jnz	.wait
1354
	jnz	.wait
1305
.no:
1355
.no:
1306
	push	40
1356
	push	40
1307
	pop	eax
1357
	pop	eax
1308
	mov	ebx, 0x107
1358
	mov	ebx, 0x107
1309
	mcall
1359
	mcall
1310
	call	draw_cursor
1360
	call	draw_cursor
1311
	mov	esi, aN_str
1361
	mov	esi, aN_str
1312
	jmp	put_message
1362
	jmp	put_message
1313
.yes:
1363
.yes:
1314
	push	40
1364
	push	40
1315
	pop	eax
1365
	pop	eax
1316
	mov	ebx, 0x107
1366
	mov	ebx, 0x107
1317
	mcall
1367
	mcall
1318
	call	draw_cursor
1368
	call	draw_cursor
1319
	mov	esi, aY_str
1369
	mov	esi, aY_str
1320
	call	put_message
1370
	call	put_message
1321
	call	OnUnpack
1371
	call	OnUnpack
1322
	ret
1372
	ret
1323
 
1373
 
1324
mxp_nrv_sig:
1374
mxp_nrv_sig:
1325
	xor	eax, eax
1375
	xor	eax, eax
1326
	mov	ecx, 0x95	; 0xA1 for programs with parameters
1376
	mov	ecx, 0x95	; 0xA1 for programs with parameters
1327
	mov	[eax], ecx
1377
	mov	[eax], ecx
1328
	add	ecx, [eax+24h]
1378
	add	ecx, [eax+24h]
1329
	push	40h
1379
	push	40h
1330
	pop	esi
1380
	pop	esi
1331
	mov	edi, [eax+20h]
1381
	mov	edi, [eax+20h]
1332
	push	edi
1382
	push	edi
1333
	rep	movsb
1383
	rep	movsb
1334
	jmp	dword [esp]
1384
	jmp	dword [esp]
1335
	pop	esi
1385
	pop	esi
1336
	add	esi, [eax]
1386
	add	esi, [eax]
1337
	xor	edi, edi
1387
	xor	edi, edi
1338
mxp_nrv_sig_size = $ - mxp_nrv_sig
1388
mxp_nrv_sig_size = $ - mxp_nrv_sig
1339
 
1389
 
1340
mxp_sig:
1390
mxp_sig:
1341
	mov	ecx, 1CBh
1391
	mov	ecx, 1CBh
1342
	push	46h
1392
	push	46h
1343
	pop	esi
1393
	pop	esi
1344
	mov	edi, [20h]
1394
	mov	edi, [20h]
1345
	rep	movsb
1395
	rep	movsb
1346
	mov	ecx, [24h]
1396
	mov	ecx, [24h]
1347
	rep	movsb
1397
	rep	movsb
1348
	jmp	dword [20h]
1398
	jmp	dword [20h]
1349
	mov	eax, [20h]
1399
	mov	eax, [20h]
1350
	add	eax, 1CBh
1400
	add	eax, 1CBh
1351
	push	eax
1401
	push	eax
1352
	push	dword [24h]
1402
	push	dword [24h]
1353
	push	0
1403
	push	0
1354
	push	8
1404
	push	8
1355
	call	$+0x25
1405
	call	$+0x25
1356
mxp_sig_size = $ - mxp_sig
1406
mxp_sig_size = $ - mxp_sig
1357
 
1407
 
1358
mxp_lzo_sig1:
1408
mxp_lzo_sig1:
1359
	xor	eax, eax
1409
	xor	eax, eax
1360
	mov	ebp, 0FFh
1410
	mov	ebp, 0FFh
1361
	mov	ecx, 175h
1411
	mov	ecx, 175h
1362
	mov	[eax], ecx
1412
	mov	[eax], ecx
1363
	add	ecx, [eax+24h]
1413
	add	ecx, [eax+24h]
1364
	push	45h
1414
	push	45h
1365
	pop	esi
1415
	pop	esi
1366
	mov	edi, [eax+20h]
1416
	mov	edi, [eax+20h]
1367
	push	edi
1417
	push	edi
1368
	rep	movsb
1418
	rep	movsb
1369
	jmp	dword [esp]
1419
	jmp	dword [esp]
1370
	pop	ebx
1420
	pop	ebx
1371
	add	ebx, [eax]
1421
	add	ebx, [eax]
1372
	xor	edi, edi
1422
	xor	edi, edi
1373
	cmp	byte [ebx], 11h
1423
	cmp	byte [ebx], 11h
1374
	jbe	$+0x1A
1424
	jbe	$+0x1A
1375
mxp_lzo_sig1_size = $ - mxp_lzo_sig1
1425
mxp_lzo_sig1_size = $ - mxp_lzo_sig1
1376
mxp_lzo_sig2:
1426
mxp_lzo_sig2:
1377
	xor	eax, eax
1427
	xor	eax, eax
1378
	mov	ebp, 0FFh
1428
	mov	ebp, 0FFh
1379
	mov	ecx, 188h	; or 177h
1429
	mov	ecx, 188h	; or 177h
1380
	mov	[eax], ecx
1430
	mov	[eax], ecx
1381
	add	ecx, [eax+24h]
1431
	add	ecx, [eax+24h]
1382
	push	44h
1432
	push	44h
1383
	pop	esi
1433
	pop	esi
1384
	mov	edi, [eax+20h]
1434
	mov	edi, [eax+20h]
1385
	rep	movsb
1435
	rep	movsb
1386
	jmp	dword [eax+20h]
1436
	jmp	dword [eax+20h]
1387
	mov	ebx, [eax+20h]
1437
	mov	ebx, [eax+20h]
1388
	add	ebx, [eax]
1438
	add	ebx, [eax]
1389
mxp_lzo_sig2_size = $ - mxp_lzo_sig2
1439
mxp_lzo_sig2_size = $ - mxp_lzo_sig2
1390
 
1440
 
1391
OnReload:
1441
OnReload:
1392
	cmp	[debuggee_pid], 0
1442
	cmp	[debuggee_pid], 0
1393
	jnz	terminate_reload
1443
	jnz	terminate_reload
1394
	mov	esi, need_debuggee
1444
	mov	esi, need_debuggee
1395
	cmp	byte [loadname], 0
1445
	cmp	byte [loadname], 0
1396
	jnz	do_reload
1446
	jnz	do_reload
1397
	jz	put_message
1447
	jz	put_message
1398
terminate_reload:
1448
terminate_reload:
1399
	mov	[bReload], 1
1449
	mov	[bReload], 1
1400
OnTerminate:
1450
OnTerminate:
1401
	mov	ecx, [debuggee_pid]
1451
	mov	ecx, [debuggee_pid]
1402
	push	8
1452
	push	8
1403
	pop	ebx
1453
	pop	ebx
1404
	push	69
1454
	push	69
1405
	pop	eax
1455
	pop	eax
1406
	mcall
1456
	mcall
1407
	ret
1457
	ret
1408
 
1458
 
1409
AfterSuspend:
1459
AfterSuspend:
1410
	mov	[bSuspended], 1
1460
	mov	[bSuspended], 1
1411
	call	get_new_context
1461
	call	get_new_context
1412
	call	get_dump
1462
	call	get_dump
1413
	call	redraw_title
1463
	call	redraw_title
1414
	call	redraw_registers
1464
	call	redraw_registers
1415
	call	redraw_dump
1465
	call	redraw_dump
1416
	call	update_disasm_eip
1466
	call	update_disasm_eip
1417
	ret
1467
	ret
1418
 
1468
 
1419
OnSuspend:
1469
OnSuspend:
1420
	mov	ecx, [debuggee_pid]
1470
	mov	ecx, [debuggee_pid]
1421
	push	4
1471
	push	4
1422
	pop	ebx
1472
	pop	ebx
1423
	push	69
1473
	push	69
1424
	pop	eax
1474
	pop	eax
1425
	mcall
1475
	mcall
1426
	call	AfterSuspend
1476
	call	AfterSuspend
1427
	mov	esi, aSuspended
1477
	mov	esi, aSuspended
1428
	jmp	put_message
1478
	jmp	put_message
1429
DoResume:
1479
DoResume:
1430
	mov	ecx, [debuggee_pid]
1480
	mov	ecx, [debuggee_pid]
1431
	push	5
1481
	push	5
1432
	pop	ebx
1482
	pop	ebx
1433
	push	69
1483
	push	69
1434
	pop	eax
1484
	pop	eax
1435
	mcall
1485
	mcall
1436
	mov	[bSuspended], 0
1486
	mov	[bSuspended], 0
1437
	ret
1487
	ret
1438
OnResume:
1488
OnResume:
1439
	mov	esi, [curarg]
1489
	mov	esi, [curarg]
1440
	cmp	byte [esi], 0
1490
	cmp	byte [esi], 0
1441
	jz	GoOn
1491
	jz	GoOn
1442
	call	calc_expression
1492
	call	calc_expression
1443
	jc	.ret
1493
	jc	.ret
1444
	mov	eax, ebp
1494
	mov	eax, ebp
1445
	push	eax
1495
	push	eax
1446
	call	find_enabled_breakpoint
1496
	call	find_enabled_breakpoint
1447
	pop	eax
1497
	pop	eax
1448
	jz	GoOn
1498
	jz	GoOn
1449
	mov	bl, 5	; valid enabled one-shot
1499
	mov	bl, 5	; valid enabled one-shot
1450
	call	add_breakpoint
1500
	call	add_breakpoint
1451
	jnc	GoOn
1501
	jnc	GoOn
1452
	mov	esi, aBreakpointLimitExceeded
1502
	mov	esi, aBreakpointLimitExceeded
1453
	call	put_message
1503
	call	put_message
1454
.ret:
1504
.ret:
1455
	ret
1505
	ret
1456
GoOn:
1506
GoOn:
1457
; test for enabled breakpoint at eip
1507
; test for enabled breakpoint at eip
1458
	mov	eax, [_eip]
1508
	mov	eax, [_eip]
1459
	call	find_enabled_breakpoint
1509
	call	find_enabled_breakpoint
1460
	jnz	.nobreak
1510
	jnz	.nobreak
1461
; temporarily disable breakpoint, make step, enable breakpoint, continue
1511
; temporarily disable breakpoint, make step, enable breakpoint, continue
1462
	inc	eax
1512
	inc	eax
1463
	mov	[temp_break], eax
1513
	mov	[temp_break], eax
1464
	mov	[bAfterGo], 1
1514
	mov	[bAfterGo], 1
1465
	dec	eax
1515
	dec	eax
1466
	call	disable_breakpoint
1516
	call	disable_breakpoint
1467
	call	get_context
1517
	call	get_context
1468
	or	byte [_eflags+1], 1		; set TF
1518
	or	byte [_eflags+1], 1		; set TF
1469
	call	set_context
1519
	call	set_context
1470
	and	byte [_eflags+1], not 1
1520
	and	byte [_eflags+1], not 1
1471
	call	DoResume
1521
	call	DoResume
1472
	ret
1522
	ret
1473
.nobreak:
1523
.nobreak:
1474
	call	DoResume
1524
	call	DoResume
1475
	call	redraw_title
1525
	call	redraw_title
1476
	call	redraw_registers
1526
	call	redraw_registers
1477
	call	redraw_dump
1527
	call	redraw_dump
1478
	ret
1528
	ret
1479
OnDetach:
1529
OnDetach:
1480
	mov	ecx, [debuggee_pid]
1530
	mov	ecx, [debuggee_pid]
1481
	push	3
1531
	push	3
1482
	pop	ebx
1532
	pop	ebx
1483
	push	69
1533
	push	69
1484
	pop	eax
1534
	pop	eax
1485
	mcall
1535
	mcall
1486
	and	[debuggee_pid], 0
1536
	and	[debuggee_pid], 0
1487
	call	redraw_title
1537
	call	redraw_title
1488
	call	redraw_registers
1538
	call	redraw_registers
1489
	call	redraw_dump
1539
	call	redraw_dump
-
 
1540
	call	free_symbols
1490
	mov	esi, aContinued
1541
	mov	esi, aContinued
1491
	jmp	put_message
1542
	jmp	put_message
1492
 
1543
 
1493
after_go_exception:
1544
after_go_exception:
1494
	push	eax
1545
	push	eax
1495
	mov	eax, [temp_break]
1546
	mov	eax, [temp_break]
1496
	dec	eax
1547
	dec	eax
1497
	push	esi
1548
	push	esi
1498
	call	enable_breakpoint
1549
	call	enable_breakpoint
1499
; in any case, clear TF and RF
1550
; in any case, clear TF and RF
1500
	call	get_new_context
1551
	call	get_new_context
1501
	and	[_eflags], not 10100h		; clear TF,RF
1552
	and	[_eflags], not 10100h		; clear TF,RF
1502
	call	set_context
1553
	call	set_context
1503
	xor	edx, edx
1554
	xor	edx, edx
1504
	mov	[temp_break], edx
1555
	mov	[temp_break], edx
1505
	xchg	dl, [bAfterGo]
1556
	xchg	dl, [bAfterGo]
1506
	pop	esi
1557
	pop	esi
1507
	pop	eax
1558
	pop	eax
1508
	cmp	dl, 2
1559
	cmp	dl, 2
1509
	jnz	@f
1560
	jnz	@f
1510
	lodsd
1561
	lodsd
1511
	push	esi
1562
	push	esi
1512
	call	get_dump
1563
	call	get_dump
1513
	jmp	exception.done
1564
	jmp	exception.done
1514
@@:	test	eax, eax
1565
@@:	test	eax, eax
1515
	jz	.notint1
1566
	jz	.notint1
1516
; if exception is result of single step, simply ignore it and continue
1567
; if exception is result of single step, simply ignore it and continue
1517
	test	dword [esi], 0xF
1568
	test	dword [esi], 0xF
1518
	jnz	dbgmsgstart.5
1569
	jnz	dbgmsgstart.5
1519
	lodsd
1570
	lodsd
1520
	push	esi
1571
	push	esi
1521
	mov	esi, oldcontext
1572
	mov	esi, oldcontext
1522
	mov	edi, context
1573
	mov	edi, context
1523
	mov	ecx, 28h/4
1574
	mov	ecx, 28h/4
1524
	rep	movsd
1575
	rep	movsd
1525
	call	DoResume
1576
	call	DoResume
1526
	jmp	dbgmsgend
1577
	jmp	dbgmsgend
1527
.notint1:
1578
.notint1:
1528
; in other case, work as without temp_break
1579
; in other case, work as without temp_break
1529
	lodsd
1580
	lodsd
1530
	push	esi
1581
	push	esi
1531
	push	eax
1582
	push	eax
1532
	jmp	exception.4
1583
	jmp	exception.4
1533
.notour:
1584
.notour:
1534
 
1585
 
1535
debugmsg:
1586
debugmsg:
1536
	neg	[dbgbufsize]
1587
	neg	[dbgbufsize]
1537
	mov	esi, dbgbuf
1588
	mov	esi, dbgbuf
1538
dbgmsgstart:
1589
dbgmsgstart:
1539
	lodsd
1590
	lodsd
1540
;	push	eax esi
1591
;	push	eax esi
1541
;	push	dword [esi]
1592
;	push	dword [esi]
1542
;	mov	esi, dbgmsg_str
1593
;	mov	esi, dbgmsg_str
1543
;	call	put_message_nodraw
1594
;	call	put_message_nodraw
1544
;	pop	esi eax
1595
;	pop	esi eax
1545
	add	esi, 4
1596
	add	esi, 4
1546
	dec	eax
1597
	dec	eax
1547
	jz	exception
1598
	jz	exception
1548
	dec	eax
1599
	dec	eax
1549
	jz	terminated
1600
	jz	terminated
1550
	mov	[bSuspended], 1
1601
	mov	[bSuspended], 1
1551
	cmp	[bAfterGo], 0
1602
	cmp	[bAfterGo], 0
1552
	jnz	after_go_exception
1603
	jnz	after_go_exception
1553
	push	esi
1604
	push	esi
1554
	call	get_new_context
1605
	call	get_new_context
1555
	and	[_eflags], not 10100h		; clear TF,RF
1606
	and	[_eflags], not 10100h		; clear TF,RF
1556
	call	set_context
1607
	call	set_context
1557
	pop	esi
1608
	pop	esi
1558
.5:
1609
.5:
1559
	push	esi
1610
	push	esi
1560
	call	get_dump
1611
	call	get_dump
1561
	pop	esi
1612
	pop	esi
1562
	lodsd
1613
	lodsd
1563
	xor	ecx, ecx
1614
	xor	ecx, ecx
1564
.6:
1615
.6:
1565
	bt	eax, ecx
1616
	bt	eax, ecx
1566
	jnc	.7
1617
	jnc	.7
1567
	mov	ebx, [drx_break+ecx*4]
1618
	mov	ebx, [drx_break+ecx*4]
1568
	test	ebx, ebx
1619
	test	ebx, ebx
1569
	jz	.7
1620
	jz	.7
1570
	pushad
1621
	pushad
1571
	dec	ebx
1622
	dec	ebx
1572
	push	ebx
1623
	push	ebx
1573
	mov	esi, aBreakStop
1624
	mov	esi, aBreakStop
1574
	call	put_message_nodraw
1625
	call	put_message_nodraw
1575
	popad
1626
	popad
1576
.7:
1627
.7:
1577
	inc	ecx
1628
	inc	ecx
1578
	cmp	cl, 4
1629
	cmp	cl, 4
1579
	jb	.6
1630
	jb	.6
1580
	push	esi
1631
	push	esi
1581
	jmp	exception.done_draw
1632
	jmp	exception.done_draw
1582
terminated:
1633
terminated:
1583
	push	esi
1634
	push	esi
1584
	mov	esi, terminated_msg
1635
	mov	esi, terminated_msg
1585
	call	put_message
1636
	call	put_message
1586
	and	[debuggee_pid], 0
1637
	and	[debuggee_pid], 0
1587
	and	[temp_break], 0
1638
	and	[temp_break], 0
1588
	mov	[bAfterGo], 0
1639
	mov	[bAfterGo], 0
1589
	xor	eax, eax
1640
	xor	eax, eax
1590
	mov	ecx, breakpoints_n*6/4+4
1641
	mov	ecx, breakpoints_n*6/4+4
1591
	mov	edi, breakpoints
1642
	mov	edi, breakpoints
1592
	rep	stosd
1643
	rep	stosd
1593
	cmp	[bReload], 1
1644
	cmp	[bReload], 1
1594
	sbb	[bReload], -1
1645
	sbb	[bReload], -1
-
 
1646
	jnz	exception.done
-
 
1647
	call	free_symbols
1595
	jmp	exception.done
1648
	jmp	exception.done
1596
exception:
1649
exception:
1597
	mov	[bSuspended], 1
1650
	mov	[bSuspended], 1
1598
	cmp	[bAfterGo], 0
1651
	cmp	[bAfterGo], 0
1599
	jnz	after_go_exception
1652
	jnz	after_go_exception
1600
	lodsd
1653
	lodsd
1601
	push	esi
1654
	push	esi
1602
	push	eax
1655
	push	eax
1603
	call	get_new_context
1656
	call	get_new_context
1604
	and	[_eflags], not 10100h		; clear TF,RF
1657
	and	[_eflags], not 10100h		; clear TF,RF
1605
	call	set_context
1658
	call	set_context
1606
.4:
1659
.4:
1607
	call	get_dump
1660
	call	get_dump
1608
	pop	eax
1661
	pop	eax
1609
; int3 command generates exception 0D, #GP
1662
; int3 command generates exception 0D, #GP
1610
	push	eax
1663
	push	eax
1611
	cmp	al, 0Dh
1664
	cmp	al, 0Dh
1612
	jnz	.notdbg
1665
	jnz	.notdbg
1613
; check for 0xCC byte at eip
1666
; check for 0xCC byte at eip
1614
	push	0
1667
	push	0
1615
	push	69
1668
	push	69
1616
	pop	eax
1669
	pop	eax
1617
	push	6
1670
	push	6
1618
	pop	ebx
1671
	pop	ebx
1619
	mov	ecx, [debuggee_pid]
1672
	mov	ecx, [debuggee_pid]
1620
	mov	edi, esp
1673
	mov	edi, esp
1621
	mov	esi, [_eip]
1674
	mov	esi, [_eip]
1622
	push	1
1675
	push	1
1623
	pop	edx
1676
	pop	edx
1624
	mcall
1677
	mcall
1625
	pop	eax
1678
	pop	eax
1626
	cmp	al, 0xCC
1679
	cmp	al, 0xCC
1627
	jnz	.notdbg
1680
	jnz	.notdbg
1628
; this is either dbg breakpoint or int3 cmd in debuggee
1681
; this is either dbg breakpoint or int3 cmd in debuggee
1629
	mov	eax, [_eip]
1682
	mov	eax, [_eip]
1630
	call	find_enabled_breakpoint
1683
	call	find_enabled_breakpoint
1631
	jnz	.user_int3
1684
	jnz	.user_int3
1632
; dbg breakpoint; clear if one-shot
1685
; dbg breakpoint; clear if one-shot
1633
	pop	ecx
1686
	pop	ecx
1634
	push	eax
1687
	push	eax
1635
	mov	esi, aBreakStop
1688
	mov	esi, aBreakStop
1636
	test	byte [edi+4], 4
1689
	test	byte [edi+4], 4
1637
	jz	.put_msg_eax
1690
	jz	.put_msg_eax
1638
	pop	ecx
1691
	pop	ecx
1639
	call	clear_breakpoint
1692
	call	clear_breakpoint
1640
	jmp	.done
1693
	jmp	.done
1641
.user_int3:
1694
.user_int3:
1642
	mov	eax, [_eip]
1695
	mov	eax, [_eip]
1643
	inc	[_eip]
1696
	inc	[_eip]
1644
	pop	ecx
1697
	pop	ecx
1645
	push	eax
1698
	push	eax
1646
	call	set_context
1699
	call	set_context
1647
	mov	esi, aUserBreak
1700
	mov	esi, aUserBreak
1648
	jmp	.put_msg_eax
1701
	jmp	.put_msg_eax
1649
.notdbg:
1702
.notdbg:
1650
	mov	esi, aException
1703
	mov	esi, aException
1651
.put_msg_eax:
1704
.put_msg_eax:
1652
	call	put_message_nodraw
1705
	call	put_message_nodraw
1653
.done_draw:
1706
.done_draw:
1654
	call	draw_messages
1707
	call	draw_messages
1655
.done:
1708
.done:
1656
	push	18
1709
	push	18
1657
	pop	eax
1710
	pop	eax
1658
	push	3
1711
	push	3
1659
	pop	ebx
1712
	pop	ebx
1660
	mov	ecx, [dbgwnd]
1713
	mov	ecx, [dbgwnd]
1661
	mcall	; activate dbg window
1714
	mcall	; activate dbg window
1662
	call	redraw_title
1715
	call	redraw_title
1663
	call	redraw_registers
1716
	call	redraw_registers
1664
	call	redraw_dump
1717
	call	redraw_dump
1665
	call	update_disasm_eip
1718
	call	update_disasm_eip
1666
dbgmsgend:
1719
dbgmsgend:
1667
	pop	esi
1720
	pop	esi
1668
	mov	ecx, [dbgbuflen]
1721
	mov	ecx, [dbgbuflen]
1669
	add	ecx, dbgbuf
1722
	add	ecx, dbgbuf
1670
	cmp	esi, ecx
1723
	cmp	esi, ecx
1671
	jnz	dbgmsgstart
1724
	jnz	dbgmsgstart
1672
	and	[dbgbuflen], 0
1725
	and	[dbgbuflen], 0
1673
	neg	[dbgbufsize]
1726
	neg	[dbgbufsize]
1674
	cmp	[bReload], 2
1727
	cmp	[bReload], 2
1675
	jnz	@f
1728
	jnz	@f
1676
	mov	[bReload], 0
1729
	mov	[bReload], 0
1677
	call	do_reload
1730
	call	do_reload
1678
@@:
1731
@@:
1679
	jmp	waitevent
1732
	jmp	waitevent
1680
 
1733
 
1681
CtrlF7:
1734
CtrlF7:
1682
	cmp	[debuggee_pid], 0
1735
	cmp	[debuggee_pid], 0
1683
	jz	.no
1736
	jz	.no
1684
	call	OnStep
1737
	call	OnStep
1685
.no:
1738
.no:
1686
	jmp	waitevent
1739
	jmp	waitevent
1687
CtrlF8:
1740
CtrlF8:
1688
	cmp	[debuggee_pid], 0
1741
	cmp	[debuggee_pid], 0
1689
	jz	CtrlF7.no
1742
	jz	CtrlF7.no
1690
	call	OnProceed
1743
	call	OnProceed
1691
	jmp	CtrlF7.no
1744
	jmp	CtrlF7.no
1692
 
1745
 
1693
OnStep:
1746
OnStep:
1694
	cmp	[bSuspended], 0
1747
	cmp	[bSuspended], 0
1695
	jz	.running
1748
	jz	.running
1696
	call	get_context
1749
	call	get_context
1697
	or	byte [_eflags+1], 1		; set TF
1750
	or	byte [_eflags+1], 1		; set TF
1698
	call	set_context
1751
	call	set_context
1699
	and	byte [_eflags+1], not 1
1752
	and	byte [_eflags+1], not 1
1700
; if instruction at eip is "int xx", set one-shot breakpoint immediately after
1753
; if instruction at eip is "int xx", set one-shot breakpoint immediately after
1701
	mov	eax, [_eip]
1754
	mov	eax, [_eip]
1702
	call	find_enabled_breakpoint
1755
	call	find_enabled_breakpoint
1703
	jnz	@f
1756
	jnz	@f
1704
	cmp	byte [edi+5], 0xCD
1757
	cmp	byte [edi+5], 0xCD
1705
	jz	.int
1758
	jz	.int
1706
@@:
1759
@@:
1707
	push	0
1760
	push	0
1708
	push	69
1761
	push	69
1709
	pop	eax
1762
	pop	eax
1710
	push	6
1763
	push	6
1711
	pop	ebx
1764
	pop	ebx
1712
	mov	ecx, [debuggee_pid]
1765
	mov	ecx, [debuggee_pid]
1713
	push	3
1766
	push	3
1714
	pop	edx
1767
	pop	edx
1715
	mov	edi, esp
1768
	mov	edi, esp
1716
	mov	esi, [_eip]
1769
	mov	esi, [_eip]
1717
	mcall
1770
	mcall
1718
	cmp	eax, edx
1771
	cmp	eax, edx
1719
	pop	eax
1772
	pop	eax
1720
	jnz	.doit
1773
	jnz	.doit
1721
	cmp	al, 0xCD
1774
	cmp	al, 0xCD
1722
	jz	.int
1775
	jz	.int
1723
	cmp	ax, 0x050F
1776
	cmp	ax, 0x050F
1724
	jz	.syscall_enter
1777
	jz	.syscall
1725
	cmp	ax, 0x340F
1778
	cmp	ax, 0x340F
1726
	jz	.syscall_enter
1779
	jz	.sysenter
1727
; resume process
1780
; resume process
1728
.doit:
1781
.doit:
1729
	call	GoOn
1782
	call	GoOn
1730
	cmp	[bAfterGo], 0
1783
	cmp	[bAfterGo], 0
1731
	jz	@f
1784
	jz	@f
1732
	mov	[bAfterGo], 2
1785
	mov	[bAfterGo], 2
1733
@@:
1786
@@:
1734
	ret
1787
	ret
-
 
1788
.sysenter:	; return address is [ebp-4]
-
 
1789
	push	0
-
 
1790
	push	69
-
 
1791
	pop	eax
-
 
1792
	inc	edx	; read 4 bytes
-
 
1793
	mov	esi, [_ebp]
-
 
1794
	sub	esi, 4
-
 
1795
	mcall
-
 
1796
	cmp	eax, edx
-
 
1797
	pop	eax
-
 
1798
	jnz	.syscall
-
 
1799
	push	eax
-
 
1800
	and	byte [_eflags+1], not 1
-
 
1801
	call	set_context
-
 
1802
	pop	eax
-
 
1803
	jmp	@f
1735
.syscall_enter:
1804
.syscall:
1736
	and	byte [_eflags+1], not 1	; clear TF - avoid system halt (!)
1805
	and	byte [_eflags+1], not 1	; clear TF - avoid system halt (!)
1737
	call	set_context
1806
	call	set_context
1738
.int:
1807
.int:
1739
	mov	eax, [_eip]
1808
	mov	eax, [_eip]
1740
	inc	eax
1809
	inc	eax
1741
	inc	eax
1810
	inc	eax
-
 
1811
@@:
1742
	push	eax
1812
	push	eax
1743
	call	find_enabled_breakpoint
1813
	call	find_enabled_breakpoint
1744
	pop	eax
1814
	pop	eax
1745
	jz	.doit
1815
	jz	.doit
1746
; there is no enabled breakpoint yet; set temporary breakpoint
1816
; there is no enabled breakpoint yet; set temporary breakpoint
1747
	mov	bl, 5
1817
	mov	bl, 5
1748
	call	add_breakpoint
1818
	call	add_breakpoint
1749
	jmp	.doit
1819
	jmp	.doit
1750
.running:
1820
.running:
1751
	mov	esi, aRunningErr
1821
	mov	esi, aRunningErr
1752
	jmp	put_message
1822
	jmp	put_message
1753
 
1823
 
1754
OnProceed:
1824
OnProceed:
1755
	cmp	[bSuspended], 0
1825
	cmp	[bSuspended], 0
1756
	jz	OnStep.running
1826
	jz	OnStep.running
1757
	mov	esi, [_eip]
1827
	mov	esi, [_eip]
1758
@@:
1828
@@:
1759
	call	get_byte_nobreak
1829
	call	get_byte_nobreak
1760
	jc	OnStep
1830
	jc	OnStep
1761
	inc	esi
1831
	inc	esi
1762
; skip prefixes
1832
; skip prefixes
1763
	call	is_prefix
1833
	call	is_prefix
1764
	jz	@b
1834
	jz	@b
1765
	cmp	al, 0xE8	; call
1835
	cmp	al, 0xE8	; call
1766
	jnz	@f
1836
	jnz	@f
1767
	add	esi, 4
1837
	add	esi, 4
1768
	jmp	.doit
1838
	jmp	.doit
1769
@@:	; A4,A5 = movs, A6,A7=cmps
1839
@@:	; A4,A5 = movs, A6,A7=cmps
1770
	cmp	al, 0xA4
1840
	cmp	al, 0xA4
1771
	jb	@f
1841
	jb	@f
1772
	cmp	al, 0xA8
1842
	cmp	al, 0xA8
1773
	jb	.doit
1843
	jb	.doit
1774
@@:	; AA,AB=stos, AC,AD=lods, AE,AF=scas
1844
@@:	; AA,AB=stos, AC,AD=lods, AE,AF=scas
1775
	cmp	al, 0xAA
1845
	cmp	al, 0xAA
1776
	jb	@f
1846
	jb	@f
1777
	cmp	al, 0xB0
1847
	cmp	al, 0xB0
1778
	jb	.doit
1848
	jb	.doit
1779
@@:	; E0=loopnz,E1=loopz,E2=loop
1849
@@:	; E0=loopnz,E1=loopz,E2=loop
1780
	cmp	al, 0xE0
1850
	cmp	al, 0xE0
1781
	jb	.noloop
1851
	jb	.noloop
1782
	cmp	al, 0xE2
1852
	cmp	al, 0xE2
1783
	ja	.noloop
1853
	ja	.noloop
1784
	inc	esi
1854
	inc	esi
1785
	jmp	.doit
1855
	jmp	.doit
1786
.noloop:	; FF /2 = call
1856
.noloop:	; FF /2 = call
1787
	cmp	al, 0xFF
1857
	cmp	al, 0xFF
1788
	jnz	OnStep
1858
	jnz	OnStep
1789
	call	get_byte_nobreak
1859
	call	get_byte_nobreak
1790
	jc	OnStep
1860
	jc	OnStep
1791
	inc	esi
1861
	inc	esi
1792
	mov	cl, al
1862
	mov	cl, al
1793
	and	al, 00111000b
1863
	and	al, 00111000b
1794
	cmp	al, 00010000b
1864
	cmp	al, 00010000b
1795
	jnz	OnStep
1865
	jnz	OnStep
1796
; skip instruction
1866
; skip instruction
1797
	mov	al, cl
1867
	mov	al, cl
1798
	and	eax, 7
1868
	and	eax, 7
1799
	shr	cl, 6
1869
	shr	cl, 6
1800
	jz	.mod0
1870
	jz	.mod0
1801
	jp	.doit
1871
	jp	.doit
1802
	cmp	al, 4
1872
	cmp	al, 4
1803
	jnz	@f
1873
	jnz	@f
1804
	inc	esi
1874
	inc	esi
1805
@@:
1875
@@:
1806
	inc	esi
1876
	inc	esi
1807
	dec	cl
1877
	dec	cl
1808
	jz	@f
1878
	jz	@f
1809
	add	esi, 3
1879
	add	esi, 3
1810
@@:
1880
@@:
1811
	jmp	.doit
1881
	jmp	.doit
1812
.mod0:
1882
.mod0:
1813
	cmp	al, 4
1883
	cmp	al, 4
1814
	jnz	@f
1884
	jnz	@f
1815
	call	get_byte_nobreak
1885
	call	get_byte_nobreak
1816
	jc	OnStep
1886
	jc	OnStep
1817
	inc	esi
1887
	inc	esi
1818
	and	al, 7
1888
	and	al, 7
1819
@@:
1889
@@:
1820
	cmp	al, 5
1890
	cmp	al, 5
1821
	jnz	.doit
1891
	jnz	.doit
1822
	add	esi, 4
1892
	add	esi, 4
1823
.doit:
1893
.doit:
1824
; insert one-shot breakpoint at esi and resume
1894
; insert one-shot breakpoint at esi and resume
1825
	call	get_byte_nobreak
1895
	call	get_byte_nobreak
1826
	jc	OnStep
1896
	jc	OnStep
1827
	mov	eax, esi
1897
	mov	eax, esi
1828
	call	find_enabled_breakpoint
1898
	call	find_enabled_breakpoint
1829
	jz	.ret
1899
	jz	.ret
1830
	mov	eax, esi
1900
	mov	eax, esi
1831
	mov	bl, 5
1901
	mov	bl, 5
1832
	call	add_breakpoint
1902
	call	add_breakpoint
1833
	jmp	OnStep.doit
1903
	jmp	OnStep.doit
1834
.ret:
1904
.ret:
1835
	ret
1905
	ret
1836
 
1906
 
1837
get_byte_nobreak:
1907
get_byte_nobreak:
1838
	mov	eax, esi
1908
	mov	eax, esi
1839
	call	find_enabled_breakpoint
1909
	call	find_enabled_breakpoint
1840
	jnz	.nobreak
1910
	jnz	.nobreak
1841
	mov	al, [edi+5]
1911
	mov	al, [edi+5]
1842
	clc
1912
	clc
1843
	ret
1913
	ret
1844
.nobreak:
1914
.nobreak:
1845
	push	69
1915
	push	69
1846
	pop	eax
1916
	pop	eax
1847
	push	6
1917
	push	6
1848
	pop	ebx
1918
	pop	ebx
1849
	mov	ecx, [debuggee_pid]
1919
	mov	ecx, [debuggee_pid]
1850
	xor	edx, edx
1920
	xor	edx, edx
1851
	push	edx
1921
	push	edx
1852
	inc	edx
1922
	inc	edx
1853
	mov	edi, esp
1923
	mov	edi, esp
1854
	mcall
1924
	mcall
1855
	dec	eax
1925
	dec	eax
1856
	clc
1926
	clc
1857
	jz	@f
1927
	jz	@f
1858
	stc
1928
	stc
1859
@@:	pop	eax
1929
@@:	pop	eax
1860
	ret
1930
	ret
1861
 
1931
 
1862
is_prefix:
1932
is_prefix:
1863
	cmp	al, 0x64	; fs:
1933
	cmp	al, 0x64	; fs:
1864
	jz	.ret
1934
	jz	.ret
1865
	cmp	al, 0x65	; gs:
1935
	cmp	al, 0x65	; gs:
1866
	jz	.ret
1936
	jz	.ret
1867
	cmp	al, 0x66	; use16/32
1937
	cmp	al, 0x66	; use16/32
1868
	jz	.ret
1938
	jz	.ret
1869
	cmp	al, 0x67	; addr16/32
1939
	cmp	al, 0x67	; addr16/32
1870
	jz	.ret
1940
	jz	.ret
1871
	cmp	al, 0xF0	; lock
1941
	cmp	al, 0xF0	; lock
1872
	jz	.ret
1942
	jz	.ret
1873
	cmp	al, 0xF2	; repnz
1943
	cmp	al, 0xF2	; repnz
1874
	jz	.ret
1944
	jz	.ret
1875
	cmp	al, 0xF3	; rep(z)
1945
	cmp	al, 0xF3	; rep(z)
1876
	jz	.ret
1946
	jz	.ret
1877
	cmp	al, 0x2E	; cs:
1947
	cmp	al, 0x2E	; cs:
1878
	jz	.ret
1948
	jz	.ret
1879
	cmp	al, 0x36	; ss:
1949
	cmp	al, 0x36	; ss:
1880
	jz	.ret
1950
	jz	.ret
1881
	cmp	al, 0x3E	; ds:
1951
	cmp	al, 0x3E	; ds:
1882
	jz	.ret
1952
	jz	.ret
1883
	cmp	al, 0x26	; es:
1953
	cmp	al, 0x26	; es:
1884
.ret:	ret
1954
.ret:	ret
1885
 
1955
 
1886
token_end	equ	1
1956
token_end	equ	1
1887
token_reg	equ	2
1957
token_reg	equ	2
1888
token_hex	equ	3
1958
token_hex	equ	3
1889
token_add	equ	4
1959
token_add	equ	4
1890
token_sub	equ	5
1960
token_sub	equ	5
1891
token_mul	equ	6
1961
token_mul	equ	6
1892
token_div	equ	7
1962
token_div	equ	7
1893
token_lp	equ	8
1963
token_lp	equ	8
1894
token_rp	equ	9
1964
token_rp	equ	9
1895
token_err	equ	-1
1965
token_err	equ	-1
1896
 
1966
 
1897
is_hex_digit:
1967
is_hex_digit:
1898
	cmp	al, '0'
1968
	cmp	al, '0'
1899
	jb	.no
1969
	jb	.no
1900
	cmp	al, '9'
1970
	cmp	al, '9'
1901
	jbe	.09
1971
	jbe	.09
1902
	cmp	al, 'A'
1972
	cmp	al, 'A'
1903
	jb	.no
1973
	jb	.no
1904
	cmp	al, 'F'
1974
	cmp	al, 'F'
1905
	jbe	.AF
1975
	jbe	.AF
1906
	cmp	al, 'a'
1976
	cmp	al, 'a'
1907
	jb	.no
1977
	jb	.no
1908
	cmp	al, 'f'
1978
	cmp	al, 'f'
1909
	jbe	.af
1979
	jbe	.af
1910
.no:
1980
.no:
1911
	stc
1981
	stc
1912
	ret
1982
	ret
1913
.09:
1983
.09:
1914
	sub	al, '0'
1984
	sub	al, '0'
1915
;	clc
1985
;	clc
1916
	ret
1986
	ret
1917
.AF:
1987
.AF:
1918
	sub	al, 'A'-10
1988
	sub	al, 'A'-10
1919
;	clc
1989
;	clc
1920
	ret
1990
	ret
1921
.af:
1991
.af:
1922
	sub	al, 'a'-10
1992
	sub	al, 'a'-10
1923
;	clc
1993
;	clc
1924
	ret
1994
	ret
1925
 
1995
 
1926
find_reg:
1996
find_reg:
1927
	mov	edi, reg_table
1997
	mov	edi, reg_table
1928
.findreg:
1998
.findreg:
1929
	movzx	ecx, byte [edi]
1999
	movzx	ecx, byte [edi]
1930
	stc
2000
	stc
1931
	jecxz	.regnotfound
2001
	jecxz	.regnotfound
1932
	inc	edi
2002
	inc	edi
1933
	push	esi edi ecx
2003
	push	esi edi ecx
1934
@@:
2004
@@:
1935
	lodsb
2005
	lodsb
1936
	or	al, 20h
2006
	or	al, 20h
1937
	scasb
2007
	scasb
1938
	loopz	@b
2008
	loopz	@b
1939
	pop	ecx edi esi
2009
	pop	ecx edi esi
1940
	lea	edi, [edi+ecx+1]
2010
	lea	edi, [edi+ecx+1]
1941
	jnz	.findreg
2011
	jnz	.findreg
1942
	movzx	edi, byte [edi-1]
2012
	movzx	edi, byte [edi-1]
1943
	add	esi, ecx
2013
	add	esi, ecx
1944
.regnotfound:
2014
.regnotfound:
1945
	ret
2015
	ret
1946
 
2016
 
1947
expr_get_token:
2017
expr_get_token:
1948
	lodsb
2018
	lodsb
1949
	cmp	al, 0
2019
	cmp	al, 0
1950
	jz	.end_token
2020
	jz	.end_token
1951
	cmp	al, ' '
2021
	cmp	al, ' '
1952
	jbe	expr_get_token
2022
	jbe	expr_get_token
1953
	cmp	al, '+'
2023
	cmp	al, '+'
1954
	jz	.add
2024
	jz	.add
1955
	cmp	al, '-'
2025
	cmp	al, '-'
1956
	jz	.sub
2026
	jz	.sub
1957
	cmp	al, '*'
2027
	cmp	al, '*'
1958
	jz	.mul
2028
	jz	.mul
1959
	cmp	al, '/'
2029
	cmp	al, '/'
1960
	jz	.div
2030
	jz	.div
1961
	cmp	al, '('
2031
	cmp	al, '('
1962
	jz	.lp
2032
	jz	.lp
1963
	cmp	al, ')'
2033
	cmp	al, ')'
1964
	jnz	.notsign
2034
	jnz	.notsign
1965
.rp:
2035
.rp:
1966
	mov	al, token_rp
2036
	mov	al, token_rp
1967
	ret
2037
	ret
1968
.div:
2038
.div:
1969
	mov	al, token_div
2039
	mov	al, token_div
1970
	ret
2040
	ret
1971
.end_token:
2041
.end_token:
1972
	mov	al, token_end
2042
	mov	al, token_end
1973
	ret
2043
	ret
1974
.add:
2044
.add:
1975
	mov	al, token_add
2045
	mov	al, token_add
1976
	ret
2046
	ret
1977
.sub:
2047
.sub:
1978
	mov	al, token_sub
2048
	mov	al, token_sub
1979
	ret
2049
	ret
1980
.mul:
2050
.mul:
1981
	mov	al, token_mul
2051
	mov	al, token_mul
1982
	ret
2052
	ret
1983
.lp:
2053
.lp:
1984
	mov	al, token_lp
2054
	mov	al, token_lp
1985
	ret
2055
	ret
1986
.notsign:
2056
.notsign:
1987
	dec	esi
2057
	dec	esi
1988
	call	find_reg
2058
	call	find_reg
1989
	jc	.regnotfound
2059
	jc	.regnotfound
1990
	mov	al, token_reg
2060
	mov	al, token_reg
1991
	ret
2061
	ret
1992
.regnotfound:
2062
.regnotfound:
-
 
2063
; test for symbol
-
 
2064
	push	esi
-
 
2065
@@:
-
 
2066
	lodsb
-
 
2067
	cmp	al, ' '
-
 
2068
	ja	@b
-
 
2069
	push	eax
-
 
2070
	mov	byte [esi], 0
-
 
2071
	xchg	esi, [esp+4]
-
 
2072
	call	find_symbol_name
-
 
2073
	mov	edi, eax
-
 
2074
	pop	eax
-
 
2075
	xchg	esi, [esp]
-
 
2076
	mov	byte [esi], al
-
 
2077
	jc	@f
-
 
2078
	add	esp, 4
-
 
2079
	mov	al, token_hex
-
 
2080
	ret
-
 
2081
@@:
-
 
2082
	pop	esi
1993
; test for hex number
2083
; test for hex number
1994
	xor	ecx, ecx
2084
	xor	ecx, ecx
1995
	xor	edi, edi
2085
	xor	edi, edi
1996
	xor	eax, eax
2086
	xor	eax, eax
1997
@@:
2087
@@:
1998
	lodsb
2088
	lodsb
1999
	call	is_hex_digit
2089
	call	is_hex_digit
2000
	jc	@f
2090
	jc	@f
2001
	shl	edi, 4
2091
	shl	edi, 4
2002
	or	edi, eax
2092
	or	edi, eax
2003
	inc	ecx
2093
	inc	ecx
2004
	jmp	@b
2094
	jmp	@b
2005
@@:
2095
@@:
2006
	dec	esi
2096
	dec	esi
2007
	jecxz	.err
2097
	jecxz	.err
2008
	cmp	ecx, 8
2098
	cmp	ecx, 8
2009
	ja	.err
2099
	ja	.err
2010
	mov	al, token_hex
2100
	mov	al, token_hex
2011
	ret
2101
	ret
2012
.err:
2102
.err:
2013
	mov	al, token_err
2103
	mov	al, token_err
2014
	mov	esi, aParseError
2104
	mov	esi, aParseError
2015
	ret
2105
	ret
2016
 
2106
 
2017
expr_read2:
2107
expr_read2:
2018
	cmp	al, token_hex
2108
	cmp	al, token_hex
2019
	jz	.hex
2109
	jz	.hex
2020
	cmp	al, token_reg
2110
	cmp	al, token_reg
2021
	jz	.reg
2111
	jz	.reg
2022
	cmp	al, token_lp
2112
	cmp	al, token_lp
2023
	jz	.lp
2113
	jz	.lp
2024
	mov	al, token_err
2114
	mov	al, token_err
2025
	mov	esi, aParseError
2115
	mov	esi, aParseError
2026
	ret
2116
	ret
2027
.hex:
2117
.hex:
2028
	mov	ebp, edi
2118
	mov	ebp, edi
2029
.ret:
2119
.ret:
2030
	jmp	expr_get_token
2120
	jmp	expr_get_token
2031
.reg:
2121
.reg:
2032
	cmp	edi, 24
2122
	cmp	edi, 24
2033
	jz	.eip
2123
	jz	.eip
2034
	sub	edi, 4
2124
	sub	edi, 4
2035
	jb	.8lo
2125
	jb	.8lo
2036
	sub	edi, 4
2126
	sub	edi, 4
2037
	jb	.8hi
2127
	jb	.8hi
2038
	sub	edi, 8
2128
	sub	edi, 8
2039
	jb	.16
2129
	jb	.16
2040
	mov	ebp, [_eax+edi*4]
2130
	mov	ebp, [_eax+edi*4]
2041
	jmp	.ret
2131
	jmp	.ret
2042
.16:
2132
.16:
2043
	movzx	ebp, word [_eax+(edi+8)*4]
2133
	movzx	ebp, word [_eax+(edi+8)*4]
2044
	jmp	.ret
2134
	jmp	.ret
2045
.8lo:
2135
.8lo:
2046
	movzx	ebp, byte [_eax+(edi+4)*4]
2136
	movzx	ebp, byte [_eax+(edi+4)*4]
2047
	jmp	.ret
2137
	jmp	.ret
2048
.8hi:
2138
.8hi:
2049
	movzx	ebp, byte [_eax+(edi+4)*4+1]
2139
	movzx	ebp, byte [_eax+(edi+4)*4+1]
2050
	jmp	.ret
2140
	jmp	.ret
2051
.eip:
2141
.eip:
2052
	mov	ebp, [_eip]
2142
	mov	ebp, [_eip]
2053
	jmp	.ret
2143
	jmp	.ret
2054
.lp:
2144
.lp:
2055
	call	expr_get_token
2145
	call	expr_get_token
2056
	call	expr_read0
2146
	call	expr_read0
2057
	cmp	al, token_err
2147
	cmp	al, token_err
2058
	jz	@f
2148
	jz	@f
2059
	cmp	al, token_rp
2149
	cmp	al, token_rp
2060
	jz	expr_get_token
2150
	jz	expr_get_token
2061
	mov	al, token_err
2151
	mov	al, token_err
2062
	mov	esi, aParseError
2152
	mov	esi, aParseError
2063
@@:	ret
2153
@@:	ret
2064
 
2154
 
2065
expr_read1:
2155
expr_read1:
2066
	call	expr_read2
2156
	call	expr_read2
2067
.1:
2157
.1:
2068
	cmp	al, token_mul
2158
	cmp	al, token_mul
2069
	jz	.mul
2159
	jz	.mul
2070
	cmp	al, token_div
2160
	cmp	al, token_div
2071
	jz	.div
2161
	jz	.div
2072
	ret
2162
	ret
2073
.mul:
2163
.mul:
2074
	push	ebp
2164
	push	ebp
2075
	call	expr_get_token
2165
	call	expr_get_token
2076
	call	expr_read2
2166
	call	expr_read2
2077
	pop	edx
2167
	pop	edx
2078
; ebp := edx*ebp
2168
; ebp := edx*ebp
2079
	imul	ebp, edx
2169
	imul	ebp, edx
2080
	jmp	.1
2170
	jmp	.1
2081
.div:
2171
.div:
2082
	push	ebp
2172
	push	ebp
2083
	call	expr_get_token
2173
	call	expr_get_token
2084
	call	expr_read2
2174
	call	expr_read2
2085
	pop	edx
2175
	pop	edx
2086
; ebp := edx/ebp
2176
; ebp := edx/ebp
2087
	test	ebp, ebp
2177
	test	ebp, ebp
2088
	jz	.div0
2178
	jz	.div0
2089
	push	eax
2179
	push	eax
2090
	xor	eax, eax
2180
	xor	eax, eax
2091
	xchg	eax, edx
2181
	xchg	eax, edx
2092
	div	ebp
2182
	div	ebp
2093
	xchg	eax, ebp
2183
	xchg	eax, ebp
2094
	pop	eax
2184
	pop	eax
2095
	jmp	.1
2185
	jmp	.1
2096
.div0:
2186
.div0:
2097
	mov	al, token_err
2187
	mov	al, token_err
2098
	mov	esi, aDivByZero
2188
	mov	esi, aDivByZero
2099
	ret
2189
	ret
2100
 
2190
 
2101
expr_read0:
2191
expr_read0:
2102
	xor	ebp, ebp
2192
	xor	ebp, ebp
2103
	cmp	al, token_add
2193
	cmp	al, token_add
2104
	jz	.add
2194
	jz	.add
2105
	cmp	al, token_sub
2195
	cmp	al, token_sub
2106
	jz	.sub
2196
	jz	.sub
2107
	call	expr_read1
2197
	call	expr_read1
2108
.1:
2198
.1:
2109
	cmp	al, token_add
2199
	cmp	al, token_add
2110
	jz	.add
2200
	jz	.add
2111
	cmp	al, token_sub
2201
	cmp	al, token_sub
2112
	jz	.sub
2202
	jz	.sub
2113
	ret
2203
	ret
2114
.add:
2204
.add:
2115
	push	ebp
2205
	push	ebp
2116
	call	expr_get_token
2206
	call	expr_get_token
2117
	call	expr_read1
2207
	call	expr_read1
2118
	pop	edx
2208
	pop	edx
2119
; ebp := edx+ebp
2209
; ebp := edx+ebp
2120
	add	ebp, edx
2210
	add	ebp, edx
2121
	jmp	.1
2211
	jmp	.1
2122
.sub:
2212
.sub:
2123
	push	ebp
2213
	push	ebp
2124
	call	expr_get_token
2214
	call	expr_get_token
2125
	call	expr_read1
2215
	call	expr_read1
2126
	pop	edx
2216
	pop	edx
2127
; ebp := edx-ebp
2217
; ebp := edx-ebp
2128
	xchg	edx, ebp
2218
	xchg	edx, ebp
2129
	sub	ebp, edx
2219
	sub	ebp, edx
2130
	jmp	.1
2220
	jmp	.1
2131
 
2221
 
2132
calc_expression:
2222
calc_expression:
2133
; in: esi->expression
2223
; in: esi->expression
2134
; out: CF=1 if error
2224
; out: CF=1 if error
2135
;      CF=0 and ebp=value if ok
2225
;      CF=0 and ebp=value if ok
2136
	call	expr_get_token
2226
	call	expr_get_token
2137
	call	expr_read0
2227
	call	expr_read0
2138
	cmp	al, token_end
2228
	cmp	al, token_end
2139
	jz	.end
2229
	jz	.end
2140
	cmp	al, token_err
2230
	cmp	al, token_err
2141
	jz	@f
2231
	jz	@f
2142
	mov	esi, aParseError
2232
	mov	esi, aParseError
2143
@@:
2233
@@:
2144
	call	put_message
2234
	call	put_message
2145
	stc
2235
	stc
2146
	ret
2236
	ret
2147
.end:
2237
.end:
2148
	clc
2238
	clc
2149
	ret
2239
	ret
2150
 
2240
 
2151
OnCalc:
2241
OnCalc:
2152
	mov	esi, [curarg]
2242
	mov	esi, [curarg]
2153
	call	calc_expression
2243
	call	calc_expression
2154
	jc	.ret
2244
	jc	.ret
2155
	push	ebp
2245
	push	ebp
2156
	mov	esi, calc_string
2246
	mov	esi, calc_string
2157
	call	put_message_nodraw
2247
	call	put_message_nodraw
2158
	jmp	draw_messages
2248
	jmp	draw_messages
2159
.ret:
2249
.ret:
2160
	ret
2250
	ret
2161
 
2251
 
2162
OnDump:
2252
OnDump:
2163
	mov	esi, [curarg]
2253
	mov	esi, [curarg]
2164
	cmp	byte [esi], 0
2254
	cmp	byte [esi], 0
2165
	jnz	.param
2255
	jnz	.param
2166
	add	[dumppos], dump_height*10h
2256
	add	[dumppos], dump_height*10h
2167
	jmp	.doit
2257
	jmp	.doit
2168
.param:
2258
.param:
2169
	call	calc_expression
2259
	call	calc_expression
2170
	jc	.ret
2260
	jc	.ret
2171
	mov	[dumppos], ebp
2261
	mov	[dumppos], ebp
2172
.doit:
2262
.doit:
2173
	call	get_dump
2263
	call	get_dump
2174
	call	redraw_dump
2264
	call	redraw_dump
2175
.ret:
2265
.ret:
2176
	ret
2266
	ret
2177
 
2267
 
2178
OnUnassemble:
2268
OnUnassemble:
2179
	mov	esi, [curarg]
2269
	mov	esi, [curarg]
2180
	cmp	byte [esi], 0
2270
	cmp	byte [esi], 0
2181
	jnz	.param
2271
	jnz	.param
2182
	mov	eax, [disasm_start_pos]
2272
	mov	eax, [disasm_start_pos]
2183
	mov	ecx, disasm_height
2273
	mov	ecx, disasm_height
2184
	mov	[disasm_cur_pos], eax
2274
	mov	[disasm_cur_pos], eax
-
 
2275
.l:
-
 
2276
	mov	eax, [disasm_cur_pos]
-
 
2277
	call	find_symbol
-
 
2278
	jc	@f
-
 
2279
	dec	ecx
-
 
2280
	jz	.m
2185
@@:
2281
@@:
2186
	push	ecx
2282
	push	ecx
2187
	call	disasm_instr
2283
	call	disasm_instr
2188
	pop	ecx
2284
	pop	ecx
2189
	jc	.err
2285
	jc	.err
2190
	loop	@b
2286
	loop	.l
-
 
2287
.m:
2191
	mov	eax, [disasm_cur_pos]
2288
	mov	eax, [disasm_cur_pos]
2192
	jmp	.doit
2289
	jmp	.doit
2193
.param:
2290
.param:
2194
	call	calc_expression
2291
	call	calc_expression
2195
	jc	.ret
2292
	jc	.ret
2196
	mov	eax, ebp
2293
	mov	eax, ebp
2197
.doit:
2294
.doit:
2198
	push	eax
2295
	push	eax
2199
	push	[disasm_start_pos]
2296
	push	[disasm_start_pos]
2200
	mov	[disasm_start_pos], eax
2297
	mov	[disasm_start_pos], eax
2201
	call	update_disasm
2298
	call	update_disasm
2202
	pop	[disasm_start_pos]
2299
	pop	[disasm_start_pos]
2203
	pop	eax
2300
	pop	eax
2204
	cmp	[disasm_cur_str], 0
2301
	cmp	[disasm_cur_str], 0
2205
	jz	@f
2302
	jz	@f
2206
	mov	[disasm_start_pos], eax
2303
	mov	[disasm_start_pos], eax
2207
.ret:
2304
.ret:
2208
	ret
2305
	ret
2209
@@:
2306
@@:
2210
	call	update_disasm
2307
	call	update_disasm
2211
.err:
2308
.err:
2212
	mov	esi, aInvAddr
2309
	mov	esi, aInvAddr
2213
	jmp	put_message
2310
	jmp	put_message
2214
 
2311
 
2215
OnReg:
2312
OnReg:
2216
	mov	esi, [curarg]
2313
	mov	esi, [curarg]
2217
	call	skip_spaces
2314
	call	skip_spaces
2218
	call	find_reg
2315
	call	find_reg
2219
	jnc	@f
2316
	jnc	@f
2220
.err:
2317
.err:
2221
	mov	esi, RSyntax
2318
	mov	esi, RSyntax
2222
	jmp	put_message
2319
	jmp	put_message
2223
@@:
2320
@@:
2224
	call	skip_spaces
2321
	call	skip_spaces
2225
	test	al, al
2322
	test	al, al
2226
	jz	.err
2323
	jz	.err
2227
	cmp	al, '='
2324
	cmp	al, '='
2228
	jnz	@f
2325
	jnz	@f
2229
	inc	esi
2326
	inc	esi
2230
	call	skip_spaces
2327
	call	skip_spaces
2231
	test	al, al
2328
	test	al, al
2232
	jz	.err
2329
	jz	.err
2233
@@:
2330
@@:
2234
	push	edi
2331
	push	edi
2235
	call	calc_expression
2332
	call	calc_expression
2236
	pop	edi
2333
	pop	edi
2237
	jc	.ret
2334
	jc	.ret
2238
; now edi=register id, ebp=value
2335
; now edi=register id, ebp=value
2239
	cmp	[bSuspended], 0
2336
	cmp	[bSuspended], 0
2240
	mov	esi, aRunningErr
2337
	mov	esi, aRunningErr
2241
	jz	put_message
2338
	jz	put_message
2242
	xchg	eax, ebp
2339
	xchg	eax, ebp
2243
	cmp	edi, 24
2340
	cmp	edi, 24
2244
	jz	.eip
2341
	jz	.eip
2245
	sub	edi, 4
2342
	sub	edi, 4
2246
	jb	.8lo
2343
	jb	.8lo
2247
	sub	edi, 4
2344
	sub	edi, 4
2248
	jb	.8hi
2345
	jb	.8hi
2249
	sub	edi, 8
2346
	sub	edi, 8
2250
	jb	.16
2347
	jb	.16
2251
	mov	[_eax+edi*4], eax
2348
	mov	[_eax+edi*4], eax
2252
	jmp	.ret
2349
	jmp	.ret
2253
.16:
2350
.16:
2254
	mov	word [_eax+(edi+8)*4], ax
2351
	mov	word [_eax+(edi+8)*4], ax
2255
	jmp	.ret
2352
	jmp	.ret
2256
.8lo:
2353
.8lo:
2257
	mov	byte [_eax+(edi+4)*4], al
2354
	mov	byte [_eax+(edi+4)*4], al
2258
	jmp	.ret
2355
	jmp	.ret
2259
.8hi:
2356
.8hi:
2260
	mov	byte [_eax+(edi+4)*4+1], al
2357
	mov	byte [_eax+(edi+4)*4+1], al
2261
	jmp	.ret
2358
	jmp	.ret
2262
.eip:
2359
.eip:
2263
	mov	[_eip], eax
2360
	mov	[_eip], eax
2264
	call	update_disasm_eip
2361
	call	update_disasm_eip
2265
.ret:
2362
.ret:
2266
	call	set_context
2363
	call	set_context
2267
	jmp	redraw_registers
2364
	jmp	redraw_registers
2268
 
2365
 
2269
; Breakpoints manipulation
2366
; Breakpoints manipulation
2270
OnBp:
2367
OnBp:
2271
	mov	esi, [curarg]
2368
	mov	esi, [curarg]
2272
	call	calc_expression
2369
	call	calc_expression
2273
	jc	.ret
2370
	jc	.ret
2274
	xchg	eax, ebp
2371
	xchg	eax, ebp
2275
	push	eax
2372
	push	eax
2276
	call	find_breakpoint
2373
	call	find_breakpoint
2277
	inc	eax
2374
	inc	eax
2278
	pop	eax
2375
	pop	eax
2279
	jz	.notfound
2376
	jz	.notfound
2280
	mov	esi, aDuplicateBreakpoint
2377
	mov	esi, aDuplicateBreakpoint
2281
	jmp	.sayerr
2378
	jmp	.sayerr
2282
.notfound:
2379
.notfound:
2283
	mov	bl, 1
2380
	mov	bl, 1
2284
	call	add_breakpoint
2381
	call	add_breakpoint
2285
	jnc	.ret
2382
	jnc	.ret
2286
	mov	esi, aBreakpointLimitExceeded
2383
	mov	esi, aBreakpointLimitExceeded
2287
.sayerr:
2384
.sayerr:
2288
	call	put_message
2385
	call	put_message
2289
.ret:
2386
.ret:
2290
	jmp	redraw_disasm
2387
	jmp	redraw_disasm
2291
 
2388
 
2292
OnBpmb:
2389
OnBpmb:
2293
	mov	dh, 0011b
2390
	mov	dh, 0011b
2294
	jmp	DoBpm
2391
	jmp	DoBpm
2295
OnBpmw:
2392
OnBpmw:
2296
	mov	dh, 0111b
2393
	mov	dh, 0111b
2297
	jmp	DoBpm
2394
	jmp	DoBpm
2298
OnBpmd:
2395
OnBpmd:
2299
	mov	dh, 1111b
2396
	mov	dh, 1111b
2300
DoBpm:
2397
DoBpm:
2301
	mov	esi, [curarg]
2398
	mov	esi, [curarg]
2302
	cmp	byte [esi], 'w'
2399
	cmp	byte [esi], 'w'
2303
	jnz	@f
2400
	jnz	@f
2304
	and	dh, not 2
2401
	and	dh, not 2
2305
	inc	esi
2402
	inc	esi
2306
@@:
2403
@@:
2307
	push	edx
2404
	push	edx
2308
	call	calc_expression
2405
	call	calc_expression
2309
	pop	edx
2406
	pop	edx
2310
	jnc	@f
2407
	jnc	@f
2311
	ret
2408
	ret
2312
@@:
2409
@@:
2313
; ebp=expression, dh=flags
2410
; ebp=expression, dh=flags
2314
	movzx	eax, dh
2411
	movzx	eax, dh
2315
	shr	eax, 2
2412
	shr	eax, 2
2316
	test	ebp, eax
2413
	test	ebp, eax
2317
	jz	@f
2414
	jz	@f
2318
	mov	esi, aUnaligned
2415
	mov	esi, aUnaligned
2319
	jmp	put_message
2416
	jmp	put_message
2320
@@:
2417
@@:
2321
	mov	eax, ebp
2418
	mov	eax, ebp
2322
	mov	bl, 0Bh
2419
	mov	bl, 0Bh
2323
	call	add_breakpoint
2420
	call	add_breakpoint
2324
	jnc	@f
2421
	jnc	@f
2325
	mov	esi, aBreakpointLimitExceeded
2422
	mov	esi, aBreakpointLimitExceeded
2326
	jmp	put_message
2423
	jmp	put_message
2327
@@:
2424
@@:
2328
; now find index
2425
; now find index
2329
	push	eax
2426
	push	eax
2330
	xor	ecx, ecx
2427
	xor	ecx, ecx
2331
.l1:
2428
.l1:
2332
	cmp	[drx_break+ecx*4], 0
2429
	cmp	[drx_break+ecx*4], 0
2333
	jnz	.l2
2430
	jnz	.l2
2334
	push	69
2431
	push	69
2335
	pop	eax
2432
	pop	eax
2336
	push	ecx
2433
	push	ecx
2337
	mov	dl, cl
2434
	mov	dl, cl
2338
	mov	ecx, [debuggee_pid]
2435
	mov	ecx, [debuggee_pid]
2339
	mov	esi, ebp
2436
	mov	esi, ebp
2340
	push	9
2437
	push	9
2341
	pop	ebx
2438
	pop	ebx
2342
	mcall
2439
	mcall
2343
	test	eax, eax
2440
	test	eax, eax
2344
	jz	.ok
2441
	jz	.ok
2345
	pop	ecx
2442
	pop	ecx
2346
.l2:
2443
.l2:
2347
	inc	ecx
2444
	inc	ecx
2348
	cmp	ecx, 4
2445
	cmp	ecx, 4
2349
	jb	.l1
2446
	jb	.l1
2350
	pop	eax
2447
	pop	eax
2351
	call	clear_breakpoint
2448
	call	clear_breakpoint
2352
	mov	esi, aBreakpointLimitExceeded
2449
	mov	esi, aBreakpointLimitExceeded
2353
	jmp	put_message
2450
	jmp	put_message
2354
.ok:
2451
.ok:
2355
	pop	ecx
2452
	pop	ecx
2356
	pop	eax
2453
	pop	eax
2357
	and	byte [edi], not 2	; breakpoint is enabled
2454
	and	byte [edi], not 2	; breakpoint is enabled
2358
	shl	dl, 6
2455
	shl	dl, 6
2359
	or	dl, dh
2456
	or	dl, dh
2360
	mov	byte [edi+1], dl
2457
	mov	byte [edi+1], dl
2361
	inc	eax
2458
	inc	eax
2362
	mov	[drx_break+ecx*4], eax
2459
	mov	[drx_break+ecx*4], eax
2363
	ret
2460
	ret
2364
 
2461
 
2365
OnBc:
2462
OnBc:
2366
	mov	esi, [curarg]
2463
	mov	esi, [curarg]
2367
@@:	call	get_hex_number
2464
@@:	call	get_hex_number
2368
	jc	OnBp.ret
2465
	jc	OnBp.ret
2369
	call	clear_breakpoint
2466
	call	clear_breakpoint
2370
	jmp	@b
2467
	jmp	@b
2371
 
2468
 
2372
OnBd:
2469
OnBd:
2373
	mov	esi, [curarg]
2470
	mov	esi, [curarg]
2374
@@:	call	get_hex_number
2471
@@:	call	get_hex_number
2375
	jc	OnBp.ret
2472
	jc	OnBp.ret
2376
	call	disable_breakpoint
2473
	call	disable_breakpoint
2377
	jmp	@b
2474
	jmp	@b
2378
 
2475
 
2379
OnBe:
2476
OnBe:
2380
	mov	esi, [curarg]
2477
	mov	esi, [curarg]
2381
@@:	call	get_hex_number
2478
@@:	call	get_hex_number
2382
	jc	OnBp.ret
2479
	jc	OnBp.ret
2383
	push	eax
2480
	push	eax
2384
	call	find_enabled_breakpoint
2481
	call	find_enabled_breakpoint
2385
	pop	eax
2482
	pop	eax
2386
	jz	.err
2483
	jz	.err
2387
	call	enable_breakpoint
2484
	call	enable_breakpoint
2388
	jmp	@b
2485
	jmp	@b
2389
.err:
2486
.err:
2390
	mov	esi, OnBeErrMsg
2487
	mov	esi, OnBeErrMsg
2391
	jmp	put_message
2488
	jmp	put_message
2392
 
2489
 
2393
get_hex_number:
2490
get_hex_number:
2394
	call	skip_spaces
2491
	call	skip_spaces
2395
	xor	ecx, ecx
2492
	xor	ecx, ecx
2396
	xor	edx, edx
2493
	xor	edx, edx
2397
@@:
2494
@@:
2398
	lodsb
2495
	lodsb
2399
	call	is_hex_digit
2496
	call	is_hex_digit
2400
	jc	.ret
2497
	jc	.ret
2401
	shl	edx, 4
2498
	shl	edx, 4
2402
	or	dl, al
2499
	or	dl, al
2403
	inc	ecx
2500
	inc	ecx
2404
	jmp	@b
2501
	jmp	@b
2405
.ret:
2502
.ret:
2406
	dec	esi
2503
	dec	esi
2407
	cmp	ecx, 1
2504
	cmp	ecx, 1
2408
	xchg	eax, edx
2505
	xchg	eax, edx
2409
	ret
2506
	ret
2410
 
2507
 
2411
OnBl:
2508
OnBl:
2412
	mov	esi, [curarg]
2509
	mov	esi, [curarg]
2413
	cmp	byte [esi], 0
2510
	cmp	byte [esi], 0
2414
	jz	.listall
2511
	jz	.listall
2415
	call	get_hex_number
2512
	call	get_hex_number
2416
	jc	.ret
2513
	jc	.ret
2417
	cmp	eax, breakpoints_n
2514
	cmp	eax, breakpoints_n
2418
	jae	.err
2515
	jae	.err
2419
	push	eax
2516
	push	eax
2420
	add	eax, eax
2517
	add	eax, eax
2421
	lea	edi, [breakpoints + eax + eax*2]
2518
	lea	edi, [breakpoints + eax + eax*2]
2422
	pop	eax
2519
	pop	eax
2423
	test	byte [edi+4], 1
2520
	test	byte [edi+4], 1
2424
	jz	.err
2521
	jz	.err
2425
	call	show_break_info
2522
	call	show_break_info
2426
.ret:
2523
.ret:
2427
	ret
2524
	ret
2428
.err:
2525
.err:
2429
	mov	esi, aInvalidBreak
2526
	mov	esi, aInvalidBreak
2430
	jmp	put_message
2527
	jmp	put_message
2431
.listall:
2528
.listall:
2432
	mov	edi, breakpoints
2529
	mov	edi, breakpoints
2433
	xor	eax, eax
2530
	xor	eax, eax
2434
@@:
2531
@@:
2435
	test	byte [edi+4], 1
2532
	test	byte [edi+4], 1
2436
	jz	.cont
2533
	jz	.cont
2437
	push	edi eax
2534
	push	edi eax
2438
	call	show_break_info
2535
	call	show_break_info
2439
	pop	eax edi
2536
	pop	eax edi
2440
.cont:
2537
.cont:
2441
	add	edi, 6
2538
	add	edi, 6
2442
	inc	eax
2539
	inc	eax
2443
	cmp	eax, breakpoints_n
2540
	cmp	eax, breakpoints_n
2444
	jb	@b
2541
	jb	@b
2445
	ret
2542
	ret
2446
 
2543
 
2447
show_break_info:
2544
show_break_info:
2448
	push	edi
2545
	push	edi
2449
	test	byte [edi+4], 8
2546
	test	byte [edi+4], 8
2450
	jnz	.dr
2547
	jnz	.dr
2451
	push	dword [edi]
2548
	push	dword [edi]
2452
	push	eax
2549
	push	eax
2453
	mov	esi, aBreakNum
2550
	mov	esi, aBreakNum
2454
	call	put_message_nodraw
2551
	call	put_message_nodraw
2455
	jmp	.cmn
2552
	jmp	.cmn
2456
.dr:
2553
.dr:
2457
	push	eax
2554
	push	eax
2458
	mov	esi, aMemBreak1
2555
	mov	esi, aMemBreak1
2459
	call	put_message_nodraw
2556
	call	put_message_nodraw
2460
	pop	edi
2557
	pop	edi
2461
	push	edi
2558
	push	edi
2462
	mov	esi, aMemBreak2
2559
	mov	esi, aMemBreak2
2463
	test	byte [edi+5], 2
2560
	test	byte [edi+5], 2
2464
	jz	@f
2561
	jz	@f
2465
	mov	esi, aMemBreak3
2562
	mov	esi, aMemBreak3
2466
@@:
2563
@@:
2467
	call	put_message_nodraw
2564
	call	put_message_nodraw
2468
	pop	edi
2565
	pop	edi
2469
	push	edi
2566
	push	edi
2470
	mov	esi, aMemBreak6
2567
	mov	esi, aMemBreak6
2471
	test	byte [edi+5], 8
2568
	test	byte [edi+5], 8
2472
	jnz	@f
2569
	jnz	@f
2473
	mov	esi, aMemBreak5
2570
	mov	esi, aMemBreak5
2474
	test	byte [edi+5], 4
2571
	test	byte [edi+5], 4
2475
	jnz	@f
2572
	jnz	@f
2476
	mov	esi, aMemBreak4
2573
	mov	esi, aMemBreak4
2477
@@:
2574
@@:
2478
	call	put_message_nodraw
2575
	call	put_message_nodraw
2479
	pop	edi
2576
	pop	edi
2480
	push	edi
2577
	push	edi
2481
	push	dword [edi]
2578
	push	dword [edi]
2482
	mov	esi, aMemBreak7
2579
	mov	esi, aMemBreak7
2483
	call	put_message_nodraw
2580
	call	put_message_nodraw
2484
.cmn:
2581
.cmn:
2485
	pop	edi
2582
	pop	edi
2486
	test	byte [edi+4], 2
2583
	test	byte [edi+4], 2
2487
	jz	@f
2584
	jz	@f
2488
	push	edi
2585
	push	edi
2489
	mov	esi, aDisabled
2586
	mov	esi, aDisabled
2490
	call	put_message_nodraw
2587
	call	put_message_nodraw
2491
	pop	edi
2588
	pop	edi
2492
@@:
2589
@@:
2493
	test	byte [edi+4], 4
2590
	test	byte [edi+4], 4
2494
	jz	@f
2591
	jz	@f
2495
	mov	esi, aOneShot
2592
	mov	esi, aOneShot
2496
	call	put_message_nodraw
2593
	call	put_message_nodraw
2497
@@:
2594
@@:
2498
	mov	esi, newline
2595
	mov	esi, newline
2499
	jmp	put_message
2596
	jmp	put_message
2500
 
2597
 
2501
add_breakpoint:
2598
add_breakpoint:
2502
; in: eax=address, bl=flags
2599
; in: eax=address, bl=flags
2503
; out: CF=1 => error, CF=0 => eax=breakpoint number
2600
; out: CF=1 => error, CF=0 => eax=breakpoint number
2504
	xor	ecx, ecx
2601
	xor	ecx, ecx
2505
	mov	edi, breakpoints
2602
	mov	edi, breakpoints
2506
@@:
2603
@@:
2507
	test	byte [edi+4], 1
2604
	test	byte [edi+4], 1
2508
	jz	.found
2605
	jz	.found
2509
	add	edi, 6
2606
	add	edi, 6
2510
	inc	ecx
2607
	inc	ecx
2511
	cmp	ecx, breakpoints_n
2608
	cmp	ecx, breakpoints_n
2512
	jb	@b
2609
	jb	@b
2513
	stc
2610
	stc
2514
	ret
2611
	ret
2515
.found:
2612
.found:
2516
	stosd
2613
	stosd
2517
	xchg	eax, ecx
2614
	xchg	eax, ecx
2518
	mov	[edi], bl
2615
	mov	[edi], bl
2519
	test	bl, 2
2616
	test	bl, 2
2520
	jnz	@f
2617
	jnz	@f
2521
	or	byte [edi], 2
2618
	or	byte [edi], 2
2522
	push	eax
2619
	push	eax
2523
	call	enable_breakpoint
2620
	call	enable_breakpoint
2524
	pop	eax
2621
	pop	eax
2525
@@:
2622
@@:
2526
	clc
2623
	clc
2527
	ret
2624
	ret
2528
 
2625
 
2529
clear_breakpoint:
2626
clear_breakpoint:
2530
	cmp	eax, breakpoints_n
2627
	cmp	eax, breakpoints_n
2531
	jae	.ret
2628
	jae	.ret
2532
	mov	ecx, 4
2629
	mov	ecx, 4
2533
	inc	eax
2630
	inc	eax
2534
.1:
2631
.1:
2535
	cmp	[drx_break-4+ecx*4], eax
2632
	cmp	[drx_break-4+ecx*4], eax
2536
	jnz	@f
2633
	jnz	@f
2537
	and	[drx_break-4+ecx*4], 0
2634
	and	[drx_break-4+ecx*4], 0
2538
@@:	loop	.1
2635
@@:	loop	.1
2539
	dec	eax
2636
	dec	eax
2540
	push	eax
2637
	push	eax
2541
	add	eax, eax
2638
	add	eax, eax
2542
	lea	edi, [breakpoints + eax + eax*2 + 4]
2639
	lea	edi, [breakpoints + eax + eax*2 + 4]
2543
	test	byte [edi], 1
2640
	test	byte [edi], 1
2544
	pop	eax
2641
	pop	eax
2545
	jz	.ret
2642
	jz	.ret
2546
	push	edi
2643
	push	edi
2547
	call	disable_breakpoint
2644
	call	disable_breakpoint
2548
	pop	edi
2645
	pop	edi
2549
	mov	byte [edi], 0
2646
	mov	byte [edi], 0
2550
.ret:
2647
.ret:
2551
	ret
2648
	ret
2552
 
2649
 
2553
disable_breakpoint:
2650
disable_breakpoint:
2554
	cmp	eax, breakpoints_n
2651
	cmp	eax, breakpoints_n
2555
	jae	.ret
2652
	jae	.ret
2556
	add	eax, eax
2653
	add	eax, eax
2557
	lea	edi, [breakpoints + eax + eax*2 + 5]
2654
	lea	edi, [breakpoints + eax + eax*2 + 5]
2558
	test	byte [edi-1], 1
2655
	test	byte [edi-1], 1
2559
	jz	.ret
2656
	jz	.ret
2560
	test	byte [edi-1], 2
2657
	test	byte [edi-1], 2
2561
	jnz	.ret
2658
	jnz	.ret
2562
	or	byte [edi-1], 2
2659
	or	byte [edi-1], 2
2563
	test	byte [edi-1], 8
2660
	test	byte [edi-1], 8
2564
	jnz	.dr
2661
	jnz	.dr
2565
	push	esi
2662
	push	esi
2566
	push	7
2663
	push	7
2567
	pop	ebx
2664
	pop	ebx
2568
	push	69
2665
	push	69
2569
	pop	eax
2666
	pop	eax
2570
	mov	ecx, [debuggee_pid]
2667
	mov	ecx, [debuggee_pid]
2571
	xor	edx, edx
2668
	xor	edx, edx
2572
	inc	edx
2669
	inc	edx
2573
	mov	esi, [edi-5]
2670
	mov	esi, [edi-5]
2574
	mcall
2671
	mcall
2575
	pop	esi
2672
	pop	esi
2576
.ret:
2673
.ret:
2577
	ret
2674
	ret
2578
.dr:
2675
.dr:
2579
	mov	dl, [edi]
2676
	mov	dl, [edi]
2580
	shr	dl, 6
2677
	shr	dl, 6
2581
	mov	dh, 80h
2678
	mov	dh, 80h
2582
	push	69
2679
	push	69
2583
	pop	eax
2680
	pop	eax
2584
	push	9
2681
	push	9
2585
	pop	ebx
2682
	pop	ebx
2586
	mov	ecx, [debuggee_pid]
2683
	mov	ecx, [debuggee_pid]
2587
	mcall
2684
	mcall
2588
	ret
2685
	ret
2589
 
2686
 
2590
enable_breakpoint:
2687
enable_breakpoint:
2591
	push	esi
2688
	push	esi
2592
	cmp	eax, breakpoints_n
2689
	cmp	eax, breakpoints_n
2593
	jae	.ret
2690
	jae	.ret
2594
	add	eax, eax
2691
	add	eax, eax
2595
	lea	edi, [breakpoints + eax + eax*2 + 5]
2692
	lea	edi, [breakpoints + eax + eax*2 + 5]
2596
	test	byte [edi-1], 1
2693
	test	byte [edi-1], 1
2597
	jz	.ret
2694
	jz	.ret
2598
	test	byte [edi-1], 2
2695
	test	byte [edi-1], 2
2599
	jz	.ret
2696
	jz	.ret
2600
	and	byte [edi-1], not 2
2697
	and	byte [edi-1], not 2
2601
	test	byte [edi-1], 8
2698
	test	byte [edi-1], 8
2602
	jnz	.dr
2699
	jnz	.dr
2603
	push	6
2700
	push	6
2604
	pop	ebx
2701
	pop	ebx
2605
	push	69
2702
	push	69
2606
	pop	eax
2703
	pop	eax
2607
	mov	esi, [edi-5]
2704
	mov	esi, [edi-5]
2608
	mov	ecx, [debuggee_pid]
2705
	mov	ecx, [debuggee_pid]
2609
	xor	edx, edx
2706
	xor	edx, edx
2610
	inc	edx
2707
	inc	edx
2611
	mcall
2708
	mcall
2612
	dec	eax
2709
	dec	eax
2613
	jnz	.err
2710
	jnz	.err
2614
	mov	al, 69
2711
	mov	al, 69
2615
	push	0xCC
2712
	push	0xCC
2616
	mov	edi, esp
2713
	mov	edi, esp
2617
	inc	ebx
2714
	inc	ebx
2618
	mcall
2715
	mcall
2619
	pop	eax
2716
	pop	eax
2620
.ret:
2717
.ret:
2621
	pop	esi
2718
	pop	esi
2622
	ret
2719
	ret
2623
.err:
2720
.err:
2624
	or	byte [edi-1], 2
2721
	or	byte [edi-1], 2
2625
	mov	esi, aBreakErr
2722
	mov	esi, aBreakErr
2626
	call	put_message
2723
	call	put_message
2627
	pop	esi
2724
	pop	esi
2628
	ret
2725
	ret
2629
.dr:
2726
.dr:
2630
	push	9
2727
	push	9
2631
	pop	ebx
2728
	pop	ebx
2632
	push	69
2729
	push	69
2633
	pop	eax
2730
	pop	eax
2634
	mov	esi, [edi-5]
2731
	mov	esi, [edi-5]
2635
	mov	ecx, [debuggee_pid]
2732
	mov	ecx, [debuggee_pid]
2636
	mov	dl, [edi]
2733
	mov	dl, [edi]
2637
	shr	dl, 6
2734
	shr	dl, 6
2638
	mov	dh, [edi]
2735
	mov	dh, [edi]
2639
	and	dh, 0xF
2736
	and	dh, 0xF
2640
	mcall
2737
	mcall
2641
	test	eax, eax
2738
	test	eax, eax
2642
	jnz	.err
2739
	jnz	.err
2643
	pop	esi
2740
	pop	esi
2644
	ret
2741
	ret
2645
 
2742
 
2646
find_breakpoint:
2743
find_breakpoint:
2647
	xor	ecx, ecx
2744
	xor	ecx, ecx
2648
	xchg	eax, ecx
2745
	xchg	eax, ecx
2649
	mov	edi, breakpoints
2746
	mov	edi, breakpoints
2650
@@:
2747
@@:
2651
	test	byte [edi+4], 1
2748
	test	byte [edi+4], 1
2652
	jz	.cont
2749
	jz	.cont
2653
	test	byte [edi+4], 8
2750
	test	byte [edi+4], 8
2654
	jnz	.cont
2751
	jnz	.cont
2655
	cmp	[edi], ecx
2752
	cmp	[edi], ecx
2656
	jz	.found
2753
	jz	.found
2657
.cont:
2754
.cont:
2658
	add	edi, 6
2755
	add	edi, 6
2659
	inc	eax
2756
	inc	eax
2660
	cmp	eax, breakpoints_n
2757
	cmp	eax, breakpoints_n
2661
	jb	@b
2758
	jb	@b
2662
	or	eax, -1
2759
	or	eax, -1
2663
.found:
2760
.found:
2664
	ret
2761
	ret
2665
 
2762
 
2666
find_enabled_breakpoint:
2763
find_enabled_breakpoint:
2667
	xor	ecx, ecx
2764
	xor	ecx, ecx
2668
	xchg	eax, ecx
2765
	xchg	eax, ecx
2669
	mov	edi, breakpoints
2766
	mov	edi, breakpoints
2670
@@:
2767
@@:
2671
	test	byte [edi+4], 1
2768
	test	byte [edi+4], 1
2672
	jz	.cont
2769
	jz	.cont
2673
	test	byte [edi+4], 2 or 8
2770
	test	byte [edi+4], 2 or 8
2674
	jnz	.cont
2771
	jnz	.cont
2675
	cmp	[edi], ecx
2772
	cmp	[edi], ecx
2676
	jz	.found
2773
	jz	.found
2677
.cont:
2774
.cont:
2678
	add	edi, 6
2775
	add	edi, 6
2679
	inc	eax
2776
	inc	eax
2680
	cmp	eax, breakpoints_n
2777
	cmp	eax, breakpoints_n
2681
	jb	@b
2778
	jb	@b
2682
	or	eax, -1
2779
	or	eax, -1
2683
.found:
2780
.found:
2684
	ret
2781
	ret
2685
 
2782
 
2686
OnUnpack:
2783
OnUnpack:
2687
; program must be loaded - checked when command was parsed
2784
; program must be loaded - checked when command was parsed
2688
; program must be stopped
2785
; program must be stopped
2689
	mov	esi, aRunningErr
2786
	mov	esi, aRunningErr
2690
	cmp	[bSuspended], 0
2787
	cmp	[bSuspended], 0
2691
	jz	put_message
2788
	jz	put_message
2692
; all breakpoints must be disabled
2789
; all breakpoints must be disabled
2693
	mov	edi, breakpoints
2790
	mov	edi, breakpoints
2694
@@:
2791
@@:
2695
	test	byte [edi+4], 1
2792
	test	byte [edi+4], 1
2696
	jz	.cont
2793
	jz	.cont
2697
	test	byte [edi+4], 2
2794
	test	byte [edi+4], 2
2698
	jnz	.cont
2795
	jnz	.cont
2699
	mov	esi, aEnabledBreakErr
2796
	mov	esi, aEnabledBreakErr
2700
	jmp	put_message
2797
	jmp	put_message
2701
.cont:
2798
.cont:
2702
	add	edi, 6
2799
	add	edi, 6
2703
	cmp	edi, breakpoints+breakpoints_n*6
2800
	cmp	edi, breakpoints+breakpoints_n*6
2704
	jb	@b
2801
	jb	@b
2705
; ok, now do it
2802
; ok, now do it
2706
; set breakpoint on 0xC dword access
2803
; set breakpoint on 0xC dword access
2707
	push	9
2804
	push	9
2708
	pop	ebx
2805
	pop	ebx
2709
	mov	ecx, [debuggee_pid]
2806
	mov	ecx, [debuggee_pid]
2710
	mov	dx, 1111b*256
2807
	mov	dx, 1111b*256
2711
	push	0xC
2808
	push	0xC
2712
	pop	esi
2809
	pop	esi
2713
@@:
2810
@@:
2714
	push	69
2811
	push	69
2715
	pop	eax
2812
	pop	eax
2716
	mcall
2813
	mcall
2717
	test	eax, eax
2814
	test	eax, eax
2718
	jz	.breakok
2815
	jz	.breakok
2719
	inc	edx
2816
	inc	edx
2720
	cmp	dl, 4
2817
	cmp	dl, 4
2721
	jb	@b
2818
	jb	@b
2722
.breakok:
2819
.breakok:
2723
	call	GoOn
2820
	call	GoOn
2724
; now wait for event
2821
; now wait for event
2725
.wait:
2822
.wait:
2726
	push	10
2823
	push	10
2727
	pop	eax
2824
	pop	eax
2728
	mcall
2825
	mcall
2729
	dec	eax
2826
	dec	eax
2730
	jz	.redraw
2827
	jz	.redraw
2731
	dec	eax
2828
	dec	eax
2732
	jz	.key
2829
	jz	.key
2733
	dec	eax
2830
	dec	eax
2734
	jnz	.debug
2831
	jnz	.debug
2735
; button; we have only one button, close
2832
; button; we have only one button, close
2736
	or	eax, -1
2833
	or	eax, -1
2737
	mcall
2834
	mcall
2738
.redraw:
2835
.redraw:
2739
	call	draw_window
2836
	call	draw_window
2740
	jmp	.wait
2837
	jmp	.wait
2741
.key:
2838
.key:
2742
	mov	al, 2
2839
	mov	al, 2
2743
	mcall
2840
	mcall
2744
	cmp	ah, 3	; Ctrl+C
2841
	cmp	ah, 3	; Ctrl+C
2745
	jnz	.wait
2842
	jnz	.wait
2746
.userbreak:
2843
.userbreak:
2747
	mov	esi, aInterrupted
2844
	mov	esi, aInterrupted
2748
.x1:
2845
.x1:
2749
	push	edx esi
2846
	push	edx esi
2750
	call	put_message
2847
	call	put_message
2751
	pop	esi edx
2848
	pop	esi edx
2752
	or	dh, 80h
2849
	or	dh, 80h
2753
	push	69
2850
	push	69
2754
	pop	eax
2851
	pop	eax
2755
	push	9
2852
	push	9
2756
	pop	ebx
2853
	pop	ebx
2757
	mov	ecx, [debuggee_pid]
2854
	mov	ecx, [debuggee_pid]
2758
	mcall
2855
	mcall
2759
	cmp	esi, aUnpacked
2856
	cmp	esi, aUnpacked
2760
	jnz	OnSuspend
2857
	jnz	OnSuspend
2761
	jmp	AfterSuspend
2858
	jmp	AfterSuspend
2762
.debug:
2859
.debug:
2763
	cmp	[dbgbuflen], 4*3
2860
	cmp	[dbgbuflen], 4*3
2764
	jnz	.notour
2861
	jnz	.notour
2765
	cmp	dword [dbgbuf], 3
2862
	cmp	dword [dbgbuf], 3
2766
	jnz	.notour
2863
	jnz	.notour
2767
	test	byte [dbgbuf+8], 1
2864
	test	byte [dbgbuf+8], 1
2768
	jnz	.our
2865
	jnz	.our
2769
.notour:
2866
.notour:
2770
	mov	esi, aInterrupted
2867
	mov	esi, aInterrupted
2771
	push	edx
2868
	push	edx
2772
	call	put_message
2869
	call	put_message
2773
	pop	edx
2870
	pop	edx
2774
	or	dh, 80h
2871
	or	dh, 80h
2775
	push	69
2872
	push	69
2776
	pop	eax
2873
	pop	eax
2777
	push	9
2874
	push	9
2778
	pop	ebx
2875
	pop	ebx
2779
	mov	ecx, [debuggee_pid]
2876
	mov	ecx, [debuggee_pid]
2780
	mcall
2877
	mcall
2781
	jmp	debugmsg
2878
	jmp	debugmsg
2782
.our:
2879
.our:
2783
	and	[dbgbuflen], 0
2880
	and	[dbgbuflen], 0
2784
	push	edx
2881
	push	edx
2785
	call	get_context
2882
	call	get_context
2786
	push	eax
2883
	push	eax
2787
	mov	al, 69
2884
	mov	al, 69
2788
	mov	bl, 6
2885
	mov	bl, 6
2789
	mov	ecx, [debuggee_pid]
2886
	mov	ecx, [debuggee_pid]
2790
	mov	edi, esp
2887
	mov	edi, esp
2791
	push	4
2888
	push	4
2792
	pop	edx
2889
	pop	edx
2793
	push	0xC
2890
	push	0xC
2794
	pop	esi
2891
	pop	esi
2795
	mcall
2892
	mcall
2796
	pop	eax
2893
	pop	eax
2797
	pop	edx
2894
	pop	edx
2798
	cmp	eax, [_eip]
2895
	cmp	eax, [_eip]
2799
	jz	.done
2896
	jz	.done
2800
	call	DoResume
2897
	call	DoResume
2801
	jmp	.wait
2898
	jmp	.wait
2802
.done:
2899
.done:
2803
	mov	esi, aUnpacked
2900
	mov	esi, aUnpacked
2804
	jmp	.x1
2901
	jmp	.x1
-
 
2902
 
-
 
2903
include 'sort.inc'
-
 
2904
compare:
-
 
2905
	cmpsd
-
 
2906
	jnz	@f
-
 
2907
	cmp	esi, edi
-
 
2908
@@:	ret
-
 
2909
compare2:
-
 
2910
	cmpsd
-
 
2911
@@:
-
 
2912
	cmpsb
-
 
2913
	jnz	@f
-
 
2914
	cmp	byte [esi], 0
-
 
2915
	jnz	@b
-
 
2916
	cmp	esi, edi
-
 
2917
@@:
-
 
2918
	ret
-
 
2919
 
-
 
2920
free_symbols:
-
 
2921
	mov	ecx, [symbols]
-
 
2922
	jecxz	@f
-
 
2923
	mcall	68, 13
-
 
2924
	and	[symbols], 0
-
 
2925
	and	[num_symbols], 0
-
 
2926
@@:
-
 
2927
	ret
-
 
2928
 
-
 
2929
OnLoadSymbols.fileerr:
-
 
2930
	test	ebp, ebp
-
 
2931
	jz	@f
-
 
2932
	mcall	68, 13, edi
-
 
2933
	ret
-
 
2934
@@:
-
 
2935
	push	eax
-
 
2936
	mcall	68, 13, edi
-
 
2937
	mov	esi, aCannotLoadFile
-
 
2938
	call	put_message_nodraw
-
 
2939
	pop	eax
-
 
2940
	cmp	eax, 0x20
-
 
2941
	jae	.unk
-
 
2942
	mov	esi, [load_err_msgs + eax*4]
-
 
2943
	test	esi, esi
-
 
2944
	jnz	put_message
-
 
2945
.unk:
-
 
2946
	mov	esi, unk_err_msg2
-
 
2947
	jmp	put_message
-
 
2948
 
-
 
2949
OnLoadSymbols:
-
 
2950
	xor	ebp, ebp
-
 
2951
; load input file
-
 
2952
	mov	esi, [curarg]
-
 
2953
	call	free_symbols
-
 
2954
.silent:
-
 
2955
	xor	edi, edi
-
 
2956
	cmp	[num_symbols], edi
-
 
2957
	jz	@f
-
 
2958
	ret
-
 
2959
@@:
-
 
2960
	mov	ebx, fn70_attr_block
-
 
2961
	mov	[ebx+21], esi
-
 
2962
	mcall	70
-
 
2963
	test	eax, eax
-
 
2964
	jnz	.fileerr
-
 
2965
	cmp	dword [fileattr+36], edi
-
 
2966
	jnz	.memerr
-
 
2967
	mov	ecx, dword [fileattr+32]
-
 
2968
	mcall	68, 12
-
 
2969
	test	eax, eax
-
 
2970
	jz	.memerr
-
 
2971
	mov	edi, eax
-
 
2972
	mov	ebx, fn70_read_block
-
 
2973
	mov	[ebx+12], ecx
-
 
2974
	mov	[ebx+16], edi
-
 
2975
	mov	[ebx+21], esi
-
 
2976
	mcall	70
-
 
2977
	test	eax, eax
-
 
2978
	jnz	.fileerr
-
 
2979
; calculate memory requirements
-
 
2980
	lea	edx, [ecx+edi-1]	; edx = EOF-1
-
 
2981
	mov	esi, edi
-
 
2982
	xor	ecx, ecx
-
 
2983
.calcloop:
-
 
2984
	cmp	esi, edx
-
 
2985
	jae	.calcdone
-
 
2986
	cmp	word [esi], '0x'
-
 
2987
	jnz	.skipline
-
 
2988
	inc	esi
-
 
2989
	inc	esi
-
 
2990
@@:
-
 
2991
	cmp	esi, edx
-
 
2992
	jae	.calcdone
-
 
2993
	lodsb
-
 
2994
	or	al, 20h
-
 
2995
	sub	al, '0'
-
 
2996
	cmp	al, 9
-
 
2997
	jbe	@b
-
 
2998
	sub	al, 'a'-'0'-10
-
 
2999
	cmp	al, 15
-
 
3000
	jbe	@b
-
 
3001
	dec	esi
-
 
3002
@@:
-
 
3003
	cmp	esi, edx
-
 
3004
	ja	.calcdone
-
 
3005
	lodsb
-
 
3006
	cmp	al, 20h
-
 
3007
	jz	@b
-
 
3008
	jb	.calcloop
-
 
3009
	cmp	al, 9
-
 
3010
	jz	@b
-
 
3011
	add	ecx, 12+1
-
 
3012
	inc	[num_symbols]
-
 
3013
@@:
-
 
3014
	inc	ecx
-
 
3015
	cmp	esi, edx
-
 
3016
	ja	.calcdone
-
 
3017
	lodsb
-
 
3018
	cmp	al, 0xD
-
 
3019
	jz	.calcloop
-
 
3020
	cmp	al, 0xA
-
 
3021
	jz	.calcloop
-
 
3022
	jmp	@b
-
 
3023
.skipline:
-
 
3024
	cmp	esi, edx
-
 
3025
	jae	.calcdone
-
 
3026
	lodsb
-
 
3027
	cmp	al, 0xD
-
 
3028
	jz	.calcloop
-
 
3029
	cmp	al, 0xA
-
 
3030
	jz	.calcloop
-
 
3031
	jmp	.skipline
-
 
3032
.calcdone:
-
 
3033
	mcall	68, 12
-
 
3034
	test	eax, eax
-
 
3035
	jnz	.memok
-
 
3036
	inc	ebx
-
 
3037
	mov	ecx, edi
-
 
3038
	mov	al, 68
-
 
3039
	mcall
-
 
3040
.memerr:
-
 
3041
	mov	esi, aNoMemory
-
 
3042
	jmp	put_message
-
 
3043
.memok:
-
 
3044
	mov	[symbols], eax
-
 
3045
	mov	ebx, eax
-
 
3046
	push	edi
-
 
3047
	mov	esi, edi
-
 
3048
	mov	edi, [num_symbols]
-
 
3049
	lea	ebp, [eax+edi*4]
-
 
3050
	lea	edi, [eax+edi*8]
-
 
3051
; parse input data, esi->input, edx->EOF, ebx->ptrs, edi->names
-
 
3052
.readloop:
-
 
3053
	cmp	esi, edx
-
 
3054
	jae	.readdone
-
 
3055
	cmp	word [esi], '0x'
-
 
3056
	jnz	.readline
-
 
3057
	inc	esi
-
 
3058
	inc	esi
-
 
3059
	xor	eax, eax
-
 
3060
	xor	ecx, ecx
-
 
3061
@@:
-
 
3062
	shl	ecx, 4
-
 
3063
	add	ecx, eax
-
 
3064
	cmp	esi, edx
-
 
3065
	jae	.readdone
-
 
3066
	lodsb
-
 
3067
	or	al, 20h
-
 
3068
	sub	al, '0'
-
 
3069
	cmp	al, 9
-
 
3070
	jbe	@b
-
 
3071
	sub	al, 'a'-'0'-10
-
 
3072
	cmp	al, 15
-
 
3073
	jbe	@b
-
 
3074
	dec	esi
-
 
3075
@@:
-
 
3076
	cmp	esi, edx
-
 
3077
	ja	.readdone
-
 
3078
	lodsb
-
 
3079
	cmp	al, 20h
-
 
3080
	jz	@b
-
 
3081
	jb	.readloop
-
 
3082
	cmp	al, 9
-
 
3083
	jz	@b
-
 
3084
	mov	dword [ebx], edi
-
 
3085
	add	ebx, 4
-
 
3086
	mov	dword [ebp], edi
-
 
3087
	add	ebp, 4
-
 
3088
	mov	dword [edi], ecx
-
 
3089
	add	edi, 4
-
 
3090
	stosb
-
 
3091
@@:
-
 
3092
	xor	eax, eax
-
 
3093
	stosb
-
 
3094
	cmp	esi, edx
-
 
3095
	ja	.readdone
-
 
3096
	lodsb
-
 
3097
	cmp	al, 0xD
-
 
3098
	jz	.readloop
-
 
3099
	cmp	al, 0xA
-
 
3100
	jz	.readloop
-
 
3101
	mov	byte [edi-1], al
-
 
3102
	jmp	@b
-
 
3103
.readline:
-
 
3104
	cmp	esi, edx
-
 
3105
	jae	.readdone
-
 
3106
	lodsb
-
 
3107
	cmp	al, 0xD
-
 
3108
	jz	.readloop
-
 
3109
	cmp	al, 0xA
-
 
3110
	jz	.readloop
-
 
3111
	jmp	.readline
-
 
3112
.readdone:
-
 
3113
	pop	ecx
-
 
3114
	mcall	68, 13
-
 
3115
	mov	ecx, [num_symbols]
-
 
3116
	mov	edx, [symbols]
-
 
3117
	mov	ebx, compare
-
 
3118
	call	sort
-
 
3119
	mov	ecx, [num_symbols]
-
 
3120
	lea	edx, [edx+ecx*4]
-
 
3121
	mov	ebx, compare2
-
 
3122
	call	sort
-
 
3123
	mov	esi, aSymbolsLoaded
-
 
3124
	call	put_message
-
 
3125
	jmp	redraw_disasm
-
 
3126
 
-
 
3127
find_symbol:
-
 
3128
; in: eax=address
-
 
3129
; out: esi, CF
-
 
3130
	cmp	[num_symbols], 0
-
 
3131
	jnz	@f
-
 
3132
.ret0:
-
 
3133
	xor	esi, esi
-
 
3134
	stc
-
 
3135
	ret
-
 
3136
@@:
-
 
3137
	push	ebx ecx edx
-
 
3138
	xor	edx, edx
-
 
3139
	mov	esi, [symbols]
-
 
3140
	mov	ecx, [num_symbols]
-
 
3141
	mov	ebx, [esi]
-
 
3142
	cmp	[ebx], eax
-
 
3143
	jz	.donez
-
 
3144
	jb	@f
-
 
3145
	pop	edx ecx ebx
-
 
3146
	jmp	.ret0
-
 
3147
@@:
-
 
3148
; invariant: symbols_addr[edx] < eax < symbols_addr[ecx]
-
 
3149
.0:
-
 
3150
	push	edx
-
 
3151
.1:
-
 
3152
	add	edx, ecx
-
 
3153
	sar	edx, 1
-
 
3154
	cmp	edx, [esp]
-
 
3155
	jz	.done2
-
 
3156
	mov	ebx, [esi+edx*4]
-
 
3157
	cmp	[ebx], eax
-
 
3158
	jz	.done
-
 
3159
	ja	.2
-
 
3160
	mov	[esp], edx
-
 
3161
	jmp	.1
-
 
3162
.2:
-
 
3163
	mov	ecx, edx
-
 
3164
	pop	edx
-
 
3165
	jmp	.0
-
 
3166
.donecont:
-
 
3167
	dec	edx
-
 
3168
.done:
-
 
3169
	test	edx, edx
-
 
3170
	jz	@f
-
 
3171
	mov	ebx, [esi+edx*4-4]
-
 
3172
	cmp	[ebx], eax
-
 
3173
	jz	.donecont
-
 
3174
@@:
-
 
3175
	pop	ecx
-
 
3176
.donez:
-
 
3177
	mov	esi, [esi+edx*4]
-
 
3178
	add	esi, 4
-
 
3179
	pop	edx ecx ebx
-
 
3180
	clc
-
 
3181
	ret
-
 
3182
.done2:
-
 
3183
	lea	esi, [esi+edx*4]
-
 
3184
	pop	ecx edx ecx ebx
-
 
3185
	stc
-
 
3186
	ret
-
 
3187
 
-
 
3188
find_symbol_name:
-
 
3189
; in: esi->name
-
 
3190
; out: if found: CF clear, eax=value
-
 
3191
;      otherwise CF set
-
 
3192
	cmp	[num_symbols], 0
-
 
3193
	jnz	@f
-
 
3194
.stc_ret:
-
 
3195
	stc
-
 
3196
	ret
-
 
3197
@@:
-
 
3198
	push	ebx ecx edx edi
-
 
3199
	push	-1
-
 
3200
	pop	edx
-
 
3201
	mov	ebx, [symbols]
-
 
3202
	mov	ecx, [num_symbols]
-
 
3203
	lea	ebx, [ebx+ecx*4]
-
 
3204
; invariant: symbols_name[edx] < name < symbols_name[ecx]
-
 
3205
.0:
-
 
3206
	push	edx
-
 
3207
.1:
-
 
3208
	add	edx, ecx
-
 
3209
	sar	edx, 1
-
 
3210
	cmp	edx, [esp]
-
 
3211
	jz	.done2
-
 
3212
	call	.cmp
-
 
3213
	jz	.done
-
 
3214
	jb	.2
-
 
3215
	mov	[esp], edx
-
 
3216
	jmp	.1
-
 
3217
.2:
-
 
3218
	mov	ecx, edx
-
 
3219
	pop	edx
-
 
3220
	jmp	.0
-
 
3221
.done:
-
 
3222
	pop	ecx
-
 
3223
.donez:
-
 
3224
	mov	eax, [ebx+edx*4]
-
 
3225
	mov	eax, [eax]
-
 
3226
	pop	edi edx ecx ebx
-
 
3227
	clc
-
 
3228
	ret
-
 
3229
.done2:
-
 
3230
	pop	edx edi edx ecx ebx
-
 
3231
	stc
-
 
3232
	ret
-
 
3233
 
-
 
3234
.cmp:
-
 
3235
	mov	edi, [ebx+edx*4]
-
 
3236
	push	esi
-
 
3237
	add	edi, 4
-
 
3238
@@:
-
 
3239
	cmpsb
-
 
3240
	jnz	@f
-
 
3241
	cmp	byte [esi-1], 0
-
 
3242
	jnz	@b
-
 
3243
@@:
-
 
3244
	pop	esi
-
 
3245
	ret
-
 
3246
 
-
 
3247
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
3248
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DISASSEMBLER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
3249
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2805
 
3250
 
2806
disasm_get_byte:
3251
disasm_get_byte:
2807
; out: al=byte
3252
; out: al=byte
2808
	push	ecx
3253
	push	ecx
2809
	mov	ecx, [disasm_cur_pos]
3254
	mov	ecx, [disasm_cur_pos]
2810
	sub	ecx, [disasm_start_pos]
3255
	sub	ecx, [disasm_start_pos]
2811
	cmp	ecx, [disasm_buf_size]
3256
	cmp	ecx, [disasm_buf_size]
2812
	jae	disasm_err
3257
	jae	disasm_err
2813
	mov	al, [disasm_buffer+ecx]
3258
	mov	al, [disasm_buffer+ecx]
2814
	pop	ecx
3259
	pop	ecx
2815
	inc	[disasm_cur_pos]
3260
	inc	[disasm_cur_pos]
2816
	ret
3261
	ret
2817
disasm_get_word:
3262
disasm_get_word:
2818
	push	ecx
3263
	push	ecx
2819
	mov	ecx, [disasm_cur_pos]
3264
	mov	ecx, [disasm_cur_pos]
2820
	sub	ecx, [disasm_start_pos]
3265
	sub	ecx, [disasm_start_pos]
2821
	inc	ecx
3266
	inc	ecx
2822
	cmp	ecx, [disasm_buf_size]
3267
	cmp	ecx, [disasm_buf_size]
2823
	jae	disasm_err
3268
	jae	disasm_err
2824
	mov	ax, word [disasm_buffer-1+ecx]
3269
	mov	ax, word [disasm_buffer-1+ecx]
2825
	pop	ecx
3270
	pop	ecx
2826
	add	[disasm_cur_pos], 2
3271
	add	[disasm_cur_pos], 2
2827
	ret
3272
	ret
2828
disasm_get_dword:
3273
disasm_get_dword:
2829
	push	ecx
3274
	push	ecx
2830
	mov	ecx, [disasm_cur_pos]
3275
	mov	ecx, [disasm_cur_pos]
2831
	sub	ecx, [disasm_start_pos]
3276
	sub	ecx, [disasm_start_pos]
2832
	add	ecx, 3
3277
	add	ecx, 3
2833
	cmp	ecx, [disasm_buf_size]
3278
	cmp	ecx, [disasm_buf_size]
2834
	jae	disasm_err
3279
	jae	disasm_err
2835
	mov	eax, dword [disasm_buffer-3+ecx]
3280
	mov	eax, dword [disasm_buffer-3+ecx]
2836
	pop	ecx
3281
	pop	ecx
2837
	add	[disasm_cur_pos], 4
3282
	add	[disasm_cur_pos], 4
2838
	ret
3283
	ret
2839
 
3284
 
2840
disasm_err:
3285
disasm_err:
2841
	mov	esp, ebp
3286
	mov	esp, ebp
2842
stc_ret:
3287
stc_ret:
2843
	stc
3288
	stc
2844
	ret
3289
	ret
2845
disasm_ret:
3290
disasm_ret:
2846
	mov	esp, ebp
3291
	mov	esp, ebp
2847
	and	byte [edi], 0
3292
	and	byte [edi], 0
2848
	ret
3293
	ret
2849
 
3294
 
2850
disasm_instr:
3295
disasm_instr:
2851
	mov	ebp, esp
3296
	mov	ebp, esp
2852
	cmp	[debuggee_pid], 0
3297
	cmp	[debuggee_pid], 0
2853
	jz	stc_ret
3298
	jz	stc_ret
2854
	mov	edi, disasm_string
3299
	mov	edi, disasm_string
2855
	xor	ecx, ecx
3300
	xor	ecx, ecx
2856
; ecx=flags
3301
; ecx=flags
2857
disasm_loop1:
3302
disasm_loop1:
2858
	xor	eax, eax
3303
	xor	eax, eax
2859
	call	disasm_get_byte
3304
	call	disasm_get_byte
2860
	jmp	dword [disasm_table_1 + eax*4]
3305
	jmp	dword [disasm_table_1 + eax*4]
2861
 
3306
 
2862
cop0:
3307
cop0:
2863
clock:
3308
clock:
2864
crepnz:
3309
crepnz:
2865
crep:
3310
crep:
2866
csegcs:
3311
csegcs:
2867
csegds:
3312
csegds:
2868
cseges:
3313
cseges:
2869
csegss:
3314
csegss:
2870
csegfs:
3315
csegfs:
2871
cseggs:
3316
cseggs:
-
 
3317
	mov	esi, cmd1
2872
	call	@f
3318
iglobal
-
 
3319
cmd1:
2873
	db	0x2E,3,'cs:'
3320
	db	0x2E,3,'cs:'
2874
	db	0x36,3,'ss:'
3321
	db	0x36,3,'ss:'
2875
	db	0x3E,3,'ds:'
3322
	db	0x3E,3,'ds:'
2876
	db	0x26,3,'es:'
3323
	db	0x26,3,'es:'
2877
	db	0x64,3,'fs:'
3324
	db	0x64,3,'fs:'
2878
	db	0x65,3,'gs:'
3325
	db	0x65,3,'gs:'
2879
	db	0x06,10,'push    es'
3326
	db	0x06,10,'push    es'
2880
	db	0x07,10,'pop     es'
3327
	db	0x07,10,'pop     es'
2881
	db	0x0E,10,'push    cs'
3328
	db	0x0E,10,'push    cs'
2882
	db	0x16,10,'push    ss'
3329
	db	0x16,10,'push    ss'
2883
	db	0x17,10,'pop     ss'
3330
	db	0x17,10,'pop     ss'
2884
	db	0x1E,10,'push    ds'
3331
	db	0x1E,10,'push    ds'
2885
	db	0x1F,10,'pop     ds'
3332
	db	0x1F,10,'pop     ds'
2886
	db	0x27,3,'daa'
3333
	db	0x27,3,'daa'
2887
	db	0x2F,3,'das'
3334
	db	0x2F,3,'das'
2888
	db	0x37,3,'aaa'
3335
	db	0x37,3,'aaa'
2889
	db	0x3F,3,'aas'
3336
	db	0x3F,3,'aas'
2890
	db	0x60,6,0,'pusha'
3337
	db	0x60,6,0,'pusha'
2891
	db	0x61,5,0,'popa'
3338
	db	0x61,5,0,'popa'
2892
	db	0x90,3,'nop'
3339
	db	0x90,3,'nop'
2893
	db	0x9B,5,'fwait'
3340
	db	0x9B,5,'fwait'
2894
	db	0x9C,6,0,'pushf'
3341
	db	0x9C,6,0,'pushf'
2895
	db	0x9D,5,0,'popf'
3342
	db	0x9D,5,0,'popf'
2896
	db	0x9E,4,'sahf'
3343
	db	0x9E,4,'sahf'
2897
	db	0x9F,4,'lahf'
3344
	db	0x9F,4,'lahf'
2898
	db	0xA4,5,'movsb'
3345
	db	0xA4,5,'movsb'
2899
	db	0xA5,5,0,'movs'
3346
	db	0xA5,5,0,'movs'
2900
	db	0xA6,5,'cmpsb'
3347
	db	0xA6,5,'cmpsb'
2901
	db	0xA7,5,0,'cmps'
3348
	db	0xA7,5,0,'cmps'
2902
	db	0xAA,5,'stosb'
3349
	db	0xAA,5,'stosb'
2903
	db	0xAB,5,0,'stos'
3350
	db	0xAB,5,0,'stos'
2904
	db	0xAC,5,'lodsb'
3351
	db	0xAC,5,'lodsb'
2905
	db	0xAD,5,0,'lods'
3352
	db	0xAD,5,0,'lods'
2906
	db	0xAE,5,'scasb'
3353
	db	0xAE,5,'scasb'
2907
	db	0xAF,5,0,'scas'
3354
	db	0xAF,5,0,'scas'
2908
	db	0xC3,3,'ret'
3355
	db	0xC3,3,'ret'
2909
	db	0xC9,5,'leave'
3356
	db	0xC9,5,'leave'
2910
	db	0xCC,4,'int3'
3357
	db	0xCC,4,'int3'
2911
	db	0xF0,4,'lock'
3358
	db	0xF0,4,'lock'
2912
	db	0xF2,5,'repnz'
3359
	db	0xF2,5,'repnz'
2913
	db	0xF3,6,'rep(z)'
3360
	db	0xF3,6,'rep(z)'
2914
	db	0xF5,3,'cmc'
3361
	db	0xF5,3,'cmc'
2915
	db	0xF8,3,'clc'
3362
	db	0xF8,3,'clc'
2916
	db	0xF9,3,'stc'
3363
	db	0xF9,3,'stc'
2917
	db	0xFA,3,'cli'
3364
	db	0xFA,3,'cli'
2918
	db	0xFB,3,'sti'
3365
	db	0xFB,3,'sti'
2919
	db	0xFC,3,'cld'
3366
	db	0xFC,3,'cld'
2920
	db	0xFD,3,'std'
3367
	db	0xFD,3,'std'
2921
csysenter:
-
 
2922
csyscall:
-
 
2923
ccpuid:
-
 
2924
crdtsc:
3368
cmd2:
2925
	call	@f
-
 
2926
	db	0x05,7,'syscall'
3369
	db	0x05,7,'syscall'
2927
	db	0x31,5,'rdtsc'
3370
	db	0x31,5,'rdtsc'
2928
	db	0x34,8,'sysenter'
3371
	db	0x34,8,'sysenter'
2929
	db	0xA2,5,'cpuid'
3372
	db	0xA2,5,'cpuid'
-
 
3373
	db	0x77,4,'emms'
2930
@@:
3374
endg
2931
	pop	esi
3375
	jmp	@f
-
 
3376
csysenter:
-
 
3377
csyscall:
-
 
3378
ccpuid:
-
 
3379
crdtsc:
-
 
3380
cemms:
-
 
3381
	mov	esi, cmd2
2932
@@:
3382
@@:
2933
	cmp	al, [esi]
3383
	cmp	al, [esi]
2934
	jz	.found
3384
	jz	.found
2935
	inc	esi
3385
	inc	esi
2936
	movzx	edx, byte [esi]
3386
	movzx	edx, byte [esi]
2937
	inc	esi
3387
	inc	esi
2938
	add	esi, edx
3388
	add	esi, edx
2939
	jmp	@b
3389
	jmp	@b
2940
.found:
3390
.found:
2941
	inc	esi
3391
	inc	esi
2942
	lodsb
3392
	lodsb
2943
	cmp	byte [esi], 0
3393
	cmp	byte [esi], 0
2944
	jz	@f
3394
	jz	@f
2945
	movzx	ecx, al
3395
	movzx	ecx, al
2946
disasm_1:
3396
disasm_1:
2947
	rep	movsb
3397
	rep	movsb
2948
	and	byte [edi], 0
3398
	and	byte [edi], 0
2949
	ret
3399
	ret
2950
@@:
3400
@@:
2951
	mov	dl, ch
3401
	mov	dl, ch
2952
	movzx	ecx, al
3402
	movzx	ecx, al
2953
	dec	ecx
3403
	dec	ecx
2954
	inc	esi
3404
	inc	esi
2955
	rep	movsb
3405
	rep	movsb
2956
	test	dl, 1
3406
	test	dl, 1
2957
	mov	al, 'w'
3407
	mov	al, 'w'
2958
	jnz	@f
3408
	jnz	@f
2959
	mov	al, 'd'
3409
	mov	al, 'd'
2960
@@:	stosb
3410
@@:	stosb
2961
	and	byte [edi], 0
3411
	and	byte [edi], 0
2962
	ret
3412
	ret
2963
 
3413
 
2964
c67:
3414
c67:
2965
	or	ch, 2
3415
	or	ch, 2
2966
	jmp	disasm_loop1
3416
	jmp	disasm_loop1
2967
c66:
3417
c66:
2968
	or	ch, 1
3418
	or	ch, 1
2969
	jmp	disasm_loop1
3419
	jmp	disasm_loop1
2970
 
3420
 
2971
center:
3421
center:
2972
caam:
3422
caam:
2973
cxlat:
3423
cxlat:
2974
ccmpxchg:
3424
ccmpxchg:
2975
cbsf:
3425
cbsf:
2976
cbsr:
3426
cbsr:
2977
ccmpxchg8b:
3427
ccmpxchg8b:
2978
cunk:
3428
cunk:
2979
cerr:
3429
cerr:
2980
	mov	eax, '???'
3430
	mov	eax, '???'
2981
	stosd
3431
	stosd
2982
	clc
3432
	clc
2983
	ret
3433
	ret
2984
 
3434
 
2985
cF:
3435
cF:
2986
	call	disasm_get_byte
3436
	call	disasm_get_byte
2987
	jmp	dword [disasm_table_2 + eax*4]
3437
	jmp	dword [disasm_table_2 + eax*4]
2988
 
3438
 
2989
macro disasm_set_modew
3439
macro disasm_set_modew
2990
{
3440
{
2991
	test	al, 1
3441
	test	al, 1
2992
	jz	@f
3442
	jz	@f
2993
	or	ch, 80h
3443
	or	ch, 80h
2994
@@:
3444
@@:
2995
}
3445
}
2996
 
3446
 
2997
cmov2:
3447
cmov2:
2998
	disasm_set_modew
3448
	disasm_set_modew
2999
; mov r/m,i
3449
; mov r/m,i
3000
	call	disasm_get_byte
3450
	call	disasm_get_byte
3001
	dec	[disasm_cur_pos]
3451
	dec	[disasm_cur_pos]
3002
	test	al, 00111000b
3452
	test	al, 00111000b
3003
	jnz	cunk
3453
	jnz	cunk
3004
	mov	eax, 'mov '
3454
	mov	eax, 'mov '
3005
	stosd
3455
	stosd
3006
	mov	eax, '    '
3456
	mov	eax, '    '
3007
	stosd
3457
	stosd
3008
	call	disasm_readrmop
3458
	call	disasm_readrmop
3009
	mov	ax, ', '
3459
	mov	ax, ', '
3010
	stosw
3460
	stosw
3011
	xor	eax, eax
3461
	xor	eax, eax
3012
	test	ch, 80h
3462
	test	ch, 80h
3013
	jnz	.1
3463
	jnz	.1
3014
	call	disasm_get_byte
3464
	call	disasm_get_byte
3015
	jmp	.3
3465
	jmp	.3
3016
.1:
3466
.1:
3017
	test	ch, 1
3467
	test	ch, 1
3018
	jnz	.2
3468
	jnz	.2
3019
	call	disasm_get_dword
3469
	call	disasm_get_dword
3020
	jmp	.3
3470
	jmp	.3
3021
.2:
3471
.2:
3022
	call	disasm_get_word
3472
	call	disasm_get_word
3023
.3:
3473
.3:
3024
	call	disasm_write_num
3474
	call	disasm_write_num
3025
	and	byte [edi], 0
3475
	and	byte [edi], 0
3026
	ret
3476
	ret
3027
 
3477
 
3028
cret2:
3478
cret2:
3029
	mov	eax, 'ret '
3479
	mov	eax, 'ret '
3030
	stosd
3480
	stosd
3031
	mov	eax, '    '
3481
	mov	eax, '    '
3032
	stosd
3482
	stosd
3033
	xor	eax, eax
3483
	xor	eax, eax
3034
	jmp	cmov2.2
3484
	jmp	cmov2.2
3035
 
3485
 
3036
disasm_write_num:
3486
disasm_write_num:
-
 
3487
	push	esi
-
 
3488
	cmp	eax, 0x80
-
 
3489
	jl	.nosymb
-
 
3490
	lea	esi, [eax-1]
-
 
3491
	test	eax, esi
-
 
3492
	jz	.nosymb
-
 
3493
	call	find_symbol
-
 
3494
	jc	.nosymb
-
 
3495
@@:
-
 
3496
	lodsb
-
 
3497
	test	al, al
-
 
3498
	jz	@f
-
 
3499
	stosb
-
 
3500
	jmp	@b
-
 
3501
@@:
-
 
3502
	pop	esi
-
 
3503
	ret
-
 
3504
.nosymb:
-
 
3505
	pop	esi
3037
	push	ecx eax
3506
	push	ecx eax
3038
	inc	edi
3507
	inc	edi
3039
@@:
3508
@@:
3040
	mov	ecx, eax
3509
	mov	ecx, eax
3041
	shr	eax, 4
3510
	shr	eax, 4
3042
	jz	@f
3511
	jz	@f
3043
	inc	edi
3512
	inc	edi
3044
	jmp	@b
3513
	jmp	@b
3045
@@:
3514
@@:
3046
	pop	eax
3515
	pop	eax
3047
	cmp	ecx, 10
3516
	cmp	ecx, 10
3048
	jb	@f
3517
	jb	@f
3049
	inc	edi
3518
	inc	edi
3050
@@:
3519
@@:
3051
	push	edi eax
3520
	push	edi eax
3052
@@:
3521
@@:
3053
	mov	ecx, eax
3522
	mov	ecx, eax
3054
	and	al, 0xF
3523
	and	al, 0xF
3055
	cmp	al, 10
3524
	cmp	al, 10
3056
	sbb	al, 69h
3525
	sbb	al, 69h
3057
	das
3526
	das
3058
	dec	edi
3527
	dec	edi
3059
	mov	[edi], al
3528
	mov	[edi], al
3060
	mov	eax, ecx
3529
	mov	eax, ecx
3061
	shr	eax, 4
3530
	shr	eax, 4
3062
	jnz	@b
3531
	jnz	@b
3063
	cmp	ecx, 10
3532
	cmp	ecx, 10
3064
	jb	@f
3533
	jb	@f
3065
	mov	byte [edi-1], '0'
3534
	mov	byte [edi-1], '0'
3066
@@:
3535
@@:
3067
	pop	eax edi ecx
3536
	pop	eax edi ecx
3068
	cmp	eax, 10
3537
	cmp	eax, 10
3069
	jb	@f
3538
	jb	@f
3070
	mov	byte [edi], 'h'
3539
	mov	byte [edi], 'h'
3071
	inc	edi
3540
	inc	edi
3072
@@:
3541
@@:
3073
	ret
3542
	ret
-
 
3543
 
3074
 
3544
iglobal
3075
label disasm_regs32 dword
3545
label disasm_regs32 dword
3076
label disasm_regs dword
3546
label disasm_regs dword
3077
	db	'eax',0
3547
	db	'eax',0
3078
	db	'ecx',0
3548
	db	'ecx',0
3079
	db	'edx',0
3549
	db	'edx',0
3080
	db	'ebx',0
3550
	db	'ebx',0
3081
	db	'esp',0
3551
	db	'esp',0
3082
	db	'ebp',0
3552
	db	'ebp',0
3083
	db	'esi',0
3553
	db	'esi',0
3084
	db	'edi',0
3554
	db	'edi',0
3085
disasm_regs16	dw	'ax','cx','dx','bx','sp','bp','si','di'
3555
disasm_regs16	dw	'ax','cx','dx','bx','sp','bp','si','di'
3086
disasm_regs8	dw	'al','cl','dl','bl','ah','ch','dh','bh'
3556
disasm_regs8	dw	'al','cl','dl','bl','ah','ch','dh','bh'
3087
disasm_scale	db	'1248'
3557
disasm_scale	db	'1248'
-
 
3558
endg
3088
disasm_readrmop:
3559
disasm_readrmop:
3089
	call	disasm_get_byte
3560
	call	disasm_get_byte
3090
	test	ch, 40h
3561
	test	ch, 40h
3091
	jnz	.skip_size
3562
	jnz	.skip_size
3092
	push	eax
3563
	push	eax
3093
	and	al, 0xC0
3564
	and	al, 0xC0
3094
	cmp	al, 0xC0
3565
	cmp	al, 0xC0
3095
	pop	eax
3566
	pop	eax
3096
	jz	.skip_size
3567
	jz	.skip_size
3097
	test	ch, 80h
3568
	test	ch, 80h
3098
	jz	.byte
3569
	jz	.byte
3099
	test	ch, 1
3570
	test	ch, 1
3100
	jnz	.word
3571
	jnz	.word
3101
	mov	dword [edi], 'dwor'
3572
	mov	dword [edi], 'dwor'
3102
	mov	byte [edi+4], 'd'
3573
	mov	byte [edi+4], 'd'
3103
	inc	edi
3574
	inc	edi
3104
	jmp	@f
3575
	jmp	@f
3105
.byte:
3576
.byte:
3106
	test	ch, 20h
3577
	test	ch, 20h
3107
	jz	.qb
3578
	jz	.qb
3108
	mov	byte [edi], 't'
3579
	mov	byte [edi], 't'
3109
	inc	edi
3580
	inc	edi
3110
.qb:
3581
.qb:
3111
	mov	dword [edi], 'byte'
3582
	mov	dword [edi], 'byte'
3112
	jmp	@f
3583
	jmp	@f
3113
.word:
3584
.word:
3114
	test	ch, 20h
3585
	test	ch, 20h
3115
	jz	.qw
3586
	jz	.qw
3116
	mov	byte [edi], 'q'
3587
	mov	byte [edi], 'q'
3117
	inc	edi
3588
	inc	edi
3118
.qw:
3589
.qw:
3119
	mov	dword [edi], 'word'
3590
	mov	dword [edi], 'word'
3120
@@:
3591
@@:
3121
	mov	byte [edi+4], ' '
3592
	mov	byte [edi+4], ' '
3122
	add	edi, 5
3593
	add	edi, 5
3123
.skip_size:
3594
.skip_size:
3124
	test	ch, 2
3595
	test	ch, 2
3125
	jnz	disasm_readrmop16
3596
	jnz	disasm_readrmop16
3126
	push	ecx
3597
	push	ecx
3127
	movzx	ecx, al
3598
	movzx	ecx, al
3128
	and	eax, 7
3599
	and	eax, 7
3129
	shr	ecx, 6
3600
	shr	ecx, 6
3130
	jz	.vmod0
3601
	jz	.vmod0
3131
	jp	.vmod3
3602
	jp	.vmod3
3132
	mov	byte [edi], '['
3603
	mov	byte [edi], '['
3133
	inc	edi
3604
	inc	edi
3134
	cmp	al, 4
3605
	cmp	al, 4
3135
	jz	.sib1
3606
	jz	.sib1
3136
	mov	eax, [disasm_regs+eax*4]
3607
	mov	eax, [disasm_regs+eax*4]
3137
	stosd
3608
	stosd
3138
	dec	edi
3609
	dec	edi
3139
	jmp	@f
3610
	jmp	@f
3140
.sib1:
3611
.sib1:
3141
	call	.parse_sib
3612
	call	.parse_sib
3142
@@:
3613
@@:
3143
	mov	al, '+'
3614
	mov	al, '+'
3144
	stosb
3615
	stosb
3145
	dec	ecx
3616
	dec	ecx
3146
	jz	.vmod1
3617
	jz	.vmod1
3147
	call	disasm_get_dword
3618
	call	disasm_get_dword
3148
	jmp	@f
3619
	jmp	@f
3149
.vmod1:
3620
.vmod1:
3150
	call	disasm_get_byte
3621
	call	disasm_get_byte
3151
	movsx	eax, al
3622
	movsx	eax, al
3152
@@:
3623
@@:
3153
	test	eax, eax
3624
	test	eax, eax
3154
	jns	.2
3625
	jns	.2
3155
	neg	eax
3626
	neg	eax
3156
	mov	byte [edi-1], '-'
3627
	mov	byte [edi-1], '-'
3157
.2:
3628
.2:
3158
	call	disasm_write_num
3629
	call	disasm_write_num
-
 
3630
.2a:
3159
	mov	al, ']'
3631
	mov	al, ']'
3160
	stosb
3632
	stosb
3161
	pop	ecx
3633
	pop	ecx
3162
	ret
3634
	ret
3163
.vmod3:
3635
.vmod3:
3164
	pop	ecx
3636
	pop	ecx
-
 
3637
	test	ch, 10h
-
 
3638
	jnz	.vmod3_mmi
3165
	test	ch, 80h
3639
	test	ch, 80h
3166
	jz	.vmod3_byte
3640
	jz	.vmod3_byte
3167
	test	ch, 1
3641
	test	ch, 1
3168
	jnz	.vmod3_word
3642
	jnz	.vmod3_word
3169
	test	ch, 20h
3643
	test	ch, 20h
3170
	jnz	.vmod3_sti
3644
	jnz	.vmod3_sti
3171
	mov	eax, [disasm_regs32+eax*4]
3645
	mov	eax, [disasm_regs32+eax*4]
3172
	stosd
3646
	stosd
3173
	dec	edi
3647
	dec	edi
3174
	ret
3648
	ret
3175
.vmod3_byte:
3649
.vmod3_byte:
3176
	mov	ax, [disasm_regs8+eax*2]
3650
	mov	ax, [disasm_regs8+eax*2]
3177
@@:
3651
@@:
3178
	stosw
3652
	stosw
3179
	ret
3653
	ret
3180
.vmod3_word:
3654
.vmod3_word:
3181
	mov	ax, [disasm_regs16+eax*2]
3655
	mov	ax, [disasm_regs16+eax*2]
3182
	jmp	@b
3656
	jmp	@b
3183
.vmod3_sti:
3657
.vmod3_sti:
3184
	mov	word [edi], 'st'
3658
	mov	word [edi], 'st'
3185
	add	al, '0'
3659
	add	al, '0'
3186
	mov	byte [edi+2], al
3660
	mov	byte [edi+2], al
3187
	add	edi, 3
3661
	add	edi, 3
3188
	ret
3662
	ret
-
 
3663
.vmod3_mmi:
-
 
3664
disasm_write_mmreg = $
-
 
3665
	test	ch, 1
-
 
3666
	jz	@f
-
 
3667
	mov	byte [edi], 'x'
-
 
3668
	inc	edi
-
 
3669
@@:
-
 
3670
	mov	word [edi], 'mm'
-
 
3671
	add	al, '0'
-
 
3672
	mov	byte [edi+2], al
-
 
3673
	add	edi, 3
-
 
3674
	ret
3189
.vmod0:
3675
.vmod0:
3190
	mov	byte [edi], '['
3676
	mov	byte [edi], '['
3191
	inc	edi
3677
	inc	edi
3192
	cmp	al, 4
3678
	cmp	al, 4
3193
	jz	.sib2
3679
	jz	.sib2
3194
	cmp	al, 5
3680
	cmp	al, 5
3195
	jz	.ofs32
3681
	jz	.ofs32
3196
	mov	eax, [disasm_regs+eax*4]
3682
	mov	eax, [disasm_regs+eax*4]
3197
	stosd
3683
	stosd
3198
	mov	byte [edi-1], ']'
3684
	mov	byte [edi-1], ']'
3199
	pop	ecx
3685
	pop	ecx
3200
	ret
3686
	ret
3201
.ofs32:
3687
.ofs32:
3202
	call	disasm_get_dword
3688
	call	disasm_get_dword
3203
	jmp	.2
3689
	jmp	.2
3204
.sib2:
3690
.sib2:
3205
	call	.parse_sib
3691
	call	.parse_sib
3206
	mov	al, ']'
3692
	mov	al, ']'
3207
	stosb
3693
	stosb
3208
	pop	ecx
3694
	pop	ecx
3209
	ret
3695
	ret
3210
.parse_sib:
3696
.parse_sib:
3211
	call	disasm_get_byte
3697
	call	disasm_get_byte
3212
	push	edx
3698
	push	edx
3213
	mov	dl, al
3699
	mov	dl, al
3214
	mov	dh, 0
3700
	mov	dh, 0
3215
	and	eax, 7
3701
	and	eax, 7
3216
	cmp	al, 5
3702
	cmp	al, 5
3217
	jnz	@f
3703
	jnz	@f
3218
	jecxz	.sib0
3704
	jecxz	.sib0
3219
@@:
3705
@@:
3220
	mov	eax, [disasm_regs+eax*4]
3706
	mov	eax, [disasm_regs+eax*4]
3221
	stosd
3707
	stosd
3222
	dec	edi
3708
	dec	edi
3223
	mov	dh, 1
3709
	mov	dh, 1
3224
.sib0:
3710
.sib0:
3225
	mov	al, dl
3711
	mov	al, dl
3226
	shr	eax, 3
3712
	shr	eax, 3
3227
	and	eax, 7
3713
	and	eax, 7
3228
	cmp	al, 4
3714
	cmp	al, 4
3229
	jz	.sibret
3715
	jz	.sibret
3230
	test	dh, dh
3716
	test	dh, dh
3231
	jz	@f
3717
	jz	@f
3232
	mov	byte [edi], '+'
3718
	mov	byte [edi], '+'
3233
	inc	edi
3719
	inc	edi
3234
@@:
3720
@@:
3235
	mov	eax, [disasm_regs+eax*4]
3721
	mov	eax, [disasm_regs+eax*4]
3236
	stosd
3722
	stosd
3237
	dec	edi
3723
	dec	edi
3238
	shr	dl, 6
3724
	shr	dl, 6
3239
	jz	@f
3725
	jz	@f
3240
	mov	al, '*'
3726
	mov	al, '*'
3241
	stosb
3727
	stosb
3242
	movzx	eax, dl
3728
	movzx	eax, dl
3243
	mov	al, [disasm_scale+eax]
3729
	mov	al, [disasm_scale+eax]
3244
	stosb
3730
	stosb
3245
@@:
3731
@@:
3246
.sibret:
3732
.sibret:
3247
	test	dh, dh
3733
	test	dh, dh
3248
	jnz	.sibret2
3734
	jnz	.sibret2
3249
	call	disasm_get_dword
3735
	call	disasm_get_dword
3250
	cmp	byte [edi-1], '['
3736
	cmp	byte [edi-1], '['
3251
	jz	@f
3737
	jz	@f
3252
	mov	byte [edi], '+'
3738
	mov	byte [edi], '+'
3253
	test	eax, eax
3739
	test	eax, eax
3254
	jns	.sibns
3740
	jns	.sibns
3255
	neg	eax
3741
	neg	eax
3256
	mov	byte [edi], '-'
3742
	mov	byte [edi], '-'
3257
.sibns:
3743
.sibns:
3258
	inc	edi
3744
	inc	edi
3259
@@:
3745
@@:
3260
	call	disasm_write_num
3746
	call	disasm_write_num
3261
.sibret2:
3747
.sibret2:
3262
	pop	edx
3748
	pop	edx
3263
	ret
3749
	ret
-
 
3750
 
3264
 
3751
iglobal
3265
disasm_rm16_1	dd	'bxsi','bxdi','bpsi','bpdi'
3752
disasm_rm16_1	dd	'bxsi','bxdi','bpsi','bpdi'
-
 
3753
disasm_rm16_2	dw	'si','di','bp','bx'
3266
disasm_rm16_2	dw	'si','di','bp','bx'
3754
endg
3267
disasm_readrmop16:
3755
disasm_readrmop16:
3268
	push	ecx
3756
	push	ecx
3269
	movzx	ecx, al
3757
	movzx	ecx, al
3270
	and	eax, 7
3758
	and	eax, 7
3271
	shr	ecx, 6
3759
	shr	ecx, 6
3272
	jz	.vmod0
3760
	jz	.vmod0
3273
	jp	disasm_readrmop.vmod3	; mod=3 is the same in 16- and 32-bit code
3761
	jp	disasm_readrmop.vmod3	; mod=3 is the same in 16- and 32-bit code
3274
; 1 or 2
3762
; 1 or 2
3275
	mov	byte [edi], '['
3763
	mov	byte [edi], '['
3276
	inc	edi
3764
	inc	edi
3277
	cmp	al, 4
3765
	cmp	al, 4
3278
	jae	@f
3766
	jae	@f
3279
	mov	eax, [disasm_rm16_1+eax*4]
3767
	mov	eax, [disasm_rm16_1+eax*4]
3280
	stosw
3768
	stosw
3281
	mov	al, '+'
3769
	mov	al, '+'
3282
	stosb
3770
	stosb
3283
	shr	eax, 16
3771
	shr	eax, 16
3284
	jmp	.1
3772
	jmp	.1
3285
@@:
3773
@@:
3286
	mov	eax, dword [disasm_rm16_2+eax*2-4*2]
3774
	mov	eax, dword [disasm_rm16_2+eax*2-4*2]
3287
.1:
3775
.1:
3288
	stosw
3776
	stosw
3289
	mov	al, '+'
3777
	mov	al, '+'
3290
	stosb
3778
	stosb
3291
	xor	eax, eax
3779
	xor	eax, eax
3292
	dec	ecx
3780
	dec	ecx
3293
	jnz	.2
3781
	jnz	.2
3294
	call	disasm_get_byte
3782
	call	disasm_get_byte
3295
	cbw
3783
	cbw
3296
	jmp	@f
3784
	jmp	@f
3297
.2:
3785
.2:
3298
	call	disasm_get_word
3786
	call	disasm_get_word
3299
@@:
3787
@@:
3300
	test	ax, ax
3788
	test	ax, ax
3301
	jns	@f
3789
	jns	@f
3302
	mov	byte [edi-1], '-'
3790
	mov	byte [edi-1], '-'
3303
	neg	ax
3791
	neg	ax
3304
@@:
3792
@@:
3305
	call	disasm_write_num
3793
	call	disasm_write_num
3306
.done1:
3794
.done1:
3307
	mov	al, ']'
3795
	mov	al, ']'
3308
	stosb
3796
	stosb
3309
	pop	ecx
3797
	pop	ecx
3310
	ret
3798
	ret
3311
.vmod0:
3799
.vmod0:
3312
	mov	byte [edi], '['
3800
	mov	byte [edi], '['
3313
	inc	edi
3801
	inc	edi
3314
	cmp	al, 6
3802
	cmp	al, 6
3315
	jz	.ofs16
3803
	jz	.ofs16
3316
	cmp	al, 4
3804
	cmp	al, 4
3317
	jae	@f
3805
	jae	@f
3318
	mov	eax, [disasm_rm16_1+eax*4]
3806
	mov	eax, [disasm_rm16_1+eax*4]
3319
	stosw
3807
	stosw
3320
	mov	al, '+'
3808
	mov	al, '+'
3321
	stosb
3809
	stosb
3322
	shr	eax, 16
3810
	shr	eax, 16
3323
	jmp	.3
3811
	jmp	.3
3324
@@:
3812
@@:
3325
	mov	eax, dword [disasm_rm16_2+eax*2-4*2]
3813
	mov	eax, dword [disasm_rm16_2+eax*2-4*2]
3326
.3:
3814
.3:
3327
	stosw
3815
	stosw
3328
	jmp	.done1
3816
	jmp	.done1
3329
.ofs16:
3817
.ofs16:
3330
	xor	eax, eax
3818
	xor	eax, eax
3331
	call	disasm_get_word
3819
	call	disasm_get_word
3332
	call	disasm_write_num
3820
	call	disasm_write_num
3333
	jmp	.done1
3821
	jmp	.done1
3334
 
3822
 
3335
cpush21:
3823
cpush21:
3336
	mov	eax, 'push'
3824
	mov	eax, 'push'
3337
	stosd
3825
	stosd
3338
	mov	eax, '    '
3826
	mov	eax, '    '
3339
	stosd
3827
	stosd
3340
disasm_i32:
3828
disasm_i32:
3341
	call	disasm_get_dword
3829
	call	disasm_get_dword
3342
	call	disasm_write_num
3830
	call	disasm_write_num
3343
	and	byte [edi], 0
3831
	and	byte [edi], 0
3344
	ret
3832
	ret
3345
 
3833
 
3346
cpush22:
3834
cpush22:
3347
	mov	eax, 'push'
3835
	mov	eax, 'push'
3348
	stosd
3836
	stosd
3349
	mov	eax, '    '
3837
	mov	eax, '    '
3350
	stosd
3838
	stosd
3351
	call	disasm_get_byte
3839
	call	disasm_get_byte
3352
	movsx	eax, al
3840
	movsx	eax, al
3353
	call	disasm_write_num
3841
	call	disasm_write_num
3354
	and	byte [edi], 0
3842
	and	byte [edi], 0
3355
	ret
3843
	ret
3356
 
3844
 
3357
cinc1:
3845
cinc1:
3358
; inc reg32
3846
; inc reg32
3359
cdec1:
3847
cdec1:
3360
; dec reg32
3848
; dec reg32
3361
cpush1:
3849
cpush1:
3362
; push reg32
3850
; push reg32
3363
cpop1:
3851
cpop1:
3364
; pop reg32
3852
; pop reg32
3365
cbswap:
3853
cbswap:
3366
; bswap reg32
3854
; bswap reg32
3367
	mov	edx, eax
3855
	mov	edx, eax
3368
	and	edx, 7
3856
	and	edx, 7
3369
	shr	eax, 3
3857
	shr	eax, 3
3370
	sub	al, 8
3858
	sub	al, 8
3371
	mov	esi, 'inc '
3859
	mov	esi, 'inc '
3372
	jz	@f
3860
	jz	@f
3373
	mov	esi, 'dec '
3861
	mov	esi, 'dec '
3374
	dec	al
3862
	dec	al
3375
	jz	@f
3863
	jz	@f
3376
	mov	esi, 'push'
3864
	mov	esi, 'push'
3377
	dec	al
3865
	dec	al
3378
	jz	@f
3866
	jz	@f
3379
	mov	esi, 'pop '
3867
	mov	esi, 'pop '
3380
	dec	al
3868
	dec	al
3381
	jz	@f
3869
	jz	@f
3382
	mov	esi, 'bswa'
3870
	mov	esi, 'bswa'
3383
@@:
3871
@@:
3384
	xchg	eax, esi
3872
	xchg	eax, esi
3385
	stosd
3873
	stosd
3386
	mov	eax, '    '
3874
	mov	eax, '    '
3387
	jz	@f
3875
	jz	@f
3388
	mov	al, 'p'
3876
	mov	al, 'p'
3389
@@:
3877
@@:
3390
	stosd
3878
	stosd
3391
	xchg	eax, edx
3879
	xchg	eax, edx
3392
	call	disasm_write_reg1632
3880
	call	disasm_write_reg1632
3393
	and	byte [edi], 0
3881
	and	byte [edi], 0
3394
	ret
3882
	ret
3395
 
3883
 
3396
cxchg1:
3884
cxchg1:
3397
; xchg eax,reg32
3885
; xchg eax,reg32
3398
	and	eax, 7
3886
	and	eax, 7
3399
	xchg	eax, edx
3887
	xchg	eax, edx
3400
	mov	eax, 'xchg'
3888
	mov	eax, 'xchg'
3401
	stosd
3889
	stosd
3402
	mov	eax, '    '
3890
	mov	eax, '    '
3403
	stosd
3891
	stosd
3404
	xor	eax, eax
3892
	xor	eax, eax
3405
	call	disasm_write_reg1632
3893
	call	disasm_write_reg1632
3406
	mov	ax, ', '
3894
	mov	ax, ', '
3407
	stosw
3895
	stosw
3408
	xchg	eax, edx
3896
	xchg	eax, edx
3409
	call	disasm_write_reg1632
3897
	call	disasm_write_reg1632
3410
	and	byte [edi], 0
3898
	and	byte [edi], 0
3411
	ret
3899
	ret
3412
 
3900
 
3413
cint:
3901
cint:
3414
	mov	eax, 'int '
3902
	mov	eax, 'int '
3415
	stosd
3903
	stosd
3416
	mov	eax, '    '
3904
	mov	eax, '    '
3417
	stosd
3905
	stosd
3418
disasm_i8u:
3906
disasm_i8u:
3419
	xor	eax, eax
3907
	xor	eax, eax
3420
	call	disasm_get_byte
3908
	call	disasm_get_byte
3421
	call	disasm_write_num
3909
	call	disasm_write_num
3422
	and	byte [edi], 0
3910
	and	byte [edi], 0
3423
	ret
3911
	ret
3424
 
3912
 
3425
cmov11:
3913
cmov11:
3426
; mov r8,i8
3914
; mov r8,i8
3427
	mov	ecx, eax
3915
	mov	ecx, eax
3428
	mov	eax, 'mov '
3916
	mov	eax, 'mov '
3429
	stosd
3917
	stosd
3430
	mov	eax, '    '
3918
	mov	eax, '    '
3431
	stosd
3919
	stosd
3432
	and	ecx, 7
3920
	and	ecx, 7
3433
	mov	ax, [disasm_regs8+ecx*2]
3921
	mov	ax, [disasm_regs8+ecx*2]
3434
	stosw
3922
	stosw
3435
	mov	ax, ', '
3923
	mov	ax, ', '
3436
	stosw
3924
	stosw
3437
	jmp	disasm_i8u
3925
	jmp	disasm_i8u
3438
 
3926
 
3439
cmov12:
3927
cmov12:
3440
; mov r32,i32
3928
; mov r32,i32
3441
	xchg	eax, edx
3929
	xchg	eax, edx
3442
	mov	eax, 'mov '
3930
	mov	eax, 'mov '
3443
	stosd
3931
	stosd
3444
	mov	eax, '    '
3932
	mov	eax, '    '
3445
	stosd
3933
	stosd
3446
	xchg	eax, edx
3934
	xchg	eax, edx
3447
	and	eax, 7
3935
	and	eax, 7
3448
	call	disasm_write_reg1632
3936
	call	disasm_write_reg1632
3449
	mov	ax, ', '
3937
	mov	ax, ', '
3450
	stosw
3938
	stosw
3451
	jmp	cmov2.1
3939
	jmp	cmov2.1
-
 
3940
 
3452
 
3941
iglobal
-
 
3942
disasm_shifts	dd	'rol ','ror ','rcl ','rcr ','shl ','shr ','sal ','sar '
3453
disasm_shifts	dd	'rol ','ror ','rcl ','rcr ','shl ','shr ','sal ','sar '
3943
endg
3454
cshift2:
3944
cshift2:
3455
; shift r/m,1 = D0/D1
3945
; shift r/m,1 = D0/D1
3456
cshift3:
3946
cshift3:
3457
; shift r/m,cl = D2/D3
3947
; shift r/m,cl = D2/D3
3458
	disasm_set_modew
3948
	disasm_set_modew
3459
	mov	dl, al
3949
	mov	dl, al
3460
	call	disasm_get_byte
3950
	call	disasm_get_byte
3461
	dec	[disasm_cur_pos]
3951
	dec	[disasm_cur_pos]
3462
	shr	al, 3
3952
	shr	al, 3
3463
	and	eax, 7
3953
	and	eax, 7
3464
	mov	eax, [disasm_shifts+eax*4]
3954
	mov	eax, [disasm_shifts+eax*4]
3465
	stosd
3955
	stosd
3466
	mov	eax, '    '
3956
	mov	eax, '    '
3467
	stosd
3957
	stosd
3468
	call	disasm_readrmop
3958
	call	disasm_readrmop
3469
	cmp	dl, 0xD2
3959
	cmp	dl, 0xD2
3470
	jb	.s1
3960
	jb	.s1
3471
	mov	eax, ', cl'
3961
	mov	eax, ', cl'
3472
	stosd
3962
	stosd
3473
	and	byte [edi], 0
3963
	and	byte [edi], 0
3474
	ret
3964
	ret
3475
.s1:
3965
.s1:
3476
	mov	eax, ', 1'
3966
	mov	eax, ', 1'
3477
	stosd
3967
	stosd
3478
	clc
3968
	clc
3479
	ret
3969
	ret
3480
 
3970
 
3481
cshift1:
3971
cshift1:
3482
; shift r/m,i8 = C0/C1
3972
; shift r/m,i8 = C0/C1
3483
	disasm_set_modew
3973
	disasm_set_modew
3484
	call	disasm_get_byte
3974
	call	disasm_get_byte
3485
	dec	[disasm_cur_pos]
3975
	dec	[disasm_cur_pos]
3486
	shr	al, 3
3976
	shr	al, 3
3487
	and	eax, 7
3977
	and	eax, 7
3488
	mov	eax, [disasm_shifts+eax*4]
3978
	mov	eax, [disasm_shifts+eax*4]
3489
	stosd
3979
	stosd
3490
	mov	eax, '    '
3980
	mov	eax, '    '
3491
	stosd
3981
	stosd
3492
	call	disasm_readrmop
3982
	call	disasm_readrmop
3493
	mov	ax, ', '
3983
	mov	ax, ', '
3494
	stosw
3984
	stosw
3495
	jmp	disasm_i8u
3985
	jmp	disasm_i8u
3496
 
3986
 
3497
 
3987
 
3498
cmov3:
3988
cmov3:
3499
; A0: mov al,[ofs32]
3989
; A0: mov al,[ofs32]
3500
; A1: mov ax/eax,[ofs32]
3990
; A1: mov ax/eax,[ofs32]
3501
; A2: mov [ofs32],al
3991
; A2: mov [ofs32],al
3502
; A3: mov [ofs32],ax/eax
3992
; A3: mov [ofs32],ax/eax
3503
	mov	edx, 'mov '
3993
	mov	edx, 'mov '
3504
	xchg	eax, edx
3994
	xchg	eax, edx
3505
	stosd
3995
	stosd
3506
	mov	eax, '    '
3996
	mov	eax, '    '
3507
	stosd
3997
	stosd
3508
	test	dl, 2
3998
	test	dl, 2
3509
	jnz	.1
3999
	jnz	.1
3510
	call	.write_acc
4000
	call	.write_acc
3511
	mov	ax, ', '
4001
	mov	ax, ', '
3512
	stosw
4002
	stosw
3513
	call	.write_ofs32
4003
	call	.write_ofs32
3514
	jmp	.2
4004
	jmp	.2
3515
.1:
4005
.1:
3516
	call	.write_ofs32
4006
	call	.write_ofs32
3517
	mov	ax, ', '
4007
	mov	ax, ', '
3518
	stosw
4008
	stosw
3519
	call	.write_acc
4009
	call	.write_acc
3520
.2:	and	byte [edi], 0
4010
.2:	and	byte [edi], 0
3521
	ret
4011
	ret
3522
.write_acc:
4012
.write_acc:
3523
	test	dl, 1
4013
	test	dl, 1
3524
	jz	.8bit
4014
	jz	.8bit
3525
	test	ch, 1
4015
	test	ch, 1
3526
	jnz	.16bit
4016
	jnz	.16bit
3527
	mov	eax, 'eax'
4017
	mov	eax, 'eax'
3528
	stosd
4018
	stosd
3529
	dec	edi
4019
	dec	edi
3530
	ret
4020
	ret
3531
.16bit:
4021
.16bit:
3532
	mov	ax, 'ax'
4022
	mov	ax, 'ax'
3533
	stosw
4023
	stosw
3534
	ret
4024
	ret
3535
.8bit:
4025
.8bit:
3536
	mov	ax, 'al'
4026
	mov	ax, 'al'
3537
	stosw
4027
	stosw
3538
	ret
4028
	ret
3539
.write_ofs32:
4029
.write_ofs32:
3540
	mov	al, '['
4030
	mov	al, '['
3541
	stosb
4031
	stosb
3542
	call	disasm_get_dword
4032
	call	disasm_get_dword
3543
	call	disasm_write_num
4033
	call	disasm_write_num
3544
	mov	al, ']'
4034
	mov	al, ']'
3545
	stosb
4035
	stosb
3546
	ret
4036
	ret
3547
 
4037
 
3548
disasm_write_reg:
4038
disasm_write_reg:
3549
	test	ch, 80h
4039
	test	ch, 80h
3550
	jnz	disasm_write_reg1632
4040
	jnz	disasm_write_reg1632
3551
	mov	ax, [disasm_regs8+eax*2]
4041
	mov	ax, [disasm_regs8+eax*2]
3552
	stosw
4042
	stosw
3553
	ret
4043
	ret
3554
disasm_write_reg1632:
4044
disasm_write_reg1632:
3555
	test	ch, 1
4045
	test	ch, 1
3556
	jnz	@f
4046
	jnz	@f
3557
	mov	eax, [disasm_regs32+eax*4]
4047
	mov	eax, [disasm_regs32+eax*4]
3558
	stosd
4048
	stosd
3559
	dec	edi
4049
	dec	edi
3560
	ret
4050
	ret
3561
@@:
4051
@@:
3562
	mov	ax, [disasm_regs16+eax*2]
4052
	mov	ax, [disasm_regs16+eax*2]
3563
	stosw
4053
	stosw
3564
	ret
4054
	ret
3565
 
4055
 
3566
cmovzx:		; 0F B6/B7
4056
cmovzx:		; 0F B6/B7
3567
cmovsx:		; 0F BE/BF
4057
cmovsx:		; 0F BE/BF
3568
	mov	edx, eax
4058
	mov	edx, eax
3569
	disasm_set_modew
4059
	disasm_set_modew
3570
	mov	eax, 'movz'
4060
	mov	eax, 'movz'
3571
	cmp	dl, 0xB8
4061
	cmp	dl, 0xB8
3572
	jb	@f
4062
	jb	@f
3573
	mov	eax, 'movs'
4063
	mov	eax, 'movs'
3574
@@:
4064
@@:
3575
	stosd
4065
	stosd
3576
	mov	eax, 'x   '
4066
	mov	eax, 'x   '
3577
	stosd
4067
	stosd
3578
	call	disasm_get_byte
4068
	call	disasm_get_byte
3579
	dec	[disasm_cur_pos]
4069
	dec	[disasm_cur_pos]
3580
	shr	al, 3
4070
	shr	al, 3
3581
	and	eax, 7
4071
	and	eax, 7
3582
	call	disasm_write_reg1632
4072
	call	disasm_write_reg1632
3583
	mov	ax, ', '
4073
	mov	ax, ', '
3584
	stosw
4074
	stosw
3585
	or	ch, 1	; 2nd operand - 8 or 16 bits
4075
	or	ch, 1	; 2nd operand - 8 or 16 bits
3586
	call	disasm_readrmop
4076
	call	disasm_readrmop
3587
	and	byte [edi], 0
4077
	and	byte [edi], 0
3588
	ret
4078
	ret
-
 
4079
 
3589
 
4080
iglobal
-
 
4081
disasm_op2cmds	dd 'add ','or  ','adc ','sbb ','and ','sub ','xor ','cmp '
3590
disasm_op2cmds	dd 'add ','or  ','adc ','sbb ','and ','sub ','xor ','cmp '
4082
endg
3591
cop21:
4083
cop21:
3592
	disasm_set_modew
4084
	disasm_set_modew
3593
	mov	esi, 'test'
4085
	mov	esi, 'test'
3594
	cmp	al, 0A8h
4086
	cmp	al, 0A8h
3595
	jae	@f
4087
	jae	@f
3596
	shr	al, 3
4088
	shr	al, 3
3597
	and	eax, 7
4089
	and	eax, 7
3598
	mov	esi, [disasm_op2cmds+eax*4]
4090
	mov	esi, [disasm_op2cmds+eax*4]
3599
@@:
4091
@@:
3600
	xchg	eax, esi
4092
	xchg	eax, esi
3601
	stosd
4093
	stosd
3602
	mov	eax, '    '
4094
	mov	eax, '    '
3603
	stosd
4095
	stosd
3604
	test	ch, 80h
4096
	test	ch, 80h
3605
	jnz	.1632
4097
	jnz	.1632
3606
	mov	eax, 'al, '
4098
	mov	eax, 'al, '
3607
	stosd
4099
	stosd
3608
	jmp	disasm_i8u
4100
	jmp	disasm_i8u
3609
.1632:
4101
.1632:
3610
	test	ch, 1
4102
	test	ch, 1
3611
	jnz	.16
4103
	jnz	.16
3612
	mov	eax, 'eax,'
4104
	mov	eax, 'eax,'
3613
	stosd
4105
	stosd
3614
	mov	al, ' '
4106
	mov	al, ' '
3615
	stosb
4107
	stosb
3616
	call	disasm_get_dword
4108
	call	disasm_get_dword
3617
	jmp	.x
4109
	jmp	.x
3618
.16:
4110
.16:
3619
	mov	eax, 'ax, '
4111
	mov	eax, 'ax, '
3620
	stosd
4112
	stosd
3621
	xor	eax, eax
4113
	xor	eax, eax
3622
	call	disasm_get_word
4114
	call	disasm_get_word
3623
.x:
4115
.x:
3624
	call	disasm_write_num
4116
	call	disasm_write_num
3625
	and	byte [edi], 0
4117
	and	byte [edi], 0
3626
	ret
4118
	ret
3627
 
4119
 
3628
cop22:
4120
cop22:
3629
	disasm_set_modew
4121
	disasm_set_modew
3630
	or	ch, 40h
4122
	or	ch, 40h
3631
	mov	edx, eax
4123
	mov	edx, eax
3632
	mov	esi, 'lea '
4124
	mov	esi, 'lea '
3633
	cmp	al, 8Dh
4125
	cmp	al, 8Dh
3634
	jz	@f
4126
	jz	@f
3635
	mov	esi, 'imul'
4127
	mov	esi, 'imul'
3636
	cmp	al, 0xAF
4128
	cmp	al, 0xAF
3637
	jz	@f
4129
	jz	@f
3638
	mov	esi, 'mov '
4130
	mov	esi, 'mov '
3639
	cmp	al, 88h
4131
	cmp	al, 88h
3640
	jae	@f
4132
	jae	@f
3641
	mov	esi, 'xchg'
4133
	mov	esi, 'xchg'
3642
	cmp	al, 86h
4134
	cmp	al, 86h
3643
	jae	@f
4135
	jae	@f
3644
	mov	esi, 'test'
4136
	mov	esi, 'test'
3645
	cmp	al, 84h
4137
	cmp	al, 84h
3646
	jae	@f
4138
	jae	@f
3647
	shr	al, 3
4139
	shr	al, 3
3648
	and	eax, 7
4140
	and	eax, 7
3649
	mov	esi, [disasm_op2cmds+eax*4]
4141
	mov	esi, [disasm_op2cmds+eax*4]
3650
@@:
4142
@@:
3651
	xchg	eax, esi
4143
	xchg	eax, esi
3652
	stosd
4144
	stosd
3653
	mov	eax, '    '
4145
	mov	eax, '    '
3654
	stosd
4146
	stosd
3655
	call	disasm_get_byte
4147
	call	disasm_get_byte
3656
	dec	[disasm_cur_pos]
4148
	dec	[disasm_cur_pos]
3657
	shr	al, 3
4149
	shr	al, 3
3658
	and	eax, 7
4150
	and	eax, 7
3659
	cmp	dl, 0x8D
4151
	cmp	dl, 0x8D
3660
	jz	@f
4152
	jz	@f
3661
	cmp	dl, 0x86
4153
	cmp	dl, 0x86
3662
	jz	@f
4154
	jz	@f
3663
	cmp	dl, 0x87
4155
	cmp	dl, 0x87
3664
	jz	@f
4156
	jz	@f
3665
	test	dl, 2
4157
	test	dl, 2
3666
	jz	.d0
4158
	jz	.d0
3667
@@:
4159
@@:
3668
	call	disasm_write_reg
4160
	call	disasm_write_reg
3669
	mov	ax, ', '
4161
	mov	ax, ', '
3670
	stosw
4162
	stosw
3671
	call	disasm_readrmop
4163
	call	disasm_readrmop
3672
	and	byte [edi], 0
4164
	and	byte [edi], 0
3673
	ret
4165
	ret
3674
.d0:
4166
.d0:
3675
	push	eax
4167
	push	eax
3676
	call	disasm_readrmop
4168
	call	disasm_readrmop
3677
	mov	ax, ', '
4169
	mov	ax, ', '
3678
	stosw
4170
	stosw
3679
	pop	eax
4171
	pop	eax
3680
	call	disasm_write_reg
4172
	call	disasm_write_reg
3681
	and	byte [edi], 0
4173
	and	byte [edi], 0
3682
	ret
4174
	ret
3683
 
4175
 
3684
cop23:
4176
cop23:
3685
	disasm_set_modew
4177
	disasm_set_modew
3686
	xchg	eax, edx
4178
	xchg	eax, edx
3687
	call	disasm_get_byte
4179
	call	disasm_get_byte
3688
	dec	[disasm_cur_pos]
4180
	dec	[disasm_cur_pos]
3689
	shr	eax, 3
4181
	shr	eax, 3
3690
	and	eax, 7
4182
	and	eax, 7
3691
	mov	eax, [disasm_op2cmds+eax*4]
4183
	mov	eax, [disasm_op2cmds+eax*4]
3692
ctest:
4184
ctest:
3693
	stosd
4185
	stosd
3694
	mov	eax, '    '
4186
	mov	eax, '    '
3695
	stosd
4187
	stosd
3696
	call	disasm_readrmop
4188
	call	disasm_readrmop
3697
	mov	ax, ', '
4189
	mov	ax, ', '
3698
	stosw
4190
	stosw
3699
	test	ch, 80h
4191
	test	ch, 80h
3700
	jz	.i8
4192
	jz	.i8
3701
	cmp	dl, 83h
4193
	cmp	dl, 83h
3702
	jz	.i8
4194
	jz	.i8
3703
	test	ch, 1
4195
	test	ch, 1
3704
	jnz	.i16
4196
	jnz	.i16
3705
	call	disasm_get_dword
4197
	call	disasm_get_dword
3706
	jmp	.ic
4198
	jmp	.ic
3707
.i8:
4199
.i8:
3708
	xor	eax, eax
4200
	xor	eax, eax
3709
	call	disasm_get_byte
4201
	call	disasm_get_byte
3710
	cmp	dl, 83h
4202
	cmp	dl, 83h
3711
	jnz	.ic
4203
	jnz	.ic
3712
	movsx	eax, al
4204
	movsx	eax, al
3713
	jmp	.ic
4205
	jmp	.ic
3714
.i16:
4206
.i16:
3715
	xor	eax, eax
4207
	xor	eax, eax
3716
	call	disasm_get_word
4208
	call	disasm_get_word
3717
.ic:
4209
.ic:
3718
	call	disasm_write_num
4210
	call	disasm_write_num
3719
	and	byte [edi], 0
4211
	and	byte [edi], 0
3720
	ret
4212
	ret
-
 
4213
 
-
 
4214
cmovcc:
-
 
4215
	or	ch, 0C0h
-
 
4216
	and	eax, 0xF
-
 
4217
	mov	ax, [disasm_jcc_codes + eax*2]
-
 
4218
	mov	dword [edi], 'cmov'
-
 
4219
	add	edi, 4
-
 
4220
	stosw
-
 
4221
	mov	ax, '  '
-
 
4222
	stosw
-
 
4223
	call	disasm_get_byte
-
 
4224
	dec	[disasm_cur_pos]
-
 
4225
	shr	eax, 3
-
 
4226
	and	eax, 7
-
 
4227
	call	disasm_write_reg1632
-
 
4228
	mov	ax, ', '
-
 
4229
	stosw
-
 
4230
	call	disasm_readrmop
-
 
4231
	and	byte [edi], 0
-
 
4232
	ret
3721
 
4233
 
3722
cbtx1:
4234
cbtx1:
3723
; btx r/m,i8 = 0F BA
4235
; btx r/m,i8 = 0F BA
3724
	or	ch, 80h
4236
	or	ch, 80h
3725
	call	disasm_get_byte
4237
	call	disasm_get_byte
3726
	dec	[disasm_cur_pos]
4238
	dec	[disasm_cur_pos]
3727
	shr	al, 3
4239
	shr	al, 3
3728
	and	eax, 7
4240
	and	eax, 7
3729
	cmp	al, 4
4241
	cmp	al, 4
3730
	jb	cunk
4242
	jb	cunk
3731
	mov	eax, [btx1codes+eax*4-4*4]
4243
	mov	eax, [btx1codes+eax*4-4*4]
3732
	stosd
4244
	stosd
3733
	mov	eax, '    '
4245
	mov	eax, '    '
3734
	stosd
4246
	stosd
3735
	call	disasm_readrmop
4247
	call	disasm_readrmop
3736
	mov	ax, ', '
4248
	mov	ax, ', '
3737
	stosw
4249
	stosw
3738
	jmp	disasm_i8u
4250
	jmp	disasm_i8u
-
 
4251
iglobal
3739
btx1codes	dd	'bt  ','bts ','btr ','btc '
4252
btx1codes	dd	'bt  ','bts ','btr ','btc '
-
 
4253
endg
3740
cbtx2:
4254
cbtx2:
3741
; btx r/m,r = 0F 101xx011 (A3,AB,B3,BB)
4255
; btx r/m,r = 0F 101xx011 (A3,AB,B3,BB)
3742
	shr	al, 3
4256
	shr	al, 3
3743
	and	eax, 3
4257
	and	eax, 3
3744
	mov	eax, [btx1codes+eax*4]
4258
	mov	eax, [btx1codes+eax*4]
3745
	stosd
4259
	stosd
3746
	mov	eax, '    '
4260
	mov	eax, '    '
3747
	stosd
4261
	stosd
3748
	or	ch, 0xC0
4262
	or	ch, 0xC0
3749
	call	disasm_get_byte
4263
	call	disasm_get_byte
3750
	dec	[disasm_cur_pos]
4264
	dec	[disasm_cur_pos]
3751
	shr	al, 3
4265
	shr	al, 3
3752
	and	eax, 7
4266
	and	eax, 7
3753
	push	eax
4267
	push	eax
3754
	call	disasm_readrmop
4268
	call	disasm_readrmop
3755
	mov	ax, ', '
4269
	mov	ax, ', '
3756
	stosw
4270
	stosw
3757
	pop	eax
4271
	pop	eax
3758
	call	disasm_write_reg1632
4272
	call	disasm_write_reg1632
3759
	and	byte [edi], 0
4273
	and	byte [edi], 0
3760
	ret
4274
	ret
3761
 
4275
 
3762
csetcc:
4276
csetcc:
3763
	and	eax, 0xF
4277
	and	eax, 0xF
3764
	mov	ax, [disasm_jcc_codes + eax*2]
4278
	mov	ax, [disasm_jcc_codes + eax*2]
3765
	mov	dword [edi], 'setc'
4279
	mov	dword [edi], 'setc'
3766
	add	edi, 3
4280
	add	edi, 3
3767
	stosw
4281
	stosw
3768
	mov	ax, '  '
4282
	mov	ax, '  '
3769
	stosw
4283
	stosw
3770
	stosb
4284
	stosb
3771
	call	disasm_readrmop
4285
	call	disasm_readrmop
3772
	and	byte [edi], 0
4286
	and	byte [edi], 0
3773
	ret
4287
	ret
-
 
4288
 
3774
 
4289
iglobal
-
 
4290
disasm_jcc_codes dw 'o ','no','b ','ae','z ','nz','be','a ','s ','ns','p ','np','l ','ge','le','g '
3775
disasm_jcc_codes dw 'o ','no','b ','ae','z ','nz','be','a ','s ','ns','p ','np','l ','ge','le','g '
4291
endg
3776
cjcc1:
4292
cjcc1:
3777
cjmp2:
4293
cjmp2:
3778
	cmp	al, 0xEB
4294
	cmp	al, 0xEB
3779
	jz	.1
4295
	jz	.1
3780
	and	eax, 0xF
4296
	and	eax, 0xF
3781
	mov	ax, [disasm_jcc_codes + eax*2]
4297
	mov	ax, [disasm_jcc_codes + eax*2]
3782
	jmp	.2
4298
	jmp	.2
3783
.1:
4299
.1:
3784
	mov	ax, 'mp'
4300
	mov	ax, 'mp'
3785
.2:
4301
.2:
3786
	mov	byte [edi], 'j'
4302
	mov	byte [edi], 'j'
3787
	inc	edi
4303
	inc	edi
3788
	stosw
4304
	stosw
3789
	mov	eax, '    '
4305
	mov	eax, '    '
3790
	stosb
4306
	stosb
3791
	stosd
4307
	stosd
3792
	call	disasm_get_byte
4308
	call	disasm_get_byte
3793
	movsx	eax, al
4309
	movsx	eax, al
3794
disasm_rva:
4310
disasm_rva:
3795
	add	eax, [disasm_cur_pos]
4311
	add	eax, [disasm_cur_pos]
3796
	call	disasm_write_num
4312
	call	disasm_write_num
3797
	and	byte [edi], 0
4313
	and	byte [edi], 0
3798
	ret
4314
	ret
3799
 
4315
 
3800
ccall1:
4316
ccall1:
3801
cjmp1:
4317
cjmp1:
3802
cjcc2:
4318
cjcc2:
3803
	mov	edx, 'call'
4319
	mov	edx, 'call'
3804
	cmp	al, 0xE8
4320
	cmp	al, 0xE8
3805
	jz	@f
4321
	jz	@f
3806
	mov	edx, 'jmp '
4322
	mov	edx, 'jmp '
3807
	cmp	al, 0xE9
4323
	cmp	al, 0xE9
3808
	jz	@f
4324
	jz	@f
3809
	mov	edx, '    '
4325
	mov	edx, '    '
3810
	and	eax, 0xF
4326
	and	eax, 0xF
3811
	mov	dx, [disasm_jcc_codes+eax*2]
4327
	mov	dx, [disasm_jcc_codes+eax*2]
3812
	shl	edx, 8
4328
	shl	edx, 8
3813
	mov	dl, 'j'
4329
	mov	dl, 'j'
3814
@@:
4330
@@:
3815
	xchg	eax, edx
4331
	xchg	eax, edx
3816
	stosd
4332
	stosd
3817
	mov	eax, '    '
4333
	mov	eax, '    '
3818
	stosd
4334
	stosd
3819
	call	disasm_get_dword
4335
	call	disasm_get_dword
3820
	jmp	disasm_rva
4336
	jmp	disasm_rva
-
 
4337
 
3821
 
4338
iglobal
3822
op11codes	dd	'test',0,'not ','neg ','mul ','imul','div ','idiv'
4339
op11codes	dd	'test',0,'not ','neg ','mul ','imul','div ','idiv'
-
 
4340
op12codes	dd	'inc ','dec ','call',0,'jmp ',0,'push',0
3823
op12codes	dd	'inc ','dec ','call',0,'jmp ',0,'push',0
4341
endg
3824
cop1:
4342
cop1:
3825
	disasm_set_modew
4343
	disasm_set_modew
3826
	xchg	eax, edx
4344
	xchg	eax, edx
3827
	call	disasm_get_byte
4345
	call	disasm_get_byte
3828
	dec	[disasm_cur_pos]
4346
	dec	[disasm_cur_pos]
3829
	shr	al, 3
4347
	shr	al, 3
3830
	and	eax, 7
4348
	and	eax, 7
3831
	cmp	dl, 0xFE
4349
	cmp	dl, 0xFE
3832
	jnz	@f
4350
	jnz	@f
3833
	cmp	al, 1
4351
	cmp	al, 1
3834
	ja	cunk
4352
	ja	cunk
3835
@@:
4353
@@:
3836
	and	edx, 8
4354
	and	edx, 8
3837
	add	eax, edx
4355
	add	eax, edx
3838
	mov	eax, [op11codes+eax*4]
4356
	mov	eax, [op11codes+eax*4]
3839
	test	eax, eax
4357
	test	eax, eax
3840
	jz	cunk
4358
	jz	cunk
3841
	cmp	eax, 'test'
4359
	cmp	eax, 'test'
3842
	jz	ctest
4360
	jz	ctest
3843
@@:
4361
@@:
3844
	stosd
4362
	stosd
3845
	mov	eax, '    '
4363
	mov	eax, '    '
3846
	stosd
4364
	stosd
3847
	call	disasm_readrmop
4365
	call	disasm_readrmop
3848
	and	byte [edi], 0
4366
	and	byte [edi], 0
3849
	ret
4367
	ret
3850
 
4368
 
3851
cpop2:
4369
cpop2:
3852
	or	ch, 80h
4370
	or	ch, 80h
3853
	call	disasm_get_byte
4371
	call	disasm_get_byte
3854
	dec	[disasm_cur_pos]
4372
	dec	[disasm_cur_pos]
3855
	test	al, 00111000b
4373
	test	al, 00111000b
3856
	jnz	cunk
4374
	jnz	cunk
3857
	mov	eax, 'pop '
4375
	mov	eax, 'pop '
3858
	jmp	@b
4376
	jmp	@b
3859
 
4377
 
3860
cloopnz:
4378
cloopnz:
3861
	mov	eax, 'loop'
4379
	mov	eax, 'loop'
3862
	stosd
4380
	stosd
3863
	mov	eax, 'nz  '
4381
	mov	eax, 'nz  '
3864
	test	ch, 2
4382
	test	ch, 2
3865
	jz	@f
4383
	jz	@f
3866
	mov	ah, 'w'
4384
	mov	ah, 'w'
3867
@@:	jmp	cloop.cmn
4385
@@:	jmp	cloop.cmn
3868
cloopz:
4386
cloopz:
3869
	mov	eax, 'loop'
4387
	mov	eax, 'loop'
3870
	stosd
4388
	stosd
3871
	mov	eax, 'z   '
4389
	mov	eax, 'z   '
3872
	test	ch, 2
4390
	test	ch, 2
3873
	jz	@f
4391
	jz	@f
3874
	mov	eax, 'zw  '
4392
	mov	eax, 'zw  '
3875
@@:	jmp	cloop.cmn
4393
@@:	jmp	cloop.cmn
3876
 
4394
 
3877
cjcxz:
4395
cjcxz:
3878
cloop:
4396
cloop:
3879
	cmp	al, 0xE2
4397
	cmp	al, 0xE2
3880
	jz	.loop
4398
	jz	.loop
3881
	test	ch, 2
4399
	test	ch, 2
3882
	jnz	.jcxz
4400
	jnz	.jcxz
3883
	mov	eax, 'jecx'
4401
	mov	eax, 'jecx'
3884
	stosd
4402
	stosd
3885
	mov	eax, 'z   '
4403
	mov	eax, 'z   '
3886
	jmp	.cmn
4404
	jmp	.cmn
3887
.jcxz:
4405
.jcxz:
3888
	mov	eax, 'jcxz'
4406
	mov	eax, 'jcxz'
3889
	stosd
4407
	stosd
3890
	mov	eax, '    '
4408
	mov	eax, '    '
3891
	jmp	.cmn
4409
	jmp	.cmn
3892
.loop:
4410
.loop:
3893
	mov	eax, 'loop'
4411
	mov	eax, 'loop'
3894
	stosd
4412
	stosd
3895
	mov	eax, '    '
4413
	mov	eax, '    '
3896
	test	ch, 2
4414
	test	ch, 2
3897
	jz	.cmn
4415
	jz	.cmn
3898
	mov	al, 'w'
4416
	mov	al, 'w'
3899
.cmn:
4417
.cmn:
3900
	stosd
4418
	stosd
3901
	call	disasm_get_byte
4419
	call	disasm_get_byte
3902
	movsx	eax, al
4420
	movsx	eax, al
3903
	add	eax, [disasm_cur_pos]
4421
	add	eax, [disasm_cur_pos]
3904
	test	ch, 1
4422
	test	ch, 1
3905
	jz	@f
4423
	jz	@f
3906
	and	eax, 0xFFFF
4424
	and	eax, 0xFFFF
3907
@@:
4425
@@:
3908
disasm_write_num_done:
4426
disasm_write_num_done:
3909
	call	disasm_write_num
4427
	call	disasm_write_num
3910
	and	byte [edi], 0
4428
	and	byte [edi], 0
3911
	ret
4429
	ret
3912
 
4430
 
3913
cimul1:
4431
cimul1:
3914
; imul r,r/m,i
4432
; imul r,r/m,i
3915
	or	ch, 80h		; 32bit operation
4433
	or	ch, 80h		; 32bit operation
3916
	xchg	eax, edx
4434
	xchg	eax, edx
3917
	mov	eax, 'imul'
4435
	mov	eax, 'imul'
3918
	stosd
4436
	stosd
3919
	mov	eax, '    '
4437
	mov	eax, '    '
3920
	stosd
4438
	stosd
3921
	call	disasm_get_byte
4439
	call	disasm_get_byte
3922
	dec	[disasm_cur_pos]
4440
	dec	[disasm_cur_pos]
3923
	shr	al, 3
4441
	shr	al, 3
3924
	and	eax, 7
4442
	and	eax, 7
3925
	call	disasm_write_reg1632
4443
	call	disasm_write_reg1632
3926
	mov	ax, ', '
4444
	mov	ax, ', '
3927
	stosw
4445
	stosw
3928
	call	disasm_readrmop
4446
	call	disasm_readrmop
3929
	mov	ax, ', '
4447
	mov	ax, ', '
3930
	stosw
4448
	stosw
3931
	test	ch, 1
4449
	test	ch, 1
3932
	jnz	.16
4450
	jnz	.16
3933
	cmp	dl, 0x69
4451
	cmp	dl, 0x69
3934
	jz	.op32
4452
	jz	.op32
3935
	call	disasm_get_byte
4453
	call	disasm_get_byte
3936
	movsx	eax, al
4454
	movsx	eax, al
3937
	jmp	disasm_write_num_done
4455
	jmp	disasm_write_num_done
3938
.op32:
4456
.op32:
3939
	call	disasm_get_dword
4457
	call	disasm_get_dword
3940
	jmp	disasm_write_num_done
4458
	jmp	disasm_write_num_done
3941
.16:
4459
.16:
3942
	cmp	dl, 0x69
4460
	cmp	dl, 0x69
3943
	jz	.op16
4461
	jz	.op16
3944
	call	disasm_get_byte
4462
	call	disasm_get_byte
3945
	cbw
4463
	cbw
3946
	jmp	disasm_write_num_done
4464
	jmp	disasm_write_num_done
3947
.op16:
4465
.op16:
3948
	xor	eax, eax
4466
	xor	eax, eax
3949
	call	disasm_get_word
4467
	call	disasm_get_word
3950
	jmp	disasm_write_num_done
4468
	jmp	disasm_write_num_done
3951
 
4469
 
3952
cshld:
4470
cshld:
3953
cshrd:
4471
cshrd:
3954
	mov	edx, 'shld'
4472
	mov	edx, 'shld'
3955
	test	al, 8
4473
	test	al, 8
3956
	jz	@f
4474
	jz	@f
3957
	mov	edx, 'shrd'
4475
	mov	edx, 'shrd'
3958
@@:
4476
@@:
3959
	xchg	eax, edx
4477
	xchg	eax, edx
3960
	stosd
4478
	stosd
3961
	mov	eax, '    '
4479
	mov	eax, '    '
3962
	stosd
4480
	stosd
3963
	call	disasm_get_byte
4481
	call	disasm_get_byte
3964
	dec	[disasm_cur_pos]
4482
	dec	[disasm_cur_pos]
3965
	shr	al, 3
4483
	shr	al, 3
3966
	and	eax, 7
4484
	and	eax, 7
3967
	push	eax
4485
	push	eax
3968
	or	ch, 80h
4486
	or	ch, 80h
3969
	call	disasm_readrmop
4487
	call	disasm_readrmop
3970
	mov	ax, ', '
4488
	mov	ax, ', '
3971
	stosw
4489
	stosw
3972
	pop	eax
4490
	pop	eax
3973
	call	disasm_write_reg1632
4491
	call	disasm_write_reg1632
3974
	mov	ax, ', '
4492
	mov	ax, ', '
3975
	stosw
4493
	stosw
3976
	test	dl, 1
4494
	test	dl, 1
3977
	jz	disasm_i8u
4495
	jz	disasm_i8u
3978
	mov	ax, 'cl'
4496
	mov	ax, 'cl'
3979
	stosw
4497
	stosw
3980
	and	byte [edi], 0
4498
	and	byte [edi], 0
3981
	ret
4499
	ret
3982
 
4500
 
3983
ccbw:
4501
ccbw:
3984
	mov	eax, 'cbw '
4502
	mov	eax, 'cbw '
3985
	test	ch, 1
4503
	test	ch, 1
3986
	jnz	@f
4504
	jnz	@f
3987
	mov	eax, 'cwde'
4505
	mov	eax, 'cwde'
3988
@@:	stosd
4506
@@:	stosd
3989
	and	byte [edi+1], 0
4507
	and	byte [edi+1], 0
3990
	ret
4508
	ret
3991
ccwd:
4509
ccwd:
3992
	mov	eax, 'cwd '
4510
	mov	eax, 'cwd '
3993
	test	ch, 1
4511
	test	ch, 1
3994
	jnz	@b
4512
	jnz	@b
3995
	mov	eax, 'cdq '
4513
	mov	eax, 'cdq '
3996
	jmp	@b
4514
	jmp	@b
-
 
4515
 
3997
 
4516
iglobal
-
 
4517
fpuD8	dd	'add ','mul ','com ','comp','sub ','subr','div ','divr'
3998
fpuD8	dd	'add ','mul ','com ','comp','sub ','subr','div ','divr'
4518
endg
3999
 
4519
 
4000
cD8:
4520
cD8:
4001
	call	disasm_get_byte
4521
	call	disasm_get_byte
4002
	dec	[disasm_cur_pos]
4522
	dec	[disasm_cur_pos]
4003
	push	eax
4523
	push	eax
4004
	shr	al, 3
4524
	shr	al, 3
4005
	and	eax, 7
4525
	and	eax, 7
4006
	mov	byte [edi], 'f'
4526
	mov	byte [edi], 'f'
4007
	inc	edi
4527
	inc	edi
4008
	xchg	eax, edx
4528
	xchg	eax, edx
4009
	mov	eax, [fpuD8+edx*4]
4529
	mov	eax, [fpuD8+edx*4]
4010
	stosd
4530
	stosd
4011
	mov	ax, '  '
4531
	mov	ax, '  '
4012
	stosw
4532
	stosw
4013
	stosb
4533
	stosb
4014
	pop	eax
4534
	pop	eax
4015
	cmp	dl, 2
4535
	cmp	dl, 2
4016
	jb	.1
4536
	jb	.1
4017
	cmp	dl, 3
4537
	cmp	dl, 3
4018
	jbe	.2
4538
	jbe	.2
4019
.1:
4539
.1:
4020
	cmp	al, 0xC0
4540
	cmp	al, 0xC0
4021
	jb	.2
4541
	jb	.2
4022
	mov	eax, 'st0,'
4542
	mov	eax, 'st0,'
4023
	stosd
4543
	stosd
4024
	mov	al, ' '
4544
	mov	al, ' '
4025
	stosb
4545
	stosb
4026
.2:
4546
.2:
4027
	or	ch, 80h or 20h
4547
	or	ch, 80h or 20h
4028
	and	ch, not 1
4548
	and	ch, not 1
4029
	call	disasm_readrmop
4549
	call	disasm_readrmop
4030
	and	byte [edi], 0
4550
	and	byte [edi], 0
4031
	ret
4551
	ret
-
 
4552
 
4032
 
4553
iglobal
4033
fpuD9_2:
4554
fpuD9_2:
4034
	dq	'fchs    ','fabs    ',0,0,'ftst    ','fxam    ',0,0
4555
	dq	'fchs    ','fabs    ',0,0,'ftst    ','fxam    ',0,0
4035
	db	'fld1    fldl2t  fldl2e  fldpi   fldlg2  fldln2  fldz    '
4556
	db	'fld1    fldl2t  fldl2e  fldpi   fldlg2  fldln2  fldz    '
4036
	dq	0
4557
	dq	0
4037
	db	'f2xm1   fyl2x   fptan   fpatan  fxtract fprem1  fdecstp fincstp '
4558
	db	'f2xm1   fyl2x   fptan   fpatan  fxtract fprem1  fdecstp fincstp '
4038
	db	'fprem   fyl2xp1 fsqrt   fsincos frndint fscale  fsin    fcos    '
4559
	db	'fprem   fyl2xp1 fsqrt   fsincos frndint fscale  fsin    fcos    '
4039
fpuD9_fnop	db	'fnop    '
4560
fpuD9_fnop	db	'fnop    '
-
 
4561
endg
4040
cD9:
4562
cD9:
4041
	call	disasm_get_byte
4563
	call	disasm_get_byte
4042
	sub	al, 0xC0
4564
	sub	al, 0xC0
4043
	jae	.l1
4565
	jae	.l1
4044
	dec	[disasm_cur_pos]
4566
	dec	[disasm_cur_pos]
4045
	shr	al, 3
4567
	shr	al, 3
4046
	and	eax, 7
4568
	and	eax, 7
4047
	cmp	al, 7
4569
	cmp	al, 7
4048
	jnz	@f
4570
	jnz	@f
4049
	mov	eax, 'fnst'
4571
	mov	eax, 'fnst'
4050
	stosd
4572
	stosd
4051
	mov	eax, 'cw  '
4573
	mov	eax, 'cw  '
4052
	jmp	.x1
4574
	jmp	.x1
4053
@@:
4575
@@:
4054
	cmp	al, 5
4576
	cmp	al, 5
4055
	jnz	@f
4577
	jnz	@f
4056
	mov	eax, 'fldc'
4578
	mov	eax, 'fldc'
4057
	stosd
4579
	stosd
4058
	mov	eax, 'w   '
4580
	mov	eax, 'w   '
4059
.x1:
4581
.x1:
4060
	stosd
4582
	stosd
4061
	or	ch, 0C1h
4583
	or	ch, 0C1h
4062
	jmp	.cmn
4584
	jmp	.cmn
4063
@@:
4585
@@:
4064
	mov	edx, 'fld '
4586
	mov	edx, 'fld '
4065
	test	al, al
4587
	test	al, al
4066
	jz	@f
4588
	jz	@f
4067
	mov	edx, 'fst '
4589
	mov	edx, 'fst '
4068
	cmp	al, 2
4590
	cmp	al, 2
4069
	jz	@f
4591
	jz	@f
4070
	mov	edx, 'fstp'
4592
	mov	edx, 'fstp'
4071
	cmp	al, 3
4593
	cmp	al, 3
4072
	jnz	cunk
4594
	jnz	cunk
4073
@@:
4595
@@:
4074
	xchg	eax, edx
4596
	xchg	eax, edx
4075
	stosd
4597
	stosd
4076
	mov	eax, '    '
4598
	mov	eax, '    '
4077
	stosd
4599
	stosd
4078
	or	ch, 80h
4600
	or	ch, 80h
4079
	and	ch, not 1
4601
	and	ch, not 1
4080
.cmn:
4602
.cmn:
4081
	call	disasm_readrmop
4603
	call	disasm_readrmop
4082
	and	byte [edi], 0
4604
	and	byte [edi], 0
4083
	ret
4605
	ret
4084
.l1:
4606
.l1:
4085
	cmp	al, 10h
4607
	cmp	al, 10h
4086
	jae	.l2
4608
	jae	.l2
4087
	mov	edx, 'fld '
4609
	mov	edx, 'fld '
4088
	cmp	al, 8
4610
	cmp	al, 8
4089
	jb	@f
4611
	jb	@f
4090
	mov	edx, 'fxch'
4612
	mov	edx, 'fxch'
4091
@@:
4613
@@:
4092
	xchg	eax, edx
4614
	xchg	eax, edx
4093
	stosd
4615
	stosd
4094
	mov	eax, '    '
4616
	mov	eax, '    '
4095
	stosd
4617
	stosd
4096
	xchg	eax, edx
4618
	xchg	eax, edx
4097
	and	al, 7
4619
	and	al, 7
4098
	add	al, '0'
4620
	add	al, '0'
4099
	shl	eax, 16
4621
	shl	eax, 16
4100
	mov	ax, 'st'
4622
	mov	ax, 'st'
4101
	stosd
4623
	stosd
4102
	clc
4624
	clc
4103
	ret
4625
	ret
4104
.l2:
4626
.l2:
4105
	cmp	al, 0x10
4627
	cmp	al, 0x10
4106
	jnz	@f
4628
	jnz	@f
4107
	mov	esi, fpuD9_fnop
4629
	mov	esi, fpuD9_fnop
4108
	jmp	.l3
4630
	jmp	.l3
4109
@@:
4631
@@:
4110
	sub	al, 0x20
4632
	sub	al, 0x20
4111
	jb	cerr
4633
	jb	cerr
4112
	lea	esi, [fpuD9_2+eax*8]
4634
	lea	esi, [fpuD9_2+eax*8]
4113
	cmp	byte [esi], 0
4635
	cmp	byte [esi], 0
4114
	jz	cerr
4636
	jz	cerr
4115
.l3:
4637
.l3:
4116
	movsd
4638
	movsd
4117
	movsd
4639
	movsd
4118
	and	byte [edi-1], 0
4640
	and	byte [edi-1], 0
4119
	ret
4641
	ret
4120
 
4642
 
4121
cDA:
4643
cDA:
4122
	call	disasm_get_byte
4644
	call	disasm_get_byte
4123
	cmp	al, 0xC0
4645
	cmp	al, 0xC0
4124
	jae	cunk
4646
	jae	cunk
4125
	dec	[disasm_cur_pos]
4647
	dec	[disasm_cur_pos]
4126
	shr	al, 3
4648
	shr	al, 3
4127
	and	eax, 7
4649
	and	eax, 7
4128
	mov	word [edi], 'fi'
4650
	mov	word [edi], 'fi'
4129
	inc	edi
4651
	inc	edi
4130
	inc	edi
4652
	inc	edi
4131
	mov	eax, [fpuD8+eax*4]
4653
	mov	eax, [fpuD8+eax*4]
4132
	stosd
4654
	stosd
4133
	mov	ax, '  '
4655
	mov	ax, '  '
4134
	stosw
4656
	stosw
4135
	or	ch, 80h
4657
	or	ch, 80h
4136
	and	ch, not 1	; 32-bit operand
4658
	and	ch, not 1	; 32-bit operand
4137
	call	disasm_readrmop
4659
	call	disasm_readrmop
4138
	and	byte [edi], 0
4660
	and	byte [edi], 0
4139
	ret
4661
	ret
-
 
4662
 
4140
 
4663
iglobal
-
 
4664
fpuDB	dd	'ild ',0,'ist ','istp',0,'ld  ',0,'stp '
4141
fpuDB	dd	'ild ',0,'ist ','istp',0,'ld  ',0,'stp '
4665
endg
4142
cDB:
4666
cDB:
4143
	call	disasm_get_byte
4667
	call	disasm_get_byte
4144
	cmp	al, 0xC0
4668
	cmp	al, 0xC0
4145
	jae	.1
4669
	jae	.1
4146
	dec	[disasm_cur_pos]
4670
	dec	[disasm_cur_pos]
4147
	shr	al, 3
4671
	shr	al, 3
4148
	and	eax, 7
4672
	and	eax, 7
4149
	xchg	eax, edx
4673
	xchg	eax, edx
4150
	mov	eax, [fpuDB+edx*4]
4674
	mov	eax, [fpuDB+edx*4]
4151
	test	eax, eax
4675
	test	eax, eax
4152
	jz	cerr
4676
	jz	cerr
4153
	mov	byte [edi], 'f'
4677
	mov	byte [edi], 'f'
4154
	inc	edi
4678
	inc	edi
4155
	stosd
4679
	stosd
4156
	mov	ax, '  '
4680
	mov	ax, '  '
4157
	stosw
4681
	stosw
4158
	stosb
4682
	stosb
4159
	or	ch, 80h
4683
	or	ch, 80h
4160
	and	ch, not 1	; 32-bit operand
4684
	and	ch, not 1	; 32-bit operand
4161
	cmp	dl, 4
4685
	cmp	dl, 4
4162
	jb	@f
4686
	jb	@f
4163
	or	ch, 20h
4687
	or	ch, 20h
4164
	and	ch, not 80h	; 80-bit operand
4688
	and	ch, not 80h	; 80-bit operand
4165
@@:
4689
@@:
4166
	call	disasm_readrmop
4690
	call	disasm_readrmop
4167
	and	byte [edi], 0
4691
	and	byte [edi], 0
4168
	ret
4692
	ret
4169
.1:
4693
.1:
4170
	cmp	al, 0xE3
4694
	cmp	al, 0xE3
4171
	jnz	cunk
4695
	jnz	cunk
4172
	mov	eax, 'fnin'
4696
	mov	eax, 'fnin'
4173
	stosd
4697
	stosd
4174
	mov	eax, 'it'
4698
	mov	eax, 'it'
4175
	stosd
4699
	stosd
4176
	dec	edi
4700
	dec	edi
4177
	ret		; CF cleared
4701
	ret		; CF cleared
-
 
4702
 
4178
 
4703
iglobal
-
 
4704
fpuDC	dd	'add ','mul ',0,0,'subr','sub ','divr','div '
4179
fpuDC	dd	'add ','mul ',0,0,'subr','sub ','divr','div '
4705
endg
4180
cDC:
4706
cDC:
4181
	call	disasm_get_byte
4707
	call	disasm_get_byte
4182
	cmp	al, 0xC0
4708
	cmp	al, 0xC0
4183
	jae	.1
4709
	jae	.1
4184
	dec	[disasm_cur_pos]
4710
	dec	[disasm_cur_pos]
4185
	shr	al, 3
4711
	shr	al, 3
4186
	and	eax, 7
4712
	and	eax, 7
4187
	mov	byte [edi], 'f'
4713
	mov	byte [edi], 'f'
4188
	inc	edi
4714
	inc	edi
4189
	mov	eax, [fpuD8+eax*4]
4715
	mov	eax, [fpuD8+eax*4]
4190
	stosd
4716
	stosd
4191
	mov	ax, '  '
4717
	mov	ax, '  '
4192
	stosw
4718
	stosw
4193
	stosb
4719
	stosb
4194
	or	ch, 0A1h	; qword
4720
	or	ch, 0A1h	; qword
4195
	call	disasm_readrmop
4721
	call	disasm_readrmop
4196
	and	byte [edi], 0
4722
	and	byte [edi], 0
4197
	ret
4723
	ret
4198
.1:
4724
.1:
4199
	mov	dl, al
4725
	mov	dl, al
4200
	shr	al, 3
4726
	shr	al, 3
4201
	and	eax, 7
4727
	and	eax, 7
4202
	mov	eax, [fpuDC+eax*4]
4728
	mov	eax, [fpuDC+eax*4]
4203
	test	eax, eax
4729
	test	eax, eax
4204
	jz	cerr
4730
	jz	cerr
4205
	mov	byte [edi], 'f'
4731
	mov	byte [edi], 'f'
4206
	inc	edi
4732
	inc	edi
4207
	stosd
4733
	stosd
4208
	mov	eax, '   s'
4734
	mov	eax, '   s'
4209
	stosd
4735
	stosd
4210
	mov	al, 't'
4736
	mov	al, 't'
4211
	stosb
4737
	stosb
4212
	and	edx, 7
4738
	and	edx, 7
4213
	lea	eax, [edx+'0']
4739
	lea	eax, [edx+'0']
4214
	stosb
4740
	stosb
4215
	mov	eax, ', st'
4741
	mov	eax, ', st'
4216
	stosd
4742
	stosd
4217
	mov	ax, '0'
4743
	mov	ax, '0'
4218
	stosw
4744
	stosw
4219
	ret	; CF cleared
4745
	ret	; CF cleared
-
 
4746
 
4220
 
4747
iglobal
4221
fpuDD	dd	'fld ',0,'fst ','fstp',0,0,0,0
4748
fpuDD	dd	'fld ',0,'fst ','fstp',0,0,0,0
-
 
4749
fpuDD_2	dq	'ffree   ',0,'fst     ','fstp    ','fucom   ','fucomp  ',0,0
4222
fpuDD_2	dq	'ffree   ',0,'fst     ','fstp    ','fucom   ','fucomp  ',0,0
4750
endg
4223
cDD:
4751
cDD:
4224
	call	disasm_get_byte
4752
	call	disasm_get_byte
4225
	cmp	al, 0xC0
4753
	cmp	al, 0xC0
4226
	jae	.1
4754
	jae	.1
4227
	dec	[disasm_cur_pos]
4755
	dec	[disasm_cur_pos]
4228
	shr	al, 3
4756
	shr	al, 3
4229
	and	eax, 7
4757
	and	eax, 7
4230
	xchg	eax, edx
4758
	xchg	eax, edx
4231
	mov	eax, [fpuDD+edx*4]
4759
	mov	eax, [fpuDD+edx*4]
4232
	test	eax, eax
4760
	test	eax, eax
4233
	jz	cunk
4761
	jz	cunk
4234
	stosd
4762
	stosd
4235
	mov	eax, '    '
4763
	mov	eax, '    '
4236
	stosd
4764
	stosd
4237
	or	ch, 0A1h	; qword operand
4765
	or	ch, 0A1h	; qword operand
4238
	call	disasm_readrmop
4766
	call	disasm_readrmop
4239
	and	byte [edi], 0
4767
	and	byte [edi], 0
4240
	ret
4768
	ret
4241
.1:
4769
.1:
4242
	push	eax
4770
	push	eax
4243
	shr	al, 3
4771
	shr	al, 3
4244
	and	eax, 7
4772
	and	eax, 7
4245
	xchg	eax, edx
4773
	xchg	eax, edx
4246
	mov	eax, dword [fpuDD_2+edx*8]
4774
	mov	eax, dword [fpuDD_2+edx*8]
4247
	test	eax, eax
4775
	test	eax, eax
4248
	jz	cerr
4776
	jz	cerr
4249
	stosd
4777
	stosd
4250
	mov	eax, dword [fpuDD_2+4+edx*8]
4778
	mov	eax, dword [fpuDD_2+4+edx*8]
4251
	stosd
4779
	stosd
4252
	mov	ax, 'st'
4780
	mov	ax, 'st'
4253
	stosw
4781
	stosw
4254
	pop	eax
4782
	pop	eax
4255
	and	al, 7
4783
	and	al, 7
4256
	add	al, '0'
4784
	add	al, '0'
4257
	stosb
4785
	stosb
4258
	and	byte [edi], 0
4786
	and	byte [edi], 0
4259
	ret
4787
	ret
-
 
4788
 
4260
 
4789
iglobal
-
 
4790
fpuDE	dd	'add ','mul ',0,0,'subr','sub ','divr','div '
4261
fpuDE	dd	'add ','mul ',0,0,'subr','sub ','divr','div '
4791
endg
4262
cDE:
4792
cDE:
4263
	call	disasm_get_byte
4793
	call	disasm_get_byte
4264
	cmp	al, 0xC0
4794
	cmp	al, 0xC0
4265
	jae	.1
4795
	jae	.1
4266
	dec	[disasm_cur_pos]
4796
	dec	[disasm_cur_pos]
4267
	mov	word [edi], 'fi'
4797
	mov	word [edi], 'fi'
4268
	inc	edi
4798
	inc	edi
4269
	inc	edi
4799
	inc	edi
4270
	shr	al, 3
4800
	shr	al, 3
4271
	and	eax, 7
4801
	and	eax, 7
4272
	mov	eax, [fpuD8+eax*4]
4802
	mov	eax, [fpuD8+eax*4]
4273
	stosd
4803
	stosd
4274
	mov	ax, '  '
4804
	mov	ax, '  '
4275
	stosw
4805
	stosw
4276
	or	ch, 81h		; force 16-bit
4806
	or	ch, 81h		; force 16-bit
4277
	call	disasm_readrmop
4807
	call	disasm_readrmop
4278
	and	byte [edi], 0
4808
	and	byte [edi], 0
4279
	ret
4809
	ret
4280
.1:
4810
.1:
4281
	push	eax
4811
	push	eax
4282
	shr	al, 3
4812
	shr	al, 3
4283
	and	eax, 7
4813
	and	eax, 7
4284
	xchg	eax, edx
4814
	xchg	eax, edx
4285
	mov	eax, [fpuDE+edx*4]
4815
	mov	eax, [fpuDE+edx*4]
4286
	test	eax, eax
4816
	test	eax, eax
4287
	jz	.fcompp
4817
	jz	.fcompp
4288
	mov	byte [edi], 'f'
4818
	mov	byte [edi], 'f'
4289
	inc	edi
4819
	inc	edi
4290
	stosd
4820
	stosd
4291
	mov	al, 'p'
4821
	mov	al, 'p'
4292
	cmp	byte [edi-1], ' '
4822
	cmp	byte [edi-1], ' '
4293
	jnz	@f
4823
	jnz	@f
4294
	mov	byte [edi-1], al
4824
	mov	byte [edi-1], al
4295
	mov	al, ' '
4825
	mov	al, ' '
4296
@@:	stosb
4826
@@:	stosb
4297
	mov	eax, '  st'
4827
	mov	eax, '  st'
4298
	stosd
4828
	stosd
4299
	pop	eax
4829
	pop	eax
4300
	and	al, 7
4830
	and	al, 7
4301
	add	al, '0'
4831
	add	al, '0'
4302
	stosb
4832
	stosb
4303
	mov	ax, ', '
4833
	mov	ax, ', '
4304
	stosw
4834
	stosw
4305
	mov	eax, 'st0'
4835
	mov	eax, 'st0'
4306
	stosd
4836
	stosd
4307
	ret	; CF cleared
4837
	ret	; CF cleared
4308
.fcompp:
4838
.fcompp:
4309
	pop	eax
4839
	pop	eax
4310
	cmp	al, 0xD9
4840
	cmp	al, 0xD9
4311
	jnz	cerr
4841
	jnz	cerr
4312
	mov	eax, 'fcom'
4842
	mov	eax, 'fcom'
4313
	stosd
4843
	stosd
4314
	mov	ax, 'pp'
4844
	mov	ax, 'pp'
4315
	stosw
4845
	stosw
4316
	and	byte [edi], 0
4846
	and	byte [edi], 0
4317
	ret
4847
	ret
-
 
4848
 
4318
 
4849
iglobal
-
 
4850
fpuDF	dd	'ild ',0,'ist ','istp','bld ','ild ','bstp','istp'
4319
fpuDF	dd	'ild ',0,'ist ','istp','bld ','ild ','bstp','istp'
4851
endg
4320
 
4852
 
4321
cDF:
4853
cDF:
4322
	call	disasm_get_byte
4854
	call	disasm_get_byte
4323
	cmp	al, 0xC0
4855
	cmp	al, 0xC0
4324
	jae	.1
4856
	jae	.1
4325
	dec	[disasm_cur_pos]
4857
	dec	[disasm_cur_pos]
4326
	shr	al, 3
4858
	shr	al, 3
4327
	and	eax, 7
4859
	and	eax, 7
4328
	xchg	eax, edx
4860
	xchg	eax, edx
4329
	mov	eax, [fpuDF+edx*4]
4861
	mov	eax, [fpuDF+edx*4]
4330
	test	eax, eax
4862
	test	eax, eax
4331
	jz	cerr
4863
	jz	cerr
4332
	mov	byte [edi], 'f'
4864
	mov	byte [edi], 'f'
4333
	inc	edi
4865
	inc	edi
4334
	stosd
4866
	stosd
4335
	mov	ax, '  '
4867
	mov	ax, '  '
4336
	stosw
4868
	stosw
4337
	stosb
4869
	stosb
4338
	or	ch, 81h		; force 16-bit operand
4870
	or	ch, 81h		; force 16-bit operand
4339
	cmp	dl, 4
4871
	cmp	dl, 4
4340
	jb	@f
4872
	jb	@f
4341
	or	ch, 20h
4873
	or	ch, 20h
4342
	test	dl, 1
4874
	test	dl, 1
4343
	jnz	@f
4875
	jnz	@f
4344
	or	ch, 40h
4876
	or	ch, 40h
4345
@@:
4877
@@:
4346
	call	disasm_readrmop
4878
	call	disasm_readrmop
4347
	and	byte [edi], 0
4879
	and	byte [edi], 0
4348
	ret
4880
	ret
4349
.1:
4881
.1:
4350
	cmp	al, 0xE0
4882
	cmp	al, 0xE0
4351
	jnz	cunk
4883
	jnz	cunk
4352
	mov	eax, 'fnst'
4884
	mov	eax, 'fnst'
4353
	stosd
4885
	stosd
4354
	mov	eax, 'sw  '
4886
	mov	eax, 'sw  '
4355
	stosd
4887
	stosd
4356
	mov	ax, 'ax'
4888
	mov	ax, 'ax'
4357
	stosw
4889
	stosw
4358
	and	byte [edi], 0
4890
	and	byte [edi], 0
4359
	ret
4891
	ret
-
 
4892
 
-
 
4893
cmovd1:
-
 
4894
	mov	eax, 'movd'
-
 
4895
	stosd
-
 
4896
	mov	eax, '    '
-
 
4897
	stosd
-
 
4898
	call	disasm_get_byte
-
 
4899
	dec	[disasm_cur_pos]
-
 
4900
	shr	al, 3
-
 
4901
	and	eax, 7
-
 
4902
	call	disasm_write_mmreg
-
 
4903
	mov	ax, ', '
-
 
4904
	stosw
-
 
4905
	or	ch, 0C0h
-
 
4906
	and	ch, not 1
-
 
4907
	call	disasm_readrmop
-
 
4908
	and	byte [edi], 0
-
 
4909
	ret
-
 
4910
cmovd2:
-
 
4911
	mov	eax, 'movd'
-
 
4912
	stosd
-
 
4913
	mov	eax, '    '
-
 
4914
	stosd
-
 
4915
	call	disasm_get_byte
-
 
4916
	dec	[disasm_cur_pos]
-
 
4917
	shr	al, 3
-
 
4918
	and	eax, 7
-
 
4919
	push	eax ecx
-
 
4920
	or	ch, 0C0h
-
 
4921
	and	ch, not 1
-
 
4922
	call	disasm_readrmop
-
 
4923
	mov	ax, ', '
-
 
4924
	stosw
-
 
4925
	pop	ecx eax
-
 
4926
	call	disasm_write_mmreg
-
 
4927
	and	byte [edi], 0
-
 
4928
	ret
-
 
4929
 
-
 
4930
cmovq1:
-
 
4931
	test	ch, 1
-
 
4932
	jz	.mm
-
 
4933
	mov	eax, 'movd'
-
 
4934
	stosd
-
 
4935
	mov	eax, 'qa  '
-
 
4936
	stosd
-
 
4937
	jmp	disasm_mmx1
-
 
4938
.mm:
-
 
4939
	mov	eax, 'movq'
-
 
4940
	stosd
-
 
4941
	mov	eax, '    '
-
 
4942
	stosd
-
 
4943
	jmp	disasm_mmx1
-
 
4944
cmovq2:
-
 
4945
	test	ch, 1
-
 
4946
	jz	.mm
-
 
4947
	mov	eax, 'movd'
-
 
4948
	stosd
-
 
4949
	mov	eax, 'qa  '
-
 
4950
	stosd
-
 
4951
	jmp	disasm_mmx3
-
 
4952
.mm:
-
 
4953
	mov	eax, 'movq'
-
 
4954
disasm_mmx2:
-
 
4955
	stosd
-
 
4956
	mov	eax, '    '
-
 
4957
	stosd
-
 
4958
disasm_mmx3:
-
 
4959
	or	ch, 50h
-
 
4960
	call	disasm_get_byte
-
 
4961
	dec	[disasm_cur_pos]
-
 
4962
	push	eax
-
 
4963
	call	disasm_readrmop
-
 
4964
	mov	ax, ', '
-
 
4965
	stosw
-
 
4966
	pop	eax
-
 
4967
	shr	al, 3
-
 
4968
	and	eax, 7
-
 
4969
	call	disasm_write_mmreg
-
 
4970
	and	byte [edi], 0
-
 
4971
	ret
-
 
4972
 
-
 
4973
iglobal
-
 
4974
mmx_cmds:
-
 
4975
	db	0x60,'unpcklbw'
-
 
4976
	db	0x61,'unpcklwd'
-
 
4977
	db	0x62,'unpckldq'
-
 
4978
	db	0x63,'packsswb'
-
 
4979
	db	0x64,'pcmpgtb '
-
 
4980
	db	0x65,'pcmpgtw '
-
 
4981
	db	0x66,'pcmpgtd '
-
 
4982
	db	0x67,'packuswb'
-
 
4983
	db	0x68,'unpckhbw'
-
 
4984
	db	0x69,'unpckhwd'
-
 
4985
	db	0x6A,'unpckhdq'
-
 
4986
	db	0x6B,'packssdw'
-
 
4987
	db	0x74,'pcmpeqb '
-
 
4988
	db	0x75,'pcmpeqw '
-
 
4989
	db	0x76,'pcmpeqd '
-
 
4990
	db	0xD4,'paddq   '
-
 
4991
	db	0xD5,'pmullw  '
-
 
4992
	db	0xD8,'psubusb '
-
 
4993
	db	0xD9,'psubusw '
-
 
4994
	db	0xDA,'pminub  '
-
 
4995
	db	0xDB,'pand    '
-
 
4996
	db	0xDC,'paddusb '
-
 
4997
	db	0xDD,'paddusw '
-
 
4998
	db	0xDE,'pmaxub  '
-
 
4999
	db	0xDF,'pandn   '
-
 
5000
	db	0xE0,'pavgb   '
-
 
5001
	db	0xE3,'pavgw   '
-
 
5002
	db	0xE4,'pmulhuw '
-
 
5003
	db	0xE5,'pmulhw  '
-
 
5004
	db	0xE8,'psubsb  '
-
 
5005
	db	0xE9,'psubsw  '
-
 
5006
	db	0xEA,'pminsw  '
-
 
5007
	db	0xEB,'por     '
-
 
5008
	db	0xEC,'paddsb  '
-
 
5009
	db	0xED,'paddsw  '
-
 
5010
	db	0xEE,'pmaxsw  '
-
 
5011
	db	0xEF,'pxor    '
-
 
5012
	db	0xF4,'pmuludq '
-
 
5013
	db	0xF5,'pmaddwd '
-
 
5014
	db	0xF6,'psadbw  '
-
 
5015
	db	0xF8,'psubb   '
-
 
5016
	db	0xF9,'psubw   '
-
 
5017
	db	0xFA,'psubd   '
-
 
5018
	db	0xFB,'psubq   '
-
 
5019
	db	0xFC,'paddb   '
-
 
5020
	db	0xFD,'paddw   '
-
 
5021
	db	0xFE,'paddd   '
-
 
5022
endg
-
 
5023
cpcmn:
-
 
5024
	mov	esi, mmx_cmds
-
 
5025
@@:
-
 
5026
	cmp	al, [esi]
-
 
5027
	jz	@f
-
 
5028
	add	esi, 9
-
 
5029
	jmp	@b
-
 
5030
@@:
-
 
5031
	inc	esi
-
 
5032
	mov	al, 'p'
-
 
5033
	cmp	byte [esi], al
-
 
5034
	jz	@f
-
 
5035
	stosb
-
 
5036
@@:
-
 
5037
	movsd
-
 
5038
	movsd
-
 
5039
	cmp	byte [edi-1], ' '
-
 
5040
	jz	@f
-
 
5041
	mov	al, ' '
-
 
5042
	stosb
-
 
5043
@@:
-
 
5044
 
-
 
5045
disasm_mmx1:
-
 
5046
	or	ch, 50h
-
 
5047
	call	disasm_get_byte
-
 
5048
	dec	[disasm_cur_pos]
-
 
5049
	shr	al, 3
-
 
5050
	and	eax, 7
-
 
5051
	call	disasm_write_mmreg
-
 
5052
	mov	ax, ', '
-
 
5053
	stosw
-
 
5054
	call	disasm_readrmop
-
 
5055
	and	byte [edi], 0
-
 
5056
	ret
-
 
5057
 
-
 
5058
cpsrlw:
-
 
5059
	mov	eax, 'psrl'
-
 
5060
	jmp	@f
-
 
5061
cpsraw:
-
 
5062
	mov	eax, 'psra'
-
 
5063
	jmp	@f
-
 
5064
cpsllw:
-
 
5065
	mov	eax, 'psll'
-
 
5066
@@:
-
 
5067
	stosd
-
 
5068
	mov	eax, 'w   '
-
 
5069
	stosd
-
 
5070
	jmp	disasm_mmx1
-
 
5071
cpsrld:
-
 
5072
	mov	eax, 'psrl'
-
 
5073
	jmp	@f
-
 
5074
cpsrad:
-
 
5075
	mov	eax, 'psra'
-
 
5076
	jmp	@f
-
 
5077
cpslld:
-
 
5078
	mov	eax, 'psll'
-
 
5079
@@:
-
 
5080
	stosd
-
 
5081
	mov	eax, 'd   '
-
 
5082
	stosd
-
 
5083
	jmp	disasm_mmx1
-
 
5084
cpsrlq:
-
 
5085
	mov	eax, 'psrl'
-
 
5086
	jmp	@f
-
 
5087
cpsllq:
-
 
5088
	mov	eax, 'psll'
-
 
5089
@@:
-
 
5090
	stosd
-
 
5091
	mov	eax, 'q   '
-
 
5092
	stosd
-
 
5093
	jmp	disasm_mmx1
-
 
5094
 
-
 
5095
cpshift:
-
 
5096
	mov	dl, al
-
 
5097
	mov	ax, 'ps'
-
 
5098
	stosw
-
 
5099
	call	disasm_get_byte
-
 
5100
	push	eax
-
 
5101
	and	al, 0xC0
-
 
5102
	cmp	al, 0xC0
-
 
5103
	jnz	.pop_cunk
-
 
5104
	pop	eax
-
 
5105
	push	eax
-
 
5106
	shr	al, 3
-
 
5107
	and	eax, 7
-
 
5108
	cmp	al, 2
-
 
5109
	jz	.rl
-
 
5110
	cmp	al, 4
-
 
5111
	jz	.ra
-
 
5112
	cmp	al, 6
-
 
5113
	jz	.ll
-
 
5114
.pop_cunk:
-
 
5115
	pop	eax
-
 
5116
	jmp	cunk
-
 
5117
.ll:
-
 
5118
	mov	ax, 'll'
-
 
5119
	jmp	@f
-
 
5120
.rl:
-
 
5121
	mov	ax, 'rl'
-
 
5122
	jmp	@f
-
 
5123
.ra:
-
 
5124
	cmp	dl, 0x73
-
 
5125
	jz	.pop_cunk
-
 
5126
	mov	ax, 'ra'
-
 
5127
@@:
-
 
5128
	stosw
-
 
5129
	mov	al, 'w'
-
 
5130
	cmp	dl, 0x71
-
 
5131
	jz	@f
-
 
5132
	mov	al, 'd'
-
 
5133
	cmp	dl, 0x72
-
 
5134
	jz	@f
-
 
5135
	mov	al, 'q'
-
 
5136
@@:
-
 
5137
	stosb
-
 
5138
	mov	ax, '  '
-
 
5139
	stosw
-
 
5140
	stosb
-
 
5141
	pop	eax
-
 
5142
	and	eax, 7
-
 
5143
	call	disasm_write_mmreg
-
 
5144
	mov	ax, ', '
-
 
5145
	stosw
-
 
5146
	xor	eax, eax
-
 
5147
	call	disasm_get_byte
-
 
5148
	call	disasm_write_num
-
 
5149
	and	byte [edi], 0
-
 
5150
	ret
4360
 
5151
 
4361
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5152
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4362
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5153
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4363
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5154
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4364
 
5155
 
4365
caption_str db 'Kolibri Debugger',0
5156
caption_str db 'Kolibri Debugger',0
4366
caption_len = $ - caption_str
5157
caption_len = $ - caption_str
4367
begin_str db	'Kolibri Debugger, version 0.2',10
5158
begin_str db	'Kolibri Debugger, version 0.3',10
4368
	db	'Hint: type "help" for help, "quit" for quit'
5159
	db	'Hint: type "help" for help, "quit" for quit'
4369
newline	db	10,0
5160
newline	db	10,0
4370
prompt	db	'> ',0
5161
prompt	db	'> ',0
4371
 
5162
 
4372
help_groups:
5163
help_groups:
4373
	dd	aControl, 0, 0, help_control_msg
5164
	dd	aControl, 0, 0, help_control_msg
4374
	db	0
5165
	db	0
4375
	dd	aData, 0, 0, help_data_msg
5166
	dd	aData, 0, 0, help_data_msg
4376
	db	0
5167
	db	0
4377
	dd	aBreakpoints, 0, 0, help_breaks_msg
5168
	dd	aBreakpoints, 0, 0, help_breaks_msg
4378
	db	0
5169
	db	0
4379
; flags field:
5170
; flags field:
4380
; &1: command may be called without parameters
5171
; &1: command may be called without parameters
4381
; &2: command may be called with parameters
5172
; &2: command may be called with parameters
4382
; &4: command may be called without loaded program
5173
; &4: command may be called without loaded program
4383
; &8: command may be called with loaded program
5174
; &8: command may be called with loaded program
4384
commands:
5175
commands:
4385
	dd	_aH, OnHelp, HelpSyntax, HelpHelp
5176
	dd	_aH, OnHelp, HelpSyntax, HelpHelp
4386
	db	0Fh
5177
	db	0Fh
4387
	dd	aHelp, OnHelp, HelpSyntax, HelpHelp
5178
	dd	aHelp, OnHelp, HelpSyntax, HelpHelp
4388
	db	0Fh
5179
	db	0Fh
4389
	dd	aQuit, OnQuit, QuitSyntax, QuitHelp
5180
	dd	aQuit, OnQuit, QuitSyntax, QuitHelp
4390
	db	0Dh
5181
	db	0Dh
4391
	dd	aLoad, OnLoad, LoadSyntax, LoadHelp
5182
	dd	aLoad, OnLoad, LoadSyntax, LoadHelp
4392
	db	6
5183
	db	6
4393
	dd	aReload, OnReload, ReloadSyntax, ReloadHelp
5184
	dd	aReload, OnReload, ReloadSyntax, ReloadHelp
4394
	db	0Dh
5185
	db	0Dh
4395
	dd	aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
5186
	dd	aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
4396
	db	9
5187
	db	9
4397
	dd	aDetach, OnDetach, DetachSyntax, DetachHelp
5188
	dd	aDetach, OnDetach, DetachSyntax, DetachHelp
4398
	db	9
5189
	db	9
4399
	dd	aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
5190
	dd	aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
4400
	db	9
5191
	db	9
4401
	dd	aResume, OnResume, ResumeSyntax, ResumeHelp
5192
	dd	aResume, OnResume, ResumeSyntax, ResumeHelp
4402
	db	0Bh
5193
	db	0Bh
4403
	dd	aStep, OnStep, StepSyntax, StepHelp
5194
	dd	aStep, OnStep, StepSyntax, StepHelp
4404
	db	9
5195
	db	9
4405
	dd	aProceed, OnProceed, ProceedSyntax, ProceedHelp
5196
	dd	aProceed, OnProceed, ProceedSyntax, ProceedHelp
4406
	db	9
5197
	db	9
4407
	dd	aCalc, OnCalc, CalcSyntax, CalcHelp
5198
	dd	aCalc, OnCalc, CalcSyntax, CalcHelp
4408
	db	0Eh
5199
	db	0Eh
4409
	dd	aDump, OnDump, DumpSyntax, DumpHelp
5200
	dd	aDump, OnDump, DumpSyntax, DumpHelp
4410
	db	0Bh
5201
	db	0Bh
4411
	dd	aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
5202
	dd	aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
4412
	db	0Bh
5203
	db	0Bh
4413
	dd	aBp, OnBp, BpSyntax, BpHelp
5204
	dd	aBp, OnBp, BpSyntax, BpHelp
4414
	db	0Ah
5205
	db	0Ah
4415
	dd	aBpm, OnBpmb, BpmSyntax, BpmHelp
5206
	dd	aBpm, OnBpmb, BpmSyntax, BpmHelp
4416
	db	0Ah
5207
	db	0Ah
4417
	dd	aBpmb, OnBpmb, BpmSyntax, BpmHelp
5208
	dd	aBpmb, OnBpmb, BpmSyntax, BpmHelp
4418
	db	0Ah
5209
	db	0Ah
4419
	dd	aBpmw, OnBpmw, BpmSyntax, BpmHelp
5210
	dd	aBpmw, OnBpmw, BpmSyntax, BpmHelp
4420
	db	0Ah
5211
	db	0Ah
4421
	dd	aBpmd, OnBpmd, BpmSyntax, BpmHelp
5212
	dd	aBpmd, OnBpmd, BpmSyntax, BpmHelp
4422
	db	0Ah
5213
	db	0Ah
4423
	dd	aBl, OnBl, BlSyntax, BlHelp
5214
	dd	aBl, OnBl, BlSyntax, BlHelp
4424
	db	0Bh
5215
	db	0Bh
4425
	dd	aBc, OnBc, BcSyntax, BcHelp
5216
	dd	aBc, OnBc, BcSyntax, BcHelp
4426
	db	0Ah
5217
	db	0Ah
4427
	dd	aBd, OnBd, BdSyntax, BdHelp
5218
	dd	aBd, OnBd, BdSyntax, BdHelp
4428
	db	0Ah
5219
	db	0Ah
4429
	dd	aBe, OnBe, BeSyntax, BeHelp
5220
	dd	aBe, OnBe, BeSyntax, BeHelp
4430
	db	0Ah
5221
	db	0Ah
4431
	dd	aReg, OnReg, RSyntax, RHelp
5222
	dd	aReg, OnReg, RSyntax, RHelp
4432
	db	0Ah
5223
	db	0Ah
4433
	dd	aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
5224
	dd	aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
4434
	db	9
5225
	db	9
-
 
5226
	dd	aLoadSymbols, OnLoadSymbols, LoadSymbolsSyntax, LoadSymbolsHelp
-
 
5227
	db	0Ah
4435
	dd	0
5228
	dd	0
4436
aHelp	db	5,'help',0
5229
aHelp	db	5,'help',0
4437
_aH	db	2,'h',0
5230
_aH	db	2,'h',0
4438
HelpHelp db	'Help on specified function',10
5231
HelpHelp db	'Help on specified function',10
4439
HelpSyntax db	'Usage: h or help [group | command]',10,0
5232
HelpSyntax db	'Usage: h or help [group | command]',10,0
4440
 
5233
 
4441
help_msg db	'List of known command groups:',10
5234
help_msg db	'List of known command groups:',10
4442
	db	'"help control"     - display list of control commands',10
5235
	db	'"help control"     - display list of control commands',10
4443
	db	'"help data"        - display list of commands concerning data',10
5236
	db	'"help data"        - display list of commands concerning data',10
4444
	db	'"help breakpoints" - display list of commands concerning breakpoints',10,0
5237
	db	'"help breakpoints" - display list of commands concerning breakpoints',10,0
4445
aControl db	8,'control',0
5238
aControl db	8,'control',0
4446
help_control_msg db	'List of control commands:',10
5239
help_control_msg db	'List of control commands:',10
4447
	db	'h = help             - help',10
5240
	db	'h = help             - help',10
4448
	db	'quit                 - exit from debugger',10
5241
	db	'quit                 - exit from debugger',10
4449
	db	'load  [params] - load program for debugging',10
5242
	db	'load  [params] - load program for debugging',10
4450
	db	'reload               - reload debugging program',10
5243
	db	'reload               - reload debugging program',10
-
 
5244
	db	'load-symbols   - load information on symbols for program',10
4451
	db	'terminate            - terminate loaded program',10
5245
	db	'terminate            - terminate loaded program',10
4452
	db	'detach               - detach from debugging program',10
5246
	db	'detach               - detach from debugging program',10
4453
	db	'stop                 - suspend execution of debugging program',10
5247
	db	'stop                 - suspend execution of debugging program',10
4454
	db	'g []     - go on (resume execution of debugging program)',10
5248
	db	'g []     - go on (resume execution of debugging program)',10
4455
	db	's =         - program step',10
5249
	db	's =         - program step',10
4456
	db	'p =         - program wide step',10
5250
	db	'p =         - program wide step',10
4457
	db	'unpack               - try to bypass unpacker code (heuristic)',10,0
5251
	db	'unpack               - try to bypass unpacker code (heuristic)',10,0
4458
aData	db	5,'data',0
5252
aData	db	5,'data',0
4459
help_data_msg db	'List of data commands:',10
5253
help_data_msg db	'List of data commands:',10
4460
	db	'?        - calculate value of expression',10
5254
	db	'?        - calculate value of expression',10
4461
	db	'd []     - dump data at given address',10
5255
	db	'd []     - dump data at given address',10
4462
	db	'u []     - unassemble instructions at given address',10
5256
	db	'u []     - unassemble instructions at given address',10
4463
	db	'r   or',10
5257
	db	'r   or',10
4464
	db	'r = - set register value',10,0
5258
	db	'r = - set register value',10,0
4465
aBreakpoints db 12,'breakpoints',0
5259
aBreakpoints db 12,'breakpoints',0
4466
help_breaks_msg db	'List of breakpoints commands:',10
5260
help_breaks_msg db	'List of breakpoints commands:',10
4467
	db	'bp       - set breakpoint on execution',10
5261
	db	'bp       - set breakpoint on execution',10
4468
	db	'bpm[b|w|d]   - set breakpoint on memory access',10
5262
	db	'bpm[b|w|d]   - set breakpoint on memory access',10
4469
	db	'bl []        - breakpoint(s) info',10
5263
	db	'bl []        - breakpoint(s) info',10
4470
	db	'bc ...       - clear breakpoint',10
5264
	db	'bc ...       - clear breakpoint',10
4471
	db	'bd ...       - disable breakpoint',10
5265
	db	'bd ...       - disable breakpoint',10
4472
	db	'be ...       - enable breakpoint',10,0
5266
	db	'be ...       - enable breakpoint',10,0
4473
 
5267
 
4474
aQuit	db	5,'quit',0
5268
aQuit	db	5,'quit',0
4475
QuitHelp db	'Quit from debugger',10
5269
QuitHelp db	'Quit from debugger',10
4476
QuitSyntax db	'Usage: quit',10,0
5270
QuitSyntax db	'Usage: quit',10,0
4477
 
5271
 
4478
aLoad	db	5,'load',0
5272
aLoad	db	5,'load',0
4479
LoadHelp db	'Load program for debugging',10
5273
LoadHelp db	'Load program for debugging',10
4480
LoadSyntax db	'Usage: load  [parameters]',10,0
5274
LoadSyntax db	'Usage: load  [parameters]',10,0
4481
 
5275
 
4482
aReload db	7,'reload',0
5276
aReload db	7,'reload',0
4483
ReloadHelp db	'Reload debugging program (restart debug session)',10
5277
ReloadHelp db	'Reload debugging program (restart debug session)',10
4484
ReloadSyntax db	'Usage: reload',10,0
5278
ReloadSyntax db	'Usage: reload',10,0
4485
 
5279
 
4486
aTerminate db	10,'terminate',0
5280
aTerminate db	10,'terminate',0
4487
TerminateHelp db 'Terminate debugged program',10
5281
TerminateHelp db 'Terminate debugged program',10
4488
TerminateSyntax db 'Usage: terminate',10,0
5282
TerminateSyntax db 'Usage: terminate',10,0
4489
 
5283
 
4490
aDetach	db	7,'detach',0
5284
aDetach	db	7,'detach',0
4491
DetachHelp db	'Detach from debugged program',10
5285
DetachHelp db	'Detach from debugged program',10
4492
DetachSyntax db	'Usage: detach',10,0
5286
DetachSyntax db	'Usage: detach',10,0
4493
 
5287
 
4494
aSuspend db	5,'stop',0
5288
aSuspend db	5,'stop',0
4495
SuspendHelp db	'Suspend execution of debugged program',10
5289
SuspendHelp db	'Suspend execution of debugged program',10
4496
SuspendSyntax db 'Usage: stop',10,0
5290
SuspendSyntax db 'Usage: stop',10,0
4497
 
5291
 
4498
aResume db	2,'g',0
5292
aResume db	2,'g',0
4499
ResumeHelp db	'Go (resume execution of debugged program)',10
5293
ResumeHelp db	'Go (resume execution of debugged program)',10
4500
ResumeSyntax db	'Usage: g',10
5294
ResumeSyntax db	'Usage: g',10
4501
	db	'   or: g  - wait until specified address is reached',10,0
5295
	db	'   or: g  - wait until specified address is reached',10,0
4502
 
5296
 
4503
aStep	db	2,'s',0
5297
aStep	db	2,'s',0
4504
StepHelp db	'Make step in debugged program',10
5298
StepHelp db	'Make step in debugged program',10
4505
StepSyntax db	'Usage: s',10,0
5299
StepSyntax db	'Usage: s',10,0
4506
 
5300
 
4507
aProceed db	2,'p',0
5301
aProceed db	2,'p',0
4508
ProceedHelp db	'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10
5302
ProceedHelp db	'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10
4509
ProceedSyntax db 'Usage: p',10,0
5303
ProceedSyntax db 'Usage: p',10,0
4510
 
5304
 
4511
aDump	db	2,'d',0
5305
aDump	db	2,'d',0
4512
DumpHelp db	'Dump data of debugged program',10
5306
DumpHelp db	'Dump data of debugged program',10
4513
DumpSyntax db	'Usage: d  - dump data at specified address',10
5307
DumpSyntax db	'Usage: d  - dump data at specified address',10
4514
	db	'   or: d              - continue current dump',10,0
5308
	db	'   or: d              - continue current dump',10,0
4515
 
5309
 
4516
aCalc	db	2,'?',0
5310
aCalc	db	2,'?',0
4517
CalcHelp db	'Calculate value of expression',10
5311
CalcHelp db	'Calculate value of expression',10
4518
CalcSyntax db	'Usage: ? ',10,0
5312
CalcSyntax db	'Usage: ? ',10,0
4519
 
5313
 
4520
aUnassemble db	2,'u',0
5314
aUnassemble db	2,'u',0
4521
UnassembleHelp db 'Unassemble',10
5315
UnassembleHelp db 'Unassemble',10
4522
UnassembleSyntax:
5316
UnassembleSyntax:
4523
	db	'Usage: u  - unassemble instructions at specified address',10
5317
	db	'Usage: u  - unassemble instructions at specified address',10
4524
	db	'   or: u              - continue current unassemble screen',10,0
5318
	db	'   or: u              - continue current unassemble screen',10,0
4525
 
5319
 
4526
aReg	db	2,'r',0
5320
aReg	db	2,'r',0
4527
RHelp	db	'Set register value',10
5321
RHelp	db	'Set register value',10
4528
RSyntax:
5322
RSyntax:
4529
	db	'Usage: r  ',10
5323
	db	'Usage: r  ',10
4530
	db	'   or: r = - set value of  to ',10,0
5324
	db	'   or: r = - set value of  to ',10,0
4531
 
5325
 
4532
aBp	db	3,'bp',0
5326
aBp	db	3,'bp',0
4533
BpHelp	db	'set BreakPoint on execution',10
5327
BpHelp	db	'set BreakPoint on execution',10
4534
BpSyntax db	'Usage: bp ',10,0
5328
BpSyntax db	'Usage: bp ',10,0
4535
 
5329
 
4536
aBpm	db	4,'bpm',0
5330
aBpm	db	4,'bpm',0
4537
aBpmb	db	5,'bpmb',0
5331
aBpmb	db	5,'bpmb',0
4538
aBpmw	db	5,'bpmw',0
5332
aBpmw	db	5,'bpmw',0
4539
aBpmd	db	5,'bpmd',0
5333
aBpmd	db	5,'bpmd',0
4540
BpmHelp	db	'set BreakPoint on Memory access',10
5334
BpmHelp	db	'set BreakPoint on Memory access',10
4541
	db	'Maximum 4 breakpoints of this type are allowed',10
5335
	db	'Maximum 4 breakpoints of this type are allowed',10
4542
	db	'Note that for this breaks debugger is activated after access',10
5336
	db	'Note that for this breaks debugger is activated after access',10
4543
BpmSyntax db	'Usage: bpmb [w] ',10
5337
BpmSyntax db	'Usage: bpmb [w] ',10
4544
	db	'       bpmw [w] ',10
5338
	db	'       bpmw [w] ',10
4545
	db	'       bpmd [w] ',10
5339
	db	'       bpmd [w] ',10
4546
	db	'       bpm is synonym for bpmd',10
5340
	db	'       bpm is synonym for bpmd',10
4547
	db	'"w" means break only on writes (default is on read/write)',10,0
5341
	db	'"w" means break only on writes (default is on read/write)',10,0
4548
 
5342
 
4549
aBl	db	3,'bl',0
5343
aBl	db	3,'bl',0
4550
BlHelp	db	'Breakpoint List',10
5344
BlHelp	db	'Breakpoint List',10
4551
BlSyntax db	'Usage: bl          - list all breakpoints',10
5345
BlSyntax db	'Usage: bl          - list all breakpoints',10
4552
	db	'       bl  - display info on particular breakpoint',10,0
5346
	db	'       bl  - display info on particular breakpoint',10,0
4553
 
5347
 
4554
aBc	db	3,'bc',0
5348
aBc	db	3,'bc',0
4555
BcHelp	db	'Breakpoint Clear',10
5349
BcHelp	db	'Breakpoint Clear',10
4556
BcSyntax db	'Usage: bc ',10
5350
BcSyntax db	'Usage: bc ',10
4557
	db	'Examples: bc 2',10
5351
	db	'Examples: bc 2',10
4558
	db	'          bc 1 3 4 A',10,0
5352
	db	'          bc 1 3 4 A',10,0
4559
 
5353
 
4560
aBd	db	3,'bd',0
5354
aBd	db	3,'bd',0
4561
BdHelp	db	'Breakpoint Disable',10
5355
BdHelp	db	'Breakpoint Disable',10
4562
BdSyntax db	'Usage: bd ',10
5356
BdSyntax db	'Usage: bd ',10
4563
	db	'Examples: bd 2',10
5357
	db	'Examples: bd 2',10
4564
	db	'          bd 1 3 4 A',10,0
5358
	db	'          bd 1 3 4 A',10,0
4565
 
5359
 
4566
aBe	db	3,'be',0
5360
aBe	db	3,'be',0
4567
BeHelp	db	'Breakpoint Enable',10
5361
BeHelp	db	'Breakpoint Enable',10
4568
BeSyntax db	'Usage: be ',10
5362
BeSyntax db	'Usage: be ',10
4569
	db	'Examples: be 2',10
5363
	db	'Examples: be 2',10
4570
	db	'          be 1 3 4 A',10,0
5364
	db	'          be 1 3 4 A',10,0
4571
 
5365
 
4572
aUnpack	db	7,'unpack',0
5366
aUnpack	db	7,'unpack',0
4573
UnpackHelp db	'Try to bypass unpacker code',10
5367
UnpackHelp db	'Try to bypass unpacker code',10
4574
UnpackSyntax db	'Usage: unpack',10,0
5368
UnpackSyntax db	'Usage: unpack',10,0
-
 
5369
 
-
 
5370
aLoadSymbols db	13,'load-symbols',0
-
 
5371
LoadSymbolsHelp db 'Load symbolic information for executable',10
-
 
5372
LoadSymbolsSyntax db 'Usage: load-symbols ',10,0
4575
 
5373
 
4576
aUnknownCommand db 'Unknown command',10,0
5374
aUnknownCommand db 'Unknown command',10,0
4577
 
5375
 
4578
load_err_msg	db	'Cannot load program. ',0
5376
load_err_msg	db	'Cannot load program. ',0
4579
unk_err_msg	db	'Unknown error code -%4X',10,0
5377
unk_err_msg	db	'Unknown error code -%4X',10,0
-
 
5378
aCannotLoadFile	db	'Cannot load file. ',0
-
 
5379
unk_err_msg2	db	'Unknown error code %4X.',10,0
4580
load_err_msgs:
5380
load_err_msgs:
4581
	dd	.1, 0, .3, 0, .5, .6, 0, 0, .9, .A, 0, 0, 0, 0, 0, 0
5381
	dd	.1, 0, .3, 0, .5, .6, 0, 0, .9, .A, 0, 0, 0, 0, 0, 0
4582
	dd	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .1E, .1F, .20
5382
	dd	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .1E, .1F, .20
4583
.1		db	'HD undefined.',10,0
5383
.1		db	'HD undefined.',10,0
4584
.3		db	'Unknown FS.',10,0
5384
.3		db	'Unknown FS.',10,0
4585
.5		db	'File not found.',10,0
5385
.5		db	'File not found.',10,0
4586
.6		db	'Unexpected EOF.',10,0
5386
.6		db	'Unexpected EOF.',10,0
4587
.9		db	'FAT table corrupted.',10,0
5387
.9		db	'FAT table corrupted.',10,0
4588
.A		db	'Access denied.',10,0
5388
.A		db	'Access denied.',10,0
4589
.1E		db	'No memory.',10,0
5389
.1E		db	'No memory.',10,0
4590
.1F		db	'Not Menuet/Kolibri executable.',10,0
5390
.1F		db	'Not Menuet/Kolibri executable.',10,0
4591
.20		db	'Too many processes.',10,0
5391
.20		db	'Too many processes.',10,0
4592
load_succ_msg	db	'Program loaded successfully! PID=%4X. Use "g" to run.',10,0
5392
load_succ_msg	db	'Program loaded successfully! PID=%4X. Use "g" to run.',10,0
4593
need_debuggee	db	'No program loaded. Use "load" command.',10,0
5393
need_debuggee	db	'No program loaded. Use "load" command.',10,0
4594
aAlreadyLoaded	db	'Program is already loaded. Use "terminate" or "detach" commands',10,0
5394
aAlreadyLoaded	db	'Program is already loaded. Use "terminate" or "detach" commands',10,0
4595
terminated_msg	db	'Program terminated.',10,0
5395
terminated_msg	db	'Program terminated.',10,0
4596
aException	db	'Debugged program caused an exception %2X. '
5396
aException	db	'Debugged program caused an exception %2X. '
4597
aSuspended	db	'Suspended',10,0
5397
aSuspended	db	'Suspended',10,0
4598
aContinued	db	'Continuing',10,0
5398
aContinued	db	'Continuing',10,0
4599
aRunningErr	db	'Program is running',10,0
5399
aRunningErr	db	'Program is running',10,0
4600
read_mem_err	db	'ERROR: cannot read process memory!!!',10,0
5400
read_mem_err	db	'ERROR: cannot read process memory!!!',10,0
4601
aBreakpointLimitExceeded db 'Breakpoint limit exceeded',10,0
5401
aBreakpointLimitExceeded db 'Breakpoint limit exceeded',10,0
4602
aBreakErr	db	'Cannot activate breakpoint, it will be disabled',10,0
5402
aBreakErr	db	'Cannot activate breakpoint, it will be disabled',10,0
4603
aDuplicateBreakpoint db	'Duplicate breakpoint',10,0
5403
aDuplicateBreakpoint db	'Duplicate breakpoint',10,0
4604
aInvalidBreak	db	'Invalid breakpoint number',10,0
5404
aInvalidBreak	db	'Invalid breakpoint number',10,0
4605
OnBeErrMsg	db	'There is already enabled breakpoint on this address',10,0
5405
OnBeErrMsg	db	'There is already enabled breakpoint on this address',10,0
4606
aBreakNum	db	'%2X: at %8X',0
5406
aBreakNum	db	'%2X: at %8X',0
4607
aMemBreak1	db	'%2X: on ',0
5407
aMemBreak1	db	'%2X: on ',0
4608
aMemBreak2	db	'read from ',0
5408
aMemBreak2	db	'read from ',0
4609
aMemBreak3	db	'access of ',0
5409
aMemBreak3	db	'access of ',0
4610
aMemBreak4	db	'byte',0
5410
aMemBreak4	db	'byte',0
4611
aMemBreak5	db	'word',0
5411
aMemBreak5	db	'word',0
4612
aMemBreak6	db	'dword',0
5412
aMemBreak6	db	'dword',0
4613
aMemBreak7	db	' at %8X',0
5413
aMemBreak7	db	' at %8X',0
4614
aOneShot	db	', one-shot',0
5414
aOneShot	db	', one-shot',0
4615
aDisabled	db	', disabled',0
5415
aDisabled	db	', disabled',0
4616
aBreakStop	db	'Breakpoint #%2X',10,0
5416
aBreakStop	db	'Breakpoint #%2X',10,0
4617
aUserBreak	db	'int3 command at %8X',10,0
5417
aUserBreak	db	'int3 command at %8X',10,0
4618
;dbgmsg_str	db	'Debug message for process %4X.',10,0
5418
;dbgmsg_str	db	'Debug message for process %4X.',10,0
4619
aInvAddr	db	'Invalid address',10,0
5419
aInvAddr	db	'Invalid address',10,0
4620
NoPrgLoaded_str	db	'No program loaded'
5420
NoPrgLoaded_str	db	'No program loaded'
4621
NoPrgLoaded_len = $ - NoPrgLoaded_str
5421
NoPrgLoaded_len = $ - NoPrgLoaded_str
4622
aRunning	db	'Running'
5422
aRunning	db	'Running'
4623
aPaused		db	'Paused'
5423
aPaused		db	'Paused'
4624
aPoint		db	0x1C
5424
aPoint		db	0x1C
4625
aMinus		db	'-'
5425
aMinus		db	'-'
4626
aColon		db	':'
5426
aColon		db	':'
4627
aQuests		db	'??'
5427
aQuests		db	'??'
4628
aDots		db	'...'
5428
aDots		db	'...'
4629
aParseError	db	'Parse error',10,0
5429
aParseError	db	'Parse error',10,0
4630
aDivByZero	db	'Division by 0',10,0
5430
aDivByZero	db	'Division by 0',10,0
4631
calc_string	db	'%8X',10,0
5431
calc_string	db	'%8X',10,0
-
 
5432
aNoMemory	db	'No memory',10,0
-
 
5433
aSymbolsLoaded	db	'Symbols loaded',10,0
4632
aUnaligned	db	'Unaligned address',10,0
5434
aUnaligned	db	'Unaligned address',10,0
4633
aEnabledBreakErr db	'Enabled breakpoints are not allowed',10,0
5435
aEnabledBreakErr db	'Enabled breakpoints are not allowed',10,0
4634
aInterrupted	db	'Interrupted',10,0
5436
aInterrupted	db	'Interrupted',10,0
4635
aUnpacked	db	'Unpacked successful!',10,0
5437
aUnpacked	db	'Unpacked successful!',10,0
4636
aPacked1	db	'Program is probably packed with ',0
5438
aPacked1	db	'Program is probably packed with ',0
4637
aPacked2	db	'.',10,'Try to unpack automatically? [y/n]: ',0
5439
aPacked2	db	'.',10,'Try to unpack automatically? [y/n]: ',0
4638
aY_str		db	'y',10,0
5440
aY_str		db	'y',10,0
4639
aN_str		db	'n',10,0
5441
aN_str		db	'n',10,0
4640
mxp_nrv_name	db	'mxp_nrv',0
5442
mxp_nrv_name	db	'mxp_nrv',0
4641
mxp_name	db	'mxp',0
5443
mxp_name	db	'mxp',0
4642
mxp_lzo_name	db	'mxp_lzo',0
5444
mxp_lzo_name	db	'mxp_lzo',0
4643
mtappack_name	db	'mtappack',0
5445
mtappack_name	db	'mtappack',0
4644
flags		db	'CPAZSDO'
5446
flags		db	'CPAZSDO'
4645
flags_bits	db	0,2,4,6,7,10,11
5447
flags_bits	db	0,2,4,6,7,10,11
4646
regs_strs:
5448
regs_strs:
4647
	db	'EAX='
5449
	db	'EAX='
4648
	db	'EBX='
5450
	db	'EBX='
4649
	db	'ECX='
5451
	db	'ECX='
4650
	db	'EDX='
5452
	db	'EDX='
4651
	db	'ESI='
5453
	db	'ESI='
4652
	db	'EDI='
5454
	db	'EDI='
4653
	db	'EBP='
5455
	db	'EBP='
4654
	db	'ESP='
5456
	db	'ESP='
4655
	db	'EIP='
5457
	db	'EIP='
4656
	db	'EFLAGS='
5458
	db	'EFLAGS='
4657
 
5459
 
4658
debuggee_pid	dd	0
5460
debuggee_pid	dd	0
4659
bSuspended	db	0
5461
bSuspended	db	0
4660
bAfterGo	db	0
5462
bAfterGo	db	0
4661
temp_break	dd	0
5463
temp_break	dd	0
4662
 
5464
 
4663
disasm_table_1:
5465
disasm_table_1:
4664
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0		; 0x
5466
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0		; 0x
4665
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cF
5467
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cF
4666
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0		; 1x
5468
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0		; 1x
4667
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0
5469
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0
4668
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cseges,cop0		; 2x
5470
	dd	cop22, cop22, cop22, cop22, cop21, cop21, cseges,cop0		; 2x
4669
	dd	cop22, cop22, cop22, cop22, cop21, cop21, csegcs,cop0
5471
	dd	cop22, cop22, cop22, cop22, cop21, cop21, csegcs,cop0
4670
	dd	cop22, cop22, cop22, cop22, cop21, cop21, csegss,cop0		; 3x
5472
	dd	cop22, cop22, cop22, cop22, cop21, cop21, csegss,cop0		; 3x
4671
	dd	cop22, cop22, cop22, cop22, cop21, cop21, csegds,cop0
5473
	dd	cop22, cop22, cop22, cop22, cop21, cop21, csegds,cop0
4672
	dd	cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1		; 4x
5474
	dd	cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1		; 4x
4673
	dd	cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1
5475
	dd	cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1
4674
	dd	cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1		; 5x
5476
	dd	cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1		; 5x
4675
	dd	cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1
5477
	dd	cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1
4676
	dd	cop0,  cop0,  cunk,  cunk,  csegfs,cseggs,c66,   c67		; 6x
5478
	dd	cop0,  cop0,  cunk,  cunk,  csegfs,cseggs,c66,   c67		; 6x
4677
	dd	cpush21,cimul1,cpush22,cimul1,cunk,cunk,  cunk,  cunk
5479
	dd	cpush21,cimul1,cpush22,cimul1,cunk,cunk,  cunk,  cunk
4678
	dd	cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1		; 7x
5480
	dd	cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1		; 7x
4679
	dd	cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1
5481
	dd	cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1
4680
	dd	cop23, cop23, cop23, cop23, cop22, cop22, cop22, cop22		; 8x
5482
	dd	cop23, cop23, cop23, cop23, cop22, cop22, cop22, cop22		; 8x
4681
	dd	cop22, cop22, cop22, cop22, cunk,  cop22, cunk,  cpop2
5483
	dd	cop22, cop22, cop22, cop22, cunk,  cop22, cunk,  cpop2
4682
	dd	cop0,  cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1		; 9x
5484
	dd	cop0,  cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1		; 9x
4683
	dd	ccbw,  ccwd,  cunk,  cop0,  cop0,  cop0,  cop0,  cop0
5485
	dd	ccbw,  ccwd,  cunk,  cop0,  cop0,  cop0,  cop0,  cop0
4684
	dd	cmov3, cmov3, cmov3, cmov3, cop0,  cop0,  cop0,  cop0		; Ax
5486
	dd	cmov3, cmov3, cmov3, cmov3, cop0,  cop0,  cop0,  cop0		; Ax
4685
	dd	cop21, cop21, cop0,  cop0,  cop0,  cop0,  cop0,  cop0
5487
	dd	cop21, cop21, cop0,  cop0,  cop0,  cop0,  cop0,  cop0
4686
	dd	cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11		; Bx
5488
	dd	cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11		; Bx
4687
	dd	cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12
5489
	dd	cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12
4688
	dd	cshift1,cshift1,cret2,cop0, cunk,  cunk,  cmov2, cmov2		; Cx
5490
	dd	cshift1,cshift1,cret2,cop0, cunk,  cunk,  cmov2, cmov2		; Cx
4689
	dd	center,cop0,  cunk,  cunk,  cop0,  cint,  cunk,  cunk
5491
	dd	center,cop0,  cunk,  cunk,  cop0,  cint,  cunk,  cunk
4690
	dd	cshift2,cshift2,cshift3,cshift3,caam,cunk,cunk,  cxlat		; Dx
5492
	dd	cshift2,cshift2,cshift3,cshift3,caam,cunk,cunk,  cxlat		; Dx
4691
	dd	cD8,   cD9,   cDA,   cDB,   cDC,   cDD,   cDE,   cDF
5493
	dd	cD8,   cD9,   cDA,   cDB,   cDC,   cDD,   cDE,   cDF
4692
	dd	cloopnz,cloopz,cloop,cjcxz, cunk,  cunk,  cunk,  cunk		; Ex
5494
	dd	cloopnz,cloopz,cloop,cjcxz, cunk,  cunk,  cunk,  cunk		; Ex
4693
	dd	ccall1,cjmp1, cunk,  cjmp2, cunk,  cunk,  cunk,  cunk
5495
	dd	ccall1,cjmp1, cunk,  cjmp2, cunk,  cunk,  cunk,  cunk
4694
	dd	clock, cunk,  crepnz,crep,  cunk,  cop0,  cop1,  cop1		; Fx
5496
	dd	clock, cunk,  crepnz,crep,  cunk,  cop0,  cop1,  cop1		; Fx
4695
	dd	cop0,  cop0,  cop0,  cop0,  cop0,  cop0,  cop1,  cop1
5497
	dd	cop0,  cop0,  cop0,  cop0,  cop0,  cop0,  cop1,  cop1
4696
 
5498
 
4697
disasm_table_2:
5499
disasm_table_2:
4698
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  csyscall,cunk,cunk		; 0x
5500
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  csyscall,cunk,cunk		; 0x
4699
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5501
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
4700
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; 1x
5502
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; 1x
4701
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5503
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
4702
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; 2x
5504
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; 2x
4703
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5505
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
4704
	dd	cunk,  crdtsc,cunk,  cunk,  csysenter,cunk,cunk, cunk		; 3x
5506
	dd	cunk,  crdtsc,cunk,  cunk,  csysenter,cunk,cunk, cunk		; 3x
4705
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5507
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
4706
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; 4x
5508
	dd	cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc		; 4x
4707
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5509
	dd	cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc
4708
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; 5x
5510
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; 5x
4709
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5511
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
4710
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; 6x
5512
	dd	cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn		; 6x
4711
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5513
	dd	cpcmn, cpcmn, cpcmn, cpcmn, cunk,  cunk,  cmovd1,cmovq1
4712
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; 7x
5514
	dd	cunk,  cpshift,cpshift,cpshift,cpcmn,cpcmn,cpcmn,cemms		; 7x
4713
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5515
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cmovd2,cmovq2
4714
	dd	cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2		; 8x
5516
	dd	cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2		; 8x
4715
	dd	cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2
5517
	dd	cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2
4716
	dd	csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc		; 9x
5518
	dd	csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc		; 9x
4717
	dd	csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc
5519
	dd	csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc
4718
	dd	cunk,  cunk,  ccpuid,cbtx2, cshld, cshld, cunk,  cunk		; Ax
5520
	dd	cunk,  cunk,  ccpuid,cbtx2, cshld, cshld, cunk,  cunk		; Ax
4719
	dd	cunk,  cunk,  cunk,  cbtx2, cshrd, cshrd, cunk,  cop22
5521
	dd	cunk,  cunk,  cunk,  cbtx2, cshrd, cshrd, cunk,  cop22
4720
	dd	ccmpxchg,ccmpxchg,cunk,cbtx2,cunk, cunk,  cmovzx,cmovzx		; Bx
5522
	dd	ccmpxchg,ccmpxchg,cunk,cbtx2,cunk, cunk,  cmovzx,cmovzx		; Bx
4721
	dd	cunk,  cunk,  cbtx1, cbtx2, cbsf,  cbsr,  cmovsx,cmovsx
5523
	dd	cunk,  cunk,  cbtx1, cbtx2, cbsf,  cbsr,  cmovsx,cmovsx
4722
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  ccmpxchg8b	; Cx
5524
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  ccmpxchg8b	; Cx
4723
	dd	cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap
5525
	dd	cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap
4724
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; Dx
5526
	dd	cunk,  cpsrlw,cpsrlw,cpsrlq,cpcmn, cpcmn, cunk,  cunk		; Dx
4725
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5527
	dd	cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn
4726
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; Ex
5528
	dd	cpcmn, cpsraw,cpsrad,cpcmn, cpcmn, cpcmn, cunk,  cunk		; Ex
4727
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5529
	dd	cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn
4728
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk		; Fx
5530
	dd	cunk,  cpsllw,cpslld,cpsllq,cpcmn, cpcmn, cpcmn, cunk		; Fx
4729
	dd	cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
5531
	dd	cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cunk
4730
 
5532
 
4731
reg_table:
5533
reg_table:
4732
	db	2,'al',0
5534
	db	2,'al',0
4733
	db	2,'cl',1
5535
	db	2,'cl',1
4734
	db	2,'dl',2
5536
	db	2,'dl',2
4735
	db	2,'bl',3
5537
	db	2,'bl',3
4736
	db	2,'ah',4
5538
	db	2,'ah',4
4737
	db	2,'ch',5
5539
	db	2,'ch',5
4738
	db	2,'dh',6
5540
	db	2,'dh',6
4739
	db	2,'bh',7
5541
	db	2,'bh',7
4740
	db	2,'ax',8
5542
	db	2,'ax',8
4741
	db	2,'cx',9
5543
	db	2,'cx',9
4742
	db	2,'dx',10
5544
	db	2,'dx',10
4743
	db	2,'bx',11
5545
	db	2,'bx',11
4744
	db	2,'sp',12
5546
	db	2,'sp',12
4745
	db	2,'bp',13
5547
	db	2,'bp',13
4746
	db	2,'si',14
5548
	db	2,'si',14
4747
	db	2,'di',15
5549
	db	2,'di',15
4748
	db	3,'eax',16
5550
	db	3,'eax',16
4749
	db	3,'ecx',17
5551
	db	3,'ecx',17
4750
	db	3,'edx',18
5552
	db	3,'edx',18
4751
	db	3,'ebx',19
5553
	db	3,'ebx',19
4752
	db	3,'esp',20
5554
	db	3,'esp',20
4753
	db	3,'ebp',21
5555
	db	3,'ebp',21
4754
	db	3,'esi',22
5556
	db	3,'esi',22
4755
	db	3,'edi',23
5557
	db	3,'edi',23
4756
	db	3,'eip',24
5558
	db	3,'eip',24
4757
	db	0
5559
	db	0
-
 
5560
 
-
 
5561
IncludeIGlobals
-
 
5562
 
-
 
5563
fn70_read_block:
-
 
5564
	dd	0
-
 
5565
	dq	0
-
 
5566
	dd	?
-
 
5567
	dd	?
-
 
5568
	db	0
-
 
5569
	dd	?
-
 
5570
 
-
 
5571
fn70_attr_block:
-
 
5572
	dd	5
-
 
5573
	dd	0,0,0
-
 
5574
	dd	fileattr
-
 
5575
	db	0
-
 
5576
	dd	?
4758
 
5577
 
4759
fn70_load_block:
5578
fn70_load_block:
4760
	dd	7
5579
	dd	7
4761
	dd	1
5580
	dd	1
4762
load_params dd	0
5581
load_params dd	0
4763
	dd	0
5582
	dd	0
4764
	dd	0
5583
	dd	0
4765
i_end:
5584
i_end:
4766
loadname:
5585
loadname:
4767
	db	0
5586
	db	0
4768
	rb	255
5587
	rb	255
-
 
5588
 
-
 
5589
symbolsfile	rb	260
4769
 
5590
 
4770
prgname_ptr dd ?
5591
prgname_ptr dd ?
4771
prgname_len dd ?
5592
prgname_len dd ?
-
 
5593
 
-
 
5594
IncludeUGlobals
4772
 
5595
 
4773
dbgwnd		dd	?
5596
dbgwnd		dd	?
4774
 
5597
 
4775
messages	rb	messages_height*messages_width
5598
messages	rb	messages_height*messages_width
4776
messages_pos	dd	?
5599
messages_pos	dd	?
4777
 
5600
 
4778
cmdline		rb	cmdline_width+1
5601
cmdline		rb	cmdline_width+1
4779
cmdline_len	dd	?
5602
cmdline_len	dd	?
4780
cmdline_pos	dd	?
5603
cmdline_pos	dd	?
4781
curarg		dd	?
5604
curarg		dd	?
4782
 
5605
 
4783
was_temp_break	db	?
5606
was_temp_break	db	?
4784
 
5607
 
4785
dbgbufsize	dd	?
5608
dbgbufsize	dd	?
4786
dbgbuflen	dd	?
5609
dbgbuflen	dd	?
4787
dbgbuf		rb	256
5610
dbgbuf		rb	256
-
 
5611
 
-
 
5612
fileattr	rb	40
4788
 
5613
 
4789
needzerostart:
5614
needzerostart:
4790
 
5615
 
4791
context:
5616
context:
4792
_eip	dd	?
5617
_eip	dd	?
4793
_eflags	dd	?
5618
_eflags	dd	?
4794
_eax	dd	?
5619
_eax	dd	?
4795
_ecx	dd	?
5620
_ecx	dd	?
4796
_edx	dd	?
5621
_edx	dd	?
4797
_ebx	dd	?
5622
_ebx	dd	?
4798
_esp	dd	?
5623
_esp	dd	?
4799
_ebp	dd	?
5624
_ebp	dd	?
4800
_esi	dd	?
5625
_esi	dd	?
4801
_edi	dd	?
5626
_edi	dd	?
4802
 
5627
 
4803
oldcontext rb $-context
5628
oldcontext rb $-context
4804
 
5629
 
4805
dumpread dd	?
5630
dumpread dd	?
4806
dumppos dd	?
5631
dumppos dd	?
4807
dumpdata rb	dump_height*10h
5632
dumpdata rb	dump_height*10h
4808
 
5633
 
4809
; breakpoint structure:
5634
; breakpoint structure:
4810
; dword +0: address
5635
; dword +0: address
4811
; byte +4: flags
5636
; byte +4: flags
4812
; bit 0: 1 <=> breakpoint valid
5637
; bit 0: 1 <=> breakpoint valid
4813
; bit 1: 1 <=> breakpoint disabled
5638
; bit 1: 1 <=> breakpoint disabled
4814
; bit 2: 1 <=> one-shot breakpoint
5639
; bit 2: 1 <=> one-shot breakpoint
4815
; bit 3: 1 <=> DRx breakpoint
5640
; bit 3: 1 <=> DRx breakpoint
4816
; byte +5: overwritten byte
5641
; byte +5: overwritten byte
4817
;          for DRx breaks: flags + (index shl 6)
5642
;          for DRx breaks: flags + (index shl 6)
4818
breakpoints_n = 256
5643
breakpoints_n = 256
4819
breakpoints	rb	breakpoints_n*6
5644
breakpoints	rb	breakpoints_n*6
4820
drx_break	rd	4
5645
drx_break	rd	4
4821
 
5646
 
4822
disasm_buf_size		dd	?
5647
disasm_buf_size		dd	?
-
 
5648
 
-
 
5649
symbols		dd	?
-
 
5650
num_symbols	dd	?
4823
 
5651
 
4824
bReload			db	?
5652
bReload			db	?
4825
 
5653
 
4826
needzeroend:
5654
needzeroend:
4827
 
5655
 
4828
disasm_buffer		rb	256
5656
disasm_buffer		rb	256
4829
disasm_start_pos	dd	?
5657
disasm_start_pos	dd	?
4830
disasm_cur_pos		dd	?
5658
disasm_cur_pos		dd	?
4831
disasm_cur_str		dd	?
5659
disasm_cur_str		dd	?
4832
disasm_string		rb	256
5660
disasm_string		rb	256
4833
 
5661
 
4834
i_param		rb	256
5662
i_param		rb	256
4835
 
5663
 
4836
; stack
5664
; stack
4837
	align	400h
5665
	align	400h
4838
	rb	400h
5666
	rb	400h
4839
used_mem:
5667
used_mem: