Module Name:    src
Committed By:   bouyer
Date:           Sat Apr 20 09:58:24 UTC 2013

Modified Files:
        src/sys/arch/vax/boot/xxboot [netbsd-6]: start.S
        src/sys/arch/vax/include [netbsd-6]: disklabel.h
        src/sys/kern [netbsd-6]: sys_generic.c
        src/sys/sys [netbsd-6]: bootblock.h disklabel.h
        src/usr.sbin/installboot/arch [netbsd-6]: vax.c

Log Message:
Pull up following revision(s) (requested by martin in ticket #865):
        sys/arch/vax/include/disklabel.h: revision 1.7
        sys/arch/vax/boot/xxboot/start.S: revision 1.5
        sys/sys/bootblock.h: revision 1.55
        sys/sys/disklabel.h: revision 1.113
        usr.sbin/installboot/arch/vax.c: revision 1.14
        usr.sbin/installboot/arch/vax.c: revision 1.15
        sys/kern/sys_generic.c: revision 1.129
Revert VAX MAXPARTITION bump to 16, adjusting it to 12 instead. Fix bootblocks
and installboot for VAX 780 and other machines booting via VMB.EXE.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.4.118.1 src/sys/arch/vax/boot/xxboot/start.S
cvs rdiff -u -r1.5.8.1 -r1.5.8.2 src/sys/arch/vax/include/disklabel.h
cvs rdiff -u -r1.128 -r1.128.2.1 src/sys/kern/sys_generic.c
cvs rdiff -u -r1.52.14.1 -r1.52.14.2 src/sys/sys/bootblock.h
cvs rdiff -u -r1.112 -r1.112.2.1 src/sys/sys/disklabel.h
cvs rdiff -u -r1.13 -r1.13.8.1 src/usr.sbin/installboot/arch/vax.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/vax/boot/xxboot/start.S
diff -u src/sys/arch/vax/boot/xxboot/start.S:1.4 src/sys/arch/vax/boot/xxboot/start.S:1.4.118.1
--- src/sys/arch/vax/boot/xxboot/start.S:1.4	Sun Dec 11 12:19:34 2005
+++ src/sys/arch/vax/boot/xxboot/start.S	Sat Apr 20 09:58:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: start.S,v 1.4 2005/12/11 12:19:34 christos Exp $ */
+/*	$NetBSD: start.S,v 1.4.118.1 2013/04/20 09:58:23 bouyer Exp $ */
 /*
  * Copyright (c) 1995 Ludd, University of Lule}, Sweden.
  * All rights reserved.
@@ -38,6 +38,7 @@
 
 #define _LOCORE
 
+#define	__HAVE_OLD_DISKLABEL	/* not automatically added due to _LOCORE */
 #define OMIT_DKTYPENUMS
 #define OMIT_FSTYPENUMS
 #include "sys/disklabel.h"
@@ -55,8 +56,12 @@ _C_LABEL(start):
 .org	0x00			# uVAX booted from TK50 starts here
 	brb	from_0x00	# continue behind dispatch-block
 
+# At offset 0x02 we have a dual used area: VMB.EXE starts execution here,
+# and uVAX-ROM looks for a pointer to a parameter block. We arrange for
+# the parameter block offset to disassmble as a CASEL instructions which
+# falls through to 0x08.
 .org	0x02			# information used by uVAX-ROM
-	.byte	0xcf		# offset in words to identification area 
+	.byte	0xcf		# offset in words to identification area
 	.byte	1		# this byte must be 1
 	.word	0		# logical block number (word swapped) 
 	.word	0		# of the secondary image
@@ -74,20 +79,6 @@ from_0x00:			# uVAX from TK50 
 
 from_0x08:			# Any machine from VMB
 	movzbl	$4,_C_LABEL(from)		# Booted from full VMB
-	brw	start_vmb
-
-# the complete area reserved for label
-# must be empty (i.e. filled with zeroes).
-# disklabel(8) checks that before installing
-# the bootblocks over existing label.
-
-.org	LABELOFFSET
-	.globl	_C_LABEL(romlabel)
-_C_LABEL(romlabel):
-	.long	0
-
-.org	LABELOFFSET + d_end_
-start_vmb:
 	/*
 	 * Read in block 1-15.
 	 */
@@ -102,6 +93,20 @@ start_vmb:
 	calls	$6, (%r6)	# call the qio-routine
 	brw	start_uvax
 
+# the complete area reserved for label
+# must be empty (i.e. filled with zeroes).
+# disklabel(8) checks that before installing
+# the bootblocks over existing label.
+
+.org	LABELOFFSET
+	.globl	_C_LABEL(romlabel)
+_C_LABEL(romlabel):
+	.long	0
+
+.org	LABELOFFSET + d_end_
+# Make sure the parameter block is past the disklabel.
+# If not, the next .org would try to move backwards.
+
 /*
  * Parameter block for uVAX boot.
  */
@@ -110,7 +115,7 @@ start_vmb:
 #define SILOAD		0	/* load offset (usually 0) from the default */
 #define SIOFF		0x200	/* byte offset into secondary image */
 
-.org	0x19e
+.org	0x19e	# do not move, see comment earlier about CASEL
 	.byte	0x18		# must be 0x18 
 	.byte	0x00		# must be 0x00 (MBZ) 
 	.byte	0x00		# any value 

Index: src/sys/arch/vax/include/disklabel.h
diff -u src/sys/arch/vax/include/disklabel.h:1.5.8.1 src/sys/arch/vax/include/disklabel.h:1.5.8.2
--- src/sys/arch/vax/include/disklabel.h:1.5.8.1	Thu Jul  5 18:16:14 2012
+++ src/sys/arch/vax/include/disklabel.h	Sat Apr 20 09:58:22 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: disklabel.h,v 1.5.8.1 2012/07/05 18:16:14 riz Exp $	*/
+/*	$NetBSD: disklabel.h,v 1.5.8.2 2013/04/20 09:58:22 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou
@@ -36,16 +36,24 @@
 #define LABELUSESMBR		0	/* no MBR partitionning */
 #define	LABELSECTOR		0	/* sector containing label */
 #define	LABELOFFSET		64	/* offset of label in sector */
-#define	MAXPARTITIONS		16	/* number of partitions */
+#define	MAXPARTITIONS		12	/* number of partitions */
 #define	OLDMAXPARTITIONS 	8	/* number of partitions before nb-6 */
 #define	RAW_PART		2	/* raw partition: xx?c */
+/*
+ * In NetBSD 6 we eroneously used a too large MAXPARTITIONS value (disklabel
+ * overlapped with important parts of the bootblocks and made some machines
+ * unbootable).
+ */
+#define	__TMPBIGMAXPARTITIONS	16	/* compatibility with 6.0 installs */
 
 /*
  * We use the highest bit of the minor number for the partition number.
  * This maintains backward compatibility with device nodes created before
  * MAXPARTITIONS was increased.
+ * Temporarily MAXPARTITIONS was 16, so we use that to keep compatibility
+ * with existing installations.
  */
-#define __VAX_MAXDISKS	((1 << 20) / MAXPARTITIONS)
+#define __VAX_MAXDISKS	((1 << 20) / __TMPBIGMAXPARTITIONS)
 #define DISKUNIT(dev)	((minor(dev) / OLDMAXPARTITIONS) % __VAX_MAXDISKS)
 #define DISKPART(dev)	((minor(dev) % OLDMAXPARTITIONS) + \
     ((minor(dev) / (__VAX_MAXDISKS * OLDMAXPARTITIONS)) * OLDMAXPARTITIONS))

Index: src/sys/kern/sys_generic.c
diff -u src/sys/kern/sys_generic.c:1.128 src/sys/kern/sys_generic.c:1.128.2.1
--- src/sys/kern/sys_generic.c:1.128	Wed Jan 25 00:28:36 2012
+++ src/sys/kern/sys_generic.c	Sat Apr 20 09:58:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_generic.c,v 1.128 2012/01/25 00:28:36 christos Exp $	*/
+/*	$NetBSD: sys_generic.c,v 1.128.2.1 2013/04/20 09:58:23 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_generic.c,v 1.128 2012/01/25 00:28:36 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_generic.c,v 1.128.2.1 2013/04/20 09:58:23 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -526,6 +526,12 @@ sys_ioctl(struct lwp *l, const struct sy
 	void 		*data, *memp;
 #define	STK_PARAMS	128
 	u_long		stkbuf[STK_PARAMS/sizeof(u_long)];
+#if  __TMPBIGMAXPARTITIONS > MAXPARTITIONS
+	size_t		zero_last = 0;
+#define	zero_size(SZ)	((SZ)+zero_last)
+#else
+#define	zero_size(SZ)	(SZ)
+#endif
 
 	memp = NULL;
 	alloc_size = 0;
@@ -563,7 +569,34 @@ sys_ioctl(struct lwp *l, const struct sy
 	 * but only copyin/out the smaller amount.
 	 */
 	if (IOCGROUP(com) == 'd') {
+#if  __TMPBIGMAXPARTITIONS > MAXPARTITIONS
+		u_long ocom = com;
+#endif
 		u_long ncom = com ^ (DIOCGDINFO ^ DIOCGDINFO32);
+
+#if  __TMPBIGMAXPARTITIONS > MAXPARTITIONS
+	/*
+	 * Userland might use struct disklabel that is bigger than the
+	 * the kernel version (historic accident) - alloc userland
+	 * size and zero unused part on copyout.
+	 */
+#define	DISKLABELLENDIFF	(sizeof(struct partition)	\
+				       *(__TMPBIGMAXPARTITIONS-MAXPARTITIONS))
+#define	IOCFIXUP(NIOC)	((NIOC&~(IOCPARM_MASK<<IOCPARM_SHIFT))	| \
+			   (IOCPARM_LEN(NIOC)-DISKLABELLENDIFF)<<IOCPARM_SHIFT)
+
+		switch (IOCFIXUP(ocom)) {
+		case DIOCGDINFO:
+		case DIOCWDINFO:
+		case DIOCSDINFO:
+		case DIOCGDEFLABEL:
+			com = ncom = IOCFIXUP(ocom);
+			zero_last = DISKLABELLENDIFF;
+			size -= DISKLABELLENDIFF;
+			goto done;
+		}
+#endif
+
 		switch (ncom) {
 		case DIOCGDINFO:
 		case DIOCWDINFO:
@@ -574,6 +607,9 @@ sys_ioctl(struct lwp *l, const struct sy
 				alloc_size = IOCPARM_LEN(DIOCGDINFO);
 			break;
 		}
+#if  __TMPBIGMAXPARTITIONS > MAXPARTITIONS
+		done: ;
+#endif
 	}
 	if (size > IOCPARM_MAX) {
 		error = ENOTTY;
@@ -615,7 +651,7 @@ sys_ioctl(struct lwp *l, const struct sy
 			 * Zero the buffer so the user always
 			 * gets back something deterministic.
 			 */
-			memset(data, 0, size);
+			memset(data, 0, zero_size(size));
 		} else if (com&IOC_VOID) {
 			*(void **)data = SCARG(uap, data);
 		}
@@ -648,7 +684,8 @@ sys_ioctl(struct lwp *l, const struct sy
 		 * already set and checked above.
 		 */
 		if (error == 0 && (com&IOC_OUT) && size) {
-			error = copyout(data, SCARG(uap, data), size);
+			error = copyout(data, SCARG(uap, data),
+			    zero_size(size));
 			ktrgenio(SCARG(uap, fd), UIO_READ, SCARG(uap, data),
 			    size, error);
 		}

Index: src/sys/sys/bootblock.h
diff -u src/sys/sys/bootblock.h:1.52.14.1 src/sys/sys/bootblock.h:1.52.14.2
--- src/sys/sys/bootblock.h:1.52.14.1	Thu Jul  5 18:16:15 2012
+++ src/sys/sys/bootblock.h	Sat Apr 20 09:58:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootblock.h,v 1.52.14.1 2012/07/05 18:16:15 riz Exp $	*/
+/*	$NetBSD: bootblock.h,v 1.52.14.2 2013/04/20 09:58:23 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2002-2004 The NetBSD Foundation, Inc.
@@ -1389,7 +1389,7 @@ struct vax_boot_block {
 	uint8_t		bb_mbone;	/* must be one */
 	uint16_t	bb_lbn_hi;	/* lbn (hi word) of bootstrap */
 	uint16_t	bb_lbn_low;	/* lbn (low word) of bootstrap */
-	uint8_t		pad1[460];
+	uint8_t		pad1[406];
 	/* disklabel offset is 64 from base, or 56 from start of pad1 */
 
 	/* The rest of these fields are identification area and describe
@@ -1412,7 +1412,7 @@ struct vax_boot_block {
 
 	/* The rest is unused.
 	 */
-	uint8_t		pad2[20];
+	uint8_t		pad2[74];
 } __packed;
 
 #define	VAX_BOOT_MAGIC1			0x18	/* size of BB info? */

Index: src/sys/sys/disklabel.h
diff -u src/sys/sys/disklabel.h:1.112 src/sys/sys/disklabel.h:1.112.2.1
--- src/sys/sys/disklabel.h:1.112	Mon Jan 16 18:47:58 2012
+++ src/sys/sys/disklabel.h	Sat Apr 20 09:58:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: disklabel.h,v 1.112 2012/01/16 18:47:58 christos Exp $	*/
+/*	$NetBSD: disklabel.h,v 1.112.2.1 2013/04/20 09:58:23 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1987, 1988, 1993
@@ -267,7 +267,7 @@ struct olddisklabel {
 	.set	d_ncylinders,52
 	.set	d_secpercyl,56
 	.set	d_secperunit,60
-	.set	d_end_,276		/* size of disk label */
+	.set	d_end_,148+(MAXPARTITIONS*16)
 #endif /* _LOCORE */
 
 /*

Index: src/usr.sbin/installboot/arch/vax.c
diff -u src/usr.sbin/installboot/arch/vax.c:1.13 src/usr.sbin/installboot/arch/vax.c:1.13.8.1
--- src/usr.sbin/installboot/arch/vax.c:1.13	Sun Apr  5 11:55:39 2009
+++ src/usr.sbin/installboot/arch/vax.c	Sat Apr 20 09:58:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vax.c,v 1.13 2009/04/05 11:55:39 lukem Exp $	*/
+/*	$NetBSD: vax.c,v 1.13.8.1 2013/04/20 09:58:23 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
@@ -68,20 +68,26 @@
 
 #include <sys/cdefs.h>
 #if !defined(__lint)
-__RCSID("$NetBSD: vax.c,v 1.13 2009/04/05 11:55:39 lukem Exp $");
+__RCSID("$NetBSD: vax.c,v 1.13.8.1 2013/04/20 09:58:23 bouyer Exp $");
 #endif	/* !__lint */
 
 #include <sys/param.h>
+#include <sys/disklabel.h>
 
 #include <assert.h>
 #include <err.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include "installboot.h"
 
+#ifndef __CTASSERT
+#define	__CTASSERT(X)
+#endif
+
 static int	load_bootstrap(ib_params *, char **,
 		    uint32_t *, uint32_t *, size_t *);
 
@@ -101,7 +107,7 @@ vax_clearboot(ib_params *params)
 	assert(params != NULL);
 	assert(params->fsfd != -1);
 	assert(params->filesystem != NULL);
-	assert(sizeof(struct vax_boot_block) == VAX_BOOT_BLOCK_BLOCKSIZE);
+	__CTASSERT(sizeof(bb)==VAX_BOOT_BLOCK_BLOCKSIZE);
 
 	rv = pread(params->fsfd, &bb, sizeof(bb), VAX_BOOT_BLOCK_OFFSET);
 	if (rv == -1) {
@@ -112,7 +118,7 @@ vax_clearboot(ib_params *params)
 		return (0);
 	}
 
-	if (bb.bb_id_offset * 2 != offsetof(struct vax_boot_block, bb_magic1)
+	if (bb.bb_id_offset*2 >= VAX_BOOT_BLOCK_BLOCKSIZE
 	    || bb.bb_magic1 != VAX_BOOT_MAGIC1) {
 		warnx(
 		    "Old boot block magic number invalid; boot block invalid");
@@ -154,10 +160,10 @@ static int
 vax_setboot(ib_params *params)
 {
 	struct stat		bootstrapsb;
-	struct vax_boot_block	bb;
+	struct vax_boot_block	*bb;
 	uint32_t		startblock;
 	int			retval;
-	char			*bootstrapbuf;
+	char			*bootstrapbuf, oldbb[VAX_BOOT_BLOCK_BLOCKSIZE];
 	size_t			bootstrapsize;
 	uint32_t		bootstrapload, bootstrapexec;
 	ssize_t			rv;
@@ -167,8 +173,12 @@ vax_setboot(ib_params *params)
 	assert(params->filesystem != NULL);
 	assert(params->s1fd != -1);
 	assert(params->stage1 != NULL);
-	assert(sizeof(struct vax_boot_block) == VAX_BOOT_BLOCK_BLOCKSIZE);
 
+	/* see sys/arch/vax/boot/xxboot/start.S for explanation */
+	__CTASSERT(offsetof(struct vax_boot_block,bb_magic1) == 0x19e);
+	__CTASSERT(sizeof(struct vax_boot_block) == VAX_BOOT_BLOCK_BLOCKSIZE);
+
+	startblock = 0;
 	retval = 0;
 	bootstrapbuf = NULL;
 
@@ -184,16 +194,29 @@ vax_setboot(ib_params *params)
 	    &bootstrapexec, &bootstrapsize))
 		goto done;
 
-	rv = pread(params->fsfd, &bb, sizeof(bb), VAX_BOOT_BLOCK_OFFSET);
+	/* read old boot block */
+	rv = pread(params->fsfd, oldbb, sizeof(oldbb), VAX_BOOT_BLOCK_OFFSET);
 	if (rv == -1) {
 		warn("Reading `%s'", params->filesystem);
 		goto done;
-	} else if (rv != sizeof(bb)) {
+	} else if (rv != sizeof(oldbb)) {
 		warnx("Reading `%s': short read", params->filesystem);
 		goto done;
 	}
 
-		/* fill in the updated boot block fields */
+	/*
+	 * Copy disklabel from old boot block to new.
+	 * Assume everything between LABELOFFSET and the start of
+	 * the param block is scratch area and can be copied over.
+	 */
+	memcpy(bootstrapbuf+LABELOFFSET,
+	    oldbb+LABELOFFSET,
+	    offsetof(struct vax_boot_block,bb_magic1)-LABELOFFSET);
+
+	/* point to bootblock at begining of bootstrap */
+	bb = (struct vax_boot_block*)bootstrapbuf;
+
+	/* fill in the updated boot block fields */
 	if (params->flags & IB_APPEND) {
 		struct stat	filesyssb;
 
@@ -209,46 +232,21 @@ vax_setboot(ib_params *params)
 		}
 		startblock = howmany(filesyssb.st_size,
 		    VAX_BOOT_BLOCK_BLOCKSIZE);
-	} else if (params->flags & IB_STAGE1START) {
-		startblock = params->s1start;
-	} else {
-		startblock = VAX_BOOT_BLOCK_OFFSET / VAX_BOOT_BLOCK_BLOCKSIZE
-		    + 1;
+		bb->bb_lbn_hi = htole16((uint16_t) (startblock >> 16));
+		bb->bb_lbn_low = htole16((uint16_t) (startblock >>  0));
 	}
 
-	bb.bb_id_offset = offsetof(struct vax_boot_block, bb_magic1) / 2;
-	bb.bb_mbone = 1;
-	bb.bb_lbn_hi = htole16((uint16_t) (startblock >> 16));
-	bb.bb_lbn_low = htole16((uint16_t) (startblock >>  0));
-	/*
-	 * Now the identification block
-	 */
-	bb.bb_magic1 = VAX_BOOT_MAGIC1;
-	bb.bb_mbz1 = 0;
-	bb.bb_sum1 = ~(bb.bb_magic1 + bb.bb_mbz1 + bb.bb_pad1);
-
-	bb.bb_mbz2 = 0;
-	bb.bb_volinfo = VAX_BOOT_VOLINFO_NONE;
-	bb.bb_pad2a = 0;
-	bb.bb_pad2b = 0;
-
-	bb.bb_size = htole32(bootstrapsize / VAX_BOOT_BLOCK_BLOCKSIZE);
-	bb.bb_load = htole32(VAX_BOOT_LOAD);
-	bb.bb_entry = htole32(VAX_BOOT_ENTRY);
-	bb.bb_sum3 = htole32(le32toh(bb.bb_size) + le32toh(bb.bb_load) \
-	    + le32toh(bb.bb_entry));
-
 	if (params->flags & IB_SUNSUM) {
 		uint16_t	sum;
 
-		sum = compute_sunsum((uint16_t *)&bb);
-		if (! set_sunsum(params, (uint16_t *)&bb, sum))
+		sum = compute_sunsum((uint16_t *)bb);
+		if (! set_sunsum(params, (uint16_t *)bb, sum))
 			goto done;
 	}
 
 	if (params->flags & IB_VERBOSE) {
 		printf("Bootstrap start sector: %u\n", startblock);
-		printf("Bootstrap sector count: %u\n", le32toh(bb.bb_size));
+		printf("Bootstrap sector count: %u\n", le32toh(bb->bb_size));
 		printf("%sriting bootstrap\n",
 		    (params->flags & IB_NOWRITE) ? "Not w" : "W");
 	}
@@ -256,8 +254,7 @@ vax_setboot(ib_params *params)
 		retval = 1;
 		goto done;
 	}
-	rv = pwrite(params->fsfd, bootstrapbuf, bootstrapsize,
-	     startblock * VAX_BOOT_BLOCK_BLOCKSIZE);
+	rv = pwrite(params->fsfd, bootstrapbuf, bootstrapsize, 0);
 	if (rv == -1) {
 		warn("Writing `%s'", params->filesystem);
 		goto done;
@@ -265,19 +262,7 @@ vax_setboot(ib_params *params)
 		warnx("Writing `%s': short write", params->filesystem);
 		goto done;
 	}
-
-	if (params->flags & IB_VERBOSE)
-		printf("Writing boot block\n");
-	rv = pwrite(params->fsfd, &bb, sizeof(bb), VAX_BOOT_BLOCK_OFFSET);
-	if (rv == -1) {
-		warn("Writing `%s'", params->filesystem);
-		goto done;
-	} else if (rv != sizeof(bb)) {
-		warnx("Writing `%s': short write", params->filesystem);
-		goto done;
-	} else {
-		retval = 1;
-	}
+	retval = 1;
 
  done:
 	if (bootstrapbuf)

Reply via email to