2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-22 12:14:01 +08:00
linux-next/arch/x86/tools/objdump_reformat.awk
Masami Hiramatsu 98fe07fccc x86/tools: Rename distill.awk to objdump_reformat.awk
Rename distill.awk to objdump_reformat.awk because it more
clearly expresses its purpose of re-formatting the output
of objdump so that insn_decoder_test can read it.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/151153625409.22827.10470603625519700259.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-12-12 13:27:47 +01:00

49 lines
1.3 KiB
Awk

#!/bin/awk -f
# SPDX-License-Identifier: GPL-2.0
# Usage: objdump -d a.out | awk -f objdump_reformat.awk | ./insn_decoder_test
# Reformats the disassembly as follows:
# - Removes all lines except the disassembled instructions.
# - For instructions that exceed 1 line (7 bytes), crams all the hex bytes
# into a single line.
# - Remove bad(or prefix only) instructions
BEGIN {
prev_addr = ""
prev_hex = ""
prev_mnemonic = ""
bad_expr = "(\\(bad\\)|^rex|^.byte|^rep(z|nz)$|^lock$|^es$|^cs$|^ss$|^ds$|^fs$|^gs$|^data(16|32)$|^addr(16|32|64))"
fwait_expr = "^9b "
fwait_str="9b\tfwait"
}
/^ *[0-9a-f]+ <[^>]*>:/ {
# Symbol entry
printf("%s%s\n", $2, $1)
}
/^ *[0-9a-f]+:/ {
if (split($0, field, "\t") < 3) {
# This is a continuation of the same insn.
prev_hex = prev_hex field[2]
} else {
# Skip bad instructions
if (match(prev_mnemonic, bad_expr))
prev_addr = ""
# Split fwait from other f* instructions
if (match(prev_hex, fwait_expr) && prev_mnemonic != "fwait") {
printf "%s\t%s\n", prev_addr, fwait_str
sub(fwait_expr, "", prev_hex)
}
if (prev_addr != "")
printf "%s\t%s\t%s\n", prev_addr, prev_hex, prev_mnemonic
prev_addr = field[1]
prev_hex = field[2]
prev_mnemonic = field[3]
}
}
END {
if (prev_addr != "")
printf "%s\t%s\t%s\n", prev_addr, prev_hex, prev_mnemonic
}