[project @ 1998-11-26 09:17:22 by sof]
[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 #if 1 /* ndef CONCURRENT */ /* HWL */
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) = PrelBase_Z91Z93_closure;
39         STKO_RETURN(MainStkO) = NULL;
40
41         ASSERT(sanityChk_StkO(MainStkO));
42
43         if (RTSflags.GcFlags.trace)
44             fprintf(stderr, "STACK init: botA, spa: 0x%lx, 0x%lx\n            botB, spb: 0x%lx, 0x%lx\n",
45               (W_) STKO_ASTK_BOT(MainStkO), (W_) STKO_SpA(MainStkO), (W_) STKO_BSTK_BOT(MainStkO), (W_) STKO_SpB(MainStkO));
46 #endif
47     }
48
49 # if STACK_CHECK_BY_PAGE_FAULT
50     unmapMiddleStackPage((char *) stks_space, RTSflags.GcFlags.stksSize * sizeof(W_));
51 # endif
52
53     /* Initialise Stack Info and pointers */
54 #if 1 /* ndef CONCURRENT */ /* HWL */
55     stackInfo.botA = STK_A_FRAME_BASE(stks_space, RTSflags.GcFlags.stksSize);
56     stackInfo.botB = STK_B_FRAME_BASE(stks_space, RTSflags.GcFlags.stksSize);
57
58     MAIN_SuA = MAIN_SpA = stackInfo.botA + AREL(1);
59     MAIN_SuB = MAIN_SpB = stackInfo.botB + BREL(1);
60
61     if (RTSflags.GcFlags.trace)
62         fprintf(stderr, "STACK init: botA, spa: 0x%lx, 0x%lx\n            botB, spb: 0x%lx, 0x%lx\n",
63           (W_) stackInfo.botA, (W_) MAIN_SpA, (W_) stackInfo.botB, (W_) MAIN_SpB);
64 #endif /* !CONCURRENT */
65
66     return rtsTrue;
67 }
68
69 #endif /* not parallel */
70 \end{code}