lumine
UEFI x86_64 bootloader for linux kernel images
src/boot/Chainload.zig
864 bytes raw
1const std = @import("std");
2const uefi = std.os.uefi;
3
4const Path = @import("../Config.zig").Path;
5const luefi = @import("../luefi.zig");
6
7const log = std.log.scoped(.chainload);
8
9const Chainload = @This();
10
11img_buffer: []align(4096) u8,
12img_pages: usize,
13
14pub fn load(path: Path) !Chainload {
15 const buffer, const pages = try luefi.pathReadAlloc(path);
16 errdefer luefi.freePages(buffer, pages);
17
18 return .{
19 .img_buffer = buffer,
20 .img_pages = pages,
21 };
22}
23
24pub fn deinit(self: Chainload) void {
25 luefi.freePages(self.img_buffer, self.img_pages);
26}
27
28pub fn start(self: Chainload) !uefi.Status {
29 const boot_svc = uefi.system_table.boot_services.?;
30
31 const handle, _ = try luefi.loadImage(self.img_buffer);
32 defer luefi.unloadImage(handle);
33
34 const exit_data = try boot_svc.startImage(handle);
35 return exit_data.code;
36}