platform-pdp11: minimal PDP11 compile test bed
authorAlan Cox <alan@linux.intel.com>
Tue, 25 Oct 2016 20:43:13 +0000 (21:43 +0100)
committerAlan Cox <alan@linux.intel.com>
Tue, 25 Oct 2016 20:43:13 +0000 (21:43 +0100)
14 files changed:
Kernel/platform-pdp11/Makefile [new file with mode: 0644]
Kernel/platform-pdp11/README [new file with mode: 0644]
Kernel/platform-pdp11/config.h [new file with mode: 0644]
Kernel/platform-pdp11/crt0.S [new file with mode: 0644]
Kernel/platform-pdp11/device.h [new file with mode: 0644]
Kernel/platform-pdp11/devices.c [new file with mode: 0644]
Kernel/platform-pdp11/devtty.c [new file with mode: 0644]
Kernel/platform-pdp11/devtty.h [new file with mode: 0644]
Kernel/platform-pdp11/libc.c [new file with mode: 0644]
Kernel/platform-pdp11/main.c [new file with mode: 0644]
Kernel/platform-pdp11/pdp11.S [new file with mode: 0644]
Kernel/platform-pdp11/target.mk [new file with mode: 0644]
Kernel/platform-pdp11/tricks.S [new file with mode: 0644]
Kernel/platform-pdp11/usermem_std-pdp11.S [new file with mode: 0644]

diff --git a/Kernel/platform-pdp11/Makefile b/Kernel/platform-pdp11/Makefile
new file mode 100644 (file)
index 0000000..40344ae
--- /dev/null
@@ -0,0 +1,41 @@
+
+CSRCS = devtty.c
+CSRCS += devices.c main.c libc.c
+
+ASRCS = pdp11.S crt0.S
+ASRCS += tricks.S
+
+DSRCS = 
+DOBJS = $(patsubst ../dev/%.c,%.o, $(DSRCS))
+
+COBJS = $(CSRCS:.c=$(BINEXT))
+AOBJS = $(ASRCS:.S=.o)
+OBJS  = $(COBJS) $(AOBJS) $(DOBJS)
+
+JUNK = $(CSRCS:.c=.o) $(ASRCS:.S=.o)
+
+all:   $(OBJS)
+
+$(COBJS): %.o: %.c
+       $(CROSS_CC) $(CROSS_CCOPTS) -c $<
+
+$(AOBJS): %.o: %.S
+       $(CROSS_AS) $(ASOPTS) $< -o $*.o
+
+$(DOBJS): %.o: ../dev/%.c
+       $(CROSS_CC) $(CROSS_CCOPTS) -c $<
+
+clean:
+       rm -f $(OBJS) $(JUNK)  core *~ 
+
+image:
+       $(CROSS_LD) -M -o fuzix.aout -T fuzix.ld \
+       crt0.o \
+       ../start.o ../version.o ../lowlevel-pdp11.o \
+       main.o ../swap.o ../timer.o ../simple.o ../kdata.o devices.o \
+       ../tty.o ../devio.o ../filesys.o ../process.o ../inode.o ../syscall_fs.o \
+       pdp11.o ../syscall_proc.o ../syscall_other.o ../mm.o \
+       ../devsys.o ../usermem.o ../syscall_exec16.o ../syscall_fs2.o \
+       tricks.o ../syscall_fs3.o \
+       ../usermem_std-pdp11.o devtty.o libc.o > ../fuzix.map
+       pdp11-aout-objcopy fuzix.aout -O binary ../fuzix.bin
diff --git a/Kernel/platform-pdp11/README b/Kernel/platform-pdp11/README
new file mode 100644 (file)
index 0000000..f514980
--- /dev/null
@@ -0,0 +1,6 @@
+At the moment this is just build testing and seeing what in the toolchain
+breaks.
+
+Once it all builds and the syscall and some minimal driver code is filled in
+it ought to come in at about 20KW for a pure swap based system so probably
+not useful on an MMUless /11 except for testing.
diff --git a/Kernel/platform-pdp11/config.h b/Kernel/platform-pdp11/config.h
new file mode 100644 (file)
index 0000000..10e8889
--- /dev/null
@@ -0,0 +1,42 @@
+/* Enable to make ^Z dump the inode table for debug */
+#undef CONFIG_IDUMP
+/* Enable to make ^A drop back into the monitor */
+#undef CONFIG_MONITOR
+/* Profil syscall support (not yet complete) */
+#undef CONFIG_PROFIL
+
+#define CONFIG_MULTI
+#define CONFIG_SWAP_ONLY
+#define CONFIG_USERMEM_DIRECT
+#define CONFIG_BANKS   1
+#define PROC_SIZE      128                     /* 64K, 128 * 512 */
+
+#define CONFIG_SPLIT_UDATA
+#define UDATA_SIZE     512
+#define UDATA_BLKS     1
+
+#define PROGBASE       0x8000UL
+#define PROGLOAD       PROGBASE
+#define PROGTOP                0xE000UL
+#define SWAP_SIZE      (130 + 2)               /* 2 for the udata */
+#define SWAPBASE       PROGBASE
+#define SWAPTOP                0xE000UL
+#define MAX_SWAPS      PTABSIZE                /* Mandatory for swap only */
+#define swap_map(x)    ((uint8_t *)(x))
+
+#define SWAPDEV                (1)
+
+#define TICKSPERSEC 50   /* Ticks per second */
+
+#define BOOT_TTY (512 + 1)   /* Set this to default device for stdio, stderr */
+                          /* In this case, the default is the first TTY device */
+                            /* Temp FIXME set to serial port for debug ease */
+
+/* We need a tidier way to do this from the loader */
+#define CMDLINE        NULL      /* Location of root dev name */
+
+/* Device parameters */
+#define NUM_DEV_TTY 1
+#define TTYDEV   BOOT_TTY /* Device used by kernel for messages, panics */
+#define NBUFS    6        /* Number of block buffers */
+#define NMOUNTS         2        /* Number of mounts at a time */
diff --git a/Kernel/platform-pdp11/crt0.S b/Kernel/platform-pdp11/crt0.S
new file mode 100644 (file)
index 0000000..2aaf63c
--- /dev/null
@@ -0,0 +1,18 @@
+
+               .globl __end
+               .globl __bss_start
+
+_start:
+               bis 0340,0177776        /* IRQs off */
+               mov $_udata+512,sp      /* Set kernel stack */
+               mov $__bss_start,r0
+1:                                     /* Wipe BSS */
+               clr (r0)+
+               cmp r0,$__end
+               ble 1b
+               jsr pc,init_early
+               jsr pc,init_hardware
+               jsr pc,_fuzix_main
+               bis 0340,0177776
+2:
+               jmp 2b
diff --git a/Kernel/platform-pdp11/device.h b/Kernel/platform-pdp11/device.h
new file mode 100644 (file)
index 0000000..6f4c1e2
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __DEVICE_DOT_H__
+#define __DEVICE_DOT_H__
+
+extern void mod_control(uint8_t set, uint8_t clr);
+
+#endif /* __DEVICE_DOT_H__ */
diff --git a/Kernel/platform-pdp11/devices.c b/Kernel/platform-pdp11/devices.c
new file mode 100644 (file)
index 0000000..7abcab5
--- /dev/null
@@ -0,0 +1,41 @@
+#include <kernel.h>
+#include <version.h>
+#include <kdata.h>
+#include <devsys.h>
+#include <tty.h>
+#include <vt.h>
+
+struct devsw dev_tab[] =  /* The device driver switch table */
+{
+// minor    open         close        read      write       ioctl
+// -----------------------------------------------------------------
+  /* 0: /dev/hd                Disc block devices  */
+  {  nxio_open,     no_close,    no_rdwr,   no_rdwr,   no_ioctl },
+  /* 1: /dev/fd                Hard disc block devices (absent) */
+  {  nxio_open,     no_close,    no_rdwr,   no_rdwr,   no_ioctl },
+  /* 2: /dev/tty       TTY devices */
+  {  tty_open,     tty_close,   tty_read,  tty_write,  tty_ioctl },
+  /* 3: /dev/lpr       Printer devices */
+  {  no_open,     no_close,   no_rdwr,   no_rdwr,  no_ioctl  },
+  /* 4: /dev/mem etc   System devices (one offs) */
+  {  no_open,      no_close,    sys_read, sys_write, sys_ioctl  },
+  /* Pack to 7 with nxio if adding private devices and start at 8 */
+};
+
+bool validdev(uint16_t dev)
+{
+    /* This is a bit uglier than needed but the right hand side is
+       a constant this way */
+    if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255)
+       return false;
+    else
+        return true;
+}
+
+void device_init(void)
+{
+  int i;
+
+  for (i = 1; i <= MAX_SWAPS; i++)
+    swapmap_add(i);
+}
diff --git a/Kernel/platform-pdp11/devtty.c b/Kernel/platform-pdp11/devtty.c
new file mode 100644 (file)
index 0000000..3954fa8
--- /dev/null
@@ -0,0 +1,65 @@
+#include <kernel.h>
+#include <kdata.h>
+#include <printf.h>
+#include <stdbool.h>
+#include <devtty.h>
+#include <device.h>
+#include <tty.h>
+
+volatile uint8_t *uart_data = (volatile uint8_t *)0xF03000;    /* UART data */
+volatile uint8_t *uart_status = (volatile uint8_t *)0xF03010;  /* UART status */
+
+unsigned char tbuf1[TTYSIZ];
+
+struct s_queue ttyinq[NUM_DEV_TTY + 1] = {     /* ttyinq[0] is never used */
+       {NULL, NULL, NULL, 0, 0, 0},
+       {tbuf1, tbuf1, tbuf1, TTYSIZ, 0, TTYSIZ / 2},
+};
+
+/* Output for the system console (kprintf etc) */
+void kputchar(char c)
+{
+       if (c == '\n')
+               tty_putc(1, '\r');
+       tty_putc(1, c);
+}
+
+ttyready_t tty_writeready(uint8_t minor)
+{
+       uint8_t c = *uart_status;
+       return (c & 2) ? TTY_READY_NOW : TTY_READY_SOON; /* TX DATA empty */
+}
+
+void tty_putc(uint8_t minor, unsigned char c)
+{
+       *uart_data = c; /* Data */
+}
+
+void tty_setup(uint8_t minor)
+{
+}
+
+int tty_carrier(uint8_t minor)
+{
+       return 1;
+}
+
+void tty_sleeping(uint8_t minor)
+{
+}
+
+/* Currently run off the timer */
+void tty_interrupt(void)
+{
+       uint8_t r = *uart_status;
+       if (r & 1) {
+               r = *uart_data;
+               tty_inproc(1,r);
+       }       
+}
+
+void platform_interrupt(void)
+{
+       timer_interrupt();
+       tty_interrupt();
+}
diff --git a/Kernel/platform-pdp11/devtty.h b/Kernel/platform-pdp11/devtty.h
new file mode 100644 (file)
index 0000000..14c28c3
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __DEVTTY_DOT_H__
+#define __DEVTTY_DOT_H__
+
+#define KEY_ROWS 8
+#define KEY_COLS 7
+extern uint8_t keymap[8];
+extern uint8_t keyboard[8][7];
+extern uint8_t shiftkeyboard[8][7];
+
+#endif
diff --git a/Kernel/platform-pdp11/libc.c b/Kernel/platform-pdp11/libc.c
new file mode 100644 (file)
index 0000000..e718087
--- /dev/null
@@ -0,0 +1,40 @@
+#include "cpu.h"
+
+void *memcpy(void *d, const void *s, size_t sz)
+{
+  unsigned char *dp = d;
+  const unsigned char *sp = s;
+  while(sz--)
+    *dp++=*sp++;
+  return d;
+}
+
+void *memset(void *d, int c, size_t sz)
+{
+  unsigned char *p = d;
+  while(sz--)
+    *p++ = c;
+  return d;
+}
+
+size_t strlen(const char *p)
+{
+  const char *e = p;
+  while(*e++);
+  return e-p-1;
+}
+
+int memcmp(const void *a, const void *b, size_t n)
+{
+  const uint8_t *ap = a;
+  const uint8_t *bp = b;
+  while(n--) {
+    if (*ap < *bp)
+      return -1;
+    if (*ap != *bp)
+      return 1;
+    ap++;
+    bp++;
+  }
+  return 0;
+}
diff --git a/Kernel/platform-pdp11/main.c b/Kernel/platform-pdp11/main.c
new file mode 100644 (file)
index 0000000..e7cc3a4
--- /dev/null
@@ -0,0 +1,42 @@
+#include <kernel.h>
+#include <timer.h>
+#include <kdata.h>
+#include <printf.h>
+#include <devtty.h>
+#include <buddy.h>
+
+void platform_idle(void)
+{
+       /* FIXME: disable IRQ, run tty interrupt, re-enable ? */
+}
+
+void do_beep(void)
+{
+}
+
+/*
+ *     MMU initialize
+ */
+
+void map_init(void)
+{
+}
+
+uaddr_t ramtop;
+uint8_t need_resched;
+
+uint8_t platform_param(char *p)
+{
+       return 0;
+}
+
+void platform_discard(void)
+{
+}
+
+void memzero(void *p, usize_t len)
+{
+       memset(p, 0, len);
+}
+
+uint16_t irqstack[128];        /* Used for swapping only */
diff --git a/Kernel/platform-pdp11/pdp11.S b/Kernel/platform-pdp11/pdp11.S
new file mode 100644 (file)
index 0000000..63a4630
--- /dev/null
@@ -0,0 +1,47 @@
+       .text
+       .globl _program_vectors
+       .globl _trap_monitor
+       .globl _trap_reboot
+       .globl outchar
+       .globl init_hardware
+       .globl init_early
+
+init_early:
+_program_vectors:
+       rts pc
+       
+_trap_monitor:
+_trap_reboot:
+       jmp _trap_reboot
+
+/*     .data FOR now */
+       .even
+       .globl _udata
+
+_udata:
+       .= . + 512
+
+
+       .text
+
+/*
+ *     KL11 and equivalents BR 4  vec 064 (tx) 060 (rx)
+ */ 
+
+outchar:
+       bit $0x8000,0177564             /* test bit 7 of TCSR (tx ready) */
+       beq outchar
+       mov r0,0177566
+       rts pc
+
+init_hardware:
+       /* FIXME: set up traps */
+       /* FIXME: make up some numbers for the moment */
+       mov $512,r0
+       mov r0,_ramsize
+       sub $64,r0
+       mov r0,_procmem
+       /* KW11: Enable IRQ at 0100 every line frequency tick BR 6 vec 100 */
+       mov $0x4000,0177546
+       rts pc
+
diff --git a/Kernel/platform-pdp11/target.mk b/Kernel/platform-pdp11/target.mk
new file mode 100644 (file)
index 0000000..6630ed0
--- /dev/null
@@ -0,0 +1 @@
+export CPU = pdp11
diff --git a/Kernel/platform-pdp11/tricks.S b/Kernel/platform-pdp11/tricks.S
new file mode 100644 (file)
index 0000000..30521a6
--- /dev/null
@@ -0,0 +1,111 @@
+#include "../kernel-pdp11.def"
+
+       .text
+
+       .globl _switchin
+       .globl _switchout
+       .globl _dofork
+
+_switchout:
+       bis 0340,0177776
+       jsr pc,_chksigs
+       clr -(sp)
+       mov r5,-(sp)
+       mov r4,-(sp)
+       mov r3,-(sp)
+       mov r2,-(sp)
+       mov r1,-(sp)
+#ifndef CONFIG_PDP11_04
+       mov 0177717,-(sp)       /* User stack ptr if not 11/04 */
+#endif
+       mov sp,_udata+U_DATA__U_SP
+       jsr pc,_getproc
+       mov r0,-(sp)
+       jsr pc,_switchin
+       jmp _trap_monitor
+
+/* Simple swap based to begin with */
+_switchin:
+       bis 0340,0177776
+       mov 2(sp),r0
+       tst P_TAB__P_PAGE_OFFSET(r0)
+       bne not_swapped
+       mov _udata+U_DATA__U_PTAB,r1
+       tst P_TAB__P_PAGE_OFFSET(r1)
+       /* FIXME: irqs on for swap needed yet */
+       beq its_dead_jim
+       mov r0,-(sp)
+       mov r1,-(sp)
+       jsr pc,_swapout
+       mov (sp)+,r0
+       mov (sp)+,r0
+its_dead_jim:
+       mov sp,r1
+       mov $swapstack,sp
+       mov r1,-(sp)
+       mov r0,-(sp)
+       mov r0,-(sp)
+       jsr pc,_swapper
+       mov (sp)+,r0
+       mov (sp)+,r0
+       mov $1,P_TAB__P_PAGE_OFFSET(r0)
+       mov -(sp),sp
+       bis 0340,0177776
+not_swapped:
+       cmp _udata+U_DATA__U_PTAB,r0
+       bne switchfail
+       movb $P_RUNNING,P_TAB__P_STATUS_OFFSET(r0)
+       clr _runticks
+       mov _udata+U_DATA__U_SP,sp
+#ifndef CONFIG_PDP11_04
+       mov (sp)+,0177717       /* User stack ptr if not 11/04 */
+       /* TODO - user MMU state */
+#endif
+       mov (sp)+,r1
+       mov (sp)+,r2
+       mov (sp)+,r3
+       mov (sp)+,r4
+       mov (sp)+,r5
+       mov (sp)+,r0
+       rts pc
+switchfail:
+       jsr pc,outr0hex
+       mov $badswitchmsg,r0
+       jsr pc,outstring                
+       jmp _trap_monitor
+
+_dofork:
+       mov 2(sp),r0
+       mov r5,-(sp)
+       mov r4,-(sp)
+       mov r3,-(sp)
+       mov r2,-(sp)
+       mov r1,-(sp)
+#ifndef CONFIG_PDP11_04
+       mov 0177717,-(sp)       /* User stack ptr if not 11/04 */
+       /* TODO - user MMU state */
+#endif
+       mov P_TAB__P_PID_OFFSET(r0),-(sp)
+       mov sp,_udata+U_DATA__U_SP
+       mov _udata+U_DATA__U_PTAB,-(sp)
+       jsr pc,_swapout
+       add $14,sp
+       tst r0
+       bne forked_up
+       mov 2(sp),-(sp)
+       jsr pc,_newproc
+       add $2,sp
+       clr r0
+       clr _runticks
+       rts pc
+forked_up:
+       mov $-1,r0
+       rts pc
+
+/*     .data   For now: no split I/D yet */
+badswitchmsg:
+       .ascii "_switchin: FAIL"
+       .byte 13,10,0
+       .even
+swapstack:
+       .= .+256
diff --git a/Kernel/platform-pdp11/usermem_std-pdp11.S b/Kernel/platform-pdp11/usermem_std-pdp11.S
new file mode 100644 (file)
index 0000000..e69de29