Linux/4004: booting Linux on Intel 4004 for fun, art, and no profit
dmitry.gr
dmitry.gr
It illustrates a point I've explained to many people over the years: once computers started coming with persistent storage, open address spaces and MMUs towards the late '80s and early '90s, we basically arrived at modern computing. An Amiga 3000 or i80486 computer can run the same things as a modern computer. Sure, we have ways to run things orders of magnitude faster, and sure, we now have things that didn't exist then (like GPUs that can run code), but there's no functional difference between those machines and new ones.
I love that Dmitry shows how loosely "functional" can be defined :)
This project is basically Linux-by-correspondence. The challenge is here too. By the time the command produces an output, you might have forgotten why you ran it.
It sounds very similar to what you mentioned.
I guess you never forget your first time : - )
> Richard Stallman browses the web via email.
Did you write the PIC12F1840 HEX file in 4004 machine code for your PIC-based one-chip sound player?
> towards the late '80s and early '90s
By the late 1960s, really. It would probably be possible to port Linux to the IBM Model 67 [1]; might even be easy since GCC can already target the instruction set. The MMU is sufficient. Maybe a tight squeeze with the max of 2 MB of fast core. Would be in a similar ballpark, a bit slower, to that 68030 machine.
Full virtualization, and hardware enforced memory and IO boundaries, were invented early on, too. It took a while for such features to trickle down to mini- and then micro- computers. And then much longer for popular software to take advantage.
The fact that Linux runs well on a modern zSeries demonstrates that, even with all the historical baggage this 60+-year-old architecture has, it carries with it many of the architectural innovations that current OSes and languages need.
My example was about hardware that was affordable to mere mortals (although it's getting to be more expensive to buy that same hardware now as it was to buy it when it was new), but the idea is the same :)
A universe isn't a turing machine because it can't run all the programs that can run on a turing machine. This isn't exactly controversial.
If you only allow arbitrary large turning machines, there is a fixed number of programs which can run
perf stat -Bddd qemu-system-x86_64 -m 2048 -cdrom alpine.iso -boot d -enable-kvm -cpu host -smp 2 -net nic -net user,hostfwd=tcp::2222-:22 -nographic -serial mon:stdio -monitor telnet:127.0.0.1:1234,server,nowait -d in_asm,cpu -D qemu.log
It takes 1,927,757,029,221 cycles to summarize a 1625 token Dijkstra essay with LLaMA 8B. perf stat -Bddd llamafile -m Meta-Llama-3.1-8B-Instruct.BF16.gguf -f ~/prompt1625.txt -c 4096 -n 40
Ignoring things like AVX512 you're looking at about 100x more compute to do something serious with LLaMA.However! If you just want to demo it working, then you could generate 4 tokens using TinyLLaMA 1.1B which takes 25,164,386,466 cycles. That's about the same cost as booting Linux. So you could do TinyLLaMA if you can do Linux.
Note also that the 4004 lacks a floating-point unit of any kind - not just a vector unit. I think people make 8-bit integer quantizations of LLMs, though, which would be the fastest versions to run on a 4004.
Machines that address storage using fixed width pointers (and have no other kind of storage) cannot be Turing machines.
In so far as infinite tape is feasibile, you are correct.
No wait ... the other one ...
"the network is the computer"
And then IBM mocked "When they put the dot into dot-com, they forgot how they were going to connect the dots," after sassily rolling out Eclipse just to cast a dark shadow on Java. Badoom psssh!
https://www.itbusiness.ca/news/ibm-brings-on-demand-computin...
"The Network Is The Network and The Computer Is The Computer. We regret the confusion."
https://news.ycombinator.com/item?id=34256623
>Oh yeah, don't get me started about NFS! (Oops, too late.) I'll just link with short summaries: [...]
>NFS originally stood for "No File Security". [...]
>The network is the computer is insecure, indeed.
Tarpit,
where everything is possible but nothing of interest is easy.
Like geological time.
Alas, dimitygr's method wouldn't work on the badge, as the memory and RAM are all internal to the PIC24 that implements the CPU emulator.
BTW, 4-bit CPUs are still made and used. Many of the mass-produced IR remotes are programmed using a 4-bit MCU. See https://www.emmicroelectronic.com/sites/default/files/produc... for a datasheet.
Considering the frequencies and wattage I wonder how RF it spits out and what is detectable and decodable on the waterfall of a SDR.
By the way still reading through it, but at the time of this comment I see the word "soubroutine" which is probably a misspelling.
Also probably the only time I'd have gone for an LCD over a VFD. If you're running a multi-year long compile, it'll probably be burned in to hell by the end.
…you can see in the high PC bits what's currently executing!
P.S.: Still loads the kernel faster than a virtual ISO on a server's shitty IPMI over the internet ;D
Also, when in user space, you can tell between the main binary (way below 0x01000000) and shared libraries (loaded high near 0x77000000)
This gave me flashbacks of trying to boot Dell M1000e blade servers from an NFS-hosted ISO running on a Raspberry Pi, which was painfully slow to boot and run.
Thanks for documenting your work so well!
https://hackaday.com/2021/12/27/single-bit-computer-from-vac...
Also I wonder why he's using Windows 95?
For the video, i wanted a laptop with a real serial port (no usb). This one fit the bill and was $20 on eBay. Windows 2000 is the prettiest windows IMHO, so that’s what I installed for the demo video.
Though my highlight (which I could completely comprehend) is "Section 14.b & 14.c - Getting the data..." All it took was 400K files (~275 photos/day after 4 years). We have so much of raw power of processing, storage & network still the most-used (probably) media-sync apps crashed or faced slow sync, AirDrop fails & lack of 'Select-All' UI feature. Crazy times we live/will live in... :)
It's a cool project don't get me wrong, but Nobel Peace Prize? What is this thread? I would consider something like a strandbeest to be more award-worthy - but it too is just a neat invention, not contributing to world peace or anything near it.
> some have shitty addressing modes necessitating that they would be slow (RISCV)
What is wrong with the RISC-V addressing modes?
On all MIPS instructions, the bits for a immediate add, load constant, branch, etc value are always stored in order.
On RISC-V, the bits are (sometimes) jumbled around. For example, on a unconditional branch, the bits for the destination offset are stored in the order of bit 19, bits 9-0, bit 10, bits 18-11. In hardware, reordering that is free, you just run your wires the right way to decode it. In software, you have to do a ton of bit manipulation to fix it up.
The reason RISC-V does that is to simplify the hardware design.
Does it? Well, there's a vendor specific extension for that (XTheadMemIdx):
https://github.com/XUANTIE-RV/thead-extension-spec/releases/...
Not sure about GCC, but on clang it is trivial to enable it. And if you really want to (assuming you have the hardware) you could compile exactly the same code with and without it and compare how much exactly it is handicapped if those instructions are not there.
Plus, on RISC-V multiplication/division (about which you've complained) is optional, and there is also a variant of RISC-V with only 16 registers instead of 32 (also very simple to enable on recent versions of clang, although Linux would probably need some modifications to be able to run on that).
So I'm not entirely convinced that RISC-V would be worse here.
My other issue was that there is NO working Linux user space for rv32. There is for rv64. No Debian. No Ubuntu. No anything for rv32
Is this a guess, or statistically supported on a body of empirical evidence like the RISC-V spec is?
It is well known design deficiency. Much like lack of bit field ops.
i.e. it does not have my favored instructions or addressing modes, so it must be worse.
How is that subjective?
Neither are concepts RISC-V invented, but rather, adopted. Ideas that have been plenty tested out there, and proven beneficial.
Large body of evidence trumps intuition and guesswork. Most of this is documented in the spec itself and/or in:
Computer Architecture: A Quantitative Approach (John L. Hennessy, David A. Patterson)
https://www.ganssle.com/rants/is4bitsdead.htm
I suspected we’d see either 4- or 8-bit return for neural networks. IBM did try the kilocore processor which was a massively-parallel, 8-bit system. Multicore 4- and 8-bitters are also the kind thing people could build on cheaper nodes, like Skywater’s 130nm.
Impressive work, as always.
The first true (civilian) microprocessor was Intel 8008, in 1972.
Intel 8008 was a monolithic implementation, i.e. in a single PMOS integrated circuit, of the processor of Datapoint 2200, therefore it deserves the name "microprocessor".
The processor of Datapoint 2200 had an ugly architecture, but there is no doubt that it was a general-purpose CPU and traces of its ISA remain present in the latest Intel and AMD CPUs.
On the other hand, the set of chips that included Intel 4004 was not intended for the implementation of a general-purpose computer, but it was intended just for the implementation of a classic desktop calculator, not even a programmable desktop calculator.
This is the reason for the many quirks of Intel 4004, e.g. the lack of instructions for the logic operations, and many others that have increased the amount of work required for implementing a MIPS emulator suitable for running Linux.
Even if Intel 4004 was intended for a restricted application, after Intel has offered to sell it to anyone, there have been many who have succeeded to use it in various creative ways for implementing microcontrollers for the automation of diverse industrial processes, saving some money or some space over a TTL implementation.
In the early days of the electronics industry it was very normal to find ways to use integrated circuits for purposes very different from those for which the circuits had been designed. Such applications do not make Intel 4004 a true microcontroller or microprocessor. Very soon many other companies, and later also Intel, have begun to produce true microcontrollers, designed for this purpose, either 4-bit or 8-bit MCUs, then Intel 4004 has no longer been used for new designs.
Intel's real innovation—the thing that made the microprocessor important—was creating the microprocessor as a product category. Selling a low-cost general-purpose processor chip to anyone who wanted it is what created the modern computer industry. By this perspective, too, the 4004 was the first microprocessor, creating the category.
My article in IEEE Spectrum on this subject goes into much more detail: https://spectrum.ieee.org/the-surprising-story-of-the-first-...
Your statement about Intel 'pushing back' the date to 1971 also makes little sense given Intel advertised [1] the 4004 as a CPU in Electronic News in Nov 1971.
[1] https://en.wikipedia.org/wiki/Intel_4004#/media/File:Intel_4...
Therefore I do not believe that it is possible to consider Intel 4004 as a general-purpose processor. It had only the features strictly necessary for the implementation of the Busicom calculator.
The idea to sell 4004 for other uses has appeared long after the design was finished, when Busicom did not want to pay for the chipset as much as Intel desired, so Intel decided to try to sell the chipset to other customers too, and then they thought to advertise it as a "CPU".
Moreover, it is debatable whether Intel 4004 can be considered as a monolithic processor, because 4004 was not really usable without the rest of the chipset, which provided some of the functions that are normally considered to belong into a processor.
The Intel 4004 4-bit "CPU" implemented less functions than the 4-bit TTL ALU 74181, which was general-purpose and which was the main alternative at that time for implementing a CPU, but it had the advantage of including many registers, because the MOS registers were much cheaper in die area than the TTL registers, and these included registers were the reason why a CPU implemented with the Intel 4004 chipset had a lower integrated circuit count than the equivalent implementation with MSI TTL ICs.
Intel's advertisement of 4004 being a CPU was just an advertisement of the same kind of Tesla having a "Full Self-Driving".
So you're setting a range of instructions without which a device can't be considered a general-purpose computer even if the missing instructions can be recreated in software with instructions that do exist.
Sorry disagree with this completely, as does every definition I've ever seen.
The reason that the 4004 is considered a CPU and the 74181 is not a CPU is that the 4004 contains the control logic, while the 74181 is only the ALU.
Of course, "microprocessor" and "CPU" are social constructs, not objective definitions. (For instance, bit-slice processors like the Am2901 were considered microprocessors in Russia.) So you can craft your own definition if you want to declare a particular processor first. cough MP944 cough
PS: love the VFD
Bit of course you can solve this by sending letters speculatively, and having Dave keep copies of his letters back to you so he reference them for recently set values, that way you can at least keep Dave busy while the letters are in flight.
A chip like the 4004 could be used in some simple embedded applications using its instruction set directly. But that calculator was the original application was developed for. Already that was too complicated, not unlike, say, booting Linux.
It kind of shows that no one can be an expert in everything at the same time.
A write to t0 is not simply ignored. It will generate an exception. Another MIPS-like thing is that t1 is an assembler temporary.
It would have been far easier to write an MIPS Emulator in a tiny VM and run that VM instead of MIPS
It would also be even slower ^^
BogoMIPS : 0.00
Very impressive project. Recording it with a phone seems complicated though. Why not a Raspberry Pi with camera module? Or a decent webcam and any computer? Just to keep you on your toes, there does exist a single one-byte instruction that takes 16 cycles - FIN. However, that is only the beginning.
Please tell me that was intentional.The alternative is to find the Windows MIPS DDK and build a paravirtualized disk driver for it like I did for Linux. That would make it more doable.
Perhaps we need a competition, assembly programmers only need apply. :-)
One, it reminds me of that "worlds longest song" or somesuch thing, where they play a note every 10 years.
The other is just a picture of someone, asleep at their desk, a pile of calendars with days checked off tossed to the side, random unwashed mugs and such all dimly lit by a desk lamp and see the `$ make linux` finally return to an new, unassuming `$` prompt. Like Neo in the Matrix.
It will be completed in the year 2640.