Setting up repository
[linux-libre-firmware.git] / dsp56k / concat-bootstrap.pl
1 # Postprocessor for dsp56k bootstrap code.
2 #
3 # Copyright Ben Hutchings 2011.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9
10 use strict;
11 use warnings;
12
13 my @memory;
14 my %symbol;
15
16 # Reconstruct memory image and symbol table
17 while (<>) {
18     if (/^P ([0-9A-F]{4}) ([0-9A-F]{6})\n/) {
19         $memory[hex($1)] = hex($2);
20     } elsif (/^I ([0-9A-F]{6}) (\w+)\n/) {
21         $symbol{$2} = hex($1);
22     } else {
23         print STDERR "W: did not recognise line $.\n";
24     }
25 }
26
27 # Concatenate first and second stage.  Second stage is assembled
28 # between 'upload' and 'upload_end', but initially loaded at
29 # 'real' (end of the first stage).
30 for (0 .. ($symbol{real} - 1), $symbol{upload} .. ($symbol{upload_end} - 1)) {
31     my $word = $memory[$_] || 0;
32     print pack('CCC', $word / 65536, ($word / 256) % 256, $word % 256);
33 }