2 ## -----------------------------------------------------------------------
4 ## Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ## Boston MA 02111-1307, USA; either version 2 of the License, or
10 ## (at your option) any later version; incorporated herein by reference.
12 ## -----------------------------------------------------------------------
15 # Postprocess the memdisk binary. Used during the 'make' process.
16 # We write memdisk16.bin out to the final memdisk kernel, pad it to an
17 # integral 512-byte sector length, write this number of sectors into the
18 # kernel header field "setup_sects", then append memdisk32.bin
22 ($out,$file16,$file32) = @ARGV;
24 open(OUT
, "> $out\0") or die "$0: Cannot create file: $out\n";
25 eval { binmode OUT
; };
26 open(FILE
, "< $file16\0") or die "$0: Cannot open file: $file16\n";
27 eval { binmode FILE
};
32 $sectors = ($size + 511) >> 9;
33 $xsize = $sectors << 9;
35 read(FILE
, $f16, $size);
39 if ( $size != $xsize ) {
40 # Pad to a sector boundary
41 print OUT
"\0" x
($xsize-$size);
44 seek(OUT
, 0x1f1, SEEK_SET
); # setup_sects
45 # All sectors are setup except the first
46 print OUT
pack("C", $sectors-1);
48 seek(OUT
, $xsize, SEEK_SET
);
51 open(FILE
, "+< $file32\0") or die "$0: Cannot open file: $file32\n";
53 while ( ($n = read(FILE
, $f32, 65536)) > 0 ) {