2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Internal debugger.
9 #include <aros/debug.h>
10 #include <exec/interrupts.h>
11 #include <proto/exec.h>
12 #include <proto/kernel.h>
17 #include "exec_intern.h"
19 /****************************************************************************************/
26 int get_irq_list(char *buf
);
29 #define GetA (APTR)GetQ
31 #define GetA (APTR)GetL
34 /****************************************************************************************/
36 static char *NextWord(char *s
)
38 /* Skip to first space or EOL */
46 /* Then skip to first non-space */
52 /*****************************************************************************
59 AROS_LHA(unsigned long, flags
, D0
),
62 struct ExecBase
*, SysBase
, 19, Exec
)
65 Runs SAD - internal debuger.
68 flags not used. Should be 0 now.
83 18-01-99 initial PC version.
85 *****************************************************************************/
91 BOOL ignorelf
= FALSE
;
95 * Try to obtain debug input from the kernel.
96 * If it failed, we will hang up in RawMayGetChar(), so exit immediately.
98 if (!KrnObtainInput())
108 kprintf("SAD(%d,%d)>", SysBase
->TDNestCnt
, SysBase
->IDNestCnt
);
110 /* Get Command code */
113 char key
= GetK(SysBase
);
116 /* We skip only single LF which immediately follows the CR. So we remember
117 previous value of the flag and reset it when any character arrives. */
126 /* TABs are problematic to deal with, we ignore them */
127 else if (key
== 0x09)
130 /* If we've just got CR, we may get LF next and we'll need to skip it */
131 else if (key
== '\r') {
136 /* Process backspace */
137 else if (key
== 0x08)
140 /* Go backwards, erase the character, then go backwards again */
152 while (i
< (int)sizeof(comm
)-1);
156 /* Now get data for command */
157 data
= NextWord(comm
);
161 if (strcmp(comm
, "RE") == 0 && strcmp(data
, "AAAAAAAA") == 0)
163 /* Restart command */
164 else if (strcmp(comm
, "RS") == 0 && strcmp(data
, "FFFFFFFF") == 0)
165 ShutdownA(SD_ACTION_COLDREBOOT
);
167 else if (strcmp(comm
, "FO") == 0)
170 else if (strcmp(comm
, "PE") == 0)
172 /* Disable command */
173 else if (strcmp(comm
, "DI") == 0)
175 /* Show active task information */
176 else if (strcmp(comm
, "TI") == 0)
178 struct Task
*t
= SysBase
->ThisTask
;
180 kprintf("Active task (%p = '%s'):\n"
181 "tc_Node.ln_Pri = %d\n"
182 "tc_SigAlloc = %04.4lx\n"
187 t
, t
->tc_Node
.ln_Name
,
195 else if (strcmp(comm
,"RI") == 0)
198 * TODO: this function is not useful at all in its current implementation.
199 * When the task is running its context is not valid. It would be much better
200 * to be able to examine contexts of other tasks.
201 * I left this here for demonstration purposes.
203 * 24.12.2010: reference to kernel.resource's private includes is removed,
204 * so PRINT_CPU_CONTEXT is not defined at all. Exec needs some CPU-specific
205 * .c file where all CPU-dependent functionality needs to be gathered. This
206 * is going to include full CPU context dump, stack trace, etc.
208 #ifdef PRINT_CPU_CONTEXT
209 struct ExceptionContext
*r
= SysBase
->ThisTask
->tc_UnionETask
.tc_ETask
->et_RegFrame
;
211 PRINT_CPU_CONTEXT(r
);
213 kprintf("Not implemented on this platform.\n");
217 else if (strcmp(comm
, "EN") == 0)
219 /* ShowLibs command */
220 else if (strcmp(comm
, "SL") == 0)
224 kprintf("Available libraries:\n");
226 /* Look through the list */
227 for (node
= GetHead(&SysBase
->LibList
); node
; node
= GetSucc(node
))
229 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
232 else if (strcmp(comm
, "SI") == 0)
236 kprintf("Available interrupts:\n");
240 kprintf("Not implemented\n");
242 /* ShowResources command */
243 else if (strcmp(comm
, "SR") == 0)
247 kprintf("Available resources:\n");
249 /* Look through the list */
250 for (node
= GetHead(&SysBase
->ResourceList
); node
; node
= GetSucc(node
))
252 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
255 /* ShowDevices command */
256 else if (strcmp(comm
,"SD") == 0)
260 kprintf("Available devices:\n");
262 /* Look through the list */
263 for (node
=GetHead(&SysBase
->DeviceList
); node
; node
= GetSucc(node
))
265 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
268 /* ShowTasks command */
269 else if (strcmp(comm
, "ST") == 0)
273 kprintf("Task List:\n");
275 kprintf("0x%p T %d %s\n",SysBase
->ThisTask
,
276 SysBase
->ThisTask
->tc_Node
.ln_Pri
,
277 SysBase
->ThisTask
->tc_Node
.ln_Name
);
279 /* Look through the list */
280 for (node
= GetHead(&SysBase
->TaskReady
); node
; node
= GetSucc(node
))
282 kprintf("0x%p R %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
285 for (node
= GetHead(&SysBase
->TaskWait
); node
; node
= GetSucc(node
))
287 kprintf("0x%p W %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
290 kprintf("Idle called %d times\n", SysBase
->IdleCount
);
293 else if (strcmp(comm
, "HE") == 0)
295 kprintf("SAD Help:\n");
296 kprintf("RE AAAAAAAA - reboots AROS - ColdReboot()\n"
297 "RS FFFFFFFF - RESET\n"
302 "SI - Show IRQ lines status\n"
303 "TI - Show Active task info\n"
304 "RI - Show registers inside task's context\n"
305 "AM xxxxxxxx yyyyyyyy - AllocVec - size=xxxxxxxx, "
306 "requiments=yyyyyyyy\n"
307 "FM xxxxxxxx - FreeVec from xxxxxxxx\n"
308 "RB xxxxxxxx - read byte from xxxxxxxx\n"
309 "RW xxxxxxxx - read word from xxxxxxxx\n"
310 "RL xxxxxxxx - read long from xxxxxxxx\n"
311 "WB xxxxxxxx bb - write byte bb at xxxxxxxx\n"
312 "WW xxxxxxxx wwww - write word wwww at xxxxxxxx\n"
313 "WL xxxxxxxx llllllll - write long llllllll at xxxxxxxx\n"
314 "RA xxxxxxxx ssssssss - read array(ssssssss bytes long) "
316 "RC xxxxxxxx ssssssss - read ascii (ssssssss bytes long) "
318 "QT 00000000 - quit SAD\n"
319 "SL - show all available libraries (libbase : libname)\n"
320 "SR - show all available resources (resbase : resname)\n"
321 "SD - show all available devices (devbase : devname)\n"
322 "ST - show tasks (T - this, R - ready, W - wait)\n"
323 "HE - this help.\n");
325 /* AllocMem command */
326 else if (strcmp(comm
, "AM") == 0)
328 ULONG size
= GetL(data
);
329 ULONG requim
= GetL(NextWord(data
));
331 kprintf("Allocated at 0x%p\n", AllocVec(size
, requim
));
333 /* FreeMem command */
334 else if (strcmp(comm
, "FM") == 0)
336 APTR base
= GetA(&data
[0]);
338 kprintf("Freed at 0x%p\n", base
);
342 else if (strcmp(comm
, "RB") == 0)
344 UBYTE
*addr
= GetA(data
);
346 kprintf("Byte at 0x%p: %02X\n", addr
, *addr
);
349 else if (strcmp(comm
, "RW") == 0)
351 UWORD
*addr
= GetA(data
);
353 kprintf("Word at 0x%p: %04X\n", addr
, *addr
);
356 else if (strcmp(comm
, "RL") == 0)
358 ULONG
*addr
= GetA(data
);
360 kprintf("Long at 0x%p: %08X\n", addr
, *addr
);
363 else if (strcmp(comm
,"WB") == 0)
365 UBYTE
*addr
= GetA(data
);
366 UBYTE val
= GetB(NextWord(data
));
368 kprintf("Byte at 0x%p: %02X\n", addr
, val
);
372 else if (strcmp(comm
, "WW") == 0)
374 UWORD
*addr
= GetA(data
);
375 UWORD val
= GetW(NextWord(data
));
377 kprintf("Word at 0x%p: %04X\n", addr
, val
);
381 else if (strcmp(comm
, "WL") == 0)
383 ULONG
*addr
= GetA(data
);
384 ULONG val
= GetL(NextWord(data
));
386 kprintf("Long at 0x%p: %08X\n", addr
, val
);
390 else if (strcmp(comm
, "RA") == 0)
392 UBYTE
*ptr
= GetA(data
);
393 ULONG cnt
= GetL(NextWord(data
));
396 kprintf("Array from 0x%p (size=0x%08lX):\n", ptr
, cnt
);
398 for(t
= 1; t
<= cnt
; t
++)
400 kprintf("%02X ", *ptr
++);
401 if(!(t
% 16)) kprintf("\n");
406 else if (strcmp(comm
, "RC") == 0)
408 char *ptr
= GetA(data
);
409 ULONG cnt
= GetL(NextWord(data
));
412 kprintf("ASCII from 0x%p (size=%08X):\n", ptr
, cnt
);
414 for(t
= 1; t
<= cnt
; t
++)
417 if(!(t
% 70)) kprintf(" \n");
421 else if (strcmp(comm
, "QT") == 0 && strcmp(data
, "00000000") == 0)
423 kprintf("Quitting SAD...\n");
425 #ifdef KrnReleaseInput
426 /* Release debug input */
431 else kprintf("?? Type HE for help\n");
437 /****************************************************************************************/
439 char GetK(struct ExecBase
*SysBase
)
451 /****************************************************************************************/
453 UQUAD
GetQ(char* string
)
459 for(i
= 0; i
< 16; i
++)
461 digit
= toupper(string
[i
]);
463 if (!isxdigit(digit
))
467 if (digit
> 9) digit
-= 'A' - '0' - 10;
468 ret
= (ret
<< 4) + digit
;
474 /****************************************************************************************/
476 ULONG
GetL(char* string
)
482 for(i
= 0; i
< 8; 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 UWORD
GetW(char* string
)
505 for(i
= 0; i
< 4; 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 UBYTE
GetB(char* string
)
528 for(i
= 0; i
< 2; i
++)
530 digit
= toupper(string
[i
]);
532 if (!isxdigit(digit
))
536 if (digit
> 9) digit
-= 'A' - '0' - 10;
537 ret
= (ret
<< 4) + digit
;