Fold base.git into ghc.git (re #8545)
[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    C finalizer lists
443
444    Singly linked lists that chain multiple C finalizers on a weak pointer.
445    ------------------------------------------------------------------------- */
446
447 INFO_TABLE_CONSTR(stg_C_FINALIZER_LIST,1,4,0,CONSTR,"C_FINALIZER_LIST","C_FINALIZER_LIST")
448 { foreign "C" barf("C_FINALIZER_LIST object entered!") never returns; }
449
450 /* ----------------------------------------------------------------------------
451    NO_FINALIZER
452
453    This is a static nullary constructor (like []) that we use to mark an empty
454    finalizer in a weak pointer object.
455    ------------------------------------------------------------------------- */
456
457 INFO_TABLE_CONSTR(stg_NO_FINALIZER,0,0,0,CONSTR_NOCAF_STATIC,"NO_FINALIZER","NO_FINALIZER")
458 { foreign "C" barf("NO_FINALIZER object entered!") never returns; }
459
460 CLOSURE(stg_NO_FINALIZER_closure,stg_NO_FINALIZER);
461
462 /* ----------------------------------------------------------------------------
463    Stable Names are unlifted too.
464    ------------------------------------------------------------------------- */
465
466 INFO_TABLE(stg_STABLE_NAME,0,1,PRIM,"STABLE_NAME","STABLE_NAME")
467 { foreign "C" barf("STABLE_NAME object entered!") never returns; }
468
469 /* ----------------------------------------------------------------------------
470    MVars
471
472    There are two kinds of these: full and empty.  We need an info table
473    and entry code for each type.
474    ------------------------------------------------------------------------- */
475
476 INFO_TABLE(stg_MVAR_CLEAN,3,0,MVAR_CLEAN,"MVAR","MVAR")
477 { foreign "C" barf("MVAR object entered!") never returns; }
478
479 INFO_TABLE(stg_MVAR_DIRTY,3,0,MVAR_DIRTY,"MVAR","MVAR")
480 { foreign "C" barf("MVAR object entered!") never returns; }
481
482 /* -----------------------------------------------------------------------------
483    STM
484    -------------------------------------------------------------------------- */
485
486 INFO_TABLE(stg_TVAR_CLEAN, 2, 1, TVAR, "TVAR", "TVAR")
487 { foreign "C" barf("TVAR_CLEAN object entered!") never returns; }
488
489 INFO_TABLE(stg_TVAR_DIRTY, 2, 1, TVAR, "TVAR", "TVAR")
490 { foreign "C" barf("TVAR_DIRTY object entered!") never returns; }
491
492 INFO_TABLE(stg_TVAR_WATCH_QUEUE, 3, 0, MUT_PRIM, "TVAR_WATCH_QUEUE", "TVAR_WATCH_QUEUE")
493 { foreign "C" barf("TVAR_WATCH_QUEUE object entered!") never returns; }
494
495 INFO_TABLE(stg_ATOMIC_INVARIANT, 2, 1, MUT_PRIM, "ATOMIC_INVARIANT", "ATOMIC_INVARIANT")
496 { foreign "C" barf("ATOMIC_INVARIANT object entered!") never returns; }
497
498 INFO_TABLE(stg_INVARIANT_CHECK_QUEUE, 3, 0, MUT_PRIM, "INVARIANT_CHECK_QUEUE", "INVARIANT_CHECK_QUEUE")
499 { foreign "C" barf("INVARIANT_CHECK_QUEUE object entered!") never returns; }
500
501 INFO_TABLE(stg_TREC_CHUNK, 0, 0, TREC_CHUNK, "TREC_CHUNK", "TREC_CHUNK")
502 { foreign "C" barf("TREC_CHUNK object entered!") never returns; }
503
504 INFO_TABLE(stg_TREC_HEADER, 3, 1, MUT_PRIM, "TREC_HEADER", "TREC_HEADER")
505 { foreign "C" barf("TREC_HEADER object entered!") never returns; }
506
507 INFO_TABLE_CONSTR(stg_END_STM_WATCH_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_STM_WATCH_QUEUE","END_STM_WATCH_QUEUE")
508 { foreign "C" barf("END_STM_WATCH_QUEUE object entered!") never returns; }
509
510 INFO_TABLE_CONSTR(stg_END_INVARIANT_CHECK_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_INVARIANT_CHECK_QUEUE","END_INVARIANT_CHECK_QUEUE")
511 { foreign "C" barf("END_INVARIANT_CHECK_QUEUE object entered!") never returns; }
512
513 INFO_TABLE_CONSTR(stg_END_STM_CHUNK_LIST,0,0,0,CONSTR_NOCAF_STATIC,"END_STM_CHUNK_LIST","END_STM_CHUNK_LIST")
514 { foreign "C" barf("END_STM_CHUNK_LIST object entered!") never returns; }
515
516 INFO_TABLE_CONSTR(stg_NO_TREC,0,0,0,CONSTR_NOCAF_STATIC,"NO_TREC","NO_TREC")
517 { foreign "C" barf("NO_TREC object entered!") never returns; }
518
519 CLOSURE(stg_END_STM_WATCH_QUEUE_closure,stg_END_STM_WATCH_QUEUE);
520
521 CLOSURE(stg_END_INVARIANT_CHECK_QUEUE_closure,stg_END_INVARIANT_CHECK_QUEUE);
522
523 CLOSURE(stg_END_STM_CHUNK_LIST_closure,stg_END_STM_CHUNK_LIST);
524
525 CLOSURE(stg_NO_TREC_closure,stg_NO_TREC);
526
527 /* ----------------------------------------------------------------------------
528    Messages
529    ------------------------------------------------------------------------- */
530
531 // PRIM rather than CONSTR, because PRIM objects cannot be duplicated by the GC.
532
533 INFO_TABLE_CONSTR(stg_MSG_TRY_WAKEUP,2,0,0,PRIM,"MSG_TRY_WAKEUP","MSG_TRY_WAKEUP")
534 { foreign "C" barf("MSG_TRY_WAKEUP object entered!") never returns; }
535
536 INFO_TABLE_CONSTR(stg_MSG_THROWTO,4,0,0,PRIM,"MSG_THROWTO","MSG_THROWTO")
537 { foreign "C" barf("MSG_THROWTO object entered!") never returns; }
538
539 INFO_TABLE_CONSTR(stg_MSG_BLACKHOLE,3,0,0,PRIM,"MSG_BLACKHOLE","MSG_BLACKHOLE")
540 { foreign "C" barf("MSG_BLACKHOLE object entered!") never returns; }
541
542 // used to overwrite a MSG_THROWTO when the message has been used/revoked
543 INFO_TABLE_CONSTR(stg_MSG_NULL,1,0,0,PRIM,"MSG_NULL","MSG_NULL")
544 { foreign "C" barf("MSG_NULL object entered!") never returns; }
545
546 /* ----------------------------------------------------------------------------
547    END_TSO_QUEUE
548
549    This is a static nullary constructor (like []) that we use to mark the
550    end of a linked TSO queue.
551    ------------------------------------------------------------------------- */
552
553 INFO_TABLE_CONSTR(stg_END_TSO_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_TSO_QUEUE","END_TSO_QUEUE")
554 { foreign "C" barf("END_TSO_QUEUE object entered!") never returns; }
555
556 CLOSURE(stg_END_TSO_QUEUE_closure,stg_END_TSO_QUEUE);
557
558 /* ----------------------------------------------------------------------------
559    GCD_CAF
560    ------------------------------------------------------------------------- */
561
562 INFO_TABLE_CONSTR(stg_GCD_CAF,0,0,0,CONSTR_NOCAF_STATIC,"GCD_CAF","GCD_CAF")
563 { foreign "C" barf("Evaluated a CAF that was GC'd!") never returns; }
564
565 /* ----------------------------------------------------------------------------
566    STM_AWOKEN
567
568    This is a static nullary constructor (like []) that we use to mark a
569    thread waiting on an STM wakeup
570    ------------------------------------------------------------------------- */
571
572 INFO_TABLE_CONSTR(stg_STM_AWOKEN,0,0,0,CONSTR_NOCAF_STATIC,"STM_AWOKEN","STM_AWOKEN")
573 { foreign "C" barf("STM_AWOKEN object entered!") never returns; }
574
575 CLOSURE(stg_STM_AWOKEN_closure,stg_STM_AWOKEN);
576
577 /* ----------------------------------------------------------------------------
578    Arrays
579
580    These come in two basic flavours: arrays of data (StgArrWords) and arrays of
581    pointers (StgArrPtrs).  They all have a similar layout:
582
583    ___________________________
584    | Info | No. of | data....
585    |  Ptr | Words  |
586    ---------------------------
587
588    These are *unpointed* objects: i.e. they cannot be entered.
589
590    ------------------------------------------------------------------------- */
591
592 INFO_TABLE(stg_ARR_WORDS, 0, 0, ARR_WORDS, "ARR_WORDS", "ARR_WORDS")
593 { foreign "C" barf("ARR_WORDS object entered!") never returns; }
594
595 INFO_TABLE(stg_MUT_ARR_PTRS_CLEAN, 0, 0, MUT_ARR_PTRS_CLEAN, "MUT_ARR_PTRS_CLEAN", "MUT_ARR_PTRS_CLEAN")
596 { foreign "C" barf("MUT_ARR_PTRS_CLEAN object entered!") never returns; }
597
598 INFO_TABLE(stg_MUT_ARR_PTRS_DIRTY, 0, 0, MUT_ARR_PTRS_DIRTY, "MUT_ARR_PTRS_DIRTY", "MUT_ARR_PTRS_DIRTY")
599 { foreign "C" barf("MUT_ARR_PTRS_DIRTY object entered!") never returns; }
600
601 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN, 0, 0, MUT_ARR_PTRS_FROZEN, "MUT_ARR_PTRS_FROZEN", "MUT_ARR_PTRS_FROZEN")
602 { foreign "C" barf("MUT_ARR_PTRS_FROZEN object entered!") never returns; }
603
604 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN0, 0, 0, MUT_ARR_PTRS_FROZEN0, "MUT_ARR_PTRS_FROZEN0", "MUT_ARR_PTRS_FROZEN0")
605 { foreign "C" barf("MUT_ARR_PTRS_FROZEN0 object entered!") never returns; }
606
607 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")
608 { foreign "C" barf("SMALL_MUT_ARR_PTRS_CLEAN object entered!") never returns; }
609
610 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")
611 { foreign "C" barf("SMALL_MUT_ARR_PTRS_DIRTY object entered!") never returns; }
612
613 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")
614 { foreign "C" barf("SMALL_MUT_ARR_PTRS_FROZEN object entered!") never returns; }
615
616 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")
617 { foreign "C" barf("SMALL_MUT_ARR_PTRS_FROZEN0 object entered!") never returns; }
618
619 /* ----------------------------------------------------------------------------
620    Mutable Variables
621    ------------------------------------------------------------------------- */
622
623 INFO_TABLE(stg_MUT_VAR_CLEAN, 1, 0, MUT_VAR_CLEAN, "MUT_VAR_CLEAN", "MUT_VAR_CLEAN")
624 { foreign "C" barf("MUT_VAR_CLEAN object entered!") never returns; }
625 INFO_TABLE(stg_MUT_VAR_DIRTY, 1, 0, MUT_VAR_DIRTY, "MUT_VAR_DIRTY", "MUT_VAR_DIRTY")
626 { foreign "C" barf("MUT_VAR_DIRTY object entered!") never returns; }
627
628 /* ----------------------------------------------------------------------------
629    Dummy return closure
630
631    Entering this closure will just return to the address on the top of the
632    stack.  Useful for getting a thread in a canonical form where we can
633    just enter the top stack word to start the thread.  (see deleteThread)
634  * ------------------------------------------------------------------------- */
635
636 INFO_TABLE( stg_dummy_ret, 0, 0, CONSTR_NOCAF_STATIC, "DUMMY_RET", "DUMMY_RET")
637     ()
638 {
639     return ();
640 }
641 CLOSURE(stg_dummy_ret_closure,stg_dummy_ret);
642
643 /* ----------------------------------------------------------------------------
644    MVAR_TSO_QUEUE
645    ------------------------------------------------------------------------- */
646
647 INFO_TABLE_CONSTR(stg_MVAR_TSO_QUEUE,2,0,0,PRIM,"MVAR_TSO_QUEUE","MVAR_TSO_QUEUE")
648 { foreign "C" barf("MVAR_TSO_QUEUE object entered!") never returns; }
649
650 /* ----------------------------------------------------------------------------
651    CHARLIKE and INTLIKE closures.
652
653    These are static representations of Chars and small Ints, so that
654    we can remove dynamic Chars and Ints during garbage collection and
655    replace them with references to the static objects.
656    ------------------------------------------------------------------------- */
657
658 #if defined(COMPILING_WINDOWS_DLL)
659 /*
660  * When sticking the RTS in a Windows DLL, we delay populating the
661  * Charlike and Intlike tables until load-time, which is only
662  * when we've got the real addresses to the C# and I# closures.
663  *
664  * -- this is currently broken BL 2009/11/14.
665  *    we don't rewrite to static closures at all with Windows DLLs.
666  */
667 // #warning Is this correct? _imp is a pointer!
668 #define Char_hash_static_info _imp__ghczmprim_GHCziTypes_Czh_static_info
669 #define Int_hash_static_info _imp__ghczmprim_GHCziTypes_Izh_static_info
670 #else
671 #define Char_hash_static_info ghczmprim_GHCziTypes_Czh_static_info
672 #define Int_hash_static_info ghczmprim_GHCziTypes_Izh_static_info
673 #endif
674
675
676 #define CHARLIKE_HDR(n)  CLOSURE(Char_hash_static_info, n)
677 #define INTLIKE_HDR(n)   CLOSURE(Int_hash_static_info, n)
678
679 /* put these in the *data* section, since the garbage collector relies
680  * on the fact that static closures live in the data section.
681  */
682
683 #if !(defined(COMPILING_WINDOWS_DLL))
684 section "data" {
685  stg_CHARLIKE_closure:
686     CHARLIKE_HDR(0)
687     CHARLIKE_HDR(1)
688     CHARLIKE_HDR(2)
689     CHARLIKE_HDR(3)
690     CHARLIKE_HDR(4)
691     CHARLIKE_HDR(5)
692     CHARLIKE_HDR(6)
693     CHARLIKE_HDR(7)
694     CHARLIKE_HDR(8)
695     CHARLIKE_HDR(9)
696     CHARLIKE_HDR(10)
697     CHARLIKE_HDR(11)
698     CHARLIKE_HDR(12)
699     CHARLIKE_HDR(13)
700     CHARLIKE_HDR(14)
701     CHARLIKE_HDR(15)
702     CHARLIKE_HDR(16)
703     CHARLIKE_HDR(17)
704     CHARLIKE_HDR(18)
705     CHARLIKE_HDR(19)
706     CHARLIKE_HDR(20)
707     CHARLIKE_HDR(21)
708     CHARLIKE_HDR(22)
709     CHARLIKE_HDR(23)
710     CHARLIKE_HDR(24)
711     CHARLIKE_HDR(25)
712     CHARLIKE_HDR(26)
713     CHARLIKE_HDR(27)
714     CHARLIKE_HDR(28)
715     CHARLIKE_HDR(29)
716     CHARLIKE_HDR(30)
717     CHARLIKE_HDR(31)
718     CHARLIKE_HDR(32)
719     CHARLIKE_HDR(33)
720     CHARLIKE_HDR(34)
721     CHARLIKE_HDR(35)
722     CHARLIKE_HDR(36)
723     CHARLIKE_HDR(37)
724     CHARLIKE_HDR(38)
725     CHARLIKE_HDR(39)
726     CHARLIKE_HDR(40)
727     CHARLIKE_HDR(41)
728     CHARLIKE_HDR(42)
729     CHARLIKE_HDR(43)
730     CHARLIKE_HDR(44)
731     CHARLIKE_HDR(45)
732     CHARLIKE_HDR(46)
733     CHARLIKE_HDR(47)
734     CHARLIKE_HDR(48)
735     CHARLIKE_HDR(49)
736     CHARLIKE_HDR(50)
737     CHARLIKE_HDR(51)
738     CHARLIKE_HDR(52)
739     CHARLIKE_HDR(53)
740     CHARLIKE_HDR(54)
741     CHARLIKE_HDR(55)
742     CHARLIKE_HDR(56)
743     CHARLIKE_HDR(57)
744     CHARLIKE_HDR(58)
745     CHARLIKE_HDR(59)
746     CHARLIKE_HDR(60)
747     CHARLIKE_HDR(61)
748     CHARLIKE_HDR(62)
749     CHARLIKE_HDR(63)
750     CHARLIKE_HDR(64)
751     CHARLIKE_HDR(65)
752     CHARLIKE_HDR(66)
753     CHARLIKE_HDR(67)
754     CHARLIKE_HDR(68)
755     CHARLIKE_HDR(69)
756     CHARLIKE_HDR(70)
757     CHARLIKE_HDR(71)
758     CHARLIKE_HDR(72)
759     CHARLIKE_HDR(73)
760     CHARLIKE_HDR(74)
761     CHARLIKE_HDR(75)
762     CHARLIKE_HDR(76)
763     CHARLIKE_HDR(77)
764     CHARLIKE_HDR(78)
765     CHARLIKE_HDR(79)
766     CHARLIKE_HDR(80)
767     CHARLIKE_HDR(81)
768     CHARLIKE_HDR(82)
769     CHARLIKE_HDR(83)
770     CHARLIKE_HDR(84)
771     CHARLIKE_HDR(85)
772     CHARLIKE_HDR(86)
773     CHARLIKE_HDR(87)
774     CHARLIKE_HDR(88)
775     CHARLIKE_HDR(89)
776     CHARLIKE_HDR(90)
777     CHARLIKE_HDR(91)
778     CHARLIKE_HDR(92)
779     CHARLIKE_HDR(93)
780     CHARLIKE_HDR(94)
781     CHARLIKE_HDR(95)
782     CHARLIKE_HDR(96)
783     CHARLIKE_HDR(97)
784     CHARLIKE_HDR(98)
785     CHARLIKE_HDR(99)
786     CHARLIKE_HDR(100)
787     CHARLIKE_HDR(101)
788     CHARLIKE_HDR(102)
789     CHARLIKE_HDR(103)
790     CHARLIKE_HDR(104)
791     CHARLIKE_HDR(105)
792     CHARLIKE_HDR(106)
793     CHARLIKE_HDR(107)
794     CHARLIKE_HDR(108)
795     CHARLIKE_HDR(109)
796     CHARLIKE_HDR(110)
797     CHARLIKE_HDR(111)
798     CHARLIKE_HDR(112)
799     CHARLIKE_HDR(113)
800     CHARLIKE_HDR(114)
801     CHARLIKE_HDR(115)
802     CHARLIKE_HDR(116)
803     CHARLIKE_HDR(117)
804     CHARLIKE_HDR(118)
805     CHARLIKE_HDR(119)
806     CHARLIKE_HDR(120)
807     CHARLIKE_HDR(121)
808     CHARLIKE_HDR(122)
809     CHARLIKE_HDR(123)
810     CHARLIKE_HDR(124)
811     CHARLIKE_HDR(125)
812     CHARLIKE_HDR(126)
813     CHARLIKE_HDR(127)
814     CHARLIKE_HDR(128)
815     CHARLIKE_HDR(129)
816     CHARLIKE_HDR(130)
817     CHARLIKE_HDR(131)
818     CHARLIKE_HDR(132)
819     CHARLIKE_HDR(133)
820     CHARLIKE_HDR(134)
821     CHARLIKE_HDR(135)
822     CHARLIKE_HDR(136)
823     CHARLIKE_HDR(137)
824     CHARLIKE_HDR(138)
825     CHARLIKE_HDR(139)
826     CHARLIKE_HDR(140)
827     CHARLIKE_HDR(141)
828     CHARLIKE_HDR(142)
829     CHARLIKE_HDR(143)
830     CHARLIKE_HDR(144)
831     CHARLIKE_HDR(145)
832     CHARLIKE_HDR(146)
833     CHARLIKE_HDR(147)
834     CHARLIKE_HDR(148)
835     CHARLIKE_HDR(149)
836     CHARLIKE_HDR(150)
837     CHARLIKE_HDR(151)
838     CHARLIKE_HDR(152)
839     CHARLIKE_HDR(153)
840     CHARLIKE_HDR(154)
841     CHARLIKE_HDR(155)
842     CHARLIKE_HDR(156)
843     CHARLIKE_HDR(157)
844     CHARLIKE_HDR(158)
845     CHARLIKE_HDR(159)
846     CHARLIKE_HDR(160)
847     CHARLIKE_HDR(161)
848     CHARLIKE_HDR(162)
849     CHARLIKE_HDR(163)
850     CHARLIKE_HDR(164)
851     CHARLIKE_HDR(165)
852     CHARLIKE_HDR(166)
853     CHARLIKE_HDR(167)
854     CHARLIKE_HDR(168)
855     CHARLIKE_HDR(169)
856     CHARLIKE_HDR(170)
857     CHARLIKE_HDR(171)
858     CHARLIKE_HDR(172)
859     CHARLIKE_HDR(173)
860     CHARLIKE_HDR(174)
861     CHARLIKE_HDR(175)
862     CHARLIKE_HDR(176)
863     CHARLIKE_HDR(177)
864     CHARLIKE_HDR(178)
865     CHARLIKE_HDR(179)
866     CHARLIKE_HDR(180)
867     CHARLIKE_HDR(181)
868     CHARLIKE_HDR(182)
869     CHARLIKE_HDR(183)
870     CHARLIKE_HDR(184)
871     CHARLIKE_HDR(185)
872     CHARLIKE_HDR(186)
873     CHARLIKE_HDR(187)
874     CHARLIKE_HDR(188)
875     CHARLIKE_HDR(189)
876     CHARLIKE_HDR(190)
877     CHARLIKE_HDR(191)
878     CHARLIKE_HDR(192)
879     CHARLIKE_HDR(193)
880     CHARLIKE_HDR(194)
881     CHARLIKE_HDR(195)
882     CHARLIKE_HDR(196)
883     CHARLIKE_HDR(197)
884     CHARLIKE_HDR(198)
885     CHARLIKE_HDR(199)
886     CHARLIKE_HDR(200)
887     CHARLIKE_HDR(201)
888     CHARLIKE_HDR(202)
889     CHARLIKE_HDR(203)
890     CHARLIKE_HDR(204)
891     CHARLIKE_HDR(205)
892     CHARLIKE_HDR(206)
893     CHARLIKE_HDR(207)
894     CHARLIKE_HDR(208)
895     CHARLIKE_HDR(209)
896     CHARLIKE_HDR(210)
897     CHARLIKE_HDR(211)
898     CHARLIKE_HDR(212)
899     CHARLIKE_HDR(213)
900     CHARLIKE_HDR(214)
901     CHARLIKE_HDR(215)
902     CHARLIKE_HDR(216)
903     CHARLIKE_HDR(217)
904     CHARLIKE_HDR(218)
905     CHARLIKE_HDR(219)
906     CHARLIKE_HDR(220)
907     CHARLIKE_HDR(221)
908     CHARLIKE_HDR(222)
909     CHARLIKE_HDR(223)
910     CHARLIKE_HDR(224)
911     CHARLIKE_HDR(225)
912     CHARLIKE_HDR(226)
913     CHARLIKE_HDR(227)
914     CHARLIKE_HDR(228)
915     CHARLIKE_HDR(229)
916     CHARLIKE_HDR(230)
917     CHARLIKE_HDR(231)
918     CHARLIKE_HDR(232)
919     CHARLIKE_HDR(233)
920     CHARLIKE_HDR(234)
921     CHARLIKE_HDR(235)
922     CHARLIKE_HDR(236)
923     CHARLIKE_HDR(237)
924     CHARLIKE_HDR(238)
925     CHARLIKE_HDR(239)
926     CHARLIKE_HDR(240)
927     CHARLIKE_HDR(241)
928     CHARLIKE_HDR(242)
929     CHARLIKE_HDR(243)
930     CHARLIKE_HDR(244)
931     CHARLIKE_HDR(245)
932     CHARLIKE_HDR(246)
933     CHARLIKE_HDR(247)
934     CHARLIKE_HDR(248)
935     CHARLIKE_HDR(249)
936     CHARLIKE_HDR(250)
937     CHARLIKE_HDR(251)
938     CHARLIKE_HDR(252)
939     CHARLIKE_HDR(253)
940     CHARLIKE_HDR(254)
941     CHARLIKE_HDR(255)
942 }
943
944 section "data" {
945  stg_INTLIKE_closure:
946     INTLIKE_HDR(-16) /* MIN_INTLIKE == -16 */
947     INTLIKE_HDR(-15)
948     INTLIKE_HDR(-14)
949     INTLIKE_HDR(-13)
950     INTLIKE_HDR(-12)
951     INTLIKE_HDR(-11)
952     INTLIKE_HDR(-10)
953     INTLIKE_HDR(-9)
954     INTLIKE_HDR(-8)
955     INTLIKE_HDR(-7)
956     INTLIKE_HDR(-6)
957     INTLIKE_HDR(-5)
958     INTLIKE_HDR(-4)
959     INTLIKE_HDR(-3)
960     INTLIKE_HDR(-2)
961     INTLIKE_HDR(-1)
962     INTLIKE_HDR(0)
963     INTLIKE_HDR(1)
964     INTLIKE_HDR(2)
965     INTLIKE_HDR(3)
966     INTLIKE_HDR(4)
967     INTLIKE_HDR(5)
968     INTLIKE_HDR(6)
969     INTLIKE_HDR(7)
970     INTLIKE_HDR(8)
971     INTLIKE_HDR(9)
972     INTLIKE_HDR(10)
973     INTLIKE_HDR(11)
974     INTLIKE_HDR(12)
975     INTLIKE_HDR(13)
976     INTLIKE_HDR(14)
977     INTLIKE_HDR(15)
978     INTLIKE_HDR(16)  /* MAX_INTLIKE == 16 */
979 }
980
981 #endif