Files
ViperOS/vpsdk/syscall.vp
T

119 lines
4.5 KiB
Plaintext

import t, c
define CREATE_WINDOW = 1
define DRAW_TEXT = 2
define EXIT = 3
define OPEN = 4
define CLOSE = 5
define READ = 6
define WRITE = 7
define SEEK = 8
define TELL = 9
define SIZE = 10
define MKDIR = 11
define REMOVE = 12
define OPENDIR = 13
define READDIR = 14
define CLOSEDIR = 15
define STAT = 16
define WAIT_WINDOW = 17
define SERIAL_PUTS = 18
define LOAD_SO = 19
define SO_CALL1 = 20
define GET_WINBUF = 21
define WIN_FLUSH = 22
define POLL_EVENT = 23
define SET_CURSOR = 24
define YIELD = 25
define SET_TITLE = 26
define SET_GEOMETRY = 27
define SPAWN = 28
define MMAP = 29
define MUNMAP = 30
define SET_RESIZABLE = 31
define GET_WIN_SIZE = 32
define THREAD_CREATE = 33
define THREAD_EXIT = 34
# SYSCALL_* 别名(vpsdk.stdlib 等模块引用;数值与内核 VKernel/intr/syscall.vp 一致)
define SYSCALL_MMAP = 29
def _syscall0(num: uint64) -> uint64:
ret: uint64
c.Asm(f"""mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)}
syscall""",
out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)],
op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX,
t.ASM_DESCR.CLOBBER_R11])
return ret
def _syscall1(num: uint64, a1: uint64) -> uint64:
ret: uint64
c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)}
mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)}
syscall""",
out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)],
op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX,
t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI])
return ret
def _syscall2(num: uint64, a1: uint64, a2: uint64) -> uint64:
ret: uint64
c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)}
mov rsi, {c.AsmInp(a2, t.ASM_DESCR.REG_ANY)}
mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)}
syscall""",
out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)],
op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX,
t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI,
t.ASM_DESCR.CLOBBER_RSI])
return ret
def _syscall3(num: uint64, a1: uint64, a2: uint64, a3: uint64) -> uint64:
ret: uint64
c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)}
mov rsi, {c.AsmInp(a2, t.ASM_DESCR.REG_ANY)}
mov rdx, {c.AsmInp(a3, t.ASM_DESCR.REG_ANY)}
mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)}
syscall""",
out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)],
op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX,
t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI,
t.ASM_DESCR.CLOBBER_RSI, t.ASM_DESCR.CLOBBER_RDX])
return ret
def _syscall5(num: uint64, a1: uint64, a2: uint64, a3: uint64, a4: uint64, a5: uint64) -> uint64:
ret: uint64
c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)}
mov rsi, {c.AsmInp(a2, t.ASM_DESCR.REG_ANY)}
mov rdx, {c.AsmInp(a3, t.ASM_DESCR.REG_ANY)}
mov r10, {c.AsmInp(a4, t.ASM_DESCR.REG_ANY)}
mov r8, {c.AsmInp(a5, t.ASM_DESCR.REG_ANY)}
mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)}
syscall""",
out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)],
op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX,
t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI,
t.ASM_DESCR.CLOBBER_RSI, t.ASM_DESCR.CLOBBER_RDX,
t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R8])
return ret
def _syscall6(num: uint64, a1: uint64, a2: uint64, a3: uint64, a4: uint64, a5: uint64, a6: uint64) -> uint64:
ret: uint64
c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)}
mov rsi, {c.AsmInp(a2, t.ASM_DESCR.REG_ANY)}
mov rdx, {c.AsmInp(a3, t.ASM_DESCR.REG_ANY)}
mov r10, {c.AsmInp(a4, t.ASM_DESCR.REG_ANY)}
mov r8, {c.AsmInp(a5, t.ASM_DESCR.REG_ANY)}
mov r9, {c.AsmInp(a6, t.ASM_DESCR.REG_ANY)}
mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)}
syscall""",
out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)],
op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX,
t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI,
t.ASM_DESCR.CLOBBER_RSI, t.ASM_DESCR.CLOBBER_RDX,
t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R8,
t.ASM_DESCR.CLOBBER_R9])
return ret