The shared kernel<->user ABI contract (BootInformation, the SystemCall numbers, DeviceDescriptor, page_size, ...) is now the `system` module at system/system.zig, following the convention that a directory's root file takes the directory's name. One overlap to note: the runtime's syscall wrappers are already `runtime.system`, so the single file that uses both the contract and those wrappers (library/runtime/heap.zig) aliases the wrappers locally as `system_calls`. The two are distinct (top-level `system` vs `runtime.system`); everywhere else the contract is just `system`. Also: the QEMU run's serial capture now lands in the FHS log location, zig-out/var/log/system/serial0-<timestamp>.log — a stand-in for the kernel's own logging system, which will eventually write there itself. Suite 35/35 plus host tests green.
53 lines
2.3 KiB
Zig
53 lines
2.3 KiB
Zig
//! Raw `system_call` instruction wrappers for user space — one per arity.
|
|
//!
|
|
//! ABI: number in rax, arguments in rdi, rsi, rdx, r10, r8, r9, result in rax.
|
|
//! The `system_call` instruction itself clobbers rcx (it holds the return rip) and
|
|
//! r11 (the saved rflags); the kernel entry stub preserves everything else.
|
|
//! Note argument #3 goes in **r10, not rcx** — rcx is unavailable across the
|
|
//! instruction, so the kernel reads the 4th argument from r10.
|
|
|
|
const system = @import("system");
|
|
const SystemCall = system.SystemCall;
|
|
|
|
pub inline fn systemCall0(n: SystemCall) usize {
|
|
return asm volatile ("syscall"
|
|
: [ret] "={rax}" (-> usize),
|
|
: [n] "{rax}" (@intFromEnum(n)),
|
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
|
}
|
|
|
|
pub inline fn systemCall1(n: SystemCall, a0: usize) usize {
|
|
return asm volatile ("syscall"
|
|
: [ret] "={rax}" (-> usize),
|
|
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0),
|
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
|
}
|
|
|
|
pub inline fn systemCall2(n: SystemCall, a0: usize, a1: usize) usize {
|
|
return asm volatile ("syscall"
|
|
: [ret] "={rax}" (-> usize),
|
|
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0), [a1] "{rsi}" (a1),
|
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
|
}
|
|
|
|
pub inline fn systemCall3(n: SystemCall, a0: usize, a1: usize, a2: usize) usize {
|
|
return asm volatile ("syscall"
|
|
: [ret] "={rax}" (-> usize),
|
|
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0), [a1] "{rsi}" (a1), [a2] "{rdx}" (a2),
|
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
|
}
|
|
|
|
pub inline fn systemCall4(n: SystemCall, a0: usize, a1: usize, a2: usize, a3: usize) usize {
|
|
return asm volatile ("syscall"
|
|
: [ret] "={rax}" (-> usize),
|
|
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0), [a1] "{rsi}" (a1), [a2] "{rdx}" (a2), [a3] "{r10}" (a3),
|
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
|
}
|
|
|
|
pub inline fn systemCall5(n: SystemCall, a0: usize, a1: usize, a2: usize, a3: usize, a4: usize) usize {
|
|
return asm volatile ("syscall"
|
|
: [ret] "={rax}" (-> usize),
|
|
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0), [a1] "{rsi}" (a1), [a2] "{rdx}" (a2), [a3] "{r10}" (a3), [a4] "{r8}" (a4),
|
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
|
}
|