On 13.11.2013 15:49, Colin Watson wrote:
> After my previous fix, arm-uboot still fails to build with:
> 
>   arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I. -I../../../grub-core -I..  
> -Wall -W -I../../../include -I../include  -DGRUB_MACHINE_UBOOT=1 
> -DGRUB_MACHINE_ARM=1 -DGRUB_MACHINE=ARM_UBOOT -DGRUB_TARGET_CPU_ARM=1 
> -nostdinc -isystem /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/include 
> -DGRUB_FILE=\"lib/arg.c\" -I. -I../../../grub-core -I.. -I../../.. 
> -I../../../include -I../include 
> -I../../../grub-core/lib/libgcrypt-grub/include 
> -I../../../grub-core/lib/libgcrypt-grub/src/   -DGRUB_KERNEL=1   -Os -Wall -W 
> -Wshadow -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Wattributes 
> -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization 
> -Wdiv-by-zero -Wendif-labels -Wfloat-equal -Wformat-extra-args 
> -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration 
> -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmain 
> -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute 
> -Wmultichar -Wnonnull -Woverflow -Wparentheses -Wpointer-ar
ith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow 
-Wsign-compare -Wstrict-aliasing -Wswitch -Wtrigraphs -Wundef -Wunknown-pragmas 
-Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  
-Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings 
-Wnested-externs -Wstrict-prototypes -Wpointer-sign -g -Wredundant-decls 
-Wmissing-prototypes -Wmissing-declarations -Wcast-align -freg-struct-return 
-fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fno-stack-protector 
-mno-unaligned-access -Wtrampolines -Werror -DUSE_ASCII_FALLBACK=1 
-DHAVE_UNIFONT_WIDTHSPEC=1     -mthumb-interwork -mlong-calls -ffreestanding   
-MT lib/kernel_exec-arg.o -MD -MP -MF lib/.deps-core/kernel_exec-arg.Tpo -c -o 
lib/kernel_exec-arg.o `test -f 'lib/arg.c' || echo 
'../../../grub-core/'`lib/arg.c
>   misc.S: Assembler messages:
>   misc.S:56: Error: r13 not allowed here -- `sub sp,fp,#4'
>   make[3]: *** [kern/arm/kernel_exec-misc.o] Error 1
> 
> I don't think SP can be used that way in Thumb mode?
> 
I think that our asm routines should be in full ARM. Attached patch
follows this strategy. One remaining problem is to make sure that thumb
flags in TARGET_CFLAGS and TARGET_CCASFLAGS match.
diff --git a/conf/Makefile.common b/conf/Makefile.common
index 0dc26db..c563c51 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -19,7 +19,8 @@ if COND_sparc64_ieee1275
   LDFLAGS_PLATFORM = -Wl,-melf64_sparc -mno-relax
 endif
 if COND_arm
-  CFLAGS_PLATFORM += -mthumb-interwork -mlong-calls
+  CFLAGS_PLATFORM += -mlong-calls -mthumb-interwork
+  CCASFLAGS_PLATFORM = -mthumb-interwork
   LDFLAGS_PLATFORM = -Wl,--wrap=__clear_cache
 endif
 
diff --git a/grub-core/kern/arm/cache.S b/grub-core/kern/arm/cache.S
index 8522d24..3d2503e 100644
--- a/grub-core/kern/arm/cache.S
+++ b/grub-core/kern/arm/cache.S
@@ -84,19 +84,22 @@ FUNCTION(grub_arch_sync_caches_armv6)
 #else
 FUNCTION(grub_arch_sync_caches_armv7)
 #endif
+	ARM_PROLOGUE
 	DSB
 	add	r1, r0, r1
 	push	{r0-r2, lr}
 	bl	clean_dcache_range
 	pop	{r0, r1}
 	bl	invalidate_icache_range
-	pop	{r2, pc}
+	pop	{r2, lr}
+	bx 	lr
 
 #ifdef ARMV6
 FUNCTION(grub_arm_disable_caches_mmu_armv6)
 #else
 FUNCTION(grub_arm_disable_caches_mmu_armv7)
 #endif
+	ARM_PROLOGUE
 
 	push	{r4, lr}
 
@@ -132,5 +135,6 @@ FUNCTION(grub_arm_disable_caches_mmu_armv7)
 	DSB
 	ISB
 
-	pop	{r4, pc}
+	pop	{r4, lr}
+	bx	lr
 
diff --git a/grub-core/kern/arm/cache_armv6.S b/grub-core/kern/arm/cache_armv6.S
index 52b8157..d6371eb 100644
--- a/grub-core/kern/arm/cache_armv6.S
+++ b/grub-core/kern/arm/cache_armv6.S
@@ -37,9 +37,11 @@ clean_invalidate_dcache:
 #include "cache.S"
 
 FUNCTION(grub_arm_main_id)
+	ARM_PROLOGUE
 	mrc 	p15, 0, r0, c0, c0, 0
 	bx lr
 
 FUNCTION(grub_arm_cache_type)
+	ARM_PROLOGUE
 	mrc 	p15, 0, r0, c0, c0, 1
 	bx lr
\ No newline at end of file
diff --git a/grub-core/kern/arm/cache_armv7.S b/grub-core/kern/arm/cache_armv7.S
index 0c16b10..454bad3 100644
--- a/grub-core/kern/arm/cache_armv7.S
+++ b/grub-core/kern/arm/cache_armv7.S
@@ -22,10 +22,16 @@
 	.text
 	.syntax	unified
 	.arm
+#ifdef __clang__
+# define DMB .long 0xf57ff05f
+# define DSB .long 0xf57ff04f
+# define ISB .long 0xf57ff06f
+#else
 	.arch	armv7a
 # define DMB	dmb
 # define DSB	dsb
 # define ISB	isb
+#endif
 #define ARMV7 1
 
 	@ r0  - CLIDR
@@ -58,11 +64,17 @@ clean_invalidate_dcache:
 	@ read current cache information
 	mrc	p15, 1, r8, c0, c0, 0	@ Read CCSIDR
 	lsr	r3, r8, #13		@ Number of sets -1
-	ldr	r9, =0x3fff
-	and	r3, r3, r9
+
+	@ Keep only 14 bits of r3
+	lsl     r3, r3, #18
+	lsr     r3, r3, #18
+
 	lsr	r4, r8, #3		@ Number of ways -1
-	ldr	r9, =0x1ff
-	and	r4, r4, r9
+
+	@ Keep only 9  bits of r4
+	lsl     r4, r4, #23
+	lsr     r4, r4, #23
+
 	and	r7, r8, #7		@ log2(line size in words) - 2
 	add	r7, r7, #2		@  adjust
 	mov	r8, #1
diff --git a/grub-core/kern/arm/misc.S b/grub-core/kern/arm/misc.S
index 8420a2a..f5513c0 100644
--- a/grub-core/kern/arm/misc.S
+++ b/grub-core/kern/arm/misc.S
@@ -22,16 +22,13 @@
 	.file	"misc.S"
 	.text
 	.syntax	unified
-#if !defined (__thumb2__)
 	.arm
-#else
-	.thumb
-#endif
 
 	.align	2
 
 FUNCTION(__muldi3)
 FUNCTION(__aeabi_lmul)
+	ARM_PROLOGUE
         stmfd   sp!, {r4, fp}
         add     fp, sp, #4
         sub     sp, sp, #16
@@ -74,14 +71,15 @@ FUNCTION(__aeabi_lmul)
 	.endm
 
 FUNCTION(__aeabi_uidivmod)
+	ARM_PROLOGUE
 	division grub_divmod64
 
-
 /*
  * Null divide-by-zero handler
  */
 FUNCTION(__aeabi_unwind_cpp_pr0)
 FUNCTION(raise)
+	ARM_PROLOGUE
 	mov	r0, #0
 	bx	lr
 	
diff --git a/grub-core/kern/arm/uboot/startup.S b/grub-core/kern/arm/uboot/startup.S
index f54b14b..25c978a 100644
--- a/grub-core/kern/arm/uboot/startup.S
+++ b/grub-core/kern/arm/uboot/startup.S
@@ -47,7 +47,10 @@
 	
 	.text
 	.arm
-FUNCTION(_start)
+	/* Don't use FUNCTION as this entry point is always ARM.  */
+	.globl EXT_C(_start)
+	.type EXT_C(_start), %function
+EXT_C(_start):
 	b	codestart
 	
 	@ Size of final image integrated module blob - set by grub-mkimage
@@ -66,7 +69,7 @@ bss_start_ptr:
 end_ptr:
 	.long   EXT_C(_end)
 
-FUNCTION(codestart)
+codestart:
 	@ Store context: Machine ID, atags/dtb, ...
 	@ U-Boot API signature is stored on the U-Boot heap
 	@ Stack pointer used as start address for signature probing
@@ -117,8 +120,19 @@ FUNCTION(codestart)
 1:	str	r2, [r0], #4
 	cmp	r0, r1
 	bne	1b
-	
-	b	EXT_C(grub_main)
+
+	ldr     r0, main_addr
+#ifdef __thumb__
+	orr     r0, r0, #1
+#endif
+	bx	r0
+	.p2align 2
+#ifdef __thumb__
+	.thumb
+#endif
+main_addr:
+	.long EXT_C(grub_main)
+	.arm
 
 	/*
 	 * uboot_syscall():
@@ -128,6 +142,7 @@ FUNCTION(codestart)
 	 *   U-Boot (Global Data Pointer) and preserve it for Grub.
 	 */
 FUNCTION(grub_uboot_syscall)
+	ARM_PROLOGUE
 	str     r8, transition_space
 	str     lr, transition_space + 4
 	str     r9, transition_space + 8
@@ -152,6 +167,7 @@ FUNCTION(grub_uboot_syscall)
 	bx	lr
 	
 FUNCTION(grub_uboot_return)
+	ARM_PROLOGUE
 	adr	sp, entry_state_end
 	pop	{r4-r12, lr}
 	mov	sp, r12
diff --git a/grub-core/lib/arm/setjmp.S b/grub-core/lib/arm/setjmp.S
index 4f15679..b731975 100644
--- a/grub-core/lib/arm/setjmp.S
+++ b/grub-core/lib/arm/setjmp.S
@@ -32,6 +32,7 @@ GRUB_MOD_LICENSE "GPLv3+"
  * int grub_setjmp (grub_jmp_buf env)
  */
 FUNCTION(grub_setjmp)
+	ARM_PROLOGUE
 	stm	r0, { r4-r11, sp, lr }
 	mov	r0, #0
 	bx	lr
@@ -40,6 +41,7 @@ FUNCTION(grub_setjmp)
  * int grub_longjmp (grub_jmp_buf env, int val)
  */
 FUNCTION(grub_longjmp)
+	ARM_PROLOGUE
  	ldm	r0, { r4-r11, sp, lr }
 	movs	r0, r1
 	moveq	r0, #1
diff --git a/include/grub/symbol.h b/include/grub/symbol.h
index 62d3cb1..6de9be2 100644
--- a/include/grub/symbol.h
+++ b/include/grub/symbol.h
@@ -52,9 +52,25 @@
 /* .type not supported for non-ELF targets.  XXX: Check this in configure? */
 #define FUNCTION(x)	.globl EXT_C(x) ; .def EXT_C(x); .scl 2; .type 32; .endef; EXT_C(x):
 #define VARIABLE(x)	.globl EXT_C(x) ; .def EXT_C(x); .scl 2; .type 0; .endef; EXT_C(x):
+#elif defined (__thumb__)
+#define FUNCTION(x)	.p2align 2 ; .thumb ; .globl EXT_C(x) ; .type EXT_C(x), %function ; .thumb_func ; EXT_C(x):
+#define VARIABLE(x)	.globl EXT_C(x) ; .type EXT_C(x), %object ; EXT_C(x):
+#ifdef ASM_FILE
+	.macro ARM_PROLOGUE
+	bx pc
+	nop
+	.arm
+	orr lr, lr, #1
+	.endm
+#endif
 #elif defined (__arm__)
 #define FUNCTION(x)	.globl EXT_C(x) ; .type EXT_C(x), %function ; EXT_C(x):
 #define VARIABLE(x)	.globl EXT_C(x) ; .type EXT_C(x), %object ; EXT_C(x):
+#ifdef ASM_FILE
+	.macro ARM_PROLOGUE
+	.arm
+	.endm
+#endif
 #else
 #define FUNCTION(x)	.globl EXT_C(x) ; .type EXT_C(x), @function ; EXT_C(x):
 #define VARIABLE(x)	.globl EXT_C(x) ; .type EXT_C(x), @object ; EXT_C(x):

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to