-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding more test payloads (debug, mret, mcause, mepc, mconfigpts, mts…
…elect) Now we got all the pieces needed to add a new bunch of tests, those are now enabled by default (including the breakpoint test!). Co-authored-by: Abel Vexina Wilkinson <abel.vexinawilkinson@epfl.ch>
- Loading branch information
Showing
13 changed files
with
369 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "mcause" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
mirage_abi = { path = "../../crates/mirage_abi" } |
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,72 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::arch::{asm, global_asm}; | ||
use core::panic::PanicInfo; | ||
use core::usize; | ||
|
||
use mirage_abi::{failure, success}; | ||
|
||
global_asm!( | ||
r#" | ||
.text | ||
.align 4 | ||
.global _start | ||
_start: | ||
j {entry} | ||
"#, | ||
entry = sym entry, | ||
); | ||
|
||
extern "C" fn entry() -> ! { | ||
let secret1: usize = 0x42; | ||
let mut res: usize; | ||
unsafe { | ||
asm!( | ||
"li {0}, 0x42", | ||
"csrw mcause, {0}", | ||
"csrr {1}, mcause", | ||
in(reg) secret1, | ||
out(reg) res, | ||
); | ||
} | ||
|
||
read_test(res, 0); | ||
|
||
let secret2: usize = 0x9; | ||
|
||
unsafe { | ||
asm!( | ||
"li {0}, 0x9", | ||
"csrw mcause, {0}", | ||
"csrr {1}, mcause", | ||
in(reg) secret2, | ||
out(reg) res, | ||
); | ||
} | ||
|
||
read_test(res, secret2); | ||
|
||
unsafe { | ||
asm!( | ||
"li {0}, 0x8000000000000009", | ||
"csrw mcause, {0}", | ||
"csrr {1}, mcause", | ||
in(reg) secret2, | ||
out(reg) res, | ||
); | ||
} | ||
|
||
read_test(res, secret2); | ||
|
||
success(); | ||
} | ||
|
||
fn read_test(out_csr: usize, expected: usize) { | ||
assert_eq!(out_csr, expected); | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(_info: &PanicInfo) -> ! { | ||
failure(); | ||
} |
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,7 @@ | ||
[package] | ||
name = "mconfigptr" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
mirage_abi = { path = "../../crates/mirage_abi" } |
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,46 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::arch::{asm, global_asm}; | ||
use core::panic::PanicInfo; | ||
use core::usize; | ||
|
||
use mirage_abi::{failure, success}; | ||
|
||
global_asm!( | ||
r#" | ||
.text | ||
.align 4 | ||
.global _start | ||
_start: | ||
j {entry} | ||
"#, | ||
entry = sym entry, | ||
); | ||
|
||
extern "C" fn entry() -> ! { | ||
let secret1: usize = 0x42; | ||
let mut res: usize; | ||
unsafe { | ||
asm!( | ||
"li {0}, 0x42", | ||
"csrw mcause, {0}", | ||
"csrr {1}, mcause", | ||
in(reg) secret1, | ||
out(reg) res, | ||
); | ||
} | ||
|
||
read_test(res, 0); | ||
|
||
success(); | ||
} | ||
|
||
fn read_test(out_csr: usize, expected: usize) { | ||
assert_eq!(out_csr, expected); | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(_info: &PanicInfo) -> ! { | ||
failure(); | ||
} |
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,7 @@ | ||
[package] | ||
name = "mepc" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
mirage_abi = { path = "../../crates/mirage_abi" } |
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,44 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::arch::{asm, global_asm}; | ||
use core::panic::PanicInfo; | ||
use core::usize; | ||
|
||
use mirage_abi::{failure, success}; | ||
|
||
global_asm!( | ||
r#" | ||
.text | ||
.align 4 | ||
.global _start | ||
_start: | ||
j {entry} | ||
"#, | ||
entry = sym entry, | ||
); | ||
|
||
extern "C" fn entry() -> ! { | ||
let secret: usize = 0x42; | ||
let res: usize; | ||
unsafe { | ||
asm!( | ||
"li {0}, 0x42", | ||
"csrw mepc, {0}", | ||
"csrr {1}, mepc", | ||
in(reg) secret, | ||
out(reg) res, | ||
); | ||
} | ||
|
||
if res == secret { | ||
success(); | ||
} | ||
|
||
panic!(); | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(_info: &PanicInfo) -> ! { | ||
failure(); | ||
} |
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,7 @@ | ||
[package] | ||
name = "mret" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
mirage_abi = { path = "../../crates/mirage_abi" } |
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,80 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::arch::{asm, global_asm}; | ||
use core::panic::PanicInfo; | ||
|
||
use mirage_abi::{failure, success}; | ||
|
||
global_asm!( | ||
r#" | ||
.text | ||
.align 4 | ||
.global _start | ||
_start: | ||
j {entry} | ||
"#, | ||
entry = sym entry, | ||
); | ||
|
||
extern "C" fn entry() -> ! { | ||
let mut mstatus: usize; | ||
let mut t6: usize; | ||
unsafe { | ||
let handler = _raw_breakpoint_trap_handler as usize; | ||
// Let's rise an exception breakpoint directly | ||
asm!( | ||
"csrw mtvec, {0}", // Write mtvec | ||
"ebreak", // Cause an exception, we should return right away! | ||
"csrr {1}, mstatus", // Read mstatus | ||
in(reg) handler, | ||
out(reg) mstatus, | ||
out("t6") t6, // The handler writes a secret value in t6 | ||
); | ||
} | ||
|
||
// MPP = 0 | ||
read_test((mstatus >> 11) & 0b11, 0); | ||
// MPIE = 1 | ||
read_test((mstatus >> 7) & 0b1, 1); | ||
// MPRV = 0 | ||
read_test((mstatus >> 17) & 0b1, 0); | ||
|
||
assert_eq!( | ||
t6, 0x42, | ||
"Trap handler did not properly update the value in t6" | ||
); | ||
|
||
success(); | ||
} | ||
|
||
// —————————————————————————————— Trap Handler —————————————————————————————— // | ||
|
||
global_asm!( | ||
r#" | ||
.text | ||
.align 4 | ||
.global _raw_breakpoint_trap_handler | ||
_raw_breakpoint_trap_handler: | ||
csrr t6, mepc // Read EPC | ||
addi t6, t6, 4 // Increment return pointer | ||
csrw mepc, t6 // Write it back | ||
li t6, 0x42 // And store a secret value in t6 before returning | ||
mret | ||
"#, | ||
); | ||
|
||
extern "C" { | ||
fn _raw_breakpoint_trap_handler(); | ||
} | ||
|
||
fn read_test(out_csr: usize, expected: usize) { | ||
assert_eq!(out_csr, expected); | ||
} | ||
|
||
// ————————————————————————————— Panic Handler —————————————————————————————— // | ||
|
||
#[panic_handler] | ||
fn panic(_info: &PanicInfo) -> ! { | ||
failure(); | ||
} |
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,7 @@ | ||
[package] | ||
name = "tselect" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
mirage_abi = { path = "../../crates/mirage_abi" } |
Oops, something went wrong.