@@ -17,13 +17,6 @@ Rust for bare-metal 32-bit SPARC V7 and V8 systems, e.g. the Gaisler LEON3.
17
17
This target is cross-compiled. There is no support for ` std ` . There is no
18
18
default allocator, but it's possible to use ` alloc ` by supplying an allocator.
19
19
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
-
27
20
By default, code generated with this target should run on any ` SPARC ` hardware;
28
21
enabling additional target features may raise this baseline.
29
22
@@ -46,20 +39,31 @@ list in `config.toml`:
46
39
``` toml
47
40
[build ]
48
41
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" ]
50
44
```
51
45
46
+ Replace ` <target for your host> ` with ` x86_64-unknown-linux-gnu ` or whatever
47
+ else is appropriate for your host machine.
48
+
52
49
## Building Rust programs
53
50
54
- ``` text
51
+ To build with this target, pass it to the ` --target ` argument, like:
52
+
53
+ ``` console
55
54
cargo build --target sparc-unknown-none-elf
56
55
```
57
56
58
57
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:
60
61
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
+ ```
63
67
64
68
## Testing
65
69
@@ -81,6 +85,26 @@ something like:
81
85
linker = " sparc-gaisler-elf-gcc"
82
86
runner = " tsim-leon3"
83
87
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
+
84
108
[build ]
85
109
target = [" sparc-unknown-none-elf" ]
86
110
rustflags = " -Ctarget-cpu=leon3"
@@ -89,16 +113,16 @@ rustflags = "-Ctarget-cpu=leon3"
89
113
build-std = [" core" ]
90
114
```
91
115
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.
96
118
97
119
The default C toolchain libraries are linked in, so with the Gaisler [ BCC2]
98
120
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.
100
124
101
- Here's a complete example:
125
+ Here's a complete example using the above config file :
102
126
103
127
``` rust,ignore (cannot-test-this-because-it-assumes-special-libc-functions)
104
128
#![no_std]
0 commit comments