mirror of
https://github.com/lupyuen/lupyuen.github.io.git
synced 2025-01-13 10:18:33 +08:00
Commit from GitHub Actions
This commit is contained in:
parent
5a28458b3f
commit
7231a55cc0
1 changed files with 80 additions and 59 deletions
|
@ -246,7 +246,10 @@ File Attributes
|
|||
<p>Indeed we have a problem: Double-Float and Soft-Float won’t mix! Let’s fix this…</p>
|
||||
<p>TODO: Pic of Rust Won’t Double-Float</p>
|
||||
<h1 id="rust-wont-double-float"><a class="doc-anchor" href="#rust-wont-double-float">§</a>2 Rust Won’t Double-Float</h1>
|
||||
<p><em>What if we ask Rust Compiler to compile for Double-Float?</em></p>
|
||||
<p><em>What if we ask Rust Compiler to compile for Double-Float: RV32IMAFDC?</em></p>
|
||||
<p><a href="https://www.qemu.org/docs/master/system/riscv/virt.html"><strong>QEMU RISC-V</strong></a> offically supports <a href="https://www.qemu.org/docs/master/system/riscv/virt.html"><strong><code>riscv32gc</code></strong></a>.</p>
|
||||
<p><a href="https://en.wikipedia.org/wiki/RISC-V#ISA_base_and_extensions">(“<strong><code>gc</code></strong>” in “<strong><code>riscv32gc</code></strong>” denotes <strong>IMAFDC</strong>)</a></p>
|
||||
<p>We could do this…</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>## Compile `hello_rust_main.rs` to `hello_rust.o`
|
||||
## for Double-Precision Hardware Floating-Point
|
||||
rustc \
|
||||
|
@ -259,13 +262,12 @@ rustc \
|
|||
hello_rust_main.rs \
|
||||
-o hello_rust.o
|
||||
</code></pre></div>
|
||||
<p>TODO: Explain riscv32gc</p>
|
||||
<p>Nope sorry it won’t work…</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>Error loading target specification:
|
||||
Could not find specification for target "riscv32gc-unknown-none-elf".
|
||||
Run `rustc --print target-list` for a list of built-in targets
|
||||
</code></pre></div>
|
||||
<p>That’s because <em>riscv32gc</em> isn’t a <strong>Predefined Rust Target</strong>…</p>
|
||||
<p>That’s because <strong><code>riscv32gc</code></strong> isn’t a <strong>Predefined Rust Target</strong>…</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>## List the Predefined Rust Targets for RISC-V.
|
||||
## Nope no riscv32gc!
|
||||
$ rustup target list | grep riscv
|
||||
|
@ -277,10 +279,10 @@ riscv64gc-unknown-linux-gnu
|
|||
riscv64gc-unknown-none-elf
|
||||
riscv64imac-unknown-none-elf
|
||||
</code></pre></div>
|
||||
<p>But we can create a <strong>Custom Rust Target</strong> for <em>riscv32gc</em>. Coming up next section!</p>
|
||||
<p>But we can create a <strong>Custom Rust Target</strong> for <strong><code>riscv32gc</code></strong>. Coming up next section!</p>
|
||||
<p><em>Won’t GCC Compiler have the same problem with Double-Float?</em></p>
|
||||
<p>When we list the <strong>Predefined GCC Targets</strong>…</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>## List the Predefined Targets for GCC RISC-V
|
||||
<div class="example-wrap"><pre class="language-bash"><code>## List the Predefined Targets for GCC RISC-V.
|
||||
## ABI means Application Binary Interface
|
||||
$ riscv64-unknown-elf-gcc --target-help
|
||||
|
||||
|
@ -293,8 +295,7 @@ Supported ABIs (for use with the -mabi= option):
|
|||
<li><strong><code>d</code></strong>: <strong>Double-Precision</strong> Hardware Floating-Point</li>
|
||||
</ul>
|
||||
<p>That’s why we saw <strong><code>ilp32d</code></strong> earlier…</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>## GCC compiles `hello_main.c` to `hello.o`
|
||||
## for RISC-V 32-bit (Double-Float)
|
||||
<div class="example-wrap"><pre class="language-bash"><code>## GCC compiles for RISC-V 32-bit (Double-Float)
|
||||
riscv64-unknown-elf-gcc \
|
||||
-march=rv32imafdc \
|
||||
-mabi=ilp32d \
|
||||
|
@ -303,35 +304,38 @@ riscv64-unknown-elf-gcc \
|
|||
<p><a href="https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html#index-mabi-5">(More about <strong>Application Binary Interfaces</strong>)</a></p>
|
||||
<p>TODO: Pic of Custom Target for Rust</p>
|
||||
<h1 id="custom-target-for-rust"><a class="doc-anchor" href="#custom-target-for-rust">§</a>3 Custom Target for Rust</h1>
|
||||
<p>TODO</p>
|
||||
<p>But nope it’s not supported! So we create a Rust Custom Target for <code>riscv32gc-unknown-none-elf</code>…</p>
|
||||
<ul>
|
||||
<li><a href="https://docs.rust-embedded.org/embedonomicon/custom-target.html">Custom Target for Rust</a></li>
|
||||
</ul>
|
||||
<p>Let’s dump the Rust Targets <code>riscv32i</code> and <code>riscv64gc</code> to compare…</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>$ rustc \
|
||||
<p><em>To compile Rust for Double-Float, we need a Custom Target: riscv32gc</em></p>
|
||||
<p><em>How to create the Custom Target?</em></p>
|
||||
<p>According to the <a href="https://docs.rust-embedded.org/embedonomicon/custom-target.html"><strong>Official Rust Docs</strong></a>, we dump a Predefined Rust Target: <strong><code>riscv32i</code></strong> </p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>## Dump the Predefined Rust Target:
|
||||
## riscv32i (32-bit RISC-V with Soft-Float)
|
||||
$ rustc \
|
||||
+nightly \
|
||||
-Z unstable-options \
|
||||
--print target-spec-json \
|
||||
--target riscv32i-unknown-none-elf
|
||||
|
||||
{
|
||||
"arch": "riscv32",
|
||||
"atomic-cas": false,
|
||||
"cpu": "generic-rv32",
|
||||
"arch": "riscv32",
|
||||
"atomic-cas": false,
|
||||
"cpu": "generic-rv32",
|
||||
"data-layout": "e-m:e-p:32:32-i64:64-n32-S128",
|
||||
"eh-frame-header": false,
|
||||
"eh-frame-header": false,
|
||||
"emit-debug-gdb-scripts": false,
|
||||
"is-builtin": true,
|
||||
"linker": "rust-lld",
|
||||
"linker-flavor": "ld.lld",
|
||||
"llvm-target": "riscv32",
|
||||
"max-atomic-width": 0,
|
||||
"panic-strategy": "abort",
|
||||
"relocation-model": "static",
|
||||
"is-builtin": true,
|
||||
"linker": "rust-lld",
|
||||
"linker-flavor": "ld.lld",
|
||||
"llvm-target": "riscv32",
|
||||
"max-atomic-width": 0,
|
||||
"panic-strategy": "abort",
|
||||
"relocation-model": "static",
|
||||
"target-pointer-width": "32"
|
||||
}
|
||||
|
||||
</code></pre></div>
|
||||
<p>That’s the Rust Definition of <strong><code>riscv32i</code></strong>: 32-bit RISC-V with Soft-Float.</p>
|
||||
<p>We do the same for <strong><code>riscv64gc</code></strong>: 64-bit RISC-V with Double-Float…</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>## Dump the Predefined Rust Target:
|
||||
## riscv64gc (64-bit RISC-V with Hard-Float)
|
||||
$ rustc \
|
||||
+nightly \
|
||||
-Z unstable-options \
|
||||
|
@ -339,62 +343,79 @@ $ rustc \
|
|||
--target riscv64gc-unknown-none-elf
|
||||
|
||||
{
|
||||
"arch": "riscv64",
|
||||
"code-model": "medium",
|
||||
"cpu": "generic-rv64",
|
||||
"arch": "riscv64",
|
||||
"code-model": "medium",
|
||||
"cpu": "generic-rv64",
|
||||
"data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
|
||||
"eh-frame-header": false,
|
||||
"eh-frame-header": false,
|
||||
"emit-debug-gdb-scripts": false,
|
||||
"features": "+m,+a,+f,+d,+c",
|
||||
"is-builtin": true,
|
||||
"linker": "rust-lld",
|
||||
"features": "+m,+a,+f,+d,+c",
|
||||
"is-builtin": true,
|
||||
"linker": "rust-lld",
|
||||
"linker-flavor": "ld.lld",
|
||||
"llvm-abiname": "lp64d",
|
||||
"llvm-target": "riscv64",
|
||||
"max-atomic-width": 64,
|
||||
"panic-strategy": "abort",
|
||||
"relocation-model": "static",
|
||||
"supported-sanitizers": [
|
||||
"kernel-address"
|
||||
],
|
||||
"llvm-abiname": "lp64d",
|
||||
"llvm-target": "riscv64",
|
||||
"max-atomic-width": 64,
|
||||
"panic-strategy": "abort",
|
||||
"relocation-model": "static",
|
||||
"supported-sanitizers": [ "kernel-address" ],
|
||||
"target-pointer-width": "64"
|
||||
}
|
||||
</code></pre></div>
|
||||
<p>Based on the above, we create our Rust Custom Target: <a href="riscv32gc-unknown-none-elf.json">riscv32gc-unknown-none-elf.json</a></p>
|
||||
<p><em>We need to mash the Two Targets into a New Target?</em></p>
|
||||
<p>Exactly! Based on the above, we create our <strong>Rust Custom Target</strong>: <a href="https://github.com/lupyuen/nuttx-rust-app/blob/main/riscv32gc-unknown-none-elf.json"><em>riscv32gc-unknown-none-elf.json</em></a></p>
|
||||
<div class="example-wrap"><pre class="language-json"><code>{
|
||||
"arch": "riscv32",
|
||||
"cpu": "generic-rv32",
|
||||
"arch": "riscv32",
|
||||
"cpu": "generic-rv32",
|
||||
"data-layout": "e-m:e-p:32:32-i64:64-n32-S128",
|
||||
"eh-frame-header": false,
|
||||
"eh-frame-header": false,
|
||||
"emit-debug-gdb-scripts": false,
|
||||
"features": "+m,+a,+f,+d,+c",
|
||||
"linker": "rust-lld",
|
||||
"features": "+m,+a,+f,+d,+c",
|
||||
"linker": "rust-lld",
|
||||
"linker-flavor": "ld.lld",
|
||||
"llvm-abiname": "ilp32d",
|
||||
"llvm-target": "riscv32",
|
||||
"max-atomic-width": 0,
|
||||
"panic-strategy": "abort",
|
||||
"relocation-model": "static",
|
||||
"llvm-abiname": "ilp32d",
|
||||
"llvm-target": "riscv32",
|
||||
"max-atomic-width": 0,
|
||||
"panic-strategy": "abort",
|
||||
"relocation-model": "static",
|
||||
"target-pointer-width": "32"
|
||||
}
|
||||
</code></pre></div>
|
||||
<p>Which is based on <code>riscv32i</code> with these changes…</p>
|
||||
<p>Which is <a href="TODO"><strong><code>riscv32i</code></strong></a> plus these changes…</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p>Removed <code>"atomic-cas": false</code></p>
|
||||
<p>Removed <strong><code>"is-builtin": true</code></strong></p>
|
||||
<p>TODO</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Added <code>"features": "+m,+a,+f,+d,+c"</code></p>
|
||||
<p>Removed <strong><code>"atomic-cas": false</code></strong></p>
|
||||
<p>TODO</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Removed <code>"is-builtin": true</code></p>
|
||||
<p>Added <strong><code>"features": "+m,+a,+f,+d,+c"</code></strong></p>
|
||||
<p>TODO</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Added <code>"llvm-abiname": "ilp32d"</code></p>
|
||||
<p>(<code>ilp32d</code> comes from <code>make --trace</code> above)</p>
|
||||
<p><a href="https://lupyuen.github.io/articles/rust#custom-rust-target-for-bl602">(More about <code>llvm-abiname</code>)</a></p>
|
||||
<p>Added <strong><code>"llvm-abiname": "ilp32d"</code></strong></p>
|
||||
<p>(<strong><code>ilp32d</code></strong> comes from <strong><code>make --trace</code></strong> above)</p>
|
||||
<p><a href="https://lupyuen.github.io/articles/rust#custom-rust-target-for-bl602">(More about <strong><code>llvm-abiname</code></strong>)</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
<p>Once Again: This is how we splice the Two Predefined Targets to create our Custom Target <strong><code>riscv32gc</code></strong>…</p>
|
||||
<span style="font-size:90%">
|
||||
<div><table><thead><tr><th></th><th>riscv32i</th><th>riscv64gc</th><th>riscv32gc</th></tr></thead><tbody>
|
||||
<tr><td><em>arch</em></td><td><strong>riscv32</strong></td><td>riscv64</td><td><strong>riscv32</strong></td></tr>
|
||||
<tr><td><em>atomic-cas</em></td><td>false</td><td></td><td></td></tr>
|
||||
<tr><td><em>cpu</em></td><td><strong>generic-rv32</strong></td><td>generic-rv64</td><td><strong>generic-rv32</strong></td></tr>
|
||||
<tr><td><em>data-layout</em></td><td><strong>e-m:e-p:32…</strong></td><td>e-m:e-p:64…</td><td><strong>e-m:e-p:32…</strong></td></tr>
|
||||
<tr><td><em>features</em></td><td></td><td><strong>+m,+a,+f,+d,+c</strong></td><td><strong>+m,+a,+f,+d,+c</strong></td></tr>
|
||||
<tr><td><em>is-builtin</em></td><td>true</td><td>true</td><td></td></tr>
|
||||
<tr><td><em>llvm-abiname</em></td><td></td><td>lp64d</td><td>ilp32d</td></tr>
|
||||
<tr><td><em>llvm-target</em></td><td><strong>riscv32</strong></td><td>riscv64</td><td><strong>riscv32</strong></td></tr>
|
||||
<tr><td><em>max-atomic-width</em></td><td></td><td>64</td><td>0</td></tr>
|
||||
<tr><td><em>target-pointer-width</em></td><td><strong>32</strong></td><td>64</td><td><strong>32</strong></td></tr>
|
||||
</tbody></table>
|
||||
</div></span>
|
||||
<p>TODO: Pic of Rust Core Library</p>
|
||||
<h1 id="build-the-rust-core-library"><a class="doc-anchor" href="#build-the-rust-core-library">§</a>4 Build the Rust Core Library</h1>
|
||||
<p>TODO</p>
|
||||
|
|
Loading…
Reference in a new issue