2018-04-11 17:27:11 +04:00
|
|
|
extern crate cc;
|
|
|
|
|
2018-05-20 19:56:41 +04:00
|
|
|
use std::fs::File;
|
2018-11-28 21:22:44 +04:00
|
|
|
use std::io::{Result, Write};
|
2019-04-01 19:29:50 +04:00
|
|
|
use std::path::Path;
|
2018-05-20 19:56:41 +04:00
|
|
|
|
2018-04-11 17:27:11 +04:00
|
|
|
fn main() {
|
2019-03-27 14:35:08 +04:00
|
|
|
println!("cargo:rerun-if-env-changed=LOG");
|
|
|
|
println!("cargo:rerun-if-env-changed=BOARD");
|
|
|
|
println!("cargo:rerun-if-env-changed=SFSIMG");
|
2018-11-28 21:22:44 +04:00
|
|
|
|
2019-04-09 13:08:04 +04:00
|
|
|
let arch: String = std::env::var("ARCH").unwrap();
|
|
|
|
let board: String = std::env::var("BOARD").unwrap();
|
|
|
|
match arch.as_str() {
|
|
|
|
"x86_64" => {
|
|
|
|
gen_vector_asm().unwrap();
|
|
|
|
}
|
|
|
|
"riscv32" => {}
|
|
|
|
"riscv64" => {}
|
|
|
|
"mipsel" => {
|
|
|
|
gen_dtb_asm(&arch, &board).unwrap();
|
|
|
|
}
|
|
|
|
"aarch64" => {}
|
|
|
|
_ => panic!("Unknown arch {}", arch),
|
|
|
|
}
|
2018-05-20 19:56:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn gen_vector_asm() -> Result<()> {
|
2019-03-27 14:35:08 +04:00
|
|
|
let mut f = File::create("src/arch/x86_64/interrupt/vector.asm").unwrap();
|
2018-05-20 19:56:41 +04:00
|
|
|
|
2019-03-27 14:35:08 +04:00
|
|
|
writeln!(f, "# generated by build.rs - do not edit")?;
|
|
|
|
writeln!(f, ".section .text")?;
|
|
|
|
writeln!(f, ".intel_syntax noprefix")?;
|
|
|
|
for i in 0..256 {
|
|
|
|
writeln!(f, "vector{}:", i)?;
|
|
|
|
if !(i == 8 || (i >= 10 && i <= 14) || i == 17) {
|
|
|
|
writeln!(f, "\tpush 0")?;
|
|
|
|
}
|
|
|
|
writeln!(f, "\tpush {}", i)?;
|
|
|
|
writeln!(f, "\tjmp __alltraps")?;
|
|
|
|
}
|
2018-05-20 19:56:41 +04:00
|
|
|
|
2019-03-27 14:35:08 +04:00
|
|
|
writeln!(f, "\n.section .rodata")?;
|
|
|
|
writeln!(f, ".global __vectors")?;
|
|
|
|
writeln!(f, "__vectors:")?;
|
|
|
|
for i in 0..256 {
|
|
|
|
writeln!(f, "\t.quad vector{}", i)?;
|
|
|
|
}
|
|
|
|
Ok(())
|
2018-11-28 21:22:44 +04:00
|
|
|
}
|
2019-04-01 19:07:49 +04:00
|
|
|
|
2019-04-03 20:10:18 +04:00
|
|
|
fn gen_dtb_asm(arch: &String, _board: &String) -> Result<()> {
|
2019-04-01 19:07:49 +04:00
|
|
|
let dtb = std::env::var("DTB").unwrap();
|
|
|
|
|
|
|
|
if !Path::new(&dtb).is_file() {
|
|
|
|
panic!("DTB `{}` not found", dtb)
|
|
|
|
}
|
|
|
|
|
2019-04-09 13:08:04 +04:00
|
|
|
let mut f = File::create(format!("src/arch/{}/boot/dtb.gen.s", arch)).unwrap();
|
2019-04-01 19:07:49 +04:00
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed={}", dtb);
|
|
|
|
println!("cargo:rerun-if-env-changed=DTB");
|
|
|
|
|
2019-04-09 13:08:04 +04:00
|
|
|
writeln!(f, "# generated by build.rs - do not edit")?;
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
r#"
|
2019-04-01 19:07:49 +04:00
|
|
|
.section .dtb,"a"
|
|
|
|
.align 12
|
|
|
|
.global _dtb_start, _dtb_end
|
|
|
|
_dtb_start:
|
|
|
|
.incbin "{}"
|
|
|
|
_dtb_end:
|
2019-04-09 13:08:04 +04:00
|
|
|
"#,
|
|
|
|
dtb
|
|
|
|
)?;
|
2019-04-01 19:07:49 +04:00
|
|
|
|
|
|
|
Ok(())
|
2019-04-09 13:08:04 +04:00
|
|
|
}
|