Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/branches/SMLNJ/src/runtime/kernel/ml-state.c
ViewVC logotype

Annotation of /sml/branches/SMLNJ/src/runtime/kernel/ml-state.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 106 - (view) (download) (as text)

1 : monnier 2 /* ml-state.c
2 :     *
3 :     * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.
4 :     *
5 :     */
6 :    
7 :     #include <stdarg.h>
8 :     #include "ml-base.h"
9 :     #include "vproc-state.h"
10 :     #include "ml-state.h"
11 :     #include "system-signals.h"
12 :     #include "tags.h"
13 :     #include "ml-values.h"
14 :     #include "ml-objects.h"
15 :     #include "ml-globals.h"
16 :     #include "gc.h"
17 :     #include "ml-timer.h"
18 :     #include "ml-limits.h"
19 :    
20 :    
21 :     vproc_state_t *VProc[MAX_NUM_PROCS];
22 :     int NumVProcs;
23 :    
24 :    
25 :     /* local routines */
26 :     PVT void InitVProcState (vproc_state_t *vsp);
27 :    
28 :    
29 :     /* This table maps the register numbers of the code generator to the proper
30 :     * indices of the root vector. The order of entries in this table must
31 :     * respect both the MLState vector layout and the order of the miscregs in
32 :     * the C-machine implementation. The pc, varptr, and exncont are not included.
33 :     */
34 :     int ArgRegMap[N_ARG_REGS] = {
35 :     LINK_INDX, CLOSURE_INDX, ARG_INDX, CONT_INDX, /* the standard arg registers */
36 :     #if defined(TARGET_SPARC)
37 :     /* misc. regs = %g2-%g3, %o1-%o2, %l0-%l7, %i4; */
38 :     8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
39 :     #elif defined(TARGET_M68)
40 :     5
41 :     #elif defined(TARGET_MIPS)
42 :     6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18
43 :     #elif defined(TARGET_HPPA)
44 :     MISC0_INDX, MISC1_INDX, MISC2_INDX, MISC3_INDX, MISC4_INDX,
45 :     MISC5_INDX, MISC6_INDX, MISC7_INDX, MISC8_INDX, MISC9_INDX,
46 : monnier 106 MISC10_INDX, MISC11_INDX, MISC12_INDX, MISC13_INDX, MISC14_INDX,
47 :     MISC15_INDX
48 : monnier 2 #elif defined(TARGET_ALPHA32)
49 :     MISC0_INDX,MISC1_INDX,MISC2_INDX,MISC3_INDX,MISC4_INDX,
50 :     MISC5_INDX,MISC6_INDX,MISC7_INDX,MISC8_INDX,MISC9_INDX,
51 :     MISC10_INDX,MISC11_INDX,MISC12_INDX,MISC13_INDX
52 :     #elif defined(TARGET_RS6000)
53 :     9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
54 :     #elif defined(TARGET_X86)
55 :     7, 8, 9,
56 :     /* virtual registers */
57 :     10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
58 :     #elif defined(TARGET_BYTECODE)
59 :     4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
60 :     #elif defined(TARGET_C)
61 :     /* this is really defunct */
62 :     6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
63 :     22, 23, 24, 25, 26
64 :     #else
65 :     # error ArgRegMap not defined for target architecture
66 :     #endif
67 :     };
68 :    
69 :    
70 :     /* AllocMLState:
71 :     */
72 :     ml_state_t *AllocMLState (bool_t isBoot, heap_params_t *heapParams)
73 :     {
74 :     ml_state_t *msp;
75 :     int i;
76 :    
77 :     #ifdef MP_SUPPORT
78 :     for (i = 0; i < MAX_NUM_PROCS; i++) {
79 :     if (((VProc[i] = NEW_OBJ(vproc_state_t)) == NIL(vproc_state_t *))
80 :     || ((msp = NEW_OBJ(ml_state_t)) == NIL(ml_state_t *))) {
81 :     Die ("unable to allocate ML state vectors");
82 :     }
83 :     VProc[i]->vp_state = msp;
84 :     }
85 :     msp = VProc[0]->vp_state;
86 :     #else
87 :     if (((VProc[0] = NEW_OBJ(vproc_state_t)) == NIL (vproc_state_t *))
88 :     || ((msp = NEW_OBJ(ml_state_t)) == NIL(ml_state_t *))) {
89 :     Die ("unable to allocate ML state vector");
90 :     }
91 :     VProc[0]->vp_state = msp;
92 :     #endif /* MP_SUPPORT */
93 :    
94 :     /* allocate and initialize the heap data structures */
95 :     InitHeap (msp, isBoot, heapParams);
96 :    
97 :     #ifdef MP_SUPPORT
98 :     /* partition the allocation arena given by InitHeap among the
99 :     * MAX_NUM_PROCS processors.
100 :     */
101 :     NumVProcs = MAX_NUM_PROCS;
102 :     PartitionAllocArena(VProc);
103 :     /* initialize the per-processor ML state */
104 :     for (i = 0; i < MAX_NUM_PROCS; i++) {
105 :     int j;
106 :    
107 :     InitVProcState (VProc[i]);
108 :     /* single timers are currently shared among multiple processors */
109 :     if (i != 0) {
110 :     VProc[i]->vp_gcTime0 = VProc[0]->vp_gcTime0;
111 :     VProc[i]->vp_gcTime = VProc[0]->vp_gcTime;
112 :     }
113 :     }
114 :     /* initialize the first processor here */
115 :     VProc[0]->vp_mpSelf = MP_ProcId ();
116 :     VProc[0]->vp_mpState = MP_PROC_RUNNING;
117 :     #else
118 :     InitVProcState (VProc[0]);
119 :     NumVProcs = 1;
120 :     #endif /* MP_SUPPORT */
121 :    
122 :     /* initialize the timers */
123 :     /** MP_SUPPORT note: for now, only proc 0 has timers **/
124 :     ResetTimers (VProc[0]);
125 :    
126 :     return msp;
127 :    
128 :     } /* end of AllocMLState */
129 :    
130 :     /* InitVProcState:
131 :     */
132 :     PVT void InitVProcState (vproc_state_t *vsp)
133 :     {
134 :     int i;
135 :    
136 :     vsp->vp_heap = vsp->vp_state->ml_heap;
137 :     vsp->vp_state->ml_vproc = vsp;
138 :     vsp->vp_inMLFlag = FALSE;
139 :     vsp->vp_handlerPending = FALSE;
140 :     vsp->vp_inSigHandler = FALSE;
141 :     vsp->vp_numPendingSysSigs = 0;
142 :     vsp->vp_numPendingSigs = 0;
143 :     vsp->vp_sigCode = 0;
144 :     vsp->vp_sigCount = 0;
145 :     vsp->vp_nextPendingSig = 0;
146 :     vsp->vp_numInQ = 0;
147 :     vsp->vp_gcSigState = ML_SIG_IGNORE;
148 :     vsp->vp_gcTime0 = NEW_OBJ(Time_t);
149 :     vsp->vp_gcTime = NEW_OBJ(Time_t);
150 :    
151 :     for (i = 0; i < NUM_SIGS; i++) {
152 :     vsp->vp_pendingSigQ[i].sigNum = 0;
153 :     vsp->vp_pendingSigQ[i].count = 0;
154 :     }
155 :    
156 :     /* initialize the ML state, including the roots */
157 :     InitMLState (vsp->vp_state);
158 :     for (i = 0; i < NROOTS; i++) {
159 :     vsp->vp_state->ml_roots[i] = ML_unit;
160 :     }
161 :    
162 :     #ifdef MP_SUPPORT
163 :     vsp->vp_mpSelf = 0;
164 :     vsp->vp_mpState = MP_PROC_NO_PROC;
165 :     #endif
166 :    
167 :     } /* end of InitVProcState */
168 :    
169 :     /* InitMLState:
170 :     *
171 :     * Initialize the ML State vector. Note that we do not initialize the root
172 :     * registers here, since this is sometimes called when the roots are live (from
173 :     * ML_ApplyFn).
174 :     */
175 :     void InitMLState (ml_state_t *msp)
176 :     {
177 :     int i;
178 :    
179 :     msp->ml_storePtr = ML_unit;
180 :     msp->ml_liveRegMask = 0;
181 :     #ifdef SOFT_POLL
182 :     msp->ml_pollPending = FALSE;
183 :     msp->ml_inPollHandler = FALSE;
184 :     #endif
185 :    
186 :     #ifdef N_PSEUDO_REGS
187 :     for (i = 0; i < N_PSEUDO_REGS; i++)
188 :     msp->ml_pseudoRegs[i] = ML_unit;
189 :     #endif
190 :    
191 :     } /* end of InitMLState. */
192 :    
193 :     /* SaveCState:
194 :     *
195 :     * Build a return closure that will save a collection of ML values
196 :     * being used by C. The ML values are passed by reference, with NIL
197 :     * as termination.
198 :     */
199 :     void SaveCState (ml_state_t *msp, ...)
200 :     {
201 :     va_list ap;
202 :     int n, i;
203 :     ml_val_t *vp;
204 :     extern ml_val_t return_a[];
205 :    
206 :     va_start (ap, msp);
207 :     for (n = 0; (vp = va_arg(ap, ml_val_t *)) != NIL(ml_val_t *); n++)
208 :     continue;
209 :     va_end (ap);
210 :    
211 :     va_start (ap, msp);
212 :     #if (CALLEESAVE > 0)
213 :     ML_AllocWrite (msp, 0, MAKE_DESC(n, DTAG_record));
214 :     i = 1;
215 :     #else
216 :     n++;
217 :     ML_AllocWrite (msp, 0, MAKE_DESC(n, DTAG_record));
218 :     ML_AllocWrite (msp, 1, PTR_CtoML(return_a));
219 :     i = 2;
220 :     #endif
221 :     for (; i <= n; i++) {
222 :     vp = va_arg (ap, ml_val_t *);
223 :     ML_AllocWrite (msp, i, *vp);
224 :     }
225 :     #if (CALLEESAVE > 0)
226 :     msp->ml_calleeSave(0) = ML_Alloc(msp, n);
227 :     msp->ml_cont = PTR_CtoML(return_c);
228 :     #else
229 :     msp->ml_cont = ML_Alloc(msp, n);
230 :     #endif
231 :     va_end (ap);
232 :    
233 :     } /* end of SaveCState */
234 :    
235 :     /* RestoreCState:
236 :     *
237 :     * Restore a collection of ML values from the return closure.
238 :     */
239 :     void RestoreCState (ml_state_t *msp, ...)
240 :     {
241 :     va_list ap;
242 :     int n, i;
243 :     ml_val_t *vp;
244 :     ml_val_t savedState;
245 :    
246 :     va_start (ap, msp);
247 :     #if (CALLEESAVE > 0)
248 :     savedState = msp->ml_calleeSave(0);
249 :     i = 0;
250 :     #else
251 :     savedState = msp->ml_cont;
252 :     i = 1;
253 :     #endif
254 :     n = OBJ_LEN(savedState);
255 :     for (; i < n; i++) {
256 :     vp = va_arg (ap, ml_val_t *);
257 :     *vp = REC_SEL(savedState, i);
258 :     }
259 :     va_end (ap);
260 :    
261 :     } /* end of RestoreCState */
262 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0