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 <libraries/debug.h>
12 #include <proto/exec.h>
13 #include <proto/kernel.h>
14 #include <proto/debug.h>
19 #include "exec_intern.h"
21 /****************************************************************************************/
28 int get_irq_list(char *buf
);
31 #define GetA (APTR)GetQ
33 #define GetA (APTR)GetL
36 /****************************************************************************************/
38 static char *NextWord(char *s
)
40 /* Skip to first space or EOL */
48 /* Then skip to first non-space */
54 /*****************************************************************************
61 AROS_LHA(unsigned long, flags
, D0
),
64 struct ExecBase
*, SysBase
, 19, Exec
)
67 Runs SAD - internal debuger.
70 flags not used. Should be 0 now.
85 18-01-99 initial PC version.
87 *****************************************************************************/
93 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())
110 kprintf("SAD(%d,%d)>", SysBase
->TDNestCnt
, SysBase
->IDNestCnt
);
112 /* Get Command code */
115 char key
= GetK(SysBase
);
118 /* We skip only single LF which immediately follows the CR. So we remember
119 previous value of the flag and reset it when any character arrives. */
128 /* TABs are problematic to deal with, we ignore them */
129 else if (key
== 0x09)
132 /* If we've just got CR, we may get LF next and we'll need to skip it */
133 else if (key
== '\r') {
138 /* Process backspace */
139 else if (key
== 0x08)
142 /* Go backwards, erase the character, then go backwards again */
154 while (i
< (int)sizeof(comm
)-1);
158 /* Now get data for command */
159 data
= NextWord(comm
);
163 if (strcmp(comm
, "RE") == 0 && strcmp(data
, "AAAAAAAA") == 0)
165 /* Restart command */
166 else if (strcmp(comm
, "RS") == 0 && strcmp(data
, "FFFFFFFF") == 0)
167 ShutdownA(SD_ACTION_COLDREBOOT
);
169 else if (strcmp(comm
, "FO") == 0)
172 else if (strcmp(comm
, "PE") == 0)
174 /* Disable command */
175 else if (strcmp(comm
, "DI") == 0)
177 /* Show active task information */
178 else if (strcmp(comm
, "TI") == 0)
180 struct Task
*t
= SysBase
->ThisTask
;
182 kprintf("Active task (%p = '%s'):\n"
183 "tc_Node.ln_Pri = %d\n"
184 "tc_SigAlloc = %04.4lx\n"
189 t
, t
->tc_Node
.ln_Name
,
197 else if (strcmp(comm
,"RI") == 0)
200 * TODO: this function is not useful at all in its current implementation.
201 * When the task is running its context is not valid. It would be much better
202 * to be able to examine contexts of other tasks.
203 * I left this here for demonstration purposes.
205 * 24.12.2010: reference to kernel.resource's private includes is removed,
206 * so PRINT_CPU_CONTEXT is not defined at all. Exec needs some CPU-specific
207 * .c file where all CPU-dependent functionality needs to be gathered. This
208 * is going to include full CPU context dump, stack trace, etc.
210 #ifdef PRINT_CPU_CONTEXT
211 struct ExceptionContext
*r
= SysBase
->ThisTask
->tc_UnionETask
.tc_ETask
->et_RegFrame
;
213 PRINT_CPU_CONTEXT(r
);
215 kprintf("Not implemented on this platform.\n");
219 else if (strcmp(comm
, "EN") == 0)
221 /* ShowLibs command */
222 else if (strcmp(comm
, "SL") == 0)
226 kprintf("Available libraries:\n");
228 /* Look through the list */
229 for (node
= GetHead(&SysBase
->LibList
); node
; node
= GetSucc(node
))
231 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
234 else if (strcmp(comm
, "SI") == 0)
238 kprintf("Available interrupts:\n");
242 kprintf("Not implemented\n");
244 /* ShowResources command */
245 else if (strcmp(comm
, "SR") == 0)
249 kprintf("Available resources:\n");
251 /* Look through the list */
252 for (node
= GetHead(&SysBase
->ResourceList
); node
; node
= GetSucc(node
))
254 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
257 /* ShowDevices command */
258 else if (strcmp(comm
,"SD") == 0)
262 kprintf("Available devices:\n");
264 /* Look through the list */
265 for (node
=GetHead(&SysBase
->DeviceList
); node
; node
= GetSucc(node
))
267 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
270 /* ShowTasks command */
271 else if (strcmp(comm
, "ST") == 0)
275 kprintf("Task List:\n");
277 kprintf("0x%p T %d %s\n",SysBase
->ThisTask
,
278 SysBase
->ThisTask
->tc_Node
.ln_Pri
,
279 SysBase
->ThisTask
->tc_Node
.ln_Name
);
281 /* Look through the list */
282 for (node
= GetHead(&SysBase
->TaskReady
); node
; node
= GetSucc(node
))
284 kprintf("0x%p R %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
287 for (node
= GetHead(&SysBase
->TaskWait
); node
; node
= GetSucc(node
))
289 kprintf("0x%p W %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
292 kprintf("Idle called %d times\n", SysBase
->IdleCount
);
295 else if (strcmp(comm
, "HE") == 0)
297 kprintf("SAD Help:\n");
298 kprintf("RE AAAAAAAA - reboots AROS - ColdReboot()\n"
299 "RS FFFFFFFF - RESET\n"
304 "SI - Show IRQ lines status\n"
305 "TI - Show Active task info\n"
306 "RI - Show registers inside task's context\n"
307 "AM xxxxxxxx yyyyyyyy - AllocVec - size=xxxxxxxx, "
308 "requiments=yyyyyyyy\n"
309 "FM xxxxxxxx - FreeVec from xxxxxxxx\n"
310 "RB xxxxxxxx - read byte from xxxxxxxx\n"
311 "RW xxxxxxxx - read word from xxxxxxxx\n"
312 "RL xxxxxxxx - read long from xxxxxxxx\n"
313 "WB xxxxxxxx bb - write byte bb at xxxxxxxx\n"
314 "WW xxxxxxxx wwww - write word wwww at xxxxxxxx\n"
315 "WL xxxxxxxx llllllll - write long llllllll at xxxxxxxx\n"
316 "RA xxxxxxxx ssssssss - read array(ssssssss bytes long) "
318 "RC xxxxxxxx ssssssss - read ascii (ssssssss bytes long) "
320 "QT 00000000 - quit SAD\n"
321 "SL - show all available libraries (libbase : libname)\n"
322 "SR - show all available resources (resbase : resname)\n"
323 "SD - show all available devices (devbase : devname)\n"
324 "SS xxxxxxxx - show symbol for xxxxxxxx\n"
325 "ST - show tasks (T - this, R - ready, W - wait)\n"
326 "HE - this help.\n");
328 /* AllocMem command */
329 else if (strcmp(comm
, "AM") == 0)
331 ULONG size
= GetL(data
);
332 ULONG requim
= GetL(NextWord(data
));
334 kprintf("Allocated at 0x%p\n", AllocVec(size
, requim
));
336 /* FreeMem command */
337 else if (strcmp(comm
, "FM") == 0)
339 APTR base
= GetA(&data
[0]);
341 kprintf("Freed at 0x%p\n", base
);
345 else if (strcmp(comm
, "RB") == 0)
347 UBYTE
*addr
= GetA(data
);
349 kprintf("Byte at 0x%p: %02X\n", addr
, *addr
);
352 else if (strcmp(comm
, "RW") == 0)
354 UWORD
*addr
= GetA(data
);
356 kprintf("Word at 0x%p: %04X\n", addr
, *addr
);
359 else if (strcmp(comm
, "RL") == 0)
361 ULONG
*addr
= GetA(data
);
363 kprintf("Long at 0x%p: %08X\n", addr
, *addr
);
366 else if (strcmp(comm
,"WB") == 0)
368 UBYTE
*addr
= GetA(data
);
369 UBYTE val
= GetB(NextWord(data
));
371 kprintf("Byte at 0x%p: %02X\n", addr
, val
);
375 else if (strcmp(comm
, "WW") == 0)
377 UWORD
*addr
= GetA(data
);
378 UWORD val
= GetW(NextWord(data
));
380 kprintf("Word at 0x%p: %04X\n", addr
, val
);
384 else if (strcmp(comm
, "WL") == 0)
386 ULONG
*addr
= GetA(data
);
387 ULONG val
= GetL(NextWord(data
));
389 kprintf("Long at 0x%p: %08X\n", addr
, val
);
393 else if (strcmp(comm
, "RA") == 0)
395 UBYTE
*ptr
= GetA(data
);
396 ULONG cnt
= GetL(NextWord(data
));
399 kprintf("Array from 0x%p (size=0x%08lX):\n", ptr
, cnt
);
401 for(t
= 1; t
<= cnt
; t
++)
403 kprintf("%02X ", *ptr
++);
404 if(!(t
% 16)) kprintf("\n");
409 else if (strcmp(comm
, "RC") == 0)
411 char *ptr
= GetA(data
);
412 ULONG cnt
= GetL(NextWord(data
));
415 kprintf("ASCII from 0x%p (size=%08X):\n", ptr
, cnt
);
417 for(t
= 1; t
<= cnt
; t
++)
420 if(!(t
% 70)) kprintf(" \n");
424 else if (strcmp(comm
, "SS") == 0) {
425 char *ptr
= GetA(data
);
426 STRPTR modname
= "(unknown)";
427 STRPTR symname
= "(unknown)";
428 APTR sym_l
= (APTR
)(IPTR
)0;
429 APTR sym_h
= (APTR
)~(IPTR
)0;
430 struct TagItem tags
[] = {
431 { DL_ModuleName
, (IPTR
)&modname
},
432 { DL_SymbolName
, (IPTR
)&symname
},
433 { DL_SymbolStart
, (IPTR
)&sym_l
},
434 { DL_SymbolEnd
, (IPTR
)&sym_h
},
439 DecodeLocationA(ptr
, tags
);
442 kprintf("%p-%p %s.%s\n", sym_l
, sym_h
, modname
, symname
);
444 else if (strcmp(comm
, "QT") == 0 && strcmp(data
, "00000000") == 0)
446 kprintf("Quitting SAD...\n");
448 #ifdef KrnReleaseInput
449 /* 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
;