Using CGEN to Generate Files for Binutils

CGEN (Cpu tools GENerator) is a tool to create CPU tools e.g. assembler, disassembler and simulators. All these tools start from uniform code base. This reduces duplicating code written manually. It helps decreasing error from redundancy.

Binutils is a collection of tools dealing with bits and bytes for various types of file format and CPU models. It is one of CGEN’s big fans. Actually, it has CPU description files for CGEN to process laid inside its source tree. That folder is


The CGEN documentation of how to port a processor is confusing to me. Its Wiki and FAQ pages from its homepage are down. Yeah, this is normal for open source projects. Big goals, big users, text-only documents and no funding.

Luckily I found a remnant of its FAQ. After trying a few times, I can get it running.

This walkthrough assumes using binutils-2.25 and cgen-1.1 and targeting lm32 architecture.


tar -xzf binutils-2.25.tar.gz

This will get you ./binutils-2.25 folder.

tar -xzf cgen-1.1.tar.gz

This will get you ./cgen-1.1 folder.

  • Copy ./cgen-<version>/cgen to Binutils folder
cp -R ./cgen-1.1/cgen ./binutils-2.25

The copied folder contains necessary routines written in scheme language.

  • Make a folder for building & Go inside
mkdir build
cd build
  • Do configure and make Binutils
make -j4

This will throw a lot of text on your terminal.

  • Go inside opcodes directory
cd opcodes
  • run make stamp-<arch> to generate new files for Binutils
make stamp-lm32

CGEN will compile ../../binutils/cpu/lm32.{cpu,opc}.

It will generate text like

Analyzing instruction set ...
Done analysis.
Generating lm32-desc.h ...
Generating lm32-desc.c ...
Generating lm32-opc.h ...
Generating lm32-opc.c ...
Generating ...
Generating ...
Generating ...
Generating lm32-opinst.c ...
touch stamp-lm32

You can go back to the Binutils folder to confirm changes by timestamp.

cd ../../binutils-2.25/opcodes
ls lm32-*

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s