λ

lumine

UEFI x86_64 bootloader for linux kernel images

settings

src/boot/linux/Kernel.zig

891 bytes raw

const std = @import("std");
const uefi = std.os.uefi;
const log = std.log;

const Chainload = @import("../Chainload.zig");

const luefi = @import("../../luefi.zig");
const Path = @import("../../Config.zig").Path;

const Kernel = @This();

chainload: Chainload,

pub fn load(path: Path) !Kernel {
    log.info("loading kernel {f}", .{path});
    return .{ .chainload = try .load(path) };
}

pub fn deinit(self: Kernel) void {
    self.chainload.deinit();
}

pub fn start(self: Kernel, cmdline: []const u8) !uefi.Status {
    const allocator = uefi.pool_allocator;

    const cmdline_utf16 = try std.unicode.utf8ToUtf16LeAllocZ(allocator, cmdline);
    defer allocator.free(cmdline_utf16);

    self.chainload.img_loaded.load_options = @ptrCast(cmdline_utf16);
    self.chainload.img_loaded.load_options_size = @intCast(cmdline_utf16.len * @sizeOf(u16));

    return self.chainload.start();
}