xref: /DragonOS/build-scripts/kernel_build/src/cfiles/arch/x86_64.rs (revision 415e46ea470ba1dd33e4368c3684c700a75f3be8)
1*415e46eaSLoGin use std::{collections::HashSet, path::PathBuf};
2e26ca418SLoGin 
3e26ca418SLoGin use cc::Build;
4e26ca418SLoGin 
546e234aeSLoGin use crate::{constant::ARCH_DIR_X86_64, utils::FileUtils};
6e26ca418SLoGin 
7e26ca418SLoGin use super::CFilesArch;
8e26ca418SLoGin 
9e26ca418SLoGin pub(super) struct X86_64CFilesArch;
10e26ca418SLoGin 
11e26ca418SLoGin impl CFilesArch for X86_64CFilesArch {
setup_defines(&self, c: &mut cc::Build)12e26ca418SLoGin     fn setup_defines(&self, c: &mut cc::Build) {
13e26ca418SLoGin         c.define("__x86_64__", None);
14e26ca418SLoGin     }
15e26ca418SLoGin 
setup_global_include_dir(&self, include_dirs: &mut HashSet<PathBuf>)16*415e46eaSLoGin     fn setup_global_include_dir(&self, include_dirs: &mut HashSet<PathBuf>) {
17*415e46eaSLoGin         include_dirs.insert("src/arch/x86_64/include".into());
18e26ca418SLoGin     }
19e26ca418SLoGin 
setup_files(&self, _c: &mut Build, files: &mut HashSet<PathBuf>)20*415e46eaSLoGin     fn setup_files(&self, _c: &mut Build, files: &mut HashSet<PathBuf>) {
21*415e46eaSLoGin         const DIRS: [&str; 4] = ["driver/apic", "init", "asm", "interrupt"];
22*415e46eaSLoGin         DIRS.iter().for_each(|dir| {
23*415e46eaSLoGin             FileUtils::list_all_files(&arch_path(dir), Some("c"), true)
24*415e46eaSLoGin                 .into_iter()
25*415e46eaSLoGin                 .for_each(|f| {
26*415e46eaSLoGin                     files.insert(f);
27*415e46eaSLoGin                 });
28*415e46eaSLoGin         });
2911f78b73SLoGin 
3011f78b73SLoGin         // setup asm files
31*415e46eaSLoGin         files.insert(PathBuf::from("src/arch/x86_64/asm/head.S"));
32*415e46eaSLoGin         files.insert(PathBuf::from("src/arch/x86_64/asm/entry.S"));
33*415e46eaSLoGin         files.insert(PathBuf::from("src/arch/x86_64/asm/apu_boot.S"));
3411f78b73SLoGin     }
3511f78b73SLoGin 
setup_global_flags(&self, c: &mut Build)3611f78b73SLoGin     fn setup_global_flags(&self, c: &mut Build) {
3711f78b73SLoGin         c.asm_flag("-m64");
384fda81ceSLoGin         c.flag("-mcmodel=large").flag("-m64");
39e26ca418SLoGin     }
40e26ca418SLoGin }
4146e234aeSLoGin 
arch_path(relative_path: &str) -> PathBuf4246e234aeSLoGin fn arch_path(relative_path: &str) -> PathBuf {
4346e234aeSLoGin     PathBuf::from(format!("{}/{}", ARCH_DIR_X86_64, relative_path))
4446e234aeSLoGin }
45