1 /* -----------------------------------------------------------------------------
2 * $Id: StgRun.S,v 1.2 1998/12/15 09:41:57 simonm Exp $
4 * Tiny assembler 'layer' between the C and STG worlds.
6 * To run an STG function from C land, call
10 * where "f" is the STG function to call.
12 * In the end, "f" must JMP to StgReturn (defined below),
13 * passing the return-value "rv" in R1,
14 * to return to the caller of StgRun returning "rv" in
15 * the whatever way C returns a value.
17 * NOTE: StgRun/StgReturn do *NOT* load or store Hp or any
18 * other registers (other than saving the C callee-saves
19 * registers). Instead, the called function "f" must do that
21 * -------------------------------------------------------------------------- */
24 #include "Constants.h"
26 #ifndef USE_MINIINTERPRETER
29 * GCC will have assumed that pushing/popping of C-stack frames is
30 * going on when it generated its code, and used stack space
31 * accordingly. However, we actually {\em post-process away} all
32 * such stack-framery (see \tr{ghc/driver/ghc-asm.lprl}). Things will
33 * be OK however, if we initially make sure there are
34 * @RESERVED_C_STACK_BYTES@ on the C-stack to begin with, for local
38 /* -----------------------------------------------------------------------------
40 -------------------------------------------------------------------------- */
47 #ifdef LEADING_UNDERSCORE
54 pushl %ebp /* standard frame-pointer stuff */
58 * leave a giant chunk of C-stack for temporaries in the STG world.
60 subl $RESERVED_C_STACK_BYTES + 4*SIZEOF_LONG,%esp
63 * save callee-saves registers on behalf of the STG code.
65 leal RESERVED_C_STACK_BYTES(%esp),%eax
72 * grab the function argument from the stack, and jump to it.
79 #ifdef LEADING_UNDERSCORE
86 movl %esi,%eax /* Return value in R1 */
89 * restore callee-saves registers. (Don't stomp on %eax!)
91 leal RESERVED_C_STACK_BYTES(%esp),%edx
92 movl 0(%edx),%ebx /* restore the registers saved above */
97 movl %ebp, %esp /* restore the C stack state */
101 #endif /* i386_TARGET_ARCH */
103 /* -----------------------------------------------------------------------------
105 -------------------------------------------------------------------------- */
107 /* -----------------------------------------------------------------------------
108 hppa1.1-hp-hpux architecture
109 -------------------------------------------------------------------------- */
111 /* -----------------------------------------------------------------------------
113 -------------------------------------------------------------------------- */
115 #endif /* !USE_MINIINTERPRETER */