Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/arch/x86_64/arch_start.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern __multiboot_addr
%define P4_TAB 0x1000
%define P3_TAB 0x2000 ;; - 0x5fff
%define P2_TAB 0x100000
%define STACK_LOCATION 0x9fff00
%define STACK_LOCATION 0x9ffff0

[BITS 32]
__arch_start:
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/ist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ extern gdtr64 __gdt64_base_pointer;

#define INTR_SIZE 4096
#define NMI_SIZE 20480
#define DFI_SIZE 20480
#define DFI_SIZE 4096

namespace x86
{
struct alignas(SMP_ALIGN) LM_IST
{
char* intr; // 4kb
char* nmi; // 20kb
char* dfi; // 20kb
char* dfi; // 4kb

AMD64_TSS tss;
};
Expand Down
39 changes: 29 additions & 10 deletions src/kernel/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ void OS::on_panic(on_panic_func func)
panic_handler = std::move(func);
}

extern "C" __attribute__((noreturn)) void panic_epilogue(const char*);


/**
* panic:
* Display reason for kernel panic
Expand Down Expand Up @@ -193,21 +196,37 @@ asm("panic_begin:");
fflush(stderr);
SMP::global_unlock();

// call custom on panic handler (if present)
if (panic_handler) panic_handler(why);
panic_epilogue(why);
}

#if defined(ARCH_x86)
extern "C"
void double_fault(const char* why)
{
SMP::global_lock();
// Signal End-Of-Transmission
kprint("\x04");
fprintf(stderr, "\n%s\nCPU: %d, Reason: %s\n",
panic_signature, SMP::cpu_id(), why);
SMP::global_unlock();

// .. if we return from the panic handler, go to permanent sleep
while (1) asm("cli; hlt");
panic_epilogue(why);
}

void panic_epilogue(const char* why)
{
// call custom on panic handler (if present)
if (panic_handler) panic_handler(why);

#if defined(ARCH_x86)
SMP::global_lock();
// Signal End-Of-Transmission
kprint("\x04");
SMP::global_unlock();

// .. if we return from the panic handler, go to permanent sleep
while (1) asm("cli; hlt");
#else
#warning "panic() handler not implemented for selected arch"
#endif
__builtin_unreachable();
#else
#warning "panic() handler not implemented for selected arch"
#endif
}

// Shutdown the machine when one of the exit functions are called
Expand Down
15 changes: 13 additions & 2 deletions src/platform/x86_pc/idt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ static void cpu_dump_regs(uintptr_t* regs)
fprintf(stderr, "\n");
}

extern "C" void double_fault(const char*);

extern "C"
__attribute__((noreturn, optnone))
void __cpu_exception(uintptr_t* regs, int error, uint32_t code)
Expand All @@ -270,8 +272,17 @@ void __cpu_exception(uintptr_t* regs, int error, uint32_t code)
exception_names[error], error, (void*) regs[RIP_REG], code);
cpu_dump_regs(regs);
SMP::global_unlock();
// call panic, which will decide what to do next
// error message:
char buffer[64];
snprintf(buffer, sizeof(buffer), "%s (%d)", exception_names[error], error);
panic(buffer);
// normal CPU exception
if (error != 0x8) {
// call panic, which will decide what to do next
panic(buffer);
}
else {
// handle double faults differently
double_fault(buffer);
}
__builtin_unreachable();
}