Skip to contentSkip to conversation

MIPS: improve start.S and add exception support

PATCH Superseded Daniel Schwierzeck 1 participant 11 messages Oct 3, 2016 – Oct 30, 2016 MIPS

lore
Share & tools
lore
#0 lore raw

v2 cover MIPS: improve start.S and add exception support

Fix and optinmize initialization of cp0 registers. Also add the possibilty to setup the initial stack and global data in SRAM to provide a C environment for lowlevel_init(). This could be used on the QCA ath79 platform to rewrite and optimize the low-level init code.

Add support for a dynamic exception vectors in RAM and add initial exception handlers. The general exception handler prints an oops message similar to Linux kernel and then hangs. The EJTAG exception handler checks for SDBBP and delegates to the SDBBP handler if necessary. Otherwise the debug mode will be simply exited. The SDBBP handler currently only prints the content of registers c0_depc and c0_debug. This could be extended in the future to handle semi-hosting according to the MIPS UHI specification.

This patch series is also available at:
git://git.denx.de/u-boot-mips.git mips_rework_start_v2

Changes in v2:
- invoke UHI exception operation for all exception vectors but the EJTAG debug exception
- use EHB after setting cp0 status
- reordered macros in genex.S to allow side-by-side diff with Linux's arch/mips/include/asm/stackframe.h
- sync'ed genex.S with Linux v4.8-rc8 to incorporate changes for MIPS r6
- add execution_hazard_barrier() after clearing c0 status.BEV

Daniel Schwierzeck (9):
MIPS: make inclusion of ROM exception vectors configurable
MIPS: fix ROM exception vectors
MIPS: fix iand optimize setup of CP0 registers
MIPS: factor out code for initial stack and global data
MIPS: add possibility to setup initial stack and global data in SRAM
MIPS: add asm-offsets for struct pt_regs
MIPS: reserve space for exception vectors
MIPS: add handling for generic and EJTAG exceptions common/board_f: enable initr_trap for MIPS

 arch/mips/Kconfig                   |  32 ++++++
 arch/mips/cpu/start.S               | 174 ++++++++++++++++++----------
 arch/mips/include/asm/asm-offsets.h |   5 +
 arch/mips/include/asm/mipsregs.h    |   1 +
 arch/mips/include/asm/system.h      |   8 ++
 arch/mips/include/asm/u-boot-mips.h |   4 +
 arch/mips/lib/Makefile              |   3 +
 arch/mips/lib/asm-offsets.c         |  61 ++++++++++
 arch/mips/lib/genex.S               | 224 ++++++++++++++++++++++++++++++++++++
 arch/mips/lib/stack.c               |  19 +++
 arch/mips/lib/traps.c               | 106 +++++++++++++++++
 arch/mips/mach-ath79/Kconfig        |   2 +
 arch/mips/mach-pic32/Kconfig        |   1 +
 common/board_r.c                    |   4 +-
 14 files changed, 581 insertions(+), 63 deletions(-)
 create mode 100644 arch/mips/include/asm/asm-offsets.h
 create mode 100644 arch/mips/lib/asm-offsets.c
 create mode 100644 arch/mips/lib/genex.S
 create mode 100644 arch/mips/lib/stack.c
 create mode 100644 arch/mips/lib/traps.c
Signature · 1 line
2.10.0
#1 lore raw

PATCH v2 1/9 MIPS: make inclusion of ROM exception vectors configurable

This adds a compile time option to include code for static exception vectors. Static exception vectors are only needed, when the U-Boot entry point is equal to the CPU reset exception vector address. For instance this is the case when U-Boot is used as ROM in Qemu or booted from parallel NOR flash. When U-Boot is booted from RAM (e.g. loaded there by SPL), the exception vectors need to be setup dynamically, which is done in follow-up commits.

---

Changes in v2: None

 arch/mips/Kconfig            | 21 +++++++++++++++++++++
 arch/mips/cpu/start.S        | 11 ++++++++---
 arch/mips/mach-ath79/Kconfig |  2 ++
 arch/mips/mach-pic32/Kconfig |  1 +
 4 files changed, 32 insertions(+), 3 deletions(-)
arch/mips/Kconfig +21 -0
index 097ad58..709ac5c 100644
@@ -20,6 +20,7 @@ config TARGET_QEMU_MIPS
 	select SUPPORTS_CPU_MIPS32_R2
 	select SUPPORTS_CPU_MIPS64_R1
 	select SUPPORTS_CPU_MIPS64_R2
+	select ROM_EXCEPTION_VECTORS
 
 config TARGET_MALTA
 	bool "Support malta"
@@ -40,6 +41,7 @@ config TARGET_MALTA
 	select SUPPORTS_CPU_MIPS64_R6
 	select SWAP_IO_SPACE
 	select MIPS_L1_CACHE_SHIFT_6
+	select ROM_EXCEPTION_VECTORS
 
 config TARGET_VCT
 	bool "Support vct"
@@ -47,6 +49,7 @@ config TARGET_VCT
 	select SUPPORTS_CPU_MIPS32_R1
 	select SUPPORTS_CPU_MIPS32_R2
 	select SYS_MIPS_CACHE_INIT_RAM_LOAD
+	select ROM_EXCEPTION_VECTORS
 
 config TARGET_DBAU1X00
 	bool "Support dbau1x00"
@@ -55,6 +58,7 @@ config TARGET_DBAU1X00
 	select SUPPORTS_CPU_MIPS32_R1
 	select SUPPORTS_CPU_MIPS32_R2
 	select SYS_MIPS_CACHE_INIT_RAM_LOAD
+	select ROM_EXCEPTION_VECTORS
 	select MIPS_TUNE_4KC
 
 config TARGET_PB1X00
@@ -63,6 +67,7 @@ config TARGET_PB1X00
 	select SUPPORTS_CPU_MIPS32_R1
 	select SUPPORTS_CPU_MIPS32_R2
 	select SYS_MIPS_CACHE_INIT_RAM_LOAD
+	select ROM_EXCEPTION_VECTORS
 	select MIPS_TUNE_4KC
 
 config ARCH_ATH79
@@ -91,6 +96,7 @@ config TARGET_BOSTON
 	select SUPPORTS_CPU_MIPS64_R1
 	select SUPPORTS_CPU_MIPS64_R2
 	select SUPPORTS_CPU_MIPS64_R6
+	select ROM_EXCEPTION_VECTORS
 
 config TARGET_XILFPGA
 	bool "Support Imagination Xilfpga"
@@ -103,6 +109,7 @@ config TARGET_XILFPGA
 	select SUPPORTS_CPU_MIPS32_R1
 	select SUPPORTS_CPU_MIPS32_R2
 	select MIPS_L1_CACHE_SHIFT_4
+	select ROM_EXCEPTION_VECTORS
 	help
 	  This supports IMGTEC MIPSfpga platform
 
@@ -192,6 +199,20 @@ config CPU_MIPS64_R6
 
 endchoice
 
+menu "General setup"
+
+config ROM_EXCEPTION_VECTORS
+	bool "Build U-Boot image with exception vectors"
+	help
+	  Enable this to include exception vectors in the U-Boot image. This is
+	  required if the U-Boot entry point is equal to the address of the
+	  CPU reset exception vector (e.g. U-Boot as ROM loader in Qemu,
+	  U-Boot booted from parallel NOR flash).
+	  Disable this, if the U-Boot image is booted from DRAM (e.g. by SPL).
+	  In that case the image size will be reduced by 0x500 bytes.
+
+endmenu
+
 menu "OS boot interface"
 
 config MIPS_BOOT_CMDLINE_LEGACY
arch/mips/cpu/start.S +8 -3
index 3f0fc12..108d2df 100644
@@ -57,7 +57,6 @@ ENTRY(_start)
 	b	reset
 	 nop
 
-	.org 0x10
 #if defined(CONFIG_SYS_XWAY_EBU_BOOTCFG)
 	/*
 	 * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
@@ -66,16 +65,20 @@ ENTRY(_start)
 	 * initial configuration for that EBU in order to access the flash
 	 * device with correct parameters. This config option is board-specific.
 	 */
+	.org 0x10
 	.word CONFIG_SYS_XWAY_EBU_BOOTCFG
 	.word 0x0
-#elif defined(CONFIG_MALTA)
+#endif
+#if defined(CONFIG_MALTA)
 	/*
 	 * Linux expects the Board ID here.
 	 */
+	.org 0x10
 	.word 0x00000420	# 0x420 (Malta Board with CoreLV)
 	.word 0x00000000
 #endif
 
+#if defined(CONFIG_ROM_EXCEPTION_VECTORS)
 	.org 0x200
 	/* TLB refill, 32 bit task */
 1:	b	1b
@@ -106,7 +109,9 @@ ENTRY(_start)
 1:	b	1b
 	 nop
 
-	.align 4
+	.org 0x500
+#endif
+
 reset:
 #if __mips_isa_rev >= 6
 	mfc0	t0, CP0_CONFIG, 5
arch/mips/mach-ath79/Kconfig +2 -0
index 7d483aa..d982b0f 100644
@@ -9,6 +9,7 @@ config SOC_AR933X
 	select SUPPORTS_BIG_ENDIAN
 	select SUPPORTS_CPU_MIPS32_R1
 	select SUPPORTS_CPU_MIPS32_R2
+	select ROM_EXCEPTION_VECTORS
 	select MIPS_TUNE_24KC
 	help
 	  This supports QCA/Atheros ar933x family SOCs.
@@ -27,6 +28,7 @@ config SOC_QCA953X
 	select SUPPORTS_BIG_ENDIAN
 	select SUPPORTS_CPU_MIPS32_R1
 	select SUPPORTS_CPU_MIPS32_R2
+	select ROM_EXCEPTION_VECTORS
 	select MIPS_TUNE_24KC
 	help
 	  This supports QCA/Atheros qca953x family SOCs.
arch/mips/mach-pic32/Kconfig +1 -0
index 2e38bb7..8fad4cf 100644
@@ -14,6 +14,7 @@ config SOC_PIC32MZDA
 	select SUPPORTS_CPU_MIPS32_R2
 	select MIPS_L1_CACHE_SHIFT_4
 	select SYS_MIPS_CACHE_INIT_RAM_LOAD
+	select ROM_EXCEPTION_VECTORS
 	help
 	  This supports Microchip PIC32MZ[DA] family of microcontrollers.
 
Signature · 1 line
2.10.0
#2 lore raw

PATCH v2 2/9 MIPS: fix ROM exception vectors

In reply to Daniel Schwierzeck

When booting from ROM, early exceptions can't be handled properly. Instead of busy-looping give the developer the possibilty to examine the situation. Invoke an UHI exception operation which can be read as unhandled exception by a hardware debugger if one is attached. If the debugger doesn't support UHI, the exception is read as unexpected breakpoint.

---

Changes in v2:
- invoke UHI exception operation for all exception vectors but the EJTAG debug exception

 arch/mips/cpu/start.S | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)
arch/mips/cpu/start.S +19 -10
index 108d2df..2397b6c 100644
@@ -52,6 +52,14 @@
 
 	.set noreorder
 
+	.macro uhi_mips_exception
+	move	k0, t9		# preserve t9 in k0
+	move	k1, a0		# preserve a0 in k1
+	li	t9, 15		# UHI exception operation
+	li	a0, 0		# Use hard register context
+	sdbbp	1		# Invoke UHI operation
+	.endm
+
 ENTRY(_start)
 	/* U-Boot entry point */
 	b	reset
@@ -79,30 +87,30 @@ ENTRY(_start)
 #endif
 
 #if defined(CONFIG_ROM_EXCEPTION_VECTORS)
+	/*
+	 * Exception vector entry points. When running from ROM, an exception
+	 * cannot be handled. Halt execution and transfer control to debugger,
+	 * if one is attached.
+	 */
 	.org 0x200
 	/* TLB refill, 32 bit task */
-1:	b	1b
-	 nop
+	uhi_mips_exception
 
 	.org 0x280
 	/* XTLB refill, 64 bit task */
-1:	b	1b
-	 nop
+	uhi_mips_exception
 
 	.org 0x300
 	/* Cache error exception */
-1:	b	1b
-	 nop
+	uhi_mips_exception
 
 	.org 0x380
 	/* General exception */
-1:	b	1b
-	 nop
+	uhi_mips_exception
 
 	.org 0x400
 	/* Catch interrupt exceptions */
-1:	b	1b
-	 nop
+	uhi_mips_exception
 
 	.org 0x480
 	/* EJTAG debug exception */
@@ -222,6 +230,7 @@ reset:
 
 	move	a0, zero		# a0 <-- boot_flags = 0
 	PTR_LA	t9, board_init_f
+
 	jr	t9
 	 move	ra, zero
 
Signature · 1 line
2.10.0
#3 lore raw

PATCH v2 3/9 MIPS: fix iand optimize setup of CP0 registers

In reply to Daniel Schwierzeck

Clear cp0 status while preserving implementation specific bits. Set bits BEV and ERL as the arch specification requires after a reset or soft-reset exception.

Extend and fix initialization of watch registers. Check if additional watch register sets are implemented and initialize them too.

Initialize cp0 count as early as possible to get the most accurate boot timing.

---

Changes in v2:
- use EHB after setting cp0 status

 arch/mips/cpu/start.S            | 75 +++++++++++++++++++++++++++-------------
 arch/mips/include/asm/mipsregs.h |  1 +
 2 files changed, 52 insertions(+), 24 deletions(-)
arch/mips/cpu/start.S +51 -24
index 2397b6c..82d6e9f 100644
@@ -34,24 +34,16 @@
 # define STATUS_SET	ST0_KX
 #endif
 
-	/*
-	 * For the moment disable interrupts, mark the kernel mode and
-	 * set ST0_KX so that the CPU does not spit fire when using
-	 * 64-bit addresses.
-	 */
-	.macro	setup_c0_status set clr
-	.set	push
-	mfc0	t0, CP0_STATUS
-	or	t0, ST0_CU0 | \set | 0x1f | \clr
-	xor	t0, 0x1f | \clr
-	mtc0	t0, CP0_STATUS
-	.set	noreorder
-	sll	zero, 3				# ehb
-	.set	pop
-	.endm
-
 	.set noreorder
 
+	.macro init_wr sel
+	MTC0	zero, CP0_WATCHLO,\sel
+	mtc0	t1, CP0_WATCHHI,\sel
+	mfc0	t0, CP0_WATCHHI,\sel
+	bgez	t0, wr_done
+	 nop
+	.endm
+
 	.macro uhi_mips_exception
 	move	k0, t9		# preserve t9 in k0
 	move	k1, a0		# preserve a0 in k1
@@ -63,7 +55,7 @@
 ENTRY(_start)
 	/* U-Boot entry point */
 	b	reset
-	 nop
+	 mtc0	zero, CP0_COUNT	# clear cp0 count for most accurate boot timing
 
 #if defined(CONFIG_SYS_XWAY_EBU_BOOTCFG)
 	/*
@@ -141,17 +133,52 @@ reset:
 	b	3b
 	 nop
 
-	/* Clear watch registers */
-4:	MTC0	zero, CP0_WATCHLO
+	/* Init CP0 Status */
+4:	mfc0	t0, CP0_STATUS
+	and	t0, ST0_IMPL
+	or	t0, ST0_BEV | ST0_ERL | STATUS_SET
+	mtc0	t0, CP0_STATUS
+	ehb
+
+	/*
+	 * Check whether CP0 Config1 is implemented. If not continue
+	 * with legacy Watch register initialization.
+	 */
+	mfc0	t0, CP0_CONFIG
+	bgez	t0, wr_legacy
+	 nop
+
+	/*
+	 * Check WR bit in CP0 Config1 to determine if Watch registers
+	 * are implemented.
+	 */
+	mfc0	t0, CP0_CONFIG, 1
+	andi	t0, (1 << 3)
+	beqz	t0, wr_done
+	 nop
+
+	/* Clear Watch Status bits and disable watch exceptions */
+	li	t1, 0x7		# Clear I, R and W conditions
+	init_wr	0
+	init_wr	1
+	init_wr	2
+	init_wr	3
+	init_wr	4
+	init_wr	5
+	init_wr	6
+	init_wr	7
+	b	wr_done
+	 nop
+
+wr_legacy:
+	MTC0	zero, CP0_WATCHLO
 	mtc0	zero, CP0_WATCHHI
 
-	/* WP(Watch Pending), SW0/1 should be cleared */
+wr_done:
+	/* Clear WP, IV and SW interrupts */
 	mtc0	zero, CP0_CAUSE
 
-	setup_c0_status STATUS_SET 0
-
-	/* Init Timer */
-	mtc0	zero, CP0_COUNT
+	/* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
 	mtc0	zero, CP0_COMPARE
 
 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
arch/mips/include/asm/mipsregs.h +1 -0
index 9ab5063..7a9d222 100644
@@ -299,6 +299,7 @@
 #define	 STATUSF_IP14		(_ULCAST_(1) <<	 6)
 #define	 STATUSB_IP15		7
 #define	 STATUSF_IP15		(_ULCAST_(1) <<	 7)
+#define ST0_IMPL		(_ULCAST_(3) <<	 16)
 #define ST0_CH			0x00040000
 #define ST0_NMI			0x00080000
 #define ST0_SR			0x00100000
Signature · 1 line
2.10.0
#4 lore raw

PATCH v2 4/9 MIPS: factor out code for initial stack and global data

In reply to Daniel Schwierzeck

Move the code for setting up the initial stack and global data to a macro to be able to use it more than once.

---

Changes in v2: None

 arch/mips/cpu/start.S | 56 +++++++++++++++++++++++++++------------------------
 1 file changed, 30 insertions(+), 26 deletions(-)
arch/mips/cpu/start.S +30 -26
index 82d6e9f..d426b67 100644
@@ -52,6 +52,34 @@
 	sdbbp	1		# Invoke UHI operation
 	.endm
 
+	.macro setup_stack_gd
+	li	t0, -16
+	PTR_LI	t1, CONFIG_SYS_INIT_SP_ADDR
+	and	sp, t1, t0		# force 16 byte alignment
+	PTR_SUBU \
+		sp, sp, GD_SIZE		# reserve space for gd
+	and	sp, sp, t0		# force 16 byte alignment
+	move	k0, sp			# save gd pointer
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+	li	t2, CONFIG_SYS_MALLOC_F_LEN
+	PTR_SUBU \
+		sp, sp, t2		# reserve space for early malloc
+	and	sp, sp, t0		# force 16 byte alignment
+#endif
+	move	fp, sp
+
+	/* Clear gd */
+	move	t0, k0
+1:
+	PTR_S	zero, 0(t0)
+	blt	t0, t1, 1b
+	 PTR_ADDIU t0, PTRSIZE
+
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+	PTR_S	sp, GD_MALLOC_BASE(k0)	# gd->malloc_base offset
+#endif
+	.endm
+
 ENTRY(_start)
 	/* U-Boot entry point */
 	b	reset
@@ -228,32 +256,8 @@ wr_done:
 # endif
 #endif
 
-	/* Set up temporary stack */
-	li	t0, -16
-	PTR_LI	t1, CONFIG_SYS_INIT_SP_ADDR
-	and	sp, t1, t0		# force 16 byte alignment
-	PTR_SUBU \
-		sp, sp, GD_SIZE		# reserve space for gd
-	and	sp, sp, t0		# force 16 byte alignment
-	move	k0, sp			# save gd pointer
-#ifdef CONFIG_SYS_MALLOC_F_LEN
-	li	t2, CONFIG_SYS_MALLOC_F_LEN
-	PTR_SUBU \
-		sp, sp, t2		# reserve space for early malloc
-	and	sp, sp, t0		# force 16 byte alignment
-#endif
-	move	fp, sp
-
-	/* Clear gd */
-	move	t0, k0
-1:
-	PTR_S	zero, 0(t0)
-	blt	t0, t1, 1b
-	 PTR_ADDIU t0, PTRSIZE
-
-#ifdef CONFIG_SYS_MALLOC_F_LEN
-	PTR_S	sp, GD_MALLOC_BASE(k0)	# gd->malloc_base offset
-#endif
+	/* Set up initial stack and global data */
+	setup_stack_gd
 
 	move	a0, zero		# a0 <-- boot_flags = 0
 	PTR_LA	t9, board_init_f
Signature · 1 line
2.10.0
#5 lore raw

PATCH v2 5/9 MIPS: add possibility to setup initial stack and global data in SRAM

In reply to Daniel Schwierzeck

This adds a new Kconfig option CONFIG_MIPS_INIT_STACK_IN_SRAM which a SoC can select if it supports some kind of SRAM. Together with CONFIG_SYS_INIT_SP_ADDR the initial stack and global data can be set up in that SRAM. This can be used to provide a C environment also for lowlevel_init().

---

Changes in v2: None

 arch/mips/Kconfig     | 11 +++++++++++
 arch/mips/cpu/start.S |  7 +++++++
 2 files changed, 18 insertions(+)
arch/mips/Kconfig +11 -0
index 709ac5c..d97930e 100644
@@ -302,6 +302,17 @@ config SWAP_IO_SPACE
 config SYS_MIPS_CACHE_INIT_RAM_LOAD
 	bool
 
+config MIPS_INIT_STACK_IN_SRAM
+	bool
+	default n
+	help
+	  Select this if the initial stack frame could be setup in SRAM.
+	  Normally the initial stack frame is set up in DRAM which is often
+	  only available after lowlevel_init. With this option the initial
+	  stack frame and the early C environment is set up before
+	  lowlevel_init. Thus lowlevel_init does not need to be implemented
+	  in assembler.
+
 config SYS_DCACHE_SIZE
 	int
 	default 0
arch/mips/cpu/start.S +7 -0
index d426b67..22df223 100644
@@ -235,6 +235,11 @@ wr_done:
 	 nop
 #endif
 
+#ifdef CONFIG_MIPS_INIT_STACK_IN_SRAM
+	/* Set up initial stack and global data */
+	setup_stack_gd
+#endif
+
 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
 # ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
 	/* Initialize any external memory */
@@ -256,8 +261,10 @@ wr_done:
 # endif
 #endif
 
+#ifndef CONFIG_MIPS_INIT_STACK_IN_SRAM
 	/* Set up initial stack and global data */
 	setup_stack_gd
+#endif
 
 	move	a0, zero		# a0 <-- boot_flags = 0
 	PTR_LA	t9, board_init_f
Signature · 1 line
2.10.0
#6 lore raw

PATCH v2 6/9 MIPS: add asm-offsets for struct pt_regs

In reply to Daniel Schwierzeck

Import asm-offsets.c from kernel to generate offset for struct pt_regs needed by exception handlers.

---

Changes in v2: None

 arch/mips/include/asm/asm-offsets.h |  5 +++
 arch/mips/lib/asm-offsets.c         | 61 +++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
 create mode 100644 arch/mips/include/asm/asm-offsets.h
 create mode 100644 arch/mips/lib/asm-offsets.c
arch/mips/include/asm/asm-offsets.h new file +5 -0
new file mode 100644
index 0000000..5352b1c
@@ -0,0 +1,5 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <generated/asm-offsets.h>
arch/mips/lib/asm-offsets.c new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.10.0
#7 lore raw

PATCH v2 7/9 MIPS: reserve space for exception vectors

In reply to Daniel Schwierzeck

In order to set own exception handlers, a table with the exception vectors must be built in DRAM and the CPU EBase register must be set to the base address of this table.

Reserve the space above the stack and use gd->irq_sp as storage for the exception base address.

---

Changes in v2: None

 arch/mips/lib/Makefile |  1 +
 arch/mips/lib/stack.c  | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 arch/mips/lib/stack.c
arch/mips/lib/Makefile +1 -0
index b7ce5df..02607f7 100644
@@ -7,6 +7,7 @@
 
 obj-y	+= cache.o
 obj-y	+= cache_init.o
+obj-y	+= stack.o
 
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
 
arch/mips/lib/stack.c new file +19 -0
new file mode 100644
index 0000000..c80f5fe
@@ -0,0 +1,19 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int arch_reserve_stacks(void)
+{
+	/* reserve space for exception vector table */
+	gd->start_addr_sp -= 0x500;
+	gd->start_addr_sp &= ~0xFFF;
+	gd->irq_sp = gd->start_addr_sp;
+	debug("Reserving %d Bytes for exception vector at: %08lx\n",
+	      0x500, gd->start_addr_sp);
+
+	return 0;
+}
Signature · 1 line
2.10.0
#8 lore raw

PATCH v2 8/9 MIPS: add handling for generic and EJTAG exceptions

In reply to Daniel Schwierzeck

Add exception handlers for generic and EJTAG exceptions. Most of the assembly code is imported from Linux kernel and adapted to U-Boot. The exception vector table will be reserved above the stack before U-Boot is relocated. The exception handlers will be installed and activated after relocation in the initr_traps hook function.

Generic exceptions are handled by showing a CPU register dump similar to Linux kernel. For example:

malta # md 1
00000001:
Ooops:

$ 0   : 00000000 00000000 00000009 00000004
$ 4   : 8ff7e108 00000000 0000003a 00000000
$ 8   : 00000008 00000001 8ff7cd18 00000004
$12   : 00000002 00000000 00000005 0000003a
$16   : 00000004 00000040 00000001 00000001
$20   : 00000000 8fff53c0 00000008 00000004
$24   : ffffffff 8ffdea44
$28   : 90001650 8ff7cd00 00000004 8ffe6818
Hi    : 00000000
Lo    : 00000004
epc   : 8ffe6848 (text bfc28848)
ra    : 8ffe6818 (text bfc28818)
Status: 00000006
Cause : 00000410 (ExcCode 04)
BadVA : 8ff9e928
PrId  : 00019300
 ### ERROR ### Please RESET the board ###

EJTAG exceptions are checked for SDBBP and delegated to the SDBBP handler if necessary. Otherwise the debug mode will simply be exited. The SDBBP handler currently prints the contents of registers c0_depc and c0_debug. This could be extended in the future to handle semi-hosting according to the MIPS UHI specification.

---

Changes in v2:
- reordered macros in genex.S to allow side-by-side diff with Linux's arch/mips/include/asm/stackframe.h
- sync'ed genex.S with Linux v4.8-rc8 to incorporate changes for MIPS r6
- add execution_hazard_barrier() after clearing c0 status.BEV

 arch/mips/include/asm/system.h      |   8 ++
 arch/mips/include/asm/u-boot-mips.h |   4 +
 arch/mips/lib/Makefile              |   2 +
 arch/mips/lib/genex.S               | 224 ++++++++++++++++++++++++++++++++++++
 arch/mips/lib/traps.c               | 106 +++++++++++++++++
 5 files changed, 344 insertions(+)
 create mode 100644 arch/mips/lib/genex.S
 create mode 100644 arch/mips/lib/traps.c
arch/mips/include/asm/system.h +8 -0
index e6435cc..c9c5961 100644
@@ -262,4 +262,12 @@ extern void __die_if_kernel(const char *, struct pt_regs *, const char *where,
 #define die_if_kernel(msg, regs)					\
 	__die_if_kernel(msg, regs, __FILE__ ":"__FUNCTION__, __LINE__)
 
+static inline void execution_hazard_barrier(void)
+{
+	__asm__ __volatile__(
+		".set noreorder\n"
+		"ehb\n"
+		".set reorder");
+}
+
 #endif /* _ASM_SYSTEM_H */
arch/mips/include/asm/u-boot-mips.h +4 -0
index 1f527bb..71ff41d 100644
@@ -5,4 +5,8 @@
 #ifndef _U_BOOT_MIPS_H_
 #define _U_BOOT_MIPS_H_
 
+void exc_handler(void);
+void except_vec3_generic(void);
+void except_vec_ejtag_debug(void);
+
 #endif /* _U_BOOT_MIPS_H_ */
arch/mips/lib/Makefile +2 -0
index 02607f7..659c6ad 100644
@@ -7,7 +7,9 @@
 
 obj-y	+= cache.o
 obj-y	+= cache_init.o
+obj-y	+= genex.o
 obj-y	+= stack.o
+obj-y	+= traps.o
 
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
 
arch/mips/lib/genex.S new file +224 -0

224 lines not on this page · raw message

arch/mips/lib/traps.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.10.0
#9 lore raw

PATCH v2 9/9 common/board_f: enable initr_trap for MIPS

In reply to Daniel Schwierzeck

Enable initr_trap hook also for MIPS to install and enable U-Boot's specific MIPS exception handlers.

---

Changes in v2: None

 common/board_r.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/board_r.c +2 -2
index d959ad3..5496f45 100644
@@ -191,7 +191,7 @@ static int initr_serial(void)
 	return 0;
 }
 
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
 static int initr_trap(void)
 {
 	/*
@@ -807,7 +807,7 @@ init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
 	initr_manual_reloc_cmdtable,
 #endif
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
 	initr_trap,
 #endif
 #ifdef CONFIG_ADDR_MAP
Signature · 1 line
2.10.0
#10 lore raw

v2 cover MIPS: improve start.S and add exception support

In reply to Daniel Schwierzeck

Am 03.10.2016 um 19:51 schrieb Daniel Schwierzeck:

Quoted 52 lines

Fix and optinmize initialization of cp0 registers. Also add the possibilty to setup the initial stack and global data in SRAM to provide a C environment for lowlevel_init(). This could be used on the QCA ath79 platform to rewrite and optimize the low-level init code.

Add support for a dynamic exception vectors in RAM and add initial exception handlers. The general exception handler prints an oops message similar to Linux kernel and then hangs. The EJTAG exception handler checks for SDBBP and delegates to the SDBBP handler if necessary. Otherwise the debug mode will be simply exited. The SDBBP handler currently only prints the content of registers c0_depc and c0_debug. This could be extended in the future to handle semi-hosting according to the MIPS UHI specification.

This patch series is also available at:
git://git.denx.de/u-boot-mips.git mips_rework_start_v2

Changes in v2:
- invoke UHI exception operation for all exception vectors but the EJTAG debug exception
- use EHB after setting cp0 status
- reordered macros in genex.S to allow side-by-side diff with Linux's arch/mips/include/asm/stackframe.h
- sync'ed genex.S with Linux v4.8-rc8 to incorporate changes for MIPS r6
- add execution_hazard_barrier() after clearing c0 status.BEV

Daniel Schwierzeck (9):
MIPS: make inclusion of ROM exception vectors configurable
MIPS: fix ROM exception vectors
MIPS: fix iand optimize setup of CP0 registers
MIPS: factor out code for initial stack and global data
MIPS: add possibility to setup initial stack and global data in SRAM
MIPS: add asm-offsets for struct pt_regs
MIPS: reserve space for exception vectors
MIPS: add handling for generic and EJTAG exceptions common/board_f: enable initr_trap for MIPS

 arch/mips/Kconfig                   |  32 ++++++
 arch/mips/cpu/start.S               | 174 ++++++++++++++++++----------
 arch/mips/include/asm/asm-offsets.h |   5 +
 arch/mips/include/asm/mipsregs.h    |   1 +
 arch/mips/include/asm/system.h      |   8 ++
 arch/mips/include/asm/u-boot-mips.h |   4 +
 arch/mips/lib/Makefile              |   3 +
 arch/mips/lib/asm-offsets.c         |  61 ++++++++++
 arch/mips/lib/genex.S               | 224 ++++++++++++++++++++++++++++++++++++
 arch/mips/lib/stack.c               |  19 +++
 arch/mips/lib/traps.c               | 106 +++++++++++++++++
 arch/mips/mach-ath79/Kconfig        |   2 +
Quoted 9 lines
 arch/mips/mach-pic32/Kconfig        |   1 +
 common/board_r.c                    |   4 +-
 14 files changed, 581 insertions(+), 63 deletions(-)
 create mode 100644 arch/mips/include/asm/asm-offsets.h
 create mode 100644 arch/mips/lib/asm-offsets.c
 create mode 100644 arch/mips/lib/genex.S
 create mode 100644 arch/mips/lib/stack.c
 create mode 100644 arch/mips/lib/traps.c

applied to u-boot-mips/next

Signature · 9 lines
- Daniel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161030/e3687212/attachment.sig>