import cbaos v0.1
[cbaos.git] / arch / arm-cortex-m3 / debug.c
blob15606010484f957df6ce0a2950f864c014c5c332
1 /* Author: Domen Puncer <domen@cba.si>. License: WTFPL, see file LICENSE */
2 #include <types.h>
3 #include <stdio.h>
4 #include <compiler.h>
5 #include <arch/cm3_regs.h>
6 #include <cbashell.h>
8 extern void _ram_start;
9 extern void _ram_end;
11 static const char * const exceptions[] = {
12 "Unknown",
13 "Reset",
14 "NMI",
15 "Hard Fault",
16 "Memory Management",
17 "Bus Fault",
18 "Usage Fault",
21 static const char * const regnames[16] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
22 "r8", "r9", "r10/sl", "r11/fp", "r12/ip", "sp", "lr", "pc" };
24 /* my precious debugging function
25 * HardFault is triggered on ie. invalid memory access.
26 * note: on IMPRECISERR, this doesn't help much. it just means that some
27 * invalid access occured but possibly before (after/prediction?) PC
29 void generic_exception_handler_c(u32 *oldstack, u32 *newstack, unsigned exception)
31 int oldstack_valid = (oldstack >= (u32*)&_ram_start && oldstack < (u32*)&_ram_end);
32 int i;
34 if (exception < ALEN(exceptions))
35 printf("%s was called, dumping regs:\n", exceptions[exception]);
36 else
37 printf("Exception #%i was caled, dumping regs:\n", exception);
39 printf("new_lr\t0x%08x\n", newstack[8]);
40 if (oldstack_valid) {
41 for (i=0; i<4; i++)
42 printf("%s\t0x%08x\t%i\n", regnames[i], oldstack[i], oldstack[i]);
43 } else {
44 printf("sp\t%p (newstack:%p)\n", oldstack, newstack);
45 printf("sp is invalid, so some registers are missing\n");
47 for (i=0; i<8; i++)
48 printf("%s\t0x%08x\t%i\n", regnames[i+4], newstack[i], newstack[i]);
50 if (oldstack_valid) {
51 printf("r12/ip\t0x%08x\t%i\n", oldstack[4], oldstack[4]);
52 printf("sp\t%p\n", oldstack);
53 printf("lr\t0x%08x\n", oldstack[5]);
54 printf("pc\t0x%08x\n", oldstack[6]);
55 printf("xPSR\t0x%08x\n", oldstack[7]);
58 printf("HFSR\t0x%08x\n", HFSR);
59 if (MMAR != 0xe000ed34)
60 printf("MMAR\t0x%08x\n", MMAR);
61 if (BFAR != 0xe000ed38)
62 printf("BFAR\t0x%08x\n", BFAR);
64 printf("\nentering cbashell\n");
65 cbashell_init();
66 while (1) {
67 int c;
68 c = getchar();
69 if (c >= 0)
70 cbashell_charraw(c);