mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/4] MIPS: support return from exception; allow user to pass incorrect address to md command
@ 2015-11-10  7:27 Antony Pavlov
  2015-11-10  7:27 ` [PATCH 1/4] MIPS: traps.c: separate registers print stuff to show_regs() Antony Pavlov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Antony Pavlov @ 2015-11-10  7:27 UTC (permalink / raw)
  To: barebox

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(-)

-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] MIPS: traps.c: separate registers print stuff to show_regs()
  2015-11-10  7:27 [PATCH 0/4] MIPS: support return from exception; allow user to pass incorrect address to md command Antony Pavlov
@ 2015-11-10  7:27 ` Antony Pavlov
  2015-11-10  7:27 ` [PATCH 2/4] MIPS: avoid excessive exception Antony Pavlov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Antony Pavlov @ 2015-11-10  7:27 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/lib/traps.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/arch/mips/lib/traps.c b/arch/mips/lib/traps.c
index 0a5914e..d69697d 100644
--- a/arch/mips/lib/traps.c
+++ b/arch/mips/lib/traps.c
@@ -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();
 }
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] MIPS: avoid excessive exception
  2015-11-10  7:27 [PATCH 0/4] MIPS: support return from exception; allow user to pass incorrect address to md command Antony Pavlov
  2015-11-10  7:27 ` [PATCH 1/4] MIPS: traps.c: separate registers print stuff to show_regs() Antony Pavlov
@ 2015-11-10  7:27 ` Antony Pavlov
  2015-11-10  7:27 ` [PATCH 3/4] MIPS: import exception registers restoring macros from linux kernel Antony Pavlov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Antony Pavlov @ 2015-11-10  7:27 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/include/asm/pbl_macros.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/pbl_macros.h b/arch/mips/include/asm/pbl_macros.h
index 681b40a..c4ae6a2 100644
--- a/arch/mips/include/asm/pbl_macros.h
+++ b/arch/mips/include/asm/pbl_macros.h
@@ -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
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] MIPS: import exception registers restoring macros from linux kernel
  2015-11-10  7:27 [PATCH 0/4] MIPS: support return from exception; allow user to pass incorrect address to md command Antony Pavlov
  2015-11-10  7:27 ` [PATCH 1/4] MIPS: traps.c: separate registers print stuff to show_regs() Antony Pavlov
  2015-11-10  7:27 ` [PATCH 2/4] MIPS: avoid excessive exception Antony Pavlov
@ 2015-11-10  7:27 ` Antony Pavlov
  2015-11-10  7:27 ` [PATCH 4/4] MIPS: allow user to pass incorrect address to md command Antony Pavlov
  2015-11-11  7:40 ` [PATCH 0/4] MIPS: support return from exception; " Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Antony Pavlov @ 2015-11-10  7:27 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/include/asm/stackframe.h | 87 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/arch/mips/include/asm/stackframe.h b/arch/mips/include/asm/stackframe.h
index 0266ec6..abfa2d2 100644
--- a/arch/mips/include/asm/stackframe.h
+++ b/arch/mips/include/asm/stackframe.h
@@ -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 */
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] MIPS: allow user to pass incorrect address to md command
  2015-11-10  7:27 [PATCH 0/4] MIPS: support return from exception; allow user to pass incorrect address to md command Antony Pavlov
                   ` (2 preceding siblings ...)
  2015-11-10  7:27 ` [PATCH 3/4] MIPS: import exception registers restoring macros from linux kernel Antony Pavlov
@ 2015-11-10  7:27 ` Antony Pavlov
  2015-11-11  7:40 ` [PATCH 0/4] MIPS: support return from exception; " Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Antony Pavlov @ 2015-11-10  7:27 UTC (permalink / raw)
  To: barebox

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 ###

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 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(-)

diff --git a/arch/mips/include/asm/barebox.h b/arch/mips/include/asm/barebox.h
index 499b731..e5b964c 100644
--- a/arch/mips/include/asm/barebox.h
+++ b/arch/mips/include/asm/barebox.h
@@ -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_ */
diff --git a/arch/mips/lib/genex.S b/arch/mips/lib/genex.S
index 8941714..5fb2223 100644
--- a/arch/mips/lib/genex.S
+++ b/arch/mips/lib/genex.S
@@ -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
diff --git a/arch/mips/lib/traps.c b/arch/mips/lib/traps.c
index d69697d..5fc32fe 100644
--- a/arch/mips/lib/traps.c
+++ b/arch/mips/lib/traps.c
@@ -1,9 +1,25 @@
 #include <common.h>
-
+#include <abort.h>
 #include <asm/mipsregs.h>
 #include <asm/ptrace.h>
 
-void barebox_exc_handler(const struct pt_regs *regs);
+static int mips_ignore_data_abort;
+static int mips_data_abort_occurred;
+
+void data_abort_mask(void)
+{
+	mips_data_abort_occurred = 0;
+	mips_ignore_data_abort = 1;
+}
+
+int data_abort_unmask(void)
+{
+	mips_ignore_data_abort = 0;
+
+	return mips_data_abort_occurred != 0;
+}
+
+void barebox_exc_handler(struct pt_regs *regs);
 
 /*
  * Trap codes from OpenBSD trap.h
@@ -31,9 +47,14 @@ void barebox_exc_handler(const struct pt_regs *regs);
 #define CR_EXC_CODE             0x0000007c
 #define CR_EXC_CODE_SHIFT       2
 
+static inline u32 get_exc_code(u32 cause)
+{
+	return (cause & CR_EXC_CODE) >> CR_EXC_CODE_SHIFT;
+}
+
 static char *get_exc_name(u32 cause)
 {
-	switch ((cause & CR_EXC_CODE) >> CR_EXC_CODE_SHIFT) {
+	switch (get_exc_code(cause)) {
 
 	case T_INT:
 		return "interrupt pending";
@@ -133,12 +154,31 @@ static void show_regs(const struct pt_regs *regs)
 	printf("Config: %08x\n\n", read_c0_config());
 }
 
-void barebox_exc_handler(const struct pt_regs *regs)
+void barebox_exc_handler(struct pt_regs *regs)
 {
 	unsigned int cause = regs->cp0_cause;
 
-	printf("\nOoops, %s!\n\n", get_exc_name(cause));
-	show_regs(regs);
+	if (get_exc_code(cause) == T_ADDR_ERR_LD && mips_ignore_data_abort) {
+
+		mips_data_abort_occurred = 1;
+
+		regs->cp0_epc += 4;
+
+		/*
+		 * Don't let your children do this ...
+		 */
+		__asm__ __volatile__(
+			"move\t$29, %0\n\t"
+			"j\tret_from_exception"
+			:/* no outputs */
+			:"r" (&regs));
+
+		/* Unreached */
+
+	} else {
+		printf("\nOoops, %s!\n\n", get_exc_name(cause));
+		show_regs(regs);
+	}
 
 	hang();
 }
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] MIPS: support return from exception; allow user to pass incorrect address to md command
  2015-11-10  7:27 [PATCH 0/4] MIPS: support return from exception; allow user to pass incorrect address to md command Antony Pavlov
                   ` (3 preceding siblings ...)
  2015-11-10  7:27 ` [PATCH 4/4] MIPS: allow user to pass incorrect address to md command Antony Pavlov
@ 2015-11-11  7:40 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-11-11  7:40 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Tue, Nov 10, 2015 at 10:27:12AM +0300, Antony Pavlov wrote:
> 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

Applied, thanks

Sascha


-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-11-11  7:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-10  7:27 [PATCH 0/4] MIPS: support return from exception; allow user to pass incorrect address to md command Antony Pavlov
2015-11-10  7:27 ` [PATCH 1/4] MIPS: traps.c: separate registers print stuff to show_regs() Antony Pavlov
2015-11-10  7:27 ` [PATCH 2/4] MIPS: avoid excessive exception Antony Pavlov
2015-11-10  7:27 ` [PATCH 3/4] MIPS: import exception registers restoring macros from linux kernel Antony Pavlov
2015-11-10  7:27 ` [PATCH 4/4] MIPS: allow user to pass incorrect address to md command Antony Pavlov
2015-11-11  7:40 ` [PATCH 0/4] MIPS: support return from exception; " Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox