Fix linker_unload now that we are running constructors in the linker (#8291)
[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    STM_AWOKEN
560
561    This is a static nullary constructor (like []) that we use to mark a
562    thread waiting on an STM wakeup
563    ------------------------------------------------------------------------- */
564
565 INFO_TABLE_CONSTR(stg_STM_AWOKEN,0,0,0,CONSTR_NOCAF_STATIC,"STM_AWOKEN","STM_AWOKEN")
566 { foreign "C" barf("STM_AWOKEN object entered!") never returns; }
567
568 CLOSURE(stg_STM_AWOKEN_closure,stg_STM_AWOKEN);
569
570 /* ----------------------------------------------------------------------------
571    Arrays
572
573    These come in two basic flavours: arrays of data (StgArrWords) and arrays of
574    pointers (StgArrPtrs).  They all have a similar layout:
575
576    ___________________________
577    | Info | No. of | data....
578         |  Ptr | Words  |
579    ---------------------------
580
581    These are *unpointed* objects: i.e. they cannot be entered.
582
583    ------------------------------------------------------------------------- */
584
585 INFO_TABLE(stg_ARR_WORDS, 0, 0, ARR_WORDS, "ARR_WORDS", "ARR_WORDS")
586 { foreign "C" barf("ARR_WORDS object entered!") never returns; }
587
588 INFO_TABLE(stg_MUT_ARR_PTRS_CLEAN, 0, 0, MUT_ARR_PTRS_CLEAN, "MUT_ARR_PTRS_CLEAN", "MUT_ARR_PTRS_CLEAN")
589 { foreign "C" barf("MUT_ARR_PTRS_CLEAN object entered!") never returns; }
590
591 INFO_TABLE(stg_MUT_ARR_PTRS_DIRTY, 0, 0, MUT_ARR_PTRS_DIRTY, "MUT_ARR_PTRS_DIRTY", "MUT_ARR_PTRS_DIRTY")
592 { foreign "C" barf("MUT_ARR_PTRS_DIRTY object entered!") never returns; }
593
594 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN, 0, 0, MUT_ARR_PTRS_FROZEN, "MUT_ARR_PTRS_FROZEN", "MUT_ARR_PTRS_FROZEN")
595 { foreign "C" barf("MUT_ARR_PTRS_FROZEN object entered!") never returns; }
596
597 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN0, 0, 0, MUT_ARR_PTRS_FROZEN0, "MUT_ARR_PTRS_FROZEN0", "MUT_ARR_PTRS_FROZEN0")
598 { foreign "C" barf("MUT_ARR_PTRS_FROZEN0 object entered!") never returns; }
599
600 /* ----------------------------------------------------------------------------
601    Mutable Variables
602    ------------------------------------------------------------------------- */
603
604 INFO_TABLE(stg_MUT_VAR_CLEAN, 1, 0, MUT_VAR_CLEAN, "MUT_VAR_CLEAN", "MUT_VAR_CLEAN")
605 { foreign "C" barf("MUT_VAR_CLEAN object entered!") never returns; }
606 INFO_TABLE(stg_MUT_VAR_DIRTY, 1, 0, MUT_VAR_DIRTY, "MUT_VAR_DIRTY", "MUT_VAR_DIRTY")
607 { foreign "C" barf("MUT_VAR_DIRTY object entered!") never returns; }
608
609 /* ----------------------------------------------------------------------------
610    Dummy return closure
611
612    Entering this closure will just return to the address on the top of the
613    stack.  Useful for getting a thread in a canonical form where we can
614    just enter the top stack word to start the thread.  (see deleteThread)
615  * ------------------------------------------------------------------------- */
616
617 INFO_TABLE( stg_dummy_ret, 0, 0, CONSTR_NOCAF_STATIC, "DUMMY_RET", "DUMMY_RET")
618     ()
619 {
620     return ();
621 }
622 CLOSURE(stg_dummy_ret_closure,stg_dummy_ret);
623
624 /* ----------------------------------------------------------------------------
625    MVAR_TSO_QUEUE
626    ------------------------------------------------------------------------- */
627
628 INFO_TABLE_CONSTR(stg_MVAR_TSO_QUEUE,2,0,0,PRIM,"MVAR_TSO_QUEUE","MVAR_TSO_QUEUE")
629 { foreign "C" barf("MVAR_TSO_QUEUE object entered!") never returns; }
630
631 /* ----------------------------------------------------------------------------
632    CHARLIKE and INTLIKE closures.
633
634    These are static representations of Chars and small Ints, so that
635    we can remove dynamic Chars and Ints during garbage collection and
636    replace them with references to the static objects.
637    ------------------------------------------------------------------------- */
638
639 #if defined(COMPILING_WINDOWS_DLL)
640 /*
641  * When sticking the RTS in a Windows DLL, we delay populating the
642  * Charlike and Intlike tables until load-time, which is only
643  * when we've got the real addresses to the C# and I# closures.
644  *
645  * -- this is currently broken BL 2009/11/14.
646  *    we don't rewrite to static closures at all with Windows DLLs.
647  */
648 // #warning Is this correct? _imp is a pointer!
649 #define Char_hash_static_info _imp__ghczmprim_GHCziTypes_Czh_static_info
650 #define Int_hash_static_info _imp__ghczmprim_GHCziTypes_Izh_static_info
651 #else
652 #define Char_hash_static_info ghczmprim_GHCziTypes_Czh_static_info
653 #define Int_hash_static_info ghczmprim_GHCziTypes_Izh_static_info
654 #endif
655
656
657 #define CHARLIKE_HDR(n)  CLOSURE(Char_hash_static_info, n)
658 #define INTLIKE_HDR(n)   CLOSURE(Int_hash_static_info, n)
659
660 /* put these in the *data* section, since the garbage collector relies
661  * on the fact that static closures live in the data section.
662  */
663
664 #if !(defined(COMPILING_WINDOWS_DLL))
665 section "data" {
666  stg_CHARLIKE_closure:
667     CHARLIKE_HDR(0)
668     CHARLIKE_HDR(1)
669     CHARLIKE_HDR(2)
670     CHARLIKE_HDR(3)
671     CHARLIKE_HDR(4)
672     CHARLIKE_HDR(5)
673     CHARLIKE_HDR(6)
674     CHARLIKE_HDR(7)
675     CHARLIKE_HDR(8)
676     CHARLIKE_HDR(9)
677     CHARLIKE_HDR(10)
678     CHARLIKE_HDR(11)
679     CHARLIKE_HDR(12)
680     CHARLIKE_HDR(13)
681     CHARLIKE_HDR(14)
682     CHARLIKE_HDR(15)
683     CHARLIKE_HDR(16)
684     CHARLIKE_HDR(17)
685     CHARLIKE_HDR(18)
686     CHARLIKE_HDR(19)
687     CHARLIKE_HDR(20)
688     CHARLIKE_HDR(21)
689     CHARLIKE_HDR(22)
690     CHARLIKE_HDR(23)
691     CHARLIKE_HDR(24)
692     CHARLIKE_HDR(25)
693     CHARLIKE_HDR(26)
694     CHARLIKE_HDR(27)
695     CHARLIKE_HDR(28)
696     CHARLIKE_HDR(29)
697     CHARLIKE_HDR(30)
698     CHARLIKE_HDR(31)
699     CHARLIKE_HDR(32)
700     CHARLIKE_HDR(33)
701     CHARLIKE_HDR(34)
702     CHARLIKE_HDR(35)
703     CHARLIKE_HDR(36)
704     CHARLIKE_HDR(37)
705     CHARLIKE_HDR(38)
706     CHARLIKE_HDR(39)
707     CHARLIKE_HDR(40)
708     CHARLIKE_HDR(41)
709     CHARLIKE_HDR(42)
710     CHARLIKE_HDR(43)
711     CHARLIKE_HDR(44)
712     CHARLIKE_HDR(45)
713     CHARLIKE_HDR(46)
714     CHARLIKE_HDR(47)
715     CHARLIKE_HDR(48)
716     CHARLIKE_HDR(49)
717     CHARLIKE_HDR(50)
718     CHARLIKE_HDR(51)
719     CHARLIKE_HDR(52)
720     CHARLIKE_HDR(53)
721     CHARLIKE_HDR(54)
722     CHARLIKE_HDR(55)
723     CHARLIKE_HDR(56)
724     CHARLIKE_HDR(57)
725     CHARLIKE_HDR(58)
726     CHARLIKE_HDR(59)
727     CHARLIKE_HDR(60)
728     CHARLIKE_HDR(61)
729     CHARLIKE_HDR(62)
730     CHARLIKE_HDR(63)
731     CHARLIKE_HDR(64)
732     CHARLIKE_HDR(65)
733     CHARLIKE_HDR(66)
734     CHARLIKE_HDR(67)
735     CHARLIKE_HDR(68)
736     CHARLIKE_HDR(69)
737     CHARLIKE_HDR(70)
738     CHARLIKE_HDR(71)
739     CHARLIKE_HDR(72)
740     CHARLIKE_HDR(73)
741     CHARLIKE_HDR(74)
742     CHARLIKE_HDR(75)
743     CHARLIKE_HDR(76)
744     CHARLIKE_HDR(77)
745     CHARLIKE_HDR(78)
746     CHARLIKE_HDR(79)
747     CHARLIKE_HDR(80)
748     CHARLIKE_HDR(81)
749     CHARLIKE_HDR(82)
750     CHARLIKE_HDR(83)
751     CHARLIKE_HDR(84)
752     CHARLIKE_HDR(85)
753     CHARLIKE_HDR(86)
754     CHARLIKE_HDR(87)
755     CHARLIKE_HDR(88)
756     CHARLIKE_HDR(89)
757     CHARLIKE_HDR(90)
758     CHARLIKE_HDR(91)
759     CHARLIKE_HDR(92)
760     CHARLIKE_HDR(93)
761     CHARLIKE_HDR(94)
762     CHARLIKE_HDR(95)
763     CHARLIKE_HDR(96)
764     CHARLIKE_HDR(97)
765     CHARLIKE_HDR(98)
766     CHARLIKE_HDR(99)
767     CHARLIKE_HDR(100)
768     CHARLIKE_HDR(101)
769     CHARLIKE_HDR(102)
770     CHARLIKE_HDR(103)
771     CHARLIKE_HDR(104)
772     CHARLIKE_HDR(105)
773     CHARLIKE_HDR(106)
774     CHARLIKE_HDR(107)
775     CHARLIKE_HDR(108)
776     CHARLIKE_HDR(109)
777     CHARLIKE_HDR(110)
778     CHARLIKE_HDR(111)
779     CHARLIKE_HDR(112)
780     CHARLIKE_HDR(113)
781     CHARLIKE_HDR(114)
782     CHARLIKE_HDR(115)
783     CHARLIKE_HDR(116)
784     CHARLIKE_HDR(117)
785     CHARLIKE_HDR(118)
786     CHARLIKE_HDR(119)
787     CHARLIKE_HDR(120)
788     CHARLIKE_HDR(121)
789     CHARLIKE_HDR(122)
790     CHARLIKE_HDR(123)
791     CHARLIKE_HDR(124)
792     CHARLIKE_HDR(125)
793     CHARLIKE_HDR(126)
794     CHARLIKE_HDR(127)
795     CHARLIKE_HDR(128)
796     CHARLIKE_HDR(129)
797     CHARLIKE_HDR(130)
798     CHARLIKE_HDR(131)
799     CHARLIKE_HDR(132)
800     CHARLIKE_HDR(133)
801     CHARLIKE_HDR(134)
802     CHARLIKE_HDR(135)
803     CHARLIKE_HDR(136)
804     CHARLIKE_HDR(137)
805     CHARLIKE_HDR(138)
806     CHARLIKE_HDR(139)
807     CHARLIKE_HDR(140)
808     CHARLIKE_HDR(141)
809     CHARLIKE_HDR(142)
810     CHARLIKE_HDR(143)
811     CHARLIKE_HDR(144)
812     CHARLIKE_HDR(145)
813     CHARLIKE_HDR(146)
814     CHARLIKE_HDR(147)
815     CHARLIKE_HDR(148)
816     CHARLIKE_HDR(149)
817     CHARLIKE_HDR(150)
818     CHARLIKE_HDR(151)
819     CHARLIKE_HDR(152)
820     CHARLIKE_HDR(153)
821     CHARLIKE_HDR(154)
822     CHARLIKE_HDR(155)
823     CHARLIKE_HDR(156)
824     CHARLIKE_HDR(157)
825     CHARLIKE_HDR(158)
826     CHARLIKE_HDR(159)
827     CHARLIKE_HDR(160)
828     CHARLIKE_HDR(161)
829     CHARLIKE_HDR(162)
830     CHARLIKE_HDR(163)
831     CHARLIKE_HDR(164)
832     CHARLIKE_HDR(165)
833     CHARLIKE_HDR(166)
834     CHARLIKE_HDR(167)
835     CHARLIKE_HDR(168)
836     CHARLIKE_HDR(169)
837     CHARLIKE_HDR(170)
838     CHARLIKE_HDR(171)
839     CHARLIKE_HDR(172)
840     CHARLIKE_HDR(173)
841     CHARLIKE_HDR(174)
842     CHARLIKE_HDR(175)
843     CHARLIKE_HDR(176)
844     CHARLIKE_HDR(177)
845     CHARLIKE_HDR(178)
846     CHARLIKE_HDR(179)
847     CHARLIKE_HDR(180)
848     CHARLIKE_HDR(181)
849     CHARLIKE_HDR(182)
850     CHARLIKE_HDR(183)
851     CHARLIKE_HDR(184)
852     CHARLIKE_HDR(185)
853     CHARLIKE_HDR(186)
854     CHARLIKE_HDR(187)
855     CHARLIKE_HDR(188)
856     CHARLIKE_HDR(189)
857     CHARLIKE_HDR(190)
858     CHARLIKE_HDR(191)
859     CHARLIKE_HDR(192)
860     CHARLIKE_HDR(193)
861     CHARLIKE_HDR(194)
862     CHARLIKE_HDR(195)
863     CHARLIKE_HDR(196)
864     CHARLIKE_HDR(197)
865     CHARLIKE_HDR(198)
866     CHARLIKE_HDR(199)
867     CHARLIKE_HDR(200)
868     CHARLIKE_HDR(201)
869     CHARLIKE_HDR(202)
870     CHARLIKE_HDR(203)
871     CHARLIKE_HDR(204)
872     CHARLIKE_HDR(205)
873     CHARLIKE_HDR(206)
874     CHARLIKE_HDR(207)
875     CHARLIKE_HDR(208)
876     CHARLIKE_HDR(209)
877     CHARLIKE_HDR(210)
878     CHARLIKE_HDR(211)
879     CHARLIKE_HDR(212)
880     CHARLIKE_HDR(213)
881     CHARLIKE_HDR(214)
882     CHARLIKE_HDR(215)
883     CHARLIKE_HDR(216)
884     CHARLIKE_HDR(217)
885     CHARLIKE_HDR(218)
886     CHARLIKE_HDR(219)
887     CHARLIKE_HDR(220)
888     CHARLIKE_HDR(221)
889     CHARLIKE_HDR(222)
890     CHARLIKE_HDR(223)
891     CHARLIKE_HDR(224)
892     CHARLIKE_HDR(225)
893     CHARLIKE_HDR(226)
894     CHARLIKE_HDR(227)
895     CHARLIKE_HDR(228)
896     CHARLIKE_HDR(229)
897     CHARLIKE_HDR(230)
898     CHARLIKE_HDR(231)
899     CHARLIKE_HDR(232)
900     CHARLIKE_HDR(233)
901     CHARLIKE_HDR(234)
902     CHARLIKE_HDR(235)
903     CHARLIKE_HDR(236)
904     CHARLIKE_HDR(237)
905     CHARLIKE_HDR(238)
906     CHARLIKE_HDR(239)
907     CHARLIKE_HDR(240)
908     CHARLIKE_HDR(241)
909     CHARLIKE_HDR(242)
910     CHARLIKE_HDR(243)
911     CHARLIKE_HDR(244)
912     CHARLIKE_HDR(245)
913     CHARLIKE_HDR(246)
914     CHARLIKE_HDR(247)
915     CHARLIKE_HDR(248)
916     CHARLIKE_HDR(249)
917     CHARLIKE_HDR(250)
918     CHARLIKE_HDR(251)
919     CHARLIKE_HDR(252)
920     CHARLIKE_HDR(253)
921     CHARLIKE_HDR(254)
922     CHARLIKE_HDR(255)
923 }
924
925 section "data" {
926  stg_INTLIKE_closure:
927     INTLIKE_HDR(-16) /* MIN_INTLIKE == -16 */
928     INTLIKE_HDR(-15)
929     INTLIKE_HDR(-14)
930     INTLIKE_HDR(-13)
931     INTLIKE_HDR(-12)
932     INTLIKE_HDR(-11)
933     INTLIKE_HDR(-10)
934     INTLIKE_HDR(-9)
935     INTLIKE_HDR(-8)
936     INTLIKE_HDR(-7)
937     INTLIKE_HDR(-6)
938     INTLIKE_HDR(-5)
939     INTLIKE_HDR(-4)
940     INTLIKE_HDR(-3)
941     INTLIKE_HDR(-2)
942     INTLIKE_HDR(-1)
943     INTLIKE_HDR(0)
944     INTLIKE_HDR(1)
945     INTLIKE_HDR(2)
946     INTLIKE_HDR(3)
947     INTLIKE_HDR(4)
948     INTLIKE_HDR(5)
949     INTLIKE_HDR(6)
950     INTLIKE_HDR(7)
951     INTLIKE_HDR(8)
952     INTLIKE_HDR(9)
953     INTLIKE_HDR(10)
954     INTLIKE_HDR(11)
955     INTLIKE_HDR(12)
956     INTLIKE_HDR(13)
957     INTLIKE_HDR(14)
958     INTLIKE_HDR(15)
959     INTLIKE_HDR(16)  /* MAX_INTLIKE == 16 */
960 }
961
962 #endif