2 * PowerPC emulation micro-operations for qemu.
4 * Copyright (c) 2003-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
27 #define Ts0 (int32_t)T0
28 #define Ts1 (int32_t)T1
29 #define Ts2 (int32_t)T2
31 #define FT0 (env->ft0)
32 #define FT1 (env->ft1)
33 #define FT2 (env->ft2)
35 #define PPC_OP(name) void glue(op_, name)(void)
38 #include "op_template.h"
41 #include "op_template.h"
44 #include "op_template.h"
47 #include "op_template.h"
50 #include "op_template.h"
53 #include "op_template.h"
56 #include "op_template.h"
59 #include "op_template.h"
62 #include "op_template.h"
65 #include "op_template.h"
68 #include "op_template.h"
71 #include "op_template.h"
74 #include "op_template.h"
77 #include "op_template.h"
80 #include "op_template.h"
83 #include "op_template.h"
86 #include "op_template.h"
89 #include "op_template.h"
92 #include "op_template.h"
95 #include "op_template.h"
98 #include "op_template.h"
101 #include "op_template.h"
104 #include "op_template.h"
107 #include "op_template.h"
110 #include "op_template.h"
113 #include "op_template.h"
116 #include "op_template.h"
119 #include "op_template.h"
122 #include "op_template.h"
125 #include "op_template.h"
128 #include "op_template.h"
131 #include "op_template.h"
133 /* PowerPC state maintenance operations */
141 } else if (Ts0
> 0) {
154 env
->crf
[0] = 0x02 | xer_ov
;
161 env
->crf
[0] = 0x04 | xer_ov
;
165 /* Set Rc1 (for floating point arithmetic) */
168 env
->crf
[1] = regs
->fpscr
[7];
191 /* Generate exceptions */
192 PPC_OP(raise_exception_err
)
194 do_raise_exception_err(PARAM(1), PARAM(2));
197 PPC_OP(raise_exception
)
199 do_raise_exception(PARAM(1));
209 do_raise_exception(EXCP_DEBUG
);
212 /* Segment registers load and store with immediate index */
215 T0
= regs
->sr
[T1
>> 28];
221 do_store_sr(env
, ((uint32_t)T1
>> 28), T0
);
233 do_store_sdr1(env
, T0
);
242 /* Load/store special registers */
245 T0
= do_load_cr(env
);
251 do_store_cr(env
, T0
, PARAM(1));
257 T0
= (xer_so
<< 3) | (xer_ov
<< 2) | (xer_ca
<< 1);
277 T0
= do_load_xer(env
);
283 do_store_xer(env
, T0
);
289 T0
= do_load_msr(env
);
295 do_store_msr(env
, T0
);
302 T0
= regs
->spr
[PARAM(1)];
308 regs
->spr
[PARAM(1)] = T0
;
338 T0
= cpu_ppc_load_tbl(regs
);
344 T0
= cpu_ppc_load_tbu(regs
);
350 cpu_ppc_store_tbl(regs
, T0
);
356 cpu_ppc_store_tbu(regs
, T0
);
362 T0
= cpu_ppc_load_decr(regs
);
367 cpu_ppc_store_decr(regs
, T0
);
373 T0
= regs
->IBAT
[PARAM(1)][PARAM(2)];
376 void op_store_ibatu (void)
378 do_store_ibatu(env
, PARAM1
, T0
);
382 void op_store_ibatl (void)
385 env
->IBAT
[1][PARAM1
] = T0
;
387 do_store_ibatl(env
, PARAM1
, T0
);
394 T0
= regs
->DBAT
[PARAM(1)][PARAM(2)];
397 void op_store_dbatu (void)
399 do_store_dbatu(env
, PARAM1
, T0
);
403 void op_store_dbatl (void)
406 env
->DBAT
[1][PARAM1
] = T0
;
408 do_store_dbatl(env
, PARAM1
, T0
);
416 FT0
= do_load_fpscr(env
);
422 do_store_fpscr(env
, FT0
, PARAM1
);
428 regs
->fpscr
[7] &= ~0x8;
435 T0
= (T0
>> PARAM(1)) & 1;
441 T1
= (T1
>> PARAM(1)) & 1;
447 T1
= (T1
& PARAM(1)) | (T0
<< PARAM(2));
452 #define EIP regs->nip
461 GOTO_TB(op_goto_tb0
, PARAM1
, 0);
466 GOTO_TB(op_goto_tb1
, PARAM1
, 1);
501 /* tests with result in T0 */
508 PPC_OP(test_ctr_true
)
510 T0
= (regs
->ctr
!= 0 && (T0
& PARAM(1)) != 0);
513 PPC_OP(test_ctr_false
)
515 T0
= (regs
->ctr
!= 0 && (T0
& PARAM(1)) == 0);
520 T0
= (regs
->ctr
== 0);
523 PPC_OP(test_ctrz_true
)
525 T0
= (regs
->ctr
== 0 && (T0
& PARAM(1)) != 0);
528 PPC_OP(test_ctrz_false
)
530 T0
= (regs
->ctr
== 0 && (T0
& PARAM(1)) == 0);
535 T0
= (T0
& PARAM(1));
540 T0
= ((T0
& PARAM(1)) == 0);
543 /* CTR maintenance */
550 /*** Integer arithmetic ***/
578 void do_addco (void);
592 void do_addeo (void);
606 /* add immediate carrying */
619 /* add to minus one extended */
629 void do_addmeo (void);
630 void op_addmeo (void)
636 /* add to zero extended */
649 void do_addzeo (void);
650 void op_addzeo (void)
659 if ((Ts0
== INT32_MIN
&& Ts1
== -1) || Ts1
== 0) {
660 T0
= (int32_t)((-1) * (T0
>> 31));
667 void do_divwo (void);
674 /* divide word unsigned */
685 void do_divwuo (void);
686 void op_divwuo (void)
692 /* multiply high word */
695 T0
= ((int64_t)Ts0
* (int64_t)Ts1
) >> 32;
699 /* multiply high word unsigned */
702 T0
= ((uint64_t)T0
* (uint64_t)T1
) >> 32;
706 /* multiply low immediate */
709 T0
= (Ts0
* SPARAM(1));
713 /* multiply low word */
720 void do_mullwo (void);
721 void op_mullwo (void)
730 if (T0
!= 0x80000000) {
750 void do_subfo (void);
757 /* substract from carrying */
769 void do_subfco (void);
770 void op_subfco (void)
776 /* substract from extended */
777 void do_subfe (void);
784 void do_subfeo (void);
791 /* substract from immediate carrying */
794 T0
= PARAM(1) + ~T0
+ 1;
795 if (T0
<= PARAM(1)) {
803 /* substract from minus one extended */
806 T0
= ~T0
+ xer_ca
- 1;
813 void do_subfmeo (void);
814 void op_subfmeo (void)
820 /* substract from zero extended */
833 void do_subfzeo (void);
834 void op_subfzeo (void)
840 /*** Integer comparison ***/
846 } else if (Ts0
> Ts1
) {
854 /* compare immediate */
857 if (Ts0
< SPARAM(1)) {
859 } else if (Ts0
> SPARAM(1)) {
867 /* compare logical */
872 } else if (T0
> T1
) {
880 /* compare logical immediate */
885 } else if (T0
> PARAM(1)) {
893 /*** Integer logical ***/
915 /* count leading zero */
919 for (T0
= 32; T1
> 0; T0
--)
931 /* extend sign byte */
934 T0
= (int32_t)((int8_t)(Ts0
));
938 /* extend sign half word */
941 T0
= (int32_t)((int16_t)(Ts0
));
994 /*** Integer rotate ***/
995 /* rotate left word immediate then mask insert */
998 T0
= (rotl(T0
, PARAM(1)) & PARAM(2)) | (T1
& PARAM(3));
1002 /* rotate left immediate then and with mask insert */
1005 T0
= rotl(T0
, PARAM(1));
1011 T0
= T0
<< PARAM(1);
1017 T0
= T0
>> PARAM(1);
1021 /* rotate left word then and with mask insert */
1024 T0
= rotl(T0
, PARAM(1)) & PARAM(2);
1036 T0
= rotl(T0
, T1
) & PARAM(1);
1040 /*** Integer shift ***/
1041 /* shift left word */
1052 /* shift right algebraic word */
1059 /* shift right algebraic word immediate */
1063 T0
= (Ts0
>> PARAM(1));
1064 if (Ts1
< 0 && (Ts1
& PARAM(2)) != 0) {
1072 /* shift right word */
1083 /*** Floating-Point arithmetic ***/
1108 FT0
= float64_div(FT0
, FT1
, &env
->fp_status
);
1112 /* fsqrt - fsqrt. */
1126 /* frsqrte - frsqrte. */
1140 /*** Floating-Point multiply-and-add ***/
1141 /* fmadd - fmadd. */
1144 FT0
= (FT0
* FT1
) + FT2
;
1148 /* fmsub - fmsub. */
1151 FT0
= (FT0
* FT1
) - FT2
;
1155 /* fnmadd - fnmadd. - fnmadds - fnmadds. */
1162 /* fnmsub - fnmsub. */
1169 /*** Floating-Point round & convert ***/
1177 /* fctiw - fctiw. */
1184 /* fctiwz - fctiwz. */
1192 /*** Floating-Point compare ***/
1207 /*** Floating-point move ***/
1211 FT0
= float64_abs(FT0
);
1218 FT0
= float64_abs(FT0
);
1219 FT0
= float64_chs(FT0
);
1226 FT0
= float64_chs(FT0
);
1230 /* Load and store */
1231 #define MEMSUFFIX _raw
1233 #if !defined(CONFIG_USER_ONLY)
1234 #define MEMSUFFIX _user
1237 #define MEMSUFFIX _kernel
1241 /* Special op to check and maybe clear reservation */
1242 PPC_OP(check_reservation
)
1244 if ((uint32_t)env
->reserve
== (uint32_t)(T0
& ~0x00000003))
1249 /* Return from interrupt */
1258 void do_tw (uint32_t cmp
, int flags
);
1261 do_tw(T1
, PARAM(1));
1267 do_tw(PARAM(1), PARAM(2));
1271 /* Instruction cache block invalidate */
1292 void op_store_pir (void)
1294 env
->spr
[SPR_PIR
] = T0
& 0x0000000FUL
;