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
10 changes: 8 additions & 2 deletions kernel/arch/amd64/cpu/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ void cpu_interrupt_lock_force_release() {
}

void cpu_halt() {
asm("hlt");
}
asm volatile ("hlt");
}

void cpu_full_halt() {
reflock_acquire(&lock);
lock.allow_force_unlock = false;
cpu_halt();
}
1 change: 1 addition & 0 deletions kernel/include/arch/cpu/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ extern void cpu_interrupt_lock_release();
extern void cpu_interrupt_lock_force_release();

void cpu_halt();
void cpu_full_halt();

#endif
2 changes: 1 addition & 1 deletion kernel/include/kreflock.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct {
void (*on_unlock)();

const bool strict; // if strict, panic if released empty lock
const bool allow_force_unlock;
bool allow_force_unlock;

uint8_t data[12];
} reflock_t;
Expand Down
9 changes: 8 additions & 1 deletion kernel/include/sys/panic.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#ifndef __SYS_PANIC
#define __SYS_PANIC

#include <stdint.h>

void __attribute__((noreturn)) panic_int(uint8_t int_no, const char *msg);
void __attribute__((noreturn)) panic(const char *msg);
void __attribute__((noreturn)) panic(const char *msg, const char *func, const int line);

#define PANIC(msg) panic(msg, __func__, __LINE__)

#endif
2 changes: 1 addition & 1 deletion kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void kernel_main64(uint64_t *multiboot2, uint32_t magic, void *esp,
serial_printf("[ERR]\n");
}

panic("AAAAAAAAAAAAAAAaa");
PANIC("AAAAAAAAAAAAAAAaa");

for (;;) {}
}
8 changes: 4 additions & 4 deletions kernel/klibc/reflock.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void reflock_acquire(reflock_t *lock) {
struct reflock_private *private = reflock_get_private_ptr(lock);

if (!reflock_validate_magic(lock)) {
panic("broken reflock (invalid magic)");
PANIC("broken reflock (invalid magic)");
}

if (!private->data.refcount && lock->on_lock) {
Expand All @@ -64,12 +64,12 @@ void reflock_release(reflock_t *lock) {
struct reflock_private *private = reflock_get_private_ptr(lock);

if (!reflock_validate_magic(lock)) {
panic("broken reflock (invalid magic field)");
PANIC("broken reflock (invalid magic field)");
}

if (!private->data.refcount) {
if (lock->strict) {
panic("Attempted to release empty strict reflock");
PANIC("Attempted to release empty strict reflock");
}

return;
Expand All @@ -89,7 +89,7 @@ void reflock_force_unlock(reflock_t *lock) {
struct reflock_private *private = reflock_get_private_ptr(lock);

if (!lock->allow_force_unlock) {
panic("Attempted disallowed force-unlock of a reflock");
PANIC("Attempted disallowed force-unlock of a reflock");
}

private->data.refcount = 0;
Expand Down
4 changes: 2 additions & 2 deletions kernel/klibc/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ void xmemcpy(void *dest, const void *src, size_t size, opsize_t opsize) {
: "memory");
break;
case OPSIZE_DWORD:
asm volatile("rep movsd"
asm volatile("rep movsl"
: "=&c"(d0), "=&D"(d1), "=&S"(d2)
: "0"(size), "1"(dest), "2"(src)
: "memory");
break;
case OPSIZE_QWORD:
asm volatile("rep movsd"
asm volatile("rep movsl"
: "=&c"(d0), "=&D"(d1), "=&S"(d2)
: "0"(size), "1"(dest), "2"(src)
: "memory");
Expand Down
9 changes: 6 additions & 3 deletions kernel/sys/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
// TODO: make printf-like

void __attribute__((noreturn)) panic_int(uint8_t int_no, const char *msg) {
cpu_interrupt_lock_acquire();

serial_printf("\n\rKernel panic (in interrupt) [INT=0x%02X] - %s\n", int_no,
msg);
cpu_state_print();

for (;;) cpu_halt();
}

void __attribute__((noreturn)) panic(const char *msg) {
serial_printf("\n\rKernel panic - %s\n", msg);
cpu_state_print();
void __attribute__((noreturn)) panic(const char *msg, const char *func, const int line) {
cpu_interrupt_lock_acquire();

serial_printf("\n\rKernel panic - %s in %s:%d\n", msg, func, line);
cpu_state_print();
for (;;) cpu_halt();
}
Loading