⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helper2.c

📁 qemu虚拟机代码
💻 C
📖 第 1 页 / 共 3 页
字号:
        if (pde & PG_PSE_MASK) {            /* 2 MB page */            page_size = 2048 * 1024;            ptep ^= PG_NX_MASK;            if ((ptep & PG_NX_MASK) && is_write1 == 2)                goto do_fault_protect;            if (is_user) {                if (!(ptep & PG_USER_MASK))                    goto do_fault_protect;                if (is_write && !(ptep & PG_RW_MASK))                    goto do_fault_protect;            } else {                if ((env->cr[0] & CR0_WP_MASK) &&                     is_write && !(ptep & PG_RW_MASK))                     goto do_fault_protect;            }            is_dirty = is_write && !(pde & PG_DIRTY_MASK);            if (!(pde & PG_ACCESSED_MASK) || is_dirty) {                pde |= PG_ACCESSED_MASK;                if (is_dirty)                    pde |= PG_DIRTY_MASK;                stl_phys_notdirty(pde_addr, pde);            }            /* align to page_size */            pte = pde & ((PHYS_ADDR_MASK & ~(page_size - 1)) | 0xfff);             virt_addr = addr & ~(page_size - 1);        } else {            /* 4 KB page */            if (!(pde & PG_ACCESSED_MASK)) {                pde |= PG_ACCESSED_MASK;                stl_phys_notdirty(pde_addr, pde);            }            pte_addr = ((pde & PHYS_ADDR_MASK) + (((addr >> 12) & 0x1ff) << 3)) &                env->a20_mask;            pte = ldq_phys(pte_addr);            if (!(pte & PG_PRESENT_MASK)) {                error_code = 0;                goto do_fault;            }            if (!(env->efer & MSR_EFER_NXE) && (pte & PG_NX_MASK)) {                error_code = PG_ERROR_RSVD_MASK;                goto do_fault;            }            /* combine pde and pte nx, user and rw protections */            ptep &= pte ^ PG_NX_MASK;            ptep ^= PG_NX_MASK;            if ((ptep & PG_NX_MASK) && is_write1 == 2)                goto do_fault_protect;             if (is_user) {                if (!(ptep & PG_USER_MASK))                    goto do_fault_protect;                if (is_write && !(ptep & PG_RW_MASK))                    goto do_fault_protect;            } else {                if ((env->cr[0] & CR0_WP_MASK) &&                    is_write && !(ptep & PG_RW_MASK))                     goto do_fault_protect;            }            is_dirty = is_write && !(pte & PG_DIRTY_MASK);            if (!(pte & PG_ACCESSED_MASK) || is_dirty) {                pte |= PG_ACCESSED_MASK;                if (is_dirty)                    pte |= PG_DIRTY_MASK;                stl_phys_notdirty(pte_addr, pte);            }            page_size = 4096;            virt_addr = addr & ~0xfff;            pte = pte & (PHYS_ADDR_MASK | 0xfff);        }    } else {        uint32_t pde;        /* page directory entry */        pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & ~3)) &             env->a20_mask;        pde = ldl_phys(pde_addr);        if (!(pde & PG_PRESENT_MASK)) {            error_code = 0;            goto do_fault;        }        /* if PSE bit is set, then we use a 4MB page */        if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {            page_size = 4096 * 1024;            if (is_user) {                if (!(pde & PG_USER_MASK))                    goto do_fault_protect;                if (is_write && !(pde & PG_RW_MASK))                    goto do_fault_protect;            } else {                if ((env->cr[0] & CR0_WP_MASK) &&                     is_write && !(pde & PG_RW_MASK))                     goto do_fault_protect;            }            is_dirty = is_write && !(pde & PG_DIRTY_MASK);            if (!(pde & PG_ACCESSED_MASK) || is_dirty) {                pde |= PG_ACCESSED_MASK;                if (is_dirty)                    pde |= PG_DIRTY_MASK;                stl_phys_notdirty(pde_addr, pde);            }                    pte = pde & ~( (page_size - 1) & ~0xfff); /* align to page_size */            ptep = pte;            virt_addr = addr & ~(page_size - 1);        } else {            if (!(pde & PG_ACCESSED_MASK)) {                pde |= PG_ACCESSED_MASK;                stl_phys_notdirty(pde_addr, pde);            }            /* page directory entry */            pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) &                 env->a20_mask;            pte = ldl_phys(pte_addr);            if (!(pte & PG_PRESENT_MASK)) {                error_code = 0;                goto do_fault;            }            /* combine pde and pte user and rw protections */            ptep = pte & pde;            if (is_user) {                if (!(ptep & PG_USER_MASK))                    goto do_fault_protect;                if (is_write && !(ptep & PG_RW_MASK))                    goto do_fault_protect;            } else {                if ((env->cr[0] & CR0_WP_MASK) &&                    is_write && !(ptep & PG_RW_MASK))                     goto do_fault_protect;            }            is_dirty = is_write && !(pte & PG_DIRTY_MASK);            if (!(pte & PG_ACCESSED_MASK) || is_dirty) {                pte |= PG_ACCESSED_MASK;                if (is_dirty)                    pte |= PG_DIRTY_MASK;                stl_phys_notdirty(pte_addr, pte);            }            page_size = 4096;            virt_addr = addr & ~0xfff;        }    }    /* the page can be put in the TLB */    prot = PAGE_READ;    if (!(ptep & PG_NX_MASK))        prot |= PAGE_EXEC;    if (pte & PG_DIRTY_MASK) {        /* only set write access if already dirty... otherwise wait           for dirty access */        if (is_user) {            if (ptep & PG_RW_MASK)                prot |= PAGE_WRITE;        } else {            if (!(env->cr[0] & CR0_WP_MASK) ||                (ptep & PG_RW_MASK))                prot |= PAGE_WRITE;        }    } do_mapping:    pte = pte & env->a20_mask;    /* Even if 4MB pages, we map only one 4KB page in the cache to       avoid filling it too fast */    page_offset = (addr & TARGET_PAGE_MASK) & (page_size - 1);    paddr = (pte & TARGET_PAGE_MASK) + page_offset;    vaddr = virt_addr + page_offset;        ret = tlb_set_page_exec(env, vaddr, paddr, prot, is_user, is_softmmu);    return ret; do_fault_protect:    error_code = PG_ERROR_P_MASK; do_fault:    env->cr[2] = addr;    error_code |= (is_write << PG_ERROR_W_BIT);    if (is_user)        error_code |= PG_ERROR_U_MASK;    if (is_write1 == 2 &&         (env->efer & MSR_EFER_NXE) &&         (env->cr[4] & CR4_PAE_MASK))        error_code |= PG_ERROR_I_D_MASK;    env->error_code = error_code;    env->exception_index = EXCP0E_PAGE;    return 1;}target_ulong cpu_get_phys_page_debug(CPUState *env, target_ulong addr){    uint32_t pde_addr, pte_addr;    uint32_t pde, pte, paddr, page_offset, page_size;    if (env->cr[4] & CR4_PAE_MASK) {        uint32_t pdpe_addr, pde_addr, pte_addr;        uint32_t pdpe;        /* XXX: we only use 32 bit physical addresses */#ifdef TARGET_X86_64        if (env->hflags & HF_LMA_MASK) {            uint32_t pml4e_addr, pml4e;            int32_t sext;            /* test virtual address sign extension */            sext = (int64_t)addr >> 47;            if (sext != 0 && sext != -1)                return -1;                        pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) &                 env->a20_mask;            pml4e = ldl_phys(pml4e_addr);            if (!(pml4e & PG_PRESENT_MASK))                return -1;                        pdpe_addr = ((pml4e & ~0xfff) + (((addr >> 30) & 0x1ff) << 3)) &                 env->a20_mask;            pdpe = ldl_phys(pdpe_addr);            if (!(pdpe & PG_PRESENT_MASK))                return -1;        } else #endif        {            pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 30) << 3)) &                 env->a20_mask;            pdpe = ldl_phys(pdpe_addr);            if (!(pdpe & PG_PRESENT_MASK))                return -1;        }        pde_addr = ((pdpe & ~0xfff) + (((addr >> 21) & 0x1ff) << 3)) &            env->a20_mask;        pde = ldl_phys(pde_addr);        if (!(pde & PG_PRESENT_MASK)) {            return -1;        }        if (pde & PG_PSE_MASK) {            /* 2 MB page */            page_size = 2048 * 1024;            pte = pde & ~( (page_size - 1) & ~0xfff); /* align to page_size */        } else {            /* 4 KB page */            pte_addr = ((pde & ~0xfff) + (((addr >> 12) & 0x1ff) << 3)) &                env->a20_mask;            page_size = 4096;            pte = ldl_phys(pte_addr);        }    } else {        if (!(env->cr[0] & CR0_PG_MASK)) {            pte = addr;            page_size = 4096;        } else {            /* page directory entry */            pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & ~3)) & env->a20_mask;            pde = ldl_phys(pde_addr);            if (!(pde & PG_PRESENT_MASK))                 return -1;            if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {                pte = pde & ~0x003ff000; /* align to 4MB */                page_size = 4096 * 1024;            } else {                /* page directory entry */                pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & env->a20_mask;                pte = ldl_phys(pte_addr);                if (!(pte & PG_PRESENT_MASK))                    return -1;                page_size = 4096;            }        }        pte = pte & env->a20_mask;    }    page_offset = (addr & TARGET_PAGE_MASK) & (page_size - 1);    paddr = (pte & TARGET_PAGE_MASK) + page_offset;    return paddr;}#endif /* !CONFIG_USER_ONLY */#if defined(USE_CODE_COPY)struct fpstate {    uint16_t fpuc;    uint16_t dummy1;    uint16_t fpus;    uint16_t dummy2;    uint16_t fptag;    uint16_t dummy3;    uint32_t fpip;    uint32_t fpcs;    uint32_t fpoo;    uint32_t fpos;    uint8_t fpregs1[8 * 10];};void restore_native_fp_state(CPUState *env){    int fptag, i, j;    struct fpstate fp1, *fp = &fp1;        fp->fpuc = env->fpuc;    fp->fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;    fptag = 0;    for (i=7; i>=0; i--) {	fptag <<= 2;	if (env->fptags[i]) {            fptag |= 3;        } else {            /* the FPU automatically computes it */        }    }    fp->fptag = fptag;    j = env->fpstt;    for(i = 0;i < 8; i++) {        memcpy(&fp->fpregs1[i * 10], &env->fpregs[j].d, 10);        j = (j + 1) & 7;    }    asm volatile ("frstor %0" : "=m" (*fp));    env->native_fp_regs = 1;} void save_native_fp_state(CPUState *env){    int fptag, i, j;    uint16_t fpuc;    struct fpstate fp1, *fp = &fp1;    asm volatile ("fsave %0" : : "m" (*fp));    env->fpuc = fp->fpuc;    env->fpstt = (fp->fpus >> 11) & 7;    env->fpus = fp->fpus & ~0x3800;    fptag = fp->fptag;    for(i = 0;i < 8; i++) {        env->fptags[i] = ((fptag & 3) == 3);        fptag >>= 2;    }    j = env->fpstt;    for(i = 0;i < 8; i++) {        memcpy(&env->fpregs[j].d, &fp->fpregs1[i * 10], 10);        j = (j + 1) & 7;    }    /* we must restore the default rounding state */    /* XXX: we do not restore the exception state */    fpuc = 0x037f | (env->fpuc & (3 << 10));    asm volatile("fldcw %0" : : "m" (fpuc));    env->native_fp_regs = 0;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -