Skip to content

Commit 8843ca2

Browse files
committed
remove some inline assembly
- reusing functions from rust-aarch64
1 parent b3e37ad commit 8843ca2

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

Cargo.lock

Lines changed: 23 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ memory_addresses = { version = "0.2.2", default-features = false, features = [
169169
] }
170170

171171
[target.'cfg(target_arch = "aarch64")'.dependencies]
172-
aarch64 = { version = "0.0.13", default-features = false }
172+
aarch64 = { version = "0.0.14", default-features = false }
173173
arm-gic = { version = "0.3" }
174174
arm_pl031 = {version = "0.2.1" }
175175
hermit-dtb = { version = "0.1" }

src/arch/aarch64/kernel/processor.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::arch::asm;
22
use core::{fmt, str};
33

4-
use aarch64::regs::{CNTFRQ_EL0, Readable};
4+
use aarch64::regs::*;
55
use hermit_dtb::Dtb;
66
use hermit_sync::{Lazy, without_interrupts};
77

@@ -144,17 +144,7 @@ pub fn get_frequency() -> u16 {
144144

145145
#[inline]
146146
pub fn get_timestamp() -> u64 {
147-
let value: u64;
148-
149-
unsafe {
150-
asm!(
151-
"mrs {value}, cntpct_el0",
152-
value = out(reg) value,
153-
options(nostack),
154-
);
155-
}
156-
157-
value
147+
CNTPCT_EL0.get()
158148
}
159149

160150
#[inline]
@@ -219,24 +209,12 @@ fn __set_oneshot_timer(wakeup_time: Option<u64>) {
219209
// wt is the absolute wakeup time in microseconds based on processor::get_timer_ticks.
220210
let deadline = (wt * u64::from(get_frequency())) / 1000;
221211

222-
unsafe {
223-
asm!(
224-
"msr cntp_cval_el0, {value}",
225-
"msr cntp_ctl_el0, {enable}",
226-
value = in(reg) deadline,
227-
enable = in(reg) 1u64,
228-
options(nostack, nomem),
229-
);
230-
}
212+
CNTP_CVAL_EL0.set(deadline);
213+
CNTP_CTL_EL0.write(CNTP_CTL_EL0::ENABLE::SET);
231214
} else {
232215
// disable timer
233-
unsafe {
234-
asm!(
235-
"msr cntp_cval_el0, xzr",
236-
"msr cntp_ctl_el0, xzr",
237-
options(nostack, nomem),
238-
);
239-
}
216+
CNTP_CVAL_EL0.set(0);
217+
CNTP_CTL_EL0.write(CNTP_CTL_EL0::ENABLE::CLEAR);
240218
}
241219
}
242220

0 commit comments

Comments
 (0)