From: sms@WLV.IIPO.GTEGSC.COM (Steven M. Schultz)
Subject: TOY clock support for the 11/93 and 11/94 (#72)
Organization: GTE Government Systems
Date: Sat, 29 Aug 92 07:53:49 GMT

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	c
#	toy.s
# This archive created: Sat Aug 29 00:33:00 1992
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'c'
then
	echo shar: "will not over-write existing file 'c'"
else
sed 's/^X//' << \SHAR_EOF > 'c'
XSubject: TOY clock support for the 11/93 and 11/94 (#72)
XIndex:	sys/<several> 2.11BSD
X
XDescription:
X
X	Time Of Year clock support has come to 2.11BSD at last.  In order
X	to add this new feature the cpu type probe code had to be totally
X	rewritten.  /boot will now properly announce an 84 as an 84 rather
X	than 44 and the more recent additions to the pdp-11 family will
X	also be correctly announced when as "93boot" and "94boot".
X
X	The first few diffs add "toy.s" and "toy.o" to the _prototype_
X	makefiles, you will have to add similar modifications to your locally
X	configured kernel Make.files.  It's not hard, just add toy.s in
X	the same place as the diffs do, the toy.o can be put wherever
X	you have about 500 bytes (it was a _lot_ of fun squeezing it down
X	that tight.  Whee!) free in an overlay - the code's only called
X	once so placement is definitely non critical.
X
X	On 11/93 and 11/94 systems (the TOY code checks the cputype and
X	returns an "error" which is ignored if not on a 93 or 94) the TOY 
X	clock is read at system startup time just after the root filesystem 
X	is mounted, overriding the time read from the superblock.
X
X	NOTE:  The toy clock MUST be set (via the ODT monitor) to run
X	on UCT (otherwise known as GMT).  The 'date', usw.  commands will
X	provide the necessary timezone and daylight savings time corrections.
X	(can you imagine trying to put the Elz timezone stuff in the _kernel_?)
X
X	The cpu probe logic was removed from the kernel - there was no
X	sense in replicating the effort which /boot went thru.  The cputype
X	is passed thru from /boot and the kernel takes advantage of that
X	fact.  ALSO, the 'dump code (hardly _ever_ used any more since
X	autoreboot with crash dump capability was added) in mch_dump.s
X	was streamlined - it pays attention to whether or not a Unibus
X	Map is present, _not_ simply whether the cpu type is 44 or 70.
X
X	In init_main.c there the "auto attach" call (the loop which
X	previously called _every_ driver's "XXroot" entry point) has
X	changed.  This happened quite a while ago (locally) when a second
X	MSCP controller was added and i wanted to boot from it rather than
X	the default/"first" controller.  The comments in that diff should
X	make it clear what's going on - but a brief summary here might be
X	a good idea:
X
X		All drivers work as before, in fact they don't even know
X		the protocol has changed!
X
X		/boot passes thru both the unit number _and_ CSR of the
X		controller from which the boot block was loaded.  The
X		kernel now pays attention to this information, but a way
X		was needed to pass it along to the driver which handles
X		the system disc [N.B. the kernel still only understands
X		booting from unit 0 - but it can be on _any_ controller].
X		The "auto attach" loop was removed (why attach every possible
X		controller when all that's needed is the drive we booted 
X		from - and possibly the swap device?) and in its place
X		two calls to the "root" and "swap" device drivers made.
X
X		As of now only the MSCP (ra.c) driver has been modified
X		to handle this situation - all other drivers use hardcoded
X		CSR addresses in their XXroot() routine.  I have not as
X		yet posted the diffs to the ra.c driver - the changes
X		to init_main.c will not be noticed by older ra.c drivers.
X
X		The ra.c changes (not yet posted) include a new and (i think) 
X		vastly superior partition scheme, it's not a substitute for
X		labels, but it does recognize _all_ MSCP drives! This change 
X		was made necessary by the need to get 2.11BSD up on a 93 with
X		RZ23L and RZ24L drives without adding _yet more_ tables
X		to ra.c.  Watch for it Real Soon Now on comp.bugs.2bsd
X
X	The changes have been tested on an 11/44, 11/73, 11/84 and 11/93.  
X
X	Hats off and many many thanks to Terry Kennedy for the 11/93
X	"donated" (bent or warped? ;-)) to the 2.11BSD effort!  The TOY 
X	support wouldn't have been possible without his help.  Thank you.
X
XRepeat-By:
X
X	Not really applicable, it's all "new" stuff/features.
X
XFix:
X	Assuming you've kept up with the previous fixes posted (available
X	by request, i'm also working up a "master patch set" from the base
X	2.11BSD kit) these patches should apply with no problems.  Apply
X	the patches below and remake the kernel and /boot.  If you're 
X	really paranoid make sure you have an old boot tape handy.  But
X	definitely _do_ try this at home :-)
X
X	This fix is in two parts (both included).  First unshar this
X	file, it will produce two files: /tmp/c and /tmp/toy.s.  Move
X	/tmp/toy.s to /sys/pdp/toy.s:  mv /tmp/toy.s /sys/pdp/toy.s.
X
X	Then apply the rest of the patch by:  patch -p0 < /tmp/c
X
X=================================cut here==================================
X*** /usr/src/sys/conf/Make.pdp.old	Fri Sep  2 20:20:58 1988
X--- /usr/src/sys/conf/Make.pdp	Sat Jul 11 23:07:00 1992
X***************
X*** 32,43 ****
X  	${M}/mch_click.s ${M}/mch_copy.s ${M}/mch_csv.s ${M}/mch_dump.s \
X  	${M}/mch_dzpdma.s ${M}/mch_fpsim.s ${M}/mch_KScall.s \
X  	${M}/mch_profile.s ${M}/mch_start.s ${M}/mch_trap.s \
X! 	${M}/mch_vars.s ${M}/mch_xxx.s ${M}/scb.s
X  SOBJS=	libc_bcmp.o libc_bcopy.o libc_bzero.o libc_ffs.o libc_insque.o \
X  	libc_ldiv.o libc_lmul.o libc_lrem.o libc_remque.o libc_strlen.o \
X  	libc_udiv.o mch_backup.o mch_click.o mch_copy.o mch_csv.o \
X  	mch_dump.o mch_dzpdma.o mch_fpsim.o mch_KScall.o mch_profile.o \
X! 	mch_start.o mch_trap.o mch_vars.o mch_xxx.o scb.o
X  
X  .c.o:
X  	${CC} ${CFLAGS} -S $*.c
X--- 32,43 ----
X  	${M}/mch_click.s ${M}/mch_copy.s ${M}/mch_csv.s ${M}/mch_dump.s \
X  	${M}/mch_dzpdma.s ${M}/mch_fpsim.s ${M}/mch_KScall.s \
X  	${M}/mch_profile.s ${M}/mch_start.s ${M}/mch_trap.s \
X! 	${M}/mch_vars.s ${M}/mch_xxx.s ${M}/scb.s ${M}/toy.s
X  SOBJS=	libc_bcmp.o libc_bcopy.o libc_bzero.o libc_ffs.o libc_insque.o \
X  	libc_ldiv.o libc_lmul.o libc_lrem.o libc_remque.o libc_strlen.o \
X  	libc_udiv.o mch_backup.o mch_click.o mch_copy.o mch_csv.o \
X  	mch_dump.o mch_dzpdma.o mch_fpsim.o mch_KScall.o mch_profile.o \
X! 	mch_start.o mch_trap.o mch_vars.o mch_xxx.o scb.o toy.o
X  
X  .c.o:
X  	${CC} ${CFLAGS} -S $*.c
X*** /usr/src/sys/conf/Make.nsunix.old	Sun Dec 22 16:15:43 1991
X--- /usr/src/sys/conf/Make.nsunix	Sat Jul 11 23:13:10 1992
X***************
X*** 74,80 ****
X  	sys_pipe.o
X  # OV6 gets the (hopefully) never used routines
X  OV6=	clock.o dn.o init_main.o kern_pdp.o machdep2.o subr_prf.o syscalls.o \
X! 	subr_log.o
X  OV7=	tmscp.o
X  
X  KERNOBJ=${CONF} ${BASE} ${OV1} ${OV2} ${OV3} ${OV4} ${OV5} \
X--- 74,80 ----
X  	sys_pipe.o
X  # OV6 gets the (hopefully) never used routines
X  OV6=	clock.o dn.o init_main.o kern_pdp.o machdep2.o subr_prf.o syscalls.o \
X! 	subr_log.o toy.o
X  OV7=	tmscp.o
X  
X  KERNOBJ=${CONF} ${BASE} ${OV1} ${OV2} ${OV3} ${OV4} ${OV5} \
X*** /usr/src/sys/conf/Make.sunix.old	Sun Dec 22 16:16:31 1991
X--- /usr/src/sys/conf/Make.sunix	Sat Jul 11 23:13:33 1992
X***************
X*** 58,64 ****
X  	kern_xxx.o machdep2.o quota_sys.o subr_prf.o sys_process.o \
X  	syscalls.o ufs_mount.o
X  OV4=	hk.o init_main.o kern_prot.o tty_pty.o quota_kern.o quota_subr.o \
X! 	quota_ufs.o subr_log.o vm_swap.o vm_proc.o
X  OV5=	ht.o tm.o ts.o
X  OV6=	tmscp.o
X  
X--- 58,64 ----
X  	kern_xxx.o machdep2.o quota_sys.o subr_prf.o sys_process.o \
X  	syscalls.o ufs_mount.o
X  OV4=	hk.o init_main.o kern_prot.o tty_pty.o quota_kern.o quota_subr.o \
X! 	quota_ufs.o subr_log.o vm_swap.o vm_proc.o toy.o
X  OV5=	ht.o tm.o ts.o
X  OV6=	tmscp.o
X  
X*** /usr/src/sys/conf/Make.unix.old	Thu Feb 20 13:33:30 1992
X--- /usr/src/sys/conf/Make.unix	Sat Jul 11 23:14:10 1992
X***************
X*** 55,61 ****
X  	kern_subr.o kern_synch.o kern_time.o kern_xxx.o lp.o machdep.o \
X  	machdep2.o mem.o quota_kern.o quota_subr.o quota_sys.o \
X  	quota_ufs.o ra.o ram.o rk.o rl.o rx.o si.o subr_prf.o subr_rmap.o \
X! 	subr_xxx.o sys_generic.o sys_inode.o sys_kern.o 		\
X  	sys_pipe.o sys_process.o syscalls.o tm.o trap.o tmscp.o ts.o tty.o \
X  	tty_conf.o tty_pty.o tty_subr.o tty_tb.o tty_tty.o ufs_alloc.o \
X  	ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o \
X--- 55,61 ----
X  	kern_subr.o kern_synch.o kern_time.o kern_xxx.o lp.o machdep.o \
X  	machdep2.o mem.o quota_kern.o quota_subr.o quota_sys.o \
X  	quota_ufs.o ra.o ram.o rk.o rl.o rx.o si.o subr_prf.o subr_rmap.o \
X! 	subr_xxx.o sys_generic.o sys_inode.o sys_kern.o toy.o \
X  	sys_pipe.o sys_process.o syscalls.o tm.o trap.o tmscp.o ts.o tty.o \
X  	tty_conf.o tty_pty.o tty_subr.o tty_tb.o tty_tty.o ufs_alloc.o \
X  	ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o \
X*** /usr/src/sys/sys/init_main.c.old	Sun Sep 22 09:50:36 1991
X--- /usr/src/sys/sys/init_main.c	Sun Jul 12 16:27:15 1992
X***************
X*** 46,54 ****
X--- 46,57 ----
X   */
X  main()
X  {
X+ 	extern dev_t bootdev;
X+ 	extern caddr_t bootcsr;
X  	register struct proc *p;
X  	register int i;
X  	register struct fs *fs;
X+ 	time_t  toytime, toyclk();
X  
X  	startup();
X  
X***************
X*** 94,101 ****
X  	nchinit();
X  	clkstart();
X  
X! 	for (i = 0; i < nblkdev; i++)
X! 		(void)(*bdevsw[i].d_root)();
X  	(*bdevsw[major(swapdev)].d_open)(swapdev, B_READ);
X  	fs = mountfs(rootdev, boothowto & RB_RDONLY, (struct inode *)0);
X  	if (!fs)
X--- 97,118 ----
X  	nchinit();
X  	clkstart();
X  
X! /*
X!  * Need to attach the root device.  The CSR is passed thru because this
X!  * may be a 2nd or 3rd controller rather than the 1st.  NOTE: This poses
X!  * a big problem if 'swapdev' is not on the same controller as 'rootdev'
X!  * _or_ if 'swapdev' itself is on a 2nd or 3rd controller.  Short of moving
X!  * autconfigure back in to the kernel it is not known what can be done about
X!  * this.
X!  *
X!  * As a "compatibility hack" call swapdev's attach routine with a zero
X!  * address.  The MSCP driver treats the 0 as a signal to perform the
X!  * old (fixed address) attach.  Drivers (all the rest at this point) which
X!  * do not support alternate controller booting always attach the first
X!  * (primary) CSR and do not expect an argument to be passed.
X! */
X! 	(void)(*bdevsw[major(bootdev)].d_root)(bootcsr);
X! 	(void)(*bdevsw[major(swapdev)].d_root)((caddr_t) 0);	/* XXX */
X  	(*bdevsw[major(swapdev)].d_open)(swapdev, B_READ);
X  	fs = mountfs(rootdev, boothowto & RB_RDONLY, (struct inode *)0);
X  	if (!fs)
X***************
X*** 104,109 ****
X--- 121,128 ----
X  	fs->fs_fsmnt[0] = '/';
X  	fs->fs_fsmnt[1] = '\0';
X  	time.tv_sec = fs->fs_time;
X+ 	if	(toytime = toyclk())
X+ 		time.tv_sec = toytime;
X  	boottime = time;
X  
X  /* kick off timeout driven events by calling first time */
X*** /usr/src/sys/pdp/mch_start.s.old	Sat Apr 20 21:44:52 1991
X--- /usr/src/sys/pdp/mch_start.s	Fri Jul  3 23:21:46 1992
X***************
X*** 4,9 ****
X--- 4,10 ----
X   * specifies the terms and conditions for redistribution.
X   *
X   *	@(#)mch_start.s	1.1 (2.10BSD Berkeley) 6/11/88
X+  *			1.2 (2.11BSD GTE) 7/03/92
X   */
X  
X  #include "DEFS.h"
X***************
X*** 15,20 ****
X--- 16,22 ----
X  	bit	$1,SSR0			/ is memory management enabled?
X  	beq	.			/ better be !!!
X  
X+ 	mov	r0,_cputype		/ save cpu type passed by boot
X  	/*
X  	 * The following two instructions change the contents of the "sys"
X  	 * instruction vector (034-037) to read:
X***************
X*** 137,142 ****
X--- 139,149 ----
X   * on any processor but still take advantage of hardware that is present.
X   * This is also a plus for a site which wants to maintain one kernel for a
X   * number of different processors.
X+  *
X+  * Might as well use the cpu type from /boot after all the hoops it jumped
X+  * thru to figure it out.  No sense in duplicating that code here in the
X+  * kernel.  /boot also stuffed the right bits into the MSCR register to 
X+  * disable cache and unibus traps.
X   */
X  hardprobe:
X  	mov	$1f,nofault
X***************
X*** 147,160 ****
X  	/*
X  	 * Test for SSR3 and UNIBUS map capability.  If there is no SSR3, the
X  	 * first test of SSR3 will trap and we skip past the separate I/D test.
X  	 */
X! 	mov	$cputest,nofault
X! #ifdef UNIBUS_MAP
X  	bit	$40,SSR3
X  	beq	1f
X  	incb	_ubmap
X  1:
X- #endif
X  
X  #ifdef NONSEPARATE
X  	/*
X--- 154,166 ----
X  	/*
X  	 * Test for SSR3 and UNIBUS map capability.  If there is no SSR3, the
X  	 * first test of SSR3 will trap and we skip past the separate I/D test.
X+ 	 * 2.11BSD will be _seriously_ upset if I/D is not available!
X  	 */
X! 	mov	$2f,nofault
X  	bit	$40,SSR3
X  	beq	1f
X  	incb	_ubmap
X  1:
X  
X  #ifdef NONSEPARATE
X  	/*
X***************
X*** 165,217 ****
X  	bic	$1,SSR3
X  #else
X  	bit	$1,SSR3			/ Test for separate I/D capability
X! 	beq	cputest
X  	incb	_sep_id
X  #endif
X! 
X! 	/*
X! 	 * Try to find out what kind of cpu this is.  Defaults are 40 for
X! 	 * nonseparate and 45 for separate.  Cputype will be one of: 24,
X! 	 * 40, 60, 45, 44, 70, 73.
X! 	 */
X! cputest:
X! #ifndef NONSEPARATE
X! 	tstb	_sep_id
X! 	beq	nonsepcpu
X! 
X! 	tstb	_ubmap			/ sep_id: 44, 45, 70, 73
X! 	bne	1f
X! 
X! 	mov	$cpudone,nofault	/ sep_id && !ubmap: 45 or 73
X! 	tst	*$PDP1170_MSER		/ mem sys err reg implies 73
X! 	mov	$73.,_cputype
X! 	bis	$CCR_DT,*$PDP1170_CCR	/ disable cache traps
X! 	br	cpudone
X! 1:
X! 	mov	$1f,nofault		/ sep_id && ubmap: 44 or 70
X! 	mfpt				/ if mfpt instruction exists, this is
X! 	mov	$44.,_cputype		/   a 44
X! 	bis	$CCR_DCPI,*$PDP1144_CCR	/ Disable cache parity interrupts.
X! 	br	cpudone
X! 1:
X! 	mov	$70.,_cputype
X! 	bis	$CCR_DUT|CCR_DT,*$PDP1170_CCR / Disable UNIBUS and nonfatal
X! 	br	cpudone			/   traps.
X! 
X! nonsepcpu:
X! #endif !NONSEPARATE
X! 	tstb	_ubmap			/ !sep_id: 24, 40, 60
X! 	bne	1f
X! 
X! 	mov	$cpudone,nofault	/ !sep_id && !ubmap: 40, 60
X! 	tst	PDP1160_MSR
X! 	mov	$60.,_cputype
X! 	bis	$CCR_DT,*$PDP1160_CCR	/ Disable cache parity error traps.
X! 	br	cpudone
X! 1:
X! 	mov	$24.,_cputype		/ !sepid && ubmap: 24
X! 
X! cpudone:
X  		/ Test for stack limit register; set it if present.
X  	mov	$1f,nofault
X  	mov	$intstk-256.,STACKLIM
X--- 171,180 ----
X  	bic	$1,SSR3
X  #else
X  	bit	$1,SSR3			/ Test for separate I/D capability
X! 	beq	2f
X  	incb	_sep_id
X  #endif
X! 2:
X  		/ Test for stack limit register; set it if present.
X  	mov	$1f,nofault
X  	mov	$intstk-256.,STACKLIM
X*** /usr/src/sys/pdp/mch_dump.s.old	Fri Aug  4 14:59:46 1989
X--- /usr/src/sys/pdp/mch_dump.s	Sat Jul  4 00:22:11 1992
X***************
X*** 4,9 ****
X--- 4,10 ----
X   * specifies the terms and conditions for redistribution.
X   *
X   *	@(#)mch_dump.s	1.1 (2.10BSD Berkeley) 2/10/87
X+  *			1.2 (2.11BSD GTE) 7/03/92
X   */
X  #include "DEFS.h"
X  #include "../machine/mch_iopage.h"
X***************
X*** 153,163 ****
X  	 * reg 5 -- is used as an interation counter when mapping is enabled 
X  	 */
X  
X! 	clr	r4			/ clear UB map used indicator
X! 	cmp	_cputype,$44.		/ is a 44?
X! 	beq	1f			/ yes, skip next
X! 	cmp	_cputype,$70.		/ is a 70?
X! 	bne	2f			/ not a 70 either, no UBMAP
X  1:
X  	/*
X  	 * This section of code initializes the Unibus map registers and
X--- 154,161 ----
X  	 * reg 5 -- is used as an interation counter when mapping is enabled 
X  	 */
X  
X! 	movb	_ubmap,r4		/ UB map used indicator
X! 	beq	2f			/ no UBMAP - br
X  1:
X  	/*
X  	 * This section of code initializes the Unibus map registers and
X***************
X*** 167,173 ****
X  	 * Kernal I space 7 points to the I/O page.
X  	 */
X  
X- 	inc	r4			/ indicate that UB mapping is needed
X  	mov	$UBMR0,r1		/ point to  map register 0
X  	clr	r2			/ init for low map reg
X  	clr	r3			/ init for high map reg
X--- 165,170 ----
X***************
X*** 241,253 ****
X  	 * reg 5 -- is used as an interation counter when mapping is enabled
X  	 */
X  
X! 	cmp	_cputype,$44.		/ is a 44?
X! 	beq	1f			/ yes, skip next
X! 	cmp	_cputype,$70.		/ is a 70?
X! 	bne	2f			/ not a 70 either, no UBMAP
X! 1:
X! /	tst	_ubmap			/ unibus map present?
X! /	beq	2f			/ no, skip map init
X  
X  	/*
X  	 * This section of code initializes the Unibus map registers and
X--- 238,245 ----
X  	 * reg 5 -- is used as an interation counter when mapping is enabled
X  	 */
X  
X! 	movb	_ubmap,setmap		/ unibus map present?
X! 	beq	2f			/ no, skip map init
X  
X  	/*
X  	 * This section of code initializes the Unibus map registers and
X***************
X*** 259,265 ****
X  	 * Kernal I space 7 points to the I/O page.
X  	 */
X  
X- 	inc	setmap			/ indicate that UB mapping is needed
X  	mov	$UBMR0,r0		/ point to  map register 0
X  	clr	r2			/ init for low map reg
X  	clr	r3			/ init for high map reg
X--- 251,256 ----
X*** /usr/src/sys/pdp/mch_vars.s.old	Sat Sep  8 11:02:01 1990
X--- /usr/src/sys/pdp/mch_vars.s	Sat Jul  4 00:26:50 1992
X***************
X*** 12,17 ****
X--- 12,18 ----
X  
X  INT(GLOBAL, _fpp, 0)			/ we have a floating point processor
X  INT(GLOBAL, _ubmap, 0)			/ we have a unibus map
X+ INT(GLOBAL, _cputype, 0)		/ cpu type
X  CHAR(GLOBAL, _sep_id, 0)		/ we have a separate I&D CPU
X  
X  #ifdef ENABLE34
X***************
X*** 19,25 ****
X  #endif
X  .even
X  
X- 
X  /*
X   * Define _ka6 and give it a reasonable initial value
X   */
X--- 20,25 ----
X***************
X*** 29,36 ****
X  #	else
X  		INT(GLOBAL, _ka6, KISA6)
X  #	endif
X- 
X- 	INT(GLOBAL, _cputype, 40.)
X  #else
X  #	ifdef ENABLE34
X  		INT(GLOBAL, _ka6, DEC_KDSA6)
X--- 29,34 ----
X***************
X*** 37,46 ****
X  #	else
X  		INT(GLOBAL, _ka6, KDSA6)
X  #	endif
X- 
X- 	INT(GLOBAL, _cputype, 45.)
X  #endif
X- 
X  
X  SPACE(GLOBAL, intstk, INTSTK)		/ temp stack while KDSA6 is unmapped
X  CONST(GLOBAL, eintstk, intstk+INTSTK)	/ top of interuupt stack
X--- 35,41 ----
X*** /usr/src/sys/pdpstand/M.s.old	Tue Apr 23 10:21:47 1991
X--- /usr/src/sys/pdpstand/M.s	Sat Jul  4 00:03:21 1992
X***************
X*** 1,12 ****
X  /
X  /	SCCS id	@(#)M.s	1.7 (Berkeley)	7/11/83
X! /		@(#)M.s	2.0 (2.11BSD)	4/12/91 (sms@wlv.imsd.contel.com)
X  /
X  / Startup code for two-stage bootstrap with support for autoboot.
X  / Supports 11/45, 11/70, 11/53, 11/73, 11/83, 11/84, 11/93, 11/94
X  
X- systrap = 104400	/ trap 0
X- 
X  /  The boot options and device are placed in the last SZFLAGS bytes
X  /  at the end of core by the kernel if this is an autoboot.
X  /  The first-stage boot will leave them in registers for us;
X--- 1,10 ----
X  /
X  /	SCCS id	@(#)M.s	1.7 (Berkeley)	7/11/83
X! /		@(#)M.s	3.0 (2.11BSD)	7/03/92 (sms@wlv.iipo.gtegsc.com)
X  /
X  / Startup code for two-stage bootstrap with support for autoboot.
X  / Supports 11/45, 11/70, 11/53, 11/73, 11/83, 11/84, 11/93, 11/94
X  
X  /  The boot options and device are placed in the last SZFLAGS bytes
X  /  at the end of core by the kernel if this is an autoboot.
X  /  The first-stage boot will leave them in registers for us;
X***************
X*** 60,102 ****
X  	clr	ENDCORE-BOOTDEV
X  	clr	ENDCORE-CHECKWORD
X  /
X! / determine what kind of cpu we are running on
X! / The check for the switch register removed because:  1) the only use
X! / of it was in xp.c for the drive type and an alternate method of 
X! / modifying xptype is provided, 2) the only machine with a front panel
X! / which can run the system is the 11/70 and i got tired of having the
X! / system think it was on a 11/40 because switches were left up after the
X! / boot, 3) the standalone code was becoming large enough that 'restor'
X! / was having size problems due to the addition of multi-controller support,
X! / 4) the probing proceedure adequately determines the hardware capabilities.
X  
X  	clrb	_sep_id
X  	clrb	_ubmap
X! 	mov	$40.,r0		/ assume 11/40
X! 	mov	$2f,nofault
X! 	mov	*$KDSA6,r1	/ then we have sep i/d 45, 70, 73
X! 	incb	_sep_id
X! 	mov	$45.,r0
X! 	mov	$3f,nofault
X! 	mov	*$UBMAP,r1	/ then we have a unibus map. 44 or 70
X! 	incb	_ubmap
X! 	mov	$70.,r0
X! 	mov	$1f,nofault
X! 	mfpt			/ if mfpt instruction exists, this is
X! 	mov	$44.,r0		/   a 44
X! 	br	1f
X! 3:				/ br here with sep i/d, no ubmap. 45 or 73.
X! 	mov	$1f,nofault
X! 	mov	*$MSCR,r1	/ if no MSCR, 45 !
X! 	mov	$73.,r0		/ sep i/d, no ubmap, MSCR. 73!
X! 	br	1f
X! 2:				/ br here if no sep. I/D. 23, 24, 34, 40, 60
X! 	mov	$1f,nofault
X! 	mov	*$UBMAP,r1	/ then we have a unibus map
X! 	incb	_ubmap
X! 	mov	$24.,r0		/ unibus map, no sep. I/D = 24
X! 1:	clr	nofault
X! 	mov	r0,_cputype
X  
X  /
X  /	Set kernel I space registers to physical 0 and I/O page
X--- 58,71 ----
X  	clr	ENDCORE-BOOTDEV
X  	clr	ENDCORE-CHECKWORD
X  /
X! / determine what kind of cpu we are running on.  this was totally rewritten
X! / when support for the 93 and 94 was added.
X  
X  	clrb	_sep_id
X  	clrb	_ubmap
X! 	jsr	pc,cpuprobe	/ fill in _cputype, _ubmap and _sep_id
X! 				/ also sets MSCR bits
X! 	clr	nofault
X  
X  /
X  /	Set kernel I space registers to physical 0 and I/O page
X***************
X*** 138,144 ****
X  /
X  /	If 11/40 class processor, only need set the I space registers
X  /
X! 	tstb	_sep_id
X  	jeq	1f
X  
X  /
X--- 107,113 ----
X  /
X  /	If 11/40 class processor, only need set the I space registers
X  /
X! 	movb	_sep_id, _ksep
X  	jeq	1f
X  
X  /
X***************
X*** 161,167 ****
X  
X  1:
X  / enable map
X- 	clrb	_ksep
X  	tstb	_ubmap
X  	beq	2f
X  	jsr	pc,_ubmapset	/ 24, 44, 70 -> ubmap
X--- 130,135 ----
X***************
X*** 171,195 ****
X  	br	1f
X  3:
X  	mov	$65,SSR3	/ 44, 70 -> ubmap, I/D
X- 	incb	_ksep
X- 	mov	$3,MSCR		/ 44, 70: $1: disable cache parity traps
X- 				/ 44:     $2: ignored
X- 				/ 70:     $2: disable UNIBUS traps
X  	br	1f
X  2:
X  	tstb	_sep_id		/ 23, 34, 40, 45, 60, 73 -> no ubmap
X  	beq	1f
X  	mov	$25,SSR3	/ 45, 73 -> no ubmap, I/D; maybe 22-bit
X- 	incb	_ksep
X  1:
X  	mov	$30340,PS
X! 	inc	SSR0
X  
X- 
X  / copy program to user I space
X  	mov	$_end,r0
X! 	asr	r0
X! 	bic	$100000,r0
X  	clr	r1
X  1:
X  	mov	(r1),-(sp)
X--- 139,157 ----
X  	br	1f
X  3:
X  	mov	$65,SSR3	/ 44, 70 -> ubmap, I/D
X  	br	1f
X  2:
X  	tstb	_sep_id		/ 23, 34, 40, 45, 60, 73 -> no ubmap
X  	beq	1f
X  	mov	$25,SSR3	/ 45, 73 -> no ubmap, I/D; maybe 22-bit
X  1:
X  	mov	$30340,PS
X! 	inc	SSR0		/ turn on memory management
X  
X  / copy program to user I space
X  	mov	$_end,r0
X! 	clc
X! 	ror	r0
X  	clr	r1
X  1:
X  	mov	(r1),-(sp)
X***************
X*** 228,237 ****
X  	com	r2		/ checkword
X  	mov	$160000,-(sp)	/ set ksp to very top so that the trap
X  	mtpi	sp		/ puts the return address and psw at 157774,6
X! 	systrap
X  
X  	br	user
X  
X  setseg:
X  	mov	$8,r0
X  1:
X--- 190,255 ----
X  	com	r2		/ checkword
X  	mov	$160000,-(sp)	/ set ksp to very top so that the trap
X  	mtpi	sp		/ puts the return address and psw at 157774,6
X! 	sys	0		/ can't use "trap" because that's a label
X  
X  	br	user
X  
X+ cpuprobe:
X+ 	mov	$1f,nofault	/ catch possible trap
X+ 	tst	*$UBMAP		/ look for unibus map
X+ 	incb	_ubmap		/ we've got one, note that and continue on
X+ 1:
X+ 	mov	$1f,nofault
X+ 	tst	*$KDSA6		/ look for split I/D
X+ 	incb	_sep_id
X+ 1:
X+ 	mov	$nomfpt,nofault	/ catch possible fault from instruction
X+ 	mfpt			/ 23/24, 44, and KDJ-11 have this instruction
X+ 	cmp	r0,$1		/ 44?
X+ 	bne	1f		/ no - br
X+ 	mov	$1,*$MSCR	/ disable cache parity traps
X+ 	mov	$44.,_cputype
X+ 	rts	pc
X+ 1:
X+ 	cmp	r0,$5		/ KDJ-11?
X+ 	bne	2f		/ no - br
X+ 	mov	*$MAINT,r0	/ get system maint register
X+ 	ash	$-4,r0		/ move down and
X+ 	bic	$177760,r0	/  isolate the module id
X+ 	mov	$1,*$MSCR	/ disable cache parity traps
X+ 	movb	j11typ(r0),r0	/ lookup cpu type
X+ 	movb	_ubmap,r1	/ unibus?
X+ 	beq	1f		/ nope - br
X+ 	bis	$2,*$MSCR	/ disable unibus traps
X+ 1:
X+ 	add	r1,r0		/ bump the cpu type (93 -> 94, 83 ->84)
X+ 	br	out
X+ 2:
X+ 	cmp	r0,$3		/ 23 or 24?
X+ 	bne	nomfpt		/ mfpt returned other than 1,3,5 - HELP!
X+ 	mov	$23.,r0		/ assume 23
X+ 	movb	_ubmap,r1	/ add in...
X+ 	add	r1,r0		/ the unibus flag (23 -> 24)
X+ 	br	out
X+ nomfpt:
X+ 	tstb	_sep_id		/ split I/D present?
X+ 	beq	2f		/ no - br
X+ 	mov	$45.,r0		/ assume 45
X+ 	tstb	_ubmap		/ is that correct?
X+ 	beq	out		/ yes - br
X+ 	mov	$3,*$MSCR	/ disable unibus and cache traps
X+ 	mov	$70.,r0
X+ 	br	out
X+ 2:
X+ 	mov	$40.,r0		/ assume 40
X+ 	mov	$out,nofault
X+ 	tst	*$MSCR		/ 60 has MSCR, 40 doesn't
X+ 	mov	$60.,r0
X+ 	mov	$1,*$MSCR
X+ out:
X+ 	mov	r0,_cputype
X+ 	rts	pc
X+ 
X  setseg:
X  	mov	$8,r0
X  1:
X***************
X*** 341,346 ****
X--- 359,365 ----
X  UDSA0	= 177660
X  UDSD0	= 177620
X  MSCR	= 177746	/ 11/44/60/70 memory system cache control register
X+ MAINT	= 177750	/ KDJ-11 system maintenance register
X  IO	= 177600
X  UBMAP	= 170200
X  
X***************
X*** 350,356 ****
X  .globl	_bootopts, _bootdev, _checkword, _bootcsr
X  
X  nofault:	.=.+2	/ where to go on predicted trap
X! _cputype:	.=.+2	/ cpu type (currently 40,45 or 70)
X  _sep_id:	.=.+1	/ 1 if we have separate I and D
X  _ksep:		.=.+1	/ 1 if kernel mode has sep I/D enabled
X  _ubmap:		.=.+2	/ 1 if we have a unibus map
X--- 369,375 ----
X  .globl	_bootopts, _bootdev, _checkword, _bootcsr
X  
X  nofault:	.=.+2	/ where to go on predicted trap
X! _cputype:	.=.+2	/ cpu type
X  _sep_id:	.=.+1	/ 1 if we have separate I and D
X  _ksep:		.=.+1	/ 1 if kernel mode has sep I/D enabled
X  _ubmap:		.=.+2	/ 1 if we have a unibus map
X***************
X*** 358,360 ****
X--- 377,380 ----
X  _bootdev:	.=.+2	/ device booted from
X  _bootcsr:	.=.+2	/ csr of device booted from
X  _checkword:	.=.+2	/ saved r2, complement of bootopts if an autoboot
X+ j11typ:	.byte 0, 73., 83., 0, 53., 93.
SHAR_EOF
fi
if test -f 'toy.s'
then
	echo shar: "will not over-write existing file 'toy.s'"
else
sed 's/^X//' << \SHAR_EOF > 'toy.s'
X/ the notes say that the TOY clock uses 24 hour time, but then later on
X/ mention flags dealing with AM/PM...  So, code is present but disabled
X/ to handle 12 hour time.  If this code is needed change the 0 below to
X/ a 1.
X
Xtoy24=0
X
X/ extraneous flag bit possible in the day field.  this "should never
X/ happen", but if it does change the 0 to a 1 below.
X
Xdayflags=0
X
X	.globl	TOYCSR
XTOYCSR	= 177526
X
X	.globl	_toyclk
X	.text
X_toyclk:
X	jsr	r5,csv			/ callable from C, save regs
X	sub	$8.,sp			/ need 8 byte scratch area
Xtdata = -20
X	cmp	_cputype,$93.		/ are we a 11/93?
X	beq	1f			/ yes - br
X	cmp	_cputype,$94.		/ are we a 11/94?
X	bne	err			/ no, go return "error"
X1:
X	jsr	pc,initoy		/ initialize the clock for reading
X	mov	r5,(sp)
X	add	$tdata,(sp)		/ pointer to scratch area
X	jsr	pc,_gettoy		/ read the toy clock
X	mov	(sp),r2			/ pointer to scratch area
X	mov	$8.,r3			/ number of bytes of clock data
X2:
X	clr	r1
X	bisb	(r2),r1			/ fetch byte of clock data (!sign ext)
X.if	toy24
X	cmp	r3,$5			/ are we on the hours field?
X	bne	3f			/ no - br
X	bic	$240,r1			/ clear am/pm flags
X3:
X.endif
X	jsr	pc,bcd			/ convert 2 nybbles bcd to binary
X.if	toy24
X	cmp	r3,$5			/ hours field?
X	bne	4f			/ no - skip am/pm stuff
X	tstb	(r2)			/ $200 = am/pm in use
X	bpl	4f			/ not am/pm, skip it
X	cmp	r1,$12.			/ exactly 12?
X	bne	5f			/ no - br
X	clr	r1			/ make midnight
X5:
X	bitb	$40,(r2)		/ PM?
X	beq	4f			/ no  - br
X	add	$12.,r1			/ convert to 24 hour time
X.endif
X4:
X	movb	r1,(r2)+		/ store converted/correct binary value
X	sob	r3,2b			/ continue on for rest of the bytes
X	sub	$7,r2			/ back up to seconds field
X.if	dayflags
X	bicb	$177770,4(r2)		/ clear possible excess bits in day
X.endif
X	mov	$bounds,r3		/ do bounds checking now, not 100ths
X1:
X	movb	(r2)+,r1		/ get byte of clock data
X	cmpb	r1,(r3)+		/ below lo bound?
X	blo	err			/ yes - br
X	cmpb	r1,(r3)+		/ above hi bound
X	bhi	err			/ yes - br
X	cmp	r3,$bounds+14.		/ at end (7 limits * 2 bytes per = 14)?
X	blo	1b			/ no - br
X	sub	$8.,r2			/ back to seconds field
X	movb	7(r2),r0		/ fetch the year of century
X	cmp	r0,$90.			/ are we a "90s" system?
X	bhis	1f			/ yep - br
X	add	$100.,r0		/ next century for years 00 - 89
X1:
X	movb	r0,7(r2)		/ store fixed up year
X	decb	6(r2)			/ convert 1-12 month to 0-11
X	mov	r2,(sp)			/ pointer to the toy clock data
X	jsr	pc,_tm2t		/ convert to a 32bit # of seconds time
X	br	ret
Xerr:
X	clr	r0			/ a double precision value
X	clr	r1			/ of 0 signals an error
Xret:
X	jmp	cret			/ return
X	.data
Xbounds:
X	.byte	0,59.			/ seconds lo,hi
X	.byte	0,59.			/ minutes lo,hi
X	.byte	0,23.			/ hours lo,hi
X	.byte	0,7			/ day of week lo,hi
X	.byte	1,31.			/ day of month lo,hi
X	.byte	1,12.			/ month of year lo,hi
X	.byte	0,99.			/ year of century lo,hi
X	.text
Xinitoy:
X	tst	*$TOYCSR		/ strobe the clock register
X	clr	-(sp)			/ save previous high byte of register
X	movb	*$TOYCSR+1,(sp)		/ only bit 8 belongs to TOY!
X	bic	$1,(sp)			/ make sure bit 8 (TOY bit) is clear
X	mov	$2,r2			/ number of double words to send clock
X1:
X	mov	$35305,r0		/ first word of recognition code
X	jsr	pc,toyload		/ send it to clock
X	mov	$56243,r0		/ second word
X	jsr	pc,toyload		/ send it
X	sob	r2,1b			/ do the whole thing twice
X	tst	(sp)+			/ clean stack
X	rts	pc
X
X/ send contents of r0 to the TOY.  2(sp) has the old bits 9-15, bit 8
X/ has been cleared.
X
Xtoyload:
X	mov	$16.,r1			/ number of bits to send
X1:
X	mov	r0,r3			/ scratch copy
X	bic	$177776,r3		/ clear all but bit being sent
X	bis	2(sp),r3		/ merge in old_csr_bits
X	movb	r3,*$TOYCSR+1		/ send bit to clock
X	asr	r0			/ shift pattern down
X	sob	r1,1b			/ do all 16 bits in the word
X	rts	pc
X
X	.globl	_gettoy
X_gettoy:				/ (void)gettoy(&char[8]);
X	jsr	r5,csv			/ C callable
X	mov	4(r5),r2		/ buffer address
X	mov	$4,r3			/ number of words in buffer
X1:
X	mov	$16.,r4			/ number of bits in word
X2:
X	movb	*$TOYCSR+1,r0		/ low bit of top byte is a clock bit
X	asr	r0			/ put it in carry
X	ror	r1			/ ripple in at top end of r1
X	sob	r4,2b			/ do all 16 bits
X	mov	r1,(r2)+		/ store the word in the buffer
X	sob	r3,1b			/ do all 4 words
X	jmp	cret			/ and return
X
Xbcd:
X	clr	r0
X	div	$16.,r0
X	mov	r1,-(sp)
X	mov	r0,r1
X	mul	$10.,r1
X	add	(sp)+,r1
X	rts	pc
X
X	.globl	_tm2t
X_tm2t:
X	jsr	r5,csv
X	mov	4(r5),r4
X	movb	1(r4),r1
X	mov	r1,-(sp)
X	clr	-(sp)
X	movb	2(r4),r0
X	mul	$74,r0
X	mov	r1,-(sp)
X	mov	r0,-(sp)
X	mov	$7020,-(sp)
X	sxt	-(sp)
X	movb	3(r4),r1
X	mov	r1,-(sp)
X	clr	-(sp)
X	jsr	pc,lmul
X	add	$10,sp
X	mov	r1,-(sp)
X	mov	r0,-(sp)
X	mov	$50600,-(sp)
X	mov	$1,-(sp)
X	mov	r4,-(sp)
X	jsr	pc,_ndays		/ return value in r1
X	tst	(sp)+
X	dec	r1
X	mov	r1,-(sp)
X	sxt	-(sp)
X	jsr	pc,lmul
X	add	$10,sp
X	add	(sp)+,r0
X	add	(sp)+,r1
X	adc	r0
X	add	(sp)+,r0
X	add	(sp)+,r1
X	adc	r0
X	add	(sp)+,r0
X	add	(sp)+,r1
X	adc	r0
X	jmp	cret
X
X_leap:				/ r2 = year number, r1 clobbered
X	mov	r2,r1
X	add	$3554,r1
X	sxt	r0
X	div	$620,r0
X	tst	r1
X	bne	2f
X	br	3f
X1:
X	clr	r0		/ return false
X	br	4f
X2:
X	mov	r2,r1
X	sxt	r0
X	div	$144,r0
X	tst	r1
X	jeq	1b
X	bit	$3,r2
X	jne	1b
X3:
X	mov	$1,r0		/ return true
X4:
X	rts	pc
X	.data
Xmdays:
X	.byte 37,34,37,36,37,36,37,37,36,37,36,37,0
X	.even
X	.text
X_ndays:
X	jsr	r5,csv
X	mov	4(r5),r0
X	movb	5(r0),r4
X	mov	$106,r2
X	jbr	3f
X1:
X	add	$555,r4
X	jsr	pc,*$_leap		/ r2 has year in it already
X	add	r0,r4
X	inc	r2
X3:
X	mov	4(r5),r0
X	movb	7(r0),r0
X	cmp	r2,r0
X	jlt	1b
X	clr	r3
X	jbr	8f
X4:
X	clr	r0
X	cmp	$1,r3
X	jne	5f
X	jsr	pc,*$_leap	/ r2 has year
X5:
X	movb	mdays(r3),r1
X	add	r1,r0
X	add	r0,r4
X	inc	r3
X8:
X	mov	4(r5),r0
X	movb	6(r0),r0
X	cmp	r3,r0
X	jlt	4b
X	mov	r4,r1		/ return value in r1 not r0
X	jmp	cret
SHAR_EOF
fi
exit 0
#	End of shell archive
Newsgroups: comp.bugs.2bsd