Update to Zig 0.15.2

This commit is contained in:
ktkk 2025-11-07 10:29:21 +00:00
parent dc6f7e486f
commit a5c560d2b9
4 changed files with 64 additions and 33 deletions

View file

@ -22,10 +22,12 @@ pub fn build(b: *std.Build) !void {
const kernel = b.addExecutable(.{
.name = "kernel.elf",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = .ReleaseFast,
.code_model = .kernel,
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = .ReleaseFast,
.code_model = .kernel,
}),
});
kernel.setLinkerScript(b.path("kernel.ld"));

6
flake.lock generated
View file

@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1742669843,
"narHash": "sha256-G5n+FOXLXcRx+3hCJ6Rt6ZQyF1zqQ0DL0sWAMn2Nk0w=",
"lastModified": 1762363567,
"narHash": "sha256-YRqMDEtSMbitIMj+JLpheSz0pwEr0Rmy5mC7myl17xs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1e5b653dff12029333a6546c11e108ede13052eb",
"rev": "ae814fd3904b621d8ab97418f1d0f2eb0d3716f4",
"type": "github"
},
"original": {

View file

@ -20,18 +20,18 @@ pub const ConsoleColor = enum(u8) {
red = 4,
magenta = 5,
brown = 6,
lightGray = 7,
darkGray = 8,
lightBlue = 9,
lightGreen = 10,
lightCyan = 11,
lightRed = 12,
lightMagenta = 13,
lightBrown = 14,
light_gray = 7,
dark_gray = 8,
light_blue = 9,
light_green = 10,
light_cyan = 11,
light_red = 12,
light_magenta = 13,
light_brown = 14,
white = 15,
};
const default_color = vgaEntryColor(ConsoleColor.lightGray, ConsoleColor.black);
const default_color = vgaEntryColor(ConsoleColor.light_gray, ConsoleColor.black);
column: usize = 0,
color: u8 = default_color,
@ -115,21 +115,49 @@ pub fn puts(self: *Self, data: []const u8) void {
}
}
const Writer = std.io.Writer(
*Self,
error{},
callback,
);
const Writer = struct {
console: *Self,
interface: std.Io.Writer,
pub fn writer(self: *Self) Writer {
return .{ .context = self };
}
fn drain(io_w: *std.Io.Writer, data: []const []const u8, splat: usize) std.Io.Writer.Error!usize {
const self: *@This() = @fieldParentPtr("interface", io_w);
fn callback(self: *Self, string: []const u8) error{}!usize {
self.puts(string);
return string.len;
try self.puts(io_w.buffered());
io_w.end = 0;
for (data[0..data.len - 1]) |bytes| {
try self.puts(bytes);
}
const pattern = data[data.len - 1];
for (0..splat) |_| {
try self.puts(pattern);
}
return std.Io.Writer.countSplat(data, splat);
}
fn puts(self: *@This(), data: []const u8) std.Io.Writer.Error!void {
self.console.puts(data);
}
};
pub fn writer(self: *Self, buffer: []u8) Writer {
return .{
.console = self,
.interface = .{
.buffer = buffer,
.vtable = &.{
.drain = Writer.drain,
},
},
};
}
pub fn printf(self: *Self, comptime format: []const u8, args: anytype) void {
std.fmt.format(self.writer(), format, args) catch unreachable;
var buffer: [1024]u8 = undefined;
var w = self.writer(&buffer);
const io_w = &w.interface;
io_w.print(format, args) catch unreachable;
io_w.flush() catch unreachable;
}

View file

@ -20,7 +20,7 @@ export var mutliboot: MultibootHeader align(4) linksection(".multiboot") = .{
var stack_bytes: [16 * 1024]u8 align(16) linksection(".bss") = undefined;
export fn _start() callconv(.Naked) noreturn {
export fn _start() callconv(.naked) noreturn {
asm volatile (
\\ movl %[stack_top], %%esp
\\ movl %%esp, %%ebp
@ -68,11 +68,12 @@ fn klog(
const c = console.get();
const color = switch (level) {
.err => Console.ConsoleColor.lightRed,
.warn => Console.ConsoleColor.lightBrown,
.info => Console.ConsoleColor.lightBlue,
.debug => Console.ConsoleColor.lightGreen,
.err => Console.ConsoleColor.light_red,
.warn => Console.ConsoleColor.light_brown,
.info => Console.ConsoleColor.light_blue,
.debug => Console.ConsoleColor.light_green,
};
c.putChar('[');
c.setColor(color, Console.ConsoleColor.black);
c.puts(level.asText());