Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
rev13@wp.pl | b3b57e8 | 2015-03-01 12:44:39 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 |
Kamil Lulko | decd33b | 2015-11-29 11:50:53 +0100 | [diff] [blame] | 4 | * Kamil Lulko, <kamil.lulko@gmail.com> |
rev13@wp.pl | b3b57e8 | 2015-03-01 12:44:39 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | 643dc10 | 2024-04-30 07:35:59 -0600 | [diff] [blame] | 7 | #include <stdio.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | 9b61c7c | 2019-11-14 12:57:41 -0700 | [diff] [blame] | 9 | #include <irq_func.h> |
Tom Rini | 643dc10 | 2024-04-30 07:35:59 -0600 | [diff] [blame] | 10 | #include <vsprintf.h> |
rev13@wp.pl | b3b57e8 | 2015-03-01 12:44:39 +0100 | [diff] [blame] | 11 | |
| 12 | /* |
| 13 | * Upon exception entry ARMv7-M processors automatically save stack |
| 14 | * frames containing some registers. For simplicity initial |
| 15 | * implementation uses only this auto-saved stack frame. |
| 16 | * This does not contain complete register set dump, |
| 17 | * only R0-R3, R12, LR, PC and xPSR are saved. |
| 18 | */ |
| 19 | |
| 20 | struct autosave_regs { |
| 21 | long uregs[8]; |
| 22 | }; |
| 23 | |
| 24 | #define ARM_XPSR uregs[7] |
| 25 | #define ARM_PC uregs[6] |
| 26 | #define ARM_LR uregs[5] |
| 27 | #define ARM_R12 uregs[4] |
| 28 | #define ARM_R3 uregs[3] |
| 29 | #define ARM_R2 uregs[2] |
| 30 | #define ARM_R1 uregs[1] |
| 31 | #define ARM_R0 uregs[0] |
| 32 | |
| 33 | int interrupt_init(void) |
| 34 | { |
Ovidiu Panait | 8998e71 | 2020-04-20 10:31:44 +0300 | [diff] [blame] | 35 | enable_interrupts(); |
| 36 | |
rev13@wp.pl | b3b57e8 | 2015-03-01 12:44:39 +0100 | [diff] [blame] | 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | void enable_interrupts(void) |
| 41 | { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | int disable_interrupts(void) |
| 46 | { |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | void dump_regs(struct autosave_regs *regs) |
| 51 | { |
| 52 | printf("pc : %08lx lr : %08lx xPSR : %08lx\n", |
| 53 | regs->ARM_PC, regs->ARM_LR, regs->ARM_XPSR); |
| 54 | printf("r12 : %08lx r3 : %08lx r2 : %08lx\n" |
| 55 | "r1 : %08lx r0 : %08lx\n", |
| 56 | regs->ARM_R12, regs->ARM_R3, regs->ARM_R2, |
| 57 | regs->ARM_R1, regs->ARM_R0); |
| 58 | } |
| 59 | |
| 60 | void bad_mode(void) |
| 61 | { |
| 62 | panic("Resetting CPU ...\n"); |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 63 | reset_cpu(); |
rev13@wp.pl | b3b57e8 | 2015-03-01 12:44:39 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void do_hard_fault(struct autosave_regs *autosave_regs) |
| 67 | { |
| 68 | printf("Hard fault\n"); |
| 69 | dump_regs(autosave_regs); |
| 70 | bad_mode(); |
| 71 | } |
| 72 | |
| 73 | void do_mm_fault(struct autosave_regs *autosave_regs) |
| 74 | { |
| 75 | printf("Memory management fault\n"); |
| 76 | dump_regs(autosave_regs); |
| 77 | bad_mode(); |
| 78 | } |
| 79 | |
| 80 | void do_bus_fault(struct autosave_regs *autosave_regs) |
| 81 | { |
| 82 | printf("Bus fault\n"); |
| 83 | dump_regs(autosave_regs); |
| 84 | bad_mode(); |
| 85 | } |
| 86 | |
| 87 | void do_usage_fault(struct autosave_regs *autosave_regs) |
| 88 | { |
| 89 | printf("Usage fault\n"); |
| 90 | dump_regs(autosave_regs); |
| 91 | bad_mode(); |
| 92 | } |
| 93 | |
| 94 | void do_invalid_entry(struct autosave_regs *autosave_regs) |
| 95 | { |
| 96 | printf("Exception\n"); |
| 97 | dump_regs(autosave_regs); |
| 98 | bad_mode(); |
| 99 | } |