diff --git a/build.zig.zon b/build.zig.zon index 829660b..d3fbdce 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -13,8 +13,8 @@ .hash = "N-V-__8AAAAAjAwsopZIlbp4U6NN1Eh573uVdLTwl1mkFUug", }, .zonfig = .{ - .url = "git+https://github.com/rdmsr/zonfig?ref=HEAD#ee612592ba79d99da3ddf715ffec1414f72609ca", - .hash = "zonfig-0.1.0-V0D8-WQ4AQAW5RNFJPxDNIpI7KB7eGPx0MlzGDM6HFbK", + .url = "git+https://github.com/rdmsr/zonfig?ref=HEAD#7cb4e030077acbef88458aef2d3fec4331b3b6da", + .hash = "zonfig-0.1.0-V0D8-aRMFAAQ3Yb-0u8JNpdceK6lUOWUP7EY5BRXz12C", }, }, diff --git a/build/image.zig b/build/image.zig index c3dbc0b..8586803 100644 --- a/build/image.zig +++ b/build/image.zig @@ -3,7 +3,7 @@ const std = @import("std"); const Arch = std.Target.Cpu.Arch; fn addLimineTool(b: *std.Build, limine: *std.Build.Dependency) *std.Build.Step.Compile { - const tool = b.addExecutable(.{ .name = "limine", .root_module = b.addModule("limine", .{ + const tool = b.addExecutable(.{ .name = "limine", .root_module = b.createModule(.{ .target = b.graph.host, .link_libc = true, }) }); diff --git a/src/arch/amd64/root.zig b/src/arch/amd64/root.zig index 510b6eb..29d9283 100644 --- a/src/arch/amd64/root.zig +++ b/src/arch/amd64/root.zig @@ -711,8 +711,10 @@ pub const Idtr = extern struct { pub fn sidtr() Idtr { var idtr: Idtr = undefined; - asm volatile ("sidt %[idtr]" - : [idtr] "={memory}" (idtr), + + asm volatile ("sidt %[p]" + : + : [p] "*p" (&idtr.limit), ); return idtr; } diff --git a/src/kern/tunable.zig b/src/kern/tunable.zig index a65a903..4695f06 100644 --- a/src/kern/tunable.zig +++ b/src/kern/tunable.zig @@ -71,10 +71,10 @@ fn apply_num( const sign = @typeInfo(ValueT).int.signedness; _ = switch (info.bits) { - 8 => store_int(std.meta.Int(sign, 8), entry.address, value), - 16 => store_int(std.meta.Int(sign, 16), entry.address, value), - 32 => store_int(std.meta.Int(sign, 32), entry.address, value), - 64 => store_int(std.meta.Int(sign, 64), entry.address, value), + 8 => store_int(@Int(sign, 8), entry.address, value), + 16 => store_int(@Int(sign, 16), entry.address, value), + 32 => store_int(@Int(sign, 32), entry.address, value), + 64 => store_int(@Int(sign, 64), entry.address, value), else => unreachable, }; } diff --git a/src/mm/tlb.zig b/src/mm/tlb.zig index c1e8f40..7379b10 100644 --- a/src/mm/tlb.zig +++ b/src/mm/tlb.zig @@ -23,7 +23,7 @@ fn reclaim_state(obj: *anyopaque, _: ?*anyopaque) void { const state: *ke.ShootdownState = @fieldParentPtr("link", link); const space: *mm.Space = @ptrFromInt(state.payload[0]); - const pfn_list: mmp.PfnList = @bitCast(state.payload[1]); + const pfn_list: *mmp.PfnList = @ptrCast(&state.payload[1]); const base = state.base; const npages = state.npages; @@ -70,7 +70,7 @@ pub fn reclaim_range(space: *mm.Space, va: r.VAddr, size: usize) void { .state = .init(0), .payload = .{ @intFromPtr(space), - @bitCast(list), + @as(*const usize, @ptrCast(@alignCast(&list))).*, }, }; diff --git a/src/rtl/root.zig b/src/rtl/root.zig index a40f86f..fb9f848 100644 --- a/src/rtl/root.zig +++ b/src/rtl/root.zig @@ -18,30 +18,60 @@ pub const HandoffList = @import("handoff.zig").HandoffList; pub const LinkerSet = @import("linker_set.zig").LinkerSet; pub const CachePadded = @import("cache_padded.zig").CachePadded; +pub fn comptime_error(comptime msg: []const u8, args: anytype) void { + @compileError(std.fmt.comptimePrint(msg, args)); +} + /// Asserts that a given type `T` matches the schema declared by `I`. /// This includes public methods and fields. pub fn assert_interface(T: type, I: type) void { const tinfo = @typeInfo(I); - inline for (tinfo.@"struct".fields) |f| { - if (!@hasField(T, f.name)) { - @compileError(std.fmt.comptimePrint("Expected field '{s}' of type '{s}' in type '{s}' required by '{s}'", .{ f.name, @typeName(f.type), @typeName(T), @typeName(I) })); + const info = tinfo.@"struct"; + + inline for (info.field_names, info.field_types) |name, t| { + if (!@hasField(T, name)) { + comptime_error( + "Expected field '{s}' of type '{s}' in type '{s}' required by '{s}'", + .{ + name, + @typeName(t), + @typeName(T), + @typeName(I), + }, + ); } else { - if (@FieldType(T, f.name) != f.type) { - @compileError(std.fmt.comptimePrint("Expected field '{s}' of type '{s}' in type '{s}' required by '{s}', got '{s}'", .{ f.name, @typeName(f.type), @typeName(T), @typeName(I), @typeName(@FieldType(T, f.name)) })); + if (@FieldType(T, name) != t) { + comptime_error( + "Expected field '{s}' of type '{s}' in type '{s}' required by '{s}', got '{s}'", + .{ + name, + @typeName(t), + @typeName(T), + @typeName(I), + @typeName(@FieldType(T, name)), + }, + ); } } } - inline for (tinfo.@"struct".decls) |decl| { - const member = @field(I, decl.name); + inline for (tinfo.@"struct".decl_names) |decl| { + const member = @field(I, decl); if (@typeInfo(@TypeOf(member)) == .@"fn") { - if (!@hasDecl(T, decl.name)) { - @compileError(std.fmt.comptimePrint("Expected method '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); + if (!@hasDecl(T, decl)) { + comptime_error( + "Expected method '{s}' in type '{s}' required by '{s}'", + .{ + decl, + @typeName(T), + @typeName(I), + }, + ); } - const impl_member = @field(T, decl.name); + const impl_member = @field(T, decl); const IfaceFnType = @TypeOf(member); const ImplFnType = @TypeOf(impl_member); @@ -49,36 +79,88 @@ pub fn assert_interface(T: type, I: type) void { const iface_fn = @typeInfo(IfaceFnType).@"fn"; const impl_fn = @typeInfo(ImplFnType).@"fn"; - if (iface_fn.params.len != impl_fn.params.len) { - @compileError(std.fmt.comptimePrint("Parameter count mismatch in method '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); + if (iface_fn.param_types.len != impl_fn.param_types.len) { + comptime_error( + "Parameter count mismatch in method '{s}' in type '{s}' required by '{s}'", + .{ + decl, + @typeName(T), + @typeName(I), + }, + ); } if (iface_fn.return_type != impl_fn.return_type) { - @compileError(std.fmt.comptimePrint("Return type mismatch in method '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); + comptime_error( + "Return type mismatch in method '{s}' in type '{s}' required by '{s}'", + .{ + decl, + @typeName(T), + @typeName(I), + }, + ); } - for (0..iface_fn.params.len) |i| { - if (iface_fn.params[i].type != impl_fn.params[i].type) { - @compileError(std.fmt.comptimePrint("Parameter type mismatch in method '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); + for (iface_fn.param_types, impl_fn.param_types) |a, b| { + if (a != b) { + comptime_error( + "Parameter type mismatch in method '{s}' in type '{s}' required by '{s}'", + .{ + decl, + @typeName(T), + @typeName(I), + }, + ); } } } } else if (@TypeOf(member) == type) { - if (!@hasDecl(T, decl.name)) { - @compileError(std.fmt.comptimePrint("Expected type declaration '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); + if (!@hasDecl(T, decl)) { + comptime_error( + "Expected type declaration '{s}' in type '{s}' required by '{s}'", + .{ + decl, + @typeName(T), + @typeName(I), + }, + ); } - const impl_member = @field(T, decl.name); + const impl_member = @field(T, decl); if (@TypeOf(impl_member) != type) { - @compileError(std.fmt.comptimePrint("Declaration '{s}' in type '{s}' is required to be a type by '{s}', but got '{s}'", .{ decl.name, @typeName(T), @typeName(I), @typeName(@TypeOf(impl_member)) })); + comptime_error( + "Declaration '{s}' in type '{s}' is required to be a type by '{s}', but got '{s}'", + .{ + decl, + @typeName(T), + @typeName(I), + @typeName(@TypeOf(impl_member)), + }, + ); } } else { - if (!@hasDecl(T, decl.name)) { - @compileError(std.fmt.comptimePrint("Expected variable declaration '{s}' in type '{s}' required by '{s}'", .{ decl.name, @typeName(T), @typeName(I) })); + if (!@hasDecl(T, decl)) { + comptime_error( + "Expected variable declaration '{s}' in type '{s}' required by '{s}'", + .{ + decl, + @typeName(T), + @typeName(I), + }, + ); } - const impl_member = @field(T, decl.name); + const impl_member = @field(T, decl); if (@TypeOf(impl_member) != @TypeOf(member)) { - @compileError(std.fmt.comptimePrint("Declaration '{s}' in type '{s}' is required to be a variable of type '{s}' by '{s}', but got '{s}'", .{ decl.name, @typeName(T), @typeName(@TypeOf(member)), @typeName(I), @typeName(@TypeOf(impl_member)) })); + comptime_error( + "Declaration '{s}' in type '{s}' is required to be a variable of type '{s}' by '{s}', but got '{s}'", + .{ + decl, + @typeName(T), + @typeName(@TypeOf(member)), + @typeName(I), + @typeName(@TypeOf(impl_member)), + }, + ); } } } @@ -89,9 +171,13 @@ pub fn assert(condition: bool, comptime msg: []const u8, args: anytype) void { @branchHint(.unlikely); switch (@import("builtin").mode) { - .ReleaseFast, .ReleaseSmall => unreachable, - .Debug, .ReleaseSafe => { - std.debug.panicExtra(@returnAddress(), "Assertion failed: " ++ msg, args); + .fast, .small => unreachable, + .debug, .safe => { + std.debug.panicExtra( + @returnAddress(), + "Assertion failed: " ++ msg, + args, + ); }, } }