OpenOS has been refactored from a flat directory structure into a clean, modular monolithic architecture. This document describes the new architecture, design principles, and module organization.
OpenOS follows a monolithic kernel architecture with strong modularity:
OpenOS/
├── arch/ # Architecture-specific code
│ └── x86/ # x86-specific implementations
│ ├── boot.S # Multiboot entry point, stack setup
│ ├── idt.c/h # Interrupt Descriptor Table
│ ├── isr.S/h # Interrupt Service Routines
│ ├── pic.c/h # Programmable Interrupt Controller
│ ├── ports.h # x86 port I/O operations (inb/outb)
│ └── exceptions.c/h/S # CPU exception handlers
│
├── kernel/ # Core kernel subsystems
│ ├── kernel.c/h # Main kernel entry and initialization
│ └── panic.c/h # Kernel panic handler
│
├── memory/ # Memory management
│ ├── pmm.c/h # Physical Memory Manager (page allocator)
│ ├── vmm.c/h # Virtual Memory Manager (paging)
│ └── heap.h # Kernel heap allocator (placeholder)
│
├── drivers/ # Hardware drivers
│ ├── console.c/h # VGA text mode console
│ ├── keyboard.c/h # PS/2 keyboard driver
│ └── timer.c/h # Programmable Interval Timer (PIT)
│
├── fs/ # File system support
│ └── vfs.h # Virtual File System (placeholder)
│
├── process/ # Process management
│ └── process.h # Process structures (placeholder)
│
├── ipc/ # Inter-process communication
│ └── (future) # Pipes, messages (future)
│
├── include/ # Common headers
│ ├── types.h # Standard type definitions
│ └── multiboot.h # Multiboot specification structures
│
├── Kernel2.0/ # Output directory (legacy compatibility)
│ └── openos.bin # Final kernel binary
│
├── Makefile # Build system
├── linker.ld # Linker script
└── grub.cfg # GRUB bootloader configuration
The kernel maintains a strict dependency hierarchy to prevent circular dependencies:
┌─────────────────────────────────────────┐
│ User Space (future) │
└─────────────────────────────────────────┘
▲
│ syscalls
┌─────────────────────────────────────────┐
│ Core Kernel (kernel/) │
│ - kernel.c (initialization) │
│ - panic.c (error handling) │
└─────────────────────────────────────────┘
▲ ▲ ▲
│ │ │
┌────────┴─────┐ ┌─────┴──────┐ ┌────┴─────┐
│ Drivers │ │ Memory │ │ FS │
│ (drivers/) │ │ (memory/) │ │ (fs/) │
│ - console │ │ - pmm │ │ - vfs │
│ - keyboard │ │ - vmm │ │ │
│ - timer │ │ - heap │ │ │
└──────────────┘ └────────────┘ └──────────┘
▲ ▲ ▲
│ │ │
└──────────────┴──────────────┘
│
┌─────────┴──────────┐
│ Architecture │
│ (arch/x86/) │
│ - boot.S │
│ - idt │
│ - isr │
│ - pic │
│ - exceptions │
│ - ports │
└────────────────────┘
│
┌─────────┴──────────┐
│ Common Headers │
│ (include/) │
│ - types.h │
│ - multiboot.h │
└────────────────────┘
Purpose: Hardware abstraction and x86-specific operations
Key Components:
boot.S: Multiboot entry, initial stack setup, calls kmain()idt.c/h: Interrupt Descriptor Table managementisr.S/h: Low-level interrupt service routine stubspic.c/h: 8259 PIC initialization and IRQ handlingports.h: Inline functions for x86 I/O port operationsexceptions.c/h/S: CPU exception handlers with detailed error reportingResponsibilities:
Purpose: System initialization and core kernel services
Key Components:
kernel.c/h: Main entry point (kmain), subsystem initializationpanic.c/h: Unrecoverable error handlingResponsibilities:
Purpose: Physical and virtual memory management
Key Components:
pmm.c/h: Physical Memory Manager - bitmap-based page frame allocatorvmm.c/h: Virtual Memory Manager - paging, page tablesheap.h: Kernel heap allocator (future: kmalloc/kfree)Responsibilities:
Purpose: Hardware device drivers
Key Components:
console.c/h: VGA text mode output (80x25, scrolling)keyboard.c/h: PS/2 keyboard input with scancode translationtimer.c/h: PIT timer for scheduling ticksResponsibilities:
Purpose: File system abstractions (future)
Key Components:
vfs.h: Virtual File System interface (placeholder)ramfs.c/h: RAM-based file system (future)Responsibilities:
Purpose: Process and thread management (future)
Key Components:
process.h: Process control blocks (placeholder)thread.h: Thread structures (future)scheduler.c/h: Process scheduler (future)Responsibilities:
Purpose: Shared type definitions and structures
Key Components:
types.h: Standard C types (uint32_t, size_t, etc.)multiboot.h: Multiboot specification structuresResponsibilities:
All subsystems follow a consistent initialization pattern:
void subsystem_init(void) {
// 1. Initialize internal state
// 2. Configure hardware (if applicable)
// 3. Register interrupt handlers (if applicable)
// 4. Enable operations
}
Each module exposes a minimal public interface:
// In header file: Public interface
void driver_init(void);
void driver_read(void *buffer, size_t size);
void driver_write(const void *buffer, size_t size);
// In C file: Internal implementation
static void internal_helper(void);
static int internal_state;
Hardware access is isolated to specific modules:
Application Code
↓
Driver API (console_write)
↓
Driver Implementation (drivers/console.c)
↓
Port I/O (arch/x86/ports.h)
↓
Hardware
module_name.cmodule_name.hmodule_name.S (capital S for preprocessor)module_function_name()
console_write(), pmm_alloc_page()internal_function_name()
terminal_scroll(), bitmap_set_bit()OPENOS_PATH_MODULE_HOPENOS_ARCH_X86_IDT_HOPENOS_DRIVERS_CONSOLE_HOPENOS_MEMORY_PMM_HCONSTANT_NAMEMODULE_CONSTANTVGA_WIDTH, PMM_PAGE_SIZE, PIC_EOIThe Makefile is organized by directory:
# Architecture objects
ARCH_OBJS = arch/x86/boot.o arch/x86/idt.o ...
# Kernel objects
KERNEL_OBJS = kernel/kernel.o kernel/panic.o
# Memory objects
MEMORY_OBJS = memory/pmm.o memory/vmm.o
# Driver objects
DRIVERS_OBJS = drivers/console.o drivers/keyboard.o ...
The build system provides include paths for all major directories:
CFLAGS += -I./include # Common headers
CFLAGS += -I./arch/x86 # Architecture headers
CFLAGS += -I./kernel # Kernel headers
CFLAGS += -I./memory # Memory headers
CFLAGS += -I./drivers # Driver headers
make all: Build the kernel binarymake clean: Remove build artifactsmake run: Build and run in QEMU (via ISO)make iso: Create bootable ISO imagemake run-vbox: Build and run in VirtualBoxmake help: Show available targetsSystem calls will be added in the kernel/ directory:
kernel/
├── syscall.c/h # System call dispatcher
├── syscall_table.c # System call table
└── syscall_handlers.c # System call implementations
Process scheduling will be added in kernel/ and process/:
kernel/
└── scheduler.c/h # Scheduler implementation
process/
├── process.c # Process management
└── context.S # Context switching
VFS will be fully implemented in fs/:
fs/
├── vfs.c/h # VFS core
├── ramfs.c/h # RAM-based FS
└── devfs.c/h # Device file system
Kernel2.0/
├── boot.S
├── kernel.c
├── idt.c/h
├── pic.c/h
├── isr.S/h
├── exceptions.c/h/S
├── pmm.c/h
├── vmm.c/h
├── keyboard.c/h
├── timer.c/h
└── linker.ld
Issues:
├── arch/x86/ # Hardware abstraction
├── kernel/ # Core kernel
├── memory/ # Memory management
├── drivers/ # Device drivers
├── fs/ # File systems
├── process/ # Process management
└── include/ # Common headers
Benefits:
This modular monolithic architecture provides OpenOS with a solid foundation for growth while maintaining the performance benefits of a monolithic kernel. The clear structure makes it easier for developers to understand, maintain, and extend the system.