2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Start the internal debugger.
9 #include "exec_intern.h"
10 #include <proto/exec.h>
11 #include <exec/types.h>
12 #include <asm/ptrace.h>
13 #include <asm/speaker.h>
16 /****************************************************************************************/
18 #define Prompt kprintf("SAD(%ld,%ld)>",SysBase->TDNestCnt,SysBase->IDNestCnt)
20 /*#define GetHead(l) (void *)(((struct List *)l)->lh_Head->ln_Succ \
21 ? ((struct List *)l)->lh_Head \
23 #define GetSucc(n) (void *)(((struct Node *)n)->ln_Succ->ln_Succ \
24 ? ((struct Node *)n)->ln_Succ \
27 /****************************************************************************************/
29 void InitKeyboard(void);
36 int get_irq_list(char *buf
);
38 /****************************************************************************************/
41 /*****************************************************************************
48 AROS_LHA(unsigned long, flags
, D0
),
51 struct ExecBase
*, SysBase
, 19, Exec
)
54 Runs SAD - internal debuger.
57 flags not used. Should be 0 now.
72 18-01-99 initial PC version.
74 *****************************************************************************/
79 /* KeyCode -> ASCII conversion table */
80 static char transl
[] =
81 { ' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ' ', ' ', ' ',
82 ' ', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', ' ', ' ', 10,
83 ' ', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ' ', ' ', ' ', ' ',
84 ' ', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' };
86 static char command
[3] = {0, 0, 0};
89 char *comm
= &command
[0];
100 /* Get Command code */
102 for(i
= 0; i
< 2; i
++)
104 key
= transl
[GetK() - 1];
114 /* Now get data for command */
119 key
= transl
[(key
== 0x39) ? 1 : key
- 1];
120 if (key
!= 10) kprintf("%c",key
);
123 if(key
!= ' ') data
[i
++]=key
;
124 } while(key
!=10 && i
< 70);
128 if (strcmp(comm
, "RE") == 0 && strcmp(dat
, "AAAAAAAA") == 0) ColdReboot();
129 /* Restart command, pulse reset signal */
130 else if (strcmp(comm
, "RS") == 0 && strcmp(dat
, "FFFFFFFF") == 0)
131 asm("movb $0xfe,%%al;outb %%al,$0x64":::"eax");
133 else if (strcmp(comm
, "FO") == 0)
136 else if (strcmp(comm
, "PE") == 0)
138 /* Disable command */
139 else if (strcmp(comm
, "DI") == 0)
141 /* Dump regs command */
142 else if (strcmp(comm
, "DU") == 0)
144 else if (strcmp(comm
, "MO") == 0)
145 asm("movb $0xa8,%%al;outb %%al,$0x64":::"eax");
146 /* Show active task information */
147 else if (strcmp(comm
, "TI") == 0)
149 struct Task
*t
= SysBase
->ThisTask
;
151 kprintf("Active task (%p = '%s'):\n"
152 "tc_Node.ln_Pri = %d\n"
153 "tc_SigAlloc = %04.4lx\n"
156 "tc_Flags = %08.8lx\n"
158 t
, t
->tc_Node
.ln_Name
,
166 else if (strcmp(comm
,"RI") == 0)
168 struct pt_regs
*r
= (struct pt_regs
*)
169 GetIntETask(SysBase
->ThisTask
)->iet_Context
;
171 kprintf("Active task's registers dump:\n"
172 "EAX=%p ECX=%p EDX=%p EIP=%p\n"
173 "CS=%04.4lx DS=%04.4lx ES=%04.4lx\n"
174 "SS=%04.4lx EFLAGS=%p\n",
175 r
->eax
, r
->ecx
, r
->edx
,
176 r
->eip
, r
->xcs
, r
->xds
, r
->xes
,
180 else if (strcmp(comm
, "EN") == 0)
182 /* ShowLibs command */
183 else if (strcmp(comm
, "SL") == 0)
187 kprintf("Available libraries:\n");
189 /* Look through the list */
190 for (node
= GetHead(&SysBase
->LibList
); node
; node
= GetSucc(node
))
192 kprintf("0x%08.8lx : %s\n", node
, node
->ln_Name
);
195 else if (strcmp(comm
, "SI") == 0)
199 kprintf("Available interrupts:\n");
201 // get_irq_list(&buf);
205 /* ShowResources command */
206 else if (strcmp(comm
, "SR") == 0)
210 kprintf("Available resources:\n");
212 /* Look through the list */
213 for (node
= GetHead(&SysBase
->ResourceList
); node
; node
= GetSucc(node
))
215 kprintf("0x%08.8lx : %s\n", node
, node
->ln_Name
);
218 /* ShowDevices command */
219 else if (strcmp(comm
,"SD") == 0)
223 kprintf("Available devices:\n");
225 /* Look through the list */
226 for (node
=GetHead(&SysBase
->DeviceList
); node
; node
= GetSucc(node
))
228 kprintf("0x%08.8lx : %s\n", node
, node
->ln_Name
);
231 /* ShowTasks command */
232 else if (strcmp(comm
, "ST") == 0)
236 kprintf("Task List:\n");
238 kprintf("0x%08.8lx T %d %s\n",SysBase
->ThisTask
,
239 SysBase
->ThisTask
->tc_Node
.ln_Pri
,
240 SysBase
->ThisTask
->tc_Node
.ln_Name
);
242 /* Look through the list */
243 for (node
= GetHead(&SysBase
->TaskReady
); node
; node
= GetSucc(node
))
245 kprintf("0x%08.8lx R %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
248 for (node
= GetHead(&SysBase
->TaskWait
); node
; node
= GetSucc(node
))
250 kprintf("0x%08.8lx W %d %s\n", node
, node
->ln_Pri
, node
->ln_Name
);
253 kprintf("Idle called %d times\n", SysBase
->IdleCount
);
256 else if (strcmp(comm
, "HE") == 0)
258 kprintf("SAD Help:\n");
259 kprintf("RE AAAAAAAA - reboots AROS - ColdReboot()\n"
260 "RS FFFFFFFF - RESET\n"
265 "DU - Dump most important registers\n"
266 "SI - Show IRQ lines status\n"
267 "TI - Show Active task info\n"
268 "RI - Show registers inside task's context\n"
269 "AM xxxxxxxx yyyyyyyy - AllocVec - size=xxxxxxxx, "
270 "requiments=yyyyyyyy\n"
271 "FM xxxxxxxx - FreeVec from xxxxxxxx\n"
272 "RB xxxxxxxx - read byte from xxxxxxxx\n"
273 "RW xxxxxxxx - read word from xxxxxxxx\n"
274 "RL xxxxxxxx - read long from xxxxxxxx\n"
275 "WB xxxxxxxx bb - write byte bb at xxxxxxxx\n"
276 "WW xxxxxxxx wwww - write word wwww at xxxxxxxx\n"
277 "WL xxxxxxxx llllllll - write long llllllll at xxxxxxxx\n"
278 "RA xxxxxxxx ssssssss - read array(ssssssss bytes long) "
280 "RC xxxxxxxx ssssssss - read ascii (ssssssss bytes long) "
282 "QT 00000000 - quit SAD\n"
283 "SL - show all available libraries (libbase : libname)\n"
284 "SR - show all available resources (resbase : resname)\n"
285 "SD - show all available devices (devbase : devname)\n"
286 "ST - show tasks (T - this, R - ready, W - wait)\n"
288 "HE - this help.\n");
290 /* AllocMem command */
291 else if (strcmp(comm
, "AM") == 0)
293 ULONG size
= GetL(&data
[0]);
294 ULONG requim
= GetL(&data
[8]);
296 kprintf("Allocated at %08.8lx\n", AllocVec(size
, requim
));
298 /* FreeMem command */
299 else if (strcmp(comm
, "FM") == 0)
301 APTR base
= (APTR
)GetL(&data
[0]);
302 kprintf("Freed at %08.8lx\n", base
);
306 else if (strcmp(comm
, "RB") == 0)
307 kprintf("Byte at %08.8lx:%02.8lx\n", GetL(&data
[0]),
308 *(UBYTE
*)(GetL(&data
[0])));
310 else if (strcmp(comm
, "RW") == 0)
311 kprintf("Word at %08.8lx:%04.8lx\n", GetL(&data
[0]),
312 *(UWORD
*)(GetL(&data
[0])));
314 else if (strcmp(comm
, "RL") == 0)
315 kprintf("Long at %08.8lx:%08.8lx\n", GetL(&data
[0]),
316 *(ULONG
*)(GetL(&data
[0])));
318 else if (strcmp(comm
,"WB") == 0)
320 kprintf("Byte at %08.8lx:%02.8lx\n", GetL(&data
[0]),
322 *(UBYTE
*)(GetL(&data
[0])) = GetB(&data
[8]);
325 else if (strcmp(comm
, "WW") == 0)
327 kprintf("Word at %08.8lx:%04.8lx\n", GetL(&data
[0]),
329 *(UWORD
*)(GetL(&data
[0])) = GetW(&data
[8]);
332 else if (strcmp(comm
, "WL") == 0)
334 kprintf("Long at %08.8lx:%08.8lx\n", GetL(&data
[0]),
336 *(ULONG
*)(GetL(&data
[0])) = GetL(&data
[8]);
339 else if (strcmp(comm
, "RA") == 0)
344 kprintf("Array from %08.8lx (size=%08.8lx):\n", GetL(&data
[0]),
346 ptr
= GetL(&data
[0]);
347 cnt
= (int)GetL(&data
[8]);
348 for(t
= 1; t
<= cnt
; t
++)
350 kprintf("%02.2lx ", *(UBYTE
*)ptr
);
352 if(!(t
% 16)) kprintf("\n");
357 else if (strcmp(comm
, "RC") == 0)
362 kprintf("ASCII from %08.8lx (size=%08.8lx):\n", GetL(&data
[0]),
364 ptr
= GetL(&data
[0]);
365 cnt
= (int)GetL(&data
[8]);
366 for(t
= 1; t
<= cnt
; t
++)
368 kprintf("%c",*(char*)ptr
);
370 if(!(t
% 70)) kprintf(" \n");
374 else if (strcmp(comm
, "BE") == 0)
378 kprintf("Beeping...\n");
382 for (i
= 0; i
< 100000000; dummy
= i
* i
, i
++);
384 for (i
= 0; i
< 50000000; dummy
= i
* i
, i
++);
388 for (i
= 0; i
< 100000000; dummy
= i
* i
, i
++);
390 for (i
= 0; i
< 50000000; dummy
= i
* i
, i
++);
394 for (i
=0; i
<100000000; dummy
= i
* i
, i
++);
396 for (i
=0; i
< 50000000; dummy
= i
* i
, i
++);
400 for (i
= 0; i
< 300000000; dummy
= i
* i
, i
++);
404 else if (strcmp(comm
, "QT") == 0 && strcmp(dat
, "00000000") == 0)
407 else kprintf("?? Type HE for help\n");
409 } while(strcmp(comm
, "QT") != 0 || strcmp(dat
, "00000000") != 0);
411 kprintf("Quitting SAD...\n");
416 /****************************************************************************************/
423 " xorl %%eax, %%eax \n"
424 " inb $0x64, %%al \n"
425 " andb $0x01, %%al \n"
427 " inb $0x60, %%al \n"
429 " inb $0x61, %%al \n"
430 " movb %%al, %%ah \n"
431 " orb $0x80, %%al \n"
432 " outb %%al, $0x61 \n"
433 " movb %%ah, %%al \n"
434 " outb %%al, $0x61 \n"
446 /****************************************************************************************/
448 void InitKeyboard(void)
452 /* keyboard self test */
454 while(getkey() != -1);
457 "xorl %%eax,%%eax \n"
458 "movb $0xaa, %%al \n"
459 "outb %%al, $0x64 \n"
469 //kprintf("Debug(): Keyboard self-test okay :-)\n");
471 //kprintf("Debug(): Error: keyboard self-test failed.\n");
475 /****************************************************************************************/
481 /****************************************************************************************/
490 } while((i
== -1) || (i
& 0x80));
495 /****************************************************************************************/
497 ULONG
GetL(char* string
)
503 for(i
= 0; i
< 8; i
++)
505 digit
= (*string
++) - '0';
506 if (digit
> 9) digit
-= 'A' - '0' - 10;
507 ret
= (ret
<< 4) + digit
;
513 /****************************************************************************************/
515 UWORD
GetW(char* string
)
521 for(i
= 0; i
< 4; i
++)
523 digit
= (*string
++) - '0';
524 if (digit
> 9) digit
-= 'A' - '0' - 10;
525 ret
= (ret
<< 4) + digit
;
531 /****************************************************************************************/
533 UBYTE
GetB(char* string
)
539 for(i
= 0; i
< 2; i
++)
541 digit
= (*string
++) - '0';
542 if (digit
> 9) digit
-= 'A' - '0' - 10;
543 ret
= (ret
<< 4) + digit
;
549 /****************************************************************************************/
553 int ds
, cs
, ss
, eflags
, esp
;
565 :"=m"(ds
),"=m"(cs
),"=m"(ss
),"=m"(eflags
),"=m"(esp
));
567 kprintf("DS=%04.4x CS=%04.4x SS=%04.4x ESP=%08.8x EFLAGS=%08.8x\n",
568 ds
, cs
, ss
, esp
, eflags
);
571 /****************************************************************************************/