From 3ec83368532e685f9a6b3d32640f9a3791e707af Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Thu, 12 Dec 1996 08:42:53 +0000 Subject: new makefile system, sun4/sun4c/sun4m a.out header hacking, some from netbsd --- sys/arch/sparc/stand/Makefile | 6 ++-- sys/arch/sparc/stand/binstall.sh | 27 +++++++++--------- sys/arch/sparc/stand/installboot.8 | 38 ++++++++++++++++--------- sys/arch/sparc/stand/installboot.c | 58 ++++++++++++++++++++++++++++++-------- sys/arch/sparc/stand/srt0.S | 6 ++-- sys/arch/sparc/stand/version.c | 2 +- 6 files changed, 92 insertions(+), 45 deletions(-) (limited to 'sys') diff --git a/sys/arch/sparc/stand/Makefile b/sys/arch/sparc/stand/Makefile index f3e8f5d4d6f..52bc933cea4 100644 --- a/sys/arch/sparc/stand/Makefile +++ b/sys/arch/sparc/stand/Makefile @@ -12,13 +12,13 @@ KERNREL= all: ${KERNLIB} ${SALIB} _SUBDIRUSE libdep: - @echo ${.OBJDIR}/${KERNLIB} ${.OBJDIR}/${SALIB} + @echo ${KERNLIB} ${.OBJDIR}/${SALIB} sadep: @echo ${.OBJDIR}/${SALIB} kernlibdir: - @echo ${.OBJDIR}/${KERNDST} + @echo ${KERNDST} salibdir: @echo ${.OBJDIR}/${SADST} @@ -30,7 +30,7 @@ cleandir: _SUBDIRUSE BINDIR=/usr/mdec afterinstall: - install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ ${.CURDIR}/binstall.sh ${DESTDIR}${BINDIR}/binstall .include diff --git a/sys/arch/sparc/stand/binstall.sh b/sys/arch/sparc/stand/binstall.sh index 875957fcaa8..c05bf24db6b 100644 --- a/sys/arch/sparc/stand/binstall.sh +++ b/sys/arch/sparc/stand/binstall.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: binstall.sh,v 1.4 1996/08/11 09:13:21 downsj Exp $ +# $OpenBSD: binstall.sh,v 1.5 1996/12/12 08:42:44 deraadt Exp $ # $NetBSD: binstall.sh,v 1.3 1996/04/07 20:00:12 thorpej Exp $ # @@ -60,21 +60,13 @@ fi WHAT=$1 DEST=$2 -if [ "`sysctl -n hw.model | cut -b1-5`" = "SUN-4" ]; then - KARCH=sun4 -else - KARCH=sun4c -fi -vecho "Kernel architecture: $KARCH" - if [ ! -d $DEST ]; then echo "$DEST: not a directory" Usage fi -if [ $KARCH = sun4 ]; then SKIP=1; else SKIP=0; fi - +SKIP=0 case $WHAT in "ffs") @@ -100,16 +92,25 @@ case $WHAT in TARGET=$DEST/boot vecho Boot device: $DEV vecho Target: $TARGET - $DOIT dd if=${MDEC}/boot of=$TARGET skip=$SKIP bs=32 + $DOIT dd if=${MDEC}/boot of=$TARGET bs=32 skip=$SKIP sync; sync; sync vecho installboot ${VERBOSE:+-v} $TARGET ${MDEC}/bootxx $DEV $DOIT installboot ${VERBOSE:+-v} $TARGET ${MDEC}/bootxx $DEV ;; "net") - TARGET=$DEST/boot.sparc.openbsd.$KARCH + TARGET=$DEST/boot.sparc.openbsd + TMP=/tmp/boot.$$ vecho Target: $TARGET - $DOIT dd if=${MDEC}/boot of=$TARGET skip=$SKIP bs=32 + vecho Copying to temporary file. + cp ${MDEC}/boot $TMP; chmod +w $TMP + vecho Stripping $TMP + strip $TMP + vecho Creating header magic. + printf '\01\03\01\07\060\200\0\07' | dd of=$TARGET bs=32 conv=sync + vecho Concatenating boot code. + dd if=$TMP of=$TARGET bs=32 skip=1 seek=1 + rm $TMP ;; *) diff --git a/sys/arch/sparc/stand/installboot.8 b/sys/arch/sparc/stand/installboot.8 index c2cfeef3be0..3f5b83cb54e 100644 --- a/sys/arch/sparc/stand/installboot.8 +++ b/sys/arch/sparc/stand/installboot.8 @@ -37,6 +37,7 @@ .Sh SYNOPSIS .Nm installboot .Op Fl nvh +.Op Fl a Ar karch .Ar boot .Ar bootxx .Ar device @@ -69,22 +70,20 @@ The utility .Pa /usr/mdec/binstall can be used to properly copy the a second-stage bootprogram to its destination. This script takes care of post-processing that is required -on non- -.Tn Openboot +on +.Pf non- Tn Openboot machines. .Pp The options are as follows: .Bl -tag -width flag -.It Fl n -Do not actually write anything on the disk. -.It Fl v -Verbose mode. -.It Fl h -Leave the -.Xr a.out 5 -header on the installed -.Ar bootxx -program. +.It Fl a Ar karch +Set the machine architecture. The argument +.Ar karch +can be one of +.Dq sun4 , +.Dq sun4c +or +.Dq sun4m . Sun 4c models with .Tn Openboot PROMs need the header to be present, while Sun 4 systems with the @@ -92,7 +91,20 @@ PROMs need the header to be present, while Sun 4 systems with the interface require the header to be stripped off. This is normally taken care of by .Nm -automatically. +automatically, but it's useful when preparing a bootable filesystem for +another system. +.It Fl h +Leave the +.Xr a.out 5 +header on the installed +.Ar bootxx +program. This option has been superseded by the +.Fl a Ar karch +option. +.It Fl n +Do not actually write anything on the disk. +.It Fl v +Verbose mode. .El .Pp The arguments are: diff --git a/sys/arch/sparc/stand/installboot.c b/sys/arch/sparc/stand/installboot.c index 79dd8964036..643bc96eb4e 100644 --- a/sys/arch/sparc/stand/installboot.c +++ b/sys/arch/sparc/stand/installboot.c @@ -64,6 +64,7 @@ int32_t *block_count_p; /* size of this array */ int32_t *block_size_p; /* filesystem block size */ int32_t max_block_count; +char *karch; char cpumodel[100]; @@ -78,7 +79,7 @@ static void usage() { fprintf(stderr, - "usage: installboot [-n] [-v] [-h] \n"); + "usage: installboot [-n] [-v] [-h] [-a ] \n"); exit(1); } @@ -94,9 +95,12 @@ main(argc, argv) int mib[2]; size_t size; - while ((c = getopt(argc, argv, "vnh")) != EOF) { + while ((c = getopt(argc, argv, "a:vnh")) != EOF) { switch (c) { - case 'h': + case 'a': + karch = optarg; + break; + case 'h': /* Note: for backwards compatibility */ /* Don't strip a.out header */ hflag = 1; break; @@ -121,21 +125,35 @@ main(argc, argv) proto = argv[optind + 1]; dev = argv[optind + 2]; + if (karch == NULL) { + mib[0] = CTL_HW; + mib[1] = HW_MODEL; + size = sizeof(cpumodel); + if (sysctl(mib, 2, cpumodel, &size, NULL, 0) == -1) + err(1, "sysctl"); + + if (size < 5 || strncmp(cpumodel, "SUN-4", 5) != 0) /*XXX*/ + /* Assume a sun4c/sun4m */ + karch = "sun4c"; + else + karch = "sun4"; + } + if (verbose) { printf("boot: %s\n", boot); printf("proto: %s\n", proto); printf("device: %s\n", dev); + printf("architecture: %s\n", karch); } - mib[0] = CTL_HW; - mib[1] = HW_MODEL; - size = sizeof(cpumodel); - if (sysctl(mib, 2, cpumodel, &size, NULL, 0) == -1) - err(1, "sysctl"); - - if (size < 5 || strncmp(cpumodel, "SUN-4", 5) != 0) /*XXX*/ - /* Assume a sun4c/sun4m */ + if (strcmp(karch, "sun4") == 0) { + hflag = 1; + } else if (strcmp(karch, "sun4c") == 0) { hflag = 1; + } else if (strcmp(karch, "sun4m") == 0) { + hflag = 1; + } else + errx(1, "Unsupported architecture"); /* Load proto blocks into core */ if ((protostore = loadprotoblocks(proto, &protosize)) == NULL) @@ -265,6 +283,24 @@ loadprotoblocks(fname, size) max_block_count, nl[X_BLOCKTABLE].n_value); } + /* + * We convert the a.out header in-vitro into something that + * Sun PROMs understand. + * Old-style (sun4) ROMs do not expect a header at all, so + * we turn the first two words into code that gets us past + * the 32-byte header where the actual code begins. In assembly + * speak: + * .word MAGIC ! a NOP + * ba,a start ! + * .skip 24 ! pad + * start: + */ + +#define SUN_MAGIC 0x01030107 +#define SUN4_BASTART 0x30800007 /* i.e.: ba,a `start' */ + *((int *)bp) = SUN_MAGIC; + *((int *)bp + 1) = SUN4_BASTART; + *size = sz; return (hflag ? bp : (bp + sizeof(struct exec))); } diff --git a/sys/arch/sparc/stand/srt0.S b/sys/arch/sparc/stand/srt0.S index e5248292b84..36a04cd33d9 100644 --- a/sys/arch/sparc/stand/srt0.S +++ b/sys/arch/sparc/stand/srt0.S @@ -102,16 +102,14 @@ start: call _bzero sub %o1, %o0, %o1 -#if 0 /* - * Enable interrupts above level 11. This enables "L1-A", but - * avoids spurious interrupt bites from most other devices + * Enable interrupts, but only above level 11. This enables "L1-A", + * but avoids spurious interrupt bites from most other devices. */ rd %psr, %o0 andn %o0, PSR_PIL, %o0 wr %o0, 0xb00, %psr ! (11 << 8) nop; nop; nop -#endif /* * Set CPU type that we are running on. diff --git a/sys/arch/sparc/stand/version.c b/sys/arch/sparc/stand/version.c index 1217ce7aba7..1c8ed9686ec 100644 --- a/sys/arch/sparc/stand/version.c +++ b/sys/arch/sparc/stand/version.c @@ -38,4 +38,4 @@ * 1.4 add oldmon support and network support. */ -char *version = "$Revision: 1.2 $"; +char *version = "$Revision: 1.3 $"; -- cgit v1.2.3