This commit is contained in:
Ciro Santilli 六四事件 法轮功
2020-07-31 01:00:00 +00:00
parent e11bc6eb0e
commit 23cb0409c9

View File

@@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.10">
<meta name="description" content="The perfect emulation setup to study and develop the &lt;&lt;linux-kernel&gt;&gt; v5.4.3, kernel modules, &lt;&lt;qemu-buildroot-setup,QEMU&gt;&gt;, &lt;&lt;gem5-buildroot-setup,gem5&gt;&gt; and x86_64, ARMv7 and ARMv8 &lt;&lt;userland-assembly,userland&gt;&gt; and &lt;&lt;baremetal-setup,baremetal&gt;&gt; assembly, &lt;&lt;c,ANSI C&gt;&gt;, &lt;&lt;cpp,C++&gt;&gt; and &lt;&lt;posix,POSIX&gt;&gt;. &lt;&lt;gdb&gt;&gt; and &lt;&lt;kgdb&gt;&gt; just work. Powered by &lt;&lt;about-the-qemu-buildroot-setup,Buildroot&gt;&gt; and &lt;&lt;about-the-baremetal-setup,crosstool-NG&gt;&gt;. Highly automated. Thoroughly documented. Automated &lt;&lt;test-this-repo,tests&gt;&gt;. "Tested" in an Ubuntu 19.10 host.">
<meta name="description" content="The perfect emulation setup to study and develop the &lt;&lt;linux-kernel&gt;&gt; v5.4.3, kernel modules, &lt;&lt;qemu-buildroot-setup,QEMU&gt;&gt;, &lt;&lt;gem5-buildroot-setup,gem5&gt;&gt; and x86_64, ARMv7 and ARMv8 &lt;&lt;userland-assembly,userland&gt;&gt; and &lt;&lt;baremetal-setup,baremetal&gt;&gt; assembly, &lt;&lt;c,ANSI C&gt;&gt;, &lt;&lt;cpp,C++&gt;&gt; and &lt;&lt;posix,POSIX&gt;&gt;. &lt;&lt;gdb&gt;&gt; and &lt;&lt;kgdb&gt;&gt; just work. Powered by &lt;&lt;about-the-qemu-buildroot-setup,Buildroot&gt;&gt; and &lt;&lt;about-the-baremetal-setup,crosstool-NG&gt;&gt;. Highly automated. Thoroughly documented. Automated &lt;&lt;test-this-repo,tests&gt;&gt;. "Tested" in an Ubuntu 20.04 host.">
<title>Linux Kernel Module Cheat</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<style>
@@ -436,6 +436,14 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
#footer-text{color:rgba(0,0,0,.6);font-size:.9em}}
@media amzn-kf8{#header,#content,#footnotes,#footer{padding:0}}
</style>
<style>
pre{ white-space:pre }
#header,#content,#footnotes,#footer {
margin-left:40px;
padding-right:60px;
max-width:none;
}
</style>
</head>
<body class="article">
<div id="header">
@@ -448,73 +456,74 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
<p><a href="https://zenodo.org/badge/latestdoi/64534859"><span class="image"><img src="https://zenodo.org/badge/64534859.svg" alt="64534859"></span></a></p>
</div>
<div class="paragraph">
<p>The perfect emulation setup to study and develop the <a href="#linux-kernel">Linux kernel</a> v5.4.3, kernel modules, <a href="#qemu-buildroot-setup">QEMU</a>, <a href="#gem5-buildroot-setup">gem5</a> and x86_64, ARMv7 and ARMv8 <a href="#userland-assembly">userland</a> and <a href="#baremetal-setup">baremetal</a> assembly, <a href="#c">ANSI C</a>, <a href="#cpp">C++</a> and <a href="#posix">POSIX</a>. <a href="#gdb">GDB step debug</a> and <a href="#kgdb">KGDB</a> just work. Powered by <a href="#about-the-qemu-buildroot-setup">Buildroot</a> and <a href="#about-the-baremetal-setup">crosstool-NG</a>. Highly automated. Thoroughly documented. Automated <a href="#test-this-repo">tests</a>. "Tested" in an Ubuntu 19.10 host.</p>
<p>The perfect emulation setup to study and develop the <a href="#linux-kernel">Linux kernel</a> v5.4.3, kernel modules, <a href="#qemu-buildroot-setup">QEMU</a>, <a href="#gem5-buildroot-setup">gem5</a> and x86_64, ARMv7 and ARMv8 <a href="#userland-assembly">userland</a> and <a href="#baremetal-setup">baremetal</a> assembly, <a href="#c">ANSI C</a>, <a href="#cpp">C++</a> and <a href="#posix">POSIX</a>. <a href="#gdb">GDB step debug</a> and <a href="#kgdb">KGDB</a> just work. Powered by <a href="#about-the-qemu-buildroot-setup">Buildroot</a> and <a href="#about-the-baremetal-setup">crosstool-NG</a>. Highly automated. Thoroughly documented. Automated <a href="#test-this-repo">tests</a>. "Tested" in an Ubuntu 20.04 host.</p>
</div>
<div class="paragraph">
<p>TL;DR: <a href="#qemu-buildroot-setup-getting-started">Section 1.1.1, &#8220;QEMU Buildroot setup getting started&#8221;</a></p>
<p>TL;DR: <a href="#qemu-buildroot-setup-getting-started">Section 1.2.1, &#8220;QEMU Buildroot setup getting started&#8221;</a></p>
</div>
<div class="paragraph">
<p>The source code for this page is located at: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat" class="bare">https://github.com/cirosantilli/linux-kernel-module-cheat</a>. Due to <a href="https://github.com/isaacs/github/issues/1610">a GitHub limitation</a>, this README is too long and not fully rendered on github.com. Either use: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/README.adoc">README.adoc</a>, <a href="https://cirosantilli.com/linux-kernel-module-cheat" class="bare">https://cirosantilli.com/linux-kernel-module-cheat</a> or <a href="#build-the-documentation">build the docs yourself</a>.</p>
<p>The source code for this page is located at: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat" class="bare">https://github.com/cirosantilli/linux-kernel-module-cheat</a>. Due to <a href="https://github.com/isaacs/github/issues/1610">a GitHub limitation</a>, this README is too long and not fully rendered on github.com, so either use: <a href="https://cirosantilli.com/linux-kernel-module-cheat" class="bare">https://cirosantilli.com/linux-kernel-module-cheat</a> or <a href="#build-the-documentation">build the docs yourself</a>.</p>
</div>
<div id="toc" class="toc">
<div id="toctitle" class="title"></div>
<ul class="sectlevel1">
<li><a href="#getting-started">1. Getting started</a>
<ul class="sectlevel2">
<li><a href="#qemu-buildroot-setup">1.1. QEMU Buildroot setup</a>
<li><a href="#should-you-waste-your-life-with-systems-programming">1.1. Should you waste your life with systems programming?</a></li>
<li><a href="#qemu-buildroot-setup">1.2. QEMU Buildroot setup</a>
<ul class="sectlevel3">
<li><a href="#qemu-buildroot-setup-getting-started">1.1.1. QEMU Buildroot setup getting started</a></li>
<li><a href="#how-to-hack-stuff">1.1.2. How to hack stuff</a>
<li><a href="#qemu-buildroot-setup-getting-started">1.2.1. QEMU Buildroot setup getting started</a></li>
<li><a href="#how-to-hack-stuff">1.2.2. How to hack stuff</a>
<ul class="sectlevel4">
<li><a href="#your-first-linux-kernel-hack">1.1.2.1. Your first Linux kernel hack</a></li>
<li><a href="#your-first-kernel-module-hack">1.1.2.2. Your first kernel module hack</a></li>
<li><a href="#your-first-qemu-hack">1.1.2.3. Your first QEMU hack</a></li>
<li><a href="#your-first-glibc-hack">1.1.2.4. Your first glibc hack</a></li>
<li><a href="#your-first-binutils-hack">1.1.2.5. Your first Binutils hack</a></li>
<li><a href="#your-first-gcc-hack">1.1.2.6. Your first GCC hack</a></li>
<li><a href="#your-first-linux-kernel-hack">1.2.2.1. Your first Linux kernel hack</a></li>
<li><a href="#your-first-kernel-module-hack">1.2.2.2. Your first kernel module hack</a></li>
<li><a href="#your-first-qemu-hack">1.2.2.3. Your first QEMU hack</a></li>
<li><a href="#your-first-glibc-hack">1.2.2.4. Your first glibc hack</a></li>
<li><a href="#your-first-binutils-hack">1.2.2.5. Your first Binutils hack</a></li>
<li><a href="#your-first-gcc-hack">1.2.2.6. Your first GCC hack</a></li>
</ul>
</li>
<li><a href="#about-the-qemu-buildroot-setup">1.1.3. About the QEMU Buildroot setup</a></li>
<li><a href="#about-the-qemu-buildroot-setup">1.2.3. About the QEMU Buildroot setup</a></li>
</ul>
</li>
<li><a href="#dry-run">1.2. Dry run to get commands for your project</a></li>
<li><a href="#gem5-buildroot-setup">1.3. gem5 Buildroot setup</a>
<li><a href="#dry-run">1.3. Dry run to get commands for your project</a></li>
<li><a href="#gem5-buildroot-setup">1.4. gem5 Buildroot setup</a>
<ul class="sectlevel3">
<li><a href="#about-the-gem5-buildroot-setup">1.3.1. About the gem5 Buildroot setup</a></li>
<li><a href="#gem5-buildroot-setup-getting-started">1.3.2. gem5 Buildroot setup getting started</a></li>
<li><a href="#about-the-gem5-buildroot-setup">1.4.1. About the gem5 Buildroot setup</a></li>
<li><a href="#gem5-buildroot-setup-getting-started">1.4.2. gem5 Buildroot setup getting started</a></li>
</ul>
</li>
<li><a href="#docker">1.4. Docker host setup</a></li>
<li><a href="#prebuilt">1.5. Prebuilt setup</a>
<li><a href="#docker">1.5. Docker host setup</a></li>
<li><a href="#prebuilt">1.6. Prebuilt setup</a>
<ul class="sectlevel3">
<li><a href="#about-the-prebuilt-setup">1.5.1. About the prebuilt setup</a></li>
<li><a href="#prebuilt-setup-getting-started">1.5.2. Prebuilt setup getting started</a></li>
<li><a href="#about-the-prebuilt-setup">1.6.1. About the prebuilt setup</a></li>
<li><a href="#prebuilt-setup-getting-started">1.6.2. Prebuilt setup getting started</a></li>
</ul>
</li>
<li><a href="#host">1.6. Host kernel module setup</a>
<li><a href="#host">1.7. Host kernel module setup</a>
<ul class="sectlevel3">
<li><a href="#hello-host">1.6.1. Hello host</a></li>
<li><a href="#hello-host">1.7.1. Hello host</a></li>
</ul>
</li>
<li><a href="#userland-setup">1.7. Userland setup</a>
<li><a href="#userland-setup">1.8. Userland setup</a>
<ul class="sectlevel3">
<li><a href="#about-the-userland-setup">1.7.1. About the userland setup</a></li>
<li><a href="#userland-setup-getting-started">1.7.2. Userland setup getting started</a>
<li><a href="#about-the-userland-setup">1.8.1. About the userland setup</a></li>
<li><a href="#userland-setup-getting-started">1.8.2. Userland setup getting started</a>
<ul class="sectlevel4">
<li><a href="#userland-setup-getting-started-natively">1.7.2.1. Userland setup getting started natively</a></li>
<li><a href="#userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode">1.7.2.2. Userland setup getting started with prebuilt toolchain and QEMU user mode</a></li>
<li><a href="#userland-setup-getting-started-full-system">1.7.2.3. Userland setup getting started full system</a></li>
<li><a href="#userland-setup-getting-started-natively">1.8.2.1. Userland setup getting started natively</a></li>
<li><a href="#userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode">1.8.2.2. Userland setup getting started with prebuilt toolchain and QEMU user mode</a></li>
<li><a href="#userland-setup-getting-started-full-system">1.8.2.3. Userland setup getting started full system</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#baremetal-setup">1.8. Baremetal setup</a>
<li><a href="#baremetal-setup">1.9. Baremetal setup</a>
<ul class="sectlevel3">
<li><a href="#about-the-baremetal-setup">1.8.1. About the baremetal setup</a></li>
<li><a href="#baremetal-setup-getting-started">1.8.2. Baremetal setup getting started</a></li>
<li><a href="#about-the-baremetal-setup">1.9.1. About the baremetal setup</a></li>
<li><a href="#baremetal-setup-getting-started">1.9.2. Baremetal setup getting started</a></li>
</ul>
</li>
<li><a href="#build-the-documentation">1.9. Build the documentation</a></li>
<li><a href="#build-the-documentation">1.10. Build the documentation</a></li>
</ul>
</li>
<li><a href="#gdb">2. GDB step debug</a>
@@ -1233,7 +1242,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
<li><a href="#gem5-derivo3cpu">19.16.1.3. gem5 <code>DerivO3CPU</code></a>
<ul class="sectlevel5">
<li><a href="#gem5-derivo3cpu-pipeline-stages">19.16.1.3.1. gem5 <code>DerivO3CPU</code> pipeline stages</a></li>
<li><a href="#gem5-utilo3-pipeview-py-o3-pipeline-viewer">19.16.1.3.2. gem5 util/o3-pipeview.py O3 pipeline viewer</a></li>
<li><a href="#gem5-util-o3-pipeview-py-o3-pipeline-viewer">19.16.1.3.2. gem5 util/o3-pipeview.py O3 pipeline viewer</a></li>
<li><a href="#gem5-konata-o3-pipeline-viewer">19.16.1.3.3. gem5 Konata O3 pipeline viewer</a></li>
</ul>
</li>
@@ -2263,7 +2272,6 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
<li><a href="#soft-topics">33.21. Soft topics</a>
<ul class="sectlevel3">
<li><a href="#fairy-tale">33.21.1. Fairy tale</a></li>
<li><a href="#should-you-waste-your-life-with-systems-programming">33.21.2. Should you waste your life with systems programming?</a></li>
</ul>
</li>
<li><a href="#bibliography">33.22. Bibliography</a></li>
@@ -2286,9 +2294,99 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
<p>Design goals of this project are documented at: <a href="#design-goals">Section 33.20.1, &#8220;Design goals&#8221;</a>.</p>
</div>
<div class="sect2">
<h3 id="qemu-buildroot-setup"><a class="anchor" href="#qemu-buildroot-setup"></a><a class="link" href="#qemu-buildroot-setup">1.1. QEMU Buildroot setup</a></h3>
<h3 id="should-you-waste-your-life-with-systems-programming"><a class="anchor" href="#should-you-waste-your-life-with-systems-programming"></a><a class="link" href="#should-you-waste-your-life-with-systems-programming">1.1. Should you waste your life with systems programming?</a></h3>
<div class="paragraph">
<p>Being the hardcore person who fully understands an important complex system such as a computer, it does have a nice ring to it doesn&#8217;t it?</p>
</div>
<div class="paragraph">
<p>But before you dedicate your life to this nonsense, do consider the following points:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>almost all contributions to the kernel are done by large companies, and if you are not an employee in one of them, you are likely not going to be able to do much.</p>
<div class="paragraph">
<p>This can be inferred by the fact that the <code>devices/</code> directory is by far the largest in the kernel.</p>
</div>
<div class="paragraph">
<p>The kernel is of course just an interface to hardware, and the hardware developers start developing their kernel stuff even before specs are publicly released, both to help with hardware development and to have things working when the announcement is made.</p>
</div>
<div class="paragraph">
<p>Furthermore, I believe that there are in-tree devices which have never been properly publicly documented. Linus is of course fine with this, since code == documentation for him, but it is not as easy for mere mortals.</p>
</div>
<div class="paragraph">
<p>There are some less hardware bound higher level layers in the kernel which might not require being in a hardware company, and a few people must be living off it.</p>
</div>
<div class="paragraph">
<p>But of course, those are heavily motivated by the underlying hardware characteristics, and it is very likely that most of the people working there were previously at a hardware company.</p>
</div>
<div class="paragraph">
<p>In that sense, therefore, the kernel is not as open as one might want to believe.</p>
</div>
<div class="paragraph">
<p>Of course, if there is some <a href="https://stackoverflow.com/questions/1697842/do-graphic-cards-have-instruction-sets-of-their-own/1697883">super useful and undocumented hardware that is just waiting there to be reverse engineered</a>, then that&#8217;s a much juicier target :-)</p>
</div>
</li>
<li>
<p>it is impossible to become rich with this knowledge.</p>
<div class="paragraph">
<p>This is partly implied by the fact that you need to be in a big company to make useful low level things, and therefore you will only be a tiny cog in the engine.</p>
</div>
<div class="paragraph">
<p>The key problem is that the entry cost of hardware design is just too insanely high for startups in general.</p>
</div>
</li>
<li>
<p>Is learning this the most useful thing that you think can do for society?</p>
<div class="paragraph">
<p>Or are you just learning it for job security and having a nice sounding title?</p>
</div>
<div class="paragraph">
<p>I&#8217;m not a huge fan of the person, but I think Jobs said it right: <a href="https://www.youtube.com/watch?v=FF-tKLISfPE" class="bare">https://www.youtube.com/watch?v=FF-tKLISfPE</a></p>
</div>
<div class="paragraph">
<p>First determine the useful goal, and then backtrack down to the most efficient thing you can do to reach it.</p>
</div>
</li>
<li>
<p>there are two things that sadden me compared to physics-based engineering:</p>
<div class="openblock">
<div class="content">
<div class="ulist">
<ul>
<li>
<p>you will never become eternally famous. All tech disappears sooner or later, while laws of nature, at least as useful approximations, stay unchanged.</p>
</li>
<li>
<p>every problem that you face is caused by imperfections introduced by other humans.</p>
<div class="paragraph">
<p>It is much easier to accept limitations of physics, and even natural selection in biology, which is are produced by a sentient being (?).</p>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="paragraph">
<p>Physics-based engineering, just like low level hardware, is of course completely closed source however, since wrestling against the laws of physics is about the most expensive thing humans can do.</p>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>Are you fine with those points, and ready to continue wasting your life with this crap?</p>
</div>
<div class="paragraph">
<p>Good. In that case, read on, and let&#8217;s have some fun together ;-)</p>
</div>
<div class="paragraph">
<p>Related: <a href="#soft-topics">Soft topics</a>.</p>
</div>
</div>
<div class="sect2">
<h3 id="qemu-buildroot-setup"><a class="anchor" href="#qemu-buildroot-setup"></a><a class="link" href="#qemu-buildroot-setup">1.2. QEMU Buildroot setup</a></h3>
<div class="sect3">
<h4 id="qemu-buildroot-setup-getting-started"><a class="anchor" href="#qemu-buildroot-setup-getting-started"></a><a class="link" href="#qemu-buildroot-setup-getting-started">1.1.1. QEMU Buildroot setup getting started</a></h4>
<h4 id="qemu-buildroot-setup-getting-started"><a class="anchor" href="#qemu-buildroot-setup-getting-started"></a><a class="link" href="#qemu-buildroot-setup-getting-started">1.2.1. QEMU Buildroot setup getting started</a></h4>
<div class="paragraph">
<p>This setup has been mostly tested on Ubuntu. For other host operating systems see: <a href="#supported-hosts">Section 33.1, &#8220;Supported hosts&#8221;</a>. For greater stability, consider using the <a href="#release-procedure">latest release</a> instead of master: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/releases" class="bare">https://github.com/cirosantilli/linux-kernel-module-cheat/releases</a></p>
</div>
@@ -2469,12 +2567,12 @@ hello /root/.profile
</div>
</div>
<div class="sect3">
<h4 id="how-to-hack-stuff"><a class="anchor" href="#how-to-hack-stuff"></a><a class="link" href="#how-to-hack-stuff">1.1.2. How to hack stuff</a></h4>
<h4 id="how-to-hack-stuff"><a class="anchor" href="#how-to-hack-stuff"></a><a class="link" href="#how-to-hack-stuff">1.2.2. How to hack stuff</a></h4>
<div class="paragraph">
<p>Besides a seamless <a href="#qemu-buildroot-setup-getting-started">initial build</a>, this project also aims to make it effortless to modify and rebuild several major components of the system, to serve as an awesome development setup.</p>
</div>
<div class="sect4">
<h5 id="your-first-linux-kernel-hack"><a class="anchor" href="#your-first-linux-kernel-hack"></a><a class="link" href="#your-first-linux-kernel-hack">1.1.2.1. Your first Linux kernel hack</a></h5>
<h5 id="your-first-linux-kernel-hack"><a class="anchor" href="#your-first-linux-kernel-hack"></a><a class="link" href="#your-first-linux-kernel-hack">1.2.2.1. Your first Linux kernel hack</a></h5>
<div class="paragraph">
<p>Let&#8217;s hack up the <a href="#linux-kernel-entry-point">Linux kernel entry point</a>, which is an easy place to start.</p>
</div>
@@ -2546,7 +2644,7 @@ hello /root/.profile
</div>
</div>
<div class="sect4">
<h5 id="your-first-kernel-module-hack"><a class="anchor" href="#your-first-kernel-module-hack"></a><a class="link" href="#your-first-kernel-module-hack">1.1.2.2. Your first kernel module hack</a></h5>
<h5 id="your-first-kernel-module-hack"><a class="anchor" href="#your-first-kernel-module-hack"></a><a class="link" href="#your-first-kernel-module-hack">1.2.2.2. Your first kernel module hack</a></h5>
<div class="paragraph">
<p>Edit <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/kernel_modules/hello.c">kernel_modules/hello.c</a> to contain:</p>
</div>
@@ -2634,7 +2732,7 @@ hello /root/.profile
</div>
</div>
<div class="sect4">
<h5 id="your-first-qemu-hack"><a class="anchor" href="#your-first-qemu-hack"></a><a class="link" href="#your-first-qemu-hack">1.1.2.3. Your first QEMU hack</a></h5>
<h5 id="your-first-qemu-hack"><a class="anchor" href="#your-first-qemu-hack"></a><a class="link" href="#your-first-qemu-hack">1.2.2.3. Your first QEMU hack</a></h5>
<div class="paragraph">
<p>Not satisfied with mere software? OK then, let&#8217;s hack up the QEMU x86 CPU identification:</p>
</div>
@@ -2700,14 +2798,14 @@ hello /root/.profile
<p>If you really want to develop semiconductors, your only choice is to join an university or a semiconductor company that has the EDA licenses.</p>
</div>
<div class="paragraph">
<p>See also: <a href="#should-you-waste-your-life-with-systems-programming">Section 33.21.2, &#8220;Should you waste your life with systems programming?&#8221;</a>.</p>
<p>See also: <a href="#should-you-waste-your-life-with-systems-programming">Section 1.1, &#8220;Should you waste your life with systems programming?&#8221;</a>.</p>
</div>
<div class="paragraph">
<p>While hacking QEMU, you will likely want to GDB step its source. That is trivial since QEMU is just another userland program like any other, but our setup has a shortcut to make it even more convenient, see: <a href="#debug-the-emulator">Section 18.8, &#8220;Debug the emulator&#8221;</a>.</p>
</div>
</div>
<div class="sect4">
<h5 id="your-first-glibc-hack"><a class="anchor" href="#your-first-glibc-hack"></a><a class="link" href="#your-first-glibc-hack">1.1.2.4. Your first glibc hack</a></h5>
<h5 id="your-first-glibc-hack"><a class="anchor" href="#your-first-glibc-hack"></a><a class="link" href="#your-first-glibc-hack">1.2.2.4. Your first glibc hack</a></h5>
<div class="paragraph">
<p>We use <a href="#libc-choice">glibc as our default libc now</a>, and it is tracked as an unmodified submodule at <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/submodules/glibc">submodules/glibc</a>, at the exact same version that Buildroot has it, which can be found at: <a href="https://github.com/buildroot/buildroot/blob/2018.05/package/glibc/glibc.mk#L13">package/glibc/glibc.mk</a>. Buildroot 2018.05 applies no patches.</p>
</div>
@@ -2795,7 +2893,7 @@ index 706b20b492..23185948f3 100644
</div>
</div>
<div class="sect4">
<h5 id="your-first-binutils-hack"><a class="anchor" href="#your-first-binutils-hack"></a><a class="link" href="#your-first-binutils-hack">1.1.2.5. Your first Binutils hack</a></h5>
<h5 id="your-first-binutils-hack"><a class="anchor" href="#your-first-binutils-hack"></a><a class="link" href="#your-first-binutils-hack">1.2.2.5. Your first Binutils hack</a></h5>
<div class="paragraph">
<p>Have you ever felt that a single <code>inc</code> instruction was not enough? Really? Me too!</p>
</div>
@@ -2881,7 +2979,7 @@ index af583ce578..3cc341f303 100644
</div>
</div>
<div class="sect4">
<h5 id="your-first-gcc-hack"><a class="anchor" href="#your-first-gcc-hack"></a><a class="link" href="#your-first-gcc-hack">1.1.2.6. Your first GCC hack</a></h5>
<h5 id="your-first-gcc-hack"><a class="anchor" href="#your-first-gcc-hack"></a><a class="link" href="#your-first-gcc-hack">1.2.2.6. Your first GCC hack</a></h5>
<div class="paragraph">
<p>OK, now time to hack GCC.</p>
</div>
@@ -2984,7 +3082,7 @@ j = 0</pre>
</div>
</div>
<div class="sect3">
<h4 id="about-the-qemu-buildroot-setup"><a class="anchor" href="#about-the-qemu-buildroot-setup"></a><a class="link" href="#about-the-qemu-buildroot-setup">1.1.3. About the QEMU Buildroot setup</a></h4>
<h4 id="about-the-qemu-buildroot-setup"><a class="anchor" href="#about-the-qemu-buildroot-setup"></a><a class="link" href="#about-the-qemu-buildroot-setup">1.2.3. About the QEMU Buildroot setup</a></h4>
<div class="paragraph">
<p>This is our reference setup, and the best supported one, use it unless you have good reason not to.</p>
</div>
@@ -3007,7 +3105,7 @@ j = 0</pre>
</div>
</div>
<div class="sect2">
<h3 id="dry-run"><a class="anchor" href="#dry-run"></a><a class="link" href="#dry-run">1.2. Dry run to get commands for your project</a></h3>
<h3 id="dry-run"><a class="anchor" href="#dry-run"></a><a class="link" href="#dry-run">1.3. Dry run to get commands for your project</a></h3>
<div class="paragraph">
<p>One of the major features of this repository is that we try to support the <code>--dry-run</code> option really well for all scripts.</p>
</div>
@@ -3093,9 +3191,9 @@ j = 0</pre>
</div>
</div>
<div class="sect2">
<h3 id="gem5-buildroot-setup"><a class="anchor" href="#gem5-buildroot-setup"></a><a class="link" href="#gem5-buildroot-setup">1.3. gem5 Buildroot setup</a></h3>
<h3 id="gem5-buildroot-setup"><a class="anchor" href="#gem5-buildroot-setup"></a><a class="link" href="#gem5-buildroot-setup">1.4. gem5 Buildroot setup</a></h3>
<div class="sect3">
<h4 id="about-the-gem5-buildroot-setup"><a class="anchor" href="#about-the-gem5-buildroot-setup"></a><a class="link" href="#about-the-gem5-buildroot-setup">1.3.1. About the gem5 Buildroot setup</a></h4>
<h4 id="about-the-gem5-buildroot-setup"><a class="anchor" href="#about-the-gem5-buildroot-setup"></a><a class="link" href="#about-the-gem5-buildroot-setup">1.4.1. About the gem5 Buildroot setup</a></h4>
<div class="paragraph">
<p>This setup is like the <a href="#qemu-buildroot-setup">QEMU Buildroot setup</a>, but it uses <a href="http://gem5.org/">gem5</a> instead of QEMU as a system simulator.</p>
</div>
@@ -3132,7 +3230,7 @@ j = 0</pre>
</div>
</div>
<div class="sect3">
<h4 id="gem5-buildroot-setup-getting-started"><a class="anchor" href="#gem5-buildroot-setup-getting-started"></a><a class="link" href="#gem5-buildroot-setup-getting-started">1.3.2. gem5 Buildroot setup getting started</a></h4>
<h4 id="gem5-buildroot-setup-getting-started"><a class="anchor" href="#gem5-buildroot-setup-getting-started"></a><a class="link" href="#gem5-buildroot-setup-getting-started">1.4.2. gem5 Buildroot setup getting started</a></h4>
<div class="paragraph">
<p>For the most part, if you just add the <code>--emulator gem5</code> option or <code>*-gem5</code> suffix to all commands and everything should magically work.</p>
</div>
@@ -3226,7 +3324,7 @@ j = 0</pre>
</div>
</div>
<div class="sect2">
<h3 id="docker"><a class="anchor" href="#docker"></a><a class="link" href="#docker">1.4. Docker host setup</a></h3>
<h3 id="docker"><a class="anchor" href="#docker"></a><a class="link" href="#docker">1.5. Docker host setup</a></h3>
<div class="paragraph">
<p>This repository has been tested inside clean <a href="https://en.wikipedia.org/wiki/Docker_(software)">Docker</a> containers.</p>
</div>
@@ -3375,9 +3473,9 @@ j = 0</pre>
</div>
</div>
<div class="sect2">
<h3 id="prebuilt"><a class="anchor" href="#prebuilt"></a><a class="link" href="#prebuilt">1.5. Prebuilt setup</a></h3>
<h3 id="prebuilt"><a class="anchor" href="#prebuilt"></a><a class="link" href="#prebuilt">1.6. Prebuilt setup</a></h3>
<div class="sect3">
<h4 id="about-the-prebuilt-setup"><a class="anchor" href="#about-the-prebuilt-setup"></a><a class="link" href="#about-the-prebuilt-setup">1.5.1. About the prebuilt setup</a></h4>
<h4 id="about-the-prebuilt-setup"><a class="anchor" href="#about-the-prebuilt-setup"></a><a class="link" href="#about-the-prebuilt-setup">1.6.1. About the prebuilt setup</a></h4>
<div class="paragraph">
<p>This setup uses prebuilt binaries that we upload to GitHub from time to time.</p>
</div>
@@ -3447,7 +3545,7 @@ j = 0</pre>
</div>
</div>
<div class="sect3">
<h4 id="prebuilt-setup-getting-started"><a class="anchor" href="#prebuilt-setup-getting-started"></a><a class="link" href="#prebuilt-setup-getting-started">1.5.2. Prebuilt setup getting started</a></h4>
<h4 id="prebuilt-setup-getting-started"><a class="anchor" href="#prebuilt-setup-getting-started"></a><a class="link" href="#prebuilt-setup-getting-started">1.6.2. Prebuilt setup getting started</a></h4>
<div class="paragraph">
<p>Checkout to the latest tag and use the Ubuntu packaged QEMU to boot Linux:</p>
</div>
@@ -3535,7 +3633,7 @@ unzip lkmc-*.zip
</div>
</div>
<div class="sect2">
<h3 id="host"><a class="anchor" href="#host"></a><a class="link" href="#host">1.6. Host kernel module setup</a></h3>
<h3 id="host"><a class="anchor" href="#host"></a><a class="link" href="#host">1.7. Host kernel module setup</a></h3>
<div class="paragraph">
<p><strong>THIS IS DANGEROUS (AND FUN), YOU HAVE BEEN WARNED</strong></p>
</div>
@@ -3640,7 +3738,7 @@ sudo lsmod | grep hello</pre>
</div>
</div>
<div class="sect3">
<h4 id="hello-host"><a class="anchor" href="#hello-host"></a><a class="link" href="#hello-host">1.6.1. Hello host</a></h4>
<h4 id="hello-host"><a class="anchor" href="#hello-host"></a><a class="link" href="#hello-host">1.7.1. Hello host</a></h4>
<div class="paragraph">
<p>Minimal host build system example:</p>
</div>
@@ -3657,9 +3755,9 @@ dmesg</pre>
</div>
</div>
<div class="sect2">
<h3 id="userland-setup"><a class="anchor" href="#userland-setup"></a><a class="link" href="#userland-setup">1.7. Userland setup</a></h3>
<h3 id="userland-setup"><a class="anchor" href="#userland-setup"></a><a class="link" href="#userland-setup">1.8. Userland setup</a></h3>
<div class="sect3">
<h4 id="about-the-userland-setup"><a class="anchor" href="#about-the-userland-setup"></a><a class="link" href="#about-the-userland-setup">1.7.1. About the userland setup</a></h4>
<h4 id="about-the-userland-setup"><a class="anchor" href="#about-the-userland-setup"></a><a class="link" href="#about-the-userland-setup">1.8.1. About the userland setup</a></h4>
<div class="paragraph">
<p>In order to test the kernel and emulators, userland content in the form of executables and scripts is of course required, and we store it mostly under:</p>
</div>
@@ -3709,14 +3807,14 @@ dmesg</pre>
</div>
</div>
<div class="sect3">
<h4 id="userland-setup-getting-started"><a class="anchor" href="#userland-setup-getting-started"></a><a class="link" href="#userland-setup-getting-started">1.7.2. Userland setup getting started</a></h4>
<h4 id="userland-setup-getting-started"><a class="anchor" href="#userland-setup-getting-started"></a><a class="link" href="#userland-setup-getting-started">1.8.2. Userland setup getting started</a></h4>
<div class="paragraph">
<p>There are several ways to run our <a href="#userland-content">Userland content</a>, notably:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>natively on the host as shown at: <a href="#userland-setup-getting-started-natively">Section 1.7.2.1, &#8220;Userland setup getting started natively&#8221;</a></p>
<p>natively on the host as shown at: <a href="#userland-setup-getting-started-natively">Section 1.8.2.1, &#8220;Userland setup getting started natively&#8221;</a></p>
<div class="paragraph">
<p>Can only run examples compatible with your host CPU architecture and OS, but has the fastest setup and runtimes.</p>
</div>
@@ -3728,7 +3826,7 @@ dmesg</pre>
<div class="ulist">
<ul>
<li>
<p>the host prebuilt toolchain: <a href="#userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode">Section 1.7.2.2, &#8220;Userland setup getting started with prebuilt toolchain and QEMU user mode&#8221;</a></p>
<p>the host prebuilt toolchain: <a href="#userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode">Section 1.8.2.2, &#8220;Userland setup getting started with prebuilt toolchain and QEMU user mode&#8221;</a></p>
</li>
<li>
<p>the Buildroot toolchain you built yourself: <a href="#qemu-user-mode-getting-started">Section 10.1, &#8220;QEMU user mode getting started&#8221;</a></p>
@@ -3756,7 +3854,7 @@ dmesg</pre>
</div>
</li>
<li>
<p>from full system simulation as shown at: <a href="#qemu-buildroot-setup-getting-started">Section 1.1.1, &#8220;QEMU Buildroot setup getting started&#8221;</a>.</p>
<p>from full system simulation as shown at: <a href="#qemu-buildroot-setup-getting-started">Section 1.2.1, &#8220;QEMU Buildroot setup getting started&#8221;</a>.</p>
<div class="paragraph">
<p>This is the most reproducible and controlled environment, and all examples work there. But also the slower one to setup.</p>
</div>
@@ -3764,7 +3862,7 @@ dmesg</pre>
</ul>
</div>
<div class="sect4">
<h5 id="userland-setup-getting-started-natively"><a class="anchor" href="#userland-setup-getting-started-natively"></a><a class="link" href="#userland-setup-getting-started-natively">1.7.2.1. Userland setup getting started natively</a></h5>
<h5 id="userland-setup-getting-started-natively"><a class="anchor" href="#userland-setup-getting-started-natively"></a><a class="link" href="#userland-setup-getting-started-natively">1.8.2.1. Userland setup getting started natively</a></h5>
<div class="paragraph">
<p>With this setup, we will use the host toolchain and execute executables directly on the host.</p>
</div>
@@ -3908,7 +4006,7 @@ cd userland
</div>
</div>
<div class="sect4">
<h5 id="userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode"><a class="anchor" href="#userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode"></a><a class="link" href="#userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode">1.7.2.2. Userland setup getting started with prebuilt toolchain and QEMU user mode</a></h5>
<h5 id="userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode"><a class="anchor" href="#userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode"></a><a class="link" href="#userland-setup-getting-started-with-prebuilt-toolchain-and-qemu-user-mode">1.8.2.2. Userland setup getting started with prebuilt toolchain and QEMU user mode</a></h5>
<div class="paragraph">
<p>If you are lazy to built the Buildroot toolchain and QEMU, but want to run e.g. ARM <a href="#userland-assembly">Userland assembly</a> in <a href="#user-mode-simulation">User mode simulation</a>, you can get away on Ubuntu 18.04 with just:</p>
</div>
@@ -3946,7 +4044,7 @@ cd userland
</ul>
</div>
<div class="paragraph">
<p>This present the usual trade-offs of using prebuilts as mentioned at: <a href="#prebuilt">Section 1.5, &#8220;Prebuilt setup&#8221;</a>.</p>
<p>This present the usual trade-offs of using prebuilts as mentioned at: <a href="#prebuilt">Section 1.6, &#8220;Prebuilt setup&#8221;</a>.</p>
</div>
<div class="paragraph">
<p>Other functionality are analogous, e.g. testing:</p>
@@ -3979,7 +4077,7 @@ cd userland
</div>
</div>
<div class="sect4">
<h5 id="userland-setup-getting-started-full-system"><a class="anchor" href="#userland-setup-getting-started-full-system"></a><a class="link" href="#userland-setup-getting-started-full-system">1.7.2.3. Userland setup getting started full system</a></h5>
<h5 id="userland-setup-getting-started-full-system"><a class="anchor" href="#userland-setup-getting-started-full-system"></a><a class="link" href="#userland-setup-getting-started-full-system">1.8.2.3. Userland setup getting started full system</a></h5>
<div class="paragraph">
<p>First ensure that <a href="#qemu-buildroot-setup">QEMU Buildroot setup</a> is working.</p>
</div>
@@ -3987,7 +4085,7 @@ cd userland
<p>After doing that setup, you can already execute your userland programs from inside QEMU: the only missing step is how to rebuild executables and run them.</p>
</div>
<div class="paragraph">
<p>And the answer is exactly analogous to what is shown at: <a href="#your-first-kernel-module-hack">Section 1.1.2.2, &#8220;Your first kernel module hack&#8221;</a></p>
<p>And the answer is exactly analogous to what is shown at: <a href="#your-first-kernel-module-hack">Section 1.2.2.2, &#8220;Your first kernel module hack&#8221;</a></p>
</div>
<div class="paragraph">
<p>For example, if we modify <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/c/hello.c">userland/c/hello.c</a> to print out something different, we can just rebuild it with:</p>
@@ -4028,9 +4126,9 @@ cd userland
</div>
</div>
<div class="sect2">
<h3 id="baremetal-setup"><a class="anchor" href="#baremetal-setup"></a><a class="link" href="#baremetal-setup">1.8. Baremetal setup</a></h3>
<h3 id="baremetal-setup"><a class="anchor" href="#baremetal-setup"></a><a class="link" href="#baremetal-setup">1.9. Baremetal setup</a></h3>
<div class="sect3">
<h4 id="about-the-baremetal-setup"><a class="anchor" href="#about-the-baremetal-setup"></a><a class="link" href="#about-the-baremetal-setup">1.8.1. About the baremetal setup</a></h4>
<h4 id="about-the-baremetal-setup"><a class="anchor" href="#about-the-baremetal-setup"></a><a class="link" href="#about-the-baremetal-setup">1.9.1. About the baremetal setup</a></h4>
<div class="paragraph">
<p>This setup does not use the Linux kernel nor Buildroot at all: it just runs your very own minimal OS.</p>
</div>
@@ -4051,7 +4149,7 @@ cd userland
</div>
</div>
<div class="sect3">
<h4 id="baremetal-setup-getting-started"><a class="anchor" href="#baremetal-setup-getting-started"></a><a class="link" href="#baremetal-setup-getting-started">1.8.2. Baremetal setup getting started</a></h4>
<h4 id="baremetal-setup-getting-started"><a class="anchor" href="#baremetal-setup-getting-started"></a><a class="link" href="#baremetal-setup-getting-started">1.9.2. Baremetal setup getting started</a></h4>
<div class="paragraph">
<p>Every <code>.c</code> file inside <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/baremetal/">baremetal/</a> and <code>.S</code> file inside <code>baremetal/arch/&lt;arch&gt;/</code> generates a separate baremetal image.</p>
</div>
@@ -4262,7 +4360,7 @@ echo "$(./getvar --arch aarch64 --baremetal userland/c/hello.c --emulator gem5 -
</div>
</div>
<div class="sect2">
<h3 id="build-the-documentation"><a class="anchor" href="#build-the-documentation"></a><a class="link" href="#build-the-documentation">1.9. Build the documentation</a></h3>
<h3 id="build-the-documentation"><a class="anchor" href="#build-the-documentation"></a><a class="link" href="#build-the-documentation">1.10. Build the documentation</a></h3>
<div class="paragraph">
<p>You don&#8217;t need to depend on GitHub.</p>
</div>
@@ -7874,7 +7972,7 @@ qw er</pre>
<p><code>./run --userland</code> path resolution is analogous to <a href="#baremetal-setup-getting-started">that of <code>./run --baremetal</code></a>.</p>
</div>
<div class="paragraph">
<p><code>./build user-mode-qemu</code> first builds Buildroot, and then runs <code>./build-userland</code>, which is further documented at: <a href="#userland-setup">Section 1.7, &#8220;Userland setup&#8221;</a>. It also builds QEMU. If you ahve already done a <a href="#qemu-buildroot-setup">QEMU Buildroot setup</a> previously, this will be very fast.</p>
<p><code>./build user-mode-qemu</code> first builds Buildroot, and then runs <code>./build-userland</code>, which is further documented at: <a href="#userland-setup">Section 1.8, &#8220;Userland setup&#8221;</a>. It also builds QEMU. If you ahve already done a <a href="#qemu-buildroot-setup">QEMU Buildroot setup</a> previously, this will be very fast.</p>
</div>
<div class="paragraph">
<p>If you modify the userland programs, rebuild simply with:</p>
@@ -8849,7 +8947,7 @@ Program aborted at tick 0</pre>
</div>
</li>
<li>
<p>we would have to think how to not have to include the kernel modules twice in the root filesystem, but still have <a href="#9p">9P</a> working for fast development as described at: <a href="#your-first-kernel-module-hack">Section 1.1.2.2, &#8220;Your first kernel module hack&#8221;</a></p>
<p>we would have to think how to not have to include the kernel modules twice in the root filesystem, but still have <a href="#9p">9P</a> working for fast development as described at: <a href="#your-first-kernel-module-hack">Section 1.2.2.2, &#8220;Your first kernel module hack&#8221;</a></p>
</li>
</ul>
</div>
@@ -18654,7 +18752,7 @@ root</pre>
<h2 id="gem5"><a class="anchor" href="#gem5"></a><a class="link" href="#gem5">19. gem5</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>Getting started at: <a href="#gem5-buildroot-setup">Section 1.3, &#8220;gem5 Buildroot setup&#8221;</a>.</p>
<p>Getting started at: <a href="#gem5-buildroot-setup">Section 1.4, &#8220;gem5 Buildroot setup&#8221;</a>.</p>
</div>
<div class="paragraph">
<p>gem5 has a bunch of crappiness, mostly described at: <a href="#gem5-vs-qemu">gem5 vs QEMU</a>, but it does deserve some credit on the following points:</p>
@@ -22491,8 +22589,8 @@ wbWidth=8</pre>
</div>
</div>
<div class="sect5">
<h6 id="gem5-utilo3-pipeview-py-o3-pipeline-viewer"><a class="anchor" href="#gem5-utilo3-pipeview-py-o3-pipeline-viewer"></a><a class="link" href="#gem5-utilo3-pipeview-py-o3-pipeline-viewer">19.16.1.3.2. gem5 util/o3-pipeview.py O3 pipeline viewer</a></h6>
<div id="gem5-util-o3-pipeview-py-o3-pipeline-viewer" class="paragraph">
<h6 id="gem5-util-o3-pipeview-py-o3-pipeline-viewer"><a class="anchor" href="#gem5-util-o3-pipeview-py-o3-pipeline-viewer"></a><a class="link" href="#gem5-util-o3-pipeview-py-o3-pipeline-viewer">19.16.1.3.2. gem5 util/o3-pipeview.py O3 pipeline viewer</a></h6>
<div class="paragraph">
<p>Mentioned at: <a href="http://www.m5sim.org/Visualization" class="bare">http://www.m5sim.org/Visualization</a></p>
</div>
<div class="literalblock">
@@ -22533,7 +22631,7 @@ less o3pipeview.tmp.log</pre>
<p><a href="http://learning.gem5.org/tutorial/presentations/vis-o3-gem5.pdf" class="bare">http://learning.gem5.org/tutorial/presentations/vis-o3-gem5.pdf</a></p>
</div>
<div class="paragraph">
<p>Appears to be browser based, so you can zoom in and out, rather than the forced wrapping as for <a href="#gem5-util-o3-pipeview-py-o3-pipeline-viewer">[gem5-util-o3-pipeview-py-o3-pipeline-viewer]</a>.</p>
<p>Appears to be browser based, so you can zoom in and out, rather than the forced wrapping as for <a href="#gem5-util-o3-pipeview-py-o3-pipeline-viewer">gem5 util/o3-pipeview.py O3 pipeline viewer</a>.</p>
</div>
<div class="paragraph">
<p>Uses the same data source as <code>util/o3-pipeview.py</code>.</p>
@@ -25736,7 +25834,7 @@ non-atomic 19</pre>
<p>Let&#8217;s have a look at the arguably simplest example <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/arch/aarch64/freestanding/linux/hazardless.S">userland/arch/aarch64/freestanding/linux/hazardless.S</a>.</p>
</div>
<div class="paragraph">
<p>First let&#8217;s start with a <a href="#gem5-util-o3-pipeview-py-o3-pipeline-viewer">[gem5-util-o3-pipeview-py-o3-pipeline-viewer]</a> visualization:</p>
<p>First let&#8217;s start with a <a href="#gem5-util-o3-pipeview-py-o3-pipeline-viewer">gem5 util/o3-pipeview.py O3 pipeline viewer</a> visualization:</p>
</div>
<div id="hazardless-o3-pipeline" class="listingblock">
<div class="content">
@@ -29430,7 +29528,7 @@ cd ../..
<p>This section documents our test and educational userland content, such as <a href="#c">C</a>, <a href="#cpp">C++</a> and <a href="#posix">POSIX</a> examples, present mostly under <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/">userland/</a>.</p>
</div>
<div class="paragraph">
<p>Getting started at: <a href="#userland-setup">Section 1.7, &#8220;Userland setup&#8221;</a></p>
<p>Getting started at: <a href="#userland-setup">Section 1.8, &#8220;Userland setup&#8221;</a></p>
</div>
<div class="paragraph">
<p>Userland assembly content is located at: <a href="#userland-assembly">Section 22, &#8220;Userland assembly&#8221;</a>. It was split from this section basically because we were hitting the HTML <code>h6</code> limit, stupid web :-)</p>
@@ -29439,7 +29537,7 @@ cd ../..
<p>This content makes up the bulk of the <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/">userland/</a> directory.</p>
</div>
<div class="paragraph">
<p>The quickest way to run the arch agnostic examples, which comprise the majority of the examples, is natively as shown at: <a href="#userland-setup-getting-started-natively">Section 1.7.2.1, &#8220;Userland setup getting started natively&#8221;</a></p>
<p>The quickest way to run the arch agnostic examples, which comprise the majority of the examples, is natively as shown at: <a href="#userland-setup-getting-started-natively">Section 1.8.2.1, &#8220;Userland setup getting started natively&#8221;</a></p>
</div>
<div class="paragraph">
<p>This section was originally moved in here from: <a href="https://github.com/cirosantilli/cpp-cheat" class="bare">https://github.com/cirosantilli/cpp-cheat</a></p>
@@ -32651,7 +32749,7 @@ Solution Validates: avg error less than 1.000000e-13 on all three arrays
</ul>
</div>
<div class="paragraph">
<p>Like other userland programs, these programs can be run as explained at: <a href="#userland-setup">Section 1.7, &#8220;Userland setup&#8221;</a>.</p>
<p>Like other userland programs, these programs can be run as explained at: <a href="#userland-setup">Section 1.8, &#8220;Userland setup&#8221;</a>.</p>
</div>
<div class="paragraph">
<p>As a quick reminder, the fastest setups to get started are:</p>
@@ -33184,7 +33282,7 @@ When instructions do not interpret this operand encoding as the zero register, u
<p>Userland assembly is generally simpler, and a pre-requisite for <a href="#baremetal-setup">Baremetal setup</a>.</p>
</div>
<div class="paragraph">
<p>System-land assembly cheats will be put under: <a href="#baremetal-setup">Section 1.8, &#8220;Baremetal setup&#8221;</a>.</p>
<p>System-land assembly cheats will be put under: <a href="#baremetal-setup">Section 1.9, &#8220;Baremetal setup&#8221;</a>.</p>
</div>
</div>
<div class="sect2">
@@ -38029,7 +38127,7 @@ AArch64, see Procedure Call Standard for the ARM 64-bit Architecture.</p>
<h2 id="baremetal"><a class="anchor" href="#baremetal"></a><a class="link" href="#baremetal">27. Baremetal</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>Getting started at: <a href="#baremetal-setup">Section 1.8, &#8220;Baremetal setup&#8221;</a></p>
<p>Getting started at: <a href="#baremetal-setup">Section 1.9, &#8220;Baremetal setup&#8221;</a></p>
</div>
<div class="sect2">
<h3 id="baremetal-gdb-step-debug"><a class="anchor" href="#baremetal-gdb-step-debug"></a><a class="link" href="#baremetal-gdb-step-debug">27.1. Baremetal GDB step debug</a></h3>
@@ -43213,7 +43311,7 @@ CACHE2 S nyy
<div class="sect2">
<h3 id="documentation"><a class="anchor" href="#documentation"></a><a class="link" href="#documentation">33.5. Documentation</a></h3>
<div class="paragraph">
<p>To learn how to build the documentation see: <a href="#build-the-documentation">Section 1.9, &#8220;Build the documentation&#8221;</a>.</p>
<p>To learn how to build the documentation see: <a href="#build-the-documentation">Section 1.10, &#8220;Build the documentation&#8221;</a>.</p>
</div>
<div class="sect3">
<h4 id="documentation-verification"><a class="anchor" href="#documentation-verification"></a><a class="link" href="#documentation-verification">33.5.1. Documentation verification</a></h4>
@@ -44274,7 +44372,7 @@ git -C "$(./getvar buildroot_source_dir)" checkout -
<p>Source: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/copy-overlay">copy-overlay</a></p>
</div>
<div class="paragraph">
<p>Build Buildroot is required for the same reason as described at: <a href="#your-first-kernel-module-hack">Section 1.1.2.2, &#8220;Your first kernel module hack&#8221;</a>.</p>
<p>Build Buildroot is required for the same reason as described at: <a href="#your-first-kernel-module-hack">Section 1.2.2.2, &#8220;Your first kernel module hack&#8221;</a>.</p>
</div>
<div class="paragraph">
<p>However, since the <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/rootfs_overlay">rootfs_overlay</a> directory does not require compilation, unlike say <a href="#your-first-kernel-module-hack">kernel modules</a>, we also make it <a href="#9p">9P</a> available to the guest directly even without <code>./copy-overlay</code> at:</p>
@@ -45391,93 +45489,6 @@ git push --follow-tags
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="should-you-waste-your-life-with-systems-programming"><a class="anchor" href="#should-you-waste-your-life-with-systems-programming"></a><a class="link" href="#should-you-waste-your-life-with-systems-programming">33.21.2. Should you waste your life with systems programming?</a></h4>
<div class="paragraph">
<p>Being the hardcore person who fully understands an important complex system such as a computer, it does have a nice ring to it doesn&#8217;t it?</p>
</div>
<div class="paragraph">
<p>But before you dedicate your life to this nonsense, do consider the following points:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>almost all contributions to the kernel are done by large companies, and if you are not an employee in one of them, you are likely not going to be able to do much.</p>
<div class="paragraph">
<p>This can be inferred by the fact that the <code>devices/</code> directory is by far the largest in the kernel.</p>
</div>
<div class="paragraph">
<p>The kernel is of course just an interface to hardware, and the hardware developers start developing their kernel stuff even before specs are publicly released, both to help with hardware development and to have things working when the announcement is made.</p>
</div>
<div class="paragraph">
<p>Furthermore, I believe that there are in-tree devices which have never been properly publicly documented. Linus is of course fine with this, since code == documentation for him, but it is not as easy for mere mortals.</p>
</div>
<div class="paragraph">
<p>There are some less hardware bound higher level layers in the kernel which might not require being in a hardware company, and a few people must be living off it.</p>
</div>
<div class="paragraph">
<p>But of course, those are heavily motivated by the underlying hardware characteristics, and it is very likely that most of the people working there were previously at a hardware company.</p>
</div>
<div class="paragraph">
<p>In that sense, therefore, the kernel is not as open as one might want to believe.</p>
</div>
<div class="paragraph">
<p>Of course, if there is some <a href="https://stackoverflow.com/questions/1697842/do-graphic-cards-have-instruction-sets-of-their-own/1697883">super useful and undocumented hardware that is just waiting there to be reverse engineered</a>, then that&#8217;s a much juicier target :-)</p>
</div>
</li>
<li>
<p>it is impossible to become rich with this knowledge.</p>
<div class="paragraph">
<p>This is partly implied by the fact that you need to be in a big company to make useful low level things, and therefore you will only be a tiny cog in the engine.</p>
</div>
<div class="paragraph">
<p>The key problem is that the entry cost of hardware design is just too insanely high for startups in general.</p>
</div>
</li>
<li>
<p>Is learning this the most useful thing that you think can do for society?</p>
<div class="paragraph">
<p>Or are you just learning it for job security and having a nice sounding title?</p>
</div>
<div class="paragraph">
<p>I&#8217;m not a huge fan of the person, but I think Jobs said it right: <a href="https://www.youtube.com/watch?v=FF-tKLISfPE" class="bare">https://www.youtube.com/watch?v=FF-tKLISfPE</a></p>
</div>
<div class="paragraph">
<p>First determine the useful goal, and then backtrack down to the most efficient thing you can do to reach it.</p>
</div>
</li>
<li>
<p>there are two things that sadden me compared to physics-based engineering:</p>
<div class="openblock">
<div class="content">
<div class="ulist">
<ul>
<li>
<p>you will never become eternally famous. All tech disappears sooner or later, while laws of nature, at least as useful approximations, stay unchanged.</p>
</li>
<li>
<p>every problem that you face is caused by imperfections introduced by other humans.</p>
<div class="paragraph">
<p>It is much easier to accept limitations of physics, and even natural selection in biology, which is are produced by a sentient being (?).</p>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="paragraph">
<p>Physics-based engineering, just like low level hardware, is of course completely closed source however, since wrestling against the laws of physics is about the most expensive thing humans can do.</p>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>Are you fine with those points, and ready to continue wasting your life with this crap?</p>
</div>
<div class="paragraph">
<p>Good. In that case, read on, and let&#8217;s have some fun together ;-)</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="bibliography"><a class="anchor" href="#bibliography"></a><a class="link" href="#bibliography">33.22. Bibliography</a></h3>