commit 5b9ef87373ef53591a3e0c4c8c3e1f09d8d5ff70
parent 0fffffe53076e11126f574b594a71db62d144b2a
Author: Sylvia Ivory <git@sivory.net>
Date: Sun, 15 Mar 2026 20:07:36 -0700
Lua REPL
Diffstat:
2 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/sylveos/root.zig b/sylveos/root.zig
@@ -167,5 +167,5 @@ fn main() !void {
\\ Entrypoint: {X:0>8}
\\
, .{ empty.stack_pointer, empty.entrypoint });
- try loader.execute(&empty, 0, &[_][]const u8{ "lua", "hello.lua" }, &[_][]u8{});
+ try loader.execute(&empty, 0, &[_][]const u8{"lua"}, &[_][]u8{});
}
diff --git a/sylveos/syscall.zig b/sylveos/syscall.zig
@@ -73,9 +73,9 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
// 0 => {},
// exit
1, 248 => {
- const error_code = regs.gp[0];
+ // const error_code = regs.gp[0];
- uart.print("[syscall] exit({d})\n", .{error_code});
+ // uart.print("[syscall] exit({d})\n", .{error_code});
pi.reboot();
},
// fork
@@ -86,15 +86,18 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
const buffer: [*]u8 = @ptrFromInt(regs.gp[1]);
const count = regs.gp[2];
- uart.print("[syscall] read({d}, 0x{X}, {d})", .{ fd, @intFromPtr(buffer), count });
+ // uart.print("[syscall] read({d}, 0x{X}, {d})", .{ fd, @intFromPtr(buffer), count });
if (fd == 0) {
// stdin
+ var read: u32 = 0;
for (0..count) |i| {
const byte = uart.read_byte_sync();
buffer[i] = byte;
+ read += 1;
+ if (byte == '\n') break;
}
- regs.gp[0] = @bitCast(@as(i32, @bitCast(count)));
+ regs.gp[0] = @bitCast(@as(i32, @bitCast(read)));
} else if (fd == 3) {
// temporary buffer
const code = "print('hello world')";
@@ -110,7 +113,7 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
const buffer: [*]u8 = @ptrFromInt(regs.gp[1]);
const count = regs.gp[2];
- uart.print("[syscall] write({d}, 0x{X}, {d})", .{ fd, @intFromPtr(buffer), count });
+ // uart.print("[syscall] write({d}, 0x{X}, {d})", .{ fd, @intFromPtr(buffer), count });
// stdout
if (fd == 1) {
@@ -122,35 +125,35 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
},
// open
5 => {
- const path: [*:0]u8 = @ptrFromInt(regs.gp[0]);
- const flags = regs.gp[1];
+ // const path: [*:0]u8 = @ptrFromInt(regs.gp[0]);
+ // const flags = regs.gp[1];
- uart.print("[syscall] open({s}, 0x{X})", .{ path, flags });
+ // uart.print("[syscall] open({s}, 0x{X})", .{ path, flags });
regs.gp[0] = @bitCast(@as(i32, 3));
},
// close
6 => {
- const fd = regs.gp[0];
+ // const fd = regs.gp[0];
- uart.print("[syscall] close({d})", .{fd});
+ // uart.print("[syscall] close({d})", .{fd});
regs.gp[0] = 0;
},
// brk
45 => {
- uart.print("[syscall] brk(0x{X})", .{regs.gp[0]});
+ // uart.print("[syscall] brk(0x{X})", .{regs.gp[0]});
regs.gp[0] = sbrk(regs.gp[0]);
},
// clone
120 => {
- uart.print("[syscall] clone()", .{});
+ // uart.print("[syscall] clone()", .{});
regs.gp[0] = @bitCast(@as(i32, -38));
},
// mprotect
125 => {
// Trust me, totally protected
- uart.print("[syscall] mprotect(0x{X})", .{regs.gp[0]});
+ // uart.print("[syscall] mprotect(0x{X})", .{regs.gp[0]});
regs.gp[0] = 0;
},
// readv
@@ -159,7 +162,7 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
const iov_ptr: [*]IoVec = @ptrFromInt(regs.gp[1]);
const count = regs.gp[2];
- uart.print("[syscall] readv({d}, 0x{X}, {d})", .{ fd, @intFromPtr(iov_ptr), count });
+ // uart.print("[syscall] readv({d}, 0x{X}, {d})", .{ fd, @intFromPtr(iov_ptr), count });
const iov = iov_ptr[0..count];
@@ -185,7 +188,7 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
const iov_ptr: [*]const IoVec = @ptrFromInt(regs.gp[1]);
const count = regs.gp[2];
- uart.print("[syscall] writev({d}, 0x{X}, {d})", .{ fd, @intFromPtr(iov_ptr), count });
+ // uart.print("[syscall] writev({d}, 0x{X}, {d})", .{ fd, @intFromPtr(iov_ptr), count });
const iov = iov_ptr[0..count];
@@ -208,17 +211,17 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
const length = regs.gp[1];
const prot = regs.gp[2];
const flags = regs.gp[3];
- const fd = regs.gp[4];
- const offset = regs.gp[5];
-
- uart.print("[syscall] mmap2(0x{X}, {d}, 0x{X}, 0x{X}, {d}, {d})", .{
- addr,
- length,
- prot,
- flags,
- fd,
- offset,
- });
+ // const fd = regs.gp[4];
+ // const offset = regs.gp[5];
+
+ // uart.print("[syscall] mmap2(0x{X}, {d}, 0x{X}, 0x{X}, {d}, {d})", .{
+ // addr,
+ // length,
+ // prot,
+ // flags,
+ // fd,
+ // offset,
+ // });
var translated: u32 = 0;
@@ -280,7 +283,7 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
// 248 => {},
// set_tid_address
256 => {
- uart.print("[syscall] set_tid_address(0x{X})", .{regs.gp[0]});
+ // uart.print("[syscall] set_tid_address(0x{X})", .{regs.gp[0]});
const addr: ?*i32 = @ptrFromInt(regs.gp[0]);
if (addr) |ptr| {
@@ -290,7 +293,7 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
},
// clock_gettime64
403 => {
- uart.print("[syscall] clock_gettime64(0x{X})", .{regs.gp[0]});
+ // uart.print("[syscall] clock_gettime64(0x{X})", .{regs.gp[0]});
const time = pi.devices.clock.current_count();
const seconds = time / std.time.us_per_s;
@@ -306,7 +309,7 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
983045 => {
const addr = regs.gp[0];
- uart.print("[syscall] ARM_set_tls(0x{X})", .{addr});
+ // uart.print("[syscall] ARM_set_tls(0x{X})", .{addr});
asm volatile ("mcr p15, 0, %[value], c13, c0, 3"
:
@@ -317,7 +320,7 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
},
// ARM_get_tls
983046 => {
- uart.print("[syscall] ARM_get_tls()", .{});
+ // uart.print("[syscall] ARM_get_tls()", .{});
const result = asm volatile ("mrc p15, 0, %[result], c13, c0, 3"
: [result] "=r" (-> usize),
@@ -325,12 +328,12 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
regs.gp[0] = result;
},
else => {
- uart.print("[syscall]: UNHANDLED({d})", .{n});
+ // uart.print("[syscall]: UNHANDLED({d})", .{n});
regs.gp[0] = @bitCast(@as(i32, -1));
},
}
- uart.print(" = 0x{X}\n", .{regs.gp[0]});
+ // uart.print(" = 0x{X}\n", .{regs.gp[0]});
regs.pc += 4;
last_registers = regs;
switching.restore_state(&last_registers);