My-Operating-System-OpenOS

OpenOS Architecture

Overview

OpenOS is a 32-bit x86 educational operating system kernel designed to demonstrate fundamental OS concepts. It runs in protected mode and provides a minimal but functional interrupt-driven system with keyboard support.

System Architecture

Boot Process

  1. GRUB/Multiboot Loader
    • The system boots using a Multiboot-compliant bootloader (GRUB or QEMU direct kernel loading)
    • The Multiboot header is located in boot.S
  2. Entry Point (_start in boot.S)
    • Sets up a 16KB kernel stack
    • Calls the C kernel entry point kmain()
  3. Kernel Initialization (kmain in kernel.c)
    • Initializes VGA text mode terminal
    • Sets up Interrupt Descriptor Table (IDT)
    • Configures Programmable Interrupt Controller (PIC)
    • Installs keyboard interrupt handler
    • Enables hardware interrupts
    • Enters interactive shell loop

Memory Layout

Physical Memory Map:
┌──────────────────────┬─────────────┐
│ 0x00000000           │ BIOS/IVT    │
├──────────────────────┼─────────────┤
│ 0x00007C00           │ Bootloader  │
├──────────────────────┼─────────────┤
│ 0x00100000 (1 MiB)   │ Kernel      │
│  - .multiboot        │ Multiboot   │
│  - .text             │ Code        │
│  - .rodata           │ Read-only   │
│  - .data             │ Data        │
│  - .bss              │ BSS         │
│  - Stack (16KB)      │ Stack       │
└──────────────────────┴─────────────┘

Segmentation

OpenOS uses a flat memory model with the following GDT segments:

Interrupt Handling

Interrupt Descriptor Table (IDT)

Programmable Interrupt Controller (PIC)

The 8259A PIC is configured as follows:

This remapping avoids conflicts with CPU exceptions (0x00-0x1F).

IRQ Assignments:

Interrupt Flow

Hardware Event (e.g., key press)
    ↓
PIC receives signal on IRQ1
    ↓
PIC sends interrupt to CPU (vector 0x21)
    ↓
CPU looks up handler in IDT[0x21]
    ↓
CPU pushes state and jumps to irq1_handler (isr.S)
    ↓
irq1_handler saves registers
    ↓
irq1_handler calls keyboard_handler() in C
    ↓
keyboard_handler reads scancode, processes key
    ↓
keyboard_handler sends EOI to PIC
    ↓
irq1_handler restores registers
    ↓
iret instruction returns to interrupted code

Component Details

VGA Text Mode Terminal

Keyboard Driver

Components:

Features:

State Tracking:

Interactive Shell

A simple command prompt that:

  1. Displays “OpenOS> “ prompt
  2. Accepts keyboard input
  3. Echoes back the typed line
  4. Ready for command parsing (future enhancement)

Current Limitations

Future Architecture Plans

See roadmap.md for planned enhancements:

  1. Exception handlers for page faults, GPF, etc.
  2. Timer interrupt and scheduling
  3. Physical memory management
  4. Virtual memory with paging
  5. Process abstraction and multitasking
  6. System calls for user-mode programs
  7. Basic filesystem support

Building Blocks

Core Files

File Purpose
boot.S Multiboot header and entry point
kernel.c Main kernel logic and VGA terminal
idt.c/h Interrupt descriptor table management
pic.c/h PIC initialization and EOI handling
isr.S/h Assembly interrupt service routines
keyboard.c/h Keyboard driver implementation
linker.ld Linker script for memory layout

Compilation

The kernel is compiled with:

References