Skip to content

Instantly share code, notes, and snippets.

@jsharf
Created November 11, 2020 06:17
Show Gist options
  • Save jsharf/1a3bd90b98f9111d0ed7c34d15d1a305 to your computer and use it in GitHub Desktop.
Save jsharf/1a3bd90b98f9111d0ed7c34d15d1a305 to your computer and use it in GitHub Desktop.
define armex
printf "EXEC_RETURN (LR):\n",
info registers $lr
if $lr & 0x4 == 0x4
printf "Uses MSP 0x%x return.\n", $msp
set $armex_base = (char *) $msp
else
printf "Uses PSP 0x%x return.\n", $psp
set $armex_base = (char *) $psp
end
printf "xPSR 0x%x\n", *((unsigned int *) ($armex_base+28))
printf "ReturnAddress 0x%x\n", *((unsigned int *) ($armex_base+24))
printf "LR (R14) 0x%x\n", *((unsigned int *) ($armex_base+20))
printf "R12 0x%x\n", *((unsigned int *) ($armex_base+16))
printf "R3 0x%x\n", *((unsigned int *) ($armex_base+12))
printf "R2 0x%x\n", *((unsigned int *) ($armex_base+8))
printf "R1 0x%x\n", *((unsigned int *) ($armex_base+4))
printf "R0 0x%x\n", *((unsigned int *) ($armex_base))
printf "Return instruction:\n"
x/i *($armex_base+24)
printf "LR instruction:\n"
x/i *($armex_base+20)
end
define nrf_gpio
set $pin = $arg0
set $gpio_base = 0x50000000
set $cnf_base = $gpio_base + 0x700 + 0x4 * ($pin)
set *((unsigned int *) $cnf_base) = 0x1
set $gpio_out = $gpio_base + 0x508
set *((unsigned int *) $gpio_out) = 0x1 << ($pin)
end
document armex
ARMv7 Exception entry behavior.
xPSR, ReturnAddress, LR (R14), R12, R3, R2, R1, and R0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment