Skip to content

Commit b7d60b9

Browse files
Merge pull request #82 from thejpster/fix-svc-handler
Fix SVC handler
2 parents 27a5f13 + a8b6c64 commit b7d60b9

16 files changed

+210
-15
lines changed

cortex-a-rt/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ core::arch::global_asm!(
704704
"#,
705705
save_context!(),
706706
r#"
707-
mrs r0, cpsr // Load processor status
707+
mrs r0, spsr // Load processor status
708708
tst r0, {t_bit} // Occurred in Thumb state?
709709
ldrhne r0, [lr,#-2] // Yes: Load halfword and...
710710
bicne r0, r0, #0xFF00 // ...extract comment field

cortex-r-rt/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ core::arch::global_asm!(
639639
"#,
640640
save_context!(),
641641
r#"
642-
mrs r0, cpsr // Load processor status
642+
mrs r0, spsr // Load processor status
643643
tst r0, {t_bit} // Occurred in Thumb state?
644644
ldrhne r0, [lr,#-2] // Yes: Load halfword and...
645645
bicne r0, r0, #0xFF00 // ...extract comment field

examples/mps3-an536/reference/svc-armv8r-none-eabihf.out renamed to examples/mps3-an536/reference/svc-a32-armv8r-none-eabihf.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ x = 1, y = 2, z = 3.000
55
PANIC: PanicInfo {
66
message: I am an example panic,
77
location: Location {
8-
file: "src/bin/svc.rs",
9-
line: 25,
8+
file: "src/bin/svc-a32.rs",
9+
line: 23,
1010
column: 5,
1111
},
1212
can_unwind: true,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
x = 1, y = 2, z = 3.000
2+
In svc_handler, with arg=0x000012
3+
In svc_handler, with arg=0x000034
4+
x = 1, y = 2, z = 3.000
5+
PANIC: PanicInfo {
6+
message: I am an example panic,
7+
location: Location {
8+
file: "src/bin/svc-t32.rs",
9+
line: 23,
10+
column: 5,
11+
},
12+
can_unwind: true,
13+
force_no_backtrace: false,
14+
}

examples/mps3-an536/src/bin/svc.rs renamed to examples/mps3-an536/src/bin/svc-a32.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
//! SVC (software interrupt) example for Arm Cortex-R
1+
//! SVC (software interrupt) example
22
33
#![no_std]
44
#![no_main]
55

66
// pull in our start-up code
77
use cortex_r_rt::{entry, exception};
88

9-
// pull in our library
10-
use mps3_an536 as _;
11-
129
use semihosting::println;
10+
use mps3_an536 as _;
1311

1412
/// The entry-point to the Rust application.
1513
///
16-
/// It is called by the start-up code in `cortex-r-rt`.
14+
/// It is called by the start-up.
1715
#[entry]
1816
fn main() -> ! {
1917
let x = 1;
@@ -28,7 +26,7 @@ fn main() -> ! {
2826
/// This is our SVC exception handler
2927
#[exception(SupervisorCall)]
3028
fn svc_handler(arg: u32) {
31-
println!("In svc_handler, with arg={:#06x}", arg);
29+
println!("In svc_handler, with arg=0x{:06x}", arg);
3230
if arg == 0xABCDEF {
3331
// test nested SVC calls
3432
cortex_ar::svc!(0x456789);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//! SVC (software interrupt) example
2+
3+
#![no_std]
4+
#![no_main]
5+
6+
// pull in our start-up code
7+
use cortex_r_rt::{entry, exception};
8+
9+
use semihosting::println;
10+
use mps3_an536 as _;
11+
12+
/// The entry-point to the Rust application.
13+
///
14+
/// It is called by the start-up.
15+
#[entry]
16+
fn main() -> ! {
17+
let x = 1;
18+
let y = x + 1;
19+
let z = (y as f64) * 1.5;
20+
println!("x = {}, y = {}, z = {:0.3}", x, y, z);
21+
unsafe { svc12_from_t32(); }
22+
println!("x = {}, y = {}, z = {:0.3}", x, y, z);
23+
panic!("I am an example panic");
24+
}
25+
26+
/// This is our SVC exception handler
27+
#[exception(SupervisorCall)]
28+
fn svc_handler(arg: u32) {
29+
println!("In svc_handler, with arg=0x{:06x}", arg);
30+
if arg == 0x12 {
31+
// test nested SVC calls
32+
unsafe { svc34_from_t32(); }
33+
}
34+
}
35+
36+
// These functions are written in assembly
37+
extern "C" {
38+
fn svc12_from_t32();
39+
fn svc34_from_t32();
40+
}
41+
42+
core::arch::global_asm!(
43+
r#"
44+
// fn svc12_from_t32();
45+
.thumb
46+
.global svc12_from_t32
47+
.type svc12_from_t32, %function
48+
svc12_from_t32:
49+
push {{ r7, lr }}
50+
svc 0x12
51+
pop {{ r7, pc }}
52+
.size svc12_from_t32, . - svc12_from_t32
53+
54+
// fn svc34_from_t32();
55+
.thumb
56+
.global svc34_from_t32
57+
.type svc34_from_t32, %function
58+
svc34_from_t32:
59+
push {{ r7, lr }}
60+
svc 0x34
61+
pop {{ r7, pc }}
62+
.size svc34_from_t32, . - svc34_from_t32
63+
"#
64+
);

examples/versatileab/reference/svc-armv7r-none-eabihf.out renamed to examples/versatileab/reference/svc-a32-armv7a-none-eabi.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ x = 1, y = 2, z = 3.000
55
PANIC: PanicInfo {
66
message: I am an example panic,
77
location: Location {
8-
file: "src/bin/svc.rs",
8+
file: "src/bin/svc-a32.rs",
99
line: 22,
1010
column: 5,
1111
},

examples/versatileab/reference/svc-armv7r-none-eabi.out renamed to examples/versatileab/reference/svc-a32-armv7a-none-eabihf.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ x = 1, y = 2, z = 3.000
55
PANIC: PanicInfo {
66
message: I am an example panic,
77
location: Location {
8-
file: "src/bin/svc.rs",
8+
file: "src/bin/svc-a32.rs",
99
line: 22,
1010
column: 5,
1111
},

examples/versatileab/reference/svc-armv7a-none-eabi.out renamed to examples/versatileab/reference/svc-a32-armv7r-none-eabi.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ x = 1, y = 2, z = 3.000
55
PANIC: PanicInfo {
66
message: I am an example panic,
77
location: Location {
8-
file: "src/bin/svc.rs",
8+
file: "src/bin/svc-a32.rs",
99
line: 22,
1010
column: 5,
1111
},

examples/versatileab/reference/svc-armv7a-none-eabihf.out renamed to examples/versatileab/reference/svc-a32-armv7r-none-eabihf.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ x = 1, y = 2, z = 3.000
55
PANIC: PanicInfo {
66
message: I am an example panic,
77
location: Location {
8-
file: "src/bin/svc.rs",
8+
file: "src/bin/svc-a32.rs",
99
line: 22,
1010
column: 5,
1111
},

0 commit comments

Comments
 (0)