Skip to content

Instantly share code, notes, and snippets.

@oholiab
Created January 3, 2021 11:21
Show Gist options
  • Save oholiab/01893b4820bf47e59cfd5c76491534db to your computer and use it in GitHub Desktop.
Save oholiab/01893b4820bf47e59cfd5c76491534db to your computer and use it in GitHub Desktop.
BFSR_ADDR = "0xE000ed29"
BFSR_LEN = "b"
BFSR_BITS = [
"IBUSERR",
"PRECISERR",
"IMPRECISERR",
"UNSTKERR",
"STKERR",
"LSPERR",
"Reserved",
"BFARVALID"
]
class CFSR(gdb.Command):
def __init__(self):
gdb.Command.__init__(self, "cfsr", gdb.COMMAND_DATA)
def _get_bits(self, address, length):
bits = [bit for bit
in gdb.execute(
f"x/{length}t {address}", True, True
).split("\t")[1].strip()]
bits.reverse()
return bits
def invoke(self, args, from_tty):
cmd = str(args).split(" ")
if cmd[0] == "bfsr":
bits = self._get_bits(BFSR_ADDR, BFSR_LEN)
for i in range(len(bits)):
gdb.write(f"{BFSR_BITS[i]}: {bits[i]}\n")
gdb.flush()
return
if __name__ == "__main__":
CFSR()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment