xref: /csrg-svn/sys/vax/mdec/raboot.c (revision 11087)
1*11087Ssam /*	raboot.c	4.1	83/02/16	*/
2*11087Ssam 
3*11087Ssam /*
4*11087Ssam  * From 4.1 boot sector code by Scott Comer (Rice University).
5*11087Ssam  */
6*11087Ssam 	.set	BOOTBASE, 0xfe00	/* relocated home of boot block */
7*11087Ssam 	/*
8*11087Ssam 	 * These three hold the register contents needed by the
9*11087Ssam 	 * ROM driver subroutine to access the boot device.
10*11087Ssam 	 */
11*11087Ssam 	.set	driver_r1, DATA
12*11087Ssam 	.set	driver_r2, driver_r1+4
13*11087Ssam 	.set	driver_r3, driver_r2+4
14*11087Ssam 	.set	driver, driver_r3+4		/* addr of driver routine */
15*11087Ssam 
16*11087Ssam 	.set	NOT_FIRST_64K, 		0x1001
17*11087Ssam 	.set	UNSUPPORTED_DEVICE, 	0x1002
18*11087Ssam 	.set	RETURN_FROM_BOOT, 	0x1003
19*11087Ssam 	.set	COULD_NOT_FIND_BOOT, 	0x1004
20*11087Ssam 	.set	FILE_TOO_LARGE, 	0x1005
21*11087Ssam 	.set	FILE_READ_ERROR, 	0x1006
22*11087Ssam 
23*11087Ssam init:
24*11087Ssam 	.long	0			/* boot block parameters */
25*11087Ssam 	.long	0			/* (all unused, hence 0) */
26*11087Ssam 	.long	0
27*11087Ssam 
28*11087Ssam /*
29*11087Ssam  * The registers are set by the console subsystem as follows.
30*11087Ssam  * Those marked with stars are saved by the driver subroutine.
31*11087Ssam  * Those marked with a "d" are used by the driver subroutine,
32*11087Ssam  * and must contain the indicated values before calling the driver.
33*11087Ssam  *
34*11087Ssam  *    r0  = type of boot device (see 750 hardware reference, console)
35*11087Ssam  * ds r1  = address of the unibus i/o page
36*11087Ssam  * ds r2  = boot device CSR address
37*11087Ssam  * ds r3  = boot device unit number
38*11087Ssam  *  s r4  =
39*11087Ssam  * ds r5  = software boot flags (driver: offset to buffer for read)
40*11087Ssam  *  s r6  = driver subroutine address
41*11087Ssam  *    r7  =
42*11087Ssam  * d  r8  = LBN of block to read from disk
43*11087Ssam  *    r9  =
44*11087Ssam  *  s r10 =
45*11087Ssam  *  s r11 =
46*11087Ssam  *  s ap  =
47*11087Ssam  *    fp  =
48*11087Ssam  *  s sp  =
49*11087Ssam  *
50*11087Ssam  * Memory is mapped as follows:
51*11087Ssam  *
52*11087Ssam  * 0000 to 01ff	Boot block program
53*11087Ssam  * 0200 to f9ff	Available
54*11087Ssam  * fa00 to fdff	Drivers and control routines
55*11087Ssam  * fe00 to ffff	Available
56*11087Ssam  */
57*11087Ssam start:
58*11087Ssam 	clrl	r7
59*11087Ssam 	movl	r0, r10			/* save the device type */
60*11087Ssam 	moval	init, r11		/* base address of good memory */
61*11087Ssam 	movl	r5, ap			/* save the boot flags */
62*11087Ssam 	tstl	r11			/* see if it is zero */
63*11087Ssam 	beql	1f
64*11087Ssam 	movzwl	$NOT_FIRST_64K, r7
65*11087Ssam 	halt				/* not in first 64k of memory */
66*11087Ssam 1:	moval	STACK(r11), sp		/* put the stack somewhere good */
67*11087Ssam 	/* save the register contents needed by the boot driver */
68*11087Ssam 	movl	r1, driver_r1(r11)
69*11087Ssam 	movl	r2, driver_r2(r11)
70*11087Ssam 	movl	r3, driver_r3(r11)
71*11087Ssam 	movl	r6, driver(r11)
72*11087Ssam 	/* relocate the boot program */
73*11087Ssam 	movc3	$end, (r11), BOOTBASE(r11)
74*11087Ssam 	jmp	BOOTBASE+start2(r11)
75*11087Ssam start2:					/* running relocated */
76*11087Ssam 	calls	$0, BOOTBASE+read_file(r11)
77*11087Ssam 	movl	r11, r9				/* save the base pointer */
78*11087Ssam 	/* boot strap device codes from microcode routines */
79*11087Ssam 	.set	AnyMassBus, 0
80*11087Ssam 	.set	RK07, 1
81*11087Ssam 	.set	RL02, 2
82*11087Ssam 	.set	UDA50, 17
83*11087Ssam 	.set	TU58, 64
84*11087Ssam 
85*11087Ssam 	cmpb	r10, $AnyMassBus
86*11087Ssam 	bneq	1f
87*11087Ssam 	movzbl	$0, r10				/* massbus disk */
88*11087Ssam 	brb	2f
89*11087Ssam 1:
90*11087Ssam 	cmpb	r10, $RK07
91*11087Ssam 	bneq	1f
92*11087Ssam 	movzbl	$3, r10				/* rk07 disk */
93*11087Ssam 	brb	2f
94*11087Ssam 1:
95*11087Ssam 	cmpb	r10, $UDA50
96*11087Ssam 	bneq	1f
97*11087Ssam 	movzbl	$9, r10				/* uda50 */
98*11087Ssam 	brb	2f
99*11087Ssam 1:
100*11087Ssam 	movzwl	$UNSUPPORTED_DEVICE, r7
101*11087Ssam 	halt					/* unsupported device */
102*11087Ssam 2:
103*11087Ssam 	movl	ap, r11				/* software boot flags */
104*11087Ssam 	addl3	di_size(r9), r9, r2		/* address to start clear */
105*11087Ssam 	moval	BOOTBASE(r9), r1		/* address to stop clearing */
106*11087Ssam 1:
107*11087Ssam 
108*11087Ssam 	cmpl	r2, r1
109*11087Ssam 	bgeq	2f
110*11087Ssam 	clrb	(r2)+
111*11087Ssam 	brb	1b
112*11087Ssam 2:
113*11087Ssam 	calls	$0, (r9)
114*11087Ssam 	movzwl	$RETURN_FROM_BOOT, r7
115*11087Ssam 	halt					/* end of program */
116*11087Ssam read_block:
117*11087Ssam 	.word	0xffc			/* r11-r2 */
118*11087Ssam 	clrq	-(sp)			/* make room for the buf addr */
119*11087Ssam 	movl	driver_r1(r11), r1
120*11087Ssam 	movl	driver_r2(r11), r2
121*11087Ssam 	movl	driver_r3(r11), r3
122*11087Ssam 	mull3	$2, 4(ap), r4		/* mult by 2 to get lbn */
123*11087Ssam 	movl	r4, r8
124*11087Ssam 	movl	8(ap), r5
125*11087Ssam 	addl3	r5, r11, (sp)		/* for massbus babies */
126*11087Ssam 	jsb	*driver(r11)		/* read the first block */
127*11087Ssam 	blbs	r0, 1f
128*11087Ssam 	movzwl	$FILE_READ_ERROR, r7
129*11087Ssam 	halt				/* error reading file */
130*11087Ssam 1:
131*11087Ssam 	addl3	$1, r4, r8
132*11087Ssam 	addl2	$512, r5
133*11087Ssam 	addl3	r5, r11, (sp)		/* for massbus babies */
134*11087Ssam 	jsb	*driver(r11)		/* read the second block */
135*11087Ssam 	blbs	r0, 1f
136*11087Ssam 	movzwl	$FILE_READ_ERROR, r7
137*11087Ssam 	halt				/* error reading file */
138*11087Ssam 1:
139*11087Ssam 	ret
140*11087Ssam end:
141