[project @ 1996-01-11 14:06:51 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 rtsBool
20 initStacks(smInfo *sm)
21 {
22     /*
23      * Allocate them if they don't exist. One space does for both stacks, since they
24      * grow towards each other
25      */
26     if (stks_space == 0) {
27 #ifndef CONCURRENT
28         stks_space = (P_) stgMallocWords(RTSflags.GcFlags.stksSize, "initStacks");
29 #else
30         MainStkO = (P_) stgMallocWords(STKO_HS + RTSflags.GcFlags.stksSize, "initStacks");
31         stks_space = MainStkO + STKO_HS;
32         SET_STKO_HDR(MainStkO, StkO_static_info, CC_SUBSUMED);
33         STKO_SIZE(MainStkO) = RTSflags.GcFlags.stksSize + STKO_VHS;
34         STKO_SpB(MainStkO) = STKO_SuB(MainStkO) = STKO_BSTK_BOT(MainStkO) + BREL(1);
35         STKO_SpA(MainStkO) = STKO_SuA(MainStkO) = STKO_ASTK_BOT(MainStkO) + AREL(1);
36         STKO_LINK(MainStkO) = Nil_closure;
37         STKO_RETURN(MainStkO) = NULL;
38
39         ASSERT(sanityChk_StkO(MainStkO));
40 #endif
41     }
42
43 # if STACK_CHECK_BY_PAGE_FAULT
44     unmapMiddleStackPage((char *) stks_space, RTSflags.GcFlags.stksSize * sizeof(W_));
45 # endif
46
47     /* Initialise Stack Info and pointers */
48     stackInfo.botA = STK_A_FRAME_BASE(stks_space, RTSflags.GcFlags.stksSize);
49     stackInfo.botB = STK_B_FRAME_BASE(stks_space, RTSflags.GcFlags.stksSize);
50
51     MAIN_SuA = MAIN_SpA = stackInfo.botA + AREL(1);
52     MAIN_SuB = MAIN_SpB = stackInfo.botB + BREL(1);
53
54     if (RTSflags.GcFlags.trace)
55         fprintf(stderr, "STACK init: botA, spa: 0x%lx, 0x%lx\n            botB, spb: 0x%lx, 0x%lx\n",
56           (W_) stackInfo.botA, (W_) MAIN_SpA, (W_) stackInfo.botB, (W_) MAIN_SpB);
57
58     return rtsTrue;
59 }
60
61 #endif /* not parallel */
62 \end{code}