[panic] Add separate kernel-mode panic handler
Created the framework for using different loadable panic handlers, loaded by the bootloader. Initial panic handler is panic.serial, which contains its own serial driver and stacktrace code. Other related changes: - Asserts are now based on the NMI handler - panic handlers get installed as the NMI interrupt handler - Changed symbol table generation: now use nm's own demangling and sorting, and include symbol size in the table - Move the linker script argument out of the kernel target, and into the kernel's specific module, so that other programs (ie, panic handlers) can use the kernel target as well - Some asm changes to boot.s to help GDB see stack frames - but this might not actually be all that useful - Renamed user_rsp to just rsp in cpu_state - everything in there is describing the 'user' state
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
#include "kutil/assert.h"
|
||||
|
||||
namespace kutil {
|
||||
namespace assert {
|
||||
|
||||
assert_callback __kernel_assert_p = nullptr;
|
||||
|
||||
assert_callback
|
||||
assert_set_callback(assert_callback f)
|
||||
{
|
||||
assert_callback old = __kernel_assert_p;
|
||||
__kernel_assert_p = f;
|
||||
return old;
|
||||
}
|
||||
|
||||
uint32_t *apic_icr = reinterpret_cast<uint32_t*>(0xffffc000fee00300);
|
||||
uintptr_t symbol_table = 0;
|
||||
|
||||
} // namespace assert
|
||||
} // namespace kutil
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace kutil {
|
||||
namespace assert {
|
||||
|
||||
using assert_callback =
|
||||
void (*) (const char *file, unsigned line, const char *message);
|
||||
constexpr uint32_t send_nmi_command =
|
||||
(4 << 8) | // Delivery mode NMI
|
||||
(1 << 14) | // assert level high
|
||||
(1 << 18); // destination self
|
||||
|
||||
/// Set the global kernel assert callback
|
||||
/// \args f The new callback
|
||||
/// \returns The old callback
|
||||
assert_callback assert_set_callback(assert_callback f);
|
||||
|
||||
extern assert_callback __kernel_assert_p;
|
||||
extern uint32_t *apic_icr;
|
||||
extern uintptr_t symbol_table;
|
||||
|
||||
} // namespace assert
|
||||
} // namespace kutil
|
||||
|
||||
|
||||
#define kassert(stmt, message) do { if(!(stmt)) { ::kutil::__kernel_assert_p(__FILE__, __LINE__, (message)); }} while(0);
|
||||
#define kassert(stmt, message) \
|
||||
do { \
|
||||
if(!(stmt)) { \
|
||||
register const char *m asm("rdi"); \
|
||||
register uintptr_t i asm("rsi"); \
|
||||
asm volatile ("mov %1, %0" : "=r"(m) : "r"(message)); \
|
||||
asm volatile ("mov %1, %0" : "=r"(i) : "r"(kutil::assert::symbol_table)); \
|
||||
*kutil::assert::apic_icr = kutil::assert::send_nmi_command; \
|
||||
while (1) __asm__ __volatile__ ("hlt"); \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
Reference in New Issue
Block a user