Skip to content

Commit 4ee3266

Browse files
authored
Rollup merge of rust-lang#114006 - jonathanpallant:update-sparc-unknown-readme, r=Amanieu
Update sparc-unknown-none-elf platform README Cherry picked a couple of commits that didn't quite make it in rust-lang#113535
2 parents 3723b30 + 34e01d5 commit 4ee3266

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

src/doc/rustc/src/platform-support/sparc-unknown-none-elf.md

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ Rust for bare-metal 32-bit SPARC V7 and V8 systems, e.g. the Gaisler LEON3.
1717
This target is cross-compiled. There is no support for `std`. There is no
1818
default allocator, but it's possible to use `alloc` by supplying an allocator.
1919

20-
This allows the generated code to run in environments, such as kernels, which
21-
may need to avoid the use of such registers or which may have special
22-
considerations about the use of such registers (e.g. saving and restoring them
23-
to avoid breaking userspace code using the same registers). You can change code
24-
generation to use additional CPU features via the `-C target-feature=` codegen
25-
options to rustc, or via the `#[target_feature]` mechanism within Rust code.
26-
2720
By default, code generated with this target should run on any `SPARC` hardware;
2821
enabling additional target features may raise this baseline.
2922

@@ -46,20 +39,31 @@ list in `config.toml`:
4639
```toml
4740
[build]
4841
build-stage = 1
49-
target = ["sparc-unknown-none-elf"]
42+
host = ["<target for your host>"]
43+
target = ["<target for your host>", "sparc-unknown-none-elf"]
5044
```
5145

46+
Replace `<target for your host>` with `x86_64-unknown-linux-gnu` or whatever
47+
else is appropriate for your host machine.
48+
5249
## Building Rust programs
5350

54-
```text
51+
To build with this target, pass it to the `--target` argument, like:
52+
53+
```console
5554
cargo build --target sparc-unknown-none-elf
5655
```
5756

5857
This target uses GCC as a linker, and so you will need an appropriate GCC
59-
compatible `sparc-unknown-none` toolchain.
58+
compatible `sparc-unknown-none` toolchain. The default linker binary is
59+
`sparc-elf-gcc`, but you can override this in your project configuration, as
60+
follows:
6061

61-
The default linker name is `sparc-elf-gcc`, but you can override this in your
62-
project configuration.
62+
`.cargo/config.toml`:
63+
```toml
64+
[target.sparc-unknown-none-elf]
65+
linker = "sparc-custom-elf-gcc"
66+
```
6367

6468
## Testing
6569

@@ -81,6 +85,26 @@ something like:
8185
linker = "sparc-gaisler-elf-gcc"
8286
runner = "tsim-leon3"
8387

88+
[build]
89+
target = ["sparc-unknown-none-elf"]
90+
rustflags = "-Ctarget-cpu=leon3"
91+
```
92+
93+
With this configuration, running `cargo run` will compile your code for the
94+
SPARC V8 compatible Gaisler Leon3 processor and then start the `tsim-leon3`
95+
simulator. The `libcore` was pre-compiled as part of the `rustc` compilation
96+
process using the SPARC V7 baseline, but if you are using a nightly toolchain
97+
you can use the
98+
[`-Z build-std=core`](https://doc.rust-lang.org/cargo/reference/unstable.html#build-std)
99+
option to rebuild `libcore` from source. This may be useful if you want to
100+
compile it for SPARC V8 and take advantage of the extra instructions.
101+
102+
`.cargo/config.toml`:
103+
```toml
104+
[target.sparc-unknown-none-elf]
105+
linker = "sparc-gaisler-elf-gcc"
106+
runner = "tsim-leon3"
107+
84108
[build]
85109
target = ["sparc-unknown-none-elf"]
86110
rustflags = "-Ctarget-cpu=leon3"
@@ -89,16 +113,16 @@ rustflags = "-Ctarget-cpu=leon3"
89113
build-std = ["core"]
90114
```
91115

92-
With this configuration, running `cargo run` will compile your code for the
93-
SPARC V8 compatible Gaisler Leon3 processor and then start the `tsim-leon3`
94-
simulator. Once the simulator is running, simply enter the command
95-
`run` to start the code executing in the simulator.
116+
Either way, once the simulator is running, simply enter the command `run` to
117+
start the code executing in the simulator.
96118

97119
The default C toolchain libraries are linked in, so with the Gaisler [BCC2]
98120
toolchain, and using its default Leon3 BSP, you can use call the C `putchar`
99-
function and friends to output to the simulator console.
121+
function and friends to output to the simulator console. The default linker
122+
script is also appropriate for the Leon3 simulator, so no linker script is
123+
required.
100124

101-
Here's a complete example:
125+
Here's a complete example using the above config file:
102126

103127
```rust,ignore (cannot-test-this-because-it-assumes-special-libc-functions)
104128
#![no_std]

0 commit comments

Comments
 (0)