Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn build(b: *std.Build) void {
b.getInstallStep().dependOn(&install_elf.step);

// Flat image for `-bios`.
const bin = exe.addObjCopy(.{ .format = .bin });
const bin = exe.addObjCopy(.{ .format = .binary });
const install_bin = b.addInstallBinFile(bin.getOutput(), "weir-firmware.bin");
b.getInstallStep().dependOn(&install_bin.step);

Expand Down Expand Up @@ -239,7 +239,7 @@ pub fn build(b: *std.Build) void {
"-bios",
});
run.addFileArg(bin.getOutput());
if (b.args) |args| run.addArgs(args);
run.addPassthruArgs();
const qemu_step = b.step("qemu", "Boot Weir under qemu-system-riscv64 -machine virt");
qemu_step.dependOn(&run.step);

Expand Down Expand Up @@ -281,7 +281,7 @@ pub fn build(b: *std.Build) void {
fexe.entry = .{ .symbol_name = "_start" };
fexe.setLinkerScript(genLd(b, ld_gen, dtb_path, "fsbl", null));

const fbin = fexe.addObjCopy(.{ .format = .bin });
const fbin = fexe.addObjCopy(.{ .format = .binary });
const finstall = b.addInstallBinFile(fbin.getOutput(), "weir-fsbl.bin");

b.getInstallStep().dependOn(&finstall.step);
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
.minimum_zig_version = "0.16.0",
.dependencies = .{
.conduit = .{
.url = "git+https://git.lilithsemi.com/LilithSemi/conduit.git#cb9b7130b72b71001cb4347e11b0b383c0fbcdc4",
.hash = "conduit-0.1.0-R_mFrINUBQDxhZBhJcDJ9Jxw0Wsxo3iTZl6rKdR-o7QF",
.url = "git+https://git.lilithsemi.com/LilithSemi/conduit#ee4577536650baccafef031bfd6805df2a396f3f",
.hash = "conduit-0.1.0-R_mFrINSBQDBumznUsVwExYHXxmSKd_o7ensGtl0UwEI",
},
.dtree = .{
.url = "git+https://git.lilithsemi.com/LilithSemi/dtree.git#1a37e566bb82194acfd7d7d5514615fe4fe13c68",
.hash = "dtree-0.1.0-76to8Fy8AADLnQuIRRFtYugky-X4UAtcO74DyS_9Tmp3",
.url = "git+https://git.lilithsemi.com/LilithSemi/dtree#63fe0a7292ca2df829bc3d66d86291416c657cd7",
.hash = "dtree-0.1.0-76to8F7kAAD-G7jPybrgZuWwvRQV8SmMXQilS86JCIpA",
},
},
.paths = .{""},
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@

treefmt.programs = {
nixfmt.enable = true;
zig.enable = true;
zig = {
enable = true;
package = pkgs.zig_0_17;
};
};

overlayAttrs = {
Expand Down
10 changes: 5 additions & 5 deletions pkgs/weir/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
lib,
stdenv,
mkShell,
zig,
zig_0_17,
qemu,
flakever,
}:
Expand All @@ -12,13 +12,13 @@ stdenv.mkDerivation (finalAttrs: {

src = lib.cleanSource ../../.;

zigDeps = zig.fetchDeps {
zigDeps = zig_0_17.fetchDeps {
inherit (finalAttrs) src pname version;
hash = "sha256-YY+Uyg3qUQ4Rdf68/Ur7FkDd6DIBEAJ0IlRKQazNFEk=";
hash = "sha256-lS//HnBMruyFPHLm6AsOViLbwhfV42ABIyF1yNZw8ls=";
};

nativeBuildInputs = [
zig
zig_0_17
];

postConfigure = ''
Expand All @@ -29,7 +29,7 @@ stdenv.mkDerivation (finalAttrs: {
name = "weir-dev-shell";

packages = [
zig
zig_0_17
qemu
];
};
Expand Down
2 changes: 1 addition & 1 deletion src/acpi/acpi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn setup(dsdt: ?[]const u8) void {
/// SPCR body (after the 36-byte SDT header): a full-16550 console at `uart_base`,
/// byte-wide registers, 115200 8N1, polled.
fn spcrBody(uart_base: u64) [44]u8 {
var b = [_]u8{0} ** 44;
var b: [44]u8 = @splat(0);
b[0] = 0x00; // interface type: full 16550
b[4] = 0x00; // base address GAS: system memory
b[5] = 8; // register bit width
Expand Down
2 changes: 1 addition & 1 deletion src/acpi/qemu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var pool_next: usize = POOL_BASE;
var rsdp_addr: usize = 0;

const Blob = struct {
name: [56]u8 = [_]u8{0} ** 56,
name: [56]u8 = @splat(0),
name_len: usize = 0,
buf: []u8 = &.{},
};
Expand Down
2 changes: 1 addition & 1 deletion src/block/block.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub const Partition = struct {
/// 1-based partition number and the GPT unique partition GUID, used to build
/// the Hard Drive device path node so a bootloader can match its boot volume.
number: u32 = 1,
signature: [16]u8 = .{0} ** 16,
signature: [16]u8 = @splat(0),

pub fn blockSize(self: *const Partition) u32 {
return self.dev.block_size;
Expand Down
2 changes: 1 addition & 1 deletion src/boot/manager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn tryDevice(sd: storage.Device, i: usize, buf: []u8) ?pe.Loaded {
// boot media (controller kind + MMIO base), so the ESP handle carries a
// distinct path a bootloader can match, then publish the ESP via Simple File
// System so the loaded bootloader reads its config, kernel, and initrd.
blockio.setBootMedia(@intFromEnum(sd.kind), sd.base);
blockio.setBootMedia(@backingInt(sd.kind), sd.base);
if (handledb.create()) |h| {
if (simplefs.install(h, part))
console.out.writeAll("[boot] ESP published via Simple File System\n") catch {};
Expand Down
2 changes: 1 addition & 1 deletion src/fs/fat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ fn readChain(s: *State, start_cluster: u32, size: u32, buf: []u8) ?usize {
pub const Loc = struct { root16: bool, cluster: u32 };

pub const DirEnt = struct {
name: [256]u16 = [_]u16{0} ** 256, // UTF-16, null-terminated
name: [256]u16 = @splat(0), // UTF-16, null-terminated
name_units: usize = 0, // including the null
cluster: u32 = 0,
size: u32 = 0,
Expand Down
12 changes: 6 additions & 6 deletions src/fsbl/ddr_train.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub const KnobFeedback = enum {

/// One tunable PHY delay, taken from a `knob@N` node in the device tree.
pub const Knob = struct {
name_buf: [NAME_CAP]u8 = [_]u8{0} ** NAME_CAP,
name_buf: [NAME_CAP]u8 = @splat(0),
name_len: usize = 0,
/// Register byte offset inside the window.
reg: u32 = 0,
Expand All @@ -103,7 +103,7 @@ pub const TrainDesc = struct {
train_base: u64 = 0,
stride: u32 = 8,
lanes: u32 = 0,
knobs: [MAX_KNOBS]Knob = [_]Knob{.{}} ** MAX_KNOBS,
knobs: [MAX_KNOBS]Knob = @splat(.{}),
knob_count: usize = 0,
rows: u32 = 0,
cols: u32 = 0,
Expand Down Expand Up @@ -396,7 +396,7 @@ fn widestCenter(pass: []const bool, min: u32, max: u32) SweepResult {
/// so the engine can set any tap directly. Return the centre of the widest passing
/// window.
fn sweepAbsolute(a: SweepArgs) SweepResult {
var pass = [_]bool{false} ** 33; // taps 0..31 plus a guard slot
var pass: [33]bool = @splat(false); // taps 0..31 plus a guard slot
const mask = sliceMask(a.d, a.knob, a.slice);
var tap = a.knob.min;
var pass_count: u32 = 0;
Expand All @@ -423,7 +423,7 @@ fn advanceOne(d: *const TrainDesc, knob: *const Knob, lane: u32) void {
/// absolute count, so the engine steps it forward and checks each count. The count
/// range wraps at max+1. The sweep assumes the level starts at 0.
fn sweepAdvance(a: SweepArgs) SweepResult {
var pass = [_]bool{false} ** 9; // counts 0..7 plus a guard slot
var pass: [9]bool = @splat(false); // counts 0..7 plus a guard slot
const mask = sliceMask(a.d, a.knob, a.slice);
const span = a.knob.max + 1; // the wrap period, e.g. 8 for a 3-bit slip
var pass_count: u32 = 0;
Expand Down Expand Up @@ -585,7 +585,7 @@ test "parseTrainingNode reads the creek runtime training node" {

test "widestCenter picks the centre of the widest run" {
// Two runs: 1..2 (width 2) and 5..8 (width 4). The wider run wins.
var pass = [_]bool{false} ** 33;
var pass: [33]bool = @splat(false);
pass[1] = true;
pass[2] = true;
pass[5] = true;
Expand All @@ -598,7 +598,7 @@ test "widestCenter picks the centre of the widest run" {
}

test "widestCenter reports no window when nothing passes" {
const pass = [_]bool{false} ** 33;
const pass: [33]bool = @splat(false);
const res = widestCenter(pass[0..], 0, 31);
try std.testing.expect(!res.found);
}
Expand Down
6 changes: 3 additions & 3 deletions src/loader/pe.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn sizeOf(image: []const u8) Error!usize {
var pe = coff.Coff.init(image, false) catch return error.BadPe;
if (!pe.is_image) return error.NotImage;
if (pe.getHeader().machine != .RISCV64) return error.NotRiscv64;
if (@intFromEnum(pe.getOptionalHeader().magic) != coff.IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
if (@backingInt(pe.getOptionalHeader().magic) != coff.IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
return error.NotPe32Plus;
}
return pe.getOptionalHeader64().size_of_image;
Expand All @@ -56,7 +56,7 @@ pub fn loadAt(image: []const u8, load_base: usize, max_image: usize) Error!Loade
if (!pe.is_image) return error.NotImage;

if (pe.getHeader().machine != .RISCV64) return error.NotRiscv64;
if (@intFromEnum(pe.getOptionalHeader().magic) != coff.IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
if (@backingInt(pe.getOptionalHeader().magic) != coff.IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
return error.NotPe32Plus;
}

Expand Down Expand Up @@ -155,7 +155,7 @@ fn relocate(
if (delta == 0) return; // loaded at its preferred base, nothing to fix up

const dirs = pe.getDataDirectories();
const idx = @intFromEnum(coff.IMAGE.DIRECTORY_ENTRY.BASERELOC);
const idx = @backingInt(coff.IMAGE.DIRECTORY_ENTRY.BASERELOC);
if (idx >= dirs.len) return;
const reloc = dirs[idx];
// No relocation table: the image is position-independent and relocates
Expand Down
2 changes: 1 addition & 1 deletion src/sbi/ipi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub const SOFT: u32 = 1 << 0; // relay to S-mode as SSIP
pub const FENCE_I: u32 = 1 << 1; // execute FENCE.I locally
pub const SFENCE_VMA: u32 = 1 << 2; // execute SFENCE.VMA locally (full flush)

var pending: [MAX_HARTS]u32 = [_]u32{0} ** MAX_HARTS;
var pending: [MAX_HARTS]u32 = @splat(0);

/// Queue `ops` on `target` and signal it. Fire-and-forget (used for SOFT relays).
pub fn send(target: usize, ops: u32) void {
Expand Down
14 changes: 7 additions & 7 deletions src/tpm/tcg2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const tpm2 = @import("tpm2.zig");
const handledb = @import("../uefi/handledb.zig");

const Status = uefi.Status;
const ok = @intFromEnum(Status.success);
const ok = @backingInt(Status.success);

// EFI_TCG2_PROTOCOL_GUID 607f766c-7455-42be-930b-e4d76db2720f.
pub const TCG2_GUID = uefi.Guid{
Expand Down Expand Up @@ -74,7 +74,7 @@ fn getEventLog(
last_entry: *u64,
truncated: *bool,
) callconv(.c) usize {
if (format != EVENT_LOG_FORMAT_TCG_2) return @intFromEnum(Status.invalid_parameter);
if (format != EVENT_LOG_FORMAT_TCG_2) return @backingInt(Status.invalid_parameter);
log_loc.* = tpm.eventLogStart();
last_entry.* = tpm.eventLogLastEntry();
truncated.* = tpm.logTruncated();
Expand All @@ -93,9 +93,9 @@ fn hashLogExtendEvent(
data_len: u64,
event: [*]u8,
) callconv(.c) usize {
if (!tpm.isAvailable()) return @intFromEnum(Status.device_error);
if (!tpm.isAvailable()) return @backingInt(Status.device_error);
const size = std.mem.readInt(u32, event[0..4], .little);
if (size < 18) return @intFromEnum(Status.invalid_parameter);
if (size < 18) return @backingInt(Status.invalid_parameter);
const pcr = std.mem.readInt(u32, event[10..14], .little);
const event_type = std.mem.readInt(u32, event[14..18], .little);
const event_data = event[18..size];
Expand All @@ -107,9 +107,9 @@ fn hashLogExtendEvent(
const want_log = flags & HLEE_EXTEND_ONLY == 0;
if (want_log) {
if (!tpm.logExtend(pcr, event_type, &digest, event_data))
return @intFromEnum(Status.device_error);
return @backingInt(Status.device_error);
} else {
if (!tpm.extendOnly(pcr, &digest)) return @intFromEnum(Status.device_error);
if (!tpm.extendOnly(pcr, &digest)) return @backingInt(Status.device_error);
}
return ok;
}
Expand All @@ -122,7 +122,7 @@ fn submitCommand(
out_block: [*]u8,
) callconv(.c) usize {
if (tpm2.submit(in_block[0..in_size], out_block[0..out_size]) == null)
return @intFromEnum(Status.device_error);
return @backingInt(Status.device_error);
return ok;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tpm/tpm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn initLog() void {
log_truncated = false;
logU32(0); // pcrIndex
logU32(EV_NO_ACTION); // eventType
logBytes(&[_]u8{0} ** 20); // SHA1 digest field (zero)
logBytes(&@as([20]u8, @splat(0))); // SHA1 digest field (zero)
// eventSize + TCG_EfiSpecIdEvent
const spec_size: u32 = 16 + 4 + 4 + 4 + (2 + 2) + 1; // sig+class+ver+count+1 alg+vendorlen
logU32(spec_size);
Expand Down
12 changes: 6 additions & 6 deletions src/uefi/blockio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const blk = @import("../virtio/blk.zig");
const handledb = @import("handledb.zig");

const Status = uefi.Status;
const ok = @intFromEnum(Status.success);
const ok = @backingInt(Status.success);
const BlockIo = uefi.protocol.BlockIo;
const Media = BlockIo.BlockMedia;

Expand Down Expand Up @@ -74,9 +74,9 @@ fn readBlocks(
) callconv(.c) usize {
_ = self;
_ = media_id;
if (buffer_size % dev.block_size != 0) return @intFromEnum(Status.bad_buffer_size);
if (buffer_size % dev.block_size != 0) return @backingInt(Status.bad_buffer_size);
const count: u32 = @intCast(buffer_size / dev.block_size);
if (!dev.readBlocks(lba, count, buf[0..buffer_size])) return @intFromEnum(Status.device_error);
if (!dev.readBlocks(lba, count, buf[0..buffer_size])) return @backingInt(Status.device_error);
return ok;
}

Expand All @@ -92,7 +92,7 @@ fn writeBlocks(
_ = lba;
_ = buffer_size;
_ = buf;
return @intFromEnum(Status.write_protected);
return @backingInt(Status.write_protected);
}

fn flushBlocks(self: *BlockIo) callconv(.c) usize {
Expand Down Expand Up @@ -161,10 +161,10 @@ fn partRead(
_ = self;
_ = media_id;
const bs = part_dev.dev.block_size;
if (buffer_size % bs != 0) return @intFromEnum(Status.bad_buffer_size);
if (buffer_size % bs != 0) return @backingInt(Status.bad_buffer_size);
const count: u32 = @intCast(buffer_size / bs);
if (!part_dev.readBlocks(lba, count, buf[0..buffer_size])) {
return @intFromEnum(Status.device_error);
return @backingInt(Status.device_error);
}
return ok;
}
Expand Down
Loading
Loading