Subversion Repositories Kolibri OS

Rev

Rev 1265 | Rev 4285 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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