]>
git.proxmox.com Git - qemu.git/blob - target-alpha/op_helper.c
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 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_fpcr (void)
64 #ifdef CONFIG_SOFTFLOAT
65 ret
|= env
->fp_status
.float_exception_flags
<< 52;
66 if (env
->fp_status
.float_exception_flags
)
68 env
->ipr
[IPR_EXC_SUM
] &= ~0x3E:
69 env
->ipr
[IPR_EXC_SUM
] |= env
->fp_status
.float_exception_flags
<< 1;
71 switch (env
->fp_status
.float_rounding_mode
) {
72 case float_round_nearest_even
:
75 case float_round_down
:
81 case float_round_to_zero
:
87 void helper_store_fpcr (uint64_t val
)
89 #ifdef CONFIG_SOFTFLOAT
90 set_float_exception_flags((val
>> 52) & 0x3F, &FP_STATUS
);
92 switch ((val
>> 58) & 3) {
94 set_float_rounding_mode(float_round_to_zero
, &FP_STATUS
);
97 set_float_rounding_mode(float_round_down
, &FP_STATUS
);
100 set_float_rounding_mode(float_round_nearest_even
, &FP_STATUS
);
103 set_float_rounding_mode(float_round_up
, &FP_STATUS
);
108 spinlock_t intr_cpu_lock
= SPIN_LOCK_UNLOCKED
;
110 uint64_t helper_rs(void)
114 spin_lock(&intr_cpu_lock
);
115 tmp
= env
->intr_flag
;
117 spin_unlock(&intr_cpu_lock
);
122 uint64_t helper_rc(void)
126 spin_lock(&intr_cpu_lock
);
127 tmp
= env
->intr_flag
;
129 spin_unlock(&intr_cpu_lock
);
134 uint64_t helper_addqv (uint64_t op1
, uint64_t op2
)
138 if (unlikely((tmp
^ op2
^ (-1ULL)) & (tmp
^ op1
) & (1ULL << 63))) {
139 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
144 uint64_t helper_addlv (uint64_t op1
, uint64_t op2
)
147 op1
= (uint32_t)(op1
+ op2
);
148 if (unlikely((tmp
^ op2
^ (-1UL)) & (tmp
^ op1
) & (1UL << 31))) {
149 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
154 uint64_t helper_subqv (uint64_t op1
, uint64_t op2
)
158 if (unlikely((op1
^ op2
) & (res
^ op1
) & (1ULL << 63))) {
159 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
164 uint64_t helper_sublv (uint64_t op1
, uint64_t op2
)
168 if (unlikely((op1
^ op2
) & (res
^ op1
) & (1UL << 31))) {
169 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
174 uint64_t helper_mullv (uint64_t op1
, uint64_t op2
)
176 int64_t res
= (int64_t)op1
* (int64_t)op2
;
178 if (unlikely((int32_t)res
!= res
)) {
179 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
181 return (int64_t)((int32_t)res
);
184 uint64_t helper_mulqv (uint64_t op1
, uint64_t op2
)
188 muls64(&tl
, &th
, op1
, op2
);
189 /* If th != 0 && th != -1, then we had an overflow */
190 if (unlikely((th
+ 1) > 1)) {
191 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
196 uint64_t helper_umulh (uint64_t op1
, uint64_t op2
)
200 mulu64(&tl
, &th
, op1
, op2
);
204 uint64_t helper_ctpop (uint64_t arg
)
209 uint64_t helper_ctlz (uint64_t arg
)
214 uint64_t helper_cttz (uint64_t arg
)
219 static always_inline
uint64_t byte_zap (uint64_t op
, uint8_t mskb
)
224 mask
|= ((mskb
>> 0) & 1) * 0x00000000000000FFULL
;
225 mask
|= ((mskb
>> 1) & 1) * 0x000000000000FF00ULL
;
226 mask
|= ((mskb
>> 2) & 1) * 0x0000000000FF0000ULL
;
227 mask
|= ((mskb
>> 3) & 1) * 0x00000000FF000000ULL
;
228 mask
|= ((mskb
>> 4) & 1) * 0x000000FF00000000ULL
;
229 mask
|= ((mskb
>> 5) & 1) * 0x0000FF0000000000ULL
;
230 mask
|= ((mskb
>> 6) & 1) * 0x00FF000000000000ULL
;
231 mask
|= ((mskb
>> 7) & 1) * 0xFF00000000000000ULL
;
236 uint64_t helper_mskbl(uint64_t val
, uint64_t mask
)
238 return byte_zap(val
, 0x01 << (mask
& 7));
241 uint64_t helper_insbl(uint64_t val
, uint64_t mask
)
243 val
<<= (mask
& 7) * 8;
244 return byte_zap(val
, ~(0x01 << (mask
& 7)));
247 uint64_t helper_mskwl(uint64_t val
, uint64_t mask
)
249 return byte_zap(val
, 0x03 << (mask
& 7));
252 uint64_t helper_inswl(uint64_t val
, uint64_t mask
)
254 val
<<= (mask
& 7) * 8;
255 return byte_zap(val
, ~(0x03 << (mask
& 7)));
258 uint64_t helper_mskll(uint64_t val
, uint64_t mask
)
260 return byte_zap(val
, 0x0F << (mask
& 7));
263 uint64_t helper_insll(uint64_t val
, uint64_t mask
)
265 val
<<= (mask
& 7) * 8;
266 return byte_zap(val
, ~(0x0F << (mask
& 7)));
269 uint64_t helper_zap(uint64_t val
, uint64_t mask
)
271 return byte_zap(val
, mask
);
274 uint64_t helper_zapnot(uint64_t val
, uint64_t mask
)
276 return byte_zap(val
, ~mask
);
279 uint64_t helper_mskql(uint64_t val
, uint64_t mask
)
281 return byte_zap(val
, 0xFF << (mask
& 7));
284 uint64_t helper_insql(uint64_t val
, uint64_t mask
)
286 val
<<= (mask
& 7) * 8;
287 return byte_zap(val
, ~(0xFF << (mask
& 7)));
290 uint64_t helper_mskwh(uint64_t val
, uint64_t mask
)
292 return byte_zap(val
, (0x03 << (mask
& 7)) >> 8);
295 uint64_t helper_inswh(uint64_t val
, uint64_t mask
)
297 val
>>= 64 - ((mask
& 7) * 8);
298 return byte_zap(val
, ~((0x03 << (mask
& 7)) >> 8));
301 uint64_t helper_msklh(uint64_t val
, uint64_t mask
)
303 return byte_zap(val
, (0x0F << (mask
& 7)) >> 8);
306 uint64_t helper_inslh(uint64_t val
, uint64_t mask
)
308 val
>>= 64 - ((mask
& 7) * 8);
309 return byte_zap(val
, ~((0x0F << (mask
& 7)) >> 8));
312 uint64_t helper_mskqh(uint64_t val
, uint64_t mask
)
314 return byte_zap(val
, (0xFF << (mask
& 7)) >> 8);
317 uint64_t helper_insqh(uint64_t val
, uint64_t mask
)
319 val
>>= 64 - ((mask
& 7) * 8);
320 return byte_zap(val
, ~((0xFF << (mask
& 7)) >> 8));
323 uint64_t helper_cmpbge (uint64_t op1
, uint64_t op2
)
325 uint8_t opa
, opb
, res
;
329 for (i
= 0; i
< 8; i
++) {
330 opa
= op1
>> (i
* 8);
331 opb
= op2
>> (i
* 8);
338 /* Floating point helpers */
340 /* F floating (VAX) */
341 static always_inline
uint64_t float32_to_f (float32 fa
)
343 uint64_t r
, exp
, mant
, sig
;
347 sig
= ((uint64_t)a
.l
& 0x80000000) << 32;
348 exp
= (a
.l
>> 23) & 0xff;
349 mant
= ((uint64_t)a
.l
& 0x007fffff) << 29;
352 /* NaN or infinity */
353 r
= 1; /* VAX dirty zero */
354 } else if (exp
== 0) {
360 r
= sig
| ((exp
+ 1) << 52) | mant
;
365 r
= 1; /* VAX dirty zero */
367 r
= sig
| ((exp
+ 2) << 52);
374 static always_inline float32
f_to_float32 (uint64_t a
)
376 uint32_t exp
, mant_sig
;
379 exp
= ((a
>> 55) & 0x80) | ((a
>> 52) & 0x7f);
380 mant_sig
= ((a
>> 32) & 0x80000000) | ((a
>> 29) & 0x007fffff);
382 if (unlikely(!exp
&& mant_sig
)) {
383 /* Reserved operands / Dirty zero */
384 helper_excp(EXCP_OPCDEC
, 0);
391 r
.l
= ((exp
- 2) << 23) | mant_sig
;
397 uint32_t helper_f_to_memory (uint64_t a
)
400 r
= (a
& 0x00001fffe0000000ull
) >> 13;
401 r
|= (a
& 0x07ffe00000000000ull
) >> 45;
402 r
|= (a
& 0xc000000000000000ull
) >> 48;
406 uint64_t helper_memory_to_f (uint32_t a
)
409 r
= ((uint64_t)(a
& 0x0000c000)) << 48;
410 r
|= ((uint64_t)(a
& 0x003fffff)) << 45;
411 r
|= ((uint64_t)(a
& 0xffff0000)) << 13;
412 if (!(a
& 0x00004000))
417 uint64_t helper_addf (uint64_t a
, uint64_t b
)
421 fa
= f_to_float32(a
);
422 fb
= f_to_float32(b
);
423 fr
= float32_add(fa
, fb
, &FP_STATUS
);
424 return float32_to_f(fr
);
427 uint64_t helper_subf (uint64_t a
, uint64_t b
)
431 fa
= f_to_float32(a
);
432 fb
= f_to_float32(b
);
433 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
434 return float32_to_f(fr
);
437 uint64_t helper_mulf (uint64_t a
, uint64_t b
)
441 fa
= f_to_float32(a
);
442 fb
= f_to_float32(b
);
443 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
444 return float32_to_f(fr
);
447 uint64_t helper_divf (uint64_t a
, uint64_t b
)
451 fa
= f_to_float32(a
);
452 fb
= f_to_float32(b
);
453 fr
= float32_div(fa
, fb
, &FP_STATUS
);
454 return float32_to_f(fr
);
457 uint64_t helper_sqrtf (uint64_t t
)
461 ft
= f_to_float32(t
);
462 fr
= float32_sqrt(ft
, &FP_STATUS
);
463 return float32_to_f(fr
);
467 /* G floating (VAX) */
468 static always_inline
uint64_t float64_to_g (float64 fa
)
470 uint64_t r
, exp
, mant
, sig
;
474 sig
= a
.ll
& 0x8000000000000000ull
;
475 exp
= (a
.ll
>> 52) & 0x7ff;
476 mant
= a
.ll
& 0x000fffffffffffffull
;
479 /* NaN or infinity */
480 r
= 1; /* VAX dirty zero */
481 } else if (exp
== 0) {
487 r
= sig
| ((exp
+ 1) << 52) | mant
;
492 r
= 1; /* VAX dirty zero */
494 r
= sig
| ((exp
+ 2) << 52);
501 static always_inline float64
g_to_float64 (uint64_t a
)
503 uint64_t exp
, mant_sig
;
506 exp
= (a
>> 52) & 0x7ff;
507 mant_sig
= a
& 0x800fffffffffffffull
;
509 if (!exp
&& mant_sig
) {
510 /* Reserved operands / Dirty zero */
511 helper_excp(EXCP_OPCDEC
, 0);
518 r
.ll
= ((exp
- 2) << 52) | mant_sig
;
524 uint64_t helper_g_to_memory (uint64_t a
)
527 r
= (a
& 0x000000000000ffffull
) << 48;
528 r
|= (a
& 0x00000000ffff0000ull
) << 16;
529 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
530 r
|= (a
& 0xffff000000000000ull
) >> 48;
534 uint64_t helper_memory_to_g (uint64_t a
)
537 r
= (a
& 0x000000000000ffffull
) << 48;
538 r
|= (a
& 0x00000000ffff0000ull
) << 16;
539 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
540 r
|= (a
& 0xffff000000000000ull
) >> 48;
544 uint64_t helper_addg (uint64_t a
, uint64_t b
)
548 fa
= g_to_float64(a
);
549 fb
= g_to_float64(b
);
550 fr
= float64_add(fa
, fb
, &FP_STATUS
);
551 return float64_to_g(fr
);
554 uint64_t helper_subg (uint64_t a
, uint64_t b
)
558 fa
= g_to_float64(a
);
559 fb
= g_to_float64(b
);
560 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
561 return float64_to_g(fr
);
564 uint64_t helper_mulg (uint64_t a
, uint64_t b
)
568 fa
= g_to_float64(a
);
569 fb
= g_to_float64(b
);
570 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
571 return float64_to_g(fr
);
574 uint64_t helper_divg (uint64_t a
, uint64_t b
)
578 fa
= g_to_float64(a
);
579 fb
= g_to_float64(b
);
580 fr
= float64_div(fa
, fb
, &FP_STATUS
);
581 return float64_to_g(fr
);
584 uint64_t helper_sqrtg (uint64_t a
)
588 fa
= g_to_float64(a
);
589 fr
= float64_sqrt(fa
, &FP_STATUS
);
590 return float64_to_g(fr
);
594 /* S floating (single) */
595 static always_inline
uint64_t float32_to_s (float32 fa
)
602 r
= (((uint64_t)(a
.l
& 0xc0000000)) << 32) | (((uint64_t)(a
.l
& 0x3fffffff)) << 29);
603 if (((a
.l
& 0x7f800000) != 0x7f800000) && (!(a
.l
& 0x40000000)))
608 static always_inline float32
s_to_float32 (uint64_t a
)
611 r
.l
= ((a
>> 32) & 0xc0000000) | ((a
>> 29) & 0x3fffffff);
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 */
687 static always_inline
uint64_t float64_to_t (float64 fa
)
689 /* Memory format is the same as float64 */
695 uint64_t helper_addt (uint64_t a
, uint64_t b
)
699 fa
= t_to_float64(a
);
700 fb
= t_to_float64(b
);
701 fr
= float64_add(fa
, fb
, &FP_STATUS
);
702 return float64_to_t(fr
);
705 uint64_t helper_subt (uint64_t a
, uint64_t b
)
709 fa
= t_to_float64(a
);
710 fb
= t_to_float64(b
);
711 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
712 return float64_to_t(fr
);
715 uint64_t helper_mult (uint64_t a
, uint64_t b
)
719 fa
= t_to_float64(a
);
720 fb
= t_to_float64(b
);
721 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
722 return float64_to_t(fr
);
725 uint64_t helper_divt (uint64_t a
, uint64_t b
)
729 fa
= t_to_float64(a
);
730 fb
= t_to_float64(b
);
731 fr
= float64_div(fa
, fb
, &FP_STATUS
);
732 return float64_to_t(fr
);
735 uint64_t helper_sqrtt (uint64_t a
)
739 fa
= t_to_float64(a
);
740 fr
= float64_sqrt(fa
, &FP_STATUS
);
741 return float64_to_t(fr
);
746 uint64_t helper_cpys(uint64_t a
, uint64_t b
)
748 return (a
& 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
751 uint64_t helper_cpysn(uint64_t a
, uint64_t b
)
753 return ((~a
) & 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
756 uint64_t helper_cpyse(uint64_t a
, uint64_t b
)
758 return (a
& 0xFFF0000000000000ULL
) | (b
& ~0xFFF0000000000000ULL
);
763 uint64_t helper_cmptun (uint64_t a
, uint64_t b
)
767 fa
= t_to_float64(a
);
768 fb
= t_to_float64(b
);
770 if (float64_is_nan(fa
) || float64_is_nan(fb
))
771 return 0x4000000000000000ULL
;
776 uint64_t helper_cmpteq(uint64_t a
, uint64_t b
)
780 fa
= t_to_float64(a
);
781 fb
= t_to_float64(b
);
783 if (float64_eq(fa
, fb
, &FP_STATUS
))
784 return 0x4000000000000000ULL
;
789 uint64_t helper_cmptle(uint64_t a
, uint64_t b
)
793 fa
= t_to_float64(a
);
794 fb
= t_to_float64(b
);
796 if (float64_le(fa
, fb
, &FP_STATUS
))
797 return 0x4000000000000000ULL
;
802 uint64_t helper_cmptlt(uint64_t a
, uint64_t b
)
806 fa
= t_to_float64(a
);
807 fb
= t_to_float64(b
);
809 if (float64_lt(fa
, fb
, &FP_STATUS
))
810 return 0x4000000000000000ULL
;
815 uint64_t helper_cmpgeq(uint64_t a
, uint64_t b
)
819 fa
= g_to_float64(a
);
820 fb
= g_to_float64(b
);
822 if (float64_eq(fa
, fb
, &FP_STATUS
))
823 return 0x4000000000000000ULL
;
828 uint64_t helper_cmpgle(uint64_t a
, uint64_t b
)
832 fa
= g_to_float64(a
);
833 fb
= g_to_float64(b
);
835 if (float64_le(fa
, fb
, &FP_STATUS
))
836 return 0x4000000000000000ULL
;
841 uint64_t helper_cmpglt(uint64_t a
, uint64_t b
)
845 fa
= g_to_float64(a
);
846 fb
= g_to_float64(b
);
848 if (float64_lt(fa
, fb
, &FP_STATUS
))
849 return 0x4000000000000000ULL
;
854 uint64_t helper_cmpfeq (uint64_t a
)
856 return !(a
& 0x7FFFFFFFFFFFFFFFULL
);
859 uint64_t helper_cmpfne (uint64_t a
)
861 return (a
& 0x7FFFFFFFFFFFFFFFULL
);
864 uint64_t helper_cmpflt (uint64_t a
)
866 return (a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
869 uint64_t helper_cmpfle (uint64_t a
)
871 return (a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
874 uint64_t helper_cmpfgt (uint64_t a
)
876 return !(a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
879 uint64_t helper_cmpfge (uint64_t a
)
881 return !(a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
885 /* Floating point format conversion */
886 uint64_t helper_cvtts (uint64_t a
)
891 fa
= t_to_float64(a
);
892 fr
= float64_to_float32(fa
, &FP_STATUS
);
893 return float32_to_s(fr
);
896 uint64_t helper_cvtst (uint64_t a
)
901 fa
= s_to_float32(a
);
902 fr
= float32_to_float64(fa
, &FP_STATUS
);
903 return float64_to_t(fr
);
906 uint64_t helper_cvtqs (uint64_t a
)
908 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
909 return float32_to_s(fr
);
912 uint64_t helper_cvttq (uint64_t a
)
914 float64 fa
= t_to_float64(a
);
915 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
918 uint64_t helper_cvtqt (uint64_t a
)
920 float64 fr
= int64_to_float64(a
, &FP_STATUS
);
921 return float64_to_t(fr
);
924 uint64_t helper_cvtqf (uint64_t a
)
926 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
927 return float32_to_f(fr
);
930 uint64_t helper_cvtgf (uint64_t a
)
935 fa
= g_to_float64(a
);
936 fr
= float64_to_float32(fa
, &FP_STATUS
);
937 return float32_to_f(fr
);
940 uint64_t helper_cvtgq (uint64_t a
)
942 float64 fa
= g_to_float64(a
);
943 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
946 uint64_t helper_cvtqg (uint64_t a
)
949 fr
= int64_to_float64(a
, &FP_STATUS
);
950 return float64_to_g(fr
);
953 uint64_t helper_cvtlq (uint64_t a
)
955 return (int64_t)((int32_t)((a
>> 32) | ((a
>> 29) & 0x3FFFFFFF)));
958 static always_inline
uint64_t __helper_cvtql (uint64_t a
, int s
, int v
)
962 r
= ((uint64_t)(a
& 0xC0000000)) << 32;
963 r
|= ((uint64_t)(a
& 0x7FFFFFFF)) << 29;
965 if (v
&& (int64_t)((int32_t)r
) != (int64_t)r
) {
966 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
974 uint64_t helper_cvtql (uint64_t a
)
976 return __helper_cvtql(a
, 0, 0);
979 uint64_t helper_cvtqlv (uint64_t a
)
981 return __helper_cvtql(a
, 0, 1);
984 uint64_t helper_cvtqlsv (uint64_t a
)
986 return __helper_cvtql(a
, 1, 1);
989 /* PALcode support special instructions */
990 #if !defined (CONFIG_USER_ONLY)
991 void helper_hw_rei (void)
993 env
->pc
= env
->ipr
[IPR_EXC_ADDR
] & ~3;
994 env
->ipr
[IPR_EXC_ADDR
] = env
->ipr
[IPR_EXC_ADDR
] & 1;
995 /* XXX: re-enable interrupts and memory mapping */
998 void helper_hw_ret (uint64_t a
)
1001 env
->ipr
[IPR_EXC_ADDR
] = a
& 1;
1002 /* XXX: re-enable interrupts and memory mapping */
1005 uint64_t helper_mfpr (int iprn
, uint64_t val
)
1009 if (cpu_alpha_mfpr(env
, iprn
, &tmp
) == 0)
1015 void helper_mtpr (int iprn
, uint64_t val
)
1017 cpu_alpha_mtpr(env
, iprn
, val
, NULL
);
1020 void helper_set_alt_mode (void)
1022 env
->saved_mode
= env
->ps
& 0xC;
1023 env
->ps
= (env
->ps
& ~0xC) | (env
->ipr
[IPR_ALT_MODE
] & 0xC);
1026 void helper_restore_mode (void)
1028 env
->ps
= (env
->ps
& ~0xC) | env
->saved_mode
;
1033 /*****************************************************************************/
1034 /* Softmmu support */
1035 #if !defined (CONFIG_USER_ONLY)
1037 /* XXX: the two following helpers are pure hacks.
1038 * Hopefully, we emulate the PALcode, then we should never see
1039 * HW_LD / HW_ST instructions.
1041 uint64_t helper_ld_virt_to_phys (uint64_t virtaddr
)
1043 uint64_t tlb_addr
, physaddr
;
1047 mmu_idx
= cpu_mmu_index(env
);
1048 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1050 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_read
;
1051 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1052 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1053 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1055 /* the page is not in the TLB : fill it */
1057 tlb_fill(virtaddr
, 0, mmu_idx
, retaddr
);
1063 uint64_t helper_st_virt_to_phys (uint64_t virtaddr
)
1065 uint64_t tlb_addr
, physaddr
;
1069 mmu_idx
= cpu_mmu_index(env
);
1070 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1072 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_write
;
1073 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1074 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1075 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1077 /* the page is not in the TLB : fill it */
1079 tlb_fill(virtaddr
, 1, mmu_idx
, retaddr
);
1085 void helper_ldl_raw(uint64_t t0
, uint64_t t1
)
1090 void helper_ldq_raw(uint64_t t0
, uint64_t t1
)
1095 void helper_ldl_l_raw(uint64_t t0
, uint64_t t1
)
1101 void helper_ldq_l_raw(uint64_t t0
, uint64_t t1
)
1107 void helper_ldl_kernel(uint64_t t0
, uint64_t t1
)
1112 void helper_ldq_kernel(uint64_t t0
, uint64_t t1
)
1117 void helper_ldl_data(uint64_t t0
, uint64_t t1
)
1122 void helper_ldq_data(uint64_t t0
, uint64_t t1
)
1127 void helper_stl_raw(uint64_t t0
, uint64_t t1
)
1132 void helper_stq_raw(uint64_t t0
, uint64_t t1
)
1137 uint64_t helper_stl_c_raw(uint64_t t0
, uint64_t t1
)
1141 if (t1
== env
->lock
) {
1152 uint64_t helper_stq_c_raw(uint64_t t0
, uint64_t t1
)
1156 if (t1
== env
->lock
) {
1167 #define MMUSUFFIX _mmu
1170 #include "softmmu_template.h"
1173 #include "softmmu_template.h"
1176 #include "softmmu_template.h"
1179 #include "softmmu_template.h"
1181 /* try to fill the TLB and return an exception if error. If retaddr is
1182 NULL, it means that the function was called in C code (i.e. not
1183 from generated code or from helper.c) */
1184 /* XXX: fix it to restore all registers */
1185 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
1187 TranslationBlock
*tb
;
1188 CPUState
*saved_env
;
1192 /* XXX: hack to restore env in all cases, even if not called from
1195 env
= cpu_single_env
;
1196 ret
= cpu_alpha_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
1197 if (!likely(ret
== 0)) {
1198 if (likely(retaddr
)) {
1199 /* now we have a real cpu fault */
1200 pc
= (unsigned long)retaddr
;
1201 tb
= tb_find_pc(pc
);
1203 /* the PC is inside the translated code. It means that we have
1204 a virtual CPU fault */
1205 cpu_restore_state(tb
, env
, pc
, NULL
);
1208 /* Exception index and error code are already set */