xref: /DragonOS/build-scripts/kernel_build/src/cfiles/arch/riscv64.rs (revision c635d8a9cfe25bc11779f323ef0c7d7a0f597d4a)
1 use std::path::PathBuf;
2 
3 use crate::{constant::ARCH_DIR_RISCV64, utils::FileUtils};
4 
5 use super::CFilesArch;
6 
7 pub(super) struct RiscV64CFilesArch;
8 
9 impl CFilesArch for RiscV64CFilesArch {
10     fn setup_defines(&self, c: &mut cc::Build) {
11         c.define("__riscv64__", None);
12         c.define("__riscv", None);
13     }
14 
15     fn setup_global_include_dir(&self, c: &mut cc::Build) {
16         c.include("src/arch/riscv64/include");
17     }
18 
19     fn setup_files(&self, _c: &mut cc::Build, files: &mut Vec<std::path::PathBuf>) {
20         files.push(PathBuf::from("src/arch/riscv64/asm/head.S"));
21         files.append(&mut FileUtils::list_all_files(
22             &arch_path("asm"),
23             Some("c"),
24             true,
25         ));
26     }
27 
28     fn setup_global_flags(&self, c: &mut cc::Build) {
29         // 在这里设置编译器,不然的话vscode的rust-analyzer会报错
30         c.compiler("riscv64-unknown-elf-gcc");
31         // // c.flag("-march=rv64imafdc");
32         // c.no_default_flags(true);
33         c.flag("-mcmodel=medany");
34 
35         c.flag("-mabi=lp64d");
36         c.flag("-march=rv64gc");
37     }
38 }
39 
40 fn arch_path(relative_path: &str) -> PathBuf {
41     PathBuf::from(format!("{}/{}", ARCH_DIR_RISCV64, relative_path))
42 }
43