2010-04-06 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / mini / mini-sparc.h
blob3f3eefd6ab9ce3f8ca65500a1eb9d88914c9ce68
1 #ifndef __MONO_MINI_SPARC_H__
2 #define __MONO_MINI_SPARC_H__
4 #include <mono/arch/sparc/sparc-codegen.h>
6 #include <glib.h>
8 #define MONO_ARCH_CPU_SPEC sparc_desc
10 #define MONO_MAX_IREGS 32
11 #define MONO_MAX_FREGS 32
13 /* Parameters used by the register allocator */
15 /*
16 * Use %o0..%o5 as local registers, plus %l7 since we need an extra register for
17 * holding the sreg1 in call instructions.
19 #define MONO_ARCH_CALLEE_REGS ((1 << sparc_o0) | (1 << sparc_o1) | (1 << sparc_o2) | (1 << sparc_o3) | (1 << sparc_o4) | (1 << sparc_o5) | (1 << sparc_l7))
21 #define MONO_ARCH_CALLEE_SAVED_REGS ((~MONO_ARCH_CALLEE_REGS) & ~(1 << sparc_g1))
23 #ifdef SPARCV9
24 /* Use %d34..%d62 as the double precision floating point local registers */
25 /* %d32 has the same encoding as %f1, so %d36%d38 == 0b1010 == 0xa */
26 #define MONO_ARCH_CALLEE_FREGS (0xaaaaaaa8)
27 #else
28 /* Use %f2..%f30 as the double precision floating point local registers */
29 #define MONO_ARCH_CALLEE_FREGS (0x55555554)
30 #endif
32 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
34 #define MONO_ARCH_USE_FPSTACK FALSE
35 #define MONO_ARCH_FPSTACK_SIZE 0
36 #ifdef SPARCV9
37 #define MONO_ARCH_INST_FIXED_REG(desc) ((desc == 'o') ? sparc_o0 : -1)
38 #else
39 #define MONO_ARCH_INST_FIXED_REG(desc) ((desc == 'o') ? sparc_o0 : ((desc == 'l') ? sparc_o1 : -1))
40 #endif
41 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
43 #ifdef SPARCV9
44 #define MONO_ARCH_INST_IS_REGPAIR(desc) FALSE
45 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (-1)
46 #else
47 #define MONO_ARCH_INST_IS_REGPAIR(desc) ((desc == 'l') || (desc == 'L'))
48 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (((desc == 'l') ? sparc_o0 : (desc == 'L' ? (hreg1 + 1) : -1)))
49 #endif
51 #if SIZEOF_VOID_P == 8
52 #define MONO_ARCH_FRAME_ALIGNMENT 16
53 #else
54 #define MONO_ARCH_FRAME_ALIGNMENT 8
55 #endif
57 #define MONO_ARCH_CODE_ALIGNMENT 32
59 #define MONO_ARCH_RETREG1 sparc_i0
61 #ifdef SPARCV9
62 #define MONO_SPARC_STACK_BIAS 2047
63 #else
64 #define MONO_SPARC_STACK_BIAS 0
65 #endif
67 struct MonoLMF {
68 gpointer previous_lmf;
69 gpointer lmf_addr;
70 MonoMethod *method;
71 gpointer ip;
72 gpointer sp;
73 gpointer ebp;
76 typedef struct MonoContext {
77 guint8 *ip;
78 gpointer *sp;
79 gpointer *fp;
80 } MonoContext;
82 typedef struct MonoCompileArch {
83 gint32 lmf_offset;
84 gint32 localloc_offset;
85 void *float_spill_slot;
86 } MonoCompileArch;
88 #define MONO_CONTEXT_SET_IP(ctx,eip) do { (ctx)->ip = (gpointer)(eip); } while (0);
89 #define MONO_CONTEXT_SET_BP(ctx,ebp) do { (ctx)->fp = (gpointer*)(ebp); } while (0);
90 #define MONO_CONTEXT_SET_SP(ctx,esp) do { (ctx)->sp = (gpointer*)(esp); } while (0);
92 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->ip))
93 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->fp))
94 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sp))
96 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
97 mono_arch_flush_register_windows (); \
98 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
99 MONO_CONTEXT_SET_BP ((ctx), __builtin_frame_address (0)); \
100 MONO_CONTEXT_SET_SP ((ctx), __builtin_frame_address (0)); \
101 } while (0)
103 #define MONO_ARCH_USE_SIGACTION 1
105 #ifdef HAVE_WORKING_SIGALTSTACK
106 /*#define MONO_ARCH_SIGSEGV_ON_ALTSTACK*/
107 #endif
109 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
110 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
111 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
112 #define MONO_ARCH_EMULATE_CONV_R8_UN 1
113 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
114 #define MONO_ARCH_EMULATE_FREM 1
115 #define MONO_ARCH_NEED_DIV_CHECK 1
116 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
117 #define MONO_ARCH_HAVE_IMT 1
118 #define MONO_ARCH_IMT_REG sparc_g1
119 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
121 #ifdef SPARCV9
122 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
123 #endif
125 #ifndef __GNUC__
126 /* assume Sun compiler if not GCC */
127 static void * __builtin_return_address(int depth)
129 asm("ta 3");
130 asm("tst %i0");
131 asm("be retAddr_End");
132 asm("mov %fp, %l0");
133 asm("retAddr_Start:");
134 asm("sub %i0, 1, %i0");
135 asm("tst %i0");
136 asm("bne retAddr_Start");
137 #if SPARCV9
138 asm("ldx [%l0+2159], %l0");
139 asm("retAddr_End:");
140 asm("ldx [%l0+2167], %i0");
141 #else
142 asm("ld [%l0+56], %l0");
143 asm("retAddr_End:");
144 asm("ld [%l0+60], %i0");
145 #endif
148 static void * __builtin_frame_address(int depth)
150 asm("ta 3");
151 asm("tst %i0");
152 asm("be frameAddr_End");
153 asm("mov %fp, %l0");
154 asm("frameAddr_Start:");
155 asm("sub %i0, 1, %i0");
156 asm("tst %i0");
157 asm("bne frameAddr_Start");
158 #if SPARCV9
159 asm("ldx [%l0+2159], %l0");
160 asm("frameAddr_End:");
161 asm("ldx [%l0+2159], %i0");
162 #else
163 asm("ld [%l0+56], %l0");
164 asm("frameAddr_End:");
165 asm("ld [%l0+56], %i0");
166 #endif
168 #endif
170 gboolean mono_sparc_is_virtual_call (guint32 *code);
172 gpointer* mono_sparc_get_vcall_slot_addr (guint32 *code, mgreg_t *regs);
174 void mono_sparc_flushw (void);
176 gboolean mono_sparc_is_v9 (void);
178 gboolean mono_sparc_is_sparc64 (void);
180 struct MonoCompile;
182 guint32* mono_sparc_emit_save_lmf (guint32* code, guint32 lmf_offset);
184 guint32* mono_sparc_emit_restore_lmf (guint32 *code, guint32 lmf_offset);
186 #endif /* __MONO_MINI_SPARC_H__ */