Skip to content

Commit d03185e

Browse files
committed
Add Sony PlayStation 1 tier 3 target
1 parent c27948d commit d03185e

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use crate::spec::{cvs, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "mipsel-sony-psx".into(),
6+
pointer_width: 32,
7+
data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(),
8+
arch: "mips".into(),
9+
10+
options: TargetOptions {
11+
os: "none".into(),
12+
env: "psx".into(),
13+
vendor: "sony".into(),
14+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
15+
cpu: "mips1".into(),
16+
executables: true,
17+
linker: Some("rust-lld".into()),
18+
relocation_model: RelocModel::Static,
19+
exe_suffix: ".exe".into(),
20+
21+
// PSX doesn't natively support floats.
22+
features: "+soft-float".into(),
23+
24+
// This should be 16 bits, but LLVM incorrectly tries emitting MIPS-II SYNC instructions
25+
// for atomic loads and stores. This crashes rustc so we have to disable the Atomic* API
26+
// until this is fixed upstream. See https://reviews.llvm.org/D122427#3420144 for more
27+
// info.
28+
max_atomic_width: Some(0),
29+
30+
// PSX does not support trap-on-condition instructions.
31+
llvm_args: cvs!["-mno-check-zero-division"],
32+
llvm_abiname: "o32".into(),
33+
panic_strategy: PanicStrategy::Abort,
34+
..Default::default()
35+
},
36+
}
37+
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ supported_targets! {
12221222
("armv7a-kmc-solid_asp3-eabihf", armv7a_kmc_solid_asp3_eabihf),
12231223

12241224
("mipsel-sony-psp", mipsel_sony_psp),
1225+
("mipsel-sony-psx", mipsel_sony_psx),
12251226
("mipsel-unknown-none", mipsel_unknown_none),
12261227
("thumbv4t-none-eabi", thumbv4t_none_eabi),
12271228
("armv4t-none-eabi", armv4t_none_eabi),

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)
3030
- [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md)
3131
- [mips64-openwrt-linux-musl](platform-support/mips64-openwrt-linux-musl.md)
32+
- [mipsel-sony-psx](platform-support/mipsel-sony-psx.md)
3233
- [nvptx64-nvidia-cuda](platform-support/nvptx64-nvidia-cuda.md)
3334
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
3435
- [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md)

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ target | std | host | notes
260260
`mips-unknown-linux-uclibc` | ✓ | | MIPS Linux with uClibc
261261
[`mips64-openwrt-linux-musl`](platform-support/mips64-openwrt-linux-musl.md) | ? | | MIPS64 for OpenWrt Linux MUSL
262262
`mipsel-sony-psp` | * | | MIPS (LE) Sony PlayStation Portable (PSP)
263+
[`mipsel-sony-psx`](platform-support/mipsel-sony-psx.md) | * | | MIPS (LE) Sony PlayStation 1 (PSX)
263264
`mipsel-unknown-linux-uclibc` | ✓ | | MIPS (LE) Linux with uClibc
264265
`mipsel-unknown-none` | * | | Bare MIPS (LE) softfloat
265266
`mipsisa32r6-unknown-linux-gnu` | ? | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# mipsel-sony-psx
2+
3+
**Tier: 3**
4+
5+
Sony PlayStation 1 (psx)
6+
7+
## Designated Developer
8+
9+
* [@ayrtonm](https://github.com/ayrtonm)
10+
11+
## Requirements
12+
13+
This target is cross-compiled.
14+
It has no special requirements for the host.
15+
16+
## Building
17+
18+
The target can be built by enabling it for a `rustc` build:
19+
20+
```toml
21+
[build]
22+
build-stage = 1
23+
target = ["mipsel-sony-psx"]
24+
```
25+
26+
## Cross-compilation
27+
28+
This target can be cross-compiled from any host.
29+
30+
## Testing
31+
32+
Currently there is no support to run the rustc test suite for this target.
33+
34+
## Building Rust programs
35+
36+
Since it is Tier 3, rust doesn't ship pre-compiled artifacts for this target.
37+
38+
Just use the `build-std` nightly cargo feature to build the `core` and `alloc` libraries:
39+
```shell
40+
cargo build -Zbuild-std=core,alloc --target mipsel-sony-psx
41+
```
42+
43+
The command above generates an ELF. To generate binaries in the PSEXE format that emulators run, you can use [cargo-psx](https://github.com/ayrtonm/psx-sdk-rs#readme):
44+
45+
```shell
46+
cargo psx build
47+
```
48+
49+
or use `-Clink-arg=--oformat=binary` to produce a flat binary.

0 commit comments

Comments
 (0)