新增 includes/dbgstack.vp: 挂起主线程取 x64 CONTEXT + RBP 链逐步取证 + 栈扫描兜底(4KiB 分块 ReadProcessMemory);按 <exe>.stackmap 下界查表输出 <文件>.vp:行 (函数);控制台 ASCII 输出并双写 UTF-8 <exe>.stackdump.txt;ASan 与 DbgHelp 冲突显式降级不静默;lock cmpxchg 原子重入(不用 InterlockedCompareExchange: x64 上是编译器内部函数、无导出符号)。 新增/补 w32 头: win32dbghelp.vp(新)、SetConsoleCtrlHandler、x64 CONTEXT、ReadProcessMemory。 parser.vp/tokens.vp: [N]T/[]T/const [N]T 脱糖为 t.CArray;新增 union NAME: 语句(Keyword.Union 追加表尾);list[rawptr[AST]] elem_size 2/4 改 8;新增 _record_parse_err_ctx 把 token 类型与前后 token 并入错误消息,去掉 [AST] SyntaxError 遗留单行 printf。 asm.vp: 整文件迁移到 __asm__/asminp/asmout/裸 ASM_DESCR。
146 lines
3.8 KiB
Plaintext
146 lines
3.8 KiB
Plaintext
def cli(): __asm__("cli", [ASM_DESCR.CLOBBER_MEMORY])
|
|
def sti(): __asm__("sti", [ASM_DESCR.CLOBBER_MEMORY])
|
|
def hlt(): __asm__("hlt", [ASM_DESCR.CLOBBER_MEMORY])
|
|
def nop(): __asm__("nop", [ASM_DESCR.CLOBBER_MEMORY])
|
|
def pause(): __asm__("pause", op=[ASM_DESCR.CLOBBER_MEMORY])
|
|
|
|
def inb(port: uint16) -> uint8:
|
|
value: uint32
|
|
__asm__(f"""mov edx, {asminp(uint32(port), ASM_DESCR.REG_ANY)}
|
|
in al, dx
|
|
movzx $0, al""",
|
|
out = [asmout(value, ASM_DESCR.OUTPUT_REG)],
|
|
op =[ASM_DESCR.CLOBBER_RDX, ASM_DESCR.CLOBBER_RAX])
|
|
return uint8(value)
|
|
|
|
def outb(port: uint16, value: uint8):
|
|
__asm__(f"""mov edx, {asminp(uint32(port), ASM_DESCR.REG_ANY)}
|
|
mov eax, {asminp(uint32(value), ASM_DESCR.REG_ANY)}
|
|
out dx, al""",
|
|
op = [ASM_DESCR.CLOBBER_RDX, ASM_DESCR.CLOBBER_RAX])
|
|
|
|
|
|
def inw(port: uint16) -> uint16:
|
|
value: uint32
|
|
__asm__(f"""mov edx, {asminp(uint32(port), ASM_DESCR.REG_ANY)}
|
|
in ax, dx
|
|
movzx eax, ax
|
|
mov {asmout(value, ASM_DESCR.OUTPUT_REG)}, eax""",
|
|
out = [asmout(value, ASM_DESCR.OUTPUT_REG)],
|
|
op =[ASM_DESCR.CLOBBER_RDX, ASM_DESCR.CLOBBER_RAX])
|
|
return uint16(value)
|
|
|
|
def outw(port: uint16, value: uint16):
|
|
__asm__(f"""mov edx, {asminp(uint32(port), ASM_DESCR.REG_ANY)}
|
|
mov eax, {asminp(uint32(value), ASM_DESCR.REG_ANY)}
|
|
out dx, ax""",
|
|
op = [ASM_DESCR.CLOBBER_RDX, ASM_DESCR.CLOBBER_RAX])
|
|
|
|
def inl(port: uint16) -> uint32:
|
|
value: uint32
|
|
__asm__(f"""mov edx, {asminp(uint32(port), ASM_DESCR.REG_ANY)}
|
|
in eax, dx
|
|
mov {asmout(value, ASM_DESCR.OUTPUT_REG)}, eax""",
|
|
out = [asmout(value, ASM_DESCR.OUTPUT_REG)],
|
|
op =[ASM_DESCR.CLOBBER_RDX, ASM_DESCR.CLOBBER_RAX])
|
|
return value
|
|
|
|
def outl(port: uint16, value: uint32):
|
|
__asm__(f"""mov edx, {asminp(uint32(port), ASM_DESCR.REG_ANY)}
|
|
mov eax, {asminp(value, ASM_DESCR.REG_ANY)}
|
|
out dx, eax""",
|
|
op = [ASM_DESCR.CLOBBER_RDX, ASM_DESCR.CLOBBER_RAX])
|
|
|
|
def io_wait():
|
|
__asm__(f"mov dx, 0x80; out dx, al",
|
|
op = [ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_DX])
|
|
|
|
|
|
inline def pushall():
|
|
__asm__(f"""
|
|
push rax
|
|
push rbx
|
|
push rcx
|
|
push rdx
|
|
push rsi
|
|
push rdi
|
|
push rbp
|
|
push r8
|
|
push r9
|
|
push r10
|
|
push r11
|
|
push r12
|
|
push r13
|
|
push r14
|
|
push r15""",
|
|
[ASM_DESCR.CLOBBER_MEMORY]
|
|
)
|
|
|
|
inline def popall():
|
|
__asm__(f"""
|
|
pop r15
|
|
pop r14
|
|
pop r13
|
|
pop r12
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rbp
|
|
pop rdi
|
|
pop rsi
|
|
pop rdx
|
|
pop rcx
|
|
pop rbx
|
|
pop rax""",
|
|
[ASM_DESCR.CLOBBER_MEMORY]
|
|
)
|
|
|
|
|
|
def cpu_switch_context(old_stack: uint64*, new_stack: uint64):
|
|
__asm__(f"""
|
|
push rax
|
|
push rbx
|
|
push rcx
|
|
push rdx
|
|
push rsi
|
|
push rdi
|
|
push rbp
|
|
push r8
|
|
push r9
|
|
push r10
|
|
push r11
|
|
push r12
|
|
push r13
|
|
push r14
|
|
push r15
|
|
mov [{asminp(old_stack, ASM_DESCR.REG_ANY)}], rsp
|
|
mov rsp, {asminp(new_stack, ASM_DESCR.REG_ANY)}
|
|
pop r15
|
|
pop r14
|
|
pop r13
|
|
pop r12
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rbp
|
|
pop rdi
|
|
pop rsi
|
|
pop rdx
|
|
pop rcx
|
|
pop rbx
|
|
pop rax""",
|
|
op=[ASM_DESCR.CLOBBER_MEMORY])
|
|
|
|
def BSSClean():
|
|
__asm__(
|
|
"lea rdi, [rip + __bss_start]\n"
|
|
"lea rcx, [rip + __bss_end]\n"
|
|
"sub rcx, rdi\n"
|
|
"xor eax, eax\n"
|
|
"cld\n"
|
|
"rep stosb",
|
|
op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RDI, ASM_DESCR.CLOBBER_RCX, ASM_DESCR.CLOBBER_RAX]
|
|
)
|