Adding upstream version 3.35.
[syslinux-debian/hramrach.git] / memdisk / postprocess.pl
blob31bde4a3fd1f5b898d722c2d1f5cdc309d158375
1 #!/usr/bin/perl
2 ## -----------------------------------------------------------------------
3 ##
4 ## Copyright 2001 H. Peter Anvin - All Rights Reserved
5 ##
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.
18 eval { use bytes; };
20 ($out,$file16,$file32) = @ARGV;
22 open(OUT, "> $out\0") or die "$0: Cannot create file: $out\n";
23 eval { binmode OUT; };
24 open(FILE, "< $file16\0") or die "$0: Cannot open file: $file16\n";
25 eval { binmode FILE };
27 @info = stat(FILE);
28 $size = $info[7];
30 $sectors = ($size + 511) >> 9;
31 $xsize = $sectors << 9;
33 read(FILE, $f16, $size);
35 print OUT $f16;
37 if ( $size != $xsize ) {
38 # Pad to a sector boundary
39 print OUT "\0" x ($xsize-$size);
42 seek(OUT, 0x1f1, SEEK_SET); # setup_sects
43 # All sectors are setup except the first
44 print OUT pack("C", $sectors-1);
46 seek(OUT, $xsize, SEEK_SET);
47 close(FILE);
49 open(FILE, "+< $file32\0") or die "$0: Cannot open file: $file32\n";
51 while ( ($n = read(FILE, $f32, 65536)) > 0 ) {
52 print OUT $f32;
55 close(FILE);
56 close(OUT);