const std = @import("std"); const uefi = std.os.uefi; const Path = @import("../Config.zig").Path; const luefi = @import("../luefi.zig"); const log = std.log.scoped(.chainload); const Chainload = @This(); img_buffer: []align(4096) u8, img_pages: usize, pub fn load(path: Path) !Chainload { const buffer, const pages = try luefi.pathReadAlloc(path); errdefer luefi.freePages(buffer, pages); return .{ .img_buffer = buffer, .img_pages = pages, }; } pub fn deinit(self: Chainload) void { luefi.freePages(self.img_buffer, self.img_pages); } pub fn start(self: Chainload) !uefi.Status { const boot_svc = uefi.system_table.boot_services.?; const handle, _ = try luefi.loadImage(self.img_buffer); defer luefi.unloadImage(handle); const exit_data = try boot_svc.startImage(handle); return exit_data.code; }