atarist: quick pass over the old draft code to match current state
authorAlan Cox <alan@linux.intel.com>
Wed, 23 Jan 2019 19:23:00 +0000 (19:23 +0000)
committerAlan Cox <alan@linux.intel.com>
Wed, 23 Jan 2019 19:23:00 +0000 (19:23 +0000)
Kernel/platform-atarist/Makefile
Kernel/platform-atarist/crt0.S
Kernel/platform-atarist/devfd.c
Kernel/platform-atarist/devtty.c
Kernel/platform-atarist/libc.c
Kernel/platform-atarist/main.c
Kernel/platform-atarist/p68000.S
Kernel/platform-atarist/tricks.S

index 6cd541f..a2b5bdf 100644 (file)
@@ -7,7 +7,10 @@ ASRCS += tricks.S
 
 COBJS = $(CSRCS:.c=$(BINEXT))
 AOBJS = $(ASRCS:.S=.o)
-OBJS  = $(COBJS) $(AOBJS)
+LSRCS = ../lib/68000exception.c
+LOBJS = $(patsubst ../lib/%.c,%.o, $(LSRCS))
+
+OBJS  = $(COBJS) $(AOBJS) $(LOBJS)
 
 JUNK = $(CSRCS:.c=.o) $(ASRCS:.S=.o)
 
@@ -19,17 +22,24 @@ $(COBJS): %.o: %.c
 $(AOBJS): %.o: %.S
        $(CROSS_AS) $(ASOPTS) $< -o $*.o
 
+$(LOBJS): %.o: ../lib/%.c
+       $(CROSS_CC) $(CROSS_CCOPTS) -c $<
+
 clean:
        rm -f $(OBJS) $(JUNK)  core *~ 
 
+tricks.S: ../lib/68000flat.S
+
 image:
-       $(CROSS_LD) -M -o ../fuzix.bin \
+       $(CROSS_LD) -M -o fuzix.elf -T fuzix.ld \
        crt0.o \
        p68000.o ../start.o ../version.o ../lowlevel-68000.o \
        tricks.o main.o ../timer.o ../kdata.o devfd.o devices.o \
+       68000exception.o \
        ../devio.o ../filesys.o ../process.o ../inode.o ../syscall_fs.o \
        ../syscall_proc.o ../syscall_other.o ../mm.o ../swap.o ../flat.o \
-       ../tty.o ../devsys.o ../usermem.o ../syscall_fs2.o ../syscall_exec32.o \
+       ../tty.o ../devsys.o ../usermem.o ../syscall_fs2.o \
+       ../syscall_fs3.o ../syscall_exec32.o \
        ../usermem_std-68000.o devlpr.o devtty.o libc.o ../vt.o ../malloc.o \
-       ../font8x8.o \
-       /usr/lib64/gcc/m68k-atari-mint/4.6.4/mshort/libgcc.a  >../fuzix.map
+       ../font8x8.o >../fuzix.map
+       m68k-uclinux-objcopy fuzix.elf -O binary ../fuzix.bin
index 89a6d44..6918113 100644 (file)
@@ -1,17 +1,19 @@
+#include "../kernel-68000.def"
+
 /*
  *     Need to wipe BSS etc once we figure out our preferred boot method
  */
-               .globl _start, _screenbase
+               .globl screenbase
 
 .mri 1
 
-_start:
+start:
 ;
 ;              We run from TOS for the moment
 ;
                move.w #2,-(sp)
                trap #14
-               move.l d0,_screenbase
+               move.l d0,screenbase
                clr.l (sp)
                move.w #32,-(sp)
                trap #1
@@ -24,9 +26,9 @@ _start:
 ;
                or #$0700,sr
                /* FIXME: hard coded ugly */
-               move.l #_uarea_block+508,a7
+               move.l #uarea_block+UBLOCK_SIZE,a7
                bsr init_early
                bsr init_hardware
-               bsr _fuzix_main
+               bsr fuzix_main
                or #$0700,sr
 stop:          bra stop
index 9a29772..0dffb53 100644 (file)
@@ -47,15 +47,13 @@ static uint8_t selmap[4] = {0x00, 0x01, 0x02, 0x03 };
 
 static int fd_transfer(uint8_t minor, bool is_read, uint8_t rawflag)
 {
-    blkno_t block;
-    uint32_t dptr;
     int ct = 0;
     int tries;
     uint8_t err;
     uint8_t *driveptr = fd_tab + minor;
     uint8_t cmd[6];
 
-    if(rawflag)
+    if(rawflag == 2)
         goto bad2;
 
     fd_motor_busy();           /* Touch the motor timer first so we don't
@@ -66,16 +64,17 @@ static int fd_transfer(uint8_t minor, bool is_read, uint8_t rawflag)
 //            goto bad;
     }
 
-    dptr = (uint32_t)udata.u_buf->bf_data;
-    block = udata.u_buf->bf_blk;
+//    fd_map = rawflag;
+    if (rawflag && d_blkoff(BLKSHIFT))
+            return -1;
+
+    udata.u_nblock *= 2;
 
 //    kprintf("Issue command: drive %d\n", minor);
     cmd[0] = is_read ? FD_READ : FD_WRITE;
-    cmd[1] = block / 9;                /* 2 sectors per block */
-    cmd[2] = ((block % 9) << 1) + 1;   /*eww.. */
+    cmd[1] = udata.u_block / 9;                /* 2 sectors per block */
+    cmd[2] = ((udata.u_block % 9) << 1) + 1;   /*eww.. */
     cmd[3] = is_read ? OPDIR_READ: OPDIR_WRITE;
-    cmd[4] = dptr >> 8;
-    cmd[5] = dptr & 0xFF;
         
     while (ct < 2) {
         for (tries = 0; tries < 4 ; tries++) {
index 799544f..15f986e 100644 (file)
@@ -14,6 +14,29 @@ uint8_t *uart_status = (uint8_t *)0xFF05;    /* ACIA status */
 uint8_t *uart_command = (uint8_t *)0xFF06;     /* ACIA command */
 uint8_t *uart_control = (uint8_t *)0xFF07;     /* ACIA control */
 
+static tcflag_t console_mask[4] = {
+       _ISYS,
+       _OSYS,
+       _CSYS,
+       _LSYS
+};
+
+static tcflag_t uart_mask[4] = {
+       _ISYS,
+       /* FIXME: break */
+       _OSYS,
+       /* FIXME CTS/RTS, CSTOPB ? */
+       CSIZE|CBAUD|PARENB|PARODD|_CSYS,
+       _LSYS,
+};
+
+tcflag_t *termios_mask[NUM_DEV_TTY + 1] = {
+       NULL,
+       console_mask,
+       console_mask,
+       uart_mask
+};
+
 static unsigned char tbuf1[TTYSIZ];
 static unsigned char tbuf2[TTYSIZ];
 
@@ -23,6 +46,8 @@ struct s_queue ttyinq[NUM_DEV_TTY + 1] = {    /* ttyinq[0] is never used */
        {tbuf2, tbuf2, tbuf2, TTYSIZ, 0, TTYSIZ / 2}
 };
 
+uint8_t vtattr_cap;
+
 /* tty1 is the screen tty2 is the serial port */
 
 /* Output for the system console (kprintf etc) */
@@ -52,7 +77,7 @@ void tty_putc(uint8_t minor, unsigned char c)
                *uart_data = c; /* Data */
 }
 
-void tty_setup(uint8_t minor)
+void tty_setup(uint8_t minor, uint8_t flags)
 {
        if (minor == 2) {
                /* FIXME: do proper mode setting */
@@ -85,6 +110,9 @@ void tty_interrupt(void)
        }       
 }
 
+
+struct vt_repeat keyrepeat;
+
 uint8_t keymap[8];
 static uint8_t keyin[8];
 static uint8_t keybyte, keybit;
index e718087..e35056d 100644 (file)
@@ -9,6 +9,16 @@ void *memcpy(void *d, const void *s, size_t sz)
   return d;
 }
 
+void *memcpy32(void *d, const void *s, size_t sz)
+{
+  uint32_t *dp = d;
+  const uint32_t *sp = s;
+  sz >>= 2;
+  while(sz--)
+    *dp++ = *sp++;
+  return d;
+}
+
 void *memset(void *d, int c, size_t sz)
 {
   unsigned char *p = d;
index ef3b119..878c73b 100644 (file)
@@ -8,18 +8,28 @@ void platform_idle(void)
 {
 }
 
-void do_beep(void)
+uint8_t need_resched;
+
+uint8_t platform_param(char *p)
 {
+       return 0;
 }
 
-/*
- * Map handling: We have flexible paging. Each map table consists of a set of pages
- * with the last page repeated to fill any holes.
- */
+void platform_discard(void)
+{
+}
 
-void pagemap_init(void)
+void memzero(void *p, usize_t len)
+{
+       memset(p, 0, len);
+}
+
+void platform_copyright(void)
+{
+}
+
+void do_beep(void)
 {
-       vmmu_init();
 }
 
 void map_init(void)
@@ -27,40 +37,43 @@ void map_init(void)
 }
 
 u_block uarea_block[PTABSIZE];
-uaddr_t ramtop;
 
 void *screenbase;
-uint8_t *membase = 0x10000;    /* GUESS FIXME */
-uint8_t *memtop;
 
-/*
- *     We can do our fork handling in C for once. The only oddity here is
- *     the fixups to run parent first and avoid needless memory thrashing
- */
-void dofork(ptptr p)
+void pagemap_init(void)
+{
+       /* FIXME: 512K hackish setup to get going */
+       /* Linker provided end of kernel */
+       extern uint8_t _end;
+       uint32_t e = (uint32_t)&_end;
+       kprintf("Kernel end %p\n", e);
+       /* Allocate the rest of memory to the userspace */
+       kmemaddblk((void *)e, 0x78000 - e);
+}
+
+/* Udata and kernel stacks */
+/* We need an initial kernel stack and udata so the slot for init is
+   set up at compile time */
+u_block udata_block0;
+static u_block *udata_block[PTABSIZE] = {&udata_block0,};
+
+/* This will belong in the core 68K code once finalized */
+
+void install_vdso(void)
+{
+       extern uint8_t vdso[];
+       /* Should be uput etc */
+       memcpy((void *)udata.u_codebase, &vdso, 0x40);
+}
+
+uint8_t platform_udata_set(ptptr p)
 {
-       /* Child and parent udata pointers */
-       u_block *uc = uarea_block + p - ptab;
-       u_block *up = udata_ptr;
-       uint32_t *csp = uc + 1;
-       uint32_t *psp = up->u_sp;
-       /* Duplicate the memory maps */
-       if (pagemap_fork(p))
-               return -1;
-       /* Duplicate the udata */
-       memcpy(&uc->u_d, &up->u_d, sizeof(struct u_data))
-       /* Use the child udata for initializing the child */
-       udata_ptr = uc;
-       newproc(p);
-       udata_ptr = up;
-       /* And return as the parent. The child will return via the
-          fork return path */
-       *--csp = fork_return;
-       uc->u_sp = csp;
-       /* Copy the saved register state over - must match switchin */
-       memcpy(csp - 14, psp - 14, 4 * 14);
-       /* Return as the parent and run it first (backwards to most ports) */
-       p->p_status = P_READY;
-       udata.u_ptab->p_status = P_RUNNING;
-       return p->p_pid;
+       u_block **up = &udata_block[p - ptab];
+       if (*up == NULL) {
+               *up = kmalloc(sizeof(struct u_block));
+               if (*up == NULL)
+                       return ENOMEM;
+       }
+       p->p_udata = &(*up)->u_d;
+       return 0;
 }
index ba936dd..511d14d 100644 (file)
@@ -6,38 +6,40 @@
 
                .globl init_early
                .globl init_hardware
-               .globl _program_vectors
+               .globl program_vectors
                .globl outchar
-               .globl _platform_reboot,_platform_monitor
-               .globl _scroll_down,_scroll_up,_plot_char,_clear_lines
-               .globl _clear_across,_cursor_on,_cursor_off
-               .globl _fontdata_8x8, _screenbase
-               .globl _uarea_block
+               .globl platform_reboot,platform_monitor
+               .globl scroll_down,scroll_up,plot_char,clear_lines
+               .globl clear_across,cursor_on,cursor_off
+               .globl cursor_disable, vtattr_notify
+               .globl fontdata_8x8, screenbase
+               .globl uarea_block
 
 .mri 1
-_platform_reboot:
-_platform_monitor:
+platform_reboot:
+platform_monitor:
            or #0700,sr
-           bra _platform_monitor
+           bra platform_monitor
 init_early:
-           lea.l _uarea_block,a5       ; udata ptr
+           lea.l uarea_block,a5        ; udata ptr
+           move.l a5,udata_shadow
             rts
 
 init_hardware:
             ; set system RAM size
            move.l $42E,d0              ; TOS phystop
-           move.l d0, _memtop;
            lsr.l #8,d0                 ; into KBytes
            lsr.l #2,d0
-           move.w d0,_ramsize
+           move.w d0,ramsize
            sub.w  #64,d0               ; Guess for kernel
-           move.w d0,_procmem          ; guesses for now
+           move.w d0,procmem           ; guesses for now
+           bsr install_vectors
             rts
 
 
 ;      Nothing to do in 68000 - all set up once at boot
 ;
-_program_vectors:
+program_vectors:
            rts
 
 ;
@@ -62,11 +64,9 @@ outcharw:
            move.b d0,$FFFFFA2D
            rts
 
-_scroll_down:
-_scroll_up:
-_plot_char:
+plot_char:
            ; y, x, c
-           move.l _screenbase,a0       ; Screen base from TOS
+           move.l screenbase,a0        ; Screen base from TOS
            move.w 4(sp),d0
            mulu.w #640,d0              ; Always under 64K
            adda.l d0,a0
@@ -74,21 +74,25 @@ _plot_char:
 
            move.w 8(sp),d0             ; character
            lsl.w #3,d0                 ; into font position
-           lea _fontdata_8x8,a1        ; font
+           lea fontdata_8x8,a1 ; font
            adda.w d0,a1
            moveq #7,d1
-_plotit:
+plotit:
            move.b (a1)+,(a0)
            add.l #80,a0
-           dbra d1,_plotit
+           dbra d1,plotit
            rts
 
-_clear_lines:
-_clear_across:
-_cursor_on:
-_cursor_off:
+scroll_down:
+scroll_up:
+clear_lines:
+clear_across:
+cursor_on:
+cursor_off:
+cursor_disable:
+vtattr_notify:
            rts 
 
 .section data
 
-_kernel_flag: byte 1
+kernel_flag: byte 1
index 0e73c14..b98eaa3 100644 (file)
@@ -1,70 +1,3 @@
 #include "../kernel-68000.def"
 
-
-.globl _platfomr_switchout,_switchin,_dofork
-
-.mri 1
-
-; Switchout switches out the current process, finds another that is READY,
-; possibly the same process, and switches it in.  When a process is
-; restarted after calling switchout, it thinks it has just returned
-; from switchout().
-_platform_switchout:
-        or #$0700,sr
-        ; save machine state
-
-        clr.w -(sp) ; return code set here is ignored, but _switchin can 
-        ; return from either _switchout OR _dofork, so they must both write 
-        ; U_DATA__U_SP with the following on the stack:
-       movem.l a0-a4/a6/d0-d7,-(sp)    ; FIXME: trim to callee saves
-       move.l sp,U_DATA__U_SP(a5)      ; this is where the SP is restored in _switchin
-
-        ; set _inint to false
-        clr.b _inint
-
-        ; find another process to run (may select this one again)
-        bsr _getproc
-
-               move.l a0,-(sp)         ; CHECK compiler call/return rules
-        bsr _switchin
-
-        ; we should never get here
-        bra _platform_monitor
-
-badswitchmsg: ascii "_switchin: FAIL"
-            byte 13,10,0
-swapped: ascii "_switchin: SWAPPED"
-            byte 13,10,0
-
-_switchin:
-        or #$0700,sr
-       move.l 4(sp),a0         ; task to switch to
-       move.l P_TAB__P_UDATA_OFFSET(a0),a5
-
-        ; check u_data->u_ptab matches what we wanted
-       move.l 4(sp),d0
-       cmp.l U_DATA__U_PTAB(a5),d0
-       bne switchinfail
-
-       ; wants optimising up a bit
-       move.b #P_RUNNING,P_TAB__P_STATUS_OFFSET(a0)
-
-        ; runticks = 0
-       clr.w _runticks
-
-        ; restore machine state
-        move.l U_DATA__U_SP(a5),sp
-       movem.l (sp)+,a0-a4/a6/d0-d7    ; FIXME: trim to callee saves here too
-
-        tst.b _inint
-        beq keepoff ; in ISR, leave interrupts off
-        and #$F8FF,sr
-keepoff:
-        rts ; return with interrupts on
-
-switchinfail:
-       bsr outa0hex
-        lea badswitchmsg,a0
-        bsr outstring
-       ; something went wrong and we didn't switch in what we asked for
-        bra _platform_monitor
+#include "../lib/68000flat.S"