Early exception handlers on Power
v3 cover Early exception handlers on Power
Hello all,
This series implements a basic exception handler and the required support infrastructure on Power. Currently the handler just dumps all registers to the serial console and nothing else, but even this is useful for debugging during early bring-up.
Thanks,
Shawn Anastasio (2):
xen/ppc: Add .text.exceptions section for exception vectors xen/ppc: Implement a basic exception handler
xen/arch/ppc/include/asm/config.h | 3 + xen/arch/ppc/include/asm/processor.h | 31 +++++++ xen/arch/ppc/ppc64/Makefile | 2 + xen/arch/ppc/ppc64/asm-offsets.c | 1 + xen/arch/ppc/ppc64/exceptions-asm.S | 129 +++++++++++++++++++++++++++ xen/arch/ppc/ppc64/exceptions.c | 102 +++++++++++++++++++++ xen/arch/ppc/setup.c | 11 +++ xen/arch/ppc/xen.lds.S | 7 ++ 8 files changed, 286 insertions(+) create mode 100644 xen/arch/ppc/ppc64/exceptions-asm.S create mode 100644 xen/arch/ppc/ppc64/exceptions.c
--
2.30.2
PATCH v3 1/2 xen/ppc: Add .text.exceptions section for exception vectors
On Power, the exception vectors must lie at a fixed address, depending on the state of the Alternate Interrupt Location (AIL) field of the Logical Partition Control Register (LPCR). Create a .text.exceptions section in the linker script at an address suitable for AIL=3 plus an accompanying assertion to pave the way for implementing exception support.
--- xen/arch/ppc/include/asm/config.h | 3 +++ xen/arch/ppc/xen.lds.S | 7 +++++++ 2 files changed, 10 insertions(+)
xen/arch/ppc/include/asm/config.h +3 -0
@@ -42,6 +42,9 @@#define XEN_VIRT_START _AC(0xc000000000000000, UL) +/* Fixed address for start of the section containing exception vectors */ +#define EXCEPTION_VECTORS_START _AC(0xc000000000000100, UL) +#define VMAP_VIRT_START (XEN_VIRT_START + GB(1))#define VMAP_VIRT_SIZE GB(1)
xen/arch/ppc/xen.lds.S +7 -0
@@ -24,6 +24,10 @@ SECTIONS _stext = .; /* Text section */ *(.text.header) + . = ALIGN(256); + HIDDEN(_stext_exceptions = .); + *(.text.exceptions) + *(.text.cold) *(.text.unlikely .text.*_unlikely .text.unlikely.*)
@@ -184,3 +188,6 @@ ASSERT(IS_ALIGNED(__bss_end, POINTER_ALIGN), "__bss_end is misaligned") ASSERT(!SIZEOF(.got), ".got non-empty") ASSERT(!SIZEOF(.got.plt), ".got.plt non-empty") + +ASSERT(_stext_exceptions == EXCEPTION_VECTORS_START, + ".text.exceptions not at expected location -- .text.header too big?");
Signature · 1 line
2.30.2
PATCH v3 2/2 xen/ppc: Implement a basic exception handler
In reply to Shawn AnastasioImplement a basic exception handler that dumps the CPU state to the console, as well as the code required to set the correct exception vector table's base address in setup.c.
---
v3:
- Add comment to explain %r1 clobber
- Add comment about ISR declaration order
- Drop redundant " Interrupt" from exception name strings
v2:
- Place {h_,}exception_common in .text.exceptions section
- Use assembler macro instead of CPP macro for ISR definition
- Tabulate ISR definitions
xen/arch/ppc/include/asm/processor.h | 31 +++++++ xen/arch/ppc/ppc64/Makefile | 2 + xen/arch/ppc/ppc64/asm-offsets.c | 1 + xen/arch/ppc/ppc64/exceptions-asm.S | 129 +++++++++++++++++++++++++++ xen/arch/ppc/ppc64/exceptions.c | 102 +++++++++++++++++++++ xen/arch/ppc/setup.c | 11 +++ 6 files changed, 276 insertions(+) create mode 100644 xen/arch/ppc/ppc64/exceptions-asm.S create mode 100644 xen/arch/ppc/ppc64/exceptions.c
xen/arch/ppc/include/asm/processor.h +31 -0
@@ -103,6 +103,37 @@#define PVR_BE 0x0070#define PVR_PA6T 0x0090 +/* Exception Definitions */ +#define EXC_SYSTEM_RESET 0x0100/* System Reset Interrupt */ +#define EXC_MACHINE_CHECK 0x0200/* Machine Check Interrupt */ +#define EXC_DATA_STORAGE 0x0300/* Data Storage Interrupt */ +#define EXC_DATA_SEGMENT 0x0380/* Data Segment Interrupt */ +#define EXC_INSN_STORAGE 0x0400/* Instruction Storage Interrupt */ +#define EXC_INSN_SEGMENT 0x0480/* Instruction Segment Interrupt */ +#define EXC_EXTERNAL 0x0500/* External Interrupt */ +#define EXC_ALIGNMENT 0x0600/* Alignment Interrupt */ +#define EXC_PROGRAM 0x0700/* Program Interrupt */ +#define EXC_FPU_UNAVAIL 0x0800/* Floating-Point Unavailable Interrupt */ +#define EXC_DECREMENTER 0x0900/* Decrementer Interrupt */ +#define EXC_H_DECREMENTER 0x0980/* Hypervisor Decrementer Interrupt */ +#define EXC_PRIV_DOORBELL 0x0A00/* Directed Privileged Doorbell Interrupt */ +#define EXC_SYSTEM_CALL 0x0C00/* System Call Interrupt */ +#define EXC_TRACE 0x0D00/* Trace Interrupt */ +#define EXC_H_DATA_STORAGE 0x0E00/* Hypervisor Data Storage Interrupt */ +#define EXC_H_INSN_STORAGE 0x0E20/* Hypervisor Instruction Storage Interrupt */ +#define EXC_H_EMUL_ASST 0x0E40/* Hypervisor Emulation Assistance Interrupt */ +#define EXC_H_MAINTENANCE 0x0E60/* Hypervisor Maintenance Interrupt */ +#define EXC_H_DOORBELL 0x0E80/* Directed Hypervisor Doorbell Interrupt */ +#define EXC_H_VIRT 0x0EA0/* Hypervisor Virtualization Interrupt */ +#define EXC_PERF_MON 0x0F00/* Performance Monitor Interrupt */ +#define EXC_VECTOR_UNAVAIL 0x0F20/* Vector Unavailable Interrupt */ +#define EXC_VSX_UNAVAIL 0x0F40/* VSX Unavailable Interrupt */ +#define EXC_FACIL_UNAVAIL 0x0F60/* Facility Unavailable Interrupt */ +#define EXC_H_FACIL_UNAVAIL 0x0F80/* Hypervisor Facility Unavailable Interrupt */ + +/* Base address of interrupt vector table when LPCR[AIL]=3 */ +#define AIL_VECTOR_BASE _AC(0xc000000000004000, UL) +#ifndef __ASSEMBLY__#include <xen/types.h>
xen/arch/ppc/ppc64/Makefile +2 -0
@@ -1,2 +1,4 @@ +obj-y += exceptions.o +obj-y += exceptions-asm.o obj-y += head.o obj-y += opal-calls.o
xen/arch/ppc/ppc64/asm-offsets.c +1 -0
@@ -46,6 +46,7 @@ void __dummy__(void) OFFSET(UREGS_dsisr, struct cpu_user_regs, dsisr); OFFSET(UREGS_cr, struct cpu_user_regs, cr); OFFSET(UREGS_fpscr, struct cpu_user_regs, fpscr); + OFFSET(UREGS_entry_vector, struct cpu_user_regs, entry_vector);DEFINE (UREGS_sizeof,sizeof (struct cpu_user_regs )); OFFSET(OPAL_base, struct opal, base);
xen/arch/ppc/ppc64/exceptions-asm.S new file +135 -0
135 lines not on this page · raw message
xen/arch/ppc/ppc64/exceptions.c new file +102 -0
102 lines not on this page · raw message
xen/arch/ppc/setup.c +11 -0
@@ -11,6 +11,15 @@/* Xen stack for bringing up the first CPU. */ unsigned char __initdata cpu0_boot_stack[STACK_SIZE ]__aligned(STACK_SIZE) ; +void setup_exceptions (void ) +{ +unsigned long lpcr; + +/* Set appropriate interrupt location in LPCR */ + lpcr =mfspr (SPRN_LPCR ); +mtspr (SPRN_LPCR , lpcr |LPCR_AIL_3 ); +} +void __init noreturnstart_xen (unsigned long r3,unsigned long r4,unsigned long r5,unsigned long r6,unsigned long r7)
@@ -26,6 +35,8 @@ void __init noreturn start_xen(unsigned long r3, unsigned long r4,boot_opal_init ((void *)r3); } +setup_exceptions (); +setup_initial_pagetables ();early_printk ("Hello, ppc64le!\n" );
--
2.30.2
Re: [PATCH v3 2/2] xen/ppc: Implement a basic exception handler
Quoted 5 lines · Shawn Anastasio
Implement a basic exception handler that dumps the CPU state to the console, as well as the code required to set the correct exception vector table's base address in
setup.c.Signed-off-by Shawn Anastasio <[email protected]>
Despite me being unhappy about the disconnect of the constants
One further remark/suggestion though (happy to take care of while committing):
Quoted 7 lines
xen/arch/ppc/ppc64/exceptions-asm.S new file +4
-0@@ -0,0 +1,135 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <asm/asm-defns.h> +#include <asm/processor.h>
xen/arch/ppc/ppc64/exceptions-asm.S line 14
Quoted 10 lines
xen/arch/ppc/ppc64/exceptions-asm.S new file +10
-0+ + .section .text.exceptions, "ax", %progbits + + /* Helper to dump CPU state to struct cpu_user_regs pointed to by r1. */ +ENTRY(exception_common) + /* + * Save GPRs 1-31. TODO: The value of %r1 has already been modified by the + * ISR, so the value we save isn't the exact value we had on entry. + */ + SAVE_GPRS(1, 31, %r1)
Wouldn't this comment ...
Quoted 29 lines
xen/arch/ppc/ppc64/exceptions-asm.S new file +29
-0+ /* Save LR, CTR, CR */ + mflr %r0 + std %r0, UREGS_lr(%r1) + mfctr %r0 + std %r0, UREGS_ctr(%r1) + mfcr %r0 + stw %r0, UREGS_cr(%r1) /* 32-bit */ + + /* Save Exception Registers */ + mfsrr0 %r0 + std %r0, UREGS_pc(%r1) + mfsrr1 %r0 + std %r0, UREGS_msr(%r1) + mfdsisr %r0 + stw %r0, UREGS_dsisr(%r1) /* 32-bit */ + mfdar %r0 + std %r0, UREGS_dar(%r1) + li %r0, -1 /* OS's SRR0/SRR1 have been clobbered */ + std %r0, UREGS_srr0(%r1) + std %r0, UREGS_srr1(%r1) + + /* Setup TOC and a stack frame then call C exception handler */ + mr %r3, %r1 + bcl 20, 31, 1f +1: mflr %r12 + addis %r2, %r12, .TOC.-1b@ha + addi %r2, %r2, .TOC.-1b@l + + li %r0, 0
xen/arch/ppc/ppc64/exceptions-asm.S line 54
Quoted 10 lines
xen/arch/ppc/ppc64/exceptions-asm.S new file +10
-0+ stdu %r0, -STACK_FRAME_OVERHEAD(%r1) + bl exception_handler + + .size exception_common, . - exception_common + .type exception_common, %function + + /* Same as exception_common, but for exceptions that set HSRR{0,1} */ +ENTRY(h_exception_common) + /* Save GPRs 1-31 */ + SAVE_GPRS(1, 31, %r1)
... better be repeated here?
Jan
Re: [PATCH v3 2/2] xen/ppc: Implement a basic exception handler
Quoted 65 lines · Jan Beulich
Quoted 5 lines · Shawn Anastasio
Implement a basic exception handler that dumps the CPU state to the console, as well as the code required to set the correct exception vector table's base address in
setup.c.Signed-off-by Shawn Anastasio <[email protected]>Despite me being unhappy about the disconnect of the constants
Acked-by Jan Beulich <[email protected]>One further remark/suggestion though (happy to take care of while committing):
Quoted 7 lines
xen/arch/ppc/ppc64/exceptions-asm.S new file +4
-0@@ -0,0 +1,135 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <asm/asm-defns.h> +#include <asm/processor.h>xen/arch/ppc/ppc64/exceptions-asm.S line 14
Quoted 10 lines
xen/arch/ppc/ppc64/exceptions-asm.S new file +10
-0+ + .section .text.exceptions, "ax", %progbits + + /* Helper to dump CPU state to struct cpu_user_regs pointed to by r1. */ +ENTRY(exception_common) + /* + * Save GPRs 1-31. TODO: The value of %r1 has already been modified by the + * ISR, so the value we save isn't the exact value we had on entry. + */ + SAVE_GPRS(1, 31, %r1)Wouldn't this comment ...
Quoted 33 lines
xen/arch/ppc/ppc64/exceptions-asm.S new file +33
-0+ /* Save LR, CTR, CR */ + mflr %r0 + std %r0, UREGS_lr(%r1) + mfctr %r0 + std %r0, UREGS_ctr(%r1) + mfcr %r0 + stw %r0, UREGS_cr(%r1) /* 32-bit */ + + /* Save Exception Registers */ + mfsrr0 %r0 + std %r0, UREGS_pc(%r1) + mfsrr1 %r0 + std %r0, UREGS_msr(%r1) + mfdsisr %r0 + stw %r0, UREGS_dsisr(%r1) /* 32-bit */ + mfdar %r0 + std %r0, UREGS_dar(%r1) + li %r0, -1 /* OS's SRR0/SRR1 have been clobbered */ + std %r0, UREGS_srr0(%r1) + std %r0, UREGS_srr1(%r1) + + /* Setup TOC and a stack frame then call C exception handler */ + mr %r3, %r1 + bcl 20, 31, 1f +1: mflr %r12 + addis %r2, %r12, .TOC.-1b@ha + addi %r2, %r2, .TOC.-1b@l + + li %r0, 0 + stdu %r0, -STACK_FRAME_OVERHEAD(%r1) + bl exception_handler + + .size exception_common, . - exception_common
Quoted 9 lines
xen/arch/ppc/ppc64/exceptions-asm.S line 54
Quoted 6 lines
xen/arch/ppc/ppc64/exceptions-asm.S new file +6
-0+ .type exception_common, %function + + /* Same as exception_common, but for exceptions that set HSRR{0,1} */ +ENTRY(h_exception_common) + /* Save GPRs 1-31 */ + SAVE_GPRS(1, 31, %r1)... better be repeated here?
Sure, if you'd like to make that change during commit that'd be great.
Quoted 1 line
Jan
Thanks,
Shawn