diff --git a/kernel/Makefile b/kernel/Makefile index f4c5127..b5b9a0f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -34,7 +34,7 @@ bin/$(TARGET)-$(ARCH): $(OBJ) @echo Linking $@ $(LD) $(LDFLAGS) $(OBJ) -o $@ -obj/$(ARCH)/%.c.o: src/%.c $(HFILES) +obj/$(ARCH)/%.c.o: src/%.c $(HFILES) $(ARCHHEADERS) @mkdir -p $(@D) @echo $(CC) $< @$(CC) $(CFLAGS) -c $< -o $@ diff --git a/kernel/make/x86/make.config b/kernel/make/x86/make.config index 822d909..42427fb 100644 --- a/kernel/make/x86/make.config +++ b/kernel/make/x86/make.config @@ -1,9 +1,13 @@ ARCHFILES := $(shell find src/arch/x86 -type f -name '*.c' -print) \ - $(shell find src/arch/x86 -type f -name '*.nasm' -print) \ - $(shell find src/arch/$(ARCH) -type f -name '*.nasm' -print) + $(shell find src/arch/x86 -type f -name '*.nasm' -print) \ + $(shell find src/arch/$(ARCH) -type f -name '*.nasm' -print) +ARCHHEADERS := $(shell find src/arch/x86 -type f -name '*.h' -print) \ + $(shell find src/arch/x86 -type f -name '*.nasminc' -print) \ + $(shell find src/arch/$(ARCH) -type f -name '*.nasminc' -print) ARCH_CFLAGS := -masm=intel +NASMFLAGS := -Isrc -obj/$(ARCH)/%.nasm.o: src/%.nasm +obj/$(ARCH)/%.nasm.o: src/%.nasm $(ARCHHEADERS) @mkdir -p $(@D) @echo nasm $< @$(NASM) $(NASMFLAGS) $< -o $@ \ No newline at end of file diff --git a/kernel/src/arch/x86_64/entry-stivale2.c b/kernel/src/arch/x86_64/entry-stivale2.c index c8c174e..61ef24e 100644 --- a/kernel/src/arch/x86_64/entry-stivale2.c +++ b/kernel/src/arch/x86_64/entry-stivale2.c @@ -13,6 +13,8 @@ static uint8_t stack[4096] = {0}; void stivale2_main(struct stivale2_struct *info); +extern void asmpanic(); + struct stivale2_header_tag_smp smp_request = { .tag = { .identifier = STIVALE2_HEADER_TAG_SMP_ID, @@ -48,10 +50,10 @@ void stivale2_main(struct stivale2_struct *info) { __asm__ __volatile__("sgdt %0" : : "m"(pGDT) : "memory"); printf("GDT: %x (%d)\n", pGDT.base, pGDT.limit); for(int i = 0; i < (pGDT.limit+1)/8; i++) { - uint64_t *gdt_ent = pGDT.base + 8*i; + uint64_t *gdt_ent = (uint64_t*)(pGDT.base + 8*i); printf("GDT %d: ", i); print_gdt_ent(gdt_ent); putchar('\n'); } - char *argv[3] = {"stivale2", info->bootloader_brand, info->bootloader_version}; - kmain(3, argv); + asmpanic(); + kmain(); } diff --git a/kernel/src/arch/x86_64/info.nasm b/kernel/src/arch/x86_64/info.nasm index 599fe31..963e001 100644 --- a/kernel/src/arch/x86_64/info.nasm +++ b/kernel/src/arch/x86_64/info.nasm @@ -1,2 +1,8 @@ +%include "arch/x86_64/panic.nasminc" + global archval -archval db "x86_64-nasm", 0 \ No newline at end of file +archval db "x86_64-nasm", 0 + +global asmpanic +asmpanic: + PANIC "asmpanic" \ No newline at end of file diff --git a/kernel/src/arch/x86_64/panic.nasminc b/kernel/src/arch/x86_64/panic.nasminc new file mode 100644 index 0000000..feccb6c --- /dev/null +++ b/kernel/src/arch/x86_64/panic.nasminc @@ -0,0 +1,17 @@ +%ifndef PANIC_NASM_MAC + %define PANIC_NASM_MAC + + extern panic + + %macro PANIC 1 + [SECTION .data] + panicval db %1, 0 + filename db __FILE__, 0 + __SECT__ + mov rdi, panicval + mov rsi, filename + mov rdx, __LINE__ + call panic + %endmacro +%endif + \ No newline at end of file