Handcrafted CPU and Unix-like System with Assembly Language

Handcrafted CPU and Unix-like System with Assembly Language

Author: Anfulai Electronics, Typesetting: Xiaoyu

WeChat Official Account: Chip Home (ID: chiphome-dy)

Hardware Design: GR8CPU is a fully functional computer built on a breadboard. The first version, GR8CPU Rev2, has over 600 wires, 74 integrated circuits, and 79 LED lights. It is an 8-bit architecture that considers simplicity and processing power. The CPU can access 256 bytes of RAM and has a fully functional Tic-Tac-Toe game written for it. So far, the second GR8CPU Rev3 is being built. There is a lot of interesting work to do: with 65536 bytes of memory, improved algorithms, and designs for higher speed, this CPU is the most complex breadboard CPU ever.

Handcrafted CPU and Unix-like System with Assembly Language

Earliest Effects:

Handcrafted CPU and Unix-like System with Assembly Language

RAM Module Completed:

Handcrafted CPU and Unix-like System with Assembly Language

Design ALU:

Handcrafted CPU and Unix-like System with Assembly Language

ALU Design Completed:

Handcrafted CPU and Unix-like System with Assembly Language

Video Card Design:

Handcrafted CPU and Unix-like System with Assembly Language

Video Output Circuit Completed:

Handcrafted CPU and Unix-like System with Assembly Language

Handcrafted CPU and Unix-like System with Assembly Language

Unix-like System Design GR8NIX is an operating system inspired by Unix, which is a simple multi-user, multi-tasking operating system released in the 1970s. Modern operating systems based on Unix ideas include Linux, MacOS, and Android. GR8CPU Rev3 is written in assembly language, with the kernel implemented in 2000 lines of assembly code: (1) Multi-threading support for 32 concurrent threads. (2) Theoretically unlimited number of running programs. (3) Dynamic memory allocation, with a current maximum size of 8 KB. (4) True program execution is location-independent (dynamic application loading). However, GR8NIX is not perfect. Due to hardware limitations, GR8NIX cannot: (1) Protect memory from process interference. (2) Recover from attempts to run invalid instructions. (3) Reliably prevent memory leaks after processes exit. After implementing dynamic memory management, the file system was started to be created, allowing files to be loaded from the disk:

Handcrafted CPU and Unix-like System with Assembly Language In the video demonstration, you can see GR8NIX come to life, successfully loading and running a Shell program, which in turn loads and runs any other program you want.

First, Exec is responsible for loading and running programs. Exec first performs some integrity checks: Does the file exist? Is it a program file? Is it valid? Next, Exec finds the length of the executable file by checking each entry and adding its offset to its length. The length found by Exec is the maximum length calculated. After that, Exec calls thread_launch, which is a method used to prepare to start a thread. Exec completes this by adding some raw data to the process: user ID, pointer to allocated memory, command line being run, working directory, etc.

Previous Good Reads

Chip Home Selected Article Collection (1): Save for Later

Chip Home Selected Article Collection (2): Save for Later

Click to Read👆

Handcrafted CPU and Unix-like System with Assembly Language

Leave a Comment