This repository has been archived by the owner on Apr 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.inc
289 lines (256 loc) · 3.69 KB
/
debug.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
;
; Some debug routines
; (c) Dmytro Sirenko
; ___________________________________________________________________
%ifndef __DEBUG_INC__
%define __DEBUG_INC__
%include "pseudogr.inc"
;
dbg_print_char_dl:
; args: dl - ASCII
; out: none
; preserves all fags
pusha
pushf
mov ah, 0x0E
mov bx, 0x0007
mov al, dl
int 10h
popf
popa
retn
;
dbg_print_hex_dl:
pusha
pushf
mov ah, 0x0E
mov bx, 0x0007
mov al, dl
shr al, 4
cmp al, 10
jl .dec
add al, 'A' - '9' - 1
.dec: add al, '0'
int 10h
mov al, dl
and al, 0x0F
cmp al, 10
jl .dec2
add al, 'A' - '9' - 1
.dec2: add al, '0'
int 10h
mov al, ' '
call out_char
popf
popa
retn
;
dbg_print_word_dx:
; args:
; dx - word
; out: none
; preserves all flags
pusha
pushf
mov ah, 0x0E
mov bx, 0x0007
mov cx, 0x0004
.loop:
mov al, dh
shr al, 4 ; al = digit
; convert to ascii
cmp al, 10
jl .dec
add al, 'A' - '9' - 1
.dec: add al, '0'
int 10h
shl dx, 4
loop .loop
mov al, ' '
int 10h
popf
popa
retn
;
dbg_print_string:
pusha
pushf
mov ah, 0x0E
mov bx, 0x0007
.iter:
mov al, [si]
and al, al
jz .done
int 0x10
lodsb
jmp .iter
.done:
popf
popa
retn
;
dbg_dump_mem:
; hex output of memory at [es:di] to [es:di+cx]
;
pusha
pushf
xor bx, bx
mov al, 1
.loop: dec al
jnz .next
mov al, 0x10
mov dl, 13
call dbg_print_char_dl
mov dl, 10
call dbg_print_char_dl
.next: mov dl, byte [es : di+bx]
call dbg_print_hex_dl
inc bx
loop .loop
popf
popa
retn
.endl db 13, 10, 0
;; __________________________________________________________________
dbg_hex_input_dx:
;; args: none
;; rets: dx - word
pusha
xor dx, dx
xor cl, cl
.loop:
push dx
call get_char
pop dx
cmp cl, 4
jge .no_digit
cmp al, '0'
jl .is_A_F
cmp al, '9'
jg .is_A_F
call out_char
sub al, '0'
jmp .digit
.is_A_F:
cmp al, 'A'
jl .is_a_f
cmp al, 'F'
jg .is_a_f
call out_char
sub al, 'A' - 10
jmp .digit
.is_a_f:
cmp al, 'a'
jl .no_digit
cmp al, 'f'
jg .no_digit
call out_char
sub al, 'a' - 10
jmp .digit
.no_digit:
cmp al, 13 ;; enter?
je .break
cmp al, 8 ;; bksp?
jne .loop
test cl, cl
jle .loop
dec cl
;; clear last symbol
mov si, clsymb
call display_string
;; dlete it from dx
shr dx, 4
jmp .loop
.digit:
shl dx, 4
inc cl
add dl, al
jmp .loop
.break:
mov si, endl
call display_string
mov word[.res], dx
popa
mov dx, word[.res]
retn
.res dw 0x0000
%macro SHOW_SEGREG 1
mov si, dbg_seg_regs.s_%1
call display_string
mov al, '='
call out_char
mov dx, %1
call dbg_print_word_dx
mov al, ' '
call out_char
%endmacro
;; __________________________________________________________________
dbg_window_cpu:
;;;
REG_STR_LENGTH equ 3
pusha
;; adrress where this function called from
mov si, .caller
call display_string
mov si, sp
add si, 16
mov dx, [ss : si]
call dbg_print_word_dx
mov si, endl
call display_string
;; general registers
mov cx, 8
mov di, dbg_regs
.next_reg:
mov ax, cx
dec ax
mov bl, 0x03
mul bl
mov si, di
add si, ax
call display_string
mov al, '='
call out_char
mov si, sp
;inc si ;; cause of flags
mov bx, cx
dec bx
shl bx, 1
add si, bx ;; offset
mov dx, word [ss : si]
call dbg_print_word_dx
mov al, ' '
call out_char
loop .next_reg
mov si, endl
call display_string
;; segment registers
SHOW_SEGREG ds
SHOW_SEGREG es
SHOW_SEGREG fs
SHOW_SEGREG gs
SHOW_SEGREG ss
SHOW_SEGREG cs
;popf
popa
retn
.caller db "Called from ", 0
dbg_regs:
.s_di db "DI", 0
.s_si db "SI", 0
.s_bp db "BP", 0
.s_sp db "SP", 0
.s_bx db "BX", 0
.s_dx db "DX", 0
.s_cx db "CX", 0
.s_ax db "AX", 0
dbg_seg_regs:
.s_ds db "DS", 0
.s_es db "ES", 0
.s_fs db "FS", 0
.s_gs db "GS", 0
.s_cs db "CS", 0
.s_ss db "SS", 0
.s_ip db "IP", 0
.s_flags db "FLAGS", 0
%endif