chiark / gitweb /
base/asm-common.h, *.S: Include metadata for 64-bit Windows stack unwinding.
[catacomb] / base / asm-common.h
index bf42e4fe0d860931aa15e5f5e8459f6f164c8825..0d32ccf90952bd5272236a75d4e12bf214078b85 100644 (file)
@@ -33,6 +33,7 @@
 // Literal pools done the hard way.
 #define _LIT .text .L$_subsec + 1
 #define _ENDLIT .text .L$_subsec
+#define _LTORG .L$_subsec = .L$_subsec + 2; .text .L$_subsec
 
 // Announcing an external function.
 #define FUNC(name)                                                     \
@@ -48,8 +49,20 @@ F(name):                                                             \
        .purgem ENDFUNC;                                                \
        SIZE_OBJ(name);                                                 \
        ENDFUNC_HOOK(name);                                             \
-       .L$_subsec = .L$_subsec + 2;                                    \
-       .text .L$_subsec
+       _LTORG
+
+// Make a helper function, if necessary.
+#define AUXFN(name)                                                    \
+  .ifndef .L$_auxfn_def.name;                                          \
+       .text 7128;                                                     \
+       .macro _ENDAUXFN; _ENDAUXFN_TAIL(name); .endm;                  \
+       FUNC_PREHOOK(name);                                             \
+name:
+#define _ENDAUXFN_TAIL(name)                                           \
+       .purgem _ENDAUXFN;                                              \
+       .text .L$_subsec;                                               \
+       .L$_auxfn_def.name = 1
+#define ENDAUXFN _ENDAUXFN; .endif
 
 ///--------------------------------------------------------------------------
 /// ELF-specific hacking.
@@ -87,6 +100,14 @@ F(name):                                                            \
 // Set the function hooks.
 #define FUNC_PREHOOK(_) .balign 16
 
+// On Windows, arrange to install stack-unwinding data.
+#if CPUFAM_AMD64 && ABI_WIN
+#  define FUNC_POSTHOOK(name) .seh_proc name
+#  define ENDFUNC_HOOK(_) .seh_endproc
+// Procedures are expected to invoke `.seh_setframe' if necessary, and
+// `.seh_pushreg' and friends, and `.seh_endprologue'.
+#endif
+
 // Don't use the wretched AT&T syntax.  It's festooned with pointless
 // punctuation, and all of the data movement is backwards.  Ugh!
        .intel_syntax noprefix
@@ -109,18 +130,12 @@ F(name):                                                          \
 // Maybe load GOT address into GOT.
 .macro ldgot got=GOTREG
 #if WANT_PIC && CPUFAM_X86
-       call    _where_am_i.\got
-       add     \got, offset _GLOBAL_OFFSET_TABLE_
-#endif
-.endm
-
-// Maybe build a helper subroutine for `ldgot GOT'.
-.macro gotaux got=GOTREG
-#if WANT_PIC && CPUFAM_X86
-       .align  16
-_where_am_i.\got :
+  AUXFN(_ldgot.\got)
        mov     \got, [esp]
        ret
+  ENDAUXFN
+       call    _ldgot.\got
+       add     \got, offset _GLOBAL_OFFSET_TABLE_
 #endif
 .endm