2 * PowerPC emulation micro-operations for qemu.
4 * Copyright (c) 2003-2007 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 #include "op_helper.h"
27 /* XXX: this is to be suppressed */
30 #define FT0 (env->ft0)
31 #define FT1 (env->ft1)
32 #define FT2 (env->ft2)
34 /* XXX: this is to be suppressed... */
35 #define PPC_OP(name) void OPPROTO 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 */
137 env
->crf
[0] = T0
| xer_ov
;
141 /* Set Rc1 (for floating point arithmetic) */
144 env
->crf
[1] = regs
->fpscr
[7];
149 void OPPROTO
op_reset_T0 (void)
157 T0
= (uint32_t)PARAM1
;
161 #if defined(TARGET_PPC64)
162 void OPPROTO
op_set_T0_64 (void)
164 T0
= ((uint64_t)PARAM1
<< 32) | (uint64_t)PARAM2
;
171 T1
= (uint32_t)PARAM1
;
175 #if defined(TARGET_PPC64)
176 void OPPROTO
op_set_T1_64 (void)
178 T1
= ((uint64_t)PARAM1
<< 32) | (uint64_t)PARAM2
;
191 void OPPROTO
op_move_T1_T0 (void)
197 void OPPROTO
op_move_T2_T0 (void)
203 /* Generate exceptions */
204 PPC_OP(raise_exception_err
)
206 do_raise_exception_err(PARAM(1), PARAM(2));
211 env
->nip
= (uint32_t)PARAM1
;
215 #if defined(TARGET_PPC64)
216 void OPPROTO
op_update_nip_64 (void)
218 env
->nip
= ((uint64_t)PARAM1
<< 32) | (uint64_t)PARAM2
;
225 do_raise_exception(EXCP_DEBUG
);
233 /* Load/store special registers */
242 do_store_cr(PARAM(1));
246 void OPPROTO
op_load_cro (void)
248 T0
= env
->crf
[PARAM1
];
252 void OPPROTO
op_store_cro (void)
254 env
->crf
[PARAM1
] = T0
;
260 T0
= (xer_so
<< 3) | (xer_ov
<< 2) | (xer_ca
<< 1);
283 void OPPROTO
op_store_xer_bc (void)
301 #if !defined(CONFIG_USER_ONLY)
302 /* Segment registers load and store */
311 do_store_sr(env
, T1
, T0
);
323 do_store_sdr1(env
, T0
);
327 #if defined (TARGET_PPC64)
328 void OPPROTO
op_load_asr (void)
334 void OPPROTO
op_store_asr (void)
336 ppc_store_asr(env
, T0
);
343 T0
= do_load_msr(env
);
349 do_store_msr(env
, T0
);
353 #if defined (TARGET_PPC64)
354 void OPPROTO
op_store_msr_32 (void)
356 ppc_store_msr_32(env
, T0
);
365 T0
= regs
->spr
[PARAM(1)];
371 regs
->spr
[PARAM(1)] = T0
;
401 T0
= cpu_ppc_load_tbl(regs
);
407 T0
= cpu_ppc_load_tbu(regs
);
411 #if !defined(CONFIG_USER_ONLY)
414 cpu_ppc_store_tbl(regs
, T0
);
420 cpu_ppc_store_tbu(regs
, T0
);
426 T0
= cpu_ppc_load_decr(regs
);
432 cpu_ppc_store_decr(regs
, T0
);
438 T0
= regs
->IBAT
[PARAM(1)][PARAM(2)];
442 void OPPROTO
op_store_ibatu (void)
444 do_store_ibatu(env
, PARAM1
, T0
);
448 void OPPROTO
op_store_ibatl (void)
451 env
->IBAT
[1][PARAM1
] = T0
;
453 do_store_ibatl(env
, PARAM1
, T0
);
460 T0
= regs
->DBAT
[PARAM(1)][PARAM(2)];
464 void OPPROTO
op_store_dbatu (void)
466 do_store_dbatu(env
, PARAM1
, T0
);
470 void OPPROTO
op_store_dbatl (void)
473 env
->DBAT
[1][PARAM1
] = T0
;
475 do_store_dbatl(env
, PARAM1
, T0
);
479 #endif /* !defined(CONFIG_USER_ONLY) */
490 do_store_fpscr(PARAM1
);
496 regs
->fpscr
[7] &= ~0x8;
503 T0
= (T0
>> PARAM(1)) & 1;
509 T1
= (T1
>> PARAM(1)) & 1;
515 T1
= (T1
& PARAM(1)) | (T0
<< PARAM(2));
520 #define EIP regs->nip
524 regs
->lr
= (uint32_t)PARAM1
;
528 #if defined (TARGET_PPC64)
529 void OPPROTO
op_setlr_64 (void)
531 regs
->lr
= ((uint64_t)PARAM1
<< 32) | (uint64_t)PARAM2
;
538 GOTO_TB(op_goto_tb0
, PARAM1
, 0);
543 GOTO_TB(op_goto_tb1
, PARAM1
, 1);
546 void OPPROTO
op_b_T1 (void)
548 regs
->nip
= (uint32_t)(T1
& ~3);
552 #if defined (TARGET_PPC64)
553 void OPPROTO
op_b_T1_64 (void)
555 regs
->nip
= (uint64_t)(T1
& ~3);
567 void OPPROTO
op_btest_T1 (void)
570 regs
->nip
= (uint32_t)(T1
& ~3);
572 regs
->nip
= (uint32_t)PARAM1
;
577 #if defined (TARGET_PPC64)
578 void OPPROTO
op_btest_T1_64 (void)
581 regs
->nip
= (uint64_t)(T1
& ~3);
583 regs
->nip
= ((uint64_t)PARAM1
<< 32) | (uint64_t)PARAM2
;
601 /* tests with result in T0 */
602 void OPPROTO
op_test_ctr (void)
604 T0
= (uint32_t)regs
->ctr
;
608 #if defined(TARGET_PPC64)
609 void OPPROTO
op_test_ctr_64 (void)
611 T0
= (uint64_t)regs
->ctr
;
616 void OPPROTO
op_test_ctr_true (void)
618 T0
= ((uint32_t)regs
->ctr
!= 0 && (T0
& PARAM1
) != 0);
622 #if defined(TARGET_PPC64)
623 void OPPROTO
op_test_ctr_true_64 (void)
625 T0
= ((uint64_t)regs
->ctr
!= 0 && (T0
& PARAM1
) != 0);
630 void OPPROTO
op_test_ctr_false (void)
632 T0
= ((uint32_t)regs
->ctr
!= 0 && (T0
& PARAM1
) == 0);
636 #if defined(TARGET_PPC64)
637 void OPPROTO
op_test_ctr_false_64 (void)
639 T0
= ((uint64_t)regs
->ctr
!= 0 && (T0
& PARAM1
) == 0);
644 void OPPROTO
op_test_ctrz (void)
646 T0
= ((uint32_t)regs
->ctr
== 0);
650 #if defined(TARGET_PPC64)
651 void OPPROTO
op_test_ctrz_64 (void)
653 T0
= ((uint64_t)regs
->ctr
== 0);
658 void OPPROTO
op_test_ctrz_true (void)
660 T0
= ((uint32_t)regs
->ctr
== 0 && (T0
& PARAM1
) != 0);
664 #if defined(TARGET_PPC64)
665 void OPPROTO
op_test_ctrz_true_64 (void)
667 T0
= ((uint64_t)regs
->ctr
== 0 && (T0
& PARAM1
) != 0);
672 void OPPROTO
op_test_ctrz_false (void)
674 T0
= ((uint32_t)regs
->ctr
== 0 && (T0
& PARAM1
) == 0);
678 #if defined(TARGET_PPC64)
679 void OPPROTO
op_test_ctrz_false_64 (void)
681 T0
= ((uint64_t)regs
->ctr
== 0 && (T0
& PARAM1
) == 0);
688 T0
= (T0
& PARAM(1));
694 T0
= ((T0
& PARAM(1)) == 0);
698 /* CTR maintenance */
705 /*** Integer arithmetic ***/
713 void OPPROTO
op_check_addo (void)
715 if (likely(!(((uint32_t)T2
^ (uint32_t)T1
^ UINT32_MAX
) &
716 ((uint32_t)T2
^ (uint32_t)T0
) & (1UL << 31)))) {
725 #if defined(TARGET_PPC64)
726 void OPPROTO
op_check_addo_64 (void)
728 if (likely(!(((uint64_t)T2
^ (uint64_t)T1
^ UINT64_MAX
) &
729 ((uint64_t)T2
^ (uint64_t)T0
) & (1ULL << 63)))) {
740 void OPPROTO
op_check_addc (void)
742 if (likely((uint32_t)T0
>= (uint32_t)T2
)) {
750 #if defined(TARGET_PPC64)
751 void OPPROTO
op_check_addc_64 (void)
753 if (likely((uint64_t)T0
>= (uint64_t)T2
)) {
763 void OPPROTO
op_adde (void)
769 #if defined(TARGET_PPC64)
770 void OPPROTO
op_adde_64 (void)
784 /* add to minus one extended */
785 void OPPROTO
op_add_me (void)
788 if (likely((uint32_t)T1
!= 0))
793 #if defined(TARGET_PPC64)
794 void OPPROTO
op_add_me_64 (void)
797 if (likely((uint64_t)T1
!= 0))
803 void OPPROTO
op_addmeo (void)
809 void OPPROTO
op_addmeo_64 (void)
815 /* add to zero extended */
816 void OPPROTO
op_add_ze (void)
823 void OPPROTO
op_divw (void)
825 if (unlikely(((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== -1) ||
827 T0
= (int32_t)((-1) * ((uint32_t)T0
>> 31));
829 T0
= (int32_t)T0
/ (int32_t)T1
;
834 #if defined(TARGET_PPC64)
835 void OPPROTO
op_divd (void)
837 if (unlikely(((int64_t)T0
== INT64_MIN
&& (int64_t)T1
== -1) ||
839 T0
= (int64_t)((-1ULL) * ((uint64_t)T0
>> 63));
841 T0
= (int64_t)T0
/ (int64_t)T1
;
847 void OPPROTO
op_divwo (void)
853 #if defined(TARGET_PPC64)
854 void OPPROTO
op_divdo (void)
861 /* divide word unsigned */
862 void OPPROTO
op_divwu (void)
864 if (unlikely(T1
== 0)) {
867 T0
= (uint32_t)T0
/ (uint32_t)T1
;
872 #if defined(TARGET_PPC64)
873 void OPPROTO
op_divdu (void)
875 if (unlikely(T1
== 0)) {
884 void OPPROTO
op_divwuo (void)
890 #if defined(TARGET_PPC64)
891 void OPPROTO
op_divduo (void)
898 /* multiply high word */
899 void OPPROTO
op_mulhw (void)
901 T0
= ((int64_t)((int32_t)T0
) * (int64_t)((int32_t)T1
)) >> 32;
905 #if defined(TARGET_PPC64)
906 void OPPROTO
op_mulhd (void)
916 /* multiply high word unsigned */
917 void OPPROTO
op_mulhwu (void)
919 T0
= ((uint64_t)(uint32_t)T0
* (uint64_t)(uint32_t)T1
) >> 32;
923 #if defined(TARGET_PPC64)
924 void OPPROTO
op_mulhdu (void)
934 /* multiply low immediate */
937 T0
= ((int32_t)T0
* (int32_t)PARAM1
);
941 /* multiply low word */
944 T0
= (int32_t)(T0
* T1
);
948 #if defined(TARGET_PPC64)
949 void OPPROTO
op_mulld (void)
956 void OPPROTO
op_mullwo (void)
962 #if defined(TARGET_PPC64)
963 void OPPROTO
op_mulldo (void)
971 void OPPROTO
op_neg (void)
973 if (likely(T0
!= INT32_MIN
)) {
979 #if defined(TARGET_PPC64)
980 void OPPROTO
op_neg_64 (void)
982 if (likely(T0
!= INT64_MIN
)) {
989 void OPPROTO
op_nego (void)
995 #if defined(TARGET_PPC64)
996 void OPPROTO
op_nego_64 (void)
1003 /* substract from */
1010 void OPPROTO
op_check_subfo (void)
1012 if (likely(!(((uint32_t)(~T2
) ^ (uint32_t)T1
^ UINT32_MAX
) &
1013 ((uint32_t)(~T2
) ^ (uint32_t)T0
) & (1UL << 31)))) {
1022 #if defined(TARGET_PPC64)
1023 void OPPROTO
op_check_subfo_64 (void)
1025 if (likely(!(((uint64_t)(~T2
) ^ (uint64_t)T1
^ UINT64_MAX
) &
1026 ((uint64_t)(~T2
) ^ (uint64_t)T0
) & (1ULL << 63)))) {
1036 /* substract from carrying */
1037 void OPPROTO
op_check_subfc (void)
1039 if (likely((uint32_t)T0
> (uint32_t)T1
)) {
1047 #if defined(TARGET_PPC64)
1048 void OPPROTO
op_check_subfc_64 (void)
1050 if (likely((uint64_t)T0
> (uint64_t)T1
)) {
1059 /* substract from extended */
1060 void OPPROTO
op_subfe (void)
1066 #if defined(TARGET_PPC64)
1067 void OPPROTO
op_subfe_64 (void)
1074 /* substract from immediate carrying */
1075 void OPPROTO
op_subfic (void)
1077 T0
= PARAM1
+ ~T0
+ 1;
1078 if ((uint32_t)T0
<= (uint32_t)PARAM1
) {
1086 #if defined(TARGET_PPC64)
1087 void OPPROTO
op_subfic_64 (void)
1089 T0
= PARAM1
+ ~T0
+ 1;
1090 if ((uint64_t)T0
<= (uint64_t)PARAM1
) {
1099 /* substract from minus one extended */
1100 void OPPROTO
op_subfme (void)
1102 T0
= ~T0
+ xer_ca
- 1;
1103 if (likely((uint32_t)T0
!= (uint32_t)-1))
1108 #if defined(TARGET_PPC64)
1109 void OPPROTO
op_subfme_64 (void)
1111 T0
= ~T0
+ xer_ca
- 1;
1112 if (likely((uint64_t)T0
!= (uint64_t)-1))
1118 void OPPROTO
op_subfmeo (void)
1124 #if defined(TARGET_PPC64)
1125 void OPPROTO
op_subfmeo_64 (void)
1132 /* substract from zero extended */
1133 void OPPROTO
op_subfze (void)
1137 if ((uint32_t)T0
< (uint32_t)T1
) {
1145 #if defined(TARGET_PPC64)
1146 void OPPROTO
op_subfze_64 (void)
1150 if ((uint64_t)T0
< (uint64_t)T1
) {
1159 void OPPROTO
op_subfzeo (void)
1165 #if defined(TARGET_PPC64)
1166 void OPPROTO
op_subfzeo_64 (void)
1173 /*** Integer comparison ***/
1175 void OPPROTO
op_cmp (void)
1177 if ((int32_t)T0
< (int32_t)T1
) {
1179 } else if ((int32_t)T0
> (int32_t)T1
) {
1187 #if defined(TARGET_PPC64)
1188 void OPPROTO
op_cmp_64 (void)
1190 if ((int64_t)T0
< (int64_t)T1
) {
1192 } else if ((int64_t)T0
> (int64_t)T1
) {
1201 /* compare immediate */
1202 void OPPROTO
op_cmpi (void)
1204 if ((int32_t)T0
< (int32_t)PARAM1
) {
1206 } else if ((int32_t)T0
> (int32_t)PARAM1
) {
1214 #if defined(TARGET_PPC64)
1215 void OPPROTO
op_cmpi_64 (void)
1217 if ((int64_t)T0
< (int64_t)((int32_t)PARAM1
)) {
1219 } else if ((int64_t)T0
> (int64_t)((int32_t)PARAM1
)) {
1228 /* compare logical */
1229 void OPPROTO
op_cmpl (void)
1231 if ((uint32_t)T0
< (uint32_t)T1
) {
1233 } else if ((uint32_t)T0
> (uint32_t)T1
) {
1241 #if defined(TARGET_PPC64)
1242 void OPPROTO
op_cmpl_64 (void)
1244 if ((uint64_t)T0
< (uint64_t)T1
) {
1246 } else if ((uint64_t)T0
> (uint64_t)T1
) {
1255 /* compare logical immediate */
1256 void OPPROTO
op_cmpli (void)
1258 if ((uint32_t)T0
< (uint32_t)PARAM1
) {
1260 } else if ((uint32_t)T0
> (uint32_t)PARAM1
) {
1268 #if defined(TARGET_PPC64)
1269 void OPPROTO
op_cmpli_64 (void)
1271 if ((uint64_t)T0
< (uint64_t)PARAM1
) {
1273 } else if ((uint64_t)T0
> (uint64_t)PARAM1
) {
1282 void OPPROTO
op_isel (void)
1291 void OPPROTO
op_popcntb (void)
1297 #if defined(TARGET_PPC64)
1298 void OPPROTO
op_popcntb_64 (void)
1305 /*** Integer logical ***/
1321 void OPPROTO
op_andi_T0 (void)
1327 void OPPROTO
op_andi_T1 (void)
1333 /* count leading zero */
1334 void OPPROTO
op_cntlzw (void)
1336 T0
= _do_cntlzw(T0
);
1340 #if defined(TARGET_PPC64)
1341 void OPPROTO
op_cntlzd (void)
1343 T0
= _do_cntlzd(T0
);
1355 /* extend sign byte */
1356 void OPPROTO
op_extsb (void)
1358 #if defined (TARGET_PPC64)
1359 T0
= (int64_t)((int8_t)T0
);
1361 T0
= (int32_t)((int8_t)T0
);
1366 /* extend sign half word */
1367 void OPPROTO
op_extsh (void)
1369 #if defined (TARGET_PPC64)
1370 T0
= (int64_t)((int16_t)T0
);
1372 T0
= (int32_t)((int16_t)T0
);
1377 #if defined (TARGET_PPC64)
1378 void OPPROTO
op_extsw (void)
1380 T0
= (int64_t)((int32_t)T0
);
1434 /*** Integer rotate ***/
1435 void OPPROTO
op_rotl32_T0_T1 (void)
1437 T0
= rotl32(T0
, T1
& 0x1F);
1441 void OPPROTO
op_rotli32_T0 (void)
1443 T0
= rotl32(T0
, PARAM1
);
1447 #if defined(TARGET_PPC64)
1448 void OPPROTO
op_rotl64_T0_T1 (void)
1450 T0
= rotl64(T0
, T1
& 0x3F);
1454 void OPPROTO
op_rotli64_T0 (void)
1456 T0
= rotl64(T0
, PARAM1
);
1461 /*** Integer shift ***/
1462 /* shift left word */
1463 void OPPROTO
op_slw (void)
1468 T0
= (uint32_t)(T0
<< T1
);
1473 #if defined(TARGET_PPC64)
1474 void OPPROTO
op_sld (void)
1485 /* shift right algebraic word */
1486 void OPPROTO
op_sraw (void)
1492 #if defined(TARGET_PPC64)
1493 void OPPROTO
op_srad (void)
1500 /* shift right algebraic word immediate */
1501 void OPPROTO
op_srawi (void)
1503 uint32_t mask
= (uint32_t)PARAM2
;
1505 T0
= (int32_t)T0
>> PARAM1
;
1506 if ((int32_t)T1
< 0 && (T1
& mask
) != 0) {
1514 #if defined(TARGET_PPC64)
1515 void OPPROTO
op_sradi (void)
1517 uint64_t mask
= ((uint64_t)PARAM2
<< 32) | (uint64_t)PARAM3
;
1519 T0
= (int64_t)T0
>> PARAM1
;
1520 if ((int64_t)T1
< 0 && ((uint64_t)T1
& mask
) != 0) {
1529 /* shift right word */
1530 void OPPROTO
op_srw (void)
1535 T0
= (uint32_t)T0
>> T1
;
1540 #if defined(TARGET_PPC64)
1541 void OPPROTO
op_srd (void)
1546 T0
= (uint64_t)T0
>> T1
;
1552 void OPPROTO
op_sl_T0_T1 (void)
1558 void OPPROTO
op_sli_T0 (void)
1564 void OPPROTO
op_srl_T0_T1 (void)
1566 T0
= (uint32_t)T0
>> T1
;
1570 #if defined(TARGET_PPC64)
1571 void OPPROTO
op_srl_T0_T1_64 (void)
1573 T0
= (uint32_t)T0
>> T1
;
1578 void OPPROTO
op_srli_T0 (void)
1580 T0
= (uint32_t)T0
>> PARAM1
;
1584 #if defined(TARGET_PPC64)
1585 void OPPROTO
op_srli_T0_64 (void)
1587 T0
= (uint64_t)T0
>> PARAM1
;
1592 void OPPROTO
op_srli_T1 (void)
1594 T1
= (uint32_t)T1
>> PARAM1
;
1598 #if defined(TARGET_PPC64)
1599 void OPPROTO
op_srli_T1_64 (void)
1601 T1
= (uint64_t)T1
>> PARAM1
;
1606 /*** Floating-Point arithmetic ***/
1610 FT0
= float64_add(FT0
, FT1
, &env
->fp_status
);
1617 FT0
= float64_sub(FT0
, FT1
, &env
->fp_status
);
1624 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1631 FT0
= float64_div(FT0
, FT1
, &env
->fp_status
);
1635 /* fsqrt - fsqrt. */
1649 /* frsqrte - frsqrte. */
1663 /*** Floating-Point multiply-and-add ***/
1664 /* fmadd - fmadd. */
1667 #if USE_PRECISE_EMULATION
1670 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1671 FT0
= float64_add(FT0
, FT2
, &env
->fp_status
);
1676 /* fmsub - fmsub. */
1679 #if USE_PRECISE_EMULATION
1682 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1683 FT0
= float64_sub(FT0
, FT2
, &env
->fp_status
);
1688 /* fnmadd - fnmadd. - fnmadds - fnmadds. */
1695 /* fnmsub - fnmsub. */
1702 /*** Floating-Point round & convert ***/
1706 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1710 /* fctiw - fctiw. */
1717 /* fctiwz - fctiwz. */
1724 #if defined(TARGET_PPC64)
1725 /* fcfid - fcfid. */
1732 /* fctid - fctid. */
1739 /* fctidz - fctidz. */
1747 /*** Floating-Point compare ***/
1762 /*** Floating-point move ***/
1766 FT0
= float64_abs(FT0
);
1773 FT0
= float64_abs(FT0
);
1774 FT0
= float64_chs(FT0
);
1781 FT0
= float64_chs(FT0
);
1785 /* Load and store */
1786 #define MEMSUFFIX _raw
1787 #include "op_helper.h"
1789 #if !defined(CONFIG_USER_ONLY)
1790 #define MEMSUFFIX _user
1791 #include "op_helper.h"
1793 #define MEMSUFFIX _kernel
1794 #include "op_helper.h"
1798 /* Special op to check and maybe clear reservation */
1799 void OPPROTO
op_check_reservation (void)
1801 if ((uint32_t)env
->reserve
== (uint32_t)(T0
& ~0x00000003))
1806 #if defined(TARGET_PPC64)
1807 void OPPROTO
op_check_reservation_64 (void)
1809 if ((uint64_t)env
->reserve
== (uint64_t)(T0
& ~0x00000003))
1815 /* Return from interrupt */
1816 #if !defined(CONFIG_USER_ONLY)
1817 void OPPROTO
op_rfi (void)
1823 #if defined(TARGET_PPC64)
1824 void OPPROTO
op_rfid (void)
1833 void OPPROTO
op_tw (void)
1839 #if defined(TARGET_PPC64)
1840 void OPPROTO
op_td (void)
1847 #if !defined(CONFIG_USER_ONLY)
1856 void OPPROTO
op_tlbie (void)
1862 #if defined(TARGET_PPC64)
1863 void OPPROTO
op_tlbie_64 (void)
1870 #if defined(TARGET_PPC64)
1871 void OPPROTO
op_slbia (void)
1877 void OPPROTO
op_slbie (void)
1885 /* PowerPC 602/603/755 software TLB load instructions */
1886 #if !defined(CONFIG_USER_ONLY)
1887 void OPPROTO
op_6xx_tlbld (void)
1893 void OPPROTO
op_6xx_tlbli (void)
1901 void OPPROTO
op_load_601_rtcl (void)
1903 T0
= cpu_ppc601_load_rtcl(env
);
1907 void OPPROTO
op_load_601_rtcu (void)
1909 T0
= cpu_ppc601_load_rtcu(env
);
1913 #if !defined(CONFIG_USER_ONLY)
1914 void OPPROTO
op_store_601_rtcl (void)
1916 cpu_ppc601_store_rtcl(env
, T0
);
1920 void OPPROTO
op_store_601_rtcu (void)
1922 cpu_ppc601_store_rtcu(env
, T0
);
1926 void OPPROTO
op_load_601_bat (void)
1928 T0
= env
->IBAT
[PARAM1
][PARAM2
];
1931 #endif /* !defined(CONFIG_USER_ONLY) */
1933 /* 601 unified BATs store.
1934 * To avoid using specific MMU code for 601, we store BATs in
1935 * IBAT and DBAT simultaneously, then emulate unified BATs.
1937 #if !defined(CONFIG_USER_ONLY)
1938 void OPPROTO
op_store_601_batl (void)
1942 env
->IBAT
[1][nr
] = T0
;
1943 env
->DBAT
[1][nr
] = T0
;
1947 void OPPROTO
op_store_601_batu (void)
1949 do_store_601_batu(PARAM1
);
1952 #endif /* !defined(CONFIG_USER_ONLY) */
1954 /* PowerPC 601 specific instructions (POWER bridge) */
1955 /* XXX: those micro-ops need tests ! */
1956 void OPPROTO
op_POWER_abs (void)
1958 if (T0
== INT32_MIN
)
1965 void OPPROTO
op_POWER_abso (void)
1971 void OPPROTO
op_POWER_clcs (void)
1977 void OPPROTO
op_POWER_div (void)
1983 void OPPROTO
op_POWER_divo (void)
1989 void OPPROTO
op_POWER_divs (void)
1995 void OPPROTO
op_POWER_divso (void)
2001 void OPPROTO
op_POWER_doz (void)
2003 if ((int32_t)T1
> (int32_t)T0
)
2010 void OPPROTO
op_POWER_dozo (void)
2016 void OPPROTO
op_load_xer_cmp (void)
2022 void OPPROTO
op_POWER_maskg (void)
2028 void OPPROTO
op_POWER_maskir (void)
2030 T0
= (T0
& ~T2
) | (T1
& T2
);
2034 void OPPROTO
op_POWER_mul (void)
2038 tmp
= (uint64_t)T0
* (uint64_t)T1
;
2039 env
->spr
[SPR_MQ
] = tmp
>> 32;
2044 void OPPROTO
op_POWER_mulo (void)
2050 void OPPROTO
op_POWER_nabs (void)
2057 void OPPROTO
op_POWER_nabso (void)
2059 /* nabs never overflows */
2066 /* XXX: factorise POWER rotates... */
2067 void OPPROTO
op_POWER_rlmi (void)
2069 T0
= rotl32(T0
, T2
) & PARAM1
;
2074 void OPPROTO
op_POWER_rrib (void)
2077 T0
= rotl32(T0
& INT32_MIN
, T2
);
2078 T0
|= T1
& ~rotl32(INT32_MIN
, T2
);
2082 void OPPROTO
op_POWER_sle (void)
2085 env
->spr
[SPR_MQ
] = rotl32(T0
, T1
);
2090 void OPPROTO
op_POWER_sleq (void)
2092 uint32_t tmp
= env
->spr
[SPR_MQ
];
2095 env
->spr
[SPR_MQ
] = rotl32(T0
, T1
);
2097 T0
|= tmp
>> (32 - T1
);
2101 void OPPROTO
op_POWER_sllq (void)
2105 msk
= msk
<< (T1
& 0x1FUL
);
2109 T0
= (T0
<< T1
) & msk
;
2110 T0
|= env
->spr
[SPR_MQ
] & ~msk
;
2114 void OPPROTO
op_POWER_slq (void)
2116 uint32_t msk
= -1, tmp
;
2118 msk
= msk
<< (T1
& 0x1FUL
);
2122 tmp
= rotl32(T0
, T1
);
2124 env
->spr
[SPR_MQ
] = tmp
;
2128 void OPPROTO
op_POWER_sraq (void)
2130 env
->spr
[SPR_MQ
] = rotl32(T0
, 32 - (T1
& 0x1FUL
));
2134 T0
= (int32_t)T0
>> T1
;
2138 void OPPROTO
op_POWER_sre (void)
2141 env
->spr
[SPR_MQ
] = rotl32(T0
, 32 - T1
);
2142 T0
= (int32_t)T0
>> T1
;
2146 void OPPROTO
op_POWER_srea (void)
2149 env
->spr
[SPR_MQ
] = T0
>> T1
;
2150 T0
= (int32_t)T0
>> T1
;
2154 void OPPROTO
op_POWER_sreq (void)
2160 msk
= INT32_MIN
>> T1
;
2161 tmp
= env
->spr
[SPR_MQ
];
2162 env
->spr
[SPR_MQ
] = rotl32(T0
, 32 - T1
);
2168 void OPPROTO
op_POWER_srlq (void)
2173 msk
= INT32_MIN
>> (T1
& 0x1FUL
);
2177 tmp
= env
->spr
[SPR_MQ
];
2178 env
->spr
[SPR_MQ
] = rotl32(T0
, 32 - T1
);
2185 void OPPROTO
op_POWER_srq (void)
2188 env
->spr
[SPR_MQ
] = rotl32(T0
, 32 - T1
);
2193 /* POWER instructions not implemented in PowerPC 601 */
2194 #if !defined(CONFIG_USER_ONLY)
2195 void OPPROTO
op_POWER_mfsri (void)
2202 void OPPROTO
op_POWER_rac (void)
2208 void OPPROTO
op_POWER_rfsvc (void)
2215 /* PowerPC 602 specific instruction */
2216 #if !defined(CONFIG_USER_ONLY)
2217 void OPPROTO
op_602_mfrom (void)
2224 /* PowerPC 4xx specific micro-ops */
2225 void OPPROTO
op_405_add_T0_T2 (void)
2227 T0
= (int32_t)T0
+ (int32_t)T2
;
2231 void OPPROTO
op_405_mulchw (void)
2233 T0
= ((int16_t)T0
) * ((int16_t)(T1
>> 16));
2237 void OPPROTO
op_405_mulchwu (void)
2239 T0
= ((uint16_t)T0
) * ((uint16_t)(T1
>> 16));
2243 void OPPROTO
op_405_mulhhw (void)
2245 T0
= ((int16_t)(T0
>> 16)) * ((int16_t)(T1
>> 16));
2249 void OPPROTO
op_405_mulhhwu (void)
2251 T0
= ((uint16_t)(T0
>> 16)) * ((uint16_t)(T1
>> 16));
2255 void OPPROTO
op_405_mullhw (void)
2257 T0
= ((int16_t)T0
) * ((int16_t)T1
);
2261 void OPPROTO
op_405_mullhwu (void)
2263 T0
= ((uint16_t)T0
) * ((uint16_t)T1
);
2267 void OPPROTO
op_405_check_ov (void)
2273 void OPPROTO
op_405_check_sat (void)
2279 void OPPROTO
op_405_check_ovu (void)
2281 if (likely(T0
>= T2
)) {
2290 void OPPROTO
op_405_check_satu (void)
2292 if (unlikely(T0
< T2
)) {
2293 /* Saturate result */
2299 #if !defined(CONFIG_USER_ONLY)
2300 void OPPROTO
op_load_dcr (void)
2306 void OPPROTO
op_store_dcr (void)
2312 /* Return from critical interrupt :
2313 * same as rfi, except nip & MSR are loaded from SRR2/3 instead of SRR0/1
2315 void OPPROTO
op_40x_rfci (void)
2321 void OPPROTO
op_rfci (void)
2327 void OPPROTO
op_rfdi (void)
2333 void OPPROTO
op_rfmci (void)
2339 void OPPROTO
op_wrte (void)
2345 void OPPROTO
op_4xx_tlbre_lo (void)
2351 void OPPROTO
op_4xx_tlbre_hi (void)
2357 void OPPROTO
op_4xx_tlbsx (void)
2363 void OPPROTO
op_4xx_tlbsx_ (void)
2369 void OPPROTO
op_4xx_tlbwe_lo (void)
2375 void OPPROTO
op_4xx_tlbwe_hi (void)
2384 void OPPROTO
op_440_dlmzb (void)
2390 void OPPROTO
op_440_dlmzb_update_Rc (void)
2401 #if !defined(CONFIG_USER_ONLY)
2402 void OPPROTO
op_store_pir (void)
2404 env
->spr
[SPR_PIR
] = T0
& 0x0000000FUL
;
2408 void OPPROTO
op_load_403_pb (void)
2410 do_load_403_pb(PARAM1
);
2414 void OPPROTO
op_store_403_pb (void)
2416 do_store_403_pb(PARAM1
);
2420 void OPPROTO
op_load_40x_pit (void)
2422 T0
= load_40x_pit(env
);
2426 void OPPROTO
op_store_40x_pit (void)
2428 store_40x_pit(env
, T0
);
2432 void OPPROTO
op_store_booke_tcr (void)
2434 store_booke_tcr(env
, T0
);
2438 void OPPROTO
op_store_booke_tsr (void)
2440 store_booke_tsr(env
, T0
);
2444 #endif /* !defined(CONFIG_USER_ONLY) */
2446 #if defined(TARGET_PPCSPE)
2448 void OPPROTO
op_splatw_T1_64 (void)
2450 T1_64
= (T1_64
<< 32) | (T1_64
& 0x00000000FFFFFFFFULL
);
2454 void OPPROTO
op_splatwi_T0_64 (void)
2456 uint64_t tmp
= PARAM1
;
2458 T0_64
= (tmp
<< 32) | tmp
;
2462 void OPPROTO
op_splatwi_T1_64 (void)
2464 uint64_t tmp
= PARAM1
;
2466 T1_64
= (tmp
<< 32) | tmp
;
2470 void OPPROTO
op_extsh_T1_64 (void)
2472 T1_64
= (int32_t)((int16_t)T1_64
);
2476 void OPPROTO
op_sli16_T1_64 (void)
2478 T1_64
= T1_64
<< 16;
2482 void OPPROTO
op_sli32_T1_64 (void)
2484 T1_64
= T1_64
<< 32;
2488 void OPPROTO
op_srli32_T1_64 (void)
2490 T1_64
= T1_64
>> 32;
2494 void OPPROTO
op_evsel (void)
2500 void OPPROTO
op_evaddw (void)
2506 void OPPROTO
op_evsubfw (void)
2512 void OPPROTO
op_evneg (void)
2518 void OPPROTO
op_evabs (void)
2524 void OPPROTO
op_evextsh (void)
2526 T0_64
= ((uint64_t)((int32_t)(int16_t)(T0_64
>> 32)) << 32) |
2527 (uint64_t)((int32_t)(int16_t)T0_64
);
2531 void OPPROTO
op_evextsb (void)
2533 T0_64
= ((uint64_t)((int32_t)(int8_t)(T0_64
>> 32)) << 32) |
2534 (uint64_t)((int32_t)(int8_t)T0_64
);
2538 void OPPROTO
op_evcntlzw (void)
2544 void OPPROTO
op_evrndw (void)
2550 void OPPROTO
op_brinc (void)
2556 void OPPROTO
op_evcntlsw (void)
2562 void OPPROTO
op_evand (void)
2568 void OPPROTO
op_evandc (void)
2574 void OPPROTO
op_evor (void)
2580 void OPPROTO
op_evxor (void)
2586 void OPPROTO
op_eveqv (void)
2588 T0_64
= ~(T0_64
^ T1_64
);
2592 void OPPROTO
op_evnor (void)
2594 T0_64
= ~(T0_64
| T1_64
);
2598 void OPPROTO
op_evorc (void)
2604 void OPPROTO
op_evnand (void)
2606 T0_64
= ~(T0_64
& T1_64
);
2610 void OPPROTO
op_evsrws (void)
2616 void OPPROTO
op_evsrwu (void)
2622 void OPPROTO
op_evslw (void)
2628 void OPPROTO
op_evrlw (void)
2634 void OPPROTO
op_evmergelo (void)
2636 T0_64
= (T0_64
<< 32) | (T1_64
& 0x00000000FFFFFFFFULL
);
2640 void OPPROTO
op_evmergehi (void)
2642 T0_64
= (T0_64
& 0xFFFFFFFF00000000ULL
) | (T1_64
>> 32);
2646 void OPPROTO
op_evmergelohi (void)
2648 T0_64
= (T0_64
<< 32) | (T1_64
>> 32);
2652 void OPPROTO
op_evmergehilo (void)
2654 T0_64
= (T0_64
& 0xFFFFFFFF00000000ULL
) | (T1_64
& 0x00000000FFFFFFFFULL
);
2658 void OPPROTO
op_evcmpgts (void)
2664 void OPPROTO
op_evcmpgtu (void)
2670 void OPPROTO
op_evcmplts (void)
2676 void OPPROTO
op_evcmpltu (void)
2682 void OPPROTO
op_evcmpeq (void)
2688 void OPPROTO
op_evfssub (void)
2694 void OPPROTO
op_evfsadd (void)
2700 void OPPROTO
op_evfsnabs (void)
2706 void OPPROTO
op_evfsabs (void)
2712 void OPPROTO
op_evfsneg (void)
2718 void OPPROTO
op_evfsdiv (void)
2724 void OPPROTO
op_evfsmul (void)
2730 void OPPROTO
op_evfscmplt (void)
2736 void OPPROTO
op_evfscmpgt (void)
2742 void OPPROTO
op_evfscmpeq (void)
2748 void OPPROTO
op_evfscfsi (void)
2754 void OPPROTO
op_evfscfui (void)
2760 void OPPROTO
op_evfscfsf (void)
2766 void OPPROTO
op_evfscfuf (void)
2772 void OPPROTO
op_evfsctsi (void)
2778 void OPPROTO
op_evfsctui (void)
2784 void OPPROTO
op_evfsctsf (void)
2790 void OPPROTO
op_evfsctuf (void)
2796 void OPPROTO
op_evfsctuiz (void)
2802 void OPPROTO
op_evfsctsiz (void)
2808 void OPPROTO
op_evfststlt (void)
2814 void OPPROTO
op_evfststgt (void)
2820 void OPPROTO
op_evfststeq (void)
2826 void OPPROTO
op_efssub (void)
2828 T0_64
= _do_efssub(T0_64
, T1_64
);
2832 void OPPROTO
op_efsadd (void)
2834 T0_64
= _do_efsadd(T0_64
, T1_64
);
2838 void OPPROTO
op_efsnabs (void)
2840 T0_64
= _do_efsnabs(T0_64
);
2844 void OPPROTO
op_efsabs (void)
2846 T0_64
= _do_efsabs(T0_64
);
2850 void OPPROTO
op_efsneg (void)
2852 T0_64
= _do_efsneg(T0_64
);
2856 void OPPROTO
op_efsdiv (void)
2858 T0_64
= _do_efsdiv(T0_64
, T1_64
);
2862 void OPPROTO
op_efsmul (void)
2864 T0_64
= _do_efsmul(T0_64
, T1_64
);
2868 void OPPROTO
op_efscmplt (void)
2874 void OPPROTO
op_efscmpgt (void)
2880 void OPPROTO
op_efscfd (void)
2886 void OPPROTO
op_efscmpeq (void)
2892 void OPPROTO
op_efscfsi (void)
2898 void OPPROTO
op_efscfui (void)
2904 void OPPROTO
op_efscfsf (void)
2910 void OPPROTO
op_efscfuf (void)
2916 void OPPROTO
op_efsctsi (void)
2922 void OPPROTO
op_efsctui (void)
2928 void OPPROTO
op_efsctsf (void)
2934 void OPPROTO
op_efsctuf (void)
2940 void OPPROTO
op_efsctsiz (void)
2946 void OPPROTO
op_efsctuiz (void)
2952 void OPPROTO
op_efststlt (void)
2954 T0
= _do_efststlt(T0_64
, T1_64
);
2958 void OPPROTO
op_efststgt (void)
2960 T0
= _do_efststgt(T0_64
, T1_64
);
2964 void OPPROTO
op_efststeq (void)
2966 T0
= _do_efststeq(T0_64
, T1_64
);
2970 void OPPROTO
op_efdsub (void)
2978 u1
.f
= float64_sub(u1
.f
, u2
.f
, &env
->spe_status
);
2983 void OPPROTO
op_efdadd (void)
2991 u1
.f
= float64_add(u1
.f
, u2
.f
, &env
->spe_status
);
2996 void OPPROTO
op_efdcfsid (void)
3002 void OPPROTO
op_efdcfuid (void)
3008 void OPPROTO
op_efdnabs (void)
3010 T0_64
|= 0x8000000000000000ULL
;
3014 void OPPROTO
op_efdabs (void)
3016 T0_64
&= ~0x8000000000000000ULL
;
3020 void OPPROTO
op_efdneg (void)
3022 T0_64
^= 0x8000000000000000ULL
;
3026 void OPPROTO
op_efddiv (void)
3034 u1
.f
= float64_div(u1
.f
, u2
.f
, &env
->spe_status
);
3039 void OPPROTO
op_efdmul (void)
3047 u1
.f
= float64_mul(u1
.f
, u2
.f
, &env
->spe_status
);
3052 void OPPROTO
op_efdctsidz (void)
3058 void OPPROTO
op_efdctuidz (void)
3064 void OPPROTO
op_efdcmplt (void)
3070 void OPPROTO
op_efdcmpgt (void)
3076 void OPPROTO
op_efdcfs (void)
3082 void OPPROTO
op_efdcmpeq (void)
3088 void OPPROTO
op_efdcfsi (void)
3094 void OPPROTO
op_efdcfui (void)
3100 void OPPROTO
op_efdcfsf (void)
3106 void OPPROTO
op_efdcfuf (void)
3112 void OPPROTO
op_efdctsi (void)
3118 void OPPROTO
op_efdctui (void)
3124 void OPPROTO
op_efdctsf (void)
3130 void OPPROTO
op_efdctuf (void)
3136 void OPPROTO
op_efdctuiz (void)
3142 void OPPROTO
op_efdctsiz (void)
3148 void OPPROTO
op_efdtstlt (void)
3150 T0
= _do_efdtstlt(T0_64
, T1_64
);
3154 void OPPROTO
op_efdtstgt (void)
3156 T0
= _do_efdtstgt(T0_64
, T1_64
);
3160 void OPPROTO
op_efdtsteq (void)
3162 T0
= _do_efdtsteq(T0_64
, T1_64
);
3165 #endif /* defined(TARGET_PPCSPE) */