2 /* -----------------------------------------------------------------------------
3 * $Id: Assembler.h,v 1.7 1999/07/06 16:17:39 sewardj Exp $
5 * (c) The GHC Team 1994-1998.
9 * NB This is one of the few files shared between Hugs and the runtime system,
10 * so it is very important that it not conflict with either and that it not
12 * (In fact, it might be fun to create a GreenCard interface to this file too.)
13 * ---------------------------------------------------------------------------*/
15 /* ToDo: put this somewhere more sensible */
16 extern void DEBUG_LoadSymbols( char *name );
18 /* This file is supposed to be somewhat self-contained because it is one
19 * of the major external interfaces to the runtime system.
20 * Keeping it self-contained reduces the chance of conflict with Hugs
21 * (or anything else that includes it).
22 * The big disadvantage of being self-contained is that definitions
23 * like AsmNat8, etc duplicate definitions in StgTypes.h.
24 * I'm not sure what we can do about this but, if you try to fix it,
25 * please remember why it was done this way in the first place.
29 typedef unsigned char AsmNat8;
30 typedef unsigned int AsmNat;
31 typedef signed int AsmInt;
32 typedef signed long long int AsmInt64; /* ToDo: not portable! */
33 typedef unsigned int AsmWord;
34 typedef void* AsmAddr;
35 typedef unsigned char AsmChar;
36 typedef float AsmFloat; /* ToDo: not on Alphas! */
37 typedef double AsmDouble;
38 typedef char* AsmString;
40 /* I want to #include this file into the file that defines the
41 * functions but I don't want to expose the structures that
42 * these types point to.
43 * This hack is the best I could think of. Surely there's a better way?
45 #ifdef INSIDE_ASSEMBLER_C
46 typedef struct AsmObject_ *AsmObject;
47 typedef struct AsmBCO_ *AsmBCO;
48 typedef struct AsmCAF_ *AsmCAF;
49 typedef struct AsmCon_ *AsmCon;
50 typedef StgInfoTable *AsmInfo;
51 typedef StgClosure *AsmClosure;
52 typedef Instr AsmInstr;
54 /* the types we export are totally opaque */
55 typedef void *AsmObject;
59 typedef void *AsmInfo;
60 typedef void *AsmClosure;
61 typedef unsigned int AsmInstr;
64 typedef int AsmSp; /* stack offset */
65 typedef int AsmPc; /* program counter */
66 typedef AsmSp AsmVar; /* offset of a Var on the stack */
68 /* --------------------------------------------------------------------------
69 * "Types" used within the assembler
71 * Some of these types are synonyms for the same underlying representation
72 * to let Hugs (or whoever) generate useful Haskell types from the type
73 * of a primitive operation.
75 * Extreme care should be taken if you change any of these - the
76 * same constants are hardwired into Hugs (ILLEGAL_REP) and into
77 * pieces of assembly language used to implement foreign import/export.
78 * And, of course, you'll have to change the primop table in Assembler.c
79 * ------------------------------------------------------------------------*/
84 /* The following can be passed to C */
93 STABLE_REP = 's', /* StablePtr a */
95 #ifdef PROVIDE_FOREIGN
96 FOREIGN_REP = 'f', /* ForeignObj */
99 WEAK_REP = 'w', /* Weak a */
101 BARR_REP = 'x', /* PrimByteArray a */
102 MUTBARR_REP = 'm', /* PrimMutableByteArray s a */
104 /* The following can't be passed to C */
106 ALPHA_REP = 'a', /* a */
107 BETA_REP = 'b', /* b */
108 GAMMA_REP = 'c', /* c */
109 BOOL_REP = 'B', /* Bool */
110 IO_REP = 'i', /* IO a */
111 HANDLER_REP = 'H', /* Exception -> IO a */
112 ERROR_REP = 'E', /* Exception */
113 ARR_REP = 'X', /* PrimArray a */
114 REF_REP = 'R', /* Ref s a */
115 MUTARR_REP = 'M', /* PrimMutableArray s a */
116 #ifdef PROVIDE_CONCURRENT
117 THREADID_REP = 'T', /* ThreadId */
118 MVAR_REP = 'r', /* MVar a */
121 /* Allegedly used in the IO monad */
125 /* --------------------------------------------------------------------------
126 * Allocating (top level) heap objects
127 * ------------------------------------------------------------------------*/
129 extern AsmBCO asmBeginBCO ( int /*StgExpr*/ e );
130 extern void asmEndBCO ( AsmBCO bco );
132 extern AsmBCO asmBeginContinuation ( AsmSp sp, int /*List*/ alts );
133 extern void asmEndContinuation ( AsmBCO bco );
135 extern AsmObject asmMkObject ( AsmClosure c );
137 extern AsmCAF asmBeginCAF ( void );
138 extern void asmEndCAF ( AsmCAF caf, AsmBCO body );
140 extern AsmInfo asmMkInfo ( AsmNat tag, AsmNat ptrs );
141 extern AsmCon asmBeginCon ( AsmInfo info );
142 extern void asmEndCon ( AsmCon con );
144 /* NB: we add ptrs to other objects in left-to-right order.
145 * This is different from pushing arguments on the stack which is done
146 * in right to left order.
148 extern void asmAddPtr ( AsmObject obj, AsmObject arg );
150 extern int asmObjectHasClosure( AsmObject obj );
151 extern AsmClosure asmClosureOfObject ( AsmObject obj );
152 extern void asmMarkObject ( AsmObject obj );
154 extern int asmRepSizeW ( AsmRep rep );
156 /* --------------------------------------------------------------------------
157 * Generating instruction streams
158 * ------------------------------------------------------------------------*/
160 extern AsmSp asmBeginArgCheck ( AsmBCO bco );
161 extern void asmEndArgCheck ( AsmBCO bco, AsmSp last_arg );
163 extern AsmSp asmBeginEnter ( AsmBCO bco );
164 extern void asmEndEnter ( AsmBCO bco, AsmSp sp1, AsmSp sp2 );
166 extern AsmVar asmBind ( AsmBCO bco, AsmRep rep );
167 extern void asmVar ( AsmBCO bco, AsmVar v, AsmRep rep );
169 extern AsmSp asmBeginCase ( AsmBCO bco );
170 extern void asmEndCase ( AsmBCO bco );
171 extern AsmSp asmContinuation ( AsmBCO bco, AsmBCO ret_addr );
173 extern AsmSp asmBeginAlt ( AsmBCO bco );
174 extern void asmEndAlt ( AsmBCO bco, AsmSp sp );
175 extern AsmPc asmTest ( AsmBCO bco, AsmWord tag );
176 extern AsmPc asmTestInt ( AsmBCO bco, AsmVar v, AsmInt x );
177 extern void asmFixBranch ( AsmBCO bco, AsmPc pc );
178 extern void asmPanic ( AsmBCO bco );
180 extern AsmVar asmBox ( AsmBCO bco, AsmRep rep );
181 extern AsmVar asmUnbox ( AsmBCO bco, AsmRep rep );
182 extern void asmReturnUnboxed ( AsmBCO bco, AsmRep rep );
184 /* push unboxed Ints, Floats, etc */
185 extern void asmConstInt ( AsmBCO bco, AsmInt x );
186 extern void asmConstAddr ( AsmBCO bco, AsmAddr x );
187 extern void asmConstWord ( AsmBCO bco, AsmWord x );
188 extern void asmConstChar ( AsmBCO bco, AsmChar x );
189 extern void asmConstFloat ( AsmBCO bco, AsmFloat x );
190 extern void asmConstDouble ( AsmBCO bco, AsmDouble x );
191 extern void asmConstInteger ( AsmBCO bco, AsmString x );
193 /* Which monad (if any) does the primop live in? */
195 MONAD_Id, /* no monad (aka the identity monad) */
205 AsmNat8 prefix; /* should be StgInstr */
206 AsmNat8 opcode; /* should be Primop1 or Primop2 */
209 extern const AsmPrim asmPrimOps[]; /* null terminated list */
211 extern const AsmPrim* asmFindPrim ( char* s );
212 extern const AsmPrim* asmFindPrimop ( AsmInstr prefix, AsmInstr op );
213 extern AsmSp asmBeginPrim ( AsmBCO bco );
214 extern void asmEndPrim ( AsmBCO bco, const AsmPrim* prim, AsmSp base );
216 extern AsmBCO asm_BCO_catch ( void );
217 extern AsmBCO asm_BCO_raise ( void );
218 extern AsmBCO asm_BCO_seq ( void );
221 /* --------------------------------------------------------------------------
223 * ------------------------------------------------------------------------*/
225 extern AsmVar asmClosure ( AsmBCO bco, AsmObject p );
226 extern AsmVar asmGHCClosure ( AsmBCO bco, AsmObject p );
228 extern AsmVar asmAllocCONSTR ( AsmBCO bco, AsmInfo info );
230 extern AsmSp asmBeginPack ( AsmBCO bco );
231 extern void asmEndPack ( AsmBCO bco, AsmVar v, AsmSp start, AsmInfo info );
233 extern void asmBeginUnpack ( AsmBCO bco );
234 extern void asmEndUnpack ( AsmBCO bco );
236 extern AsmVar asmAllocAP ( AsmBCO bco, AsmNat size );
237 extern AsmSp asmBeginMkAP ( AsmBCO bco );
238 extern void asmEndMkAP ( AsmBCO bco, AsmVar v, AsmSp start );
240 extern AsmVar asmAllocPAP ( AsmBCO bco, AsmNat size );
241 extern AsmSp asmBeginMkPAP ( AsmBCO bco );
242 extern void asmEndMkPAP ( AsmBCO bco, AsmVar v, AsmSp start );
244 /* --------------------------------------------------------------------------
246 * ------------------------------------------------------------------------*/
248 extern const AsmPrim ccall_Id;
249 extern const AsmPrim ccall_IO;
263 CFunDescriptor* mkDescriptor( char* as, char* rs );
265 /*-------------------------------------------------------------------------*/