nios2: convert copy_exception_trampoline to use dm cpu data
PATCH 1/1 nios2: convert copy_exception_trampoline to use dm cpu data
Convert copy_exception_trampoline() to use dm cpu data.
--- arch/nios2/cpu/cpu.c | 24 ++++++++++++++++++++++++ arch/nios2/cpu/start.S | 24 +----------------------- 2 files changed, 25 insertions(+), 23 deletions(-)
arch/nios2/cpu/cpu.c +24 -0
@@ -44,6 +44,27 @@ void dcache_disable(void)flush_dcache (CONFIG_SYS_DCACHE_SIZE ,CONFIG_SYS_DCACHELINE_SIZE ); } +/* +* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the +* exception address. Define CONFIG_ROM_STUBS to prevent +* the copy (e.g. exception in flash or in other +* softare/firmware component). +*/ +#ifndef CONFIG_ROM_STUBS +static void copy_exception_trampoline (void ) +{ +extern void *_except_start, *_except_end; +void *except_target = (void *)gd->arch.exception_addr; + +if (_except_start != except_target) { +memcpy (except_target, _except_start, + _except_end - _except_start); +flush_cache (gd->arch.exception_addr, + _except_end - _except_start); + } +} +#endif +int arch_cpu_init_dm (void ) {struct udevice *dev;
@@ -56,6 +77,9 @@ int arch_cpu_init_dm(void)return -ENODEV ; gd->ram_size =CONFIG_SYS_SDRAM_SIZE ; +#ifndef CONFIG_ROM_STUBS +copy_exception_trampoline (); +#endif return 0 ; }
arch/nios2/cpu/start.S +1 -23
@@ -14,7 +14,7 @@ ************************************************************************/ .text - .global _start + .global _start, _except_start, _except_end _start: wrctl status, r0 /* Disable interrupts */
@@ -89,28 +89,6 @@ _cur: movhi r5, %hi(_cur - _start) jmp r4 _reloc: - /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the - * exception address. Define CONFIG_ROM_STUBS to prevent - * the copy (e.g. exception in flash or in other - * softare/firmware component). - */ -#if !defined(CONFIG_ROM_STUBS) - movhi r4, %hi(_except_start) - ori r4, r4, %lo(_except_start) - movhi r5, %hi(_except_end) - ori r5, r5, %lo(_except_end) - movhi r6, %hi(CONFIG_SYS_EXCEPTION_ADDR) - ori r6, r6, %lo(CONFIG_SYS_EXCEPTION_ADDR) - beq r4, r6, 7f /* Skip if at proper addr */ - -6: ldwio r7, 0(r4) - stwio r7, 0(r6) - addi r4, r4, 4 - addi r6, r6, 4 - bne r4, r5, 6b -7: -#endif - /* STACK INIT -- zero top two words for call back chain. */ movhi sp, %hi(CONFIG_SYS_INIT_SP)
Signature · 1 line
2.1.4
PATCH v2 1/1 nios2: convert copy_exception_trampoline to use dm cpu data
Convert copy_exception_trampoline() to use dm cpu data.
---
v2
fix exception address references.
arch/nios2/cpu/cpu.c | 24 ++++++++++++++++++++++++ arch/nios2/cpu/start.S | 24 +----------------------- 2 files changed, 25 insertions(+), 23 deletions(-)
arch/nios2/cpu/cpu.c +24 -0
@@ -44,6 +44,27 @@ void dcache_disable(void)flush_dcache (CONFIG_SYS_DCACHE_SIZE ,CONFIG_SYS_DCACHELINE_SIZE ); } +/* +* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the +* exception address. Define CONFIG_ROM_STUBS to prevent +* the copy (e.g. exception in flash or in other +* softare/firmware component). +*/ +#ifndef CONFIG_ROM_STUBS +static void copy_exception_trampoline (void ) +{ +extern int _except_start, _except_end; +void *except_target = (void *)gd->arch.exception_addr; + +if (&_except_start != except_target) { +memcpy (except_target, &_except_start, + &_except_end - &_except_start); +flush_cache (gd->arch.exception_addr, + &_except_end - &_except_start); + } +} +#endif +int arch_cpu_init_dm (void ) {struct udevice *dev;
@@ -56,6 +77,9 @@ int arch_cpu_init_dm(void)return -ENODEV ; gd->ram_size =CONFIG_SYS_SDRAM_SIZE ; +#ifndef CONFIG_ROM_STUBS +copy_exception_trampoline (); +#endif return 0 ; }
arch/nios2/cpu/start.S +1 -23
@@ -14,7 +14,7 @@ ************************************************************************/ .text - .global _start + .global _start, _except_start, _except_end _start: wrctl status, r0 /* Disable interrupts */
@@ -89,28 +89,6 @@ _cur: movhi r5, %hi(_cur - _start) jmp r4 _reloc: - /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the - * exception address. Define CONFIG_ROM_STUBS to prevent - * the copy (e.g. exception in flash or in other - * softare/firmware component). - */ -#if !defined(CONFIG_ROM_STUBS) - movhi r4, %hi(_except_start) - ori r4, r4, %lo(_except_start) - movhi r5, %hi(_except_end) - ori r5, r5, %lo(_except_end) - movhi r6, %hi(CONFIG_SYS_EXCEPTION_ADDR) - ori r6, r6, %lo(CONFIG_SYS_EXCEPTION_ADDR) - beq r4, r6, 7f /* Skip if at proper addr */ - -6: ldwio r7, 0(r4) - stwio r7, 0(r6) - addi r4, r4, 4 - addi r6, r6, 4 - bne r4, r5, 6b -7: -#endif - /* STACK INIT -- zero top two words for call back chain. */ movhi sp, %hi(CONFIG_SYS_INIT_SP)
Signature · 1 line
2.1.4
PATCH v2 1/1 nios2: convert copy_exception_trampoline to use dm cpu data
Quoted 26 lines · Thomas Chou
Convert
copy_exception_trampoline()to use dm cpu data.Signed-off-by Thomas Chou <[email protected]>---
v2
fix exception address references.arch/nios2/cpu/cpu.c | 24 ++++++++++++++++++++++++ arch/nios2/cpu/start.S | 24 +----------------------- 2 files changed, 25 insertions(+), 23 deletions(-)arch/nios2/cpu/cpu.c +7
-0@@ -44,6 +44,27 @@ void dcache_disable(void)flush_dcache (CONFIG_SYS_DCACHE_SIZE ,CONFIG_SYS_DCACHELINE_SIZE ); } +/* +* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the +* exception address. Define CONFIG_ROM_STUBS to prevent +* the copy (e.g. exception in flash or in other +* softare/firmware component). +*/ +#ifndef CONFIG_ROM_STUBS
arch/nios2/cpu/cpu.c void dcache_disable(void) · line 63
Quoted 10 lines
arch/nios2/cpu/cpu.c +10
-0+static void copy_exception_trampoline (void ) +{ +extern int _except_start, _except_end; +void *except_target = (void *)gd->arch.exception_addr; + +if (&_except_start != except_target) { +memcpy (except_target, &_except_start, + &_except_end - &_except_start); +flush_cache (gd->arch.exception_addr, + &_except_end - &_except_start);
Are you absolutelly sure that those addresses are aligned ?
Quoted 59 lines
arch/nios2/cpu/cpu.c +7
-0+ } +} +#endif +int arch_cpu_init_dm (void ) {struct udevice *dev;@@ -56,6 +77,9 @@ int arch_cpu_init_dm(void)return -ENODEV ; gd->ram_size =CONFIG_SYS_SDRAM_SIZE ; +#ifndef CONFIG_ROM_STUBS +copy_exception_trampoline (); +#endif return 0 ; }arch/nios2/cpu/start.S +1
-23@@ -14,7 +14,7 @@ ************************************************************************/ .text - .global _start + .global _start, _except_start, _except_end _start: wrctl status, r0 /* Disable interrupts */@@ -89,28 +89,6 @@ _cur: movhi r5, %hi(_cur - _start) jmp r4 _reloc: - /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the - * exception address. Define CONFIG_ROM_STUBS to prevent - * the copy (e.g. exception in flash or in other - * softare/firmware component). - */ -#if !defined(CONFIG_ROM_STUBS) - movhi r4, %hi(_except_start) - ori r4, r4, %lo(_except_start) - movhi r5, %hi(_except_end) - ori r5, r5, %lo(_except_end) - movhi r6, %hi(CONFIG_SYS_EXCEPTION_ADDR) - ori r6, r6, %lo(CONFIG_SYS_EXCEPTION_ADDR) - beq r4, r6, 7f /* Skip if at proper addr */ - -6: ldwio r7, 0(r4) - stwio r7, 0(r6) - addi r4, r4, 4 - addi r6, r6, 4 - bne r4, r5, 6b -7: -#endif - /* STACK INIT -- zero top two words for call back chain. */ movhi sp, %hi(CONFIG_SYS_INIT_SP)
PATCH v2 1/1 nios2: convert copy_exception_trampoline to use dm cpu data
In reply to Thomas ChouQuoted 19 lines · Thomas Chou
Convert
copy_exception_trampoline()to use dm cpu data.Signed-off-by Thomas Chou <[email protected]>---
v2
fix exception address references.arch/nios2/cpu/cpu.c | 24 ++++++++++++++++++++++++ arch/nios2/cpu/start.S | 24 +----------------------- 2 files changed, 25 insertions(+), 23 deletions(-)arch/nios2/cpu/cpu.c +0
-0@@ -44,6 +44,27 @@ void dcache_disable(void)flush_dcache (CONFIG_SYS_DCACHE_SIZE ,CONFIG_SYS_DCACHELINE_SIZE ); }
arch/nios2/cpu/cpu.c void dcache_disable(void) · line 56
Quoted 10 lines
arch/nios2/cpu/cpu.c +10
-0+/* +* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the +* exception address. Define CONFIG_ROM_STUBS to prevent +* the copy (e.g. exception in flash or in other +* softare/firmware component). +*/ +#ifndef CONFIG_ROM_STUBS +static void copy_exception_trampoline (void ) +{ +extern int _except_start, _except_end;
Can we use void* for _except_start and _except_end?
Quoted 11 lines
arch/nios2/cpu/cpu.c +11
-0+void *except_target = (void *)gd->arch.exception_addr; + +if (&_except_start != except_target) { +memcpy (except_target, &_except_start, + &_except_end - &_except_start); +flush_cache (gd->arch.exception_addr, + &_except_end - &_except_start); + } +} +#endif +
PATCH v2 1/1 nios2: convert copy_exception_trampoline to use dm cpu data
Hi Ley Foon,
Quoted 4 lines · Ley Foon Tan
arch/nios2/cpu/cpu.c void dcache_disable(void) · line 56
Quoted 3 lines
arch/nios2/cpu/cpu.c +3
-0+static void copy_exception_trampoline (void ) +{ +extern int _except_start, _except_end;Can we use void* for
_except_startand_except_end?
Yes, we can. Actually I used void * at first draft of this patch v1. But it doesn't work. We still need to get the address with '&' operator as in v2. I think it is confusing with void *, so I use int instead. But anything will do.
Best regards,
Thomas
PATCH v2 1/1 nios2: convert copy_exception_trampoline to use dm cpu data
Quoted 9 lines · Thomas Chou
Hi Ley Foon,
Quoted 5 lines · Ley Foon Tan
arch/nios2/cpu/cpu.c void dcache_disable(void) · line 56
Quoted 3 lines
arch/nios2/cpu/cpu.c +3
-0+static void copy_exception_trampoline (void ) +{ +extern int _except_start, _except_end;Can we use void* for
_except_startand_except_end?
Quoted 4 lines
Yes, we can. Actually I used void * at first draft of this patch v1. But it doesn't work. We still need to get the address with '&' operator as in v2. I think it is confusing with void *, so I use int instead. But anything will do.
I think extern void * might work, but extern int is also OK when referencing external symbol.
Best regards,
Marek Vasut
PATCH v2 1/1 nios2: convert copy_exception_trampoline to use dm cpu data
In reply to Thomas ChouQuoted 11 lines · Thomas Chou
Convert
copy_exception_trampoline()to use dm cpu data.Signed-off-by Thomas Chou <[email protected]>---
v2
fix exception address references.arch/nios2/cpu/cpu.c | 24 ++++++++++++++++++++++++ arch/nios2/cpu/start.S | 24 +----------------------- 2 files changed, 25 insertions(+), 23 deletions(-)
Applied to u-boot-nios.
Quoted 85 lines
arch/nios2/cpu/cpu.c +24
-0@@ -44,6 +44,27 @@ void dcache_disable(void)flush_dcache (CONFIG_SYS_DCACHE_SIZE ,CONFIG_SYS_DCACHELINE_SIZE ); } +/* +* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the +* exception address. Define CONFIG_ROM_STUBS to prevent +* the copy (e.g. exception in flash or in other +* softare/firmware component). +*/ +#ifndef CONFIG_ROM_STUBS +static void copy_exception_trampoline (void ) +{ +extern int _except_start, _except_end; +void *except_target = (void *)gd->arch.exception_addr; + +if (&_except_start != except_target) { +memcpy (except_target, &_except_start, + &_except_end - &_except_start); +flush_cache (gd->arch.exception_addr, + &_except_end - &_except_start); + } +} +#endif +int arch_cpu_init_dm (void ) {struct udevice *dev;@@ -56,6 +77,9 @@ int arch_cpu_init_dm(void)return -ENODEV ; gd->ram_size =CONFIG_SYS_SDRAM_SIZE ; +#ifndef CONFIG_ROM_STUBS +copy_exception_trampoline (); +#endif return 0 ; }arch/nios2/cpu/start.S +1
-23@@ -14,7 +14,7 @@ ************************************************************************/ .text - .global _start + .global _start, _except_start, _except_end _start: wrctl status, r0 /* Disable interrupts */@@ -89,28 +89,6 @@ _cur: movhi r5, %hi(_cur - _start) jmp r4 _reloc: - /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the - * exception address. Define CONFIG_ROM_STUBS to prevent - * the copy (e.g. exception in flash or in other - * softare/firmware component). - */ -#if !defined(CONFIG_ROM_STUBS) - movhi r4, %hi(_except_start) - ori r4, r4, %lo(_except_start) - movhi r5, %hi(_except_end) - ori r5, r5, %lo(_except_end) - movhi r6, %hi(CONFIG_SYS_EXCEPTION_ADDR) - ori r6, r6, %lo(CONFIG_SYS_EXCEPTION_ADDR) - beq r4, r6, 7f /* Skip if at proper addr */ - -6: ldwio r7, 0(r4) - stwio r7, 0(r6) - addi r4, r4, 4 - addi r6, r6, 4 - bne r4, r5, 6b -7: -#endif - /* STACK INIT -- zero top two words for call back chain. */ movhi sp, %hi(CONFIG_SYS_INIT_SP)