-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.rs
33 lines (29 loc) · 898 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::fs::File;
use std::io::{Result, Write};
use std::path::PathBuf;
fn main() -> Result<()> {
gen_vector_asm()?;
Ok(())
}
/// Generate assembly file for x86_64 trap vector
fn gen_vector_asm() -> Result<()> {
let out_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let mut f = File::create(out_path.join("vector.S"))?;
writeln!(f, "# generated by build.rs - do not edit")?;
writeln!(f, ".section .text")?;
for i in 0..256 {
writeln!(f, "vector{}:", i)?;
if !(i == 8 || (10..=14).contains(&i) || i == 17) {
writeln!(f, "\tpush 0")?;
}
writeln!(f, "\tpush {}", i)?;
writeln!(f, "\tjmp __alltraps")?;
}
writeln!(f, "\n.section .rodata")?;
writeln!(f, ".global __vectors")?;
writeln!(f, "__vectors:")?;
for i in 0..256 {
writeln!(f, "\t.quad vector{}", i)?;
}
Ok(())
}