-
Notifications
You must be signed in to change notification settings - Fork 1
xv6 custom kernel development, referencing - https://pdos.csail.mit.edu/6.828/2024/xv6/book-riscv-rev4.pdf
License
kennykguo/xv6-kernel-dev
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix Version 6 (v6). xv6 loosely follows the structure and style of v6, but is implemented for a modern RISC-V multiprocessor using ANSI C. ACKNOWLEDGMENTS xv6 is inspired by John Lions's Commentary on UNIX 6th Edition (Peer to Peer Communications; ISBN: 1-57398-013-7; 1st edition (June 14, 2000)). See also https://pdos.csail.mit.edu/6.1810/, which provides pointers to on-line resources for v6. The following people have made contributions: Russ Cox (context switching, locking), Cliff Frey (MP), Xiao Yu (MP), Nickolai Zeldovich, and Austin Clements. We are also grateful for the bug reports and patches contributed by Takahiro Aoyagi, Marcelo Arroyo, Silas Boyd-Wickizer, Anton Burtsev, carlclone, Ian Chen, Dan Cross, Cody Cutler, Mike CAT, Tej Chajed, Asami Doi,Wenyang Duan, eyalz800, Nelson Elhage, Saar Ettinger, Alice Ferrazzi, Nathaniel Filardo, flespark, Peter Froehlich, Yakir Goaron, Shivam Handa, Matt Harvey, Bryan Henry, jaichenhengjie, Jim Huang, Matúš Jókay, John Jolly, Alexander Kapshuk, Anders Kaseorg, kehao95, Wolfgang Keller, Jungwoo Kim, Jonathan Kimmitt, Eddie Kohler, Vadim Kolontsov, Austin Liew, l0stman, Pavan Maddamsetti, Imbar Marinescu, Yandong Mao, Matan Shabtay, Hitoshi Mitake, Carmi Merimovich, Mark Morrissey, mtasm, Joel Nider, Hayato Ohhashi, OptimisticSide, phosphagos, Harry Porter, Greg Price, RayAndrew, Jude Rich, segfault, Ayan Shafqat, Eldar Sehayek, Yongming Shen, Fumiya Shigemitsu, snoire, Taojie, Cam Tenny, tyfkda, Warren Toomey, Stephen Tu, Alissa Tung, Rafael Ubal, Amane Uehara, Pablo Ventura, Xi Wang, WaheedHafez, Keiichi Watanabe, Lucas Wolf, Nicolas Wolovick, wxdao, Grant Wu, x653, Jindong Zhang, Icenowy Zheng, ZhUyU1997, and Zou Chang Wei. ERROR REPORTS Please send errors and suggestions to Frans Kaashoek and Robert Morris (kaashoek,rtm@mit.edu). The main purpose of xv6 is as a teaching operating system for MIT's 6.1810, so we are more interested in simplifications and clarifications than new features. BUILDING AND RUNNING XV6 You will need a RISC-V "newlib" tool chain from https://github.com/riscv/riscv-gnu-toolchain, and qemu compiled for riscv64-softmmu. Once they are installed, and in your shell search path, you can run "make qemu". Looking at xv6's current capabilities, here are some practical and educational features you could implement that would give you deep insight into kernel internals: Memory Management Extensions You could implement copy-on-write fork(), which is a fundamental optimization missing from xv6. Currently xv6 copies all parent pages immediately during fork - implementing COW would involve modifying the page fault handler to detect write attempts to shared pages and then perform the actual copy. This teaches you about memory management units, page table manipulation, and trap handling. Another valuable addition would be memory-mapped files through an mmap() system call. This requires understanding how virtual memory maps to file system blocks and implementing the page fault logic to load file data on demand. File System Improvements xv6's file system is quite basic - you could add symbolic links, which involves creating a new inode type and modifying path resolution logic throughout the kernel. Or implement a buffer cache with better replacement policies beyond the simple LRU currently used. Process Scheduling Enhancements The current round-robin scheduler could be extended with priority levels or completely replaced with a multi-level feedback queue scheduler. This would involve modifying the process structure to track priority/queue levels and implementing the scheduling logic in the timer interrupt handler. Inter-Process Communication Adding Unix pipes would be educational - this requires implementing a ring buffer data structure in kernel space, managing blocked reader/writer processes, and handling the pipe file descriptor semantics. Message queues or POSIX semaphores would be similar exercises in IPC primitives. System Call Extensions You could add useful system calls like getpid(), signal handling (kill/signal), or process groups. Each involves understanding the system call interface, trap handling, and process management data structures. Which of these areas interests you most? The implementation details vary significantly between each approach. ### Questions cpu0 should get 0 to 4096 still no here? # get this cpu's hardware thread id (hart id) # mhartid is a machine-mode csr (control status register) # csrr atomically reads the csr value into a general purpose register csrr a1, mhartid # add 1 to hart id so stack calculation works correctly # this ensures cpu 0 gets stack0[4096..8191], cpu 1 gets stack0[8192..12287], etc. addi a1, a1, 1 # multiply stack size by (hartid + 1) to get offset for this cpu mul a0, a0, a1 # set stack pointer to this cpu's stack area # now sp points to the top of this cpu's dedicated stack add sp, sp, a0 help me clean up and clean up grammar and make everything concise entry.S jumps here while running in machine mode after setting up stack, on all cpus this function configures the risc-v privilege system and jumps to supervisor mode - can you explain if all cores run this void start()
About
xv6 custom kernel development, referencing - https://pdos.csail.mit.edu/6.828/2024/xv6/book-riscv-rev4.pdf
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published