Files
ViperOS/vpsdk/stdio.vp
T

25 lines
1.0 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.
import vpsdk.syscall as _syscall
import t, c
import viperlib
# ============================================================
# vpsdk.stdio - 用户态 printf/exit(CExport 裸名,供内核侧代码
# 如 includes/memhub.vp 跨模块引用解析)
#
# 裸机 App 无 libc:printf 走 viperlib.vsnprintf 格式化 + SERIAL_PUTS
# syscall 输出到串口;exit 走 EXIT syscall 通知内核销毁本进程窗口。
# ============================================================
def printf(fmt: t.CConst | str, *args) -> t.CInt | t.CExport:
"""格式化输出到串口(SERIAL_PUTS syscall),返回输出字节数"""
if fmt is None:
return 0
buf: t.CArray[t.CChar, 1024]
n: t.CInt = viperlib.vsnprintf(c.Addr(buf), 1024, fmt, args)
_syscall._syscall1(t.CUInt64T(_syscall.SERIAL_PUTS), t.CUInt64T(c.Addr(buf)))
return n
def exit(status: t.CInt) -> t.CVoid | t.CExport:
"""终止当前进程(EXIT syscall:销毁本进程窗口)"""
_syscall._syscall1(t.CUInt64T(_syscall.EXIT), t.CUInt64T(status))