Subversion Repositories Kolibri OS

Rev

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