diff options
-rw-r--r-- | sys/arch/wgrisc/conf/ld.script | 2 | ||||
-rw-r--r-- | sys/arch/wgrisc/include/ansi.h | 3 | ||||
-rw-r--r-- | sys/arch/wgrisc/include/asm.h | 4 | ||||
-rw-r--r-- | sys/arch/wgrisc/include/disklabel.h | 52 | ||||
-rw-r--r-- | sys/arch/wgrisc/include/param.h | 4 | ||||
-rw-r--r-- | sys/arch/wgrisc/riscbus/riscbus.h | 4 | ||||
-rw-r--r-- | sys/arch/wgrisc/wgrisc/autoconf.c | 91 | ||||
-rw-r--r-- | sys/arch/wgrisc/wgrisc/disksubr.c | 539 | ||||
-rw-r--r-- | sys/arch/wgrisc/wgrisc/locore.S | 52 | ||||
-rw-r--r-- | sys/arch/wgrisc/wgrisc/machdep.c | 5 |
10 files changed, 489 insertions, 267 deletions
diff --git a/sys/arch/wgrisc/conf/ld.script b/sys/arch/wgrisc/conf/ld.script index 3c59f13f80b..12f80cef7c1 100644 --- a/sys/arch/wgrisc/conf/ld.script +++ b/sys/arch/wgrisc/conf/ld.script @@ -5,7 +5,7 @@ ENTRY(_start) SECTIONS { /* Read-only sections, merged into text segment: */ - . = 0x80100000 + SIZEOF_HEADERS; + . = 0x80040000 + SIZEOF_HEADERS; .text : { _ftext = . ; diff --git a/sys/arch/wgrisc/include/ansi.h b/sys/arch/wgrisc/include/ansi.h index cc607a5d559..3803a631267 100644 --- a/sys/arch/wgrisc/include/ansi.h +++ b/sys/arch/wgrisc/include/ansi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ansi.h,v 1.1 1997/02/06 16:02:44 pefo Exp $ */ +/* $OpenBSD: ansi.h,v 1.2 1997/05/11 16:25:59 pefo Exp $ */ /* $NetBSD: ansi.h,v 1.5 1994/10/26 21:09:33 cgd Exp $ */ /*- @@ -54,6 +54,7 @@ #define _BSD_SSIZE_T_ int /* byte count or error */ #define _BSD_TIME_T_ long /* time() */ #define _BSD_VA_LIST_ char * /* va_list */ +#define _BSD_CLOCKID_T_ int /* * Runes (wchar_t) is declared to be an ``int'' instead of the more natural diff --git a/sys/arch/wgrisc/include/asm.h b/sys/arch/wgrisc/include/asm.h index 06df98758c2..e5c8f892109 100644 --- a/sys/arch/wgrisc/include/asm.h +++ b/sys/arch/wgrisc/include/asm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asm.h,v 1.1 1997/02/06 16:02:44 pefo Exp $ */ +/* $OpenBSD: asm.h,v 1.2 1997/05/11 16:26:00 pefo Exp $ */ /* * Copyright (c) 1992, 1993 @@ -49,7 +49,9 @@ #include <machine/regdef.h> +#ifndef ABICALLS #define ABICALLS .abicalls +#endif #if defined(ABICALLS) && !defined(_KERNEL) ABICALLS diff --git a/sys/arch/wgrisc/include/disklabel.h b/sys/arch/wgrisc/include/disklabel.h index 41df7318418..8c71a8c20d5 100644 --- a/sys/arch/wgrisc/include/disklabel.h +++ b/sys/arch/wgrisc/include/disklabel.h @@ -1,5 +1,5 @@ -/* $OpenBSD: disklabel.h,v 1.1 1997/02/06 16:02:42 pefo Exp $ */ -/* $NetBSD: disklabel.h,v 1.2 1995/01/18 06:37:55 mellon Exp $ */ +/* $OpenBSD: disklabel.h,v 1.2 1997/05/11 16:26:01 pefo Exp $ */ +/* $NetBSD: disklabel.h,v 1.3 1996/03/09 20:52:54 ghudson Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -34,41 +34,41 @@ #ifndef _MACHINE_DISKLABEL_H_ #define _MACHINE_DISKLABEL_H_ -#define LABELSECTOR 1 /* sector containing label */ -#define LABELOFFSET 0 /* offset of label in sector */ -#define MAXPARTITIONS 16 /* number of partitions */ -#define PARTITIONSHIFT 4 /* log2 */ -#define PARTITIONMASK 0xf -#define RAW_PART 2 /* raw partition: xx?c */ +#define LABELSECTOR 1 /* sector containing label */ +#define LABELOFFSET 0 /* offset of label in sector */ +#define MAXPARTITIONS 16 /* number of partitions */ +#define RAW_PART 2 /* raw partition: ie. rsd0c */ -/* DOS partition table -- used when the system is booted from a dos - * partition. This is the case on NT systems. - */ +/* DOS partition table -- located in boot block */ #define DOSBBSECTOR 0 /* DOS boot block relative sector # */ #define DOSPARTOFF 446 #define NDOSPART 4 struct dos_partition { - unsigned char dp_flag; /* bootstrap flags */ - unsigned char dp_shd; /* starting head */ - unsigned char dp_ssect; /* starting sector */ - unsigned char dp_scyl; /* starting cylinder */ - unsigned char dp_typ; /* partition type (see below) */ - unsigned char dp_ehd; /* end head */ - unsigned char dp_esect; /* end sector */ - unsigned char dp_ecyl; /* end cylinder */ - unsigned long dp_start; /* absolute starting sector number */ - unsigned long dp_size; /* partition size in sectors */ -} dos_partitions[NDOSPART]; + u_int8_t dp_flag; /* bootstrap flags */ + u_int8_t dp_shd; /* starting head */ + u_int8_t dp_ssect; /* starting sector */ + u_int8_t dp_scyl; /* starting cylinder */ + u_int8_t dp_typ; /* partition type (see below) */ + u_int8_t dp_ehd; /* end head */ + u_int8_t dp_esect; /* end sector */ + u_int8_t dp_ecyl; /* end cylinder */ + u_int32_t dp_start; /* absolute starting sector number */ + u_int32_t dp_size; /* partition size in sectors */ +}; /* Known DOS partition types. */ +#define DOSPTYP_UNUSED 0x00 /* Unused partition */ +#define DOSPTYP_FAT12 0x01 /* 12-bit FAT */ +#define DOSPTYP_FAT16S 0x04 /* 16-bit FAT, less than 32M */ +#define DOSPTYP_EXTEND 0x05 /* Extended; contains sub-partitions */ +#define DOSPTYP_FAT16B 0x06 /* 16-bit FAT, more than 32M */ +#define DOSPTYP_FAT16C 0x0e /* 16-bit FAT, CHS-mapped */ +#define DOSPTYP_ONTRACK 0x54 +#define DOSPTYP_LINUX 0x83 /* That other thing */ #define DOSPTYP_386BSD 0xa5 /* 386BSD partition type */ #define DOSPTYP_NETBSD DOSPTYP_386BSD /* NetBSD partition type (XXX) */ #define DOSPTYP_OPENBSD 0xa6 /* OpenBSD partition type */ -#define DOSPTYP_FAT12 0x1 -#define DOSPTYP_FAT16S 0x4 -#define DOSPTYP_FAT16B 0x6 -#define DOSPTYP_FAT16C 0xe #include <sys/dkbad.h> struct cpu_disklabel { diff --git a/sys/arch/wgrisc/include/param.h b/sys/arch/wgrisc/include/param.h index a53fcbc6a9c..f788a31ad68 100644 --- a/sys/arch/wgrisc/include/param.h +++ b/sys/arch/wgrisc/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.3 1997/02/28 22:57:41 niklas Exp $ */ +/* $OpenBSD: param.h,v 1.4 1997/05/11 16:26:02 pefo Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -45,7 +45,7 @@ * Machine dependent constants for Willowglen Mips RISC machines: */ #define MACHINE "wgrisc" -#define MACHINE wgrisc +#define _MACHINE wgrisc #define MACHINE_ARCH "mips" #define _MACHINE_ARCH mips #define MID_MACHINE MID_PMAX /* XXX Bogus, but needed for now... */ diff --git a/sys/arch/wgrisc/riscbus/riscbus.h b/sys/arch/wgrisc/riscbus/riscbus.h index 3fb52adc839..5b8bb362c97 100644 --- a/sys/arch/wgrisc/riscbus/riscbus.h +++ b/sys/arch/wgrisc/riscbus/riscbus.h @@ -1,4 +1,4 @@ -/* $OpenBSD: riscbus.h,v 1.1 1997/02/06 16:02:44 pefo Exp $ */ +/* $OpenBSD: riscbus.h,v 1.2 1997/05/11 16:26:03 pefo Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom @@ -104,6 +104,7 @@ #define R3715_DMA_INT0 0x00000020 #define R3715_DMA_INT1 0x00000040 +#ifndef _LOCORE /* * Interrupt vector descriptor for device on risc bus. */ @@ -115,4 +116,5 @@ struct riscbus_int_desc { }; int riscbus_intrnull __P((void *)); +#endif /* _LOCORE */ #endif /* RISCBUS_H */ diff --git a/sys/arch/wgrisc/wgrisc/autoconf.c b/sys/arch/wgrisc/wgrisc/autoconf.c index 2cbc766d88f..b246fbe2fab 100644 --- a/sys/arch/wgrisc/wgrisc/autoconf.c +++ b/sys/arch/wgrisc/wgrisc/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.2 1997/02/23 21:59:32 pefo Exp $ */ +/* $OpenBSD: autoconf.c,v 1.3 1997/05/11 16:26:04 pefo Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom * Copyright (c) 1995 Theo de Raadt @@ -41,7 +41,7 @@ * from: Utah Hdr: autoconf.c 1.31 91/01/21 * * from: @(#)autoconf.c 8.1 (Berkeley) 6/10/93 - * $Id: autoconf.c,v 1.2 1997/02/23 21:59:32 pefo Exp $ + * $Id: autoconf.c,v 1.3 1997/05/11 16:26:04 pefo Exp $ */ /* @@ -64,6 +64,14 @@ struct device *parsedisk __P((char *, int, int, dev_t *)); void setroot __P((void)); +void configure __P((void)); +void swapconf __P((void)); +extern void dumpconf __P((void)); +static int findblkmajor __P((struct device *)); +static struct device * getdisk __P((char *, int, int, dev_t *)); +struct device * getdevunit __P((char *, int)); +void makebootdev __P((char *cp)); +int getpno __P((char **)); /* * The following several variables are related to @@ -79,9 +87,10 @@ struct device *bootdv = NULL; * Configure all devices found that we know about. * This is done at boot time. */ +void configure() { - (void)splhigh(); /* To be really shure.. */ + (void)splhigh(); /* To be really sure.. */ if(config_rootfound("mainbus", "mainbus") == 0) panic("no mainbus found"); (void)spl0(); @@ -94,6 +103,7 @@ configure() /* * Configure swap space and related parameters. */ +void swapconf() { register struct swdevt *swp; @@ -122,8 +132,8 @@ static struct nam2blk { int maj; } nam2blk[] = { { "sd", 0 }, /* 0 = sd */ - { "fd", 7 }, /* 7 = floppy (ick!)*/ - { "flash", 10 } /* 10 = Flash memory disk */ + { "fd", 7 }, /* 7 = floppy (probably never...)*/ + { "flash", 10 } /* 10 = Flash memory disk */ }; static int @@ -171,13 +181,13 @@ parsedisk(str, len, defpart, devp) { register struct device *dv; register char *cp, c; - int majdev, mindev, part; + int majdev, part; if (len == 0) return (NULL); cp = str + len - 1; c = *cp; - if (c >= 'a' && c <= 'h') { + if (c >= 'a' && (c - 'a') < MAXPARTITIONS) { part = c - 'a'; *cp = '\0'; } else @@ -189,8 +199,7 @@ parsedisk(str, len, defpart, devp) majdev = findblkmajor(dv); if (majdev < 0) panic("parsedisk"); - mindev = (dv->dv_unit << PARTITIONSHIFT) + part; - *devp = makedev(majdev, mindev); + *devp = MAKEDISKDEV(majdev, dv->dv_unit, part); break; } #ifdef NFSCLIENT @@ -224,9 +233,6 @@ setroot() #if defined(NFSCLIENT) extern char *nfsbootdevname; #endif -#if defined(FFS) - extern int ffs_mountroot __P((void)); -#endif /* Lookup boot device from boot if not set by configuration */ if(bootdv == NULL) { @@ -242,7 +248,7 @@ setroot() if (boothowto & RB_ASKNAME) { for (;;) { - printf("root device "); + printf("root device "); if (bootdv != NULL) printf("(default %s%c)", bootdv->dv_xname, @@ -290,9 +296,8 @@ setroot() nswapdev = NODEV; break; case DV_DISK: - nswapdev = makedev(major(nrootdev), - (minor(nrootdev) & ~ PARTITIONMASK) -| 1); + nswapdev = MAKEDISKDEV(major(nrootdev), + DISKUNIT(nrootdev), 1); break; case DV_TAPE: case DV_TTY: @@ -359,15 +364,14 @@ gotswap: nfsbootdevname = bootdv->dv_xname; return; #endif -#if defined(FFS) case DV_DISK: - mountroot = ffs_mountroot; + mountroot = dk_mountroot; majdev = major(rootdev); mindev = minor(rootdev); - printf("root on %s%c\n", bootdv->dv_xname, - (mindev & PARTITIONMASK) + 'a'); + unit = DISKUNIT(rootdev); + part = DISKPART(rootdev); + printf("root on %s%c\n", bootdv->dv_xname, part + 'a'); break; -#endif default: printf("can't figure root, hope your kernel is right\n"); return; @@ -376,11 +380,10 @@ gotswap: /* * XXX: What is this doing? */ - mindev &= ~PARTITIONMASK; temp = NODEV; for (swp = swdevt; swp->sw_dev != NODEV; swp++) { if (majdev == major(swp->sw_dev) && - mindev == (minor(swp->sw_dev) & ~PARTITIONMASK)) { + unit == DISKUNIT(swp->sw_dev)) { temp = swdevt[0].sw_dev; swdevt[0].sw_dev = swp->sw_dev; swp->sw_dev = temp; @@ -426,24 +429,36 @@ getdevunit(name, unit) return dev; } +struct devmap { + char *attachment; + char *dev; +}; + /* * Look at the string 'cp' and decode the boot device. - * Boot names look like: scsi()disk(n)rdisk()partition(1)\bsd - * (beware for empty scsi id's...) + * Boot names look like: sd(0,0,0)/bsd */ void makebootdev(cp) char *cp; { - int unit, part, ctrl; - - bootdev[0] = *cp; - ctrl = getpno(&cp); - if(*cp++ == ')') { - bootdev[1] = *cp; - unit = getpno(&cp); + int unit = 0, part = 0, ctrl = 0; + + bootdev[0] = *cp++; + bootdev[1] = *cp++; + if(*cp == '(') { + ctrl = getpno(&cp); + if(*cp == ',') { + unit = getpno(&cp); + if(*cp == ',') { + part = getpno(&cp); + } + } + sprintf(&bootdev[2], "%d%c", ctrl*16 + unit, part + 'a'); + } + else { + sprintf(bootdev, "unknown"); } - sprintf(&bootdev[2], "%d", ctrl*16 + unit); } getpno(cp) char **cp; @@ -451,14 +466,10 @@ getpno(cp) int val = 0; char *cx = *cp; - while(*cx && *cx != '(') - cx++; - if(*cx == '(') { + cx++; + while(*cx && *cx != ')' && *cx != ',') { + val = val * 10 + *cx - '0'; cx++; - while(*cx && *cx != ')') { - val = val * 10 + *cx - '0'; - cx++; - } } *cp = cx; return val; diff --git a/sys/arch/wgrisc/wgrisc/disksubr.c b/sys/arch/wgrisc/wgrisc/disksubr.c index ed0cccd5704..75529824914 100644 --- a/sys/arch/wgrisc/wgrisc/disksubr.c +++ b/sys/arch/wgrisc/wgrisc/disksubr.c @@ -1,51 +1,55 @@ -/* $OpenBSD: disksubr.c,v 1.2 1997/04/07 12:04:02 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.3 1997/05/11 16:26:05 pefo Exp $ */ +/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* - * Copyright (c) 1994, 1995 Carnegie-Mellon University. + * Copyright (c) 1996 Theo de Raadt + * Copyright (c) 1982, 1986, 1988 Regents of the University of California. * All rights reserved. * - * Authors: Keith Bostic, Chris G. Demetriou, Per Fogelstrom (R4000) - * - * 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 + * 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. * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 + * 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. * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. + * @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91 */ #include <sys/param.h> +#include <sys/systm.h> #include <sys/buf.h> -#include <sys/ioccom.h> #include <sys/device.h> #include <sys/disklabel.h> +#include <sys/syslog.h> #include <sys/disk.h> -#include <scsi/scsi_all.h> -#include <scsi/scsiconf.h> +#define b_cylin b_resid -#include <machine/cpu.h> -#include <machine/autoconf.h> +#define BOOT_MAGIC 0xAA55 +#define BOOT_MAGIC_OFF (DOSPARTOFF+NDOSPART*sizeof(struct dos_partition)) -extern struct device *bootdv; - -int fat_types[] = { DOSPTYP_FAT12, DOSPTYP_FAT16S, - DOSPTYP_FAT16B, DOSPTYP_FAT16C, -1 }; - -/* was this the boot device ? */ void dk_establish(dk, dev) struct disk *dk; @@ -54,146 +58,285 @@ dk_establish(dk, dev) } /* - * Attempt to read a disk label from a device * using the indicated stategy routine. + * Attempt to read a disk label from a device + * using the indicated stategy routine. * The label must be partly set up before this: - * secpercyl and anything required in the strategy routine - * (e.g., sector size) must be filled in before calling us. + * secpercyl, secsize and anything required for a block i/o read + * operation in the driver's strategy/start routines + * must be filled in before calling us. + * + * If dos partition table requested, attempt to load it and + * find disklabel inside a DOS partition. Also, if bad block + * table needed, attempt to extract it as well. Return buffer + * for use in signalling errors if requested. + * * Returns null on success and an error string on failure. */ char * -readdisklabel(dev, strat, lp, clp) +readdisklabel(dev, strat, lp, osdep) dev_t dev; - void (*strat)(); - struct disklabel *lp; - struct cpu_disklabel *clp; + void (*strat) __P((struct buf *)); + register struct disklabel *lp; + struct cpu_disklabel *osdep; { + struct dos_partition *dp = osdep->dosparts, *dp2; + struct dkbad *bdp = &osdep->bad; struct buf *bp; struct disklabel *dlp; - struct dos_partition *dp = clp->dosparts; - char *msg = NULL; - int dospart, dospartoff, i, *ip; + char *msg = NULL, *cp; + int dospartoff, cyl, i, ourpart = -1; /* minimal requirements for archtypal disk label */ + if (lp->d_secsize == 0) + lp->d_secsize = DEV_BSIZE; if (lp->d_secperunit == 0) - lp->d_secperunit = 0x1fffffff; + lp->d_secperunit = 0x1fffffff; lp->d_npartitions = RAW_PART + 1; - for(i = 0; i < RAW_PART; i++) { + for (i = 0; i < RAW_PART; i++) { lp->d_partitions[i].p_size = 0; lp->d_partitions[i].p_offset = 0; } - if (lp->d_partitions[RAW_PART].p_size == 0) - lp->d_partitions[RAW_PART].p_size = 0x1fffffff; - lp->d_partitions[RAW_PART].p_offset = 0; + if (lp->d_partitions[i].p_size == 0) + lp->d_partitions[i].p_size = 0x1fffffff; + lp->d_partitions[i].p_offset = 0; - /* obtain buffer to probe drive with */ + /* get a buffer and initialize it */ bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; - dospartoff = 0; - dospart = -1; /* do dos partitions in the process of getting disklabel? */ + dospartoff = 0; + cyl = LABELSECTOR / lp->d_secpercyl; if (dp) { - /* read master boot record */ - bp->b_blkno = DOSBBSECTOR; - bp->b_bcount = lp->d_secsize; - bp->b_flags = B_BUSY | B_READ; - bp->b_resid = 0; - (*strat)(bp); + daddr_t part_blkno = DOSBBSECTOR; + unsigned long extoff = 0; + int wander = 1; + int n = 0; + int loop = 0; - /* if successful, wander through dos partition table */ - if (biowait(bp)) { - msg = "dos partition I/O error"; - goto done; - } - if (*(unsigned int *)(bp->b_data) == 0x8efac033) { - /* XXX how do we check veracity/bounds of this? */ + /* + * Read dos partition table, follow extended partitions. + * Map the partitions to disklabel entries i-p + */ + while (wander && n < 8 && loop < 8) { + loop++; + + /* on finding a extended partition wander further */ + wander = 0; + + /* read boot record */ + bp->b_blkno = part_blkno; + bp->b_bcount = lp->d_secsize; + bp->b_flags = B_BUSY | B_READ; + bp->b_cylin = part_blkno / lp->d_secpercyl; + (*strat)(bp); + + /* if successful, wander through dos partition table */ + if (biowait(bp)) { + msg = "dos partition I/O error"; + goto done; + } + + /* + * We would like to check if each MBR has a valid + * BOOT_MAGIC, but we cannot because it doesn't + * always exist. So.. we assume the MBR is valid. + */ + bcopy(bp->b_data + DOSPARTOFF, dp, NDOSPART * sizeof(*dp)); - for (i = 0, dp = clp->dosparts; i < NDOSPART; i++, dp++) { - if (dp->dp_size && dp->dp_typ == DOSPTYP_OPENBSD - && dospart < 0) - dospart = i; - } - for (i = 0, dp = clp->dosparts; i < NDOSPART; i++, dp++) { - if (dp->dp_size && dp->dp_typ == DOSPTYP_386BSD - && dospart < 0) - dospart = i; + /* + * Search for our MBR partition + */ + if (ourpart == -1) { + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; + i++, dp2++) + if (dp2->dp_size && + dp2->dp_typ == DOSPTYP_OPENBSD) + ourpart = i; + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; + i++, dp2++) + if (dp2->dp_size && + dp2->dp_typ == DOSPTYP_386BSD) + ourpart = i; } - if(dospart >= 0) { + + if (ourpart != -1) { + dp2 = &dp[ourpart]; + /* - * set part a to show OpenBSD part + * This is our MBR partition. need sector address + * for SCSI/IDE, cylinder for ESDI/ST506/RLL */ - dp = clp->dosparts+dospart; - dospartoff = dp->dp_start; - - lp->d_partitions[0].p_size = dp->dp_size; - lp->d_partitions[0].p_offset = dp->dp_start; - lp->d_partitions[RAW_PART].p_size = dp->dp_size; - lp->d_partitions[RAW_PART].p_offset = dp->dp_start; - lp->d_ntracks = dp->dp_ehd + 1; - lp->d_nsectors = DPSECT(dp->dp_esect); - lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; + dospartoff = dp2->dp_start + part_blkno; + cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect); + + /* XXX build a temporary disklabel */ + lp->d_partitions[0].p_size = dp2->dp_size; + lp->d_partitions[0].p_offset = dp2->dp_start + + part_blkno; + if (lp->d_ntracks == 0) + lp->d_ntracks = dp2->dp_ehd + 1; + if (lp->d_nsectors == 0) + lp->d_nsectors = DPSECT(dp2->dp_esect); + if (lp->d_secpercyl == 0) + lp->d_secpercyl = lp->d_ntracks * + lp->d_nsectors; } + /* - * In case the disklabel read below fails, we want to provide - * a fake label in which m/n/o/p are MBR partitions 0/1/2/3 + * In case the disklabel read below fails, we want to + * provide a fake label in which m/n/o/p are MBR + * partitions 0/1/2/3 */ - for (i=0, dp = clp->dosparts; i < NDOSPART; i++, dp++) { - lp->d_partitions[MAXPARTITIONS - NDOSPART + i].p_size = dp->dp_size; - lp->d_partitions[MAXPARTITIONS - NDOSPART + i].p_offset = dp->dp_start; - for (ip = fat_types; *ip != -1; ip++) { - if (dp->dp_typ != *ip) - continue; - lp->d_partitions[MAXPARTITIONS - NDOSPART +i].p_fstype = FS_MSDOS; + for (dp2=dp, i=0; i < NDOSPART && !wander; i++, dp2++) { + struct partition *pp = &lp->d_partitions[8+n]; + +/* if (dp2->dp_start + dp2->dp_size > + lp->d_ncylinders * lp->d_secpercyl) + continue; +*/ + + if (dp2->dp_size) + pp->p_size = dp2->dp_size; + if (dp2->dp_start) + pp->p_offset = + dp2->dp_start + part_blkno; + + switch (dp2->dp_typ) { + case DOSPTYP_UNUSED: + for (cp = (char *)dp2; + cp < (char *)(dp2 + 1); cp++) + if (*cp) + break; + /* + * Was it all zeroes? If so, it is + * an unused entry that we don't + * want to show. + */ + if (cp == (char *)(dp2 + 1)) + continue; + lp->d_partitions[8 + n++].p_fstype = + FS_UNUSED; + break; + + case DOSPTYP_LINUX: + pp->p_fstype = FS_EXT2FS; + n++; + break; + + case DOSPTYP_FAT12: + case DOSPTYP_FAT16S: + case DOSPTYP_FAT16B: + case DOSPTYP_FAT16C: + pp->p_fstype = FS_MSDOS; + n++; + break; + case DOSPTYP_EXTEND: + part_blkno = dp2->dp_start + extoff; + if (!extoff) + extoff = dp2->dp_start; + wander = 1; + break; + default: + pp->p_fstype = FS_OTHER; + n++; + break; } } - lp->d_bbsize = 8192; - lp->d_sbsize = 64*1024; /* XXX ? */ - lp->d_npartitions = MAXPARTITIONS; } - + lp->d_bbsize = 8192; + lp->d_sbsize = 64*1024; /* XXX ? */ + lp->d_npartitions = MAXPARTITIONS; } + /* next, dig out disk label */ bp->b_blkno = dospartoff + LABELSECTOR; - bp->b_resid = 0; + bp->b_cylin = cyl; bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ; - (*strat)(bp); + (*strat)(bp); /* if successful, locate disk label within block and validate */ if (biowait(bp)) { - msg = "disk label read error"; + /* XXX we return the faked label built so far */ + msg = "disk label I/O error"; goto done; } - - dlp = (struct disklabel *)(bp->b_un.b_addr + LABELOFFSET); - if (dlp->d_magic == DISKMAGIC) { - if (dkcksum(dlp)) { - msg = "OpenBSD disk label corrupted"; - goto done; + for (dlp = (struct disklabel *)bp->b_data; + dlp <= (struct disklabel *)(bp->b_data + lp->d_secsize - sizeof(*dlp)); + dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { + if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { + if (msg == NULL) + msg = "no disk label"; + } else if (dlp->d_npartitions > MAXPARTITIONS || + dkcksum(dlp) != 0) + msg = "disk label corrupted"; + else { + *lp = *dlp; + msg = NULL; + break; } - *lp = *dlp; - goto done; } + + if (msg) { #if defined(CD9660) - if (iso_disklabelspoof(dev, strat, lp) == 0) - goto done; + if (iso_disklabelspoof(dev, strat, lp) == 0) + msg = NULL; #endif - msg = "no disk label"; + goto done; + } + + /* obtain bad sector table if requested and present */ + if (bdp && (lp->d_flags & D_BADSECT)) { + struct dkbad *db; + + i = 0; + do { + /* read a bad sector table */ + bp->b_flags = B_BUSY | B_READ; + bp->b_blkno = lp->d_secperunit - lp->d_nsectors + i; + if (lp->d_secsize > DEV_BSIZE) + bp->b_blkno *= lp->d_secsize / DEV_BSIZE; + else + bp->b_blkno /= DEV_BSIZE / lp->d_secsize; + bp->b_bcount = lp->d_secsize; + bp->b_cylin = lp->d_ncylinders - 1; + (*strat)(bp); + + /* if successful, validate, otherwise try another */ + if (biowait(bp)) { + msg = "bad sector table I/O error"; + } else { + db = (struct dkbad *)(bp->b_data); +#define DKBAD_MAGIC 0x4321 + if (db->bt_mbz == 0 + && db->bt_flag == DKBAD_MAGIC) { + msg = NULL; + *bdp = *db; + break; + } else + msg = "bad sector table corrupted"; + } + } while ((bp->b_flags & B_ERROR) && (i += 2) < 10 && + i < lp->d_nsectors); + } + done: - bp->b_flags = B_INVAL | B_AGE | B_READ; + bp->b_flags |= B_INVAL; brelse(bp); return (msg); } /* - * Check new disk label for sensibility before setting it. + * Check new disk label for sensibility + * before setting it. */ int -setdisklabel(olp, nlp, openmask, clp) +setdisklabel(olp, nlp, openmask, osdep) register struct disklabel *olp, *nlp; u_long openmask; - struct cpu_disklabel *clp; + struct cpu_disklabel *osdep; { register i; register struct partition *opp, *npp; @@ -203,12 +346,20 @@ setdisklabel(olp, nlp, openmask, clp) (nlp->d_secsize % DEV_BSIZE) != 0) return(EINVAL); + /* special case to allow disklabel to be invalidated */ + if (nlp->d_magic == 0xffffffff) { + *olp = *nlp; + return (0); + } + if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC || - dkcksum(nlp) != 0) + dkcksum(nlp) != 0) return (EINVAL); - while ((i = ffs((long)openmask)) != 0) { - i--; + /* XXX missing check if other dos partitions will be overwritten */ + + while (openmask != 0) { + i = ffs(openmask) - 1; openmask &= ~(1 << i); if (nlp->d_npartitions <= i) return (EBUSY); @@ -217,9 +368,9 @@ setdisklabel(olp, nlp, openmask, clp) if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size) return (EBUSY); /* - * Copy internally-set partition information - * if new label doesn't include it. XXX - */ + * Copy internally-set partition information + * if new label doesn't include it. XXX + */ if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) { npp->p_fstype = opp->p_fstype; npp->p_fsize = opp->p_fsize; @@ -227,88 +378,101 @@ setdisklabel(olp, nlp, openmask, clp) npp->p_cpg = opp->p_cpg; } } - nlp->d_checksum = 0; - nlp->d_checksum = dkcksum(nlp); + nlp->d_checksum = 0; + nlp->d_checksum = dkcksum(nlp); *olp = *nlp; - return (0); + return (0); } + /* * Write disk label back to device after modification. - * this means write out the Rigid disk blocks to represent the - * label. Hope the user was carefull. */ int -writedisklabel(dev, strat, lp, clp) +writedisklabel(dev, strat, lp, osdep) dev_t dev; - void (*strat)(); + void (*strat) __P((struct buf *)); register struct disklabel *lp; - struct cpu_disklabel *clp; + struct cpu_disklabel *osdep; { - struct buf *bp; + struct dos_partition *dp = osdep->dosparts, *dp2; + struct buf *bp; struct disklabel *dlp; - struct dos_partition *dp = clp->dosparts; - int error = 0, i; - int dospart, dospartoff; + int error, dospartoff, cyl, i; + int ourpart = -1; + /* get a buffer and initialize it */ bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; - dospart = -1; - dospartoff = 0; /* do dos partitions in the process of getting disklabel? */ + dospartoff = 0; + cyl = LABELSECTOR / lp->d_secpercyl; if (dp) { /* read master boot record */ bp->b_blkno = DOSBBSECTOR; bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ; - bp->b_resid = 0; + bp->b_cylin = DOSBBSECTOR / lp->d_secpercyl; (*strat)(bp); - if (((error = biowait(bp)) == 0) - && *(unsigned int *)(bp->b_data) == 0x8efac033) { - /* XXX how do we check veracity/bounds of this? */ - bcopy(bp->b_data + DOSPARTOFF, dp, NDOSPART * sizeof(*dp)); + if ((error = biowait(bp)) != 0) + goto done; - for (i = 0, dp = clp->dosparts; i < NDOSPART; i++, dp++) { - if (dp->dp_size && dp->dp_typ == DOSPTYP_OPENBSD - && dospart < 0) { - dospart = i; - dospartoff = dp->dp_start; - } - } - for (i = 0, dp = clp->dosparts; i < NDOSPART; i++, dp++) { - if (dp->dp_size && dp->dp_typ == DOSPTYP_386BSD - && dospart < 0) { - dospart = i; - dospartoff = dp->dp_start; - } - } + /* XXX how do we check veracity/bounds of this? */ + bcopy(bp->b_data + DOSPARTOFF, dp, + NDOSPART * sizeof(*dp)); + + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) + if (dp2->dp_size && dp2->dp_typ == DOSPTYP_OPENBSD) + ourpart = i; + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) + if (dp2->dp_size && dp2->dp_typ == DOSPTYP_386BSD) + ourpart = i; + + if (ourpart != -1) { + dp2 = &dp[ourpart]; + + /* + * need sector address for SCSI/IDE, + * cylinder for ESDI/ST506/RLL + */ + dospartoff = dp2->dp_start; + cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect); } - } + + /* next, dig out disk label */ bp->b_blkno = dospartoff + LABELSECTOR; - bp->b_resid = 0; + bp->b_cylin = cyl; bp->b_bcount = lp->d_secsize; - bp->b_flags = B_READ; /* get current label */ + bp->b_flags = B_BUSY | B_READ; (*strat)(bp); - if (error = biowait(bp)) - goto done; - - dlp = (struct disklabel *)(bp->b_un.b_addr + LABELOFFSET); - *dlp = *lp; /* struct assignment */ - bp->b_flags = B_WRITE; - (*strat)(bp); - error = biowait(bp); + /* if successful, locate disk label within block and validate */ + if ((error = biowait(bp)) != 0) + goto done; + for (dlp = (struct disklabel *)bp->b_data; + dlp <= (struct disklabel *)(bp->b_data + lp->d_secsize - sizeof(*dlp)); + dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { + if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC && + dkcksum(dlp) == 0) { + *dlp = *lp; + bp->b_flags = B_BUSY | B_WRITE; + (*strat)(bp); + error = biowait(bp); + goto done; + } + } + error = ESRCH; done: + bp->b_flags |= B_INVAL; brelse(bp); - return (error); + return (error); } - -/* +/* * Determine the size of the transfer, and make sure it is * within the boundaries of the partition. Adjust transfer * if needed, and signal errors or early completion. @@ -321,40 +485,43 @@ bounds_check_with_label(bp, lp, wlabel) { #define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); - int labelsect = blockpersec(lp->d_partitions[RAW_PART].p_offset, lp) + + int labelsector = blockpersec(lp->d_partitions[RAW_PART].p_offset, lp) + LABELSECTOR; int sz = howmany(bp->b_bcount, DEV_BSIZE); - /* overwriting disk label ? */ - /* XXX should also protect bootstrap in first 8K */ - if (bp->b_blkno + blockpersec(p->p_offset, lp) <= labelsect && - (bp->b_flags & B_READ) == 0 && wlabel == 0) { - bp->b_error = EROFS; - goto bad; - } - - /* beyond partition? */ if (bp->b_blkno + sz > blockpersec(p->p_size, lp)) { sz = blockpersec(p->p_size, lp) - bp->b_blkno; if (sz == 0) { - /* if exactly at end of disk, return an EOF */ + /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - return(0); + goto done; } - sz = maxsz - bp->b_blkno; if (sz < 0) { + /* If past end of disk, return EINVAL. */ bp->b_error = EINVAL; goto bad; } - /* or truncate if part of it fits */ + /* Otherwise, truncate request. */ bp->b_bcount = sz << DEV_BSHIFT; - } + } + + /* Overwriting disk label? */ + if (bp->b_blkno + blockpersec(p->p_offset, lp) <= labelsector && +#if LABELSECTOR != 0 + bp->b_blkno + blockpersec(p->p_offset, lp) + sz > labelsector && +#endif + (bp->b_flags & B_READ) == 0 && !wlabel) { + bp->b_error = EROFS; + goto bad; + } /* calculate cylinder for disksort to order transfers with */ - bp->b_resid = (bp->b_blkno + blockpersec(p->p_offset, lp)) / + bp->b_cylin = (bp->b_blkno + blockpersec(p->p_offset, lp)) / lp->d_secpercyl; - return(1); + return (1); + bad: bp->b_flags |= B_ERROR; - return(-1); +done: + return (0); } diff --git a/sys/arch/wgrisc/wgrisc/locore.S b/sys/arch/wgrisc/wgrisc/locore.S index c4e33c9ebea..92c92c09c37 100644 --- a/sys/arch/wgrisc/wgrisc/locore.S +++ b/sys/arch/wgrisc/wgrisc/locore.S @@ -1,5 +1,5 @@ -/* $OpenBSD: locore.S,v 1.1 1997/02/06 16:02:45 pefo Exp $ */ +/* $OpenBSD: locore.S,v 1.2 1997/05/11 16:26:07 pefo Exp $ */ /* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -51,7 +51,7 @@ * v 1.1 89/07/10 14:27:41 nelson Exp SPRITE (DECWRL) * * from: @(#)locore.s 8.5 (Berkeley) 1/4/94 - * $Id: locore.S,v 1.1 1997/02/06 16:02:45 pefo Exp $ + * $Id: locore.S,v 1.2 1997/05/11 16:26:07 pefo Exp $ */ /* @@ -68,6 +68,7 @@ #include <machine/cpu.h> #include <machine/regnum.h> #include <machine/pte.h> +#include <wgrisc/riscbus/riscbus.h> #include "assym.h" @@ -78,6 +79,9 @@ */ #define START_FRAME ((4 * 4) + 4 + 4) + .globl _C_LABEL(kernel_start) + _C_LABEL(kernel_start) = start + .globl start start: mtc0 zero, COP_0_STATUS_REG # Disable interrupts @@ -719,12 +723,32 @@ LEAF(idle) mtc0 t0, COP_0_STATUS_REG # enable all interrupts sw zero, curproc # set curproc NULL for stats 1: +#ifdef ROTATING_LED + lbu t4, led_sw + nop + or t4, 0x40 + sb t4, RISC_LEDS +#endif + mfc0 v1, COP_0_PRID lw t0, whichqs # look for non-empty queue + li v1, 0xff00 + bne t0, zero, sw1 + and v0, v1 + li v1, (MIPS_R3000 << 8) + bne v1, v0, 1b +#if 0 + mfc0 v1, COP_0_CFG +#else nop - beq t0, zero, 1b +#endif + li v0, 0x02000000 # XXX assume halt for now. + or v1, v0, v1 + b 1b +#if 0 + mtc0 v1, COP_0_CFG +#else nop - b sw1 - mtc0 zero, COP_0_STATUS_REG # Disable all interrupts +#endif END(idle) /* @@ -753,16 +777,30 @@ NON_LEAF(cpu_switch, STAND_FRAME_SIZE, ra) addu t2, t2, 1 sw t2, cnt+V_SWTCH beq t1, zero, idle # if none, idle - mtc0 zero, COP_0_STATUS_REG # Disable all interrupts sw1: + mtc0 zero, COP_0_STATUS_REG # Disable all interrupts +#ifdef ROTATING_LED + lbu t4, led_sw nop # wait for intrs disabled + srl t5, t4, 5 # instructions below is part + sll t4, t4, 1 # if the delay! + or t4, t5 + and t4, 0x3f + sb t4, led_sw + sb t4, RISC_LEDS +#else + nop nop nop nop + nop +#endif + lw t0, whichqs # look for non-empty queue li t2, -1 # t2 = lowest bit set beq t0, zero, idle # if none, idle move t3, t0 # t3 = saved whichqs + 1: addu t2, t2, 1 and t1, t0, 1 # bit set? @@ -4469,6 +4507,8 @@ END(cpu_getregs) .globl eintrcnt .globl intrnames .globl eintrnames +led_sw: + .byte 1 intrnames: .asciiz "softclock" .asciiz "softnet" diff --git a/sys/arch/wgrisc/wgrisc/machdep.c b/sys/arch/wgrisc/wgrisc/machdep.c index a0ab1bdcbd5..e8521ba6373 100644 --- a/sys/arch/wgrisc/wgrisc/machdep.c +++ b/sys/arch/wgrisc/wgrisc/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.2 1997/02/16 22:31:26 pefo Exp $ */ +/* $OpenBSD: machdep.c,v 1.3 1997/05/11 16:26:08 pefo Exp $ */ /* * Copyright (c) 1988 University of Utah. * Copyright (c) 1992, 1993 @@ -38,7 +38,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 8.3 (Berkeley) 1/12/94 - * $Id: machdep.c,v 1.2 1997/02/16 22:31:26 pefo Exp $ + * $Id: machdep.c,v 1.3 1997/05/11 16:26:08 pefo Exp $ */ /* from: Utah Hdr: machdep.c 1.63 91/04/24 */ @@ -460,7 +460,6 @@ consinit() return; initted = 1; cninit(); -mdbpanic(); } /* |