forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#130555 - hegza:rv32e, r=workingjubilee Initial support for riscv32{e|em|emc}_unknown_none_elf We have a research prototype of an RV32EMC target and have been successfully running the e, em, emc programs on it. I'm hoping upstreaming this configuration would make the target maintenance slightly easier. Configuration is based on the respective {i, im, imc} variants. As defined in RISC-V Unprivileged Spec. 20191213, the only change in RVE wrt. RVI is to reduce the number of integer registers to 16 (x0-x15), which also implies - 2 callee saved registers instead of 12 - 32-bit / 4-byte stack alignment instead of 128 bits / 16 bytes My initial presumption is that this will not impact how the target is defined for the compiler but only becomes relevant at the runtime level. I am willing to investigate, though. EDIT: LLVM is now told about the presumed 32-bit stack alignment. `@Disasm` `@romancardenas`
- Loading branch information
Showing
13 changed files
with
825 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
compiler/rustc_target/src/spec/targets/riscv32e_unknown_none_elf.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions}; | ||
|
||
pub(crate) fn target() -> Target { | ||
Target { | ||
// The below `data_layout` is explicitly specified by the ilp32e ABI in LLVM. See also | ||
// `options.llvm_abiname`. | ||
data_layout: "e-m:e-p:32:32-i64:64-n32-S32".into(), | ||
llvm_target: "riscv32".into(), | ||
metadata: crate::spec::TargetMetadata { | ||
description: Some("Bare RISC-V (RV32E ISA)".into()), | ||
tier: Some(3), | ||
host_tools: Some(false), | ||
std: Some(false), | ||
}, | ||
pointer_width: 32, | ||
arch: "riscv32".into(), | ||
|
||
options: TargetOptions { | ||
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), | ||
linker: Some("rust-lld".into()), | ||
cpu: "generic-rv32".into(), | ||
// The ilp32e ABI specifies the `data_layout` | ||
llvm_abiname: "ilp32e".into(), | ||
max_atomic_width: Some(32), | ||
atomic_cas: false, | ||
features: "+e,+forced-atomics".into(), | ||
panic_strategy: PanicStrategy::Abort, | ||
relocation_model: RelocModel::Static, | ||
emit_debug_gdb_scripts: false, | ||
eh_frame_header: false, | ||
..Default::default() | ||
}, | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
compiler/rustc_target/src/spec/targets/riscv32em_unknown_none_elf.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions}; | ||
|
||
pub(crate) fn target() -> Target { | ||
Target { | ||
// The below `data_layout` is explicitly specified by the ilp32e ABI in LLVM. See also | ||
// `options.llvm_abiname`. | ||
data_layout: "e-m:e-p:32:32-i64:64-n32-S32".into(), | ||
llvm_target: "riscv32".into(), | ||
metadata: crate::spec::TargetMetadata { | ||
description: Some("Bare RISC-V (RV32EM ISA)".into()), | ||
tier: Some(3), | ||
host_tools: Some(false), | ||
std: Some(false), | ||
}, | ||
pointer_width: 32, | ||
arch: "riscv32".into(), | ||
|
||
options: TargetOptions { | ||
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), | ||
linker: Some("rust-lld".into()), | ||
cpu: "generic-rv32".into(), | ||
// The ilp32e ABI specifies the `data_layout` | ||
llvm_abiname: "ilp32e".into(), | ||
max_atomic_width: Some(32), | ||
atomic_cas: false, | ||
features: "+e,+m,+forced-atomics".into(), | ||
panic_strategy: PanicStrategy::Abort, | ||
relocation_model: RelocModel::Static, | ||
emit_debug_gdb_scripts: false, | ||
eh_frame_header: false, | ||
..Default::default() | ||
}, | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
compiler/rustc_target/src/spec/targets/riscv32emc_unknown_none_elf.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions}; | ||
|
||
pub(crate) fn target() -> Target { | ||
Target { | ||
// The below `data_layout` is explicitly specified by the ilp32e ABI in LLVM. See also | ||
// `options.llvm_abiname`. | ||
data_layout: "e-m:e-p:32:32-i64:64-n32-S32".into(), | ||
llvm_target: "riscv32".into(), | ||
metadata: crate::spec::TargetMetadata { | ||
description: Some("Bare RISC-V (RV32EMC ISA)".into()), | ||
tier: Some(3), | ||
host_tools: Some(false), | ||
std: Some(false), | ||
}, | ||
pointer_width: 32, | ||
arch: "riscv32".into(), | ||
|
||
options: TargetOptions { | ||
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), | ||
linker: Some("rust-lld".into()), | ||
cpu: "generic-rv32".into(), | ||
// The ilp32e ABI specifies the `data_layout` | ||
llvm_abiname: "ilp32e".into(), | ||
max_atomic_width: Some(32), | ||
atomic_cas: false, | ||
features: "+e,+m,+c,+forced-atomics".into(), | ||
panic_strategy: PanicStrategy::Abort, | ||
relocation_model: RelocModel::Static, | ||
emit_debug_gdb_scripts: false, | ||
eh_frame_header: false, | ||
..Default::default() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/doc/rustc/src/platform-support/riscv32e-unknown-none-elf.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# `riscv32{e,em,emc}-unknown-none-elf` | ||
|
||
**Tier: 3** | ||
|
||
Bare-metal target for RISC-V CPUs with the RV32E, RV32EM and RV32EMC ISAs. | ||
|
||
## Target maintainers | ||
|
||
* Henri Lunnikivi, <[email protected]>, [@hegza](https://github.com/hegza) | ||
|
||
## Requirements | ||
|
||
The target is cross-compiled, and uses static linking. No external toolchain is | ||
required and the default `rust-lld` linker works, but you must specify a linker | ||
script. | ||
|
||
## Building the target | ||
|
||
This target is included in Rust and can be installed via `rustup`. | ||
|
||
## Testing | ||
|
||
This is a cross-compiled `no-std` target, which must be run either in a | ||
simulator or by programming them onto suitable hardware. It is not possible to | ||
run the Rust test-suite on this target. | ||
|
||
## Cross-compilation toolchains and C code | ||
|
||
This target supports C code. If interlinking with C or C++, you may need to use | ||
`riscv32-unknown-elf-gcc` as a linker instead of `rust-lld`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:43:11 | ||
| | ||
LL | asm!("li x16, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x16, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:46:11 | ||
| | ||
LL | asm!("li x17, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x17, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:49:11 | ||
| | ||
LL | asm!("li x18, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x18, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:52:11 | ||
| | ||
LL | asm!("li x19, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x19, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:55:11 | ||
| | ||
LL | asm!("li x20, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x20, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:58:11 | ||
| | ||
LL | asm!("li x21, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x21, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:61:11 | ||
| | ||
LL | asm!("li x22, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x22, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:64:11 | ||
| | ||
LL | asm!("li x23, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x23, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:67:11 | ||
| | ||
LL | asm!("li x24, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x24, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:70:11 | ||
| | ||
LL | asm!("li x25, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x25, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:73:11 | ||
| | ||
LL | asm!("li x26, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x26, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:76:11 | ||
| | ||
LL | asm!("li x27, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x27, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:79:11 | ||
| | ||
LL | asm!("li x28, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x28, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:82:11 | ||
| | ||
LL | asm!("li x29, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x29, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:85:11 | ||
| | ||
LL | asm!("li x30, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x30, 0 | ||
| ^ | ||
|
||
error: invalid operand for instruction | ||
--> $DIR/riscv32e-registers.rs:88:11 | ||
| | ||
LL | asm!("li x31, 0"); | ||
| ^ | ||
| | ||
note: instantiated into assembly here | ||
--> <inline asm>:1:5 | ||
| | ||
LL | li x31, 0 | ||
| ^ | ||
|
||
error: aborting due to 16 previous errors | ||
|
Oops, something went wrong.