Skip to content

Commit

Permalink
dainboot: now builds for all 3 targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Jul 15, 2024
1 parent 0bec29f commit fc78497
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 26 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

18 changes: 11 additions & 7 deletions dainboot/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ pub fn build(b: *std.Build) !void {
return;
}

const optimize = b.standardOptimizeOption(.{});

const exe = b.addExecutable(.{
.name = bootName(b, board, resolvedTarget),
.root_source_file = b.path("src/dainboot.zig"),
.target = resolvedTarget,
.optimize = b.standardOptimizeOption(.{}),
.optimize = optimize,
});
try dbuild.addBuildOptions(b, exe, board);
const dtb = b.addModule("dtb", .{
.root_source_file = b.path("../dtb/src/dtb.zig"),
});
const dtb = b.dependency("dtb.zig", .{
.target = resolvedTarget,
.optimize = optimize,
}).module("dtb");
exe.root_module.addImport("dtb", dtb);

b.installArtifact(exe);
Expand All @@ -49,9 +52,10 @@ fn buildRiscv64(b: *std.Build, board: dcommon.Board, resolvedTarget: std.Build.R
});
try dbuild.addBuildOptions(b, obj, board);

const dtb = b.addModule("dtb", .{
.root_source_file = b.path("../dtb/src/dtb.zig"),
});
const dtb = b.dependency("dtb.zig", .{
.target = resolvedTarget,
.optimize = optimize,
}).module("dtb");
obj.root_module.addImport("dtb", dtb);

const combined = b.addSystemCommand(&.{
Expand Down
16 changes: 16 additions & 0 deletions dainboot/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.{
.name = "dainboot",
.version = "0.0.0",
.dependencies = .{
.@"dtb.zig" = .{
.url = "https://github.com/kivikakk/dtb.zig/archive/e5f50cb3dfba304802c899d5a5fec3ad7b66443c.tar.gz",
.hash = "1220c4cf97bc6df21c6b1e21e242058828d2abbdc53f0c1e3b60600ebc18c1e24543",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
"elf_riscv64_efi.lds",
},
}
4 changes: 2 additions & 2 deletions dainboot/src/dainboot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ fn exitBootServices(dainkrnl: []const u8, dtb: []const u8) noreturn {
while (it.next() catch u.haltMsg("iterating phdrs (2)")) |phdr| {
if (phdr.p_type == std.elf.PT_LOAD) {
const target = phdr.p_vaddr - dcommon.daintree_kernel_start + conventional_start;
std.mem.copy(u8, @as([*]u8, @ptrFromInt(target))[0..phdr.p_filesz], dainkrnl[phdr.p_offset .. phdr.p_offset + phdr.p_filesz]);
@memcpy(@as([*]u8, @ptrFromInt(target))[0..phdr.p_filesz], dainkrnl[phdr.p_offset .. phdr.p_offset + phdr.p_filesz]);
if (phdr.p_memsz > phdr.p_filesz) {
std.mem.set(u8, @as([*]u8, @ptrFromInt(target))[phdr.p_filesz..phdr.p_memsz], 0);
@memset(@as([*]u8, @ptrFromInt(target))[phdr.p_filesz..phdr.p_memsz], 0);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions dainboot/src/riscv64.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export fn relocate(ldbase: u64, dyn: [*]elf.Elf64_Dyn) uefi.Status {
// R_RISCV_RELATIVE
const addr: *u64 = @as(*u64, @ptrFromInt(ldbase + relp.r_offset));
if (relp.r_addend > 0) {
addr.* = ldbase + std.math.absCast(relp.r_addend);
addr.* = ldbase + @abs(relp.r_addend);
} else {
addr.* = ldbase - std.math.absCast(relp.r_addend);
addr.* = ldbase - @abs(relp.r_addend);
}
} else {
asm volatile (
Expand All @@ -94,11 +94,11 @@ export fn relocate(ldbase: u64, dyn: [*]elf.Elf64_Dyn) uefi.Status {
// included, and it's adding a PLT and GOT to have them looked up later. They
// aren't being provided by anyone else, so we must.
export fn memset(b: *anyopaque, c: c_int, len: usize) *anyopaque {
std.mem.set(u8, @as([*]u8, @ptrFromInt(b))[0..len], @as(u8, @truncate(std.math.absCast(c))));
@memset(@as([*]u8, @ptrCast(b))[0..len], @as(u8, @truncate(@abs(c))));
return b;
}

export fn memcpy(dst: *anyopaque, src: *const anyopaque, n: usize) *anyopaque {
std.mem.copy(u8, @as([*]u8, @ptrFromInt(dst))[0..n], @as([*]const u8, @ptrFromInt(src))[0..n]);
@memcpy(@as([*]u8, @ptrCast(dst))[0..n], @as([*]const u8, @ptrCast(src))[0..n]);
return dst;
}
2 changes: 1 addition & 1 deletion dainkrnl/src/arm64/entry.zig
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub export fn daintree_mmu_start(entry_data: *dcommon.EntryData) noreturn {
l3.map(i, bump.allocPage(), .table, .kernel_rodata);
}

std.mem.copy(u8, dtb_target, entry_data.dtb_ptr[0..entry_data.dtb_len]);
@memcpy(dtb_target, entry_data.dtb_ptr[0..entry_data.dtb_len]);
}

new_entry.bump_next = bump.next;
Expand Down
8 changes: 4 additions & 4 deletions dainkrnl/src/console/fb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub fn init(in_fb: [*]u32, in_vert: u32, in_horiz: u32) void {
if (console_height * console_width > console_buf.len) {
@panic("can't fit console");
}
std.mem.set(u16, console_buf[0 .. console_width * console_height], 0);
std.mem.set(u32, fb.?[0 .. fb_horiz * fb_vert], 0);
@memset(console_buf[0 .. console_width * console_height], 0);
@memset(fb.?[0 .. fb_horiz * fb_vert], 0);

arch.sleep(500);
drawEnergyStar(false);
Expand Down Expand Up @@ -165,9 +165,9 @@ pub fn print(msg: []const u8) void {
fn scroll() void {
var row: CONSOLE_DIMENSION = 0;
while (row < console_height - 1) : (row += 1) {
std.mem.copy(u16, console_buf[row * console_width .. (row + 1) * console_width], console_buf[(row + 1) * console_width .. (row + 2) * console_width]);
@memcpy(console_buf[row * console_width .. (row + 1) * console_width], console_buf[(row + 1) * console_width .. (row + 2) * console_width]);
}
std.mem.set(u16, console_buf[(console_height - 1) * console_width .. console_height * console_width], 0);
@memset(console_buf[(console_height - 1) * console_width .. console_height * console_width], 0);
refresh();
}

Expand Down
2 changes: 1 addition & 1 deletion dainkrnl/src/paging.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub const BumpAllocator = struct {
self.next += size;
// XXX this only works if physical addresses are mapped, i.e. MMU is off
// or identity mapping is in place
std.mem.set(u8, @intToPtr([*]u8, next)[0..size], 0);
@memset(@intToPtr([*]u8, next)[0..size], 0);
return next;
}

Expand Down
2 changes: 1 addition & 1 deletion dainkrnl/src/riscv64/entry.zig
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub export fn daintree_mmu_start(entry_data: *dcommon.EntryData) noreturn {
l3.map(i, bump.allocPage(), .kernel_rodata);
}

std.mem.copy(u8, dtb_target, entry_data.dtb_ptr[0..entry_data.dtb_len]);
@memcpy(dtb_target, entry_data.dtb_ptr[0..entry_data.dtb_len]);
}

new_entry.bump_next = bump.next;
Expand Down
4 changes: 2 additions & 2 deletions dainkrnl/src/shell.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ pub const Shell = struct {
},
};
if (maybe_rest) |rest| {
std.mem.copy(u8, buf[len..], rest);
@memcpy(buf[len..], rest);
printf("{s}", .{rest});
len += @truncate(u8, rest.len);
}
},
'\r' => {
printf("\n", .{});
std.mem.copy(u8, &last_buf, buf[0..len]);
@memcpy(&last_buf, buf[0..len]);
last_len = len;
self.process(buf[0..len]);
printf("> ", .{});
Expand Down
1 change: 0 additions & 1 deletion dtb
Submodule dtb deleted from f8b0e1

0 comments on commit fc78497

Please sign in to comment.