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