e566f535a6eeada977e7abffc27839e953a10125
[mono.git] / mono / mini / interp / interp-internals.h
1 #ifndef __MONO_MINI_INTERPRETER_INTERNALS_H__
2 #define __MONO_MINI_INTERPRETER_INTERNALS_H__
3
4 #include <setjmp.h>
5 #include <glib.h>
6 #include <mono/metadata/loader.h>
7 #include <mono/metadata/object.h>
8 #include <mono/metadata/domain-internals.h>
9 #include <mono/metadata/class-internals.h>
10 #include <mono/metadata/debug-internals.h>
11 #include "config.h"
12
13 enum {
14         VAL_I32     = 0,
15         VAL_DOUBLE  = 1,
16         VAL_I64     = 2,
17         VAL_VALUET  = 3,
18         VAL_POINTER = 4,
19         VAL_NATI    = 0 + VAL_POINTER,
20         VAL_MP      = 1 + VAL_POINTER,
21         VAL_TP      = 2 + VAL_POINTER,
22         VAL_OBJ     = 3 + VAL_POINTER
23 };
24
25 #if SIZEOF_VOID_P == 4
26 typedef guint32 mono_u;
27 typedef gint32  mono_i;
28 #elif SIZEOF_VOID_P == 8
29 typedef guint64 mono_u;
30 typedef gint64  mono_i;
31 #endif
32
33 /*
34  * Value types are represented on the eval stack as pointers to the
35  * actual storage. The size field tells how much storage is allocated.
36  * A value type can't be larger than 16 MB.
37  */
38 typedef struct {
39         union {
40                 gint32 i;
41                 gint64 l;
42                 struct {
43                         gint32 lo;
44                         gint32 hi;
45                 } pair;
46                 double f;
47                 /* native size integer and pointer types */
48                 gpointer p;
49                 mono_u nati;
50                 gpointer vt;
51         } data;
52 #if defined(__ppc__) || defined(__powerpc__)
53         int pad;
54 #endif
55 } stackval;
56
57 typedef struct _InterpFrame InterpFrame;
58
59 typedef void (*MonoFuncV) (void);
60 typedef void (*MonoPIFunc) (MonoFuncV callme, void *margs);
61
62 /* 
63  * Structure representing a method transformed for the interpreter 
64  * This is domain specific
65  */
66 typedef struct _InterpMethod
67 {
68         /* NOTE: These first two elements (method and
69            next_jit_code_hash) must be in the same order and at the
70            same offset as in MonoJitInfo, because of the jit_code_hash
71            internal hash table in MonoDomain. */
72         MonoMethod *method;
73         struct _InterpMethod *next_jit_code_hash;
74         guint32 locals_size;
75         guint32 args_size;
76         guint32 stack_size;
77         guint32 vt_stack_size;
78         guint32 alloca_size;
79         unsigned short *code;
80         unsigned short *new_body_start; /* after all STINARG instrs */
81         MonoPIFunc func;
82         int num_clauses;
83         MonoExceptionClause *clauses;
84         void **data_items;
85         int transformed;
86         guint32 *arg_offsets;
87         guint32 *local_offsets;
88         guint32 *exvar_offsets;
89         unsigned int param_count;
90         unsigned int hasthis;
91         gpointer jit_wrapper;
92         gpointer jit_addr;
93         MonoMethodSignature *jit_sig;
94         gpointer jit_entry;
95         MonoType *rtype;
96         MonoType **param_types;
97         MonoJitInfo *jinfo;
98         MonoDomain *domain;
99 } InterpMethod;
100
101 struct _InterpFrame {
102         InterpFrame *parent; /* parent */
103         InterpMethod  *imethod; /* parent */
104         MonoMethod     *method; /* parent */
105         stackval       *retval; /* parent */
106         char           *args;
107         stackval       *stack_args; /* parent */
108         stackval       *stack;
109         stackval       *sp; /* For GC stack marking */
110         unsigned char  *locals;
111         /* exception info */
112         unsigned char  invoke_trap;
113         const unsigned short  *ip;
114         MonoException     *ex;
115         MonoExceptionClause *ex_handler;
116 };
117
118 typedef struct {
119         MonoDomain *original_domain;
120         InterpFrame *base_frame;
121         InterpFrame *current_frame;
122         InterpFrame *env_frame;
123         jmp_buf *current_env;
124         unsigned char search_for_handler;
125         unsigned char managed_code;
126
127         /* Resume state for resuming execution in mixed mode */
128         gboolean       has_resume_state;
129         /* Frame to resume execution at */
130         InterpFrame *handler_frame;
131         /* IP to resume execution at */
132         gpointer handler_ip;
133 } ThreadContext;
134
135 extern int mono_interp_traceopt;
136 extern GSList *jit_classes;
137
138 MonoException *
139 mono_interp_transform_method (InterpMethod *imethod, ThreadContext *context);
140
141 void
142 mono_interp_transform_init (void);
143
144 InterpMethod *
145 mono_interp_get_imethod (MonoDomain *domain, MonoMethod *method, MonoError *error);
146
147 #endif /* __MONO_MINI_INTERPRETER_INTERNALS_H__ */