# nnbx2k1/xv6-riscv architecture

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

- Interactive diagram: https://gitdiagram.com/nnbx2k1/xv6-riscv
- Repository: https://github.com/nnbx2k1/xv6-riscv

## Overview

xv6 is a teaching Unix-like operating system for multiprocessor RISC-V. Its principal workflow is a user program making system calls, which the kernel dispatches to process, memory, file, or device services; results return to the program. The tree also shows a command shell, filesystem utilities, and user-space tests. The excerpts and index establish the major modules, but provide little call-site detail, so most runtime links are dashed and unverified rather than asserted as direct calls.

Main entry points: [`kernel/syscall.c`](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/syscall.c) (System call dispatch), [`kernel/exec.c`](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/exec.c) (Program loading), [`kernel/fs.c`](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/fs.c) (Filesystem), [`kernel/bio.c`](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/bio.c) (Block cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_userland["User environment"]
  node_user["User program<br/>[user.h]"]
  node_shell["Command shell<br/>[sh.c]"]
  node_userlib["User library<br/>[ulib.c]"]
  node_usertests["User tests<br/>[usertests.c]"]
end

subgraph group_kernel["Kernel services"]
  node_syscall["System call dispatch<br/>[syscall.c]"]
  node_sysfile["File syscalls<br/>[sysfile.c]"]
  node_exec["Program loading<br/>[exec.c]"]
  node_process["Process scheduler<br/>[proc.c]"]
  node_memory["Virtual memory<br/>[vm.c]"]
  node_trap["Trap handling<br/>[trap.c]"]
  node_interfaces["Kernel interfaces<br/>[defs.h]"]
end

subgraph group_storage["Storage and devices"]
  node_fileio["File objects<br/>[file.c]"]
  node_filesystem[("Filesystem<br/>[fs.c]")]
  node_blockcache["Block cache<br/>[bio.c]"]
  node_journal["Filesystem journal<br/>[log.c]"]
  node_disk["Virtio disk<br/>[virtio_disk.c]"]
  node_console["Console I/O<br/>[console.c]"]
end

subgraph group_arch["RISC-V platform"]
  node_boot["Kernel startup<br/>[main.c]"]
  node_riscv["RISC-V control<br/>[riscv.h]"]
  node_plic["Interrupt controller<br/>[plic.c]"]
end

node_actor(("User"))

node_actor -.->|"starts commands"| node_shell
node_shell -.->|"uses library"| node_userlib
node_user -.->|"requests services"| node_syscall
node_usertests -.->|"exercises calls"| node_syscall
node_syscall -.->|"dispatches file calls"| node_sysfile
node_syscall -.->|"dispatches process calls"| node_process
node_syscall -.->|"dispatches exec"| node_exec
node_sysfile -.->|"uses file objects"| node_fileio
node_fileio -.->|"accesses files"| node_filesystem
node_filesystem -.->|"reads blocks"| node_blockcache
node_journal -.->|"journals blocks"| node_blockcache
node_blockcache -.->|"transfers blocks"| node_disk
node_exec -.->|"loads executable"| node_filesystem
node_exec -.->|"builds address space"| node_memory
node_process -.->|"manages address spaces"| node_memory
node_trap -.->|"handles user traps"| node_syscall
node_console -.->|"receives interrupts"| node_plic
node_boot -.->|"configures platform"| node_riscv

click node_user "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/user/user.h"
click node_shell "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/user/sh.c"
click node_userlib "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/user/ulib.c"
click node_usertests "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/user/usertests.c"
click node_syscall "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/syscall.c"
click node_sysfile "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/sysfile.c"
click node_exec "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/exec.c"
click node_process "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/proc.c"
click node_memory "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/vm.c"
click node_trap "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/trap.c"
click node_interfaces "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/defs.h"
click node_fileio "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/file.c"
click node_filesystem "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/fs.c"
click node_blockcache "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/bio.c"
click node_journal "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/log.c"
click node_disk "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/virtio_disk.c"
click node_console "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/console.c"
click node_boot "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/main.c"
click node_riscv "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/riscv.h"
click node_plic "https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/plic.c"

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_user,node_shell,node_userlib,node_usertests,node_actor toneBlue
class node_syscall,node_sysfile,node_exec,node_process,node_memory,node_trap,node_interfaces toneAmber
class node_fileio,node_filesystem,node_blockcache,node_journal,node_disk,node_console toneMint
class node_boot,node_riscv,node_plic toneRose
```

## Components

### User environment

- [User program](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/user/user.h): `user/user.h`
- [Command shell](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/user/sh.c): `user/sh.c`
- [User library](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/user/ulib.c): `user/ulib.c`
- [User tests](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/user/usertests.c): `user/usertests.c`

### Kernel services

- [System call dispatch](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/syscall.c): `kernel/syscall.c`
- [File syscalls](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/sysfile.c): `kernel/sysfile.c`
- [Program loading](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/exec.c): `kernel/exec.c`
- [Process scheduler](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/proc.c): `kernel/proc.c`
- [Virtual memory](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/vm.c): `kernel/vm.c`
- [Trap handling](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/trap.c): `kernel/trap.c`
- [Kernel interfaces](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/defs.h): `kernel/defs.h`

### Storage and devices

- [File objects](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/file.c): `kernel/file.c`
- [Filesystem](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/fs.c): `kernel/fs.c`
- [Block cache](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/bio.c): `kernel/bio.c`
- [Filesystem journal](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/log.c): `kernel/log.c`
- [Virtio disk](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/virtio_disk.c): `kernel/virtio_disk.c`
- [Console I/O](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/console.c): `kernel/console.c`

### RISC-V platform

- [Kernel startup](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/main.c): `kernel/main.c`
- [RISC-V control](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/riscv.h): `kernel/riscv.h`
- [Interrupt controller](https://github.com/nnbx2k1/xv6-riscv/blob/riscv/kernel/plic.c): `kernel/plic.c`

### Other components

- **User**

## Connections

- User → Command shell: starts commands (evidence: `README`)
- Command shell → User library: uses library
- User program → System call dispatch: requests services
- User tests → System call dispatch: exercises calls
- System call dispatch → File syscalls: dispatches file calls
- System call dispatch → Process scheduler: dispatches process calls
- System call dispatch → Program loading: dispatches exec
- File syscalls → File objects: uses file objects (evidence: `kernel/sysfile.c`)
- File objects → Filesystem: accesses files
- Filesystem → Block cache: reads blocks (evidence: `kernel/fs.c`)
- Filesystem journal → Block cache: journals blocks (evidence: `kernel/log.c`)
- Block cache → Virtio disk: transfers blocks (evidence: `kernel/virtio_disk.c`)
- Program loading → Filesystem: loads executable (evidence: `kernel/exec.c`)
- Program loading → Virtual memory: builds address space (evidence: `kernel/exec.c`)
- Process scheduler → Virtual memory: manages address spaces (evidence: `kernel/proc.c`)
- Trap handling → System call dispatch: handles user traps
- Console I/O → Interrupt controller: receives interrupts
- Kernel startup → RISC-V control: configures platform (evidence: `kernel/main.c`)
