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