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 void do_brinc (void)
1629 uint32_t a, b, d, mask;
1631 mask = UINT32_MAX >> (32 - MASKBITS);
1634 d = word_reverse(1 + word_reverse(a | ~b));
1635 T0 = (T0 & ~mask) | (d & b);
1638 #define DO_SPE_OP2(name) \
1639 void do_ev##name (void) \
1641 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) | \
1642 (uint64_t)_do_e##name(T0_64, T1_64); \
1645 #define DO_SPE_OP1(name) \
1646 void do_ev##name (void) \
1648 T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) | \
1649 (uint64_t)_do_e##name(T0_64); \
1652 /* Fixed-point vector arithmetic */
1653 static always_inline uint32_t _do_eabs (uint32_t val)
1655 if ((val & 0x80000000) && val != 0x80000000)
1661 static always_inline uint32_t _do_eaddw (uint32_t op1, uint32_t op2)
1666 static always_inline int _do_ecntlsw (uint32_t val)
1668 if (val & 0x80000000)
1674 static always_inline int _do_ecntlzw (uint32_t val)
1679 static always_inline uint32_t _do_eneg (uint32_t val)
1681 if (val != 0x80000000)
1687 static always_inline uint32_t _do_erlw (uint32_t op1, uint32_t op2)
1689 return rotl32(op1, op2);
1692 static always_inline uint32_t _do_erndw (uint32_t val)
1694 return (val + 0x000080000000) & 0xFFFF0000;
1697 static always_inline uint32_t _do_eslw (uint32_t op1, uint32_t op2)
1699 /* No error here: 6 bits are used */
1700 return op1 << (op2 & 0x3F);
1703 static always_inline int32_t _do_esrws (int32_t op1, uint32_t op2)
1705 /* No error here: 6 bits are used */
1706 return op1 >> (op2 & 0x3F);
1709 static always_inline uint32_t _do_esrwu (uint32_t op1, uint32_t op2)
1711 /* No error here: 6 bits are used */
1712 return op1 >> (op2 & 0x3F);
1715 static always_inline uint32_t _do_esubfw (uint32_t op1, uint32_t op2)
1743 /* evsel is a little bit more complicated... */
1744 static always_inline uint32_t _do_esel (uint32_t op1, uint32_t op2, int n)
1752 void do_evsel (void)
1754 T0_64 = ((uint64_t)_do_esel(T0_64 >> 32, T1_64 >> 32, T0 >> 3) << 32) |
1755 (uint64_t)_do_esel(T0_64, T1_64, (T0 >> 2) & 1);
1758 /* Fixed-point vector comparisons */
1759 #define DO_SPE_CMP(name) \
1760 void do_ev##name (void) \
1762 T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32, \
1763 T1_64 >> 32) << 32, \
1764 _do_e##name(T0_64, T1_64)); \
1767 static always_inline uint32_t _do_evcmp_merge (int t0, int t1)
1769 return (t0 << 3) | (t1 << 2) | ((t0 | t1) << 1) | (t0 & t1);
1771 static always_inline int _do_ecmpeq (uint32_t op1, uint32_t op2)
1773 return op1 == op2 ? 1 : 0;
1776 static always_inline int _do_ecmpgts (int32_t op1, int32_t op2)
1778 return op1 > op2 ? 1 : 0;
1781 static always_inline int _do_ecmpgtu (uint32_t op1, uint32_t op2)
1783 return op1 > op2 ? 1 : 0;
1786 static always_inline int _do_ecmplts (int32_t op1, int32_t op2)
1788 return op1 < op2 ? 1 : 0;
1791 static always_inline int _do_ecmpltu (uint32_t op1, uint32_t op2)
1793 return op1 < op2 ? 1 : 0;
1807 /* Single precision floating-point conversions from/to integer */
1808 static always_inline uint32_t _do_efscfsi (int32_t val)
1812 u.f = int32_to_float32(val, &env->spe_status);
1817 static always_inline uint32_t _do_efscfui (uint32_t val)
1821 u.f = uint32_to_float32(val, &env->spe_status);
1826 static always_inline int32_t _do_efsctsi (uint32_t val)
1831 /* NaN are not treated the same way IEEE 754 does */
1832 if (unlikely(isnan(u.f)))
1835 return float32_to_int32(u.f, &env->spe_status);
1838 static always_inline uint32_t _do_efsctui (uint32_t val)
1843 /* NaN are not treated the same way IEEE 754 does */
1844 if (unlikely(isnan(u.f)))
1847 return float32_to_uint32(u.f, &env->spe_status);
1850 static always_inline int32_t _do_efsctsiz (uint32_t val)
1855 /* NaN are not treated the same way IEEE 754 does */
1856 if (unlikely(isnan(u.f)))
1859 return float32_to_int32_round_to_zero(u.f, &env->spe_status);
1862 static always_inline uint32_t _do_efsctuiz (uint32_t val)
1867 /* NaN are not treated the same way IEEE 754 does */
1868 if (unlikely(isnan(u.f)))
1871 return float32_to_uint32_round_to_zero(u.f, &env->spe_status);
1874 void do_efscfsi (void)
1876 T0_64 = _do_efscfsi(T0_64);
1879 void do_efscfui (void)
1881 T0_64 = _do_efscfui(T0_64);
1884 void do_efsctsi (void)
1886 T0_64 = _do_efsctsi(T0_64);
1889 void do_efsctui (void)
1891 T0_64 = _do_efsctui(T0_64);
1894 void do_efsctsiz (void)
1896 T0_64 = _do_efsctsiz(T0_64);
1899 void do_efsctuiz (void)
1901 T0_64 = _do_efsctuiz(T0_64);
1904 /* Single precision floating-point conversion to/from fractional */
1905 static always_inline uint32_t _do_efscfsf (uint32_t val)
1910 u.f = int32_to_float32(val, &env->spe_status);
1911 tmp = int64_to_float32(1ULL << 32, &env->spe_status);
1912 u.f = float32_div(u.f, tmp, &env->spe_status);
1917 static always_inline uint32_t _do_efscfuf (uint32_t val)
1922 u.f = uint32_to_float32(val, &env->spe_status);
1923 tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1924 u.f = float32_div(u.f, tmp, &env->spe_status);
1929 static always_inline int32_t _do_efsctsf (uint32_t val)
1935 /* NaN are not treated the same way IEEE 754 does */
1936 if (unlikely(isnan(u.f)))
1938 tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1939 u.f = float32_mul(u.f, tmp, &env->spe_status);
1941 return float32_to_int32(u.f, &env->spe_status);
1944 static always_inline uint32_t _do_efsctuf (uint32_t val)
1950 /* NaN are not treated the same way IEEE 754 does */
1951 if (unlikely(isnan(u.f)))
1953 tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1954 u.f = float32_mul(u.f, tmp, &env->spe_status);
1956 return float32_to_uint32(u.f, &env->spe_status);
1959 static always_inline int32_t _do_efsctsfz (uint32_t val)
1965 /* NaN are not treated the same way IEEE 754 does */
1966 if (unlikely(isnan(u.f)))
1968 tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1969 u.f = float32_mul(u.f, tmp, &env->spe_status);
1971 return float32_to_int32_round_to_zero(u.f, &env->spe_status);
1974 static always_inline uint32_t _do_efsctufz (uint32_t val)
1980 /* NaN are not treated the same way IEEE 754 does */
1981 if (unlikely(isnan(u.f)))
1983 tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1984 u.f = float32_mul(u.f, tmp, &env->spe_status);
1986 return float32_to_uint32_round_to_zero(u.f, &env->spe_status);
1989 void do_efscfsf (void)
1991 T0_64 = _do_efscfsf(T0_64);
1994 void do_efscfuf (void)
1996 T0_64 = _do_efscfuf(T0_64);
1999 void do_efsctsf (void)
2001 T0_64 = _do_efsctsf(T0_64);
2004 void do_efsctuf (void)
2006 T0_64 = _do_efsctuf(T0_64);
2009 void do_efsctsfz (void)
2011 T0_64 = _do_efsctsfz(T0_64);
2014 void do_efsctufz (void)
2016 T0_64 = _do_efsctufz(T0_64);
2019 /* Double precision floating point helpers */
2020 static always_inline int _do_efdcmplt (uint64_t op1, uint64_t op2)
2022 /* XXX: TODO: test special values (NaN, infinites, ...) */
2023 return _do_efdtstlt(op1, op2);
2026 static always_inline int _do_efdcmpgt (uint64_t op1, uint64_t op2)
2028 /* XXX: TODO: test special values (NaN, infinites, ...) */
2029 return _do_efdtstgt(op1, op2);
2032 static always_inline int _do_efdcmpeq (uint64_t op1, uint64_t op2)
2034 /* XXX: TODO: test special values (NaN, infinites, ...) */
2035 return _do_efdtsteq(op1, op2);
2038 void do_efdcmplt (void)
2040 T0 = _do_efdcmplt(T0_64, T1_64);
2043 void do_efdcmpgt (void)
2045 T0 = _do_efdcmpgt(T0_64, T1_64);
2048 void do_efdcmpeq (void)
2050 T0 = _do_efdcmpeq(T0_64, T1_64);
2053 /* Double precision floating-point conversion to/from integer */
2054 static always_inline uint64_t _do_efdcfsi (int64_t val)
2058 u.d = int64_to_float64(val, &env->spe_status);
2063 static always_inline uint64_t _do_efdcfui (uint64_t val)
2067 u.d = uint64_to_float64(val, &env->spe_status);
2072 static always_inline int64_t _do_efdctsi (uint64_t val)
2077 /* NaN are not treated the same way IEEE 754 does */
2078 if (unlikely(isnan(u.d)))
2081 return float64_to_int64(u.d, &env->spe_status);
2084 static always_inline uint64_t _do_efdctui (uint64_t val)
2089 /* NaN are not treated the same way IEEE 754 does */
2090 if (unlikely(isnan(u.d)))
2093 return float64_to_uint64(u.d, &env->spe_status);
2096 static always_inline int64_t _do_efdctsiz (uint64_t val)
2101 /* NaN are not treated the same way IEEE 754 does */
2102 if (unlikely(isnan(u.d)))
2105 return float64_to_int64_round_to_zero(u.d, &env->spe_status);
2108 static always_inline uint64_t _do_efdctuiz (uint64_t val)
2113 /* NaN are not treated the same way IEEE 754 does */
2114 if (unlikely(isnan(u.d)))
2117 return float64_to_uint64_round_to_zero(u.d, &env->spe_status);
2120 void do_efdcfsi (void)
2122 T0_64 = _do_efdcfsi(T0_64);
2125 void do_efdcfui (void)
2127 T0_64 = _do_efdcfui(T0_64);
2130 void do_efdctsi (void)
2132 T0_64 = _do_efdctsi(T0_64);
2135 void do_efdctui (void)
2137 T0_64 = _do_efdctui(T0_64);
2140 void do_efdctsiz (void)
2142 T0_64 = _do_efdctsiz(T0_64);
2145 void do_efdctuiz (void)
2147 T0_64 = _do_efdctuiz(T0_64);
2150 /* Double precision floating-point conversion to/from fractional */
2151 static always_inline uint64_t _do_efdcfsf (int64_t val)
2156 u.d = int32_to_float64(val, &env->spe_status);
2157 tmp = int64_to_float64(1ULL << 32, &env->spe_status);
2158 u.d = float64_div(u.d, tmp, &env->spe_status);
2163 static always_inline uint64_t _do_efdcfuf (uint64_t val)
2168 u.d = uint32_to_float64(val, &env->spe_status);
2169 tmp = int64_to_float64(1ULL << 32, &env->spe_status);
2170 u.d = float64_div(u.d, tmp, &env->spe_status);
2175 static always_inline int64_t _do_efdctsf (uint64_t val)
2181 /* NaN are not treated the same way IEEE 754 does */
2182 if (unlikely(isnan(u.d)))
2184 tmp = uint64_to_float64(1ULL << 32, &env->spe_status);
2185 u.d = float64_mul(u.d, tmp, &env->spe_status);
2187 return float64_to_int32(u.d, &env->spe_status);
2190 static always_inline uint64_t _do_efdctuf (uint64_t val)
2196 /* NaN are not treated the same way IEEE 754 does */
2197 if (unlikely(isnan(u.d)))
2199 tmp = uint64_to_float64(1ULL << 32, &env->spe_status);
2200 u.d = float64_mul(u.d, tmp, &env->spe_status);
2202 return float64_to_uint32(u.d, &env->spe_status);
2205 static always_inline int64_t _do_efdctsfz (uint64_t val)
2211 /* NaN are not treated the same way IEEE 754 does */
2212 if (unlikely(isnan(u.d)))
2214 tmp = uint64_to_float64(1ULL << 32, &env->spe_status);
2215 u.d = float64_mul(u.d, tmp, &env->spe_status);
2217 return float64_to_int32_round_to_zero(u.d, &env->spe_status);
2220 static always_inline uint64_t _do_efdctufz (uint64_t val)
2226 /* NaN are not treated the same way IEEE 754 does */
2227 if (unlikely(isnan(u.d)))
2229 tmp = uint64_to_float64(1ULL << 32, &env->spe_status);
2230 u.d = float64_mul(u.d, tmp, &env->spe_status);
2232 return float64_to_uint32_round_to_zero(u.d, &env->spe_status);
2235 void do_efdcfsf (void)
2237 T0_64 = _do_efdcfsf(T0_64);
2240 void do_efdcfuf (void)
2242 T0_64 = _do_efdcfuf(T0_64);
2245 void do_efdctsf (void)
2247 T0_64 = _do_efdctsf(T0_64);
2250 void do_efdctuf (void)
2252 T0_64 = _do_efdctuf(T0_64);
2255 void do_efdctsfz (void)
2257 T0_64 = _do_efdctsfz(T0_64);
2260 void do_efdctufz (void)
2262 T0_64 = _do_efdctufz(T0_64);
2265 /* Floating point conversion between single and double precision */
2266 static always_inline uint32_t _do_efscfd (uint64_t val)
2272 u2.f = float64_to_float32(u1.d, &env->spe_status);
2277 static always_inline uint64_t _do_efdcfs (uint32_t val)
2283 u2.d = float32_to_float64(u1.f, &env->spe_status);
2288 void do_efscfd (void)
2290 T0_64 = _do_efscfd(T0_64);
2293 void do_efdcfs (void)
2295 T0_64 = _do_efdcfs(T0_64);
2298 /* Single precision fixed-point vector arithmetic */
2314 /* Single-precision floating-point comparisons */
2315 static always_inline int _do_efscmplt (uint32_t op1, uint32_t op2)
2317 /* XXX: TODO: test special values (NaN, infinites, ...) */
2318 return _do_efststlt(op1, op2);
2321 static always_inline int _do_efscmpgt (uint32_t op1, uint32_t op2)
2323 /* XXX: TODO: test special values (NaN, infinites, ...) */
2324 return _do_efststgt(op1, op2);
2327 static always_inline int _do_efscmpeq (uint32_t op1, uint32_t op2)
2329 /* XXX: TODO: test special values (NaN, infinites, ...) */
2330 return _do_efststeq(op1, op2);
2333 void do_efscmplt (void)
2335 T0 = _do_efscmplt(T0_64, T1_64);
2338 void do_efscmpgt (void)
2340 T0 = _do_efscmpgt(T0_64, T1_64);
2343 void do_efscmpeq (void)
2345 T0 = _do_efscmpeq(T0_64, T1_64);
2348 /* Single-precision floating-point vector comparisons */
2350 DO_SPE_CMP(fscmplt);
2352 DO_SPE_CMP(fscmpgt);
2354 DO_SPE_CMP(fscmpeq);
2356 DO_SPE_CMP(fststlt);
2358 DO_SPE_CMP(fststgt);
2360 DO_SPE_CMP(fststeq);
2362 /* Single-precision floating-point vector conversions */
2376 DO_SPE_OP1(fsctsiz);
2378 DO_SPE_OP1(fsctuiz);
2384 /*****************************************************************************/
2385 /* Softmmu support */
2386 #if !defined (CONFIG_USER_ONLY)
2388 #define MMUSUFFIX _mmu
2391 #include "softmmu_template.h"
2394 #include "softmmu_template.h"
2397 #include "softmmu_template.h"
2400 #include "softmmu_template.h"
2402 /* try to fill the TLB and return an exception if error. If retaddr is
2403 NULL, it means that the function was called in C code (i.e. not
2404 from generated code or from helper.c) */
2405 /* XXX: fix it to restore all registers */
2406 void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
2408 TranslationBlock *tb;
2409 CPUState *saved_env;
2413 /* XXX: hack to restore env in all cases, even if not called from
2416 env = cpu_single_env;
2417 ret = cpu_ppc_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
2418 if (unlikely(ret != 0)) {
2419 if (likely(retaddr)) {
2420 /* now we have a real cpu fault */
2421 pc = (unsigned long)retaddr;
2422 tb = tb_find_pc(pc);
2424 /* the PC is inside the translated code. It means that we have
2425 a virtual CPU fault */
2426 cpu_restore_state(tb, env, pc, NULL);
2429 do_raise_exception_err(env->exception_index, env->error_code);
2434 /* Software driven TLBs management */
2435 /* PowerPC 602/603 software TLB load instructions helpers */
2436 void do_load_6xx_tlb (int is_code)
2438 target_ulong RPN, CMP, EPN;
2441 RPN = env->spr[SPR_RPA];
2443 CMP = env->spr[SPR_ICMP];
2444 EPN = env->spr[SPR_IMISS];
2446 CMP = env->spr[SPR_DCMP];
2447 EPN = env->spr[SPR_DMISS];
2449 way = (env->spr[SPR_SRR1] >> 17) & 1;
2450 #if defined (DEBUG_SOFTWARE_TLB)
2451 if (loglevel != 0) {
2452 fprintf(logfile, "%s: EPN " TDX " " ADDRX " PTE0 " ADDRX
2453 " PTE1 " ADDRX " way %d\n",
2454 __func__, T0, EPN, CMP, RPN, way);
2457 /* Store this TLB */
2458 ppc6xx_tlb_store(env, (uint32_t)(T0 & TARGET_PAGE_MASK),
2459 way, is_code, CMP, RPN);
2462 void do_load_74xx_tlb (int is_code)
2464 target_ulong RPN, CMP, EPN;
2467 RPN = env->spr[SPR_PTELO];
2468 CMP = env->spr[SPR_PTEHI];
2469 EPN = env->spr[SPR_TLBMISS] & ~0x3;
2470 way = env->spr[SPR_TLBMISS] & 0x3;
2471 #if defined (DEBUG_SOFTWARE_TLB)
2472 if (loglevel != 0) {
2473 fprintf(logfile, "%s: EPN " TDX " " ADDRX " PTE0 " ADDRX
2474 " PTE1 " ADDRX " way %d\n",
2475 __func__, T0, EPN, CMP, RPN, way);
2478 /* Store this TLB */
2479 ppc6xx_tlb_store(env, (uint32_t)(T0 & TARGET_PAGE_MASK),
2480 way, is_code, CMP, RPN);
2483 static always_inline target_ulong booke_tlb_to_page_size (int size)
2485 return 1024 << (2 * size);
2488 static always_inline int booke_page_size_to_tlb (target_ulong page_size)
2492 switch (page_size) {
2526 #if defined (TARGET_PPC64)
2527 case 0x000100000000ULL:
2530 case 0x000400000000ULL:
2533 case 0x001000000000ULL:
2536 case 0x004000000000ULL:
2539 case 0x010000000000ULL:
2551 /* Helpers for 4xx TLB management */
2552 void do_4xx_tlbre_lo (void)
2558 tlb = &env->tlb[T0].tlbe;
2560 if (tlb->prot & PAGE_VALID)
2562 size = booke_page_size_to_tlb(tlb->size);
2563 if (size < 0 || size > 0x7)
2566 env->spr[SPR_40x_PID] = tlb->PID;
2569 void do_4xx_tlbre_hi (void)
2574 tlb = &env->tlb[T0].tlbe;
2576 if (tlb->prot & PAGE_EXEC)
2578 if (tlb->prot & PAGE_WRITE)
2582 void do_4xx_tlbwe_hi (void)
2585 target_ulong page, end;
2587 #if defined (DEBUG_SOFTWARE_TLB)
2588 if (loglevel != 0) {
2589 fprintf(logfile, "%s T0 " TDX " T1 " TDX "\n", __func__, T0, T1);
2593 tlb = &env->tlb[T0].tlbe;
2594 /* Invalidate previous TLB (if it's valid) */
2595 if (tlb->prot & PAGE_VALID) {
2596 end = tlb->EPN + tlb->size;
2597 #if defined (DEBUG_SOFTWARE_TLB)
2598 if (loglevel != 0) {
2599 fprintf(logfile, "%s: invalidate old TLB %d start " ADDRX
2600 " end " ADDRX "\n", __func__, (int)T0, tlb->EPN, end);
2603 for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
2604 tlb_flush_page(env, page);
2606 tlb->size = booke_tlb_to_page_size((T1 >> 7) & 0x7);
2607 /* We cannot handle TLB size < TARGET_PAGE_SIZE.
2608 * If this ever occurs, one should use the ppcemb target instead
2609 * of the ppc or ppc64 one
2611 if ((T1 & 0x40) && tlb->size < TARGET_PAGE_SIZE) {
2612 cpu_abort(env, "TLB size " TARGET_FMT_lu " < %u "
2613 "are not supported (%d)\n",
2614 tlb->size, TARGET_PAGE_SIZE, (int)((T1 >> 7) & 0x7));
2616 tlb->EPN = T1 & ~(tlb->size - 1);
2618 tlb->prot |= PAGE_VALID;
2620 tlb->prot &= ~PAGE_VALID;
2622 /* XXX: TO BE FIXED */
2623 cpu_abort(env, "Little-endian TLB entries are not supported by now\n");
2625 tlb->PID = env->spr[SPR_40x_PID]; /* PID */
2626 tlb->attr = T1 & 0xFF;
2627 #if defined (DEBUG_SOFTWARE_TLB)
2628 if (loglevel != 0) {
2629 fprintf(logfile, "%s: set up TLB %d RPN " PADDRX " EPN " ADDRX
2630 " size " ADDRX " prot %c%c%c%c PID %d\n", __func__,
2631 (int)T0, tlb->RPN, tlb->EPN, tlb->size,
2632 tlb->prot & PAGE_READ ? 'r' : '-',
2633 tlb->prot & PAGE_WRITE ? 'w' : '-',
2634 tlb->prot & PAGE_EXEC ? 'x' : '-',
2635 tlb->prot & PAGE_VALID ? 'v' : '-', (int)tlb->PID);
2638 /* Invalidate new TLB (if valid) */
2639 if (tlb->prot & PAGE_VALID) {
2640 end = tlb->EPN + tlb->size;
2641 #if defined (DEBUG_SOFTWARE_TLB)
2642 if (loglevel != 0) {
2643 fprintf(logfile, "%s: invalidate TLB %d start " ADDRX
2644 " end " ADDRX "\n", __func__, (int)T0, tlb->EPN, end);
2647 for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
2648 tlb_flush_page(env, page);
2652 void do_4xx_tlbwe_lo (void)
2656 #if defined (DEBUG_SOFTWARE_TLB)
2657 if (loglevel != 0) {
2658 fprintf(logfile, "%s T0 " TDX " T1 " TDX "\n", __func__, T0, T1);
2662 tlb = &env->tlb[T0].tlbe;
2663 tlb->RPN = T1 & 0xFFFFFC00;
2664 tlb->prot = PAGE_READ;
2666 tlb->prot |= PAGE_EXEC;
2668 tlb->prot |= PAGE_WRITE;
2669 #if defined (DEBUG_SOFTWARE_TLB)
2670 if (loglevel != 0) {
2671 fprintf(logfile, "%s: set up TLB %d RPN " PADDRX " EPN " ADDRX
2672 " size " ADDRX " prot %c%c%c%c PID %d\n", __func__,
2673 (int)T0, tlb->RPN, tlb->EPN, tlb->size,
2674 tlb->prot & PAGE_READ ? 'r' : '-',
2675 tlb->prot & PAGE_WRITE ? 'w' : '-',
2676 tlb->prot & PAGE_EXEC ? 'x' : '-',
2677 tlb->prot & PAGE_VALID ? 'v' : '-', (int)tlb->PID);
2682 /* PowerPC 440 TLB management */
2683 void do_440_tlbwe (int word)
2686 target_ulong EPN, RPN, size;
2689 #if defined (DEBUG_SOFTWARE_TLB)
2690 if (loglevel != 0) {
2691 fprintf(logfile, "%s word %d T0 " TDX " T1 " TDX "\n",
2692 __func__, word, T0, T1);
2697 tlb = &env->tlb[T0].tlbe;
2700 /* Just here to please gcc */
2702 EPN = T1 & 0xFFFFFC00;
2703 if ((tlb->prot & PAGE_VALID) && EPN != tlb->EPN)
2706 size = booke_tlb_to_page_size((T1 >> 4) & 0xF);
2707 if ((tlb->prot & PAGE_VALID) && tlb->size < size)
2711 tlb->attr |= (T1 >> 8) & 1;
2713 tlb->prot |= PAGE_VALID;
2715 if (tlb->prot & PAGE_VALID) {
2716 tlb->prot &= ~PAGE_VALID;
2720 tlb->PID = env->spr[SPR_440_MMUCR] & 0x000000FF;
2725 RPN = T1 & 0xFFFFFC0F;
2726 if ((tlb->prot & PAGE_VALID) && tlb->RPN != RPN)
2731 tlb->attr = (tlb->attr & 0x1) | (T1 & 0x0000FF00);
2732 tlb->prot = tlb->prot & PAGE_VALID;
2734 tlb->prot |= PAGE_READ << 4;
2736 tlb->prot |= PAGE_WRITE << 4;
2738 tlb->prot |= PAGE_EXEC << 4;
2740 tlb->prot |= PAGE_READ;
2742 tlb->prot |= PAGE_WRITE;
2744 tlb->prot |= PAGE_EXEC;
2749 void do_440_tlbre (int word)
2755 tlb = &env->tlb[T0].tlbe;
2758 /* Just here to please gcc */
2761 size = booke_page_size_to_tlb(tlb->size);
2762 if (size < 0 || size > 0xF)
2765 if (tlb->attr & 0x1)
2767 if (tlb->prot & PAGE_VALID)
2769 env->spr[SPR_440_MMUCR] &= ~0x000000FF;
2770 env->spr[SPR_440_MMUCR] |= tlb->PID;
2776 T0 = tlb->attr & ~0x1;
2777 if (tlb->prot & (PAGE_READ << 4))
2779 if (tlb->prot & (PAGE_WRITE << 4))
2781 if (tlb->prot & (PAGE_EXEC << 4))
2783 if (tlb->prot & PAGE_READ)
2785 if (tlb->prot & PAGE_WRITE)
2787 if (tlb->prot & PAGE_EXEC)
2792 #endif /* !CONFIG_USER_ONLY */