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