Skip to contentSkip to conversation

MIPS: support return from exception; allow user to pass incorrect address to md command

PATCH Applied Antony Pavlov 2 participants 6 messages Nov 10, 2015 – Nov 11, 2015 MIPS

lore
Share & tools
lore
#0 lore raw

cover MIPS: support return from exception; allow user to pass incorrect address to md command

This patchseries adds return from exception for MIPS, so the 'md' command incorrect memory accesses can be handled correctly instead of crashing the system, e.g.

barebox:/ md -l 0xa0000003+4
a0000003: xxxxxxxx ....

Without this patchseries we will get this

    barebox:/ md -l 0xa0000003+4
    a0000003:
    Ooops, address error on load or ifetch!

    ...

    ### ERROR ### Please RESET the board ###

The patchseries is tested on QEMU Malta and Black Swift boards.

Antony Pavlov (4):
MIPS: traps.c: separate registers print stuff to show_regs()
MIPS: avoid excessive exception
MIPS: import exception registers restoring macros from linux kernel
MIPS: allow user to pass incorrect address to md command

 arch/mips/include/asm/barebox.h    |  2 +-
 arch/mips/include/asm/pbl_macros.h |  2 +-
 arch/mips/include/asm/stackframe.h | 87 ++++++++++++++++++++++++++++++++++++++
 arch/mips/lib/genex.S              |  6 +++
 arch/mips/lib/traps.c              | 65 +++++++++++++++++++++++-----
 5 files changed, 150 insertions(+), 12 deletions(-)
Signature · 7 lines
2.6.2


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

PATCH 1/4 MIPS: traps.c: separate registers print stuff to show_regs()

---
 arch/mips/lib/traps.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
arch/mips/lib/traps.c +12 -7
index 0a5914e..d69697d 100644
@@ -96,13 +96,10 @@ static char *get_exc_name(u32 cause)
 	return "unknown exception";
 }
 
-void barebox_exc_handler(const struct pt_regs *regs)
+static void show_regs(const struct pt_regs *regs)
 {
-	const int field = 2 * sizeof(unsigned long);
-	unsigned int cause = regs->cp0_cause;
 	int i;
-
-	printf("\nOoops, %s!\n\n", get_exc_name(cause));
+	const int field = 2 * sizeof(unsigned long);
 
 	/*
 	 * Saved main processor registers
@@ -131,9 +128,17 @@ void barebox_exc_handler(const struct pt_regs *regs)
 	printf("epc   : %0*lx\n", field, regs->cp0_epc);
 	printf("ra    : %0*lx\n", field, regs->regs[31]);
 
-	printf("Status: %08x\n", (uint32_t) regs->cp0_status);
-	printf("Cause : %08x\n", cause);
+	printf("Status: %08x\n", (uint32_t)regs->cp0_status);
+	printf("Cause : %08x\n", (uint32_t)regs->cp0_cause);
 	printf("Config: %08x\n\n", read_c0_config());
+}
+
+void barebox_exc_handler(const struct pt_regs *regs)
+{
+	unsigned int cause = regs->cp0_cause;
+
+	printf("\nOoops, %s!\n\n", get_exc_name(cause));
+	show_regs(regs);
 
 	hang();
 }
Signature · 7 lines
2.6.2


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

PATCH 2/4 MIPS: avoid excessive exception

In reply to Antony Pavlov

This commit clears ERL (ERror Level) flag on start. If this flag is set then we get 'TLB miss on load or ifetch' just after return from exception.

---
 arch/mips/include/asm/pbl_macros.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/pbl_macros.h +1 -1
index 681b40a..c4ae6a2 100644
@@ -145,7 +145,7 @@ copy_loop_exit:
 	.set	push
 	.set	noreorder
 	mfc0	k0, CP0_STATUS
-	li	k1, ~ST0_IE
+	li	k1, ~(ST0_ERL | ST0_IE)
 	and	k0, k1
 	mtc0	k0, CP0_STATUS
 	.set	pop
Signature · 7 lines
2.6.2


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

PATCH 3/4 MIPS: import exception registers restoring macros from linux kernel

In reply to Antony Pavlov
---
 arch/mips/include/asm/stackframe.h | 87 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
arch/mips/include/asm/stackframe.h +87 -0
index 0266ec6..abfa2d2 100644
@@ -15,6 +15,8 @@
 #include <asm/mipsregs.h>
 #include <asm/asm-offsets.h>
 
+#define STATMASK 0x1f
+
 		.macro	SAVE_AT
 		.set	push
 		.set	noat
@@ -102,4 +104,89 @@
 		SAVE_STATIC
 		.endm
 
+		.macro	RESTORE_AT
+		.set	push
+		.set	noat
+		LONG_L	$1,  PT_R1(sp)
+		.set	pop
+		.endm
+
+		.macro	RESTORE_TEMP
+		LONG_L	$24, PT_LO(sp)
+		mtlo	$24
+		LONG_L	$24, PT_HI(sp)
+		mthi	$24
+#ifdef CONFIG_32BIT
+		LONG_L	$8, PT_R8(sp)
+		LONG_L	$9, PT_R9(sp)
+#endif
+		LONG_L	$10, PT_R10(sp)
+		LONG_L	$11, PT_R11(sp)
+		LONG_L	$12, PT_R12(sp)
+		LONG_L	$13, PT_R13(sp)
+		LONG_L	$14, PT_R14(sp)
+		LONG_L	$15, PT_R15(sp)
+		LONG_L	$24, PT_R24(sp)
+		.endm
+
+		.macro	RESTORE_STATIC
+		LONG_L	$16, PT_R16(sp)
+		LONG_L	$17, PT_R17(sp)
+		LONG_L	$18, PT_R18(sp)
+		LONG_L	$19, PT_R19(sp)
+		LONG_L	$20, PT_R20(sp)
+		LONG_L	$21, PT_R21(sp)
+		LONG_L	$22, PT_R22(sp)
+		LONG_L	$23, PT_R23(sp)
+		LONG_L	$30, PT_R30(sp)
+		.endm
+
+		.macro	RESTORE_SOME
+		.set	push
+		.set	reorder
+		.set	noat
+		mfc0	a0, CP0_STATUS
+		ori	a0, STATMASK
+		xori	a0, STATMASK
+		mtc0	a0, CP0_STATUS
+		li	v1, 0xff00
+		and	a0, v1
+		LONG_L	v0, PT_STATUS(sp)
+		nor	v1, $0, v1
+		and	v0, v1
+		or	v0, a0
+		mtc0	v0, CP0_STATUS
+		LONG_L	v1, PT_EPC(sp)
+		MTC0	v1, CP0_EPC
+		LONG_L	$31, PT_R31(sp)
+		LONG_L	$28, PT_R28(sp)
+		LONG_L	$25, PT_R25(sp)
+#ifdef CONFIG_64BIT
+		LONG_L	$8, PT_R8(sp)
+		LONG_L	$9, PT_R9(sp)
+#endif
+		LONG_L	$7,  PT_R7(sp)
+		LONG_L	$6,  PT_R6(sp)
+		LONG_L	$5,  PT_R5(sp)
+		LONG_L	$4,  PT_R4(sp)
+		LONG_L	$3,  PT_R3(sp)
+		LONG_L	$2,  PT_R2(sp)
+		.set	pop
+		.endm
+
+		.macro	RESTORE_SP_AND_RET
+		LONG_L	sp, PT_R29(sp)
+		.set	arch=r4000
+		eret
+		.set	mips0
+		.endm
+
+		.macro	RESTORE_ALL_AND_RET
+		RESTORE_TEMP
+		RESTORE_STATIC
+		RESTORE_AT
+		RESTORE_SOME
+		RESTORE_SP_AND_RET
+		.endm
+
 #endif /* _ASM_STACKFRAME_H */
Signature · 7 lines
2.6.2


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

PATCH 4/4 MIPS: allow user to pass incorrect address to md command

In reply to Antony Pavlov

This commit makes it possible to handle exception on incorrect data access so 'md' command just show 'xxxxxxxx' instead of crashing the system.

barebox:/ md -l 0xa0000003+4
a0000003: xxxxxxxx ....

Without this commit we will get this

    barebox:/ md -l 0xa0000003+4
    a0000003:
    Ooops, address error on load or ifetch!

    ...

    ### ERROR ### Please RESET the board ###
---
 arch/mips/include/asm/barebox.h |  2 +-
 arch/mips/lib/genex.S           |  6 +++++
 arch/mips/lib/traps.c           | 52 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 53 insertions(+), 7 deletions(-)
arch/mips/include/asm/barebox.h +1 -1
index 499b731..e5b964c 100644
@@ -15,6 +15,6 @@
 #ifndef _ASM_MIPS_BAREBOX_H_
 #define _ASM_MIPS_BAREBOX_H_
 
-/* nothing special yet */
+#define ARCH_HAS_DATA_ABORT_MASK
 
 #endif /* _ASM_MIPS_BAREBOX_H_ */
arch/mips/lib/genex.S +6 -0
index 8941714..5fb2223 100644
@@ -31,3 +31,9 @@ NESTED(except_vec3_generic, 0, sp)
 	 nop
 	END(except_vec3_generic)
 	.set	at
+
+FEXPORT(ret_from_exception)
+	.set	noat
+	RESTORE_ALL_AND_RET
+	 nop
+	.set	at
arch/mips/lib/traps.c +46 -6

76 lines not on this page · raw message

Signature · 7 lines
2.6.2


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

This patchseries adds return from exception for MIPS, so the 'md' command incorrect memory accesses can be handled correctly instead of crashing the system, e.g.

barebox:/ md -l 0xa0000003+4
a0000003: xxxxxxxx ....

Without this patchseries we will get this

    barebox:/ md -l 0xa0000003+4
    a0000003:
    Ooops, address error on load or ifetch!

    ...

    ### ERROR ### Please RESET the board ###
Quoted 7 lines

The patchseries is tested on QEMU Malta and Black Swift boards.

Antony Pavlov (4):
MIPS: traps.c: separate registers print stuff to show_regs()
MIPS: avoid excessive exception
MIPS: import exception registers restoring macros from linux kernel
MIPS: allow user to pass incorrect address to md command

Applied, thanks

Sascha

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