diff options
Diffstat (limited to 'scripts/decodecode')
| -rwxr-xr-x | scripts/decodecode | 48 | 
1 files changed, 35 insertions, 13 deletions
diff --git a/scripts/decodecode b/scripts/decodecode index 4b00647814bc..8b30cc36744f 100755 --- a/scripts/decodecode +++ b/scripts/decodecode  | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | # AFLAGS=--32 decodecode < 386.oops | 7 | # AFLAGS=--32 decodecode < 386.oops | 
| 8 | 8 | ||
| 9 | cleanup() { | 9 | cleanup() { | 
| 10 | rm -f $T $T.s $T.o $T.oo $T.aa $T.aaa | 10 | rm -f $T $T.s $T.o $T.oo $T.aa $T.dis | 
| 11 | exit 1 | 11 | exit 1 | 
| 12 | } | 12 | } | 
| 13 | 13 | ||
| @@ -39,6 +39,29 @@ fi | |||
| 39 | echo $code | 39 | echo $code | 
| 40 | code=`echo $code | sed -e 's/.*Code: //'` | 40 | code=`echo $code | sed -e 's/.*Code: //'` | 
| 41 | 41 | ||
| 42 | width=`expr index "$code" ' '` | ||
| 43 | width=$[($width-1)/2] | ||
| 44 | case $width in | ||
| 45 | 1) type=byte ;; | ||
| 46 | 2) type=2byte ;; | ||
| 47 | 4) type=4byte ;; | ||
| 48 | esac | ||
| 49 | |||
| 50 | disas() { | ||
| 51 | ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s &> /dev/null | ||
| 52 | |||
| 53 | if [ "$ARCH" == "arm" ]; then | ||
| 54 | if [ $width == 2 ]; then | ||
| 55 | OBJDUMPFLAGS="-M force-thumb" | ||
| 56 | fi | ||
| 57 | |||
| 58 | ${CROSS_COMPILE}strip $1.o | ||
| 59 | fi | ||
| 60 | |||
| 61 | ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \ | ||
| 62 | grep -v "/tmp\|Disassembly\|\.text\|^$" &> $1.dis | ||
| 63 | } | ||
| 64 | |||
| 42 | marker=`expr index "$code" "\<"` | 65 | marker=`expr index "$code" "\<"` | 
| 43 | if [ $marker -eq 0 ]; then | 66 | if [ $marker -eq 0 ]; then | 
| 44 | marker=`expr index "$code" "\("` | 67 | marker=`expr index "$code" "\("` | 
| @@ -49,26 +72,25 @@ if [ $marker -ne 0 ]; then | |||
| 49 | echo All code >> $T.oo | 72 | echo All code >> $T.oo | 
| 50 | echo ======== >> $T.oo | 73 | echo ======== >> $T.oo | 
| 51 | beforemark=`echo "$code"` | 74 | beforemark=`echo "$code"` | 
| 52 | echo -n " .byte 0x" > $T.s | 75 | echo -n " .$type 0x" > $T.s | 
| 53 | echo $beforemark | sed -e 's/ /,0x/g' | sed -e 's/<//g' | sed -e 's/>//g' >> $T.s | 76 | echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s | 
| 54 | as $AFLAGS -o $T.o $T.s &> /dev/null | 77 | disas $T | 
| 55 | objdump -S $T.o | grep -v "/tmp" | grep -v "Disassembly" | grep -v "\.text" | grep -v "^$" &> $T.ooo | 78 | cat $T.dis >> $T.oo | 
| 56 | cat $T.ooo >> $T.oo | 79 | rm -f $T.o $T.s $T.dis | 
| 57 | rm -f $T.o $T.s $T.ooo | ||
| 58 | 80 | ||
| 59 | # and fix code at-and-after marker | 81 | # and fix code at-and-after marker | 
| 60 | code=`echo "$code" | cut -c$((${marker} + 1))-` | 82 | code=`echo "$code" | cut -c$((${marker} + 1))-` | 
| 61 | fi | 83 | fi | 
| 62 | echo Code starting with the faulting instruction > $T.aa | 84 | echo Code starting with the faulting instruction > $T.aa | 
| 63 | echo =========================================== >> $T.aa | 85 | echo =========================================== >> $T.aa | 
| 64 | code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'` | 86 | code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'` | 
| 65 | echo -n " .byte 0x" > $T.s | 87 | echo -n " .$type 0x" > $T.s | 
| 66 | echo $code >> $T.s | 88 | echo $code >> $T.s | 
| 67 | as $AFLAGS -o $T.o $T.s &> /dev/null | 89 | disas $T | 
| 68 | objdump -S $T.o | grep -v "Disassembly" | grep -v "/tmp" | grep -v "\.text" | grep -v "^$" &> $T.aaa | 90 | cat $T.dis >> $T.aa | 
| 69 | cat $T.aaa >> $T.aa | ||
| 70 | 91 | ||
| 71 | faultline=`cat $T.aaa | head -1 | cut -d":" -f2` | 92 | faultline=`cat $T.dis | head -1 | cut -d":" -f2` | 
| 93 | faultline=`echo "$faultline" | sed -e 's/\[/\\\[/g; s/\]/\\\]/g'` | ||
| 72 | 94 | ||
| 73 | cat $T.oo | sed -e "s/\($faultline\)/\*\1 <-- trapping instruction/g" | 95 | cat $T.oo | sed -e "s/\($faultline\)/\*\1 <-- trapping instruction/g" | 
| 74 | echo | 96 | echo | 
