$ show cfenollosa/os-tutorial
This repository is a step-by-step tutorial for building an operating system from scratch, progressing from a simple boot sector to a kernel with interrupts, memory management, and a basic shell. The code is organized into sequential lessons, each building upon the previous. The system boots via a custom boot sector, loads a kernel into memory, transitions to 32-bit protected mode, sets up interrupt handling (including timer and keyboard), and provides a shell that can echo user input and handle basic commands like 'END' to halt and 'PAGE' to test memory allocation. While educational and well-commented, the codebase shows signs of abandonment per the README, though the last commit date indicates recent activity. The architecture is monolithic with modular components for bootloader, kernel, drivers (screen, keyboard, timer), and a lightweight libc.
The LLM identified 3 files worth highlighting for reuse:
Provides inline assembly functions for reading and writing to I/O ports (port_byte_in, port_byte_out, port_word_in, port_word_out). This hardware abstraction layer is architecture-specific (x86) but self-contained, requiring only basic type definitions. It demonstrates non-obvious low-level skill in using inline asm for port I/O and can be extracted to any bare-metal x86 project with minimal modification.
Implements a VGA text mode driver with functions to clear the screen, print strings at specific coordinates, handle cursor positioning, and scroll the screen when necessary. Encapsulates direct video memory access (0xb8000) and hardware port interactions for the VGA controller (ports 0x3d4/0x3d5). The module is isolated, depending only on port I/O and basic types, and showcases proper encapsulation of hardware-specific details for reuse in other x86 text-mode projects.
Contains assembly stubs for interrupt service routines (ISRs) and interrupt request (IRQ) handlers. It saves processor state via pusha/popa, calls C handlers, and restores state, including handling of error codes and PIC remapping. This module demonstrates non-obvious skill in bridging assembly and C for interrupt handling, following standard OSDev patterns. While tied to the kernel's segment selectors, the core stub design is reusable in any x86 OS project with minor adjustments to the C handler interface.