2 * PowerPC emulation helpers for qemu.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "host-utils.h"
23 #include "helper_regs.h"
24 #include "op_helper.h"
26 #define MEMSUFFIX _raw
27 #include "op_helper.h"
28 #include "op_helper_mem.h"
29 #if !defined(CONFIG_USER_ONLY)
30 #define MEMSUFFIX _user
31 #include "op_helper.h"
32 #include "op_helper_mem.h"
33 #define MEMSUFFIX _kernel
34 #include "op_helper.h"
35 #include "op_helper_mem.h"
36 #define MEMSUFFIX _hypv
37 #include "op_helper.h"
38 #include "op_helper_mem.h"
42 //#define DEBUG_EXCEPTIONS
43 //#define DEBUG_SOFTWARE_TLB
45 /*****************************************************************************/
46 /* Exceptions processing helpers */
48 void do_raise_exception_err (uint32_t exception
, int error_code
)
51 printf("Raise exception %3x code : %d\n", exception
, error_code
);
53 env
->exception_index
= exception
;
54 env
->error_code
= error_code
;
58 void do_raise_exception (uint32_t exception
)
60 do_raise_exception_err(exception
, 0);
63 /*****************************************************************************/
64 /* Registers load and stores */
65 uint32_t helper_load_cr (void)
67 return (env
->crf
[0] << 28) |
77 void helper_store_cr (target_ulong val
, uint32_t mask
)
81 for (i
= 0, sh
= 7; i
< 8; i
++, sh
--) {
83 env
->crf
[i
] = (val
>> (sh
* 4)) & 0xFUL
;
87 #if defined(TARGET_PPC64)
88 void do_store_pri (int prio
)
90 env
->spr
[SPR_PPR
] &= ~0x001C000000000000ULL
;
91 env
->spr
[SPR_PPR
] |= ((uint64_t)prio
& 0x7) << 50;
95 target_ulong
ppc_load_dump_spr (int sprn
)
98 fprintf(logfile
, "Read SPR %d %03x => " ADDRX
"\n",
99 sprn
, sprn
, env
->spr
[sprn
]);
102 return env
->spr
[sprn
];
105 void ppc_store_dump_spr (int sprn
, target_ulong val
)
108 fprintf(logfile
, "Write SPR %d %03x => " ADDRX
" <= " ADDRX
"\n",
109 sprn
, sprn
, env
->spr
[sprn
], val
);
111 env
->spr
[sprn
] = val
;
114 /*****************************************************************************/
115 /* Fixed point operations helpers */
116 #if defined(TARGET_PPC64)
118 /* multiply high word */
119 uint64_t helper_mulhd (uint64_t arg1
, uint64_t arg2
)
123 muls64(&tl
, &th
, arg1
, arg2
);
127 /* multiply high word unsigned */
128 uint64_t helper_mulhdu (uint64_t arg1
, uint64_t arg2
)
132 mulu64(&tl
, &th
, arg1
, arg2
);
136 uint64_t helper_mulldo (uint64_t arg1
, uint64_t arg2
)
141 muls64(&tl
, (uint64_t *)&th
, arg1
, arg2
);
142 /* If th != 0 && th != -1, then we had an overflow */
143 if (likely((uint64_t)(th
+ 1) <= 1)) {
144 env
->xer
&= ~(1 << XER_OV
);
146 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
152 target_ulong
helper_cntlzw (target_ulong t
)
157 #if defined(TARGET_PPC64)
158 target_ulong
helper_cntlzd (target_ulong t
)
164 /* shift right arithmetic helper */
165 target_ulong
helper_sraw (target_ulong value
, target_ulong shift
)
169 if (likely(!(shift
& 0x20))) {
170 if (likely((uint32_t)shift
!= 0)) {
172 ret
= (int32_t)value
>> shift
;
173 if (likely(ret
>= 0 || (value
& ((1 << shift
) - 1)) == 0)) {
174 env
->xer
&= ~(1 << XER_CA
);
176 env
->xer
|= (1 << XER_CA
);
179 ret
= (int32_t)value
;
180 env
->xer
&= ~(1 << XER_CA
);
183 ret
= (int32_t)value
>> 31;
185 env
->xer
|= (1 << XER_CA
);
187 env
->xer
&= ~(1 << XER_CA
);
190 return (target_long
)ret
;
193 #if defined(TARGET_PPC64)
194 target_ulong
helper_srad (target_ulong value
, target_ulong shift
)
198 if (likely(!(shift
& 0x40))) {
199 if (likely((uint64_t)shift
!= 0)) {
201 ret
= (int64_t)value
>> shift
;
202 if (likely(ret
>= 0 || (value
& ((1 << shift
) - 1)) == 0)) {
203 env
->xer
&= ~(1 << XER_CA
);
205 env
->xer
|= (1 << XER_CA
);
208 ret
= (int64_t)value
;
209 env
->xer
&= ~(1 << XER_CA
);
212 ret
= (int64_t)value
>> 63;
214 env
->xer
|= (1 << XER_CA
);
216 env
->xer
&= ~(1 << XER_CA
);
223 target_ulong
helper_popcntb (target_ulong val
)
225 val
= (val
& 0x55555555) + ((val
>> 1) & 0x55555555);
226 val
= (val
& 0x33333333) + ((val
>> 2) & 0x33333333);
227 val
= (val
& 0x0f0f0f0f) + ((val
>> 4) & 0x0f0f0f0f);
231 #if defined(TARGET_PPC64)
232 target_ulong
helper_popcntb_64 (target_ulong val
)
234 val
= (val
& 0x5555555555555555ULL
) + ((val
>> 1) & 0x5555555555555555ULL
);
235 val
= (val
& 0x3333333333333333ULL
) + ((val
>> 2) & 0x3333333333333333ULL
);
236 val
= (val
& 0x0f0f0f0f0f0f0f0fULL
) + ((val
>> 4) & 0x0f0f0f0f0f0f0f0fULL
);
241 /*****************************************************************************/
242 /* Floating point operations helpers */
243 static always_inline
int fpisneg (float64 d
)
249 return u
.ll
>> 63 != 0;
252 static always_inline
int isden (float64 d
)
258 return ((u
.ll
>> 52) & 0x7FF) == 0;
261 static always_inline
int iszero (float64 d
)
267 return (u
.ll
& ~0x8000000000000000ULL
) == 0;
270 static always_inline
int isinfinity (float64 d
)
276 return ((u
.ll
>> 52) & 0x7FF) == 0x7FF &&
277 (u
.ll
& 0x000FFFFFFFFFFFFFULL
) == 0;
280 #ifdef CONFIG_SOFTFLOAT
281 static always_inline
int isfinite (float64 d
)
287 return (((u
.ll
>> 52) & 0x7FF) != 0x7FF);
290 static always_inline
int isnormal (float64 d
)
296 uint32_t exp
= (u
.ll
>> 52) & 0x7FF;
297 return ((0 < exp
) && (exp
< 0x7FF));
301 void do_compute_fprf (int set_fprf
)
305 isneg
= fpisneg(FT0
);
306 if (unlikely(float64_is_nan(FT0
))) {
307 if (float64_is_signaling_nan(FT0
)) {
308 /* Signaling NaN: flags are undefined */
314 } else if (unlikely(isinfinity(FT0
))) {
329 /* Denormalized numbers */
332 /* Normalized numbers */
343 /* We update FPSCR_FPRF */
344 env
->fpscr
&= ~(0x1F << FPSCR_FPRF
);
345 env
->fpscr
|= T0
<< FPSCR_FPRF
;
347 /* We just need fpcc to update Rc1 */
351 /* Floating-point invalid operations exception */
352 static always_inline
void fload_invalid_op_excp (int op
)
357 if (op
& POWERPC_EXCP_FP_VXSNAN
) {
358 /* Operation on signaling NaN */
359 env
->fpscr
|= 1 << FPSCR_VXSNAN
;
361 if (op
& POWERPC_EXCP_FP_VXSOFT
) {
362 /* Software-defined condition */
363 env
->fpscr
|= 1 << FPSCR_VXSOFT
;
365 switch (op
& ~(POWERPC_EXCP_FP_VXSOFT
| POWERPC_EXCP_FP_VXSNAN
)) {
366 case POWERPC_EXCP_FP_VXISI
:
367 /* Magnitude subtraction of infinities */
368 env
->fpscr
|= 1 << FPSCR_VXISI
;
370 case POWERPC_EXCP_FP_VXIDI
:
371 /* Division of infinity by infinity */
372 env
->fpscr
|= 1 << FPSCR_VXIDI
;
374 case POWERPC_EXCP_FP_VXZDZ
:
375 /* Division of zero by zero */
376 env
->fpscr
|= 1 << FPSCR_VXZDZ
;
378 case POWERPC_EXCP_FP_VXIMZ
:
379 /* Multiplication of zero by infinity */
380 env
->fpscr
|= 1 << FPSCR_VXIMZ
;
382 case POWERPC_EXCP_FP_VXVC
:
383 /* Ordered comparison of NaN */
384 env
->fpscr
|= 1 << FPSCR_VXVC
;
385 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
386 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
387 /* We must update the target FPR before raising the exception */
389 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
390 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_VXVC
;
391 /* Update the floating-point enabled exception summary */
392 env
->fpscr
|= 1 << FPSCR_FEX
;
393 /* Exception is differed */
397 case POWERPC_EXCP_FP_VXSQRT
:
398 /* Square root of a negative number */
399 env
->fpscr
|= 1 << FPSCR_VXSQRT
;
401 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
403 /* Set the result to quiet NaN */
405 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
406 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
409 case POWERPC_EXCP_FP_VXCVI
:
410 /* Invalid conversion */
411 env
->fpscr
|= 1 << FPSCR_VXCVI
;
412 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
414 /* Set the result to quiet NaN */
416 env
->fpscr
&= ~(0xF << FPSCR_FPCC
);
417 env
->fpscr
|= 0x11 << FPSCR_FPCC
;
421 /* Update the floating-point invalid operation summary */
422 env
->fpscr
|= 1 << FPSCR_VX
;
423 /* Update the floating-point exception summary */
424 env
->fpscr
|= 1 << FPSCR_FX
;
426 /* Update the floating-point enabled exception summary */
427 env
->fpscr
|= 1 << FPSCR_FEX
;
428 if (msr_fe0
!= 0 || msr_fe1
!= 0)
429 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_FP
| op
);
433 static always_inline
void float_zero_divide_excp (void)
437 env
->fpscr
|= 1 << FPSCR_ZX
;
438 env
->fpscr
&= ~((1 << FPSCR_FR
) | (1 << FPSCR_FI
));
439 /* Update the floating-point exception summary */
440 env
->fpscr
|= 1 << FPSCR_FX
;
442 /* Update the floating-point enabled exception summary */
443 env
->fpscr
|= 1 << FPSCR_FEX
;
444 if (msr_fe0
!= 0 || msr_fe1
!= 0) {
445 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
446 POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
);
449 /* Set the result to infinity */
452 u0
.ll
= ((u0
.ll
^ u1
.ll
) & 0x8000000000000000ULL
);
453 u0
.ll
|= 0x7FFULL
<< 52;
458 static always_inline
void float_overflow_excp (void)
460 env
->fpscr
|= 1 << FPSCR_OX
;
461 /* Update the floating-point exception summary */
462 env
->fpscr
|= 1 << FPSCR_FX
;
464 /* XXX: should adjust the result */
465 /* Update the floating-point enabled exception summary */
466 env
->fpscr
|= 1 << FPSCR_FEX
;
467 /* We must update the target FPR before raising the exception */
468 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
469 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
471 env
->fpscr
|= 1 << FPSCR_XX
;
472 env
->fpscr
|= 1 << FPSCR_FI
;
476 static always_inline
void float_underflow_excp (void)
478 env
->fpscr
|= 1 << FPSCR_UX
;
479 /* Update the floating-point exception summary */
480 env
->fpscr
|= 1 << FPSCR_FX
;
482 /* XXX: should adjust the result */
483 /* Update the floating-point enabled exception summary */
484 env
->fpscr
|= 1 << FPSCR_FEX
;
485 /* We must update the target FPR before raising the exception */
486 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
487 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
491 static always_inline
void float_inexact_excp (void)
493 env
->fpscr
|= 1 << FPSCR_XX
;
494 /* Update the floating-point exception summary */
495 env
->fpscr
|= 1 << FPSCR_FX
;
497 /* Update the floating-point enabled exception summary */
498 env
->fpscr
|= 1 << FPSCR_FEX
;
499 /* We must update the target FPR before raising the exception */
500 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
501 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
505 static always_inline
void fpscr_set_rounding_mode (void)
509 /* Set rounding mode */
512 /* Best approximation (round to nearest) */
513 rnd_type
= float_round_nearest_even
;
516 /* Smaller magnitude (round toward zero) */
517 rnd_type
= float_round_to_zero
;
520 /* Round toward +infinite */
521 rnd_type
= float_round_up
;
525 /* Round toward -infinite */
526 rnd_type
= float_round_down
;
529 set_float_rounding_mode(rnd_type
, &env
->fp_status
);
532 void do_fpscr_setbit (int bit
)
536 prev
= (env
->fpscr
>> bit
) & 1;
537 env
->fpscr
|= 1 << bit
;
541 env
->fpscr
|= 1 << FPSCR_FX
;
545 env
->fpscr
|= 1 << FPSCR_FX
;
550 env
->fpscr
|= 1 << FPSCR_FX
;
555 env
->fpscr
|= 1 << FPSCR_FX
;
560 env
->fpscr
|= 1 << FPSCR_FX
;
573 env
->fpscr
|= 1 << FPSCR_VX
;
574 env
->fpscr
|= 1 << FPSCR_FX
;
581 env
->error_code
= POWERPC_EXCP_FP
;
583 env
->error_code
|= POWERPC_EXCP_FP_VXSNAN
;
585 env
->error_code
|= POWERPC_EXCP_FP_VXISI
;
587 env
->error_code
|= POWERPC_EXCP_FP_VXIDI
;
589 env
->error_code
|= POWERPC_EXCP_FP_VXZDZ
;
591 env
->error_code
|= POWERPC_EXCP_FP_VXIMZ
;
593 env
->error_code
|= POWERPC_EXCP_FP_VXVC
;
595 env
->error_code
|= POWERPC_EXCP_FP_VXSOFT
;
597 env
->error_code
|= POWERPC_EXCP_FP_VXSQRT
;
599 env
->error_code
|= POWERPC_EXCP_FP_VXCVI
;
606 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_OX
;
613 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_UX
;
620 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_ZX
;
627 env
->error_code
= POWERPC_EXCP_FP
| POWERPC_EXCP_FP_XX
;
633 fpscr_set_rounding_mode();
638 /* Update the floating-point enabled exception summary */
639 env
->fpscr
|= 1 << FPSCR_FEX
;
640 /* We have to update Rc1 before raising the exception */
641 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
647 #if defined(WORDS_BIGENDIAN)
654 void do_store_fpscr (uint32_t mask
)
657 * We use only the 32 LSB of the incoming fpr
667 new |= prev
& 0x90000000;
668 for (i
= 0; i
< 7; i
++) {
669 if (mask
& (1 << i
)) {
670 env
->fpscr
&= ~(0xF << (4 * i
));
671 env
->fpscr
|= new & (0xF << (4 * i
));
674 /* Update VX and FEX */
676 env
->fpscr
|= 1 << FPSCR_VX
;
678 env
->fpscr
&= ~(1 << FPSCR_VX
);
679 if ((fpscr_ex
& fpscr_eex
) != 0) {
680 env
->fpscr
|= 1 << FPSCR_FEX
;
681 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
682 /* XXX: we should compute it properly */
683 env
->error_code
= POWERPC_EXCP_FP
;
686 env
->fpscr
&= ~(1 << FPSCR_FEX
);
687 fpscr_set_rounding_mode();
692 #ifdef CONFIG_SOFTFLOAT
693 void do_float_check_status (void)
695 if (env
->exception_index
== POWERPC_EXCP_PROGRAM
&&
696 (env
->error_code
& POWERPC_EXCP_FP
)) {
697 /* Differred floating-point exception after target FPR update */
698 if (msr_fe0
!= 0 || msr_fe1
!= 0)
699 do_raise_exception_err(env
->exception_index
, env
->error_code
);
700 } else if (env
->fp_status
.float_exception_flags
& float_flag_overflow
) {
701 float_overflow_excp();
702 } else if (env
->fp_status
.float_exception_flags
& float_flag_underflow
) {
703 float_underflow_excp();
704 } else if (env
->fp_status
.float_exception_flags
& float_flag_inexact
) {
705 float_inexact_excp();
710 #if USE_PRECISE_EMULATION
713 if (unlikely(float64_is_signaling_nan(FT0
) ||
714 float64_is_signaling_nan(FT1
))) {
716 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
717 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
718 fpisneg(FT0
) == fpisneg(FT1
))) {
719 FT0
= float64_add(FT0
, FT1
, &env
->fp_status
);
721 /* Magnitude subtraction of infinities */
722 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
728 if (unlikely(float64_is_signaling_nan(FT0
) ||
729 float64_is_signaling_nan(FT1
))) {
730 /* sNaN subtraction */
731 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
732 } else if (likely(isfinite(FT0
) || isfinite(FT1
) ||
733 fpisneg(FT0
) != fpisneg(FT1
))) {
734 FT0
= float64_sub(FT0
, FT1
, &env
->fp_status
);
736 /* Magnitude subtraction of infinities */
737 fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI
);
743 if (unlikely(float64_is_signaling_nan(FT0
) ||
744 float64_is_signaling_nan(FT1
))) {
745 /* sNaN multiplication */
746 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
747 } else if (unlikely((isinfinity(FT0
) && iszero(FT1
)) ||
748 (iszero(FT0
) && isinfinity(FT1
)))) {
749 /* Multiplication of zero by infinity */
750 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIMZ
);
752 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
758 if (unlikely(float64_is_signaling_nan(FT0
) ||
759 float64_is_signaling_nan(FT1
))) {
761 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
762 } else if (unlikely(isinfinity(FT0
) && isinfinity(FT1
))) {
763 /* Division of infinity by infinity */
764 fload_invalid_op_excp(POWERPC_EXCP_FP_VXIDI
);
765 } else if (unlikely(iszero(FT1
))) {
767 /* Division of zero by zero */
768 fload_invalid_op_excp(POWERPC_EXCP_FP_VXZDZ
);
770 /* Division by zero */
771 float_zero_divide_excp();
774 FT0
= float64_div(FT0
, FT1
, &env
->fp_status
);
777 #endif /* USE_PRECISE_EMULATION */
783 if (unlikely(float64_is_signaling_nan(FT0
))) {
784 /* sNaN conversion */
785 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
786 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
787 /* qNan / infinity conversion */
788 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
790 p
.ll
= float64_to_int32(FT0
, &env
->fp_status
);
791 #if USE_PRECISE_EMULATION
792 /* XXX: higher bits are not supposed to be significant.
793 * to make tests easier, return the same as a real PowerPC 750
795 p
.ll
|= 0xFFF80000ULL
<< 32;
801 void do_fctiwz (void)
805 if (unlikely(float64_is_signaling_nan(FT0
))) {
806 /* sNaN conversion */
807 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
808 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
809 /* qNan / infinity conversion */
810 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
812 p
.ll
= float64_to_int32_round_to_zero(FT0
, &env
->fp_status
);
813 #if USE_PRECISE_EMULATION
814 /* XXX: higher bits are not supposed to be significant.
815 * to make tests easier, return the same as a real PowerPC 750
817 p
.ll
|= 0xFFF80000ULL
<< 32;
823 #if defined(TARGET_PPC64)
829 FT0
= int64_to_float64(p
.ll
, &env
->fp_status
);
836 if (unlikely(float64_is_signaling_nan(FT0
))) {
837 /* sNaN conversion */
838 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
839 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
840 /* qNan / infinity conversion */
841 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
843 p
.ll
= float64_to_int64(FT0
, &env
->fp_status
);
848 void do_fctidz (void)
852 if (unlikely(float64_is_signaling_nan(FT0
))) {
853 /* sNaN conversion */
854 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
855 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
856 /* qNan / infinity conversion */
857 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
859 p
.ll
= float64_to_int64_round_to_zero(FT0
, &env
->fp_status
);
866 static always_inline
void do_fri (int rounding_mode
)
868 if (unlikely(float64_is_signaling_nan(FT0
))) {
870 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
| POWERPC_EXCP_FP_VXCVI
);
871 } else if (unlikely(float64_is_nan(FT0
) || isinfinity(FT0
))) {
872 /* qNan / infinity round */
873 fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI
);
875 set_float_rounding_mode(rounding_mode
, &env
->fp_status
);
876 FT0
= float64_round_to_int(FT0
, &env
->fp_status
);
877 /* Restore rounding mode from FPSCR */
878 fpscr_set_rounding_mode();
884 do_fri(float_round_nearest_even
);
889 do_fri(float_round_to_zero
);
894 do_fri(float_round_up
);
899 do_fri(float_round_down
);
902 #if USE_PRECISE_EMULATION
905 if (unlikely(float64_is_signaling_nan(FT0
) ||
906 float64_is_signaling_nan(FT1
) ||
907 float64_is_signaling_nan(FT2
))) {
909 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
912 /* This is the way the PowerPC specification defines it */
913 float128 ft0_128
, ft1_128
;
915 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
916 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
917 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
918 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
919 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
920 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
922 /* This is OK on x86 hosts */
923 FT0
= (FT0
* FT1
) + FT2
;
930 if (unlikely(float64_is_signaling_nan(FT0
) ||
931 float64_is_signaling_nan(FT1
) ||
932 float64_is_signaling_nan(FT2
))) {
934 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
937 /* This is the way the PowerPC specification defines it */
938 float128 ft0_128
, ft1_128
;
940 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
941 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
942 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
943 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
944 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
945 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
947 /* This is OK on x86 hosts */
948 FT0
= (FT0
* FT1
) - FT2
;
952 #endif /* USE_PRECISE_EMULATION */
954 void do_fnmadd (void)
956 if (unlikely(float64_is_signaling_nan(FT0
) ||
957 float64_is_signaling_nan(FT1
) ||
958 float64_is_signaling_nan(FT2
))) {
960 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
962 #if USE_PRECISE_EMULATION
964 /* This is the way the PowerPC specification defines it */
965 float128 ft0_128
, ft1_128
;
967 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
968 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
969 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
970 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
971 ft0_128
= float128_add(ft0_128
, ft1_128
, &env
->fp_status
);
972 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
974 /* This is OK on x86 hosts */
975 FT0
= (FT0
* FT1
) + FT2
;
978 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
979 FT0
= float64_add(FT0
, FT2
, &env
->fp_status
);
981 if (likely(!isnan(FT0
)))
982 FT0
= float64_chs(FT0
);
986 void do_fnmsub (void)
988 if (unlikely(float64_is_signaling_nan(FT0
) ||
989 float64_is_signaling_nan(FT1
) ||
990 float64_is_signaling_nan(FT2
))) {
992 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
994 #if USE_PRECISE_EMULATION
996 /* This is the way the PowerPC specification defines it */
997 float128 ft0_128
, ft1_128
;
999 ft0_128
= float64_to_float128(FT0
, &env
->fp_status
);
1000 ft1_128
= float64_to_float128(FT1
, &env
->fp_status
);
1001 ft0_128
= float128_mul(ft0_128
, ft1_128
, &env
->fp_status
);
1002 ft1_128
= float64_to_float128(FT2
, &env
->fp_status
);
1003 ft0_128
= float128_sub(ft0_128
, ft1_128
, &env
->fp_status
);
1004 FT0
= float128_to_float64(ft0_128
, &env
->fp_status
);
1006 /* This is OK on x86 hosts */
1007 FT0
= (FT0
* FT1
) - FT2
;
1010 FT0
= float64_mul(FT0
, FT1
, &env
->fp_status
);
1011 FT0
= float64_sub(FT0
, FT2
, &env
->fp_status
);
1013 if (likely(!isnan(FT0
)))
1014 FT0
= float64_chs(FT0
);
1018 #if USE_PRECISE_EMULATION
1021 if (unlikely(float64_is_signaling_nan(FT0
))) {
1022 /* sNaN square root */
1023 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1025 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1028 #endif /* USE_PRECISE_EMULATION */
1030 void do_fsqrt (void)
1032 if (unlikely(float64_is_signaling_nan(FT0
))) {
1033 /* sNaN square root */
1034 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1035 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1036 /* Square root of a negative nonzero number */
1037 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1039 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1047 if (unlikely(float64_is_signaling_nan(FT0
))) {
1048 /* sNaN reciprocal */
1049 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1050 } else if (unlikely(iszero(FT0
))) {
1051 /* Zero reciprocal */
1052 float_zero_divide_excp();
1053 } else if (likely(isnormal(FT0
))) {
1054 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1057 if (p
.ll
== 0x8000000000000000ULL
) {
1058 p
.ll
= 0xFFF0000000000000ULL
;
1059 } else if (p
.ll
== 0x0000000000000000ULL
) {
1060 p
.ll
= 0x7FF0000000000000ULL
;
1061 } else if (isnan(FT0
)) {
1062 p
.ll
= 0x7FF8000000000000ULL
;
1063 } else if (fpisneg(FT0
)) {
1064 p
.ll
= 0x8000000000000000ULL
;
1066 p
.ll
= 0x0000000000000000ULL
;
1076 if (unlikely(float64_is_signaling_nan(FT0
))) {
1077 /* sNaN reciprocal */
1078 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1079 } else if (unlikely(iszero(FT0
))) {
1080 /* Zero reciprocal */
1081 float_zero_divide_excp();
1082 } else if (likely(isnormal(FT0
))) {
1083 #if USE_PRECISE_EMULATION
1084 FT0
= float64_div(1.0, FT0
, &env
->fp_status
);
1085 FT0
= float64_to_float32(FT0
, &env
->fp_status
);
1087 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1091 if (p
.ll
== 0x8000000000000000ULL
) {
1092 p
.ll
= 0xFFF0000000000000ULL
;
1093 } else if (p
.ll
== 0x0000000000000000ULL
) {
1094 p
.ll
= 0x7FF0000000000000ULL
;
1095 } else if (isnan(FT0
)) {
1096 p
.ll
= 0x7FF8000000000000ULL
;
1097 } else if (fpisneg(FT0
)) {
1098 p
.ll
= 0x8000000000000000ULL
;
1100 p
.ll
= 0x0000000000000000ULL
;
1106 void do_frsqrte (void)
1110 if (unlikely(float64_is_signaling_nan(FT0
))) {
1111 /* sNaN reciprocal square root */
1112 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1113 } else if (unlikely(fpisneg(FT0
) && !iszero(FT0
))) {
1114 /* Reciprocal square root of a negative nonzero number */
1115 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT
);
1116 } else if (likely(isnormal(FT0
))) {
1117 FT0
= float64_sqrt(FT0
, &env
->fp_status
);
1118 FT0
= float32_div(1.0, FT0
, &env
->fp_status
);
1121 if (p
.ll
== 0x8000000000000000ULL
) {
1122 p
.ll
= 0xFFF0000000000000ULL
;
1123 } else if (p
.ll
== 0x0000000000000000ULL
) {
1124 p
.ll
= 0x7FF0000000000000ULL
;
1125 } else if (isnan(FT0
)) {
1126 p
.ll
|= 0x000FFFFFFFFFFFFFULL
;
1127 } else if (fpisneg(FT0
)) {
1128 p
.ll
= 0x7FF8000000000000ULL
;
1130 p
.ll
= 0x0000000000000000ULL
;
1138 if (!fpisneg(FT0
) || iszero(FT0
))
1144 uint32_t helper_fcmpu (void)
1148 if (unlikely(float64_is_signaling_nan(FT0
) ||
1149 float64_is_signaling_nan(FT1
))) {
1150 /* sNaN comparison */
1151 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
);
1153 if (float64_lt(FT0
, FT1
, &env
->fp_status
)) {
1155 } else if (!float64_le(FT0
, FT1
, &env
->fp_status
)) {
1161 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1162 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1166 uint32_t helper_fcmpo (void)
1170 if (unlikely(float64_is_nan(FT0
) ||
1171 float64_is_nan(FT1
))) {
1172 if (float64_is_signaling_nan(FT0
) ||
1173 float64_is_signaling_nan(FT1
)) {
1174 /* sNaN comparison */
1175 fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN
|
1176 POWERPC_EXCP_FP_VXVC
);
1178 /* qNaN comparison */
1179 fload_invalid_op_excp(POWERPC_EXCP_FP_VXVC
);
1182 if (float64_lt(FT0
, FT1
, &env
->fp_status
)) {
1184 } else if (!float64_le(FT0
, FT1
, &env
->fp_status
)) {
1190 env
->fpscr
&= ~(0x0F << FPSCR_FPRF
);
1191 env
->fpscr
|= ret
<< FPSCR_FPRF
;
1195 #if !defined (CONFIG_USER_ONLY)
1196 void cpu_dump_rfi (target_ulong RA
, target_ulong msr
);
1198 void do_store_msr (void)
1200 T0
= hreg_store_msr(env
, T0
, 0);
1202 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1203 do_raise_exception(T0
);
1207 static always_inline
void __do_rfi (target_ulong nip
, target_ulong msr
,
1208 target_ulong msrm
, int keep_msrh
)
1210 #if defined(TARGET_PPC64)
1211 if (msr
& (1ULL << MSR_SF
)) {
1212 nip
= (uint64_t)nip
;
1213 msr
&= (uint64_t)msrm
;
1215 nip
= (uint32_t)nip
;
1216 msr
= (uint32_t)(msr
& msrm
);
1218 msr
|= env
->msr
& ~((uint64_t)0xFFFFFFFF);
1221 nip
= (uint32_t)nip
;
1222 msr
&= (uint32_t)msrm
;
1224 /* XXX: beware: this is false if VLE is supported */
1225 env
->nip
= nip
& ~((target_ulong
)0x00000003);
1226 hreg_store_msr(env
, msr
, 1);
1227 #if defined (DEBUG_OP)
1228 cpu_dump_rfi(env
->nip
, env
->msr
);
1230 /* No need to raise an exception here,
1231 * as rfi is always the last insn of a TB
1233 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1238 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1239 ~((target_ulong
)0xFFFF0000), 1);
1242 #if defined(TARGET_PPC64)
1245 __do_rfi(env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
1246 ~((target_ulong
)0xFFFF0000), 0);
1249 void do_hrfid (void)
1251 __do_rfi(env
->spr
[SPR_HSRR0
], env
->spr
[SPR_HSRR1
],
1252 ~((target_ulong
)0xFFFF0000), 0);
1257 void do_tw (int flags
)
1259 if (!likely(!(((int32_t)T0
< (int32_t)T1
&& (flags
& 0x10)) ||
1260 ((int32_t)T0
> (int32_t)T1
&& (flags
& 0x08)) ||
1261 ((int32_t)T0
== (int32_t)T1
&& (flags
& 0x04)) ||
1262 ((uint32_t)T0
< (uint32_t)T1
&& (flags
& 0x02)) ||
1263 ((uint32_t)T0
> (uint32_t)T1
&& (flags
& 0x01))))) {
1264 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1268 #if defined(TARGET_PPC64)
1269 void do_td (int flags
)
1271 if (!likely(!(((int64_t)T0
< (int64_t)T1
&& (flags
& 0x10)) ||
1272 ((int64_t)T0
> (int64_t)T1
&& (flags
& 0x08)) ||
1273 ((int64_t)T0
== (int64_t)T1
&& (flags
& 0x04)) ||
1274 ((uint64_t)T0
< (uint64_t)T1
&& (flags
& 0x02)) ||
1275 ((uint64_t)T0
> (uint64_t)T1
&& (flags
& 0x01)))))
1276 do_raise_exception_err(POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
1280 /*****************************************************************************/
1281 /* PowerPC 601 specific instructions (POWER bridge) */
1282 void do_POWER_abso (void)
1284 if ((int32_t)T0
== INT32_MIN
) {
1286 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1287 } else if ((int32_t)T0
< 0) {
1289 env
->xer
&= ~(1 << XER_OV
);
1291 env
->xer
&= ~(1 << XER_OV
);
1295 void do_POWER_clcs (void)
1299 /* Instruction cache line size */
1300 T0
= env
->icache_line_size
;
1303 /* Data cache line size */
1304 T0
= env
->dcache_line_size
;
1307 /* Minimum cache line size */
1308 T0
= env
->icache_line_size
< env
->dcache_line_size
?
1309 env
->icache_line_size
: env
->dcache_line_size
;
1312 /* Maximum cache line size */
1313 T0
= env
->icache_line_size
> env
->dcache_line_size
?
1314 env
->icache_line_size
: env
->dcache_line_size
;
1322 void do_POWER_div (void)
1326 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1328 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1329 env
->spr
[SPR_MQ
] = 0;
1331 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1332 env
->spr
[SPR_MQ
] = tmp
% T1
;
1333 T0
= tmp
/ (int32_t)T1
;
1337 void do_POWER_divo (void)
1341 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1343 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1344 env
->spr
[SPR_MQ
] = 0;
1345 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1347 tmp
= ((uint64_t)T0
<< 32) | env
->spr
[SPR_MQ
];
1348 env
->spr
[SPR_MQ
] = tmp
% T1
;
1350 if (tmp
> (int64_t)INT32_MAX
|| tmp
< (int64_t)INT32_MIN
) {
1351 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1353 env
->xer
&= ~(1 << XER_OV
);
1359 void do_POWER_divs (void)
1361 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1363 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1364 env
->spr
[SPR_MQ
] = 0;
1366 env
->spr
[SPR_MQ
] = T0
% T1
;
1367 T0
= (int32_t)T0
/ (int32_t)T1
;
1371 void do_POWER_divso (void)
1373 if (((int32_t)T0
== INT32_MIN
&& (int32_t)T1
== (int32_t)-1) ||
1375 T0
= UINT32_MAX
* ((uint32_t)T0
>> 31);
1376 env
->spr
[SPR_MQ
] = 0;
1377 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1379 T0
= (int32_t)T0
/ (int32_t)T1
;
1380 env
->spr
[SPR_MQ
] = (int32_t)T0
% (int32_t)T1
;
1381 env
->xer
&= ~(1 << XER_OV
);
1385 void do_POWER_dozo (void)
1387 if ((int32_t)T1
> (int32_t)T0
) {
1390 if (((uint32_t)(~T2
) ^ (uint32_t)T1
^ UINT32_MAX
) &
1391 ((uint32_t)(~T2
) ^ (uint32_t)T0
) & (1UL << 31)) {
1392 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1394 env
->xer
&= ~(1 << XER_OV
);
1398 env
->xer
&= ~(1 << XER_OV
);
1402 void do_POWER_maskg (void)
1406 if ((uint32_t)T0
== (uint32_t)(T1
+ 1)) {
1409 ret
= (UINT32_MAX
>> ((uint32_t)T0
)) ^
1410 ((UINT32_MAX
>> ((uint32_t)T1
)) >> 1);
1411 if ((uint32_t)T0
> (uint32_t)T1
)
1417 void do_POWER_mulo (void)
1421 tmp
= (uint64_t)T0
* (uint64_t)T1
;
1422 env
->spr
[SPR_MQ
] = tmp
>> 32;
1424 if (tmp
>> 32 != ((uint64_t)T0
>> 16) * ((uint64_t)T1
>> 16)) {
1425 env
->xer
|= (1 << XER_OV
) | (1 << XER_SO
);
1427 env
->xer
&= ~(1 << XER_OV
);
1431 #if !defined (CONFIG_USER_ONLY)
1432 void do_POWER_rac (void)
1437 /* We don't have to generate many instances of this instruction,
1438 * as rac is supervisor only.
1440 /* XXX: FIX THIS: Pretend we have no BAT */
1441 nb_BATs
= env
->nb_BATs
;
1443 if (get_physical_address(env
, &ctx
, T0
, 0, ACCESS_INT
) == 0)
1445 env
->nb_BATs
= nb_BATs
;
1448 void do_POWER_rfsvc (void)
1450 __do_rfi(env
->lr
, env
->ctr
, 0x0000FFFF, 0);
1453 void do_store_hid0_601 (void)
1457 hid0
= env
->spr
[SPR_HID0
];
1458 if ((T0
^ hid0
) & 0x00000008) {
1459 /* Change current endianness */
1460 env
->hflags
&= ~(1 << MSR_LE
);
1461 env
->hflags_nmsr
&= ~(1 << MSR_LE
);
1462 env
->hflags_nmsr
|= (1 << MSR_LE
) & (((T0
>> 3) & 1) << MSR_LE
);
1463 env
->hflags
|= env
->hflags_nmsr
;
1464 if (loglevel
!= 0) {
1465 fprintf(logfile
, "%s: set endianness to %c => " ADDRX
"\n",
1466 __func__
, T0
& 0x8 ? 'l' : 'b', env
->hflags
);
1469 env
->spr
[SPR_HID0
] = T0
;
1473 /*****************************************************************************/
1474 /* 602 specific instructions */
1475 /* mfrom is the most crazy instruction ever seen, imho ! */
1476 /* Real implementation uses a ROM table. Do the same */
1477 #define USE_MFROM_ROM_TABLE
1478 void do_op_602_mfrom (void)
1480 if (likely(T0
< 602)) {
1481 #if defined(USE_MFROM_ROM_TABLE)
1482 #include "mfrom_table.c"
1483 T0
= mfrom_ROM_table
[T0
];
1486 /* Extremly decomposed:
1488 * T0 = 256 * log10(10 + 1.0) + 0.5
1491 d
= float64_div(d
, 256, &env
->fp_status
);
1493 d
= exp10(d
); // XXX: use float emulation function
1494 d
= float64_add(d
, 1.0, &env
->fp_status
);
1495 d
= log10(d
); // XXX: use float emulation function
1496 d
= float64_mul(d
, 256, &env
->fp_status
);
1497 d
= float64_add(d
, 0.5, &env
->fp_status
);
1498 T0
= float64_round_to_int(d
, &env
->fp_status
);
1505 /*****************************************************************************/
1506 /* Embedded PowerPC specific helpers */
1508 /* XXX: to be improved to check access rights when in user-mode */
1509 void do_load_dcr (void)
1513 if (unlikely(env
->dcr_env
== NULL
)) {
1514 if (loglevel
!= 0) {
1515 fprintf(logfile
, "No DCR environment\n");
1517 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1518 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1519 } else if (unlikely(ppc_dcr_read(env
->dcr_env
, T0
, &val
) != 0)) {
1520 if (loglevel
!= 0) {
1521 fprintf(logfile
, "DCR read error %d %03x\n", (int)T0
, (int)T0
);
1523 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1524 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1530 void do_store_dcr (void)
1532 if (unlikely(env
->dcr_env
== NULL
)) {
1533 if (loglevel
!= 0) {
1534 fprintf(logfile
, "No DCR environment\n");
1536 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1537 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
);
1538 } else if (unlikely(ppc_dcr_write(env
->dcr_env
, T0
, T1
) != 0)) {
1539 if (loglevel
!= 0) {
1540 fprintf(logfile
, "DCR write error %d %03x\n", (int)T0
, (int)T0
);
1542 do_raise_exception_err(POWERPC_EXCP_PROGRAM
,
1543 POWERPC_EXCP_INVAL
| POWERPC_EXCP_PRIV_REG
);
1547 #if !defined(CONFIG_USER_ONLY)
1548 void do_40x_rfci (void)
1550 __do_rfi(env
->spr
[SPR_40x_SRR2
], env
->spr
[SPR_40x_SRR3
],
1551 ~((target_ulong
)0xFFFF0000), 0);
1556 __do_rfi(env
->spr
[SPR_BOOKE_CSRR0
], SPR_BOOKE_CSRR1
,
1557 ~((target_ulong
)0x3FFF0000), 0);
1562 __do_rfi(env
->spr
[SPR_BOOKE_DSRR0
], SPR_BOOKE_DSRR1
,
1563 ~((target_ulong
)0x3FFF0000), 0);
1566 void do_rfmci (void)
1568 __do_rfi(env
->spr
[SPR_BOOKE_MCSRR0
], SPR_BOOKE_MCSRR1
,
1569 ~((target_ulong
)0x3FFF0000), 0);
1572 void do_load_403_pb (int num
)
1577 void do_store_403_pb (int num
)
1579 if (likely(env
->pb
[num
] != T0
)) {
1581 /* Should be optimized */
1588 void do_440_dlmzb (void)
1594 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1595 if ((T0
& mask
) == 0)
1599 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
1600 if ((T1
& mask
) == 0)
1608 /* SPE extension helpers */
1609 /* Use a table to make this quicker */
1610 static uint8_t hbrev
[16] = {
1611 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
1612 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF,
1615 static always_inline
uint8_t byte_reverse (uint8_t val
)
1617 return hbrev
[val
>> 4] | (hbrev
[val
& 0xF] << 4);
1620 static always_inline
uint32_t word_reverse (uint32_t val
)
1622 return byte_reverse(val
>> 24) | (byte_reverse(val
>> 16) << 8) |
1623 (byte_reverse(val
>> 8) << 16) | (byte_reverse(val
) << 24);
1626 #define MASKBITS 16 // Random value - to be fixed (implementation dependant)
1627 target_ulong
helper_brinc (target_ulong arg1
, target_ulong arg2
)
1629 uint32_t a
, b
, d
, mask
;
1631 mask
= UINT32_MAX
>> (32 - MASKBITS
);
1634 d
= word_reverse(1 + word_reverse(a
| ~b
));
1635 return (arg1
& ~mask
) | (d
& b
);
1638 uint32_t helper_cntlsw32 (uint32_t val
)
1640 if (val
& 0x80000000)
1646 uint32_t helper_cntlzw32 (uint32_t val
)
1651 #define DO_SPE_OP1(name) \
1652 void do_ev##name (void) \
1654 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) | \
1655 (uint64_t)_do_e##name(T0_64); \
1658 #define DO_SPE_OP2(name) \
1659 void do_ev##name (void) \
1661 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) | \
1662 (uint64_t)_do_e##name(T0_64, T1_64); \
1665 /* Fixed-point vector comparisons */
1666 #define DO_SPE_CMP(name) \
1667 void do_ev##name (void) \
1669 T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32, \
1670 T1_64 >> 32) << 32, \
1671 _do_e##name(T0_64, T1_64)); \
1674 static always_inline
uint32_t _do_evcmp_merge (int t0
, int t1
)
1676 return (t0
<< 3) | (t1
<< 2) | ((t0
| t1
) << 1) | (t0
& t1
);
1679 /* Single precision floating-point conversions from/to integer */
1680 static always_inline
uint32_t _do_efscfsi (int32_t val
)
1684 u
.f
= int32_to_float32(val
, &env
->spe_status
);
1689 static always_inline
uint32_t _do_efscfui (uint32_t val
)
1693 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
1698 static always_inline
int32_t _do_efsctsi (uint32_t val
)
1703 /* NaN are not treated the same way IEEE 754 does */
1704 if (unlikely(isnan(u
.f
)))
1707 return float32_to_int32(u
.f
, &env
->spe_status
);
1710 static always_inline
uint32_t _do_efsctui (uint32_t val
)
1715 /* NaN are not treated the same way IEEE 754 does */
1716 if (unlikely(isnan(u
.f
)))
1719 return float32_to_uint32(u
.f
, &env
->spe_status
);
1722 static always_inline
int32_t _do_efsctsiz (uint32_t val
)
1727 /* NaN are not treated the same way IEEE 754 does */
1728 if (unlikely(isnan(u
.f
)))
1731 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
1734 static always_inline
uint32_t _do_efsctuiz (uint32_t val
)
1739 /* NaN are not treated the same way IEEE 754 does */
1740 if (unlikely(isnan(u
.f
)))
1743 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
1746 void do_efscfsi (void)
1748 T0_64
= _do_efscfsi(T0_64
);
1751 void do_efscfui (void)
1753 T0_64
= _do_efscfui(T0_64
);
1756 void do_efsctsi (void)
1758 T0_64
= _do_efsctsi(T0_64
);
1761 void do_efsctui (void)
1763 T0_64
= _do_efsctui(T0_64
);
1766 void do_efsctsiz (void)
1768 T0_64
= _do_efsctsiz(T0_64
);
1771 void do_efsctuiz (void)
1773 T0_64
= _do_efsctuiz(T0_64
);
1776 /* Single precision floating-point conversion to/from fractional */
1777 static always_inline
uint32_t _do_efscfsf (uint32_t val
)
1782 u
.f
= int32_to_float32(val
, &env
->spe_status
);
1783 tmp
= int64_to_float32(1ULL << 32, &env
->spe_status
);
1784 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
1789 static always_inline
uint32_t _do_efscfuf (uint32_t val
)
1794 u
.f
= uint32_to_float32(val
, &env
->spe_status
);
1795 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
1796 u
.f
= float32_div(u
.f
, tmp
, &env
->spe_status
);
1801 static always_inline
int32_t _do_efsctsf (uint32_t val
)
1807 /* NaN are not treated the same way IEEE 754 does */
1808 if (unlikely(isnan(u
.f
)))
1810 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
1811 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
1813 return float32_to_int32(u
.f
, &env
->spe_status
);
1816 static always_inline
uint32_t _do_efsctuf (uint32_t val
)
1822 /* NaN are not treated the same way IEEE 754 does */
1823 if (unlikely(isnan(u
.f
)))
1825 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
1826 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
1828 return float32_to_uint32(u
.f
, &env
->spe_status
);
1831 static always_inline
int32_t _do_efsctsfz (uint32_t val
)
1837 /* NaN are not treated the same way IEEE 754 does */
1838 if (unlikely(isnan(u
.f
)))
1840 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
1841 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
1843 return float32_to_int32_round_to_zero(u
.f
, &env
->spe_status
);
1846 static always_inline
uint32_t _do_efsctufz (uint32_t val
)
1852 /* NaN are not treated the same way IEEE 754 does */
1853 if (unlikely(isnan(u
.f
)))
1855 tmp
= uint64_to_float32(1ULL << 32, &env
->spe_status
);
1856 u
.f
= float32_mul(u
.f
, tmp
, &env
->spe_status
);
1858 return float32_to_uint32_round_to_zero(u
.f
, &env
->spe_status
);
1861 void do_efscfsf (void)
1863 T0_64
= _do_efscfsf(T0_64
);
1866 void do_efscfuf (void)
1868 T0_64
= _do_efscfuf(T0_64
);
1871 void do_efsctsf (void)
1873 T0_64
= _do_efsctsf(T0_64
);
1876 void do_efsctuf (void)
1878 T0_64
= _do_efsctuf(T0_64
);
1881 void do_efsctsfz (void)
1883 T0_64
= _do_efsctsfz(T0_64
);
1886 void do_efsctufz (void)
1888 T0_64
= _do_efsctufz(T0_64
);
1891 /* Double precision floating point helpers */
1892 static always_inline
int _do_efdcmplt (uint64_t op1
, uint64_t op2
)
1894 /* XXX: TODO: test special values (NaN, infinites, ...) */
1895 return _do_efdtstlt(op1
, op2
);
1898 static always_inline
int _do_efdcmpgt (uint64_t op1
, uint64_t op2
)
1900 /* XXX: TODO: test special values (NaN, infinites, ...) */
1901 return _do_efdtstgt(op1
, op2
);
1904 static always_inline
int _do_efdcmpeq (uint64_t op1
, uint64_t op2
)
1906 /* XXX: TODO: test special values (NaN, infinites, ...) */
1907 return _do_efdtsteq(op1
, op2
);
1910 void do_efdcmplt (void)
1912 T0
= _do_efdcmplt(T0_64
, T1_64
);
1915 void do_efdcmpgt (void)
1917 T0
= _do_efdcmpgt(T0_64
, T1_64
);
1920 void do_efdcmpeq (void)
1922 T0
= _do_efdcmpeq(T0_64
, T1_64
);
1925 /* Double precision floating-point conversion to/from integer */
1926 static always_inline
uint64_t _do_efdcfsi (int64_t val
)
1930 u
.d
= int64_to_float64(val
, &env
->spe_status
);
1935 static always_inline
uint64_t _do_efdcfui (uint64_t val
)
1939 u
.d
= uint64_to_float64(val
, &env
->spe_status
);
1944 static always_inline
int64_t _do_efdctsi (uint64_t val
)
1949 /* NaN are not treated the same way IEEE 754 does */
1950 if (unlikely(isnan(u
.d
)))
1953 return float64_to_int64(u
.d
, &env
->spe_status
);
1956 static always_inline
uint64_t _do_efdctui (uint64_t val
)
1961 /* NaN are not treated the same way IEEE 754 does */
1962 if (unlikely(isnan(u
.d
)))
1965 return float64_to_uint64(u
.d
, &env
->spe_status
);
1968 static always_inline
int64_t _do_efdctsiz (uint64_t val
)
1973 /* NaN are not treated the same way IEEE 754 does */
1974 if (unlikely(isnan(u
.d
)))
1977 return float64_to_int64_round_to_zero(u
.d
, &env
->spe_status
);
1980 static always_inline
uint64_t _do_efdctuiz (uint64_t val
)
1985 /* NaN are not treated the same way IEEE 754 does */
1986 if (unlikely(isnan(u
.d
)))
1989 return float64_to_uint64_round_to_zero(u
.d
, &env
->spe_status
);
1992 void do_efdcfsi (void)
1994 T0_64
= _do_efdcfsi(T0_64
);
1997 void do_efdcfui (void)
1999 T0_64
= _do_efdcfui(T0_64
);
2002 void do_efdctsi (void)
2004 T0_64
= _do_efdctsi(T0_64
);
2007 void do_efdctui (void)
2009 T0_64
= _do_efdctui(T0_64
);
2012 void do_efdctsiz (void)
2014 T0_64
= _do_efdctsiz(T0_64
);
2017 void do_efdctuiz (void)
2019 T0_64
= _do_efdctuiz(T0_64
);
2022 /* Double precision floating-point conversion to/from fractional */
2023 static always_inline
uint64_t _do_efdcfsf (int64_t val
)
2028 u
.d
= int32_to_float64(val
, &env
->spe_status
);
2029 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2030 u
.d
= float64_div(u
.d
, tmp
, &env
->spe_status
);
2035 static always_inline
uint64_t _do_efdcfuf (uint64_t val
)
2040 u
.d
= uint32_to_float64(val
, &env
->spe_status
);
2041 tmp
= int64_to_float64(1ULL << 32, &env
->spe_status
);
2042 u
.d
= float64_div(u
.d
, tmp
, &env
->spe_status
);
2047 static always_inline
int64_t _do_efdctsf (uint64_t val
)
2053 /* NaN are not treated the same way IEEE 754 does */
2054 if (unlikely(isnan(u
.d
)))
2056 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2057 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2059 return float64_to_int32(u
.d
, &env
->spe_status
);
2062 static always_inline
uint64_t _do_efdctuf (uint64_t val
)
2068 /* NaN are not treated the same way IEEE 754 does */
2069 if (unlikely(isnan(u
.d
)))
2071 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2072 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2074 return float64_to_uint32(u
.d
, &env
->spe_status
);
2077 static always_inline
int64_t _do_efdctsfz (uint64_t val
)
2083 /* NaN are not treated the same way IEEE 754 does */
2084 if (unlikely(isnan(u
.d
)))
2086 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2087 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2089 return float64_to_int32_round_to_zero(u
.d
, &env
->spe_status
);
2092 static always_inline
uint64_t _do_efdctufz (uint64_t val
)
2098 /* NaN are not treated the same way IEEE 754 does */
2099 if (unlikely(isnan(u
.d
)))
2101 tmp
= uint64_to_float64(1ULL << 32, &env
->spe_status
);
2102 u
.d
= float64_mul(u
.d
, tmp
, &env
->spe_status
);
2104 return float64_to_uint32_round_to_zero(u
.d
, &env
->spe_status
);
2107 void do_efdcfsf (void)
2109 T0_64
= _do_efdcfsf(T0_64
);
2112 void do_efdcfuf (void)
2114 T0_64
= _do_efdcfuf(T0_64
);
2117 void do_efdctsf (void)
2119 T0_64
= _do_efdctsf(T0_64
);
2122 void do_efdctuf (void)
2124 T0_64
= _do_efdctuf(T0_64
);
2127 void do_efdctsfz (void)
2129 T0_64
= _do_efdctsfz(T0_64
);
2132 void do_efdctufz (void)
2134 T0_64
= _do_efdctufz(T0_64
);
2137 /* Floating point conversion between single and double precision */
2138 static always_inline
uint32_t _do_efscfd (uint64_t val
)
2144 u2
.f
= float64_to_float32(u1
.d
, &env
->spe_status
);
2149 static always_inline
uint64_t _do_efdcfs (uint32_t val
)
2155 u2
.d
= float32_to_float64(u1
.f
, &env
->spe_status
);
2160 void do_efscfd (void)
2162 T0_64
= _do_efscfd(T0_64
);
2165 void do_efdcfs (void)
2167 T0_64
= _do_efdcfs(T0_64
);
2170 /* Single precision fixed-point vector arithmetic */
2186 /* Single-precision floating-point comparisons */
2187 static always_inline
int _do_efscmplt (uint32_t op1
, uint32_t op2
)
2189 /* XXX: TODO: test special values (NaN, infinites, ...) */
2190 return _do_efststlt(op1
, op2
);
2193 static always_inline
int _do_efscmpgt (uint32_t op1
, uint32_t op2
)
2195 /* XXX: TODO: test special values (NaN, infinites, ...) */
2196 return _do_efststgt(op1
, op2
);
2199 static always_inline
int _do_efscmpeq (uint32_t op1
, uint32_t op2
)
2201 /* XXX: TODO: test special values (NaN, infinites, ...) */
2202 return _do_efststeq(op1
, op2
);
2205 void do_efscmplt (void)
2207 T0
= _do_efscmplt(T0_64
, T1_64
);
2210 void do_efscmpgt (void)
2212 T0
= _do_efscmpgt(T0_64
, T1_64
);
2215 void do_efscmpeq (void)
2217 T0
= _do_efscmpeq(T0_64
, T1_64
);
2220 /* Single-precision floating-point vector comparisons */
2222 DO_SPE_CMP(fscmplt
);
2224 DO_SPE_CMP(fscmpgt
);
2226 DO_SPE_CMP(fscmpeq
);
2228 DO_SPE_CMP(fststlt
);
2230 DO_SPE_CMP(fststgt
);
2232 DO_SPE_CMP(fststeq
);
2234 /* Single-precision floating-point vector conversions */
2248 DO_SPE_OP1(fsctsiz
);
2250 DO_SPE_OP1(fsctuiz
);
2256 /*****************************************************************************/
2257 /* Softmmu support */
2258 #if !defined (CONFIG_USER_ONLY)
2260 #define MMUSUFFIX _mmu
2263 #include "softmmu_template.h"
2266 #include "softmmu_template.h"
2269 #include "softmmu_template.h"
2272 #include "softmmu_template.h"
2274 /* try to fill the TLB and return an exception if error. If retaddr is
2275 NULL, it means that the function was called in C code (i.e. not
2276 from generated code or from helper.c) */
2277 /* XXX: fix it to restore all registers */
2278 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
2280 TranslationBlock
*tb
;
2281 CPUState
*saved_env
;
2285 /* XXX: hack to restore env in all cases, even if not called from
2288 env
= cpu_single_env
;
2289 ret
= cpu_ppc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
2290 if (unlikely(ret
!= 0)) {
2291 if (likely(retaddr
)) {
2292 /* now we have a real cpu fault */
2293 pc
= (unsigned long)retaddr
;
2294 tb
= tb_find_pc(pc
);
2296 /* the PC is inside the translated code. It means that we have
2297 a virtual CPU fault */
2298 cpu_restore_state(tb
, env
, pc
, NULL
);
2301 do_raise_exception_err(env
->exception_index
, env
->error_code
);
2306 /* Software driven TLBs management */
2307 /* PowerPC 602/603 software TLB load instructions helpers */
2308 void do_load_6xx_tlb (int is_code
)
2310 target_ulong RPN
, CMP
, EPN
;
2313 RPN
= env
->spr
[SPR_RPA
];
2315 CMP
= env
->spr
[SPR_ICMP
];
2316 EPN
= env
->spr
[SPR_IMISS
];
2318 CMP
= env
->spr
[SPR_DCMP
];
2319 EPN
= env
->spr
[SPR_DMISS
];
2321 way
= (env
->spr
[SPR_SRR1
] >> 17) & 1;
2322 #if defined (DEBUG_SOFTWARE_TLB)
2323 if (loglevel
!= 0) {
2324 fprintf(logfile
, "%s: EPN " TDX
" " ADDRX
" PTE0 " ADDRX
2325 " PTE1 " ADDRX
" way %d\n",
2326 __func__
, T0
, EPN
, CMP
, RPN
, way
);
2329 /* Store this TLB */
2330 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2331 way
, is_code
, CMP
, RPN
);
2334 void do_load_74xx_tlb (int is_code
)
2336 target_ulong RPN
, CMP
, EPN
;
2339 RPN
= env
->spr
[SPR_PTELO
];
2340 CMP
= env
->spr
[SPR_PTEHI
];
2341 EPN
= env
->spr
[SPR_TLBMISS
] & ~0x3;
2342 way
= env
->spr
[SPR_TLBMISS
] & 0x3;
2343 #if defined (DEBUG_SOFTWARE_TLB)
2344 if (loglevel
!= 0) {
2345 fprintf(logfile
, "%s: EPN " TDX
" " ADDRX
" PTE0 " ADDRX
2346 " PTE1 " ADDRX
" way %d\n",
2347 __func__
, T0
, EPN
, CMP
, RPN
, way
);
2350 /* Store this TLB */
2351 ppc6xx_tlb_store(env
, (uint32_t)(T0
& TARGET_PAGE_MASK
),
2352 way
, is_code
, CMP
, RPN
);
2355 static always_inline target_ulong
booke_tlb_to_page_size (int size
)
2357 return 1024 << (2 * size
);
2360 static always_inline
int booke_page_size_to_tlb (target_ulong page_size
)
2364 switch (page_size
) {
2398 #if defined (TARGET_PPC64)
2399 case 0x000100000000ULL
:
2402 case 0x000400000000ULL
:
2405 case 0x001000000000ULL
:
2408 case 0x004000000000ULL
:
2411 case 0x010000000000ULL
:
2423 /* Helpers for 4xx TLB management */
2424 void do_4xx_tlbre_lo (void)
2430 tlb
= &env
->tlb
[T0
].tlbe
;
2432 if (tlb
->prot
& PAGE_VALID
)
2434 size
= booke_page_size_to_tlb(tlb
->size
);
2435 if (size
< 0 || size
> 0x7)
2438 env
->spr
[SPR_40x_PID
] = tlb
->PID
;
2441 void do_4xx_tlbre_hi (void)
2446 tlb
= &env
->tlb
[T0
].tlbe
;
2448 if (tlb
->prot
& PAGE_EXEC
)
2450 if (tlb
->prot
& PAGE_WRITE
)
2454 void do_4xx_tlbwe_hi (void)
2457 target_ulong page
, end
;
2459 #if defined (DEBUG_SOFTWARE_TLB)
2460 if (loglevel
!= 0) {
2461 fprintf(logfile
, "%s T0 " TDX
" T1 " TDX
"\n", __func__
, T0
, T1
);
2465 tlb
= &env
->tlb
[T0
].tlbe
;
2466 /* Invalidate previous TLB (if it's valid) */
2467 if (tlb
->prot
& PAGE_VALID
) {
2468 end
= tlb
->EPN
+ tlb
->size
;
2469 #if defined (DEBUG_SOFTWARE_TLB)
2470 if (loglevel
!= 0) {
2471 fprintf(logfile
, "%s: invalidate old TLB %d start " ADDRX
2472 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2475 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2476 tlb_flush_page(env
, page
);
2478 tlb
->size
= booke_tlb_to_page_size((T1
>> 7) & 0x7);
2479 /* We cannot handle TLB size < TARGET_PAGE_SIZE.
2480 * If this ever occurs, one should use the ppcemb target instead
2481 * of the ppc or ppc64 one
2483 if ((T1
& 0x40) && tlb
->size
< TARGET_PAGE_SIZE
) {
2484 cpu_abort(env
, "TLB size " TARGET_FMT_lu
" < %u "
2485 "are not supported (%d)\n",
2486 tlb
->size
, TARGET_PAGE_SIZE
, (int)((T1
>> 7) & 0x7));
2488 tlb
->EPN
= T1
& ~(tlb
->size
- 1);
2490 tlb
->prot
|= PAGE_VALID
;
2492 tlb
->prot
&= ~PAGE_VALID
;
2494 /* XXX: TO BE FIXED */
2495 cpu_abort(env
, "Little-endian TLB entries are not supported by now\n");
2497 tlb
->PID
= env
->spr
[SPR_40x_PID
]; /* PID */
2498 tlb
->attr
= T1
& 0xFF;
2499 #if defined (DEBUG_SOFTWARE_TLB)
2500 if (loglevel
!= 0) {
2501 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
2502 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
2503 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
2504 tlb
->prot
& PAGE_READ
? 'r' : '-',
2505 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
2506 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
2507 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
2510 /* Invalidate new TLB (if valid) */
2511 if (tlb
->prot
& PAGE_VALID
) {
2512 end
= tlb
->EPN
+ tlb
->size
;
2513 #if defined (DEBUG_SOFTWARE_TLB)
2514 if (loglevel
!= 0) {
2515 fprintf(logfile
, "%s: invalidate TLB %d start " ADDRX
2516 " end " ADDRX
"\n", __func__
, (int)T0
, tlb
->EPN
, end
);
2519 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
2520 tlb_flush_page(env
, page
);
2524 void do_4xx_tlbwe_lo (void)
2528 #if defined (DEBUG_SOFTWARE_TLB)
2529 if (loglevel
!= 0) {
2530 fprintf(logfile
, "%s T0 " TDX
" T1 " TDX
"\n", __func__
, T0
, T1
);
2534 tlb
= &env
->tlb
[T0
].tlbe
;
2535 tlb
->RPN
= T1
& 0xFFFFFC00;
2536 tlb
->prot
= PAGE_READ
;
2538 tlb
->prot
|= PAGE_EXEC
;
2540 tlb
->prot
|= PAGE_WRITE
;
2541 #if defined (DEBUG_SOFTWARE_TLB)
2542 if (loglevel
!= 0) {
2543 fprintf(logfile
, "%s: set up TLB %d RPN " PADDRX
" EPN " ADDRX
2544 " size " ADDRX
" prot %c%c%c%c PID %d\n", __func__
,
2545 (int)T0
, tlb
->RPN
, tlb
->EPN
, tlb
->size
,
2546 tlb
->prot
& PAGE_READ
? 'r' : '-',
2547 tlb
->prot
& PAGE_WRITE
? 'w' : '-',
2548 tlb
->prot
& PAGE_EXEC
? 'x' : '-',
2549 tlb
->prot
& PAGE_VALID
? 'v' : '-', (int)tlb
->PID
);
2554 /* PowerPC 440 TLB management */
2555 void do_440_tlbwe (int word
)
2558 target_ulong EPN
, RPN
, size
;
2561 #if defined (DEBUG_SOFTWARE_TLB)
2562 if (loglevel
!= 0) {
2563 fprintf(logfile
, "%s word %d T0 " TDX
" T1 " TDX
"\n",
2564 __func__
, word
, T0
, T1
);
2569 tlb
= &env
->tlb
[T0
].tlbe
;
2572 /* Just here to please gcc */
2574 EPN
= T1
& 0xFFFFFC00;
2575 if ((tlb
->prot
& PAGE_VALID
) && EPN
!= tlb
->EPN
)
2578 size
= booke_tlb_to_page_size((T1
>> 4) & 0xF);
2579 if ((tlb
->prot
& PAGE_VALID
) && tlb
->size
< size
)
2583 tlb
->attr
|= (T1
>> 8) & 1;
2585 tlb
->prot
|= PAGE_VALID
;
2587 if (tlb
->prot
& PAGE_VALID
) {
2588 tlb
->prot
&= ~PAGE_VALID
;
2592 tlb
->PID
= env
->spr
[SPR_440_MMUCR
] & 0x000000FF;
2597 RPN
= T1
& 0xFFFFFC0F;
2598 if ((tlb
->prot
& PAGE_VALID
) && tlb
->RPN
!= RPN
)
2603 tlb
->attr
= (tlb
->attr
& 0x1) | (T1
& 0x0000FF00);
2604 tlb
->prot
= tlb
->prot
& PAGE_VALID
;
2606 tlb
->prot
|= PAGE_READ
<< 4;
2608 tlb
->prot
|= PAGE_WRITE
<< 4;
2610 tlb
->prot
|= PAGE_EXEC
<< 4;
2612 tlb
->prot
|= PAGE_READ
;
2614 tlb
->prot
|= PAGE_WRITE
;
2616 tlb
->prot
|= PAGE_EXEC
;
2621 void do_440_tlbre (int word
)
2627 tlb
= &env
->tlb
[T0
].tlbe
;
2630 /* Just here to please gcc */
2633 size
= booke_page_size_to_tlb(tlb
->size
);
2634 if (size
< 0 || size
> 0xF)
2637 if (tlb
->attr
& 0x1)
2639 if (tlb
->prot
& PAGE_VALID
)
2641 env
->spr
[SPR_440_MMUCR
] &= ~0x000000FF;
2642 env
->spr
[SPR_440_MMUCR
] |= tlb
->PID
;
2648 T0
= tlb
->attr
& ~0x1;
2649 if (tlb
->prot
& (PAGE_READ
<< 4))
2651 if (tlb
->prot
& (PAGE_WRITE
<< 4))
2653 if (tlb
->prot
& (PAGE_EXEC
<< 4))
2655 if (tlb
->prot
& PAGE_READ
)
2657 if (tlb
->prot
& PAGE_WRITE
)
2659 if (tlb
->prot
& PAGE_EXEC
)
2664 #endif /* !CONFIG_USER_ONLY */