Many changes:
[Marmot.git] / cs.pl
blobac7fc9ebd79933034aeb6d19850ba8f161904b2b
1 #!/usr/bin/perl
3 # cs.pl --
5 # Calculate sectors and save to loaderSectors
7 use strict;
8 use warnings;
10 my $off = 0;
12 my $map = "link.map";
13 open MAP, "<$map" or die "Unable to open $map: $!";
14 while (my $line = <MAP>) {
15 if ($line =~ m/(0x[0-9a-f]+)\s+loaderSectors/) {
16 $off = hex($1) - 0x7c00;
17 last;
21 my $bytes = (stat('boot'))[7];
22 my $sectors = int(($bytes + 512) / 512) - 1;
24 my $image = "boot.img";
26 open IMG, "+<$image" or die "Unable to open $image: $!";
27 binmode IMG;
28 seek IMG, $off, 0;
30 my $n = syswrite IMG, pack('S', $sectors), 2;
32 close IMG;
34 print sprintf(" ==> Writing 0x%04x to loaderSectors at offset 0x%x\n",
35 $sectors, $off);