add panicking from assembly

This commit is contained in:
Quinten Kock 2020-12-08 12:21:05 +01:00
parent 026e6d0e1a
commit 7d257b014a
5 changed files with 37 additions and 8 deletions

View File

@ -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 $@

View File

@ -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 $@

View File

@ -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();
}

View File

@ -1,2 +1,8 @@
%include "arch/x86_64/panic.nasminc"
global archval
archval db "x86_64-nasm", 0
archval db "x86_64-nasm", 0
global asmpanic
asmpanic:
PANIC "asmpanic"

View File

@ -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