2009-12-30 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / mini / mini-sparc.h
blob5cc2ec47a61ba89b58d75fad52d44ddc8bb2450e
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 #ifndef __linux__
105 * Can't use sigaction on sparc/linux, since it doesn't support SA_SIGINFO. Instead, we
106 * have to use the obsolete sigcontext parameter:
107 * http://www.ussg.iu.edu/hypermail/linux/kernel/0110.3/1531.html.
109 #define MONO_ARCH_USE_SIGACTION 1
110 #endif
112 #ifdef HAVE_WORKING_SIGALTSTACK
113 /*#define MONO_ARCH_SIGSEGV_ON_ALTSTACK*/
114 #endif
116 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
117 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
118 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
119 #define MONO_ARCH_EMULATE_CONV_R8_UN 1
120 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
121 #define MONO_ARCH_EMULATE_FREM 1
122 #define MONO_ARCH_NEED_DIV_CHECK 1
123 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
124 #define MONO_ARCH_HAVE_IMT 1
125 #define MONO_ARCH_IMT_REG sparc_g1
126 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
128 #ifdef SPARCV9
129 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
130 #endif
132 #ifndef __GNUC__
133 /* assume Sun compiler if not GCC */
134 static void * __builtin_return_address(int depth)
136 asm("ta 3");
137 asm("tst %i0");
138 asm("be retAddr_End");
139 asm("mov %fp, %l0");
140 asm("retAddr_Start:");
141 asm("sub %i0, 1, %i0");
142 asm("tst %i0");
143 asm("bne retAddr_Start");
144 #if SPARCV9
145 asm("ldx [%l0+2159], %l0");
146 asm("retAddr_End:");
147 asm("ldx [%l0+2167], %i0");
148 #else
149 asm("ld [%l0+56], %l0");
150 asm("retAddr_End:");
151 asm("ld [%l0+60], %i0");
152 #endif
155 static void * __builtin_frame_address(int depth)
157 asm("ta 3");
158 asm("tst %i0");
159 asm("be frameAddr_End");
160 asm("mov %fp, %l0");
161 asm("frameAddr_Start:");
162 asm("sub %i0, 1, %i0");
163 asm("tst %i0");
164 asm("bne frameAddr_Start");
165 #if SPARCV9
166 asm("ldx [%l0+2159], %l0");
167 asm("frameAddr_End:");
168 asm("ldx [%l0+2159], %i0");
169 #else
170 asm("ld [%l0+56], %l0");
171 asm("frameAddr_End:");
172 asm("ld [%l0+56], %i0");
173 #endif
175 #endif
177 gboolean mono_sparc_is_virtual_call (guint32 *code);
179 gpointer* mono_sparc_get_vcall_slot_addr (guint32 *code, mgreg_t *regs);
181 void mono_sparc_flushw (void);
183 gboolean mono_sparc_is_v9 (void);
185 gboolean mono_sparc_is_sparc64 (void);
187 struct MonoCompile;
189 guint32* mono_sparc_emit_save_lmf (guint32* code, guint32 lmf_offset);
191 guint32* mono_sparc_emit_restore_lmf (guint32 *code, guint32 lmf_offset);
193 #endif /* __MONO_MINI_SPARC_H__ */