Bexkat1’s pipeline redesign exposes an exception-handling snag in a 32-bit FPGA CPU

FPGA, CPU, Verilog

This is the read-only HTML version. For the full Visual Space experience, open the app.

FPGA development board — Image

FPGA development board — Image

Source: Bexkat1 CPU on Hackaday.io · Matt Stock

CPU design, simulation

Matt Stock’s Bexkat1 pairs a custom processor with GCC, binutils and newlib ports. Its move toward a five-stage pipeline shows why changing how instructions execute can also force a rethink of how the machine saves state when an exception interrupts them.

🎉 1

A custom CPU needs more than instructions that produce the right answers: it also needs tools to generate those instructions and tests that catch what breaks when the hardware changes. Matt Stock’s Bexkat1 project on Hackaday.io tackles that whole stack, pairing a synthesizable 32-bit Verilog processor with ports of GCC, binutils and newlib. Its documented pipeline redesign offers a particularly useful lesson: two cores can agree across their tests while still disagreeing on how to handle an exception.

A processor with its own software toolchain

Bexkat1 has 32-bit data and address buses, 16 general-purpose registers, hardware single-precision floating point, interrupt and exception handling, and supervisor/protected mode. Stock also developed or adapted peripheral cores around it, with Wishbone providing the bus interface.

The software work matters because it gives the hardware something beyond hand-written instruction sequences to execute. Stock supplies repositories for the CPU and system code, GCC port, binutils port and newlib port. Together, those projects cover the processor and the tools used to turn programs into machine code for it.

The Hackaday.io project dates to December 9, 2015. The latest supplied log is from December 30, 2019, so this is a record of an ongoing design effort at that point—not a newly launched processor or evidence of its present status.

Simulation makes the redesign easier to check

In an October 2017 discussion, Stock described a core that had become difficult to change without a simulation or regression-testing framework. He had relied heavily on Quartus’s on-chip logic-analyzer tools, which were useful but made isolated component testing awkward.

Commenter Andre Powell suggested keeping the existing instruction set and using the old core as a reference for a rewritten, pipelined version. That was a proposal, not a demonstrated test setup, but it identified a valuable asset: the original implementation could help define what the replacement should do.

By November 15, 2017, Stock had cleaned up the Verilog so it could run in Verilator, which converts a hardware module into a C++ model for simulation. An initialized RAM module also made compiling and running arbitrary code easier. The same log described an early five-stage pipeline.

Memory access presented an immediate design problem: instruction fetches and data accesses would compete on a shared bus. For pipeline testing, Stock gave the core separate logical instruction and data buses connected to dual-port RAM. He proposed an L1 cache to deal with the external bus later; that cache was a plan, not a completed feature in the supplied account.

Exceptions reveal the remaining mismatch

The December 30, 2019 update reported that the original “microcoded” core and the pipelined core ran the same tests and returned the same results—with one important exception: exception handling.

The original instruction-set design pushed both the condition-code register, or CCR, and the program counter onto the stack before jumping to an interrupt service routine. Stock found that arrangement ill-suited to the pipeline. At that point, the pipelined version simply ignored the CCR, while the microcoded version handled it correctly.

Matching ordinary instruction results wasn’t enough. An exception also requires preserving the state needed to resume execution correctly. Stock was considering moving the save-and-restore responsibility into the service routine, but had not implemented that redesign.

The same update reported refreshed toolchain branches and unified board code intended to support the DE10-standard and DE2i-150. MAX10-lite support remained untested. A further public repository push was promised, rather than confirmed in that log.

Bexkat1’s useful lesson is that a pipeline rewrite reaches beyond datapath timing. It can expose assumptions baked into the instruction set and the software that handles interrupts. The next meaningful milestone would be tests showing that both cores preserve and restore the same exception state—not merely that they calculate the same answers.

Source: Bexkat1 CPU

Hardware

3 Followers

A workshop for electronics and physical computing. Share circuits, boards, tools and prototypes; work through measurement and debugging, compare components, and document the choices that turn an idea into working hardware.

Visual Space is built for projects like this—where creators collaborate, organize goals, and grow communities around real work.