<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>fawn.rest - rust</title>
    <subtitle>notes, journal entries, and other things</subtitle>
    <link rel="self" type="application/atom+xml" href="https://fawn.rest/tags/rust/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://fawn.rest"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-11-22T00:00:00+00:00</updated>
    <id>https://fawn.rest/tags/rust/atom.xml</id>
    <entry xml:lang="en">
        <title>crossing the boundary, part 1: freestanding kernel</title>
        <published>2026-11-22T00:00:00+00:00</published>
        <updated>2026-11-22T00:00:00+00:00</updated>
        
        <author>
          <name>Saoirse Josetta</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://fawn.rest/journal/crossing-the-boundary-1/"/>
        <id>https://fawn.rest/journal/crossing-the-boundary-1/</id>
        
        <content type="html" xml:base="https://fawn.rest/journal/crossing-the-boundary-1/">&lt;p&gt;hello again! a little while ago i promised a tutorial series in my &lt;a href=&quot;https://fawn.rest/journal/first-entry/&quot;&gt;first entry&lt;/a&gt;, and here it is, not a short time later.&lt;/p&gt;
&lt;p&gt;when i started getting into OS development with rust, i read every tutorial i could find. there are so &lt;em&gt;many&lt;/em&gt; amazing tutorials out there, but hardly any of them actually cross into &lt;strong&gt;userspace&lt;/strong&gt;, the part where your kernel can become an OS.&lt;/p&gt;
&lt;p&gt;that’s what &lt;strong&gt;crossing the boundary&lt;/strong&gt; is about. we are gonna write a kernel in rust from nothing, and the finish line is dropping into ring 3, running a userspace program, and then having that program call back into the kernel.&lt;/p&gt;
&lt;p&gt;this chapter will take you from a blank slate, to a minimal kernel that can boot and say hello to you!&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;multiboot info @ 0x2db660..0x2dbd00&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  bootloader    GRUB 2.12&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  command line  &amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  memory map&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x000000000000..0x00000009fc00  Available&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x00000009fc00..0x0000000a0000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x0000000f0000..0x000000100000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x000000100000..0x000007fe0000  Available&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x000007fe0000..0x000008000000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x0000fffc0000..0x000100000000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x00fd00000000..0x010000000000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;hello from the kernel! chapter 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;if you get stuck, the finished code for this chapter page will be hosted on my &lt;a rel=&quot;external&quot; href=&quot;https://git.fawn.rest/fawn/crossing-the-boundary&quot;&gt;Forgejo instance&lt;/a&gt; if you need some help.&lt;/p&gt;
&lt;h2 id=&quot;what-you-ll-need&quot;&gt;what you’ll need&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https://rustup.rs&quot;&gt;&lt;code&gt;rustup&lt;/code&gt;&lt;/a&gt; (each chapter has a rust-toolchain.toml)&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https://just.systems&quot;&gt;&lt;code&gt;just&lt;/code&gt;&lt;/a&gt;, for running the build recipes&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nasm&lt;/code&gt;, for assembling the boot code&lt;/li&gt;
&lt;li&gt;GNU &lt;code&gt;ld&lt;/code&gt; (binutils)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;qemu-system-x86_64&lt;/code&gt;, for running the kernel in a virtual machine&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grub-mkrescue/grub2-mkrescue&lt;/code&gt;, &lt;code&gt;xorriso&lt;/code&gt;, &lt;code&gt;mtools&lt;/code&gt; for creating a bootable ISO with GRUB&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;shellscript&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; install rustup&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;curl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-proto&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;=https&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-tlsv1.2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;sSf&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; https://sh.rustup.rs&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; sh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; fedora&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; dnf&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; just&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; nasm&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; binutils&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; qemu-system-x86&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; xorriso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; mtools&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; grub2-tools-extra&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; grub2-pc-modules&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; debian 13+ or ubuntu 24.04+&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; apt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; just&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; nasm&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; binutils&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; qemu-system-x86&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; xorriso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; mtools&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; grub-pc-bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; grub-common&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;setting-up-the-scaffold&quot;&gt;setting up the scaffold&lt;/h2&gt;
&lt;p&gt;create the project and cd into it!&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;shellscript&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;mkdir&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; freestanding&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; &amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; cd&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; freestanding&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;mkdir&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; .cargo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; kernel/src/{log,drivers/serial,arch/x86_64/{cpu,boot}}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the project is a Cargo workspace with just one member for now, &lt;code&gt;kernel/&lt;/code&gt;. don’t worry, it won’t be lonely for too long.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Cargo.toml&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;toml&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;workspace&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;resolver&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;members&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;kernel&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;workspace&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;package&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;version&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.1.0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;edition&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;2024&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;license&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;MIT&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;publish&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;workspace&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;lints&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;rust&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;unsafe_op_in_unsafe_fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;deny&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;workspace&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;lints&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;clippy&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;undocumented_unsafe_blocks&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;warn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;profile&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;dev&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;panic&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;abort&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;profile&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;release&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;panic&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;abort&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;debug&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this goes in the root of the project. &lt;code&gt;[workspace.package]&lt;/code&gt; holds settings every crate in the workspace can inherit, so you don’t have to repeat them in each crate’s &lt;code&gt;Cargo.toml&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;a kernel has a &lt;em&gt;lot&lt;/em&gt; of &lt;code&gt;unsafe&lt;/code&gt;, so the lints keep us honest:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;unsafe_op_in_unsafe_fn&lt;/code&gt;&lt;/strong&gt; means that even inside an &lt;code&gt;unsafe fn&lt;/code&gt;, every unsafe operation must be marked with an &lt;code&gt;unsafe { ... }&lt;/code&gt; block.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;undocumented_unsafe_blocks&lt;/code&gt;&lt;/strong&gt; warns if an &lt;code&gt;unsafe&lt;/code&gt; block is not documented with a &lt;code&gt;// SAFETY: ...&lt;/code&gt; comment explaining why it’s safe.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;panic = &quot;abort&quot;&lt;/code&gt; turns off &lt;strong&gt;unwinding&lt;/strong&gt;. normally, a panic walks back up the stack, running destructors along the way, but that needs support from the runtime. in a freestanding kernel, we don’t have that, so we just abort immediately on panic.&lt;/p&gt;
&lt;p&gt;next, let’s set up the &lt;code&gt;kernel/Cargo.toml&lt;/code&gt; file for our kernel project.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/Cargo.toml&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;toml&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;package&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;kernel&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;version&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;.&lt;/span&gt;&lt;span&gt;workspace&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;edition&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;.&lt;/span&gt;&lt;span&gt;workspace&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;license&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;.&lt;/span&gt;&lt;span&gt;workspace&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;publish&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;.&lt;/span&gt;&lt;span&gt;workspace&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;lib&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;crate-type&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;staticlib&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;dependencies&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;spin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span&gt; version&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.12&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; default-features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;spin_mutex&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;target&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;&amp;#39;cfg(target_arch&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &amp;quot;x86_64&amp;quot;)&amp;#39;&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;dependencies&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;multiboot2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span&gt; version&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.23&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; default-features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span&gt; version&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.15.5&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; default-features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;instructions&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;lints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;workspace&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the kernel is a &lt;strong&gt;static library&lt;/strong&gt; (&lt;code&gt;staticlib&lt;/code&gt;), not a binary. cargo compiles our rust into &lt;code&gt;libkernel.a&lt;/code&gt;, and we link that with the boot assembly. that gives us full control over where every byte ends up, which we’ll need for the higher half.&lt;/p&gt;
&lt;p&gt;the &lt;code&gt;test&lt;/code&gt; feature doesn’t enable anything by itself. it’s a switch: building with &lt;code&gt;--features test&lt;/code&gt; runs the test harness, which we’ll set up at the end.&lt;/p&gt;
&lt;p&gt;for now, we only need 3 dependencies:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;external&quot; href=&quot;https://crates.io/crates/spin&quot;&gt;&lt;code&gt;spin&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; provides a spinlock &lt;code&gt;Mutex&lt;/code&gt;, since we don’t have access to &lt;code&gt;std::sync&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;external&quot; href=&quot;https://crates.io/crates/multiboot2&quot;&gt;&lt;code&gt;multiboot2&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; parses the boot information GRUB hands us&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;external&quot; href=&quot;https://crates.io/crates/x86_64&quot;&gt;&lt;code&gt;x86_64&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; will be extremely useful for working with x86_64-specific instructions, structures, and paging. for now, it wraps CPU instructions like &lt;code&gt;hlt&lt;/code&gt;, &lt;code&gt;cli&lt;/code&gt;, and port I/O, so we don’t have to write inline assembly.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;all three have &lt;code&gt;default-features = false&lt;/code&gt;, because default features often assume &lt;code&gt;std&lt;/code&gt; or an allocator, and we have neither. the last two only get pulled in when building for &lt;code&gt;x86_64&lt;/code&gt;, since they’re x86-specific.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[lints] workspace = true&lt;/code&gt; tells this crate to use the workspace’s lints. don’t skip it: without it, the lints we set up a moment ago silently do nothing!&lt;/p&gt;
&lt;p&gt;now, create a new file in your project: &lt;code&gt;rust-toolchain.toml&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;toml&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;toolchain&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;channel&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;nightly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;components&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;rust-src&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;rustfmt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;clippy&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;llvm-tools&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;targets&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;x86_64-unknown-none&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;profile&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;minimal&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;rustup reads &lt;code&gt;rust-toolchain.toml&lt;/code&gt; automatically, so anyone who builds the project gets the same toolchain without having to manually install or select it.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;nightly&lt;/code&gt;&lt;/strong&gt;: kernel development often requires unstable rust features sooner or later&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;rust-src&lt;/code&gt;&lt;/strong&gt;: the source code of the standard library, which tools like rust-analyzer use to look inside &lt;code&gt;core&lt;/code&gt;. &lt;strong&gt;&lt;code&gt;rustfmt&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;clippy&lt;/code&gt;&lt;/strong&gt; are the formatter and linter, and &lt;strong&gt;&lt;code&gt;llvm-tools&lt;/code&gt;&lt;/strong&gt; gives us tools for inspecting the binaries we build.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;targets&lt;/code&gt;&lt;/strong&gt;: specifies the target triple(s) we want to build for, in this case &lt;code&gt;x86_64-unknown-none&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;profile&lt;/code&gt;&lt;/strong&gt;: selects the toolchain profile, &lt;code&gt;minimal&lt;/code&gt; installs only the essential components, skipping things we don’t need, like offline docs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;now, put this in the .cargo directory as &lt;code&gt;config.toml&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;toml&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;build&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;x86_64-unknown-none&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;target&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;x86_64-unknown-none&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rustflags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-C&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;force-frame-pointers=yes&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;setting the default target means we don’t have to pass &lt;code&gt;--target x86_64-unknown-none&lt;/code&gt; to every cargo command. it also ensures that all dependencies are built for the correct target automatically.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;force-frame-pointers&lt;/code&gt; makes every function keep a pointer to its caller’s stack frame in &lt;code&gt;rbp&lt;/code&gt;. that forms a chain we can walk later to print &lt;strong&gt;backtraces&lt;/strong&gt; when something goes wrong, which is also why &lt;code&gt;boot.asm&lt;/code&gt; zeroes &lt;code&gt;rbp&lt;/code&gt; before calling into rust: it marks the end of the chain.&lt;/p&gt;
&lt;h2 id=&quot;booting-into-64-bit-mode&quot;&gt;booting into 64-bit mode&lt;/h2&gt;
&lt;p&gt;before we write any boot code, we need to decide where our kernel lives in memory.&lt;/p&gt;
&lt;p&gt;we want a &lt;strong&gt;higher-half kernel&lt;/strong&gt;. every program on &lt;code&gt;x86_64&lt;/code&gt; sees its own huge virtual address space, and we put the kernel at the very top of it, at &lt;code&gt;0xFFFFFFFF80000000&lt;/code&gt;, the last 2 GiB. the bottom half stays free for userspace programs later, so they can use whatever addresses they like without bumping into the kernel!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;rust’s &lt;code&gt;x86_64-unknown-none&lt;/code&gt; target expects this too: it compiles code assuming it lives in the higher-half of the address space.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;the catch: GRUB doesn’t know any of this. it loads our kernel at 1 MiB in physical memory with paging off, so those high addresses are not yet valid. the kernel has to be &lt;strong&gt;linked&lt;/strong&gt; to run in the higher-half, but it’s loaded low:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             virtual address           physical address&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;kernel   ──► 0xFFFFFFFF80100000 ──┐&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                                  ├──► 0x00100000, 1 MiB&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;boot     ──► 0x0000000000100000 ──┘&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;the-linker-deciding-memory-layout&quot;&gt;the linker: deciding memory layout&lt;/h3&gt;
&lt;p&gt;the linker script is how we tell the linker about those addresses.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/x86_64/boot/linker.ld&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ENTRY(start)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;/*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; * base virtual address of the higher-half kernel: the top 2 GB of the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; * 64-bit address space (-2 GiB, sign-extended)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;KERNEL_VMA = 0xFFFFFFFF80000000;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SECTIONS {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    . = 1M;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .boot :&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        /*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;         * the multiboot2 header goes first, because GRUB only looks for&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;         * it in the first 32 KiB of the image, 8-byte aligned. KEEP stops&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;         * --gc-sections from dropping it, since nothing references it&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        KEEP(*(.multiboot_header))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.boot.text)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.boot.rodata)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .boot.bss :&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.boot.bss)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    . = ALIGN(4K) + KERNEL_VMA;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .text : AT(ADDR(.text) - KERNEL_VMA)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.text .text.*)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    . = ALIGN(4K);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .rodata : AT(ADDR(.rodata) - KERNEL_VMA)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.rodata .rodata.*)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .tests : AT(ADDR(.tests) - KERNEL_VMA)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        . = ALIGN(8);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        __tests_start = .;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        KEEP(*(.tests))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        __tests_end = .;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    . = ALIGN(4K);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .data : AT(ADDR(.data) - KERNEL_VMA)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.data .data.*)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.got .got.plt)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    . = ALIGN(4K);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .bss : AT(ADDR(.bss) - KERNEL_VMA)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        *(.bss .bss.*)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;there are two halves to consider:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;boot sections&lt;/strong&gt; are sitting at 1 MiB, and they’re linked &lt;em&gt;and&lt;/em&gt; loaded there. this is the code that runs before we jump to the higher-half.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;higher-half&lt;/strong&gt; is linked at &lt;code&gt;KERNEL_VMA&lt;/code&gt;, but &lt;code&gt;AT(...)&lt;/code&gt; tells the linker to &lt;em&gt;load&lt;/em&gt; it at that address minus &lt;code&gt;KERNEL_VMA&lt;/code&gt;, so &lt;code&gt;.text&lt;/code&gt; ends up right after the boot code, but every address inside it points into the higher-half.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;so every section has two addresses: where it &lt;em&gt;sits in memory&lt;/em&gt;, which GRUB uses, and where it &lt;em&gt;thinks it is&lt;/em&gt;, which our code uses.&lt;/p&gt;
&lt;p&gt;now, the goal of our boot code is to bridge the gap.&lt;/p&gt;
&lt;h3 id=&quot;boot-asm-getting-ready-for-the-higher-half&quot;&gt;&lt;code&gt;boot.asm&lt;/code&gt;: getting ready for the higher-half&lt;/h3&gt;
&lt;p&gt;when GRUB gives us control, the CPU is in 32-bit protected mode with paging off, with no stack. before we can get to rust, we need to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;check that we were booted by a multiboot2-compliant bootloader, that the CPU supports the CPUID instruction,
and that it supports long mode&lt;/li&gt;
&lt;li&gt;build page tables that map the same 1 GiB of memory twice, once at &lt;code&gt;0&lt;/code&gt; and once at the top&lt;/li&gt;
&lt;li&gt;turn on paging and switch to 64-bit long mode&lt;/li&gt;
&lt;li&gt;jump to the higher-half and call &lt;code&gt;kernel_main&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/x86_64/boot/boot.asm&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;global&lt;/span&gt;&lt;span&gt; start&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;extern&lt;/span&gt;&lt;span&gt; kernel_main&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;KERNEL_P4 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;equ&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 511&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;KERNEL_P3 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;equ&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 510&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .boot&lt;/span&gt;&lt;span&gt;.text&lt;/span&gt;&lt;span&gt; progbits alloc exec nowrite align=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;16&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;bits &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;32&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; esp&lt;/span&gt;&lt;span&gt;, boot_stack_top &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; set up a stack pointer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; edi&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ebx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ; save the multiboot info pointer in edi&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    call&lt;/span&gt;&lt;span&gt; check_multiboot&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    call&lt;/span&gt;&lt;span&gt; check_cpuid&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    call&lt;/span&gt;&lt;span&gt; check_long_mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    call&lt;/span&gt;&lt;span&gt; set_up_page_tables&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    call&lt;/span&gt;&lt;span&gt; enable_paging&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    lgdt&lt;/span&gt;&lt;span&gt; [gdt64.pointer] &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; load the GDT for 64-bit mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; gdt64.code&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;span&gt;long_mode_low &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; jump to the 64-bit code segment&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;now, we check if the bootloader is multiboot2-compliant, and then whether the CPU supports the CPUID instruction:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; checks if the system was booted by a multiboot2-compliant bootloader&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;check_multiboot&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    cmp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0x36d76289&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jne&lt;/span&gt;&lt;span&gt; .no_multiboot&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    ret&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;no_multiboot&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &amp;quot;M&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span&gt; error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; checks if the CPU supports the CPUID instruction&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;check_cpuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pushfd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ecx&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    xor&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt; &amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;21&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ; flip the ID bit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    push&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    popfd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pushfd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    push&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ecx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    popfd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    cmp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ecx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    je&lt;/span&gt;&lt;span&gt; .no_cpuid&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    ret&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ; bit flipped so CPUID is supported&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;no_cpuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &amp;quot;C&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span&gt; error&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the last check is whether the CPU supports long mode, and the NX bit:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; check if the CPU supports long mode and NX bit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;check_long_mode&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0x80000000&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ; ask CPUID for the highest extended leaf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    cpuid&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    cmp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0x80000001&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jb&lt;/span&gt;&lt;span&gt; .no_long_mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0x80000001&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    cpuid&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; edx&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt; &amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;29&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jz&lt;/span&gt;&lt;span&gt; .no_long_mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; edx&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt; &amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ; NX bit support&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jz&lt;/span&gt;&lt;span&gt; .no_nx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    ret&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ; long mode and NX are supported, return&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;no_long_mode&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &amp;quot;L&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span&gt; error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;no_nx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &amp;quot;N&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span&gt; error&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;now, we know the CPU can do everything we need, so we build the page tables from the diagram earlier: the same 1 GiB of memory, mapped twice.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; sets up the initial page tables for long mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;set_up_page_tables&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, p3_low&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    or&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0b11&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span&gt; [p4_table], &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, p3_high&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    or&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0b11&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span&gt; [p4_table + KERNEL_P4 * &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;8&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, p2_table&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    or&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0b11&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span&gt; [p3_low], &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span&gt; [p3_high + KERNEL_P3 * &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;8&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    xor&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ecx&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ecx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; maps the P2 table entries for the kernel&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;map_p2_table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ecx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    shl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;21&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    or&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0b10000011&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span&gt; [p2_table + &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ecx&lt;/span&gt;&lt;span&gt; * &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;8&lt;/span&gt;&lt;span&gt;], &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    inc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ecx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    cmp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ecx&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;512&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jne&lt;/span&gt;&lt;span&gt; .map_p2_table&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    ret&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;a quick bit of background: the CPU turns a virtual address into a physical address by walking four levels of &lt;strong&gt;page tables&lt;/strong&gt;: P4 → P3 → P2 → P1. each table is 4 KiB and has 512 entries, and each entry points to the next table down. we skip P1 entirely with &lt;strong&gt;huge pages&lt;/strong&gt;, where a single P2 entry maps a whole 2 MiB.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;set_up_page_tables&lt;/code&gt; builds the tables in a few steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;P4&lt;/strong&gt; gets two entries, with entry 0 pointing to &lt;code&gt;p3_low&lt;/code&gt; for the bottom of the address space, and entry 511 (&lt;code&gt;KERNEL_P4&lt;/code&gt;) pointing to &lt;code&gt;p3_high&lt;/code&gt;, for the very top of the address space&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;P3&lt;/strong&gt;: both tables get one entry each, pointing to the same P2 table. &lt;code&gt;p3_low&lt;/code&gt; uses entry 0 and &lt;code&gt;p3_high&lt;/code&gt; uses entry 510 (&lt;code&gt;KERNEL_P3&lt;/code&gt;). 511 and 510 are where &lt;code&gt;0xFFFFFFFF80000000&lt;/code&gt; lands when the CPU splits it into table indices&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;P2&lt;/strong&gt; is filled by the loop. entry &lt;code&gt;n&lt;/code&gt; maps the 2 MiB starting at physical address &lt;code&gt;n * 2 MiB&lt;/code&gt; (&lt;code&gt;shl eax, 21&lt;/code&gt; multiplies by 2 MiB). 512 entries cover the first 1 GiB of physical memory&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;the &lt;code&gt;or&lt;/code&gt; lines set flags on each entry: &lt;code&gt;0b11&lt;/code&gt; sets the &lt;strong&gt;present&lt;/strong&gt; and &lt;strong&gt;writable&lt;/strong&gt; bits, while &lt;code&gt;0b10000011&lt;/code&gt; also sets the &lt;strong&gt;huge&lt;/strong&gt; bit (bit 7).&lt;/p&gt;
&lt;p&gt;since both paths lead to the same P2 table, both addresses end up at the same memory:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;p4[0]   ──► p3_low[0]    ──┐&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                           ├──► p2[0..512] ──► physical 0..1 GiB&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;p4[511] ──► p3_high[510] ──┘&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;that’s the diagram from earlier, built for real: &lt;code&gt;0x100000&lt;/code&gt; and &lt;code&gt;0xFFFFFFFF80100000&lt;/code&gt; now point at the same byte!&lt;/p&gt;
&lt;p&gt;the tables are ready, so we can enable paging and switch to long mode:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; enables paging and sets up the necessary control registers for long mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;enable_paging&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, p4_table&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; cr3&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;cr4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    or&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt; &amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; cr4&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;eax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ecx&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0xC0000080&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    rdmsr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    or&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt; &amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;8&lt;/span&gt;&lt;span&gt;) | (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt; &amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;11&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    wrmsr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;cr0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;                    ; read cr0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    or&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; eax&lt;/span&gt;&lt;span&gt;, (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt; &amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;31&lt;/span&gt;&lt;span&gt;) | (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt; &amp;lt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;16&lt;/span&gt;&lt;span&gt;)   &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; set paging and write protect bits&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; cr0&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;eax&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;                    ; write back to cr0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ; long mode is active from here but the CPU runs in 32-bit compatibility mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ; until the far jump through the 64-bit GDT code segment in start&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    ret&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this does the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;cr3&lt;/code&gt;&lt;/strong&gt; gets the address of our P4 table so the CPU knows where to start looking for page tables&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;bit 5 of &lt;code&gt;cr4&lt;/code&gt;&lt;/strong&gt; enables PAE (Physical Address Extension), which is required for long mode&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;EFER&lt;/code&gt; register&lt;/strong&gt; (model-specific register &lt;code&gt;0xC0000080&lt;/code&gt;, read with &lt;code&gt;rdmsr&lt;/code&gt; and written with &lt;code&gt;wrmsr&lt;/code&gt;) gets bit 8: &lt;em&gt;long mode enable&lt;/em&gt; and bit 11: &lt;em&gt;no-execute enable&lt;/em&gt; (so we can mark memory as non-executable later)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;cr0&lt;/code&gt; gets bit 31&lt;/strong&gt; (paging), and bit 16 (write protect), which makes read-only pages read-only even for the kernel, so a stray write crashes spectacularly instead of silently corrupting memory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;the order matters! paging has to be last, after the CPU knows where the tables are and the format they use,&lt;/p&gt;
&lt;p&gt;we’re not fully in 64-bit mode yet. we still need a 64-bit code segment, which is what the &lt;code&gt;lgdt&lt;/code&gt; and far jump in &lt;code&gt;start&lt;/code&gt; take care of.&lt;/p&gt;
&lt;p&gt;before that, remember that every check jumped to &lt;code&gt;error&lt;/code&gt; on failure:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; handle boot errors&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; bl&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;al&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; esi&lt;/span&gt;&lt;span&gt;, error_msg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;print&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    lodsb&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;al&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jz&lt;/span&gt;&lt;span&gt; .code&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    call&lt;/span&gt;&lt;span&gt; serial_putc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span&gt; .print&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;code&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;bl&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    call&lt;/span&gt;&lt;span&gt; serial_putc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;10&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    call&lt;/span&gt;&lt;span&gt; serial_putc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;hang&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    cli&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    hlt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span&gt; .hang&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; outputs a character to the serial port (COM1)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;serial_putc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ah&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;al&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; dx&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0x3F8&lt;/span&gt;&lt;span&gt; + &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;wait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    in&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;dx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0x20&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jz&lt;/span&gt;&lt;span&gt; .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;wait&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; al&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ah&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; dx&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0x3F8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    out&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; dx&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;al&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    ret&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;error&lt;/code&gt; prints &lt;code&gt;boot error:&lt;/code&gt; followed by the letter indicating which check failed, then a newline, and then halts the CPU forever. &lt;code&gt;lodsb&lt;/code&gt; loads a byte of the message at a time, and the loop stops at the null terminator of the string.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;serial_putc&lt;/code&gt; talks to COM1 at I/O port &lt;code&gt;0x3F8&lt;/code&gt;. it waits until bit 5 of the &lt;em&gt;line status&lt;/em&gt; register (&lt;code&gt;0x3F8 + 5&lt;/code&gt;) says the port is ready for a new byte, and then sends another byte. we’ll write a serial driver in rust later, but this is enough for debugging and fixing early boot issues.&lt;/p&gt;
&lt;p&gt;now, for the jump to 64-bit. do you remember the last two lines of &lt;code&gt;start&lt;/code&gt;?&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    lgdt&lt;/span&gt;&lt;span&gt; [gdt64.pointer]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; gdt64.code&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;span&gt;long_mode_low&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;lgdt&lt;/code&gt; loads a GDT with a 64-bit code segment, which we’ll define momentarily, and the far jump switches to that segment, entering 64-bit mode. right now, we’re still running in the low, identity-mapped address space, and the rest of the kernel is linked to run in the higher half, so we need one more jump to get there.&lt;/p&gt;
&lt;p&gt;a plain &lt;code&gt;jmp long_mode_high&lt;/code&gt; won’t work, since direct jumps in 64-bit mode are relative and can only reach 2 GiB from either direction. the higher half is well beyond that.&lt;/p&gt;
&lt;p&gt;instead, we load the full 64-bit address of &lt;code&gt;long_mode_high&lt;/code&gt; into &lt;code&gt;rax&lt;/code&gt; and jump to it:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;bits &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;long_mode_low&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; rax&lt;/span&gt;&lt;span&gt;, long_mode_high&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; rax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .boot&lt;/span&gt;&lt;span&gt;.rodata&lt;/span&gt;&lt;span&gt; progbits alloc noexec nowrite align=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error_msg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    db&lt;/span&gt;&lt;span&gt; &amp;quot;boot &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;span&gt;&amp;quot;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this block also defines the read-only error message the &lt;code&gt;error&lt;/code&gt; routine prints. it lives down here with the boot code, so it’s reachable before the higher-half kernel is mapped in.&lt;/p&gt;
&lt;p&gt;next up is the GDT loaded earlier in &lt;code&gt;start&lt;/code&gt;. in long mode, segmentation is mostly gone, so we only need the null descriptor every GDT needs to start with, and a single 64-bit code segment:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; 64-bit GDT for long mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; contains the GDT entries and the pointer for long mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;gdt64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dq&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;code&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; equ&lt;/span&gt;&lt;span&gt; $ - gdt64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dq&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;43&lt;/span&gt;&lt;span&gt;) | (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;44&lt;/span&gt;&lt;span&gt;) | (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;47&lt;/span&gt;&lt;span&gt;) | (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;53&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;pointer&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dw&lt;/span&gt;&lt;span&gt; $ - gdt64 - &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dq&lt;/span&gt;&lt;span&gt; gdt64&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the code segment is just four bits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;43&lt;/strong&gt;: executable, making this a code segment&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;44&lt;/strong&gt;: code/data segment&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;47&lt;/strong&gt;: present&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;53&lt;/strong&gt;: 64-bit&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;.code&lt;/code&gt; is the segment’s offset into the table (8, right after the null entry) which is the number the far jump uses. &lt;code&gt;.pointer&lt;/code&gt; is the structure &lt;code&gt;lgdt&lt;/code&gt; expects: the table’s size minus one, followed by its address.&lt;/p&gt;
&lt;p&gt;lastly, we need to reserve the memory everything is using. each table is one 4 KiB page, and the section is page-aligned. the boot stack gets a page too:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .boot&lt;/span&gt;&lt;span&gt;.bss&lt;/span&gt;&lt;span&gt; nobits alloc noexec write align=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;4096&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;p4_table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    resb&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 4096&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;p3_low&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    resb&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 4096&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;p3_high&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    resb&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 4096&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;p2_table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    resb&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 4096&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;boot_stack_bottom&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    resb&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 4096&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;boot_stack_top&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;.bss&lt;/code&gt; sections take up no space in the kernel file. &lt;code&gt;resb&lt;/code&gt; just reserves bytes, and they are zeroed when GRUB loads the kernel, so every page table entry starts out empty (not present)&lt;/p&gt;
&lt;p&gt;finally, &lt;code&gt;long_mode_high&lt;/code&gt; is the entry point for the higher-half kernel code. this is where we give control to rust, switching to the proper stack and calling &lt;code&gt;kernel_main&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .text&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;bits &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;long_mode_high&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ss&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ds&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; es&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; fs&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; gs&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; rsp&lt;/span&gt;&lt;span&gt;, stack_top &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; switch to the real kernel stack&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    xor&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; ebp&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;ebp&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    mov&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; edi&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;edi&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    call&lt;/span&gt;&lt;span&gt; kernel_main &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; never returns&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    cli&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;hang&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    hlt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    jmp&lt;/span&gt;&lt;span&gt; .hang&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .bss&lt;/span&gt;&lt;span&gt; nobits alloc noexec write align=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;4096&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;stack_bottom&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    resb&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 4096&lt;/span&gt;&lt;span&gt; * &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;16&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;stack_top&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the segment registers are cleared because they may still hold leftover values from GRUB. long mode ignores them, but it’s good practice to clear them to avoid any unexpected behavior.&lt;/p&gt;
&lt;p&gt;next, the stack pointer is moved to the higher-half stack, which is the proper kernel stack, instead of the small stack set up by &lt;code&gt;start&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;xor ebp, ebp&lt;/code&gt;&lt;/strong&gt; zeroes the frame pointer, ending the chain of previous stack frames. this’ll matter once we start printing backtraces.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;mov edi, edi&lt;/code&gt;&lt;/strong&gt; looks like it does nothing, but writing to a 32-bit register in 64-bit mode clears the top half of the 64-bit one. that leaves &lt;code&gt;rdi&lt;/code&gt; holding exactly the multiboot pointer we saved at the very start, and &lt;code&gt;rdi&lt;/code&gt; is where the first argument to &lt;code&gt;kernel_main&lt;/code&gt; goes.&lt;/p&gt;
&lt;p&gt;then, &lt;code&gt;kernel_main&lt;/code&gt; is called with the multiboot information pointer in &lt;code&gt;rdi&lt;/code&gt;. this is the entry point for the rust kernel.&lt;/p&gt;
&lt;h3 id=&quot;multiboot-header-asm-introducing-ourselves-to-grub&quot;&gt;&lt;code&gt;multiboot_header.asm&lt;/code&gt;: introducing ourselves to GRUB&lt;/h3&gt;
&lt;p&gt;GRUB won’t boot any file you hand it. it scans the first 32 KiB of the kernel for a &lt;strong&gt;multiboot2 header&lt;/strong&gt;: a small data structure that tells the bootloader how to load the kernel and what information it expects.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/x86_64/boot/multiboot_header.asm&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;asm&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; multiboot2 header&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; GRUB looks for it, 8-byte aligned, within the first 32 KiB of the kernel&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;; linker.ld ensures the header is placed correctly&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .multiboot_header progbits alloc noexec nowrite align=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;header_start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dd&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0xe85250d6&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ; magic number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dd&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;          ; architecture: 32-bit protected mode i386&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dd&lt;/span&gt;&lt;span&gt; header_end - header_start&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ; checksum -(magic + arch + length)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dd&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0x100000000&lt;/span&gt;&lt;span&gt; - (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0xe85250d6&lt;/span&gt;&lt;span&gt; + &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span&gt; + (header_end - header_start))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ; end tag&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    align &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dw&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dw&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    dd&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;header_end&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the header starts with four 32-bit fields:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;the magic number&lt;/strong&gt;: &lt;code&gt;0xe85250d6&lt;/code&gt;, which identifies the header as a multiboot2 header&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;the architecture&lt;/strong&gt;: &lt;code&gt;0&lt;/code&gt;, indicating 32-bit protected mode on x86, which is the state GRUB will leave the CPU in when it jumps to the kernel&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;the header length&lt;/strong&gt;: the size of the header in bytes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;the checksum&lt;/strong&gt;, which is calculated so that the sum of the magic number, architecture, header length, and checksum equals zero. otherwise, GRUB will ignore the header.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;after these fields, the header may contain various &lt;strong&gt;tags&lt;/strong&gt; which act as requests to the bootloader, such as asking for a framebuffer. each tag starts with a type, flags, and a size.&lt;/p&gt;
&lt;p&gt;we don’t need to ask for anything for now, so we just have the &lt;strong&gt;end tag&lt;/strong&gt;: type &lt;code&gt;0&lt;/code&gt;, flags &lt;code&gt;0&lt;/code&gt;, size &lt;code&gt;8&lt;/code&gt;, which marks the end of the header.&lt;/p&gt;
&lt;p&gt;the section name matters, too. &lt;code&gt;.multiboot_header&lt;/code&gt; is the section the linker script puts first in the file, with &lt;code&gt;KEEP&lt;/code&gt;, so that it always lands inside those first 32 KiB.&lt;/p&gt;
&lt;p&gt;that’s all GRUB needs! in return, GRUB tells the kernel it understood by putting a magic number, &lt;code&gt;0x36d76289&lt;/code&gt;, in &lt;code&gt;eax&lt;/code&gt;. that’s the number &lt;code&gt;check_multiboot&lt;/code&gt; looks for in &lt;code&gt;boot.asm&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;ready-for-rust&quot;&gt;ready for rust?&lt;/h2&gt;
&lt;p&gt;let’s write some rust. we’ll start at the bottom, with the hardware, and work up to &lt;code&gt;kernel_main&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;the-root&quot;&gt;the root&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;kernel/src/lib.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;no_std&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;macro_use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; log&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; drivers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; panic&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;feature &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; `multiboot_info_ptr` is the physical address of the multiboot2 information structure provided by the bootloader.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;no_mangle&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; extern&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; kernel_main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt;multiboot_info_ptr&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;not&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;feature &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; entry&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; kernel_start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;feature &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; entry&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;run&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: this is the pointer the boot stub handed us&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;multiboot_info_ptr&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; entry&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;not&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;feature &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; kernel_start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;hello from the kernel! chapter 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;    arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;halt_loop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;#![no_std]&lt;/code&gt; drops the standard library, since there’s nothing for it to talk to. we still get &lt;code&gt;core&lt;/code&gt;, which has all the essential stuff: &lt;code&gt;Option&lt;/code&gt;, iterators, slices, and so on.&lt;/p&gt;
&lt;p&gt;notice there’s no &lt;code&gt;#![no_main]&lt;/code&gt;. because we’re a static library, we don’t define a &lt;code&gt;main&lt;/code&gt; function. instead, &lt;code&gt;kernel_main&lt;/code&gt; serves as the entry point for the assembly.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;#[unsafe(no_mangle)]&lt;/code&gt; tells the compiler not to mangle the function name, so it can be called from somewhere else&lt;/li&gt;
&lt;li&gt;&lt;code&gt;extern &quot;C&quot;&lt;/code&gt; gives it the C calling conventions&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-&amp;gt; !&lt;/code&gt; means it never returns&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;kernel_main&lt;/code&gt; picks an entry point (the kernel, or the test runner when built with &lt;code&gt;--features test&lt;/code&gt;) and hands it off to &lt;code&gt;init&lt;/code&gt;, which we’ll write soon.&lt;/p&gt;
&lt;p&gt;don’t worry if it doesn’t compile yet; we’ll fill in the missing pieces as we go, one at a time!&lt;/p&gt;
&lt;h3 id=&quot;architecture-specific-code&quot;&gt;architecture-specific code&lt;/h3&gt;
&lt;p&gt;all the architecture-specific code lives in &lt;code&gt;arch&lt;/code&gt;, so that the rest of the kernel doesn’t need to care about what platform it runs on. there’s only &lt;code&gt;x86_64&lt;/code&gt; for now, but it keeps it tidy regardless, and keeps the door open for other architectures in the future! ;)&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/mod.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Architecture support.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Each architecture exports the same interface, which is re-exported here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! for the kernel to use.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;target_arch &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;target_arch &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;not&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;target_arch &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;compile_error!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;this kernel does not support this target architecture yet&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/x86_64/mod.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! x86_64 architecture support.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; bringup&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; cpu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; uart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;feature &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; qemu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;feature &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; qemu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;exit_qemu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; bringup&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; cpu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span&gt;disable_interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; halt_loop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; without_interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; uart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Uart16550&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ConsoleUart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this is the architecture-specific layer, which provides the CPU, UART, and other low-level hardware interfaces for the kernel. it abstracts away the details of the underlying architecture, so the rest of the kernel can remain platform-agnostic.&lt;/p&gt;
&lt;h3 id=&quot;support-for-isa-debug-exit&quot;&gt;support for &lt;code&gt;isa-debug-exit&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;this device allows the kernel to signal to QEMU that it should exit, which is useful for our testing harness. we will use it to implement the &lt;code&gt;exit_qemu&lt;/code&gt; function in the &lt;code&gt;qemu&lt;/code&gt; module, which will be called by our test runner to indicate success or failure.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/x86_64/qemu.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! `isa-debug-exit` device support, so test runs can end with&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! a verdict.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Writing `value` to its port exits QEMU with the status&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! `(value &amp;lt;&amp;lt; 1) | 1`.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; super&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;cpu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;port&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; halt_loop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; PORT&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0xF4&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; PASSED&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u32&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0x10&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; FAILED&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u32&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0x11&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Stop QEMU, reporting if the tests passed or failed. Without&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; the device, this will halt instead.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; exit_qemu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt;passed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; bool&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; code&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; if&lt;/span&gt;&lt;span&gt; passed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; PASSED&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; else&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; FAILED&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: the `isa-debug-exit` device is mapped to the specified&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; port by QEMU, and writing to it is safe in this context&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;PORT&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;code&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    halt_loop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;the-cpu&quot;&gt;the CPU&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/x86_64/cpu/mod.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! The CPU: interrupts, halting, and port I/O.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; port&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;instructions&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;without_interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;instructions&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Stops the CPU from handling interrupts.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;inline&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; disable_interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;    interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;disable&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Idle the CPU indefinitely. Interrupts will be handled.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; halt_loop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    loop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;        instructions&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;hlt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;halt_loop&lt;/code&gt; is how our kernel “ends”: &lt;code&gt;hlt&lt;/code&gt; sleeps the CPU until next interrupt, and the loop ensures it keeps halting indefinitely.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/x86_64/cpu/port.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Re-export port I/O types from [`x86_64`].&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;instructions&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;port&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;PortReadOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;16550-uart&quot;&gt;16550 UART&lt;/h3&gt;
&lt;p&gt;now, we implement the 16550 UART driver, allowing us to communicate with the serial console hardware directly. the kernel can use this to send bytes over the serial port, giving us a way to output information!&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/x86_64/uart.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! The 16550 UART, reached via I/O ports.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; super&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;cpu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;port&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;PortReadOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;drivers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Uart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; COM1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0x3F8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; LCTL_DLAB&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0x80&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; LCTL_8N1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0x03&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; FCTL_ENABLE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0xC7&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; MCTL_READY&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0x08&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; LSTS_TX_EMPTY&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0x20&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; DIVISOR&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uart16550&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    int_en&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    fifo_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    line_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    modem_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    line_sts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortReadOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uart16550&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; COM1, which the serial console runs on.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; # Safety&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Nothing else may drive COM1: call this only once.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; console&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; Self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;        Self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;COM1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; Self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;        Self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            data&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;base&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            int_en&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;base&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            fifo_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;base&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            line_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;base&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            modem_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortWriteOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;base&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            line_sts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PortReadOnly&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;base&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uart16550&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;        //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: these are the UART&amp;#39;s registers, and we&amp;#39;re the only ones&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;        //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; accessing them&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;int_en&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0x00&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;line_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;LCTL_DLAB&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;data&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;DIVISOR&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;int_en&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;DIVISOR&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;line_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;LCTL_8N1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;fifo_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;FCTL_ENABLE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;modem_ctrl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;MCTL_READY&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; send&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt; byte&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;        //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: as in `init`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;            while&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;line_sts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; LSTS_TX_EMPTY&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;                core&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;hint&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;spin_loop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;data&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;byte&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the 16550 has a handful of registers, each at an offset from its base port (&lt;code&gt;0x3F8&lt;/code&gt; for COM1). &lt;code&gt;new&lt;/code&gt; sets up a port per register:&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;offset&lt;/th&gt;&lt;th&gt;register&lt;/th&gt;&lt;th&gt;purpose&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;+0&lt;/code&gt;&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;td&gt;write a byte here to send it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;+1&lt;/code&gt;&lt;/td&gt;&lt;td&gt;interrupt enable&lt;/td&gt;&lt;td&gt;which events make the UART raise an interrupt&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;+2&lt;/code&gt;&lt;/td&gt;&lt;td&gt;FIFO control&lt;/td&gt;&lt;td&gt;configure the chip’s internal byte queue&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;+3&lt;/code&gt;&lt;/td&gt;&lt;td&gt;line control&lt;/td&gt;&lt;td&gt;data format: bits per charactr, parity, stop bits&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;+4&lt;/code&gt;&lt;/td&gt;&lt;td&gt;modem control&lt;/td&gt;&lt;td&gt;control signals to the modem&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;+5&lt;/code&gt;&lt;/td&gt;&lt;td&gt;line status&lt;/td&gt;&lt;td&gt;status of the transmitter and receiver&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;&lt;code&gt;init&lt;/code&gt; sets up the UART, one register at a time:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;interrupts off.&lt;/strong&gt; we don’t handle interrupts yet, so we’ll &lt;em&gt;poll&lt;/em&gt; the chip instead and ask it whether it’s ready.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;set DLAB.&lt;/strong&gt; bit 7 of the line control register is the &lt;em&gt;divisor latch access bit&lt;/em&gt;. while it’s set, the data and interrupt enable registers temporarily turn into the low and high bytes of the &lt;strong&gt;baud rate divisor&lt;/strong&gt;. it’s a weird bit of hardware history, but it’s how every 16550 works.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;write the divisor.&lt;/strong&gt; the UART runs at &lt;code&gt;115200 / divisor&lt;/code&gt; baud, so a divisor of &lt;code&gt;1&lt;/code&gt; is the fastest it goes: 115200 baud. the low byte (&lt;code&gt;1&lt;/code&gt;) goes into the data register, and the high byte (&lt;code&gt;0&lt;/code&gt;) into the interrupt enable register, both still acting as the divisor thanks to DLAB.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;set the line format.&lt;/strong&gt; &lt;code&gt;0x03&lt;/code&gt; in line control means 8 data bits, no parity and 1 stop bit, usually written &lt;strong&gt;8N1&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;enable the FIFOs.&lt;/strong&gt; &lt;code&gt;0xC7&lt;/code&gt; turns on the chip’s built-in buffers (bit 0), clears out anything left in them (bits 1 and 2), and sets the receive buffer’s threshold to 14 bytes (bits 6 and 7).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;set OUT2.&lt;/strong&gt; &lt;code&gt;0x08&lt;/code&gt; sets the OUT2 line in modem control. on PCs, OUT2 connects the UART’s interrupt line to the interrupt controller. we don’t need it while polling, but setting it now means the wiring is ready when we start handling interrupts.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;code&gt;send&lt;/code&gt; is much simpler: it spins until bit 5 of the line status register (transmitter empty) is set, which means the UART is ready to accept a new byte, and then writes the byte to the data register.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;in QEMU, the baud rate doesn’t matter, since &lt;code&gt;-serial stdio&lt;/code&gt; just pipes the serial output to your terminal. it’s only relevant on real hardware: both ends of a serial cable must agree on the same baud rate, or you’ll get garbage data.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;the-serial-driver&quot;&gt;the serial driver&lt;/h3&gt;
&lt;p&gt;the UART is x86-specific, but most of what sits on top of it isn’t: locking, formatting, and fixing up newlines work the same on any hardware. so the serial driver lives in &lt;code&gt;drivers/&lt;/code&gt;, and talks to the hardware only through a small &lt;code&gt;Uart&lt;/code&gt; trait. the arch module plugs in its implementation, &lt;code&gt;Uart16550&lt;/code&gt;, under the name &lt;code&gt;ConsoleUart&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/drivers/serial/mod.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! The serial console.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! The UART itself belongs to the architecture, behind [`Uart`]; this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! is everything above it, and handles locking, line editing,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! and formatting.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; core&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;fmt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; spin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Mutex&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;ConsoleUart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; without_interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; A UART, as far as the serial driver is concerned.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; trait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Bring the UART up: 8N1, fast as possible, interrupts off.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Send a byte over the UART, waiting for room if necessary.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; send&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt; byte&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; write_str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; fmt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        for&lt;/span&gt;&lt;span&gt; byte&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;            if&lt;/span&gt;&lt;span&gt; byte&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;                self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;byte&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;        Ok&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: the only place the console UART is created&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; CONSOLE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Mutex&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;ConsoleUart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Mutex&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; ConsoleUart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;console&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;    CONSOLE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lock&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Retake the serial lock by force.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; # Safety&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Only the panic handler may call this function, and&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; interrupts must be disabled.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; force_unlock&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: upheld by the caller&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; CONSOLE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;force_unlock&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt;args&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; fmt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Arguments&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    without_interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;        //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; should never fail&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        let&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; CONSOLE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lock&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write_fmt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;there are a few things going on here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Uart&lt;/code&gt;&lt;/strong&gt; is the whole interface the driver needs from the hardware: &lt;code&gt;init&lt;/code&gt; to bring it up, and &lt;code&gt;send&lt;/code&gt; to push out one byte. anything that implements those two can be a serial port, which comes in handy for testing later.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Serial&lt;/code&gt;&lt;/strong&gt; wraps a UART and implements &lt;code&gt;core::fmt::Write&lt;/code&gt;. that trait only asks us for one method, &lt;code&gt;write_str&lt;/code&gt;, and in return we get all of rust’s formatting machinery for free: &lt;code&gt;{}&lt;/code&gt;, &lt;code&gt;{:#x}&lt;/code&gt;, &lt;code&gt;{:?}&lt;/code&gt; and friends just work.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;\r\n&lt;/code&gt;&lt;/strong&gt;: terminals treat &lt;code&gt;\n&lt;/code&gt; as “move down a line” and &lt;code&gt;\r&lt;/code&gt; as “go back to the start of the line”. without the &lt;code&gt;\r&lt;/code&gt;, every new line would start where the last one ended, and our output would slowly staircase across the screen. so we sneak a &lt;code&gt;\r&lt;/code&gt; in before every &lt;code&gt;\n&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;CONSOLE&lt;/code&gt;&lt;/strong&gt; is the one and only serial console, living in a &lt;code&gt;static&lt;/code&gt; behind a &lt;code&gt;spin::Mutex&lt;/code&gt;. a spinlock just loops until the lock is free, because there’s no OS to put a waiting thread to sleep. we can build the UART right inside the &lt;code&gt;static&lt;/code&gt; because its constructors are &lt;code&gt;const fn&lt;/code&gt;s, and the &lt;code&gt;// SAFETY:&lt;/code&gt; comment explains why calling the &lt;code&gt;unsafe&lt;/code&gt; &lt;code&gt;console()&lt;/code&gt; is fine here: this is the only place it ever happens.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;init&lt;/code&gt;&lt;/strong&gt; locks the console and calls the UART’s &lt;code&gt;init&lt;/code&gt; (&lt;code&gt;.0&lt;/code&gt; is the UART inside &lt;code&gt;Serial&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;write&lt;/code&gt;&lt;/strong&gt; takes the lock with interrupts disabled. we don’t handle interrupts yet, but once we do, picture this: the kernel is halfway through printing, holding the lock, and an interrupt arrives. if the interrupt handler tries to print too, it waits for a lock that will never be released, because the code holding it can’t run until the handler finishes. that’s a &lt;strong&gt;deadlock&lt;/strong&gt;, and turning interrupts off while we hold the lock prevents it. better to build the habit now!&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;let _ =&lt;/code&gt;&lt;/strong&gt; ignores the result of &lt;code&gt;write_fmt&lt;/code&gt;. our &lt;code&gt;write_str&lt;/code&gt; never fails, so there’s nothing useful to do with an error anyway.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;force_unlock&lt;/code&gt; is an escape hatch for the panic handler. we’ll see why it needs one in a bit.&lt;/p&gt;
&lt;h3 id=&quot;console-and-logging&quot;&gt;console, and logging&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;kernel/src/drivers/console.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! The kernel console: where the kernel talks!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Not a device of its own, more like a fan-out over the ones that do. For&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! now, that&amp;#39;s the serial port.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; core&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;fmt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;drivers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; plain&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt;args&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; fmt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Arguments&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;    serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Retake every sink immediately.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; # Safety&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Only the panic handler may call this function, and&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; interrupts must be disabled with nothing else running.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; force_unlock&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: upheld by the caller&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;force_unlock&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;right now the console is just a thin wrapper around serial, but later on, this will change as more things are added.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/drivers/mod.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Drivers for hardware components.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; console&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Initialize all available drivers.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;    serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and the macros we will actually use to print…&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/log/mod.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Kernel output.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Only the raw path exists right now: straight to console.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Write a raw output to the console.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;macro_export&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;macro_rules!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; raw&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;arg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span&gt;tt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;drivers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;console&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;plain&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;format_args!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span&gt;arg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Write a raw output to the console, with a newline.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;macro_export&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;macro_rules!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; rawln&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;raw!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;arg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span&gt;tt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;raw!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; format_args!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;arg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;those are our equivalent of &lt;code&gt;print!&lt;/code&gt; and &lt;code&gt;println!&lt;/code&gt; for now. eventually, they will be proper logs, featuring module paths, exact timestamps, log levels with colors, filtering, and so on.&lt;/p&gt;
&lt;h3 id=&quot;reading-the-boot-info&quot;&gt;reading the boot info&lt;/h3&gt;
&lt;p&gt;remember that pointer GRUB gave? it points to a list of tags describing the machine, and the &lt;code&gt;multiboot2&lt;/code&gt; crate helps us parse all those tags.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/arch/x86_64/bringup.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Architecture bringup for x86_64.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; multiboot2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;BootInformation&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; BootInformationHeader&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; MemoryAreaType&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; # Safety&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; `boot_info` must be a valid pointer to the multiboot2 information left by the bootloader.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Only call once.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt;boot_info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; ptr&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; boot_info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; BootInformationHeader&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: upheld by caller&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; loaded&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; BootInformation&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;load&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; loaded&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;expect&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;failed to find the secrets you seek&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    report&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Report the multiboot2 information.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; report&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt;info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;BootInformation&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;start_address&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; end&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span&gt; info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;total_size&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;multiboot info @ &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;start:#x&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;end:#x&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; let&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Some&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;tag&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;boot_loader_name_tag&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;  bootloader    &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; tag&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap_or&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; let&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Some&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;tag&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;command_line_tag&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;  command line  &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; tag&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;cmdline&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap_or&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    match&lt;/span&gt;&lt;span&gt; info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;memory_map_tag&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;        Some&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;map&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;            rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;  memory map&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;            for&lt;/span&gt;&lt;span&gt; area&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; map&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;memory_areas&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;                let&lt;/span&gt;&lt;span&gt; start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; area&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;start_address&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;                let&lt;/span&gt;&lt;span&gt; end&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span&gt; area&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;                let&lt;/span&gt;&lt;span&gt; kind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; MemoryAreaType&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;area&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;typ&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;                rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;start:#014x&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;end:#014x&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;  {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;kind:?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;        None&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;  no memory map&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the boot info sits at a physical address, but we can use it as a pointer because the first 1 GiB is still identity mapped (not forever, but enough for early bringup).&lt;/p&gt;
&lt;p&gt;for this chapter, we just report what the bootloader gave us, without trying to interpret or act on it: the bootloader’s name, the kernel command line, and the &lt;strong&gt;memory map&lt;/strong&gt;. the memory map is the most important; we’ll need to consult it once we start allocating memory.&lt;/p&gt;
&lt;h3 id=&quot;initializing-everything&quot;&gt;initializing everything&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;kernel/src/init.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Kernel bringup, in order.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span&gt;arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; drivers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Bring the kernel from entry to a usable state before calling `entry`.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; # Safety&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; `boot_info` must be the physical address of the multiboot2 info.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Call only once.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt;boot_info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt; entry&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;    drivers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: upheld by caller&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;boot_info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    entry&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;drivers first, so that everything after them can print. this file will grow a lot as the series grows: memory, interrupts, and eventually userspace!&lt;/p&gt;
&lt;h3 id=&quot;when-things-go-wrong&quot;&gt;when things go wrong&lt;/h3&gt;
&lt;p&gt;the panic handler disables interrupts, unlocks the console by force (&lt;code&gt;force_unlock&lt;/code&gt; is needed because the lock might be held when the panic occurs), and then prints the panic information before halting, or exiting QEMU if we’re running under the test harness.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/panic.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Panic handling.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Tells us what went wrong, then stops: halting for good,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! or failing to continue execution.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; core&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;panic&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;PanicInfo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span&gt;arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; drivers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;console&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;panic_handler&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; panic&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt;info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;PanicInfo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;    arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;disable_interrupts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: interrupts are off and theres only one cpu&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; so whoever held this can&amp;#39;t anymore&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; console&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;force_unlock&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;kernel panic: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;feature &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;    arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;exit_qemu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;not&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;feature &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;    arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;halt_loop&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;testing-and-making-sure-they-don-t&quot;&gt;testing, and making sure they don’t&lt;/h3&gt;
&lt;p&gt;every good program needs tests to ensure correct behavior, and a kernel is no exception!&lt;/p&gt;
&lt;p&gt;earlier, we added a test feature to the kernel, we created a special area of memory in &lt;code&gt;linker.ld&lt;/code&gt; to hold test cases, we added a module for interacting with &lt;code&gt;isa-debug-exit&lt;/code&gt; in QEMU to signal test results, and now we need to implement the test framework itself.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/test.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! A testing framework, backed by the `isa-debug-exit` device on QEMU.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Built under `--features test`, where `kernel_main` runs [`run`] instead&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! of the normal kernel entry. A test is a `fn()`; failing tests panic, which&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! the panic handler reports and then fails a run.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;! Tests register themselves with [`test!`]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; A single test case, with a name and function.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pub&lt;/span&gt;&lt;span&gt; name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pub&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; extern&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    static&lt;/span&gt;&lt;span&gt; __tests_start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    static&lt;/span&gt;&lt;span&gt; __tests_end&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Define one or more test cases and register them with the test framework.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ```ignore&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; crate::test! {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;     /// doc something here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;     fn it_works() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;         assert_eq!(1 + 1, 2);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;     }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ```&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;macro_export&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;macro_rules!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;  (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;meta&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;meta&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span&gt;ident&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span&gt;block&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;            $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;meta&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;            fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;body&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;            const&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;                #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;used&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;                #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;link_section &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;.tests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;                static&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; ENTRY&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; concat!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;module_path!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; stringify!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    run&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;                }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;            }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        )&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Every [`Test`] collected into `.tests`.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; collected&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;raw&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; const&lt;/span&gt;&lt;span&gt; __tests_start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;cast&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; end&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;raw&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; const&lt;/span&gt;&lt;span&gt; __tests_end&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;cast&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; len&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;end&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; usize&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&lt;/span&gt;&lt;span&gt; start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; usize&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; size_of&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; SAFETY: linker.ld gathers every `test!` entry between these&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; symbols back to back and 8-byte aligned, and nothing ever writes to them&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    unsafe&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; core&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;slice&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;from_raw_parts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; len&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Run all collected tests, and report their results. This function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; does not return.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; tests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; collected&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    assert!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;!&lt;/span&gt;&lt;span&gt;tests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;no tests collected; check linker.ld&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;running &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; tests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; tests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    for&lt;/span&gt;&lt;span&gt; test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; tests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        raw!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ... &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        (&lt;/span&gt;&lt;span&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;run&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;ok !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;all &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; tests passed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; tests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;    arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;exit_qemu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;now, we can use the &lt;code&gt;test!&lt;/code&gt; macro to define test cases for our kernel. each &lt;code&gt;test!&lt;/code&gt; invocation puts a struct into &lt;code&gt;.tests&lt;/code&gt;, the linker collects them between &lt;code&gt;__tests_start&lt;/code&gt; and &lt;code&gt;__tests_end&lt;/code&gt;, and &lt;code&gt;#[used]&lt;/code&gt; plus &lt;code&gt;KEEP&lt;/code&gt; ensure they aren’t thrown away. on a passing test, the framework will print &lt;code&gt;ok !&lt;/code&gt; for each test and &lt;code&gt;all N tests passed&lt;/code&gt; at the end, and QEMU will exit successfully.&lt;/p&gt;
&lt;p&gt;lastly, we need to write our first test case for the kernel, using the &lt;code&gt;test!&lt;/code&gt; macro we defined.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kernel/src/drivers/serial/mod.rs&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;we also are gonna add a test for the serial driver to make sure it works correctly. add this at the &lt;strong&gt;end&lt;/strong&gt; of the file:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;feature &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; tests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; core&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;fmt&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; super&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Recorder&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        sent&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        len&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; usize&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    impl&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uart&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Recorder&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; send&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt; byte&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;sent&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;len&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; byte&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);&quot;&gt;            self&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;len &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;test!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; newline_becomes_crlf&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;            let&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; mut&lt;/span&gt;&lt;span&gt; serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; Serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Recorder&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span&gt; sent&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; len&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;            write!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;            assert_eq!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;.&lt;/span&gt;&lt;span&gt;sent&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;..&lt;/span&gt;&lt;span&gt;serial&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;.&lt;/span&gt;&lt;span&gt;len&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;finishing-up&quot;&gt;finishing up&lt;/h2&gt;
&lt;h3 id=&quot;writing-the-justfile&quot;&gt;writing the &lt;code&gt;justfile&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;before we can say we’re finished, we still need to create our &lt;code&gt;justfile&lt;/code&gt;, a file that defines named, reusable commands, called “recipes”, that we can invoke from the command line using the &lt;code&gt;just&lt;/code&gt; command.&lt;/p&gt;
&lt;p&gt;first, we need to define some variables for the architecture, build profile, command line arguments, and other settings that will be used by build and test recipes.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;justfile&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;just&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# run `just` to list recipes. override a setting with `just &amp;lt;name&amp;gt;=&amp;lt;value&amp;gt; &amp;lt;recipe&amp;gt;`,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# e.g. `just profile=release run` or `just cmdline=&amp;quot;foo=bar&amp;quot; run`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;set&lt;/span&gt;&lt;span&gt; shell&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;bash&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-euo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;pipefail&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-c&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;x86_64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;profile&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;debug&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cmdline&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;test_timeout&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;nasm&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;nasm&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ld&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;ld&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;qemu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;qemu-system-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; arch&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-unknown-none&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;out&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;build&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;boot&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;kernel/src/arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; arch&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;boot&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;kernel_bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span&gt; out &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;kernel.bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;kernel_iso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span&gt; out &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;kernel.iso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;test_bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span&gt; out &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test.bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;test_iso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span&gt; out &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;test.iso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lib&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; /&lt;/span&gt;&lt;span&gt; target &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;/&lt;/span&gt;&lt;span&gt; profile &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;libkernel.a&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;linker&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span&gt; boot &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;linker.ld&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cargo_flags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;--target &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span&gt; target &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; if&lt;/span&gt;&lt;span&gt; profile &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;release&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; --release&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; } &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;else&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ldflags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-n --gc-sections -z noexecstack --no-warn-rwx-segments&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;qemu_flags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-serial stdio -no-reboot -display none&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;test_qemu_flags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :=&lt;/span&gt;&lt;span&gt; qemu_flags &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -device isa-debug-exit,iobase=0xf4,iosize=0x04&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;these variables configure settings for the build system, such as the target architecture, output files and directories, build tools, cargo flags, linker flags, and QEMU options.&lt;/p&gt;
&lt;p&gt;now, let’s define recipes for building, running, debugging, running tests, checking our code with &lt;code&gt;rustfmt&lt;/code&gt; and &lt;code&gt;clippy&lt;/code&gt;, installing the toolchain, and cleaning up build artifacts:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;just&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# list the recipes&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;    @&lt;/span&gt;&lt;span&gt;just --list&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# build and link the kernel binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;build&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;_link&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; kernel_bin&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# build a bootable ISO image&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;iso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; build&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;_iso&lt;/span&gt;&lt;span&gt; kernel_bin kernel_iso&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# build and boot in QEMU; extra arguments go to QEMU&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;run&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt;args&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; iso&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    {{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;qemu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;span&gt; -cdrom &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;{{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;kernel_iso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;qemu_flags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;args&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# boot halted, waiting for gdb on :1234&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;debug&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; iso&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    {{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;qemu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;span&gt; -cdrom &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;{{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;kernel_iso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;qemu_flags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;span&gt; -s -S&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;_link&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;--features test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; test_bin&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;_iso&lt;/span&gt;&lt;span&gt; test_bin test_iso&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    #!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; isa-debug-exit makes QEMU exit with (code &amp;lt;&amp;lt; 1) | 1, 33 is a pass&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; timeout(1) exits 124 from a hanging test&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;    set&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;uo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; pipefail&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    timeout&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-foreground&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{test_timeout}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{qemu}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;cdrom&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{test_iso}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{test_qemu_flags}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/dev/null&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    case&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;status&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        3&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; echo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; PASS&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; ;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; echo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; TIMEOUT&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; exit&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; ;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        *)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; echo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;FAIL (qemu exited &lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;status&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; exit&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; ;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    esac&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# rustfmt and clippy, with/without tests&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;check&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    cargo fmt --all --check&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    cargo clippy &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;{{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;cargo_flags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;span&gt; --workspace -- -D warnings&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    cargo clippy &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;{{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;cargo_flags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;span&gt; -p kernel --features test -- -D warnings&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# install the toolchain pinned in rust-toolchain.toml&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;toolchain&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    rustup toolchain install&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# remove build artifacts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;clean&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    rm -rf &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;{{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;out&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    cargo &lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;clean&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# assemble the boot code, build the kernel lib with `features`, and link&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# them into `bin`. both builds share the library&amp;#39;s path, so link after&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;link&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    #!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;    set&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;euo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; pipefail&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    mkdir&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{out}}/asm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    objs&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    for&lt;/span&gt;&lt;span&gt; src&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span&gt;{boot}}/*.asm; do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        obj&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;{{out}}/asm/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;basename&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;src&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; .asm&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;.o&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        {&lt;/span&gt;&lt;span&gt;{nasm}} -f elf64 &amp;quot;$src&amp;quot; -o &amp;quot;$obj&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        objs&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;obj&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    done&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    cargo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; build&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{cargo_flags}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; kernel&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{features}}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    {&lt;/span&gt;&lt;span&gt;{ld}} {{ldflags}} -T {{linker}} -o {{bin}} &amp;quot;${objs[@]}&amp;quot; --whole-archive {{lib}} --no-whole-archive&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;# wrap the kernel at `bin` in a bootable GRUB image at `image`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;iso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; image&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    #!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;    set&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;euo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; pipefail&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    mkrescue&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;command&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; grub2-mkrescue&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; command&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; grub-mkrescue&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -z&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;mkrescue&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; ]]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;        echo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;grub-mkrescue or grub2-mkrescue not found; install grub and xorriso&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;gt;&amp;amp;2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;        exit&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    fi&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;{out}}/isofiles&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rm&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;rf&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    mkdir&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/boot/grub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    cp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{bin}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/boot/kernel.bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;    printf&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;%s\n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;set timeout=0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;set default=0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;menuentry &amp;quot;Crossing the Boundary&amp;quot; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;      &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    multiboot2 /boot/kernel.bin {{cmdline}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;      &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    boot&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/boot/grub/grub.cfg&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;mkrescue&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{image}}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;{{out}}/grub.log&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&amp;amp;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; cat&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; {{out}}/grub.log&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt; exit&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rm&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;rf&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;that’s a lot of recipes, but most of them one or two lines. the public ones are what you’ll type, and the ones starting with &lt;code&gt;_&lt;/code&gt; are private and don’t show up in &lt;code&gt;just --list&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;recipes can depend on other recipes, listed after the colon, so running one runs everything it needs first:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;run ──► iso ──► build ──► _link&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;          └───────────────► _iso&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;link-building-the-kernel&quot;&gt;&lt;code&gt;_link&lt;/code&gt;: building the kernel&lt;/h3&gt;
&lt;p&gt;this is where everything comes together:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;every &lt;code&gt;.asm&lt;/code&gt; file in &lt;code&gt;boot/&lt;/code&gt; is assembled by &lt;code&gt;nasm&lt;/code&gt; into a 64-bit ELF object in &lt;code&gt;build/asm/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cargo build&lt;/code&gt; compiles our rust into &lt;code&gt;libkernel.a&lt;/code&gt;, passing along any features (like &lt;code&gt;--features test&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ld&lt;/code&gt; links it all into one binary, using our linker script (&lt;code&gt;-T&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;the linker flags are worth a closer look:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-n&lt;/code&gt;&lt;/strong&gt; stops &lt;code&gt;ld&lt;/code&gt; from page-aligning sections inside the file. without it, padding could push the multiboot header past the first 32 KiB, and GRUB would never find it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;--gc-sections&lt;/code&gt;&lt;/strong&gt; throws away any section nothing uses. that’s why the linker script needs &lt;code&gt;KEEP&lt;/code&gt; around the multiboot header and the tests: nothing references them directly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-z noexecstack&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;--no-warn-rwx-segments&lt;/code&gt;&lt;/strong&gt; quiet two warnings that &lt;code&gt;ld&lt;/code&gt; gives about our hand-written assembly. they’re harmless for a kernel at this stage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;--whole-archive&lt;/code&gt;&lt;/strong&gt; makes &lt;code&gt;ld&lt;/code&gt; include &lt;em&gt;everything&lt;/em&gt; in &lt;code&gt;libkernel.a&lt;/code&gt;. normally, it only pulls in whatever is needed to resolve a symbol, which for us is just &lt;code&gt;kernel_main&lt;/code&gt;. our tests are never called by name, so without this flag they’d silently disappear!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;the build is a &lt;code&gt;#!/usr/bin/env bash&lt;/code&gt; recipe, so it runs as one script. that lets the &lt;code&gt;objs&lt;/code&gt; array carry over from the loop to the &lt;code&gt;ld&lt;/code&gt; line. normal recipes run each line in a separate shell.&lt;/p&gt;
&lt;h3 id=&quot;iso-making-it-bootable&quot;&gt;&lt;code&gt;_iso&lt;/code&gt;: making it bootable&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;_iso&lt;/code&gt; wraps the kernel in a bootable CD image. it finds &lt;code&gt;grub-mkrescue&lt;/code&gt; (some distros call it &lt;code&gt;grub2-mkrescue&lt;/code&gt;), copies the kernel into a temporary folder, and writes a tiny &lt;code&gt;grub.cfg&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set timeout=0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set default=0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;menuentry &amp;quot;Crossing the Boundary&amp;quot; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    multiboot2 /boot/kernel.bin&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    boot&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;no menu and no waiting, just boot our kernel with the multiboot2 protocol. &lt;code&gt;grub-mkrescue&lt;/code&gt; then turns the folder into an ISO with GRUB installed. its output goes to &lt;code&gt;build/grub.log&lt;/code&gt;, which only gets printed if something fails.&lt;/p&gt;
&lt;h3 id=&quot;the-recipes-you-ll-actually-use&quot;&gt;the recipes you’ll actually use&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;just run&lt;/code&gt;&lt;/strong&gt; builds everything and boots it in QEMU. &lt;code&gt;-serial stdio&lt;/code&gt; connects COM1 to your terminal, &lt;code&gt;-display none&lt;/code&gt; skips the window (we don’t have a screen yet anyway), and &lt;code&gt;-no-reboot&lt;/code&gt; makes QEMU quit instead of rebooting if the CPU hits a fatal error, so a crash doesn’t turn into an endless reboot loop. any extra arguments go straight to QEMU, like &lt;code&gt;just run -m 512M&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;just debug&lt;/code&gt;&lt;/strong&gt; boots QEMU paused (&lt;code&gt;-S&lt;/code&gt;), waiting for a debugger on port 1234 (&lt;code&gt;-s&lt;/code&gt;). in another terminal, run &lt;code&gt;gdb build/kernel.bin -ex &#39;target remote :1234&#39;&lt;/code&gt; to attach.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;just test&lt;/code&gt;&lt;/strong&gt; builds a second kernel with &lt;code&gt;--features test&lt;/code&gt; and boots it with the &lt;code&gt;isa-debug-exit&lt;/code&gt; device. QEMU’s exit code tells the recipe what happened: &lt;code&gt;33&lt;/code&gt; means every test passed, and &lt;code&gt;124&lt;/code&gt; means &lt;code&gt;timeout&lt;/code&gt; had to kill a test that hung. anything else is a failure.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;just check&lt;/code&gt;&lt;/strong&gt; runs &lt;code&gt;rustfmt&lt;/code&gt; and &lt;code&gt;clippy&lt;/code&gt;, with and without the test feature, and treats every warning as an error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;just toolchain&lt;/code&gt;&lt;/strong&gt; installs the toolchain from &lt;code&gt;rust-toolchain.toml&lt;/code&gt;, and &lt;strong&gt;&lt;code&gt;just clean&lt;/code&gt;&lt;/strong&gt; deletes all build output.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;you can override any variable from the command line, too:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;shellscript&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;just&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; cmdline=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;hello=world&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;   #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; pass a command line to the kernel&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;just&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; profile=release&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;         #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; build with optimizations&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;running-the-kernel&quot;&gt;running the kernel&lt;/h2&gt;
&lt;p&gt;the moment of truth! from the root of the project, run:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;shellscript&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;just&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; run&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the first build may take a little while, since cargo has to compile all dependencies and the kernel itself. subsequent builds will be faster. then, QEMU starts, GRUB boots our kernel, and you should see:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;multiboot info @ 0x2db660..0x2dbd00&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  bootloader    GRUB 2.12&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  command line  &amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  memory map&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x000000000000..0x00000009fc00  Available&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x00000009fc00..0x0000000a0000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x0000000f0000..0x000000100000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x000000100000..0x000007fe0000  Available&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x000007fe0000..0x000008000000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x0000fffc0000..0x000100000000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x00fd00000000..0x010000000000  Reserved&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;hello from the kernel! chapter 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;congratulations!&lt;/strong&gt; you have successfully built and run your kernel! :)&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;don’t worry if your numbers don’t match exactly. the first line shows up wherever GRUB put the boot info, which can change between versions and machines.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;the memory map is worth paying attention to. the big &lt;code&gt;Available&lt;/code&gt; region from 1 MiB to about 128 MiB is all the RAM QEMU gives a VM by default, and the &lt;code&gt;Reserved&lt;/code&gt; areas belong to firmware and devices.&lt;/p&gt;
&lt;h3 id=&quot;things-to-try&quot;&gt;things to try&lt;/h3&gt;
&lt;p&gt;now that it works, let’s mess around a bit.&lt;/p&gt;
&lt;p&gt;give it a bit more memory, and watch the memory map change accordingly:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;shellscript&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;just&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; 512M&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    0x000000100000..0x00001ffe0000  Available&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;pass a command line to the kernel:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;shellscript&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;just&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; cmdline=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;hello=world&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; run&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  command line  &amp;quot;hello=world&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and break something on purpose! add a &lt;code&gt;panic!&lt;/code&gt; to &lt;code&gt;kernel_start&lt;/code&gt; in &lt;code&gt;lib.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;rust&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; kernel_start&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    rawln!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;hello from the kernel! chapter 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    panic!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;oops&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;hello from the kernel! chapter 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;kernel panic: panicked at kernel/src/lib.rs:30:5:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;oops&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;that’s your panic handler in action! just remember to take the &lt;code&gt;panic!&lt;/code&gt; back out afterwards.&lt;/p&gt;
&lt;h3 id=&quot;running-tests&quot;&gt;running tests&lt;/h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;shellscript&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;just&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; test&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; data-lang=&quot;plain&quot;&gt;&lt;code &gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;running 1 tests&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;test kernel::drivers::serial::tests::newline_becomes_crlf ... ok !&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;all 1 tests passed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PASS&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;PASS&lt;/code&gt; comes from the justfile reading QEMU’s exit code, so this works in scripts and CI as well.&lt;/p&gt;
&lt;h3 id=&quot;something-wrong&quot;&gt;something wrong?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;grub-mkrescue or grub2-mkrescue not found&lt;/code&gt;&lt;/strong&gt;: install GRUB’s tools along with &lt;code&gt;xorriso&lt;/code&gt; and &lt;code&gt;mtools&lt;/code&gt;, as listed at the start.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;boot error:&lt;/code&gt; and a letter&lt;/strong&gt;: one of the checks in &lt;code&gt;boot.asm&lt;/code&gt; failed. &lt;code&gt;M&lt;/code&gt; means we weren’t booted by a multiboot2 bootloader, &lt;code&gt;C&lt;/code&gt; means no &lt;code&gt;cpuid&lt;/code&gt;, &lt;code&gt;L&lt;/code&gt; means no long mode, and &lt;code&gt;N&lt;/code&gt; means no NX bit. in QEMU, you shouldn’t ever see these.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;QEMU exits immediately with no output&lt;/strong&gt;: the CPU probably hit a triple fault, and &lt;code&gt;-no-reboot&lt;/code&gt; made QEMU quit. double-check &lt;code&gt;boot.asm&lt;/code&gt; and &lt;code&gt;linker.ld&lt;/code&gt; against the code above, or compare with the finished code in the repo.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;nothing at all, and QEMU just sits there&lt;/strong&gt;: GRUB couldn’t find the multiboot header. make sure &lt;code&gt;multiboot_header.asm&lt;/code&gt; is in &lt;code&gt;kernel/src/arch/x86_64/boot/&lt;/code&gt;, so the justfile picks it up.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;conclusion&lt;/h2&gt;
&lt;p&gt;thank you for reading the first post in this series! i am super passionate about rust and osdev, and i hope you found it helpful and interesting. i plan to continue this series when i have more time, so stay tuned for future posts.&lt;/p&gt;
&lt;p&gt;if you ever got stuck, the repository for this series is located &lt;a rel=&quot;external&quot; href=&quot;https://git.fawn.rest/fawn/crossing-the-boundary&quot;&gt;here&lt;/a&gt;, or you can email me at &lt;a href=&quot;mailto:saoirse@fawn.rest&quot;&gt;saoirse@fawn.rest&lt;/a&gt; if you have any questions or feedback.&lt;/p&gt;
&lt;p&gt;see you soon for part 2!&lt;/p&gt;
</content>
        
    </entry>
</feed>
