Removed autodocs of arch specific variants of ROM modules.
[AROS.git] / arch / i386-pc / exec / debug.c
blobf708bfb1d1f731ff587d19a41fff7b0c00f4484e
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Start the internal debugger.
6 Lang: english
7 */
9 #include <string.h>
10 #include "exec_intern.h"
11 #include <proto/exec.h>
12 #include <exec/types.h>
13 #include <asm/speaker.h>
15 /* See rom/exec/debug.c for documentation */
17 /****************************************************************************************/
19 #define Prompt kprintf("SAD(%ld,%ld)>",SysBase->TDNestCnt,SysBase->IDNestCnt)
21 /*#define GetHead(l) (void *)(((struct List *)l)->lh_Head->ln_Succ \
22 ? ((struct List *)l)->lh_Head \
23 : (struct Node *)0)
24 #define GetSucc(n) (void *)(((struct Node *)n)->ln_Succ->ln_Succ \
25 ? ((struct Node *)n)->ln_Succ \
26 : (struct Node *)0)
28 /****************************************************************************************/
30 void InitKeyboard(void);
31 char GetK();
32 void UnGetK();
33 void DumpRegs();
34 ULONG GetL(char*);
35 UWORD GetW(char*);
36 UBYTE GetB(char*);
37 int get_irq_list(char *buf);
39 /****************************************************************************************/
41 AROS_LH1(void, Debug,
42 AROS_LHA(unsigned long, flags, D0),
43 struct ExecBase *, SysBase, 19, Exec)
45 AROS_LIBFUNC_INIT
47 char key;
48 /* KeyCode -> ASCII conversion table */
49 static char transl[] =
50 { ' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ' ', ' ', ' ',
51 ' ', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', ' ', ' ', 10,
52 ' ', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ' ', ' ', ' ', ' ',
53 ' ', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' };
55 static char command[3] = {0, 0, 0};
56 static char data[70];
58 char *comm = &command[0];
59 char *dat = &data[0];
61 InitKeyboard();
65 int i;
67 Prompt;
69 /* Get Command code */
71 for(i = 0; i < 2; i++)
73 key = transl[GetK() - 1];
74 kprintf("%c", key);
75 UnGetK();
76 command[i] = key;
78 command[2] = 0;
80 kprintf(" ");
81 i = 0;
83 /* Now get data for command */
87 key = GetK();
88 key = transl[(key == 0x39) ? 1 : key - 1];
89 if (key != 10) kprintf("%c",key);
90 else kprintf("\n");
91 UnGetK();
92 if(key != ' ') data[i++]=key;
93 } while(key !=10 && i < 70);
94 data[i - 1] = 0;
96 /* Reboot command */
97 if (strcmp(comm, "RE") == 0 && strcmp(dat, "AAAAAAAA") == 0) ColdReboot();
98 /* Restart command, pulse reset signal */
99 else if (strcmp(comm, "RS") == 0 && strcmp(dat, "FFFFFFFF") == 0)
100 asm("movb $0xfe,%%al;outb %%al,$0x64":::"eax");
101 /* Forbid command */
102 else if (strcmp(comm, "FO") == 0)
103 Forbid();
104 /* Permit command */
105 else if (strcmp(comm, "PE") == 0)
106 Permit();
107 /* Disable command */
108 else if (strcmp(comm, "DI") == 0)
109 Disable();
110 /* Dump regs command */
111 else if (strcmp(comm, "DU") == 0)
112 DumpRegs();
113 else if (strcmp(comm, "MO") == 0)
114 asm("movb $0xa8,%%al;outb %%al,$0x64":::"eax");
115 /* Show active task information */
116 else if (strcmp(comm, "TI") == 0)
118 struct Task *t = SysBase->ThisTask;
120 kprintf("Active task (%p = '%s'):\n"
121 "tc_Node.ln_Pri = %d\n"
122 "tc_SigAlloc = %04.4lx\n"
123 "tc_SPLower = %p\n"
124 "tc_SPUpper = %p\n"
125 "tc_Flags = %08.8lx\n"
126 "tc_SPReg = %p\n",
127 t, t->tc_Node.ln_Name,
128 t->tc_Node.ln_Pri,
129 t->tc_SigAlloc,
130 t->tc_SPLower,
131 t->tc_SPUpper,
132 t->tc_Flags,
133 t->tc_SPReg);
135 /* else if (strcmp(comm,"RI") == 0)
138 struct pt_regs *r = (struct pt_regs *)SysBase->ThisTask->tc_UnionETask.tc_ETask->et_RegFrame;
140 kprintf("Active task's registers dump:\n"
141 "EAX=%p ECX=%p EDX=%p EIP=%p\n"
142 "CS=%04.4lx DS=%04.4lx ES=%04.4lx\n"
143 "SS=%04.4lx EFLAGS=%p\n",
144 r->eax, r->ecx, r->edx,
145 r->eip, r->xcs, r->xds, r->xes,
146 r->xss, r->eflags);
147 } */
148 /* Enable command */
149 else if (strcmp(comm, "EN") == 0)
150 Enable();
151 /* ShowLibs command */
152 else if (strcmp(comm, "SL") == 0)
154 struct Node * node;
156 kprintf("Available libraries:\n");
158 /* Look through the list */
159 for (node = GetHead(&SysBase->LibList); node; node = GetSucc(node))
161 kprintf("0x%08.8lx : %s\n", node, node->ln_Name);
164 else if (strcmp(comm, "SI") == 0)
166 // char buf[512];
168 kprintf("Available interrupts:\n");
170 // get_irq_list(&buf);
172 // kprintf(buf);
174 /* ShowResources command */
175 else if (strcmp(comm, "SR") == 0)
177 struct Node * node;
179 kprintf("Available resources:\n");
181 /* Look through the list */
182 for (node = GetHead(&SysBase->ResourceList); node; node = GetSucc(node))
184 kprintf("0x%08.8lx : %s\n", node, node->ln_Name);
187 /* ShowDevices command */
188 else if (strcmp(comm,"SD") == 0)
190 struct Node * node;
192 kprintf("Available devices:\n");
194 /* Look through the list */
195 for (node=GetHead(&SysBase->DeviceList); node; node = GetSucc(node))
197 kprintf("0x%08.8lx : %s\n", node, node->ln_Name);
200 /* ShowTasks command */
201 else if (strcmp(comm, "ST") == 0)
203 struct Node * node;
205 kprintf("Task List:\n");
207 kprintf("0x%08.8lx T %d %s\n",SysBase->ThisTask,
208 SysBase->ThisTask->tc_Node.ln_Pri,
209 SysBase->ThisTask->tc_Node.ln_Name);
211 /* Look through the list */
212 for (node = GetHead(&SysBase->TaskReady); node; node = GetSucc(node))
214 kprintf("0x%08.8lx R %d %s\n", node, node->ln_Pri, node->ln_Name);
217 for (node = GetHead(&SysBase->TaskWait); node; node = GetSucc(node))
219 kprintf("0x%08.8lx W %d %s\n", node, node->ln_Pri, node->ln_Name);
222 kprintf("Idle called %d times\n", SysBase->IdleCount);
224 /* Help command */
225 else if (strcmp(comm, "HE") == 0)
227 kprintf("SAD Help:\n");
228 kprintf("RE AAAAAAAA - reboots AROS - ColdReboot()\n"
229 "RS FFFFFFFF - RESET\n"
230 "FO - Forbid()\n"
231 "PE - Permit()\n"
232 "DI - Disable()\n"
233 "EN - Enable()\n"
234 "DU - Dump most important registers\n"
235 "SI - Show IRQ lines status\n"
236 "TI - Show Active task info\n"
237 "RI - Show registers inside task's context\n"
238 "AM xxxxxxxx yyyyyyyy - AllocVec - size=xxxxxxxx, "
239 "requirements=yyyyyyyy\n"
240 "FM xxxxxxxx - FreeVec from xxxxxxxx\n"
241 "RB xxxxxxxx - read byte from xxxxxxxx\n"
242 "RW xxxxxxxx - read word from xxxxxxxx\n"
243 "RL xxxxxxxx - read long from xxxxxxxx\n"
244 "WB xxxxxxxx bb - write byte bb at xxxxxxxx\n"
245 "WW xxxxxxxx wwww - write word wwww at xxxxxxxx\n"
246 "WL xxxxxxxx llllllll - write long llllllll at xxxxxxxx\n"
247 "RA xxxxxxxx ssssssss - read array(ssssssss bytes long) "
248 "from xxxxxxxx\n"
249 "RC xxxxxxxx ssssssss - read ascii (ssssssss bytes long) "
250 "from xxxxxxxx\n"
251 "QT 00000000 - quit SAD\n"
252 "SL - show all available libraries (libbase : libname)\n"
253 "SR - show all available resources (resbase : resname)\n"
254 "SD - show all available devices (devbase : devname)\n"
255 "ST - show tasks (T - this, R - ready, W - wait)\n"
256 "BE - beep\n"
257 "HE - this help.\n");
259 /* AllocMem command */
260 else if (strcmp(comm, "AM") == 0)
262 ULONG size = GetL(&data[0]);
263 ULONG requim = GetL(&data[8]);
265 kprintf("Allocated at %08.8lx\n", AllocVec(size, requim));
267 /* FreeMem command */
268 else if (strcmp(comm, "FM") == 0)
270 APTR base = (APTR)GetL(&data[0]);
271 kprintf("Freed at %08.8lx\n", base);
272 FreeVec(base);
274 /* ReadByte */
275 else if (strcmp(comm, "RB") == 0)
276 kprintf("Byte at %08.8lx:%02.8lx\n", GetL(&data[0]),
277 *(UBYTE*)(GetL(&data[0])));
278 /* ReadWord */
279 else if (strcmp(comm, "RW") == 0)
280 kprintf("Word at %08.8lx:%04.8lx\n", GetL(&data[0]),
281 *(UWORD*)(GetL(&data[0])));
282 /* ReadLong */
283 else if (strcmp(comm, "RL") == 0)
284 kprintf("Long at %08.8lx:%08.8lx\n", GetL(&data[0]),
285 *(ULONG*)(GetL(&data[0])));
286 /* WriteByte */
287 else if (strcmp(comm,"WB") == 0)
289 kprintf("Byte at %08.8lx:%02.8lx\n", GetL(&data[0]),
290 GetB(&data[8]));
291 *(UBYTE*)(GetL(&data[0])) = GetB(&data[8]);
293 /* WriteWord */
294 else if (strcmp(comm, "WW") == 0)
296 kprintf("Word at %08.8lx:%04.8lx\n", GetL(&data[0]),
297 GetW(&data[8]));
298 *(UWORD*)(GetL(&data[0])) = GetW(&data[8]);
300 /* WriteLong */
301 else if (strcmp(comm, "WL") == 0)
303 kprintf("Long at %08.8lx:%08.8lx\n", GetL(&data[0]),
304 GetL(&data[8]));
305 *(ULONG*)(GetL(&data[0])) = GetL(&data[8]);
307 /* ReadArray */
308 else if (strcmp(comm, "RA") == 0)
310 ULONG ptr;
311 int cnt, t;
313 kprintf("Array from %08.8lx (size=%08.8lx):\n", GetL(&data[0]),
314 GetL(&data[8]));
315 ptr = GetL(&data[0]);
316 cnt = (int)GetL(&data[8]);
317 for(t = 1; t <= cnt; t++)
319 kprintf("%02.2lx ", *(UBYTE*)ptr);
320 ptr++;
321 if(!(t % 16)) kprintf("\n");
323 kprintf("\n");
325 /* ReadASCII */
326 else if (strcmp(comm, "RC") == 0)
328 ULONG ptr;
329 int cnt, t;
331 kprintf("ASCII from %08.8lx (size=%08.8lx):\n", GetL(&data[0]),
332 GetL(&data[8]));
333 ptr = GetL(&data[0]);
334 cnt = (int)GetL(&data[8]);
335 for(t = 1; t <= cnt; t++)
337 kprintf("%c",*(char*)ptr);
338 ptr++;
339 if(!(t % 70)) kprintf(" \n");
341 kprintf(" \n");
343 else if (strcmp(comm, "BE") == 0)
345 ULONG i;
346 #define DELAY_1USEC() inb(0x80)
348 kprintf("Beeping...\n");
350 SetSpkFreq (400);
351 SpkOn();
352 for (i = 0; i < 2000000; i++)
353 DELAY_1USEC();
354 SpkOff();
355 for (i = 0; i < 1000000; i++)
356 DELAY_1USEC();
358 SetSpkFreq (500);
359 SpkOn();
360 for (i = 0; i < 2000000; i++)
361 DELAY_1USEC();
362 SpkOff();
363 for (i = 0; i < 1000000; i++)
364 DELAY_1USEC();
366 SetSpkFreq (592);
367 SpkOn();
368 for (i = 0; i < 2000000; i++)
369 DELAY_1USEC();
370 SpkOff();
371 for (i = 0; i < 1000000; i++)
372 DELAY_1USEC();
374 SetSpkFreq (788);
375 SpkOn();
376 for (i = 0; i < 2000000; i++)
377 DELAY_1USEC();
378 SpkOff();
381 else if (strcmp(comm, "QT") == 0 && strcmp(dat, "00000000") == 0)
384 else kprintf("?? Type HE for help\n");
386 } while(strcmp(comm, "QT") != 0 || strcmp(dat, "00000000") != 0);
388 kprintf("Quitting SAD...\n");
390 AROS_LIBFUNC_EXIT
391 } /* Debug */
393 /****************************************************************************************/
395 int getkey(void)
397 int i;
399 asm (
400 " xorl %%eax, %%eax \n"
401 " inb $0x64, %%al \n"
402 " andb $0x01, %%al \n"
403 " jz 2f \n"
404 " inb $0x60, %%al \n"
405 " movl %%eax, %0 \n"
406 " inb $0x61, %%al \n"
407 " movb %%al, %%ah \n"
408 " orb $0x80, %%al \n"
409 " outb %%al, $0x61 \n"
410 " movb %%ah, %%al \n"
411 " outb %%al, $0x61 \n"
412 " jmp 3f \n"
413 "2: movl $-1, %0 \n"
414 "3: \n"
415 : "=g" (i)
417 : "%eax"
420 return i;
423 /****************************************************************************************/
425 void InitKeyboard(void)
427 int i;
429 /* keyboard self test */
431 while(getkey() != -1);
433 asm (
434 "xorl %%eax,%%eax \n"
435 "movb $0xaa, %%al \n"
436 "outb %%al, $0x64 \n"
437 "inb $0x60, %%al \n"
438 "movl %%eax, %0 \n"
439 : "=g" (i)
441 : "%eax"
444 if(i == 0x55)
446 //kprintf("Debug(): Keyboard self-test okay :-)\n");
447 } else {
448 //kprintf("Debug(): Error: keyboard self-test failed.\n");
452 /****************************************************************************************/
454 void UnGetK()
458 /****************************************************************************************/
460 char GetK(void)
462 int i;
466 i = getkey();
467 } while((i == -1) || (i & 0x80));
469 return (char)i;
472 /****************************************************************************************/
474 ULONG GetL(char* string)
476 ULONG ret = 0;
477 int i;
478 char digit;
480 for(i = 0; i < 8; i++)
482 digit = (*string++) - '0';
483 if (digit > 9) digit -= 'A' - '0' - 10;
484 ret = (ret << 4) + digit;
487 return(ret);
490 /****************************************************************************************/
492 UWORD GetW(char* string)
494 UWORD ret = 0;
495 int i;
496 char digit;
498 for(i = 0; i < 4; i++)
500 digit = (*string++) - '0';
501 if (digit > 9) digit -= 'A' - '0' - 10;
502 ret = (ret << 4) + digit;
505 return(ret);
508 /****************************************************************************************/
510 UBYTE GetB(char* string)
512 UBYTE ret = 0;
513 int i;
514 char digit;
516 for(i = 0; i < 2; i++)
518 digit = (*string++) - '0';
519 if (digit > 9) digit -= 'A' - '0' - 10;
520 ret = (ret << 4) + digit;
523 return(ret);
526 /****************************************************************************************/
528 void DumpRegs()
530 int ds, cs, ss, eflags, esp;
532 asm("push %%ds\n\t"
533 "popl %0\n\t"
534 "push %%cs\n\t"
535 "popl %1\n\t"
536 "push %%ss\n\t"
537 "popl %2\n\t"
538 "pushfl\n\t"
539 "popl %3\n\t"
540 "pushl %%esp\n\t"
541 "popl %4"
542 :"=m"(ds),"=m"(cs),"=m"(ss),"=m"(eflags),"=m"(esp));
544 kprintf("DS=%04.4x CS=%04.4x SS=%04.4x ESP=%08.8x EFLAGS=%08.8x\n",
545 ds, cs, ss, esp, eflags);
548 /****************************************************************************************/