chiark / gitweb /
base/asm-common.h: Introduce bad literal-pool handling macros.
[catacomb] / base / asm-common.h
index 8745ea43cd02a136f43fbe3c5c43c78228daecae..aa6b4c3e40696794d60b255bb1a110c4158d7b49 100644 (file)
 ///--------------------------------------------------------------------------
 /// General definitions.
 
+// Some useful variables.
+       .L$_subsec = 0
+
+// Literal pools done the hard way.
+#define _LIT .text .L$_subsec + 1
+#define _ENDLIT .text .L$_subsec
+
 // Announcing an external function.
 #define FUNC(name)                                                     \
        .globl  F(name);                                                \
@@ -40,7 +47,9 @@ F(name):                                                              \
 #define _ENDFUNC(name)                                                 \
        .purgem ENDFUNC;                                                \
        SIZE_OBJ(name);                                                 \
-       ENDFUNC_HOOK(name)
+       ENDFUNC_HOOK(name);                                             \
+       .L$_subsec = .L$_subsec + 2;                                    \
+       .text .L$_subsec
 
 ///--------------------------------------------------------------------------
 /// ELF-specific hacking.
@@ -148,6 +157,50 @@ _where_am_i.\got :
 
 #endif
 
+///--------------------------------------------------------------------------
+/// ARM-specific hacking.
+
+#if CPUFAM_ARM
+
+// Set the function hooks.
+#define FUNC_PREHOOK(_) .balign 4
+#define ENDFUNC_HOOK(name) .ltorg
+
+// Call external subroutine at ADDR, possibly via PLT.
+       .macro  callext addr, cond=
+#if WANT_PIC
+       bl\cond \addr(PLT)
+#else
+       bl\cond \addr
+#endif
+       .endm
+
+// Do I need to arrange a spare GOT register?
+#if WANT_PIC
+#  define NEED_GOT 1
+#endif
+#define GOTREG r9
+
+// Maybe load GOT address into GOT.
+       .macro  ldgot   cond=, got=GOTREG
+#if WANT_PIC
+       ldr\cond \got, =_GLOBAL_OFFSET_TABLE_ - . - 12
+       add\cond \got, pc, \got
+#endif
+       .endm
+
+// Load address of external symbol ADDR into REG, maybe using GOT.
+       .macro  leaext  reg, addr, cond=, got=GOTREG
+#if WANT_PIC
+       ldr\cond \reg, =\addr(GOT)
+       ldr\cond \reg, [\got, \reg]
+#else
+       ldr\cond \reg, =\addr
+#endif
+       .endm
+
+#endif
+
 ///--------------------------------------------------------------------------
 /// Final stuff.