4 Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
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 REG (env->gregs[0])
26 #include "op_template.h"
28 #define REG (env->gregs[1])
29 #include "op_template.h"
31 #define REG (env->gregs[2])
32 #include "op_template.h"
34 #define REG (env->gregs[3])
35 #include "op_template.h"
37 #define REG (env->gregs[4])
38 #include "op_template.h"
40 #define REG (env->gregs[5])
41 #include "op_template.h"
43 #define REG (env->gregs[6])
44 #include "op_template.h"
46 #define REG (env->gregs[7])
47 #include "op_template.h"
49 #define REG (env->regwptr[16])
50 #include "op_template.h"
52 #define REG (env->regwptr[17])
53 #include "op_template.h"
55 #define REG (env->regwptr[18])
56 #include "op_template.h"
58 #define REG (env->regwptr[19])
59 #include "op_template.h"
61 #define REG (env->regwptr[20])
62 #include "op_template.h"
64 #define REG (env->regwptr[21])
65 #include "op_template.h"
67 #define REG (env->regwptr[22])
68 #include "op_template.h"
70 #define REG (env->regwptr[23])
71 #include "op_template.h"
73 #define REG (env->regwptr[8])
74 #include "op_template.h"
76 #define REG (env->regwptr[9])
77 #include "op_template.h"
79 #define REG (env->regwptr[10])
80 #include "op_template.h"
82 #define REG (env->regwptr[11])
83 #include "op_template.h"
85 #define REG (env->regwptr[12])
86 #include "op_template.h"
88 #define REG (env->regwptr[13])
89 #include "op_template.h"
91 #define REG (env->regwptr[14])
92 #include "op_template.h"
94 #define REG (env->regwptr[15])
95 #include "op_template.h"
97 #define REG (env->regwptr[0])
98 #include "op_template.h"
100 #define REG (env->regwptr[1])
101 #include "op_template.h"
103 #define REG (env->regwptr[2])
104 #include "op_template.h"
106 #define REG (env->regwptr[3])
107 #include "op_template.h"
109 #define REG (env->regwptr[4])
110 #include "op_template.h"
112 #define REG (env->regwptr[5])
113 #include "op_template.h"
115 #define REG (env->regwptr[6])
116 #include "op_template.h"
118 #define REG (env->regwptr[7])
119 #include "op_template.h"
122 #define REG (env->fpr[0])
123 #include "fop_template.h"
125 #define REG (env->fpr[1])
126 #include "fop_template.h"
128 #define REG (env->fpr[2])
129 #include "fop_template.h"
131 #define REG (env->fpr[3])
132 #include "fop_template.h"
134 #define REG (env->fpr[4])
135 #include "fop_template.h"
137 #define REG (env->fpr[5])
138 #include "fop_template.h"
140 #define REG (env->fpr[6])
141 #include "fop_template.h"
143 #define REG (env->fpr[7])
144 #include "fop_template.h"
146 #define REG (env->fpr[8])
147 #include "fop_template.h"
149 #define REG (env->fpr[9])
150 #include "fop_template.h"
152 #define REG (env->fpr[10])
153 #include "fop_template.h"
155 #define REG (env->fpr[11])
156 #include "fop_template.h"
158 #define REG (env->fpr[12])
159 #include "fop_template.h"
161 #define REG (env->fpr[13])
162 #include "fop_template.h"
164 #define REG (env->fpr[14])
165 #include "fop_template.h"
167 #define REG (env->fpr[15])
168 #include "fop_template.h"
170 #define REG (env->fpr[16])
171 #include "fop_template.h"
173 #define REG (env->fpr[17])
174 #include "fop_template.h"
176 #define REG (env->fpr[18])
177 #include "fop_template.h"
179 #define REG (env->fpr[19])
180 #include "fop_template.h"
182 #define REG (env->fpr[20])
183 #include "fop_template.h"
185 #define REG (env->fpr[21])
186 #include "fop_template.h"
188 #define REG (env->fpr[22])
189 #include "fop_template.h"
191 #define REG (env->fpr[23])
192 #include "fop_template.h"
194 #define REG (env->fpr[24])
195 #include "fop_template.h"
197 #define REG (env->fpr[25])
198 #include "fop_template.h"
200 #define REG (env->fpr[26])
201 #include "fop_template.h"
203 #define REG (env->fpr[27])
204 #include "fop_template.h"
206 #define REG (env->fpr[28])
207 #include "fop_template.h"
209 #define REG (env->fpr[29])
210 #include "fop_template.h"
212 #define REG (env->fpr[30])
213 #include "fop_template.h"
215 #define REG (env->fpr[31])
216 #include "fop_template.h"
218 #define EIP (env->pc)
220 #define FLAG_SET(x) ((env->psr&x)?1:0)
221 #define FFLAG_SET(x) ((env->fsr&x)?1:0)
223 void OPPROTO op_movl_T0_0(void)
228 void OPPROTO op_movl_T0_im(void)
233 void OPPROTO op_movl_T1_im(void)
238 void OPPROTO op_movl_T2_im(void)
243 void OPPROTO op_add_T1_T0(void)
248 void OPPROTO op_add_T1_T0_cc(void)
256 env->psr |= PSR_ZERO;
257 if ((int32_t) T0 < 0)
260 env->psr |= PSR_CARRY;
261 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
267 void OPPROTO op_addx_T1_T0(void)
269 T0 += T1 + FLAG_SET(PSR_CARRY);
272 void OPPROTO op_addx_T1_T0_cc(void)
277 T0 += T1 + FLAG_SET(PSR_CARRY);
280 env->psr |= PSR_ZERO;
281 if ((int32_t) T0 < 0)
284 env->psr |= PSR_CARRY;
285 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
291 void OPPROTO op_sub_T1_T0(void)
296 void OPPROTO op_sub_T1_T0_cc(void)
304 env->psr |= PSR_ZERO;
305 if ((int32_t) T0 < 0)
308 env->psr |= PSR_CARRY;
309 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
315 void OPPROTO op_subx_T1_T0(void)
317 T0 -= T1 + FLAG_SET(PSR_CARRY);
320 void OPPROTO op_subx_T1_T0_cc(void)
325 T0 -= T1 + FLAG_SET(PSR_CARRY);
328 env->psr |= PSR_ZERO;
329 if ((int32_t) T0 < 0)
332 env->psr |= PSR_CARRY;
333 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
339 void OPPROTO op_and_T1_T0(void)
344 void OPPROTO op_or_T1_T0(void)
349 void OPPROTO op_xor_T1_T0(void)
354 void OPPROTO op_andn_T1_T0(void)
359 void OPPROTO op_orn_T1_T0(void)
364 void OPPROTO op_xnor_T1_T0(void)
369 void OPPROTO op_umul_T1_T0(void)
372 res = (uint64_t) T0 * (uint64_t) T1;
373 T0 = res & 0xffffffff;
377 void OPPROTO op_smul_T1_T0(void)
380 res = (int64_t) ((int32_t) T0) * (int64_t) ((int32_t) T1);
381 T0 = res & 0xffffffff;
385 void OPPROTO op_mulscc_T1_T0(void)
387 unsigned int b1, N, V, b2;
390 N = FLAG_SET(PSR_NEG);
391 V = FLAG_SET(PSR_OVF);
394 T0 = (b1 << 31) | (T0 >> 1);
397 /* do addition and update flags */
402 env->psr |= PSR_ZERO;
403 if ((int32_t) T0 < 0)
406 env->psr |= PSR_CARRY;
407 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
409 env->y = (b2 << 31) | (env->y >> 1);
413 void OPPROTO op_udiv_T1_T0(void)
418 x0 = T0 | ((uint64_t) (env->y) << 32);
421 if (x0 > 0xffffffff) {
431 void OPPROTO op_sdiv_T1_T0(void)
436 x0 = T0 | ((int64_t) (env->y) << 32);
439 if ((int32_t) x0 != x0) {
440 T0 = x0 < 0? 0x80000000: 0x7fffffff;
449 void OPPROTO op_div_cc(void)
453 env->psr |= PSR_ZERO;
454 if ((int32_t) T0 < 0)
462 void OPPROTO op_logic_T0_cc(void)
466 env->psr |= PSR_ZERO;
467 if ((int32_t) T0 < 0)
473 void OPPROTO op_sll(void)
478 void OPPROTO op_srl(void)
483 void OPPROTO op_sra(void)
485 T0 = ((int32_t) T0) >> T1;
489 #define MEMSUFFIX _raw
491 #if !defined(CONFIG_USER_ONLY)
492 #define MEMSUFFIX _user
495 #define MEMSUFFIX _kernel
499 void OPPROTO op_ldfsr(void)
501 env->fsr = *((uint32_t *) &FT0);
505 void OPPROTO op_stfsr(void)
507 *((uint32_t *) &FT0) = env->fsr;
510 void OPPROTO op_wry(void)
515 void OPPROTO op_rdy(void)
520 void OPPROTO op_rdwim(void)
525 void OPPROTO op_wrwim(void)
531 void OPPROTO op_rdpsr(void)
536 void OPPROTO op_wrpsr(void)
542 void OPPROTO op_rdtbr(void)
547 void OPPROTO op_wrtbr(void)
553 void OPPROTO op_rett(void)
559 /* XXX: use another pointer for %iN registers to avoid slow wrapping
561 void OPPROTO op_save(void)
564 cwp = (env->cwp - 1) & (NWINDOWS - 1);
565 if (env->wim & (1 << cwp)) {
566 raise_exception(TT_WIN_OVF);
572 void OPPROTO op_restore(void)
575 cwp = (env->cwp + 1) & (NWINDOWS - 1);
576 if (env->wim & (1 << cwp)) {
577 raise_exception(TT_WIN_UNF);
583 void OPPROTO op_exception(void)
585 env->exception_index = PARAM1;
589 void OPPROTO op_trap_T0(void)
591 env->exception_index = TT_TRAP + (T0 & 0x7f);
595 void OPPROTO op_trapcc_T0(void)
598 env->exception_index = TT_TRAP + (T0 & 0x7f);
604 void OPPROTO op_trap_ifnofpu(void)
607 env->exception_index = TT_NFPU_INSN;
613 void OPPROTO op_fpexception_im(void)
615 env->exception_index = TT_FP_EXCP;
616 env->fsr &= ~FSR_FTT_MASK;
622 void OPPROTO op_debug(void)
627 void OPPROTO op_exit_tb(void)
632 void OPPROTO op_eval_be(void)
634 T2 = FLAG_SET(PSR_ZERO);
637 void OPPROTO op_eval_ble(void)
639 target_ulong Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
644 void OPPROTO op_eval_bl(void)
646 target_ulong N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
651 void OPPROTO op_eval_bleu(void)
653 target_ulong Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
658 void OPPROTO op_eval_bcs(void)
660 T2 = FLAG_SET(PSR_CARRY);
663 void OPPROTO op_eval_bvs(void)
665 T2 = FLAG_SET(PSR_OVF);
668 void OPPROTO op_eval_bneg(void)
670 T2 = FLAG_SET(PSR_NEG);
673 void OPPROTO op_eval_bne(void)
675 T2 = !FLAG_SET(PSR_ZERO);
678 void OPPROTO op_eval_bg(void)
680 target_ulong Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
685 void OPPROTO op_eval_bge(void)
687 target_ulong N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
692 void OPPROTO op_eval_bgu(void)
694 target_ulong Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
699 void OPPROTO op_eval_bcc(void)
701 T2 = !FLAG_SET(PSR_CARRY);
704 void OPPROTO op_eval_bpos(void)
706 T2 = !FLAG_SET(PSR_NEG);
709 void OPPROTO op_eval_bvc(void)
711 T2 = !FLAG_SET(PSR_OVF);
714 /* FCC1:FCC0: 0 =, 1 <, 2 >, 3 u */
716 void OPPROTO op_eval_fbne(void)
719 T2 = (env->fsr & (FSR_FCC1 | FSR_FCC0)); /* L or G or U */
722 void OPPROTO op_eval_fblg(void)
725 T2 = FFLAG_SET(FSR_FCC0) ^ FFLAG_SET(FSR_FCC1);
728 void OPPROTO op_eval_fbul(void)
731 T2 = FFLAG_SET(FSR_FCC0);
734 void OPPROTO op_eval_fbl(void)
737 T2 = FFLAG_SET(FSR_FCC0) & !FFLAG_SET(FSR_FCC1);
740 void OPPROTO op_eval_fbug(void)
743 T2 = FFLAG_SET(FSR_FCC1);
746 void OPPROTO op_eval_fbg(void)
749 T2 = !FFLAG_SET(FSR_FCC0) & FFLAG_SET(FSR_FCC1);
752 void OPPROTO op_eval_fbu(void)
755 T2 = FFLAG_SET(FSR_FCC0) & FFLAG_SET(FSR_FCC1);
758 void OPPROTO op_eval_fbe(void)
761 T2 = !FFLAG_SET(FSR_FCC0) & !FFLAG_SET(FSR_FCC1);
764 void OPPROTO op_eval_fbue(void)
767 T2 = !(FFLAG_SET(FSR_FCC1) ^ FFLAG_SET(FSR_FCC0));
771 void OPPROTO op_eval_fbge(void)
774 T2 = !FFLAG_SET(FSR_FCC0);
777 void OPPROTO op_eval_fbuge(void)
780 T2 = !(FFLAG_SET(FSR_FCC0) & !FFLAG_SET(FSR_FCC1));
783 void OPPROTO op_eval_fble(void)
786 T2 = !FFLAG_SET(FSR_FCC1);
789 void OPPROTO op_eval_fbule(void)
792 T2 = !(!FFLAG_SET(FSR_FCC0) & FFLAG_SET(FSR_FCC1));
795 void OPPROTO op_eval_fbo(void)
798 T2 = !(FFLAG_SET(FSR_FCC0) & FFLAG_SET(FSR_FCC1));
801 void OPPROTO op_jmp_im(void)
806 void OPPROTO op_movl_npc_im(void)
811 void OPPROTO op_movl_npc_T0(void)
816 void OPPROTO op_mov_pc_npc(void)
821 void OPPROTO op_next_insn(void)
824 env->npc = env->npc + 4;
827 void OPPROTO op_branch(void)
829 env->npc = PARAM3; /* XXX: optimize */
830 JUMP_TB(op_branch, PARAM1, 0, PARAM2);
833 void OPPROTO op_branch2(void)
836 env->npc = PARAM2 + 4;
837 JUMP_TB(op_branch2, PARAM1, 0, PARAM2);
839 env->npc = PARAM3 + 4;
840 JUMP_TB(op_branch2, PARAM1, 1, PARAM3);
845 void OPPROTO op_branch_a(void)
848 env->npc = PARAM2; /* XXX: optimize */
849 JUMP_TB(op_branch_a, PARAM1, 0, PARAM3);
851 env->npc = PARAM3 + 8; /* XXX: optimize */
852 JUMP_TB(op_branch_a, PARAM1, 1, PARAM3 + 4);
857 void OPPROTO op_generic_branch(void)
867 void OPPROTO op_flush_T0(void)
872 void OPPROTO op_fnegs(void)
877 void OPPROTO op_fabss(void)
882 void OPPROTO op_fsqrts(void)
887 void OPPROTO op_fsqrtd(void)
892 void OPPROTO op_fmuls(void)
897 void OPPROTO op_fmuld(void)
902 void OPPROTO op_fsmuld(void)
907 void OPPROTO op_fadds(void)
912 void OPPROTO op_faddd(void)
917 void OPPROTO op_fsubs(void)
922 void OPPROTO op_fsubd(void)
927 void OPPROTO op_fdivs(void)
932 void OPPROTO op_fdivd(void)
937 void OPPROTO op_fcmps(void)
942 void OPPROTO op_fcmpd(void)
947 #ifdef USE_INT_TO_FLOAT_HELPERS
948 void OPPROTO op_fitos(void)
953 void OPPROTO op_fitod(void)
958 void OPPROTO op_fitos(void)
960 FT0 = (float) *((int32_t *)&FT1);
963 void OPPROTO op_fitod(void)
965 DT0 = (double) *((int32_t *)&FT1);
969 void OPPROTO op_fdtos(void)
974 void OPPROTO op_fstod(void)
979 void OPPROTO op_fstoi(void)
981 *((int32_t *)&FT0) = (int32_t) FT1;
984 void OPPROTO op_fdtoi(void)
986 *((int32_t *)&FT0) = (int32_t) DT1;
989 void OPPROTO op_ld_asi()
991 helper_ld_asi(PARAM1, PARAM2, PARAM3);
994 void OPPROTO op_st_asi()
996 helper_st_asi(PARAM1, PARAM2, PARAM3);