Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / include / amd64-main.h
1 /* Copyright (C) 2000-2007 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 *
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
6 */
7
8 #ifndef _AMD64_MAIN_H_
9 #define _AMD64_MAIN_H_
10
11 #include "common-main.h"
12
13 /* Globals */
14 PRIVATE Word64 applyFFTempFun;
15 PRIVATE Word64 applyFFTempStackArg;
16 PRIVATE Word64 applyFFTempRegArg[6];
17 PRIVATE Real32 applyFFTempXmmsRegArgD[8];
18 PRIVATE Real64 applyFFTempXmmsRegArgS[8];
19 PRIVATE Word32 checkTemp;
20 PRIVATE Word64 cReturnTemp[16];
21 PRIVATE Pointer c_stackP;
22 PRIVATE Word64 fpcvtTemp;
23 PRIVATE Word32 fpeqTemp;
24 PRIVATE Word64 divTemp;
25 PRIVATE Word64 indexTemp;
26 PRIVATE Word64 raTemp1;
27 PRIVATE Word64 spill[32];
28 PRIVATE Word64 stackTopTemp;
29
30 #ifndef DEBUG_AMD64CODEGEN
31 #define DEBUG_AMD64CODEGEN FALSE
32 #endif
33
34 static GC_frameIndex returnAddressToFrameIndex (GC_returnAddress ra) {
35 return *((GC_frameIndex*)(ra - sizeof(GC_frameIndex)));
36 }
37
38 #define MLtonCallFromC \
39 PRIVATE void MLton_jumpToSML (pointer jump); \
40 static void MLton_callFromC () { \
41 pointer jump; \
42 GC_state s; \
43 \
44 if (DEBUG_AMD64CODEGEN) \
45 fprintf (stderr, "MLton_callFromC() starting\n"); \
46 s = &gcState; \
47 GC_setSavedThread (s, GC_getCurrentThread (s)); \
48 s->atomicState += 3; \
49 if (s->signalsInfo.signalIsPending) \
50 s->limit = s->limitPlusSlop - GC_HEAP_LIMIT_SLOP; \
51 /* Return to the C Handler thread. */ \
52 GC_switchToThread (s, GC_getCallFromCHandlerThread (s), 0); \
53 jump = *(pointer*)(s->stackTop - GC_RETURNADDRESS_SIZE); \
54 MLton_jumpToSML(jump); \
55 s->atomicState += 1; \
56 GC_switchToThread (s, GC_getSavedThread (s), 0); \
57 s->atomicState -= 1; \
58 if (0 == s->atomicState && s->signalsInfo.signalIsPending) \
59 s->limit = 0; \
60 if (DEBUG_AMD64CODEGEN) \
61 fprintf (stderr, "MLton_callFromC() done\n"); \
62 return; \
63 }
64
65 #define MLtonMain(al, mg, mfs, mmc, pk, ps, ml) \
66 MLtonCallFromC \
67 PUBLIC int MLton_main (int argc, char* argv[]) { \
68 pointer jump; \
69 extern pointer ml; \
70 \
71 Initialize (al, mg, mfs, mmc, pk, ps); \
72 if (gcState.amOriginal) { \
73 real_Init(); \
74 jump = (pointer)&ml; \
75 } else { \
76 jump = *(pointer*)(gcState.stackTop - GC_RETURNADDRESS_SIZE); \
77 } \
78 MLton_jumpToSML(jump); \
79 return 1; \
80 }
81
82 #define MLtonLibrary(al, mg, mfs, mmc, pk, ps, ml) \
83 MLtonCallFromC \
84 PUBLIC void LIB_OPEN(LIBNAME) (int argc, char* argv[]) { \
85 pointer jump; \
86 extern pointer ml; \
87 \
88 Initialize (al, mg, mfs, mmc, pk, ps); \
89 if (gcState.amOriginal) { \
90 real_Init(); \
91 jump = (pointer)&ml; \
92 } else { \
93 jump = *(pointer*)(gcState.stackTop - GC_RETURNADDRESS_SIZE); \
94 } \
95 MLton_jumpToSML(jump); \
96 } \
97 PUBLIC void LIB_CLOSE(LIBNAME) () { \
98 pointer jump; \
99 jump = *(pointer*)(gcState.stackTop - GC_RETURNADDRESS_SIZE); \
100 MLton_jumpToSML(jump); \
101 GC_done(&gcState); \
102 }
103
104 #endif /* #ifndef _AMD64_MAIN_H_ */