2022-01-23 15:17:52 +00:00
|
|
|
|
SUBDIR_ROOTS := . common
|
|
|
|
|
|
DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
|
2022-01-27 06:58:14 +00:00
|
|
|
|
GARBAGE_PATTERNS := *.o *.s~ *.s *.S~ *.c~ *.h~ kernel
|
2022-01-23 15:17:52 +00:00
|
|
|
|
GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS)))
|
2022-01-21 05:49:09 +00:00
|
|
|
|
|
2022-01-27 06:58:14 +00:00
|
|
|
|
DIR_LIB=lib
|
|
|
|
|
|
lib_patterns := *.a
|
|
|
|
|
|
LIB_FILES := $(foreach DIR,$(DIR_LIB),$(addprefix $(DIR)/,$(lib_patterns)))
|
2022-01-21 05:49:09 +00:00
|
|
|
|
all: kernel
|
|
|
|
|
|
objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary kernel ../bin/kernel/kernel.bin
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-29 04:52:25 +00:00
|
|
|
|
kernel: head.o entry.o main.o printk.o trap.o mm.o irq.o 8259A.o
|
|
|
|
|
|
ld -b elf64-x86-64 -z muldefs -o kernel head.o exception/entry.o main.o common/printk.o exception/trap.o exception/irq.o exception/8259A.o mm/mm.o -T link.lds
|
2022-01-21 05:49:09 +00:00
|
|
|
|
|
|
|
|
|
|
head.o: head.S
|
|
|
|
|
|
gcc -E head.S > head.s # 预处理
|
|
|
|
|
|
as --64 -o head.o head.s
|
|
|
|
|
|
|
2022-01-25 10:04:18 +00:00
|
|
|
|
entry.o: exception/entry.S
|
|
|
|
|
|
gcc -E exception/entry.S > exception/entry.s
|
|
|
|
|
|
as --64 -o exception/entry.o exception/entry.s
|
|
|
|
|
|
|
2022-01-29 04:52:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2022-01-23 15:17:52 +00:00
|
|
|
|
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.
|
2022-01-27 06:58:14 +00:00
|
|
|
|
gcc -mcmodel=large -fno-builtin -m64 -c main.c -o main.o
|
2022-01-23 15:17:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printk.o: common/printk.c
|
2022-01-27 06:58:14 +00:00
|
|
|
|
gcc -mcmodel=large -fno-builtin -m64 -c common/printk.c -o common/printk.o
|
2022-01-25 10:04:18 +00:00
|
|
|
|
|
|
|
|
|
|
trap.o: exception/trap.c
|
2022-01-27 06:58:14 +00:00
|
|
|
|
gcc -mcmodel=large -fno-builtin -m64 -c exception/trap.c -o exception/trap.o
|
|
|
|
|
|
|
2022-01-29 04:52:25 +00:00
|
|
|
|
irq.o: exception/irq.c
|
|
|
|
|
|
gcc -mcmodel=large -fno-builtin -m64 -c exception/irq.c -o exception/irq.o
|
|
|
|
|
|
|
|
|
|
|
|
8259A.o: exception/8259A.c
|
|
|
|
|
|
gcc -mcmodel=large -fno-builtin -m64 -c exception/8259A.c -o exception/8259A.o
|
|
|
|
|
|
|
2022-01-27 06:58:14 +00:00
|
|
|
|
mm.o: mm/mm.c
|
|
|
|
|
|
gcc -mcmodel=large -fno-builtin -m64 -c mm/mm.c -o mm/mm.o
|
2022-01-23 15:17:52 +00:00
|
|
|
|
|
|
|
|
|
|
clean:
|
|
|
|
|
|
rm -rf $(GARBAGE)
|