Debian Codegraph @

include/amd64-main.h

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