Update contrib.
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 # This component and the accompanying materials are made available
5 # under the terms of the License "Eclipse Public License v1.0"
6 # which accompanies this distribution, and is available
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 # Initial Contributors:
10 # Nokia Corporation - initial contribution.
16 # Perl script to decode ROM symbols
18 # Usage: perl printsym.pl symbolfile
20 # Converts various forms of text from STDIN and write to stdout
24 add_object(0xF8000000,0xFFF00000, "ROM");
26 die "Usage: printsym.pl romsymbolfile\n" unless @ARGV;
31 read_rom_symbols($ARGV[0]);
34 ## need to add more file types here... especially .map files
37 # We've accumulated the ranges of objects indexed by start address,
38 # with a companion list of addresses subdivided by the leading byte
39 # Now sort them numerically...
41 sub numerically { $a <=> $b }
42 foreach my $key (keys %addresslist)
44 @{$addresslist{$key}} = sort numerically @{$addresslist{$key}};
47 # read lines from STDIN and decode them
49 print "Please enter data to be decoded\n";
51 while (my $line=<STDIN>)
53 next if ($line =~ /^\s+$/); # skip blank lines
55 if ($line =~ /(?:^|\s)(([0-9A-Fa-f]{2} ){4,})/) # pairs of hex digits separated by spaces = hex dump?
61 if ($line =~ /[0-9A-Fa-f]{8}\s+/) # groups of hex words
70 #############################################################################
74 my ($base, $max, $name) = @_;
75 $address{$base} = [ $base, $max, $name ];
78 while ($key <= $maxkey) # allowing for objects that span the boundary
80 push @{$addresslist{$key}}, $base;
87 # Try matching one of the named areas in the addresslist
92 if ($word < 1024*1024)
97 # Optimization - try looking up the address directly
102 if(defined $address{$word}) {
103 ($base, $max, $name) = @{$address{$word}};
105 if (!(defined $base))
109 foreach $base (@{$addresslist{$key}})
121 if(defined $regionbase)
123 ($base, $max, $name) = @{$address{$regionbase}};
126 if (defined $base && defined $max && $base <= $word && $max >= $word)
128 printf "%s + 0x%x", $name, $word - $base;
134 # Handle a MAKSYM.LOG file for a ROM
138 # open ROMIMAGE, "cxxfilt <$romimage |" or open ROMIMAGE, $romimage or die
140 # but this uses "/bin/sh cxxfilt <$romimage" which works up to the point where the
141 # shell can't load cxxfilt.
146 open ROMSYMBOLS, $romimage or print "Can't open $romimage\n" and return;
150 while (my $line = <ROMSYMBOLS>)
152 if(!($line =~ /^[0-9A-Fa-f]{8}/))
156 # 8 bytes for the address
158 $a = substr $line,0,8;
159 if(!($a =~ /[0-9A-Fa-f]{8}/))
163 # 4 bytes for the length
164 $b = substr $line,12,4;
165 if(!($b =~ /[0-9A-Fa-f]{4}/))
169 # rest of line is symbol
170 my $symbol = substr $line,20;
175 if ($base < 0x50000000)
177 next; # skip this line
179 if ($length==0xffffffff)
181 $length=100; # MAKSYM bug? choose a rational length
183 add_object($base, $base+$length-1, $symbol);
185 print "ROM Symbols from $romimage\n";
191 my $data = pack "V", @_[0];
192 $data =~ tr [\040-\177]/./c;
193 printf "= %08x %4s ", $word, $data;
200 my @bytes = split /\s+/, @_[0];
201 my $wordcount = @bytes/4;
202 map { dumpword($_) } (unpack "V$wordcount", (pack "H2"x($wordcount*4), @bytes));
206 my @words = grep /[0-9A-Fa-f]{8}/, split( /[^0-9A-Fa-f]+/, @_[0]);
207 my $wordcount = @words;
208 map { dumpword($_) } (unpack "N$wordcount", (pack "H8"x($wordcount), @words));