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/>.
22 #include "qemu-common.h"
24 #include "sysemu/kvm.h"
25 #include "exec/cpu_ldst.h"
37 #if !defined(CONFIG_USER_ONLY)
39 /* no MMU emulation */
40 int no_mmu_map_address (CPUMIPSState
*env
, hwaddr
*physical
, int *prot
,
41 target_ulong address
, int rw
, int access_type
)
51 /* fixed mapping MMU emulation */
52 int fixed_mmu_map_address (CPUMIPSState
*env
, hwaddr
*physical
, int *prot
,
53 target_ulong address
, int rw
, int access_type
)
55 if (address
<= (int32_t)0x7FFFFFFFUL
) {
56 if (!(env
->CP0_Status
& (1 << CP0St_ERL
)))
57 *physical
= address
+ 0x40000000UL
;
60 } else if (address
<= (int32_t)0xBFFFFFFFUL
)
61 *physical
= address
& 0x1FFFFFFF;
72 /* MIPS32/MIPS64 R4000-style MMU emulation */
73 int r4k_map_address (CPUMIPSState
*env
, hwaddr
*physical
, int *prot
,
74 target_ulong address
, int rw
, int access_type
)
76 uint8_t ASID
= env
->CP0_EntryHi
& 0xFF;
79 for (i
= 0; i
< env
->tlb
->tlb_in_use
; i
++) {
80 r4k_tlb_t
*tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
81 /* 1k pages are not supported. */
82 target_ulong mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
83 target_ulong tag
= address
& ~mask
;
84 target_ulong VPN
= tlb
->VPN
& ~mask
;
85 #if defined(TARGET_MIPS64)
89 /* Check ASID, virtual page number & size */
90 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
&& !tlb
->EHINV
) {
92 int n
= !!(address
& mask
& ~(mask
>> 1));
93 /* Check access rights */
94 if (!(n
? tlb
->V1
: tlb
->V0
)) {
95 return TLBRET_INVALID
;
97 if (rw
== MMU_INST_FETCH
&& (n
? tlb
->XI1
: tlb
->XI0
)) {
100 if (rw
== MMU_DATA_LOAD
&& (n
? tlb
->RI1
: tlb
->RI0
)) {
103 if (rw
!= MMU_DATA_STORE
|| (n
? tlb
->D1
: tlb
->D0
)) {
104 *physical
= tlb
->PFN
[n
] | (address
& (mask
>> 1));
106 if (n
? tlb
->D1
: tlb
->D0
)
113 return TLBRET_NOMATCH
;
116 static int get_physical_address (CPUMIPSState
*env
, hwaddr
*physical
,
117 int *prot
, target_ulong real_address
,
118 int rw
, int access_type
)
120 /* User mode can only access useg/xuseg */
121 int user_mode
= (env
->hflags
& MIPS_HFLAG_MODE
) == MIPS_HFLAG_UM
;
122 int supervisor_mode
= (env
->hflags
& MIPS_HFLAG_MODE
) == MIPS_HFLAG_SM
;
123 int kernel_mode
= !user_mode
&& !supervisor_mode
;
124 #if defined(TARGET_MIPS64)
125 int UX
= (env
->CP0_Status
& (1 << CP0St_UX
)) != 0;
126 int SX
= (env
->CP0_Status
& (1 << CP0St_SX
)) != 0;
127 int KX
= (env
->CP0_Status
& (1 << CP0St_KX
)) != 0;
129 int ret
= TLBRET_MATCH
;
130 /* effective address (modified for KVM T&E kernel segments) */
131 target_ulong address
= real_address
;
133 #define USEG_LIMIT 0x7FFFFFFFUL
134 #define KSEG0_BASE 0x80000000UL
135 #define KSEG1_BASE 0xA0000000UL
136 #define KSEG2_BASE 0xC0000000UL
137 #define KSEG3_BASE 0xE0000000UL
139 #define KVM_KSEG0_BASE 0x40000000UL
140 #define KVM_KSEG2_BASE 0x60000000UL
143 /* KVM T&E adds guest kernel segments in useg */
144 if (real_address
>= KVM_KSEG0_BASE
) {
145 if (real_address
< KVM_KSEG2_BASE
) {
147 address
+= KSEG0_BASE
- KVM_KSEG0_BASE
;
148 } else if (real_address
<= USEG_LIMIT
) {
150 address
+= KSEG2_BASE
- KVM_KSEG2_BASE
;
155 if (address
<= USEG_LIMIT
) {
157 if (env
->CP0_Status
& (1 << CP0St_ERL
)) {
158 *physical
= address
& 0xFFFFFFFF;
164 ret
= env
->tlb
->map_address(env
, physical
, prot
, real_address
, rw
, access_type
);
166 #if defined(TARGET_MIPS64)
167 } else if (address
< 0x4000000000000000ULL
) {
169 if (UX
&& address
<= (0x3FFFFFFFFFFFFFFFULL
& env
->SEGMask
)) {
170 ret
= env
->tlb
->map_address(env
, physical
, prot
, real_address
, rw
, access_type
);
172 ret
= TLBRET_BADADDR
;
174 } else if (address
< 0x8000000000000000ULL
) {
176 if ((supervisor_mode
|| kernel_mode
) &&
177 SX
&& address
<= (0x7FFFFFFFFFFFFFFFULL
& env
->SEGMask
)) {
178 ret
= env
->tlb
->map_address(env
, physical
, prot
, real_address
, rw
, access_type
);
180 ret
= TLBRET_BADADDR
;
182 } else if (address
< 0xC000000000000000ULL
) {
184 if (kernel_mode
&& KX
&&
185 (address
& 0x07FFFFFFFFFFFFFFULL
) <= env
->PAMask
) {
186 *physical
= address
& env
->PAMask
;
192 ret
= TLBRET_BADADDR
;
194 } else if (address
< 0xFFFFFFFF80000000ULL
) {
196 if (kernel_mode
&& KX
&&
197 address
<= (0xFFFFFFFF7FFFFFFFULL
& env
->SEGMask
)) {
198 ret
= env
->tlb
->map_address(env
, physical
, prot
, real_address
, rw
, access_type
);
200 ret
= TLBRET_BADADDR
;
203 } else if (address
< (int32_t)KSEG1_BASE
) {
206 *physical
= address
- (int32_t)KSEG0_BASE
;
212 ret
= TLBRET_BADADDR
;
214 } else if (address
< (int32_t)KSEG2_BASE
) {
217 *physical
= address
- (int32_t)KSEG1_BASE
;
223 ret
= TLBRET_BADADDR
;
225 } else if (address
< (int32_t)KSEG3_BASE
) {
227 if (supervisor_mode
|| kernel_mode
) {
228 ret
= env
->tlb
->map_address(env
, physical
, prot
, real_address
, rw
, access_type
);
230 ret
= TLBRET_BADADDR
;
234 /* XXX: debug segment is not emulated */
236 ret
= env
->tlb
->map_address(env
, physical
, prot
, real_address
, rw
, access_type
);
238 ret
= TLBRET_BADADDR
;
245 static void raise_mmu_exception(CPUMIPSState
*env
, target_ulong address
,
246 int rw
, int tlb_error
)
248 CPUState
*cs
= CPU(mips_env_get_cpu(env
));
249 int exception
= 0, error_code
= 0;
251 if (rw
== MMU_INST_FETCH
) {
252 error_code
|= EXCP_INST_NOTAVAIL
;
258 /* Reference to kernel address from user mode or supervisor mode */
259 /* Reference to supervisor address from user mode */
260 if (rw
== MMU_DATA_STORE
) {
261 exception
= EXCP_AdES
;
263 exception
= EXCP_AdEL
;
267 /* No TLB match for a mapped address */
268 if (rw
== MMU_DATA_STORE
) {
269 exception
= EXCP_TLBS
;
271 exception
= EXCP_TLBL
;
273 error_code
|= EXCP_TLB_NOMATCH
;
276 /* TLB match with no valid bit */
277 if (rw
== MMU_DATA_STORE
) {
278 exception
= EXCP_TLBS
;
280 exception
= EXCP_TLBL
;
284 /* TLB match but 'D' bit is cleared */
285 exception
= EXCP_LTLBL
;
288 /* Execute-Inhibit Exception */
289 if (env
->CP0_PageGrain
& (1 << CP0PG_IEC
)) {
290 exception
= EXCP_TLBXI
;
292 exception
= EXCP_TLBL
;
296 /* Read-Inhibit Exception */
297 if (env
->CP0_PageGrain
& (1 << CP0PG_IEC
)) {
298 exception
= EXCP_TLBRI
;
300 exception
= EXCP_TLBL
;
304 /* Raise exception */
305 env
->CP0_BadVAddr
= address
;
306 env
->CP0_Context
= (env
->CP0_Context
& ~0x007fffff) |
307 ((address
>> 9) & 0x007ffff0);
309 (env
->CP0_EntryHi
& 0xFF) | (address
& (TARGET_PAGE_MASK
<< 1));
310 #if defined(TARGET_MIPS64)
311 env
->CP0_EntryHi
&= env
->SEGMask
;
312 env
->CP0_XContext
= (env
->CP0_XContext
& ((~0ULL) << (env
->SEGBITS
- 7))) |
313 ((address
& 0xC00000000000ULL
) >> (55 - env
->SEGBITS
)) |
314 ((address
& ((1ULL << env
->SEGBITS
) - 1) & 0xFFFFFFFFFFFFE000ULL
) >> 9);
316 cs
->exception_index
= exception
;
317 env
->error_code
= error_code
;
320 #if !defined(CONFIG_USER_ONLY)
321 hwaddr
mips_cpu_get_phys_page_debug(CPUState
*cs
, vaddr addr
)
323 MIPSCPU
*cpu
= MIPS_CPU(cs
);
327 if (get_physical_address(&cpu
->env
, &phys_addr
, &prot
, addr
, 0,
335 int mips_cpu_handle_mmu_fault(CPUState
*cs
, vaddr address
, int rw
,
338 MIPSCPU
*cpu
= MIPS_CPU(cs
);
339 CPUMIPSState
*env
= &cpu
->env
;
340 #if !defined(CONFIG_USER_ONLY)
348 log_cpu_state(cs
, 0);
350 qemu_log_mask(CPU_LOG_MMU
,
351 "%s pc " TARGET_FMT_lx
" ad %" VADDR_PRIx
" rw %d mmu_idx %d\n",
352 __func__
, env
->active_tc
.PC
, address
, rw
, mmu_idx
);
355 #if !defined(CONFIG_USER_ONLY)
356 /* XXX: put correct access by using cpu_restore_state()
358 access_type
= ACCESS_INT
;
359 ret
= get_physical_address(env
, &physical
, &prot
,
360 address
, rw
, access_type
);
361 qemu_log_mask(CPU_LOG_MMU
,
362 "%s address=%" VADDR_PRIx
" ret %d physical " TARGET_FMT_plx
364 __func__
, address
, ret
, physical
, prot
);
365 if (ret
== TLBRET_MATCH
) {
366 tlb_set_page(cs
, address
& TARGET_PAGE_MASK
,
367 physical
& TARGET_PAGE_MASK
, prot
| PAGE_EXEC
,
368 mmu_idx
, TARGET_PAGE_SIZE
);
373 raise_mmu_exception(env
, address
, rw
, ret
);
380 #if !defined(CONFIG_USER_ONLY)
381 hwaddr
cpu_mips_translate_address(CPUMIPSState
*env
, target_ulong address
, int rw
)
389 access_type
= ACCESS_INT
;
390 ret
= get_physical_address(env
, &physical
, &prot
,
391 address
, rw
, access_type
);
392 if (ret
!= TLBRET_MATCH
) {
393 raise_mmu_exception(env
, address
, rw
, ret
);
400 static const char * const excp_names
[EXCP_LAST
+ 1] = {
401 [EXCP_RESET
] = "reset",
402 [EXCP_SRESET
] = "soft reset",
403 [EXCP_DSS
] = "debug single step",
404 [EXCP_DINT
] = "debug interrupt",
405 [EXCP_NMI
] = "non-maskable interrupt",
406 [EXCP_MCHECK
] = "machine check",
407 [EXCP_EXT_INTERRUPT
] = "interrupt",
408 [EXCP_DFWATCH
] = "deferred watchpoint",
409 [EXCP_DIB
] = "debug instruction breakpoint",
410 [EXCP_IWATCH
] = "instruction fetch watchpoint",
411 [EXCP_AdEL
] = "address error load",
412 [EXCP_AdES
] = "address error store",
413 [EXCP_TLBF
] = "TLB refill",
414 [EXCP_IBE
] = "instruction bus error",
415 [EXCP_DBp
] = "debug breakpoint",
416 [EXCP_SYSCALL
] = "syscall",
417 [EXCP_BREAK
] = "break",
418 [EXCP_CpU
] = "coprocessor unusable",
419 [EXCP_RI
] = "reserved instruction",
420 [EXCP_OVERFLOW
] = "arithmetic overflow",
421 [EXCP_TRAP
] = "trap",
422 [EXCP_FPE
] = "floating point",
423 [EXCP_DDBS
] = "debug data break store",
424 [EXCP_DWATCH
] = "data watchpoint",
425 [EXCP_LTLBL
] = "TLB modify",
426 [EXCP_TLBL
] = "TLB load",
427 [EXCP_TLBS
] = "TLB store",
428 [EXCP_DBE
] = "data bus error",
429 [EXCP_DDBL
] = "debug data break load",
430 [EXCP_THREAD
] = "thread",
431 [EXCP_MDMX
] = "MDMX",
432 [EXCP_C2E
] = "precise coprocessor 2",
433 [EXCP_CACHE
] = "cache error",
434 [EXCP_TLBXI
] = "TLB execute-inhibit",
435 [EXCP_TLBRI
] = "TLB read-inhibit",
436 [EXCP_MSADIS
] = "MSA disabled",
437 [EXCP_MSAFPE
] = "MSA floating point",
441 target_ulong
exception_resume_pc (CPUMIPSState
*env
)
444 target_ulong isa_mode
;
446 isa_mode
= !!(env
->hflags
& MIPS_HFLAG_M16
);
447 bad_pc
= env
->active_tc
.PC
| isa_mode
;
448 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
449 /* If the exception was raised from a delay slot, come back to
451 bad_pc
-= (env
->hflags
& MIPS_HFLAG_B16
? 2 : 4);
457 #if !defined(CONFIG_USER_ONLY)
458 static void set_hflags_for_handler (CPUMIPSState
*env
)
460 /* Exception handlers are entered in 32-bit mode. */
461 env
->hflags
&= ~(MIPS_HFLAG_M16
);
462 /* ...except that microMIPS lets you choose. */
463 if (env
->insn_flags
& ASE_MICROMIPS
) {
464 env
->hflags
|= (!!(env
->CP0_Config3
465 & (1 << CP0C3_ISA_ON_EXC
))
466 << MIPS_HFLAG_M16_SHIFT
);
470 static inline void set_badinstr_registers(CPUMIPSState
*env
)
472 if (env
->hflags
& MIPS_HFLAG_M16
) {
473 /* TODO: add BadInstr support for microMIPS */
476 if (env
->CP0_Config3
& (1 << CP0C3_BI
)) {
477 env
->CP0_BadInstr
= cpu_ldl_code(env
, env
->active_tc
.PC
);
479 if ((env
->CP0_Config3
& (1 << CP0C3_BP
)) &&
480 (env
->hflags
& MIPS_HFLAG_BMASK
)) {
481 env
->CP0_BadInstrP
= cpu_ldl_code(env
, env
->active_tc
.PC
- 4);
486 void mips_cpu_do_interrupt(CPUState
*cs
)
488 #if !defined(CONFIG_USER_ONLY)
489 MIPSCPU
*cpu
= MIPS_CPU(cs
);
490 CPUMIPSState
*env
= &cpu
->env
;
491 bool update_badinstr
= 0;
496 if (qemu_loglevel_mask(CPU_LOG_INT
)
497 && cs
->exception_index
!= EXCP_EXT_INTERRUPT
) {
498 if (cs
->exception_index
< 0 || cs
->exception_index
> EXCP_LAST
) {
501 name
= excp_names
[cs
->exception_index
];
504 qemu_log("%s enter: PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
506 __func__
, env
->active_tc
.PC
, env
->CP0_EPC
, name
);
508 if (cs
->exception_index
== EXCP_EXT_INTERRUPT
&&
509 (env
->hflags
& MIPS_HFLAG_DM
)) {
510 cs
->exception_index
= EXCP_DINT
;
513 switch (cs
->exception_index
) {
515 env
->CP0_Debug
|= 1 << CP0DB_DSS
;
516 /* Debug single step cannot be raised inside a delay slot and
517 resume will always occur on the next instruction
518 (but we assume the pc has always been updated during
519 code translation). */
520 env
->CP0_DEPC
= env
->active_tc
.PC
| !!(env
->hflags
& MIPS_HFLAG_M16
);
521 goto enter_debug_mode
;
523 env
->CP0_Debug
|= 1 << CP0DB_DINT
;
526 env
->CP0_Debug
|= 1 << CP0DB_DIB
;
529 env
->CP0_Debug
|= 1 << CP0DB_DBp
;
532 env
->CP0_Debug
|= 1 << CP0DB_DDBS
;
535 env
->CP0_Debug
|= 1 << CP0DB_DDBL
;
537 env
->CP0_DEPC
= exception_resume_pc(env
);
538 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
540 if (env
->insn_flags
& ISA_MIPS3
) {
541 env
->hflags
|= MIPS_HFLAG_64
;
543 env
->hflags
|= MIPS_HFLAG_DM
| MIPS_HFLAG_CP0
;
544 env
->hflags
&= ~(MIPS_HFLAG_KSU
);
545 /* EJTAG probe trap enable is not implemented... */
546 if (!(env
->CP0_Status
& (1 << CP0St_EXL
)))
547 env
->CP0_Cause
&= ~(1U << CP0Ca_BD
);
548 env
->active_tc
.PC
= (int32_t)0xBFC00480;
549 set_hflags_for_handler(env
);
555 env
->CP0_Status
|= (1 << CP0St_SR
);
556 memset(env
->CP0_WatchLo
, 0, sizeof(*env
->CP0_WatchLo
));
559 env
->CP0_Status
|= (1 << CP0St_NMI
);
561 env
->CP0_ErrorEPC
= exception_resume_pc(env
);
562 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
563 env
->CP0_Status
|= (1 << CP0St_ERL
) | (1 << CP0St_BEV
);
564 if (env
->insn_flags
& ISA_MIPS3
) {
565 env
->hflags
|= MIPS_HFLAG_64
;
567 env
->hflags
|= MIPS_HFLAG_CP0
;
568 env
->hflags
&= ~(MIPS_HFLAG_KSU
);
569 if (!(env
->CP0_Status
& (1 << CP0St_EXL
)))
570 env
->CP0_Cause
&= ~(1U << CP0Ca_BD
);
571 env
->active_tc
.PC
= (int32_t)0xBFC00000;
572 set_hflags_for_handler(env
);
574 case EXCP_EXT_INTERRUPT
:
576 if (env
->CP0_Cause
& (1 << CP0Ca_IV
)) {
577 uint32_t spacing
= (env
->CP0_IntCtl
>> CP0IntCtl_VS
) & 0x1f;
579 if ((env
->CP0_Status
& (1 << CP0St_BEV
)) || spacing
== 0) {
583 uint32_t pending
= (env
->CP0_Cause
& CP0Ca_IP_mask
) >> CP0Ca_IP
;
585 if (env
->CP0_Config3
& (1 << CP0C3_VEIC
)) {
586 /* For VEIC mode, the external interrupt controller feeds
587 * the vector through the CP0Cause IP lines. */
590 /* Vectored Interrupts
591 * Mask with Status.IM7-IM0 to get enabled interrupts. */
592 pending
&= (env
->CP0_Status
>> CP0St_IM
) & 0xff;
593 /* Find the highest-priority interrupt. */
594 while (pending
>>= 1) {
598 offset
= 0x200 + (vector
* (spacing
<< 5));
604 update_badinstr
= !(env
->error_code
& EXCP_INST_NOTAVAIL
);
608 update_badinstr
= !(env
->error_code
& EXCP_INST_NOTAVAIL
);
609 if ((env
->error_code
& EXCP_TLB_NOMATCH
) &&
610 !(env
->CP0_Status
& (1 << CP0St_EXL
))) {
611 #if defined(TARGET_MIPS64)
612 int R
= env
->CP0_BadVAddr
>> 62;
613 int UX
= (env
->CP0_Status
& (1 << CP0St_UX
)) != 0;
614 int SX
= (env
->CP0_Status
& (1 << CP0St_SX
)) != 0;
615 int KX
= (env
->CP0_Status
& (1 << CP0St_KX
)) != 0;
617 if (((R
== 0 && UX
) || (R
== 1 && SX
) || (R
== 3 && KX
)) &&
618 (!(env
->insn_flags
& (INSN_LOONGSON2E
| INSN_LOONGSON2F
))))
628 if ((env
->error_code
& EXCP_TLB_NOMATCH
) &&
629 !(env
->CP0_Status
& (1 << CP0St_EXL
))) {
630 #if defined(TARGET_MIPS64)
631 int R
= env
->CP0_BadVAddr
>> 62;
632 int UX
= (env
->CP0_Status
& (1 << CP0St_UX
)) != 0;
633 int SX
= (env
->CP0_Status
& (1 << CP0St_SX
)) != 0;
634 int KX
= (env
->CP0_Status
& (1 << CP0St_KX
)) != 0;
636 if (((R
== 0 && UX
) || (R
== 1 && SX
) || (R
== 3 && KX
)) &&
637 (!(env
->insn_flags
& (INSN_LOONGSON2E
| INSN_LOONGSON2F
))))
646 update_badinstr
= !(env
->error_code
& EXCP_INST_NOTAVAIL
);
673 env
->CP0_Cause
= (env
->CP0_Cause
& ~(0x3 << CP0Ca_CE
)) |
674 (env
->error_code
<< CP0Ca_CE
);
711 /* XXX: TODO: manage defered watch exceptions */
724 if (env
->CP0_Status
& (1 << CP0St_BEV
)) {
730 if (!(env
->CP0_Status
& (1 << CP0St_EXL
))) {
731 env
->CP0_EPC
= exception_resume_pc(env
);
732 if (update_badinstr
) {
733 set_badinstr_registers(env
);
735 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
736 env
->CP0_Cause
|= (1U << CP0Ca_BD
);
738 env
->CP0_Cause
&= ~(1U << CP0Ca_BD
);
740 env
->CP0_Status
|= (1 << CP0St_EXL
);
741 if (env
->insn_flags
& ISA_MIPS3
) {
742 env
->hflags
|= MIPS_HFLAG_64
;
744 env
->hflags
|= MIPS_HFLAG_CP0
;
745 env
->hflags
&= ~(MIPS_HFLAG_KSU
);
747 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
748 if (env
->CP0_Status
& (1 << CP0St_BEV
)) {
749 env
->active_tc
.PC
= (int32_t)0xBFC00200;
751 env
->active_tc
.PC
= (int32_t)(env
->CP0_EBase
& ~0x3ff);
753 env
->active_tc
.PC
+= offset
;
754 set_hflags_for_handler(env
);
755 env
->CP0_Cause
= (env
->CP0_Cause
& ~(0x1f << CP0Ca_EC
)) | (cause
<< CP0Ca_EC
);
760 if (qemu_loglevel_mask(CPU_LOG_INT
)
761 && cs
->exception_index
!= EXCP_EXT_INTERRUPT
) {
762 qemu_log("%s: PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
" cause %d\n"
763 " S %08x C %08x A " TARGET_FMT_lx
" D " TARGET_FMT_lx
"\n",
764 __func__
, env
->active_tc
.PC
, env
->CP0_EPC
, cause
,
765 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_BadVAddr
,
769 cs
->exception_index
= EXCP_NONE
;
772 bool mips_cpu_exec_interrupt(CPUState
*cs
, int interrupt_request
)
774 if (interrupt_request
& CPU_INTERRUPT_HARD
) {
775 MIPSCPU
*cpu
= MIPS_CPU(cs
);
776 CPUMIPSState
*env
= &cpu
->env
;
778 if (cpu_mips_hw_interrupts_pending(env
)) {
780 cs
->exception_index
= EXCP_EXT_INTERRUPT
;
782 mips_cpu_do_interrupt(cs
);
789 #if !defined(CONFIG_USER_ONLY)
790 void r4k_invalidate_tlb (CPUMIPSState
*env
, int idx
, int use_extra
)
792 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
797 uint8_t ASID
= env
->CP0_EntryHi
& 0xFF;
800 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
801 /* The qemu TLB is flushed when the ASID changes, so no need to
802 flush these entries again. */
803 if (tlb
->G
== 0 && tlb
->ASID
!= ASID
) {
807 if (use_extra
&& env
->tlb
->tlb_in_use
< MIPS_TLB_MAX
) {
808 /* For tlbwr, we can shadow the discarded entry into
809 a new (fake) TLB entry, as long as the guest can not
810 tell that it's there. */
811 env
->tlb
->mmu
.r4k
.tlb
[env
->tlb
->tlb_in_use
] = *tlb
;
812 env
->tlb
->tlb_in_use
++;
816 /* 1k pages are not supported. */
817 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
820 addr
= tlb
->VPN
& ~mask
;
821 #if defined(TARGET_MIPS64)
822 if (addr
>= (0xFFFFFFFF80000000ULL
& env
->SEGMask
)) {
823 addr
|= 0x3FFFFF0000000000ULL
;
826 end
= addr
| (mask
>> 1);
828 // optimize memset in tlb_flush_page!!!
829 tlb_flush_page(cs
, addr
);
830 addr
+= TARGET_PAGE_SIZE
;
835 addr
= (tlb
->VPN
& ~mask
) | ((mask
>> 1) + 1);
836 #if defined(TARGET_MIPS64)
837 if (addr
>= (0xFFFFFFFF80000000ULL
& env
->SEGMask
)) {
838 addr
|= 0x3FFFFF0000000000ULL
;
842 while (addr
- 1 < end
) {
843 // optimize memset in tlb_flush_page!!!
844 tlb_flush_page(cs
, addr
);
845 addr
+= TARGET_PAGE_SIZE
;