Skip to content

Commit adab0e1

Browse files
committed
Update examples to use new macros.
1 parent 41bffee commit adab0e1

35 files changed

+215
-222
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Hello, this is an data abort exception example
2+
data abort occurred
3+
DFSR (Fault Status Register): DFSR { ext=false wnr=false Domain=0b0010 Status=0b00001 }
4+
DFSR Status: Ok(AlignmentFault)
5+
DFAR (Faulting Address Register): Dfar(4097)
6+
data abort occurred
7+
DFSR (Fault Status Register): DFSR { ext=false wnr=false Domain=0b0010 Status=0b00001 }
8+
DFSR Status: Ok(AlignmentFault)
9+
DFAR (Faulting Address Register): Dfar(4097)

examples/mps3-an536/reference/hello-armv8r-none-eabihf.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PANIC: PanicInfo {
33
message: I am an example panic,
44
location: Location {
55
file: "src/bin/hello.rs",
6-
line: 26,
6+
line: 22,
77
col: 5,
88
},
99
can_unwind: true,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PANIC: PanicInfo {
66
message: I am an example panic,
77
location: Location {
88
file: "src/bin/svc.rs",
9-
line: 29,
9+
line: 25,
1010
col: 5,
1111
},
1212
can_unwind: true,

examples/mps3-an536/src/bin/abt-exception-a32.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
use core::sync::atomic::{AtomicU32, Ordering};
77

88
use cortex_ar::register::{Dfar, Dfsr, Sctlr};
9+
910
// pull in our start-up code
11+
use cortex_r_rt::{entry, exception};
12+
13+
// pull in our library
1014
use mps3_an536 as _;
1115

1216
use semihosting::println;
@@ -17,14 +21,7 @@ static COUNTER: AtomicU32 = AtomicU32::new(0);
1721
/// The entry-point to the Rust application.
1822
///
1923
/// It is called by the start-up.
20-
#[no_mangle]
21-
pub extern "C" fn kmain() -> ! {
22-
main();
23-
}
24-
25-
/// The main function of our Rust application.
26-
#[export_name = "main"]
27-
#[allow(unreachable_code)]
24+
#[entry]
2825
fn main() -> ! {
2926
// Enable alignment check for Armv7-R. Was not required
3027
// on Cortex-A for some reason, even though the bit was not set.
@@ -73,18 +70,18 @@ fn disable_alignment_check() {
7370
Sctlr::write(sctrl);
7471
}
7572

76-
#[unsafe(no_mangle)]
77-
unsafe extern "C" fn _undefined_handler(_addr: u32) -> ! {
73+
#[exception(UndefinedHandler)]
74+
fn undefined_handler(_addr: usize) -> ! {
7875
panic!("unexpected undefined exception");
7976
}
8077

81-
#[unsafe(no_mangle)]
82-
unsafe extern "C" fn _prefetch_handler(_addr: u32) -> ! {
78+
#[exception(PrefetchHandler)]
79+
fn prefetch_handler(_addr: usize) -> ! {
8380
panic!("unexpected prefetch exception");
8481
}
8582

86-
#[unsafe(no_mangle)]
87-
unsafe extern "C" fn _abort_handler(addr: usize) -> usize {
83+
#[exception(AbortHandler)]
84+
fn abort_handler(addr: usize) -> usize {
8885
println!("data abort occurred");
8986
// If this is not disabled, reading DFAR will trigger an alignment fault on Armv8-R, leading
9087
// to a loop.

examples/mps3-an536/src/bin/abt-exception-t32.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
use core::sync::atomic::{AtomicU32, Ordering};
77

88
use cortex_ar::register::{Dfar, Dfsr, Sctlr};
9+
910
// pull in our start-up code
11+
use cortex_r_rt::{entry, exception};
12+
13+
// pull in our library
1014
use mps3_an536 as _;
1115

1216
use semihosting::println;
@@ -17,14 +21,7 @@ static COUNTER: AtomicU32 = AtomicU32::new(0);
1721
/// The entry-point to the Rust application.
1822
///
1923
/// It is called by the start-up.
20-
#[no_mangle]
21-
pub extern "C" fn kmain() -> ! {
22-
main();
23-
}
24-
25-
/// The main function of our Rust application.
26-
#[export_name = "main"]
27-
#[allow(unreachable_code)]
24+
#[entry]
2825
fn main() -> ! {
2926
// Enable alignment check for Armv7-R. Was not required
3027
// on Cortex-A for some reason, even though the bit was not set.
@@ -73,18 +70,18 @@ fn disable_alignment_check() {
7370
Sctlr::write(sctrl);
7471
}
7572

76-
#[unsafe(no_mangle)]
77-
unsafe extern "C" fn _undefined_handler(_addr: u32) -> ! {
73+
#[exception(UndefinedHandler)]
74+
fn undefined_handler(_addr: usize) -> ! {
7875
panic!("unexpected undefined exception");
7976
}
8077

81-
#[unsafe(no_mangle)]
82-
unsafe extern "C" fn _prefetch_handler(_addr: u32) -> ! {
78+
#[exception(PrefetchHandler)]
79+
fn prefetch_handler(_addr: usize) -> ! {
8380
panic!("unexpected prefetch exception");
8481
}
8582

86-
#[unsafe(no_mangle)]
87-
unsafe extern "C" fn _abort_handler(addr: usize) -> usize {
83+
#[exception(AbortHandler)]
84+
fn abort_handler(addr: usize) -> usize {
8885
println!("data abort occurred");
8986
// If this is not disabled, reading DFAR will trigger an alignment fault on Armv8-R, leading
9087
// to a loop.

examples/mps3-an536/src/bin/generic_timer.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44
#![no_main]
55

66
// pull in our start-up code
7+
use cortex_r_rt::entry;
8+
9+
// pull in our library
710
use mps3_an536 as _;
811

912
use semihosting::println;
1013

1114
/// The entry-point to the Rust application.
1215
///
13-
/// It is called by the start-up code in `cortex-m-rt`.
14-
#[no_mangle]
15-
pub extern "C" fn kmain() {
16-
main();
17-
semihosting::process::exit(0);
18-
}
19-
20-
/// Let's test some timers!
21-
fn main() {
16+
/// It is called by the start-up code in `cortex-r-rt`.
17+
#[entry]
18+
fn main() -> ! {
2219
use cortex_ar::generic_timer::{El1PhysicalTimer, El1VirtualTimer, GenericTimer};
2320
let cntfrq = cortex_ar::register::Cntfrq::read().0;
2421
println!("cntfrq = {:.03} MHz", cntfrq as f32 / 1_000_000.0);
@@ -59,4 +56,6 @@ fn main() {
5956
}
6057
println!("{} countdown hit zero!", name,);
6158
}
59+
60+
semihosting::process::exit(0);
6261
}

examples/mps3-an536/src/bin/gic.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#![no_main]
55

66
// pull in our start-up code
7+
use cortex_r_rt::{entry, exception};
8+
9+
// pull in our library
710
use mps3_an536 as _;
811

912
use arm_gic::{
@@ -22,15 +25,8 @@ const GICR_BASE_OFFSET: usize = 0x0010_0000usize;
2225

2326
/// The entry-point to the Rust application.
2427
///
25-
/// It is called by the start-up code in `cortex-m-rt`.
26-
#[no_mangle]
27-
pub extern "C" fn kmain() {
28-
main();
29-
}
30-
31-
/// The main function of our Rust application.
32-
///
33-
/// Called by [`kmain`].
28+
/// It is called by the start-up code in `cortex-r-rt`.
29+
#[entry]
3430
fn main() -> ! {
3531
// Get the GIC address by reading CBAR
3632
let periphbase = cortex_ar::register::ImpCbar::read().periphbase();
@@ -89,8 +85,8 @@ fn dump_cpsr() {
8985
println!("CPSR: {:?}", cpsr);
9086
}
9187

92-
#[no_mangle]
93-
unsafe extern "C" fn _irq_handler() {
88+
#[exception(IrqHandler)]
89+
fn irq_handler() {
9490
println!("> IRQ");
9591
while let Some(int_id) = SingleCoreGic::get_and_acknowledge_interrupt() {
9692
println!("- IRQ handle {:?}", int_id);

examples/mps3-an536/src/bin/hello.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@
44
#![no_main]
55

66
// pull in our start-up code
7+
use cortex_r_rt::entry;
8+
9+
// pull in our library
710
use mps3_an536 as _;
811

912
use semihosting::println;
1013

1114
/// The entry-point to the Rust application.
1215
///
13-
/// It is called by the start-up code in `cortex-m-rt`.
14-
#[no_mangle]
15-
pub extern "C" fn kmain() {
16-
main();
17-
}
18-
19-
/// The main function of our Rust application.
20-
///
21-
/// Called by [`kmain`].
16+
/// It is called by the start-up code in `cortex-r-rt`.
17+
#[entry]
2218
fn main() -> ! {
2319
let x = 1.0f64;
2420
let y = x * 2.0;

examples/mps3-an536/src/bin/prefetch-exception-a32.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ use cortex_ar::register::{Ifar, Ifsr};
88
use semihosting::println;
99

1010
// pull in our start-up code
11+
use cortex_r_rt::{entry, exception};
12+
13+
// pull in our library
1114
use mps3_an536 as _;
1215

1316
static COUNTER: AtomicU32 = AtomicU32::new(0);
1417

1518
/// The entry-point to the Rust application.
1619
///
1720
/// It is called by the start-up.
18-
#[no_mangle]
19-
pub extern "C" fn kmain() -> ! {
21+
#[entry]
22+
fn main() -> ! {
2023
println!("Hello, this is a prefetch exception example");
2124

2225
// A BKPT instruction triggers a Prefetch Abort except when Halting debug-mode is enabled.
@@ -49,13 +52,13 @@ core::arch::global_asm!(
4952
"#
5053
);
5154

52-
#[unsafe(no_mangle)]
53-
unsafe extern "C" fn _undefined_handler(_addr: usize) -> ! {
55+
#[exception(UndefinedHandler)]
56+
fn undefined_handler(_addr: usize) -> ! {
5457
panic!("unexpected undefined exception");
5558
}
5659

57-
#[unsafe(no_mangle)]
58-
unsafe extern "C" fn _prefetch_handler(addr: usize) -> usize {
60+
#[exception(PrefetchHandler)]
61+
fn prefetch_handler(addr: usize) -> usize {
5962
println!("prefetch abort occurred");
6063
let ifsr = Ifsr::read();
6164
println!("IFSR (Fault Status Register): {:?}", ifsr);
@@ -92,7 +95,7 @@ unsafe extern "C" fn _prefetch_handler(addr: usize) -> usize {
9295
}
9396
}
9497

95-
#[unsafe(no_mangle)]
96-
unsafe extern "C" fn _abort_handler(_addr: usize) -> ! {
98+
#[exception(AbortHandler)]
99+
fn abort_handler(_addr: usize) -> ! {
97100
panic!("unexpected abort exception");
98101
}

examples/mps3-an536/src/bin/prefetch-exception-t32.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ use cortex_ar::register::{Ifar, Ifsr};
88
use semihosting::println;
99

1010
// pull in our start-up code
11+
use cortex_r_rt::{entry, exception};
12+
13+
// pull in our library
1114
use mps3_an536 as _;
1215

1316
static COUNTER: AtomicU32 = AtomicU32::new(0);
1417

1518
/// The entry-point to the Rust application.
1619
///
1720
/// It is called by the start-up.
18-
#[no_mangle]
19-
pub extern "C" fn kmain() -> ! {
21+
#[entry]
22+
fn main() -> ! {
2023
println!("Hello, this is a prefetch exception example");
2124

2225
// A BKPT instruction triggers a Prefetch Abort except when Halting debug-mode is enabled.
@@ -49,13 +52,13 @@ core::arch::global_asm!(
4952
"#
5053
);
5154

52-
#[unsafe(no_mangle)]
53-
unsafe extern "C" fn _undefined_handler(_addr: usize) -> ! {
55+
#[exception(UndefinedHandler)]
56+
fn undefined_handler(_addr: usize) -> ! {
5457
panic!("unexpected undefined exception");
5558
}
5659

57-
#[unsafe(no_mangle)]
58-
unsafe extern "C" fn _prefetch_handler(addr: usize) -> usize {
60+
#[exception(PrefetchHandler)]
61+
fn prefetch_handler(addr: usize) -> usize {
5962
println!("prefetch abort occurred");
6063
let ifsr = Ifsr::read();
6164
println!("IFSR (Fault Status Register): {:?}", ifsr);
@@ -95,7 +98,7 @@ unsafe extern "C" fn _prefetch_handler(addr: usize) -> usize {
9598
}
9699
}
97100

98-
#[unsafe(no_mangle)]
99-
unsafe extern "C" fn _abort_handler(_addr: usize) -> ! {
101+
#[exception(AbortHandler)]
102+
fn abort_handler(_addr: usize) -> ! {
100103
panic!("unexpected abort exception");
101104
}

examples/mps3-an536/src/bin/registers.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,18 @@
44
#![no_main]
55

66
// pull in our start-up code
7+
use cortex_r_rt::entry;
8+
9+
// pull in our library
710
use mps3_an536 as _;
811

912
use semihosting::println;
1013

1114
/// The entry-point to the Rust application.
1215
///
13-
/// It is called by the start-up code in `cortex-m-rt`.
14-
#[no_mangle]
15-
pub extern "C" fn kmain() {
16-
main();
17-
}
18-
19-
/// The entry-point to the Rust application.
20-
///
21-
/// Called by [`kmain`].
22-
pub fn main() -> ! {
16+
/// It is called by the start-up code in `cortex-r-rt`.
17+
#[entry]
18+
fn main() -> ! {
2319
chip_info();
2420
#[cfg(arm_architecture = "v7-r")]
2521
mpu_pmsa_v7();

examples/mps3-an536/src/bin/smp_test.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use core::cell::{RefCell, UnsafeCell};
1414
use core::sync::atomic::{AtomicBool, AtomicU32, Ordering};
1515

1616
// pull in our start-up code
17+
use cortex_r_rt::entry;
18+
19+
// pull in our library
1720
use mps3_an536 as _;
1821

1922
use semihosting::println;
@@ -58,9 +61,9 @@ const CS_MUTEX_LOOPS: u32 = 1000;
5861

5962
/// The entry-point to the Rust application.
6063
///
61-
/// It is called by the start-up code in `cortex-m-rt`.
62-
#[no_mangle]
63-
pub extern "C" fn kmain() {
64+
/// It is called by the start-up code in `cortex-r-rt`.
65+
#[entry]
66+
fn main() -> ! {
6467
let fpga_led = 0xE020_2000 as *mut u32;
6568
extern "C" {
6669
static mut _core1_stack_pointer: usize;

0 commit comments

Comments
 (0)