1*85e3fbd2Sdholland /* $NetBSD: boot.c,v 1.33 2016/06/11 06:26:06 dholland Exp $ */
221ad9905Scgd
321ad9905Scgd /*
421ad9905Scgd * Copyright (c) 1992, 1993
521ad9905Scgd * The Regents of the University of California. All rights reserved.
621ad9905Scgd *
721ad9905Scgd * This code is derived from software contributed to Berkeley by
821ad9905Scgd * Ralph Campbell.
921ad9905Scgd *
1021ad9905Scgd * Redistribution and use in source and binary forms, with or without
1121ad9905Scgd * modification, are permitted provided that the following conditions
1221ad9905Scgd * are met:
1321ad9905Scgd * 1. Redistributions of source code must retain the above copyright
1421ad9905Scgd * notice, this list of conditions and the following disclaimer.
1521ad9905Scgd * 2. Redistributions in binary form must reproduce the above copyright
1621ad9905Scgd * notice, this list of conditions and the following disclaimer in the
1721ad9905Scgd * documentation and/or other materials provided with the distribution.
18aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
1921ad9905Scgd * may be used to endorse or promote products derived from this software
2021ad9905Scgd * without specific prior written permission.
2121ad9905Scgd *
2221ad9905Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2321ad9905Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2421ad9905Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2521ad9905Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2621ad9905Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2721ad9905Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2821ad9905Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2921ad9905Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3021ad9905Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3121ad9905Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3221ad9905Scgd * SUCH DAMAGE.
3321ad9905Scgd *
3421ad9905Scgd * @(#)boot.c 8.1 (Berkeley) 6/10/93
3521ad9905Scgd */
3621ad9905Scgd
3721ad9905Scgd #include <lib/libsa/stand.h>
38728d6723Sthorpej #include <lib/libkern/libkern.h>
39e66e4867Sross #include <lib/libsa/loadfile.h>
4021ad9905Scgd
4121ad9905Scgd #include <sys/param.h>
4221ad9905Scgd #include <sys/exec.h>
4321ad9905Scgd #include <sys/exec_ecoff.h>
4421ad9905Scgd
45f65454b2Sthorpej #include <machine/autoconf.h>
4621ad9905Scgd #include <machine/prom.h>
4792d17b5bScgd #include <machine/rpb.h>
4821ad9905Scgd
4980d9738dSdrochner #include <machine/pte.h>
5080d9738dSdrochner
5180d9738dSdrochner #include "common.h"
52f0bdf503Scgd
53f0bdf503Scgd #if !defined(UNIFIED_BOOTBLOCK) && !defined(SECONDARY_BOOTBLOCK)
54f0bdf503Scgd #error not UNIFIED_BOOTBLOCK and not SECONDARY_BOOTBLOCK
55f0bdf503Scgd #endif
5621ad9905Scgd
5721ad9905Scgd char boot_file[128];
5821ad9905Scgd char boot_flags[128];
5921ad9905Scgd
6092d17b5bScgd struct bootinfo_v1 bootinfo_v1;
61f65454b2Sthorpej
62d5df5511Sthorpej paddr_t ffp_save, ptbr_save;
6321ad9905Scgd
6421ad9905Scgd int debug;
6521ad9905Scgd
6621ad9905Scgd char *kernelnames[] = {
6721ad9905Scgd "netbsd", "netbsd.gz",
6821ad9905Scgd "netbsd.bak", "netbsd.bak.gz",
6921ad9905Scgd "netbsd.old", "netbsd.old.gz",
7021ad9905Scgd "onetbsd", "onetbsd.gz",
7158ca6aacSmatt "netbsd.alpha", "netbsd.alpha.gz",
7221ad9905Scgd NULL
7321ad9905Scgd };
7421ad9905Scgd
7521ad9905Scgd void
76f0bdf503Scgd #if defined(UNIFIED_BOOTBLOCK)
main(void)77f0bdf503Scgd main(void)
78f0bdf503Scgd #else /* defined(SECONDARY_BOOTBLOCK) */
79f0bdf503Scgd main(long fd)
80f0bdf503Scgd #endif
8121ad9905Scgd {
8221ad9905Scgd char *name, **namep;
83e66e4867Sross u_long marks[MARK_MAX];
8421ad9905Scgd u_int64_t entry;
855d71772dStsutsui int win, loadflag;
8621ad9905Scgd
8721ad9905Scgd /* Init prom callback vector. */
8821ad9905Scgd init_prom_calls();
89d4e15df5Scgd
90d4e15df5Scgd /* print a banner */
91d4e15df5Scgd printf("\n");
921fddfb80Scgd printf("NetBSD/alpha " NETBSD_VERS " " BOOT_TYPE_NAME " Bootstrap, Revision %s\n",
93d4e15df5Scgd bootprog_rev);
94d4e15df5Scgd printf("\n");
95d4e15df5Scgd
96d4e15df5Scgd /* set up the booted device descriptor */
97f0bdf503Scgd #if defined(UNIFIED_BOOTBLOCK)
98f0bdf503Scgd if (!booted_dev_open()) {
99f0bdf503Scgd printf("Boot device (%s) open failed.\n",
100f0bdf503Scgd booted_dev_name[0] ? booted_dev_name : "unknown");
101f0bdf503Scgd goto fail;
102f0bdf503Scgd }
103f0bdf503Scgd #else /* defined(SECONDARY_BOOTBLOCK) */
104f0bdf503Scgd booted_dev_setfd(fd);
105f0bdf503Scgd #endif
106412f6ae8Sross
10721ad9905Scgd /* switch to OSF pal code. */
10821ad9905Scgd OSFpal();
10921ad9905Scgd
11021ad9905Scgd printf("\n");
11121ad9905Scgd
11221ad9905Scgd prom_getenv(PROM_E_BOOTED_FILE, boot_file, sizeof(boot_file));
11321ad9905Scgd prom_getenv(PROM_E_BOOTED_OSFLAGS, boot_flags, sizeof(boot_flags));
11421ad9905Scgd
11521ad9905Scgd if (boot_file[0] != 0)
11621ad9905Scgd (void)printf("Boot file: %s\n", boot_file);
11721ad9905Scgd (void)printf("Boot flags: %s\n", boot_flags);
11821ad9905Scgd
119dabc8eb4Sdrochner if (strchr(boot_flags, 'i') || strchr(boot_flags, 'I')) {
120dabc8eb4Sdrochner printf("Boot file: ");
121*85e3fbd2Sdholland kgets(boot_file, sizeof(boot_file));
122dabc8eb4Sdrochner }
123dabc8eb4Sdrochner
1246b3899fdSchristos #ifdef NO_LOAD_BACKWARDS
1256b3899fdSchristos loadflag = LOAD_KERNEL & ~LOAD_BACKWARDS;
1265d71772dStsutsui #else
1275d71772dStsutsui loadflag = LOAD_KERNEL;
1285d71772dStsutsui #endif
1295d71772dStsutsui
130e66e4867Sross memset(marks, 0, sizeof marks);
1315df57d7dStsutsui if (boot_file[0] != '\0') {
1325df57d7dStsutsui name = boot_file;
1335d71772dStsutsui win = loadfile(name, marks, loadflag) == 0;
1345df57d7dStsutsui } else {
1355df57d7dStsutsui name = NULL; /* XXX gcc -Wuninitialized */
13621ad9905Scgd for (namep = kernelnames, win = 0; *namep != NULL && !win;
1375df57d7dStsutsui namep++) {
1385df57d7dStsutsui name = *namep;
1395d71772dStsutsui win = loadfile(name, marks, loadflag) == 0;
1405df57d7dStsutsui }
1415df57d7dStsutsui }
14221ad9905Scgd
143e66e4867Sross entry = marks[MARK_ENTRY];
144f0bdf503Scgd booted_dev_close();
14521ad9905Scgd printf("\n");
146e66e4867Sross if (!win)
147f0bdf503Scgd goto fail;
148f0bdf503Scgd
149f65454b2Sthorpej /*
150f65454b2Sthorpej * Fill in the bootinfo for the kernel.
151f65454b2Sthorpej */
152684d06baSwiz memset(&bootinfo_v1, 0, sizeof(bootinfo_v1));
153e66e4867Sross bootinfo_v1.ssym = marks[MARK_SYM];
154e66e4867Sross bootinfo_v1.esym = marks[MARK_END];
155684d06baSwiz memcpy(bootinfo_v1.booted_kernel, name,
15692d17b5bScgd sizeof(bootinfo_v1.booted_kernel));
157684d06baSwiz memcpy(bootinfo_v1.boot_flags, boot_flags,
15892d17b5bScgd sizeof(bootinfo_v1.boot_flags));
15992d17b5bScgd bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
16092d17b5bScgd bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
16192d17b5bScgd bootinfo_v1.cngetc = NULL;
16292d17b5bScgd bootinfo_v1.cnputc = NULL;
16392d17b5bScgd bootinfo_v1.cnpollc = NULL;
164f65454b2Sthorpej
16521ad9905Scgd (void)printf("Entering %s at 0x%lx...\n", name, entry);
16643a34719Sross alpha_pal_imb();
167ebca60d3Scgd (*(void (*)(u_int64_t, u_int64_t, u_int64_t, void *, u_int64_t,
168ebca60d3Scgd u_int64_t))entry)(ffp_save, ptbr_save, BOOTINFO_MAGIC,
169f0bdf503Scgd &bootinfo_v1, 1, 0);
17021ad9905Scgd
171f0bdf503Scgd (void)printf("KERNEL RETURNED!\n");
172f0bdf503Scgd
173f0bdf503Scgd fail:
17421ad9905Scgd (void)printf("Boot failed! Halting...\n");
17521ad9905Scgd halt();
17621ad9905Scgd }
177