.. | .. |
---|
6 | 6 | # options: set env. variable AFLAGS=options to pass options to "as"; |
---|
7 | 7 | # e.g., to decode an i386 oops on an x86_64 system, use: |
---|
8 | 8 | # AFLAGS=--32 decodecode < 386.oops |
---|
| 9 | +# PC=hex - the PC (program counter) the oops points to |
---|
9 | 10 | |
---|
10 | 11 | cleanup() { |
---|
11 | 12 | rm -f $T $T.s $T.o $T.oo $T.aa $T.dis |
---|
.. | .. |
---|
60 | 61 | 4) type=4byte ;; |
---|
61 | 62 | esac |
---|
62 | 63 | |
---|
| 64 | +if [ -z "$ARCH" ]; then |
---|
| 65 | + case `uname -m` in |
---|
| 66 | + aarch64*) ARCH=arm64 ;; |
---|
| 67 | + arm*) ARCH=arm ;; |
---|
| 68 | + esac |
---|
| 69 | +fi |
---|
| 70 | + |
---|
| 71 | +# Params: (tmp_file, pc_sub) |
---|
63 | 72 | disas() { |
---|
64 | | - ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s > /dev/null 2>&1 |
---|
| 73 | + t=$1 |
---|
| 74 | + pc_sub=$2 |
---|
| 75 | + |
---|
| 76 | + ${CROSS_COMPILE}as $AFLAGS -o $t.o $t.s > /dev/null 2>&1 |
---|
65 | 77 | |
---|
66 | 78 | if [ "$ARCH" = "arm" ]; then |
---|
67 | 79 | if [ $width -eq 2 ]; then |
---|
68 | 80 | OBJDUMPFLAGS="-M force-thumb" |
---|
69 | 81 | fi |
---|
70 | 82 | |
---|
71 | | - ${CROSS_COMPILE}strip $1.o |
---|
| 83 | + ${CROSS_COMPILE}strip $t.o |
---|
72 | 84 | fi |
---|
73 | 85 | |
---|
74 | 86 | if [ "$ARCH" = "arm64" ]; then |
---|
.. | .. |
---|
76 | 88 | type=inst |
---|
77 | 89 | fi |
---|
78 | 90 | |
---|
79 | | - ${CROSS_COMPILE}strip $1.o |
---|
| 91 | + ${CROSS_COMPILE}strip $t.o |
---|
80 | 92 | fi |
---|
81 | 93 | |
---|
82 | | - ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \ |
---|
83 | | - grep -v "/tmp\|Disassembly\|\.text\|^$" > $1.dis 2>&1 |
---|
| 94 | + if [ $pc_sub -ne 0 ]; then |
---|
| 95 | + if [ $PC ]; then |
---|
| 96 | + adj_vma=$(( $PC - $pc_sub )) |
---|
| 97 | + OBJDUMPFLAGS="$OBJDUMPFLAGS --adjust-vma=$adj_vma" |
---|
| 98 | + fi |
---|
| 99 | + fi |
---|
| 100 | + |
---|
| 101 | + ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $t.o | \ |
---|
| 102 | + grep -v "/tmp\|Disassembly\|\.text\|^$" > $t.dis 2>&1 |
---|
84 | 103 | } |
---|
85 | 104 | |
---|
86 | 105 | marker=`expr index "$code" "\<"` |
---|
.. | .. |
---|
88 | 107 | marker=`expr index "$code" "\("` |
---|
89 | 108 | fi |
---|
90 | 109 | |
---|
| 110 | + |
---|
91 | 111 | touch $T.oo |
---|
92 | 112 | if [ $marker -ne 0 ]; then |
---|
| 113 | + # 2 opcode bytes and a single space |
---|
| 114 | + pc_sub=$(( $marker / 3 )) |
---|
93 | 115 | echo All code >> $T.oo |
---|
94 | 116 | echo ======== >> $T.oo |
---|
95 | 117 | beforemark=`echo "$code"` |
---|
96 | 118 | echo -n " .$type 0x" > $T.s |
---|
97 | 119 | echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s |
---|
98 | | - disas $T |
---|
| 120 | + disas $T $pc_sub |
---|
99 | 121 | cat $T.dis >> $T.oo |
---|
100 | 122 | rm -f $T.o $T.s $T.dis |
---|
101 | 123 | |
---|
.. | .. |
---|
107 | 129 | code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'` |
---|
108 | 130 | echo -n " .$type 0x" > $T.s |
---|
109 | 131 | echo $code >> $T.s |
---|
110 | | -disas $T |
---|
| 132 | +disas $T 0 |
---|
111 | 133 | cat $T.dis >> $T.aa |
---|
112 | 134 | |
---|
113 | 135 | # (lines of whole $T.oo) - (lines of $T.aa, i.e. "Code starting") + 3, |
---|