Debian Codegraph @

src/cpu/core_dynrec/risc_armv4le-thumb-niw.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-thumb-niw.h,v 1.5 2009-06-27 12:51:10 c2woody Exp $ */
20
21
22 /* ARMv4 (little endian) backend by M-HT (thumb version with data pool) */
23
24
25 // temporary "lo" registers
26 #define templo1 HOST_v3
27 #define templo2 HOST_v4
28 #define templo3 HOST_v2
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_a4
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_a4
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 // instruction encodings
66
67 // move
68 // mov dst, #imm @ 0 <= imm <= 255
69 #define MOV_IMM(dst, imm) (0x2000 + ((dst) << 8) + (imm) )
70 // mov dst, src
71 #define MOV_REG(dst, src) ADD_IMM3(dst, src, 0)
72 // mov dst, src
73 #define MOV_LO_HI(dst, src) (0x4640 + (dst) + (((src) - HOST_r8) << 3) )
74 // mov dst, src
75 #define MOV_HI_LO(dst, src) (0x4680 + ((dst) - HOST_r8) + ((src) << 3) )
76
77 // arithmetic
78 // add dst, src, #imm @ 0 <= imm <= 7
79 #define ADD_IMM3(dst, src, imm) (0x1c00 + (dst) + ((src) << 3) + ((imm) << 6) )
80 // add dst, #imm @ 0 <= imm <= 255
81 #define ADD_IMM8(dst, imm) (0x3000 + ((dst) << 8) + (imm) )
82 // add dst, src1, src2
83 #define ADD_REG(dst, src1, src2) (0x1800 + (dst) + ((src1) << 3) + ((src2) << 6) )
84 // add dst, pc, #imm @ 0 <= imm < 1024 & imm mod 4 = 0
85 #define ADD_LO_PC_IMM(dst, imm) (0xa000 + ((dst) << 8) + ((imm) >> 2) )
86 // sub dst, src1, src2
87 #define SUB_REG(dst, src1, src2) (0x1a00 + (dst) + ((src1) << 3) + ((src2) << 6) )
88 // sub dst, src, #imm @ 0 <= imm <= 7
89 #define SUB_IMM3(dst, src, imm) (0x1e00 + (dst) + ((src) << 3) + ((imm) << 6) )
90 // sub dst, #imm @ 0 <= imm <= 255
91 #define SUB_IMM8(dst, imm) (0x3800 + ((dst) << 8) + (imm) )
92 // neg dst, src
93 #define NEG(dst, src) (0x4240 + (dst) + ((src) << 3) )
94 // cmp dst, #imm @ 0 <= imm <= 255
95 #define CMP_IMM(dst, imm) (0x2800 + ((dst) << 8) + (imm) )
96 // nop
97 #define NOP (0x46c0)
98
99 // logical
100 // and dst, src
101 #define AND(dst, src) (0x4000 + (dst) + ((src) << 3) )
102 // eor dst, src
103 #define EOR(dst, src) (0x4040 + (dst) + ((src) << 3) )
104 // orr dst, src
105 #define ORR(dst, src) (0x4300 + (dst) + ((src) << 3) )
106
107 // shift/rotate
108 // lsl dst, src, #imm
109 #define LSL_IMM(dst, src, imm) (0x0000 + (dst) + ((src) << 3) + ((imm) << 6) )
110 // lsl dst, reg
111 #define LSL_REG(dst, reg) (0x4080 + (dst) + ((reg) << 3) )
112 // lsr dst, src, #imm
113 #define LSR_IMM(dst, src, imm) (0x0800 + (dst) + ((src) << 3) + ((imm) << 6) )
114 // lsr dst, reg
115 #define LSR_REG(dst, reg) (0x40c0 + (dst) + ((reg) << 3) )
116 // asr dst, src, #imm
117 #define ASR_IMM(dst, src, imm) (0x1000 + (dst) + ((src) << 3) + ((imm) << 6) )
118 // asr dst, reg
119 #define ASR_REG(dst, reg) (0x4100 + (dst) + ((reg) << 3) )
120 // ror dst, reg
121 #define ROR_REG(dst, reg) (0x41c0 + (dst) + ((reg) << 3) )
122
123 // load
124 // ldr reg, [addr, #imm] @ 0 <= imm < 128 & imm mod 4 = 0
125 #define LDR_IMM(reg, addr, imm) (0x6800 + (reg) + ((addr) << 3) + ((imm) << 4) )
126 // ldrh reg, [addr, #imm] @ 0 <= imm < 64 & imm mod 2 = 0
127 #define LDRH_IMM(reg, addr, imm) (0x8800 + (reg) + ((addr) << 3) + ((imm) << 5) )
128 // ldrb reg, [addr, #imm] @ 0 <= imm < 32
129 #define LDRB_IMM(reg, addr, imm) (0x7800 + (reg) + ((addr) << 3) + ((imm) << 6) )
130 // ldr reg, [pc, #imm] @ 0 <= imm < 1024 & imm mod 4 = 0
131 #define LDR_PC_IMM(reg, imm) (0x4800 + ((reg) << 8) + ((imm) >> 2) )
132
133 // store
134 // str reg, [addr, #imm] @ 0 <= imm < 128 & imm mod 4 = 0
135 #define STR_IMM(reg, addr, imm) (0x6000 + (reg) + ((addr) << 3) + ((imm) << 4) )
136 // strh reg, [addr, #imm] @ 0 <= imm < 64 & imm mod 2 = 0
137 #define STRH_IMM(reg, addr, imm) (0x8000 + (reg) + ((addr) << 3) + ((imm) << 5) )
138 // strb reg, [addr, #imm] @ 0 <= imm < 32
139 #define STRB_IMM(reg, addr, imm) (0x7000 + (reg) + ((addr) << 3) + ((imm) << 6) )
140
141 // branch
142 // beq pc+imm @ 0 <= imm < 256 & imm mod 2 = 0
143 #define BEQ_FWD(imm) (0xd000 + ((imm) >> 1) )
144 // bne pc+imm @ 0 <= imm < 256 & imm mod 2 = 0
145 #define BNE_FWD(imm) (0xd100 + ((imm) >> 1) )
146 // bgt pc+imm @ 0 <= imm < 256 & imm mod 2 = 0
147 #define BGT_FWD(imm) (0xdc00 + ((imm) >> 1) )
148 // b pc+imm @ 0 <= imm < 2048 & imm mod 2 = 0
149 #define B_FWD(imm) (0xe000 + ((imm) >> 1) )
150 // bx reg
151 #define BX(reg) (0x4700 + ((reg) << 3) )
152
153
154 // data pool defines
155 #define CACHE_DATA_JUMP (2)
156 #define CACHE_DATA_ALIGN (32)
157 #define CACHE_DATA_MIN (32)
158 #define CACHE_DATA_MAX (288)
159
160 // data pool variables
161 static Bit8u * cache_datapos = NULL; // position of data pool in the cache block
162 static Bit32u cache_datasize = 0; // total size of data pool
163 static Bit32u cache_dataindex = 0; // used size of data pool = index of free data item (in bytes) in data pool
164
165
166 // forwarded function
167 static void INLINE gen_create_branch_short(void * func);
168
169 // function to check distance to data pool
170 // if too close, then generate jump after data pool
171 static void cache_checkinstr(Bit32u size) {
172 if (cache_datasize == 0) {
173 if (cache_datapos != NULL) {
174 if (cache.pos + size + CACHE_DATA_JUMP >= cache_datapos) {
175 cache_datapos = NULL;
176 }
177 }
178 return;
179 }
180
181 if (cache.pos + size + CACHE_DATA_JUMP <= cache_datapos) return;
182
183 {
184 register Bit8u * newcachepos;
185
186 newcachepos = cache_datapos + cache_datasize;
187 gen_create_branch_short(newcachepos);
188 cache.pos = newcachepos;
189 }
190
191 if (cache.pos + CACHE_DATA_MAX + CACHE_DATA_ALIGN >= cache.block.active->cache.start + cache.block.active->cache.size &&
192 cache.pos + CACHE_DATA_MIN + CACHE_DATA_ALIGN + (CACHE_DATA_ALIGN - CACHE_ALIGN) < cache.block.active->cache.start + cache.block.active->cache.size)
193 {
194 cache_datapos = (Bit8u *) (((Bitu)cache.block.active->cache.start + cache.block.active->cache.size - CACHE_DATA_ALIGN) & ~(CACHE_DATA_ALIGN - 1));
195 } else {
196 register Bit32u cachemodsize;
197
198 cachemodsize = (cache.pos - cache.block.active->cache.start) & (CACHE_MAXSIZE - 1);
199
200 if (cachemodsize + CACHE_DATA_MAX + CACHE_DATA_ALIGN <= CACHE_MAXSIZE ||
201 cachemodsize + CACHE_DATA_MIN + CACHE_DATA_ALIGN + (CACHE_DATA_ALIGN - CACHE_ALIGN) > CACHE_MAXSIZE)
202 {
203 cache_datapos = (Bit8u *) (((Bitu)cache.pos + CACHE_DATA_MAX) & ~(CACHE_DATA_ALIGN - 1));
204 } else {
205 cache_datapos = (Bit8u *) (((Bitu)cache.pos + (CACHE_MAXSIZE - CACHE_DATA_ALIGN) - cachemodsize) & ~(CACHE_DATA_ALIGN - 1));
206 }
207 }
208
209 cache_datasize = 0;
210 cache_dataindex = 0;
211 }
212
213 // function to reserve item in data pool
214 // returns address of item
215 static Bit8u * cache_reservedata(void) {
216 // if data pool not yet initialized, then initialize data pool
217 if (GCC_UNLIKELY(cache_datapos == NULL)) {
218 if (cache.pos + CACHE_DATA_MIN + CACHE_DATA_ALIGN < cache.block.active->cache.start + CACHE_DATA_MAX) {
219 cache_datapos = (Bit8u *) (((Bitu)cache.block.active->cache.start + CACHE_DATA_MAX) & ~(CACHE_DATA_ALIGN - 1));
220 }
221 }
222
223 // if data pool not yet used, then set data pool
224 if (cache_datasize == 0) {
225 // set data pool address is too close (or behind) cache.pos then set new data pool size
226 if (cache.pos + CACHE_DATA_MIN + CACHE_DATA_JUMP /*+ CACHE_DATA_ALIGN*/ > cache_datapos) {
227 if (cache.pos + CACHE_DATA_MAX + CACHE_DATA_ALIGN >= cache.block.active->cache.start + cache.block.active->cache.size &&
228 cache.pos + CACHE_DATA_MIN + CACHE_DATA_ALIGN + (CACHE_DATA_ALIGN - CACHE_ALIGN) < cache.block.active->cache.start + cache.block.active->cache.size)
229 {
230 cache_datapos = (Bit8u *) (((Bitu)cache.block.active->cache.start + cache.block.active->cache.size - CACHE_DATA_ALIGN) & ~(CACHE_DATA_ALIGN - 1));
231 } else {
232 register Bit32u cachemodsize;
233
234 cachemodsize = (cache.pos - cache.block.active->cache.start) & (CACHE_MAXSIZE - 1);
235
236 if (cachemodsize + CACHE_DATA_MAX + CACHE_DATA_ALIGN <= CACHE_MAXSIZE ||
237 cachemodsize + CACHE_DATA_MIN + CACHE_DATA_ALIGN + (CACHE_DATA_ALIGN - CACHE_ALIGN) > CACHE_MAXSIZE)
238 {
239 cache_datapos = (Bit8u *) (((Bitu)cache.pos + CACHE_DATA_MAX) & ~(CACHE_DATA_ALIGN - 1));
240 } else {
241 cache_datapos = (Bit8u *) (((Bitu)cache.pos + (CACHE_MAXSIZE - CACHE_DATA_ALIGN) - cachemodsize) & ~(CACHE_DATA_ALIGN - 1));
242 }
243 }
244 }
245 // set initial data pool size
246 cache_datasize = CACHE_DATA_ALIGN;
247 }
248
249 // if data pool is full, then enlarge data pool
250 if (cache_dataindex == cache_datasize) {
251 cache_datasize += CACHE_DATA_ALIGN;
252 }
253
254 cache_dataindex += 4;
255 return (cache_datapos + (cache_dataindex - 4));
256 }
257
258 static void cache_block_before_close(void) {
259 // if data pool in use, then resize cache block to include the data pool
260 if (cache_datasize != 0)
261 {
262 cache.pos = cache_datapos + cache_dataindex;
263 }
264
265 // clear the values before next use
266 cache_datapos = NULL;
267 cache_datasize = 0;
268 cache_dataindex = 0;
269 }
270
271
272 // move a full register from reg_src to reg_dst
273 static void gen_mov_regs(HostReg reg_dst,HostReg reg_src) {
274 if(reg_src == reg_dst) return;
275 cache_checkinstr(2);
276 cache_addw( MOV_REG(reg_dst, reg_src) ); // mov reg_dst, reg_src
277 }
278
279 // move a 32bit constant value into dest_reg
280 static void gen_mov_dword_to_reg_imm(HostReg dest_reg,Bit32u imm) {
281 if ((imm & 0xffffff00) == 0) {
282 cache_checkinstr(2);
283 cache_addw( MOV_IMM(dest_reg, imm) ); // mov dest_reg, #(imm)
284 } else if ((imm & 0xffff00ff) == 0) {
285 cache_checkinstr(4);
286 cache_addw( MOV_IMM(dest_reg, imm >> 8) ); // mov dest_reg, #(imm >> 8)
287 cache_addw( LSL_IMM(dest_reg, dest_reg, 8) ); // lsl dest_reg, dest_reg, #8
288 } else if ((imm & 0xff00ffff) == 0) {
289 cache_checkinstr(4);
290 cache_addw( MOV_IMM(dest_reg, imm >> 16) ); // mov dest_reg, #(imm >> 16)
291 cache_addw( LSL_IMM(dest_reg, dest_reg, 16) ); // lsl dest_reg, dest_reg, #16
292 } else if ((imm & 0x00ffffff) == 0) {
293 cache_checkinstr(4);
294 cache_addw( MOV_IMM(dest_reg, imm >> 24) ); // mov dest_reg, #(imm >> 24)
295 cache_addw( LSL_IMM(dest_reg, dest_reg, 24) ); // lsl dest_reg, dest_reg, #24
296 } else {
297 Bit32u diff;
298
299 cache_checkinstr(4);
300
301 diff = imm - ((Bit32u)cache.pos+4);
302
303 if ((diff < 1024) && ((imm & 0x03) == 0)) {
304 if (((Bit32u)cache.pos & 0x03) == 0) {
305 cache_addw( ADD_LO_PC_IMM(dest_reg, diff >> 2) ); // add dest_reg, pc, #(diff >> 2)
306 } else {
307 cache_addw( NOP ); // nop
308 cache_addw( ADD_LO_PC_IMM(dest_reg, (diff - 2) >> 2) ); // add dest_reg, pc, #((diff - 2) >> 2)
309 }
310 } else {
311 Bit8u *datapos;
312
313 datapos = cache_reservedata();
314 *(Bit32u*)datapos=imm;
315
316 if (((Bit32u)cache.pos & 0x03) == 0) {
317 cache_addw( LDR_PC_IMM(dest_reg, datapos - (cache.pos + 4)) ); // ldr dest_reg, [pc, datapos]
318 } else {
319 cache_addw( LDR_PC_IMM(dest_reg, datapos - (cache.pos + 2)) ); // ldr dest_reg, [pc, datapos]
320 }
321 }
322 }
323 }
324
325 // helper function for gen_mov_word_to_reg
326 static void gen_mov_word_to_reg_helper(HostReg dest_reg,void* data,bool dword,HostReg data_reg) {
327 // alignment....
328 if (dword) {
329 if ((Bit32u)data & 3) {
330 if ( ((Bit32u)data & 3) == 2 ) {
331 cache_checkinstr(8);
332 cache_addw( LDRH_IMM(dest_reg, data_reg, 0) ); // ldrh dest_reg, [data_reg]
333 cache_addw( LDRH_IMM(templo1, data_reg, 2) ); // ldrh templo1, [data_reg, #2]
334 cache_addw( LSL_IMM(templo1, templo1, 16) ); // lsl templo1, templo1, #16
335 cache_addw( ORR(dest_reg, templo1) ); // orr dest_reg, templo1
336 } else {
337 cache_checkinstr(16);
338 cache_addw( LDRB_IMM(dest_reg, data_reg, 0) ); // ldrb dest_reg, [data_reg]
339 cache_addw( ADD_IMM3(templo1, data_reg, 1) ); // add templo1, data_reg, #1
340 cache_addw( LDRH_IMM(templo1, templo1, 0) ); // ldrh templo1, [templo1]
341 cache_addw( LSL_IMM(templo1, templo1, 8) ); // lsl templo1, templo1, #8
342 cache_addw( ORR(dest_reg, templo1) ); // orr dest_reg, templo1
343 cache_addw( LDRB_IMM(templo1, data_reg, 3) ); // ldrb templo1, [data_reg, #3]
344 cache_addw( LSL_IMM(templo1, templo1, 24) ); // lsl templo1, templo1, #24
345 cache_addw( ORR(dest_reg, templo1) ); // orr dest_reg, templo1
346 }
347 } else {
348 cache_checkinstr(2);
349 cache_addw( LDR_IMM(dest_reg, data_reg, 0) ); // ldr dest_reg, [data_reg]
350 }
351 } else {
352 if ((Bit32u)data & 1) {
353 cache_checkinstr(8);
354 cache_addw( LDRB_IMM(dest_reg, data_reg, 0) ); // ldrb dest_reg, [data_reg]
355 cache_addw( LDRB_IMM(templo1, data_reg, 1) ); // ldrb templo1, [data_reg, #1]
356 cache_addw( LSL_IMM(templo1, templo1, 8) ); // lsl templo1, templo1, #8
357 cache_addw( ORR(dest_reg, templo1) ); // orr dest_reg, templo1
358 } else {
359 cache_checkinstr(2);
360 cache_addw( LDRH_IMM(dest_reg, data_reg, 0) ); // ldrh dest_reg, [data_reg]
361 }
362 }
363 }
364
365 // move a 32bit (dword==true) or 16bit (dword==false) value from memory into dest_reg
366 // 16bit moves may destroy the upper 16bit of the destination register
367 static void gen_mov_word_to_reg(HostReg dest_reg,void* data,bool dword) {
368 gen_mov_dword_to_reg_imm(templo2, (Bit32u)data);
369 gen_mov_word_to_reg_helper(dest_reg, data, dword, templo2);
370 }
371
372 // move a 16bit constant value into dest_reg
373 // the upper 16bit of the destination register may be destroyed
374 static void INLINE gen_mov_word_to_reg_imm(HostReg dest_reg,Bit16u imm) {
375 gen_mov_dword_to_reg_imm(dest_reg, (Bit32u)imm);
376 }
377
378 // helper function for gen_mov_word_from_reg
379 static void gen_mov_word_from_reg_helper(HostReg src_reg,void* dest,bool dword, HostReg data_reg) {
380 // alignment....
381 if (dword) {
382 if ((Bit32u)dest & 3) {
383 if ( ((Bit32u)dest & 3) == 2 ) {
384 cache_checkinstr(8);
385 cache_addw( STRH_IMM(src_reg, data_reg, 0) ); // strh src_reg, [data_reg]
386 cache_addw( MOV_REG(templo1, src_reg) ); // mov templo1, src_reg
387 cache_addw( LSR_IMM(templo1, templo1, 16) ); // lsr templo1, templo1, #16
388 cache_addw( STRH_IMM(templo1, data_reg, 2) ); // strh templo1, [data_reg, #2]
389 } else {
390 cache_checkinstr(20);
391 cache_addw( STRB_IMM(src_reg, data_reg, 0) ); // strb src_reg, [data_reg]
392 cache_addw( MOV_REG(templo1, src_reg) ); // mov templo1, src_reg
393 cache_addw( LSR_IMM(templo1, templo1, 8) ); // lsr templo1, templo1, #8
394 cache_addw( STRB_IMM(templo1, data_reg, 1) ); // strb templo1, [data_reg, #1]
395 cache_addw( MOV_REG(templo1, src_reg) ); // mov templo1, src_reg
396 cache_addw( LSR_IMM(templo1, templo1, 16) ); // lsr templo1, templo1, #16
397 cache_addw( STRB_IMM(templo1, data_reg, 2) ); // strb templo1, [data_reg, #2]
398 cache_addw( MOV_REG(templo1, src_reg) ); // mov templo1, src_reg
399 cache_addw( LSR_IMM(templo1, templo1, 24) ); // lsr templo1, templo1, #24
400 cache_addw( STRB_IMM(templo1, data_reg, 3) ); // strb templo1, [data_reg, #3]
401 }
402 } else {
403 cache_checkinstr(2);
404 cache_addw( STR_IMM(src_reg, data_reg, 0) ); // str src_reg, [data_reg]
405 }
406 } else {
407 if ((Bit32u)dest & 1) {
408 cache_checkinstr(8);
409 cache_addw( STRB_IMM(src_reg, data_reg, 0) ); // strb src_reg, [data_reg]
410 cache_addw( MOV_REG(templo1, src_reg) ); // mov templo1, src_reg
411 cache_addw( LSR_IMM(templo1, templo1, 8) ); // lsr templo1, templo1, #8
412 cache_addw( STRB_IMM(templo1, data_reg, 1) ); // strb templo1, [data_reg, #1]
413 } else {
414 cache_checkinstr(2);
415 cache_addw( STRH_IMM(src_reg, data_reg, 0) ); // strh src_reg, [data_reg]
416 }
417 }
418 }
419
420 // move 32bit (dword==true) or 16bit (dword==false) of a register into memory
421 static void gen_mov_word_from_reg(HostReg src_reg,void* dest,bool dword) {
422 gen_mov_dword_to_reg_imm(templo2, (Bit32u)dest);
423 gen_mov_word_from_reg_helper(src_reg, dest, dword, templo2);
424 }
425
426 // move an 8bit value from memory into dest_reg
427 // the upper 24bit of the destination register can be destroyed
428 // this function does not use FC_OP1/FC_OP2 as dest_reg as these
429 // registers might not be directly byte-accessible on some architectures
430 static void gen_mov_byte_to_reg_low(HostReg dest_reg,void* data) {
431 gen_mov_dword_to_reg_imm(templo1, (Bit32u)data);
432 cache_checkinstr(2);
433 cache_addw( LDRB_IMM(dest_reg, templo1, 0) ); // ldrb dest_reg, [templo1]
434 }
435
436 // move an 8bit value from memory into dest_reg
437 // the upper 24bit of the destination register can be destroyed
438 // this function can use FC_OP1/FC_OP2 as dest_reg which are
439 // not directly byte-accessible on some architectures
440 static void INLINE gen_mov_byte_to_reg_low_canuseword(HostReg dest_reg,void* data) {
441 gen_mov_byte_to_reg_low(dest_reg, data);
442 }
443
444 // move an 8bit constant value into dest_reg
445 // the upper 24bit of the destination register can be destroyed
446 // this function does not use FC_OP1/FC_OP2 as dest_reg as these
447 // registers might not be directly byte-accessible on some architectures
448 static void gen_mov_byte_to_reg_low_imm(HostReg dest_reg,Bit8u imm) {
449 cache_checkinstr(2);
450 cache_addw( MOV_IMM(dest_reg, imm) ); // mov dest_reg, #(imm)
451 }
452
453 // move an 8bit constant value into dest_reg
454 // the upper 24bit of the destination register can be destroyed
455 // this function can use FC_OP1/FC_OP2 as dest_reg which are
456 // not directly byte-accessible on some architectures
457 static void INLINE gen_mov_byte_to_reg_low_imm_canuseword(HostReg dest_reg,Bit8u imm) {
458 gen_mov_byte_to_reg_low_imm(dest_reg, imm);
459 }
460
461 // move the lowest 8bit of a register into memory
462 static void gen_mov_byte_from_reg_low(HostReg src_reg,void* dest) {
463 gen_mov_dword_to_reg_imm(templo1, (Bit32u)dest);
464 cache_checkinstr(2);
465 cache_addw( STRB_IMM(src_reg, templo1, 0) ); // strb src_reg, [templo1]
466 }
467
468
469
470 // convert an 8bit word to a 32bit dword
471 // the register is zero-extended (sign==false) or sign-extended (sign==true)
472 static void gen_extend_byte(bool sign,HostReg reg) {
473 cache_checkinstr(4);
474 cache_addw( LSL_IMM(reg, reg, 24) ); // lsl reg, reg, #24
475
476 if (sign) {
477 cache_addw( ASR_IMM(reg, reg, 24) ); // asr reg, reg, #24
478 } else {
479 cache_addw( LSR_IMM(reg, reg, 24) ); // lsr reg, reg, #24
480 }
481 }
482
483 // convert a 16bit word to a 32bit dword
484 // the register is zero-extended (sign==false) or sign-extended (sign==true)
485 static void gen_extend_word(bool sign,HostReg reg) {
486 cache_checkinstr(4);
487 cache_addw( LSL_IMM(reg, reg, 16) ); // lsl reg, reg, #16
488
489 if (sign) {
490 cache_addw( ASR_IMM(reg, reg, 16) ); // asr reg, reg, #16
491 } else {
492 cache_addw( LSR_IMM(reg, reg, 16) ); // lsr reg, reg, #16
493 }
494 }
495
496 // add a 32bit value from memory to a full register
497 static void gen_add(HostReg reg,void* op) {
498 gen_mov_word_to_reg(templo3, op, 1);
499 cache_checkinstr(2);
500 cache_addw( ADD_REG(reg, reg, templo3) ); // add reg, reg, templo3
501 }
502
503 // add a 32bit constant value to a full register
504 static void gen_add_imm(HostReg reg,Bit32u imm) {
505 if(!imm) return;
506 gen_mov_dword_to_reg_imm(templo1, imm);
507 cache_checkinstr(2);
508 cache_addw( ADD_REG(reg, reg, templo1) ); // add reg, reg, templo1
509 }
510
511 // and a 32bit constant value with a full register
512 static void gen_and_imm(HostReg reg,Bit32u imm) {
513 if(imm == 0xffffffff) return;
514 gen_mov_dword_to_reg_imm(templo1, imm);
515 cache_checkinstr(2);
516 cache_addw( AND(reg, templo1) ); // and reg, templo1
517 }
518
519
520 // move a 32bit constant value into memory
521 static void gen_mov_direct_dword(void* dest,Bit32u imm) {
522 gen_mov_dword_to_reg_imm(templo3, imm);
523 gen_mov_word_from_reg(templo3, dest, 1);
524 }
525
526 // move an address into memory
527 static void INLINE gen_mov_direct_ptr(void* dest,DRC_PTR_SIZE_IM imm) {
528 gen_mov_direct_dword(dest,(Bit32u)imm);
529 }
530
531 // add an 8bit constant value to a dword memory value
532 static void gen_add_direct_byte(void* dest,Bit8s imm) {
533 if(!imm) return;
534 gen_mov_dword_to_reg_imm(templo2, (Bit32u)dest);
535 gen_mov_word_to_reg_helper(templo3, dest, 1, templo2);
536 cache_checkinstr(2);
537 if (imm >= 0) {
538 cache_addw( ADD_IMM8(templo3, (Bit32s)imm) ); // add templo3, #(imm)
539 } else {
540 cache_addw( SUB_IMM8(templo3, -((Bit32s)imm)) ); // sub templo3, #(-imm)
541 }
542 gen_mov_word_from_reg_helper(templo3, dest, 1, templo2);
543 }
544
545 // add a 32bit (dword==true) or 16bit (dword==false) constant value to a memory value
546 static void gen_add_direct_word(void* dest,Bit32u imm,bool dword) {
547 if(!imm) return;
548 if (dword && ( (imm<128) || (imm>=0xffffff80) ) ) {
549 gen_add_direct_byte(dest,(Bit8s)imm);
550 return;
551 }
552 gen_mov_dword_to_reg_imm(templo2, (Bit32u)dest);
553 gen_mov_word_to_reg_helper(templo3, dest, dword, templo2);
554 if (dword) {
555 gen_mov_dword_to_reg_imm(templo1, imm);
556 } else {
557 gen_mov_word_to_reg_imm(templo1, (Bit16u)imm);
558 }
559 cache_checkinstr(2);
560 cache_addw( ADD_REG(templo3, templo3, templo1) ); // add templo3, templo3, templo1
561 gen_mov_word_from_reg_helper(templo3, dest, dword, templo2);
562 }
563
564 // subtract an 8bit constant value from a dword memory value
565 static void gen_sub_direct_byte(void* dest,Bit8s imm) {
566 if(!imm) return;
567 gen_mov_dword_to_reg_imm(templo2, (Bit32u)dest);
568 gen_mov_word_to_reg_helper(templo3, dest, 1, templo2);
569 cache_checkinstr(2);
570 if (imm >= 0) {
571 cache_addw( SUB_IMM8(templo3, (Bit32s)imm) ); // sub templo3, #(imm)
572 } else {
573 cache_addw( ADD_IMM8(templo3, -((Bit32s)imm)) ); // add templo3, #(-imm)
574 }
575 gen_mov_word_from_reg_helper(templo3, dest, 1, templo2);
576 }
577
578 // subtract a 32bit (dword==true) or 16bit (dword==false) constant value from a memory value
579 static void gen_sub_direct_word(void* dest,Bit32u imm,bool dword) {
580 if(!imm) return;
581 if (dword && ( (imm<128) || (imm>=0xffffff80) ) ) {
582 gen_sub_direct_byte(dest,(Bit8s)imm);
583 return;
584 }
585 gen_mov_dword_to_reg_imm(templo2, (Bit32u)dest);
586 gen_mov_word_to_reg_helper(templo3, dest, dword, templo2);
587 if (dword) {
588 gen_mov_dword_to_reg_imm(templo1, imm);
589 } else {
590 gen_mov_word_to_reg_imm(templo1, (Bit16u)imm);
591 }
592 cache_checkinstr(2);
593 cache_addw( SUB_REG(templo3, templo3, templo1) ); // sub templo3, templo3, templo1
594 gen_mov_word_from_reg_helper(templo3, dest, dword, templo2);
595 }
596
597 // effective address calculation, destination is dest_reg
598 // scale_reg is scaled by scale (scale_reg*(2^scale)) and
599 // added to dest_reg, then the immediate value is added
600 static INLINE void gen_lea(HostReg dest_reg,HostReg scale_reg,Bitu scale,Bits imm) {
601 if (scale) {
602 cache_checkinstr(4);
603 cache_addw( LSL_IMM(templo1, scale_reg, scale) ); // lsl templo1, scale_reg, #(scale)
604 cache_addw( ADD_REG(dest_reg, dest_reg, templo1) ); // add dest_reg, dest_reg, templo1
605 } else {
606 cache_checkinstr(2);
607 cache_addw( ADD_REG(dest_reg, dest_reg, scale_reg) ); // add dest_reg, dest_reg, scale_reg
608 }
609 gen_add_imm(dest_reg, imm);
610 }
611
612 // effective address calculation, destination is dest_reg
613 // dest_reg is scaled by scale (dest_reg*(2^scale)),
614 // then the immediate value is added
615 static INLINE void gen_lea(HostReg dest_reg,Bitu scale,Bits imm) {
616 if (scale) {
617 cache_checkinstr(2);
618 cache_addw( LSL_IMM(dest_reg, dest_reg, scale) ); // lsl dest_reg, dest_reg, #(scale)
619 }
620 gen_add_imm(dest_reg, imm);
621 }
622
623 // helper function for gen_call_function_raw and gen_call_function_setup
624 static void gen_call_function_helper(void * func) {
625 Bit8u *datapos;
626
627 datapos = cache_reservedata();
628 *(Bit32u*)datapos=(Bit32u)func;
629
630 if (((Bit32u)cache.pos & 0x03) == 0) {
631 cache_addw( LDR_PC_IMM(templo1, datapos - (cache.pos + 4)) ); // ldr templo1, [pc, datapos]
632 cache_addw( ADD_LO_PC_IMM(templo2, 4) ); // adr templo2, after_call (add templo2, pc, #4)
633 cache_addw( MOV_HI_LO(HOST_lr, templo2) ); // mov lr, templo2
634 cache_addw( BX(templo1) ); // bx templo1 --- switch to arm state
635 } else {
636 cache_addw( LDR_PC_IMM(templo1, datapos - (cache.pos + 2)) ); // ldr templo1, [pc, datapos]
637 cache_addw( ADD_LO_PC_IMM(templo2, 4) ); // adr templo2, after_call (add templo2, pc, #4)
638 cache_addw( MOV_HI_LO(HOST_lr, templo2) ); // mov lr, templo2
639 cache_addw( BX(templo1) ); // bx templo1 --- switch to arm state
640 cache_addw( NOP ); // nop
641 }
642 // after_call:
643
644 // switch from arm to thumb state
645 cache_addd(0xe2800000 + (templo1 << 12) + (HOST_pc << 16) + (1)); // add templo1, pc, #1
646 cache_addd(0xe12fff10 + (templo1)); // bx templo1
647
648 // thumb state from now on
649 }
650
651 // generate a call to a parameterless function
652 static void INLINE gen_call_function_raw(void * func) {
653 cache_checkinstr(18);
654 gen_call_function_helper(func);
655 }
656
657 // generate a call to a function with paramcount parameters
658 // note: the parameters are loaded in the architecture specific way
659 // using the gen_load_param_ functions below
660 static Bit32u INLINE gen_call_function_setup(void * func,Bitu paramcount,bool fastcall=false) {
661 cache_checkinstr(18);
662 Bit32u proc_addr = (Bit32u)cache.pos;
663 gen_call_function_helper(func);
664 return proc_addr;
665 // if proc_addr is on word boundary ((proc_addr & 0x03) == 0)
666 // then length of generated code is 16 bytes
667 // otherwise length of generated code is 18 bytes
668 }
669
670 #if (1)
671 // max of 4 parameters in a1-a4
672
673 // load an immediate value as param'th function parameter
674 static void INLINE gen_load_param_imm(Bitu imm,Bitu param) {
675 gen_mov_dword_to_reg_imm(param, imm);
676 }
677
678 // load an address as param'th function parameter
679 static void INLINE gen_load_param_addr(Bitu addr,Bitu param) {
680 gen_mov_dword_to_reg_imm(param, addr);
681 }
682
683 // load a host-register as param'th function parameter
684 static void INLINE gen_load_param_reg(Bitu reg,Bitu param) {
685 gen_mov_regs(param, reg);
686 }
687
688 // load a value from memory as param'th function parameter
689 static void INLINE gen_load_param_mem(Bitu mem,Bitu param) {
690 gen_mov_word_to_reg(param, (void *)mem, 1);
691 }
692 #else
693 other arm abis
694 #endif
695
696 // jump to an address pointed at by ptr, offset is in imm
697 static void gen_jmp_ptr(void * ptr,Bits imm=0) {
698 gen_mov_word_to_reg(templo3, ptr, 1);
699
700 if (imm) {
701 gen_mov_dword_to_reg_imm(templo2, imm);
702 cache_checkinstr(2);
703 cache_addw( ADD_REG(templo3, templo3, templo2) ); // add templo3, templo3, templo2
704 }
705
706 #if (1)
707 // (*ptr) should be word aligned
708 if ((imm & 0x03) == 0) {
709 cache_checkinstr(6);
710 cache_addw( LDR_IMM(templo2, templo3, 0) ); // ldr templo2, [templo3]
711 } else
712 #endif
713 {
714 cache_checkinstr(24);
715 cache_addw( LDRB_IMM(templo2, templo3, 0) ); // ldrb templo2, [templo3]
716 cache_addw( LDRB_IMM(templo1, templo3, 1) ); // ldrb templo1, [templo3, #1]
717 cache_addw( LSL_IMM(templo1, templo1, 8) ); // lsl templo1, templo1, #8
718 cache_addw( ORR(templo2, templo1) ); // orr templo2, templo1
719 cache_addw( LDRB_IMM(templo1, templo3, 2) ); // ldrb templo1, [templo3, #2]
720 cache_addw( LSL_IMM(templo1, templo1, 16) ); // lsl templo1, templo1, #16
721 cache_addw( ORR(templo2, templo1) ); // orr templo2, templo1
722 cache_addw( LDRB_IMM(templo1, templo3, 3) ); // ldrb templo1, [templo3, #3]
723 cache_addw( LSL_IMM(templo1, templo1, 24) ); // lsl templo1, templo1, #24
724 cache_addw( ORR(templo2, templo1) ); // orr templo2, templo1
725 }
726
727 // increase jmp address to keep thumb state
728 cache_addw( ADD_IMM3(templo2, templo2, 1) ); // add templo2, templo2, #1
729
730 cache_addw( BX(templo2) ); // bx templo2
731 }
732
733 // short conditional jump (+-127 bytes) if register is zero
734 // the destination is set by gen_fill_branch() later
735 static Bit32u gen_create_branch_on_zero(HostReg reg,bool dword) {
736 cache_checkinstr(4);
737 if (dword) {
738 cache_addw( CMP_IMM(reg, 0) ); // cmp reg, #0
739 } else {
740 cache_addw( LSL_IMM(templo1, reg, 16) ); // lsl templo1, reg, #16
741 }
742 cache_addw( BEQ_FWD(0) ); // beq j
743 return ((Bit32u)cache.pos-2);
744 }
745
746 // short conditional jump (+-127 bytes) if register is nonzero
747 // the destination is set by gen_fill_branch() later
748 static Bit32u gen_create_branch_on_nonzero(HostReg reg,bool dword) {
749 cache_checkinstr(4);
750 if (dword) {
751 cache_addw( CMP_IMM(reg, 0) ); // cmp reg, #0
752 } else {
753 cache_addw( LSL_IMM(templo1, reg, 16) ); // lsl templo1, reg, #16
754 }
755 cache_addw( BNE_FWD(0) ); // bne j
756 return ((Bit32u)cache.pos-2);
757 }
758
759 // calculate relative offset and fill it into the location pointed to by data
760 static void INLINE gen_fill_branch(DRC_PTR_SIZE_IM data) {
761 #if C_DEBUG
762 Bits len=(Bit32u)cache.pos-(data+4);
763 if (len<0) len=-len;
764 if (len>252) LOG_MSG("Big jump %d",len);
765 #endif
766 *(Bit8u*)data=(Bit8u)( ((Bit32u)cache.pos-(data+4)) >> 1 );
767 }
768
769
770 // conditional jump if register is nonzero
771 // for isdword==true the 32bit of the register are tested
772 // for isdword==false the lowest 8bit of the register are tested
773 static Bit32u gen_create_branch_long_nonzero(HostReg reg,bool isdword) {
774 Bit8u *datapos;
775
776 cache_checkinstr(8);
777 datapos = cache_reservedata();
778
779 if (isdword) {
780 cache_addw( CMP_IMM(reg, 0) ); // cmp reg, #0
781 } else {
782 cache_addw( LSL_IMM(templo2, reg, 24) ); // lsl templo2, reg, #24
783 }
784 cache_addw( BEQ_FWD(2) ); // beq nobranch (pc+2)
785 if (((Bit32u)cache.pos & 0x03) == 0) {
786 cache_addw( LDR_PC_IMM(templo1, datapos - (cache.pos + 4)) ); // ldr templo1, [pc, datapos]
787 } else {
788 cache_addw( LDR_PC_IMM(templo1, datapos - (cache.pos + 2)) ); // ldr templo1, [pc, datapos]
789 }
790 cache_addw( BX(templo1) ); // bx templo1
791 // nobranch:
792 return ((Bit32u)datapos);
793 }
794
795 // compare 32bit-register against zero and jump if value less/equal than zero
796 static Bit32u gen_create_branch_long_leqzero(HostReg reg) {
797 Bit8u *datapos;
798
799 cache_checkinstr(8);
800 datapos = cache_reservedata();
801
802 cache_addw( CMP_IMM(reg, 0) ); // cmp reg, #0
803 cache_addw( BGT_FWD(2) ); // bgt nobranch (pc+2)
804 if (((Bit32u)cache.pos & 0x03) == 0) {
805 cache_addw( LDR_PC_IMM(templo1, datapos - (cache.pos + 4)) ); // ldr templo1, [pc, datapos]
806 } else {
807 cache_addw( LDR_PC_IMM(templo1, datapos - (cache.pos + 2)) ); // ldr templo1, [pc, datapos]
808 }
809 cache_addw( BX(templo1) ); // bx templo1
810 // nobranch:
811 return ((Bit32u)datapos);
812 }
813
814 // calculate long relative offset and fill it into the location pointed to by data
815 static void INLINE gen_fill_branch_long(Bit32u data) {
816 // this is an absolute branch
817 *(Bit32u*)data=((Bit32u)cache.pos) + 1; // add 1 to keep processor in thumb state
818 }
819
820 static void gen_run_code(void) {
821 // switch from arm to thumb state
822 cache_addd(0xe2800000 + (HOST_r3 << 12) + (HOST_pc << 16) + (1)); // add r3, pc, #1
823 cache_addd(0xe12fff10 + (HOST_r3)); // bx r3
824
825 // thumb state from now on
826 cache_addw(0xb500); // push {lr}
827 cache_addw( MOV_LO_HI(HOST_r3, FC_SEGS_ADDR) ); // mov r3, FC_SEGS_ADDR
828 cache_addw( MOV_LO_HI(HOST_r2, FC_REGS_ADDR) ); // mov r2, FC_REGS_ADDR
829 cache_addw(0xb4fc); // push {r2,r3,v1-v4}
830
831 // adr: 16
832 cache_addw( LDR_PC_IMM(HOST_r3, 64 - (16 + 4)) ); // ldr r3, [pc, #(&Segs)]
833 // adr: 18
834 cache_addw( LDR_PC_IMM(HOST_r2, 68 - (18 + 2)) ); // ldr r2, [pc, #(&cpu_regs)]
835 cache_addw( MOV_HI_LO(FC_SEGS_ADDR, HOST_r3) ); // mov FC_SEGS_ADDR, r3
836 cache_addw( MOV_HI_LO(FC_REGS_ADDR, HOST_r2) ); // mov FC_REGS_ADDR, r2
837
838 // align 4
839 cache_addw( ADD_LO_PC_IMM(HOST_r3, 8) ); // add r3, pc, #8
840 cache_addw( ADD_IMM8(HOST_r0, 1) ); // add r0, #1
841 cache_addw( ADD_IMM8(HOST_r3, 1) ); // add r3, #1
842 cache_addw(0xb408); // push {r3}
843 cache_addw( BX(HOST_r0) ); // bx r0
844 cache_addw( NOP ); // nop
845
846 // align 4
847 cache_addw(0xbcfc); // pop {r2,r3,v1-v4}
848 cache_addw( MOV_HI_LO(FC_SEGS_ADDR, HOST_r3) ); // mov FC_SEGS_ADDR, r3
849 cache_addw( MOV_HI_LO(FC_REGS_ADDR, HOST_r2) ); // mov FC_REGS_ADDR, r2
850
851 cache_addw(0xbc08); // pop {r3}
852 cache_addw( BX(HOST_r3) ); // bx r3
853
854 // fill up to 64 bytes
855 cache_addw( NOP ); // nop
856 cache_addd( NOP | (NOP << 16) ); // nop, nop
857 cache_addd( NOP | (NOP << 16) ); // nop, nop
858 cache_addd( NOP | (NOP << 16) ); // nop, nop
859 cache_addd( NOP | (NOP << 16) ); // nop, nop
860
861 // adr: 64
862 cache_addd((Bit32u)&Segs); // address of "Segs"
863 // adr: 68
864 cache_addd((Bit32u)&cpu_regs); // address of "cpu_regs"
865 }
866
867 // return from a function
868 static void gen_return_function(void) {
869 cache_checkinstr(4);
870 cache_addw(0xbc08); // pop {r3}
871 cache_addw( BX(HOST_r3) ); // bx r3
872 }
873
874
875 // short unconditional jump (over data pool)
876 // must emit at most CACHE_DATA_JUMP bytes
877 static void INLINE gen_create_branch_short(void * func) {
878 cache_addw( B_FWD((Bit32u)func - ((Bit32u)cache.pos + 4)) ); // b func
879 }
880
881
882 #ifdef DRC_FLAGS_INVALIDATION
883
884 // called when a call to a function can be replaced by a
885 // call to a simpler function
886 static void gen_fill_function_ptr(Bit8u * pos,void* fct_ptr,Bitu flags_type) {
887 if ((*(Bit16u*)pos & 0xf000) == 0xe000) {
888 if ((*(Bit16u*)pos & 0x0fff) >= ((CACHE_DATA_ALIGN / 2) - 1) &&
889 (*(Bit16u*)pos & 0x0fff) < 0x0800)
890 {
891 pos = (Bit8u *) ( ( ( (Bit32u)(*(Bit16u*)pos & 0x0fff) ) << 1 ) + ((Bit32u)pos + 4) );
892 }
893 }
894
895 #ifdef DRC_FLAGS_INVALIDATION_DCODE
896 if (((Bit32u)pos & 0x03) == 0)
897 {
898 // try to avoid function calls but rather directly fill in code
899 switch (flags_type) {
900 case t_ADDb:
901 case t_ADDw:
902 case t_ADDd:
903 *(Bit16u*)pos=ADD_REG(HOST_a1, HOST_a1, HOST_a2); // add a1, a1, a2
904 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
905 break;
906 case t_ORb:
907 case t_ORw:
908 case t_ORd:
909 *(Bit16u*)pos=ORR(HOST_a1, HOST_a2); // orr a1, a2
910 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
911 break;
912 case t_ANDb:
913 case t_ANDw:
914 case t_ANDd:
915 *(Bit16u*)pos=AND(HOST_a1, HOST_a2); // and a1, a2
916 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
917 break;
918 case t_SUBb:
919 case t_SUBw:
920 case t_SUBd:
921 *(Bit16u*)pos=SUB_REG(HOST_a1, HOST_a1, HOST_a2); // sub a1, a1, a2
922 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
923 break;
924 case t_XORb:
925 case t_XORw:
926 case t_XORd:
927 *(Bit16u*)pos=EOR(HOST_a1, HOST_a2); // eor a1, a2
928 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
929 break;
930 case t_CMPb:
931 case t_CMPw:
932 case t_CMPd:
933 case t_TESTb:
934 case t_TESTw:
935 case t_TESTd:
936 *(Bit16u*)pos=B_FWD(12); // b after_call (pc+12)
937 break;
938 case t_INCb:
939 case t_INCw:
940 case t_INCd:
941 *(Bit16u*)pos=ADD_IMM3(HOST_a1, HOST_a1, 1); // add a1, a1, #1
942 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
943 break;
944 case t_DECb:
945 case t_DECw:
946 case t_DECd:
947 *(Bit16u*)pos=SUB_IMM3(HOST_a1, HOST_a1, 1); // sub a1, a1, #1
948 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
949 break;
950 case t_SHLb:
951 case t_SHLw:
952 case t_SHLd:
953 *(Bit16u*)pos=LSL_REG(HOST_a1, HOST_a2); // lsl a1, a2
954 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
955 break;
956 case t_SHRb:
957 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 24); // lsl a1, a1, #24
958 *(Bit16u*)(pos+2)=LSR_IMM(HOST_a1, HOST_a1, 24); // lsr a1, a1, #24
959 *(Bit16u*)(pos+4)=LSR_REG(HOST_a1, HOST_a2); // lsr a1, a2
960 *(Bit16u*)(pos+6)=B_FWD(6); // b after_call (pc+6)
961 break;
962 case t_SHRw:
963 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 16); // lsl a1, a1, #16
964 *(Bit16u*)(pos+2)=LSR_IMM(HOST_a1, HOST_a1, 16); // lsr a1, a1, #16
965 *(Bit16u*)(pos+4)=LSR_REG(HOST_a1, HOST_a2); // lsr a1, a2
966 *(Bit16u*)(pos+6)=B_FWD(6); // b after_call (pc+6)
967 break;
968 case t_SHRd:
969 *(Bit16u*)pos=LSR_REG(HOST_a1, HOST_a2); // lsr a1, a2
970 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
971 break;
972 case t_SARb:
973 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 24); // lsl a1, a1, #24
974 *(Bit16u*)(pos+2)=ASR_IMM(HOST_a1, HOST_a1, 24); // asr a1, a1, #24
975 *(Bit16u*)(pos+4)=ASR_REG(HOST_a1, HOST_a2); // asr a1, a2
976 *(Bit16u*)(pos+6)=B_FWD(6); // b after_call (pc+6)
977 break;
978 case t_SARw:
979 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 16); // lsl a1, a1, #16
980 *(Bit16u*)(pos+2)=ASR_IMM(HOST_a1, HOST_a1, 16); // asr a1, a1, #16
981 *(Bit16u*)(pos+4)=ASR_REG(HOST_a1, HOST_a2); // asr a1, a2
982 *(Bit16u*)(pos+6)=B_FWD(6); // b after_call (pc+6)
983 break;
984 case t_SARd:
985 *(Bit16u*)pos=ASR_REG(HOST_a1, HOST_a2); // asr a1, a2
986 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
987 break;
988 case t_RORb:
989 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 24); // lsl a1, a1, #24
990 *(Bit16u*)(pos+2)=LSR_IMM(templo1, HOST_a1, 8); // lsr templo1, a1, #8
991 *(Bit16u*)(pos+4)=ORR(HOST_a1, templo1); // orr a1, templo1
992 *(Bit16u*)(pos+6)=NOP; // nop
993 *(Bit16u*)(pos+8)=LSR_IMM(templo1, HOST_a1, 16); // lsr templo1, a1, #16
994 *(Bit16u*)(pos+10)=NOP; // nop
995 *(Bit16u*)(pos+12)=ORR(HOST_a1, templo1); // orr a1, templo1
996 *(Bit16u*)(pos+14)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
997 break;
998 case t_RORw:
999 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 16); // lsl a1, a1, #16
1000 *(Bit16u*)(pos+2)=LSR_IMM(templo1, HOST_a1, 16); // lsr templo1, a1, #16
1001 *(Bit16u*)(pos+4)=ORR(HOST_a1, templo1); // orr a1, templo1
1002 *(Bit16u*)(pos+6)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1003 *(Bit16u*)(pos+8)=B_FWD(4); // b after_call (pc+4)
1004 break;
1005 case t_RORd:
1006 *(Bit16u*)pos=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1007 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
1008 break;
1009 case t_ROLb:
1010 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 24); // lsl a1, a1, #24
1011 *(Bit16u*)(pos+2)=NEG(HOST_a2, HOST_a2); // neg a2, a2
1012 *(Bit16u*)(pos+4)=LSR_IMM(templo1, HOST_a1, 8); // lsr templo1, a1, #8
1013 *(Bit16u*)(pos+6)=ADD_IMM8(HOST_a2, 32); // add a2, #32
1014 *(Bit16u*)(pos+8)=ORR(HOST_a1, templo1); // orr a1, templo1
1015 *(Bit16u*)(pos+10)=LSR_IMM(templo1, HOST_a1, 16); // lsr templo1, a1, #16
1016 *(Bit16u*)(pos+12)=ORR(HOST_a1, templo1); // orr a1, templo1
1017 *(Bit16u*)(pos+14)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1018 break;
1019 case t_ROLw:
1020 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 16); // lsl a1, a1, #16
1021 *(Bit16u*)(pos+2)=NEG(HOST_a2, HOST_a2); // neg a2, a2
1022 *(Bit16u*)(pos+4)=LSR_IMM(templo1, HOST_a1, 16); // lsr templo1, a1, #16
1023 *(Bit16u*)(pos+6)=ADD_IMM8(HOST_a2, 32); // add a2, #32
1024 *(Bit16u*)(pos+8)=ORR(HOST_a1, templo1); // orr a1, templo1
1025 *(Bit16u*)(pos+10)=NOP; // nop
1026 *(Bit16u*)(pos+12)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1027 *(Bit16u*)(pos+14)=NOP; // nop
1028 break;
1029 case t_ROLd:
1030 *(Bit16u*)pos=NEG(HOST_a2, HOST_a2); // neg a2, a2
1031 *(Bit16u*)(pos+2)=ADD_IMM8(HOST_a2, 32); // add a2, #32
1032 *(Bit16u*)(pos+4)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1033 *(Bit16u*)(pos+6)=B_FWD(6); // b after_call (pc+6)
1034 break;
1035 case t_NEGb:
1036 case t_NEGw:
1037 case t_NEGd:
1038 *(Bit16u*)pos=NEG(HOST_a1, HOST_a1); // neg a1, a1
1039 *(Bit16u*)(pos+2)=B_FWD(10); // b after_call (pc+10)
1040 break;
1041 default:
1042 *(Bit32u*)( ( ((Bit32u) (*pos)) << 2 ) + ((Bit32u)pos + 4) ) = (Bit32u)fct_ptr; // simple_func
1043 break;
1044 }
1045 }
1046 else
1047 {
1048 // try to avoid function calls but rather directly fill in code
1049 switch (flags_type) {
1050 case t_ADDb:
1051 case t_ADDw:
1052 case t_ADDd:
1053 *(Bit16u*)pos=ADD_REG(HOST_a1, HOST_a1, HOST_a2); // add a1, a1, a2
1054 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1055 break;
1056 case t_ORb:
1057 case t_ORw:
1058 case t_ORd:
1059 *(Bit16u*)pos=ORR(HOST_a1, HOST_a2); // orr a1, a2
1060 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1061 break;
1062 case t_ANDb:
1063 case t_ANDw:
1064 case t_ANDd:
1065 *(Bit16u*)pos=AND(HOST_a1, HOST_a2); // and a1, a2
1066 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1067 break;
1068 case t_SUBb:
1069 case t_SUBw:
1070 case t_SUBd:
1071 *(Bit16u*)pos=SUB_REG(HOST_a1, HOST_a1, HOST_a2); // sub a1, a1, a2
1072 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1073 break;
1074 case t_XORb:
1075 case t_XORw:
1076 case t_XORd:
1077 *(Bit16u*)pos=EOR(HOST_a1, HOST_a2); // eor a1, a2
1078 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1079 break;
1080 case t_CMPb:
1081 case t_CMPw:
1082 case t_CMPd:
1083 case t_TESTb:
1084 case t_TESTw:
1085 case t_TESTd:
1086 *(Bit16u*)pos=B_FWD(14); // b after_call (pc+14)
1087 break;
1088 case t_INCb:
1089 case t_INCw:
1090 case t_INCd:
1091 *(Bit16u*)pos=ADD_IMM3(HOST_a1, HOST_a1, 1); // add a1, a1, #1
1092 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1093 break;
1094 case t_DECb:
1095 case t_DECw:
1096 case t_DECd:
1097 *(Bit16u*)pos=SUB_IMM3(HOST_a1, HOST_a1, 1); // sub a1, a1, #1
1098 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1099 break;
1100 case t_SHLb:
1101 case t_SHLw:
1102 case t_SHLd:
1103 *(Bit16u*)pos=LSL_REG(HOST_a1, HOST_a2); // lsl a1, a2
1104 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1105 break;
1106 case t_SHRb:
1107 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 24); // lsl a1, a1, #24
1108 *(Bit16u*)(pos+2)=LSR_IMM(HOST_a1, HOST_a1, 24); // lsr a1, a1, #24
1109 *(Bit16u*)(pos+4)=LSR_REG(HOST_a1, HOST_a2); // lsr a1, a2
1110 *(Bit16u*)(pos+6)=B_FWD(8); // b after_call (pc+8)
1111 break;
1112 case t_SHRw:
1113 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 16); // lsl a1, a1, #16
1114 *(Bit16u*)(pos+2)=LSR_IMM(HOST_a1, HOST_a1, 16); // lsr a1, a1, #16
1115 *(Bit16u*)(pos+4)=LSR_REG(HOST_a1, HOST_a2); // lsr a1, a2
1116 *(Bit16u*)(pos+6)=B_FWD(8); // b after_call (pc+8)
1117 break;
1118 case t_SHRd:
1119 *(Bit16u*)pos=LSR_REG(HOST_a1, HOST_a2); // lsr a1, a2
1120 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1121 break;
1122 case t_SARb:
1123 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 24); // lsl a1, a1, #24
1124 *(Bit16u*)(pos+2)=ASR_IMM(HOST_a1, HOST_a1, 24); // asr a1, a1, #24
1125 *(Bit16u*)(pos+4)=ASR_REG(HOST_a1, HOST_a2); // asr a1, a2
1126 *(Bit16u*)(pos+6)=B_FWD(8); // b after_call (pc+8)
1127 break;
1128 case t_SARw:
1129 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 16); // lsl a1, a1, #16
1130 *(Bit16u*)(pos+2)=ASR_IMM(HOST_a1, HOST_a1, 16); // asr a1, a1, #16
1131 *(Bit16u*)(pos+4)=ASR_REG(HOST_a1, HOST_a2); // asr a1, a2
1132 *(Bit16u*)(pos+6)=B_FWD(8); // b after_call (pc+8)
1133 break;
1134 case t_SARd:
1135 *(Bit16u*)pos=ASR_REG(HOST_a1, HOST_a2); // asr a1, a2
1136 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1137 break;
1138 case t_RORb:
1139 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 24); // lsl a1, a1, #24
1140 *(Bit16u*)(pos+2)=LSR_IMM(templo1, HOST_a1, 8); // lsr templo1, a1, #8
1141 *(Bit16u*)(pos+4)=ORR(HOST_a1, templo1); // orr a1, templo1
1142 *(Bit16u*)(pos+6)=NOP; // nop
1143 *(Bit16u*)(pos+8)=LSR_IMM(templo1, HOST_a1, 16); // lsr templo1, a1, #16
1144 *(Bit16u*)(pos+10)=NOP; // nop
1145 *(Bit16u*)(pos+12)=ORR(HOST_a1, templo1); // orr a1, templo1
1146 *(Bit16u*)(pos+14)=NOP; // nop
1147 *(Bit16u*)(pos+16)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1148 break;
1149 case t_RORw:
1150 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 16); // lsl a1, a1, #16
1151 *(Bit16u*)(pos+2)=LSR_IMM(templo1, HOST_a1, 16); // lsr templo1, a1, #16
1152 *(Bit16u*)(pos+4)=ORR(HOST_a1, templo1); // orr a1, templo1
1153 *(Bit16u*)(pos+6)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1154 *(Bit16u*)(pos+8)=B_FWD(6); // b after_call (pc+6)
1155 break;
1156 case t_RORd:
1157 *(Bit16u*)pos=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1158 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1159 break;
1160 case t_ROLb:
1161 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 24); // lsl a1, a1, #24
1162 *(Bit16u*)(pos+2)=NEG(HOST_a2, HOST_a2); // neg a2, a2
1163 *(Bit16u*)(pos+4)=LSR_IMM(templo1, HOST_a1, 8); // lsr templo1, a1, #8
1164 *(Bit16u*)(pos+6)=ADD_IMM8(HOST_a2, 32); // add a2, #32
1165 *(Bit16u*)(pos+8)=ORR(HOST_a1, templo1); // orr a1, templo1
1166 *(Bit16u*)(pos+10)=LSR_IMM(templo1, HOST_a1, 16); // lsr templo1, a1, #16
1167 *(Bit16u*)(pos+12)=ORR(HOST_a1, templo1); // orr a1, templo1
1168 *(Bit16u*)(pos+14)=NOP; // nop
1169 *(Bit16u*)(pos+16)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1170 break;
1171 case t_ROLw:
1172 *(Bit16u*)pos=LSL_IMM(HOST_a1, HOST_a1, 16); // lsl a1, a1, #16
1173 *(Bit16u*)(pos+2)=NEG(HOST_a2, HOST_a2); // neg a2, a2
1174 *(Bit16u*)(pos+4)=LSR_IMM(templo1, HOST_a1, 16); // lsr templo1, a1, #16
1175 *(Bit16u*)(pos+6)=ADD_IMM8(HOST_a2, 32); // add a2, #32
1176 *(Bit16u*)(pos+8)=ORR(HOST_a1, templo1); // orr a1, templo1
1177 *(Bit16u*)(pos+10)=NOP; // nop
1178 *(Bit16u*)(pos+12)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1179 *(Bit16u*)(pos+14)=NOP; // nop
1180 *(Bit16u*)(pos+16)=NOP; // nop
1181 break;
1182 case t_ROLd:
1183 *(Bit16u*)pos=NEG(HOST_a2, HOST_a2); // neg a2, a2
1184 *(Bit16u*)(pos+2)=ADD_IMM8(HOST_a2, 32); // add a2, #32
1185 *(Bit16u*)(pos+4)=ROR_REG(HOST_a1, HOST_a2); // ror a1, a2
1186 *(Bit16u*)(pos+6)=B_FWD(8); // b after_call (pc+8)
1187 break;
1188 case t_NEGb:
1189 case t_NEGw:
1190 case t_NEGd:
1191 *(Bit16u*)pos=NEG(HOST_a1, HOST_a1); // neg a1, a1
1192 *(Bit16u*)(pos+2)=B_FWD(12); // b after_call (pc+12)
1193 break;
1194 default:
1195 *(Bit32u*)( ( ((Bit32u) (*pos)) << 2 ) + ((Bit32u)pos + 2) ) = (Bit32u)fct_ptr; // simple_func
1196 break;
1197 }
1198
1199 }
1200 #else
1201 if (((Bit32u)pos & 0x03) == 0)
1202 {
1203 *(Bit32u*)( ( ((Bit32u) (*pos)) << 2 ) + ((Bit32u)pos + 4) ) = (Bit32u)fct_ptr; // simple_func
1204 }
1205 else
1206 {
1207 *(Bit32u*)( ( ((Bit32u) (*pos)) << 2 ) + ((Bit32u)pos + 2) ) = (Bit32u)fct_ptr; // simple_func
1208 }
1209 #endif
1210 }
1211 #endif
1212
1213 #ifdef DRC_USE_SEGS_ADDR
1214
1215 // mov 16bit value from Segs[index] into dest_reg using FC_SEGS_ADDR (index modulo 2 must be zero)
1216 // 16bit moves may destroy the upper 16bit of the destination register
1217 static void gen_mov_seg16_to_reg(HostReg dest_reg,Bitu index) {
1218 cache_checkinstr(4);
1219 cache_addw( MOV_LO_HI(templo1, FC_SEGS_ADDR) ); // mov templo1, FC_SEGS_ADDR
1220 cache_addw( LDRH_IMM(dest_reg, templo1, index) ); // ldrh dest_reg, [templo1, #index]
1221 }
1222
1223 // mov 32bit value from Segs[index] into dest_reg using FC_SEGS_ADDR (index modulo 4 must be zero)
1224 static void gen_mov_seg32_to_reg(HostReg dest_reg,Bitu index) {
1225 cache_checkinstr(4);
1226 cache_addw( MOV_LO_HI(templo1, FC_SEGS_ADDR) ); // mov templo1, FC_SEGS_ADDR
1227 cache_addw( LDR_IMM(dest_reg, templo1, index) ); // ldr dest_reg, [templo1, #index]
1228 }
1229
1230 // add a 32bit value from Segs[index] to a full register using FC_SEGS_ADDR (index modulo 4 must be zero)
1231 static void gen_add_seg32_to_reg(HostReg reg,Bitu index) {
1232 cache_checkinstr(6);
1233 cache_addw( MOV_LO_HI(templo1, FC_SEGS_ADDR) ); // mov templo1, FC_SEGS_ADDR
1234 cache_addw( LDR_IMM(templo2, templo1, index) ); // ldr templo2, [templo1, #index]
1235 cache_addw( ADD_REG(reg, reg, templo2) ); // add reg, reg, templo2
1236 }
1237
1238 #endif
1239
1240 #ifdef DRC_USE_REGS_ADDR
1241
1242 // mov 16bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR (index modulo 2 must be zero)
1243 // 16bit moves may destroy the upper 16bit of the destination register
1244 static void gen_mov_regval16_to_reg(HostReg dest_reg,Bitu index) {
1245 cache_checkinstr(4);
1246 cache_addw( MOV_LO_HI(templo2, FC_REGS_ADDR) ); // mov templo2, FC_REGS_ADDR
1247 cache_addw( LDRH_IMM(dest_reg, templo2, index) ); // ldrh dest_reg, [templo2, #index]
1248 }
1249
1250 // mov 32bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR (index modulo 4 must be zero)
1251 static void gen_mov_regval32_to_reg(HostReg dest_reg,Bitu index) {
1252 cache_checkinstr(4);
1253 cache_addw( MOV_LO_HI(templo2, FC_REGS_ADDR) ); // mov templo2, FC_REGS_ADDR
1254 cache_addw( LDR_IMM(dest_reg, templo2, index) ); // ldr dest_reg, [templo2, #index]
1255 }
1256
1257 // 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)
1258 // 16bit moves may destroy the upper 16bit of the destination register
1259 static void gen_mov_regword_to_reg(HostReg dest_reg,Bitu index,bool dword) {
1260 cache_checkinstr(4);
1261 cache_addw( MOV_LO_HI(templo2, FC_REGS_ADDR) ); // mov templo2, FC_REGS_ADDR
1262 if (dword) {
1263 cache_addw( LDR_IMM(dest_reg, templo2, index) ); // ldr dest_reg, [templo2, #index]
1264 } else {
1265 cache_addw( LDRH_IMM(dest_reg, templo2, index) ); // ldrh dest_reg, [templo2, #index]
1266 }
1267 }
1268
1269 // move an 8bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR
1270 // the upper 24bit of the destination register can be destroyed
1271 // this function does not use FC_OP1/FC_OP2 as dest_reg as these
1272 // registers might not be directly byte-accessible on some architectures
1273 static void gen_mov_regbyte_to_reg_low(HostReg dest_reg,Bitu index) {
1274 cache_checkinstr(4);
1275 cache_addw( MOV_LO_HI(templo2, FC_REGS_ADDR) ); // mov templo2, FC_REGS_ADDR
1276 cache_addw( LDRB_IMM(dest_reg, templo2, index) ); // ldrb dest_reg, [templo2, #index]
1277 }
1278
1279 // move an 8bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR
1280 // the upper 24bit of the destination register can be destroyed
1281 // this function can use FC_OP1/FC_OP2 as dest_reg which are
1282 // not directly byte-accessible on some architectures
1283 static void INLINE gen_mov_regbyte_to_reg_low_canuseword(HostReg dest_reg,Bitu index) {
1284 cache_checkinstr(4);
1285 cache_addw( MOV_LO_HI(templo2, FC_REGS_ADDR) ); // mov templo2, FC_REGS_ADDR
1286 cache_addw( LDRB_IMM(dest_reg, templo2, index) ); // ldrb dest_reg, [templo2, #index]
1287 }
1288
1289
1290 // add a 32bit value from cpu_regs[index] to a full register using FC_REGS_ADDR (index modulo 4 must be zero)
1291 static void gen_add_regval32_to_reg(HostReg reg,Bitu index) {
1292 cache_checkinstr(6);
1293 cache_addw( MOV_LO_HI(templo2, FC_REGS_ADDR) ); // mov templo2, FC_REGS_ADDR
1294 cache_addw( LDR_IMM(templo1, templo2, index) ); // ldr templo1, [templo2, #index]
1295 cache_addw( ADD_REG(reg, reg, templo1) ); // add reg, reg, templo1
1296 }
1297
1298
1299 // move 16bit of register into cpu_regs[index] using FC_REGS_ADDR (index modulo 2 must be zero)
1300 static void gen_mov_regval16_from_reg(HostReg src_reg,Bitu index) {
1301 cache_checkinstr(4);
1302 cache_addw( MOV_LO_HI(templo1, FC_REGS_ADDR) ); // mov templo1, FC_REGS_ADDR
1303 cache_addw( STRH_IMM(src_reg, templo1, index) ); // strh src_reg, [templo1, #index]
1304 }
1305
1306 // move 32bit of register into cpu_regs[index] using FC_REGS_ADDR (index modulo 4 must be zero)
1307 static void gen_mov_regval32_from_reg(HostReg src_reg,Bitu index) {
1308 cache_checkinstr(4);
1309 cache_addw( MOV_LO_HI(templo1, FC_REGS_ADDR) ); // mov templo1, FC_REGS_ADDR
1310 cache_addw( STR_IMM(src_reg, templo1, index) ); // str src_reg, [templo1, #index]
1311 }
1312
1313 // 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)
1314 static void gen_mov_regword_from_reg(HostReg src_reg,Bitu index,bool dword) {
1315 cache_checkinstr(4);
1316 cache_addw( MOV_LO_HI(templo1, FC_REGS_ADDR) ); // mov templo1, FC_REGS_ADDR
1317 if (dword) {
1318 cache_addw( STR_IMM(src_reg, templo1, index) ); // str src_reg, [templo1, #index]
1319 } else {
1320 cache_addw( STRH_IMM(src_reg, templo1, index) ); // strh src_reg, [templo1, #index]
1321 }
1322 }
1323
1324 // move the lowest 8bit of a register into cpu_regs[index] using FC_REGS_ADDR
1325 static void gen_mov_regbyte_from_reg_low(HostReg src_reg,Bitu index) {
1326 cache_checkinstr(4);
1327 cache_addw( MOV_LO_HI(templo1, FC_REGS_ADDR) ); // mov templo1, FC_REGS_ADDR
1328 cache_addw( STRB_IMM(src_reg, templo1, index) ); // strb src_reg, [templo1, #index]
1329 }
1330
1331 #endif