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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 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 (exception
< 0x100)
33 qemu_log("%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 #if !defined(CONFIG_USER_ONLY)
58 static void do_restore_state (void *pc_ptr
)
61 unsigned long pc
= (unsigned long) pc_ptr
;
65 cpu_restore_state (tb
, env
, pc
, NULL
);
70 target_ulong
do_clo (target_ulong t0
)
75 target_ulong
do_clz (target_ulong t0
)
80 #if defined(TARGET_MIPS64)
81 target_ulong
do_dclo (target_ulong t0
)
86 target_ulong
do_dclz (target_ulong t0
)
90 #endif /* TARGET_MIPS64 */
92 /* 64 bits arithmetic for 32 bits hosts */
93 static inline uint64_t get_HILO (void)
95 return ((uint64_t)(env
->active_tc
.HI
[0]) << 32) | (uint32_t)env
->active_tc
.LO
[0];
98 static inline void set_HILO (uint64_t HILO
)
100 env
->active_tc
.LO
[0] = (int32_t)HILO
;
101 env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
104 static inline void set_HIT0_LO (target_ulong t0
, uint64_t HILO
)
106 env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
107 t0
= env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
110 static inline void set_HI_LOT0 (target_ulong t0
, uint64_t HILO
)
112 t0
= env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
113 env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
116 #if TARGET_LONG_BITS > HOST_LONG_BITS
117 void do_madd (target_ulong t0
, target_ulong t1
)
121 tmp
= ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
);
122 set_HILO((int64_t)get_HILO() + tmp
);
125 void do_maddu (target_ulong t0
, target_ulong t1
)
129 tmp
= ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
);
130 set_HILO(get_HILO() + tmp
);
133 void do_msub (target_ulong t0
, target_ulong t1
)
137 tmp
= ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
);
138 set_HILO((int64_t)get_HILO() - tmp
);
141 void do_msubu (target_ulong t0
, target_ulong t1
)
145 tmp
= ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
);
146 set_HILO(get_HILO() - tmp
);
148 #endif /* TARGET_LONG_BITS > HOST_LONG_BITS */
150 /* Multiplication variants of the vr54xx. */
151 target_ulong
do_muls (target_ulong t0
, target_ulong t1
)
153 set_HI_LOT0(t0
, 0 - ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
158 target_ulong
do_mulsu (target_ulong t0
, target_ulong t1
)
160 set_HI_LOT0(t0
, 0 - ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
165 target_ulong
do_macc (target_ulong t0
, target_ulong t1
)
167 set_HI_LOT0(t0
, ((int64_t)get_HILO()) + ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
172 target_ulong
do_macchi (target_ulong t0
, target_ulong t1
)
174 set_HIT0_LO(t0
, ((int64_t)get_HILO()) + ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
179 target_ulong
do_maccu (target_ulong t0
, target_ulong t1
)
181 set_HI_LOT0(t0
, ((uint64_t)get_HILO()) + ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
186 target_ulong
do_macchiu (target_ulong t0
, target_ulong t1
)
188 set_HIT0_LO(t0
, ((uint64_t)get_HILO()) + ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
193 target_ulong
do_msac (target_ulong t0
, target_ulong t1
)
195 set_HI_LOT0(t0
, ((int64_t)get_HILO()) - ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
200 target_ulong
do_msachi (target_ulong t0
, target_ulong t1
)
202 set_HIT0_LO(t0
, ((int64_t)get_HILO()) - ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
207 target_ulong
do_msacu (target_ulong t0
, target_ulong t1
)
209 set_HI_LOT0(t0
, ((uint64_t)get_HILO()) - ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
214 target_ulong
do_msachiu (target_ulong t0
, target_ulong t1
)
216 set_HIT0_LO(t0
, ((uint64_t)get_HILO()) - ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
221 target_ulong
do_mulhi (target_ulong t0
, target_ulong t1
)
223 set_HIT0_LO(t0
, (int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
);
228 target_ulong
do_mulhiu (target_ulong t0
, target_ulong t1
)
230 set_HIT0_LO(t0
, (uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
);
235 target_ulong
do_mulshi (target_ulong t0
, target_ulong t1
)
237 set_HIT0_LO(t0
, 0 - ((int64_t)(int32_t)t0
* (int64_t)(int32_t)t1
));
242 target_ulong
do_mulshiu (target_ulong t0
, target_ulong t1
)
244 set_HIT0_LO(t0
, 0 - ((uint64_t)(uint32_t)t0
* (uint64_t)(uint32_t)t1
));
250 void do_dmult (target_ulong t0
, target_ulong t1
)
252 muls64(&(env
->active_tc
.LO
[0]), &(env
->active_tc
.HI
[0]), t0
, t1
);
255 void do_dmultu (target_ulong t0
, target_ulong t1
)
257 mulu64(&(env
->active_tc
.LO
[0]), &(env
->active_tc
.HI
[0]), t0
, t1
);
261 #ifdef TARGET_WORDS_BIGENDIAN
262 #define GET_LMASK(v) ((v) & 3)
263 #define GET_OFFSET(addr, offset) (addr + (offset))
265 #define GET_LMASK(v) (((v) & 3) ^ 3)
266 #define GET_OFFSET(addr, offset) (addr - (offset))
269 target_ulong
do_lwl(target_ulong t0
, target_ulong t1
, int mem_idx
)
273 #ifdef CONFIG_USER_ONLY
274 #define ldfun ldub_raw
276 int (*ldfun
)(target_ulong
);
280 case 0: ldfun
= ldub_kernel
; break;
281 case 1: ldfun
= ldub_super
; break;
283 case 2: ldfun
= ldub_user
; break;
287 t1
= (t1
& 0x00FFFFFF) | (tmp
<< 24);
289 if (GET_LMASK(t0
) <= 2) {
290 tmp
= ldfun(GET_OFFSET(t0
, 1));
291 t1
= (t1
& 0xFF00FFFF) | (tmp
<< 16);
294 if (GET_LMASK(t0
) <= 1) {
295 tmp
= ldfun(GET_OFFSET(t0
, 2));
296 t1
= (t1
& 0xFFFF00FF) | (tmp
<< 8);
299 if (GET_LMASK(t0
) == 0) {
300 tmp
= ldfun(GET_OFFSET(t0
, 3));
301 t1
= (t1
& 0xFFFFFF00) | tmp
;
306 target_ulong
do_lwr(target_ulong t0
, target_ulong t1
, int mem_idx
)
310 #ifdef CONFIG_USER_ONLY
311 #define ldfun ldub_raw
313 int (*ldfun
)(target_ulong
);
317 case 0: ldfun
= ldub_kernel
; break;
318 case 1: ldfun
= ldub_super
; break;
320 case 2: ldfun
= ldub_user
; break;
324 t1
= (t1
& 0xFFFFFF00) | tmp
;
326 if (GET_LMASK(t0
) >= 1) {
327 tmp
= ldfun(GET_OFFSET(t0
, -1));
328 t1
= (t1
& 0xFFFF00FF) | (tmp
<< 8);
331 if (GET_LMASK(t0
) >= 2) {
332 tmp
= ldfun(GET_OFFSET(t0
, -2));
333 t1
= (t1
& 0xFF00FFFF) | (tmp
<< 16);
336 if (GET_LMASK(t0
) == 3) {
337 tmp
= ldfun(GET_OFFSET(t0
, -3));
338 t1
= (t1
& 0x00FFFFFF) | (tmp
<< 24);
343 void do_swl(target_ulong t0
, target_ulong t1
, int mem_idx
)
345 #ifdef CONFIG_USER_ONLY
346 #define stfun stb_raw
348 void (*stfun
)(target_ulong
, int);
352 case 0: stfun
= stb_kernel
; break;
353 case 1: stfun
= stb_super
; break;
355 case 2: stfun
= stb_user
; break;
358 stfun(t0
, (uint8_t)(t1
>> 24));
360 if (GET_LMASK(t0
) <= 2)
361 stfun(GET_OFFSET(t0
, 1), (uint8_t)(t1
>> 16));
363 if (GET_LMASK(t0
) <= 1)
364 stfun(GET_OFFSET(t0
, 2), (uint8_t)(t1
>> 8));
366 if (GET_LMASK(t0
) == 0)
367 stfun(GET_OFFSET(t0
, 3), (uint8_t)t1
);
370 void do_swr(target_ulong t0
, target_ulong t1
, int mem_idx
)
372 #ifdef CONFIG_USER_ONLY
373 #define stfun stb_raw
375 void (*stfun
)(target_ulong
, int);
379 case 0: stfun
= stb_kernel
; break;
380 case 1: stfun
= stb_super
; break;
382 case 2: stfun
= stb_user
; break;
385 stfun(t0
, (uint8_t)t1
);
387 if (GET_LMASK(t0
) >= 1)
388 stfun(GET_OFFSET(t0
, -1), (uint8_t)(t1
>> 8));
390 if (GET_LMASK(t0
) >= 2)
391 stfun(GET_OFFSET(t0
, -2), (uint8_t)(t1
>> 16));
393 if (GET_LMASK(t0
) == 3)
394 stfun(GET_OFFSET(t0
, -3), (uint8_t)(t1
>> 24));
397 #if defined(TARGET_MIPS64)
398 /* "half" load and stores. We must do the memory access inline,
399 or fault handling won't work. */
401 #ifdef TARGET_WORDS_BIGENDIAN
402 #define GET_LMASK64(v) ((v) & 7)
404 #define GET_LMASK64(v) (((v) & 7) ^ 7)
407 target_ulong
do_ldl(target_ulong t0
, target_ulong t1
, int mem_idx
)
411 #ifdef CONFIG_USER_ONLY
412 #define ldfun ldub_raw
414 int (*ldfun
)(target_ulong
);
418 case 0: ldfun
= ldub_kernel
; break;
419 case 1: ldfun
= ldub_super
; break;
421 case 2: ldfun
= ldub_user
; break;
425 t1
= (t1
& 0x00FFFFFFFFFFFFFFULL
) | (tmp
<< 56);
427 if (GET_LMASK64(t0
) <= 6) {
428 tmp
= ldfun(GET_OFFSET(t0
, 1));
429 t1
= (t1
& 0xFF00FFFFFFFFFFFFULL
) | (tmp
<< 48);
432 if (GET_LMASK64(t0
) <= 5) {
433 tmp
= ldfun(GET_OFFSET(t0
, 2));
434 t1
= (t1
& 0xFFFF00FFFFFFFFFFULL
) | (tmp
<< 40);
437 if (GET_LMASK64(t0
) <= 4) {
438 tmp
= ldfun(GET_OFFSET(t0
, 3));
439 t1
= (t1
& 0xFFFFFF00FFFFFFFFULL
) | (tmp
<< 32);
442 if (GET_LMASK64(t0
) <= 3) {
443 tmp
= ldfun(GET_OFFSET(t0
, 4));
444 t1
= (t1
& 0xFFFFFFFF00FFFFFFULL
) | (tmp
<< 24);
447 if (GET_LMASK64(t0
) <= 2) {
448 tmp
= ldfun(GET_OFFSET(t0
, 5));
449 t1
= (t1
& 0xFFFFFFFFFF00FFFFULL
) | (tmp
<< 16);
452 if (GET_LMASK64(t0
) <= 1) {
453 tmp
= ldfun(GET_OFFSET(t0
, 6));
454 t1
= (t1
& 0xFFFFFFFFFFFF00FFULL
) | (tmp
<< 8);
457 if (GET_LMASK64(t0
) == 0) {
458 tmp
= ldfun(GET_OFFSET(t0
, 7));
459 t1
= (t1
& 0xFFFFFFFFFFFFFF00ULL
) | tmp
;
465 target_ulong
do_ldr(target_ulong t0
, target_ulong t1
, int mem_idx
)
469 #ifdef CONFIG_USER_ONLY
470 #define ldfun ldub_raw
472 int (*ldfun
)(target_ulong
);
476 case 0: ldfun
= ldub_kernel
; break;
477 case 1: ldfun
= ldub_super
; break;
479 case 2: ldfun
= ldub_user
; break;
483 t1
= (t1
& 0xFFFFFFFFFFFFFF00ULL
) | tmp
;
485 if (GET_LMASK64(t0
) >= 1) {
486 tmp
= ldfun(GET_OFFSET(t0
, -1));
487 t1
= (t1
& 0xFFFFFFFFFFFF00FFULL
) | (tmp
<< 8);
490 if (GET_LMASK64(t0
) >= 2) {
491 tmp
= ldfun(GET_OFFSET(t0
, -2));
492 t1
= (t1
& 0xFFFFFFFFFF00FFFFULL
) | (tmp
<< 16);
495 if (GET_LMASK64(t0
) >= 3) {
496 tmp
= ldfun(GET_OFFSET(t0
, -3));
497 t1
= (t1
& 0xFFFFFFFF00FFFFFFULL
) | (tmp
<< 24);
500 if (GET_LMASK64(t0
) >= 4) {
501 tmp
= ldfun(GET_OFFSET(t0
, -4));
502 t1
= (t1
& 0xFFFFFF00FFFFFFFFULL
) | (tmp
<< 32);
505 if (GET_LMASK64(t0
) >= 5) {
506 tmp
= ldfun(GET_OFFSET(t0
, -5));
507 t1
= (t1
& 0xFFFF00FFFFFFFFFFULL
) | (tmp
<< 40);
510 if (GET_LMASK64(t0
) >= 6) {
511 tmp
= ldfun(GET_OFFSET(t0
, -6));
512 t1
= (t1
& 0xFF00FFFFFFFFFFFFULL
) | (tmp
<< 48);
515 if (GET_LMASK64(t0
) == 7) {
516 tmp
= ldfun(GET_OFFSET(t0
, -7));
517 t1
= (t1
& 0x00FFFFFFFFFFFFFFULL
) | (tmp
<< 56);
523 void do_sdl(target_ulong t0
, target_ulong t1
, int mem_idx
)
525 #ifdef CONFIG_USER_ONLY
526 #define stfun stb_raw
528 void (*stfun
)(target_ulong
, int);
532 case 0: stfun
= stb_kernel
; break;
533 case 1: stfun
= stb_super
; break;
535 case 2: stfun
= stb_user
; break;
538 stfun(t0
, (uint8_t)(t1
>> 56));
540 if (GET_LMASK64(t0
) <= 6)
541 stfun(GET_OFFSET(t0
, 1), (uint8_t)(t1
>> 48));
543 if (GET_LMASK64(t0
) <= 5)
544 stfun(GET_OFFSET(t0
, 2), (uint8_t)(t1
>> 40));
546 if (GET_LMASK64(t0
) <= 4)
547 stfun(GET_OFFSET(t0
, 3), (uint8_t)(t1
>> 32));
549 if (GET_LMASK64(t0
) <= 3)
550 stfun(GET_OFFSET(t0
, 4), (uint8_t)(t1
>> 24));
552 if (GET_LMASK64(t0
) <= 2)
553 stfun(GET_OFFSET(t0
, 5), (uint8_t)(t1
>> 16));
555 if (GET_LMASK64(t0
) <= 1)
556 stfun(GET_OFFSET(t0
, 6), (uint8_t)(t1
>> 8));
558 if (GET_LMASK64(t0
) <= 0)
559 stfun(GET_OFFSET(t0
, 7), (uint8_t)t1
);
562 void do_sdr(target_ulong t0
, target_ulong t1
, int mem_idx
)
564 #ifdef CONFIG_USER_ONLY
565 #define stfun stb_raw
567 void (*stfun
)(target_ulong
, int);
571 case 0: stfun
= stb_kernel
; break;
572 case 1: stfun
= stb_super
; break;
574 case 2: stfun
= stb_user
; break;
577 stfun(t0
, (uint8_t)t1
);
579 if (GET_LMASK64(t0
) >= 1)
580 stfun(GET_OFFSET(t0
, -1), (uint8_t)(t1
>> 8));
582 if (GET_LMASK64(t0
) >= 2)
583 stfun(GET_OFFSET(t0
, -2), (uint8_t)(t1
>> 16));
585 if (GET_LMASK64(t0
) >= 3)
586 stfun(GET_OFFSET(t0
, -3), (uint8_t)(t1
>> 24));
588 if (GET_LMASK64(t0
) >= 4)
589 stfun(GET_OFFSET(t0
, -4), (uint8_t)(t1
>> 32));
591 if (GET_LMASK64(t0
) >= 5)
592 stfun(GET_OFFSET(t0
, -5), (uint8_t)(t1
>> 40));
594 if (GET_LMASK64(t0
) >= 6)
595 stfun(GET_OFFSET(t0
, -6), (uint8_t)(t1
>> 48));
597 if (GET_LMASK64(t0
) == 7)
598 stfun(GET_OFFSET(t0
, -7), (uint8_t)(t1
>> 56));
600 #endif /* TARGET_MIPS64 */
602 #ifndef CONFIG_USER_ONLY
604 target_ulong
do_mfc0_mvpcontrol (void)
606 return env
->mvp
->CP0_MVPControl
;
609 target_ulong
do_mfc0_mvpconf0 (void)
611 return env
->mvp
->CP0_MVPConf0
;
614 target_ulong
do_mfc0_mvpconf1 (void)
616 return env
->mvp
->CP0_MVPConf1
;
619 target_ulong
do_mfc0_random (void)
621 return (int32_t)cpu_mips_get_random(env
);
624 target_ulong
do_mfc0_tcstatus (void)
626 return env
->active_tc
.CP0_TCStatus
;
629 target_ulong
do_mftc0_tcstatus(void)
631 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
633 if (other_tc
== env
->current_tc
)
634 return env
->active_tc
.CP0_TCStatus
;
636 return env
->tcs
[other_tc
].CP0_TCStatus
;
639 target_ulong
do_mfc0_tcbind (void)
641 return env
->active_tc
.CP0_TCBind
;
644 target_ulong
do_mftc0_tcbind(void)
646 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
648 if (other_tc
== env
->current_tc
)
649 return env
->active_tc
.CP0_TCBind
;
651 return env
->tcs
[other_tc
].CP0_TCBind
;
654 target_ulong
do_mfc0_tcrestart (void)
656 return env
->active_tc
.PC
;
659 target_ulong
do_mftc0_tcrestart(void)
661 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
663 if (other_tc
== env
->current_tc
)
664 return env
->active_tc
.PC
;
666 return env
->tcs
[other_tc
].PC
;
669 target_ulong
do_mfc0_tchalt (void)
671 return env
->active_tc
.CP0_TCHalt
;
674 target_ulong
do_mftc0_tchalt(void)
676 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
678 if (other_tc
== env
->current_tc
)
679 return env
->active_tc
.CP0_TCHalt
;
681 return env
->tcs
[other_tc
].CP0_TCHalt
;
684 target_ulong
do_mfc0_tccontext (void)
686 return env
->active_tc
.CP0_TCContext
;
689 target_ulong
do_mftc0_tccontext(void)
691 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
693 if (other_tc
== env
->current_tc
)
694 return env
->active_tc
.CP0_TCContext
;
696 return env
->tcs
[other_tc
].CP0_TCContext
;
699 target_ulong
do_mfc0_tcschedule (void)
701 return env
->active_tc
.CP0_TCSchedule
;
704 target_ulong
do_mftc0_tcschedule(void)
706 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
708 if (other_tc
== env
->current_tc
)
709 return env
->active_tc
.CP0_TCSchedule
;
711 return env
->tcs
[other_tc
].CP0_TCSchedule
;
714 target_ulong
do_mfc0_tcschefback (void)
716 return env
->active_tc
.CP0_TCScheFBack
;
719 target_ulong
do_mftc0_tcschefback(void)
721 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
723 if (other_tc
== env
->current_tc
)
724 return env
->active_tc
.CP0_TCScheFBack
;
726 return env
->tcs
[other_tc
].CP0_TCScheFBack
;
729 target_ulong
do_mfc0_count (void)
731 return (int32_t)cpu_mips_get_count(env
);
734 target_ulong
do_mftc0_entryhi(void)
736 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
739 if (other_tc
== env
->current_tc
)
740 tcstatus
= env
->active_tc
.CP0_TCStatus
;
742 tcstatus
= env
->tcs
[other_tc
].CP0_TCStatus
;
744 return (env
->CP0_EntryHi
& ~0xff) | (tcstatus
& 0xff);
747 target_ulong
do_mftc0_status(void)
749 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
753 if (other_tc
== env
->current_tc
)
754 tcstatus
= env
->active_tc
.CP0_TCStatus
;
756 tcstatus
= env
->tcs
[other_tc
].CP0_TCStatus
;
758 t0
= env
->CP0_Status
& ~0xf1000018;
759 t0
|= tcstatus
& (0xf << CP0TCSt_TCU0
);
760 t0
|= (tcstatus
& (1 << CP0TCSt_TMX
)) >> (CP0TCSt_TMX
- CP0St_MX
);
761 t0
|= (tcstatus
& (0x3 << CP0TCSt_TKSU
)) >> (CP0TCSt_TKSU
- CP0St_KSU
);
766 target_ulong
do_mfc0_lladdr (void)
768 return (int32_t)env
->CP0_LLAddr
>> 4;
771 target_ulong
do_mfc0_watchlo (uint32_t sel
)
773 return (int32_t)env
->CP0_WatchLo
[sel
];
776 target_ulong
do_mfc0_watchhi (uint32_t sel
)
778 return env
->CP0_WatchHi
[sel
];
781 target_ulong
do_mfc0_debug (void)
783 target_ulong t0
= env
->CP0_Debug
;
784 if (env
->hflags
& MIPS_HFLAG_DM
)
790 target_ulong
do_mftc0_debug(void)
792 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
795 if (other_tc
== env
->current_tc
)
796 tcstatus
= env
->active_tc
.CP0_Debug_tcstatus
;
798 tcstatus
= env
->tcs
[other_tc
].CP0_Debug_tcstatus
;
800 /* XXX: Might be wrong, check with EJTAG spec. */
801 return (env
->CP0_Debug
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
802 (tcstatus
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
805 #if defined(TARGET_MIPS64)
806 target_ulong
do_dmfc0_tcrestart (void)
808 return env
->active_tc
.PC
;
811 target_ulong
do_dmfc0_tchalt (void)
813 return env
->active_tc
.CP0_TCHalt
;
816 target_ulong
do_dmfc0_tccontext (void)
818 return env
->active_tc
.CP0_TCContext
;
821 target_ulong
do_dmfc0_tcschedule (void)
823 return env
->active_tc
.CP0_TCSchedule
;
826 target_ulong
do_dmfc0_tcschefback (void)
828 return env
->active_tc
.CP0_TCScheFBack
;
831 target_ulong
do_dmfc0_lladdr (void)
833 return env
->CP0_LLAddr
>> 4;
836 target_ulong
do_dmfc0_watchlo (uint32_t sel
)
838 return env
->CP0_WatchLo
[sel
];
840 #endif /* TARGET_MIPS64 */
842 void do_mtc0_index (target_ulong t0
)
845 unsigned int tmp
= env
->tlb
->nb_tlb
;
851 env
->CP0_Index
= (env
->CP0_Index
& 0x80000000) | (t0
& (num
- 1));
854 void do_mtc0_mvpcontrol (target_ulong t0
)
859 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))
860 mask
|= (1 << CP0MVPCo_CPA
) | (1 << CP0MVPCo_VPC
) |
862 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
863 mask
|= (1 << CP0MVPCo_STLB
);
864 newval
= (env
->mvp
->CP0_MVPControl
& ~mask
) | (t0
& mask
);
866 // TODO: Enable/disable shared TLB, enable/disable VPEs.
868 env
->mvp
->CP0_MVPControl
= newval
;
871 void do_mtc0_vpecontrol (target_ulong t0
)
876 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
877 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
878 newval
= (env
->CP0_VPEControl
& ~mask
) | (t0
& mask
);
880 /* Yield scheduler intercept not implemented. */
881 /* Gating storage scheduler intercept not implemented. */
883 // TODO: Enable/disable TCs.
885 env
->CP0_VPEControl
= newval
;
888 void do_mtc0_vpeconf0 (target_ulong t0
)
893 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) {
894 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_VPA
))
895 mask
|= (0xff << CP0VPEC0_XTC
);
896 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
898 newval
= (env
->CP0_VPEConf0
& ~mask
) | (t0
& mask
);
900 // TODO: TC exclusive handling due to ERL/EXL.
902 env
->CP0_VPEConf0
= newval
;
905 void do_mtc0_vpeconf1 (target_ulong t0
)
910 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
911 mask
|= (0xff << CP0VPEC1_NCX
) | (0xff << CP0VPEC1_NCP2
) |
912 (0xff << CP0VPEC1_NCP1
);
913 newval
= (env
->CP0_VPEConf1
& ~mask
) | (t0
& mask
);
915 /* UDI not implemented. */
916 /* CP2 not implemented. */
918 // TODO: Handle FPU (CP1) binding.
920 env
->CP0_VPEConf1
= newval
;
923 void do_mtc0_yqmask (target_ulong t0
)
925 /* Yield qualifier inputs not implemented. */
926 env
->CP0_YQMask
= 0x00000000;
929 void do_mtc0_vpeopt (target_ulong t0
)
931 env
->CP0_VPEOpt
= t0
& 0x0000ffff;
934 void do_mtc0_entrylo0 (target_ulong t0
)
936 /* Large physaddr (PABITS) not implemented */
937 /* 1k pages not implemented */
938 env
->CP0_EntryLo0
= t0
& 0x3FFFFFFF;
941 void do_mtc0_tcstatus (target_ulong t0
)
943 uint32_t mask
= env
->CP0_TCStatus_rw_bitmask
;
946 newval
= (env
->active_tc
.CP0_TCStatus
& ~mask
) | (t0
& mask
);
948 // TODO: Sync with CP0_Status.
950 env
->active_tc
.CP0_TCStatus
= newval
;
953 void do_mttc0_tcstatus (target_ulong t0
)
955 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
957 // TODO: Sync with CP0_Status.
959 if (other_tc
== env
->current_tc
)
960 env
->active_tc
.CP0_TCStatus
= t0
;
962 env
->tcs
[other_tc
].CP0_TCStatus
= t0
;
965 void do_mtc0_tcbind (target_ulong t0
)
967 uint32_t mask
= (1 << CP0TCBd_TBE
);
970 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
971 mask
|= (1 << CP0TCBd_CurVPE
);
972 newval
= (env
->active_tc
.CP0_TCBind
& ~mask
) | (t0
& mask
);
973 env
->active_tc
.CP0_TCBind
= newval
;
976 void do_mttc0_tcbind (target_ulong t0
)
978 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
979 uint32_t mask
= (1 << CP0TCBd_TBE
);
982 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
983 mask
|= (1 << CP0TCBd_CurVPE
);
984 if (other_tc
== env
->current_tc
) {
985 newval
= (env
->active_tc
.CP0_TCBind
& ~mask
) | (t0
& mask
);
986 env
->active_tc
.CP0_TCBind
= newval
;
988 newval
= (env
->tcs
[other_tc
].CP0_TCBind
& ~mask
) | (t0
& mask
);
989 env
->tcs
[other_tc
].CP0_TCBind
= newval
;
993 void do_mtc0_tcrestart (target_ulong t0
)
995 env
->active_tc
.PC
= t0
;
996 env
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
997 env
->CP0_LLAddr
= 0ULL;
998 /* MIPS16 not implemented. */
1001 void do_mttc0_tcrestart (target_ulong t0
)
1003 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1005 if (other_tc
== env
->current_tc
) {
1006 env
->active_tc
.PC
= t0
;
1007 env
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1008 env
->CP0_LLAddr
= 0ULL;
1009 /* MIPS16 not implemented. */
1011 env
->tcs
[other_tc
].PC
= t0
;
1012 env
->tcs
[other_tc
].CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1013 env
->CP0_LLAddr
= 0ULL;
1014 /* MIPS16 not implemented. */
1018 void do_mtc0_tchalt (target_ulong t0
)
1020 env
->active_tc
.CP0_TCHalt
= t0
& 0x1;
1022 // TODO: Halt TC / Restart (if allocated+active) TC.
1025 void do_mttc0_tchalt (target_ulong t0
)
1027 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1029 // TODO: Halt TC / Restart (if allocated+active) TC.
1031 if (other_tc
== env
->current_tc
)
1032 env
->active_tc
.CP0_TCHalt
= t0
;
1034 env
->tcs
[other_tc
].CP0_TCHalt
= t0
;
1037 void do_mtc0_tccontext (target_ulong t0
)
1039 env
->active_tc
.CP0_TCContext
= t0
;
1042 void do_mttc0_tccontext (target_ulong t0
)
1044 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1046 if (other_tc
== env
->current_tc
)
1047 env
->active_tc
.CP0_TCContext
= t0
;
1049 env
->tcs
[other_tc
].CP0_TCContext
= t0
;
1052 void do_mtc0_tcschedule (target_ulong t0
)
1054 env
->active_tc
.CP0_TCSchedule
= t0
;
1057 void do_mttc0_tcschedule (target_ulong t0
)
1059 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1061 if (other_tc
== env
->current_tc
)
1062 env
->active_tc
.CP0_TCSchedule
= t0
;
1064 env
->tcs
[other_tc
].CP0_TCSchedule
= t0
;
1067 void do_mtc0_tcschefback (target_ulong t0
)
1069 env
->active_tc
.CP0_TCScheFBack
= t0
;
1072 void do_mttc0_tcschefback (target_ulong t0
)
1074 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1076 if (other_tc
== env
->current_tc
)
1077 env
->active_tc
.CP0_TCScheFBack
= t0
;
1079 env
->tcs
[other_tc
].CP0_TCScheFBack
= t0
;
1082 void do_mtc0_entrylo1 (target_ulong t0
)
1084 /* Large physaddr (PABITS) not implemented */
1085 /* 1k pages not implemented */
1086 env
->CP0_EntryLo1
= t0
& 0x3FFFFFFF;
1089 void do_mtc0_context (target_ulong t0
)
1091 env
->CP0_Context
= (env
->CP0_Context
& 0x007FFFFF) | (t0
& ~0x007FFFFF);
1094 void do_mtc0_pagemask (target_ulong t0
)
1096 /* 1k pages not implemented */
1097 env
->CP0_PageMask
= t0
& (0x1FFFFFFF & (TARGET_PAGE_MASK
<< 1));
1100 void do_mtc0_pagegrain (target_ulong t0
)
1102 /* SmartMIPS not implemented */
1103 /* Large physaddr (PABITS) not implemented */
1104 /* 1k pages not implemented */
1105 env
->CP0_PageGrain
= 0;
1108 void do_mtc0_wired (target_ulong t0
)
1110 env
->CP0_Wired
= t0
% env
->tlb
->nb_tlb
;
1113 void do_mtc0_srsconf0 (target_ulong t0
)
1115 env
->CP0_SRSConf0
|= t0
& env
->CP0_SRSConf0_rw_bitmask
;
1118 void do_mtc0_srsconf1 (target_ulong t0
)
1120 env
->CP0_SRSConf1
|= t0
& env
->CP0_SRSConf1_rw_bitmask
;
1123 void do_mtc0_srsconf2 (target_ulong t0
)
1125 env
->CP0_SRSConf2
|= t0
& env
->CP0_SRSConf2_rw_bitmask
;
1128 void do_mtc0_srsconf3 (target_ulong t0
)
1130 env
->CP0_SRSConf3
|= t0
& env
->CP0_SRSConf3_rw_bitmask
;
1133 void do_mtc0_srsconf4 (target_ulong t0
)
1135 env
->CP0_SRSConf4
|= t0
& env
->CP0_SRSConf4_rw_bitmask
;
1138 void do_mtc0_hwrena (target_ulong t0
)
1140 env
->CP0_HWREna
= t0
& 0x0000000F;
1143 void do_mtc0_count (target_ulong t0
)
1145 cpu_mips_store_count(env
, t0
);
1148 void do_mtc0_entryhi (target_ulong t0
)
1150 target_ulong old
, val
;
1152 /* 1k pages not implemented */
1153 val
= t0
& ((TARGET_PAGE_MASK
<< 1) | 0xFF);
1154 #if defined(TARGET_MIPS64)
1155 val
&= env
->SEGMask
;
1157 old
= env
->CP0_EntryHi
;
1158 env
->CP0_EntryHi
= val
;
1159 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
1160 uint32_t tcst
= env
->active_tc
.CP0_TCStatus
& ~0xff;
1161 env
->active_tc
.CP0_TCStatus
= tcst
| (val
& 0xff);
1163 /* If the ASID changes, flush qemu's TLB. */
1164 if ((old
& 0xFF) != (val
& 0xFF))
1165 cpu_mips_tlb_flush(env
, 1);
1168 void do_mttc0_entryhi(target_ulong t0
)
1170 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1173 env
->CP0_EntryHi
= (env
->CP0_EntryHi
& 0xff) | (t0
& ~0xff);
1174 if (other_tc
== env
->current_tc
) {
1175 tcstatus
= (env
->active_tc
.CP0_TCStatus
& ~0xff) | (t0
& 0xff);
1176 env
->active_tc
.CP0_TCStatus
= tcstatus
;
1178 tcstatus
= (env
->tcs
[other_tc
].CP0_TCStatus
& ~0xff) | (t0
& 0xff);
1179 env
->tcs
[other_tc
].CP0_TCStatus
= tcstatus
;
1183 void do_mtc0_compare (target_ulong t0
)
1185 cpu_mips_store_compare(env
, t0
);
1188 void do_mtc0_status (target_ulong t0
)
1191 uint32_t mask
= env
->CP0_Status_rw_bitmask
;
1194 old
= env
->CP0_Status
;
1195 env
->CP0_Status
= (env
->CP0_Status
& ~mask
) | val
;
1196 compute_hflags(env
);
1197 if (qemu_loglevel_mask(CPU_LOG_EXEC
))
1198 do_mtc0_status_debug(old
, val
);
1199 cpu_mips_update_irq(env
);
1202 void do_mttc0_status(target_ulong t0
)
1204 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1205 int32_t tcstatus
= env
->tcs
[other_tc
].CP0_TCStatus
;
1207 env
->CP0_Status
= t0
& ~0xf1000018;
1208 tcstatus
= (tcstatus
& ~(0xf << CP0TCSt_TCU0
)) | (t0
& (0xf << CP0St_CU0
));
1209 tcstatus
= (tcstatus
& ~(1 << CP0TCSt_TMX
)) | ((t0
& (1 << CP0St_MX
)) << (CP0TCSt_TMX
- CP0St_MX
));
1210 tcstatus
= (tcstatus
& ~(0x3 << CP0TCSt_TKSU
)) | ((t0
& (0x3 << CP0St_KSU
)) << (CP0TCSt_TKSU
- CP0St_KSU
));
1211 if (other_tc
== env
->current_tc
)
1212 env
->active_tc
.CP0_TCStatus
= tcstatus
;
1214 env
->tcs
[other_tc
].CP0_TCStatus
= tcstatus
;
1217 void do_mtc0_intctl (target_ulong t0
)
1219 /* vectored interrupts not implemented, no performance counters. */
1220 env
->CP0_IntCtl
= (env
->CP0_IntCtl
& ~0x000002e0) | (t0
& 0x000002e0);
1223 void do_mtc0_srsctl (target_ulong t0
)
1225 uint32_t mask
= (0xf << CP0SRSCtl_ESS
) | (0xf << CP0SRSCtl_PSS
);
1226 env
->CP0_SRSCtl
= (env
->CP0_SRSCtl
& ~mask
) | (t0
& mask
);
1229 void do_mtc0_cause (target_ulong t0
)
1231 uint32_t mask
= 0x00C00300;
1232 uint32_t old
= env
->CP0_Cause
;
1234 if (env
->insn_flags
& ISA_MIPS32R2
)
1235 mask
|= 1 << CP0Ca_DC
;
1237 env
->CP0_Cause
= (env
->CP0_Cause
& ~mask
) | (t0
& mask
);
1239 if ((old
^ env
->CP0_Cause
) & (1 << CP0Ca_DC
)) {
1240 if (env
->CP0_Cause
& (1 << CP0Ca_DC
))
1241 cpu_mips_stop_count(env
);
1243 cpu_mips_start_count(env
);
1246 /* Handle the software interrupt as an hardware one, as they
1248 if (t0
& CP0Ca_IP_mask
) {
1249 cpu_mips_update_irq(env
);
1253 void do_mtc0_ebase (target_ulong t0
)
1255 /* vectored interrupts not implemented */
1256 /* Multi-CPU not implemented */
1257 env
->CP0_EBase
= 0x80000000 | (t0
& 0x3FFFF000);
1260 void do_mtc0_config0 (target_ulong t0
)
1262 env
->CP0_Config0
= (env
->CP0_Config0
& 0x81FFFFF8) | (t0
& 0x00000007);
1265 void do_mtc0_config2 (target_ulong t0
)
1267 /* tertiary/secondary caches not implemented */
1268 env
->CP0_Config2
= (env
->CP0_Config2
& 0x8FFF0FFF);
1271 void do_mtc0_watchlo (target_ulong t0
, uint32_t sel
)
1273 /* Watch exceptions for instructions, data loads, data stores
1275 env
->CP0_WatchLo
[sel
] = (t0
& ~0x7);
1278 void do_mtc0_watchhi (target_ulong t0
, uint32_t sel
)
1280 env
->CP0_WatchHi
[sel
] = (t0
& 0x40FF0FF8);
1281 env
->CP0_WatchHi
[sel
] &= ~(env
->CP0_WatchHi
[sel
] & t0
& 0x7);
1284 void do_mtc0_xcontext (target_ulong t0
)
1286 target_ulong mask
= (1ULL << (env
->SEGBITS
- 7)) - 1;
1287 env
->CP0_XContext
= (env
->CP0_XContext
& mask
) | (t0
& ~mask
);
1290 void do_mtc0_framemask (target_ulong t0
)
1292 env
->CP0_Framemask
= t0
; /* XXX */
1295 void do_mtc0_debug (target_ulong t0
)
1297 env
->CP0_Debug
= (env
->CP0_Debug
& 0x8C03FC1F) | (t0
& 0x13300120);
1298 if (t0
& (1 << CP0DB_DM
))
1299 env
->hflags
|= MIPS_HFLAG_DM
;
1301 env
->hflags
&= ~MIPS_HFLAG_DM
;
1304 void do_mttc0_debug(target_ulong t0
)
1306 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1307 uint32_t val
= t0
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
));
1309 /* XXX: Might be wrong, check with EJTAG spec. */
1310 if (other_tc
== env
->current_tc
)
1311 env
->active_tc
.CP0_Debug_tcstatus
= val
;
1313 env
->tcs
[other_tc
].CP0_Debug_tcstatus
= val
;
1314 env
->CP0_Debug
= (env
->CP0_Debug
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
1315 (t0
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
1318 void do_mtc0_performance0 (target_ulong t0
)
1320 env
->CP0_Performance0
= t0
& 0x000007ff;
1323 void do_mtc0_taglo (target_ulong t0
)
1325 env
->CP0_TagLo
= t0
& 0xFFFFFCF6;
1328 void do_mtc0_datalo (target_ulong t0
)
1330 env
->CP0_DataLo
= t0
; /* XXX */
1333 void do_mtc0_taghi (target_ulong t0
)
1335 env
->CP0_TagHi
= t0
; /* XXX */
1338 void do_mtc0_datahi (target_ulong t0
)
1340 env
->CP0_DataHi
= t0
; /* XXX */
1343 void do_mtc0_status_debug(uint32_t old
, uint32_t val
)
1345 qemu_log("Status %08x (%08x) => %08x (%08x) Cause %08x",
1346 old
, old
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1347 val
, val
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1349 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
1350 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
1351 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
1352 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
1353 default: cpu_abort(env
, "Invalid MMU mode!\n"); break;
1357 void do_mtc0_status_irqraise_debug(void)
1359 qemu_log("Raise pending IRQs\n");
1362 /* MIPS MT functions */
1363 target_ulong
do_mftgpr(uint32_t sel
)
1365 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1367 if (other_tc
== env
->current_tc
)
1368 return env
->active_tc
.gpr
[sel
];
1370 return env
->tcs
[other_tc
].gpr
[sel
];
1373 target_ulong
do_mftlo(uint32_t sel
)
1375 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1377 if (other_tc
== env
->current_tc
)
1378 return env
->active_tc
.LO
[sel
];
1380 return env
->tcs
[other_tc
].LO
[sel
];
1383 target_ulong
do_mfthi(uint32_t sel
)
1385 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1387 if (other_tc
== env
->current_tc
)
1388 return env
->active_tc
.HI
[sel
];
1390 return env
->tcs
[other_tc
].HI
[sel
];
1393 target_ulong
do_mftacx(uint32_t sel
)
1395 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1397 if (other_tc
== env
->current_tc
)
1398 return env
->active_tc
.ACX
[sel
];
1400 return env
->tcs
[other_tc
].ACX
[sel
];
1403 target_ulong
do_mftdsp(void)
1405 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1407 if (other_tc
== env
->current_tc
)
1408 return env
->active_tc
.DSPControl
;
1410 return env
->tcs
[other_tc
].DSPControl
;
1413 void do_mttgpr(target_ulong t0
, uint32_t sel
)
1415 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1417 if (other_tc
== env
->current_tc
)
1418 env
->active_tc
.gpr
[sel
] = t0
;
1420 env
->tcs
[other_tc
].gpr
[sel
] = t0
;
1423 void do_mttlo(target_ulong t0
, uint32_t sel
)
1425 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1427 if (other_tc
== env
->current_tc
)
1428 env
->active_tc
.LO
[sel
] = t0
;
1430 env
->tcs
[other_tc
].LO
[sel
] = t0
;
1433 void do_mtthi(target_ulong t0
, uint32_t sel
)
1435 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1437 if (other_tc
== env
->current_tc
)
1438 env
->active_tc
.HI
[sel
] = t0
;
1440 env
->tcs
[other_tc
].HI
[sel
] = t0
;
1443 void do_mttacx(target_ulong t0
, uint32_t sel
)
1445 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1447 if (other_tc
== env
->current_tc
)
1448 env
->active_tc
.ACX
[sel
] = t0
;
1450 env
->tcs
[other_tc
].ACX
[sel
] = t0
;
1453 void do_mttdsp(target_ulong t0
)
1455 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1457 if (other_tc
== env
->current_tc
)
1458 env
->active_tc
.DSPControl
= t0
;
1460 env
->tcs
[other_tc
].DSPControl
= t0
;
1463 /* MIPS MT functions */
1464 target_ulong
do_dmt(target_ulong t0
)
1473 target_ulong
do_emt(target_ulong t0
)
1482 target_ulong
do_dvpe(target_ulong t0
)
1491 target_ulong
do_evpe(target_ulong t0
)
1499 #endif /* !CONFIG_USER_ONLY */
1501 void do_fork(target_ulong t0
, target_ulong t1
)
1505 // TODO: store to TC register
1508 target_ulong
do_yield(target_ulong t0
)
1511 /* No scheduling policy implemented. */
1513 if (env
->CP0_VPEControl
& (1 << CP0VPECo_YSI
) &&
1514 env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_DT
)) {
1515 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1516 env
->CP0_VPEControl
|= 4 << CP0VPECo_EXCPT
;
1517 do_raise_exception(EXCP_THREAD
);
1520 } else if (t0
== 0) {
1521 if (0 /* TODO: TC underflow */) {
1522 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1523 do_raise_exception(EXCP_THREAD
);
1525 // TODO: Deallocate TC
1527 } else if (t0
> 0) {
1528 /* Yield qualifier inputs not implemented. */
1529 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1530 env
->CP0_VPEControl
|= 2 << CP0VPECo_EXCPT
;
1531 do_raise_exception(EXCP_THREAD
);
1533 return env
->CP0_YQMask
;
1536 #ifndef CONFIG_USER_ONLY
1537 /* TLB management */
1538 void cpu_mips_tlb_flush (CPUState
*env
, int flush_global
)
1540 /* Flush qemu's TLB and discard all shadowed entries. */
1541 tlb_flush (env
, flush_global
);
1542 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
1545 static void r4k_mips_tlb_flush_extra (CPUState
*env
, int first
)
1547 /* Discard entries from env->tlb[first] onwards. */
1548 while (env
->tlb
->tlb_in_use
> first
) {
1549 r4k_invalidate_tlb(env
, --env
->tlb
->tlb_in_use
, 0);
1553 static void r4k_fill_tlb (int idx
)
1557 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
1558 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1559 tlb
->VPN
= env
->CP0_EntryHi
& (TARGET_PAGE_MASK
<< 1);
1560 #if defined(TARGET_MIPS64)
1561 tlb
->VPN
&= env
->SEGMask
;
1563 tlb
->ASID
= env
->CP0_EntryHi
& 0xFF;
1564 tlb
->PageMask
= env
->CP0_PageMask
;
1565 tlb
->G
= env
->CP0_EntryLo0
& env
->CP0_EntryLo1
& 1;
1566 tlb
->V0
= (env
->CP0_EntryLo0
& 2) != 0;
1567 tlb
->D0
= (env
->CP0_EntryLo0
& 4) != 0;
1568 tlb
->C0
= (env
->CP0_EntryLo0
>> 3) & 0x7;
1569 tlb
->PFN
[0] = (env
->CP0_EntryLo0
>> 6) << 12;
1570 tlb
->V1
= (env
->CP0_EntryLo1
& 2) != 0;
1571 tlb
->D1
= (env
->CP0_EntryLo1
& 4) != 0;
1572 tlb
->C1
= (env
->CP0_EntryLo1
>> 3) & 0x7;
1573 tlb
->PFN
[1] = (env
->CP0_EntryLo1
>> 6) << 12;
1576 void r4k_do_tlbwi (void)
1580 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
1582 /* Discard cached TLB entries. We could avoid doing this if the
1583 tlbwi is just upgrading access permissions on the current entry;
1584 that might be a further win. */
1585 r4k_mips_tlb_flush_extra (env
, env
->tlb
->nb_tlb
);
1587 r4k_invalidate_tlb(env
, idx
, 0);
1591 void r4k_do_tlbwr (void)
1593 int r
= cpu_mips_get_random(env
);
1595 r4k_invalidate_tlb(env
, r
, 1);
1599 void r4k_do_tlbp (void)
1608 ASID
= env
->CP0_EntryHi
& 0xFF;
1609 for (i
= 0; i
< env
->tlb
->nb_tlb
; i
++) {
1610 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
1611 /* 1k pages are not supported. */
1612 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
1613 tag
= env
->CP0_EntryHi
& ~mask
;
1614 VPN
= tlb
->VPN
& ~mask
;
1615 /* Check ASID, virtual page number & size */
1616 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
1622 if (i
== env
->tlb
->nb_tlb
) {
1623 /* No match. Discard any shadow entries, if any of them match. */
1624 for (i
= env
->tlb
->nb_tlb
; i
< env
->tlb
->tlb_in_use
; i
++) {
1625 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
1626 /* 1k pages are not supported. */
1627 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
1628 tag
= env
->CP0_EntryHi
& ~mask
;
1629 VPN
= tlb
->VPN
& ~mask
;
1630 /* Check ASID, virtual page number & size */
1631 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
1632 r4k_mips_tlb_flush_extra (env
, i
);
1637 env
->CP0_Index
|= 0x80000000;
1641 void r4k_do_tlbr (void)
1647 ASID
= env
->CP0_EntryHi
& 0xFF;
1648 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
1649 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1651 /* If this will change the current ASID, flush qemu's TLB. */
1652 if (ASID
!= tlb
->ASID
)
1653 cpu_mips_tlb_flush (env
, 1);
1655 r4k_mips_tlb_flush_extra(env
, env
->tlb
->nb_tlb
);
1657 env
->CP0_EntryHi
= tlb
->VPN
| tlb
->ASID
;
1658 env
->CP0_PageMask
= tlb
->PageMask
;
1659 env
->CP0_EntryLo0
= tlb
->G
| (tlb
->V0
<< 1) | (tlb
->D0
<< 2) |
1660 (tlb
->C0
<< 3) | (tlb
->PFN
[0] >> 6);
1661 env
->CP0_EntryLo1
= tlb
->G
| (tlb
->V1
<< 1) | (tlb
->D1
<< 2) |
1662 (tlb
->C1
<< 3) | (tlb
->PFN
[1] >> 6);
1667 env
->tlb
->do_tlbwi();
1672 env
->tlb
->do_tlbwr();
1677 env
->tlb
->do_tlbp();
1682 env
->tlb
->do_tlbr();
1686 target_ulong
do_di (void)
1688 target_ulong t0
= env
->CP0_Status
;
1690 env
->CP0_Status
= t0
& ~(1 << CP0St_IE
);
1691 cpu_mips_update_irq(env
);
1696 target_ulong
do_ei (void)
1698 target_ulong t0
= env
->CP0_Status
;
1700 env
->CP0_Status
= t0
| (1 << CP0St_IE
);
1701 cpu_mips_update_irq(env
);
1706 static void debug_pre_eret (void)
1708 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
1709 qemu_log("ERET: PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
1710 env
->active_tc
.PC
, env
->CP0_EPC
);
1711 if (env
->CP0_Status
& (1 << CP0St_ERL
))
1712 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
1713 if (env
->hflags
& MIPS_HFLAG_DM
)
1714 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
1719 static void debug_post_eret (void)
1721 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
1722 qemu_log(" => PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
1723 env
->active_tc
.PC
, env
->CP0_EPC
);
1724 if (env
->CP0_Status
& (1 << CP0St_ERL
))
1725 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
1726 if (env
->hflags
& MIPS_HFLAG_DM
)
1727 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
1728 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
1729 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
1730 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
1731 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
1732 default: cpu_abort(env
, "Invalid MMU mode!\n"); break;
1740 if (env
->CP0_Status
& (1 << CP0St_ERL
)) {
1741 env
->active_tc
.PC
= env
->CP0_ErrorEPC
;
1742 env
->CP0_Status
&= ~(1 << CP0St_ERL
);
1744 env
->active_tc
.PC
= env
->CP0_EPC
;
1745 env
->CP0_Status
&= ~(1 << CP0St_EXL
);
1747 compute_hflags(env
);
1749 env
->CP0_LLAddr
= 1;
1752 void do_deret (void)
1755 env
->active_tc
.PC
= env
->CP0_DEPC
;
1756 env
->hflags
&= MIPS_HFLAG_DM
;
1757 compute_hflags(env
);
1759 env
->CP0_LLAddr
= 1;
1761 #endif /* !CONFIG_USER_ONLY */
1763 target_ulong
do_rdhwr_cpunum(void)
1765 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
1766 (env
->CP0_HWREna
& (1 << 0)))
1767 return env
->CP0_EBase
& 0x3ff;
1769 do_raise_exception(EXCP_RI
);
1774 target_ulong
do_rdhwr_synci_step(void)
1776 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
1777 (env
->CP0_HWREna
& (1 << 1)))
1778 return env
->SYNCI_Step
;
1780 do_raise_exception(EXCP_RI
);
1785 target_ulong
do_rdhwr_cc(void)
1787 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
1788 (env
->CP0_HWREna
& (1 << 2)))
1789 return env
->CP0_Count
;
1791 do_raise_exception(EXCP_RI
);
1796 target_ulong
do_rdhwr_ccres(void)
1798 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
1799 (env
->CP0_HWREna
& (1 << 3)))
1802 do_raise_exception(EXCP_RI
);
1807 void do_pmon (int function
)
1811 case 2: /* TODO: char inbyte(int waitflag); */
1812 if (env
->active_tc
.gpr
[4] == 0)
1813 env
->active_tc
.gpr
[2] = -1;
1815 case 11: /* TODO: char inbyte (void); */
1816 env
->active_tc
.gpr
[2] = -1;
1820 printf("%c", (char)(env
->active_tc
.gpr
[4] & 0xFF));
1826 unsigned char *fmt
= (void *)(unsigned long)env
->active_tc
.gpr
[4];
1836 do_raise_exception(EXCP_HLT
);
1839 #if !defined(CONFIG_USER_ONLY)
1841 static void do_unaligned_access (target_ulong addr
, int is_write
, int is_user
, void *retaddr
);
1843 #define MMUSUFFIX _mmu
1844 #define ALIGNED_ONLY
1847 #include "softmmu_template.h"
1850 #include "softmmu_template.h"
1853 #include "softmmu_template.h"
1856 #include "softmmu_template.h"
1858 static void do_unaligned_access (target_ulong addr
, int is_write
, int is_user
, void *retaddr
)
1860 env
->CP0_BadVAddr
= addr
;
1861 do_restore_state (retaddr
);
1862 do_raise_exception ((is_write
== 1) ? EXCP_AdES
: EXCP_AdEL
);
1865 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
1867 TranslationBlock
*tb
;
1868 CPUState
*saved_env
;
1872 /* XXX: hack to restore env in all cases, even if not called from
1875 env
= cpu_single_env
;
1876 ret
= cpu_mips_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
1879 /* now we have a real cpu fault */
1880 pc
= (unsigned long)retaddr
;
1881 tb
= tb_find_pc(pc
);
1883 /* the PC is inside the translated code. It means that we have
1884 a virtual CPU fault */
1885 cpu_restore_state(tb
, env
, pc
, NULL
);
1888 do_raise_exception_err(env
->exception_index
, env
->error_code
);
1893 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
1894 int unused
, int size
)
1897 do_raise_exception(EXCP_IBE
);
1899 do_raise_exception(EXCP_DBE
);
1901 #endif /* !CONFIG_USER_ONLY */
1903 /* Complex FPU operations which may need stack space. */
1905 #define FLOAT_ONE32 make_float32(0x3f8 << 20)
1906 #define FLOAT_ONE64 make_float64(0x3ffULL << 52)
1907 #define FLOAT_TWO32 make_float32(1 << 30)
1908 #define FLOAT_TWO64 make_float64(1ULL << 62)
1909 #define FLOAT_QNAN32 0x7fbfffff
1910 #define FLOAT_QNAN64 0x7ff7ffffffffffffULL
1911 #define FLOAT_SNAN32 0x7fffffff
1912 #define FLOAT_SNAN64 0x7fffffffffffffffULL
1914 /* convert MIPS rounding mode in FCR31 to IEEE library */
1915 unsigned int ieee_rm
[] = {
1916 float_round_nearest_even
,
1917 float_round_to_zero
,
1922 #define RESTORE_ROUNDING_MODE \
1923 set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3], &env->active_fpu.fp_status)
1925 target_ulong
do_cfc1 (uint32_t reg
)
1931 t0
= (int32_t)env
->active_fpu
.fcr0
;
1934 t0
= ((env
->active_fpu
.fcr31
>> 24) & 0xfe) | ((env
->active_fpu
.fcr31
>> 23) & 0x1);
1937 t0
= env
->active_fpu
.fcr31
& 0x0003f07c;
1940 t0
= (env
->active_fpu
.fcr31
& 0x00000f83) | ((env
->active_fpu
.fcr31
>> 22) & 0x4);
1943 t0
= (int32_t)env
->active_fpu
.fcr31
;
1950 void do_ctc1 (target_ulong t0
, uint32_t reg
)
1954 if (t0
& 0xffffff00)
1956 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0x017fffff) | ((t0
& 0xfe) << 24) |
1960 if (t0
& 0x007c0000)
1962 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfffc0f83) | (t0
& 0x0003f07c);
1965 if (t0
& 0x007c0000)
1967 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfefff07c) | (t0
& 0x00000f83) |
1971 if (t0
& 0x007c0000)
1973 env
->active_fpu
.fcr31
= t0
;
1978 /* set rounding mode */
1979 RESTORE_ROUNDING_MODE
;
1980 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
1981 if ((GET_FP_ENABLE(env
->active_fpu
.fcr31
) | 0x20) & GET_FP_CAUSE(env
->active_fpu
.fcr31
))
1982 do_raise_exception(EXCP_FPE
);
1985 static inline char ieee_ex_to_mips(char xcpt
)
1987 return (xcpt
& float_flag_inexact
) >> 5 |
1988 (xcpt
& float_flag_underflow
) >> 3 |
1989 (xcpt
& float_flag_overflow
) >> 1 |
1990 (xcpt
& float_flag_divbyzero
) << 1 |
1991 (xcpt
& float_flag_invalid
) << 4;
1994 static inline char mips_ex_to_ieee(char xcpt
)
1996 return (xcpt
& FP_INEXACT
) << 5 |
1997 (xcpt
& FP_UNDERFLOW
) << 3 |
1998 (xcpt
& FP_OVERFLOW
) << 1 |
1999 (xcpt
& FP_DIV0
) >> 1 |
2000 (xcpt
& FP_INVALID
) >> 4;
2003 static inline void update_fcr31(void)
2005 int tmp
= ieee_ex_to_mips(get_float_exception_flags(&env
->active_fpu
.fp_status
));
2007 SET_FP_CAUSE(env
->active_fpu
.fcr31
, tmp
);
2008 if (GET_FP_ENABLE(env
->active_fpu
.fcr31
) & tmp
)
2009 do_raise_exception(EXCP_FPE
);
2011 UPDATE_FP_FLAGS(env
->active_fpu
.fcr31
, tmp
);
2015 Single precition routines have a "s" suffix, double precision a
2016 "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
2017 paired single lower "pl", paired single upper "pu". */
2019 /* unary operations, modifying fp status */
2020 uint64_t do_float_sqrt_d(uint64_t fdt0
)
2022 return float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2025 uint32_t do_float_sqrt_s(uint32_t fst0
)
2027 return float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2030 uint64_t do_float_cvtd_s(uint32_t fst0
)
2034 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2035 fdt2
= float32_to_float64(fst0
, &env
->active_fpu
.fp_status
);
2040 uint64_t do_float_cvtd_w(uint32_t wt0
)
2044 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2045 fdt2
= int32_to_float64(wt0
, &env
->active_fpu
.fp_status
);
2050 uint64_t do_float_cvtd_l(uint64_t dt0
)
2054 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2055 fdt2
= int64_to_float64(dt0
, &env
->active_fpu
.fp_status
);
2060 uint64_t do_float_cvtl_d(uint64_t fdt0
)
2064 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2065 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2067 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2072 uint64_t do_float_cvtl_s(uint32_t fst0
)
2076 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2077 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2079 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2084 uint64_t do_float_cvtps_pw(uint64_t dt0
)
2089 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2090 fst2
= int32_to_float32(dt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2091 fsth2
= int32_to_float32(dt0
>> 32, &env
->active_fpu
.fp_status
);
2093 return ((uint64_t)fsth2
<< 32) | fst2
;
2096 uint64_t do_float_cvtpw_ps(uint64_t fdt0
)
2101 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2102 wt2
= float32_to_int32(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2103 wth2
= float32_to_int32(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2105 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
)) {
2107 wth2
= FLOAT_SNAN32
;
2109 return ((uint64_t)wth2
<< 32) | wt2
;
2112 uint32_t do_float_cvts_d(uint64_t fdt0
)
2116 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2117 fst2
= float64_to_float32(fdt0
, &env
->active_fpu
.fp_status
);
2122 uint32_t do_float_cvts_w(uint32_t wt0
)
2126 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2127 fst2
= int32_to_float32(wt0
, &env
->active_fpu
.fp_status
);
2132 uint32_t do_float_cvts_l(uint64_t dt0
)
2136 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2137 fst2
= int64_to_float32(dt0
, &env
->active_fpu
.fp_status
);
2142 uint32_t do_float_cvts_pl(uint32_t wt0
)
2146 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2152 uint32_t do_float_cvts_pu(uint32_t wth0
)
2156 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2162 uint32_t do_float_cvtw_s(uint32_t fst0
)
2166 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2167 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2169 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2174 uint32_t do_float_cvtw_d(uint64_t fdt0
)
2178 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2179 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2181 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2186 uint64_t do_float_roundl_d(uint64_t fdt0
)
2190 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2191 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2192 RESTORE_ROUNDING_MODE
;
2194 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2199 uint64_t do_float_roundl_s(uint32_t fst0
)
2203 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2204 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2205 RESTORE_ROUNDING_MODE
;
2207 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2212 uint32_t do_float_roundw_d(uint64_t fdt0
)
2216 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2217 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2218 RESTORE_ROUNDING_MODE
;
2220 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2225 uint32_t do_float_roundw_s(uint32_t fst0
)
2229 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2230 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2231 RESTORE_ROUNDING_MODE
;
2233 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2238 uint64_t do_float_truncl_d(uint64_t fdt0
)
2242 dt2
= float64_to_int64_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2244 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2249 uint64_t do_float_truncl_s(uint32_t fst0
)
2253 dt2
= float32_to_int64_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2255 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2260 uint32_t do_float_truncw_d(uint64_t fdt0
)
2264 wt2
= float64_to_int32_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2266 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2271 uint32_t do_float_truncw_s(uint32_t fst0
)
2275 wt2
= float32_to_int32_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2277 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2282 uint64_t do_float_ceill_d(uint64_t fdt0
)
2286 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2287 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2288 RESTORE_ROUNDING_MODE
;
2290 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2295 uint64_t do_float_ceill_s(uint32_t fst0
)
2299 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2300 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2301 RESTORE_ROUNDING_MODE
;
2303 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2308 uint32_t do_float_ceilw_d(uint64_t fdt0
)
2312 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2313 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2314 RESTORE_ROUNDING_MODE
;
2316 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2321 uint32_t do_float_ceilw_s(uint32_t fst0
)
2325 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2326 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2327 RESTORE_ROUNDING_MODE
;
2329 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2334 uint64_t do_float_floorl_d(uint64_t fdt0
)
2338 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2339 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2340 RESTORE_ROUNDING_MODE
;
2342 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2347 uint64_t do_float_floorl_s(uint32_t fst0
)
2351 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2352 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2353 RESTORE_ROUNDING_MODE
;
2355 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2360 uint32_t do_float_floorw_d(uint64_t fdt0
)
2364 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2365 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2366 RESTORE_ROUNDING_MODE
;
2368 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2373 uint32_t do_float_floorw_s(uint32_t fst0
)
2377 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2378 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2379 RESTORE_ROUNDING_MODE
;
2381 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2386 /* unary operations, not modifying fp status */
2387 #define FLOAT_UNOP(name) \
2388 uint64_t do_float_ ## name ## _d(uint64_t fdt0) \
2390 return float64_ ## name(fdt0); \
2392 uint32_t do_float_ ## name ## _s(uint32_t fst0) \
2394 return float32_ ## name(fst0); \
2396 uint64_t do_float_ ## name ## _ps(uint64_t fdt0) \
2401 wt0 = float32_ ## name(fdt0 & 0XFFFFFFFF); \
2402 wth0 = float32_ ## name(fdt0 >> 32); \
2403 return ((uint64_t)wth0 << 32) | wt0; \
2409 /* MIPS specific unary operations */
2410 uint64_t do_float_recip_d(uint64_t fdt0
)
2414 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2415 fdt2
= float64_div(FLOAT_ONE64
, fdt0
, &env
->active_fpu
.fp_status
);
2420 uint32_t do_float_recip_s(uint32_t fst0
)
2424 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2425 fst2
= float32_div(FLOAT_ONE32
, fst0
, &env
->active_fpu
.fp_status
);
2430 uint64_t do_float_rsqrt_d(uint64_t fdt0
)
2434 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2435 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2436 fdt2
= float64_div(FLOAT_ONE64
, fdt2
, &env
->active_fpu
.fp_status
);
2441 uint32_t do_float_rsqrt_s(uint32_t fst0
)
2445 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2446 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2447 fst2
= float32_div(FLOAT_ONE32
, fst2
, &env
->active_fpu
.fp_status
);
2452 uint64_t do_float_recip1_d(uint64_t fdt0
)
2456 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2457 fdt2
= float64_div(FLOAT_ONE64
, fdt0
, &env
->active_fpu
.fp_status
);
2462 uint32_t do_float_recip1_s(uint32_t fst0
)
2466 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2467 fst2
= float32_div(FLOAT_ONE32
, fst0
, &env
->active_fpu
.fp_status
);
2472 uint64_t do_float_recip1_ps(uint64_t fdt0
)
2477 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2478 fst2
= float32_div(FLOAT_ONE32
, fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2479 fsth2
= float32_div(FLOAT_ONE32
, fdt0
>> 32, &env
->active_fpu
.fp_status
);
2481 return ((uint64_t)fsth2
<< 32) | fst2
;
2484 uint64_t do_float_rsqrt1_d(uint64_t fdt0
)
2488 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2489 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2490 fdt2
= float64_div(FLOAT_ONE64
, fdt2
, &env
->active_fpu
.fp_status
);
2495 uint32_t do_float_rsqrt1_s(uint32_t fst0
)
2499 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2500 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2501 fst2
= float32_div(FLOAT_ONE32
, fst2
, &env
->active_fpu
.fp_status
);
2506 uint64_t do_float_rsqrt1_ps(uint64_t fdt0
)
2511 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2512 fst2
= float32_sqrt(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2513 fsth2
= float32_sqrt(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2514 fst2
= float32_div(FLOAT_ONE32
, fst2
, &env
->active_fpu
.fp_status
);
2515 fsth2
= float32_div(FLOAT_ONE32
, fsth2
, &env
->active_fpu
.fp_status
);
2517 return ((uint64_t)fsth2
<< 32) | fst2
;
2520 #define FLOAT_OP(name, p) void do_float_##name##_##p(void)
2522 /* binary operations */
2523 #define FLOAT_BINOP(name) \
2524 uint64_t do_float_ ## name ## _d(uint64_t fdt0, uint64_t fdt1) \
2528 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2529 dt2 = float64_ ## name (fdt0, fdt1, &env->active_fpu.fp_status); \
2531 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
2532 dt2 = FLOAT_QNAN64; \
2536 uint32_t do_float_ ## name ## _s(uint32_t fst0, uint32_t fst1) \
2540 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2541 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2543 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
2544 wt2 = FLOAT_QNAN32; \
2548 uint64_t do_float_ ## name ## _ps(uint64_t fdt0, uint64_t fdt1) \
2550 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2551 uint32_t fsth0 = fdt0 >> 32; \
2552 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2553 uint32_t fsth1 = fdt1 >> 32; \
2557 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2558 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2559 wth2 = float32_ ## name (fsth0, fsth1, &env->active_fpu.fp_status); \
2561 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) { \
2562 wt2 = FLOAT_QNAN32; \
2563 wth2 = FLOAT_QNAN32; \
2565 return ((uint64_t)wth2 << 32) | wt2; \
2574 /* ternary operations */
2575 #define FLOAT_TERNOP(name1, name2) \
2576 uint64_t do_float_ ## name1 ## name2 ## _d(uint64_t fdt0, uint64_t fdt1, \
2579 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
2580 return float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
2583 uint32_t do_float_ ## name1 ## name2 ## _s(uint32_t fst0, uint32_t fst1, \
2586 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2587 return float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2590 uint64_t do_float_ ## name1 ## name2 ## _ps(uint64_t fdt0, uint64_t fdt1, \
2593 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2594 uint32_t fsth0 = fdt0 >> 32; \
2595 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2596 uint32_t fsth1 = fdt1 >> 32; \
2597 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
2598 uint32_t fsth2 = fdt2 >> 32; \
2600 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2601 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
2602 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2603 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
2604 return ((uint64_t)fsth2 << 32) | fst2; \
2607 FLOAT_TERNOP(mul
, add
)
2608 FLOAT_TERNOP(mul
, sub
)
2611 /* negated ternary operations */
2612 #define FLOAT_NTERNOP(name1, name2) \
2613 uint64_t do_float_n ## name1 ## name2 ## _d(uint64_t fdt0, uint64_t fdt1, \
2616 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
2617 fdt2 = float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
2618 return float64_chs(fdt2); \
2621 uint32_t do_float_n ## name1 ## name2 ## _s(uint32_t fst0, uint32_t fst1, \
2624 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2625 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2626 return float32_chs(fst2); \
2629 uint64_t do_float_n ## name1 ## name2 ## _ps(uint64_t fdt0, uint64_t fdt1,\
2632 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2633 uint32_t fsth0 = fdt0 >> 32; \
2634 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2635 uint32_t fsth1 = fdt1 >> 32; \
2636 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
2637 uint32_t fsth2 = fdt2 >> 32; \
2639 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2640 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
2641 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2642 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
2643 fst2 = float32_chs(fst2); \
2644 fsth2 = float32_chs(fsth2); \
2645 return ((uint64_t)fsth2 << 32) | fst2; \
2648 FLOAT_NTERNOP(mul
, add
)
2649 FLOAT_NTERNOP(mul
, sub
)
2650 #undef FLOAT_NTERNOP
2652 /* MIPS specific binary operations */
2653 uint64_t do_float_recip2_d(uint64_t fdt0
, uint64_t fdt2
)
2655 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2656 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
2657 fdt2
= float64_chs(float64_sub(fdt2
, FLOAT_ONE64
, &env
->active_fpu
.fp_status
));
2662 uint32_t do_float_recip2_s(uint32_t fst0
, uint32_t fst2
)
2664 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2665 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
2666 fst2
= float32_chs(float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
));
2671 uint64_t do_float_recip2_ps(uint64_t fdt0
, uint64_t fdt2
)
2673 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
2674 uint32_t fsth0
= fdt0
>> 32;
2675 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
2676 uint32_t fsth2
= fdt2
>> 32;
2678 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2679 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
2680 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
2681 fst2
= float32_chs(float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
));
2682 fsth2
= float32_chs(float32_sub(fsth2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
));
2684 return ((uint64_t)fsth2
<< 32) | fst2
;
2687 uint64_t do_float_rsqrt2_d(uint64_t fdt0
, uint64_t fdt2
)
2689 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2690 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
2691 fdt2
= float64_sub(fdt2
, FLOAT_ONE64
, &env
->active_fpu
.fp_status
);
2692 fdt2
= float64_chs(float64_div(fdt2
, FLOAT_TWO64
, &env
->active_fpu
.fp_status
));
2697 uint32_t do_float_rsqrt2_s(uint32_t fst0
, uint32_t fst2
)
2699 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2700 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
2701 fst2
= float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
);
2702 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
2707 uint64_t do_float_rsqrt2_ps(uint64_t fdt0
, uint64_t fdt2
)
2709 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
2710 uint32_t fsth0
= fdt0
>> 32;
2711 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
2712 uint32_t fsth2
= fdt2
>> 32;
2714 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2715 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
2716 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
2717 fst2
= float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
);
2718 fsth2
= float32_sub(fsth2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
);
2719 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
2720 fsth2
= float32_chs(float32_div(fsth2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
2722 return ((uint64_t)fsth2
<< 32) | fst2
;
2725 uint64_t do_float_addr_ps(uint64_t fdt0
, uint64_t fdt1
)
2727 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
2728 uint32_t fsth0
= fdt0
>> 32;
2729 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
2730 uint32_t fsth1
= fdt1
>> 32;
2734 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2735 fst2
= float32_add (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
2736 fsth2
= float32_add (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
2738 return ((uint64_t)fsth2
<< 32) | fst2
;
2741 uint64_t do_float_mulr_ps(uint64_t fdt0
, uint64_t fdt1
)
2743 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
2744 uint32_t fsth0
= fdt0
>> 32;
2745 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
2746 uint32_t fsth1
= fdt1
>> 32;
2750 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2751 fst2
= float32_mul (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
2752 fsth2
= float32_mul (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
2754 return ((uint64_t)fsth2
<< 32) | fst2
;
2757 /* compare operations */
2758 #define FOP_COND_D(op, cond) \
2759 void do_cmp_d_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2764 SET_FP_COND(cc, env->active_fpu); \
2766 CLEAR_FP_COND(cc, env->active_fpu); \
2768 void do_cmpabs_d_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2771 fdt0 = float64_abs(fdt0); \
2772 fdt1 = float64_abs(fdt1); \
2776 SET_FP_COND(cc, env->active_fpu); \
2778 CLEAR_FP_COND(cc, env->active_fpu); \
2781 static int float64_is_unordered(int sig
, float64 a
, float64 b STATUS_PARAM
)
2783 if (float64_is_signaling_nan(a
) ||
2784 float64_is_signaling_nan(b
) ||
2785 (sig
&& (float64_is_nan(a
) || float64_is_nan(b
)))) {
2786 float_raise(float_flag_invalid
, status
);
2788 } else if (float64_is_nan(a
) || float64_is_nan(b
)) {
2795 /* NOTE: the comma operator will make "cond" to eval to false,
2796 * but float*_is_unordered() is still called. */
2797 FOP_COND_D(f
, (float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
2798 FOP_COND_D(un
, float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
2799 FOP_COND_D(eq
, !float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2800 FOP_COND_D(ueq
, float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2801 FOP_COND_D(olt
, !float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2802 FOP_COND_D(ult
, float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2803 FOP_COND_D(ole
, !float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2804 FOP_COND_D(ule
, float64_is_unordered(0, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2805 /* NOTE: the comma operator will make "cond" to eval to false,
2806 * but float*_is_unordered() is still called. */
2807 FOP_COND_D(sf
, (float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
2808 FOP_COND_D(ngle
,float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
2809 FOP_COND_D(seq
, !float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2810 FOP_COND_D(ngl
, float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2811 FOP_COND_D(lt
, !float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2812 FOP_COND_D(nge
, float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2813 FOP_COND_D(le
, !float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) && float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2814 FOP_COND_D(ngt
, float64_is_unordered(1, fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
2816 #define FOP_COND_S(op, cond) \
2817 void do_cmp_s_ ## op (uint32_t fst0, uint32_t fst1, int cc) \
2822 SET_FP_COND(cc, env->active_fpu); \
2824 CLEAR_FP_COND(cc, env->active_fpu); \
2826 void do_cmpabs_s_ ## op (uint32_t fst0, uint32_t fst1, int cc) \
2829 fst0 = float32_abs(fst0); \
2830 fst1 = float32_abs(fst1); \
2834 SET_FP_COND(cc, env->active_fpu); \
2836 CLEAR_FP_COND(cc, env->active_fpu); \
2839 static flag
float32_is_unordered(int sig
, float32 a
, float32 b STATUS_PARAM
)
2841 if (float32_is_signaling_nan(a
) ||
2842 float32_is_signaling_nan(b
) ||
2843 (sig
&& (float32_is_nan(a
) || float32_is_nan(b
)))) {
2844 float_raise(float_flag_invalid
, status
);
2846 } else if (float32_is_nan(a
) || float32_is_nan(b
)) {
2853 /* NOTE: the comma operator will make "cond" to eval to false,
2854 * but float*_is_unordered() is still called. */
2855 FOP_COND_S(f
, (float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
2856 FOP_COND_S(un
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
))
2857 FOP_COND_S(eq
, !float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2858 FOP_COND_S(ueq
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2859 FOP_COND_S(olt
, !float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2860 FOP_COND_S(ult
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2861 FOP_COND_S(ole
, !float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2862 FOP_COND_S(ule
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2863 /* NOTE: the comma operator will make "cond" to eval to false,
2864 * but float*_is_unordered() is still called. */
2865 FOP_COND_S(sf
, (float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
2866 FOP_COND_S(ngle
,float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
))
2867 FOP_COND_S(seq
, !float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2868 FOP_COND_S(ngl
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2869 FOP_COND_S(lt
, !float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2870 FOP_COND_S(nge
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2871 FOP_COND_S(le
, !float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) && float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2872 FOP_COND_S(ngt
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
2874 #define FOP_COND_PS(op, condl, condh) \
2875 void do_cmp_ps_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2877 uint32_t fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
2878 uint32_t fsth0 = float32_abs(fdt0 >> 32); \
2879 uint32_t fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
2880 uint32_t fsth1 = float32_abs(fdt1 >> 32); \
2886 SET_FP_COND(cc, env->active_fpu); \
2888 CLEAR_FP_COND(cc, env->active_fpu); \
2890 SET_FP_COND(cc + 1, env->active_fpu); \
2892 CLEAR_FP_COND(cc + 1, env->active_fpu); \
2894 void do_cmpabs_ps_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2896 uint32_t fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
2897 uint32_t fsth0 = float32_abs(fdt0 >> 32); \
2898 uint32_t fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
2899 uint32_t fsth1 = float32_abs(fdt1 >> 32); \
2905 SET_FP_COND(cc, env->active_fpu); \
2907 CLEAR_FP_COND(cc, env->active_fpu); \
2909 SET_FP_COND(cc + 1, env->active_fpu); \
2911 CLEAR_FP_COND(cc + 1, env->active_fpu); \
2914 /* NOTE: the comma operator will make "cond" to eval to false,
2915 * but float*_is_unordered() is still called. */
2916 FOP_COND_PS(f
, (float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
2917 (float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
2918 FOP_COND_PS(un
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
),
2919 float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
2920 FOP_COND_PS(eq
, !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(ueq
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2923 float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2924 FOP_COND_PS(olt
, !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(ult
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2927 float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2928 FOP_COND_PS(ole
, !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 FOP_COND_PS(ule
, float32_is_unordered(0, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2931 float32_is_unordered(0, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2932 /* NOTE: the comma operator will make "cond" to eval to false,
2933 * but float*_is_unordered() is still called. */
2934 FOP_COND_PS(sf
, (float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
2935 (float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
2936 FOP_COND_PS(ngle
,float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
),
2937 float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
2938 FOP_COND_PS(seq
, !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(ngl
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2941 float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2942 FOP_COND_PS(lt
, !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(nge
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2945 float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
2946 FOP_COND_PS(le
, !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
))
2948 FOP_COND_PS(ngt
, float32_is_unordered(1, fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
2949 float32_is_unordered(1, fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))