Close

Another GCC 68K Cross Compiler

A project log for Retro 68000 CPU in an FPGA

Making a Retrocomputer with a 68000 CPU in an FPGA

land-boardscomland-boards.com 08/27/2020 at 10:160 Comments

I've loved the (on-line GodBolt) Compiler Explorer project for a while now. It lets you type code in one window and see it compiled to assembly language in another window. 

There's a Compiler Explorer site which does 68k cross compiling. This also lets you play with compiler options like optimization. One thing that you learn doing embedded system software is the C language keyword volatile. Any hardware register which is updated externally to the 68K needs to have volatile added. For instance, the ports for the VDU and ACIA can be accessed as pointers with the following defines:

#define ACIASTAT    (volatile unsigned char *) 0x010041
#define ACIADATA    (volatile unsigned char *) 0x010043
#define VDUSTAT     (volatile unsigned char *) 0x010040
#define VDUDATA     (volatile unsigned char *) 0x010042
#define TXRDYBIT 0x2

To print a character to the ACIA:

void printCharToACIA(unsigned char charToPrint)
{
    while ((*ACIASTAT & TXRDYBIT) == 0x0);
    * ACIADATA = charToPrint;
}

 The 68K Compiler Explorer looks like:

A very nice and fast way to see what the compiler does. Setting the -O3 flag shows what the optimizer does to the code:

Nice job of optimization. If you click the green check box you can see the compiler options:

-g -o /tmp/compiler-explorer-compiler120727-1067-xxj1yf.t0dk/output.s 
-S -fdiagnostics-color=always -O3 /tmp/compiler-explorer-compiler120727-1067-xxj1yf.t0dk/example.cpp

Discussions