Skip to contentSkip to conversation

MIPS: import exception stuff from linux kernel

PATCH Applied Antony Pavlov 2 participants 4 messages Dec 3, 2013 – Dec 4, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover MIPS: import exception stuff from linux kernel

This patch series imports registers saving code from linux kernel. Just now it makes possible to dump registers state on exception; this dump is very valuable for debugging purposes.

[PATCH 1/2] MIPS: add asm-offsets.h generation
[PATCH 2/2] MIPS: import exception registers saving from linux kernel

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/2 MIPS: add asm-offsets.h generation

---
 arch/mips/Makefile                  | 43 ++++++++++++++++++++++++++
 arch/mips/include/asm/asm-offsets.h |  1 +
 arch/mips/include/asm/ptrace.h      | 35 +++++++++++++++++++++
 arch/mips/lib/asm-offsets.c         | 61 +++++++++++++++++++++++++++++++++++++
 include/linux/kbuild.h              | 15 +++++++++
 5 files changed, 155 insertions(+)
 create mode 100644 arch/mips/include/asm/asm-offsets.h
 create mode 100644 arch/mips/include/asm/ptrace.h
 create mode 100644 arch/mips/lib/asm-offsets.c
 create mode 100644 include/linux/kbuild.h
arch/mips/Makefile +43 -0
index dc0fe56..62e1acf 100644
@@ -143,3 +143,46 @@ dtbs: scripts
 KBUILD_DTBS := dtbs
 
 KBUILD_IMAGE ?= $(KBUILD_BINARY)
+
+#####
+# Generate asm-offsets.h
+#
+
+offsets-file := include/generated/asm-offsets.h
+
+always  += $(offsets-file)
+targets += $(offsets-file)
+targets += arch/$(SRCARCH)/lib/asm-offsets.s
+
+# Default sed regexp - multiline due to syntax constraints
+define sed-y
+	"/^->/{s:->#\(.*\):/* \1 */:; \
+	s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
+	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
+	s:->::; p;}"
+endef
+
+quiet_cmd_offsets = GEN     $@
+define cmd_offsets
+	(set -e; \
+	 echo "#ifndef __ASM_OFFSETS_H__"; \
+	 echo "#define __ASM_OFFSETS_H__"; \
+	 echo "/*"; \
+	 echo " * DO NOT MODIFY."; \
+	 echo " *"; \
+	 echo " * This file was generated by Kbuild"; \
+	 echo " *"; \
+	 echo " */"; \
+	 echo ""; \
+	 sed -ne $(sed-y) $<; \
+	 echo ""; \
+	 echo "#endif" ) > $@
+endef
+
+# We use internal kbuild rules to avoid the "is up to date" message from make
+arch/$(SRCARCH)/lib/asm-offsets.s: arch/$(SRCARCH)/lib/asm-offsets.c FORCE
+	$(Q)mkdir -p $(dir $@)
+	$(call if_changed_dep,cc_s_c)
+
+$(obj)/$(offsets-file): arch/$(SRCARCH)/lib/asm-offsets.s Makefile
+	$(call cmd,offsets)
arch/mips/include/asm/asm-offsets.h new file +1 -0
new file mode 100644
index 0000000..d370ee3
@@ -0,0 +1 @@
+#include <generated/asm-offsets.h>
arch/mips/include/asm/ptrace.h new file +35 -0
new file mode 100644
index 0000000..211834d
@@ -0,0 +1,35 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle
+ * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
+ */
+
+#ifndef _ASM_PTRACE_H
+#define _ASM_PTRACE_H
+
+/*
+ * This struct defines the way the registers are stored on the stack during an
+ * exception. As usual the registers k0/k1 aren't being saved.
+ */
+struct pt_regs {
+#ifdef CONFIG_32BIT
+	/* Pad bytes for argument save space on the stack. */
+	unsigned long pad0[6];
+#endif
+
+	/* Saved main processor registers. */
+	unsigned long regs[32];
+
+	/* Saved special registers. */
+	unsigned long cp0_status;
+	unsigned long hi;
+	unsigned long lo;
+	unsigned long cp0_badvaddr;
+	unsigned long cp0_cause;
+	unsigned long cp0_epc;
+} __attribute__ ((aligned (8)));
+
+#endif /* _ASM_PTRACE_H */
arch/mips/lib/asm-offsets.c new file +61 -0

61 lines not on this page · raw message

include/linux/kbuild.h new file +15 -0
new file mode 100644
index 0000000..359d4a8
@@ -0,0 +1,15 @@
+#ifndef __LINUX_KBUILD_H
+#define __LINUX_KBUILD_H
+
+#define DEFINE(sym, val) \
+	asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+
+#define BLANK() asm volatile("\n->" : : )
+
+#define OFFSET(sym, str, mem) \
+	DEFINE(sym, offsetof(struct str, mem))
+
+#define COMMENT(x) \
+	asm volatile("\n->#" x)
+
+#endif
Signature · 7 lines
1.8.4.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/2 MIPS: import exception registers saving from linux kernel

In reply to Antony Pavlov

Checking registers saving:

    $ make qemu-malta_defconfig
    $ make
    ...

    $ qemu-system-mips -nodefaults -M malta -m 256 \
       -nographic -serial stdio -bios ./barebox-flash-image

    ...

    barebox:/ md -l 0x03

    Ooops, address error on load or ifetch!

    $ 0   : 00000000 00000000 ffffffff 0000003f
    $ 4   : 00000000 ffffffff 00000004 00000004
    $ 8   : 00000003 a0404d50 00000001 00000002
    $12   : a0404d50 0000000a a0840000 00000003
    $16   : 00000100 a0404d50 00000100 00000003
    $20   : 00000000 a0406cd8 00000000 00000000
    $24   : a083b4d8 a083058c
    $28   : 00000000 a03ffca8 a0406ab0 a0830604
    Hi    : 00000000
    Lo    : 00000040
    epc   : a083056c
    ra    : a0830604
    Status: 00000006
    Cause : 00000410
    Config: 80008482

    ### ERROR ### Please RESET the board ###
---
 arch/mips/include/asm/stackframe.h | 105 +++++++++++++++++++++++++++++++++++++
 arch/mips/lib/genex.S              |   2 +
 arch/mips/lib/traps.c              |  46 +++++++++++++---
 3 files changed, 146 insertions(+), 7 deletions(-)
 create mode 100644 arch/mips/include/asm/stackframe.h
arch/mips/include/asm/stackframe.h new file +105 -0
new file mode 100644
index 0000000..0266ec6
@@ -0,0 +1,105 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1994, 95, 96, 99, 2001 Ralf Baechle
+ * Copyright (C) 1994, 1995, 1996 Paul M. Antoine.
+ * Copyright (C) 1999 Silicon Graphics, Inc.
+ * Copyright (C) 2007  Maciej W. Rozycki
+ */
+#ifndef _ASM_STACKFRAME_H
+#define _ASM_STACKFRAME_H
+
+#include <asm/asm.h>
+#include <asm/mipsregs.h>
+#include <asm/asm-offsets.h>
+
+		.macro	SAVE_AT
+		.set	push
+		.set	noat
+		LONG_S	$1, PT_R1(sp)
+		.set	pop
+		.endm
+
+		.macro	SAVE_TEMP
+		mfhi	v1
+#ifdef CONFIG_32BIT
+		LONG_S	$8, PT_R8(sp)
+		LONG_S	$9, PT_R9(sp)
+#endif
+		LONG_S	$10, PT_R10(sp)
+		LONG_S	$11, PT_R11(sp)
+		LONG_S	$12, PT_R12(sp)
+
+		LONG_S	v1, PT_HI(sp)
+		mflo	v1
+
+		LONG_S	$13, PT_R13(sp)
+		LONG_S	$14, PT_R14(sp)
+		LONG_S	$15, PT_R15(sp)
+		LONG_S	$24, PT_R24(sp)
+
+		LONG_S	v1, PT_LO(sp)
+
+		.endm
+
+		.macro	SAVE_STATIC
+		LONG_S	$16, PT_R16(sp)
+		LONG_S	$17, PT_R17(sp)
+		LONG_S	$18, PT_R18(sp)
+		LONG_S	$19, PT_R19(sp)
+		LONG_S	$20, PT_R20(sp)
+		LONG_S	$21, PT_R21(sp)
+		LONG_S	$22, PT_R22(sp)
+		LONG_S	$23, PT_R23(sp)
+		LONG_S	$30, PT_R30(sp)
+		.endm
+
+		.macro	SAVE_SOME
+		.set	push
+		.set	noat
+		.set	reorder
+		.set	at=k0
+		move	k1, sp
+		PTR_SUBU k1, PT_SIZE
+		.set	noat
+		move	k0, sp
+		move	sp, k1
+		LONG_S	k0, PT_R29(sp)
+		LONG_S	$3, PT_R3(sp)
+		/*
+		 * You might think that you don't need to save $0,
+		 * but the FPU emulator and gdb remote debug stub
+		 * need it to operate correctly
+		 */
+		LONG_S	$0, PT_R0(sp)
+		mfc0	v1, CP0_STATUS
+		LONG_S	$2, PT_R2(sp)
+		LONG_S	v1, PT_STATUS(sp)
+		LONG_S	$4, PT_R4(sp)
+		mfc0	v1, CP0_CAUSE
+		LONG_S	$5, PT_R5(sp)
+		LONG_S	v1, PT_CAUSE(sp)
+		LONG_S	$6, PT_R6(sp)
+		MFC0	v1, CP0_EPC
+		LONG_S	$7, PT_R7(sp)
+#ifdef CONFIG_64BIT
+		LONG_S	$8, PT_R8(sp)
+		LONG_S	$9, PT_R9(sp)
+#endif
+		LONG_S	v1, PT_EPC(sp)
+		LONG_S	$25, PT_R25(sp)
+		LONG_S	$28, PT_R28(sp)
+		LONG_S	$31, PT_R31(sp)
+		.set	pop
+		.endm
+
+		.macro	SAVE_ALL
+		SAVE_SOME
+		SAVE_AT
+		SAVE_TEMP
+		SAVE_STATIC
+		.endm
+
+#endif /* _ASM_STACKFRAME_H */
arch/mips/lib/genex.S +2 -0
index d6f65a2..8941714 100644
@@ -1,6 +1,7 @@
 #include <asm/asm.h>
 #include <asm/regdef.h>
 #include <asm/mipsregs.h>
+#include <asm/stackframe.h>
 
 	.text
 	.set	macro
@@ -10,6 +11,7 @@
 
 /* Exception vector */
 NESTED(handle_reserved, 0, sp)
+	SAVE_ALL
 	la	k0, barebox_exc_handler
 	jal	k0
 	 move	a0, sp
arch/mips/lib/traps.c +39 -7

60 lines not on this page · raw message

Signature · 7 lines
1.8.4.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#3 lore raw
In reply to Antony Pavlov
Quoted 6 lines · Antony Pavlov

This patch series imports registers saving code from linux kernel. Just now it makes possible to dump registers state on exception; this dump is very valuable for debugging purposes.

[PATCH 1/2] MIPS: add asm-offsets.h generation
[PATCH 2/2] MIPS: import exception registers saving from linux kernel

Applied, thanks

Sascha

Quoted 6 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox