rcc – Retargetable C Compiler

I’ve recently been doing projects such as porting CP/M-86 to C, and the porting MP/M to C. I decided to take a look at UnixV0 and TOPS-10 the same way and quickly discovered that I would like to have a compiler that consumes C and emits… whatever back-end instruction set I want. So I decided, with the help of the LLM’s to write rcc (RCC on Github)

If you want to just use the binaries they are here:

The structure of RCC is simple. It consumes as “pretty close to complete” dialect of C, documented here. The front-end compiler emits IR, documented here. The IR is compiled to assembler for the specific processor, in an assembler format described here. The assembler is then assembled to binary output, usually in COFF format (other options are available). The COFF is then consumed by the rcc linker and/or emitted to a chosen file format such as a PE, or maybe Apple][ PRODOS executable.

Optimizations are applied at the IR level and therefore benefit all target platforms.

For example, these two commands compile a main.c to 8086 COFF and then emit a MS-DOS .com file (source)

rcc --platform=8086-dos-raw --out=main.raw main.c
rcc --link --platform=8086-dos-raw --out=main.com main.o" msdos.lib

Here are commands to create a pdp7 rim file (source)

rcc --platform=pdp7-rim --dump-ir --dump-asm --out=main.o main.c
rcc --link --platform=pdp7-rim --out=main.rim main.o

You might notice that the MS-DOS build includes msdos.lib. Where it’s appropriate, rcc provides C wrappers around the ROM/PROM in the host. You can see them here.

The full list of processors, file formats and platforms is growing however at the time of writing this there are currently 189 combinations of processor and platform supported. The current list is here.

Similar Posts

  • CP/M on i386

    I’ve been interested in CP/M for a while. The source code for CP/M from “way back in the time tunnel” is available at the CHM and multiple other places. The challenge however was that CP/M source is in assembler code for 8080 and z80. I wanted to run it on i386 hardware. So, with the…

  • MP/M on i386

    Following on the work to port CP/M to C, I decided to take on MP/M from 1979, since it has multi-user capability. With Claude’s help this was a 2-stage process: The net result is C code that compiles to 32-bit real mode MP/M. You can see it in QEMU here: qemu-system-i386 -drive file=build/mpm86c.img,format=raw,if=floppy -boot a…

  • CP/M on i386 part 2

    Part 1 here. Well, i discovered that none of the CP/M commands that are .com files were present. So we now have: All of the .COM’s were “back-ported” from the original assembler code to C so that they can now be compiled for different platforms. BASICBAS.COM, BASICINT.COM and BASIC.COM are the original Basic-e from 1976,…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.