1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1992, 1991 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie Mellon
|
|
|
|
* the rights to redistribute these changes.
|
1993-10-11 02:43:42 +00:00
|
|
|
*
|
1993-10-16 19:17:18 +00:00
|
|
|
* from: Mach, [92/04/03 16:51:14 rvb]
|
1994-10-06 09:41:05 +00:00
|
|
|
* $Id: boot.c,v 1.15 1994/08/21 17:47:25 paul Exp $
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright 1988, 1989, 1990, 1991, 1992
|
|
|
|
by Intel Corporation, Santa Clara, California.
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software and
|
|
|
|
its documentation for any purpose and without fee is hereby
|
|
|
|
granted, provided that the above copyright notice appears in all
|
|
|
|
copies and that both the copyright notice and this permission notice
|
|
|
|
appear in supporting documentation, and that the name of Intel
|
|
|
|
not be used in advertising or publicity pertaining to distribution
|
|
|
|
of the software without specific, written prior permission.
|
|
|
|
|
|
|
|
INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
|
|
|
|
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
|
|
|
|
IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
|
|
|
|
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
|
|
|
|
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include "boot.h"
|
|
|
|
#include <a.out.h>
|
|
|
|
#include <sys/reboot.h>
|
1994-10-06 09:41:05 +00:00
|
|
|
#include <machine/bootinfo.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
struct exec head;
|
1994-10-06 09:41:05 +00:00
|
|
|
struct bootinfo_t bootinfo;
|
1993-06-12 14:58:17 +00:00
|
|
|
char *name;
|
|
|
|
char *names[] = {
|
1994-08-21 17:47:26 +00:00
|
|
|
"/kernel"
|
1993-06-12 14:58:17 +00:00
|
|
|
};
|
|
|
|
#define NUMNAMES (sizeof(names)/sizeof(char *))
|
|
|
|
|
|
|
|
extern int end;
|
|
|
|
boot(drive)
|
|
|
|
int drive;
|
|
|
|
{
|
|
|
|
int loadflags, currname = 0;
|
1993-07-13 18:15:32 +00:00
|
|
|
char *t;
|
|
|
|
|
1994-08-21 17:47:26 +00:00
|
|
|
printf("\n>> FreeBSD BOOT @ 0x%x: %d/%d k of memory\n",
|
1993-06-12 14:58:17 +00:00
|
|
|
ouraddr,
|
1994-10-06 09:41:05 +00:00
|
|
|
memsize(0),
|
|
|
|
memsize(1));
|
1994-08-21 17:47:26 +00:00
|
|
|
printf("use hd(1,a)/kernel to boot sd0 when wd0 is also installed\n");
|
1993-06-12 14:58:17 +00:00
|
|
|
gateA20();
|
|
|
|
loadstart:
|
|
|
|
/***************************************************************\
|
|
|
|
* As a default set it to the first partition of the first *
|
|
|
|
* floppy or hard drive *
|
|
|
|
\***************************************************************/
|
|
|
|
part = unit = 0;
|
|
|
|
maj = (drive&0x80 ? 0 : 2); /* a good first bet */
|
|
|
|
name = names[currname++];
|
|
|
|
|
|
|
|
loadflags = 0;
|
|
|
|
if (currname == NUMNAMES)
|
|
|
|
currname = 0;
|
|
|
|
getbootdev(&loadflags);
|
|
|
|
if (openrd()) {
|
|
|
|
printf("Can't find %s\n", name);
|
|
|
|
goto loadstart;
|
|
|
|
}
|
|
|
|
/* if (inode.i_mode&IEXEC)
|
|
|
|
loadflags |= RB_KDB;
|
|
|
|
*/
|
|
|
|
loadprog(loadflags);
|
|
|
|
goto loadstart;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadprog(howto)
|
|
|
|
int howto;
|
|
|
|
{
|
|
|
|
long int startaddr;
|
|
|
|
long int addr; /* physical address.. not directly useable */
|
1994-10-06 09:41:05 +00:00
|
|
|
long int bootdev;
|
|
|
|
long int total;
|
1993-06-12 14:58:17 +00:00
|
|
|
int i;
|
|
|
|
unsigned char tmpbuf[4096]; /* we need to load the first 4k here */
|
|
|
|
|
|
|
|
read(&head, sizeof(head));
|
1993-07-13 18:15:32 +00:00
|
|
|
if ( N_BADMAG(head)) {
|
1993-06-12 14:58:17 +00:00
|
|
|
printf("Invalid format!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1993-07-13 18:15:32 +00:00
|
|
|
poff = N_TXTOFF(head);
|
|
|
|
/*if(poff==0)
|
|
|
|
poff = 32;*/
|
|
|
|
|
1994-10-06 09:41:05 +00:00
|
|
|
startaddr = (int)head.a_entry & 0x00FFFFFF; /* some MEG boundary */
|
|
|
|
addr = startaddr;
|
1993-06-12 14:58:17 +00:00
|
|
|
printf("Booting %s(%d,%c)%s @ 0x%x\n"
|
|
|
|
, devs[maj]
|
|
|
|
, unit
|
|
|
|
, 'a'+part
|
|
|
|
, name
|
|
|
|
, addr);
|
|
|
|
if(addr < ouraddr)
|
|
|
|
{
|
|
|
|
if((addr + head.a_text + head.a_data) > ouraddr)
|
|
|
|
{
|
1994-06-16 03:53:29 +00:00
|
|
|
printf("kernel overlaps loader\n");
|
1993-06-12 14:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
1993-10-15 12:33:03 +00:00
|
|
|
if((addr + head.a_text + head.a_data + head.a_bss) > 0xa0000)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1994-06-16 03:53:29 +00:00
|
|
|
printf("bss exceeds 640k limit\n");
|
1993-06-12 14:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1993-07-13 18:15:32 +00:00
|
|
|
printf("text=0x%x ", head.a_text);
|
1993-06-12 14:58:17 +00:00
|
|
|
/********************************************************/
|
|
|
|
/* LOAD THE TEXT SEGMENT */
|
|
|
|
/* don't clobber the first 4k yet (BIOS NEEDS IT) */
|
|
|
|
/********************************************************/
|
|
|
|
read(tmpbuf,4096);
|
|
|
|
addr += 4096;
|
|
|
|
xread(addr, head.a_text - 4096);
|
|
|
|
addr += head.a_text - 4096;
|
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* Load the Initialised data after the text */
|
|
|
|
/********************************************************/
|
|
|
|
while (addr & CLOFSET)
|
|
|
|
*(char *)addr++ = 0;
|
|
|
|
|
1993-07-13 18:15:32 +00:00
|
|
|
printf("data=0x%x ", head.a_data);
|
1993-06-12 14:58:17 +00:00
|
|
|
xread(addr, head.a_data);
|
|
|
|
addr += head.a_data;
|
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* Skip over the uninitialised data */
|
|
|
|
/* (but clear it) */
|
|
|
|
/********************************************************/
|
1993-07-13 18:15:32 +00:00
|
|
|
printf("bss=0x%x ", head.a_bss);
|
1993-06-12 14:58:17 +00:00
|
|
|
if( (addr < ouraddr) && ((addr + head.a_bss) > ouraddr))
|
|
|
|
{
|
|
|
|
pbzero(addr,ouraddr - (int)addr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pbzero(addr,head.a_bss);
|
|
|
|
}
|
1994-10-06 09:41:05 +00:00
|
|
|
addr += head.a_bss;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
#ifdef LOADSYMS /* not yet, haven't worked this out yet */
|
|
|
|
if (addr > 0x100000)
|
|
|
|
{
|
|
|
|
/********************************************************/
|
|
|
|
/*copy in the symbol header */
|
|
|
|
/********************************************************/
|
|
|
|
pcpy(&head.a_syms, addr, sizeof(head.a_syms));
|
|
|
|
addr += sizeof(head.a_syms);
|
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* READ in the symbol table */
|
|
|
|
/********************************************************/
|
1993-07-13 18:15:32 +00:00
|
|
|
printf("symbols=[+0x%x", head.a_syms);
|
1993-06-12 14:58:17 +00:00
|
|
|
xread(addr, head.a_syms);
|
|
|
|
addr += head.a_syms;
|
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* Followed by the next integer (another header) */
|
|
|
|
/* more debug symbols? */
|
|
|
|
/********************************************************/
|
|
|
|
read(&i, sizeof(int));
|
|
|
|
pcpy(&i, addr, sizeof(int));
|
|
|
|
i -= sizeof(int);
|
|
|
|
addr += sizeof(int);
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* and that many bytes of (debug symbols?) */
|
|
|
|
/********************************************************/
|
1993-07-13 18:15:32 +00:00
|
|
|
printf("+0x%x] ", i);
|
1993-06-12 14:58:17 +00:00
|
|
|
xread(addr, i);
|
|
|
|
addr += i;
|
|
|
|
}
|
|
|
|
#endif LOADSYMS
|
|
|
|
/********************************************************/
|
|
|
|
/* and note the end address of all this */
|
|
|
|
/********************************************************/
|
|
|
|
|
1994-10-06 09:41:05 +00:00
|
|
|
total = ((addr+sizeof(int)-1))&~(sizeof(int)-1);
|
|
|
|
printf("total=0x%x ", total);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*
|
1994-10-06 09:41:05 +00:00
|
|
|
* If we are booting from floppy prompt for a filesystem floppy
|
|
|
|
* before we call the kernel
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
switch(maj)
|
|
|
|
{
|
|
|
|
case 2:
|
1993-10-09 08:31:39 +00:00
|
|
|
printf("\n\nInsert file system floppy in drive A or B\n");
|
|
|
|
printf("Press 'A', 'B' or any other key for the default ");
|
|
|
|
printf("%c: ", unit+'A');
|
|
|
|
i = getchar();
|
1994-05-01 03:53:29 +00:00
|
|
|
if (i=='0' || i=='A' || i=='a')
|
|
|
|
unit = 0;
|
|
|
|
if (i=='1' || i=='B' || i=='b')
|
|
|
|
unit = 1;
|
1993-10-09 08:31:39 +00:00
|
|
|
printf("\n");
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
break;
|
|
|
|
}
|
1994-10-06 09:41:05 +00:00
|
|
|
bootdev = (MAKEBOOTDEV(maj, 0, 0, unit, part)) ;
|
1993-06-12 14:58:17 +00:00
|
|
|
/****************************************************************/
|
|
|
|
/* copy that first page and overwrite any BIOS variables */
|
|
|
|
/****************************************************************/
|
1994-10-06 09:41:05 +00:00
|
|
|
printf("entry point=0x%x\n" ,(int)startaddr);
|
1993-07-13 18:15:32 +00:00
|
|
|
/* Under no circumstances overwrite precious BIOS variables! */
|
1994-10-06 09:41:05 +00:00
|
|
|
pcpy(tmpbuf, startaddr, 0x400);
|
|
|
|
pcpy(tmpbuf + 0x500, startaddr + 0x500, 4096 - 0x500);
|
|
|
|
bootinfo.version=1;
|
|
|
|
bootinfo.kernelname=(char *)((int)name + (BOOTSEG<<4));
|
|
|
|
bootinfo.nfs_diskless=0;
|
|
|
|
startprog((int)startaddr, howto, bootdev, (int)&bootinfo+(BOOTSEG<<4));
|
|
|
|
return;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char namebuf[100];
|
|
|
|
getbootdev(howto)
|
|
|
|
int *howto;
|
|
|
|
{
|
|
|
|
char c, *ptr = namebuf;
|
|
|
|
printf("Boot: [[[%s(%d,%c)]%s][-s][-a][-d]] :- "
|
|
|
|
, devs[maj]
|
|
|
|
, unit
|
|
|
|
, 'a'+part
|
|
|
|
, name);
|
|
|
|
if (gets(namebuf)) {
|
|
|
|
while (c=*ptr) {
|
|
|
|
while (c==' ')
|
|
|
|
c = *++ptr;
|
|
|
|
if (!c)
|
|
|
|
return;
|
|
|
|
if (c=='-')
|
|
|
|
while ((c = *++ptr) && c!=' ')
|
|
|
|
switch (c) {
|
1994-04-20 22:06:24 +00:00
|
|
|
case 'r':
|
|
|
|
*howto |= RB_DFLTROOT; continue;
|
1993-06-12 14:58:17 +00:00
|
|
|
case 'a':
|
|
|
|
*howto |= RB_ASKNAME; continue;
|
|
|
|
case 's':
|
|
|
|
*howto |= RB_SINGLE; continue;
|
|
|
|
case 'd':
|
|
|
|
*howto |= RB_KDB; continue;
|
|
|
|
case 'b':
|
|
|
|
*howto |= RB_HALT; continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
name = ptr;
|
|
|
|
while ((c = *++ptr) && c!=' ');
|
|
|
|
if (c)
|
|
|
|
*ptr++ = 0;
|
|
|
|
}
|
|
|
|
}
|
1993-07-13 18:15:32 +00:00
|
|
|
} else
|
|
|
|
printf("\n");
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|