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, see <http://www.gnu.org/licenses/>.
21 #include "host-utils.h"
25 #if !defined(CONFIG_USER_ONLY)
26 #include "softmmu_exec.h"
27 #endif /* !defined(CONFIG_USER_ONLY) */
29 #ifndef CONFIG_USER_ONLY
30 static inline void cpu_mips_tlb_flush (CPUMIPSState
*env
, int flush_global
);
33 /*****************************************************************************/
34 /* Exceptions processing helpers */
36 static inline void QEMU_NORETURN
do_raise_exception_err(CPUMIPSState
*env
,
43 if (exception
< 0x100)
44 qemu_log("%s: %d %d\n", __func__
, exception
, error_code
);
46 env
->exception_index
= exception
;
47 env
->error_code
= error_code
;
50 /* now we have a real cpu fault */
53 /* the PC is inside the translated code. It means that we have
54 a virtual CPU fault */
55 cpu_restore_state(tb
, env
, pc
);
62 static inline void QEMU_NORETURN
do_raise_exception(CPUMIPSState
*env
,
66 do_raise_exception_err(env
, exception
, 0, pc
);
69 void helper_raise_exception_err(CPUMIPSState
*env
, uint32_t exception
,
72 do_raise_exception_err(env
, exception
, error_code
, 0);
75 void helper_raise_exception(CPUMIPSState
*env
, uint32_t exception
)
77 do_raise_exception(env
, exception
, 0);
80 #if defined(CONFIG_USER_ONLY)
81 #define HELPER_LD(name, insn, type) \
82 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
85 return (type) insn##_raw(addr); \
88 #define HELPER_LD(name, insn, type) \
89 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
94 case 0: return (type) cpu_##insn##_kernel(env, addr); break; \
95 case 1: return (type) cpu_##insn##_super(env, addr); break; \
97 case 2: return (type) cpu_##insn##_user(env, addr); break; \
101 HELPER_LD(lbu
, ldub
, uint8_t)
102 HELPER_LD(lw
, ldl
, int32_t)
104 HELPER_LD(ld
, ldq
, int64_t)
108 #if defined(CONFIG_USER_ONLY)
109 #define HELPER_ST(name, insn, type) \
110 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
111 type val, int mem_idx) \
113 insn##_raw(addr, val); \
116 #define HELPER_ST(name, insn, type) \
117 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
118 type val, int mem_idx) \
122 case 0: cpu_##insn##_kernel(env, addr, val); break; \
123 case 1: cpu_##insn##_super(env, addr, val); break; \
125 case 2: cpu_##insn##_user(env, addr, val); break; \
129 HELPER_ST(sb
, stb
, uint8_t)
130 HELPER_ST(sw
, stl
, uint32_t)
132 HELPER_ST(sd
, stq
, uint64_t)
136 target_ulong
helper_clo (target_ulong arg1
)
141 target_ulong
helper_clz (target_ulong arg1
)
146 #if defined(TARGET_MIPS64)
147 target_ulong
helper_dclo (target_ulong arg1
)
152 target_ulong
helper_dclz (target_ulong arg1
)
156 #endif /* TARGET_MIPS64 */
158 /* 64 bits arithmetic for 32 bits hosts */
159 static inline uint64_t get_HILO(CPUMIPSState
*env
)
161 return ((uint64_t)(env
->active_tc
.HI
[0]) << 32) | (uint32_t)env
->active_tc
.LO
[0];
164 static inline target_ulong
set_HIT0_LO(CPUMIPSState
*env
, uint64_t HILO
)
167 env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
168 tmp
= env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
172 static inline target_ulong
set_HI_LOT0(CPUMIPSState
*env
, uint64_t HILO
)
174 target_ulong tmp
= env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
175 env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
179 /* Multiplication variants of the vr54xx. */
180 target_ulong
helper_muls(CPUMIPSState
*env
, target_ulong arg1
,
183 return set_HI_LOT0(env
, 0 - ((int64_t)(int32_t)arg1
*
184 (int64_t)(int32_t)arg2
));
187 target_ulong
helper_mulsu(CPUMIPSState
*env
, target_ulong arg1
,
190 return set_HI_LOT0(env
, 0 - (uint64_t)(uint32_t)arg1
*
191 (uint64_t)(uint32_t)arg2
);
194 target_ulong
helper_macc(CPUMIPSState
*env
, target_ulong arg1
,
197 return set_HI_LOT0(env
, (int64_t)get_HILO(env
) + (int64_t)(int32_t)arg1
*
198 (int64_t)(int32_t)arg2
);
201 target_ulong
helper_macchi(CPUMIPSState
*env
, target_ulong arg1
,
204 return set_HIT0_LO(env
, (int64_t)get_HILO(env
) + (int64_t)(int32_t)arg1
*
205 (int64_t)(int32_t)arg2
);
208 target_ulong
helper_maccu(CPUMIPSState
*env
, target_ulong arg1
,
211 return set_HI_LOT0(env
, (uint64_t)get_HILO(env
) +
212 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
215 target_ulong
helper_macchiu(CPUMIPSState
*env
, target_ulong arg1
,
218 return set_HIT0_LO(env
, (uint64_t)get_HILO(env
) +
219 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
222 target_ulong
helper_msac(CPUMIPSState
*env
, target_ulong arg1
,
225 return set_HI_LOT0(env
, (int64_t)get_HILO(env
) - (int64_t)(int32_t)arg1
*
226 (int64_t)(int32_t)arg2
);
229 target_ulong
helper_msachi(CPUMIPSState
*env
, target_ulong arg1
,
232 return set_HIT0_LO(env
, (int64_t)get_HILO(env
) - (int64_t)(int32_t)arg1
*
233 (int64_t)(int32_t)arg2
);
236 target_ulong
helper_msacu(CPUMIPSState
*env
, target_ulong arg1
,
239 return set_HI_LOT0(env
, (uint64_t)get_HILO(env
) -
240 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
243 target_ulong
helper_msachiu(CPUMIPSState
*env
, target_ulong arg1
,
246 return set_HIT0_LO(env
, (uint64_t)get_HILO(env
) -
247 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
250 target_ulong
helper_mulhi(CPUMIPSState
*env
, target_ulong arg1
,
253 return set_HIT0_LO(env
, (int64_t)(int32_t)arg1
* (int64_t)(int32_t)arg2
);
256 target_ulong
helper_mulhiu(CPUMIPSState
*env
, target_ulong arg1
,
259 return set_HIT0_LO(env
, (uint64_t)(uint32_t)arg1
*
260 (uint64_t)(uint32_t)arg2
);
263 target_ulong
helper_mulshi(CPUMIPSState
*env
, target_ulong arg1
,
266 return set_HIT0_LO(env
, 0 - (int64_t)(int32_t)arg1
*
267 (int64_t)(int32_t)arg2
);
270 target_ulong
helper_mulshiu(CPUMIPSState
*env
, target_ulong arg1
,
273 return set_HIT0_LO(env
, 0 - (uint64_t)(uint32_t)arg1
*
274 (uint64_t)(uint32_t)arg2
);
278 void helper_dmult(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
)
280 muls64(&(env
->active_tc
.LO
[0]), &(env
->active_tc
.HI
[0]), arg1
, arg2
);
283 void helper_dmultu(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
)
285 mulu64(&(env
->active_tc
.LO
[0]), &(env
->active_tc
.HI
[0]), arg1
, arg2
);
289 #ifndef CONFIG_USER_ONLY
291 static inline hwaddr
do_translate_address(CPUMIPSState
*env
,
292 target_ulong address
,
297 lladdr
= cpu_mips_translate_address(env
, address
, rw
);
299 if (lladdr
== -1LL) {
306 #define HELPER_LD_ATOMIC(name, insn) \
307 target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \
309 env->lladdr = do_translate_address(env, arg, 0); \
310 env->llval = do_##insn(env, arg, mem_idx); \
313 HELPER_LD_ATOMIC(ll
, lw
)
315 HELPER_LD_ATOMIC(lld
, ld
)
317 #undef HELPER_LD_ATOMIC
319 #define HELPER_ST_ATOMIC(name, ld_insn, st_insn, almask) \
320 target_ulong helper_##name(CPUMIPSState *env, target_ulong arg1, \
321 target_ulong arg2, int mem_idx) \
325 if (arg2 & almask) { \
326 env->CP0_BadVAddr = arg2; \
327 helper_raise_exception(env, EXCP_AdES); \
329 if (do_translate_address(env, arg2, 1) == env->lladdr) { \
330 tmp = do_##ld_insn(env, arg2, mem_idx); \
331 if (tmp == env->llval) { \
332 do_##st_insn(env, arg2, arg1, mem_idx); \
338 HELPER_ST_ATOMIC(sc
, lw
, sw
, 0x3)
340 HELPER_ST_ATOMIC(scd
, ld
, sd
, 0x7)
342 #undef HELPER_ST_ATOMIC
345 #ifdef TARGET_WORDS_BIGENDIAN
346 #define GET_LMASK(v) ((v) & 3)
347 #define GET_OFFSET(addr, offset) (addr + (offset))
349 #define GET_LMASK(v) (((v) & 3) ^ 3)
350 #define GET_OFFSET(addr, offset) (addr - (offset))
353 target_ulong
helper_lwl(CPUMIPSState
*env
, target_ulong arg1
,
354 target_ulong arg2
, int mem_idx
)
358 tmp
= do_lbu(env
, arg2
, mem_idx
);
359 arg1
= (arg1
& 0x00FFFFFF) | (tmp
<< 24);
361 if (GET_LMASK(arg2
) <= 2) {
362 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 1), mem_idx
);
363 arg1
= (arg1
& 0xFF00FFFF) | (tmp
<< 16);
366 if (GET_LMASK(arg2
) <= 1) {
367 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 2), mem_idx
);
368 arg1
= (arg1
& 0xFFFF00FF) | (tmp
<< 8);
371 if (GET_LMASK(arg2
) == 0) {
372 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 3), mem_idx
);
373 arg1
= (arg1
& 0xFFFFFF00) | tmp
;
375 return (int32_t)arg1
;
378 target_ulong
helper_lwr(CPUMIPSState
*env
, target_ulong arg1
,
379 target_ulong arg2
, int mem_idx
)
383 tmp
= do_lbu(env
, arg2
, mem_idx
);
384 arg1
= (arg1
& 0xFFFFFF00) | tmp
;
386 if (GET_LMASK(arg2
) >= 1) {
387 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -1), mem_idx
);
388 arg1
= (arg1
& 0xFFFF00FF) | (tmp
<< 8);
391 if (GET_LMASK(arg2
) >= 2) {
392 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -2), mem_idx
);
393 arg1
= (arg1
& 0xFF00FFFF) | (tmp
<< 16);
396 if (GET_LMASK(arg2
) == 3) {
397 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -3), mem_idx
);
398 arg1
= (arg1
& 0x00FFFFFF) | (tmp
<< 24);
400 return (int32_t)arg1
;
403 void helper_swl(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
406 do_sb(env
, arg2
, (uint8_t)(arg1
>> 24), mem_idx
);
408 if (GET_LMASK(arg2
) <= 2)
409 do_sb(env
, GET_OFFSET(arg2
, 1), (uint8_t)(arg1
>> 16), mem_idx
);
411 if (GET_LMASK(arg2
) <= 1)
412 do_sb(env
, GET_OFFSET(arg2
, 2), (uint8_t)(arg1
>> 8), mem_idx
);
414 if (GET_LMASK(arg2
) == 0)
415 do_sb(env
, GET_OFFSET(arg2
, 3), (uint8_t)arg1
, mem_idx
);
418 void helper_swr(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
421 do_sb(env
, arg2
, (uint8_t)arg1
, mem_idx
);
423 if (GET_LMASK(arg2
) >= 1)
424 do_sb(env
, GET_OFFSET(arg2
, -1), (uint8_t)(arg1
>> 8), mem_idx
);
426 if (GET_LMASK(arg2
) >= 2)
427 do_sb(env
, GET_OFFSET(arg2
, -2), (uint8_t)(arg1
>> 16), mem_idx
);
429 if (GET_LMASK(arg2
) == 3)
430 do_sb(env
, GET_OFFSET(arg2
, -3), (uint8_t)(arg1
>> 24), mem_idx
);
433 #if defined(TARGET_MIPS64)
434 /* "half" load and stores. We must do the memory access inline,
435 or fault handling won't work. */
437 #ifdef TARGET_WORDS_BIGENDIAN
438 #define GET_LMASK64(v) ((v) & 7)
440 #define GET_LMASK64(v) (((v) & 7) ^ 7)
443 target_ulong
helper_ldl(CPUMIPSState
*env
, target_ulong arg1
,
444 target_ulong arg2
, int mem_idx
)
448 tmp
= do_lbu(env
, arg2
, mem_idx
);
449 arg1
= (arg1
& 0x00FFFFFFFFFFFFFFULL
) | (tmp
<< 56);
451 if (GET_LMASK64(arg2
) <= 6) {
452 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 1), mem_idx
);
453 arg1
= (arg1
& 0xFF00FFFFFFFFFFFFULL
) | (tmp
<< 48);
456 if (GET_LMASK64(arg2
) <= 5) {
457 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 2), mem_idx
);
458 arg1
= (arg1
& 0xFFFF00FFFFFFFFFFULL
) | (tmp
<< 40);
461 if (GET_LMASK64(arg2
) <= 4) {
462 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 3), mem_idx
);
463 arg1
= (arg1
& 0xFFFFFF00FFFFFFFFULL
) | (tmp
<< 32);
466 if (GET_LMASK64(arg2
) <= 3) {
467 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 4), mem_idx
);
468 arg1
= (arg1
& 0xFFFFFFFF00FFFFFFULL
) | (tmp
<< 24);
471 if (GET_LMASK64(arg2
) <= 2) {
472 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 5), mem_idx
);
473 arg1
= (arg1
& 0xFFFFFFFFFF00FFFFULL
) | (tmp
<< 16);
476 if (GET_LMASK64(arg2
) <= 1) {
477 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 6), mem_idx
);
478 arg1
= (arg1
& 0xFFFFFFFFFFFF00FFULL
) | (tmp
<< 8);
481 if (GET_LMASK64(arg2
) == 0) {
482 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 7), mem_idx
);
483 arg1
= (arg1
& 0xFFFFFFFFFFFFFF00ULL
) | tmp
;
489 target_ulong
helper_ldr(CPUMIPSState
*env
, target_ulong arg1
,
490 target_ulong arg2
, int mem_idx
)
494 tmp
= do_lbu(env
, arg2
, mem_idx
);
495 arg1
= (arg1
& 0xFFFFFFFFFFFFFF00ULL
) | tmp
;
497 if (GET_LMASK64(arg2
) >= 1) {
498 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -1), mem_idx
);
499 arg1
= (arg1
& 0xFFFFFFFFFFFF00FFULL
) | (tmp
<< 8);
502 if (GET_LMASK64(arg2
) >= 2) {
503 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -2), mem_idx
);
504 arg1
= (arg1
& 0xFFFFFFFFFF00FFFFULL
) | (tmp
<< 16);
507 if (GET_LMASK64(arg2
) >= 3) {
508 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -3), mem_idx
);
509 arg1
= (arg1
& 0xFFFFFFFF00FFFFFFULL
) | (tmp
<< 24);
512 if (GET_LMASK64(arg2
) >= 4) {
513 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -4), mem_idx
);
514 arg1
= (arg1
& 0xFFFFFF00FFFFFFFFULL
) | (tmp
<< 32);
517 if (GET_LMASK64(arg2
) >= 5) {
518 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -5), mem_idx
);
519 arg1
= (arg1
& 0xFFFF00FFFFFFFFFFULL
) | (tmp
<< 40);
522 if (GET_LMASK64(arg2
) >= 6) {
523 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -6), mem_idx
);
524 arg1
= (arg1
& 0xFF00FFFFFFFFFFFFULL
) | (tmp
<< 48);
527 if (GET_LMASK64(arg2
) == 7) {
528 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -7), mem_idx
);
529 arg1
= (arg1
& 0x00FFFFFFFFFFFFFFULL
) | (tmp
<< 56);
535 void helper_sdl(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
538 do_sb(env
, arg2
, (uint8_t)(arg1
>> 56), mem_idx
);
540 if (GET_LMASK64(arg2
) <= 6)
541 do_sb(env
, GET_OFFSET(arg2
, 1), (uint8_t)(arg1
>> 48), mem_idx
);
543 if (GET_LMASK64(arg2
) <= 5)
544 do_sb(env
, GET_OFFSET(arg2
, 2), (uint8_t)(arg1
>> 40), mem_idx
);
546 if (GET_LMASK64(arg2
) <= 4)
547 do_sb(env
, GET_OFFSET(arg2
, 3), (uint8_t)(arg1
>> 32), mem_idx
);
549 if (GET_LMASK64(arg2
) <= 3)
550 do_sb(env
, GET_OFFSET(arg2
, 4), (uint8_t)(arg1
>> 24), mem_idx
);
552 if (GET_LMASK64(arg2
) <= 2)
553 do_sb(env
, GET_OFFSET(arg2
, 5), (uint8_t)(arg1
>> 16), mem_idx
);
555 if (GET_LMASK64(arg2
) <= 1)
556 do_sb(env
, GET_OFFSET(arg2
, 6), (uint8_t)(arg1
>> 8), mem_idx
);
558 if (GET_LMASK64(arg2
) <= 0)
559 do_sb(env
, GET_OFFSET(arg2
, 7), (uint8_t)arg1
, mem_idx
);
562 void helper_sdr(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
565 do_sb(env
, arg2
, (uint8_t)arg1
, mem_idx
);
567 if (GET_LMASK64(arg2
) >= 1)
568 do_sb(env
, GET_OFFSET(arg2
, -1), (uint8_t)(arg1
>> 8), mem_idx
);
570 if (GET_LMASK64(arg2
) >= 2)
571 do_sb(env
, GET_OFFSET(arg2
, -2), (uint8_t)(arg1
>> 16), mem_idx
);
573 if (GET_LMASK64(arg2
) >= 3)
574 do_sb(env
, GET_OFFSET(arg2
, -3), (uint8_t)(arg1
>> 24), mem_idx
);
576 if (GET_LMASK64(arg2
) >= 4)
577 do_sb(env
, GET_OFFSET(arg2
, -4), (uint8_t)(arg1
>> 32), mem_idx
);
579 if (GET_LMASK64(arg2
) >= 5)
580 do_sb(env
, GET_OFFSET(arg2
, -5), (uint8_t)(arg1
>> 40), mem_idx
);
582 if (GET_LMASK64(arg2
) >= 6)
583 do_sb(env
, GET_OFFSET(arg2
, -6), (uint8_t)(arg1
>> 48), mem_idx
);
585 if (GET_LMASK64(arg2
) == 7)
586 do_sb(env
, GET_OFFSET(arg2
, -7), (uint8_t)(arg1
>> 56), mem_idx
);
588 #endif /* TARGET_MIPS64 */
590 static const int multiple_regs
[] = { 16, 17, 18, 19, 20, 21, 22, 23, 30 };
592 void helper_lwm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
595 target_ulong base_reglist
= reglist
& 0xf;
596 target_ulong do_r31
= reglist
& 0x10;
598 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
601 for (i
= 0; i
< base_reglist
; i
++) {
602 env
->active_tc
.gpr
[multiple_regs
[i
]] =
603 (target_long
)do_lw(env
, addr
, mem_idx
);
609 env
->active_tc
.gpr
[31] = (target_long
)do_lw(env
, addr
, mem_idx
);
613 void helper_swm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
616 target_ulong base_reglist
= reglist
& 0xf;
617 target_ulong do_r31
= reglist
& 0x10;
619 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
622 for (i
= 0; i
< base_reglist
; i
++) {
623 do_sw(env
, addr
, env
->active_tc
.gpr
[multiple_regs
[i
]], mem_idx
);
629 do_sw(env
, addr
, env
->active_tc
.gpr
[31], mem_idx
);
633 #if defined(TARGET_MIPS64)
634 void helper_ldm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
637 target_ulong base_reglist
= reglist
& 0xf;
638 target_ulong do_r31
= reglist
& 0x10;
640 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
643 for (i
= 0; i
< base_reglist
; i
++) {
644 env
->active_tc
.gpr
[multiple_regs
[i
]] = do_ld(env
, addr
, mem_idx
);
650 env
->active_tc
.gpr
[31] = do_ld(env
, addr
, mem_idx
);
654 void helper_sdm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
657 target_ulong base_reglist
= reglist
& 0xf;
658 target_ulong do_r31
= reglist
& 0x10;
660 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
663 for (i
= 0; i
< base_reglist
; i
++) {
664 do_sd(env
, addr
, env
->active_tc
.gpr
[multiple_regs
[i
]], mem_idx
);
670 do_sd(env
, addr
, env
->active_tc
.gpr
[31], mem_idx
);
675 #ifndef CONFIG_USER_ONLY
677 static bool mips_vpe_is_wfi(MIPSCPU
*c
)
679 CPUMIPSState
*env
= &c
->env
;
681 /* If the VPE is halted but otherwise active, it means it's waiting for
683 return env
->halted
&& mips_vpe_active(env
);
686 static inline void mips_vpe_wake(CPUMIPSState
*c
)
688 /* Dont set ->halted = 0 directly, let it be done via cpu_has_work
689 because there might be other conditions that state that c should
691 cpu_interrupt(c
, CPU_INTERRUPT_WAKE
);
694 static inline void mips_vpe_sleep(MIPSCPU
*cpu
)
696 CPUMIPSState
*c
= &cpu
->env
;
698 /* The VPE was shut off, really go to bed.
699 Reset any old _WAKE requests. */
701 cpu_reset_interrupt(c
, CPU_INTERRUPT_WAKE
);
704 static inline void mips_tc_wake(MIPSCPU
*cpu
, int tc
)
706 CPUMIPSState
*c
= &cpu
->env
;
708 /* FIXME: TC reschedule. */
709 if (mips_vpe_active(c
) && !mips_vpe_is_wfi(cpu
)) {
714 static inline void mips_tc_sleep(MIPSCPU
*cpu
, int tc
)
716 CPUMIPSState
*c
= &cpu
->env
;
718 /* FIXME: TC reschedule. */
719 if (!mips_vpe_active(c
)) {
724 /* tc should point to an int with the value of the global TC index.
725 This function will transform it into a local index within the
726 returned CPUMIPSState.
728 FIXME: This code assumes that all VPEs have the same number of TCs,
729 which depends on runtime setup. Can probably be fixed by
730 walking the list of CPUMIPSStates. */
731 static CPUMIPSState
*mips_cpu_map_tc(CPUMIPSState
*env
, int *tc
)
734 int vpe_idx
, nr_threads
= env
->nr_threads
;
737 if (!(env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))) {
738 /* Not allowed to address other CPUs. */
739 *tc
= env
->current_tc
;
743 vpe_idx
= tc_idx
/ nr_threads
;
744 *tc
= tc_idx
% nr_threads
;
745 other
= qemu_get_cpu(vpe_idx
);
746 return other
? other
: env
;
749 /* The per VPE CP0_Status register shares some fields with the per TC
750 CP0_TCStatus registers. These fields are wired to the same registers,
751 so changes to either of them should be reflected on both registers.
753 Also, EntryHi shares the bottom 8 bit ASID with TCStauts.
755 These helper call synchronizes the regs for a given cpu. */
757 /* Called for updates to CP0_Status. */
758 static void sync_c0_status(CPUMIPSState
*env
, CPUMIPSState
*cpu
, int tc
)
760 int32_t tcstatus
, *tcst
;
761 uint32_t v
= cpu
->CP0_Status
;
762 uint32_t cu
, mx
, asid
, ksu
;
763 uint32_t mask
= ((1 << CP0TCSt_TCU3
)
764 | (1 << CP0TCSt_TCU2
)
765 | (1 << CP0TCSt_TCU1
)
766 | (1 << CP0TCSt_TCU0
)
768 | (3 << CP0TCSt_TKSU
)
769 | (0xff << CP0TCSt_TASID
));
771 cu
= (v
>> CP0St_CU0
) & 0xf;
772 mx
= (v
>> CP0St_MX
) & 0x1;
773 ksu
= (v
>> CP0St_KSU
) & 0x3;
774 asid
= env
->CP0_EntryHi
& 0xff;
776 tcstatus
= cu
<< CP0TCSt_TCU0
;
777 tcstatus
|= mx
<< CP0TCSt_TMX
;
778 tcstatus
|= ksu
<< CP0TCSt_TKSU
;
781 if (tc
== cpu
->current_tc
) {
782 tcst
= &cpu
->active_tc
.CP0_TCStatus
;
784 tcst
= &cpu
->tcs
[tc
].CP0_TCStatus
;
792 /* Called for updates to CP0_TCStatus. */
793 static void sync_c0_tcstatus(CPUMIPSState
*cpu
, int tc
,
797 uint32_t tcu
, tmx
, tasid
, tksu
;
798 uint32_t mask
= ((1 << CP0St_CU3
)
805 tcu
= (v
>> CP0TCSt_TCU0
) & 0xf;
806 tmx
= (v
>> CP0TCSt_TMX
) & 0x1;
808 tksu
= (v
>> CP0TCSt_TKSU
) & 0x3;
810 status
= tcu
<< CP0St_CU0
;
811 status
|= tmx
<< CP0St_MX
;
812 status
|= tksu
<< CP0St_KSU
;
814 cpu
->CP0_Status
&= ~mask
;
815 cpu
->CP0_Status
|= status
;
817 /* Sync the TASID with EntryHi. */
818 cpu
->CP0_EntryHi
&= ~0xff;
819 cpu
->CP0_EntryHi
= tasid
;
824 /* Called for updates to CP0_EntryHi. */
825 static void sync_c0_entryhi(CPUMIPSState
*cpu
, int tc
)
828 uint32_t asid
, v
= cpu
->CP0_EntryHi
;
832 if (tc
== cpu
->current_tc
) {
833 tcst
= &cpu
->active_tc
.CP0_TCStatus
;
835 tcst
= &cpu
->tcs
[tc
].CP0_TCStatus
;
843 target_ulong
helper_mfc0_mvpcontrol(CPUMIPSState
*env
)
845 return env
->mvp
->CP0_MVPControl
;
848 target_ulong
helper_mfc0_mvpconf0(CPUMIPSState
*env
)
850 return env
->mvp
->CP0_MVPConf0
;
853 target_ulong
helper_mfc0_mvpconf1(CPUMIPSState
*env
)
855 return env
->mvp
->CP0_MVPConf1
;
858 target_ulong
helper_mfc0_random(CPUMIPSState
*env
)
860 return (int32_t)cpu_mips_get_random(env
);
863 target_ulong
helper_mfc0_tcstatus(CPUMIPSState
*env
)
865 return env
->active_tc
.CP0_TCStatus
;
868 target_ulong
helper_mftc0_tcstatus(CPUMIPSState
*env
)
870 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
871 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
873 if (other_tc
== other
->current_tc
)
874 return other
->active_tc
.CP0_TCStatus
;
876 return other
->tcs
[other_tc
].CP0_TCStatus
;
879 target_ulong
helper_mfc0_tcbind(CPUMIPSState
*env
)
881 return env
->active_tc
.CP0_TCBind
;
884 target_ulong
helper_mftc0_tcbind(CPUMIPSState
*env
)
886 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
887 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
889 if (other_tc
== other
->current_tc
)
890 return other
->active_tc
.CP0_TCBind
;
892 return other
->tcs
[other_tc
].CP0_TCBind
;
895 target_ulong
helper_mfc0_tcrestart(CPUMIPSState
*env
)
897 return env
->active_tc
.PC
;
900 target_ulong
helper_mftc0_tcrestart(CPUMIPSState
*env
)
902 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
903 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
905 if (other_tc
== other
->current_tc
)
906 return other
->active_tc
.PC
;
908 return other
->tcs
[other_tc
].PC
;
911 target_ulong
helper_mfc0_tchalt(CPUMIPSState
*env
)
913 return env
->active_tc
.CP0_TCHalt
;
916 target_ulong
helper_mftc0_tchalt(CPUMIPSState
*env
)
918 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
919 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
921 if (other_tc
== other
->current_tc
)
922 return other
->active_tc
.CP0_TCHalt
;
924 return other
->tcs
[other_tc
].CP0_TCHalt
;
927 target_ulong
helper_mfc0_tccontext(CPUMIPSState
*env
)
929 return env
->active_tc
.CP0_TCContext
;
932 target_ulong
helper_mftc0_tccontext(CPUMIPSState
*env
)
934 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
935 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
937 if (other_tc
== other
->current_tc
)
938 return other
->active_tc
.CP0_TCContext
;
940 return other
->tcs
[other_tc
].CP0_TCContext
;
943 target_ulong
helper_mfc0_tcschedule(CPUMIPSState
*env
)
945 return env
->active_tc
.CP0_TCSchedule
;
948 target_ulong
helper_mftc0_tcschedule(CPUMIPSState
*env
)
950 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
951 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
953 if (other_tc
== other
->current_tc
)
954 return other
->active_tc
.CP0_TCSchedule
;
956 return other
->tcs
[other_tc
].CP0_TCSchedule
;
959 target_ulong
helper_mfc0_tcschefback(CPUMIPSState
*env
)
961 return env
->active_tc
.CP0_TCScheFBack
;
964 target_ulong
helper_mftc0_tcschefback(CPUMIPSState
*env
)
966 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
967 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
969 if (other_tc
== other
->current_tc
)
970 return other
->active_tc
.CP0_TCScheFBack
;
972 return other
->tcs
[other_tc
].CP0_TCScheFBack
;
975 target_ulong
helper_mfc0_count(CPUMIPSState
*env
)
977 return (int32_t)cpu_mips_get_count(env
);
980 target_ulong
helper_mftc0_entryhi(CPUMIPSState
*env
)
982 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
983 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
985 return other
->CP0_EntryHi
;
988 target_ulong
helper_mftc0_cause(CPUMIPSState
*env
)
990 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
992 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
994 if (other_tc
== other
->current_tc
) {
995 tccause
= other
->CP0_Cause
;
997 tccause
= other
->CP0_Cause
;
1003 target_ulong
helper_mftc0_status(CPUMIPSState
*env
)
1005 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1006 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1008 return other
->CP0_Status
;
1011 target_ulong
helper_mfc0_lladdr(CPUMIPSState
*env
)
1013 return (int32_t)(env
->lladdr
>> env
->CP0_LLAddr_shift
);
1016 target_ulong
helper_mfc0_watchlo(CPUMIPSState
*env
, uint32_t sel
)
1018 return (int32_t)env
->CP0_WatchLo
[sel
];
1021 target_ulong
helper_mfc0_watchhi(CPUMIPSState
*env
, uint32_t sel
)
1023 return env
->CP0_WatchHi
[sel
];
1026 target_ulong
helper_mfc0_debug(CPUMIPSState
*env
)
1028 target_ulong t0
= env
->CP0_Debug
;
1029 if (env
->hflags
& MIPS_HFLAG_DM
)
1030 t0
|= 1 << CP0DB_DM
;
1035 target_ulong
helper_mftc0_debug(CPUMIPSState
*env
)
1037 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1039 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1041 if (other_tc
== other
->current_tc
)
1042 tcstatus
= other
->active_tc
.CP0_Debug_tcstatus
;
1044 tcstatus
= other
->tcs
[other_tc
].CP0_Debug_tcstatus
;
1046 /* XXX: Might be wrong, check with EJTAG spec. */
1047 return (other
->CP0_Debug
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
1048 (tcstatus
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
1051 #if defined(TARGET_MIPS64)
1052 target_ulong
helper_dmfc0_tcrestart(CPUMIPSState
*env
)
1054 return env
->active_tc
.PC
;
1057 target_ulong
helper_dmfc0_tchalt(CPUMIPSState
*env
)
1059 return env
->active_tc
.CP0_TCHalt
;
1062 target_ulong
helper_dmfc0_tccontext(CPUMIPSState
*env
)
1064 return env
->active_tc
.CP0_TCContext
;
1067 target_ulong
helper_dmfc0_tcschedule(CPUMIPSState
*env
)
1069 return env
->active_tc
.CP0_TCSchedule
;
1072 target_ulong
helper_dmfc0_tcschefback(CPUMIPSState
*env
)
1074 return env
->active_tc
.CP0_TCScheFBack
;
1077 target_ulong
helper_dmfc0_lladdr(CPUMIPSState
*env
)
1079 return env
->lladdr
>> env
->CP0_LLAddr_shift
;
1082 target_ulong
helper_dmfc0_watchlo(CPUMIPSState
*env
, uint32_t sel
)
1084 return env
->CP0_WatchLo
[sel
];
1086 #endif /* TARGET_MIPS64 */
1088 void helper_mtc0_index(CPUMIPSState
*env
, target_ulong arg1
)
1091 unsigned int tmp
= env
->tlb
->nb_tlb
;
1097 env
->CP0_Index
= (env
->CP0_Index
& 0x80000000) | (arg1
& (num
- 1));
1100 void helper_mtc0_mvpcontrol(CPUMIPSState
*env
, target_ulong arg1
)
1105 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))
1106 mask
|= (1 << CP0MVPCo_CPA
) | (1 << CP0MVPCo_VPC
) |
1107 (1 << CP0MVPCo_EVP
);
1108 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1109 mask
|= (1 << CP0MVPCo_STLB
);
1110 newval
= (env
->mvp
->CP0_MVPControl
& ~mask
) | (arg1
& mask
);
1112 // TODO: Enable/disable shared TLB, enable/disable VPEs.
1114 env
->mvp
->CP0_MVPControl
= newval
;
1117 void helper_mtc0_vpecontrol(CPUMIPSState
*env
, target_ulong arg1
)
1122 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
1123 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
1124 newval
= (env
->CP0_VPEControl
& ~mask
) | (arg1
& mask
);
1126 /* Yield scheduler intercept not implemented. */
1127 /* Gating storage scheduler intercept not implemented. */
1129 // TODO: Enable/disable TCs.
1131 env
->CP0_VPEControl
= newval
;
1134 void helper_mttc0_vpecontrol(CPUMIPSState
*env
, target_ulong arg1
)
1136 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1137 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1141 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
1142 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
1143 newval
= (other
->CP0_VPEControl
& ~mask
) | (arg1
& mask
);
1145 /* TODO: Enable/disable TCs. */
1147 other
->CP0_VPEControl
= newval
;
1150 target_ulong
helper_mftc0_vpecontrol(CPUMIPSState
*env
)
1152 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1153 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1154 /* FIXME: Mask away return zero on read bits. */
1155 return other
->CP0_VPEControl
;
1158 target_ulong
helper_mftc0_vpeconf0(CPUMIPSState
*env
)
1160 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1161 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1163 return other
->CP0_VPEConf0
;
1166 void helper_mtc0_vpeconf0(CPUMIPSState
*env
, target_ulong arg1
)
1171 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) {
1172 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_VPA
))
1173 mask
|= (0xff << CP0VPEC0_XTC
);
1174 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
1176 newval
= (env
->CP0_VPEConf0
& ~mask
) | (arg1
& mask
);
1178 // TODO: TC exclusive handling due to ERL/EXL.
1180 env
->CP0_VPEConf0
= newval
;
1183 void helper_mttc0_vpeconf0(CPUMIPSState
*env
, target_ulong arg1
)
1185 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1186 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1190 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
1191 newval
= (other
->CP0_VPEConf0
& ~mask
) | (arg1
& mask
);
1193 /* TODO: TC exclusive handling due to ERL/EXL. */
1194 other
->CP0_VPEConf0
= newval
;
1197 void helper_mtc0_vpeconf1(CPUMIPSState
*env
, target_ulong arg1
)
1202 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1203 mask
|= (0xff << CP0VPEC1_NCX
) | (0xff << CP0VPEC1_NCP2
) |
1204 (0xff << CP0VPEC1_NCP1
);
1205 newval
= (env
->CP0_VPEConf1
& ~mask
) | (arg1
& mask
);
1207 /* UDI not implemented. */
1208 /* CP2 not implemented. */
1210 // TODO: Handle FPU (CP1) binding.
1212 env
->CP0_VPEConf1
= newval
;
1215 void helper_mtc0_yqmask(CPUMIPSState
*env
, target_ulong arg1
)
1217 /* Yield qualifier inputs not implemented. */
1218 env
->CP0_YQMask
= 0x00000000;
1221 void helper_mtc0_vpeopt(CPUMIPSState
*env
, target_ulong arg1
)
1223 env
->CP0_VPEOpt
= arg1
& 0x0000ffff;
1226 void helper_mtc0_entrylo0(CPUMIPSState
*env
, target_ulong arg1
)
1228 /* Large physaddr (PABITS) not implemented */
1229 /* 1k pages not implemented */
1230 env
->CP0_EntryLo0
= arg1
& 0x3FFFFFFF;
1233 void helper_mtc0_tcstatus(CPUMIPSState
*env
, target_ulong arg1
)
1235 uint32_t mask
= env
->CP0_TCStatus_rw_bitmask
;
1238 newval
= (env
->active_tc
.CP0_TCStatus
& ~mask
) | (arg1
& mask
);
1240 env
->active_tc
.CP0_TCStatus
= newval
;
1241 sync_c0_tcstatus(env
, env
->current_tc
, newval
);
1244 void helper_mttc0_tcstatus(CPUMIPSState
*env
, target_ulong arg1
)
1246 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1247 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1249 if (other_tc
== other
->current_tc
)
1250 other
->active_tc
.CP0_TCStatus
= arg1
;
1252 other
->tcs
[other_tc
].CP0_TCStatus
= arg1
;
1253 sync_c0_tcstatus(other
, other_tc
, arg1
);
1256 void helper_mtc0_tcbind(CPUMIPSState
*env
, target_ulong arg1
)
1258 uint32_t mask
= (1 << CP0TCBd_TBE
);
1261 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1262 mask
|= (1 << CP0TCBd_CurVPE
);
1263 newval
= (env
->active_tc
.CP0_TCBind
& ~mask
) | (arg1
& mask
);
1264 env
->active_tc
.CP0_TCBind
= newval
;
1267 void helper_mttc0_tcbind(CPUMIPSState
*env
, target_ulong arg1
)
1269 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1270 uint32_t mask
= (1 << CP0TCBd_TBE
);
1272 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1274 if (other
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1275 mask
|= (1 << CP0TCBd_CurVPE
);
1276 if (other_tc
== other
->current_tc
) {
1277 newval
= (other
->active_tc
.CP0_TCBind
& ~mask
) | (arg1
& mask
);
1278 other
->active_tc
.CP0_TCBind
= newval
;
1280 newval
= (other
->tcs
[other_tc
].CP0_TCBind
& ~mask
) | (arg1
& mask
);
1281 other
->tcs
[other_tc
].CP0_TCBind
= newval
;
1285 void helper_mtc0_tcrestart(CPUMIPSState
*env
, target_ulong arg1
)
1287 env
->active_tc
.PC
= arg1
;
1288 env
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1290 /* MIPS16 not implemented. */
1293 void helper_mttc0_tcrestart(CPUMIPSState
*env
, target_ulong arg1
)
1295 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1296 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1298 if (other_tc
== other
->current_tc
) {
1299 other
->active_tc
.PC
= arg1
;
1300 other
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1301 other
->lladdr
= 0ULL;
1302 /* MIPS16 not implemented. */
1304 other
->tcs
[other_tc
].PC
= arg1
;
1305 other
->tcs
[other_tc
].CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1306 other
->lladdr
= 0ULL;
1307 /* MIPS16 not implemented. */
1311 void helper_mtc0_tchalt(CPUMIPSState
*env
, target_ulong arg1
)
1313 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
1315 env
->active_tc
.CP0_TCHalt
= arg1
& 0x1;
1317 // TODO: Halt TC / Restart (if allocated+active) TC.
1318 if (env
->active_tc
.CP0_TCHalt
& 1) {
1319 mips_tc_sleep(cpu
, env
->current_tc
);
1321 mips_tc_wake(cpu
, env
->current_tc
);
1325 void helper_mttc0_tchalt(CPUMIPSState
*env
, target_ulong arg1
)
1327 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1328 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1329 MIPSCPU
*other_cpu
= mips_env_get_cpu(other
);
1331 // TODO: Halt TC / Restart (if allocated+active) TC.
1333 if (other_tc
== other
->current_tc
)
1334 other
->active_tc
.CP0_TCHalt
= arg1
;
1336 other
->tcs
[other_tc
].CP0_TCHalt
= arg1
;
1339 mips_tc_sleep(other_cpu
, other_tc
);
1341 mips_tc_wake(other_cpu
, other_tc
);
1345 void helper_mtc0_tccontext(CPUMIPSState
*env
, target_ulong arg1
)
1347 env
->active_tc
.CP0_TCContext
= arg1
;
1350 void helper_mttc0_tccontext(CPUMIPSState
*env
, target_ulong arg1
)
1352 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1353 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1355 if (other_tc
== other
->current_tc
)
1356 other
->active_tc
.CP0_TCContext
= arg1
;
1358 other
->tcs
[other_tc
].CP0_TCContext
= arg1
;
1361 void helper_mtc0_tcschedule(CPUMIPSState
*env
, target_ulong arg1
)
1363 env
->active_tc
.CP0_TCSchedule
= arg1
;
1366 void helper_mttc0_tcschedule(CPUMIPSState
*env
, target_ulong arg1
)
1368 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1369 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1371 if (other_tc
== other
->current_tc
)
1372 other
->active_tc
.CP0_TCSchedule
= arg1
;
1374 other
->tcs
[other_tc
].CP0_TCSchedule
= arg1
;
1377 void helper_mtc0_tcschefback(CPUMIPSState
*env
, target_ulong arg1
)
1379 env
->active_tc
.CP0_TCScheFBack
= arg1
;
1382 void helper_mttc0_tcschefback(CPUMIPSState
*env
, target_ulong arg1
)
1384 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1385 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1387 if (other_tc
== other
->current_tc
)
1388 other
->active_tc
.CP0_TCScheFBack
= arg1
;
1390 other
->tcs
[other_tc
].CP0_TCScheFBack
= arg1
;
1393 void helper_mtc0_entrylo1(CPUMIPSState
*env
, target_ulong arg1
)
1395 /* Large physaddr (PABITS) not implemented */
1396 /* 1k pages not implemented */
1397 env
->CP0_EntryLo1
= arg1
& 0x3FFFFFFF;
1400 void helper_mtc0_context(CPUMIPSState
*env
, target_ulong arg1
)
1402 env
->CP0_Context
= (env
->CP0_Context
& 0x007FFFFF) | (arg1
& ~0x007FFFFF);
1405 void helper_mtc0_pagemask(CPUMIPSState
*env
, target_ulong arg1
)
1407 /* 1k pages not implemented */
1408 env
->CP0_PageMask
= arg1
& (0x1FFFFFFF & (TARGET_PAGE_MASK
<< 1));
1411 void helper_mtc0_pagegrain(CPUMIPSState
*env
, target_ulong arg1
)
1413 /* SmartMIPS not implemented */
1414 /* Large physaddr (PABITS) not implemented */
1415 /* 1k pages not implemented */
1416 env
->CP0_PageGrain
= 0;
1419 void helper_mtc0_wired(CPUMIPSState
*env
, target_ulong arg1
)
1421 env
->CP0_Wired
= arg1
% env
->tlb
->nb_tlb
;
1424 void helper_mtc0_srsconf0(CPUMIPSState
*env
, target_ulong arg1
)
1426 env
->CP0_SRSConf0
|= arg1
& env
->CP0_SRSConf0_rw_bitmask
;
1429 void helper_mtc0_srsconf1(CPUMIPSState
*env
, target_ulong arg1
)
1431 env
->CP0_SRSConf1
|= arg1
& env
->CP0_SRSConf1_rw_bitmask
;
1434 void helper_mtc0_srsconf2(CPUMIPSState
*env
, target_ulong arg1
)
1436 env
->CP0_SRSConf2
|= arg1
& env
->CP0_SRSConf2_rw_bitmask
;
1439 void helper_mtc0_srsconf3(CPUMIPSState
*env
, target_ulong arg1
)
1441 env
->CP0_SRSConf3
|= arg1
& env
->CP0_SRSConf3_rw_bitmask
;
1444 void helper_mtc0_srsconf4(CPUMIPSState
*env
, target_ulong arg1
)
1446 env
->CP0_SRSConf4
|= arg1
& env
->CP0_SRSConf4_rw_bitmask
;
1449 void helper_mtc0_hwrena(CPUMIPSState
*env
, target_ulong arg1
)
1451 env
->CP0_HWREna
= arg1
& 0x0000000F;
1454 void helper_mtc0_count(CPUMIPSState
*env
, target_ulong arg1
)
1456 cpu_mips_store_count(env
, arg1
);
1459 void helper_mtc0_entryhi(CPUMIPSState
*env
, target_ulong arg1
)
1461 target_ulong old
, val
;
1463 /* 1k pages not implemented */
1464 val
= arg1
& ((TARGET_PAGE_MASK
<< 1) | 0xFF);
1465 #if defined(TARGET_MIPS64)
1466 val
&= env
->SEGMask
;
1468 old
= env
->CP0_EntryHi
;
1469 env
->CP0_EntryHi
= val
;
1470 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
1471 sync_c0_entryhi(env
, env
->current_tc
);
1473 /* If the ASID changes, flush qemu's TLB. */
1474 if ((old
& 0xFF) != (val
& 0xFF))
1475 cpu_mips_tlb_flush(env
, 1);
1478 void helper_mttc0_entryhi(CPUMIPSState
*env
, target_ulong arg1
)
1480 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1481 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1483 other
->CP0_EntryHi
= arg1
;
1484 sync_c0_entryhi(other
, other_tc
);
1487 void helper_mtc0_compare(CPUMIPSState
*env
, target_ulong arg1
)
1489 cpu_mips_store_compare(env
, arg1
);
1492 void helper_mtc0_status(CPUMIPSState
*env
, target_ulong arg1
)
1495 uint32_t mask
= env
->CP0_Status_rw_bitmask
;
1498 old
= env
->CP0_Status
;
1499 env
->CP0_Status
= (env
->CP0_Status
& ~mask
) | val
;
1500 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
1501 sync_c0_status(env
, env
, env
->current_tc
);
1503 compute_hflags(env
);
1506 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
1507 qemu_log("Status %08x (%08x) => %08x (%08x) Cause %08x",
1508 old
, old
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1509 val
, val
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1511 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
1512 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
1513 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
1514 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
1515 default: cpu_abort(env
, "Invalid MMU mode!\n"); break;
1520 void helper_mttc0_status(CPUMIPSState
*env
, target_ulong arg1
)
1522 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1523 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1525 other
->CP0_Status
= arg1
& ~0xf1000018;
1526 sync_c0_status(env
, other
, other_tc
);
1529 void helper_mtc0_intctl(CPUMIPSState
*env
, target_ulong arg1
)
1531 /* vectored interrupts not implemented, no performance counters. */
1532 env
->CP0_IntCtl
= (env
->CP0_IntCtl
& ~0x000003e0) | (arg1
& 0x000003e0);
1535 void helper_mtc0_srsctl(CPUMIPSState
*env
, target_ulong arg1
)
1537 uint32_t mask
= (0xf << CP0SRSCtl_ESS
) | (0xf << CP0SRSCtl_PSS
);
1538 env
->CP0_SRSCtl
= (env
->CP0_SRSCtl
& ~mask
) | (arg1
& mask
);
1541 static void mtc0_cause(CPUMIPSState
*cpu
, target_ulong arg1
)
1543 uint32_t mask
= 0x00C00300;
1544 uint32_t old
= cpu
->CP0_Cause
;
1547 if (cpu
->insn_flags
& ISA_MIPS32R2
) {
1548 mask
|= 1 << CP0Ca_DC
;
1551 cpu
->CP0_Cause
= (cpu
->CP0_Cause
& ~mask
) | (arg1
& mask
);
1553 if ((old
^ cpu
->CP0_Cause
) & (1 << CP0Ca_DC
)) {
1554 if (cpu
->CP0_Cause
& (1 << CP0Ca_DC
)) {
1555 cpu_mips_stop_count(cpu
);
1557 cpu_mips_start_count(cpu
);
1561 /* Set/reset software interrupts */
1562 for (i
= 0 ; i
< 2 ; i
++) {
1563 if ((old
^ cpu
->CP0_Cause
) & (1 << (CP0Ca_IP
+ i
))) {
1564 cpu_mips_soft_irq(cpu
, i
, cpu
->CP0_Cause
& (1 << (CP0Ca_IP
+ i
)));
1569 void helper_mtc0_cause(CPUMIPSState
*env
, target_ulong arg1
)
1571 mtc0_cause(env
, arg1
);
1574 void helper_mttc0_cause(CPUMIPSState
*env
, target_ulong arg1
)
1576 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1577 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1579 mtc0_cause(other
, arg1
);
1582 target_ulong
helper_mftc0_epc(CPUMIPSState
*env
)
1584 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1585 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1587 return other
->CP0_EPC
;
1590 target_ulong
helper_mftc0_ebase(CPUMIPSState
*env
)
1592 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1593 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1595 return other
->CP0_EBase
;
1598 void helper_mtc0_ebase(CPUMIPSState
*env
, target_ulong arg1
)
1600 /* vectored interrupts not implemented */
1601 env
->CP0_EBase
= (env
->CP0_EBase
& ~0x3FFFF000) | (arg1
& 0x3FFFF000);
1604 void helper_mttc0_ebase(CPUMIPSState
*env
, target_ulong arg1
)
1606 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1607 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1608 other
->CP0_EBase
= (other
->CP0_EBase
& ~0x3FFFF000) | (arg1
& 0x3FFFF000);
1611 target_ulong
helper_mftc0_configx(CPUMIPSState
*env
, target_ulong idx
)
1613 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1614 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1617 case 0: return other
->CP0_Config0
;
1618 case 1: return other
->CP0_Config1
;
1619 case 2: return other
->CP0_Config2
;
1620 case 3: return other
->CP0_Config3
;
1621 /* 4 and 5 are reserved. */
1622 case 6: return other
->CP0_Config6
;
1623 case 7: return other
->CP0_Config7
;
1630 void helper_mtc0_config0(CPUMIPSState
*env
, target_ulong arg1
)
1632 env
->CP0_Config0
= (env
->CP0_Config0
& 0x81FFFFF8) | (arg1
& 0x00000007);
1635 void helper_mtc0_config2(CPUMIPSState
*env
, target_ulong arg1
)
1637 /* tertiary/secondary caches not implemented */
1638 env
->CP0_Config2
= (env
->CP0_Config2
& 0x8FFF0FFF);
1641 void helper_mtc0_lladdr(CPUMIPSState
*env
, target_ulong arg1
)
1643 target_long mask
= env
->CP0_LLAddr_rw_bitmask
;
1644 arg1
= arg1
<< env
->CP0_LLAddr_shift
;
1645 env
->lladdr
= (env
->lladdr
& ~mask
) | (arg1
& mask
);
1648 void helper_mtc0_watchlo(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1650 /* Watch exceptions for instructions, data loads, data stores
1652 env
->CP0_WatchLo
[sel
] = (arg1
& ~0x7);
1655 void helper_mtc0_watchhi(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1657 env
->CP0_WatchHi
[sel
] = (arg1
& 0x40FF0FF8);
1658 env
->CP0_WatchHi
[sel
] &= ~(env
->CP0_WatchHi
[sel
] & arg1
& 0x7);
1661 void helper_mtc0_xcontext(CPUMIPSState
*env
, target_ulong arg1
)
1663 target_ulong mask
= (1ULL << (env
->SEGBITS
- 7)) - 1;
1664 env
->CP0_XContext
= (env
->CP0_XContext
& mask
) | (arg1
& ~mask
);
1667 void helper_mtc0_framemask(CPUMIPSState
*env
, target_ulong arg1
)
1669 env
->CP0_Framemask
= arg1
; /* XXX */
1672 void helper_mtc0_debug(CPUMIPSState
*env
, target_ulong arg1
)
1674 env
->CP0_Debug
= (env
->CP0_Debug
& 0x8C03FC1F) | (arg1
& 0x13300120);
1675 if (arg1
& (1 << CP0DB_DM
))
1676 env
->hflags
|= MIPS_HFLAG_DM
;
1678 env
->hflags
&= ~MIPS_HFLAG_DM
;
1681 void helper_mttc0_debug(CPUMIPSState
*env
, target_ulong arg1
)
1683 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1684 uint32_t val
= arg1
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
));
1685 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1687 /* XXX: Might be wrong, check with EJTAG spec. */
1688 if (other_tc
== other
->current_tc
)
1689 other
->active_tc
.CP0_Debug_tcstatus
= val
;
1691 other
->tcs
[other_tc
].CP0_Debug_tcstatus
= val
;
1692 other
->CP0_Debug
= (other
->CP0_Debug
&
1693 ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
1694 (arg1
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
1697 void helper_mtc0_performance0(CPUMIPSState
*env
, target_ulong arg1
)
1699 env
->CP0_Performance0
= arg1
& 0x000007ff;
1702 void helper_mtc0_taglo(CPUMIPSState
*env
, target_ulong arg1
)
1704 env
->CP0_TagLo
= arg1
& 0xFFFFFCF6;
1707 void helper_mtc0_datalo(CPUMIPSState
*env
, target_ulong arg1
)
1709 env
->CP0_DataLo
= arg1
; /* XXX */
1712 void helper_mtc0_taghi(CPUMIPSState
*env
, target_ulong arg1
)
1714 env
->CP0_TagHi
= arg1
; /* XXX */
1717 void helper_mtc0_datahi(CPUMIPSState
*env
, target_ulong arg1
)
1719 env
->CP0_DataHi
= arg1
; /* XXX */
1722 /* MIPS MT functions */
1723 target_ulong
helper_mftgpr(CPUMIPSState
*env
, uint32_t sel
)
1725 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1726 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1728 if (other_tc
== other
->current_tc
)
1729 return other
->active_tc
.gpr
[sel
];
1731 return other
->tcs
[other_tc
].gpr
[sel
];
1734 target_ulong
helper_mftlo(CPUMIPSState
*env
, uint32_t sel
)
1736 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1737 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1739 if (other_tc
== other
->current_tc
)
1740 return other
->active_tc
.LO
[sel
];
1742 return other
->tcs
[other_tc
].LO
[sel
];
1745 target_ulong
helper_mfthi(CPUMIPSState
*env
, uint32_t sel
)
1747 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1748 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1750 if (other_tc
== other
->current_tc
)
1751 return other
->active_tc
.HI
[sel
];
1753 return other
->tcs
[other_tc
].HI
[sel
];
1756 target_ulong
helper_mftacx(CPUMIPSState
*env
, uint32_t sel
)
1758 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1759 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1761 if (other_tc
== other
->current_tc
)
1762 return other
->active_tc
.ACX
[sel
];
1764 return other
->tcs
[other_tc
].ACX
[sel
];
1767 target_ulong
helper_mftdsp(CPUMIPSState
*env
)
1769 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1770 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1772 if (other_tc
== other
->current_tc
)
1773 return other
->active_tc
.DSPControl
;
1775 return other
->tcs
[other_tc
].DSPControl
;
1778 void helper_mttgpr(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1780 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1781 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1783 if (other_tc
== other
->current_tc
)
1784 other
->active_tc
.gpr
[sel
] = arg1
;
1786 other
->tcs
[other_tc
].gpr
[sel
] = arg1
;
1789 void helper_mttlo(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1791 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1792 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1794 if (other_tc
== other
->current_tc
)
1795 other
->active_tc
.LO
[sel
] = arg1
;
1797 other
->tcs
[other_tc
].LO
[sel
] = arg1
;
1800 void helper_mtthi(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1802 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1803 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1805 if (other_tc
== other
->current_tc
)
1806 other
->active_tc
.HI
[sel
] = arg1
;
1808 other
->tcs
[other_tc
].HI
[sel
] = arg1
;
1811 void helper_mttacx(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1813 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1814 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1816 if (other_tc
== other
->current_tc
)
1817 other
->active_tc
.ACX
[sel
] = arg1
;
1819 other
->tcs
[other_tc
].ACX
[sel
] = arg1
;
1822 void helper_mttdsp(CPUMIPSState
*env
, target_ulong arg1
)
1824 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1825 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1827 if (other_tc
== other
->current_tc
)
1828 other
->active_tc
.DSPControl
= arg1
;
1830 other
->tcs
[other_tc
].DSPControl
= arg1
;
1833 /* MIPS MT functions */
1834 target_ulong
helper_dmt(void)
1840 target_ulong
helper_emt(void)
1846 target_ulong
helper_dvpe(CPUMIPSState
*env
)
1848 CPUMIPSState
*other_cpu_env
= first_cpu
;
1849 target_ulong prev
= env
->mvp
->CP0_MVPControl
;
1852 /* Turn off all VPEs except the one executing the dvpe. */
1853 if (other_cpu_env
!= env
) {
1854 MIPSCPU
*other_cpu
= mips_env_get_cpu(other_cpu_env
);
1856 other_cpu_env
->mvp
->CP0_MVPControl
&= ~(1 << CP0MVPCo_EVP
);
1857 mips_vpe_sleep(other_cpu
);
1859 other_cpu_env
= other_cpu_env
->next_cpu
;
1860 } while (other_cpu_env
);
1864 target_ulong
helper_evpe(CPUMIPSState
*env
)
1866 CPUMIPSState
*other_cpu_env
= first_cpu
;
1867 target_ulong prev
= env
->mvp
->CP0_MVPControl
;
1870 MIPSCPU
*other_cpu
= mips_env_get_cpu(other_cpu_env
);
1872 if (other_cpu_env
!= env
1873 /* If the VPE is WFI, don't disturb its sleep. */
1874 && !mips_vpe_is_wfi(other_cpu
)) {
1875 /* Enable the VPE. */
1876 other_cpu_env
->mvp
->CP0_MVPControl
|= (1 << CP0MVPCo_EVP
);
1877 mips_vpe_wake(other_cpu_env
); /* And wake it up. */
1879 other_cpu_env
= other_cpu_env
->next_cpu
;
1880 } while (other_cpu_env
);
1883 #endif /* !CONFIG_USER_ONLY */
1885 void helper_fork(target_ulong arg1
, target_ulong arg2
)
1887 // arg1 = rt, arg2 = rs
1889 // TODO: store to TC register
1892 target_ulong
helper_yield(CPUMIPSState
*env
, target_ulong arg
)
1894 target_long arg1
= arg
;
1897 /* No scheduling policy implemented. */
1899 if (env
->CP0_VPEControl
& (1 << CP0VPECo_YSI
) &&
1900 env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_DT
)) {
1901 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1902 env
->CP0_VPEControl
|= 4 << CP0VPECo_EXCPT
;
1903 helper_raise_exception(env
, EXCP_THREAD
);
1906 } else if (arg1
== 0) {
1907 if (0 /* TODO: TC underflow */) {
1908 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1909 helper_raise_exception(env
, EXCP_THREAD
);
1911 // TODO: Deallocate TC
1913 } else if (arg1
> 0) {
1914 /* Yield qualifier inputs not implemented. */
1915 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1916 env
->CP0_VPEControl
|= 2 << CP0VPECo_EXCPT
;
1917 helper_raise_exception(env
, EXCP_THREAD
);
1919 return env
->CP0_YQMask
;
1922 #ifndef CONFIG_USER_ONLY
1923 /* TLB management */
1924 static void cpu_mips_tlb_flush (CPUMIPSState
*env
, int flush_global
)
1926 /* Flush qemu's TLB and discard all shadowed entries. */
1927 tlb_flush (env
, flush_global
);
1928 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
1931 static void r4k_mips_tlb_flush_extra (CPUMIPSState
*env
, int first
)
1933 /* Discard entries from env->tlb[first] onwards. */
1934 while (env
->tlb
->tlb_in_use
> first
) {
1935 r4k_invalidate_tlb(env
, --env
->tlb
->tlb_in_use
, 0);
1939 static void r4k_fill_tlb(CPUMIPSState
*env
, int idx
)
1943 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
1944 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1945 tlb
->VPN
= env
->CP0_EntryHi
& (TARGET_PAGE_MASK
<< 1);
1946 #if defined(TARGET_MIPS64)
1947 tlb
->VPN
&= env
->SEGMask
;
1949 tlb
->ASID
= env
->CP0_EntryHi
& 0xFF;
1950 tlb
->PageMask
= env
->CP0_PageMask
;
1951 tlb
->G
= env
->CP0_EntryLo0
& env
->CP0_EntryLo1
& 1;
1952 tlb
->V0
= (env
->CP0_EntryLo0
& 2) != 0;
1953 tlb
->D0
= (env
->CP0_EntryLo0
& 4) != 0;
1954 tlb
->C0
= (env
->CP0_EntryLo0
>> 3) & 0x7;
1955 tlb
->PFN
[0] = (env
->CP0_EntryLo0
>> 6) << 12;
1956 tlb
->V1
= (env
->CP0_EntryLo1
& 2) != 0;
1957 tlb
->D1
= (env
->CP0_EntryLo1
& 4) != 0;
1958 tlb
->C1
= (env
->CP0_EntryLo1
>> 3) & 0x7;
1959 tlb
->PFN
[1] = (env
->CP0_EntryLo1
>> 6) << 12;
1962 void r4k_helper_tlbwi(CPUMIPSState
*env
)
1966 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
1968 /* Discard cached TLB entries. We could avoid doing this if the
1969 tlbwi is just upgrading access permissions on the current entry;
1970 that might be a further win. */
1971 r4k_mips_tlb_flush_extra (env
, env
->tlb
->nb_tlb
);
1973 r4k_invalidate_tlb(env
, idx
, 0);
1974 r4k_fill_tlb(env
, idx
);
1977 void r4k_helper_tlbwr(CPUMIPSState
*env
)
1979 int r
= cpu_mips_get_random(env
);
1981 r4k_invalidate_tlb(env
, r
, 1);
1982 r4k_fill_tlb(env
, r
);
1985 void r4k_helper_tlbp(CPUMIPSState
*env
)
1994 ASID
= env
->CP0_EntryHi
& 0xFF;
1995 for (i
= 0; i
< env
->tlb
->nb_tlb
; i
++) {
1996 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
1997 /* 1k pages are not supported. */
1998 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
1999 tag
= env
->CP0_EntryHi
& ~mask
;
2000 VPN
= tlb
->VPN
& ~mask
;
2001 /* Check ASID, virtual page number & size */
2002 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
2008 if (i
== env
->tlb
->nb_tlb
) {
2009 /* No match. Discard any shadow entries, if any of them match. */
2010 for (i
= env
->tlb
->nb_tlb
; i
< env
->tlb
->tlb_in_use
; i
++) {
2011 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
2012 /* 1k pages are not supported. */
2013 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
2014 tag
= env
->CP0_EntryHi
& ~mask
;
2015 VPN
= tlb
->VPN
& ~mask
;
2016 /* Check ASID, virtual page number & size */
2017 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
2018 r4k_mips_tlb_flush_extra (env
, i
);
2023 env
->CP0_Index
|= 0x80000000;
2027 void r4k_helper_tlbr(CPUMIPSState
*env
)
2033 ASID
= env
->CP0_EntryHi
& 0xFF;
2034 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
2035 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
2037 /* If this will change the current ASID, flush qemu's TLB. */
2038 if (ASID
!= tlb
->ASID
)
2039 cpu_mips_tlb_flush (env
, 1);
2041 r4k_mips_tlb_flush_extra(env
, env
->tlb
->nb_tlb
);
2043 env
->CP0_EntryHi
= tlb
->VPN
| tlb
->ASID
;
2044 env
->CP0_PageMask
= tlb
->PageMask
;
2045 env
->CP0_EntryLo0
= tlb
->G
| (tlb
->V0
<< 1) | (tlb
->D0
<< 2) |
2046 (tlb
->C0
<< 3) | (tlb
->PFN
[0] >> 6);
2047 env
->CP0_EntryLo1
= tlb
->G
| (tlb
->V1
<< 1) | (tlb
->D1
<< 2) |
2048 (tlb
->C1
<< 3) | (tlb
->PFN
[1] >> 6);
2051 void helper_tlbwi(CPUMIPSState
*env
)
2053 env
->tlb
->helper_tlbwi(env
);
2056 void helper_tlbwr(CPUMIPSState
*env
)
2058 env
->tlb
->helper_tlbwr(env
);
2061 void helper_tlbp(CPUMIPSState
*env
)
2063 env
->tlb
->helper_tlbp(env
);
2066 void helper_tlbr(CPUMIPSState
*env
)
2068 env
->tlb
->helper_tlbr(env
);
2072 target_ulong
helper_di(CPUMIPSState
*env
)
2074 target_ulong t0
= env
->CP0_Status
;
2076 env
->CP0_Status
= t0
& ~(1 << CP0St_IE
);
2080 target_ulong
helper_ei(CPUMIPSState
*env
)
2082 target_ulong t0
= env
->CP0_Status
;
2084 env
->CP0_Status
= t0
| (1 << CP0St_IE
);
2088 static void debug_pre_eret(CPUMIPSState
*env
)
2090 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
2091 qemu_log("ERET: PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
2092 env
->active_tc
.PC
, env
->CP0_EPC
);
2093 if (env
->CP0_Status
& (1 << CP0St_ERL
))
2094 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
2095 if (env
->hflags
& MIPS_HFLAG_DM
)
2096 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
2101 static void debug_post_eret(CPUMIPSState
*env
)
2103 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
2104 qemu_log(" => PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
2105 env
->active_tc
.PC
, env
->CP0_EPC
);
2106 if (env
->CP0_Status
& (1 << CP0St_ERL
))
2107 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
2108 if (env
->hflags
& MIPS_HFLAG_DM
)
2109 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
2110 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
2111 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
2112 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
2113 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
2114 default: cpu_abort(env
, "Invalid MMU mode!\n"); break;
2119 static void set_pc(CPUMIPSState
*env
, target_ulong error_pc
)
2121 env
->active_tc
.PC
= error_pc
& ~(target_ulong
)1;
2123 env
->hflags
|= MIPS_HFLAG_M16
;
2125 env
->hflags
&= ~(MIPS_HFLAG_M16
);
2129 void helper_eret(CPUMIPSState
*env
)
2131 debug_pre_eret(env
);
2132 if (env
->CP0_Status
& (1 << CP0St_ERL
)) {
2133 set_pc(env
, env
->CP0_ErrorEPC
);
2134 env
->CP0_Status
&= ~(1 << CP0St_ERL
);
2136 set_pc(env
, env
->CP0_EPC
);
2137 env
->CP0_Status
&= ~(1 << CP0St_EXL
);
2139 compute_hflags(env
);
2140 debug_post_eret(env
);
2144 void helper_deret(CPUMIPSState
*env
)
2146 debug_pre_eret(env
);
2147 set_pc(env
, env
->CP0_DEPC
);
2149 env
->hflags
&= MIPS_HFLAG_DM
;
2150 compute_hflags(env
);
2151 debug_post_eret(env
);
2154 #endif /* !CONFIG_USER_ONLY */
2156 target_ulong
helper_rdhwr_cpunum(CPUMIPSState
*env
)
2158 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2159 (env
->CP0_HWREna
& (1 << 0)))
2160 return env
->CP0_EBase
& 0x3ff;
2162 helper_raise_exception(env
, EXCP_RI
);
2167 target_ulong
helper_rdhwr_synci_step(CPUMIPSState
*env
)
2169 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2170 (env
->CP0_HWREna
& (1 << 1)))
2171 return env
->SYNCI_Step
;
2173 helper_raise_exception(env
, EXCP_RI
);
2178 target_ulong
helper_rdhwr_cc(CPUMIPSState
*env
)
2180 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2181 (env
->CP0_HWREna
& (1 << 2)))
2182 return env
->CP0_Count
;
2184 helper_raise_exception(env
, EXCP_RI
);
2189 target_ulong
helper_rdhwr_ccres(CPUMIPSState
*env
)
2191 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2192 (env
->CP0_HWREna
& (1 << 3)))
2195 helper_raise_exception(env
, EXCP_RI
);
2200 void helper_pmon(CPUMIPSState
*env
, int function
)
2204 case 2: /* TODO: char inbyte(int waitflag); */
2205 if (env
->active_tc
.gpr
[4] == 0)
2206 env
->active_tc
.gpr
[2] = -1;
2208 case 11: /* TODO: char inbyte (void); */
2209 env
->active_tc
.gpr
[2] = -1;
2213 printf("%c", (char)(env
->active_tc
.gpr
[4] & 0xFF));
2219 unsigned char *fmt
= (void *)(uintptr_t)env
->active_tc
.gpr
[4];
2226 void helper_wait(CPUMIPSState
*env
)
2229 cpu_reset_interrupt(env
, CPU_INTERRUPT_WAKE
);
2230 helper_raise_exception(env
, EXCP_HLT
);
2233 #if !defined(CONFIG_USER_ONLY)
2235 static void QEMU_NORETURN
do_unaligned_access(CPUMIPSState
*env
,
2236 target_ulong addr
, int is_write
,
2237 int is_user
, uintptr_t retaddr
);
2239 #define MMUSUFFIX _mmu
2240 #define ALIGNED_ONLY
2243 #include "softmmu_template.h"
2246 #include "softmmu_template.h"
2249 #include "softmmu_template.h"
2252 #include "softmmu_template.h"
2254 static void do_unaligned_access(CPUMIPSState
*env
, target_ulong addr
,
2255 int is_write
, int is_user
, uintptr_t retaddr
)
2257 env
->CP0_BadVAddr
= addr
;
2258 do_raise_exception(env
, (is_write
== 1) ? EXCP_AdES
: EXCP_AdEL
, retaddr
);
2261 void tlb_fill(CPUMIPSState
*env
, target_ulong addr
, int is_write
, int mmu_idx
,
2266 ret
= cpu_mips_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
2268 do_raise_exception_err(env
, env
->exception_index
,
2269 env
->error_code
, retaddr
);
2273 void cpu_unassigned_access(CPUMIPSState
*env
, hwaddr addr
,
2274 int is_write
, int is_exec
, int unused
, int size
)
2277 helper_raise_exception(env
, EXCP_IBE
);
2279 helper_raise_exception(env
, EXCP_DBE
);
2281 #endif /* !CONFIG_USER_ONLY */
2283 /* Complex FPU operations which may need stack space. */
2285 #define FLOAT_TWO32 make_float32(1 << 30)
2286 #define FLOAT_TWO64 make_float64(1ULL << 62)
2287 #define FP_TO_INT32_OVERFLOW 0x7fffffff
2288 #define FP_TO_INT64_OVERFLOW 0x7fffffffffffffffULL
2290 /* convert MIPS rounding mode in FCR31 to IEEE library */
2291 static unsigned int ieee_rm
[] = {
2292 float_round_nearest_even
,
2293 float_round_to_zero
,
2298 #define RESTORE_ROUNDING_MODE \
2299 set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3], &env->active_fpu.fp_status)
2301 #define RESTORE_FLUSH_MODE \
2302 set_flush_to_zero((env->active_fpu.fcr31 & (1 << 24)) != 0, &env->active_fpu.fp_status);
2304 target_ulong
helper_cfc1(CPUMIPSState
*env
, uint32_t reg
)
2310 arg1
= (int32_t)env
->active_fpu
.fcr0
;
2313 arg1
= ((env
->active_fpu
.fcr31
>> 24) & 0xfe) | ((env
->active_fpu
.fcr31
>> 23) & 0x1);
2316 arg1
= env
->active_fpu
.fcr31
& 0x0003f07c;
2319 arg1
= (env
->active_fpu
.fcr31
& 0x00000f83) | ((env
->active_fpu
.fcr31
>> 22) & 0x4);
2322 arg1
= (int32_t)env
->active_fpu
.fcr31
;
2329 void helper_ctc1(CPUMIPSState
*env
, target_ulong arg1
, uint32_t reg
)
2333 if (arg1
& 0xffffff00)
2335 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0x017fffff) | ((arg1
& 0xfe) << 24) |
2336 ((arg1
& 0x1) << 23);
2339 if (arg1
& 0x007c0000)
2341 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfffc0f83) | (arg1
& 0x0003f07c);
2344 if (arg1
& 0x007c0000)
2346 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfefff07c) | (arg1
& 0x00000f83) |
2347 ((arg1
& 0x4) << 22);
2350 if (arg1
& 0x007c0000)
2352 env
->active_fpu
.fcr31
= arg1
;
2357 /* set rounding mode */
2358 RESTORE_ROUNDING_MODE
;
2359 /* set flush-to-zero mode */
2361 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2362 if ((GET_FP_ENABLE(env
->active_fpu
.fcr31
) | 0x20) & GET_FP_CAUSE(env
->active_fpu
.fcr31
))
2363 do_raise_exception(env
, EXCP_FPE
, GETPC());
2366 static inline int ieee_ex_to_mips(int xcpt
)
2370 if (xcpt
& float_flag_invalid
) {
2373 if (xcpt
& float_flag_overflow
) {
2376 if (xcpt
& float_flag_underflow
) {
2377 ret
|= FP_UNDERFLOW
;
2379 if (xcpt
& float_flag_divbyzero
) {
2382 if (xcpt
& float_flag_inexact
) {
2389 static inline void update_fcr31(CPUMIPSState
*env
, uintptr_t pc
)
2391 int tmp
= ieee_ex_to_mips(get_float_exception_flags(&env
->active_fpu
.fp_status
));
2393 SET_FP_CAUSE(env
->active_fpu
.fcr31
, tmp
);
2396 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2398 if (GET_FP_ENABLE(env
->active_fpu
.fcr31
) & tmp
) {
2399 do_raise_exception(env
, EXCP_FPE
, pc
);
2401 UPDATE_FP_FLAGS(env
->active_fpu
.fcr31
, tmp
);
2407 Single precition routines have a "s" suffix, double precision a
2408 "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
2409 paired single lower "pl", paired single upper "pu". */
2411 /* unary operations, modifying fp status */
2412 uint64_t helper_float_sqrt_d(CPUMIPSState
*env
, uint64_t fdt0
)
2414 fdt0
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2415 update_fcr31(env
, GETPC());
2419 uint32_t helper_float_sqrt_s(CPUMIPSState
*env
, uint32_t fst0
)
2421 fst0
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2422 update_fcr31(env
, GETPC());
2426 uint64_t helper_float_cvtd_s(CPUMIPSState
*env
, uint32_t fst0
)
2430 fdt2
= float32_to_float64(fst0
, &env
->active_fpu
.fp_status
);
2431 update_fcr31(env
, GETPC());
2435 uint64_t helper_float_cvtd_w(CPUMIPSState
*env
, uint32_t wt0
)
2439 fdt2
= int32_to_float64(wt0
, &env
->active_fpu
.fp_status
);
2440 update_fcr31(env
, GETPC());
2444 uint64_t helper_float_cvtd_l(CPUMIPSState
*env
, uint64_t dt0
)
2448 fdt2
= int64_to_float64(dt0
, &env
->active_fpu
.fp_status
);
2449 update_fcr31(env
, GETPC());
2453 uint64_t helper_float_cvtl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2457 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2458 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2459 & (float_flag_invalid
| float_flag_overflow
)) {
2460 dt2
= FP_TO_INT64_OVERFLOW
;
2462 update_fcr31(env
, GETPC());
2466 uint64_t helper_float_cvtl_s(CPUMIPSState
*env
, uint32_t fst0
)
2470 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2471 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2472 & (float_flag_invalid
| float_flag_overflow
)) {
2473 dt2
= FP_TO_INT64_OVERFLOW
;
2475 update_fcr31(env
, GETPC());
2479 uint64_t helper_float_cvtps_pw(CPUMIPSState
*env
, uint64_t dt0
)
2484 fst2
= int32_to_float32(dt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2485 fsth2
= int32_to_float32(dt0
>> 32, &env
->active_fpu
.fp_status
);
2486 update_fcr31(env
, GETPC());
2487 return ((uint64_t)fsth2
<< 32) | fst2
;
2490 uint64_t helper_float_cvtpw_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2496 wt2
= float32_to_int32(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2497 excp
= get_float_exception_flags(&env
->active_fpu
.fp_status
);
2498 if (excp
& (float_flag_overflow
| float_flag_invalid
)) {
2499 wt2
= FP_TO_INT32_OVERFLOW
;
2502 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2503 wth2
= float32_to_int32(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2504 excph
= get_float_exception_flags(&env
->active_fpu
.fp_status
);
2505 if (excph
& (float_flag_overflow
| float_flag_invalid
)) {
2506 wth2
= FP_TO_INT32_OVERFLOW
;
2509 set_float_exception_flags(excp
| excph
, &env
->active_fpu
.fp_status
);
2510 update_fcr31(env
, GETPC());
2512 return ((uint64_t)wth2
<< 32) | wt2
;
2515 uint32_t helper_float_cvts_d(CPUMIPSState
*env
, uint64_t fdt0
)
2519 fst2
= float64_to_float32(fdt0
, &env
->active_fpu
.fp_status
);
2520 update_fcr31(env
, GETPC());
2524 uint32_t helper_float_cvts_w(CPUMIPSState
*env
, uint32_t wt0
)
2528 fst2
= int32_to_float32(wt0
, &env
->active_fpu
.fp_status
);
2529 update_fcr31(env
, GETPC());
2533 uint32_t helper_float_cvts_l(CPUMIPSState
*env
, uint64_t dt0
)
2537 fst2
= int64_to_float32(dt0
, &env
->active_fpu
.fp_status
);
2538 update_fcr31(env
, GETPC());
2542 uint32_t helper_float_cvts_pl(CPUMIPSState
*env
, uint32_t wt0
)
2547 update_fcr31(env
, GETPC());
2551 uint32_t helper_float_cvts_pu(CPUMIPSState
*env
, uint32_t wth0
)
2556 update_fcr31(env
, GETPC());
2560 uint32_t helper_float_cvtw_s(CPUMIPSState
*env
, uint32_t fst0
)
2564 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2565 update_fcr31(env
, GETPC());
2566 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2567 & (float_flag_invalid
| float_flag_overflow
)) {
2568 wt2
= FP_TO_INT32_OVERFLOW
;
2573 uint32_t helper_float_cvtw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2577 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2578 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2579 & (float_flag_invalid
| float_flag_overflow
)) {
2580 wt2
= FP_TO_INT32_OVERFLOW
;
2582 update_fcr31(env
, GETPC());
2586 uint64_t helper_float_roundl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2590 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2591 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2592 RESTORE_ROUNDING_MODE
;
2593 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2594 & (float_flag_invalid
| float_flag_overflow
)) {
2595 dt2
= FP_TO_INT64_OVERFLOW
;
2597 update_fcr31(env
, GETPC());
2601 uint64_t helper_float_roundl_s(CPUMIPSState
*env
, uint32_t fst0
)
2605 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2606 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2607 RESTORE_ROUNDING_MODE
;
2608 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2609 & (float_flag_invalid
| float_flag_overflow
)) {
2610 dt2
= FP_TO_INT64_OVERFLOW
;
2612 update_fcr31(env
, GETPC());
2616 uint32_t helper_float_roundw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2620 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2621 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2622 RESTORE_ROUNDING_MODE
;
2623 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2624 & (float_flag_invalid
| float_flag_overflow
)) {
2625 wt2
= FP_TO_INT32_OVERFLOW
;
2627 update_fcr31(env
, GETPC());
2631 uint32_t helper_float_roundw_s(CPUMIPSState
*env
, uint32_t fst0
)
2635 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2636 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2637 RESTORE_ROUNDING_MODE
;
2638 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2639 & (float_flag_invalid
| float_flag_overflow
)) {
2640 wt2
= FP_TO_INT32_OVERFLOW
;
2642 update_fcr31(env
, GETPC());
2646 uint64_t helper_float_truncl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2650 dt2
= float64_to_int64_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2651 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2652 & (float_flag_invalid
| float_flag_overflow
)) {
2653 dt2
= FP_TO_INT64_OVERFLOW
;
2655 update_fcr31(env
, GETPC());
2659 uint64_t helper_float_truncl_s(CPUMIPSState
*env
, uint32_t fst0
)
2663 dt2
= float32_to_int64_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2664 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2665 & (float_flag_invalid
| float_flag_overflow
)) {
2666 dt2
= FP_TO_INT64_OVERFLOW
;
2668 update_fcr31(env
, GETPC());
2672 uint32_t helper_float_truncw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2676 wt2
= float64_to_int32_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2677 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2678 & (float_flag_invalid
| float_flag_overflow
)) {
2679 wt2
= FP_TO_INT32_OVERFLOW
;
2681 update_fcr31(env
, GETPC());
2685 uint32_t helper_float_truncw_s(CPUMIPSState
*env
, uint32_t fst0
)
2689 wt2
= float32_to_int32_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2690 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2691 & (float_flag_invalid
| float_flag_overflow
)) {
2692 wt2
= FP_TO_INT32_OVERFLOW
;
2694 update_fcr31(env
, GETPC());
2698 uint64_t helper_float_ceill_d(CPUMIPSState
*env
, uint64_t fdt0
)
2702 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2703 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2704 RESTORE_ROUNDING_MODE
;
2705 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2706 & (float_flag_invalid
| float_flag_overflow
)) {
2707 dt2
= FP_TO_INT64_OVERFLOW
;
2709 update_fcr31(env
, GETPC());
2713 uint64_t helper_float_ceill_s(CPUMIPSState
*env
, uint32_t fst0
)
2717 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2718 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2719 RESTORE_ROUNDING_MODE
;
2720 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2721 & (float_flag_invalid
| float_flag_overflow
)) {
2722 dt2
= FP_TO_INT64_OVERFLOW
;
2724 update_fcr31(env
, GETPC());
2728 uint32_t helper_float_ceilw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2732 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2733 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2734 RESTORE_ROUNDING_MODE
;
2735 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2736 & (float_flag_invalid
| float_flag_overflow
)) {
2737 wt2
= FP_TO_INT32_OVERFLOW
;
2739 update_fcr31(env
, GETPC());
2743 uint32_t helper_float_ceilw_s(CPUMIPSState
*env
, uint32_t fst0
)
2747 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2748 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2749 RESTORE_ROUNDING_MODE
;
2750 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2751 & (float_flag_invalid
| float_flag_overflow
)) {
2752 wt2
= FP_TO_INT32_OVERFLOW
;
2754 update_fcr31(env
, GETPC());
2758 uint64_t helper_float_floorl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2762 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2763 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2764 RESTORE_ROUNDING_MODE
;
2765 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2766 & (float_flag_invalid
| float_flag_overflow
)) {
2767 dt2
= FP_TO_INT64_OVERFLOW
;
2769 update_fcr31(env
, GETPC());
2773 uint64_t helper_float_floorl_s(CPUMIPSState
*env
, uint32_t fst0
)
2777 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2778 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2779 RESTORE_ROUNDING_MODE
;
2780 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2781 & (float_flag_invalid
| float_flag_overflow
)) {
2782 dt2
= FP_TO_INT64_OVERFLOW
;
2784 update_fcr31(env
, GETPC());
2788 uint32_t helper_float_floorw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2792 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2793 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2794 RESTORE_ROUNDING_MODE
;
2795 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2796 & (float_flag_invalid
| float_flag_overflow
)) {
2797 wt2
= FP_TO_INT32_OVERFLOW
;
2799 update_fcr31(env
, GETPC());
2803 uint32_t helper_float_floorw_s(CPUMIPSState
*env
, uint32_t fst0
)
2807 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2808 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2809 RESTORE_ROUNDING_MODE
;
2810 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2811 & (float_flag_invalid
| float_flag_overflow
)) {
2812 wt2
= FP_TO_INT32_OVERFLOW
;
2814 update_fcr31(env
, GETPC());
2818 /* unary operations, not modifying fp status */
2819 #define FLOAT_UNOP(name) \
2820 uint64_t helper_float_ ## name ## _d(uint64_t fdt0) \
2822 return float64_ ## name(fdt0); \
2824 uint32_t helper_float_ ## name ## _s(uint32_t fst0) \
2826 return float32_ ## name(fst0); \
2828 uint64_t helper_float_ ## name ## _ps(uint64_t fdt0) \
2833 wt0 = float32_ ## name(fdt0 & 0XFFFFFFFF); \
2834 wth0 = float32_ ## name(fdt0 >> 32); \
2835 return ((uint64_t)wth0 << 32) | wt0; \
2841 /* MIPS specific unary operations */
2842 uint64_t helper_float_recip_d(CPUMIPSState
*env
, uint64_t fdt0
)
2846 fdt2
= float64_div(float64_one
, fdt0
, &env
->active_fpu
.fp_status
);
2847 update_fcr31(env
, GETPC());
2851 uint32_t helper_float_recip_s(CPUMIPSState
*env
, uint32_t fst0
)
2855 fst2
= float32_div(float32_one
, fst0
, &env
->active_fpu
.fp_status
);
2856 update_fcr31(env
, GETPC());
2860 uint64_t helper_float_rsqrt_d(CPUMIPSState
*env
, uint64_t fdt0
)
2864 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2865 fdt2
= float64_div(float64_one
, fdt2
, &env
->active_fpu
.fp_status
);
2866 update_fcr31(env
, GETPC());
2870 uint32_t helper_float_rsqrt_s(CPUMIPSState
*env
, uint32_t fst0
)
2874 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2875 fst2
= float32_div(float32_one
, fst2
, &env
->active_fpu
.fp_status
);
2876 update_fcr31(env
, GETPC());
2880 uint64_t helper_float_recip1_d(CPUMIPSState
*env
, uint64_t fdt0
)
2884 fdt2
= float64_div(float64_one
, fdt0
, &env
->active_fpu
.fp_status
);
2885 update_fcr31(env
, GETPC());
2889 uint32_t helper_float_recip1_s(CPUMIPSState
*env
, uint32_t fst0
)
2893 fst2
= float32_div(float32_one
, fst0
, &env
->active_fpu
.fp_status
);
2894 update_fcr31(env
, GETPC());
2898 uint64_t helper_float_recip1_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2903 fst2
= float32_div(float32_one
, fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2904 fsth2
= float32_div(float32_one
, fdt0
>> 32, &env
->active_fpu
.fp_status
);
2905 update_fcr31(env
, GETPC());
2906 return ((uint64_t)fsth2
<< 32) | fst2
;
2909 uint64_t helper_float_rsqrt1_d(CPUMIPSState
*env
, uint64_t fdt0
)
2913 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2914 fdt2
= float64_div(float64_one
, fdt2
, &env
->active_fpu
.fp_status
);
2915 update_fcr31(env
, GETPC());
2919 uint32_t helper_float_rsqrt1_s(CPUMIPSState
*env
, uint32_t fst0
)
2923 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2924 fst2
= float32_div(float32_one
, fst2
, &env
->active_fpu
.fp_status
);
2925 update_fcr31(env
, GETPC());
2929 uint64_t helper_float_rsqrt1_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2934 fst2
= float32_sqrt(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2935 fsth2
= float32_sqrt(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2936 fst2
= float32_div(float32_one
, fst2
, &env
->active_fpu
.fp_status
);
2937 fsth2
= float32_div(float32_one
, fsth2
, &env
->active_fpu
.fp_status
);
2938 update_fcr31(env
, GETPC());
2939 return ((uint64_t)fsth2
<< 32) | fst2
;
2942 #define FLOAT_OP(name, p) void helper_float_##name##_##p(CPUMIPSState *env)
2944 /* binary operations */
2945 #define FLOAT_BINOP(name) \
2946 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
2947 uint64_t fdt0, uint64_t fdt1) \
2951 dt2 = float64_ ## name (fdt0, fdt1, &env->active_fpu.fp_status); \
2952 update_fcr31(env, GETPC()); \
2956 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
2957 uint32_t fst0, uint32_t fst1) \
2961 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2962 update_fcr31(env, GETPC()); \
2966 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
2970 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2971 uint32_t fsth0 = fdt0 >> 32; \
2972 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2973 uint32_t fsth1 = fdt1 >> 32; \
2977 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2978 wth2 = float32_ ## name (fsth0, fsth1, &env->active_fpu.fp_status); \
2979 update_fcr31(env, GETPC()); \
2980 return ((uint64_t)wth2 << 32) | wt2; \
2989 /* FMA based operations */
2990 #define FLOAT_FMA(name, type) \
2991 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
2992 uint64_t fdt0, uint64_t fdt1, \
2995 fdt0 = float64_muladd(fdt0, fdt1, fdt2, type, \
2996 &env->active_fpu.fp_status); \
2997 update_fcr31(env, GETPC()); \
3001 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
3002 uint32_t fst0, uint32_t fst1, \
3005 fst0 = float32_muladd(fst0, fst1, fst2, type, \
3006 &env->active_fpu.fp_status); \
3007 update_fcr31(env, GETPC()); \
3011 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
3012 uint64_t fdt0, uint64_t fdt1, \
3015 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
3016 uint32_t fsth0 = fdt0 >> 32; \
3017 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
3018 uint32_t fsth1 = fdt1 >> 32; \
3019 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
3020 uint32_t fsth2 = fdt2 >> 32; \
3022 fst0 = float32_muladd(fst0, fst1, fst2, type, \
3023 &env->active_fpu.fp_status); \
3024 fsth0 = float32_muladd(fsth0, fsth1, fsth2, type, \
3025 &env->active_fpu.fp_status); \
3026 update_fcr31(env, GETPC()); \
3027 return ((uint64_t)fsth0 << 32) | fst0; \
3030 FLOAT_FMA(msub
, float_muladd_negate_c
)
3031 FLOAT_FMA(nmadd
, float_muladd_negate_result
)
3032 FLOAT_FMA(nmsub
, float_muladd_negate_result
| float_muladd_negate_c
)
3035 /* MIPS specific binary operations */
3036 uint64_t helper_float_recip2_d(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3038 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
3039 fdt2
= float64_chs(float64_sub(fdt2
, float64_one
, &env
->active_fpu
.fp_status
));
3040 update_fcr31(env
, GETPC());
3044 uint32_t helper_float_recip2_s(CPUMIPSState
*env
, uint32_t fst0
, uint32_t fst2
)
3046 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3047 fst2
= float32_chs(float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
));
3048 update_fcr31(env
, GETPC());
3052 uint64_t helper_float_recip2_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3054 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3055 uint32_t fsth0
= fdt0
>> 32;
3056 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
3057 uint32_t fsth2
= fdt2
>> 32;
3059 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3060 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
3061 fst2
= float32_chs(float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
));
3062 fsth2
= float32_chs(float32_sub(fsth2
, float32_one
, &env
->active_fpu
.fp_status
));
3063 update_fcr31(env
, GETPC());
3064 return ((uint64_t)fsth2
<< 32) | fst2
;
3067 uint64_t helper_float_rsqrt2_d(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3069 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
3070 fdt2
= float64_sub(fdt2
, float64_one
, &env
->active_fpu
.fp_status
);
3071 fdt2
= float64_chs(float64_div(fdt2
, FLOAT_TWO64
, &env
->active_fpu
.fp_status
));
3072 update_fcr31(env
, GETPC());
3076 uint32_t helper_float_rsqrt2_s(CPUMIPSState
*env
, uint32_t fst0
, uint32_t fst2
)
3078 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3079 fst2
= float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
);
3080 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3081 update_fcr31(env
, GETPC());
3085 uint64_t helper_float_rsqrt2_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3087 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3088 uint32_t fsth0
= fdt0
>> 32;
3089 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
3090 uint32_t fsth2
= fdt2
>> 32;
3092 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3093 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
3094 fst2
= float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
);
3095 fsth2
= float32_sub(fsth2
, float32_one
, &env
->active_fpu
.fp_status
);
3096 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3097 fsth2
= float32_chs(float32_div(fsth2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3098 update_fcr31(env
, GETPC());
3099 return ((uint64_t)fsth2
<< 32) | fst2
;
3102 uint64_t helper_float_addr_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt1
)
3104 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3105 uint32_t fsth0
= fdt0
>> 32;
3106 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
3107 uint32_t fsth1
= fdt1
>> 32;
3111 fst2
= float32_add (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
3112 fsth2
= float32_add (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
3113 update_fcr31(env
, GETPC());
3114 return ((uint64_t)fsth2
<< 32) | fst2
;
3117 uint64_t helper_float_mulr_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt1
)
3119 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3120 uint32_t fsth0
= fdt0
>> 32;
3121 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
3122 uint32_t fsth1
= fdt1
>> 32;
3126 fst2
= float32_mul (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
3127 fsth2
= float32_mul (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
3128 update_fcr31(env
, GETPC());
3129 return ((uint64_t)fsth2
<< 32) | fst2
;
3132 /* compare operations */
3133 #define FOP_COND_D(op, cond) \
3134 void helper_cmp_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3135 uint64_t fdt1, int cc) \
3139 update_fcr31(env, GETPC()); \
3141 SET_FP_COND(cc, env->active_fpu); \
3143 CLEAR_FP_COND(cc, env->active_fpu); \
3145 void helper_cmpabs_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3146 uint64_t fdt1, int cc) \
3149 fdt0 = float64_abs(fdt0); \
3150 fdt1 = float64_abs(fdt1); \
3152 update_fcr31(env, GETPC()); \
3154 SET_FP_COND(cc, env->active_fpu); \
3156 CLEAR_FP_COND(cc, env->active_fpu); \
3159 /* NOTE: the comma operator will make "cond" to eval to false,
3160 * but float64_unordered_quiet() is still called. */
3161 FOP_COND_D(f
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3162 FOP_COND_D(un
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
3163 FOP_COND_D(eq
, float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3164 FOP_COND_D(ueq
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3165 FOP_COND_D(olt
, float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3166 FOP_COND_D(ult
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3167 FOP_COND_D(ole
, float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3168 FOP_COND_D(ule
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3169 /* NOTE: the comma operator will make "cond" to eval to false,
3170 * but float64_unordered() is still called. */
3171 FOP_COND_D(sf
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3172 FOP_COND_D(ngle
,float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
3173 FOP_COND_D(seq
, float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3174 FOP_COND_D(ngl
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3175 FOP_COND_D(lt
, float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3176 FOP_COND_D(nge
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3177 FOP_COND_D(le
, float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3178 FOP_COND_D(ngt
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3180 #define FOP_COND_S(op, cond) \
3181 void helper_cmp_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3182 uint32_t fst1, int cc) \
3186 update_fcr31(env, GETPC()); \
3188 SET_FP_COND(cc, env->active_fpu); \
3190 CLEAR_FP_COND(cc, env->active_fpu); \
3192 void helper_cmpabs_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3193 uint32_t fst1, int cc) \
3196 fst0 = float32_abs(fst0); \
3197 fst1 = float32_abs(fst1); \
3199 update_fcr31(env, GETPC()); \
3201 SET_FP_COND(cc, env->active_fpu); \
3203 CLEAR_FP_COND(cc, env->active_fpu); \
3206 /* NOTE: the comma operator will make "cond" to eval to false,
3207 * but float32_unordered_quiet() is still called. */
3208 FOP_COND_S(f
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3209 FOP_COND_S(un
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
))
3210 FOP_COND_S(eq
, float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3211 FOP_COND_S(ueq
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3212 FOP_COND_S(olt
, float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3213 FOP_COND_S(ult
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3214 FOP_COND_S(ole
, float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3215 FOP_COND_S(ule
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3216 /* NOTE: the comma operator will make "cond" to eval to false,
3217 * but float32_unordered() is still called. */
3218 FOP_COND_S(sf
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3219 FOP_COND_S(ngle
,float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
))
3220 FOP_COND_S(seq
, float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3221 FOP_COND_S(ngl
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3222 FOP_COND_S(lt
, float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3223 FOP_COND_S(nge
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3224 FOP_COND_S(le
, float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3225 FOP_COND_S(ngt
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3227 #define FOP_COND_PS(op, condl, condh) \
3228 void helper_cmp_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3229 uint64_t fdt1, int cc) \
3231 uint32_t fst0, fsth0, fst1, fsth1; \
3233 fst0 = fdt0 & 0XFFFFFFFF; \
3234 fsth0 = fdt0 >> 32; \
3235 fst1 = fdt1 & 0XFFFFFFFF; \
3236 fsth1 = fdt1 >> 32; \
3239 update_fcr31(env, GETPC()); \
3241 SET_FP_COND(cc, env->active_fpu); \
3243 CLEAR_FP_COND(cc, env->active_fpu); \
3245 SET_FP_COND(cc + 1, env->active_fpu); \
3247 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3249 void helper_cmpabs_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3250 uint64_t fdt1, int cc) \
3252 uint32_t fst0, fsth0, fst1, fsth1; \
3254 fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
3255 fsth0 = float32_abs(fdt0 >> 32); \
3256 fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
3257 fsth1 = float32_abs(fdt1 >> 32); \
3260 update_fcr31(env, GETPC()); \
3262 SET_FP_COND(cc, env->active_fpu); \
3264 CLEAR_FP_COND(cc, env->active_fpu); \
3266 SET_FP_COND(cc + 1, env->active_fpu); \
3268 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3271 /* NOTE: the comma operator will make "cond" to eval to false,
3272 * but float32_unordered_quiet() is still called. */
3273 FOP_COND_PS(f
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
3274 (float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
3275 FOP_COND_PS(un
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
),
3276 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
3277 FOP_COND_PS(eq
, float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3278 float32_eq_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3279 FOP_COND_PS(ueq
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3280 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3281 FOP_COND_PS(olt
, float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3282 float32_lt_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3283 FOP_COND_PS(ult
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3284 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3285 FOP_COND_PS(ole
, float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3286 float32_le_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3287 FOP_COND_PS(ule
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3288 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3289 /* NOTE: the comma operator will make "cond" to eval to false,
3290 * but float32_unordered() is still called. */
3291 FOP_COND_PS(sf
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
3292 (float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
3293 FOP_COND_PS(ngle
,float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
),
3294 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
3295 FOP_COND_PS(seq
, float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3296 float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3297 FOP_COND_PS(ngl
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3298 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3299 FOP_COND_PS(lt
, float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3300 float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3301 FOP_COND_PS(nge
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3302 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3303 FOP_COND_PS(le
, float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3304 float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3305 FOP_COND_PS(ngt
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3306 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))