Improve multiarch support

This commit is contained in:
Quinten Kock 2020-12-01 03:30:47 +01:00
parent 20e7a7486a
commit 2cc8a36c11
7 changed files with 24 additions and 12 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
kornos.img kornos.img
kernel/kernel kernel/kernel*
obj/ obj/
*.o *.o

View File

@ -1,12 +1,14 @@
COMPONENTS = kernel COMPONENTS = kernel
ARCH ?= x86_64
KERNEL_HDD = kornos.img KERNEL_HDD = kornos.img
.PHONY: clean all $(COMPONENTS) .PHONY: clean all $(COMPONENTS)
.DEFAULT_GOAL = $(KERNEL_HDD) .DEFAULT_GOAL = $(KERNEL_HDD)
$(COMPONENTS): $(COMPONENTS):
$(MAKE) -C $@ $(MAKE) -C $@ $@-$(ARCH)
disk: $(KERNEL_HDD) disk: $(KERNEL_HDD)
run: $(KERNEL_HDD) run: $(KERNEL_HDD)
@ -26,7 +28,7 @@ $(KERNEL_HDD): ext/limine/limine-install $(COMPONENTS)
parted -s $(KERNEL_HDD) mklabel msdos parted -s $(KERNEL_HDD) mklabel msdos
parted -s $(KERNEL_HDD) mkpart primary 1 100% parted -s $(KERNEL_HDD) mkpart primary 1 100%
echfs-utils -m -p0 $(KERNEL_HDD) quick-format 32768 > /dev/null # silence UUID echfs-utils -m -p0 $(KERNEL_HDD) quick-format 32768 > /dev/null # silence UUID
@for f in $(COMPONENTS); do echo "Installing $$f ($$(du -h $$f/$$f | cut -f1))"; echfs-utils -m -p0 $@ import $$f/$$f $$f; done @for f in $(COMPONENTS); do echo "Installing $$f ($$(du -h $$f/$$f | cut -f1))"; echfs-utils -m -p0 $@ import $$f/$$f-$(ARCH) $$f; done
echfs-utils -m -p0 $(KERNEL_HDD) import ext/limine.cfg limine.cfg echfs-utils -m -p0 $(KERNEL_HDD) import ext/limine.cfg limine.cfg
ext/limine/limine-install ext/limine/limine.bin $(KERNEL_HDD) ext/limine/limine-install ext/limine/limine.bin $(KERNEL_HDD)

View File

@ -1,4 +1,6 @@
ARCH ?= $(shell uname -m) ARCHES = x86_64 i386 aarch64
ARCH ?= x86_64
CC = zig cc -target $(ARCH)-freestanding CC = zig cc -target $(ARCH)-freestanding
LD = ld -m elf_$(ARCH) LD = ld -m elf_$(ARCH)
@ -16,18 +18,18 @@ TARGET := kernel
CFILES := $(shell find src -path src/arch -prune -o -type f -name '*.c' -print) CFILES := $(shell find src -path src/arch -prune -o -type f -name '*.c' -print)
ARCHFILES := $(shell find src/arch/$(ARCH) -type f -name '*.c' -print) ARCHFILES := $(shell find src/arch/$(ARCH) -type f -name '*.c' -print)
HFILES := $(shell find src -type f -name '*.h') HFILES := $(shell find src -type f -name '*.h')
OBJ := $(patsubst src/%.c,obj/%.o,$(CFILES) $(ARCHFILES)) OBJ := $(patsubst src/%.c,obj/$(ARCH)/%.o,$(CFILES) $(ARCHFILES))
.PHONY: all clean obj .PHONY: all clean obj
all: $(TARGET) all: $(TARGET)
$(TARGET): $(OBJ) $(TARGET)-$(ARCH): $(OBJ)
$(LD) $(LDFLAGS) $(OBJ) -o $@ $(LD) $(LDFLAGS) $(OBJ) -o $@
obj/%.o: src/%.c $(HFILES) obj/$(ARCH)/%.o: src/%.c $(HFILES)
@mkdir -p obj/arch/$(ARCH) @mkdir -p obj/$(ARCH)/arch/$(ARCH)
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
clean: clean:
rm -rf $(TARGET) obj zig-cache rm -rf $(TARGET)* obj zig-cache

View File

@ -1,4 +1,6 @@
void halt_catch_fire() { void halt_catch_fire() {
asm volatile ("cli"); asm volatile ("cli");
while(1) asm volatile ("hlt"); while(1) asm volatile ("hlt");
} }
const char *arch = "i386";

View File

@ -1,4 +1,6 @@
void halt_catch_fire() { void halt_catch_fire() {
asm volatile ("cli"); asm volatile ("cli");
while(1) asm volatile ("hlt"); while(1) asm volatile ("hlt");
} }
const char *arch = "x86_64";

View File

@ -1 +1,3 @@
void halt_catch_fire(); void halt_catch_fire();
extern const char *arch;

View File

@ -2,7 +2,9 @@
#include "hal/ops.h" #include "hal/ops.h"
void kmain(int argc, char **argv) { void kmain(int argc, char **argv) {
vga_puts("Kernel initialized!\n"); vga_puts("Kernel initialized! Platform: ");
vga_puts(arch);
vga_putc('\n');
vga_puts("Bootloader information:\t"); vga_puts("Bootloader information:\t");
for(int i = 0; i < argc; i++) { for(int i = 0; i < argc; i++) {
vga_puts(argv[i]); vga_puts(argv[i]);