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.html115
1 files changed, 43 insertions, 72 deletions
diff --git a/docs/posts/call_to_ARMs/index.html b/docs/posts/call_to_ARMs/index.html
index 3f759e4..578a8b7 100644
--- a/docs/posts/call_to_ARMs/index.html
+++ b/docs/posts/call_to_ARMs/index.html
@@ -37,88 +37,59 @@
37 Call To ARMs 37 Call To ARMs
38 </h1> 38 </h1>
39 <div class="post-text"> 39 <div class="post-text">
40 <p>My 4th semester involves ARM programming. And proprietary 40 <!DOCTYPE html>
41tooling (Keil C). But we don&#39;t do that here.</p> 41<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
42 42<head>
43<h3 id="Building">Building</h3> 43 <meta charset="utf-8" />
44 44 <meta name="generator" content="pandoc" />
45<p>Assembling and linking ARM binaries on non-ARM architecture 45 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
46devices is fairly trivial. I went along with the GNU cross 46 <title>call_to_ARMs</title>
47bare metal toolchain binutils, which provides <code>arm-as</code> and 47 <style>
48<code>arm-ld</code> (among a bunch of other utils that I don&#39;t care 48 code{white-space: pre-wrap;}
49about for now). </p> 49 span.smallcaps{font-variant: small-caps;}
50 50 span.underline{text-decoration: underline;}
51 div.column{display: inline-block; vertical-align: top; width: 50%;}
52 div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
53 ul.task-list{list-style: none;}
54 </style>
55 <!--[if lt IE 9]>
56 <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
57 <![endif]-->
58</head>
59<body>
60<p>My 4th semester involves ARM programming. And proprietary tooling (Keil C). But we don’t do that here.</p>
61<h3 id="building">Building</h3>
62<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>
51<p>Assemble <code>.s</code> files with:</p> 63<p>Assemble <code>.s</code> files with:</p>
52 64<pre class="shell"><code>arm-none-eabi-as main.s -g -march=armv8.1-a -o main.out</code></pre>
53<pre><code class="language-shell">arm-none-eabi-as main.s -g -march=armv8.1-a -o main.out 65<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</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> 66<p>Link <code>.o</code> files with:</p>
61 67<pre class="shell"><code>arm-none-eabi-ld main.out -o main</code></pre>
62<pre><code class="language-shell">arm-none-eabi-ld main.out -o main 68<h3 id="running-and-debugging">Running (and Debugging)</h3>
63</code></pre> 69<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>
64 70<p>Run <code>qemu</code>, with <code>gdbserver</code> on port <code>1234</code>, with our ARM binary, <code>main</code>:</p>
65<h3 id="Running%20(and%20Debugging)">Running (and Debugging)</h3> 71<pre class="shell"><code>qemu-arm -singlestep -g 1234 main</code></pre>
66 72<p>Start up <code>gdb</code> on your machine, and connect to <code>qemu</code>’s <code>gdbserver</code>:</p>
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 73<pre><code>(gdb) set architecture armv8-a
84(gdb) target remote localhost:1234 74(gdb) target remote localhost:1234
85(gdb) file main 75(gdb) file main
86Reading symbols from main... # yay! 76Reading symbols from main... # yay!</code></pre>
87</code></pre> 77<h3 id="gdb-enhanced">GDB Enhanced</h3>
88 78<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>
89<h3 id="GDB%20Enhanced">GDB Enhanced</h3> 79<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>
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> 80<p><em>But</em>, it is an absolute eyesore.</p>
101 81<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>
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> 82<ul>
108<li>Memory watches</li> 83<li>Memory watches</li>
109<li>Register watches, with up to 7 levels of deref (overkill, 84<li>Register watches, with up to 7 levels of deref (overkill, I agree)</li>
110I agree)</li>
111<li>Stack tracing</li> 85<li>Stack tracing</li>
112</ul> 86</ul>
113 87<p>And it’s pretty! See for yourself:</p>
114<p>And it&#39;s pretty! See for yourself:</p> 88<p><a href="https://u.peppe.rs/wq.png"><img src="https://u.peppe.rs/wq.png" /></a></p>
115 89<h3 id="editing">Editing</h3>
116<p><a href="https://u.peppe.rs/wq.png"><img src="https://u.peppe.rs/wq.png" alt="gef.png" /></a></p> 90<p>Vim, with <code>syntax off</code> because it dosen’t handle GNU ARM syntax too well.</p>
117 91</body>
118<h3 id="Editing">Editing</h3> 92</html>
119
120<p>Vim, with <code>syntax off</code> because it
121dosen&#39;t handle GNU ARM syntax too well.</p>
122 93
123 </div> 94 </div>
124 95