2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 Desc: Start the internal debugger.
10 #include "exec_intern.h"
11 #include <proto/exec.h>
12 #include <exec/types.h>
13 #include <asm/speaker.h>
15 /* See rom/exec/debug.c for documentation */
17 /****************************************************************************************/
19 #define Prompt kprintf("SAD(%ld,%ld)>",SysBase->TDNestCnt,SysBase->IDNestCnt)
21 /*#define GetHead(l) (void *)(((struct List *)l)->lh_Head->ln_Succ \
22 ? ((struct List *)l)->lh_Head \
24 #define GetSucc(n) (void *)(((struct Node *)n)->ln_Succ->ln_Succ \
25 ? ((struct Node *)n)->ln_Succ \
28 /****************************************************************************************/
30 void InitKeyboard(void);
37 int get_irq_list(char *buf
);
39 /****************************************************************************************/
42 AROS_LHA(unsigned long, flags
, D0
),
43 struct ExecBase
*, SysBase
, 19, Exec
)
48 /* KeyCode -> ASCII conversion table */
49 static char transl
[] =
50 { ' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ' ', ' ', ' ',
51 ' ', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', ' ', ' ', 10,
52 ' ', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ' ', ' ', ' ', ' ',
53 ' ', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' };
55 static char command
[3] = {0, 0, 0};
58 char *comm
= &command
[0];
69 /* Get Command code */
71 for(i
= 0; i
< 2; i
++)
73 key
= transl
[GetK() - 1];
83 /* Now get data for command */
88 key
= transl
[(key
== 0x39) ? 1 : key
- 1];
89 if (key
!= 10) kprintf("%c",key
);
92 if(key
!= ' ') data
[i
++]=key
;
93 } while(key
!=10 && i
< 70);
97 if (strcmp(comm
, "RE") == 0 && strcmp(dat
, "AAAAAAAA") == 0) ColdReboot();
98 /* Restart command, pulse reset signal */
99 else if (strcmp(comm
, "RS") == 0 && strcmp(dat
, "FFFFFFFF") == 0)
100 asm("movb $0xfe,%%al;outb %%al,$0x64":::"eax");
102 else if (strcmp(comm
, "FO") == 0)
105 else if (strcmp(comm
, "PE") == 0)
107 /* Disable command */
108 else if (strcmp(comm
, "DI") == 0)
110 /* Dump regs command */
111 else if (strcmp(comm
, "DU") == 0)
113 else if (strcmp(comm
, "MO") == 0)
114 asm("movb $0xa8,%%al;outb %%al,$0x64":::"eax");
115 /* Show active task information */
116 else if (strcmp(comm
, "TI") == 0)
118 struct Task
*t
= SysBase
->ThisTask
;
120 kprintf("Active task (%p = '%s'):\n"
121 "tc_Node.ln_Pri = %d\n"
122 "tc_SigAlloc = %04.4lx\n"
125 "tc_Flags = %08.8lx\n"
127 t
, t
->tc_Node
.ln_Name
,
135 /* else if (strcmp(comm,"RI") == 0)
138 struct pt_regs *r = (struct pt_regs *)SysBase->ThisTask->tc_UnionETask.tc_ETask->et_RegFrame;
140 kprintf("Active task's registers dump:\n"
141 "EAX=%p ECX=%p EDX=%p EIP=%p\n"
142 "CS=%04.4lx DS=%04.4lx ES=%04.4lx\n"
143 "SS=%04.4lx EFLAGS=%p\n",
144 r->eax, r->ecx, r->edx,
145 r->eip, r->xcs, r->xds, r->xes,
149 else if (strcmp(comm
, "EN") == 0)
151 /* ShowLibs command */
152 else if (strcmp(comm
, "SL") == 0)
156 kprintf("Available libraries:\n");
158 /* Look through the list */
159 for (node
= GetHead(&SysBase
->LibList
); node
; node
= GetSucc(node
))
161 kprintf("0x%08.8lx : %s\n", node
, node
->ln_Name
);
164 else if (strcmp(comm
, "SI") == 0)
168 kprintf("Available interrupts:\n");
170 // get_irq_list(&buf);
174 /* ShowResources command */
175 else if (strcmp(comm
, "SR") == 0)
179 kprintf("Available resources:\n");
181 /* Look through the list */
182 for (node
= GetHead(&SysBase
->ResourceList
); node
; node
= GetSucc(node
))
184 kprintf("0x%08.8lx : %s\n", node
, node
->ln_Name
);
187 /* ShowDevices command */
188 else if (strcmp(comm
,"SD") == 0)
192 kprintf("Available devices:\n");
194 /* Look through the list */
195 for (node
=GetHead(&SysBase
->DeviceList
); node
; node
= GetSucc(node
))
197 kprintf("0x%08.8lx : %s\n", node
, node
->ln_Name
);
200 /* ShowTasks command */
201 else if (strcmp(comm
, "ST") == 0)
205 kprintf("Task List:\n");
207 kprintf("0x%08.8lx T %d %s\n",SysBase
->ThisTask
,
208 SysBase
->ThisTask
->tc_Node
.ln_Pri
,
209 SysBase
->ThisTask
->tc_Node
.ln_Name
);
211 /* Look through the list */
212 for (node
= GetHead(&SysBase
->TaskReady
); node
; node
= GetSucc(node
))
214 kprintf("0x%08.8lx R %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
217 for (node
= GetHead(&SysBase
->TaskWait
); node
; node
= GetSucc(node
))
219 kprintf("0x%08.8lx W %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
222 kprintf("Idle called %d times\n", SysBase
->IdleCount
);
225 else if (strcmp(comm
, "HE") == 0)
227 kprintf("SAD Help:\n");
228 kprintf("RE AAAAAAAA - reboots AROS - ColdReboot()\n"
229 "RS FFFFFFFF - RESET\n"
234 "DU - Dump most important registers\n"
235 "SI - Show IRQ lines status\n"
236 "TI - Show Active task info\n"
237 "RI - Show registers inside task's context\n"
238 "AM xxxxxxxx yyyyyyyy - AllocVec - size=xxxxxxxx, "
239 "requirements=yyyyyyyy\n"
240 "FM xxxxxxxx - FreeVec from xxxxxxxx\n"
241 "RB xxxxxxxx - read byte from xxxxxxxx\n"
242 "RW xxxxxxxx - read word from xxxxxxxx\n"
243 "RL xxxxxxxx - read long from xxxxxxxx\n"
244 "WB xxxxxxxx bb - write byte bb at xxxxxxxx\n"
245 "WW xxxxxxxx wwww - write word wwww at xxxxxxxx\n"
246 "WL xxxxxxxx llllllll - write long llllllll at xxxxxxxx\n"
247 "RA xxxxxxxx ssssssss - read array(ssssssss bytes long) "
249 "RC xxxxxxxx ssssssss - read ascii (ssssssss bytes long) "
251 "QT 00000000 - quit SAD\n"
252 "SL - show all available libraries (libbase : libname)\n"
253 "SR - show all available resources (resbase : resname)\n"
254 "SD - show all available devices (devbase : devname)\n"
255 "ST - show tasks (T - this, R - ready, W - wait)\n"
257 "HE - this help.\n");
259 /* AllocMem command */
260 else if (strcmp(comm
, "AM") == 0)
262 ULONG size
= GetL(&data
[0]);
263 ULONG requim
= GetL(&data
[8]);
265 kprintf("Allocated at %08.8lx\n", AllocVec(size
, requim
));
267 /* FreeMem command */
268 else if (strcmp(comm
, "FM") == 0)
270 APTR base
= (APTR
)GetL(&data
[0]);
271 kprintf("Freed at %08.8lx\n", base
);
275 else if (strcmp(comm
, "RB") == 0)
276 kprintf("Byte at %08.8lx:%02.8lx\n", GetL(&data
[0]),
277 *(UBYTE
*)(GetL(&data
[0])));
279 else if (strcmp(comm
, "RW") == 0)
280 kprintf("Word at %08.8lx:%04.8lx\n", GetL(&data
[0]),
281 *(UWORD
*)(GetL(&data
[0])));
283 else if (strcmp(comm
, "RL") == 0)
284 kprintf("Long at %08.8lx:%08.8lx\n", GetL(&data
[0]),
285 *(ULONG
*)(GetL(&data
[0])));
287 else if (strcmp(comm
,"WB") == 0)
289 kprintf("Byte at %08.8lx:%02.8lx\n", GetL(&data
[0]),
291 *(UBYTE
*)(GetL(&data
[0])) = GetB(&data
[8]);
294 else if (strcmp(comm
, "WW") == 0)
296 kprintf("Word at %08.8lx:%04.8lx\n", GetL(&data
[0]),
298 *(UWORD
*)(GetL(&data
[0])) = GetW(&data
[8]);
301 else if (strcmp(comm
, "WL") == 0)
303 kprintf("Long at %08.8lx:%08.8lx\n", GetL(&data
[0]),
305 *(ULONG
*)(GetL(&data
[0])) = GetL(&data
[8]);
308 else if (strcmp(comm
, "RA") == 0)
313 kprintf("Array from %08.8lx (size=%08.8lx):\n", GetL(&data
[0]),
315 ptr
= GetL(&data
[0]);
316 cnt
= (int)GetL(&data
[8]);
317 for(t
= 1; t
<= cnt
; t
++)
319 kprintf("%02.2lx ", *(UBYTE
*)ptr
);
321 if(!(t
% 16)) kprintf("\n");
326 else if (strcmp(comm
, "RC") == 0)
331 kprintf("ASCII from %08.8lx (size=%08.8lx):\n", GetL(&data
[0]),
333 ptr
= GetL(&data
[0]);
334 cnt
= (int)GetL(&data
[8]);
335 for(t
= 1; t
<= cnt
; t
++)
337 kprintf("%c",*(char*)ptr
);
339 if(!(t
% 70)) kprintf(" \n");
343 else if (strcmp(comm
, "BE") == 0)
346 #define DELAY_1USEC() inb(0x80)
348 kprintf("Beeping...\n");
352 for (i
= 0; i
< 2000000; i
++)
355 for (i
= 0; i
< 1000000; i
++)
360 for (i
= 0; i
< 2000000; i
++)
363 for (i
= 0; i
< 1000000; i
++)
368 for (i
= 0; i
< 2000000; i
++)
371 for (i
= 0; i
< 1000000; i
++)
376 for (i
= 0; i
< 2000000; i
++)
381 else if (strcmp(comm
, "QT") == 0 && strcmp(dat
, "00000000") == 0)
384 else kprintf("?? Type HE for help\n");
386 } while(strcmp(comm
, "QT") != 0 || strcmp(dat
, "00000000") != 0);
388 kprintf("Quitting SAD...\n");
393 /****************************************************************************************/
400 " xorl %%eax, %%eax \n"
401 " inb $0x64, %%al \n"
402 " andb $0x01, %%al \n"
404 " inb $0x60, %%al \n"
406 " inb $0x61, %%al \n"
407 " movb %%al, %%ah \n"
408 " orb $0x80, %%al \n"
409 " outb %%al, $0x61 \n"
410 " movb %%ah, %%al \n"
411 " outb %%al, $0x61 \n"
423 /****************************************************************************************/
425 void InitKeyboard(void)
429 /* keyboard self test */
431 while(getkey() != -1);
434 "xorl %%eax,%%eax \n"
435 "movb $0xaa, %%al \n"
436 "outb %%al, $0x64 \n"
446 //kprintf("Debug(): Keyboard self-test okay :-)\n");
448 //kprintf("Debug(): Error: keyboard self-test failed.\n");
452 /****************************************************************************************/
458 /****************************************************************************************/
467 } while((i
== -1) || (i
& 0x80));
472 /****************************************************************************************/
474 ULONG
GetL(char* string
)
480 for(i
= 0; i
< 8; i
++)
482 digit
= (*string
++) - '0';
483 if (digit
> 9) digit
-= 'A' - '0' - 10;
484 ret
= (ret
<< 4) + digit
;
490 /****************************************************************************************/
492 UWORD
GetW(char* string
)
498 for(i
= 0; i
< 4; i
++)
500 digit
= (*string
++) - '0';
501 if (digit
> 9) digit
-= 'A' - '0' - 10;
502 ret
= (ret
<< 4) + digit
;
508 /****************************************************************************************/
510 UBYTE
GetB(char* string
)
516 for(i
= 0; i
< 2; i
++)
518 digit
= (*string
++) - '0';
519 if (digit
> 9) digit
-= 'A' - '0' - 10;
520 ret
= (ret
<< 4) + digit
;
526 /****************************************************************************************/
530 int ds
, cs
, ss
, eflags
, esp
;
542 :"=m"(ds
),"=m"(cs
),"=m"(ss
),"=m"(eflags
),"=m"(esp
));
544 kprintf("DS=%04.4x CS=%04.4x SS=%04.4x ESP=%08.8x EFLAGS=%08.8x\n",
545 ds
, cs
, ss
, esp
, eflags
);
548 /****************************************************************************************/