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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "host-utils.h"
23 #include "softfloat.h"
26 void helper_tb_flush (void)
31 /*****************************************************************************/
32 /* Exceptions processing helpers */
33 void helper_excp (int excp
, int error
)
35 env
->exception_index
= excp
;
36 env
->error_code
= error
;
40 uint64_t helper_amask (uint64_t arg
)
42 switch (env
->implver
) {
44 /* EV4, EV45, LCA, LCA45 & EV5 */
55 uint64_t helper_load_pcc (void)
61 uint64_t helper_load_implver (void)
66 uint64_t helper_load_fpcr (void)
69 #ifdef CONFIG_SOFTFLOAT
70 ret
|= env
->fp_status
.float_exception_flags
<< 52;
71 if (env
->fp_status
.float_exception_flags
)
73 env
->ipr
[IPR_EXC_SUM
] &= ~0x3E:
74 env
->ipr
[IPR_EXC_SUM
] |= env
->fp_status
.float_exception_flags
<< 1;
76 switch (env
->fp_status
.float_rounding_mode
) {
77 case float_round_nearest_even
:
80 case float_round_down
:
86 case float_round_to_zero
:
92 void helper_store_fpcr (uint64_t val
)
94 #ifdef CONFIG_SOFTFLOAT
95 set_float_exception_flags((val
>> 52) & 0x3F, &FP_STATUS
);
97 switch ((val
>> 58) & 3) {
99 set_float_rounding_mode(float_round_to_zero
, &FP_STATUS
);
102 set_float_rounding_mode(float_round_down
, &FP_STATUS
);
105 set_float_rounding_mode(float_round_nearest_even
, &FP_STATUS
);
108 set_float_rounding_mode(float_round_up
, &FP_STATUS
);
113 spinlock_t intr_cpu_lock
= SPIN_LOCK_UNLOCKED
;
115 uint64_t helper_rs(void)
119 spin_lock(&intr_cpu_lock
);
120 tmp
= env
->intr_flag
;
122 spin_unlock(&intr_cpu_lock
);
127 uint64_t helper_rc(void)
131 spin_lock(&intr_cpu_lock
);
132 tmp
= env
->intr_flag
;
134 spin_unlock(&intr_cpu_lock
);
139 uint64_t helper_addqv (uint64_t op1
, uint64_t op2
)
143 if (unlikely((tmp
^ op2
^ (-1ULL)) & (tmp
^ op1
) & (1ULL << 63))) {
144 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
149 uint64_t helper_addlv (uint64_t op1
, uint64_t op2
)
152 op1
= (uint32_t)(op1
+ op2
);
153 if (unlikely((tmp
^ op2
^ (-1UL)) & (tmp
^ op1
) & (1UL << 31))) {
154 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
159 uint64_t helper_subqv (uint64_t op1
, uint64_t op2
)
163 if (unlikely(((~tmp
) ^ op1
^ (-1ULL)) & ((~tmp
) ^ op2
) & (1ULL << 63))) {
164 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
169 uint64_t helper_sublv (uint64_t op1
, uint64_t op2
)
172 op1
= (uint32_t)(op1
- op2
);
173 if (unlikely(((~tmp
) ^ op1
^ (-1UL)) & ((~tmp
) ^ op2
) & (1UL << 31))) {
174 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
179 uint64_t helper_mullv (uint64_t op1
, uint64_t op2
)
181 int64_t res
= (int64_t)op1
* (int64_t)op2
;
183 if (unlikely((int32_t)res
!= res
)) {
184 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
186 return (int64_t)((int32_t)res
);
189 uint64_t helper_mulqv (uint64_t op1
, uint64_t op2
)
193 muls64(&tl
, &th
, op1
, op2
);
194 /* If th != 0 && th != -1, then we had an overflow */
195 if (unlikely((th
+ 1) > 1)) {
196 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
201 uint64_t helper_umulh (uint64_t op1
, uint64_t op2
)
205 mulu64(&tl
, &th
, op1
, op2
);
209 uint64_t helper_ctpop (uint64_t arg
)
214 uint64_t helper_ctlz (uint64_t arg
)
219 uint64_t helper_cttz (uint64_t arg
)
224 static always_inline
uint64_t byte_zap (uint64_t op
, uint8_t mskb
)
229 mask
|= ((mskb
>> 0) & 1) * 0x00000000000000FFULL
;
230 mask
|= ((mskb
>> 1) & 1) * 0x000000000000FF00ULL
;
231 mask
|= ((mskb
>> 2) & 1) * 0x0000000000FF0000ULL
;
232 mask
|= ((mskb
>> 3) & 1) * 0x00000000FF000000ULL
;
233 mask
|= ((mskb
>> 4) & 1) * 0x000000FF00000000ULL
;
234 mask
|= ((mskb
>> 5) & 1) * 0x0000FF0000000000ULL
;
235 mask
|= ((mskb
>> 6) & 1) * 0x00FF000000000000ULL
;
236 mask
|= ((mskb
>> 7) & 1) * 0xFF00000000000000ULL
;
241 uint64_t helper_mskbl(uint64_t val
, uint64_t mask
)
243 return byte_zap(val
, 0x01 << (mask
& 7));
246 uint64_t helper_insbl(uint64_t val
, uint64_t mask
)
248 val
<<= (mask
& 7) * 8;
249 return byte_zap(val
, ~(0x01 << (mask
& 7)));
252 uint64_t helper_mskwl(uint64_t val
, uint64_t mask
)
254 return byte_zap(val
, 0x03 << (mask
& 7));
257 uint64_t helper_inswl(uint64_t val
, uint64_t mask
)
259 val
<<= (mask
& 7) * 8;
260 return byte_zap(val
, ~(0x03 << (mask
& 7)));
263 uint64_t helper_mskll(uint64_t val
, uint64_t mask
)
265 return byte_zap(val
, 0x0F << (mask
& 7));
268 uint64_t helper_insll(uint64_t val
, uint64_t mask
)
270 val
<<= (mask
& 7) * 8;
271 return byte_zap(val
, ~(0x0F << (mask
& 7)));
274 uint64_t helper_zap(uint64_t val
, uint64_t mask
)
276 return byte_zap(val
, mask
);
279 uint64_t helper_zapnot(uint64_t val
, uint64_t mask
)
281 return byte_zap(val
, ~mask
);
284 uint64_t helper_mskql(uint64_t val
, uint64_t mask
)
286 return byte_zap(val
, 0xFF << (mask
& 7));
289 uint64_t helper_insql(uint64_t val
, uint64_t mask
)
291 val
<<= (mask
& 7) * 8;
292 return byte_zap(val
, ~(0xFF << (mask
& 7)));
295 uint64_t helper_mskwh(uint64_t val
, uint64_t mask
)
297 return byte_zap(val
, (0x03 << (mask
& 7)) >> 8);
300 uint64_t helper_inswh(uint64_t val
, uint64_t mask
)
302 val
>>= 64 - ((mask
& 7) * 8);
303 return byte_zap(val
, ~((0x03 << (mask
& 7)) >> 8));
306 uint64_t helper_msklh(uint64_t val
, uint64_t mask
)
308 return byte_zap(val
, (0x0F << (mask
& 7)) >> 8);
311 uint64_t helper_inslh(uint64_t val
, uint64_t mask
)
313 val
>>= 64 - ((mask
& 7) * 8);
314 return byte_zap(val
, ~((0x0F << (mask
& 7)) >> 8));
317 uint64_t helper_mskqh(uint64_t val
, uint64_t mask
)
319 return byte_zap(val
, (0xFF << (mask
& 7)) >> 8);
322 uint64_t helper_insqh(uint64_t val
, uint64_t mask
)
324 val
>>= 64 - ((mask
& 7) * 8);
325 return byte_zap(val
, ~((0xFF << (mask
& 7)) >> 8));
328 uint64_t helper_cmpbge (uint64_t op1
, uint64_t op2
)
330 uint8_t opa
, opb
, res
;
334 for (i
= 0; i
< 8; i
++) {
335 opa
= op1
>> (i
* 8);
336 opb
= op2
>> (i
* 8);
343 /* Floating point helpers */
345 /* F floating (VAX) */
346 static always_inline
uint64_t float32_to_f (float32 fa
)
349 uint64_t r
, exp
, mant
, sig
;
351 a
= *(uint32_t*)(&fa
);
352 sig
= ((uint64_t)a
& 0x80000000) << 32;
353 exp
= (a
>> 23) & 0xff;
354 mant
= ((uint64_t)a
& 0x007fffff) << 29;
357 /* NaN or infinity */
358 r
= 1; /* VAX dirty zero */
359 } else if (exp
== 0) {
365 r
= sig
| ((exp
+ 1) << 52) | mant
;
370 r
= 1; /* VAX dirty zero */
372 r
= sig
| ((exp
+ 2) << 52);
379 static always_inline float32
f_to_float32 (uint64_t a
)
381 uint32_t r
, exp
, mant_sig
;
383 exp
= ((a
>> 55) & 0x80) | ((a
>> 52) & 0x7f);
384 mant_sig
= ((a
>> 32) & 0x80000000) | ((a
>> 29) & 0x007fffff);
386 if (unlikely(!exp
&& mant_sig
)) {
387 /* Reserved operands / Dirty zero */
388 helper_excp(EXCP_OPCDEC
, 0);
395 r
= ((exp
- 2) << 23) | mant_sig
;
398 return *(float32
*)(&a
);
401 uint32_t helper_f_to_memory (uint64_t a
)
404 r
= (a
& 0x00001fffe0000000ull
) >> 13;
405 r
|= (a
& 0x07ffe00000000000ull
) >> 45;
406 r
|= (a
& 0xc000000000000000ull
) >> 48;
410 uint64_t helper_memory_to_f (uint32_t a
)
413 r
= ((uint64_t)(a
& 0x0000c000)) << 48;
414 r
|= ((uint64_t)(a
& 0x003fffff)) << 45;
415 r
|= ((uint64_t)(a
& 0xffff0000)) << 13;
416 if (!(a
& 0x00004000))
421 uint64_t helper_addf (uint64_t a
, uint64_t b
)
425 fa
= f_to_float32(a
);
426 fb
= f_to_float32(b
);
427 fr
= float32_add(fa
, fb
, &FP_STATUS
);
428 return float32_to_f(fr
);
431 uint64_t helper_subf (uint64_t a
, uint64_t b
)
435 fa
= f_to_float32(a
);
436 fb
= f_to_float32(b
);
437 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
438 return float32_to_f(fr
);
441 uint64_t helper_mulf (uint64_t a
, uint64_t b
)
445 fa
= f_to_float32(a
);
446 fb
= f_to_float32(b
);
447 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
448 return float32_to_f(fr
);
451 uint64_t helper_divf (uint64_t a
, uint64_t b
)
455 fa
= f_to_float32(a
);
456 fb
= f_to_float32(b
);
457 fr
= float32_div(fa
, fb
, &FP_STATUS
);
458 return float32_to_f(fr
);
461 uint64_t helper_sqrtf (uint64_t t
)
465 ft
= f_to_float32(t
);
466 fr
= float32_sqrt(ft
, &FP_STATUS
);
467 return float32_to_f(fr
);
471 /* G floating (VAX) */
472 static always_inline
uint64_t float64_to_g (float64 fa
)
474 uint64_t a
, r
, exp
, mant
, sig
;
476 a
= *(uint64_t*)(&fa
);
477 sig
= a
& 0x8000000000000000ull
;
478 exp
= (a
>> 52) & 0x7ff;
479 mant
= a
& 0x000fffffffffffffull
;
482 /* NaN or infinity */
483 r
= 1; /* VAX dirty zero */
484 } else if (exp
== 0) {
490 r
= sig
| ((exp
+ 1) << 52) | mant
;
495 r
= 1; /* VAX dirty zero */
497 r
= sig
| ((exp
+ 2) << 52);
504 static always_inline float64
g_to_float64 (uint64_t a
)
506 uint64_t r
, exp
, mant_sig
;
508 exp
= (a
>> 52) & 0x7ff;
509 mant_sig
= a
& 0x800fffffffffffffull
;
511 if (!exp
&& mant_sig
) {
512 /* Reserved operands / Dirty zero */
513 helper_excp(EXCP_OPCDEC
, 0);
520 r
= ((exp
- 2) << 52) | mant_sig
;
523 return *(float64
*)(&a
);
526 uint64_t helper_g_to_memory (uint64_t a
)
529 r
= (a
& 0x000000000000ffffull
) << 48;
530 r
|= (a
& 0x00000000ffff0000ull
) << 16;
531 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
532 r
|= (a
& 0xffff000000000000ull
) >> 48;
536 uint64_t helper_memory_to_g (uint64_t a
)
539 r
= (a
& 0x000000000000ffffull
) << 48;
540 r
|= (a
& 0x00000000ffff0000ull
) << 16;
541 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
542 r
|= (a
& 0xffff000000000000ull
) >> 48;
546 uint64_t helper_addg (uint64_t a
, uint64_t b
)
550 fa
= g_to_float64(a
);
551 fb
= g_to_float64(b
);
552 fr
= float64_add(fa
, fb
, &FP_STATUS
);
553 return float64_to_g(fr
);
556 uint64_t helper_subg (uint64_t a
, uint64_t b
)
560 fa
= g_to_float64(a
);
561 fb
= g_to_float64(b
);
562 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
563 return float64_to_g(fr
);
566 uint64_t helper_mulg (uint64_t a
, uint64_t b
)
570 fa
= g_to_float64(a
);
571 fb
= g_to_float64(b
);
572 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
573 return float64_to_g(fr
);
576 uint64_t helper_divg (uint64_t a
, uint64_t b
)
580 fa
= g_to_float64(a
);
581 fb
= g_to_float64(b
);
582 fr
= float64_div(fa
, fb
, &FP_STATUS
);
583 return float64_to_g(fr
);
586 uint64_t helper_sqrtg (uint64_t a
)
590 fa
= g_to_float64(a
);
591 fr
= float64_sqrt(fa
, &FP_STATUS
);
592 return float64_to_g(fr
);
596 /* S floating (single) */
597 static always_inline
uint64_t float32_to_s (float32 fa
)
602 a
= *(uint32_t*)(&fa
);
604 r
= (((uint64_t)(a
& 0xc0000000)) << 32) | (((uint64_t)(a
& 0x3fffffff)) << 29);
605 if (((a
& 0x7f800000) != 0x7f800000) && (!(a
& 0x40000000)))
610 static always_inline float32
s_to_float32 (uint64_t a
)
612 uint32_t r
= ((a
>> 32) & 0xc0000000) | ((a
>> 29) & 0x3fffffff);
613 return *(float32
*)(&r
);
616 uint32_t helper_s_to_memory (uint64_t a
)
618 /* Memory format is the same as float32 */
619 float32 fa
= s_to_float32(a
);
620 return *(uint32_t*)(&fa
);
623 uint64_t helper_memory_to_s (uint32_t a
)
625 /* Memory format is the same as float32 */
626 return float32_to_s(*(float32
*)(&a
));
629 uint64_t helper_adds (uint64_t a
, uint64_t b
)
633 fa
= s_to_float32(a
);
634 fb
= s_to_float32(b
);
635 fr
= float32_add(fa
, fb
, &FP_STATUS
);
636 return float32_to_s(fr
);
639 uint64_t helper_subs (uint64_t a
, uint64_t b
)
643 fa
= s_to_float32(a
);
644 fb
= s_to_float32(b
);
645 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
646 return float32_to_s(fr
);
649 uint64_t helper_muls (uint64_t a
, uint64_t b
)
653 fa
= s_to_float32(a
);
654 fb
= s_to_float32(b
);
655 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
656 return float32_to_s(fr
);
659 uint64_t helper_divs (uint64_t a
, uint64_t b
)
663 fa
= s_to_float32(a
);
664 fb
= s_to_float32(b
);
665 fr
= float32_div(fa
, fb
, &FP_STATUS
);
666 return float32_to_s(fr
);
669 uint64_t helper_sqrts (uint64_t a
)
673 fa
= s_to_float32(a
);
674 fr
= float32_sqrt(fa
, &FP_STATUS
);
675 return float32_to_s(fr
);
679 /* T floating (double) */
680 static always_inline float64
t_to_float64 (uint64_t a
)
682 /* Memory format is the same as float64 */
683 return *(float64
*)(&a
);
686 static always_inline
uint64_t float64_to_t (float64 fa
)
688 /* Memory format is the same as float64 */
689 return *(uint64
*)(&fa
);
692 uint64_t helper_addt (uint64_t a
, uint64_t b
)
696 fa
= t_to_float64(a
);
697 fb
= t_to_float64(b
);
698 fr
= float64_add(fa
, fb
, &FP_STATUS
);
699 return float64_to_t(fr
);
702 uint64_t helper_subt (uint64_t a
, uint64_t b
)
706 fa
= t_to_float64(a
);
707 fb
= t_to_float64(b
);
708 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
709 return float64_to_t(fr
);
712 uint64_t helper_mult (uint64_t a
, uint64_t b
)
716 fa
= t_to_float64(a
);
717 fb
= t_to_float64(b
);
718 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
719 return float64_to_t(fr
);
722 uint64_t helper_divt (uint64_t a
, uint64_t b
)
726 fa
= t_to_float64(a
);
727 fb
= t_to_float64(b
);
728 fr
= float64_div(fa
, fb
, &FP_STATUS
);
729 return float64_to_t(fr
);
732 uint64_t helper_sqrtt (uint64_t a
)
736 fa
= t_to_float64(a
);
737 fr
= float64_sqrt(fa
, &FP_STATUS
);
738 return float64_to_t(fr
);
743 uint64_t helper_cpys(uint64_t a
, uint64_t b
)
745 return (a
& 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
748 uint64_t helper_cpysn(uint64_t a
, uint64_t b
)
750 return ((~a
) & 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
753 uint64_t helper_cpyse(uint64_t a
, uint64_t b
)
755 return (a
& 0xFFF0000000000000ULL
) | (b
& ~0xFFF0000000000000ULL
);
760 uint64_t helper_cmptun (uint64_t a
, uint64_t b
)
764 fa
= t_to_float64(a
);
765 fb
= t_to_float64(b
);
767 if (float64_is_nan(fa
) || float64_is_nan(fb
))
768 return 0x4000000000000000ULL
;
773 uint64_t helper_cmpteq(uint64_t a
, uint64_t b
)
777 fa
= t_to_float64(a
);
778 fb
= t_to_float64(b
);
780 if (float64_eq(fa
, fb
, &FP_STATUS
))
781 return 0x4000000000000000ULL
;
786 uint64_t helper_cmptle(uint64_t a
, uint64_t b
)
790 fa
= t_to_float64(a
);
791 fb
= t_to_float64(b
);
793 if (float64_le(fa
, fb
, &FP_STATUS
))
794 return 0x4000000000000000ULL
;
799 uint64_t helper_cmptlt(uint64_t a
, uint64_t b
)
803 fa
= t_to_float64(a
);
804 fb
= t_to_float64(b
);
806 if (float64_lt(fa
, fb
, &FP_STATUS
))
807 return 0x4000000000000000ULL
;
812 uint64_t helper_cmpgeq(uint64_t a
, uint64_t b
)
816 fa
= g_to_float64(a
);
817 fb
= g_to_float64(b
);
819 if (float64_eq(fa
, fb
, &FP_STATUS
))
820 return 0x4000000000000000ULL
;
825 uint64_t helper_cmpgle(uint64_t a
, uint64_t b
)
829 fa
= g_to_float64(a
);
830 fb
= g_to_float64(b
);
832 if (float64_le(fa
, fb
, &FP_STATUS
))
833 return 0x4000000000000000ULL
;
838 uint64_t helper_cmpglt(uint64_t a
, uint64_t b
)
842 fa
= g_to_float64(a
);
843 fb
= g_to_float64(b
);
845 if (float64_lt(fa
, fb
, &FP_STATUS
))
846 return 0x4000000000000000ULL
;
851 uint64_t helper_cmpfeq (uint64_t a
)
853 return !(a
& 0x7FFFFFFFFFFFFFFFULL
);
856 uint64_t helper_cmpfne (uint64_t a
)
858 return (a
& 0x7FFFFFFFFFFFFFFFULL
);
861 uint64_t helper_cmpflt (uint64_t a
)
863 return (a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
866 uint64_t helper_cmpfle (uint64_t a
)
868 return (a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
871 uint64_t helper_cmpfgt (uint64_t a
)
873 return !(a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
876 uint64_t helper_cmpfge (uint64_t a
)
878 return !(a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
882 /* Floating point format conversion */
883 uint64_t helper_cvtts (uint64_t a
)
888 fa
= t_to_float64(a
);
889 fr
= float64_to_float32(fa
, &FP_STATUS
);
890 return float32_to_s(fr
);
893 uint64_t helper_cvtst (uint64_t a
)
898 fa
= s_to_float32(a
);
899 fr
= float32_to_float64(fa
, &FP_STATUS
);
900 return float64_to_t(fr
);
903 uint64_t helper_cvtqs (uint64_t a
)
905 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
906 return float32_to_s(fr
);
909 uint64_t helper_cvttq (uint64_t a
)
911 float64 fa
= t_to_float64(a
);
912 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
915 uint64_t helper_cvtqt (uint64_t a
)
917 float64 fr
= int64_to_float64(a
, &FP_STATUS
);
918 return float64_to_t(fr
);
921 uint64_t helper_cvtqf (uint64_t a
)
923 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
924 return float32_to_f(fr
);
927 uint64_t helper_cvtgf (uint64_t a
)
932 fa
= g_to_float64(a
);
933 fr
= float64_to_float32(fa
, &FP_STATUS
);
934 return float32_to_f(fr
);
937 uint64_t helper_cvtgq (uint64_t a
)
939 float64 fa
= g_to_float64(a
);
940 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
943 uint64_t helper_cvtqg (uint64_t a
)
946 fr
= int64_to_float64(a
, &FP_STATUS
);
947 return float64_to_g(fr
);
950 uint64_t helper_cvtlq (uint64_t a
)
952 return (int64_t)((int32_t)((a
>> 32) | ((a
>> 29) & 0x3FFFFFFF)));
955 static always_inline
uint64_t __helper_cvtql (uint64_t a
, int s
, int v
)
959 r
= ((uint64_t)(a
& 0xC0000000)) << 32;
960 r
|= ((uint64_t)(a
& 0x7FFFFFFF)) << 29;
962 if (v
&& (int64_t)((int32_t)r
) != (int64_t)r
) {
963 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
971 uint64_t helper_cvtql (uint64_t a
)
973 return __helper_cvtql(a
, 0, 0);
976 uint64_t helper_cvtqlv (uint64_t a
)
978 return __helper_cvtql(a
, 0, 1);
981 uint64_t helper_cvtqlsv (uint64_t a
)
983 return __helper_cvtql(a
, 1, 1);
986 /* PALcode support special instructions */
987 #if !defined (CONFIG_USER_ONLY)
988 void helper_hw_rei (void)
990 env
->pc
= env
->ipr
[IPR_EXC_ADDR
] & ~3;
991 env
->ipr
[IPR_EXC_ADDR
] = env
->ipr
[IPR_EXC_ADDR
] & 1;
992 /* XXX: re-enable interrupts and memory mapping */
995 void helper_hw_ret (uint64_t a
)
998 env
->ipr
[IPR_EXC_ADDR
] = a
& 1;
999 /* XXX: re-enable interrupts and memory mapping */
1002 uint64_t helper_mfpr (int iprn
, uint64_t val
)
1006 if (cpu_alpha_mfpr(env
, iprn
, &tmp
) == 0)
1012 void helper_mtpr (int iprn
, uint64_t val
)
1014 cpu_alpha_mtpr(env
, iprn
, val
, NULL
);
1017 void helper_set_alt_mode (void)
1019 env
->saved_mode
= env
->ps
& 0xC;
1020 env
->ps
= (env
->ps
& ~0xC) | (env
->ipr
[IPR_ALT_MODE
] & 0xC);
1023 void helper_restore_mode (void)
1025 env
->ps
= (env
->ps
& ~0xC) | env
->saved_mode
;
1030 /*****************************************************************************/
1031 /* Softmmu support */
1032 #if !defined (CONFIG_USER_ONLY)
1034 /* XXX: the two following helpers are pure hacks.
1035 * Hopefully, we emulate the PALcode, then we should never see
1036 * HW_LD / HW_ST instructions.
1038 uint64_t helper_ld_virt_to_phys (uint64_t virtaddr
)
1040 uint64_t tlb_addr
, physaddr
;
1044 mmu_idx
= cpu_mmu_index(env
);
1045 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1047 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_read
;
1048 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1049 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1050 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1052 /* the page is not in the TLB : fill it */
1054 tlb_fill(virtaddr
, 0, mmu_idx
, retaddr
);
1060 uint64_t helper_st_virt_to_phys (uint64_t virtaddr
)
1062 uint64_t tlb_addr
, physaddr
;
1066 mmu_idx
= cpu_mmu_index(env
);
1067 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1069 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_write
;
1070 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1071 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1072 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1074 /* the page is not in the TLB : fill it */
1076 tlb_fill(virtaddr
, 1, mmu_idx
, retaddr
);
1082 void helper_ldl_raw(uint64_t t0
, uint64_t t1
)
1087 void helper_ldq_raw(uint64_t t0
, uint64_t t1
)
1092 void helper_ldl_l_raw(uint64_t t0
, uint64_t t1
)
1098 void helper_ldq_l_raw(uint64_t t0
, uint64_t t1
)
1104 void helper_ldl_kernel(uint64_t t0
, uint64_t t1
)
1109 void helper_ldq_kernel(uint64_t t0
, uint64_t t1
)
1114 void helper_ldl_data(uint64_t t0
, uint64_t t1
)
1119 void helper_ldq_data(uint64_t t0
, uint64_t t1
)
1124 void helper_stl_raw(uint64_t t0
, uint64_t t1
)
1129 void helper_stq_raw(uint64_t t0
, uint64_t t1
)
1134 uint64_t helper_stl_c_raw(uint64_t t0
, uint64_t t1
)
1138 if (t1
== env
->lock
) {
1149 uint64_t helper_stq_c_raw(uint64_t t0
, uint64_t t1
)
1153 if (t1
== env
->lock
) {
1164 #define MMUSUFFIX _mmu
1167 #include "softmmu_template.h"
1170 #include "softmmu_template.h"
1173 #include "softmmu_template.h"
1176 #include "softmmu_template.h"
1178 /* try to fill the TLB and return an exception if error. If retaddr is
1179 NULL, it means that the function was called in C code (i.e. not
1180 from generated code or from helper.c) */
1181 /* XXX: fix it to restore all registers */
1182 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
1184 TranslationBlock
*tb
;
1185 CPUState
*saved_env
;
1189 /* XXX: hack to restore env in all cases, even if not called from
1192 env
= cpu_single_env
;
1193 ret
= cpu_alpha_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
1194 if (!likely(ret
== 0)) {
1195 if (likely(retaddr
)) {
1196 /* now we have a real cpu fault */
1197 pc
= (unsigned long)retaddr
;
1198 tb
= tb_find_pc(pc
);
1200 /* the PC is inside the translated code. It means that we have
1201 a virtual CPU fault */
1202 cpu_restore_state(tb
, env
, pc
, NULL
);
1205 /* Exception index and error code are already set */