From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Subject: [RFC PATCH 3/4] ARM: rethrow CPU exceptions as sjlj-exceptions
Date: Wed, 1 Apr 2020 11:31:03 +0200 [thread overview]
Message-ID: <20200401093104.959691-4-ahmad@a3f.at> (raw)
In-Reply-To: <20200401093104.959691-1-ahmad@a3f.at>
Having to differentiate between hardware and software exceptions is
confusing, especially for newcomers. Be more welcoming by just treating
them the same.
Reviewed-by: Ahmad Fatoum <ahmad@a3f.at>
---
arch/arm/cpu/interrupts.c | 32 +++++++++-----------------------
common/startup.c | 32 ++++++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 25 deletions(-)
diff --git a/arch/arm/cpu/interrupts.c b/arch/arm/cpu/interrupts.c
index b9b91f315312..497167e4d2ab 100644
--- a/arch/arm/cpu/interrupts.c
+++ b/arch/arm/cpu/interrupts.c
@@ -27,6 +27,7 @@
#include <asm/ptrace.h>
#include <asm/unwind.h>
#include <init.h>
+#include "exceptions.h"
/* Avoid missing prototype warning, called from assembly */
void do_undefined_instruction (struct pt_regs *pt_regs);
@@ -80,11 +81,9 @@ void show_regs (struct pt_regs *regs)
#endif
}
-static void __noreturn do_exception(struct pt_regs *pt_regs)
+static void __noreturn do_exception(int exception, struct pt_regs *pt_regs)
{
- show_regs(pt_regs);
-
- panic("");
+ THROW_DATA(exception, NULL, XCEPT_DATA_NONDYN(pt_regs));
}
/**
@@ -93,8 +92,7 @@ static void __noreturn do_exception(struct pt_regs *pt_regs)
*/
void do_undefined_instruction (struct pt_regs *pt_regs)
{
- printf ("undefined instruction\n");
- do_exception(pt_regs);
+ do_exception(UndefinedInstructionException, pt_regs);
}
/**
@@ -106,8 +104,7 @@ void do_undefined_instruction (struct pt_regs *pt_regs)
*/
void do_software_interrupt (struct pt_regs *pt_regs)
{
- printf ("software interrupt\n");
- do_exception(pt_regs);
+ do_exception(SoftwareInterruptException, pt_regs);
}
/**
@@ -118,8 +115,7 @@ void do_software_interrupt (struct pt_regs *pt_regs)
*/
void do_prefetch_abort (struct pt_regs *pt_regs)
{
- printf ("prefetch abort\n");
- do_exception(pt_regs);
+ do_exception(PrefetchAbortException, pt_regs);
}
/**
@@ -130,15 +126,7 @@ void do_prefetch_abort (struct pt_regs *pt_regs)
*/
void do_data_abort (struct pt_regs *pt_regs)
{
- u32 far;
-
- asm volatile ("mrc p15, 0, %0, c6, c0, 0" : "=r" (far) : : "cc");
-
- printf("unable to handle %s at address 0x%08x\n",
- far < PAGE_SIZE ? "NULL pointer dereference" :
- "paging request", far);
-
- do_exception(pt_regs);
+ do_exception(DataAbortException, pt_regs);
}
/**
@@ -149,8 +137,7 @@ void do_data_abort (struct pt_regs *pt_regs)
*/
void do_fiq (struct pt_regs *pt_regs)
{
- printf ("fast interrupt request\n");
- do_exception(pt_regs);
+ do_exception(FiqException, pt_regs);
}
/**
@@ -161,8 +148,7 @@ void do_fiq (struct pt_regs *pt_regs)
*/
void do_irq (struct pt_regs *pt_regs)
{
- printf ("interrupt request\n");
- do_exception(pt_regs);
+ do_exception(IrqException, pt_regs);
}
extern volatile int arm_ignore_data_abort;
diff --git a/common/startup.c b/common/startup.c
index 41da1359def6..32f247c0276a 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -45,6 +45,8 @@
#include <console_countdown.h>
#include <environment.h>
#include <linux/ctype.h>
+#include <asm/unwind.h>
+#include <exceptions.h>
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
__barebox_initcalls_end[];
@@ -370,13 +372,39 @@ void __noreturn start_barebox(void)
while (1)
run_shell();
}
- } CATCH_ALL {
- panic("Unhandled exception");
+ } CATCH_ERRORS {
+ unwind_backtrace(GET_DATA);
+ } CATCH(UndefinedInstructionException) {
+ printf ("undefined instruction\n");
+ show_regs(GET_DATA);
+ } CATCH(SoftwareInterruptException) {
+ printf ("software interrupt\n");
+ show_regs(GET_DATA);
+ } CATCH(PrefetchAbortException) {
+ printf ("prefetch abort\n");
+ show_regs(GET_DATA);
+ } CATCH(DataAbortException) {
+ u32 far;
+
+ asm volatile ("mrc p15, 0, %0, c6, c0, 0" : "=r" (far) : : "cc");
+
+ printf("unable to handle %s at address 0x%08x\n",
+ far < PAGE_SIZE ? "NULL pointer dereference" :
+ "paging request", far);
+
+ show_regs((void*)((unsigned long)GET_DATA & ~1U));
+ } CATCH(FiqException) {
+ printf ("fast interrupt request\n");
+ show_regs(GET_DATA);
+ } CATCH (IrqException) {
+ printf ("interrupt request\n");
+ show_regs(GET_DATA);
}
ENDTRY;
+ panic("Unhandled exception");
}
void __noreturn hang (void)
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2020-04-01 9:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-01 9:31 [RFC PATCH 0/4] ARM: introduce sjlj structured exception handling Ahmad Fatoum
2020-04-01 9:31 ` [RFC PATCH 1/4] ARM: implement sjlj-based TRY/CATCH " Ahmad Fatoum
2020-04-02 19:51 ` Roland Hieber
2020-04-03 6:09 ` Ahmad Fatoum
2020-04-01 9:31 ` [RFC PATCH 2/4] startup: wrap barebox startup in TRY/CATCH Ahmad Fatoum
2020-04-01 9:31 ` Ahmad Fatoum [this message]
2020-04-01 9:31 ` [RFC PATCH 4/4] commands: implement except test command Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200401093104.959691-4-ahmad@a3f.at \
--to=ahmad@a3f.at \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox