1 /* -----------------------------------------------------------------------------
2 * $Id: StgRun.S,v 1.4 1999/12/01 14:21:02 simonmar Exp $
4 * Tiny assembler 'layer' between the C and STG worlds.
6 * To run an STG function from C land, call
8 * rv = StgRun(f,BaseReg);
10 * where "f" is the STG function to call, and BaseReg is the address of the
11 * RegTable for this run (we might have separate RegTables if we're running
12 * multiple threads on an SMP machine).
14 * In the end, "f" must JMP to StgReturn (defined below),
15 * passing the return-value "rv" in R1,
16 * to return to the caller of StgRun returning "rv" in
17 * the whatever way C returns a value.
19 * NOTE: StgRun/StgReturn do *NOT* load or store Hp or any
20 * other registers (other than saving the C callee-saves
21 * registers). Instead, the called function "f" must do that
23 * -------------------------------------------------------------------------- */
26 #include "Constants.h"
28 #ifndef USE_MINIINTERPRETER
31 * GCC will have assumed that pushing/popping of C-stack frames is
32 * going on when it generated its code, and used stack space
33 * accordingly. However, we actually {\em post-process away} all
34 * such stack-framery (see \tr{ghc/driver/ghc-asm.lprl}). Things will
35 * be OK however, if we initially make sure there are
36 * @RESERVED_C_STACK_BYTES@ on the C-stack to begin with, for local
40 /* -----------------------------------------------------------------------------
42 -------------------------------------------------------------------------- */
49 #ifdef LEADING_UNDERSCORE
56 pushl %ebp /* standard frame-pointer stuff */
60 * leave a giant chunk of C-stack for temporaries in the STG world.
62 subl $RESERVED_C_STACK_BYTES + 4*SIZEOF_LONG,%esp
65 * save callee-saves registers on behalf of the STG code.
67 leal RESERVED_C_STACK_BYTES(%esp),%eax
79 * grab the function argument from the stack, and jump to it.
86 #ifdef LEADING_UNDERSCORE
93 movl %esi,%eax /* Return value in R1 */
96 * restore callee-saves registers. (Don't stomp on %eax!)
98 leal RESERVED_C_STACK_BYTES(%esp),%edx
99 movl 0(%edx),%ebx /* restore the registers saved above */
104 movl %ebp, %esp /* restore the C stack state */
108 #endif /* i386_TARGET_ARCH */
110 #endif /* !USE_MINIINTERPRETER */