Skip to content

Commit b1dd190

Browse files
committed
add C-cmse-nonsecure-entry ABI
1 parent d3dd34a commit b1dd190

File tree

22 files changed

+133
-14
lines changed

22 files changed

+133
-14
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: Call
6161
Conv::CCmseNonSecureCall => {
6262
sess.dcx().fatal("C-cmse-nonsecure-call call conv is not yet implemented");
6363
}
64+
Conv::CCmseNonSecureEntry => {
65+
sess.dcx().fatal("C-cmse-nonsecure-entry call conv is not yet implemented");
66+
}
6467

6568
Conv::Msp430Intr | Conv::PtxKernel | Conv::AvrInterrupt | Conv::AvrNonBlockingInterrupt => {
6669
unreachable!("tried to use {c:?} call conv which only exists on an unsupported target");

compiler/rustc_codegen_llvm/src/abi.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
407407
if let Conv::RiscvInterrupt { kind } = self.conv {
408408
func_attrs.push(llvm::CreateAttrStringValue(cx.llcx, "interrupt", kind.as_str()));
409409
}
410+
if let Conv::CCmseNonSecureEntry = self.conv {
411+
func_attrs.push(llvm::CreateAttrString(cx.llcx, "cmse_nonsecure_entry"))
412+
}
410413
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &{ func_attrs });
411414

412415
let mut i = 0;
@@ -606,9 +609,11 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
606609
impl From<Conv> for llvm::CallConv {
607610
fn from(conv: Conv) -> Self {
608611
match conv {
609-
Conv::C | Conv::Rust | Conv::CCmseNonSecureCall | Conv::RiscvInterrupt { .. } => {
610-
llvm::CCallConv
611-
}
612+
Conv::C
613+
| Conv::Rust
614+
| Conv::CCmseNonSecureCall
615+
| Conv::CCmseNonSecureEntry
616+
| Conv::RiscvInterrupt { .. } => llvm::CCallConv,
612617
Conv::Cold => llvm::ColdCallConv,
613618
Conv::PreserveMost => llvm::PreserveMost,
614619
Conv::PreserveAll => llvm::PreserveAll,

compiler/rustc_middle/src/ty/layout.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
12121212
| RiscvInterruptM
12131213
| RiscvInterruptS
12141214
| CCmseNonSecureCall
1215+
| CCmseNonSecureEntry
12151216
| Unadjusted => false,
12161217
Rust | RustCall | RustCold | RustIntrinsic => {
12171218
tcx.sess.panic_strategy() == PanicStrategy::Unwind

compiler/rustc_smir/src/rustc_internal/internal.rs

+1
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ impl RustcInternal for Abi {
466466
Abi::AvrInterrupt => rustc_target::spec::abi::Abi::AvrInterrupt,
467467
Abi::AvrNonBlockingInterrupt => rustc_target::spec::abi::Abi::AvrNonBlockingInterrupt,
468468
Abi::CCmseNonSecureCall => rustc_target::spec::abi::Abi::CCmseNonSecureCall,
469+
Abi::CCmseNonSecureEntry => rustc_target::spec::abi::Abi::CCmseNonSecureEntry,
469470
Abi::System { unwind } => rustc_target::spec::abi::Abi::System { unwind },
470471
Abi::RustIntrinsic => rustc_target::spec::abi::Abi::RustIntrinsic,
471472
Abi::RustCall => rustc_target::spec::abi::Abi::RustCall,

compiler/rustc_smir/src/rustc_smir/convert/abi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::Conv {
104104
Conv::PreserveAll => CallConvention::PreserveAll,
105105
Conv::ArmAapcs => CallConvention::ArmAapcs,
106106
Conv::CCmseNonSecureCall => CallConvention::CCmseNonSecureCall,
107+
Conv::CCmseNonSecureEntry => CallConvention::CCmseNonSecureEntry,
107108
Conv::Msp430Intr => CallConvention::Msp430Intr,
108109
Conv::PtxKernel => CallConvention::PtxKernel,
109110
Conv::X86Fastcall => CallConvention::X86Fastcall,

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::spec::abi::Abi {
909909
abi::Abi::AvrInterrupt => Abi::AvrInterrupt,
910910
abi::Abi::AvrNonBlockingInterrupt => Abi::AvrNonBlockingInterrupt,
911911
abi::Abi::CCmseNonSecureCall => Abi::CCmseNonSecureCall,
912+
abi::Abi::CCmseNonSecureEntry => Abi::CCmseNonSecureEntry,
912913
abi::Abi::System { unwind } => Abi::System { unwind },
913914
abi::Abi::RustIntrinsic => Abi::RustIntrinsic,
914915
abi::Abi::RustCall => Abi::RustCall,

compiler/rustc_target/src/abi/call/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ pub enum Conv {
748748
// Target-specific calling conventions.
749749
ArmAapcs,
750750
CCmseNonSecureCall,
751+
CCmseNonSecureEntry,
751752

752753
Msp430Intr,
753754

@@ -942,6 +943,7 @@ impl FromStr for Conv {
942943
"RustCold" => Ok(Conv::Rust),
943944
"ArmAapcs" => Ok(Conv::ArmAapcs),
944945
"CCmseNonSecureCall" => Ok(Conv::CCmseNonSecureCall),
946+
"CCmseNonSecureEntry" => Ok(Conv::CCmseNonSecureEntry),
945947
"Msp430Intr" => Ok(Conv::Msp430Intr),
946948
"PtxKernel" => Ok(Conv::PtxKernel),
947949
"X86Fastcall" => Ok(Conv::X86Fastcall),

compiler/rustc_target/src/json.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl ToJson for crate::abi::call::Conv {
103103
Self::PreserveAll => "PreserveAll",
104104
Self::ArmAapcs => "ArmAapcs",
105105
Self::CCmseNonSecureCall => "CCmseNonSecureCall",
106+
Self::CCmseNonSecureEntry => "CCmseNonSecureEntry",
106107
Self::Msp430Intr => "Msp430Intr",
107108
Self::PtxKernel => "PtxKernel",
108109
Self::X86Fastcall => "X86Fastcall",

compiler/rustc_target/src/spec/abi/mod.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub enum Abi {
4848
AvrInterrupt,
4949
AvrNonBlockingInterrupt,
5050
CCmseNonSecureCall,
51+
CCmseNonSecureEntry,
5152
System {
5253
unwind: bool,
5354
},
@@ -122,6 +123,7 @@ const AbiDatas: &[AbiData] = &[
122123
AbiData { abi: Abi::AvrInterrupt, name: "avr-interrupt" },
123124
AbiData { abi: Abi::AvrNonBlockingInterrupt, name: "avr-non-blocking-interrupt" },
124125
AbiData { abi: Abi::CCmseNonSecureCall, name: "C-cmse-nonsecure-call" },
126+
AbiData { abi: Abi::CCmseNonSecureEntry, name: "C-cmse-nonsecure-entry" },
125127
AbiData { abi: Abi::System { unwind: false }, name: "system" },
126128
AbiData { abi: Abi::System { unwind: true }, name: "system-unwind" },
127129
AbiData { abi: Abi::RustIntrinsic, name: "rust-intrinsic" },
@@ -242,6 +244,10 @@ pub fn is_stable(name: &str) -> Result<(), AbiDisabled> {
242244
feature: sym::abi_c_cmse_nonsecure_call,
243245
explain: "C-cmse-nonsecure-call ABI is experimental and subject to change",
244246
}),
247+
"C-cmse-nonsecure-entry" => Err(AbiDisabled::Unstable {
248+
feature: sym::cmse_nonsecure_entry,
249+
explain: "C-cmse-nonsecure-entry ABI is experimental and subject to change",
250+
}),
245251
_ => Err(AbiDisabled::Unrecognized),
246252
}
247253
}
@@ -284,15 +290,16 @@ impl Abi {
284290
AvrInterrupt => 23,
285291
AvrNonBlockingInterrupt => 24,
286292
CCmseNonSecureCall => 25,
293+
CCmseNonSecureEntry => 26,
287294
// Cross-platform ABIs
288-
System { unwind: false } => 26,
289-
System { unwind: true } => 27,
290-
RustIntrinsic => 28,
291-
RustCall => 29,
292-
Unadjusted => 30,
293-
RustCold => 31,
294-
RiscvInterruptM => 32,
295-
RiscvInterruptS => 33,
295+
System { unwind: false } => 27,
296+
System { unwind: true } => 28,
297+
RustIntrinsic => 29,
298+
RustCall => 30,
299+
Unadjusted => 31,
300+
RustCold => 32,
301+
RiscvInterruptM => 33,
302+
RiscvInterruptS => 34,
296303
};
297304
debug_assert!(
298305
AbiDatas

compiler/rustc_target/src/spec/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1251,9 +1251,9 @@ impl StackProbeType {
12511251
.and_then(|o| o.as_array())
12521252
.ok_or_else(|| "expected `min-llvm-version-for-inline` to be an array")?;
12531253
let mut iter = min_version.into_iter().map(|v| {
1254-
let int = v.as_u64().ok_or_else(
1255-
|| "expected `min-llvm-version-for-inline` values to be integers",
1256-
)?;
1254+
let int = v.as_u64().ok_or_else(|| {
1255+
"expected `min-llvm-version-for-inline` values to be integers"
1256+
})?;
12571257
u32::try_from(int)
12581258
.map_err(|_| "`min-llvm-version-for-inline` values don't convert to u32")
12591259
});
@@ -2657,6 +2657,7 @@ impl Target {
26572657
X86Interrupt => ["x86", "x86_64"].contains(&&self.arch[..]),
26582658
Aapcs { .. } => "arm" == self.arch,
26592659
CCmseNonSecureCall => ["arm", "aarch64"].contains(&&self.arch[..]),
2660+
CCmseNonSecureEntry => ["arm", "aarch64"].contains(&&self.arch[..]),
26602661
Win64 { .. } | SysV64 { .. } => self.arch == "x86_64",
26612662
PtxKernel => self.arch == "nvptx64",
26622663
Msp430Interrupt => self.arch == "msp430",

compiler/rustc_ty_utils/src/abi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi, c_variadic: bool) -> Conv {
345345
SysV64 { .. } => Conv::X86_64SysV,
346346
Aapcs { .. } => Conv::ArmAapcs,
347347
CCmseNonSecureCall => Conv::CCmseNonSecureCall,
348+
CCmseNonSecureEntry => Conv::CCmseNonSecureEntry,
348349
PtxKernel => Conv::PtxKernel,
349350
Msp430Interrupt => Conv::Msp430Intr,
350351
X86Interrupt => Conv::X86Intr,

compiler/stable_mir/src/abi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ pub enum CallConvention {
432432
// Target-specific calling conventions.
433433
ArmAapcs,
434434
CCmseNonSecureCall,
435+
CCmseNonSecureEntry,
435436

436437
Msp430Intr,
437438

compiler/stable_mir/src/ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ pub enum Abi {
10451045
AvrInterrupt,
10461046
AvrNonBlockingInterrupt,
10471047
CCmseNonSecureCall,
1048+
CCmseNonSecureEntry,
10481049
System { unwind: bool },
10491050
RustIntrinsic,
10501051
RustCall,

src/tools/rust-analyzer/crates/hir-ty/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ pub enum FnAbi {
373373
AvrNonBlockingInterrupt,
374374
C,
375375
CCmseNonsecureCall,
376+
CCmseNonsecureEntry,
376377
CDecl,
377378
CDeclUnwind,
378379
CUnwind,
@@ -430,6 +431,7 @@ impl FnAbi {
430431
"avr-interrupt" => FnAbi::AvrInterrupt,
431432
"avr-non-blocking-interrupt" => FnAbi::AvrNonBlockingInterrupt,
432433
"C-cmse-nonsecure-call" => FnAbi::CCmseNonsecureCall,
434+
"C-cmse-nonsecure-entry" => FnAbi::CCmseNonsecureEntry,
433435
"C-unwind" => FnAbi::CUnwind,
434436
"C" => FnAbi::C,
435437
"cdecl-unwind" => FnAbi::CDeclUnwind,
@@ -473,6 +475,7 @@ impl FnAbi {
473475
FnAbi::AvrNonBlockingInterrupt => "avr-non-blocking-interrupt",
474476
FnAbi::C => "C",
475477
FnAbi::CCmseNonsecureCall => "C-cmse-nonsecure-call",
478+
FnAbi::CCmseNonsecureEntry => "C-cmse-nonsecure-entry",
476479
FnAbi::CDecl => "C-decl",
477480
FnAbi::CDeclUnwind => "cdecl-unwind",
478481
FnAbi::CUnwind => "C-unwind",

src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const SUPPORTED_CALLING_CONVENTIONS: &[&str] = &[
3232
"riscv-interrupt-m",
3333
"riscv-interrupt-s",
3434
"C-cmse-nonsecure-call",
35+
"C-cmse-nonsecure-entry",
3536
"wasm",
3637
"system",
3738
"system-unwind",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// gate-test-cmse_nonsecure_entry
2+
3+
#[no_mangle]
4+
pub extern "C-cmse-nonsecure-entry" fn entry_function(input: u32) -> u32 {
5+
//~^ ERROR [E0570]
6+
//~| ERROR [E0658]
7+
input + 6
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0658]: C-cmse-nonsecure-entry ABI is experimental and subject to change
2+
--> $DIR/gate_test.rs:4:12
3+
|
4+
LL | pub extern "C-cmse-nonsecure-entry" fn entry_function(input: u32) -> u32 {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #75835 <https://github.com/rust-lang/rust/issues/75835> for more information
8+
= help: add `#![feature(cmse_nonsecure_entry)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
12+
--> $DIR/gate_test.rs:4:1
13+
|
14+
LL | pub extern "C-cmse-nonsecure-entry" fn entry_function(input: u32) -> u32 {
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
error: aborting due to 2 previous errors
18+
19+
Some errors have detailed explanations: E0570, E0658.
20+
For more information about an error, try `rustc --explain E0570`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ build-pass
2+
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
3+
//@ needs-llvm-components: arm
4+
#![feature(cmse_nonsecure_entry, no_core, lang_items)]
5+
#![no_core]
6+
#[lang = "sized"]
7+
trait Sized {}
8+
#[lang = "copy"]
9+
trait Copy {}
10+
impl Copy for u32 {}
11+
12+
#[no_mangle]
13+
pub extern "C-cmse-nonsecure-entry" fn entry_function(_: u32, _: u32, _: u32, d: u32) -> u32 {
14+
d
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ build-fail
2+
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
3+
//@ needs-llvm-components: arm
4+
#![feature(cmse_nonsecure_entry, no_core, lang_items)]
5+
#![no_core]
6+
#[lang = "sized"]
7+
trait Sized {}
8+
#[lang = "copy"]
9+
trait Copy {}
10+
impl Copy for u32 {}
11+
12+
#[no_mangle]
13+
pub extern "C-cmse-nonsecure-entry" fn entry_function(
14+
_: u32,
15+
_: u32,
16+
_: u32,
17+
_: u32,
18+
e: u32,
19+
) -> u32 {
20+
e
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: <unknown>:0:0: in function entry_function i32 (i32, i32, i32, i32, i32): secure entry function requires arguments on stack
2+
3+
error: aborting due to 1 previous error
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ ignore-thumbv8m.main-none-eabi
2+
#![feature(cmse_nonsecure_entry)]
3+
4+
#[no_mangle]
5+
pub extern "C-cmse-nonsecure-entry" fn entry_function(input: u32) -> u32 {
6+
//~^ ERROR [E0570]
7+
input + 6
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
2+
--> $DIR/trustzone-only.rs:5:1
3+
|
4+
LL | pub extern "C-cmse-nonsecure-entry" fn entry_function(input: u32) -> u32 {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0570`.

0 commit comments

Comments
 (0)