Make kprintf_internal so panic.h can use it.

This commit is contained in:
Liam Kerr 2026-02-10 13:22:12 +00:00
parent b4d5f8f6eb
commit 663c2712fd
6 changed files with 75 additions and 63 deletions

View file

@ -3,7 +3,7 @@
A monolithic hobbyist kernel written in C and Assembly for the RISC-V 64-bit architecture. A monolithic hobbyist kernel written in C and Assembly for the RISC-V 64-bit architecture.
## Project Overview ## Project Overview
The Gemini Kernel is a from-scratch operating system project designed to explore low-level systems programming, memory management, and hardware-software interfacing. The Squidge Kernel is a from-scratch operating system project designed to explore low-level systems programming, memory management, and hardware-software interfacing.
### Target Architecture ### Target Architecture
* **Architecture**: RISC-V (RV64GC) * **Architecture**: RISC-V (RV64GC)

View file

@ -130,11 +130,8 @@ void kputs(const char *str)
knewline(); knewline();
} }
void kprintf(const char *format, ...) void kprintf_internal(const char *format, va_list args)
{ {
va_list args;
va_start(args, format);
for (const char *p = format; *p != '\0'; p++) for (const char *p = format; *p != '\0'; p++)
{ {
if (*p == '%') if (*p == '%')
@ -186,6 +183,13 @@ void kprintf(const char *format, ...)
kputchar(*p); kputchar(*p);
} }
} }
va_end(args);
knewline(); knewline();
} }
void kprintf(const char *format, ...)
{
va_list args;
va_start(args, format);
kprintf_internal(format, args);
va_end(args);
}

View file

@ -1,6 +1,7 @@
#include <stdarg.h>
#ifndef UART_H #ifndef UART_H
#define UART_H #define UART_H
#define UART_RBR (volatile uint8_t *)(UART_ADDRESS + 0) #define UART_RBR (volatile uint8_t *)(UART_ADDRESS + 0)
#define UART_LSR (volatile uint8_t *)(UART_ADDRESS + 5) #define UART_LSR (volatile uint8_t *)(UART_ADDRESS + 5)
#define UART_ADDRESS 0x10000000 #define UART_ADDRESS 0x10000000
@ -13,6 +14,7 @@ void uart_handle_interrupt();
int kputchar(int ch); int kputchar(int ch);
void kprint_hex(uint64_t val); void kprint_hex(uint64_t val);
void kprint_int(int num); void kprint_int(int num);
void kprintf_internal(const char *format, va_list args);
void kprintf(const char *format, ...); void kprintf(const char *format, ...);
void kprint_float(float num); void kprint_float(float num);
void knewline(); void knewline();

View file

@ -1,5 +1,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdarg.h>
#include <drivers/uart.h> #include <drivers/uart.h>
#include <syscon/syscon.h> #include <syscon/syscon.h>
#include <kernel/plic.h> #include <kernel/plic.h>
@ -21,11 +22,14 @@ void interrupt_init()
kputs("OK"); kputs("OK");
} }
void kpanic(const char *reason) void kpanic(const char *reason, ...)
{ {
va_list args;
va_start(args, reason);
kputs("\n!!! PANIC !!!\n"); kputs("\n!!! PANIC !!!\n");
kputs(reason); kprintf_internal(reason, args);
kputs("\n!!! PANIC !!!\n"); kputs("\n!!! PANIC !!!\n");
va_end(args);
poweroff(); poweroff();
} }
@ -80,7 +84,7 @@ void handle_trap()
kpanic("Reason: Illegal Instruction\n"); kpanic("Reason: Illegal Instruction\n");
break; break;
case 3: case 3:
kpanic("Reason: Breakpoint (ebreak)\n"); kpanic("Reason: Breakpoint (ebreak) %s\n", "woo!");
break; break;
case 4: case 4:
kpanic("Reason: Load Address Misaligned\n"); kpanic("Reason: Load Address Misaligned\n");
@ -96,7 +100,7 @@ void handle_trap()
break; break;
default: default:
break; break;
// kpanic("Reason: Unknown Exception Code %d\n", cause); kpanic("Reason: Unknown Exception Code %d\n", cause);
} }
kprintf("Faulting Address (if applicable): %x\n", mtval); kprintf("Faulting Address (if applicable): %x\n", mtval);
} }

View file

@ -2,7 +2,7 @@
#define PANIC_H #define PANIC_H
void interrupt_init(); void interrupt_init();
void kpanic(const char *); void kpanic(const char *, ...);
void kpanic_force(); void kpanic_force();
void handle_interrupt(unsigned long code); void handle_interrupt(unsigned long code);

View file

@ -16,4 +16,6 @@ void kmain()
uart_init(); uart_init();
page_init(); page_init();
interrupt_init(); interrupt_init();
kpanic_force();
} }