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 ((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31)) {
210 CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW);
226 T0 = (int32_t)T0 - (int32_t)T1;
227 if (!((T0 >> 31) ^ (T1 >> 31) ^ (tmp >> 31))) {
228 CALL_FROM_TB1(do_raise_exception_direct, EXCP_OVERFLOW);
235 T0 = (int32_t)T0 * (int32_t)T1;
242 env->LO = (int32_t)T0 / (int32_t)T1;
243 env->HI = (int32_t)T0 % (int32_t)T1;
290 T0 = (int32_t)T0 >> T1;
302 T0 = T1 << (T0 & 0x1F);
308 T0 = (int32_t)T1 >> (T0 & 0x1F);
314 T0 = T1 >> (T0 & 0x1F);
322 if (T0 == (target_ulong)-1) {
325 for (n = 0; n < 32; n++) {
326 if (!(T0 & (1 << 31)))
342 for (n = 0; n < 32; n++) {
352 /* 64 bits arithmetic */
353 #if (HOST_LONG_BITS == 64)
354 static inline uint64_t get_HILO (void)
356 return ((uint64_t)env->HI << 32) | (uint64_t)env->LO;
359 static inline void set_HILO (uint64_t HILO)
361 env->LO = HILO & 0xFFFFFFFF;
362 env->HI = HILO >> 32;
367 set_HILO((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
373 set_HILO((uint64_t)T0 * (uint64_t)T1);
381 tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
382 set_HILO((int64_t)get_HILO() + tmp);
390 tmp = ((uint64_t)T0 * (uint64_t)T1);
391 set_HILO(get_HILO() + tmp);
399 tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
400 set_HILO((int64_t)get_HILO() - tmp);
408 tmp = ((uint64_t)T0 * (uint64_t)T1);
409 set_HILO(get_HILO() - tmp);
415 CALL_FROM_TB0(do_mult);
421 CALL_FROM_TB0(do_multu);
427 CALL_FROM_TB0(do_madd);
433 CALL_FROM_TB0(do_maddu);
439 CALL_FROM_TB0(do_msub);
445 CALL_FROM_TB0(do_msubu);
450 /* Conditional moves */
454 env->gpr[PARAM1] = T0;
461 env->gpr[PARAM1] = T0;
466 #define OP_COND(name, cond) \
467 void glue(op_, name) (void) \
477 OP_COND(eq, T0 == T1);
478 OP_COND(ne, T0 != T1);
479 OP_COND(ge, (int32_t)T0 >= (int32_t)T1);
480 OP_COND(geu, T0 >= T1);
481 OP_COND(lt, (int32_t)T0 < (int32_t)T1);
482 OP_COND(ltu, T0 < T1);
483 OP_COND(gez, (int32_t)T0 >= 0);
484 OP_COND(gtz, (int32_t)T0 > 0);
485 OP_COND(lez, (int32_t)T0 <= 0);
486 OP_COND(ltz, (int32_t)T0 < 0);
489 //#undef USE_DIRECT_JUMP
491 void OPPROTO op_goto_tb0(void)
493 GOTO_TB(op_goto_tb0, PARAM1, 0);
496 void OPPROTO op_goto_tb1(void)
498 GOTO_TB(op_goto_tb1, PARAM1, 1);
501 /* Branch to register */
502 void op_save_breg_target (void)
507 void op_restore_breg_target (void)
518 void op_save_btarget (void)
520 env->btarget = PARAM1;
524 /* Conditional branch */
525 void op_set_bcond (void)
531 void op_save_bcond (void)
537 void op_restore_bcond (void)
543 void op_jnz_T2 (void)
553 CALL_FROM_TB2(do_mfc0, PARAM1, PARAM2);
559 CALL_FROM_TB2(do_mtc0, PARAM1, PARAM2);
563 #if defined(MIPS_USES_R4K_TLB)
566 CALL_FROM_TB0(do_tlbwi);
572 CALL_FROM_TB0(do_tlbwr);
578 CALL_FROM_TB0(do_tlbp);
584 CALL_FROM_TB0(do_tlbr);
592 CALL_FROM_TB1(do_pmon, PARAM1);
598 CALL_FROM_TB1(do_raise_exception_direct, EXCP_TRAP);
605 CALL_FROM_TB1(do_raise_exception_direct, EXCP_DEBUG);
608 void op_set_lladdr (void)
610 env->CP0_LLAddr = T2;
613 void debug_eret (void);
616 CALL_FROM_TB0(debug_eret);
617 if (env->hflags & MIPS_HFLAG_ERL) {
618 env->PC = env->CP0_ErrorEPC;
619 env->hflags &= ~MIPS_HFLAG_ERL;
621 env->PC = env->CP0_EPC;
622 env->hflags &= ~MIPS_HFLAG_EXL;
629 CALL_FROM_TB0(debug_eret);
630 env->PC = env->CP0_DEPC;
633 void op_save_state (void)
635 env->hflags = PARAM1;
639 void op_save_pc (void)
645 void op_raise_exception (void)
647 CALL_FROM_TB1(do_raise_exception, PARAM1);
651 void op_raise_exception_err (void)
653 CALL_FROM_TB2(do_raise_exception_err, PARAM1, PARAM2);
657 void op_exit_tb (void)
665 CALL_FROM_TB1(do_raise_exception, EXCP_HLT);