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