Kernelite 0.1.0
Kernelite is a minimalist, educational operating system kernel built from scratch. The project aims to recreate core components of the Linux architecture to explore the fundamentals of operating system design and hardware-software interaction.
Loading...
Searching...
No Matches
Functions | Variables
kprintf.c File Reference

Implementation of formatted print functions for kernel debugging. More...

#include "utils/kprintf.h"
#include <stdarg.h>
#include <stddef.h>
Include dependency graph for kprintf.c:

Functions

static void itoa (unsigned long num, int base, char *buf)
 Convert an unsigned integer to a string using the given base.
 
int vprintf (const char *format, va_list args)
 Variadic print function.
 
void set_kprintf_console (serial_t con)
 Configures the global serial console used by kprintf.
 
int kprintf (const char *format,...)
 Standard formatted print to the serial console.
 

Variables

static serial_t serial_console
 Global serial console.
 

Detailed Description

Implementation of formatted print functions for kernel debugging.

Implements variadic print helpers and serial output wiring for the in-kernel diagnostic console.

Author
Abhin Parekadan Jose
Date
2026-05-16

Function Documentation

◆ itoa()

static void itoa ( unsigned long  num,
int  base,
char *  buf 
)
static

Convert an unsigned integer to a string using the given base.

This helper writes the string representation of num into buf. The resulting string is always null-terminated.

Parameters
numNumber to convert.
baseNumerical base for conversion (e.g. 10 for decimal, 16 for hex).
bufBuffer to receive the converted string. Must be large enough to hold the result.

◆ kprintf()

int kprintf ( const char *  format,
  ... 
)

Standard formatted print to the serial console.

A wrapper around vprintf that handles variadic argument initialization and cleanup.

Parameters
formatFormatting string containing plain text and specifiers.
...Variable arguments matching the specifiers in the format string.
Returns
The total number of characters successfully printed.

◆ set_kprintf_console()

void set_kprintf_console ( serial_t  console)

Configures the global serial console used by kprintf.

Sets the function pointers that kprintf will use to output characters.

Parameters
consoleA serial_t structure containing initialized function pointers.

◆ vprintf()

int vprintf ( const char *  format,
va_list  args 
)

Variadic print function.

Processes the format string and arguments, outputting characters via the configured serial console.

Supports: %c, %s, %d, %u, %x, %p. A leading 'l' length modifier (e.g. lx) is accepted, but the character after 'l' is consumed and ignored — any l followed by any character is always printed as unsigned hex, regardless of what that character actually is.

Parameters
formatFormatting string containing plain text and specifiers.
argsAn initialized va_list containing the arguments to be formatted.
Returns
The total number of characters successfully printed.