|
|
|
@ -1,23 +1,42 @@
|
|
|
|
|
extern crate cc;
|
|
|
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
|
use std::io::{Write, Result};
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
use std::io::{Result, Write};
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
if std::env::var("TARGET").unwrap().find("x86_64").is_some() {
|
|
|
|
|
// cc::Build::new()
|
|
|
|
|
// .file("src/arch/x86_64/driver/apic/lapic.c")
|
|
|
|
|
// .file("src/arch/x86_64/driver/keyboard/keyboard.c")
|
|
|
|
|
// .flag("-mcmodel=large")
|
|
|
|
|
// .compile("cobj");
|
|
|
|
|
println!("cargo:rerun-if-env-changed=LOG");
|
|
|
|
|
|
|
|
|
|
let arch: String = std::env::var("ARCH").unwrap();
|
|
|
|
|
match arch.as_str() {
|
|
|
|
|
"x86_64" => {
|
|
|
|
|
// cc::Build::new()
|
|
|
|
|
// .file("src/arch/x86_64/driver/apic/lapic.c")
|
|
|
|
|
// .file("src/arch/x86_64/driver/keyboard/keyboard.c")
|
|
|
|
|
// .flag("-mcmodel=large")
|
|
|
|
|
// .compile("cobj");
|
|
|
|
|
gen_vector_asm().unwrap();
|
|
|
|
|
}
|
|
|
|
|
if std::env::var("TARGET").unwrap().find("riscv32").is_some() {
|
|
|
|
|
"riscv32" => {
|
|
|
|
|
cc::Build::new()
|
|
|
|
|
.file("src/arch/riscv32/compiler_rt.c")
|
|
|
|
|
.flag("-march=rv32ia")
|
|
|
|
|
.flag("-mabi=ilp32")
|
|
|
|
|
.compile("atomic_rt");
|
|
|
|
|
if let Ok(file_path) = gen_sfsimg_asm() {
|
|
|
|
|
cc::Build::new()
|
|
|
|
|
.file(&file_path)
|
|
|
|
|
.flag("-march=rv32ia")
|
|
|
|
|
.flag("-mabi=ilp32")
|
|
|
|
|
.compile("sfsimg");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
"aarch64" => {
|
|
|
|
|
if let Ok(file_path) = gen_sfsimg_asm() {
|
|
|
|
|
cc::Build::new().file(&file_path).compile("cobj");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => panic!("Unknown arch {}", arch),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -44,3 +63,27 @@ fn gen_vector_asm() -> Result<()> {
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn gen_sfsimg_asm() -> Result<std::path::PathBuf> {
|
|
|
|
|
let out_dir = std::env::var("OUT_DIR").unwrap();
|
|
|
|
|
let sfsimg = std::env::var("SFSIMG").unwrap();
|
|
|
|
|
|
|
|
|
|
let file_path = Path::new(&out_dir).join("sfsimg.S");
|
|
|
|
|
let mut f = File::create(&file_path).unwrap();
|
|
|
|
|
|
|
|
|
|
write!(f, "# generated by build.rs - do not edit")?;
|
|
|
|
|
write!(f, r#"
|
|
|
|
|
.section .rodata
|
|
|
|
|
.align 12
|
|
|
|
|
.global _user_img_start
|
|
|
|
|
.global _user_img_end
|
|
|
|
|
_user_img_start:
|
|
|
|
|
.incbin "{}"
|
|
|
|
|
_user_img_end:
|
|
|
|
|
"#, sfsimg)?;
|
|
|
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed={}", sfsimg);
|
|
|
|
|
println!("cargo:rerun-if-env-changed=SFSIMG");
|
|
|
|
|
|
|
|
|
|
Ok(file_path)
|
|
|
|
|
}
|
|
|
|
|