Subversion Repositories Kolibri OS

Rev

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