hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/scripts/decodecode
....@@ -6,6 +6,7 @@
66 # options: set env. variable AFLAGS=options to pass options to "as";
77 # e.g., to decode an i386 oops on an x86_64 system, use:
88 # AFLAGS=--32 decodecode < 386.oops
9
+# PC=hex - the PC (program counter) the oops points to
910
1011 cleanup() {
1112 rm -f $T $T.s $T.o $T.oo $T.aa $T.dis
....@@ -60,15 +61,26 @@
6061 4) type=4byte ;;
6162 esac
6263
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)
6372 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
6577
6678 if [ "$ARCH" = "arm" ]; then
6779 if [ $width -eq 2 ]; then
6880 OBJDUMPFLAGS="-M force-thumb"
6981 fi
7082
71
- ${CROSS_COMPILE}strip $1.o
83
+ ${CROSS_COMPILE}strip $t.o
7284 fi
7385
7486 if [ "$ARCH" = "arm64" ]; then
....@@ -76,11 +88,18 @@
7688 type=inst
7789 fi
7890
79
- ${CROSS_COMPILE}strip $1.o
91
+ ${CROSS_COMPILE}strip $t.o
8092 fi
8193
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
84103 }
85104
86105 marker=`expr index "$code" "\<"`
....@@ -88,14 +107,17 @@
88107 marker=`expr index "$code" "\("`
89108 fi
90109
110
+
91111 touch $T.oo
92112 if [ $marker -ne 0 ]; then
113
+ # 2 opcode bytes and a single space
114
+ pc_sub=$(( $marker / 3 ))
93115 echo All code >> $T.oo
94116 echo ======== >> $T.oo
95117 beforemark=`echo "$code"`
96118 echo -n " .$type 0x" > $T.s
97119 echo $beforemark | sed -e 's/ /,0x/g; s/[<>()]//g' >> $T.s
98
- disas $T
120
+ disas $T $pc_sub
99121 cat $T.dis >> $T.oo
100122 rm -f $T.o $T.s $T.dis
101123
....@@ -107,7 +129,7 @@
107129 code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g; s/[>)]$//'`
108130 echo -n " .$type 0x" > $T.s
109131 echo $code >> $T.s
110
-disas $T
132
+disas $T 0
111133 cat $T.dis >> $T.aa
112134
113135 # (lines of whole $T.oo) - (lines of $T.aa, i.e. "Code starting") + 3,