1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 16:36:18 +04:00
rCore/kernel/build.rs

95 lines
2.2 KiB
Rust
Raw Normal View History

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::path::Path;
use std::io::{Result, Write};
2018-05-20 19:56:41 +04:00
2018-04-11 17:27:11 +04:00
fn main() {
2018-11-28 21:22:44 +04:00
println!("cargo:rerun-if-env-changed=LOG");
2019-02-15 13:00:34 +04:00
println!("cargo:rerun-if-env-changed=BOARD");
2018-11-28 21:22:44 +04:00
let arch: String = std::env::var("ARCH").unwrap();
2019-02-15 13:00:34 +04:00
let board: String = std::env::var("BOARD").unwrap();
2018-11-28 21:22:44 +04:00
match arch.as_str() {
"x86_64" => {
gen_vector_asm().unwrap();
}
"riscv32" => {
if let Ok(file_path) = gen_sfsimg_asm() {
cc::Build::new()
.file(&file_path)
2018-12-31 21:40:34 +04:00
.flag("-march=rv32imac")
2018-11-28 21:22:44 +04:00
.flag("-mabi=ilp32")
.compile("sfsimg");
}
}
"riscv64" => {
if let Ok(file_path) = gen_sfsimg_asm() {
cc::Build::new()
.file(&file_path)
.flag("-march=rv64imac")
.flag("-mabi=lp64")
.compile("sfsimg");
}
2019-02-15 13:00:34 +04:00
if board == "k210" {
println!("cargo:rustc-link-search=native={}", "../tools/k210");
println!("cargo:rustc-link-lib=static=kendryte");
}
}
2018-11-28 21:22:44 +04:00
"aarch64" => {
if let Ok(file_path) = gen_sfsimg_asm() {
2018-12-02 15:44:05 +04:00
cc::Build::new().file(&file_path).compile("sfsimg");
2018-11-28 21:22:44 +04:00
}
}
_ => panic!("Unknown arch {}", arch),
2018-10-17 15:37:53 +04:00
}
2018-05-20 19:56:41 +04:00
}
fn gen_vector_asm() -> Result<()> {
2018-08-05 13:50:56 +04:00
let mut f = File::create("src/arch/x86_64/interrupt/vector.asm").unwrap();
2018-05-20 19:56:41 +04:00
writeln!(f, "# generated by build.rs - do not edit")?;
2018-08-05 13:50:56 +04:00
writeln!(f, ".section .text")?;
writeln!(f, ".intel_syntax noprefix")?;
2018-05-20 19:56:41 +04:00
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-08-05 13:50:56 +04:00
writeln!(f, "\n.section .rodata")?;
writeln!(f, ".global __vectors")?;
2018-05-20 19:56:41 +04:00
writeln!(f, "__vectors:")?;
for i in 0..256 {
2018-08-05 13:50:56 +04:00
writeln!(f, "\t.quad vector{}", i)?;
2018-05-20 19:56:41 +04:00
}
Ok(())
2018-11-28 21:22:44 +04:00
}
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)
}