📄 helper.c
字号:
#else#define SMM_REVISION_ID 0x00020000#endifvoid do_smm_enter(void){ target_ulong sm_state; SegmentCache *dt; int i, offset; if (loglevel & CPU_LOG_INT) { fprintf(logfile, "SMM: enter\n"); cpu_dump_state(env, logfile, fprintf, X86_DUMP_CCOP); } env->hflags |= HF_SMM_MASK; cpu_smm_update(env); sm_state = env->smbase + 0x8000; #ifdef TARGET_X86_64 for(i = 0; i < 6; i++) { dt = &env->segs[i]; offset = 0x7e00 + i * 16; stw_phys(sm_state + offset, dt->selector); stw_phys(sm_state + offset + 2, (dt->flags >> 8) & 0xf0ff); stl_phys(sm_state + offset + 4, dt->limit); stq_phys(sm_state + offset + 8, dt->base); } stq_phys(sm_state + 0x7e68, env->gdt.base); stl_phys(sm_state + 0x7e64, env->gdt.limit); stw_phys(sm_state + 0x7e70, env->ldt.selector); stq_phys(sm_state + 0x7e78, env->ldt.base); stl_phys(sm_state + 0x7e74, env->ldt.limit); stw_phys(sm_state + 0x7e72, (env->ldt.flags >> 8) & 0xf0ff); stq_phys(sm_state + 0x7e88, env->idt.base); stl_phys(sm_state + 0x7e84, env->idt.limit); stw_phys(sm_state + 0x7e90, env->tr.selector); stq_phys(sm_state + 0x7e98, env->tr.base); stl_phys(sm_state + 0x7e94, env->tr.limit); stw_phys(sm_state + 0x7e92, (env->tr.flags >> 8) & 0xf0ff); stq_phys(sm_state + 0x7ed0, env->efer); stq_phys(sm_state + 0x7ff8, EAX); stq_phys(sm_state + 0x7ff0, ECX); stq_phys(sm_state + 0x7fe8, EDX); stq_phys(sm_state + 0x7fe0, EBX); stq_phys(sm_state + 0x7fd8, ESP); stq_phys(sm_state + 0x7fd0, EBP); stq_phys(sm_state + 0x7fc8, ESI); stq_phys(sm_state + 0x7fc0, EDI); for(i = 8; i < 16; i++) stq_phys(sm_state + 0x7ff8 - i * 8, env->regs[i]); stq_phys(sm_state + 0x7f78, env->eip); stl_phys(sm_state + 0x7f70, compute_eflags()); stl_phys(sm_state + 0x7f68, env->dr[6]); stl_phys(sm_state + 0x7f60, env->dr[7]); stl_phys(sm_state + 0x7f48, env->cr[4]); stl_phys(sm_state + 0x7f50, env->cr[3]); stl_phys(sm_state + 0x7f58, env->cr[0]); stl_phys(sm_state + 0x7efc, SMM_REVISION_ID); stl_phys(sm_state + 0x7f00, env->smbase);#else stl_phys(sm_state + 0x7ffc, env->cr[0]); stl_phys(sm_state + 0x7ff8, env->cr[3]); stl_phys(sm_state + 0x7ff4, compute_eflags()); stl_phys(sm_state + 0x7ff0, env->eip); stl_phys(sm_state + 0x7fec, EDI); stl_phys(sm_state + 0x7fe8, ESI); stl_phys(sm_state + 0x7fe4, EBP); stl_phys(sm_state + 0x7fe0, ESP); stl_phys(sm_state + 0x7fdc, EBX); stl_phys(sm_state + 0x7fd8, EDX); stl_phys(sm_state + 0x7fd4, ECX); stl_phys(sm_state + 0x7fd0, EAX); stl_phys(sm_state + 0x7fcc, env->dr[6]); stl_phys(sm_state + 0x7fc8, env->dr[7]); stl_phys(sm_state + 0x7fc4, env->tr.selector); stl_phys(sm_state + 0x7f64, env->tr.base); stl_phys(sm_state + 0x7f60, env->tr.limit); stl_phys(sm_state + 0x7f5c, (env->tr.flags >> 8) & 0xf0ff); stl_phys(sm_state + 0x7fc0, env->ldt.selector); stl_phys(sm_state + 0x7f80, env->ldt.base); stl_phys(sm_state + 0x7f7c, env->ldt.limit); stl_phys(sm_state + 0x7f78, (env->ldt.flags >> 8) & 0xf0ff); stl_phys(sm_state + 0x7f74, env->gdt.base); stl_phys(sm_state + 0x7f70, env->gdt.limit); stl_phys(sm_state + 0x7f58, env->idt.base); stl_phys(sm_state + 0x7f54, env->idt.limit); for(i = 0; i < 6; i++) { dt = &env->segs[i]; if (i < 3) offset = 0x7f84 + i * 12; else offset = 0x7f2c + (i - 3) * 12; stl_phys(sm_state + 0x7fa8 + i * 4, dt->selector); stl_phys(sm_state + offset + 8, dt->base); stl_phys(sm_state + offset + 4, dt->limit); stl_phys(sm_state + offset, (dt->flags >> 8) & 0xf0ff); } stl_phys(sm_state + 0x7f14, env->cr[4]); stl_phys(sm_state + 0x7efc, SMM_REVISION_ID); stl_phys(sm_state + 0x7ef8, env->smbase);#endif /* init SMM cpu state */#ifdef TARGET_X86_64 env->efer = 0; env->hflags &= ~HF_LMA_MASK;#endif load_eflags(0, ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK)); env->eip = 0x00008000; cpu_x86_load_seg_cache(env, R_CS, (env->smbase >> 4) & 0xffff, env->smbase, 0xffffffff, 0); cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0xffffffff, 0); cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0xffffffff, 0); cpu_x86_load_seg_cache(env, R_SS, 0, 0, 0xffffffff, 0); cpu_x86_load_seg_cache(env, R_FS, 0, 0, 0xffffffff, 0); cpu_x86_load_seg_cache(env, R_GS, 0, 0, 0xffffffff, 0); cpu_x86_update_cr0(env, env->cr[0] & ~(CR0_PE_MASK | CR0_EM_MASK | CR0_TS_MASK | CR0_PG_MASK)); cpu_x86_update_cr4(env, 0); env->dr[7] = 0x00000400; CC_OP = CC_OP_EFLAGS;}void helper_rsm(void){ target_ulong sm_state; int i, offset; uint32_t val; sm_state = env->smbase + 0x8000;#ifdef TARGET_X86_64 env->efer = ldq_phys(sm_state + 0x7ed0); if (env->efer & MSR_EFER_LMA) env->hflags |= HF_LMA_MASK; else env->hflags &= ~HF_LMA_MASK; for(i = 0; i < 6; i++) { offset = 0x7e00 + i * 16; cpu_x86_load_seg_cache(env, i, lduw_phys(sm_state + offset), ldq_phys(sm_state + offset + 8), ldl_phys(sm_state + offset + 4), (lduw_phys(sm_state + offset + 2) & 0xf0ff) << 8); } env->gdt.base = ldq_phys(sm_state + 0x7e68); env->gdt.limit = ldl_phys(sm_state + 0x7e64); env->ldt.selector = lduw_phys(sm_state + 0x7e70); env->ldt.base = ldq_phys(sm_state + 0x7e78); env->ldt.limit = ldl_phys(sm_state + 0x7e74); env->ldt.flags = (lduw_phys(sm_state + 0x7e72) & 0xf0ff) << 8; env->idt.base = ldq_phys(sm_state + 0x7e88); env->idt.limit = ldl_phys(sm_state + 0x7e84); env->tr.selector = lduw_phys(sm_state + 0x7e90); env->tr.base = ldq_phys(sm_state + 0x7e98); env->tr.limit = ldl_phys(sm_state + 0x7e94); env->tr.flags = (lduw_phys(sm_state + 0x7e92) & 0xf0ff) << 8; EAX = ldq_phys(sm_state + 0x7ff8); ECX = ldq_phys(sm_state + 0x7ff0); EDX = ldq_phys(sm_state + 0x7fe8); EBX = ldq_phys(sm_state + 0x7fe0); ESP = ldq_phys(sm_state + 0x7fd8); EBP = ldq_phys(sm_state + 0x7fd0); ESI = ldq_phys(sm_state + 0x7fc8); EDI = ldq_phys(sm_state + 0x7fc0); for(i = 8; i < 16; i++) env->regs[i] = ldq_phys(sm_state + 0x7ff8 - i * 8); env->eip = ldq_phys(sm_state + 0x7f78); load_eflags(ldl_phys(sm_state + 0x7f70), ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK)); env->dr[6] = ldl_phys(sm_state + 0x7f68); env->dr[7] = ldl_phys(sm_state + 0x7f60); cpu_x86_update_cr4(env, ldl_phys(sm_state + 0x7f48)); cpu_x86_update_cr3(env, ldl_phys(sm_state + 0x7f50)); cpu_x86_update_cr0(env, ldl_phys(sm_state + 0x7f58)); val = ldl_phys(sm_state + 0x7efc); /* revision ID */ if (val & 0x20000) { env->smbase = ldl_phys(sm_state + 0x7f00) & ~0x7fff; }#else cpu_x86_update_cr0(env, ldl_phys(sm_state + 0x7ffc)); cpu_x86_update_cr3(env, ldl_phys(sm_state + 0x7ff8)); load_eflags(ldl_phys(sm_state + 0x7ff4), ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK)); env->eip = ldl_phys(sm_state + 0x7ff0); EDI = ldl_phys(sm_state + 0x7fec); ESI = ldl_phys(sm_state + 0x7fe8); EBP = ldl_phys(sm_state + 0x7fe4); ESP = ldl_phys(sm_state + 0x7fe0); EBX = ldl_phys(sm_state + 0x7fdc); EDX = ldl_phys(sm_state + 0x7fd8); ECX = ldl_phys(sm_state + 0x7fd4); EAX = ldl_phys(sm_state + 0x7fd0); env->dr[6] = ldl_phys(sm_state + 0x7fcc); env->dr[7] = ldl_phys(sm_state + 0x7fc8); env->tr.selector = ldl_phys(sm_state + 0x7fc4) & 0xffff; env->tr.base = ldl_phys(sm_state + 0x7f64); env->tr.limit = ldl_phys(sm_state + 0x7f60); env->tr.flags = (ldl_phys(sm_state + 0x7f5c) & 0xf0ff) << 8; env->ldt.selector = ldl_phys(sm_state + 0x7fc0) & 0xffff; env->ldt.base = ldl_phys(sm_state + 0x7f80); env->ldt.limit = ldl_phys(sm_state + 0x7f7c); env->ldt.flags = (ldl_phys(sm_state + 0x7f78) & 0xf0ff) << 8; env->gdt.base = ldl_phys(sm_state + 0x7f74); env->gdt.limit = ldl_phys(sm_state + 0x7f70); env->idt.base = ldl_phys(sm_state + 0x7f58); env->idt.limit = ldl_phys(sm_state + 0x7f54); for(i = 0; i < 6; i++) { if (i < 3) offset = 0x7f84 + i * 12; else offset = 0x7f2c + (i - 3) * 12; cpu_x86_load_seg_cache(env, i, ldl_phys(sm_state + 0x7fa8 + i * 4) & 0xffff, ldl_phys(sm_state + offset + 8), ldl_phys(sm_state + offset + 4), (ldl_phys(sm_state + offset) & 0xf0ff) << 8); } cpu_x86_update_cr4(env, ldl_phys(sm_state + 0x7f14)); val = ldl_phys(sm_state + 0x7efc); /* revision ID */ if (val & 0x20000) { env->smbase = ldl_phys(sm_state + 0x7ef8) & ~0x7fff; }#endif CC_OP = CC_OP_EFLAGS; env->hflags &= ~HF_SMM_MASK; cpu_smm_update(env); if (loglevel & CPU_LOG_INT) { fprintf(logfile, "SMM: after RSM\n"); cpu_dump_state(env, logfile, fprintf, X86_DUMP_CCOP); }}#endif /* !CONFIG_USER_ONLY */#ifdef BUGGY_GCC_DIV64/* gcc 2.95.4 on PowerPC does not seem to like using __udivdi3, so we call it from another function */uint32_t div32(uint64_t *q_ptr, uint64_t num, uint32_t den){ *q_ptr = num / den; return num % den;}int32_t idiv32(int64_t *q_ptr, int64_t num, int32_t den){ *q_ptr = num / den; return num % den;}#endifvoid helper_divl_EAX_T0(void){ unsigned int den, r; uint64_t num, q; num = ((uint32_t)EAX) | ((uint64_t)((uint32_t)EDX) << 32); den = T0; if (den == 0) { raise_exception(EXCP00_DIVZ); }#ifdef BUGGY_GCC_DIV64 r = div32(&q, num, den);#else q = (num / den); r = (num % den);#endif if (q > 0xffffffff) raise_exception(EXCP00_DIVZ); EAX = (uint32_t)q; EDX = (uint32_t)r;}void helper_idivl_EAX_T0(void){ int den, r; int64_t num, q; num = ((uint32_t)EAX) | ((uint64_t)((uint32_t)EDX) << 32); den = T0; if (den == 0) { raise_exception(EXCP00_DIVZ); }#ifdef BUGGY_GCC_DIV64 r = idiv32(&q, num, den);#else q = (num / den); r = (num % den);#endif if (q != (int32_t)q) raise_exception(EXCP00_DIVZ); EAX = (uint32_t)q; EDX = (uint32_t)r;}void helper_cmpxchg8b(void){ uint64_t d; int eflags; eflags = cc_table[CC_OP].compute_all(); d = ldq(A0); if (d == (((uint64_t)EDX << 32) | EAX)) { stq(A0, ((uint64_t)ECX << 32) | EBX); eflags |= CC_Z; } else { EDX = d >> 32; EAX = d; eflags &= ~CC_Z; } CC_SRC = eflags;}void helper_cpuid(void){ uint32_t index; index = (uint32_t)EAX; /* test if maximum index reached */ if (index & 0x80000000) { if (index > env->cpuid_xlevel) index = env->cpuid_level; } else { if (index > env->cpuid_level) index = env->cpuid_level; } switch(index) { case 0: EAX = env->cpuid_level; EBX = env->cpuid_vendor1; EDX = env->cpuid_vendor2; ECX = env->cpuid_vendor3; break; case 1: EAX = env->cpuid_version; EBX = 8 << 8; /* CLFLUSH size in quad words, Linux wants it. */ ECX = env->cpuid_ext_features; EDX = env->cpuid_features; break; case 2: /* cache info: needed for Pentium Pro compatibility */ EAX = 0x410601; EBX = 0; ECX = 0; EDX = 0; break; case 0x80000000: EAX = env->cpuid_xlevel; EBX = env->cpuid_vendor1; EDX = env->cpuid_vendor2; ECX = env->cpuid_vendor3; break; case 0x80000001: EAX = env->cpuid_features; EBX = 0; ECX = 0; EDX = env->cpuid_ext2_features; break; case 0x80000002: case 0x80000003: case 0x80000004: EAX = env->cpuid_model[(index - 0x80000002) * 4 + 0]; EBX = env->cpuid_model[(index - 0x80000002) * 4 + 1]; ECX = env->cpuid_model[(index - 0x80000002) * 4 + 2]; EDX = env->cpuid_model[(index - 0x80000002) * 4 + 3]; break; case 0x80000005: /* cache info (L1 cache) */ EAX = 0x01ff01ff; EBX = 0x01ff01ff; ECX = 0x40020140; EDX = 0x40020140; break; case 0x80000006: /* cache info (L2 cache) */ EAX = 0; EBX = 0x42004200; ECX = 0x02008140; EDX = 0; break; case 0x80000008: /* virtual & phys address size in low 2 bytes. */ EAX = 0x00003028;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -