Skip to content

Add Verilog RTL, simulators, and toolchain#2

Open
Elwimen wants to merge 4 commits intoDanijel-Korent:mainfrom
Elwimen:add-verilog
Open

Add Verilog RTL, simulators, and toolchain#2
Elwimen wants to merge 4 commits intoDanijel-Korent:mainfrom
Elwimen:add-verilog

Conversation

@Elwimen
Copy link
Copy Markdown

@Elwimen Elwimen commented Apr 15, 2026

Summary

  • verilog/cpu.v — cycle-accurate single-cycle RTL: Harvard architecture, 8-bit datapath, 12-bit instructions, 13-instruction ISA, NAND-only ALU, $readmemh ROM init
  • verilog/tb_cpu.v — automated testbench: injects help\n, captures TTY output, dumps VCD waveform; terminates in 12 000 cycles
  • verilog/tb_interactive.v — interactive testbench via Icarus $fgetc; stdin → keyboard, stdout → TTY; exit with Ctrl-D
  • verilog/Makefilemake sim / make isim / make wave / make clean
  • cpu_sim.py — pure-Python cycle-accurate interactive simulator; raw terminal mode, backspace/Ctrl-D handling, --trace and --max-cycles flags
  • extract_netlist.py — Logisim .circnetlistsvg-compatible JSON; flood-fills 930 wire segments into 149 nets, decodes Splitter pin geometry, emits 11-cell Yosys-style JSON
  • useless_OS_clean.hex — ROM image assembled from useless_OS_clean.asm
  • README.md — full architecture docs, ISA table, memory map, I/O interface, tool usage, Verilog/Logisim correspondence table, expected simulation output
  • .gitignore — exclude Verilog build artifacts and generated netlist files

Test plan

  • cd verilog && make sim — automated testbench prints banner, responds to help, terminates cleanly at cycle 12003
  • cd verilog && make isim — interactive shell accepts keyboard input, exit with Ctrl-D
  • python3 cpu_sim.py — Python interactive shell, same behaviour
  • python3 extract_netlist.py --summary — prints net table, writes cpu_netlist.json (11 cells, 149 nets)
  • python3 assembler.py useless_OS_clean.asm — all 182 instructions match useless_OS.hex exactly

Elwimen added 4 commits March 22, 2026 01:29
Two-pass assembler that takes .asm source files and outputs Logisim
v2.0 raw hex format. Supports labels, comments, hex/decimal/char
literals (including escape sequences like '\n'). Also adds a clean,
labelled assembly source for useless_OS that assembles identically
to the existing useless_OS.hex.

This was made quickly by Claude Sonnet 4.6 as a proof of concept. AI building stuff
assembler.py:
- String literals: mov out1, "Hello\nWorld" expands to per-char movs
- Numeric labels: disassembler output (0x0:, 0xa:) now assembles cleanly

Makefile:
- make / make all: force-rebuild all *.asm -> *.hex
- make <stem>: assemble <stem>.asm into useless_OS.hex (active ROM)

New sources:
- useless_OS_strings.asm: useless_OS rewritten using string literals
- fake_linux.asm: fake Linux boot + POSIX-like shell (ls, pwd, uname,
  whoami, help, exit); exit uses out2=0xFF as halt signal
- verilog/cpu.v: cycle-accurate single-cycle RTL (Harvard, 8-bit, 13
  instructions, NAND-only ALU)
- verilog/tb_cpu.v: automated testbench — injects "help\n", captures
  TTY output, dumps VCD waveform
- verilog/tb_interactive.v: interactive testbench via Icarus $fgetc;
  exit with Ctrl-D
- verilog/Makefile: make sim / make isim / make wave / make clean
- cpu_sim.py: pure-Python cycle-accurate interactive simulator with
  raw terminal mode, --trace, --max-cycles flags
- extract_netlist.py: Logisim .circ → netlistsvg-compatible JSON
  (flood-fill nets, Splitter geometry decoding, 11-cell Yosys JSON)
- useless_OS_clean.hex: ROM image assembled from useless_OS_clean.asm
- README.md: full architecture docs, ISA table, I/O interface, all
  tool usage, Verilog/Logisim correspondence, expected sim output
- .gitignore: exclude Verilog build artifacts and generated netlist
- CLAUDE.md: project guidance for Claude Code
cpu_sim.py: exits cleanly when CPU writes out2=0xFF
verilog/cpu.v: document out2=0xFF halt in header comment
verilog/tb_cpu.v: detect out2=0xFF and call $finish; keyboard sequence
  updated to "help\nexit\n"; fixed cycle timeout replaced with safety limit
verilog/tb_interactive.v: detect out2=0xFF and call $finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant