-
Notifications
You must be signed in to change notification settings - Fork 23
PDP 11 GCC Cross Compiler
Most of this page covers building a GCC cross-compiler for the PDP-11 architecture, using the latest version of binutils (2.37) and gcc (11.2).
This will allow you to compile C code into a.out format PDP-11 binaries that can be used on the PDP-11 Co Pro.
I'm doing this Ubuntu 18.04 - later versions should be fine.
You will need ~4GB of free disk space!
sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev
Then create a working directory, in which you will do all the building:
mkdir ~/pdp11
This can be anywhere you like on your filesystem.
Download and unpack the latest binutils version from here (version 2.37 in my case):
cd ~/pdp11
wget http://mirror.lyrahosting.com/gnu/binutils/binutils-2.37.tar.gz
tar xf binutils-2.37.tar.gz
Create a build directory:
cd binutils-2.37
mkdir build-pdp11-aout
cd build-pdp11-aout
Configure the build:
../configure --target=pdp11-aout --prefix=/usr/local
Make (this took 2m 23s minutes on my machine):
make
If there are no errors then install to the configured location:
sudo make install
This gives you the following additional commands:
pdp11-aout-addr2line
pdp11-aout-ar
pdp11-aout-as
pdp11-aout-c++filt
pdp11-aout-elfedit
pdp11-aout-ld
pdp11-aout-ld.bfd
pdp11-aout-nm
pdp11-aout-objcopy
pdp11-aout-objdump
pdp11-aout-ranlib
pdp11-aout-readelf
pdp11-aout-size
pdp11-aout-strings
pdp11-aout-strip
Download and unpack the latest gcc version from here (version 11.2 in my case):
wget http://mirror.lyrahosting.com/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.gz
tar xf gcc-11.2.0.tar.gz
Create a build directory:
cd ~/pdp11
cd gcc-11.2.0
mkdir build-pdp11-aout
cd build-pdp11-aout
Configure the build:
../configure --target=pdp11-aout --prefix=/usr/local --enable-languages=c,c++ --disable-libstdc++-v3 --disable-libssp --disable-libgfortran --disable-libobjc
Make (this took 24m 37s on my machine):
make
If there are no errors then install to the configured location:
sudo make install
This gives you the following additional commands:
pdp11-aout-c++
pdp11-aout-cpp
pdp11-aout-g++
pdp11-aout-gcc
pdp11-aout-gcc-11.2.0
pdp11-aout-gcc-ar
pdp11-aout-gcc-nm
pdp11-aout-gcc-ranlib
pdp11-aout-gcov
pdp11-aout-gcov-dump
pdp11-aout-gcov-tool
Build and install libgcc:
make all-target-libgcc
sudo make install-target-libgcc
To test the GCC cross-compiler, try building the Pi Spigot example.
Here are some notes:
git clone https://github.com/hoglet67/pdp11pispigot.git
cd pdp11pispigot
pdp11-aout-gcc -nostdlib src/spigot.c src/mathlib.s -o SPIGOT
pdp11-aout-objdump -D SPIGOT > SPIGOT.lst
pdp11-aout-strip -D SPIGOT
The file SPIGOT is the a.out format executable (stripped of symbols to reduce it's size). This can be executed directly on the PDP-11 Co Processor.
The file SPIGOT.lst is the assembler listing of the compiled PDP-11 code.
Copying SPIGOT over to a SSD disk is a bit tedious....
You'll need Stephen's MMB/SSD Utilities on your seach path. These can be found here
Setup the BBC_FILE environment variable to point to where your BEEB.MMB usually appears:
export BBC_FILE=/media/$USER/MMFS/BEEB.MMB
(you'll need to adapt this to your system)
Start with Jonathan's PDP11 Utility disc from here and add the SPIGOT file to it (with addresses of &B000)
wget https://mdfs.net/Software/PDP11/BBCBasic/bbcpdp.ssd
echo "$.SPIGOT B000 B000" > SPIGOT.inf
beeb putfile bbcpdp.ssd SPIGOT
Copy the modified bbcpdp.ssd onto a free slot in the BEEB.MMB file on the SD card.
beeb dput_ssd 123 bbcpdp.ssd
Finally, eject the SD card, put it into the Beeb and power on.
I've not been able to build successfully the standard C library for PDP-11, so you need to use the -nostdlib option to tell GCC this is not available. A consequence of this is the program entry point needs to be called startup() rather than main().
By default, the size of int type is 16-bits. This can be changed to 32-bits using -mint32
Because the standard C library is not available, only a few basic include files are available, and you will need to do all I/O yourself within your program.
You can see the available include file by doing:
find /usr/local/lib/gcc/pdp11-aout/11.2.0/include | sort
/usr/local/lib/gcc/pdp11-aout/11.2.0/include
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/float.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/gcov.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/iso646.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/stdalign.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/stdarg.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/stdatomic.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/stdbool.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/stddef.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/stdfix.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/stdint-gcc.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/stdint.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/stdnoreturn.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/tgmath.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/unwind.h
/usr/local/lib/gcc/pdp11-aout/11.2.0/include/varargs.h
Jonathan Harston has documented the PDP-11 Client ROM API here.
If you want to output a character, for example, use a function like:
void myputchar(char c) {
asm("mov 4(r5), r0");
asm("emt 4");
}
Hardware
Software
- Build dependencies
- Running cmake
- Compiling kernel.img
- Deploying on a Pi
- Recommended config.txt and cmdline.txt options
- Validation
- Compilation flags
Implementation Notes