[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / runtime / storage / SMstacks.lc
1 \section[SMstacks.lc]{Stack allocation (sequential)}
2
3 Routine that allocates the A and B stack (sequential only).
4
5 \begin{code}
6 #ifndef PAR
7 # define NULL_REG_MAP
8 # include "SMinternal.h"
9
10 stackData stackInfo;
11
12 P_ stks_space = 0;
13
14 #ifdef CONCURRENT
15 EXTDATA_RO(StkO_static_info);
16 P_ MainStkO;
17 #endif
18
19 I_
20 initStacks(sm)
21 smInfo *sm;
22 {
23     /*
24      * Allocate them if they don't exist. One space does for both stacks, since they
25      * grow towards each other
26      */
27     if (stks_space == 0) {
28 #ifdef CONCURRENT
29         MainStkO = (P_) xmalloc((STKO_HS + SM_word_stk_size) * sizeof(W_));
30         stks_space = MainStkO + STKO_HS;
31         SET_STKO_HDR(MainStkO, StkO_static_info, CC_SUBSUMED);
32         STKO_SIZE(MainStkO) = SM_word_stk_size + STKO_VHS;
33         STKO_LINK(MainStkO) = Nil_closure;
34         STKO_RETURN(MainStkO) = NULL;
35 #else
36         stks_space = (P_) xmalloc(SM_word_stk_size * sizeof(W_));
37 #endif
38     }
39 # if STACK_CHECK_BY_PAGE_FAULT
40     unmapMiddleStackPage((char *) stks_space, SM_word_stk_size * sizeof(W_));
41 # endif
42
43     /* Initialise Stack Info and pointers */
44     stackInfo.botA = STK_A_FRAME_BASE(stks_space, SM_word_stk_size);
45     stackInfo.botB = STK_B_FRAME_BASE(stks_space, SM_word_stk_size);
46
47     MAIN_SuA = MAIN_SpA = stackInfo.botA + AREL(1);
48     MAIN_SuB = MAIN_SpB = stackInfo.botB + BREL(1);
49
50     if (SM_trace)
51         fprintf(stderr, "STACK init: botA, spa: 0x%lx, 0x%lx\n            botB, spb: 0x%lx, 0x%lx\n",
52           (W_) stackInfo.botA, (W_) MAIN_SpA, (W_) stackInfo.botB, (W_) MAIN_SpB);
53
54     return 0;
55 }
56 #endif /* not parallel */
57 \end{code}