-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use core::{arch::asm, ptr::NonNull}; | ||
|
||
#[naked] | ||
unsafe extern "C" fn _dcache_invalidate_range(_addr: usize, _end: usize) { | ||
asm!( | ||
"mrs x3, ctr_el0", | ||
"ubfx x3, x3, #16, #4", | ||
"mov x2, #4", | ||
"lsl x2, x2, x3", /* cache line size */ | ||
/* x2 <- minimal cache line size in cache system */ | ||
"sub x3, x2, #1", | ||
"bic x0, x0, x3", | ||
"1: dc ivac, x0", /* invalidate data or unified cache */ | ||
"add x0, x0, x2", | ||
"cmp x0, x1", | ||
"b.lo 1b", | ||
"dsb sy", | ||
"ret", | ||
options(noreturn) | ||
); | ||
} | ||
|
||
#[naked] | ||
unsafe extern "C" fn _dcache_flush_range(_addr: usize, _end: usize) { | ||
asm!( | ||
"mrs x3, ctr_el0", | ||
"ubfx x3, x3, #16, #4", | ||
"mov x2, #4", | ||
"lsl x2, x2, x3", /* cache line size */ | ||
/* x2 <- minimal cache line size in cache system */ | ||
"sub x3, x2, #1", | ||
"bic x0, x0, x3", | ||
"1: dc civac, x0", /* clean & invalidate data or unified cache */ | ||
"add x0, x0, x2", | ||
"cmp x0, x1", | ||
"b.lo 1b", | ||
"dsb sy", | ||
"ret", | ||
options(noreturn), | ||
); | ||
} | ||
|
||
/// Invalidate data cache | ||
#[inline] | ||
pub fn dcache_invalidate_range(addr: NonNull<u8>, size: usize) { | ||
unsafe { _dcache_invalidate_range(addr.as_ptr() as usize, addr.as_ptr() as usize + size) } | ||
} | ||
|
||
/// Flush data cache | ||
#[inline] | ||
pub fn dcache_flush_range(addr: NonNull<u8>, size: usize) { | ||
unsafe { _dcache_flush_range(addr.as_ptr() as usize, addr.as_ptr() as usize + size) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters