xref: /DragonOS/build-scripts/kernel_build/src/cfiles/arch/x86_64.rs (revision da152319797436368304cbc3f85a3b9ec049134b)
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         // 获取`kernel/src/arch/x86_64/driver/apic`下的所有C文件
22         files.append(&mut FileUtils::list_all_files(
23             &arch_path("driver/apic"),
24             Some("c"),
25             true,
26         ));
27 
28         files.append(&mut FileUtils::list_all_files(
29             &arch_path("init"),
30             Some("c"),
31             true,
32         ));
33         files.append(&mut FileUtils::list_all_files(
34             &arch_path("asm"),
35             Some("c"),
36             true,
37         ));
38         files.append(&mut FileUtils::list_all_files(
39             &arch_path("interrupt"),
40             Some("c"),
41             true,
42         ));
43 
44         // setup asm files
45         files.push(PathBuf::from("src/arch/x86_64/asm/head.S"));
46         files.push(PathBuf::from("src/arch/x86_64/asm/entry.S"));
47         files.push(PathBuf::from("src/arch/x86_64/asm/apu_boot.S"));
48     }
49 
50     fn setup_global_flags(&self, c: &mut Build) {
51         c.asm_flag("-m64");
52         c.flag("-mcmodel=large").flag("-m64");
53     }
54 }
55 
56 fn arch_path(relative_path: &str) -> PathBuf {
57     PathBuf::from(format!("{}/{}", ARCH_DIR_X86_64, relative_path))
58 }
59