Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / include / amd64-main.h
CommitLineData
7f918cf1
CE
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 */
14PRIVATE Word64 applyFFTempFun;
15PRIVATE Word64 applyFFTempStackArg;
16PRIVATE Word64 applyFFTempRegArg[6];
17PRIVATE Real32 applyFFTempXmmsRegArgD[8];
18PRIVATE Real64 applyFFTempXmmsRegArgS[8];
19PRIVATE Word32 checkTemp;
20PRIVATE Word64 cReturnTemp[16];
21PRIVATE Pointer c_stackP;
22PRIVATE Word64 fpcvtTemp;
23PRIVATE Word32 fpeqTemp;
24PRIVATE Word64 divTemp;
25PRIVATE Word64 indexTemp;
26PRIVATE Word64 raTemp1;
27PRIVATE Word64 spill[32];
28PRIVATE Word64 stackTopTemp;
29
30#ifndef DEBUG_AMD64CODEGEN
31#define DEBUG_AMD64CODEGEN FALSE
32#endif
33
34static GC_frameIndex returnAddressToFrameIndex (GC_returnAddress ra) {
35 return *((GC_frameIndex*)(ra - sizeof(GC_frameIndex)));
36}
37
38#define MLtonCallFromC \
39PRIVATE void MLton_jumpToSML (pointer jump); \
40static 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) \
66MLtonCallFromC \
67PUBLIC 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) \
83MLtonCallFromC \
84PUBLIC 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} \
97PUBLIC 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_ */