Debian Codegraph @

src/cpu/core_dynrec/risc_armv4le-s3.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /* $Id: risc_armv4le-s3.h,v 1.6 2009-06-27 12:51:10 c2woody Exp $ */
20
21
22 /* ARMv4 (little endian) backend by M-HT (speed-tweaked arm version) */
23
24
25 // temporary registers
26 #define temp1 HOST_ip
27 #define temp2 HOST_v3
28 #define temp3 HOST_v4
29
30 // register that holds function return values
31 #define FC_RETOP HOST_a1
32
33 // register used for address calculations,
34 #define FC_ADDR HOST_v1 // has to be saved across calls, see DRC_PROTECT_ADDR_REG
35
36 // register that holds the first parameter
37 #define FC_OP1 HOST_a1
38
39 // register that holds the second parameter
40 #define FC_OP2 HOST_a2
41
42 // special register that holds the third parameter for _R3 calls (byte accessible)
43 #define FC_OP3 HOST_v2
44
45 // register that holds byte-accessible temporary values
46 #define FC_TMP_BA1 HOST_a1
47
48 // register that holds byte-accessible temporary values
49 #define FC_TMP_BA2 HOST_a2
50
51 // temporary register for LEA
52 #define TEMP_REG_DRC HOST_v2
53
54 #ifdef DRC_USE_REGS_ADDR
55 // used to hold the address of "cpu_regs" - preferably filled in function gen_run_code
56 #define FC_REGS_ADDR HOST_v7
57 #endif
58
59 #ifdef DRC_USE_SEGS_ADDR
60 // used to hold the address of "Segs" - preferably filled in function gen_run_code
61 #define FC_SEGS_ADDR HOST_v8
62 #endif
63
64
65 // helper macro
66 #define ROTATE_SCALE(x) ( (x)?(32 - x):(0) )
67
68
69 // instruction encodings
70
71 // move
72 // mov dst, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
73 #define MOV_IMM(dst, imm, rimm) (0xe3a00000 + ((dst) << 12) + (imm) + ((rimm) << 7) )
74 // mov dst, src, lsl #imm
75 #define MOV_REG_LSL_IMM(dst, src, imm) (0xe1a00000 + ((dst) << 12) + (src) + ((imm) << 7) )
76 // movs dst, src, lsl #imm
77 #define MOVS_REG_LSL_IMM(dst, src, imm) (0xe1b00000 + ((dst) << 12) + (src) + ((imm) << 7) )
78 // mov dst, src, lsr #imm
79 #define MOV_REG_LSR_IMM(dst, src, imm) (0xe1a00020 + ((dst) << 12) + (src) + ((imm) << 7) )
80 // mov dst, src, asr #imm
81 #define MOV_REG_ASR_IMM(dst, src, imm) (0xe1a00040 + ((dst) << 12) + (src) + ((imm) << 7) )
82 // mov dst, src, lsl rreg
83 #define MOV_REG_LSL_REG(dst, src, rreg) (0xe1a00010 + ((dst) << 12) + (src) + ((rreg) << 8) )
84 // mov dst, src, lsr rreg
85 #define MOV_REG_LSR_REG(dst, src, rreg) (0xe1a00030 + ((dst) << 12) + (src) + ((rreg) << 8) )
86 // mov dst, src, asr rreg
87 #define MOV_REG_ASR_REG(dst, src, rreg) (0xe1a00050 + ((dst) << 12) + (src) + ((rreg) << 8) )
88 // mov dst, src, ror rreg
89 #define MOV_REG_ROR_REG(dst, src, rreg) (0xe1a00070 + ((dst) << 12) + (src) + ((rreg) << 8) )
90 // mvn dst, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
91 #define MVN_IMM(dst, imm, rimm) (0xe3e00000 + ((dst) << 12) + (imm) + ((rimm) << 7) )
92
93 // arithmetic
94 // add dst, src, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
95 #define ADD_IMM(dst, src, imm, rimm) (0xe2800000 + ((dst) << 12) + ((src) << 16) + (imm) + ((rimm) << 7) )
96 // add dst, src1, src2, lsl #imm
97 #define ADD_REG_LSL_IMM(dst, src1, src2, imm) (0xe0800000 + ((dst) << 12) + ((src1) << 16) + (src2) + ((imm) << 7) )
98 // sub dst, src, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
99 #define SUB_IMM(dst, src, imm, rimm) (0xe2400000 + ((dst) << 12) + ((src) << 16) + (imm) + ((rimm) << 7) )
100 // sub dst, src1, src2, lsl #imm
101 #define SUB_REG_LSL_IMM(dst, src1, src2, imm) (0xe0400000 + ((dst) << 12) + ((src1) << 16) + (src2) + ((imm) << 7) )
102 // rsb dst, src, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
103 #define RSB_IMM(dst, src, imm, rimm) (0xe2600000 + ((dst) << 12) + ((src) << 16) + (imm) + ((rimm) << 7) )
104 // cmp src, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
105 #define CMP_IMM(src, imm, rimm) (0xe3500000 + ((src) << 16) + (imm) + ((rimm) << 7) )
106 // nop
107 #define NOP MOV_REG_LSL_IMM(HOST_r0, HOST_r0, 0)
108
109 // logical
110 // tst src, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
111 #define TST_IMM(src, imm, rimm) (0xe3100000 + ((src) << 16) + (imm) + ((rimm) << 7) )
112 // and dst, src, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
113 #define AND_IMM(dst, src, imm, rimm) (0xe2000000 + ((dst) << 12) + ((src) << 16) + (imm) + ((rimm) << 7) )
114 // and dst, src1, src2, lsl #imm
115 #define AND_REG_LSL_IMM(dst, src1, src2, imm) (0xe0000000 + ((dst) << 12) + ((src1) << 16) + (src2) + ((imm) << 7) )
116 // orr dst, src, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
117 #define ORR_IMM(dst, src, imm, rimm) (0xe3800000 + ((dst) << 12) + ((src) << 16) + (imm) + ((rimm) << 7) )
118 // orr dst, src1, src2, lsl #imm
119 #define ORR_REG_LSL_IMM(dst, src1, src2, imm) (0xe1800000 + ((dst) << 12) + ((src1) << 16) + (src2) + ((imm) << 7) )
120 // orr dst, src1, src2, lsr #imm
121 #define ORR_REG_LSR_IMM(dst, src1, src2, imm) (0xe1800020 + ((dst) << 12) + ((src1) << 16) + (src2) + ((imm) << 7) )
122 // eor dst, src1, src2, lsl #imm
123 #define EOR_REG_LSL_IMM(dst, src1, src2, imm) (0xe0200000 + ((dst) << 12) + ((src1) << 16) + (src2) + ((imm) << 7) )
124 // bic dst, src, #(imm ror rimm) @ 0 <= imm <= 255 & rimm mod 2 = 0
125 #define BIC_IMM(dst, src, imm, rimm) (0xe3c00000 + ((dst) << 12) + ((src) << 16) + (imm) + ((rimm) << 7) )
126
127 // load
128 // ldr reg, [addr, #imm] @ 0 <= imm < 4096
129 #define LDR_IMM(reg, addr, imm) (0xe5900000 + ((reg) << 12) + ((addr) << 16) + (imm) )
130 // ldrh reg, [addr, #imm] @ 0 <= imm < 256
131 #define LDRH_IMM(reg, addr, imm) (0xe1d000b0 + ((reg) << 12) + ((addr) << 16) + (((imm) & 0xf0) << 4) + ((imm) & 0x0f) )
132 // ldrb reg, [addr, #imm] @ 0 <= imm < 4096
133 #define LDRB_IMM(reg, addr, imm) (0xe5d00000 + ((reg) << 12) + ((addr) << 16) + (imm) )
134
135 // store
136 // str reg, [addr, #imm] @ 0 <= imm < 4096
137 #define STR_IMM(reg, addr, imm) (0xe5800000 + ((reg) << 12) + ((addr) << 16) + (imm) )
138 // strh reg, [addr, #imm] @ 0 <= imm < 256
139 #define STRH_IMM(reg, addr, imm) (0xe1c000b0 + ((reg) << 12) + ((addr) << 16) + (((imm) & 0xf0) << 4) + ((imm) & 0x0f) )
140 // strb reg, [addr, #imm] @ 0 <= imm < 4096
141 #define STRB_IMM(reg, addr, imm) (0xe5c00000 + ((reg) << 12) + ((addr) << 16) + (imm) )
142
143 // branch
144 // beq pc+imm @ 0 <= imm < 32M & imm mod 4 = 0
145 #define BEQ_FWD(imm) (0x0a000000 + ((imm) >> 2) )
146 // bne pc+imm @ 0 <= imm < 32M & imm mod 4 = 0
147 #define BNE_FWD(imm) (0x1a000000 + ((imm) >> 2) )
148 // bgt pc+imm @ 0 <= imm < 32M & imm mod 4 = 0
149 #define BGT_FWD(imm) (0xca000000 + ((imm) >> 2) )
150 // b pc+imm @ 0 <= imm < 32M & imm mod 4 = 0
151 #define B_FWD(imm) (0xea000000 + ((imm) >> 2) )
152 // bx reg
153 #define BX(reg) (0xe12fff10 + (reg) )
154
155
156 // move a full register from reg_src to reg_dst
157 static void gen_mov_regs(HostReg reg_dst,HostReg reg_src) {
158 if(reg_src == reg_dst) return;
159 cache_addd( MOV_REG_LSL_IMM(reg_dst, reg_src, 0) ); // mov reg_dst, reg_src
160 }
161
162 // move a 32bit constant value into dest_reg
163 static void gen_mov_dword_to_reg_imm(HostReg dest_reg,Bit32u imm) {
164 Bits first, scale;
165 if (imm == 0) {
166 cache_addd( MOV_IMM(dest_reg, 0, 0) ); // mov dest_reg, #0
167 } else {
168 scale = 0;
169 first = 1;
170 while (imm) {
171 while ((imm & 3) == 0) {
172 imm>>=2;
173 scale+=2;
174 }
175 if (first) {
176 cache_addd( MOV_IMM(dest_reg, imm & 0xff, ROTATE_SCALE(scale)) ); // mov dest_reg, #((imm & 0xff) << scale)
177 first = 0;
178 } else {
179 cache_addd( ORR_IMM(dest_reg, dest_reg, imm & 0xff, ROTATE_SCALE(scale)) ); // orr dest_reg, dest_reg, #((imm & 0xff) << scale)
180 }
181 imm>>=8;
182 scale+=8;
183 }
184 }
185 }
186
187 // helper function for gen_mov_word_to_reg
188 static void gen_mov_word_to_reg_helper(HostReg dest_reg,void* data,bool dword,HostReg data_reg) {
189 // alignment....
190 if (dword) {
191 if ((Bit32u)data & 3) {
192 if ( ((Bit32u)data & 3) == 2 ) {
193 cache_addd( LDRH_IMM(dest_reg, data_reg, 0) ); // ldrh dest_reg, [data_reg]
194 cache_addd( LDRH_IMM(temp2, data_reg, 2) ); // ldrh temp2, [data_reg, #2]
195 cache_addd( ORR_REG_LSL_IMM(dest_reg, dest_reg, temp2, 16) ); // orr dest_reg, dest_reg, temp2, lsl #16
196 } else {
197 cache_addd( LDRB_IMM(dest_reg, data_reg, 0) ); // ldrb dest_reg, [data_reg]
198 cache_addd( LDRH_IMM(temp2, data_reg, 1) ); // ldrh temp2, [data_reg, #1]
199 cache_addd( ORR_REG_LSL_IMM(dest_reg, dest_reg, temp2, 8) ); // orr dest_reg, dest_reg, temp2, lsl #8
200 cache_addd( LDRB_IMM(temp2, data_reg, 3) ); // ldrb temp2, [data_reg, #3]
201 cache_addd( ORR_REG_LSL_IMM(dest_reg, dest_reg, temp2, 24) ); // orr dest_reg, dest_reg, temp2, lsl #24
202 }
203 } else {
204 cache_addd( LDR_IMM(dest_reg, data_reg, 0) ); // ldr dest_reg, [data_reg]
205 }
206 } else {
207 if ((Bit32u)data & 1) {
208 cache_addd( LDRB_IMM(dest_reg, data_reg, 0) ); // ldrb dest_reg, [data_reg]
209 cache_addd( LDRB_IMM(temp2, data_reg, 1) ); // ldrb temp2, [data_reg, #1]
210 cache_addd( ORR_REG_LSL_IMM(dest_reg, dest_reg, temp2, 8) ); // orr dest_reg, dest_reg, temp2, lsl #8
211 } else {
212 cache_addd( LDRH_IMM(dest_reg, data_reg, 0) ); // ldrh dest_reg, [data_reg]
213 }
214 }
215 }
216
217 // move a 32bit (dword==true) or 16bit (dword==false) value from memory into dest_reg
218 // 16bit moves may destroy the upper 16bit of the destination register
219 static void gen_mov_word_to_reg(HostReg dest_reg,void* data,bool dword) {
220 gen_mov_dword_to_reg_imm(temp1, (Bit32u)data);
221 gen_mov_word_to_reg_helper(dest_reg, data, dword, temp1);
222 }
223
224 // move a 16bit constant value into dest_reg
225 // the upper 16bit of the destination register may be destroyed
226 static void INLINE gen_mov_word_to_reg_imm(HostReg dest_reg,Bit16u imm) {
227 gen_mov_dword_to_reg_imm(dest_reg, (Bit32u)imm);
228 }
229
230 // helper function for gen_mov_word_from_reg
231 static void gen_mov_word_from_reg_helper(HostReg src_reg,void* dest,bool dword, HostReg data_reg) {
232 // alignment....
233 if (dword) {
234 if ((Bit32u)dest & 3) {
235 if ( ((Bit32u)dest & 3) == 2 ) {
236 cache_addd( STRH_IMM(src_reg, data_reg, 0) ); // strh src_reg, [data_reg]
237 cache_addd( MOV_REG_LSR_IMM(temp2, src_reg, 16) ); // mov temp2, src_reg, lsr #16
238 cache_addd( STRH_IMM(temp2, data_reg, 2) ); // strh temp2, [data_reg, #2]
239 } else {
240 cache_addd( STRB_IMM(src_reg, data_reg, 0) ); // strb src_reg, [data_reg]
241 cache_addd( MOV_REG_LSR_IMM(temp2, src_reg, 8) ); // mov temp2, src_reg, lsr #8
242 cache_addd( STRH_IMM(temp2, data_reg, 1) ); // strh temp2, [data_reg, #1]
243 cache_addd( MOV_REG_LSR_IMM(temp2, temp2, 16) ); // mov temp2, temp2, lsr #16
244 cache_addd( STRB_IMM(temp2, data_reg, 3) ); // strb temp2, [data_reg, #3]
245 }
246 } else {
247 cache_addd( STR_IMM(src_reg, data_reg, 0) ); // str src_reg, [data_reg]
248 }
249 } else {
250 if ((Bit32u)dest & 1) {
251 cache_addd( STRB_IMM(src_reg, data_reg, 0) ); // strb src_reg, [data_reg]
252 cache_addd( MOV_REG_LSR_IMM(temp2, src_reg, 8) ); // mov temp2, src_reg, lsr #8
253 cache_addd( STRB_IMM(temp2, data_reg, 1) ); // strb temp2, [data_reg, #1]
254 } else {
255 cache_addd( STRH_IMM(src_reg, data_reg, 0) ); // strh src_reg, [data_reg]
256 }
257 }
258 }
259
260 // move 32bit (dword==true) or 16bit (dword==false) of a register into memory
261 static void gen_mov_word_from_reg(HostReg src_reg,void* dest,bool dword) {
262 gen_mov_dword_to_reg_imm(temp1, (Bit32u)dest);
263 gen_mov_word_from_reg_helper(src_reg, dest, dword, temp1);
264 }
265
266 // move an 8bit value from memory into dest_reg
267 // the upper 24bit of the destination register can be destroyed
268 // this function does not use FC_OP1/FC_OP2 as dest_reg as these
269 // registers might not be directly byte-accessible on some architectures
270 static void gen_mov_byte_to_reg_low(HostReg dest_reg,void* data) {
271 gen_mov_dword_to_reg_imm(temp1, (Bit32u)data);
272 cache_addd( LDRB_IMM(dest_reg, temp1, 0) ); // ldrb dest_reg, [temp1]
273 }
274
275 // move an 8bit value from memory into dest_reg
276 // the upper 24bit of the destination register can be destroyed
277 // this function can use FC_OP1/FC_OP2 as dest_reg which are
278 // not directly byte-accessible on some architectures
279 static void INLINE gen_mov_byte_to_reg_low_canuseword(HostReg dest_reg,void* data) {
280 gen_mov_byte_to_reg_low(dest_reg, data);
281 }
282
283 // move an 8bit constant value into dest_reg
284 // the upper 24bit of the destination register can be destroyed
285 // this function does not use FC_OP1/FC_OP2 as dest_reg as these
286 // registers might not be directly byte-accessible on some architectures
287 static void gen_mov_byte_to_reg_low_imm(HostReg dest_reg,Bit8u imm) {
288 cache_addd( MOV_IMM(dest_reg, imm, 0) ); // mov dest_reg, #(imm)
289 }
290
291 // move an 8bit constant value into dest_reg
292 // the upper 24bit of the destination register can be destroyed
293 // this function can use FC_OP1/FC_OP2 as dest_reg which are
294 // not directly byte-accessible on some architectures
295 static void INLINE gen_mov_byte_to_reg_low_imm_canuseword(HostReg dest_reg,Bit8u imm) {
296 gen_mov_byte_to_reg_low_imm(dest_reg, imm);
297 }
298
299 // move the lowest 8bit of a register into memory
300 static void gen_mov_byte_from_reg_low(HostReg src_reg,void* dest) {
301 gen_mov_dword_to_reg_imm(temp1, (Bit32u)dest);
302 cache_addd( STRB_IMM(src_reg, temp1, 0) ); // strb src_reg, [temp1]
303 }
304
305
306
307 // convert an 8bit word to a 32bit dword
308 // the register is zero-extended (sign==false) or sign-extended (sign==true)
309 static void gen_extend_byte(bool sign,HostReg reg) {
310 if (sign) {
311 cache_addd( MOV_REG_LSL_IMM(reg, reg, 24) ); // mov reg, reg, lsl #24
312 cache_addd( MOV_REG_ASR_IMM(reg, reg, 24) ); // mov reg, reg, asr #24
313 } else {
314 cache_addd( AND_IMM(reg, reg, 0xff, 0) ); // and reg, reg, #0xff
315 }
316 }
317
318 // convert a 16bit word to a 32bit dword
319 // the register is zero-extended (sign==false) or sign-extended (sign==true)
320 static void gen_extend_word(bool sign,HostReg reg) {
321 if (sign) {
322 cache_addd( MOV_REG_LSL_IMM(reg, reg, 16) ); // mov reg, reg, lsl #16
323 cache_addd( MOV_REG_ASR_IMM(reg, reg, 16) ); // mov reg, reg, asr #16
324 } else {
325 cache_addd( MOV_REG_LSL_IMM(reg, reg, 16) ); // mov reg, reg, lsl #16
326 cache_addd( MOV_REG_LSR_IMM(reg, reg, 16) ); // mov reg, reg, lsr #16
327 }
328 }
329
330 // add a 32bit value from memory to a full register
331 static void gen_add(HostReg reg,void* op) {
332 gen_mov_word_to_reg(temp3, op, 1);
333 cache_addd( ADD_REG_LSL_IMM(reg, reg, temp3, 0) ); // add reg, reg, temp3
334 }
335
336 // add a 32bit constant value to a full register
337 static void gen_add_imm(HostReg reg,Bit32u imm) {
338 Bits scale;
339 if(!imm) return;
340 if (imm == 0xffffffff) {
341 cache_addd( SUB_IMM(reg, reg, 1, 0) ); // sub reg, reg, #1
342 } else {
343 scale = 0;
344 while (imm) {
345 while ((imm & 3) == 0) {
346 imm>>=2;
347 scale+=2;
348 }
349 cache_addd( ADD_IMM(reg, reg, imm & 0xff, ROTATE_SCALE(scale)) ); // add reg, reg, #((imm & 0xff) << scale)
350 imm>>=8;
351 scale+=8;
352 }
353 }
354 }
355
356 // and a 32bit constant value with a full register
357 static void gen_and_imm(HostReg reg,Bit32u imm) {
358 Bits scale;
359 Bit32u imm2;
360 imm2 = ~imm;
361 if(!imm2) return;
362 if (!imm) {
363 cache_addd( MOV_IMM(reg, 0, 0) ); // mov reg, #0
364 } else {
365 scale = 0;
366 while (imm2) {
367 while ((imm2 & 3) == 0) {
368 imm2>>=2;
369 scale+=2;
370 }
371 cache_addd( BIC_IMM(reg, reg, imm2 & 0xff, ROTATE_SCALE(scale)) ); // bic reg, reg, #((imm2 & 0xff) << scale)
372 imm2>>=8;
373 scale+=8;
374 }
375 }
376 }
377
378
379 // move a 32bit constant value into memory
380 static void gen_mov_direct_dword(void* dest,Bit32u imm) {
381 gen_mov_dword_to_reg_imm(temp3, imm);
382 gen_mov_word_from_reg(temp3, dest, 1);
383 }
384
385 // move an address into memory
386 static void INLINE gen_mov_direct_ptr(void* dest,DRC_PTR_SIZE_IM imm) {
387 gen_mov_direct_dword(dest,(Bit32u)imm);
388 }
389
390 // add an 8bit constant value to a dword memory value
391 static void gen_add_direct_byte(void* dest,Bit8s imm) {
392 if(!imm) return;
393 gen_mov_dword_to_reg_imm(temp1, (Bit32u)dest);
394 gen_mov_word_to_reg_helper(temp3, dest, 1, temp1);
395 if (imm >= 0) {
396 cache_addd( ADD_IMM(temp3, temp3, (Bit32s)imm, 0) ); // add temp3, temp3, #(imm)
397 } else {
398 cache_addd( SUB_IMM(temp3, temp3, -((Bit32s)imm), 0) ); // sub temp3, temp3, #(-imm)
399 }
400 gen_mov_word_from_reg_helper(temp3, dest, 1, temp1);
401 }
402
403 // add a 32bit (dword==true) or 16bit (dword==false) constant value to a memory value
404 static void gen_add_direct_word(void* dest,Bit32u imm,bool dword) {
405 if(!imm) return;
406 if (dword && ( (imm<128) || (imm>=0xffffff80) ) ) {
407 gen_add_direct_byte(dest,(Bit8s)imm);
408 return;
409 }
410 gen_mov_dword_to_reg_imm(temp1, (Bit32u)dest);
411 gen_mov_word_to_reg_helper(temp3, dest, dword, temp1);
412 // maybe use function gen_add_imm
413 if (dword) {
414 gen_mov_dword_to_reg_imm(temp2, imm);
415 } else {
416 gen_mov_word_to_reg_imm(temp2, (Bit16u)imm);
417 }
418 cache_addd( ADD_REG_LSL_IMM(temp3, temp3, temp2, 0) ); // add temp3, temp3, temp2
419 gen_mov_word_from_reg_helper(temp3, dest, dword, temp1);
420 }
421
422 // subtract an 8bit constant value from a dword memory value
423 static void gen_sub_direct_byte(void* dest,Bit8s imm) {
424 if(!imm) return;
425 gen_mov_dword_to_reg_imm(temp1, (Bit32u)dest);
426 gen_mov_word_to_reg_helper(temp3, dest, 1, temp1);
427 if (imm >= 0) {
428 cache_addd( SUB_IMM(temp3, temp3, (Bit32s)imm, 0) ); // sub temp3, temp3, #(imm)
429 } else {
430 cache_addd( ADD_IMM(temp3, temp3, -((Bit32s)imm), 0) ); // add temp3, temp3, #(-imm)
431 }
432 gen_mov_word_from_reg_helper(temp3, dest, 1, temp1);
433 }
434
435 // subtract a 32bit (dword==true) or 16bit (dword==false) constant value from a memory value
436 static void gen_sub_direct_word(void* dest,Bit32u imm,bool dword) {
437 if(!imm) return;
438 if (dword && ( (imm<128) || (imm>=0xffffff80) ) ) {
439 gen_sub_direct_byte(dest,(Bit8s)imm);
440 return;
441 }
442 gen_mov_dword_to_reg_imm(temp1, (Bit32u)dest);
443 gen_mov_word_to_reg_helper(temp3, dest, dword, temp1);
444 // maybe use function gen_add_imm/gen_sub_imm
445 if (dword) {
446 gen_mov_dword_to_reg_imm(temp2, imm);
447 } else {
448 gen_mov_word_to_reg_imm(temp2, (Bit16u)imm);
449 }
450 cache_addd( SUB_REG_LSL_IMM(temp3, temp3, temp2, 0) ); // sub temp3, temp3, temp2
451 gen_mov_word_from_reg_helper(temp3, dest, dword, temp1);
452 }
453
454 // effective address calculation, destination is dest_reg
455 // scale_reg is scaled by scale (scale_reg*(2^scale)) and
456 // added to dest_reg, then the immediate value is added
457 static INLINE void gen_lea(HostReg dest_reg,HostReg scale_reg,Bitu scale,Bits imm) {
458 cache_addd( ADD_REG_LSL_IMM(dest_reg, dest_reg, scale_reg, scale) ); // add dest_reg, dest_reg, scale_reg, lsl #(scale)
459 gen_add_imm(dest_reg, imm);
460 }
461
462 // effective address calculation, destination is dest_reg
463 // dest_reg is scaled by scale (dest_reg*(2^scale)),
464 // then the immediate value is added
465 static INLINE void gen_lea(HostReg dest_reg,Bitu scale,Bits imm) {
466 if (scale) {
467 cache_addd( MOV_REG_LSL_IMM(dest_reg, dest_reg, scale) ); // mov dest_reg, dest_reg, lsl #(scale)
468 }
469 gen_add_imm(dest_reg, imm);
470 }
471
472 // generate a call to a parameterless function
473 static void INLINE gen_call_function_raw(void * func) {
474 cache_addd( LDR_IMM(temp1, HOST_pc, 4) ); // ldr temp1, [pc, #4]
475 cache_addd( ADD_IMM(HOST_lr, HOST_pc, 4, 0) ); // add lr, pc, #4
476 cache_addd( BX(temp1) ); // bx temp1
477 cache_addd((Bit32u)func); // .int func
478 }
479
480 // generate a call to a function with paramcount parameters
481 // note: the parameters are loaded in the architecture specific way
482 // using the gen_load_param_ functions below
483 static Bit32u INLINE gen_call_function_setup(void * func,Bitu paramcount,bool fastcall=false) {
484 Bit32u proc_addr = (Bit32u)cache.pos;
485 gen_call_function_raw(func);
486 return proc_addr;
487 }
488
489 #if (1)
490 // max of 4 parameters in a1-a4
491
492 // load an immediate value as param'th function parameter
493 static void INLINE gen_load_param_imm(Bitu imm,Bitu param) {
494 gen_mov_dword_to_reg_imm(param, imm);
495 }
496
497 // load an address as param'th function parameter
498 static void INLINE gen_load_param_addr(Bitu addr,Bitu param) {
499 gen_mov_dword_to_reg_imm(param, addr);
500 }
501
502 // load a host-register as param'th function parameter
503 static void INLINE gen_load_param_reg(Bitu reg,Bitu param) {
504 gen_mov_regs(param, reg);
505 }
506
507 // load a value from memory as param'th function parameter
508 static void INLINE gen_load_param_mem(Bitu mem,Bitu param) {
509 gen_mov_word_to_reg(param, (void *)mem, 1);
510 }
511 #else
512 other arm abis
513 #endif
514
515 // jump to an address pointed at by ptr, offset is in imm
516 static void gen_jmp_ptr(void * ptr,Bits imm=0) {
517 Bits scale;
518 Bitu imm2;
519 gen_mov_word_to_reg(temp3, ptr, 1);
520
521 if (imm) {
522 scale = 0;
523 imm2 = (Bitu)imm;
524 while (imm2) {
525 while ((imm2 & 3) == 0) {
526 imm2>>=2;
527 scale+=2;
528 }
529 cache_addd( ADD_IMM(temp3, temp3, imm2 & 0xff, ROTATE_SCALE(scale)) ); // add temp3, temp3, #((imm2 & 0xff) << scale)
530 imm2>>=8;
531 scale+=8;
532 }
533 }
534
535 #if (1)
536 // (*ptr) should be word aligned
537 if ((imm & 0x03) == 0) {
538 cache_addd( LDR_IMM(temp1, temp3, 0) ); // ldr temp1, [temp3]
539 } else
540 #endif
541 {
542 cache_addd( LDRB_IMM(temp1, temp3, 0) ); // ldrb temp1, [temp3]
543 cache_addd( LDRB_IMM(temp2, temp3, 1) ); // ldrb temp2, [temp3, #1]
544 cache_addd( ORR_REG_LSL_IMM(temp1, temp1, temp2, 8) ); // orr temp1, temp1, temp2, lsl #8
545 cache_addd( LDRB_IMM(temp2, temp3, 2) ); // ldrb temp2, [temp3, #2]
546 cache_addd( ORR_REG_LSL_IMM(temp1, temp1, temp2, 16) ); // orr temp1, temp1, temp2, lsl #16
547 cache_addd( LDRB_IMM(temp2, temp3, 3) ); // ldrb temp2, [temp3, #3]
548 cache_addd( ORR_REG_LSL_IMM(temp1, temp1, temp2, 24) ); // orr temp1, temp1, temp2, lsl #24
549 }
550
551 cache_addd( BX(temp1) ); // bx temp1
552 }
553
554 // short conditional jump (+-127 bytes) if register is zero
555 // the destination is set by gen_fill_branch() later
556 static Bit32u gen_create_branch_on_zero(HostReg reg,bool dword) {
557 if (dword) {
558 cache_addd( CMP_IMM(reg, 0, 0) ); // cmp reg, #0
559 } else {
560 cache_addd( MOVS_REG_LSL_IMM(temp1, reg, 16) ); // movs temp1, reg, lsl #16
561 }
562 cache_addd( BEQ_FWD(0) ); // beq j
563 return ((Bit32u)cache.pos-4);
564 }
565
566 // short conditional jump (+-127 bytes) if register is nonzero
567 // the destination is set by gen_fill_branch() later
568 static Bit32u gen_create_branch_on_nonzero(HostReg reg,bool dword) {
569 if (dword) {
570 cache_addd( CMP_IMM(reg, 0, 0) ); // cmp reg, #0
571 } else {
572 cache_addd( MOVS_REG_LSL_IMM(temp1, reg, 16) ); // movs temp1, reg, lsl #16
573 }
574 cache_addd( BNE_FWD(0) ); // bne j
575 return ((Bit32u)cache.pos-4);
576 }
577
578 // calculate relative offset and fill it into the location pointed to by data
579 static void INLINE gen_fill_branch(DRC_PTR_SIZE_IM data) {
580 #if C_DEBUG
581 Bits len=(Bit32u)cache.pos-(data+8);
582 if (len<0) len=-len;
583 if (len>0x02000000) LOG_MSG("Big jump %d",len);
584 #endif
585 *(Bit32u*)data=( (*(Bit32u*)data) & 0xff000000 ) | ( ( ((Bit32u)cache.pos - (data+8)) >> 2 ) & 0x00ffffff );
586 }
587
588 // conditional jump if register is nonzero
589 // for isdword==true the 32bit of the register are tested
590 // for isdword==false the lowest 8bit of the register are tested
591 static Bit32u gen_create_branch_long_nonzero(HostReg reg,bool isdword) {
592 if (isdword) {
593 cache_addd( CMP_IMM(reg, 0, 0) ); // cmp reg, #0
594 } else {
595 cache_addd( TST_IMM(reg, 0xff, 0) ); // tst reg, #0xff
596 }
597 cache_addd( BEQ_FWD(8) ); // beq nobranch (pc +8)
598 cache_addd( LDR_IMM(temp1, HOST_pc, 0) ); // ldr temp1, [pc, #0]
599 cache_addd( BX(temp1) ); // bx temp1
600 cache_addd(0); // fill j
601 // nobranch:
602 return ((Bit32u)cache.pos-4);
603 }
604
605 // compare 32bit-register against zero and jump if value less/equal than zero
606 static Bit32u gen_create_branch_long_leqzero(HostReg reg) {
607 cache_addd( CMP_IMM(reg, 0, 0) ); // cmp reg, #0
608 cache_addd( BGT_FWD(8) ); // bgt nobranch (pc+8)
609 cache_addd( LDR_IMM(temp1, HOST_pc, 0) ); // ldr temp1, [pc, #0]
610 cache_addd( BX(temp1) ); // bx temp1
611 cache_addd(0); // fill j
612 // nobranch:
613 return ((Bit32u)cache.pos-4);
614 }
615
616 // calculate long relative offset and fill it into the location pointed to by data
617 static void INLINE gen_fill_branch_long(Bit32u data) {
618 // this is an absolute branch
619 *(Bit32u*)data=(Bit32u)cache.pos;
620 }
621
622 static void gen_run_code(void) {
623 cache_addd(0xe92d4000); // stmfd sp!, {lr}
624 cache_addd(0xe92d0cf0); // stmfd sp!, {v1-v4,v7,v8}
625
626 // adr: 8
627 cache_addd( LDR_IMM(FC_SEGS_ADDR, HOST_pc, 64 - (8 + 8)) ); // ldr FC_SEGS_ADDR, [pc, #(&Segs)]
628 // adr: 12
629 cache_addd( LDR_IMM(FC_REGS_ADDR, HOST_pc, 68 - (12 + 8)) ); // ldr FC_REGS_ADDR, [pc, #(&cpu_regs)]
630
631 cache_addd( ADD_IMM(HOST_lr, HOST_pc, 4, 0) ); // add lr, pc, #4
632 cache_addd(0xe92d4000); // stmfd sp!, {lr}
633 cache_addd( BX(HOST_r0) ); // bx r0
634
635 cache_addd(0xe8bd0cf0); // ldmfd sp!, {v1-v4,v7,v8}
636
637 cache_addd(0xe8bd4000); // ldmfd sp!, {lr}
638 cache_addd( BX(HOST_lr) ); // bx lr
639
640 // fill up to 64 bytes
641 cache_addd( NOP ); // nop
642 cache_addd( NOP ); // nop
643 cache_addd( NOP ); // nop
644 cache_addd( NOP ); // nop
645 cache_addd( NOP ); // nop
646 cache_addd( NOP ); // nop
647
648 // adr: 64
649 cache_addd((Bit32u)&Segs); // address of "Segs"
650 // adr: 68
651 cache_addd((Bit32u)&cpu_regs); // address of "cpu_regs"
652 }
653
654 // return from a function
655 static void gen_return_function(void) {
656 cache_addd(0xe8bd4000); // ldmfd sp!, {lr}
657 cache_addd( BX(HOST_lr) ); // bx lr
658 }
659
660 #ifdef DRC_FLAGS_INVALIDATION
661
662 // called when a call to a function can be replaced by a
663 // call to a simpler function
664 static void gen_fill_function_ptr(Bit8u * pos,void* fct_ptr,Bitu flags_type) {
665 #ifdef DRC_FLAGS_INVALIDATION_DCODE
666 // try to avoid function calls but rather directly fill in code
667 switch (flags_type) {
668 case t_ADDb:
669 case t_ADDw:
670 case t_ADDd:
671 *(Bit32u*)pos=ADD_REG_LSL_IMM(FC_RETOP, HOST_a1, HOST_a2, 0); // add FC_RETOP, a1, a2
672 *(Bit32u*)(pos+4)=NOP; // nop
673 *(Bit32u*)(pos+8)=NOP; // nop
674 *(Bit32u*)(pos+12)=NOP; // nop
675 break;
676 case t_ORb:
677 case t_ORw:
678 case t_ORd:
679 *(Bit32u*)pos=ORR_REG_LSL_IMM(FC_RETOP, HOST_a1, HOST_a2, 0); // orr FC_RETOP, a1, a2
680 *(Bit32u*)(pos+4)=NOP; // nop
681 *(Bit32u*)(pos+8)=NOP; // nop
682 *(Bit32u*)(pos+12)=NOP; // nop
683 break;
684 case t_ANDb:
685 case t_ANDw:
686 case t_ANDd:
687 *(Bit32u*)pos=AND_REG_LSL_IMM(FC_RETOP, HOST_a1, HOST_a2, 0); // and FC_RETOP, a1, a2
688 *(Bit32u*)(pos+4)=NOP; // nop
689 *(Bit32u*)(pos+8)=NOP; // nop
690 *(Bit32u*)(pos+12)=NOP; // nop
691 break;
692 case t_SUBb:
693 case t_SUBw:
694 case t_SUBd:
695 *(Bit32u*)pos=SUB_REG_LSL_IMM(FC_RETOP, HOST_a1, HOST_a2, 0); // sub FC_RETOP, a1, a2
696 *(Bit32u*)(pos+4)=NOP; // nop
697 *(Bit32u*)(pos+8)=NOP; // nop
698 *(Bit32u*)(pos+12)=NOP; // nop
699 break;
700 case t_XORb:
701 case t_XORw:
702 case t_XORd:
703 *(Bit32u*)pos=EOR_REG_LSL_IMM(FC_RETOP, HOST_a1, HOST_a2, 0); // eor FC_RETOP, a1, a2
704 *(Bit32u*)(pos+4)=NOP; // nop
705 *(Bit32u*)(pos+8)=NOP; // nop
706 *(Bit32u*)(pos+12)=NOP; // nop
707 break;
708 case t_CMPb:
709 case t_CMPw:
710 case t_CMPd:
711 case t_TESTb:
712 case t_TESTw:
713 case t_TESTd:
714 *(Bit32u*)pos=B_FWD(8); // b (pc+2*4)
715 break;
716 case t_INCb:
717 case t_INCw:
718 case t_INCd:
719 *(Bit32u*)pos=ADD_IMM(FC_RETOP, HOST_a1, 1, 0); // add FC_RETOP, a1, #1
720 *(Bit32u*)(pos+4)=NOP; // nop
721 *(Bit32u*)(pos+8)=NOP; // nop
722 *(Bit32u*)(pos+12)=NOP; // nop
723 break;
724 case t_DECb:
725 case t_DECw:
726 case t_DECd:
727 *(Bit32u*)pos=SUB_IMM(FC_RETOP, HOST_a1, 1, 0); // sub FC_RETOP, a1, #1
728 *(Bit32u*)(pos+4)=NOP; // nop
729 *(Bit32u*)(pos+8)=NOP; // nop
730 *(Bit32u*)(pos+12)=NOP; // nop
731 break;
732 case t_SHLb:
733 case t_SHLw:
734 case t_SHLd:
735 *(Bit32u*)pos=MOV_REG_LSL_REG(FC_RETOP, HOST_a1, HOST_a2); // mov FC_RETOP, a1, lsl a2
736 *(Bit32u*)(pos+4)=NOP; // nop
737 *(Bit32u*)(pos+8)=NOP; // nop
738 *(Bit32u*)(pos+12)=NOP; // nop
739 break;
740 case t_SHRb:
741 *(Bit32u*)pos=AND_IMM(FC_RETOP, HOST_a1, 0xff, 0); // and FC_RETOP, a1, #0xff
742 *(Bit32u*)(pos+4)=MOV_REG_LSR_REG(FC_RETOP, FC_RETOP, HOST_a2); // mov FC_RETOP, FC_RETOP, lsr a2
743 *(Bit32u*)(pos+8)=NOP; // nop
744 *(Bit32u*)(pos+12)=NOP; // nop
745 break;
746 case t_SHRw:
747 *(Bit32u*)pos=MOV_REG_LSL_IMM(FC_RETOP, HOST_a1, 16); // mov FC_RETOP, a1, lsl #16
748 *(Bit32u*)(pos+4)=MOV_REG_LSR_IMM(FC_RETOP, FC_RETOP, 16); // mov FC_RETOP, FC_RETOP, lsr #16
749 *(Bit32u*)(pos+8)=MOV_REG_LSR_REG(FC_RETOP, FC_RETOP, HOST_a2); // mov FC_RETOP, FC_RETOP, lsr a2
750 *(Bit32u*)(pos+12)=NOP; // nop
751 break;
752 case t_SHRd:
753 *(Bit32u*)pos=MOV_REG_LSR_REG(FC_RETOP, HOST_a1, HOST_a2); // mov FC_RETOP, a1, lsr a2
754 *(Bit32u*)(pos+4)=NOP; // nop
755 *(Bit32u*)(pos+8)=NOP; // nop
756 *(Bit32u*)(pos+12)=NOP; // nop
757 break;
758 case t_SARb:
759 *(Bit32u*)pos=MOV_REG_LSL_IMM(FC_RETOP, HOST_a1, 24); // mov FC_RETOP, a1, lsl #24
760 *(Bit32u*)(pos+4)=MOV_REG_ASR_IMM(FC_RETOP, FC_RETOP, 24); // mov FC_RETOP, FC_RETOP, asr #24
761 *(Bit32u*)(pos+8)=MOV_REG_ASR_REG(FC_RETOP, FC_RETOP, HOST_a2); // mov FC_RETOP, FC_RETOP, asr a2
762 *(Bit32u*)(pos+12)=NOP; // nop
763 break;
764 case t_SARw:
765 *(Bit32u*)pos=MOV_REG_LSL_IMM(FC_RETOP, HOST_a1, 16); // mov FC_RETOP, a1, lsl #16
766 *(Bit32u*)(pos+4)=MOV_REG_ASR_IMM(FC_RETOP, FC_RETOP, 16); // mov FC_RETOP, FC_RETOP, asr #16
767 *(Bit32u*)(pos+8)=MOV_REG_ASR_REG(FC_RETOP, FC_RETOP, HOST_a2); // mov FC_RETOP, FC_RETOP, asr a2
768 *(Bit32u*)(pos+12)=NOP; // nop
769 break;
770 case t_SARd:
771 *(Bit32u*)pos=MOV_REG_ASR_REG(FC_RETOP, HOST_a1, HOST_a2); // mov FC_RETOP, a1, asr a2
772 *(Bit32u*)(pos+4)=NOP; // nop
773 *(Bit32u*)(pos+8)=NOP; // nop
774 *(Bit32u*)(pos+12)=NOP; // nop
775 break;
776 case t_RORb:
777 *(Bit32u*)pos=MOV_REG_LSL_IMM(FC_RETOP, HOST_a1, 24); // mov FC_RETOP, a1, lsl #24
778 *(Bit32u*)(pos+4)=ORR_REG_LSR_IMM(FC_RETOP, FC_RETOP, FC_RETOP, 8); // orr FC_RETOP, FC_RETOP, FC_RETOP, lsr #8
779 *(Bit32u*)(pos+8)=ORR_REG_LSR_IMM(FC_RETOP, FC_RETOP, FC_RETOP, 16); // orr FC_RETOP, FC_RETOP, FC_RETOP, lsr #16
780 *(Bit32u*)(pos+12)=MOV_REG_ROR_REG(FC_RETOP, FC_RETOP, HOST_a2); // mov FC_RETOP, FC_RETOP, ror a2
781 break;
782 case t_RORw:
783 *(Bit32u*)pos=MOV_REG_LSL_IMM(FC_RETOP, HOST_a1, 16); // mov FC_RETOP, a1, lsl #16
784 *(Bit32u*)(pos+4)=ORR_REG_LSR_IMM(FC_RETOP, FC_RETOP, FC_RETOP, 16); // orr FC_RETOP, FC_RETOP, FC_RETOP, lsr #16
785 *(Bit32u*)(pos+8)=MOV_REG_ROR_REG(FC_RETOP, FC_RETOP, HOST_a2); // mov FC_RETOP, FC_RETOP, ror a2
786 *(Bit32u*)(pos+12)=NOP; // nop
787 break;
788 case t_RORd:
789 *(Bit32u*)pos=MOV_REG_ROR_REG(FC_RETOP, HOST_a1, HOST_a2); // mov FC_RETOP, a1, ror a2
790 *(Bit32u*)(pos+4)=NOP; // nop
791 *(Bit32u*)(pos+8)=NOP; // nop
792 *(Bit32u*)(pos+12)=NOP; // nop
793 break;
794 case t_ROLw:
795 *(Bit32u*)pos=MOV_REG_LSL_IMM(FC_RETOP, HOST_a1, 16); // mov FC_RETOP, a1, lsl #16
796 *(Bit32u*)(pos+4)=RSB_IMM(HOST_a2, HOST_a2, 32, 0); // rsb a2, a2, #32
797 *(Bit32u*)(pos+8)=ORR_REG_LSR_IMM(FC_RETOP, FC_RETOP, FC_RETOP, 16); // orr FC_RETOP, FC_RETOP, FC_RETOP, lsr #16
798 *(Bit32u*)(pos+12)=MOV_REG_ROR_REG(FC_RETOP, FC_RETOP, HOST_a2); // mov FC_RETOP, FC_RETOP, ror a2
799 break;
800 case t_ROLd:
801 *(Bit32u*)pos=RSB_IMM(HOST_a2, HOST_a2, 32, 0); // rsb a2, a2, #32
802 *(Bit32u*)(pos+4)=MOV_REG_ROR_REG(FC_RETOP, HOST_a1, HOST_a2); // mov FC_RETOP, a1, ror a2
803 *(Bit32u*)(pos+8)=NOP; // nop
804 *(Bit32u*)(pos+12)=NOP; // nop
805 break;
806 case t_NEGb:
807 case t_NEGw:
808 case t_NEGd:
809 *(Bit32u*)pos=RSB_IMM(FC_RETOP, HOST_a1, 0, 0); // rsb FC_RETOP, a1, #0
810 *(Bit32u*)(pos+4)=NOP; // nop
811 *(Bit32u*)(pos+8)=NOP; // nop
812 *(Bit32u*)(pos+12)=NOP; // nop
813 break;
814 default:
815 *(Bit32u*)(pos+12)=(Bit32u)fct_ptr; // simple_func
816 break;
817
818 }
819 #else
820 *(Bit32u*)(pos+12)=(Bit32u)fct_ptr; // simple_func
821 #endif
822 }
823 #endif
824
825 static void cache_block_before_close(void) { }
826
827 #ifdef DRC_USE_SEGS_ADDR
828
829 // mov 16bit value from Segs[index] into dest_reg using FC_SEGS_ADDR (index modulo 2 must be zero)
830 // 16bit moves may destroy the upper 16bit of the destination register
831 static void gen_mov_seg16_to_reg(HostReg dest_reg,Bitu index) {
832 cache_addd( LDRH_IMM(dest_reg, FC_SEGS_ADDR, index) ); // ldrh dest_reg, [FC_SEGS_ADDR, #index]
833 }
834
835 // mov 32bit value from Segs[index] into dest_reg using FC_SEGS_ADDR (index modulo 4 must be zero)
836 static void gen_mov_seg32_to_reg(HostReg dest_reg,Bitu index) {
837 cache_addd( LDR_IMM(dest_reg, FC_SEGS_ADDR, index) ); // ldr dest_reg, [FC_SEGS_ADDR, #index]
838 }
839
840 // add a 32bit value from Segs[index] to a full register using FC_SEGS_ADDR (index modulo 4 must be zero)
841 static void gen_add_seg32_to_reg(HostReg reg,Bitu index) {
842 cache_addd( LDR_IMM(temp1, FC_SEGS_ADDR, index) ); // ldr temp1, [FC_SEGS_ADDR, #index]
843 cache_addd( ADD_REG_LSL_IMM(reg, reg, temp1, 0) ); // add reg, reg, temp1
844 }
845
846 #endif
847
848 #ifdef DRC_USE_REGS_ADDR
849
850 // mov 16bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR (index modulo 2 must be zero)
851 // 16bit moves may destroy the upper 16bit of the destination register
852 static void gen_mov_regval16_to_reg(HostReg dest_reg,Bitu index) {
853 cache_addd( LDRH_IMM(dest_reg, FC_REGS_ADDR, index) ); // ldrh dest_reg, [FC_REGS_ADDR, #index]
854 }
855
856 // mov 32bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR (index modulo 4 must be zero)
857 static void gen_mov_regval32_to_reg(HostReg dest_reg,Bitu index) {
858 cache_addd( LDR_IMM(dest_reg, FC_REGS_ADDR, index) ); // ldr dest_reg, [FC_REGS_ADDR, #index]
859 }
860
861 // move a 32bit (dword==true) or 16bit (dword==false) value from cpu_regs[index] into dest_reg using FC_REGS_ADDR (if dword==true index modulo 4 must be zero) (if dword==false index modulo 2 must be zero)
862 // 16bit moves may destroy the upper 16bit of the destination register
863 static void gen_mov_regword_to_reg(HostReg dest_reg,Bitu index,bool dword) {
864 if (dword) {
865 cache_addd( LDR_IMM(dest_reg, FC_REGS_ADDR, index) ); // ldr dest_reg, [FC_REGS_ADDR, #index]
866 } else {
867 cache_addd( LDRH_IMM(dest_reg, FC_REGS_ADDR, index) ); // ldrh dest_reg, [FC_REGS_ADDR, #index]
868 }
869 }
870
871 // move an 8bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR
872 // the upper 24bit of the destination register can be destroyed
873 // this function does not use FC_OP1/FC_OP2 as dest_reg as these
874 // registers might not be directly byte-accessible on some architectures
875 static void gen_mov_regbyte_to_reg_low(HostReg dest_reg,Bitu index) {
876 cache_addd( LDRB_IMM(dest_reg, FC_REGS_ADDR, index) ); // ldrb dest_reg, [FC_REGS_ADDR, #index]
877 }
878
879 // move an 8bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR
880 // the upper 24bit of the destination register can be destroyed
881 // this function can use FC_OP1/FC_OP2 as dest_reg which are
882 // not directly byte-accessible on some architectures
883 static void INLINE gen_mov_regbyte_to_reg_low_canuseword(HostReg dest_reg,Bitu index) {
884 cache_addd( LDRB_IMM(dest_reg, FC_REGS_ADDR, index) ); // ldrb dest_reg, [FC_REGS_ADDR, #index]
885 }
886
887
888 // add a 32bit value from cpu_regs[index] to a full register using FC_REGS_ADDR (index modulo 4 must be zero)
889 static void gen_add_regval32_to_reg(HostReg reg,Bitu index) {
890 cache_addd( LDR_IMM(temp2, FC_REGS_ADDR, index) ); // ldr temp2, [FC_REGS_ADDR, #index]
891 cache_addd( ADD_REG_LSL_IMM(reg, reg, temp2, 0) ); // add reg, reg, temp2
892 }
893
894
895 // move 16bit of register into cpu_regs[index] using FC_REGS_ADDR (index modulo 2 must be zero)
896 static void gen_mov_regval16_from_reg(HostReg src_reg,Bitu index) {
897 cache_addd( STRH_IMM(src_reg, FC_REGS_ADDR, index) ); // strh src_reg, [FC_REGS_ADDR, #index]
898 }
899
900 // move 32bit of register into cpu_regs[index] using FC_REGS_ADDR (index modulo 4 must be zero)
901 static void gen_mov_regval32_from_reg(HostReg src_reg,Bitu index) {
902 cache_addd( STR_IMM(src_reg, FC_REGS_ADDR, index) ); // str src_reg, [FC_REGS_ADDR, #index]
903 }
904
905 // move 32bit (dword==true) or 16bit (dword==false) of a register into cpu_regs[index] using FC_REGS_ADDR (if dword==true index modulo 4 must be zero) (if dword==false index modulo 2 must be zero)
906 static void gen_mov_regword_from_reg(HostReg src_reg,Bitu index,bool dword) {
907 if (dword) {
908 cache_addd( STR_IMM(src_reg, FC_REGS_ADDR, index) ); // str src_reg, [FC_REGS_ADDR, #index]
909 } else {
910 cache_addd( STRH_IMM(src_reg, FC_REGS_ADDR, index) ); // strh src_reg, [FC_REGS_ADDR, #index]
911 }
912 }
913
914 // move the lowest 8bit of a register into cpu_regs[index] using FC_REGS_ADDR
915 static void gen_mov_regbyte_from_reg_low(HostReg src_reg,Bitu index) {
916 cache_addd( STRB_IMM(src_reg, FC_REGS_ADDR, index) ); // strb src_reg, [FC_REGS_ADDR, #index]
917 }
918
919 #endif