2 * MIPS emulation helpers for qemu.
4 * Copyright (c) 2004-2005 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
23 #include "host-utils.h"
26 /*****************************************************************************/
27 /* Exceptions processing helpers */
29 void do_raise_exception_err (uint32_t exception
, int error_code
)
32 if (logfile
&& exception
< 0x100)
33 fprintf(logfile
, "%s: %d %d\n", __func__
, exception
, error_code
);
35 env
->exception_index
= exception
;
36 env
->error_code
= error_code
;
40 void do_raise_exception (uint32_t exception
)
42 do_raise_exception_err(exception
, 0);
45 void do_interrupt_restart (void)
47 if (!(env
->CP0_Status
& (1 << CP0St_EXL
)) &&
48 !(env
->CP0_Status
& (1 << CP0St_ERL
)) &&
49 !(env
->hflags
& MIPS_HFLAG_DM
) &&
50 (env
->CP0_Status
& (1 << CP0St_IE
)) &&
51 (env
->CP0_Status
& env
->CP0_Cause
& CP0Ca_IP_mask
)) {
52 env
->CP0_Cause
&= ~(0x1f << CP0Ca_EC
);
53 do_raise_exception(EXCP_EXT_INTERRUPT
);
57 void do_restore_state (void *pc_ptr
)
60 unsigned long pc
= (unsigned long) pc_ptr
;
64 cpu_restore_state (tb
, env
, pc
, NULL
);
68 target_ulong
do_clo (target_ulong t0
)
73 target_ulong
do_clz (target_ulong t0
)
78 #if defined(TARGET_MIPS64)
79 target_ulong
do_dclo (target_ulong t0
)
84 target_ulong
do_dclz (target_ulong t0
)
88 #endif /* TARGET_MIPS64 */
90 /* 64 bits arithmetic for 32 bits hosts */
91 static inline uint64_t get_HILO (void)
93 return ((uint64_t)(env
->active_tc
.HI
[0]) << 32) | (uint32_t)env
->active_tc
.LO
[0];
96 static inline void set_HILO (uint64_t HILO
)
98 env
->active_tc
.LO
[0] = (int32_t)HILO
;
99 env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
102 static inline void set_HIT0_LO (target_ulong t0
, uint64_t HILO
)
104 env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
105 t0
= env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
108 static inline void set_HI_LOT0 (target_ulong t0
, uint64_t HILO
)
110 t0
= env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
111 env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
114 #if TARGET_LONG_BITS > HOST_LONG_BITS
115 void do_madd (target_ulong t0
, target_ulong t1
)
119 tmp
= ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
);
120 set_HILO((int64_t)get_HILO() + tmp
);
123 void do_maddu (target_ulong t0
, target_ulong t1
)
127 tmp
= ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
);
128 set_HILO(get_HILO() + tmp
);
131 void do_msub (target_ulong t0
, target_ulong t1
)
135 tmp
= ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
);
136 set_HILO((int64_t)get_HILO() - tmp
);
139 void do_msubu (target_ulong t0
, target_ulong t1
)
143 tmp
= ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
);
144 set_HILO(get_HILO() - tmp
);
146 #endif /* TARGET_LONG_BITS > HOST_LONG_BITS */
148 /* Multiplication variants of the vr54xx. */
149 target_ulong
do_muls (target_ulong t0
, target_ulong t1
)
151 set_HI_LOT0(t0
, 0 - ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
156 target_ulong
do_mulsu (target_ulong t0
, target_ulong t1
)
158 set_HI_LOT0(t0
, 0 - ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
163 target_ulong
do_macc (target_ulong t0
, target_ulong t1
)
165 set_HI_LOT0(t0
, ((int64_t)get_HILO()) + ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
170 target_ulong
do_macchi (target_ulong t0
, target_ulong t1
)
172 set_HIT0_LO(t0
, ((int64_t)get_HILO()) + ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
177 target_ulong
do_maccu (target_ulong t0
, target_ulong t1
)
179 set_HI_LOT0(t0
, ((uint64_t)get_HILO()) + ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
184 target_ulong
do_macchiu (target_ulong t0
, target_ulong t1
)
186 set_HIT0_LO(t0
, ((uint64_t)get_HILO()) + ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
191 target_ulong
do_msac (target_ulong t0
, target_ulong t1
)
193 set_HI_LOT0(t0
, ((int64_t)get_HILO()) - ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
198 target_ulong
do_msachi (target_ulong t0
, target_ulong t1
)
200 set_HIT0_LO(t0
, ((int64_t)get_HILO()) - ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
205 target_ulong
do_msacu (target_ulong t0
, target_ulong t1
)
207 set_HI_LOT0(t0
, ((uint64_t)get_HILO()) - ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
212 target_ulong
do_msachiu (target_ulong t0
, target_ulong t1
)
214 set_HIT0_LO(t0
, ((uint64_t)get_HILO()) - ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
219 target_ulong
do_mulhi (target_ulong t0
, target_ulong t1
)
221 set_HIT0_LO(t0
, (int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
);
226 target_ulong
do_mulhiu (target_ulong t0
, target_ulong t1
)
228 set_HIT0_LO(t0
, (uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
);
233 target_ulong
do_mulshi (target_ulong t0
, target_ulong t1
)
235 set_HIT0_LO(t0
, 0 - ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
240 target_ulong
do_mulshiu (target_ulong t0
, target_ulong t1
)
242 set_HIT0_LO(t0
, 0 - ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
248 void do_dmult (target_ulong t0
, target_ulong t1
)
250 muls64(&(env
->active_tc
.LO
[0]), &(env
->active_tc
.HI
[0]), t0
, t1
);
253 void do_dmultu (target_ulong t0
, target_ulong t1
)
255 mulu64(&(env
->active_tc
.LO
[0]), &(env
->active_tc
.HI
[0]), t0
, t1
);
259 #ifdef TARGET_WORDS_BIGENDIAN
260 #define GET_LMASK(v) ((v) & 3)
261 #define GET_OFFSET(addr, offset) (addr + (offset))
263 #define GET_LMASK(v) (((v) & 3) ^ 3)
264 #define GET_OFFSET(addr, offset) (addr - (offset))
267 target_ulong
do_lwl(target_ulong t0
, target_ulong t1
, int mem_idx
)
271 #ifdef CONFIG_USER_ONLY
272 #define ldfun ldub_raw
274 int (*ldfun
)(target_ulong
);
278 case 0: ldfun
= ldub_kernel
; break;
279 case 1: ldfun
= ldub_super
; break;
281 case 2: ldfun
= ldub_user
; break;
285 t1
= (t1
& 0x00FFFFFF) | (tmp
<< 24);
287 if (GET_LMASK(t0
) <= 2) {
288 tmp
= ldfun(GET_OFFSET(t0
, 1));
289 t1
= (t1
& 0xFF00FFFF) | (tmp
<< 16);
292 if (GET_LMASK(t0
) <= 1) {
293 tmp
= ldfun(GET_OFFSET(t0
, 2));
294 t1
= (t1
& 0xFFFF00FF) | (tmp
<< 8);
297 if (GET_LMASK(t0
) == 0) {
298 tmp
= ldfun(GET_OFFSET(t0
, 3));
299 t1
= (t1
& 0xFFFFFF00) | tmp
;
304 target_ulong
do_lwr(target_ulong t0
, target_ulong t1
, int mem_idx
)
308 #ifdef CONFIG_USER_ONLY
309 #define ldfun ldub_raw
311 int (*ldfun
)(target_ulong
);
315 case 0: ldfun
= ldub_kernel
; break;
316 case 1: ldfun
= ldub_super
; break;
318 case 2: ldfun
= ldub_user
; break;
322 t1
= (t1
& 0xFFFFFF00) | tmp
;
324 if (GET_LMASK(t0
) >= 1) {
325 tmp
= ldfun(GET_OFFSET(t0
, -1));
326 t1
= (t1
& 0xFFFF00FF) | (tmp
<< 8);
329 if (GET_LMASK(t0
) >= 2) {
330 tmp
= ldfun(GET_OFFSET(t0
, -2));
331 t1
= (t1
& 0xFF00FFFF) | (tmp
<< 16);
334 if (GET_LMASK(t0
) == 3) {
335 tmp
= ldfun(GET_OFFSET(t0
, -3));
336 t1
= (t1
& 0x00FFFFFF) | (tmp
<< 24);
341 void do_swl(target_ulong t0
, target_ulong t1
, int mem_idx
)
343 #ifdef CONFIG_USER_ONLY
344 #define stfun stb_raw
346 void (*stfun
)(target_ulong
, int);
350 case 0: stfun
= stb_kernel
; break;
351 case 1: stfun
= stb_super
; break;
353 case 2: stfun
= stb_user
; break;
356 stfun(t0
, (uint8_t)(t1
>> 24));
358 if (GET_LMASK(t0
) <= 2)
359 stfun(GET_OFFSET(t0
, 1), (uint8_t)(t1
>> 16));
361 if (GET_LMASK(t0
) <= 1)
362 stfun(GET_OFFSET(t0
, 2), (uint8_t)(t1
>> 8));
364 if (GET_LMASK(t0
) == 0)
365 stfun(GET_OFFSET(t0
, 3), (uint8_t)t1
);
368 void do_swr(target_ulong t0
, target_ulong t1
, int mem_idx
)
370 #ifdef CONFIG_USER_ONLY
371 #define stfun stb_raw
373 void (*stfun
)(target_ulong
, int);
377 case 0: stfun
= stb_kernel
; break;
378 case 1: stfun
= stb_super
; break;
380 case 2: stfun
= stb_user
; break;
383 stfun(t0
, (uint8_t)t1
);
385 if (GET_LMASK(t0
) >= 1)
386 stfun(GET_OFFSET(t0
, -1), (uint8_t)(t1
>> 8));
388 if (GET_LMASK(t0
) >= 2)
389 stfun(GET_OFFSET(t0
, -2), (uint8_t)(t1
>> 16));
391 if (GET_LMASK(t0
) == 3)
392 stfun(GET_OFFSET(t0
, -3), (uint8_t)(t1
>> 24));
395 #if defined(TARGET_MIPS64)
396 /* "half" load and stores. We must do the memory access inline,
397 or fault handling won't work. */
399 #ifdef TARGET_WORDS_BIGENDIAN
400 #define GET_LMASK64(v) ((v) & 7)
402 #define GET_LMASK64(v) (((v) & 7) ^ 7)
405 target_ulong
do_ldl(target_ulong t0
, target_ulong t1
, int mem_idx
)
409 #ifdef CONFIG_USER_ONLY
410 #define ldfun ldub_raw
412 int (*ldfun
)(target_ulong
);
416 case 0: ldfun
= ldub_kernel
; break;
417 case 1: ldfun
= ldub_super
; break;
419 case 2: ldfun
= ldub_user
; break;
423 t1
= (t1
& 0x00FFFFFFFFFFFFFFULL
) | (tmp
<< 56);
425 if (GET_LMASK64(t0
) <= 6) {
426 tmp
= ldfun(GET_OFFSET(t0
, 1));
427 t1
= (t1
& 0xFF00FFFFFFFFFFFFULL
) | (tmp
<< 48);
430 if (GET_LMASK64(t0
) <= 5) {
431 tmp
= ldfun(GET_OFFSET(t0
, 2));
432 t1
= (t1
& 0xFFFF00FFFFFFFFFFULL
) | (tmp
<< 40);
435 if (GET_LMASK64(t0
) <= 4) {
436 tmp
= ldfun(GET_OFFSET(t0
, 3));
437 t1
= (t1
& 0xFFFFFF00FFFFFFFFULL
) | (tmp
<< 32);
440 if (GET_LMASK64(t0
) <= 3) {
441 tmp
= ldfun(GET_OFFSET(t0
, 4));
442 t1
= (t1
& 0xFFFFFFFF00FFFFFFULL
) | (tmp
<< 24);
445 if (GET_LMASK64(t0
) <= 2) {
446 tmp
= ldfun(GET_OFFSET(t0
, 5));
447 t1
= (t1
& 0xFFFFFFFFFF00FFFFULL
) | (tmp
<< 16);
450 if (GET_LMASK64(t0
) <= 1) {
451 tmp
= ldfun(GET_OFFSET(t0
, 6));
452 t1
= (t1
& 0xFFFFFFFFFFFF00FFULL
) | (tmp
<< 8);
455 if (GET_LMASK64(t0
) == 0) {
456 tmp
= ldfun(GET_OFFSET(t0
, 7));
457 t1
= (t1
& 0xFFFFFFFFFFFFFF00ULL
) | tmp
;
463 target_ulong
do_ldr(target_ulong t0
, target_ulong t1
, int mem_idx
)
467 #ifdef CONFIG_USER_ONLY
468 #define ldfun ldub_raw
470 int (*ldfun
)(target_ulong
);
474 case 0: ldfun
= ldub_kernel
; break;
475 case 1: ldfun
= ldub_super
; break;
477 case 2: ldfun
= ldub_user
; break;
481 t1
= (t1
& 0xFFFFFFFFFFFFFF00ULL
) | tmp
;
483 if (GET_LMASK64(t0
) >= 1) {
484 tmp
= ldfun(GET_OFFSET(t0
, -1));
485 t1
= (t1
& 0xFFFFFFFFFFFF00FFULL
) | (tmp
<< 8);
488 if (GET_LMASK64(t0
) >= 2) {
489 tmp
= ldfun(GET_OFFSET(t0
, -2));
490 t1
= (t1
& 0xFFFFFFFFFF00FFFFULL
) | (tmp
<< 16);
493 if (GET_LMASK64(t0
) >= 3) {
494 tmp
= ldfun(GET_OFFSET(t0
, -3));
495 t1
= (t1
& 0xFFFFFFFF00FFFFFFULL
) | (tmp
<< 24);
498 if (GET_LMASK64(t0
) >= 4) {
499 tmp
= ldfun(GET_OFFSET(t0
, -4));
500 t1
= (t1
& 0xFFFFFF00FFFFFFFFULL
) | (tmp
<< 32);
503 if (GET_LMASK64(t0
) >= 5) {
504 tmp
= ldfun(GET_OFFSET(t0
, -5));
505 t1
= (t1
& 0xFFFF00FFFFFFFFFFULL
) | (tmp
<< 40);
508 if (GET_LMASK64(t0
) >= 6) {
509 tmp
= ldfun(GET_OFFSET(t0
, -6));
510 t1
= (t1
& 0xFF00FFFFFFFFFFFFULL
) | (tmp
<< 48);
513 if (GET_LMASK64(t0
) == 7) {
514 tmp
= ldfun(GET_OFFSET(t0
, -7));
515 t1
= (t1
& 0x00FFFFFFFFFFFFFFULL
) | (tmp
<< 56);
521 void do_sdl(target_ulong t0
, target_ulong t1
, int mem_idx
)
523 #ifdef CONFIG_USER_ONLY
524 #define stfun stb_raw
526 void (*stfun
)(target_ulong
, int);
530 case 0: stfun
= stb_kernel
; break;
531 case 1: stfun
= stb_super
; break;
533 case 2: stfun
= stb_user
; break;
536 stfun(t0
, (uint8_t)(t1
>> 56));
538 if (GET_LMASK64(t0
) <= 6)
539 stfun(GET_OFFSET(t0
, 1), (uint8_t)(t1
>> 48));
541 if (GET_LMASK64(t0
) <= 5)
542 stfun(GET_OFFSET(t0
, 2), (uint8_t)(t1
>> 40));
544 if (GET_LMASK64(t0
) <= 4)
545 stfun(GET_OFFSET(t0
, 3), (uint8_t)(t1
>> 32));
547 if (GET_LMASK64(t0
) <= 3)
548 stfun(GET_OFFSET(t0
, 4), (uint8_t)(t1
>> 24));
550 if (GET_LMASK64(t0
) <= 2)
551 stfun(GET_OFFSET(t0
, 5), (uint8_t)(t1
>> 16));
553 if (GET_LMASK64(t0
) <= 1)
554 stfun(GET_OFFSET(t0
, 6), (uint8_t)(t1
>> 8));
556 if (GET_LMASK64(t0
) <= 0)
557 stfun(GET_OFFSET(t0
, 7), (uint8_t)t1
);
560 void do_sdr(target_ulong t0
, target_ulong t1
, int mem_idx
)
562 #ifdef CONFIG_USER_ONLY
563 #define stfun stb_raw
565 void (*stfun
)(target_ulong
, int);
569 case 0: stfun
= stb_kernel
; break;
570 case 1: stfun
= stb_super
; break;
572 case 2: stfun
= stb_user
; break;
575 stfun(t0
, (uint8_t)t1
);
577 if (GET_LMASK64(t0
) >= 1)
578 stfun(GET_OFFSET(t0
, -1), (uint8_t)(t1
>> 8));
580 if (GET_LMASK64(t0
) >= 2)
581 stfun(GET_OFFSET(t0
, -2), (uint8_t)(t1
>> 16));
583 if (GET_LMASK64(t0
) >= 3)
584 stfun(GET_OFFSET(t0
, -3), (uint8_t)(t1
>> 24));
586 if (GET_LMASK64(t0
) >= 4)
587 stfun(GET_OFFSET(t0
, -4), (uint8_t)(t1
>> 32));
589 if (GET_LMASK64(t0
) >= 5)
590 stfun(GET_OFFSET(t0
, -5), (uint8_t)(t1
>> 40));
592 if (GET_LMASK64(t0
) >= 6)
593 stfun(GET_OFFSET(t0
, -6), (uint8_t)(t1
>> 48));
595 if (GET_LMASK64(t0
) == 7)
596 stfun(GET_OFFSET(t0
, -7), (uint8_t)(t1
>> 56));
598 #endif /* TARGET_MIPS64 */
600 #ifndef CONFIG_USER_ONLY
602 target_ulong
do_mfc0_mvpcontrol (void)
604 return env
->mvp
->CP0_MVPControl
;
607 target_ulong
do_mfc0_mvpconf0 (void)
609 return env
->mvp
->CP0_MVPConf0
;
612 target_ulong
do_mfc0_mvpconf1 (void)
614 return env
->mvp
->CP0_MVPConf1
;
617 target_ulong
do_mfc0_random (void)
619 return (int32_t)cpu_mips_get_random(env
);
622 target_ulong
do_mfc0_tcstatus (void)
624 return env
->active_tc
.CP0_TCStatus
;
627 target_ulong
do_mftc0_tcstatus(void)
629 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
631 if (other_tc
== env
->current_tc
)
632 return env
->active_tc
.CP0_TCStatus
;
634 return env
->tcs
[other_tc
].CP0_TCStatus
;
637 target_ulong
do_mfc0_tcbind (void)
639 return env
->active_tc
.CP0_TCBind
;
642 target_ulong
do_mftc0_tcbind(void)
644 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
646 if (other_tc
== env
->current_tc
)
647 return env
->active_tc
.CP0_TCBind
;
649 return env
->tcs
[other_tc
].CP0_TCBind
;
652 target_ulong
do_mfc0_tcrestart (void)
654 return env
->active_tc
.PC
;
657 target_ulong
do_mftc0_tcrestart(void)
659 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
661 if (other_tc
== env
->current_tc
)
662 return env
->active_tc
.PC
;
664 return env
->tcs
[other_tc
].PC
;
667 target_ulong
do_mfc0_tchalt (void)
669 return env
->active_tc
.CP0_TCHalt
;
672 target_ulong
do_mftc0_tchalt(void)
674 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
676 if (other_tc
== env
->current_tc
)
677 return env
->active_tc
.CP0_TCHalt
;
679 return env
->tcs
[other_tc
].CP0_TCHalt
;
682 target_ulong
do_mfc0_tccontext (void)
684 return env
->active_tc
.CP0_TCContext
;
687 target_ulong
do_mftc0_tccontext(void)
689 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
691 if (other_tc
== env
->current_tc
)
692 return env
->active_tc
.CP0_TCContext
;
694 return env
->tcs
[other_tc
].CP0_TCContext
;
697 target_ulong
do_mfc0_tcschedule (void)
699 return env
->active_tc
.CP0_TCSchedule
;
702 target_ulong
do_mftc0_tcschedule(void)
704 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
706 if (other_tc
== env
->current_tc
)
707 return env
->active_tc
.CP0_TCSchedule
;
709 return env
->tcs
[other_tc
].CP0_TCSchedule
;
712 target_ulong
do_mfc0_tcschefback (void)
714 return env
->active_tc
.CP0_TCScheFBack
;
717 target_ulong
do_mftc0_tcschefback(void)
719 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
721 if (other_tc
== env
->current_tc
)
722 return env
->active_tc
.CP0_TCScheFBack
;
724 return env
->tcs
[other_tc
].CP0_TCScheFBack
;
727 target_ulong
do_mfc0_count (void)
729 return (int32_t)cpu_mips_get_count(env
);
732 target_ulong
do_mftc0_entryhi(void)
734 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
737 if (other_tc
== env
->current_tc
)
738 tcstatus
= env
->active_tc
.CP0_TCStatus
;
740 tcstatus
= env
->tcs
[other_tc
].CP0_TCStatus
;
742 return (env
->CP0_EntryHi
& ~0xff) | (tcstatus
& 0xff);
745 target_ulong
do_mftc0_status(void)
747 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
751 if (other_tc
== env
->current_tc
)
752 tcstatus
= env
->active_tc
.CP0_TCStatus
;
754 tcstatus
= env
->tcs
[other_tc
].CP0_TCStatus
;
756 t0
= env
->CP0_Status
& ~0xf1000018;
757 t0
|= tcstatus
& (0xf << CP0TCSt_TCU0
);
758 t0
|= (tcstatus
& (1 << CP0TCSt_TMX
)) >> (CP0TCSt_TMX
- CP0St_MX
);
759 t0
|= (tcstatus
& (0x3 << CP0TCSt_TKSU
)) >> (CP0TCSt_TKSU
- CP0St_KSU
);
764 target_ulong
do_mfc0_lladdr (void)
766 return (int32_t)env
->CP0_LLAddr
>> 4;
769 target_ulong
do_mfc0_watchlo (uint32_t sel
)
771 return (int32_t)env
->CP0_WatchLo
[sel
];
774 target_ulong
do_mfc0_watchhi (uint32_t sel
)
776 return env
->CP0_WatchHi
[sel
];
779 target_ulong
do_mfc0_debug (void)
781 target_ulong t0
= env
->CP0_Debug
;
782 if (env
->hflags
& MIPS_HFLAG_DM
)
788 target_ulong
do_mftc0_debug(void)
790 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
793 if (other_tc
== env
->current_tc
)
794 tcstatus
= env
->active_tc
.CP0_Debug_tcstatus
;
796 tcstatus
= env
->tcs
[other_tc
].CP0_Debug_tcstatus
;
798 /* XXX: Might be wrong, check with EJTAG spec. */
799 return (env
->CP0_Debug
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
800 (tcstatus
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
803 #if defined(TARGET_MIPS64)
804 target_ulong
do_dmfc0_tcrestart (void)
806 return env
->active_tc
.PC
;
809 target_ulong
do_dmfc0_tchalt (void)
811 return env
->active_tc
.CP0_TCHalt
;
814 target_ulong
do_dmfc0_tccontext (void)
816 return env
->active_tc
.CP0_TCContext
;
819 target_ulong
do_dmfc0_tcschedule (void)
821 return env
->active_tc
.CP0_TCSchedule
;
824 target_ulong
do_dmfc0_tcschefback (void)
826 return env
->active_tc
.CP0_TCScheFBack
;
829 target_ulong
do_dmfc0_lladdr (void)
831 return env
->CP0_LLAddr
>> 4;
834 target_ulong
do_dmfc0_watchlo (uint32_t sel
)
836 return env
->CP0_WatchLo
[sel
];
838 #endif /* TARGET_MIPS64 */
840 void do_mtc0_index (target_ulong t0
)
843 unsigned int tmp
= env
->tlb
->nb_tlb
;
849 env
->CP0_Index
= (env
->CP0_Index
& 0x80000000) | (t0
& (num
- 1));
852 void do_mtc0_mvpcontrol (target_ulong t0
)
857 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))
858 mask
|= (1 << CP0MVPCo_CPA
) | (1 << CP0MVPCo_VPC
) |
860 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
861 mask
|= (1 << CP0MVPCo_STLB
);
862 newval
= (env
->mvp
->CP0_MVPControl
& ~mask
) | (t0
& mask
);
864 // TODO: Enable/disable shared TLB, enable/disable VPEs.
866 env
->mvp
->CP0_MVPControl
= newval
;
869 void do_mtc0_vpecontrol (target_ulong t0
)
874 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
875 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
876 newval
= (env
->CP0_VPEControl
& ~mask
) | (t0
& mask
);
878 /* Yield scheduler intercept not implemented. */
879 /* Gating storage scheduler intercept not implemented. */
881 // TODO: Enable/disable TCs.
883 env
->CP0_VPEControl
= newval
;
886 void do_mtc0_vpeconf0 (target_ulong t0
)
891 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) {
892 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_VPA
))
893 mask
|= (0xff << CP0VPEC0_XTC
);
894 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
896 newval
= (env
->CP0_VPEConf0
& ~mask
) | (t0
& mask
);
898 // TODO: TC exclusive handling due to ERL/EXL.
900 env
->CP0_VPEConf0
= newval
;
903 void do_mtc0_vpeconf1 (target_ulong t0
)
908 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
909 mask
|= (0xff << CP0VPEC1_NCX
) | (0xff << CP0VPEC1_NCP2
) |
910 (0xff << CP0VPEC1_NCP1
);
911 newval
= (env
->CP0_VPEConf1
& ~mask
) | (t0
& mask
);
913 /* UDI not implemented. */
914 /* CP2 not implemented. */
916 // TODO: Handle FPU (CP1) binding.
918 env
->CP0_VPEConf1
= newval
;
921 void do_mtc0_yqmask (target_ulong t0
)
923 /* Yield qualifier inputs not implemented. */
924 env
->CP0_YQMask
= 0x00000000;
927 void do_mtc0_vpeopt (target_ulong t0
)
929 env
->CP0_VPEOpt
= t0
& 0x0000ffff;
932 void do_mtc0_entrylo0 (target_ulong t0
)
934 /* Large physaddr (PABITS) not implemented */
935 /* 1k pages not implemented */
936 env
->CP0_EntryLo0
= t0
& 0x3FFFFFFF;
939 void do_mtc0_tcstatus (target_ulong t0
)
941 uint32_t mask
= env
->CP0_TCStatus_rw_bitmask
;
944 newval
= (env
->active_tc
.CP0_TCStatus
& ~mask
) | (t0
& mask
);
946 // TODO: Sync with CP0_Status.
948 env
->active_tc
.CP0_TCStatus
= newval
;
951 void do_mttc0_tcstatus (target_ulong t0
)
953 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
955 // TODO: Sync with CP0_Status.
957 if (other_tc
== env
->current_tc
)
958 env
->active_tc
.CP0_TCStatus
= t0
;
960 env
->tcs
[other_tc
].CP0_TCStatus
= t0
;
963 void do_mtc0_tcbind (target_ulong t0
)
965 uint32_t mask
= (1 << CP0TCBd_TBE
);
968 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
969 mask
|= (1 << CP0TCBd_CurVPE
);
970 newval
= (env
->active_tc
.CP0_TCBind
& ~mask
) | (t0
& mask
);
971 env
->active_tc
.CP0_TCBind
= newval
;
974 void do_mttc0_tcbind (target_ulong t0
)
976 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
977 uint32_t mask
= (1 << CP0TCBd_TBE
);
980 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
981 mask
|= (1 << CP0TCBd_CurVPE
);
982 if (other_tc
== env
->current_tc
) {
983 newval
= (env
->active_tc
.CP0_TCBind
& ~mask
) | (t0
& mask
);
984 env
->active_tc
.CP0_TCBind
= newval
;
986 newval
= (env
->tcs
[other_tc
].CP0_TCBind
& ~mask
) | (t0
& mask
);
987 env
->tcs
[other_tc
].CP0_TCBind
= newval
;
991 void do_mtc0_tcrestart (target_ulong t0
)
993 env
->active_tc
.PC
= t0
;
994 env
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
995 env
->CP0_LLAddr
= 0ULL;
996 /* MIPS16 not implemented. */
999 void do_mttc0_tcrestart (target_ulong t0
)
1001 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1003 if (other_tc
== env
->current_tc
) {
1004 env
->active_tc
.PC
= t0
;
1005 env
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1006 env
->CP0_LLAddr
= 0ULL;
1007 /* MIPS16 not implemented. */
1009 env
->tcs
[other_tc
].PC
= t0
;
1010 env
->tcs
[other_tc
].CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1011 env
->CP0_LLAddr
= 0ULL;
1012 /* MIPS16 not implemented. */
1016 void do_mtc0_tchalt (target_ulong t0
)
1018 env
->active_tc
.CP0_TCHalt
= t0
& 0x1;
1020 // TODO: Halt TC / Restart (if allocated+active) TC.
1023 void do_mttc0_tchalt (target_ulong t0
)
1025 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1027 // TODO: Halt TC / Restart (if allocated+active) TC.
1029 if (other_tc
== env
->current_tc
)
1030 env
->active_tc
.CP0_TCHalt
= t0
;
1032 env
->tcs
[other_tc
].CP0_TCHalt
= t0
;
1035 void do_mtc0_tccontext (target_ulong t0
)
1037 env
->active_tc
.CP0_TCContext
= t0
;
1040 void do_mttc0_tccontext (target_ulong t0
)
1042 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1044 if (other_tc
== env
->current_tc
)
1045 env
->active_tc
.CP0_TCContext
= t0
;
1047 env
->tcs
[other_tc
].CP0_TCContext
= t0
;
1050 void do_mtc0_tcschedule (target_ulong t0
)
1052 env
->active_tc
.CP0_TCSchedule
= t0
;
1055 void do_mttc0_tcschedule (target_ulong t0
)
1057 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1059 if (other_tc
== env
->current_tc
)
1060 env
->active_tc
.CP0_TCSchedule
= t0
;
1062 env
->tcs
[other_tc
].CP0_TCSchedule
= t0
;
1065 void do_mtc0_tcschefback (target_ulong t0
)
1067 env
->active_tc
.CP0_TCScheFBack
= t0
;
1070 void do_mttc0_tcschefback (target_ulong t0
)
1072 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1074 if (other_tc
== env
->current_tc
)
1075 env
->active_tc
.CP0_TCScheFBack
= t0
;
1077 env
->tcs
[other_tc
].CP0_TCScheFBack
= t0
;
1080 void do_mtc0_entrylo1 (target_ulong t0
)
1082 /* Large physaddr (PABITS) not implemented */
1083 /* 1k pages not implemented */
1084 env
->CP0_EntryLo1
= t0
& 0x3FFFFFFF;
1087 void do_mtc0_context (target_ulong t0
)
1089 env
->CP0_Context
= (env
->CP0_Context
& 0x007FFFFF) | (t0
& ~0x007FFFFF);
1092 void do_mtc0_pagemask (target_ulong t0
)
1094 /* 1k pages not implemented */
1095 env
->CP0_PageMask
= t0
& (0x1FFFFFFF & (TARGET_PAGE_MASK
<< 1));
1098 void do_mtc0_pagegrain (target_ulong t0
)
1100 /* SmartMIPS not implemented */
1101 /* Large physaddr (PABITS) not implemented */
1102 /* 1k pages not implemented */
1103 env
->CP0_PageGrain
= 0;
1106 void do_mtc0_wired (target_ulong t0
)
1108 env
->CP0_Wired
= t0
% env
->tlb
->nb_tlb
;
1111 void do_mtc0_srsconf0 (target_ulong t0
)
1113 env
->CP0_SRSConf0
|= t0
& env
->CP0_SRSConf0_rw_bitmask
;
1116 void do_mtc0_srsconf1 (target_ulong t0
)
1118 env
->CP0_SRSConf1
|= t0
& env
->CP0_SRSConf1_rw_bitmask
;
1121 void do_mtc0_srsconf2 (target_ulong t0
)
1123 env
->CP0_SRSConf2
|= t0
& env
->CP0_SRSConf2_rw_bitmask
;
1126 void do_mtc0_srsconf3 (target_ulong t0
)
1128 env
->CP0_SRSConf3
|= t0
& env
->CP0_SRSConf3_rw_bitmask
;
1131 void do_mtc0_srsconf4 (target_ulong t0
)
1133 env
->CP0_SRSConf4
|= t0
& env
->CP0_SRSConf4_rw_bitmask
;
1136 void do_mtc0_hwrena (target_ulong t0
)
1138 env
->CP0_HWREna
= t0
& 0x0000000F;
1141 void do_mtc0_count (target_ulong t0
)
1143 cpu_mips_store_count(env
, t0
);
1146 void do_mtc0_entryhi (target_ulong t0
)
1148 target_ulong old
, val
;
1150 /* 1k pages not implemented */
1151 val
= t0
& ((TARGET_PAGE_MASK
<< 1) | 0xFF);
1152 #if defined(TARGET_MIPS64)
1153 val
&= env
->SEGMask
;
1155 old
= env
->CP0_EntryHi
;
1156 env
->CP0_EntryHi
= val
;
1157 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
1158 uint32_t tcst
= env
->active_tc
.CP0_TCStatus
& ~0xff;
1159 env
->active_tc
.CP0_TCStatus
= tcst
| (val
& 0xff);
1161 /* If the ASID changes, flush qemu's TLB. */
1162 if ((old
& 0xFF) != (val
& 0xFF))
1163 cpu_mips_tlb_flush(env
, 1);
1166 void do_mttc0_entryhi(target_ulong t0
)
1168 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1171 env
->CP0_EntryHi
= (env
->CP0_EntryHi
& 0xff) | (t0
& ~0xff);
1172 if (other_tc
== env
->current_tc
) {
1173 tcstatus
= (env
->active_tc
.CP0_TCStatus
& ~0xff) | (t0
& 0xff);
1174 env
->active_tc
.CP0_TCStatus
= tcstatus
;
1176 tcstatus
= (env
->tcs
[other_tc
].CP0_TCStatus
& ~0xff) | (t0
& 0xff);
1177 env
->tcs
[other_tc
].CP0_TCStatus
= tcstatus
;
1181 void do_mtc0_compare (target_ulong t0
)
1183 cpu_mips_store_compare(env
, t0
);
1186 void do_mtc0_status (target_ulong t0
)
1189 uint32_t mask
= env
->CP0_Status_rw_bitmask
;
1192 old
= env
->CP0_Status
;
1193 env
->CP0_Status
= (env
->CP0_Status
& ~mask
) | val
;
1194 compute_hflags(env
);
1195 if (loglevel
& CPU_LOG_EXEC
)
1196 do_mtc0_status_debug(old
, val
);
1197 cpu_mips_update_irq(env
);
1200 void do_mttc0_status(target_ulong t0
)
1202 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1203 int32_t tcstatus
= env
->tcs
[other_tc
].CP0_TCStatus
;
1205 env
->CP0_Status
= t0
& ~0xf1000018;
1206 tcstatus
= (tcstatus
& ~(0xf << CP0TCSt_TCU0
)) | (t0
& (0xf << CP0St_CU0
));
1207 tcstatus
= (tcstatus
& ~(1 << CP0TCSt_TMX
)) | ((t0
& (1 << CP0St_MX
)) << (CP0TCSt_TMX
- CP0St_MX
));
1208 tcstatus
= (tcstatus
& ~(0x3 << CP0TCSt_TKSU
)) | ((t0
& (0x3 << CP0St_KSU
)) << (CP0TCSt_TKSU
- CP0St_KSU
));
1209 if (other_tc
== env
->current_tc
)
1210 env
->active_tc
.CP0_TCStatus
= tcstatus
;
1212 env
->tcs
[other_tc
].CP0_TCStatus
= tcstatus
;
1215 void do_mtc0_intctl (target_ulong t0
)
1217 /* vectored interrupts not implemented, no performance counters. */
1218 env
->CP0_IntCtl
= (env
->CP0_IntCtl
& ~0x000002e0) | (t0
& 0x000002e0);
1221 void do_mtc0_srsctl (target_ulong t0
)
1223 uint32_t mask
= (0xf << CP0SRSCtl_ESS
) | (0xf << CP0SRSCtl_PSS
);
1224 env
->CP0_SRSCtl
= (env
->CP0_SRSCtl
& ~mask
) | (t0
& mask
);
1227 void do_mtc0_cause (target_ulong t0
)
1229 uint32_t mask
= 0x00C00300;
1230 uint32_t old
= env
->CP0_Cause
;
1232 if (env
->insn_flags
& ISA_MIPS32R2
)
1233 mask
|= 1 << CP0Ca_DC
;
1235 env
->CP0_Cause
= (env
->CP0_Cause
& ~mask
) | (t0
& mask
);
1237 if ((old
^ env
->CP0_Cause
) & (1 << CP0Ca_DC
)) {
1238 if (env
->CP0_Cause
& (1 << CP0Ca_DC
))
1239 cpu_mips_stop_count(env
);
1241 cpu_mips_start_count(env
);
1244 /* Handle the software interrupt as an hardware one, as they
1246 if (t0
& CP0Ca_IP_mask
) {
1247 cpu_mips_update_irq(env
);
1251 void do_mtc0_ebase (target_ulong t0
)
1253 /* vectored interrupts not implemented */
1254 /* Multi-CPU not implemented */
1255 env
->CP0_EBase
= 0x80000000 | (t0
& 0x3FFFF000);
1258 void do_mtc0_config0 (target_ulong t0
)
1260 env
->CP0_Config0
= (env
->CP0_Config0
& 0x81FFFFF8) | (t0
& 0x00000007);
1263 void do_mtc0_config2 (target_ulong t0
)
1265 /* tertiary/secondary caches not implemented */
1266 env
->CP0_Config2
= (env
->CP0_Config2
& 0x8FFF0FFF);
1269 void do_mtc0_watchlo (target_ulong t0
, uint32_t sel
)
1271 /* Watch exceptions for instructions, data loads, data stores
1273 env
->CP0_WatchLo
[sel
] = (t0
& ~0x7);
1276 void do_mtc0_watchhi (target_ulong t0
, uint32_t sel
)
1278 env
->CP0_WatchHi
[sel
] = (t0
& 0x40FF0FF8);
1279 env
->CP0_WatchHi
[sel
] &= ~(env
->CP0_WatchHi
[sel
] & t0
& 0x7);
1282 void do_mtc0_xcontext (target_ulong t0
)
1284 target_ulong mask
= (1ULL << (env
->SEGBITS
- 7)) - 1;
1285 env
->CP0_XContext
= (env
->CP0_XContext
& mask
) | (t0
& ~mask
);
1288 void do_mtc0_framemask (target_ulong t0
)
1290 env
->CP0_Framemask
= t0
; /* XXX */
1293 void do_mtc0_debug (target_ulong t0
)
1295 env
->CP0_Debug
= (env
->CP0_Debug
& 0x8C03FC1F) | (t0
& 0x13300120);
1296 if (t0
& (1 << CP0DB_DM
))
1297 env
->hflags
|= MIPS_HFLAG_DM
;
1299 env
->hflags
&= ~MIPS_HFLAG_DM
;
1302 void do_mttc0_debug(target_ulong t0
)
1304 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1305 uint32_t val
= t0
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
));
1307 /* XXX: Might be wrong, check with EJTAG spec. */
1308 if (other_tc
== env
->current_tc
)
1309 env
->active_tc
.CP0_Debug_tcstatus
= val
;
1311 env
->tcs
[other_tc
].CP0_Debug_tcstatus
= val
;
1312 env
->CP0_Debug
= (env
->CP0_Debug
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
1313 (t0
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
1316 void do_mtc0_performance0 (target_ulong t0
)
1318 env
->CP0_Performance0
= t0
& 0x000007ff;
1321 void do_mtc0_taglo (target_ulong t0
)
1323 env
->CP0_TagLo
= t0
& 0xFFFFFCF6;
1326 void do_mtc0_datalo (target_ulong t0
)
1328 env
->CP0_DataLo
= t0
; /* XXX */
1331 void do_mtc0_taghi (target_ulong t0
)
1333 env
->CP0_TagHi
= t0
; /* XXX */
1336 void do_mtc0_datahi (target_ulong t0
)
1338 env
->CP0_DataHi
= t0
; /* XXX */
1341 void do_mtc0_status_debug(uint32_t old
, uint32_t val
)
1343 fprintf(logfile
, "Status %08x (%08x) => %08x (%08x) Cause %08x",
1344 old
, old
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1345 val
, val
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1347 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
1348 case MIPS_HFLAG_UM
: fputs(", UM\n", logfile
); break;
1349 case MIPS_HFLAG_SM
: fputs(", SM\n", logfile
); break;
1350 case MIPS_HFLAG_KM
: fputs("\n", logfile
); break;
1351 default: cpu_abort(env
, "Invalid MMU mode!\n"); break;
1355 void do_mtc0_status_irqraise_debug(void)
1357 fprintf(logfile
, "Raise pending IRQs\n");
1359 #endif /* !CONFIG_USER_ONLY */
1361 /* MIPS MT functions */
1362 target_ulong
do_mftgpr(uint32_t sel
)
1364 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1366 if (other_tc
== env
->current_tc
)
1367 return env
->active_tc
.gpr
[sel
];
1369 return env
->tcs
[other_tc
].gpr
[sel
];
1372 target_ulong
do_mftlo(uint32_t sel
)
1374 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1376 if (other_tc
== env
->current_tc
)
1377 return env
->active_tc
.LO
[sel
];
1379 return env
->tcs
[other_tc
].LO
[sel
];
1382 target_ulong
do_mfthi(uint32_t sel
)
1384 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1386 if (other_tc
== env
->current_tc
)
1387 return env
->active_tc
.HI
[sel
];
1389 return env
->tcs
[other_tc
].HI
[sel
];
1392 target_ulong
do_mftacx(uint32_t sel
)
1394 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1396 if (other_tc
== env
->current_tc
)
1397 return env
->active_tc
.ACX
[sel
];
1399 return env
->tcs
[other_tc
].ACX
[sel
];
1402 target_ulong
do_mftdsp(void)
1404 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1406 if (other_tc
== env
->current_tc
)
1407 return env
->active_tc
.DSPControl
;
1409 return env
->tcs
[other_tc
].DSPControl
;
1412 void do_mttgpr(target_ulong t0
, uint32_t sel
)
1414 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1416 if (other_tc
== env
->current_tc
)
1417 env
->active_tc
.gpr
[sel
] = t0
;
1419 env
->tcs
[other_tc
].gpr
[sel
] = t0
;
1422 void do_mttlo(target_ulong t0
, uint32_t sel
)
1424 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1426 if (other_tc
== env
->current_tc
)
1427 env
->active_tc
.LO
[sel
] = t0
;
1429 env
->tcs
[other_tc
].LO
[sel
] = t0
;
1432 void do_mtthi(target_ulong t0
, uint32_t sel
)
1434 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1436 if (other_tc
== env
->current_tc
)
1437 env
->active_tc
.HI
[sel
] = t0
;
1439 env
->tcs
[other_tc
].HI
[sel
] = t0
;
1442 void do_mttacx(target_ulong t0
, uint32_t sel
)
1444 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1446 if (other_tc
== env
->current_tc
)
1447 env
->active_tc
.ACX
[sel
] = t0
;
1449 env
->tcs
[other_tc
].ACX
[sel
] = t0
;
1452 void do_mttdsp(target_ulong t0
)
1454 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1456 if (other_tc
== env
->current_tc
)
1457 env
->active_tc
.DSPControl
= t0
;
1459 env
->tcs
[other_tc
].DSPControl
= t0
;
1462 /* MIPS MT functions */
1463 target_ulong
do_dmt(target_ulong t0
)
1472 target_ulong
do_emt(target_ulong t0
)
1481 target_ulong
do_dvpe(target_ulong t0
)
1490 target_ulong
do_evpe(target_ulong t0
)
1499 void do_fork(target_ulong t0
, target_ulong t1
)
1503 // TODO: store to TC register
1506 target_ulong
do_yield(target_ulong t0
)
1509 /* No scheduling policy implemented. */
1511 if (env
->CP0_VPEControl
& (1 << CP0VPECo_YSI
) &&
1512 env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_DT
)) {
1513 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1514 env
->CP0_VPEControl
|= 4 << CP0VPECo_EXCPT
;
1515 do_raise_exception(EXCP_THREAD
);
1518 } else if (t0
== 0) {
1519 if (0 /* TODO: TC underflow */) {
1520 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1521 do_raise_exception(EXCP_THREAD
);
1523 // TODO: Deallocate TC
1525 } else if (t0
> 0) {
1526 /* Yield qualifier inputs not implemented. */
1527 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1528 env
->CP0_VPEControl
|= 2 << CP0VPECo_EXCPT
;
1529 do_raise_exception(EXCP_THREAD
);
1531 return env
->CP0_YQMask
;
1534 #ifndef CONFIG_USER_ONLY
1535 /* TLB management */
1536 void cpu_mips_tlb_flush (CPUState
*env
, int flush_global
)
1538 /* Flush qemu's TLB and discard all shadowed entries. */
1539 tlb_flush (env
, flush_global
);
1540 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
1543 static void r4k_mips_tlb_flush_extra (CPUState
*env
, int first
)
1545 /* Discard entries from env->tlb[first] onwards. */
1546 while (env
->tlb
->tlb_in_use
> first
) {
1547 r4k_invalidate_tlb(env
, --env
->tlb
->tlb_in_use
, 0);
1551 static void r4k_fill_tlb (int idx
)
1555 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
1556 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1557 tlb
->VPN
= env
->CP0_EntryHi
& (TARGET_PAGE_MASK
<< 1);
1558 #if defined(TARGET_MIPS64)
1559 tlb
->VPN
&= env
->SEGMask
;
1561 tlb
->ASID
= env
->CP0_EntryHi
& 0xFF;
1562 tlb
->PageMask
= env
->CP0_PageMask
;
1563 tlb
->G
= env
->CP0_EntryLo0
& env
->CP0_EntryLo1
& 1;
1564 tlb
->V0
= (env
->CP0_EntryLo0
& 2) != 0;
1565 tlb
->D0
= (env
->CP0_EntryLo0
& 4) != 0;
1566 tlb
->C0
= (env
->CP0_EntryLo0
>> 3) & 0x7;
1567 tlb
->PFN
[0] = (env
->CP0_EntryLo0
>> 6) << 12;
1568 tlb
->V1
= (env
->CP0_EntryLo1
& 2) != 0;
1569 tlb
->D1
= (env
->CP0_EntryLo1
& 4) != 0;
1570 tlb
->C1
= (env
->CP0_EntryLo1
>> 3) & 0x7;
1571 tlb
->PFN
[1] = (env
->CP0_EntryLo1
>> 6) << 12;
1574 void r4k_do_tlbwi (void)
1578 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
1580 /* Discard cached TLB entries. We could avoid doing this if the
1581 tlbwi is just upgrading access permissions on the current entry;
1582 that might be a further win. */
1583 r4k_mips_tlb_flush_extra (env
, env
->tlb
->nb_tlb
);
1585 r4k_invalidate_tlb(env
, idx
, 0);
1589 void r4k_do_tlbwr (void)
1591 int r
= cpu_mips_get_random(env
);
1593 r4k_invalidate_tlb(env
, r
, 1);
1597 void r4k_do_tlbp (void)
1606 ASID
= env
->CP0_EntryHi
& 0xFF;
1607 for (i
= 0; i
< env
->tlb
->nb_tlb
; i
++) {
1608 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
1609 /* 1k pages are not supported. */
1610 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
1611 tag
= env
->CP0_EntryHi
& ~mask
;
1612 VPN
= tlb
->VPN
& ~mask
;
1613 /* Check ASID, virtual page number & size */
1614 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
1620 if (i
== env
->tlb
->nb_tlb
) {
1621 /* No match. Discard any shadow entries, if any of them match. */
1622 for (i
= env
->tlb
->nb_tlb
; i
< env
->tlb
->tlb_in_use
; i
++) {
1623 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
1624 /* 1k pages are not supported. */
1625 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
1626 tag
= env
->CP0_EntryHi
& ~mask
;
1627 VPN
= tlb
->VPN
& ~mask
;
1628 /* Check ASID, virtual page number & size */
1629 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
1630 r4k_mips_tlb_flush_extra (env
, i
);
1635 env
->CP0_Index
|= 0x80000000;
1639 void r4k_do_tlbr (void)
1645 ASID
= env
->CP0_EntryHi
& 0xFF;
1646 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
1647 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1649 /* If this will change the current ASID, flush qemu's TLB. */
1650 if (ASID
!= tlb
->ASID
)
1651 cpu_mips_tlb_flush (env
, 1);
1653 r4k_mips_tlb_flush_extra(env
, env
->tlb
->nb_tlb
);
1655 env
->CP0_EntryHi
= tlb
->VPN
| tlb
->ASID
;
1656 env
->CP0_PageMask
= tlb
->PageMask
;
1657 env
->CP0_EntryLo0
= tlb
->G
| (tlb
->V0
<< 1) | (tlb
->D0
<< 2) |
1658 (tlb
->C0
<< 3) | (tlb
->PFN
[0] >> 6);
1659 env
->CP0_EntryLo1
= tlb
->G
| (tlb
->V1
<< 1) | (tlb
->D1
<< 2) |
1660 (tlb
->C1
<< 3) | (tlb
->PFN
[1] >> 6);
1665 env
->tlb
->do_tlbwi();
1670 env
->tlb
->do_tlbwr();
1675 env
->tlb
->do_tlbp();
1680 env
->tlb
->do_tlbr();
1684 target_ulong
do_di (void)
1686 target_ulong t0
= env
->CP0_Status
;
1688 env
->CP0_Status
= t0
& ~(1 << CP0St_IE
);
1689 cpu_mips_update_irq(env
);
1694 target_ulong
do_ei (void)
1696 target_ulong t0
= env
->CP0_Status
;
1698 env
->CP0_Status
= t0
| (1 << CP0St_IE
);
1699 cpu_mips_update_irq(env
);
1704 static void debug_pre_eret (void)
1706 fprintf(logfile
, "ERET: PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
1707 env
->active_tc
.PC
, env
->CP0_EPC
);
1708 if (env
->CP0_Status
& (1 << CP0St_ERL
))
1709 fprintf(logfile
, " ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
1710 if (env
->hflags
& MIPS_HFLAG_DM
)
1711 fprintf(logfile
, " DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
1712 fputs("\n", logfile
);
1715 static void debug_post_eret (void)
1717 fprintf(logfile
, " => PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
1718 env
->active_tc
.PC
, env
->CP0_EPC
);
1719 if (env
->CP0_Status
& (1 << CP0St_ERL
))
1720 fprintf(logfile
, " ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
1721 if (env
->hflags
& MIPS_HFLAG_DM
)
1722 fprintf(logfile
, " DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
1723 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
1724 case MIPS_HFLAG_UM
: fputs(", UM\n", logfile
); break;
1725 case MIPS_HFLAG_SM
: fputs(", SM\n", logfile
); break;
1726 case MIPS_HFLAG_KM
: fputs("\n", logfile
); break;
1727 default: cpu_abort(env
, "Invalid MMU mode!\n"); break;
1733 if (loglevel
& CPU_LOG_EXEC
)
1735 if (env
->CP0_Status
& (1 << CP0St_ERL
)) {
1736 env
->active_tc
.PC
= env
->CP0_ErrorEPC
;
1737 env
->CP0_Status
&= ~(1 << CP0St_ERL
);
1739 env
->active_tc
.PC
= env
->CP0_EPC
;
1740 env
->CP0_Status
&= ~(1 << CP0St_EXL
);
1742 compute_hflags(env
);
1743 if (loglevel
& CPU_LOG_EXEC
)
1745 env
->CP0_LLAddr
= 1;
1748 void do_deret (void)
1750 if (loglevel
& CPU_LOG_EXEC
)
1752 env
->active_tc
.PC
= env
->CP0_DEPC
;
1753 env
->hflags
&= MIPS_HFLAG_DM
;
1754 compute_hflags(env
);
1755 if (loglevel
& CPU_LOG_EXEC
)
1757 env
->CP0_LLAddr
= 1;
1759 #endif /* !CONFIG_USER_ONLY */
1761 target_ulong
do_rdhwr_cpunum(void)
1763 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
1764 (env
->CP0_HWREna
& (1 << 0)))
1765 return env
->CP0_EBase
& 0x3ff;
1767 do_raise_exception(EXCP_RI
);
1772 target_ulong
do_rdhwr_synci_step(void)
1774 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
1775 (env
->CP0_HWREna
& (1 << 1)))
1776 return env
->SYNCI_Step
;
1778 do_raise_exception(EXCP_RI
);
1783 target_ulong
do_rdhwr_cc(void)
1785 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
1786 (env
->CP0_HWREna
& (1 << 2)))
1787 return env
->CP0_Count
;
1789 do_raise_exception(EXCP_RI
);
1794 target_ulong
do_rdhwr_ccres(void)
1796 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
1797 (env
->CP0_HWREna
& (1 << 3)))
1800 do_raise_exception(EXCP_RI
);
1805 void do_pmon (int function
)
1809 case 2: /* TODO: char inbyte(int waitflag); */
1810 if (env
->active_tc
.gpr
[4] == 0)
1811 env
->active_tc
.gpr
[2] = -1;
1813 case 11: /* TODO: char inbyte (void); */
1814 env
->active_tc
.gpr
[2] = -1;
1818 printf("%c", (char)(env
->active_tc
.gpr
[4] & 0xFF));
1824 unsigned char *fmt
= (void *)(unsigned long)env
->active_tc
.gpr
[4];
1834 do_raise_exception(EXCP_HLT
);
1837 #if !defined(CONFIG_USER_ONLY)
1839 static void do_unaligned_access (target_ulong addr
, int is_write
, int is_user
, void *retaddr
);
1841 #define MMUSUFFIX _mmu
1842 #define ALIGNED_ONLY
1845 #include "softmmu_template.h"
1848 #include "softmmu_template.h"
1851 #include "softmmu_template.h"
1854 #include "softmmu_template.h"
1856 static void do_unaligned_access (target_ulong addr
, int is_write
, int is_user
, void *retaddr
)
1858 env
->CP0_BadVAddr
= addr
;
1859 do_restore_state (retaddr
);
1860 do_raise_exception ((is_write
== 1) ? EXCP_AdES
: EXCP_AdEL
);
1863 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
1865 TranslationBlock
*tb
;
1866 CPUState
*saved_env
;
1870 /* XXX: hack to restore env in all cases, even if not called from
1873 env
= cpu_single_env
;
1874 ret
= cpu_mips_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
1877 /* now we have a real cpu fault */
1878 pc
= (unsigned long)retaddr
;
1879 tb
= tb_find_pc(pc
);
1881 /* the PC is inside the translated code. It means that we have
1882 a virtual CPU fault */
1883 cpu_restore_state(tb
, env
, pc
, NULL
);
1886 do_raise_exception_err(env
->exception_index
, env
->error_code
);
1891 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
1892 int unused
, int size
)
1895 do_raise_exception(EXCP_IBE
);
1897 do_raise_exception(EXCP_DBE
);
1899 #endif /* !CONFIG_USER_ONLY */
1901 /* Complex FPU operations which may need stack space. */
1903 #define FLOAT_ONE32 make_float32(0x3f8 << 20)
1904 #define FLOAT_ONE64 make_float64(0x3ffULL << 52)
1905 #define FLOAT_TWO32 make_float32(1 << 30)
1906 #define FLOAT_TWO64 make_float64(1ULL << 62)
1907 #define FLOAT_QNAN32 0x7fbfffff
1908 #define FLOAT_QNAN64 0x7ff7ffffffffffffULL
1909 #define FLOAT_SNAN32 0x7fffffff
1910 #define FLOAT_SNAN64 0x7fffffffffffffffULL
1912 /* convert MIPS rounding mode in FCR31 to IEEE library */
1913 unsigned int ieee_rm
[] = {
1914 float_round_nearest_even
,
1915 float_round_to_zero
,
1920 #define RESTORE_ROUNDING_MODE \
1921 set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3], &env->active_fpu.fp_status)
1923 target_ulong
do_cfc1 (uint32_t reg
)
1929 t0
= (int32_t)env
->active_fpu
.fcr0
;
1932 t0
= ((env
->active_fpu
.fcr31
>> 24) & 0xfe) | ((env
->active_fpu
.fcr31
>> 23) & 0x1);
1935 t0
= env
->active_fpu
.fcr31
& 0x0003f07c;
1938 t0
= (env
->active_fpu
.fcr31
& 0x00000f83) | ((env
->active_fpu
.fcr31
>> 22) & 0x4);
1941 t0
= (int32_t)env
->active_fpu
.fcr31
;
1948 void do_ctc1 (target_ulong t0
, uint32_t reg
)
1952 if (t0
& 0xffffff00)
1954 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0x017fffff) | ((t0
& 0xfe) << 24) |
1958 if (t0
& 0x007c0000)
1960 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfffc0f83) | (t0
& 0x0003f07c);
1963 if (t0
& 0x007c0000)
1965 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfefff07c) | (t0
& 0x00000f83) |
1969 if (t0
& 0x007c0000)
1971 env
->active_fpu
.fcr31
= t0
;
1976 /* set rounding mode */
1977 RESTORE_ROUNDING_MODE
;
1978 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
1979 if ((GET_FP_ENABLE(env
->active_fpu
.fcr31
) | 0x20) & GET_FP_CAUSE(env
->active_fpu
.fcr31
))
1980 do_raise_exception(EXCP_FPE
);
1983 static inline char ieee_ex_to_mips(char xcpt
)
1985 return (xcpt
& float_flag_inexact
) >> 5 |
1986 (xcpt
& float_flag_underflow
) >> 3 |
1987 (xcpt
& float_flag_overflow
) >> 1 |
1988 (xcpt
& float_flag_divbyzero
) << 1 |
1989 (xcpt
& float_flag_invalid
) << 4;
1992 static inline char mips_ex_to_ieee(char xcpt
)
1994 return (xcpt
& FP_INEXACT
) << 5 |
1995 (xcpt
& FP_UNDERFLOW
) << 3 |
1996 (xcpt
& FP_OVERFLOW
) << 1 |
1997 (xcpt
& FP_DIV0
) >> 1 |
1998 (xcpt
& FP_INVALID
) >> 4;
2001 static inline void update_fcr31(void)
2003 int tmp
= ieee_ex_to_mips(get_float_exception_flags(&env
->active_fpu
.fp_status
));
2005 SET_FP_CAUSE(env
->active_fpu
.fcr31
, tmp
);
2006 if (GET_FP_ENABLE(env
->active_fpu
.fcr31
) & tmp
)
2007 do_raise_exception(EXCP_FPE
);
2009 UPDATE_FP_FLAGS(env
->active_fpu
.fcr31
, tmp
);
2013 Single precition routines have a "s" suffix, double precision a
2014 "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
2015 paired single lower "pl", paired single upper "pu". */
2017 /* unary operations, modifying fp status */
2018 uint64_t do_float_sqrt_d(uint64_t fdt0
)
2020 return float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2023 uint32_t do_float_sqrt_s(uint32_t fst0
)
2025 return float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2028 uint64_t do_float_cvtd_s(uint32_t fst0
)
2032 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2033 fdt2
= float32_to_float64(fst0
, &env
->active_fpu
.fp_status
);
2038 uint64_t do_float_cvtd_w(uint32_t wt0
)
2042 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2043 fdt2
= int32_to_float64(wt0
, &env
->active_fpu
.fp_status
);
2048 uint64_t do_float_cvtd_l(uint64_t dt0
)
2052 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2053 fdt2
= int64_to_float64(dt0
, &env
->active_fpu
.fp_status
);
2058 uint64_t do_float_cvtl_d(uint64_t fdt0
)
2062 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2063 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2065 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2070 uint64_t do_float_cvtl_s(uint32_t fst0
)
2074 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2075 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2077 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2082 uint64_t do_float_cvtps_pw(uint64_t dt0
)
2087 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2088 fst2
= int32_to_float32(dt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2089 fsth2
= int32_to_float32(dt0
>> 32, &env
->active_fpu
.fp_status
);
2091 return ((uint64_t)fsth2
<< 32) | fst2
;
2094 uint64_t do_float_cvtpw_ps(uint64_t fdt0
)
2099 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2100 wt2
= float32_to_int32(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2101 wth2
= float32_to_int32(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2103 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
)) {
2105 wth2
= FLOAT_SNAN32
;
2107 return ((uint64_t)wth2
<< 32) | wt2
;
2110 uint32_t do_float_cvts_d(uint64_t fdt0
)
2114 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2115 fst2
= float64_to_float32(fdt0
, &env
->active_fpu
.fp_status
);
2120 uint32_t do_float_cvts_w(uint32_t wt0
)
2124 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2125 fst2
= int32_to_float32(wt0
, &env
->active_fpu
.fp_status
);
2130 uint32_t do_float_cvts_l(uint64_t dt0
)
2134 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2135 fst2
= int64_to_float32(dt0
, &env
->active_fpu
.fp_status
);
2140 uint32_t do_float_cvts_pl(uint32_t wt0
)
2144 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2150 uint32_t do_float_cvts_pu(uint32_t wth0
)
2154 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2160 uint32_t do_float_cvtw_s(uint32_t fst0
)
2164 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2165 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2167 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2172 uint32_t do_float_cvtw_d(uint64_t fdt0
)
2176 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2177 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2179 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2184 uint64_t do_float_roundl_d(uint64_t fdt0
)
2188 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2189 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2190 RESTORE_ROUNDING_MODE
;
2192 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2197 uint64_t do_float_roundl_s(uint32_t fst0
)
2201 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2202 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2203 RESTORE_ROUNDING_MODE
;
2205 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2210 uint32_t do_float_roundw_d(uint64_t fdt0
)
2214 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2215 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2216 RESTORE_ROUNDING_MODE
;
2218 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2223 uint32_t do_float_roundw_s(uint32_t fst0
)
2227 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2228 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2229 RESTORE_ROUNDING_MODE
;
2231 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2236 uint64_t do_float_truncl_d(uint64_t fdt0
)
2240 dt2
= float64_to_int64_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2242 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2247 uint64_t do_float_truncl_s(uint32_t fst0
)
2251 dt2
= float32_to_int64_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2253 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2258 uint32_t do_float_truncw_d(uint64_t fdt0
)
2262 wt2
= float64_to_int32_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2264 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2269 uint32_t do_float_truncw_s(uint32_t fst0
)
2273 wt2
= float32_to_int32_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2275 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2280 uint64_t do_float_ceill_d(uint64_t fdt0
)
2284 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2285 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2286 RESTORE_ROUNDING_MODE
;
2288 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2293 uint64_t do_float_ceill_s(uint32_t fst0
)
2297 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2298 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2299 RESTORE_ROUNDING_MODE
;
2301 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2306 uint32_t do_float_ceilw_d(uint64_t fdt0
)
2310 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2311 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2312 RESTORE_ROUNDING_MODE
;
2314 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2319 uint32_t do_float_ceilw_s(uint32_t fst0
)
2323 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2324 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2325 RESTORE_ROUNDING_MODE
;
2327 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2332 uint64_t do_float_floorl_d(uint64_t fdt0
)
2336 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2337 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2338 RESTORE_ROUNDING_MODE
;
2340 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2345 uint64_t do_float_floorl_s(uint32_t fst0
)
2349 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2350 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2351 RESTORE_ROUNDING_MODE
;
2353 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2358 uint32_t do_float_floorw_d(uint64_t fdt0
)
2362 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2363 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2364 RESTORE_ROUNDING_MODE
;
2366 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2371 uint32_t do_float_floorw_s(uint32_t fst0
)
2375 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2376 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2377 RESTORE_ROUNDING_MODE
;
2379 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2384 /* unary operations, not modifying fp status */
2385 #define FLOAT_UNOP(name) \
2386 uint64_t do_float_ ## name ## _d(uint64_t fdt0) \
2388 return float64_ ## name(fdt0); \
2390 uint32_t do_float_ ## name ## _s(uint32_t fst0) \
2392 return float32_ ## name(fst0); \
2394 uint64_t do_float_ ## name ## _ps(uint64_t fdt0) \
2399 wt0 = float32_ ## name(fdt0 & 0XFFFFFFFF); \
2400 wth0 = float32_ ## name(fdt0 >> 32); \
2401 return ((uint64_t)wth0 << 32) | wt0; \
2407 /* MIPS specific unary operations */
2408 uint64_t do_float_recip_d(uint64_t fdt0
)
2412 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2413 fdt2
= float64_div(FLOAT_ONE64
, fdt0
, &env
->active_fpu
.fp_status
);
2418 uint32_t do_float_recip_s(uint32_t fst0
)
2422 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2423 fst2
= float32_div(FLOAT_ONE32
, fst0
, &env
->active_fpu
.fp_status
);
2428 uint64_t do_float_rsqrt_d(uint64_t fdt0
)
2432 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2433 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2434 fdt2
= float64_div(FLOAT_ONE64
, fdt2
, &env
->active_fpu
.fp_status
);
2439 uint32_t do_float_rsqrt_s(uint32_t fst0
)
2443 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2444 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2445 fst2
= float32_div(FLOAT_ONE32
, fst2
, &env
->active_fpu
.fp_status
);
2450 uint64_t do_float_recip1_d(uint64_t fdt0
)
2454 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2455 fdt2
= float64_div(FLOAT_ONE64
, fdt0
, &env
->active_fpu
.fp_status
);
2460 uint32_t do_float_recip1_s(uint32_t fst0
)
2464 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2465 fst2
= float32_div(FLOAT_ONE32
, fst0
, &env
->active_fpu
.fp_status
);
2470 uint64_t do_float_recip1_ps(uint64_t fdt0
)
2475 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2476 fst2
= float32_div(FLOAT_ONE32
, fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2477 fsth2
= float32_div(FLOAT_ONE32
, fdt0
>> 32, &env
->active_fpu
.fp_status
);
2479 return ((uint64_t)fsth2
<< 32) | fst2
;
2482 uint64_t do_float_rsqrt1_d(uint64_t fdt0
)
2486 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2487 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2488 fdt2
= float64_div(FLOAT_ONE64
, fdt2
, &env
->active_fpu
.fp_status
);
2493 uint32_t do_float_rsqrt1_s(uint32_t fst0
)
2497 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2498 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2499 fst2
= float32_div(FLOAT_ONE32
, fst2
, &env
->active_fpu
.fp_status
);
2504 uint64_t do_float_rsqrt1_ps(uint64_t fdt0
)
2509 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2510 fst2
= float32_sqrt(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2511 fsth2
= float32_sqrt(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2512 fst2
= float32_div(FLOAT_ONE32
, fst2
, &env
->active_fpu
.fp_status
);
2513 fsth2
= float32_div(FLOAT_ONE32
, fsth2
, &env
->active_fpu
.fp_status
);
2515 return ((uint64_t)fsth2
<< 32) | fst2
;
2518 #define FLOAT_OP(name, p) void do_float_##name##_##p(void)
2520 /* binary operations */
2521 #define FLOAT_BINOP(name) \
2522 uint64_t do_float_ ## name ## _d(uint64_t fdt0, uint64_t fdt1) \
2526 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2527 dt2 = float64_ ## name (fdt0, fdt1, &env->active_fpu.fp_status); \
2529 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
2530 dt2 = FLOAT_QNAN64; \
2534 uint32_t do_float_ ## name ## _s(uint32_t fst0, uint32_t fst1) \
2538 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2539 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2541 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
2542 wt2 = FLOAT_QNAN32; \
2546 uint64_t do_float_ ## name ## _ps(uint64_t fdt0, uint64_t fdt1) \
2548 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2549 uint32_t fsth0 = fdt0 >> 32; \
2550 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2551 uint32_t fsth1 = fdt1 >> 32; \
2555 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2556 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2557 wth2 = float32_ ## name (fsth0, fsth1, &env->active_fpu.fp_status); \
2559 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) { \
2560 wt2 = FLOAT_QNAN32; \
2561 wth2 = FLOAT_QNAN32; \
2563 return ((uint64_t)wth2 << 32) | wt2; \
2572 /* ternary operations */
2573 #define FLOAT_TERNOP(name1, name2) \
2574 uint64_t do_float_ ## name1 ## name2 ## _d(uint64_t fdt0, uint64_t fdt1, \
2577 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
2578 return float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
2581 uint32_t do_float_ ## name1 ## name2 ## _s(uint32_t fst0, uint32_t fst1, \
2584 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2585 return float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2588 uint64_t do_float_ ## name1 ## name2 ## _ps(uint64_t fdt0, uint64_t fdt1, \
2591 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2592 uint32_t fsth0 = fdt0 >> 32; \
2593 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2594 uint32_t fsth1 = fdt1 >> 32; \
2595 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
2596 uint32_t fsth2 = fdt2 >> 32; \
2598 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2599 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
2600 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2601 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
2602 return ((uint64_t)fsth2 << 32) | fst2; \
2605 FLOAT_TERNOP(mul
, add
)
2606 FLOAT_TERNOP(mul
, sub
)
2609 /* negated ternary operations */
2610 #define FLOAT_NTERNOP(name1, name2) \
2611 uint64_t do_float_n ## name1 ## name2 ## _d(uint64_t fdt0, uint64_t fdt1, \
2614 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
2615 fdt2 = float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
2616 return float64_chs(fdt2); \
2619 uint32_t do_float_n ## name1 ## name2 ## _s(uint32_t fst0, uint32_t fst1, \
2622 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2623 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2624 return float32_chs(fst2); \
2627 uint64_t do_float_n ## name1 ## name2 ## _ps(uint64_t fdt0, uint64_t fdt1,\
2630 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2631 uint32_t fsth0 = fdt0 >> 32; \
2632 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2633 uint32_t fsth1 = fdt1 >> 32; \
2634 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
2635 uint32_t fsth2 = fdt2 >> 32; \
2637 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2638 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
2639 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2640 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
2641 fst2 = float32_chs(fst2); \
2642 fsth2 = float32_chs(fsth2); \
2643 return ((uint64_t)fsth2 << 32) | fst2; \
2646 FLOAT_NTERNOP(mul
, add
)
2647 FLOAT_NTERNOP(mul
, sub
)
2648 #undef FLOAT_NTERNOP
2650 /* MIPS specific binary operations */
2651 uint64_t do_float_recip2_d(uint64_t fdt0
, uint64_t fdt2
)
2653 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2654 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
2655 fdt2
= float64_chs(float64_sub(fdt2
, FLOAT_ONE64
, &env
->active_fpu
.fp_status
));
2660 uint32_t do_float_recip2_s(uint32_t fst0
, uint32_t fst2
)
2662 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2663 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
2664 fst2
= float32_chs(float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
));
2669 uint64_t do_float_recip2_ps(uint64_t fdt0
, uint64_t fdt2
)
2671 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
2672 uint32_t fsth0
= fdt0
>> 32;
2673 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
2674 uint32_t fsth2
= fdt2
>> 32;
2676 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2677 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
2678 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
2679 fst2
= float32_chs(float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
));
2680 fsth2
= float32_chs(float32_sub(fsth2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
));
2682 return ((uint64_t)fsth2
<< 32) | fst2
;
2685 uint64_t do_float_rsqrt2_d(uint64_t fdt0
, uint64_t fdt2
)
2687 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2688 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
2689 fdt2
= float64_sub(fdt2
, FLOAT_ONE64
, &env
->active_fpu
.fp_status
);
2690 fdt2
= float64_chs(float64_div(fdt2
, FLOAT_TWO64
, &env
->active_fpu
.fp_status
));
2695 uint32_t do_float_rsqrt2_s(uint32_t fst0
, uint32_t fst2
)
2697 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2698 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
2699 fst2
= float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
);
2700 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
2705 uint64_t do_float_rsqrt2_ps(uint64_t fdt0
, uint64_t fdt2
)
2707 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
2708 uint32_t fsth0
= fdt0
>> 32;
2709 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
2710 uint32_t fsth2
= fdt2
>> 32;
2712 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2713 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
2714 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
2715 fst2
= float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
);
2716 fsth2
= float32_sub(fsth2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
);
2717 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
2718 fsth2
= float32_chs(float32_div(fsth2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
2720 return ((uint64_t)fsth2
<< 32) | fst2
;
2723 uint64_t do_float_addr_ps(uint64_t fdt0
, uint64_t fdt1
)
2725 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
2726 uint32_t fsth0
= fdt0
>> 32;
2727 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
2728 uint32_t fsth1
= fdt1
>> 32;
2732 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2733 fst2
= float32_add (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
2734 fsth2
= float32_add (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
2736 return ((uint64_t)fsth2
<< 32) | fst2
;
2739 uint64_t do_float_mulr_ps(uint64_t fdt0
, uint64_t fdt1
)
2741 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
2742 uint32_t fsth0
= fdt0
>> 32;
2743 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
2744 uint32_t fsth1
= fdt1
>> 32;
2748 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2749 fst2
= float32_mul (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
2750 fsth2
= float32_mul (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
2752 return ((uint64_t)fsth2
<< 32) | fst2
;
2755 /* compare operations */
2756 #define FOP_COND_D(op, cond) \
2757 void do_cmp_d_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2762 SET_FP_COND(cc, env->active_fpu); \
2764 CLEAR_FP_COND(cc, env->active_fpu); \
2766 void do_cmpabs_d_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2769 fdt0 = float64_abs(fdt0); \
2770 fdt1 = float64_abs(fdt1); \
2774 SET_FP_COND(cc, env->active_fpu); \
2776 CLEAR_FP_COND(cc, env->active_fpu); \
2779 static int float64_is_unordered(int sig
, float64 a
, float64 b STATUS_PARAM
)
2781 if (float64_is_signaling_nan(a
) ||
2782 float64_is_signaling_nan(b
) ||
2783 (sig
&& (float64_is_nan(a
) || float64_is_nan(b
)))) {
2784 float_raise(float_flag_invalid
, status
);
2786 } else if (float64_is_nan(a
) || float64_is_nan(b
)) {
2793 /* NOTE: the comma operator will make "cond" to eval to false,
2794 * but float*_is_unordered() is still called. */
2795 FOP_COND_D(f
, (float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
2796 FOP_COND_D(un
, float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
2797 FOP_COND_D(eq
, !float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2798 FOP_COND_D(ueq
, float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2799 FOP_COND_D(olt
, !float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2800 FOP_COND_D(ult
, float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2801 FOP_COND_D(ole
, !float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2802 FOP_COND_D(ule
, float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2803 /* NOTE: the comma operator will make "cond" to eval to false,
2804 * but float*_is_unordered() is still called. */
2805 FOP_COND_D(sf
, (float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
2806 FOP_COND_D(ngle
,float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
2807 FOP_COND_D(seq
, !float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2808 FOP_COND_D(ngl
, float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2809 FOP_COND_D(lt
, !float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2810 FOP_COND_D(nge
, float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2811 FOP_COND_D(le
, !float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2812 FOP_COND_D(ngt
, float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2814 #define FOP_COND_S(op, cond) \
2815 void do_cmp_s_ ## op (uint32_t fst0, uint32_t fst1, int cc) \
2820 SET_FP_COND(cc, env->active_fpu); \
2822 CLEAR_FP_COND(cc, env->active_fpu); \
2824 void do_cmpabs_s_ ## op (uint32_t fst0, uint32_t fst1, int cc) \
2827 fst0 = float32_abs(fst0); \
2828 fst1 = float32_abs(fst1); \
2832 SET_FP_COND(cc, env->active_fpu); \
2834 CLEAR_FP_COND(cc, env->active_fpu); \
2837 static flag
float32_is_unordered(int sig
, float32 a
, float32 b STATUS_PARAM
)
2839 if (float32_is_signaling_nan(a
) ||
2840 float32_is_signaling_nan(b
) ||
2841 (sig
&& (float32_is_nan(a
) || float32_is_nan(b
)))) {
2842 float_raise(float_flag_invalid
, status
);
2844 } else if (float32_is_nan(a
) || float32_is_nan(b
)) {
2851 /* NOTE: the comma operator will make "cond" to eval to false,
2852 * but float*_is_unordered() is still called. */
2853 FOP_COND_S(f
, (float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
2854 FOP_COND_S(un
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
))
2855 FOP_COND_S(eq
, !float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2856 FOP_COND_S(ueq
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2857 FOP_COND_S(olt
, !float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2858 FOP_COND_S(ult
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2859 FOP_COND_S(ole
, !float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2860 FOP_COND_S(ule
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2861 /* NOTE: the comma operator will make "cond" to eval to false,
2862 * but float*_is_unordered() is still called. */
2863 FOP_COND_S(sf
, (float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
2864 FOP_COND_S(ngle
,float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
))
2865 FOP_COND_S(seq
, !float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2866 FOP_COND_S(ngl
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2867 FOP_COND_S(lt
, !float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2868 FOP_COND_S(nge
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2869 FOP_COND_S(le
, !float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2870 FOP_COND_S(ngt
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2872 #define FOP_COND_PS(op, condl, condh) \
2873 void do_cmp_ps_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2875 uint32_t fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
2876 uint32_t fsth0 = float32_abs(fdt0 >> 32); \
2877 uint32_t fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
2878 uint32_t fsth1 = float32_abs(fdt1 >> 32); \
2884 SET_FP_COND(cc, env->active_fpu); \
2886 CLEAR_FP_COND(cc, env->active_fpu); \
2888 SET_FP_COND(cc + 1, env->active_fpu); \
2890 CLEAR_FP_COND(cc + 1, env->active_fpu); \
2892 void do_cmpabs_ps_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2894 uint32_t fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
2895 uint32_t fsth0 = float32_abs(fdt0 >> 32); \
2896 uint32_t fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
2897 uint32_t fsth1 = float32_abs(fdt1 >> 32); \
2903 SET_FP_COND(cc, env->active_fpu); \
2905 CLEAR_FP_COND(cc, env->active_fpu); \
2907 SET_FP_COND(cc + 1, env->active_fpu); \
2909 CLEAR_FP_COND(cc + 1, env->active_fpu); \
2912 /* NOTE: the comma operator will make "cond" to eval to false,
2913 * but float*_is_unordered() is still called. */
2914 FOP_COND_PS(f
, (float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
2915 (float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
2916 FOP_COND_PS(un
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
),
2917 float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
2918 FOP_COND_PS(eq
, !float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2919 !float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) && float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2920 FOP_COND_PS(ueq
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2921 float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2922 FOP_COND_PS(olt
, !float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2923 !float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) && float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2924 FOP_COND_PS(ult
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2925 float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2926 FOP_COND_PS(ole
, !float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2927 !float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) && float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2928 FOP_COND_PS(ule
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2929 float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2930 /* NOTE: the comma operator will make "cond" to eval to false,
2931 * but float*_is_unordered() is still called. */
2932 FOP_COND_PS(sf
, (float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
2933 (float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
2934 FOP_COND_PS(ngle
,float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
),
2935 float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
2936 FOP_COND_PS(seq
, !float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2937 !float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) && float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2938 FOP_COND_PS(ngl
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2939 float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2940 FOP_COND_PS(lt
, !float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2941 !float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) && float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2942 FOP_COND_PS(nge
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2943 float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2944 FOP_COND_PS(le
, !float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2945 !float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) && float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2946 FOP_COND_PS(ngt
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2947 float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))