zig fmt
This commit is contained in:
@@ -124,4 +124,4 @@ pub fn findDeviceDescriptorByHid(buffer: []DeviceDescriptor, hid_needle: []const
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,34 +19,49 @@ pub inline fn systemCall0(n: SystemCall) usize {
|
|||||||
pub inline fn systemCall1(n: SystemCall, a0: usize) usize {
|
pub inline fn systemCall1(n: SystemCall, a0: usize) usize {
|
||||||
return asm volatile ("syscall"
|
return asm volatile ("syscall"
|
||||||
: [ret] "={rax}" (-> usize),
|
: [ret] "={rax}" (-> usize),
|
||||||
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0),
|
: [n] "{rax}" (@intFromEnum(n)),
|
||||||
|
[a0] "{rdi}" (a0),
|
||||||
: .{ .rcx = true, .r11 = true, .memory = true });
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn systemCall2(n: SystemCall, a0: usize, a1: usize) usize {
|
pub inline fn systemCall2(n: SystemCall, a0: usize, a1: usize) usize {
|
||||||
return asm volatile ("syscall"
|
return asm volatile ("syscall"
|
||||||
: [ret] "={rax}" (-> usize),
|
: [ret] "={rax}" (-> usize),
|
||||||
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0), [a1] "{rsi}" (a1),
|
: [n] "{rax}" (@intFromEnum(n)),
|
||||||
|
[a0] "{rdi}" (a0),
|
||||||
|
[a1] "{rsi}" (a1),
|
||||||
: .{ .rcx = true, .r11 = true, .memory = true });
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn systemCall3(n: SystemCall, a0: usize, a1: usize, a2: usize) usize {
|
pub inline fn systemCall3(n: SystemCall, a0: usize, a1: usize, a2: usize) usize {
|
||||||
return asm volatile ("syscall"
|
return asm volatile ("syscall"
|
||||||
: [ret] "={rax}" (-> usize),
|
: [ret] "={rax}" (-> usize),
|
||||||
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0), [a1] "{rsi}" (a1), [a2] "{rdx}" (a2),
|
: [n] "{rax}" (@intFromEnum(n)),
|
||||||
|
[a0] "{rdi}" (a0),
|
||||||
|
[a1] "{rsi}" (a1),
|
||||||
|
[a2] "{rdx}" (a2),
|
||||||
: .{ .rcx = true, .r11 = true, .memory = true });
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn systemCall4(n: SystemCall, a0: usize, a1: usize, a2: usize, a3: usize) usize {
|
pub inline fn systemCall4(n: SystemCall, a0: usize, a1: usize, a2: usize, a3: usize) usize {
|
||||||
return asm volatile ("syscall"
|
return asm volatile ("syscall"
|
||||||
: [ret] "={rax}" (-> usize),
|
: [ret] "={rax}" (-> usize),
|
||||||
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0), [a1] "{rsi}" (a1), [a2] "{rdx}" (a2), [a3] "{r10}" (a3),
|
: [n] "{rax}" (@intFromEnum(n)),
|
||||||
|
[a0] "{rdi}" (a0),
|
||||||
|
[a1] "{rsi}" (a1),
|
||||||
|
[a2] "{rdx}" (a2),
|
||||||
|
[a3] "{r10}" (a3),
|
||||||
: .{ .rcx = true, .r11 = true, .memory = true });
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn systemCall5(n: SystemCall, a0: usize, a1: usize, a2: usize, a3: usize, a4: usize) usize {
|
pub inline fn systemCall5(n: SystemCall, a0: usize, a1: usize, a2: usize, a3: usize, a4: usize) usize {
|
||||||
return asm volatile ("syscall"
|
return asm volatile ("syscall"
|
||||||
: [ret] "={rax}" (-> usize),
|
: [ret] "={rax}" (-> usize),
|
||||||
: [n] "{rax}" (@intFromEnum(n)), [a0] "{rdi}" (a0), [a1] "{rsi}" (a1), [a2] "{rdx}" (a2), [a3] "{r10}" (a3), [a4] "{r8}" (a4),
|
: [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 });
|
: .{ .rcx = true, .r11 = true, .memory = true });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ pub const PixelFormat = enum(u32) {
|
|||||||
/// Output Protocol (a headless server, say). The kernel must treat on-screen
|
/// Output Protocol (a headless server, say). The kernel must treat on-screen
|
||||||
/// output as optional and never assume a framebuffer exists.
|
/// output as optional and never assume a framebuffer exists.
|
||||||
pub const Framebuffer = extern struct {
|
pub const Framebuffer = extern struct {
|
||||||
base: usize, // the memory address where pixel data starts (0 = none)
|
base: usize, // the memory address where pixel data starts (0 = none)
|
||||||
width: u32, // visible pixels per row (e.g. 1920)
|
width: u32, // visible pixels per row (e.g. 1920)
|
||||||
height: u32, // visible rows (e.g. 1080)
|
height: u32, // visible rows (e.g. 1080)
|
||||||
pitch: u32, // bytes from the start of one row to the start of the next
|
pitch: u32, // bytes from the start of one row to the start of the next
|
||||||
format: PixelFormat,
|
format: PixelFormat,
|
||||||
|
|
||||||
/// Whether a usable framebuffer was handed over.
|
/// Whether a usable framebuffer was handed over.
|
||||||
|
|||||||
@@ -126,17 +126,22 @@ test "parses a nested namespace and finds the sleep package" {
|
|||||||
// Scope(\_SB) packagelen=0x27
|
// Scope(\_SB) packagelen=0x27
|
||||||
0x10, 0x27, 0x5C, 0x5F, 0x53, 0x42, 0x5F,
|
0x10, 0x27, 0x5C, 0x5F, 0x53, 0x42, 0x5F,
|
||||||
// Device(PCI0) packagelen=0x1F
|
// Device(PCI0) packagelen=0x1F
|
||||||
0x5B, 0x82, 0x1F, 0x50, 0x43, 0x49, 0x30,
|
0x5B, 0x82, 0x1F, 0x50, 0x43,
|
||||||
|
0x49, 0x30,
|
||||||
// Name(_HID, 0x11)
|
// Name(_HID, 0x11)
|
||||||
0x08, 0x5F, 0x48, 0x49, 0x44, 0x0A, 0x11,
|
0x08, 0x5F, 0x48, 0x49, 0x44, 0x0A, 0x11,
|
||||||
// Method(MTHD, flags=1) empty, packagelen=0x06
|
// Method(MTHD, flags=1) empty, packagelen=0x06
|
||||||
0x14, 0x06, 0x4D, 0x54, 0x48, 0x44, 0x01,
|
0x14, 0x06, 0x4D,
|
||||||
|
0x54, 0x48, 0x44, 0x01,
|
||||||
// Method(CALL, flags=0) { MTHD(Zero) }, packagelen=0x0B
|
// Method(CALL, flags=0) { MTHD(Zero) }, packagelen=0x0B
|
||||||
0x14, 0x0B, 0x43, 0x41, 0x4C, 0x4C, 0x00, 0x4D, 0x54, 0x48, 0x44, 0x00,
|
0x14, 0x0B, 0x43, 0x41, 0x4C, 0x4C, 0x00, 0x4D,
|
||||||
|
0x54, 0x48, 0x44, 0x00,
|
||||||
// OperationRegion(DBG0, SystemIO, Word 0x0402, Byte 1)
|
// OperationRegion(DBG0, SystemIO, Word 0x0402, Byte 1)
|
||||||
0x5B, 0x80, 0x44, 0x42, 0x47, 0x30, 0x01, 0x0B, 0x02, 0x04, 0x0A, 0x01,
|
0x5B, 0x80, 0x44, 0x42, 0x47, 0x30, 0x01, 0x0B,
|
||||||
|
0x02, 0x04, 0x0A, 0x01,
|
||||||
// Field(DBG0, flags=1) { DBGB, 8 }, packagelen=0x0B
|
// Field(DBG0, flags=1) { DBGB, 8 }, packagelen=0x0B
|
||||||
0x5B, 0x81, 0x0B, 0x44, 0x42, 0x47, 0x30, 0x01, 0x44, 0x42, 0x47, 0x42, 0x08,
|
0x5B, 0x81, 0x0B, 0x44, 0x42, 0x47, 0x30, 0x01,
|
||||||
|
0x44, 0x42, 0x47, 0x42, 0x08,
|
||||||
};
|
};
|
||||||
|
|
||||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||||
|
|||||||
@@ -198,8 +198,7 @@ fn dumpNode(device: *const Device, depth: usize, emit: *const fn ([]const u8) vo
|
|||||||
std.fmt.bufPrint(buffer[indent..], "{s} [{s}] hid={s} ({s})\n", .{ device.name(), @tagName(device.class), device.hid(), desc }) catch return
|
std.fmt.bufPrint(buffer[indent..], "{s} [{s}] hid={s} ({s})\n", .{ device.name(), @tagName(device.class), device.hid(), desc }) catch return
|
||||||
else
|
else
|
||||||
std.fmt.bufPrint(buffer[indent..], "{s} [{s}] hid={s}\n", .{ device.name(), @tagName(device.class), device.hid() }) catch return;
|
std.fmt.bufPrint(buffer[indent..], "{s} [{s}] hid={s}\n", .{ device.name(), @tagName(device.class), device.hid() }) catch return;
|
||||||
} else
|
} else std.fmt.bufPrint(buffer[indent..], "{s} [{s}]\n", .{ device.name(), @tagName(device.class) }) catch return;
|
||||||
std.fmt.bufPrint(buffer[indent..], "{s} [{s}]\n", .{ device.name(), @tagName(device.class) }) catch return;
|
|
||||||
emit(buffer[0 .. indent + body.len]);
|
emit(buffer[0 .. indent + body.len]);
|
||||||
|
|
||||||
// For a PCI function, decode its class code — the (class / subclass / prog-IF)
|
// For a PCI function, decode its class code — the (class / subclass / prog-IF)
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ pub fn main() void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller.performSelfTest()) | reply | {
|
if (controller.performSelfTest()) |reply| {
|
||||||
if (reply != ps2.response_controller_test_passed) {
|
if (reply != ps2.response_controller_test_passed) {
|
||||||
_ = runtime.system.write("system/drivers/ps2-bus: perform controller self test failed\n");
|
_ = runtime.system.write("system/drivers/ps2-bus: perform controller self test failed\n");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -481,4 +481,4 @@ pub const Controller = struct {
|
|||||||
_ = self.sendToDevice(port, device_cmd_enable_scanning);
|
_ = self.sendToDevice(port, device_cmd_enable_scanning);
|
||||||
return device_type;
|
return device_type;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -490,8 +490,7 @@ pub fn saveInterrupts() u64 {
|
|||||||
\\cli
|
\\cli
|
||||||
: [f] "=r" (flags),
|
: [f] "=r" (flags),
|
||||||
:
|
:
|
||||||
: .{ .memory = true }
|
: .{ .memory = true });
|
||||||
);
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,22 +78,22 @@ fn defaultFault(_: *const CpuState) noreturn {
|
|||||||
|
|
||||||
/// Names for the 32 defined exception vectors, for readable output.
|
/// Names for the 32 defined exception vectors, for readable output.
|
||||||
const names = [_][]const u8{
|
const names = [_][]const u8{
|
||||||
"divide error", "debug",
|
"divide error", "debug",
|
||||||
"NMI", "breakpoint",
|
"NMI", "breakpoint",
|
||||||
"overflow", "bound range exceeded",
|
"overflow", "bound range exceeded",
|
||||||
"invalid opcode", "device not available",
|
"invalid opcode", "device not available",
|
||||||
"double fault", "coprocessor segment overrun",
|
"double fault", "coprocessor segment overrun",
|
||||||
"invalid TSS", "segment not present",
|
"invalid TSS", "segment not present",
|
||||||
"stack-segment fault", "general protection fault",
|
"stack-segment fault", "general protection fault",
|
||||||
"page fault", "reserved (15)",
|
"page fault", "reserved (15)",
|
||||||
"x87 floating-point", "alignment check",
|
"x87 floating-point", "alignment check",
|
||||||
"machine check", "SIMD floating-point",
|
"machine check", "SIMD floating-point",
|
||||||
"virtualization", "control protection",
|
"virtualization", "control protection",
|
||||||
"reserved (22)", "reserved (23)",
|
"reserved (22)", "reserved (23)",
|
||||||
"reserved (24)", "reserved (25)",
|
"reserved (24)", "reserved (25)",
|
||||||
"reserved (26)", "reserved (27)",
|
"reserved (26)", "reserved (27)",
|
||||||
"hypervisor injection", "VMM communication",
|
"hypervisor injection", "VMM communication",
|
||||||
"security exception", "reserved (31)",
|
"security exception", "reserved (31)",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn vectorName(vector: u64) []const u8 {
|
pub fn vectorName(vector: u64) []const u8 {
|
||||||
|
|||||||
@@ -166,8 +166,7 @@ pub fn init(allocFrame: *const fn () ?u64, freeFrame: *const fn (u64) void, boot
|
|||||||
asm volatile ("mov %[pml4], %%cr3"
|
asm volatile ("mov %[pml4], %%cr3"
|
||||||
:
|
:
|
||||||
: [pml4] "r" (pml4),
|
: [pml4] "r" (pml4),
|
||||||
: .{ .memory = true }
|
: .{ .memory = true });
|
||||||
);
|
|
||||||
on_own_tables = true; // now on the kernel's physmap (covers all RAM)
|
on_own_tables = true; // now on the kernel's physmap (covers all RAM)
|
||||||
init_done = true; // the kernel half is fixed from here
|
init_done = true; // the kernel half is fixed from here
|
||||||
}
|
}
|
||||||
@@ -409,6 +408,5 @@ fn invalidate(virtual: u64) void {
|
|||||||
\\invlpg (%%rax)
|
\\invlpg (%%rax)
|
||||||
:
|
:
|
||||||
: [v] "r" (virtual),
|
: [v] "r" (virtual),
|
||||||
: .{ .rax = true, .memory = true }
|
: .{ .rax = true, .memory = true });
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,5 +154,3 @@ pub const Console = struct {
|
|||||||
while (x < self.fb.width) : (x += 1) destination[x] = source[x];
|
while (x < self.fb.width) : (x += 1) destination[x] = source[x];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ fn kmain(boot_information: *const BootInformation) noreturn {
|
|||||||
log.print(" pitch : {d} bytes\n", .{fb.pitch});
|
log.print(" pitch : {d} bytes\n", .{fb.pitch});
|
||||||
log.print(" format : {s}\n", .{@tagName(fb.format)});
|
log.print(" format : {s}\n", .{@tagName(fb.format)});
|
||||||
log.print(" framebuffer: 0x{x:0>16}\n", .{fb.base});
|
log.print(" framebuffer: 0x{x:0>16}\n", .{fb.base});
|
||||||
log.print (" footprint : {d} MiB\n", .{(fb.pitch * fb.height) / (1024 * 1024)});
|
log.print(" footprint : {d} MiB\n", .{(fb.pitch * fb.height) / (1024 * 1024)});
|
||||||
|
|
||||||
// Summarise the physical memory the loader handed us. The array is danos's
|
// Summarise the physical memory the loader handed us. The array is danos's
|
||||||
// own MemoryRegion, so this is a plain slice — no firmware layout in sight.
|
// own MemoryRegion, so this is a plain slice — no firmware layout in sight.
|
||||||
|
|||||||
@@ -1082,4 +1082,4 @@ pub fn spawnProcessSupervised(image: []const u8, priority: u3, argv: []const []c
|
|||||||
/// a spin count, and time short delays.
|
/// a spin count, and time short delays.
|
||||||
fn systemClock(state: *architecture.CpuState) void {
|
fn systemClock(state: *architecture.CpuState) void {
|
||||||
architecture.setSystemCallResult(state, architecture.nanos());
|
architecture.setSystemCallResult(state, architecture.nanos());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2023,7 +2023,10 @@ fn faultNull() void {
|
|||||||
// access). `allowzero` skips the same null check on the cast. The write then
|
// access). `allowzero` skips the same null check on the cast. The write then
|
||||||
// hits the unmapped page 0 and takes a real hardware #PF.
|
// hits the unmapped page 0 and takes a real hardware #PF.
|
||||||
var address: u64 = 0;
|
var address: u64 = 0;
|
||||||
address = asm ("" : [ret] "=r" (-> u64) : [in] "0" (address));
|
address = asm (""
|
||||||
|
: [ret] "=r" (-> u64),
|
||||||
|
: [in] "0" (address),
|
||||||
|
);
|
||||||
const p: *allowzero volatile u64 = @ptrFromInt(address);
|
const p: *allowzero volatile u64 = @ptrFromInt(address);
|
||||||
p.* = 1;
|
p.* = 1;
|
||||||
}
|
}
|
||||||
@@ -2049,8 +2052,7 @@ fn faultDoubleFault() void {
|
|||||||
\\ud2
|
\\ud2
|
||||||
:
|
:
|
||||||
: [sp] "r" (bad_sp),
|
: [sp] "r" (bad_sp),
|
||||||
: .{ .memory = true }
|
: .{ .memory = true });
|
||||||
);
|
|
||||||
bad_sp += 0;
|
bad_sp += 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2069,8 +2071,7 @@ fn apDoubleFaultTask() void {
|
|||||||
\\ud2
|
\\ud2
|
||||||
:
|
:
|
||||||
: [sp] "r" (bad_sp),
|
: [sp] "r" (bad_sp),
|
||||||
: .{ .memory = true }
|
: .{ .memory = true });
|
||||||
);
|
|
||||||
bad_sp += 0;
|
bad_sp += 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ fn driverFor(d: device.DeviceDescriptor) ?[]const u8 {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn main() void {
|
pub fn main() void {
|
||||||
// Enumerate into a heap buffer (too big for the one-page user stack).
|
// Enumerate into a heap buffer (too big for the one-page user stack).
|
||||||
const buffer = runtime.allocator().alloc(device.DeviceDescriptor, 64) catch {
|
const buffer = runtime.allocator().alloc(device.DeviceDescriptor, 64) catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user