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