Initial commit with strict idiomatic rust enforcement

This commit is contained in:
Kevin Thomas
2023-10-06 14:27:20 -04:00
commit 8b9d2d93a1
1232 changed files with 114453 additions and 0 deletions
Binary file not shown.
+1269
View File
File diff suppressed because it is too large Load Diff
+79
View File
@@ -0,0 +1,79 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Background grid decoration -->
<g opacity="0.06">
<line x1="0" y1="100" x2="1200" y2="100" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="200" x2="1200" y2="200" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="300" x2="1200" y2="300" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="400" x2="1200" y2="400" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="500" x2="1200" y2="500" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="600" x2="1200" y2="600" stroke="#00ff41" stroke-width="1"/>
<line x1="0" y1="700" x2="1200" y2="700" stroke="#00ff41" stroke-width="1"/>
<line x1="200" y1="0" x2="200" y2="800" stroke="#00ff41" stroke-width="1"/>
<line x1="400" y1="0" x2="400" y2="800" stroke="#00ff41" stroke-width="1"/>
<line x1="600" y1="0" x2="600" y2="800" stroke="#00ff41" stroke-width="1"/>
<line x1="800" y1="0" x2="800" y2="800" stroke="#00ff41" stroke-width="1"/>
<line x1="1000" y1="0" x2="1000" y2="800" stroke="#00ff41" stroke-width="1"/>
</g>
<!-- Hex rain decoration -->
<g opacity="0.04" font-family="'Courier New',monospace" font-size="14" fill="#00ff41">
<text x="50" y="80">4F 70 65 6E 4F 43 44</text>
<text x="900" y="120">10 00 02 34 08 B5 01</text>
<text x="150" y="180">47 44 42 20 52 45 56</text>
<text x="800" y="240">20 08 20 00 FF AA 00</text>
<text x="80" y="350">52 50 32 33 35 30 00</text>
<text x="950" y="380">0A 0A 0F 12 12 1A 1A</text>
<text x="100" y="520">41 52 4D 76 38 2D 4D</text>
<text x="870" y="560">00 FF 41 00 D4 FF 88</text>
<text x="60" y="680">47 48 49 44 52 41 00</text>
<text x="920" y="720">FF 00 40 C0 C0 C0 00</text>
</g>
<!-- Corner accents -->
<polyline points="30,30 30,80 80,80" fill="none" stroke="#00ff41" stroke-width="2" opacity="0.3"/>
<polyline points="1170,30 1170,80 1120,80" fill="none" stroke="#00ff41" stroke-width="2" opacity="0.3"/>
<polyline points="30,770 30,720 80,720" fill="none" stroke="#00ff41" stroke-width="2" opacity="0.3"/>
<polyline points="1170,770 1170,720 1120,720" fill="none" stroke="#00ff41" stroke-width="2" opacity="0.3"/>
<!-- Top accent line -->
<rect x="100" y="140" width="1000" height="2" fill="#00ff41" opacity="0.4"/>
<!-- Course Title -->
<text x="600" y="210" text-anchor="middle" font-family="'Courier New',monospace" font-size="56" font-weight="bold" fill="#00ff41">Embedded Systems</text>
<text x="600" y="278" text-anchor="middle" font-family="'Courier New',monospace" font-size="56" font-weight="bold" fill="#00ff41">Reverse Engineering</text>
<!-- Divider -->
<rect x="300" y="310" width="600" height="2" fill="#00d4ff" opacity="0.6"/>
<!-- Week Number -->
<text x="600" y="380" text-anchor="middle" font-family="'Courier New',monospace" font-size="42" font-weight="bold" fill="#00d4ff">// WEEK 06</text>
<!-- Week Topic -->
<text x="600" y="440" text-anchor="middle" font-family="'Courier New',monospace" font-size="28" fill="#c0c0c0">Static Variables in Embedded Systems:</text>
<text x="600" y="478" text-anchor="middle" font-family="'Courier New',monospace" font-size="28" fill="#c0c0c0">Debugging and Hacking Static Variables</text>
<text x="600" y="516" text-anchor="middle" font-family="'Courier New',monospace" font-size="28" fill="#c0c0c0">w/ GPIO Input Basics</text>
<!-- Bottom accent line -->
<rect x="100" y="570" width="1000" height="2" fill="#00ff41" opacity="0.4"/>
<!-- University -->
<text x="600" y="635" text-anchor="middle" font-family="'Courier New',monospace" font-size="36" font-weight="bold" fill="#ffaa00">George Mason University</text>
<!-- Bottom badge -->
<rect x="400" y="670" width="400" height="40" rx="20" fill="none" stroke="#00ff41" stroke-width="1.5" opacity="0.5"/>
<text x="600" y="697" text-anchor="middle" font-family="'Courier New',monospace" font-size="20" fill="#00ff41" opacity="0.7">RP2350 // ARM Cortex-M33</text>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

+74
View File
@@ -0,0 +1,74 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">Static vs Regular Vars</text>
<text x="600" y="88" text-anchor="middle" class="dim">Persistence across loop iterations</text>
<!-- Regular Variable -->
<rect x="40" y="110" width="540" height="310" rx="8" class="pnl"/>
<text x="310" y="148" text-anchor="middle" class="sub">Regular (auto)</text>
<rect x="60" y="168" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="80" y="202" class="red">Loop 1: 42 -> 43 -> destroy</text>
<rect x="60" y="233" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="80" y="267" class="red">Loop 2: 42 -> 43 -> destroy</text>
<rect x="60" y="298" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="80" y="332" class="red">Loop 3: 42 -> 43 -> destroy</text>
<text x="60" y="393" class="txt">Always prints:</text>
<text x="340" y="393" class="red">42</text>
<!-- Static Variable -->
<rect x="620" y="110" width="540" height="310" rx="8" class="pnl"/>
<text x="890" y="148" text-anchor="middle" class="sub">Static</text>
<rect x="640" y="168" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="660" y="202" class="grn">Loop 1: 42 -> 43 (kept!)</text>
<rect x="640" y="233" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="660" y="267" class="grn">Loop 2: 43 -> 44 (kept!)</text>
<rect x="640" y="298" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="660" y="332" class="grn">Loop 3: 44 -> 45 (kept!)</text>
<text x="640" y="393" class="txt">Keeps incrementing:</text>
<text x="960" y="393" class="grn">42,43,44...</text>
<!-- Code Example -->
<rect x="40" y="440" width="1120" height="160" rx="8" class="pnl"/>
<text x="600" y="478" text-anchor="middle" class="sub">Declaration Syntax</text>
<rect x="60" y="498" width="500" height="80" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="80" y="530" class="txt">uint8_t reg = 42;</text>
<text x="80" y="558" class="dim">Recreated each iteration</text>
<rect x="620" y="498" width="520" height="80" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="640" y="530" class="grn">static uint8_t s = 42;</text>
<text x="640" y="558" class="dim">Persists for program life</text>
<!-- Overflow Note -->
<rect x="40" y="620" width="1120" height="160" rx="8" class="pnl"/>
<text x="600" y="658" text-anchor="middle" class="sub">uint8_t Overflow</text>
<text x="60" y="698" class="txt">255 + 1 =</text>
<text x="260" y="698" class="red">0</text>
<text x="320" y="698" class="dim">(wraps around!)</text>
<text x="60" y="733" class="dim">Binary: 11111111 + 1 = 100000000 (9 bits)</text>
<text x="60" y="763" class="dim">Only 8 bits kept: 00000000 = 0</text>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

+93
View File
@@ -0,0 +1,93 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">Memory Layout</text>
<text x="600" y="88" text-anchor="middle" class="dim">Where variables live in RAM</text>
<!-- Memory Diagram -->
<rect x="40" y="110" width="540" height="670" rx="8" class="pnl"/>
<text x="310" y="148" text-anchor="middle" class="sub">RP2350 SRAM Map</text>
<!-- Stack -->
<rect x="60" y="170" width="380" height="90" rx="4" fill="#ff0040" stroke="#ff0040" stroke-width="1" opacity="0.15"/>
<text x="250" y="205" text-anchor="middle" class="red">STACK (grows down)</text>
<text x="250" y="235" text-anchor="middle" class="dim">Local/auto variables</text>
<text x="455" y="210" class="dim">0x20082000</text>
<!-- Free Space -->
<rect x="60" y="270" width="380" height="100" rx="4" fill="#1a1a2e" stroke="#1a1a2e" stroke-width="1"/>
<text x="250" y="325" text-anchor="middle" class="dim">(free space)</text>
<!-- Heap -->
<rect x="60" y="380" width="380" height="90" rx="4" fill="#ffaa00" stroke="#ffaa00" stroke-width="1" opacity="0.15"/>
<text x="250" y="415" text-anchor="middle" class="amb">HEAP (grows up)</text>
<text x="250" y="445" text-anchor="middle" class="dim">malloc / free</text>
<!-- .bss -->
<rect x="60" y="480" width="380" height="90" rx="4" fill="#00d4ff" stroke="#00d4ff" stroke-width="1" opacity="0.15"/>
<text x="250" y="515" text-anchor="middle" class="cyn">.bss section</text>
<text x="250" y="545" text-anchor="middle" class="dim">Uninit static/global</text>
<!-- .data -->
<rect x="60" y="580" width="380" height="90" rx="4" fill="#00ff41" stroke="#00ff41" stroke-width="1" opacity="0.15"/>
<text x="250" y="615" text-anchor="middle" class="grn">.data section</text>
<text x="250" y="645" text-anchor="middle" class="dim">Initialized static/global</text>
<text x="455" y="650" class="dim">0x20000000</text>
<text x="60" y="730" class="dim">Static vars: .data (init)</text>
<text x="60" y="755" class="dim">Static vars: .bss (uninit)</text>
<!-- Variable Types Table -->
<rect x="620" y="110" width="540" height="390" rx="8" class="pnl"/>
<text x="890" y="148" text-anchor="middle" class="sub">Variable Storage</text>
<text x="640" y="188" class="cyn">Type</text>
<text x="880" y="188" class="cyn">Location</text>
<line x1="640" y1="198" x2="1140" y2="198" stroke="#1a1a2e" stroke-width="1"/>
<text x="640" y="228" class="txt">Automatic</text>
<text x="880" y="228" class="red">Stack</text>
<text x="640" y="258" class="txt">Static</text>
<text x="880" y="258" class="grn">.data / .bss</text>
<text x="640" y="288" class="txt">Global</text>
<text x="880" y="288" class="grn">.data / .bss</text>
<text x="640" y="318" class="txt">Dynamic</text>
<text x="880" y="318" class="amb">Heap</text>
<text x="640" y="358" class="dim">Static vars are NOT on heap!</text>
<text x="640" y="383" class="dim">Fixed location, set at compile</text>
<text x="640" y="408" class="dim">time. Lives entire program.</text>
<text x="640" y="448" class="grn">Example:</text>
<text x="640" y="473" class="dim">static_fav_num @ 0x200005A8</text>
<!-- Key Insight -->
<rect x="620" y="520" width="540" height="260" rx="8" class="pnl"/>
<text x="890" y="548" text-anchor="middle" class="sub">Key Insight</text>
<text x="640" y="588" class="txt">Stack vars:</text>
<text x="640" y="618" class="red">Created + destroyed</text>
<text x="640" y="648" class="dim">each function call</text>
<text x="640" y="693" class="txt">Static vars:</text>
<text x="640" y="723" class="grn">Fixed RAM address</text>
<text x="640" y="753" class="dim">persist entire runtime</text>
</svg>

After

Width:  |  Height:  |  Size: 4.2 KiB

+93
View File
@@ -0,0 +1,93 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">GPIO Input Basics</text>
<text x="600" y="88" text-anchor="middle" class="dim">Reading buttons with the RP2350</text>
<!-- Output vs Input -->
<rect x="40" y="110" width="540" height="200" rx="8" class="pnl"/>
<text x="310" y="148" text-anchor="middle" class="sub">OUTPUT (before)</text>
<rect x="60" y="170" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="80" y="204" class="grn">Pico GPIO 16</text>
<text x="370" y="204" class="txt">--></text>
<text x="420" y="204" class="amb">LED</text>
<text x="60" y="268" class="dim">We CONTROL the LED</text>
<text x="60" y="293" class="dim">gpio_put(pin, value)</text>
<rect x="620" y="110" width="540" height="200" rx="8" class="pnl"/>
<text x="890" y="148" text-anchor="middle" class="sub">INPUT (new!)</text>
<rect x="640" y="170" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#00d4ff" stroke-width="1"/>
<text x="660" y="204" class="cyn">Pico GPIO 15</text>
<text x="950" y="204" class="txt">&lt;--</text>
<text x="1000" y="204" class="amb">BTN</text>
<text x="640" y="268" class="dim">We READ button state</text>
<text x="640" y="293" class="dim">gpio_get(pin)</text>
<!-- Floating Input Problem -->
<rect x="40" y="330" width="540" height="200" rx="8" class="pnl"/>
<text x="310" y="368" text-anchor="middle" class="sub">Floating Input</text>
<text x="60" y="408" class="txt">No connection =</text>
<text x="60" y="438" class="red">RANDOM values!</text>
<text x="60" y="478" class="dim">Read 1: HIGH</text>
<text x="260" y="478" class="dim">Read 2: LOW</text>
<text x="60" y="503" class="dim">Read 3: HIGH</text>
<text x="260" y="503" class="dim">Read 4: HIGH</text>
<text x="440" y="503" class="dim">???</text>
<!-- Pull Resistors -->
<rect x="620" y="330" width="540" height="200" rx="8" class="pnl"/>
<text x="890" y="368" text-anchor="middle" class="sub">Pull Resistors</text>
<text x="640" y="408" class="cyn">Type</text>
<text x="840" y="408" class="cyn">Default</text>
<text x="1000" y="408" class="cyn">Pressed</text>
<line x1="640" y1="418" x2="1140" y2="418" stroke="#1a1a2e" stroke-width="1"/>
<text x="640" y="448" class="amb">Pull-Up</text>
<text x="840" y="448" class="grn">HIGH(1)</text>
<text x="1000" y="448" class="red">LOW(0)</text>
<text x="640" y="483" class="amb">Pull-Down</text>
<text x="840" y="483" class="red">LOW(0)</text>
<text x="1000" y="483" class="grn">HIGH(1)</text>
<text x="640" y="513" class="dim">Pico 2 has internal pull resistors!</text>
<!-- GPIO Functions -->
<rect x="40" y="550" width="1120" height="230" rx="8" class="pnl"/>
<text x="600" y="588" text-anchor="middle" class="sub">GPIO Input Functions</text>
<text x="60" y="628" class="grn">gpio_init(pin)</text>
<text x="500" y="628" class="dim">Initialize pin</text>
<text x="60" y="658" class="grn">gpio_set_dir(pin, GPIO_IN)</text>
<text x="500" y="658" class="dim">Set as input</text>
<text x="60" y="688" class="grn">gpio_pull_up(pin)</text>
<text x="500" y="688" class="dim">Enable pull-up</text>
<text x="60" y="718" class="grn">gpio_get(pin)</text>
<text x="500" y="718" class="dim">Read state (0 or 1)</text>
<text x="60" y="748" class="dim">No external resistor needed -- internal pull-up!</text>
</svg>

After

Width:  |  Height:  |  Size: 3.9 KiB

+99
View File
@@ -0,0 +1,99 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">Pull-Up Resistor</text>
<text x="600" y="88" text-anchor="middle" class="dim">Internal pull-up on GPIO 15</text>
<!-- Circuit Diagram -->
<rect x="40" y="110" width="540" height="370" rx="8" class="pnl"/>
<text x="310" y="148" text-anchor="middle" class="sub">Circuit</text>
<text x="160" y="195" class="amb">3.3V</text>
<line x1="195" y1="205" x2="195" y2="240" stroke="#ffaa00" stroke-width="2"/>
<rect x="175" y="240" width="40" height="60" rx="2" fill="none" stroke="#ffaa00" stroke-width="2"/>
<text x="240" y="275" class="dim">pull-up R</text>
<line x1="195" y1="300" x2="195" y2="340" stroke="#ffaa00" stroke-width="2"/>
<line x1="195" y1="340" x2="350" y2="340" stroke="#00d4ff" stroke-width="2"/>
<text x="370" y="345" class="cyn">GPIO 15</text>
<line x1="195" y1="340" x2="195" y2="380" stroke="#888" stroke-width="2"/>
<rect x="170" y="380" width="50" height="30" rx="2" fill="none" stroke="#c0c0c0" stroke-width="2"/>
<text x="240" y="400" class="dim">BTN</text>
<line x1="195" y1="410" x2="195" y2="450" stroke="#888" stroke-width="2"/>
<text x="160" y="465" class="dim">GND</text>
<!-- Logic Table -->
<rect x="620" y="110" width="540" height="200" rx="8" class="pnl"/>
<text x="890" y="148" text-anchor="middle" class="sub">Button Logic</text>
<text x="640" y="188" class="cyn">State</text>
<text x="840" y="188" class="cyn">GPIO</text>
<text x="1000" y="188" class="cyn">LED</text>
<line x1="640" y1="198" x2="1140" y2="198" stroke="#1a1a2e" stroke-width="1"/>
<text x="640" y="233" class="txt">Released</text>
<text x="840" y="233" class="grn">HIGH (1)</text>
<text x="1000" y="233" class="red">OFF</text>
<text x="640" y="268" class="txt">Pressed</text>
<text x="840" y="268" class="red">LOW (0)</text>
<text x="1000" y="268" class="grn">ON</text>
<text x="640" y="293" class="dim">Inverted! Pull-up = backwards</text>
<!-- Ternary Operator -->
<rect x="620" y="330" width="540" height="150" rx="8" class="pnl"/>
<text x="890" y="368" text-anchor="middle" class="sub">Ternary Operator</text>
<rect x="640" y="390" width="500" height="40" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="660" y="418" class="amb">gpio_put(LED, pressed?0:1);</text>
<text x="640" y="460" class="dim">pressed=1 -> LED OFF (inverted!)</text>
<!-- Wiring -->
<rect x="40" y="500" width="1120" height="280" rx="8" class="pnl"/>
<text x="600" y="538" text-anchor="middle" class="sub">Hardware Wiring</text>
<rect x="60" y="560" width="300" height="190" rx="6" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="210" y="590" text-anchor="middle" class="cyn">Pico 2</text>
<text x="80" y="625" class="grn">GPIO 15</text>
<text x="80" y="660" class="amb">GPIO 16</text>
<text x="80" y="695" class="dim">GND</text>
<text x="80" y="725" class="dim">BOOTSEL</text>
<text x="380" y="625" class="txt">--></text>
<text x="380" y="660" class="txt">--></text>
<text x="380" y="695" class="txt">--></text>
<rect x="440" y="560" width="300" height="190" rx="6" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="590" y="590" text-anchor="middle" class="amb">Components</text>
<text x="460" y="625" class="txt">Button (one leg)</text>
<text x="460" y="660" class="txt">LED + resistor</text>
<text x="460" y="695" class="txt">Button (other leg)</text>
<text x="460" y="725" class="dim">Hold to flash UF2</text>
<rect x="780" y="560" width="360" height="190" rx="6" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="960" y="590" text-anchor="middle" class="grn">Key Point</text>
<text x="800" y="625" class="txt">No external</text>
<text x="800" y="655" class="txt">resistor needed!</text>
<text x="800" y="695" class="dim">Internal pull-up</text>
<text x="800" y="720" class="dim">handles it all</text>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

+83
View File
@@ -0,0 +1,83 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">Source Code</text>
<text x="600" y="88" text-anchor="middle" class="dim">0x0014_static-variables.c</text>
<!-- Code Panel -->
<rect x="40" y="110" width="700" height="510" rx="8" class="pnl"/>
<text x="390" y="148" text-anchor="middle" class="sub">main()</text>
<rect x="60" y="168" width="660" height="440" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="80" y="198" class="cyn">int main(void) {</text>
<text x="110" y="226" class="txt">stdio_init_all();</text>
<text x="110" y="254" class="dim">// GPIO setup</text>
<text x="110" y="282" class="txt">gpio_init(15);</text>
<text x="110" y="310" class="txt">gpio_set_dir(15, GPIO_IN);</text>
<text x="110" y="338" class="amb">gpio_pull_up(15);</text>
<text x="110" y="366" class="txt">gpio_init(16);</text>
<text x="110" y="394" class="txt">gpio_set_dir(16, GPIO_OUT);</text>
<text x="110" y="430" class="cyn">while (true) {</text>
<text x="140" y="458" class="txt">uint8_t reg = 42;</text>
<text x="140" y="486" class="grn">static uint8_t s = 42;</text>
<text x="140" y="514" class="txt">printf(... reg, s);</text>
<text x="140" y="542" class="red">reg++; s++;</text>
<text x="110" y="570" class="cyn">}</text>
<text x="80" y="590" class="cyn">}</text>
<!-- Annotations -->
<rect x="780" y="110" width="380" height="180" rx="8" class="pnl"/>
<text x="970" y="148" text-anchor="middle" class="sub">GPIO Setup</text>
<text x="800" y="183" class="grn">Pin 15:</text>
<text x="920" y="183" class="txt">Input</text>
<text x="800" y="213" class="dim">Pull-up enabled</text>
<text x="800" y="248" class="amb">Pin 16:</text>
<text x="920" y="248" class="txt">Output</text>
<text x="800" y="268" class="dim">LED control</text>
<!-- Serial Output -->
<rect x="780" y="310" width="380" height="200" rx="8" class="pnl"/>
<text x="970" y="348" text-anchor="middle" class="sub">Serial Output</text>
<rect x="800" y="370" width="340" height="115" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="820" y="397" class="txt">reg: 42</text>
<text x="820" y="422" class="txt">s: 42</text>
<text x="820" y="447" class="txt">reg: 42</text>
<text x="820" y="472" class="grn">s: 43</text>
<text x="800" y="498" class="dim">reg always 42, s grows</text>
<!-- Button Logic -->
<rect x="780" y="530" width="380" height="90" rx="8" class="pnl"/>
<text x="970" y="565" text-anchor="middle" class="sub">Button Logic</text>
<text x="800" y="598" class="dim">pressed = gpio_get(15);</text>
<!-- Key -->
<rect x="40" y="640" width="1120" height="140" rx="8" class="pnl"/>
<text x="600" y="678" text-anchor="middle" class="sub">Key Behaviors</text>
<rect x="60" y="698" width="340" height="55" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="230" y="730" text-anchor="middle" class="red">reg: always 42</text>
<rect x="420" y="698" width="340" height="55" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="590" y="730" text-anchor="middle" class="grn">s: 42,43,44...</text>
<rect x="780" y="698" width="360" height="55" rx="4" fill="#0a0a0f" stroke="#ffaa00" stroke-width="1"/>
<text x="960" y="730" text-anchor="middle" class="amb">wraps at 255->0</text>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

+65
View File
@@ -0,0 +1,65 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">Compiler Optimizations</text>
<text x="600" y="88" text-anchor="middle" class="dim">What the compiler does to your code</text>
<!-- Optimization 1: Regular var removed -->
<rect x="40" y="110" width="1120" height="220" rx="8" class="pnl"/>
<text x="600" y="148" text-anchor="middle" class="sub">Optimization 1: Dead Code Removal</text>
<rect x="60" y="170" width="500" height="135" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="80" y="200" class="red">Your code:</text>
<text x="80" y="230" class="txt">uint8_t reg = 42;</text>
<text x="80" y="260" class="txt">reg++;</text>
<text x="80" y="285" class="dim">// No lasting effect!</text>
<rect x="620" y="170" width="520" height="135" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="640" y="200" class="grn">Compiler output:</text>
<text x="640" y="230" class="amb">movs r1, #42</text>
<text x="640" y="260" class="dim">// reg++ is GONE</text>
<text x="640" y="285" class="dim">// Uses constant 42 directly</text>
<!-- Optimization 2: Function Inlining -->
<rect x="40" y="350" width="1120" height="200" rx="8" class="pnl"/>
<text x="600" y="388" text-anchor="middle" class="sub">Optimization 2: Function Inlining</text>
<rect x="60" y="410" width="500" height="110" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="80" y="440" class="red">Your code:</text>
<text x="80" y="470" class="txt">gpio_pull_up(15);</text>
<text x="80" y="500" class="dim">// Simple wrapper func</text>
<rect x="620" y="410" width="520" height="110" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="640" y="440" class="grn">Compiler output:</text>
<text x="640" y="470" class="amb">gpio_set_pulls(15,1,0);</text>
<text x="640" y="500" class="dim">// Inlined to real func</text>
<!-- Optimization 3: Instruction Scheduling -->
<rect x="40" y="570" width="1120" height="210" rx="8" class="pnl"/>
<text x="600" y="608" text-anchor="middle" class="sub">Optimization 3: Scheduling</text>
<text x="60" y="648" class="txt">Compiler reorders instructions</text>
<text x="60" y="678" class="txt">to avoid pipeline stalls:</text>
<rect x="60" y="698" width="340" height="55" rx="4" fill="#0a0a0f" stroke="#00d4ff" stroke-width="1"/>
<text x="230" y="732" text-anchor="middle" class="cyn">Load SIO base</text>
<rect x="420" y="698" width="340" height="55" rx="4" fill="#0a0a0f" stroke="#ffaa00" stroke-width="1"/>
<text x="590" y="732" text-anchor="middle" class="amb">Increment s</text>
<rect x="780" y="698" width="340" height="55" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="950" y="732" text-anchor="middle" class="grn">Read GPIO</text>
</svg>

After

Width:  |  Height:  |  Size: 3.4 KiB

+90
View File
@@ -0,0 +1,90 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">Assembly Analysis</text>
<text x="600" y="88" text-anchor="middle" class="dim">Key instructions in main() loop</text>
<!-- Assembly Listing -->
<rect x="40" y="110" width="700" height="490" rx="8" class="pnl"/>
<text x="390" y="148" text-anchor="middle" class="sub">Loop Body (0x10000264)</text>
<rect x="60" y="168" width="660" height="410" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="80" y="196" class="cyn">movs r1, #0x2a</text>
<text x="420" y="196" class="dim">; reg=42</text>
<text x="80" y="226" class="txt">bl __wrap_printf</text>
<text x="420" y="226" class="dim">; print reg</text>
<text x="80" y="256" class="amb">ldrb r1, [r4]</text>
<text x="420" y="256" class="dim">; load static</text>
<text x="80" y="286" class="txt">bl __wrap_printf</text>
<text x="420" y="286" class="dim">; print s</text>
<text x="80" y="316" class="red">mov.w r1, #0xd0000000</text>
<text x="420" y="316" class="dim">; SIO base</text>
<text x="80" y="346" class="amb">ldrb r3, [r4]</text>
<text x="420" y="346" class="dim">; reload s</text>
<text x="80" y="376" class="grn">adds r3, #1</text>
<text x="420" y="376" class="dim">; s++</text>
<text x="80" y="406" class="grn">strb r3, [r4]</text>
<text x="420" y="406" class="dim">; store s</text>
<text x="80" y="436" class="cyn">ldr r3, [r1, #4]</text>
<text x="420" y="436" class="dim">; read GPIO</text>
<text x="80" y="466" class="cyn">ubfx r3, r3, #15, #1</text>
<text x="420" y="466" class="dim">; bit 15</text>
<text x="80" y="496" class="red">eor.w r3, r3, #1</text>
<text x="420" y="496" class="dim">; invert</text>
<text x="80" y="526" class="amb">mcrr 0, 4, r2, r3, cr0</text>
<text x="420" y="526" class="dim">; GPIO out</text>
<text x="80" y="556" class="cyn">b.n 0x10000264</text>
<text x="420" y="556" class="dim">; loop</text>
<!-- Key Registers -->
<rect x="780" y="110" width="380" height="220" rx="8" class="pnl"/>
<text x="970" y="148" text-anchor="middle" class="sub">Key Registers</text>
<text x="800" y="188" class="cyn">r1:</text>
<text x="860" y="188" class="txt">printf arg</text>
<text x="800" y="223" class="amb">r3:</text>
<text x="860" y="223" class="txt">temp / static</text>
<text x="800" y="258" class="grn">r4:</text>
<text x="860" y="258" class="txt">0x200005a8</text>
<text x="800" y="283" class="dim">(static var addr)</text>
<text x="800" y="308" class="red">r2:</text>
<text x="860" y="308" class="txt">LED pin (16)</text>
<!-- Key Instructions -->
<rect x="780" y="350" width="380" height="250" rx="8" class="pnl"/>
<text x="970" y="388" text-anchor="middle" class="sub">Key Patterns</text>
<text x="800" y="428" class="grn">ldrb/adds/strb</text>
<text x="800" y="453" class="dim">Load-increment-store</text>
<text x="800" y="478" class="dim">(static var update)</text>
<text x="800" y="518" class="cyn">ubfx #15, #1</text>
<text x="800" y="543" class="dim">Extract GPIO bit 15</text>
<text x="800" y="573" class="red">eor.w #1</text>
<text x="800" y="598" class="dim">Inverts (? 0 : 1)</text>
<!-- Infinite Loop -->
<rect x="40" y="620" width="1120" height="160" rx="8" class="pnl"/>
<text x="600" y="658" text-anchor="middle" class="sub">Infinite Loop</text>
<rect x="60" y="680" width="400" height="70" rx="4" fill="#0a0a0f" stroke="#00d4ff" stroke-width="1"/>
<text x="80" y="715" class="cyn">b.n 0x10000264</text>
<text x="80" y="738" class="dim">; while(true)</text>
<text x="500" y="715" class="txt">No pop/bx lr</text>
<text x="500" y="745" class="dim">main() never returns</text>
</svg>

After

Width:  |  Height:  |  Size: 4.2 KiB

+75
View File
@@ -0,0 +1,75 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">GDB: Static Variable</text>
<text x="600" y="88" text-anchor="middle" class="dim">Finding static_fav_num in RAM</text>
<!-- Literal Pool -->
<rect x="40" y="110" width="1120" height="200" rx="8" class="pnl"/>
<text x="600" y="148" text-anchor="middle" class="sub">Literal Pool Lookup</text>
<rect x="60" y="170" width="700" height="48" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="80" y="200" class="cyn">ldr r4, [pc, #44]</text>
<text x="400" y="200" class="dim">@ 0x10000290</text>
<text x="60" y="248" class="txt">Examine literal pool:</text>
<rect x="60" y="258" width="700" height="30" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="80" y="282" class="grn">x/1wx 0x10000290 = 0x200005A8</text>
<text x="790" y="248" class="amb">r4 now holds the</text>
<text x="790" y="278" class="amb">RAM address of</text>
<text x="790" y="298" class="grn">static_fav_num!</text>
<!-- Examining the Variable -->
<rect x="40" y="330" width="540" height="220" rx="8" class="pnl"/>
<text x="310" y="368" text-anchor="middle" class="sub">Read Value</text>
<rect x="60" y="390" width="500" height="40" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="80" y="418" class="grn">x/1db 0x200005a8 = 42</text>
<text x="60" y="458" class="dim">After one loop iteration:</text>
<rect x="60" y="468" width="500" height="40" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="80" y="496" class="amb">x/1db 0x200005a8 = 43</text>
<text x="60" y="536" class="dim">It incremented! Persists in RAM.</text>
<!-- Disasm Gotcha -->
<rect x="620" y="330" width="540" height="220" rx="8" class="pnl"/>
<text x="890" y="368" text-anchor="middle" class="sub">Disasm Gotcha</text>
<text x="640" y="408" class="txt">x/i 0x10000290 shows:</text>
<rect x="640" y="425" width="500" height="40" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="660" y="453" class="red">lsls r0, r5, #22</text>
<text x="640" y="493" class="dim">GDB decodes DATA as code!</text>
<text x="640" y="518" class="dim">Bytes A8 05 00 20 = 0x200005A8</text>
<text x="640" y="538" class="dim">Use x/wx not x/i for data</text>
<!-- GPIO Register -->
<rect x="40" y="570" width="1120" height="210" rx="8" class="pnl"/>
<text x="600" y="608" text-anchor="middle" class="sub">GPIO Input Register</text>
<text x="60" y="648" class="txt">Read button state in GDB:</text>
<rect x="60" y="668" width="700" height="40" rx="4" fill="#0a0a0f" stroke="#1a1a2e" stroke-width="1"/>
<text x="80" y="696" class="grn">p/x (*(uint*)0xd0000004 >> 15) &amp; 1</text>
<text x="60" y="738" class="cyn">Returns 1:</text>
<text x="260" y="738" class="dim">not pressed (pull-up)</text>
<text x="60" y="758" class="amb">Returns 0:</text>
<text x="260" y="758" class="dim">button pressed</text>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

+63
View File
@@ -0,0 +1,63 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">Hacking the Binary</text>
<text x="600" y="88" text-anchor="middle" class="dim">Two patches with a hex editor</text>
<!-- Offset Formula -->
<rect x="40" y="110" width="1120" height="100" rx="8" class="pnl"/>
<text x="600" y="148" text-anchor="middle" class="sub">File Offset Formula</text>
<text x="60" y="188" class="grn">offset = address - 0x10000000</text>
<text x="600" y="188" class="dim">Example: 0x10000264 -> 0x264</text>
<!-- Hack 1 -->
<rect x="40" y="230" width="1120" height="240" rx="8" class="pnl"/>
<text x="600" y="268" text-anchor="middle" class="sub">Hack 1: Change 42 to 43</text>
<text x="60" y="308" class="txt">Target: movs r1, #0x2a</text>
<text x="60" y="338" class="dim">at address 0x10000264 (offset 0x264)</text>
<rect x="60" y="358" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="80" y="393" class="red">Before: 2A 21</text>
<text x="310" y="393" class="dim">movs r1, #42</text>
<rect x="620" y="358" width="520" height="55" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="640" y="393" class="grn">After: 2B 21</text>
<text x="880" y="393" class="dim">movs r1, #43</text>
<text x="60" y="443" class="dim">Thumb encoding: imm8 byte first, opcode 0x21 second</text>
<!-- Hack 2 -->
<rect x="40" y="490" width="1120" height="290" rx="8" class="pnl"/>
<text x="600" y="528" text-anchor="middle" class="sub">Hack 2: Invert Button Logic</text>
<text x="60" y="568" class="txt">Target: eor.w r3, r3, #1</text>
<text x="60" y="598" class="dim">at address 0x10000286 (offset 0x286)</text>
<rect x="60" y="618" width="500" height="55" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="80" y="653" class="red">Before: 83 F0 01 03</text>
<rect x="620" y="618" width="520" height="55" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="640" y="653" class="grn">After: 83 F0 00 03</text>
<text x="60" y="703" class="dim">Byte at offset 0x288:</text>
<text x="380" y="703" class="red">01</text>
<text x="430" y="703" class="txt">-></text>
<text x="470" y="703" class="grn">00</text>
<text x="60" y="738" class="txt">XOR with 0 = no invert</text>
<text x="60" y="758" class="dim">LED now ON by default, OFF when pressed</text>
</svg>

After

Width:  |  Height:  |  Size: 3.0 KiB

+112
View File
@@ -0,0 +1,112 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<!-- Title -->
<text x="600" y="52" text-anchor="middle" class="title">Static Vars &amp; GPIO Input</text>
<text x="600" y="88" text-anchor="middle" class="dim">Static variables, GPIO input, hacking</text>
<!-- Static vs Auto Table -->
<rect x="40" y="110" width="540" height="300" rx="8" class="pnl"/>
<text x="310" y="148" text-anchor="middle" class="sub">Static vs Auto</text>
<text x="60" y="188" class="cyn">Aspect</text>
<text x="260" y="188" class="red">Auto</text>
<text x="420" y="188" class="grn">Static</text>
<line x1="60" y1="198" x2="560" y2="198" stroke="#1a1a2e" stroke-width="1"/>
<text x="60" y="228" class="txt">Where</text>
<text x="260" y="228" class="red">Stack</text>
<text x="420" y="228" class="grn">.data</text>
<text x="60" y="258" class="txt">Life</text>
<text x="260" y="258" class="red">Scope</text>
<text x="420" y="258" class="grn">Forever</text>
<text x="60" y="288" class="txt">Init</text>
<text x="260" y="288" class="red">Every</text>
<text x="420" y="288" class="grn">Once</text>
<text x="60" y="318" class="txt">Keeps?</text>
<text x="260" y="318" class="red">No</text>
<text x="420" y="318" class="grn">Yes</text>
<text x="60" y="348" class="txt">Optimized?</text>
<text x="260" y="348" class="red">Often</text>
<text x="420" y="348" class="grn">In RAM</text>
<text x="60" y="388" class="dim">Compiler may remove auto vars</text>
<!-- GPIO Input -->
<rect x="620" y="110" width="540" height="300" rx="8" class="pnl"/>
<text x="890" y="148" text-anchor="middle" class="sub">GPIO Input Setup</text>
<text x="640" y="188" class="grn">1.</text>
<text x="680" y="188" class="txt">gpio_init(pin)</text>
<text x="640" y="223" class="grn">2.</text>
<text x="680" y="223" class="txt">gpio_set_dir(pin, GPIO_IN)</text>
<text x="640" y="258" class="grn">3.</text>
<text x="680" y="258" class="txt">gpio_pull_up(pin)</text>
<text x="640" y="293" class="grn">4.</text>
<text x="680" y="293" class="txt">gpio_get(pin)</text>
<text x="640" y="338" class="dim">Pull-up: released=HIGH</text>
<text x="640" y="363" class="dim">pressed=LOW (inverted!)</text>
<text x="640" y="388" class="dim">Internal R, no hardware</text>
<!-- Key Assembly -->
<rect x="40" y="430" width="540" height="200" rx="8" class="pnl"/>
<text x="310" y="468" text-anchor="middle" class="sub">Key Instructions</text>
<text x="60" y="508" class="amb">ubfx r3,r3,#15,#1</text>
<text x="60" y="533" class="dim">Extract single GPIO bit</text>
<text x="60" y="568" class="red">eor.w r3,r3,#1</text>
<text x="60" y="593" class="dim">XOR to invert logic</text>
<text x="60" y="618" class="cyn">b.n 0x10000264</text>
<!-- Hacking Workflow -->
<rect x="620" y="430" width="540" height="200" rx="8" class="pnl"/>
<text x="890" y="468" text-anchor="middle" class="sub">Hacking Workflow</text>
<text x="640" y="508" class="grn">1.</text>
<text x="680" y="508" class="txt">Analyze in GDB</text>
<text x="640" y="538" class="grn">2.</text>
<text x="680" y="538" class="txt">Calculate offset</text>
<text x="640" y="568" class="grn">3.</text>
<text x="680" y="568" class="txt">Patch .bin in HxD</text>
<text x="640" y="598" class="grn">4.</text>
<text x="680" y="598" class="txt">uf2conv.py + flash</text>
<!-- Key Takeaways -->
<rect x="40" y="650" width="1120" height="130" rx="8" class="pnl"/>
<text x="600" y="688" text-anchor="middle" class="sub">Takeaways</text>
<rect x="60" y="708" width="340" height="50" rx="4" fill="#0a0a0f" stroke="#ff0040" stroke-width="1"/>
<text x="230" y="740" text-anchor="middle" class="red">42 -> 43 (1 byte)</text>
<rect x="420" y="708" width="340" height="50" rx="4" fill="#0a0a0f" stroke="#00ff41" stroke-width="1"/>
<text x="590" y="740" text-anchor="middle" class="grn">XOR 1->0 (invert)</text>
<rect x="780" y="708" width="360" height="50" rx="4" fill="#0a0a0f" stroke="#ffaa00" stroke-width="1"/>
<text x="960" y="740" text-anchor="middle" class="amb">offset = addr - base</text>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB