boot.c revision 1.4.8.2 1 /* $NetBSD: boot.c,v 1.4.8.2 2002/08/01 02:42:52 nathanw Exp $ */
2 /*
3 * Copyright (c) 1994 Rolf Grossmann
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Rolf Grossmann.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/param.h>
33 #include <sys/reboot.h>
34
35 #include <lib/libsa/stand.h>
36 #include <lib/libsa/loadfile.h>
37 #include <lib/libkern/libkern.h>
38
39 #include <machine/cpu.h> /* for NEXT_RAMBASE */
40
41 #include <next68k/next68k/nextrom.h>
42
43 #define KERN_LOADADDR NEXT_RAMBASE
44
45 extern int errno;
46
47 extern char *mg;
48 #define MON(type, off) (*(type *)((u_int) (mg) + off))
49
50 int devparse __P((const char *fname, int *dev,
51 char *count, char *lun, char *part, char **file));
52
53 /* the PROM overwrites MG_boot_arg :-( */
54 /* #define PROCESS_ARGS */
55
56 /*
57 * Boot device is derived from PROM provided information.
58 */
59
60 extern char bootprog_rev[];
61 extern char bootprog_name[];
62 extern int build;
63 #define KNAMEN 100
64 char kernel[KNAMEN];
65 int entry_point; /* return value filled in by machdep_start */
66
67 extern void rtc_init(void);
68
69 extern int try_bootp;
70
71 volatile int qq;
72
73 int
74 main(char *boot_arg)
75 {
76 int fd;
77 u_long marks[MARK_MAX];
78 int dev;
79 char count, lun, part;
80 char *file;
81 #ifdef PROCESS_ARGS
82 char *kernel_args = MON(char *, MG_boot_dev);
83 #endif
84
85 memset(marks, 0, sizeof(marks));
86 printf(">> %s BOOT [%s #%d]\n", bootprog_name, bootprog_rev, build);
87 rtc_init();
88
89 try_bootp = 1;
90
91 #if 0
92 printf("Press return to continue.\n");
93 getchar();
94 #endif
95
96 strcpy(kernel, boot_arg);
97 entry_point = NULL;
98
99 for (;;) {
100 marks[MARK_START] = (u_long)KERN_LOADADDR;
101 fd = loadfile(kernel, marks, LOAD_KERNEL);
102 if (fd != -1) {
103 break;
104 }
105
106 printf("load of %s: %s\n", kernel, strerror(errno));
107 printf("boot: ");
108 gets(kernel);
109 if (kernel[0] == '\0')
110 return NULL;
111
112 #ifdef PROCESS_ARGS
113 kernel_args = strchr(kernel, ')');
114 if (kernel_args == NULL)
115 kernel_args = kernel;
116 kernel_args = strchr(kernel_args, ' ');
117 if (kernel_args)
118 *kernel_args++ = '\0';
119 #endif
120 }
121
122 dev = 0;
123 count = lun = part = 0;
124 if (devparse(kernel, &dev, &count, &lun, &part, &file) == 0) {
125 char *p = (char *)marks[MARK_END];
126 strcpy (p, devsw[dev].dv_name);
127 MON(char *, MG_boot_dev) = p;
128 p += strlen (p) + 1;
129 sprintf (p, "(%d,%d,%d)", count, lun, part);
130 MON(char *, MG_boot_info) = p;
131 p += strlen (p) + 1;
132 sprintf (p, "%s", file);
133 MON(char *, MG_boot_file) = p;
134 #ifdef PROCESS_ARGS
135 p += strlen (p) + 1;
136 if (kernel_args)
137 strcpy (p, kernel_args);
138 else
139 *p = 0;
140 MON(char *, MG_boot_arg) = p;
141 #endif
142 }
143
144 *((u_long *)KERN_LOADADDR) = marks[MARK_END] - KERN_LOADADDR;
145 printf("entry 0x%lx esym 0x%lx\n",
146 marks[MARK_ENTRY], marks[MARK_END] - KERN_LOADADDR);
147 return marks[MARK_ENTRY];
148 }
149