MIPS: improve start.S and add exception support
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_v1
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 | 165 +++++++++++++++++---------- arch/mips/include/asm/asm-offsets.h | 5 + arch/mips/include/asm/mipsregs.h | 1 + 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 | 214 ++++++++++++++++++++++++++++++++++++ arch/mips/lib/stack.c | 19 ++++ arch/mips/lib/traps.c | 104 ++++++++++++++++++ arch/mips/mach-ath79/Kconfig | 2 + arch/mips/mach-pic32/Kconfig | 1 + common/board_r.c | 4 +- 13 files changed, 552 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.9.3
PATCH 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.
---
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
@@ -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
@@ -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
@@ -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
@@ -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.9.3
PATCH 2/9 MIPS: fix ROM exception vectors
In reply to Daniel SchwierzeckWhen booting from ROM, early exceptions can't be handled properly. Instead of busy-looping give the developer the possibilty to examine the situation. Thus issue a SDBBP instruction to transfer control to hardware debugger if one is attached.
---
arch/mips/cpu/start.S | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
arch/mips/cpu/start.S +11 -10
@@ -79,30 +79,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 + sdbbp .org 0x280 /* XTLB refill, 64 bit task */ -1: b 1b - nop + sdbbp .org 0x300 /* Cache error exception */ -1: b 1b - nop + sdbbp .org 0x380 /* General exception */ -1: b 1b - nop + sdbbp .org 0x400 /* Catch interrupt exceptions */ -1: b 1b - nop + sdbbp .org 0x480 /* EJTAG debug exception */
@@ -222,6 +222,7 @@ reset: move a0, zero # a0 <-- boot_flags = 0 PTR_LA t9, board_init_f + jr t9 move ra, zero
Signature · 1 line
2.9.3
PATCH 2/9 MIPS: fix ROM exception vectors
Quoted 5 lines · 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. Thus issue a SDBBP instruction to transfer control to hardware debugger if one is attached.
You could make the SDBBP into a UHI operation that can be read by a debugger as an unhandled exception rather than an unexpected breakpoint (assuming said debugger knows about UHI). The fragment I use in lightweight boot code is:
move k0, t9 # Preserve t9
move k1, a0 # Preserve a0
li $25, 15 # UHI exception operation
li $4, 0 # Use hard register context
sdbbp 1 # Invoke UHI operationYou lose k0/k1 in this which may be undesirable but it might be a reasonable trade off. This shouldn't go in the debug vector of course!
Matthew
PATCH 2/9 MIPS: fix ROM exception vectors
2016-09-26 9:58 GMT+02:00 Matthew Fortune <[email protected]>:
Quoted 18 lines
Quoted 5 lines · 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. Thus issue a SDBBP instruction to transfer control to hardware debugger if one is attached.
You could make the SDBBP into a UHI operation that can be read by a debugger as an unhandled exception rather than an unexpected breakpoint (assuming said debugger knows about UHI). The fragment I use in lightweight boot code is:
move k0, t9 # Preserve t9 move k1, a0 # Preserve a0 li $25, 15 # UHI exception operation li $4, 0 # Use hard register context sdbbp 1 # Invoke UHI operation
Quoted 4 lines
You lose k0/k1 in this which may be undesirable but it might be a reasonable trade off. This shouldn't go in the debug vector of course!
sounds interesting. I'll have a look into that. Can I test this with OpenOCD and GDB?
Signature · 1 line
- Daniel
PATCH 2/9 MIPS: fix ROM exception vectors
Quoted 19 lines · Daniel Schwierzeck
2016-09-26 9:58 GMT+02:00 Matthew Fortune <[email protected]>:
Quoted 18 lines
Quoted 5 lines · 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. Thus issue a SDBBP instruction to transfer control to hardware debugger if one is attached.
You could make the SDBBP into a UHI operation that can be read by a debugger as an unhandled exception rather than an unexpected breakpoint (assuming said debugger knows about UHI). The fragment I use in lightweight boot code is:
move k0, t9 # Preserve t9 move k1, a0 # Preserve a0 li $25, 15 # UHI exception operation li $4, 0 # Use hard register context sdbbp 1 # Invoke UHI operation
Quoted 7 lines
Quoted 4 lines
You lose k0/k1 in this which may be undesirable but it might be a reasonable trade off. This shouldn't go in the debug vector of course!
sounds interesting. I'll have a look into that. Can I test this with OpenOCD and GDB?
I'm sorry to say progress with getting UHI into OpenOCD is rather slow. The main effort for OpenOCD has been part of the MIPSfpga project which I am not directly involved with. To my knowledge they have the basic 'write' call implemented but are not handling all the operations and the implementation is out of tree. I'll try and check on this and let you know.
I had an idea of using a special UHI operation to indicate a boot failure with a simple enumerated 'reason' code so you could get a quick hint at what blew up in low level boot code without the source. I.e. any errors that can be detected without ending up raising an exception. I put two quickly thought up errors into the UHI spec as an example but I only have some simplistic boot code to play with. If you think U-boot could have a range of errors to report like this (and want to use it) then we can add to the list.
Matthew
PATCH 3/9 MIPS: fix iand optimize setup of CP0 registers
In reply to Daniel SchwierzeckClear 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.
---
arch/mips/cpu/start.S | 74 +++++++++++++++++++++++++++------------- arch/mips/include/asm/mipsregs.h | 1 + 2 files changed, 51 insertions(+), 24 deletions(-)
arch/mips/cpu/start.S +50 -24
@@ -34,28 +34,20 @@ # 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 + 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) /*
@@ -133,17 +125,51 @@ 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 + + /* + * 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
@@ -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.9.3
PATCH 4/9 MIPS: factor out code for initial stack and global data
In reply to Daniel SchwierzeckMove the code for setting up the initial stack and global data to a macro to be able to use it more than once.
---
arch/mips/cpu/start.S | 56 +++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 26 deletions(-)
arch/mips/cpu/start.S +30 -26
@@ -44,6 +44,34 @@ nop .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
@@ -219,32 +247,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.9.3
PATCH 5/9 MIPS: add possibility to setup initial stack and global data in SRAM
In reply to Daniel SchwierzeckThis 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().
---
arch/mips/Kconfig | 11 +++++++++++ arch/mips/cpu/start.S | 7 +++++++ 2 files changed, 18 insertions(+)
arch/mips/Kconfig +11 -0
@@ -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
@@ -226,6 +226,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 */
@@ -247,8 +252,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.9.3
PATCH 6/9 MIPS: add asm-offsets for struct pt_regs
In reply to Daniel SchwierzeckImport asm-offsets.c from kernel to generate offset for struct pt_regs needed by exception handlers.
---
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
@@ -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.9.3
PATCH 7/9 MIPS: reserve space for exception vectors
In reply to Daniel SchwierzeckIn 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.
---
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
@@ -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
@@ -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.9.3
PATCH 8/9 MIPS: add handling for generic and EJTAG exceptions
In reply to Daniel SchwierzeckAdd 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.
---
arch/mips/include/asm/u-boot-mips.h | 4 + arch/mips/lib/Makefile | 2 + arch/mips/lib/genex.S | 214 ++++++++++++++++++++++++++++++++++++ arch/mips/lib/traps.c | 104 ++++++++++++++++++ 4 files changed, 324 insertions(+) create mode 100644 arch/mips/lib/genex.S create mode 100644 arch/mips/lib/traps.c
arch/mips/include/asm/u-boot-mips.h +4 -0
@@ -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
@@ -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 +214 -0
214 lines not on this page · raw message
arch/mips/lib/traps.c new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH 8/9 MIPS: add handling for generic and EJTAG exceptions
Quoted 5 lines · On Sunday, 25 September 2016 20:05:31 BST Daniel Schwierzeck wrote:
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_trapshook function.
Hi Daniel,
This series looks good :) Just a couple of comments below.
Quoted 16 lines
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
Quoted 8 lines
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 ###
Something I've had in the U-Boot source we use on Boston, Malta & SEAD-3 boards internally for a while is the ability to longjmp back to the shell after an exception. It seems to work pretty well & generally means exceptions are non-fatal. I'll submit that once this goes in.
Quoted 83 lines
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_depcandc0_debug. This could be extended in the future to handle semi-hosting according to the MIPS UHI specification.Signed-off-by Daniel Schwierzeck <[email protected]>---
arch/mips/include/asm/u-boot-mips.h | 4 + arch/mips/lib/Makefile | 2 + arch/mips/lib/genex.S | 214 ++++++++++++++++++++++++++++++++++++ arch/mips/lib/traps.c | 104 ++++++++++++++++++ 4 files changed, 324 insertions(+) create mode 100644 arch/mips/lib/genex.S create mode 100644 arch/mips/lib/traps.c(quoted diff) +0
-0
b/arch/mips/include/asm/u-boot-mips.hindex 1f527bb..71ff41d 100644arch/mips/include/asm/u-boot-mips.h +4
-0@@ -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@@ -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.oarch/mips/lib/genex.S new file +31
-0@@ -0,0 +1,214 @@ +/* + * Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle + * Copyright (C) 1999, 2000 Silicon Graphics, Inc. + * Copyright (C) 2002, 2007 Maciej W. Rozycki + * Copyright (C) 2001, 2012 MIPS Technologies, Inc. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <asm/asm.h> +#include <asm/regdef.h> +#include <asm/mipsregs.h> +#include <asm/asm-offsets.h> + + .set noreorder + + /* + * Macros copied and adapted from Linux MIPS + */ + .macro SAVE_AT + .set push + .set noat + LONG_S $1, PT_R1(sp) + .set pop + .endm + + .macro RESTORE_AT + .set push + .set noat + LONG_L $1, PT_R1(sp) + .set pop
arch/mips/lib/genex.S line 41
Quoted 10 lines
arch/mips/lib/genex.S new file +10
-0+ .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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160926/1ab44545/attachment.sig>
PATCH 8/9 MIPS: add handling for generic and EJTAG exceptions
2016-09-26 12:29 GMT+02:00 Paul Burton <[email protected]>:
Quoted 6 lines
Something I've had in the U-Boot source we use on Boston, Malta & SEAD-3 boards internally for a while is the ability to longjmp back to the shell after an exception. It seems to work pretty well & generally means exceptions are non-fatal. I'll submit that once this goes in.
But this only works for commands issues at the U-Boot prompt? If the init code crashes,
then you have no valid code to jump to.
Quoted 9 lines
Quoted 8 lines
+
+ .macro
RESTORE_TEMP+
LONG_L$24,PT_LO(sp)+ mtlo $24
Quoted 9 lines
Quoted 3 lines
+
LONG_L$24,PT_HI(sp)+ mthi $24
The hi & lo bits here & in the save code above need to be wrapped in "#if
__mips_isa_rev< 6", since the hi & lo registers were removed in MIPSr6.
ok, I'll do a resync with Linux's arch/mips/include/asm/stackframe.h.
Quoted 15 lines
Quoted 14 lines
arch/mips/lib/traps.c new file +7
-0+void trap_init (ulong reloc_addr) +{ +unsigned long ebase = gd->irq_sp; + +set_handler (0x180 , &except_vec3_generic,0x80 ); +set_handler (0x280 , &except_vec_ejtag_debug,0x80 ); +
Quoted 8 lines
Quoted 3 lines
+
write_c0_ebase(ebase);+
clear_c0_status(ST0_BEV);I think strictly speaking we should probably have an ehb instruction at the end of
trap_initso that we know the new ebase takes effect straight away.
Sounds plausible. Shall I import arch/mips/include/asm/hazards.h from Linux?
Quoted 12 lines
With the R6 change mentioned above this works fine on a 64r6el (I6400) Boston board, so feel free to add:
Reviewed-by Paul Burton <[email protected]>Tested-by Paul Burton <[email protected]>
thanks for testing and reviewing
Signature · 1 line
- Daniel
PATCH 8/9 MIPS: add handling for generic and EJTAG exceptions
Quoted 9 lines · On Monday, 26 September 2016 19:41:22 BST Daniel Schwierzeck wrote:
2016-09-26 12:29 GMT+02:00 Paul Burton <[email protected]>:
Quoted 4 lines
Something I've had in the U-Boot source we use on Boston, Malta & SEAD-3 boards internally for a while is the ability to longjmp back to the shell after an exception. It seems to work pretty well & generally means exceptions are non-fatal. I'll submit that once this goes in.
But this only works for commands issues at the U-Boot prompt? If the init code crashes,
then you have no valid code to jump to.
Hi Daniel,
Yes, that's true. To end users though that's the typical case - when an exception occurs it's generally because an address was typed incorrectly or because the wrong size of access was used. Allowing the user to recover from that by returning them to the prompt where they can simply push the up key & modify the command they typed makes use much nicer.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
+
+ .macro
RESTORE_TEMP+
LONG_L$24,PT_LO(sp)+ mtlo $24
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
+
LONG_L$24,PT_HI(sp)+ mthi $24
The hi & lo bits here & in the save code above need to be wrapped in "#if
__mips_isa_rev< 6", since the hi & lo registers were removed in MIPSr6.ok, I'll do a resync with Linux's
arch/mips/include/asm/stackframe.h.
Sounds good :)
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
arch/mips/lib/traps.c new file +8
-0+void trap_init (ulong reloc_addr) +{ +unsigned long ebase = gd->irq_sp; + +set_handler (0x180 , &except_vec3_generic,0x80 ); +set_handler (0x280 , &except_vec_ejtag_debug,0x80 ); + +write_c0_ebase (ebase);
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
+
clear_c0_status(ST0_BEV);I think strictly speaking we should probably have an ehb instruction at the
end oftrap_initso that we know the new ebase takes effect straight away.Sounds plausible. Shall I import
arch/mips/include/asm/hazards.hfrom Linux?
Could be good. I have a patch lying around which adds hazards.h to clear the instruction hazard at the end of flush_cache, but it doesn't reuse the instruction_hazard function from Linux because that caused problems when run during relocation. I expect since my change to relocate_code that ought not to be a problem anymore though & the Linux version will probably work fine, but I haven't yet tested it.
Quoted 10 lines
Quoted 8 lines
With the R6 change mentioned above this works fine on a 64r6el (I6400) Boston board, so feel free to add:
Reviewed-by Paul Burton <[email protected]>Tested-by Paul Burton <[email protected]>thanks for testing and reviewing
No problem.
Thanks,
Paul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160926/cfd6e5b5/attachment.sig>
PATCH 9/9 common/board_f: enable initr_trap for MIPS
In reply to Daniel SchwierzeckEnable initr_trap hook also for MIPS to install and enable U-Boot's specific MIPS exception handlers.
---
common/board_r.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common/board_r.c +2 -2
@@ -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.9.3
PATCH 9/9 common/board_f: enable initr_trap for MIPS
Quoted 9 lines · Daniel Schwierzeck
Enable
initr_traphook also for MIPS to install and enable U-Boot's specific MIPS exception handlers.Signed-off-by Daniel Schwierzeck <[email protected]>---
common/board_r.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
cover MIPS: improve start.S and add exception support
In reply to Daniel SchwierzeckQuoted 4 lines · Daniel Schwierzeck
will be simply exited. The SDBBP handler currently only prints the content of registers
c0_depcandc0_debug. This could be extended in the future to handle semi-hosting according to the MIPS UHI specification.
Thanks for considering UHI in this. I worked on a prototype implementation of UHI with Paul that is yet to be submitted which hooks the syscall exception in U-Boot. There is a way to avoid going all the way down to debug mode to process a UHI operation on-target so we can support cores that don't have ejtag or simply to stay out of debug mode wherever possible. The basic principle is that either an application doesn't install its own exception vector and hence uses U-boot's or it does install its own but remembers where U-boot's EBASE was and unwinds a SYSCALL exception and forwards it to U-boot's general-exception handler. It seems to work pretty well but there is certainly no harm in hooking the debug vector too.
Matthew