aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/call_to_ARMs/index.html
blob: 8dfc89cbe9930c3023bfd77b8469d1dc05a80ac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="/style.css">
    <link rel="stylesheet" href="/syntax.css">
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1">
    <meta content="#ffffff" name="theme-color">
    <meta name="HandheldFriendly" content="true">
    <meta property="og:title" content="Call To ARMs">
    <meta property="og:type" content="website">
    <meta property="og:description" content="a static site {for, by, about} me ">
    <meta property="og:url" content="https://peppe.rs">
    <link rel="icon" type="image/x-icon" href="/favicon.png">
    <title>Call To ARMs · peppe.rs</title>
    <body>
      <div class="posts">
        <div class="post">
          <a href="/posts" class="post-end-link">⟵ Back</a>
          <a class="stats post-end-link" href="https://git.peppe.rs/web/site/plain/posts/call_to_ARMs.md
">View Raw</a>
          <div class="separator"></div>
          <div class="date">
            08/02 — 2020
            <div class="stats">
              <span class="stats-number">
                33.57
              </span>
              <span class="stats-unit">cm</span>
              &nbsp
              <span class="stats-number">
                2.2
              </span>
              <span class="stats-unit">min</span>
            </div>
          </div>
          <h1>
            Call To ARMs
          </h1>
          <div class="post-text">
            <p>My 4th semester involves ARM programming. And proprietary tooling (Keil C). But we don’t do that here.</p>
<h3 id="building">Building</h3>
<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>
<p>Assemble <code>.s</code> files with:</p>
<pre class="shell"><code>arm-none-eabi-as main.s -g -march=armv8.1-a -o main.out</code></pre>
<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>
<p>Link <code>.o</code> files with:</p>
<pre class="shell"><code>arm-none-eabi-ld main.out -o main</code></pre>
<h3 id="running-and-debugging">Running (and Debugging)</h3>
<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>
<p>Run <code>qemu</code>, with <code>gdbserver</code> on port <code>1234</code>, with our ARM binary, <code>main</code>:</p>
<pre class="shell"><code>qemu-arm -singlestep -g 1234 main</code></pre>
<p>Start up <code>gdb</code> on your machine, and connect to <code>qemu</code>’s <code>gdbserver</code>:</p>
<pre><code>(gdb) set architecture armv8-a
(gdb) target remote localhost:1234
(gdb) file main
Reading symbols from main...  # yay!</code></pre>
<h3 id="gdb-enhanced">GDB Enhanced</h3>
<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>
<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>
<p><em>But</em>, it is an absolute eyesore.</p>
<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>
<ul>
<li>Memory watches</li>
<li>Register watches, with up to 7 levels of deref (overkill, I agree)</li>
<li>Stack tracing</li>
</ul>
<p>And it’s pretty! See for yourself:</p>
<p><a href="https://u.peppe.rs/wq.png"><img src="https://u.peppe.rs/wq.png" /></a></p>
<h3 id="editing">Editing</h3>
<p>Vim, with <code>syntax off</code> because it dosen’t handle GNU ARM syntax too well.</p>

          </div>
          
    <div class="intro">
        Hi. 
        <div class="hot-links">
            <a href="https://peppe.rs/index.xml" class="feed-button">Subscribe</a>
            <a href="https://liberapay.com/nerdypepper/donate" class="donate-button">Donate</a>
        </div>
        <p>I'm Akshay, I go by nerd or nerdypepper on the internet.</p>
        <p>
        I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
        I write <a href="https://git.peppe.rs">open-source stuff</a> to pass time. 
        I also design fonts: 
        <a href="https://git.peppe.rs/fonts/scientifica">scientifica</a>, 
        <a href="https://git.peppe.rs/fonts/curie">curie</a>.
        </p>
        <p>Send me a mail at [email protected] or a message at [email protected].</p>
    </div>
    
          <a href="/posts" class="post-end-link">⟵ Back</a>
          <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/call_to_ARMs.md
">View Raw</a>
        </div>
      </div>
    </body>
</html>