diff options
author | msmith <msmith@FreeBSD.org> | 1998-08-21 03:17:42 +0000 |
---|---|---|
committer | msmith <msmith@FreeBSD.org> | 1998-08-21 03:17:42 +0000 |
commit | 8adeb775c43d4c2ae76cce40837a3953af6abc83 (patch) | |
tree | ec778e5f3903abe2dbb59959c0fd8398c99c145b /sys/boot/alpha/boot1 | |
parent | 335c4be5b17816baac6b70d4d0b3132925de858d (diff) | |
download | FreeBSD-src-8adeb775c43d4c2ae76cce40837a3953af6abc83.zip FreeBSD-src-8adeb775c43d4c2ae76cce40837a3953af6abc83.tar.gz |
This is the new unified bootstrap, sometimes known previously as the
'three-stage' bootstrap.
There are a number of caveats with the code in its current state:
- The i386 bootstrap only supports booting from a floppy.
- The kernel and kld do not yet know how to deal with the extended
information and module summary passed in.
- PnP-based autodetection and demand loading of modules is not implemented.
- i386 ELF kernel loading is not ready yet.
- The i386 bootstrap is loaded via an ugly blockmap.
On the alpha, both net- and disk-booting (SRM console machines only) is
supported. No blockmaps are used by this code.
Obtained from: Parts from the NetBSD/i386 standalone bootstrap.
Diffstat (limited to 'sys/boot/alpha/boot1')
-rw-r--r-- | sys/boot/alpha/boot1/Makefile | 47 | ||||
-rw-r--r-- | sys/boot/alpha/boot1/boot1.c | 188 | ||||
-rw-r--r-- | sys/boot/alpha/boot1/sys.c | 187 |
3 files changed, 422 insertions, 0 deletions
diff --git a/sys/boot/alpha/boot1/Makefile b/sys/boot/alpha/boot1/Makefile new file mode 100644 index 0000000..f97f5fb --- /dev/null +++ b/sys/boot/alpha/boot1/Makefile @@ -0,0 +1,47 @@ +# $NetBSD: Makefile,v 1.15 1998/03/28 00:21:35 thorpej Exp $ + +.include <../Makefile.inc> + +PROG = boot1 + +.PATH: ${.CURDIR}/../../common +.PATH: ${.CURDIR}/../libalpha + +SRCS= start.S boot1.c sys.c +CFLAGS+= -mno-fp-regs +CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR} +LIBSTANDDIR= /home/dfr/FreeBSD/alpha/src/lib/libstand +LIBSTAND= ${LIBSTANDDIR}/obj/libstand.a +CFLAGS+= -I${LIBSTANDDIR} +LIBALPHA= ${.CURDIR}/../libalpha/obj/libalpha.a +CFLAGS+= -I${.CURDIR}/.. +CFLAGS+= -DSECONDARY_LOAD_ADDRESS=0x${SECONDARY_LOAD_ADDRESS} -DMINIMAL +NOMAN=1 +STRIP= + +BOOT_RELOC = ${PRIMARY_LOAD_ADDRESS} + +CLEANFILES+= ${PROG}.sym ${PROG}.nosym ${PROG}.list + +all: ${PROG} + +afterinstall: + ln -sf boot1 /usr/mdec/sdboot + +${PROG}.nosym: ${PROG}.sym + cp ${PROG}.sym ${PROG}.nosym + strip ${PROG}.nosym + +${PROG}: ${PROG}.nosym + objcopy -O binary ${PROG}.nosym ${PROG} + +.include <bsd.prog.mk> + +start.o: ${.CURDIR}/../libalpha/start.S + ${CC} -c -DPRIMARY_BOOTBLOCK $< + +${PROG}.sym: ${OBJS} ${LIBKERN} + ${LD} -M -Ttext ${BOOT_RELOC} -N -e start -o ${PROG}.sym ${OBJS} \ + ${LIBSTAND} ${LIBALPHA} ${LIBSTAND} > ${.OBJDIR}/${PROG}.list + size ${PROG}.sym + diff --git a/sys/boot/alpha/boot1/boot1.c b/sys/boot/alpha/boot1/boot1.c new file mode 100644 index 0000000..e52987a --- /dev/null +++ b/sys/boot/alpha/boot1/boot1.c @@ -0,0 +1,188 @@ +/* + * $Id$ + * From $NetBSD: bootxx.c,v 1.4 1997/09/06 14:08:29 drochner Exp $ + */ + +/* + * Copyright (c) 1995 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * 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 the + * rights to redistribute these changes. + */ + +#include <sys/param.h> + +#include <machine/prom.h> + +#define DEBUGxx + +extern end[]; +int errno; + +char *heap = (char*) end; + +void +putchar(int c) +{ + if (c == '\n') + prom_putchar('\r'); + prom_putchar(c); +} + +void +puts(const char *s) +{ + while (*s) + putchar(*s++); +} + +void * +malloc(size_t size) +{ + char *p = heap; + size = (size + 7) & ~7; + heap += size; + return p; +} + +void +free(void * p) +{ +} + +void +panic(const char *message, ...) +{ + puts(message); + puts("\r\n"); + halt(); +} + +int prom_fd = 0; + +int +devopen() +{ + prom_return_t ret; + char devname[64]; + + if (prom_fd) + return; + + ret.bits = prom_getenv(PROM_E_BOOTED_DEV, devname, sizeof devname); + + ret.bits = prom_open(devname, ret.u.retval + 1); + if (ret.u.status) + panic("devopen: open failed\n"); + + prom_fd = ret.u.retval; + + /* XXX read disklabel and setup partition offset */ + + return 0; +} + +#ifdef DEBUG + +void +puthex(u_long v) +{ + int digit; + char hex[] = "0123456789abcdef"; + + if (!v) { + puts("0"); + return; + } + + for (digit = 0; v >= (0x10L << digit); digit += 4) + ; + + for (; digit >= 0; digit -= 4) + putchar(hex[(v >> digit) & 0xf]); +} + +#endif + +void +devread(char *buf, int block, size_t size) +{ +#ifdef DEBUG + puts("devread("); + puthex((u_long)buf); + puts(","); + puthex(block); + puts(","); + puthex(size); + puts(")\n"); +#endif + + prom_read(prom_fd, size, buf, block); +} + +void +devclose() +{ + if (prom_fd) { + prom_close(prom_fd); + prom_fd = 0; + } +} + +void +loadfile(char *name, char *addr) +{ + int n; + + if (openrd(name)) { + puts("Can't open file "); + puts(name); + puts("\n"); + halt(); + } + + do { + n = read(addr, 1024); + addr += n; + twiddle(); + } while (n > 0); + + devclose(); +} + +void +main() +{ + char *loadaddr = (char*) SECONDARY_LOAD_ADDRESS; + char *p; + void (*entry) __P((void)); + + int i; + + init_prom_calls(); + + loadfile("/boot/boot2", loadaddr); + + entry = (void (*)())loadaddr; + (*entry)(); +} diff --git a/sys/boot/alpha/boot1/sys.c b/sys/boot/alpha/boot1/sys.c new file mode 100644 index 0000000..1c0d912 --- /dev/null +++ b/sys/boot/alpha/boot1/sys.c @@ -0,0 +1,187 @@ +/* + * 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. + * + * from: Mach, Revision 2.2 92/04/04 11:36:34 rpd + * fromL Id: sys.c,v 1.21 1997/06/09 05:10:56 bde Exp + * $Id$ + */ + +#include <sys/param.h> +#include <sys/time.h> + +#include <ufs/ffs/fs.h> +#include <ufs/ufs/quota.h> +#include <ufs/ufs/inode.h> + +#include <sys/dirent.h> + +struct fs *fs; +struct inode inode; +int boff = 0; + +#if 0 +/* #define BUFSIZE 4096 */ +#define BUFSIZE MAXBSIZE + +static char buf[BUFSIZE], fsbuf[SBSIZE], iobuf[MAXBSIZE]; +#endif + +#define BUFSIZE 8192 +#define MAPBUFSIZE BUFSIZE +static char buf[BUFSIZE], fsbuf[BUFSIZE], iobuf[BUFSIZE]; + +static char mapbuf[MAPBUFSIZE]; +static int mapblock; + +int poff; + +#ifdef RAWBOOT +#define STARTBYTE 8192 /* Where on the media the kernel starts */ +#endif + +static int block_map(int file_block); +static int find(char *path); + +int +read(char *buffer, int count) +{ + int logno, off, size; + int cnt2, bnum2; + struct fs *fs_copy; + int n = 0; + + if (poff + count > inode.i_size) + count = inode.i_size - poff; + while (count > 0 && poff < inode.i_size) { + fs_copy = fs; + off = blkoff(fs_copy, poff); + logno = lblkno(fs_copy, poff); + cnt2 = size = blksize(fs_copy, &inode, logno); + bnum2 = fsbtodb(fs_copy, block_map(logno)) + boff; + if ( (!off) && (size <= count)) { + devread(buffer, bnum2, cnt2); + } else { + size -= off; + if (size > count) + size = count; + devread(iobuf, bnum2, cnt2); + bcopy(iobuf+off, buffer, size); + } + buffer += size; + count -= size; + poff += size; + n += size; + } + return n; +} + +static int +find(char *path) +{ + char *rest, ch; + int block, off, loc, ino = ROOTINO; + struct dirent *dp; + char list_only; + + list_only = (path[0] == '?' && path[1] == '\0'); + loop: + devread(iobuf, fsbtodb(fs, ino_to_fsba(fs, ino)) + boff, fs->fs_bsize); + bcopy((void *)&((struct dinode *)iobuf)[ino % fs->fs_inopb], + (void *)&inode.i_din, + sizeof (struct dinode)); + if (!*path) + return 1; + while (*path == '/') + path++; + if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR)) + return 0; + for (rest = path; (ch = *rest) && ch != '/'; rest++) ; + *rest = 0; + loc = 0; + do { + if (loc >= inode.i_size) { + if (list_only) { + putchar('\n'); + return -1; + } else { + return 0; + } + } + if (!(off = blkoff(fs, loc))) { + block = lblkno(fs, loc); + devread(iobuf, fsbtodb(fs, block_map(block)) + boff, + blksize(fs, &inode, block)); + } + dp = (struct dirent *)(iobuf + off); + loc += dp->d_reclen; + if (dp->d_fileno && list_only) { + puts(dp->d_name); + putchar(' '); + } + } while (!dp->d_fileno || strcmp(path, dp->d_name)); + ino = dp->d_fileno; + *(path = rest) = ch; + goto loop; +} + + +static int +block_map(int file_block) +{ + int bnum; + if (file_block < NDADDR) + return(inode.i_db[file_block]); + if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) { + devread(mapbuf, bnum, fs->fs_bsize); + mapblock = bnum; + } + return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]); +} + + +int +openrd(char *name) +{ + int ret; + + if (devopen()) + return 1; + + /* + * Load Filesystem info (mount the device). + */ + devread((char *)(fs = (struct fs *)fsbuf), SBLOCK + boff, SBSIZE); + + /* + * Find the actual FILE on the mounted device. + */ + ret = find(name); + if (ret == 0) + return 1; + if (ret < 0) + return -1; + poff = 0; + return 0; +} |