使用cargo管理一些C文件的编译,并且移动部分汇编到arch目录 (#447)

* 使用cargo管理main.c的编译

* 使用build-scripts编译架构相关的c代码

* 删除elf.h
This commit is contained in:
LoGin
2023-11-17 21:25:15 +08:00
committed by GitHub
parent e4600f7f7d
commit 46e234aef6
36 changed files with 556 additions and 1683 deletions

View File

@ -26,21 +26,16 @@ export ASFLAGS := --64
LD_LIST := ""
kernel_subdirs := common driver debug arch exception smp syscall ktest libs time
kernel_subdirs := common driver debug exception smp syscall ktest libs time
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 AMDs x86-64 architecture.
$(CC) $(CFLAGS) -c main.c -o main.o
kernel_rust:
RUSTFLAGS="$(RUSTFLAGS_UNWIND)" cargo +nightly-2023-01-21 build --release --target ./arch/x86_64/x86_64-unknown-none.json
all: kernel
@echo "Linking kernel..."
$(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
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds --no-relax
# 生成kallsyms
current_dir=$(pwd)
@ -54,7 +49,7 @@ all: kernel
# 重新链接
@echo "Re-Linking kernel..."
@echo $(shell find . -name "*.o")
$(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
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel $(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)
@ -71,7 +66,7 @@ $(kernel_subdirs): ECHO
$(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" kernel_root_path="$(shell pwd)"
kernel: main.o $(kernel_subdirs) kernel_rust
kernel: $(kernel_subdirs) kernel_rust