1 /* -----------------------------------------------------------------------------
2 * $Id: StgCRun.c,v 1.3 1999/02/05 16:02:57 simonm Exp $
4 * (c) The GHC Team, 1998-1999
6 * STG-to-C glue. Some architectures have this code written in
7 * straight assembler (see StgRun.S), some in C.
9 * -------------------------------------------------------------------------- */
11 /* include Stg.h first because we want real machine regs in here: we
12 * have to get the value of R1 back from Stg land to C land intact.
24 #ifdef USE_MINIINTERPRETER
26 /* -----------------------------------------------------------------------------
27 any architecture (using miniinterpreter)
28 -------------------------------------------------------------------------- */
30 /* The static @jmp_environment@ variable allows @miniInterpret@ to
31 * communicate with @StgReturn@.
33 * Because @StgRun@ may be used recursively, we carefully
34 * save and restore the whole of @jmp_environment@.
37 #include <string.h> /* for memcpy */
39 static jmp_buf jmp_environment;
41 extern StgThreadReturnCode StgRun(StgFunPtr f)
44 /* Save jmp_environment for previous call to miniInterpret */
45 memcpy((void *) jmp_environment, (void *) save_buf, sizeof(jmp_buf));
46 if (setjmp(jmp_environment) == 0) {
49 fprintf(stderr,"Jumping to ");
53 f = (StgFunPtr) (f)();
56 /* Restore jmp_environment for previous call */
57 memcpy((void*) save_buf, (void*) jmp_environment, sizeof(jmp_buf));
59 return (StgThreadReturnCode)R1.i;
64 longjmp(jmp_environment, 1);
67 #else /* !USE_MINIINTERPRETER */
69 #ifdef LEADING_UNDERSCORE
70 #define STG_RETURN "_StgReturn"
72 #define STG_RETURN "StgReturn"
75 /* -----------------------------------------------------------------------------
77 -------------------------------------------------------------------------- */
79 #ifdef sparc_TARGET_ARCH
84 StgChar space[RESERVED_C_STACK_BYTES+sizeof(void *)];
85 register void *i7 __asm__("%i7");
86 ((void **)(space))[100] = i7;
88 __asm__ volatile (".align 4\n"
89 ".global " STG_RETURN "\n"
91 "\tld %1,%0" : "=r" (i7) : "m" (((void **)(space))[100]));
92 return (StgThreadReturnCode)R1.i;
97 /* -----------------------------------------------------------------------------
99 -------------------------------------------------------------------------- */
101 #ifdef alpha_TARGET_ARCH
106 __asm__ volatile ("stq $9,-8($30)\n\t"
107 "stq $10,-16($30)\n\t"
108 "stq $11,-24($30)\n\t"
109 "stq $12,-32($30)\n\t"
110 "stq $13,-40($30)\n\t"
111 "stq $14,-48($30)\n\t"
112 "stq $15,-56($30)\n\t"
113 "stt $f2,-64($30)\n\t"
114 "stt $f3,-72($30)\n\t"
115 "stt $f4,-80($30)\n\t"
116 "stt $f5,-88($30)\n\t"
117 "stt $f6,-96($30)\n\t"
118 "stt $f7,-104($30)\n\t"
119 "stt $f8,-112($30)\n\t"
120 "stt $f9,-120($30)\n\t"
121 "lda $30,-%0($30)" : :
122 "K" (RESERVED_C_STACK_BYTES+
123 8*sizeof(double)+8*sizeof(long)));
127 __asm__ volatile (".align 3\n"
128 ".globl " STG_RETURN "\n"
130 "lda $30,%0($30)\n\t"
132 "ldq $10,-16($30)\n\t"
133 "ldq $11,-24($30)\n\t"
134 "ldq $12,-32($30)\n\t"
135 "ldq $13,-40($30)\n\t"
136 "ldq $14,-48($30)\n\t"
137 "ldq $15,-56($30)\n\t"
138 "ldt $f2,-64($30)\n\t"
139 "ldt $f3,-72($30)\n\t"
140 "ldt $f4,-80($30)\n\t"
141 "ldt $f5,-88($30)\n\t"
142 "ldt $f6,-96($30)\n\t"
143 "ldt $f7,-104($30)\n\t"
144 "ldt $f8,-112($30)\n\t"
145 "ldt $f9,-120($30)" : :
146 "K" (RESERVED_C_STACK_BYTES+
147 8*sizeof(double)+8*sizeof(long)));
149 return (StgThreadReturnCode)R1.i;
152 #endif /* sparc_TARGET_ARCH */
154 #endif /* !USE_MINIINTERPRETER */