xref: /openbsd/sys/arch/alpha/stand/boot/boot.c (revision 29295d1c)
1*29295d1cSmillert /*	$OpenBSD: boot.c,v 1.15 2003/06/02 23:27:43 millert Exp $	*/
2dfe00690Smillert /*	$NetBSD: boot.c,v 1.10 1997/01/18 01:58:33 cgd Exp $	*/
3df930be7Sderaadt 
4df930be7Sderaadt /*
5df930be7Sderaadt  * Copyright (c) 1992, 1993
6df930be7Sderaadt  *	The Regents of the University of California.  All rights reserved.
7df930be7Sderaadt  *
8df930be7Sderaadt  * This code is derived from software contributed to Berkeley by
9df930be7Sderaadt  * Ralph Campbell.
10df930be7Sderaadt  *
11df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
12df930be7Sderaadt  * modification, are permitted provided that the following conditions
13df930be7Sderaadt  * are met:
14df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
15df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
16df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
17df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
18df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
19*29295d1cSmillert  * 3. Neither the name of the University nor the names of its contributors
20df930be7Sderaadt  *    may be used to endorse or promote products derived from this software
21df930be7Sderaadt  *    without specific prior written permission.
22df930be7Sderaadt  *
23df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24df930be7Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25df930be7Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26df930be7Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27df930be7Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28df930be7Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29df930be7Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30df930be7Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31df930be7Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32df930be7Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33df930be7Sderaadt  * SUCH DAMAGE.
34df930be7Sderaadt  *
35df930be7Sderaadt  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
36df930be7Sderaadt  */
37df930be7Sderaadt 
3834fbf6deSderaadt #include <lib/libkern/libkern.h>
391e699572Smickey #include <lib/libsa/stand.h>
40df930be7Sderaadt 
41df930be7Sderaadt #include <sys/param.h>
42df930be7Sderaadt #include <sys/exec.h>
43417eba8cSderaadt #include <sys/exec_ecoff.h>
44df930be7Sderaadt 
45777da4a6Sniklas #include <machine/rpb.h>
46df930be7Sderaadt #include <machine/prom.h>
47aed035abSart #include <machine/autoconf.h>
48df930be7Sderaadt 
49df930be7Sderaadt #define _KERNEL
5034fbf6deSderaadt #include "include/pte.h"
51df930be7Sderaadt 
52c4071fd1Smillert int loadfile(char *, u_int64_t *);
53df930be7Sderaadt 
54df930be7Sderaadt char boot_file[128];
55df930be7Sderaadt char boot_flags[128];
56df930be7Sderaadt 
57df930be7Sderaadt extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
58df930be7Sderaadt 
59aed035abSart struct bootinfo_v1 bootinfo_v1;
60aed035abSart 
61aed035abSart extern paddr_t ffp_save, ptbr_save;
62aed035abSart 
63aed035abSart extern vaddr_t ssym, esym;
64df930be7Sderaadt 
65dfe00690Smillert int debug;
66dfe00690Smillert 
67dfe00690Smillert char *kernelnames[] = {
68dfe00690Smillert 	"bsd",
69dfe00690Smillert 	"bsd.bak",
70dfe00690Smillert 	"bsd.old",
71dfe00690Smillert 	"obsd",
72dfe00690Smillert 	NULL
73dfe00690Smillert };
74dfe00690Smillert 
756f295a11Sderaadt int
7650ce9ee0Sniklas main()
77df930be7Sderaadt {
78dfe00690Smillert 	char *name, **namep;
79df930be7Sderaadt 	u_int64_t entry;
80dfe00690Smillert 	int win;
81df930be7Sderaadt 
82df930be7Sderaadt 	/* Init prom callback vector. */
83df930be7Sderaadt 	init_prom_calls();
84df930be7Sderaadt 
85df930be7Sderaadt 	/* print a banner */
86eb45c5c9Sderaadt 	printf("%s, Revision %s (%s, %s)\n", bootprog_name, bootprog_rev,
87eb45c5c9Sderaadt 	    bootprog_maker, bootprog_date);
88df930be7Sderaadt 
89df930be7Sderaadt 	/* switch to OSF pal code. */
90df930be7Sderaadt 	OSFpal();
91df930be7Sderaadt 
92df930be7Sderaadt 	printf("\n");
93df930be7Sderaadt 
94df930be7Sderaadt 	prom_getenv(PROM_E_BOOTED_FILE, boot_file, sizeof(boot_file));
95df930be7Sderaadt 	prom_getenv(PROM_E_BOOTED_OSFLAGS, boot_flags, sizeof(boot_flags));
96df930be7Sderaadt 
97dfe00690Smillert 	if (boot_file[0] != 0)
98eb45c5c9Sderaadt 		(void)printf("Boot file: %s %s\n", boot_file, boot_flags);
99df930be7Sderaadt 
100dfe00690Smillert 	if (boot_file[0] != '\0')
101dfe00690Smillert 		win = (loadfile(name = boot_file, &entry) == 0);
102dfe00690Smillert 	else
103dfe00690Smillert 		for (namep = kernelnames, win = 0; *namep != NULL && !win;
104dfe00690Smillert 		    namep++)
105dfe00690Smillert 			win = (loadfile(name = *namep, &entry) == 0);
106df930be7Sderaadt 
107dfe00690Smillert 	printf("\n");
108aed035abSart 	if (!win)
109aed035abSart 		goto fail;
110df930be7Sderaadt 
111aed035abSart 	/*
112aed035abSart 	 * Fill in the bootinfo for the kernel.
113aed035abSart 	 */
114aed035abSart 	bzero(&bootinfo_v1, sizeof(bootinfo_v1));
115aed035abSart 	bootinfo_v1.ssym = ssym;
116aed035abSart 	bootinfo_v1.esym = esym;
117aed035abSart 	bcopy(name, bootinfo_v1.booted_kernel,
118aed035abSart 	    sizeof(bootinfo_v1.booted_kernel));
119aed035abSart 	bcopy(boot_flags, bootinfo_v1.boot_flags,
120aed035abSart 	    sizeof(bootinfo_v1.boot_flags));
121aed035abSart 	bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
122aed035abSart 	bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
123aed035abSart 	bootinfo_v1.cngetc = NULL;
124aed035abSart 	bootinfo_v1.cnputc = NULL;
125aed035abSart 	bootinfo_v1.cnpollc = NULL;
126aed035abSart 
127aed035abSart 	(void)printf("Entering %s at 0x%lx...\n", name, entry);
128aed035abSart 	(*(void (*)(u_int64_t, u_int64_t, u_int64_t, void *, u_int64_t,
129aed035abSart 	    u_int64_t))entry)(ffp_save, ptbr_save, BOOTINFO_MAGIC,
130aed035abSart 	    &bootinfo_v1, 1, 0);
131aed035abSart 
132aed035abSart fail:
13350ce9ee0Sniklas 	(void)printf("Boot failed!  Halting...\n");
13450ce9ee0Sniklas 	halt();
135df930be7Sderaadt }
136