3 # Calculate the highest possible location for an overlay based
4 # on a reference map file (.refmap)
7 # The buflib handle table is a few hundred bytes, just before
8 # the plugin buffer. We assume it's never more than 1024 bytes.
9 # If this assumption is wrong, overlay loading will fail.
10 my $max_handle_table_size = 1024;
12 my $ramstart = -1, $ramsize = -1, $startaddr = -1, $endaddr = -1;
15 if ($_ =~ /^PLUGIN_RAM +0x([0-9a-f]+) +0x([0-9a-f]+)$/) {
19 elsif ($_ =~ / +0x([0-9a-f]+) +_?plugin_start_addr = ./) {
22 elsif ($_ =~ / +0x([0-9a-f]+) +_?plugin_end_addr = ./) {
27 if ($ramstart < 0 || $ramsize < 0 || $startaddr < 0 || $endaddr < 0
28 || $ramstart != $startaddr) {
29 printf "Could not analyze map file.\n";
32 return $ramstart + $ramsize - $endaddr - $max_handle_table_size;
35 printf map_scan
($ARGV[0]) & ~0xf;