From 846f4d60e4994a39decd6c27463411f53965fc60 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sun, 10 Jan 2021 19:25:59 -0800 Subject: [PATCH] Initial commit to 'Modern C Template For PDP-11' repository. --- LICENSE.txt | 21 ++++++++++++++++ Makefile | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ hello.c | 24 ++++++++++++++++++ init.s | 9 +++++++ pdp11.ld | 25 +++++++++++++++++++ pdp11/pdp11.c | 37 +++++++++++++++++++++++++++ pdp11/pdp11.h | 13 ++++++++++ simh.conf | 13 ++++++++++ 8 files changed, 211 insertions(+) create mode 100644 LICENSE.txt create mode 100644 Makefile create mode 100644 hello.c create mode 100644 init.s create mode 100644 pdp11.ld create mode 100644 pdp11/pdp11.c create mode 100644 pdp11/pdp11.h create mode 100644 simh.conf diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..7c29737 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT/X Consortium License + +© 2020 Aaron Taylor + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..51c8869 --- /dev/null +++ b/Makefile @@ -0,0 +1,69 @@ +############################################################# +# (c) 2020 Aaron Taylor # +# See LICENSE.txt file for copyright and license details. # +############################################################# + + +#################################################################################################### +# GNU Executables & Flags + +CC = pdp11-aout-gcc +LD = pdp11-aout-ld +AS = pdp11-aout-as +OC = pdp11-aout-objcopy +OD = pdp11-aout-objdump + +CC_FLAGS = -c -Wall -Wno-unused-function -O0 -ffreestanding -fomit-frame-pointer -fno-builtin-alloca -std=c99 +LD_FLAGS = -T pdp11.ld --entry _start +AS_FLAGS = +OC_FLAGS = --only-section=.text --output-target binary + + +#################################################################################################### +# Misc Configuration + +# Physical serial port connected to a PDP-11 for transfering program into memory. +SERIAL_PORT = /dev/cuau0 + +# Commands for converting raw binary into SIMH or real PDP compatible formats. +SIM_LOAD = bin2load +PDP_LOAD = bin2pdp + +# Commands for running the SIMH PDP-11 simulation. +SIMH_CMD = pdp11 +SIMH_CFG = simh.conf + +# List of all source files in PDP-11 library. +PDPLIB_SRC != ls pdp11/*.c + + +#################################################################################################### +# Targets + +all: aout + +aout: + $(AS) $(AS_FLAGS) -o init.o init.s + $(CC) $(CC_FLAGS) -o pdp11.o $(PDPLIB_SRC) + + ############################################## + # Insert your program's build commands here. # + $(CC) $(CC_FLAGS) -o hello.o hello.c + ############################################## + + $(LD) $(LD_FLAGS) init.o pdp11.o hello.o -o program.out + +clean: + @rm -rf *.o *.out *.pdp11 *.bin *.core + +sim: aout + $(OC) $(OC_FLAGS) program.out program.bin + $(SIM_LOAD) -i program.bin -o program.pdp11 -a 01000 + $(SIMH_CMD) $(SIMH_CFG) + +pdp: aout + $(OC) $(OC_FLAGS) program.out program.bin + $(PDP_LOAD) -i program.bin -o $(SERIAL_PORT) + +examine: aout + @$(OD) -d program.out diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..8c52dc9 --- /dev/null +++ b/hello.c @@ -0,0 +1,24 @@ +/* (c) 2020 Aaron Taylor */ +/* See LICENSE.txt file for copyright and license details. */ + +#include "pdp11/pdp11.h" + +void +hello(void) +{ + wait(01000); + putch('H'); + putch('e'); + putch('l'); + putch('l'); + putch('o'); + putch(','); + putch(' '); + putch('W'); + putch('o'); + putch('r'); + putch('l'); + putch('d'); + putch('!'); + putch('\n'); +} diff --git a/init.s b/init.s new file mode 100644 index 0000000..f3c4c68 --- /dev/null +++ b/init.s @@ -0,0 +1,9 @@ +# (c) 2020 Aaron Taylor +# See LICENSE.txt file for copyright and license details. + +.globl _start + +_start: + mov $01000,sp + jsr pc,_hello + halt diff --git a/pdp11.ld b/pdp11.ld new file mode 100644 index 0000000..3affcb0 --- /dev/null +++ b/pdp11.ld @@ -0,0 +1,25 @@ +OUTPUT_FORMAT("a.out-pdp11") +ENTRY(start) +phys = 00001000; +SECTIONS +{ + .text phys : AT(phys) { + code = .; + *(.text) + *(.rodata) + . = ALIGN(0100); + } + .data : AT(phys + (data - code)) + { + data = .; + *(.data) + . = ALIGN(0100); + } + .bss : AT(phys + (bss - code)) + { + bss = .; + *(.bss) + . = ALIGN(0100); + } + end = .; +} diff --git a/pdp11/pdp11.c b/pdp11/pdp11.c new file mode 100644 index 0000000..f92bad5 --- /dev/null +++ b/pdp11/pdp11.c @@ -0,0 +1,37 @@ +/* (c) 2020 Aaron Taylor */ +/* See LICENSE.txt file for copyright and license details. */ + +#include + +/* + * Polled console I/O + */ + +#define RCSR (*((volatile uint16_t *)0177560)) +#define RBUF (*((volatile uint16_t *)0177562)) +#define XCSR (*((volatile uint16_t *)0177564)) +#define XBUF (*((volatile uint16_t *)0177566)) + +void +putch(uint16_t c) +{ + while((XCSR && 0200) == 0) continue; + XBUF = c; +} + +uint16_t +getch(void) +{ + while((RCSR && 0200) == 0) continue; + return RBUF; +} + +/* + * Busy-loop + */ + +void +wait(uint16_t count) +{ + while (count--) continue; +} diff --git a/pdp11/pdp11.h b/pdp11/pdp11.h new file mode 100644 index 0000000..2aff814 --- /dev/null +++ b/pdp11/pdp11.h @@ -0,0 +1,13 @@ +/* (c) 2020 Aaron Taylor */ +/* See LICENSE.txt file for copyright and license details. */ + +#ifndef SGK_PDP11_H +#define SGK_PDP11_H + +#include + +void putch(uint16_t); +uint16_t getch(void); +void wait(uint16_t); + +#endif /* SGK_PDP11_H */ diff --git a/simh.conf b/simh.conf new file mode 100644 index 0000000..d77ab24 --- /dev/null +++ b/simh.conf @@ -0,0 +1,13 @@ +set cpu 11/73 +set cpu 4M + +; Optional line printer +; att lpt printer.txt + +; Eight terminal lines accessible via telnet to port 1170. +; set dci en +; set dci lines=8 +; att dci 1170 + +load program.pdp11 +go 1000 -- 2.20.1