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