Make sure x86 ATOMIC_CAS doesn't overwrite its own operands.
[mono-debugger.git] / mono / mini / mini-arm.h
blob7e947c7cbfb9184c6c312a100643a51b6bc55ced
1 #ifndef __MONO_MINI_ARM_H__
2 #define __MONO_MINI_ARM_H__
4 #include <mono/arch/arm/arm-codegen.h>
5 #include <glib.h>
7 #if defined(ARM_FPU_NONE) || defined(ARM_FPU_VFP) || defined(__ARM_EABI__)
8 #define MONO_ARCH_SOFT_FLOAT 1
9 #endif
11 #if defined(__ARM_EABI__)
12 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
13 #define ARM_ARCHITECTURE "armel"
14 #else
15 #define ARM_ARCHITECTURE "armeb"
16 #endif
17 #else
18 #define ARM_ARCHITECTURE "arm"
19 #endif
21 #if defined(ARM_FPU_FPA)
22 #define ARM_FP_MODEL "fpa"
23 #elif defined(ARM_FPU_VFP)
24 #define ARM_FP_MODEL "vfp"
25 #elif defined(ARM_FPU_NONE)
26 #define ARM_FP_MODEL "soft-float"
27 #else
28 #error "At least one of ARM_FPU_NONE or ARM_FPU_FPA or ARM_FPU_VFP must be defined."
29 #endif
31 #define MONO_ARCH_ARCHITECTURE ARM_ARCHITECTURE "," ARM_FP_MODEL
33 #define MONO_ARCH_CPU_SPEC arm_cpu_desc
35 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
36 #define ARM_LSW_REG ARMREG_R0
37 #define ARM_MSW_REG ARMREG_R1
38 #else
39 #define ARM_LSW_REG ARMREG_R1
40 #define ARM_MSW_REG ARMREG_R0
41 #endif
43 #define MONO_MAX_IREGS 16
44 #define MONO_MAX_FREGS 16
46 #define MONO_SAVED_GREGS 10 /* r4-411, ip, lr */
47 #define MONO_SAVED_FREGS 8
49 /* r4-r11, ip, lr: registers saved in the LMF and MonoContext */
50 #define MONO_ARM_REGSAVE_MASK 0x5ff0
52 /* Parameters used by the register allocator */
54 #define MONO_ARCH_CALLEE_REGS ((1<<ARMREG_R0) | (1<<ARMREG_R1) | (1<<ARMREG_R2) | (1<<ARMREG_R3) | (1<<ARMREG_IP))
55 #define MONO_ARCH_CALLEE_SAVED_REGS ((1<<ARMREG_V1) | (1<<ARMREG_V2) | (1<<ARMREG_V3) | (1<<ARMREG_V4) | (1<<ARMREG_V5) | (1<<ARMREG_V6) | (1<<ARMREG_V7))
57 #define MONO_ARCH_CALLEE_FREGS 0xf
58 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
60 #define MONO_ARCH_USE_FPSTACK FALSE
61 #define MONO_ARCH_FPSTACK_SIZE 0
63 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
65 #ifdef MONO_ARCH_SOFT_FLOAT
66 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'l' || (desc == 'f') || (desc == 'g')) ? ARM_LSW_REG: (((desc) == 'a') ? ARMREG_R0 : -1))
67 #define MONO_ARCH_INST_IS_REGPAIR(desc) ((desc) == 'l' || (desc) == 'L' || (desc) == 'f' || (desc) == 'g')
68 #define MONO_ARCH_INST_IS_FLOAT(desc) (FALSE)
69 #else
70 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'l')? ARM_LSW_REG: (((desc) == 'a') ? ARMREG_R0 : -1))
71 #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l' || desc == 'L')
72 #define MONO_ARCH_INST_IS_FLOAT(desc) ((desc == 'f') || (desc == 'g'))
73 #endif
74 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' || (desc == 'f') || (desc == 'g')? ARM_MSW_REG : -1)
76 #define MONO_ARCH_FRAME_ALIGNMENT 8
78 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get
79 * reproduceable results for benchmarks */
80 #define MONO_ARCH_CODE_ALIGNMENT 32
82 void arm_patch (guchar *code, const guchar *target);
83 guint8* mono_arm_emit_load_imm (guint8 *code, int dreg, guint32 val);
84 int mono_arm_is_rotated_imm8 (guint32 val, gint *rot_amount);
86 void
87 mono_arm_throw_exception_by_token (guint32 type_token, unsigned long eip, unsigned long esp, gulong *int_regs, gdouble *fp_regs);
89 /* keep the size of the structure a multiple of 8 */
90 struct MonoLMF {
91 gpointer previous_lmf;
92 gpointer lmf_addr;
93 MonoMethod *method;
94 gulong esp;
95 gulong ebp;
96 gulong eip;
97 gdouble fregs [MONO_SAVED_FREGS]; /* 8..15 */
98 /* all but sp and pc: matches the PUSH instruction layout in the trampolines
99 * 0-4 should be considered undefined (execpt in the magic tramp)
101 gulong iregs [14];
104 /* we define our own structure and we'll copy the data
105 * from sigcontext/ucontext/mach when we need it.
106 * This also makes us save stack space and time when copying
107 * We might also want to add an additional field to propagate
108 * the original context from the signal handler.
110 typedef struct {
111 gulong eip; // pc
112 gulong ebp; // fp
113 gulong esp; // sp
114 gulong regs [MONO_SAVED_GREGS];
115 double fregs [MONO_SAVED_FREGS];
116 } MonoContext;
118 typedef struct MonoCompileArch {
119 int dummy;
120 } MonoCompileArch;
122 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
123 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
124 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
125 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
126 #define MONO_ARCH_EMULATE_FREM 1
127 #define MONO_ARCH_EMULATE_DIV 1
128 #define MONO_ARCH_EMULATE_CONV_R8_UN 1
129 #define MONO_ARCH_EMULATE_MUL_OVF 1
130 //#define MONO_ARCH_BIGMUL_INTRINS 1
132 #define ARM_FIRST_ARG_REG 0
133 #define ARM_LAST_ARG_REG 3
135 #define MONO_ARCH_USE_SIGACTION 1
136 #define MONO_ARCH_NEED_DIV_CHECK 1
138 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
139 #define MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN
140 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
141 #define MONO_ARCH_COMMON_VTABLE_TRAMPOLINE 1
142 #define MONO_ARCH_HAVE_XP_UNWIND 1
144 #define ARM_NUM_REG_ARGS (ARM_LAST_ARG_REG-ARM_FIRST_ARG_REG+1)
145 #define ARM_NUM_REG_FPARGS 0
147 #define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
148 #define MONO_ARCH_HAVE_IMT 1
150 #define MONO_ARCH_AOT_SUPPORTED 1
152 /* ARM doesn't have too many registers, so we have to use a callee saved one */
153 #define MONO_ARCH_RGCTX_REG ARMREG_V5
154 /* First argument reg */
155 #define MONO_ARCH_VTABLE_REG ARMREG_R0
157 /* we have the stack pointer, not the base pointer in sigcontext */
158 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->eip = (int)ip; } while (0);
159 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->ebp = (int)bp; } while (0);
160 #define MONO_CONTEXT_SET_SP(ctx,bp) do { (ctx)->esp = (int)bp; } while (0);
162 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->eip))
163 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->ebp))
164 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->esp))
166 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,func) do { \
167 MONO_CONTEXT_SET_BP ((ctx), __builtin_frame_address (0)); \
168 MONO_CONTEXT_SET_SP ((ctx), __builtin_frame_address (0)); \
169 MONO_CONTEXT_SET_IP ((ctx), (func)); \
170 } while (0)
172 #if __APPLE__
173 #define UCONTEXT_REG_PC(ctx) ((ctx)->uc_mcontext->__ss.__pc)
174 #define UCONTEXT_REG_SP(ctx) ((ctx)->uc_mcontext->__ss.__sp)
175 #define UCONTEXT_REG_R4(ctx) ((ctx)->uc_mcontext->__ss.__r[4])
176 #else
177 #define UCONTEXT_REG_PC(ctx) ((ctx)->sig_ctx.arm_pc)
178 #define UCONTEXT_REG_SP(ctx) ((ctx)->sig_ctx.arm_sp)
179 #define UCONTEXT_REG_R4(ctx) ((ctx)->sig_ctx.arm_r4)
180 #endif
182 void
183 mono_arm_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, gulong *int_regs, gdouble *fp_regs);
185 void
186 mono_arm_throw_exception_by_token (guint32 type_token, unsigned long eip, unsigned long esp, gulong *int_regs, gdouble *fp_regs);
188 #endif /* __MONO_MINI_ARM_H__ */