Re-enabled use of AROS.Boot file due to lack of general enthusiasm for
[tangerine.git] / arch / i386-pc / exec / debug.c
blobe9ee390f5ad71a301467d4dc5848b420ee6bd526
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Start the internal debugger.
6 Lang: english
7 */
8 #include <string.h>
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>
14 #include "etask.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 \
22 : (struct Node *)0)
23 #define GetSucc(n) (void *)(((struct Node *)n)->ln_Succ->ln_Succ \
24 ? ((struct Node *)n)->ln_Succ \
25 : (struct Node *)0)
27 /****************************************************************************************/
29 void InitKeyboard(void);
30 char GetK();
31 void UnGetK();
32 void DumpRegs();
33 ULONG GetL(char*);
34 UWORD GetW(char*);
35 UBYTE GetB(char*);
36 int get_irq_list(char *buf);
38 /****************************************************************************************/
41 /*****************************************************************************
43 NAME */
45 AROS_LH1(void, Debug,
47 /* SYNOPSIS */
48 AROS_LHA(unsigned long, flags, D0),
50 /* LOCATION */
51 struct ExecBase *, SysBase, 19, Exec)
53 /* FUNCTION
54 Runs SAD - internal debuger.
56 INPUTS
57 flags not used. Should be 0 now.
59 RESULT
61 NOTES
63 EXAMPLE
65 BUGS
67 SEE ALSO
69 INTERNALS
71 HISTORY
72 18-01-99 initial PC version.
74 *****************************************************************************/
76 AROS_LIBFUNC_INIT
78 char key;
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};
87 static char data[70];
89 char *comm = &command[0];
90 char *dat = &data[0];
92 InitKeyboard();
96 int i;
98 Prompt;
100 /* Get Command code */
102 for(i = 0; i < 2; i++)
104 key = transl[GetK() - 1];
105 kprintf("%c", key);
106 UnGetK();
107 command[i] = key;
109 command[2] = 0;
111 kprintf(" ");
112 i = 0;
114 /* Now get data for command */
118 key = GetK();
119 key = transl[(key == 0x39) ? 1 : key - 1];
120 if (key != 10) kprintf("%c",key);
121 else kprintf("\n");
122 UnGetK();
123 if(key != ' ') data[i++]=key;
124 } while(key !=10 && i < 70);
125 data[i - 1] = 0;
127 /* Reboot command */
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");
132 /* Forbid command */
133 else if (strcmp(comm, "FO") == 0)
134 Forbid();
135 /* Permit command */
136 else if (strcmp(comm, "PE") == 0)
137 Permit();
138 /* Disable command */
139 else if (strcmp(comm, "DI") == 0)
140 Disable();
141 /* Dump regs command */
142 else if (strcmp(comm, "DU") == 0)
143 DumpRegs();
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"
154 "tc_SPLower = %p\n"
155 "tc_SPUpper = %p\n"
156 "tc_Flags = %08.8lx\n"
157 "tc_SPReg = %p\n",
158 t, t->tc_Node.ln_Name,
159 t->tc_Node.ln_Pri,
160 t->tc_SigAlloc,
161 t->tc_SPLower,
162 t->tc_SPUpper,
163 t->tc_Flags,
164 t->tc_SPReg);
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,
177 r->xss, r->eflags);
179 /* Enable command */
180 else if (strcmp(comm, "EN") == 0)
181 Enable();
182 /* ShowLibs command */
183 else if (strcmp(comm, "SL") == 0)
185 struct Node * node;
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)
197 char buf[512];
199 kprintf("Available interrupts:\n");
201 // get_irq_list(&buf);
203 // kprintf(buf);
205 /* ShowResources command */
206 else if (strcmp(comm, "SR") == 0)
208 struct Node * node;
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)
221 struct Node * node;
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)
234 struct Node * node;
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);
255 /* Help command */
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"
261 "FO - Forbid()\n"
262 "PE - Permit()\n"
263 "DI - Disable()\n"
264 "EN - Enable()\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) "
279 "from xxxxxxxx\n"
280 "RC xxxxxxxx ssssssss - read ascii (ssssssss bytes long) "
281 "from xxxxxxxx\n"
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"
287 "BE - beep\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);
303 FreeVec(base);
305 /* ReadByte */
306 else if (strcmp(comm, "RB") == 0)
307 kprintf("Byte at %08.8lx:%02.8lx\n", GetL(&data[0]),
308 *(UBYTE*)(GetL(&data[0])));
309 /* ReadWord */
310 else if (strcmp(comm, "RW") == 0)
311 kprintf("Word at %08.8lx:%04.8lx\n", GetL(&data[0]),
312 *(UWORD*)(GetL(&data[0])));
313 /* ReadLong */
314 else if (strcmp(comm, "RL") == 0)
315 kprintf("Long at %08.8lx:%08.8lx\n", GetL(&data[0]),
316 *(ULONG*)(GetL(&data[0])));
317 /* WriteByte */
318 else if (strcmp(comm,"WB") == 0)
320 kprintf("Byte at %08.8lx:%02.8lx\n", GetL(&data[0]),
321 GetB(&data[8]));
322 *(UBYTE*)(GetL(&data[0])) = GetB(&data[8]);
324 /* WriteWord */
325 else if (strcmp(comm, "WW") == 0)
327 kprintf("Word at %08.8lx:%04.8lx\n", GetL(&data[0]),
328 GetW(&data[8]));
329 *(UWORD*)(GetL(&data[0])) = GetW(&data[8]);
331 /* WriteLong */
332 else if (strcmp(comm, "WL") == 0)
334 kprintf("Long at %08.8lx:%08.8lx\n", GetL(&data[0]),
335 GetL(&data[8]));
336 *(ULONG*)(GetL(&data[0])) = GetL(&data[8]);
338 /* ReadArray */
339 else if (strcmp(comm, "RA") == 0)
341 ULONG ptr;
342 int cnt, t;
344 kprintf("Array from %08.8lx (size=%08.8lx):\n", GetL(&data[0]),
345 GetL(&data[8]));
346 ptr = GetL(&data[0]);
347 cnt = (int)GetL(&data[8]);
348 for(t = 1; t <= cnt; t++)
350 kprintf("%02.2lx ", *(UBYTE*)ptr);
351 ptr++;
352 if(!(t % 16)) kprintf("\n");
354 kprintf("\n");
356 /* ReadASCII */
357 else if (strcmp(comm, "RC") == 0)
359 ULONG ptr;
360 int cnt, t;
362 kprintf("ASCII from %08.8lx (size=%08.8lx):\n", GetL(&data[0]),
363 GetL(&data[8]));
364 ptr = GetL(&data[0]);
365 cnt = (int)GetL(&data[8]);
366 for(t = 1; t <= cnt; t++)
368 kprintf("%c",*(char*)ptr);
369 ptr++;
370 if(!(t % 70)) kprintf(" \n");
372 kprintf(" \n");
374 else if (strcmp(comm, "BE") == 0)
376 ULONG i, dummy;
378 kprintf("Beeping...\n");
380 SetSpkFreq (400);
381 SpkOn();
382 for (i = 0; i < 100000000; dummy = i * i, i++);
383 SpkOff();
384 for (i = 0; i< 50000000; dummy = i * i, i++);
386 SetSpkFreq (500);
387 SpkOn();
388 for (i = 0; i < 100000000; dummy = i * i, i++);
389 SpkOff();
390 for (i = 0; i < 50000000; dummy = i * i, i++);
392 SetSpkFreq (592);
393 SpkOn();
394 for (i=0; i<100000000; dummy = i * i, i++);
395 SpkOff();
396 for (i=0; i< 50000000; dummy = i * i, i++);
398 SetSpkFreq (788);
399 SpkOn();
400 for (i = 0; i < 300000000; dummy = i * i, i++);
401 SpkOff();
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");
413 AROS_LIBFUNC_EXIT
414 } /* Debug */
416 /****************************************************************************************/
418 int getkey(void)
420 int i;
422 asm (
423 " xorl %%eax, %%eax \n"
424 " inb $0x64, %%al \n"
425 " andb $0x01, %%al \n"
426 " jz 2f \n"
427 " inb $0x60, %%al \n"
428 " movl %%eax, %0 \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"
435 " jmp 3f \n"
436 "2: movl $-1, %0 \n"
437 "3: \n"
438 : "=g" (i)
440 : "%eax"
443 return i;
446 /****************************************************************************************/
448 void InitKeyboard(void)
450 int i;
452 /* keyboard self test */
454 while(getkey() != -1);
456 asm (
457 "xorl %%eax,%%eax \n"
458 "movb $0xaa, %%al \n"
459 "outb %%al, $0x64 \n"
460 "inb $0x60, %%al \n"
461 "movl %%eax, %0 \n"
462 : "=g" (i)
464 : "%eax"
467 if(i == 0x55)
469 //kprintf("Debug(): Keyboard self-test okay :-)\n");
470 } else {
471 //kprintf("Debug(): Error: keyboard self-test failed.\n");
475 /****************************************************************************************/
477 void UnGetK()
481 /****************************************************************************************/
483 char GetK(void)
485 int i;
489 i = getkey();
490 } while((i == -1) || (i & 0x80));
492 return (char)i;
495 /****************************************************************************************/
497 ULONG GetL(char* string)
499 ULONG ret = 0;
500 int i;
501 char digit;
503 for(i = 0; i < 8; i++)
505 digit = (*string++) - '0';
506 if (digit > 9) digit -= 'A' - '0' - 10;
507 ret = (ret << 4) + digit;
510 return(ret);
513 /****************************************************************************************/
515 UWORD GetW(char* string)
517 UWORD ret = 0;
518 int i;
519 char digit;
521 for(i = 0; i < 4; i++)
523 digit = (*string++) - '0';
524 if (digit > 9) digit -= 'A' - '0' - 10;
525 ret = (ret << 4) + digit;
528 return(ret);
531 /****************************************************************************************/
533 UBYTE GetB(char* string)
535 UBYTE ret = 0;
536 int i;
537 char digit;
539 for(i = 0; i < 2; i++)
541 digit = (*string++) - '0';
542 if (digit > 9) digit -= 'A' - '0' - 10;
543 ret = (ret << 4) + digit;
546 return(ret);
549 /****************************************************************************************/
551 void DumpRegs()
553 int ds, cs, ss, eflags, esp;
555 asm("push %%ds\n\t"
556 "popl %0\n\t"
557 "push %%cs\n\t"
558 "popl %1\n\t"
559 "push %%ss\n\t"
560 "popl %2\n\t"
561 "pushfl\n\t"
562 "popl %3\n\t"
563 "pushl %%esp\n\t"
564 "popl %4"
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 /****************************************************************************************/