Skip to content

Commit 92cb29e

Browse files
committed
riscv-macros: modify multi-hart example to use post_init attribute
1 parent 71a97c8 commit 92cb29e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

tests-qemu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ riscv-semihosting = { path = "../riscv-semihosting" }
1515
default = ["single-hart"]
1616
s-mode = ["riscv-rt/s-mode", "single-hart"]
1717
single-hart = ["riscv-rt/single-hart", "riscv/critical-section-single-hart"]
18-
multi-hart = []
18+
multi-hart = ["riscv-rt/post-init"]

tests-qemu/examples/multi_hart.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern crate panic_halt;
1010

1111
use core::arch::global_asm;
1212
use core::sync::atomic::{AtomicBool, Ordering};
13-
use riscv_rt::entry;
13+
use riscv_rt::{entry, post_init};
1414
use riscv_semihosting::debug::{self, EXIT_SUCCESS};
1515

1616
const UART_BASE: usize = 0x1000_0000;
@@ -104,21 +104,24 @@ _mp_hook:
104104
"#
105105
);
106106

107-
#[entry]
108-
fn main(hartid: usize) -> ! {
107+
#[post_init]
108+
fn post_init(hartid: usize) {
109109
if hartid == 0 {
110110
uart_init();
111111
uart_print("Hart 0: Initializing\n");
112112

113113
// Send IPI to Hart 1 (write to CLINT msip register for hart 1)
114-
unsafe {
115-
(0x02000004usize as *mut u32).write_volatile(1);
116-
}
114+
unsafe { (0x02000004usize as *mut u32).write_volatile(1) };
115+
}
116+
}
117117

118+
#[entry]
119+
fn main(hartid: usize) -> ! {
120+
if hartid == 0 {
121+
// Hart 0 reaches here after initializing UART and sending IPI
118122
while !HART1_DONE.load(Ordering::Acquire) {
119123
core::hint::spin_loop();
120124
}
121-
122125
uart_print("Hart 0: Both harts done\n");
123126
debug::exit(EXIT_SUCCESS);
124127
} else {

0 commit comments

Comments
 (0)