68000: Get tiny68k into a workable state
authorAlan Cox <alan@linux.intel.com>
Mon, 21 Jan 2019 22:24:21 +0000 (22:24 +0000)
committerAlan Cox <alan@linux.intel.com>
Mon, 21 Jan 2019 22:24:21 +0000 (22:24 +0000)
v68 will need to be reworked to deal with the changes

Kernel/lowlevel-68000.S
Kernel/platform-tiny68k/README
Kernel/platform-tiny68k/main.c
Kernel/platform-tiny68k/p68000.S

index 55760c0..17cd3b0 100644 (file)
@@ -381,9 +381,9 @@ SYM (__umodsi3):
                .globl get_usp, set_usp
                .globl outstring,outstringhex,outcharhex,outa0hex
                .globl bus_error,addr_error,illegal,divzero,chk,trapv,priv
-               .globl trace,unimpa,unimpf,trap14,sysc_err
+               .globl trace,unimpa,unimpf,sysc_err
                .globl trap0,trap1,trap2,trap3,trap4,trap5,trap6,trap7
-               .globl trap8,trap9,trap10,trap11,trap12,trap13,trap15
+               .globl trap8,trap9,trap10,trap11,trap12,trap13,trap14,trap15
                .globl spurious,unexpected,uninit
                .globl udata_shadow
                .globl trap_via_signal
@@ -519,12 +519,12 @@ trap10:           move.w sr,-(sp)
 trap11:                move.w sr,-(sp)
                move.w #43,-(sp)
                bra synchronous_exception
-trap12:                move.w sr,-(sp)
-               move.w #44,-(sp)
-               bra synchronous_exception
 trap13:                move.w sr,-(sp)
                move.w #45,-(sp)
                bra synchronous_exception
+trap14:                move.w sr,-(sp)
+               move.w #46,-(sp)
+               bra synchronous_exception
 trap15:                move.w sr,-(sp)
                move.w #47,-(sp)
 
@@ -555,7 +555,7 @@ synchronous_exception:
 ;
 ;              fork is special see the fork code.
 ;
-trap14:
+trap12:
                move.l a5,-(sp)         ; must be first to match fork
                move.l udata_shadow,a5
                move.b d0,U_DATA__U_CALLNO(a5)
@@ -603,6 +603,7 @@ sysc_err:   moveq #-1,d0
 ;
 return_via_signal:
                ; Stack now is return frame,a5
+               move.l (sp)+,a5
                move.w sr,-(sp)
                move.w #0,-(sp)
                movem.l a0-a6/d0-d7,-(sp)
@@ -612,7 +613,6 @@ return_via_signal:
                addq #4,sp
                movem.l (sp)+,a0-a6/d0-d7
                addq #4,sp
-               move.l (sp)+,a5                 ; recover user A5
                rte                             ; into modified handler
 
 spurious:      movem.l a0-a6/d0-d7,-(sp)
index 51f4f3e..4b560be 100644 (file)
@@ -17,27 +17,7 @@ Unsupported right now:
 Known problems
 --------------
 
-Traps need to report their actual trap number and the correct type and
-frame (optionally for userspace)
-Trap need to report extra frame info (eg address of bus error)
-
-Signals need to include trap frame on stack and unwind it or siginfo ptr
-or somesuch ?
-
-Trap/signal recovery is broken somewhere. Easy way to see is when we get
-a hail of errors from fforth. We eventually blow up with signal in kernel mode
-
-We ssig on a trap, but for a synchronous trap we need immediate delivery
-and ssig does not ensure that. What else is needed ? - chksigs and trap
-exit path with signal ?
-       - Directly check masking on our trap
-       - If blocked RTE back
-       - If uncaught act immediately (ignore or kill)
-       - If vectored push pending signal back, push frame and RTE
-         through that frame direct to a signal handler.
-
-
-fforth doesn't work (panic data stack underflow and traps out)
+vi is not getting built linked as such
 
 68010 support - frame sizes needed but also the code to deal with move
 to/from sr from user
@@ -45,31 +25,41 @@ to/from sr from user
 Core dumps are unfinished (need to include trap frame info and a lot
 more)
 
-Something null pointers at boot time (sh)
-       - sh null pointers on ">/var/run/utmp"
-
 Select doesn't work (need new hash algorithm for bigger setups)
 
+Scheduler
+       - linked list of runnables for big boxes
+       - linked list of alarm/timer uses (and need to wrap setting into
+         a function or on small boxes trivial define)
+
 (CURSES lib) invaders always reports that the terminal is too small
 (stty reports rows cols correctly)
 
 All I/O going via buffers
 
-Sometimes get a trap then it repeats
-(various panics - trap then nready panic, switch fail etc)
-
 Is the header and binary start mismatch right (seems to be 0x48 v 0x44)
 
 cpuinfo does not support 68K. Need to probe in kernel and add a new devsys
 ioctl to hand back an arch specific blob ?
 
-Pick a final trap number that is clear of any interesting emulations
 
-Should sh report (core dumped)?
 
 To Do
 -----
 
+Propogate synchronous trap changes to Z80+MMU and Z180 illegal and maybe
+generically jp 0 and 0 corruptor ?
+
+Move lots of p68000.S code into lowlevel-68000.S
+Need some kind of CPU specific C file (or a general one with ifdefs ?) and
+then move lots of platform/main.c into it.
+
+Switch from one process in memory model to flat model with parent first
+and child custom stack build
+
+
+Look into posix spawn functions or vfork and if /bin/sh can use them
+
 DONE Add a 'user touches kernel' catcher on the debug/sim
 DONE ps user/kernel include mismatch error
 DONE (libc bug) calendar does not put a : before 'cannot open file'
@@ -80,4 +70,26 @@ DONE startrek pauses before hit any key to accept message
 DONE (sh longjmp bug) init forgets to run the bootwait stuff
 DONE (sh longjmp bug) shutdown doesn't
 DONE chmem does not support 68K (and fixed size too)
-
+DONE Traps need to report their actual trap number and the correct type and
+     frame (optionally for userspace)
+DONE Trap need to report extra frame info (eg address of bus error)
+DONE We ssig on a trap, but for a synchronous trap we need immediate delivery
+     and ssig does not ensure that. What else is needed ? - chksigs and trap
+     exit path with signal ?
+       - Directly check masking on our trap
+       - If blocked RTE back
+       - If uncaught act immediately (ignore or kill)
+       - If vectored push pending signal back, push frame and RTE
+         through that frame direct to a signal handler.
+DONE (preempt bug I think) Sometimes get a trap then it repeats
+    (various panics - trap then nready panic, switch fail etc)
+DONE Trap/signal recovery is broken somewhere. Easy way to see is when we get
+     a hail of errors from fforth. We eventually blow up with signal in kernel mode
+DONE Something null pointers at boot time (sh)
+       - sh null pointers on ">/var/run/utmp". Historic bug in xec().
+DONE Should sh report (core dumped)?
+DONE fweep needs to build differently for 68K (and build v1-v8)
+DONE (longjmp bug) fforth doesn't work (panic data stack underflow and traps out)
+DONE Signals need to include trap frame on stack and unwind it or siginfo ptr
+or somesuch ?
+DONE Pick a final trap number that is clear of any interesting emulations
index 2aec656..ac899db 100644 (file)
@@ -123,28 +123,55 @@ static void explode(struct trapdata *framedata, int type)
 {
        uint16_t *excp = framedata->exception;
        uint32_t *fv;
-       int i;
+       unsigned int i = framedata->trap;
+       unsigned int j;
+
+       if (i > 12)
+               i = 12;
+
+       for (j = 0; j < i; j++)
+               kputs("   '* ");
+       kputchar('\n');
+       for (j = 0; j < i; j++)
+               kputs("  |   ");
+       kputchar('\n');
+       for (j = 0; j < i; j++)
+               kputs(".###. ");
+       kputchar('\n');
+       for (j = 0; j < i; j++)
+               kputs("##### ");
+       kputchar('\n');
+       for (j = 0; j < i; j++)
+               kputs("##### ");
+       kputchar('\n');
+       for (j = 0; j < i; j++)
+               kputs("`###' ");
+       kputchar('\n');
 
        kprintf("Trap: %d\n", framedata->trap);
        kprintf("Register Dump\nA: ");
-       for (i = 0; i < 8; i++)
+       for (i = 0; i < 7; i++)
                kprintf("%p ", framedata->a[i]);
-       kprintf("\nD: ");
+       kprintf("%p\nD: ", get_usp());
        for (i = 0; i < 8; i++)
                kprintf("%p ", framedata->d[i]);
-       kprintf("\nUSP: %p   SR: %x\n", get_usp(), framedata->sr);
+       kprintf("\nSR: %x\n", framedata->sr);
+
+       kprintf("Exception frame:\n");
+       for (j = 0;j < 16; j++)
+               kprintf("%d: %x\n", j, excp[j]);
 
        /* For now we only do 68000 */
        if (type == FRAME_A) {
                kputs((excp[0] & 0x10)?"R":"W");
-               kprintf(" FC %x\n", excp[0] & 7);
+               kprintf(" FC %x", excp[0] & 7);
                fv = (uint32_t *)(excp + 1);
-               kprintf(" Addr %p IR %x", *fv, excp[3]);
+               kprintf(" Addr %p IR %x ", *fv, excp[3]);
                excp += 4;
        }
        if (type == FRAME_A || type == FRAME_B) {
                fv = (uint32_t *)(excp + 1);
-               kprintf("PC %p SR %x\n", *fv, excp[1]);
+               kprintf("PC %p SR %x\n", *fv, *excp);
        }
 }
 
@@ -189,7 +216,7 @@ int exception(struct trapdata *framedata)
        static const uint8_t trap_to_sig[] = {
                0, 0, SIGSEGV, SIGBUS, SIGILL, SIGFPE,
                SIGABRT/*CHK*/, SIGTRAP/*TRAPV */,
-               SIGILL, SIGIOT, SIGILL, SIGILL };
+               SIGILL, SIGIOT, SIGILL, SIGFPE };
 
        proc = udata.u_ptab;
 
@@ -199,22 +226,20 @@ int exception(struct trapdata *framedata)
        fsize = 3;              /* Three words on 68000 */
        /* TODO: On the 68010 there are at least 4 words as word 4 always holds
           the vector and format */
-       if (trap < 4) {
-               /* TODO: On a 68010 this frame is 29 words and the event is
-                  restartable (although not always usefully). We need to
-                  decide whether to set the restart flag case by case */
-               frame = FRAME_A;
-               fsize = 7;
-       }
-       if (trap < 12)
-               sig = trap_to_sig[sig];
-       else if (trap >= 32 && trap < 48)
-               sig = SIGTRAP;
-       else if (trap == 0) {
+       if (trap == 0) {
                sig = udata.u_cursig;
                udata.u_cursig = 0;
-       }
-
+       } else if (trap < 12) {
+               if (trap < 4) {
+                       /* TODO: On a 68010 this frame is 29 words and the event is
+                          restartable (although not always usefully). We need to
+                          decide whether to set the restart flag case by case */
+                       frame = FRAME_A;
+                       fsize = 7;
+               }
+               sig = trap_to_sig[trap];
+       } else if (trap >= 32 && trap < 48)
+               sig = SIGTRAP;
        /* This processing only applies to synchronous hardware exceptions */
        if (trap) {
                /* Went boom in kernel space or without a user recovery */
@@ -257,8 +282,14 @@ int exception(struct trapdata *framedata)
                rts */
 
        /* Push the recovery PC */
+
+       /* Now update the user stack */
        err |= pushw(&usp, sp[31 + fsize]);
        err |= pushw(&usp, sp[30 + fsize]);
+
+       /* Patch the kernel exception frame */
+       *(uint32_t *)(&sp[30 + fsize]) = (uint32_t)udata.u_sigvec[sig];
+
        /* FIXME: when we do ptrace we will need to support adding the T
           flag back here as the exception cleared it */
        err |= pushw(&usp,  framedata->sr);
@@ -269,7 +300,7 @@ int exception(struct trapdata *framedata)
        err |= pushl(&usp, framedata->d[0]);
 
        /* Remember the target for undoing the frame */
-       unwind = get_usp();
+       unwind = usp;
 
        /* Copy in the signal context itself. 30 words of registers, 2 of
           trap code and then the hardware exception */
index bf00fc9..9704faa 100644 (file)
@@ -105,7 +105,7 @@ timer_irq:
            tst.b U_DATA__U_INSYS(a5)
            bne no_preempt
            tst.b need_resched
-           bne no_preempt
+           beq no_preempt
            ;
            ;   Vanish into the scheduler. Some other task will pop back out
            ;   and eventually we'll re-appear here and continue.
@@ -113,7 +113,12 @@ timer_irq:
            ;   FIXME: check IRQ masking
            ;
            move.l U_DATA__U_PTAB(a5),a0
+           ; We might be in STOPPED state in which case do not go back
+           ; to ready !
+           cmp.b #P_RUNNING,P_TAB__P_STATUS_OFFSET(a0)
+           bne no_ready
            move.b #P_READY,P_TAB__P_STATUS_OFFSET(a0)
+no_ready:
            bsr switchout
 no_preempt:
            tst.b U_DATA__U_CURSIG(a5)
@@ -123,6 +128,7 @@ no_preempt:
            move.w sr,-(sp)
            move.w #0,-(sp)
            movem.l a0-a6/d0-d7,-(sp)
+           move.l (sp),-(sp)
            bsr exception
            addq #4,sp
            movem.l (sp)+,a0-a6/d0-d7
@@ -180,7 +186,7 @@ devide_write_l:
 ;
 ;      'VDSO'
 ;
-vdso:  trap #14                ; syscall entry
+vdso:  trap #12                ; syscall entry
        rts
        ; signal unwind
        move.l 8(sp),sp         ; blow away stack frame