From cd24e113c38e81c15a72536a99062373d5701389 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Wed, 13 Feb 2013 21:21:39 -0800 Subject: arm: Introduce and use LDST_PCREL Macro-ising the few instances where we need to distinguish between arm and thumb pc-relative memory operations. --- ports/sysdeps/arm/sysdep.h | 17 +++++++++++++++++ ports/sysdeps/unix/arm/sysdep.S | 22 ++++++++++++---------- .../unix/sysv/linux/arm/nptl/sysdep-cancel.h | 10 ++-------- ports/sysdeps/unix/sysv/linux/arm/sysdep.h | 10 ++++------ 4 files changed, 35 insertions(+), 24 deletions(-) (limited to 'ports/sysdeps') diff --git a/ports/sysdeps/arm/sysdep.h b/ports/sysdeps/arm/sysdep.h index 4af7429ac9..29a78f043d 100644 --- a/ports/sysdeps/arm/sysdep.h +++ b/ports/sysdeps/arm/sysdep.h @@ -117,6 +117,23 @@ the caller. */ .eabi_attribute 24, 1 +/* Load or store to/from a pc-relative EXPR into/from R, using T. */ +# ifdef __thumb2__ +# define LDST_PCREL(OP, R, T, EXPR) \ + ldr T, 98f; \ + .subsection 2; \ +98: .word EXPR - 99f - PC_OFS; \ + .previous; \ +99: add T, T, pc; \ + OP R, [T] +# else +# define LDST_PCREL(OP, R, T, EXPR) \ + ldr T, 98f; \ + .subsection 2; \ +98: .word EXPR - 99f - PC_OFS; \ + .previous; \ +99: OP R, [pc, T] +# endif #endif /* __ASSEMBLER__ */ /* This number is the offset from the pc at the current location. */ diff --git a/ports/sysdeps/unix/arm/sysdep.S b/ports/sysdeps/unix/arm/sysdep.S index 40e4d80eca..d44ee4869a 100644 --- a/ports/sysdeps/unix/arm/sysdep.S +++ b/ports/sysdeps/unix/arm/sysdep.S @@ -45,20 +45,22 @@ __syscall_error: mov lr, pc sub pc, r0, #31 - ldr r2, 1f -2: ldr r2, [pc, r2] - str r1, [r0, r2] - mvn r0, #0 - RETINSTR (, ip) + ldr r2, 1f +#ifdef __thumb__ +2: add r2, r2, pc + ldr r2, [r2] +#else +2: ldr r2, [pc, r2] +#endif + str r1, [r0, r2] + mvn r0, #0 + DO_RET(ip) 1: .word errno(gottpoff) + (. - 2b - PC_OFS) #elif RTLD_PRIVATE_ERRNO - ldr r1, 1f -0: str r0, [pc, r1] - mvn r0, $0 + LDST_PCREL(str, r0, r1, C_SYMBOL_NAME(rtld_errno)) + mvn r0, #0 DO_RET(r14) - -1: .word C_SYMBOL_NAME(rtld_errno) - 0b - PC_OFS #else #error "Unsupported non-TLS case" #endif diff --git a/ports/sysdeps/unix/sysv/linux/arm/nptl/sysdep-cancel.h b/ports/sysdeps/unix/sysv/linux/arm/nptl/sysdep-cancel.h index df85d51995..8889369ae3 100644 --- a/ports/sysdeps/unix/sysv/linux/arm/nptl/sysdep-cancel.h +++ b/ports/sysdeps/unix/sysv/linux/arm/nptl/sysdep-cancel.h @@ -31,7 +31,6 @@ # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ .text; \ - PSEUDO_PROLOGUE; \ ENTRY (__##syscall_name##_nocancel); \ CFI_SECTIONS; \ DO_CALL (syscall_name, args); \ @@ -203,12 +202,8 @@ extern int __local_multiple_threads attribute_hidden; # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1) # else # define SINGLE_THREAD_P \ - ldr ip, 1b; \ - 2: \ - ldr ip, [pc, ip]; \ - teq ip, #0; -# define PSEUDO_PROLOGUE \ - 1: .word __local_multiple_threads - 2f - PC_OFS; + LDST_PCREL(ldr, ip, ip, __local_multiple_threads); \ + teq ip, #0 # endif # else /* There is no __local_multiple_threads for librt, so use the TCB. */ @@ -217,7 +212,6 @@ extern int __local_multiple_threads attribute_hidden; __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ header.multiple_threads) == 0, 1) # else -# define PSEUDO_PROLOGUE # define SINGLE_THREAD_P \ stmfd sp!, {r0, lr}; \ cfi_adjust_cfa_offset (8); \ diff --git a/ports/sysdeps/unix/sysv/linux/arm/sysdep.h b/ports/sysdeps/unix/sysv/linux/arm/sysdep.h index f40cb95e87..89208a9f19 100644 --- a/ports/sysdeps/unix/sysv/linux/arm/sysdep.h +++ b/ports/sysdeps/unix/sysv/linux/arm/sysdep.h @@ -110,12 +110,10 @@ # if RTLD_PRIVATE_ERRNO # define SYSCALL_ERROR_HANDLER \ __local_syscall_error: \ - ldr r1, 1f; \ - rsb r0, r0, #0; \ -0: str r0, [pc, r1]; \ - mvn r0, #0; \ - DO_RET(lr); \ -1: .word C_SYMBOL_NAME(rtld_errno) - 0b - PC_OFS; + rsb r0, r0, #0; \ + LDST_PCREL(str, r0, r1, C_SYMBOL_NAME(rtld_errno)); \ + mvn r0, #0; \ + DO_RET(lr) # else # if defined(__ARM_ARCH_4T__) && defined(__THUMB_INTERWORK__) # define POP_PC \ -- cgit v1.2.3