Merge branch 'master' of darcs.haskell.org:/srv/darcs//ghc
[ghc.git] / rts / StgMiscClosures.cmm
1 /* ----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Entry code for various built-in closure types.
6  *
7  * This file is written in a subset of C--, extended with various
8  * features specific to GHC.  It is compiled by GHC directly.  For the
9  * syntax of .cmm files, see the parser in ghc/compiler/cmm/CmmParse.y.
10  *
11  * --------------------------------------------------------------------------*/
12
13 #include "Cmm.h"
14
15 import pthread_mutex_lock;
16 import ghczmprim_GHCziTypes_Czh_static_info;
17 import ghczmprim_GHCziTypes_Izh_static_info;
18 import EnterCriticalSection;
19 import LeaveCriticalSection;
20
21 /* ----------------------------------------------------------------------------
22    Stack underflow
23    ------------------------------------------------------------------------- */
24
25 INFO_TABLE_RET (stg_stack_underflow_frame, UNDERFLOW_FRAME,
26                 W_ info_ptr, P_ unused)
27     /* no args => explicit stack */
28 {
29     W_ new_tso;
30     W_ ret_off;
31
32     SAVE_STGREGS
33
34     SAVE_THREAD_STATE();
35     ("ptr" ret_off) = foreign "C" threadStackUnderflow(MyCapability(),
36                                                        CurrentTSO);
37     LOAD_THREAD_STATE();
38
39     RESTORE_STGREGS
40
41     jump %ENTRY_CODE(Sp(ret_off)) [*]; // NB. all registers live!
42 }
43
44 /* ----------------------------------------------------------------------------
45    Restore a saved cost centre
46    ------------------------------------------------------------------------- */
47
48 INFO_TABLE_RET (stg_restore_cccs, RET_SMALL, W_ info_ptr, W_ cccs)
49 {
50 #if defined(PROFILING)
51     CCCS = Sp(1);
52 #endif
53     Sp_adj(2);
54     jump %ENTRY_CODE(Sp(0)) [*]; // NB. all registers live!
55 }
56
57 /* ----------------------------------------------------------------------------
58    Support for the bytecode interpreter.
59    ------------------------------------------------------------------------- */
60
61 /* 9 bits of return code for constructors created by the interpreter. */
62 stg_interp_constr_entry (P_ ret)
63 {
64     return (ret);
65 }
66
67 /* Some info tables to be used when compiled code returns a value to
68    the interpreter, i.e. the interpreter pushes one of these onto the
69    stack before entering a value.  What the code does is to
70    impedance-match the compiled return convention (in R1p/R1n/F1/D1 etc) to
71    the interpreter's convention (returned value is on top of stack),
72    and then cause the scheduler to enter the interpreter.
73
74    On entry, the stack (growing down) looks like this:
75
76       ptr to BCO holding return continuation
77       ptr to one of these info tables.
78
79    The info table code, both direct and vectored, must:
80       * push R1/F1/D1 on the stack, and its tag if necessary
81       * push the BCO (so it's now on the stack twice)
82       * Yield, ie, go to the scheduler.
83
84    Scheduler examines the t.o.s, discovers it is a BCO, and proceeds
85    directly to the bytecode interpreter.  That pops the top element
86    (the BCO, containing the return continuation), and interprets it.
87    Net result: return continuation gets interpreted, with the
88    following stack:
89
90       ptr to this BCO
91       ptr to the info table just jumped thru
92       return value
93
94    which is just what we want -- the "standard" return layout for the
95    interpreter.  Hurrah!
96
97    Don't ask me how unboxed tuple returns are supposed to work.  We
98    haven't got a good story about that yet.
99 */
100
101 INFO_TABLE_RET( stg_ctoi_R1p, RET_BCO)
102     /* explicit stack */
103 {
104     Sp_adj(-2);
105     Sp(1) = R1;
106     Sp(0) = stg_enter_info;
107     jump stg_yield_to_interpreter [];
108 }
109
110 /*
111  * When the returned value is a pointer, but unlifted, in R1 ...
112  */
113 INFO_TABLE_RET( stg_ctoi_R1unpt, RET_BCO )
114     /* explicit stack */
115 {
116     Sp_adj(-2);
117     Sp(1) = R1;
118     Sp(0) = stg_ret_p_info;
119     jump stg_yield_to_interpreter [];
120 }
121
122 /*
123  * When the returned value is a non-pointer in R1 ...
124  */
125 INFO_TABLE_RET( stg_ctoi_R1n, RET_BCO )
126     /* explicit stack */
127 {
128     Sp_adj(-2);
129     Sp(1) = R1;
130     Sp(0) = stg_ret_n_info;
131     jump stg_yield_to_interpreter [];
132 }
133
134 /*
135  * When the returned value is in F1
136  */
137 INFO_TABLE_RET( stg_ctoi_F1, RET_BCO )
138     /* explicit stack */
139 {
140     Sp_adj(-2);
141     F_[Sp + WDS(1)] = F1;
142     Sp(0) = stg_ret_f_info;
143     jump stg_yield_to_interpreter [];
144 }
145
146 /*
147  * When the returned value is in D1
148  */
149 INFO_TABLE_RET( stg_ctoi_D1, RET_BCO )
150     /* explicit stack */
151 {
152     Sp_adj(-1) - SIZEOF_DOUBLE;
153     D_[Sp + WDS(1)] = D1;
154     Sp(0) = stg_ret_d_info;
155     jump stg_yield_to_interpreter [];
156 }
157
158 /*
159  * When the returned value is in L1
160  */
161 INFO_TABLE_RET( stg_ctoi_L1, RET_BCO )
162     /* explicit stack */
163 {
164     Sp_adj(-1) - 8;
165     L_[Sp + WDS(1)] = L1;
166     Sp(0) = stg_ret_l_info;
167     jump stg_yield_to_interpreter [];
168 }
169
170 /*
171  * When the returned value is a void
172  */
173 INFO_TABLE_RET( stg_ctoi_V, RET_BCO )
174     /* explicit stack */
175 {
176     Sp_adj(-1);
177     Sp(0) = stg_ret_v_info;
178     jump stg_yield_to_interpreter [];
179 }
180
181 /*
182  * Dummy info table pushed on the top of the stack when the interpreter
183  * should apply the BCO on the stack to its arguments, also on the
184  * stack.
185  */
186 INFO_TABLE_RET( stg_apply_interp, RET_BCO )
187     /* explicit stack */
188 {
189     /* Just in case we end up in here... (we shouldn't) */
190     jump stg_yield_to_interpreter [];
191 }
192
193 /* ----------------------------------------------------------------------------
194    Entry code for a BCO
195    ------------------------------------------------------------------------- */
196
197 INFO_TABLE_FUN( stg_BCO, 4, 0, BCO, "BCO", "BCO", ARG_BCO )
198     /* explicit stack */
199 {
200   /* entering a BCO means "apply it", same as a function */
201   Sp_adj(-2);
202   Sp(1) = R1;
203   Sp(0) = stg_apply_interp_info;
204   jump stg_yield_to_interpreter [];
205 }
206
207 /* ----------------------------------------------------------------------------
208    Info tables for indirections.
209
210    SPECIALISED INDIRECTIONS: we have a specialised indirection for direct returns,
211    so that we can avoid entering
212    the object when we know it points directly to a value.  The update
213    code (Updates.cmm) updates objects with the appropriate kind of
214    indirection.  We only do this for young-gen indirections.
215    ------------------------------------------------------------------------- */
216
217 INFO_TABLE(stg_IND,1,0,IND,"IND","IND")
218 #if 0
219 /*
220   This version in high-level cmm generates slightly less good code
221   than the low-level version below it. (ToDo)
222 */
223     (P_ node)
224 {
225     TICK_ENT_DYN_IND(); /* tick */
226     node = UNTAG(StgInd_indirectee(node));
227     TICK_ENT_VIA_NODE();
228     jump %GET_ENTRY(node) (node);
229 }
230 #else
231     /* explicit stack */
232 {
233     TICK_ENT_DYN_IND(); /* tick */
234     R1 = UNTAG(StgInd_indirectee(R1));
235     TICK_ENT_VIA_NODE();
236     jump %GET_ENTRY(R1) [R1];
237 }
238 #endif
239
240 INFO_TABLE(stg_IND_direct,1,0,IND,"IND","IND")
241     (P_ node)
242 {
243     TICK_ENT_DYN_IND(); /* tick */
244     node = StgInd_indirectee(node);
245     TICK_ENT_VIA_NODE();
246     jump %ENTRY_CODE(Sp(0)) (node);
247 }
248
249 INFO_TABLE(stg_IND_STATIC,1,0,IND_STATIC,"IND_STATIC","IND_STATIC")
250     /* explicit stack */
251 {
252     TICK_ENT_STATIC_IND(); /* tick */
253     R1 = UNTAG(StgInd_indirectee(R1));
254     TICK_ENT_VIA_NODE();
255     jump %GET_ENTRY(R1) [R1];
256 }
257
258 INFO_TABLE(stg_IND_PERM,1,0,IND_PERM,"IND_PERM","IND_PERM")
259     /* explicit stack */
260 {
261     /* Don't add INDs to granularity cost */
262
263     /* Don't: TICK_ENT_STATIC_IND(Node); for ticky-ticky; this ind is
264        here only to help profiling */
265
266 #if defined(TICKY_TICKY) && !defined(PROFILING)
267     /* TICKY_TICKY && !PROFILING means PERM_IND *replaces* an IND, rather than
268        being extra  */
269     TICK_ENT_PERM_IND();
270 #endif
271
272     LDV_ENTER(R1);
273
274     /* For ticky-ticky, change the perm_ind to a normal ind on first
275      * entry, so the number of ent_perm_inds is the number of *thunks*
276      * entered again, not the number of subsequent entries.
277      *
278      * Since this screws up cost centres, we die if profiling and
279      * ticky_ticky are on at the same time.  KSW 1999-01.
280      */
281 #ifdef TICKY_TICKY
282 #  ifdef PROFILING
283 #    error Profiling and ticky-ticky do not mix at present!
284 #  endif  /* PROFILING */
285     StgHeader_info(R1) = stg_IND_info;
286 #endif /* TICKY_TICKY */
287
288     R1 = UNTAG(StgInd_indirectee(R1));
289
290 #if defined(TICKY_TICKY) && !defined(PROFILING)
291     TICK_ENT_VIA_NODE();
292 #endif
293
294     jump %GET_ENTRY(R1) [R1];
295 }
296
297 /* ----------------------------------------------------------------------------
298    Black holes.
299
300    Entering a black hole normally causes a cyclic data dependency, but
301    in the concurrent world, black holes are synchronization points,
302    and they are turned into blocking queues when there are threads
303    waiting for the evaluation of the closure to finish.
304    ------------------------------------------------------------------------- */
305
306 INFO_TABLE(stg_BLACKHOLE,1,0,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
307     (P_ node)
308 {
309     W_ r, info, owner, bd;
310     P_ p, bq, msg;
311
312     TICK_ENT_DYN_IND(); /* tick */
313
314 retry:
315     p = StgInd_indirectee(node);
316     if (GETTAG(p) != 0) {
317         return (p);
318     }
319
320     info = StgHeader_info(p);
321     if (info == stg_IND_info) {
322         // This could happen, if e.g. we got a BLOCKING_QUEUE that has
323         // just been replaced with an IND by another thread in
324         // wakeBlockingQueue().
325         goto retry;
326     }
327
328     if (info == stg_TSO_info ||
329         info == stg_BLOCKING_QUEUE_CLEAN_info ||
330         info == stg_BLOCKING_QUEUE_DIRTY_info)
331     {
332         ("ptr" msg) = ccall allocate(MyCapability() "ptr",
333                                      BYTES_TO_WDS(SIZEOF_MessageBlackHole));
334
335         SET_HDR(msg, stg_MSG_BLACKHOLE_info, CCS_SYSTEM);
336         MessageBlackHole_tso(msg) = CurrentTSO;
337         MessageBlackHole_bh(msg) = node;
338
339         (r) = ccall messageBlackHole(MyCapability() "ptr", msg "ptr");
340
341         if (r == 0) {
342             goto retry;
343         } else {
344             StgTSO_why_blocked(CurrentTSO) = BlockedOnBlackHole::I16;
345             StgTSO_block_info(CurrentTSO) = msg;
346             jump stg_block_blackhole(node);
347         }
348     }
349     else
350     {
351         ENTER(p);
352     }
353 }
354
355 INFO_TABLE(__stg_EAGER_BLACKHOLE,1,0,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
356     (P_ node)
357 {
358     jump ENTRY_LBL(stg_BLACKHOLE) (node);
359 }
360
361 // CAF_BLACKHOLE is allocated when entering a CAF.  The reason it is
362 // distinct from BLACKHOLE is so that we can tell the difference
363 // between an update frame on the stack that points to a CAF under
364 // evaluation, and one that points to a closure that is under
365 // evaluation by another thread (a BLACKHOLE).  See threadPaused().
366 //
367 INFO_TABLE(stg_CAF_BLACKHOLE,1,0,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
368     (P_ node)
369 {
370     jump ENTRY_LBL(stg_BLACKHOLE) (node);
371 }
372
373 INFO_TABLE(stg_BLOCKING_QUEUE_CLEAN,4,0,BLOCKING_QUEUE,"BLOCKING_QUEUE","BLOCKING_QUEUE")
374 { foreign "C" barf("BLOCKING_QUEUE_CLEAN object entered!") never returns; }
375
376
377 INFO_TABLE(stg_BLOCKING_QUEUE_DIRTY,4,0,BLOCKING_QUEUE,"BLOCKING_QUEUE","BLOCKING_QUEUE")
378 { foreign "C" barf("BLOCKING_QUEUE_DIRTY object entered!") never returns; }
379
380
381 /* ----------------------------------------------------------------------------
382    Whiteholes are used for the "locked" state of a closure (see lockClosure())
383    ------------------------------------------------------------------------- */
384
385 INFO_TABLE(stg_WHITEHOLE, 0,0, WHITEHOLE, "WHITEHOLE", "WHITEHOLE")
386     (P_ node)
387 {
388 #if defined(THREADED_RTS)
389     W_ info, i;
390
391     i = 0;
392 loop:
393     // spin until the WHITEHOLE is updated
394     info = StgHeader_info(node);
395     if (info == stg_WHITEHOLE_info) {
396         i = i + 1;
397         if (i == SPIN_COUNT) {
398             i = 0;
399             ccall yieldThread();
400         }
401         goto loop;
402     }
403     jump %ENTRY_CODE(info) (node);
404 #else
405     ccall barf("WHITEHOLE object entered!") never returns;
406 #endif
407 }
408
409 /* ----------------------------------------------------------------------------
410    Some static info tables for things that don't get entered, and
411    therefore don't need entry code (i.e. boxed but unpointed objects)
412    NON_ENTERABLE_ENTRY_CODE now defined at the beginning of the file
413    ------------------------------------------------------------------------- */
414
415 INFO_TABLE(stg_TSO, 0,0,TSO, "TSO", "TSO")
416 { foreign "C" barf("TSO object entered!") never returns; }
417
418 INFO_TABLE(stg_STACK, 0,0, STACK, "STACK", "STACK")
419 { foreign "C" barf("STACK object entered!") never returns; }
420
421 /* ----------------------------------------------------------------------------
422    Weak pointers
423
424    Live weak pointers have a special closure type.  Dead ones are just
425    nullary constructors (although they live on the heap - we overwrite
426    live weak pointers with dead ones).
427    ------------------------------------------------------------------------- */
428
429 INFO_TABLE(stg_WEAK,1,4,WEAK,"WEAK","WEAK")
430 { foreign "C" barf("WEAK object entered!") never returns; }
431
432 /*
433  * It's important when turning an existing WEAK into a DEAD_WEAK
434  * (which is what finalizeWeak# does) that we don't lose the link
435  * field and break the linked list of weak pointers.  Hence, we give
436  * DEAD_WEAK 5 non-pointer fields.
437  */
438 INFO_TABLE_CONSTR(stg_DEAD_WEAK,0,5,0,CONSTR,"DEAD_WEAK","DEAD_WEAK")
439 { foreign "C" barf("DEAD_WEAK object entered!") never returns; }
440
441 /* ----------------------------------------------------------------------------
442    NO_FINALIZER
443
444    This is a static nullary constructor (like []) that we use to mark an empty
445    finalizer in a weak pointer object.
446    ------------------------------------------------------------------------- */
447
448 INFO_TABLE_CONSTR(stg_NO_FINALIZER,0,0,0,CONSTR_NOCAF_STATIC,"NO_FINALIZER","NO_FINALIZER")
449 { foreign "C" barf("NO_FINALIZER object entered!") never returns; }
450
451 CLOSURE(stg_NO_FINALIZER_closure,stg_NO_FINALIZER);
452
453 /* ----------------------------------------------------------------------------
454    Stable Names are unlifted too.
455    ------------------------------------------------------------------------- */
456
457 INFO_TABLE(stg_STABLE_NAME,0,1,PRIM,"STABLE_NAME","STABLE_NAME")
458 { foreign "C" barf("STABLE_NAME object entered!") never returns; }
459
460 /* ----------------------------------------------------------------------------
461    MVars
462
463    There are two kinds of these: full and empty.  We need an info table
464    and entry code for each type.
465    ------------------------------------------------------------------------- */
466
467 INFO_TABLE(stg_MVAR_CLEAN,3,0,MVAR_CLEAN,"MVAR","MVAR")
468 { foreign "C" barf("MVAR object entered!") never returns; }
469
470 INFO_TABLE(stg_MVAR_DIRTY,3,0,MVAR_DIRTY,"MVAR","MVAR")
471 { foreign "C" barf("MVAR object entered!") never returns; }
472
473 /* -----------------------------------------------------------------------------
474    STM
475    -------------------------------------------------------------------------- */
476
477 INFO_TABLE(stg_TVAR, 2, 1, MUT_PRIM, "TVAR", "TVAR")
478 { foreign "C" barf("TVAR object entered!") never returns; }
479
480 INFO_TABLE(stg_TVAR_WATCH_QUEUE, 3, 0, MUT_PRIM, "TVAR_WATCH_QUEUE", "TVAR_WATCH_QUEUE")
481 { foreign "C" barf("TVAR_WATCH_QUEUE object entered!") never returns; }
482
483 INFO_TABLE(stg_ATOMIC_INVARIANT, 2, 1, MUT_PRIM, "ATOMIC_INVARIANT", "ATOMIC_INVARIANT")
484 { foreign "C" barf("ATOMIC_INVARIANT object entered!") never returns; }
485
486 INFO_TABLE(stg_INVARIANT_CHECK_QUEUE, 3, 0, MUT_PRIM, "INVARIANT_CHECK_QUEUE", "INVARIANT_CHECK_QUEUE")
487 { foreign "C" barf("INVARIANT_CHECK_QUEUE object entered!") never returns; }
488
489 INFO_TABLE(stg_TREC_CHUNK, 0, 0, TREC_CHUNK, "TREC_CHUNK", "TREC_CHUNK")
490 { foreign "C" barf("TREC_CHUNK object entered!") never returns; }
491
492 INFO_TABLE(stg_TREC_HEADER, 3, 1, MUT_PRIM, "TREC_HEADER", "TREC_HEADER")
493 { foreign "C" barf("TREC_HEADER object entered!") never returns; }
494
495 INFO_TABLE_CONSTR(stg_END_STM_WATCH_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_STM_WATCH_QUEUE","END_STM_WATCH_QUEUE")
496 { foreign "C" barf("END_STM_WATCH_QUEUE object entered!") never returns; }
497
498 INFO_TABLE_CONSTR(stg_END_INVARIANT_CHECK_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_INVARIANT_CHECK_QUEUE","END_INVARIANT_CHECK_QUEUE")
499 { foreign "C" barf("END_INVARIANT_CHECK_QUEUE object entered!") never returns; }
500
501 INFO_TABLE_CONSTR(stg_END_STM_CHUNK_LIST,0,0,0,CONSTR_NOCAF_STATIC,"END_STM_CHUNK_LIST","END_STM_CHUNK_LIST")
502 { foreign "C" barf("END_STM_CHUNK_LIST object entered!") never returns; }
503
504 INFO_TABLE_CONSTR(stg_NO_TREC,0,0,0,CONSTR_NOCAF_STATIC,"NO_TREC","NO_TREC")
505 { foreign "C" barf("NO_TREC object entered!") never returns; }
506
507 CLOSURE(stg_END_STM_WATCH_QUEUE_closure,stg_END_STM_WATCH_QUEUE);
508
509 CLOSURE(stg_END_INVARIANT_CHECK_QUEUE_closure,stg_END_INVARIANT_CHECK_QUEUE);
510
511 CLOSURE(stg_END_STM_CHUNK_LIST_closure,stg_END_STM_CHUNK_LIST);
512
513 CLOSURE(stg_NO_TREC_closure,stg_NO_TREC);
514
515 /* ----------------------------------------------------------------------------
516    Messages
517    ------------------------------------------------------------------------- */
518
519 // PRIM rather than CONSTR, because PRIM objects cannot be duplicated by the GC.
520
521 INFO_TABLE_CONSTR(stg_MSG_TRY_WAKEUP,2,0,0,PRIM,"MSG_TRY_WAKEUP","MSG_TRY_WAKEUP")
522 { foreign "C" barf("MSG_TRY_WAKEUP object entered!") never returns; }
523
524 INFO_TABLE_CONSTR(stg_MSG_THROWTO,4,0,0,PRIM,"MSG_THROWTO","MSG_THROWTO")
525 { foreign "C" barf("MSG_THROWTO object entered!") never returns; }
526
527 INFO_TABLE_CONSTR(stg_MSG_BLACKHOLE,3,0,0,PRIM,"MSG_BLACKHOLE","MSG_BLACKHOLE")
528 { foreign "C" barf("MSG_BLACKHOLE object entered!") never returns; }
529
530 // used to overwrite a MSG_THROWTO when the message has been used/revoked
531 INFO_TABLE_CONSTR(stg_MSG_NULL,1,0,0,PRIM,"MSG_NULL","MSG_NULL")
532 { foreign "C" barf("MSG_NULL object entered!") never returns; }
533
534 /* ----------------------------------------------------------------------------
535    END_TSO_QUEUE
536
537    This is a static nullary constructor (like []) that we use to mark the
538    end of a linked TSO queue.
539    ------------------------------------------------------------------------- */
540
541 INFO_TABLE_CONSTR(stg_END_TSO_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_TSO_QUEUE","END_TSO_QUEUE")
542 { foreign "C" barf("END_TSO_QUEUE object entered!") never returns; }
543
544 CLOSURE(stg_END_TSO_QUEUE_closure,stg_END_TSO_QUEUE);
545
546 /* ----------------------------------------------------------------------------
547    Arrays
548
549    These come in two basic flavours: arrays of data (StgArrWords) and arrays of
550    pointers (StgArrPtrs).  They all have a similar layout:
551
552    ___________________________
553    | Info | No. of | data....
554         |  Ptr | Words  |
555    ---------------------------
556
557    These are *unpointed* objects: i.e. they cannot be entered.
558
559    ------------------------------------------------------------------------- */
560
561 INFO_TABLE(stg_ARR_WORDS, 0, 0, ARR_WORDS, "ARR_WORDS", "ARR_WORDS")
562 { foreign "C" barf("ARR_WORDS object entered!") never returns; }
563
564 INFO_TABLE(stg_MUT_ARR_PTRS_CLEAN, 0, 0, MUT_ARR_PTRS_CLEAN, "MUT_ARR_PTRS_CLEAN", "MUT_ARR_PTRS_CLEAN")
565 { foreign "C" barf("MUT_ARR_PTRS_CLEAN object entered!") never returns; }
566
567 INFO_TABLE(stg_MUT_ARR_PTRS_DIRTY, 0, 0, MUT_ARR_PTRS_DIRTY, "MUT_ARR_PTRS_DIRTY", "MUT_ARR_PTRS_DIRTY")
568 { foreign "C" barf("MUT_ARR_PTRS_DIRTY object entered!") never returns; }
569
570 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN, 0, 0, MUT_ARR_PTRS_FROZEN, "MUT_ARR_PTRS_FROZEN", "MUT_ARR_PTRS_FROZEN")
571 { foreign "C" barf("MUT_ARR_PTRS_FROZEN object entered!") never returns; }
572
573 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN0, 0, 0, MUT_ARR_PTRS_FROZEN0, "MUT_ARR_PTRS_FROZEN0", "MUT_ARR_PTRS_FROZEN0")
574 { foreign "C" barf("MUT_ARR_PTRS_FROZEN0 object entered!") never returns; }
575
576 /* ----------------------------------------------------------------------------
577    Mutable Variables
578    ------------------------------------------------------------------------- */
579
580 INFO_TABLE(stg_MUT_VAR_CLEAN, 1, 0, MUT_VAR_CLEAN, "MUT_VAR_CLEAN", "MUT_VAR_CLEAN")
581 { foreign "C" barf("MUT_VAR_CLEAN object entered!") never returns; }
582 INFO_TABLE(stg_MUT_VAR_DIRTY, 1, 0, MUT_VAR_DIRTY, "MUT_VAR_DIRTY", "MUT_VAR_DIRTY")
583 { foreign "C" barf("MUT_VAR_DIRTY object entered!") never returns; }
584
585 /* ----------------------------------------------------------------------------
586    Dummy return closure
587
588    Entering this closure will just return to the address on the top of the
589    stack.  Useful for getting a thread in a canonical form where we can
590    just enter the top stack word to start the thread.  (see deleteThread)
591  * ------------------------------------------------------------------------- */
592
593 INFO_TABLE( stg_dummy_ret, 0, 0, CONSTR_NOCAF_STATIC, "DUMMY_RET", "DUMMY_RET")
594     ()
595 {
596     return ();
597 }
598 CLOSURE(stg_dummy_ret_closure,stg_dummy_ret);
599
600 /* ----------------------------------------------------------------------------
601    MVAR_TSO_QUEUE
602    ------------------------------------------------------------------------- */
603
604 INFO_TABLE_CONSTR(stg_MVAR_TSO_QUEUE,2,0,0,PRIM,"MVAR_TSO_QUEUE","MVAR_TSO_QUEUE")
605 { foreign "C" barf("MVAR_TSO_QUEUE object entered!") never returns; }
606
607 /* ----------------------------------------------------------------------------
608    CHARLIKE and INTLIKE closures.
609
610    These are static representations of Chars and small Ints, so that
611    we can remove dynamic Chars and Ints during garbage collection and
612    replace them with references to the static objects.
613    ------------------------------------------------------------------------- */
614
615 #if defined(COMPILING_WINDOWS_DLL)
616 /*
617  * When sticking the RTS in a Windows DLL, we delay populating the
618  * Charlike and Intlike tables until load-time, which is only
619  * when we've got the real addresses to the C# and I# closures.
620  *
621  * -- this is currently broken BL 2009/11/14.
622  *    we don't rewrite to static closures at all with Windows DLLs.
623  */
624 // #warning Is this correct? _imp is a pointer!
625 #define Char_hash_static_info _imp__ghczmprim_GHCziTypes_Czh_static_info
626 #define Int_hash_static_info _imp__ghczmprim_GHCziTypes_Izh_static_info
627 #else
628 #define Char_hash_static_info ghczmprim_GHCziTypes_Czh_static_info
629 #define Int_hash_static_info ghczmprim_GHCziTypes_Izh_static_info
630 #endif
631
632
633 #define CHARLIKE_HDR(n)  CLOSURE(Char_hash_static_info, n)
634 #define INTLIKE_HDR(n)   CLOSURE(Int_hash_static_info, n)
635
636 /* put these in the *data* section, since the garbage collector relies
637  * on the fact that static closures live in the data section.
638  */
639
640 #if !(defined(COMPILING_WINDOWS_DLL))
641 section "data" {
642  stg_CHARLIKE_closure:
643     CHARLIKE_HDR(0)
644     CHARLIKE_HDR(1)
645     CHARLIKE_HDR(2)
646     CHARLIKE_HDR(3)
647     CHARLIKE_HDR(4)
648     CHARLIKE_HDR(5)
649     CHARLIKE_HDR(6)
650     CHARLIKE_HDR(7)
651     CHARLIKE_HDR(8)
652     CHARLIKE_HDR(9)
653     CHARLIKE_HDR(10)
654     CHARLIKE_HDR(11)
655     CHARLIKE_HDR(12)
656     CHARLIKE_HDR(13)
657     CHARLIKE_HDR(14)
658     CHARLIKE_HDR(15)
659     CHARLIKE_HDR(16)
660     CHARLIKE_HDR(17)
661     CHARLIKE_HDR(18)
662     CHARLIKE_HDR(19)
663     CHARLIKE_HDR(20)
664     CHARLIKE_HDR(21)
665     CHARLIKE_HDR(22)
666     CHARLIKE_HDR(23)
667     CHARLIKE_HDR(24)
668     CHARLIKE_HDR(25)
669     CHARLIKE_HDR(26)
670     CHARLIKE_HDR(27)
671     CHARLIKE_HDR(28)
672     CHARLIKE_HDR(29)
673     CHARLIKE_HDR(30)
674     CHARLIKE_HDR(31)
675     CHARLIKE_HDR(32)
676     CHARLIKE_HDR(33)
677     CHARLIKE_HDR(34)
678     CHARLIKE_HDR(35)
679     CHARLIKE_HDR(36)
680     CHARLIKE_HDR(37)
681     CHARLIKE_HDR(38)
682     CHARLIKE_HDR(39)
683     CHARLIKE_HDR(40)
684     CHARLIKE_HDR(41)
685     CHARLIKE_HDR(42)
686     CHARLIKE_HDR(43)
687     CHARLIKE_HDR(44)
688     CHARLIKE_HDR(45)
689     CHARLIKE_HDR(46)
690     CHARLIKE_HDR(47)
691     CHARLIKE_HDR(48)
692     CHARLIKE_HDR(49)
693     CHARLIKE_HDR(50)
694     CHARLIKE_HDR(51)
695     CHARLIKE_HDR(52)
696     CHARLIKE_HDR(53)
697     CHARLIKE_HDR(54)
698     CHARLIKE_HDR(55)
699     CHARLIKE_HDR(56)
700     CHARLIKE_HDR(57)
701     CHARLIKE_HDR(58)
702     CHARLIKE_HDR(59)
703     CHARLIKE_HDR(60)
704     CHARLIKE_HDR(61)
705     CHARLIKE_HDR(62)
706     CHARLIKE_HDR(63)
707     CHARLIKE_HDR(64)
708     CHARLIKE_HDR(65)
709     CHARLIKE_HDR(66)
710     CHARLIKE_HDR(67)
711     CHARLIKE_HDR(68)
712     CHARLIKE_HDR(69)
713     CHARLIKE_HDR(70)
714     CHARLIKE_HDR(71)
715     CHARLIKE_HDR(72)
716     CHARLIKE_HDR(73)
717     CHARLIKE_HDR(74)
718     CHARLIKE_HDR(75)
719     CHARLIKE_HDR(76)
720     CHARLIKE_HDR(77)
721     CHARLIKE_HDR(78)
722     CHARLIKE_HDR(79)
723     CHARLIKE_HDR(80)
724     CHARLIKE_HDR(81)
725     CHARLIKE_HDR(82)
726     CHARLIKE_HDR(83)
727     CHARLIKE_HDR(84)
728     CHARLIKE_HDR(85)
729     CHARLIKE_HDR(86)
730     CHARLIKE_HDR(87)
731     CHARLIKE_HDR(88)
732     CHARLIKE_HDR(89)
733     CHARLIKE_HDR(90)
734     CHARLIKE_HDR(91)
735     CHARLIKE_HDR(92)
736     CHARLIKE_HDR(93)
737     CHARLIKE_HDR(94)
738     CHARLIKE_HDR(95)
739     CHARLIKE_HDR(96)
740     CHARLIKE_HDR(97)
741     CHARLIKE_HDR(98)
742     CHARLIKE_HDR(99)
743     CHARLIKE_HDR(100)
744     CHARLIKE_HDR(101)
745     CHARLIKE_HDR(102)
746     CHARLIKE_HDR(103)
747     CHARLIKE_HDR(104)
748     CHARLIKE_HDR(105)
749     CHARLIKE_HDR(106)
750     CHARLIKE_HDR(107)
751     CHARLIKE_HDR(108)
752     CHARLIKE_HDR(109)
753     CHARLIKE_HDR(110)
754     CHARLIKE_HDR(111)
755     CHARLIKE_HDR(112)
756     CHARLIKE_HDR(113)
757     CHARLIKE_HDR(114)
758     CHARLIKE_HDR(115)
759     CHARLIKE_HDR(116)
760     CHARLIKE_HDR(117)
761     CHARLIKE_HDR(118)
762     CHARLIKE_HDR(119)
763     CHARLIKE_HDR(120)
764     CHARLIKE_HDR(121)
765     CHARLIKE_HDR(122)
766     CHARLIKE_HDR(123)
767     CHARLIKE_HDR(124)
768     CHARLIKE_HDR(125)
769     CHARLIKE_HDR(126)
770     CHARLIKE_HDR(127)
771     CHARLIKE_HDR(128)
772     CHARLIKE_HDR(129)
773     CHARLIKE_HDR(130)
774     CHARLIKE_HDR(131)
775     CHARLIKE_HDR(132)
776     CHARLIKE_HDR(133)
777     CHARLIKE_HDR(134)
778     CHARLIKE_HDR(135)
779     CHARLIKE_HDR(136)
780     CHARLIKE_HDR(137)
781     CHARLIKE_HDR(138)
782     CHARLIKE_HDR(139)
783     CHARLIKE_HDR(140)
784     CHARLIKE_HDR(141)
785     CHARLIKE_HDR(142)
786     CHARLIKE_HDR(143)
787     CHARLIKE_HDR(144)
788     CHARLIKE_HDR(145)
789     CHARLIKE_HDR(146)
790     CHARLIKE_HDR(147)
791     CHARLIKE_HDR(148)
792     CHARLIKE_HDR(149)
793     CHARLIKE_HDR(150)
794     CHARLIKE_HDR(151)
795     CHARLIKE_HDR(152)
796     CHARLIKE_HDR(153)
797     CHARLIKE_HDR(154)
798     CHARLIKE_HDR(155)
799     CHARLIKE_HDR(156)
800     CHARLIKE_HDR(157)
801     CHARLIKE_HDR(158)
802     CHARLIKE_HDR(159)
803     CHARLIKE_HDR(160)
804     CHARLIKE_HDR(161)
805     CHARLIKE_HDR(162)
806     CHARLIKE_HDR(163)
807     CHARLIKE_HDR(164)
808     CHARLIKE_HDR(165)
809     CHARLIKE_HDR(166)
810     CHARLIKE_HDR(167)
811     CHARLIKE_HDR(168)
812     CHARLIKE_HDR(169)
813     CHARLIKE_HDR(170)
814     CHARLIKE_HDR(171)
815     CHARLIKE_HDR(172)
816     CHARLIKE_HDR(173)
817     CHARLIKE_HDR(174)
818     CHARLIKE_HDR(175)
819     CHARLIKE_HDR(176)
820     CHARLIKE_HDR(177)
821     CHARLIKE_HDR(178)
822     CHARLIKE_HDR(179)
823     CHARLIKE_HDR(180)
824     CHARLIKE_HDR(181)
825     CHARLIKE_HDR(182)
826     CHARLIKE_HDR(183)
827     CHARLIKE_HDR(184)
828     CHARLIKE_HDR(185)
829     CHARLIKE_HDR(186)
830     CHARLIKE_HDR(187)
831     CHARLIKE_HDR(188)
832     CHARLIKE_HDR(189)
833     CHARLIKE_HDR(190)
834     CHARLIKE_HDR(191)
835     CHARLIKE_HDR(192)
836     CHARLIKE_HDR(193)
837     CHARLIKE_HDR(194)
838     CHARLIKE_HDR(195)
839     CHARLIKE_HDR(196)
840     CHARLIKE_HDR(197)
841     CHARLIKE_HDR(198)
842     CHARLIKE_HDR(199)
843     CHARLIKE_HDR(200)
844     CHARLIKE_HDR(201)
845     CHARLIKE_HDR(202)
846     CHARLIKE_HDR(203)
847     CHARLIKE_HDR(204)
848     CHARLIKE_HDR(205)
849     CHARLIKE_HDR(206)
850     CHARLIKE_HDR(207)
851     CHARLIKE_HDR(208)
852     CHARLIKE_HDR(209)
853     CHARLIKE_HDR(210)
854     CHARLIKE_HDR(211)
855     CHARLIKE_HDR(212)
856     CHARLIKE_HDR(213)
857     CHARLIKE_HDR(214)
858     CHARLIKE_HDR(215)
859     CHARLIKE_HDR(216)
860     CHARLIKE_HDR(217)
861     CHARLIKE_HDR(218)
862     CHARLIKE_HDR(219)
863     CHARLIKE_HDR(220)
864     CHARLIKE_HDR(221)
865     CHARLIKE_HDR(222)
866     CHARLIKE_HDR(223)
867     CHARLIKE_HDR(224)
868     CHARLIKE_HDR(225)
869     CHARLIKE_HDR(226)
870     CHARLIKE_HDR(227)
871     CHARLIKE_HDR(228)
872     CHARLIKE_HDR(229)
873     CHARLIKE_HDR(230)
874     CHARLIKE_HDR(231)
875     CHARLIKE_HDR(232)
876     CHARLIKE_HDR(233)
877     CHARLIKE_HDR(234)
878     CHARLIKE_HDR(235)
879     CHARLIKE_HDR(236)
880     CHARLIKE_HDR(237)
881     CHARLIKE_HDR(238)
882     CHARLIKE_HDR(239)
883     CHARLIKE_HDR(240)
884     CHARLIKE_HDR(241)
885     CHARLIKE_HDR(242)
886     CHARLIKE_HDR(243)
887     CHARLIKE_HDR(244)
888     CHARLIKE_HDR(245)
889     CHARLIKE_HDR(246)
890     CHARLIKE_HDR(247)
891     CHARLIKE_HDR(248)
892     CHARLIKE_HDR(249)
893     CHARLIKE_HDR(250)
894     CHARLIKE_HDR(251)
895     CHARLIKE_HDR(252)
896     CHARLIKE_HDR(253)
897     CHARLIKE_HDR(254)
898     CHARLIKE_HDR(255)
899 }
900
901 section "data" {
902  stg_INTLIKE_closure:
903     INTLIKE_HDR(-16) /* MIN_INTLIKE == -16 */
904     INTLIKE_HDR(-15)
905     INTLIKE_HDR(-14)
906     INTLIKE_HDR(-13)
907     INTLIKE_HDR(-12)
908     INTLIKE_HDR(-11)
909     INTLIKE_HDR(-10)
910     INTLIKE_HDR(-9)
911     INTLIKE_HDR(-8)
912     INTLIKE_HDR(-7)
913     INTLIKE_HDR(-6)
914     INTLIKE_HDR(-5)
915     INTLIKE_HDR(-4)
916     INTLIKE_HDR(-3)
917     INTLIKE_HDR(-2)
918     INTLIKE_HDR(-1)
919     INTLIKE_HDR(0)
920     INTLIKE_HDR(1)
921     INTLIKE_HDR(2)
922     INTLIKE_HDR(3)
923     INTLIKE_HDR(4)
924     INTLIKE_HDR(5)
925     INTLIKE_HDR(6)
926     INTLIKE_HDR(7)
927     INTLIKE_HDR(8)
928     INTLIKE_HDR(9)
929     INTLIKE_HDR(10)
930     INTLIKE_HDR(11)
931     INTLIKE_HDR(12)
932     INTLIKE_HDR(13)
933     INTLIKE_HDR(14)
934     INTLIKE_HDR(15)
935     INTLIKE_HDR(16)  /* MAX_INTLIKE == 16 */
936 }
937
938 #endif