make elphin shut up in pipelines

This commit is contained in:
Hamcha 2024-05-11 21:27:02 +02:00
parent d33c09a1ab
commit b7c527394d
Signed by: hamcha
GPG key ID: 1669C533B8CF6D89
6 changed files with 27 additions and 16 deletions

View file

@ -1,6 +1,6 @@
.{
.name = "elphin",
.version = "0.1.5",
.version = "0.1.6",
.minimum_zig_version = "0.12.0",
.paths = .{
"build.zig",

View file

@ -60,7 +60,7 @@ fn make(step: *std.Build.Step, _: *std.Progress.Node) !void {
defer output.close();
// Run conversion
try lib.convert(input, output);
try lib.convert(input, output, false);
// Copy file to destination
const cwd = std.fs.cwd();

View file

@ -83,7 +83,7 @@ pub fn createDOLMapping(segments: elf.ELFSegments) DolMap {
return dolMap;
}
pub fn writeDOL(map: DolMap, input: std.fs.File, output: std.fs.File) !void {
pub fn writeDOL(map: DolMap, input: std.fs.File, output: std.fs.File, verbose: bool) !void {
const reader = input.reader();
const writer = output.writer();
@ -106,7 +106,9 @@ pub fn writeDOL(map: DolMap, input: std.fs.File, output: std.fs.File) !void {
try output.seekTo(map.header.textOffsets[i]);
// Copy segment
if (verbose) {
std.log.debug("Copying text segment {d} at 0x{x} -> 0x{x}", .{ i, map.header.textAddress[i], map.header.textOffsets[i] });
}
try fifo.pump(&limitedReader, writer);
}
@ -122,7 +124,9 @@ pub fn writeDOL(map: DolMap, input: std.fs.File, output: std.fs.File) !void {
try output.seekTo(map.header.dataOffsets[i]);
// Copy segment
if (verbose) {
std.log.debug("Copying data segment {d} at 0x{x} -> 0x{x}", .{ i, map.header.dataAddress[i], map.header.dataOffsets[i] });
}
try fifo.pump(&limitedReader, writer);
}
}

View file

@ -78,7 +78,7 @@ pub const ELFSegments = struct {
bssSize: u32,
};
pub fn readELF(file: std.fs.File) !ELFSegments {
pub fn readELF(file: std.fs.File, verbose: bool) !ELFSegments {
// Create segment map
var elfMap: ELFSegments = .{
.entryPoint = undefined,
@ -156,10 +156,14 @@ pub fn readELF(file: std.fs.File) !ELFSegments {
if (programHeader.p_filesz < programHeader.p_memsz) {
// Add as BSS segment of whatever is left between the file and memory sizes
addOrExtendBSS(&elfMap, programHeader.p_paddr + programHeader.p_filesz, programHeader.p_memsz - programHeader.p_filesz);
if (verbose) {
std.log.debug("Found bss segment (TEXT) at 0x{x}", .{programHeader.p_paddr + programHeader.p_filesz});
}
}
if (verbose) {
std.log.debug("Found text segment at 0x{x}", .{programHeader.p_vaddr});
}
elfMap.text[elfMap.textCount] = .{
.address = programHeader.p_paddr,
@ -170,11 +174,12 @@ pub fn readELF(file: std.fs.File) !ELFSegments {
elfMap.textCount += 1;
} else {
// DATA or BSS segment
// TODO: ????
if (programHeader.p_filesz == 0) {
addOrExtendBSS(&elfMap, programHeader.p_paddr, programHeader.p_memsz);
if (verbose) {
std.log.debug("Found bss segment (DATA) at 0x{x}", .{programHeader.p_vaddr});
}
continue;
}
@ -183,7 +188,9 @@ pub fn readELF(file: std.fs.File) !ELFSegments {
return ELFError.TooManyDataSegments;
}
if (verbose) {
std.log.debug("Found data segment at 0x{x}", .{programHeader.p_vaddr});
}
elfMap.data[elfMap.dataCount] = .{
.address = programHeader.p_paddr,

View file

@ -10,13 +10,13 @@ pub const writeDOL = dol.writeDOL;
/// Converts an ELF file to a DOL file.
/// `input` and `output` must be open files.
pub fn convert(input: anytype, output: anytype) !void {
pub fn convert(input: anytype, output: anytype, verbose: bool) !void {
// Read input
const map = try elf.readELF(input);
const map = try elf.readELF(input, verbose);
// Align segments to 64 byte boundaries
const dolMap = dol.createDOLMapping(map);
// Write header and copy over segments from input
try dol.writeDOL(dolMap, input, output);
try dol.writeDOL(dolMap, input, output, verbose);
}

View file

@ -27,5 +27,5 @@ pub fn main() !void {
const output = try std.fs.cwd().createFile(outputPath, .{});
defer output.close();
try lib.convert(input, output);
try lib.convert(input, output, true);
}