xref: /csrg-svn/sys/vax/stand/srt0.c (revision 33408)
123242Smckusick /*
229309Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
323242Smckusick  * All rights reserved.  The Berkeley software License Agreement
423242Smckusick  * specifies the terms and conditions for redistribution.
523242Smckusick  *
6*33408Skarels  *	@(#)srt0.c	7.4 (Berkeley) 01/28/88
723242Smckusick  */
8326Sbill 
99186Ssam #include "../vax/mtpr.h"
103349Swnj #define	LOCORE
119186Ssam #include "../vax/cpu.h"
123263Swnj 
131914Swnj /*
141914Swnj  * Startup code for standalone system
151914Swnj  * Non-relocating version -- for programs which are loaded by boot
1625442Skarels  * Relocating version for boot*
171914Swnj  */
18326Sbill 
193349Swnj 	.globl	_end
201757Sbill 	.globl	_edata
21326Sbill 	.globl	_main
22326Sbill 	.globl	__rtt
233263Swnj 	.globl	_configure
243349Swnj 	.globl	_cpu
253349Swnj 	.globl	_openfirst
2630770Skarels 	.globl	_boothowto
2730770Skarels 	.globl	_bootdev
28326Sbill 
29326Sbill 	.set	HIGH,31		# mask for total disable
30326Sbill 
312438Swnj entry:	.globl	entry
32*33408Skarels 	nop; nop			# .word	0x0101
33326Sbill 	mtpr	$HIGH,$IPL		# just in case
34*33408Skarels 
353349Swnj #ifdef REL
36*33408Skarels 	# we need to do special stuff on microvax II
37*33408Skarels 	mfpr	$SID,r0
38*33408Skarels 	cmpzv	$24,$8,r0,$VAX_630
39*33408Skarels 	bneq	1f
40*33408Skarels 
41*33408Skarels 	/*
42*33408Skarels 	 * Were we booted by VMB?  If so, r11 is not boothowto,
43*33408Skarels 	 * but rather the address of the `Extended RPB' (see KA630
44*33408Skarels 	 * User's Manual, pp 3-21).  These tests were devised by
45*33408Skarels 	 * richl@tektronix, 11/10/87.
46*33408Skarels 	 */
47*33408Skarels 	cmpl	(r11),r11		# if boothowto, r11 will be small
48*33408Skarels 	bneq	1f			# and these will not fault
49*33408Skarels 	cmpl	4(r11),$0
50*33408Skarels 	bneq	1f
51*33408Skarels 	cmpl	8(r11),$-1
52*33408Skarels 	bneq	1f
53*33408Skarels 	tstl	0xc(r11)
54*33408Skarels 	bneq	1f
55*33408Skarels 
56*33408Skarels 	/*
57*33408Skarels 	 * Booted by VMB: get flags from extended rpb.
58*33408Skarels 	 * We can only guess at the boot device (here ra(0,0)).
59*33408Skarels 	 */
60*33408Skarels 	movl	0x30(r11),r11
61*33408Skarels 	movl	$9,r10			# device = ra(0,0)
62*33408Skarels 1:
633349Swnj 	movl	$RELOC,sp
643349Swnj #else
653349Swnj 	movl	$RELOC-0x2400,sp
663349Swnj #endif
672438Swnj start:
68*33408Skarels #ifndef REL
69*33408Skarels 	/*
70*33408Skarels 	 * Clear bss segment
71*33408Skarels 	 */
723349Swnj 	movl	aedata,r0
73411Sbill clr:
74411Sbill 	clrl	(r0)+
75411Sbill 	cmpl	r0,sp
76411Sbill 	jlss	clr
77*33408Skarels #else
78*33408Skarels 	/*
79*33408Skarels 	 * `entry' below generates a pc-relative reference to the
80*33408Skarels 	 * code, so this works no matter where we are now.
81*33408Skarels 	 * Clear bss segment *after* moving text and data.
82*33408Skarels 	 */
83*33408Skarels 	movc3	aedata,entry,(sp)
8412366Ssam dclr:
8512366Ssam 	clrl	(r3)+
8612366Ssam 	cmpl	r3,$_end
8712366Ssam 	jlss	dclr
8812366Ssam /* this loop shouldn't be necessary, but is when booting from an ra81 */
8912366Ssam xclr:
9012366Ssam 	clrl	(r3)+
9112366Ssam 	cmpl	r3,$0x100000
9212366Ssam 	jlss	xclr
933349Swnj 	jmp	*abegin
943349Swnj begin:
953349Swnj #endif
9630770Skarels 	movl	r11,_boothowto
9730770Skarels 	movl	r10,_bootdev
9830770Skarels again:
993349Swnj 	mtpr	$0,$SCBB
1003263Swnj 	calls	$0,_configure
1013349Swnj 	movl	$1,_openfirst
102326Sbill 	calls	$0,_main
10330770Skarels #ifdef REL
10430770Skarels 	jmp	again
1053349Swnj #else
1063349Swnj 	ret
1073349Swnj #endif
108326Sbill 
1093349Swnj 	.data
1103349Swnj #ifdef REL
1113349Swnj abegin:	.long	begin
1123349Swnj aedata:	.long	_edata-RELOC
1133349Swnj #else
1143349Swnj aedata:	.long	_edata
1153349Swnj #endif
11630770Skarels _bootdev:	.long	0
11730770Skarels _boothowto:	.long	0
11830770Skarels 	.text
1193349Swnj 
120326Sbill __rtt:
121326Sbill 	.word	0x0
12225442Skarels #ifdef	REL
12325442Skarels 	halt
12425442Skarels #else
125326Sbill 	jmp	start
12625442Skarels #endif
1273349Swnj 
12830547Skarels 	.globl	_badaddr
12930547Skarels _badaddr:
1303349Swnj 	.word	0
1313349Swnj 	movl	$1,r0
1323349Swnj 	movl	4(ap),r3
13330547Skarels 	movl	8(ap),r4
1343349Swnj 	movl	$4,r2
1353349Swnj 	movab	9f,(r2)
13630547Skarels 	bbc	$0,r4,1f; tstb	(r3)
13730547Skarels 1:	bbc	$1,r4,1f; tstw	(r3)
13830547Skarels 1:	bbc	$2,r4,1f; tstl	(r3)
1393349Swnj 1:	clrl	r0			# made it w/o machine checks
1403349Swnj 2:	movl	$4,r2
1413349Swnj 	clrl	(r2)
1423349Swnj 	ret
1433349Swnj 	.align	2
1443349Swnj 9:
1453349Swnj 	casel	_cpu,$1,$VAX_MAX
1463349Swnj 0:
1473349Swnj 	.word	8f-0b		# 1 is 780
1483349Swnj 	.word	5f-0b		# 2 is 750
1497446Sroot 	.word	5f-0b		# 3 is 730
15024153Sbloom 	.word	6f-0b		# 4 is 8600
151*33408Skarels 	.word	5f-0b		# 5 is 8200
152*33408Skarels 	.word	1f-0b		# 6 is 8800
153*33408Skarels 	.word	1f-0b		# 7 is 610
154*33408Skarels 	.word	5f-0b		# 8 is 630
1553349Swnj 5:
1563349Swnj 	mtpr	$0xf,$MCESR
1573349Swnj 	brb	1f
15824153Sbloom 6:
15924153Sbloom 	mtpr	$0,$EHSR
16024153Sbloom 	brb	1f
1613349Swnj 8:
1623349Swnj 	mtpr	$0,$SBIFS
1633349Swnj 1:
1643349Swnj 	addl2	(sp)+,sp		# discard mchchk trash
1653349Swnj 	movab	2b,(sp)
1663349Swnj 	rei
167*33408Skarels 
168*33408Skarels /*
169*33408Skarels  * Short assembly versions of strcmp, strcpy, and strlen
170*33408Skarels  * that do not use special instructions.
171*33408Skarels  */
172*33408Skarels 	.globl	_strcmp
173*33408Skarels _strcmp:
174*33408Skarels 	.word	0
175*33408Skarels 	movq	4(ap),r0
176*33408Skarels 0:	cmpb	(r0),(r1)+
177*33408Skarels 	bneq	1f
178*33408Skarels 	tstb	(r0)+
179*33408Skarels 	bneq	0b
180*33408Skarels 	clrl	r0
181*33408Skarels 	ret
182*33408Skarels 1:	cvtbl	(r0),r0
183*33408Skarels 	cvtbl	-(r1),r1
184*33408Skarels 	subl2	r1,r0
185*33408Skarels 	ret
186*33408Skarels 
187*33408Skarels 	.globl	_strcpy
188*33408Skarels _strcpy:
189*33408Skarels 	.word	0
190*33408Skarels 	movq	4(ap),r0
191*33408Skarels 0:	movb	(r1)+,(r0)+
192*33408Skarels 	bneq	0b
193*33408Skarels 	movl	4(ap),r0
194*33408Skarels 	ret
195*33408Skarels 
196*33408Skarels 	.globl	_strlen
197*33408Skarels _strlen:
198*33408Skarels 	.word	0
199*33408Skarels 	movl	4(ap),r0
200*33408Skarels 0:	tstb	(r0)+
201*33408Skarels 	bneq	0b
202*33408Skarels 	decl	r0
203*33408Skarels 	subl2	4(ap),r0
204*33408Skarels 	ret
205