Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / next68k / stand / boot / boot.c
blob1aa493a4f629c5207acea0695ba8c0860fb75458
1 /* $NetBSD: boot.c,v 1.7.6.4 2005/01/24 08:34:26 skrll Exp $ */
2 /*
3 * Copyright (c) 1994 Rolf Grossmann
4 * All rights reserved.
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
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.
32 #include <sys/param.h>
33 #include <sys/reboot.h>
35 #include <lib/libsa/stand.h>
36 #include <lib/libsa/loadfile.h>
37 #include <lib/libkern/libkern.h>
39 #include <machine/cpu.h> /* for NEXT_RAMBASE */
41 #include <next68k/next68k/nextrom.h>
43 #define KERN_LOADADDR NEXT_RAMBASE
45 extern int errno;
47 extern char *mg;
48 #define MON(type, off) (*(type *)((u_int) (mg) + off))
50 int devparse(const char *, int *, char *, char *, char *, char **);
52 /* the PROM overwrites MG_boot_arg :-( */
53 /* #define PROCESS_ARGS */
56 * Boot device is derived from PROM provided information.
59 extern char bootprog_rev[];
60 extern char bootprog_name[];
61 extern int build;
62 #define KNAMEN 100
63 char kernel[KNAMEN];
64 int entry_point; /* return value filled in by machdep_start */
65 int turbo;
67 extern void rtc_init(void);
69 extern int try_bootp;
71 volatile int qq;
73 int
74 main(char *boot_arg)
76 int fd;
77 u_long marks[MARK_MAX];
78 int dev;
79 char count, lun, part;
80 char machine;
81 char *file;
82 #ifdef PROCESS_ARGS
83 char *kernel_args = MON(char *, MG_boot_dev);
84 #endif
86 machine = MON(char, MG_machine_type);
87 if (machine == NeXT_TURBO_MONO || machine == NeXT_TURBO_COLOR)
88 turbo = 1;
89 else
90 turbo = 0;
92 memset(marks, 0, sizeof(marks));
93 printf(">> %s BOOT [%s #%d]\n", bootprog_name, bootprog_rev, build);
94 printf(">> type %d, %sturbo\n", machine, turbo ? "" : "non-");
95 rtc_init();
97 try_bootp = 1;
99 #if 0
101 int i;
102 int *p = (int *)mg;
103 for (i = 0; i <= 896; ) {
104 printf ("%d: %x %x %x %x %x %x %x %x\n", i, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
105 p = &p[8];
106 i += 8*4;
109 printf("Press return to continue.\n");
110 getchar();
111 #endif
113 strcpy(kernel, boot_arg);
114 entry_point = 0;
116 for (;;) {
117 marks[MARK_START] = (u_long)KERN_LOADADDR;
118 fd = loadfile(kernel, marks, LOAD_KERNEL);
119 if (fd != -1) {
120 break;
123 printf("load of %s: %s\n", kernel, strerror(errno));
124 printf("boot: ");
125 gets(kernel);
126 if (kernel[0] == '\0')
127 return 0;
129 #ifdef PROCESS_ARGS
130 kernel_args = strchr(kernel, ')');
131 if (kernel_args == NULL)
132 kernel_args = kernel;
133 kernel_args = strchr(kernel_args, ' ');
134 if (kernel_args)
135 *kernel_args++ = '\0';
136 #endif
139 dev = 0;
140 count = lun = part = 0;
141 if (devparse(kernel, &dev, &count, &lun, &part, &file) == 0) {
142 char *p = (char *)marks[MARK_END];
143 strcpy (p, devsw[dev].dv_name);
144 MON(char *, MG_boot_dev) = p;
145 p += strlen (p) + 1;
146 sprintf (p, "(%d,%d,%d)", count, lun, part);
147 MON(char *, MG_boot_info) = p;
148 p += strlen (p) + 1;
149 sprintf (p, "%s", file);
150 MON(char *, MG_boot_file) = p;
151 #ifdef PROCESS_ARGS
152 p += strlen (p) + 1;
153 if (kernel_args)
154 strcpy (p, kernel_args);
155 else
156 *p = 0;
157 MON(char *, MG_boot_arg) = p;
158 #endif
161 *((u_long *)KERN_LOADADDR) = marks[MARK_END] - KERN_LOADADDR;
162 printf("entry 0x%lx esym 0x%lx\n",
163 marks[MARK_ENTRY], marks[MARK_END] - KERN_LOADADDR);
164 return marks[MARK_ENTRY];