2 * MIPS emulation micro-operations for qemu.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "op_template.c"
28 #include "op_template.c"
31 #include "op_template.c"
34 #include "op_template.c"
37 #include "op_template.c"
40 #include "op_template.c"
43 #include "op_template.c"
46 #include "op_template.c"
49 #include "op_template.c"
52 #include "op_template.c"
55 #include "op_template.c"
58 #include "op_template.c"
61 #include "op_template.c"
64 #include "op_template.c"
67 #include "op_template.c"
70 #include "op_template.c"
73 #include "op_template.c"
76 #include "op_template.c"
79 #include "op_template.c"
82 #include "op_template.c"
85 #include "op_template.c"
88 #include "op_template.c"
91 #include "op_template.c"
94 #include "op_template.c"
97 #include "op_template.c"
100 #include "op_template.c"
103 #include "op_template.c"
106 #include "op_template.c"
109 #include "op_template.c"
112 #include "op_template.c"
115 #include "op_template.c"
119 #include "op_template.c"
122 #include "op_template.c"
125 #include "op_template.c"
128 void op_dup_T0 (void)
134 void op_load_HI (void)
140 void op_store_HI (void)
146 void op_load_LO (void)
152 void op_store_LO (void)
159 #define MEMSUFFIX _raw
162 #if !defined(CONFIG_USER_ONLY)
163 #define MEMSUFFIX _user
167 #define MEMSUFFIX _kernel
185 if ((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31)) {
186 CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
202 T0 = (int32_t)T0 - (int32_t)T1;
203 if (!((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31))) {
204 CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
211 T0 = (int32_t)T0 * (int32_t)T1;
218 env->LO = (int32_t)T0 / (int32_t)T1;
219 env->HI = (int32_t)T0 % (int32_t)T1;
266 T0 = (int32_t)T0 >> T1;
278 T0 = T1 << (T0 & 0x1F);
284 T0 = (int32_t)T1 >> (T0 & 0x1F);
290 T0 = T1 >> (T0 & 0x1F);
298 if (T0 == (target_ulong)-1) {
301 for (n = 0; n < 32; n++) {
302 if (!(T0 & (1 << 31)))
318 for (n = 0; n < 32; n++) {
328 /* 64 bits arithmetic */
329 #if (HOST_LONG_BITS == 64)
330 static inline uint64_t get_HILO (void)
332 return ((uint64_t)env->HI << 32) | (uint64_t)env->LO;
335 static inline void set_HILO (uint64_t HILO)
337 env->LO = HILO & 0xFFFFFFFF;
338 env->HI = HILO >> 32;
343 set_HILO((int64_t)T0 * (int64_t)T1);
349 set_HILO((uint64_t)T0 * (uint64_t)T1);
357 tmp = ((int64_t)T0 * (int64_t)T1);
358 set_HILO((int64_t)get_HILO() + tmp);
366 tmp = ((uint64_t)T0 * (uint64_t)T1);
367 set_HILO(get_HILO() + tmp);
375 tmp = ((int64_t)T0 * (int64_t)T1);
376 set_HILO((int64_t)get_HILO() - tmp);
384 tmp = ((uint64_t)T0 * (uint64_t)T1);
385 set_HILO(get_HILO() - tmp);
391 CALL_FROM_TB0(do_mult);
397 CALL_FROM_TB0(do_multu);
403 CALL_FROM_TB0(do_madd);
409 CALL_FROM_TB0(do_maddu);
415 CALL_FROM_TB0(do_msub);
421 CALL_FROM_TB0(do_msubu);
426 /* Conditional moves */
430 env->gpr[PARAM1] = T0;
437 env->gpr[PARAM1] = T0;
442 #define OP_COND(name, cond) \
443 void glue(op_, name) (void) \
453 OP_COND(eq, T0 == T1);
454 OP_COND(ne, T0 != T1);
455 OP_COND(ge, (int32_t)T0 >= (int32_t)T1);
456 OP_COND(geu, T0 >= T1);
457 OP_COND(lt, (int32_t)T0 < (int32_t)T1);
458 OP_COND(ltu, T0 < T1);
459 OP_COND(gez, (int32_t)T0 >= 0);
460 OP_COND(gtz, (int32_t)T0 > 0);
461 OP_COND(lez, (int32_t)T0 <= 0);
462 OP_COND(ltz, (int32_t)T0 < 0);
465 //#undef USE_DIRECT_JUMP
468 /* Branch to register */
469 void op_save_breg_target (void)
474 void op_restore_breg_target (void)
485 /* Unconditional branch */
486 void op_branch (void)
488 JUMP_TB(branch, PARAM1, 0, PARAM2);
492 void op_save_btarget (void)
494 env->btarget = PARAM1;
498 /* Conditional branch */
499 void op_set_bcond (void)
505 void op_save_bcond (void)
511 void op_restore_bcond (void)
520 JUMP_TB(bcond, PARAM1, 0, PARAM2);
522 JUMP_TB(bcond, PARAM1, 1, PARAM3);
527 /* Likely branch (used to skip the delay slot) */
528 void op_blikely (void)
530 /* If the test is false, skip the delay slot */
532 env->hflags = PARAM3;
533 JUMP_TB(blikely, PARAM1, 1, PARAM2);
541 CALL_FROM_TB2(do_mfc0, PARAM1, PARAM2);
547 CALL_FROM_TB2(do_mtc0, PARAM1, PARAM2);
551 #if defined(MIPS_USES_R4K_TLB)
554 CALL_FROM_TB0(do_tlbwi);
560 CALL_FROM_TB0(do_tlbwr);
566 CALL_FROM_TB0(do_tlbp);
572 CALL_FROM_TB0(do_tlbr);
580 CALL_FROM_TB1(do_pmon, PARAM1);
586 CALL_FROM_TB1(do_raise_exception, EXCP_TRAP);
591 void op_set_lladdr (void)
593 env->CP0_LLAddr = T2;
596 void debug_eret (void);
599 CALL_FROM_TB0(debug_eret);
600 if (env->hflags & MIPS_HFLAG_ERL) {
601 env->PC = env->CP0_ErrorEPC;
602 env->hflags &= ~MIPS_HFLAG_ERL;
604 env->PC = env->CP0_EPC;
605 env->hflags &= ~MIPS_HFLAG_EXL;
612 CALL_FROM_TB0(debug_eret);
613 env->PC = env->CP0_DEPC;
616 void op_save_state (void)
618 env->hflags = PARAM1;
622 void op_save_pc (void)
628 void op_raise_exception (void)
630 CALL_FROM_TB1(do_raise_exception, PARAM1);
634 void op_raise_exception_err (void)
636 CALL_FROM_TB2(do_raise_exception_err, PARAM1, PARAM2);
640 void op_exit_tb (void)