aarch64_cpu_ext/asm/
cache.rs

1mod sealed {
2
3    pub trait Ic {
4        fn ic(&self);
5    }
6
7    pub trait Dc {
8        fn dc(&self, addr: u64);
9    }
10}
11
12macro_rules! ic {
13    ($A:ident, $T: ident) => {
14        pub struct $T;
15        pub const $A: $T = $T {};
16
17        impl sealed::Ic for $T {
18            #[inline(always)]
19            fn ic(&self) {
20                match () {
21                    #[cfg(target_arch = "aarch64")]
22                    () => unsafe {
23                        core::arch::asm!(concat!("ic ", stringify!($A)), options(nostack))
24                    },
25
26                    #[cfg(not(target_arch = "aarch64"))]
27                    () => unimplemented!(),
28                }
29            }
30        }
31    };
32}
33
34macro_rules! dc {
35    ($A: ident, $T: ident) => {
36        pub struct $T;
37        pub const $A: $T = $T{};
38        impl sealed::Dc for $T {
39            #[inline(always)]
40            fn dc(&self, addr:u64){
41                match() {
42                    #[cfg(target_arch = "aarch64")]
43                    () => unsafe {
44                        core::arch::asm!(concat!("dc ",stringify!($A), ",{}"), in(reg) addr, options(nostack))
45                    },
46                    #[cfg(not(target_arch = "aarch64"))]
47                    () => unimplemented!(),
48                }
49            }
50        }
51    }
52}
53
54ic!(IALLU, Iallu);
55ic!(IALLUIS, Ialluis);
56dc!(CVAC, Cvac);
57dc!(IVAC, Ivac);
58dc!(CIVAC, Civac);
59dc!(CISW, Cisw);
60dc!(ISW, Isw);
61dc!(CSW, Csw);
62
63#[inline(always)]
64pub fn ic(_arg: impl sealed::Ic) {
65    _arg.ic();
66}
67
68#[inline(always)]
69pub fn dc(_arg: impl sealed::Dc, addr: u64) {
70    _arg.dc(addr);
71}