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