comments only
[ghc.git] / includes / stg / MiscClosures.h
1 /* ----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2009
4 *
5 * Declarations for various symbols exported by the RTS.
6 *
7 * ToDo: many of the symbols in here don't need to be exported, but
8 * our Cmm code generator doesn't know how to generate local symbols
9 * for the RTS bits (it assumes all RTS symbols are external).
10 *
11 * See wiki:Commentary/Compiler/Backends/PprC#Prototypes
12 *
13 * Do not #include this file directly: #include "Rts.h" instead.
14 *
15 * To understand the structure of the RTS headers, see the wiki:
16 * http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
17 *
18 * --------------------------------------------------------------------------*/
19
20 #ifndef STGMISCCLOSURES_H
21 #define STGMISCCLOSURES_H
22
23 #if IN_STG_CODE
24 # define RTS_RET_INFO(i) extern W_(i)[]
25 # define RTS_FUN_INFO(i) extern W_(i)[]
26 # define RTS_THUNK_INFO(i) extern W_(i)[]
27 # define RTS_INFO(i) extern W_(i)[]
28 # define RTS_CLOSURE(i) extern W_(i)[]
29 # define RTS_FUN_DECL(f) extern DLL_IMPORT_RTS StgFunPtr f(void)
30 #else
31 # define RTS_RET_INFO(i) extern DLL_IMPORT_RTS const StgRetInfoTable i
32 # define RTS_FUN_INFO(i) extern DLL_IMPORT_RTS const StgFunInfoTable i
33 # define RTS_THUNK_INFO(i) extern DLL_IMPORT_RTS const StgThunkInfoTable i
34 # define RTS_INFO(i) extern DLL_IMPORT_RTS const StgInfoTable i
35 # define RTS_CLOSURE(i) extern DLL_IMPORT_RTS StgClosure i
36 # define RTS_FUN_DECL(f) extern DLL_IMPORT_RTS StgFunPtr f(void)
37 #endif
38
39 #ifdef TABLES_NEXT_TO_CODE
40 # define RTS_RET(f) RTS_INFO(f##_info)
41 # define RTS_ENTRY(f) RTS_INFO(f##_info)
42 # define RTS_FUN(f) RTS_FUN_INFO(f##_info)
43 # define RTS_THUNK(f) RTS_THUNK_INFO(f##_info)
44 #else
45 # define RTS_RET(f) RTS_INFO(f##_info); RTS_FUN_DECL(f##_ret)
46 # define RTS_ENTRY(f) RTS_INFO(f##_info); RTS_FUN_DECL(f##_entry)
47 # define RTS_FUN(f) RTS_FUN_INFO(f##_info); RTS_FUN_DECL(f##_entry)
48 # define RTS_THUNK(f) RTS_THUNK_INFO(f##_info); RTS_FUN_DECL(f##_entry)
49 #endif
50
51 /* Stack frames */
52 RTS_RET(stg_upd_frame);
53 RTS_RET(stg_bh_upd_frame);
54 RTS_RET(stg_marked_upd_frame);
55 RTS_RET(stg_noupd_frame);
56 RTS_RET(stg_catch_frame);
57 RTS_RET(stg_catch_retry_frame);
58 RTS_RET(stg_atomically_frame);
59 RTS_RET(stg_atomically_waiting_frame);
60 RTS_RET(stg_catch_stm_frame);
61 RTS_RET(stg_unmaskAsyncExceptionszh_ret);
62 RTS_RET(stg_maskUninterruptiblezh_ret);
63 RTS_RET(stg_maskAsyncExceptionszh_ret);
64 RTS_RET(stg_stack_underflow_frame);
65 RTS_RET(stg_restore_cccs);
66
67 // RTS_FUN(stg_interp_constr_entry);
68 //
69 // This is referenced using the FFI in the compiler (ByteCodeItbls),
70 // so we can't give it the correct type here because the prototypes
71 // would clash (FFI references are always declared with type StgWord[]
72 // in the generated C code).
73
74 /* Magic glue code for when compiled code returns a value in R1/F1/D1
75 or a VoidRep to the interpreter. */
76 RTS_RET(stg_ctoi_R1p);
77 RTS_RET(stg_ctoi_R1unpt);
78 RTS_RET(stg_ctoi_R1n);
79 RTS_RET(stg_ctoi_F1);
80 RTS_RET(stg_ctoi_D1);
81 RTS_RET(stg_ctoi_L1);
82 RTS_RET(stg_ctoi_V);
83
84 RTS_RET(stg_apply_interp);
85
86 RTS_ENTRY(stg_IND);
87 RTS_ENTRY(stg_IND_direct);
88 RTS_ENTRY(stg_IND_STATIC);
89 RTS_ENTRY(stg_IND_PERM);
90 RTS_ENTRY(stg_BLACKHOLE);
91 RTS_ENTRY(stg_CAF_BLACKHOLE);
92 RTS_ENTRY(__stg_EAGER_BLACKHOLE);
93 RTS_ENTRY(stg_WHITEHOLE);
94 RTS_ENTRY(stg_BLOCKING_QUEUE_CLEAN);
95 RTS_ENTRY(stg_BLOCKING_QUEUE_DIRTY);
96
97 RTS_FUN(stg_BCO);
98 RTS_ENTRY(stg_EVACUATED);
99 RTS_ENTRY(stg_WEAK);
100 RTS_ENTRY(stg_DEAD_WEAK);
101 RTS_ENTRY(stg_STABLE_NAME);
102 RTS_ENTRY(stg_MVAR_CLEAN);
103 RTS_ENTRY(stg_MVAR_DIRTY);
104 RTS_ENTRY(stg_TSO);
105 RTS_ENTRY(stg_STACK);
106 RTS_ENTRY(stg_ARR_WORDS);
107 RTS_ENTRY(stg_MUT_ARR_WORDS);
108 RTS_ENTRY(stg_MUT_ARR_PTRS_CLEAN);
109 RTS_ENTRY(stg_MUT_ARR_PTRS_DIRTY);
110 RTS_ENTRY(stg_MUT_ARR_PTRS_FROZEN);
111 RTS_ENTRY(stg_MUT_ARR_PTRS_FROZEN0);
112 RTS_ENTRY(stg_MUT_VAR_CLEAN);
113 RTS_ENTRY(stg_MUT_VAR_DIRTY);
114 RTS_ENTRY(stg_END_TSO_QUEUE);
115 RTS_ENTRY(stg_MSG_TRY_WAKEUP);
116 RTS_ENTRY(stg_MSG_THROWTO);
117 RTS_ENTRY(stg_MSG_BLACKHOLE);
118 RTS_ENTRY(stg_MSG_NULL);
119 RTS_ENTRY(stg_MVAR_TSO_QUEUE);
120 RTS_ENTRY(stg_catch);
121 RTS_ENTRY(stg_PAP);
122 RTS_ENTRY(stg_AP);
123 RTS_ENTRY(stg_AP_NOUPD);
124 RTS_ENTRY(stg_AP_STACK);
125 RTS_ENTRY(stg_AP_STACK_NOUPD);
126 RTS_ENTRY(stg_dummy_ret);
127 RTS_ENTRY(stg_raise);
128 RTS_ENTRY(stg_raise_ret);
129 RTS_ENTRY(stg_atomically);
130 RTS_ENTRY(stg_TVAR_WATCH_QUEUE);
131 RTS_ENTRY(stg_INVARIANT_CHECK_QUEUE);
132 RTS_ENTRY(stg_ATOMIC_INVARIANT);
133 RTS_ENTRY(stg_TVAR);
134 RTS_ENTRY(stg_TREC_CHUNK);
135 RTS_ENTRY(stg_TREC_HEADER);
136 RTS_ENTRY(stg_END_STM_WATCH_QUEUE);
137 RTS_ENTRY(stg_END_INVARIANT_CHECK_QUEUE);
138 RTS_ENTRY(stg_END_STM_CHUNK_LIST);
139 RTS_ENTRY(stg_NO_TREC);
140
141 /* closures */
142
143 RTS_CLOSURE(stg_END_TSO_QUEUE_closure);
144 RTS_CLOSURE(stg_NO_FINALIZER_closure);
145 RTS_CLOSURE(stg_dummy_ret_closure);
146 RTS_CLOSURE(stg_forceIO_closure);
147
148 RTS_CLOSURE(stg_END_STM_WATCH_QUEUE_closure);
149 RTS_CLOSURE(stg_END_INVARIANT_CHECK_QUEUE_closure);
150 RTS_CLOSURE(stg_END_STM_CHUNK_LIST_closure);
151 RTS_CLOSURE(stg_NO_TREC_closure);
152
153 RTS_ENTRY(stg_NO_FINALIZER_entry);
154
155 #if IN_STG_CODE
156 extern DLL_IMPORT_RTS StgWordArray stg_CHARLIKE_closure;
157 extern DLL_IMPORT_RTS StgWordArray stg_INTLIKE_closure;
158 #else
159 extern DLL_IMPORT_RTS StgIntCharlikeClosure stg_CHARLIKE_closure[];
160 extern DLL_IMPORT_RTS StgIntCharlikeClosure stg_INTLIKE_closure[];
161 #endif
162
163 /* StgStartup */
164
165 RTS_RET(stg_forceIO);
166 RTS_RET(stg_noforceIO);
167
168 /* standard entry points */
169
170 /* standard selector thunks */
171
172 RTS_ENTRY(stg_sel_0_upd);
173 RTS_ENTRY(stg_sel_1_upd);
174 RTS_ENTRY(stg_sel_2_upd);
175 RTS_ENTRY(stg_sel_3_upd);
176 RTS_ENTRY(stg_sel_4_upd);
177 RTS_ENTRY(stg_sel_5_upd);
178 RTS_ENTRY(stg_sel_6_upd);
179 RTS_ENTRY(stg_sel_7_upd);
180 RTS_ENTRY(stg_sel_8_upd);
181 RTS_ENTRY(stg_sel_9_upd);
182 RTS_ENTRY(stg_sel_10_upd);
183 RTS_ENTRY(stg_sel_11_upd);
184 RTS_ENTRY(stg_sel_12_upd);
185 RTS_ENTRY(stg_sel_13_upd);
186 RTS_ENTRY(stg_sel_14_upd);
187 RTS_ENTRY(stg_sel_15_upd);
188
189 RTS_ENTRY(stg_sel_0_noupd);
190 RTS_ENTRY(stg_sel_1_noupd);
191 RTS_ENTRY(stg_sel_2_noupd);
192 RTS_ENTRY(stg_sel_3_noupd);
193 RTS_ENTRY(stg_sel_4_noupd);
194 RTS_ENTRY(stg_sel_5_noupd);
195 RTS_ENTRY(stg_sel_6_noupd);
196 RTS_ENTRY(stg_sel_7_noupd);
197 RTS_ENTRY(stg_sel_8_noupd);
198 RTS_ENTRY(stg_sel_9_noupd);
199 RTS_ENTRY(stg_sel_10_noupd);
200 RTS_ENTRY(stg_sel_11_noupd);
201 RTS_ENTRY(stg_sel_12_noupd);
202 RTS_ENTRY(stg_sel_13_noupd);
203 RTS_ENTRY(stg_sel_14_noupd);
204 RTS_ENTRY(stg_sel_15_noupd);
205
206 /* standard ap thunks */
207
208 RTS_THUNK(stg_ap_1_upd);
209 RTS_THUNK(stg_ap_2_upd);
210 RTS_THUNK(stg_ap_3_upd);
211 RTS_THUNK(stg_ap_4_upd);
212 RTS_THUNK(stg_ap_5_upd);
213 RTS_THUNK(stg_ap_6_upd);
214 RTS_THUNK(stg_ap_7_upd);
215
216 /* standard application routines (see also utils/genapply,
217 * and compiler/codeGen/CgStackery.lhs).
218 */
219 RTS_RET(stg_ap_v);
220 RTS_RET(stg_ap_f);
221 RTS_RET(stg_ap_d);
222 RTS_RET(stg_ap_l);
223 RTS_RET(stg_ap_n);
224 RTS_RET(stg_ap_p);
225 RTS_RET(stg_ap_pv);
226 RTS_RET(stg_ap_pp);
227 RTS_RET(stg_ap_ppv);
228 RTS_RET(stg_ap_ppp);
229 RTS_RET(stg_ap_pppv);
230 RTS_RET(stg_ap_pppp);
231 RTS_RET(stg_ap_ppppp);
232 RTS_RET(stg_ap_pppppp);
233
234 RTS_FUN_DECL(stg_ap_0_fast);
235 RTS_FUN_DECL(stg_ap_v_fast);
236 RTS_FUN_DECL(stg_ap_f_fast);
237 RTS_FUN_DECL(stg_ap_d_fast);
238 RTS_FUN_DECL(stg_ap_l_fast);
239 RTS_FUN_DECL(stg_ap_n_fast);
240 RTS_FUN_DECL(stg_ap_p_fast);
241 RTS_FUN_DECL(stg_ap_pv_fast);
242 RTS_FUN_DECL(stg_ap_pp_fast);
243 RTS_FUN_DECL(stg_ap_ppv_fast);
244 RTS_FUN_DECL(stg_ap_ppp_fast);
245 RTS_FUN_DECL(stg_ap_pppv_fast);
246 RTS_FUN_DECL(stg_ap_pppp_fast);
247 RTS_FUN_DECL(stg_ap_ppppp_fast);
248 RTS_FUN_DECL(stg_ap_pppppp_fast);
249 RTS_FUN_DECL(stg_PAP_apply);
250
251 /* standard GC & stack check entry points, all defined in HeapStackCheck.hc */
252
253 RTS_FUN_DECL(stg_gc_noregs);
254
255 RTS_RET(stg_enter_checkbh);
256
257 RTS_RET(stg_ret_v);
258 RTS_RET(stg_ret_p);
259 RTS_RET(stg_ret_n);
260 RTS_RET(stg_ret_f);
261 RTS_RET(stg_ret_d);
262 RTS_RET(stg_ret_l);
263
264 RTS_FUN_DECL(stg_gc_prim_p);
265 RTS_FUN_DECL(stg_gc_prim_pp);
266 RTS_FUN_DECL(stg_gc_prim_n);
267
268 RTS_RET(stg_enter);
269 RTS_FUN_DECL(__stg_gc_enter_1);
270
271 RTS_FUN_DECL(stg_gc_unpt_r1);
272 RTS_FUN_DECL(stg_gc_unbx_r1);
273 RTS_FUN_DECL(stg_gc_f1);
274 RTS_FUN_DECL(stg_gc_d1);
275 RTS_FUN_DECL(stg_gc_l1);
276 RTS_FUN_DECL(stg_gc_pp);
277 RTS_FUN_DECL(stg_gc_ppp);
278 RTS_FUN_DECL(stg_gc_pppp);
279
280 RTS_RET(stg_gc_fun);
281 RTS_FUN_DECL(__stg_gc_fun);
282
283 RTS_FUN_DECL(stg_yield_noregs);
284 RTS_FUN_DECL(stg_yield_to_interpreter);
285 RTS_FUN_DECL(stg_block_noregs);
286 RTS_FUN_DECL(stg_block_blackhole);
287 RTS_FUN_DECL(stg_block_blackhole_finally);
288 RTS_FUN_DECL(stg_block_takemvar);
289 RTS_RET(stg_block_takemvar);
290 RTS_FUN_DECL(stg_block_putmvar);
291 RTS_RET(stg_block_putmvar);
292 #ifdef mingw32_HOST_OS
293 RTS_FUN_DECL(stg_block_async);
294 RTS_RET(stg_block_async);
295 RTS_FUN_DECL(stg_block_async_void);
296 RTS_RET(stg_block_async_void);
297 #endif
298 RTS_FUN_DECL(stg_block_stmwait);
299 RTS_FUN_DECL(stg_block_throwto);
300 RTS_RET(stg_block_throwto);
301
302 /* Entry/exit points from StgStartup.cmm */
303
304 RTS_RET(stg_stop_thread);
305
306 RTS_FUN_DECL(stg_returnToStackTop);
307 RTS_FUN_DECL(stg_returnToSched);
308 RTS_FUN_DECL(stg_returnToSchedNotPaused);
309 RTS_FUN_DECL(stg_returnToSchedButFirst);
310 RTS_FUN_DECL(stg_threadFinished);
311
312 RTS_FUN_DECL(stg_init_finish);
313 RTS_FUN_DECL(stg_init);
314
315 RTS_FUN_DECL(StgReturn);
316
317 /* -----------------------------------------------------------------------------
318 PrimOps
319 -------------------------------------------------------------------------- */
320
321 RTS_FUN_DECL(stg_plusIntegerzh);
322 RTS_FUN_DECL(stg_minusIntegerzh);
323 RTS_FUN_DECL(stg_timesIntegerzh);
324 RTS_FUN_DECL(stg_gcdIntegerzh);
325 RTS_FUN_DECL(stg_quotRemIntegerzh);
326 RTS_FUN_DECL(stg_quotIntegerzh);
327 RTS_FUN_DECL(stg_remIntegerzh);
328 RTS_FUN_DECL(stg_divExactIntegerzh);
329 RTS_FUN_DECL(stg_divModIntegerzh);
330
331 RTS_FUN_DECL(stg_cmpIntegerIntzh);
332 RTS_FUN_DECL(stg_cmpIntegerzh);
333 RTS_FUN_DECL(stg_integer2Intzh);
334 RTS_FUN_DECL(stg_integer2Wordzh);
335 RTS_FUN_DECL(stg_gcdIntegerIntzh);
336 RTS_FUN_DECL(stg_gcdIntzh);
337
338 RTS_FUN_DECL(stg_int2Integerzh);
339 RTS_FUN_DECL(stg_word2Integerzh);
340
341 RTS_FUN_DECL(stg_decodeFloatzuIntzh);
342 RTS_FUN_DECL(stg_decodeDoublezh);
343 RTS_FUN_DECL(stg_decodeDoublezu2Intzh);
344
345 RTS_FUN_DECL(stg_andIntegerzh);
346 RTS_FUN_DECL(stg_orIntegerzh);
347 RTS_FUN_DECL(stg_xorIntegerzh);
348 RTS_FUN_DECL(stg_complementIntegerzh);
349
350 #if SIZEOF_HSINT == 4
351
352 RTS_FUN_DECL(stg_int64ToIntegerzh);
353 RTS_FUN_DECL(stg_word64ToIntegerzh);
354
355 #endif
356
357 RTS_FUN_DECL(stg_unsafeThawArrayzh);
358 RTS_FUN_DECL(stg_newByteArrayzh);
359 RTS_FUN_DECL(stg_newPinnedByteArrayzh);
360 RTS_FUN_DECL(stg_newAlignedPinnedByteArrayzh);
361 RTS_FUN_DECL(stg_newArrayzh);
362 RTS_FUN_DECL(stg_newArrayArrayzh);
363
364 RTS_FUN_DECL(stg_newMutVarzh);
365 RTS_FUN_DECL(stg_atomicModifyMutVarzh);
366 RTS_FUN_DECL(stg_casMutVarzh);
367
368 RTS_FUN_DECL(stg_isEmptyMVarzh);
369 RTS_FUN_DECL(stg_newMVarzh);
370 RTS_FUN_DECL(stg_takeMVarzh);
371 RTS_FUN_DECL(stg_putMVarzh);
372 RTS_FUN_DECL(stg_tryTakeMVarzh);
373 RTS_FUN_DECL(stg_tryPutMVarzh);
374
375 RTS_FUN_DECL(stg_waitReadzh);
376 RTS_FUN_DECL(stg_waitWritezh);
377 RTS_FUN_DECL(stg_delayzh);
378 #ifdef mingw32_HOST_OS
379 RTS_FUN_DECL(stg_asyncReadzh);
380 RTS_FUN_DECL(stg_asyncWritezh);
381 RTS_FUN_DECL(stg_asyncDoProczh);
382 #endif
383
384 RTS_FUN_DECL(stg_catchzh);
385 RTS_FUN_DECL(stg_raisezh);
386 RTS_FUN_DECL(stg_raiseIOzh);
387
388 RTS_FUN_DECL(stg_makeStableNamezh);
389 RTS_FUN_DECL(stg_makeStablePtrzh);
390 RTS_FUN_DECL(stg_deRefStablePtrzh);
391
392 RTS_FUN_DECL(stg_forkzh);
393 RTS_FUN_DECL(stg_forkOnzh);
394 RTS_FUN_DECL(stg_yieldzh);
395 RTS_FUN_DECL(stg_killThreadzh);
396 RTS_FUN_DECL(stg_getMaskingStatezh);
397 RTS_FUN_DECL(stg_maskAsyncExceptionszh);
398 RTS_FUN_DECL(stg_maskUninterruptiblezh);
399 RTS_FUN_DECL(stg_unmaskAsyncExceptionszh);
400 RTS_FUN_DECL(stg_myThreadIdzh);
401 RTS_FUN_DECL(stg_labelThreadzh);
402 RTS_FUN_DECL(stg_isCurrentThreadBoundzh);
403 RTS_FUN_DECL(stg_threadStatuszh);
404
405 RTS_FUN_DECL(stg_mkWeakzh);
406 RTS_FUN_DECL(stg_mkWeakNoFinalizzerzh);
407 RTS_FUN_DECL(stg_mkWeakForeignzh);
408 RTS_FUN_DECL(stg_mkWeakForeignEnvzh);
409 RTS_FUN_DECL(stg_finalizzeWeakzh);
410 RTS_FUN_DECL(stg_deRefWeakzh);
411
412 RTS_FUN_DECL(stg_newBCOzh);
413 RTS_FUN_DECL(stg_mkApUpd0zh);
414
415 RTS_FUN_DECL(stg_retryzh);
416 RTS_FUN_DECL(stg_catchRetryzh);
417 RTS_FUN_DECL(stg_catchSTMzh);
418 RTS_FUN_DECL(stg_atomicallyzh);
419 RTS_FUN_DECL(stg_newTVarzh);
420 RTS_FUN_DECL(stg_readTVarzh);
421 RTS_FUN_DECL(stg_readTVarIOzh);
422 RTS_FUN_DECL(stg_writeTVarzh);
423 RTS_FUN_DECL(stg_checkzh);
424
425 RTS_FUN_DECL(stg_unpackClosurezh);
426 RTS_FUN_DECL(stg_getApStackValzh);
427 RTS_FUN_DECL(stg_getSparkzh);
428 RTS_FUN_DECL(stg_numSparkszh);
429
430 RTS_FUN_DECL(stg_noDuplicatezh);
431
432 RTS_FUN_DECL(stg_traceCcszh);
433 RTS_FUN_DECL(stg_traceEventzh);
434 RTS_FUN_DECL(stg_traceMarkerzh);
435
436 /* Other misc stuff */
437 // See wiki:Commentary/Compiler/Backends/PprC#Prototypes
438
439 #if IN_STG_CODE && !IN_STGCRUN
440
441 // Interpreter.c
442 extern StgWord rts_stop_next_breakpoint[];
443 extern StgWord rts_stop_on_exception[];
444 extern StgWord rts_breakpoint_io_action[];
445
446 // Schedule.c
447 extern StgWord RTS_VAR(blocked_queue_hd), RTS_VAR(blocked_queue_tl);
448 extern StgWord RTS_VAR(sleeping_queue);
449 extern StgWord RTS_VAR(blackhole_queue);
450 extern StgWord RTS_VAR(sched_mutex);
451
452 // Apply.cmm
453 // canned bitmap for each arg type
454 extern StgWord stg_arg_bitmaps[];
455 extern StgWord stg_ap_stack_entries[];
456 extern StgWord stg_stack_save_entries[];
457
458 // Storage.c
459 extern unsigned int RTS_VAR(g0);
460 extern unsigned int RTS_VAR(large_alloc_lim);
461 extern StgWord RTS_VAR(weak_ptr_list);
462 extern StgWord RTS_VAR(atomic_modify_mutvar_mutex);
463
464 // RtsFlags
465 extern StgWord RTS_VAR(RtsFlags); // bogus type
466
467 // Stable.c
468 extern StgWord RTS_VAR(stable_ptr_table);
469
470 // Profiling.c
471 extern unsigned int RTS_VAR(era);
472 extern unsigned int RTS_VAR(entering_PAP);
473 extern StgWord RTS_VAR(CC_LIST); /* registered CC list */
474 extern StgWord RTS_VAR(CCS_LIST); /* registered CCS list */
475 extern StgWord CCS_SYSTEM[];
476 extern unsigned int RTS_VAR(CC_ID); /* global ids */
477 extern unsigned int RTS_VAR(CCS_ID);
478
479 #endif
480
481 #endif /* STGMISCCLOSURES_H */