Files
ViperOS/vpsdk/stdio.vp
T

34 lines
1.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.
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))
def fflush(stream: t.CConst | t.CVoid | t.CPtr) -> t.CInt | t.CExport:
"""刷新输出流:串口/控制台输出都是直写,无缓冲可刷,空操作返回 0
覆盖 libc fflush 的裸机缺失(includes/memhub.vp 的诊断/终止路径 call @fflush);
与 printf/exit 同为 CExport 裸名,供内核侧 includes 跨模块引用解析。
"""
return 0