Skip to content

Commit db603e8

Browse files
zaklogicianmidnightveil
authored andcommitted
tool: implement Viper export
We implement the `--viper-output` command line argument which lets one dump the capability table of a PD into a Viper file for verification purposes. Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
1 parent 2e049a4 commit db603e8

4 files changed

Lines changed: 396 additions & 0 deletions

File tree

tool/microkit/src/argparse.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn print_help(sdk: &Sdk) {
2929
);
3030
println!(" --config CONFIG");
3131
println!(" --capdl-json CAPDL_SPEC (JSON format)");
32+
println!(" --viper-output DIRECTORY_PATH");
3233
println!(" --search-path [SEARCH_PATH ...]");
3334
}
3435

@@ -69,6 +70,7 @@ pub struct Args {
6970
pub config: String,
7071
pub report_path: PathBuf,
7172
pub capdl_json_path: Option<PathBuf>,
73+
pub viper_output_dir: Option<PathBuf>,
7274
pub output_path: PathBuf,
7375
pub search_paths: Vec<PathBuf>,
7476
pub requested_image_type: RequestedImageType,
@@ -167,6 +169,7 @@ impl Args {
167169
let mut output_path = PathBuf::from("loader.img");
168170
let mut report_path = PathBuf::from("report.txt");
169171
let mut capdl_json_path = None;
172+
let mut viper_output_dir = None;
170173
let mut search_paths = Vec::new();
171174

172175
let mut sdf_path = None;
@@ -205,6 +208,9 @@ impl Args {
205208
let params = consume_parameters(&mut args);
206209
search_paths.extend(params.into_iter().map(PathBuf::from));
207210
}
211+
"--viper-output" => {
212+
viper_output_dir = Some(consume_parameter(&mut args, "--viper-output")?.into());
213+
}
208214
"--image-type" => {
209215
let value = consume_parameter(&mut args, "--image-type")?;
210216
match RequestedImageType::parse(value.as_str()) {
@@ -262,6 +268,7 @@ impl Args {
262268
config,
263269
report_path,
264270
capdl_json_path,
271+
viper_output_dir,
265272
output_path,
266273
search_paths,
267274
requested_image_type,

tool/microkit/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub mod sel4;
2323
pub mod symbols;
2424
pub mod uimage;
2525
pub mod util;
26+
pub mod viper;
2627

2728
// Note that these values are used in the monitor so should also be changed there
2829
// if any of these were to change.

tool/microkit/src/main.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use microkit_tool::util::{
2929
get_full_path, human_size_strict, json_str, json_str_as_bool, json_str_as_u64, round_down,
3030
round_up,
3131
};
32+
use microkit_tool::viper;
3233
use microkit_tool::{DisjointMemoryRegion, MemoryRegion};
3334
use std::collections::HashMap;
3435
use std::fs::{self, metadata};
@@ -694,6 +695,33 @@ fn main() -> Result<(), String> {
694695
fs::write(capdl_json, &serialised).unwrap();
695696
};
696697

698+
if let Some(viper_output_dir) = args.viper_output_dir {
699+
// NB returns Ok if the directory already exists, that's fine
700+
fs::create_dir_all(&viper_output_dir).unwrap_or_else(|source| {
701+
eprintln!(
702+
"ERROR: cannot write Viper output directory {}: {source}",
703+
&viper_output_dir.display()
704+
);
705+
std::process::exit(1);
706+
});
707+
for view in viper::get_combined_views(&spec_container, &system) {
708+
let mut output = format!(
709+
"// exported invariants for PD {} in {}\n",
710+
view.pd_name,
711+
&args.sdf_path.display(),
712+
);
713+
view.export(&mut output);
714+
let path = viper_output_dir.join(format!("{}.vpr", view.pd_name));
715+
fs::write(&path, output).unwrap_or_else(|source| {
716+
eprintln!(
717+
"ERROR: cannot write Viper output file {}: {source}",
718+
&path.display()
719+
);
720+
std::process::exit(1);
721+
});
722+
}
723+
}
724+
697725
write_report(&spec_container, &kernel_config, &args.report_path);
698726
system_built = true;
699727
break;

0 commit comments

Comments
 (0)