blob: b977961bde8a2792054a9c679abe49a9b04c8f4f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
rev13@wp.plb3b57e82015-03-01 12:44:39 +01002/*
3 * (C) Copyright 2015
Kamil Lulkodecd33b2015-11-29 11:50:53 +01004 * Kamil Lulko, <kamil.lulko@gmail.com>
rev13@wp.plb3b57e82015-03-01 12:44:39 +01005 */
6
Tom Rini643dc102024-04-30 07:35:59 -06007#include <stdio.h>
Simon Glassafb02152019-12-28 10:45:01 -07008#include <cpu_func.h>
Simon Glass9b61c7c2019-11-14 12:57:41 -07009#include <irq_func.h>
Tom Rini643dc102024-04-30 07:35:59 -060010#include <vsprintf.h>
rev13@wp.plb3b57e82015-03-01 12:44:39 +010011
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
20struct 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
33int interrupt_init(void)
34{
Ovidiu Panait8998e712020-04-20 10:31:44 +030035 enable_interrupts();
36
rev13@wp.plb3b57e82015-03-01 12:44:39 +010037 return 0;
38}
39
40void enable_interrupts(void)
41{
42 return;
43}
44
45int disable_interrupts(void)
46{
47 return 0;
48}
49
50void 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
60void bad_mode(void)
61{
62 panic("Resetting CPU ...\n");
Harald Seiler6f14d5f2020-12-15 16:47:52 +010063 reset_cpu();
rev13@wp.plb3b57e82015-03-01 12:44:39 +010064}
65
66void do_hard_fault(struct autosave_regs *autosave_regs)
67{
68 printf("Hard fault\n");
69 dump_regs(autosave_regs);
70 bad_mode();
71}
72
73void 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
80void do_bus_fault(struct autosave_regs *autosave_regs)
81{
82 printf("Bus fault\n");
83 dump_regs(autosave_regs);
84 bad_mode();
85}
86
87void do_usage_fault(struct autosave_regs *autosave_regs)
88{
89 printf("Usage fault\n");
90 dump_regs(autosave_regs);
91 bad_mode();
92}
93
94void do_invalid_entry(struct autosave_regs *autosave_regs)
95{
96 printf("Exception\n");
97 dump_regs(autosave_regs);
98 bad_mode();
99}