xref: /netbsd-src/sys/arch/hppa/stand/cdboot/cdboot.c (revision 6d3ceb1d619615401b17c9aa3e4bc674a1cb048b)
1*6d3ceb1dSskrll /*	$NetBSD: cdboot.c,v 1.1 2014/02/24 07:23:43 skrll Exp $	*/
2*6d3ceb1dSskrll 
3*6d3ceb1dSskrll /*-
4*6d3ceb1dSskrll  * Copyright (c) 1982, 1986, 1990, 1993
5*6d3ceb1dSskrll  *	The Regents of the University of California.  All rights reserved.
6*6d3ceb1dSskrll  *
7*6d3ceb1dSskrll  * Redistribution and use in source and binary forms, with or without
8*6d3ceb1dSskrll  * modification, are permitted provided that the following conditions
9*6d3ceb1dSskrll  * are met:
10*6d3ceb1dSskrll  * 1. Redistributions of source code must retain the above copyright
11*6d3ceb1dSskrll  *    notice, this list of conditions and the following disclaimer.
12*6d3ceb1dSskrll  * 2. Redistributions in binary form must reproduce the above copyright
13*6d3ceb1dSskrll  *    notice, this list of conditions and the following disclaimer in the
14*6d3ceb1dSskrll  *    documentation and/or other materials provided with the distribution.
15*6d3ceb1dSskrll  * 3. Neither the name of the University nor the names of its contributors
16*6d3ceb1dSskrll  *    may be used to endorse or promote products derived from this software
17*6d3ceb1dSskrll  *    without specific prior written permission.
18*6d3ceb1dSskrll  *
19*6d3ceb1dSskrll  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*6d3ceb1dSskrll  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*6d3ceb1dSskrll  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*6d3ceb1dSskrll  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*6d3ceb1dSskrll  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*6d3ceb1dSskrll  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*6d3ceb1dSskrll  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*6d3ceb1dSskrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*6d3ceb1dSskrll  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*6d3ceb1dSskrll  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*6d3ceb1dSskrll  * SUCH DAMAGE.
30*6d3ceb1dSskrll  *
31*6d3ceb1dSskrll  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
32*6d3ceb1dSskrll  */
33*6d3ceb1dSskrll 
34*6d3ceb1dSskrll /*
35*6d3ceb1dSskrll  * Copyright (c) 1998-2004 Michael Shalayeff
36*6d3ceb1dSskrll  * All rights reserved.
37*6d3ceb1dSskrll  *
38*6d3ceb1dSskrll  * Redistribution and use in source and binary forms, with or without
39*6d3ceb1dSskrll  * modification, are permitted provided that the following conditions
40*6d3ceb1dSskrll  * are met:
41*6d3ceb1dSskrll  * 1. Redistributions of source code must retain the above copyright
42*6d3ceb1dSskrll  *    notice, this list of conditions and the following disclaimer.
43*6d3ceb1dSskrll  * 2. Redistributions in binary form must reproduce the above copyright
44*6d3ceb1dSskrll  *    notice, this list of conditions and the following disclaimer in the
45*6d3ceb1dSskrll  *    documentation and/or other materials provided with the distribution.
46*6d3ceb1dSskrll  *
47*6d3ceb1dSskrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48*6d3ceb1dSskrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49*6d3ceb1dSskrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50*6d3ceb1dSskrll  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
51*6d3ceb1dSskrll  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
52*6d3ceb1dSskrll  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
53*6d3ceb1dSskrll  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54*6d3ceb1dSskrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
55*6d3ceb1dSskrll  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
56*6d3ceb1dSskrll  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
57*6d3ceb1dSskrll  * THE POSSIBILITY OF SUCH DAMAGE.
58*6d3ceb1dSskrll  *
59*6d3ceb1dSskrll  */
60*6d3ceb1dSskrll 
61*6d3ceb1dSskrll #include <sys/param.h>
62*6d3ceb1dSskrll #include <sys/reboot.h>
63*6d3ceb1dSskrll #include <sys/boot_flag.h>
64*6d3ceb1dSskrll 
65*6d3ceb1dSskrll #include <arch/hppa/stand/common/libsa.h>
66*6d3ceb1dSskrll #include <lib/libsa/loadfile.h>
67*6d3ceb1dSskrll 
68*6d3ceb1dSskrll #include <machine/pdc.h>
69*6d3ceb1dSskrll #include <machine/vmparam.h>
70*6d3ceb1dSskrll 
71*6d3ceb1dSskrll #include <arch/hppa/stand/common/dev_hppa.h>
72*6d3ceb1dSskrll 
73*6d3ceb1dSskrll /*
74*6d3ceb1dSskrll  * Boot program... bits in `howto' determine whether boot stops to
75*6d3ceb1dSskrll  * ask for system name.	 Boot device is derived from ROM provided
76*6d3ceb1dSskrll  * information.
77*6d3ceb1dSskrll  */
78*6d3ceb1dSskrll 
79*6d3ceb1dSskrll void boot(dev_t boot_dev);
80*6d3ceb1dSskrll 
81*6d3ceb1dSskrll typedef void (*startfuncp)(int, int, int, int, int, int, void *)
82*6d3ceb1dSskrll     __attribute__ ((noreturn));
83*6d3ceb1dSskrll 
84*6d3ceb1dSskrll void
boot(dev_t boot_dev)85*6d3ceb1dSskrll boot(dev_t boot_dev)
86*6d3ceb1dSskrll {
87*6d3ceb1dSskrll 	u_long marks[MARK_MAX];
88*6d3ceb1dSskrll 	u_long loadaddr = 0;
89*6d3ceb1dSskrll 	char path[128];
90*6d3ceb1dSskrll 	int fd;
91*6d3ceb1dSskrll 
92*6d3ceb1dSskrll 	machdep();
93*6d3ceb1dSskrll #ifdef	DEBUGBUG
94*6d3ceb1dSskrll 	debug = 1;
95*6d3ceb1dSskrll #endif
96*6d3ceb1dSskrll 	devboot(boot_dev, path);
97*6d3ceb1dSskrll 
98*6d3ceb1dSskrll 	strncpy(path + strlen(path), ":/netbsd", 9);
99*6d3ceb1dSskrll 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
100*6d3ceb1dSskrll 	printf(">> Booting %s: ", path);
101*6d3ceb1dSskrll 
102*6d3ceb1dSskrll #define	round_to_size(x) \
103*6d3ceb1dSskrll 	(((x) + sizeof(u_long) - 1) & ~(sizeof(u_long) - 1))
104*6d3ceb1dSskrll 
105*6d3ceb1dSskrll #define	BOOTARG_APIVER 2
106*6d3ceb1dSskrll 
107*6d3ceb1dSskrll 	marks[MARK_START] = loadaddr;
108*6d3ceb1dSskrll 	if ((fd = loadfile(path, marks, LOAD_KERNEL)) == -1)
109*6d3ceb1dSskrll 		return;
110*6d3ceb1dSskrll 
111*6d3ceb1dSskrll 	marks[MARK_END] = round_to_size(marks[MARK_END] - loadaddr);
112*6d3ceb1dSskrll 	printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n",
113*6d3ceb1dSskrll 	    marks[MARK_ENTRY], marks[MARK_NSYM],
114*6d3ceb1dSskrll 	    marks[MARK_SYM], marks[MARK_END]);
115*6d3ceb1dSskrll 
116*6d3ceb1dSskrll #ifdef EXEC_DEBUG
117*6d3ceb1dSskrll 	if (debug) {
118*6d3ceb1dSskrll 		printf("ep=0x%x [", marks[MARK_ENTRY]);
119*6d3ceb1dSskrll 		for (i = 0; i < 10240; i++) {
120*6d3ceb1dSskrll 			if (!(i % 8)) {
121*6d3ceb1dSskrll 				printf("\b\n%p:", &((u_int *)marks[MARK_ENTRY])[i]);
122*6d3ceb1dSskrll 				if (getchar() != ' ')
123*6d3ceb1dSskrll 					break;
124*6d3ceb1dSskrll 			}
125*6d3ceb1dSskrll 			printf("%x,", ((int *)marks[MARK_ENTRY])[i]);
126*6d3ceb1dSskrll 		}
127*6d3ceb1dSskrll 		printf("\b\b ]\n");
128*6d3ceb1dSskrll 	}
129*6d3ceb1dSskrll #endif
130*6d3ceb1dSskrll 
131*6d3ceb1dSskrll 	fcacheall();
132*6d3ceb1dSskrll 
133*6d3ceb1dSskrll 	__asm("mtctl %r0, %cr17");
134*6d3ceb1dSskrll 	__asm("mtctl %r0, %cr17");
135*6d3ceb1dSskrll 	/* stack and the gung is ok at this point, so, no need for asm setup */
136*6d3ceb1dSskrll 	(*(startfuncp)(marks[MARK_ENTRY])) ((int)pdc, 0, boot_dev, marks[MARK_END],
137*6d3ceb1dSskrll 				       BOOTARG_APIVER, 0, NULL);
138*6d3ceb1dSskrll 	/* not reached */
139*6d3ceb1dSskrll }
140