BSD 4_4_Lite1 release
[unix-history] / usr / src / sys / luna68k / luna68k / locore.s
index 86124c6..5a4260e 100644 (file)
@@ -8,12 +8,38 @@
  * the Systems Programming Group of the University of Utah Computer
  * Science Department.
  *
  * the Systems Programming Group of the University of Utah Computer
  * Science Department.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  *
  * from: Utah $Hdr: locore.s 1.62 92/01/20$
  *
  * from: Utah $Hdr: locore.s 1.62 92/01/20$
- * from: hp300/hp300/locore.s  7.22 (Berkeley) 2/18/93
+ * from: hp300/hp300/locore.s  8.5 (Berkeley) 11/14/93
  *
  *
- *     @(#)locore.s    8.1 (Berkeley) %G%
+ *     @(#)locore.s    8.4 (Berkeley) 12/6/93
  */
 
 /*
  */
 
 /*
@@ -558,7 +584,7 @@ _lev5intr:
        .globl  _panicstr,_badkstack
        cmpl    #_kstack+NBPG,sp        | are we still in stack page?
        jcc     Lstackok                | yes, continue normally
        .globl  _panicstr,_badkstack
        cmpl    #_kstack+NBPG,sp        | are we still in stack page?
        jcc     Lstackok                | yes, continue normally
-       tstl    _curproc                | if !curproc could have swtch_exit'ed,
+       tstl    _curproc                | if !curproc could have switch_exited,
        jeq     Lstackok                |     might be on tmpstk
        tstl    _panicstr               | have we paniced?
        jne     Lstackok                | yes, do not re-panic
        jeq     Lstackok                |     might be on tmpstk
        tstl    _panicstr               | have we paniced?
        jne     Lstackok                | yes, do not re-panic
@@ -910,11 +936,25 @@ Lnocache0:
        movw    #PSL_LOWIPL,sr          | lower SPL
        movl    d7,_boothowto           | save reboot flags
        movl    d6,_bootdev             |   and boot device
        movw    #PSL_LOWIPL,sr          | lower SPL
        movl    d7,_boothowto           | save reboot flags
        movl    d6,_bootdev             |   and boot device
-       jbsr    _main                   | call main()
-
-/* proc[1] == init now running here;
- * create a null exception frame and return to user mode in icode
+/*
+ * Create a fake exception frame that returns to user mode,
+ * make space for the rest of a fake saved register set, and
+ * pass the first available RAM and a pointer to the register
+ * set to "main()".  "main()" will call "icode()", which fakes
+ * an "execve()" system call, which is why we need to do that
+ * ("main()" sets "u.u_ar0" to point to the register set).
+ * When "main()" returns, we're running in process 1 and have
+ * successfully faked the "execve()".  We load up the registers from
+ * that set; the "rte" loads the PC and PSR, which jumps to "init".
  */
  */
+       clrw    sp@-                    | vector offset/frame type
+       clrl    sp@-                    | PC - filled in by "execve"
+       movw    #PSL_USER,sp@-          | in user mode
+       clrw    sp@-                    | pad SR to longword
+       lea     sp@(-64),sp             | construct space for D0-D7/A0-A7
+       pea     sp@                     | addr of space for D0
+       jbsr    _main                   | main(firstaddr, r0)
+       addql   #4,sp                   | pop args
 #if defined(LUNA2)
        cmpl    #-2,_mmutype            | 68040?
        jne     Lnoflush                | no, skip
 #if defined(LUNA2)
        cmpl    #-2,_mmutype            | 68040?
        jne     Lnoflush                | no, skip
@@ -922,10 +962,11 @@ Lnocache0:
        .word   0xf498                  | cinva ic
 Lnoflush:
 #endif
        .word   0xf498                  | cinva ic
 Lnoflush:
 #endif
-       clrw    sp@-                    | vector offset/frame type
-       clrl    sp@-                    | return to icode location 0
-       movw    #PSL_USER,sp@-          | in user mode
-       rte
+       movl    sp@(60),a0              | grab and load
+       movl    a0,usp                  |   user SP
+       moveml  sp@+,#0x7FFF            | load most registers (all but SSP)
+       addql   #6,sp                   | pop SSP and align word
+       rte
 
 /*
  * Signal "trampoline" code (18 bytes).  Invoked from RTE setup by sendsig().
 
 /*
  * Signal "trampoline" code (18 bytes).  Invoked from RTE setup by sendsig().
@@ -955,57 +996,25 @@ _sigcodetrap:
        .align  2
 _esigcode:
 
        .align  2
 _esigcode:
 
-/*
- * Icode is copied out to process 1 to exec init.
- * If the exec fails, process 1 exits.
- */
-       .globl  _icode,_szicode
-       .text
-_icode:
-       clrl    sp@-
-       pea     pc@((argv-.)+2)
-       pea     pc@((init-.)+2)
-       clrl    sp@-
-       moveq   #SYS_execve,d0
-       trap    #0
-       moveq   #SYS_exit,d0
-       trap    #0
-init:
-       .asciz  "/sbin/init"
-       .even
-argv:
-       .long   init+6-_icode           | argv[0] = "init" ("/sbin/init" + 6)
-       .long   eicode-_icode           | argv[1] follows icode after copyout
-       .long   0
-eicode:
-
-_szicode:
-       .long   _szicode-_icode
-
 /*
  * Primitives
  */ 
 
 #ifdef __STDC__
 /*
  * Primitives
  */ 
 
 #ifdef __STDC__
-#define EXPORT(name)   .globl _ ## name; _ ## name:
+#define EXPORT(name)           .globl _ ## name; _ ## name:
 #else
 #else
-#define EXPORT(name)   .globl _/**/name; _/**/name:
+#define EXPORT(name)           .globl _/**/name; _/**/name:
 #endif
 #ifdef GPROF
 #if __GNUC__ >= 2
 #endif
 #ifdef GPROF
 #if __GNUC__ >= 2
-#define        ENTRY(name) \
-       EXPORT(name) link a6,\#0; jbsr mcount; unlk a6
+#define                ENTRY(name)             EXPORT(name) link a6,\#0; jbsr mcount; unlk a6
 #else
 #else
-#define        ENTRY(name) \
-       EXPORT(name) link a6,#0; jbsr mcount; unlk a6
+#define                ENTRY(name)             EXPORT(name) link a6,#0; jbsr mcount; unlk a6
 #endif
 #endif
-#define ALTENTRY(name, rname) \
-       ENTRY(name); jra rname+12
+#define ALTENTRY(name, rname) ENTRY(name); jra rname+12
 #else
 #else
-#define        ENTRY(name) \
-       EXPORT(name)
-#define ALTENTRY(name, rname) \
-       ENTRY(name)
+#define                ENTRY(name)             EXPORT(name)
+#define ALTENTRY(name, rname)          ENTRY(name)
 #endif
 
 /*
 #endif
 
 /*
@@ -1014,12 +1023,45 @@ _szicode:
 ENTRY(__main)
        rts
 
 ENTRY(__main)
        rts
 
+/*
+ * copypage(fromaddr, toaddr)
+ *
+ * Optimized version of bcopy for a single page-aligned NBPG byte copy.
+ */
+ENTRY(copypage)
+       movl    sp@(4),a0               | source address
+       movl    sp@(8),a1               | destination address
+       movl    #NBPG/32,d0             | number of 32 byte chunks
+#if defined(LUNA2)
+       cmpl    #-2,_mmutype            | 68040?
+       jne     Lmlloop                 | no, use movl
+Lm16loop:
+       .long   0xf6209000              | move16 a0@+,a1@+
+       .long   0xf6209000              | move16 a0@+,a1@+
+       subql   #1,d0
+       jne     Lm16loop
+       rts
+#endif
+Lmlloop:
+       movl    a0@+,a1@+
+       movl    a0@+,a1@+
+       movl    a0@+,a1@+
+       movl    a0@+,a1@+
+       movl    a0@+,a1@+
+       movl    a0@+,a1@+
+       movl    a0@+,a1@+
+       movl    a0@+,a1@+
+       subql   #1,d0
+       jne     Lmlloop
+       rts
+
 /*
  * copyinstr(fromaddr, toaddr, maxlength, &lencopied)
  *
  * Copy a null terminated string from the user address space into
  * the kernel address space.
 /*
  * copyinstr(fromaddr, toaddr, maxlength, &lencopied)
  *
  * Copy a null terminated string from the user address space into
  * the kernel address space.
- * NOTE: maxlength must be < 64K
+ *
+ * NOTE: maxlength must be < 64K (due to use of DBcc)
  */
 ENTRY(copyinstr)
        movl    _curpcb,a0              | current pcb
  */
 ENTRY(copyinstr)
        movl    _curpcb,a0              | current pcb
@@ -1101,7 +1143,8 @@ Lcosflt2:
  *
  * Copy a null terminated string from one point to another in
  * the kernel address space.
  *
  * Copy a null terminated string from one point to another in
  * the kernel address space.
- * NOTE: maxlength must be < 64K
+ *
+ * NOTE: maxlength must be < 64K (due to use of DBcc)
  */
 ENTRY(copystr)
        movl    sp@(4),a0               | a0 = fromaddr
  */
 ENTRY(copystr)
        movl    sp@(4),a0               | a0 = fromaddr
@@ -1144,104 +1187,110 @@ Lcsflt2:
  * fixing this code!
  */
 ENTRY(copyin)
  * fixing this code!
  */
 ENTRY(copyin)
+       movl    sp@(12),d0              | get size
+#ifdef MAPPEDCOPY
+       .globl  _mappedcopysize,_mappedcopyin
+       cmpl    _mappedcopysize,d0      | size >= mappedcopysize
+       jcc     _mappedcopyin           | yes, go do it the new way
+#endif
        movl    d2,sp@-                 | scratch register
        movl    _curpcb,a0              | current pcb
        movl    #Lciflt,a0@(PCB_ONFAULT) | set up to catch faults
        movl    d2,sp@-                 | scratch register
        movl    _curpcb,a0              | current pcb
        movl    #Lciflt,a0@(PCB_ONFAULT) | set up to catch faults
-       movl    sp@(16),d2              | check count
+       tstl    d0                      | check count
        jlt     Lciflt                  | negative, error
        jeq     Lcidone                 | zero, done
        movl    sp@(8),a0               | src address
        movl    sp@(12),a1              | dest address
        jlt     Lciflt                  | negative, error
        jeq     Lcidone                 | zero, done
        movl    sp@(8),a0               | src address
        movl    sp@(12),a1              | dest address
-       movl    a0,d0
-       btst    #0,d0                   | src address odd?
+       movl    a0,d2
+       btst    #0,d2                   | src address odd?
        jeq     Lcieven                 | no, go check dest
        movsb   a0@+,d1                 | yes, get a byte
        nop
        movb    d1,a1@+                 | put a byte
        jeq     Lcieven                 | no, go check dest
        movsb   a0@+,d1                 | yes, get a byte
        nop
        movb    d1,a1@+                 | put a byte
-       subql   #1,d2                   | adjust count
+       subql   #1,d0                   | adjust count
        jeq     Lcidone                 | exit if done
 Lcieven:
        jeq     Lcidone                 | exit if done
 Lcieven:
-       movl    a1,d0
-       btst    #0,d0                   | dest address odd?
-       jne     Lcibyte                 | yes, must copy by bytes
-       movl    d2,d0                   | no, get count
-       lsrl    #2,d0                   | convert to longwords
-       jeq     Lcibyte                 | no longwords, copy bytes
-       subql   #1,d0                   | set up for dbf
+       movl    a1,d2
+       btst    #0,d2                   | dest address odd?
+       jne     Lcibloop                | yes, must copy by bytes
+       movl    d0,d2                   | no, get count
+       lsrl    #2,d2                   | convert to longwords
+       jeq     Lcibloop                | no longwords, copy bytes
 Lcilloop:
        movsl   a0@+,d1                 | get a long
        nop
        movl    d1,a1@+                 | put a long
 Lcilloop:
        movsl   a0@+,d1                 | get a long
        nop
        movl    d1,a1@+                 | put a long
-       dbf     d0,Lcilloop             | til done
-       andl    #3,d2                   | what remains
+       subql   #1,d2
+       jne     Lcilloop                | til done
+       andl    #3,d0                   | what remains
        jeq     Lcidone                 | all done
        jeq     Lcidone                 | all done
-Lcibyte:
-       subql   #1,d2                   | set up for dbf
 Lcibloop:
        movsb   a0@+,d1                 | get a byte
        nop
        movb    d1,a1@+                 | put a byte
 Lcibloop:
        movsb   a0@+,d1                 | get a byte
        nop
        movb    d1,a1@+                 | put a byte
-       dbf     d2,Lcibloop             | til done
+       subql   #1,d0
+       jne     Lcibloop                | til done
 Lcidone:
 Lcidone:
-       moveq   #0,d0                   | success
-Lciexit:
        movl    _curpcb,a0              | current pcb
        clrl    a0@(PCB_ONFAULT)        | clear fault catcher
        movl    sp@+,d2                 | restore scratch reg
        rts
 Lciflt:
        moveq   #EFAULT,d0              | got a fault
        movl    _curpcb,a0              | current pcb
        clrl    a0@(PCB_ONFAULT)        | clear fault catcher
        movl    sp@+,d2                 | restore scratch reg
        rts
 Lciflt:
        moveq   #EFAULT,d0              | got a fault
-       jra     Lciexit
+       jra     Lcidone
 
 ENTRY(copyout)
 
 ENTRY(copyout)
+       movl    sp@(12),d0              | get size
+#ifdef MAPPEDCOPY
+       .globl  _mappedcopysize,_mappedcopyout
+       cmpl    _mappedcopysize,d0      | size >= mappedcopysize
+       jcc     _mappedcopyout          | yes, go do it the new way
+#endif
        movl    d2,sp@-                 | scratch register
        movl    _curpcb,a0              | current pcb
        movl    #Lcoflt,a0@(PCB_ONFAULT) | catch faults
        movl    d2,sp@-                 | scratch register
        movl    _curpcb,a0              | current pcb
        movl    #Lcoflt,a0@(PCB_ONFAULT) | catch faults
-       movl    sp@(16),d2              | check count
+       tstl    d0                      | check count
        jlt     Lcoflt                  | negative, error
        jeq     Lcodone                 | zero, done
        movl    sp@(8),a0               | src address
        movl    sp@(12),a1              | dest address
        jlt     Lcoflt                  | negative, error
        jeq     Lcodone                 | zero, done
        movl    sp@(8),a0               | src address
        movl    sp@(12),a1              | dest address
-       movl    a0,d0
-       btst    #0,d0                   | src address odd?
+       movl    a0,d2
+       btst    #0,d2                   | src address odd?
        jeq     Lcoeven                 | no, go check dest
        movb    a0@+,d1                 | yes, get a byte
        movsb   d1,a1@+                 | put a byte
        nop
        jeq     Lcoeven                 | no, go check dest
        movb    a0@+,d1                 | yes, get a byte
        movsb   d1,a1@+                 | put a byte
        nop
-       subql   #1,d2                   | adjust count
+       subql   #1,d0                   | adjust count
        jeq     Lcodone                 | exit if done
 Lcoeven:
        jeq     Lcodone                 | exit if done
 Lcoeven:
-       movl    a1,d0
-       btst    #0,d0                   | dest address odd?
-       jne     Lcobyte                 | yes, must copy by bytes
-       movl    d2,d0                   | no, get count
-       lsrl    #2,d0                   | convert to longwords
-       jeq     Lcobyte                 | no longwords, copy bytes
-       subql   #1,d0                   | set up for dbf
+       movl    a1,d2
+       btst    #0,d2                   | dest address odd?
+       jne     Lcobloop                | yes, must copy by bytes
+       movl    d0,d2                   | no, get count
+       lsrl    #2,d2                   | convert to longwords
+       jeq     Lcobloop                | no longwords, copy bytes
 Lcolloop:
        movl    a0@+,d1                 | get a long
        movsl   d1,a1@+                 | put a long
        nop
 Lcolloop:
        movl    a0@+,d1                 | get a long
        movsl   d1,a1@+                 | put a long
        nop
-       dbf     d0,Lcolloop             | til done
-       andl    #3,d2                   | what remains
+       subql   #1,d2
+       jne     Lcolloop                | til done
+       andl    #3,d0                   | what remains
        jeq     Lcodone                 | all done
        jeq     Lcodone                 | all done
-Lcobyte:
-       subql   #1,d2                   | set up for dbf
 Lcobloop:
        movb    a0@+,d1                 | get a byte
        movsb   d1,a1@+                 | put a byte
        nop
 Lcobloop:
        movb    a0@+,d1                 | get a byte
        movsb   d1,a1@+                 | put a byte
        nop
-       dbf     d2,Lcobloop             | til done
+       subql   #1,d0
+       jne     Lcobloop                | til done
 Lcodone:
 Lcodone:
-       moveq   #0,d0                   | success
-Lcoexit:
        movl    _curpcb,a0              | current pcb
        clrl    a0@(PCB_ONFAULT)        | clear fault catcher
        movl    sp@+,d2                 | restore scratch reg
        rts
 Lcoflt:
        moveq   #EFAULT,d0              | got a fault
        movl    _curpcb,a0              | current pcb
        clrl    a0@(PCB_ONFAULT)        | clear fault catcher
        movl    sp@+,d2                 | restore scratch reg
        rts
 Lcoflt:
        moveq   #EFAULT,d0              | got a fault
-       jra     Lcoexit
+       jra     Lcodone
 
 /*
  * non-local gotos
 
 /*
  * non-local gotos
@@ -1261,12 +1310,11 @@ ENTRY(longjmp)
        rts
 
 /*
        rts
 
 /*
- * The following primitives manipulate the run queues.
- * _whichqs tells which of the 32 queues _qs
- * have processes in them.  Setrq puts processes into queues, Remrq
- * removes them from queues.  The running process is on no queue,
- * other processes are on a queue related to p->p_pri, divided by 4
- * actually to shrink the 0-127 range of priorities into the 32 available
+ * The following primitives manipulate the run queues.  _whichqs tells which
+ * of the 32 queues _qs have processes in them.  Setrunqueue puts processes
+ * into queues, Remrq removes them from queues.  The running process is on
+ * no queue, other processes are on a queue related to p->p_priority, divided
+ * by 4 actually to shrink the 0-127 range of priorities into the 32 available
  * queues.
  */
 
  * queues.
  */
 
@@ -1274,35 +1322,35 @@ ENTRY(longjmp)
        .globl  _curproc,_want_resched
 
 /*
        .globl  _curproc,_want_resched
 
 /*
- * Setrq(p)
+ * Setrunqueue(p)
  *
  * Call should be made at spl6(), and p->p_stat should be SRUN
  */
  *
  * Call should be made at spl6(), and p->p_stat should be SRUN
  */
-ENTRY(setrq)
+ENTRY(setrunqueue)
        movl    sp@(4),a0
        movl    sp@(4),a0
-       tstl    a0@(P_RLINK)
+       tstl    a0@(P_BACK)
        jeq     Lset1
        movl    #Lset2,sp@-
        jbsr    _panic
 Lset1:
        clrl    d0
        jeq     Lset1
        movl    #Lset2,sp@-
        jbsr    _panic
 Lset1:
        clrl    d0
-       movb    a0@(P_PRI),d0
+       movb    a0@(P_PRIORITY),d0
        lsrb    #2,d0
        movl    _whichqs,d1
        bset    d0,d1
        movl    d1,_whichqs
        lslb    #3,d0
        addl    #_qs,d0
        lsrb    #2,d0
        movl    _whichqs,d1
        bset    d0,d1
        movl    d1,_whichqs
        lslb    #3,d0
        addl    #_qs,d0
-       movl    d0,a0@(P_LINK)
+       movl    d0,a0@(P_FORW)
        movl    d0,a1
        movl    d0,a1
-       movl    a1@(P_RLINK),a0@(P_RLINK)
-       movl    a0,a1@(P_RLINK)
-       movl    a0@(P_RLINK),a1
-       movl    a0,a1@(P_LINK)
+       movl    a1@(P_BACK),a0@(P_BACK)
+       movl    a0,a1@(P_BACK)
+       movl    a0@(P_BACK),a1
+       movl    a0,a1@(P_FORW)
        rts
 
 Lset2:
        rts
 
 Lset2:
-       .asciz  "setrq"
+       .asciz  "setrunqueue"
        .even
 
 /*
        .even
 
 /*
@@ -1313,7 +1361,7 @@ Lset2:
 ENTRY(remrq)
        movl    sp@(4),a0
        clrl    d0
 ENTRY(remrq)
        movl    sp@(4),a0
        clrl    d0
-       movb    a0@(P_PRI),d0
+       movb    a0@(P_PRIORITY),d0
        lsrb    #2,d0
        movl    _whichqs,d1
        bclr    d0,d1
        lsrb    #2,d0
        movl    _whichqs,d1
        bclr    d0,d1
@@ -1322,27 +1370,27 @@ ENTRY(remrq)
        jbsr    _panic
 Lrem1:
        movl    d1,_whichqs
        jbsr    _panic
 Lrem1:
        movl    d1,_whichqs
-       movl    a0@(P_LINK),a1
-       movl    a0@(P_RLINK),a1@(P_RLINK)
-       movl    a0@(P_RLINK),a1
-       movl    a0@(P_LINK),a1@(P_LINK)
+       movl    a0@(P_FORW),a1
+       movl    a0@(P_BACK),a1@(P_BACK)
+       movl    a0@(P_BACK),a1
+       movl    a0@(P_FORW),a1@(P_FORW)
        movl    #_qs,a1
        movl    d0,d1
        lslb    #3,d1
        addl    d1,a1
        movl    #_qs,a1
        movl    d0,d1
        lslb    #3,d1
        addl    d1,a1
-       cmpl    a1@(P_LINK),a1
+       cmpl    a1@(P_FORW),a1
        jeq     Lrem2
        movl    _whichqs,d1
        bset    d0,d1
        movl    d1,_whichqs
 Lrem2:
        jeq     Lrem2
        movl    _whichqs,d1
        bset    d0,d1
        movl    d1,_whichqs
 Lrem2:
-       clrl    a0@(P_RLINK)
+       clrl    a0@(P_BACK)
        rts
 
 Lrem3:
        .asciz  "remrq"
 Lsw0:
        rts
 
 Lrem3:
        .asciz  "remrq"
 Lsw0:
-       .asciz  "swtch"
+       .asciz  "switch"
        .even
 
        .globl  _curpcb
        .even
 
        .globl  _curpcb
@@ -1358,27 +1406,27 @@ mdpflag:
        .text
 
 /*
        .text
 
 /*
- * At exit of a process, do a swtch for the last time.
+ * At exit of a process, do a switch for the last time.
  * The mapping of the pcb at p->p_addr has already been deleted,
  * and the memory for the pcb+stack has been freed.
  * The ipl is high enough to prevent the memory from being reallocated.
  */
  * The mapping of the pcb at p->p_addr has already been deleted,
  * and the memory for the pcb+stack has been freed.
  * The ipl is high enough to prevent the memory from being reallocated.
  */
-ENTRY(swtch_exit)
+ENTRY(switch_exit)
        movl    #nullpcb,_curpcb        | save state into garbage pcb
        lea     tmpstk,sp               | goto a tmp stack
        movl    #nullpcb,_curpcb        | save state into garbage pcb
        lea     tmpstk,sp               | goto a tmp stack
-       jra     _cpu_swtch
+       jra     _cpu_switch
 
 /*
 
 /*
- * When no processes are on the runq, Swtch branches to idle
+ * When no processes are on the runq, Swtch branches to Idle
  * to wait for something to come ready.
  */
        .globl  idle
  * to wait for something to come ready.
  */
        .globl  idle
-Lidle:
-       stop    #PSL_LOWIPL
 idle:
 idle:
+       stop    #PSL_LOWIPL
+Idle:
        movw    #PSL_HIGHIPL,sr
        tstl    _whichqs
        movw    #PSL_HIGHIPL,sr
        tstl    _whichqs
-       jeq     Lidle
+       jeq     idle
        movw    #PSL_LOWIPL,sr
        jra     Lsw1
 
        movw    #PSL_LOWIPL,sr
        jra     Lsw1
 
@@ -1388,7 +1436,7 @@ Lbadsw:
        /*NOTREACHED*/
 
 /*
        /*NOTREACHED*/
 
 /*
- * cpu_swtch()
+ * cpu_switch()
  *
  * NOTE: On the mc68851 (318/319/330) we attempt to avoid flushing the
  * entire ATC.  The effort involved in selective flushing may not be
  *
  * NOTE: On the mc68851 (318/319/330) we attempt to avoid flushing the
  * entire ATC.  The effort involved in selective flushing may not be
@@ -1398,7 +1446,7 @@ Lbadsw:
  * user's PTEs have been changed (formerly denoted by the SPTECHG p_flag
  * bit).  For now, we just always flush the full ATC.
  */
  * user's PTEs have been changed (formerly denoted by the SPTECHG p_flag
  * bit).  For now, we just always flush the full ATC.
  */
-ENTRY(cpu_swtch)
+ENTRY(cpu_switch)
        movl    _curpcb,a0              | current pcb
        movw    sr,a0@(PCB_PS)          | save sr before changing ipl
 #ifdef notyet
        movl    _curpcb,a0              | current pcb
        movw    sr,a0@(PCB_PS)          | save sr before changing ipl
 #ifdef notyet
@@ -1421,7 +1469,7 @@ Lswchk:
        addqb   #1,d0
        cmpb    #32,d0
        jne     Lswchk
        addqb   #1,d0
        cmpb    #32,d0
        jne     Lswchk
-       jra     idle
+       jra     Idle
 Lswfnd:
        movw    #PSL_HIGHIPL,sr         | lock out interrupts
        movl    a0@,d1                  | and check again...
 Lswfnd:
        movw    #PSL_HIGHIPL,sr         | lock out interrupts
        movl    a0@,d1                  | and check again...
@@ -1442,13 +1490,13 @@ Lswok:
        lslb    #3,d1                   | convert queue number to index
        addl    #_qs,d1                 | locate queue (q)
        movl    d1,a1
        lslb    #3,d1                   | convert queue number to index
        addl    #_qs,d1                 | locate queue (q)
        movl    d1,a1
-       cmpl    a1@(P_LINK),a1          | anyone on queue?
+       cmpl    a1@(P_FORW),a1          | anyone on queue?
        jeq     Lbadsw                  | no, panic
        jeq     Lbadsw                  | no, panic
-       movl    a1@(P_LINK),a0                  | p = q->p_link
-       movl    a0@(P_LINK),a1@(P_LINK)         | q->p_link = p->p_link
-       movl    a0@(P_LINK),a1                  | q = p->p_link
-       movl    a0@(P_RLINK),a1@(P_RLINK)       | q->p_rlink = p->p_rlink
-       cmpl    a0@(P_LINK),d1          | anyone left on queue?
+       movl    a1@(P_FORW),a0          | p = q->p_forw
+       movl    a0@(P_FORW),a1@(P_FORW) | q->p_forw = p->p_forw
+       movl    a0@(P_FORW),a1          | q = p->p_forw
+       movl    a0@(P_BACK),a1@(P_BACK) | q->p_back = p->p_back
+       cmpl    a0@(P_FORW),d1          | anyone left on queue?
        jeq     Lsw2                    | no, skip
        movl    _whichqs,d1
        bset    d0,d1                   | yes, reset bit
        jeq     Lsw2                    | no, skip
        movl    _whichqs,d1
        bset    d0,d1                   | yes, reset bit
@@ -1484,7 +1532,7 @@ Lswnofpsave:
        cmpb    #SRUN,a0@(P_STAT)
        jne     Lbadsw
 #endif
        cmpb    #SRUN,a0@(P_STAT)
        jne     Lbadsw
 #endif
-       clrl    a0@(P_RLINK)            | clear back link
+       clrl    a0@(P_BACK)             | clear back link
        movb    a0@(P_MDFLAG+3),mdpflag | low byte of p_md.md_flags
        movl    a0@(P_ADDR),a1          | get p_addr
        movl    a1,_curpcb
        movb    a0@(P_MDFLAG+3),mdpflag | low byte of p_md.md_flags
        movl    a0@(P_ADDR),a1          | get p_addr
        movl    a1,_curpcb
@@ -1570,7 +1618,7 @@ Lresfprest:
 /*
  * savectx(pcb, altreturn)
  * Update pcb, saving current processor state and arranging
 /*
  * savectx(pcb, altreturn)
  * Update pcb, saving current processor state and arranging
- * for alternate return ala longjmp in swtch if altreturn is true.
+ * for alternate return ala longjmp in switch if altreturn is true.
  */
 ENTRY(savectx)
        movl    sp@(4),a1
  */
 ENTRY(savectx)
        movl    sp@(4),a1
@@ -1784,7 +1832,6 @@ ENTRY(TBIS)
        rts
 Lmotommu4:
 #endif
        rts
 Lmotommu4:
 #endif
-
        movl    sp@(4),a0               | get addr to flush
        pflush  #0,#0,a0@               | flush address from both sides
        movl    #DC_CLEAR,d0
        movl    sp@(4),a0               | get addr to flush
        pflush  #0,#0,a0@               | flush address from both sides
        movl    #DC_CLEAR,d0
@@ -1942,7 +1989,6 @@ ENTRY(ecacheoff)
 /*
  * Get callers current SP value.
  * Note that simply taking the address of a local variable in a C function
 /*
  * Get callers current SP value.
  * Note that simply taking the address of a local variable in a C function
-
  * doesn't work because callee saved registers may be outside the stack frame
  * defined by A6 (e.g. GCC generated code).
  */
  * doesn't work because callee saved registers may be outside the stack frame
  * defined by A6 (e.g. GCC generated code).
  */