-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic aarch64 cache coherency test.
- Loading branch information
1 parent
6796c0b
commit 4c9c71e
Showing
2 changed files
with
61 additions
and
2 deletions.
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,60 @@ | ||
// This file contains test cases designed to validate proper assembler cache invalidation | ||
// this is needed because aarch64's modified harvard architecture has an incoherent instruction and | ||
// data cache. Therefore, it is needed to explicitly command the cache hierarchy to flush the dcache | ||
// to the coherent layers, invalidate the icache, and ensure no stale data is left in the | ||
// instruction pipeline. Testcases in this file are designed to break if this isn't handled properly | ||
#![allow(unused_imports)] | ||
|
||
extern crate dynasmrt; | ||
|
||
use dynasmrt::dynasm; | ||
use dynasmrt::{DynasmApi}; | ||
|
||
#[cfg(target_arch="aarch64")] | ||
#[test] | ||
fn test_cache_coherency_same_core() { | ||
let mut ops = dynasmrt::aarch64::Assembler::new().unwrap(); | ||
let reader = ops.reader(); | ||
|
||
// write some code | ||
let start = ops.offset(); | ||
dynasm!(ops | ||
; .arch aarch64 | ||
; mov w0, 0xABCD | ||
; ret | ||
); | ||
let end = ops.offset(); | ||
|
||
ops.commit().unwrap(); | ||
|
||
// execute it once | ||
{ | ||
let buf = reader.lock(); | ||
let callable: extern "C" fn() -> u32 = unsafe { std::mem::transmute(buf.ptr(start)) }; | ||
assert_eq!(callable(), 0xABCD); | ||
drop(buf); | ||
} | ||
|
||
// change the code | ||
ops.alter(|modifier| { | ||
modifier.goto(start); | ||
|
||
dynasm!(modifier | ||
; .arch aarch64 | ||
; mov w0, 0xCDEF | ||
; ret | ||
); | ||
modifier.check_exact(end).unwrap(); | ||
|
||
}).unwrap(); | ||
|
||
ops.commit().unwrap(); | ||
|
||
// execute it again! | ||
{ | ||
let buf = reader.lock(); | ||
let callable: extern "C" fn() -> u32 = unsafe { std::mem::transmute(buf.ptr(start)) }; | ||
assert_eq!(callable(), 0xCDEF); | ||
drop(buf); | ||
} | ||
} |
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