2 * PowerPC emulation helpers 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
21 #include "host-utils.h"
23 #include "helper_regs.h"
24 #include "op_helper.h"
26 #define MEMSUFFIX _raw
27 #include "op_helper.h"
28 #include "op_helper_mem.h"
29 #if !defined(CONFIG_USER_ONLY)
30 #define MEMSUFFIX _user
31 #include "op_helper.h"
32 #include "op_helper_mem.h"
33 #define MEMSUFFIX _kernel
34 #include "op_helper.h"
35 #include "op_helper_mem.h"
36 #define MEMSUFFIX _hypv
37 #include "op_helper.h"
38 #include "op_helper_mem.h"
42 //#define DEBUG_EXCEPTIONS
43 //#define DEBUG_SOFTWARE_TLB
45 /*****************************************************************************/
46 /* Exceptions processing helpers */
48 void do_raise_exception_err (uint32_t exception
, int error_code
)
51 printf("Raise exception %3x code : %d\n", exception
, error_code
);
53 env
->exception_index
= exception
;
54 env
->error_code
= error_code
;
58 void do_raise_exception (uint32_t exception
)
60 do_raise_exception_err(exception
, 0);
63 /*****************************************************************************/
64 /* Registers load and stores */
65 void do_load_cr (void)
67 T0
= (env
->crf
[0] << 28) |
77 void do_store_cr (uint32_t mask
)
81 for (i
= 0, sh
= 7; i
< 8; i
++, sh
--) {
83 env
->crf
[i
] = (T0
>> (sh
* 4)) & 0xFUL
;
87 #if defined(TARGET_PPC64)
88 void do_store_pri (int prio
)
90 env
->spr
[SPR_PPR
] &= ~0x001C000000000000ULL
;
91 env
->spr
[SPR_PPR
] |= ((uint64_t)prio
& 0x7) << 50;
95 target_ulong
ppc_load_dump_spr (int sprn
)
98 fprintf(logfile
, "Read SPR %d %03x => " ADDRX
"\n",
99 sprn
, sprn
, env
->spr
[sprn
]);
102 return env
->spr
[sprn
];
105 void ppc_store_dump_spr (int sprn
, target_ulong val
)
108 fprintf(logfile
, "Write SPR %d %03x => " ADDRX
" <= " ADDRX
"\n",
109 sprn
, sprn
, env
->spr
[sprn
], val
);
111 env
->spr
[sprn
] = val
;
114 /*****************************************************************************/
115 /* Fixed point operations helpers */
120 if (likely(!((uint32_t)T0
< (uint32_t)T2
||
121 (xer_ca
== 1 && (uint32_t)T0
== (uint32_t)T2
)))) {
122 env
->xer
&= ~(1 << XER_CA
);
124 env
->xer
|= (1 << XER_CA
);
128 #if defined(TARGET_PPC64)
129 void do_adde_64 (void)
133 if (likely(!((uint64_t)T0
< (uint64_t)T2
||
134 (xer_ca
== 1 && (uint64_t)T0
== (uint64_t)T2
)))) {
135 env
->xer
&= ~(1 << XER_CA
);
137 env
->xer
|= (1 << XER_CA
);
142 void do_addmeo (void)
147 ov
= ((uint32_t)T1
& ((uint32_t)T1
^ (uint32_t)T0
)) >> 31;
149 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
151 env
->xer
&= ~(1 << XER_OV
);
153 if (likely((uint32_t)T1
!= 0))
154 env
->xer
|= (1 << XER_CA
);
157 #if defined(TARGET_PPC64)
158 void do_addmeo_64 (void)
163 ov
= ((uint64_t)T1
& ((uint64_t)T1
^ (uint64_t)T0
)) >> 63;
165 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
167 env
->xer
&= ~(1 << XER_OV
);
169 if (likely((uint64_t)T1
!= 0))
170 env
->xer
|= (1 << XER_CA
);
176 if (likely(!(((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
177 (int32_t)T1
== 0))) {
178 env
->xer
&= ~(1 << XER_OV
);
179 T0
= (int32_t)T0
/ (int32_t)T1
;
181 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
182 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
186 #if defined(TARGET_PPC64)
189 if (likely(!(((int64_t)T0
== INT64_MIN
&& (int64_t)T1
== (int64_t)-1LL) ||
190 (int64_t)T1
== 0))) {
191 env
->xer
&= ~(1 << XER_OV
);
192 T0
= (int64_t)T0
/ (int64_t)T1
;
194 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
195 T0
= UINT64_MAX
* ((uint64_t)T0
>> 63);
200 void do_divwuo (void)
202 if (likely((uint32_t)T1
!= 0)) {
203 env
->xer
&= ~(1 << XER_OV
);
204 T0
= (uint32_t)T0
/ (uint32_t)T1
;
206 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
211 #if defined(TARGET_PPC64)
212 void do_divduo (void)
214 if (likely((uint64_t)T1
!= 0)) {
215 env
->xer
&= ~(1 << XER_OV
);
216 T0
= (uint64_t)T0
/ (uint64_t)T1
;
218 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
224 void do_mullwo (void)
226 int64_t res
= (int64_t)(int32_t)T0
* (int64_t)(int32_t)T1
;
228 if (likely((int32_t)res
== res
)) {
229 env
->xer
&= ~(1 << XER_OV
);
231 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
236 #if defined(TARGET_PPC64)
237 void do_mulldo (void)
242 muls64(&tl
, (uint64_t *)&th
, T0
, T1
);
244 /* If th != 0 && th != -1, then we had an overflow */
245 if (likely((uint64_t)(th
+ 1) <= 1)) {
246 env
->xer
&= ~(1 << XER_OV
);
248 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
255 if (likely((int32_t)T0
!= INT32_MIN
)) {
256 env
->xer
&= ~(1 << XER_OV
);
259 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
263 #if defined(TARGET_PPC64)
264 void do_nego_64 (void)
266 if (likely((int64_t)T0
!= INT64_MIN
)) {
267 env
->xer
&= ~(1 << XER_OV
);
270 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
277 T0
= T1
+ ~T0
+ xer_ca
;
278 if (likely((uint32_t)T0
>= (uint32_t)T1
&&
279 (xer_ca
== 0 || (uint32_t)T0
!= (uint32_t)T1
))) {
280 env
->xer
&= ~(1 << XER_CA
);
282 env
->xer
|= (1 << XER_CA
);
286 #if defined(TARGET_PPC64)
287 void do_subfe_64 (void)
289 T0
= T1
+ ~T0
+ xer_ca
;
290 if (likely((uint64_t)T0
>= (uint64_t)T1
&&
291 (xer_ca
== 0 || (uint64_t)T0
!= (uint64_t)T1
))) {
292 env
->xer
&= ~(1 << XER_CA
);
294 env
->xer
|= (1 << XER_CA
);
299 void do_subfmeo (void)
303 T0
= ~T0
+ xer_ca
- 1;
304 ov
= ((uint32_t)~T1
& ((uint32_t)~T1
^ (uint32_t)T0
)) >> 31;
306 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
308 env
->xer
&= ~(1 << XER_OV
);
310 if (likely((uint32_t)T1
!= UINT32_MAX
))
311 env
->xer
|= (1 << XER_CA
);
314 #if defined(TARGET_PPC64)
315 void do_subfmeo_64 (void)
319 T0
= ~T0
+ xer_ca
- 1;
320 ov
= ((uint64_t)~T1
& ((uint64_t)~T1
^ (uint64_t)T0
)) >> 63;
322 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
324 env
->xer
&= ~(1 << XER_OV
);
326 if (likely((uint64_t)T1
!= UINT64_MAX
))
327 env
->xer
|= (1 << XER_CA
);
331 void do_subfzeo (void)
336 ov
= (((uint32_t)~T1
^ UINT32_MAX
) &
337 ((uint32_t)(~T1
) ^ (uint32_t)T0
)) >> 31;
339 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
341 env
->xer
&= ~(1 << XER_OV
);
343 if (likely((uint32_t)T0
>= (uint32_t)~T1
)) {
344 env
->xer
&= ~(1 << XER_CA
);
346 env
->xer
|= (1 << XER_CA
);
350 #if defined(TARGET_PPC64)
351 void do_subfzeo_64 (void)
356 ov
= (((uint64_t)~T1
^ UINT64_MAX
) &
357 ((uint64_t)(~T1
) ^ (uint64_t)T0
)) >> 63;
359 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
361 env
->xer
&= ~(1 << XER_OV
);
363 if (likely((uint64_t)T0
>= (uint64_t)~T1
)) {
364 env
->xer
&= ~(1 << XER_CA
);
366 env
->xer
|= (1 << XER_CA
);
371 void do_cntlzw (void)
376 #if defined(TARGET_PPC64)
377 void do_cntlzd (void)
383 /* shift right arithmetic helper */
388 if (likely(!(T1
& 0x20UL
))) {
389 if (likely((uint32_t)T1
!= 0)) {
390 ret
= (int32_t)T0
>> (T1
& 0x1fUL
);
391 if (likely(ret
>= 0 || ((int32_t)T0
& ((1 << T1
) - 1)) == 0)) {
392 env
->xer
&= ~(1 << XER_CA
);
394 env
->xer
|= (1 << XER_CA
);
398 env
->xer
&= ~(1 << XER_CA
);
401 ret
= UINT32_MAX
* ((uint32_t)T0
>> 31);
402 if (likely(ret
>= 0 || ((uint32_t)T0
& ~0x80000000UL
) == 0)) {
403 env
->xer
&= ~(1 << XER_CA
);
405 env
->xer
|= (1 << XER_CA
);
411 #if defined(TARGET_PPC64)
416 if (likely(!(T1
& 0x40UL
))) {
417 if (likely((uint64_t)T1
!= 0)) {
418 ret
= (int64_t)T0
>> (T1
& 0x3FUL
);
419 if (likely(ret
>= 0 || ((int64_t)T0
& ((1 << T1
) - 1)) == 0)) {
420 env
->xer
&= ~(1 << XER_CA
);
422 env
->xer
|= (1 << XER_CA
);
426 env
->xer
&= ~(1 << XER_CA
);
429 ret
= UINT64_MAX
* ((uint64_t)T0
>> 63);
430 if (likely(ret
>= 0 || ((uint64_t)T0
& ~0x8000000000000000ULL
) == 0)) {
431 env
->xer
&= ~(1 << XER_CA
);
433 env
->xer
|= (1 << XER_CA
);
440 void do_popcntb (void)
446 for (i
= 0; i
< 32; i
+= 8)
447 ret
|= ctpop8((T0
>> i
) & 0xFF) << i
;
451 #if defined(TARGET_PPC64)
452 void do_popcntb_64 (void)
458 for (i
= 0; i
< 64; i
+= 8)
459 ret
|= ctpop8((T0
>> i
) & 0xFF) << i
;
464 /*****************************************************************************/
465 /* Floating point operations helpers */
466 static always_inline
int fpisneg (float64 d
)
472 return u
.ll
>> 63 != 0;
475 static always_inline
int isden (float64 d
)
481 return ((u
.ll
>> 52) & 0x7FF) == 0;
484 static always_inline
int iszero (float64 d
)
490 return (u
.ll
& ~0x8000000000000000ULL
) == 0;
493 static always_inline
int isinfinity (float64 d
)
499 return ((u
.ll
>> 52) & 0x7FF) == 0x7FF &&
500 (u
.ll
& 0x000FFFFFFFFFFFFFULL
) == 0;
503 #ifdef CONFIG_SOFTFLOAT
504 static always_inline
int isfinite (float64 d
)
510 return (((u
.ll
>> 52) & 0x7FF) != 0x7FF);
513 static always_inline
int isnormal (float64 d
)
519 uint32_t exp
= (u
.ll
>> 52) & 0x7FF;
520 return ((0 < exp
) && (exp
< 0x7FF));
524 void do_compute_fprf (int set_fprf
)
528 isneg
= fpisneg(FT0
);
529 if (unlikely(float64_is_nan(FT0
))) {
530 if (float64_is_signaling_nan(FT0
)) {
531 /* Signaling NaN: flags are undefined */
537 } else if (unlikely(isinfinity(FT0
))) {
552 /* Denormalized numbers */
555 /* Normalized numbers */
566 /* We update FPSCR_FPRF */
567 env
->fpscr
&= ~(0x1F << FPSCR_FPRF
);
568 env
->fpscr
|= T0
<< FPSCR_FPRF
;
570 /* We just need fpcc to update Rc1 */
574 /* Floating-point invalid operations exception */
575 static always_inline
void fload_invalid_op_excp (int op
)
580 if (op
& POWERPC_EXCP_FP_VXSNAN
) {
581 /* Operation on signaling NaN */
582 env
->fpscr
|= 1 << FPSCR_VXSNAN
;
584 if (op
& POWERPC_EXCP_FP_VXSOFT
) {
585 /* Software-defined condition */
586 env
->fpscr
|= 1 << FPSCR_VXSOFT
;
588 switch (op
& ~(POWERPC_EXCP_FP_VXSOFT
| POWERPC_EXCP_FP_VXSNAN
)) {
589 case POWERPC_EXCP_FP_VXISI
:
590 /* Magnitude subtraction of infinities */
591 env
->fpscr
|= 1 << FPSCR_VXISI
;
593 case POWERPC_EXCP_FP_VXIDI
:
594 /* Division of infinity by infinity */
595 env
->fpscr
|= 1 << FPSCR_VXIDI
;
597 case POWERPC_EXCP_FP_VXZDZ
:
598 /* Division of zero by zero */
599 env
->fpscr
|= 1 << FPSCR_VXZDZ
;
601 case POWERPC_EXCP_FP_VXIMZ
:
602 /* Multiplication of zero by infinity */
603 env
->fpscr
|= 1 << FPSCR_VXIMZ
;
605 case POWERPC_EXCP_FP_VXVC
:
606 /* Ordered comparison of NaN */
607 env
->fpscr
|= 1 << FPSCR_VXVC
;
608 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
609 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
610 /* We must update the target FPR before raising the exception */
612 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
613 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_VXVC
;
614 /* Update the floating-point enabled exception summary */
615 env
->fpscr
|= 1 << FPSCR_FEX
;
616 /* Exception is differed */
620 case POWERPC_EXCP_FP_VXSQRT
:
621 /* Square root of a negative number */
622 env
->fpscr
|= 1 << FPSCR_VXSQRT
;
624 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
626 /* Set the result to quiet NaN */
628 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
629 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
632 case POWERPC_EXCP_FP_VXCVI
:
633 /* Invalid conversion */
634 env
->fpscr
|= 1 << FPSCR_VXCVI
;
635 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
637 /* Set the result to quiet NaN */
639 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
640 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
644 /* Update the floating-point invalid operation summary */
645 env
->fpscr
|= 1 << FPSCR_VX
;
646 /* Update the floating-point exception summary */
647 env
->fpscr
|= 1 << FPSCR_FX
;
649 /* Update the floating-point enabled exception summary */
650 env
->fpscr
|= 1 << FPSCR_FEX
;
651 if (msr_fe0
!= 0 || msr_fe1
!= 0)
652 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_FP
| op
);
656 static always_inline
void float_zero_divide_excp (void)
660 env
->fpscr
|= 1 << FPSCR_ZX
;
661 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
662 /* Update the floating-point exception summary */
663 env
->fpscr
|= 1 << FPSCR_FX
;
665 /* Update the floating-point enabled exception summary */
666 env
->fpscr
|= 1 << FPSCR_FEX
;
667 if (msr_fe0
!= 0 || msr_fe1
!= 0) {
668 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
669 POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
);
672 /* Set the result to infinity */
675 u0
.ll
= ((u0
.ll
^ u1
.ll
) & 0x8000000000000000ULL
);
676 u0
.ll
|= 0x7FFULL
<< 52;
681 static always_inline
void float_overflow_excp (void)
683 env
->fpscr
|= 1 << FPSCR_OX
;
684 /* Update the floating-point exception summary */
685 env
->fpscr
|= 1 << FPSCR_FX
;
687 /* XXX: should adjust the result */
688 /* Update the floating-point enabled exception summary */
689 env
->fpscr
|= 1 << FPSCR_FEX
;
690 /* We must update the target FPR before raising the exception */
691 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
692 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
694 env
->fpscr
|= 1 << FPSCR_XX
;
695 env
->fpscr
|= 1 << FPSCR_FI
;
699 static always_inline
void float_underflow_excp (void)
701 env
->fpscr
|= 1 << FPSCR_UX
;
702 /* Update the floating-point exception summary */
703 env
->fpscr
|= 1 << FPSCR_FX
;
705 /* XXX: should adjust the result */
706 /* Update the floating-point enabled exception summary */
707 env
->fpscr
|= 1 << FPSCR_FEX
;
708 /* We must update the target FPR before raising the exception */
709 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
710 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
714 static always_inline
void float_inexact_excp (void)
716 env
->fpscr
|= 1 << FPSCR_XX
;
717 /* Update the floating-point exception summary */
718 env
->fpscr
|= 1 << FPSCR_FX
;
720 /* Update the floating-point enabled exception summary */
721 env
->fpscr
|= 1 << FPSCR_FEX
;
722 /* We must update the target FPR before raising the exception */
723 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
724 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
728 static always_inline
void fpscr_set_rounding_mode (void)
732 /* Set rounding mode */
735 /* Best approximation (round to nearest) */
736 rnd_type
= float_round_nearest_even
;
739 /* Smaller magnitude (round toward zero) */
740 rnd_type
= float_round_to_zero
;
743 /* Round toward +infinite */
744 rnd_type
= float_round_up
;
748 /* Round toward -infinite */
749 rnd_type
= float_round_down
;
752 set_float_rounding_mode(rnd_type
, &env
->fp_status
);
755 void do_fpscr_setbit (int bit
)
759 prev
= (env
->fpscr
>> bit
) & 1;
760 env
->fpscr
|= 1 << bit
;
764 env
->fpscr
|= 1 << FPSCR_FX
;
768 env
->fpscr
|= 1 << FPSCR_FX
;
773 env
->fpscr
|= 1 << FPSCR_FX
;
778 env
->fpscr
|= 1 << FPSCR_FX
;
783 env
->fpscr
|= 1 << FPSCR_FX
;
796 env
->fpscr
|= 1 << FPSCR_VX
;
797 env
->fpscr
|= 1 << FPSCR_FX
;
804 env
->error_code
= POWERPC_EXCP_FP
;
806 env
->error_code
|= POWERPC_EXCP_FP_VXSNAN
;
808 env
->error_code
|= POWERPC_EXCP_FP_VXISI
;
810 env
->error_code
|= POWERPC_EXCP_FP_VXIDI
;
812 env
->error_code
|= POWERPC_EXCP_FP_VXZDZ
;
814 env
->error_code
|= POWERPC_EXCP_FP_VXIMZ
;
816 env
->error_code
|= POWERPC_EXCP_FP_VXVC
;
818 env
->error_code
|= POWERPC_EXCP_FP_VXSOFT
;
820 env
->error_code
|= POWERPC_EXCP_FP_VXSQRT
;
822 env
->error_code
|= POWERPC_EXCP_FP_VXCVI
;
829 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
836 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
843 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
;
850 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
856 fpscr_set_rounding_mode();
861 /* Update the floating-point enabled exception summary */
862 env
->fpscr
|= 1 << FPSCR_FEX
;
863 /* We have to update Rc1 before raising the exception */
864 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
870 #if defined(WORDS_BIGENDIAN)
877 void do_store_fpscr (uint32_t mask
)
880 * We use only the 32 LSB of the incoming fpr
890 new |= prev
& 0x90000000;
891 for (i
= 0; i
< 7; i
++) {
892 if (mask
& (1 << i
)) {
893 env
->fpscr
&= ~(0xF << (4 * i
));
894 env
->fpscr
|= new & (0xF << (4 * i
));
897 /* Update VX and FEX */
899 env
->fpscr
|= 1 << FPSCR_VX
;
901 env
->fpscr
&= ~(1 << FPSCR_VX
);
902 if ((fpscr_ex
& fpscr_eex
) != 0) {
903 env
->fpscr
|= 1 << FPSCR_FEX
;
904 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
905 /* XXX: we should compute it properly */
906 env
->error_code
= POWERPC_EXCP_FP
;
909 env
->fpscr
&= ~(1 << FPSCR_FEX
);
910 fpscr_set_rounding_mode();
915 #ifdef CONFIG_SOFTFLOAT
916 void do_float_check_status (void)
918 if (env
->exception_index
== POWERPC_EXCP_PROGRAM
&&
919 (env
->error_code
& POWERPC_EXCP_FP
)) {
920 /* Differred floating-point exception after target FPR update */
921 if (msr_fe0
!= 0 || msr_fe1
!= 0)
922 do_raise_exception_err(env
->exception_index
, env
->error_code
);
923 } else if (env
->fp_status
.float_exception_flags
& float_flag_overflow
) {
924 float_overflow_excp();
925 } else if (env
->fp_status
.float_exception_flags
& float_flag_underflow
) {
926 float_underflow_excp();
927 } else if (env
->fp_status
.float_exception_flags
& float_flag_inexact
) {
928 float_inexact_excp();
933 #if USE_PRECISE_EMULATION
936 if (unlikely(float64_is_signaling_nan(FT0
) ||
937 float64_is_signaling_nan(FT1
))) {
939 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
940 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
941 fpisneg(FT0
) == fpisneg(FT1
))) {
942 FT0
= float64_add(FT0
, FT1
, &env
->fp_status
);
944 /* Magnitude subtraction of infinities */
945 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
951 if (unlikely(float64_is_signaling_nan(FT0
) ||
952 float64_is_signaling_nan(FT1
))) {
953 /* sNaN subtraction */
954 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
955 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
956 fpisneg(FT0
) != fpisneg(FT1
))) {
957 FT0
= float64_sub(FT0
, FT1
, &env
->fp_status
);
959 /* Magnitude subtraction of infinities */
960 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
966 if (unlikely(float64_is_signaling_nan(FT0
) ||
967 float64_is_signaling_nan(FT1
))) {
968 /* sNaN multiplication */
969 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
970 } else if (unlikely((isinfinity(FT0
) && iszero(FT1
)) ||
971 (iszero(FT0
) && isinfinity(FT1
)))) {
972 /* Multiplication of zero by infinity */
973 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIMZ
);
975 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
981 if (unlikely(float64_is_signaling_nan(FT0
) ||
982 float64_is_signaling_nan(FT1
))) {
984 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
985 } else if (unlikely(isinfinity(FT0
) && isinfinity(FT1
))) {
986 /* Division of infinity by infinity */
987 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIDI
);
988 } else if (unlikely(iszero(FT1
))) {
990 /* Division of zero by zero */
991 fload_invalid_op_excp(POWERPC_EXCP_FP_VXZDZ
);
993 /* Division by zero */
994 float_zero_divide_excp();
997 FT0
= float64_div(FT0
, FT1
, &env
->fp_status
);
1000 #endif /* USE_PRECISE_EMULATION */
1002 void do_fctiw (void)
1006 if (unlikely(float64_is_signaling_nan(FT0
))) {
1007 /* sNaN conversion */
1008 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1009 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1010 /* qNan / infinity conversion */
1011 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1013 p
.ll
= float64_to_int32(FT0
, &env
->fp_status
);
1014 #if USE_PRECISE_EMULATION
1015 /* XXX: higher bits are not supposed to be significant.
1016 * to make tests easier, return the same as a real PowerPC 750
1018 p
.ll
|= 0xFFF80000ULL
<< 32;
1024 void do_fctiwz (void)
1028 if (unlikely(float64_is_signaling_nan(FT0
))) {
1029 /* sNaN conversion */
1030 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1031 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1032 /* qNan / infinity conversion */
1033 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1035 p
.ll
= float64_to_int32_round_to_zero(FT0
, &env
->fp_status
);
1036 #if USE_PRECISE_EMULATION
1037 /* XXX: higher bits are not supposed to be significant.
1038 * to make tests easier, return the same as a real PowerPC 750
1040 p
.ll
|= 0xFFF80000ULL
<< 32;
1046 #if defined(TARGET_PPC64)
1047 void do_fcfid (void)
1052 FT0
= int64_to_float64(p
.ll
, &env
->fp_status
);
1055 void do_fctid (void)
1059 if (unlikely(float64_is_signaling_nan(FT0
))) {
1060 /* sNaN conversion */
1061 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1062 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1063 /* qNan / infinity conversion */
1064 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1066 p
.ll
= float64_to_int64(FT0
, &env
->fp_status
);
1071 void do_fctidz (void)
1075 if (unlikely(float64_is_signaling_nan(FT0
))) {
1076 /* sNaN conversion */
1077 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1078 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1079 /* qNan / infinity conversion */
1080 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1082 p
.ll
= float64_to_int64_round_to_zero(FT0
, &env
->fp_status
);
1089 static always_inline
void do_fri (int rounding_mode
)
1091 if (unlikely(float64_is_signaling_nan(FT0
))) {
1093 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1094 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1095 /* qNan / infinity round */
1096 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1098 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
1099 FT0
= float64_round_to_int(FT0
, &env
->fp_status
);
1100 /* Restore rounding mode from FPSCR */
1101 fpscr_set_rounding_mode();
1107 do_fri(float_round_nearest_even
);
1112 do_fri(float_round_to_zero
);
1117 do_fri(float_round_up
);
1122 do_fri(float_round_down
);
1125 #if USE_PRECISE_EMULATION
1126 void do_fmadd (void)
1128 if (unlikely(float64_is_signaling_nan(FT0
) ||
1129 float64_is_signaling_nan(FT1
) ||
1130 float64_is_signaling_nan(FT2
))) {
1131 /* sNaN operation */
1132 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1135 /* This is the way the PowerPC specification defines it */
1136 float128 ft0_128
, ft1_128
;
1138 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1139 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1140 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1141 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1142 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
1143 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1145 /* This is OK on x86 hosts */
1146 FT0
= (FT0
* FT1
) + FT2
;
1151 void do_fmsub (void)
1153 if (unlikely(float64_is_signaling_nan(FT0
) ||
1154 float64_is_signaling_nan(FT1
) ||
1155 float64_is_signaling_nan(FT2
))) {
1156 /* sNaN operation */
1157 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1160 /* This is the way the PowerPC specification defines it */
1161 float128 ft0_128
, ft1_128
;
1163 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1164 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1165 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1166 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1167 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
1168 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1170 /* This is OK on x86 hosts */
1171 FT0
= (FT0
* FT1
) - FT2
;
1175 #endif /* USE_PRECISE_EMULATION */
1177 void do_fnmadd (void)
1179 if (unlikely(float64_is_signaling_nan(FT0
) ||
1180 float64_is_signaling_nan(FT1
) ||
1181 float64_is_signaling_nan(FT2
))) {
1182 /* sNaN operation */
1183 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1185 #if USE_PRECISE_EMULATION
1187 /* This is the way the PowerPC specification defines it */
1188 float128 ft0_128
, ft1_128
;
1190 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1191 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1192 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1193 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1194 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
1195 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1197 /* This is OK on x86 hosts */
1198 FT0
= (FT0
* FT1
) + FT2
;
1201 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1202 FT0
= float64_add(FT0
, FT2
, &env
->fp_status
);
1204 if (likely(!isnan(FT0
)))
1205 FT0
= float64_chs(FT0
);
1209 void do_fnmsub (void)
1211 if (unlikely(float64_is_signaling_nan(FT0
) ||
1212 float64_is_signaling_nan(FT1
) ||
1213 float64_is_signaling_nan(FT2
))) {
1214 /* sNaN operation */
1215 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1217 #if USE_PRECISE_EMULATION
1219 /* This is the way the PowerPC specification defines it */
1220 float128 ft0_128
, ft1_128
;
1222 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1223 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1224 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1225 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1226 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
1227 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1229 /* This is OK on x86 hosts */
1230 FT0
= (FT0
* FT1
) - FT2
;
1233 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1234 FT0
= float64_sub(FT0
, FT2
, &env
->fp_status
);
1236 if (likely(!isnan(FT0
)))
1237 FT0
= float64_chs(FT0
);
1241 #if USE_PRECISE_EMULATION
1244 if (unlikely(float64_is_signaling_nan(FT0
))) {
1245 /* sNaN square root */
1246 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1248 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1251 #endif /* USE_PRECISE_EMULATION */
1253 void do_fsqrt (void)
1255 if (unlikely(float64_is_signaling_nan(FT0
))) {
1256 /* sNaN square root */
1257 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1258 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1259 /* Square root of a negative nonzero number */
1260 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1262 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1270 if (unlikely(float64_is_signaling_nan(FT0
))) {
1271 /* sNaN reciprocal */
1272 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1273 } else if (unlikely(iszero(FT0
))) {
1274 /* Zero reciprocal */
1275 float_zero_divide_excp();
1276 } else if (likely(isnormal(FT0
))) {
1277 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1280 if (p
.ll
== 0x8000000000000000ULL
) {
1281 p
.ll
= 0xFFF0000000000000ULL
;
1282 } else if (p
.ll
== 0x0000000000000000ULL
) {
1283 p
.ll
= 0x7FF0000000000000ULL
;
1284 } else if (isnan(FT0
)) {
1285 p
.ll
= 0x7FF8000000000000ULL
;
1286 } else if (fpisneg(FT0
)) {
1287 p
.ll
= 0x8000000000000000ULL
;
1289 p
.ll
= 0x0000000000000000ULL
;
1299 if (unlikely(float64_is_signaling_nan(FT0
))) {
1300 /* sNaN reciprocal */
1301 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1302 } else if (unlikely(iszero(FT0
))) {
1303 /* Zero reciprocal */
1304 float_zero_divide_excp();
1305 } else if (likely(isnormal(FT0
))) {
1306 #if USE_PRECISE_EMULATION
1307 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1308 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1310 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1314 if (p
.ll
== 0x8000000000000000ULL
) {
1315 p
.ll
= 0xFFF0000000000000ULL
;
1316 } else if (p
.ll
== 0x0000000000000000ULL
) {
1317 p
.ll
= 0x7FF0000000000000ULL
;
1318 } else if (isnan(FT0
)) {
1319 p
.ll
= 0x7FF8000000000000ULL
;
1320 } else if (fpisneg(FT0
)) {
1321 p
.ll
= 0x8000000000000000ULL
;
1323 p
.ll
= 0x0000000000000000ULL
;
1329 void do_frsqrte (void)
1333 if (unlikely(float64_is_signaling_nan(FT0
))) {
1334 /* sNaN reciprocal square root */
1335 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1336 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1337 /* Reciprocal square root of a negative nonzero number */
1338 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1339 } else if (likely(isnormal(FT0
))) {
1340 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1341 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1344 if (p
.ll
== 0x8000000000000000ULL
) {
1345 p
.ll
= 0xFFF0000000000000ULL
;
1346 } else if (p
.ll
== 0x0000000000000000ULL
) {
1347 p
.ll
= 0x7FF0000000000000ULL
;
1348 } else if (isnan(FT0
)) {
1349 p
.ll
|= 0x000FFFFFFFFFFFFFULL
;
1350 } else if (fpisneg(FT0
)) {
1351 p
.ll
= 0x7FF8000000000000ULL
;
1353 p
.ll
= 0x0000000000000000ULL
;
1361 if (!fpisneg(FT0
) || iszero(FT0
))
1367 void do_fcmpu (void)
1369 if (unlikely(float64_is_signaling_nan(FT0
) ||
1370 float64_is_signaling_nan(FT1
))) {
1371 /* sNaN comparison */
1372 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1374 if (float64_lt(FT0
, FT1
, &env
->fp_status
)) {
1376 } else if (!float64_le(FT0
, FT1
, &env
->fp_status
)) {
1382 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1383 env
->fpscr
|= T0
<< FPSCR_FPRF
;
1386 void do_fcmpo (void)
1388 if (unlikely(float64_is_nan(FT0
) ||
1389 float64_is_nan(FT1
))) {
1390 if (float64_is_signaling_nan(FT0
) ||
1391 float64_is_signaling_nan(FT1
)) {
1392 /* sNaN comparison */
1393 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
|
1394 POWERPC_EXCP_FP_VXVC
);
1396 /* qNaN comparison */
1397 fload_invalid_op_excp(POWERPC_EXCP_FP_VXVC
);
1400 if (float64_lt(FT0
, FT1
, &env
->fp_status
)) {
1402 } else if (!float64_le(FT0
, FT1
, &env
->fp_status
)) {
1408 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1409 env
->fpscr
|= T0
<< FPSCR_FPRF
;
1412 #if !defined (CONFIG_USER_ONLY)
1413 void cpu_dump_rfi (target_ulong RA
, target_ulong msr
);
1415 void do_store_msr (void)
1417 T0
= hreg_store_msr(env
, T0
, 0);
1419 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1420 do_raise_exception(T0
);
1424 static always_inline
void __do_rfi (target_ulong nip
, target_ulong msr
,
1425 target_ulong msrm
, int keep_msrh
)
1427 #if defined(TARGET_PPC64)
1428 if (msr
& (1ULL << MSR_SF
)) {
1429 nip
= (uint64_t)nip
;
1430 msr
&= (uint64_t)msrm
;
1432 nip
= (uint32_t)nip
;
1433 msr
= (uint32_t)(msr
& msrm
);
1435 msr
|= env
->msr
& ~((uint64_t)0xFFFFFFFF);
1438 nip
= (uint32_t)nip
;
1439 msr
&= (uint32_t)msrm
;
1441 /* XXX: beware: this is false if VLE is supported */
1442 env
->nip
= nip
& ~((target_ulong
)0x00000003);
1443 hreg_store_msr(env
, msr
, 1);
1444 #if defined (DEBUG_OP)
1445 cpu_dump_rfi(env
->nip
, env
->msr
);
1447 /* No need to raise an exception here,
1448 * as rfi is always the last insn of a TB
1450 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1455 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1456 ~((target_ulong
)0xFFFF0000), 1);
1459 #if defined(TARGET_PPC64)
1462 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1463 ~((target_ulong
)0xFFFF0000), 0);
1466 void do_hrfid (void)
1468 __do_rfi(env
->spr
[SPR_HSRR0
], env
->spr
[SPR_HSRR1
],
1469 ~((target_ulong
)0xFFFF0000), 0);
1474 void do_tw (int flags
)
1476 if (!likely(!(((int32_t)T0
< (int32_t)T1
&& (flags
& 0x10)) ||
1477 ((int32_t)T0
> (int32_t)T1
&& (flags
& 0x08)) ||
1478 ((int32_t)T0
== (int32_t)T1
&& (flags
& 0x04)) ||
1479 ((uint32_t)T0
< (uint32_t)T1
&& (flags
& 0x02)) ||
1480 ((uint32_t)T0
> (uint32_t)T1
&& (flags
& 0x01))))) {
1481 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1485 #if defined(TARGET_PPC64)
1486 void do_td (int flags
)
1488 if (!likely(!(((int64_t)T0
< (int64_t)T1
&& (flags
& 0x10)) ||
1489 ((int64_t)T0
> (int64_t)T1
&& (flags
& 0x08)) ||
1490 ((int64_t)T0
== (int64_t)T1
&& (flags
& 0x04)) ||
1491 ((uint64_t)T0
< (uint64_t)T1
&& (flags
& 0x02)) ||
1492 ((uint64_t)T0
> (uint64_t)T1
&& (flags
& 0x01)))))
1493 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1497 /*****************************************************************************/
1498 /* PowerPC 601 specific instructions (POWER bridge) */
1499 void do_POWER_abso (void)
1501 if ((int32_t)T0
== INT32_MIN
) {
1503 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1504 } else if ((int32_t)T0
< 0) {
1506 env
->xer
&= ~(1 << XER_OV
);
1508 env
->xer
&= ~(1 << XER_OV
);
1512 void do_POWER_clcs (void)
1516 /* Instruction cache line size */
1517 T0
= env
->icache_line_size
;
1520 /* Data cache line size */
1521 T0
= env
->dcache_line_size
;
1524 /* Minimum cache line size */
1525 T0
= env
->icache_line_size
< env
->dcache_line_size
?
1526 env
->icache_line_size
: env
->dcache_line_size
;
1529 /* Maximum cache line size */
1530 T0
= env
->icache_line_size
> env
->dcache_line_size
?
1531 env
->icache_line_size
: env
->dcache_line_size
;
1539 void do_POWER_div (void)
1543 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1545 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1546 env
->spr
[SPR_MQ
] = 0;
1548 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1549 env
->spr
[SPR_MQ
] = tmp
% T1
;
1550 T0
= tmp
/ (int32_t)T1
;
1554 void do_POWER_divo (void)
1558 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1560 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1561 env
->spr
[SPR_MQ
] = 0;
1562 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1564 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1565 env
->spr
[SPR_MQ
] = tmp
% T1
;
1567 if (tmp
> (int64_t)INT32_MAX
|| tmp
< (int64_t)INT32_MIN
) {
1568 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1570 env
->xer
&= ~(1 << XER_OV
);
1576 void do_POWER_divs (void)
1578 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1580 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1581 env
->spr
[SPR_MQ
] = 0;
1583 env
->spr
[SPR_MQ
] = T0
% T1
;
1584 T0
= (int32_t)T0
/ (int32_t)T1
;
1588 void do_POWER_divso (void)
1590 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1592 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1593 env
->spr
[SPR_MQ
] = 0;
1594 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1596 T0
= (int32_t)T0
/ (int32_t)T1
;
1597 env
->spr
[SPR_MQ
] = (int32_t)T0
% (int32_t)T1
;
1598 env
->xer
&= ~(1 << XER_OV
);
1602 void do_POWER_dozo (void)
1604 if ((int32_t)T1
> (int32_t)T0
) {
1607 if (((uint32_t)(~T2
) ^ (uint32_t)T1
^ UINT32_MAX
) &
1608 ((uint32_t)(~T2
) ^ (uint32_t)T0
) & (1UL << 31)) {
1609 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1611 env
->xer
&= ~(1 << XER_OV
);
1615 env
->xer
&= ~(1 << XER_OV
);
1619 void do_POWER_maskg (void)
1623 if ((uint32_t)T0
== (uint32_t)(T1
+ 1)) {
1626 ret
= (UINT32_MAX
>> ((uint32_t)T0
)) ^
1627 ((UINT32_MAX
>> ((uint32_t)T1
)) >> 1);
1628 if ((uint32_t)T0
> (uint32_t)T1
)
1634 void do_POWER_mulo (void)
1638 tmp
= (uint64_t)T0
* (uint64_t)T1
;
1639 env
->spr
[SPR_MQ
] = tmp
>> 32;
1641 if (tmp
>> 32 != ((uint64_t)T0
>> 16) * ((uint64_t)T1
>> 16)) {
1642 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1644 env
->xer
&= ~(1 << XER_OV
);
1648 #if !defined (CONFIG_USER_ONLY)
1649 void do_POWER_rac (void)
1654 /* We don't have to generate many instances of this instruction,
1655 * as rac is supervisor only.
1657 /* XXX: FIX THIS: Pretend we have no BAT */
1658 nb_BATs
= env
->nb_BATs
;
1660 if (get_physical_address(env
, &ctx
, T0
, 0, ACCESS_INT
) == 0)
1662 env
->nb_BATs
= nb_BATs
;
1665 void do_POWER_rfsvc (void)
1667 __do_rfi(env
->lr
, env
->ctr
, 0x0000FFFF, 0);
1670 void do_store_hid0_601 (void)
1674 hid0
= env
->spr
[SPR_HID0
];
1675 if ((T0
^ hid0
) & 0x00000008) {
1676 /* Change current endianness */
1677 env
->hflags
&= ~(1 << MSR_LE
);
1678 env
->hflags_nmsr
&= ~(1 << MSR_LE
);
1679 env
->hflags_nmsr
|= (1 << MSR_LE
) & (((T0
>> 3) & 1) << MSR_LE
);
1680 env
->hflags
|= env
->hflags_nmsr
;
1681 if (loglevel
!= 0) {
1682 fprintf(logfile
, "%s: set endianness to %c => " ADDRX
"\n",
1683 __func__
, T0
& 0x8 ? 'l' : 'b', env
->hflags
);
1686 env
->spr
[SPR_HID0
] = T0
;
1690 /*****************************************************************************/
1691 /* 602 specific instructions */
1692 /* mfrom is the most crazy instruction ever seen, imho ! */
1693 /* Real implementation uses a ROM table. Do the same */
1694 #define USE_MFROM_ROM_TABLE
1695 void do_op_602_mfrom (void)
1697 if (likely(T0
< 602)) {
1698 #if defined(USE_MFROM_ROM_TABLE)
1699 #include "mfrom_table.c"
1700 T0
= mfrom_ROM_table
[T0
];
1703 /* Extremly decomposed:
1705 * T0 = 256 * log10(10 + 1.0) + 0.5
1708 d
= float64_div(d
, 256, &env
->fp_status
);
1710 d
= exp10(d
); // XXX: use float emulation function
1711 d
= float64_add(d
, 1.0, &env
->fp_status
);
1712 d
= log10(d
); // XXX: use float emulation function
1713 d
= float64_mul(d
, 256, &env
->fp_status
);
1714 d
= float64_add(d
, 0.5, &env
->fp_status
);
1715 T0
= float64_round_to_int(d
, &env
->fp_status
);
1722 /*****************************************************************************/
1723 /* Embedded PowerPC specific helpers */
1724 void do_405_check_sat (void)
1726 if (!likely((((uint32_t)T1
^ (uint32_t)T2
) >> 31) ||
1727 !(((uint32_t)T0
^ (uint32_t)T2
) >> 31))) {
1728 /* Saturate result */
1737 /* XXX: to be improved to check access rights when in user-mode */
1738 void do_load_dcr (void)
1742 if (unlikely(env
->dcr_env
== NULL
)) {
1743 if (loglevel
!= 0) {
1744 fprintf(logfile
, "No DCR environment\n");
1746 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1747 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1748 } else if (unlikely(ppc_dcr_read(env
->dcr_env
, T0
, &val
) != 0)) {
1749 if (loglevel
!= 0) {
1750 fprintf(logfile
, "DCR read error %d %03x\n", (int)T0
, (int)T0
);
1752 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1753 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1759 void do_store_dcr (void)
1761 if (unlikely(env
->dcr_env
== NULL
)) {
1762 if (loglevel
!= 0) {
1763 fprintf(logfile
, "No DCR environment\n");
1765 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1766 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1767 } else if (unlikely(ppc_dcr_write(env
->dcr_env
, T0
, T1
) != 0)) {
1768 if (loglevel
!= 0) {
1769 fprintf(logfile
, "DCR write error %d %03x\n", (int)T0
, (int)T0
);
1771 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1772 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1776 #if !defined(CONFIG_USER_ONLY)
1777 void do_40x_rfci (void)
1779 __do_rfi(env
->spr
[SPR_40x_SRR2
], env
->spr
[SPR_40x_SRR3
],
1780 ~((target_ulong
)0xFFFF0000), 0);
1785 __do_rfi(env
->spr
[SPR_BOOKE_CSRR0
], SPR_BOOKE_CSRR1
,
1786 ~((target_ulong
)0x3FFF0000), 0);
1791 __do_rfi(env
->spr
[SPR_BOOKE_DSRR0
], SPR_BOOKE_DSRR1
,
1792 ~((target_ulong
)0x3FFF0000), 0);
1795 void do_rfmci (void)
1797 __do_rfi(env
->spr
[SPR_BOOKE_MCSRR0
], SPR_BOOKE_MCSRR1
,
1798 ~((target_ulong
)0x3FFF0000), 0);
1801 void do_load_403_pb (int num
)
1806 void do_store_403_pb (int num
)
1808 if (likely(env
->pb
[num
] != T0
)) {
1810 /* Should be optimized */
1817 void do_440_dlmzb (void)
1823 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1824 if ((T0
& mask
) == 0)
1828 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1829 if ((T1
& mask
) == 0)
1837 /* SPE extension helpers */
1838 /* Use a table to make this quicker */
1839 static uint8_t hbrev
[16] = {
1840 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
1841 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF,
1844 static always_inline
uint8_t byte_reverse (uint8_t val
)
1846 return hbrev
[val
>> 4] | (hbrev
[val
& 0xF] << 4);
1849 static always_inline
uint32_t word_reverse (uint32_t val
)
1851 return byte_reverse(val
>> 24) | (byte_reverse(val
>> 16) << 8) |
1852 (byte_reverse(val
>> 8) << 16) | (byte_reverse(val
) << 24);
1855 #define MASKBITS 16 // Random value - to be fixed (implementation dependant)
1856 void do_brinc (void)
1858 uint32_t a
, b
, d
, mask
;
1860 mask
= UINT32_MAX
>> (32 - MASKBITS
);
1863 d
= word_reverse(1 + word_reverse(a
| ~b
));
1864 T0
= (T0
& ~mask
) | (d
& b
);
1867 #define DO_SPE_OP2(name) \
1868 void do_ev##name (void) \
1870 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) | \
1871 (uint64_t)_do_e##name(T0_64, T1_64); \
1874 #define DO_SPE_OP1(name) \
1875 void do_ev##name (void) \
1877 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) | \
1878 (uint64_t)_do_e##name(T0_64); \
1881 /* Fixed-point vector arithmetic */
1882 static always_inline
uint32_t _do_eabs (uint32_t val
)
1884 if ((val
& 0x80000000) && val
!= 0x80000000)
1890 static always_inline
uint32_t _do_eaddw (uint32_t op1
, uint32_t op2
)
1895 static always_inline
int _do_ecntlsw (uint32_t val
)
1897 if (val
& 0x80000000)
1903 static always_inline
int _do_ecntlzw (uint32_t val
)
1908 static always_inline
uint32_t _do_eneg (uint32_t val
)
1910 if (val
!= 0x80000000)
1916 static always_inline
uint32_t _do_erlw (uint32_t op1
, uint32_t op2
)
1918 return rotl32(op1
, op2
);
1921 static always_inline
uint32_t _do_erndw (uint32_t val
)
1923 return (val
+ 0x000080000000) & 0xFFFF0000;
1926 static always_inline
uint32_t _do_eslw (uint32_t op1
, uint32_t op2
)
1928 /* No error here: 6 bits are used */
1929 return op1
<< (op2
& 0x3F);
1932 static always_inline
int32_t _do_esrws (int32_t op1
, uint32_t op2
)
1934 /* No error here: 6 bits are used */
1935 return op1
>> (op2
& 0x3F);
1938 static always_inline
uint32_t _do_esrwu (uint32_t op1
, uint32_t op2
)
1940 /* No error here: 6 bits are used */
1941 return op1
>> (op2
& 0x3F);
1944 static always_inline
uint32_t _do_esubfw (uint32_t op1
, uint32_t op2
)
1972 /* evsel is a little bit more complicated... */
1973 static always_inline
uint32_t _do_esel (uint32_t op1
, uint32_t op2
, int n
)
1981 void do_evsel (void)
1983 T0_64
= ((uint64_t)_do_esel(T0_64
>> 32, T1_64
>> 32, T0
>> 3) << 32) |
1984 (uint64_t)_do_esel(T0_64
, T1_64
, (T0
>> 2) & 1);
1987 /* Fixed-point vector comparisons */
1988 #define DO_SPE_CMP(name) \
1989 void do_ev##name (void) \
1991 T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32, \
1992 T1_64 >> 32) << 32, \
1993 _do_e##name(T0_64, T1_64)); \
1996 static always_inline
uint32_t _do_evcmp_merge (int t0
, int t1
)
1998 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
2000 static always_inline
int _do_ecmpeq (uint32_t op1
, uint32_t op2
)
2002 return op1
== op2
? 1 : 0;
2005 static always_inline
int _do_ecmpgts (int32_t op1
, int32_t op2
)
2007 return op1
> op2
? 1 : 0;
2010 static always_inline
int _do_ecmpgtu (uint32_t op1
, uint32_t op2
)
2012 return op1
> op2
? 1 : 0;
2015 static always_inline
int _do_ecmplts (int32_t op1
, int32_t op2
)
2017 return op1
< op2
? 1 : 0;
2020 static always_inline
int _do_ecmpltu (uint32_t op1
, uint32_t op2
)
2022 return op1
< op2
? 1 : 0;
2036 /* Single precision floating-point conversions from/to integer */
2037 static always_inline
uint32_t _do_efscfsi (int32_t val
)
2041 u
.f
= int32_to_float32(val
, &env
->spe_status
);
2046 static always_inline
uint32_t _do_efscfui (uint32_t val
)
2050 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
2055 static always_inline
int32_t _do_efsctsi (uint32_t val
)
2060 /* NaN are not treated the same way IEEE 754 does */
2061 if (unlikely(isnan(u
.f
)))
2064 return float32_to_int32(u
.f
, &env
->spe_status
);
2067 static always_inline
uint32_t _do_efsctui (uint32_t val
)
2072 /* NaN are not treated the same way IEEE 754 does */
2073 if (unlikely(isnan(u
.f
)))
2076 return float32_to_uint32(u
.f
, &env
->spe_status
);
2079 static always_inline
int32_t _do_efsctsiz (uint32_t val
)
2084 /* NaN are not treated the same way IEEE 754 does */
2085 if (unlikely(isnan(u
.f
)))
2088 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
2091 static always_inline
uint32_t _do_efsctuiz (uint32_t val
)
2096 /* NaN are not treated the same way IEEE 754 does */
2097 if (unlikely(isnan(u
.f
)))
2100 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
2103 void do_efscfsi (void)
2105 T0_64
= _do_efscfsi(T0_64
);
2108 void do_efscfui (void)
2110 T0_64
= _do_efscfui(T0_64
);
2113 void do_efsctsi (void)
2115 T0_64
= _do_efsctsi(T0_64
);
2118 void do_efsctui (void)
2120 T0_64
= _do_efsctui(T0_64
);
2123 void do_efsctsiz (void)
2125 T0_64
= _do_efsctsiz(T0_64
);
2128 void do_efsctuiz (void)
2130 T0_64
= _do_efsctuiz(T0_64
);
2133 /* Single precision floating-point conversion to/from fractional */
2134 static always_inline
uint32_t _do_efscfsf (uint32_t val
)
2139 u
.f
= int32_to_float32(val
, &env
->spe_status
);
2140 tmp
= int64_to_float32(1ULL << 32, &env
->spe_status
);
2141 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
2146 static always_inline
uint32_t _do_efscfuf (uint32_t val
)
2151 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
2152 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2153 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
2158 static always_inline
int32_t _do_efsctsf (uint32_t val
)
2164 /* NaN are not treated the same way IEEE 754 does */
2165 if (unlikely(isnan(u
.f
)))
2167 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2168 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2170 return float32_to_int32(u
.f
, &env
->spe_status
);
2173 static always_inline
uint32_t _do_efsctuf (uint32_t val
)
2179 /* NaN are not treated the same way IEEE 754 does */
2180 if (unlikely(isnan(u
.f
)))
2182 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2183 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2185 return float32_to_uint32(u
.f
, &env
->spe_status
);
2188 static always_inline
int32_t _do_efsctsfz (uint32_t val
)
2194 /* NaN are not treated the same way IEEE 754 does */
2195 if (unlikely(isnan(u
.f
)))
2197 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2198 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2200 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
2203 static always_inline
uint32_t _do_efsctufz (uint32_t val
)
2209 /* NaN are not treated the same way IEEE 754 does */
2210 if (unlikely(isnan(u
.f
)))
2212 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2213 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2215 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
2218 void do_efscfsf (void)
2220 T0_64
= _do_efscfsf(T0_64
);
2223 void do_efscfuf (void)
2225 T0_64
= _do_efscfuf(T0_64
);
2228 void do_efsctsf (void)
2230 T0_64
= _do_efsctsf(T0_64
);
2233 void do_efsctuf (void)
2235 T0_64
= _do_efsctuf(T0_64
);
2238 void do_efsctsfz (void)
2240 T0_64
= _do_efsctsfz(T0_64
);
2243 void do_efsctufz (void)
2245 T0_64
= _do_efsctufz(T0_64
);
2248 /* Double precision floating point helpers */
2249 static always_inline
int _do_efdcmplt (uint64_t op1
, uint64_t op2
)
2251 /* XXX: TODO: test special values (NaN, infinites, ...) */
2252 return _do_efdtstlt(op1
, op2
);
2255 static always_inline
int _do_efdcmpgt (uint64_t op1
, uint64_t op2
)
2257 /* XXX: TODO: test special values (NaN, infinites, ...) */
2258 return _do_efdtstgt(op1
, op2
);
2261 static always_inline
int _do_efdcmpeq (uint64_t op1
, uint64_t op2
)
2263 /* XXX: TODO: test special values (NaN, infinites, ...) */
2264 return _do_efdtsteq(op1
, op2
);
2267 void do_efdcmplt (void)
2269 T0
= _do_efdcmplt(T0_64
, T1_64
);
2272 void do_efdcmpgt (void)
2274 T0
= _do_efdcmpgt(T0_64
, T1_64
);
2277 void do_efdcmpeq (void)
2279 T0
= _do_efdcmpeq(T0_64
, T1_64
);
2282 /* Double precision floating-point conversion to/from integer */
2283 static always_inline
uint64_t _do_efdcfsi (int64_t val
)
2287 u
.d
= int64_to_float64(val
, &env
->spe_status
);
2292 static always_inline
uint64_t _do_efdcfui (uint64_t val
)
2296 u
.d
= uint64_to_float64(val
, &env
->spe_status
);
2301 static always_inline
int64_t _do_efdctsi (uint64_t val
)
2306 /* NaN are not treated the same way IEEE 754 does */
2307 if (unlikely(isnan(u
.d
)))
2310 return float64_to_int64(u
.d
, &env
->spe_status
);
2313 static always_inline
uint64_t _do_efdctui (uint64_t val
)
2318 /* NaN are not treated the same way IEEE 754 does */
2319 if (unlikely(isnan(u
.d
)))
2322 return float64_to_uint64(u
.d
, &env
->spe_status
);
2325 static always_inline
int64_t _do_efdctsiz (uint64_t val
)
2330 /* NaN are not treated the same way IEEE 754 does */
2331 if (unlikely(isnan(u
.d
)))
2334 return float64_to_int64_round_to_zero(u
.d
, &env
->spe_status
);
2337 static always_inline
uint64_t _do_efdctuiz (uint64_t val
)
2342 /* NaN are not treated the same way IEEE 754 does */
2343 if (unlikely(isnan(u
.d
)))
2346 return float64_to_uint64_round_to_zero(u
.d
, &env
->spe_status
);
2349 void do_efdcfsi (void)
2351 T0_64
= _do_efdcfsi(T0_64
);
2354 void do_efdcfui (void)
2356 T0_64
= _do_efdcfui(T0_64
);
2359 void do_efdctsi (void)
2361 T0_64
= _do_efdctsi(T0_64
);
2364 void do_efdctui (void)
2366 T0_64
= _do_efdctui(T0_64
);
2369 void do_efdctsiz (void)
2371 T0_64
= _do_efdctsiz(T0_64
);
2374 void do_efdctuiz (void)
2376 T0_64
= _do_efdctuiz(T0_64
);
2379 /* Double precision floating-point conversion to/from fractional */
2380 static always_inline
uint64_t _do_efdcfsf (int64_t val
)
2385 u
.d
= int32_to_float64(val
, &env
->spe_status
);
2386 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2387 u
.d
= float64_div(u
.d
, tmp
, &env
->spe_status
);
2392 static always_inline
uint64_t _do_efdcfuf (uint64_t val
)
2397 u
.d
= uint32_to_float64(val
, &env
->spe_status
);
2398 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2399 u
.d
= float64_div(u
.d
, tmp
, &env
->spe_status
);
2404 static always_inline
int64_t _do_efdctsf (uint64_t val
)
2410 /* NaN are not treated the same way IEEE 754 does */
2411 if (unlikely(isnan(u
.d
)))
2413 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2414 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2416 return float64_to_int32(u
.d
, &env
->spe_status
);
2419 static always_inline
uint64_t _do_efdctuf (uint64_t val
)
2425 /* NaN are not treated the same way IEEE 754 does */
2426 if (unlikely(isnan(u
.d
)))
2428 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2429 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2431 return float64_to_uint32(u
.d
, &env
->spe_status
);
2434 static always_inline
int64_t _do_efdctsfz (uint64_t val
)
2440 /* NaN are not treated the same way IEEE 754 does */
2441 if (unlikely(isnan(u
.d
)))
2443 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2444 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2446 return float64_to_int32_round_to_zero(u
.d
, &env
->spe_status
);
2449 static always_inline
uint64_t _do_efdctufz (uint64_t val
)
2455 /* NaN are not treated the same way IEEE 754 does */
2456 if (unlikely(isnan(u
.d
)))
2458 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2459 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2461 return float64_to_uint32_round_to_zero(u
.d
, &env
->spe_status
);
2464 void do_efdcfsf (void)
2466 T0_64
= _do_efdcfsf(T0_64
);
2469 void do_efdcfuf (void)
2471 T0_64
= _do_efdcfuf(T0_64
);
2474 void do_efdctsf (void)
2476 T0_64
= _do_efdctsf(T0_64
);
2479 void do_efdctuf (void)
2481 T0_64
= _do_efdctuf(T0_64
);
2484 void do_efdctsfz (void)
2486 T0_64
= _do_efdctsfz(T0_64
);
2489 void do_efdctufz (void)
2491 T0_64
= _do_efdctufz(T0_64
);
2494 /* Floating point conversion between single and double precision */
2495 static always_inline
uint32_t _do_efscfd (uint64_t val
)
2501 u2
.f
= float64_to_float32(u1
.d
, &env
->spe_status
);
2506 static always_inline
uint64_t _do_efdcfs (uint32_t val
)
2512 u2
.d
= float32_to_float64(u1
.f
, &env
->spe_status
);
2517 void do_efscfd (void)
2519 T0_64
= _do_efscfd(T0_64
);
2522 void do_efdcfs (void)
2524 T0_64
= _do_efdcfs(T0_64
);
2527 /* Single precision fixed-point vector arithmetic */
2543 /* Single-precision floating-point comparisons */
2544 static always_inline
int _do_efscmplt (uint32_t op1
, uint32_t op2
)
2546 /* XXX: TODO: test special values (NaN, infinites, ...) */
2547 return _do_efststlt(op1
, op2
);
2550 static always_inline
int _do_efscmpgt (uint32_t op1
, uint32_t op2
)
2552 /* XXX: TODO: test special values (NaN, infinites, ...) */
2553 return _do_efststgt(op1
, op2
);
2556 static always_inline
int _do_efscmpeq (uint32_t op1
, uint32_t op2
)
2558 /* XXX: TODO: test special values (NaN, infinites, ...) */
2559 return _do_efststeq(op1
, op2
);
2562 void do_efscmplt (void)
2564 T0
= _do_efscmplt(T0_64
, T1_64
);
2567 void do_efscmpgt (void)
2569 T0
= _do_efscmpgt(T0_64
, T1_64
);
2572 void do_efscmpeq (void)
2574 T0
= _do_efscmpeq(T0_64
, T1_64
);
2577 /* Single-precision floating-point vector comparisons */
2579 DO_SPE_CMP(fscmplt
);
2581 DO_SPE_CMP(fscmpgt
);
2583 DO_SPE_CMP(fscmpeq
);
2585 DO_SPE_CMP(fststlt
);
2587 DO_SPE_CMP(fststgt
);
2589 DO_SPE_CMP(fststeq
);
2591 /* Single-precision floating-point vector conversions */
2605 DO_SPE_OP1(fsctsiz
);
2607 DO_SPE_OP1(fsctuiz
);
2613 /*****************************************************************************/
2614 /* Softmmu support */
2615 #if !defined (CONFIG_USER_ONLY)
2617 #define MMUSUFFIX _mmu
2620 #include "softmmu_template.h"
2623 #include "softmmu_template.h"
2626 #include "softmmu_template.h"
2629 #include "softmmu_template.h"
2631 /* try to fill the TLB and return an exception if error. If retaddr is
2632 NULL, it means that the function was called in C code (i.e. not
2633 from generated code or from helper.c) */
2634 /* XXX: fix it to restore all registers */
2635 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
2637 TranslationBlock
*tb
;
2638 CPUState
*saved_env
;
2642 /* XXX: hack to restore env in all cases, even if not called from
2645 env
= cpu_single_env
;
2646 ret
= cpu_ppc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
2647 if (unlikely(ret
!= 0)) {
2648 if (likely(retaddr
)) {
2649 /* now we have a real cpu fault */
2650 pc
= (unsigned long)retaddr
;
2651 tb
= tb_find_pc(pc
);
2653 /* the PC is inside the translated code. It means that we have
2654 a virtual CPU fault */
2655 cpu_restore_state(tb
, env
, pc
, NULL
);
2658 do_raise_exception_err(env
->exception_index
, env
->error_code
);
2663 /* Software driven TLBs management */
2664 /* PowerPC 602/603 software TLB load instructions helpers */
2665 void do_load_6xx_tlb (int is_code
)
2667 target_ulong RPN
, CMP
, EPN
;
2670 RPN
= env
->spr
[SPR_RPA
];
2672 CMP
= env
->spr
[SPR_ICMP
];
2673 EPN
= env
->spr
[SPR_IMISS
];
2675 CMP
= env
->spr
[SPR_DCMP
];
2676 EPN
= env
->spr
[SPR_DMISS
];
2678 way
= (env
->spr
[SPR_SRR1
] >> 17) & 1;
2679 #if defined (DEBUG_SOFTWARE_TLB)
2680 if (loglevel
!= 0) {
2681 fprintf(logfile
, "%s: EPN " TDX
" " ADDRX
" PTE0 " ADDRX
2682 " PTE1 " ADDRX
" way %d\n",
2683 __func__
, T0
, EPN
, CMP
, RPN
, way
);
2686 /* Store this TLB */
2687 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2688 way
, is_code
, CMP
, RPN
);
2691 void do_load_74xx_tlb (int is_code
)
2693 target_ulong RPN
, CMP
, EPN
;
2696 RPN
= env
->spr
[SPR_PTELO
];
2697 CMP
= env
->spr
[SPR_PTEHI
];
2698 EPN
= env
->spr
[SPR_TLBMISS
] & ~0x3;
2699 way
= env
->spr
[SPR_TLBMISS
] & 0x3;
2700 #if defined (DEBUG_SOFTWARE_TLB)
2701 if (loglevel
!= 0) {
2702 fprintf(logfile
, "%s: EPN " TDX
" " ADDRX
" PTE0 " ADDRX
2703 " PTE1 " ADDRX
" way %d\n",
2704 __func__
, T0
, EPN
, CMP
, RPN
, way
);
2707 /* Store this TLB */
2708 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2709 way
, is_code
, CMP
, RPN
);
2712 static always_inline target_ulong
booke_tlb_to_page_size (int size
)
2714 return 1024 << (2 * size
);
2717 static always_inline
int booke_page_size_to_tlb (target_ulong page_size
)
2721 switch (page_size
) {
2755 #if defined (TARGET_PPC64)
2756 case 0x000100000000ULL
:
2759 case 0x000400000000ULL
:
2762 case 0x001000000000ULL
:
2765 case 0x004000000000ULL
:
2768 case 0x010000000000ULL
:
2780 /* Helpers for 4xx TLB management */
2781 void do_4xx_tlbre_lo (void)
2787 tlb
= &env
->tlb
[T0
].tlbe
;
2789 if (tlb
->prot
& PAGE_VALID
)
2791 size
= booke_page_size_to_tlb(tlb
->size
);
2792 if (size
< 0 || size
> 0x7)
2795 env
->spr
[SPR_40x_PID
] = tlb
->PID
;
2798 void do_4xx_tlbre_hi (void)
2803 tlb
= &env
->tlb
[T0
].tlbe
;
2805 if (tlb
->prot
& PAGE_EXEC
)
2807 if (tlb
->prot
& PAGE_WRITE
)
2811 void do_4xx_tlbwe_hi (void)
2814 target_ulong page
, end
;
2816 #if defined (DEBUG_SOFTWARE_TLB)
2817 if (loglevel
!= 0) {
2818 fprintf(logfile
, "%s T0 " TDX
" T1 " TDX
"\n", __func__
, T0
, T1
);
2822 tlb
= &env
->tlb
[T0
].tlbe
;
2823 /* Invalidate previous TLB (if it's valid) */
2824 if (tlb
->prot
& PAGE_VALID
) {
2825 end
= tlb
->EPN
+ tlb
->size
;
2826 #if defined (DEBUG_SOFTWARE_TLB)
2827 if (loglevel
!= 0) {
2828 fprintf(logfile
, "%s: invalidate old TLB %d start " ADDRX
2829 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2832 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2833 tlb_flush_page(env
, page
);
2835 tlb
->size
= booke_tlb_to_page_size((T1
>> 7) & 0x7);
2836 /* We cannot handle TLB size < TARGET_PAGE_SIZE.
2837 * If this ever occurs, one should use the ppcemb target instead
2838 * of the ppc or ppc64 one
2840 if ((T1
& 0x40) && tlb
->size
< TARGET_PAGE_SIZE
) {
2841 cpu_abort(env
, "TLB size " TARGET_FMT_lu
" < %u "
2842 "are not supported (%d)\n",
2843 tlb
->size
, TARGET_PAGE_SIZE
, (int)((T1
>> 7) & 0x7));
2845 tlb
->EPN
= T1
& ~(tlb
->size
- 1);
2847 tlb
->prot
|= PAGE_VALID
;
2849 tlb
->prot
&= ~PAGE_VALID
;
2851 /* XXX: TO BE FIXED */
2852 cpu_abort(env
, "Little-endian TLB entries are not supported by now\n");
2854 tlb
->PID
= env
->spr
[SPR_40x_PID
]; /* PID */
2855 tlb
->attr
= T1
& 0xFF;
2856 #if defined (DEBUG_SOFTWARE_TLB)
2857 if (loglevel
!= 0) {
2858 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
2859 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
2860 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
2861 tlb
->prot
& PAGE_READ
? 'r' : '-',
2862 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
2863 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
2864 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
2867 /* Invalidate new TLB (if valid) */
2868 if (tlb
->prot
& PAGE_VALID
) {
2869 end
= tlb
->EPN
+ tlb
->size
;
2870 #if defined (DEBUG_SOFTWARE_TLB)
2871 if (loglevel
!= 0) {
2872 fprintf(logfile
, "%s: invalidate TLB %d start " ADDRX
2873 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2876 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2877 tlb_flush_page(env
, page
);
2881 void do_4xx_tlbwe_lo (void)
2885 #if defined (DEBUG_SOFTWARE_TLB)
2886 if (loglevel
!= 0) {
2887 fprintf(logfile
, "%s T0 " TDX
" T1 " TDX
"\n", __func__
, T0
, T1
);
2891 tlb
= &env
->tlb
[T0
].tlbe
;
2892 tlb
->RPN
= T1
& 0xFFFFFC00;
2893 tlb
->prot
= PAGE_READ
;
2895 tlb
->prot
|= PAGE_EXEC
;
2897 tlb
->prot
|= PAGE_WRITE
;
2898 #if defined (DEBUG_SOFTWARE_TLB)
2899 if (loglevel
!= 0) {
2900 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
2901 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
2902 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
2903 tlb
->prot
& PAGE_READ
? 'r' : '-',
2904 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
2905 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
2906 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
2911 /* PowerPC 440 TLB management */
2912 void do_440_tlbwe (int word
)
2915 target_ulong EPN
, RPN
, size
;
2918 #if defined (DEBUG_SOFTWARE_TLB)
2919 if (loglevel
!= 0) {
2920 fprintf(logfile
, "%s word %d T0 " TDX
" T1 " TDX
"\n",
2921 __func__
, word
, T0
, T1
);
2926 tlb
= &env
->tlb
[T0
].tlbe
;
2929 /* Just here to please gcc */
2931 EPN
= T1
& 0xFFFFFC00;
2932 if ((tlb
->prot
& PAGE_VALID
) && EPN
!= tlb
->EPN
)
2935 size
= booke_tlb_to_page_size((T1
>> 4) & 0xF);
2936 if ((tlb
->prot
& PAGE_VALID
) && tlb
->size
< size
)
2940 tlb
->attr
|= (T1
>> 8) & 1;
2942 tlb
->prot
|= PAGE_VALID
;
2944 if (tlb
->prot
& PAGE_VALID
) {
2945 tlb
->prot
&= ~PAGE_VALID
;
2949 tlb
->PID
= env
->spr
[SPR_440_MMUCR
] & 0x000000FF;
2954 RPN
= T1
& 0xFFFFFC0F;
2955 if ((tlb
->prot
& PAGE_VALID
) && tlb
->RPN
!= RPN
)
2960 tlb
->attr
= (tlb
->attr
& 0x1) | (T1
& 0x0000FF00);
2961 tlb
->prot
= tlb
->prot
& PAGE_VALID
;
2963 tlb
->prot
|= PAGE_READ
<< 4;
2965 tlb
->prot
|= PAGE_WRITE
<< 4;
2967 tlb
->prot
|= PAGE_EXEC
<< 4;
2969 tlb
->prot
|= PAGE_READ
;
2971 tlb
->prot
|= PAGE_WRITE
;
2973 tlb
->prot
|= PAGE_EXEC
;
2978 void do_440_tlbre (int word
)
2984 tlb
= &env
->tlb
[T0
].tlbe
;
2987 /* Just here to please gcc */
2990 size
= booke_page_size_to_tlb(tlb
->size
);
2991 if (size
< 0 || size
> 0xF)
2994 if (tlb
->attr
& 0x1)
2996 if (tlb
->prot
& PAGE_VALID
)
2998 env
->spr
[SPR_440_MMUCR
] &= ~0x000000FF;
2999 env
->spr
[SPR_440_MMUCR
] |= tlb
->PID
;
3005 T0
= tlb
->attr
& ~0x1;
3006 if (tlb
->prot
& (PAGE_READ
<< 4))
3008 if (tlb
->prot
& (PAGE_WRITE
<< 4))
3010 if (tlb
->prot
& (PAGE_EXEC
<< 4))
3012 if (tlb
->prot
& PAGE_READ
)
3014 if (tlb
->prot
& PAGE_WRITE
)
3016 if (tlb
->prot
& PAGE_EXEC
)
3021 #endif /* !CONFIG_USER_ONLY */