# mit-pdos/xv6-riscv architecture

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

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

## Overview

xv6 is a teaching Unix-like operating system for multiprocessor RISC-V. Its main user-to-result path is a user program or shell issuing system calls, the kernel dispatching those requests to process, memory, file, or device services, and results reaching the caller. The graph preserves these major runtime domains and the storage path. Several implementation links are dashed because the supplied excerpts do not show their calls; the file tree and README establish the product, not those specific connections.

Main entry points: [`kernel/fs.c`](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/fs.c) (Filesystem), [`kernel/syscall.c`](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/syscall.c) (Syscall API), [`kernel/trap.c`](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/trap.c) (Trap handling), [`kernel/sysfile.c`](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/sysfile.c) (File syscalls)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_userland["User programs"]
  node_user["User programs<br/>[user.h]"]
  node_shell["Shell<br/>[sh.c]"]
  node_init["Init<br/>[init.c]"]
  node_utilities["Utilities"]
end

subgraph group_entry["System entry"]
  node_api["Syscall API<br/>[syscall.c]"]
  node_dispatch["Trap handling<br/>[trap.c]"]
end

subgraph group_kernel["Kernel services"]
  node_sysfile["File syscalls<br/>[sysfile.c]"]
  node_sysproc["Process syscalls<br/>[sysproc.c]"]
  node_process["Processes<br/>[proc.c]"]
  node_exec["Program loading<br/>[exec.c]"]
  node_memory["Virtual memory<br/>[vm.c]"]
  node_files["Files and pipes<br/>[file.c]"]
end

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

node_actor(("User"))

node_actor -.->|"starts"| node_shell
node_actor -.->|"starts"| node_init
node_shell -.->|"requests"| node_api
node_init -.->|"requests"| node_api
node_user -.->|"requests"| node_api
node_utilities -.->|"requests"| node_api
node_api -.->|"enters"| node_dispatch
node_dispatch -.->|"dispatches"| node_sysfile
node_dispatch -.->|"dispatches"| node_sysproc
node_sysfile -.->|"uses"| node_files
node_sysfile -.->|"operates"| node_filesystem
node_sysproc -.->|"operates"| node_process
node_process -.->|"loads programs"| node_exec
node_exec -.->|"reads image"| node_filesystem
node_exec -.->|"maps image"| node_memory
node_process -.->|"manages address space"| node_memory
node_files -.->|"accesses"| node_filesystem
node_filesystem -.->|"logs updates"| node_journal
node_filesystem -.->|"uses blocks"| node_blockcache
node_blockcache -.->|"transfers blocks"| node_disk
node_dispatch -.->|"handles console I/O"| node_console

click node_user "https://github.com/mit-pdos/xv6-riscv/blob/riscv/user/user.h"
click node_shell "https://github.com/mit-pdos/xv6-riscv/blob/riscv/user/sh.c"
click node_init "https://github.com/mit-pdos/xv6-riscv/blob/riscv/user/init.c"
click node_utilities "https://github.com/mit-pdos/xv6-riscv/tree/riscv/user"
click node_api "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/syscall.c"
click node_dispatch "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/trap.c"
click node_sysfile "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/sysfile.c"
click node_sysproc "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/sysproc.c"
click node_process "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/proc.c"
click node_exec "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/exec.c"
click node_memory "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/vm.c"
click node_files "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/file.c"
click node_filesystem "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/fs.c"
click node_journal "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/log.c"
click node_blockcache "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/bio.c"
click node_disk "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/virtio_disk.c"
click node_console "https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/console.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_init,node_utilities,node_actor toneBlue
class node_api,node_dispatch toneAmber
class node_sysfile,node_sysproc,node_process,node_exec,node_memory,node_files toneMint
class node_filesystem,node_journal,node_blockcache,node_disk,node_console toneRose
```

## Components

### User programs

- [User programs](https://github.com/mit-pdos/xv6-riscv/blob/riscv/user/user.h): `user/user.h`
- [Shell](https://github.com/mit-pdos/xv6-riscv/blob/riscv/user/sh.c): `user/sh.c`
- [Init](https://github.com/mit-pdos/xv6-riscv/blob/riscv/user/init.c): `user/init.c`
- [Utilities](https://github.com/mit-pdos/xv6-riscv/tree/riscv/user): `user`

### System entry

- [Syscall API](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/syscall.c): `kernel/syscall.c`
- [Trap handling](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/trap.c): `kernel/trap.c`

### Kernel services

- [File syscalls](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/sysfile.c): `kernel/sysfile.c`
- [Process syscalls](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/sysproc.c): `kernel/sysproc.c`
- [Processes](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/proc.c): `kernel/proc.c`
- [Program loading](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/exec.c): `kernel/exec.c`
- [Virtual memory](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/vm.c): `kernel/vm.c`
- [Files and pipes](https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/file.c): `kernel/file.c`

### Storage and devices

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

### Other components

- **User**

## Connections

- User → Shell: starts
- User → Init: starts
- Shell → Syscall API: requests
- Init → Syscall API: requests
- User programs → Syscall API: requests
- Utilities → Syscall API: requests
- Syscall API → Trap handling: enters
- Trap handling → File syscalls: dispatches
- Trap handling → Process syscalls: dispatches
- File syscalls → Files and pipes: uses
- File syscalls → Filesystem: operates
- Process syscalls → Processes: operates
- Processes → Program loading: loads programs
- Program loading → Filesystem: reads image
- Program loading → Virtual memory: maps image
- Processes → Virtual memory: manages address space
- Files and pipes → Filesystem: accesses
- Filesystem → Filesystem log: logs updates
- Filesystem → Block cache: uses blocks
- Block cache → Virtio disk: transfers blocks
- Trap handling → Console I/O: handles console I/O
