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
kernel/kernel
kernel/kernel*
obj/
*.o

View File

@ -1,12 +1,14 @@
COMPONENTS = kernel
ARCH ?= x86_64
KERNEL_HDD = kornos.img
.PHONY: clean all $(COMPONENTS)
.DEFAULT_GOAL = $(KERNEL_HDD)
$(COMPONENTS):
$(MAKE) -C $@
$(MAKE) -C $@ $@-$(ARCH)
disk: $(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) mkpart primary 1 100%
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
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
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)
ARCHFILES := $(shell find src/arch/$(ARCH) -type f -name '*.c' -print)
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
all: $(TARGET)
$(TARGET): $(OBJ)
$(TARGET)-$(ARCH): $(OBJ)
$(LD) $(LDFLAGS) $(OBJ) -o $@
obj/%.o: src/%.c $(HFILES)
@mkdir -p obj/arch/$(ARCH)
obj/$(ARCH)/%.o: src/%.c $(HFILES)
@mkdir -p obj/$(ARCH)/arch/$(ARCH)
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -rf $(TARGET) obj zig-cache
rm -rf $(TARGET)* obj zig-cache

View File

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

View File

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

View File

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

View File

@ -2,7 +2,9 @@
#include "hal/ops.h"
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");
for(int i = 0; i < argc; i++) {
vga_puts(argv[i]);