https://www.ioccc.org/2018/mills/hint.text
I guess he doesn't know there is a running PDP-7 in Seattle About the Program ================= The program came about when I was looking for something to honor the pending 50th anniversary of the C language (because of the mercurial nature of IOCCC contest scheduling, I chose not to wait for the actual 50th anniversary). I had though of writing self-hosting compilers for a stripped-down version of C, or maybe even a version of the B language... At the same time, I was obsessed with the idea of allowing `mullender.c` from 1984 to run. Although that was still a possibility on an interpreted version of B or a stripped-down version of C, it felt cheap, as it would be `mullender.c` only in spirit. It was during this time that I discovered that in 2016, members of the Unix Heritage Society got access to [printouts of assembly-language source for the original version of UNIX] [7]. With what was a [huge amount of work] [8], they scanned in the printouts, fixed up the OCR translations, built assembler and file system tools from scratch and made an accurate simulation of Thompson's PDP-7 that allowed them to get the system up and running. Although source for the entire kernel and about half of the user-space commands were present (including the runtime and libraries for the B compiler), the remainder needed to be written from scratch, including the shell. The final results of the project are [available on github] [9]. None of this was remotely easy (as I was to discover myself). The PDP-7 is long gone, and the documentation for it is less complete than one would like. In addition, the devices attached for it were a bit of a mystery. The disk system is referenced only in an old price list. It was a RB09 fixed disk, probably made by Burroughs. It is close to what was called the RC10 for the PDP-10, but with a different interface. And the system also included a custom display device called Graphics-2, which had been built in-house by AT&T. It can't be completely ignored, because the kernel itself pokes at it (the UNIX crew used it as a second terminal -- a "glass TTY"). I decided that implementing this PDP-7 would be possible as an IOCCC entry. The emulator emulates the full machine: * PDP-7 Central Processor * Core Memeory Module Type 147 -- extends the core to 8,192 18-bit words * Extended Arithmetic Element Type 177 -- adds one's-complement multiplication, division and shifting * Real Time Clock * Teletype Model 33 KSR * Perforated Tape Reader Type 444 * RB09 Fixed Disk Controller The [PDP-7] [10] is an odd duck by modern computer standards: * 18 bit words, with no byte addressing. * Both one's and two's complement math (there is `ADD` for one's complement and `TAD` for two's complement). The EAE is entirely one's-complement. * "Microcoded" instructions. * Auto-increment memory locations. * Non-reentrant function calls (the return address is stored at the indicated address and the PC jumps to the location after it). * The `XCT` instruction, that executes the word loaded from memory as an instruction. * An instruction `LAW` that loads the instruction opcode into the accumulator. * Heavy use of "inline" operands. For instance the `MUL` instruction expects the second operand to be stored in memory after the instruction. This pretty much requires the use of self-modifying code. * No immediates. Almost all constants have to live in memory locations and be referenced by address. * Common operations, like "subtract" and "inclusive OR" are not directly supported on the machine and require multiple instructions and some spare memory locations to support. Being clever also helps. * Single accumulator architecture. No direct support for things like stacks. * I/O is done with dedicated I/O instructions (which are also microcoded). * The RB09 disk controller gets a special mention here because of its particularly annoying encoding of track and sector offsets in [packed BCD] [11]. A non-trivial amount of code space in the simulator is needed to convert into and out of BCD, along with an equivalent amount of code in the UNIX kernel itself. The simulation handles everything I was able to discover about the PDP-7, even things that the UNIX code itself doesn't use. For instance, it correctly implements the "trap mode" feature (a primitive form of supervisor mode) even though the kernel does not enable it. It also implements the microcoding of the EAE instructions even though the UNIX environment uses only the standard encodings. If you wanted to do a 11-bit multiply instead of an 18-bit one, it will probably work. The simulation starts by loading a boot program off of the virtualized paper tape, which is in a modified version of the RIM boot loader format. The RIM format encodes each 18-bit word as three six-bit characters, using one bit to denote the final word (which is executed directly and is usually a `JMP` or `HLT` instruction). The load address comes from the console address switches. Both of these are controlled by compile-time flags. The emulator continues emulating instructions until it sees a `HLT` instruction which will cause it to exit. Console I/O is emulated by setting the terminal into raw mode and polling via `read`. Line-clock ticks (at 60 Hz) are done by polling `gettimeofday`. Dynamic frequency code arranges to reduce the polling interval to a few polls per tick, so that simulation remains responsive. Since we use the real wall-clock time, this means that the emulated system will see time advance at the correct rate. Licencing Fun ------------- So now I have a system that can run UNIX v0. One problem remains... I don't have permission to submit UNIX v0 to the IOCCC. It is not my code and the copyright for it remains the property of whoever owns that part of what was once Bell Labs -- I believe it is Nokia at this point. I have worked around this problem in two ways: First, I didn't submit the source code or binary image for v0 UNIX as part of my IOCCC entry. I merely submitted a `Makefile` that can issue a `curl` command to fetch a prebuilt v0 disk image from the github repository. I am hoping this is considered part of "Legal abose of the rules" which is supposed to be "somewhat encouraged". As per RULE 12, I am justifying said abuse here, in the remarks file. Secondly, the choice to run the UNIX v0 code is optional. If you are worried about Nokia's lawyers running you to ground for running a 50-year old copy of a binary image for a machine that is almost completely nonexistant, you can just not do so. Delete the lines from the `Makefile` and sleep well. You still have two other UNIXes to play with. What about the other two UNIX variants? These are both covered by licences that allow me to use them. Back in 2002, Caldera International released Research Unix versions 1-7 and 32V under a [permissive BSD-like license] [12]. BSD UNIX is based off of v7 UNIX, and of course has its own permissive BSD licence. And in 2017, Nokia also released versions 8-10 under the condition that it will not assert copyright rights for non-commercial use. So the newer UNIXes are in the clear. I doubt anyone actually cares about version 0 either, but technically it's still under copyright. _______________________________________________ Simh mailing list Simh@trailing-edge.com http://mailman.trailing-edge.com/mailman/listinfo/simh