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