aboutsummaryrefslogtreecommitdiff
path: root/posts
diff options
context:
space:
mode:
Diffstat (limited to 'posts')
-rw-r--r--posts/call_to_ARMs.md84
1 files changed, 84 insertions, 0 deletions
diff --git a/posts/call_to_ARMs.md b/posts/call_to_ARMs.md
new file mode 100644
index 0000000..c4ce60a
--- /dev/null
+++ b/posts/call_to_ARMs.md
@@ -0,0 +1,84 @@
1My 4th semester involves ARM programming. And proprietary
2tooling (Keil C). But we don't do that here.
3
4### Building
5
6Assembling and linking ARM binaries on non-ARM architecture
7devices is fairly trivial. I went along with the GNU cross
8bare metal toolchain binutils, which provides `arm-as` and
9`arm-ld` (among a bunch of other utils that I don't care
10about for now).
11
12Assemble `.s` files with:
13
14```shell
15arm-none-eabi-as main.s -g -march=armv8.1-a -o main.out
16```
17
18The `-g` flag generates extra debugging information that
19`gdb` picks up. The `-march` option establishes target
20architecture.
21
22Link `.o` files with:
23
24```shell
25arm-none-eabi-ld main.out -o main
26```
27
28### Running (and Debugging)
29
30Things get interesting here. `gdb` on your x86 machine
31cannot read nor execute binaries compiled for ARM. So, we
32simulate an ARM processor using `qemu`. Now qemu allows you
33to run `gdbserver` on startup. Connecting our local `gdb`
34instance to `gdbserver` gives us a view into the program's
35execution. Easy!
36
37Run `qemu`, with `gdbserver` on port `1234`, with our ARM
38binary, `main`:
39
40```shell
41qemu-arm -singlestep -g 1234 main
42```
43
44Start up `gdb` on your machine, and connect to `qemu`'s
45`gdbserver`:
46
47```
48(gdb) set architecture armv8-a
49(gdb) target remote localhost:1234
50(gdb) file main
51Reading symbols from main... # yay!
52```
53
54### GDB Enhanced
55
56`gdb` is cool, but it's not nearly as comfortable as well
57fleshed out emulators/IDEs like Keil. Watching registers,
58CPSR and memory chunks update *is* pretty fun.
59
60I came across `gdb`'s TUI mode (hit `C-x C-a` or type `tui
61enable` at the prompt). TUI mode is a godsend. It highlights
62the current line of execution, shows you disassembly
63outputs, updated registers, active breakpoints and more.
64
65*But*, it is an absolute eyesore.
66
67Say hello to [GEF](https://github.com/hugsy/gef)! "GDB
68Enhanced Features" teaches our old dog some cool new tricks.
69Here are some additions that made my ARM debugging
70experience loads better:
71
72 - Memory watches
73 - Register watches, with up to 7 levels of deref (overkill,
74 I agree)
75 - Stack tracing
76
77And its pretty! See for yourself:
78
79![gef.png](https://u.peppe.rs/wq.png)
80
81### Editing
82
83Vim, with `syntax off` because it
84dosen't handle GNU ARM syntax too well.