2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Desc: Internal debugger.
9 #include <aros/debug.h>
10 #include <exec/interrupts.h>
11 #include <libraries/debug.h>
12 #include <proto/exec.h>
13 #include <proto/kernel.h>
14 #include <proto/debug.h>
19 #include "exec_intern.h"
20 #include "exec_util.h"
22 /****************************************************************************************/
29 int get_irq_list(char *buf
);
32 #define GetA (APTR)GetQ
34 #define GetA (APTR)GetL
37 /****************************************************************************************/
39 static char *NextWord(char *s
)
41 /* Skip to first space or EOL */
49 /* Then skip to first non-space */
55 /*****************************************************************************
62 AROS_LHA(unsigned long, flags
, D0
),
65 struct ExecBase
*, SysBase
, 19, Exec
)
68 Runs SAD - internal debuger.
71 flags not used. Should be 0 now.
86 18-01-99 initial PC version.
88 *****************************************************************************/
94 BOOL ignorelf
= FALSE
;
97 * Try to obtain debug input from the kernel.
98 * If it failed, we will hang up in RawMayGetChar(), so exit immediately.
100 if (!KrnObtainInput())
109 kprintf("SAD(%d,%d)>", SysBase
->TDNestCnt
, SysBase
->IDNestCnt
);
111 /* Get Command code */
114 char key
= GetK(SysBase
);
117 /* We skip only single LF which immediately follows the CR. So we remember
118 previous value of the flag and reset it when any character arrives. */
127 /* TABs are problematic to deal with, we ignore them */
128 else if (key
== 0x09)
131 /* If we've just got CR, we may get LF next and we'll need to skip it */
132 else if (key
== '\r') {
137 /* Process backspace */
138 else if (key
== 0x08)
141 /* Go backwards, erase the character, then go backwards again */
153 while (i
< (int)sizeof(comm
)-1);
157 /* Now get data for command */
158 data
= NextWord(comm
);
162 if (strcmp(comm
, "RE") == 0 && strcmp(data
, "AAAAAAAA") == 0)
164 /* Restart command */
165 else if (strcmp(comm
, "RS") == 0 && strcmp(data
, "FFFFFFFF") == 0)
166 ShutdownA(SD_ACTION_COLDREBOOT
);
168 else if (strcmp(comm
, "FO") == 0)
171 else if (strcmp(comm
, "PE") == 0)
173 /* Disable command */
174 else if (strcmp(comm
, "DI") == 0)
176 /* Show task information */
177 else if (strcmp(comm
, "TI") == 0)
179 struct Task
*t
= GetA(data
);
181 if (!Exec_CheckTask(t
, SysBase
))
183 kprintf("Task 0x%P not found\n", t
);
187 kprintf("Task status (%p = '%s'):\n"
188 "tc_Node.ln_Pri = %d\n"
190 "tc_SigAlloc = %04.4lx\n"
191 "tc_SigWait = %04.4lx\n"
195 "tc_IDNestCnt = %d\n"
196 "tc_TDNestCnt = %d\n",
197 t
, t
->tc_Node
.ln_Name
,
208 else if (strcmp(comm
,"RI") == 0)
210 struct Task
*t
= GetA(data
);
212 if (!Exec_CheckTask(t
, SysBase
))
214 kprintf("Task 0x%P not found\n", t
);
218 kprintf("Task context (%p = '%s'):\n", t
, t
->tc_Node
.ln_Name
);
219 FormatCPUContext(NULL
, t
->tc_UnionETask
.tc_ETask
->et_RegFrame
, SysBase
);
223 else if (strcmp(comm
, "EN") == 0)
225 /* ShowLibs command */
226 else if (strcmp(comm
, "SL") == 0)
230 kprintf("Available libraries:\n");
232 /* Look through the list */
233 for (node
= GetHead(&SysBase
->LibList
); node
; node
= GetSucc(node
))
235 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
238 else if (strcmp(comm
, "SI") == 0)
242 kprintf("Available interrupts:\n");
246 kprintf("Not implemented\n");
248 /* ShowResources command */
249 else if (strcmp(comm
, "SR") == 0)
253 kprintf("Available resources:\n");
255 /* Look through the list */
256 for (node
= GetHead(&SysBase
->ResourceList
); node
; node
= GetSucc(node
))
258 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
261 /* ShowDevices command */
262 else if (strcmp(comm
,"SD") == 0)
266 kprintf("Available devices:\n");
268 /* Look through the list */
269 for (node
=GetHead(&SysBase
->DeviceList
); node
; node
= GetSucc(node
))
271 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
274 /* ShowTasks command */
275 else if (strcmp(comm
, "ST") == 0)
279 kprintf("Task List:\n");
281 kprintf("0x%p T %d %s\n",SysBase
->ThisTask
,
282 SysBase
->ThisTask
->tc_Node
.ln_Pri
,
283 SysBase
->ThisTask
->tc_Node
.ln_Name
);
285 /* Look through the list */
286 for (node
= GetHead(&SysBase
->TaskReady
); node
; node
= GetSucc(node
))
288 kprintf("0x%p R %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
291 for (node
= GetHead(&SysBase
->TaskWait
); node
; node
= GetSucc(node
))
293 kprintf("0x%p W %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
296 kprintf("Idle called %d times\n", SysBase
->IdleCount
);
299 else if (strcmp(comm
, "HE") == 0)
301 kprintf("SAD Help:\n");
302 kprintf("RE AAAAAAAA - reboots AROS - ColdReboot()\n"
303 "RS FFFFFFFF - RESET\n"
308 "SI - Show IRQ lines status\n"
309 "TI - Show Active task info\n"
310 "RI xxxxxxxx - Show registers inside task's context\n"
311 "AM xxxxxxxx yyyyyyyy - AllocVec - size=xxxxxxxx, "
312 "requiments=yyyyyyyy\n"
313 "FM xxxxxxxx - FreeVec from xxxxxxxx\n"
314 "RB xxxxxxxx - read byte from xxxxxxxx\n"
315 "RW xxxxxxxx - read word from xxxxxxxx\n"
316 "RL xxxxxxxx - read long from xxxxxxxx\n"
317 "WB xxxxxxxx bb - write byte bb at xxxxxxxx\n"
318 "WW xxxxxxxx wwww - write word wwww at xxxxxxxx\n"
319 "WL xxxxxxxx llllllll - write long llllllll at xxxxxxxx\n"
320 "RA xxxxxxxx ssssssss - read array(ssssssss bytes long) "
322 "RC xxxxxxxx ssssssss - read ascii (ssssssss bytes long) "
324 "QT 00000000 - quit SAD\n"
325 "SL - show all available libraries (libbase : libname)\n"
326 "SR - show all available resources (resbase : resname)\n"
327 "SD - show all available devices (devbase : devname)\n"
328 "SS xxxxxxxx - show symbol for xxxxxxxx\n"
329 "ST - show tasks (T - this, R - ready, W - wait)\n"
330 "HE - this help.\n");
332 /* AllocMem command */
333 else if (strcmp(comm
, "AM") == 0)
335 ULONG size
= GetL(data
);
336 ULONG requim
= GetL(NextWord(data
));
338 kprintf("Allocated at 0x%p\n", AllocVec(size
, requim
));
340 /* FreeMem command */
341 else if (strcmp(comm
, "FM") == 0)
343 APTR base
= GetA(&data
[0]);
345 kprintf("Freed at 0x%p\n", base
);
349 else if (strcmp(comm
, "RB") == 0)
351 UBYTE
*addr
= GetA(data
);
353 kprintf("Byte at 0x%p: %02X\n", addr
, *addr
);
356 else if (strcmp(comm
, "RW") == 0)
358 UWORD
*addr
= GetA(data
);
360 kprintf("Word at 0x%p: %04X\n", addr
, *addr
);
363 else if (strcmp(comm
, "RL") == 0)
365 ULONG
*addr
= GetA(data
);
367 kprintf("Long at 0x%p: %08X\n", addr
, *addr
);
370 else if (strcmp(comm
,"WB") == 0)
372 UBYTE
*addr
= GetA(data
);
373 UBYTE val
= GetB(NextWord(data
));
375 kprintf("Byte at 0x%p: %02X\n", addr
, val
);
379 else if (strcmp(comm
, "WW") == 0)
381 UWORD
*addr
= GetA(data
);
382 UWORD val
= GetW(NextWord(data
));
384 kprintf("Word at 0x%p: %04X\n", addr
, val
);
388 else if (strcmp(comm
, "WL") == 0)
390 ULONG
*addr
= GetA(data
);
391 ULONG val
= GetL(NextWord(data
));
393 kprintf("Long at 0x%p: %08X\n", addr
, val
);
397 else if (strcmp(comm
, "RA") == 0)
399 UBYTE
*ptr
= GetA(data
);
400 ULONG cnt
= GetL(NextWord(data
));
403 kprintf("Array from 0x%p (size=0x%08lX):\n", ptr
, cnt
);
405 for(t
= 1; t
<= cnt
; t
++)
407 kprintf("%02X ", *ptr
++);
408 if(!(t
% 16)) kprintf("\n");
413 else if (strcmp(comm
, "RC") == 0)
415 char *ptr
= GetA(data
);
416 ULONG cnt
= GetL(NextWord(data
));
419 kprintf("ASCII from 0x%p (size=%08X):\n", ptr
, cnt
);
421 for(t
= 1; t
<= cnt
; t
++)
424 if(!(t
% 70)) kprintf(" \n");
428 else if (strcmp(comm
, "SS") == 0) {
429 char *ptr
= GetA(data
);
430 STRPTR modname
= "(unknown)";
431 STRPTR symname
= "(unknown)";
432 APTR sym_l
= (APTR
)(IPTR
)0;
433 APTR sym_h
= (APTR
)~(IPTR
)0;
434 struct TagItem tags
[] = {
435 { DL_ModuleName
, (IPTR
)&modname
},
436 { DL_SymbolName
, (IPTR
)&symname
},
437 { DL_SymbolStart
, (IPTR
)&sym_l
},
438 { DL_SymbolEnd
, (IPTR
)&sym_h
},
443 DecodeLocationA(ptr
, tags
);
446 kprintf("%p %s %s+0x%x\n", sym_l
, sym_h
, modname
, symname
, (APTR
)ptr
- (APTR
)sym_l
);
448 else if (strcmp(comm
, "QT") == 0 && strcmp(data
, "00000000") == 0)
450 kprintf("Quitting SAD...\n");
451 KrnReleaseInput(); /* Release debug input */
454 else kprintf("?? Type HE for help\n");
460 /****************************************************************************************/
462 char GetK(struct ExecBase
*SysBase
)
474 /****************************************************************************************/
476 UQUAD
GetQ(char* string
)
482 for(i
= 0; i
< 16; i
++)
484 digit
= toupper(string
[i
]);
486 if (!isxdigit(digit
))
490 if (digit
> 9) digit
-= 'A' - '0' - 10;
491 ret
= (ret
<< 4) + digit
;
497 /****************************************************************************************/
499 ULONG
GetL(char* string
)
505 for(i
= 0; i
< 8; i
++)
507 digit
= toupper(string
[i
]);
509 if (!isxdigit(digit
))
513 if (digit
> 9) digit
-= 'A' - '0' - 10;
514 ret
= (ret
<< 4) + digit
;
520 /****************************************************************************************/
522 UWORD
GetW(char* string
)
528 for(i
= 0; i
< 4; i
++)
530 digit
= toupper(string
[i
]);
532 if (!isxdigit(digit
))
536 if (digit
> 9) digit
-= 'A' - '0' - 10;
537 ret
= (ret
<< 4) + digit
;
543 /****************************************************************************************/
545 UBYTE
GetB(char* string
)
551 for(i
= 0; i
< 2; i
++)
553 digit
= toupper(string
[i
]);
555 if (!isxdigit(digit
))
559 if (digit
> 9) digit
-= 'A' - '0' - 10;
560 ret
= (ret
<< 4) + digit
;