xref: /linux/scripts/decodecode (revision fa220d89ad050cf5d970c0418ded019a80efedfb)
1dcecc6c7SRandy Dunlap#!/bin/sh
2dcecc6c7SRandy Dunlap# Disassemble the Code: line in Linux oopses
3dcecc6c7SRandy Dunlap# usage: decodecode < oops.file
4dcecc6c7SRandy Dunlap#
5dcecc6c7SRandy Dunlap# options: set env. variable AFLAGS=options to pass options to "as";
6dcecc6c7SRandy Dunlap# e.g., to decode an i386 oops on an x86_64 system, use:
7dcecc6c7SRandy Dunlap# AFLAGS=--32 decodecode < 386.oops
8dcecc6c7SRandy Dunlap
9*fa220d89SRandy Dunlapcleanup() {
10*fa220d89SRandy Dunlap	rm -f $T $T.s $T.o
11*fa220d89SRandy Dunlap	exit 1
12*fa220d89SRandy Dunlap}
13*fa220d89SRandy Dunlap
14*fa220d89SRandy Dunlapdie() {
15*fa220d89SRandy Dunlap	echo "$@"
16*fa220d89SRandy Dunlap	exit 1
17*fa220d89SRandy Dunlap}
18*fa220d89SRandy Dunlap
19*fa220d89SRandy Dunlaptrap cleanup EXIT
20*fa220d89SRandy Dunlap
21*fa220d89SRandy DunlapT=`mktemp` || die "cannot create temp file"
22dcecc6c7SRandy Dunlapcode=
23dcecc6c7SRandy Dunlap
24dcecc6c7SRandy Dunlapwhile read i ; do
25dcecc6c7SRandy Dunlap
26dcecc6c7SRandy Dunlapcase "$i" in
27dcecc6c7SRandy Dunlap*Code:*)
28dcecc6c7SRandy Dunlap	code=$i
29dcecc6c7SRandy Dunlap	;;
30dcecc6c7SRandy Dunlapesac
31dcecc6c7SRandy Dunlap
32dcecc6c7SRandy Dunlapdone
33dcecc6c7SRandy Dunlap
34dcecc6c7SRandy Dunlapif [ -z "$code" ]; then
35*fa220d89SRandy Dunlap	rm $T
36dcecc6c7SRandy Dunlap	exit
37dcecc6c7SRandy Dunlapfi
38dcecc6c7SRandy Dunlap
39dcecc6c7SRandy Dunlapecho $code
40dcecc6c7SRandy Dunlapcode=`echo $code | sed -e 's/.*Code: //'`
41dcecc6c7SRandy Dunlap
42dcecc6c7SRandy Dunlapmarker=`expr index "$code" "\<"`
43dcecc6c7SRandy Dunlapif [ $marker -eq 0 ]; then
44dcecc6c7SRandy Dunlap	marker=`expr index "$code" "\("`
45dcecc6c7SRandy Dunlapfi
46dcecc6c7SRandy Dunlap
47dcecc6c7SRandy Dunlapif [ $marker -ne 0 ]; then
48dcecc6c7SRandy Dunlap	beforemark=`echo "$code" | cut -c-$((${marker} - 1))`
49dcecc6c7SRandy Dunlap	echo -n "	.byte 0x" > $T.s
50dcecc6c7SRandy Dunlap	echo $beforemark | sed -e 's/ /,0x/g' >> $T.s
51dcecc6c7SRandy Dunlap	as $AFLAGS -o $T.o $T.s
52dcecc6c7SRandy Dunlap	objdump -S $T.o
53dcecc6c7SRandy Dunlap	rm $T.o $T.s
54dcecc6c7SRandy Dunlap
55dcecc6c7SRandy Dunlap# and fix code at-and-after marker
56dcecc6c7SRandy Dunlap	code=`echo "$code" | cut -c$((${marker} + 1))-`
57dcecc6c7SRandy Dunlapfi
58dcecc6c7SRandy Dunlap
59dcecc6c7SRandy Dunlapcode=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'`
60dcecc6c7SRandy Dunlapecho -n "	.byte 0x" > $T.s
61dcecc6c7SRandy Dunlapecho $code >> $T.s
62dcecc6c7SRandy Dunlapas $AFLAGS -o $T.o $T.s
63dcecc6c7SRandy Dunlapobjdump -S $T.o
64*fa220d89SRandy Dunlaprm $T $T.s $T.o
65