sparc-unknown-none-elf
Tier: 3
用于裸机 32 位 SPARC V7 和 V8 系统的 Rust,例如 Gaisler LEON3。
目标 | 描述 |
---|---|
sparc-unknown-none-elf | SPARC V7 32 位 (freestanding, hardfloat) |
目标维护者
- Jonathan Pallant, [email protected], https://ferrous-systems.com
要求
此目标是交叉编译的。不支持 std
。没有默认的分配器,但是可以通过提供分配器来使用 alloc
。
默认情况下,使用此目标生成的代码应在任何 SPARC
硬件上运行;启用额外的目标特性可能会提高此基线。
-
-Ctarget-cpu=v8
添加额外的 SPARC V8 指令。 -
-Ctarget-cpu=leon3
添加 SPARC V8 指令并设置调度以适应 Gaisler Leon3。
标记为 extern "C"
的函数使用标准的 SPARC 架构调用约定。
此目标生成 ELF 二进制文件。任何其他格式或二进制布局的特殊考虑都需要链接器选项或链接器脚本。
构建目标
您可以通过将其添加到 config.toml
中的 target
列表来构建支持该目标的 Rust
[build]
build-stage = 1
host = ["<target for your host>"]
target = ["<target for your host>", "sparc-unknown-none-elf"]
将 <target for your host>
替换为 x86_64-unknown-linux-gnu
或适合您主机机器的任何其他目标。
构建 Rust 程序
要使用此目标进行构建,请将其传递给 --target
参数,例如
cargo build --target sparc-unknown-none-elf
此目标使用 GCC 作为链接器,因此您需要一个合适的 GCC 兼容的 sparc-unknown-none
工具链。默认的链接器二进制文件是 sparc-elf-gcc
,但您可以像下面这样在您的项目配置中覆盖它
.cargo/config.toml
:
[target.sparc-unknown-none-elf]
linker = "sparc-custom-elf-gcc"
测试
由于 sparc-unknown-none-elf
支持各种不同的环境并且不支持 std
,因此此目标不支持运行 Rust 测试套件。
交叉编译工具链和 C 代码
此目标最初使用 Gaisler 的 BCC2 以及 TSIM Leon3 处理器模拟器进行测试。 BCC2 GCC 和 BCC2 Clang 都已证明可以工作。要使用这些工具,您的项目配置应包含如下内容
.cargo/config.toml
:
[target.sparc-unknown-none-elf]
linker = "sparc-gaisler-elf-gcc"
runner = "tsim-leon3"
[build]
target = ["sparc-unknown-none-elf"]
rustflags = "-Ctarget-cpu=leon3"
通过此配置,运行 cargo run
将为 SPARC V8 兼容的 Gaisler Leon3 处理器编译您的代码,然后启动 tsim-leon3
模拟器。 libcore
已作为 rustc
编译过程的一部分使用 SPARC V7 基线预编译,但是如果您使用的是 nightly 工具链,则可以使用 -Z build-std=core
选项从源代码重建 libcore
。 如果您想为 SPARC V8 编译它并利用额外的指令,这可能很有用。
.cargo/config.toml
:
[target.sparc-unknown-none-elf]
linker = "sparc-gaisler-elf-gcc"
runner = "tsim-leon3"
[build]
target = ["sparc-unknown-none-elf"]
rustflags = "-Ctarget-cpu=leon3"
[unstable]
build-std = ["core"]
无论哪种方式,一旦模拟器运行,只需输入命令 run
即可开始在模拟器中执行代码。
默认的 C 工具链库已链接,因此使用 Gaisler BCC2 工具链,并使用其默认的 Leon3 BSP,您可以调用 C putchar
函数及其友元来输出到模拟器控制台。 默认链接器脚本也适用于 Leon3 模拟器,因此不需要链接器脚本。
这是一个使用上述配置文件的完整示例
#![no_std]
#![no_main]
extern "C" {
fn putchar(ch: i32);
fn _exit(code: i32) -> !;
}
#[no_mangle]
extern "C" fn main() -> i32 {
let message = "Hello, this is Rust!";
for b in message.bytes() {
unsafe {
putchar(b as i32);
}
}
0
}
#[panic_handler]
fn panic(_panic: &core::panic::PanicInfo) -> ! {
unsafe {
_exit(1);
}
}
$ cargo run --target=sparc-unknown-none-elf
Compiling sparc-demo-rust v0.1.0 (/work/sparc-demo-rust)
Finished dev [unoptimized + debuginfo] target(s) in 3.44s
Running `tsim-leon3 target/sparc-unknown-none-elf/debug/sparc-demo-rust`
TSIM3 LEON3 SPARC simulator, version 3.1.9 (evaluation version)
Copyright (C) 2023, Frontgrade Gaisler - all rights reserved.
This software may only be used with a valid license.
For latest updates, go to https://www.gaisler.com/
Comments or bug-reports to [email protected]
This TSIM evaluation version will expire 2023-11-28
Number of CPUs: 2
system frequency: 50.000 MHz
icache: 1 * 4 KiB, 16 bytes/line (4 KiB total)
dcache: 1 * 4 KiB, 16 bytes/line (4 KiB total)
Allocated 8192 KiB SRAM memory, in 1 bank at 0x40000000
Allocated 32 MiB SDRAM memory, in 1 bank at 0x60000000
Allocated 8192 KiB ROM memory at 0x00000000
section: .text, addr: 0x40000000, size: 20528 bytes
section: .rodata, addr: 0x40005030, size: 128 bytes
section: .data, addr: 0x400050b0, size: 1176 bytes
read 347 symbols
tsim> run
Initializing and starting from 0x40000000
Hello, this is Rust!
Program exited normally on CPU 0.
tsim>