From 6df6071a9aa7cc813d1efc93747493b4f71409c7 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Fri, 25 Dec 2020 06:37:54 -0800 Subject: [PATCH] Initial framework for C code. --- Makefile | 5 ++--- bootstrap.s | 6 ++++++ memtest.c | 21 +++++++++++++++++++++ pdp11.c | 34 ++++++++++++++++++++++++++++++++++ pdp11.h | 10 ++++++++++ pdp11.ld | 25 +++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 bootstrap.s create mode 100644 memtest.c create mode 100644 pdp11.c create mode 100644 pdp11.h create mode 100644 pdp11.ld diff --git a/Makefile b/Makefile index 2d43f29..c66d625 100644 --- a/Makefile +++ b/Makefile @@ -42,10 +42,9 @@ all: aout aout: $(AS) $(AS_FLAGS) -o bootstrap.o bootstrap.s - $(CC) $(CC_FLAGS) -o cstart.o cstart.c $(CC) $(CC_FLAGS) -o pdp11.o pdp11.c - $(CC) $(CC_FLAGS) -o hello.o hello.c - $(LD) $(LD_FLAGS) bootstrap.o cstart.o pdp11.o hello.o -o program.out + $(CC) $(CC_FLAGS) -o memtest.o memtest.c + $(LD) $(LD_FLAGS) bootstrap.o pdp11.o memtest.o -o program.out clean: @rm -rf *.o *.out *.pdp11 *.bin *.core diff --git a/bootstrap.s b/bootstrap.s new file mode 100644 index 0000000..3e30f65 --- /dev/null +++ b/bootstrap.s @@ -0,0 +1,6 @@ +.globl _start + +_start: + mov $020000,sp + jsr pc,_memtest + halt diff --git a/memtest.c b/memtest.c new file mode 100644 index 0000000..e3bf460 --- /dev/null +++ b/memtest.c @@ -0,0 +1,21 @@ +#include "pdp11.h" + +void +memtest(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/pdp11.c b/pdp11.c new file mode 100644 index 0000000..c96ddf9 --- /dev/null +++ b/pdp11.c @@ -0,0 +1,34 @@ +#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.h b/pdp11.h new file mode 100644 index 0000000..1e55595 --- /dev/null +++ b/pdp11.h @@ -0,0 +1,10 @@ +#ifndef PDP11_STDIO_H +#define PDP11_STDIO_H + +#include + +void putch(uint16_t); +uint16_t getch(void); +void wait(uint16_t); + +#endif /* PDP11_STDIO_H */ 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 = .; +} -- 2.20.1