diff options
author | Akshay <[email protected]> | 2020-02-09 04:54:03 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-02-09 04:54:03 +0000 |
commit | 359a92f770e621828e628f319290bb5736b1f67b (patch) | |
tree | c4c4e5168c22ac13cd62c2ee03ef1a4334aa10fc /docs/posts/call_to_ARMs | |
parent | 75c5c6044170bd6cc23502a6f40f15378269b3d1 (diff) |
new styles, new post!
Diffstat (limited to 'docs/posts/call_to_ARMs')
-rw-r--r-- | docs/posts/call_to_ARMs/index.html | 131 |
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 |   | ||
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 | ||
41 | tooling (Keil C). But we don't do that here.</p> | ||
42 | |||
43 | <h3 id="Building">Building</h3> | ||
44 | |||
45 | <p>Assembling and linking ARM binaries on non-ARM architecture | ||
46 | devices is fairly trivial. I went along with the GNU cross | ||
47 | bare metal toolchain binutils, which provides <code>arm-as</code> and | ||
48 | <code>arm-ld</code> (among a bunch of other utils that I don't care | ||
49 | about 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 | ||
58 | architecture.</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 | ||
68 | cannot read nor execute binaries compiled for ARM. So, we | ||
69 | simulate an ARM processor using <code>qemu</code>. Now qemu allows you | ||
70 | to run <code>gdbserver</code> on startup. Connecting our local <code>gdb</code> | ||
71 | instance to <code>gdbserver</code> gives us a view into the program’s | ||
72 | execution. Easy!</p> | ||
73 | |||
74 | <p>Run <code>qemu</code>, with <code>gdbserver</code> on port <code>1234</code>, with our ARM | ||
75 | binary, <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>’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 | ||
86 | Reading 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's not nearly as comfortable as well | ||
92 | fleshed out emulators/IDEs like Keil. Watching registers, | ||
93 | CPSR and memory chunks update <em>is</em> pretty fun. </p> | ||
94 | |||
95 | <p>I came across <code>gdb</code>'s TUI mode (hit <code>C-x C-a</code> or type <code>tui | ||
96 | enable</code> at the prompt). TUI mode is a godsend. It highlights | ||
97 | the current line of execution, shows you disassembly | ||
98 | outputs, 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>! “GDB | ||
103 | Enhanced Features” teaches our old dog some cool new tricks. | ||
104 | Here are some additions that made my ARM debugging | ||
105 | experience loads better:</p> | ||
106 | |||
107 | <ul> | ||
108 | <li>Memory watches</li> | ||
109 | <li>Register watches, with up to 7 levels of deref (overkill, | ||
110 | I 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 | ||
121 | dosen'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> | ||