Reading Code / 2026 Jul 13 -------------------------- In February I picked up a ThinkCentre M700 Tiny for $120 on Ebay to run NetBSD. It's been eye-opening to see what a 10-year-old computer can do if you're a bit more discerning about the software you run. While it won't become my only desktop anytime soon, the more time I spend tweaking it, the more I find myself using it with pleasure everyday. Reading through The Design and Implementation of the 4.4BSD Operating System got me very excited to learn more about the details around operating system implementation. So why not just read the NetBSD sources? I don't really know anything about operating system kernels and my understanding of C is rusty, to put it generously. But I've spent two decades dealing with web technologies, it can't be any worse than that! NetBSD has a great guide about getting the current development branch via CVS. This can take a while if you get everything, for the purpose of reading the essential parts of the operating system I decided I only needed `src/sys`: cvs checkout -A -P src/sys The NetBSD source code follows some fairly strict style conventions, including tabs instead of spaces and an 80 column limit. I wrote the following to make browsing and editing C sources from Emacs more comfortable: (defun my/c-mode-setup () (when (buffer-file-name) (whitespace-mode) (display-line-numbers-mode) (display-fill-column-indicator-mode) (setq-local display-fill-column-indicator ?│) (indent-tabs-mode) (flycheck-mode))) (use-package c-mode :hook (c-mode . my/c-mode-setup)) (use-package xcscope :ensure t :defer t :hook (c-mode . cscope-minor-mode)) At some point I can across cscope which which seemed useful for reading a C code base. The `xcscope` package exposes an Emacs interface that makes it easy to find the definition of a symbol, its references, and produces links that can be jumped to. One useful command I learned along the way that I don't recall encountering in 20+ years of using Emacs is `M-x ffap` - find file at point, useful for jumping to includes. I started off by scanning `src/sys/kern/init_main.c` and jotting down notes here and there. I'm sure I will read this file many times. This got me looking around on the web for more pointers on how to study a BSD implementation, and so I found the FreeBSD Architecture Handbook. It seems like there's enough common ground here to still be a useful accompanying text. I've also bookmarked the Dr. Dobbs Journal article starting in 1991 on porting BSD to 386.