iris_boot.c revision 1.1.6.2 1 1.1.6.2 christos /* $NetBSD: iris_boot.c,v 1.1.6.2 2019/06/10 22:06:44 christos Exp $ */
2 1.1.6.2 christos
3 1.1.6.2 christos /*
4 1.1.6.2 christos * Copyright (c) 2018 Naruaki Etomi
5 1.1.6.2 christos * All rights reserved.
6 1.1.6.2 christos *
7 1.1.6.2 christos * Redistribution and use in source and binary forms, with or without
8 1.1.6.2 christos * modification, are permitted provided that the following conditions
9 1.1.6.2 christos * are met:
10 1.1.6.2 christos * 1. Redistributions of source code must retain the above copyright
11 1.1.6.2 christos * notice, this list of conditions and the following disclaimer.
12 1.1.6.2 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.6.2 christos * notice, this list of conditions and the following disclaimer in the
14 1.1.6.2 christos * documentation and/or other materials provided with the distribution.
15 1.1.6.2 christos *
16 1.1.6.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1.6.2 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1.6.2 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1.6.2 christos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1.6.2 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1.6.2 christos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1.6.2 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1.6.2 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1.6.2 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1.6.2 christos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1.6.2 christos */
27 1.1.6.2 christos
28 1.1.6.2 christos /*
29 1.1.6.2 christos * Silicon Graphics "IRIS" series MIPS processors machine bootloader.
30 1.1.6.2 christos *
31 1.1.6.2 christos * Notes:
32 1.1.6.2 christos * The amount of physical memory space available to
33 1.1.6.2 christos * the system is 3661820 (0x80002000 - 0x8037fffc) bytes.
34 1.1.6.2 christos * This space is too tight for kernel and bootloader.
35 1.1.6.2 christos * So we keep it simple.
36 1.1.6.2 christos */
37 1.1.6.2 christos
38 1.1.6.2 christos #include <lib/libsa/stand.h>
39 1.1.6.2 christos #include <lib/libsa/loadfile.h>
40 1.1.6.2 christos #include <lib/libkern/libkern.h>
41 1.1.6.2 christos
42 1.1.6.2 christos #include <sys/param.h>
43 1.1.6.2 christos #include <sys/exec.h>
44 1.1.6.2 christos #include <sys/exec_elf.h>
45 1.1.6.2 christos #include <sys/boot_flag.h>
46 1.1.6.2 christos
47 1.1.6.2 christos #ifndef INDIGO_R3K_MODE
48 1.1.6.2 christos #include <dev/arcbios/arcbios.h>
49 1.1.6.2 christos #endif
50 1.1.6.2 christos
51 1.1.6.2 christos #include "iris_machdep.h"
52 1.1.6.2 christos
53 1.1.6.2 christos #include "common.h"
54 1.1.6.2 christos #include "bootinfo.h"
55 1.1.6.2 christos
56 1.1.6.2 christos int main(int, char **);
57 1.1.6.2 christos
58 1.1.6.2 christos /* Storage must be static. */
59 1.1.6.2 christos struct btinfo_symtab bi_syms;
60 1.1.6.2 christos struct btinfo_bootpath bi_bpath;
61 1.1.6.2 christos
62 1.1.6.2 christos static uint8_t bootinfo[BOOTINFO_SIZE];
63 1.1.6.2 christos
64 1.1.6.2 christos /*
65 1.1.6.2 christos * This gets arguments from the PROM monitor.
66 1.1.6.2 christos * argv[0] will be path to the bootloader (i.e., "dksc(X,Y,8)/bootiris").
67 1.1.6.2 christos *
68 1.1.6.2 christos * argv[1] through argv[n] will contain arguments passed from the PROM, if any.
69 1.1.6.2 christos */
70 1.1.6.2 christos
71 1.1.6.2 christos int
72 1.1.6.2 christos main(int argc, char **argv)
73 1.1.6.2 christos {
74 1.1.6.2 christos char kernelname[1 + 32];
75 1.1.6.2 christos void (*entry) (int, char *[], int, void *);
76 1.1.6.2 christos u_long marks[MARK_MAX];
77 1.1.6.2 christos int win = 0;
78 1.1.6.2 christos int zs_addr, speed;
79 1.1.6.2 christos
80 1.1.6.2 christos cninit(&zs_addr, &speed);
81 1.1.6.2 christos
82 1.1.6.2 christos /* print a banner */
83 1.1.6.2 christos printf("\n");
84 1.1.6.2 christos printf("%s " NETBSD_VERS " Yet another Bootstrap, Revision %s\n",
85 1.1.6.2 christos bootprog_name, bootprog_rev);
86 1.1.6.2 christos printf("\n");
87 1.1.6.2 christos
88 1.1.6.2 christos memset(marks, 0, sizeof marks);
89 1.1.6.2 christos
90 1.1.6.2 christos /* initialise bootinfo structure early */
91 1.1.6.2 christos bi_init(bootinfo);
92 1.1.6.2 christos
93 1.1.6.2 christos switch (argc) {
94 1.1.6.2 christos #ifdef INDIGO_R3K_MODE
95 1.1.6.2 christos case 1:
96 1.1.6.2 christos again();
97 1.1.6.2 christos break;
98 1.1.6.2 christos #endif
99 1.1.6.2 christos case 2:
100 1.1.6.2 christos /* To specify HDD on Indigo R3K */
101 1.1.6.2 christos if (strstr(argv[1], "dksc(")) {
102 1.1.6.2 christos parse(argv, kernelname);
103 1.1.6.2 christos } else {
104 1.1.6.2 christos again();
105 1.1.6.2 christos }
106 1.1.6.2 christos break;
107 1.1.6.2 christos default:
108 1.1.6.2 christos /* To specify HDD on Indigo R4K and Indy */
109 1.1.6.2 christos if (strstr(argv[1], "dksc(")) {
110 1.1.6.2 christos parse(argv, kernelname);
111 1.1.6.2 christos } else {
112 1.1.6.2 christos again();
113 1.1.6.2 christos }
114 1.1.6.2 christos break;
115 1.1.6.2 christos }
116 1.1.6.2 christos
117 1.1.6.2 christos find_devs();
118 1.1.6.2 christos
119 1.1.6.2 christos win = loadfile(kernelname, marks, LOAD_KERNEL);
120 1.1.6.2 christos
121 1.1.6.2 christos if (win < 0) {
122 1.1.6.2 christos printf("Boot failed! Halting...\n");
123 1.1.6.2 christos reboot();
124 1.1.6.2 christos }
125 1.1.6.2 christos
126 1.1.6.2 christos strlcpy(bi_bpath.bootpath, kernelname, BTINFO_BOOTPATH_LEN);
127 1.1.6.2 christos bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));
128 1.1.6.2 christos
129 1.1.6.2 christos bi_syms.nsym = marks[MARK_NSYM];
130 1.1.6.2 christos bi_syms.ssym = marks[MARK_SYM];
131 1.1.6.2 christos bi_syms.esym = marks[MARK_END];
132 1.1.6.2 christos bi_add(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms));
133 1.1.6.2 christos entry = (void *)marks[MARK_ENTRY];
134 1.1.6.2 christos
135 1.1.6.2 christos (*entry)(argc, argv, BOOTINFO_MAGIC, bootinfo);
136 1.1.6.2 christos
137 1.1.6.2 christos printf("Kernel returned! Halting...\n");
138 1.1.6.2 christos return 0;
139 1.1.6.2 christos }
140 1.1.6.2 christos
141 1.1.6.2 christos void
142 1.1.6.2 christos again(void)
143 1.1.6.2 christos {
144 1.1.6.2 christos printf("Invalid argument\n");
145 1.1.6.2 christos printf("i.e., dksc(0,X,8)loader dksc(0,X,0)/kernel\n");
146 1.1.6.2 christos reboot();
147 1.1.6.2 christos }
148 1.1.6.2 christos
149 1.1.6.2 christos void
150 1.1.6.2 christos reboot(void)
151 1.1.6.2 christos {
152 1.1.6.2 christos #ifdef INDIGO_R3K_MODE
153 1.1.6.2 christos romrestart();
154 1.1.6.2 christos #else
155 1.1.6.2 christos arcbios_Reboot();
156 1.1.6.2 christos #endif
157 1.1.6.2 christos }
158