cg-tg-rcore-tutorial-ch8
cg-tg-rcore-tutorial-ch8 is a reproducible Rust learning crate built from the tg-rcore-tutorial chapter 8 experiment. It preserves the original chapter-8 teaching goals around threads, synchronization primitives, and deadlock detection, and it keeps the framebuffer / keyboard path that was later added for a user-mode DoomGeneric demo on QEMU.
This crate is prepared for two concrete use cases:
- learners reading and extending a non-trivial RISC-V teaching kernel
- TAs or instructors who need a crate that can be cloned, built, and run again with minimal hidden setup
Project Intro
The kernel starts from the standard chapter 8 structure:
Processis the shared resource containerThreadis the execution unit- blocking
Mutex,Semaphore, andCondvarsyscalls are wired into the scheduler - chapter exercise mode adds deadlock detection for mutexes and semaphores
The current experiment snapshot also includes:
- VirtIO GPU framebuffer support
- VirtIO keyboard input support
- user-space DoomGeneric porting glue
- easy-fs packing of
doom1.wadwhen a shareware WAD is available
Learning Goals
This crate is meant to help you learn and practice:
- the difference between process-as-resource-container and thread-as-execution-unit
- thread creation, join, and blocking state transitions
- kernel synchronization primitives in a teaching OS
- deadlock detection with wait-for graph and safety-check style reasoning
- framebuffer output and keyboard event delivery in a small RISC-V kernel
- how to port a user-space graphical program onto a teaching kernel
Features
- RISC-V64
no_stdkernel for QEMU virt - chapter 8 thread and synchronization support
- exercise-mode deadlock detection
- VirtIO block, GPU, and keyboard drivers
- integrated user app packaging through easy-fs
- bundled
tg-usersnapshot socargo clone && cargo rundoes not depend on a drifting external user crate - optional Doom shareware WAD auto-detection via
TG_DOOM_WAD
Project Structure
tg-rcore-tutorial-ch8/
├── .cargo/config.toml # target + QEMU runner
├── build.rs # builds user apps and packs fs.img
├── Cargo.toml # release metadata for crates.io
├── docs/reproduce.md # reproducible setup notes
├── exercise.md # chapter exercise description
├── report.md # implementation notes
├── tg-user/ # bundled user-space app snapshot with DoomGeneric support
├── Makefile # convenience wrappers
└── src/
├── main.rs # kernel init, trap loop, syscall dispatch
├── process.rs # Process / Thread split and deadlock state
├── processor.rs # scheduler-side thread management
├── fs.rs # file descriptor abstractions
├── virtio_block.rs # block device driver
├── virtio_gpu.rs # framebuffer support
└── virtio_input.rs # keyboard input support
Environment Requirements
- Rust stable
>= 1.85 - target
riscv64gc-unknown-none-elf - QEMU with
qemu-system-riscv64 - a C toolchain for bundled Doom support:
riscv64-unknown-elf-gccriscv64-unknown-elf-ar- picolibc for
riscv64-unknown-elf
- optional shareware WAD for Doom:
- set
TG_DOOM_WAD=/path/to/doom1.wad - or install
doom-wad-shareware
- set
Minimum Rust setup:
On macOS:
On Debian / Ubuntu:
Build And Run
Base chapter run:
Exercise mode:
Convenience wrappers:
After the kernel boots into Rust user shell, you can run normal chapter-8 user programs such as threads, sync_sem, and test_condvar. If a WAD has been packed into fs.img, you can also run:
doom
Reproduce
Option 1: clone from crates.io
Or:
Option 2: clone from git
Or:
Test And Validation
Base checker:
The test script forces a headless QEMU runner, so it works in CI or Docker environments without SDL / X11.
Exercise checker:
Both:
Example Output
Typical boot log:
[ INFO] .text ----> 0x80200000..0x8026xxxx
[ INFO] MMIO range -> 0x10001000..0x10002000
Rust user shell
>> threads
If Doom support is active, you should also see:
doom: framebuffer 1280x800 stride=5120 format=1
doom: first frame flushed
Version And Tag Mapping
- crate version:
0.0.0 - git tag:
v0.0.0
Release mapping:
v0.0.0 -> cg-tg-rcore-tutorial-ch8 0.0.0
Included Learning Documents
exercise.md: original chapter-8 exercise statementreport.md: implementation notes and debugging recorddocs/reproduce.md: reproducible setup checklist for reviewers
Notes
- this is a teaching kernel, not a production OS
cargo runuses the default graphical QEMU runner with VirtIO GPU + keyboard enabledbash ./test.sh ...overrides the runner to a headless serial-only QEMU command for automated checking- Doom is optional at build time; the kernel itself still runs without a WAD
- the bundled
tg-usersnapshot is included specifically so the published crate remains reproducible even when upstream user crates evolve