use the locations specified in the bcm2708_boot header
[AROS.git] / rom / exec / debug.c
blobf938d5c59bed9425f9d5aad4ff9cab493af0680f
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Internal debugger.
6 Lang: english
7 */
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>
16 #include <ctype.h>
17 #include <string.h>
19 #include "exec_intern.h"
20 #include "exec_util.h"
22 /****************************************************************************************/
24 char GetK();
25 UQUAD GetQ(char *);
26 ULONG GetL(char *);
27 UWORD GetW(char *);
28 UBYTE GetB(char *);
29 int get_irq_list(char *buf);
31 #if __WORDSIZE == 64
32 #define GetA (APTR)GetQ
33 #else
34 #define GetA (APTR)GetL
35 #endif
37 /****************************************************************************************/
39 static char *NextWord(char *s)
41 /* Skip to first space or EOL */
42 while (*s != ' ')
44 if (!*s)
45 return s;
46 s++;
49 /* Then skip to first non-space */
50 while (*++s == ' ');
52 return s;
55 /*****************************************************************************
57 NAME */
59 AROS_LH1(void, Debug,
61 /* SYNOPSIS */
62 AROS_LHA(unsigned long, flags, D0),
64 /* LOCATION */
65 struct ExecBase *, SysBase, 19, Exec)
67 /* FUNCTION
68 Runs SAD - internal debuger.
70 INPUTS
71 flags not used. Should be 0 now.
73 RESULT
75 NOTES
77 EXAMPLE
79 BUGS
81 SEE ALSO
83 INTERNALS
85 HISTORY
86 18-01-99 initial PC version.
88 *****************************************************************************/
90 AROS_LIBFUNC_INIT
92 char comm[128];
93 char *data;
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())
101 return;
103 RawIOInit();
105 for (;;)
107 int i = 0;
109 kprintf("SAD(%d,%d)>", SysBase->TDNestCnt, SysBase->IDNestCnt);
111 /* Get Command code */
114 char key = GetK(SysBase);
115 BOOL t = ignorelf;
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. */
119 ignorelf = FALSE;
120 if (key == '\n') {
121 if (t)
122 continue;
123 else
124 break;
127 /* TABs are problematic to deal with, we ignore them */
128 else if (key == 0x09)
129 continue;
131 /* If we've just got CR, we may get LF next and we'll need to skip it */
132 else if (key == '\r') {
133 ignorelf = TRUE;
134 break;
137 /* Process backspace */
138 else if (key == 0x08)
140 if (i > 0) {
141 /* Go backwards, erase the character, then go backwards again */
142 RawPutChar(key);
143 RawPutChar(' ');
144 RawPutChar(key);
145 i--;
147 continue;
150 RawPutChar(key);
151 comm[i++] = key;
153 while (i < (int)sizeof(comm)-1);
154 comm[i] = 0;
155 RawPutChar('\n');
157 /* Now get data for command */
158 data = NextWord(comm);
159 comm[2] = 0;
161 /* Reboot command */
162 if (strcmp(comm, "RE") == 0 && strcmp(data, "AAAAAAAA") == 0)
163 ColdReboot();
164 /* Restart command */
165 else if (strcmp(comm, "RS") == 0 && strcmp(data, "FFFFFFFF") == 0)
166 ShutdownA(SD_ACTION_COLDREBOOT);
167 /* Forbid command */
168 else if (strcmp(comm, "FO") == 0)
169 Forbid();
170 /* Permit command */
171 else if (strcmp(comm, "PE") == 0)
172 Permit();
173 /* Disable command */
174 else if (strcmp(comm, "DI") == 0)
175 Disable();
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);
184 continue;
187 kprintf("Task status (%p = '%s'):\n"
188 "tc_Node.ln_Pri = %d\n"
189 "tc_Flags = %p\n"
190 "tc_SigAlloc = %04.4lx\n"
191 "tc_SigWait = %04.4lx\n"
192 "tc_SPLower = %p\n"
193 "tc_SPReg = %p\n"
194 "tc_SPUpper = %p\n"
195 "tc_IDNestCnt = %d\n"
196 "tc_TDNestCnt = %d\n",
197 t, t->tc_Node.ln_Name,
198 t->tc_Node.ln_Pri,
199 t->tc_Flags,
200 t->tc_SigAlloc,
201 t->tc_SigWait,
202 t->tc_SPLower,
203 t->tc_SPReg,
204 t->tc_SPUpper,
205 t->tc_IDNestCnt,
206 t->tc_TDNestCnt);
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);
215 continue;
218 kprintf("Task context (%p = '%s'):\n", t, t->tc_Node.ln_Name);
219 FormatCPUContext(NULL, t->tc_UnionETask.tc_ETask->et_RegFrame, SysBase);
220 RawPutChar('\n');
222 /* Enable command */
223 else if (strcmp(comm, "EN") == 0)
224 Enable();
225 /* ShowLibs command */
226 else if (strcmp(comm, "SL") == 0)
228 struct Node * node;
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)
240 /* char buf[512];
242 kprintf("Available interrupts:\n");
244 get_irq_list(&buf);
245 kprintf(buf);*/
246 kprintf("Not implemented\n");
248 /* ShowResources command */
249 else if (strcmp(comm, "SR") == 0)
251 struct Node * node;
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)
264 struct Node * node;
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)
277 struct Node * node;
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);
298 /* Help command */
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"
304 "FO - Forbid()\n"
305 "PE - Permit()\n"
306 "DI - Disable()\n"
307 "EN - Enable()\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) "
321 "from xxxxxxxx\n"
322 "RC xxxxxxxx ssssssss - read ascii (ssssssss bytes long) "
323 "from xxxxxxxx\n"
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);
346 FreeVec(base);
348 /* ReadByte */
349 else if (strcmp(comm, "RB") == 0)
351 UBYTE *addr = GetA(data);
353 kprintf("Byte at 0x%p: %02X\n", addr, *addr);
355 /* ReadWord */
356 else if (strcmp(comm, "RW") == 0)
358 UWORD *addr = GetA(data);
360 kprintf("Word at 0x%p: %04X\n", addr, *addr);
362 /* ReadLong */
363 else if (strcmp(comm, "RL") == 0)
365 ULONG *addr = GetA(data);
367 kprintf("Long at 0x%p: %08X\n", addr, *addr);
369 /* WriteByte */
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);
376 *addr = val;
378 /* WriteWord */
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);
385 *addr = val;
387 /* WriteLong */
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);
394 *addr = val;
396 /* ReadArray */
397 else if (strcmp(comm, "RA") == 0)
399 UBYTE *ptr = GetA(data);
400 ULONG cnt = GetL(NextWord(data));
401 ULONG t;
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");
410 kprintf("\n");
412 /* ReadASCII */
413 else if (strcmp(comm, "RC") == 0)
415 char *ptr = GetA(data);
416 ULONG cnt = GetL(NextWord(data));
417 ULONG t;
419 kprintf("ASCII from 0x%p (size=%08X):\n", ptr, cnt);
421 for(t = 1; t <= cnt; t++)
423 RawPutChar(*ptr++);
424 if(!(t % 70)) kprintf(" \n");
426 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 },
439 { TAG_END }
442 if (DebugBase) {
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 */
452 return;
454 else kprintf("?? Type HE for help\n");
457 AROS_LIBFUNC_EXIT
458 } /* Debug */
460 /****************************************************************************************/
462 char GetK(struct ExecBase *SysBase)
464 int i;
468 i = RawMayGetChar();
469 } while(i == -1);
471 return (char)i;
474 /****************************************************************************************/
476 UQUAD GetQ(char* string)
478 UQUAD ret = 0;
479 int i;
480 char digit;
482 for(i = 0; i < 16; i++)
484 digit = toupper(string[i]);
486 if (!isxdigit(digit))
487 break;
489 digit -= '0';
490 if (digit > 9) digit -= 'A' - '0' - 10;
491 ret = (ret << 4) + digit;
494 return ret;
497 /****************************************************************************************/
499 ULONG GetL(char* string)
501 ULONG ret = 0;
502 int i;
503 char digit;
505 for(i = 0; i < 8; i++)
507 digit = toupper(string[i]);
509 if (!isxdigit(digit))
510 break;
512 digit -= '0';
513 if (digit > 9) digit -= 'A' - '0' - 10;
514 ret = (ret << 4) + digit;
517 return ret;
520 /****************************************************************************************/
522 UWORD GetW(char* string)
524 UWORD ret = 0;
525 int i;
526 char digit;
528 for(i = 0; i < 4; i++)
530 digit = toupper(string[i]);
532 if (!isxdigit(digit))
533 break;
535 digit -= '0';
536 if (digit > 9) digit -= 'A' - '0' - 10;
537 ret = (ret << 4) + digit;
540 return ret;
543 /****************************************************************************************/
545 UBYTE GetB(char* string)
547 UBYTE ret = 0;
548 int i;
549 char digit;
551 for(i = 0; i < 2; i++)
553 digit = toupper(string[i]);
555 if (!isxdigit(digit))
556 break;
558 digit -= '0';
559 if (digit > 9) digit -= 'A' - '0' - 10;
560 ret = (ret << 4) + digit;
563 return ret;