Organizing the kernel code.

This commit is contained in:
Nicolás Ortega Froysa 2018-02-23 18:50:05 +01:00
parent 7a2618dd4d
commit 78c1155430
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF
9 changed files with 11 additions and 16 deletions

View File

@ -1,38 +1,33 @@
ASM=nasm ASM=nasm
AFLAGS=-f bin
BIN=bin BIN=bin
CFLAGS=-ffreestanding -fno-pie -m32 CFLAGS=-ffreestanding -fno-pie -m32
CC=gcc CC=gcc
LD=ld LD=ld
LDFLAGS=-melf_i386 -Ttext 0x1000 --oformat binary LDFLAGS=-melf_i386 -Ttext 0x1000 --oformat binary
OBJ=kernel/kernel_entry.o kernel/kernel.o
all: os-image all: os-image
os-image: boot_sect.bin kernel.bin os-image: boot/boot_sect.bin kernel.bin
mkdir -p $(BIN) mkdir -p $(BIN)
cat $^ > $(BIN)/$@ cat $^ > $(BIN)/$@
# build kernel binary file # build kernel binary file
kernel.bin: kernel_entry.o kernel.o kernel.bin: $(OBJ)
$(LD) $(LDFLAGS) $^ -o $@ $(LD) $(LDFLAGS) $^ -o $@
# build kernel object file %.o: %.c ${HEADERS}
kernel.o: kernel.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
# build kernel entry object file %.o: %.asm
kernel_entry.o: kernel_entry.asm $(ASM) $< -f elf -o $@
$(ASM) -f elf $< -o $@
boot_sect.bin: boot_sect.asm
$(ASM) $< $(AFLAGS) -o $@
basicos: boot_sect.bin kernel.bin
mkdir -p $(BIN)
cat boot_sect.bin kernel.bin > $(BIN)/os-image
%.bin: %.asm
$(ASM) $< -f bin -I 'boot/' -o $@
.PHONY: clean .PHONY: clean
clean: clean:
rm -f *.bin *.o rm -rf boot/*.bin boot/*.o
rm -rf kernel/*.o boot/*.o drivers/*.o