2 * Alpha emulation cpu micro-operations helpers for qemu.
4 * Copyright (c) 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, see <http://www.gnu.org/licenses/>.
21 #include "host-utils.h"
22 #include "softfloat.h"
25 void helper_tb_flush (void)
30 /*****************************************************************************/
31 /* Exceptions processing helpers */
32 void helper_excp (int excp
, int error
)
34 env
->exception_index
= excp
;
35 env
->error_code
= error
;
39 uint64_t helper_load_pcc (void)
45 uint64_t helper_load_fpcr (void)
48 #ifdef CONFIG_SOFTFLOAT
49 ret
|= env
->fp_status
.float_exception_flags
<< 52;
50 if (env
->fp_status
.float_exception_flags
)
52 env
->ipr
[IPR_EXC_SUM
] &= ~0x3E:
53 env
->ipr
[IPR_EXC_SUM
] |= env
->fp_status
.float_exception_flags
<< 1;
55 switch (env
->fp_status
.float_rounding_mode
) {
56 case float_round_nearest_even
:
59 case float_round_down
:
65 case float_round_to_zero
:
71 void helper_store_fpcr (uint64_t val
)
73 #ifdef CONFIG_SOFTFLOAT
74 set_float_exception_flags((val
>> 52) & 0x3F, &FP_STATUS
);
76 switch ((val
>> 58) & 3) {
78 set_float_rounding_mode(float_round_to_zero
, &FP_STATUS
);
81 set_float_rounding_mode(float_round_down
, &FP_STATUS
);
84 set_float_rounding_mode(float_round_nearest_even
, &FP_STATUS
);
87 set_float_rounding_mode(float_round_up
, &FP_STATUS
);
92 spinlock_t intr_cpu_lock
= SPIN_LOCK_UNLOCKED
;
94 uint64_t helper_rs(void)
98 spin_lock(&intr_cpu_lock
);
101 spin_unlock(&intr_cpu_lock
);
106 uint64_t helper_rc(void)
110 spin_lock(&intr_cpu_lock
);
111 tmp
= env
->intr_flag
;
113 spin_unlock(&intr_cpu_lock
);
118 uint64_t helper_addqv (uint64_t op1
, uint64_t op2
)
122 if (unlikely((tmp
^ op2
^ (-1ULL)) & (tmp
^ op1
) & (1ULL << 63))) {
123 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
128 uint64_t helper_addlv (uint64_t op1
, uint64_t op2
)
131 op1
= (uint32_t)(op1
+ op2
);
132 if (unlikely((tmp
^ op2
^ (-1UL)) & (tmp
^ op1
) & (1UL << 31))) {
133 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
138 uint64_t helper_subqv (uint64_t op1
, uint64_t op2
)
142 if (unlikely((op1
^ op2
) & (res
^ op1
) & (1ULL << 63))) {
143 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
148 uint64_t helper_sublv (uint64_t op1
, uint64_t op2
)
152 if (unlikely((op1
^ op2
) & (res
^ op1
) & (1UL << 31))) {
153 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
158 uint64_t helper_mullv (uint64_t op1
, uint64_t op2
)
160 int64_t res
= (int64_t)op1
* (int64_t)op2
;
162 if (unlikely((int32_t)res
!= res
)) {
163 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
165 return (int64_t)((int32_t)res
);
168 uint64_t helper_mulqv (uint64_t op1
, uint64_t op2
)
172 muls64(&tl
, &th
, op1
, op2
);
173 /* If th != 0 && th != -1, then we had an overflow */
174 if (unlikely((th
+ 1) > 1)) {
175 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
180 uint64_t helper_umulh (uint64_t op1
, uint64_t op2
)
184 mulu64(&tl
, &th
, op1
, op2
);
188 uint64_t helper_ctpop (uint64_t arg
)
193 uint64_t helper_ctlz (uint64_t arg
)
198 uint64_t helper_cttz (uint64_t arg
)
203 static inline uint64_t byte_zap(uint64_t op
, uint8_t mskb
)
208 mask
|= ((mskb
>> 0) & 1) * 0x00000000000000FFULL
;
209 mask
|= ((mskb
>> 1) & 1) * 0x000000000000FF00ULL
;
210 mask
|= ((mskb
>> 2) & 1) * 0x0000000000FF0000ULL
;
211 mask
|= ((mskb
>> 3) & 1) * 0x00000000FF000000ULL
;
212 mask
|= ((mskb
>> 4) & 1) * 0x000000FF00000000ULL
;
213 mask
|= ((mskb
>> 5) & 1) * 0x0000FF0000000000ULL
;
214 mask
|= ((mskb
>> 6) & 1) * 0x00FF000000000000ULL
;
215 mask
|= ((mskb
>> 7) & 1) * 0xFF00000000000000ULL
;
220 uint64_t helper_mskbl(uint64_t val
, uint64_t mask
)
222 return byte_zap(val
, 0x01 << (mask
& 7));
225 uint64_t helper_insbl(uint64_t val
, uint64_t mask
)
227 val
<<= (mask
& 7) * 8;
228 return byte_zap(val
, ~(0x01 << (mask
& 7)));
231 uint64_t helper_mskwl(uint64_t val
, uint64_t mask
)
233 return byte_zap(val
, 0x03 << (mask
& 7));
236 uint64_t helper_inswl(uint64_t val
, uint64_t mask
)
238 val
<<= (mask
& 7) * 8;
239 return byte_zap(val
, ~(0x03 << (mask
& 7)));
242 uint64_t helper_mskll(uint64_t val
, uint64_t mask
)
244 return byte_zap(val
, 0x0F << (mask
& 7));
247 uint64_t helper_insll(uint64_t val
, uint64_t mask
)
249 val
<<= (mask
& 7) * 8;
250 return byte_zap(val
, ~(0x0F << (mask
& 7)));
253 uint64_t helper_zap(uint64_t val
, uint64_t mask
)
255 return byte_zap(val
, mask
);
258 uint64_t helper_zapnot(uint64_t val
, uint64_t mask
)
260 return byte_zap(val
, ~mask
);
263 uint64_t helper_mskql(uint64_t val
, uint64_t mask
)
265 return byte_zap(val
, 0xFF << (mask
& 7));
268 uint64_t helper_insql(uint64_t val
, uint64_t mask
)
270 val
<<= (mask
& 7) * 8;
271 return byte_zap(val
, ~(0xFF << (mask
& 7)));
274 uint64_t helper_mskwh(uint64_t val
, uint64_t mask
)
276 return byte_zap(val
, (0x03 << (mask
& 7)) >> 8);
279 uint64_t helper_inswh(uint64_t val
, uint64_t mask
)
281 val
>>= 64 - ((mask
& 7) * 8);
282 return byte_zap(val
, ~((0x03 << (mask
& 7)) >> 8));
285 uint64_t helper_msklh(uint64_t val
, uint64_t mask
)
287 return byte_zap(val
, (0x0F << (mask
& 7)) >> 8);
290 uint64_t helper_inslh(uint64_t val
, uint64_t mask
)
292 val
>>= 64 - ((mask
& 7) * 8);
293 return byte_zap(val
, ~((0x0F << (mask
& 7)) >> 8));
296 uint64_t helper_mskqh(uint64_t val
, uint64_t mask
)
298 return byte_zap(val
, (0xFF << (mask
& 7)) >> 8);
301 uint64_t helper_insqh(uint64_t val
, uint64_t mask
)
303 val
>>= 64 - ((mask
& 7) * 8);
304 return byte_zap(val
, ~((0xFF << (mask
& 7)) >> 8));
307 uint64_t helper_cmpbge (uint64_t op1
, uint64_t op2
)
309 uint8_t opa
, opb
, res
;
313 for (i
= 0; i
< 8; i
++) {
314 opa
= op1
>> (i
* 8);
315 opb
= op2
>> (i
* 8);
322 /* Floating point helpers */
324 /* F floating (VAX) */
325 static inline uint64_t float32_to_f(float32 fa
)
327 uint64_t r
, exp
, mant
, sig
;
331 sig
= ((uint64_t)a
.l
& 0x80000000) << 32;
332 exp
= (a
.l
>> 23) & 0xff;
333 mant
= ((uint64_t)a
.l
& 0x007fffff) << 29;
336 /* NaN or infinity */
337 r
= 1; /* VAX dirty zero */
338 } else if (exp
== 0) {
344 r
= sig
| ((exp
+ 1) << 52) | mant
;
349 r
= 1; /* VAX dirty zero */
351 r
= sig
| ((exp
+ 2) << 52);
358 static inline float32
f_to_float32(uint64_t a
)
360 uint32_t exp
, mant_sig
;
363 exp
= ((a
>> 55) & 0x80) | ((a
>> 52) & 0x7f);
364 mant_sig
= ((a
>> 32) & 0x80000000) | ((a
>> 29) & 0x007fffff);
366 if (unlikely(!exp
&& mant_sig
)) {
367 /* Reserved operands / Dirty zero */
368 helper_excp(EXCP_OPCDEC
, 0);
375 r
.l
= ((exp
- 2) << 23) | mant_sig
;
381 uint32_t helper_f_to_memory (uint64_t a
)
384 r
= (a
& 0x00001fffe0000000ull
) >> 13;
385 r
|= (a
& 0x07ffe00000000000ull
) >> 45;
386 r
|= (a
& 0xc000000000000000ull
) >> 48;
390 uint64_t helper_memory_to_f (uint32_t a
)
393 r
= ((uint64_t)(a
& 0x0000c000)) << 48;
394 r
|= ((uint64_t)(a
& 0x003fffff)) << 45;
395 r
|= ((uint64_t)(a
& 0xffff0000)) << 13;
396 if (!(a
& 0x00004000))
401 uint64_t helper_addf (uint64_t a
, uint64_t b
)
405 fa
= f_to_float32(a
);
406 fb
= f_to_float32(b
);
407 fr
= float32_add(fa
, fb
, &FP_STATUS
);
408 return float32_to_f(fr
);
411 uint64_t helper_subf (uint64_t a
, uint64_t b
)
415 fa
= f_to_float32(a
);
416 fb
= f_to_float32(b
);
417 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
418 return float32_to_f(fr
);
421 uint64_t helper_mulf (uint64_t a
, uint64_t b
)
425 fa
= f_to_float32(a
);
426 fb
= f_to_float32(b
);
427 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
428 return float32_to_f(fr
);
431 uint64_t helper_divf (uint64_t a
, uint64_t b
)
435 fa
= f_to_float32(a
);
436 fb
= f_to_float32(b
);
437 fr
= float32_div(fa
, fb
, &FP_STATUS
);
438 return float32_to_f(fr
);
441 uint64_t helper_sqrtf (uint64_t t
)
445 ft
= f_to_float32(t
);
446 fr
= float32_sqrt(ft
, &FP_STATUS
);
447 return float32_to_f(fr
);
451 /* G floating (VAX) */
452 static inline uint64_t float64_to_g(float64 fa
)
454 uint64_t r
, exp
, mant
, sig
;
458 sig
= a
.ll
& 0x8000000000000000ull
;
459 exp
= (a
.ll
>> 52) & 0x7ff;
460 mant
= a
.ll
& 0x000fffffffffffffull
;
463 /* NaN or infinity */
464 r
= 1; /* VAX dirty zero */
465 } else if (exp
== 0) {
471 r
= sig
| ((exp
+ 1) << 52) | mant
;
476 r
= 1; /* VAX dirty zero */
478 r
= sig
| ((exp
+ 2) << 52);
485 static inline float64
g_to_float64(uint64_t a
)
487 uint64_t exp
, mant_sig
;
490 exp
= (a
>> 52) & 0x7ff;
491 mant_sig
= a
& 0x800fffffffffffffull
;
493 if (!exp
&& mant_sig
) {
494 /* Reserved operands / Dirty zero */
495 helper_excp(EXCP_OPCDEC
, 0);
502 r
.ll
= ((exp
- 2) << 52) | mant_sig
;
508 uint64_t helper_g_to_memory (uint64_t a
)
511 r
= (a
& 0x000000000000ffffull
) << 48;
512 r
|= (a
& 0x00000000ffff0000ull
) << 16;
513 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
514 r
|= (a
& 0xffff000000000000ull
) >> 48;
518 uint64_t helper_memory_to_g (uint64_t a
)
521 r
= (a
& 0x000000000000ffffull
) << 48;
522 r
|= (a
& 0x00000000ffff0000ull
) << 16;
523 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
524 r
|= (a
& 0xffff000000000000ull
) >> 48;
528 uint64_t helper_addg (uint64_t a
, uint64_t b
)
532 fa
= g_to_float64(a
);
533 fb
= g_to_float64(b
);
534 fr
= float64_add(fa
, fb
, &FP_STATUS
);
535 return float64_to_g(fr
);
538 uint64_t helper_subg (uint64_t a
, uint64_t b
)
542 fa
= g_to_float64(a
);
543 fb
= g_to_float64(b
);
544 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
545 return float64_to_g(fr
);
548 uint64_t helper_mulg (uint64_t a
, uint64_t b
)
552 fa
= g_to_float64(a
);
553 fb
= g_to_float64(b
);
554 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
555 return float64_to_g(fr
);
558 uint64_t helper_divg (uint64_t a
, uint64_t b
)
562 fa
= g_to_float64(a
);
563 fb
= g_to_float64(b
);
564 fr
= float64_div(fa
, fb
, &FP_STATUS
);
565 return float64_to_g(fr
);
568 uint64_t helper_sqrtg (uint64_t a
)
572 fa
= g_to_float64(a
);
573 fr
= float64_sqrt(fa
, &FP_STATUS
);
574 return float64_to_g(fr
);
578 /* S floating (single) */
579 static inline uint64_t float32_to_s(float32 fa
)
586 r
= (((uint64_t)(a
.l
& 0xc0000000)) << 32) | (((uint64_t)(a
.l
& 0x3fffffff)) << 29);
587 if (((a
.l
& 0x7f800000) != 0x7f800000) && (!(a
.l
& 0x40000000)))
592 static inline float32
s_to_float32(uint64_t a
)
595 r
.l
= ((a
>> 32) & 0xc0000000) | ((a
>> 29) & 0x3fffffff);
599 uint32_t helper_s_to_memory (uint64_t a
)
601 /* Memory format is the same as float32 */
602 float32 fa
= s_to_float32(a
);
603 return *(uint32_t*)(&fa
);
606 uint64_t helper_memory_to_s (uint32_t a
)
608 /* Memory format is the same as float32 */
609 return float32_to_s(*(float32
*)(&a
));
612 uint64_t helper_adds (uint64_t a
, uint64_t b
)
616 fa
= s_to_float32(a
);
617 fb
= s_to_float32(b
);
618 fr
= float32_add(fa
, fb
, &FP_STATUS
);
619 return float32_to_s(fr
);
622 uint64_t helper_subs (uint64_t a
, uint64_t b
)
626 fa
= s_to_float32(a
);
627 fb
= s_to_float32(b
);
628 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
629 return float32_to_s(fr
);
632 uint64_t helper_muls (uint64_t a
, uint64_t b
)
636 fa
= s_to_float32(a
);
637 fb
= s_to_float32(b
);
638 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
639 return float32_to_s(fr
);
642 uint64_t helper_divs (uint64_t a
, uint64_t b
)
646 fa
= s_to_float32(a
);
647 fb
= s_to_float32(b
);
648 fr
= float32_div(fa
, fb
, &FP_STATUS
);
649 return float32_to_s(fr
);
652 uint64_t helper_sqrts (uint64_t a
)
656 fa
= s_to_float32(a
);
657 fr
= float32_sqrt(fa
, &FP_STATUS
);
658 return float32_to_s(fr
);
662 /* T floating (double) */
663 static inline float64
t_to_float64(uint64_t a
)
665 /* Memory format is the same as float64 */
671 static inline uint64_t float64_to_t(float64 fa
)
673 /* Memory format is the same as float64 */
679 uint64_t helper_addt (uint64_t a
, uint64_t b
)
683 fa
= t_to_float64(a
);
684 fb
= t_to_float64(b
);
685 fr
= float64_add(fa
, fb
, &FP_STATUS
);
686 return float64_to_t(fr
);
689 uint64_t helper_subt (uint64_t a
, uint64_t b
)
693 fa
= t_to_float64(a
);
694 fb
= t_to_float64(b
);
695 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
696 return float64_to_t(fr
);
699 uint64_t helper_mult (uint64_t a
, uint64_t b
)
703 fa
= t_to_float64(a
);
704 fb
= t_to_float64(b
);
705 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
706 return float64_to_t(fr
);
709 uint64_t helper_divt (uint64_t a
, uint64_t b
)
713 fa
= t_to_float64(a
);
714 fb
= t_to_float64(b
);
715 fr
= float64_div(fa
, fb
, &FP_STATUS
);
716 return float64_to_t(fr
);
719 uint64_t helper_sqrtt (uint64_t a
)
723 fa
= t_to_float64(a
);
724 fr
= float64_sqrt(fa
, &FP_STATUS
);
725 return float64_to_t(fr
);
730 uint64_t helper_cpys(uint64_t a
, uint64_t b
)
732 return (a
& 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
735 uint64_t helper_cpysn(uint64_t a
, uint64_t b
)
737 return ((~a
) & 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
740 uint64_t helper_cpyse(uint64_t a
, uint64_t b
)
742 return (a
& 0xFFF0000000000000ULL
) | (b
& ~0xFFF0000000000000ULL
);
747 uint64_t helper_cmptun (uint64_t a
, uint64_t b
)
751 fa
= t_to_float64(a
);
752 fb
= t_to_float64(b
);
754 if (float64_is_nan(fa
) || float64_is_nan(fb
))
755 return 0x4000000000000000ULL
;
760 uint64_t helper_cmpteq(uint64_t a
, uint64_t b
)
764 fa
= t_to_float64(a
);
765 fb
= t_to_float64(b
);
767 if (float64_eq(fa
, fb
, &FP_STATUS
))
768 return 0x4000000000000000ULL
;
773 uint64_t helper_cmptle(uint64_t a
, uint64_t b
)
777 fa
= t_to_float64(a
);
778 fb
= t_to_float64(b
);
780 if (float64_le(fa
, fb
, &FP_STATUS
))
781 return 0x4000000000000000ULL
;
786 uint64_t helper_cmptlt(uint64_t a
, uint64_t b
)
790 fa
= t_to_float64(a
);
791 fb
= t_to_float64(b
);
793 if (float64_lt(fa
, fb
, &FP_STATUS
))
794 return 0x4000000000000000ULL
;
799 uint64_t helper_cmpgeq(uint64_t a
, uint64_t b
)
803 fa
= g_to_float64(a
);
804 fb
= g_to_float64(b
);
806 if (float64_eq(fa
, fb
, &FP_STATUS
))
807 return 0x4000000000000000ULL
;
812 uint64_t helper_cmpgle(uint64_t a
, uint64_t b
)
816 fa
= g_to_float64(a
);
817 fb
= g_to_float64(b
);
819 if (float64_le(fa
, fb
, &FP_STATUS
))
820 return 0x4000000000000000ULL
;
825 uint64_t helper_cmpglt(uint64_t a
, uint64_t b
)
829 fa
= g_to_float64(a
);
830 fb
= g_to_float64(b
);
832 if (float64_lt(fa
, fb
, &FP_STATUS
))
833 return 0x4000000000000000ULL
;
838 uint64_t helper_cmpfeq (uint64_t a
)
840 return !(a
& 0x7FFFFFFFFFFFFFFFULL
);
843 uint64_t helper_cmpfne (uint64_t a
)
845 return (a
& 0x7FFFFFFFFFFFFFFFULL
);
848 uint64_t helper_cmpflt (uint64_t a
)
850 return (a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
853 uint64_t helper_cmpfle (uint64_t a
)
855 return (a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
858 uint64_t helper_cmpfgt (uint64_t a
)
860 return !(a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
863 uint64_t helper_cmpfge (uint64_t a
)
865 return !(a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
869 /* Floating point format conversion */
870 uint64_t helper_cvtts (uint64_t a
)
875 fa
= t_to_float64(a
);
876 fr
= float64_to_float32(fa
, &FP_STATUS
);
877 return float32_to_s(fr
);
880 uint64_t helper_cvtst (uint64_t a
)
885 fa
= s_to_float32(a
);
886 fr
= float32_to_float64(fa
, &FP_STATUS
);
887 return float64_to_t(fr
);
890 uint64_t helper_cvtqs (uint64_t a
)
892 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
893 return float32_to_s(fr
);
896 uint64_t helper_cvttq (uint64_t a
)
898 float64 fa
= t_to_float64(a
);
899 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
902 uint64_t helper_cvtqt (uint64_t a
)
904 float64 fr
= int64_to_float64(a
, &FP_STATUS
);
905 return float64_to_t(fr
);
908 uint64_t helper_cvtqf (uint64_t a
)
910 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
911 return float32_to_f(fr
);
914 uint64_t helper_cvtgf (uint64_t a
)
919 fa
= g_to_float64(a
);
920 fr
= float64_to_float32(fa
, &FP_STATUS
);
921 return float32_to_f(fr
);
924 uint64_t helper_cvtgq (uint64_t a
)
926 float64 fa
= g_to_float64(a
);
927 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
930 uint64_t helper_cvtqg (uint64_t a
)
933 fr
= int64_to_float64(a
, &FP_STATUS
);
934 return float64_to_g(fr
);
937 uint64_t helper_cvtlq (uint64_t a
)
939 return (int64_t)((int32_t)((a
>> 32) | ((a
>> 29) & 0x3FFFFFFF)));
942 static inline uint64_t __helper_cvtql(uint64_t a
, int s
, int v
)
946 r
= ((uint64_t)(a
& 0xC0000000)) << 32;
947 r
|= ((uint64_t)(a
& 0x7FFFFFFF)) << 29;
949 if (v
&& (int64_t)((int32_t)r
) != (int64_t)r
) {
950 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
958 uint64_t helper_cvtql (uint64_t a
)
960 return __helper_cvtql(a
, 0, 0);
963 uint64_t helper_cvtqlv (uint64_t a
)
965 return __helper_cvtql(a
, 0, 1);
968 uint64_t helper_cvtqlsv (uint64_t a
)
970 return __helper_cvtql(a
, 1, 1);
973 /* PALcode support special instructions */
974 #if !defined (CONFIG_USER_ONLY)
975 void helper_hw_rei (void)
977 env
->pc
= env
->ipr
[IPR_EXC_ADDR
] & ~3;
978 env
->ipr
[IPR_EXC_ADDR
] = env
->ipr
[IPR_EXC_ADDR
] & 1;
979 /* XXX: re-enable interrupts and memory mapping */
982 void helper_hw_ret (uint64_t a
)
985 env
->ipr
[IPR_EXC_ADDR
] = a
& 1;
986 /* XXX: re-enable interrupts and memory mapping */
989 uint64_t helper_mfpr (int iprn
, uint64_t val
)
993 if (cpu_alpha_mfpr(env
, iprn
, &tmp
) == 0)
999 void helper_mtpr (int iprn
, uint64_t val
)
1001 cpu_alpha_mtpr(env
, iprn
, val
, NULL
);
1004 void helper_set_alt_mode (void)
1006 env
->saved_mode
= env
->ps
& 0xC;
1007 env
->ps
= (env
->ps
& ~0xC) | (env
->ipr
[IPR_ALT_MODE
] & 0xC);
1010 void helper_restore_mode (void)
1012 env
->ps
= (env
->ps
& ~0xC) | env
->saved_mode
;
1017 /*****************************************************************************/
1018 /* Softmmu support */
1019 #if !defined (CONFIG_USER_ONLY)
1021 /* XXX: the two following helpers are pure hacks.
1022 * Hopefully, we emulate the PALcode, then we should never see
1023 * HW_LD / HW_ST instructions.
1025 uint64_t helper_ld_virt_to_phys (uint64_t virtaddr
)
1027 uint64_t tlb_addr
, physaddr
;
1031 mmu_idx
= cpu_mmu_index(env
);
1032 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1034 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_read
;
1035 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1036 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1037 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1039 /* the page is not in the TLB : fill it */
1041 tlb_fill(virtaddr
, 0, mmu_idx
, retaddr
);
1047 uint64_t helper_st_virt_to_phys (uint64_t virtaddr
)
1049 uint64_t tlb_addr
, physaddr
;
1053 mmu_idx
= cpu_mmu_index(env
);
1054 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1056 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_write
;
1057 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1058 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1059 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1061 /* the page is not in the TLB : fill it */
1063 tlb_fill(virtaddr
, 1, mmu_idx
, retaddr
);
1069 void helper_ldl_raw(uint64_t t0
, uint64_t t1
)
1074 void helper_ldq_raw(uint64_t t0
, uint64_t t1
)
1079 void helper_ldl_l_raw(uint64_t t0
, uint64_t t1
)
1085 void helper_ldq_l_raw(uint64_t t0
, uint64_t t1
)
1091 void helper_ldl_kernel(uint64_t t0
, uint64_t t1
)
1096 void helper_ldq_kernel(uint64_t t0
, uint64_t t1
)
1101 void helper_ldl_data(uint64_t t0
, uint64_t t1
)
1106 void helper_ldq_data(uint64_t t0
, uint64_t t1
)
1111 void helper_stl_raw(uint64_t t0
, uint64_t t1
)
1116 void helper_stq_raw(uint64_t t0
, uint64_t t1
)
1121 uint64_t helper_stl_c_raw(uint64_t t0
, uint64_t t1
)
1125 if (t1
== env
->lock
) {
1136 uint64_t helper_stq_c_raw(uint64_t t0
, uint64_t t1
)
1140 if (t1
== env
->lock
) {
1151 #define MMUSUFFIX _mmu
1154 #include "softmmu_template.h"
1157 #include "softmmu_template.h"
1160 #include "softmmu_template.h"
1163 #include "softmmu_template.h"
1165 /* try to fill the TLB and return an exception if error. If retaddr is
1166 NULL, it means that the function was called in C code (i.e. not
1167 from generated code or from helper.c) */
1168 /* XXX: fix it to restore all registers */
1169 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
1171 TranslationBlock
*tb
;
1172 CPUState
*saved_env
;
1176 /* XXX: hack to restore env in all cases, even if not called from
1179 env
= cpu_single_env
;
1180 ret
= cpu_alpha_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
1181 if (!likely(ret
== 0)) {
1182 if (likely(retaddr
)) {
1183 /* now we have a real cpu fault */
1184 pc
= (unsigned long)retaddr
;
1185 tb
= tb_find_pc(pc
);
1187 /* the PC is inside the translated code. It means that we have
1188 a virtual CPU fault */
1189 cpu_restore_state(tb
, env
, pc
, NULL
);
1192 /* Exception index and error code are already set */