-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0001-Extend-debugging-prints-in-crt0.patch
46 lines (43 loc) · 2.92 KB
/
0001-Extend-debugging-prints-in-crt0.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 9438e3a61a310c09171a6b13aa860b26b2e1bd01 Mon Sep 17 00:00:00 2001
From: Steven van der Schoot <[email protected]>
Date: Sat, 31 Dec 2022 21:32:42 +0100
Subject: [PATCH] Extend debugging prints in crt0
---
picocrt/machine/arm/crt0.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/picocrt/machine/arm/crt0.c b/picocrt/machine/arm/crt0.c
index 39aed3e89..b53e489eb 100644
--- a/picocrt/machine/arm/crt0.c
+++ b/picocrt/machine/arm/crt0.c
@@ -166,6 +166,29 @@ static const char *const reasons[] = {
static void __attribute__((used))
arm_fault(struct fault *f, int reason)
{
+ const uint32_t cfsr = *(volatile uint32_t *)0xE000ED28;
+ const uint32_t usage_fault = cfsr & 0xffff0000 >> 16;
+
+ if(cfsr & 0x2000000) puts("Usage fault: The processor has executed an SDIV or UDIV instruction with a divisor of 0");
+ if(cfsr & 0x1000000) puts("Usage fault: The processor has made an unaligned memory access");
+ if(cfsr & 0x0080000) puts("Usage fault: The processor has attempted to access a coprocessor, but no coprosessor is present");
+ if(cfsr & 0x0040000) puts("Usage fault: The processor has attempted an illegal load of EXC_RETURN to the PC, as a result of an invalid context, or an invalid EXC_RETURN value");
+ if(cfsr & 0x0020000) puts("Usage fault: The processor has attempted to execute an instruction that makes illegal use of the EPSR");
+ if(cfsr & 0x0010000) puts("Usage fault: The processor has attempted to execute an undefined instruction");
+
+ if(cfsr & 0x1000) puts("Bus fault: Stacking for an exception entry has caused one or more bus faults");
+ if(cfsr & 0x0800) puts("Bus fault: Unstack for an exception return has caused one or more bus faults");
+ if(cfsr & 0x0400) puts("Bus fault: A data bus error has occurred, but the return address in the stack frame is not related to the instruction that caused the error");
+ if(cfsr & 0x0200) puts("Bus fault: A data bus error has occurred, and the PC value stacked for the exception return points to the instruction that caused the fault");
+ if(cfsr & 0x0100) puts("Bus fault: Instruction bus error");
+ if(cfsr & 0x8000) printf("Bus fault address: %p\n", (void*)0xE000ED38);
+
+ if(cfsr & 0x10) puts("Memory manage fault: Stacking for an exception entry has caused one or more access violations");
+ if(cfsr & 0x08) puts("Memory manage fault: Unstack for an exception return has caused one or more access violations");
+ if(cfsr & 0x02) puts("Memory manage fault: The processor attempted a load or store at a location that does not permit the operation");
+ if(cfsr & 0x01) puts("Memory manage fault: The processor attempted an instruction fetch from a location that does not permit execution");
+ if(cfsr & 0x80) printf("Memory manage fault address: %p\n", (void*)0xE000ED34);
+
printf("ARM fault: %s\n", reasons[reason]);
printf("\tR0: 0x%08x\n", f->r0);
printf("\tR1: 0x%08x\n", f->r1);
--
2.38.1