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 void helper_raise_exception_err(CPUMIPSState
*env
, uint32_t exception
,
40 if (exception
< 0x100)
41 qemu_log("%s: %d %d\n", __func__
, exception
, error_code
);
43 env
->exception_index
= exception
;
44 env
->error_code
= error_code
;
48 void helper_raise_exception(CPUMIPSState
*env
, uint32_t exception
)
50 helper_raise_exception_err(env
, exception
, 0);
53 #if !defined(CONFIG_USER_ONLY)
54 static void do_restore_state(CPUMIPSState
*env
, uintptr_t pc
)
60 cpu_restore_state(tb
, env
, pc
);
65 #if defined(CONFIG_USER_ONLY)
66 #define HELPER_LD(name, insn, type) \
67 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
70 return (type) insn##_raw(addr); \
73 #define HELPER_LD(name, insn, type) \
74 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
79 case 0: return (type) cpu_##insn##_kernel(env, addr); break; \
80 case 1: return (type) cpu_##insn##_super(env, addr); break; \
82 case 2: return (type) cpu_##insn##_user(env, addr); break; \
86 HELPER_LD(lbu
, ldub
, uint8_t)
87 HELPER_LD(lw
, ldl
, int32_t)
89 HELPER_LD(ld
, ldq
, int64_t)
93 #if defined(CONFIG_USER_ONLY)
94 #define HELPER_ST(name, insn, type) \
95 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
96 type val, int mem_idx) \
98 insn##_raw(addr, val); \
101 #define HELPER_ST(name, insn, type) \
102 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
103 type val, int mem_idx) \
107 case 0: cpu_##insn##_kernel(env, addr, val); break; \
108 case 1: cpu_##insn##_super(env, addr, val); break; \
110 case 2: cpu_##insn##_user(env, addr, val); break; \
114 HELPER_ST(sb
, stb
, uint8_t)
115 HELPER_ST(sw
, stl
, uint32_t)
117 HELPER_ST(sd
, stq
, uint64_t)
121 target_ulong
helper_clo (target_ulong arg1
)
126 target_ulong
helper_clz (target_ulong arg1
)
131 #if defined(TARGET_MIPS64)
132 target_ulong
helper_dclo (target_ulong arg1
)
137 target_ulong
helper_dclz (target_ulong arg1
)
141 #endif /* TARGET_MIPS64 */
143 /* 64 bits arithmetic for 32 bits hosts */
144 static inline uint64_t get_HILO(CPUMIPSState
*env
)
146 return ((uint64_t)(env
->active_tc
.HI
[0]) << 32) | (uint32_t)env
->active_tc
.LO
[0];
149 static inline target_ulong
set_HIT0_LO(CPUMIPSState
*env
, uint64_t HILO
)
152 env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
153 tmp
= env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
157 static inline target_ulong
set_HI_LOT0(CPUMIPSState
*env
, uint64_t HILO
)
159 target_ulong tmp
= env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
160 env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
164 /* Multiplication variants of the vr54xx. */
165 target_ulong
helper_muls(CPUMIPSState
*env
, target_ulong arg1
,
168 return set_HI_LOT0(env
, 0 - ((int64_t)(int32_t)arg1
*
169 (int64_t)(int32_t)arg2
));
172 target_ulong
helper_mulsu(CPUMIPSState
*env
, target_ulong arg1
,
175 return set_HI_LOT0(env
, 0 - (uint64_t)(uint32_t)arg1
*
176 (uint64_t)(uint32_t)arg2
);
179 target_ulong
helper_macc(CPUMIPSState
*env
, target_ulong arg1
,
182 return set_HI_LOT0(env
, (int64_t)get_HILO(env
) + (int64_t)(int32_t)arg1
*
183 (int64_t)(int32_t)arg2
);
186 target_ulong
helper_macchi(CPUMIPSState
*env
, target_ulong arg1
,
189 return set_HIT0_LO(env
, (int64_t)get_HILO(env
) + (int64_t)(int32_t)arg1
*
190 (int64_t)(int32_t)arg2
);
193 target_ulong
helper_maccu(CPUMIPSState
*env
, target_ulong arg1
,
196 return set_HI_LOT0(env
, (uint64_t)get_HILO(env
) +
197 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
200 target_ulong
helper_macchiu(CPUMIPSState
*env
, target_ulong arg1
,
203 return set_HIT0_LO(env
, (uint64_t)get_HILO(env
) +
204 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
207 target_ulong
helper_msac(CPUMIPSState
*env
, target_ulong arg1
,
210 return set_HI_LOT0(env
, (int64_t)get_HILO(env
) - (int64_t)(int32_t)arg1
*
211 (int64_t)(int32_t)arg2
);
214 target_ulong
helper_msachi(CPUMIPSState
*env
, target_ulong arg1
,
217 return set_HIT0_LO(env
, (int64_t)get_HILO(env
) - (int64_t)(int32_t)arg1
*
218 (int64_t)(int32_t)arg2
);
221 target_ulong
helper_msacu(CPUMIPSState
*env
, target_ulong arg1
,
224 return set_HI_LOT0(env
, (uint64_t)get_HILO(env
) -
225 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
228 target_ulong
helper_msachiu(CPUMIPSState
*env
, target_ulong arg1
,
231 return set_HIT0_LO(env
, (uint64_t)get_HILO(env
) -
232 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
235 target_ulong
helper_mulhi(CPUMIPSState
*env
, target_ulong arg1
,
238 return set_HIT0_LO(env
, (int64_t)(int32_t)arg1
* (int64_t)(int32_t)arg2
);
241 target_ulong
helper_mulhiu(CPUMIPSState
*env
, target_ulong arg1
,
244 return set_HIT0_LO(env
, (uint64_t)(uint32_t)arg1
*
245 (uint64_t)(uint32_t)arg2
);
248 target_ulong
helper_mulshi(CPUMIPSState
*env
, target_ulong arg1
,
251 return set_HIT0_LO(env
, 0 - (int64_t)(int32_t)arg1
*
252 (int64_t)(int32_t)arg2
);
255 target_ulong
helper_mulshiu(CPUMIPSState
*env
, target_ulong arg1
,
258 return set_HIT0_LO(env
, 0 - (uint64_t)(uint32_t)arg1
*
259 (uint64_t)(uint32_t)arg2
);
263 void helper_dmult(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
)
265 muls64(&(env
->active_tc
.LO
[0]), &(env
->active_tc
.HI
[0]), arg1
, arg2
);
268 void helper_dmultu(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
)
270 mulu64(&(env
->active_tc
.LO
[0]), &(env
->active_tc
.HI
[0]), arg1
, arg2
);
274 #ifndef CONFIG_USER_ONLY
276 static inline hwaddr
do_translate_address(CPUMIPSState
*env
,
277 target_ulong address
,
282 lladdr
= cpu_mips_translate_address(env
, address
, rw
);
284 if (lladdr
== -1LL) {
291 #define HELPER_LD_ATOMIC(name, insn) \
292 target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \
294 env->lladdr = do_translate_address(env, arg, 0); \
295 env->llval = do_##insn(env, arg, mem_idx); \
298 HELPER_LD_ATOMIC(ll
, lw
)
300 HELPER_LD_ATOMIC(lld
, ld
)
302 #undef HELPER_LD_ATOMIC
304 #define HELPER_ST_ATOMIC(name, ld_insn, st_insn, almask) \
305 target_ulong helper_##name(CPUMIPSState *env, target_ulong arg1, \
306 target_ulong arg2, int mem_idx) \
310 if (arg2 & almask) { \
311 env->CP0_BadVAddr = arg2; \
312 helper_raise_exception(env, EXCP_AdES); \
314 if (do_translate_address(env, arg2, 1) == env->lladdr) { \
315 tmp = do_##ld_insn(env, arg2, mem_idx); \
316 if (tmp == env->llval) { \
317 do_##st_insn(env, arg2, arg1, mem_idx); \
323 HELPER_ST_ATOMIC(sc
, lw
, sw
, 0x3)
325 HELPER_ST_ATOMIC(scd
, ld
, sd
, 0x7)
327 #undef HELPER_ST_ATOMIC
330 #ifdef TARGET_WORDS_BIGENDIAN
331 #define GET_LMASK(v) ((v) & 3)
332 #define GET_OFFSET(addr, offset) (addr + (offset))
334 #define GET_LMASK(v) (((v) & 3) ^ 3)
335 #define GET_OFFSET(addr, offset) (addr - (offset))
338 target_ulong
helper_lwl(CPUMIPSState
*env
, target_ulong arg1
,
339 target_ulong arg2
, int mem_idx
)
343 tmp
= do_lbu(env
, arg2
, mem_idx
);
344 arg1
= (arg1
& 0x00FFFFFF) | (tmp
<< 24);
346 if (GET_LMASK(arg2
) <= 2) {
347 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 1), mem_idx
);
348 arg1
= (arg1
& 0xFF00FFFF) | (tmp
<< 16);
351 if (GET_LMASK(arg2
) <= 1) {
352 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 2), mem_idx
);
353 arg1
= (arg1
& 0xFFFF00FF) | (tmp
<< 8);
356 if (GET_LMASK(arg2
) == 0) {
357 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 3), mem_idx
);
358 arg1
= (arg1
& 0xFFFFFF00) | tmp
;
360 return (int32_t)arg1
;
363 target_ulong
helper_lwr(CPUMIPSState
*env
, target_ulong arg1
,
364 target_ulong arg2
, int mem_idx
)
368 tmp
= do_lbu(env
, arg2
, mem_idx
);
369 arg1
= (arg1
& 0xFFFFFF00) | tmp
;
371 if (GET_LMASK(arg2
) >= 1) {
372 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -1), mem_idx
);
373 arg1
= (arg1
& 0xFFFF00FF) | (tmp
<< 8);
376 if (GET_LMASK(arg2
) >= 2) {
377 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -2), mem_idx
);
378 arg1
= (arg1
& 0xFF00FFFF) | (tmp
<< 16);
381 if (GET_LMASK(arg2
) == 3) {
382 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -3), mem_idx
);
383 arg1
= (arg1
& 0x00FFFFFF) | (tmp
<< 24);
385 return (int32_t)arg1
;
388 void helper_swl(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
391 do_sb(env
, arg2
, (uint8_t)(arg1
>> 24), mem_idx
);
393 if (GET_LMASK(arg2
) <= 2)
394 do_sb(env
, GET_OFFSET(arg2
, 1), (uint8_t)(arg1
>> 16), mem_idx
);
396 if (GET_LMASK(arg2
) <= 1)
397 do_sb(env
, GET_OFFSET(arg2
, 2), (uint8_t)(arg1
>> 8), mem_idx
);
399 if (GET_LMASK(arg2
) == 0)
400 do_sb(env
, GET_OFFSET(arg2
, 3), (uint8_t)arg1
, mem_idx
);
403 void helper_swr(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
406 do_sb(env
, arg2
, (uint8_t)arg1
, mem_idx
);
408 if (GET_LMASK(arg2
) >= 1)
409 do_sb(env
, GET_OFFSET(arg2
, -1), (uint8_t)(arg1
>> 8), mem_idx
);
411 if (GET_LMASK(arg2
) >= 2)
412 do_sb(env
, GET_OFFSET(arg2
, -2), (uint8_t)(arg1
>> 16), mem_idx
);
414 if (GET_LMASK(arg2
) == 3)
415 do_sb(env
, GET_OFFSET(arg2
, -3), (uint8_t)(arg1
>> 24), mem_idx
);
418 #if defined(TARGET_MIPS64)
419 /* "half" load and stores. We must do the memory access inline,
420 or fault handling won't work. */
422 #ifdef TARGET_WORDS_BIGENDIAN
423 #define GET_LMASK64(v) ((v) & 7)
425 #define GET_LMASK64(v) (((v) & 7) ^ 7)
428 target_ulong
helper_ldl(CPUMIPSState
*env
, target_ulong arg1
,
429 target_ulong arg2
, int mem_idx
)
433 tmp
= do_lbu(env
, arg2
, mem_idx
);
434 arg1
= (arg1
& 0x00FFFFFFFFFFFFFFULL
) | (tmp
<< 56);
436 if (GET_LMASK64(arg2
) <= 6) {
437 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 1), mem_idx
);
438 arg1
= (arg1
& 0xFF00FFFFFFFFFFFFULL
) | (tmp
<< 48);
441 if (GET_LMASK64(arg2
) <= 5) {
442 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 2), mem_idx
);
443 arg1
= (arg1
& 0xFFFF00FFFFFFFFFFULL
) | (tmp
<< 40);
446 if (GET_LMASK64(arg2
) <= 4) {
447 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 3), mem_idx
);
448 arg1
= (arg1
& 0xFFFFFF00FFFFFFFFULL
) | (tmp
<< 32);
451 if (GET_LMASK64(arg2
) <= 3) {
452 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 4), mem_idx
);
453 arg1
= (arg1
& 0xFFFFFFFF00FFFFFFULL
) | (tmp
<< 24);
456 if (GET_LMASK64(arg2
) <= 2) {
457 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 5), mem_idx
);
458 arg1
= (arg1
& 0xFFFFFFFFFF00FFFFULL
) | (tmp
<< 16);
461 if (GET_LMASK64(arg2
) <= 1) {
462 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 6), mem_idx
);
463 arg1
= (arg1
& 0xFFFFFFFFFFFF00FFULL
) | (tmp
<< 8);
466 if (GET_LMASK64(arg2
) == 0) {
467 tmp
= do_lbu(env
, GET_OFFSET(arg2
, 7), mem_idx
);
468 arg1
= (arg1
& 0xFFFFFFFFFFFFFF00ULL
) | tmp
;
474 target_ulong
helper_ldr(CPUMIPSState
*env
, target_ulong arg1
,
475 target_ulong arg2
, int mem_idx
)
479 tmp
= do_lbu(env
, arg2
, mem_idx
);
480 arg1
= (arg1
& 0xFFFFFFFFFFFFFF00ULL
) | tmp
;
482 if (GET_LMASK64(arg2
) >= 1) {
483 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -1), mem_idx
);
484 arg1
= (arg1
& 0xFFFFFFFFFFFF00FFULL
) | (tmp
<< 8);
487 if (GET_LMASK64(arg2
) >= 2) {
488 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -2), mem_idx
);
489 arg1
= (arg1
& 0xFFFFFFFFFF00FFFFULL
) | (tmp
<< 16);
492 if (GET_LMASK64(arg2
) >= 3) {
493 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -3), mem_idx
);
494 arg1
= (arg1
& 0xFFFFFFFF00FFFFFFULL
) | (tmp
<< 24);
497 if (GET_LMASK64(arg2
) >= 4) {
498 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -4), mem_idx
);
499 arg1
= (arg1
& 0xFFFFFF00FFFFFFFFULL
) | (tmp
<< 32);
502 if (GET_LMASK64(arg2
) >= 5) {
503 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -5), mem_idx
);
504 arg1
= (arg1
& 0xFFFF00FFFFFFFFFFULL
) | (tmp
<< 40);
507 if (GET_LMASK64(arg2
) >= 6) {
508 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -6), mem_idx
);
509 arg1
= (arg1
& 0xFF00FFFFFFFFFFFFULL
) | (tmp
<< 48);
512 if (GET_LMASK64(arg2
) == 7) {
513 tmp
= do_lbu(env
, GET_OFFSET(arg2
, -7), mem_idx
);
514 arg1
= (arg1
& 0x00FFFFFFFFFFFFFFULL
) | (tmp
<< 56);
520 void helper_sdl(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
523 do_sb(env
, arg2
, (uint8_t)(arg1
>> 56), mem_idx
);
525 if (GET_LMASK64(arg2
) <= 6)
526 do_sb(env
, GET_OFFSET(arg2
, 1), (uint8_t)(arg1
>> 48), mem_idx
);
528 if (GET_LMASK64(arg2
) <= 5)
529 do_sb(env
, GET_OFFSET(arg2
, 2), (uint8_t)(arg1
>> 40), mem_idx
);
531 if (GET_LMASK64(arg2
) <= 4)
532 do_sb(env
, GET_OFFSET(arg2
, 3), (uint8_t)(arg1
>> 32), mem_idx
);
534 if (GET_LMASK64(arg2
) <= 3)
535 do_sb(env
, GET_OFFSET(arg2
, 4), (uint8_t)(arg1
>> 24), mem_idx
);
537 if (GET_LMASK64(arg2
) <= 2)
538 do_sb(env
, GET_OFFSET(arg2
, 5), (uint8_t)(arg1
>> 16), mem_idx
);
540 if (GET_LMASK64(arg2
) <= 1)
541 do_sb(env
, GET_OFFSET(arg2
, 6), (uint8_t)(arg1
>> 8), mem_idx
);
543 if (GET_LMASK64(arg2
) <= 0)
544 do_sb(env
, GET_OFFSET(arg2
, 7), (uint8_t)arg1
, mem_idx
);
547 void helper_sdr(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
550 do_sb(env
, arg2
, (uint8_t)arg1
, mem_idx
);
552 if (GET_LMASK64(arg2
) >= 1)
553 do_sb(env
, GET_OFFSET(arg2
, -1), (uint8_t)(arg1
>> 8), mem_idx
);
555 if (GET_LMASK64(arg2
) >= 2)
556 do_sb(env
, GET_OFFSET(arg2
, -2), (uint8_t)(arg1
>> 16), mem_idx
);
558 if (GET_LMASK64(arg2
) >= 3)
559 do_sb(env
, GET_OFFSET(arg2
, -3), (uint8_t)(arg1
>> 24), mem_idx
);
561 if (GET_LMASK64(arg2
) >= 4)
562 do_sb(env
, GET_OFFSET(arg2
, -4), (uint8_t)(arg1
>> 32), mem_idx
);
564 if (GET_LMASK64(arg2
) >= 5)
565 do_sb(env
, GET_OFFSET(arg2
, -5), (uint8_t)(arg1
>> 40), mem_idx
);
567 if (GET_LMASK64(arg2
) >= 6)
568 do_sb(env
, GET_OFFSET(arg2
, -6), (uint8_t)(arg1
>> 48), mem_idx
);
570 if (GET_LMASK64(arg2
) == 7)
571 do_sb(env
, GET_OFFSET(arg2
, -7), (uint8_t)(arg1
>> 56), mem_idx
);
573 #endif /* TARGET_MIPS64 */
575 static const int multiple_regs
[] = { 16, 17, 18, 19, 20, 21, 22, 23, 30 };
577 void helper_lwm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
580 target_ulong base_reglist
= reglist
& 0xf;
581 target_ulong do_r31
= reglist
& 0x10;
582 #ifdef CONFIG_USER_ONLY
584 #define ldfun(env, addr) ldl_raw(addr)
586 uint32_t (*ldfun
)(CPUMIPSState
*env
, target_ulong
);
590 case 0: ldfun
= cpu_ldl_kernel
; break;
591 case 1: ldfun
= cpu_ldl_super
; break;
593 case 2: ldfun
= cpu_ldl_user
; break;
597 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
600 for (i
= 0; i
< base_reglist
; i
++) {
601 env
->active_tc
.gpr
[multiple_regs
[i
]] = (target_long
)ldfun(env
, addr
);
607 env
->active_tc
.gpr
[31] = (target_long
)ldfun(env
, addr
);
611 void helper_swm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
614 target_ulong base_reglist
= reglist
& 0xf;
615 target_ulong do_r31
= reglist
& 0x10;
616 #ifdef CONFIG_USER_ONLY
618 #define stfun(env, addr, val) stl_raw(addr, val)
620 void (*stfun
)(CPUMIPSState
*env
, target_ulong
, uint32_t);
624 case 0: stfun
= cpu_stl_kernel
; break;
625 case 1: stfun
= cpu_stl_super
; break;
627 case 2: stfun
= cpu_stl_user
; break;
631 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
634 for (i
= 0; i
< base_reglist
; i
++) {
635 stfun(env
, addr
, env
->active_tc
.gpr
[multiple_regs
[i
]]);
641 stfun(env
, addr
, env
->active_tc
.gpr
[31]);
645 #if defined(TARGET_MIPS64)
646 void helper_ldm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
649 target_ulong base_reglist
= reglist
& 0xf;
650 target_ulong do_r31
= reglist
& 0x10;
651 #ifdef CONFIG_USER_ONLY
653 #define ldfun(env, addr) ldq_raw(addr)
655 uint64_t (*ldfun
)(CPUMIPSState
*env
, target_ulong
);
659 case 0: ldfun
= cpu_ldq_kernel
; break;
660 case 1: ldfun
= cpu_ldq_super
; break;
662 case 2: ldfun
= cpu_ldq_user
; break;
666 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
669 for (i
= 0; i
< base_reglist
; i
++) {
670 env
->active_tc
.gpr
[multiple_regs
[i
]] = ldfun(env
, addr
);
676 env
->active_tc
.gpr
[31] = ldfun(env
, addr
);
680 void helper_sdm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
683 target_ulong base_reglist
= reglist
& 0xf;
684 target_ulong do_r31
= reglist
& 0x10;
685 #ifdef CONFIG_USER_ONLY
687 #define stfun(env, addr, val) stq_raw(addr, val)
689 void (*stfun
)(CPUMIPSState
*env
, target_ulong
, uint64_t);
693 case 0: stfun
= cpu_stq_kernel
; break;
694 case 1: stfun
= cpu_stq_super
; break;
696 case 2: stfun
= cpu_stq_user
; break;
700 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
703 for (i
= 0; i
< base_reglist
; i
++) {
704 stfun(env
, addr
, env
->active_tc
.gpr
[multiple_regs
[i
]]);
710 stfun(env
, addr
, env
->active_tc
.gpr
[31]);
715 #ifndef CONFIG_USER_ONLY
717 static bool mips_vpe_is_wfi(MIPSCPU
*c
)
719 CPUMIPSState
*env
= &c
->env
;
721 /* If the VPE is halted but otherwise active, it means it's waiting for
723 return env
->halted
&& mips_vpe_active(env
);
726 static inline void mips_vpe_wake(CPUMIPSState
*c
)
728 /* Dont set ->halted = 0 directly, let it be done via cpu_has_work
729 because there might be other conditions that state that c should
731 cpu_interrupt(c
, CPU_INTERRUPT_WAKE
);
734 static inline void mips_vpe_sleep(MIPSCPU
*cpu
)
736 CPUMIPSState
*c
= &cpu
->env
;
738 /* The VPE was shut off, really go to bed.
739 Reset any old _WAKE requests. */
741 cpu_reset_interrupt(c
, CPU_INTERRUPT_WAKE
);
744 static inline void mips_tc_wake(MIPSCPU
*cpu
, int tc
)
746 CPUMIPSState
*c
= &cpu
->env
;
748 /* FIXME: TC reschedule. */
749 if (mips_vpe_active(c
) && !mips_vpe_is_wfi(cpu
)) {
754 static inline void mips_tc_sleep(MIPSCPU
*cpu
, int tc
)
756 CPUMIPSState
*c
= &cpu
->env
;
758 /* FIXME: TC reschedule. */
759 if (!mips_vpe_active(c
)) {
764 /* tc should point to an int with the value of the global TC index.
765 This function will transform it into a local index within the
766 returned CPUMIPSState.
768 FIXME: This code assumes that all VPEs have the same number of TCs,
769 which depends on runtime setup. Can probably be fixed by
770 walking the list of CPUMIPSStates. */
771 static CPUMIPSState
*mips_cpu_map_tc(CPUMIPSState
*env
, int *tc
)
774 int vpe_idx
, nr_threads
= env
->nr_threads
;
777 if (!(env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))) {
778 /* Not allowed to address other CPUs. */
779 *tc
= env
->current_tc
;
783 vpe_idx
= tc_idx
/ nr_threads
;
784 *tc
= tc_idx
% nr_threads
;
785 other
= qemu_get_cpu(vpe_idx
);
786 return other
? other
: env
;
789 /* The per VPE CP0_Status register shares some fields with the per TC
790 CP0_TCStatus registers. These fields are wired to the same registers,
791 so changes to either of them should be reflected on both registers.
793 Also, EntryHi shares the bottom 8 bit ASID with TCStauts.
795 These helper call synchronizes the regs for a given cpu. */
797 /* Called for updates to CP0_Status. */
798 static void sync_c0_status(CPUMIPSState
*env
, CPUMIPSState
*cpu
, int tc
)
800 int32_t tcstatus
, *tcst
;
801 uint32_t v
= cpu
->CP0_Status
;
802 uint32_t cu
, mx
, asid
, ksu
;
803 uint32_t mask
= ((1 << CP0TCSt_TCU3
)
804 | (1 << CP0TCSt_TCU2
)
805 | (1 << CP0TCSt_TCU1
)
806 | (1 << CP0TCSt_TCU0
)
808 | (3 << CP0TCSt_TKSU
)
809 | (0xff << CP0TCSt_TASID
));
811 cu
= (v
>> CP0St_CU0
) & 0xf;
812 mx
= (v
>> CP0St_MX
) & 0x1;
813 ksu
= (v
>> CP0St_KSU
) & 0x3;
814 asid
= env
->CP0_EntryHi
& 0xff;
816 tcstatus
= cu
<< CP0TCSt_TCU0
;
817 tcstatus
|= mx
<< CP0TCSt_TMX
;
818 tcstatus
|= ksu
<< CP0TCSt_TKSU
;
821 if (tc
== cpu
->current_tc
) {
822 tcst
= &cpu
->active_tc
.CP0_TCStatus
;
824 tcst
= &cpu
->tcs
[tc
].CP0_TCStatus
;
832 /* Called for updates to CP0_TCStatus. */
833 static void sync_c0_tcstatus(CPUMIPSState
*cpu
, int tc
,
837 uint32_t tcu
, tmx
, tasid
, tksu
;
838 uint32_t mask
= ((1 << CP0St_CU3
)
845 tcu
= (v
>> CP0TCSt_TCU0
) & 0xf;
846 tmx
= (v
>> CP0TCSt_TMX
) & 0x1;
848 tksu
= (v
>> CP0TCSt_TKSU
) & 0x3;
850 status
= tcu
<< CP0St_CU0
;
851 status
|= tmx
<< CP0St_MX
;
852 status
|= tksu
<< CP0St_KSU
;
854 cpu
->CP0_Status
&= ~mask
;
855 cpu
->CP0_Status
|= status
;
857 /* Sync the TASID with EntryHi. */
858 cpu
->CP0_EntryHi
&= ~0xff;
859 cpu
->CP0_EntryHi
= tasid
;
864 /* Called for updates to CP0_EntryHi. */
865 static void sync_c0_entryhi(CPUMIPSState
*cpu
, int tc
)
868 uint32_t asid
, v
= cpu
->CP0_EntryHi
;
872 if (tc
== cpu
->current_tc
) {
873 tcst
= &cpu
->active_tc
.CP0_TCStatus
;
875 tcst
= &cpu
->tcs
[tc
].CP0_TCStatus
;
883 target_ulong
helper_mfc0_mvpcontrol(CPUMIPSState
*env
)
885 return env
->mvp
->CP0_MVPControl
;
888 target_ulong
helper_mfc0_mvpconf0(CPUMIPSState
*env
)
890 return env
->mvp
->CP0_MVPConf0
;
893 target_ulong
helper_mfc0_mvpconf1(CPUMIPSState
*env
)
895 return env
->mvp
->CP0_MVPConf1
;
898 target_ulong
helper_mfc0_random(CPUMIPSState
*env
)
900 return (int32_t)cpu_mips_get_random(env
);
903 target_ulong
helper_mfc0_tcstatus(CPUMIPSState
*env
)
905 return env
->active_tc
.CP0_TCStatus
;
908 target_ulong
helper_mftc0_tcstatus(CPUMIPSState
*env
)
910 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
911 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
913 if (other_tc
== other
->current_tc
)
914 return other
->active_tc
.CP0_TCStatus
;
916 return other
->tcs
[other_tc
].CP0_TCStatus
;
919 target_ulong
helper_mfc0_tcbind(CPUMIPSState
*env
)
921 return env
->active_tc
.CP0_TCBind
;
924 target_ulong
helper_mftc0_tcbind(CPUMIPSState
*env
)
926 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
927 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
929 if (other_tc
== other
->current_tc
)
930 return other
->active_tc
.CP0_TCBind
;
932 return other
->tcs
[other_tc
].CP0_TCBind
;
935 target_ulong
helper_mfc0_tcrestart(CPUMIPSState
*env
)
937 return env
->active_tc
.PC
;
940 target_ulong
helper_mftc0_tcrestart(CPUMIPSState
*env
)
942 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
943 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
945 if (other_tc
== other
->current_tc
)
946 return other
->active_tc
.PC
;
948 return other
->tcs
[other_tc
].PC
;
951 target_ulong
helper_mfc0_tchalt(CPUMIPSState
*env
)
953 return env
->active_tc
.CP0_TCHalt
;
956 target_ulong
helper_mftc0_tchalt(CPUMIPSState
*env
)
958 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
959 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
961 if (other_tc
== other
->current_tc
)
962 return other
->active_tc
.CP0_TCHalt
;
964 return other
->tcs
[other_tc
].CP0_TCHalt
;
967 target_ulong
helper_mfc0_tccontext(CPUMIPSState
*env
)
969 return env
->active_tc
.CP0_TCContext
;
972 target_ulong
helper_mftc0_tccontext(CPUMIPSState
*env
)
974 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
975 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
977 if (other_tc
== other
->current_tc
)
978 return other
->active_tc
.CP0_TCContext
;
980 return other
->tcs
[other_tc
].CP0_TCContext
;
983 target_ulong
helper_mfc0_tcschedule(CPUMIPSState
*env
)
985 return env
->active_tc
.CP0_TCSchedule
;
988 target_ulong
helper_mftc0_tcschedule(CPUMIPSState
*env
)
990 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
991 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
993 if (other_tc
== other
->current_tc
)
994 return other
->active_tc
.CP0_TCSchedule
;
996 return other
->tcs
[other_tc
].CP0_TCSchedule
;
999 target_ulong
helper_mfc0_tcschefback(CPUMIPSState
*env
)
1001 return env
->active_tc
.CP0_TCScheFBack
;
1004 target_ulong
helper_mftc0_tcschefback(CPUMIPSState
*env
)
1006 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1007 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1009 if (other_tc
== other
->current_tc
)
1010 return other
->active_tc
.CP0_TCScheFBack
;
1012 return other
->tcs
[other_tc
].CP0_TCScheFBack
;
1015 target_ulong
helper_mfc0_count(CPUMIPSState
*env
)
1017 return (int32_t)cpu_mips_get_count(env
);
1020 target_ulong
helper_mftc0_entryhi(CPUMIPSState
*env
)
1022 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1023 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1025 return other
->CP0_EntryHi
;
1028 target_ulong
helper_mftc0_cause(CPUMIPSState
*env
)
1030 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1032 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1034 if (other_tc
== other
->current_tc
) {
1035 tccause
= other
->CP0_Cause
;
1037 tccause
= other
->CP0_Cause
;
1043 target_ulong
helper_mftc0_status(CPUMIPSState
*env
)
1045 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1046 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1048 return other
->CP0_Status
;
1051 target_ulong
helper_mfc0_lladdr(CPUMIPSState
*env
)
1053 return (int32_t)(env
->lladdr
>> env
->CP0_LLAddr_shift
);
1056 target_ulong
helper_mfc0_watchlo(CPUMIPSState
*env
, uint32_t sel
)
1058 return (int32_t)env
->CP0_WatchLo
[sel
];
1061 target_ulong
helper_mfc0_watchhi(CPUMIPSState
*env
, uint32_t sel
)
1063 return env
->CP0_WatchHi
[sel
];
1066 target_ulong
helper_mfc0_debug(CPUMIPSState
*env
)
1068 target_ulong t0
= env
->CP0_Debug
;
1069 if (env
->hflags
& MIPS_HFLAG_DM
)
1070 t0
|= 1 << CP0DB_DM
;
1075 target_ulong
helper_mftc0_debug(CPUMIPSState
*env
)
1077 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1079 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1081 if (other_tc
== other
->current_tc
)
1082 tcstatus
= other
->active_tc
.CP0_Debug_tcstatus
;
1084 tcstatus
= other
->tcs
[other_tc
].CP0_Debug_tcstatus
;
1086 /* XXX: Might be wrong, check with EJTAG spec. */
1087 return (other
->CP0_Debug
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
1088 (tcstatus
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
1091 #if defined(TARGET_MIPS64)
1092 target_ulong
helper_dmfc0_tcrestart(CPUMIPSState
*env
)
1094 return env
->active_tc
.PC
;
1097 target_ulong
helper_dmfc0_tchalt(CPUMIPSState
*env
)
1099 return env
->active_tc
.CP0_TCHalt
;
1102 target_ulong
helper_dmfc0_tccontext(CPUMIPSState
*env
)
1104 return env
->active_tc
.CP0_TCContext
;
1107 target_ulong
helper_dmfc0_tcschedule(CPUMIPSState
*env
)
1109 return env
->active_tc
.CP0_TCSchedule
;
1112 target_ulong
helper_dmfc0_tcschefback(CPUMIPSState
*env
)
1114 return env
->active_tc
.CP0_TCScheFBack
;
1117 target_ulong
helper_dmfc0_lladdr(CPUMIPSState
*env
)
1119 return env
->lladdr
>> env
->CP0_LLAddr_shift
;
1122 target_ulong
helper_dmfc0_watchlo(CPUMIPSState
*env
, uint32_t sel
)
1124 return env
->CP0_WatchLo
[sel
];
1126 #endif /* TARGET_MIPS64 */
1128 void helper_mtc0_index(CPUMIPSState
*env
, target_ulong arg1
)
1131 unsigned int tmp
= env
->tlb
->nb_tlb
;
1137 env
->CP0_Index
= (env
->CP0_Index
& 0x80000000) | (arg1
& (num
- 1));
1140 void helper_mtc0_mvpcontrol(CPUMIPSState
*env
, target_ulong arg1
)
1145 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))
1146 mask
|= (1 << CP0MVPCo_CPA
) | (1 << CP0MVPCo_VPC
) |
1147 (1 << CP0MVPCo_EVP
);
1148 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1149 mask
|= (1 << CP0MVPCo_STLB
);
1150 newval
= (env
->mvp
->CP0_MVPControl
& ~mask
) | (arg1
& mask
);
1152 // TODO: Enable/disable shared TLB, enable/disable VPEs.
1154 env
->mvp
->CP0_MVPControl
= newval
;
1157 void helper_mtc0_vpecontrol(CPUMIPSState
*env
, target_ulong arg1
)
1162 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
1163 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
1164 newval
= (env
->CP0_VPEControl
& ~mask
) | (arg1
& mask
);
1166 /* Yield scheduler intercept not implemented. */
1167 /* Gating storage scheduler intercept not implemented. */
1169 // TODO: Enable/disable TCs.
1171 env
->CP0_VPEControl
= newval
;
1174 void helper_mttc0_vpecontrol(CPUMIPSState
*env
, target_ulong arg1
)
1176 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1177 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1181 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
1182 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
1183 newval
= (other
->CP0_VPEControl
& ~mask
) | (arg1
& mask
);
1185 /* TODO: Enable/disable TCs. */
1187 other
->CP0_VPEControl
= newval
;
1190 target_ulong
helper_mftc0_vpecontrol(CPUMIPSState
*env
)
1192 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1193 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1194 /* FIXME: Mask away return zero on read bits. */
1195 return other
->CP0_VPEControl
;
1198 target_ulong
helper_mftc0_vpeconf0(CPUMIPSState
*env
)
1200 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1201 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1203 return other
->CP0_VPEConf0
;
1206 void helper_mtc0_vpeconf0(CPUMIPSState
*env
, target_ulong arg1
)
1211 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) {
1212 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_VPA
))
1213 mask
|= (0xff << CP0VPEC0_XTC
);
1214 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
1216 newval
= (env
->CP0_VPEConf0
& ~mask
) | (arg1
& mask
);
1218 // TODO: TC exclusive handling due to ERL/EXL.
1220 env
->CP0_VPEConf0
= newval
;
1223 void helper_mttc0_vpeconf0(CPUMIPSState
*env
, target_ulong arg1
)
1225 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1226 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1230 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
1231 newval
= (other
->CP0_VPEConf0
& ~mask
) | (arg1
& mask
);
1233 /* TODO: TC exclusive handling due to ERL/EXL. */
1234 other
->CP0_VPEConf0
= newval
;
1237 void helper_mtc0_vpeconf1(CPUMIPSState
*env
, target_ulong arg1
)
1242 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1243 mask
|= (0xff << CP0VPEC1_NCX
) | (0xff << CP0VPEC1_NCP2
) |
1244 (0xff << CP0VPEC1_NCP1
);
1245 newval
= (env
->CP0_VPEConf1
& ~mask
) | (arg1
& mask
);
1247 /* UDI not implemented. */
1248 /* CP2 not implemented. */
1250 // TODO: Handle FPU (CP1) binding.
1252 env
->CP0_VPEConf1
= newval
;
1255 void helper_mtc0_yqmask(CPUMIPSState
*env
, target_ulong arg1
)
1257 /* Yield qualifier inputs not implemented. */
1258 env
->CP0_YQMask
= 0x00000000;
1261 void helper_mtc0_vpeopt(CPUMIPSState
*env
, target_ulong arg1
)
1263 env
->CP0_VPEOpt
= arg1
& 0x0000ffff;
1266 void helper_mtc0_entrylo0(CPUMIPSState
*env
, target_ulong arg1
)
1268 /* Large physaddr (PABITS) not implemented */
1269 /* 1k pages not implemented */
1270 env
->CP0_EntryLo0
= arg1
& 0x3FFFFFFF;
1273 void helper_mtc0_tcstatus(CPUMIPSState
*env
, target_ulong arg1
)
1275 uint32_t mask
= env
->CP0_TCStatus_rw_bitmask
;
1278 newval
= (env
->active_tc
.CP0_TCStatus
& ~mask
) | (arg1
& mask
);
1280 env
->active_tc
.CP0_TCStatus
= newval
;
1281 sync_c0_tcstatus(env
, env
->current_tc
, newval
);
1284 void helper_mttc0_tcstatus(CPUMIPSState
*env
, target_ulong arg1
)
1286 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1287 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1289 if (other_tc
== other
->current_tc
)
1290 other
->active_tc
.CP0_TCStatus
= arg1
;
1292 other
->tcs
[other_tc
].CP0_TCStatus
= arg1
;
1293 sync_c0_tcstatus(other
, other_tc
, arg1
);
1296 void helper_mtc0_tcbind(CPUMIPSState
*env
, target_ulong arg1
)
1298 uint32_t mask
= (1 << CP0TCBd_TBE
);
1301 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1302 mask
|= (1 << CP0TCBd_CurVPE
);
1303 newval
= (env
->active_tc
.CP0_TCBind
& ~mask
) | (arg1
& mask
);
1304 env
->active_tc
.CP0_TCBind
= newval
;
1307 void helper_mttc0_tcbind(CPUMIPSState
*env
, target_ulong arg1
)
1309 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1310 uint32_t mask
= (1 << CP0TCBd_TBE
);
1312 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1314 if (other
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1315 mask
|= (1 << CP0TCBd_CurVPE
);
1316 if (other_tc
== other
->current_tc
) {
1317 newval
= (other
->active_tc
.CP0_TCBind
& ~mask
) | (arg1
& mask
);
1318 other
->active_tc
.CP0_TCBind
= newval
;
1320 newval
= (other
->tcs
[other_tc
].CP0_TCBind
& ~mask
) | (arg1
& mask
);
1321 other
->tcs
[other_tc
].CP0_TCBind
= newval
;
1325 void helper_mtc0_tcrestart(CPUMIPSState
*env
, target_ulong arg1
)
1327 env
->active_tc
.PC
= arg1
;
1328 env
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1330 /* MIPS16 not implemented. */
1333 void helper_mttc0_tcrestart(CPUMIPSState
*env
, target_ulong arg1
)
1335 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1336 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1338 if (other_tc
== other
->current_tc
) {
1339 other
->active_tc
.PC
= arg1
;
1340 other
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1341 other
->lladdr
= 0ULL;
1342 /* MIPS16 not implemented. */
1344 other
->tcs
[other_tc
].PC
= arg1
;
1345 other
->tcs
[other_tc
].CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1346 other
->lladdr
= 0ULL;
1347 /* MIPS16 not implemented. */
1351 void helper_mtc0_tchalt(CPUMIPSState
*env
, target_ulong arg1
)
1353 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
1355 env
->active_tc
.CP0_TCHalt
= arg1
& 0x1;
1357 // TODO: Halt TC / Restart (if allocated+active) TC.
1358 if (env
->active_tc
.CP0_TCHalt
& 1) {
1359 mips_tc_sleep(cpu
, env
->current_tc
);
1361 mips_tc_wake(cpu
, env
->current_tc
);
1365 void helper_mttc0_tchalt(CPUMIPSState
*env
, target_ulong arg1
)
1367 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1368 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1369 MIPSCPU
*other_cpu
= mips_env_get_cpu(other
);
1371 // TODO: Halt TC / Restart (if allocated+active) TC.
1373 if (other_tc
== other
->current_tc
)
1374 other
->active_tc
.CP0_TCHalt
= arg1
;
1376 other
->tcs
[other_tc
].CP0_TCHalt
= arg1
;
1379 mips_tc_sleep(other_cpu
, other_tc
);
1381 mips_tc_wake(other_cpu
, other_tc
);
1385 void helper_mtc0_tccontext(CPUMIPSState
*env
, target_ulong arg1
)
1387 env
->active_tc
.CP0_TCContext
= arg1
;
1390 void helper_mttc0_tccontext(CPUMIPSState
*env
, target_ulong arg1
)
1392 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1393 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1395 if (other_tc
== other
->current_tc
)
1396 other
->active_tc
.CP0_TCContext
= arg1
;
1398 other
->tcs
[other_tc
].CP0_TCContext
= arg1
;
1401 void helper_mtc0_tcschedule(CPUMIPSState
*env
, target_ulong arg1
)
1403 env
->active_tc
.CP0_TCSchedule
= arg1
;
1406 void helper_mttc0_tcschedule(CPUMIPSState
*env
, target_ulong arg1
)
1408 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1409 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1411 if (other_tc
== other
->current_tc
)
1412 other
->active_tc
.CP0_TCSchedule
= arg1
;
1414 other
->tcs
[other_tc
].CP0_TCSchedule
= arg1
;
1417 void helper_mtc0_tcschefback(CPUMIPSState
*env
, target_ulong arg1
)
1419 env
->active_tc
.CP0_TCScheFBack
= arg1
;
1422 void helper_mttc0_tcschefback(CPUMIPSState
*env
, target_ulong arg1
)
1424 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1425 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1427 if (other_tc
== other
->current_tc
)
1428 other
->active_tc
.CP0_TCScheFBack
= arg1
;
1430 other
->tcs
[other_tc
].CP0_TCScheFBack
= arg1
;
1433 void helper_mtc0_entrylo1(CPUMIPSState
*env
, target_ulong arg1
)
1435 /* Large physaddr (PABITS) not implemented */
1436 /* 1k pages not implemented */
1437 env
->CP0_EntryLo1
= arg1
& 0x3FFFFFFF;
1440 void helper_mtc0_context(CPUMIPSState
*env
, target_ulong arg1
)
1442 env
->CP0_Context
= (env
->CP0_Context
& 0x007FFFFF) | (arg1
& ~0x007FFFFF);
1445 void helper_mtc0_pagemask(CPUMIPSState
*env
, target_ulong arg1
)
1447 /* 1k pages not implemented */
1448 env
->CP0_PageMask
= arg1
& (0x1FFFFFFF & (TARGET_PAGE_MASK
<< 1));
1451 void helper_mtc0_pagegrain(CPUMIPSState
*env
, target_ulong arg1
)
1453 /* SmartMIPS not implemented */
1454 /* Large physaddr (PABITS) not implemented */
1455 /* 1k pages not implemented */
1456 env
->CP0_PageGrain
= 0;
1459 void helper_mtc0_wired(CPUMIPSState
*env
, target_ulong arg1
)
1461 env
->CP0_Wired
= arg1
% env
->tlb
->nb_tlb
;
1464 void helper_mtc0_srsconf0(CPUMIPSState
*env
, target_ulong arg1
)
1466 env
->CP0_SRSConf0
|= arg1
& env
->CP0_SRSConf0_rw_bitmask
;
1469 void helper_mtc0_srsconf1(CPUMIPSState
*env
, target_ulong arg1
)
1471 env
->CP0_SRSConf1
|= arg1
& env
->CP0_SRSConf1_rw_bitmask
;
1474 void helper_mtc0_srsconf2(CPUMIPSState
*env
, target_ulong arg1
)
1476 env
->CP0_SRSConf2
|= arg1
& env
->CP0_SRSConf2_rw_bitmask
;
1479 void helper_mtc0_srsconf3(CPUMIPSState
*env
, target_ulong arg1
)
1481 env
->CP0_SRSConf3
|= arg1
& env
->CP0_SRSConf3_rw_bitmask
;
1484 void helper_mtc0_srsconf4(CPUMIPSState
*env
, target_ulong arg1
)
1486 env
->CP0_SRSConf4
|= arg1
& env
->CP0_SRSConf4_rw_bitmask
;
1489 void helper_mtc0_hwrena(CPUMIPSState
*env
, target_ulong arg1
)
1491 env
->CP0_HWREna
= arg1
& 0x0000000F;
1494 void helper_mtc0_count(CPUMIPSState
*env
, target_ulong arg1
)
1496 cpu_mips_store_count(env
, arg1
);
1499 void helper_mtc0_entryhi(CPUMIPSState
*env
, target_ulong arg1
)
1501 target_ulong old
, val
;
1503 /* 1k pages not implemented */
1504 val
= arg1
& ((TARGET_PAGE_MASK
<< 1) | 0xFF);
1505 #if defined(TARGET_MIPS64)
1506 val
&= env
->SEGMask
;
1508 old
= env
->CP0_EntryHi
;
1509 env
->CP0_EntryHi
= val
;
1510 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
1511 sync_c0_entryhi(env
, env
->current_tc
);
1513 /* If the ASID changes, flush qemu's TLB. */
1514 if ((old
& 0xFF) != (val
& 0xFF))
1515 cpu_mips_tlb_flush(env
, 1);
1518 void helper_mttc0_entryhi(CPUMIPSState
*env
, target_ulong arg1
)
1520 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1521 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1523 other
->CP0_EntryHi
= arg1
;
1524 sync_c0_entryhi(other
, other_tc
);
1527 void helper_mtc0_compare(CPUMIPSState
*env
, target_ulong arg1
)
1529 cpu_mips_store_compare(env
, arg1
);
1532 void helper_mtc0_status(CPUMIPSState
*env
, target_ulong arg1
)
1535 uint32_t mask
= env
->CP0_Status_rw_bitmask
;
1538 old
= env
->CP0_Status
;
1539 env
->CP0_Status
= (env
->CP0_Status
& ~mask
) | val
;
1540 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
1541 sync_c0_status(env
, env
, env
->current_tc
);
1543 compute_hflags(env
);
1546 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
1547 qemu_log("Status %08x (%08x) => %08x (%08x) Cause %08x",
1548 old
, old
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1549 val
, val
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1551 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
1552 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
1553 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
1554 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
1555 default: cpu_abort(env
, "Invalid MMU mode!\n"); break;
1560 void helper_mttc0_status(CPUMIPSState
*env
, target_ulong arg1
)
1562 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1563 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1565 other
->CP0_Status
= arg1
& ~0xf1000018;
1566 sync_c0_status(env
, other
, other_tc
);
1569 void helper_mtc0_intctl(CPUMIPSState
*env
, target_ulong arg1
)
1571 /* vectored interrupts not implemented, no performance counters. */
1572 env
->CP0_IntCtl
= (env
->CP0_IntCtl
& ~0x000003e0) | (arg1
& 0x000003e0);
1575 void helper_mtc0_srsctl(CPUMIPSState
*env
, target_ulong arg1
)
1577 uint32_t mask
= (0xf << CP0SRSCtl_ESS
) | (0xf << CP0SRSCtl_PSS
);
1578 env
->CP0_SRSCtl
= (env
->CP0_SRSCtl
& ~mask
) | (arg1
& mask
);
1581 static void mtc0_cause(CPUMIPSState
*cpu
, target_ulong arg1
)
1583 uint32_t mask
= 0x00C00300;
1584 uint32_t old
= cpu
->CP0_Cause
;
1587 if (cpu
->insn_flags
& ISA_MIPS32R2
) {
1588 mask
|= 1 << CP0Ca_DC
;
1591 cpu
->CP0_Cause
= (cpu
->CP0_Cause
& ~mask
) | (arg1
& mask
);
1593 if ((old
^ cpu
->CP0_Cause
) & (1 << CP0Ca_DC
)) {
1594 if (cpu
->CP0_Cause
& (1 << CP0Ca_DC
)) {
1595 cpu_mips_stop_count(cpu
);
1597 cpu_mips_start_count(cpu
);
1601 /* Set/reset software interrupts */
1602 for (i
= 0 ; i
< 2 ; i
++) {
1603 if ((old
^ cpu
->CP0_Cause
) & (1 << (CP0Ca_IP
+ i
))) {
1604 cpu_mips_soft_irq(cpu
, i
, cpu
->CP0_Cause
& (1 << (CP0Ca_IP
+ i
)));
1609 void helper_mtc0_cause(CPUMIPSState
*env
, target_ulong arg1
)
1611 mtc0_cause(env
, arg1
);
1614 void helper_mttc0_cause(CPUMIPSState
*env
, target_ulong arg1
)
1616 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1617 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1619 mtc0_cause(other
, arg1
);
1622 target_ulong
helper_mftc0_epc(CPUMIPSState
*env
)
1624 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1625 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1627 return other
->CP0_EPC
;
1630 target_ulong
helper_mftc0_ebase(CPUMIPSState
*env
)
1632 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1633 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1635 return other
->CP0_EBase
;
1638 void helper_mtc0_ebase(CPUMIPSState
*env
, target_ulong arg1
)
1640 /* vectored interrupts not implemented */
1641 env
->CP0_EBase
= (env
->CP0_EBase
& ~0x3FFFF000) | (arg1
& 0x3FFFF000);
1644 void helper_mttc0_ebase(CPUMIPSState
*env
, target_ulong arg1
)
1646 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1647 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1648 other
->CP0_EBase
= (other
->CP0_EBase
& ~0x3FFFF000) | (arg1
& 0x3FFFF000);
1651 target_ulong
helper_mftc0_configx(CPUMIPSState
*env
, target_ulong idx
)
1653 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1654 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1657 case 0: return other
->CP0_Config0
;
1658 case 1: return other
->CP0_Config1
;
1659 case 2: return other
->CP0_Config2
;
1660 case 3: return other
->CP0_Config3
;
1661 /* 4 and 5 are reserved. */
1662 case 6: return other
->CP0_Config6
;
1663 case 7: return other
->CP0_Config7
;
1670 void helper_mtc0_config0(CPUMIPSState
*env
, target_ulong arg1
)
1672 env
->CP0_Config0
= (env
->CP0_Config0
& 0x81FFFFF8) | (arg1
& 0x00000007);
1675 void helper_mtc0_config2(CPUMIPSState
*env
, target_ulong arg1
)
1677 /* tertiary/secondary caches not implemented */
1678 env
->CP0_Config2
= (env
->CP0_Config2
& 0x8FFF0FFF);
1681 void helper_mtc0_lladdr(CPUMIPSState
*env
, target_ulong arg1
)
1683 target_long mask
= env
->CP0_LLAddr_rw_bitmask
;
1684 arg1
= arg1
<< env
->CP0_LLAddr_shift
;
1685 env
->lladdr
= (env
->lladdr
& ~mask
) | (arg1
& mask
);
1688 void helper_mtc0_watchlo(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1690 /* Watch exceptions for instructions, data loads, data stores
1692 env
->CP0_WatchLo
[sel
] = (arg1
& ~0x7);
1695 void helper_mtc0_watchhi(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1697 env
->CP0_WatchHi
[sel
] = (arg1
& 0x40FF0FF8);
1698 env
->CP0_WatchHi
[sel
] &= ~(env
->CP0_WatchHi
[sel
] & arg1
& 0x7);
1701 void helper_mtc0_xcontext(CPUMIPSState
*env
, target_ulong arg1
)
1703 target_ulong mask
= (1ULL << (env
->SEGBITS
- 7)) - 1;
1704 env
->CP0_XContext
= (env
->CP0_XContext
& mask
) | (arg1
& ~mask
);
1707 void helper_mtc0_framemask(CPUMIPSState
*env
, target_ulong arg1
)
1709 env
->CP0_Framemask
= arg1
; /* XXX */
1712 void helper_mtc0_debug(CPUMIPSState
*env
, target_ulong arg1
)
1714 env
->CP0_Debug
= (env
->CP0_Debug
& 0x8C03FC1F) | (arg1
& 0x13300120);
1715 if (arg1
& (1 << CP0DB_DM
))
1716 env
->hflags
|= MIPS_HFLAG_DM
;
1718 env
->hflags
&= ~MIPS_HFLAG_DM
;
1721 void helper_mttc0_debug(CPUMIPSState
*env
, target_ulong arg1
)
1723 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1724 uint32_t val
= arg1
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
));
1725 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1727 /* XXX: Might be wrong, check with EJTAG spec. */
1728 if (other_tc
== other
->current_tc
)
1729 other
->active_tc
.CP0_Debug_tcstatus
= val
;
1731 other
->tcs
[other_tc
].CP0_Debug_tcstatus
= val
;
1732 other
->CP0_Debug
= (other
->CP0_Debug
&
1733 ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
1734 (arg1
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
1737 void helper_mtc0_performance0(CPUMIPSState
*env
, target_ulong arg1
)
1739 env
->CP0_Performance0
= arg1
& 0x000007ff;
1742 void helper_mtc0_taglo(CPUMIPSState
*env
, target_ulong arg1
)
1744 env
->CP0_TagLo
= arg1
& 0xFFFFFCF6;
1747 void helper_mtc0_datalo(CPUMIPSState
*env
, target_ulong arg1
)
1749 env
->CP0_DataLo
= arg1
; /* XXX */
1752 void helper_mtc0_taghi(CPUMIPSState
*env
, target_ulong arg1
)
1754 env
->CP0_TagHi
= arg1
; /* XXX */
1757 void helper_mtc0_datahi(CPUMIPSState
*env
, target_ulong arg1
)
1759 env
->CP0_DataHi
= arg1
; /* XXX */
1762 /* MIPS MT functions */
1763 target_ulong
helper_mftgpr(CPUMIPSState
*env
, uint32_t sel
)
1765 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1766 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1768 if (other_tc
== other
->current_tc
)
1769 return other
->active_tc
.gpr
[sel
];
1771 return other
->tcs
[other_tc
].gpr
[sel
];
1774 target_ulong
helper_mftlo(CPUMIPSState
*env
, uint32_t sel
)
1776 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1777 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1779 if (other_tc
== other
->current_tc
)
1780 return other
->active_tc
.LO
[sel
];
1782 return other
->tcs
[other_tc
].LO
[sel
];
1785 target_ulong
helper_mfthi(CPUMIPSState
*env
, uint32_t sel
)
1787 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1788 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1790 if (other_tc
== other
->current_tc
)
1791 return other
->active_tc
.HI
[sel
];
1793 return other
->tcs
[other_tc
].HI
[sel
];
1796 target_ulong
helper_mftacx(CPUMIPSState
*env
, uint32_t sel
)
1798 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1799 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1801 if (other_tc
== other
->current_tc
)
1802 return other
->active_tc
.ACX
[sel
];
1804 return other
->tcs
[other_tc
].ACX
[sel
];
1807 target_ulong
helper_mftdsp(CPUMIPSState
*env
)
1809 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1810 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1812 if (other_tc
== other
->current_tc
)
1813 return other
->active_tc
.DSPControl
;
1815 return other
->tcs
[other_tc
].DSPControl
;
1818 void helper_mttgpr(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1820 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1821 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1823 if (other_tc
== other
->current_tc
)
1824 other
->active_tc
.gpr
[sel
] = arg1
;
1826 other
->tcs
[other_tc
].gpr
[sel
] = arg1
;
1829 void helper_mttlo(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1831 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1832 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1834 if (other_tc
== other
->current_tc
)
1835 other
->active_tc
.LO
[sel
] = arg1
;
1837 other
->tcs
[other_tc
].LO
[sel
] = arg1
;
1840 void helper_mtthi(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1842 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1843 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1845 if (other_tc
== other
->current_tc
)
1846 other
->active_tc
.HI
[sel
] = arg1
;
1848 other
->tcs
[other_tc
].HI
[sel
] = arg1
;
1851 void helper_mttacx(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1853 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1854 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1856 if (other_tc
== other
->current_tc
)
1857 other
->active_tc
.ACX
[sel
] = arg1
;
1859 other
->tcs
[other_tc
].ACX
[sel
] = arg1
;
1862 void helper_mttdsp(CPUMIPSState
*env
, target_ulong arg1
)
1864 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1865 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1867 if (other_tc
== other
->current_tc
)
1868 other
->active_tc
.DSPControl
= arg1
;
1870 other
->tcs
[other_tc
].DSPControl
= arg1
;
1873 /* MIPS MT functions */
1874 target_ulong
helper_dmt(void)
1880 target_ulong
helper_emt(void)
1886 target_ulong
helper_dvpe(CPUMIPSState
*env
)
1888 CPUMIPSState
*other_cpu_env
= first_cpu
;
1889 target_ulong prev
= env
->mvp
->CP0_MVPControl
;
1892 /* Turn off all VPEs except the one executing the dvpe. */
1893 if (other_cpu_env
!= env
) {
1894 MIPSCPU
*other_cpu
= mips_env_get_cpu(other_cpu_env
);
1896 other_cpu_env
->mvp
->CP0_MVPControl
&= ~(1 << CP0MVPCo_EVP
);
1897 mips_vpe_sleep(other_cpu
);
1899 other_cpu_env
= other_cpu_env
->next_cpu
;
1900 } while (other_cpu_env
);
1904 target_ulong
helper_evpe(CPUMIPSState
*env
)
1906 CPUMIPSState
*other_cpu_env
= first_cpu
;
1907 target_ulong prev
= env
->mvp
->CP0_MVPControl
;
1910 MIPSCPU
*other_cpu
= mips_env_get_cpu(other_cpu_env
);
1912 if (other_cpu_env
!= env
1913 /* If the VPE is WFI, don't disturb its sleep. */
1914 && !mips_vpe_is_wfi(other_cpu
)) {
1915 /* Enable the VPE. */
1916 other_cpu_env
->mvp
->CP0_MVPControl
|= (1 << CP0MVPCo_EVP
);
1917 mips_vpe_wake(other_cpu_env
); /* And wake it up. */
1919 other_cpu_env
= other_cpu_env
->next_cpu
;
1920 } while (other_cpu_env
);
1923 #endif /* !CONFIG_USER_ONLY */
1925 void helper_fork(target_ulong arg1
, target_ulong arg2
)
1927 // arg1 = rt, arg2 = rs
1929 // TODO: store to TC register
1932 target_ulong
helper_yield(CPUMIPSState
*env
, target_ulong arg
)
1934 target_long arg1
= arg
;
1937 /* No scheduling policy implemented. */
1939 if (env
->CP0_VPEControl
& (1 << CP0VPECo_YSI
) &&
1940 env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_DT
)) {
1941 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1942 env
->CP0_VPEControl
|= 4 << CP0VPECo_EXCPT
;
1943 helper_raise_exception(env
, EXCP_THREAD
);
1946 } else if (arg1
== 0) {
1947 if (0 /* TODO: TC underflow */) {
1948 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1949 helper_raise_exception(env
, EXCP_THREAD
);
1951 // TODO: Deallocate TC
1953 } else if (arg1
> 0) {
1954 /* Yield qualifier inputs not implemented. */
1955 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1956 env
->CP0_VPEControl
|= 2 << CP0VPECo_EXCPT
;
1957 helper_raise_exception(env
, EXCP_THREAD
);
1959 return env
->CP0_YQMask
;
1962 #ifndef CONFIG_USER_ONLY
1963 /* TLB management */
1964 static void cpu_mips_tlb_flush (CPUMIPSState
*env
, int flush_global
)
1966 /* Flush qemu's TLB and discard all shadowed entries. */
1967 tlb_flush (env
, flush_global
);
1968 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
1971 static void r4k_mips_tlb_flush_extra (CPUMIPSState
*env
, int first
)
1973 /* Discard entries from env->tlb[first] onwards. */
1974 while (env
->tlb
->tlb_in_use
> first
) {
1975 r4k_invalidate_tlb(env
, --env
->tlb
->tlb_in_use
, 0);
1979 static void r4k_fill_tlb(CPUMIPSState
*env
, int idx
)
1983 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
1984 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1985 tlb
->VPN
= env
->CP0_EntryHi
& (TARGET_PAGE_MASK
<< 1);
1986 #if defined(TARGET_MIPS64)
1987 tlb
->VPN
&= env
->SEGMask
;
1989 tlb
->ASID
= env
->CP0_EntryHi
& 0xFF;
1990 tlb
->PageMask
= env
->CP0_PageMask
;
1991 tlb
->G
= env
->CP0_EntryLo0
& env
->CP0_EntryLo1
& 1;
1992 tlb
->V0
= (env
->CP0_EntryLo0
& 2) != 0;
1993 tlb
->D0
= (env
->CP0_EntryLo0
& 4) != 0;
1994 tlb
->C0
= (env
->CP0_EntryLo0
>> 3) & 0x7;
1995 tlb
->PFN
[0] = (env
->CP0_EntryLo0
>> 6) << 12;
1996 tlb
->V1
= (env
->CP0_EntryLo1
& 2) != 0;
1997 tlb
->D1
= (env
->CP0_EntryLo1
& 4) != 0;
1998 tlb
->C1
= (env
->CP0_EntryLo1
>> 3) & 0x7;
1999 tlb
->PFN
[1] = (env
->CP0_EntryLo1
>> 6) << 12;
2002 void r4k_helper_tlbwi(CPUMIPSState
*env
)
2006 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
2008 /* Discard cached TLB entries. We could avoid doing this if the
2009 tlbwi is just upgrading access permissions on the current entry;
2010 that might be a further win. */
2011 r4k_mips_tlb_flush_extra (env
, env
->tlb
->nb_tlb
);
2013 r4k_invalidate_tlb(env
, idx
, 0);
2014 r4k_fill_tlb(env
, idx
);
2017 void r4k_helper_tlbwr(CPUMIPSState
*env
)
2019 int r
= cpu_mips_get_random(env
);
2021 r4k_invalidate_tlb(env
, r
, 1);
2022 r4k_fill_tlb(env
, r
);
2025 void r4k_helper_tlbp(CPUMIPSState
*env
)
2034 ASID
= env
->CP0_EntryHi
& 0xFF;
2035 for (i
= 0; i
< env
->tlb
->nb_tlb
; i
++) {
2036 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
2037 /* 1k pages are not supported. */
2038 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
2039 tag
= env
->CP0_EntryHi
& ~mask
;
2040 VPN
= tlb
->VPN
& ~mask
;
2041 /* Check ASID, virtual page number & size */
2042 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
2048 if (i
== env
->tlb
->nb_tlb
) {
2049 /* No match. Discard any shadow entries, if any of them match. */
2050 for (i
= env
->tlb
->nb_tlb
; i
< env
->tlb
->tlb_in_use
; i
++) {
2051 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
2052 /* 1k pages are not supported. */
2053 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
2054 tag
= env
->CP0_EntryHi
& ~mask
;
2055 VPN
= tlb
->VPN
& ~mask
;
2056 /* Check ASID, virtual page number & size */
2057 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
2058 r4k_mips_tlb_flush_extra (env
, i
);
2063 env
->CP0_Index
|= 0x80000000;
2067 void r4k_helper_tlbr(CPUMIPSState
*env
)
2073 ASID
= env
->CP0_EntryHi
& 0xFF;
2074 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
2075 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
2077 /* If this will change the current ASID, flush qemu's TLB. */
2078 if (ASID
!= tlb
->ASID
)
2079 cpu_mips_tlb_flush (env
, 1);
2081 r4k_mips_tlb_flush_extra(env
, env
->tlb
->nb_tlb
);
2083 env
->CP0_EntryHi
= tlb
->VPN
| tlb
->ASID
;
2084 env
->CP0_PageMask
= tlb
->PageMask
;
2085 env
->CP0_EntryLo0
= tlb
->G
| (tlb
->V0
<< 1) | (tlb
->D0
<< 2) |
2086 (tlb
->C0
<< 3) | (tlb
->PFN
[0] >> 6);
2087 env
->CP0_EntryLo1
= tlb
->G
| (tlb
->V1
<< 1) | (tlb
->D1
<< 2) |
2088 (tlb
->C1
<< 3) | (tlb
->PFN
[1] >> 6);
2091 void helper_tlbwi(CPUMIPSState
*env
)
2093 env
->tlb
->helper_tlbwi(env
);
2096 void helper_tlbwr(CPUMIPSState
*env
)
2098 env
->tlb
->helper_tlbwr(env
);
2101 void helper_tlbp(CPUMIPSState
*env
)
2103 env
->tlb
->helper_tlbp(env
);
2106 void helper_tlbr(CPUMIPSState
*env
)
2108 env
->tlb
->helper_tlbr(env
);
2112 target_ulong
helper_di(CPUMIPSState
*env
)
2114 target_ulong t0
= env
->CP0_Status
;
2116 env
->CP0_Status
= t0
& ~(1 << CP0St_IE
);
2120 target_ulong
helper_ei(CPUMIPSState
*env
)
2122 target_ulong t0
= env
->CP0_Status
;
2124 env
->CP0_Status
= t0
| (1 << CP0St_IE
);
2128 static void debug_pre_eret(CPUMIPSState
*env
)
2130 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
2131 qemu_log("ERET: PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
2132 env
->active_tc
.PC
, env
->CP0_EPC
);
2133 if (env
->CP0_Status
& (1 << CP0St_ERL
))
2134 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
2135 if (env
->hflags
& MIPS_HFLAG_DM
)
2136 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
2141 static void debug_post_eret(CPUMIPSState
*env
)
2143 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
2144 qemu_log(" => PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
2145 env
->active_tc
.PC
, env
->CP0_EPC
);
2146 if (env
->CP0_Status
& (1 << CP0St_ERL
))
2147 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
2148 if (env
->hflags
& MIPS_HFLAG_DM
)
2149 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
2150 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
2151 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
2152 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
2153 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
2154 default: cpu_abort(env
, "Invalid MMU mode!\n"); break;
2159 static void set_pc(CPUMIPSState
*env
, target_ulong error_pc
)
2161 env
->active_tc
.PC
= error_pc
& ~(target_ulong
)1;
2163 env
->hflags
|= MIPS_HFLAG_M16
;
2165 env
->hflags
&= ~(MIPS_HFLAG_M16
);
2169 void helper_eret(CPUMIPSState
*env
)
2171 debug_pre_eret(env
);
2172 if (env
->CP0_Status
& (1 << CP0St_ERL
)) {
2173 set_pc(env
, env
->CP0_ErrorEPC
);
2174 env
->CP0_Status
&= ~(1 << CP0St_ERL
);
2176 set_pc(env
, env
->CP0_EPC
);
2177 env
->CP0_Status
&= ~(1 << CP0St_EXL
);
2179 compute_hflags(env
);
2180 debug_post_eret(env
);
2184 void helper_deret(CPUMIPSState
*env
)
2186 debug_pre_eret(env
);
2187 set_pc(env
, env
->CP0_DEPC
);
2189 env
->hflags
&= MIPS_HFLAG_DM
;
2190 compute_hflags(env
);
2191 debug_post_eret(env
);
2194 #endif /* !CONFIG_USER_ONLY */
2196 target_ulong
helper_rdhwr_cpunum(CPUMIPSState
*env
)
2198 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2199 (env
->CP0_HWREna
& (1 << 0)))
2200 return env
->CP0_EBase
& 0x3ff;
2202 helper_raise_exception(env
, EXCP_RI
);
2207 target_ulong
helper_rdhwr_synci_step(CPUMIPSState
*env
)
2209 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2210 (env
->CP0_HWREna
& (1 << 1)))
2211 return env
->SYNCI_Step
;
2213 helper_raise_exception(env
, EXCP_RI
);
2218 target_ulong
helper_rdhwr_cc(CPUMIPSState
*env
)
2220 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2221 (env
->CP0_HWREna
& (1 << 2)))
2222 return env
->CP0_Count
;
2224 helper_raise_exception(env
, EXCP_RI
);
2229 target_ulong
helper_rdhwr_ccres(CPUMIPSState
*env
)
2231 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2232 (env
->CP0_HWREna
& (1 << 3)))
2235 helper_raise_exception(env
, EXCP_RI
);
2240 void helper_pmon(CPUMIPSState
*env
, int function
)
2244 case 2: /* TODO: char inbyte(int waitflag); */
2245 if (env
->active_tc
.gpr
[4] == 0)
2246 env
->active_tc
.gpr
[2] = -1;
2248 case 11: /* TODO: char inbyte (void); */
2249 env
->active_tc
.gpr
[2] = -1;
2253 printf("%c", (char)(env
->active_tc
.gpr
[4] & 0xFF));
2259 unsigned char *fmt
= (void *)(uintptr_t)env
->active_tc
.gpr
[4];
2266 void helper_wait(CPUMIPSState
*env
)
2269 cpu_reset_interrupt(env
, CPU_INTERRUPT_WAKE
);
2270 helper_raise_exception(env
, EXCP_HLT
);
2273 #if !defined(CONFIG_USER_ONLY)
2275 static void QEMU_NORETURN
do_unaligned_access(CPUMIPSState
*env
,
2276 target_ulong addr
, int is_write
,
2277 int is_user
, uintptr_t retaddr
);
2279 #define MMUSUFFIX _mmu
2280 #define ALIGNED_ONLY
2283 #include "softmmu_template.h"
2286 #include "softmmu_template.h"
2289 #include "softmmu_template.h"
2292 #include "softmmu_template.h"
2294 static void do_unaligned_access(CPUMIPSState
*env
, target_ulong addr
,
2295 int is_write
, int is_user
, uintptr_t retaddr
)
2297 env
->CP0_BadVAddr
= addr
;
2298 do_restore_state(env
, retaddr
);
2299 helper_raise_exception(env
, (is_write
== 1) ? EXCP_AdES
: EXCP_AdEL
);
2302 void tlb_fill(CPUMIPSState
*env
, target_ulong addr
, int is_write
, int mmu_idx
,
2305 TranslationBlock
*tb
;
2308 ret
= cpu_mips_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
2311 /* now we have a real cpu fault */
2312 tb
= tb_find_pc(retaddr
);
2314 /* the PC is inside the translated code. It means that we have
2315 a virtual CPU fault */
2316 cpu_restore_state(tb
, env
, retaddr
);
2319 helper_raise_exception_err(env
, env
->exception_index
, env
->error_code
);
2323 void cpu_unassigned_access(CPUMIPSState
*env
, hwaddr addr
,
2324 int is_write
, int is_exec
, int unused
, int size
)
2327 helper_raise_exception(env
, EXCP_IBE
);
2329 helper_raise_exception(env
, EXCP_DBE
);
2331 #endif /* !CONFIG_USER_ONLY */
2333 /* Complex FPU operations which may need stack space. */
2335 #define FLOAT_ONE32 make_float32(0x3f8 << 20)
2336 #define FLOAT_ONE64 make_float64(0x3ffULL << 52)
2337 #define FLOAT_TWO32 make_float32(1 << 30)
2338 #define FLOAT_TWO64 make_float64(1ULL << 62)
2339 #define FLOAT_QNAN32 0x7fbfffff
2340 #define FLOAT_QNAN64 0x7ff7ffffffffffffULL
2341 #define FLOAT_SNAN32 0x7fffffff
2342 #define FLOAT_SNAN64 0x7fffffffffffffffULL
2344 /* convert MIPS rounding mode in FCR31 to IEEE library */
2345 static unsigned int ieee_rm
[] = {
2346 float_round_nearest_even
,
2347 float_round_to_zero
,
2352 #define RESTORE_ROUNDING_MODE \
2353 set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3], &env->active_fpu.fp_status)
2355 #define RESTORE_FLUSH_MODE \
2356 set_flush_to_zero((env->active_fpu.fcr31 & (1 << 24)) != 0, &env->active_fpu.fp_status);
2358 target_ulong
helper_cfc1(CPUMIPSState
*env
, uint32_t reg
)
2364 arg1
= (int32_t)env
->active_fpu
.fcr0
;
2367 arg1
= ((env
->active_fpu
.fcr31
>> 24) & 0xfe) | ((env
->active_fpu
.fcr31
>> 23) & 0x1);
2370 arg1
= env
->active_fpu
.fcr31
& 0x0003f07c;
2373 arg1
= (env
->active_fpu
.fcr31
& 0x00000f83) | ((env
->active_fpu
.fcr31
>> 22) & 0x4);
2376 arg1
= (int32_t)env
->active_fpu
.fcr31
;
2383 void helper_ctc1(CPUMIPSState
*env
, target_ulong arg1
, uint32_t reg
)
2387 if (arg1
& 0xffffff00)
2389 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0x017fffff) | ((arg1
& 0xfe) << 24) |
2390 ((arg1
& 0x1) << 23);
2393 if (arg1
& 0x007c0000)
2395 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfffc0f83) | (arg1
& 0x0003f07c);
2398 if (arg1
& 0x007c0000)
2400 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfefff07c) | (arg1
& 0x00000f83) |
2401 ((arg1
& 0x4) << 22);
2404 if (arg1
& 0x007c0000)
2406 env
->active_fpu
.fcr31
= arg1
;
2411 /* set rounding mode */
2412 RESTORE_ROUNDING_MODE
;
2413 /* set flush-to-zero mode */
2415 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2416 if ((GET_FP_ENABLE(env
->active_fpu
.fcr31
) | 0x20) & GET_FP_CAUSE(env
->active_fpu
.fcr31
))
2417 helper_raise_exception(env
, EXCP_FPE
);
2420 static inline int ieee_ex_to_mips(int xcpt
)
2424 if (xcpt
& float_flag_invalid
) {
2427 if (xcpt
& float_flag_overflow
) {
2430 if (xcpt
& float_flag_underflow
) {
2431 ret
|= FP_UNDERFLOW
;
2433 if (xcpt
& float_flag_divbyzero
) {
2436 if (xcpt
& float_flag_inexact
) {
2443 static inline void update_fcr31(CPUMIPSState
*env
)
2445 int tmp
= ieee_ex_to_mips(get_float_exception_flags(&env
->active_fpu
.fp_status
));
2447 SET_FP_CAUSE(env
->active_fpu
.fcr31
, tmp
);
2448 if (GET_FP_ENABLE(env
->active_fpu
.fcr31
) & tmp
)
2449 helper_raise_exception(env
, EXCP_FPE
);
2451 UPDATE_FP_FLAGS(env
->active_fpu
.fcr31
, tmp
);
2455 Single precition routines have a "s" suffix, double precision a
2456 "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
2457 paired single lower "pl", paired single upper "pu". */
2459 /* unary operations, modifying fp status */
2460 uint64_t helper_float_sqrt_d(CPUMIPSState
*env
, uint64_t fdt0
)
2462 return float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2465 uint32_t helper_float_sqrt_s(CPUMIPSState
*env
, uint32_t fst0
)
2467 return float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2470 uint64_t helper_float_cvtd_s(CPUMIPSState
*env
, uint32_t fst0
)
2474 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2475 fdt2
= float32_to_float64(fst0
, &env
->active_fpu
.fp_status
);
2480 uint64_t helper_float_cvtd_w(CPUMIPSState
*env
, uint32_t wt0
)
2484 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2485 fdt2
= int32_to_float64(wt0
, &env
->active_fpu
.fp_status
);
2490 uint64_t helper_float_cvtd_l(CPUMIPSState
*env
, uint64_t dt0
)
2494 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2495 fdt2
= int64_to_float64(dt0
, &env
->active_fpu
.fp_status
);
2500 uint64_t helper_float_cvtl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2504 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2505 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2507 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2512 uint64_t helper_float_cvtl_s(CPUMIPSState
*env
, uint32_t fst0
)
2516 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2517 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2519 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2524 uint64_t helper_float_cvtps_pw(CPUMIPSState
*env
, uint64_t dt0
)
2529 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2530 fst2
= int32_to_float32(dt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2531 fsth2
= int32_to_float32(dt0
>> 32, &env
->active_fpu
.fp_status
);
2533 return ((uint64_t)fsth2
<< 32) | fst2
;
2536 uint64_t helper_float_cvtpw_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2541 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2542 wt2
= float32_to_int32(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2543 wth2
= float32_to_int32(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2545 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
)) {
2547 wth2
= FLOAT_SNAN32
;
2549 return ((uint64_t)wth2
<< 32) | wt2
;
2552 uint32_t helper_float_cvts_d(CPUMIPSState
*env
, uint64_t fdt0
)
2556 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2557 fst2
= float64_to_float32(fdt0
, &env
->active_fpu
.fp_status
);
2562 uint32_t helper_float_cvts_w(CPUMIPSState
*env
, uint32_t wt0
)
2566 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2567 fst2
= int32_to_float32(wt0
, &env
->active_fpu
.fp_status
);
2572 uint32_t helper_float_cvts_l(CPUMIPSState
*env
, uint64_t dt0
)
2576 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2577 fst2
= int64_to_float32(dt0
, &env
->active_fpu
.fp_status
);
2582 uint32_t helper_float_cvts_pl(CPUMIPSState
*env
, uint32_t wt0
)
2586 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2592 uint32_t helper_float_cvts_pu(CPUMIPSState
*env
, uint32_t wth0
)
2596 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2602 uint32_t helper_float_cvtw_s(CPUMIPSState
*env
, uint32_t fst0
)
2606 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2607 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2609 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2614 uint32_t helper_float_cvtw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2618 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2619 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2621 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2626 uint64_t helper_float_roundl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2630 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2631 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2632 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2633 RESTORE_ROUNDING_MODE
;
2635 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2640 uint64_t helper_float_roundl_s(CPUMIPSState
*env
, uint32_t fst0
)
2644 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2645 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2646 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2647 RESTORE_ROUNDING_MODE
;
2649 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2654 uint32_t helper_float_roundw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2658 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2659 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2660 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2661 RESTORE_ROUNDING_MODE
;
2663 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2668 uint32_t helper_float_roundw_s(CPUMIPSState
*env
, uint32_t fst0
)
2672 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2673 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2674 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2675 RESTORE_ROUNDING_MODE
;
2677 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2682 uint64_t helper_float_truncl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2686 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2687 dt2
= float64_to_int64_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2689 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2694 uint64_t helper_float_truncl_s(CPUMIPSState
*env
, uint32_t fst0
)
2698 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2699 dt2
= float32_to_int64_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2701 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2706 uint32_t helper_float_truncw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2710 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2711 wt2
= float64_to_int32_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2713 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2718 uint32_t helper_float_truncw_s(CPUMIPSState
*env
, uint32_t fst0
)
2722 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2723 wt2
= float32_to_int32_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2725 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2730 uint64_t helper_float_ceill_d(CPUMIPSState
*env
, uint64_t fdt0
)
2734 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2735 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2736 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2737 RESTORE_ROUNDING_MODE
;
2739 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2744 uint64_t helper_float_ceill_s(CPUMIPSState
*env
, uint32_t fst0
)
2748 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2749 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2750 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2751 RESTORE_ROUNDING_MODE
;
2753 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2758 uint32_t helper_float_ceilw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2762 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2763 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2764 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2765 RESTORE_ROUNDING_MODE
;
2767 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2772 uint32_t helper_float_ceilw_s(CPUMIPSState
*env
, uint32_t fst0
)
2776 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2777 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2778 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2779 RESTORE_ROUNDING_MODE
;
2781 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2786 uint64_t helper_float_floorl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2790 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2791 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2792 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2793 RESTORE_ROUNDING_MODE
;
2795 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2800 uint64_t helper_float_floorl_s(CPUMIPSState
*env
, uint32_t fst0
)
2804 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2805 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2806 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2807 RESTORE_ROUNDING_MODE
;
2809 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2814 uint32_t helper_float_floorw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2818 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2819 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2820 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2821 RESTORE_ROUNDING_MODE
;
2823 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2828 uint32_t helper_float_floorw_s(CPUMIPSState
*env
, uint32_t fst0
)
2832 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2833 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2834 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2835 RESTORE_ROUNDING_MODE
;
2837 if (GET_FP_CAUSE(env
->active_fpu
.fcr31
) & (FP_OVERFLOW
| FP_INVALID
))
2842 /* unary operations, not modifying fp status */
2843 #define FLOAT_UNOP(name) \
2844 uint64_t helper_float_ ## name ## _d(uint64_t fdt0) \
2846 return float64_ ## name(fdt0); \
2848 uint32_t helper_float_ ## name ## _s(uint32_t fst0) \
2850 return float32_ ## name(fst0); \
2852 uint64_t helper_float_ ## name ## _ps(uint64_t fdt0) \
2857 wt0 = float32_ ## name(fdt0 & 0XFFFFFFFF); \
2858 wth0 = float32_ ## name(fdt0 >> 32); \
2859 return ((uint64_t)wth0 << 32) | wt0; \
2865 /* MIPS specific unary operations */
2866 uint64_t helper_float_recip_d(CPUMIPSState
*env
, uint64_t fdt0
)
2870 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2871 fdt2
= float64_div(FLOAT_ONE64
, fdt0
, &env
->active_fpu
.fp_status
);
2876 uint32_t helper_float_recip_s(CPUMIPSState
*env
, uint32_t fst0
)
2880 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2881 fst2
= float32_div(FLOAT_ONE32
, fst0
, &env
->active_fpu
.fp_status
);
2886 uint64_t helper_float_rsqrt_d(CPUMIPSState
*env
, uint64_t fdt0
)
2890 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2891 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2892 fdt2
= float64_div(FLOAT_ONE64
, fdt2
, &env
->active_fpu
.fp_status
);
2897 uint32_t helper_float_rsqrt_s(CPUMIPSState
*env
, uint32_t fst0
)
2901 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2902 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2903 fst2
= float32_div(FLOAT_ONE32
, fst2
, &env
->active_fpu
.fp_status
);
2908 uint64_t helper_float_recip1_d(CPUMIPSState
*env
, uint64_t fdt0
)
2912 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2913 fdt2
= float64_div(FLOAT_ONE64
, fdt0
, &env
->active_fpu
.fp_status
);
2918 uint32_t helper_float_recip1_s(CPUMIPSState
*env
, uint32_t fst0
)
2922 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2923 fst2
= float32_div(FLOAT_ONE32
, fst0
, &env
->active_fpu
.fp_status
);
2928 uint64_t helper_float_recip1_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2933 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2934 fst2
= float32_div(FLOAT_ONE32
, fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2935 fsth2
= float32_div(FLOAT_ONE32
, fdt0
>> 32, &env
->active_fpu
.fp_status
);
2937 return ((uint64_t)fsth2
<< 32) | fst2
;
2940 uint64_t helper_float_rsqrt1_d(CPUMIPSState
*env
, uint64_t fdt0
)
2944 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2945 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2946 fdt2
= float64_div(FLOAT_ONE64
, fdt2
, &env
->active_fpu
.fp_status
);
2951 uint32_t helper_float_rsqrt1_s(CPUMIPSState
*env
, uint32_t fst0
)
2955 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2956 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2957 fst2
= float32_div(FLOAT_ONE32
, fst2
, &env
->active_fpu
.fp_status
);
2962 uint64_t helper_float_rsqrt1_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2967 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2968 fst2
= float32_sqrt(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2969 fsth2
= float32_sqrt(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2970 fst2
= float32_div(FLOAT_ONE32
, fst2
, &env
->active_fpu
.fp_status
);
2971 fsth2
= float32_div(FLOAT_ONE32
, fsth2
, &env
->active_fpu
.fp_status
);
2973 return ((uint64_t)fsth2
<< 32) | fst2
;
2976 #define FLOAT_OP(name, p) void helper_float_##name##_##p(CPUMIPSState *env)
2978 /* binary operations */
2979 #define FLOAT_BINOP(name) \
2980 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
2981 uint64_t fdt0, uint64_t fdt1) \
2985 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2986 dt2 = float64_ ## name (fdt0, fdt1, &env->active_fpu.fp_status); \
2987 update_fcr31(env); \
2988 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
2989 dt2 = FLOAT_QNAN64; \
2993 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
2994 uint32_t fst0, uint32_t fst1) \
2998 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2999 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
3000 update_fcr31(env); \
3001 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
3002 wt2 = FLOAT_QNAN32; \
3006 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
3010 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
3011 uint32_t fsth0 = fdt0 >> 32; \
3012 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
3013 uint32_t fsth1 = fdt1 >> 32; \
3017 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3018 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
3019 wth2 = float32_ ## name (fsth0, fsth1, &env->active_fpu.fp_status); \
3020 update_fcr31(env); \
3021 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) { \
3022 wt2 = FLOAT_QNAN32; \
3023 wth2 = FLOAT_QNAN32; \
3025 return ((uint64_t)wth2 << 32) | wt2; \
3034 /* ternary operations */
3035 #define FLOAT_TERNOP(name1, name2) \
3036 uint64_t helper_float_ ## name1 ## name2 ## _d(CPUMIPSState *env, \
3041 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
3042 return float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
3045 uint32_t helper_float_ ## name1 ## name2 ## _s(CPUMIPSState *env, \
3050 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
3051 return float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
3054 uint64_t helper_float_ ## name1 ## name2 ## _ps(CPUMIPSState *env, \
3059 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
3060 uint32_t fsth0 = fdt0 >> 32; \
3061 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
3062 uint32_t fsth1 = fdt1 >> 32; \
3063 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
3064 uint32_t fsth2 = fdt2 >> 32; \
3066 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
3067 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
3068 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
3069 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
3070 return ((uint64_t)fsth2 << 32) | fst2; \
3073 FLOAT_TERNOP(mul
, add
)
3074 FLOAT_TERNOP(mul
, sub
)
3077 /* negated ternary operations */
3078 #define FLOAT_NTERNOP(name1, name2) \
3079 uint64_t helper_float_n ## name1 ## name2 ## _d(CPUMIPSState *env, \
3084 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
3085 fdt2 = float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
3086 return float64_chs(fdt2); \
3089 uint32_t helper_float_n ## name1 ## name2 ## _s(CPUMIPSState *env, \
3094 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
3095 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
3096 return float32_chs(fst2); \
3099 uint64_t helper_float_n ## name1 ## name2 ## _ps(CPUMIPSState *env, \
3104 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
3105 uint32_t fsth0 = fdt0 >> 32; \
3106 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
3107 uint32_t fsth1 = fdt1 >> 32; \
3108 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
3109 uint32_t fsth2 = fdt2 >> 32; \
3111 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
3112 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
3113 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
3114 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
3115 fst2 = float32_chs(fst2); \
3116 fsth2 = float32_chs(fsth2); \
3117 return ((uint64_t)fsth2 << 32) | fst2; \
3120 FLOAT_NTERNOP(mul
, add
)
3121 FLOAT_NTERNOP(mul
, sub
)
3122 #undef FLOAT_NTERNOP
3124 /* MIPS specific binary operations */
3125 uint64_t helper_float_recip2_d(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3127 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
3128 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
3129 fdt2
= float64_chs(float64_sub(fdt2
, FLOAT_ONE64
, &env
->active_fpu
.fp_status
));
3134 uint32_t helper_float_recip2_s(CPUMIPSState
*env
, uint32_t fst0
, uint32_t fst2
)
3136 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
3137 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3138 fst2
= float32_chs(float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
));
3143 uint64_t helper_float_recip2_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3145 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3146 uint32_t fsth0
= fdt0
>> 32;
3147 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
3148 uint32_t fsth2
= fdt2
>> 32;
3150 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
3151 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3152 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
3153 fst2
= float32_chs(float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
));
3154 fsth2
= float32_chs(float32_sub(fsth2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
));
3156 return ((uint64_t)fsth2
<< 32) | fst2
;
3159 uint64_t helper_float_rsqrt2_d(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3161 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
3162 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
3163 fdt2
= float64_sub(fdt2
, FLOAT_ONE64
, &env
->active_fpu
.fp_status
);
3164 fdt2
= float64_chs(float64_div(fdt2
, FLOAT_TWO64
, &env
->active_fpu
.fp_status
));
3169 uint32_t helper_float_rsqrt2_s(CPUMIPSState
*env
, uint32_t fst0
, uint32_t fst2
)
3171 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
3172 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3173 fst2
= float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
);
3174 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3179 uint64_t helper_float_rsqrt2_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3181 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3182 uint32_t fsth0
= fdt0
>> 32;
3183 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
3184 uint32_t fsth2
= fdt2
>> 32;
3186 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
3187 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3188 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
3189 fst2
= float32_sub(fst2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
);
3190 fsth2
= float32_sub(fsth2
, FLOAT_ONE32
, &env
->active_fpu
.fp_status
);
3191 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3192 fsth2
= float32_chs(float32_div(fsth2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3194 return ((uint64_t)fsth2
<< 32) | fst2
;
3197 uint64_t helper_float_addr_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt1
)
3199 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3200 uint32_t fsth0
= fdt0
>> 32;
3201 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
3202 uint32_t fsth1
= fdt1
>> 32;
3206 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
3207 fst2
= float32_add (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
3208 fsth2
= float32_add (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
3210 return ((uint64_t)fsth2
<< 32) | fst2
;
3213 uint64_t helper_float_mulr_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt1
)
3215 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3216 uint32_t fsth0
= fdt0
>> 32;
3217 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
3218 uint32_t fsth1
= fdt1
>> 32;
3222 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
3223 fst2
= float32_mul (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
3224 fsth2
= float32_mul (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
3226 return ((uint64_t)fsth2
<< 32) | fst2
;
3229 /* compare operations */
3230 #define FOP_COND_D(op, cond) \
3231 void helper_cmp_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3232 uint64_t fdt1, int cc) \
3235 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3237 update_fcr31(env); \
3239 SET_FP_COND(cc, env->active_fpu); \
3241 CLEAR_FP_COND(cc, env->active_fpu); \
3243 void helper_cmpabs_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3244 uint64_t fdt1, int cc) \
3247 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3248 fdt0 = float64_abs(fdt0); \
3249 fdt1 = float64_abs(fdt1); \
3251 update_fcr31(env); \
3253 SET_FP_COND(cc, env->active_fpu); \
3255 CLEAR_FP_COND(cc, env->active_fpu); \
3258 /* NOTE: the comma operator will make "cond" to eval to false,
3259 * but float64_unordered_quiet() is still called. */
3260 FOP_COND_D(f
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3261 FOP_COND_D(un
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
3262 FOP_COND_D(eq
, float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3263 FOP_COND_D(ueq
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3264 FOP_COND_D(olt
, float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3265 FOP_COND_D(ult
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3266 FOP_COND_D(ole
, float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3267 FOP_COND_D(ule
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3268 /* NOTE: the comma operator will make "cond" to eval to false,
3269 * but float64_unordered() is still called. */
3270 FOP_COND_D(sf
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3271 FOP_COND_D(ngle
,float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
3272 FOP_COND_D(seq
, float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3273 FOP_COND_D(ngl
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3274 FOP_COND_D(lt
, float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3275 FOP_COND_D(nge
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3276 FOP_COND_D(le
, float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3277 FOP_COND_D(ngt
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3279 #define FOP_COND_S(op, cond) \
3280 void helper_cmp_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3281 uint32_t fst1, int cc) \
3284 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3286 update_fcr31(env); \
3288 SET_FP_COND(cc, env->active_fpu); \
3290 CLEAR_FP_COND(cc, env->active_fpu); \
3292 void helper_cmpabs_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3293 uint32_t fst1, int cc) \
3296 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3297 fst0 = float32_abs(fst0); \
3298 fst1 = float32_abs(fst1); \
3300 update_fcr31(env); \
3302 SET_FP_COND(cc, env->active_fpu); \
3304 CLEAR_FP_COND(cc, env->active_fpu); \
3307 /* NOTE: the comma operator will make "cond" to eval to false,
3308 * but float32_unordered_quiet() is still called. */
3309 FOP_COND_S(f
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3310 FOP_COND_S(un
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
))
3311 FOP_COND_S(eq
, float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3312 FOP_COND_S(ueq
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3313 FOP_COND_S(olt
, float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3314 FOP_COND_S(ult
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3315 FOP_COND_S(ole
, float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3316 FOP_COND_S(ule
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3317 /* NOTE: the comma operator will make "cond" to eval to false,
3318 * but float32_unordered() is still called. */
3319 FOP_COND_S(sf
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3320 FOP_COND_S(ngle
,float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
))
3321 FOP_COND_S(seq
, float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3322 FOP_COND_S(ngl
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3323 FOP_COND_S(lt
, float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3324 FOP_COND_S(nge
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3325 FOP_COND_S(le
, float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3326 FOP_COND_S(ngt
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3328 #define FOP_COND_PS(op, condl, condh) \
3329 void helper_cmp_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3330 uint64_t fdt1, int cc) \
3332 uint32_t fst0, fsth0, fst1, fsth1; \
3334 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3335 fst0 = fdt0 & 0XFFFFFFFF; \
3336 fsth0 = fdt0 >> 32; \
3337 fst1 = fdt1 & 0XFFFFFFFF; \
3338 fsth1 = fdt1 >> 32; \
3341 update_fcr31(env); \
3343 SET_FP_COND(cc, env->active_fpu); \
3345 CLEAR_FP_COND(cc, env->active_fpu); \
3347 SET_FP_COND(cc + 1, env->active_fpu); \
3349 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3351 void helper_cmpabs_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3352 uint64_t fdt1, int cc) \
3354 uint32_t fst0, fsth0, fst1, fsth1; \
3356 fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
3357 fsth0 = float32_abs(fdt0 >> 32); \
3358 fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
3359 fsth1 = float32_abs(fdt1 >> 32); \
3362 update_fcr31(env); \
3364 SET_FP_COND(cc, env->active_fpu); \
3366 CLEAR_FP_COND(cc, env->active_fpu); \
3368 SET_FP_COND(cc + 1, env->active_fpu); \
3370 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3373 /* NOTE: the comma operator will make "cond" to eval to false,
3374 * but float32_unordered_quiet() is still called. */
3375 FOP_COND_PS(f
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
3376 (float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
3377 FOP_COND_PS(un
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
),
3378 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
3379 FOP_COND_PS(eq
, float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3380 float32_eq_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3381 FOP_COND_PS(ueq
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3382 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3383 FOP_COND_PS(olt
, float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3384 float32_lt_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3385 FOP_COND_PS(ult
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3386 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3387 FOP_COND_PS(ole
, float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3388 float32_le_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3389 FOP_COND_PS(ule
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3390 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3391 /* NOTE: the comma operator will make "cond" to eval to false,
3392 * but float32_unordered() is still called. */
3393 FOP_COND_PS(sf
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
3394 (float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
3395 FOP_COND_PS(ngle
,float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
),
3396 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
3397 FOP_COND_PS(seq
, float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3398 float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3399 FOP_COND_PS(ngl
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3400 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3401 FOP_COND_PS(lt
, float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3402 float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3403 FOP_COND_PS(nge
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3404 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3405 FOP_COND_PS(le
, float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3406 float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3407 FOP_COND_PS(ngt
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3408 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))