NetBSD/sys/arch/bebox/stand/boot/boot.c

209 lines
5.1 KiB
C
Raw Normal View History

/* $NetBSD: boot.c,v 1.12 2000/09/24 12:32:34 jdolecek Exp $ */
1998-01-16 07:17:36 +03:00
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
* Copyright (C) 1995, 1996 TooLs GmbH.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stand.h>
1999-06-28 05:20:43 +04:00
#include <loadfile.h>
#include <sys/boot_flag.h>
1998-01-16 07:17:36 +03:00
#include <sys/reboot.h>
1999-06-28 05:20:43 +04:00
#include <machine/bootinfo.h>
#include "boot.h"
1998-01-16 07:17:36 +03:00
char *names[] = {
"in()",
"fd(0,1,0)netbsd", "fd(0,1,0)netbsd.gz",
"fd(0,1,0)netbsd.old", "fd(0,1,0)netbsd.old.gz",
"fd(0,1,0)onetbsd", "fd(0,1,0)onetbsd.gz"
};
1999-06-28 05:20:43 +04:00
#define NUMNAMES (sizeof (names) / sizeof (names[0]))
1998-01-16 07:17:36 +03:00
1999-06-28 05:20:43 +04:00
#define NAMELEN 128
1998-01-16 07:17:36 +03:00
char namebuf[NAMELEN];
char nametmp[NAMELEN];
1999-06-28 05:20:43 +04:00
1998-01-16 07:17:36 +03:00
struct btinfo_memory btinfo_memory;
struct btinfo_console btinfo_console;
struct btinfo_clock btinfo_clock;
1999-06-28 05:20:43 +04:00
extern char bootprog_name[], bootprog_rev[], bootprog_maker[], bootprog_date[];
void exec_kernel __P((char *, void *));
1998-01-16 07:17:36 +03:00
void
main()
{
1999-06-28 05:20:43 +04:00
int n = 0;
int addr, speed;
1999-06-28 05:20:43 +04:00
char *name, *cnname;
void *p, *bootinfo;
1998-01-16 07:17:36 +03:00
if (whichCPU() == 1)
cpu1();
resetCPU1();
/*
* console init
*/
cnname = cninit(&addr, &speed);
1998-01-16 07:17:36 +03:00
/*
* make bootinfo
*/
bootinfo = (void *)0x3030;
1998-01-16 07:17:36 +03:00
/*
* memory
*/
btinfo_memory.common.next = sizeof (btinfo_memory);
1998-01-16 07:17:36 +03:00
btinfo_memory.common.type = BTINFO_MEMORY;
btinfo_memory.memsize = *(int *)0x3010;
/*
* console
*/
btinfo_console.common.next = sizeof (btinfo_console);
btinfo_console.common.type = BTINFO_CONSOLE;
strcpy(btinfo_console.devname, cnname);
btinfo_console.addr = addr;
btinfo_console.speed = speed;
1998-01-16 07:17:36 +03:00
/*
* clock
*/
btinfo_clock.common.next = 0;
btinfo_clock.common.type = BTINFO_CLOCK;
btinfo_clock.ticks_per_sec = TICKS_PER_SEC;
p = bootinfo;
1999-06-28 05:20:43 +04:00
memcpy(p, (void *)&btinfo_memory, sizeof (btinfo_memory));
p += sizeof (btinfo_memory);
1999-06-28 05:20:43 +04:00
memcpy(p, (void *)&btinfo_console, sizeof (btinfo_console));
p += sizeof (btinfo_console);
1999-06-28 05:20:43 +04:00
memcpy(p, (void *)&btinfo_clock, sizeof (btinfo_clock));
1998-01-16 07:17:36 +03:00
/*
* attached kernel check
*/
init_in();
1999-06-28 05:20:43 +04:00
runCPU1((void *)start_CPU1);
1998-01-16 07:17:36 +03:00
wait_for(&CPU1_alive);
printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
printf(">> Memory: %d k\n", btinfo_memory.memsize / 1024);
for (;;) {
name = names[n++];
if (n >= NUMNAMES)
n = 0;
1999-06-28 05:20:43 +04:00
exec_kernel(name, bootinfo);
1998-01-16 07:17:36 +03:00
}
}
/*
1999-06-28 05:20:43 +04:00
* Exec kernel
1998-01-16 07:17:36 +03:00
*/
1999-06-28 05:20:43 +04:00
void
exec_kernel(name, bootinfo)
char *name;
void *bootinfo;
1998-01-16 07:17:36 +03:00
{
1999-06-28 05:20:43 +04:00
int howto = 0;
1998-01-16 07:17:36 +03:00
char c, *ptr;
1999-06-28 05:20:43 +04:00
u_long marks[MARK_MAX];
1998-01-16 07:17:36 +03:00
#ifdef DBMONITOR
1999-06-28 05:20:43 +04:00
int go_monitor;
extern int db_monitor __P((void));
1998-01-16 07:17:36 +03:00
#endif /* DBMONITOR */
1999-06-28 05:20:43 +04:00
extern int tgets __P((char *buf));
1998-01-16 07:17:36 +03:00
ret:
1999-06-28 05:35:11 +04:00
printf("\nBoot: ");
memset(namebuf, 0, sizeof (namebuf));
(void)tgets(namebuf);
1998-01-16 07:17:36 +03:00
1999-06-28 05:20:43 +04:00
ptr = namebuf;
1998-01-16 07:17:36 +03:00
#ifdef DBMONITOR
1999-06-28 05:20:43 +04:00
go_monitor = 0;
if (*ptr == '!') {
if (*(++ptr) == NULL) {
1998-01-16 07:17:36 +03:00
db_monitor();
printf("\n");
goto ret;
1999-06-28 05:20:43 +04:00
} else {
go_monitor++;
1998-01-16 07:17:36 +03:00
}
1999-06-28 05:20:43 +04:00
}
1998-01-16 07:17:36 +03:00
#endif /* DBMONITOR */
1999-06-28 05:20:43 +04:00
while ((c = *ptr)) {
while (c == ' ')
c = *++ptr;
if (!c)
goto next;
if (c == '-') {
while ((c = *++ptr) && c != ' ')
BOOT_FLAG(c, howto);
1999-06-28 05:20:43 +04:00
} else {
name = ptr;
while ((c = *++ptr) && c != ' ');
if (c)
*ptr++ = 0;
1998-01-16 07:17:36 +03:00
}
}
1999-06-28 05:20:43 +04:00
next:
printf("Loading %s\n", name);
1998-01-16 07:17:36 +03:00
1999-06-28 05:20:43 +04:00
marks[MARK_START] = 0;
if (loadfile(name, marks, LOAD_ALL) == 0) {
1998-01-16 07:17:36 +03:00
#ifdef DBMONITOR
1999-06-28 05:20:43 +04:00
if (go_monitor) {
db_monitor();
printf("\n");
1998-01-16 07:17:36 +03:00
}
1999-06-28 05:20:43 +04:00
#endif /* DBMONITOR */
1998-01-16 07:17:36 +03:00
1999-06-28 05:20:43 +04:00
printf("start=0x%x\n\n", marks[MARK_ENTRY]);
delay(1000);
__syncicache((void *)marks[MARK_ENTRY],
(u_int)marks[MARK_SYM] - (u_int)marks[MARK_ENTRY]);
*(volatile u_long *)0x0080 = marks[MARK_ENTRY];
run((void *)marks[MARK_SYM],
(void *)marks[MARK_END],
(void *)howto,
bootinfo,
(void *)marks[MARK_ENTRY]);
1998-01-16 07:17:36 +03:00
}
}