Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/awk -f
0002 # SPDX-License-Identifier: GPL-2.0
0003 # Usage: objdump -d a.out | awk -f objdump_reformat.awk | ./insn_decoder_test
0004 # Reformats the disassembly as follows:
0005 # - Removes all lines except the disassembled instructions.
0006 # - For instructions that exceed 1 line (7 bytes), crams all the hex bytes
0007 # into a single line.
0008 # - Remove bad(or prefix only) instructions
0009 
0010 BEGIN {
0011   prev_addr = ""
0012   prev_hex = ""
0013   prev_mnemonic = ""
0014   bad_expr = "(\\(bad\\)|^rex|^.byte|^rep(z|nz)$|^lock$|^es$|^cs$|^ss$|^ds$|^fs$|^gs$|^data(16|32)$|^addr(16|32|64))"
0015   fwait_expr = "^9b "
0016   fwait_str="9b\tfwait"
0017 }
0018 
0019 /^ *[0-9a-f]+ <[^>]*>:/ {
0020   # Symbol entry
0021   printf("%s%s\n", $2, $1)
0022 }
0023 
0024 /^ *[0-9a-f]+:/ {
0025   if (split($0, field, "\t") < 3) {
0026     # This is a continuation of the same insn.
0027     prev_hex = prev_hex field[2]
0028   } else {
0029     # Skip bad instructions
0030     if (match(prev_mnemonic, bad_expr))
0031       prev_addr = ""
0032     # Split fwait from other f* instructions
0033     if (match(prev_hex, fwait_expr) && prev_mnemonic != "fwait") {
0034       printf "%s\t%s\n", prev_addr, fwait_str
0035       sub(fwait_expr, "", prev_hex)
0036     }
0037     if (prev_addr != "")
0038       printf "%s\t%s\t%s\n", prev_addr, prev_hex, prev_mnemonic
0039     prev_addr = field[1]
0040     prev_hex = field[2]
0041     prev_mnemonic = field[3]
0042   }
0043 }
0044 
0045 END {
0046   if (prev_addr != "")
0047     printf "%s\t%s\t%s\n", prev_addr, prev_hex, prev_mnemonic
0048 }