aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/call_to_ARMs/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/posts/call_to_ARMs/index.html')
-rw-r--r--docs/posts/call_to_ARMs/index.html49
1 files changed, 36 insertions, 13 deletions
diff --git a/docs/posts/call_to_ARMs/index.html b/docs/posts/call_to_ARMs/index.html
index 3331107..1b13213 100644
--- a/docs/posts/call_to_ARMs/index.html
+++ b/docs/posts/call_to_ARMs/index.html
@@ -33,7 +33,7 @@
33 <span class="stats-unit">cm</span> 33 <span class="stats-unit">cm</span>
34 &nbsp 34 &nbsp
35 <span class="stats-number"> 35 <span class="stats-number">
36 2.2 36 2.3
37 </span> 37 </span>
38 <span class="stats-unit">min</span> 38 <span class="stats-unit">min</span>
39 </div> 39 </div>
@@ -42,37 +42,60 @@
42 Call To ARMs 42 Call To ARMs
43 </h1> 43 </h1>
44 <div class="post-text"> 44 <div class="post-text">
45 <p>My 4th semester involves ARM programming. And proprietary tooling (Keil C). But we don’t do that here.</p> 45 <p>My 4th semester involves ARM programming. And proprietary tooling
46(Keil C). But we don’t do that here.</p>
46<h3 id="building">Building</h3> 47<h3 id="building">Building</h3>
47<p>Assembling and linking ARM binaries on non-ARM architecture devices is fairly trivial. I went along with the GNU cross bare metal toolchain binutils, which provides <code>arm-as</code> and <code>arm-ld</code> (among a bunch of other utils that I don’t care about for now).</p> 48<p>Assembling and linking ARM binaries on non-ARM architecture devices
49is fairly trivial. I went along with the GNU cross bare metal toolchain
50binutils, which provides <code>arm-as</code> and <code>arm-ld</code>
51(among a bunch of other utils that I don’t care about for now).</p>
48<p>Assemble <code>.s</code> files with:</p> 52<p>Assemble <code>.s</code> files with:</p>
49<pre class="shell"><code>arm-none-eabi-as main.s -g -march=armv8.1-a -o main.out</code></pre> 53<pre class="shell"><code>arm-none-eabi-as main.s -g -march=armv8.1-a -o main.out</code></pre>
50<p>The <code>-g</code> flag generates extra debugging information that <code>gdb</code> picks up. The <code>-march</code> option establishes target architecture.</p> 54<p>The <code>-g</code> flag generates extra debugging information that
55<code>gdb</code> picks up. The <code>-march</code> option establishes
56target architecture.</p>
51<p>Link <code>.o</code> files with:</p> 57<p>Link <code>.o</code> files with:</p>
52<pre class="shell"><code>arm-none-eabi-ld main.out -o main</code></pre> 58<pre class="shell"><code>arm-none-eabi-ld main.out -o main</code></pre>
53<h3 id="running-and-debugging">Running (and Debugging)</h3> 59<h3 id="running-and-debugging">Running (and Debugging)</h3>
54<p>Things get interesting here. <code>gdb</code> on your x86 machine cannot read nor execute binaries compiled for ARM. So, we simulate an ARM processor using <code>qemu</code>. Now qemu allows you to run <code>gdbserver</code> on startup. Connecting our local <code>gdb</code> instance to <code>gdbserver</code> gives us a view into the program’s execution. Easy!</p> 60<p>Things get interesting here. <code>gdb</code> on your x86 machine
55<p>Run <code>qemu</code>, with <code>gdbserver</code> on port <code>1234</code>, with our ARM binary, <code>main</code>:</p> 61cannot read nor execute binaries compiled for ARM. So, we simulate an
62ARM processor using <code>qemu</code>. Now qemu allows you to run
63<code>gdbserver</code> on startup. Connecting our local <code>gdb</code>
64instance to <code>gdbserver</code> gives us a view into the program’s
65execution. Easy!</p>
66<p>Run <code>qemu</code>, with <code>gdbserver</code> on port
67<code>1234</code>, with our ARM binary, <code>main</code>:</p>
56<pre class="shell"><code>qemu-arm -singlestep -g 1234 main</code></pre> 68<pre class="shell"><code>qemu-arm -singlestep -g 1234 main</code></pre>
57<p>Start up <code>gdb</code> on your machine, and connect to <code>qemu</code>’s <code>gdbserver</code>:</p> 69<p>Start up <code>gdb</code> on your machine, and connect to
70<code>qemu</code>’s <code>gdbserver</code>:</p>
58<pre><code>(gdb) set architecture armv8-a 71<pre><code>(gdb) set architecture armv8-a
59(gdb) target remote localhost:1234 72(gdb) target remote localhost:1234
60(gdb) file main 73(gdb) file main
61Reading symbols from main... # yay!</code></pre> 74Reading symbols from main... # yay!</code></pre>
62<h3 id="gdb-enhanced">GDB Enhanced</h3> 75<h3 id="gdb-enhanced">GDB Enhanced</h3>
63<p><code>gdb</code> is cool, but it’s not nearly as comfortable as well fleshed out emulators/IDEs like Keil. Watching registers, CPSR and memory chunks update <em>is</em> pretty fun.</p> 76<p><code>gdb</code> is cool, but it’s not nearly as comfortable as well
64<p>I came across <code>gdb</code>’s TUI mode (hit <code>C-x C-a</code> or type <code>tui enable</code> at the prompt). TUI mode is a godsend. It highlights the current line of execution, shows you disassembly outputs, updated registers, active breakpoints and more.</p> 77fleshed out emulators/IDEs like Keil. Watching registers, CPSR and
78memory chunks update <em>is</em> pretty fun.</p>
79<p>I came across <code>gdb</code>’s TUI mode (hit <code>C-x C-a</code>
80or type <code>tui enable</code> at the prompt). TUI mode is a godsend.
81It highlights the current line of execution, shows you disassembly
82outputs, updated registers, active breakpoints and more.</p>
65<p><em>But</em>, it is an absolute eyesore.</p> 83<p><em>But</em>, it is an absolute eyesore.</p>
66<p>Say hello to <a href="https://github.com/hugsy/gef">GEF</a>! “GDB Enhanced Features” teaches our old dog some cool new tricks. Here are some additions that made my ARM debugging experience loads better:</p> 84<p>Say hello to <a href="https://github.com/hugsy/gef">GEF</a>! “GDB
85Enhanced Features” teaches our old dog some cool new tricks. Here are
86some additions that made my ARM debugging experience loads better:</p>
67<ul> 87<ul>
68<li>Memory watches</li> 88<li>Memory watches</li>
69<li>Register watches, with up to 7 levels of deref (overkill, I agree)</li> 89<li>Register watches, with up to 7 levels of deref (overkill, I
90agree)</li>
70<li>Stack tracing</li> 91<li>Stack tracing</li>
71</ul> 92</ul>
72<p>And it’s pretty! See for yourself:</p> 93<p>And it’s pretty! See for yourself:</p>
73<p><a href="https://u.peppe.rs/wq.png"><img src="https://u.peppe.rs/wq.png" /></a></p> 94<p><a href="https://u.peppe.rs/wq.png"><img
95src="https://u.peppe.rs/wq.png" /></a></p>
74<h3 id="editing">Editing</h3> 96<h3 id="editing">Editing</h3>
75<p>Vim, with <code>syntax off</code> because it dosen’t handle GNU ARM syntax too well.</p> 97<p>Vim, with <code>syntax off</code> because it dosen’t handle GNU ARM
98syntax too well.</p>
76 99
77 </div> 100 </div>
78 101