Initial framework for C code.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 25 Dec 2020 14:37:54 +0000 (06:37 -0800)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 25 Dec 2020 14:37:54 +0000 (06:37 -0800)
Makefile
bootstrap.s [new file with mode: 0644]
memtest.c [new file with mode: 0644]
pdp11.c [new file with mode: 0644]
pdp11.h [new file with mode: 0644]
pdp11.ld [new file with mode: 0644]

index 2d43f29..c66d625 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -42,10 +42,9 @@ all: aout
 
 aout: 
        $(AS) $(AS_FLAGS) -o bootstrap.o bootstrap.s
 
 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 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
 
 clean:
        @rm -rf *.o *.out *.pdp11 *.bin *.core
diff --git a/bootstrap.s b/bootstrap.s
new file mode 100644 (file)
index 0000000..3e30f65
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..c96ddf9
--- /dev/null
+++ b/pdp11.c
@@ -0,0 +1,34 @@
+#include <stdint.h>
+
+/*
+ * 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 (file)
index 0000000..1e55595
--- /dev/null
+++ b/pdp11.h
@@ -0,0 +1,10 @@
+#ifndef PDP11_STDIO_H
+#define PDP11_STDIO_H
+
+#include <stdint.h>
+
+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 (file)
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 = .;
+}