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