X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;ds=sidebyside;f=helper%2Fbin2s.pl;fp=helper%2Fbin2s.pl;h=2c78b5e5f612dfc1b215c1d3942ec7063e50dee6;hb=df569d49aa10af5995f771362ddc1400f16486e8;hp=0000000000000000000000000000000000000000;hpb=57b3004bde579b986523c43e3a0e6693fd49dd21;p=febootstrap.git diff --git a/helper/bin2s.pl b/helper/bin2s.pl new file mode 100755 index 0000000..2c78b5e --- /dev/null +++ b/helper/bin2s.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +# This script creates a source file for the GNU assembler which shuold +# result in an object file equivalent to that of +# +# objcopy -I binary -B $(DEFAULT_ARCH) -O $(ELF_DEFAULT_ARCH) + +use strict; +use warnings; + +die "usage: $0 \n" if @ARGV != 2; + +my ($infile, $outfile) = @ARGV; +my ($buf, $i, $sz); +open my $ifh, '<', $infile or die "open $infile: $!"; +open my $ofh, '>', $outfile or die "open $outfile: $!"; + +print $ofh <<"EOF"; +/* This file has been automatically generated from $infile by $0 */ + +\t.globl\t_binary_${infile}_start +\t.globl\t_binary_${infile}_end +\t.globl\t_binary_${infile}_size + +\t.section\t.data +_binary_${infile}_start: +EOF + +$sz = 0; +while ( $i = read $ifh, $buf, 12 ) { + print $ofh "\t.byte\t" + . join( ',', map { sprintf '0x%02x', ord $_ } split //, $buf ) . "\n"; + $sz += $i; +} +die "read $infile (at offset $sz): $!\n" if not defined $i; +close $ifh; + +print $ofh <<"EOF"; + +_binary_${infile}_end: + +\t.equ _binary_${infile}_size, $sz +EOF + +close $ofh;