Skip to content

Commit 728cd2b

Browse files
committed
address review comments
1 parent bbacedb commit 728cd2b

File tree

10 files changed

+302
-291
lines changed

10 files changed

+302
-291
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ categories = ["embedded", "no-std"]
1111

1212
[dependencies]
1313
aarch64-paging = { version = "0.10", default-features = false }
14-
aarch64-rt = { version = "0.3", features = ["el2", "exceptions", "initial-pagetable", "psci"], default-features = false }
14+
aarch64-rt = { version = "0.4", features = ["el2", "exceptions", "initial-pagetable", "psci"], default-features = false }
1515
arm-pl011-uart = "0.4"
16+
arm-psci = "0.2"
1617
buddy_system_allocator = { version = "0.11", default-features = false, features = ["alloc", "use_spin"] }
1718
# TODO: replace with a crates.io version when it's released
1819
dtoolkit = { version = "0.1", git = "ssh://git@github.com/google/dtoolkit.git", rev = "35c8644de5fd2ff0098cfd8e493a8cffc163cf04", features = ["write"] }
@@ -23,10 +24,6 @@ safe-mmio = "0.2"
2324
smccc = "0.2"
2425
spin = { version = "0.10", features = ["lazy", "once", "spin_mutex"], default-features = false }
2526

26-
[patch.crates-io]
27-
# TODO: replace with a crates.io version when this is merged: https://github.com/google/aarch64-rt/pull/31
28-
aarch64-rt = { git = "https://github.com/m4tx/aarch64-rt.git", rev = "a93fdb00baa88549c7e9c90a4dd1c66b164844bf" }
29-
3027
[lints.rust]
3128
deprecated-safe = "warn"
3229
keyword-idents = "warn"

src/arch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ sys_reg!(spsr_el2, {
151151
});
152152
sys_reg!(elr_el2);
153153
sys_reg!(sp_el1);
154+
sys_reg!(mpidr_el1);
154155

155156
pub(super) fn disable_mmu_and_caches() {
156157
invalidate_dcache();

src/exceptions.rs

Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,69 +6,13 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use core::arch::naked_asm;
10-
11-
#[unsafe(no_mangle)]
12-
extern "C" fn sync_exception_current(_elr: u64, _spsr: u64) {
13-
panic!("Unexpected sync_exception_current");
14-
}
15-
16-
#[unsafe(no_mangle)]
17-
extern "C" fn irq_current(_elr: u64, _spsr: u64) {
18-
panic!("Unexpected irq_current");
19-
}
20-
21-
#[unsafe(no_mangle)]
22-
extern "C" fn fiq_current(_elr: u64, _spsr: u64) {
23-
panic!("Unexpected fiq_current");
24-
}
25-
26-
#[unsafe(no_mangle)]
27-
extern "C" fn serr_current(_elr: u64, _spsr: u64) {
28-
panic!("Unexpected serr_current");
29-
}
30-
31-
#[unsafe(naked)]
32-
#[unsafe(no_mangle)]
33-
#[rustfmt::skip]
34-
unsafe extern "C" fn sync_lower() {
35-
naked_asm!(
36-
// We load and store the registers from/to where aarch64 exception handler expects them:
37-
// https://github.com/google/aarch64-rt/blob/047f3b0962064d334f149fe5fcd46ba57ea758ab/src/exceptions.S#L16-L65
38-
"stp x29, x30, [sp, #-0x10]!",
39-
40-
"ldp x2, x3, [sp, #0x10]",
41-
"ldp x4, x5, [sp, #0x20]",
42-
43-
"bl {sync_lower_impl}",
44-
45-
"mov x1, xzr",
46-
"mov x2, xzr",
47-
"mov x3, xzr",
48-
"stp x0, x1, [sp, #0x10]",
49-
"stp x2, x3, [sp, #0x20]",
50-
"ldr x4, [sp, #8 * 22 + 16]",
51-
// Return after the HVC call
52-
"add x4, x4, #4",
53-
"str x4, [sp, #8 * 22 + 16]",
54-
55-
"ldp x29, x30, [sp], #0x10",
56-
"ret",
57-
sync_lower_impl = sym crate::hypervisor::sync_lower_impl,
58-
)
59-
}
60-
61-
#[unsafe(no_mangle)]
62-
extern "C" fn irq_lower(_elr: u64, _spsr: u64) {
63-
panic!("Unexpected irq_lower");
64-
}
65-
66-
#[unsafe(no_mangle)]
67-
extern "C" fn fiq_lower(_elr: u64, _spsr: u64) {
68-
panic!("Unexpected fiq_lower");
69-
}
70-
71-
#[unsafe(no_mangle)]
72-
extern "C" fn serr_lower(_elr: u64, _spsr: u64) {
73-
panic!("Unexpected serr_lower");
9+
use aarch64_rt::{ExceptionHandlers, RegisterStateRef};
10+
11+
pub struct Exceptions;
12+
impl ExceptionHandlers for Exceptions {
13+
extern "C" fn sync_lower(register_state: RegisterStateRef) {
14+
// sync_lower exception is most likely a HVC/SMC call, which we should
15+
// handle in the hypervisor.
16+
crate::hypervisor::handle_sync_lower(register_state);
17+
}
7418
}

0 commit comments

Comments
 (0)