forked from PoliEcho-holding-org/kern
Implemented a proper libc
This commit is contained in:
@@ -3,8 +3,8 @@ CC := i686-elf-gcc
|
||||
LD := i686-elf-ld
|
||||
AS := nasm
|
||||
|
||||
CFLAGS := -g -std=c17 -ffreestanding -fno-builtin -fno-stack-protector -fno-pie \
|
||||
-Os -nostdinc -mgeneral-regs-only -m32 -march=i386 -Wall -Iinclude/c
|
||||
CCFLAGS := -g -std=c17 -ffreestanding -fno-builtin -fno-stack-protector -fno-pie \
|
||||
-Os -nostdinc -mgeneral-regs-only -m32 -march=i386 -Wall
|
||||
LDFLAGS := -z notext -melf_i386 -nostdlib
|
||||
ASFLAGS :=
|
||||
|
||||
@@ -12,61 +12,78 @@ include make.config
|
||||
|
||||
SRC := ./src
|
||||
BIN := ./bin
|
||||
LIBK_INC := ./include
|
||||
LIBC_INC := ./include/libc
|
||||
LIBC_DIR := ./libc
|
||||
LIBK_DIR := ./libk
|
||||
|
||||
C_FILES := calc edit
|
||||
FONTS := testfont term16n
|
||||
|
||||
BOOTLOADER := $(BIN)/stage1.bin $(BIN)/stage2.bin $(BIN)/stage3.bin
|
||||
KERNEL := $(BIN)/kernel.bin
|
||||
LIBC := $(BIN)/libc.o
|
||||
# TODO: LIBK := $(BIN)/libk.o
|
||||
ISO := kern.iso
|
||||
|
||||
.PHONY: os clean run
|
||||
|
||||
# Main compilation target
|
||||
os: $(BIN) bootloader kernel $(C_FILES) $(FONTS)
|
||||
@cc ./makedisk.c -o ./makedisk
|
||||
@./makedisk # TODO: List of files
|
||||
os: $(ISO)
|
||||
$(ISO): $(BIN) $(BOOTLOADER) $(KERNEL) $(C_FILES) $(FONTS)
|
||||
cc ./makedisk.c -o ./makedisk
|
||||
./makedisk # TODO: List of files
|
||||
@echo "\nDone!\n"
|
||||
|
||||
$(BIN):
|
||||
@[ -d $(BIN) ] || mkdir $(BIN)
|
||||
@rm -rf $(BIN)/*
|
||||
[ -d $(BIN) ] || mkdir $(BIN)
|
||||
rm -rf $(BIN)/*
|
||||
|
||||
# Bootloader: This target is responsible for creating stage?.bin (1,2,3)
|
||||
bootloader: $(SRC)/stage1.asm $(SRC)/stage2.asm
|
||||
$(BOOTLOADER): $(SRC)/stage1.asm $(SRC)/stage2.asm $(SRC)/stage3.c $(LIBC)
|
||||
@echo "Assembling $(SRC)/stage1.asm..."
|
||||
@$(AS) -fbin -o $(BIN)/stage1.bin $(SRC)/stage1.asm $(ASFLAGS)
|
||||
$(AS) -fbin -o $(BIN)/stage1.bin $(SRC)/stage1.asm $(ASFLAGS)
|
||||
@echo "Assembling $(SRC)/stage2.asm..."
|
||||
@$(AS) -fbin -o $(BIN)/stage2.bin $(SRC)/stage2.asm $(ASFLAGS)
|
||||
$(AS) -fbin -o $(BIN)/stage2.bin $(SRC)/stage2.asm $(ASFLAGS)
|
||||
@echo "Compiling $(SRC)/stage3.c..."
|
||||
@$(CC) $(CFLAGS) -Iinclude -o $(BIN)/stage3.o -c $(SRC)/stage3.c
|
||||
@$(LD) $(LDFLAGS) -T$(SRC)/stage3.ld --oformat binary -o $(BIN)/stage3.bin $(BIN)/stage3.o
|
||||
@rm $(BIN)/stage3.o
|
||||
$(CC) $(CCFLAGS) -I$(LIBK_INC) -I$(LIBC_INC) -o $(BIN)/stage3.o -c $(SRC)/stage3.c
|
||||
$(LD) $(LDFLAGS) -T$(SRC)/stage3.ld --oformat binary -o $(BIN)/stage3.bin $(BIN)/stage3.o $(LIBC)
|
||||
rm $(BIN)/stage3.o
|
||||
|
||||
# Kernel: This target is responsible for creating kernel.bin
|
||||
kernel: $(SRC)/kernel.c
|
||||
$(KERNEL): $(SRC)/kernel.c $(LIBC) #TODO: $(LIBK)
|
||||
@echo "Compiling $(SRC)/kernel.c..."
|
||||
@$(CC) $(CFLAGS) -Iinclude -o $(BIN)/kernel.o -c $(SRC)/kernel.c
|
||||
@$(LD) $(LDFLAGS) -T$(SRC)/kernel.ld --oformat binary -o $(BIN)/kernel.bin $(BIN)/kernel.o
|
||||
@rm $(BIN)/kernel.o
|
||||
$(CC) $(CCFLAGS) -I$(LIBK_INC) -I$(LIBC_INC) -o $(BIN)/kernel.o -c $(SRC)/kernel.c
|
||||
$(LD) $(LDFLAGS) -T$(SRC)/kernel.ld --oformat binary -o $(BIN)/kernel.bin $(BIN)/kernel.o $(LIBC) #TODO: LIBK
|
||||
rm $(BIN)/kernel.o
|
||||
|
||||
# This target compiles *.c (except kernel.c)
|
||||
$(C_FILES):
|
||||
$(C_FILES): $(LIBC)
|
||||
@echo "Compiling $(SRC)/$@.c..."
|
||||
@$(CC) $(CFLAGS) -o $(BIN)/$@.o -c $(SRC)/$@.c
|
||||
@$(LD) $(LDFLAGS) -T$(SRC)/$@.ld --oformat binary -o $(BIN)/$@.bin $(BIN)/$@.o
|
||||
@rm $(BIN)/$@.o
|
||||
$(CC) $(CCFLAGS) -I$(LIBC_INC) -o $(BIN)/$@.o -c $(SRC)/$@.c
|
||||
$(LD) $(LDFLAGS) -T$(SRC)/$@.ld --oformat binary -o $(BIN)/$@.bin $(BIN)/$@.o $(LIBC)
|
||||
rm $(BIN)/$@.o
|
||||
|
||||
# This target builds all fonts inside src/fonts
|
||||
$(LIBC): $(LIBC_DIR)/**.c
|
||||
@echo "Compiling $(LIBC)..."
|
||||
mkdir -p $(BIN)/libc
|
||||
for f in libc/*.c; do $(CC) $(CCFLAGS) -I$(LIBC_INC) -o $(BIN)/$$f.o -c $$f; done
|
||||
$(LD) $(LDFLAGS) -r -o $(LIBC) $(BIN)/libc/**.o
|
||||
|
||||
# This target retrieves all fonts inside src/fonts
|
||||
$(FONTS):
|
||||
@cp $(SRC)/fonts/$@.fnt $(BIN)/$@.fnt
|
||||
cp $(SRC)/fonts/$@.fnt $(BIN)/$@.fnt
|
||||
|
||||
# Run QEMU
|
||||
run:
|
||||
qemu-system-x86_64\
|
||||
-drive format=raw,file="./kern.iso",index=0,media=disk\
|
||||
-drive format=raw,file=$(ISO),index=0,media=disk\
|
||||
-m 256M -accel tcg -monitor stdio\
|
||||
-rtc base=localtime,clock=host,driftfix=slew\
|
||||
-audiodev coreaudio,id=audio0 -machine pcspk-audiodev=audio0
|
||||
|
||||
# Clean all build files
|
||||
clean:
|
||||
@rm -rf $(BIN)
|
||||
@#rm -f kern.iso
|
||||
@rm -f makedisk
|
||||
rm -rf $(BIN)
|
||||
rm -f makedisk
|
||||
|
||||
|
||||
Reference in New Issue
Block a user