xref: /DragonOS/build-scripts/kernel_build/src/cfiles/arch/x86_64.rs (revision 83ed0ebc293d5a10245089f627f52770fd5b9dd4)
1 use std::path::PathBuf;
2 
3 use cc::Build;
4 
5 use crate::{constant::ARCH_DIR_X86_64, utils::FileUtils};
6 
7 use super::CFilesArch;
8 
9 pub(super) struct X86_64CFilesArch;
10 
11 impl CFilesArch for X86_64CFilesArch {
12     fn setup_defines(&self, c: &mut cc::Build) {
13         c.define("__x86_64__", None);
14     }
15 
16     fn setup_global_include_dir(&self, c: &mut cc::Build) {
17         c.include("src/arch/x86_64/include");
18     }
19 
20     fn setup_files(&self, _c: &mut Build, files: &mut Vec<PathBuf>) {
21         files.push(arch_path("driver/hpet.c"));
22         // 获取`kernel/src/arch/x86_64/driver/apic`下的所有C文件
23         files.append(&mut FileUtils::list_all_files(
24             &arch_path("driver/apic"),
25             Some("c"),
26             true,
27         ));
28 
29         files.append(&mut FileUtils::list_all_files(
30             &arch_path("init"),
31             Some("c"),
32             true,
33         ));
34         files.append(&mut FileUtils::list_all_files(
35             &arch_path("asm"),
36             Some("c"),
37             true,
38         ));
39         files.append(&mut FileUtils::list_all_files(
40             &arch_path("interrupt"),
41             Some("c"),
42             true,
43         ));
44 
45         // setup asm files
46         files.push(PathBuf::from("src/arch/x86_64/asm/head.S"));
47         files.push(PathBuf::from("src/arch/x86_64/asm/entry.S"));
48         files.push(PathBuf::from("src/arch/x86_64/asm/apu_boot.S"));
49     }
50 
51     fn setup_global_flags(&self, c: &mut Build) {
52         c.asm_flag("-m64");
53         c.flag("-mcmodel=large").flag("-m64");
54     }
55 }
56 
57 fn arch_path(relative_path: &str) -> PathBuf {
58     PathBuf::from(format!("{}/{}", ARCH_DIR_X86_64, relative_path))
59 }
60