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