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 #define CALL_FROM_TB0(func) func();
28 #define CALL_FROM_TB1(func, arg0) func(arg0);
30 #ifndef CALL_FROM_TB1_CONST16
31 #define CALL_FROM_TB1_CONST16(func, arg0) CALL_FROM_TB1(func, arg0);
34 #define CALL_FROM_TB2(func, arg0, arg1) func(arg0, arg1);
36 #ifndef CALL_FROM_TB2_CONST16
37 #define CALL_FROM_TB2_CONST16(func, arg0, arg1) \
38 CALL_FROM_TB2(func, arg0, arg1);
41 #define CALL_FROM_TB3(func, arg0, arg1, arg2) func(arg0, arg1, arg2);
44 #define CALL_FROM_TB4(func, arg0, arg1, arg2, arg3) \
45 func(arg0, arg1, arg2, arg3);
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"
118 #include "op_template.c"
121 #include "op_template.c"
124 #include "op_template.c"
127 #include "op_template.c"
130 #include "op_template.c"
133 #include "op_template.c"
136 #include "op_template.c"
139 #include "op_template.c"
143 #include "op_template.c"
146 #include "op_template.c"
149 #include "op_template.c"
152 void op_dup_T0 (void)
158 void op_load_HI (void)
164 void op_store_HI (void)
170 void op_load_LO (void)
176 void op_store_LO (void)
183 #define MEMSUFFIX _raw
186 #if !defined(CONFIG_USER_ONLY)
187 #define MEMSUFFIX _user
191 #define MEMSUFFIX _kernel
209 if (((tmp ^ T1 ^ (-1)) & (T0 ^ T1)) >> 31) {
210 /* operands of same sign, result different sign */
211 CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW);
227 T0 = (int32_t)T0 - (int32_t)T1;
228 if (((tmp ^ T1) & (tmp ^ T0)) >> 31) {
229 /* operands of different sign, first operand and result different sign */
230 CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW);
237 T0 = (int32_t)T0 * (int32_t)T1;
244 env->LO = (int32_t)T0 / (int32_t)T1;
245 env->HI = (int32_t)T0 % (int32_t)T1;
292 T0 = (int32_t)T0 >> T1;
304 T0 = T1 << (T0 & 0x1F);
310 T0 = (int32_t)T1 >> (T0 & 0x1F);
316 T0 = T1 >> (T0 & 0x1F);
324 if (T0 == (target_ulong)-1) {
327 for (n = 0; n < 32; n++) {
328 if (!(T0 & (1 << 31)))
344 for (n = 0; n < 32; n++) {
354 /* 64 bits arithmetic */
355 #if (HOST_LONG_BITS == 64)
356 static inline uint64_t get_HILO (void)
358 return ((uint64_t)env->HI << 32) | (uint64_t)env->LO;
361 static inline void set_HILO (uint64_t HILO)
363 env->LO = HILO & 0xFFFFFFFF;
364 env->HI = HILO >> 32;
369 set_HILO((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
375 set_HILO((uint64_t)T0 * (uint64_t)T1);
383 tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
384 set_HILO((int64_t)get_HILO() + tmp);
392 tmp = ((uint64_t)T0 * (uint64_t)T1);
393 set_HILO(get_HILO() + tmp);
401 tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
402 set_HILO((int64_t)get_HILO() - tmp);
410 tmp = ((uint64_t)T0 * (uint64_t)T1);
411 set_HILO(get_HILO() - tmp);
417 CALL_FROM_TB0(do_mult);
423 CALL_FROM_TB0(do_multu);
429 CALL_FROM_TB0(do_madd);
435 CALL_FROM_TB0(do_maddu);
441 CALL_FROM_TB0(do_msub);
447 CALL_FROM_TB0(do_msubu);
452 /* Conditional moves */
456 env->gpr[PARAM1] = T0;
463 env->gpr[PARAM1] = T0;
468 #define OP_COND(name, cond) \
469 void glue(op_, name) (void) \
479 OP_COND(eq, T0 == T1);
480 OP_COND(ne, T0 != T1);
481 OP_COND(ge, (int32_t)T0 >= (int32_t)T1);
482 OP_COND(geu, T0 >= T1);
483 OP_COND(lt, (int32_t)T0 < (int32_t)T1);
484 OP_COND(ltu, T0 < T1);
485 OP_COND(gez, (int32_t)T0 >= 0);
486 OP_COND(gtz, (int32_t)T0 > 0);
487 OP_COND(lez, (int32_t)T0 <= 0);
488 OP_COND(ltz, (int32_t)T0 < 0);
491 //#undef USE_DIRECT_JUMP
493 void OPPROTO op_goto_tb0(void)
495 GOTO_TB(op_goto_tb0, PARAM1, 0);
498 void OPPROTO op_goto_tb1(void)
500 GOTO_TB(op_goto_tb1, PARAM1, 1);
503 /* Branch to register */
504 void op_save_breg_target (void)
509 void op_restore_breg_target (void)
520 void op_save_btarget (void)
522 env->btarget = PARAM1;
526 /* Conditional branch */
527 void op_set_bcond (void)
533 void op_save_bcond (void)
539 void op_restore_bcond (void)
545 void op_jnz_T2 (void)
555 CALL_FROM_TB2(do_mfc0, PARAM1, PARAM2);
561 CALL_FROM_TB2(do_mtc0, PARAM1, PARAM2);
565 #if defined(MIPS_USES_R4K_TLB)
568 CALL_FROM_TB0(do_tlbwi);
574 CALL_FROM_TB0(do_tlbwr);
580 CALL_FROM_TB0(do_tlbp);
586 CALL_FROM_TB0(do_tlbr);
594 CALL_FROM_TB1(do_pmon, PARAM1);
600 CALL_FROM_TB1(do_raise_exception_direct, EXCP_TRAP);
607 CALL_FROM_TB1(do_raise_exception, EXCP_DEBUG);
610 void op_set_lladdr (void)
612 env->CP0_LLAddr = T2;
615 void debug_eret (void);
618 CALL_FROM_TB0(debug_eret);
619 if (env->hflags & MIPS_HFLAG_ERL) {
620 env->PC = env->CP0_ErrorEPC;
621 env->hflags &= ~MIPS_HFLAG_ERL;
623 env->PC = env->CP0_EPC;
624 env->hflags &= ~MIPS_HFLAG_EXL;
631 CALL_FROM_TB0(debug_eret);
632 env->PC = env->CP0_DEPC;
635 void op_save_state (void)
637 env->hflags = PARAM1;
641 void op_save_pc (void)
647 void op_raise_exception (void)
649 CALL_FROM_TB1(do_raise_exception, PARAM1);
653 void op_raise_exception_err (void)
655 CALL_FROM_TB2(do_raise_exception_err, PARAM1, PARAM2);
659 void op_exit_tb (void)
667 CALL_FROM_TB1(do_raise_exception, EXCP_HLT);