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"
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_amask (uint64_t arg
)
41 switch (env
->implver
) {
43 /* EV4, EV45, LCA, LCA45 & EV5 */
54 uint64_t helper_load_pcc (void)
60 uint64_t helper_load_implver (void)
65 uint64_t helper_load_fpcr (void)
68 #ifdef CONFIG_SOFTFLOAT
69 ret
|= env
->fp_status
.float_exception_flags
<< 52;
70 if (env
->fp_status
.float_exception_flags
)
72 env
->ipr
[IPR_EXC_SUM
] &= ~0x3E:
73 env
->ipr
[IPR_EXC_SUM
] |= env
->fp_status
.float_exception_flags
<< 1;
75 switch (env
->fp_status
.float_rounding_mode
) {
76 case float_round_nearest_even
:
79 case float_round_down
:
85 case float_round_to_zero
:
91 void helper_store_fpcr (uint64_t val
)
93 #ifdef CONFIG_SOFTFLOAT
94 set_float_exception_flags((val
>> 52) & 0x3F, &FP_STATUS
);
96 switch ((val
>> 58) & 3) {
98 set_float_rounding_mode(float_round_to_zero
, &FP_STATUS
);
101 set_float_rounding_mode(float_round_down
, &FP_STATUS
);
104 set_float_rounding_mode(float_round_nearest_even
, &FP_STATUS
);
107 set_float_rounding_mode(float_round_up
, &FP_STATUS
);
112 spinlock_t intr_cpu_lock
= SPIN_LOCK_UNLOCKED
;
114 uint64_t helper_rs(void)
118 spin_lock(&intr_cpu_lock
);
119 tmp
= env
->intr_flag
;
121 spin_unlock(&intr_cpu_lock
);
126 uint64_t helper_rc(void)
130 spin_lock(&intr_cpu_lock
);
131 tmp
= env
->intr_flag
;
133 spin_unlock(&intr_cpu_lock
);
138 uint64_t helper_addqv (uint64_t op1
, uint64_t op2
)
142 if (unlikely((tmp
^ op2
^ (-1ULL)) & (tmp
^ op1
) & (1ULL << 63))) {
143 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
148 uint64_t helper_addlv (uint64_t op1
, uint64_t op2
)
151 op1
= (uint32_t)(op1
+ op2
);
152 if (unlikely((tmp
^ op2
^ (-1UL)) & (tmp
^ op1
) & (1UL << 31))) {
153 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
158 uint64_t helper_subqv (uint64_t op1
, uint64_t op2
)
162 if (unlikely(((~tmp
) ^ op1
^ (-1ULL)) & ((~tmp
) ^ op2
) & (1ULL << 63))) {
163 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
168 uint64_t helper_sublv (uint64_t op1
, uint64_t op2
)
171 op1
= (uint32_t)(op1
- op2
);
172 if (unlikely(((~tmp
) ^ op1
^ (-1UL)) & ((~tmp
) ^ op2
) & (1UL << 31))) {
173 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
178 uint64_t helper_mullv (uint64_t op1
, uint64_t op2
)
180 int64_t res
= (int64_t)op1
* (int64_t)op2
;
182 if (unlikely((int32_t)res
!= res
)) {
183 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
185 return (int64_t)((int32_t)res
);
188 uint64_t helper_mulqv (uint64_t op1
, uint64_t op2
)
192 muls64(&tl
, &th
, op1
, op2
);
193 /* If th != 0 && th != -1, then we had an overflow */
194 if (unlikely((th
+ 1) > 1)) {
195 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
200 uint64_t helper_umulh (uint64_t op1
, uint64_t op2
)
204 mulu64(&tl
, &th
, op1
, op2
);
208 uint64_t helper_ctpop (uint64_t arg
)
213 uint64_t helper_ctlz (uint64_t arg
)
218 uint64_t helper_cttz (uint64_t arg
)
223 static always_inline
uint64_t byte_zap (uint64_t op
, uint8_t mskb
)
228 mask
|= ((mskb
>> 0) & 1) * 0x00000000000000FFULL
;
229 mask
|= ((mskb
>> 1) & 1) * 0x000000000000FF00ULL
;
230 mask
|= ((mskb
>> 2) & 1) * 0x0000000000FF0000ULL
;
231 mask
|= ((mskb
>> 3) & 1) * 0x00000000FF000000ULL
;
232 mask
|= ((mskb
>> 4) & 1) * 0x000000FF00000000ULL
;
233 mask
|= ((mskb
>> 5) & 1) * 0x0000FF0000000000ULL
;
234 mask
|= ((mskb
>> 6) & 1) * 0x00FF000000000000ULL
;
235 mask
|= ((mskb
>> 7) & 1) * 0xFF00000000000000ULL
;
240 uint64_t helper_mskbl(uint64_t val
, uint64_t mask
)
242 return byte_zap(val
, 0x01 << (mask
& 7));
245 uint64_t helper_insbl(uint64_t val
, uint64_t mask
)
247 val
<<= (mask
& 7) * 8;
248 return byte_zap(val
, ~(0x01 << (mask
& 7)));
251 uint64_t helper_mskwl(uint64_t val
, uint64_t mask
)
253 return byte_zap(val
, 0x03 << (mask
& 7));
256 uint64_t helper_inswl(uint64_t val
, uint64_t mask
)
258 val
<<= (mask
& 7) * 8;
259 return byte_zap(val
, ~(0x03 << (mask
& 7)));
262 uint64_t helper_mskll(uint64_t val
, uint64_t mask
)
264 return byte_zap(val
, 0x0F << (mask
& 7));
267 uint64_t helper_insll(uint64_t val
, uint64_t mask
)
269 val
<<= (mask
& 7) * 8;
270 return byte_zap(val
, ~(0x0F << (mask
& 7)));
273 uint64_t helper_zap(uint64_t val
, uint64_t mask
)
275 return byte_zap(val
, mask
);
278 uint64_t helper_zapnot(uint64_t val
, uint64_t mask
)
280 return byte_zap(val
, ~mask
);
283 uint64_t helper_mskql(uint64_t val
, uint64_t mask
)
285 return byte_zap(val
, 0xFF << (mask
& 7));
288 uint64_t helper_insql(uint64_t val
, uint64_t mask
)
290 val
<<= (mask
& 7) * 8;
291 return byte_zap(val
, ~(0xFF << (mask
& 7)));
294 uint64_t helper_mskwh(uint64_t val
, uint64_t mask
)
296 return byte_zap(val
, (0x03 << (mask
& 7)) >> 8);
299 uint64_t helper_inswh(uint64_t val
, uint64_t mask
)
301 val
>>= 64 - ((mask
& 7) * 8);
302 return byte_zap(val
, ~((0x03 << (mask
& 7)) >> 8));
305 uint64_t helper_msklh(uint64_t val
, uint64_t mask
)
307 return byte_zap(val
, (0x0F << (mask
& 7)) >> 8);
310 uint64_t helper_inslh(uint64_t val
, uint64_t mask
)
312 val
>>= 64 - ((mask
& 7) * 8);
313 return byte_zap(val
, ~((0x0F << (mask
& 7)) >> 8));
316 uint64_t helper_mskqh(uint64_t val
, uint64_t mask
)
318 return byte_zap(val
, (0xFF << (mask
& 7)) >> 8);
321 uint64_t helper_insqh(uint64_t val
, uint64_t mask
)
323 val
>>= 64 - ((mask
& 7) * 8);
324 return byte_zap(val
, ~((0xFF << (mask
& 7)) >> 8));
327 uint64_t helper_cmpbge (uint64_t op1
, uint64_t op2
)
329 uint8_t opa
, opb
, res
;
333 for (i
= 0; i
< 7; i
++) {
334 opa
= op1
>> (i
* 8);
335 opb
= op2
>> (i
* 8);
342 /* Floating point helpers */
344 /* F floating (VAX) */
345 static always_inline
uint64_t float32_to_f (float32 fa
)
348 uint64_t r
, exp
, mant
, sig
;
350 a
= *(uint32_t*)(&fa
);
351 sig
= ((uint64_t)a
& 0x80000000) << 32;
352 exp
= (a
>> 23) & 0xff;
353 mant
= ((uint64_t)a
& 0x007fffff) << 29;
356 /* NaN or infinity */
357 r
= 1; /* VAX dirty zero */
358 } else if (exp
== 0) {
364 r
= sig
| ((exp
+ 1) << 52) | mant
;
369 r
= 1; /* VAX dirty zero */
371 r
= sig
| ((exp
+ 2) << 52);
378 static always_inline float32
f_to_float32 (uint64_t a
)
380 uint32_t r
, exp
, mant_sig
;
382 exp
= ((a
>> 55) & 0x80) | ((a
>> 52) & 0x7f);
383 mant_sig
= ((a
>> 32) & 0x80000000) | ((a
>> 29) & 0x007fffff);
385 if (unlikely(!exp
&& mant_sig
)) {
386 /* Reserved operands / Dirty zero */
387 helper_excp(EXCP_OPCDEC
, 0);
394 r
= ((exp
- 2) << 23) | mant_sig
;
397 return *(float32
*)(&a
);
400 uint32_t helper_f_to_memory (uint64_t a
)
403 r
= (a
& 0x00001fffe0000000ull
) >> 13;
404 r
|= (a
& 0x07ffe00000000000ull
) >> 45;
405 r
|= (a
& 0xc000000000000000ull
) >> 48;
409 uint64_t helper_memory_to_f (uint32_t a
)
412 r
= ((uint64_t)(a
& 0x0000c000)) << 48;
413 r
|= ((uint64_t)(a
& 0x003fffff)) << 45;
414 r
|= ((uint64_t)(a
& 0xffff0000)) << 13;
415 if (!(a
& 0x00004000))
420 uint64_t helper_addf (uint64_t a
, uint64_t b
)
424 fa
= f_to_float32(a
);
425 fb
= f_to_float32(b
);
426 fr
= float32_add(fa
, fb
, &FP_STATUS
);
427 return float32_to_f(fr
);
430 uint64_t helper_subf (uint64_t a
, uint64_t b
)
434 fa
= f_to_float32(a
);
435 fb
= f_to_float32(b
);
436 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
437 return float32_to_f(fr
);
440 uint64_t helper_mulf (uint64_t a
, uint64_t b
)
444 fa
= f_to_float32(a
);
445 fb
= f_to_float32(b
);
446 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
447 return float32_to_f(fr
);
450 uint64_t helper_divf (uint64_t a
, uint64_t b
)
454 fa
= f_to_float32(a
);
455 fb
= f_to_float32(b
);
456 fr
= float32_div(fa
, fb
, &FP_STATUS
);
457 return float32_to_f(fr
);
460 uint64_t helper_sqrtf (uint64_t t
)
464 ft
= f_to_float32(t
);
465 fr
= float32_sqrt(ft
, &FP_STATUS
);
466 return float32_to_f(fr
);
470 /* G floating (VAX) */
471 static always_inline
uint64_t float64_to_g (float64 fa
)
473 uint64_t a
, r
, exp
, mant
, sig
;
475 a
= *(uint64_t*)(&fa
);
476 sig
= a
& 0x8000000000000000ull
;
477 exp
= (a
>> 52) & 0x7ff;
478 mant
= a
& 0x000fffffffffffffull
;
481 /* NaN or infinity */
482 r
= 1; /* VAX dirty zero */
483 } else if (exp
== 0) {
489 r
= sig
| ((exp
+ 1) << 52) | mant
;
494 r
= 1; /* VAX dirty zero */
496 r
= sig
| ((exp
+ 2) << 52);
503 static always_inline float64
g_to_float64 (uint64_t a
)
505 uint64_t r
, exp
, mant_sig
;
507 exp
= (a
>> 52) & 0x7ff;
508 mant_sig
= a
& 0x800fffffffffffffull
;
510 if (!exp
&& mant_sig
) {
511 /* Reserved operands / Dirty zero */
512 helper_excp(EXCP_OPCDEC
, 0);
519 r
= ((exp
- 2) << 52) | mant_sig
;
522 return *(float64
*)(&a
);
525 uint64_t helper_g_to_memory (uint64_t a
)
528 r
= (a
& 0x000000000000ffffull
) << 48;
529 r
|= (a
& 0x00000000ffff0000ull
) << 16;
530 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
531 r
|= (a
& 0xffff000000000000ull
) >> 48;
535 uint64_t helper_memory_to_g (uint64_t a
)
538 r
= (a
& 0x000000000000ffffull
) << 48;
539 r
|= (a
& 0x00000000ffff0000ull
) << 16;
540 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
541 r
|= (a
& 0xffff000000000000ull
) >> 48;
545 uint64_t helper_addg (uint64_t a
, uint64_t b
)
549 fa
= g_to_float64(a
);
550 fb
= g_to_float64(b
);
551 fr
= float64_add(fa
, fb
, &FP_STATUS
);
552 return float64_to_g(fr
);
555 uint64_t helper_subg (uint64_t a
, uint64_t b
)
559 fa
= g_to_float64(a
);
560 fb
= g_to_float64(b
);
561 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
562 return float64_to_g(fr
);
565 uint64_t helper_mulg (uint64_t a
, uint64_t b
)
569 fa
= g_to_float64(a
);
570 fb
= g_to_float64(b
);
571 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
572 return float64_to_g(fr
);
575 uint64_t helper_divg (uint64_t a
, uint64_t b
)
579 fa
= g_to_float64(a
);
580 fb
= g_to_float64(b
);
581 fr
= float64_div(fa
, fb
, &FP_STATUS
);
582 return float64_to_g(fr
);
585 uint64_t helper_sqrtg (uint64_t a
)
589 fa
= g_to_float64(a
);
590 fr
= float64_sqrt(fa
, &FP_STATUS
);
591 return float64_to_g(fr
);
595 /* S floating (single) */
596 static always_inline
uint64_t float32_to_s (float32 fa
)
601 a
= *(uint32_t*)(&fa
);
603 r
= (((uint64_t)(a
& 0xc0000000)) << 32) | (((uint64_t)(a
& 0x3fffffff)) << 29);
604 if (((a
& 0x7f800000) != 0x7f800000) && (!(a
& 0x40000000)))
609 static always_inline float32
s_to_float32 (uint64_t a
)
611 uint32_t r
= ((a
>> 32) & 0xc0000000) | ((a
>> 29) & 0x3fffffff);
612 return *(float32
*)(&r
);
615 uint32_t helper_s_to_memory (uint64_t a
)
617 /* Memory format is the same as float32 */
618 float32 fa
= s_to_float32(a
);
619 return *(uint32_t*)(&fa
);
622 uint64_t helper_memory_to_s (uint32_t a
)
624 /* Memory format is the same as float32 */
625 return float32_to_s(*(float32
*)(&a
));
628 uint64_t helper_adds (uint64_t a
, uint64_t b
)
632 fa
= s_to_float32(a
);
633 fb
= s_to_float32(b
);
634 fr
= float32_add(fa
, fb
, &FP_STATUS
);
635 return float32_to_s(fr
);
638 uint64_t helper_subs (uint64_t a
, uint64_t b
)
642 fa
= s_to_float32(a
);
643 fb
= s_to_float32(b
);
644 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
645 return float32_to_s(fr
);
648 uint64_t helper_muls (uint64_t a
, uint64_t b
)
652 fa
= s_to_float32(a
);
653 fb
= s_to_float32(b
);
654 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
655 return float32_to_s(fr
);
658 uint64_t helper_divs (uint64_t a
, uint64_t b
)
662 fa
= s_to_float32(a
);
663 fb
= s_to_float32(b
);
664 fr
= float32_div(fa
, fb
, &FP_STATUS
);
665 return float32_to_s(fr
);
668 uint64_t helper_sqrts (uint64_t a
)
672 fa
= s_to_float32(a
);
673 fr
= float32_sqrt(fa
, &FP_STATUS
);
674 return float32_to_s(fr
);
678 /* T floating (double) */
679 static always_inline float64
t_to_float64 (uint64_t a
)
681 /* Memory format is the same as float64 */
682 return *(float64
*)(&a
);
685 static always_inline
uint64_t float64_to_t (float64 fa
)
687 /* Memory format is the same as float64 */
688 return *(uint64
*)(&fa
);
691 uint64_t helper_addt (uint64_t a
, uint64_t b
)
695 fa
= t_to_float64(a
);
696 fb
= t_to_float64(b
);
697 fr
= float64_add(fa
, fb
, &FP_STATUS
);
698 return float64_to_t(fr
);
701 uint64_t helper_subt (uint64_t a
, uint64_t b
)
705 fa
= t_to_float64(a
);
706 fb
= t_to_float64(b
);
707 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
708 return float64_to_t(fr
);
711 uint64_t helper_mult (uint64_t a
, uint64_t b
)
715 fa
= t_to_float64(a
);
716 fb
= t_to_float64(b
);
717 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
718 return float64_to_t(fr
);
721 uint64_t helper_divt (uint64_t a
, uint64_t b
)
725 fa
= t_to_float64(a
);
726 fb
= t_to_float64(b
);
727 fr
= float64_div(fa
, fb
, &FP_STATUS
);
728 return float64_to_t(fr
);
731 uint64_t helper_sqrtt (uint64_t a
)
735 fa
= t_to_float64(a
);
736 fr
= float64_sqrt(fa
, &FP_STATUS
);
737 return float64_to_t(fr
);
742 uint64_t helper_cpys(uint64_t a
, uint64_t b
)
744 return (a
& 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
747 uint64_t helper_cpysn(uint64_t a
, uint64_t b
)
749 return ((~a
) & 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
752 uint64_t helper_cpyse(uint64_t a
, uint64_t b
)
754 return (a
& 0xFFF0000000000000ULL
) | (b
& ~0xFFF0000000000000ULL
);
759 uint64_t helper_cmptun (uint64_t a
, uint64_t b
)
763 fa
= t_to_float64(a
);
764 fb
= t_to_float64(b
);
766 if (float64_is_nan(fa
) || float64_is_nan(fb
))
767 return 0x4000000000000000ULL
;
772 uint64_t helper_cmpteq(uint64_t a
, uint64_t b
)
776 fa
= t_to_float64(a
);
777 fb
= t_to_float64(b
);
779 if (float64_eq(fa
, fb
, &FP_STATUS
))
780 return 0x4000000000000000ULL
;
785 uint64_t helper_cmptle(uint64_t a
, uint64_t b
)
789 fa
= t_to_float64(a
);
790 fb
= t_to_float64(b
);
792 if (float64_le(fa
, fb
, &FP_STATUS
))
793 return 0x4000000000000000ULL
;
798 uint64_t helper_cmptlt(uint64_t a
, uint64_t b
)
802 fa
= t_to_float64(a
);
803 fb
= t_to_float64(b
);
805 if (float64_lt(fa
, fb
, &FP_STATUS
))
806 return 0x4000000000000000ULL
;
811 uint64_t helper_cmpgeq(uint64_t a
, uint64_t b
)
815 fa
= g_to_float64(a
);
816 fb
= g_to_float64(b
);
818 if (float64_eq(fa
, fb
, &FP_STATUS
))
819 return 0x4000000000000000ULL
;
824 uint64_t helper_cmpgle(uint64_t a
, uint64_t b
)
828 fa
= g_to_float64(a
);
829 fb
= g_to_float64(b
);
831 if (float64_le(fa
, fb
, &FP_STATUS
))
832 return 0x4000000000000000ULL
;
837 uint64_t helper_cmpglt(uint64_t a
, uint64_t b
)
841 fa
= g_to_float64(a
);
842 fb
= g_to_float64(b
);
844 if (float64_lt(fa
, fb
, &FP_STATUS
))
845 return 0x4000000000000000ULL
;
850 uint64_t helper_cmpfeq (uint64_t a
)
852 return !(a
& 0x7FFFFFFFFFFFFFFFULL
);
855 uint64_t helper_cmpfne (uint64_t a
)
857 return (a
& 0x7FFFFFFFFFFFFFFFULL
);
860 uint64_t helper_cmpflt (uint64_t a
)
862 return (a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
865 uint64_t helper_cmpfle (uint64_t a
)
867 return (a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
870 uint64_t helper_cmpfgt (uint64_t a
)
872 return !(a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
875 uint64_t helper_cmpfge (uint64_t a
)
877 return !(a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
881 /* Floating point format conversion */
882 uint64_t helper_cvtts (uint64_t a
)
887 fa
= t_to_float64(a
);
888 fr
= float64_to_float32(fa
, &FP_STATUS
);
889 return float32_to_s(fr
);
892 uint64_t helper_cvtst (uint64_t a
)
897 fa
= s_to_float32(a
);
898 fr
= float32_to_float64(fa
, &FP_STATUS
);
899 return float64_to_t(fr
);
902 uint64_t helper_cvtqs (uint64_t a
)
904 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
905 return float32_to_s(fr
);
908 uint64_t helper_cvttq (uint64_t a
)
910 float64 fa
= t_to_float64(a
);
911 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
914 uint64_t helper_cvtqt (uint64_t a
)
916 float64 fr
= int64_to_float64(a
, &FP_STATUS
);
917 return float64_to_t(fr
);
920 uint64_t helper_cvtqf (uint64_t a
)
922 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
923 return float32_to_f(fr
);
926 uint64_t helper_cvtgf (uint64_t a
)
931 fa
= g_to_float64(a
);
932 fr
= float64_to_float32(fa
, &FP_STATUS
);
933 return float32_to_f(fr
);
936 uint64_t helper_cvtgq (uint64_t a
)
938 float64 fa
= g_to_float64(a
);
939 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
942 uint64_t helper_cvtqg (uint64_t a
)
945 fr
= int64_to_float64(a
, &FP_STATUS
);
946 return float64_to_g(fr
);
949 uint64_t helper_cvtlq (uint64_t a
)
951 return (int64_t)((int32_t)((a
>> 32) | ((a
>> 29) & 0x3FFFFFFF)));
954 static always_inline
uint64_t __helper_cvtql (uint64_t a
, int s
, int v
)
958 r
= ((uint64_t)(a
& 0xC0000000)) << 32;
959 r
|= ((uint64_t)(a
& 0x7FFFFFFF)) << 29;
961 if (v
&& (int64_t)((int32_t)r
) != (int64_t)r
) {
962 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
970 uint64_t helper_cvtql (uint64_t a
)
972 return __helper_cvtql(a
, 0, 0);
975 uint64_t helper_cvtqlv (uint64_t a
)
977 return __helper_cvtql(a
, 0, 1);
980 uint64_t helper_cvtqlsv (uint64_t a
)
982 return __helper_cvtql(a
, 1, 1);
985 /* PALcode support special instructions */
986 #if !defined (CONFIG_USER_ONLY)
987 void helper_hw_rei (void)
989 env
->pc
= env
->ipr
[IPR_EXC_ADDR
] & ~3;
990 env
->ipr
[IPR_EXC_ADDR
] = env
->ipr
[IPR_EXC_ADDR
] & 1;
991 /* XXX: re-enable interrupts and memory mapping */
994 void helper_hw_ret (uint64_t a
)
997 env
->ipr
[IPR_EXC_ADDR
] = a
& 1;
998 /* XXX: re-enable interrupts and memory mapping */
1001 uint64_t helper_mfpr (int iprn
, uint64_t val
)
1005 if (cpu_alpha_mfpr(env
, iprn
, &tmp
) == 0)
1011 void helper_mtpr (int iprn
, uint64_t val
)
1013 cpu_alpha_mtpr(env
, iprn
, val
, NULL
);
1016 void helper_set_alt_mode (void)
1018 env
->saved_mode
= env
->ps
& 0xC;
1019 env
->ps
= (env
->ps
& ~0xC) | (env
->ipr
[IPR_ALT_MODE
] & 0xC);
1022 void helper_restore_mode (void)
1024 env
->ps
= (env
->ps
& ~0xC) | env
->saved_mode
;
1029 /*****************************************************************************/
1030 /* Softmmu support */
1031 #if !defined (CONFIG_USER_ONLY)
1033 /* XXX: the two following helpers are pure hacks.
1034 * Hopefully, we emulate the PALcode, then we should never see
1035 * HW_LD / HW_ST instructions.
1037 uint64_t helper_ld_virt_to_phys (uint64_t virtaddr
)
1039 uint64_t tlb_addr
, physaddr
;
1043 mmu_idx
= cpu_mmu_index(env
);
1044 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1046 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_read
;
1047 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1048 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1049 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1051 /* the page is not in the TLB : fill it */
1053 tlb_fill(virtaddr
, 0, mmu_idx
, retaddr
);
1059 uint64_t helper_st_virt_to_phys (uint64_t virtaddr
)
1061 uint64_t tlb_addr
, physaddr
;
1065 mmu_idx
= cpu_mmu_index(env
);
1066 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1068 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_write
;
1069 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1070 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1071 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1073 /* the page is not in the TLB : fill it */
1075 tlb_fill(virtaddr
, 1, mmu_idx
, retaddr
);
1081 void helper_ldl_raw(uint64_t t0
, uint64_t t1
)
1086 void helper_ldq_raw(uint64_t t0
, uint64_t t1
)
1091 void helper_ldl_l_raw(uint64_t t0
, uint64_t t1
)
1097 void helper_ldq_l_raw(uint64_t t0
, uint64_t t1
)
1103 void helper_ldl_kernel(uint64_t t0
, uint64_t t1
)
1108 void helper_ldq_kernel(uint64_t t0
, uint64_t t1
)
1113 void helper_ldl_data(uint64_t t0
, uint64_t t1
)
1118 void helper_ldq_data(uint64_t t0
, uint64_t t1
)
1123 void helper_stl_raw(uint64_t t0
, uint64_t t1
)
1128 void helper_stq_raw(uint64_t t0
, uint64_t t1
)
1133 uint64_t helper_stl_c_raw(uint64_t t0
, uint64_t t1
)
1137 if (t1
== env
->lock
) {
1148 uint64_t helper_stq_c_raw(uint64_t t0
, uint64_t t1
)
1152 if (t1
== env
->lock
) {
1163 #define MMUSUFFIX _mmu
1166 #include "softmmu_template.h"
1169 #include "softmmu_template.h"
1172 #include "softmmu_template.h"
1175 #include "softmmu_template.h"
1177 /* try to fill the TLB and return an exception if error. If retaddr is
1178 NULL, it means that the function was called in C code (i.e. not
1179 from generated code or from helper.c) */
1180 /* XXX: fix it to restore all registers */
1181 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
1183 TranslationBlock
*tb
;
1184 CPUState
*saved_env
;
1188 /* XXX: hack to restore env in all cases, even if not called from
1191 env
= cpu_single_env
;
1192 ret
= cpu_alpha_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
1193 if (!likely(ret
== 0)) {
1194 if (likely(retaddr
)) {
1195 /* now we have a real cpu fault */
1196 pc
= (unsigned long)retaddr
;
1197 tb
= tb_find_pc(pc
);
1199 /* the PC is inside the translated code. It means that we have
1200 a virtual CPU fault */
1201 cpu_restore_state(tb
, env
, pc
, NULL
);
1204 /* Exception index and error code are already set */