2022-01-23 15:17:52 +00:00
|
|
|
|
SUBDIR_ROOTS := . common
|
|
|
|
|
|
DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
|
2022-05-06 03:44:53 +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-02-22 13:45:51 +00:00
|
|
|
|
|
2022-04-15 07:28:00 +00:00
|
|
|
|
|
2022-03-04 05:40:22 +00:00
|
|
|
|
# 控制操作系统使用的中断控制器 _INTR_8259A_ _INTR_APIC_
|
|
|
|
|
|
PIC := _INTR_APIC_
|
2022-05-05 16:25:32 +00:00
|
|
|
|
CFLAGS = $(GLOBAL_CFLAGS) -D $(PIC) -I .
|
2022-03-04 05:40:22 +00:00
|
|
|
|
|
2022-02-22 13:45:51 +00:00
|
|
|
|
ASFLAGS := --64
|
|
|
|
|
|
|
2022-04-07 12:21:28 +00:00
|
|
|
|
LD_LIST := head.o
|
|
|
|
|
|
OBJ_LIST := head.o
|
|
|
|
|
|
|
2022-01-21 05:49:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
head.o: head.S
|
|
|
|
|
|
gcc -E head.S > head.s # 预处理
|
2022-02-22 13:45:51 +00:00
|
|
|
|
as $(ASFLAGS) -o head.o head.s
|
2022-02-21 14:59:57 +00:00
|
|
|
|
#gcc -mcmodel=large -fno-builtin -m64 -c head.S -o head.o
|
2022-01-21 05:49:09 +00:00
|
|
|
|
|
2022-01-25 10:04:18 +00:00
|
|
|
|
entry.o: exception/entry.S
|
|
|
|
|
|
gcc -E exception/entry.S > exception/entry.s
|
2022-02-22 13:45:51 +00:00
|
|
|
|
as $(ASFLAGS) -o exception/entry.o exception/entry.s
|
2022-01-25 10:04:18 +00:00
|
|
|
|
|
2022-04-25 16:25:15 +00:00
|
|
|
|
procs.o: process/proc.S
|
|
|
|
|
|
gcc -E process/proc.S > process/proc.s
|
|
|
|
|
|
as $(ASFLAGS) -o process/procs.o process/proc.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-02-22 13:45:51 +00:00
|
|
|
|
gcc $(CFLAGS) -c main.c -o main.o
|
2022-01-23 15:17:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printk.o: common/printk.c
|
2022-02-22 13:45:51 +00:00
|
|
|
|
gcc $(CFLAGS) -c common/printk.c -o common/printk.o
|
2022-01-25 10:04:18 +00:00
|
|
|
|
|
|
|
|
|
|
trap.o: exception/trap.c
|
2022-02-22 13:45:51 +00:00
|
|
|
|
gcc $(CFLAGS) -c exception/trap.c -o exception/trap.o
|
2022-01-27 06:58:14 +00:00
|
|
|
|
|
2022-01-29 04:52:25 +00:00
|
|
|
|
irq.o: exception/irq.c
|
2022-02-22 13:45:51 +00:00
|
|
|
|
gcc $(CFLAGS) -c exception/irq.c -o exception/irq.o
|
2022-01-29 04:52:25 +00:00
|
|
|
|
|
2022-02-23 04:18:18 +00:00
|
|
|
|
|
2022-01-29 04:52:25 +00:00
|
|
|
|
|
2022-01-27 06:58:14 +00:00
|
|
|
|
mm.o: mm/mm.c
|
2022-02-22 13:45:51 +00:00
|
|
|
|
gcc $(CFLAGS) -c mm/mm.c -o mm/mm.o
|
2022-01-23 15:17:52 +00:00
|
|
|
|
|
2022-02-28 08:15:44 +00:00
|
|
|
|
slab.o: mm/slab.c
|
|
|
|
|
|
gcc $(CFLAGS) -c mm/slab.c -o mm/slab.o
|
|
|
|
|
|
|
2022-02-10 05:45:38 +00:00
|
|
|
|
process.o: process/process.c
|
2022-02-22 13:45:51 +00:00
|
|
|
|
gcc $(CFLAGS) -c process/process.c -o process/process.o
|
2022-04-09 13:11:07 +00:00
|
|
|
|
|
|
|
|
|
|
sched.o: sched/sched.c
|
|
|
|
|
|
gcc $(CFLAGS) -c sched/sched.c -o sched/sched.o
|
|
|
|
|
|
|
2022-02-16 06:07:53 +00:00
|
|
|
|
syscall.o: syscall/syscall.c
|
2022-02-22 13:45:51 +00:00
|
|
|
|
gcc $(CFLAGS) -c syscall/syscall.c -o syscall/syscall.o
|
2022-02-10 05:45:38 +00:00
|
|
|
|
|
2022-04-04 10:42:22 +00:00
|
|
|
|
smp.o: smp/smp.c
|
|
|
|
|
|
gcc $(CFLAGS) -c smp/smp.c -o smp/smp.o
|
2022-02-21 06:39:48 +00:00
|
|
|
|
|
2022-04-04 14:30:06 +00:00
|
|
|
|
apu_boot.o: smp/apu_boot.S
|
|
|
|
|
|
gcc -E smp/apu_boot.S > smp/apu_boot.s # 预处理
|
|
|
|
|
|
as $(ASFLAGS) -o smp/apu_boot.o smp/apu_boot.s
|
|
|
|
|
|
|
2022-02-22 15:31:33 +00:00
|
|
|
|
cpu.o: common/cpu.c
|
|
|
|
|
|
gcc $(CFLAGS) -c common/cpu.c -o common/cpu.o
|
|
|
|
|
|
|
2022-04-08 12:04:12 +00:00
|
|
|
|
softirq.o: exception/softirq.c
|
|
|
|
|
|
gcc $(CFLAGS) -c exception/softirq.c -o exception/softirq.o
|
|
|
|
|
|
|
2022-04-19 12:56:01 +00:00
|
|
|
|
fat32.o: filesystem/fat32/fat32.c
|
|
|
|
|
|
gcc $(CFLAGS) -c filesystem/fat32/fat32.c -o filesystem/fat32/fat32.o
|
|
|
|
|
|
|
2022-04-20 11:55:36 +00:00
|
|
|
|
MBR.o: filesystem/MBR.c
|
|
|
|
|
|
gcc $(CFLAGS) -c filesystem/MBR.c -o filesystem/MBR.o
|
|
|
|
|
|
|
2022-04-21 15:48:47 +00:00
|
|
|
|
VFS.o: filesystem/VFS/VFS.c
|
|
|
|
|
|
gcc $(CFLAGS) -c filesystem/VFS/VFS.c -o filesystem/VFS/VFS.o
|
|
|
|
|
|
|
2022-04-07 12:21:28 +00:00
|
|
|
|
# IPI的代码
|
|
|
|
|
|
ifeq ($(ARCH), x86_64)
|
|
|
|
|
|
OBJ_LIST += ipi.o
|
|
|
|
|
|
LD_LIST += arch/x86_64/x86_64_ipi.o
|
|
|
|
|
|
ipi.o: arch/x86_64/x86_64_ipi.c
|
|
|
|
|
|
gcc $(CFLAGS) -c arch/x86_64/x86_64_ipi.c -o arch/x86_64/x86_64_ipi.o
|
|
|
|
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
2022-02-23 04:18:18 +00:00
|
|
|
|
# 驱动程序
|
2022-03-04 05:40:22 +00:00
|
|
|
|
# 中断处理芯片的驱动程序
|
2022-03-12 16:31:46 +00:00
|
|
|
|
ifeq ($(PIC), _INTR_8259A_)
|
2022-03-04 05:40:22 +00:00
|
|
|
|
pic.o: driver/interrupt/8259A/8259A.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/interrupt/8259A/8259A.c -o driver/interrupt/pic.o
|
2022-03-12 16:31:46 +00:00
|
|
|
|
else
|
2022-03-04 05:40:22 +00:00
|
|
|
|
pic.o: driver/interrupt/apic/apic.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/interrupt/apic/apic.c -o driver/interrupt/pic.o
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
multiboot2.o: driver/multiboot2/multiboot2.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/multiboot2/multiboot2.c -o driver/multiboot2/multiboot2.o
|
|
|
|
|
|
|
2022-03-12 16:31:46 +00:00
|
|
|
|
acpi.o: driver/acpi/acpi.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/acpi/acpi.c -o driver/acpi/acpi.o
|
|
|
|
|
|
|
2022-03-18 11:18:36 +00:00
|
|
|
|
ps2_keyboard.o: driver/keyboard/ps2_keyboard.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/keyboard/ps2_keyboard.c -o driver/keyboard/ps2_keyboard.o
|
2022-03-16 05:54:26 +00:00
|
|
|
|
|
2022-03-18 11:18:36 +00:00
|
|
|
|
ps2_mouse.o: driver/mouse/ps2_mouse.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/mouse/ps2_mouse.c -o driver/mouse/ps2_mouse.o
|
2022-03-17 12:51:14 +00:00
|
|
|
|
|
2022-03-21 09:13:15 +00:00
|
|
|
|
ata.o: driver/disk/ata.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/disk/ata.c -o driver/disk/ata.o
|
|
|
|
|
|
|
2022-03-22 10:02:37 +00:00
|
|
|
|
pci.o: driver/pci/pci.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/pci/pci.c -o driver/pci/pci.o
|
|
|
|
|
|
|
2022-03-30 07:36:00 +00:00
|
|
|
|
ahci.o: driver/disk/ahci/ahci.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/disk/ahci/ahci.c -o driver/disk/ahci/ahci.o
|
|
|
|
|
|
|
2022-04-07 16:10:02 +00:00
|
|
|
|
rtc.o: driver/timers/rtc/rtc.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/timers/rtc/rtc.c -o driver/timers/rtc/rtc.o
|
|
|
|
|
|
|
2022-04-08 04:20:53 +00:00
|
|
|
|
HPET.o: driver/timers/HPET/HPET.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/timers/HPET/HPET.c -o driver/timers/HPET/HPET.o
|
|
|
|
|
|
|
2022-04-08 12:04:12 +00:00
|
|
|
|
timer.o: driver/timers/timer.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/timers/timer.c -o driver/timers/timer.o
|
|
|
|
|
|
|
2022-04-15 07:23:17 +00:00
|
|
|
|
OBJ_LIST += uart.o
|
|
|
|
|
|
LD_LIST += driver/uart/uart.o
|
|
|
|
|
|
uart.o: driver/uart/uart.c
|
|
|
|
|
|
gcc $(CFLAGS) -c driver/uart/uart.c -o driver/uart/uart.o
|
|
|
|
|
|
|
2022-03-17 12:51:14 +00:00
|
|
|
|
|
2022-04-07 12:21:28 +00:00
|
|
|
|
|
|
|
|
|
|
all: kernel
|
|
|
|
|
|
objcopy -I elf64-x86-64 -O elf64-x86-64 -R ".comment" -R ".eh_frame" kernel ../bin/kernel/kernel.elf
|
|
|
|
|
|
#
|
|
|
|
|
|
|
2022-04-25 16:25:15 +00:00
|
|
|
|
kernel: head.o entry.o procs.o main.o printk.o trap.o mm.o slab.o irq.o pic.o process.o sched.o syscall.o multiboot2.o cpu.o acpi.o ps2_keyboard.o ps2_mouse.o ata.o pci.o ahci.o smp.o apu_boot.o rtc.o HPET.o softirq.o timer.o fat32.o MBR.o VFS.o $(OBJ_LIST)
|
|
|
|
|
|
ld -b elf64-x86-64 -z muldefs -o kernel head.o exception/entry.o process/procs.o main.o common/printk.o exception/trap.o exception/irq.o mm/mm.o mm/slab.o process/process.o syscall/syscall.o driver/multiboot2/multiboot2.o \
|
2022-04-21 15:48:47 +00:00
|
|
|
|
common/cpu.o smp/smp.o smp/apu_boot.o exception/softirq.o sched/sched.o filesystem/fat32/fat32.o filesystem/MBR.o filesystem/VFS/VFS.o \
|
2022-04-08 12:04:12 +00:00
|
|
|
|
driver/acpi/acpi.o driver/interrupt/pic.o driver/keyboard/ps2_keyboard.o driver/mouse/ps2_mouse.o driver/disk/ata.o driver/pci/pci.o driver/disk/ahci/ahci.o driver/timers/rtc/rtc.o driver/timers/HPET/HPET.o driver/timers/timer.o \
|
2022-04-07 12:21:28 +00:00
|
|
|
|
$(LD_LIST) \
|
|
|
|
|
|
-T link.lds
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-23 15:17:52 +00:00
|
|
|
|
clean:
|
|
|
|
|
|
rm -rf $(GARBAGE)
|