#!perl # Use this to comments to string references in ColdFire assembly code # as extracted using the ColdFire emulator. The ".bin" file is the # raw binary image, and the ".asm" file is the disassembly output. # the "offset" parameter says where the code would have been located # in the processor's memory space. # # Example usage: # ./addstrings.pl sdram_img.bin ihp_sdram.asm 0x31000000 if ($#ARGV < 1) { print "Usage: $ARGV0 [address_offset]\n"; exit 1; } open(BINFILE, $ARGV[0]); open(ASMFILE, $ARGV[1]); my $offset = 0; $offset = hex($ARGV[2]) if ($#ARGV > 1); while () { chomp; print; if (/(PEA|MOVEA.L|MOVE.L).*0x([0-9A-F]*)/ && hex($2) > $offset && hex($2) < $offset + 0xfffff) { my $offset = hex($2) - $offset; seek(BINFILE, $offset, 0); my $str; my $ret = read(BINFILE, $str, 80); $str = unpack("Z*", $str); if (length($str) > 4 && $str =~ /^[\r\n\s[:print:]]*$/) { $str =~ s/\r/\\r/g; $str =~ s/\n/\\n/g; print qq(\t\t; "$str"); } } print "\n"; }