blob: f418c91b71f011b7306c837dd84c27ca4d0c3c1a [file] [log] [blame]
Masami Hiramatsuca0e9ba2009-08-13 16:34:21 -04001#!/bin/awk -f
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
Masami Hiramatsu98fe07f2017-11-25 00:10:54 +09003# Usage: objdump -d a.out | awk -f objdump_reformat.awk | ./insn_decoder_test
4# Reformats the disassembly as follows:
Masami Hiramatsuca0e9ba2009-08-13 16:34:21 -04005# - Removes all lines except the disassembled instructions.
6# - For instructions that exceed 1 line (7 bytes), crams all the hex bytes
7# into a single line.
8# - Remove bad(or prefix only) instructions
9
10BEGIN {
11 prev_addr = ""
12 prev_hex = ""
13 prev_mnemonic = ""
14 bad_expr = "(\\(bad\\)|^rex|^.byte|^rep(z|nz)$|^lock$|^es$|^cs$|^ss$|^ds$|^fs$|^gs$|^data(16|32)$|^addr(16|32|64))"
15 fwait_expr = "^9b "
16 fwait_str="9b\tfwait"
17}
18
Masami Hiramatsu35039eb2009-11-16 18:06:24 -050019/^ *[0-9a-f]+ <[^>]*>:/ {
20 # Symbol entry
21 printf("%s%s\n", $2, $1)
22}
23
Masami Hiramatsuca0e9ba2009-08-13 16:34:21 -040024/^ *[0-9a-f]+:/ {
25 if (split($0, field, "\t") < 3) {
26 # This is a continuation of the same insn.
27 prev_hex = prev_hex field[2]
28 } else {
29 # Skip bad instructions
30 if (match(prev_mnemonic, bad_expr))
31 prev_addr = ""
32 # Split fwait from other f* instructions
33 if (match(prev_hex, fwait_expr) && prev_mnemonic != "fwait") {
34 printf "%s\t%s\n", prev_addr, fwait_str
35 sub(fwait_expr, "", prev_hex)
36 }
37 if (prev_addr != "")
38 printf "%s\t%s\t%s\n", prev_addr, prev_hex, prev_mnemonic
39 prev_addr = field[1]
40 prev_hex = field[2]
41 prev_mnemonic = field[3]
42 }
43}
44
45END {
46 if (prev_addr != "")
47 printf "%s\t%s\t%s\n", prev_addr, prev_hex, prev_mnemonic
48}