Magic1 Homebrew CPU Bill Buzbee www homebrewcpu com
Magic-1 Homebrew. CPU Bill Buzbee www. homebrewcpu. com Page
2 11/9/2020
3 11/9/2020
4 11/9/2020
The hardware…. . Custom CPU made from 74 series TTL ~200 chips, wire-wrap construction 4. 09 Mhz, 4 Meg SRAM Microcoded CISC, 512 40 -bit microcode words 8 -bit data bus, 8/16 -bit arithmetic ops 16 -bit virtual addresses, mapped onto 23 -bit physical address space via MMU (2 K pages) Memory mapped I/O User & supervisor modes IDE controller, 2 UARTS, real-time clock Bits & bytes numbered from the correct end • • • 5 11/9/2020
Instruction Set Architecture Evolved throughout the project Started as accumulator machine, now 2 -address Two general purpose registers: A & B PC, SP, Kernel SP, MSW, Page. Table. Base DP (data pointer) for globals access C (count) for counted instructions Emphasis on base + offset addressing Compare & branch for density 16 -bit memory to memory with pre-decrement added to better support 32 -bit arithmetic operations • • • 6 11/9/2020
Addressing Modes • Reg-Reg • Reg indirect w/ offset [u 16(A), u 16(b)] • Frame local w/ offset [u 16(SP)] • Global w/ offset [u 16(DP)] • Immediate [(PC++)] • Push/Pop • Memory to memory move • Memory to memory 16 -bit arithmetic 7 11/9/2020
; Magic-1 assembly file, generated by lcc 4. 2 . global _fib. cseg _fib: enter 8 ld. 16 a, 2 cmp. 16 a, 0+4+10(sp) br. le L 2 ld. 16 a, 1 br L 1 L 2: ld. 16 a, 0+4+10(sp) sub. 16 a, 1 st. 16 2(sp), a call _fib st. 16 -2+10(sp), a ld. 16 a, 0+4+10(sp) sub. 16 a, 2 st. 16 2(sp), a call _fib st. 16 -4+10(sp), a ld. 16 b, -2+10(sp) copy a, b ld. 16 b, -4+10(sp) add. 16 a, b L 1: leave ret 8 11/9/2020
9 11/9/2020
The software… • Runs port of Minix 2. 0. 4 • Cross-development toolchain – LCC C Compiler – Custom assembler & linker • Minix TCP/IP stack – Web server – Telnet session support – FTP, etc. • Hundreds of old Unix games & utilities – vi clone, sc spreadsheet, adventure, etc. . • Open for guest telnet access – telnet magic-1. org, user: guest, password: magic 10 11/9/2020
Construction… • Built on my kitchen table – Evenings & weekends over 4 -5 months – Stored in a plastic bin – table had to be cleared by each morning • Special cut-strip-wrap bit & wire (expensive & hard to • • • find – thanks e. Bay!) Surplus high-quality wire-wrap VME prototype cards Hand-wired backplane e. Bay card cage Custom enclosure (more on that later…) Very tolerant wife 11 11/9/2020
Timeline • • • • • Mid-2001: It begins following lunch w/ Ken Sumrall 12 -2001: Start homebrewcpu. com website to hold design diary & notes 1 -2002: Simulate Fibonacci run 2 -2002: Simulate page fault 6 -2002: Significant ISA redesign based on output of LCC retargeting 9 -2002: Buy card cage on e. Bay 5 -2003: Complete schematics 8 -2003: Simulate C Fibonacci run 1 -2004: Construction begins 4 -2004: Success! Magic-1 runs Fibonacci 10 -2004: Adventure runs 4 -2005: Alistar Roe’s enclosure & front panel arrives 6 -2005: Serves web pages via Adam Dunkels’ u. IP TCP/IP stack 10 -2005: Monitor supports simple multi-tasking 12 -2005: Redesign of memory card allows operation at 4 Mhz 11 -2006: Aidil Jazmi clones Magic-1 8 -2007: Minix 2. 0. 4 ported 12 11/9/2020
13 11/9/2020
14 11/9/2020
15 11/9/2020
16 11/9/2020
17 11/9/2020
18 11/9/2020
The big question: Why? 19 11/9/2020
Why #1: ‘Because I didn’t know how to do it. ’ • Lunch @ Vito’s Pizza w/ Ken Sumrall • Forrest Mims’ “Understanding Digital Computers” • Malvino’s “Digital Computer Electronics” 20 11/9/2020
Why #2: • You can’t touch software • Did simple TTL projects in the 70’s & 80’s – fun stuff • Blinky lights • FPGAs just felt too much like software • Somewhat relaxing (kind of like knitting, I suppose) 21 11/9/2020
Project goals Sane start: 4 -bit design, weekend project. Quickly grew out of control. • Real programs – so needed C compiler. • With C compiler, how about a capable OS? • Minix – but need multi-tasking & MMU • Must have internet connectivity! • Vi, adventure & Larn (ended up with 2 of 3) • Strained to keep it buildable 22 11/9/2020
Design envelope • 16 -bit ints and pointers meant hard 64 K code, 64 K data per-process limits. • Old Minix barely runs on 8086, so Magic-1 needed to have code density similar to x 86. – Traded ISA orthogonality for density • Fast message passing • Fast context switching • Lots of RAM to make up for slow clock speed 23 11/9/2020
Along the way… • Community effort – – • • Assistance from around the world Internet & in-person design reviews Bring up assistance Debugging Alistair Roe & the enclosure Aidil Jazmi’s Magic-1 Clone Development website was essential Surprised by the attention – 2 Slashdottings – Thousands of telnet visitors (still several a day) – Maker Faire & VCF 24 11/9/2020
Aidil Jazmi’s Magic-1 Clone 25 11/9/2020
26 11/9/2020
What worked well • Taking my time • The www. homebrewcpu. com website • • The wire-wrap construction Simulating first Build system Iterating between the C compiler retargeting and the ISA design Avoiding putting in features until I knew why they were needed The kernel stack pointer for context switch support Having a logic analyzer The device server (UDS 200, allowed internet connectivity via serial port before TCP/IP stack was up) Front panel artwork using photo printer & lamination • – Treated as the multi-year project it was – Allowed me to take long (up to 6 month) breaks, and resume when I got interested again 27 11/9/2020
28 11/9/2020
What didn’t work well • Too-simple system clock – As a software guy, I failed to appreciate gate and propagation delays Message passing support (tosys, fromsys) Failure to keep simulator up-to-date Incompatible variant of Minix file system Write-only page table entries 2 protection domains (3 would have been better) • Card cage too tight • • • 29 11/9/2020
Debugging • No one to blame but me…. • Front panel useful at first • Notable bugs: – Ungrounded SRAM – Bad solder joint in daughter card – Wire break inside the insulation – Fault during execution of frame creation instruction where pushed SP spans page boundary – IOCLK 30 11/9/2020
31 11/9/2020
What’s next? • Probably nothing – it’s pretty much done • However, there a few things I wanted, but never completed: – – – 32 Native tool chain Demand paging Larn Magic-1 Simulator Magic-1 FPGA implementation Track down that (last? ) elusive bug 11/9/2020
For more info: http: //www. homebrewcpu. com • Full schematics • Lots of pictures • Developent diaries • Videos of bring-up attempts • Links to other homebrew projects and references To visit Magic-1 itself • http: //www. magic-1. org • telnet magic-1. org [user: guest, password: magic] 33 11/9/2020
Questions? 34 11/9/2020
- Slides: 34