/* locore.s 4.73 82/11/03 */
#include "../vax/nexus.h"
#include "../vaxuba/ubareg.h"
#include "../vax/clock.h"
.set HIGH,0x1f # mask for total disable
.set MCKVEC,4 # offset into scb of machine check vector
.set NISP,3 # number of interrupt stack pages
* User structure is UPAGES at top of user space.
.set _u,0x80000000 - UPAGES*NBPG
* Restart parameter block
* This is filled in in machdep.c in startup().
* It MUST be page aligned.
* When auto-restart occurs, we run restart() in machdep.c, which
* takes a core-dump and then cold-starts.
* Called by auto-restart.
* May be called manually.
#define _rpbmap _Sysmap+8 # scb, UNIvec, rpb, istack*4
tstl _rpb+RP_FLAG # dump only once!
* Interrupt vector routines
#define SCBVEC(name) .align 2; .globl _X/**/name; _X/**/name
#define PANIC(msg) clrl _waittime; pushab 1f; \
calls $1,_panic; 1: .asciz msg
#define PRINTF(n,msg) pushab 1f; calls $n+1,_printf; MSG(msg)
#define MSG(msg) .data; 1: .asciz msg; .text
#define PUSHR pushr $0x3f
PUSHR; pushab 6*4(sp); calls $1,_machinecheck; POPR;
PUSHR; PANIC("KSP not valid");
SCBVEC(chme): SCBVEC(chms): SCBVEC(chmu):
PUSHR; PANIC("CHM? in kernel");
PUSHR; PRINTF(0, "stray scb interrupt\n"); POPR;
PUSHR; mfpr $IPL,-(sp); PRINTF(1, "nexus stray intr ipl%x\n"); POPR; rei
PUSHR; calls $0,_memerr; POPR; rei
PUSHR; pushl 6*4(sp); PRINTF(1,"write timeout %x\n"); POPR;
* Registers for the uba handling code
PUSHR; movl $3,rUBANUM; moval _uba_hd+(3*UH_SIZE),rUBAHD; brb 1f
PUSHR; movl $2,rUBANUM; moval _uba_hd+(2*UH_SIZE),rUBAHD; brb 1f
PUSHR; movl $1,rUBANUM; moval _uba_hd+(1*UH_SIZE),rUBAHD; brb 1f
PUSHR; movl $0,rUBANUM; moval _uba_hd+(0*UH_SIZE),rUBAHD;
mfpr $IPL,r2 /* r2 = mfpr(IPL); */
movl UH_UBA(rUBAHD),rUBA /* uba = uhp->uh_uba; */
movl UBA_BRRVR-0x14*4(rUBA)[r2],rUVEC
/* uvec = uba->uba_brrvr[r2-0x14] */
addl2 UH_VEC(rUBAHD),rUVEC /* uvec += uh->uh_vec */
jmp 2(r1) /* 2 skips ``pushr $0x3f'' */
PUSHR; calls $0,_ubaerror; POPR /* ubaerror r/w's r0-r5 */
tstl rUVEC; jneq ubanorm /* rUVEC contains result */
PUSHR; calls $0,_cnrint; POPR; incl _cnt+V_INTR; rei
PUSHR; calls $0,_cnxint; POPR; incl _cnt+V_INTR; rei
mtpr $ICCS_RUN|ICCS_IE|ICCS_INT|ICCS_ERR,$ICCS
pushl 4+6*4(sp); pushl 4+6*4(sp);
calls $2,_hardclock # hardclock(pc,psl)
pushl 4+6*4(sp); pushl 4+6*4(sp);
incl _cnt+V_INTR ## temp so not to break vmstat -= HZ
pushl 4+6*4(sp); pushl 4+6*4(sp);
calls $2,_softclock # softclock(pc,psl)
#include "../net/netisr.h"
bbcc $NETISR_RAW,_netisr,1f; calls $0,_rawintr; 1:
#include "../netinet/in_systm.h"
bbcc $NETISR_IP,_netisr,1f; calls $0,_ipintr; 1:
bbcc $NETISR_NS,_netisr,1f; calls $0,_nsintr; 1:
#if defined(VAX750) || defined(VAX730)
PUSHR; calls $0,_turintr; POPR; incl _cnt+V_INTR; rei
PUSHR; calls $0,_tuxintr; POPR; incl _cnt+V_INTR; rei
movab _dzpdma(r0),r3 # pdma structure base
movl (r0)+,r1 # device register address
movzbl 1(r1),r2 # get line number
bicb2 $0xf8,r2 # clear garbage bits
addl2 r2,r0 # point at line's pdma structure
cmpl r2,(r0)+ # p_mem < p_end ?
bgequ dzpcall # no, go call dzxint
movb (r2)+,6(r1) # dztbuf = *p_mem++
brb dzploop # check for another line
pushl (r0)+ # push tty address
calls $1,*(r0) # call interrupt rtn
brb dzploop # check for another line
* Stray UNIBUS interrupt catch routines
#define PJ PUSHR;jsb _Xustray
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
subl3 $_catcher+8,(sp)+,r10
subl3 $_catcher+8,(sp)+,r0
PRINTF(2, "uba?: stray intr ipl %x vec %o\n")
* Trap and fault vector routines
#define TRAP(a) pushl $T_/**/a; jbr alltraps
* Ast delivery (profiling and/or reschedule)
pushl $0; TRAP(PRIVINFLT)
mfpr $USP,-(sp); calls $0,_trap; mtpr (sp)+,$USP
addl2 $8,sp # pop type, code
mtpr $HIGH,$IPL ## dont go to a higher IPL (GROT)
mfpr $USP,-(sp); calls $0,_syscall; mtpr (sp)+,$USP
addl2 $8,sp # pop type, code
mtpr $HIGH,$IPL ## dont go to a higher IPL (GROT)
#define vaddr(x) ((((x)-_Sysmap)/4)*NBPG+0x80000000)
#define SYSMAP(mname, vname, npte) \
_/**/mname: .globl _/**/mname; \
.set _/**/vname,vaddr(_/**/mname)
SYSMAP(Sysmap ,Sysbase ,SYSPTSIZE )
SYSMAP(UMBAbeg ,umbabeg ,0 )
SYSMAP(Nexmap ,nexus ,16*MAXNNEXUS )
SYSMAP(UMEMmap ,umem ,512*MAXNUBA )
SYSMAP(UMBAend ,umbaend ,0 )
SYSMAP(Usrptmap ,usrpt ,USRPTSIZE )
SYSMAP(Forkmap ,forkutl ,UPAGES )
SYSMAP(Xswapmap ,xswaputl ,UPAGES )
SYSMAP(Xswap2map,xswap2utl ,UPAGES )
SYSMAP(Swapmap ,swaputl ,UPAGES )
SYSMAP(Pushmap ,pushutl ,UPAGES )
SYSMAP(Vfmap ,vfutl ,UPAGES )
SYSMAP(CMAP1 ,CADDR1 ,1 )
SYSMAP(CMAP2 ,CADDR2 ,1 )
SYSMAP(msgbufmap,msgbuf ,MSGBUFPTECNT )
SYSMAP(camap ,cabase ,16*CLSIZE )
SYSMAP(ecamap ,calimit ,0 )
SYSMAP(Mbmap ,mbutl ,NMBCLUSTERS*CLSIZE)
.set _Syssize,(eSysmap-_Sysmap)/4
* ipl 0x1f; mapen 0; scbb, pcbb, sbr, slr, isp, ksp not set
/* set system control block base and system page table params */
mtpr $_scb-0x80000000,$SCBB
mtpr $_Sysmap-0x80000000,$SBR
/* double map the kernel into the virtual user addresses of phys mem */
/* set ISP and get cpu type */
movl $_intstack+NISP*NBPG,sp
movl r0,(r0)+ # rp_selfref
movl r1,(r0)+ # rp_dumprout
1: addl2 (r1)+,r3; sobgtr r2,1b
movl r3,(r0)+ # rp_chksum
1: pushl $4; pushl r7; calls $2,_badaddr; tstl r0; bneq 9f
acbl $8192*1024-1,$64*1024,r7,1b
/* clear memory from kernel bss and pages for proc 0 u. and page table */
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) */
/* initialize system page table: scb and int stack writeable */
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 read-only as red zone for interrupt stack */
/* 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_KR,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
1: bisl3 $PG_V|PG_KW,r2,_Sysmap[r2]; aoblss r1,r2,1b
/* now go to mapped mode */
mtpr $1,$TBIA; mtpr $1,$MAPEN; jmp *$0f; 0:
ashl $-PGSHIFT,r7,_maxmem
/* setup context for proc[0] == Scheduler */
bicl2 $NBPG-1,r6 # make page boundary
/* setup page table for proc[0] */
ashl $-PGSHIFT,r6,r3 # r3 = btoc(r6)
bisl3 $PG_V|PG_KW,r3,_Usrptmap # init first upt entry
moval -4*UPAGES(r0)[r1],r2
/* setup mapping for UPAGES of _u */
movl $UPAGES,r2; movab _u+NBPG*UPAGES,r1; addl2 $UPAGES,r3; jbr 2f
bisl3 $PG_V|PG_URKW,r3,-(r0)
/* initialize (slightly) the pcb */
movab UPAGES*NBPG(r1),PCB_KSP(r1)
movb $4,PCB_P0LR+3(r1) # disable ast
movl $CLSIZE,PCB_SZPT(r1) # init u.u_pcb.pcb_szpt
movab 1f,PCB_PC(r1) # initial pc
clrl PCB_PSL(r1) # mode(k,k), ipl=0
mtpr r3,$PCBB # first pcbb
/* set regs, p0br, p0lr, p1br, p1lr, astlvl, ksp and change to kernel mode */
/* put signal trampoline code in u. area */
movc3 $12,sigcode,PCB_SIGC(r0)
/* save reboot flags in global _boothowto */
/* calculate firstaddr, and call main() */
movab _end+NBPG-1,r0; bbcc $31,r0,0f; 0:; 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
/* signal trampoline code: it is known that this code takes exactly 12 bytes */
/* in ../h/pcb.h and in the movc3 above */
.word 0x7f # registers 0-6 (6==sp/compat)
* see if access addr with a len type instruction causes a machine check
* len is length of access (1=byte, 2=short, 4=long)
movab 9f+INTSTK,_scb+MCKVEC
1: bbc $1,r4,1f; tstw (r3)
1: bbc $2,r4,1f; tstl (r3)
1: clrl r0 # made it w/o machine checks
#if defined(VAX750) || defined(VAX730)
addl2 (sp)+,sp # discard mchchk trash
_Copyin: .globl _Copyin # <<<massaged for jsb by asm.sed>>>
movl 12(sp),r0 # copy length
movl 4(sp),r1 # copy user address
cmpl $NBPG,r0 # probing one page or less ?
prober $3,$NBPG,(r1) # bytes accessible ?
addl2 $NBPG,r1 # incr user address ptr
acbl $NBPG+1,$-NBPG,r0,ciloop # reduce count and loop
prober $3,r0,(r1) # bytes accessible ?
_Copyout: .globl _Copyout # <<<massaged for jsb by asm.sed >>>
movl 12(sp),r0 # get count
movl 8(sp),r1 # get user address
cmpl $NBPG,r0 # can do in one probew?
probew $3,$NBPG,(r1) # bytes accessible?
addl2 $NBPG,r1 # increment user address
acbl $NBPG+1,$-NBPG,r0,coloop # reduce count and loop
probew $3,r0,(r1) # bytes accessible?
cmpl r1,sp # must be a pop
* The following primitives use the fancy VAX instructions
* much like VMS does. _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
* Setrq(p), using fancy VAX instructions.
* Call should be made at spl6(), and p->p_stat should be SRUN
.globl _Setrq # <<<massaged to jsb by "asm.sed">>>
tstl P_RLINK(r0) ## firewall: p->p_rlink must be 0
movzbl P_PRI(r0),r1 # put on queue which is p->p_pri / 4
insque (r0),*4(r2) # at end of queue
bbss r1,_whichqs,set2 # mark queue non-empty
* Remrq(p), using fancy VAX instructions
* Call should be made at spl6().
.globl _Remrq # <<<massaged to jsb by "asm.sed">>>
pushab rem3 # it wasn't recorded to be on its q
clrl P_RLINK(r0) ## for firewall checking
* Masterpaddr is the p->p_addr of the running process on the master
* processor. When a multiprocessor system, the slave processors will have
* an array of slavepaddr's.
* Swtch(), using fancy VAX instructions
_Swtch: # <<<massaged to jsb by "asm.sed">>>
sw1: ffs $0,$32,_whichqs,r0 # look for non-empty queue
mtpr $0,$IPL # must allow interrupts here
jbr sw1 # this is an idle loop!
sw1a: mtpr $0x18,$IPL # lock out all so _whichqs==_qs
bbcc r0,_whichqs,sw1 # proc moved via lbolt interrupt
remque *(r1),r2 # r2 = p = highest pri process
bvc sw2 # make sure something was there
insv $1,r0,$1,_whichqs # still more procs in this queue
tstl P_WCHAN(r2) ## firewalls
ashl $PGSHIFT,r0,r0 # r0 = pcbb(p)
/* mfpr $PCBB,r1 # resume of current proc is easy
.globl _Resume # <<<massaged to jsb by "asm.sed">>>
mtpr $0x18,$IPL # no interrupts, please
movl _CMAP2,_u+PCB_CMAP2 # yech
movl _u+PCB_CMAP2,_CMAP2 # yech
movl $PSL_PRVMOD,4(sp) # ``cheating'' (jfr)
* {fu,su},{byte,word}, all massaged by asm.sed to jsb's
* Copy 1 relocation unit (NBPG bytes)
* from user virtual address to physical address
_copyseg: .globl _copyseg
bisl3 $PG_V|PG_KW,8(ap),_CMAP2
mtpr $_CADDR2,$TBIS # invalidate entry for copy
movc3 $NBPG,*4(ap),_CADDR2
* zero out physical memory
* specified in relocation units (NBPG bytes)
_clearseg: .globl _clearseg
bisl3 $PG_V|PG_KW,4(ap),_CMAP1
movc5 $0,(sp),$0,$NBPG,_CADDR1
* Given virtual address, byte count, and rw flag
* returns 0 on no access.
_useracc: .globl _useracc
tstl 12(ap) # test for read access ?
cmpl $NBPG,r1 # can we do it in one probe ?
acbl $NBPG+1,$-NBPG,r1,uaw1
acbl $NBPG+1,$-NBPG,r1,uar1
* kernacc - check for kernel access privileges
* We can't use the probe instruction directly because
* it ors together current and previous mode.
movl 4(ap),r0 # virtual address
mfpr $SBR,r2 # address and length of page table (system)
mfpr $P1BR,r2 # user P1 (stack)
addl3 8(ap),r0,r1 # ending virtual address
blss kacerr # address too low
cmpl r1,r3 # compare last page to P0LR or SLR
bgtr kacerr # address too high
bbc $31,r3,kacerr # valid bit is off
cmpzv $27,$4,r3,$1 # check protection code
bleq kacerr # no access allowed
bneq kacc5 # only check read access
cmpzv $27,$2,r3,$3 # check low 2 bits of prot code
beql kacerr # no write access
aoblss r1,r0,kacc4 # next page