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 #if defined(TARGET_PPC64H)
37 #define MEMSUFFIX _hypv
38 #include "op_helper.h"
39 #include "op_helper_mem.h"
44 //#define DEBUG_EXCEPTIONS
45 //#define DEBUG_SOFTWARE_TLB
47 /*****************************************************************************/
48 /* Exceptions processing helpers */
50 void do_raise_exception_err (uint32_t exception
, int error_code
)
53 printf("Raise exception %3x code : %d\n", exception
, error_code
);
55 env
->exception_index
= exception
;
56 env
->error_code
= error_code
;
60 void do_raise_exception (uint32_t exception
)
62 do_raise_exception_err(exception
, 0);
65 void cpu_dump_EA (target_ulong EA
);
66 void do_print_mem_EA (target_ulong EA
)
71 /*****************************************************************************/
72 /* Registers load and stores */
73 void do_load_cr (void)
75 T0
= (env
->crf
[0] << 28) |
85 void do_store_cr (uint32_t mask
)
89 for (i
= 0, sh
= 7; i
< 8; i
++, sh
--) {
91 env
->crf
[i
] = (T0
>> (sh
* 4)) & 0xFUL
;
95 #if defined(TARGET_PPC64)
96 void do_store_pri (int prio
)
98 env
->spr
[SPR_PPR
] &= ~0x001C000000000000ULL
;
99 env
->spr
[SPR_PPR
] |= ((uint64_t)prio
& 0x7) << 50;
103 target_ulong
ppc_load_dump_spr (int sprn
)
106 fprintf(logfile
, "Read SPR %d %03x => " ADDRX
"\n",
107 sprn
, sprn
, env
->spr
[sprn
]);
110 return env
->spr
[sprn
];
113 void ppc_store_dump_spr (int sprn
, target_ulong val
)
116 fprintf(logfile
, "Write SPR %d %03x => " ADDRX
" <= " ADDRX
"\n",
117 sprn
, sprn
, env
->spr
[sprn
], val
);
119 env
->spr
[sprn
] = val
;
122 /*****************************************************************************/
123 /* Fixed point operations helpers */
128 if (likely(!((uint32_t)T0
< (uint32_t)T2
||
129 (xer_ca
== 1 && (uint32_t)T0
== (uint32_t)T2
)))) {
136 #if defined(TARGET_PPC64)
137 void do_adde_64 (void)
141 if (likely(!((uint64_t)T0
< (uint64_t)T2
||
142 (xer_ca
== 1 && (uint64_t)T0
== (uint64_t)T2
)))) {
150 void do_addmeo (void)
154 if (likely(!((uint32_t)T1
&
155 ((uint32_t)T1
^ (uint32_t)T0
) & (1UL << 31)))) {
165 #if defined(TARGET_PPC64)
166 void do_addmeo_64 (void)
170 if (likely(!((uint64_t)T1
&
171 ((uint64_t)T1
^ (uint64_t)T0
) & (1ULL << 63)))) {
184 if (likely(!(((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== -1) ||
185 (int32_t)T1
== 0))) {
187 T0
= (int32_t)T0
/ (int32_t)T1
;
191 T0
= (-1) * ((uint32_t)T0
>> 31);
195 #if defined(TARGET_PPC64)
198 if (likely(!(((int64_t)T0
== INT64_MIN
&& (int64_t)T1
== -1ULL) ||
199 (int64_t)T1
== 0))) {
201 T0
= (int64_t)T0
/ (int64_t)T1
;
205 T0
= (-1ULL) * ((uint64_t)T0
>> 63);
210 void do_divwuo (void)
212 if (likely((uint32_t)T1
!= 0)) {
214 T0
= (uint32_t)T0
/ (uint32_t)T1
;
222 #if defined(TARGET_PPC64)
223 void do_divduo (void)
225 if (likely((uint64_t)T1
!= 0)) {
227 T0
= (uint64_t)T0
/ (uint64_t)T1
;
236 void do_mullwo (void)
238 int64_t res
= (int64_t)T0
* (int64_t)T1
;
240 if (likely((int32_t)res
== res
)) {
249 #if defined(TARGET_PPC64)
250 void do_mulldo (void)
255 muls64(&tl
, &th
, T0
, T1
);
256 /* If th != 0 && th != -1, then we had an overflow */
257 if (likely((th
+ 1) <= 1)) {
269 if (likely((int32_t)T0
!= INT32_MIN
)) {
278 #if defined(TARGET_PPC64)
279 void do_nego_64 (void)
281 if (likely((int64_t)T0
!= INT64_MIN
)) {
293 T0
= T1
+ ~T0
+ xer_ca
;
294 if (likely((uint32_t)T0
>= (uint32_t)T1
&&
295 (xer_ca
== 0 || (uint32_t)T0
!= (uint32_t)T1
))) {
302 #if defined(TARGET_PPC64)
303 void do_subfe_64 (void)
305 T0
= T1
+ ~T0
+ xer_ca
;
306 if (likely((uint64_t)T0
>= (uint64_t)T1
&&
307 (xer_ca
== 0 || (uint64_t)T0
!= (uint64_t)T1
))) {
315 void do_subfmeo (void)
318 T0
= ~T0
+ xer_ca
- 1;
319 if (likely(!((uint32_t)~T1
& ((uint32_t)~T1
^ (uint32_t)T0
) &
326 if (likely((uint32_t)T1
!= UINT32_MAX
))
330 #if defined(TARGET_PPC64)
331 void do_subfmeo_64 (void)
334 T0
= ~T0
+ xer_ca
- 1;
335 if (likely(!((uint64_t)~T1
& ((uint64_t)~T1
^ (uint64_t)T0
) &
342 if (likely((uint64_t)T1
!= UINT64_MAX
))
347 void do_subfzeo (void)
351 if (likely(!(((uint32_t)~T1
^ UINT32_MAX
) &
352 ((uint32_t)(~T1
) ^ (uint32_t)T0
) & (1UL << 31)))) {
358 if (likely((uint32_t)T0
>= (uint32_t)~T1
)) {
365 #if defined(TARGET_PPC64)
366 void do_subfzeo_64 (void)
370 if (likely(!(((uint64_t)~T1
^ UINT64_MAX
) &
371 ((uint64_t)(~T1
) ^ (uint64_t)T0
) & (1ULL << 63)))) {
377 if (likely((uint64_t)T0
>= (uint64_t)~T1
)) {
385 void do_cntlzw (void)
390 #if defined(TARGET_PPC64)
391 void do_cntlzd (void)
397 /* shift right arithmetic helper */
402 if (likely(!(T1
& 0x20UL
))) {
403 if (likely((uint32_t)T1
!= 0)) {
404 ret
= (int32_t)T0
>> (T1
& 0x1fUL
);
405 if (likely(ret
>= 0 || ((int32_t)T0
& ((1 << T1
) - 1)) == 0)) {
415 ret
= (-1) * ((uint32_t)T0
>> 31);
416 if (likely(ret
>= 0 || ((uint32_t)T0
& ~0x80000000UL
) == 0)) {
425 #if defined(TARGET_PPC64)
430 if (likely(!(T1
& 0x40UL
))) {
431 if (likely((uint64_t)T1
!= 0)) {
432 ret
= (int64_t)T0
>> (T1
& 0x3FUL
);
433 if (likely(ret
>= 0 || ((int64_t)T0
& ((1 << T1
) - 1)) == 0)) {
443 ret
= (-1) * ((uint64_t)T0
>> 63);
444 if (likely(ret
>= 0 || ((uint64_t)T0
& ~0x8000000000000000ULL
) == 0)) {
454 void do_popcntb (void)
460 for (i
= 0; i
< 32; i
+= 8)
461 ret
|= ctpop8((T0
>> i
) & 0xFF) << i
;
465 #if defined(TARGET_PPC64)
466 void do_popcntb_64 (void)
472 for (i
= 0; i
< 64; i
+= 8)
473 ret
|= ctpop8((T0
>> i
) & 0xFF) << i
;
478 /*****************************************************************************/
479 /* Floating point operations helpers */
480 static always_inline
int fpisneg (float64 f
)
489 return u
.u
>> 63 != 0;
492 static always_inline
int isden (float f
)
501 return ((u
.u
>> 52) & 0x7FF) == 0;
504 static always_inline
int iszero (float64 f
)
513 return (u
.u
& ~0x8000000000000000ULL
) == 0;
516 static always_inline
int isinfinity (float64 f
)
525 return ((u
.u
>> 52) & 0x3FF) == 0x3FF &&
526 (u
.u
& 0x000FFFFFFFFFFFFFULL
) == 0;
529 void do_compute_fprf (int set_fprf
)
533 isneg
= fpisneg(FT0
);
534 if (unlikely(float64_is_nan(FT0
))) {
535 if (float64_is_signaling_nan(FT0
)) {
536 /* Signaling NaN: flags are undefined */
542 } else if (unlikely(isinfinity(FT0
))) {
557 /* Denormalized numbers */
560 /* Normalized numbers */
571 /* We update FPSCR_FPRF */
572 env
->fpscr
&= ~(0x1F << FPSCR_FPRF
);
573 env
->fpscr
|= T0
<< FPSCR_FPRF
;
575 /* We just need fpcc to update Rc1 */
579 /* Floating-point invalid operations exception */
580 static always_inline
void fload_invalid_op_excp (int op
)
585 if (op
& POWERPC_EXCP_FP_VXSNAN
) {
586 /* Operation on signaling NaN */
587 env
->fpscr
|= 1 << FPSCR_VXSNAN
;
589 if (op
& POWERPC_EXCP_FP_VXSOFT
) {
590 /* Software-defined condition */
591 env
->fpscr
|= 1 << FPSCR_VXSOFT
;
593 switch (op
& ~(POWERPC_EXCP_FP_VXSOFT
| POWERPC_EXCP_FP_VXSNAN
)) {
594 case POWERPC_EXCP_FP_VXISI
:
595 /* Magnitude subtraction of infinities */
596 env
->fpscr
|= 1 << FPSCR_VXISI
;
598 case POWERPC_EXCP_FP_VXIDI
:
599 /* Division of infinity by infinity */
600 env
->fpscr
|= 1 << FPSCR_VXIDI
;
602 case POWERPC_EXCP_FP_VXZDZ
:
603 /* Division of zero by zero */
604 env
->fpscr
|= 1 << FPSCR_VXZDZ
;
606 case POWERPC_EXCP_FP_VXIMZ
:
607 /* Multiplication of zero by infinity */
608 env
->fpscr
|= 1 << FPSCR_VXIMZ
;
610 case POWERPC_EXCP_FP_VXVC
:
611 /* Ordered comparison of NaN */
612 env
->fpscr
|= 1 << FPSCR_VXVC
;
613 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
614 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
615 /* We must update the target FPR before raising the exception */
617 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
618 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_VXVC
;
619 /* Update the floating-point enabled exception summary */
620 env
->fpscr
|= 1 << FPSCR_FEX
;
621 /* Exception is differed */
625 case POWERPC_EXCP_FP_VXSQRT
:
626 /* Square root of a negative number */
627 env
->fpscr
|= 1 << FPSCR_VXSQRT
;
629 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
631 /* Set the result to quiet NaN */
633 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
634 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
637 case POWERPC_EXCP_FP_VXCVI
:
638 /* Invalid conversion */
639 env
->fpscr
|= 1 << FPSCR_VXCVI
;
640 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
642 /* Set the result to quiet NaN */
644 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
645 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
649 /* Update the floating-point invalid operation summary */
650 env
->fpscr
|= 1 << FPSCR_VX
;
651 /* Update the floating-point exception summary */
652 env
->fpscr
|= 1 << FPSCR_FX
;
654 /* Update the floating-point enabled exception summary */
655 env
->fpscr
|= 1 << FPSCR_FEX
;
656 if (msr_fe0
!= 0 || msr_fe1
!= 0)
657 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_FP
| op
);
661 static always_inline
void float_zero_divide_excp (void)
668 env
->fpscr
|= 1 << FPSCR_ZX
;
669 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
670 /* Update the floating-point exception summary */
671 env
->fpscr
|= 1 << FPSCR_FX
;
673 /* Update the floating-point enabled exception summary */
674 env
->fpscr
|= 1 << FPSCR_FEX
;
675 if (msr_fe0
!= 0 || msr_fe1
!= 0) {
676 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
677 POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
);
680 /* Set the result to infinity */
683 u0
.u
= ((u0
.u
^ u1
.u
) & 0x8000000000000000ULL
);
684 u0
.u
|= 0x3FFULL
<< 52;
689 static always_inline
void float_overflow_excp (void)
691 env
->fpscr
|= 1 << FPSCR_OX
;
692 /* Update the floating-point exception summary */
693 env
->fpscr
|= 1 << FPSCR_FX
;
695 /* XXX: should adjust the result */
696 /* Update the floating-point enabled exception summary */
697 env
->fpscr
|= 1 << FPSCR_FEX
;
698 /* We must update the target FPR before raising the exception */
699 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
700 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
702 env
->fpscr
|= 1 << FPSCR_XX
;
703 env
->fpscr
|= 1 << FPSCR_FI
;
707 static always_inline
void float_underflow_excp (void)
709 env
->fpscr
|= 1 << FPSCR_UX
;
710 /* Update the floating-point exception summary */
711 env
->fpscr
|= 1 << FPSCR_FX
;
713 /* XXX: should adjust the result */
714 /* Update the floating-point enabled exception summary */
715 env
->fpscr
|= 1 << FPSCR_FEX
;
716 /* We must update the target FPR before raising the exception */
717 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
718 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
722 static always_inline
void float_inexact_excp (void)
724 env
->fpscr
|= 1 << FPSCR_XX
;
725 /* Update the floating-point exception summary */
726 env
->fpscr
|= 1 << FPSCR_FX
;
728 /* Update the floating-point enabled exception summary */
729 env
->fpscr
|= 1 << FPSCR_FEX
;
730 /* We must update the target FPR before raising the exception */
731 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
732 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
736 static always_inline
void fpscr_set_rounding_mode (void)
740 /* Set rounding mode */
743 /* Best approximation (round to nearest) */
744 rnd_type
= float_round_nearest_even
;
747 /* Smaller magnitude (round toward zero) */
748 rnd_type
= float_round_to_zero
;
751 /* Round toward +infinite */
752 rnd_type
= float_round_up
;
756 /* Round toward -infinite */
757 rnd_type
= float_round_down
;
760 set_float_rounding_mode(rnd_type
, &env
->fp_status
);
763 void do_fpscr_setbit (int bit
)
767 prev
= (env
->fpscr
>> bit
) & 1;
768 env
->fpscr
|= 1 << bit
;
772 env
->fpscr
|= 1 << FPSCR_FX
;
776 env
->fpscr
|= 1 << FPSCR_FX
;
781 env
->fpscr
|= 1 << FPSCR_FX
;
786 env
->fpscr
|= 1 << FPSCR_FX
;
791 env
->fpscr
|= 1 << FPSCR_FX
;
804 env
->fpscr
|= 1 << FPSCR_VX
;
805 env
->fpscr
|= 1 << FPSCR_FX
;
812 env
->error_code
= POWERPC_EXCP_FP
;
814 env
->error_code
|= POWERPC_EXCP_FP_VXSNAN
;
816 env
->error_code
|= POWERPC_EXCP_FP_VXISI
;
818 env
->error_code
|= POWERPC_EXCP_FP_VXIDI
;
820 env
->error_code
|= POWERPC_EXCP_FP_VXZDZ
;
822 env
->error_code
|= POWERPC_EXCP_FP_VXIMZ
;
824 env
->error_code
|= POWERPC_EXCP_FP_VXVC
;
826 env
->error_code
|= POWERPC_EXCP_FP_VXSOFT
;
828 env
->error_code
|= POWERPC_EXCP_FP_VXSQRT
;
830 env
->error_code
|= POWERPC_EXCP_FP_VXCVI
;
837 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
844 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
851 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
;
858 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
864 fpscr_set_rounding_mode();
869 /* Update the floating-point enabled exception summary */
870 env
->fpscr
|= 1 << FPSCR_FEX
;
871 /* We have to update Rc1 before raising the exception */
872 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
878 #if defined(WORDS_BIGENDIAN)
885 void do_store_fpscr (uint32_t mask
)
888 * We use only the 32 LSB of the incoming fpr
903 new |= prev
& 0x90000000;
904 for (i
= 0; i
< 7; i
++) {
905 if (mask
& (1 << i
)) {
906 env
->fpscr
&= ~(0xF << (4 * i
));
907 env
->fpscr
|= new & (0xF << (4 * i
));
910 /* Update VX and FEX */
912 env
->fpscr
|= 1 << FPSCR_VX
;
913 if ((fpscr_ex
& fpscr_eex
) != 0) {
914 env
->fpscr
|= 1 << FPSCR_FEX
;
915 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
916 /* XXX: we should compute it properly */
917 env
->error_code
= POWERPC_EXCP_FP
;
919 fpscr_set_rounding_mode();
924 #ifdef CONFIG_SOFTFLOAT
925 void do_float_check_status (void)
927 if (env
->exception_index
== POWERPC_EXCP_PROGRAM
&&
928 (env
->error_code
& POWERPC_EXCP_FP
)) {
929 /* Differred floating-point exception after target FPR update */
930 if (msr_fe0
!= 0 || msr_fe1
!= 0)
931 do_raise_exception_err(env
->exception_index
, env
->error_code
);
932 } else if (env
->fp_status
.float_exception_flags
& float_flag_overflow
) {
933 float_overflow_excp();
934 } else if (env
->fp_status
.float_exception_flags
& float_flag_underflow
) {
935 float_underflow_excp();
936 } else if (env
->fp_status
.float_exception_flags
& float_flag_inexact
) {
937 float_inexact_excp();
942 #if USE_PRECISE_EMULATION
945 if (unlikely(float64_is_signaling_nan(FT0
) ||
946 float64_is_signaling_nan(FT1
))) {
948 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
949 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
950 fpisneg(FT0
) == fpisneg(FT1
))) {
951 FT0
= float64_add(FT0
, FT1
, &env
->fp_status
);
953 /* Magnitude subtraction of infinities */
954 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
960 if (unlikely(float64_is_signaling_nan(FT0
) ||
961 float64_is_signaling_nan(FT1
))) {
962 /* sNaN subtraction */
963 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
964 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
965 fpisneg(FT0
) != fpisneg(FT1
))) {
966 FT0
= float64_sub(FT0
, FT1
, &env
->fp_status
);
968 /* Magnitude subtraction of infinities */
969 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
975 if (unlikely(float64_is_signaling_nan(FT0
) ||
976 float64_is_signaling_nan(FT1
))) {
977 /* sNaN multiplication */
978 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
979 } else if (unlikely((isinfinity(FT0
) && iszero(FT1
)) ||
980 (iszero(FT0
) && isinfinity(FT1
)))) {
981 /* Multiplication of zero by infinity */
982 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIMZ
);
984 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
990 if (unlikely(float64_is_signaling_nan(FT0
) ||
991 float64_is_signaling_nan(FT1
))) {
993 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
994 } else if (unlikely(isinfinity(FT0
) && isinfinity(FT1
))) {
995 /* Division of infinity by infinity */
996 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIDI
);
997 } else if (unlikely(iszero(FT1
))) {
999 /* Division of zero by zero */
1000 fload_invalid_op_excp(POWERPC_EXCP_FP_VXZDZ
);
1002 /* Division by zero */
1003 float_zero_divide_excp();
1006 FT0
= float64_div(FT0
, FT1
, &env
->fp_status
);
1009 #endif /* USE_PRECISE_EMULATION */
1011 void do_fctiw (void)
1018 if (unlikely(float64_is_signaling_nan(FT0
))) {
1019 /* sNaN conversion */
1020 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1021 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1022 /* qNan / infinity conversion */
1023 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1025 p
.i
= float64_to_int32(FT0
, &env
->fp_status
);
1026 #if USE_PRECISE_EMULATION
1027 /* XXX: higher bits are not supposed to be significant.
1028 * to make tests easier, return the same as a real PowerPC 750
1030 p
.i
|= 0xFFF80000ULL
<< 32;
1036 void do_fctiwz (void)
1043 if (unlikely(float64_is_signaling_nan(FT0
))) {
1044 /* sNaN conversion */
1045 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1046 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1047 /* qNan / infinity conversion */
1048 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1050 p
.i
= float64_to_int32_round_to_zero(FT0
, &env
->fp_status
);
1051 #if USE_PRECISE_EMULATION
1052 /* XXX: higher bits are not supposed to be significant.
1053 * to make tests easier, return the same as a real PowerPC 750
1055 p
.i
|= 0xFFF80000ULL
<< 32;
1061 #if defined(TARGET_PPC64)
1062 void do_fcfid (void)
1070 FT0
= int64_to_float64(p
.i
, &env
->fp_status
);
1073 void do_fctid (void)
1080 if (unlikely(float64_is_signaling_nan(FT0
))) {
1081 /* sNaN conversion */
1082 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1083 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1084 /* qNan / infinity conversion */
1085 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1087 p
.i
= float64_to_int64(FT0
, &env
->fp_status
);
1092 void do_fctidz (void)
1099 if (unlikely(float64_is_signaling_nan(FT0
))) {
1100 /* sNaN conversion */
1101 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1102 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1103 /* qNan / infinity conversion */
1104 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1106 p
.i
= float64_to_int64_round_to_zero(FT0
, &env
->fp_status
);
1113 static always_inline
void do_fri (int rounding_mode
)
1115 if (unlikely(float64_is_signaling_nan(FT0
))) {
1117 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
1118 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
1119 /* qNan / infinity round */
1120 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
1122 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
1123 FT0
= float64_round_to_int(FT0
, &env
->fp_status
);
1124 /* Restore rounding mode from FPSCR */
1125 fpscr_set_rounding_mode();
1131 do_fri(float_round_nearest_even
);
1136 do_fri(float_round_to_zero
);
1141 do_fri(float_round_up
);
1146 do_fri(float_round_down
);
1149 #if USE_PRECISE_EMULATION
1150 void do_fmadd (void)
1152 if (unlikely(float64_is_signaling_nan(FT0
) ||
1153 float64_is_signaling_nan(FT1
) ||
1154 float64_is_signaling_nan(FT2
))) {
1155 /* sNaN operation */
1156 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1159 /* This is the way the PowerPC specification defines it */
1160 float128 ft0_128
, ft1_128
;
1162 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1163 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1164 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1165 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1166 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
1167 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1169 /* This is OK on x86 hosts */
1170 FT0
= (FT0
* FT1
) + FT2
;
1175 void do_fmsub (void)
1177 if (unlikely(float64_is_signaling_nan(FT0
) ||
1178 float64_is_signaling_nan(FT1
) ||
1179 float64_is_signaling_nan(FT2
))) {
1180 /* sNaN operation */
1181 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1184 /* This is the way the PowerPC specification defines it */
1185 float128 ft0_128
, ft1_128
;
1187 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1188 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1189 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1190 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1191 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
1192 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1194 /* This is OK on x86 hosts */
1195 FT0
= (FT0
* FT1
) - FT2
;
1199 #endif /* USE_PRECISE_EMULATION */
1201 void do_fnmadd (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_add(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_add(FT0
, FT2
, &env
->fp_status
);
1228 if (likely(!isnan(FT0
)))
1229 FT0
= float64_chs(FT0
);
1233 void do_fnmsub (void)
1235 if (unlikely(float64_is_signaling_nan(FT0
) ||
1236 float64_is_signaling_nan(FT1
) ||
1237 float64_is_signaling_nan(FT2
))) {
1238 /* sNaN operation */
1239 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1241 #if USE_PRECISE_EMULATION
1243 /* This is the way the PowerPC specification defines it */
1244 float128 ft0_128
, ft1_128
;
1246 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1247 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1248 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1249 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1250 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
1251 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1253 /* This is OK on x86 hosts */
1254 FT0
= (FT0
* FT1
) - FT2
;
1257 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1258 FT0
= float64_sub(FT0
, FT2
, &env
->fp_status
);
1260 if (likely(!isnan(FT0
)))
1261 FT0
= float64_chs(FT0
);
1265 #if USE_PRECISE_EMULATION
1268 if (unlikely(float64_is_signaling_nan(FT0
))) {
1269 /* sNaN square root */
1270 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1272 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1275 #endif /* USE_PRECISE_EMULATION */
1277 void do_fsqrt (void)
1279 if (unlikely(float64_is_signaling_nan(FT0
))) {
1280 /* sNaN square root */
1281 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1282 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1283 /* Square root of a negative nonzero number */
1284 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1286 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1297 if (unlikely(float64_is_signaling_nan(FT0
))) {
1298 /* sNaN reciprocal */
1299 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1300 } else if (unlikely(iszero(FT0
))) {
1301 /* Zero reciprocal */
1302 float_zero_divide_excp();
1303 } else if (likely(isnormal(FT0
))) {
1304 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1307 if (p
.i
== 0x8000000000000000ULL
) {
1308 p
.i
= 0xFFF0000000000000ULL
;
1309 } else if (p
.i
== 0x0000000000000000ULL
) {
1310 p
.i
= 0x7FF0000000000000ULL
;
1311 } else if (isnan(FT0
)) {
1312 p
.i
= 0x7FF8000000000000ULL
;
1313 } else if (fpisneg(FT0
)) {
1314 p
.i
= 0x8000000000000000ULL
;
1316 p
.i
= 0x0000000000000000ULL
;
1329 if (unlikely(float64_is_signaling_nan(FT0
))) {
1330 /* sNaN reciprocal */
1331 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1332 } else if (unlikely(iszero(FT0
))) {
1333 /* Zero reciprocal */
1334 float_zero_divide_excp();
1335 } else if (likely(isnormal(FT0
))) {
1336 #if USE_PRECISE_EMULATION
1337 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1338 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1340 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1344 if (p
.i
== 0x8000000000000000ULL
) {
1345 p
.i
= 0xFFF0000000000000ULL
;
1346 } else if (p
.i
== 0x0000000000000000ULL
) {
1347 p
.i
= 0x7FF0000000000000ULL
;
1348 } else if (isnan(FT0
)) {
1349 p
.i
= 0x7FF8000000000000ULL
;
1350 } else if (fpisneg(FT0
)) {
1351 p
.i
= 0x8000000000000000ULL
;
1353 p
.i
= 0x0000000000000000ULL
;
1359 void do_frsqrte (void)
1366 if (unlikely(float64_is_signaling_nan(FT0
))) {
1367 /* sNaN reciprocal square root */
1368 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1369 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1370 /* Reciprocal square root of a negative nonzero number */
1371 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1372 } else if (likely(isnormal(FT0
))) {
1373 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1374 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1377 if (p
.i
== 0x8000000000000000ULL
) {
1378 p
.i
= 0xFFF0000000000000ULL
;
1379 } else if (p
.i
== 0x0000000000000000ULL
) {
1380 p
.i
= 0x7FF0000000000000ULL
;
1381 } else if (isnan(FT0
)) {
1382 p
.i
|= 0x000FFFFFFFFFFFFFULL
;
1383 } else if (fpisneg(FT0
)) {
1384 p
.i
= 0x7FF8000000000000ULL
;
1386 p
.i
= 0x0000000000000000ULL
;
1394 if (!fpisneg(FT0
) || iszero(FT0
))
1400 void do_fcmpu (void)
1402 if (unlikely(float64_is_signaling_nan(FT0
) ||
1403 float64_is_signaling_nan(FT1
))) {
1404 /* sNaN comparison */
1405 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
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
|= T0
<< FPSCR_FPRF
;
1419 void do_fcmpo (void)
1421 if (unlikely(float64_is_nan(FT0
) ||
1422 float64_is_nan(FT1
))) {
1423 if (float64_is_signaling_nan(FT0
) ||
1424 float64_is_signaling_nan(FT1
)) {
1425 /* sNaN comparison */
1426 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
|
1427 POWERPC_EXCP_FP_VXVC
);
1429 /* qNaN comparison */
1430 fload_invalid_op_excp(POWERPC_EXCP_FP_VXVC
);
1433 if (float64_lt(FT0
, FT1
, &env
->fp_status
)) {
1435 } else if (!float64_le(FT0
, FT1
, &env
->fp_status
)) {
1441 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1442 env
->fpscr
|= T0
<< FPSCR_FPRF
;
1445 #if !defined (CONFIG_USER_ONLY)
1446 void cpu_dump_rfi (target_ulong RA
, target_ulong msr
);
1448 void do_store_msr (void)
1450 T0
= hreg_store_msr(env
, T0
);
1452 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1453 do_raise_exception(T0
);
1457 static always_inline
void __do_rfi (target_ulong nip
, target_ulong msr
,
1458 target_ulong msrm
, int keep_msrh
)
1460 #if defined(TARGET_PPC64)
1461 if (msr
& (1ULL << MSR_SF
)) {
1462 nip
= (uint64_t)nip
;
1463 msr
&= (uint64_t)msrm
;
1465 nip
= (uint32_t)nip
;
1466 msr
= (uint32_t)(msr
& msrm
);
1468 msr
|= env
->msr
& ~((uint64_t)0xFFFFFFFF);
1471 nip
= (uint32_t)nip
;
1472 msr
&= (uint32_t)msrm
;
1474 /* XXX: beware: this is false if VLE is supported */
1475 env
->nip
= nip
& ~((target_ulong
)0x00000003);
1476 hreg_store_msr(env
, msr
);
1477 #if defined (DEBUG_OP)
1478 cpu_dump_rfi(env
->nip
, env
->msr
);
1480 /* No need to raise an exception here,
1481 * as rfi is always the last insn of a TB
1483 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1488 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1489 ~((target_ulong
)0xFFFF0000), 1);
1492 #if defined(TARGET_PPC64)
1495 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1496 ~((target_ulong
)0xFFFF0000), 0);
1499 #if defined(TARGET_PPC64H)
1500 void do_hrfid (void)
1502 __do_rfi(env
->spr
[SPR_HSRR0
], env
->spr
[SPR_HSRR1
],
1503 ~((target_ulong
)0xFFFF0000), 0);
1508 void do_tw (int flags
)
1510 if (!likely(!(((int32_t)T0
< (int32_t)T1
&& (flags
& 0x10)) ||
1511 ((int32_t)T0
> (int32_t)T1
&& (flags
& 0x08)) ||
1512 ((int32_t)T0
== (int32_t)T1
&& (flags
& 0x04)) ||
1513 ((uint32_t)T0
< (uint32_t)T1
&& (flags
& 0x02)) ||
1514 ((uint32_t)T0
> (uint32_t)T1
&& (flags
& 0x01))))) {
1515 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1519 #if defined(TARGET_PPC64)
1520 void do_td (int flags
)
1522 if (!likely(!(((int64_t)T0
< (int64_t)T1
&& (flags
& 0x10)) ||
1523 ((int64_t)T0
> (int64_t)T1
&& (flags
& 0x08)) ||
1524 ((int64_t)T0
== (int64_t)T1
&& (flags
& 0x04)) ||
1525 ((uint64_t)T0
< (uint64_t)T1
&& (flags
& 0x02)) ||
1526 ((uint64_t)T0
> (uint64_t)T1
&& (flags
& 0x01)))))
1527 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1531 /*****************************************************************************/
1532 /* PowerPC 601 specific instructions (POWER bridge) */
1533 void do_POWER_abso (void)
1535 if ((uint32_t)T0
== INT32_MIN
) {
1545 void do_POWER_clcs (void)
1549 /* Instruction cache line size */
1550 T0
= env
->icache_line_size
;
1553 /* Data cache line size */
1554 T0
= env
->dcache_line_size
;
1557 /* Minimum cache line size */
1558 T0
= env
->icache_line_size
< env
->dcache_line_size
?
1559 env
->icache_line_size
: env
->dcache_line_size
;
1562 /* Maximum cache line size */
1563 T0
= env
->icache_line_size
> env
->dcache_line_size
?
1564 env
->icache_line_size
: env
->dcache_line_size
;
1572 void do_POWER_div (void)
1576 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== -1) || (int32_t)T1
== 0) {
1577 T0
= (long)((-1) * (T0
>> 31));
1578 env
->spr
[SPR_MQ
] = 0;
1580 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1581 env
->spr
[SPR_MQ
] = tmp
% T1
;
1582 T0
= tmp
/ (int32_t)T1
;
1586 void do_POWER_divo (void)
1590 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== -1) || (int32_t)T1
== 0) {
1591 T0
= (long)((-1) * (T0
>> 31));
1592 env
->spr
[SPR_MQ
] = 0;
1596 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1597 env
->spr
[SPR_MQ
] = tmp
% T1
;
1599 if (tmp
> (int64_t)INT32_MAX
|| tmp
< (int64_t)INT32_MIN
) {
1609 void do_POWER_divs (void)
1611 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== -1) || (int32_t)T1
== 0) {
1612 T0
= (long)((-1) * (T0
>> 31));
1613 env
->spr
[SPR_MQ
] = 0;
1615 env
->spr
[SPR_MQ
] = T0
% T1
;
1616 T0
= (int32_t)T0
/ (int32_t)T1
;
1620 void do_POWER_divso (void)
1622 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== -1) || (int32_t)T1
== 0) {
1623 T0
= (long)((-1) * (T0
>> 31));
1624 env
->spr
[SPR_MQ
] = 0;
1628 T0
= (int32_t)T0
/ (int32_t)T1
;
1629 env
->spr
[SPR_MQ
] = (int32_t)T0
% (int32_t)T1
;
1634 void do_POWER_dozo (void)
1636 if ((int32_t)T1
> (int32_t)T0
) {
1639 if (((uint32_t)(~T2
) ^ (uint32_t)T1
^ UINT32_MAX
) &
1640 ((uint32_t)(~T2
) ^ (uint32_t)T0
) & (1UL << 31)) {
1652 void do_POWER_maskg (void)
1656 if ((uint32_t)T0
== (uint32_t)(T1
+ 1)) {
1659 ret
= (((uint32_t)(-1)) >> ((uint32_t)T0
)) ^
1660 (((uint32_t)(-1) >> ((uint32_t)T1
)) >> 1);
1661 if ((uint32_t)T0
> (uint32_t)T1
)
1667 void do_POWER_mulo (void)
1671 tmp
= (uint64_t)T0
* (uint64_t)T1
;
1672 env
->spr
[SPR_MQ
] = tmp
>> 32;
1674 if (tmp
>> 32 != ((uint64_t)T0
>> 16) * ((uint64_t)T1
>> 16)) {
1682 #if !defined (CONFIG_USER_ONLY)
1683 void do_POWER_rac (void)
1688 /* We don't have to generate many instances of this instruction,
1689 * as rac is supervisor only.
1691 if (get_physical_address(env
, &ctx
, T0
, 0, ACCESS_INT
, 1) == 0)
1696 void do_POWER_rfsvc (void)
1698 __do_rfi(env
->lr
, env
->ctr
, 0x0000FFFF, 0);
1701 /* PowerPC 601 BAT management helper */
1702 void do_store_601_batu (int nr
)
1704 do_store_ibatu(env
, nr
, (uint32_t)T0
);
1705 env
->DBAT
[0][nr
] = env
->IBAT
[0][nr
];
1706 env
->DBAT
[1][nr
] = env
->IBAT
[1][nr
];
1710 /*****************************************************************************/
1711 /* 602 specific instructions */
1712 /* mfrom is the most crazy instruction ever seen, imho ! */
1713 /* Real implementation uses a ROM table. Do the same */
1714 #define USE_MFROM_ROM_TABLE
1715 void do_op_602_mfrom (void)
1717 if (likely(T0
< 602)) {
1718 #if defined(USE_MFROM_ROM_TABLE)
1719 #include "mfrom_table.c"
1720 T0
= mfrom_ROM_table
[T0
];
1723 /* Extremly decomposed:
1725 * T0 = 256 * log10(10 + 1.0) + 0.5
1728 d
= float64_div(d
, 256, &env
->fp_status
);
1730 d
= exp10(d
); // XXX: use float emulation function
1731 d
= float64_add(d
, 1.0, &env
->fp_status
);
1732 d
= log10(d
); // XXX: use float emulation function
1733 d
= float64_mul(d
, 256, &env
->fp_status
);
1734 d
= float64_add(d
, 0.5, &env
->fp_status
);
1735 T0
= float64_round_to_int(d
, &env
->fp_status
);
1742 /*****************************************************************************/
1743 /* Embedded PowerPC specific helpers */
1744 void do_405_check_ov (void)
1746 if (likely((((uint32_t)T1
^ (uint32_t)T2
) >> 31) ||
1747 !(((uint32_t)T0
^ (uint32_t)T2
) >> 31))) {
1755 void do_405_check_sat (void)
1757 if (!likely((((uint32_t)T1
^ (uint32_t)T2
) >> 31) ||
1758 !(((uint32_t)T0
^ (uint32_t)T2
) >> 31))) {
1759 /* Saturate result */
1768 /* XXX: to be improved to check access rights when in user-mode */
1769 void do_load_dcr (void)
1773 if (unlikely(env
->dcr_env
== NULL
)) {
1774 if (loglevel
!= 0) {
1775 fprintf(logfile
, "No DCR environment\n");
1777 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1778 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1779 } else if (unlikely(ppc_dcr_read(env
->dcr_env
, T0
, &val
) != 0)) {
1780 if (loglevel
!= 0) {
1781 fprintf(logfile
, "DCR read error %d %03x\n", (int)T0
, (int)T0
);
1783 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1784 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1790 void do_store_dcr (void)
1792 if (unlikely(env
->dcr_env
== NULL
)) {
1793 if (loglevel
!= 0) {
1794 fprintf(logfile
, "No DCR environment\n");
1796 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1797 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1798 } else if (unlikely(ppc_dcr_write(env
->dcr_env
, T0
, T1
) != 0)) {
1799 if (loglevel
!= 0) {
1800 fprintf(logfile
, "DCR write error %d %03x\n", (int)T0
, (int)T0
);
1802 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1803 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1807 #if !defined(CONFIG_USER_ONLY)
1808 void do_40x_rfci (void)
1810 __do_rfi(env
->spr
[SPR_40x_SRR2
], env
->spr
[SPR_40x_SRR3
],
1811 ~((target_ulong
)0xFFFF0000), 0);
1816 __do_rfi(env
->spr
[SPR_BOOKE_CSRR0
], SPR_BOOKE_CSRR1
,
1817 ~((target_ulong
)0x3FFF0000), 0);
1822 __do_rfi(env
->spr
[SPR_BOOKE_DSRR0
], SPR_BOOKE_DSRR1
,
1823 ~((target_ulong
)0x3FFF0000), 0);
1826 void do_rfmci (void)
1828 __do_rfi(env
->spr
[SPR_BOOKE_MCSRR0
], SPR_BOOKE_MCSRR1
,
1829 ~((target_ulong
)0x3FFF0000), 0);
1832 void do_load_403_pb (int num
)
1837 void do_store_403_pb (int num
)
1839 if (likely(env
->pb
[num
] != T0
)) {
1841 /* Should be optimized */
1848 void do_440_dlmzb (void)
1854 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1855 if ((T0
& mask
) == 0)
1859 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1860 if ((T1
& mask
) == 0)
1868 #if defined(TARGET_PPCEMB)
1869 /* SPE extension helpers */
1870 /* Use a table to make this quicker */
1871 static uint8_t hbrev
[16] = {
1872 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
1873 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF,
1876 static always_inline
uint8_t byte_reverse (uint8_t val
)
1878 return hbrev
[val
>> 4] | (hbrev
[val
& 0xF] << 4);
1881 static always_inline
uint32_t word_reverse (uint32_t val
)
1883 return byte_reverse(val
>> 24) | (byte_reverse(val
>> 16) << 8) |
1884 (byte_reverse(val
>> 8) << 16) | (byte_reverse(val
) << 24);
1887 #define MASKBITS 16 // Random value - to be fixed
1888 void do_brinc (void)
1890 uint32_t a
, b
, d
, mask
;
1892 mask
= (uint32_t)(-1UL) >> MASKBITS
;
1895 d
= word_reverse(1 + word_reverse(a
| ~mask
));
1896 T0_64
= (T0_64
& ~mask
) | (d
& mask
);
1899 #define DO_SPE_OP2(name) \
1900 void do_ev##name (void) \
1902 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) | \
1903 (uint64_t)_do_e##name(T0_64, T1_64); \
1906 #define DO_SPE_OP1(name) \
1907 void do_ev##name (void) \
1909 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) | \
1910 (uint64_t)_do_e##name(T0_64); \
1913 /* Fixed-point vector arithmetic */
1914 static always_inline
uint32_t _do_eabs (uint32_t val
)
1916 if (val
!= 0x80000000)
1922 static always_inline
uint32_t _do_eaddw (uint32_t op1
, uint32_t op2
)
1927 static always_inline
int _do_ecntlsw (uint32_t val
)
1929 if (val
& 0x80000000)
1935 static always_inline
int _do_ecntlzw (uint32_t val
)
1940 static always_inline
uint32_t _do_eneg (uint32_t val
)
1942 if (val
!= 0x80000000)
1948 static always_inline
uint32_t _do_erlw (uint32_t op1
, uint32_t op2
)
1950 return rotl32(op1
, op2
);
1953 static always_inline
uint32_t _do_erndw (uint32_t val
)
1955 return (val
+ 0x000080000000) & 0xFFFF0000;
1958 static always_inline
uint32_t _do_eslw (uint32_t op1
, uint32_t op2
)
1960 /* No error here: 6 bits are used */
1961 return op1
<< (op2
& 0x3F);
1964 static always_inline
int32_t _do_esrws (int32_t op1
, uint32_t op2
)
1966 /* No error here: 6 bits are used */
1967 return op1
>> (op2
& 0x3F);
1970 static always_inline
uint32_t _do_esrwu (uint32_t op1
, uint32_t op2
)
1972 /* No error here: 6 bits are used */
1973 return op1
>> (op2
& 0x3F);
1976 static always_inline
uint32_t _do_esubfw (uint32_t op1
, uint32_t op2
)
2004 /* evsel is a little bit more complicated... */
2005 static always_inline
uint32_t _do_esel (uint32_t op1
, uint32_t op2
, int n
)
2013 void do_evsel (void)
2015 T0_64
= ((uint64_t)_do_esel(T0_64
>> 32, T1_64
>> 32, T0
>> 3) << 32) |
2016 (uint64_t)_do_esel(T0_64
, T1_64
, (T0
>> 2) & 1);
2019 /* Fixed-point vector comparisons */
2020 #define DO_SPE_CMP(name) \
2021 void do_ev##name (void) \
2023 T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32, \
2024 T1_64 >> 32) << 32, \
2025 _do_e##name(T0_64, T1_64)); \
2028 static always_inline
uint32_t _do_evcmp_merge (int t0
, int t1
)
2030 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
2032 static always_inline
int _do_ecmpeq (uint32_t op1
, uint32_t op2
)
2034 return op1
== op2
? 1 : 0;
2037 static always_inline
int _do_ecmpgts (int32_t op1
, int32_t op2
)
2039 return op1
> op2
? 1 : 0;
2042 static always_inline
int _do_ecmpgtu (uint32_t op1
, uint32_t op2
)
2044 return op1
> op2
? 1 : 0;
2047 static always_inline
int _do_ecmplts (int32_t op1
, int32_t op2
)
2049 return op1
< op2
? 1 : 0;
2052 static always_inline
int _do_ecmpltu (uint32_t op1
, uint32_t op2
)
2054 return op1
< op2
? 1 : 0;
2068 /* Single precision floating-point conversions from/to integer */
2069 static always_inline
uint32_t _do_efscfsi (int32_t val
)
2076 u
.f
= int32_to_float32(val
, &env
->spe_status
);
2081 static always_inline
uint32_t _do_efscfui (uint32_t val
)
2088 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
2093 static always_inline
int32_t _do_efsctsi (uint32_t val
)
2101 /* NaN are not treated the same way IEEE 754 does */
2102 if (unlikely(isnan(u
.f
)))
2105 return float32_to_int32(u
.f
, &env
->spe_status
);
2108 static always_inline
uint32_t _do_efsctui (uint32_t val
)
2116 /* NaN are not treated the same way IEEE 754 does */
2117 if (unlikely(isnan(u
.f
)))
2120 return float32_to_uint32(u
.f
, &env
->spe_status
);
2123 static always_inline
int32_t _do_efsctsiz (uint32_t val
)
2131 /* NaN are not treated the same way IEEE 754 does */
2132 if (unlikely(isnan(u
.f
)))
2135 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
2138 static always_inline
uint32_t _do_efsctuiz (uint32_t val
)
2146 /* NaN are not treated the same way IEEE 754 does */
2147 if (unlikely(isnan(u
.f
)))
2150 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
2153 void do_efscfsi (void)
2155 T0_64
= _do_efscfsi(T0_64
);
2158 void do_efscfui (void)
2160 T0_64
= _do_efscfui(T0_64
);
2163 void do_efsctsi (void)
2165 T0_64
= _do_efsctsi(T0_64
);
2168 void do_efsctui (void)
2170 T0_64
= _do_efsctui(T0_64
);
2173 void do_efsctsiz (void)
2175 T0_64
= _do_efsctsiz(T0_64
);
2178 void do_efsctuiz (void)
2180 T0_64
= _do_efsctuiz(T0_64
);
2183 /* Single precision floating-point conversion to/from fractional */
2184 static always_inline
uint32_t _do_efscfsf (uint32_t val
)
2192 u
.f
= int32_to_float32(val
, &env
->spe_status
);
2193 tmp
= int64_to_float32(1ULL << 32, &env
->spe_status
);
2194 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
2199 static always_inline
uint32_t _do_efscfuf (uint32_t val
)
2207 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
2208 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2209 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
2214 static always_inline
int32_t _do_efsctsf (uint32_t val
)
2223 /* NaN are not treated the same way IEEE 754 does */
2224 if (unlikely(isnan(u
.f
)))
2226 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2227 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2229 return float32_to_int32(u
.f
, &env
->spe_status
);
2232 static always_inline
uint32_t _do_efsctuf (uint32_t val
)
2241 /* NaN are not treated the same way IEEE 754 does */
2242 if (unlikely(isnan(u
.f
)))
2244 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2245 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2247 return float32_to_uint32(u
.f
, &env
->spe_status
);
2250 static always_inline
int32_t _do_efsctsfz (uint32_t val
)
2259 /* NaN are not treated the same way IEEE 754 does */
2260 if (unlikely(isnan(u
.f
)))
2262 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2263 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2265 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
2268 static always_inline
uint32_t _do_efsctufz (uint32_t val
)
2277 /* NaN are not treated the same way IEEE 754 does */
2278 if (unlikely(isnan(u
.f
)))
2280 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
2281 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
2283 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
2286 void do_efscfsf (void)
2288 T0_64
= _do_efscfsf(T0_64
);
2291 void do_efscfuf (void)
2293 T0_64
= _do_efscfuf(T0_64
);
2296 void do_efsctsf (void)
2298 T0_64
= _do_efsctsf(T0_64
);
2301 void do_efsctuf (void)
2303 T0_64
= _do_efsctuf(T0_64
);
2306 void do_efsctsfz (void)
2308 T0_64
= _do_efsctsfz(T0_64
);
2311 void do_efsctufz (void)
2313 T0_64
= _do_efsctufz(T0_64
);
2316 /* Double precision floating point helpers */
2317 static always_inline
int _do_efdcmplt (uint64_t op1
, uint64_t op2
)
2319 /* XXX: TODO: test special values (NaN, infinites, ...) */
2320 return _do_efdtstlt(op1
, op2
);
2323 static always_inline
int _do_efdcmpgt (uint64_t op1
, uint64_t op2
)
2325 /* XXX: TODO: test special values (NaN, infinites, ...) */
2326 return _do_efdtstgt(op1
, op2
);
2329 static always_inline
int _do_efdcmpeq (uint64_t op1
, uint64_t op2
)
2331 /* XXX: TODO: test special values (NaN, infinites, ...) */
2332 return _do_efdtsteq(op1
, op2
);
2335 void do_efdcmplt (void)
2337 T0
= _do_efdcmplt(T0_64
, T1_64
);
2340 void do_efdcmpgt (void)
2342 T0
= _do_efdcmpgt(T0_64
, T1_64
);
2345 void do_efdcmpeq (void)
2347 T0
= _do_efdcmpeq(T0_64
, T1_64
);
2350 /* Double precision floating-point conversion to/from integer */
2351 static always_inline
uint64_t _do_efdcfsi (int64_t val
)
2358 u
.f
= int64_to_float64(val
, &env
->spe_status
);
2363 static always_inline
uint64_t _do_efdcfui (uint64_t val
)
2370 u
.f
= uint64_to_float64(val
, &env
->spe_status
);
2375 static always_inline
int64_t _do_efdctsi (uint64_t val
)
2383 /* NaN are not treated the same way IEEE 754 does */
2384 if (unlikely(isnan(u
.f
)))
2387 return float64_to_int64(u
.f
, &env
->spe_status
);
2390 static always_inline
uint64_t _do_efdctui (uint64_t val
)
2398 /* NaN are not treated the same way IEEE 754 does */
2399 if (unlikely(isnan(u
.f
)))
2402 return float64_to_uint64(u
.f
, &env
->spe_status
);
2405 static always_inline
int64_t _do_efdctsiz (uint64_t val
)
2413 /* NaN are not treated the same way IEEE 754 does */
2414 if (unlikely(isnan(u
.f
)))
2417 return float64_to_int64_round_to_zero(u
.f
, &env
->spe_status
);
2420 static always_inline
uint64_t _do_efdctuiz (uint64_t val
)
2428 /* NaN are not treated the same way IEEE 754 does */
2429 if (unlikely(isnan(u
.f
)))
2432 return float64_to_uint64_round_to_zero(u
.f
, &env
->spe_status
);
2435 void do_efdcfsi (void)
2437 T0_64
= _do_efdcfsi(T0_64
);
2440 void do_efdcfui (void)
2442 T0_64
= _do_efdcfui(T0_64
);
2445 void do_efdctsi (void)
2447 T0_64
= _do_efdctsi(T0_64
);
2450 void do_efdctui (void)
2452 T0_64
= _do_efdctui(T0_64
);
2455 void do_efdctsiz (void)
2457 T0_64
= _do_efdctsiz(T0_64
);
2460 void do_efdctuiz (void)
2462 T0_64
= _do_efdctuiz(T0_64
);
2465 /* Double precision floating-point conversion to/from fractional */
2466 static always_inline
uint64_t _do_efdcfsf (int64_t val
)
2474 u
.f
= int32_to_float64(val
, &env
->spe_status
);
2475 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2476 u
.f
= float64_div(u
.f
, tmp
, &env
->spe_status
);
2481 static always_inline
uint64_t _do_efdcfuf (uint64_t val
)
2489 u
.f
= uint32_to_float64(val
, &env
->spe_status
);
2490 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2491 u
.f
= float64_div(u
.f
, tmp
, &env
->spe_status
);
2496 static always_inline
int64_t _do_efdctsf (uint64_t val
)
2505 /* NaN are not treated the same way IEEE 754 does */
2506 if (unlikely(isnan(u
.f
)))
2508 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2509 u
.f
= float64_mul(u
.f
, tmp
, &env
->spe_status
);
2511 return float64_to_int32(u
.f
, &env
->spe_status
);
2514 static always_inline
uint64_t _do_efdctuf (uint64_t val
)
2523 /* NaN are not treated the same way IEEE 754 does */
2524 if (unlikely(isnan(u
.f
)))
2526 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2527 u
.f
= float64_mul(u
.f
, tmp
, &env
->spe_status
);
2529 return float64_to_uint32(u
.f
, &env
->spe_status
);
2532 static always_inline
int64_t _do_efdctsfz (uint64_t val
)
2541 /* NaN are not treated the same way IEEE 754 does */
2542 if (unlikely(isnan(u
.f
)))
2544 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2545 u
.f
= float64_mul(u
.f
, tmp
, &env
->spe_status
);
2547 return float64_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
2550 static always_inline
uint64_t _do_efdctufz (uint64_t val
)
2559 /* NaN are not treated the same way IEEE 754 does */
2560 if (unlikely(isnan(u
.f
)))
2562 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2563 u
.f
= float64_mul(u
.f
, tmp
, &env
->spe_status
);
2565 return float64_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
2568 void do_efdcfsf (void)
2570 T0_64
= _do_efdcfsf(T0_64
);
2573 void do_efdcfuf (void)
2575 T0_64
= _do_efdcfuf(T0_64
);
2578 void do_efdctsf (void)
2580 T0_64
= _do_efdctsf(T0_64
);
2583 void do_efdctuf (void)
2585 T0_64
= _do_efdctuf(T0_64
);
2588 void do_efdctsfz (void)
2590 T0_64
= _do_efdctsfz(T0_64
);
2593 void do_efdctufz (void)
2595 T0_64
= _do_efdctufz(T0_64
);
2598 /* Floating point conversion between single and double precision */
2599 static always_inline
uint32_t _do_efscfd (uint64_t val
)
2611 u2
.f
= float64_to_float32(u1
.f
, &env
->spe_status
);
2616 static always_inline
uint64_t _do_efdcfs (uint32_t val
)
2628 u2
.f
= float32_to_float64(u1
.f
, &env
->spe_status
);
2633 void do_efscfd (void)
2635 T0_64
= _do_efscfd(T0_64
);
2638 void do_efdcfs (void)
2640 T0_64
= _do_efdcfs(T0_64
);
2643 /* Single precision fixed-point vector arithmetic */
2659 /* Single-precision floating-point comparisons */
2660 static always_inline
int _do_efscmplt (uint32_t op1
, uint32_t op2
)
2662 /* XXX: TODO: test special values (NaN, infinites, ...) */
2663 return _do_efststlt(op1
, op2
);
2666 static always_inline
int _do_efscmpgt (uint32_t op1
, uint32_t op2
)
2668 /* XXX: TODO: test special values (NaN, infinites, ...) */
2669 return _do_efststgt(op1
, op2
);
2672 static always_inline
int _do_efscmpeq (uint32_t op1
, uint32_t op2
)
2674 /* XXX: TODO: test special values (NaN, infinites, ...) */
2675 return _do_efststeq(op1
, op2
);
2678 void do_efscmplt (void)
2680 T0
= _do_efscmplt(T0_64
, T1_64
);
2683 void do_efscmpgt (void)
2685 T0
= _do_efscmpgt(T0_64
, T1_64
);
2688 void do_efscmpeq (void)
2690 T0
= _do_efscmpeq(T0_64
, T1_64
);
2693 /* Single-precision floating-point vector comparisons */
2695 DO_SPE_CMP(fscmplt
);
2697 DO_SPE_CMP(fscmpgt
);
2699 DO_SPE_CMP(fscmpeq
);
2701 DO_SPE_CMP(fststlt
);
2703 DO_SPE_CMP(fststgt
);
2705 DO_SPE_CMP(fststeq
);
2707 /* Single-precision floating-point vector conversions */
2721 DO_SPE_OP1(fsctsiz
);
2723 DO_SPE_OP1(fsctuiz
);
2728 #endif /* defined(TARGET_PPCEMB) */
2730 /*****************************************************************************/
2731 /* Softmmu support */
2732 #if !defined (CONFIG_USER_ONLY)
2734 #define MMUSUFFIX _mmu
2735 #define GETPC() (__builtin_return_address(0))
2738 #include "softmmu_template.h"
2741 #include "softmmu_template.h"
2744 #include "softmmu_template.h"
2747 #include "softmmu_template.h"
2749 /* try to fill the TLB and return an exception if error. If retaddr is
2750 NULL, it means that the function was called in C code (i.e. not
2751 from generated code or from helper.c) */
2752 /* XXX: fix it to restore all registers */
2753 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
2755 TranslationBlock
*tb
;
2756 CPUState
*saved_env
;
2757 target_phys_addr_t pc
;
2760 /* XXX: hack to restore env in all cases, even if not called from
2763 env
= cpu_single_env
;
2764 ret
= cpu_ppc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
2765 if (unlikely(ret
!= 0)) {
2766 if (likely(retaddr
)) {
2767 /* now we have a real cpu fault */
2768 pc
= (target_phys_addr_t
)(unsigned long)retaddr
;
2769 tb
= tb_find_pc(pc
);
2771 /* the PC is inside the translated code. It means that we have
2772 a virtual CPU fault */
2773 cpu_restore_state(tb
, env
, pc
, NULL
);
2776 do_raise_exception_err(env
->exception_index
, env
->error_code
);
2781 /* Software driven TLBs management */
2782 /* PowerPC 602/603 software TLB load instructions helpers */
2783 void do_load_6xx_tlb (int is_code
)
2785 target_ulong RPN
, CMP
, EPN
;
2788 RPN
= env
->spr
[SPR_RPA
];
2790 CMP
= env
->spr
[SPR_ICMP
];
2791 EPN
= env
->spr
[SPR_IMISS
];
2793 CMP
= env
->spr
[SPR_DCMP
];
2794 EPN
= env
->spr
[SPR_DMISS
];
2796 way
= (env
->spr
[SPR_SRR1
] >> 17) & 1;
2797 #if defined (DEBUG_SOFTWARE_TLB)
2798 if (loglevel
!= 0) {
2799 fprintf(logfile
, "%s: EPN %08lx %08lx PTE0 %08lx PTE1 %08lx way %d\n",
2800 __func__
, (unsigned long)T0
, (unsigned long)EPN
,
2801 (unsigned long)CMP
, (unsigned long)RPN
, way
);
2804 /* Store this TLB */
2805 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2806 way
, is_code
, CMP
, RPN
);
2809 void do_load_74xx_tlb (int is_code
)
2811 target_ulong RPN
, CMP
, EPN
;
2814 RPN
= env
->spr
[SPR_PTELO
];
2815 CMP
= env
->spr
[SPR_PTEHI
];
2816 EPN
= env
->spr
[SPR_TLBMISS
] & ~0x3;
2817 way
= env
->spr
[SPR_TLBMISS
] & 0x3;
2818 #if defined (DEBUG_SOFTWARE_TLB)
2819 if (loglevel
!= 0) {
2820 fprintf(logfile
, "%s: EPN %08lx %08lx PTE0 %08lx PTE1 %08lx way %d\n",
2821 __func__
, (unsigned long)T0
, (unsigned long)EPN
,
2822 (unsigned long)CMP
, (unsigned long)RPN
, way
);
2825 /* Store this TLB */
2826 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2827 way
, is_code
, CMP
, RPN
);
2830 static always_inline target_ulong
booke_tlb_to_page_size (int size
)
2832 return 1024 << (2 * size
);
2835 static always_inline
int booke_page_size_to_tlb (target_ulong page_size
)
2839 switch (page_size
) {
2873 #if defined (TARGET_PPC64)
2874 case 0x000100000000ULL
:
2877 case 0x000400000000ULL
:
2880 case 0x001000000000ULL
:
2883 case 0x004000000000ULL
:
2886 case 0x010000000000ULL
:
2898 /* Helpers for 4xx TLB management */
2899 void do_4xx_tlbre_lo (void)
2905 tlb
= &env
->tlb
[T0
].tlbe
;
2907 if (tlb
->prot
& PAGE_VALID
)
2909 size
= booke_page_size_to_tlb(tlb
->size
);
2910 if (size
< 0 || size
> 0x7)
2913 env
->spr
[SPR_40x_PID
] = tlb
->PID
;
2916 void do_4xx_tlbre_hi (void)
2921 tlb
= &env
->tlb
[T0
].tlbe
;
2923 if (tlb
->prot
& PAGE_EXEC
)
2925 if (tlb
->prot
& PAGE_WRITE
)
2929 void do_4xx_tlbwe_hi (void)
2932 target_ulong page
, end
;
2934 #if defined (DEBUG_SOFTWARE_TLB)
2935 if (loglevel
!= 0) {
2936 fprintf(logfile
, "%s T0 " REGX
" T1 " REGX
"\n", __func__
, T0
, T1
);
2940 tlb
= &env
->tlb
[T0
].tlbe
;
2941 /* Invalidate previous TLB (if it's valid) */
2942 if (tlb
->prot
& PAGE_VALID
) {
2943 end
= tlb
->EPN
+ tlb
->size
;
2944 #if defined (DEBUG_SOFTWARE_TLB)
2945 if (loglevel
!= 0) {
2946 fprintf(logfile
, "%s: invalidate old TLB %d start " ADDRX
2947 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2950 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2951 tlb_flush_page(env
, page
);
2953 tlb
->size
= booke_tlb_to_page_size((T1
>> 7) & 0x7);
2954 /* We cannot handle TLB size < TARGET_PAGE_SIZE.
2955 * If this ever occurs, one should use the ppcemb target instead
2956 * of the ppc or ppc64 one
2958 if ((T1
& 0x40) && tlb
->size
< TARGET_PAGE_SIZE
) {
2959 cpu_abort(env
, "TLB size " TARGET_FMT_lu
" < %u "
2960 "are not supported (%d)\n",
2961 tlb
->size
, TARGET_PAGE_SIZE
, (int)((T1
>> 7) & 0x7));
2963 tlb
->EPN
= T1
& ~(tlb
->size
- 1);
2965 tlb
->prot
|= PAGE_VALID
;
2967 tlb
->prot
&= ~PAGE_VALID
;
2969 /* XXX: TO BE FIXED */
2970 cpu_abort(env
, "Little-endian TLB entries are not supported by now\n");
2972 tlb
->PID
= env
->spr
[SPR_40x_PID
]; /* PID */
2973 tlb
->attr
= T1
& 0xFF;
2974 #if defined (DEBUG_SOFTWARE_TLB)
2975 if (loglevel
!= 0) {
2976 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
2977 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
2978 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
2979 tlb
->prot
& PAGE_READ
? 'r' : '-',
2980 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
2981 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
2982 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
2985 /* Invalidate new TLB (if valid) */
2986 if (tlb
->prot
& PAGE_VALID
) {
2987 end
= tlb
->EPN
+ tlb
->size
;
2988 #if defined (DEBUG_SOFTWARE_TLB)
2989 if (loglevel
!= 0) {
2990 fprintf(logfile
, "%s: invalidate TLB %d start " ADDRX
2991 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2994 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2995 tlb_flush_page(env
, page
);
2999 void do_4xx_tlbwe_lo (void)
3003 #if defined (DEBUG_SOFTWARE_TLB)
3004 if (loglevel
!= 0) {
3005 fprintf(logfile
, "%s T0 " REGX
" T1 " REGX
"\n", __func__
, T0
, T1
);
3009 tlb
= &env
->tlb
[T0
].tlbe
;
3010 tlb
->RPN
= T1
& 0xFFFFFC00;
3011 tlb
->prot
= PAGE_READ
;
3013 tlb
->prot
|= PAGE_EXEC
;
3015 tlb
->prot
|= PAGE_WRITE
;
3016 #if defined (DEBUG_SOFTWARE_TLB)
3017 if (loglevel
!= 0) {
3018 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
3019 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
3020 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
3021 tlb
->prot
& PAGE_READ
? 'r' : '-',
3022 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
3023 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
3024 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
3029 /* PowerPC 440 TLB management */
3030 void do_440_tlbwe (int word
)
3033 target_ulong EPN
, RPN
, size
;
3036 #if defined (DEBUG_SOFTWARE_TLB)
3037 if (loglevel
!= 0) {
3038 fprintf(logfile
, "%s word %d T0 " REGX
" T1 " REGX
"\n",
3039 __func__
, word
, T0
, T1
);
3044 tlb
= &env
->tlb
[T0
].tlbe
;
3047 /* Just here to please gcc */
3049 EPN
= T1
& 0xFFFFFC00;
3050 if ((tlb
->prot
& PAGE_VALID
) && EPN
!= tlb
->EPN
)
3053 size
= booke_tlb_to_page_size((T1
>> 4) & 0xF);
3054 if ((tlb
->prot
& PAGE_VALID
) && tlb
->size
< size
)
3058 tlb
->attr
|= (T1
>> 8) & 1;
3060 tlb
->prot
|= PAGE_VALID
;
3062 if (tlb
->prot
& PAGE_VALID
) {
3063 tlb
->prot
&= ~PAGE_VALID
;
3067 tlb
->PID
= env
->spr
[SPR_440_MMUCR
] & 0x000000FF;
3072 RPN
= T1
& 0xFFFFFC0F;
3073 if ((tlb
->prot
& PAGE_VALID
) && tlb
->RPN
!= RPN
)
3078 tlb
->attr
= (tlb
->attr
& 0x1) | (T1
& 0x0000FF00);
3079 tlb
->prot
= tlb
->prot
& PAGE_VALID
;
3081 tlb
->prot
|= PAGE_READ
<< 4;
3083 tlb
->prot
|= PAGE_WRITE
<< 4;
3085 tlb
->prot
|= PAGE_EXEC
<< 4;
3087 tlb
->prot
|= PAGE_READ
;
3089 tlb
->prot
|= PAGE_WRITE
;
3091 tlb
->prot
|= PAGE_EXEC
;
3096 void do_440_tlbre (int word
)
3102 tlb
= &env
->tlb
[T0
].tlbe
;
3105 /* Just here to please gcc */
3108 size
= booke_page_size_to_tlb(tlb
->size
);
3109 if (size
< 0 || size
> 0xF)
3112 if (tlb
->attr
& 0x1)
3114 if (tlb
->prot
& PAGE_VALID
)
3116 env
->spr
[SPR_440_MMUCR
] &= ~0x000000FF;
3117 env
->spr
[SPR_440_MMUCR
] |= tlb
->PID
;
3123 T0
= tlb
->attr
& ~0x1;
3124 if (tlb
->prot
& (PAGE_READ
<< 4))
3126 if (tlb
->prot
& (PAGE_WRITE
<< 4))
3128 if (tlb
->prot
& (PAGE_EXEC
<< 4))
3130 if (tlb
->prot
& PAGE_READ
)
3132 if (tlb
->prot
& PAGE_WRITE
)
3134 if (tlb
->prot
& PAGE_EXEC
)
3139 #endif /* !CONFIG_USER_ONLY */