implement multi-architecure stuff

This commit is contained in:
Quinten Kock 2020-11-30 05:01:07 +01:00
parent 03ed46212d
commit 08a80c7731
9 changed files with 30 additions and 16 deletions

View File

@ -1,27 +1,33 @@
ARCH ?= $(shell uname -m)
CC = zig cc -target $(ARCH)-freestanding
LD = ld -m elf_$(ARCH)
-include make.$(ARCH).config
CFLAGS ?= -O2
CFLAGS := $(CFLAGS) $(ARCH_CFLAGS) \
-Wall -Wextra -pedantic -Wno-language-extension-token -std=gnu11 -I../ext/limine/stivale -fPIE
LDFLAGS := $(LDFLAGS) -T linker.ld
TARGET := kernel
CC = zig cc -target x86_64-freestanding
CFLAGS = -O2 -Wall -Wextra -Wno-language-extension-token -pedantic -std=gnu11 -pedantic
LD = ld -m elf_x86_64
QEMU = qemu-system-x86_64
QEMUFLAGS = -m 1G -enable-kvm -cpu host
LDINTERNALFLAGS := -Tlinker.ld
INTERNALCFLAGS := -I../ext/limine/stivale -mcmodel=kernel
CFILES := $(shell find src -type f -name '*.c')
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))
OBJ := $(patsubst src/%.c,obj/%.o,$(CFILES) $(ARCHFILES))
.PHONY: all clean obj
all: $(TARGET)
$(TARGET): $(OBJ)
$(LD) $(LDINTERNALFLAGS) $(OBJ) -o $@
$(LD) $(LDFLAGS) $(OBJ) -o $@
obj/%.o: src/%.c $(HFILES)
@mkdir -p obj
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
@mkdir -p obj/arch/$(ARCH)
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -rf $(TARGET) obj zig-cache

View File

@ -0,0 +1 @@
LD=arm-none-eabi-ld

View File

@ -0,0 +1 @@
ARCH_CFLAGS = -mcmodel=kernel

View File

@ -2,7 +2,7 @@
#include <stdint.h>
#include <stddef.h>
#include "main.h"
#include "../../main.h"
static uint8_t stack[4096] = {0};
void stivale2_main(struct stivale2_struct *info);

View File

@ -0,0 +1,4 @@
void halt_catch_fire() {
asm volatile ("cli");
while(1) asm volatile ("hlt");
}

1
kernel/src/hal/ops.h Normal file
View File

@ -0,0 +1 @@
void halt_catch_fire();

View File

@ -1,4 +1,5 @@
#include "vga.h"
#include "arch/x86_64/vga.h"
#include "hal/ops.h"
void kmain(int argc, char **argv) {
vga_puts("Kernel initialized!\n");
@ -10,5 +11,5 @@ void kmain(int argc, char **argv) {
vga_setcolor(VGA_DARK_GRAY);
vga_write_elsewhere("(c) Quinten Kock 2020 (MIT License)", 24, 0);
asm volatile ("hlt");
halt_catch_fire();
}