An Explainer on Unix’s Most Notorious Code Comment
thenewstack.io
thenewstack.io
(EDIT: I was wrong about v7 save/resume at first)
Note that Lions doesn't explain this either, he assumed that the difficulty was with with u_rsav and u_ssav, but those are still in v7 with the comment gone (he probably wasn't that wrong though, it really is confusing, but it's just not what the comment refers to)
However, the machine itself doesn't have any real notion of "call" and "return", and although dedicated instructions may be provided for convenience, all a call amounts to is "remember where in the code you were, and go somewhere else" and return is "use the saved information to go back".
It then follows that, if this saved information be not precisely that of the immediately preceding call, the processor can be caused to "return" somewhere else; and that is the basis of coroutines and process switching. Call and return are simply a convenient abstraction atop the sequential instruction stream the processor executes.
The classic make-your-own-game engines ZZT and MegaZeux had a lot of this; the scripts for in-game objects had no function calls or well-managed events, just GOTOs and per-object vars, and could get interrupted at any time by GOTOs triggered by other in-game objects.
So, basically, assembler without a lot of fancy macros? :)
Essentially this was the days before save/restore were in the C library - savu/aretu are an equivalent that works differently (you savu() somewhere and aretu() somewhere else, it was sad because aretu() played stack games so unlike save() savu() didn't just return a different value on return)
Essentially v6 was a swapping system, fork() (or newproc() in the kernel) worked by allocating memory and making a copy of an app in memory, if there wasn't enough memory it would pretend to swap out the existing process, then mark it as the new process and set a flag (SSWAP), this is the case when it's returning - a process is being swapped in, part way through it realises it's really this special case and this code returns into newproc() as the new process
For further edification, the entire 9h Systems We Love live stream is up on youtube at https://www.youtube.com/watch?v=TPe6UXMDMGM or split into videos and via Vimeo at http://systemswe.love/videos
https://github.com/dspinellis/unix-history-repo/blob/Researc...
has anyone perused it? 9k is tiny.. is there any value, either direct or extrapolated, in lending it the mindshare?
xv6 (https://en.wikipedia.org/wiki/Xv6) is a modern (x86/ANSI C) but similarly sized kernel designed for teaching purposes and to avoid the awkward obsolete-architecture-and-compiler aspects of the original 6th Ed code. If you can live with the PDP-11 assembly and ancient C (and not being able to run the code) I'd recommend the original, though.
http://www.c-c-g.de/attachments/article/211/lions_book_comme...
https://books.google.com/books?id=n3vVBwAAQBAJ&pg=PA429&lpg=...
which gives credence to the original story that it was part of an interrupted prinout.