Files
ViperOS/vpsdk/process.vp
T
TermiNexus 7e0aa5c7af feat(acpi): power off via the ACPI FADT
Pass the firmware ACPI RSDP through boot_info so the kernel can locate
the FADT. Shutdown now writes the S5 sleep type to the PM1a/PM1b control
blocks advertised by the FADT instead of fixed QEMU/Bochs/VirtualBox
ports.

- boot: capture the ACPI 2.0/1.0 RSDP from the UEFI configuration table
- kernel: add platform/acpi; walk RSDP -> RSDT/XSDT -> FADT
- syscall: power_shutdown calls acpi.poweroff()
2026-10-27 17:05:05 +08:00

84 lines
2.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from . import syscall as syscall
def exit(code: int):
syscall._syscall1(uint64(syscall.Syscall.EXIT), uint64(code))
def reboot():
"""Reset the machine."""
syscall._syscall0(uint64(syscall.Syscall.REBOOT))
def shutdown():
"""Power off the machine via ACPI S5."""
syscall._syscall0(uint64(syscall.Syscall.SHUTDOWN))
def thread_exit():
"""当前用户线程显式退出:内核回收其用户栈并标记线程结束(不返回)。"""
syscall._syscall0(uint64(syscall.Syscall.THREAD_EXIT))
def yield_cpu():
# S3e:原走 WAIT_WINDOW(0,2)(UI 私有 syscall,已随内核 UI 一并删除)。
# 语义等价的是 Linux 对齐段里的 sched_yield ⇒ 内核同样是 try_reschedule()。
syscall._syscall0(uint64(syscall.Syscall.YIELD))
def get_pid() -> int:
"""当前进程 pid(getpid)。/dev/desk 的事件按 pid 过滤,建窗前就要拿到它。"""
return int(syscall._syscall0(uint64(syscall.Syscall.GETPID)))
def spawn(path: const str, blocking: int = 0) -> int:
return int(syscall._syscall2(uint64(syscall.Syscall.SPAWN), uint64(path), uint64(blocking)))
def thread_create(func: rawptr, arg: rawptr = None) -> int:
return int(syscall._syscall2(uint64(syscall.Syscall.THREAD_CREATE), uint64(func), uint64(arg)))
class Thread:
_tid: int
_func: rawptr
_arg: rawptr
_running: int
def __init__(self, func: rawptr, arg: rawptr = None):
self._func = func
self._arg = arg
self._tid = -1
self._running = 0
def start(self) -> int:
if self._running: return -1
self._tid = thread_create(self._func, self._arg)
if self._tid < 0: return -1
self._running = 1
return 0
def is_alive(self) -> int:
return self._running
def get_tid(self) -> int:
return self._tid
class Process:
_pid: int
_path: [128]char
def __init__(self, path: const str):
self._pid = -1
i: int = 0
for ch in path:
if i >= 127: break
self._path[i] = ch
i += 1
self._path[i] = 0
def start(self) -> int:
self._pid = spawn(&self._path[0], 0)
return self._pid
def start_blocking(self) -> int:
self._pid = spawn(&self._path[0], 1)
return self._pid
def get_pid(self) -> int:
return self._pid