Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pastaboy12345/NKLegacy/llms.txt
Use this file to discover all available pages before exploring further.
kprintf is NKLegacy’s kernel-level formatted print function. Every call outputs simultaneously to both the VGA text console and the COM1 serial port (0x3F8), making it the primary debug channel during kernel development. There is no buffering or locking — output is written character-by-character in the order it is produced.
Function Signature
ntoskrnl/kernel/kprintf.h and implemented in ntoskrnl/kernel/kprintf.c. Include the header anywhere you need formatted output:
Format Specifiers
kprintf does not support padding, field-width specifiers, precision, length modifiers (%ld, %zu, etc.), or floating-point types. It is intentionally minimal for a freestanding kernel environment where the C standard library is unavailable.%s — string
Prints a null-terminated C string. If the pointer is
NULL, prints the literal text (null) instead of faulting.%d — signed integer
Prints a signed decimal
int. Negative values are preceded by a minus sign (-).%u — unsigned integer
Prints an unsigned decimal
unsigned int. Use this for tick counters, sizes, and other non-negative quantities.%x — hexadecimal
Prints an unsigned
int in uppercase hexadecimal, always prefixed with 0x (e.g., 0x1F4).%p — pointer
Identical to
%x — the value is formatted as an unsigned hex integer with a 0x prefix. Useful for printing addresses.%c — character
Prints a single
char.%% — literal percent
Emits a single
% character in the output.Dual Output Behaviour
Internally,kprintf routes every character through the private kput helper:
- VGA: Each character is written at the current cursor position using
vga_putchar. The VGA driver advances the cursor and scrolls when the bottom row is reached. - Serial (COM1): Each character is sent to
0x3F8. Newline characters (\n) automatically emit a carriage return (\r) before the newline so that serial terminals receive proper CRLF line endings. - Order: VGA and serial writes happen within the same
kputcall, so both outputs stay in sync even if the kernel crashes mid-print.
Usage Examples
Basic string and integer
Hexadecimal address
Multiple arguments
NULL pointer guard
Signed integer
Single character
Internal Implementation Reference
The fullkprintf.c source shows each specifier’s handling path:
default branch) are passed through literally — kprintf("%q", ...) would emit %q verbatim rather than silently discarding the character.