xref: /csrg-svn/sys/vax/stand/srt0.c (revision 45803)
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*45803Sbostic  *	@(#)srt0.c	7.7 (Berkeley) 12/16/90
723242Smckusick  */
8326Sbill 
9*45803Sbostic #include "../include/mtpr.h"
103349Swnj #define	LOCORE
11*45803Sbostic #include "../include/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
3233408Skarels 	nop; nop			# .word	0x0101
33326Sbill 	mtpr	$HIGH,$IPL		# just in case
3433408Skarels 
353349Swnj #ifdef REL
3635402Stef 	# we need to do special stuff on microvaxen
3733408Skarels 	mfpr	$SID,r0
3833408Skarels 	cmpzv	$24,$8,r0,$VAX_630
3935402Stef 	beql	1f
4035402Stef 	cmpzv	$24,$8,r0,$VAX_650
4135402Stef 	bneq	2f
4233408Skarels 
4333408Skarels 	/*
4433408Skarels 	 * Were we booted by VMB?  If so, r11 is not boothowto,
4533408Skarels 	 * but rather the address of the `Extended RPB' (see KA630
4633408Skarels 	 * User's Manual, pp 3-21).  These tests were devised by
4733408Skarels 	 * richl@tektronix, 11/10/87.
4833408Skarels 	 */
4935402Stef 1:
5033408Skarels 	cmpl	(r11),r11		# if boothowto, r11 will be small
5135402Stef 	bneq	2f			# and these will not fault
5233408Skarels 	cmpl	4(r11),$0
5335402Stef 	bneq	2f
5433408Skarels 	cmpl	8(r11),$-1
5535402Stef 	bneq	2f
5633408Skarels 	tstl	0xc(r11)
5735402Stef 	bneq	2f
5833408Skarels 
5933408Skarels 	/*
6033408Skarels 	 * Booted by VMB: get flags from extended rpb.
6133408Skarels 	 * We can only guess at the boot device (here ra(0,0)).
6233408Skarels 	 */
6333408Skarels 	movl	0x30(r11),r11
6433408Skarels 	movl	$9,r10			# device = ra(0,0)
6535402Stef 2:
663349Swnj 	movl	$RELOC,sp
673349Swnj #else
683349Swnj 	movl	$RELOC-0x2400,sp
693349Swnj #endif
702438Swnj start:
7133408Skarels #ifndef REL
7233408Skarels 	/*
7333408Skarels 	 * Clear bss segment
7433408Skarels 	 */
753349Swnj 	movl	aedata,r0
76411Sbill clr:
77411Sbill 	clrl	(r0)+
78411Sbill 	cmpl	r0,sp
79411Sbill 	jlss	clr
8033408Skarels #else
8133408Skarels 	/*
8233408Skarels 	 * `entry' below generates a pc-relative reference to the
8333408Skarels 	 * code, so this works no matter where we are now.
8433408Skarels 	 * Clear bss segment *after* moving text and data.
8533408Skarels 	 */
8633408Skarels 	movc3	aedata,entry,(sp)
8712366Ssam dclr:
8812366Ssam 	clrl	(r3)+
8912366Ssam 	cmpl	r3,$_end
9012366Ssam 	jlss	dclr
9112366Ssam /* this loop shouldn't be necessary, but is when booting from an ra81 */
9212366Ssam xclr:
9312366Ssam 	clrl	(r3)+
9412366Ssam 	cmpl	r3,$0x100000
9512366Ssam 	jlss	xclr
963349Swnj 	jmp	*abegin
973349Swnj begin:
983349Swnj #endif
9930770Skarels 	movl	r11,_boothowto
10030770Skarels 	movl	r10,_bootdev
10130770Skarels again:
1023349Swnj 	mtpr	$0,$SCBB
1033263Swnj 	calls	$0,_configure
1043349Swnj 	movl	$1,_openfirst
105326Sbill 	calls	$0,_main
10630770Skarels #ifdef REL
10730770Skarels 	jmp	again
1083349Swnj #else
1093349Swnj 	ret
1103349Swnj #endif
111326Sbill 
1123349Swnj 	.data
1133349Swnj #ifdef REL
1143349Swnj abegin:	.long	begin
1153349Swnj aedata:	.long	_edata-RELOC
1163349Swnj #else
1173349Swnj aedata:	.long	_edata
1183349Swnj #endif
11930770Skarels _bootdev:	.long	0
12030770Skarels _boothowto:	.long	0
12130770Skarels 	.text
1223349Swnj 
123326Sbill __rtt:
124326Sbill 	.word	0x0
12525442Skarels #ifdef	REL
12625442Skarels 	halt
12725442Skarels #else
128326Sbill 	jmp	start
12925442Skarels #endif
1303349Swnj 
13130547Skarels 	.globl	_badaddr
13230547Skarels _badaddr:
1333349Swnj 	.word	0
1343349Swnj 	movl	$1,r0
1353349Swnj 	movl	4(ap),r3
13630547Skarels 	movl	8(ap),r4
1373349Swnj 	movl	$4,r2
1383349Swnj 	movab	9f,(r2)
13930547Skarels 	bbc	$0,r4,1f; tstb	(r3)
14030547Skarels 1:	bbc	$1,r4,1f; tstw	(r3)
14130547Skarels 1:	bbc	$2,r4,1f; tstl	(r3)
1423349Swnj 1:	clrl	r0			# made it w/o machine checks
1433349Swnj 2:	movl	$4,r2
1443349Swnj 	clrl	(r2)
1453349Swnj 	ret
1463349Swnj 	.align	2
1473349Swnj 9:
1483349Swnj 	casel	_cpu,$1,$VAX_MAX
1493349Swnj 0:
1503349Swnj 	.word	8f-0b		# 1 is 780
1513349Swnj 	.word	5f-0b		# 2 is 750
1527446Sroot 	.word	5f-0b		# 3 is 730
15324153Sbloom 	.word	6f-0b		# 4 is 8600
15433408Skarels 	.word	5f-0b		# 5 is 8200
15533408Skarels 	.word	1f-0b		# 6 is 8800
15633408Skarels 	.word	1f-0b		# 7 is 610
15733408Skarels 	.word	5f-0b		# 8 is 630
15835402Stef 	.word	1f-0b		# 9 is ???
15936205Stef 	.word	1f-0b		# 10 is 650
1603349Swnj 5:
1613349Swnj 	mtpr	$0xf,$MCESR
1623349Swnj 	brb	1f
16324153Sbloom 6:
16424153Sbloom 	mtpr	$0,$EHSR
16524153Sbloom 	brb	1f
1663349Swnj 8:
1673349Swnj 	mtpr	$0,$SBIFS
1683349Swnj 1:
1693349Swnj 	addl2	(sp)+,sp		# discard mchchk trash
1703349Swnj 	movab	2b,(sp)
1713349Swnj 	rei
17233408Skarels 
17333408Skarels /*
17433408Skarels  * Short assembly versions of strcmp, strcpy, and strlen
17533408Skarels  * that do not use special instructions.
17633408Skarels  */
17733408Skarels 	.globl	_strcmp
17833408Skarels _strcmp:
17933408Skarels 	.word	0
18033408Skarels 	movq	4(ap),r0
18133408Skarels 0:	cmpb	(r0),(r1)+
18233408Skarels 	bneq	1f
18333408Skarels 	tstb	(r0)+
18433408Skarels 	bneq	0b
18533408Skarels 	clrl	r0
18633408Skarels 	ret
18733408Skarels 1:	cvtbl	(r0),r0
18833408Skarels 	cvtbl	-(r1),r1
18933408Skarels 	subl2	r1,r0
19033408Skarels 	ret
19133408Skarels 
19233408Skarels 	.globl	_strcpy
19333408Skarels _strcpy:
19433408Skarels 	.word	0
19533408Skarels 	movq	4(ap),r0
19633408Skarels 0:	movb	(r1)+,(r0)+
19733408Skarels 	bneq	0b
19833408Skarels 	movl	4(ap),r0
19933408Skarels 	ret
20033408Skarels 
20133408Skarels 	.globl	_strlen
20233408Skarels _strlen:
20333408Skarels 	.word	0
20433408Skarels 	movl	4(ap),r0
20533408Skarels 0:	tstb	(r0)+
20633408Skarels 	bneq	0b
20733408Skarels 	decl	r0
20833408Skarels 	subl2	4(ap),r0
20933408Skarels 	ret
210