# knightmar/knightos architecture

> Architecture diagram of the GitHub repository knightmar/knightos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/knightmar/knightos
- Repository: https://github.com/knightmar/knightos

## Overview

KnightOS is a handcrafted x86 Rust kernel. Its documented workflow begins with a Multiboot boot, enters the kernel, initializes memory, interrupt hardware and task scheduling, then runs kernel tasks including graphics rendering; keyboard interrupts feed input into text state. The graph includes the documented boot capability, while source excerpts do not show the assembly-to-Rust handoff or how protected_main is reached, so those links are marked unverified. The README also documents cooperative scheduling, serial logging, memory management, graphics, text rendering and keyboard input.

Main entry points: [`src/kernel.rs`](https://github.com/knightmar/knightos/blob/master/src/kernel.rs) (Protected initialization), [`src/main.rs`](https://github.com/knightmar/knightos/blob/master/src/main.rs) (Kernel entry), [`src/user_interface/graphics/helper.rs`](https://github.com/knightmar/knightos/blob/master/src/user_interface/graphics/helper.rs) (Graphics renderer), [`src/user_interface/input/mod.rs`](https://github.com/knightmar/knightos/blob/master/src/user_interface/input/mod.rs) (Keyboard input)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_boot["Boot and kernel"]
  node_bootloader["Multiboot boot<br/>[boot.s]"]
  node_entry["Kernel entry<br/>[main.rs]"]
  node_kernel_init["Protected initialization<br/>[kernel.rs]"]
end

subgraph group_hardware["Hardware services"]
  node_gdt["GDT setup<br/>[gdt.rs]"]
  node_idt_pic["IDT and PIC<br/>[idt.rs]"]
  node_interrupts["Interrupt handlers<br/>[mod.rs]"]
  node_scheduler["Task scheduler<br/>[mod.rs]"]
  node_serial["Serial logging<br/>[mod.rs]"]
end

subgraph group_memory["Memory management"]
  node_paging["Paging<br/>[mod.rs]"]
  node_pmm["Physical allocator<br/>[pmm.rs]"]
  node_vmm["Virtual mapper<br/>[vmm.rs]"]
end

subgraph group_ui["User interface"]
  node_graphics["Graphics renderer<br/>[helper.rs]"]
  node_text["Text state and font<br/>[text.rs]"]
  node_keyboard["Keyboard input<br/>[mod.rs]"]
  node_key_translation["Key translation<br/>[utils.rs]"]
end

node_hardware_actor(("x86 hardware"))

node_bootloader -.->|"hands off"| node_entry
node_entry -->|"loads GDT"| node_gdt
node_entry -->|"initializes bitmap"| node_pmm
node_kernel_init -->|"initializes paging"| node_paging
node_kernel_init -->|"loads IDT, remaps PIC"| node_idt_pic
node_kernel_init -->|"creates tasks, starts"| node_scheduler
node_kernel_init -->|"schedules renderer"| node_graphics
node_interrupts -->|"switches task"| node_scheduler
node_interrupts -->|"dispatches scancode"| node_keyboard
node_keyboard -->|"translates scancode"| node_key_translation
node_keyboard -->|"adds character"| node_text
node_graphics -->|"maps framebuffer"| node_vmm
node_graphics -->|"looks up glyph"| node_text
node_pmm -->|"references directory"| node_paging
node_hardware_actor -.->|"raises interrupts"| node_interrupts

click node_bootloader "https://github.com/knightmar/knightos/blob/master/src/boot/boot.s"
click node_entry "https://github.com/knightmar/knightos/blob/master/src/main.rs"
click node_gdt "https://github.com/knightmar/knightos/blob/master/src/backend/descriptors/gdt.rs"
click node_kernel_init "https://github.com/knightmar/knightos/blob/master/src/kernel.rs"
click node_idt_pic "https://github.com/knightmar/knightos/blob/master/src/backend/descriptors/idt.rs"
click node_interrupts "https://github.com/knightmar/knightos/blob/master/src/backend/interrupts/mod.rs"
click node_scheduler "https://github.com/knightmar/knightos/blob/master/src/backend/multitasking/mod.rs"
click node_serial "https://github.com/knightmar/knightos/blob/master/src/backend/serial/mod.rs"
click node_paging "https://github.com/knightmar/knightos/blob/master/src/backend/paging/mod.rs"
click node_pmm "https://github.com/knightmar/knightos/blob/master/src/backend/memory/pmm.rs"
click node_vmm "https://github.com/knightmar/knightos/blob/master/src/backend/memory/vmm.rs"
click node_graphics "https://github.com/knightmar/knightos/blob/master/src/user_interface/graphics/helper.rs"
click node_text "https://github.com/knightmar/knightos/blob/master/src/user_interface/graphics/text.rs"
click node_keyboard "https://github.com/knightmar/knightos/blob/master/src/user_interface/input/mod.rs"
click node_key_translation "https://github.com/knightmar/knightos/blob/master/src/user_interface/utils.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bootloader,node_entry,node_kernel_init toneBlue
class node_gdt,node_idt_pic,node_interrupts,node_scheduler,node_serial toneAmber
class node_paging,node_pmm,node_vmm toneMint
class node_graphics,node_text,node_keyboard,node_key_translation toneRose
class node_hardware_actor toneIndigo
```

## Components

### Boot and kernel

- [Multiboot boot](https://github.com/knightmar/knightos/blob/master/src/boot/boot.s): `src/boot/boot.s`
- [Kernel entry](https://github.com/knightmar/knightos/blob/master/src/main.rs): `src/main.rs`
- [Protected initialization](https://github.com/knightmar/knightos/blob/master/src/kernel.rs): `src/kernel.rs`

### Hardware services

- [GDT setup](https://github.com/knightmar/knightos/blob/master/src/backend/descriptors/gdt.rs): `src/backend/descriptors/gdt.rs`
- [IDT and PIC](https://github.com/knightmar/knightos/blob/master/src/backend/descriptors/idt.rs): `src/backend/descriptors/idt.rs`
- [Interrupt handlers](https://github.com/knightmar/knightos/blob/master/src/backend/interrupts/mod.rs): `src/backend/interrupts/mod.rs`
- [Task scheduler](https://github.com/knightmar/knightos/blob/master/src/backend/multitasking/mod.rs): `src/backend/multitasking/mod.rs`
- [Serial logging](https://github.com/knightmar/knightos/blob/master/src/backend/serial/mod.rs): `src/backend/serial/mod.rs`

### Memory management

- [Paging](https://github.com/knightmar/knightos/blob/master/src/backend/paging/mod.rs): `src/backend/paging/mod.rs`
- [Physical allocator](https://github.com/knightmar/knightos/blob/master/src/backend/memory/pmm.rs): `src/backend/memory/pmm.rs`
- [Virtual mapper](https://github.com/knightmar/knightos/blob/master/src/backend/memory/vmm.rs): `src/backend/memory/vmm.rs`

### User interface

- [Graphics renderer](https://github.com/knightmar/knightos/blob/master/src/user_interface/graphics/helper.rs): `src/user_interface/graphics/helper.rs`
- [Text state and font](https://github.com/knightmar/knightos/blob/master/src/user_interface/graphics/text.rs): `src/user_interface/graphics/text.rs`
- [Keyboard input](https://github.com/knightmar/knightos/blob/master/src/user_interface/input/mod.rs): `src/user_interface/input/mod.rs`
- [Key translation](https://github.com/knightmar/knightos/blob/master/src/user_interface/utils.rs): `src/user_interface/utils.rs`

### Other components

- **x86 hardware**

## Connections

- Multiboot boot → Kernel entry: hands off
- Kernel entry → GDT setup: loads GDT (evidence: `src/main.rs`)
- Kernel entry → Physical allocator: initializes bitmap (evidence: `src/main.rs`)
- Protected initialization → Paging: initializes paging (evidence: `src/kernel.rs`)
- Protected initialization → IDT and PIC: loads IDT, remaps PIC (evidence: `src/kernel.rs`)
- Protected initialization → Task scheduler: creates tasks, starts (evidence: `src/kernel.rs`)
- Protected initialization → Graphics renderer: schedules renderer (evidence: `src/kernel.rs`)
- Interrupt handlers → Task scheduler: switches task (evidence: `src/backend/interrupts/mod.rs`)
- Interrupt handlers → Keyboard input: dispatches scancode (evidence: `src/backend/interrupts/mod.rs`)
- Keyboard input → Key translation: translates scancode (evidence: `src/user_interface/input/mod.rs`)
- Keyboard input → Text state and font: adds character (evidence: `src/user_interface/input/mod.rs`)
- Graphics renderer → Virtual mapper: maps framebuffer (evidence: `src/user_interface/graphics/helper.rs`)
- Graphics renderer → Text state and font: looks up glyph (evidence: `src/user_interface/graphics/helper.rs`)
- Physical allocator → Paging: references directory (evidence: `src/backend/memory/pmm.rs`)
- x86 hardware → Interrupt handlers: raises interrupts
