Re: [U-Boot] [PATCH v3] arm: build arch memset/memcpy in Thumb2 mode

2015-01-09 Thread Albert ARIBAUD
Hello Stefan,

On Mon, 05 Jan 2015 23:21:41 +0100, Stefan Agner ste...@agner.ch
wrote:
 Albert,
 
 I guess it is too late for that now. Thought it would make it into
 2015.01, since your last comment in v2 suggested that you would treat it
 as bugfix...

If Tom's OK, I or he can take it.

Amicalement,
-- 
Albert.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v3] arm: build arch memset/memcpy in Thumb2 mode

2015-01-05 Thread Stefan Agner
Albert,

I guess it is too late for that now. Thought it would make it into
2015.01, since your last comment in v2 suggested that you would treat it
as bugfix...

--
Stefan

On 2014-12-18 18:10, Stefan Agner wrote:
 Resynchronize memcpy/memset with kernel 3.17 and build them in
 Thumb2 mode (unified syntax). Those assembler files can be built
 and linked in ARM mode too, however when calling them from Thumb2
 built code, the stack got corrupted and the copy did not succeed
 (the exact details have not been traced back). However, the Linux
 kernel builds those files in Thumb2 mode. Hence U-Boot should
 build them in Thumb2 mode too when CONFIG_SYS_THUMB_BUILD is set.
 
 To build the files without warning, some assembler instructions
 had to be replaced with their UAL compliant variant (thanks
 Jeroen for this input).
 
 To build the file in Thumb2 mode the implicit-it=always option need
 to be set to generate Thumb2 compliant IT instructions where needed.
 We add this option to the general AFLAGS when building for Thumb2.
 
 Reviewed-by: Simon Glass s...@chromium.org
 Tested-by: Simon Glass s...@chromium.org
 Signed-off-by: Stefan Agner ste...@agner.ch
 ---
  arch/arm/config.mk   |   4 +-
  arch/arm/include/asm/assembler.h |  33 ++--
  arch/arm/lib/memcpy.S|  80 +++-
  arch/arm/lib/memset.S| 112 
 ---
  4 files changed, 142 insertions(+), 87 deletions(-)
 
 diff --git a/arch/arm/config.mk b/arch/arm/config.mk
 index f0eafd6..9a4c270 100644
 --- a/arch/arm/config.mk
 +++ b/arch/arm/config.mk
 @@ -26,7 +26,9 @@ PLATFORM_CPPFLAGS += -D__ARM__
  
  # Choose between ARM/Thumb instruction sets
  ifeq ($(CONFIG_SYS_THUMB_BUILD),y)
 -PF_CPPFLAGS_ARM := $(call cc-option, -mthumb -mthumb-interwork,\
 +AFLAGS_IMPLICIT_IT   := $(call as-option,-Wa$(comma)-mimplicit-it=always)
 +PF_CPPFLAGS_ARM  := $(AFLAGS_IMPLICIT_IT) \
 + $(call cc-option, -mthumb -mthumb-interwork,\
   $(call cc-option,-marm,)\
   $(call cc-option,-mno-thumb-interwork,)\
   )
 diff --git a/arch/arm/include/asm/assembler.h 
 b/arch/arm/include/asm/assembler.h
 index 5e4789b..11b80fb 100644
 --- a/arch/arm/include/asm/assembler.h
 +++ b/arch/arm/include/asm/assembler.h
 @@ -14,12 +14,14 @@
   *  assembler source.
   */
  
 +#include config.h
 +
  /*
   * Endian independent macros for shifting bytes within registers.
   */
  #ifndef __ARMEB__
 -#define pull lsr
 -#define push lsl
 +#define lspull   lsr
 +#define lspush   lsl
  #define get_byte_0   lsl #0
  #define get_byte_1   lsr #8
  #define get_byte_2   lsr #16
 @@ -29,8 +31,8 @@
  #define put_byte_2   lsl #16
  #define put_byte_3   lsl #24
  #else
 -#define pull lsl
 -#define push lsr
 +#define lspull   lsl
 +#define lspush   lsr
  #define get_byte_0   lsr #24
  #define get_byte_1   lsr #16
  #define get_byte_2   lsr #8
 @@ -54,7 +56,28 @@
  #define PLD(code...)
  #endif
  
 + .irpc,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo
 + .macro  ret\c, reg
 +#if defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__)
 + mov\c   pc, \reg
 +#else
 + .ifeqs  \reg, lr
 + bx\c\reg
 + .else
 + mov\c   pc, \reg
 + .endif
 +#endif
 + .endm
 + .endr
 +
  /*
 - * Cache alligned
 + * Cache aligned, used for optimized memcpy/memset
 + * In the kernel this is only enabled for Feroceon CPU's...
 + * We disable it especially for Thumb builds since those instructions
 + * are not made in a Thumb ready way...
   */
 +#ifdef CONFIG_SYS_THUMB_BUILD
 +#define CALGN(code...)
 +#else
  #define CALGN(code...) code
 +#endif
 diff --git a/arch/arm/lib/memcpy.S b/arch/arm/lib/memcpy.S
 index f655256..eeaf003 100644
 --- a/arch/arm/lib/memcpy.S
 +++ b/arch/arm/lib/memcpy.S
 @@ -10,9 +10,14 @@
   *  published by the Free Software Foundation.
   */
  
 +#include linux/linkage.h
  #include asm/assembler.h
  
 +#ifdef CONFIG_SYS_THUMB_BUILD
 +#define W(instr) instr.w
 +#else
  #define W(instr) instr
 +#endif
  
  #define LDR1W_SHIFT  0
  #define STR1W_SHIFT  0
 @@ -30,7 +35,7 @@
   .endm
  
   .macro ldr1b ptr reg cond=al abort
 - ldr\cond\()b \reg, [\ptr], #1
 + ldrb\cond\() \reg, [\ptr], #1
   .endm
  
   .macro str1w ptr reg abort
 @@ -42,7 +47,7 @@
   .endm
  
   .macro str1b ptr reg cond=al abort
 - str\cond\()b \reg, [\ptr], #1
 + strb\cond\() \reg, [\ptr], #1
   .endm
  
   .macro enter reg1 reg2
 @@ -56,10 +61,12 @@
   .text
  
  /* Prototype: void *memcpy(void *dest, const void *src, size_t n); */
 -
 -.globl memcpy
 -memcpy:
 -
 + .syntax unified
 +#ifdef CONFIG_SYS_THUMB_BUILD
 + .thumb
 + .thumb_func
 +#endif
 +ENTRY(memcpy)
   cmp r0, r1
   moveq   pc, lr
  
 @@ -79,7 +86,7 @@ memcpy:
  
   CALGN(  ands

[U-Boot] [PATCH v3] arm: build arch memset/memcpy in Thumb2 mode

2014-12-18 Thread Stefan Agner
Resynchronize memcpy/memset with kernel 3.17 and build them in
Thumb2 mode (unified syntax). Those assembler files can be built
and linked in ARM mode too, however when calling them from Thumb2
built code, the stack got corrupted and the copy did not succeed
(the exact details have not been traced back). However, the Linux
kernel builds those files in Thumb2 mode. Hence U-Boot should
build them in Thumb2 mode too when CONFIG_SYS_THUMB_BUILD is set.

To build the files without warning, some assembler instructions
had to be replaced with their UAL compliant variant (thanks
Jeroen for this input).

To build the file in Thumb2 mode the implicit-it=always option need
to be set to generate Thumb2 compliant IT instructions where needed.
We add this option to the general AFLAGS when building for Thumb2.

Reviewed-by: Simon Glass s...@chromium.org
Tested-by: Simon Glass s...@chromium.org
Signed-off-by: Stefan Agner ste...@agner.ch
---
 arch/arm/config.mk   |   4 +-
 arch/arm/include/asm/assembler.h |  33 ++--
 arch/arm/lib/memcpy.S|  80 +++-
 arch/arm/lib/memset.S| 112 ---
 4 files changed, 142 insertions(+), 87 deletions(-)

diff --git a/arch/arm/config.mk b/arch/arm/config.mk
index f0eafd6..9a4c270 100644
--- a/arch/arm/config.mk
+++ b/arch/arm/config.mk
@@ -26,7 +26,9 @@ PLATFORM_CPPFLAGS += -D__ARM__
 
 # Choose between ARM/Thumb instruction sets
 ifeq ($(CONFIG_SYS_THUMB_BUILD),y)
-PF_CPPFLAGS_ARM := $(call cc-option, -mthumb -mthumb-interwork,\
+AFLAGS_IMPLICIT_IT := $(call as-option,-Wa$(comma)-mimplicit-it=always)
+PF_CPPFLAGS_ARM:= $(AFLAGS_IMPLICIT_IT) \
+   $(call cc-option, -mthumb -mthumb-interwork,\
$(call cc-option,-marm,)\
$(call cc-option,-mno-thumb-interwork,)\
)
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 5e4789b..11b80fb 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -14,12 +14,14 @@
  *  assembler source.
  */
 
+#include config.h
+
 /*
  * Endian independent macros for shifting bytes within registers.
  */
 #ifndef __ARMEB__
-#define pull   lsr
-#define push   lsl
+#define lspull lsr
+#define lspush lsl
 #define get_byte_0 lsl #0
 #define get_byte_1 lsr #8
 #define get_byte_2 lsr #16
@@ -29,8 +31,8 @@
 #define put_byte_2 lsl #16
 #define put_byte_3 lsl #24
 #else
-#define pull   lsl
-#define push   lsr
+#define lspull lsl
+#define lspush lsr
 #define get_byte_0 lsr #24
 #define get_byte_1 lsr #16
 #define get_byte_2 lsr #8
@@ -54,7 +56,28 @@
 #define PLD(code...)
 #endif
 
+   .irpc,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo
+   .macro  ret\c, reg
+#if defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__)
+   mov\c   pc, \reg
+#else
+   .ifeqs  \reg, lr
+   bx\c\reg
+   .else
+   mov\c   pc, \reg
+   .endif
+#endif
+   .endm
+   .endr
+
 /*
- * Cache alligned
+ * Cache aligned, used for optimized memcpy/memset
+ * In the kernel this is only enabled for Feroceon CPU's...
+ * We disable it especially for Thumb builds since those instructions
+ * are not made in a Thumb ready way...
  */
+#ifdef CONFIG_SYS_THUMB_BUILD
+#define CALGN(code...)
+#else
 #define CALGN(code...) code
+#endif
diff --git a/arch/arm/lib/memcpy.S b/arch/arm/lib/memcpy.S
index f655256..eeaf003 100644
--- a/arch/arm/lib/memcpy.S
+++ b/arch/arm/lib/memcpy.S
@@ -10,9 +10,14 @@
  *  published by the Free Software Foundation.
  */
 
+#include linux/linkage.h
 #include asm/assembler.h
 
+#ifdef CONFIG_SYS_THUMB_BUILD
+#define W(instr)   instr.w
+#else
 #define W(instr)   instr
+#endif
 
 #define LDR1W_SHIFT0
 #define STR1W_SHIFT0
@@ -30,7 +35,7 @@
.endm
 
.macro ldr1b ptr reg cond=al abort
-   ldr\cond\()b \reg, [\ptr], #1
+   ldrb\cond\() \reg, [\ptr], #1
.endm
 
.macro str1w ptr reg abort
@@ -42,7 +47,7 @@
.endm
 
.macro str1b ptr reg cond=al abort
-   str\cond\()b \reg, [\ptr], #1
+   strb\cond\() \reg, [\ptr], #1
.endm
 
.macro enter reg1 reg2
@@ -56,10 +61,12 @@
.text
 
 /* Prototype: void *memcpy(void *dest, const void *src, size_t n); */
-
-.globl memcpy
-memcpy:
-
+   .syntax unified
+#ifdef CONFIG_SYS_THUMB_BUILD
+   .thumb
+   .thumb_func
+#endif
+ENTRY(memcpy)
cmp r0, r1
moveq   pc, lr
 
@@ -79,7 +86,7 @@ memcpy:
 
CALGN(  andsip, r0, #31 )
CALGN(  rsb r3, ip, #32 )
-   CALGN(  sbcnes  r4, r3, r2  )  @ C is always set here
+   CALGN(  sbcsne  r4, r3, r2  )  @ C is always set here
CALGN(  bcs 2f  )
CALGN(  adr r4,