PDP11 bare metal coding

Coding for PDP11 machines without any target operating system (bare metal). Gnu GCC does the job.

Github location

There is useful code on Github, see here: https://github.com/DennisD2/pdptools/tree/main/all2deposit

Toolchain install

https://www.teckelworks.com/2020/03/c-programming-on-a-bare-metal-pdp-11/

https://xw.is/wiki/Bare_metal_PDP-11_GCC_9.3.0_cross_compiler_instructions

# Download packages
curl https://ftp.gnu.org/gnu/binutils/binutils-2.34.tar.gz >binutils-2.34.tar.gz
curl https://ftp.gnu.org/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz >gcc-9.3.0.tar.gz

# Extract packages
tar xvf gcc-9.3.0.tar.gz 
tar xvf binutils-2.34.tar.gz

# Download/install prerequisites for compiler 
cd gcc-9.3.0/
./contrib/download_prerequisites

# Create build dirs
cd ..
mkdir binutils-build
mkdir gcc-build

# Build binutils
cd binutils-build/
../binutils-2.34/configure --prefix $HOME/xgcc --bindir $HOME/bin --target pdp11-aout
make -j8
# install toool called makeinfo which seems to be required...
cnf makeinfo
sudo zypper install makeinfo

# Restart build
make -j8
make install

# Build gcc
cd ../gcc-build/
../gcc-9.3.0/configure --prefix $HOME/xgcc --bindir $HOME/bin --target pdp11-aout --enable-languages=c --with-gnu-as --with-gnu-ld --without-headers --disable-libssp
make -j8
make install

# Download and install aout2lda tool
cp ~/Downloads/aout2lda ~/bin
chmod 755 ~/bin/aout2lda 

# Download test code
cd
mkdir pdp11-bare-metal-src
cd pdp11-bare-metal-src/
cat >hello.c
cat >console.h
cat >console.c
cat >crt0.s

# Compile test code
pdp11-aout-gcc -nostdlib -Ttext 0x200 -m10 -Os     -N -e _start crt0.s console.c hello.c -o hello
pdp11-aout-gcc -nostdlib -Ttext 0x200 -m10 -Os     -N -e _start crt0.s console.c hello.c -o hello

# Create PTAP file
aout2lda --aout hello --lda hello.ptap --data-align 2     --text 0x200 --vector0
file hello.ptap 

# Examine files
pdp11-aout-nm hello
# Create object files
pdp11-aout-gcc -c -nostdlib -Ttext 0x200 -m10 -Os     -N -e _start crt0.s console.c hello.c -o hello
pdp11-aout-gcc -c -nostdlib -Ttext 0x200 -m10 -Os     -N -e _start crt0.s console.c hello.c 

# Dissassemble object files for inspection
pdp11dasm hello.o 
more hello.o.das 

pdp11dasm console.o 
more console.o.das 

pdp11dasm crt0.o 
more crt0.o.das