内核 intr/syscall.vp 与 vpsdk/syscall.vp 各一份 1..34 的 define 表改为同名 enum Syscall。编号口径:与 Linux 同名同号;Linux 有而我们未实现的留空不占号(12 brk / 39 getpid / 84 rmdir / 217 getdents64 / 257 openat … 需要时按号补)。 15 个语义重合的调用直接用 Linux 号:READ 0 / WRITE 1 / OPEN 2 / CLOSE 3 / STAT 4 / SEEK 8 / MMAP 9 / MUNMAP 11 / YIELD 24 / THREAD_CREATE 56(≈clone) / SPAWN 59(≈execve) / THREAD_EXIT 60(exit) / MKDIR 83 / REMOVE 87 / EXIT 231(exit_group)。 其余 19 个(UI 11 个 + SERIAL_PUTS/TELL/SIZE/OPENDIR/READDIR/CLOSEDIR/LOAD_SO/SO_CALL1)暂放 0x1000 起的**临时私有段**,每条带迁移标注:私有能力最终不占 syscall 号、改走 devfs 设备文件;UI 11 个待用户态 explorer(图形壳)接管 framebuffer 与输入后删除。 内核派发链改 n == int(Syscall.X)(n 是 int/i64、成员是 i32,显式 int() 规避未证实的混合宽度比较);SDK 全部调用点统一为 syscall.Syscall.X;stdlib 的 SYSCALL_MMAP 别名并入 Syscall.MMAP;Terminal 里硬编码的 uint64(18) 改为常量。
124 lines
6.5 KiB
Plaintext
124 lines
6.5 KiB
Plaintext
# ============================================================================
|
||
# 系统调用号表(SDK 侧镜像)。**与 VKernel/Kernel/intr/syscall.vp 的同名 enum 逐条对应**:
|
||
# vpsdk 不允许依赖 VKernel,所以这里是一份必须手工同步的副本 —— 增删/改号/改名两边一起改。
|
||
# 编号口径:与 Linux x86-64 ABI 同名同号;Linux 有而我们未实现的留空不占号;
|
||
# 我们独有的能力不再新增 syscall,最终走 devfs 设备文件或下沉到用户层(见 0x1000+ 段的标注)。
|
||
# ============================================================================
|
||
enum Syscall:
|
||
# ---- Linux 对齐段(号 = Linux x86-64 的号)----
|
||
READ = 0 # read(fd, buf, count)
|
||
WRITE = 1 # write(fd, buf, count)
|
||
OPEN = 2 # open(path, flags)
|
||
CLOSE = 3 # close(fd)
|
||
STAT = 4 # stat(path, info)(结构体仍是本系统的 fileinfo)
|
||
SEEK = 8 # lseek(fd, offset, whence)(whence 目前恒 0 = SEEK_SET)
|
||
MMAP = 9 # mmap(size) → VA(ABI 待向 Linux 的 addr/len/prot/flags/fd/off 靠拢)
|
||
MUNMAP = 11 # munmap(ptr, size)(目前空实现)
|
||
YIELD = 24 # sched_yield()
|
||
THREAD_CREATE = 56 # clone():建用户线程,返回 tid
|
||
SPAWN = 59 # execve():加载并运行新 ELF,返回 pid
|
||
THREAD_EXIT = 60 # exit():退役当前线程
|
||
MKDIR = 83 # mkdir(path)
|
||
REMOVE = 87 # unlink(path)
|
||
EXIT = 231 # exit_group():退役当前线程 + 拆掉本 pid 的窗口
|
||
# ---- 临时私有段(0x1000+):Linux 无对应,且**逐条都会被消掉** ----
|
||
# 目标形态:私有能力不占 syscall 号 → 改 devfs 设备文件;UI 11 个 → 由用户态
|
||
# explorer(图形壳)接管 framebuffer 与输入后删除。当前保留只为让现有 app 还能跑。
|
||
SERIAL_PUTS = 0x1000 # TODO(devfs):改为 write(/dev/serial0)
|
||
TELL = 0x1001 # TODO(linux):可由 lseek(fd, 0, SEEK_CUR) 表达
|
||
SIZE = 0x1002 # TODO(linux):可由 fstat 表达
|
||
OPENDIR = 0x1003 # TODO(linux):openat(O_DIRECTORY) + getdents64
|
||
READDIR = 0x1004 # TODO(linux):getdents64
|
||
CLOSEDIR = 0x1005 # TODO(linux):close
|
||
LOAD_SO = 0x1006 # TODO(用户层):动态库加载下沉
|
||
SO_CALL1 = 0x1007 # TODO(用户层):同上
|
||
WAIT_WINDOW = 0x1008 # TODO(explorer):UI
|
||
CREATE_WINDOW = 0x1009 # TODO(explorer):UI
|
||
DRAW_TEXT = 0x100A # TODO(explorer):UI
|
||
GET_WINBUF = 0x100B # TODO(explorer):UI
|
||
WIN_FLUSH = 0x100C # TODO(explorer):UI
|
||
POLL_EVENT = 0x100D # TODO(explorer):UI
|
||
SET_CURSOR = 0x100E # TODO(explorer):UI
|
||
SET_TITLE = 0x100F # TODO(explorer):UI
|
||
SET_GEOMETRY = 0x1010 # TODO(explorer):UI
|
||
SET_RESIZABLE = 0x1011 # TODO(explorer):UI
|
||
GET_WIN_SIZE = 0x1012 # TODO(explorer):UI
|
||
|
||
def _syscall0(num: uint64) -> uint64:
|
||
ret: uint64
|
||
__asm__(f"""mov rax, {asminp(num, ASM_DESCR.REG_ANY)}
|
||
syscall""",
|
||
out=[asmout(ret, ASM_DESCR.OUTPUT_REG)],
|
||
op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX,
|
||
ASM_DESCR.CLOBBER_R11])
|
||
return ret
|
||
|
||
def _syscall1(num: uint64, a1: uint64) -> uint64:
|
||
ret: uint64
|
||
__asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)}
|
||
mov rax, {asminp(num, ASM_DESCR.REG_ANY)}
|
||
syscall""",
|
||
out=[asmout(ret, ASM_DESCR.OUTPUT_REG)],
|
||
op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX,
|
||
ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI])
|
||
return ret
|
||
|
||
def _syscall2(num: uint64, a1: uint64, a2: uint64) -> uint64:
|
||
ret: uint64
|
||
__asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)}
|
||
mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)}
|
||
mov rax, {asminp(num, ASM_DESCR.REG_ANY)}
|
||
syscall""",
|
||
out=[asmout(ret, ASM_DESCR.OUTPUT_REG)],
|
||
op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX,
|
||
ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI,
|
||
ASM_DESCR.CLOBBER_RSI])
|
||
return ret
|
||
|
||
def _syscall3(num: uint64, a1: uint64, a2: uint64, a3: uint64) -> uint64:
|
||
ret: uint64
|
||
__asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)}
|
||
mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)}
|
||
mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)}
|
||
mov rax, {asminp(num, ASM_DESCR.REG_ANY)}
|
||
syscall""",
|
||
out=[asmout(ret, ASM_DESCR.OUTPUT_REG)],
|
||
op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX,
|
||
ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI,
|
||
ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX])
|
||
return ret
|
||
|
||
def _syscall5(num: uint64, a1: uint64, a2: uint64, a3: uint64, a4: uint64, a5: uint64) -> uint64:
|
||
ret: uint64
|
||
__asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)}
|
||
mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)}
|
||
mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)}
|
||
mov r10, {asminp(a4, ASM_DESCR.REG_ANY)}
|
||
mov r8, {asminp(a5, ASM_DESCR.REG_ANY)}
|
||
mov rax, {asminp(num, ASM_DESCR.REG_ANY)}
|
||
syscall""",
|
||
out=[asmout(ret, ASM_DESCR.OUTPUT_REG)],
|
||
op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX,
|
||
ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI,
|
||
ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX,
|
||
ASM_DESCR.CLOBBER_R10, 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
|
||
__asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)}
|
||
mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)}
|
||
mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)}
|
||
mov r10, {asminp(a4, ASM_DESCR.REG_ANY)}
|
||
mov r8, {asminp(a5, ASM_DESCR.REG_ANY)}
|
||
mov r9, {asminp(a6, ASM_DESCR.REG_ANY)}
|
||
mov rax, {asminp(num, ASM_DESCR.REG_ANY)}
|
||
syscall""",
|
||
out=[asmout(ret, ASM_DESCR.OUTPUT_REG)],
|
||
op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX,
|
||
ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI,
|
||
ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX,
|
||
ASM_DESCR.CLOBBER_R10, ASM_DESCR.CLOBBER_R8,
|
||
ASM_DESCR.CLOBBER_R9])
|
||
return ret
|