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