aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/call_to_ARMs
diff options
context:
space:
mode:
Diffstat (limited to 'docs/posts/call_to_ARMs')
-rw-r--r--docs/posts/call_to_ARMs/index.html131
1 files changed, 131 insertions, 0 deletions
diff --git a/docs/posts/call_to_ARMs/index.html b/docs/posts/call_to_ARMs/index.html
new file mode 100644
index 0000000..4085a90
--- /dev/null
+++ b/docs/posts/call_to_ARMs/index.html
@@ -0,0 +1,131 @@
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <link rel="stylesheet" href="/style.css">
5 <meta charset="UTF-8">
6 <meta name="viewport" content="initial-scale=1">
7 <meta content="#ffffff" name="theme-color">
8 <meta name="HandheldFriendly" content="true">
9 <meta property="og:title" content="nerdypepper">
10 <meta property="og:type" content="website">
11 <meta property="og:description" content="a static site {for, by, about} me ">
12 <meta property="og:url" content="https://peppe.rs">
13 <link rel="icon" type="image/x-icon" href="/favicon.png">
14 <title>Call To ARMs - peppe.rs</title>
15 <body>
16 <div class="posts">
17 <div class="post">
18 <a href="/" class="post-end-link">⟵ Back</a>
19 <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/call_to_ARMs.md
20">View Raw</a>
21 <div class="separator"></div>
22 <div class="date">
23 09/02 — 2020
24 <div class="stats">
25 <span class="stats-number">
26 33.57
27 </span>
28 <span class="stats-unit">cm</span>
29 &nbsp
30 <span class="stats-number">
31 2.2
32 </span>
33 <span class="stats-unit">min</span>
34 </div>
35 </div>
36 <span class="post-title">
37 Call To ARMs
38 </span>
39 <div class="post-text">
40 <p>My 4th semester involves ARM programming. And proprietary
41tooling (Keil C). But we don&#39;t do that here.</p>
42
43<h3 id="Building">Building</h3>
44
45<p>Assembling and linking ARM binaries on non-ARM architecture
46devices is fairly trivial. I went along with the GNU cross
47bare metal toolchain binutils, which provides <code>arm-as</code> and
48<code>arm-ld</code> (among a bunch of other utils that I don&#39;t care
49about for now). </p>
50
51<p>Assemble <code>.s</code> files with:</p>
52
53<pre><code class="language-shell">arm-none-eabi-as main.s -g -march=armv8.1-a -o main.out
54</code></pre>
55
56<p>The <code>-g</code> flag generates extra debugging information that
57<code>gdb</code> picks up. The <code>-march</code> option establishes target
58architecture.</p>
59
60<p>Link <code>.o</code> files with:</p>
61
62<pre><code class="language-shell">arm-none-eabi-ld main.out -o main
63</code></pre>
64
65<h3 id="Running%20(and%20Debugging)">Running (and Debugging)</h3>
66
67<p>Things get interesting here. <code>gdb</code> on your x86 machine
68cannot read nor execute binaries compiled for ARM. So, we
69simulate an ARM processor using <code>qemu</code>. Now qemu allows you
70to run <code>gdbserver</code> on startup. Connecting our local <code>gdb</code>
71instance to <code>gdbserver</code> gives us a view into the program&#8217;s
72execution. Easy!</p>
73
74<p>Run <code>qemu</code>, with <code>gdbserver</code> on port <code>1234</code>, with our ARM
75binary, <code>main</code>:</p>
76
77<pre><code class="language-shell">qemu-arm -singlestep -g 1234 main
78</code></pre>
79
80<p>Start up <code>gdb</code> on your machine, and connect to <code>qemu</code>&#8217;s
81<code>gdbserver</code>:</p>
82
83<pre><code>(gdb) set architecture armv8-a
84(gdb) target remote localhost:1234
85(gdb) file main
86Reading symbols from main... # yay!
87</code></pre>
88
89<h3 id="GDB%20Enhanced">GDB Enhanced</h3>
90
91<p><code>gdb</code> is cool, but it&#39;s not nearly as comfortable as well
92fleshed out emulators&#47;IDEs like Keil. Watching registers,
93CPSR and memory chunks update <em>is</em> pretty fun. </p>
94
95<p>I came across <code>gdb</code>&#39;s TUI mode (hit <code>C-x C-a</code> or type <code>tui
96enable</code> at the prompt). TUI mode is a godsend. It highlights
97the current line of execution, shows you disassembly
98outputs, updated registers, active breakpoints and more.</p>
99
100<p><em>But</em>, it is an absolute eyesore.</p>
101
102<p>Say hello to <a href="https://github.com/hugsy/gef">GEF</a>! &#8220;GDB
103Enhanced Features&#8221; teaches our old dog some cool new tricks.
104Here are some additions that made my ARM debugging
105experience loads better:</p>
106
107<ul>
108<li>Memory watches</li>
109<li>Register watches, with up to 7 levels of deref (overkill,
110I agree)</li>
111<li>Stack tracing</li>
112</ul>
113
114<p>And its pretty! See for yourself:</p>
115
116<p><img src="https://u.peppe.rs/wq.png" alt="gef.png" /></p>
117
118<h3 id="Editing">Editing</h3>
119
120<p>Vim, with <code>syntax off</code> because it
121dosen&#39;t handle GNU ARM syntax too well.</p>
122
123 </div>
124 <div class="separator"></div>
125 <a href="/" class="post-end-link">⟵ Back</a>
126 <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/call_to_ARMs.md
127">View Raw</a>
128 </div>
129 </div>
130 </body>
131</html>