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