Sparc bootblocks (a tight fit)

This commit is contained in:
pk 1994-02-26 10:57:09 +00:00
parent a7ccc4228a
commit 196acb6c78
6 changed files with 643 additions and 0 deletions

View File

@ -0,0 +1,85 @@
# from: @(#)Makefile 8.1 (Berkeley) 6/10/93
# $Id: Makefile,v 1.1 1994/02/26 10:57:09 pk Exp $
DESTDIR=
RELOC_SUN4= 240000
RELOC_SUN4C= 340000
RELOC_SUN4M= 440000
RELOC= ${RELOC_SUN4C}
DEFS= -DSTANDALONE -DCOMPAT_NOLABEL # -DROMPRF
CFLAGS= -O2 ${INCPATH} ${DEFS}
SRCS= boot.c promdev.c version.c
#SRCS+= io.c strerror.c
S= ${.CURDIR}/../../..
.PATH: ${S}/arch/${MACHINE_ARCH}/${MACHINE_ARCH}
.PATH: ${S}/stand ${S}/lib/libsa
INCPATH=-I${.CURDIR} -I${.CURDIR}/../.. -I${S} -I${S}/lib/libsa
### find out what to use for libkern
.include "$S/lib/libkern/Makefile.inc"
LIBKERN= ${KERNLIB}
#KERNLIB= ${.CURDIR}/../compile/libkern.a
.include "$S/lib/libsa/Makefile.inc"
LIBSA= ${SA_LIB}
LIBS= ${LIBSA} ${LIBKERN}
BOOTS= boot
ALL= ${BOOTS}
all: ${ALL}
${BOOTS}: ${LIBS}
OBJS= ${SRCS:N*.h:R:S/$/.o/g}
${.OBJDIR}/libdrive.a: ${OBJS}
ar crv $@ $?
ranlib $@
# depend on DEFS
devopen.o machdep.o srt0.o: Makefile
# startups
srt0.o: ${.CURDIR}/srt0.S
${CC} ${INCPATH} ${DEFS} -c ${.CURDIR}/srt0.S
# new boot
boot: srt0.o ${OBJS} ${LIBS} fixhdr
${LD} -N -T ${RELOC} -e start srt0.o ${OBJS} ${LIBS} -o $@
${.OBJDIR}/fixhdr boot
@size boot
bootconf.o: ${.CURDIR}/conf.c
rm -f bootconf.c
ln -s ${.CURDIR}/conf.c bootconf.c
${CC} -c ${CFLAGS} -DBOOT bootconf.c
rm -f bootconf.c
mkboot: ${.CURDIR}/mkboot.c
${CC} ${CFLAGS} -o mkboot ${.CURDIR}/mkboot.c
installboot: ${.CURDIR}/installboot.c
${CC} ${CFLAGS} -o installboot ${.CURDIR}/installboot.c
# utilities
fixhdr: fixhdr.c
${CC} -o fixhdr ${.CURDIR}/fixhdr.c
clean cleandir:
rm -f *.o errs make.out
rm -f a.out boot cat ls fixhdr
.include <bsd.dep.mk>
.include <bsd.obj.mk>

165
sys/arch/sparc/stand/boot.c Normal file
View File

@ -0,0 +1,165 @@
/*-
* Copyright (c) 1982, 1986, 1990, 1993
* The Regents of the University of California. 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 the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS OR CONTRIBUTORS 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.
*
* from: @(#)boot.c 8.1 (Berkeley) 6/10/93
*
* $Id: boot.c,v 1.1 1994/02/26 10:57:13 pk Exp $
*/
#include <sys/param.h>
#include <sys/reboot.h>
#include <a.out.h>
#include <machine/bsd_openprom.h>
#include "stand.h"
/*
* Boot device is derived from ROM provided information.
*/
extern char *version;
extern struct promvec *promvec;
char *ssym, *esym;
main(pp)
struct promvec *pp;
{
int io;
char *file;
printf(">> NetBSD BOOT [%s]\n", version);
if (promvec->pv_romvec_vers == 2)
file = *promvec->pv_v2bootargs.v2_bootargs;
else
file = (*promvec->pv_v0bootargs)->ba_kernel;
if ((io = open(file, 0)) < 0) {
printf("Can't open %s: %s\n", file, strerror(errno));
promvec->pv_halt();
}
reset_twiddle();
printf("Booting %s @ 0x%x\n", file, 0x4000);
copyunix(io, 0x4000);
promvec->pv_halt();
}
/*ARGSUSED*/
copyunix(io, addr)
register int io;
register char *addr;
{
struct exec x;
int i;
void (*entry)() = (void (*)())addr;
i = read(io, (char *)&x, sizeof(x));
if (i != sizeof(x) ||
N_BADMAG(x)) {
printf("Bad format\n");
return;
}
reset_twiddle();
printf("%d", x.a_text);
if (N_GETMAGIC(x) == ZMAGIC) {
entry = (void (*)())(addr+sizeof(struct exec));
addr += sizeof(struct exec);
}
if (read(io, (char *)addr, x.a_text) != x.a_text)
goto shread;
addr += x.a_text;
if (N_GETMAGIC(x) == ZMAGIC || N_GETMAGIC(x) == NMAGIC)
while ((int)addr & CLOFSET)
*addr++ = 0;
reset_twiddle();
printf("+%d", x.a_data);
if (read(io, addr, x.a_data) != x.a_data)
goto shread;
addr += x.a_data;
reset_twiddle();
printf("+%d", x.a_bss);
for (i = 0; i < x.a_bss; i++)
*addr++ = 0;
ssym = addr;
if (x.a_syms != 0) {
bcopy(&x.a_syms, addr, sizeof(x.a_syms));
addr += sizeof(x.a_syms);
printf(" [%d+", x.a_syms);
if (read(io, addr, x.a_syms) != x.a_syms)
goto shread;
addr += x.a_syms;
reset_twiddle();
if (read(io, &i, sizeof(int)) != sizeof(int))
goto shread;
reset_twiddle();
bcopy(&i, addr, sizeof(int));
if (i) {
i -= sizeof(int);
addr += sizeof(int);
if (read(io, addr, i) != i)
goto shread;
reset_twiddle();
addr += i;
}
printf("%d] ", i);
}
printf(" start 0x%x\n", (int)entry);
(*entry)(promvec);
return;
shread:
printf("Short read\n");
return;
}
static int tw_on;
static int tw_pos;
static char tw_chars[] = "|/-\\";
reset_twiddle()
{
if (tw_on)
putchar('\b');
tw_on = 0;
tw_pos = 0;
}
twiddle()
{
if (tw_on)
putchar('\b');
else
tw_on = 1;
putchar(tw_chars[tw_pos++]);
tw_pos %= (sizeof(tw_chars) - 1);
}

View File

@ -0,0 +1,43 @@
#include <stdio.h>
#include <fcntl.h>
main(argc, argv)
int argc;
char *argv[];
{
int fd;
struct sun_magic {
unsigned int a_dynamic:1;
unsigned int a_toolversion:7;
unsigned char a_machtype;
#define SUN_MID_SPARC 3
unsigned short a_magic;
} sm;
if (argc != 2) {
fprintf(stderr, "Usage: fixhdr <bootfile>\n");
exit(1);
}
if ((fd = open(argv[1], O_RDWR, 0)) < 0) {
perror("open");
exit(1);
}
if (read(fd, &sm, sizeof(sm)) != sizeof(sm)) {
perror("read");
exit(1);
}
sm.a_dynamic = 0;
sm.a_toolversion = 1;
sm.a_machtype = SUN_MID_SPARC;
lseek(fd, 0, 0);
if (write(fd, &sm, sizeof(sm)) != sizeof(sm)) {
perror("write");
exit(1);
}
(void)close(fd);
return 0;
}

View File

@ -0,0 +1,243 @@
/*
* Copyright (c) 1993 Paul Kranenburg
* 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 Paul Kranenburg.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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.
*
* $Id: promdev.c,v 1.1 1994/02/26 10:57:18 pk Exp $
*/
#include <sys/param.h>
#include <sys/disklabel.h>
#include <machine/bsd_openprom.h>
#include "stand.h"
int promopen __P((struct open_file *, ...));
int promclose __P((struct open_file *));
int promioctl __P((struct open_file *, int, void *));
int promstrategy __P((void *, int, daddr_t, u_int, char *, u_int *));
struct devsw devsw[] = {
{ "prom", promstrategy, promopen, promclose, promioctl },
};
int ndevs = (sizeof(devsw)/sizeof(devsw[0]));
struct promvec *promvec;
struct prom_softc {
int fd; /* Prom file descriptor */
int poff; /* Partition offset */
int psize; /* Partition size */
} prom_softc[1];
static struct disklabel sdlabel;
int
devopen(f, fname, file)
struct open_file *f;
char *fname;
char **file;
{
int v2 = promvec->pv_romvec_vers == 2;
register struct prom_softc *pp = &prom_softc[0];
int error, i, pn = 0;
char *dev, *cp;
static char iobuf[MAXBSIZE];
if (v2)
dev = *promvec->pv_v2bootargs.v2_bootpath;
else
dev = (*promvec->pv_v0bootargs)->ba_bootdev;
/*
* Extract partition # from boot device string.
*/
for (cp = dev; *cp; cp++) /* void */;
while (*cp != '/' && cp > dev) {
if (*cp == ':')
pn = *(cp+1) - 'a';
--cp;
}
if (v2)
pp->fd = (*promvec->pv_v2devops.v2_open)(dev);
else
pp->fd = (*promvec->pv_v0devops.v0_open)(dev);
if (pp->fd == 0) {
printf("Can't open device `%s'\n", dev);
return ENXIO;
}
error = promstrategy(pp, F_READ, LABELSECTOR, DEV_BSIZE, iobuf, &i);
if (error)
return error;
if (i != DEV_BSIZE)
return EINVAL;
if (sun_disklabel(iobuf, &sdlabel) == 0) {
printf("WARNING: no label\n");
/* some default label */
return EINVAL;
} else {
pp->poff = sdlabel.d_partitions[pn].p_offset;
pp->psize = sdlabel.d_partitions[pn].p_size;
}
f->f_dev = devsw;
f->f_devdata = (void *)pp;
*file = fname;
return 0;
}
#include <sparc/scsi/sun_disklabel.h>
/*
* Take a sector (cp) containing a SunOS disk label and set lp to a BSD
* disk label.
*/
int
sun_disklabel(cp, lp)
register caddr_t cp;
register struct disklabel *lp;
{
register u_short *sp;
register struct sun_disklabel *sl;
register int i, v;
sp = (u_short *)(cp + sizeof(struct sun_disklabel));
--sp;
v = 0;
while (sp >= (u_short *)cp)
v ^= *sp--;
if (v)
return (0);
sl = (struct sun_disklabel *)cp;
lp->d_magic = 0; /* denote as pseudo */
lp->d_ncylinders = sl->sl_ncylinders;
lp->d_acylinders = sl->sl_acylinders;
v = (lp->d_ntracks = sl->sl_ntracks) *
(lp->d_nsectors = sl->sl_nsectors);
lp->d_secpercyl = v;
lp->d_npartitions = 8;
for (i = 0; i < 8; i++) {
lp->d_partitions[i].p_offset =
sl->sl_part[i].sdkp_cyloffset * v;
lp->d_partitions[i].p_size = sl->sl_part[i].sdkp_nsectors;
#ifdef DEBUG
printf("P%d: off %x, size %x\n", i,
lp->d_partitions[i].p_offset, lp->d_partitions[i].p_size);
#endif
}
return (1);
}
int
promstrategy(devdata, func, dblk, size, buf, rsize)
void *devdata;
int func;
daddr_t dblk;
u_int size;
char *buf;
u_int *rsize;
{
register struct prom_softc *pp = (struct prom_softc *)devdata;
u_int (*pf)();
int v2 = promvec->pv_romvec_vers == 2;
daddr_t blk = dblk + pp->poff;
int error = 0;
#ifdef DEBUG
printf("promstrategy: size=%d blk=%d dblk=%d\n", size, blk, dblk);
#endif
twiddle();
if (func == F_READ)
pf = v2 ? (u_int (*)())promvec->pv_v2devops.v2_read:
(u_int (*)())promvec->pv_v0devops.v0_rbdev;
else
pf = v2 ? (u_int (*)())promvec->pv_v2devops.v2_write:
(u_int (*)())promvec->pv_v0devops.v0_wbdev;
if (v2)
(*promvec->pv_v2devops.v2_seek)(pp->fd, 0, blk<<DEV_BSHIFT);
else
(*promvec->pv_v0devops.v0_seek)(pp->fd, blk<<DEV_BSHIFT, 0);
if (v2) {
*rsize = (*pf)(pp->fd, buf, size);
} else
*rsize = (*pf)(pp->fd, size>>DEV_BSHIFT, blk, buf);
return error;
}
int
promopen(f)
struct open_file *f;
{
#ifdef DEBUG
printf("promopen:\n");
#endif
f->f_devdata = (void *)prom_softc;
return 0;
}
int
promclose(f)
struct open_file *f;
{
return EIO;
}
int
promioctl(f, cmd, data)
struct open_file *f;
int cmd;
void *data;
{
return EIO;
}
getchar()
{
register int c;
c = (*promvec->pv_getchar)();
if (c == '\r')
c = '\n';
return (c);
}
putchar(c)
register int c;
{
if (c == '\n')
(*promvec->pv_putchar)('\r');
(*promvec->pv_putchar)(c);
}

View File

@ -0,0 +1,96 @@
#define CCFSZ 96
.file "str0.s"
.text
.globl start
start:
/*
* Set up a stack.
*/
set start, %o1
save %o1, -CCFSZ, %sp
/*
* Relocate.
*/
1: call 2f
nop
2: add %o7, (start-1b), %l0
set start, %l1
set _end, %o0
sub %o0, %l1, %l2 ! length
3: ld [%l0], %o0
add %l0, 4, %l0
st %o0, [%l1]
subcc %l2, 4, %l2
bg 3b
add %l1, 4, %l1
set 4f, %g1
jmp %g1
nop
4:
/*
* Clear BSS
*/
set _edata, %o0 ! bzero(edata, end - edata)
set _end, %o1
call _bzero
sub %o1, %o0, %o1
/*
* Save address of PROM vector (passed in %i0).
*/
sethi %hi(_promvec), %o0
st %i0, [%o0 + %lo(_promvec)]
/*
* That's it, really...
*/
call _main
mov %i0, %o0
ret
restore
/*
* XXX - Space saving .div & .rem routines (small & non-negative numbres only)
*/
.align 4
.global .div, .udiv
! int n = 0; while (a >= b) { a -= b; n++; }; return n;
.div:
.udiv:
cmp %o0, %o1
bl 2f
mov 0, %o5
1:
sub %o0, %o1, %o0
cmp %o0, %o1
bge 1b
add %o5, 1, %o5
2:
retl
mov %o5, %o0
.align 4
.global .rem, .urem
! while (a>=b) a -= b; return a;
.rem:
.urem:
cmp %o0, %o1
bl 2f
nop
sub %o0, %o1, %o0
1:
cmp %o0, %o1
bge,a 1b
sub %o0, %o1, %o0
2:
retl
nop

View File

@ -0,0 +1,11 @@
/*
* $Id: version.c,v 1.1 1994/02/26 10:57:23 pk Exp $
*/
/*
* NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE.
*
* 1.1
*/
char *version = "$Revision: 1.1 $";