SchOS/tools/padstage2.pl
Nexoniarz d0f7acf9eb Initial commit: Schunix as it stands before the SchOS rename
An x86-64 operating system built from xv6, now largely rewritten: SMP,
a copy-on-write root filesystem (SchFS), PCI/USB/virtio drivers, a TTF
rasteriser, and a Linux-numbered syscall ABI.

No history before this point -- the tree was never under version control.
This commit exists so the rename that follows has something to undo to.
2026-08-09 13:47:01 +02:00

24 lines
714 B
Perl

#!/usr/bin/perl
# Zero-pads the stage2 bootloader binary out to a fixed size (STAGE2_SECTORS
# * 512 bytes), so the kernel's on-disk starting sector is predictable
# regardless of stage2's actual compiled size. Errors out if stage2 has
# grown past that budget instead of silently truncating it.
my $size = $ARGV[1] || die "usage: padstage2.pl <file> <size-in-bytes>\n";
open(F, $ARGV[0]) || die "open $ARGV[0]: $!";
my $n = sysread(F, my $buf, $size + 1);
close(F);
if ($n > $size) {
print STDERR "stage2 too large: $n bytes (max $size)\n";
exit 1;
}
print STDERR "stage2 is $n bytes (max $size)\n";
$buf .= "\0" x ($size - $n);
open(F, ">$ARGV[0]") || die "open >$ARGV[0]: $!";
print F $buf;
close(F);