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_1(void)
233 void OPPROTO op_movl_T0_im(void)
238 void OPPROTO op_movl_T1_im(void)
243 void OPPROTO op_movl_T2_im(void)
248 void OPPROTO op_addl_T1_im(void)
253 void OPPROTO op_addl_T1_T2(void)
258 void OPPROTO op_subl_T1_T2(void)
263 void OPPROTO op_add_T1_T0(void)
268 void OPPROTO op_add_T1_T0_cc(void)
275 env->psr |= PSR_ZERO;
279 env->psr |= PSR_CARRY;
280 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
285 void OPPROTO op_sub_T1_T0(void)
290 void OPPROTO op_sub_T1_T0_cc(void)
298 env->psr |= PSR_ZERO;
302 env->psr |= PSR_CARRY;
303 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
308 void OPPROTO op_and_T1_T0(void)
313 void OPPROTO op_or_T1_T0(void)
318 void OPPROTO op_xor_T1_T0(void)
323 void OPPROTO op_andn_T1_T0(void)
328 void OPPROTO op_orn_T1_T0(void)
333 void OPPROTO op_xnor_T1_T0(void)
338 void OPPROTO op_addx_T1_T0(void)
340 T0 += T1 + ((env->psr & PSR_CARRY) ? 1 : 0);
343 void OPPROTO op_umul_T1_T0(void)
346 res = (uint64_t) T0 *(uint64_t) T1;
347 T0 = res & 0xffffffff;
351 void OPPROTO op_smul_T1_T0(void)
354 res = (int64_t) ((int32_t) T0) * (int64_t) ((int32_t) T1);
355 T0 = res & 0xffffffff;
359 void OPPROTO op_mulscc_T1_T0(void)
361 unsigned int b1, N, V, b2, src1;
362 N = FLAG_SET(PSR_NEG);
363 V = FLAG_SET(PSR_OVF);
366 T0 = (b1 << 31) | (T0 >> 1);
369 /* do addition and update flags */
374 env->psr |= PSR_ZERO;
378 env->psr |= PSR_CARRY;
379 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
381 env->y = (b2 << 31) | (env->y >> 1);
385 void OPPROTO op_udiv_T1_T0(void)
390 x0 = T0 | ((uint64_t) (env->y) << 32);
393 if (x0 > 0xffffffff) {
403 void OPPROTO op_sdiv_T1_T0(void)
408 x0 = T0 | ((uint64_t) (env->y) << 32);
411 if ((int32_t) x0 != x0) {
421 void OPPROTO op_div_cc(void)
425 env->psr |= PSR_ZERO;
433 void OPPROTO op_subx_T1_T0(void)
435 T0 -= T1 + ((env->psr & PSR_CARRY) ? 1 : 0);
438 void OPPROTO op_logic_T0_cc(void)
442 env->psr |= PSR_ZERO;
448 void OPPROTO op_set_flags(void)
452 env->psr |= PSR_ZERO;
453 if ((unsigned int) T0 < (unsigned int) T1)
454 env->psr |= PSR_CARRY;
455 if ((int) T0 < (int) T1)
462 void OPPROTO op_sll(void)
467 void OPPROTO op_srl(void)
472 void OPPROTO op_sra(void)
474 T0 = ((int32_t) T0) >> T1;
478 #define MEMSUFFIX _raw
480 #if !defined(CONFIG_USER_ONLY)
481 #define MEMSUFFIX _user
484 #define MEMSUFFIX _kernel
488 void OPPROTO op_ldfsr(void)
490 env->fsr = *((uint32_t *) &FT0);
494 void OPPROTO op_stfsr(void)
496 *((uint32_t *) &FT0) = env->fsr;
499 void OPPROTO op_wry(void)
504 void OPPROTO op_rdy(void)
509 void OPPROTO op_rdwim(void)
514 void OPPROTO op_wrwim(void)
520 void OPPROTO op_rdpsr(void)
525 void OPPROTO op_wrpsr(void)
528 env->psr = T0 & ~PSR_ICC;
529 env->psrs = (T0 & PSR_S)? 1 : 0;
530 env->psrps = (T0 & PSR_PS)? 1 : 0;
531 env->psret = (T0 & PSR_ET)? 1 : 0;
532 cwp = (T0 & PSR_CWP) & (NWINDOWS - 1);
537 void OPPROTO op_rdtbr(void)
542 void OPPROTO op_wrtbr(void)
548 void OPPROTO op_rett(void)
554 void raise_exception(int tt)
556 env->exception_index = tt;
560 /* XXX: use another pointer for %iN registers to avoid slow wrapping
562 void OPPROTO op_save(void)
565 cwp = (env->cwp - 1) & (NWINDOWS - 1);
566 if (env->wim & (1 << cwp)) {
567 raise_exception(TT_WIN_OVF);
573 void OPPROTO op_restore(void)
576 cwp = (env->cwp + 1) & (NWINDOWS - 1);
577 if (env->wim & (1 << cwp)) {
578 raise_exception(TT_WIN_UNF);
584 void OPPROTO op_exception(void)
586 env->exception_index = PARAM1;
590 void OPPROTO op_trap_T0(void)
592 env->exception_index = TT_TRAP + (T0 & 0x7f);
596 void OPPROTO op_trapcc_T0(void)
599 env->exception_index = TT_TRAP + (T0 & 0x7f);
605 void OPPROTO op_debug(void)
607 env->exception_index = EXCP_DEBUG;
611 void OPPROTO op_exit_tb(void)
616 void OPPROTO op_eval_be(void)
618 T2 = (env->psr & PSR_ZERO);
621 void OPPROTO op_eval_ble(void)
623 unsigned int Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
628 void OPPROTO op_eval_bl(void)
630 unsigned int N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
635 void OPPROTO op_eval_bleu(void)
637 unsigned int Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
642 void OPPROTO op_eval_bcs(void)
644 T2 = (env->psr & PSR_CARRY);
647 void OPPROTO op_eval_bvs(void)
649 T2 = (env->psr & PSR_OVF);
652 void OPPROTO op_eval_bneg(void)
654 T2 = (env->psr & PSR_NEG);
657 void OPPROTO op_eval_bne(void)
659 T2 = !(env->psr & PSR_ZERO);
662 void OPPROTO op_eval_bg(void)
664 unsigned int Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
669 void OPPROTO op_eval_bge(void)
671 unsigned int N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
676 void OPPROTO op_eval_bgu(void)
678 unsigned int Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
683 void OPPROTO op_eval_bcc(void)
685 T2 = !(env->psr & PSR_CARRY);
688 void OPPROTO op_eval_bpos(void)
690 T2 = !(env->psr & PSR_NEG);
693 void OPPROTO op_eval_bvc(void)
695 T2 = !(env->psr & PSR_OVF);
698 /* FCC1:FCC0: 0 =, 1 <, 2 >, 3 u */
700 void OPPROTO op_eval_fbne(void)
703 T2 = (env->fsr & (FSR_FCC1 | FSR_FCC0)); /* L or G or U */
706 void OPPROTO op_eval_fblg(void)
709 T2 = FFLAG_SET(FSR_FCC0) ^ FFLAG_SET(FSR_FCC1);
712 void OPPROTO op_eval_fbul(void)
715 T2 = FFLAG_SET(FSR_FCC0);
718 void OPPROTO op_eval_fbl(void)
721 T2 = FFLAG_SET(FSR_FCC0) & !FFLAG_SET(FSR_FCC1);
724 void OPPROTO op_eval_fbug(void)
727 T2 = FFLAG_SET(FSR_FCC1);
730 void OPPROTO op_eval_fbg(void)
733 T2 = !FFLAG_SET(FSR_FCC0) & FFLAG_SET(FSR_FCC1);
736 void OPPROTO op_eval_fbu(void)
739 T2 = FFLAG_SET(FSR_FCC0) & FFLAG_SET(FSR_FCC1);
742 void OPPROTO op_eval_fbe(void)
745 T2 = !FFLAG_SET(FSR_FCC0) & !FFLAG_SET(FSR_FCC1);
748 void OPPROTO op_eval_fbue(void)
751 T2 = !(FFLAG_SET(FSR_FCC1) ^ FFLAG_SET(FSR_FCC0));
754 void OPPROTO op_eval_fbge(void)
757 T2 = !FFLAG_SET(FSR_FCC0);
760 void OPPROTO op_eval_fbuge(void)
763 T2 = !(FFLAG_SET(FSR_FCC0) & !FFLAG_SET(FSR_FCC1));
766 void OPPROTO op_eval_fble(void)
769 T2 = !FFLAG_SET(FSR_FCC1);
772 void OPPROTO op_eval_fbule(void)
775 T2 = !(!FFLAG_SET(FSR_FCC0) & FFLAG_SET(FSR_FCC1));
778 void OPPROTO op_eval_fbo(void)
781 T2 = !(FFLAG_SET(FSR_FCC0) & FFLAG_SET(FSR_FCC1));
784 void OPPROTO op_movl_T2_0(void)
789 void OPPROTO op_movl_T2_1(void)
794 void OPPROTO op_jmp_im(void)
799 void OPPROTO op_movl_npc_im(void)
804 void OPPROTO op_movl_npc_T0(void)
809 void OPPROTO op_next_insn(void)
812 env->npc = env->npc + 4;
815 void OPPROTO op_branch(void)
817 env->npc = PARAM3; /* XXX: optimize */
818 JUMP_TB(op_branch, PARAM1, 0, PARAM2);
821 void OPPROTO op_branch2(void)
824 env->npc = PARAM2 + 4;
825 JUMP_TB(op_branch2, PARAM1, 0, PARAM2);
827 env->npc = PARAM3 + 4;
828 JUMP_TB(op_branch2, PARAM1, 1, PARAM3);
833 void OPPROTO op_branch_a(void)
836 env->npc = PARAM2; /* XXX: optimize */
837 JUMP_TB(op_generic_branch_a, PARAM1, 0, PARAM3);
839 env->npc = PARAM3 + 8; /* XXX: optimize */
840 JUMP_TB(op_generic_branch_a, PARAM1, 1, PARAM3 + 4);
845 void OPPROTO op_generic_branch(void)
855 void OPPROTO op_flush_T0(void)
860 void OPPROTO op_fnegs(void)
865 void OPPROTO op_fabss(void)
870 void OPPROTO op_fsqrts(void)
875 void OPPROTO op_fsqrtd(void)
880 void OPPROTO op_fmuls(void)
885 void OPPROTO op_fmuld(void)
890 void OPPROTO op_fsmuld(void)
895 void OPPROTO op_fadds(void)
900 void OPPROTO op_faddd(void)
905 void OPPROTO op_fsubs(void)
910 void OPPROTO op_fsubd(void)
915 void OPPROTO op_fdivs(void)
920 void OPPROTO op_fdivd(void)
925 void OPPROTO op_fcmps(void)
930 void OPPROTO op_fcmpd(void)
935 #ifdef USE_INT_TO_FLOAT_HELPERS
936 void OPPROTO op_fitos(void)
941 void OPPROTO op_fitod(void)
946 void OPPROTO op_fitos(void)
948 FT0 = (float) *((int32_t *)&FT1);
951 void OPPROTO op_fitod(void)
953 DT0 = (double) *((int32_t *)&FT1);
957 void OPPROTO op_fdtos(void)
962 void OPPROTO op_fstod(void)
967 void OPPROTO op_fstoi(void)
969 *((int32_t *)&FT0) = (int32_t) FT1;
972 void OPPROTO op_fdtoi(void)
974 *((int32_t *)&FT0) = (int32_t) DT1;
977 void OPPROTO op_ld_asi()
979 helper_ld_asi(PARAM1, PARAM2, PARAM3);
982 void OPPROTO op_st_asi()
984 helper_st_asi(PARAM1, PARAM2, PARAM3);