feat(loader, kernel): impl part of loader and initialize kernel structure
This commit is contained in:
41
arch/x86_64/boot/build_tool/symbol_extract.zig
Normal file
41
arch/x86_64/boot/build_tool/symbol_extract.zig
Normal file
@@ -0,0 +1,41 @@
|
||||
const std = @import("std");
|
||||
const Dir = std.Io.Dir;
|
||||
|
||||
const elfy = @import("elfy");
|
||||
const mvzr = @import("mvzr");
|
||||
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
var gpa: std.heap.DebugAllocator(.{}) = .init;
|
||||
const allocator = gpa.allocator();
|
||||
defer _ = gpa.deinit();
|
||||
|
||||
const args = try init.minimal.args.toSlice(init.arena.allocator());
|
||||
|
||||
if (args.len != 5) {
|
||||
std.debug.print("Usage: {s} <source_file> <pattern> <prefix> <output_file>\n", .{args[0]});
|
||||
std.process.exit(1);
|
||||
}
|
||||
const input_path = args[1];
|
||||
const pattern = args[2];
|
||||
const prefix = args[3];
|
||||
const output_path = args[4];
|
||||
const re = mvzr.compile(pattern) orelse @panic("Failed to compile regex pattern");
|
||||
|
||||
var file = try Dir.cwd().createFile(init.io, output_path, .{ .truncate = true });
|
||||
defer file.close(init.io);
|
||||
var w = file.writer(init.io, &[0]u8{});
|
||||
|
||||
_ = try w.interface.write("/* Auto-generated symbol extract header */\n#pragma once\n");
|
||||
var binary = try elfy.Elf.init(init.io, input_path, .ReadOnly, allocator);
|
||||
defer binary.deinit();
|
||||
|
||||
var symbols = try binary.getIterator(elfy.ElfSymbol);
|
||||
while (try symbols.next()) |symbol| {
|
||||
const name = try binary.getSymbolName(symbol);
|
||||
if (re.isMatch(name)) {
|
||||
try w.interface.print("#define {s}{s} 0x{x}\n", .{prefix, name, symbol.getValue()});
|
||||
}
|
||||
}
|
||||
try w.interface.flush();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user