# jack-d1/j-os architecture

> Architecture diagram of the GitHub repository jack-d1/j-os, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jack-d1/j-os
- Repository: https://github.com/jack-d1/j-os

## Overview

##### Main Components Identification
- Boot Loader & Initialization:
- Components include the boot-related assembly code found in the “boot” directory.
- It contains submodules for different modes (16-bit, protected mode) and tasks like disk loading and printing.

- CPU & Interrupt Handling:
- Files in the “cpu” directory (such as idt.c, isr.c, and timer functions) define interrupt handling, port interactions, and timer management.
- The “interrupt.asm” supports configuring the CPU to handle system interrupts.

- Kernel Core:
- The “kernel” directory (kernel.c, kernel_entry.asm) represents the core of the operating system that integrates various subsystems.

- Drivers:
- This includes the “drivers” directory where keyboard, mouse, and screen drivers handle hardware interactions.

- Standard Library Support (libc):
- Implements basic memory and string operations that are used throughout the OS.

##### Relationships and Interactions
- Boot Process Flow:
- Transition to boot/16bit code that prepares the system (loading disk sectors, printing initial messages, switching to protected mode).

- CPU & Interrupt Infrastructure:
- After the boot sequence, initialize CPU settings (GDT setup in gdt.asm) and register interrupt and exception handlers from the “cpu” folder.

- Kernel Initialization and Runtime:
- Once the CPU is configured, control is passed to the kernel (kernel_entry.asm to kernel.c).
- The kernel then interacts with the drivers (keyboard, mouse, screen) to manage I/O and with the libc for basic operations.

- Device Driver Integration:
- The drivers interact with both the kernel and directly with hardware ports (as seen in "cpu/ports.c").

##### Architectural Patterns and Design Principles
- Layered Architecture:
- The design is layered: Boot (lowest level) prepares the environment, followed by CPU and interrupt management, then the kernel integrating drivers and library calls.

- Modular Design:
- Each component (boot loader, CPU management, drivers, kernel, libc) is separated into its own directory, promoting clear boundaries and modular development.

##### Relevant Technologies and Frameworks
- Assembly Language:
- Used extensively in the boot process and startup (e.g., .asm files).

- C Programming:
- Employed for kernel logic, CPU management, and drivers.

- Basic OS Development Concepts:
- Bootstrapping, interrupt handling, and hardware abstraction.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Boot Loader & Initialization"
        B1["Boot Sector"]
        B2["16bit Boot"]
        B3["Disk Loader"]
        B4["GDT Setup"]
        B5["PM Switch"]
        B6["Print String"]
        B1 --> B2
        B2 --> B3
        B2 --> B4
        B2 --> B5
        B2 --> B6
    end

    subgraph "CPU & Interrupt Handling"
        C1["IDT Setup"]
        C2["Interrupt Config"]
        C3["ISR"]
        C4["Timer Management"]
        C5["Port Management"]
        C1 --> C2
        C2 --> C3
        C3 --> C4
        C4 --> C5
    end

    subgraph "Kernel Core"
        K1["Kernel Entry"]
        K2["Kernel Core"]
        K1 --> K2
    end

    subgraph "Drivers"
        D1["Keyboard Driver"]
        D2["Mouse Driver"]
        D3["Screen Driver"]
        K2 --> D1
        K2 --> D2
        K2 --> D3
        D1 --> K2
        D2 --> K2
        D3 --> K2
    end

    subgraph "Standard Library (libc)"
        L1["Memory Functions"]
        L2["String Functions"]
        K2 --> L1
        L1 --> L2
    end

    %% Inter-group connections
    B6 --> C1
    C5 --> K1

    %% Click Events
    click B1 "https://github.com/jack-d1/j-os/blob/master/boot/boot_sect.asm"
    click B2 "https://github.com/jack-d1/j-os/tree/master/boot/16bit/"
    click B3 "https://github.com/jack-d1/j-os/blob/master/boot/16bit/disk/disk_load.asm"
    click B4 "https://github.com/jack-d1/j-os/blob/master/boot/16bit/pm/gdt.asm"
    click B5 "https://github.com/jack-d1/j-os/blob/master/boot/16bit/pm/switch_to_pm.asm"
    click B6 "https://github.com/jack-d1/j-os/blob/master/boot/16bit/print/print_string.asm"
    click C1 "https://github.com/jack-d1/j-os/blob/master/cpu/idt.c"
    click C2 "https://github.com/jack-d1/j-os/blob/master/cpu/interrupt.asm"
    click C3 "https://github.com/jack-d1/j-os/blob/master/cpu/isr.c"
    click C4 "https://github.com/jack-d1/j-os/blob/master/cpu/timer.c"
    click C5 "https://github.com/jack-d1/j-os/blob/master/cpu/ports.c"
    click K1 "https://github.com/jack-d1/j-os/blob/master/kernel/kernel_entry.asm"
    click K2 "https://github.com/jack-d1/j-os/blob/master/kernel/kernel.c"
    click D1 "https://github.com/jack-d1/j-os/blob/master/drivers/keyboard.c"
    click D2 "https://github.com/jack-d1/j-os/blob/master/drivers/mouse.c"
    click D3 "https://github.com/jack-d1/j-os/blob/master/drivers/screen.c"
    click L1 "https://github.com/jack-d1/j-os/blob/master/libc/mem.c"
    click L2 "https://github.com/jack-d1/j-os/blob/master/libc/string.c"

    %% Styles
    classDef boot fill:#f9c74f,stroke:#000,stroke-width:2px;
    classDef cpu fill:#90be6d,stroke:#000,stroke-width:2px;
    classDef kernel fill:#f94144,stroke:#000,stroke-width:2px;
    classDef driver fill:#577590,stroke:#000,stroke-width:2px;
    classDef libc fill:#277da1,stroke:#000,stroke-width:2px;

    class B1,B2,B3,B4,B5,B6 boot;
    class C1,C2,C3,C4,C5 cpu;
    class K1,K2 kernel;
    class D1,D2,D3 driver;
    class L1,L2 libc;
```
