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:

2a03-aout
2a03-coff
2a03-elf
2a03-nes
2a03-raw
6502-aout
6502-atari
6502-coff
6502-dos33
6502-elf
6502-prg
6502-prodos
6502-raw
65c02-aout
65c02-atari
65c02-coff
65c02-dos33
65c02-elf
65c02-prg
65c02-prodos
65c02-raw
68000-aout
68000-coff
68000-elf
68000-raw
6809-aout
6809-coff
6809-decb
6809-elf
6809-raw
8008-aout
8008-coff
8008-elf
8008-raw
8031-aout
8031-coff
8031-elf
8031-raw
8032-aout
8032-coff
8032-elf
8032-raw
8051-aout
8051-coff
8051-elf
8051-raw
8052-aout
8052-coff
8052-elf
8052-raw
8080-aout
8080-coff
8080-elf
8080-raw
8086-aout
8086-coff
8086-dos-aout
8086-dos-coff
8086-dos-elf
8086-dos-raw
8086-elf
8086-raw
8088-aout
8088-coff
8088-elf
8088-raw
alpha-aout
alpha-coff
alpha-elf
alpha-raw
armv7a-aout
armv7a-coff
armv7a-elf
armv7a-raw
armv8a-aout
armv8a-coff
armv8a-elf
armv8a-macos
armv8a-raw
atari2600-a26
atari2600-aout
atari2600-coff
atari2600-elf
atari2600-raw
avr-aout
avr-coff
avr-elf
avr-raw
cortex-m3-aout
cortex-m3-coff
cortex-m3-elf
cortex-m3-raw
cortex-m4-aout
cortex-m4-coff
cortex-m4-elf
cortex-m4-raw
cortex-m7-aout
cortex-m7-coff
cortex-m7-elf
cortex-m7-raw
i386-aout
i386-coff
i386-elf
i386-linux
i386-raw
i386-windows
m16c-aout
m16c-coff
m16c-elf
m16c-raw
m30626fjpfp-aout
m30626fjpfp-coff
m30626fjpfp-elf
m30626fjpfp-raw
mc68328-aout
mc68328-coff
mc68328-elf
mc68328-raw
pdp1-list
pdp1-rim
pdp10-aout
pdp10-coff
pdp10-elf
pdp10-raw
pdp11-aout
pdp11-coff
pdp11-elf
pdp11-raw
pdp7-a7out
pdp7-aout
pdp7-coff
pdp7-list
pdp7-ptr
pdp7-rim
pic16-aout
pic16-coff
pic16-elf
pic16-raw
pic18-aout
pic18-coff
pic18-elf
pic18-raw
powerpc-aout
powerpc-coff
powerpc-elf
powerpc-raw
r10000-aout
r10000-coff
r10000-elf
r10000-raw
r4000-aout
r4000-coff
r4000-elf
r4000-raw
saturn-coff
saturn-raw
sparc-aout
sparc-coff
sparc-elf
sparc-raw
stm32-aout
stm32-coff
stm32-elf
stm32-raw
stm8-aout
stm8-coff
stm8-elf
stm8-raw
tms320c6713-raw
tms9900-aout
tms9900-coff
tms9900-elf
tms9900-raw
vax-aout
vax-coff
vax-elf
vax-raw
z80-amsdos
z80-aout
z80-cmd
z80-coff
z80-coleco-aout
z80-coleco-coff
z80-coleco-colecorom
z80-coleco-elf
z80-coleco-raw
z80-elf
z80-raw
z80-sna

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…

  • 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,…

  • 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…

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.