summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-01-27 21:19:47 -0800
committerPixel <pixel@nobis-crew.org>2011-01-27 21:19:47 -0800
commitbcfc9ad0a5d72f6d49fa96f221fdcb0930862539 (patch)
treebfa3d553290c3fef1e518afb7d6beda18acbe577
parentd15180e03ed30deb56e929d5007a4977cc7a9bd5 (diff)
Slightly more stable crash handler.
-rw-r--r--arch/arm/lpc17xx/handlers.c31
-rw-r--r--arch/arm/lpc17xx/startup.s4
2 files changed, 20 insertions, 15 deletions
diff --git a/arch/arm/lpc17xx/handlers.c b/arch/arm/lpc17xx/handlers.c
index b3366e0..ffd01dc 100644
--- a/arch/arm/lpc17xx/handlers.c
+++ b/arch/arm/lpc17xx/handlers.c
@@ -11,24 +11,29 @@ enum FaultType {
NMI = 2, HardFault, MemManage, BusFault, UsageFault,
};
-struct fault_data_t {
- uint32_t r4, r5, r6, r7, r8, r9, r10, r11, r0, r1, r2, r3, r12, lr, pc, xPSR;
+struct fault_data_cpu_t {
+ uint32_t r0, r1, r2, r3, r12, lr, pc, xPSR;
};
-static void print_fault_data(struct fault_data_t * fault_data1, struct fault_data_t * fault_data2) {
+struct fault_data_extra_t {
+ uint32_t r4, r5, r6, r7, r8, r9, r10, r11;
+};
+
+static void print_fault_data(struct fault_data_cpu_t * fault_data_cpu, struct fault_data_extra_t * fault_data_extra) {
// These ones are saved naturally by the CPU
- DBGOUT("pc: %p\r\n", fault_data1->pc);
- DBGOUT("sp = %p - lr = %p - r12 = %p -xPSR = %p\r\n", fault_data1 + 1, fault_data1->lr, fault_data1->r12, fault_data1->xPSR);
- DBGOUT("r0 = %p - r1 = %p - r2 = %p - r3 = %p\r\n", fault_data1->r0, fault_data1->r1, fault_data1->r2, fault_data1->r3);
+ DBGOUT("fd_cpu = %p - fd_extra = %p\r\n", fault_data_cpu, fault_data_extra);
+ DBGOUT("pc: %p\r\n", fault_data_cpu->pc);
+ DBGOUT("sp = %p - lr = %p - r12 = %p -xPSR = %p\r\n", fault_data_cpu + 1, fault_data_cpu->lr, fault_data_cpu->r12, fault_data_cpu->xPSR);
+ DBGOUT("r0 = %p - r1 = %p - r2 = %p - r3 = %p\r\n", fault_data_cpu->r0, fault_data_cpu->r1, fault_data_cpu->r2, fault_data_cpu->r3);
// These ones are saved by the ASM handler; hence the reason they are before in memory.
- DBGOUT("r4 = %p - r5 = %p - r6 = %p - r7 = %p\r\n", fault_data2->r4, fault_data2->r5, fault_data2->r6, fault_data2->r7);
- DBGOUT("r8 = %p - r9 = %p - r10 = %p - r11 = %p\r\n", fault_data2->r8, fault_data2->r9, fault_data2->r10, fault_data2->r11);
+ DBGOUT("r4 = %p - r5 = %p - r6 = %p - r7 = %p\r\n", fault_data_extra->r4, fault_data_extra->r5, fault_data_extra->r6, fault_data_extra->r7);
+ DBGOUT("r8 = %p - r9 = %p - r10 = %p - r11 = %p\r\n", fault_data_extra->r8, fault_data_extra->r9, fault_data_extra->r10, fault_data_extra->r11);
}
-void general_C_handler(enum FaultType fault, struct fault_data_t * fault_data2) {
- uintptr_t eflags = ((uintptr_t) __builtin_return_address(0)) & 15;
- struct fault_data_t * fault_data1 = (eflags & 4 ? fault_data2 : (struct fault_data_t *) __get_MSP());
- DBGOUT("***FAULT***\r\nType: ");
+void general_C_handler(enum FaultType fault, struct fault_data_extra_t * fault_data_extra, uintptr_t lr) {
+ uintptr_t eflags = lr & 15;
+ struct fault_data_cpu_t * fault_data_cpu = (struct fault_data_cpu_t *) ((eflags & 4) ? (void *) __get_PSP() : (void *) (fault_data_extra + 1));
+ DBGOUT("***FAULT***\r\neflags = 0x0%x\r\nPSP = %p\r\nType: ", eflags, __get_PSP());
switch (fault) {
case NMI:
DBGOUT("NMI\r\n");
@@ -49,7 +54,7 @@ void general_C_handler(enum FaultType fault, struct fault_data_t * fault_data2)
DBGOUT("Unknown\r\n");
}
- print_fault_data(fault_data1, fault_data2);
+ print_fault_data(fault_data_cpu, fault_data_extra);
DBGOUT("HALTING\r\n");
BoardExceptionHandler(-1);
diff --git a/arch/arm/lpc17xx/startup.s b/arch/arm/lpc17xx/startup.s
index d0917b6..86365c1 100644
--- a/arch/arm/lpc17xx/startup.s
+++ b/arch/arm/lpc17xx/startup.s
@@ -169,9 +169,9 @@ UsageFault_Handler:
MOV R0, 6
.type general_handler, %function
general_handler:
- MOV R1, SP
- SUB R1, #32
PUSH {R4-R11}
+ MOV R1, SP
+ MOV R2, LR
MOV R4, LR
BL general_C_handler
AND R0, #7