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
4 changes: 2 additions & 2 deletions arch/x86/extables.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
void init_extables(void) {
for (extable_entry_t *cur = __start_extables; cur < __stop_extables; ++cur) {
if (!cur->fixup && !cur->cb)
panic("extable entry #%d for addr 0x%lx lacks fixup and callback!\n",
cur - __start_extables, cur->fault_addr);
warning("extable entry #%d for addr 0x%lx lacks fixup and callback!",
cur - __start_extables, cur->fault_addr);
}
}
2 changes: 1 addition & 1 deletion arch/x86/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void do_exception(cpu_regs_t *regs) {
x86_ex_decode_error_code(ec_str, sizeof(ec_str), regs->exc.vector, regs->exc.error_code);

snprintf(panic_str, sizeof(panic_str),
"#%s %sat IP: 0x%02x:0x%016lx SP: 0x%02x:0x%016lx\n",
"#%s %sat IP: 0x%02x:0x%016lx SP: 0x%02x:0x%016lx",
exception_names[regs->exc.vector], ec_str, regs->exc.cs, regs->exc._ASM_IP, regs->exc.ss,
regs->exc._ASM_SP);

Expand Down
10 changes: 6 additions & 4 deletions common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ static inline bool validate_rsdp(rsdp_rev1_t *ptr) {
size = sizeof(rsdp_rev2_t);
break;
default:
panic("Unknown ACPI revision: %u\n", ptr->rev);
warning("Unknown ACPI revision: %u", ptr->rev);
return false;
}

if (get_checksum(ptr, size) != 0x0)
Expand Down Expand Up @@ -141,7 +142,7 @@ static unsigned acpi_table_map_pages(paddr_t pa, size_t len) {

for (unsigned i = 0; i < num_pages; i++, mfn++) {
if (mfn_invalid(mfn)) {
panic("ACPI table at %p of length %lx has invalid MFN: %lx\n", _ptr(pa), len,
panic("ACPI table at %p of length %lx has invalid MFN: %lx", _ptr(pa), len,
mfn);
}

Expand Down Expand Up @@ -366,7 +367,8 @@ static int process_madt_entries(void) {
break;
}
default:
panic("Unknown ACPI MADT entry type: %u\n", entry->type);
warning("Unknown ACPI MADT entry type: %u", entry->type);
break;
}
}

Expand Down Expand Up @@ -681,7 +683,7 @@ static void madt_parser(ACPI_SUBTABLE_HEADER *entry, void *arg) {
break;
}
default:
panic("ACPI [MADT]: Unsupported subtable entry type: %x\n", entry->Type);
warning("ACPI [MADT]: Unsupported subtable entry type: %x", entry->Type);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void __text_init cmdline_parse(const char *cmdline) {
!!parse_bool(!strcmp(optval, optkey) ? "1" : optval);
break;
default:
panic("Unkown cmdline type detected...");
warning("Unkown cmdline type \"%u\" for %s", param->type, param->name);
break;
}
}
Expand Down
21 changes: 17 additions & 4 deletions common/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void vprintk(const char *fmt, va_list args) {
rc = vsnprintf(buf, sizeof(buf), fmt, args);

if (rc > (int) sizeof(buf))
panic("vprintk() buffer overflow\n");
panic("vprintk() buffer overflow");

for (i = 0; i < num_console_callbacks; i++) {
void *arg = console_callbacks[i].arg;
Expand Down Expand Up @@ -125,15 +125,28 @@ void register_console_callback(console_callback_t cb, void *arg) {
void __noreturn panic(const char *fmt, ...) {
va_list args;

printk("******************************\n");
printk("CPU[%u] PANIC: ", smp_processor_id());
printk("************** PANIC **************\n");
printk("CPU[%u]: ", smp_processor_id());

va_start(args, fmt);
vprintk(fmt, args);
va_end(args);

printk("******************************\n");
printk("\n***********************************\n");

while (1)
halt();
}

void warning(const char *fmt, ...) {
va_list args;

printk("************* WARNING *************\n");
printk("CPU[%u]: ", smp_processor_id());

va_start(args, fmt);
vprintk(fmt, args);
va_end(args);

printk("\n***********************************\n");
}
4 changes: 2 additions & 2 deletions common/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static int prepare_task(task_t *task, const char *name, task_func_t func, void *
if (!task)
return -EINVAL;

BUG_ON(get_task_state(task) > TASK_STATE_READY);
ASSERT(get_task_state(task) <= TASK_STATE_READY);

task->name = name;
task->func = func;
Expand Down Expand Up @@ -179,7 +179,7 @@ int schedule_task(task_t *task, cpu_t *cpu) {
return -EEXIST;
}

BUG_ON(get_task_state(task) != TASK_STATE_READY);
ASSERT(get_task_state(task) == TASK_STATE_READY);

printk("CPU[%u]: Scheduling task %s[%u] (%s)\n", cpu->id, task->name, task->id,
task_repeat_string(task->repeat));
Expand Down
3 changes: 2 additions & 1 deletion drivers/acpi/acpica/osl.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ ACPI_STATUS AcpiOsSignal(UINT32 Function, void *Info) {
printk("ACPI: Received ACPI_SIGNAL_BREAKPOINT: %s", bp_msg ?: "");
} break;
default:
BUG();
warning("ACPI: Unsupported ACPI signal: %u", Function);
break;
}

return AE_OK;
Expand Down
8 changes: 3 additions & 5 deletions drivers/fb/fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ void init_framebuffer(const struct multiboot2_tag_framebuffer *fb) {
banner_size = (size_t) width * (LOGO_HEIGHT + FONT_SIZE);

switch (bpp) {
case 0 ... 7:
printk("FB: Unsupported framebuffer BPP: %u\n", bpp);
has_fb = false;
return;
case 8:
put_pixel = put_pixel8;
break;
Expand All @@ -117,7 +113,9 @@ void init_framebuffer(const struct multiboot2_tag_framebuffer *fb) {
banner_size *= 4;
break;
default:
BUG();
warning("FB: Unsupported framebuffer BPP: %u", bpp);
has_fb = false;
return;
}

line_width = pitch * FONT_SIZE;
Expand Down
3 changes: 2 additions & 1 deletion drivers/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static inline const char *com_name(com_idx_t com) {
case COM4:
return "COM4";
default:
BUG();
warning("Invalid COM port %u\n", com);
return NULL;
}
}

Expand Down
1 change: 1 addition & 0 deletions include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ extern void fb_console_write(void *arg, const char *buf, size_t len);
extern void register_console_callback(console_callback_t func, void *arg);

extern void panic(const char *fmt, ...);
extern void warning(const char *fmt, ...);

#endif /* KTF_CONSOLE_H */
14 changes: 12 additions & 2 deletions include/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,28 @@ static inline void sysret(void) {

#define BUG() \
do { \
panic("BUG in %s() at line %u\n", __func__, __LINE__); \
panic("BUG in %s() at line %u", __func__, __LINE__); \
} while (true)
#define BUG_ON(cond) \
do { \
if ((cond)) \
BUG(); \
} while (0)

#define WARN(msg) \
do { \
warning("Warning in %s() at line %u: %s", __func__, __LINE__, (msg)); \
} while (0)
#define WARN_ON(cond, msg) \
do { \
if ((cond)) \
WARN((msg)); \
} while (0)

#define ASSERT(cond) \
do { \
if (!(cond)) \
panic("%s: Assert at %d failed: %s\n", __func__, __LINE__, STR((cond))); \
panic("%s: Assert at %d failed: %s", __func__, __LINE__, STR((cond))); \
} while (0)

/* I/O Ports handling */
Expand Down
42 changes: 20 additions & 22 deletions mm/pmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static frames_array_t *new_frames_array(void) {
array = get_free_page(GFP_KERNEL);

if (!array)
panic("PMM: Unable to allocate new page for frame array\n");
panic("PMM: Unable to allocate new page for frame array");

dprintk("%s: allocated new frames array: %p\n", __func__, array);

Expand All @@ -109,15 +109,11 @@ static bool is_frames_array_free(const frames_array_t *array) {
if (array->meta.free_count < ARRAY_SIZE(array->frames))
return false;
else if (array->meta.free_count > ARRAY_SIZE(array->frames))
panic("PMM: incorrect number of free slots: %d in array: %p\n",
panic("PMM: incorrect number of free slots: %d in array: %p",
array->meta.free_count, array);

for (unsigned i = 0; i < ARRAY_SIZE(array->frames); i++) {
const frame_t *frame = &array->frames[i];

if (!is_frame_free(frame))
panic("PMM: found occupied slot in an empty array: %p\n", array);
}
for (unsigned i = 0; i < ARRAY_SIZE(array->frames); i++)
ASSERT(is_frame_free(&array->frames[i]));

return true;
}
Expand Down Expand Up @@ -171,7 +167,7 @@ static inline frame_t *take_frame(frame_t *frame, frames_array_t *array) {
}

static inline frame_t *put_frames_array_entry(frame_t *frame, frames_array_t *array) {
BUG_ON(is_frame_free(frame));
ASSERT(!is_frame_free(frame));

if (!array)
array = find_frames_array(frame);
Expand All @@ -190,7 +186,7 @@ static inline frame_t *get_frames_array_entry(void) {
frames_array_t *array = get_frames_array();

if (!array)
panic("PMM: Unable to get a free array of frames' metadata\n");
panic("PMM: Unable to get a free array of frames' metadata");

for (unsigned i = 0; i < ARRAY_SIZE(array->frames); i++) {
frame_t *frame = &array->frames[i];
Expand All @@ -203,7 +199,7 @@ static inline frame_t *get_frames_array_entry(void) {
}

static inline void destroy_frame(frame_t *frame) {
BUG_ON(is_frame_used(frame));
ASSERT(!is_frame_used(frame));

if (frame) {
list_unlink(&frame->list);
Expand Down Expand Up @@ -260,7 +256,7 @@ static unsigned find_first_avail_region(void) {
return i;
}

panic("PMM: Cannot obtain first available physical memory address range\n");
panic("PMM: Cannot obtain first available physical memory address range");
UNREACHABLE();
}

Expand Down Expand Up @@ -313,8 +309,8 @@ static size_t process_memory_range(unsigned index, unsigned first_avail_region)
}

if (cur != end) {
panic(
"PMM range processing failed: start=0x%016lx end=0x%016lx current=0x%016lx\n",
warning(
"PMM range processing failed: start=0x%016lx end=0x%016lx current=0x%016lx",
start, end, cur);
}

Expand Down Expand Up @@ -343,12 +339,12 @@ static inline void check_early_frames(unsigned first_avail_region) {
addr_range_t range;

if (get_avail_memory_range(first_avail_region, &range) < 0)
panic("PMM: Cannot obtain first available physical memory address range\n");
panic("PMM: Cannot obtain first available physical memory address range");

early_frames_cnt =
(MB(EARLY_VIRT_MEM) - get_region_free_start(range.start)) / PAGE_SIZE;
if (frames_count[PAGE_ORDER_4K] < early_frames_cnt) {
panic("Not enough early frames: %u missing\n",
panic("Not enough early frames: %u missing",
early_frames_cnt - frames_count[PAGE_ORDER_4K]);
}
}
Expand Down Expand Up @@ -395,8 +391,7 @@ static inline frame_t *reserve_frame(frame_t *frame) {
}

static inline bool return_frame(frame_t *frame) {
if (!is_frame_used(frame))
panic("PMM: trying to return unused frame: %p\n", frame);
ASSERT(is_frame_used(frame));

if (--frame->refcount == 0) {
list_unlink(&frame->list);
Expand Down Expand Up @@ -458,7 +453,7 @@ frame_t *get_free_frames_cond(free_frames_cond_t cb) {
}

static inline void relink_frame_to_order(frame_t *frame, unsigned int new_order) {
BUG_ON(new_order > MAX_PAGE_ORDER);
ASSERT(new_order <= MAX_PAGE_ORDER);

list_unlink(&frame->list);
frames_count[frame->order]--;
Expand Down Expand Up @@ -548,13 +543,16 @@ void put_free_frames(mfn_t mfn, unsigned int order) {

spin_lock(&lock);
frame = find_mfn_frame(busy_frames, mfn, order);
if (!frame)
panic("PMM: unable to find frame: %lx, order: %u among busy frames\n", mfn,
order);
if (!frame) {
warning("PMM: unable to find frame: %lx, order: %u among busy frames", mfn,
order);
goto unlock;
}

if (return_frame(frame))
merge_frames(frame);

unlock:
spin_unlock(&lock);
}

Expand Down
2 changes: 1 addition & 1 deletion mm/regions.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ addr_range_t get_memory_range(paddr_t pa) {
memset(&r, 0, sizeof(r));
if (mbi_get_memory_range(pa, &r) < 0)
/* FIXME: e820_lower_memory_bound() */
panic("Unable to get memory range for: 0x%016lx\n", pa);
panic("Unable to get memory range for: 0x%016lx", pa);

return r;
}
Expand Down
2 changes: 1 addition & 1 deletion mm/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ static void ktf_free(void *ptr) {
}
}

panic("Attempted to free %p and couldn't find it\n", ptr);
panic("Attempted to free %p and couldn't find it", ptr);
/* If we reached here, something terribly went wrong */
UNREACHABLE();
}
Expand Down
2 changes: 1 addition & 1 deletion mm/vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void *get_free_pages(unsigned int order, gfp_flags_t flags) {
mfn_t mfn;

if (!boot_flags.virt)
panic("Unable to use %s() before final page tables are set\n", __func__);
panic("Unable to use %s() before final page tables are set", __func__);

if (!frame)
return NULL;
Expand Down
12 changes: 9 additions & 3 deletions smp/mptables.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ static mpc_hdr_t *get_mpc_addr(const mpf_t *mpf_ptr) {
mpc_hdr_t *mpc_ptr;

mpc_ptr = paddr_to_virt_kern(mpf_ptr->mpc_base);
if (!validate_mpc(mpc_ptr))
panic("Incorrect MP Configuration Table found!\n");
if (!validate_mpc(mpc_ptr)) {
warning("Incorrect MP Configuration Table found!");
return NULL;
}

return mpc_ptr;
}
Expand Down Expand Up @@ -284,7 +286,8 @@ static void process_mpc_entries(mpc_hdr_t *mpc_ptr) {
break;
}
default:
panic("Unknown MP Configuration Table entry type: %x\n", *entry_ptr);
warning("Unknown MP Configuration Table entry type: %x", *entry_ptr);
break;
}
}
}
Expand All @@ -307,6 +310,9 @@ int init_mptables(void) {
}

mpc_ptr = get_mpc_addr(mpf_ptr);
if (!mpc_ptr)
return -EINVAL;

if (opt_debug)
dump_mpc_hdr(mpc_ptr);
process_mpc_entries(mpc_ptr);
Expand Down