He's at a it again...booting Linux on an actual 4004

I see there is an old thread about Dmitry’s efforts, but this time he’s really outdone himself. Very nice writeup too.

3 Likes

Exercise left for the reader: port the MIPS emulator from the Intel 4004
to the DEC PDP-8. (To make things easy on yourself, you are allowed to
forgo actual PDP-8 hardware and just use your favorite PDP-8 emulator.
SimH is probably the easiest choice; but ultimately, something like Bernhard
Baehr’s blinkenlights emulator – sorry, Mac only! – would be more
spectacular.)

;->

Are you allowed to use the later memory extension for the PDP 8-E KT8-A, 128K words?
8 bit bytes and 12 bit words are a odd mix. Perhaps a better idea is a PDP 10 emulated
instead. The PDP 10 I think had a PDP 8 emulator, shades of infinite recursion, :slight_smile:
Ben.

Perhaps a better idea is a PDP 10 emulated instead.

Of course, then there would be the small matter of getting
Linux to run on the PDP-10.

Well, Dmitry didn’t really “get Linux to run on a 4004”; he wrote a MIPS emulator for the 4004, which could do whatever it needed to do (on a 4004) because the hardware didn’t have any notion of “protected mode.”

On a DEC-10, presumably the same idea is possible; but the emulator would have to run in protected mode so it could do I/O instructions that would allow it to access the disk drive.

Since the PDP 10 packs 5 7 bit bytes into a word, regardless of how portable Linux is
I can see that as No Go computing problem. Now with the Retro PDP-10 who knows what the future
brings, as more PDP 10’s are in the hands of hackers.

Exercise left for the reader: port the MIPS emulator from the Intel 4004
to the DEC PDP-8 [and run Linux atop the MIPS emulator, as with Linux/4004].

As crazy as this sounds, it might actually be doable. I’m not a PDP-8
person, but I looked into tools that might ease the job. There are actually
a couple of Small-C-based cross-compilers, one from Vincent Slyngstad:
https://so-much-stuff.com/pdp8/C/Small-C.php
and one that comes with the PiDP-8 software distribution:
https://tangentsoft.com/pidp8i/doc/trunk/doc/cc8-manual.md

I gather the Slyngstad compiler is strictly limited to 4K memory usage,
whereas cc8 can utilize up to 16K, so that’s probably the one you’d
want to use. There are two versions of cc8; one is a cross-compiler,
and there’s also a more limited native compiler. The cross-compiler
generates SABR assembler source; you can “inject” this into the
OS/8 RK05 disk image (“v3d-patched.rk05”, presumably) using a tool
called “os8-cp”. Then you assemble and link under OS/8 to get
an executable. The linker is the OS/8 FORTRAN II linking loader
(LOADER.SV), and it determines the memory layout of the executable.
The executables generated are not stand-alone; they need to run
under OS/8. So if you were crazy enough to attempt Dmitry Grinberg’s
trick with the PDP-8, you’d be running Linux on top of OS/8
(with the MIPS emulator as the intermediary).

Also, I was tickled to discover that as of March, 2023 (Version 2.5.1),
Bernhard Baehr’s graphical PDP-8 emulator can mount SimH RK05
(and hence PiDP-8) disk images.
https://www.bernhard-baehr.de/pdp8e/history.html
Also, I would hope that software built for a 1968 PDP-8/i
(PiDP-8) would have run without problems on a 1970 PDP-8/e (Baehr).

;->

All models of the PDP-8 are mostly compatible , but every version has it’s own flavor of microcoded
bit combinations over the basic PDP-8.(Only the CMOS version had hardware I/O issues.).

Small C is very primitive compiler, and you need a full C compiler for linux.
Small C has two versions the 8080 and the 8086. I have been able to only port the 8080-cp/m
version because it has simple code generation and IO use. The 8086 version is a dogs breakfast,
but has the latest version and needs the small memory model. (64k data/64k code).

A hello world program is 8K and the Compiler is 48Kb when ported for my CPU.
My quick and dirty assembler is around 32Kb.
In hindsight 16 bit addressing is just able to have a simple O/S and a compiled language with
good code generation.
If the 4004 emulated a PDP-11 could one port historic unix.

The whole point of this seems to be to get the old CPU to emulate a new enough CPU that would boot Linux then hit the GO button.

So you don’t need a C compiler you need a good assembler for the old CPU then you write an emulator for the new enough CPU (MIPS in this case, but his previous task on the ATmega was ARM), then boot Linux on it.

The 4004 being effectively the oldest microprocessor obviously “wins”.

But if you want it to emulate, say, a PDP-11 then get your 4004 assembler out and go for it…

Or if you want to use a PDP-8 to run Linux, then again, write an emulator for the MIPS CPU in PDP-8 assembler and go for it.

One of the hardest parts of it seems to be expanding the RAM and disk storage. Not insurmountable as it’s been done, but something to consider.

So what next? Another lonely CPU might be the INS8060 aka SC/MP …

-Gordon

2 Likes

Signetics (1977) 8X300 8 bit micro controller seems to be also another little known chip.
Other than Disc Controllers using it, I have seen very few designs with this chip being used.

I’m not a PDP-8 person, but I looked into tools that might ease
the job. There are actually a couple of Small-C-based cross-compilers. . .
[The] one that comes with the PiDP-8 software distribution. . .
generates SABR assembler source; you can “inject” this into
the OS/8 RK05 disk image (“v3d-patched.rk05”, presumably). . .

Actually, the final disk image is ock.rk05 (for “OS/8 Combined Kit”).

So I tried this out with a simple test program and – it worked. But
there was a glitch I haven’t yet figured out. I’ve tried this out
both with the SimH pdp8 that comes with the PiDP-8 software kit and
with Bernhard Baehr’s emulator (latest version 2.5.2; on a Mac Mini
M2 Pro running macOS ver. 15 ‘Sequoia’).

In both cases, test programs will only run properly if the
link step is a load-and-go command at the end of an OS/8
batch file, e.g.:

.R LOADER
*HELLO,LIBC/I/O/G
$END
If the commands are issued separately from the command line in
order to link and then save the executable, e.g.:
.R LOADER
*HELLO,LIBC/I/O$ ← $ = Escape
.SAVE SYS:HELLO
.R HELLO
…then the test executable SYS:HELLO.SV is created,
but won’t run (symptoms vary – SimH halts, the Baehr
emulator hangs).

Interestingly, the same thing happens using the OS/8 native C
compiler (“.R CC”, etc.) on the test programs included with
the PiDP-8 software kit. You can do a compile-and-go with the
provided CCR.BI batch file, but you can’t get a working program
if you issue the commands separately from the command line.

Like I said, I’m not a PDP-8 person; I may well be missing
something blindingly obvious.

;->




In case anybody’s actually interested in this, an update:

If the commands are issued separately from the command line in
order to link and then save the executable, e.g.:
.R LOADER
*HELLO,LIBC/I/O$ ← $ = Escape
.SAVE SYS:HELLO
.R HELLO
…then the test executable SYS:HELLO.SV is created,
but won’t run (symptoms vary – SimH halts, the Baehr
emulator hangs).

With the test programs included with the PiDP-8
software kit, you can do a compile-and-go with the
provided CCR.BI batch file, but you can’t get a working
program if you issue the commands separately from the
command line.

This seems to be a problem specific to the ock.rk05
(“OS/8 Combined Kit”) disk image. If you use v3d.rk05
then creating executables by running LOADER directly
from the command line works properly.

Linux on 4004, check. Next challenge: port Linux to a Turing Machine. :slight_smile:

In a similar vein there are attempts to port Linux to small chips like the ESP32 using emulation - Risc V for example: RISC-V Linux on ESP32 ~ Dror Gluska - similar to the ‘Linux in a web browser’ projects such as GitHub - riscv-software-src/riscv-angel: JavaScript RISC-V ISA Simulator. Boots linux in a web-browser. or JSLinux or my favourite, jor1k: OpenRISC OR1K Javascript Emulator Running Linux With Network Support ( jor1k ethmac support | Stuff Ben Built )

I don’t think we have any big hardware Turing Machine’s. The few I have seen are 256 states or less
or take about 15 seconds read/write a symbol on a real tape.

I find that quite curious - more-so when there is an ESP-32 chip that has RISC-V cores - the ESP32-C3 and -C6. RAM is the limit though - less than 500KB, but adding external RAM via e.g. SPI is do-able.

But other than the “because we can” appeal It’s not very practical - It’s a huge personal achievement to do it on something quite inconceivable like the 4004 but something “almost, but not quite” … does mane you wonder. At least me, anyway.

Maybe taking something like the 65c816 - hybrid 8/16 bit CPU with 64K banks of RAM - and writing a Unix for that might be a nice challenge - but it’s lack of general purpose registers compared to the PDP11 is what might hold that back, I suspect - and while i’s been a very long time since I looked at PDP11 assembler, I suspect it will take a lot more lines of code on the '816 to do the same thing as you can do on the PDP11.

But my '816 system runs a 32-bit VM and runs BCPL - which was used to bootstrap B then C then Unix, so who knows…

-Gordon

I wasn’t serious—more of a thought experiment—though I suppose someone could write a MIPS to Turing Machine cross-compiler, and simulate the result. Or port it to a 4004 and use an SD card as “tape.”

BTW, Is there a description of what Dmitry used for Linux memory? The 4004 can’t directly address more than 4,096 bytes without external bank switching.

Prompted by your reply, I found a few physical Turing machines on the web. Yes, they are small, slow, and not surprisingly, finite. This one from 1972, claiming to be the first one ever physically built (TOWTMTEWP = “The Only Working Turing Machine There Ever Was Probably”) is part of the Henry Ford Museum collection in Dearborn, MI. The FSM is a tangible, programmable plug-box. It’s “tape” is a 1D gantry, and from the video, seems to work at about 2Hz. Tape symbols are little metal sliders tweaked by the write head.

Moving from the realm of Hz to milli-Hertz, what I really want to see someone build is a CRISPR-like DNA-based Turing Machine. Now that AlphaFold is a reality, this challenge has been transformed from nearly impossible to engineer… to merely very, very hard… but also very, very useful for the purposes of arbitrary gene editing.

[Apologies for veering off topic. Or perhaps I can justify this brief digression by calling it retro-futurism, where the retro past usefully informs future breakthroughs…]

Ed, I know this is really off topic, but a how do you reply to that comment and not start a off topic
new thread?
Nova PBS “hunt for the oldest DNA” shows the latest DNA computer tech,of
this year. The 2 million year old samples, still need many more years of editing
and more powerful computer search algorithms and bigger gene libraries.
The last 5 minutes, discus the future and hopes of using historic DNA to modify
modern gene DNA for research studies.
.

(when you find yourself starting a new train of thought, you can compose your reply as usual, then click on the curved reply arrow at top left of the compose window, and select “Reply as linked topic”:

image

It can be helpful to select and quote some appropriate text too.
)

1 Like