boot.c revision 1.14
1/*	$NetBSD: boot.c,v 1.14 2023/02/12 08:25:09 tsutsui 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/libsa/dev_net.h>
38#include <lib/libkern/libkern.h>
39
40#include <machine/cpu.h>        /* for NEXT_RAMBASE */
41
42#include <next68k/next68k/nextrom.h>
43
44#include "samachdep.h"
45
46#define KERN_LOADADDR NEXT_RAMBASE
47
48#define	MON(type, off) (*(type *)((u_int) (mg) + off))
49
50int devparse(const char *, int *, char *, char *, char *, char **);
51
52/* the PROM overwrites MG_boot_arg :-( */
53/* #define PROCESS_ARGS */
54
55/*
56 * Boot device is derived from PROM provided information.
57 */
58
59#define KNAMEN 100
60char kernel[KNAMEN];
61int entry_point;		/* return value filled in by machdep_start */
62int turbo;
63
64volatile int qq;
65
66int
67main(char *boot_arg)
68{
69	int fd;
70	u_long marks[MARK_MAX];
71	int dev;
72	char count, lun, part;
73	char machine;
74	char *file;
75#ifdef PROCESS_ARGS
76	char *kernel_args = MON(char *, MG_boot_dev);
77#endif
78
79	machine = MON(char, MG_machine_type);
80	if (machine == NeXT_TURBO_MONO ||
81	    machine == NeXT_TURBO_COLOR ||
82	    machine == NeXT_CUBE_TURBO)
83		turbo = 1;
84	else
85		turbo = 0;
86
87	memset(marks, 0, sizeof(marks));
88	printf(">> %s BOOT [%s #%d]\n", bootprog_name, bootprog_rev, build);
89	printf(">> type %d, %sturbo\n", machine, turbo ? "" : "non-");
90	rtc_init();
91
92	try_bootp = 1;
93
94#if 0
95	{
96		int i;
97		int *p = (int *)mg;
98		for (i = 0; i <= 896; ) {
99			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]);
100			p = &p[8];
101			i += 8*4;
102		}
103	}
104	printf("Press return to continue.\n");
105	getchar();
106#endif
107
108	strcpy(kernel, boot_arg);
109	entry_point = 0;
110
111	for (;;) {
112		marks[MARK_START] = (u_long)KERN_LOADADDR;
113		fd = loadfile(kernel, marks, LOAD_KERNEL);
114		if (fd != -1) {
115			break;
116		}
117
118		printf("load of %s: %s\n", kernel, strerror(errno));
119		printf("boot: ");
120		kgets(kernel, sizeof(kernel));
121		if (kernel[0] == '\0')
122			return 0;
123
124#ifdef PROCESS_ARGS
125		kernel_args = strchr(kernel, ')');
126		if (kernel_args == NULL)
127			kernel_args = kernel;
128		kernel_args = strchr(kernel_args, ' ');
129		if (kernel_args)
130			*kernel_args++ = '\0';
131#endif
132	}
133
134	dev = 0;
135	count = lun = part = 0;
136	if (devparse(kernel, &dev, &count, &lun, &part, &file) == 0) {
137		char *p = (char *)marks[MARK_END];
138		strcpy (p, devsw[dev].dv_name);
139		MON(char *, MG_boot_dev) = p;
140		p += strlen (p) + 1;
141		snprintf (p, 1024, "(%d,%d,%d)", count, lun, part); /* XXX */
142		MON(char *, MG_boot_info) = p;
143		p += strlen (p) + 1;
144		snprintf (p, 1024, "%s", file); /* XXX */
145		MON(char *, MG_boot_file) = p;
146#ifdef PROCESS_ARGS
147		p += strlen (p) + 1;
148		if (kernel_args)
149			strcpy (p, kernel_args);
150		else
151			*p = 0;
152		MON(char *, MG_boot_arg) = p;
153#endif
154	}
155
156	*((u_long *)KERN_LOADADDR) = marks[MARK_END] - KERN_LOADADDR;
157	printf("entry 0x%lx esym 0x%lx\n",
158	       marks[MARK_ENTRY], marks[MARK_END] - KERN_LOADADDR);
159	return marks[MARK_ENTRY];
160}
161