|
6 | 6 | // option. This file may not be copied, modified, or distributed |
7 | 7 | // except according to those terms. |
8 | 8 |
|
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 | + } |
74 | 18 | } |
0 commit comments