Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 442fb88

Browse files
bors[bot]nickray
andauthored
Merge #57
57: Add `no-semihosting` feature to suppress all semihosting calls r=adamgreig a=nickray I must not be the only one who indulges in semihosting for quick print-debugging and then has a trail of intermediate mess... With this new feature, one can easily patch out all these calls in the application (by additivity of cargo features), and get a binary that runs without debugger attached. Co-authored-by: Nicolas Stalder <n@stalder.io>
2 parents 05766e3 + ecdb08f commit 442fb88

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ edition = "2018"
1616
[features]
1717
inline-asm = []
1818
jlink-quirks = []
19+
no-semihosting = []
1920

2021
[dependencies]
2122
cortex-m = ">= 0.5.8, < 0.7"

src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@
170170
//! latest version 6.48b of J-Link exhibits such behaviour, causing a panic if this feature
171171
//! is not enabled.
172172
//!
173+
//! ## `no-semihosting`
174+
//!
175+
//! When this feature is enabled, the underlying system calls to `bkpt` are patched out.
176+
//!
173177
//! # Reference
174178
//!
175179
//! For documentation about the semihosting operations, check:
@@ -207,16 +211,21 @@ pub unsafe fn syscall<T>(nr: usize, arg: &T) -> usize {
207211
#[inline(always)]
208212
pub unsafe fn syscall1(_nr: usize, _arg: usize) -> usize {
209213
match () {
210-
#[cfg(all(thumb, not(feature = "inline-asm")))]
214+
#[cfg(all(thumb, not(feature = "inline-asm"), not(feature = "no-semihosting")))]
211215
() => __syscall(_nr, _arg),
212216

213-
#[cfg(all(thumb, feature = "inline-asm"))]
217+
#[cfg(all(thumb, feature = "inline-asm", not(feature = "no-semihosting")))]
214218
() => {
215219
let mut nr = _nr;
216220
llvm_asm!("bkpt 0xAB" : "+{r0}"(nr) : "{r1}"(_arg) :: "volatile");
217221
nr
218222
}
219223

224+
#[cfg(all(thumb, feature = "no-semihosting"))]
225+
() => {
226+
0
227+
}
228+
220229
#[cfg(not(thumb))]
221230
() => unimplemented!(),
222231
}

0 commit comments

Comments
 (0)