Files
ViperOS/vpsdk/stdio.vp
T
TermiNexus 5b4bab59cc chore(ViperOS): 合并落库内核侧在途改动并移除 vpsdk wiki 拷贝
VKernel / vpsdk / Apps / Libs 共 30 个源文件:内核与 SDK 侧的新语法适配及编译修正(含 bootinfo.vp / main.vp 位宽改 uint64、gfx.vp 前向引用改指针、devfs.vp 指针解引用赋值、elf.vp 跨模块函数取值等)。删除 vpsdk/wiki/*.md(14 文件,约 -8100 行):与仓库根 wiki 重复的拷贝,统一以根 wiki 为唯一来源。
2026-10-07 19:04:33 +08:00

34 lines
1.3 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 通知内核销毁本进程窗口。
# ============================================================
export def printf(fmt: const str, *args) -> int:
"""格式化输出到串口(SERIAL_PUTS syscall),返回输出字节数"""
if fmt is None:
return 0
buf: t.CArray[char, 1024]
n: int = viperlib.vsnprintf(&buf, 1024, fmt, args)
_syscall._syscall1(uint64(_syscall.SERIAL_PUTS), uint64(&buf))
return n
export def exit(status: int):
"""终止当前进程(EXIT syscall:销毁本进程窗口)"""
_syscall._syscall1(uint64(_syscall.EXIT), uint64(status))
export def fflush(stream: const t.CPtr) -> int:
"""刷新输出流:串口/控制台输出都是直写,无缓冲可刷,空操作返回 0
覆盖 libc fflush 的裸机缺失(includes/memhub.vp 的诊断/终止路径 call @fflush);
与 printf/exit 同为 CExport 裸名,供内核侧 includes 跨模块引用解析。
"""
return 0