]> wirehaze git hosting - BOS.git/blob - kernel/krl_incs/debug.inc

wirehaze git hosting

Merge commit 'dba047e616f303ce818ba9ac7fb9f8a18a3717d3'
[BOS.git] / kernel / krl_incs / debug.inc
1 ;----------------------------------------------------------;
2 ; BOS kernel Christoffer Bubach, 2004-2005. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; BOS mighty debugging service, dump some regs.. ;
6 ; ;
7 ;----------------------------------------------------------;
8
9 ;----------------;
10 ; variables ;
11 ;----------------;
12 dbg_head db 'ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»',0
13 dbg_head2 db 'º BOS 0.04 - ERROR: ',0
14 dbg_head3 db 'º º',0
15 dbg_press db 'º Press any key to continue... º',0
16 dbg_restart db 'º Press a key to restart the PC... º',0
17 dbg_footer db 'ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ',0
18 dbg_close_row db ' º',0
19 dbg_keypress db 1 ; 0 = restart, 1 = wait for key
20 dbg_error db ' none. ',0 ; error msg to show, max 14 chars
21
22 ;--------------------------------------;
23 ; I'll start with the common regs.. ;
24 ;--------------------------------------;
25 debug_eax db 'º EAX: 0x', 0
26 debug_ebx db ' EBX: 0x', 0
27 debug_ecx db 'º ECX: 0x', 0
28 debug_edx db ' EDX: 0x', 0
29 debug_esp db 'º ESP: 0x', 0
30 debug_ebp db ' EBP: 0x', 0
31 debug_esi db 'º ESI: 0x', 0
32 debug_edi db ' EDI: 0x', 0
33
34 ;-------------------;
35 ; state to print ;
36 ;-------------------;
37 state_eax dd 0
38 state_ebx dd 0
39 state_ecx dd 0
40 state_edx dd 0
41 state_esp dd 0
42 state_ebp dd 0
43 state_esi dd 0
44 state_edi dd 0
45
46 ;-----------------------------------;
47 ; "fake stack" to save regs on.. ;
48 ;-----------------------------------;
49 stack_eax dd 0
50 stack_eax2 dd 0
51 stack_ebx dd 0
52 stack_edx dd 0
53
54 ;-------------------------------;
55 ; original cursor placment.. ;
56 ;-------------------------------;
57 state_cursor dw 0
58
59 ;-------------------------------------------------;
60 ; mostly in debug purpose, and in lack of MM.. ;
61 ;-------------------------------------------------;
62 scr_buffer: times 180 dd 0 ; 720 = box buffer size (char+attrib)
63
64
65 ;--------------------------------------------;
66 ; dump regs.. does not use the stack. ;
67 ;--------------------------------------------;
68 dump_regs:
69 mov [state_eax], eax
70 mov [state_ebx], ebx
71 mov [state_ecx], ecx
72 mov [state_edx], edx
73 mov [state_esp], esp
74 mov [state_ebp], ebp
75 mov [state_esi], esi
76 mov [state_edi], edi
77
78 call .get_cur
79 mov [state_cursor], bx
80
81 mov dx, 0 ; row counter
82 mov esi, (0xB8000+840)
83 mov edi, scr_buffer
84 .big_loop:
85 mov cx, 0 ; col counter
86 .small_loop:
87 movsb ; copy creen content
88 inc cx ; increase counter
89 cmp cx, 72 ; have we copied 72 bytes?
90 je .end_small ; if we have, end small loop
91 jmp .small_loop ; if not continue with next byte
92 .end_small:
93 inc dx ; increase row count
94 cmp dx, 10 ; check if all ten is copied
95 je .end_big ; if it is, end.
96 add esi, 88 ; else continue with next row
97 jmp .big_loop
98 .end_big:
99
100 mov bx, 420 ; row 5 char 20
101 call .set_cur
102 mov ebp, dbg_head
103 call .print
104 mov bx, 500 ; row 6 char 20
105 call .set_cur
106 mov ebp, dbg_head2
107 call .print
108 mov ebp, dbg_error
109 call .print
110 mov ebp, dbg_close_row
111 call .print
112 mov bx, 580 ; row 7 char 20
113 call .set_cur
114 mov ebp, dbg_head3
115 call .print
116
117
118 mov bx, 660 ; row 8 char 20
119 call .set_cur
120 mov ebp, debug_eax
121 call .print
122 mov eax, [state_eax] ; eax
123 call .print_hex32
124 mov ebp, debug_ebx
125 call .print
126 mov eax, [state_ebx] ; ebx
127 call .print_hex32
128 mov ebp, dbg_close_row
129 call .print
130
131 mov bx, 740 ; row 9 char 20
132 call .set_cur
133 mov ebp, debug_ecx
134 call .print
135 mov eax, [state_ecx] ; ecx
136 call .print_hex32
137 mov ebp, debug_edx
138 call .print
139 mov eax, [state_edx] ; edx
140 call .print_hex32
141 mov ebp, dbg_close_row
142 call .print
143
144 mov bx, 820 ; row 10 char 20
145 call .set_cur
146 mov ebp, debug_esp
147 call .print
148 mov eax, [state_esp] ; esp
149 call .print_hex32
150 mov ebp, debug_ebp
151 call .print
152 mov eax, [state_ebp] ; ebp
153 call .print_hex32
154 mov ebp, dbg_close_row
155 call .print
156
157 mov bx, 900 ; row 11 char 20
158 call .set_cur
159 mov ebp, debug_esi
160 call .print
161 mov eax, [state_esi] ; esi
162 call .print_hex32
163 mov ebp, debug_edi
164 call .print
165 mov eax, [state_edi] ; edi
166 call .print_hex32
167 mov ebp, dbg_close_row
168 call .print
169
170 mov bx, 980 ; row 12 char 20
171 call .set_cur
172 mov ebp, dbg_head3
173 call .print
174 mov bx, 1140 ; row 14 char 20
175 call .set_cur
176 mov ebp, dbg_footer
177 call .print
178 mov bx, 1060 ; row 13 char 20
179 call .set_cur
180
181 cmp [dbg_keypress], 1
182 je .wait_key
183
184 ;----------------------------------;
185 ; wait for scancode and restart ;
186 ;----------------------------------;
187 mov ebp, dbg_restart
188 call .print
189 mov bx, 1093 ; row 13 char 46
190 call .set_cur
191
192 .no_new1:
193 mov al, [kbd_head]
194 mov ah, [kbd_tail]
195 cmp ah, 63
196 jne .check1
197 cmp al, 0
198 je .no_new1
199 mov [kbd_tail], 0
200 jmp .done_check1
201 .check1:
202 mov bl, ah
203 inc bl
204 cmp bl, al
205 je .no_new1
206 inc [kbd_tail]
207 .done_check1:
208
209 mov esi, kbd_buffer
210 movzx eax, [kbd_tail]
211 add esi, eax
212 mov ah, byte [esi] ; ah = scancode
213 cmp ah, 0xFA ; check for some stuff..
214 je .no_new1
215 cmp ah, 0xE0
216 je .no_new1
217 cmp ah, 0xE1
218 je .no_new1
219 test ah, 0x80
220 jnz .no_new1
221
222 call reboot ; in commands.inc
223
224 ;--------------------------;
225 ; wait for key and quit ;
226 ;--------------------------;
227 .wait_key:
228 mov ebp, dbg_press
229 call .print
230 mov bx, 1091 ; row 13 char 51
231 call .set_cur
232
233 .no_new2:
234 mov al, [kbd_head]
235 mov ah, [kbd_tail]
236 cmp ah, 63 ; if we are at the buffer end,
237 jne .check2 ; we must check that head != 0
238 cmp al, 0
239 je .no_new2 ; we don't have new keys to read
240 mov [kbd_tail], 0 ; "increase" to 0 (loop buffer)
241 jmp .done_check2
242 .check2:
243 mov bl, ah
244 inc bl ; head should be +1 compared to tail
245 cmp bl, al
246 je .no_new2
247 inc [kbd_tail] ; increase
248 .done_check2:
249 mov esi, kbd_buffer
250 movzx eax, [kbd_tail]
251 add esi, eax
252 mov ah, byte [esi] ; ah = scancode
253 cmp ah, 0xFA ; check for some stuff..
254 je .no_new2
255 cmp ah, 0xE0
256 je .no_new2
257 cmp ah, 0xE1
258 je .no_new2
259 test ah, 0x80
260 jnz .no_new2
261
262 mov dx, 0 ; restore screen as
263 mov edi, (0xB8000+840) ; it was before.
264 mov esi, scr_buffer ; same loops as above
265 .big_loop2: ; but exchanged esi and edi
266 mov cx, 0
267 .small_loop2:
268 movsb
269 inc cx
270 cmp cx, 72
271 je .end_small2
272 jmp .small_loop2
273 .end_small2:
274 inc dx
275 cmp dx, 10
276 je .end_big2
277 add edi, 88
278 jmp .big_loop2
279 .end_big2:
280
281 mov bx, [state_cursor]
282 call .set_cur
283 mov [dbg_keypress], 1
284 mov [dbg_error], ' ' ; restore variables.
285 mov [dbg_error+1], 'n' ; ugly..
286 mov [dbg_error+2], 'o'
287 mov [dbg_error+3], 'n'
288 mov [dbg_error+4], 'e'
289 mov [dbg_error+5], '.'
290 mov [dbg_error+6], ' '
291 mov [dbg_error+7], ' '
292 mov [dbg_error+8], ' '
293 mov [dbg_error+9], ' '
294 mov [dbg_error+10], ' '
295 mov [dbg_error+11], ' '
296 mov [dbg_error+12], ' '
297 mov [dbg_error+13], ' '
298 mov [dbg_error+14], 0
299 ret
300
301 ;-------------------------------;
302 ; subfunctions to inc cursor ;
303 ;-------------------------------;
304 .set_cur:
305 mov [stack_eax2], eax
306 mov [stack_edx], edx ; can it get any uglier?
307 mov al, 0x0E
308 mov ah, bh
309 mov dx, 0x3D4
310 out dx, ax
311 inc ax
312 mov ah, bl
313 out dx, ax
314 mov edx, [stack_edx]
315 mov eax, [stack_eax2]
316 ret
317 .get_cur:
318 mov [stack_eax2], eax
319 mov [stack_edx], edx
320 mov dx, 0x3D4
321 mov al, 0x0E
322 out dx, al
323 inc dx
324 in al, dx
325 mov bh, al
326 mov al, 0x0F
327 dec dx
328 out dx, al
329 inc dx
330 in al, dx
331 mov bl, al
332 mov edx, [stack_edx]
333 mov eax, [stack_eax2]
334 ret
335 ;--------------------------------;
336 ; subfunction to print a char ;
337 ; bl = char, bh = attrib ;
338 ;--------------------------------;
339 .print_char:
340 mov [stack_eax], eax
341 mov [stack_ebx], ebx
342 call .get_cur
343 mov eax, ebx
344 mov ebx, [stack_ebx]
345 mov [es:(eax*2 + 0xB8000)], bx
346 mov ebx, eax
347 inc bx
348 call .set_cur
349 mov ebx, [stack_ebx]
350 mov eax, [stack_eax]
351 ret
352 ;------------------------------------------;
353 ; subfunction to print 32-bit hex value ;
354 ; IN: eax = value, bh = color. ;
355 ;------------------------------------------;
356 .print_hex32:
357 mov ecx, 8
358 .print_it:
359 rol eax, 4
360 movzx edx, al
361 and edx, 0x0F
362 or edx, 0x30
363 cmp edx, 0x39
364 jna .cont
365 add edx, 7
366 .cont:
367 mov bl, dl
368 call .print_char
369 loop .print_it
370 ret
371 ;-----------------------------------------;
372 ; subfunction to display asciiz string ;
373 ; Input: ebp = string ;
374 ;-----------------------------------------;
375 .print:
376 mov al, byte [ebp]
377 or al, al
378 jz .done
379 mov bl, al
380 mov bh, 0x40 ; standard color for this...
381 call .print_char
382 inc ebp
383 jmp .print
384 .done:
385 ret