1#!/usr/bin/perl -w 2# $FreeBSD$ 3 4use strict; 5 6if (!defined($ARGV[0])) { 7 print( 8" 9Perl script to convert NCR script address into label+offset. 10Useful to find the failed NCR instruction ... 11 12usage: $0 <address> 13"); 14 exit(1); 15} 16 17my $errpos = hex($ARGV[0])/4; 18my $ofs=0; 19 20open (INPUT, "cc -E ncr.c 2>/dev/null |"); 21 22while ($_ = <INPUT>) 23{ 24 last if /^struct script \{/; 25} 26 27while ($_ = <INPUT>) 28{ 29 last if /^\}\;/; 30 my ($label, $size) = /ncrcmd\s+(\S+)\s+\[([^]]+)/; 31 $size = eval($size); 32 if (defined($label) && $label) { 33 if ($errpos) { 34 if ($ofs + $size > $errpos) { 35 printf ("%4x: %s\n", $ofs * 4, $label); 36 printf ("%4x: %s + %d\n", $errpos * 4, $label, $errpos - $ofs); 37 last; 38 } 39 $ofs += $size; 40 } else { 41 printf ("%4x: %s\n", $ofs * 4, $label); 42 } 43 } 44} 45 46