2 * Copyright 2011 Xamarin Inc
5 #ifndef __MONO_MINI_ARM_H__
6 #define __MONO_MINI_ARM_H__
8 #include <mono/arch/arm/arm-codegen.h>
9 #include <mono/utils/mono-context.h>
12 #if defined(ARM_FPU_NONE) || (defined(__ARM_EABI__) && !defined(ARM_FPU_VFP) && !defined(ARM_FPU_VFP_HARD))
13 #define MONO_ARCH_SOFT_FLOAT 1
16 #ifdef ARM_FPU_VFP_HARD
17 #error "hardfp-abi not yet supported."
20 #if defined(__ARM_EABI__)
21 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
22 #define ARM_ARCHITECTURE "armel"
24 #define ARM_ARCHITECTURE "armeb"
27 #define ARM_ARCHITECTURE "arm"
30 #if defined(ARM_FPU_FPA)
31 #define ARM_FP_MODEL "fpa"
32 #elif defined(ARM_FPU_VFP)
33 #define ARM_FP_MODEL "vfp"
34 #elif defined(ARM_FPU_NONE)
35 #define ARM_FP_MODEL "soft-float"
36 #elif defined(ARM_FPU_VFP_HARD)
37 #define ARM_FP_MODEL "vfp(hardfp-abi)"
39 #error "At least one of ARM_FPU_NONE, ARM_FPU_FPA, ARM_FPU_VFP or ARM_FPU_VFP_HARD must be defined."
42 #define MONO_ARCH_ARCHITECTURE ARM_ARCHITECTURE "," ARM_FP_MODEL
44 #define MONO_ARCH_CPU_SPEC arm_cpu_desc
46 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
47 #define ARM_LSW_REG ARMREG_R0
48 #define ARM_MSW_REG ARMREG_R1
50 #define ARM_LSW_REG ARMREG_R1
51 #define ARM_MSW_REG ARMREG_R0
54 #define MONO_MAX_IREGS 16
55 #define MONO_MAX_FREGS 16
57 #define MONO_SAVED_GREGS 10 /* r4-r11, ip, lr */
58 #define MONO_SAVED_FREGS 8
60 /* r4-r11, ip, lr: registers saved in the LMF */
61 #define MONO_ARM_REGSAVE_MASK 0x5ff0
62 #define MONO_ARM_FIRST_SAVED_REG ARMREG_R4
63 #define MONO_ARM_NUM_SAVED_REGS 10
65 /* Parameters used by the register allocator */
67 #define MONO_ARCH_CALLEE_REGS ((1<<ARMREG_R0) | (1<<ARMREG_R1) | (1<<ARMREG_R2) | (1<<ARMREG_R3) | (1<<ARMREG_IP))
68 #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))
70 #if defined(ARM_FPU_VFP) || defined(ARM_FPU_VFP_HARD)
71 /* Every double precision vfp register, d0/d1 is reserved for a scratch reg */
72 #define MONO_ARCH_CALLEE_FREGS 0x55555550
74 #define MONO_ARCH_CALLEE_FREGS 0xf
76 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
78 #define MONO_ARCH_USE_FPSTACK FALSE
79 #define MONO_ARCH_FPSTACK_SIZE 0
81 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
83 #ifdef MONO_ARCH_SOFT_FLOAT
84 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'l' || (desc == 'f') || (desc == 'g')) ? ARM_LSW_REG: (((desc) == 'a') ? ARMREG_R0 : -1))
85 #define MONO_ARCH_INST_IS_REGPAIR(desc) ((desc) == 'l' || (desc) == 'L' || (desc) == 'f' || (desc) == 'g')
86 #define MONO_ARCH_INST_IS_FLOAT(desc) (FALSE)
88 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'l')? ARM_LSW_REG: (((desc) == 'a') ? ARMREG_R0 : -1))
89 #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l' || desc == 'L')
90 #define MONO_ARCH_INST_IS_FLOAT(desc) ((desc == 'f') || (desc == 'g'))
92 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' || (desc == 'f') || (desc == 'g')? ARM_MSW_REG : -1)
94 #define MONO_ARCH_FRAME_ALIGNMENT 8
96 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get
97 * reproduceable results for benchmarks */
98 #define MONO_ARCH_CODE_ALIGNMENT 32
100 void arm_patch (guchar
*code
, const guchar
*target
);
101 guint8
* mono_arm_emit_load_imm (guint8
*code
, int dreg
, guint32 val
);
102 int mono_arm_is_rotated_imm8 (guint32 val
, gint
*rot_amount
);
105 mono_arm_throw_exception_by_token (guint32 type_token
, mgreg_t pc
, mgreg_t sp
, mgreg_t
*int_regs
, gdouble
*fp_regs
);
108 MONO_ARM_FPU_NONE
= 0,
109 MONO_ARM_FPU_FPA
= 1,
110 MONO_ARM_FPU_VFP
= 2,
111 MONO_ARM_FPU_VFP_HARD
= 3
114 /* keep the size of the structure a multiple of 8 */
117 * If the second lowest bit is set to 1, then this is a MonoLMFExt structure, and
118 * the other fields are not valid.
120 gpointer previous_lmf
;
122 /* This is only set in trampoline LMF frames */
127 /* all but sp and pc: matches the PUSH instruction layout in the trampolines
128 * 0-4 should be considered undefined (execpt in the magic tramp)
134 typedef struct MonoCompileArch
{
135 gpointer seq_point_info_var
, ss_trigger_page_var
;
136 gpointer seq_point_read_var
, seq_point_ss_method_var
;
137 gpointer seq_point_bp_method_var
;
138 gboolean omit_fp
, omit_fp_computed
;
142 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
143 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
144 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
145 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
146 #define MONO_ARCH_EMULATE_FREM 1
147 #define MONO_ARCH_EMULATE_DIV 1
148 #define MONO_ARCH_EMULATE_CONV_R8_UN 1
149 #define MONO_ARCH_EMULATE_MUL_OVF 1
150 //#define MONO_ARCH_BIGMUL_INTRINS 1
152 #define ARM_FIRST_ARG_REG 0
153 #define ARM_LAST_ARG_REG 3
155 #define MONO_ARCH_USE_SIGACTION 1
156 #define MONO_ARCH_NEED_DIV_CHECK 1
158 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
159 #define MONO_ARCH_HAVE_XP_UNWIND 1
160 #define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
162 #define ARM_NUM_REG_ARGS (ARM_LAST_ARG_REG-ARM_FIRST_ARG_REG+1)
163 #define ARM_NUM_REG_FPARGS 0
165 #define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
166 #define MONO_ARCH_HAVE_IMT 1
167 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
169 #define MONO_ARCH_AOT_SUPPORTED 1
170 #define MONO_ARCH_LLVM_SUPPORTED 1
171 #define MONO_ARCH_THIS_AS_FIRST_ARG 1
173 #define MONO_ARCH_GSHARED_SUPPORTED 1
174 #define MONO_ARCH_DYN_CALL_SUPPORTED 1
175 #define MONO_ARCH_DYN_CALL_PARAM_AREA 24
177 #define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
178 #define MONO_ARCH_HAVE_EXCEPTIONS_INIT 1
179 #define MONO_ARCH_HAVE_GET_TRAMPOLINES 1
180 #define MONO_ARCH_HAVE_CONTEXT_SET_INT_REG 1
181 #define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX 1
182 #define MONO_ARCH_GC_MAPS_SUPPORTED 1
183 #define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK 1
184 #define MONO_ARCH_HAVE_CONTEXT_SET_INT_REG 1
185 #define MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX 1
187 /* Matches the HAVE_AEABI_READ_TP define in mini-arm.c */
188 #if defined(__ARM_EABI__) && defined(__linux__) && !defined(TARGET_ANDROID)
189 #define MONO_ARCH_HAVE_TLS_GET 1
192 /* ARM doesn't have too many registers, so we have to use a callee saved one */
193 #define MONO_ARCH_RGCTX_REG ARMREG_V5
194 /* First argument reg */
195 #define MONO_ARCH_VTABLE_REG ARMREG_R0
197 #define MONO_CONTEXT_SET_LLVM_EXC_REG(ctx, exc) do { (ctx)->regs [0] = (gsize)exc; } while (0)
199 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,func) do { \
200 MONO_CONTEXT_SET_BP ((ctx), __builtin_frame_address (0)); \
201 MONO_CONTEXT_SET_SP ((ctx), __builtin_frame_address (0)); \
202 MONO_CONTEXT_SET_IP ((ctx), (func)); \
205 #define MONO_ARCH_INIT_TOP_LMF_ENTRY(lmf)
208 mono_arm_throw_exception (MonoObject
*exc
, mgreg_t pc
, mgreg_t sp
, mgreg_t
*int_regs
, gdouble
*fp_regs
);
211 mono_arm_throw_exception_by_token (guint32 type_token
, mgreg_t pc
, mgreg_t sp
, mgreg_t
*int_regs
, gdouble
*fp_regs
);
214 mono_arm_resume_unwind (guint32 dummy1
, mgreg_t pc
, mgreg_t sp
, mgreg_t
*int_regs
, gdouble
*fp_regs
);
217 mono_arm_thumb_supported (void);
220 mono_arm_get_exception_trampolines (gboolean aot
) MONO_INTERNAL
;
223 mono_arm_get_thumb_plt_entry (guint8
*code
) MONO_INTERNAL
;
225 #endif /* __MONO_MINI_ARM_H__ */