1use super::Rec;
2
3use aarch64_cpu::registers::*;
4
5#[repr(C)]
6#[derive(Default, Debug)]
7pub struct PauthRegister {
8 pub apiakeylo_el1: u64,
9 pub apiakeyhi_el1: u64,
10 pub apibkeylo_el1: u64,
11 pub apibkeyhi_el1: u64,
12 pub apdakeylo_el1: u64,
13 pub apdakeyhi_el1: u64,
14 pub apdbkeylo_el1: u64,
15 pub apdbkeyhi_el1: u64,
16 pub apgakeylo_el1: u64,
17 pub apgakeyhi_el1: u64,
18}
19
20pub fn init_pauth(_rec: &mut Rec<'_>) {
21 }
23
24pub fn restore_state(rec: &Rec<'_>) {
25 unsafe {
26 _restore_state(rec);
27 }
28}
29
30#[target_feature(enable = "pacg", enable = "paca")]
34unsafe fn _restore_state(rec: &Rec<'_>) {
35 let pauth = &rec.context.pauth;
36
37 APIAKEYLO_EL1.set(pauth.apiakeylo_el1);
38 APIAKEYHI_EL1.set(pauth.apiakeyhi_el1);
39 APIBKEYLO_EL1.set(pauth.apibkeylo_el1);
40 APIBKEYHI_EL1.set(pauth.apibkeyhi_el1);
41 APDAKEYLO_EL1.set(pauth.apdakeylo_el1);
42 APDAKEYHI_EL1.set(pauth.apdakeyhi_el1);
43 APDBKEYLO_EL1.set(pauth.apdbkeylo_el1);
44 APDBKEYHI_EL1.set(pauth.apdbkeyhi_el1);
45 APGAKEYLO_EL1.set(pauth.apgakeylo_el1);
46 APGAKEYHI_EL1.set(pauth.apgakeyhi_el1);
47}
48
49pub fn save_state(rec: &mut Rec<'_>) {
50 unsafe {
51 _save_state(rec);
52 }
53}
54
55#[target_feature(enable = "pacg", enable = "paca")]
59unsafe fn _save_state(rec: &mut Rec<'_>) {
60 let pauth = &mut rec.context.pauth;
61
62 pauth.apiakeylo_el1 = APIAKEYLO_EL1.get();
63 pauth.apiakeyhi_el1 = APIAKEYHI_EL1.get();
64 pauth.apibkeylo_el1 = APIBKEYLO_EL1.get();
65 pauth.apibkeyhi_el1 = APIBKEYHI_EL1.get();
66 pauth.apdakeylo_el1 = APDAKEYLO_EL1.get();
67 pauth.apdakeyhi_el1 = APDAKEYHI_EL1.get();
68 pauth.apdbkeylo_el1 = APDBKEYLO_EL1.get();
69 pauth.apdbkeyhi_el1 = APDBKEYHI_EL1.get();
70 pauth.apgakeylo_el1 = APGAKEYLO_EL1.get();
71 pauth.apgakeyhi_el1 = APGAKEYHI_EL1.get();
72}