Initial import of ViperOS

This commit is contained in:
Viper
2026-07-19 12:38:20 +08:00
commit 6813947181
104 changed files with 26710 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
SECTIONS {
. = 0;
.text : {
*(.text)
*(.text.*)
}
.rodata : {
*(.rodata)
*(.rodata.*)
}
.data : {
*(.data)
*(.data.*)
}
.bss : {
PROVIDE(__bss_start = .);
*(.bss)
*(.bss.*)
PROVIDE(__bss_end = .);
}
/DISCARD/ : {
*(.comment)
*(.note)
*(.eh_frame)
*(.eh_frame_hdr)
*(.reloc)
*(.debug*)
}
}

View File

@@ -0,0 +1,34 @@
{
"name": "SerialLogger",
"version": "1.0.0",
"source_dir": "./",
"temp_dir": "./temp",
"output_dir": "./output",
"compiler": {
"cmd": "llc",
"flags": ["-filetype=obj", "-mtriple=x86_64-none-elf", "-relocation-model=pic", "-O2"]
},
"linker": {
"cmd": "ld.lld.exe",
"flags": [
"-m", "elf_x86_64",
"-T", "linker.ld",
"--oformat", "elf64-x86-64",
"-shared",
"-z", "notext",
"--no-relax",
"--strip-all"
],
"output": "slog.so"
},
"includes": ["../.."],
"target": {
"triple": "x86_64-none-elf",
"datalayout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
},
"options": {
"slice_level": 3,
"target": "llvm",
"strict_mode": true
}
}

View File

@@ -0,0 +1,12 @@
import vpsdk.syscall as syscall
import t, c
def log_info(msg: t.CConst | t.CChar | t.CPtr) -> t.CVoid | t.CExport:
syscall._syscall1(t.CUInt64T(syscall.SERIAL_PUTS), t.CUInt64T("[SerialLogger] "))
syscall._syscall1(t.CUInt64T(syscall.SERIAL_PUTS), t.CUInt64T(msg))
syscall._syscall1(t.CUInt64T(syscall.SERIAL_PUTS), t.CUInt64T("\n"))
def log_warn(msg: t.CConst | t.CChar | t.CPtr) -> t.CVoid | t.CExport:
syscall._syscall1(t.CUInt64T(syscall.SERIAL_PUTS), t.CUInt64T("[SerialLogger:WARN] "))
syscall._syscall1(t.CUInt64T(syscall.SERIAL_PUTS), t.CUInt64T(msg))
syscall._syscall1(t.CUInt64T(syscall.SERIAL_PUTS), t.CUInt64T("\n"))

34
Libs/VPUI64/linker.ld Normal file
View File

@@ -0,0 +1,34 @@
SECTIONS {
. = 0;
.text : {
*(.text)
*(.text.*)
}
.rodata : {
*(.rodata)
*(.rodata.*)
}
.data : {
*(.data)
*(.data.*)
}
.bss : {
PROVIDE(__bss_start = .);
*(.bss)
*(.bss.*)
PROVIDE(__bss_end = .);
}
/DISCARD/ : {
*(.comment)
*(.note)
*(.eh_frame)
*(.eh_frame_hdr)
*(.reloc)
*(.debug*)
}
}

34
Libs/VPUI64/project.json Normal file
View File

@@ -0,0 +1,34 @@
{
"name": "VPUI64",
"version": "1.0.0",
"source_dir": "./",
"temp_dir": "./temp",
"output_dir": "./output",
"compiler": {
"cmd": "llc",
"flags": ["-filetype=obj", "-mtriple=x86_64-none-elf", "-relocation-model=pic", "-O2"]
},
"linker": {
"cmd": "ld.lld.exe",
"flags": [
"-m", "elf_x86_64",
"-T", "linker.ld",
"--oformat", "elf64-x86-64",
"-shared",
"-z", "notext",
"--no-relax",
"--strip-all"
],
"output": "vpui64.so"
},
"includes": ["../.."],
"target": {
"triple": "x86_64-none-elf",
"datalayout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
},
"options": {
"slice_level": 3,
"target": "llvm",
"strict_mode": true
}
}

80
Libs/VPUI64/vpui64.py Normal file
View File

@@ -0,0 +1,80 @@
import t
import vpsdk.syscall as syscall
UINT32PTR: t.CTypedef = t.CUInt32T | t.CPtr
def color_rgb(r: t.CUInt8T, g: t.CUInt8T, b: t.CUInt8T) -> t.CUInt32T:
return t.CUInt32T(r) | (t.CUInt32T(g) << 8) | (t.CUInt32T(b) << 16)
def get_winbuf(win_id: t.CInt) -> UINT32PTR:
return t.CVoid(syscall._syscall2(t.CUInt64T(syscall.GET_WINBUF), t.CUInt64T(win_id), 0), t.CPtr)
def win_flush(win_id: t.CInt) -> t.CVoid:
syscall._syscall2(t.CUInt64T(syscall.WIN_FLUSH), t.CUInt64T(win_id), 0)
def draw_pixel(buf: UINT32PTR, bw: t.CInt, x: t.CInt, y: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
if x < 0 or y < 0: return
buf[y * bw + x] = color
def draw_line(buf: UINT32PTR, bw: t.CInt, x0: t.CInt, y0: t.CInt, x1: t.CInt, y1: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
dx: t.CInt = x1 - x0
dy: t.CInt = y1 - y0
sx: t.CInt = 1
sy: t.CInt = 1
if dx < 0:
dx = -dx
sx = -1
if dy < 0:
dy = -dy
sy = -1
err: t.CInt = dx - dy
while True:
if x0 >= 0 and y0 >= 0:
buf[y0 * bw + x0] = color
if x0 == x1 and y0 == y1:
break
e2: t.CInt = 2 * err
if e2 > -dy:
err -= dy
x0 += sx
if e2 < dx:
err += dx
y0 += sy
def draw_rect(buf: UINT32PTR, bw: t.CInt, rx: t.CInt, ry: t.CInt, rw: t.CInt, rh: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
draw_line(buf, bw, rx, ry, rx + rw - 1, ry, color)
draw_line(buf, bw, rx + rw - 1, ry, rx + rw - 1, ry + rh - 1, color)
draw_line(buf, bw, rx + rw - 1, ry + rh - 1, rx, ry + rh - 1, color)
draw_line(buf, bw, rx, ry + rh - 1, rx, ry, color)
def fill_rect(buf: UINT32PTR, bw: t.CInt, rx: t.CInt, ry: t.CInt, rw: t.CInt, rh: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
if rx < 0: rw += rx; rx = 0
if ry < 0: rh += ry; ry = 0
if rw <= 0 or rh <= 0: return
py: t.CInt = ry
while py < ry + rh:
px: t.CInt = rx
while px < rx + rw:
buf[py * bw + px] = color
px += 1
py += 1
def draw_circle(buf: UINT32PTR, bw: t.CInt, cx: t.CInt, cy: t.CInt, r: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
x: t.CInt = r
y: t.CInt = 0
d: t.CInt = 1 - r
while x >= y:
if cx + x >= 0: buf[(cy + y) * bw + cx + x] = color
if cx + y >= 0: buf[(cy + x) * bw + cx + y] = color
if cx - y >= 0: buf[(cy + x) * bw + cx - y] = color
if cx - x >= 0: buf[(cy + y) * bw + cx - x] = color
if cx - x >= 0: buf[(cy - y) * bw + cx - x] = color
if cx - y >= 0: buf[(cy - x) * bw + cx - y] = color
if cx + y >= 0: buf[(cy - x) * bw + cx + y] = color
if cx + x >= 0: buf[(cy - y) * bw + cx + x] = color
y += 1
if d <= 0:
d += 2 * y + 1
else:
x -= 1
d += 2 * (y - x) + 1