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 /*****************************************************************************/
26 /* Exceptions processing helpers */
27 void helper_excp (int excp
, int error
)
29 env
->exception_index
= excp
;
30 env
->error_code
= error
;
34 uint64_t helper_load_pcc (void)
40 uint64_t helper_load_fpcr (void)
42 return cpu_alpha_load_fpcr (env
);
45 void helper_store_fpcr (uint64_t val
)
47 cpu_alpha_store_fpcr (env
, val
);
50 static spinlock_t intr_cpu_lock
= SPIN_LOCK_UNLOCKED
;
52 uint64_t helper_rs(void)
56 spin_lock(&intr_cpu_lock
);
59 spin_unlock(&intr_cpu_lock
);
64 uint64_t helper_rc(void)
68 spin_lock(&intr_cpu_lock
);
71 spin_unlock(&intr_cpu_lock
);
76 uint64_t helper_addqv (uint64_t op1
, uint64_t op2
)
80 if (unlikely((tmp
^ op2
^ (-1ULL)) & (tmp
^ op1
) & (1ULL << 63))) {
81 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
86 uint64_t helper_addlv (uint64_t op1
, uint64_t op2
)
89 op1
= (uint32_t)(op1
+ op2
);
90 if (unlikely((tmp
^ op2
^ (-1UL)) & (tmp
^ op1
) & (1UL << 31))) {
91 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
96 uint64_t helper_subqv (uint64_t op1
, uint64_t op2
)
100 if (unlikely((op1
^ op2
) & (res
^ op1
) & (1ULL << 63))) {
101 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
106 uint64_t helper_sublv (uint64_t op1
, uint64_t op2
)
110 if (unlikely((op1
^ op2
) & (res
^ op1
) & (1UL << 31))) {
111 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
116 uint64_t helper_mullv (uint64_t op1
, uint64_t op2
)
118 int64_t res
= (int64_t)op1
* (int64_t)op2
;
120 if (unlikely((int32_t)res
!= res
)) {
121 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
123 return (int64_t)((int32_t)res
);
126 uint64_t helper_mulqv (uint64_t op1
, uint64_t op2
)
130 muls64(&tl
, &th
, op1
, op2
);
131 /* If th != 0 && th != -1, then we had an overflow */
132 if (unlikely((th
+ 1) > 1)) {
133 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
138 uint64_t helper_umulh (uint64_t op1
, uint64_t op2
)
142 mulu64(&tl
, &th
, op1
, op2
);
146 uint64_t helper_ctpop (uint64_t arg
)
151 uint64_t helper_ctlz (uint64_t arg
)
156 uint64_t helper_cttz (uint64_t arg
)
161 static inline uint64_t byte_zap(uint64_t op
, uint8_t mskb
)
166 mask
|= ((mskb
>> 0) & 1) * 0x00000000000000FFULL
;
167 mask
|= ((mskb
>> 1) & 1) * 0x000000000000FF00ULL
;
168 mask
|= ((mskb
>> 2) & 1) * 0x0000000000FF0000ULL
;
169 mask
|= ((mskb
>> 3) & 1) * 0x00000000FF000000ULL
;
170 mask
|= ((mskb
>> 4) & 1) * 0x000000FF00000000ULL
;
171 mask
|= ((mskb
>> 5) & 1) * 0x0000FF0000000000ULL
;
172 mask
|= ((mskb
>> 6) & 1) * 0x00FF000000000000ULL
;
173 mask
|= ((mskb
>> 7) & 1) * 0xFF00000000000000ULL
;
178 uint64_t helper_zap(uint64_t val
, uint64_t mask
)
180 return byte_zap(val
, mask
);
183 uint64_t helper_zapnot(uint64_t val
, uint64_t mask
)
185 return byte_zap(val
, ~mask
);
188 uint64_t helper_cmpbge (uint64_t op1
, uint64_t op2
)
190 uint8_t opa
, opb
, res
;
194 for (i
= 0; i
< 8; i
++) {
195 opa
= op1
>> (i
* 8);
196 opb
= op2
>> (i
* 8);
203 uint64_t helper_minub8 (uint64_t op1
, uint64_t op2
)
206 uint8_t opa
, opb
, opr
;
209 for (i
= 0; i
< 8; ++i
) {
210 opa
= op1
>> (i
* 8);
211 opb
= op2
>> (i
* 8);
212 opr
= opa
< opb
? opa
: opb
;
213 res
|= (uint64_t)opr
<< (i
* 8);
218 uint64_t helper_minsb8 (uint64_t op1
, uint64_t op2
)
225 for (i
= 0; i
< 8; ++i
) {
226 opa
= op1
>> (i
* 8);
227 opb
= op2
>> (i
* 8);
228 opr
= opa
< opb
? opa
: opb
;
229 res
|= (uint64_t)opr
<< (i
* 8);
234 uint64_t helper_minuw4 (uint64_t op1
, uint64_t op2
)
237 uint16_t opa
, opb
, opr
;
240 for (i
= 0; i
< 4; ++i
) {
241 opa
= op1
>> (i
* 16);
242 opb
= op2
>> (i
* 16);
243 opr
= opa
< opb
? opa
: opb
;
244 res
|= (uint64_t)opr
<< (i
* 16);
249 uint64_t helper_minsw4 (uint64_t op1
, uint64_t op2
)
256 for (i
= 0; i
< 4; ++i
) {
257 opa
= op1
>> (i
* 16);
258 opb
= op2
>> (i
* 16);
259 opr
= opa
< opb
? opa
: opb
;
260 res
|= (uint64_t)opr
<< (i
* 16);
265 uint64_t helper_maxub8 (uint64_t op1
, uint64_t op2
)
268 uint8_t opa
, opb
, opr
;
271 for (i
= 0; i
< 8; ++i
) {
272 opa
= op1
>> (i
* 8);
273 opb
= op2
>> (i
* 8);
274 opr
= opa
> opb
? opa
: opb
;
275 res
|= (uint64_t)opr
<< (i
* 8);
280 uint64_t helper_maxsb8 (uint64_t op1
, uint64_t op2
)
287 for (i
= 0; i
< 8; ++i
) {
288 opa
= op1
>> (i
* 8);
289 opb
= op2
>> (i
* 8);
290 opr
= opa
> opb
? opa
: opb
;
291 res
|= (uint64_t)opr
<< (i
* 8);
296 uint64_t helper_maxuw4 (uint64_t op1
, uint64_t op2
)
299 uint16_t opa
, opb
, opr
;
302 for (i
= 0; i
< 4; ++i
) {
303 opa
= op1
>> (i
* 16);
304 opb
= op2
>> (i
* 16);
305 opr
= opa
> opb
? opa
: opb
;
306 res
|= (uint64_t)opr
<< (i
* 16);
311 uint64_t helper_maxsw4 (uint64_t op1
, uint64_t op2
)
318 for (i
= 0; i
< 4; ++i
) {
319 opa
= op1
>> (i
* 16);
320 opb
= op2
>> (i
* 16);
321 opr
= opa
> opb
? opa
: opb
;
322 res
|= (uint64_t)opr
<< (i
* 16);
327 uint64_t helper_perr (uint64_t op1
, uint64_t op2
)
330 uint8_t opa
, opb
, opr
;
333 for (i
= 0; i
< 8; ++i
) {
334 opa
= op1
>> (i
* 8);
335 opb
= op2
>> (i
* 8);
345 uint64_t helper_pklb (uint64_t op1
)
347 return (op1
& 0xff) | ((op1
>> 24) & 0xff00);
350 uint64_t helper_pkwb (uint64_t op1
)
353 | ((op1
>> 8) & 0xff00)
354 | ((op1
>> 16) & 0xff0000)
355 | ((op1
>> 24) & 0xff000000));
358 uint64_t helper_unpkbl (uint64_t op1
)
360 return (op1
& 0xff) | ((op1
& 0xff00) << 24);
363 uint64_t helper_unpkbw (uint64_t op1
)
366 | ((op1
& 0xff00) << 8)
367 | ((op1
& 0xff0000) << 16)
368 | ((op1
& 0xff000000) << 24));
371 /* Floating point helpers */
373 /* F floating (VAX) */
374 static inline uint64_t float32_to_f(float32 fa
)
376 uint64_t r
, exp
, mant
, sig
;
380 sig
= ((uint64_t)a
.l
& 0x80000000) << 32;
381 exp
= (a
.l
>> 23) & 0xff;
382 mant
= ((uint64_t)a
.l
& 0x007fffff) << 29;
385 /* NaN or infinity */
386 r
= 1; /* VAX dirty zero */
387 } else if (exp
== 0) {
393 r
= sig
| ((exp
+ 1) << 52) | mant
;
398 r
= 1; /* VAX dirty zero */
400 r
= sig
| ((exp
+ 2) << 52);
407 static inline float32
f_to_float32(uint64_t a
)
409 uint32_t exp
, mant_sig
;
412 exp
= ((a
>> 55) & 0x80) | ((a
>> 52) & 0x7f);
413 mant_sig
= ((a
>> 32) & 0x80000000) | ((a
>> 29) & 0x007fffff);
415 if (unlikely(!exp
&& mant_sig
)) {
416 /* Reserved operands / Dirty zero */
417 helper_excp(EXCP_OPCDEC
, 0);
424 r
.l
= ((exp
- 2) << 23) | mant_sig
;
430 uint32_t helper_f_to_memory (uint64_t a
)
433 r
= (a
& 0x00001fffe0000000ull
) >> 13;
434 r
|= (a
& 0x07ffe00000000000ull
) >> 45;
435 r
|= (a
& 0xc000000000000000ull
) >> 48;
439 uint64_t helper_memory_to_f (uint32_t a
)
442 r
= ((uint64_t)(a
& 0x0000c000)) << 48;
443 r
|= ((uint64_t)(a
& 0x003fffff)) << 45;
444 r
|= ((uint64_t)(a
& 0xffff0000)) << 13;
445 if (!(a
& 0x00004000))
450 uint64_t helper_addf (uint64_t a
, uint64_t b
)
454 fa
= f_to_float32(a
);
455 fb
= f_to_float32(b
);
456 fr
= float32_add(fa
, fb
, &FP_STATUS
);
457 return float32_to_f(fr
);
460 uint64_t helper_subf (uint64_t a
, uint64_t b
)
464 fa
= f_to_float32(a
);
465 fb
= f_to_float32(b
);
466 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
467 return float32_to_f(fr
);
470 uint64_t helper_mulf (uint64_t a
, uint64_t b
)
474 fa
= f_to_float32(a
);
475 fb
= f_to_float32(b
);
476 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
477 return float32_to_f(fr
);
480 uint64_t helper_divf (uint64_t a
, uint64_t b
)
484 fa
= f_to_float32(a
);
485 fb
= f_to_float32(b
);
486 fr
= float32_div(fa
, fb
, &FP_STATUS
);
487 return float32_to_f(fr
);
490 uint64_t helper_sqrtf (uint64_t t
)
494 ft
= f_to_float32(t
);
495 fr
= float32_sqrt(ft
, &FP_STATUS
);
496 return float32_to_f(fr
);
500 /* G floating (VAX) */
501 static inline uint64_t float64_to_g(float64 fa
)
503 uint64_t r
, exp
, mant
, sig
;
507 sig
= a
.ll
& 0x8000000000000000ull
;
508 exp
= (a
.ll
>> 52) & 0x7ff;
509 mant
= a
.ll
& 0x000fffffffffffffull
;
512 /* NaN or infinity */
513 r
= 1; /* VAX dirty zero */
514 } else if (exp
== 0) {
520 r
= sig
| ((exp
+ 1) << 52) | mant
;
525 r
= 1; /* VAX dirty zero */
527 r
= sig
| ((exp
+ 2) << 52);
534 static inline float64
g_to_float64(uint64_t a
)
536 uint64_t exp
, mant_sig
;
539 exp
= (a
>> 52) & 0x7ff;
540 mant_sig
= a
& 0x800fffffffffffffull
;
542 if (!exp
&& mant_sig
) {
543 /* Reserved operands / Dirty zero */
544 helper_excp(EXCP_OPCDEC
, 0);
551 r
.ll
= ((exp
- 2) << 52) | mant_sig
;
557 uint64_t helper_g_to_memory (uint64_t a
)
560 r
= (a
& 0x000000000000ffffull
) << 48;
561 r
|= (a
& 0x00000000ffff0000ull
) << 16;
562 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
563 r
|= (a
& 0xffff000000000000ull
) >> 48;
567 uint64_t helper_memory_to_g (uint64_t a
)
570 r
= (a
& 0x000000000000ffffull
) << 48;
571 r
|= (a
& 0x00000000ffff0000ull
) << 16;
572 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
573 r
|= (a
& 0xffff000000000000ull
) >> 48;
577 uint64_t helper_addg (uint64_t a
, uint64_t b
)
581 fa
= g_to_float64(a
);
582 fb
= g_to_float64(b
);
583 fr
= float64_add(fa
, fb
, &FP_STATUS
);
584 return float64_to_g(fr
);
587 uint64_t helper_subg (uint64_t a
, uint64_t b
)
591 fa
= g_to_float64(a
);
592 fb
= g_to_float64(b
);
593 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
594 return float64_to_g(fr
);
597 uint64_t helper_mulg (uint64_t a
, uint64_t b
)
601 fa
= g_to_float64(a
);
602 fb
= g_to_float64(b
);
603 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
604 return float64_to_g(fr
);
607 uint64_t helper_divg (uint64_t a
, uint64_t b
)
611 fa
= g_to_float64(a
);
612 fb
= g_to_float64(b
);
613 fr
= float64_div(fa
, fb
, &FP_STATUS
);
614 return float64_to_g(fr
);
617 uint64_t helper_sqrtg (uint64_t a
)
621 fa
= g_to_float64(a
);
622 fr
= float64_sqrt(fa
, &FP_STATUS
);
623 return float64_to_g(fr
);
627 /* S floating (single) */
629 /* Taken from linux/arch/alpha/kernel/traps.c, s_mem_to_reg. */
630 static inline uint64_t float32_to_s_int(uint32_t fi
)
632 uint32_t frac
= fi
& 0x7fffff;
633 uint32_t sign
= fi
>> 31;
634 uint32_t exp_msb
= (fi
>> 30) & 1;
635 uint32_t exp_low
= (fi
>> 23) & 0x7f;
638 exp
= (exp_msb
<< 10) | exp_low
;
647 return (((uint64_t)sign
<< 63)
648 | ((uint64_t)exp
<< 52)
649 | ((uint64_t)frac
<< 29));
652 static inline uint64_t float32_to_s(float32 fa
)
656 return float32_to_s_int(a
.l
);
659 static inline uint32_t s_to_float32_int(uint64_t a
)
661 return ((a
>> 32) & 0xc0000000) | ((a
>> 29) & 0x3fffffff);
664 static inline float32
s_to_float32(uint64_t a
)
667 r
.l
= s_to_float32_int(a
);
671 uint32_t helper_s_to_memory (uint64_t a
)
673 return s_to_float32_int(a
);
676 uint64_t helper_memory_to_s (uint32_t a
)
678 return float32_to_s_int(a
);
681 uint64_t helper_adds (uint64_t a
, uint64_t b
)
685 fa
= s_to_float32(a
);
686 fb
= s_to_float32(b
);
687 fr
= float32_add(fa
, fb
, &FP_STATUS
);
688 return float32_to_s(fr
);
691 uint64_t helper_subs (uint64_t a
, uint64_t b
)
695 fa
= s_to_float32(a
);
696 fb
= s_to_float32(b
);
697 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
698 return float32_to_s(fr
);
701 uint64_t helper_muls (uint64_t a
, uint64_t b
)
705 fa
= s_to_float32(a
);
706 fb
= s_to_float32(b
);
707 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
708 return float32_to_s(fr
);
711 uint64_t helper_divs (uint64_t a
, uint64_t b
)
715 fa
= s_to_float32(a
);
716 fb
= s_to_float32(b
);
717 fr
= float32_div(fa
, fb
, &FP_STATUS
);
718 return float32_to_s(fr
);
721 uint64_t helper_sqrts (uint64_t a
)
725 fa
= s_to_float32(a
);
726 fr
= float32_sqrt(fa
, &FP_STATUS
);
727 return float32_to_s(fr
);
731 /* T floating (double) */
732 static inline float64
t_to_float64(uint64_t a
)
734 /* Memory format is the same as float64 */
740 static inline uint64_t float64_to_t(float64 fa
)
742 /* Memory format is the same as float64 */
748 uint64_t helper_addt (uint64_t a
, uint64_t b
)
752 fa
= t_to_float64(a
);
753 fb
= t_to_float64(b
);
754 fr
= float64_add(fa
, fb
, &FP_STATUS
);
755 return float64_to_t(fr
);
758 uint64_t helper_subt (uint64_t a
, uint64_t b
)
762 fa
= t_to_float64(a
);
763 fb
= t_to_float64(b
);
764 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
765 return float64_to_t(fr
);
768 uint64_t helper_mult (uint64_t a
, uint64_t b
)
772 fa
= t_to_float64(a
);
773 fb
= t_to_float64(b
);
774 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
775 return float64_to_t(fr
);
778 uint64_t helper_divt (uint64_t a
, uint64_t b
)
782 fa
= t_to_float64(a
);
783 fb
= t_to_float64(b
);
784 fr
= float64_div(fa
, fb
, &FP_STATUS
);
785 return float64_to_t(fr
);
788 uint64_t helper_sqrtt (uint64_t a
)
792 fa
= t_to_float64(a
);
793 fr
= float64_sqrt(fa
, &FP_STATUS
);
794 return float64_to_t(fr
);
799 uint64_t helper_cpys(uint64_t a
, uint64_t b
)
801 return (a
& 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
804 uint64_t helper_cpysn(uint64_t a
, uint64_t b
)
806 return ((~a
) & 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
809 uint64_t helper_cpyse(uint64_t a
, uint64_t b
)
811 return (a
& 0xFFF0000000000000ULL
) | (b
& ~0xFFF0000000000000ULL
);
816 uint64_t helper_cmptun (uint64_t a
, uint64_t b
)
820 fa
= t_to_float64(a
);
821 fb
= t_to_float64(b
);
823 if (float64_is_nan(fa
) || float64_is_nan(fb
))
824 return 0x4000000000000000ULL
;
829 uint64_t helper_cmpteq(uint64_t a
, uint64_t b
)
833 fa
= t_to_float64(a
);
834 fb
= t_to_float64(b
);
836 if (float64_eq(fa
, fb
, &FP_STATUS
))
837 return 0x4000000000000000ULL
;
842 uint64_t helper_cmptle(uint64_t a
, uint64_t b
)
846 fa
= t_to_float64(a
);
847 fb
= t_to_float64(b
);
849 if (float64_le(fa
, fb
, &FP_STATUS
))
850 return 0x4000000000000000ULL
;
855 uint64_t helper_cmptlt(uint64_t a
, uint64_t b
)
859 fa
= t_to_float64(a
);
860 fb
= t_to_float64(b
);
862 if (float64_lt(fa
, fb
, &FP_STATUS
))
863 return 0x4000000000000000ULL
;
868 uint64_t helper_cmpgeq(uint64_t a
, uint64_t b
)
872 fa
= g_to_float64(a
);
873 fb
= g_to_float64(b
);
875 if (float64_eq(fa
, fb
, &FP_STATUS
))
876 return 0x4000000000000000ULL
;
881 uint64_t helper_cmpgle(uint64_t a
, uint64_t b
)
885 fa
= g_to_float64(a
);
886 fb
= g_to_float64(b
);
888 if (float64_le(fa
, fb
, &FP_STATUS
))
889 return 0x4000000000000000ULL
;
894 uint64_t helper_cmpglt(uint64_t a
, uint64_t b
)
898 fa
= g_to_float64(a
);
899 fb
= g_to_float64(b
);
901 if (float64_lt(fa
, fb
, &FP_STATUS
))
902 return 0x4000000000000000ULL
;
907 /* Floating point format conversion */
908 uint64_t helper_cvtts (uint64_t a
)
913 fa
= t_to_float64(a
);
914 fr
= float64_to_float32(fa
, &FP_STATUS
);
915 return float32_to_s(fr
);
918 uint64_t helper_cvtst (uint64_t a
)
923 fa
= s_to_float32(a
);
924 fr
= float32_to_float64(fa
, &FP_STATUS
);
925 return float64_to_t(fr
);
928 uint64_t helper_cvtqs (uint64_t a
)
930 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
931 return float32_to_s(fr
);
934 uint64_t helper_cvttq (uint64_t a
)
936 float64 fa
= t_to_float64(a
);
937 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
940 uint64_t helper_cvtqt (uint64_t a
)
942 float64 fr
= int64_to_float64(a
, &FP_STATUS
);
943 return float64_to_t(fr
);
946 uint64_t helper_cvtqf (uint64_t a
)
948 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
949 return float32_to_f(fr
);
952 uint64_t helper_cvtgf (uint64_t a
)
957 fa
= g_to_float64(a
);
958 fr
= float64_to_float32(fa
, &FP_STATUS
);
959 return float32_to_f(fr
);
962 uint64_t helper_cvtgq (uint64_t a
)
964 float64 fa
= g_to_float64(a
);
965 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
968 uint64_t helper_cvtqg (uint64_t a
)
971 fr
= int64_to_float64(a
, &FP_STATUS
);
972 return float64_to_g(fr
);
975 uint64_t helper_cvtlq (uint64_t a
)
977 int32_t lo
= a
>> 29;
978 int32_t hi
= a
>> 32;
979 return (lo
& 0x3FFFFFFF) | (hi
& 0xc0000000);
982 static inline uint64_t __helper_cvtql(uint64_t a
, int s
, int v
)
986 r
= ((uint64_t)(a
& 0xC0000000)) << 32;
987 r
|= ((uint64_t)(a
& 0x7FFFFFFF)) << 29;
989 if (v
&& (int64_t)((int32_t)r
) != (int64_t)r
) {
990 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
998 uint64_t helper_cvtql (uint64_t a
)
1000 return __helper_cvtql(a
, 0, 0);
1003 uint64_t helper_cvtqlv (uint64_t a
)
1005 return __helper_cvtql(a
, 0, 1);
1008 uint64_t helper_cvtqlsv (uint64_t a
)
1010 return __helper_cvtql(a
, 1, 1);
1013 /* PALcode support special instructions */
1014 #if !defined (CONFIG_USER_ONLY)
1015 void helper_hw_rei (void)
1017 env
->pc
= env
->ipr
[IPR_EXC_ADDR
] & ~3;
1018 env
->ipr
[IPR_EXC_ADDR
] = env
->ipr
[IPR_EXC_ADDR
] & 1;
1019 /* XXX: re-enable interrupts and memory mapping */
1022 void helper_hw_ret (uint64_t a
)
1025 env
->ipr
[IPR_EXC_ADDR
] = a
& 1;
1026 /* XXX: re-enable interrupts and memory mapping */
1029 uint64_t helper_mfpr (int iprn
, uint64_t val
)
1033 if (cpu_alpha_mfpr(env
, iprn
, &tmp
) == 0)
1039 void helper_mtpr (int iprn
, uint64_t val
)
1041 cpu_alpha_mtpr(env
, iprn
, val
, NULL
);
1044 void helper_set_alt_mode (void)
1046 env
->saved_mode
= env
->ps
& 0xC;
1047 env
->ps
= (env
->ps
& ~0xC) | (env
->ipr
[IPR_ALT_MODE
] & 0xC);
1050 void helper_restore_mode (void)
1052 env
->ps
= (env
->ps
& ~0xC) | env
->saved_mode
;
1057 /*****************************************************************************/
1058 /* Softmmu support */
1059 #if !defined (CONFIG_USER_ONLY)
1061 /* XXX: the two following helpers are pure hacks.
1062 * Hopefully, we emulate the PALcode, then we should never see
1063 * HW_LD / HW_ST instructions.
1065 uint64_t helper_ld_virt_to_phys (uint64_t virtaddr
)
1067 uint64_t tlb_addr
, physaddr
;
1071 mmu_idx
= cpu_mmu_index(env
);
1072 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1074 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_read
;
1075 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1076 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1077 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1079 /* the page is not in the TLB : fill it */
1081 tlb_fill(virtaddr
, 0, mmu_idx
, retaddr
);
1087 uint64_t helper_st_virt_to_phys (uint64_t virtaddr
)
1089 uint64_t tlb_addr
, physaddr
;
1093 mmu_idx
= cpu_mmu_index(env
);
1094 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1096 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_write
;
1097 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1098 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1099 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1101 /* the page is not in the TLB : fill it */
1103 tlb_fill(virtaddr
, 1, mmu_idx
, retaddr
);
1109 void helper_ldl_raw(uint64_t t0
, uint64_t t1
)
1114 void helper_ldq_raw(uint64_t t0
, uint64_t t1
)
1119 void helper_ldl_l_raw(uint64_t t0
, uint64_t t1
)
1125 void helper_ldq_l_raw(uint64_t t0
, uint64_t t1
)
1131 void helper_ldl_kernel(uint64_t t0
, uint64_t t1
)
1136 void helper_ldq_kernel(uint64_t t0
, uint64_t t1
)
1141 void helper_ldl_data(uint64_t t0
, uint64_t t1
)
1146 void helper_ldq_data(uint64_t t0
, uint64_t t1
)
1151 void helper_stl_raw(uint64_t t0
, uint64_t t1
)
1156 void helper_stq_raw(uint64_t t0
, uint64_t t1
)
1161 uint64_t helper_stl_c_raw(uint64_t t0
, uint64_t t1
)
1165 if (t1
== env
->lock
) {
1176 uint64_t helper_stq_c_raw(uint64_t t0
, uint64_t t1
)
1180 if (t1
== env
->lock
) {
1191 #define MMUSUFFIX _mmu
1194 #include "softmmu_template.h"
1197 #include "softmmu_template.h"
1200 #include "softmmu_template.h"
1203 #include "softmmu_template.h"
1205 /* try to fill the TLB and return an exception if error. If retaddr is
1206 NULL, it means that the function was called in C code (i.e. not
1207 from generated code or from helper.c) */
1208 /* XXX: fix it to restore all registers */
1209 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
1211 TranslationBlock
*tb
;
1212 CPUState
*saved_env
;
1216 /* XXX: hack to restore env in all cases, even if not called from
1219 env
= cpu_single_env
;
1220 ret
= cpu_alpha_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
1221 if (!likely(ret
== 0)) {
1222 if (likely(retaddr
)) {
1223 /* now we have a real cpu fault */
1224 pc
= (unsigned long)retaddr
;
1225 tb
= tb_find_pc(pc
);
1227 /* the PC is inside the translated code. It means that we have
1228 a virtual CPU fault */
1229 cpu_restore_state(tb
, env
, pc
, NULL
);
1232 /* Exception index and error code are already set */