commit 4534a220dca0a4d1c79869e3512bf975195d7250
parent 87587621d9c6e6f68494275faa7a39717b4163b0
Author: Sylvia Ivory <git@sivory.net>
Date: Sun, 15 Mar 2026 23:51:54 -0700
Use journal in syscalls
Diffstat:
4 files changed, 79 insertions(+), 37 deletions(-)
diff --git a/sylveos/journal.zig b/sylveos/journal.zig
@@ -6,14 +6,16 @@ const uart = pi.devices.mini_uart;
const JOURNAL_START: u8 = 0x1;
const JOURNAL_START_SENTINEL: u8 = 0x2;
const JOURNAL_END_SENTINEL: u8 = 0x2;
+const JOURNAL_APPEND_LAST_START: u8 = 0x3;
+const JOURNAL_APPEND_LAST_END: u8 = 0x3;
pub const LogLevel = enum(u8) {
Critical = 0,
Error = 1,
Warning = 2,
Info = 3,
- Trace = 4,
- Debug = 5,
+ Debug = 4,
+ Trace = 5,
};
pub fn write_slice(level: LogLevel, slice: []const u8) void {
@@ -42,6 +44,12 @@ pub fn print(level: LogLevel, comptime fmt: []const u8, args: anytype) void {
end_entry();
}
+pub fn append(comptime fmt: []const u8, args: anytype) void {
+ uart.write_byte(JOURNAL_APPEND_LAST_START);
+ uart.print(fmt, args);
+ uart.write_byte(JOURNAL_APPEND_LAST_END);
+}
+
pub fn critical(comptime fmt: []const u8, args: anytype) void {
print(.Critical, fmt, args);
}
diff --git a/sylveos/syscall.zig b/sylveos/syscall.zig
@@ -3,6 +3,7 @@ const pi = @import("pi");
const loader = @import("./loader.zig");
const memory = @import("./memory.zig");
+const journal = @import("./journal.zig");
const switching = pi.switching;
const interrupts = pi.interrupts;
@@ -73,9 +74,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});
+ journal.trace("[syscall] exit({d})\n", .{error_code});
pi.reboot();
},
// fork
@@ -86,7 +87,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] read({d}, 0x{X}, {d})", .{ fd, @intFromPtr(buffer), count });
+ journal.trace("[syscall] read({d}, 0x{X}, {d})", .{ fd, @intFromPtr(buffer), count });
if (fd == 0) {
// stdin
@@ -113,7 +114,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 });
+ journal.trace("[syscall] write({d}, 0x{X}, {d})", .{ fd, @intFromPtr(buffer), count });
// stdout
if (fd == 1) {
@@ -125,35 +126,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 });
+ journal.trace("[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});
+ journal.trace("[syscall] close({d})", .{fd});
regs.gp[0] = 0;
},
// brk
45 => {
- // uart.print("[syscall] brk(0x{X})", .{regs.gp[0]});
+ journal.trace("[syscall] brk(0x{X})", .{regs.gp[0]});
regs.gp[0] = sbrk(regs.gp[0]);
},
// clone
120 => {
- // uart.print("[syscall] clone()", .{});
+ journal.trace("[syscall] clone()", .{});
regs.gp[0] = @bitCast(@as(i32, -38));
},
// mprotect
125 => {
// Trust me, totally protected
- // uart.print("[syscall] mprotect(0x{X})", .{regs.gp[0]});
+ journal.trace("[syscall] mprotect(0x{X})", .{regs.gp[0]});
regs.gp[0] = 0;
},
// readv
@@ -162,7 +163,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 });
+ journal.trace("[syscall] readv({d}, 0x{X}, {d})", .{ fd, @intFromPtr(iov_ptr), count });
const iov = iov_ptr[0..count];
@@ -188,7 +189,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 });
+ journal.trace("[syscall] writev({d}, 0x{X}, {d})", .{ fd, @intFromPtr(iov_ptr), count });
const iov = iov_ptr[0..count];
@@ -211,17 +212,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];
+
+ journal.trace("[syscall] mmap2(0x{X}, {d}, 0x{X}, 0x{X}, {d}, {d})", .{
+ addr,
+ length,
+ prot,
+ flags,
+ fd,
+ offset,
+ });
var translated: u32 = 0;
@@ -283,7 +284,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]});
+ journal.trace("[syscall] set_tid_address(0x{X})", .{regs.gp[0]});
const addr: ?*i32 = @ptrFromInt(regs.gp[0]);
if (addr) |ptr| {
@@ -293,7 +294,7 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
},
// clock_gettime64
403 => {
- // uart.print("[syscall] clock_gettime64(0x{X})", .{regs.gp[0]});
+ journal.trace("[syscall] clock_gettime64(0x{X})", .{regs.gp[0]});
const time = pi.devices.clock.current_count();
const seconds = time / std.time.us_per_s;
@@ -309,7 +310,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});
+ journal.trace("[syscall] ARM_set_tls(0x{X})", .{addr});
asm volatile ("mcr p15, 0, %[value], c13, c0, 3"
:
@@ -320,7 +321,7 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
},
// ARM_get_tls
983046 => {
- // uart.print("[syscall] ARM_get_tls()", .{});
+ journal.trace("[syscall] ARM_get_tls()", .{});
const result = asm volatile ("mrc p15, 0, %[result], c13, c0, 3"
: [result] "=r" (-> usize),
@@ -328,12 +329,12 @@ pub fn syscall_handler(registers: interrupts.Registers, _: interrupts.ExceptionV
regs.gp[0] = result;
},
else => {
- // uart.print("[syscall]: UNHANDLED({d})", .{n});
+ journal.warn("[syscall]: UNHANDLED({d})", .{n});
regs.gp[0] = @bitCast(@as(i32, -1));
},
}
- // uart.print(" = 0x{X}\n", .{regs.gp[0]});
+ journal.append(" = 0x{X}", .{regs.gp[0]});
regs.pc += 4;
last_registers = regs;
switching.restore_state(&last_registers);
diff --git a/tools/src/sylveos/journal.rs b/tools/src/sylveos/journal.rs
@@ -38,6 +38,12 @@ impl JournalState {
pub fn append(&mut self, entry: JournalEntry) {
self.lines.push(entry);
}
+
+ pub fn append_last(&mut self, msg: String) {
+ if let Some(last) = self.lines.last_mut() {
+ last.msg.push_str(&msg);
+ }
+ }
}
impl ParagraphView for JournalWidget {
@@ -96,8 +102,8 @@ pub enum LogLevel {
Error = 1,
Warning = 2,
Info = 3,
- Trace = 4,
- Debug = 5,
+ Debug = 4,
+ Trace = 5,
Invalid = 6,
}
@@ -108,8 +114,8 @@ impl LogLevel {
LogLevel::Error => "error ",
LogLevel::Warning => "warning ",
LogLevel::Info => "info ",
- LogLevel::Trace => "trace ",
LogLevel::Debug => "debug ",
+ LogLevel::Trace => "trace ",
LogLevel::Invalid => "invalid ",
}
}
@@ -121,7 +127,7 @@ impl LogLevel {
2 => Self::Warning,
3 => Self::Info,
4 => Self::Debug,
- 5 => Self::Debug,
+ 5 => Self::Trace,
_ => Self::Invalid,
}
}
diff --git a/tools/src/sylveos/mod.rs b/tools/src/sylveos/mod.rs
@@ -112,6 +112,10 @@ impl App {
let mut state = journal_state.write().unwrap();
state.append(entry);
}
+ Message::Append(msg) => {
+ let mut state = journal_state.write().unwrap();
+ state.append_last(msg);
+ }
Message::Disconnect => {
disconnected.store(true, Ordering::SeqCst);
return;
@@ -216,6 +220,7 @@ impl App {
enum Message {
Console(u8),
Journal(JournalEntry),
+ Append(String),
Disconnect,
}
@@ -268,5 +273,27 @@ async fn parse_message(port: &mut ReadHalf<SerialStream>) -> Result<Message> {
return Ok(Message::Journal(JournalEntry { time, level, msg }));
}
+ if byte == 3 {
+ // Append to last entry
+ let mut buffer: Vec<u8> = Vec::new();
+ loop {
+ let byte = port.read_u8().await?;
+
+ if byte == 0 {
+ return Ok(Message::Disconnect);
+ }
+
+ if byte == 3 {
+ break;
+ }
+
+ buffer.push(byte);
+ }
+
+ let msg = String::from_utf8_lossy(buffer.as_slice()).to_string();
+
+ return Ok(Message::Append(msg));
+ }
+
Ok(Message::Console(byte))
}