BSD 4_3_Tahoe release
[unix-history] / usr / src / sys / vax / locore.s
index 76a6b82..53788d4 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)locore.s    7.1 (Berkeley) 6/5/86
+ *     @(#)locore.s    7.12 (Berkeley) 5/27/88
  */
 
 #include "psl.h"
  */
 
 #include "psl.h"
@@ -20,6 +20,7 @@
 #include "clock.h"
 #include "ioa.h"
 #include "ka630.h"
 #include "clock.h"
 #include "ioa.h"
 #include "ka630.h"
+#include "ka820.h"
 #include "../vaxuba/ubareg.h"
 
 #include "dz.h"
 #include "../vaxuba/ubareg.h"
 
 #include "dz.h"
@@ -32,6 +33,7 @@
        .set    MCKVEC,4        # offset into scb of machine check vector
        .set    NBPG,512
        .set    PGSHIFT,9
        .set    MCKVEC,4        # offset into scb of machine check vector
        .set    NBPG,512
        .set    PGSHIFT,9
+       .set    SYSTEM,0x80000000       # virtual address of system start
 
        .set    NISP,3          # number of interrupt stack pages
 
 
        .set    NISP,3          # number of interrupt stack pages
 
@@ -53,9 +55,10 @@ eintstack:
  */
        .align  2
        .globl  _doadump
  */
        .align  2
        .globl  _doadump
+       .globl  _msgbufmapped
 _doadump:
        nop; nop                                # .word 0x0101
 _doadump:
        nop; nop                                # .word 0x0101
-#define        _rpbmap _Sysmap                         # rpb, scb, UNI*vec, istack*4
+#define        _rpbmap _Sysmap                         # rpb, scb, UNIvec[], istack*4
        bicl2   $PG_PROT,_rpbmap
        bisl2   $PG_KW,_rpbmap
        mtpr    $0,$TBIA
        bicl2   $PG_PROT,_rpbmap
        bisl2   $PG_KW,_rpbmap
        mtpr    $0,$TBIA
@@ -67,13 +70,14 @@ _doadump:
        mfpr    $PCBB,-(sp)
        mfpr    $MAPEN,-(sp)
        mfpr    $IPL,-(sp)
        mfpr    $PCBB,-(sp)
        mfpr    $MAPEN,-(sp)
        mfpr    $IPL,-(sp)
+       clrl    _msgbufmapped
        mtpr    $0,$MAPEN
        mtpr    $HIGH,$IPL
        pushr   $0x3fff
        calls   $0,_dumpsys
 1:
        mtpr    $0,$MAPEN
        mtpr    $HIGH,$IPL
        pushr   $0x3fff
        calls   $0,_dumpsys
 1:
-       pushl   $TXDB_BOOT
-       calls   $1,_tocons
+       clrl    r11                             # boot flags
+       calls   $0,_vaxboot
        halt
 
 /*
        halt
 
 /*
@@ -105,12 +109,12 @@ SCBVEC(machcheck):
        .word   5f-0b           # 2 is 750
        .word   5f-0b           # 3 is 730
        .word   7f-0b           # 4 is 8600
        .word   5f-0b           # 2 is 750
        .word   5f-0b           # 3 is 730
        .word   7f-0b           # 4 is 8600
-       .word   1f-0b           # ???
-       .word   1f-0b           # ???
-       .word   1f-0b           # ???
+       .word   5f-0b           # 5 is 8200
+       .word   1f-0b           # 6 is 8800 (unsupported)
+       .word   1f-0b           # 7 is 610  (unsupported)
        .word   1f-0b           # 8 is 630
 5:
        .word   1f-0b           # 8 is 630
 5:
-#if defined(VAX750) || defined(VAX730)
+#if defined(VAX8200) || defined(VAX750) || defined(VAX730)
        mtpr    $0xf,$MCESR
 #endif
        brb     1f
        mtpr    $0xf,$MCESR
 #endif
        brb     1f
@@ -128,21 +132,136 @@ SCBVEC(machcheck):
        movl    nofault,(sp)
        rei
 SCBVEC(kspnotval):
        movl    nofault,(sp)
        rei
 SCBVEC(kspnotval):
-       PUSHR; PANIC("KSP not valid");
+       PANIC("KSP not valid");
 SCBVEC(powfail):
        halt
 SCBVEC(chme): SCBVEC(chms): SCBVEC(chmu):
 SCBVEC(powfail):
        halt
 SCBVEC(chme): SCBVEC(chms): SCBVEC(chmu):
-       PUSHR; PANIC("CHM? in kernel");
-SCBVEC(stray):
-       PUSHR; PRINTF(0, "stray scb interrupt\n"); POPR;
+       PANIC("CHM? in kernel");
+
+SCBVEC(nex0zvec):
+       PUSHR
+       clrl    r0
+       brb     1f
+SCBVEC(nex1zvec):
+       PUSHR
+       movl    $1,r0
+1:
+       cmpl    _cpu,$VAX_8600          # this is a frill
+       beql    2f
+       mfpr    $IPL,-(sp)
+       PRINTF(1, "nexus stray intr ipl%x\n")
+       POPR
+       rei
+2:
+       pushl   r0
+       mfpr    $IPL,-(sp)
+       PRINTF(2, "nexus stray intr ipl%x sbia%d\n")
+       POPR
        rei
        rei
-SCBVEC(nexzvec):
-       PUSHR; mfpr $IPL,-(sp); PRINTF(1, "nexus stray intr ipl%x\n"); POPR; rei
+
 SCBVEC(cmrd):
        PUSHR; calls $0,_memerr; POPR; rei
 SCBVEC(cmrd):
        PUSHR; calls $0,_memerr; POPR; rei
-SCBVEC(wtime):
-       PUSHR; pushl 6*4(sp); PRINTF(1,"write timeout %x\n"); POPR;
-       PANIC("wtimo");
+
+SCBVEC(wtime):                 /* sbi0err on 8600 */
+#if VAX8600
+       cmpl    _cpu,$VAX_8600
+       bneq    wtimo
+       PANIC("sbia0 error")
+wtimo:
+#endif
+       PUSHR; pushl 6*4(sp); PRINTF(1, "write timeout %x\n"); POPR
+       PANIC("wtimo")
+
+SCBVEC(sbi0fail):
+       PANIC("sbia0 fail")
+SCBVEC(sbi0alert):
+#if VAX8200
+       cmpl    _cpu,$VAX_8200
+       bneq    alert
+       PUSHR; calls $0,_rxcdintr; POPR; rei
+alert:
+#endif
+       PANIC("sbia0 alert")
+SCBVEC(sbi0fault):
+       PANIC("sbia0 fault")
+
+#ifdef notyet
+#if VAX8600
+SCBVEC(sbi1fail):
+       PANIC("sbia1 fail")
+SCBVEC(sbi1alert):
+       PANIC("sbia1 alert")
+SCBVEC(sbi1fault):
+       PANIC("sbia1 fault")
+SCBVEC(sbi1err):
+       PANIC("sbia1 error")
+#endif
+#endif
+
+/*
+ * BI 0 bus error (8200), or SBI silo compare error (others)
+ * VMS boot leaves us 1 BI error to ignore.
+ */
+#if VAX8200 && 0
+       .data
+       .align  2
+_ignorebi: .globl _ignorebi
+       .long   1
+       .text
+#endif VAX8200
+
+SCBVEC(sbisilo):
+#if VAX8200
+       cmpl    _cpu,$VAX_8200
+       bneq    sbisilo
+#if 0
+       blbs    _ignorebi,1f
+#else
+       blbs    _cold,1f
+#endif
+       PUSHR; pushl $0; calls $1,_bi_buserr; POPR
+1:
+       rei
+#endif
+sbisilo:
+       PANIC("sbi silo compare error")
+
+/*
+ * SCB stray interrupt catcher.  Compute and print the actual
+ * SCB vector (for fault diagnosis).
+ */
+       .align  2
+_scbstray: .globl _scbstray
+#define        PJ      PUSHR;jsb 1f
+       /* 128 of 'em */
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+#if VAX8600
+       /* and another 128, for the second SBIA's scb */
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+       PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ;PJ
+#endif
+#undef PJ
+1:
+       subl3   $_scbstray+8,(sp)+,r0
+       mfpr    $IPL,-(sp)
+       ashl    $-1,r0,-(sp)
+/* call a C handler instead? perhaps later */
+       PRINTF(2, "stray scb intr vec 0x%x ipl%x\n")
+       POPR
+       rei
 
 #if NMBA > 0
 SCBVEC(mba3int):
 
 #if NMBA > 0
 SCBVEC(mba3int):
@@ -159,7 +278,7 @@ SCBVEC(mba0int):
        rei
 #endif
 
        rei
 #endif
 
-#if defined(VAX780) || defined(VAX8600)
+#ifdef DW780
 /*
  * Registers for the uba handling code
  */
 /*
  * Registers for the uba handling code
  */
@@ -257,15 +376,15 @@ SCBVEC(netintr):
        incl    _cnt+V_SOFT
        rei
 
        incl    _cnt+V_SOFT
        rei
 
-#if defined(VAX750) || defined(VAX730) || defined(VAX8600)
 SCBVEC(consdin):
        PUSHR;
 SCBVEC(consdin):
        PUSHR;
-       incl _intrcnt+I_TUR
-       casel   _cpu,$VAX_750,$VAX_8600
+       incl    _intrcnt+I_TUR
+       casel   _cpu,$VAX_750,$VAX_8200
 0:
        .word   5f-0b           # 2 is VAX_750
        .word   3f-0b           # 3 is VAX_730
        .word   6f-0b           # 4 is VAX_8600
 0:
        .word   5f-0b           # 2 is VAX_750
        .word   3f-0b           # 3 is VAX_730
        .word   6f-0b           # 4 is VAX_8600
+       .word   7f-0b           # 5 is VAX_8200
        halt
 5:
 #if defined(VAX750) && !defined(MRSP)
        halt
 5:
 #if defined(VAX750) && !defined(MRSP)
@@ -273,25 +392,28 @@ SCBVEC(consdin):
 #endif
 3:
 #if defined(VAX750) || defined(VAX730)
 #endif
 3:
 #if defined(VAX750) || defined(VAX730)
-       calls $0,_turintr
-       brb 2f
+       calls   $0,_turintr
+       brb     2f
+#else
+       halt
+#endif
+7:
+#if VAX8200
+       calls   $0,_rx50intr
+       brb     2f
 #else
        halt
 #endif
 6:
 #if VAX8600
 #else
        halt
 #endif
 6:
 #if VAX8600
-       calls $0, _crlintr
+       calls   $0,_crlintr
 #else
        halt
 #endif
 2:
 #else
        halt
 #endif
 2:
-       POPR;
-       incl _cnt+V_INTR;
+       POPR
+       incl    _cnt+V_INTR
        rei
        rei
-#else
-SCBVEC(consdin):
-       halt
-#endif
 
 #if defined(VAX750) || defined(VAX730)
 SCBVEC(consdout):
 
 #if defined(VAX750) || defined(VAX730)
 SCBVEC(consdout):
@@ -511,6 +633,12 @@ tudma:
        rsb
 #endif
 
        rsb
 #endif
 
+/*
+ * BI passive release things.
+ */
+SCBVEC(passiverel):
+       rei                             # well that was useless
+
 /*
  * Stray UNIBUS interrupt catch routines
  */
 /*
  * Stray UNIBUS interrupt catch routines
  */
@@ -599,6 +727,8 @@ SCBVEC(bptflt):
        pushl $0; TRAP(BPTFLT)
 SCBVEC(compatflt):
        TRAP(COMPATFLT);
        pushl $0; TRAP(BPTFLT)
 SCBVEC(compatflt):
        TRAP(COMPATFLT);
+SCBVEC(kdbintr):
+       pushl $0; TRAP(KDBTRAP)
 SCBVEC(tracep):
        pushl $0; TRAP(TRCTRAP)
 SCBVEC(arithtrap):
 SCBVEC(tracep):
        pushl $0; TRAP(TRCTRAP)
 SCBVEC(arithtrap):
@@ -715,21 +845,45 @@ _/**/mname:       .globl  _/**/mname;             \
        SYSMAP(alignmap ,alignutl       ,1              )       /* XXX */
        SYSMAP(msgbufmap,msgbuf         ,MSGBUFPTECNT   )
        SYSMAP(Mbmap    ,mbutl          ,NMBCLUSTERS*CLSIZE+CLSIZE )
        SYSMAP(alignmap ,alignutl       ,1              )       /* XXX */
        SYSMAP(msgbufmap,msgbuf         ,MSGBUFPTECNT   )
        SYSMAP(Mbmap    ,mbutl          ,NMBCLUSTERS*CLSIZE+CLSIZE )
-       SYSMAP(camap    ,cabase         ,16*CLSIZE      )
+       SYSMAP(kmempt   ,kmembase       ,200*CLSIZE     )
 #ifdef GPROF
        SYSMAP(profmap  ,profbase       ,600*CLSIZE     )
 #endif
 #ifdef GPROF
        SYSMAP(profmap  ,profbase       ,600*CLSIZE     )
 #endif
-       SYSMAP(ecamap   ,calimit        ,0              )
+       SYSMAP(ekmempt  ,kmemlimit      ,0              )
 
        SYSMAP(UMBAbeg  ,umbabeg        ,0              )
        SYSMAP(Nexmap   ,nexus          ,16*MAXNNEXUS   )
 
        SYSMAP(UMBAbeg  ,umbabeg        ,0              )
        SYSMAP(Nexmap   ,nexus          ,16*MAXNNEXUS   )
-       SYSMAP(UMEMmap  ,umem           ,UBAPAGES*NUBA  )
+       SYSMAP(UMEMmap  ,umem           ,(UBAPAGES+UBAIOPAGES)*NUBA )
+#if VAX8600
        SYSMAP(Ioamap   ,ioa            ,MAXNIOA*IOAMAPSIZ/NBPG )
        SYSMAP(Ioamap   ,ioa            ,MAXNIOA*IOAMAPSIZ/NBPG )
-       SYSMAP(UMBAend  ,umbaend        ,0              )
+#endif
+#if VAX8200 || VAX630
+       SYSMAP(Clockmap ,ka630clock     ,1              )
+#endif
+#if VAX8200
+       /* alas, the clocks on the 8200 and 630 are not quite identical */
+       /* they could be shared for now, but this seemed cleaner */
+       .globl _ka820clock; .set _ka820clock,_ka630clock
+       SYSMAP(Ka820map ,ka820port      ,1              )
+       SYSMAP(RX50map  ,rx50device     ,1              )
+#ifdef notyet
+       SYSMAP(BRAMmap  ,ka820bootram   ,KA820_BRPAGES  )
+       SYSMAP(EEPROMmap,ka820eeprom    ,KA820_EEPAGES  )
+#endif
+#endif
 #if VAX630
 #if VAX630
-       SYSMAP(Clockmap ,cldevice       ,1              )
        SYSMAP(Ka630map ,ka630cpu       ,1              )
        SYSMAP(Ka630map ,ka630cpu       ,1              )
-#endif
+       /*
+        * qvss and qdss can't coexist - one map will suffice
+        * for either. qvss is 256K each and qdss is 64K each.
+        */
+#include "qv.h"
+#include "qd.h"
+#if NQV > 0 || NQD > 0
+       SYSMAP(QVmap    ,qvmem          ,((512*NQV)+(128*NQD)))
+#endif /* NQV || NQD */
+#endif /* VAX630 */
+       SYSMAP(UMBAend  ,umbaend        ,0              )
 
        SYSMAP(Usrptmap ,usrpt          ,USRPTSIZE+CLSIZE )
 
 
        SYSMAP(Usrptmap ,usrpt          ,USRPTSIZE+CLSIZE )
 
@@ -785,9 +939,18 @@ start:
 1:
 #endif
 /* clear memory from kernel bss and pages for proc 0 u. and page table */
 1:
 #endif
 /* clear memory from kernel bss and pages for proc 0 u. and page table */
-       movab   _edata,r6
-       movab   _end,r5
-       bbcc    $31,r5,0f; 0:
+       movab   _edata,r6; bicl2 $SYSTEM,r6
+       movab   _end,r5; bicl2 $SYSTEM,r5
+#ifdef KADB
+       subl2   $4,r5
+1:     clrl    (r6); acbl r5,$4,r6,1b          # clear just bss
+       addl2   $4,r5
+       bbc     $6,r11,0f                       # check RB_KDB
+       bicl3   $SYSTEM,r9,r5                   # skip symbol & string tables
+       bicl3   $SYSTEM,r9,r6                   # r9 obtained from boot
+#endif
+0:     bisl3   $SYSTEM,r5,r9                   # convert to virtual address
+       addl2   $NBPG-1,r9                      # roundup to next page
        addl2   $(UPAGES*NBPG)+NBPG+NBPG,r5
 1:     clrq    (r6); acbl r5,$8,r6,1b
 /* trap() and syscall() save r0-r11 in the entry mask (per ../h/reg.h) */
        addl2   $(UPAGES*NBPG)+NBPG+NBPG,r5
 1:     clrq    (r6); acbl r5,$8,r6,1b
 /* trap() and syscall() save r0-r11 in the entry mask (per ../h/reg.h) */
@@ -800,14 +963,17 @@ start:
        clrl    r2
        movab   eintstack,r1; bbcc $31,r1,0f; 0: ashl $-PGSHIFT,r1,r1
 1:     bisl3   $PG_V|PG_KW,r2,_Sysmap[r2]; aoblss r1,r2,1b
        clrl    r2
        movab   eintstack,r1; bbcc $31,r1,0f; 0: ashl $-PGSHIFT,r1,r1
 1:     bisl3   $PG_V|PG_KW,r2,_Sysmap[r2]; aoblss r1,r2,1b
-/* make rpb, scb read-only as red zone for interrupt stack */
+/*
+ * make rpb read-only as red zone for interrupt stack
+ * (scb(s) and UNIvec are write-protected later)
+ */
        bicl2   $PG_PROT,_rpbmap
        bisl2   $PG_KR,_rpbmap
 /* make kernel text space read-only */
        movab   _etext+NBPG-1,r1; bbcc $31,r1,0f; 0: ashl $-PGSHIFT,r1,r1
 1:     bisl3   $PG_V|PG_URKR,r2,_Sysmap[r2]; aoblss r1,r2,1b
 /* make kernel data, bss, read-write */
        bicl2   $PG_PROT,_rpbmap
        bisl2   $PG_KR,_rpbmap
 /* make kernel text space read-only */
        movab   _etext+NBPG-1,r1; bbcc $31,r1,0f; 0: ashl $-PGSHIFT,r1,r1
 1:     bisl3   $PG_V|PG_URKR,r2,_Sysmap[r2]; aoblss r1,r2,1b
 /* make kernel data, bss, read-write */
-       movab   _end+NBPG-1,r1; bbcc $31,r1,0f; 0:; ashl $-PGSHIFT,r1,r1
+       bicl3   $SYSTEM,r9,r1; ashl $-PGSHIFT,r1,r1
 1:     bisl3   $PG_V|PG_KW,r2,_Sysmap[r2]; aoblss r1,r2,1b
 /* now go to mapped mode */
        mtpr    $0,$TBIA; mtpr $1,$MAPEN; jmp *$0f; 0:
 1:     bisl3   $PG_V|PG_KW,r2,_Sysmap[r2]; aoblss r1,r2,1b
 /* now go to mapped mode */
        mtpr    $0,$TBIA; mtpr $1,$MAPEN; jmp *$0f; 0:
@@ -816,10 +982,8 @@ start:
        movl    _maxmem,_physmem
        movl    _maxmem,_freemem
 /* setup context for proc[0] == Scheduler */
        movl    _maxmem,_physmem
        movl    _maxmem,_freemem
 /* setup context for proc[0] == Scheduler */
-       movab   _end+NBPG-1,r6
-       bicl2   $NBPG-1,r6              # make page boundary
+       bicl3   $SYSTEM|(NBPG-1),r9,r6  # make phys, page boundary
 /* setup page table for proc[0] */
 /* setup page table for proc[0] */
-       bbcc    $31,r6,0f; 0:
        ashl    $-PGSHIFT,r6,r3                 # r3 = btoc(r6)
        bisl3   $PG_V|PG_KW,r3,_Usrptmap        # init first upt entry
        incl    r3
        ashl    $-PGSHIFT,r6,r3                 # r3 = btoc(r6)
        bisl3   $PG_V|PG_KW,r3,_Usrptmap        # init first upt entry
        incl    r3
@@ -853,6 +1017,7 @@ start:
        mfpr    $P1BR,PCB_P1BR(r1)
        mfpr    $P1LR,PCB_P1LR(r1)
        movl    $CLSIZE,PCB_SZPT(r1)            # init u.u_pcb.pcb_szpt
        mfpr    $P1BR,PCB_P1BR(r1)
        mfpr    $P1LR,PCB_P1LR(r1)
        movl    $CLSIZE,PCB_SZPT(r1)            # init u.u_pcb.pcb_szpt
+       movl    r9,PCB_R9(r1)
        movl    r10,PCB_R10(r1)
        movl    r11,PCB_R11(r1)
        movab   1f,PCB_PC(r1)                   # initial pc
        movl    r10,PCB_R10(r1)
        movl    r11,PCB_R11(r1)
        movab   1f,PCB_PC(r1)                   # initial pc
@@ -869,8 +1034,12 @@ start:
        movl    r10,_bootdev
 /* save reboot flags in global _boothowto */
        movl    r11,_boothowto
        movl    r10,_bootdev
 /* save reboot flags in global _boothowto */
        movl    r11,_boothowto
+#ifdef KADB
+/* save end of symbol & string table in global _bootesym */
+       subl3   $NBPG-1,r9,_bootesym
+#endif
 /* calculate firstaddr, and call main() */
 /* calculate firstaddr, and call main() */
-       movab   _end+NBPG-1,r0; bbcc $31,r0,0f; 0:; ashl $-PGSHIFT,r0,-(sp)
+       bicl3   $SYSTEM,r9,r0; ashl $-PGSHIFT,r0,-(sp)
        addl2   $UPAGES+1,(sp); calls $1,_main
 /* proc[1] == /etc/init now running here; run icode */
        pushl   $PSL_CURMOD|PSL_PRVMOD; pushl $0; rei
        addl2   $UPAGES+1,(sp); calls $1,_main
 /* proc[1] == /etc/init now running here; run icode */
        pushl   $PSL_CURMOD|PSL_PRVMOD; pushl $0; rei
@@ -901,6 +1070,7 @@ l0:        pushab  b`init-l1(pc)
 l1:    pushl   $2
        movl    sp,ap
        chmk    $exec
 l1:    pushl   $2
        movl    sp,ap
        chmk    $exec
+       pushl   r0
        chmk    $exit
 
 init:  .asciz  "/etc/init"
        chmk    $exit
 
 init:  .asciz  "/etc/init"
@@ -1284,6 +1454,46 @@ ENTRY(savectx, 0)
        clrl    r0
        ret
 
        clrl    r0
        ret
 
+#ifdef KADB
+/*
+ * C library -- reset, setexit
+ *
+ *     reset(x)
+ * will generate a "return" from
+ * the last call to
+ *     setexit()
+ * by restoring r6 - r12, ap, fp
+ * and doing a return.
+ * The returned value is x; on the original
+ * call the returned value is 0.
+ */
+ENTRY(setexit, 0)
+       movab   setsav,r0
+       movq    r6,(r0)+
+       movq    r8,(r0)+
+       movq    r10,(r0)+
+       movq    8(fp),(r0)+             # ap, fp
+       movab   4(ap),(r0)+             # sp
+       movl    16(fp),(r0)             # pc
+       clrl    r0
+       ret
+
+ENTRY(reset, 0)
+       movl    4(ap),r0        # returned value
+       movab   setsav,r1
+       movq    (r1)+,r6
+       movq    (r1)+,r8
+       movq    (r1)+,r10
+       movq    (r1)+,r12
+       movl    (r1)+,sp
+       jmp     *(r1)
+
+       .data
+       .align  2
+setsav:        .space  10*4
+       .text
+#endif
+
        .globl  _whichqs
        .globl  _qs
        .globl  _cnt
        .globl  _whichqs
        .globl  _qs
        .globl  _cnt
@@ -1309,7 +1519,7 @@ ENTRY(savectx, 0)
  * Call should be made at splclock(), and p->p_stat should be SRUN
  */
        .align  1
  * Call should be made at splclock(), and p->p_stat should be SRUN
  */
        .align  1
- JSBENTRY(Setrq, R0)
+JSBENTRY(Setrq, R0)
        tstl    P_RLINK(r0)             ## firewall: p->p_rlink must be 0
        beql    set1                    ##
        pushab  set3                    ##
        tstl    P_RLINK(r0)             ## firewall: p->p_rlink must be 0
        beql    set1                    ##
        pushab  set3                    ##
@@ -1331,7 +1541,7 @@ set3:     .asciz  "setrq"
  * Call should be made at splclock().
  */
        .align  1
  * Call should be made at splclock().
  */
        .align  1
- JSBENTRY(Remrq, R0)
+JSBENTRY(Remrq, R0)
        movzbl  P_PRI(r0),r1
        ashl    $-2,r1,r1
        bbsc    r1,_whichqs,rem1
        movzbl  P_PRI(r0),r1
        ashl    $-2,r1,r1
        bbsc    r1,_whichqs,rem1
@@ -1357,7 +1567,6 @@ rem3:     .asciz  "remrq"
 _masterpaddr:
        .long   0
 
 _masterpaddr:
        .long   0
 
-       .set    ASTLVL_NONE,4
        .text
 sw0:   .asciz  "swtch"
 
        .text
 sw0:   .asciz  "swtch"
 
@@ -1367,10 +1576,12 @@ sw0:    .asciz  "swtch"
  */
        .globl  Idle
 Idle: idle:
  */
        .globl  Idle
 Idle: idle:
+       movl    $1,_noproc
        mtpr    $0,$IPL                 # must allow interrupts here
        mtpr    $0,$IPL                 # must allow interrupts here
+1:
        tstl    _whichqs                # look for non-empty queue
        bneq    sw1
        tstl    _whichqs                # look for non-empty queue
        bneq    sw1
-       brb     idle
+       brb     1b
 
 badsw: pushab  sw0
        calls   $1,_panic
 
 badsw: pushab  sw0
        calls   $1,_panic
@@ -1381,24 +1592,25 @@ badsw:  pushab  sw0
  */
        .align  1
 JSBENTRY(Swtch, 0)
  */
        .align  1
 JSBENTRY(Swtch, 0)
-       movl    $1,_noproc
        incl    _cnt+V_SWTCH
 sw1:   ffs     $0,$32,_whichqs,r0      # look for non-empty queue
        beql    idle                    # if none, idle
        mtpr    $0x18,$IPL              # lock out all so _whichqs==_qs
        incl    _cnt+V_SWTCH
 sw1:   ffs     $0,$32,_whichqs,r0      # look for non-empty queue
        beql    idle                    # if none, idle
        mtpr    $0x18,$IPL              # lock out all so _whichqs==_qs
-       bbcc    r0,_whichqs,sw1         # proc moved via lbolt interrupt
+       bbcc    r0,_whichqs,sw1         # proc moved via interrupt
        movaq   _qs[r0],r1
        remque  *(r1),r2                # r2 = p = highest pri process
        bvs     badsw                   # make sure something was there
        movaq   _qs[r0],r1
        remque  *(r1),r2                # r2 = p = highest pri process
        bvs     badsw                   # make sure something was there
-sw2:   beql    sw3
+       beql    sw2
        insv    $1,r0,$1,_whichqs       # still more procs in this queue
        insv    $1,r0,$1,_whichqs       # still more procs in this queue
-sw3:
+sw2:
        clrl    _noproc
        clrl    _runrun
        clrl    _noproc
        clrl    _runrun
+#ifdef notdef
        tstl    P_WCHAN(r2)             ## firewalls
        bneq    badsw                   ##
        cmpb    P_STAT(r2),$SRUN        ##
        bneq    badsw                   ##
        tstl    P_WCHAN(r2)             ## firewalls
        bneq    badsw                   ##
        cmpb    P_STAT(r2),$SRUN        ##
        bneq    badsw                   ##
+#endif
        clrl    P_RLINK(r2)             ##
        movl    *P_ADDR(r2),r0
 #ifdef notdef
        clrl    P_RLINK(r2)             ##
        movl    *P_ADDR(r2),r0
 #ifdef notdef
@@ -1427,20 +1639,20 @@ res0:
 res1:
        movl    _u+PCB_SSWAP,r0                 # longjmp to saved context
        clrl    _u+PCB_SSWAP
 res1:
        movl    _u+PCB_SSWAP,r0                 # longjmp to saved context
        clrl    _u+PCB_SSWAP
-       movq    (r0)+,r6
-       movq    (r0)+,r8
-       movq    (r0)+,r10
-       movq    (r0)+,r12
-       movl    (r0)+,r1
+       movq    (r0)+,r6                        # restore r6, r7
+       movq    (r0)+,r8                        # restore r8, r9
+       movq    (r0)+,r10                       # restore r10, r11
+       movq    (r0)+,r12                       # restore ap, fp
+       movl    (r0)+,r1                        # saved sp
        cmpl    r1,sp                           # must be a pop
        bgequ   1f
        pushab  2f
        calls   $1,_panic
        /* NOTREACHED */
 1:
        cmpl    r1,sp                           # must be a pop
        bgequ   1f
        pushab  2f
        calls   $1,_panic
        /* NOTREACHED */
 1:
-       movl    r1,sp
-       movl    (r0),(sp)                       # address to return to
-       movl    $PSL_PRVMOD,4(sp)               # ``cheating'' (jfr)
+       movl    r1,sp                           # restore sp
+       pushl   $PSL_PRVMOD                     # return psl
+       pushl   (r0)                            # address to return to
        rei
 
 2:     .asciz  "ldctx"
        rei
 
 2:     .asciz  "ldctx"