Explorar el Código

使用kernel-build脚本来编译所有的asm文件 (#445)

LoGin hace 1 año
padre
commit
11f78b73e7

+ 3 - 0
build-scripts/kernel_build/src/cfiles/arch/mod.rs

@@ -15,6 +15,9 @@ pub(super) trait CFilesArch {
     fn setup_global_include_dir(&self, c: &mut Build);
     /// 设置需要编译的架构相关的文件
     fn setup_files(&self, c: &mut Build, files: &mut Vec<PathBuf>);
+
+    /// 设置架构相关的全局编译标志
+    fn setup_global_flags(&self, c: &mut Build);
 }
 
 /// 获取当前的架构;

+ 9 - 0
build-scripts/kernel_build/src/cfiles/arch/x86_64.rs

@@ -25,5 +25,14 @@ impl CFilesArch for X86_64CFilesArch {
             Some("c"),
             true,
         ));
+
+        // setup asm files
+        files.push(PathBuf::from("src/arch/x86_64/asm/head.S"));
+        files.push(PathBuf::from("src/arch/x86_64/asm/entry.S"));
+        files.push(PathBuf::from("src/arch/x86_64/asm/apu_boot.S"));
+    }
+
+    fn setup_global_flags(&self, c: &mut Build) {
+        c.asm_flag("-m64");
     }
 }

+ 4 - 0
build-scripts/kernel_build/src/cfiles/mod.rs

@@ -14,6 +14,7 @@ pub struct CFilesBuilder;
 impl CFilesBuilder {
     pub fn build() {
         let mut c = cc::Build::new();
+
         Self::setup_global_flags(&mut c);
         Self::setup_defines(&mut c);
         Self::setup_global_include_dir(&mut c);
@@ -31,6 +32,9 @@ impl CFilesBuilder {
             .flag("-Wno-unused-parameter")
             .flag("-m64")
             .flag("-O1");
+
+        // set Arch-specific flags
+        current_cfiles_arch().setup_global_flags(c);
     }
 
     fn setup_defines(c: &mut Build) {

+ 4 - 9
kernel/src/Makefile

@@ -23,17 +23,12 @@ CFLAGS = $(GLOBAL_CFLAGS) -fno-pie $(CFLAGS_UNWIND) -I $(shell pwd) -I $(shell p
 
 export ASFLAGS := --64
 
-LD_LIST := head.o
+LD_LIST := ""
 
 
 kernel_subdirs := common driver debug arch exception smp syscall ktest libs time
 
 
-head.o: head.S
-	$(CC) -E head.S > _head.s # 预处理
-	$(AS) $(ASFLAGS) -o head.o _head.s
-
-
 main.o: main.c 
 # -fno-builtin: 不使用C语言内建函数
 # The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture.
@@ -45,7 +40,7 @@ kernel_rust:
 all: kernel
 
 	@echo "Linking kernel..."
-	$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds --no-relax
+	$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds --no-relax
 # 生成kallsyms
 	current_dir=$(pwd)
 	
@@ -59,7 +54,7 @@ all: kernel
 # 重新链接
 	@echo "Re-Linking kernel..."
 	@echo $(shell find . -name "*.o")
-	$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o  -T link.lds --no-relax
+	$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o  -T link.lds --no-relax
 	@echo "Generating kernel ELF file..."
 # 生成内核文件
 ifeq ($(UNWIND_ENABLE), yes)
@@ -76,7 +71,7 @@ $(kernel_subdirs): ECHO
 
 	$(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)"  kernel_root_path="$(shell pwd)"
 
-kernel: head.o main.o $(kernel_subdirs) kernel_rust
+kernel: main.o $(kernel_subdirs) kernel_rust
 	
 
 

+ 0 - 0
kernel/src/smp/apu_boot.S → kernel/src/arch/x86_64/asm/apu_boot.S


+ 1 - 1
kernel/src/exception/entry.S → kernel/src/arch/x86_64/asm/entry.S

@@ -1,4 +1,4 @@
-#include"../common/asm.h"
+#include <common/asm.h>
 .code64
 //.section .text
 

+ 0 - 0
kernel/src/head.S → kernel/src/arch/x86_64/asm/head.S


+ 1 - 5
kernel/src/exception/Makefile

@@ -2,11 +2,7 @@
 CFLAGS += -I .
 
 
-all: entry.o irq.o trap.o
-
-entry.o: entry.S
-	$(CC) -E entry.S > _entry.s
-	$(AS) $(ASFLAGS) -o entry.o _entry.s
+all: irq.o trap.o
 
 trap.o: trap.c
 	$(CC) $(CFLAGS) -c trap.c -o trap.o

+ 3 - 3
kernel/src/link.lds

@@ -13,9 +13,9 @@ SECTIONS
 	.boot.text :
 	{
 		KEEP(*(.multiboot_header))
-		head.o(.bootstrap)
-		head.o(.bootstrap.code64)
-		head.o(.bootstrap.data)
+		*(.bootstrap)
+		*(.bootstrap.code64)
+		*(.bootstrap.data)
 		. = ALIGN(4096);
 	}
 	

+ 1 - 6
kernel/src/smp/Makefile

@@ -2,12 +2,7 @@
 CFLAGS += -I .
 
 
-all: apu_boot.o smp.o
-
-
-apu_boot.o: apu_boot.S
-	$(CC) -E apu_boot.S > _apu_boot.s # 预处理
-	$(AS) $(ASFLAGS) -o apu_boot.o _apu_boot.s
+all: smp.o
 
 smp.o: smp.c
 	$(CC) $(CFLAGS) -c smp.c -o smp.o