From: Thomas Leonard <talex5@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Thomas Leonard <talex5@gmail.com>,
Dave.Scott@eu.citrix.com, anil@recoil.org,
stefano.stabellini@eu.citrix.com, samuel.thibault@ens-lyon.org
Subject: [PATCH ARM v7 12/13] mini-os: arm: show registers, stack and exception vector on fault
Date: Fri, 8 Aug 2014 16:47:41 +0100 [thread overview]
Message-ID: <1407512862-9373-13-git-send-email-talex5@gmail.com> (raw)
In-Reply-To: <1407512862-9373-1-git-send-email-talex5@gmail.com>
Signed-off-by: Thomas Leonard <talex5@gmail.com>
---
- Exit with SHUTDOWN_crash on BUG or fault (suggested by Ian Campbell).
- Fixed printk format types.
---
| 1 -
| 75 ++++++++++++++++++++++++++++---
| 98 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 166 insertions(+), 8 deletions(-)
create mode 100644 extras/mini-os/arch/arm/panic.c
--git a/extras/mini-os/ARM-TODO.txt b/extras/mini-os/ARM-TODO.txt
index 3226d39..1e40db1 100644
--- a/extras/mini-os/ARM-TODO.txt
+++ b/extras/mini-os/ARM-TODO.txt
@@ -1,4 +1,3 @@
-* support abort exception handling ( and others )
* gic request_irq implementation, currently all IRQs all hardcoded in gic irq handler.
* bind_*
* add multiple cpu support (?)
--git a/extras/mini-os/arch/arm/arm32.S b/extras/mini-os/arch/arm/arm32.S
index 73223c8..a08a170 100644
--- a/extras/mini-os/arch/arm/arm32.S
+++ b/extras/mini-os/arch/arm/arm32.S
@@ -162,8 +162,69 @@ irqstack:
.fill (1024), 4, 0x0
irqstack_end:
+fault_dump:
+ .fill 18, 4, 0x0 @ On fault, we save the registers + CPSR + handler address
+
.popsection
+fault:
+ cpsid aif @ Disable interrupts
+
+ ldr r13, =fault_dump
+ stmia r13, {r0-r12} @ Dump the non-banked registers directly (well, unless from FIQ mode)
+ str r14, [r13, #15 << 2] @ Our r14 is the faulting r15
+ mov r0, r13
+
+ @ Save the caller's CPSR (our SPSR) too.
+ mrs r1, SPSR
+ str r1, [r13, #16 << 2]
+
+ @ Switch to the mode we came from to get r13 and r14.
+ @ If coming from user mode, use System mode instead so we're still
+ @ privileged.
+ and r1, r1, #0x1f @ r1 = SPSR mode
+ cmp r1, #0x10 @ If from User mode
+ moveq r1, #0x1f @ Then use System mode instead
+
+ mrs r3, CPSR @ r3 = our CPSR
+ bic r2, r3, #0x1f
+ orr r2, r2, r1
+ msr CPSR, r2 @ Change to mode r1
+
+ @ Save old mode's r13, r14
+ str r13, [r0, #13 << 2]
+ str r14, [r0, #14 << 2]
+
+ msr CPSR, r3 @ Back to fault mode
+
+ ldr r1, [r0, #17 << 2]
+ sub r1, r1, #12 @ Fix to point at start of handler
+ str r1, [r0, #17 << 2]
+
+ @ Call C code to format the register dump.
+ @ Clobbers the stack, but we're not going to return anyway.
+ ldr sp, =_boot_stack_end
+ bl dump_registers
+ b do_exit
+
+@ We want to store a unique value to identify this handler, without corrupting
+@ any of the registers. So, we store r15 (which will point just after the branch).
+@ Later, we subtract 12 so the user gets pointed at the start of the exception
+@ handler.
+#define FAULT(name) \
+.globl fault_##name; \
+fault_##name: \
+ ldr r13, =fault_dump; \
+ str r15, [r13, #17 << 2]; \
+ b fault
+
+FAULT(reset)
+FAULT(undefined_instruction)
+FAULT(svc)
+FAULT(prefetch_call)
+FAULT(prefetch_abort)
+FAULT(data_abort)
+
@ exception base address
.align 5
.globl exception_vector_table
@@ -173,13 +234,13 @@ irqstack_end:
@ instruction to clear an existing tag is required on context switches."
@ -- ARM Cortex-A Series Programmer’s Guide (Version: 4.0)
exception_vector_table:
- b . @ reset
- b . @ undefined instruction
- b . @ supervisor call
- b . @ prefetch call
- b . @ prefetch abort
- b . @ data abort
- b irq_handler @ irq
+ b fault_reset
+ b fault_undefined_instruction
+ b fault_svc
+ b fault_prefetch_call
+ b fault_prefetch_abort
+ b fault_data_abort
+ b irq_handler @ IRQ
.word 0xe7f000f0 @ abort on FIQ
@ Call fault_undefined_instruction in "Undefined mode"
--git a/extras/mini-os/arch/arm/panic.c b/extras/mini-os/arch/arm/panic.c
new file mode 100644
index 0000000..a049d05
--- /dev/null
+++ b/extras/mini-os/arch/arm/panic.c
@@ -0,0 +1,98 @@
+/******************************************************************************
+ * panic.c
+ *
+ * Displays a register dump and stack trace for debugging.
+ *
+ * Copyright (c) 2014, Thomas Leonard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <mini-os/os.h>
+#include <mini-os/console.h>
+#include <arch_mm.h>
+
+extern int irqstack[];
+extern int irqstack_end[];
+
+typedef void handler(void);
+
+extern handler fault_reset;
+extern handler fault_undefined_instruction;
+extern handler fault_svc;
+extern handler fault_prefetch_call;
+extern handler fault_prefetch_abort;
+extern handler fault_data_abort;
+
+void dump_registers(int *saved_registers) {
+ static int in_dump = 0;
+ int *sp, *stack_top, *x;
+ char *fault_name;
+ void *fault_handler;
+ int i;
+
+ if (in_dump)
+ {
+ printk("Crash while in dump_registers! Not generating a second report.\n");
+ return;
+ }
+
+ in_dump = 1;
+
+ fault_handler = (handler *) saved_registers[17];
+ if (fault_handler == fault_reset)
+ fault_name = "reset";
+ else if (fault_handler == fault_undefined_instruction)
+ fault_name = "undefined_instruction";
+ else if (fault_handler == fault_svc)
+ fault_name = "svc";
+ else if (fault_handler == fault_prefetch_call)
+ fault_name = "prefetch_call";
+ else if (fault_handler == fault_prefetch_abort)
+ fault_name = "prefetch_abort";
+ else if (fault_handler == fault_data_abort)
+ fault_name = "data_abort";
+ else
+ fault_name = "unknown fault type!";
+
+ printk("Fault handler at %p called (%s)\n", fault_handler, fault_name);
+
+ for (i = 0; i < 16; i++) {
+ printk("r%d = %x\n", i, saved_registers[i]);
+ }
+ printk("CPSR = %x\n", saved_registers[16]);
+
+ printk("Stack dump (innermost last)\n");
+ sp = (int *) saved_registers[13];
+
+ if (sp >= _boot_stack && sp <= _boot_stack_end)
+ stack_top = _boot_stack_end; /* The boot stack */
+ else if (sp >= irqstack && sp <= irqstack_end)
+ stack_top = irqstack_end; /* The IRQ stack */
+ else
+ stack_top = (int *) ((((unsigned long) sp) | (__STACK_SIZE-1)) + 1); /* A normal thread stack */
+
+ for (x = stack_top - 1; x >= sp; x--)
+ {
+ printk(" [%8p] %8x\n", x, *x);
+ }
+ printk("End of stack\n");
+
+ in_dump = 0;
+}
--
2.0.3
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2014-08-08 15:47 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-08 15:47 [PATCH ARM v7 00/13] mini-os: initial ARM support Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 01/13] mini-os: don't include lib.h from mm.h Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 02/13] mini-os: added HYPERVISOR_xsm_op Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 03/13] mini-os: move poor rand function to test.c Thomas Leonard
2014-08-08 16:37 ` Samuel Thibault
2014-08-11 7:59 ` Thomas Leonard
2014-08-11 9:29 ` Samuel Thibault
2014-08-28 15:07 ` Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 04/13] mini-os: arm: add header files Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 05/13] mini-os: arm: boot code Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 06/13] mini-os: arm: memory management Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 07/13] mini-os: arm: scheduling Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 08/13] mini-os: arm: events Thomas Leonard
2014-09-08 11:52 ` Ian Campbell
2014-08-08 15:47 ` [PATCH ARM v7 09/13] mini-os: arm: time Thomas Leonard
2014-09-08 10:59 ` Ian Campbell
2014-09-08 16:08 ` Thomas Leonard
2014-09-22 10:35 ` Dave Scott
2014-09-23 16:53 ` Stefano Stabellini
2014-09-26 10:01 ` Thomas Leonard
2014-10-01 11:10 ` Thomas Leonard
2014-10-01 11:10 ` Thomas Leonard
2014-10-01 11:31 ` Ian Campbell
2014-08-08 15:47 ` [PATCH ARM v7 10/13] mini-os: arm: interrupt controller Thomas Leonard
2014-09-08 11:01 ` Ian Campbell
2014-08-08 15:47 ` [PATCH ARM v7 11/13] mini-os: arm: build system Thomas Leonard
2014-09-08 11:05 ` Ian Campbell
2014-08-08 15:47 ` Thomas Leonard [this message]
2014-09-08 11:06 ` [PATCH ARM v7 12/13] mini-os: arm: show registers, stack and exception vector on fault Ian Campbell
2014-08-08 15:47 ` [PATCH ARM v7 13/13] mini-os: fixed compiling with debug=n Thomas Leonard
2014-09-08 11:08 ` Ian Campbell
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=1407512862-9373-13-git-send-email-talex5@gmail.com \
--to=talex5@gmail.com \
--cc=Dave.Scott@eu.citrix.com \
--cc=anil@recoil.org \
--cc=samuel.thibault@ens-lyon.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.