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/trunk/src/runtime/kernel/ml-state.c
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (view) (download) (as text)
Original Path: sml/branches/SMLNJ/src/runtime/kernel/ml-state.c

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

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