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 void cpu_dump_EA (target_ulong EA
);
64 void do_print_mem_EA (target_ulong EA
)
69 /*****************************************************************************/
70 /* Registers load and stores */
71 void do_load_cr (void)
73 T0
= (env
->crf
[0] << 28) |
83 void do_store_cr (uint32_t mask
)
87 for (i
= 0, sh
= 7; i
< 8; i
++, sh
--) {
89 env
->crf
[i
] = (T0
>> (sh
* 4)) & 0xFUL
;
93 #if defined(TARGET_PPC64)
94 void do_store_pri (int prio
)
96 env
->spr
[SPR_PPR
] &= ~0x001C000000000000ULL
;
97 env
->spr
[SPR_PPR
] |= ((uint64_t)prio
& 0x7) << 50;
101 target_ulong
ppc_load_dump_spr (int sprn
)
104 fprintf(logfile
, "Read SPR %d %03x => " ADDRX
"\n",
105 sprn
, sprn
, env
->spr
[sprn
]);
108 return env
->spr
[sprn
];
111 void ppc_store_dump_spr (int sprn
, target_ulong val
)
114 fprintf(logfile
, "Write SPR %d %03x => " ADDRX
" <= " ADDRX
"\n",
115 sprn
, sprn
, env
->spr
[sprn
], val
);
117 env
->spr
[sprn
] = val
;
120 /*****************************************************************************/
121 /* Fixed point operations helpers */
126 if (likely(!((uint32_t)T0
< (uint32_t)T2
||
127 (xer_ca
== 1 && (uint32_t)T0
== (uint32_t)T2
)))) {
134 #if defined(TARGET_PPC64)
135 void do_adde_64 (void)
139 if (likely(!((uint64_t)T0
< (uint64_t)T2
||
140 (xer_ca
== 1 && (uint64_t)T0
== (uint64_t)T2
)))) {
148 void do_addmeo (void)
152 xer_ov
= ((uint32_t)T1
& ((uint32_t)T1
^ (uint32_t)T0
)) >> 31;
160 #if defined(TARGET_PPC64)
161 void do_addmeo_64 (void)
165 xer_ov
= ((uint64_t)T1
& ((uint64_t)T1
^ (uint64_t)T0
)) >> 63;
176 if (likely(!(((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
177 (int32_t)T1
== 0))) {
179 T0
= (int32_t)T0
/ (int32_t)T1
;
182 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
187 #if defined(TARGET_PPC64)
190 if (likely(!(((int64_t)T0
== INT64_MIN
&& (int64_t)T1
== (int64_t)-1LL) ||
191 (int64_t)T1
== 0))) {
193 T0
= (int64_t)T0
/ (int64_t)T1
;
196 T0
= UINT64_MAX
* ((uint64_t)T0
>> 63);
202 void do_divwuo (void)
204 if (likely((uint32_t)T1
!= 0)) {
206 T0
= (uint32_t)T0
/ (uint32_t)T1
;
214 #if defined(TARGET_PPC64)
215 void do_divduo (void)
217 if (likely((uint64_t)T1
!= 0)) {
219 T0
= (uint64_t)T0
/ (uint64_t)T1
;
228 void do_mullwo (void)
230 int64_t res
= (int64_t)T0
* (int64_t)T1
;
232 if (likely((int32_t)res
== res
)) {
241 #if defined(TARGET_PPC64)
242 void do_mulldo (void)
247 muls64(&tl
, &th
, T0
, T1
);
249 /* If th != 0 && th != -1, then we had an overflow */
250 if (likely((uint64_t)(th
+ 1) <= 1)) {
261 if (likely((int32_t)T0
!= INT32_MIN
)) {
270 #if defined(TARGET_PPC64)
271 void do_nego_64 (void)
273 if (likely((int64_t)T0
!= INT64_MIN
)) {
285 T0
= T1
+ ~T0
+ xer_ca
;
286 if (likely((uint32_t)T0
>= (uint32_t)T1
&&
287 (xer_ca
== 0 || (uint32_t)T0
!= (uint32_t)T1
))) {
294 #if defined(TARGET_PPC64)
295 void do_subfe_64 (void)
297 T0
= T1
+ ~T0
+ xer_ca
;
298 if (likely((uint64_t)T0
>= (uint64_t)T1
&&
299 (xer_ca
== 0 || (uint64_t)T0
!= (uint64_t)T1
))) {
307 void do_subfmeo (void)
310 T0
= ~T0
+ xer_ca
- 1;
311 xer_ov
= ((uint32_t)~T1
& ((uint32_t)~T1
^ (uint32_t)T0
)) >> 31;
313 if (likely((uint32_t)T1
!= UINT32_MAX
))
319 #if defined(TARGET_PPC64)
320 void do_subfmeo_64 (void)
323 T0
= ~T0
+ xer_ca
- 1;
324 xer_ov
= ((uint64_t)~T1
& ((uint64_t)~T1
^ (uint64_t)T0
)) >> 63;
326 if (likely((uint64_t)T1
!= UINT64_MAX
))
333 void do_subfzeo (void)
337 xer_ov
= (((uint32_t)~T1
^ UINT32_MAX
) &
338 ((uint32_t)(~T1
) ^ (uint32_t)T0
)) >> 31;
340 if (likely((uint32_t)T0
>= (uint32_t)~T1
)) {
347 #if defined(TARGET_PPC64)
348 void do_subfzeo_64 (void)
352 xer_ov
= (((uint64_t)~T1
^ UINT64_MAX
) &
353 ((uint64_t)(~T1
) ^ (uint64_t)T0
)) >> 63;
355 if (likely((uint64_t)T0
>= (uint64_t)~T1
)) {
363 void do_cntlzw (void)
368 #if defined(TARGET_PPC64)
369 void do_cntlzd (void)
375 /* shift right arithmetic helper */
380 if (likely(!(T1
& 0x20UL
))) {
381 if (likely((uint32_t)T1
!= 0)) {
382 ret
= (int32_t)T0
>> (T1
& 0x1fUL
);
383 if (likely(ret
>= 0 || ((int32_t)T0
& ((1 << T1
) - 1)) == 0)) {
393 ret
= UINT32_MAX
* ((uint32_t)T0
>> 31);
394 if (likely(ret
>= 0 || ((uint32_t)T0
& ~0x80000000UL
) == 0)) {
403 #if defined(TARGET_PPC64)
408 if (likely(!(T1
& 0x40UL
))) {
409 if (likely((uint64_t)T1
!= 0)) {
410 ret
= (int64_t)T0
>> (T1
& 0x3FUL
);
411 if (likely(ret
>= 0 || ((int64_t)T0
& ((1 << T1
) - 1)) == 0)) {
421 ret
= UINT64_MAX
* ((uint64_t)T0
>> 63);
422 if (likely(ret
>= 0 || ((uint64_t)T0
& ~0x8000000000000000ULL
) == 0)) {
432 void do_popcntb (void)
438 for (i
= 0; i
< 32; i
+= 8)
439 ret
|= ctpop8((T0
>> i
) & 0xFF) << i
;
443 #if defined(TARGET_PPC64)
444 void do_popcntb_64 (void)
450 for (i
= 0; i
< 64; i
+= 8)
451 ret
|= ctpop8((T0
>> i
) & 0xFF) << i
;
456 /*****************************************************************************/
457 /* Floating point operations helpers */
458 static always_inline
int fpisneg (float64 d
)
464 return u
.ll
>> 63 != 0;
467 static always_inline
int isden (float64 d
)
473 return ((u
.ll
>> 52) & 0x7FF) == 0;
476 static always_inline
int iszero (float64 d
)
482 return (u
.ll
& ~0x8000000000000000ULL
) == 0;
485 static always_inline
int isinfinity (float64 d
)
491 return ((u
.ll
>> 52) & 0x7FF) == 0x7FF &&
492 (u
.ll
& 0x000FFFFFFFFFFFFFULL
) == 0;
495 #ifdef CONFIG_SOFTFLOAT
496 static always_inline
int isfinite (float64 d
)
502 return (((u
.ll
>> 52) & 0x7FF) != 0x7FF);
505 static always_inline
int isnormal (float64 d
)
511 uint32_t exp
= (u
.ll
>> 52) & 0x7FF;
512 return ((0 < exp
) && (exp
< 0x7FF));
516 void do_compute_fprf (int set_fprf
)
520 isneg
= fpisneg(FT0
);
521 if (unlikely(float64_is_nan(FT0
))) {
522 if (float64_is_signaling_nan(FT0
)) {
523 /* Signaling NaN: flags are undefined */
529 } else if (unlikely(isinfinity(FT0
))) {
544 /* Denormalized numbers */
547 /* Normalized numbers */
558 /* We update FPSCR_FPRF */
559 env
->fpscr
&= ~(0x1F << FPSCR_FPRF
);
560 env
->fpscr
|= T0
<< FPSCR_FPRF
;
562 /* We just need fpcc to update Rc1 */
566 /* Floating-point invalid operations exception */
567 static always_inline
void fload_invalid_op_excp (int op
)
572 if (op
& POWERPC_EXCP_FP_VXSNAN
) {
573 /* Operation on signaling NaN */
574 env
->fpscr
|= 1 << FPSCR_VXSNAN
;
576 if (op
& POWERPC_EXCP_FP_VXSOFT
) {
577 /* Software-defined condition */
578 env
->fpscr
|= 1 << FPSCR_VXSOFT
;
580 switch (op
& ~(POWERPC_EXCP_FP_VXSOFT
| POWERPC_EXCP_FP_VXSNAN
)) {
581 case POWERPC_EXCP_FP_VXISI
:
582 /* Magnitude subtraction of infinities */
583 env
->fpscr
|= 1 << FPSCR_VXISI
;
585 case POWERPC_EXCP_FP_VXIDI
:
586 /* Division of infinity by infinity */
587 env
->fpscr
|= 1 << FPSCR_VXIDI
;
589 case POWERPC_EXCP_FP_VXZDZ
:
590 /* Division of zero by zero */
591 env
->fpscr
|= 1 << FPSCR_VXZDZ
;
593 case POWERPC_EXCP_FP_VXIMZ
:
594 /* Multiplication of zero by infinity */
595 env
->fpscr
|= 1 << FPSCR_VXIMZ
;
597 case POWERPC_EXCP_FP_VXVC
:
598 /* Ordered comparison of NaN */
599 env
->fpscr
|= 1 << FPSCR_VXVC
;
600 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
601 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
602 /* We must update the target FPR before raising the exception */
604 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
605 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_VXVC
;
606 /* Update the floating-point enabled exception summary */
607 env
->fpscr
|= 1 << FPSCR_FEX
;
608 /* Exception is differed */
612 case POWERPC_EXCP_FP_VXSQRT
:
613 /* Square root of a negative number */
614 env
->fpscr
|= 1 << FPSCR_VXSQRT
;
616 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
618 /* Set the result to quiet NaN */
620 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
621 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
624 case POWERPC_EXCP_FP_VXCVI
:
625 /* Invalid conversion */
626 env
->fpscr
|= 1 << FPSCR_VXCVI
;
627 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
629 /* Set the result to quiet NaN */
631 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
632 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
636 /* Update the floating-point invalid operation summary */
637 env
->fpscr
|= 1 << FPSCR_VX
;
638 /* Update the floating-point exception summary */
639 env
->fpscr
|= 1 << FPSCR_FX
;
641 /* Update the floating-point enabled exception summary */
642 env
->fpscr
|= 1 << FPSCR_FEX
;
643 if (msr_fe0
!= 0 || msr_fe1
!= 0)
644 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_FP
| op
);
648 static always_inline
void float_zero_divide_excp (void)
652 env
->fpscr
|= 1 << FPSCR_ZX
;
653 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
654 /* Update the floating-point exception summary */
655 env
->fpscr
|= 1 << FPSCR_FX
;
657 /* Update the floating-point enabled exception summary */
658 env
->fpscr
|= 1 << FPSCR_FEX
;
659 if (msr_fe0
!= 0 || msr_fe1
!= 0) {
660 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
661 POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
);
664 /* Set the result to infinity */
667 u0
.ll
= ((u0
.ll
^ u1
.ll
) & 0x8000000000000000ULL
);
668 u0
.ll
|= 0x7FFULL
<< 52;
673 static always_inline
void float_overflow_excp (void)
675 env
->fpscr
|= 1 << FPSCR_OX
;
676 /* Update the floating-point exception summary */
677 env
->fpscr
|= 1 << FPSCR_FX
;
679 /* XXX: should adjust the result */
680 /* Update the floating-point enabled exception summary */
681 env
->fpscr
|= 1 << FPSCR_FEX
;
682 /* We must update the target FPR before raising the exception */
683 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
684 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
686 env
->fpscr
|= 1 << FPSCR_XX
;
687 env
->fpscr
|= 1 << FPSCR_FI
;
691 static always_inline
void float_underflow_excp (void)
693 env
->fpscr
|= 1 << FPSCR_UX
;
694 /* Update the floating-point exception summary */
695 env
->fpscr
|= 1 << FPSCR_FX
;
697 /* XXX: should adjust the result */
698 /* Update the floating-point enabled exception summary */
699 env
->fpscr
|= 1 << FPSCR_FEX
;
700 /* We must update the target FPR before raising the exception */
701 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
702 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
706 static always_inline
void float_inexact_excp (void)
708 env
->fpscr
|= 1 << FPSCR_XX
;
709 /* Update the floating-point exception summary */
710 env
->fpscr
|= 1 << FPSCR_FX
;
712 /* Update the floating-point enabled exception summary */
713 env
->fpscr
|= 1 << FPSCR_FEX
;
714 /* We must update the target FPR before raising the exception */
715 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
716 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
720 static always_inline
void fpscr_set_rounding_mode (void)
724 /* Set rounding mode */
727 /* Best approximation (round to nearest) */
728 rnd_type
= float_round_nearest_even
;
731 /* Smaller magnitude (round toward zero) */
732 rnd_type
= float_round_to_zero
;
735 /* Round toward +infinite */
736 rnd_type
= float_round_up
;
740 /* Round toward -infinite */
741 rnd_type
= float_round_down
;
744 set_float_rounding_mode(rnd_type
, &env
->fp_status
);
747 void do_fpscr_setbit (int bit
)
751 prev
= (env
->fpscr
>> bit
) & 1;
752 env
->fpscr
|= 1 << bit
;
756 env
->fpscr
|= 1 << FPSCR_FX
;
760 env
->fpscr
|= 1 << FPSCR_FX
;
765 env
->fpscr
|= 1 << FPSCR_FX
;
770 env
->fpscr
|= 1 << FPSCR_FX
;
775 env
->fpscr
|= 1 << FPSCR_FX
;
788 env
->fpscr
|= 1 << FPSCR_VX
;
789 env
->fpscr
|= 1 << FPSCR_FX
;
796 env
->error_code
= POWERPC_EXCP_FP
;
798 env
->error_code
|= POWERPC_EXCP_FP_VXSNAN
;
800 env
->error_code
|= POWERPC_EXCP_FP_VXISI
;
802 env
->error_code
|= POWERPC_EXCP_FP_VXIDI
;
804 env
->error_code
|= POWERPC_EXCP_FP_VXZDZ
;
806 env
->error_code
|= POWERPC_EXCP_FP_VXIMZ
;
808 env
->error_code
|= POWERPC_EXCP_FP_VXVC
;
810 env
->error_code
|= POWERPC_EXCP_FP_VXSOFT
;
812 env
->error_code
|= POWERPC_EXCP_FP_VXSQRT
;
814 env
->error_code
|= POWERPC_EXCP_FP_VXCVI
;
821 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
828 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
835 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
;
842 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
848 fpscr_set_rounding_mode();
853 /* Update the floating-point enabled exception summary */
854 env
->fpscr
|= 1 << FPSCR_FEX
;
855 /* We have to update Rc1 before raising the exception */
856 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
862 #if defined(WORDS_BIGENDIAN)
869 void do_store_fpscr (uint32_t mask
)
872 * We use only the 32 LSB of the incoming fpr
882 new |= prev
& 0x90000000;
883 for (i
= 0; i
< 7; i
++) {
884 if (mask
& (1 << i
)) {
885 env
->fpscr
&= ~(0xF << (4 * i
));
886 env
->fpscr
|= new & (0xF << (4 * i
));
889 /* Update VX and FEX */
891 env
->fpscr
|= 1 << FPSCR_VX
;
893 env
->fpscr
&= ~(1 << FPSCR_VX
);
894 if ((fpscr_ex
& fpscr_eex
) != 0) {
895 env
->fpscr
|= 1 << FPSCR_FEX
;
896 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
897 /* XXX: we should compute it properly */
898 env
->error_code
= POWERPC_EXCP_FP
;
901 env
->fpscr
&= ~(1 << FPSCR_FEX
);
902 fpscr_set_rounding_mode();
907 #ifdef CONFIG_SOFTFLOAT
908 void do_float_check_status (void)
910 if (env
->exception_index
== POWERPC_EXCP_PROGRAM
&&
911 (env
->error_code
& POWERPC_EXCP_FP
)) {
912 /* Differred floating-point exception after target FPR update */
913 if (msr_fe0
!= 0 || msr_fe1
!= 0)
914 do_raise_exception_err(env
->exception_index
, env
->error_code
);
915 } else if (env
->fp_status
.float_exception_flags
& float_flag_overflow
) {
916 float_overflow_excp();
917 } else if (env
->fp_status
.float_exception_flags
& float_flag_underflow
) {
918 float_underflow_excp();
919 } else if (env
->fp_status
.float_exception_flags
& float_flag_inexact
) {
920 float_inexact_excp();
925 #if USE_PRECISE_EMULATION
928 if (unlikely(float64_is_signaling_nan(FT0
) ||
929 float64_is_signaling_nan(FT1
))) {
931 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
932 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
933 fpisneg(FT0
) == fpisneg(FT1
))) {
934 FT0
= float64_add(FT0
, FT1
, &env
->fp_status
);
936 /* Magnitude subtraction of infinities */
937 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
943 if (unlikely(float64_is_signaling_nan(FT0
) ||
944 float64_is_signaling_nan(FT1
))) {
945 /* sNaN subtraction */
946 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
947 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
948 fpisneg(FT0
) != fpisneg(FT1
))) {
949 FT0
= float64_sub(FT0
, FT1
, &env
->fp_status
);
951 /* Magnitude subtraction of infinities */
952 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
958 if (unlikely(float64_is_signaling_nan(FT0
) ||
959 float64_is_signaling_nan(FT1
))) {
960 /* sNaN multiplication */
961 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
962 } else if (unlikely((isinfinity(FT0
) && iszero(FT1
)) ||
963 (iszero(FT0
) && isinfinity(FT1
)))) {
964 /* Multiplication of zero by infinity */
965 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIMZ
);
967 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
973 if (unlikely(float64_is_signaling_nan(FT0
) ||
974 float64_is_signaling_nan(FT1
))) {
976 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
977 } else if (unlikely(isinfinity(FT0
) && isinfinity(FT1
))) {
978 /* Division of infinity by infinity */
979 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIDI
);
980 } else if (unlikely(iszero(FT1
))) {
982 /* Division of zero by zero */
983 fload_invalid_op_excp(POWERPC_EXCP_FP_VXZDZ
);
985 /* Division by zero */
986 float_zero_divide_excp();
989 FT0
= float64_div(FT0
, FT1
, &env
->fp_status
);
992 #endif /* USE_PRECISE_EMULATION */
998 if (unlikely(float64_is_signaling_nan(FT0
))) {
999 /* sNaN conversion */
1000 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1001 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1002 /* qNan / infinity conversion */
1003 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1005 p
.ll
= float64_to_int32(FT0
, &env
->fp_status
);
1006 #if USE_PRECISE_EMULATION
1007 /* XXX: higher bits are not supposed to be significant.
1008 * to make tests easier, return the same as a real PowerPC 750
1010 p
.ll
|= 0xFFF80000ULL
<< 32;
1016 void do_fctiwz (void)
1020 if (unlikely(float64_is_signaling_nan(FT0
))) {
1021 /* sNaN conversion */
1022 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1023 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1024 /* qNan / infinity conversion */
1025 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1027 p
.ll
= float64_to_int32_round_to_zero(FT0
, &env
->fp_status
);
1028 #if USE_PRECISE_EMULATION
1029 /* XXX: higher bits are not supposed to be significant.
1030 * to make tests easier, return the same as a real PowerPC 750
1032 p
.ll
|= 0xFFF80000ULL
<< 32;
1038 #if defined(TARGET_PPC64)
1039 void do_fcfid (void)
1044 FT0
= int64_to_float64(p
.ll
, &env
->fp_status
);
1047 void do_fctid (void)
1051 if (unlikely(float64_is_signaling_nan(FT0
))) {
1052 /* sNaN conversion */
1053 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1054 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1055 /* qNan / infinity conversion */
1056 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1058 p
.ll
= float64_to_int64(FT0
, &env
->fp_status
);
1063 void do_fctidz (void)
1067 if (unlikely(float64_is_signaling_nan(FT0
))) {
1068 /* sNaN conversion */
1069 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1070 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1071 /* qNan / infinity conversion */
1072 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1074 p
.ll
= float64_to_int64_round_to_zero(FT0
, &env
->fp_status
);
1081 static always_inline
void do_fri (int rounding_mode
)
1083 if (unlikely(float64_is_signaling_nan(FT0
))) {
1085 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1086 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1087 /* qNan / infinity round */
1088 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1090 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
1091 FT0
= float64_round_to_int(FT0
, &env
->fp_status
);
1092 /* Restore rounding mode from FPSCR */
1093 fpscr_set_rounding_mode();
1099 do_fri(float_round_nearest_even
);
1104 do_fri(float_round_to_zero
);
1109 do_fri(float_round_up
);
1114 do_fri(float_round_down
);
1117 #if USE_PRECISE_EMULATION
1118 void do_fmadd (void)
1120 if (unlikely(float64_is_signaling_nan(FT0
) ||
1121 float64_is_signaling_nan(FT1
) ||
1122 float64_is_signaling_nan(FT2
))) {
1123 /* sNaN operation */
1124 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1127 /* This is the way the PowerPC specification defines it */
1128 float128 ft0_128
, ft1_128
;
1130 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1131 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1132 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1133 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1134 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
1135 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1137 /* This is OK on x86 hosts */
1138 FT0
= (FT0
* FT1
) + FT2
;
1143 void do_fmsub (void)
1145 if (unlikely(float64_is_signaling_nan(FT0
) ||
1146 float64_is_signaling_nan(FT1
) ||
1147 float64_is_signaling_nan(FT2
))) {
1148 /* sNaN operation */
1149 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1152 /* This is the way the PowerPC specification defines it */
1153 float128 ft0_128
, ft1_128
;
1155 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1156 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1157 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1158 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1159 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
1160 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1162 /* This is OK on x86 hosts */
1163 FT0
= (FT0
* FT1
) - FT2
;
1167 #endif /* USE_PRECISE_EMULATION */
1169 void do_fnmadd (void)
1171 if (unlikely(float64_is_signaling_nan(FT0
) ||
1172 float64_is_signaling_nan(FT1
) ||
1173 float64_is_signaling_nan(FT2
))) {
1174 /* sNaN operation */
1175 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1177 #if USE_PRECISE_EMULATION
1179 /* This is the way the PowerPC specification defines it */
1180 float128 ft0_128
, ft1_128
;
1182 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1183 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1184 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1185 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1186 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
1187 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1189 /* This is OK on x86 hosts */
1190 FT0
= (FT0
* FT1
) + FT2
;
1193 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1194 FT0
= float64_add(FT0
, FT2
, &env
->fp_status
);
1196 if (likely(!isnan(FT0
)))
1197 FT0
= float64_chs(FT0
);
1201 void do_fnmsub (void)
1203 if (unlikely(float64_is_signaling_nan(FT0
) ||
1204 float64_is_signaling_nan(FT1
) ||
1205 float64_is_signaling_nan(FT2
))) {
1206 /* sNaN operation */
1207 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1209 #if USE_PRECISE_EMULATION
1211 /* This is the way the PowerPC specification defines it */
1212 float128 ft0_128
, ft1_128
;
1214 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1215 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1216 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1217 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1218 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
1219 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1221 /* This is OK on x86 hosts */
1222 FT0
= (FT0
* FT1
) - FT2
;
1225 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1226 FT0
= float64_sub(FT0
, FT2
, &env
->fp_status
);
1228 if (likely(!isnan(FT0
)))
1229 FT0
= float64_chs(FT0
);
1233 #if USE_PRECISE_EMULATION
1236 if (unlikely(float64_is_signaling_nan(FT0
))) {
1237 /* sNaN square root */
1238 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1240 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1243 #endif /* USE_PRECISE_EMULATION */
1245 void do_fsqrt (void)
1247 if (unlikely(float64_is_signaling_nan(FT0
))) {
1248 /* sNaN square root */
1249 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1250 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1251 /* Square root of a negative nonzero number */
1252 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1254 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1262 if (unlikely(float64_is_signaling_nan(FT0
))) {
1263 /* sNaN reciprocal */
1264 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1265 } else if (unlikely(iszero(FT0
))) {
1266 /* Zero reciprocal */
1267 float_zero_divide_excp();
1268 } else if (likely(isnormal(FT0
))) {
1269 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1272 if (p
.ll
== 0x8000000000000000ULL
) {
1273 p
.ll
= 0xFFF0000000000000ULL
;
1274 } else if (p
.ll
== 0x0000000000000000ULL
) {
1275 p
.ll
= 0x7FF0000000000000ULL
;
1276 } else if (isnan(FT0
)) {
1277 p
.ll
= 0x7FF8000000000000ULL
;
1278 } else if (fpisneg(FT0
)) {
1279 p
.ll
= 0x8000000000000000ULL
;
1281 p
.ll
= 0x0000000000000000ULL
;
1291 if (unlikely(float64_is_signaling_nan(FT0
))) {
1292 /* sNaN reciprocal */
1293 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1294 } else if (unlikely(iszero(FT0
))) {
1295 /* Zero reciprocal */
1296 float_zero_divide_excp();
1297 } else if (likely(isnormal(FT0
))) {
1298 #if USE_PRECISE_EMULATION
1299 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1300 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1302 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1306 if (p
.ll
== 0x8000000000000000ULL
) {
1307 p
.ll
= 0xFFF0000000000000ULL
;
1308 } else if (p
.ll
== 0x0000000000000000ULL
) {
1309 p
.ll
= 0x7FF0000000000000ULL
;
1310 } else if (isnan(FT0
)) {
1311 p
.ll
= 0x7FF8000000000000ULL
;
1312 } else if (fpisneg(FT0
)) {
1313 p
.ll
= 0x8000000000000000ULL
;
1315 p
.ll
= 0x0000000000000000ULL
;
1321 void do_frsqrte (void)
1325 if (unlikely(float64_is_signaling_nan(FT0
))) {
1326 /* sNaN reciprocal square root */
1327 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1328 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1329 /* Reciprocal square root of a negative nonzero number */
1330 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1331 } else if (likely(isnormal(FT0
))) {
1332 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1333 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1336 if (p
.ll
== 0x8000000000000000ULL
) {
1337 p
.ll
= 0xFFF0000000000000ULL
;
1338 } else if (p
.ll
== 0x0000000000000000ULL
) {
1339 p
.ll
= 0x7FF0000000000000ULL
;
1340 } else if (isnan(FT0
)) {
1341 p
.ll
|= 0x000FFFFFFFFFFFFFULL
;
1342 } else if (fpisneg(FT0
)) {
1343 p
.ll
= 0x7FF8000000000000ULL
;
1345 p
.ll
= 0x0000000000000000ULL
;
1353 if (!fpisneg(FT0
) || iszero(FT0
))
1359 void do_fcmpu (void)
1361 if (unlikely(float64_is_signaling_nan(FT0
) ||
1362 float64_is_signaling_nan(FT1
))) {
1363 /* sNaN comparison */
1364 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1366 if (float64_lt(FT0
, FT1
, &env
->fp_status
)) {
1368 } else if (!float64_le(FT0
, FT1
, &env
->fp_status
)) {
1374 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1375 env
->fpscr
|= T0
<< FPSCR_FPRF
;
1378 void do_fcmpo (void)
1380 if (unlikely(float64_is_nan(FT0
) ||
1381 float64_is_nan(FT1
))) {
1382 if (float64_is_signaling_nan(FT0
) ||
1383 float64_is_signaling_nan(FT1
)) {
1384 /* sNaN comparison */
1385 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
|
1386 POWERPC_EXCP_FP_VXVC
);
1388 /* qNaN comparison */
1389 fload_invalid_op_excp(POWERPC_EXCP_FP_VXVC
);
1392 if (float64_lt(FT0
, FT1
, &env
->fp_status
)) {
1394 } else if (!float64_le(FT0
, FT1
, &env
->fp_status
)) {
1400 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1401 env
->fpscr
|= T0
<< FPSCR_FPRF
;
1404 #if !defined (CONFIG_USER_ONLY)
1405 void cpu_dump_rfi (target_ulong RA
, target_ulong msr
);
1407 void do_store_msr (void)
1409 T0
= hreg_store_msr(env
, T0
, 0);
1411 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1412 do_raise_exception(T0
);
1416 static always_inline
void __do_rfi (target_ulong nip
, target_ulong msr
,
1417 target_ulong msrm
, int keep_msrh
)
1419 #if defined(TARGET_PPC64)
1420 if (msr
& (1ULL << MSR_SF
)) {
1421 nip
= (uint64_t)nip
;
1422 msr
&= (uint64_t)msrm
;
1424 nip
= (uint32_t)nip
;
1425 msr
= (uint32_t)(msr
& msrm
);
1427 msr
|= env
->msr
& ~((uint64_t)0xFFFFFFFF);
1430 nip
= (uint32_t)nip
;
1431 msr
&= (uint32_t)msrm
;
1433 /* XXX: beware: this is false if VLE is supported */
1434 env
->nip
= nip
& ~((target_ulong
)0x00000003);
1435 hreg_store_msr(env
, msr
, 1);
1436 #if defined (DEBUG_OP)
1437 cpu_dump_rfi(env
->nip
, env
->msr
);
1439 /* No need to raise an exception here,
1440 * as rfi is always the last insn of a TB
1442 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1447 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1448 ~((target_ulong
)0xFFFF0000), 1);
1451 #if defined(TARGET_PPC64)
1454 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1455 ~((target_ulong
)0xFFFF0000), 0);
1458 void do_hrfid (void)
1460 __do_rfi(env
->spr
[SPR_HSRR0
], env
->spr
[SPR_HSRR1
],
1461 ~((target_ulong
)0xFFFF0000), 0);
1466 void do_tw (int flags
)
1468 if (!likely(!(((int32_t)T0
< (int32_t)T1
&& (flags
& 0x10)) ||
1469 ((int32_t)T0
> (int32_t)T1
&& (flags
& 0x08)) ||
1470 ((int32_t)T0
== (int32_t)T1
&& (flags
& 0x04)) ||
1471 ((uint32_t)T0
< (uint32_t)T1
&& (flags
& 0x02)) ||
1472 ((uint32_t)T0
> (uint32_t)T1
&& (flags
& 0x01))))) {
1473 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1477 #if defined(TARGET_PPC64)
1478 void do_td (int flags
)
1480 if (!likely(!(((int64_t)T0
< (int64_t)T1
&& (flags
& 0x10)) ||
1481 ((int64_t)T0
> (int64_t)T1
&& (flags
& 0x08)) ||
1482 ((int64_t)T0
== (int64_t)T1
&& (flags
& 0x04)) ||
1483 ((uint64_t)T0
< (uint64_t)T1
&& (flags
& 0x02)) ||
1484 ((uint64_t)T0
> (uint64_t)T1
&& (flags
& 0x01)))))
1485 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1489 /*****************************************************************************/
1490 /* PowerPC 601 specific instructions (POWER bridge) */
1491 void do_POWER_abso (void)
1493 if ((int32_t)T0
== INT32_MIN
) {
1496 } else if ((int32_t)T0
< 0) {
1505 void do_POWER_clcs (void)
1509 /* Instruction cache line size */
1510 T0
= env
->icache_line_size
;
1513 /* Data cache line size */
1514 T0
= env
->dcache_line_size
;
1517 /* Minimum cache line size */
1518 T0
= env
->icache_line_size
< env
->dcache_line_size
?
1519 env
->icache_line_size
: env
->dcache_line_size
;
1522 /* Maximum cache line size */
1523 T0
= env
->icache_line_size
> env
->dcache_line_size
?
1524 env
->icache_line_size
: env
->dcache_line_size
;
1532 void do_POWER_div (void)
1536 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1538 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1539 env
->spr
[SPR_MQ
] = 0;
1541 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1542 env
->spr
[SPR_MQ
] = tmp
% T1
;
1543 T0
= tmp
/ (int32_t)T1
;
1547 void do_POWER_divo (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;
1557 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1558 env
->spr
[SPR_MQ
] = tmp
% T1
;
1560 if (tmp
> (int64_t)INT32_MAX
|| tmp
< (int64_t)INT32_MIN
) {
1570 void do_POWER_divs (void)
1572 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1574 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1575 env
->spr
[SPR_MQ
] = 0;
1577 env
->spr
[SPR_MQ
] = T0
% T1
;
1578 T0
= (int32_t)T0
/ (int32_t)T1
;
1582 void do_POWER_divso (void)
1584 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1586 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1587 env
->spr
[SPR_MQ
] = 0;
1590 T0
= (int32_t)T0
/ (int32_t)T1
;
1591 env
->spr
[SPR_MQ
] = (int32_t)T0
% (int32_t)T1
;
1597 void do_POWER_dozo (void)
1599 if ((int32_t)T1
> (int32_t)T0
) {
1602 if (((uint32_t)(~T2
) ^ (uint32_t)T1
^ UINT32_MAX
) &
1603 ((uint32_t)(~T2
) ^ (uint32_t)T0
) & (1UL << 31)) {
1615 void do_POWER_maskg (void)
1619 if ((uint32_t)T0
== (uint32_t)(T1
+ 1)) {
1622 ret
= (UINT32_MAX
>> ((uint32_t)T0
)) ^
1623 ((UINT32_MAX
>> ((uint32_t)T1
)) >> 1);
1624 if ((uint32_t)T0
> (uint32_t)T1
)
1630 void do_POWER_mulo (void)
1634 tmp
= (uint64_t)T0
* (uint64_t)T1
;
1635 env
->spr
[SPR_MQ
] = tmp
>> 32;
1637 if (tmp
>> 32 != ((uint64_t)T0
>> 16) * ((uint64_t)T1
>> 16)) {
1645 #if !defined (CONFIG_USER_ONLY)
1646 void do_POWER_rac (void)
1651 /* We don't have to generate many instances of this instruction,
1652 * as rac is supervisor only.
1654 /* XXX: FIX THIS: Pretend we have no BAT */
1655 nb_BATs
= env
->nb_BATs
;
1657 if (get_physical_address(env
, &ctx
, T0
, 0, ACCESS_INT
) == 0)
1659 env
->nb_BATs
= nb_BATs
;
1662 void do_POWER_rfsvc (void)
1664 __do_rfi(env
->lr
, env
->ctr
, 0x0000FFFF, 0);
1667 void do_store_hid0_601 (void)
1671 hid0
= env
->spr
[SPR_HID0
];
1672 if ((T0
^ hid0
) & 0x00000008) {
1673 /* Change current endianness */
1674 env
->hflags
&= ~(1 << MSR_LE
);
1675 env
->hflags_nmsr
&= ~(1 << MSR_LE
);
1676 env
->hflags_nmsr
|= (1 << MSR_LE
) & (((T0
>> 3) & 1) << MSR_LE
);
1677 env
->hflags
|= env
->hflags_nmsr
;
1678 if (loglevel
!= 0) {
1679 fprintf(logfile
, "%s: set endianness to %c => " ADDRX
"\n",
1680 __func__
, T0
& 0x8 ? 'l' : 'b', env
->hflags
);
1683 env
->spr
[SPR_HID0
] = T0
;
1687 /*****************************************************************************/
1688 /* 602 specific instructions */
1689 /* mfrom is the most crazy instruction ever seen, imho ! */
1690 /* Real implementation uses a ROM table. Do the same */
1691 #define USE_MFROM_ROM_TABLE
1692 void do_op_602_mfrom (void)
1694 if (likely(T0
< 602)) {
1695 #if defined(USE_MFROM_ROM_TABLE)
1696 #include "mfrom_table.c"
1697 T0
= mfrom_ROM_table
[T0
];
1700 /* Extremly decomposed:
1702 * T0 = 256 * log10(10 + 1.0) + 0.5
1705 d
= float64_div(d
, 256, &env
->fp_status
);
1707 d
= exp10(d
); // XXX: use float emulation function
1708 d
= float64_add(d
, 1.0, &env
->fp_status
);
1709 d
= log10(d
); // XXX: use float emulation function
1710 d
= float64_mul(d
, 256, &env
->fp_status
);
1711 d
= float64_add(d
, 0.5, &env
->fp_status
);
1712 T0
= float64_round_to_int(d
, &env
->fp_status
);
1719 /*****************************************************************************/
1720 /* Embedded PowerPC specific helpers */
1721 void do_405_check_sat (void)
1723 if (!likely((((uint32_t)T1
^ (uint32_t)T2
) >> 31) ||
1724 !(((uint32_t)T0
^ (uint32_t)T2
) >> 31))) {
1725 /* Saturate result */
1734 /* XXX: to be improved to check access rights when in user-mode */
1735 void do_load_dcr (void)
1739 if (unlikely(env
->dcr_env
== NULL
)) {
1740 if (loglevel
!= 0) {
1741 fprintf(logfile
, "No DCR environment\n");
1743 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1744 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1745 } else if (unlikely(ppc_dcr_read(env
->dcr_env
, T0
, &val
) != 0)) {
1746 if (loglevel
!= 0) {
1747 fprintf(logfile
, "DCR read error %d %03x\n", (int)T0
, (int)T0
);
1749 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1750 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1756 void do_store_dcr (void)
1758 if (unlikely(env
->dcr_env
== NULL
)) {
1759 if (loglevel
!= 0) {
1760 fprintf(logfile
, "No DCR environment\n");
1762 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1763 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1764 } else if (unlikely(ppc_dcr_write(env
->dcr_env
, T0
, T1
) != 0)) {
1765 if (loglevel
!= 0) {
1766 fprintf(logfile
, "DCR write error %d %03x\n", (int)T0
, (int)T0
);
1768 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1769 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1773 #if !defined(CONFIG_USER_ONLY)
1774 void do_40x_rfci (void)
1776 __do_rfi(env
->spr
[SPR_40x_SRR2
], env
->spr
[SPR_40x_SRR3
],
1777 ~((target_ulong
)0xFFFF0000), 0);
1782 __do_rfi(env
->spr
[SPR_BOOKE_CSRR0
], SPR_BOOKE_CSRR1
,
1783 ~((target_ulong
)0x3FFF0000), 0);
1788 __do_rfi(env
->spr
[SPR_BOOKE_DSRR0
], SPR_BOOKE_DSRR1
,
1789 ~((target_ulong
)0x3FFF0000), 0);
1792 void do_rfmci (void)
1794 __do_rfi(env
->spr
[SPR_BOOKE_MCSRR0
], SPR_BOOKE_MCSRR1
,
1795 ~((target_ulong
)0x3FFF0000), 0);
1798 void do_load_403_pb (int num
)
1803 void do_store_403_pb (int num
)
1805 if (likely(env
->pb
[num
] != T0
)) {
1807 /* Should be optimized */
1814 void do_440_dlmzb (void)
1820 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1821 if ((T0
& mask
) == 0)
1825 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1826 if ((T1
& mask
) == 0)
1834 /* SPE extension helpers */
1835 /* Use a table to make this quicker */
1836 static uint8_t hbrev
[16] = {
1837 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
1838 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF,
1841 static always_inline
uint8_t byte_reverse (uint8_t val
)
1843 return hbrev
[val
>> 4] | (hbrev
[val
& 0xF] << 4);
1846 static always_inline
uint32_t word_reverse (uint32_t val
)
1848 return byte_reverse(val
>> 24) | (byte_reverse(val
>> 16) << 8) |
1849 (byte_reverse(val
>> 8) << 16) | (byte_reverse(val
) << 24);
1852 #define MASKBITS 16 // Random value - to be fixed (implementation dependant)
1853 void do_brinc (void)
1855 uint32_t a
, b
, d
, mask
;
1857 mask
= UINT32_MAX
>> (32 - MASKBITS
);
1860 d
= word_reverse(1 + word_reverse(a
| ~b
));
1861 T0
= (T0
& ~mask
) | (d
& b
);
1864 #define DO_SPE_OP2(name) \
1865 void do_ev##name (void) \
1867 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) | \
1868 (uint64_t)_do_e##name(T0_64, T1_64); \
1871 #define DO_SPE_OP1(name) \
1872 void do_ev##name (void) \
1874 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) | \
1875 (uint64_t)_do_e##name(T0_64); \
1878 /* Fixed-point vector arithmetic */
1879 static always_inline
uint32_t _do_eabs (uint32_t val
)
1881 if ((val
& 0x80000000) && val
!= 0x80000000)
1887 static always_inline
uint32_t _do_eaddw (uint32_t op1
, uint32_t op2
)
1892 static always_inline
int _do_ecntlsw (uint32_t val
)
1894 if (val
& 0x80000000)
1900 static always_inline
int _do_ecntlzw (uint32_t val
)
1905 static always_inline
uint32_t _do_eneg (uint32_t val
)
1907 if (val
!= 0x80000000)
1913 static always_inline
uint32_t _do_erlw (uint32_t op1
, uint32_t op2
)
1915 return rotl32(op1
, op2
);
1918 static always_inline
uint32_t _do_erndw (uint32_t val
)
1920 return (val
+ 0x000080000000) & 0xFFFF0000;
1923 static always_inline
uint32_t _do_eslw (uint32_t op1
, uint32_t op2
)
1925 /* No error here: 6 bits are used */
1926 return op1
<< (op2
& 0x3F);
1929 static always_inline
int32_t _do_esrws (int32_t op1
, uint32_t op2
)
1931 /* No error here: 6 bits are used */
1932 return op1
>> (op2
& 0x3F);
1935 static always_inline
uint32_t _do_esrwu (uint32_t op1
, uint32_t op2
)
1937 /* No error here: 6 bits are used */
1938 return op1
>> (op2
& 0x3F);
1941 static always_inline
uint32_t _do_esubfw (uint32_t op1
, uint32_t op2
)
1969 /* evsel is a little bit more complicated... */
1970 static always_inline
uint32_t _do_esel (uint32_t op1
, uint32_t op2
, int n
)
1978 void do_evsel (void)
1980 T0_64
= ((uint64_t)_do_esel(T0_64
>> 32, T1_64
>> 32, T0
>> 3) << 32) |
1981 (uint64_t)_do_esel(T0_64
, T1_64
, (T0
>> 2) & 1);
1984 /* Fixed-point vector comparisons */
1985 #define DO_SPE_CMP(name) \
1986 void do_ev##name (void) \
1988 T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32, \
1989 T1_64 >> 32) << 32, \
1990 _do_e##name(T0_64, T1_64)); \
1993 static always_inline
uint32_t _do_evcmp_merge (int t0
, int t1
)
1995 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
1997 static always_inline
int _do_ecmpeq (uint32_t op1
, uint32_t op2
)
1999 return op1
== op2
? 1 : 0;
2002 static always_inline
int _do_ecmpgts (int32_t op1
, int32_t op2
)
2004 return op1
> op2
? 1 : 0;
2007 static always_inline
int _do_ecmpgtu (uint32_t op1
, uint32_t op2
)
2009 return op1
> op2
? 1 : 0;
2012 static always_inline
int _do_ecmplts (int32_t op1
, int32_t op2
)
2014 return op1
< op2
? 1 : 0;
2017 static always_inline
int _do_ecmpltu (uint32_t op1
, uint32_t op2
)
2019 return op1
< op2
? 1 : 0;
2033 /* Single precision floating-point conversions from/to integer */
2034 static always_inline
uint32_t _do_efscfsi (int32_t val
)
2038 u
.f
= int32_to_float32(val
, &env
->spe_status
);
2043 static always_inline
uint32_t _do_efscfui (uint32_t val
)
2047 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
2052 static always_inline
int32_t _do_efsctsi (uint32_t val
)
2057 /* NaN are not treated the same way IEEE 754 does */
2058 if (unlikely(isnan(u
.f
)))
2061 return float32_to_int32(u
.f
, &env
->spe_status
);
2064 static always_inline
uint32_t _do_efsctui (uint32_t val
)
2069 /* NaN are not treated the same way IEEE 754 does */
2070 if (unlikely(isnan(u
.f
)))
2073 return float32_to_uint32(u
.f
, &env
->spe_status
);
2076 static always_inline
int32_t _do_efsctsiz (uint32_t val
)
2081 /* NaN are not treated the same way IEEE 754 does */
2082 if (unlikely(isnan(u
.f
)))
2085 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
2088 static always_inline
uint32_t _do_efsctuiz (uint32_t val
)
2093 /* NaN are not treated the same way IEEE 754 does */
2094 if (unlikely(isnan(u
.f
)))
2097 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
2100 void do_efscfsi (void)
2102 T0_64
= _do_efscfsi(T0_64
);
2105 void do_efscfui (void)
2107 T0_64
= _do_efscfui(T0_64
);
2110 void do_efsctsi (void)
2112 T0_64
= _do_efsctsi(T0_64
);
2115 void do_efsctui (void)
2117 T0_64
= _do_efsctui(T0_64
);
2120 void do_efsctsiz (void)
2122 T0_64
= _do_efsctsiz(T0_64
);
2125 void do_efsctuiz (void)
2127 T0_64
= _do_efsctuiz(T0_64
);
2130 /* Single precision floating-point conversion to/from fractional */
2131 static always_inline
uint32_t _do_efscfsf (uint32_t val
)
2136 u
.f
= int32_to_float32(val
, &env
->spe_status
);
2137 tmp
= int64_to_float32(1ULL << 32, &env
->spe_status
);
2138 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
2143 static always_inline
uint32_t _do_efscfuf (uint32_t val
)
2148 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
2149 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2150 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
2155 static always_inline
int32_t _do_efsctsf (uint32_t val
)
2161 /* NaN are not treated the same way IEEE 754 does */
2162 if (unlikely(isnan(u
.f
)))
2164 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2165 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2167 return float32_to_int32(u
.f
, &env
->spe_status
);
2170 static always_inline
uint32_t _do_efsctuf (uint32_t val
)
2176 /* NaN are not treated the same way IEEE 754 does */
2177 if (unlikely(isnan(u
.f
)))
2179 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2180 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2182 return float32_to_uint32(u
.f
, &env
->spe_status
);
2185 static always_inline
int32_t _do_efsctsfz (uint32_t val
)
2191 /* NaN are not treated the same way IEEE 754 does */
2192 if (unlikely(isnan(u
.f
)))
2194 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2195 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2197 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
2200 static always_inline
uint32_t _do_efsctufz (uint32_t val
)
2206 /* NaN are not treated the same way IEEE 754 does */
2207 if (unlikely(isnan(u
.f
)))
2209 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2210 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2212 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
2215 void do_efscfsf (void)
2217 T0_64
= _do_efscfsf(T0_64
);
2220 void do_efscfuf (void)
2222 T0_64
= _do_efscfuf(T0_64
);
2225 void do_efsctsf (void)
2227 T0_64
= _do_efsctsf(T0_64
);
2230 void do_efsctuf (void)
2232 T0_64
= _do_efsctuf(T0_64
);
2235 void do_efsctsfz (void)
2237 T0_64
= _do_efsctsfz(T0_64
);
2240 void do_efsctufz (void)
2242 T0_64
= _do_efsctufz(T0_64
);
2245 /* Double precision floating point helpers */
2246 static always_inline
int _do_efdcmplt (uint64_t op1
, uint64_t op2
)
2248 /* XXX: TODO: test special values (NaN, infinites, ...) */
2249 return _do_efdtstlt(op1
, op2
);
2252 static always_inline
int _do_efdcmpgt (uint64_t op1
, uint64_t op2
)
2254 /* XXX: TODO: test special values (NaN, infinites, ...) */
2255 return _do_efdtstgt(op1
, op2
);
2258 static always_inline
int _do_efdcmpeq (uint64_t op1
, uint64_t op2
)
2260 /* XXX: TODO: test special values (NaN, infinites, ...) */
2261 return _do_efdtsteq(op1
, op2
);
2264 void do_efdcmplt (void)
2266 T0
= _do_efdcmplt(T0_64
, T1_64
);
2269 void do_efdcmpgt (void)
2271 T0
= _do_efdcmpgt(T0_64
, T1_64
);
2274 void do_efdcmpeq (void)
2276 T0
= _do_efdcmpeq(T0_64
, T1_64
);
2279 /* Double precision floating-point conversion to/from integer */
2280 static always_inline
uint64_t _do_efdcfsi (int64_t val
)
2284 u
.d
= int64_to_float64(val
, &env
->spe_status
);
2289 static always_inline
uint64_t _do_efdcfui (uint64_t val
)
2293 u
.d
= uint64_to_float64(val
, &env
->spe_status
);
2298 static always_inline
int64_t _do_efdctsi (uint64_t val
)
2303 /* NaN are not treated the same way IEEE 754 does */
2304 if (unlikely(isnan(u
.d
)))
2307 return float64_to_int64(u
.d
, &env
->spe_status
);
2310 static always_inline
uint64_t _do_efdctui (uint64_t val
)
2315 /* NaN are not treated the same way IEEE 754 does */
2316 if (unlikely(isnan(u
.d
)))
2319 return float64_to_uint64(u
.d
, &env
->spe_status
);
2322 static always_inline
int64_t _do_efdctsiz (uint64_t val
)
2327 /* NaN are not treated the same way IEEE 754 does */
2328 if (unlikely(isnan(u
.d
)))
2331 return float64_to_int64_round_to_zero(u
.d
, &env
->spe_status
);
2334 static always_inline
uint64_t _do_efdctuiz (uint64_t val
)
2339 /* NaN are not treated the same way IEEE 754 does */
2340 if (unlikely(isnan(u
.d
)))
2343 return float64_to_uint64_round_to_zero(u
.d
, &env
->spe_status
);
2346 void do_efdcfsi (void)
2348 T0_64
= _do_efdcfsi(T0_64
);
2351 void do_efdcfui (void)
2353 T0_64
= _do_efdcfui(T0_64
);
2356 void do_efdctsi (void)
2358 T0_64
= _do_efdctsi(T0_64
);
2361 void do_efdctui (void)
2363 T0_64
= _do_efdctui(T0_64
);
2366 void do_efdctsiz (void)
2368 T0_64
= _do_efdctsiz(T0_64
);
2371 void do_efdctuiz (void)
2373 T0_64
= _do_efdctuiz(T0_64
);
2376 /* Double precision floating-point conversion to/from fractional */
2377 static always_inline
uint64_t _do_efdcfsf (int64_t val
)
2382 u
.d
= int32_to_float64(val
, &env
->spe_status
);
2383 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2384 u
.d
= float64_div(u
.d
, tmp
, &env
->spe_status
);
2389 static always_inline
uint64_t _do_efdcfuf (uint64_t val
)
2394 u
.d
= uint32_to_float64(val
, &env
->spe_status
);
2395 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2396 u
.d
= float64_div(u
.d
, tmp
, &env
->spe_status
);
2401 static always_inline
int64_t _do_efdctsf (uint64_t val
)
2407 /* NaN are not treated the same way IEEE 754 does */
2408 if (unlikely(isnan(u
.d
)))
2410 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2411 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2413 return float64_to_int32(u
.d
, &env
->spe_status
);
2416 static always_inline
uint64_t _do_efdctuf (uint64_t val
)
2422 /* NaN are not treated the same way IEEE 754 does */
2423 if (unlikely(isnan(u
.d
)))
2425 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2426 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2428 return float64_to_uint32(u
.d
, &env
->spe_status
);
2431 static always_inline
int64_t _do_efdctsfz (uint64_t val
)
2437 /* NaN are not treated the same way IEEE 754 does */
2438 if (unlikely(isnan(u
.d
)))
2440 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2441 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2443 return float64_to_int32_round_to_zero(u
.d
, &env
->spe_status
);
2446 static always_inline
uint64_t _do_efdctufz (uint64_t val
)
2452 /* NaN are not treated the same way IEEE 754 does */
2453 if (unlikely(isnan(u
.d
)))
2455 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2456 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2458 return float64_to_uint32_round_to_zero(u
.d
, &env
->spe_status
);
2461 void do_efdcfsf (void)
2463 T0_64
= _do_efdcfsf(T0_64
);
2466 void do_efdcfuf (void)
2468 T0_64
= _do_efdcfuf(T0_64
);
2471 void do_efdctsf (void)
2473 T0_64
= _do_efdctsf(T0_64
);
2476 void do_efdctuf (void)
2478 T0_64
= _do_efdctuf(T0_64
);
2481 void do_efdctsfz (void)
2483 T0_64
= _do_efdctsfz(T0_64
);
2486 void do_efdctufz (void)
2488 T0_64
= _do_efdctufz(T0_64
);
2491 /* Floating point conversion between single and double precision */
2492 static always_inline
uint32_t _do_efscfd (uint64_t val
)
2498 u2
.f
= float64_to_float32(u1
.d
, &env
->spe_status
);
2503 static always_inline
uint64_t _do_efdcfs (uint32_t val
)
2509 u2
.d
= float32_to_float64(u1
.f
, &env
->spe_status
);
2514 void do_efscfd (void)
2516 T0_64
= _do_efscfd(T0_64
);
2519 void do_efdcfs (void)
2521 T0_64
= _do_efdcfs(T0_64
);
2524 /* Single precision fixed-point vector arithmetic */
2540 /* Single-precision floating-point comparisons */
2541 static always_inline
int _do_efscmplt (uint32_t op1
, uint32_t op2
)
2543 /* XXX: TODO: test special values (NaN, infinites, ...) */
2544 return _do_efststlt(op1
, op2
);
2547 static always_inline
int _do_efscmpgt (uint32_t op1
, uint32_t op2
)
2549 /* XXX: TODO: test special values (NaN, infinites, ...) */
2550 return _do_efststgt(op1
, op2
);
2553 static always_inline
int _do_efscmpeq (uint32_t op1
, uint32_t op2
)
2555 /* XXX: TODO: test special values (NaN, infinites, ...) */
2556 return _do_efststeq(op1
, op2
);
2559 void do_efscmplt (void)
2561 T0
= _do_efscmplt(T0_64
, T1_64
);
2564 void do_efscmpgt (void)
2566 T0
= _do_efscmpgt(T0_64
, T1_64
);
2569 void do_efscmpeq (void)
2571 T0
= _do_efscmpeq(T0_64
, T1_64
);
2574 /* Single-precision floating-point vector comparisons */
2576 DO_SPE_CMP(fscmplt
);
2578 DO_SPE_CMP(fscmpgt
);
2580 DO_SPE_CMP(fscmpeq
);
2582 DO_SPE_CMP(fststlt
);
2584 DO_SPE_CMP(fststgt
);
2586 DO_SPE_CMP(fststeq
);
2588 /* Single-precision floating-point vector conversions */
2602 DO_SPE_OP1(fsctsiz
);
2604 DO_SPE_OP1(fsctuiz
);
2610 /*****************************************************************************/
2611 /* Softmmu support */
2612 #if !defined (CONFIG_USER_ONLY)
2614 #define MMUSUFFIX _mmu
2617 #include "softmmu_template.h"
2620 #include "softmmu_template.h"
2623 #include "softmmu_template.h"
2626 #include "softmmu_template.h"
2628 /* try to fill the TLB and return an exception if error. If retaddr is
2629 NULL, it means that the function was called in C code (i.e. not
2630 from generated code or from helper.c) */
2631 /* XXX: fix it to restore all registers */
2632 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
2634 TranslationBlock
*tb
;
2635 CPUState
*saved_env
;
2639 /* XXX: hack to restore env in all cases, even if not called from
2642 env
= cpu_single_env
;
2643 ret
= cpu_ppc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
2644 if (unlikely(ret
!= 0)) {
2645 if (likely(retaddr
)) {
2646 /* now we have a real cpu fault */
2647 pc
= (unsigned long)retaddr
;
2648 tb
= tb_find_pc(pc
);
2650 /* the PC is inside the translated code. It means that we have
2651 a virtual CPU fault */
2652 cpu_restore_state(tb
, env
, pc
, NULL
);
2655 do_raise_exception_err(env
->exception_index
, env
->error_code
);
2660 /* Software driven TLBs management */
2661 /* PowerPC 602/603 software TLB load instructions helpers */
2662 void do_load_6xx_tlb (int is_code
)
2664 target_ulong RPN
, CMP
, EPN
;
2667 RPN
= env
->spr
[SPR_RPA
];
2669 CMP
= env
->spr
[SPR_ICMP
];
2670 EPN
= env
->spr
[SPR_IMISS
];
2672 CMP
= env
->spr
[SPR_DCMP
];
2673 EPN
= env
->spr
[SPR_DMISS
];
2675 way
= (env
->spr
[SPR_SRR1
] >> 17) & 1;
2676 #if defined (DEBUG_SOFTWARE_TLB)
2677 if (loglevel
!= 0) {
2678 fprintf(logfile
, "%s: EPN " TDX
" " ADDRX
" PTE0 " ADDRX
2679 " PTE1 " ADDRX
" way %d\n",
2680 __func__
, T0
, EPN
, CMP
, RPN
, way
);
2683 /* Store this TLB */
2684 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2685 way
, is_code
, CMP
, RPN
);
2688 void do_load_74xx_tlb (int is_code
)
2690 target_ulong RPN
, CMP
, EPN
;
2693 RPN
= env
->spr
[SPR_PTELO
];
2694 CMP
= env
->spr
[SPR_PTEHI
];
2695 EPN
= env
->spr
[SPR_TLBMISS
] & ~0x3;
2696 way
= env
->spr
[SPR_TLBMISS
] & 0x3;
2697 #if defined (DEBUG_SOFTWARE_TLB)
2698 if (loglevel
!= 0) {
2699 fprintf(logfile
, "%s: EPN " TDX
" " ADDRX
" PTE0 " ADDRX
2700 " PTE1 " ADDRX
" way %d\n",
2701 __func__
, T0
, EPN
, CMP
, RPN
, way
);
2704 /* Store this TLB */
2705 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2706 way
, is_code
, CMP
, RPN
);
2709 static always_inline target_ulong
booke_tlb_to_page_size (int size
)
2711 return 1024 << (2 * size
);
2714 static always_inline
int booke_page_size_to_tlb (target_ulong page_size
)
2718 switch (page_size
) {
2752 #if defined (TARGET_PPC64)
2753 case 0x000100000000ULL
:
2756 case 0x000400000000ULL
:
2759 case 0x001000000000ULL
:
2762 case 0x004000000000ULL
:
2765 case 0x010000000000ULL
:
2777 /* Helpers for 4xx TLB management */
2778 void do_4xx_tlbre_lo (void)
2784 tlb
= &env
->tlb
[T0
].tlbe
;
2786 if (tlb
->prot
& PAGE_VALID
)
2788 size
= booke_page_size_to_tlb(tlb
->size
);
2789 if (size
< 0 || size
> 0x7)
2792 env
->spr
[SPR_40x_PID
] = tlb
->PID
;
2795 void do_4xx_tlbre_hi (void)
2800 tlb
= &env
->tlb
[T0
].tlbe
;
2802 if (tlb
->prot
& PAGE_EXEC
)
2804 if (tlb
->prot
& PAGE_WRITE
)
2808 void do_4xx_tlbwe_hi (void)
2811 target_ulong page
, end
;
2813 #if defined (DEBUG_SOFTWARE_TLB)
2814 if (loglevel
!= 0) {
2815 fprintf(logfile
, "%s T0 " TDX
" T1 " TDX
"\n", __func__
, T0
, T1
);
2819 tlb
= &env
->tlb
[T0
].tlbe
;
2820 /* Invalidate previous TLB (if it's valid) */
2821 if (tlb
->prot
& PAGE_VALID
) {
2822 end
= tlb
->EPN
+ tlb
->size
;
2823 #if defined (DEBUG_SOFTWARE_TLB)
2824 if (loglevel
!= 0) {
2825 fprintf(logfile
, "%s: invalidate old TLB %d start " ADDRX
2826 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2829 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2830 tlb_flush_page(env
, page
);
2832 tlb
->size
= booke_tlb_to_page_size((T1
>> 7) & 0x7);
2833 /* We cannot handle TLB size < TARGET_PAGE_SIZE.
2834 * If this ever occurs, one should use the ppcemb target instead
2835 * of the ppc or ppc64 one
2837 if ((T1
& 0x40) && tlb
->size
< TARGET_PAGE_SIZE
) {
2838 cpu_abort(env
, "TLB size " TARGET_FMT_lu
" < %u "
2839 "are not supported (%d)\n",
2840 tlb
->size
, TARGET_PAGE_SIZE
, (int)((T1
>> 7) & 0x7));
2842 tlb
->EPN
= T1
& ~(tlb
->size
- 1);
2844 tlb
->prot
|= PAGE_VALID
;
2846 tlb
->prot
&= ~PAGE_VALID
;
2848 /* XXX: TO BE FIXED */
2849 cpu_abort(env
, "Little-endian TLB entries are not supported by now\n");
2851 tlb
->PID
= env
->spr
[SPR_40x_PID
]; /* PID */
2852 tlb
->attr
= T1
& 0xFF;
2853 #if defined (DEBUG_SOFTWARE_TLB)
2854 if (loglevel
!= 0) {
2855 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
2856 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
2857 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
2858 tlb
->prot
& PAGE_READ
? 'r' : '-',
2859 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
2860 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
2861 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
2864 /* Invalidate new TLB (if valid) */
2865 if (tlb
->prot
& PAGE_VALID
) {
2866 end
= tlb
->EPN
+ tlb
->size
;
2867 #if defined (DEBUG_SOFTWARE_TLB)
2868 if (loglevel
!= 0) {
2869 fprintf(logfile
, "%s: invalidate TLB %d start " ADDRX
2870 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2873 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2874 tlb_flush_page(env
, page
);
2878 void do_4xx_tlbwe_lo (void)
2882 #if defined (DEBUG_SOFTWARE_TLB)
2883 if (loglevel
!= 0) {
2884 fprintf(logfile
, "%s T0 " TDX
" T1 " TDX
"\n", __func__
, T0
, T1
);
2888 tlb
= &env
->tlb
[T0
].tlbe
;
2889 tlb
->RPN
= T1
& 0xFFFFFC00;
2890 tlb
->prot
= PAGE_READ
;
2892 tlb
->prot
|= PAGE_EXEC
;
2894 tlb
->prot
|= PAGE_WRITE
;
2895 #if defined (DEBUG_SOFTWARE_TLB)
2896 if (loglevel
!= 0) {
2897 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
2898 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
2899 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
2900 tlb
->prot
& PAGE_READ
? 'r' : '-',
2901 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
2902 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
2903 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
2908 /* PowerPC 440 TLB management */
2909 void do_440_tlbwe (int word
)
2912 target_ulong EPN
, RPN
, size
;
2915 #if defined (DEBUG_SOFTWARE_TLB)
2916 if (loglevel
!= 0) {
2917 fprintf(logfile
, "%s word %d T0 " TDX
" T1 " TDX
"\n",
2918 __func__
, word
, T0
, T1
);
2923 tlb
= &env
->tlb
[T0
].tlbe
;
2926 /* Just here to please gcc */
2928 EPN
= T1
& 0xFFFFFC00;
2929 if ((tlb
->prot
& PAGE_VALID
) && EPN
!= tlb
->EPN
)
2932 size
= booke_tlb_to_page_size((T1
>> 4) & 0xF);
2933 if ((tlb
->prot
& PAGE_VALID
) && tlb
->size
< size
)
2937 tlb
->attr
|= (T1
>> 8) & 1;
2939 tlb
->prot
|= PAGE_VALID
;
2941 if (tlb
->prot
& PAGE_VALID
) {
2942 tlb
->prot
&= ~PAGE_VALID
;
2946 tlb
->PID
= env
->spr
[SPR_440_MMUCR
] & 0x000000FF;
2951 RPN
= T1
& 0xFFFFFC0F;
2952 if ((tlb
->prot
& PAGE_VALID
) && tlb
->RPN
!= RPN
)
2957 tlb
->attr
= (tlb
->attr
& 0x1) | (T1
& 0x0000FF00);
2958 tlb
->prot
= tlb
->prot
& PAGE_VALID
;
2960 tlb
->prot
|= PAGE_READ
<< 4;
2962 tlb
->prot
|= PAGE_WRITE
<< 4;
2964 tlb
->prot
|= PAGE_EXEC
<< 4;
2966 tlb
->prot
|= PAGE_READ
;
2968 tlb
->prot
|= PAGE_WRITE
;
2970 tlb
->prot
|= PAGE_EXEC
;
2975 void do_440_tlbre (int word
)
2981 tlb
= &env
->tlb
[T0
].tlbe
;
2984 /* Just here to please gcc */
2987 size
= booke_page_size_to_tlb(tlb
->size
);
2988 if (size
< 0 || size
> 0xF)
2991 if (tlb
->attr
& 0x1)
2993 if (tlb
->prot
& PAGE_VALID
)
2995 env
->spr
[SPR_440_MMUCR
] &= ~0x000000FF;
2996 env
->spr
[SPR_440_MMUCR
] |= tlb
->PID
;
3002 T0
= tlb
->attr
& ~0x1;
3003 if (tlb
->prot
& (PAGE_READ
<< 4))
3005 if (tlb
->prot
& (PAGE_WRITE
<< 4))
3007 if (tlb
->prot
& (PAGE_EXEC
<< 4))
3009 if (tlb
->prot
& PAGE_READ
)
3011 if (tlb
->prot
& PAGE_WRITE
)
3013 if (tlb
->prot
& PAGE_EXEC
)
3018 #endif /* !CONFIG_USER_ONLY */