# rcore-os/rcore-tutorial-v3 architecture

> Architecture diagram of the GitHub repository rcore-os/rcore-tutorial-v3, 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/rcore-os/rcore-tutorial-v3
- Repository: https://github.com/rcore-os/rcore-tutorial-v3

## Overview

##### Main Components
- Bootloader: Represented by the “bootloader” directory and its associated binary. This component is responsible for the early initialization and transitioning control to the kernel.
- OS Kernel: The “os” directory contains the core of the operating system. Divide this into submodules including:
– Initialization and Bootstrapping (e.g., “entry.asm”, “main.rs”, “build.rs”)
– Memory Management (modules under “os/src/mm”, including frame allocator, heap allocator, page table management)
– Process and Task Management (subdirectories like “os/src/task” handling scheduling, task switching, context management)
– System Calls and Trap Handling (modules under “os/src/syscall” and “os/src/trap”)
– Device Drivers (organized in “os/src/drivers”: block devices, char devices, bus, GPU, input, network, and PLIC)
– Filesystem Support (components under “os/src/fs”) and integration with the easy-fs and easy-fs-fuse crates
– Synchronization primitives (found in “os/src/sync”) and logging components (“os/src/logging.rs”)
- User Space: The “user” directory contains user-level applications (shell, various demo binaries) that interact with the OS via system calls.
- File System Libraries: “easy-fs” and “easy-fs-fuse” provide filesystem functionality and likely interact with both the kernel and user-level processes.
- External Tools & Environment: Tools such as Qemu (for simulation) and possibly hardware (K210 boards) are targets for deployment. Also, there is a RustSBI (Supervisor Binary Interface) component used in bootloading.

##### Relationships and Interactions
- The Bootloader loads the OS Kernel into memory.
- The Kernel initializes its subsystems: memory management, device drivers, task management, file system, and system call interfaces.
- User applications (from the “user” directory) run on top of the Kernel and communicate via system calls.
- Filesystem libraries (easy-fs & easy-fs-fuse) interface with both kernel-level file system support and user-space applications.
- Device drivers facilitate I/O between the kernel and external hardware (or simulators such as Qemu).
- The system design should also indicate that debugging, logging, and testing are implemented (e.g., support for debug output through “os/src/logging.rs” and test workflows in .github/workflows).

##### Architectural Patterns
- Layered (or modular) design: clearly separated bootloader, kernel core (with subsystems), and user space
- Microkernel-style isolation may be implied by distinguishing kernel-level services (system calls, scheduling, memory management) from user-space applications
- Dependency injection and modular abstractions: showcases how device drivers and file systems are separate yet interrelated services

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Components
    Bootloader["Bootloader"]:::bootloaderClass

    %% OS Kernel Subsystem
    subgraph "OS Kernel"
        subgraph "Bootstrapping"
            Entry["entry.asm"]:::kernelClass
            Main["main.rs"]:::kernelClass
            Build["build.rs"]:::kernelClass
        end
        Memory["Memory Management"]:::kernelClass
        Process["Process Manager"]:::kernelClass
        Syscall["Syscall Handler"]:::kernelClass
        Trap["Trap Handler"]:::kernelClass
        Drivers["Driver Manager"]:::kernelClass
        FS["Filesystem Support"]:::kernelClass
        Sync["Sync & Logging"]:::kernelClass
    end

    %% User Space and Libraries
    User["User Space"]:::userClass
    EasyFS["easy-fs"]:::fsLibClass
    EasyFSFuse["easy-fs-fuse"]:::fsLibClass
    External["External Tools (Qemu/K210)"]:::externalClass

    %% Connections
    Bootloader -->|"loads"| Entry
    Entry -->|"initializes"| Main
    Main -->|"executes"| Build
    Build -->|"inits"| Memory
    Build -->|"inits"| Process
    Build -->|"inits"| Syscall
    Build -->|"inits"| Trap
    Build -->|"inits"| Drivers
    Build -->|"inits"| FS
    Build -->|"inits"| Sync

    User -->|"makes_syscalls"| Syscall
    User -->|"file_access"| FS

    FS -->|"uses"| EasyFS
    FS -->|"uses"| EasyFSFuse

    Drivers -->|"interfaces_with"| External

    %% Click Events
    click Bootloader "https://github.com/rcore-os/rcore-tutorial-v3/blob/main/bootloader/rustsbi-qemu.bin"
    click Entry "https://github.com/rcore-os/rcore-tutorial-v3/blob/main/os/src/entry.asm"
    click Main "https://github.com/rcore-os/rcore-tutorial-v3/blob/main/os/src/main.rs"
    click Build "https://github.com/rcore-os/rcore-tutorial-v3/blob/main/os/build.rs"
    click Memory "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/os/src/mm"
    click Process "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/os/src/task"
    click Syscall "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/os/src/syscall"
    click Trap "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/os/src/trap"
    click Drivers "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/os/src/drivers"
    click FS "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/os/src/fs"
    click Sync "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/os/src/sync"
    click User "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/user/"
    click EasyFS "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/easy-fs/"
    click EasyFSFuse "https://github.com/rcore-os/rcore-tutorial-v3/tree/main/easy-fs-fuse/"

    %% Styles
    classDef bootloaderClass fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef kernelClass fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef userClass fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef fsLibClass fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef externalClass fill:#FFB6C1,stroke:#333,stroke-width:2px;
```
