# fdos/kernel architecture

> Architecture diagram of the GitHub repository fdos/kernel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fdos/kernel
- Repository: https://github.com/fdos/kernel

## Overview

##### Main Components
- Boot Loader: Represented in the “boot” directory (and supplemented by files in “bin” and “test/bootimg”). This component is responsible for bootstrapping the system. Include elements such as “boot.asm”, “oemboot.asm”, and the makefile in this directory.
- Kernel Core: The “kernel” folder contains most of the core operating system routines. Show subcomponents like:
- Basic initialization (e.g., “entry.asm”, “initdisk.c”, “initclk.c”)
- Memory management (e.g., “memmgr.c”, “memdisk.asm”)
- Process and task management (e.g., “task.c”, “procsupt.asm”)
- DOS services (e.g., “dosfns.c”, “execrh.asm”, “fatfs.c”)
- Device and I/O handling (e.g., “io.asm”, “chario.c”, “serial.asm”)
- Network and other system functions (e.g., “network.c”)
- Drivers: The “drivers” directory includes low-level drivers (like the floppy and clock drivers). This indicates separate modules interacting with the hardware.
- Header Files and Configurations: The “hdr” directory has many header files defining the structures and interfaces (like “file.h”, “device.h”, “version.h”), which are essential for inter-module communications.
- Utility & Build System: Directories like “lib”, “mkfiles”, “utils” and files such as “makefile”, “build.bat”, and “ci_build.sh” are present for building, configuration, and support tasks.
- Documentation & Test Suites: “docs”, “test”, and “tests” directories contain documentation, history, bug notes, and test programs which can show how the components are intended to function together.

##### Architectural Patterns and Design Principles
- Layered Architecture: Show a layered stack – hardware at the bottom, then drivers, followed by the kernel core, and finally utilities and higher-level DOS functions. This adds clarity to the separation of concerns.
- Build and CI Integration: Given the presence of CI scripts (.sh and bat files) and various makefiles, include a “Build/CI Environment” element that feeds into all components, highlighting automated builds and tests.

##### Specific Elements
- Each major folder (Boot, Kernel, Drivers, Lib/Utilities, Docs/Tests) represented as a block.
- For each block, add internal submodules (for example, under “Kernel Core”, indicate “Initialization”, “Memory Management”, “Task Management”, “I/O and File Systems”, “Networking”).
- Boot Loader → Kernel Core (handover control)
- Kernel Core ↔ Drivers (interrupts and I/O requests)
- Build/CI Tools → All Components (for automated builds and testing)

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Boot Loader Subgraph
    subgraph "Boot Loader"
        direction TB
        BL1("boot.asm"):::boot
        BL2("oemboot.asm"):::boot
        BL3("makefile"):::boot
        BL4("autoexec.bat"):::boot
        BL5("a.asm"):::boot
        BL6("bootimg.asm"):::boot
    end

    %% Kernel Core Subgraph
    subgraph "Kernel Core"
        direction TB
        KC1("Basic Initialization"):::kernel
        KC2("Memory Management"):::kernel
        KC3("Process & Task Management"):::kernel
        KC4("DOS Services"):::kernel
        KC5("Device & I/O Handling"):::kernel
        KC6("Networking"):::kernel
    end

    %% Drivers Subgraph
    subgraph "Drivers"
        direction TB
        D1("floppy.asm"):::drivers
        D2("rdpcclk.asm"):::drivers
        D3("wratclk.asm"):::drivers
        D4("wrpcclk.asm"):::drivers
        D5("makefile"):::drivers
    end

    %% Build/CI & Utilities Subgraph
    subgraph "Build/CI & Utilities"
        direction TB
        U1("Top-level makefile"):::build
        U2("build.bat"):::build
        U3("buildall.bat"):::build
        U4("ci_build.sh"):::build
        U5("mkfiles: generic.mak"):::build
        U6("lib: makefile"):::build
        U7("utils: makefile"):::build
        U8("exeflat.c"):::build
    end

    %% Header Files & Configurations Subgraph
    subgraph "Header Files & Configurations"
        direction TB
        H1("file.h"):::header
        H2("device.h"):::header
        H3("version.h"):::header
    end

    %% Documentation & Testing Subgraph
    subgraph "Documentation & Testing"
        direction TB
        Doc1("docs/readme.txt"):::docs
        Doc2("docs/intfns.txt"):::docs
        Doc3("docs/history.txt"):::docs
        T1("tests: absread"):::docs
        T2("tests: opendev"):::docs
        T3("test suite"):::docs
    end

    %% Main Connections
    %% Boot process: Boot Loader hands off to Kernel Core
    BL1 -->|"handover"| KC1

    %% Kernel Core and Drivers interaction (bidirectional for I/O and interrupts)
    KC1 -->|"I/O_requests"| D1
    D1 -->|"interrupts"| KC1

    %% Kernel Core uses Header Files as Interface
    KC1 -->|"API_calls"| H1

    %% Build/CI & Utilities influence all main components
    U1 --> BL1
    U1 --> KC1
    U1 --> D1
    U1 --> H1

    %% Documentation & Testing supports components (dotted lines)
    BL1 ---|"tests"| Doc1
    KC1 ---|"tests"| Doc1
    D1 ---|"tests"| Doc1
    H1 ---|"tests"| Doc1

    %% Style Definitions
    classDef boot fill:#ffcccc,stroke:#660000,stroke-width:2px;
    classDef kernel fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef drivers fill:#ccccff,stroke:#000066,stroke-width:2px;
    classDef build fill:#fff2cc,stroke:#996600,stroke-width:2px;
    classDef header fill:#ffe6e6,stroke:#990000,stroke-width:2px;
    classDef docs fill:#e0e0e0,stroke:#666666,stroke-width:2px;

    %% Click Events for Boot Loader
    click BL1 "https://github.com/fdos/kernel/blob/master/boot/boot.asm"
    click BL2 "https://github.com/fdos/kernel/blob/master/boot/oemboot.asm"
    click BL3 "https://github.com/fdos/kernel/tree/master/boot/makefile"
    click BL4 "https://github.com/fdos/kernel/blob/master/bin/autoexec.bat"
    click BL5 "https://github.com/fdos/kernel/blob/master/test/bootimg/a.asm"
    click BL6 "https://github.com/fdos/kernel/blob/master/test/bootimg/bootimg.asm"

    %% Click Events for Kernel Core
    click KC1 "https://github.com/fdos/kernel/blob/master/kernel/entry.asm"
    click KC2 "https://github.com/fdos/kernel/blob/master/kernel/memmgr.c"
    click KC3 "https://github.com/fdos/kernel/blob/master/kernel/task.c"
    click KC4 "https://github.com/fdos/kernel/blob/master/kernel/dosfns.c"
    click KC5 "https://github.com/fdos/kernel/blob/master/kernel/io.asm"
    click KC6 "https://github.com/fdos/kernel/blob/master/kernel/network.c"

    %% Click Events for Drivers
    click D1 "https://github.com/fdos/kernel/blob/master/drivers/floppy.asm"
    click D2 "https://github.com/fdos/kernel/blob/master/drivers/rdpcclk.asm"
    click D3 "https://github.com/fdos/kernel/blob/master/drivers/wratclk.asm"
    click D4 "https://github.com/fdos/kernel/blob/master/drivers/wrpcclk.asm"
    click D5 "https://github.com/fdos/kernel/tree/master/drivers/makefile"

    %% Click Events for Header Files & Configurations
    click H1 "https://github.com/fdos/kernel/blob/master/hdr/file.h"
    click H2 "https://github.com/fdos/kernel/blob/master/hdr/device.h"
    click H3 "https://github.com/fdos/kernel/blob/master/hdr/version.h"

    %% Click Events for Build/CI & Utilities
    click U1 "https://github.com/fdos/kernel/tree/master/makefile"
    click U2 "https://github.com/fdos/kernel/blob/master/build.bat"
    click U3 "https://github.com/fdos/kernel/blob/master/buildall.bat"
    click U4 "https://github.com/fdos/kernel/blob/master/ci_build.sh"
    click U5 "https://github.com/fdos/kernel/blob/master/mkfiles/generic.mak"
    click U6 "https://github.com/fdos/kernel/tree/master/lib/makefile"
    click U7 "https://github.com/fdos/kernel/tree/master/utils/makefile"
    click U8 "https://github.com/fdos/kernel/blob/master/utils/exeflat.c"

    %% Click Events for Documentation & Testing
    click Doc1 "https://github.com/fdos/kernel/blob/master/docs/readme.txt"
    click Doc2 "https://github.com/fdos/kernel/blob/master/docs/intfns.txt"
    click Doc3 "https://github.com/fdos/kernel/blob/master/docs/history.txt"
    click T1 "https://github.com/fdos/kernel/tree/master/tests/absread"
    click T2 "https://github.com/fdos/kernel/tree/master/tests/opendev"
    click T3 "https://github.com/fdos/kernel/tree/master/test/"
```
