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/>.
19 #include "qemu/osdep.h"
22 #include "sysemu/kvm.h"
23 #include "exec/cpu_ldst.h"
36 #if !defined(CONFIG_USER_ONLY)
38 /* no MMU emulation */
39 int no_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
40 target_ulong address, int rw, int access_type)
43 *prot = PAGE_READ | PAGE_WRITE;
47 /* fixed mapping MMU emulation */
48 int fixed_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
49 target_ulong address, int rw, int access_type)
51 if (address <= (int32_t)0x7FFFFFFFUL) {
52 if (!(env->CP0_Status & (1 << CP0St_ERL)))
53 *physical = address + 0x40000000UL;
56 } else if (address <= (int32_t)0xBFFFFFFFUL)
57 *physical = address & 0x1FFFFFFF;
61 *prot = PAGE_READ | PAGE_WRITE;
65 /* MIPS32/MIPS64 R4000-style MMU emulation */
66 int r4k_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
67 target_ulong address, int rw, int access_type)
69 uint8_t ASID = env->CP0_EntryHi & 0xFF;
72 for (i = 0; i < env->tlb->tlb_in_use; i++) {
73 r4k_tlb_t *tlb = &env->tlb->mmu.r4k.tlb[i];
74 /* 1k pages are not supported. */
75 target_ulong mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
76 target_ulong tag = address & ~mask;
77 target_ulong VPN = tlb->VPN & ~mask;
78 #if defined(TARGET_MIPS64)
82 /* Check ASID, virtual page number & size */
83 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag && !tlb->EHINV) {
85 int n = !!(address & mask & ~(mask >> 1));
86 /* Check access rights */
87 if (!(n ? tlb->V1 : tlb->V0)) {
88 return TLBRET_INVALID;
90 if (rw == MMU_INST_FETCH && (n ? tlb->XI1 : tlb->XI0)) {
93 if (rw == MMU_DATA_LOAD && (n ? tlb->RI1 : tlb->RI0)) {
96 if (rw != MMU_DATA_STORE || (n ? tlb->D1 : tlb->D0)) {
97 *physical = tlb->PFN[n] | (address & (mask >> 1));
99 if (n ? tlb->D1 : tlb->D0)
106 return TLBRET_NOMATCH;
109 static int get_physical_address (CPUMIPSState *env, hwaddr *physical,
110 int *prot, target_ulong real_address,
111 int rw, int access_type)
113 /* User mode can only access useg/xuseg */
114 int user_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM;
115 int supervisor_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_SM;
116 int kernel_mode = !user_mode && !supervisor_mode;
117 #if defined(TARGET_MIPS64)
118 int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0;
119 int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0;
120 int KX = (env->CP0_Status & (1 << CP0St_KX)) != 0;
122 int ret = TLBRET_MATCH;
123 /* effective address (modified for KVM T&E kernel segments) */
124 target_ulong address = real_address;
126 #define USEG_LIMIT 0x7FFFFFFFUL
127 #define KSEG0_BASE 0x80000000UL
128 #define KSEG1_BASE 0xA0000000UL
129 #define KSEG2_BASE 0xC0000000UL
130 #define KSEG3_BASE 0xE0000000UL
132 #define KVM_KSEG0_BASE 0x40000000UL
133 #define KVM_KSEG2_BASE 0x60000000UL
136 /* KVM T&E adds guest kernel segments in useg */
137 if (real_address >= KVM_KSEG0_BASE) {
138 if (real_address < KVM_KSEG2_BASE) {
140 address += KSEG0_BASE - KVM_KSEG0_BASE;
141 } else if (real_address <= USEG_LIMIT) {
143 address += KSEG2_BASE - KVM_KSEG2_BASE;
148 if (address <= USEG_LIMIT) {
150 if (env->CP0_Status & (1 << CP0St_ERL)) {
151 *physical = address & 0xFFFFFFFF;
152 *prot = PAGE_READ | PAGE_WRITE;
154 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
156 #if defined(TARGET_MIPS64)
157 } else if (address < 0x4000000000000000ULL) {
159 if (UX && address <= (0x3FFFFFFFFFFFFFFFULL & env->SEGMask)) {
160 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
162 ret = TLBRET_BADADDR;
164 } else if (address < 0x8000000000000000ULL) {
166 if ((supervisor_mode || kernel_mode) &&
167 SX && address <= (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) {
168 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
170 ret = TLBRET_BADADDR;
172 } else if (address < 0xC000000000000000ULL) {
174 if (kernel_mode && KX &&
175 (address & 0x07FFFFFFFFFFFFFFULL) <= env->PAMask) {
176 *physical = address & env->PAMask;
177 *prot = PAGE_READ | PAGE_WRITE;
179 ret = TLBRET_BADADDR;
181 } else if (address < 0xFFFFFFFF80000000ULL) {
183 if (kernel_mode && KX &&
184 address <= (0xFFFFFFFF7FFFFFFFULL & env->SEGMask)) {
185 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
187 ret = TLBRET_BADADDR;
190 } else if (address < (int32_t)KSEG1_BASE) {
193 *physical = address - (int32_t)KSEG0_BASE;
194 *prot = PAGE_READ | PAGE_WRITE;
196 ret = TLBRET_BADADDR;
198 } else if (address < (int32_t)KSEG2_BASE) {
201 *physical = address - (int32_t)KSEG1_BASE;
202 *prot = PAGE_READ | PAGE_WRITE;
204 ret = TLBRET_BADADDR;
206 } else if (address < (int32_t)KSEG3_BASE) {
208 if (supervisor_mode || kernel_mode) {
209 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
211 ret = TLBRET_BADADDR;
215 /* XXX: debug segment is not emulated */
217 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
219 ret = TLBRET_BADADDR;
226 static void raise_mmu_exception(CPUMIPSState *env, target_ulong address,
227 int rw, int tlb_error)
229 CPUState *cs = CPU(mips_env_get_cpu(env));
230 int exception = 0, error_code = 0;
232 if (rw == MMU_INST_FETCH) {
233 error_code |= EXCP_INST_NOTAVAIL;
239 /* Reference to kernel address from user mode or supervisor mode */
240 /* Reference to supervisor address from user mode */
241 if (rw == MMU_DATA_STORE) {
242 exception = EXCP_AdES;
244 exception = EXCP_AdEL;
248 /* No TLB match for a mapped address */
249 if (rw == MMU_DATA_STORE) {
250 exception = EXCP_TLBS;
252 exception = EXCP_TLBL;
254 error_code |= EXCP_TLB_NOMATCH;
257 /* TLB match with no valid bit */
258 if (rw == MMU_DATA_STORE) {
259 exception = EXCP_TLBS;
261 exception = EXCP_TLBL;
265 /* TLB match but 'D' bit is cleared */
266 exception = EXCP_LTLBL;
269 /* Execute-Inhibit Exception */
270 if (env->CP0_PageGrain & (1 << CP0PG_IEC)) {
271 exception = EXCP_TLBXI;
273 exception = EXCP_TLBL;
277 /* Read-Inhibit Exception */
278 if (env->CP0_PageGrain & (1 << CP0PG_IEC)) {
279 exception = EXCP_TLBRI;
281 exception = EXCP_TLBL;
285 /* Raise exception */
286 env->CP0_BadVAddr = address;
287 env->CP0_Context = (env->CP0_Context & ~0x007fffff) |
288 ((address >> 9) & 0x007ffff0);
290 (env->CP0_EntryHi & 0xFF) | (address & (TARGET_PAGE_MASK << 1));
291 #if defined(TARGET_MIPS64)
292 env->CP0_EntryHi &= env->SEGMask;
294 /* PTEBase */ (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |
295 /* R */ (extract64(address, 62, 2) << (env->SEGBITS - 9)) |
296 /* BadVPN2 */ (extract64(address, 13, env->SEGBITS - 13) << 4);
298 cs->exception_index = exception;
299 env->error_code = error_code;
302 #if !defined(CONFIG_USER_ONLY)
303 hwaddr mips_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
305 MIPSCPU *cpu = MIPS_CPU(cs);
309 if (get_physical_address(&cpu->env, &phys_addr, &prot, addr, 0,
317 int mips_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
320 MIPSCPU *cpu = MIPS_CPU(cs);
321 CPUMIPSState *env = &cpu->env;
322 #if !defined(CONFIG_USER_ONLY)
330 log_cpu_state(cs, 0);
332 qemu_log_mask(CPU_LOG_MMU,
333 "%s pc " TARGET_FMT_lx " ad %" VADDR_PRIx " rw %d mmu_idx %d\n",
334 __func__, env->active_tc.PC, address, rw, mmu_idx);
337 #if !defined(CONFIG_USER_ONLY)
338 /* XXX: put correct access by using cpu_restore_state()
340 access_type = ACCESS_INT;
341 ret = get_physical_address(env, &physical, &prot,
342 address, rw, access_type);
343 qemu_log_mask(CPU_LOG_MMU,
344 "%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx
346 __func__, address, ret, physical, prot);
347 if (ret == TLBRET_MATCH) {
348 tlb_set_page(cs, address & TARGET_PAGE_MASK,
349 physical & TARGET_PAGE_MASK, prot | PAGE_EXEC,
350 mmu_idx, TARGET_PAGE_SIZE);
355 raise_mmu_exception(env, address, rw, ret);
362 #if !defined(CONFIG_USER_ONLY)
363 hwaddr cpu_mips_translate_address(CPUMIPSState *env, target_ulong address, int rw)
371 access_type = ACCESS_INT;
372 ret = get_physical_address(env, &physical, &prot,
373 address, rw, access_type);
374 if (ret != TLBRET_MATCH) {
375 raise_mmu_exception(env, address, rw, ret);
382 static const char * const excp_names[EXCP_LAST + 1] = {
383 [EXCP_RESET] = "reset",
384 [EXCP_SRESET] = "soft reset",
385 [EXCP_DSS] = "debug single step",
386 [EXCP_DINT] = "debug interrupt",
387 [EXCP_NMI] = "non-maskable interrupt",
388 [EXCP_MCHECK] = "machine check",
389 [EXCP_EXT_INTERRUPT] = "interrupt",
390 [EXCP_DFWATCH] = "deferred watchpoint",
391 [EXCP_DIB] = "debug instruction breakpoint",
392 [EXCP_IWATCH] = "instruction fetch watchpoint",
393 [EXCP_AdEL] = "address error load",
394 [EXCP_AdES] = "address error store",
395 [EXCP_TLBF] = "TLB refill",
396 [EXCP_IBE] = "instruction bus error",
397 [EXCP_DBp] = "debug breakpoint",
398 [EXCP_SYSCALL] = "syscall",
399 [EXCP_BREAK] = "break",
400 [EXCP_CpU] = "coprocessor unusable",
401 [EXCP_RI] = "reserved instruction",
402 [EXCP_OVERFLOW] = "arithmetic overflow",
403 [EXCP_TRAP] = "trap",
404 [EXCP_FPE] = "floating point",
405 [EXCP_DDBS] = "debug data break store",
406 [EXCP_DWATCH] = "data watchpoint",
407 [EXCP_LTLBL] = "TLB modify",
408 [EXCP_TLBL] = "TLB load",
409 [EXCP_TLBS] = "TLB store",
410 [EXCP_DBE] = "data bus error",
411 [EXCP_DDBL] = "debug data break load",
412 [EXCP_THREAD] = "thread",
413 [EXCP_MDMX] = "MDMX",
414 [EXCP_C2E] = "precise coprocessor 2",
415 [EXCP_CACHE] = "cache error",
416 [EXCP_TLBXI] = "TLB execute-inhibit",
417 [EXCP_TLBRI] = "TLB read-inhibit",
418 [EXCP_MSADIS] = "MSA disabled",
419 [EXCP_MSAFPE] = "MSA floating point",
423 target_ulong exception_resume_pc (CPUMIPSState *env)
426 target_ulong isa_mode;
428 isa_mode = !!(env->hflags & MIPS_HFLAG_M16);
429 bad_pc = env->active_tc.PC | isa_mode;
430 if (env->hflags & MIPS_HFLAG_BMASK) {
431 /* If the exception was raised from a delay slot, come back to
433 bad_pc -= (env->hflags & MIPS_HFLAG_B16 ? 2 : 4);
439 #if !defined(CONFIG_USER_ONLY)
440 static void set_hflags_for_handler (CPUMIPSState *env)
442 /* Exception handlers are entered in 32-bit mode. */
443 env->hflags &= ~(MIPS_HFLAG_M16);
444 /* ...except that microMIPS lets you choose. */
445 if (env->insn_flags & ASE_MICROMIPS) {
446 env->hflags |= (!!(env->CP0_Config3
447 & (1 << CP0C3_ISA_ON_EXC))
448 << MIPS_HFLAG_M16_SHIFT);
452 static inline void set_badinstr_registers(CPUMIPSState *env)
454 if (env->hflags & MIPS_HFLAG_M16) {
455 /* TODO: add BadInstr support for microMIPS */
458 if (env->CP0_Config3 & (1 << CP0C3_BI)) {
459 env->CP0_BadInstr = cpu_ldl_code(env, env->active_tc.PC);
461 if ((env->CP0_Config3 & (1 << CP0C3_BP)) &&
462 (env->hflags & MIPS_HFLAG_BMASK)) {
463 env->CP0_BadInstrP = cpu_ldl_code(env, env->active_tc.PC - 4);
468 void mips_cpu_do_interrupt(CPUState *cs)
470 #if !defined(CONFIG_USER_ONLY)
471 MIPSCPU *cpu = MIPS_CPU(cs);
472 CPUMIPSState *env = &cpu->env;
473 bool update_badinstr = 0;
478 if (qemu_loglevel_mask(CPU_LOG_INT)
479 && cs->exception_index != EXCP_EXT_INTERRUPT) {
480 if (cs->exception_index < 0 || cs->exception_index > EXCP_LAST) {
483 name = excp_names[cs->exception_index];
486 qemu_log("%s enter: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx
488 __func__, env->active_tc.PC, env->CP0_EPC, name);
490 if (cs->exception_index == EXCP_EXT_INTERRUPT &&
491 (env->hflags & MIPS_HFLAG_DM)) {
492 cs->exception_index = EXCP_DINT;
495 switch (cs->exception_index) {
497 env->CP0_Debug |= 1 << CP0DB_DSS;
498 /* Debug single step cannot be raised inside a delay slot and
499 resume will always occur on the next instruction
500 (but we assume the pc has always been updated during
501 code translation). */
502 env->CP0_DEPC = env->active_tc.PC | !!(env->hflags & MIPS_HFLAG_M16);
503 goto enter_debug_mode;
505 env->CP0_Debug |= 1 << CP0DB_DINT;
508 env->CP0_Debug |= 1 << CP0DB_DIB;
511 env->CP0_Debug |= 1 << CP0DB_DBp;
514 env->CP0_Debug |= 1 << CP0DB_DDBS;
517 env->CP0_Debug |= 1 << CP0DB_DDBL;
519 env->CP0_DEPC = exception_resume_pc(env);
520 env->hflags &= ~MIPS_HFLAG_BMASK;
522 if (env->insn_flags & ISA_MIPS3) {
523 env->hflags |= MIPS_HFLAG_64;
524 if (!(env->insn_flags & ISA_MIPS64R6) ||
525 env->CP0_Status & (1 << CP0St_KX)) {
526 env->hflags &= ~MIPS_HFLAG_AWRAP;
529 env->hflags |= MIPS_HFLAG_DM | MIPS_HFLAG_CP0;
530 env->hflags &= ~(MIPS_HFLAG_KSU);
531 /* EJTAG probe trap enable is not implemented... */
532 if (!(env->CP0_Status & (1 << CP0St_EXL)))
533 env->CP0_Cause &= ~(1U << CP0Ca_BD);
534 env->active_tc.PC = (int32_t)0xBFC00480;
535 set_hflags_for_handler(env);
541 env->CP0_Status |= (1 << CP0St_SR);
542 memset(env->CP0_WatchLo, 0, sizeof(*env->CP0_WatchLo));
545 env->CP0_Status |= (1 << CP0St_NMI);
547 env->CP0_ErrorEPC = exception_resume_pc(env);
548 env->hflags &= ~MIPS_HFLAG_BMASK;
549 env->CP0_Status |= (1 << CP0St_ERL) | (1 << CP0St_BEV);
550 if (env->insn_flags & ISA_MIPS3) {
551 env->hflags |= MIPS_HFLAG_64;
552 if (!(env->insn_flags & ISA_MIPS64R6) ||
553 env->CP0_Status & (1 << CP0St_KX)) {
554 env->hflags &= ~MIPS_HFLAG_AWRAP;
557 env->hflags |= MIPS_HFLAG_CP0;
558 env->hflags &= ~(MIPS_HFLAG_KSU);
559 if (!(env->CP0_Status & (1 << CP0St_EXL)))
560 env->CP0_Cause &= ~(1U << CP0Ca_BD);
561 env->active_tc.PC = (int32_t)0xBFC00000;
562 set_hflags_for_handler(env);
564 case EXCP_EXT_INTERRUPT:
566 if (env->CP0_Cause & (1 << CP0Ca_IV)) {
567 uint32_t spacing = (env->CP0_IntCtl >> CP0IntCtl_VS) & 0x1f;
569 if ((env->CP0_Status & (1 << CP0St_BEV)) || spacing == 0) {
573 uint32_t pending = (env->CP0_Cause & CP0Ca_IP_mask) >> CP0Ca_IP;
575 if (env->CP0_Config3 & (1 << CP0C3_VEIC)) {
576 /* For VEIC mode, the external interrupt controller feeds
577 * the vector through the CP0Cause IP lines. */
580 /* Vectored Interrupts
581 * Mask with Status.IM7-IM0 to get enabled interrupts. */
582 pending &= (env->CP0_Status >> CP0St_IM) & 0xff;
583 /* Find the highest-priority interrupt. */
584 while (pending >>= 1) {
588 offset = 0x200 + (vector * (spacing << 5));
594 update_badinstr = !(env->error_code & EXCP_INST_NOTAVAIL);
598 update_badinstr = !(env->error_code & EXCP_INST_NOTAVAIL);
599 if ((env->error_code & EXCP_TLB_NOMATCH) &&
600 !(env->CP0_Status & (1 << CP0St_EXL))) {
601 #if defined(TARGET_MIPS64)
602 int R = env->CP0_BadVAddr >> 62;
603 int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0;
604 int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0;
605 int KX = (env->CP0_Status & (1 << CP0St_KX)) != 0;
607 if (((R == 0 && UX) || (R == 1 && SX) || (R == 3 && KX)) &&
608 (!(env->insn_flags & (INSN_LOONGSON2E | INSN_LOONGSON2F))))
618 if ((env->error_code & EXCP_TLB_NOMATCH) &&
619 !(env->CP0_Status & (1 << CP0St_EXL))) {
620 #if defined(TARGET_MIPS64)
621 int R = env->CP0_BadVAddr >> 62;
622 int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0;
623 int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0;
624 int KX = (env->CP0_Status & (1 << CP0St_KX)) != 0;
626 if (((R == 0 && UX) || (R == 1 && SX) || (R == 3 && KX)) &&
627 (!(env->insn_flags & (INSN_LOONGSON2E | INSN_LOONGSON2F))))
636 update_badinstr = !(env->error_code & EXCP_INST_NOTAVAIL);
663 env->CP0_Cause = (env->CP0_Cause & ~(0x3 << CP0Ca_CE)) |
664 (env->error_code << CP0Ca_CE);
701 /* XXX: TODO: manage deferred watch exceptions */
714 if (env->CP0_Status & (1 << CP0St_BEV)) {
720 if (!(env->CP0_Status & (1 << CP0St_EXL))) {
721 env->CP0_EPC = exception_resume_pc(env);
722 if (update_badinstr) {
723 set_badinstr_registers(env);
725 if (env->hflags & MIPS_HFLAG_BMASK) {
726 env->CP0_Cause |= (1U << CP0Ca_BD);
728 env->CP0_Cause &= ~(1U << CP0Ca_BD);
730 env->CP0_Status |= (1 << CP0St_EXL);
731 if (env->insn_flags & ISA_MIPS3) {
732 env->hflags |= MIPS_HFLAG_64;
733 if (!(env->insn_flags & ISA_MIPS64R6) ||
734 env->CP0_Status & (1 << CP0St_KX)) {
735 env->hflags &= ~MIPS_HFLAG_AWRAP;
738 env->hflags |= MIPS_HFLAG_CP0;
739 env->hflags &= ~(MIPS_HFLAG_KSU);
741 env->hflags &= ~MIPS_HFLAG_BMASK;
742 if (env->CP0_Status & (1 << CP0St_BEV)) {
743 env->active_tc.PC = (int32_t)0xBFC00200;
745 env->active_tc.PC = (int32_t)(env->CP0_EBase & ~0x3ff);
747 env->active_tc.PC += offset;
748 set_hflags_for_handler(env);
749 env->CP0_Cause = (env->CP0_Cause & ~(0x1f << CP0Ca_EC)) | (cause << CP0Ca_EC);
754 if (qemu_loglevel_mask(CPU_LOG_INT)
755 && cs->exception_index != EXCP_EXT_INTERRUPT) {
756 qemu_log("%s: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx " cause %d\n"
757 " S %08x C %08x A " TARGET_FMT_lx " D " TARGET_FMT_lx "\n",
758 __func__, env->active_tc.PC, env->CP0_EPC, cause,
759 env->CP0_Status, env->CP0_Cause, env->CP0_BadVAddr,
763 cs->exception_index = EXCP_NONE;
766 bool mips_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
768 if (interrupt_request & CPU_INTERRUPT_HARD) {
769 MIPSCPU *cpu = MIPS_CPU(cs);
770 CPUMIPSState *env = &cpu->env;
772 if (cpu_mips_hw_interrupts_enabled(env) &&
773 cpu_mips_hw_interrupts_pending(env)) {
775 cs->exception_index = EXCP_EXT_INTERRUPT;
777 mips_cpu_do_interrupt(cs);
784 #if !defined(CONFIG_USER_ONLY)
785 void r4k_invalidate_tlb (CPUMIPSState *env, int idx, int use_extra)
787 MIPSCPU *cpu = mips_env_get_cpu(env);
792 uint8_t ASID = env->CP0_EntryHi & 0xFF;
795 tlb = &env->tlb->mmu.r4k.tlb[idx];
796 /* The qemu TLB is flushed when the ASID changes, so no need to
797 flush these entries again. */
798 if (tlb->G == 0 && tlb->ASID != ASID) {
802 if (use_extra && env->tlb->tlb_in_use < MIPS_TLB_MAX) {
803 /* For tlbwr, we can shadow the discarded entry into
804 a new (fake) TLB entry, as long as the guest can not
805 tell that it's there. */
806 env->tlb->mmu.r4k.tlb[env->tlb->tlb_in_use] = *tlb;
807 env->tlb->tlb_in_use++;
811 /* 1k pages are not supported. */
812 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
815 addr = tlb->VPN & ~mask;
816 #if defined(TARGET_MIPS64)
817 if (addr >= (0xFFFFFFFF80000000ULL & env->SEGMask)) {
818 addr |= 0x3FFFFF0000000000ULL;
821 end = addr | (mask >> 1);
823 tlb_flush_page(cs, addr);
824 addr += TARGET_PAGE_SIZE;
829 addr = (tlb->VPN & ~mask) | ((mask >> 1) + 1);
830 #if defined(TARGET_MIPS64)
831 if (addr >= (0xFFFFFFFF80000000ULL & env->SEGMask)) {
832 addr |= 0x3FFFFF0000000000ULL;
836 while (addr - 1 < end) {
837 tlb_flush_page(cs, addr);
838 addr += TARGET_PAGE_SIZE;