NKLegacy includes an interactive command shell modeled after the Windows NT command prompt. It runs in an infinite loop after kernel initialization, accepting input from the PS/2 keyboard or the COM1 serial port. The shell entry point isDocumentation 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.
cmd_run(), declared in ntoskrnl/exe/cmd.h and implemented in ntoskrnl/exe/cmd.c.
Shell Prompt
The prompt is printed before each input line and reflects the current working directory:| State | Prompt displayed | Color attribute |
|---|---|---|
Root directory (C:) | C:\> | 0x07 (light gray) |
Subdirectory (e.g. docs) | C:\docs> | 0x07 (light gray) |
| NKBuild mode | nkbuild> | 0x0C (light red) |
cwd_path buffer, initialized to "C:".
Input Handling
Poll for a character
keyboard_getchar() is called first. If it returns 0 (no key ready), serial_getchar(COM1) is tried. If both return 0, the loop yields with pause.Accumulate into buffer
Printable characters are appended to a 128-character
cmd_buf. The buffer silently drops any character past index 127.Handle backspace
A
\b character decrements the buffer index and erases the last character on-screen (backspace + space + backspace sequence).The shell is case-sensitive: all built-in commands must be entered in lowercase (e.g.,
dir, cls, mkdir). Entering DIR or CLS will produce an “is not recognized” error.Commands
help
Lists all available built-in commands with a short description.
cls
Clears the VGA text-mode screen and resets the hardware cursor to position (0, 0).
vga_clear() followed by vga_set_cursor(0, 0).
ver
Displays the OS version string.
dir
Lists all files and subdirectories in the current working directory. Each entry is printed with its type tag (<DIR> or blank), name, and size. For directories, size reflects the number of direct children; for files, it is the byte count.
Syntax
cwd_node->first_child through the sibling chain via next_sibling.
cd
Changes the current working directory. Use .. to navigate up one level.
Syntax
cd ..
Walks
cwd_node to its parent pointer and strips the last path component from cwd_path. If the path would become empty, it resets to "C:".The system cannot find the path specified.
mkdir / md
Creates a new subdirectory inside the current directory. Both mkdir <name> and md <name> are accepted.
Syntax
nkfs_mkdir(cwd_node, name). If the directory already exists (or the node pool is full), prints:
echo
Prints text to the VGA console. Supports output redirection to a file using >. When called with no argument, prints ECHO is on.
Syntax
> is present in the argument string, the text to the left of > is written into the named file in the current directory via nkfs_create_file + nkfs_write_file. Trailing spaces are stripped from the text before writing.
Error (file creation failed): Access denied.
type
Displays the raw byte contents of a file in the current directory to both the VGA screen and COM1.
Syntax
file->data[0..file->size-1], calling vga_putchar and serial_putchar(COM1, ...) for each byte. Newlines (\n) are followed by a carriage return (\r) on the serial port.
Error: The system cannot find the file specified.
build
Enters NKBuild mode to interactively construct a minimal PE32 binary in memory. The shell prompt changes to nkbuild> (light red) and each input line is forwarded to nkbuild_process_line(). Type done to finalize the binary and return to the normal shell prompt.
build is intercepted by the cmd_run loop before cmd_execute is called. If build somehow reaches cmd_execute directly (e.g., called programmatically), it prints a diagnostic message and does nothing useful — NKBuild mode is only entered through the main loop.run
Executes the PE32 binary most recently assembled with build. Retrieves the buffer from nkbuild_get_exe_buffer() and its size from nkbuild_get_exe_size(), then passes them to pe_load_and_run().
Syntax
Error Messages
| Message | Trigger |
|---|---|
'<cmd>' is not recognized as an internal or external command,operable program or batch file. | The input does not match any built-in command. |
The system cannot find the path specified. | cd <name> — target does not exist or is not a directory. |
The system cannot find the file specified. | type <file> — target does not exist or is a directory. |
A subdirectory or file <name> already exists. | mkdir / md — a node with that name already exists. |
Access denied. | echo ... > — nkfs_create_file returned NULL (pool full or type collision). |
No executable built yet. Run 'build' first. | run — no binary has been finalized by NKBuild. |