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/>.
27 #include "sysemu/kvm.h"
28 #include "exec/cpu_ldst.h"
40 #if !defined(CONFIG_USER_ONLY)
42 /* no MMU emulation */
43 int no_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
44 target_ulong address, int rw, int access_type)
47 *prot = PAGE_READ | PAGE_WRITE;
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;
65 *prot = PAGE_READ | PAGE_WRITE;
69 /* MIPS32/MIPS64 R4000-style MMU emulation */
70 int r4k_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
71 target_ulong address, int rw, int access_type)
73 uint8_t ASID = env->CP0_EntryHi & 0xFF;
76 for (i = 0; i < env->tlb->tlb_in_use; i++) {
77 r4k_tlb_t *tlb = &env->tlb->mmu.r4k.tlb[i];
78 /* 1k pages are not supported. */
79 target_ulong mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
80 target_ulong tag = address & ~mask;
81 target_ulong VPN = tlb->VPN & ~mask;
82 #if defined(TARGET_MIPS64)
86 /* Check ASID, virtual page number & size */
87 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag && !tlb->EHINV) {
89 int n = !!(address & mask & ~(mask >> 1));
90 /* Check access rights */
91 if (!(n ? tlb->V1 : tlb->V0)) {
92 return TLBRET_INVALID;
94 if (rw == MMU_INST_FETCH && (n ? tlb->XI1 : tlb->XI0)) {
97 if (rw == MMU_DATA_LOAD && (n ? tlb->RI1 : tlb->RI0)) {
100 if (rw != MMU_DATA_STORE || (n ? tlb->D1 : tlb->D0)) {
101 *physical = tlb->PFN[n] | (address & (mask >> 1));
103 if (n ? tlb->D1 : tlb->D0)
110 return TLBRET_NOMATCH;
113 static int get_physical_address (CPUMIPSState *env, hwaddr *physical,
114 int *prot, target_ulong real_address,
115 int rw, int access_type)
117 /* User mode can only access useg/xuseg */
118 int user_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM;
119 int supervisor_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_SM;
120 int kernel_mode = !user_mode && !supervisor_mode;
121 #if defined(TARGET_MIPS64)
122 int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0;
123 int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0;
124 int KX = (env->CP0_Status & (1 << CP0St_KX)) != 0;
126 int ret = TLBRET_MATCH;
127 /* effective address (modified for KVM T&E kernel segments) */
128 target_ulong address = real_address;
131 qemu_log("user mode %d h %08x\n", user_mode, env->hflags);
134 #define USEG_LIMIT 0x7FFFFFFFUL
135 #define KSEG0_BASE 0x80000000UL
136 #define KSEG1_BASE 0xA0000000UL
137 #define KSEG2_BASE 0xC0000000UL
138 #define KSEG3_BASE 0xE0000000UL
140 #define KVM_KSEG0_BASE 0x40000000UL
141 #define KVM_KSEG2_BASE 0x60000000UL
144 /* KVM T&E adds guest kernel segments in useg */
145 if (real_address >= KVM_KSEG0_BASE) {
146 if (real_address < KVM_KSEG2_BASE) {
148 address += KSEG0_BASE - KVM_KSEG0_BASE;
149 } else if (real_address <= USEG_LIMIT) {
151 address += KSEG2_BASE - KVM_KSEG2_BASE;
156 if (address <= USEG_LIMIT) {
158 if (env->CP0_Status & (1 << CP0St_ERL)) {
159 *physical = address & 0xFFFFFFFF;
160 *prot = PAGE_READ | PAGE_WRITE;
162 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
164 #if defined(TARGET_MIPS64)
165 } else if (address < 0x4000000000000000ULL) {
167 if (UX && address <= (0x3FFFFFFFFFFFFFFFULL & env->SEGMask)) {
168 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
170 ret = TLBRET_BADADDR;
172 } else if (address < 0x8000000000000000ULL) {
174 if ((supervisor_mode || kernel_mode) &&
175 SX && address <= (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) {
176 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
178 ret = TLBRET_BADADDR;
180 } else if (address < 0xC000000000000000ULL) {
182 if (kernel_mode && KX &&
183 (address & 0x07FFFFFFFFFFFFFFULL) <= env->PAMask) {
184 *physical = address & env->PAMask;
185 *prot = PAGE_READ | PAGE_WRITE;
187 ret = TLBRET_BADADDR;
189 } else if (address < 0xFFFFFFFF80000000ULL) {
191 if (kernel_mode && KX &&
192 address <= (0xFFFFFFFF7FFFFFFFULL & env->SEGMask)) {
193 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
195 ret = TLBRET_BADADDR;
198 } else if (address < (int32_t)KSEG1_BASE) {
201 *physical = address - (int32_t)KSEG0_BASE;
202 *prot = PAGE_READ | PAGE_WRITE;
204 ret = TLBRET_BADADDR;
206 } else if (address < (int32_t)KSEG2_BASE) {
209 *physical = address - (int32_t)KSEG1_BASE;
210 *prot = PAGE_READ | PAGE_WRITE;
212 ret = TLBRET_BADADDR;
214 } else if (address < (int32_t)KSEG3_BASE) {
216 if (supervisor_mode || kernel_mode) {
217 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
219 ret = TLBRET_BADADDR;
223 /* XXX: debug segment is not emulated */
225 ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
227 ret = TLBRET_BADADDR;
231 qemu_log(TARGET_FMT_lx " %d %d => %" HWADDR_PRIx " %d (%d)\n",
232 address, rw, access_type, *physical, *prot, ret);
239 static void raise_mmu_exception(CPUMIPSState *env, target_ulong address,
240 int rw, int tlb_error)
242 CPUState *cs = CPU(mips_env_get_cpu(env));
243 int exception = 0, error_code = 0;
245 if (rw == MMU_INST_FETCH) {
246 error_code |= EXCP_INST_NOTAVAIL;
252 /* Reference to kernel address from user mode or supervisor mode */
253 /* Reference to supervisor address from user mode */
254 if (rw == MMU_DATA_STORE) {
255 exception = EXCP_AdES;
257 exception = EXCP_AdEL;
261 /* No TLB match for a mapped address */
262 if (rw == MMU_DATA_STORE) {
263 exception = EXCP_TLBS;
265 exception = EXCP_TLBL;
267 error_code |= EXCP_TLB_NOMATCH;
270 /* TLB match with no valid bit */
271 if (rw == MMU_DATA_STORE) {
272 exception = EXCP_TLBS;
274 exception = EXCP_TLBL;
278 /* TLB match but 'D' bit is cleared */
279 exception = EXCP_LTLBL;
282 /* Execute-Inhibit Exception */
283 if (env->CP0_PageGrain & (1 << CP0PG_IEC)) {
284 exception = EXCP_TLBXI;
286 exception = EXCP_TLBL;
290 /* Read-Inhibit Exception */
291 if (env->CP0_PageGrain & (1 << CP0PG_IEC)) {
292 exception = EXCP_TLBRI;
294 exception = EXCP_TLBL;
298 /* Raise exception */
299 env->CP0_BadVAddr = address;
300 env->CP0_Context = (env->CP0_Context & ~0x007fffff) |
301 ((address >> 9) & 0x007ffff0);
303 (env->CP0_EntryHi & 0xFF) | (address & (TARGET_PAGE_MASK << 1));
304 #if defined(TARGET_MIPS64)
305 env->CP0_EntryHi &= env->SEGMask;
306 env->CP0_XContext = (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |
307 ((address & 0xC00000000000ULL) >> (55 - env->SEGBITS)) |
308 ((address & ((1ULL << env->SEGBITS) - 1) & 0xFFFFFFFFFFFFE000ULL) >> 9);
310 cs->exception_index = exception;
311 env->error_code = error_code;
314 #if !defined(CONFIG_USER_ONLY)
315 hwaddr mips_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
317 MIPSCPU *cpu = MIPS_CPU(cs);
321 if (get_physical_address(&cpu->env, &phys_addr, &prot, addr, 0,
329 int mips_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
332 MIPSCPU *cpu = MIPS_CPU(cs);
333 CPUMIPSState *env = &cpu->env;
334 #if !defined(CONFIG_USER_ONLY)
342 log_cpu_state(cs, 0);
344 qemu_log("%s pc " TARGET_FMT_lx " ad %" VADDR_PRIx " rw %d mmu_idx %d\n",
345 __func__, env->active_tc.PC, address, rw, mmu_idx);
348 #if !defined(CONFIG_USER_ONLY)
349 /* XXX: put correct access by using cpu_restore_state()
351 access_type = ACCESS_INT;
352 ret = get_physical_address(env, &physical, &prot,
353 address, rw, access_type);
354 qemu_log("%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx
356 __func__, address, ret, physical, prot);
357 if (ret == TLBRET_MATCH) {
358 tlb_set_page(cs, address & TARGET_PAGE_MASK,
359 physical & TARGET_PAGE_MASK, prot | PAGE_EXEC,
360 mmu_idx, TARGET_PAGE_SIZE);
365 raise_mmu_exception(env, address, rw, ret);
372 #if !defined(CONFIG_USER_ONLY)
373 hwaddr cpu_mips_translate_address(CPUMIPSState *env, target_ulong address, int rw)
381 access_type = ACCESS_INT;
382 ret = get_physical_address(env, &physical, &prot,
383 address, rw, access_type);
384 if (ret != TLBRET_MATCH) {
385 raise_mmu_exception(env, address, rw, ret);
393 static const char * const excp_names[EXCP_LAST + 1] = {
394 [EXCP_RESET] = "reset",
395 [EXCP_SRESET] = "soft reset",
396 [EXCP_DSS] = "debug single step",
397 [EXCP_DINT] = "debug interrupt",
398 [EXCP_NMI] = "non-maskable interrupt",
399 [EXCP_MCHECK] = "machine check",
400 [EXCP_EXT_INTERRUPT] = "interrupt",
401 [EXCP_DFWATCH] = "deferred watchpoint",
402 [EXCP_DIB] = "debug instruction breakpoint",
403 [EXCP_IWATCH] = "instruction fetch watchpoint",
404 [EXCP_AdEL] = "address error load",
405 [EXCP_AdES] = "address error store",
406 [EXCP_TLBF] = "TLB refill",
407 [EXCP_IBE] = "instruction bus error",
408 [EXCP_DBp] = "debug breakpoint",
409 [EXCP_SYSCALL] = "syscall",
410 [EXCP_BREAK] = "break",
411 [EXCP_CpU] = "coprocessor unusable",
412 [EXCP_RI] = "reserved instruction",
413 [EXCP_OVERFLOW] = "arithmetic overflow",
414 [EXCP_TRAP] = "trap",
415 [EXCP_FPE] = "floating point",
416 [EXCP_DDBS] = "debug data break store",
417 [EXCP_DWATCH] = "data watchpoint",
418 [EXCP_LTLBL] = "TLB modify",
419 [EXCP_TLBL] = "TLB load",
420 [EXCP_TLBS] = "TLB store",
421 [EXCP_DBE] = "data bus error",
422 [EXCP_DDBL] = "debug data break load",
423 [EXCP_THREAD] = "thread",
424 [EXCP_MDMX] = "MDMX",
425 [EXCP_C2E] = "precise coprocessor 2",
426 [EXCP_CACHE] = "cache error",
427 [EXCP_TLBXI] = "TLB execute-inhibit",
428 [EXCP_TLBRI] = "TLB read-inhibit",
429 [EXCP_MSADIS] = "MSA disabled",
430 [EXCP_MSAFPE] = "MSA floating point",
433 target_ulong exception_resume_pc (CPUMIPSState *env)
436 target_ulong isa_mode;
438 isa_mode = !!(env->hflags & MIPS_HFLAG_M16);
439 bad_pc = env->active_tc.PC | isa_mode;
440 if (env->hflags & MIPS_HFLAG_BMASK) {
441 /* If the exception was raised from a delay slot, come back to
443 bad_pc -= (env->hflags & MIPS_HFLAG_B16 ? 2 : 4);
449 #if !defined(CONFIG_USER_ONLY)
450 static void set_hflags_for_handler (CPUMIPSState *env)
452 /* Exception handlers are entered in 32-bit mode. */
453 env->hflags &= ~(MIPS_HFLAG_M16);
454 /* ...except that microMIPS lets you choose. */
455 if (env->insn_flags & ASE_MICROMIPS) {
456 env->hflags |= (!!(env->CP0_Config3
457 & (1 << CP0C3_ISA_ON_EXC))
458 << MIPS_HFLAG_M16_SHIFT);
462 static inline void set_badinstr_registers(CPUMIPSState *env)
464 if (env->hflags & MIPS_HFLAG_M16) {
465 /* TODO: add BadInstr support for microMIPS */
468 if (env->CP0_Config3 & (1 << CP0C3_BI)) {
469 env->CP0_BadInstr = cpu_ldl_code(env, env->active_tc.PC);
471 if ((env->CP0_Config3 & (1 << CP0C3_BP)) &&
472 (env->hflags & MIPS_HFLAG_BMASK)) {
473 env->CP0_BadInstrP = cpu_ldl_code(env, env->active_tc.PC - 4);
478 void mips_cpu_do_interrupt(CPUState *cs)
480 #if !defined(CONFIG_USER_ONLY)
481 MIPSCPU *cpu = MIPS_CPU(cs);
482 CPUMIPSState *env = &cpu->env;
483 bool update_badinstr = 0;
488 if (qemu_log_enabled() && cs->exception_index != EXCP_EXT_INTERRUPT) {
489 if (cs->exception_index < 0 || cs->exception_index > EXCP_LAST) {
492 name = excp_names[cs->exception_index];
495 qemu_log("%s enter: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx " %s exception\n",
496 __func__, env->active_tc.PC, env->CP0_EPC, name);
498 if (cs->exception_index == EXCP_EXT_INTERRUPT &&
499 (env->hflags & MIPS_HFLAG_DM)) {
500 cs->exception_index = EXCP_DINT;
503 switch (cs->exception_index) {
505 env->CP0_Debug |= 1 << CP0DB_DSS;
506 /* Debug single step cannot be raised inside a delay slot and
507 resume will always occur on the next instruction
508 (but we assume the pc has always been updated during
509 code translation). */
510 env->CP0_DEPC = env->active_tc.PC | !!(env->hflags & MIPS_HFLAG_M16);
511 goto enter_debug_mode;
513 env->CP0_Debug |= 1 << CP0DB_DINT;
516 env->CP0_Debug |= 1 << CP0DB_DIB;
519 env->CP0_Debug |= 1 << CP0DB_DBp;
522 env->CP0_Debug |= 1 << CP0DB_DDBS;
525 env->CP0_Debug |= 1 << CP0DB_DDBL;
527 env->CP0_DEPC = exception_resume_pc(env);
528 env->hflags &= ~MIPS_HFLAG_BMASK;
530 env->hflags |= MIPS_HFLAG_DM | MIPS_HFLAG_64 | MIPS_HFLAG_CP0;
531 env->hflags &= ~(MIPS_HFLAG_KSU);
532 /* EJTAG probe trap enable is not implemented... */
533 if (!(env->CP0_Status & (1 << CP0St_EXL)))
534 env->CP0_Cause &= ~(1U << CP0Ca_BD);
535 env->active_tc.PC = (int32_t)0xBFC00480;
536 set_hflags_for_handler(env);
542 env->CP0_Status |= (1 << CP0St_SR);
543 memset(env->CP0_WatchLo, 0, sizeof(*env->CP0_WatchLo));
546 env->CP0_Status |= (1 << CP0St_NMI);
548 env->CP0_ErrorEPC = exception_resume_pc(env);
549 env->hflags &= ~MIPS_HFLAG_BMASK;
550 env->CP0_Status |= (1 << CP0St_ERL) | (1 << CP0St_BEV);
551 env->hflags |= MIPS_HFLAG_64 | MIPS_HFLAG_CP0;
552 env->hflags &= ~(MIPS_HFLAG_KSU);
553 if (!(env->CP0_Status & (1 << CP0St_EXL)))
554 env->CP0_Cause &= ~(1U << CP0Ca_BD);
555 env->active_tc.PC = (int32_t)0xBFC00000;
556 set_hflags_for_handler(env);
558 case EXCP_EXT_INTERRUPT:
560 if (env->CP0_Cause & (1 << CP0Ca_IV))
563 if (env->CP0_Config3 & ((1 << CP0C3_VInt) | (1 << CP0C3_VEIC))) {
564 /* Vectored Interrupts. */
565 unsigned int spacing;
567 unsigned int pending = (env->CP0_Cause & CP0Ca_IP_mask) >> 8;
569 pending &= env->CP0_Status >> 8;
570 /* Compute the Vector Spacing. */
571 spacing = (env->CP0_IntCtl >> CP0IntCtl_VS) & ((1 << 6) - 1);
574 if (env->CP0_Config3 & (1 << CP0C3_VInt)) {
575 /* For VInt mode, the MIPS computes the vector internally. */
576 for (vector = 7; vector > 0; vector--) {
577 if (pending & (1 << vector)) {
583 /* For VEIC mode, the external interrupt controller feeds the
584 vector through the CP0Cause IP lines. */
587 offset = 0x200 + vector * spacing;
592 update_badinstr = !(env->error_code & EXCP_INST_NOTAVAIL);
596 update_badinstr = !(env->error_code & EXCP_INST_NOTAVAIL);
597 if ((env->error_code & EXCP_TLB_NOMATCH) &&
598 !(env->CP0_Status & (1 << CP0St_EXL))) {
599 #if defined(TARGET_MIPS64)
600 int R = env->CP0_BadVAddr >> 62;
601 int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0;
602 int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0;
603 int KX = (env->CP0_Status & (1 << CP0St_KX)) != 0;
605 if (((R == 0 && UX) || (R == 1 && SX) || (R == 3 && KX)) &&
606 (!(env->insn_flags & (INSN_LOONGSON2E | INSN_LOONGSON2F))))
616 if ((env->error_code & EXCP_TLB_NOMATCH) &&
617 !(env->CP0_Status & (1 << CP0St_EXL))) {
618 #if defined(TARGET_MIPS64)
619 int R = env->CP0_BadVAddr >> 62;
620 int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0;
621 int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0;
622 int KX = (env->CP0_Status & (1 << CP0St_KX)) != 0;
624 if (((R == 0 && UX) || (R == 1 && SX) || (R == 3 && KX)) &&
625 (!(env->insn_flags & (INSN_LOONGSON2E | INSN_LOONGSON2F))))
634 update_badinstr = !(env->error_code & EXCP_INST_NOTAVAIL);
661 env->CP0_Cause = (env->CP0_Cause & ~(0x3 << CP0Ca_CE)) |
662 (env->error_code << CP0Ca_CE);
699 /* XXX: TODO: manage defered watch exceptions */
712 if (env->CP0_Status & (1 << CP0St_BEV)) {
718 if (!(env->CP0_Status & (1 << CP0St_EXL))) {
719 env->CP0_EPC = exception_resume_pc(env);
720 if (update_badinstr) {
721 set_badinstr_registers(env);
723 if (env->hflags & MIPS_HFLAG_BMASK) {
724 env->CP0_Cause |= (1U << CP0Ca_BD);
726 env->CP0_Cause &= ~(1U << CP0Ca_BD);
728 env->CP0_Status |= (1 << CP0St_EXL);
729 env->hflags |= MIPS_HFLAG_64 | MIPS_HFLAG_CP0;
730 env->hflags &= ~(MIPS_HFLAG_KSU);
732 env->hflags &= ~MIPS_HFLAG_BMASK;
733 if (env->CP0_Status & (1 << CP0St_BEV)) {
734 env->active_tc.PC = (int32_t)0xBFC00200;
736 env->active_tc.PC = (int32_t)(env->CP0_EBase & ~0x3ff);
738 env->active_tc.PC += offset;
739 set_hflags_for_handler(env);
740 env->CP0_Cause = (env->CP0_Cause & ~(0x1f << CP0Ca_EC)) | (cause << CP0Ca_EC);
743 qemu_log("Invalid MIPS exception %d. Exiting\n", cs->exception_index);
744 printf("Invalid MIPS exception %d. Exiting\n", cs->exception_index);
747 if (qemu_log_enabled() && cs->exception_index != EXCP_EXT_INTERRUPT) {
748 qemu_log("%s: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx " cause %d\n"
749 " S %08x C %08x A " TARGET_FMT_lx " D " TARGET_FMT_lx "\n",
750 __func__, env->active_tc.PC, env->CP0_EPC, cause,
751 env->CP0_Status, env->CP0_Cause, env->CP0_BadVAddr,
755 cs->exception_index = EXCP_NONE;
758 bool mips_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
760 if (interrupt_request & CPU_INTERRUPT_HARD) {
761 MIPSCPU *cpu = MIPS_CPU(cs);
762 CPUMIPSState *env = &cpu->env;
764 if (cpu_mips_hw_interrupts_pending(env)) {
766 cs->exception_index = EXCP_EXT_INTERRUPT;
768 mips_cpu_do_interrupt(cs);
775 #if !defined(CONFIG_USER_ONLY)
776 void r4k_invalidate_tlb (CPUMIPSState *env, int idx, int use_extra)
778 MIPSCPU *cpu = mips_env_get_cpu(env);
783 uint8_t ASID = env->CP0_EntryHi & 0xFF;
786 tlb = &env->tlb->mmu.r4k.tlb[idx];
787 /* The qemu TLB is flushed when the ASID changes, so no need to
788 flush these entries again. */
789 if (tlb->G == 0 && tlb->ASID != ASID) {
793 if (use_extra && env->tlb->tlb_in_use < MIPS_TLB_MAX) {
794 /* For tlbwr, we can shadow the discarded entry into
795 a new (fake) TLB entry, as long as the guest can not
796 tell that it's there. */
797 env->tlb->mmu.r4k.tlb[env->tlb->tlb_in_use] = *tlb;
798 env->tlb->tlb_in_use++;
802 /* 1k pages are not supported. */
803 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
806 addr = tlb->VPN & ~mask;
807 #if defined(TARGET_MIPS64)
808 if (addr >= (0xFFFFFFFF80000000ULL & env->SEGMask)) {
809 addr |= 0x3FFFFF0000000000ULL;
812 end = addr | (mask >> 1);
814 tlb_flush_page(cs, addr);
815 addr += TARGET_PAGE_SIZE;
820 addr = (tlb->VPN & ~mask) | ((mask >> 1) + 1);
821 #if defined(TARGET_MIPS64)
822 if (addr >= (0xFFFFFFFF80000000ULL & env->SEGMask)) {
823 addr |= 0x3FFFFF0000000000ULL;
827 while (addr - 1 < end) {
828 tlb_flush_page(cs, addr);
829 addr += TARGET_PAGE_SIZE;