powerpc/xmon: Fix SPR read/write commands and add command to dump SPRs
PATCH 1/1 powerpc/xmon: Fix SPR read/write commands and add command to dump SPRs
Xmon has commands for reading and writing SPRs, but they don't work currently for several reasons. They attempt to synthesize a small function containing an mfspr or mtspr instruction and call it. However, the instructions are on the stack, which is usually not executable. Also, for 64-bit we set up a procedure descriptor, which is fine for the big-endian ABIv1, but not correct for ABIv2. Finally, the code uses the infrastructure for catching memory errors, but that only catches data storage interrupts and machine check interrupts, but a failed mfspr/mtspr can generate a program interrupt or a hypervisor emulation assist interrupt, or be a no-op.
Instead of trying to synthesize a function on the fly, this adds two new functions, do_mfspr and do_mtspr, which take an SPR number as an argument and read or write the SPR. Because there is no Power ISA instruction which takes an SPR number in a register, we have to generate one of each possible mfspr and mtspr instruction, for all 1024 possible SPRs. Thus we get just over 8k bytes of code for each of do_mfspr and do_mtspr. However, this 16kB of code pales in comparison to the > 130kB of PPC opcode tables used by the dissasembler.
To catch interrupts caused by the mfspr/mtspr instructions, we add a new 'doing_spr_access' flag. If an interrupt occurs while it is set, we come back into xmon() via program_check_interrupt(), _exception() and die(), see that doing_spr_access is set and do a longjmp to bus_error_jmp, back into read_spr or write_spr.
This adds a couple of other nice features: first, a "SA" command that attempts to read and print out the value of all 1024 SPRs, excluding SPRs 4, 5 and 6 (which never exist on any PPC processor later than the 601). If any mfspr instruction acts as a no-op, then the SPR is not implemented and not printed.
Secondly, the Sr and Sw commands detect when an SPR is not implemented (i.e. mfspr is a no-op) and print a message to that effect rather than printing a bogus value.
--- arch/powerpc/xmon/Makefile | 2 +- arch/powerpc/xmon/spraccess.S | 40 +++++++++++++++ arch/powerpc/xmon/xmon.c | 115 +++++++++++++++++++++++------------------- 3 files changed, 104 insertions(+), 53 deletions(-) create mode 100644 arch/powerpc/xmon/spraccess.S
arch/powerpc/xmon/Makefile +1 -1
@@ -7,7 +7,7 @@ UBSAN_SANITIZE := n ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) -obj-y += xmon.o nonstdio.o +obj-y += xmon.o nonstdio.o spraccess.o ifdef CONFIG_XMON_DISASSEMBLY obj-y += ppc-dis.o ppc-opc.o
arch/powerpc/xmon/spraccess.S new file +40 -0
@@ -0,0 +1,40 @@ +#include <asm/ppc_asm.h> + +/* do_mfspr(sprn, default_value) */ +_GLOBAL(do_mfspr) + mflr r0 + bcl 20, 31, 1f /* get address of next instr into LR */ +1: rlwinm r3, r3, 3, 0x3ff * 8 /* sprn = (sprn & 0x3ff) << 3 */ + mflr r5 + mtlr r0 + add r5, r5, r3 + addi r5, r5, 2f - 1b + mtctr r5 + mr r3, r4 + bctr +2: + spr = 0 + .rept 1024 + mfspr r3, spr + blr + spr = spr + 1 + .endr + +/* do_mtspr(sprn, new_value) */ +_GLOBAL(do_mtspr) + mflr r0 + bcl 20, 31, 1f /* get address of next instr into LR */ +1: rlwinm r3, r3, 3, 0x3ff * 8 /* sprn = (sprn & 0x3ff) << 3 */ + mflr r5 + mtlr r0 + add r5, r5, r3 + addi r5, r5, 2f - 1b + mtctr r5 + bctr +2: + spr = 0 + .rept 1024 + mtspr spr, r4 + blr + spr = spr + 1 + .endr
arch/powerpc/xmon/xmon.c +63 -52
179 lines not on this page · raw message
Signature · 1 line
2.6.4