If a comment says "Is this correct?", it's not.
[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 /* Note: a BLACKHOLE must be big enough to be
287  * overwritten with an indirection/evacuee/catch.  Thus we claim it
288  * has 1 non-pointer word of payload. 
289  */
290 INFO_TABLE(stg_BLACKHOLE,0,1,BLACKHOLE,"BLACKHOLE","BLACKHOLE")
291 {
292     TICK_ENT_BH();
293
294 #ifdef THREADED_RTS
295     // foreign "C" debugBelch("BLACKHOLE entry\n");
296 #endif
297
298     /* Actually this is not necessary because R1 is about to be destroyed. */
299     LDV_ENTER(R1);
300
301 #if defined(THREADED_RTS)
302     ACQUIRE_LOCK(sched_mutex "ptr");
303     // released in stg_block_blackhole_finally
304 #endif
305
306     /* Put ourselves on the blackhole queue */
307     StgTSO__link(CurrentTSO) = W_[blackhole_queue];
308     W_[blackhole_queue] = CurrentTSO;
309
310     /* jot down why and on what closure we are blocked */
311     StgTSO_why_blocked(CurrentTSO) = BlockedOnBlackHole::I16;
312     StgTSO_block_info(CurrentTSO) = R1;
313
314     jump stg_block_blackhole;
315 }
316
317 /* identical to BLACKHOLEs except for the infotag */
318 INFO_TABLE(stg_CAF_BLACKHOLE,0,1,CAF_BLACKHOLE,"CAF_BLACKHOLE","CAF_BLACKHOLE")
319 {
320     TICK_ENT_BH();
321     LDV_ENTER(R1);
322
323 #if defined(THREADED_RTS)
324     // foreign "C" debugBelch("BLACKHOLE entry\n");
325 #endif
326
327 #if defined(THREADED_RTS)
328     ACQUIRE_LOCK(sched_mutex "ptr");
329     // released in stg_block_blackhole_finally
330 #endif
331
332     /* Put ourselves on the blackhole queue */
333     StgTSO__link(CurrentTSO) = W_[blackhole_queue];
334     W_[blackhole_queue] = CurrentTSO;
335
336     /* jot down why and on what closure we are blocked */
337     StgTSO_why_blocked(CurrentTSO) = BlockedOnBlackHole::I16;
338     StgTSO_block_info(CurrentTSO) = R1;
339
340     jump stg_block_blackhole;
341 }
342
343 INFO_TABLE(__stg_EAGER_BLACKHOLE,0,1,BLACKHOLE,"EAGER_BLACKHOLE","EAGER_BLACKHOLE")
344 {
345     TICK_ENT_BH();
346
347 #ifdef THREADED_RTS
348     // foreign "C" debugBelch("BLACKHOLE entry\n");
349 #endif
350
351     /* Actually this is not necessary because R1 is about to be destroyed. */
352     LDV_ENTER(R1);
353
354 #if defined(THREADED_RTS)
355     ACQUIRE_LOCK(sched_mutex "ptr");
356     // released in stg_block_blackhole_finally
357 #endif
358
359     /* Put ourselves on the blackhole queue */
360     StgTSO__link(CurrentTSO) = W_[blackhole_queue];
361     W_[blackhole_queue] = CurrentTSO;
362
363     /* jot down why and on what closure we are blocked */
364     StgTSO_why_blocked(CurrentTSO) = BlockedOnBlackHole::I16;
365     StgTSO_block_info(CurrentTSO) = R1;
366
367     jump stg_block_blackhole;
368 }
369
370 /* ----------------------------------------------------------------------------
371    Whiteholes are used for the "locked" state of a closure (see lockClosure())
372    ------------------------------------------------------------------------- */
373
374 INFO_TABLE(stg_WHITEHOLE, 0,0, WHITEHOLE, "WHITEHOLE", "WHITEHOLE")
375 { foreign "C" barf("WHITEHOLE object entered!") never returns; }
376
377 /* ----------------------------------------------------------------------------
378    Some static info tables for things that don't get entered, and
379    therefore don't need entry code (i.e. boxed but unpointed objects)
380    NON_ENTERABLE_ENTRY_CODE now defined at the beginning of the file
381    ------------------------------------------------------------------------- */
382
383 INFO_TABLE(stg_TSO, 0,0,TSO, "TSO", "TSO")
384 { foreign "C" barf("TSO object entered!") never returns; }
385
386 /* ----------------------------------------------------------------------------
387    Weak pointers
388
389    Live weak pointers have a special closure type.  Dead ones are just
390    nullary constructors (although they live on the heap - we overwrite
391    live weak pointers with dead ones).
392    ------------------------------------------------------------------------- */
393
394 INFO_TABLE(stg_WEAK,1,4,WEAK,"WEAK","WEAK")
395 { foreign "C" barf("WEAK object entered!") never returns; }
396
397 /*
398  * It's important when turning an existing WEAK into a DEAD_WEAK
399  * (which is what finalizeWeak# does) that we don't lose the link
400  * field and break the linked list of weak pointers.  Hence, we give
401  * DEAD_WEAK 5 non-pointer fields.
402  */
403 INFO_TABLE_CONSTR(stg_DEAD_WEAK,0,5,0,CONSTR,"DEAD_WEAK","DEAD_WEAK")
404 { foreign "C" barf("DEAD_WEAK object entered!") never returns; }
405
406 /* ----------------------------------------------------------------------------
407    NO_FINALIZER
408
409    This is a static nullary constructor (like []) that we use to mark an empty
410    finalizer in a weak pointer object.
411    ------------------------------------------------------------------------- */
412
413 INFO_TABLE_CONSTR(stg_NO_FINALIZER,0,0,0,CONSTR_NOCAF_STATIC,"NO_FINALIZER","NO_FINALIZER")
414 { foreign "C" barf("NO_FINALIZER object entered!") never returns; }
415
416 CLOSURE(stg_NO_FINALIZER_closure,stg_NO_FINALIZER);
417
418 /* ----------------------------------------------------------------------------
419    Stable Names are unlifted too.
420    ------------------------------------------------------------------------- */
421
422 INFO_TABLE(stg_STABLE_NAME,0,1,STABLE_NAME,"STABLE_NAME","STABLE_NAME")
423 { foreign "C" barf("STABLE_NAME object entered!") never returns; }
424
425 /* ----------------------------------------------------------------------------
426    MVars
427
428    There are two kinds of these: full and empty.  We need an info table
429    and entry code for each type.
430    ------------------------------------------------------------------------- */
431
432 INFO_TABLE(stg_MVAR_CLEAN,3,0,MVAR_CLEAN,"MVAR","MVAR")
433 { foreign "C" barf("MVAR object entered!") never returns; }
434
435 INFO_TABLE(stg_MVAR_DIRTY,3,0,MVAR_DIRTY,"MVAR","MVAR")
436 { foreign "C" barf("MVAR object entered!") never returns; }
437
438 /* -----------------------------------------------------------------------------
439    STM
440    -------------------------------------------------------------------------- */
441
442 INFO_TABLE(stg_TVAR, 0, 0, TVAR, "TVAR", "TVAR")
443 { foreign "C" barf("TVAR object entered!") never returns; }
444
445 INFO_TABLE(stg_TVAR_WATCH_QUEUE, 0, 0, TVAR_WATCH_QUEUE, "TVAR_WATCH_QUEUE", "TVAR_WATCH_QUEUE")
446 { foreign "C" barf("TVAR_WATCH_QUEUE object entered!") never returns; }
447
448 INFO_TABLE(stg_ATOMIC_INVARIANT, 0, 0, ATOMIC_INVARIANT, "ATOMIC_INVARIANT", "ATOMIC_INVARIANT")
449 { foreign "C" barf("ATOMIC_INVARIANT object entered!") never returns; }
450
451 INFO_TABLE(stg_INVARIANT_CHECK_QUEUE, 0, 0, INVARIANT_CHECK_QUEUE, "INVARIANT_CHECK_QUEUE", "INVARIANT_CHECK_QUEUE")
452 { foreign "C" barf("INVARIANT_CHECK_QUEUE object entered!") never returns; }
453
454 INFO_TABLE(stg_TREC_CHUNK, 0, 0, TREC_CHUNK, "TREC_CHUNK", "TREC_CHUNK")
455 { foreign "C" barf("TREC_CHUNK object entered!") never returns; }
456
457 INFO_TABLE(stg_TREC_HEADER, 0, 0, TREC_HEADER, "TREC_HEADER", "TREC_HEADER")
458 { foreign "C" barf("TREC_HEADER object entered!") never returns; }
459
460 INFO_TABLE_CONSTR(stg_END_STM_WATCH_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_STM_WATCH_QUEUE","END_STM_WATCH_QUEUE")
461 { foreign "C" barf("END_STM_WATCH_QUEUE object entered!") never returns; }
462
463 INFO_TABLE_CONSTR(stg_END_INVARIANT_CHECK_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_INVARIANT_CHECK_QUEUE","END_INVARIANT_CHECK_QUEUE")
464 { foreign "C" barf("END_INVARIANT_CHECK_QUEUE object entered!") never returns; }
465
466 INFO_TABLE_CONSTR(stg_END_STM_CHUNK_LIST,0,0,0,CONSTR_NOCAF_STATIC,"END_STM_CHUNK_LIST","END_STM_CHUNK_LIST")
467 { foreign "C" barf("END_STM_CHUNK_LIST object entered!") never returns; }
468
469 INFO_TABLE_CONSTR(stg_NO_TREC,0,0,0,CONSTR_NOCAF_STATIC,"NO_TREC","NO_TREC")
470 { foreign "C" barf("NO_TREC object entered!") never returns; }
471
472 CLOSURE(stg_END_STM_WATCH_QUEUE_closure,stg_END_STM_WATCH_QUEUE);
473
474 CLOSURE(stg_END_INVARIANT_CHECK_QUEUE_closure,stg_END_INVARIANT_CHECK_QUEUE);
475
476 CLOSURE(stg_END_STM_CHUNK_LIST_closure,stg_END_STM_CHUNK_LIST);
477
478 CLOSURE(stg_NO_TREC_closure,stg_NO_TREC);
479
480 /* ----------------------------------------------------------------------------
481    END_TSO_QUEUE
482
483    This is a static nullary constructor (like []) that we use to mark the
484    end of a linked TSO queue.
485    ------------------------------------------------------------------------- */
486
487 INFO_TABLE_CONSTR(stg_END_TSO_QUEUE,0,0,0,CONSTR_NOCAF_STATIC,"END_TSO_QUEUE","END_TSO_QUEUE")
488 { foreign "C" barf("END_TSO_QUEUE object entered!") never returns; }
489
490 CLOSURE(stg_END_TSO_QUEUE_closure,stg_END_TSO_QUEUE);
491
492 /* ----------------------------------------------------------------------------
493    Exception lists
494    ------------------------------------------------------------------------- */
495
496 INFO_TABLE_CONSTR(stg_END_EXCEPTION_LIST,0,0,0,CONSTR_NOCAF_STATIC,"END_EXCEPTION_LIST","END_EXCEPTION_LIST")
497 { foreign "C" barf("END_EXCEPTION_LIST object entered!") never returns; }
498
499 CLOSURE(stg_END_EXCEPTION_LIST_closure,stg_END_EXCEPTION_LIST);
500
501 INFO_TABLE(stg_EXCEPTION_CONS,1,1,CONSTR,"EXCEPTION_CONS","EXCEPTION_CONS")
502 { foreign "C" barf("EXCEPTION_CONS object entered!") never returns; }
503
504 /* ----------------------------------------------------------------------------
505    Arrays
506
507    These come in two basic flavours: arrays of data (StgArrWords) and arrays of
508    pointers (StgArrPtrs).  They all have a similar layout:
509
510         ___________________________
511         | Info | No. of | data....
512         |  Ptr | Words  |
513         ---------------------------
514
515    These are *unpointed* objects: i.e. they cannot be entered.
516
517    ------------------------------------------------------------------------- */
518
519 INFO_TABLE(stg_ARR_WORDS, 0, 0, ARR_WORDS, "ARR_WORDS", "ARR_WORDS")
520 { foreign "C" barf("ARR_WORDS object entered!") never returns; }
521
522 INFO_TABLE(stg_MUT_ARR_PTRS_CLEAN, 0, 0, MUT_ARR_PTRS_CLEAN, "MUT_ARR_PTRS_CLEAN", "MUT_ARR_PTRS_CLEAN")
523 { foreign "C" barf("MUT_ARR_PTRS_CLEAN object entered!") never returns; }
524
525 INFO_TABLE(stg_MUT_ARR_PTRS_DIRTY, 0, 0, MUT_ARR_PTRS_DIRTY, "MUT_ARR_PTRS_DIRTY", "MUT_ARR_PTRS_DIRTY")
526 { foreign "C" barf("MUT_ARR_PTRS_DIRTY object entered!") never returns; }
527
528 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN, 0, 0, MUT_ARR_PTRS_FROZEN, "MUT_ARR_PTRS_FROZEN", "MUT_ARR_PTRS_FROZEN")
529 { foreign "C" barf("MUT_ARR_PTRS_FROZEN object entered!") never returns; }
530
531 INFO_TABLE(stg_MUT_ARR_PTRS_FROZEN0, 0, 0, MUT_ARR_PTRS_FROZEN0, "MUT_ARR_PTRS_FROZEN0", "MUT_ARR_PTRS_FROZEN0")
532 { foreign "C" barf("MUT_ARR_PTRS_FROZEN0 object entered!") never returns; }
533
534 /* ----------------------------------------------------------------------------
535    Mutable Variables
536    ------------------------------------------------------------------------- */
537
538 INFO_TABLE(stg_MUT_VAR_CLEAN, 1, 0, MUT_VAR_CLEAN, "MUT_VAR_CLEAN", "MUT_VAR_CLEAN")
539 { foreign "C" barf("MUT_VAR_CLEAN object entered!") never returns; }
540 INFO_TABLE(stg_MUT_VAR_DIRTY, 1, 0, MUT_VAR_DIRTY, "MUT_VAR_DIRTY", "MUT_VAR_DIRTY")
541 { foreign "C" barf("MUT_VAR_DIRTY object entered!") never returns; }
542
543 /* ----------------------------------------------------------------------------
544    Dummy return closure
545  
546    Entering this closure will just return to the address on the top of the
547    stack.  Useful for getting a thread in a canonical form where we can
548    just enter the top stack word to start the thread.  (see deleteThread)
549  * ------------------------------------------------------------------------- */
550
551 INFO_TABLE( stg_dummy_ret, 0, 0, CONSTR_NOCAF_STATIC, "DUMMY_RET", "DUMMY_RET")
552 {
553   jump %ENTRY_CODE(Sp(0));
554 }
555 CLOSURE(stg_dummy_ret_closure,stg_dummy_ret);
556
557 /* ----------------------------------------------------------------------------
558    CHARLIKE and INTLIKE closures.  
559
560    These are static representations of Chars and small Ints, so that
561    we can remove dynamic Chars and Ints during garbage collection and
562    replace them with references to the static objects.
563    ------------------------------------------------------------------------- */
564
565 #if defined(__PIC__) && defined(mingw32_TARGET_OS)
566 /*
567  * When sticking the RTS in a Windows DLL, we delay populating the
568  * Charlike and Intlike tables until load-time, which is only
569  * when we've got the real addresses to the C# and I# closures.
570  *      
571  *      -- this is currently broken BL 2009/11/14.
572  *         we don't rewrite to static closures at all with Windows DLLs.
573  */
574 // #warning Is this correct? _imp is a pointer!
575 #define Char_hash_static_info _imp__ghczmprim_GHCziTypes_Czh_static_info
576 #define Int_hash_static_info _imp__ghczmprim_GHCziTypes_Izh_static_info
577 #else
578 #define Char_hash_static_info ghczmprim_GHCziTypes_Czh_static_info
579 #define Int_hash_static_info ghczmprim_GHCziTypes_Izh_static_info
580 #endif
581
582
583 #define CHARLIKE_HDR(n)  CLOSURE(Char_hash_static_info, n)
584 #define INTLIKE_HDR(n)   CLOSURE(Int_hash_static_info, n)
585
586 /* put these in the *data* section, since the garbage collector relies
587  * on the fact that static closures live in the data section.
588  */
589
590 /* end the name with _closure, to convince the mangler this is a closure */
591
592 #if !(defined(__PIC__) && defined(mingw32_HOST_OS))
593 section "data" {
594  stg_CHARLIKE_closure:
595     CHARLIKE_HDR(0)
596     CHARLIKE_HDR(1)
597     CHARLIKE_HDR(2)
598     CHARLIKE_HDR(3)
599     CHARLIKE_HDR(4)
600     CHARLIKE_HDR(5)
601     CHARLIKE_HDR(6)
602     CHARLIKE_HDR(7)
603     CHARLIKE_HDR(8)
604     CHARLIKE_HDR(9)
605     CHARLIKE_HDR(10)
606     CHARLIKE_HDR(11)
607     CHARLIKE_HDR(12)
608     CHARLIKE_HDR(13)
609     CHARLIKE_HDR(14)
610     CHARLIKE_HDR(15)
611     CHARLIKE_HDR(16)
612     CHARLIKE_HDR(17)
613     CHARLIKE_HDR(18)
614     CHARLIKE_HDR(19)
615     CHARLIKE_HDR(20)
616     CHARLIKE_HDR(21)
617     CHARLIKE_HDR(22)
618     CHARLIKE_HDR(23)
619     CHARLIKE_HDR(24)
620     CHARLIKE_HDR(25)
621     CHARLIKE_HDR(26)
622     CHARLIKE_HDR(27)
623     CHARLIKE_HDR(28)
624     CHARLIKE_HDR(29)
625     CHARLIKE_HDR(30)
626     CHARLIKE_HDR(31)
627     CHARLIKE_HDR(32)
628     CHARLIKE_HDR(33)
629     CHARLIKE_HDR(34)
630     CHARLIKE_HDR(35)
631     CHARLIKE_HDR(36)
632     CHARLIKE_HDR(37)
633     CHARLIKE_HDR(38)
634     CHARLIKE_HDR(39)
635     CHARLIKE_HDR(40)
636     CHARLIKE_HDR(41)
637     CHARLIKE_HDR(42)
638     CHARLIKE_HDR(43)
639     CHARLIKE_HDR(44)
640     CHARLIKE_HDR(45)
641     CHARLIKE_HDR(46)
642     CHARLIKE_HDR(47)
643     CHARLIKE_HDR(48)
644     CHARLIKE_HDR(49)
645     CHARLIKE_HDR(50)
646     CHARLIKE_HDR(51)
647     CHARLIKE_HDR(52)
648     CHARLIKE_HDR(53)
649     CHARLIKE_HDR(54)
650     CHARLIKE_HDR(55)
651     CHARLIKE_HDR(56)
652     CHARLIKE_HDR(57)
653     CHARLIKE_HDR(58)
654     CHARLIKE_HDR(59)
655     CHARLIKE_HDR(60)
656     CHARLIKE_HDR(61)
657     CHARLIKE_HDR(62)
658     CHARLIKE_HDR(63)
659     CHARLIKE_HDR(64)
660     CHARLIKE_HDR(65)
661     CHARLIKE_HDR(66)
662     CHARLIKE_HDR(67)
663     CHARLIKE_HDR(68)
664     CHARLIKE_HDR(69)
665     CHARLIKE_HDR(70)
666     CHARLIKE_HDR(71)
667     CHARLIKE_HDR(72)
668     CHARLIKE_HDR(73)
669     CHARLIKE_HDR(74)
670     CHARLIKE_HDR(75)
671     CHARLIKE_HDR(76)
672     CHARLIKE_HDR(77)
673     CHARLIKE_HDR(78)
674     CHARLIKE_HDR(79)
675     CHARLIKE_HDR(80)
676     CHARLIKE_HDR(81)
677     CHARLIKE_HDR(82)
678     CHARLIKE_HDR(83)
679     CHARLIKE_HDR(84)
680     CHARLIKE_HDR(85)
681     CHARLIKE_HDR(86)
682     CHARLIKE_HDR(87)
683     CHARLIKE_HDR(88)
684     CHARLIKE_HDR(89)
685     CHARLIKE_HDR(90)
686     CHARLIKE_HDR(91)
687     CHARLIKE_HDR(92)
688     CHARLIKE_HDR(93)
689     CHARLIKE_HDR(94)
690     CHARLIKE_HDR(95)
691     CHARLIKE_HDR(96)
692     CHARLIKE_HDR(97)
693     CHARLIKE_HDR(98)
694     CHARLIKE_HDR(99)
695     CHARLIKE_HDR(100)
696     CHARLIKE_HDR(101)
697     CHARLIKE_HDR(102)
698     CHARLIKE_HDR(103)
699     CHARLIKE_HDR(104)
700     CHARLIKE_HDR(105)
701     CHARLIKE_HDR(106)
702     CHARLIKE_HDR(107)
703     CHARLIKE_HDR(108)
704     CHARLIKE_HDR(109)
705     CHARLIKE_HDR(110)
706     CHARLIKE_HDR(111)
707     CHARLIKE_HDR(112)
708     CHARLIKE_HDR(113)
709     CHARLIKE_HDR(114)
710     CHARLIKE_HDR(115)
711     CHARLIKE_HDR(116)
712     CHARLIKE_HDR(117)
713     CHARLIKE_HDR(118)
714     CHARLIKE_HDR(119)
715     CHARLIKE_HDR(120)
716     CHARLIKE_HDR(121)
717     CHARLIKE_HDR(122)
718     CHARLIKE_HDR(123)
719     CHARLIKE_HDR(124)
720     CHARLIKE_HDR(125)
721     CHARLIKE_HDR(126)
722     CHARLIKE_HDR(127)
723     CHARLIKE_HDR(128)
724     CHARLIKE_HDR(129)
725     CHARLIKE_HDR(130)
726     CHARLIKE_HDR(131)
727     CHARLIKE_HDR(132)
728     CHARLIKE_HDR(133)
729     CHARLIKE_HDR(134)
730     CHARLIKE_HDR(135)
731     CHARLIKE_HDR(136)
732     CHARLIKE_HDR(137)
733     CHARLIKE_HDR(138)
734     CHARLIKE_HDR(139)
735     CHARLIKE_HDR(140)
736     CHARLIKE_HDR(141)
737     CHARLIKE_HDR(142)
738     CHARLIKE_HDR(143)
739     CHARLIKE_HDR(144)
740     CHARLIKE_HDR(145)
741     CHARLIKE_HDR(146)
742     CHARLIKE_HDR(147)
743     CHARLIKE_HDR(148)
744     CHARLIKE_HDR(149)
745     CHARLIKE_HDR(150)
746     CHARLIKE_HDR(151)
747     CHARLIKE_HDR(152)
748     CHARLIKE_HDR(153)
749     CHARLIKE_HDR(154)
750     CHARLIKE_HDR(155)
751     CHARLIKE_HDR(156)
752     CHARLIKE_HDR(157)
753     CHARLIKE_HDR(158)
754     CHARLIKE_HDR(159)
755     CHARLIKE_HDR(160)
756     CHARLIKE_HDR(161)
757     CHARLIKE_HDR(162)
758     CHARLIKE_HDR(163)
759     CHARLIKE_HDR(164)
760     CHARLIKE_HDR(165)
761     CHARLIKE_HDR(166)
762     CHARLIKE_HDR(167)
763     CHARLIKE_HDR(168)
764     CHARLIKE_HDR(169)
765     CHARLIKE_HDR(170)
766     CHARLIKE_HDR(171)
767     CHARLIKE_HDR(172)
768     CHARLIKE_HDR(173)
769     CHARLIKE_HDR(174)
770     CHARLIKE_HDR(175)
771     CHARLIKE_HDR(176)
772     CHARLIKE_HDR(177)
773     CHARLIKE_HDR(178)
774     CHARLIKE_HDR(179)
775     CHARLIKE_HDR(180)
776     CHARLIKE_HDR(181)
777     CHARLIKE_HDR(182)
778     CHARLIKE_HDR(183)
779     CHARLIKE_HDR(184)
780     CHARLIKE_HDR(185)
781     CHARLIKE_HDR(186)
782     CHARLIKE_HDR(187)
783     CHARLIKE_HDR(188)
784     CHARLIKE_HDR(189)
785     CHARLIKE_HDR(190)
786     CHARLIKE_HDR(191)
787     CHARLIKE_HDR(192)
788     CHARLIKE_HDR(193)
789     CHARLIKE_HDR(194)
790     CHARLIKE_HDR(195)
791     CHARLIKE_HDR(196)
792     CHARLIKE_HDR(197)
793     CHARLIKE_HDR(198)
794     CHARLIKE_HDR(199)
795     CHARLIKE_HDR(200)
796     CHARLIKE_HDR(201)
797     CHARLIKE_HDR(202)
798     CHARLIKE_HDR(203)
799     CHARLIKE_HDR(204)
800     CHARLIKE_HDR(205)
801     CHARLIKE_HDR(206)
802     CHARLIKE_HDR(207)
803     CHARLIKE_HDR(208)
804     CHARLIKE_HDR(209)
805     CHARLIKE_HDR(210)
806     CHARLIKE_HDR(211)
807     CHARLIKE_HDR(212)
808     CHARLIKE_HDR(213)
809     CHARLIKE_HDR(214)
810     CHARLIKE_HDR(215)
811     CHARLIKE_HDR(216)
812     CHARLIKE_HDR(217)
813     CHARLIKE_HDR(218)
814     CHARLIKE_HDR(219)
815     CHARLIKE_HDR(220)
816     CHARLIKE_HDR(221)
817     CHARLIKE_HDR(222)
818     CHARLIKE_HDR(223)
819     CHARLIKE_HDR(224)
820     CHARLIKE_HDR(225)
821     CHARLIKE_HDR(226)
822     CHARLIKE_HDR(227)
823     CHARLIKE_HDR(228)
824     CHARLIKE_HDR(229)
825     CHARLIKE_HDR(230)
826     CHARLIKE_HDR(231)
827     CHARLIKE_HDR(232)
828     CHARLIKE_HDR(233)
829     CHARLIKE_HDR(234)
830     CHARLIKE_HDR(235)
831     CHARLIKE_HDR(236)
832     CHARLIKE_HDR(237)
833     CHARLIKE_HDR(238)
834     CHARLIKE_HDR(239)
835     CHARLIKE_HDR(240)
836     CHARLIKE_HDR(241)
837     CHARLIKE_HDR(242)
838     CHARLIKE_HDR(243)
839     CHARLIKE_HDR(244)
840     CHARLIKE_HDR(245)
841     CHARLIKE_HDR(246)
842     CHARLIKE_HDR(247)
843     CHARLIKE_HDR(248)
844     CHARLIKE_HDR(249)
845     CHARLIKE_HDR(250)
846     CHARLIKE_HDR(251)
847     CHARLIKE_HDR(252)
848     CHARLIKE_HDR(253)
849     CHARLIKE_HDR(254)
850     CHARLIKE_HDR(255)
851 }
852
853 section "data" {
854  stg_INTLIKE_closure:
855     INTLIKE_HDR(-16)    /* MIN_INTLIKE == -16 */
856     INTLIKE_HDR(-15)
857     INTLIKE_HDR(-14)
858     INTLIKE_HDR(-13)
859     INTLIKE_HDR(-12)
860     INTLIKE_HDR(-11)
861     INTLIKE_HDR(-10)
862     INTLIKE_HDR(-9)
863     INTLIKE_HDR(-8)
864     INTLIKE_HDR(-7)
865     INTLIKE_HDR(-6)
866     INTLIKE_HDR(-5)
867     INTLIKE_HDR(-4)
868     INTLIKE_HDR(-3)
869     INTLIKE_HDR(-2)
870     INTLIKE_HDR(-1)
871     INTLIKE_HDR(0)
872     INTLIKE_HDR(1)
873     INTLIKE_HDR(2)
874     INTLIKE_HDR(3)
875     INTLIKE_HDR(4)
876     INTLIKE_HDR(5)
877     INTLIKE_HDR(6)
878     INTLIKE_HDR(7)
879     INTLIKE_HDR(8)
880     INTLIKE_HDR(9)
881     INTLIKE_HDR(10)
882     INTLIKE_HDR(11)
883     INTLIKE_HDR(12)
884     INTLIKE_HDR(13)
885     INTLIKE_HDR(14)
886     INTLIKE_HDR(15)
887     INTLIKE_HDR(16)     /* MAX_INTLIKE == 16 */
888 }
889
890 #endif // !(defined(__PIC__) && defined(mingw32_HOST_OS))