fix(asm-inline): cmos_read 裸 in/out al 补 CLOBBER_RAX + 显式 mov;rdmsr out 绑定与 clobber 冲突(lo/hi 读不到 EAX/EDX)改显式 mov——同类 EAX 破坏根因,残留间歇性数据损坏源
This commit is contained in:
1 parent
f963fb16ad
commit
4296d2a19e
2 files changed
+17
-5
No files matched your search
@@ -62,8 +62,12 @@ def wrmsr(msr: t.CUInt32T, val: t.CUInt64T):
|
||||
def rdmsr(msr: t.CUInt32T) -> t.CUInt64T:
|
||||
lo: t.CUInt32T
|
||||
hi: t.CUInt32T
|
||||
# rdmsr 固定写 EDX:EAX;out 绑定 + CLOBBER_RAX/RDX 冲突会导致 lo/hi
|
||||
# 分配到非 EAX/EDX 读到垃圾。显式 mov 到输出寄存器(与 asm.inb 修复同模式)。
|
||||
c.Asm(f"""mov ecx, {c.AsmInp(msr, t.ASM_DESCR.REG_ANY)}
|
||||
rdmsr""",
|
||||
rdmsr
|
||||
mov {c.AsmOut(lo, t.ASM_DESCR.OUTPUT_REG)}, eax
|
||||
mov {c.AsmOut(hi, t.ASM_DESCR.OUTPUT_REG)}, edx""",
|
||||
out=[c.AsmOut(lo, t.ASM_DESCR.OUTPUT_REG), c.AsmOut(hi, t.ASM_DESCR.OUTPUT_REG)],
|
||||
op=[t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RDX])
|
||||
return t.CUInt64T(lo) | (t.CUInt64T(hi) << 32)
|
||||
|
||||
+12
-4
@@ -764,10 +764,18 @@ def vm_free(VirtAddr: t.CUInt64T):
|
||||
|
||||
# CMOS读取函数
|
||||
def cmos_read(reg: t.CUInt8T) -> t.CUInt8T:
|
||||
c.Asm(f"mov al, {c.AsmInp(reg)}\nout 0x70, al")
|
||||
val: t.CUInt8T
|
||||
c.Asm(f"in al, 0x71\nmov {c.AsmOut(val)}, al")
|
||||
return val
|
||||
# in/out al 会改 EAX,必须 CLOBBER_RAX;显式 mov 到输出寄存器
|
||||
#(与 asm.inb/inw 修复同模式,避免调用方 EAX 被静默破坏)。
|
||||
c.Asm(f"""mov eax, {c.AsmInp(t.CUInt32T(reg), t.ASM_DESCR.REG_ANY)}
|
||||
out 0x70, al""",
|
||||
op=[t.ASM_DESCR.CLOBBER_RAX])
|
||||
val32: t.CUInt32T
|
||||
c.Asm(f"""in al, 0x71
|
||||
movzx eax, al
|
||||
mov {c.AsmOut(val32, t.ASM_DESCR.OUTPUT_REG)}, eax""",
|
||||
out=[c.AsmOut(val32, t.ASM_DESCR.OUTPUT_REG)],
|
||||
op=[t.ASM_DESCR.CLOBBER_RAX])
|
||||
return t.CUInt8T(val32)
|
||||
|
||||
# 内存大小测试函数
|
||||
def detect_memory_size() -> t.CUInt64T:
|
||||
|
||||
Reference in new issue
Block a user