]>
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, 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_mskbl(uint64_t val
, uint64_t mask
)
180 return byte_zap(val
, 0x01 << (mask
& 7));
183 uint64_t helper_insbl(uint64_t val
, uint64_t mask
)
185 val
<<= (mask
& 7) * 8;
186 return byte_zap(val
, ~(0x01 << (mask
& 7)));
189 uint64_t helper_mskwl(uint64_t val
, uint64_t mask
)
191 return byte_zap(val
, 0x03 << (mask
& 7));
194 uint64_t helper_inswl(uint64_t val
, uint64_t mask
)
196 val
<<= (mask
& 7) * 8;
197 return byte_zap(val
, ~(0x03 << (mask
& 7)));
200 uint64_t helper_mskll(uint64_t val
, uint64_t mask
)
202 return byte_zap(val
, 0x0F << (mask
& 7));
205 uint64_t helper_insll(uint64_t val
, uint64_t mask
)
207 val
<<= (mask
& 7) * 8;
208 return byte_zap(val
, ~(0x0F << (mask
& 7)));
211 uint64_t helper_zap(uint64_t val
, uint64_t mask
)
213 return byte_zap(val
, mask
);
216 uint64_t helper_zapnot(uint64_t val
, uint64_t mask
)
218 return byte_zap(val
, ~mask
);
221 uint64_t helper_mskql(uint64_t val
, uint64_t mask
)
223 return byte_zap(val
, 0xFF << (mask
& 7));
226 uint64_t helper_insql(uint64_t val
, uint64_t mask
)
228 val
<<= (mask
& 7) * 8;
229 return byte_zap(val
, ~(0xFF << (mask
& 7)));
232 uint64_t helper_mskwh(uint64_t val
, uint64_t mask
)
234 return byte_zap(val
, (0x03 << (mask
& 7)) >> 8);
237 uint64_t helper_inswh(uint64_t val
, uint64_t mask
)
239 val
>>= 64 - ((mask
& 7) * 8);
240 return byte_zap(val
, ~((0x03 << (mask
& 7)) >> 8));
243 uint64_t helper_msklh(uint64_t val
, uint64_t mask
)
245 return byte_zap(val
, (0x0F << (mask
& 7)) >> 8);
248 uint64_t helper_inslh(uint64_t val
, uint64_t mask
)
250 val
>>= 64 - ((mask
& 7) * 8);
251 return byte_zap(val
, ~((0x0F << (mask
& 7)) >> 8));
254 uint64_t helper_mskqh(uint64_t val
, uint64_t mask
)
256 return byte_zap(val
, (0xFF << (mask
& 7)) >> 8);
259 uint64_t helper_insqh(uint64_t val
, uint64_t mask
)
261 val
>>= 64 - ((mask
& 7) * 8);
262 return byte_zap(val
, ~((0xFF << (mask
& 7)) >> 8));
265 uint64_t helper_cmpbge (uint64_t op1
, uint64_t op2
)
267 uint8_t opa
, opb
, res
;
271 for (i
= 0; i
< 8; i
++) {
272 opa
= op1
>> (i
* 8);
273 opb
= op2
>> (i
* 8);
280 /* Floating point helpers */
282 /* F floating (VAX) */
283 static inline uint64_t float32_to_f(float32 fa
)
285 uint64_t r
, exp
, mant
, sig
;
289 sig
= ((uint64_t)a
.l
& 0x80000000) << 32;
290 exp
= (a
.l
>> 23) & 0xff;
291 mant
= ((uint64_t)a
.l
& 0x007fffff) << 29;
294 /* NaN or infinity */
295 r
= 1; /* VAX dirty zero */
296 } else if (exp
== 0) {
302 r
= sig
| ((exp
+ 1) << 52) | mant
;
307 r
= 1; /* VAX dirty zero */
309 r
= sig
| ((exp
+ 2) << 52);
316 static inline float32
f_to_float32(uint64_t a
)
318 uint32_t exp
, mant_sig
;
321 exp
= ((a
>> 55) & 0x80) | ((a
>> 52) & 0x7f);
322 mant_sig
= ((a
>> 32) & 0x80000000) | ((a
>> 29) & 0x007fffff);
324 if (unlikely(!exp
&& mant_sig
)) {
325 /* Reserved operands / Dirty zero */
326 helper_excp(EXCP_OPCDEC
, 0);
333 r
.l
= ((exp
- 2) << 23) | mant_sig
;
339 uint32_t helper_f_to_memory (uint64_t a
)
342 r
= (a
& 0x00001fffe0000000ull
) >> 13;
343 r
|= (a
& 0x07ffe00000000000ull
) >> 45;
344 r
|= (a
& 0xc000000000000000ull
) >> 48;
348 uint64_t helper_memory_to_f (uint32_t a
)
351 r
= ((uint64_t)(a
& 0x0000c000)) << 48;
352 r
|= ((uint64_t)(a
& 0x003fffff)) << 45;
353 r
|= ((uint64_t)(a
& 0xffff0000)) << 13;
354 if (!(a
& 0x00004000))
359 uint64_t helper_addf (uint64_t a
, uint64_t b
)
363 fa
= f_to_float32(a
);
364 fb
= f_to_float32(b
);
365 fr
= float32_add(fa
, fb
, &FP_STATUS
);
366 return float32_to_f(fr
);
369 uint64_t helper_subf (uint64_t a
, uint64_t b
)
373 fa
= f_to_float32(a
);
374 fb
= f_to_float32(b
);
375 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
376 return float32_to_f(fr
);
379 uint64_t helper_mulf (uint64_t a
, uint64_t b
)
383 fa
= f_to_float32(a
);
384 fb
= f_to_float32(b
);
385 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
386 return float32_to_f(fr
);
389 uint64_t helper_divf (uint64_t a
, uint64_t b
)
393 fa
= f_to_float32(a
);
394 fb
= f_to_float32(b
);
395 fr
= float32_div(fa
, fb
, &FP_STATUS
);
396 return float32_to_f(fr
);
399 uint64_t helper_sqrtf (uint64_t t
)
403 ft
= f_to_float32(t
);
404 fr
= float32_sqrt(ft
, &FP_STATUS
);
405 return float32_to_f(fr
);
409 /* G floating (VAX) */
410 static inline uint64_t float64_to_g(float64 fa
)
412 uint64_t r
, exp
, mant
, sig
;
416 sig
= a
.ll
& 0x8000000000000000ull
;
417 exp
= (a
.ll
>> 52) & 0x7ff;
418 mant
= a
.ll
& 0x000fffffffffffffull
;
421 /* NaN or infinity */
422 r
= 1; /* VAX dirty zero */
423 } else if (exp
== 0) {
429 r
= sig
| ((exp
+ 1) << 52) | mant
;
434 r
= 1; /* VAX dirty zero */
436 r
= sig
| ((exp
+ 2) << 52);
443 static inline float64
g_to_float64(uint64_t a
)
445 uint64_t exp
, mant_sig
;
448 exp
= (a
>> 52) & 0x7ff;
449 mant_sig
= a
& 0x800fffffffffffffull
;
451 if (!exp
&& mant_sig
) {
452 /* Reserved operands / Dirty zero */
453 helper_excp(EXCP_OPCDEC
, 0);
460 r
.ll
= ((exp
- 2) << 52) | mant_sig
;
466 uint64_t helper_g_to_memory (uint64_t a
)
469 r
= (a
& 0x000000000000ffffull
) << 48;
470 r
|= (a
& 0x00000000ffff0000ull
) << 16;
471 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
472 r
|= (a
& 0xffff000000000000ull
) >> 48;
476 uint64_t helper_memory_to_g (uint64_t a
)
479 r
= (a
& 0x000000000000ffffull
) << 48;
480 r
|= (a
& 0x00000000ffff0000ull
) << 16;
481 r
|= (a
& 0x0000ffff00000000ull
) >> 16;
482 r
|= (a
& 0xffff000000000000ull
) >> 48;
486 uint64_t helper_addg (uint64_t a
, uint64_t b
)
490 fa
= g_to_float64(a
);
491 fb
= g_to_float64(b
);
492 fr
= float64_add(fa
, fb
, &FP_STATUS
);
493 return float64_to_g(fr
);
496 uint64_t helper_subg (uint64_t a
, uint64_t b
)
500 fa
= g_to_float64(a
);
501 fb
= g_to_float64(b
);
502 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
503 return float64_to_g(fr
);
506 uint64_t helper_mulg (uint64_t a
, uint64_t b
)
510 fa
= g_to_float64(a
);
511 fb
= g_to_float64(b
);
512 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
513 return float64_to_g(fr
);
516 uint64_t helper_divg (uint64_t a
, uint64_t b
)
520 fa
= g_to_float64(a
);
521 fb
= g_to_float64(b
);
522 fr
= float64_div(fa
, fb
, &FP_STATUS
);
523 return float64_to_g(fr
);
526 uint64_t helper_sqrtg (uint64_t a
)
530 fa
= g_to_float64(a
);
531 fr
= float64_sqrt(fa
, &FP_STATUS
);
532 return float64_to_g(fr
);
536 /* S floating (single) */
537 static inline uint64_t float32_to_s(float32 fa
)
544 r
= (((uint64_t)(a
.l
& 0xc0000000)) << 32) | (((uint64_t)(a
.l
& 0x3fffffff)) << 29);
545 if (((a
.l
& 0x7f800000) != 0x7f800000) && (!(a
.l
& 0x40000000)))
550 static inline float32
s_to_float32(uint64_t a
)
553 r
.l
= ((a
>> 32) & 0xc0000000) | ((a
>> 29) & 0x3fffffff);
557 uint32_t helper_s_to_memory (uint64_t a
)
559 /* Memory format is the same as float32 */
560 float32 fa
= s_to_float32(a
);
561 return *(uint32_t*)(&fa
);
564 uint64_t helper_memory_to_s (uint32_t a
)
566 /* Memory format is the same as float32 */
567 return float32_to_s(*(float32
*)(&a
));
570 uint64_t helper_adds (uint64_t a
, uint64_t b
)
574 fa
= s_to_float32(a
);
575 fb
= s_to_float32(b
);
576 fr
= float32_add(fa
, fb
, &FP_STATUS
);
577 return float32_to_s(fr
);
580 uint64_t helper_subs (uint64_t a
, uint64_t b
)
584 fa
= s_to_float32(a
);
585 fb
= s_to_float32(b
);
586 fr
= float32_sub(fa
, fb
, &FP_STATUS
);
587 return float32_to_s(fr
);
590 uint64_t helper_muls (uint64_t a
, uint64_t b
)
594 fa
= s_to_float32(a
);
595 fb
= s_to_float32(b
);
596 fr
= float32_mul(fa
, fb
, &FP_STATUS
);
597 return float32_to_s(fr
);
600 uint64_t helper_divs (uint64_t a
, uint64_t b
)
604 fa
= s_to_float32(a
);
605 fb
= s_to_float32(b
);
606 fr
= float32_div(fa
, fb
, &FP_STATUS
);
607 return float32_to_s(fr
);
610 uint64_t helper_sqrts (uint64_t a
)
614 fa
= s_to_float32(a
);
615 fr
= float32_sqrt(fa
, &FP_STATUS
);
616 return float32_to_s(fr
);
620 /* T floating (double) */
621 static inline float64
t_to_float64(uint64_t a
)
623 /* Memory format is the same as float64 */
629 static inline uint64_t float64_to_t(float64 fa
)
631 /* Memory format is the same as float64 */
637 uint64_t helper_addt (uint64_t a
, uint64_t b
)
641 fa
= t_to_float64(a
);
642 fb
= t_to_float64(b
);
643 fr
= float64_add(fa
, fb
, &FP_STATUS
);
644 return float64_to_t(fr
);
647 uint64_t helper_subt (uint64_t a
, uint64_t b
)
651 fa
= t_to_float64(a
);
652 fb
= t_to_float64(b
);
653 fr
= float64_sub(fa
, fb
, &FP_STATUS
);
654 return float64_to_t(fr
);
657 uint64_t helper_mult (uint64_t a
, uint64_t b
)
661 fa
= t_to_float64(a
);
662 fb
= t_to_float64(b
);
663 fr
= float64_mul(fa
, fb
, &FP_STATUS
);
664 return float64_to_t(fr
);
667 uint64_t helper_divt (uint64_t a
, uint64_t b
)
671 fa
= t_to_float64(a
);
672 fb
= t_to_float64(b
);
673 fr
= float64_div(fa
, fb
, &FP_STATUS
);
674 return float64_to_t(fr
);
677 uint64_t helper_sqrtt (uint64_t a
)
681 fa
= t_to_float64(a
);
682 fr
= float64_sqrt(fa
, &FP_STATUS
);
683 return float64_to_t(fr
);
688 uint64_t helper_cpys(uint64_t a
, uint64_t b
)
690 return (a
& 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
693 uint64_t helper_cpysn(uint64_t a
, uint64_t b
)
695 return ((~a
) & 0x8000000000000000ULL
) | (b
& ~0x8000000000000000ULL
);
698 uint64_t helper_cpyse(uint64_t a
, uint64_t b
)
700 return (a
& 0xFFF0000000000000ULL
) | (b
& ~0xFFF0000000000000ULL
);
705 uint64_t helper_cmptun (uint64_t a
, uint64_t b
)
709 fa
= t_to_float64(a
);
710 fb
= t_to_float64(b
);
712 if (float64_is_nan(fa
) || float64_is_nan(fb
))
713 return 0x4000000000000000ULL
;
718 uint64_t helper_cmpteq(uint64_t a
, uint64_t b
)
722 fa
= t_to_float64(a
);
723 fb
= t_to_float64(b
);
725 if (float64_eq(fa
, fb
, &FP_STATUS
))
726 return 0x4000000000000000ULL
;
731 uint64_t helper_cmptle(uint64_t a
, uint64_t b
)
735 fa
= t_to_float64(a
);
736 fb
= t_to_float64(b
);
738 if (float64_le(fa
, fb
, &FP_STATUS
))
739 return 0x4000000000000000ULL
;
744 uint64_t helper_cmptlt(uint64_t a
, uint64_t b
)
748 fa
= t_to_float64(a
);
749 fb
= t_to_float64(b
);
751 if (float64_lt(fa
, fb
, &FP_STATUS
))
752 return 0x4000000000000000ULL
;
757 uint64_t helper_cmpgeq(uint64_t a
, uint64_t b
)
761 fa
= g_to_float64(a
);
762 fb
= g_to_float64(b
);
764 if (float64_eq(fa
, fb
, &FP_STATUS
))
765 return 0x4000000000000000ULL
;
770 uint64_t helper_cmpgle(uint64_t a
, uint64_t b
)
774 fa
= g_to_float64(a
);
775 fb
= g_to_float64(b
);
777 if (float64_le(fa
, fb
, &FP_STATUS
))
778 return 0x4000000000000000ULL
;
783 uint64_t helper_cmpglt(uint64_t a
, uint64_t b
)
787 fa
= g_to_float64(a
);
788 fb
= g_to_float64(b
);
790 if (float64_lt(fa
, fb
, &FP_STATUS
))
791 return 0x4000000000000000ULL
;
796 uint64_t helper_cmpfeq (uint64_t a
)
798 return !(a
& 0x7FFFFFFFFFFFFFFFULL
);
801 uint64_t helper_cmpfne (uint64_t a
)
803 return (a
& 0x7FFFFFFFFFFFFFFFULL
);
806 uint64_t helper_cmpflt (uint64_t a
)
808 return (a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
811 uint64_t helper_cmpfle (uint64_t a
)
813 return (a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
816 uint64_t helper_cmpfgt (uint64_t a
)
818 return !(a
& 0x8000000000000000ULL
) && (a
& 0x7FFFFFFFFFFFFFFFULL
);
821 uint64_t helper_cmpfge (uint64_t a
)
823 return !(a
& 0x8000000000000000ULL
) || !(a
& 0x7FFFFFFFFFFFFFFFULL
);
827 /* Floating point format conversion */
828 uint64_t helper_cvtts (uint64_t a
)
833 fa
= t_to_float64(a
);
834 fr
= float64_to_float32(fa
, &FP_STATUS
);
835 return float32_to_s(fr
);
838 uint64_t helper_cvtst (uint64_t a
)
843 fa
= s_to_float32(a
);
844 fr
= float32_to_float64(fa
, &FP_STATUS
);
845 return float64_to_t(fr
);
848 uint64_t helper_cvtqs (uint64_t a
)
850 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
851 return float32_to_s(fr
);
854 uint64_t helper_cvttq (uint64_t a
)
856 float64 fa
= t_to_float64(a
);
857 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
860 uint64_t helper_cvtqt (uint64_t a
)
862 float64 fr
= int64_to_float64(a
, &FP_STATUS
);
863 return float64_to_t(fr
);
866 uint64_t helper_cvtqf (uint64_t a
)
868 float32 fr
= int64_to_float32(a
, &FP_STATUS
);
869 return float32_to_f(fr
);
872 uint64_t helper_cvtgf (uint64_t a
)
877 fa
= g_to_float64(a
);
878 fr
= float64_to_float32(fa
, &FP_STATUS
);
879 return float32_to_f(fr
);
882 uint64_t helper_cvtgq (uint64_t a
)
884 float64 fa
= g_to_float64(a
);
885 return float64_to_int64_round_to_zero(fa
, &FP_STATUS
);
888 uint64_t helper_cvtqg (uint64_t a
)
891 fr
= int64_to_float64(a
, &FP_STATUS
);
892 return float64_to_g(fr
);
895 uint64_t helper_cvtlq (uint64_t a
)
897 return (int64_t)((int32_t)((a
>> 32) | ((a
>> 29) & 0x3FFFFFFF)));
900 static inline uint64_t __helper_cvtql(uint64_t a
, int s
, int v
)
904 r
= ((uint64_t)(a
& 0xC0000000)) << 32;
905 r
|= ((uint64_t)(a
& 0x7FFFFFFF)) << 29;
907 if (v
&& (int64_t)((int32_t)r
) != (int64_t)r
) {
908 helper_excp(EXCP_ARITH
, EXCP_ARITH_OVERFLOW
);
916 uint64_t helper_cvtql (uint64_t a
)
918 return __helper_cvtql(a
, 0, 0);
921 uint64_t helper_cvtqlv (uint64_t a
)
923 return __helper_cvtql(a
, 0, 1);
926 uint64_t helper_cvtqlsv (uint64_t a
)
928 return __helper_cvtql(a
, 1, 1);
931 /* PALcode support special instructions */
932 #if !defined (CONFIG_USER_ONLY)
933 void helper_hw_rei (void)
935 env
->pc
= env
->ipr
[IPR_EXC_ADDR
] & ~3;
936 env
->ipr
[IPR_EXC_ADDR
] = env
->ipr
[IPR_EXC_ADDR
] & 1;
937 /* XXX: re-enable interrupts and memory mapping */
940 void helper_hw_ret (uint64_t a
)
943 env
->ipr
[IPR_EXC_ADDR
] = a
& 1;
944 /* XXX: re-enable interrupts and memory mapping */
947 uint64_t helper_mfpr (int iprn
, uint64_t val
)
951 if (cpu_alpha_mfpr(env
, iprn
, &tmp
) == 0)
957 void helper_mtpr (int iprn
, uint64_t val
)
959 cpu_alpha_mtpr(env
, iprn
, val
, NULL
);
962 void helper_set_alt_mode (void)
964 env
->saved_mode
= env
->ps
& 0xC;
965 env
->ps
= (env
->ps
& ~0xC) | (env
->ipr
[IPR_ALT_MODE
] & 0xC);
968 void helper_restore_mode (void)
970 env
->ps
= (env
->ps
& ~0xC) | env
->saved_mode
;
975 /*****************************************************************************/
976 /* Softmmu support */
977 #if !defined (CONFIG_USER_ONLY)
979 /* XXX: the two following helpers are pure hacks.
980 * Hopefully, we emulate the PALcode, then we should never see
981 * HW_LD / HW_ST instructions.
983 uint64_t helper_ld_virt_to_phys (uint64_t virtaddr
)
985 uint64_t tlb_addr
, physaddr
;
989 mmu_idx
= cpu_mmu_index(env
);
990 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
992 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_read
;
993 if ((virtaddr
& TARGET_PAGE_MASK
) ==
994 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
995 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
997 /* the page is not in the TLB : fill it */
999 tlb_fill(virtaddr
, 0, mmu_idx
, retaddr
);
1005 uint64_t helper_st_virt_to_phys (uint64_t virtaddr
)
1007 uint64_t tlb_addr
, physaddr
;
1011 mmu_idx
= cpu_mmu_index(env
);
1012 index
= (virtaddr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
1014 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_write
;
1015 if ((virtaddr
& TARGET_PAGE_MASK
) ==
1016 (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
1017 physaddr
= virtaddr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
1019 /* the page is not in the TLB : fill it */
1021 tlb_fill(virtaddr
, 1, mmu_idx
, retaddr
);
1027 void helper_ldl_raw(uint64_t t0
, uint64_t t1
)
1032 void helper_ldq_raw(uint64_t t0
, uint64_t t1
)
1037 void helper_ldl_l_raw(uint64_t t0
, uint64_t t1
)
1043 void helper_ldq_l_raw(uint64_t t0
, uint64_t t1
)
1049 void helper_ldl_kernel(uint64_t t0
, uint64_t t1
)
1054 void helper_ldq_kernel(uint64_t t0
, uint64_t t1
)
1059 void helper_ldl_data(uint64_t t0
, uint64_t t1
)
1064 void helper_ldq_data(uint64_t t0
, uint64_t t1
)
1069 void helper_stl_raw(uint64_t t0
, uint64_t t1
)
1074 void helper_stq_raw(uint64_t t0
, uint64_t t1
)
1079 uint64_t helper_stl_c_raw(uint64_t t0
, uint64_t t1
)
1083 if (t1
== env
->lock
) {
1094 uint64_t helper_stq_c_raw(uint64_t t0
, uint64_t t1
)
1098 if (t1
== env
->lock
) {
1109 #define MMUSUFFIX _mmu
1112 #include "softmmu_template.h"
1115 #include "softmmu_template.h"
1118 #include "softmmu_template.h"
1121 #include "softmmu_template.h"
1123 /* try to fill the TLB and return an exception if error. If retaddr is
1124 NULL, it means that the function was called in C code (i.e. not
1125 from generated code or from helper.c) */
1126 /* XXX: fix it to restore all registers */
1127 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
1129 TranslationBlock
*tb
;
1130 CPUState
*saved_env
;
1134 /* XXX: hack to restore env in all cases, even if not called from
1137 env
= cpu_single_env
;
1138 ret
= cpu_alpha_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
1139 if (!likely(ret
== 0)) {
1140 if (likely(retaddr
)) {
1141 /* now we have a real cpu fault */
1142 pc
= (unsigned long)retaddr
;
1143 tb
= tb_find_pc(pc
);
1145 /* the PC is inside the translated code. It means that we have
1146 a virtual CPU fault */
1147 cpu_restore_state(tb
, env
, pc
, NULL
);
1150 /* Exception index and error code are already set */