2 Copyright © 1995-2017, 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/debug.h>
18 #include "exec_intern.h"
19 #include "exec_util.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
;
96 * Try to obtain debug input from the kernel.
97 * If it failed, we will hang up in RawMayGetChar(), so exit immediately.
99 if (!KrnObtainInput())
108 kprintf("SAD(%d,%d)>", TDNESTCOUNT_GET
, IDNESTCOUNT_GET
);
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 task information */
176 else if (strcmp(comm
, "TI") == 0)
178 struct Task
*t
= GetA(data
);
180 if (!Exec_CheckTask(t
, SysBase
))
182 kprintf("Task 0x%P not found\n", t
);
186 kprintf("Task status (%p = '%s'):\n"
187 "tc_Node.ln_Pri = %d\n"
189 "tc_SigAlloc = %04.4lx\n"
190 "tc_SigWait = %04.4lx\n"
194 "tc_IDNestCnt = %d\n"
195 "tc_TDNestCnt = %d\n",
196 t
, t
->tc_Node
.ln_Name
,
207 else if (strcmp(comm
,"RI") == 0)
209 struct Task
*t
= GetA(data
);
211 if (!Exec_CheckTask(t
, SysBase
))
213 kprintf("Task 0x%P not found\n", t
);
217 kprintf("Task context (%p = '%s'):\n", t
, t
->tc_Node
.ln_Name
);
218 FormatCPUContext(NULL
, t
->tc_UnionETask
.tc_ETask
->et_RegFrame
, SysBase
);
222 else if (strcmp(comm
, "EN") == 0)
224 /* ShowLibs command */
225 else if (strcmp(comm
, "SL") == 0)
229 kprintf("Available libraries:\n");
231 /* Look through the list */
232 for (node
= GetHead(&SysBase
->LibList
); node
; node
= GetSucc(node
))
234 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
237 else if (strcmp(comm
, "SI") == 0)
241 kprintf("Available interrupts:\n");
245 kprintf("Not implemented\n");
247 /* ShowResources command */
248 else if (strcmp(comm
, "SR") == 0)
252 kprintf("Available resources:\n");
254 /* Look through the list */
255 for (node
= GetHead(&SysBase
->ResourceList
); node
; node
= GetSucc(node
))
257 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
260 /* ShowDevices command */
261 else if (strcmp(comm
,"SD") == 0)
265 kprintf("Available devices:\n");
267 /* Look through the list */
268 for (node
=GetHead(&SysBase
->DeviceList
); node
; node
= GetSucc(node
))
270 kprintf("0x%p : %s\n", node
, node
->ln_Name
);
273 /* ShowTasks command */
274 else if (strcmp(comm
, "ST") == 0)
278 kprintf("Task List:\n");
280 #if defined(__AROSEXEC_SMP__)
281 ForeachNode(&PrivExecBase(SysBase
)->TaskRunning
, node
)
284 node
= (struct Node
*)GET_THIS_TASK
;
286 kprintf("0x%p T %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
287 #if defined(__AROSEXEC_SMP__)
290 /* Look through the list */
291 for (node
= GetHead(&SysBase
->TaskReady
); node
; node
= GetSucc(node
))
293 kprintf("0x%p R %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
296 for (node
= GetHead(&SysBase
->TaskWait
); node
; node
= GetSucc(node
))
298 kprintf("0x%p W %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
301 kprintf("Idle called %d times\n", SysBase
->IdleCount
);
304 else if (strcmp(comm
, "HE") == 0)
306 kprintf("SAD Help:\n");
307 kprintf("RE AAAAAAAA - reboots AROS - ColdReboot()\n"
308 "RS FFFFFFFF - RESET\n"
313 "SI - Show IRQ lines status\n"
314 "TI - Show Active task info\n"
315 "RI xxxxxxxx - Show registers inside task's context\n"
316 "AM xxxxxxxx yyyyyyyy - AllocVec - size=xxxxxxxx, "
317 "requiments=yyyyyyyy\n"
318 "FM xxxxxxxx - FreeVec from xxxxxxxx\n"
319 "RB xxxxxxxx - read byte from xxxxxxxx\n"
320 "RW xxxxxxxx - read word from xxxxxxxx\n"
321 "RL xxxxxxxx - read long from xxxxxxxx\n"
322 "WB xxxxxxxx bb - write byte bb at xxxxxxxx\n"
323 "WW xxxxxxxx wwww - write word wwww at xxxxxxxx\n"
324 "WL xxxxxxxx llllllll - write long llllllll at xxxxxxxx\n"
325 "RA xxxxxxxx ssssssss - read array(ssssssss bytes long) "
327 "RC xxxxxxxx ssssssss - read ascii (ssssssss bytes long) "
329 "QT 00000000 - quit SAD\n"
330 "SL - show all available libraries (libbase : libname)\n"
331 "SR - show all available resources (resbase : resname)\n"
332 "SD - show all available devices (devbase : devname)\n"
333 "SS xxxxxxxx - show symbol for xxxxxxxx\n"
334 "ST - show tasks (T - this, R - ready, W - wait)\n"
335 "HE - this help.\n");
337 /* AllocMem command */
338 else if (strcmp(comm
, "AM") == 0)
340 ULONG size
= GetL(data
);
341 ULONG requim
= GetL(NextWord(data
));
343 kprintf("Allocated at 0x%p\n", AllocVec(size
, requim
));
345 /* FreeMem command */
346 else if (strcmp(comm
, "FM") == 0)
348 APTR base
= GetA(&data
[0]);
350 kprintf("Freed at 0x%p\n", base
);
354 else if (strcmp(comm
, "RB") == 0)
356 UBYTE
*addr
= GetA(data
);
358 kprintf("Byte at 0x%p: %02X\n", addr
, *addr
);
361 else if (strcmp(comm
, "RW") == 0)
363 UWORD
*addr
= GetA(data
);
365 kprintf("Word at 0x%p: %04X\n", addr
, *addr
);
368 else if (strcmp(comm
, "RL") == 0)
370 ULONG
*addr
= GetA(data
);
372 kprintf("Long at 0x%p: %08X\n", addr
, *addr
);
375 else if (strcmp(comm
,"WB") == 0)
377 UBYTE
*addr
= GetA(data
);
378 UBYTE val
= GetB(NextWord(data
));
380 kprintf("Byte at 0x%p: %02X\n", addr
, val
);
384 else if (strcmp(comm
, "WW") == 0)
386 UWORD
*addr
= GetA(data
);
387 UWORD val
= GetW(NextWord(data
));
389 kprintf("Word at 0x%p: %04X\n", addr
, val
);
393 else if (strcmp(comm
, "WL") == 0)
395 ULONG
*addr
= GetA(data
);
396 ULONG val
= GetL(NextWord(data
));
398 kprintf("Long at 0x%p: %08X\n", addr
, val
);
402 else if (strcmp(comm
, "RA") == 0)
404 UBYTE
*ptr
= GetA(data
);
405 ULONG cnt
= GetL(NextWord(data
));
408 kprintf("Array from 0x%p (size=0x%08lX):\n", ptr
, cnt
);
410 for(t
= 1; t
<= cnt
; t
++)
412 kprintf("%02X ", *ptr
++);
413 if(!(t
% 16)) kprintf("\n");
418 else if (strcmp(comm
, "RC") == 0)
420 char *ptr
= GetA(data
);
421 ULONG cnt
= GetL(NextWord(data
));
424 kprintf("ASCII from 0x%p (size=%08X):\n", ptr
, cnt
);
426 for(t
= 1; t
<= cnt
; t
++)
429 if(!(t
% 70)) kprintf(" \n");
433 else if (strcmp(comm
, "SS") == 0) {
434 char *ptr
= GetA(data
);
435 STRPTR modname
= "(unknown)";
436 STRPTR symname
= "(unknown)";
437 APTR sym_l
= (APTR
)(IPTR
)0;
438 APTR sym_h
= (APTR
)~(IPTR
)0;
439 struct TagItem tags
[] = {
440 { DL_ModuleName
, (IPTR
)&modname
},
441 { DL_SymbolName
, (IPTR
)&symname
},
442 { DL_SymbolStart
, (IPTR
)&sym_l
},
443 { DL_SymbolEnd
, (IPTR
)&sym_h
},
448 DecodeLocationA(ptr
, tags
);
451 kprintf("%p %s %s+0x%x\n", sym_l
, sym_h
, modname
, symname
, (APTR
)ptr
- (APTR
)sym_l
);
453 else if (strcmp(comm
, "QT") == 0 && strcmp(data
, "00000000") == 0)
455 kprintf("Quitting SAD...\n");
456 KrnReleaseInput(); /* Release debug input */
459 else kprintf("?? Type HE for help\n");
465 /****************************************************************************************/
467 char GetK(struct ExecBase
*SysBase
)
479 /****************************************************************************************/
481 UQUAD
GetQ(char* string
)
487 for(i
= 0; i
< 16; i
++)
489 digit
= toupper(string
[i
]);
491 if (!isxdigit(digit
))
495 if (digit
> 9) digit
-= 'A' - '0' - 10;
496 ret
= (ret
<< 4) + digit
;
502 /****************************************************************************************/
504 ULONG
GetL(char* string
)
510 for(i
= 0; i
< 8; i
++)
512 digit
= toupper(string
[i
]);
514 if (!isxdigit(digit
))
518 if (digit
> 9) digit
-= 'A' - '0' - 10;
519 ret
= (ret
<< 4) + digit
;
525 /****************************************************************************************/
527 UWORD
GetW(char* string
)
533 for(i
= 0; i
< 4; i
++)
535 digit
= toupper(string
[i
]);
537 if (!isxdigit(digit
))
541 if (digit
> 9) digit
-= 'A' - '0' - 10;
542 ret
= (ret
<< 4) + digit
;
548 /****************************************************************************************/
550 UBYTE
GetB(char* string
)
556 for(i
= 0; i
< 2; i
++)
558 digit
= toupper(string
[i
]);
560 if (!isxdigit(digit
))
564 if (digit
> 9) digit
-= 'A' - '0' - 10;
565 ret
= (ret
<< 4) + digit
;