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 uint32_t helper_load_cr (void)
67 return (env
->crf
[0] << 28) |
77 void helper_store_cr (target_ulong val
, uint32_t mask
)
81 for (i
= 0, sh
= 7; i
< 8; i
++, sh
--) {
83 env
->crf
[i
] = (val
>> (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 target_ulong
helper_cntlzw (target_ulong t
)
376 #if defined(TARGET_PPC64)
377 target_ulong
helper_cntlzd (target_ulong t
)
383 /* shift right arithmetic helper */
384 target_ulong
helper_sraw (target_ulong value
, target_ulong shift
)
388 if (likely(!(shift
& 0x20))) {
389 if (likely((uint32_t)shift
!= 0)) {
391 ret
= (int32_t)value
>> shift
;
392 if (likely(ret
>= 0 || (value
& ((1 << shift
) - 1)) == 0)) {
393 env
->xer
&= ~(1 << XER_CA
);
395 env
->xer
|= (1 << XER_CA
);
398 ret
= (int32_t)value
;
399 env
->xer
&= ~(1 << XER_CA
);
402 ret
= (int32_t)value
>> 31;
404 env
->xer
|= (1 << XER_CA
);
406 env
->xer
&= ~(1 << XER_CA
);
409 return (target_long
)ret
;
412 #if defined(TARGET_PPC64)
413 target_ulong
helper_srad (target_ulong value
, target_ulong shift
)
417 if (likely(!(shift
& 0x40))) {
418 if (likely((uint64_t)shift
!= 0)) {
420 ret
= (int64_t)value
>> shift
;
421 if (likely(ret
>= 0 || (value
& ((1 << shift
) - 1)) == 0)) {
422 env
->xer
&= ~(1 << XER_CA
);
424 env
->xer
|= (1 << XER_CA
);
427 ret
= (int64_t)value
;
428 env
->xer
&= ~(1 << XER_CA
);
431 ret
= (int64_t)value
>> 63;
433 env
->xer
|= (1 << XER_CA
);
435 env
->xer
&= ~(1 << XER_CA
);
442 target_ulong
helper_popcntb (target_ulong val
)
448 for (i
= 0; i
< 32; i
+= 8)
449 ret
|= ctpop8((val
>> i
) & 0xFF) << i
;
453 #if defined(TARGET_PPC64)
454 target_ulong
helper_popcntb_64 (target_ulong val
)
460 for (i
= 0; i
< 64; i
+= 8)
461 ret
|= ctpop8((val
>> i
) & 0xFF) << i
;
466 /*****************************************************************************/
467 /* Floating point operations helpers */
468 static always_inline
int fpisneg (float64 d
)
474 return u
.ll
>> 63 != 0;
477 static always_inline
int isden (float64 d
)
483 return ((u
.ll
>> 52) & 0x7FF) == 0;
486 static always_inline
int iszero (float64 d
)
492 return (u
.ll
& ~0x8000000000000000ULL
) == 0;
495 static always_inline
int isinfinity (float64 d
)
501 return ((u
.ll
>> 52) & 0x7FF) == 0x7FF &&
502 (u
.ll
& 0x000FFFFFFFFFFFFFULL
) == 0;
505 #ifdef CONFIG_SOFTFLOAT
506 static always_inline
int isfinite (float64 d
)
512 return (((u
.ll
>> 52) & 0x7FF) != 0x7FF);
515 static always_inline
int isnormal (float64 d
)
521 uint32_t exp
= (u
.ll
>> 52) & 0x7FF;
522 return ((0 < exp
) && (exp
< 0x7FF));
526 void do_compute_fprf (int set_fprf
)
530 isneg
= fpisneg(FT0
);
531 if (unlikely(float64_is_nan(FT0
))) {
532 if (float64_is_signaling_nan(FT0
)) {
533 /* Signaling NaN: flags are undefined */
539 } else if (unlikely(isinfinity(FT0
))) {
554 /* Denormalized numbers */
557 /* Normalized numbers */
568 /* We update FPSCR_FPRF */
569 env
->fpscr
&= ~(0x1F << FPSCR_FPRF
);
570 env
->fpscr
|= T0
<< FPSCR_FPRF
;
572 /* We just need fpcc to update Rc1 */
576 /* Floating-point invalid operations exception */
577 static always_inline
void fload_invalid_op_excp (int op
)
582 if (op
& POWERPC_EXCP_FP_VXSNAN
) {
583 /* Operation on signaling NaN */
584 env
->fpscr
|= 1 << FPSCR_VXSNAN
;
586 if (op
& POWERPC_EXCP_FP_VXSOFT
) {
587 /* Software-defined condition */
588 env
->fpscr
|= 1 << FPSCR_VXSOFT
;
590 switch (op
& ~(POWERPC_EXCP_FP_VXSOFT
| POWERPC_EXCP_FP_VXSNAN
)) {
591 case POWERPC_EXCP_FP_VXISI
:
592 /* Magnitude subtraction of infinities */
593 env
->fpscr
|= 1 << FPSCR_VXISI
;
595 case POWERPC_EXCP_FP_VXIDI
:
596 /* Division of infinity by infinity */
597 env
->fpscr
|= 1 << FPSCR_VXIDI
;
599 case POWERPC_EXCP_FP_VXZDZ
:
600 /* Division of zero by zero */
601 env
->fpscr
|= 1 << FPSCR_VXZDZ
;
603 case POWERPC_EXCP_FP_VXIMZ
:
604 /* Multiplication of zero by infinity */
605 env
->fpscr
|= 1 << FPSCR_VXIMZ
;
607 case POWERPC_EXCP_FP_VXVC
:
608 /* Ordered comparison of NaN */
609 env
->fpscr
|= 1 << FPSCR_VXVC
;
610 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
611 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
612 /* We must update the target FPR before raising the exception */
614 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
615 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_VXVC
;
616 /* Update the floating-point enabled exception summary */
617 env
->fpscr
|= 1 << FPSCR_FEX
;
618 /* Exception is differed */
622 case POWERPC_EXCP_FP_VXSQRT
:
623 /* Square root of a negative number */
624 env
->fpscr
|= 1 << FPSCR_VXSQRT
;
626 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
628 /* Set the result to quiet NaN */
630 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
631 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
634 case POWERPC_EXCP_FP_VXCVI
:
635 /* Invalid conversion */
636 env
->fpscr
|= 1 << FPSCR_VXCVI
;
637 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
639 /* Set the result to quiet NaN */
641 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
642 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
646 /* Update the floating-point invalid operation summary */
647 env
->fpscr
|= 1 << FPSCR_VX
;
648 /* Update the floating-point exception summary */
649 env
->fpscr
|= 1 << FPSCR_FX
;
651 /* Update the floating-point enabled exception summary */
652 env
->fpscr
|= 1 << FPSCR_FEX
;
653 if (msr_fe0
!= 0 || msr_fe1
!= 0)
654 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_FP
| op
);
658 static always_inline
void float_zero_divide_excp (void)
662 env
->fpscr
|= 1 << FPSCR_ZX
;
663 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
664 /* Update the floating-point exception summary */
665 env
->fpscr
|= 1 << FPSCR_FX
;
667 /* Update the floating-point enabled exception summary */
668 env
->fpscr
|= 1 << FPSCR_FEX
;
669 if (msr_fe0
!= 0 || msr_fe1
!= 0) {
670 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
671 POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
);
674 /* Set the result to infinity */
677 u0
.ll
= ((u0
.ll
^ u1
.ll
) & 0x8000000000000000ULL
);
678 u0
.ll
|= 0x7FFULL
<< 52;
683 static always_inline
void float_overflow_excp (void)
685 env
->fpscr
|= 1 << FPSCR_OX
;
686 /* Update the floating-point exception summary */
687 env
->fpscr
|= 1 << FPSCR_FX
;
689 /* XXX: should adjust the result */
690 /* Update the floating-point enabled exception summary */
691 env
->fpscr
|= 1 << FPSCR_FEX
;
692 /* We must update the target FPR before raising the exception */
693 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
694 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
696 env
->fpscr
|= 1 << FPSCR_XX
;
697 env
->fpscr
|= 1 << FPSCR_FI
;
701 static always_inline
void float_underflow_excp (void)
703 env
->fpscr
|= 1 << FPSCR_UX
;
704 /* Update the floating-point exception summary */
705 env
->fpscr
|= 1 << FPSCR_FX
;
707 /* XXX: should adjust the result */
708 /* Update the floating-point enabled exception summary */
709 env
->fpscr
|= 1 << FPSCR_FEX
;
710 /* We must update the target FPR before raising the exception */
711 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
712 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
716 static always_inline
void float_inexact_excp (void)
718 env
->fpscr
|= 1 << FPSCR_XX
;
719 /* Update the floating-point exception summary */
720 env
->fpscr
|= 1 << FPSCR_FX
;
722 /* Update the floating-point enabled exception summary */
723 env
->fpscr
|= 1 << FPSCR_FEX
;
724 /* We must update the target FPR before raising the exception */
725 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
726 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
730 static always_inline
void fpscr_set_rounding_mode (void)
734 /* Set rounding mode */
737 /* Best approximation (round to nearest) */
738 rnd_type
= float_round_nearest_even
;
741 /* Smaller magnitude (round toward zero) */
742 rnd_type
= float_round_to_zero
;
745 /* Round toward +infinite */
746 rnd_type
= float_round_up
;
750 /* Round toward -infinite */
751 rnd_type
= float_round_down
;
754 set_float_rounding_mode(rnd_type
, &env
->fp_status
);
757 void do_fpscr_setbit (int bit
)
761 prev
= (env
->fpscr
>> bit
) & 1;
762 env
->fpscr
|= 1 << bit
;
766 env
->fpscr
|= 1 << FPSCR_FX
;
770 env
->fpscr
|= 1 << FPSCR_FX
;
775 env
->fpscr
|= 1 << FPSCR_FX
;
780 env
->fpscr
|= 1 << FPSCR_FX
;
785 env
->fpscr
|= 1 << FPSCR_FX
;
798 env
->fpscr
|= 1 << FPSCR_VX
;
799 env
->fpscr
|= 1 << FPSCR_FX
;
806 env
->error_code
= POWERPC_EXCP_FP
;
808 env
->error_code
|= POWERPC_EXCP_FP_VXSNAN
;
810 env
->error_code
|= POWERPC_EXCP_FP_VXISI
;
812 env
->error_code
|= POWERPC_EXCP_FP_VXIDI
;
814 env
->error_code
|= POWERPC_EXCP_FP_VXZDZ
;
816 env
->error_code
|= POWERPC_EXCP_FP_VXIMZ
;
818 env
->error_code
|= POWERPC_EXCP_FP_VXVC
;
820 env
->error_code
|= POWERPC_EXCP_FP_VXSOFT
;
822 env
->error_code
|= POWERPC_EXCP_FP_VXSQRT
;
824 env
->error_code
|= POWERPC_EXCP_FP_VXCVI
;
831 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
838 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
845 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
;
852 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
858 fpscr_set_rounding_mode();
863 /* Update the floating-point enabled exception summary */
864 env
->fpscr
|= 1 << FPSCR_FEX
;
865 /* We have to update Rc1 before raising the exception */
866 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
872 #if defined(WORDS_BIGENDIAN)
879 void do_store_fpscr (uint32_t mask
)
882 * We use only the 32 LSB of the incoming fpr
892 new |= prev
& 0x90000000;
893 for (i
= 0; i
< 7; i
++) {
894 if (mask
& (1 << i
)) {
895 env
->fpscr
&= ~(0xF << (4 * i
));
896 env
->fpscr
|= new & (0xF << (4 * i
));
899 /* Update VX and FEX */
901 env
->fpscr
|= 1 << FPSCR_VX
;
903 env
->fpscr
&= ~(1 << FPSCR_VX
);
904 if ((fpscr_ex
& fpscr_eex
) != 0) {
905 env
->fpscr
|= 1 << FPSCR_FEX
;
906 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
907 /* XXX: we should compute it properly */
908 env
->error_code
= POWERPC_EXCP_FP
;
911 env
->fpscr
&= ~(1 << FPSCR_FEX
);
912 fpscr_set_rounding_mode();
917 #ifdef CONFIG_SOFTFLOAT
918 void do_float_check_status (void)
920 if (env
->exception_index
== POWERPC_EXCP_PROGRAM
&&
921 (env
->error_code
& POWERPC_EXCP_FP
)) {
922 /* Differred floating-point exception after target FPR update */
923 if (msr_fe0
!= 0 || msr_fe1
!= 0)
924 do_raise_exception_err(env
->exception_index
, env
->error_code
);
925 } else if (env
->fp_status
.float_exception_flags
& float_flag_overflow
) {
926 float_overflow_excp();
927 } else if (env
->fp_status
.float_exception_flags
& float_flag_underflow
) {
928 float_underflow_excp();
929 } else if (env
->fp_status
.float_exception_flags
& float_flag_inexact
) {
930 float_inexact_excp();
935 #if USE_PRECISE_EMULATION
938 if (unlikely(float64_is_signaling_nan(FT0
) ||
939 float64_is_signaling_nan(FT1
))) {
941 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
942 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
943 fpisneg(FT0
) == fpisneg(FT1
))) {
944 FT0
= float64_add(FT0
, FT1
, &env
->fp_status
);
946 /* Magnitude subtraction of infinities */
947 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
953 if (unlikely(float64_is_signaling_nan(FT0
) ||
954 float64_is_signaling_nan(FT1
))) {
955 /* sNaN subtraction */
956 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
957 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
958 fpisneg(FT0
) != fpisneg(FT1
))) {
959 FT0
= float64_sub(FT0
, FT1
, &env
->fp_status
);
961 /* Magnitude subtraction of infinities */
962 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
968 if (unlikely(float64_is_signaling_nan(FT0
) ||
969 float64_is_signaling_nan(FT1
))) {
970 /* sNaN multiplication */
971 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
972 } else if (unlikely((isinfinity(FT0
) && iszero(FT1
)) ||
973 (iszero(FT0
) && isinfinity(FT1
)))) {
974 /* Multiplication of zero by infinity */
975 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIMZ
);
977 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
983 if (unlikely(float64_is_signaling_nan(FT0
) ||
984 float64_is_signaling_nan(FT1
))) {
986 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
987 } else if (unlikely(isinfinity(FT0
) && isinfinity(FT1
))) {
988 /* Division of infinity by infinity */
989 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIDI
);
990 } else if (unlikely(iszero(FT1
))) {
992 /* Division of zero by zero */
993 fload_invalid_op_excp(POWERPC_EXCP_FP_VXZDZ
);
995 /* Division by zero */
996 float_zero_divide_excp();
999 FT0
= float64_div(FT0
, FT1
, &env
->fp_status
);
1002 #endif /* USE_PRECISE_EMULATION */
1004 void do_fctiw (void)
1008 if (unlikely(float64_is_signaling_nan(FT0
))) {
1009 /* sNaN conversion */
1010 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1011 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1012 /* qNan / infinity conversion */
1013 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1015 p
.ll
= float64_to_int32(FT0
, &env
->fp_status
);
1016 #if USE_PRECISE_EMULATION
1017 /* XXX: higher bits are not supposed to be significant.
1018 * to make tests easier, return the same as a real PowerPC 750
1020 p
.ll
|= 0xFFF80000ULL
<< 32;
1026 void do_fctiwz (void)
1030 if (unlikely(float64_is_signaling_nan(FT0
))) {
1031 /* sNaN conversion */
1032 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1033 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1034 /* qNan / infinity conversion */
1035 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1037 p
.ll
= float64_to_int32_round_to_zero(FT0
, &env
->fp_status
);
1038 #if USE_PRECISE_EMULATION
1039 /* XXX: higher bits are not supposed to be significant.
1040 * to make tests easier, return the same as a real PowerPC 750
1042 p
.ll
|= 0xFFF80000ULL
<< 32;
1048 #if defined(TARGET_PPC64)
1049 void do_fcfid (void)
1054 FT0
= int64_to_float64(p
.ll
, &env
->fp_status
);
1057 void do_fctid (void)
1061 if (unlikely(float64_is_signaling_nan(FT0
))) {
1062 /* sNaN conversion */
1063 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1064 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1065 /* qNan / infinity conversion */
1066 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1068 p
.ll
= float64_to_int64(FT0
, &env
->fp_status
);
1073 void do_fctidz (void)
1077 if (unlikely(float64_is_signaling_nan(FT0
))) {
1078 /* sNaN conversion */
1079 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1080 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1081 /* qNan / infinity conversion */
1082 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1084 p
.ll
= float64_to_int64_round_to_zero(FT0
, &env
->fp_status
);
1091 static always_inline
void do_fri (int rounding_mode
)
1093 if (unlikely(float64_is_signaling_nan(FT0
))) {
1095 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1096 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1097 /* qNan / infinity round */
1098 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1100 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
1101 FT0
= float64_round_to_int(FT0
, &env
->fp_status
);
1102 /* Restore rounding mode from FPSCR */
1103 fpscr_set_rounding_mode();
1109 do_fri(float_round_nearest_even
);
1114 do_fri(float_round_to_zero
);
1119 do_fri(float_round_up
);
1124 do_fri(float_round_down
);
1127 #if USE_PRECISE_EMULATION
1128 void do_fmadd (void)
1130 if (unlikely(float64_is_signaling_nan(FT0
) ||
1131 float64_is_signaling_nan(FT1
) ||
1132 float64_is_signaling_nan(FT2
))) {
1133 /* sNaN operation */
1134 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1137 /* This is the way the PowerPC specification defines it */
1138 float128 ft0_128
, ft1_128
;
1140 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1141 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1142 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1143 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1144 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
1145 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1147 /* This is OK on x86 hosts */
1148 FT0
= (FT0
* FT1
) + FT2
;
1153 void do_fmsub (void)
1155 if (unlikely(float64_is_signaling_nan(FT0
) ||
1156 float64_is_signaling_nan(FT1
) ||
1157 float64_is_signaling_nan(FT2
))) {
1158 /* sNaN operation */
1159 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1162 /* This is the way the PowerPC specification defines it */
1163 float128 ft0_128
, ft1_128
;
1165 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1166 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1167 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1168 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1169 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
1170 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1172 /* This is OK on x86 hosts */
1173 FT0
= (FT0
* FT1
) - FT2
;
1177 #endif /* USE_PRECISE_EMULATION */
1179 void do_fnmadd (void)
1181 if (unlikely(float64_is_signaling_nan(FT0
) ||
1182 float64_is_signaling_nan(FT1
) ||
1183 float64_is_signaling_nan(FT2
))) {
1184 /* sNaN operation */
1185 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1187 #if USE_PRECISE_EMULATION
1189 /* This is the way the PowerPC specification defines it */
1190 float128 ft0_128
, ft1_128
;
1192 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1193 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1194 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1195 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1196 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
1197 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1199 /* This is OK on x86 hosts */
1200 FT0
= (FT0
* FT1
) + FT2
;
1203 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1204 FT0
= float64_add(FT0
, FT2
, &env
->fp_status
);
1206 if (likely(!isnan(FT0
)))
1207 FT0
= float64_chs(FT0
);
1211 void do_fnmsub (void)
1213 if (unlikely(float64_is_signaling_nan(FT0
) ||
1214 float64_is_signaling_nan(FT1
) ||
1215 float64_is_signaling_nan(FT2
))) {
1216 /* sNaN operation */
1217 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1219 #if USE_PRECISE_EMULATION
1221 /* This is the way the PowerPC specification defines it */
1222 float128 ft0_128
, ft1_128
;
1224 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1225 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1226 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1227 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1228 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
1229 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1231 /* This is OK on x86 hosts */
1232 FT0
= (FT0
* FT1
) - FT2
;
1235 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1236 FT0
= float64_sub(FT0
, FT2
, &env
->fp_status
);
1238 if (likely(!isnan(FT0
)))
1239 FT0
= float64_chs(FT0
);
1243 #if USE_PRECISE_EMULATION
1246 if (unlikely(float64_is_signaling_nan(FT0
))) {
1247 /* sNaN square root */
1248 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1250 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1253 #endif /* USE_PRECISE_EMULATION */
1255 void do_fsqrt (void)
1257 if (unlikely(float64_is_signaling_nan(FT0
))) {
1258 /* sNaN square root */
1259 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1260 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1261 /* Square root of a negative nonzero number */
1262 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1264 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1272 if (unlikely(float64_is_signaling_nan(FT0
))) {
1273 /* sNaN reciprocal */
1274 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1275 } else if (unlikely(iszero(FT0
))) {
1276 /* Zero reciprocal */
1277 float_zero_divide_excp();
1278 } else if (likely(isnormal(FT0
))) {
1279 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1282 if (p
.ll
== 0x8000000000000000ULL
) {
1283 p
.ll
= 0xFFF0000000000000ULL
;
1284 } else if (p
.ll
== 0x0000000000000000ULL
) {
1285 p
.ll
= 0x7FF0000000000000ULL
;
1286 } else if (isnan(FT0
)) {
1287 p
.ll
= 0x7FF8000000000000ULL
;
1288 } else if (fpisneg(FT0
)) {
1289 p
.ll
= 0x8000000000000000ULL
;
1291 p
.ll
= 0x0000000000000000ULL
;
1301 if (unlikely(float64_is_signaling_nan(FT0
))) {
1302 /* sNaN reciprocal */
1303 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1304 } else if (unlikely(iszero(FT0
))) {
1305 /* Zero reciprocal */
1306 float_zero_divide_excp();
1307 } else if (likely(isnormal(FT0
))) {
1308 #if USE_PRECISE_EMULATION
1309 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1310 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1312 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1316 if (p
.ll
== 0x8000000000000000ULL
) {
1317 p
.ll
= 0xFFF0000000000000ULL
;
1318 } else if (p
.ll
== 0x0000000000000000ULL
) {
1319 p
.ll
= 0x7FF0000000000000ULL
;
1320 } else if (isnan(FT0
)) {
1321 p
.ll
= 0x7FF8000000000000ULL
;
1322 } else if (fpisneg(FT0
)) {
1323 p
.ll
= 0x8000000000000000ULL
;
1325 p
.ll
= 0x0000000000000000ULL
;
1331 void do_frsqrte (void)
1335 if (unlikely(float64_is_signaling_nan(FT0
))) {
1336 /* sNaN reciprocal square root */
1337 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1338 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1339 /* Reciprocal square root of a negative nonzero number */
1340 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1341 } else if (likely(isnormal(FT0
))) {
1342 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1343 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1346 if (p
.ll
== 0x8000000000000000ULL
) {
1347 p
.ll
= 0xFFF0000000000000ULL
;
1348 } else if (p
.ll
== 0x0000000000000000ULL
) {
1349 p
.ll
= 0x7FF0000000000000ULL
;
1350 } else if (isnan(FT0
)) {
1351 p
.ll
|= 0x000FFFFFFFFFFFFFULL
;
1352 } else if (fpisneg(FT0
)) {
1353 p
.ll
= 0x7FF8000000000000ULL
;
1355 p
.ll
= 0x0000000000000000ULL
;
1363 if (!fpisneg(FT0
) || iszero(FT0
))
1369 uint32_t helper_fcmpu (void)
1373 if (unlikely(float64_is_signaling_nan(FT0
) ||
1374 float64_is_signaling_nan(FT1
))) {
1375 /* sNaN comparison */
1376 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1378 if (float64_lt(FT0
, FT1
, &env
->fp_status
)) {
1380 } else if (!float64_le(FT0
, FT1
, &env
->fp_status
)) {
1386 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1387 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1391 uint32_t helper_fcmpo (void)
1395 if (unlikely(float64_is_nan(FT0
) ||
1396 float64_is_nan(FT1
))) {
1397 if (float64_is_signaling_nan(FT0
) ||
1398 float64_is_signaling_nan(FT1
)) {
1399 /* sNaN comparison */
1400 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
|
1401 POWERPC_EXCP_FP_VXVC
);
1403 /* qNaN comparison */
1404 fload_invalid_op_excp(POWERPC_EXCP_FP_VXVC
);
1407 if (float64_lt(FT0
, FT1
, &env
->fp_status
)) {
1409 } else if (!float64_le(FT0
, FT1
, &env
->fp_status
)) {
1415 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1416 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1420 #if !defined (CONFIG_USER_ONLY)
1421 void cpu_dump_rfi (target_ulong RA
, target_ulong msr
);
1423 void do_store_msr (void)
1425 T0
= hreg_store_msr(env
, T0
, 0);
1427 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1428 do_raise_exception(T0
);
1432 static always_inline
void __do_rfi (target_ulong nip
, target_ulong msr
,
1433 target_ulong msrm
, int keep_msrh
)
1435 #if defined(TARGET_PPC64)
1436 if (msr
& (1ULL << MSR_SF
)) {
1437 nip
= (uint64_t)nip
;
1438 msr
&= (uint64_t)msrm
;
1440 nip
= (uint32_t)nip
;
1441 msr
= (uint32_t)(msr
& msrm
);
1443 msr
|= env
->msr
& ~((uint64_t)0xFFFFFFFF);
1446 nip
= (uint32_t)nip
;
1447 msr
&= (uint32_t)msrm
;
1449 /* XXX: beware: this is false if VLE is supported */
1450 env
->nip
= nip
& ~((target_ulong
)0x00000003);
1451 hreg_store_msr(env
, msr
, 1);
1452 #if defined (DEBUG_OP)
1453 cpu_dump_rfi(env
->nip
, env
->msr
);
1455 /* No need to raise an exception here,
1456 * as rfi is always the last insn of a TB
1458 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1463 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1464 ~((target_ulong
)0xFFFF0000), 1);
1467 #if defined(TARGET_PPC64)
1470 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1471 ~((target_ulong
)0xFFFF0000), 0);
1474 void do_hrfid (void)
1476 __do_rfi(env
->spr
[SPR_HSRR0
], env
->spr
[SPR_HSRR1
],
1477 ~((target_ulong
)0xFFFF0000), 0);
1482 void do_tw (int flags
)
1484 if (!likely(!(((int32_t)T0
< (int32_t)T1
&& (flags
& 0x10)) ||
1485 ((int32_t)T0
> (int32_t)T1
&& (flags
& 0x08)) ||
1486 ((int32_t)T0
== (int32_t)T1
&& (flags
& 0x04)) ||
1487 ((uint32_t)T0
< (uint32_t)T1
&& (flags
& 0x02)) ||
1488 ((uint32_t)T0
> (uint32_t)T1
&& (flags
& 0x01))))) {
1489 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1493 #if defined(TARGET_PPC64)
1494 void do_td (int flags
)
1496 if (!likely(!(((int64_t)T0
< (int64_t)T1
&& (flags
& 0x10)) ||
1497 ((int64_t)T0
> (int64_t)T1
&& (flags
& 0x08)) ||
1498 ((int64_t)T0
== (int64_t)T1
&& (flags
& 0x04)) ||
1499 ((uint64_t)T0
< (uint64_t)T1
&& (flags
& 0x02)) ||
1500 ((uint64_t)T0
> (uint64_t)T1
&& (flags
& 0x01)))))
1501 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1505 /*****************************************************************************/
1506 /* PowerPC 601 specific instructions (POWER bridge) */
1507 void do_POWER_abso (void)
1509 if ((int32_t)T0
== INT32_MIN
) {
1511 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1512 } else if ((int32_t)T0
< 0) {
1514 env
->xer
&= ~(1 << XER_OV
);
1516 env
->xer
&= ~(1 << XER_OV
);
1520 void do_POWER_clcs (void)
1524 /* Instruction cache line size */
1525 T0
= env
->icache_line_size
;
1528 /* Data cache line size */
1529 T0
= env
->dcache_line_size
;
1532 /* Minimum cache line size */
1533 T0
= env
->icache_line_size
< env
->dcache_line_size
?
1534 env
->icache_line_size
: env
->dcache_line_size
;
1537 /* Maximum cache line size */
1538 T0
= env
->icache_line_size
> env
->dcache_line_size
?
1539 env
->icache_line_size
: env
->dcache_line_size
;
1547 void do_POWER_div (void)
1551 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1553 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1554 env
->spr
[SPR_MQ
] = 0;
1556 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1557 env
->spr
[SPR_MQ
] = tmp
% T1
;
1558 T0
= tmp
/ (int32_t)T1
;
1562 void do_POWER_divo (void)
1566 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1568 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1569 env
->spr
[SPR_MQ
] = 0;
1570 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1572 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1573 env
->spr
[SPR_MQ
] = tmp
% T1
;
1575 if (tmp
> (int64_t)INT32_MAX
|| tmp
< (int64_t)INT32_MIN
) {
1576 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1578 env
->xer
&= ~(1 << XER_OV
);
1584 void do_POWER_divs (void)
1586 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1588 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1589 env
->spr
[SPR_MQ
] = 0;
1591 env
->spr
[SPR_MQ
] = T0
% T1
;
1592 T0
= (int32_t)T0
/ (int32_t)T1
;
1596 void do_POWER_divso (void)
1598 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1600 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1601 env
->spr
[SPR_MQ
] = 0;
1602 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1604 T0
= (int32_t)T0
/ (int32_t)T1
;
1605 env
->spr
[SPR_MQ
] = (int32_t)T0
% (int32_t)T1
;
1606 env
->xer
&= ~(1 << XER_OV
);
1610 void do_POWER_dozo (void)
1612 if ((int32_t)T1
> (int32_t)T0
) {
1615 if (((uint32_t)(~T2
) ^ (uint32_t)T1
^ UINT32_MAX
) &
1616 ((uint32_t)(~T2
) ^ (uint32_t)T0
) & (1UL << 31)) {
1617 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1619 env
->xer
&= ~(1 << XER_OV
);
1623 env
->xer
&= ~(1 << XER_OV
);
1627 void do_POWER_maskg (void)
1631 if ((uint32_t)T0
== (uint32_t)(T1
+ 1)) {
1634 ret
= (UINT32_MAX
>> ((uint32_t)T0
)) ^
1635 ((UINT32_MAX
>> ((uint32_t)T1
)) >> 1);
1636 if ((uint32_t)T0
> (uint32_t)T1
)
1642 void do_POWER_mulo (void)
1646 tmp
= (uint64_t)T0
* (uint64_t)T1
;
1647 env
->spr
[SPR_MQ
] = tmp
>> 32;
1649 if (tmp
>> 32 != ((uint64_t)T0
>> 16) * ((uint64_t)T1
>> 16)) {
1650 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1652 env
->xer
&= ~(1 << XER_OV
);
1656 #if !defined (CONFIG_USER_ONLY)
1657 void do_POWER_rac (void)
1662 /* We don't have to generate many instances of this instruction,
1663 * as rac is supervisor only.
1665 /* XXX: FIX THIS: Pretend we have no BAT */
1666 nb_BATs
= env
->nb_BATs
;
1668 if (get_physical_address(env
, &ctx
, T0
, 0, ACCESS_INT
) == 0)
1670 env
->nb_BATs
= nb_BATs
;
1673 void do_POWER_rfsvc (void)
1675 __do_rfi(env
->lr
, env
->ctr
, 0x0000FFFF, 0);
1678 void do_store_hid0_601 (void)
1682 hid0
= env
->spr
[SPR_HID0
];
1683 if ((T0
^ hid0
) & 0x00000008) {
1684 /* Change current endianness */
1685 env
->hflags
&= ~(1 << MSR_LE
);
1686 env
->hflags_nmsr
&= ~(1 << MSR_LE
);
1687 env
->hflags_nmsr
|= (1 << MSR_LE
) & (((T0
>> 3) & 1) << MSR_LE
);
1688 env
->hflags
|= env
->hflags_nmsr
;
1689 if (loglevel
!= 0) {
1690 fprintf(logfile
, "%s: set endianness to %c => " ADDRX
"\n",
1691 __func__
, T0
& 0x8 ? 'l' : 'b', env
->hflags
);
1694 env
->spr
[SPR_HID0
] = T0
;
1698 /*****************************************************************************/
1699 /* 602 specific instructions */
1700 /* mfrom is the most crazy instruction ever seen, imho ! */
1701 /* Real implementation uses a ROM table. Do the same */
1702 #define USE_MFROM_ROM_TABLE
1703 void do_op_602_mfrom (void)
1705 if (likely(T0
< 602)) {
1706 #if defined(USE_MFROM_ROM_TABLE)
1707 #include "mfrom_table.c"
1708 T0
= mfrom_ROM_table
[T0
];
1711 /* Extremly decomposed:
1713 * T0 = 256 * log10(10 + 1.0) + 0.5
1716 d
= float64_div(d
, 256, &env
->fp_status
);
1718 d
= exp10(d
); // XXX: use float emulation function
1719 d
= float64_add(d
, 1.0, &env
->fp_status
);
1720 d
= log10(d
); // XXX: use float emulation function
1721 d
= float64_mul(d
, 256, &env
->fp_status
);
1722 d
= float64_add(d
, 0.5, &env
->fp_status
);
1723 T0
= float64_round_to_int(d
, &env
->fp_status
);
1730 /*****************************************************************************/
1731 /* Embedded PowerPC specific helpers */
1732 void do_405_check_sat (void)
1734 if (!likely((((uint32_t)T1
^ (uint32_t)T2
) >> 31) ||
1735 !(((uint32_t)T0
^ (uint32_t)T2
) >> 31))) {
1736 /* Saturate result */
1745 /* XXX: to be improved to check access rights when in user-mode */
1746 void do_load_dcr (void)
1750 if (unlikely(env
->dcr_env
== NULL
)) {
1751 if (loglevel
!= 0) {
1752 fprintf(logfile
, "No DCR environment\n");
1754 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1755 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1756 } else if (unlikely(ppc_dcr_read(env
->dcr_env
, T0
, &val
) != 0)) {
1757 if (loglevel
!= 0) {
1758 fprintf(logfile
, "DCR read error %d %03x\n", (int)T0
, (int)T0
);
1760 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1761 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1767 void do_store_dcr (void)
1769 if (unlikely(env
->dcr_env
== NULL
)) {
1770 if (loglevel
!= 0) {
1771 fprintf(logfile
, "No DCR environment\n");
1773 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1774 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1775 } else if (unlikely(ppc_dcr_write(env
->dcr_env
, T0
, T1
) != 0)) {
1776 if (loglevel
!= 0) {
1777 fprintf(logfile
, "DCR write error %d %03x\n", (int)T0
, (int)T0
);
1779 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1780 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1784 #if !defined(CONFIG_USER_ONLY)
1785 void do_40x_rfci (void)
1787 __do_rfi(env
->spr
[SPR_40x_SRR2
], env
->spr
[SPR_40x_SRR3
],
1788 ~((target_ulong
)0xFFFF0000), 0);
1793 __do_rfi(env
->spr
[SPR_BOOKE_CSRR0
], SPR_BOOKE_CSRR1
,
1794 ~((target_ulong
)0x3FFF0000), 0);
1799 __do_rfi(env
->spr
[SPR_BOOKE_DSRR0
], SPR_BOOKE_DSRR1
,
1800 ~((target_ulong
)0x3FFF0000), 0);
1803 void do_rfmci (void)
1805 __do_rfi(env
->spr
[SPR_BOOKE_MCSRR0
], SPR_BOOKE_MCSRR1
,
1806 ~((target_ulong
)0x3FFF0000), 0);
1809 void do_load_403_pb (int num
)
1814 void do_store_403_pb (int num
)
1816 if (likely(env
->pb
[num
] != T0
)) {
1818 /* Should be optimized */
1825 void do_440_dlmzb (void)
1831 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1832 if ((T0
& mask
) == 0)
1836 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1837 if ((T1
& mask
) == 0)
1845 /* SPE extension helpers */
1846 /* Use a table to make this quicker */
1847 static uint8_t hbrev
[16] = {
1848 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
1849 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF,
1852 static always_inline
uint8_t byte_reverse (uint8_t val
)
1854 return hbrev
[val
>> 4] | (hbrev
[val
& 0xF] << 4);
1857 static always_inline
uint32_t word_reverse (uint32_t val
)
1859 return byte_reverse(val
>> 24) | (byte_reverse(val
>> 16) << 8) |
1860 (byte_reverse(val
>> 8) << 16) | (byte_reverse(val
) << 24);
1863 #define MASKBITS 16 // Random value - to be fixed (implementation dependant)
1864 void do_brinc (void)
1866 uint32_t a
, b
, d
, mask
;
1868 mask
= UINT32_MAX
>> (32 - MASKBITS
);
1871 d
= word_reverse(1 + word_reverse(a
| ~b
));
1872 T0
= (T0
& ~mask
) | (d
& b
);
1875 #define DO_SPE_OP2(name) \
1876 void do_ev##name (void) \
1878 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) | \
1879 (uint64_t)_do_e##name(T0_64, T1_64); \
1882 #define DO_SPE_OP1(name) \
1883 void do_ev##name (void) \
1885 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) | \
1886 (uint64_t)_do_e##name(T0_64); \
1889 /* Fixed-point vector arithmetic */
1890 static always_inline
uint32_t _do_eabs (uint32_t val
)
1892 if ((val
& 0x80000000) && val
!= 0x80000000)
1898 static always_inline
uint32_t _do_eaddw (uint32_t op1
, uint32_t op2
)
1903 static always_inline
int _do_ecntlsw (uint32_t val
)
1905 if (val
& 0x80000000)
1911 static always_inline
int _do_ecntlzw (uint32_t val
)
1916 static always_inline
uint32_t _do_eneg (uint32_t val
)
1918 if (val
!= 0x80000000)
1924 static always_inline
uint32_t _do_erlw (uint32_t op1
, uint32_t op2
)
1926 return rotl32(op1
, op2
);
1929 static always_inline
uint32_t _do_erndw (uint32_t val
)
1931 return (val
+ 0x000080000000) & 0xFFFF0000;
1934 static always_inline
uint32_t _do_eslw (uint32_t op1
, uint32_t op2
)
1936 /* No error here: 6 bits are used */
1937 return op1
<< (op2
& 0x3F);
1940 static always_inline
int32_t _do_esrws (int32_t op1
, uint32_t op2
)
1942 /* No error here: 6 bits are used */
1943 return op1
>> (op2
& 0x3F);
1946 static always_inline
uint32_t _do_esrwu (uint32_t op1
, uint32_t op2
)
1948 /* No error here: 6 bits are used */
1949 return op1
>> (op2
& 0x3F);
1952 static always_inline
uint32_t _do_esubfw (uint32_t op1
, uint32_t op2
)
1980 /* evsel is a little bit more complicated... */
1981 static always_inline
uint32_t _do_esel (uint32_t op1
, uint32_t op2
, int n
)
1989 void do_evsel (void)
1991 T0_64
= ((uint64_t)_do_esel(T0_64
>> 32, T1_64
>> 32, T0
>> 3) << 32) |
1992 (uint64_t)_do_esel(T0_64
, T1_64
, (T0
>> 2) & 1);
1995 /* Fixed-point vector comparisons */
1996 #define DO_SPE_CMP(name) \
1997 void do_ev##name (void) \
1999 T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32, \
2000 T1_64 >> 32) << 32, \
2001 _do_e##name(T0_64, T1_64)); \
2004 static always_inline
uint32_t _do_evcmp_merge (int t0
, int t1
)
2006 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
2008 static always_inline
int _do_ecmpeq (uint32_t op1
, uint32_t op2
)
2010 return op1
== op2
? 1 : 0;
2013 static always_inline
int _do_ecmpgts (int32_t op1
, int32_t op2
)
2015 return op1
> op2
? 1 : 0;
2018 static always_inline
int _do_ecmpgtu (uint32_t op1
, uint32_t op2
)
2020 return op1
> op2
? 1 : 0;
2023 static always_inline
int _do_ecmplts (int32_t op1
, int32_t op2
)
2025 return op1
< op2
? 1 : 0;
2028 static always_inline
int _do_ecmpltu (uint32_t op1
, uint32_t op2
)
2030 return op1
< op2
? 1 : 0;
2044 /* Single precision floating-point conversions from/to integer */
2045 static always_inline
uint32_t _do_efscfsi (int32_t val
)
2049 u
.f
= int32_to_float32(val
, &env
->spe_status
);
2054 static always_inline
uint32_t _do_efscfui (uint32_t val
)
2058 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
2063 static always_inline
int32_t _do_efsctsi (uint32_t val
)
2068 /* NaN are not treated the same way IEEE 754 does */
2069 if (unlikely(isnan(u
.f
)))
2072 return float32_to_int32(u
.f
, &env
->spe_status
);
2075 static always_inline
uint32_t _do_efsctui (uint32_t val
)
2080 /* NaN are not treated the same way IEEE 754 does */
2081 if (unlikely(isnan(u
.f
)))
2084 return float32_to_uint32(u
.f
, &env
->spe_status
);
2087 static always_inline
int32_t _do_efsctsiz (uint32_t val
)
2092 /* NaN are not treated the same way IEEE 754 does */
2093 if (unlikely(isnan(u
.f
)))
2096 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
2099 static always_inline
uint32_t _do_efsctuiz (uint32_t val
)
2104 /* NaN are not treated the same way IEEE 754 does */
2105 if (unlikely(isnan(u
.f
)))
2108 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
2111 void do_efscfsi (void)
2113 T0_64
= _do_efscfsi(T0_64
);
2116 void do_efscfui (void)
2118 T0_64
= _do_efscfui(T0_64
);
2121 void do_efsctsi (void)
2123 T0_64
= _do_efsctsi(T0_64
);
2126 void do_efsctui (void)
2128 T0_64
= _do_efsctui(T0_64
);
2131 void do_efsctsiz (void)
2133 T0_64
= _do_efsctsiz(T0_64
);
2136 void do_efsctuiz (void)
2138 T0_64
= _do_efsctuiz(T0_64
);
2141 /* Single precision floating-point conversion to/from fractional */
2142 static always_inline
uint32_t _do_efscfsf (uint32_t val
)
2147 u
.f
= int32_to_float32(val
, &env
->spe_status
);
2148 tmp
= int64_to_float32(1ULL << 32, &env
->spe_status
);
2149 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
2154 static always_inline
uint32_t _do_efscfuf (uint32_t val
)
2159 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
2160 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2161 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
2166 static always_inline
int32_t _do_efsctsf (uint32_t val
)
2172 /* NaN are not treated the same way IEEE 754 does */
2173 if (unlikely(isnan(u
.f
)))
2175 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2176 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2178 return float32_to_int32(u
.f
, &env
->spe_status
);
2181 static always_inline
uint32_t _do_efsctuf (uint32_t val
)
2187 /* NaN are not treated the same way IEEE 754 does */
2188 if (unlikely(isnan(u
.f
)))
2190 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2191 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2193 return float32_to_uint32(u
.f
, &env
->spe_status
);
2196 static always_inline
int32_t _do_efsctsfz (uint32_t val
)
2202 /* NaN are not treated the same way IEEE 754 does */
2203 if (unlikely(isnan(u
.f
)))
2205 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2206 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2208 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
2211 static always_inline
uint32_t _do_efsctufz (uint32_t val
)
2217 /* NaN are not treated the same way IEEE 754 does */
2218 if (unlikely(isnan(u
.f
)))
2220 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2221 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2223 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
2226 void do_efscfsf (void)
2228 T0_64
= _do_efscfsf(T0_64
);
2231 void do_efscfuf (void)
2233 T0_64
= _do_efscfuf(T0_64
);
2236 void do_efsctsf (void)
2238 T0_64
= _do_efsctsf(T0_64
);
2241 void do_efsctuf (void)
2243 T0_64
= _do_efsctuf(T0_64
);
2246 void do_efsctsfz (void)
2248 T0_64
= _do_efsctsfz(T0_64
);
2251 void do_efsctufz (void)
2253 T0_64
= _do_efsctufz(T0_64
);
2256 /* Double precision floating point helpers */
2257 static always_inline
int _do_efdcmplt (uint64_t op1
, uint64_t op2
)
2259 /* XXX: TODO: test special values (NaN, infinites, ...) */
2260 return _do_efdtstlt(op1
, op2
);
2263 static always_inline
int _do_efdcmpgt (uint64_t op1
, uint64_t op2
)
2265 /* XXX: TODO: test special values (NaN, infinites, ...) */
2266 return _do_efdtstgt(op1
, op2
);
2269 static always_inline
int _do_efdcmpeq (uint64_t op1
, uint64_t op2
)
2271 /* XXX: TODO: test special values (NaN, infinites, ...) */
2272 return _do_efdtsteq(op1
, op2
);
2275 void do_efdcmplt (void)
2277 T0
= _do_efdcmplt(T0_64
, T1_64
);
2280 void do_efdcmpgt (void)
2282 T0
= _do_efdcmpgt(T0_64
, T1_64
);
2285 void do_efdcmpeq (void)
2287 T0
= _do_efdcmpeq(T0_64
, T1_64
);
2290 /* Double precision floating-point conversion to/from integer */
2291 static always_inline
uint64_t _do_efdcfsi (int64_t val
)
2295 u
.d
= int64_to_float64(val
, &env
->spe_status
);
2300 static always_inline
uint64_t _do_efdcfui (uint64_t val
)
2304 u
.d
= uint64_to_float64(val
, &env
->spe_status
);
2309 static always_inline
int64_t _do_efdctsi (uint64_t val
)
2314 /* NaN are not treated the same way IEEE 754 does */
2315 if (unlikely(isnan(u
.d
)))
2318 return float64_to_int64(u
.d
, &env
->spe_status
);
2321 static always_inline
uint64_t _do_efdctui (uint64_t val
)
2326 /* NaN are not treated the same way IEEE 754 does */
2327 if (unlikely(isnan(u
.d
)))
2330 return float64_to_uint64(u
.d
, &env
->spe_status
);
2333 static always_inline
int64_t _do_efdctsiz (uint64_t val
)
2338 /* NaN are not treated the same way IEEE 754 does */
2339 if (unlikely(isnan(u
.d
)))
2342 return float64_to_int64_round_to_zero(u
.d
, &env
->spe_status
);
2345 static always_inline
uint64_t _do_efdctuiz (uint64_t val
)
2350 /* NaN are not treated the same way IEEE 754 does */
2351 if (unlikely(isnan(u
.d
)))
2354 return float64_to_uint64_round_to_zero(u
.d
, &env
->spe_status
);
2357 void do_efdcfsi (void)
2359 T0_64
= _do_efdcfsi(T0_64
);
2362 void do_efdcfui (void)
2364 T0_64
= _do_efdcfui(T0_64
);
2367 void do_efdctsi (void)
2369 T0_64
= _do_efdctsi(T0_64
);
2372 void do_efdctui (void)
2374 T0_64
= _do_efdctui(T0_64
);
2377 void do_efdctsiz (void)
2379 T0_64
= _do_efdctsiz(T0_64
);
2382 void do_efdctuiz (void)
2384 T0_64
= _do_efdctuiz(T0_64
);
2387 /* Double precision floating-point conversion to/from fractional */
2388 static always_inline
uint64_t _do_efdcfsf (int64_t val
)
2393 u
.d
= int32_to_float64(val
, &env
->spe_status
);
2394 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2395 u
.d
= float64_div(u
.d
, tmp
, &env
->spe_status
);
2400 static always_inline
uint64_t _do_efdcfuf (uint64_t val
)
2405 u
.d
= uint32_to_float64(val
, &env
->spe_status
);
2406 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2407 u
.d
= float64_div(u
.d
, tmp
, &env
->spe_status
);
2412 static always_inline
int64_t _do_efdctsf (uint64_t val
)
2418 /* NaN are not treated the same way IEEE 754 does */
2419 if (unlikely(isnan(u
.d
)))
2421 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2422 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2424 return float64_to_int32(u
.d
, &env
->spe_status
);
2427 static always_inline
uint64_t _do_efdctuf (uint64_t val
)
2433 /* NaN are not treated the same way IEEE 754 does */
2434 if (unlikely(isnan(u
.d
)))
2436 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2437 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2439 return float64_to_uint32(u
.d
, &env
->spe_status
);
2442 static always_inline
int64_t _do_efdctsfz (uint64_t val
)
2448 /* NaN are not treated the same way IEEE 754 does */
2449 if (unlikely(isnan(u
.d
)))
2451 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2452 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2454 return float64_to_int32_round_to_zero(u
.d
, &env
->spe_status
);
2457 static always_inline
uint64_t _do_efdctufz (uint64_t val
)
2463 /* NaN are not treated the same way IEEE 754 does */
2464 if (unlikely(isnan(u
.d
)))
2466 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2467 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2469 return float64_to_uint32_round_to_zero(u
.d
, &env
->spe_status
);
2472 void do_efdcfsf (void)
2474 T0_64
= _do_efdcfsf(T0_64
);
2477 void do_efdcfuf (void)
2479 T0_64
= _do_efdcfuf(T0_64
);
2482 void do_efdctsf (void)
2484 T0_64
= _do_efdctsf(T0_64
);
2487 void do_efdctuf (void)
2489 T0_64
= _do_efdctuf(T0_64
);
2492 void do_efdctsfz (void)
2494 T0_64
= _do_efdctsfz(T0_64
);
2497 void do_efdctufz (void)
2499 T0_64
= _do_efdctufz(T0_64
);
2502 /* Floating point conversion between single and double precision */
2503 static always_inline
uint32_t _do_efscfd (uint64_t val
)
2509 u2
.f
= float64_to_float32(u1
.d
, &env
->spe_status
);
2514 static always_inline
uint64_t _do_efdcfs (uint32_t val
)
2520 u2
.d
= float32_to_float64(u1
.f
, &env
->spe_status
);
2525 void do_efscfd (void)
2527 T0_64
= _do_efscfd(T0_64
);
2530 void do_efdcfs (void)
2532 T0_64
= _do_efdcfs(T0_64
);
2535 /* Single precision fixed-point vector arithmetic */
2551 /* Single-precision floating-point comparisons */
2552 static always_inline
int _do_efscmplt (uint32_t op1
, uint32_t op2
)
2554 /* XXX: TODO: test special values (NaN, infinites, ...) */
2555 return _do_efststlt(op1
, op2
);
2558 static always_inline
int _do_efscmpgt (uint32_t op1
, uint32_t op2
)
2560 /* XXX: TODO: test special values (NaN, infinites, ...) */
2561 return _do_efststgt(op1
, op2
);
2564 static always_inline
int _do_efscmpeq (uint32_t op1
, uint32_t op2
)
2566 /* XXX: TODO: test special values (NaN, infinites, ...) */
2567 return _do_efststeq(op1
, op2
);
2570 void do_efscmplt (void)
2572 T0
= _do_efscmplt(T0_64
, T1_64
);
2575 void do_efscmpgt (void)
2577 T0
= _do_efscmpgt(T0_64
, T1_64
);
2580 void do_efscmpeq (void)
2582 T0
= _do_efscmpeq(T0_64
, T1_64
);
2585 /* Single-precision floating-point vector comparisons */
2587 DO_SPE_CMP(fscmplt
);
2589 DO_SPE_CMP(fscmpgt
);
2591 DO_SPE_CMP(fscmpeq
);
2593 DO_SPE_CMP(fststlt
);
2595 DO_SPE_CMP(fststgt
);
2597 DO_SPE_CMP(fststeq
);
2599 /* Single-precision floating-point vector conversions */
2613 DO_SPE_OP1(fsctsiz
);
2615 DO_SPE_OP1(fsctuiz
);
2621 /*****************************************************************************/
2622 /* Softmmu support */
2623 #if !defined (CONFIG_USER_ONLY)
2625 #define MMUSUFFIX _mmu
2628 #include "softmmu_template.h"
2631 #include "softmmu_template.h"
2634 #include "softmmu_template.h"
2637 #include "softmmu_template.h"
2639 /* try to fill the TLB and return an exception if error. If retaddr is
2640 NULL, it means that the function was called in C code (i.e. not
2641 from generated code or from helper.c) */
2642 /* XXX: fix it to restore all registers */
2643 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
2645 TranslationBlock
*tb
;
2646 CPUState
*saved_env
;
2650 /* XXX: hack to restore env in all cases, even if not called from
2653 env
= cpu_single_env
;
2654 ret
= cpu_ppc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
2655 if (unlikely(ret
!= 0)) {
2656 if (likely(retaddr
)) {
2657 /* now we have a real cpu fault */
2658 pc
= (unsigned long)retaddr
;
2659 tb
= tb_find_pc(pc
);
2661 /* the PC is inside the translated code. It means that we have
2662 a virtual CPU fault */
2663 cpu_restore_state(tb
, env
, pc
, NULL
);
2666 do_raise_exception_err(env
->exception_index
, env
->error_code
);
2671 /* Software driven TLBs management */
2672 /* PowerPC 602/603 software TLB load instructions helpers */
2673 void do_load_6xx_tlb (int is_code
)
2675 target_ulong RPN
, CMP
, EPN
;
2678 RPN
= env
->spr
[SPR_RPA
];
2680 CMP
= env
->spr
[SPR_ICMP
];
2681 EPN
= env
->spr
[SPR_IMISS
];
2683 CMP
= env
->spr
[SPR_DCMP
];
2684 EPN
= env
->spr
[SPR_DMISS
];
2686 way
= (env
->spr
[SPR_SRR1
] >> 17) & 1;
2687 #if defined (DEBUG_SOFTWARE_TLB)
2688 if (loglevel
!= 0) {
2689 fprintf(logfile
, "%s: EPN " TDX
" " ADDRX
" PTE0 " ADDRX
2690 " PTE1 " ADDRX
" way %d\n",
2691 __func__
, T0
, EPN
, CMP
, RPN
, way
);
2694 /* Store this TLB */
2695 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2696 way
, is_code
, CMP
, RPN
);
2699 void do_load_74xx_tlb (int is_code
)
2701 target_ulong RPN
, CMP
, EPN
;
2704 RPN
= env
->spr
[SPR_PTELO
];
2705 CMP
= env
->spr
[SPR_PTEHI
];
2706 EPN
= env
->spr
[SPR_TLBMISS
] & ~0x3;
2707 way
= env
->spr
[SPR_TLBMISS
] & 0x3;
2708 #if defined (DEBUG_SOFTWARE_TLB)
2709 if (loglevel
!= 0) {
2710 fprintf(logfile
, "%s: EPN " TDX
" " ADDRX
" PTE0 " ADDRX
2711 " PTE1 " ADDRX
" way %d\n",
2712 __func__
, T0
, EPN
, CMP
, RPN
, way
);
2715 /* Store this TLB */
2716 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2717 way
, is_code
, CMP
, RPN
);
2720 static always_inline target_ulong
booke_tlb_to_page_size (int size
)
2722 return 1024 << (2 * size
);
2725 static always_inline
int booke_page_size_to_tlb (target_ulong page_size
)
2729 switch (page_size
) {
2763 #if defined (TARGET_PPC64)
2764 case 0x000100000000ULL
:
2767 case 0x000400000000ULL
:
2770 case 0x001000000000ULL
:
2773 case 0x004000000000ULL
:
2776 case 0x010000000000ULL
:
2788 /* Helpers for 4xx TLB management */
2789 void do_4xx_tlbre_lo (void)
2795 tlb
= &env
->tlb
[T0
].tlbe
;
2797 if (tlb
->prot
& PAGE_VALID
)
2799 size
= booke_page_size_to_tlb(tlb
->size
);
2800 if (size
< 0 || size
> 0x7)
2803 env
->spr
[SPR_40x_PID
] = tlb
->PID
;
2806 void do_4xx_tlbre_hi (void)
2811 tlb
= &env
->tlb
[T0
].tlbe
;
2813 if (tlb
->prot
& PAGE_EXEC
)
2815 if (tlb
->prot
& PAGE_WRITE
)
2819 void do_4xx_tlbwe_hi (void)
2822 target_ulong page
, end
;
2824 #if defined (DEBUG_SOFTWARE_TLB)
2825 if (loglevel
!= 0) {
2826 fprintf(logfile
, "%s T0 " TDX
" T1 " TDX
"\n", __func__
, T0
, T1
);
2830 tlb
= &env
->tlb
[T0
].tlbe
;
2831 /* Invalidate previous TLB (if it's valid) */
2832 if (tlb
->prot
& PAGE_VALID
) {
2833 end
= tlb
->EPN
+ tlb
->size
;
2834 #if defined (DEBUG_SOFTWARE_TLB)
2835 if (loglevel
!= 0) {
2836 fprintf(logfile
, "%s: invalidate old TLB %d start " ADDRX
2837 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2840 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2841 tlb_flush_page(env
, page
);
2843 tlb
->size
= booke_tlb_to_page_size((T1
>> 7) & 0x7);
2844 /* We cannot handle TLB size < TARGET_PAGE_SIZE.
2845 * If this ever occurs, one should use the ppcemb target instead
2846 * of the ppc or ppc64 one
2848 if ((T1
& 0x40) && tlb
->size
< TARGET_PAGE_SIZE
) {
2849 cpu_abort(env
, "TLB size " TARGET_FMT_lu
" < %u "
2850 "are not supported (%d)\n",
2851 tlb
->size
, TARGET_PAGE_SIZE
, (int)((T1
>> 7) & 0x7));
2853 tlb
->EPN
= T1
& ~(tlb
->size
- 1);
2855 tlb
->prot
|= PAGE_VALID
;
2857 tlb
->prot
&= ~PAGE_VALID
;
2859 /* XXX: TO BE FIXED */
2860 cpu_abort(env
, "Little-endian TLB entries are not supported by now\n");
2862 tlb
->PID
= env
->spr
[SPR_40x_PID
]; /* PID */
2863 tlb
->attr
= T1
& 0xFF;
2864 #if defined (DEBUG_SOFTWARE_TLB)
2865 if (loglevel
!= 0) {
2866 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
2867 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
2868 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
2869 tlb
->prot
& PAGE_READ
? 'r' : '-',
2870 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
2871 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
2872 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
2875 /* Invalidate new TLB (if valid) */
2876 if (tlb
->prot
& PAGE_VALID
) {
2877 end
= tlb
->EPN
+ tlb
->size
;
2878 #if defined (DEBUG_SOFTWARE_TLB)
2879 if (loglevel
!= 0) {
2880 fprintf(logfile
, "%s: invalidate TLB %d start " ADDRX
2881 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2884 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2885 tlb_flush_page(env
, page
);
2889 void do_4xx_tlbwe_lo (void)
2893 #if defined (DEBUG_SOFTWARE_TLB)
2894 if (loglevel
!= 0) {
2895 fprintf(logfile
, "%s T0 " TDX
" T1 " TDX
"\n", __func__
, T0
, T1
);
2899 tlb
= &env
->tlb
[T0
].tlbe
;
2900 tlb
->RPN
= T1
& 0xFFFFFC00;
2901 tlb
->prot
= PAGE_READ
;
2903 tlb
->prot
|= PAGE_EXEC
;
2905 tlb
->prot
|= PAGE_WRITE
;
2906 #if defined (DEBUG_SOFTWARE_TLB)
2907 if (loglevel
!= 0) {
2908 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
2909 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
2910 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
2911 tlb
->prot
& PAGE_READ
? 'r' : '-',
2912 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
2913 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
2914 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
2919 /* PowerPC 440 TLB management */
2920 void do_440_tlbwe (int word
)
2923 target_ulong EPN
, RPN
, size
;
2926 #if defined (DEBUG_SOFTWARE_TLB)
2927 if (loglevel
!= 0) {
2928 fprintf(logfile
, "%s word %d T0 " TDX
" T1 " TDX
"\n",
2929 __func__
, word
, T0
, T1
);
2934 tlb
= &env
->tlb
[T0
].tlbe
;
2937 /* Just here to please gcc */
2939 EPN
= T1
& 0xFFFFFC00;
2940 if ((tlb
->prot
& PAGE_VALID
) && EPN
!= tlb
->EPN
)
2943 size
= booke_tlb_to_page_size((T1
>> 4) & 0xF);
2944 if ((tlb
->prot
& PAGE_VALID
) && tlb
->size
< size
)
2948 tlb
->attr
|= (T1
>> 8) & 1;
2950 tlb
->prot
|= PAGE_VALID
;
2952 if (tlb
->prot
& PAGE_VALID
) {
2953 tlb
->prot
&= ~PAGE_VALID
;
2957 tlb
->PID
= env
->spr
[SPR_440_MMUCR
] & 0x000000FF;
2962 RPN
= T1
& 0xFFFFFC0F;
2963 if ((tlb
->prot
& PAGE_VALID
) && tlb
->RPN
!= RPN
)
2968 tlb
->attr
= (tlb
->attr
& 0x1) | (T1
& 0x0000FF00);
2969 tlb
->prot
= tlb
->prot
& PAGE_VALID
;
2971 tlb
->prot
|= PAGE_READ
<< 4;
2973 tlb
->prot
|= PAGE_WRITE
<< 4;
2975 tlb
->prot
|= PAGE_EXEC
<< 4;
2977 tlb
->prot
|= PAGE_READ
;
2979 tlb
->prot
|= PAGE_WRITE
;
2981 tlb
->prot
|= PAGE_EXEC
;
2986 void do_440_tlbre (int word
)
2992 tlb
= &env
->tlb
[T0
].tlbe
;
2995 /* Just here to please gcc */
2998 size
= booke_page_size_to_tlb(tlb
->size
);
2999 if (size
< 0 || size
> 0xF)
3002 if (tlb
->attr
& 0x1)
3004 if (tlb
->prot
& PAGE_VALID
)
3006 env
->spr
[SPR_440_MMUCR
] &= ~0x000000FF;
3007 env
->spr
[SPR_440_MMUCR
] |= tlb
->PID
;
3013 T0
= tlb
->attr
& ~0x1;
3014 if (tlb
->prot
& (PAGE_READ
<< 4))
3016 if (tlb
->prot
& (PAGE_WRITE
<< 4))
3018 if (tlb
->prot
& (PAGE_EXEC
<< 4))
3020 if (tlb
->prot
& PAGE_READ
)
3022 if (tlb
->prot
& PAGE_WRITE
)
3024 if (tlb
->prot
& PAGE_EXEC
)
3029 #endif /* !CONFIG_USER_ONLY */