Debian Codegraph @

src/cpu/core_dynrec/risc_mipsel32.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_mipsel32.h,v 1.6 2009-06-25 19:31:43 c2woody Exp $ */
20
21
22 /* MIPS32 (little endian) backend by crazyc */
23
24
25 // some configuring defines that specify the capabilities of this architecture
26 // or aspects of the recompiling
27
28 // protect FC_ADDR over function calls if necessaray
29 // #define DRC_PROTECT_ADDR_REG
30
31 // try to use non-flags generating functions if possible
32 #define DRC_FLAGS_INVALIDATION
33 // try to replace _simple functions by code
34 #define DRC_FLAGS_INVALIDATION_DCODE
35
36 // type with the same size as a pointer
37 #define DRC_PTR_SIZE_IM Bit32u
38
39 // calling convention modifier
40 #define DRC_CALL_CONV /* nothing */
41 #define DRC_FC /* nothing */
42
43 // use FC_REGS_ADDR to hold the address of "cpu_regs" and to access it using FC_REGS_ADDR
44 //#define DRC_USE_REGS_ADDR
45 // use FC_SEGS_ADDR to hold the address of "Segs" and to access it using FC_SEGS_ADDR
46 //#define DRC_USE_SEGS_ADDR
47
48 // register mapping
49 typedef Bit8u HostReg;
50
51 #define HOST_v0 2
52 #define HOST_v1 3
53 #define HOST_a0 4
54 #define HOST_a1 5
55 #define HOST_t4 12
56 #define HOST_t5 13
57 #define HOST_t6 14
58 #define HOST_t7 15
59 #define HOST_s0 16
60 #define HOST_t8 24
61 #define HOST_t9 25
62 #define temp1 HOST_v1
63 #define temp2 HOST_t9
64
65 // register that holds function return values
66 #define FC_RETOP HOST_v0
67
68 // register used for address calculations,
69 #define FC_ADDR HOST_s0 // has to be saved across calls, see DRC_PROTECT_ADDR_REG
70
71 // register that holds the first parameter
72 #define FC_OP1 HOST_a0
73
74 // register that holds the second parameter
75 #define FC_OP2 HOST_a1
76
77 // special register that holds the third parameter for _R3 calls (byte accessible)
78 #define FC_OP3 HOST_???
79
80 // register that holds byte-accessible temporary values
81 #define FC_TMP_BA1 HOST_t5
82
83 // register that holds byte-accessible temporary values
84 #define FC_TMP_BA2 HOST_t6
85
86 // temporary register for LEA
87 #define TEMP_REG_DRC HOST_t7
88
89 #ifdef DRC_USE_REGS_ADDR
90 // used to hold the address of "cpu_regs" - preferably filled in function gen_run_code
91 #define FC_REGS_ADDR HOST_???
92 #endif
93
94 #ifdef DRC_USE_SEGS_ADDR
95 // used to hold the address of "Segs" - preferably filled in function gen_run_code
96 #define FC_SEGS_ADDR HOST_???
97 #endif
98
99 // save some state to improve code gen
100 static bool temp1_valid = false;
101 static Bit32u temp1_value;
102
103 // move a full register from reg_src to reg_dst
104 static void gen_mov_regs(HostReg reg_dst,HostReg reg_src) {
105 if(reg_src == reg_dst) return;
106 cache_addw((reg_dst<<11)+0x21); // addu reg_dst, $0, reg_src
107 cache_addw(reg_src);
108 }
109
110 // move a 32bit constant value into dest_reg
111 static void gen_mov_dword_to_reg_imm(HostReg dest_reg,Bit32u imm) {
112 if(imm < 65536) {
113 cache_addw((Bit16u)imm); // ori dest_reg, $0, imm
114 cache_addw(0x3400+dest_reg);
115 } else if(((Bit32s)imm < 0) && ((Bit32s)imm >= -32768)) {
116 cache_addw((Bit16u)imm); // addiu dest_reg, $0, imm
117 cache_addw(0x2400+dest_reg);
118 } else if(!(imm & 0xffff)) {
119 cache_addw((Bit16u)(imm >> 16)); // lui dest_reg, %hi(imm)
120 cache_addw(0x3c00+dest_reg);
121 } else {
122 cache_addw((Bit16u)(imm >> 16)); // lui dest_reg, %hi(imm)
123 cache_addw(0x3c00+dest_reg);
124 cache_addw((Bit16u)imm); // ori dest_reg, dest_reg, %lo(imm)
125 cache_addw(0x3400+(dest_reg<<5)+dest_reg);
126 }
127 }
128
129 // this is the only place temp1 should be modified
130 static void INLINE mov_imm_to_temp1(Bit32u imm) {
131 if (temp1_valid && (temp1_value == imm)) return;
132 gen_mov_dword_to_reg_imm(temp1, imm);
133 temp1_valid = true;
134 temp1_value = imm;
135 }
136
137 static Bit16s gen_addr_temp1(Bit32u addr) {
138 Bit32u hihalf = addr & 0xffff0000;
139 Bit16s lohalf = addr & 0xffff;
140 if (lohalf > 32764) { // [l,s]wl will overflow
141 hihalf = addr;
142 lohalf = 0;
143 } else if(lohalf < 0) hihalf += 0x10000;
144 mov_imm_to_temp1(hihalf);
145 return lohalf;
146 }
147
148 // move a 32bit (dword==true) or 16bit (dword==false) value from memory into dest_reg
149 // 16bit moves may destroy the upper 16bit of the destination register
150 static void gen_mov_word_to_reg(HostReg dest_reg,void* data,bool dword) {
151 Bit16s lohalf = gen_addr_temp1((Bit32u)data);
152 // alignment....
153 if (dword) {
154 if ((Bit32u)data & 3) {
155 cache_addw(lohalf+3); // lwl dest_reg, 3(temp1)
156 cache_addw(0x8800+(temp1<<5)+dest_reg);
157 cache_addw(lohalf); // lwr dest_reg, 0(temp1)
158 cache_addw(0x9800+(temp1<<5)+dest_reg);
159 } else {
160 cache_addw(lohalf); // lw dest_reg, 0(temp1)
161 cache_addw(0x8C00+(temp1<<5)+dest_reg);
162 }
163 } else {
164 if ((Bit32u)data & 1) {
165 cache_addw(lohalf); // lbu dest_reg, 0(temp1)
166 cache_addw(0x9000+(temp1<<5)+dest_reg);
167 cache_addw(lohalf+1); // lbu temp2, 1(temp1)
168 cache_addw(0x9000+(temp1<<5)+temp2);
169 #if (_MIPS_ISA==MIPS32R2) || defined(PSP)
170 cache_addw(0x7a04); // ins dest_reg, temp2, 8, 8
171 cache_addw(0x7c00+(temp2<<5)+dest_reg);
172 #else
173 cache_addw((temp2<<11)+0x200); // sll temp2, temp2, 8
174 cache_addw(temp2);
175 cache_addw((dest_reg<<11)+0x25); // or dest_reg, temp2, dest_reg
176 cache_addw((temp2<<5)+dest_reg);
177 #endif
178 } else {
179 cache_addw(lohalf); // lhu dest_reg, 0(temp1);
180 cache_addw(0x9400+(temp1<<5)+dest_reg);
181 }
182 }
183 }
184
185 // move a 16bit constant value into dest_reg
186 // the upper 16bit of the destination register may be destroyed
187 static void gen_mov_word_to_reg_imm(HostReg dest_reg,Bit16u imm) {
188 cache_addw(imm); // ori dest_reg, $0, imm
189 cache_addw(0x3400+dest_reg);
190 }
191
192 // move 32bit (dword==true) or 16bit (dword==false) of a register into memory
193 static void gen_mov_word_from_reg(HostReg src_reg,void* dest,bool dword) {
194 Bit16s lohalf = gen_addr_temp1((Bit32u)dest);
195 // alignment....
196 if (dword) {
197 if ((Bit32u)dest & 3) {
198 cache_addw(lohalf+3); // swl src_reg, 3(temp1)
199 cache_addw(0xA800+(temp1<<5)+src_reg);
200 cache_addw(lohalf); // swr src_reg, 0(temp1)
201 cache_addw(0xB800+(temp1<<5)+src_reg);
202 } else {
203 cache_addw(lohalf); // sw src_reg, 0(temp1)
204 cache_addw(0xAC00+(temp1<<5)+src_reg);
205 }
206 } else {
207 if((Bit32u)dest & 1) {
208 cache_addw(lohalf); // sb src_reg, 0(temp1)
209 cache_addw(0xA000+(temp1<<5)+src_reg);
210 cache_addw((temp2<<11)+0x202); // srl temp2, src_reg, 8
211 cache_addw(src_reg);
212 cache_addw(lohalf+1); // sb temp2, 1(temp1)
213 cache_addw(0xA000+(temp1<<5)+temp2);
214 } else {
215 cache_addw(lohalf); // sh src_reg, 0(temp1);
216 cache_addw(0xA400+(temp1<<5)+src_reg);
217 }
218 }
219 }
220
221 // move an 8bit value from memory into dest_reg
222 // the upper 24bit of the destination register can be destroyed
223 // this function does not use FC_OP1/FC_OP2 as dest_reg as these
224 // registers might not be directly byte-accessible on some architectures
225 static void gen_mov_byte_to_reg_low(HostReg dest_reg,void* data) {
226 Bit16s lohalf = gen_addr_temp1((Bit32u)data);
227 cache_addw(lohalf); // lbu dest_reg, 0(temp1)
228 cache_addw(0x9000+(temp1<<5)+dest_reg);
229 }
230
231 // move an 8bit value from memory into dest_reg
232 // the upper 24bit of the destination register can be destroyed
233 // this function can use FC_OP1/FC_OP2 as dest_reg which are
234 // not directly byte-accessible on some architectures
235 static void INLINE gen_mov_byte_to_reg_low_canuseword(HostReg dest_reg,void* data) {
236 gen_mov_byte_to_reg_low(dest_reg, data);
237 }
238
239 // move an 8bit constant value into dest_reg
240 // the upper 24bit of the destination register can be destroyed
241 // this function does not use FC_OP1/FC_OP2 as dest_reg as these
242 // registers might not be directly byte-accessible on some architectures
243 static void INLINE gen_mov_byte_to_reg_low_imm(HostReg dest_reg,Bit8u imm) {
244 gen_mov_word_to_reg_imm(dest_reg, imm);
245 }
246
247 // move an 8bit constant value into dest_reg
248 // the upper 24bit of the destination register can be destroyed
249 // this function can use FC_OP1/FC_OP2 as dest_reg which are
250 // not directly byte-accessible on some architectures
251 static void INLINE gen_mov_byte_to_reg_low_imm_canuseword(HostReg dest_reg,Bit8u imm) {
252 gen_mov_byte_to_reg_low_imm(dest_reg, imm);
253 }
254
255 // move the lowest 8bit of a register into memory
256 static void gen_mov_byte_from_reg_low(HostReg src_reg,void* dest) {
257 Bit16s lohalf = gen_addr_temp1((Bit32u)dest);
258 cache_addw(lohalf); // sb src_reg, 0(temp1)
259 cache_addw(0xA000+(temp1<<5)+src_reg);
260 }
261
262
263
264 // convert an 8bit word to a 32bit dword
265 // the register is zero-extended (sign==false) or sign-extended (sign==true)
266 static void gen_extend_byte(bool sign,HostReg reg) {
267 if (sign) {
268 #if (_MIPS_ISA==MIPS32R2) || defined(PSP)
269 cache_addw((reg<<11)+0x420); // seb reg, reg
270 cache_addw(0x7c00+reg);
271 #else
272 arch that lacks seb
273 #endif
274 } else {
275 cache_addw(0xff); // andi reg, reg, 0xff
276 cache_addw(0x3000+(reg<<5)+reg);
277 }
278 }
279
280 // convert a 16bit word to a 32bit dword
281 // the register is zero-extended (sign==false) or sign-extended (sign==true)
282 static void gen_extend_word(bool sign,HostReg reg) {
283 if (sign) {
284 #if (_MIPS_ISA==MIPS32R2) || defined(PSP)
285 cache_addw((reg<<11)+0x620); // seh reg, reg
286 cache_addw(0x7c00+reg);
287 #else
288 arch that lacks seh
289 #endif
290 } else {
291 cache_addw(0xffff); // andi reg, reg, 0xffff
292 cache_addw(0x3000+(reg<<5)+reg);
293 }
294 }
295
296 // add a 32bit value from memory to a full register
297 static void gen_add(HostReg reg,void* op) {
298 gen_mov_word_to_reg(temp2, op, 1);
299 cache_addw((reg<<11)+0x21); // addu reg, reg, temp2
300 cache_addw((reg<<5)+temp2);
301 }
302
303 // add a 32bit constant value to a full register
304 static void gen_add_imm(HostReg reg,Bit32u imm) {
305 if(!imm) return;
306 if(((Bit32s)imm >= -32768) && ((Bit32s)imm < 32768)) {
307 cache_addw((Bit16u)imm); // addiu reg, reg, imm
308 cache_addw(0x2400+(reg<<5)+reg);
309 } else {
310 mov_imm_to_temp1(imm);
311 cache_addw((reg<<11)+0x21); // addu reg, reg, temp1
312 cache_addw((reg<<5)+temp1);
313 }
314 }
315
316 // and a 32bit constant value with a full register
317 static void gen_and_imm(HostReg reg,Bit32u imm) {
318 if(imm < 65536) {
319 cache_addw((Bit16u)imm); // andi reg, reg, imm
320 cache_addw(0x3000+(reg<<5)+reg);
321 } else {
322 mov_imm_to_temp1((Bit32u)imm);
323 cache_addw((reg<<11)+0x24); // and reg, temp1, reg
324 cache_addw((temp1<<5)+reg);
325 }
326 }
327
328
329 // move a 32bit constant value into memory
330 static void INLINE gen_mov_direct_dword(void* dest,Bit32u imm) {
331 gen_mov_dword_to_reg_imm(temp2, imm);
332 gen_mov_word_from_reg(temp2, dest, 1);
333 }
334
335 // move an address into memory
336 static void INLINE gen_mov_direct_ptr(void* dest,DRC_PTR_SIZE_IM imm) {
337 gen_mov_direct_dword(dest,(Bit32u)imm);
338 }
339
340 // add a 32bit (dword==true) or 16bit (dword==false) constant value to a memory value
341 static void INLINE gen_add_direct_word(void* dest,Bit32u imm,bool dword) {
342 if(!imm) return;
343 gen_mov_word_to_reg(temp2, dest, dword);
344 gen_add_imm(temp2, imm);
345 gen_mov_word_from_reg(temp2, dest, dword);
346 }
347
348 // add an 8bit constant value to a dword memory value
349 static void INLINE gen_add_direct_byte(void* dest,Bit8s imm) {
350 gen_add_direct_word(dest, (Bit32s)imm, 1);
351 }
352
353 // subtract an 8bit constant value from a dword memory value
354 static void INLINE gen_sub_direct_byte(void* dest,Bit8s imm) {
355 gen_add_direct_word(dest, -((Bit32s)imm), 1);
356 }
357
358 // subtract a 32bit (dword==true) or 16bit (dword==false) constant value from a memory value
359 static void INLINE gen_sub_direct_word(void* dest,Bit32u imm,bool dword) {
360 gen_add_direct_word(dest, -(Bit32s)imm, dword);
361 }
362
363 // effective address calculation, destination is dest_reg
364 // scale_reg is scaled by scale (scale_reg*(2^scale)) and
365 // added to dest_reg, then the immediate value is added
366 static INLINE void gen_lea(HostReg dest_reg,HostReg scale_reg,Bitu scale,Bits imm) {
367 if (scale) {
368 cache_addw((scale_reg<<11)+(scale<<6)); // sll scale_reg, scale_reg, scale
369 cache_addw(scale_reg);
370 }
371 cache_addw((dest_reg<<11)+0x21); // addu dest_reg, dest_reg, scale_reg
372 cache_addw((dest_reg<<5)+scale_reg);
373 gen_add_imm(dest_reg, imm);
374 }
375
376 // effective address calculation, destination is dest_reg
377 // dest_reg is scaled by scale (dest_reg*(2^scale)),
378 // then the immediate value is added
379 static INLINE void gen_lea(HostReg dest_reg,Bitu scale,Bits imm) {
380 if (scale) {
381 cache_addw((dest_reg<<11)+(scale<<6)); // sll dest_reg, dest_reg, scale
382 cache_addw(dest_reg);
383 }
384 gen_add_imm(dest_reg, imm);
385 }
386
387 #define DELAY cache_addd(0) // nop
388
389 // generate a call to a parameterless function
390 static void INLINE gen_call_function_raw(void * func) {
391 #if C_DEBUG
392 if ((cache.pos ^ func) & 0xf0000000) LOG_MSG("jump overflow\n");
393 #endif
394 temp1_valid = false;
395 cache_addd(0x0c000000+(((Bit32u)func>>2)&0x3ffffff)); // jal func
396 DELAY;
397 }
398
399 // generate a call to a function with paramcount parameters
400 // note: the parameters are loaded in the architecture specific way
401 // using the gen_load_param_ functions below
402 static Bit32u INLINE gen_call_function_setup(void * func,Bitu paramcount,bool fastcall=false) {
403 Bit32u proc_addr = (Bit32u)cache.pos;
404 gen_call_function_raw(func);
405 return proc_addr;
406 }
407
408 #ifdef __mips_eabi
409 // max of 8 parameters in $a0-$a3 and $t0-$t3
410
411 // load an immediate value as param'th function parameter
412 static void INLINE gen_load_param_imm(Bitu imm,Bitu param) {
413 gen_mov_dword_to_reg_imm(param+4, imm);
414 }
415
416 // load an address as param'th function parameter
417 static void INLINE gen_load_param_addr(Bitu addr,Bitu param) {
418 gen_mov_dword_to_reg_imm(param+4, addr);
419 }
420
421 // load a host-register as param'th function parameter
422 static void INLINE gen_load_param_reg(Bitu reg,Bitu param) {
423 gen_mov_regs(param+4, reg);
424 }
425
426 // load a value from memory as param'th function parameter
427 static void INLINE gen_load_param_mem(Bitu mem,Bitu param) {
428 gen_mov_word_to_reg(param+4, (void *)mem, 1);
429 }
430 #else
431 other mips abis
432 #endif
433
434 // jump to an address pointed at by ptr, offset is in imm
435 static void INLINE gen_jmp_ptr(void * ptr,Bits imm=0) {
436 gen_mov_word_to_reg(temp2, ptr, 1);
437 if((imm < -32768) || (imm >= 32768)) {
438 gen_add_imm(temp2, imm);
439 imm = 0;
440 }
441 temp1_valid = false;
442 cache_addw((Bit16u)imm); // lw temp2, imm(temp2)
443 cache_addw(0x8C00+(temp2<<5)+temp2);
444 cache_addd((temp2<<21)+8); // jr temp2
445 DELAY;
446 }
447
448 // short conditional jump (+-127 bytes) if register is zero
449 // the destination is set by gen_fill_branch() later
450 static Bit32u INLINE gen_create_branch_on_zero(HostReg reg,bool dword) {
451 temp1_valid = false;
452 if(!dword) {
453 cache_addw(0xffff); // andi temp1, reg, 0xffff
454 cache_addw(0x3000+(reg<<5)+temp1);
455 }
456 cache_addw(0); // beq $0, reg, 0
457 cache_addw(0x1000+(dword?reg:temp1));
458 DELAY;
459 return ((Bit32u)cache.pos-8);
460 }
461
462 // short conditional jump (+-127 bytes) if register is nonzero
463 // the destination is set by gen_fill_branch() later
464 static Bit32u INLINE gen_create_branch_on_nonzero(HostReg reg,bool dword) {
465 temp1_valid = false;
466 if(!dword) {
467 cache_addw(0xffff); // andi temp1, reg, 0xffff
468 cache_addw(0x3000+(reg<<5)+temp1);
469 }
470 cache_addw(0); // bne $0, reg, 0
471 cache_addw(0x1400+(dword?reg:temp1));
472 DELAY;
473 return ((Bit32u)cache.pos-8);
474 }
475
476 // calculate relative offset and fill it into the location pointed to by data
477 static void INLINE gen_fill_branch(DRC_PTR_SIZE_IM data) {
478 #if C_DEBUG
479 Bits len=(Bit32u)cache.pos-data;
480 if (len<0) len=-len;
481 if (len>126) LOG_MSG("Big jump %d",len);
482 #endif
483 temp1_valid = false; // this is a branch target
484 *(Bit16u*)data=((Bit16u)((Bit32u)cache.pos-data-4)>>2);
485 }
486
487 #if 0 // assume for the moment no branch will go farther then +/- 128KB
488
489 // conditional jump if register is nonzero
490 // for isdword==true the 32bit of the register are tested
491 // for isdword==false the lowest 8bit of the register are tested
492 static Bit32u gen_create_branch_long_nonzero(HostReg reg,bool isdword) {
493 temp1_valid = false;
494 if (!isdword) {
495 cache_addw(0xff); // andi temp1, reg, 0xff
496 cache_addw(0x3000+(reg<<5)+temp1);
497 }
498 cache_addw(3); // beq $0, reg, +12
499 cache_addw(0x1000+(isdword?reg:temp1));
500 DELAY;
501 cache_addd(0x00000000); // fill j
502 DELAY;
503 return ((Bit32u)cache.pos-8);
504 }
505
506 // compare 32bit-register against zero and jump if value less/equal than zero
507 static Bit32u INLINE gen_create_branch_long_leqzero(HostReg reg) {
508 temp1_valid = false;
509 cache_addw(3); // bgtz reg, +12
510 cache_addw(0x1c00+(reg<<5));
511 DELAY;
512 cache_addd(0x00000000); // fill j
513 DELAY;
514 return ((Bit32u)cache.pos-8);
515 }
516
517 // calculate long relative offset and fill it into the location pointed to by data
518 static void INLINE gen_fill_branch_long(Bit32u data) {
519 temp1_valid = false;
520 // this is an absolute branch
521 *(Bit32u*)data=0x08000000+(((Bit32u)cache.pos>>2)&0x3ffffff);
522 }
523 #else
524 // conditional jump if register is nonzero
525 // for isdword==true the 32bit of the register are tested
526 // for isdword==false the lowest 8bit of the register are tested
527 static Bit32u gen_create_branch_long_nonzero(HostReg reg,bool isdword) {
528 temp1_valid = false;
529 if (!isdword) {
530 cache_addw(0xff); // andi temp1, reg, 0xff
531 cache_addw(0x3000+(reg<<5)+temp1);
532 }
533 cache_addw(0); // bne $0, reg, 0
534 cache_addw(0x1400+(isdword?reg:temp1));
535 DELAY;
536 return ((Bit32u)cache.pos-8);
537 }
538
539 // compare 32bit-register against zero and jump if value less/equal than zero
540 static Bit32u INLINE gen_create_branch_long_leqzero(HostReg reg) {
541 temp1_valid = false;
542 cache_addw(0); // blez reg, 0
543 cache_addw(0x1800+(reg<<5));
544 DELAY;
545 return ((Bit32u)cache.pos-8);
546 }
547
548 // calculate long relative offset and fill it into the location pointed to by data
549 static void INLINE gen_fill_branch_long(Bit32u data) {
550 gen_fill_branch(data);
551 }
552 #endif
553
554 static void gen_run_code(void) {
555 temp1_valid = false;
556 cache_addd(0x27bdfff0); // addiu $sp, $sp, -16
557 cache_addd(0xafb00004); // sw $s0, 4($sp)
558 cache_addd(0x00800008); // jr $a0
559 cache_addd(0xafbf0000); // sw $ra, 0($sp)
560 }
561
562 // return from a function
563 static void gen_return_function(void) {
564 temp1_valid = false;
565 cache_addd(0x8fbf0000); // lw $ra, 0($sp)
566 cache_addd(0x8fb00004); // lw $s0, 4($sp)
567 cache_addd(0x03e00008); // jr $ra
568 cache_addd(0x27bd0010); // addiu $sp, $sp, 16
569 }
570
571 #ifdef DRC_FLAGS_INVALIDATION
572 // called when a call to a function can be replaced by a
573 // call to a simpler function
574 static void gen_fill_function_ptr(Bit8u * pos,void* fct_ptr,Bitu flags_type) {
575 #ifdef DRC_FLAGS_INVALIDATION_DCODE
576 // try to avoid function calls but rather directly fill in code
577 switch (flags_type) {
578 case t_ADDb:
579 case t_ADDw:
580 case t_ADDd:
581 *(Bit32u*)pos=0x00851021; // addu $v0, $a0, $a1
582 break;
583 case t_ORb:
584 case t_ORw:
585 case t_ORd:
586 *(Bit32u*)pos=0x00851025; // or $v0, $a0, $a1
587 break;
588 case t_ANDb:
589 case t_ANDw:
590 case t_ANDd:
591 *(Bit32u*)pos=0x00851024; // and $v0, $a0, $a1
592 break;
593 case t_SUBb:
594 case t_SUBw:
595 case t_SUBd:
596 *(Bit32u*)pos=0x00851023; // subu $v0, $a0, $a1
597 break;
598 case t_XORb:
599 case t_XORw:
600 case t_XORd:
601 *(Bit32u*)pos=0x00851026; // xor $v0, $a0, $a1
602 break;
603 case t_CMPb:
604 case t_CMPw:
605 case t_CMPd:
606 case t_TESTb:
607 case t_TESTw:
608 case t_TESTd:
609 *(Bit32u*)pos=0; // nop
610 break;
611 case t_INCb:
612 case t_INCw:
613 case t_INCd:
614 *(Bit32u*)pos=0x24820001; // addiu $v0, $a0, 1
615 break;
616 case t_DECb:
617 case t_DECw:
618 case t_DECd:
619 *(Bit32u*)pos=0x2482ffff; // addiu $v0, $a0, -1
620 break;
621 case t_SHLb:
622 case t_SHLw:
623 case t_SHLd:
624 *(Bit32u*)pos=0x00a41004; // sllv $v0, $a0, $a1
625 break;
626 case t_SHRb:
627 case t_SHRw:
628 case t_SHRd:
629 *(Bit32u*)pos=0x00a41006; // srlv $v0, $a0, $a1
630 break;
631 case t_SARd:
632 *(Bit32u*)pos=0x00a41007; // srav $v0, $a0, $a1
633 break;
634 #if (_MIPS_ISA==MIPS32R2) || defined(PSP)
635 case t_RORd:
636 *(Bit32u*)pos=0x00a41046; // rotr $v0, $a0, $a1
637 break;
638 #endif
639 case t_NEGb:
640 case t_NEGw:
641 case t_NEGd:
642 *(Bit32u*)pos=0x00041023; // subu $v0, $0, $a0
643 break;
644 default:
645 *(Bit32u*)pos=0x0c000000+((((Bit32u)fct_ptr)>>2)&0x3ffffff); // jal simple_func
646 break;
647 }
648 #else
649 *(Bit32u*)pos=0x0c000000+(((Bit32u)fct_ptr)>>2)&0x3ffffff); // jal simple_func
650 #endif
651 }
652 #endif
653
654 static void cache_block_closing(Bit8u* block_start,Bitu block_size) {
655 #ifdef PSP
656 // writeback dcache and invalidate icache
657 Bit32u inval_start = ((Bit32u)block_start) & ~63;
658 Bit32u inval_end = (((Bit32u)block_start) + block_size + 64) & ~63;
659 for (;inval_start < inval_end; inval_start+=64) {
660 __builtin_allegrex_cache(0x1a, inval_start);
661 __builtin_allegrex_cache(0x08, inval_start);
662 }
663 #endif
664 }
665
666 static void cache_block_before_close(void) { }
667
668
669 #ifdef DRC_USE_SEGS_ADDR
670
671 // mov 16bit value from Segs[index] into dest_reg using FC_SEGS_ADDR (index modulo 2 must be zero)
672 // 16bit moves may destroy the upper 16bit of the destination register
673 static void gen_mov_seg16_to_reg(HostReg dest_reg,Bitu index) {
674 // stub
675 }
676
677 // mov 32bit value from Segs[index] into dest_reg using FC_SEGS_ADDR (index modulo 4 must be zero)
678 static void gen_mov_seg32_to_reg(HostReg dest_reg,Bitu index) {
679 // stub
680 }
681
682 // add a 32bit value from Segs[index] to a full register using FC_SEGS_ADDR (index modulo 4 must be zero)
683 static void gen_add_seg32_to_reg(HostReg reg,Bitu index) {
684 // stub
685 }
686
687 #endif
688
689 #ifdef DRC_USE_REGS_ADDR
690
691 // mov 16bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR (index modulo 2 must be zero)
692 // 16bit moves may destroy the upper 16bit of the destination register
693 static void gen_mov_regval16_to_reg(HostReg dest_reg,Bitu index) {
694 // stub
695 }
696
697 // mov 32bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR (index modulo 4 must be zero)
698 static void gen_mov_regval32_to_reg(HostReg dest_reg,Bitu index) {
699 // stub
700 }
701
702 // 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)
703 // 16bit moves may destroy the upper 16bit of the destination register
704 static void gen_mov_regword_to_reg(HostReg dest_reg,Bitu index,bool dword) {
705 // stub
706 }
707
708 // move an 8bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR
709 // the upper 24bit of the destination register can be destroyed
710 // this function does not use FC_OP1/FC_OP2 as dest_reg as these
711 // registers might not be directly byte-accessible on some architectures
712 static void gen_mov_regbyte_to_reg_low(HostReg dest_reg,Bitu index) {
713 // stub
714 }
715
716 // move an 8bit value from cpu_regs[index] into dest_reg using FC_REGS_ADDR
717 // the upper 24bit of the destination register can be destroyed
718 // this function can use FC_OP1/FC_OP2 as dest_reg which are
719 // not directly byte-accessible on some architectures
720 static void INLINE gen_mov_regbyte_to_reg_low_canuseword(HostReg dest_reg,Bitu index) {
721 // stub
722 }
723
724
725 // add a 32bit value from cpu_regs[index] to a full register using FC_REGS_ADDR (index modulo 4 must be zero)
726 static void gen_add_regval32_to_reg(HostReg reg,Bitu index) {
727 // stub
728 }
729
730
731 // move 16bit of register into cpu_regs[index] using FC_REGS_ADDR (index modulo 2 must be zero)
732 static void gen_mov_regval16_from_reg(HostReg src_reg,Bitu index) {
733 // stub
734 }
735
736 // move 32bit of register into cpu_regs[index] using FC_REGS_ADDR (index modulo 4 must be zero)
737 static void gen_mov_regval32_from_reg(HostReg src_reg,Bitu index) {
738 // stub
739 }
740
741 // 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)
742 static void gen_mov_regword_from_reg(HostReg src_reg,Bitu index,bool dword) {
743 // stub
744 }
745
746 // move the lowest 8bit of a register into cpu_regs[index] using FC_REGS_ADDR
747 static void gen_mov_regbyte_from_reg_low(HostReg src_reg,Bitu index) {
748 // stub
749 }
750
751 #endif