2 * mini-hppa.h: HPPA backend for the Mono code generator
4 * Copyright (c) 2007 Randolph Chung
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #ifndef __MONO_MINI_HPPA_H__
27 #define __MONO_MINI_HPPA_H__
29 #include <mono/arch/hppa/hppa-codegen.h>
33 #define MONO_ARCH_CPU_SPEC hppa_desc
35 /* HPPA's stack grows towards higher addresses */
36 #define MONO_ARCH_STACK_GROWS_UP
38 #define MONO_MAX_IREGS 32
39 #define MONO_MAX_FREGS 32
41 /* hppa_r20 - hppa_r22 are scratch registers
42 * hppa_r23 - hppa_r26 are the incoming argument registers
43 * hppa_r28, hppa_29 are the return value registers */
44 #define MONO_ARCH_CALLEE_REGS ((0x3f << hppa_r20) | (1 << hppa_r28) | (1 << hppa_r29))
46 /* hppa_r3 - hppa_r19, hppa_27, hppa_30 */
47 #define MONO_ARCH_CALLEE_SAVED_REGS ((0x1ffff << hppa_r3) | (1 << hppa_r27) | (1 << hppa_r30))
49 /* hppa_fr4 - hppa_fr7 are incoming argument registers
50 * hppa_fr8 - hppa_fr11 are scratch registers
51 * hppa_fr22 - hppa_fr31 are scratch registers
52 * we reserve hppa_fr31 for code generation */
53 #define MONO_ARCH_CALLEE_FREGS ((0xff << hppa_fr4) | (0x1ff << hppa_fr22))
55 /* hppa_fr12 - hppa_fr21 */
56 #define MONO_ARCH_CALLEE_SAVED_FREGS (0x3ff << hppa_fr12)
58 #define MONO_ARCH_USE_FPSTACK FALSE
59 #define MONO_ARCH_FPSTACK_SIZE 0
60 #define MONO_ARCH_INST_FIXED_REG(desc) ((desc == 'o') ? hppa_r0 : (desc == 'a') ? hppa_r28 : (desc == 'L') ? hppa_r29 : -1)
61 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
63 #define MONO_ARCH_INST_IS_REGPAIR(desc) ((desc == 'l') || (desc == 'L'))
64 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) ((desc == 'L') ? hppa_r28 : (desc == 'l') ? ((hreg1)+1) : -1)
66 #define MONO_ARCH_FRAME_ALIGNMENT 64
67 #define MONO_ARCH_CODE_ALIGNMENT 32
68 #define HPPA_STACK_LMF_OFFSET 8
71 #define MONO_SAVED_GREGS 18
72 #define MONO_SAVED_GREGS_MASK ((0x1ffff << hppa_r3) | (1 << hppa_r27))
74 #define MONO_SAVED_FREGS 10
75 #define MONO_SAVED_FREGS_MASK (0x003ff000)
76 #define HPPA_IS_SAVED_GREG(i) ((1 << (i)) & MONO_SAVED_GREGS_MASK)
77 #define HPPA_IS_SAVED_FREG(i) ((1 << (i)) & MONO_SAVED_FREGS_MASK)
80 gpointer previous_lmf
;
83 gpointer eip
; /* pc */
84 gpointer ebp
; /* sp */
85 gulong regs
[MONO_SAVED_GREGS
];
86 double fregs
[MONO_SAVED_FREGS
];
89 typedef struct MonoContext
{
92 gulong regs
[MONO_SAVED_GREGS
];
93 double fregs
[MONO_SAVED_FREGS
];
96 typedef struct MonoCompileArch
{
98 gint32 localloc_offset
;
101 #define MONO_CONTEXT_SET_IP(ctx,_ip) do { (ctx)->pc = (int)(_ip); } while (0)
102 #define MONO_CONTEXT_SET_BP(ctx,_bp) do { (ctx)->sp = (int)(_bp); } while (0)
103 #define MONO_CONTEXT_SET_SP(ctx,_sp) do { (ctx)->sp = (int)(_sp); } while (0)
105 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->pc))
106 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->sp))
107 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sp))
109 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
111 asm volatile ("copy %%sp, %0\n" : "=r"(sp)); \
112 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
113 MONO_CONTEXT_SET_BP ((ctx), sp); \
116 #define MONO_ARCH_USE_SIGACTION 1
118 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
119 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
120 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
121 #define MONO_ARCH_EMULATE_CONV_R8_UN 1
122 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
123 #define MONO_ARCH_EMULATE_FREM 1
124 #define MONO_ARCH_EMULATE_DIV 1
125 #define MONO_ARCH_ENABLE_EMIT_STATE_OPT 1
126 #define MONO_ARCH_NEED_DIV_CHECK 1
129 * HPPA does not have an addresable "cflags", so all our compare and branch
130 * instructions are combined
133 #define MONO_EMIT_NEW_COMPARE_BRANCH_BLOCK(cfg,op,sr1,sr2,targetbb) \
136 MonoInst *target_label; \
137 target_label = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst)); \
138 target_label->opcode = OP_LABEL; \
139 target_label->next = (targetbb)->code; \
140 target_label->inst_c0 = (targetbb)->native_offset; \
141 (targetbb)->code = target_label; \
142 inst = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst)); \
143 g_assert (op >= CEE_BEQ && op <= CEE_BLT_UN); \
144 inst->opcode = OP_HPPA_BEQ + (op - CEE_BEQ); \
145 (inst)->sreg1 = sr1; \
146 (inst)->sreg2 = sr2; \
147 inst->inst_i0 = target_label; \
148 inst->flags = MONO_INST_BRLABEL; \
149 mono_bblock_add_inst ((cfg)->cbb, inst); \
152 #define MONO_EMIT_NEW_COMPARE_IMM_BRANCH_BLOCK(cfg, cmp_op, sreg1, imm, block) \
160 MONO_EMIT_NEW_ICONST (cfg, cmp_reg, (imm)); \
162 MONO_EMIT_NEW_COMPARE_BRANCH_BLOCK(cfg, cmp_op, sreg1, cmp_reg, block); \
165 #define MONO_EMIT_NEW_COMPARE_BRANCH_LABEL(cfg, cmp_op, sr1, sr2, label) \
168 g_assert (cmp_op >= CEE_BEQ && cmp_op <= CEE_BLT_UN); \
169 inst = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst)); \
170 inst->opcode = OP_HPPA_BEQ + (cmp_op) - CEE_BEQ; \
173 inst->inst_i0 = label; \
174 inst->flags = MONO_INST_BRLABEL; \
175 mono_bblock_add_inst ((cfg)->cbb, inst); \
178 #define MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL(cfg, cmp_op, sreg1, imm, label) \
186 MONO_EMIT_NEW_ICONST (cfg, cmp_reg, (imm)); \
188 MONO_EMIT_NEW_COMPARE_BRANCH_LABEL(cfg, cmp_op, sreg1, cmp_reg, label); \
191 #define MONO_EMIT_NEW_COMPARE_BRANCH_BLOCK_CHAINED(cfg,op,sr1,sr2,targetbb) \
192 MONO_EMIT_NEW_COMPARE_BRANCH_BLOCK(cfg,op,sr1,sr2,targetbb)
193 #define MONO_EMIT_NEW_COMPARE_IMM_BRANCH_BLOCK_CHAINED(cfg, cmp_op, sreg1, imm, block) \
194 MONO_EMIT_NEW_COMPARE_IMM_BRANCH_BLOCK(cfg, cmp_op, sreg1, imm, block)
195 #define MONO_EMIT_NEW_COMPARE_BRANCH_LABEL_CHAINED(cfg, cmp_op, sr1, sr2, label) \
196 MONO_EMIT_NEW_COMPARE_BRANCH_LABEL(cfg, cmp_op, sr1, sr2, label)
197 #define MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL_CHAINED(cfg, cmp_op, sreg1, imm, label) \
198 MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL(cfg, cmp_op, sreg1, imm, label)
200 #define MONO_EMIT_NEW_HPPA_COND_EXC(cfg,cond,sr1,sr2,name) do { \
202 inst = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst)); \
203 inst->opcode = cond; \
204 inst->inst_p1 = (char*)name; \
207 mono_bblock_add_inst ((cfg)->cbb, inst); \
210 #define MONO_EMIT_NEW_COMPARE_EXC(cfg, cmp_op, sreg1, sreg2, exc) \
211 MONO_EMIT_NEW_HPPA_COND_EXC (cfg, OP_HPPA_COND_EXC_##cmp_op, sreg1, sreg2, exc)
213 #define MONO_EMIT_NEW_COMPARE_IMM_EXC(cfg, cmp_op, sreg1, imm, exc) do { \
220 MONO_EMIT_NEW_ICONST (cfg, cmp_reg, (imm)); \
222 MONO_EMIT_NEW_COMPARE_EXC (cfg, cmp_op, sreg1, cmp_reg, exc); \
225 #define MONO_EMIT_NEW_ICOMPARE_IMM_EXC(cfg, cmp_op, sreg1, imm, exc) do { \
226 MONO_EMIT_NEW_COMPARE_IMM_EXC(cfg, cmp_op, sreg1, imm, exc); \
238 void hppa_patch (guint32
*code
, const gpointer target
);
240 #endif /* __MONO_MINI_HPPA_H__ */