CVS commit: src/sys/dev/scsipi

2021-04-16 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Apr 16 12:58:54 UTC 2021

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
Limit buffer size for device capabilities requests as a work-around for PR
kern/56109.


To generate a diff of this commit:
cvs rdiff -u -r1.350 -r1.351 src/sys/dev/scsipi/cd.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/dev/scsipi/cd.c
diff -u src/sys/dev/scsipi/cd.c:1.350 src/sys/dev/scsipi/cd.c:1.351
--- src/sys/dev/scsipi/cd.c:1.350	Wed Feb 10 16:30:01 2021
+++ src/sys/dev/scsipi/cd.c	Fri Apr 16 12:58:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd.c,v 1.350 2021/02/10 16:30:01 christos Exp $	*/
+/*	$NetBSD: cd.c,v 1.351 2021/04/16 12:58:54 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.350 2021/02/10 16:30:01 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.351 2021/04/16 12:58:54 reinoud Exp $");
 
 #include 
 #include 
@@ -2695,15 +2695,13 @@ mmc_getdiscinfo(struct scsipi_periph *pe
 	struct scsipi_get_conf_feature   *gcf;
 	struct scsipi_read_discinfo   di_cmd;
 	struct scsipi_read_discinfo_data  di __aligned(2);
-	const uint32_t buffer_size = 1024;
-	uint32_t feat_tbl_len, pos;
+	const uint32_t buffer_size = 0x200; /* XXX RPZ USB3 SCSI size issue */
+	uint32_t pos;
 	u_long   last_lba = 0;
 	uint8_t  *buffer, *fpos;
 	int feature, last_feature, features_len, feature_cur, feature_len;
 	int lsb, msb, error, flags;
 
-	feat_tbl_len = buffer_size;
-
 	buffer = malloc(buffer_size, M_TEMP, M_WAITOK);
 
 	/* initialise structure */
@@ -2748,12 +2746,12 @@ mmc_getdiscinfo(struct scsipi_periph *pe
 		memset(_cmd, 0, sizeof(gc_cmd));
 		gc_cmd.opcode = GET_CONFIGURATION;
 		_lto2b(last_feature, gc_cmd.start_at_feature);
-		_lto2b(feat_tbl_len, gc_cmd.data_len);
-		memset(gc, 0, feat_tbl_len);
+		_lto2b(buffer_size, gc_cmd.data_len);
+		memset(gc, 0, buffer_size);
 
 		error = scsipi_command(periph,
 			(void *)_cmd, sizeof(gc_cmd),
-			(void *) gc, feat_tbl_len,
+			(void *) gc, buffer_size,
 			CDRETRIES, 3, NULL, flags);
 		if (error) {
 			/* ieeek... break out of loop... i dunno what to do */
@@ -2761,7 +2759,7 @@ mmc_getdiscinfo(struct scsipi_periph *pe
 		}
 
 		features_len = _4btol(gc->data_len);
-		if (features_len < 4 || features_len > feat_tbl_len)
+		if (features_len < 4 || features_len > buffer_size)
 			break;
 
 		pos  = 0;



CVS commit: src/lib/libnvmm

2021-04-06 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Apr  6 08:40:17 UTC 2021

Modified Files:
src/lib/libnvmm: libnvmm.c nvmm.h

Log Message:
Implement nvmm_vcpu::stop, a race-free exit from nvmm_vcpu_run() without
signals. This introduces a new kernel and userland NVMM version indicating
this support.

Patch by Kamil Rytarowski  and committed on his request.

This is the missing libnvmm part I forgot to include in the origional commit.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libnvmm/libnvmm.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libnvmm/nvmm.h

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

Modified files:

Index: src/lib/libnvmm/libnvmm.c
diff -u src/lib/libnvmm/libnvmm.c:1.19 src/lib/libnvmm/libnvmm.c:1.20
--- src/lib/libnvmm/libnvmm.c:1.19	Sat Sep  5 07:22:25 2020
+++ src/lib/libnvmm/libnvmm.c	Tue Apr  6 08:40:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: libnvmm.c,v 1.19 2020/09/05 07:22:25 maxv Exp $	*/
+/*	$NetBSD: libnvmm.c,v 1.20 2021/04/06 08:40:17 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -310,6 +310,7 @@ nvmm_vcpu_create(struct nvmm_machine *ma
 	vcpu->cpuid = cpuid;
 	vcpu->state = >state;
 	vcpu->event = >event;
+	vcpu->stop = >stop;
 	vcpu->exit = malloc(sizeof(*vcpu->exit));
 
 	return 0;
@@ -561,3 +562,12 @@ nvmm_ctl(int op, void *data, size_t size
 
 	return 0;
 }
+
+int
+nvmm_vcpu_stop(struct nvmm_vcpu *vcpu)
+{
+
+	*vcpu->stop = 1;
+
+	return 0;
+}

Index: src/lib/libnvmm/nvmm.h
diff -u src/lib/libnvmm/nvmm.h:1.18 src/lib/libnvmm/nvmm.h:1.19
--- src/lib/libnvmm/nvmm.h:1.18	Sat Sep  5 07:22:25 2020
+++ src/lib/libnvmm/nvmm.h	Tue Apr  6 08:40:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm.h,v 1.18 2020/09/05 07:22:25 maxv Exp $	*/
+/*	$NetBSD: nvmm.h,v 1.19 2021/04/06 08:40:17 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -37,7 +37,12 @@
 #include 
 #include 
 
-#define NVMM_USER_VERSION	1
+#define NVMM_USER_VERSION	2
+
+/*
+ * Version 1 - Initial release in NetBSD 9.0.
+ * Version 2 - Added nvmm_vcpu::stop.
+ */
 
 struct nvmm_io;
 struct nvmm_mem;
@@ -59,6 +64,7 @@ struct nvmm_vcpu {
 	struct nvmm_vcpu_state *state;
 	struct nvmm_vcpu_event *event;
 	struct nvmm_vcpu_exit *exit;
+	volatile int *stop;
 };
 
 struct nvmm_io {
@@ -123,4 +129,6 @@ int nvmm_ctl(int, void *, size_t);
 
 int nvmm_vcpu_dump(struct nvmm_machine *, struct nvmm_vcpu *);
 
+int nvmm_vcpu_stop(struct nvmm_vcpu *);
+
 #endif /* _LIBNVMM_H_ */



CVS commit: src/sys/dev/nvmm

2021-03-26 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Mar 26 15:59:53 UTC 2021

Modified Files:
src/sys/dev/nvmm: nvmm.c nvmm.h nvmm_internal.h
src/sys/dev/nvmm/x86: nvmm_x86.h nvmm_x86_svm.c nvmm_x86_vmx.c

Log Message:
Implement nvmm_vcpu::stop, a race-free exit from nvmm_vcpu_run() without
signals. This introduces a new kernel and userland NVMM version indicating
this support.

Patch by Kamil Rytarowski  and committed on his request.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/nvmm/nvmm.c
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/nvmm/nvmm.h
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/nvmm/nvmm_internal.h
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/nvmm/x86/nvmm_x86.h
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.81 -r1.82 src/sys/dev/nvmm/x86/nvmm_x86_vmx.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/dev/nvmm/nvmm.c
diff -u src/sys/dev/nvmm/nvmm.c:1.41 src/sys/dev/nvmm/nvmm.c:1.42
--- src/sys/dev/nvmm/nvmm.c:1.41	Tue Sep  8 16:58:38 2020
+++ src/sys/dev/nvmm/nvmm.c	Fri Mar 26 15:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm.c,v 1.41 2020/09/08 16:58:38 maxv Exp $	*/
+/*	$NetBSD: nvmm.c,v 1.42 2021/03/26 15:59:53 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.41 2020/09/08 16:58:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.42 2021/03/26 15:59:53 reinoud Exp $");
 
 #include 
 #include 
@@ -574,8 +574,7 @@ nvmm_do_vcpu_run(struct nvmm_machine *ma
 
 	while (1) {
 		/* Got a signal? Or pending resched? Leave. */
-		if (__predict_false(nvmm_return_needed())) {
-			exit->reason = NVMM_VCPU_EXIT_NONE;
+		if (__predict_false(nvmm_return_needed(vcpu, exit))) {
 			return 0;
 		}
 
@@ -620,6 +619,7 @@ nvmm_vcpu_run(struct nvmm_owner *owner, 
 
 out:
 	nvmm_machine_put(mach);
+	vcpu->comm->stop = 0;
 	return error;
 }
 

Index: src/sys/dev/nvmm/nvmm.h
diff -u src/sys/dev/nvmm/nvmm.h:1.15 src/sys/dev/nvmm/nvmm.h:1.16
--- src/sys/dev/nvmm/nvmm.h:1.15	Sat Sep  5 07:22:25 2020
+++ src/sys/dev/nvmm/nvmm.h	Fri Mar 26 15:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm.h,v 1.15 2020/09/05 07:22:25 maxv Exp $	*/
+/*	$NetBSD: nvmm.h,v 1.16 2021/03/26 15:59:53 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -47,7 +47,12 @@ typedef uint32_t	nvmm_cpuid_t;
 #include 
 #endif
 
-#define NVMM_KERN_VERSION		1
+#define NVMM_KERN_VERSION		2
+
+/*
+ * Version 1 - Initial release in NetBSD 9.0.
+ * Version 2 - Added nvmm_vcpu::stop.
+ */
 
 struct nvmm_capability {
 	uint32_t version;
@@ -80,6 +85,9 @@ struct nvmm_comm_page {
 	/* Event. */
 	bool event_commit;
 	struct nvmm_vcpu_event event;
+
+	/* Race-free exit from nvmm_vcpu_run() without signals. */
+	volatile int stop;
 };
 
 /*

Index: src/sys/dev/nvmm/nvmm_internal.h
diff -u src/sys/dev/nvmm/nvmm_internal.h:1.19 src/sys/dev/nvmm/nvmm_internal.h:1.20
--- src/sys/dev/nvmm/nvmm_internal.h:1.19	Sun Sep  6 02:18:53 2020
+++ src/sys/dev/nvmm/nvmm_internal.h	Fri Mar 26 15:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_internal.h,v 1.19 2020/09/06 02:18:53 riastradh Exp $	*/
+/*	$NetBSD: nvmm_internal.h,v 1.20 2021/03/26 15:59:53 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -136,14 +136,22 @@ extern const struct nvmm_impl nvmm_x86_v
 #endif
 
 static inline bool
-nvmm_return_needed(void)
+nvmm_return_needed(struct nvmm_cpu *vcpu, struct nvmm_vcpu_exit *exit)
 {
+
 	if (preempt_needed()) {
+		exit->reason = NVMM_VCPU_EXIT_NONE;
 		return true;
 	}
 	if (curlwp->l_flag & LW_USERRET) {
+		exit->reason = NVMM_VCPU_EXIT_NONE;
+		return true;
+	}
+	if (vcpu->comm->stop) {
+		exit->reason = NVMM_VCPU_EXIT_STOPPED;
 		return true;
 	}
+
 	return false;
 }
 

Index: src/sys/dev/nvmm/x86/nvmm_x86.h
diff -u src/sys/dev/nvmm/x86/nvmm_x86.h:1.20 src/sys/dev/nvmm/x86/nvmm_x86.h:1.21
--- src/sys/dev/nvmm/x86/nvmm_x86.h:1.20	Sat Sep  5 07:22:26 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86.h	Fri Mar 26 15:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86.h,v 1.20 2020/09/05 07:22:26 maxv Exp $	*/
+/*	$NetBSD: nvmm_x86.h,v 1.21 2021/03/26 15:59:53 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -74,6 +74,7 @@ struct nvmm_x86_exit_invalid {
 
 /* Generic. */
 #define NVMM_VCPU_EXIT_NONE		0xULL
+#define NVMM_VCPU_EXIT_STOPPED		0xFFFEULL
 #define NVMM_VCPU_EXIT_INVALID		0xULL
 /* x86: operations. */
 #define NVMM_VCPU_EXIT_MEMORY		0x0001ULL

Index: src/sys/dev/nvmm/x86/nvmm_x86_svm.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.82 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.83
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.82	Sat Oct 24 07:14:30 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c	Fri Mar 26 15:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_svm.c,v 1.82 

CVS commit: src/sys/arch/evbmips/conf

2021-02-16 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Feb 16 10:58:33 UTC 2021

Modified Files:
src/sys/arch/evbmips/conf: MIPSSIM files.mipssim

Log Message:
I forgot to add the needed conf files for the mipssim virtio addition


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbmips/conf/MIPSSIM
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/conf/files.mipssim

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/evbmips/conf/MIPSSIM
diff -u src/sys/arch/evbmips/conf/MIPSSIM:1.2 src/sys/arch/evbmips/conf/MIPSSIM:1.3
--- src/sys/arch/evbmips/conf/MIPSSIM:1.2	Mon Feb  8 00:47:53 2021
+++ src/sys/arch/evbmips/conf/MIPSSIM	Tue Feb 16 10:58:32 2021
@@ -1,10 +1,14 @@
-# $NetBSD: MIPSSIM,v 1.2 2021/02/08 00:47:53 simonb Exp $
+# $NetBSD: MIPSSIM,v 1.3 2021/02/16 10:58:32 reinoud Exp $
 #
 # Kernel config for the QEMU MIPS "mipssim" simulator
+#
+# The QEMU virtio support is experimental and subject to change
+# and will likely be removed when qemu gains a MIPS "virt" target.
+#
 
 include 	"arch/evbmips/conf/std.mipssim"
 
-#ident 		"GENERIC-$Revision: 1.2 $"
+#ident 		"GENERIC-$Revision: 1.3 $"
 
 maxusers	32
 
@@ -63,8 +67,8 @@ file-system	PTYFS		# /dev/pts/N support
 #options 	NFSSERVER	# Sun NFS-compatible filesystem server
 #options 	QUOTA		# legacy UFS quotas
 #options 	QUOTA2		# new, in-filesystem UFS quotas
-#options 	DISKLABEL_EI	# disklabel Endian Independent support
-#options 	FFS_EI		# FFS Endian Independent support
+options 	DISKLABEL_EI	# disklabel Endian Independent support
+options 	FFS_EI		# FFS Endian Independent support
 #options 	WAPBL		# File system journaling support
 #options 	EXT2FS_SYSTEM_FLAGS # makes ext2fs file flags (append and
 # immutable) behave as system flags.
@@ -105,6 +109,29 @@ com*		at mainbus?
 # mipsnet*	at mainbus?
 # options 	MIPSSIM_ETH_MACADDR="ba:bb:1e:01:23:45"
 
+
+# Virtio devices
+virtio*		at mainbus?		# Virtio PCI device
+#viomb*		at virtio?		# Virtio memory balloon device
+ld*		at virtio?		# Virtio disk device
+vioif*		at virtio?		# Virtio network device
+viornd*		at virtio?		# Virtio entropy device
+vioscsi*	at virtio?		# Virtio SCSI device
+#vio9p*		at virtio?		# Virtio 9P device
+
+# SCSI bus support
+scsibus* at scsi?
+
+# SCSI devices
+sd*	at scsibus? target ? lun ?	# SCSI disk drives
+#st*	at scsibus? target ? lun ?	# SCSI tape drives
+cd*	at scsibus? target ? lun ?	# SCSI CD-ROM drives
+#ch*	at scsibus? target ? lun ?	# SCSI autochangers
+#ses*	at scsibus? target ? lun ?	# SCSI Enclosure Services devices
+#ss*	at scsibus? target ? lun ?	# SCSI scanners
+#uk*	at scsibus? target ? lun ?	# SCSI unknown
+
+
 # Network pseudo-devices
 pseudo-device	bpfilter			# Berkeley packet filter
 #pseudo-device 	carp# Common Address Redundancy Protocol

Index: src/sys/arch/evbmips/conf/files.mipssim
diff -u src/sys/arch/evbmips/conf/files.mipssim:1.1 src/sys/arch/evbmips/conf/files.mipssim:1.2
--- src/sys/arch/evbmips/conf/files.mipssim:1.1	Wed Jan 27 05:24:16 2021
+++ src/sys/arch/evbmips/conf/files.mipssim	Tue Feb 16 10:58:33 2021
@@ -1,15 +1,19 @@
-# $NetBSD: files.mipssim,v 1.1 2021/01/27 05:24:16 simonb Exp $
+# $NetBSD: files.mipssim,v 1.2 2021/02/16 10:58:33 reinoud Exp $
 
 file	arch/evbmips/mipssim/autoconf.c
 file	arch/evbmips/mipssim/machdep.c
 file	arch/evbmips/mipssim/mipssim_intr.c
+file	arch/evbmips/mipssim/mipssim_dma.c
 file	arch/evbmips/mipssim/mipssim_bus_io.c
 
 file	arch/evbmips/evbmips/interrupt.c
 
+file	arch/mips/mips/bus_dma.c
 file	arch/mips/mips/mips3_clock.c
 file	arch/mips/mips/mips3_clockintr.c
 
+file	kern/subr_disk_mbr.c			disk
+
 # System bus
 device	mainbus {}
 attach	mainbus at root
@@ -27,5 +31,12 @@ attach	mipsnet at mainbus
 file	arch/evbmips/mipssim/if_mipsnet.c	mipsnet
 defparam opt_mipsnet.hMIPSSIM_ETH_MACADDR
 
+attach	virtio at mainbus with virtio_mainbus:	virtio_mmio
+file	arch/evbmips/mipssim/virtio_mainbus.c	virtio_mainbus
+
 # Memory Disk
 file	dev/md_root.cmemory_disk_hooks
+
+# SCSI support
+include "dev/scsipi/files.scsipi"
+



CVS commit: src/sys/arch/evbmips/mipssim

2021-02-15 Thread Reinoud Zandijk
/mipssim/mipssimreg.h:1.2
--- src/sys/arch/evbmips/mipssim/mipssimreg.h:1.1	Wed Jan 27 05:24:16 2021
+++ src/sys/arch/evbmips/mipssim/mipssimreg.h	Mon Feb 15 22:39:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: mipssimreg.h,v 1.1 2021/01/27 05:24:16 simonb Exp $ */
+/* $NetBSD: mipssimreg.h,v 1.2 2021/02/15 22:39:46 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,15 +35,27 @@
  *
  *	.	128MB	RAM (max ~500MB)
  *	1fd0.	 64kB	ISA IO space
+ *	1fd1.	 64kB	'ISA' VirtIO IO space (non standard)
  *
  *	CPU interrupts
  *
  *	 0	mipsnet
+ *	 1	virtio
  *	 2	16450 UART
  */
 
-#define	MIPSSIM_UART0_ADDR	0x3f8
-#define	MIPSSIM_MIPSNET0_ADDR	0x4200
+#define	MIPSSIM_UART0_ADDR	0x003f8
+#define	MIPSSIM_MIPSNET0_ADDR	0x04200
+#define MIPSSIM_VIRTIO_ADDR	0x1
 
 #define	MIPSSIM_ISA_IO_BASE	0x1fd0  /* ISA IO memory:	*/
 #define	MIPSSIM_ISA_IO_SIZE	0x0001  /*64 kByte	*/
+#define MIPSSIM_VIRTIO_IO_SIZE	0x0001  /*64 kByte  */
+
+#define MIPSSIM_DMA_BASE	0x
+#define MIPSSIM_DMA_PHYSBASE	0x
+#define MIPSSIM_DMA_SIZE	(MIPSSIM_ISA_IO_BASE - MIPSSIM_DMA_BASE)
+
+#define VIRTIO_NUM_TRANSPORTS	32
+#define VIRTIO_STRIDE		512
+
Index: src/sys/arch/evbmips/mipssim/mipssimvar.h
diff -u src/sys/arch/evbmips/mipssim/mipssimvar.h:1.1 src/sys/arch/evbmips/mipssim/mipssimvar.h:1.2
--- src/sys/arch/evbmips/mipssim/mipssimvar.h:1.1	Wed Jan 27 05:24:16 2021
+++ src/sys/arch/evbmips/mipssim/mipssimvar.h	Mon Feb 15 22:39:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: mipssimvar.h,v 1.1 2021/01/27 05:24:16 simonb Exp $ */
+/* $NetBSD: mipssimvar.h,v 1.2 2021/02/15 22:39:46 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2001,2021 The NetBSD Foundation, Inc.
@@ -33,9 +33,10 @@
 #include 
 
 struct mipssim_config {
-	struct mips_bus_space mc_iot;
+	struct mips_bus_space	mc_iot;
+	struct mips_bus_dma_tag	mc_dmat;
 
-	struct mips_isa_chipset mc_ic;
+	struct mips_isa_chipset	mc_ic;
 
 	struct extent *mc_io_ex;
 
@@ -45,3 +46,4 @@ struct mipssim_config {
 extern struct mipssim_config mipssim_configuration;
 
 void	mipssim_bus_io_init(bus_space_tag_t, void *);
+void	mipssim_dma_init(struct mipssim_config *);

Added files:

Index: src/sys/arch/evbmips/mipssim/mipssim_dma.c
diff -u /dev/null src/sys/arch/evbmips/mipssim/mipssim_dma.c:1.1
--- /dev/null	Mon Feb 15 22:39:46 2021
+++ src/sys/arch/evbmips/mipssim/mipssim_dma.c	Mon Feb 15 22:39:46 2021
@@ -0,0 +1,63 @@
+/*	$NetBSD: mipssim_dma.c,v 1.1 2021/02/15 22:39:46 reinoud Exp $	*/
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * Platform-specific DMA support for the mipssim.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: mipssim_dma.c,v 1.1 2021/02/15 22:39:46 reinoud Exp $");
+
+#include 
+#include 
+
+#define	_MIPS_BUS_DMA_PRIVATE
+#include 
+
+#include 
+
+#include 
+#include 
+
+void
+mipssim_dma_init(struct mipssim_config *mcp)
+{
+	bus_dma_tag_t t;
+
+	t = >mc_dmat;
+	t->_cookie = mcp;
+	t->_wbase = MIPSSIM_DMA_BASE;
+	t->_bounce_alloc_lo = MIPSSIM_DMA_PHYSBASE;
+	t->_bounce_alloc_hi = MIPSSIM_DMA_PHYSBASE + MIPSSIM_DMA_SIZE;
+	t->_dmamap_ops = mips_bus_dmamap_ops;
+	t->_dmamem_ops = mips_bus_dmamem_ops;
+	t->_dmatag_ops = mips_bus_dmatag_ops;
+}
Index: src/sys/arch/evbmips/mipssim/virtio_mainbus.c
diff -u /dev/null src/sys/arch/evbmips/mipssim/virtio_mainbus.c:1.1
--- /dev/null	Mon Feb 15 22:39:46 2021
+++ src/sys/arch/evbmips/mipssim/virtio_mainbus.c	Mon Feb 15 22:39:46 2021
@@ -0,0 +1,172 @@
+/* $NetBSD: virtio_mainbus.c,v 1.1 2021/02/15 22:39:46 reinou

CVS commit: src/sys/dev/virtio

2021-02-05 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Feb  5 21:25:36 UTC 2021

Modified Files:
src/sys/dev/virtio: virtio_mmio.c virtio_mmiovar.h

Log Message:
Add virtio mmio probe function


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/virtio/virtio_mmio.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/virtio/virtio_mmiovar.h

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

Modified files:

Index: src/sys/dev/virtio/virtio_mmio.c
diff -u src/sys/dev/virtio/virtio_mmio.c:1.5 src/sys/dev/virtio/virtio_mmio.c:1.6
--- src/sys/dev/virtio/virtio_mmio.c:1.5	Thu Jan 28 15:43:13 2021
+++ src/sys/dev/virtio/virtio_mmio.c	Fri Feb  5 21:25:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtio_mmio.c,v 1.5 2021/01/28 15:43:13 reinoud Exp $	*/
+/*	$NetBSD: virtio_mmio.c,v 1.6 2021/02/05 21:25:36 reinoud Exp $	*/
 /*	$OpenBSD: virtio_mmio.c,v 1.2 2017/02/24 17:12:31 patrick Exp $	*/
 
 /*
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_mmio.c,v 1.5 2021/01/28 15:43:13 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_mmio.c,v 1.6 2021/02/05 21:25:36 reinoud Exp $");
 
 #include 
 #include 
@@ -139,6 +139,16 @@ virtio_mmio_set_status(struct virtio_sof
 			  status|old);
 }
 
+bool
+virtio_mmio_common_probe_present(struct virtio_mmio_softc *sc)
+{
+	uint32_t magic;
+
+	magic = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
+	VIRTIO_MMIO_MAGIC_VALUE);
+	return (magic == VIRTIO_MMIO_MAGIC);
+}
+
 void
 virtio_mmio_common_attach(struct virtio_mmio_softc *sc)
 {

Index: src/sys/dev/virtio/virtio_mmiovar.h
diff -u src/sys/dev/virtio/virtio_mmiovar.h:1.3 src/sys/dev/virtio/virtio_mmiovar.h:1.4
--- src/sys/dev/virtio/virtio_mmiovar.h:1.3	Mon Jul 16 02:36:39 2018
+++ src/sys/dev/virtio/virtio_mmiovar.h	Fri Feb  5 21:25:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_mmiovar.h,v 1.3 2018/07/16 02:36:39 kre Exp $ */
+/* $NetBSD: virtio_mmiovar.h,v 1.4 2021/02/05 21:25:36 reinoud Exp $ */
 /*
  * Copyright (c) 2018 Jonathan A. Kollasch
  * All rights reserved.
@@ -44,6 +44,7 @@ struct virtio_mmio_softc {
 
 };
 
+bool virtio_mmio_common_probe_present(struct virtio_mmio_softc *);
 void virtio_mmio_common_attach(struct virtio_mmio_softc *);
 int virtio_mmio_common_detach(struct virtio_mmio_softc *, int);
 int virtio_mmio_intr(void *);



CVS commit: src/sys/dev/pci

2021-02-05 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Feb  5 20:45:38 UTC 2021

Modified Files:
src/sys/dev/pci: virtio.c

Log Message:
Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/pci/virtio.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/dev/pci/virtio.c
diff -u src/sys/dev/pci/virtio.c:1.46 src/sys/dev/pci/virtio.c:1.47
--- src/sys/dev/pci/virtio.c:1.46	Fri Feb  5 19:18:23 2021
+++ src/sys/dev/pci/virtio.c	Fri Feb  5 20:45:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtio.c,v 1.46 2021/02/05 19:18:23 reinoud Exp $	*/
+/*	$NetBSD: virtio.c,v 1.47 2021/02/05 20:45:38 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.46 2021/02/05 19:18:23 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.47 2021/02/05 20:45:38 reinoud Exp $");
 
 #include 
 #include 
@@ -204,7 +204,7 @@ virtio_read_device_config_4(struct virti
 /*
  * The Virtio spec explicitly tells that reading and writing 8 bytes are not
  * considered atomic and no triggers may be connected to reading or writing
- * it. This allows for reading byte-by-byte.
+ * it. We access it using two 32 reads. See virtio spec 4.1.3.1.
  */
 uint64_t
 virtio_read_device_config_8(struct virtio_softc *sc, int index) {
@@ -212,12 +212,16 @@ virtio_read_device_config_8(struct virti
 	bus_space_handle_t ioh = sc->sc_devcfg_ioh;
 	union {
 		uint64_t u64;
-		uint8_t  b[8];
+		uint32_t l[2];
 	} v;
 	uint64_t val;
 
-	for (int i = 0; i < 8; i++)
-		v.b[i] = bus_space_read_1(iot, ioh, index + i);
+	v.l[0] = bus_space_read_4(iot, ioh, index);
+	v.l[1] = bus_space_read_4(iot, ioh, index + 4);
+	if (sc->sc_bus_endian != sc->sc_struct_endian) {
+		v.l[0] = bswap32(v.l[0]);
+		v.l[1] = bswap32(v.l[1]);
+	}
 	val = v.u64;
 
 	if (BYTE_ORDER != sc->sc_struct_endian)
@@ -306,8 +310,9 @@ virtio_write_device_config_4(struct virt
 /*
  * The Virtio spec explicitly tells that reading and writing 8 bytes are not
  * considered atomic and no triggers may be connected to reading or writing
- * it. This allows for writing byte-by-byte. For good measure it is stated to
- * always write lsb first just in case of a hypervisor bug.
+ * it. We access it using two 32 bit writes. For good measure it is stated to
+ * always write lsb first just in case of a hypervisor bug. See See virtio
+ * spec 4.1.3.1.
  */
 void
 virtio_write_device_config_8(struct virtio_softc *sc, int index, uint64_t value)
@@ -316,19 +321,25 @@ virtio_write_device_config_8(struct virt
 	bus_space_handle_t ioh = sc->sc_devcfg_ioh;
 	union {
 		uint64_t u64;
-		uint8_t  b[8];
+		uint32_t l[2];
 	} v;
 
 	if (BYTE_ORDER != sc->sc_struct_endian)
 		value = bswap64(value);
 
 	v.u64 = value;
-	if (sc->sc_struct_endian == LITTLE_ENDIAN)
-		for (int i = 0; i < 8; i++)
-			bus_space_write_1(iot, ioh, index + i, v.b[i]);
- 	else
-		for (int i = 7; i >= 0; i--)
-			bus_space_write_1(iot, ioh, index + i, v.b[i]);
+	if (sc->sc_bus_endian != sc->sc_struct_endian) {
+		v.l[0] = bswap32(v.l[0]);
+		v.l[1] = bswap32(v.l[1]);
+	}
+
+	if (sc->sc_struct_endian == LITTLE_ENDIAN) {
+		bus_space_write_4(iot, ioh, index, v.l[0]);
+		bus_space_write_4(iot, ioh, index + 4, v.l[1]);
+	} else {
+		bus_space_write_4(iot, ioh, index + 4, v.l[1]);
+		bus_space_write_4(iot, ioh, index, v.l[0]);
+	}
 }
 
 /*



CVS commit: src/sys/dev/pci

2021-02-05 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Feb  5 19:18:23 UTC 2021

Modified Files:
src/sys/dev/pci: virtio.c virtio_pci.c virtiovar.h

Log Message:
Second round of cleaning up endian code. No more tailored code to maintain.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/pci/virtio.c
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/pci/virtio_pci.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/pci/virtiovar.h

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

Modified files:

Index: src/sys/dev/pci/virtio.c
diff -u src/sys/dev/pci/virtio.c:1.45 src/sys/dev/pci/virtio.c:1.46
--- src/sys/dev/pci/virtio.c:1.45	Thu Jan 28 15:43:12 2021
+++ src/sys/dev/pci/virtio.c	Fri Feb  5 19:18:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtio.c,v 1.45 2021/01/28 15:43:12 reinoud Exp $	*/
+/*	$NetBSD: virtio.c,v 1.46 2021/02/05 19:18:23 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.45 2021/01/28 15:43:12 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.46 2021/02/05 19:18:23 reinoud Exp $");
 
 #include 
 #include 
@@ -201,32 +201,27 @@ virtio_read_device_config_4(struct virti
 	return val;
 }
 
+/*
+ * The Virtio spec explicitly tells that reading and writing 8 bytes are not
+ * considered atomic and no triggers may be connected to reading or writing
+ * it. This allows for reading byte-by-byte.
+ */
 uint64_t
 virtio_read_device_config_8(struct virtio_softc *sc, int index) {
 	bus_space_tag_t	   iot = sc->sc_devcfg_iot;
 	bus_space_handle_t ioh = sc->sc_devcfg_ioh;
-	uint64_t val, val_0, val_1, val_l, val_h;
+	union {
+		uint64_t u64;
+		uint8_t  b[8];
+	} v;
+	uint64_t val;
+
+	for (int i = 0; i < 8; i++)
+		v.b[i] = bus_space_read_1(iot, ioh, index + i);
+	val = v.u64;
 
-	val_0 = bus_space_read_4(iot, ioh, index);
-	val_1 = bus_space_read_4(iot, ioh, index + 4);
-	if (BYTE_ORDER != sc->sc_bus_endian) {
-		val_l = bswap32(val_1);
-		val_h = bswap32(val_0);
-	} else {
-		val_l = val_0;
-		val_h = val_1;
-	}
-
-#ifdef AARCH64EB_PROBLEM
-	/* XXX see comment at virtio_pci.c */
-	if (sc->sc_aarch64eb_bus_problem) {
-		val_l = val_1;
-		val_h = val_0;
-	}
-#endif
-
-	val = val_h << 32;
-	val |= val_l;
+	if (BYTE_ORDER != sc->sc_struct_endian)
+		val = bswap64(val);
 
 	DPRINTFR("read_8", "%08lx", val, index, 8);
 	DPRINTFR2("read_8 low ", "%08x",
@@ -308,34 +303,32 @@ virtio_write_device_config_4(struct virt
 	bus_space_write_4(iot, ioh, index, value);
 }
 
+/*
+ * The Virtio spec explicitly tells that reading and writing 8 bytes are not
+ * considered atomic and no triggers may be connected to reading or writing
+ * it. This allows for writing byte-by-byte. For good measure it is stated to
+ * always write lsb first just in case of a hypervisor bug.
+ */
 void
 virtio_write_device_config_8(struct virtio_softc *sc, int index, uint64_t value)
 {
 	bus_space_tag_t	   iot = sc->sc_devcfg_iot;
 	bus_space_handle_t ioh = sc->sc_devcfg_ioh;
-	uint64_t val_0, val_1, val_l, val_h;
-
-	val_l = BUS_ADDR_LO32(value);
-	val_h = BUS_ADDR_HI32(value);
-
-	if (BYTE_ORDER != sc->sc_bus_endian) {
-		val_0 = bswap32(val_h);
-		val_1 = bswap32(val_l);
-	} else {
-		val_0 = val_l;
-		val_1 = val_h;
-	}
-
-#ifdef AARCH64EB_PROBLEM
-	/* XXX see comment at virtio_pci.c */
-	if (sc->sc_aarch64eb_bus_problem) {
-		val_0 = val_h;
-		val_1 = val_l;
-	}
-#endif
-
-	bus_space_write_4(iot, ioh, index, val_0);
-	bus_space_write_4(iot, ioh, index + 4, val_1);
+	union {
+		uint64_t u64;
+		uint8_t  b[8];
+	} v;
+
+	if (BYTE_ORDER != sc->sc_struct_endian)
+		value = bswap64(value);
+
+	v.u64 = value;
+	if (sc->sc_struct_endian == LITTLE_ENDIAN)
+		for (int i = 0; i < 8; i++)
+			bus_space_write_1(iot, ioh, index + i, v.b[i]);
+ 	else
+		for (int i = 7; i >= 0; i--)
+			bus_space_write_1(iot, ioh, index + i, v.b[i]);
 }
 
 /*

Index: src/sys/dev/pci/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.27 src/sys/dev/pci/virtio_pci.c:1.28
--- src/sys/dev/pci/virtio_pci.c:1.27	Thu Jan 28 15:43:12 2021
+++ src/sys/dev/pci/virtio_pci.c	Fri Feb  5 19:18:23 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.27 2021/01/28 15:43:12 reinoud Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.28 2021/02/05 19:18:23 reinoud Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.27 2021/01/28 15:43:12 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.28 2021/02/05 19:18:23 reinoud Exp $");
 
 #include 
 #include 
@@ -127,15 +127,11 @@ static int	virtio_pci_setup_intx_interru
  * suddenly read BIG_ENDIAN where it should stay LITTLE_ENDIAN. The data read
  * 1 byte at a time seem OK but reading bigger lengths result in swapped
  * endian. This is most notable on reading 8 byters since we can't use
- * bus_space_{read,write}_8() and it has to be patched there explicitly. We

CVS commit: src/sys/dev/pci

2021-02-03 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Feb  3 21:04:41 UTC 2021

Modified Files:
src/sys/dev/pci: if_vioif.c

Log Message:
Oops, made a mistake in my last commit


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/dev/pci/if_vioif.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/dev/pci/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.68 src/sys/dev/pci/if_vioif.c:1.69
--- src/sys/dev/pci/if_vioif.c:1.68	Wed Feb  3 20:27:59 2021
+++ src/sys/dev/pci/if_vioif.c	Wed Feb  3 21:04:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vioif.c,v 1.68 2021/02/03 20:27:59 reinoud Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.69 2021/02/03 21:04:41 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.68 2021/02/03 20:27:59 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.69 2021/02/03 21:04:41 reinoud Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -574,7 +574,7 @@ vioif_alloc_mems(struct vioif_softc *sc)
 		rxq = >sc_rxq[qid];
 		txq = >sc_txq[qid];
 
-		allocsize += sizeof(struct virtio_net_hdr *) *
+		allocsize += sizeof(struct virtio_net_hdr) *
 			(rxq->rxq_vq->vq_num + txq->txq_vq->vq_num);
 	}
 	if (sc->sc_has_ctrl) {



CVS commit: src/sys/dev/pci

2021-02-03 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Feb  3 20:28:00 UTC 2021

Modified Files:
src/sys/dev/pci: if_vioif.c

Log Message:
Allocate enough space for the bus_dmamap_t arrays for rxq_hdr_dmamaps[] and
txq_hdr_maps[]


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/dev/pci/if_vioif.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/dev/pci/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.67 src/sys/dev/pci/if_vioif.c:1.68
--- src/sys/dev/pci/if_vioif.c:1.67	Sun Jan 31 14:17:48 2021
+++ src/sys/dev/pci/if_vioif.c	Wed Feb  3 20:27:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vioif.c,v 1.67 2021/01/31 14:17:48 reinoud Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.68 2021/02/03 20:27:59 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.67 2021/01/31 14:17:48 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.68 2021/02/03 20:27:59 reinoud Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -574,8 +574,8 @@ vioif_alloc_mems(struct vioif_softc *sc)
 		rxq = >sc_rxq[qid];
 		txq = >sc_txq[qid];
 
-		allocsize += sc->sc_hdr_size * rxq->rxq_vq->vq_num;
-		allocsize += sc->sc_hdr_size * txq->txq_vq->vq_num;
+		allocsize += sizeof(struct virtio_net_hdr *) *
+			(rxq->rxq_vq->vq_num + txq->txq_vq->vq_num);
 	}
 	if (sc->sc_has_ctrl) {
 		allocsize += sizeof(struct virtio_net_ctrl_cmd) * 1;



CVS commit: src/sys/dev/pci

2021-01-31 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Jan 31 14:17:48 UTC 2021

Modified Files:
src/sys/dev/pci: if_vioif.c

Log Message:
Although the header structure can be smaller, the headers *are* indexed as if
they are full sized so allocate enough memory so the indexing works as
expected and we are not scribbling outside bounds.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/dev/pci/if_vioif.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/dev/pci/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.66 src/sys/dev/pci/if_vioif.c:1.67
--- src/sys/dev/pci/if_vioif.c:1.66	Wed Jan 20 19:46:48 2021
+++ src/sys/dev/pci/if_vioif.c	Sun Jan 31 14:17:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vioif.c,v 1.66 2021/01/20 19:46:48 reinoud Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.67 2021/01/31 14:17:48 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.66 2021/01/20 19:46:48 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.67 2021/01/31 14:17:48 reinoud Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -611,9 +611,9 @@ vioif_alloc_mems(struct vioif_softc *sc)
 		txq = >sc_txq[qid];
 
 		rxq->rxq_hdrs = vioif_assign_mem(,
-		sc->sc_hdr_size * rxq->rxq_vq->vq_num);
+		sizeof(struct virtio_net_hdr) * rxq->rxq_vq->vq_num);
 		txq->txq_hdrs = vioif_assign_mem(,
-		sc->sc_hdr_size * txq->txq_vq->vq_num);
+		sizeof(struct virtio_net_hdr) * txq->txq_vq->vq_num);
 	}
 	if (sc->sc_has_ctrl) {
 		ctrlq->ctrlq_cmd = vioif_assign_mem(,



CVS commit: src/sys/dev

2021-01-28 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu Jan 28 15:43:13 UTC 2021

Modified Files:
src/sys/dev/pci: virtio.c virtio_pci.c virtiovar.h
src/sys/dev/virtio: virtio_mmio.c

Log Message:
Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/pci/virtio.c
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/pci/virtio_pci.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/pci/virtiovar.h
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/virtio/virtio_mmio.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/dev/pci/virtio.c
diff -u src/sys/dev/pci/virtio.c:1.44 src/sys/dev/pci/virtio.c:1.45
--- src/sys/dev/pci/virtio.c:1.44	Wed Jan 20 21:59:48 2021
+++ src/sys/dev/pci/virtio.c	Thu Jan 28 15:43:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtio.c,v 1.44 2021/01/20 21:59:48 reinoud Exp $	*/
+/*	$NetBSD: virtio.c,v 1.45 2021/01/28 15:43:12 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.44 2021/01/20 21:59:48 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.45 2021/01/28 15:43:12 reinoud Exp $");
 
 #include 
 #include 
@@ -146,135 +146,245 @@ virtio_negotiate_features(struct virtio_
 	for (int i = 0; i < num; i++) \
 		printf("%02x ", bus_space_read_1(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index+i)); \
 	printf(") -> "); printf(fmt, val); printf("\n");
+#define DPRINTFR2(n, fmt, val_s, val_n) \
+	printf("%s ", n); \
+	printf("\nstream "); printf(fmt, val_s); printf(" norm "); printf(fmt, val_n); printf("\n");
 #else
 #define DPRINTFR(n, fmt, val, index, num)
+#define DPRINTFR2(n, fmt, val_s, val_n)
 #endif
 
+
 uint8_t
 virtio_read_device_config_1(struct virtio_softc *sc, int index) {
+	bus_space_tag_t	   iot = sc->sc_devcfg_iot;
+	bus_space_handle_t ioh = sc->sc_devcfg_ioh;
 	uint8_t val;
-	val = sc->sc_ops->read_dev_cfg_1(sc, index);
+
+	val = bus_space_read_1(iot, ioh, index);
+
 	DPRINTFR("read_1", "%02x", val, index, 1);
 	return val;
 }
 
 uint16_t
 virtio_read_device_config_2(struct virtio_softc *sc, int index) {
+	bus_space_tag_t	   iot = sc->sc_devcfg_iot;
+	bus_space_handle_t ioh = sc->sc_devcfg_ioh;
 	uint16_t val;
-	val = sc->sc_ops->read_dev_cfg_2(sc, index);
+
+	val = bus_space_read_2(iot, ioh, index);
+	if (BYTE_ORDER != sc->sc_bus_endian)
+		val = bswap16(val);
+
 	DPRINTFR("read_2", "%04x", val, index, 2);
+	DPRINTFR2("read_2", "%04x",
+		bus_space_read_stream_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index),
+		bus_space_read_2(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index));
 	return val;
 }
 
 uint32_t
 virtio_read_device_config_4(struct virtio_softc *sc, int index) {
+	bus_space_tag_t	   iot = sc->sc_devcfg_iot;
+	bus_space_handle_t ioh = sc->sc_devcfg_ioh;
 	uint32_t val;
-	val = sc->sc_ops->read_dev_cfg_4(sc, index);
+
+	val = bus_space_read_4(iot, ioh, index);
+	if (BYTE_ORDER != sc->sc_bus_endian)
+		val = bswap32(val);
+
 	DPRINTFR("read_4", "%08x", val, index, 4);
+	DPRINTFR2("read_4", "%08x",
+		bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index),
+		bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index));
 	return val;
 }
 
 uint64_t
 virtio_read_device_config_8(struct virtio_softc *sc, int index) {
-	uint64_t val;
-	val = sc->sc_ops->read_dev_cfg_8(sc, index);
+	bus_space_tag_t	   iot = sc->sc_devcfg_iot;
+	bus_space_handle_t ioh = sc->sc_devcfg_ioh;
+	uint64_t val, val_0, val_1, val_l, val_h;
+
+	val_0 = bus_space_read_4(iot, ioh, index);
+	val_1 = bus_space_read_4(iot, ioh, index + 4);
+	if (BYTE_ORDER != sc->sc_bus_endian) {
+		val_l = bswap32(val_1);
+		val_h = bswap32(val_0);
+	} else {
+		val_l = val_0;
+		val_h = val_1;
+	}
+
+#ifdef AARCH64EB_PROBLEM
+	/* XXX see comment at virtio_pci.c */
+	if (sc->sc_aarch64eb_bus_problem) {
+		val_l = val_1;
+		val_h = val_0;
+	}
+#endif
+
+	val = val_h << 32;
+	val |= val_l;
+
 	DPRINTFR("read_8", "%08lx", val, index, 8);
+	DPRINTFR2("read_8 low ", "%08x",
+		bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index),
+		bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index));
+	DPRINTFR2("read_8 high ", "%08x",
+		bus_space_read_stream_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index + 4),
+		bus_space_read_4(sc->sc_devcfg_iot, sc->sc_devcfg_ioh, index + 4));
 	return val;
 }
 
 /*
  * In the older virtio spec, device config registers are host endian. On newer
- * they are little endian. The normal logic will cater for this. However some
- * devices however explicitly state that its fields are always little endian
- * and will still need to be swapped.
+ * they are little endian. Some newer devices however explicitly specify their
+ * register to always be little endian. These fuctions cater for 

CVS commit: src/sys/dev/pci

2021-01-26 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jan 26 16:40:16 UTC 2021

Modified Files:
src/sys/dev/pci: virtio_pci.c

Log Message:
Fix indexing bug in clean up code on error in virtio PCI v1.0 attach code.
Thanks go to Rin Okuyama for spotting it.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/pci/virtio_pci.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/dev/pci/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.25 src/sys/dev/pci/virtio_pci.c:1.26
--- src/sys/dev/pci/virtio_pci.c:1.25	Sun Jan 24 15:59:35 2021
+++ src/sys/dev/pci/virtio_pci.c	Tue Jan 26 16:40:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.25 2021/01/24 15:59:35 reinoud Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.26 2021/01/26 16:40:16 reinoud Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.25 2021/01/24 15:59:35 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.26 2021/01/26 16:40:16 reinoud Exp $");
 
 #include 
 #include 
@@ -444,7 +444,7 @@ virtio_pci_attach_10(device_t self, void
 	bus_size_t bars[NMAPREG] = { 0 };
 	int bars_idx[NMAPREG] = { 0 };
 	struct virtio_pci_cap *caps[] = { , , ,  };
-	int i, j = 0, ret = 0;
+	int i, j, ret = 0;
 
 	if (virtio_pci_find_cap(psc, VIRTIO_PCI_CAP_COMMON_CFG,
 			, sizeof(common)))
@@ -471,7 +471,7 @@ virtio_pci_attach_10(device_t self, void
 			bars[bar] = len;
 	}
 
-	for (i = 0; i < __arraycount(bars); i++) {
+	for (i = j = 0; i < __arraycount(bars); i++) {
 		int reg;
 		pcireg_t type;
 		if (bars[i] == 0)
@@ -551,10 +551,10 @@ virtio_pci_attach_10(device_t self, void
 err:
 	/* undo our pci_mapreg_map()s */ 
 	for (i = 0; i < __arraycount(bars); i++) {
-		if (bars[i] == 0)
+		if (psc->sc_bars_iosize[i] == 0)
 			continue;
-		bus_space_unmap(psc->sc_bars_iot[j], psc->sc_bars_ioh[j],
-psc->sc_bars_iosize[j]);
+		bus_space_unmap(psc->sc_bars_iot[i], psc->sc_bars_ioh[i],
+psc->sc_bars_iosize[i]);
 	}
 	return ret;
 }



CVS commit: src/sys/dev/pci

2021-01-24 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Jan 24 15:59:35 UTC 2021

Modified Files:
src/sys/dev/pci: virtio_pci.c

Log Message:
Remove incorrect comment. It would violate the specs.

VirtIO PCI v1.0 attachments can only happen on revision 1 devices as they have
a radical different register layout. Transitional devices have to use revision
0 and have to use the VirtIO PCI v0.9 attachment method but can allow for
features to be negotiated normally found in later versions.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/pci/virtio_pci.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/dev/pci/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.24 src/sys/dev/pci/virtio_pci.c:1.25
--- src/sys/dev/pci/virtio_pci.c:1.24	Sun Jan 24 15:34:07 2021
+++ src/sys/dev/pci/virtio_pci.c	Sun Jan 24 15:59:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.24 2021/01/24 15:34:07 thorpej Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.25 2021/01/24 15:59:35 reinoud Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.24 2021/01/24 15:34:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.25 2021/01/24 15:59:35 reinoud Exp $");
 
 #include 
 #include 
@@ -461,12 +461,6 @@ virtio_pci_attach_10(device_t self, void
 	else
 		have_device_cfg = 1;
 
-	/*
-	 * XXX Maybe there are devices that offer the pci caps but not the
-	 * XXX VERSION_1 feature bit? Then we should check the feature bit
-	 * XXX here and fall back to 0.9 out if not present.
-	 */
-
 	/* Figure out which bars we need to map */
 	for (i = 0; i < __arraycount(caps); i++) {
 		int bar = caps[i]->bar;



CVS commit: src/sys/dev/pci

2021-01-24 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Jan 24 15:33:02 UTC 2021

Modified Files:
src/sys/dev/pci: virtio_pci.c

Log Message:
On error unmap the pci_mapreg_map()d regions using bus_space_unmap() as
suggested by jak@


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/pci/virtio_pci.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/dev/pci/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.22 src/sys/dev/pci/virtio_pci.c:1.23
--- src/sys/dev/pci/virtio_pci.c:1.22	Sun Jan 24 14:33:49 2021
+++ src/sys/dev/pci/virtio_pci.c	Sun Jan 24 15:33:02 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.22 2021/01/24 14:33:49 reinoud Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.23 2021/01/24 15:33:02 reinoud Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.22 2021/01/24 14:33:49 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.23 2021/01/24 15:33:02 reinoud Exp $");
 
 #include 
 #include 
@@ -555,7 +555,13 @@ virtio_pci_attach_10(device_t self, void
 	return 0;
 
 err:
-	/* there is no pci_mapreg_unmap() */
+	/* undo our pci_mapreg_map()s */ 
+	for (i = 0; i < __arraycount(bars); i++) {
+		if (bars[i] == 0)
+			continue;
+		bus_space_unmap(psc->sc_bars_iot[j], psc->sc_bars_ioh[j],
+psc->sc_bars_iosize[j]);
+	}
 	return ret;
 }
 



CVS commit: src/sys/dev/pci

2021-01-24 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Jan 24 14:33:49 UTC 2021

Modified Files:
src/sys/dev/pci: virtio_pci.c

Log Message:
Move definition of NMAPREG to the start


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/pci/virtio_pci.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/dev/pci/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.21 src/sys/dev/pci/virtio_pci.c:1.22
--- src/sys/dev/pci/virtio_pci.c:1.21	Sun Jan 24 14:12:36 2021
+++ src/sys/dev/pci/virtio_pci.c	Sun Jan 24 14:33:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.21 2021/01/24 14:12:36 reinoud Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.22 2021/01/24 14:33:49 reinoud Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.21 2021/01/24 14:12:36 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.22 2021/01/24 14:33:49 reinoud Exp $");
 
 #include 
 #include 
@@ -55,6 +55,9 @@ static void	virtio_pci_attach(device_t, 
 static int	virtio_pci_rescan(device_t, const char *, const int *);
 static int	virtio_pci_detach(device_t, int);
 
+
+#define NMAPREG		((PCI_MAPREG_END - PCI_MAPREG_START) / \
+sizeof(pcireg_t))
 struct virtio_pci_softc {
 	struct virtio_softc	sc_sc;
 
@@ -426,8 +429,6 @@ virtio_pci_attach_09(device_t self, void
 }
 
 
-#define NMAPREG		((PCI_MAPREG_END - PCI_MAPREG_START) / \
-sizeof(pcireg_t))
 static int
 virtio_pci_attach_10(device_t self, void *aux)
 {



CVS commit: src/sys/dev/pci

2021-01-24 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Jan 24 14:12:36 UTC 2021

Modified Files:
src/sys/dev/pci: virtio_pci.c

Log Message:
Prevent potential buffer over runs in number of BARS


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/pci/virtio_pci.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/dev/pci/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.20 src/sys/dev/pci/virtio_pci.c:1.21
--- src/sys/dev/pci/virtio_pci.c:1.20	Sun Jan 24 01:44:11 2021
+++ src/sys/dev/pci/virtio_pci.c	Sun Jan 24 14:12:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.20 2021/01/24 01:44:11 christos Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.21 2021/01/24 14:12:36 reinoud Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.20 2021/01/24 01:44:11 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.21 2021/01/24 14:12:36 reinoud Exp $");
 
 #include 
 #include 
@@ -65,9 +65,9 @@ struct virtio_pci_softc {
 	bus_size_t		sc_mapped_iosize;
 
 	/* BARs */
-	bus_space_tag_t		sc_bars_iot[4];
-	bus_space_handle_t	sc_bars_ioh[4];
-	bus_size_t		sc_bars_iosize[4];
+	bus_space_tag_t		sc_bars_iot[NMAPREG];
+	bus_space_handle_t	sc_bars_ioh[NMAPREG];
+	bus_size_t		sc_bars_iosize[NMAPREG];
 
 	/* notify space */
 	bus_space_tag_t		sc_notify_iot;



CVS commit: src/sys/dev/pci

2021-01-21 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu Jan 21 20:48:33 UTC 2021

Modified Files:
src/sys/dev/pci: virtio_pci.c

Log Message:
Remove dependency on bus_space_write_8() for i386 and instead implement it as
two bus_space_write_4()'s as allowed in the spec.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/pci/virtio_pci.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/dev/pci/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.17 src/sys/dev/pci/virtio_pci.c:1.18
--- src/sys/dev/pci/virtio_pci.c:1.17	Thu Jan 21 08:17:13 2021
+++ src/sys/dev/pci/virtio_pci.c	Thu Jan 21 20:48:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.17 2021/01/21 08:17:13 martin Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.18 2021/01/21 20:48:33 reinoud Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.17 2021/01/21 08:17:13 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.18 2021/01/21 20:48:33 reinoud Exp $");
 
 #include 
 #include 
@@ -727,6 +727,14 @@ virtio_pci_read_queue_size_10(struct vir
 	return bus_space_read_2(iot, ioh, VIRTIO_CONFIG1_QUEUE_SIZE);
 }
 
+/*
+ * By definition little endian only in v1.0 and 8 byters are allowed to be
+ * written as two 4 byters
+ */
+#define bus_space_write_le_8(iot, ioh, reg, val) \
+	bus_space_write_4(iot, ioh, reg, ((uint64_t) (val)) & 0x); \
+	bus_space_write_4(iot, ioh, reg + 4, ((uint64_t) (val)) >> 32);
+
 static void
 virtio_pci_setup_queue_10(struct virtio_softc *sc, uint16_t idx, uint64_t addr)
 {
@@ -739,15 +747,15 @@ virtio_pci_setup_queue_10(struct virtio_
 	bus_space_write_2(iot, ioh, VIRTIO_CONFIG1_QUEUE_SELECT, vq->vq_index);
 	if (addr == 0) {
 		bus_space_write_2(iot, ioh, VIRTIO_CONFIG1_QUEUE_ENABLE, 0);
-		bus_space_write_8(iot, ioh, VIRTIO_CONFIG1_QUEUE_DESC,   0);
-		bus_space_write_8(iot, ioh, VIRTIO_CONFIG1_QUEUE_AVAIL,  0);
-		bus_space_write_8(iot, ioh, VIRTIO_CONFIG1_QUEUE_USED,   0);
+		bus_space_write_le_8(iot, ioh, VIRTIO_CONFIG1_QUEUE_DESC,   0);
+		bus_space_write_le_8(iot, ioh, VIRTIO_CONFIG1_QUEUE_AVAIL,  0);
+		bus_space_write_le_8(iot, ioh, VIRTIO_CONFIG1_QUEUE_USED,   0);
 	} else {
-		bus_space_write_8(iot, ioh,
+		bus_space_write_le_8(iot, ioh,
 			VIRTIO_CONFIG1_QUEUE_DESC, addr);
-		bus_space_write_8(iot, ioh,
+		bus_space_write_le_8(iot, ioh,
 			VIRTIO_CONFIG1_QUEUE_AVAIL, addr + vq->vq_availoffset);
-		bus_space_write_8(iot, ioh,
+		bus_space_write_le_8(iot, ioh,
 			VIRTIO_CONFIG1_QUEUE_USED, addr + vq->vq_usedoffset);
 		bus_space_write_2(iot, ioh,
 			VIRTIO_CONFIG1_QUEUE_ENABLE, 1);
@@ -763,6 +771,7 @@ virtio_pci_setup_queue_10(struct virtio_
 			VIRTIO_CONFIG1_QUEUE_MSIX_VECTOR, vec);
 	}
 }
+#undef bus_space_write_le_8
 
 static void
 virtio_pci_set_status_10(struct virtio_softc *sc, int status)



CVS commit: src/sys/dev

2021-01-20 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan 20 21:59:49 UTC 2021

Modified Files:
src/sys/dev/acpi: virtio_acpi.c
src/sys/dev/fdt: virtio_mmio_fdt.c
src/sys/dev/pci: virtio.c virtio_pci.c virtiovar.h

Log Message:
Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/virtio_acpi.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/fdt/virtio_mmio_fdt.c
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/pci/virtio.c
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/pci/virtio_pci.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/pci/virtiovar.h

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

Modified files:

Index: src/sys/dev/acpi/virtio_acpi.c
diff -u src/sys/dev/acpi/virtio_acpi.c:1.5 src/sys/dev/acpi/virtio_acpi.c:1.6
--- src/sys/dev/acpi/virtio_acpi.c:1.5	Wed Jan 20 19:46:48 2021
+++ src/sys/dev/acpi/virtio_acpi.c	Wed Jan 20 21:59:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_acpi.c,v 1.5 2021/01/20 19:46:48 reinoud Exp $ */
+/* $NetBSD: virtio_acpi.c,v 1.6 2021/01/20 21:59:48 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_acpi.c,v 1.5 2021/01/20 19:46:48 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_acpi.c,v 1.6 2021/01/20 21:59:48 reinoud Exp $");
 
 #include 
 #include 
@@ -168,12 +168,6 @@ virtio_acpi_rescan(device_t self, const 
 	if (virtio_attach_failed(vsc))
 		return 0;
 
-	/*
-	 * Make sure child drivers initialize interrupts via call
-	 * to virtio_child_attach_finish().
-	 */
-	KASSERT(msc->sc_ih != NULL);
-
 	return 0;
 }
 

Index: src/sys/dev/fdt/virtio_mmio_fdt.c
diff -u src/sys/dev/fdt/virtio_mmio_fdt.c:1.5 src/sys/dev/fdt/virtio_mmio_fdt.c:1.6
--- src/sys/dev/fdt/virtio_mmio_fdt.c:1.5	Wed Jan 20 19:46:48 2021
+++ src/sys/dev/fdt/virtio_mmio_fdt.c	Wed Jan 20 21:59:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_mmio_fdt.c,v 1.5 2021/01/20 19:46:48 reinoud Exp $ */
+/* $NetBSD: virtio_mmio_fdt.c,v 1.6 2021/01/20 21:59:48 reinoud Exp $ */
 
 /*
  * Copyright (c) 2018 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_mmio_fdt.c,v 1.5 2021/01/20 19:46:48 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_mmio_fdt.c,v 1.6 2021/01/20 21:59:48 reinoud Exp $");
 
 #include 
 #include 
@@ -128,12 +128,6 @@ virtio_mmio_fdt_rescan(device_t self, co
 	if (virtio_attach_failed(vsc))
 		return 0;
 
-	/*
-	 * Make sure child drivers initialize interrupts via call
-	 * to virtio_child_attach_finish().
-	 */
-	KASSERT(msc->sc_ih != NULL);
-
 	return 0;
 }
 

Index: src/sys/dev/pci/virtio.c
diff -u src/sys/dev/pci/virtio.c:1.43 src/sys/dev/pci/virtio.c:1.44
--- src/sys/dev/pci/virtio.c:1.43	Wed Jan 20 19:46:48 2021
+++ src/sys/dev/pci/virtio.c	Wed Jan 20 21:59:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtio.c,v 1.43 2021/01/20 19:46:48 reinoud Exp $	*/
+/*	$NetBSD: virtio.c,v 1.44 2021/01/20 21:59:48 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.43 2021/01/20 19:46:48 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.44 2021/01/20 21:59:48 reinoud Exp $");
 
 #include 
 #include 
@@ -1084,6 +1084,7 @@ virtio_child_attach_finish(struct virtio
 {
 	int r;
 
+	sc->sc_finished_called = true;
 	r = sc->sc_ops->setup_interrupts(sc);
 	if (r != 0) {
 		aprint_error_dev(sc->sc_dev, "failed to setup interrupts\n");
@@ -1187,6 +1188,14 @@ virtio_attach_failed(struct virtio_softc
 		aprint_error_dev(self, "virtio configuration failed\n");
 		return 1;
 	}
+
+	/* sanity check */
+	if (!sc->sc_finished_called) {
+		aprint_error_dev(self, "virtio internal error, child driver "
+			"signaled OK but didn't initialize interrupts\n");
+		return 1;
+	}
+
 	return 0;
 }
 

Index: src/sys/dev/pci/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.15 src/sys/dev/pci/virtio_pci.c:1.16
--- src/sys/dev/pci/virtio_pci.c:1.15	Wed Jan 20 19:46:48 2021
+++ src/sys/dev/pci/virtio_pci.c	Wed Jan 20 21:59:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.15 2021/01/20 19:46:48 reinoud Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.16 2021/01/20 21:59:48 reinoud Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.15 2021/01/20 19:46:48 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.16 2021/01/20 21:59:48 reinoud Exp $");
 
 #include 
 #include 
@@ -351,12 +351,6 @@ virtio_pci_rescan(device_t self, const c
 	if (virtio_attach_failed(sc))
 		return 0;
 
-	/*
-	 * Make sure child drivers initialize interrupts via call
-	 * to virtio_child_attach_finish().
-	 */
-	KASSERT(psc->sc_ihs_num != 0);
-

CVS commit: src/sys/dev

2021-01-20 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan 20 19:46:48 UTC 2021

Modified Files:
src/sys/dev/acpi: virtio_acpi.c
src/sys/dev/fdt: virtio_mmio_fdt.c
src/sys/dev/pci: if_vioif.c ld_virtio.c vio9p.c viomb.c viornd.c
vioscsi.c virtio.c virtio_pci.c virtioreg.h virtiovar.h
src/sys/dev/virtio: virtio_mmio.c
Added Files:
src/sys/dev/pci: virtio_pcireg.h

Log Message:
Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
  attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
  regression.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/virtio_acpi.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/virtio_mmio_fdt.c
cvs rdiff -u -r1.65 -r1.66 src/sys/dev/pci/if_vioif.c
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/pci/ld_virtio.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/pci/vio9p.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/pci/viomb.c
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/pci/viornd.c
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/pci/vioscsi.c
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/pci/virtio.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/pci/virtio_pci.c
cvs rdiff -u -r0 -r1.1 src/sys/dev/pci/virtio_pcireg.h
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/pci/virtioreg.h
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/pci/virtiovar.h
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/virtio/virtio_mmio.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/dev/acpi/virtio_acpi.c
diff -u src/sys/dev/acpi/virtio_acpi.c:1.4 src/sys/dev/acpi/virtio_acpi.c:1.5
--- src/sys/dev/acpi/virtio_acpi.c:1.4	Mon Dec  7 10:02:51 2020
+++ src/sys/dev/acpi/virtio_acpi.c	Wed Jan 20 19:46:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_acpi.c,v 1.4 2020/12/07 10:02:51 jmcneill Exp $ */
+/* $NetBSD: virtio_acpi.c,v 1.5 2021/01/20 19:46:48 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_acpi.c,v 1.4 2020/12/07 10:02:51 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_acpi.c,v 1.5 2021/01/20 19:46:48 reinoud Exp $");
 
 #include 
 #include 
@@ -163,7 +163,16 @@ virtio_acpi_rescan(device_t self, const 
 	memset(, 0, sizeof(va));
 	va.sc_childdevid = vsc->sc_childdevid;
 
-	config_found_ia(self, ifattr, , virtiobusprint);
+	config_found_ia(self, ifattr, , NULL);
+
+	if (virtio_attach_failed(vsc))
+		return 0;
+
+	/*
+	 * Make sure child drivers initialize interrupts via call
+	 * to virtio_child_attach_finish().
+	 */
+	KASSERT(msc->sc_ih != NULL);
 
 	return 0;
 }

Index: src/sys/dev/fdt/virtio_mmio_fdt.c
diff -u src/sys/dev/fdt/virtio_mmio_fdt.c:1.4 src/sys/dev/fdt/virtio_mmio_fdt.c:1.5
--- src/sys/dev/fdt/virtio_mmio_fdt.c:1.4	Fri Jan 15 22:35:39 2021
+++ src/sys/dev/fdt/virtio_mmio_fdt.c	Wed Jan 20 19:46:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_mmio_fdt.c,v 1.4 2021/01/15 22:35:39 jmcneill Exp $ */
+/* $NetBSD: virtio_mmio_fdt.c,v 1.5 2021/01/20 19:46:48 reinoud Exp $ */
 
 /*
  * Copyright (c) 2018 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_mmio_fdt.c,v 1.4 2021/01/15 22:35:39 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_mmio_fdt.c,v 1.5 2021/01/20 19:46:48 reinoud Exp $");
 
 #include 
 #include 
@@ -119,19 +119,14 @@ virtio_mmio_fdt_rescan(device_t self, co
 
 	if (vsc->sc_child)	/* Child already attached? */
 		return 0;
+
 	memset(, 0, sizeof(va));
 	va.sc_childdevid = vsc->sc_childdevid;
 
-	config_found_ia(self, attr, , virtiobusprint);
+	config_found_ia(self, attr, , NULL);
 
-	if (vsc->sc_child == NULL) {
+	if (virtio_attach_failed(vsc))
 		return 0;
-	}
-
-	if (vsc->sc_child == VIRTIO_CHILD_FAILED) {
-		aprint_error_dev(self, "virtio configuration failed\n");
-		return 0;
-	}
 
 	/*
 	 * Make sure child drivers initialize interrupts via call
@@ -164,7 +159,7 @@ virtio_mmio_fdt_setup_interrupts(struct 
 		return -1;
 	}
 
-	if (vsc->sc_flags & VIRTIO_F_PCI_INTR_MPSAFE)
+	if (vsc->sc_flags & VIRTIO_F_INTR_MPSAFE)
 		flags |= FDT_INTR_MPSAFE;
 
 	msc->sc_ih = fdtbus_intr_establish_xname(fsc->sc_phandle, 0,

Index: src/sys/dev/pci/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.65 src/sys/dev/pci/if_vioif.c:1.66
--- src/sys/dev/pci/if_vioif.c:1.65	Thu May 28 23:25:17 2020
+++ src/sys/dev/pci/if_vioif.c	Wed Jan 20 19:46:48 2021
@@ -1,6 +1,7 @@
-/*	$NetBSD: if_vioif.c,v 1.65 2020/05/28 23:25:17 riastradh Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.66 2021/01/20 19:46:48 reinoud Exp $	*/
 
 /*
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
  * 

CVS commit: src/sys/dev/pci

2021-01-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan 13 19:46:49 UTC 2021

Modified Files:
src/sys/dev/pci: viomb.c

Log Message:
Fix for virtios viomb memory balloon driver. The inflate_done() and
deflate_done() issued a wrong extent to bus_dmamap_sync() giving rise to
panics on aarch64s mmio backend.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/pci/viomb.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/dev/pci/viomb.c
diff -u src/sys/dev/pci/viomb.c:1.10 src/sys/dev/pci/viomb.c:1.11
--- src/sys/dev/pci/viomb.c:1.10	Tue Dec 10 18:00:17 2019
+++ src/sys/dev/pci/viomb.c	Wed Jan 13 19:46:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: viomb.c,v 1.10 2019/12/10 18:00:17 ad Exp $	*/
+/*	$NetBSD: viomb.c,v 1.11 2021/01/13 19:46:49 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: viomb.c,v 1.10 2019/12/10 18:00:17 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: viomb.c,v 1.11 2021/01/13 19:46:49 reinoud Exp $");
 
 #include 
 #include 
@@ -341,7 +341,7 @@ inflate_done(struct viomb_softc *sc)
 	b = >sc_req;
 	nvpages = b->bl_nentries;
 	bus_dmamap_sync(virtio_dmat(vsc), b->bl_dmamap,
-			offsetof(struct balloon_req, bl_pages),
+			0,
 			sizeof(uint32_t)*nvpages,
 			BUS_DMASYNC_POSTWRITE);
 	while (!TAILQ_EMPTY(>bl_pglist)) {
@@ -456,7 +456,7 @@ deflate_done(struct viomb_softc *sc)
 	b = >sc_req;
 	nvpages = b->bl_nentries;
 	bus_dmamap_sync(virtio_dmat(vsc), b->bl_dmamap,
-			offsetof(struct balloon_req, bl_pages),
+			0,
 			sizeof(uint32_t)*nvpages,
 			BUS_DMASYNC_POSTWRITE);
 



CVS commit: src/usr.bin/resize

2020-12-27 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Dec 27 21:25:02 UTC 2020

Modified Files:
src/usr.bin/resize: resize.1

Log Message:
Make the new resize(1) manpage indistinguisable from the original


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/resize/resize.1

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

Modified files:

Index: src/usr.bin/resize/resize.1
diff -u src/usr.bin/resize/resize.1:1.1 src/usr.bin/resize/resize.1:1.2
--- src/usr.bin/resize/resize.1:1.1	Sun Dec 27 21:13:18 2020
+++ src/usr.bin/resize/resize.1	Sun Dec 27 21:25:02 2020
@@ -44,7 +44,7 @@
 .el   .ds `` ``
 .ie \n(.g .ds '' \(rq
 .el   .ds '' ''
-.TH RESIZE 1 "__app_date__" "__app_version__" "X Window System"
+.TH RESIZE 1 "2017-06-20" "Patch 330" "X Window System"
 .SH NAME
 resize \- set environment and terminal settings to current xterm window size
 .SH SYNOPSIS
@@ -187,7 +187,7 @@ so it is possible for \fI\*n\fP to be co
 .TP 15
 TERM
 .I \*N
-sets this to "__default_termname__" if not already set.
+sets this to "xterm" if not already set.
 .TP 15
 TERMCAP
 .I \*N
@@ -206,7 +206,7 @@ use_env(3x)
 .br
 csh(1), stty(1), tset(1)
 .br
-xterm(__mansuffix__)
+xterm(1)
 .SH AUTHORS
 Mark Vandevoorde (MIT-Athena), Edward Moy (Berkeley)
 .br
@@ -215,5 +215,5 @@ Thomas Dickey (invisible-island.net).
 Copyright (c) 1984, 1985 by X Consortium
 .br
 See
-.IR X (__miscmansuffix__)
+.IR X (7)
 for a complete copyright notice.



CVS commit: src

2020-12-27 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Dec 27 21:13:18 UTC 2020

Modified Files:
src/distrib/sets/lists/base: mi
src/distrib/sets/lists/man: mi
src/distrib/sets/lists/xbase: mi
src/doc: CHANGES
src/external/mit/xorg/bin/xterm: Makefile
Added Files:
src/usr.bin/resize: Makefile resize.1 resize.c xstrings.c xstrings.h

Log Message:
Import Xterm's resize(1) for querying (x)terminal sizes in base for headless
clients


To generate a diff of this commit:
cvs rdiff -u -r1.1272 -r1.1273 src/distrib/sets/lists/base/mi
cvs rdiff -u -r1.1711 -r1.1712 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.163 -r1.164 src/distrib/sets/lists/xbase/mi
cvs rdiff -u -r1.2770 -r1.2771 src/doc/CHANGES
cvs rdiff -u -r1.18 -r1.19 src/external/mit/xorg/bin/xterm/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/resize/Makefile \
src/usr.bin/resize/resize.1 src/usr.bin/resize/resize.c \
src/usr.bin/resize/xstrings.c src/usr.bin/resize/xstrings.h

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

Modified files:

Index: src/distrib/sets/lists/base/mi
diff -u src/distrib/sets/lists/base/mi:1.1272 src/distrib/sets/lists/base/mi:1.1273
--- src/distrib/sets/lists/base/mi:1.1272	Mon Nov 23 12:41:47 2020
+++ src/distrib/sets/lists/base/mi	Sun Dec 27 21:13:18 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1272 2020/11/23 12:41:47 martin Exp $
+# $NetBSD: mi,v 1.1273 2020/12/27 21:13:18 reinoud Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -951,6 +951,7 @@
 ./usr/bin/renicebase-util-bin
 ./usr/bin/reset	base-util-bin
 ./usr/bin/rev	base-util-bin
+./usr/bin/resizebase-util-bin
 ./usr/bin/revokebase-util-bin
 ./usr/bin/rfcomm_sppdbase-util-bin
 ./usr/bin/rlog	base-rcs-bin

Index: src/distrib/sets/lists/man/mi
diff -u src/distrib/sets/lists/man/mi:1.1711 src/distrib/sets/lists/man/mi:1.1712
--- src/distrib/sets/lists/man/mi:1.1711	Tue Nov 10 21:47:41 2020
+++ src/distrib/sets/lists/man/mi	Sun Dec 27 21:13:18 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1711 2020/11/10 21:47:41 kamil Exp $
+# $NetBSD: mi,v 1.1712 2020/12/27 21:13:18 reinoud Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -490,6 +490,7 @@
 ./usr/share/man/cat1/rehash.0			man-util-catman		.cat
 ./usr/share/man/cat1/repeat.0			man-util-catman		.cat
 ./usr/share/man/cat1/reset.0			man-util-catman		.cat
+./usr/share/man/cat1/resize.0			man-util-catman		.cat
 ./usr/share/man/cat1/rev.0			man-util-catman		.cat
 ./usr/share/man/cat1/rfcomm_sppd.0		man-util-catman		.cat
 ./usr/share/man/cat1/rlog.0			man-rcs-catman		.cat
@@ -3774,6 +3775,7 @@
 ./usr/share/man/html1/rehash.html		man-util-htmlman	html
 ./usr/share/man/html1/repeat.html		man-util-htmlman	html
 ./usr/share/man/html1/reset.html		man-util-htmlman	html
+./usr/share/man/html1/resize.html		man-util-htmlman	html
 ./usr/share/man/html1/rev.html			man-util-htmlman	html
 ./usr/share/man/html1/rfcomm_sppd.html		man-util-htmlman	html
 ./usr/share/man/html1/rlog.html			man-rcs-htmlman		html
@@ -6708,6 +6710,7 @@
 ./usr/share/man/man1/rehash.1			man-util-man		.man
 ./usr/share/man/man1/repeat.1			man-util-man		.man
 ./usr/share/man/man1/reset.1			man-util-man		.man
+./usr/share/man/man1/resize.1			man-util-man		.man
 ./usr/share/man/man1/rev.1			man-util-man		.man
 ./usr/share/man/man1/rfcomm_sppd.1		man-util-man		.man
 ./usr/share/man/man1/rlog.1			man-rcs-man		.man

Index: src/distrib/sets/lists/xbase/mi
diff -u src/distrib/sets/lists/xbase/mi:1.163 src/distrib/sets/lists/xbase/mi:1.164
--- src/distrib/sets/lists/xbase/mi:1.163	Tue Nov 10 21:47:41 2020
+++ src/distrib/sets/lists/xbase/mi	Sun Dec 27 21:13:18 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.163 2020/11/10 21:47:41 kamil Exp $
+# $NetBSD: mi,v 1.164 2020/12/27 21:13:18 reinoud Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -53,7 +53,7 @@
 ./usr/X11R7/bin/perfbothxbase-x11perf-bin	xorg
 ./usr/X11R7/bin/perfratioxbase-x11perf-bin	xorg
 ./usr/X11R7/bin/proxymngrxbase-proxymngr-bin	xorg
-./usr/X11R7/bin/resize	xbase-xterm-bin	xorg
+./usr/X11R7/bin/resize	xbase-obsolete		obsolete
 ./usr/X11R7/bin/revpath	xbase-revpath-bin	xorg
 ./usr/X11R7/bin/sessreg	xbase-sessreg-bin	xorg
 ./usr/X11R7/bin/setxkbmapxbase-setxkbmap-bin	xorg
@@ -1309,7 +1309,7 @@
 ./usr/X11R7/man/cat1/mkhtmlindex.0			xbase-mkhtmlindex-catman	.cat,xorg
 ./usr/X11R7/man/cat1/oclock.0xbase-oclock-catman	.cat,xorg
 ./usr/X11R7/man/cat1/proxymngr.0			xbase-proxymngr-catman	.cat,xorg
-./usr/X11R7/man/cat1/resize.0xbase-xterm-catman	.cat,xorg
+./usr/X11R7/man/cat1/resize.0xbase-obsolete		obsolete
 ./usr/X11R7/man/cat1/revpath.0xbase-revpath-catman	.cat,xorg
 ./usr/X11R7/man/cat1/sessreg.0xbase-sessreg-catman	.cat,xorg
 ./usr/X11R7/man/cat1/setxkbmap.0			

CVS commit: src

2020-12-27 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Dec 27 20:56:14 UTC 2020

Modified Files:
src/doc: CHANGES
src/lib/libnvmm: libnvmm_x86.c
src/tests/lib/libnvmm: h_mem_assist.c h_mem_assist_asm.S

Log Message:
Implement support for trapping REP CMPS instructions in NVMM.

Qemu would abort hard when NVMM would get a memory trap on the instruction
since it didn't know it.


To generate a diff of this commit:
cvs rdiff -u -r1.2769 -r1.2770 src/doc/CHANGES
cvs rdiff -u -r1.42 -r1.43 src/lib/libnvmm/libnvmm_x86.c
cvs rdiff -u -r1.19 -r1.20 src/tests/lib/libnvmm/h_mem_assist.c
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libnvmm/h_mem_assist_asm.S

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

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2769 src/doc/CHANGES:1.2770
--- src/doc/CHANGES:1.2769	Sun Dec 27 18:28:25 2020
+++ src/doc/CHANGES	Sun Dec 27 20:56:14 2020
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2769 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2770 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -321,3 +321,5 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 	sti(4), hp300: Add bitmap access ops support for SGC CRX (A1659-66001)
 		framebuffer for HP9000/425t. [tsutsui 20201223]
 	openresolv: Update to version 3.12.0 [roy 20201227]
+	nvmm: implement support for trapping REP CMPS [reinoud 20201227]
+

Index: src/lib/libnvmm/libnvmm_x86.c
diff -u src/lib/libnvmm/libnvmm_x86.c:1.42 src/lib/libnvmm/libnvmm_x86.c:1.43
--- src/lib/libnvmm/libnvmm_x86.c:1.42	Sat Oct 31 15:44:01 2020
+++ src/lib/libnvmm/libnvmm_x86.c	Sun Dec 27 20:56:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: libnvmm_x86.c,v 1.42 2020/10/31 15:44:01 reinoud Exp $	*/
+/*	$NetBSD: libnvmm_x86.c,v 1.43 2020/12/27 20:56:14 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -869,7 +869,6 @@ static void x86_func_test(struct nvmm_vc
 static void x86_func_mov(struct nvmm_vcpu *, struct nvmm_mem *, uint64_t *);
 static void x86_func_stos(struct nvmm_vcpu *, struct nvmm_mem *, uint64_t *);
 static void x86_func_lods(struct nvmm_vcpu *, struct nvmm_mem *, uint64_t *);
-static void x86_func_movs(struct nvmm_vcpu *, struct nvmm_mem *, uint64_t *);
 
 static const struct x86_emul x86_emul_or = {
 	.readreg = true,
@@ -919,10 +918,6 @@ static const struct x86_emul x86_emul_lo
 	.func = x86_func_lods
 };
 
-static const struct x86_emul x86_emul_movs = {
-	.func = x86_func_movs
-};
-
 /* Legacy prefixes. */
 #define LEG_LOCK	0xF0
 #define LEG_REPN	0xF2
@@ -941,6 +936,7 @@ struct x86_legpref {
 	bool adr_ovr:1;
 	bool rep:1;
 	bool repn:1;
+	bool repe:1;
 	int8_t seg;
 };
 
@@ -1049,6 +1045,7 @@ struct x86_opcode {
 	bool dmo:1;
 	bool todmo:1;
 	bool movs:1;
+	bool cmps:1;
 	bool stos:1;
 	bool lods:1;
 	bool szoverride:1;
@@ -1451,7 +1448,7 @@ static const struct x86_opcode primary_o
 		.movs = true,
 		.szoverride = false,
 		.defsize = OPSIZE_BYTE,
-		.emul = _emul_movs
+		.emul = NULL
 	},
 	[0xA5] = {
 		/* Yv, Xv */
@@ -1459,7 +1456,27 @@ static const struct x86_opcode primary_o
 		.movs = true,
 		.szoverride = true,
 		.defsize = -1,
-		.emul = _emul_movs
+		.emul = NULL
+	},
+
+	/*
+	 * CMPS
+	 */
+	[0xA6] = {
+		/* Yb, Xb */
+		.valid = true,
+		.cmps = true,
+		.szoverride = false,
+		.defsize = OPSIZE_BYTE,
+		.emul = NULL
+	},
+	[0xA7] = {
+		/* Yv, Xv */
+		.valid = true,
+		.cmps = true,
+		.szoverride = true,
+		.defsize = -1,
+		.emul = NULL
 	},
 
 	/*
@@ -1871,6 +1888,35 @@ node_movs(struct x86_decode_fsm *fsm, st
 }
 
 /*
+ * Special node, for CMPS. Fake two displacements of zero on the source and
+ * destination registers.
+ * XXX coded as clone of movs as its similar in register usage
+ * XXX might be merged with node_movs()
+ */
+static int
+node_cmps(struct x86_decode_fsm *fsm, struct x86_instr *instr)
+{
+	size_t adrsize;
+
+	adrsize = instr->address_size;
+
+	/* DS:RSI */
+	instr->src.type = STORE_REG;
+	instr->src.u.reg = _map__special[1][2][adrsize-1];
+	instr->src.disp.type = DISP_0;
+
+	/* ES:RDI, force ES */
+	instr->dst.type = STORE_REG;
+	instr->dst.u.reg = _map__special[1][3][adrsize-1];
+	instr->dst.disp.type = DISP_0;
+	instr->dst.hardseg = NVMM_X64_SEG_ES;
+
+	fsm_advance(fsm, 0, NULL);
+
+	return 0;
+}
+
+/*
  * Special node, for STOS and LODS. Fake a displacement of zero on the
  * destination register.
  */
@@ -2470,6 +2516,8 @@ node_primary_opcode(struct x86_decode_fs
 		fsm_advance(fsm, 1, node_stlo);
 	} else if (opcode->movs) {
 		fsm_advance(fsm, 1, node_movs);
+	} else if (opcode->cmps) {
+		fsm_advance(fsm, 1, node_cmps);
 	} else {
 		return -1;
 	}
@@ -2646,8 +2694,17 @@ x86_decode(uint8_t *inst_bytes, size_t i
 
 	while (fsm.fn != NULL) {
 		ret = (*fsm.fn)(, instr);
-		if (ret == -1)
+		if (ret == -1) {
+#ifdef NVMM_DEBUG
+			printf("\n%s debug: unrecognized instruction found " \
+			   

CVS commit: src/sys/dev/pci

2020-11-19 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu Nov 19 21:59:07 UTC 2020

Modified Files:
src/sys/dev/pci: pcidevs

Log Message:
Add modern QUMRANET/Red Hat VIRTIO range PCI devices


To generate a diff of this commit:
cvs rdiff -u -r1.1419 -r1.1420 src/sys/dev/pci/pcidevs

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

Modified files:

Index: src/sys/dev/pci/pcidevs
diff -u src/sys/dev/pci/pcidevs:1.1419 src/sys/dev/pci/pcidevs:1.1420
--- src/sys/dev/pci/pcidevs:1.1419	Tue Jul 14 16:56:35 2020
+++ src/sys/dev/pci/pcidevs	Thu Nov 19 21:59:07 2020
@@ -1,4 +1,4 @@
-$NetBSD: pcidevs,v 1.1419 2020/07/14 16:56:35 jdolecek Exp $
+$NetBSD: pcidevs,v 1.1420 2020/11/19 21:59:07 reinoud Exp $
 
 /*
  * Copyright (c) 1995, 1996 Christopher G. Demetriou
@@ -7141,11 +7141,11 @@ product QUMRANET VIRTIO_1001	0x1001	Virt
 product QUMRANET VIRTIO_1002	0x1002	Virtio Memory Balloon
 product QUMRANET VIRTIO_1003	0x1003	Virtio Console
 product QUMRANET VIRTIO_1004	0x1004	Virtio SCSI
-product QUMRANET VIRTIO_1005	0x1005	Virtio RNG
+product QUMRANET VIRTIO_1005	0x1005	Virtio RNG Entropy
 product QUMRANET VIRTIO_1006	0x1006	Virtio
 product QUMRANET VIRTIO_1007	0x1007	Virtio
 product QUMRANET VIRTIO_1008	0x1008	Virtio
-product QUMRANET VIRTIO_1009	0x1009	Virtio
+product QUMRANET VIRTIO_1009	0x1009	Virtio 9p Filesystem
 product QUMRANET VIRTIO_100A	0x100a	Virtio
 product QUMRANET VIRTIO_100B	0x100b	Virtio
 product QUMRANET VIRTIO_100C	0x100c	Virtio
@@ -7201,6 +7201,71 @@ product QUMRANET VIRTIO_103D	0x103d	Virt
 product QUMRANET VIRTIO_103E	0x103e	Virtio
 product QUMRANET VIRTIO_103F	0x103f	Virtio
 
+product QUMRANET VIRTIO_1040	0x1040	Virtio
+product QUMRANET VIRTIO_1041	0x1041	Virtio Network
+product QUMRANET VIRTIO_1042	0x1042	Virtio Storage
+product QUMRANET VIRTIO_1043	0x1043	Virtio Console
+product QUMRANET VIRTIO_1044	0x1044	Virtio RNG Entropy
+product QUMRANET VIRTIO_1045	0x1045	Virtio Memory Balloon
+product QUMRANET VIRTIO_1046	0x1046	Virtio I/O memory
+product QUMRANET VIRTIO_1047	0x1047	Virtio Remote Processor Messaging
+product QUMRANET VIRTIO_1048	0x1048	Virtio SCSI
+product QUMRANET VIRTIO_1049	0x1049	Virtio 9p Filesystem
+product QUMRANET VIRTIO_104A	0x104a	Virtio
+product QUMRANET VIRTIO_104B	0x104b	Virtio
+product QUMRANET VIRTIO_104C	0x104c	Virtio
+product QUMRANET VIRTIO_104D	0x104d	Virtio
+product QUMRANET VIRTIO_104E	0x104e	Virtio
+product QUMRANET VIRTIO_104F	0x104f	Virtio
+product QUMRANET VIRTIO_1050	0x1050	Virtio
+product QUMRANET VIRTIO_1051	0x1051	Virtio
+product QUMRANET VIRTIO_1052	0x1052	Virtio
+product QUMRANET VIRTIO_1053	0x1053	Virtio
+product QUMRANET VIRTIO_1054	0x1054	Virtio
+product QUMRANET VIRTIO_1055	0x1055	Virtio
+product QUMRANET VIRTIO_1056	0x1056	Virtio
+product QUMRANET VIRTIO_1057	0x1057	Virtio
+product QUMRANET VIRTIO_1058	0x1058	Virtio
+product QUMRANET VIRTIO_1059	0x1059	Virtio
+product QUMRANET VIRTIO_105A	0x105a	Virtio
+product QUMRANET VIRTIO_105B	0x105b	Virtio
+product QUMRANET VIRTIO_105C	0x105c	Virtio
+product QUMRANET VIRTIO_105D	0x105d	Virtio
+product QUMRANET VIRTIO_105E	0x105e	Virtio
+product QUMRANET VIRTIO_105F	0x105f	Virtio
+product QUMRANET VIRTIO_1060	0x1060	Virtio
+product QUMRANET VIRTIO_1061	0x1061	Virtio
+product QUMRANET VIRTIO_1062	0x1062	Virtio
+product QUMRANET VIRTIO_1063	0x1063	Virtio
+product QUMRANET VIRTIO_1064	0x1064	Virtio
+product QUMRANET VIRTIO_1065	0x1065	Virtio
+product QUMRANET VIRTIO_1066	0x1066	Virtio
+product QUMRANET VIRTIO_1067	0x1067	Virtio
+product QUMRANET VIRTIO_1068	0x1068	Virtio
+product QUMRANET VIRTIO_1069	0x1069	Virtio
+product QUMRANET VIRTIO_106A	0x106a	Virtio
+product QUMRANET VIRTIO_106B	0x106b	Virtio
+product QUMRANET VIRTIO_106C	0x106c	Virtio
+product QUMRANET VIRTIO_106D	0x106d	Virtio
+product QUMRANET VIRTIO_106E	0x106e	Virtio
+product QUMRANET VIRTIO_106F	0x106f	Virtio
+product QUMRANET VIRTIO_1070	0x1070	Virtio
+product QUMRANET VIRTIO_1071	0x1071	Virtio
+product QUMRANET VIRTIO_1072	0x1072	Virtio
+product QUMRANET VIRTIO_1073	0x1073	Virtio
+product QUMRANET VIRTIO_1074	0x1074	Virtio
+product QUMRANET VIRTIO_1075	0x1075	Virtio
+product QUMRANET VIRTIO_1076	0x1076	Virtio
+product QUMRANET VIRTIO_1077	0x1077	Virtio
+product QUMRANET VIRTIO_1078	0x1078	Virtio
+product QUMRANET VIRTIO_1079	0x1079	Virtio
+product QUMRANET VIRTIO_107A	0x107a	Virtio
+product QUMRANET VIRTIO_107B	0x107b	Virtio
+product QUMRANET VIRTIO_107C	0x107c	Virtio
+product QUMRANET VIRTIO_107D	0x107d	Virtio
+product QUMRANET VIRTIO_107E	0x107e	Virtio
+product QUMRANET VIRTIO_107F	0x107f	Virtio
+
 /* Rainbow Technologies products */
 product RAINBOW	CS200		0x0200	CryptoSwift 200 PKI Accelerator
 



CVS commit: src/usr.sbin/makefs

2020-11-10 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Nov 10 20:48:29 UTC 2020

Modified Files:
src/usr.sbin/makefs: cd9660.c

Log Message:
rock_ridge_move_count is only incremented and can never be negative so change
%08i to %08u.
This removes a warning when compiling with tools outside ./build.sh


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/usr.sbin/makefs/cd9660.c

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

Modified files:

Index: src/usr.sbin/makefs/cd9660.c
diff -u src/usr.sbin/makefs/cd9660.c:1.56 src/usr.sbin/makefs/cd9660.c:1.57
--- src/usr.sbin/makefs/cd9660.c:1.56	Fri Oct 18 04:09:02 2019
+++ src/usr.sbin/makefs/cd9660.c	Tue Nov 10 20:48:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660.c,v 1.56 2019/10/18 04:09:02 msaitoh Exp $	*/
+/*	$NetBSD: cd9660.c,v 1.57 2020/11/10 20:48:29 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -103,7 +103,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660.c,v 1.56 2019/10/18 04:09:02 msaitoh Exp $");
+__RCSID("$NetBSD: cd9660.c,v 1.57 2020/11/10 20:48:29 reinoud Exp $");
 #endif  /* !__lint */
 
 #include 
@@ -1295,7 +1295,7 @@ cd9660_rrip_move_directory(iso9660_disk 
 		return NULL;
 
 	diskStructure->rock_ridge_move_count++;
-	snprintf(newname, sizeof(newname), "%08i",
+	snprintf(newname, sizeof(newname), "%08u",
 	diskStructure->rock_ridge_move_count);
 
 	/* Point to old parent */



CVS commit: src/lib/libnvmm

2020-10-31 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Oct 31 15:44:01 UTC 2020

Modified Files:
src/lib/libnvmm: libnvmm_x86.c

Log Message:
Revert (REPE) CMPS support per request of Maxime, it is incorrect.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/lib/libnvmm/libnvmm_x86.c

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

Modified files:

Index: src/lib/libnvmm/libnvmm_x86.c
diff -u src/lib/libnvmm/libnvmm_x86.c:1.41 src/lib/libnvmm/libnvmm_x86.c:1.42
--- src/lib/libnvmm/libnvmm_x86.c:1.41	Fri Oct 30 21:06:13 2020
+++ src/lib/libnvmm/libnvmm_x86.c	Sat Oct 31 15:44:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: libnvmm_x86.c,v 1.41 2020/10/30 21:06:13 reinoud Exp $	*/
+/*	$NetBSD: libnvmm_x86.c,v 1.42 2020/10/31 15:44:01 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -1051,7 +1051,6 @@ struct x86_opcode {
 	bool movs:1;
 	bool stos:1;
 	bool lods:1;
-	bool cmps:1;
 	bool szoverride:1;
 	bool group1:1;
 	bool group3:1;
@@ -1464,26 +1463,6 @@ static const struct x86_opcode primary_o
 	},
 
 	/*
-	 * CMPS
-	 */
-	[0xA6] = {
-		/* Yb, Xb */
-		.valid = true,
-		.cmps = true,
-		.szoverride = false,
-		.defsize = OPSIZE_BYTE,
-		.emul = _emul_cmp
-	},
-	[0xA7] = {
-		/* Yv, Xv */
-		.valid = true,
-		.cmps = true,
-		.szoverride = true,
-		.defsize = -1,
-		.emul = _emul_cmp
-	},
-
-	/*
 	 * STOS
 	 */
 	[0xAA] = {
@@ -1892,35 +1871,6 @@ node_movs(struct x86_decode_fsm *fsm, st
 }
 
 /*
- * Special node, for CMPS. Fake two displacements of zero on the source and
- * destination registers.
- * XXX coded as clone of movs as its similar in register usage
- * XXX might be merged with node_movs()
- */
-static int
-node_cmps(struct x86_decode_fsm *fsm, struct x86_instr *instr)
-{
-	size_t adrsize;
-
-	adrsize = instr->address_size;
-
-	/* DS:RSI */
-	instr->src.type = STORE_REG;
-	instr->src.u.reg = _map__special[1][2][adrsize-1];
-	instr->src.disp.type = DISP_0;
-
-	/* ES:RDI, force ES */
-	instr->dst.type = STORE_REG;
-	instr->dst.u.reg = _map__special[1][3][adrsize-1];
-	instr->dst.disp.type = DISP_0;
-	instr->dst.hardseg = NVMM_X64_SEG_ES;
-
-	fsm_advance(fsm, 0, NULL);
-
-	return 0;
-}
-
-/*
  * Special node, for STOS and LODS. Fake a displacement of zero on the
  * destination register.
  */
@@ -2520,8 +2470,6 @@ node_primary_opcode(struct x86_decode_fs
 		fsm_advance(fsm, 1, node_stlo);
 	} else if (opcode->movs) {
 		fsm_advance(fsm, 1, node_movs);
-	} else if (opcode->cmps) {
-		fsm_advance(fsm, 1, node_cmps);
 	} else {
 		return -1;
 	}
@@ -2698,16 +2646,8 @@ x86_decode(uint8_t *inst_bytes, size_t i
 
 	while (fsm.fn != NULL) {
 		ret = (*fsm.fn)(, instr);
-		if (ret == -1) {
-			printf("\nNVMM: %s missing support for instruction " \
-			   "with max length %ld : [ ", __func__,
-			   inst_len);
-			for (uint i = 0; i < inst_len; i++)
-printf("%02x ", inst_bytes[i]);
-			printf("], please report to NetBSD!\n\n");
-			fflush(stdout);
+		if (ret == -1)
 			return -1;
-		}
 	}
 
 	instr->len = fsm.buf - inst_bytes;



CVS commit: src/lib/libnvmm

2020-10-30 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Oct 30 21:06:13 UTC 2020

Modified Files:
src/lib/libnvmm: libnvmm_x86.c

Log Message:
Implement missing (REPE) CMPS instruction support in NVMMs x86_decode().

In apparently rare cases the (REPE) CMPS instruction can trigger an memory
assist. NVMM wouldn't recognize the instruction and thus couldn't assist and
Qemu would abort.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/lib/libnvmm/libnvmm_x86.c

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

Modified files:

Index: src/lib/libnvmm/libnvmm_x86.c
diff -u src/lib/libnvmm/libnvmm_x86.c:1.40 src/lib/libnvmm/libnvmm_x86.c:1.41
--- src/lib/libnvmm/libnvmm_x86.c:1.40	Sat Sep  5 07:22:25 2020
+++ src/lib/libnvmm/libnvmm_x86.c	Fri Oct 30 21:06:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: libnvmm_x86.c,v 1.40 2020/09/05 07:22:25 maxv Exp $	*/
+/*	$NetBSD: libnvmm_x86.c,v 1.41 2020/10/30 21:06:13 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -1051,6 +1051,7 @@ struct x86_opcode {
 	bool movs:1;
 	bool stos:1;
 	bool lods:1;
+	bool cmps:1;
 	bool szoverride:1;
 	bool group1:1;
 	bool group3:1;
@@ -1463,6 +1464,26 @@ static const struct x86_opcode primary_o
 	},
 
 	/*
+	 * CMPS
+	 */
+	[0xA6] = {
+		/* Yb, Xb */
+		.valid = true,
+		.cmps = true,
+		.szoverride = false,
+		.defsize = OPSIZE_BYTE,
+		.emul = _emul_cmp
+	},
+	[0xA7] = {
+		/* Yv, Xv */
+		.valid = true,
+		.cmps = true,
+		.szoverride = true,
+		.defsize = -1,
+		.emul = _emul_cmp
+	},
+
+	/*
 	 * STOS
 	 */
 	[0xAA] = {
@@ -1871,6 +1892,35 @@ node_movs(struct x86_decode_fsm *fsm, st
 }
 
 /*
+ * Special node, for CMPS. Fake two displacements of zero on the source and
+ * destination registers.
+ * XXX coded as clone of movs as its similar in register usage
+ * XXX might be merged with node_movs()
+ */
+static int
+node_cmps(struct x86_decode_fsm *fsm, struct x86_instr *instr)
+{
+	size_t adrsize;
+
+	adrsize = instr->address_size;
+
+	/* DS:RSI */
+	instr->src.type = STORE_REG;
+	instr->src.u.reg = _map__special[1][2][adrsize-1];
+	instr->src.disp.type = DISP_0;
+
+	/* ES:RDI, force ES */
+	instr->dst.type = STORE_REG;
+	instr->dst.u.reg = _map__special[1][3][adrsize-1];
+	instr->dst.disp.type = DISP_0;
+	instr->dst.hardseg = NVMM_X64_SEG_ES;
+
+	fsm_advance(fsm, 0, NULL);
+
+	return 0;
+}
+
+/*
  * Special node, for STOS and LODS. Fake a displacement of zero on the
  * destination register.
  */
@@ -2470,6 +2520,8 @@ node_primary_opcode(struct x86_decode_fs
 		fsm_advance(fsm, 1, node_stlo);
 	} else if (opcode->movs) {
 		fsm_advance(fsm, 1, node_movs);
+	} else if (opcode->cmps) {
+		fsm_advance(fsm, 1, node_cmps);
 	} else {
 		return -1;
 	}
@@ -2646,8 +2698,16 @@ x86_decode(uint8_t *inst_bytes, size_t i
 
 	while (fsm.fn != NULL) {
 		ret = (*fsm.fn)(, instr);
-		if (ret == -1)
+		if (ret == -1) {
+			printf("\nNVMM: %s missing support for instruction " \
+			   "with max length %ld : [ ", __func__,
+			   inst_len);
+			for (uint i = 0; i < inst_len; i++)
+printf("%02x ", inst_bytes[i]);
+			printf("], please report to NetBSD!\n\n");
+			fflush(stdout);
 			return -1;
+		}
 	}
 
 	instr->len = fsm.buf - inst_bytes;



CVS commit: src/usr.sbin/makefs

2020-04-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Apr 18 09:45:45 UTC 2020

Modified Files:
src/usr.sbin/makefs: udf.c

Log Message:
Believe the datablocks predictor when determining if data on a node gets
stored internal or not. Also make a note that the datablocks predictor takes
NO extended attributes stored in the node into account

In rare cases it could lead to confusion where the predictor would say it
wouldn't fit internally when it could just have fitted. This would trigger the
assertion. Now it will on rare accasions create a datablock even though it
might have fitted.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/makefs/udf.c

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

Modified files:

Index: src/usr.sbin/makefs/udf.c
diff -u src/usr.sbin/makefs/udf.c:1.19 src/usr.sbin/makefs/udf.c:1.20
--- src/usr.sbin/makefs/udf.c:1.19	Sun Feb  3 03:19:31 2019
+++ src/usr.sbin/makefs/udf.c	Sat Apr 18 09:45:45 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: udf.c,v 1.19 2019/02/03 03:19:31 mrg Exp $ */
+/* $NetBSD: udf.c,v 1.20 2020/04/18 09:45:45 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008, 2013 Reinoud Zandijk
@@ -30,7 +30,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: udf.c,v 1.19 2019/02/03 03:19:31 mrg Exp $");
+__RCSID("$NetBSD: udf.c,v 1.20 2020/04/18 09:45:45 reinoud Exp $");
 
 #include 
 #include 
@@ -514,6 +514,7 @@ static uint32_t
 udf_datablocks(off_t sz)
 {
 	/* predictor if it can be written inside the node */
+	/* XXX the predictor assumes NO extended attributes in the node */
 	if (sz < context.sector_size - UDF_EXTFENTRY_SIZE - 16)
 		return 0;
 
@@ -561,7 +562,7 @@ udf_file_inject_blob(union dscrptr *dscr
 	struct extfile_entry *efe;
 	uint64_t inf_len, obj_size;
 	uint32_t l_ea, l_ad;
-	uint32_t free_space, desc_size;
+	uint32_t desc_size;
 	uint16_t crclen;
 	uint8_t *data, *pos;
 
@@ -590,10 +591,9 @@ udf_file_inject_blob(union dscrptr *dscr
 	}
 	crclen = udf_rw16(dscr->tag.desc_crc_len);
 
-	/* calculate free space */
-	free_space = context.sector_size - (l_ea + l_ad) - desc_size;
+	/* check if it will fit internally */
 	if (udf_datablocks(size)) {
-		assert(free_space < size);
+		/* the predictor tells it won't fit internally */
 		return 1;
 	}
 
@@ -602,7 +602,6 @@ udf_file_inject_blob(union dscrptr *dscr
 	assert((udf_rw16(icb->flags) & UDF_ICB_TAG_FLAGS_ALLOC_MASK) ==
 			UDF_ICB_INTERN_ALLOC);
 
-	// assert(free_space >= size);
 	pos = data + l_ea + l_ad;
 	memcpy(pos, blob, size);
 	l_ad   += size;



CVS commit: src/sys/fs/udf

2020-04-14 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Apr 14 12:47:44 UTC 2020

Modified Files:
src/sys/fs/udf: udf_vfsops.c

Log Message:
Move comment related to the sysctl_createv() in SYSCTL_SETUP() from the old
place to the new place too.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/fs/udf/udf_vfsops.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/fs/udf/udf_vfsops.c
diff -u src/sys/fs/udf/udf_vfsops.c:1.79 src/sys/fs/udf/udf_vfsops.c:1.80
--- src/sys/fs/udf/udf_vfsops.c:1.79	Mon Apr 13 19:23:18 2020
+++ src/sys/fs/udf/udf_vfsops.c	Tue Apr 14 12:47:44 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_vfsops.c,v 1.79 2020/04/13 19:23:18 ad Exp $ */
+/* $NetBSD: udf_vfsops.c,v 1.80 2020/04/14 12:47:44 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.79 2020/04/13 19:23:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.80 2020/04/14 12:47:44 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -167,6 +167,11 @@ udf_done(void)
  */
 #define UDF_VERBOSE_SYSCTLOPT1
 
+/*
+ * XXX the "24" below could be dynamic, thereby eliminating one
+ * more instance of the "number to vfs" mapping problem, but
+ * "24" is the order as taken from sys/mount.h
+ */
 SYSCTL_SETUP(udf_sysctl_setup, "udf sysctl")
 {
 	const struct sysctlnode *node;
@@ -197,11 +202,6 @@ udf_modcmd(modcmd_t cmd, void *arg)
 		error = vfs_attach(_vfsops);
 		if (error != 0)
 			break;
-		/*
-		 * XXX the "24" below could be dynamic, thereby eliminating one
-		 * more instance of the "number to vfs" mapping problem, but
-		 * "24" is the order as taken from sys/mount.h
-		 */
 		break;
 	case MODULE_CMD_FINI:
 		error = vfs_detach(_vfsops);



CVS commit: src/sys/fs/udf

2020-04-14 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Apr 14 11:45:43 UTC 2020

Modified Files:
src/sys/fs/udf: udf_vnops.c

Log Message:
fix debug print flag


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/fs/udf/udf_vnops.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/fs/udf/udf_vnops.c
diff -u src/sys/fs/udf/udf_vnops.c:1.110 src/sys/fs/udf/udf_vnops.c:1.111
--- src/sys/fs/udf/udf_vnops.c:1.110	Mon Apr 13 19:23:18 2020
+++ src/sys/fs/udf/udf_vnops.c	Tue Apr 14 11:45:42 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_vnops.c,v 1.110 2020/04/13 19:23:18 ad Exp $ */
+/* $NetBSD: udf_vnops.c,v 1.111 2020/04/14 11:45:42 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -32,7 +32,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.110 2020/04/13 19:23:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.111 2020/04/14 11:45:42 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -1992,7 +1992,7 @@ udf_rmdir(void *v)
 	struct udf_mount *ump = dir_node->ump;
 	int error, isempty;
 
-	DPRINTF(NOTIMPL, ("udf_rmdir '%s' called\n", cnp->cn_nameptr));
+	DPRINTF(CALL, ("udf_rmdir '%s' called\n", cnp->cn_nameptr));
 
 	/* don't allow '.' to be deleted */
 	if (dir_node == udf_node) {



CVS commit: src/usr.sbin/makefs

2020-04-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Apr  4 13:44:57 UTC 2020

Modified Files:
src/usr.sbin/makefs: makefs.8

Log Message:
Indent the makefs(8) options for UDF like the other filesystems described.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/usr.sbin/makefs/makefs.8

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

Modified files:

Index: src/usr.sbin/makefs/makefs.8
diff -u src/usr.sbin/makefs/makefs.8:1.64 src/usr.sbin/makefs/makefs.8:1.65
--- src/usr.sbin/makefs/makefs.8:1.64	Wed Nov  6 21:04:22 2019
+++ src/usr.sbin/makefs/makefs.8	Sat Apr  4 13:44:57 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: makefs.8,v 1.64 2019/11/06 21:04:22 christos Exp $
+.\"	$NetBSD: makefs.8,v 1.65 2020/04/04 13:44:57 reinoud Exp $
 .\"
 .\" Copyright (c) 2001-2003 Wasabi Systems, Inc.
 .\" All rights reserved.
@@ -489,7 +489,7 @@ Each of the options consists of a keywor
 and a value.
 The following keywords are supported:
 .Pp
-.Bl -tag -width optimization -compact
+.Bl -tag -width optimization -offset indent -compact
 .It Sy disctype
 This can have the following values:
 .Bl -tag -width cdromXdvdromXbdromXXX -compact



CVS commit: src/sys/fs/nilfs

2020-03-21 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Mar 21 13:39:31 UTC 2020

Modified Files:
src/sys/fs/nilfs: nilfs_subr.c

Log Message:
Fix use-after-free issue!


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/fs/nilfs/nilfs_subr.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/fs/nilfs/nilfs_subr.c
diff -u src/sys/fs/nilfs/nilfs_subr.c:1.14 src/sys/fs/nilfs/nilfs_subr.c:1.15
--- src/sys/fs/nilfs/nilfs_subr.c:1.14	Sun Mar 29 14:12:28 2015
+++ src/sys/fs/nilfs/nilfs_subr.c	Sat Mar 21 13:39:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: nilfs_subr.c,v 1.14 2015/03/29 14:12:28 riastradh Exp $ */
+/* $NetBSD: nilfs_subr.c,v 1.15 2020/03/21 13:39:31 reinoud Exp $ */
 
 /*
  * Copyright (c) 2008, 2009 Reinoud Zandijk
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: nilfs_subr.c,v 1.14 2015/03/29 14:12:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nilfs_subr.c,v 1.15 2020/03/21 13:39:31 reinoud Exp $");
 #endif /* not lint */
 
 #include 
@@ -230,6 +230,7 @@ nilfs_btree_lookup_level(struct nilfs_no
 	dptrs = dkeys + NILFS_BTREE_NODE_NCHILDREN_MAX(nilfsdev->blocksize);
 
 	assert((btree_hdr->bn_flags & NILFS_BTREE_NODE_ROOT) == 0);
+	assert((btree_hdr->bn_level == level));
 
 	/* select matching child XXX could use binary search */
 	selected = 0;
@@ -253,7 +254,7 @@ nilfs_btree_lookup_level(struct nilfs_no
 	brelse(bp, BC_AGE);
 
 	return nilfs_btree_lookup_level(node, lblocknr,
-			child_btree_blk, btree_hdr->bn_level-1, vblocknr);
+			child_btree_blk, level-1, vblocknr);
 }
 
 
@@ -686,9 +687,10 @@ nilfs_get_node_raw(struct nilfs_device *
 
 	/* fixup inode size for system nodes */
 	if ((ino < NILFS_USER_INO) && (ino != NILFS_ROOT_INO)) {
-		DPRINTF(VOLUMES, ("NEED TO GET my size for inode %"PRIu64"\n",
+		DPRINTF(VOLUMES, ("NEED TO GET my size for inode %"PRIu64"?\n",
 			ino));
 		/* for now set it to maximum, -1 is illegal */
+		DPRINTF(VOLUMES, ("  current size of inode is %"PRIu64"\n", inode->i_size));
 		inode->i_size = nilfs_rw64(((uint64_t) -2));
 	}
 



CVS commit: src/sys/fs/nilfs

2020-03-21 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Mar 21 13:38:29 UTC 2020

Modified Files:
src/sys/fs/nilfs: nilfs.h

Log Message:
Compile in the DPRINTF debug macro's on DEBUG kernels


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/fs/nilfs/nilfs.h

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

Modified files:

Index: src/sys/fs/nilfs/nilfs.h
diff -u src/sys/fs/nilfs/nilfs.h:1.5 src/sys/fs/nilfs/nilfs.h:1.6
--- src/sys/fs/nilfs/nilfs.h:1.5	Wed Oct 15 09:05:46 2014
+++ src/sys/fs/nilfs/nilfs.h	Sat Mar 21 13:38:29 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: nilfs.h,v 1.5 2014/10/15 09:05:46 hannken Exp $ */
+/* $NetBSD: nilfs.h,v 1.6 2020/03/21 13:38:29 reinoud Exp $ */
 
 /*
  * Copyright (c) 2008, 2009 Reinoud Zandijk
@@ -66,7 +66,7 @@ extern int nilfs_verbose;
 /* initial value of nilfs_verbose */
 #define NILFS_DEBUGGING		0
 
-#ifdef NILFS_DEBUG
+#ifdef DEBUG
 #define DPRINTF(name, arg) { \
 		if (nilfs_verbose & NILFS_DEBUG_##name) {\
 			printf arg;\



CVS commit: src/sys/arch/usermode/conf

2018-08-17 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Aug 17 20:16:07 UTC 2018

Modified Files:
src/sys/arch/usermode/conf: Makefile.usermode kern.ldscript

Log Message:
Start using the kernel ld script.

There are still issues with the .init placement and ./build.sh creating bad
images.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/usermode/conf/Makefile.usermode
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/usermode/conf/kern.ldscript

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/usermode/conf/Makefile.usermode
diff -u src/sys/arch/usermode/conf/Makefile.usermode:1.42 src/sys/arch/usermode/conf/Makefile.usermode:1.43
--- src/sys/arch/usermode/conf/Makefile.usermode:1.42	Fri Jun  1 07:22:33 2018
+++ src/sys/arch/usermode/conf/Makefile.usermode	Fri Aug 17 20:16:07 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.usermode,v 1.42 2018/06/01 07:22:33 reinoud Exp $
+# $NetBSD: Makefile.usermode,v 1.43 2018/08/17 20:16:07 reinoud Exp $
 
 MKCTF?=no
 USETOOLS?=			no
@@ -74,9 +74,9 @@ KERNLDSCRIPT?=	${USERMODE}/conf/kern.lds
 SYSTEM_LD=	@do_system_ld() { \
 		${_MKSHMSG} "   link  ${.CURDIR:T}/${.TARGET}"; \
 		${_MKSHECHO}\
-		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o ${.TARGET} ${LINKFORMAT} -Ttext ${TEXTADDR} '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o ${USERMODE_LIBS} $$@; \
+		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o ${.TARGET} ${LINKFORMAT} -Wl,-Ttext,${TEXTADDR} '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o netbsd.ldscript ${USERMODE_LIBS} $$@; \
 		${SYSTEM_LD_FIX} \
-		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o ${.TARGET} ${LINKFORMAT} -Ttext ${TEXTADDR} ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o ${USERMODE_LIBS} $$@; \
+		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o ${.TARGET} ${LINKFORMAT} -Wl,-Ttext,${TEXTADDR} ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o netbsd.ldscript ${USERMODE_LIBS} $$@; \
 		}; \
 		do_system_ld
 NVFLAGS=	-n

Index: src/sys/arch/usermode/conf/kern.ldscript
diff -u src/sys/arch/usermode/conf/kern.ldscript:1.1 src/sys/arch/usermode/conf/kern.ldscript:1.2
--- src/sys/arch/usermode/conf/kern.ldscript:1.1	Fri May 18 19:04:10 2018
+++ src/sys/arch/usermode/conf/kern.ldscript	Fri Aug 17 20:16:07 2018
@@ -1,20 +1,28 @@
-/*	$NetBSD: kern.ldscript,v 1.1 2018/05/18 19:04:10 reinoud Exp $	*/
+/*	$NetBSD: kern.ldscript,v 1.2 2018/08/17 20:16:07 reinoud Exp $	*/
 
 #include "assym.h"
 
+__PAGE_SIZE = 0x1000 ;
+
 ENTRY(_start)
 SECTIONS
 {
 	/* Read-only sections, merged into text segment: */
 	.text :
 	{
+		. = ALIGN(__PAGE_SIZE);
+		*(.text.user)
+		. = ALIGN(__PAGE_SIZE);
 		*(.text)
 		*(.text.*)
 		*(.stub)
-	}
+		. = ALIGN(__PAGE_SIZE);
+	} =0xCC
+
 	_etext = . ;
 	PROVIDE (etext = .) ;
 
+	. = ALIGN(__PAGE_SIZE);
 	.rodata :
 	{
 		*(.rodata)
@@ -25,7 +33,7 @@ SECTIONS
 	 * Adjust the address for the data segment.  We want to adjust up to
 	 * the same address within the page on the next page up.
 	 */
-	. = ALIGN(0x10) + (. & (0x10 - 1));
+	. = ALIGN(__PAGE_SIZE);
 	__data_start = . ;
 	.data :
 	{
@@ -52,22 +60,17 @@ SECTIONS
 		*(.bss)
 		*(.bss.*)
 		*(COMMON)
-		. = ALIGN(64 / 8);
 	}
-	. = ALIGN(64 / 8);
+
+	. = ALIGN(__PAGE_SIZE);
 	_end = . ;
 	PROVIDE (end = .) ;
-	.note.netbsd.ident :
-	{
-		KEEP(*(.note.netbsd.ident));
-	}
-}
 
-SECTIONS
-{
-	.text :
-	AT (ADDR(.text) & 0x0fff)
-	{
-		*(.text)
-	} = 0
+	/*
+	 * .note.netbsd.ident :
+	 * {
+	 * 	KEEP(*(.note.netbsd.ident));
+	 * }
+	 */
 }
+



CVS commit: src/sys/fs/udf

2018-08-09 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu Aug  9 20:30:26 UTC 2018

Modified Files:
src/sys/fs/udf: udf_subr.c

Log Message:
Fix length calculation


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/sys/fs/udf/udf_subr.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/fs/udf/udf_subr.c
diff -u src/sys/fs/udf/udf_subr.c:1.142 src/sys/fs/udf/udf_subr.c:1.143
--- src/sys/fs/udf/udf_subr.c:1.142	Wed Jul 25 11:09:22 2018
+++ src/sys/fs/udf/udf_subr.c	Thu Aug  9 20:30:26 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_subr.c,v 1.142 2018/07/25 11:09:22 reinoud Exp $ */
+/* $NetBSD: udf_subr.c,v 1.143 2018/08/09 20:30:26 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -29,7 +29,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.142 2018/07/25 11:09:22 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.143 2018/08/09 20:30:26 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -2623,7 +2623,7 @@ udf_update_lvid_from_vat_extattr(struct 
 		return error;
 
 	/* paranoia */
-	if (a_l != sizeof(*implext) -1 + udf_rw32(implext->iu_l) + sizeof(lvext)) {
+	if (a_l != sizeof(*implext) -2 + udf_rw32(implext->iu_l) + sizeof(lvext)) {
 		DPRINTF(VOLUMES, ("VAT LVExtension size doesn't compute\n"));
 		return EINVAL;
 	}



CVS commit: src/sys/fs/udf

2018-08-09 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu Aug  9 13:49:30 UTC 2018

Modified Files:
src/sys/fs/udf: ecma167-udf.h

Log Message:
Sync with UDFclient


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/fs/udf/ecma167-udf.h

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

Modified files:

Index: src/sys/fs/udf/ecma167-udf.h
diff -u src/sys/fs/udf/ecma167-udf.h:1.15 src/sys/fs/udf/ecma167-udf.h:1.16
--- src/sys/fs/udf/ecma167-udf.h:1.15	Wed Jul 25 19:56:56 2018
+++ src/sys/fs/udf/ecma167-udf.h	Thu Aug  9 13:49:30 2018
@@ -1,8 +1,8 @@
-/* $NetBSD: ecma167-udf.h,v 1.15 2018/07/25 19:56:56 kamil Exp $ */
+/* $NetBSD: ecma167-udf.h,v 1.16 2018/08/09 13:49:30 reinoud Exp $ */
 
 /*-
- * Copyright (c) 2003, 2004, 2005, 2006, 2008, 2009
- * 	Reinoud Zandijk * 
+ * Copyright (c) 2003, 2004, 2005, 2006, 2008, 2009, 2017, 2018
+ * 	Reinoud Zandijk 
  * Copyright (c) 2001, 2002 Scott Long 
  * All rights reserved.
  *
@@ -264,7 +264,10 @@ struct regid {
 struct icb_tag {
 	uint32_t	prev_num_dirs;
 	uint16_t	strat_type;
-	uint8_t		strat_param[2];
+	union {
+		uint8_t	 strat_param[2];
+		uint16_t strat_param16;
+	};
 	uint16_t	max_num_entries;
 	uint8_t		reserved;
 	uint8_t		file_type;
@@ -682,7 +685,10 @@ struct impl_extattr_entry {
 	struct extattr_entryhdr;
 	uint32_t		iu_l;
 	struct regid		imp_id;
-	uint8_t			data[1];
+	union {
+		uint8_t	 data[1];
+		uint16_t data16;
+	};
 } __packed;
 
 



CVS commit: src/sys/arch/usermode/usermode

2018-08-05 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Aug  5 18:57:49 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: db_memrw.c

Log Message:
Advise to explicitly set flags +agm instead of only clearing them when set


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/usermode/usermode/db_memrw.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/usermode/usermode/db_memrw.c
diff -u src/sys/arch/usermode/usermode/db_memrw.c:1.3 src/sys/arch/usermode/usermode/db_memrw.c:1.4
--- src/sys/arch/usermode/usermode/db_memrw.c:1.3	Fri Aug  3 11:18:22 2018
+++ src/sys/arch/usermode/usermode/db_memrw.c	Sun Aug  5 18:57:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.3 2018/08/03 11:18:22 reinoud Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.4 2018/08/05 18:57:49 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.3 2018/08/03 11:18:22 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.4 2018/08/05 18:57:49 reinoud Exp $");
 
 #include 
 #include 
@@ -226,14 +226,14 @@ db_write_bytes(vaddr_t addr, size_t size
 	/*
 	 * if we are in the kernel range, just allow writing by using
 	 * mprotect(); Note that this needs an unprotected binary, set with
-	 * `paxctl -agm netbsd`
+	 * `paxctl +agm netbsd`
 	 */
 	if (addr > kmem_k_start) {
 		ret = thunk_mprotect((void *) trunc_page(addr), PAGE_SIZE,
 			PROT_READ | PROT_WRITE | PROT_EXEC);
 		if (ret != 0)
 			panic("please unprotect kernel binary with "
-			  "`paxctl -agm netbsd`");
+			  "`paxctl +agm netbsd`");
 		assert(ret == 0);
 	}
 



CVS commit: src/sys/arch/usermode

2018-08-05 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Aug  5 18:42:49 UTC 2018

Modified Files:
src/sys/arch/usermode/include: db_machdep.h ucontext.h
src/sys/arch/usermode/usermode: cpufunc.S kgdb_machdep.c

Log Message:
Add KGDB definitions for i386


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/usermode/include/db_machdep.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/usermode/include/ucontext.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/usermode/usermode/cpufunc.S
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/usermode/usermode/kgdb_machdep.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/usermode/include/db_machdep.h
diff -u src/sys/arch/usermode/include/db_machdep.h:1.3 src/sys/arch/usermode/include/db_machdep.h:1.4
--- src/sys/arch/usermode/include/db_machdep.h:1.3	Wed Aug  1 09:50:57 2018
+++ src/sys/arch/usermode/include/db_machdep.h	Sun Aug  5 18:42:48 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: db_machdep.h,v 1.3 2018/08/01 09:50:57 reinoud Exp $ */
+/* $NetBSD: db_machdep.h,v 1.4 2018/08/05 18:42:48 reinoud Exp $ */
 
 #ifndef _USERMODE_DB_MACHDEP_H
 #define _USERMODE_DB_MACHDEP_H
@@ -27,6 +27,7 @@ extern db_regs_t *ddb_regp;
 #define ddb_regs	(*ddb_regp)
 #endif
 
+/* copied here in verbatim to remove dependencies */
 #if defined(__i386__)
 
 #define BKPT_SIZE 1
@@ -34,8 +35,30 @@ extern db_regs_t *ddb_regp;
 #define	BKPT_ADDR(addr)	(addr)
 #define BKPT_SET(inst, addr) (BKPT_INST)
 
-#error append db_machdep.h for i386
+#define	db_clear_single_step(regs)	_UC_MACHINE_EFLAGS(regs) &= ~PSL_T
+#define	db_set_single_step(regs)	_UC_MACHINE_EFLAGS(regs) |= PSL_T
 
+#define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BPTFLT)
+#define IS_WATCHPOINT_TRAP(type, code)	((type) == T_TRCTRAP && (code) & 15)
+
+#define	I_CALL		0xe8
+#define	I_CALLI		0xff
+#define	I_RET		0xc3
+#define	I_IRET		0xcf
+
+#define	inst_trap_return(ins)	(((ins)&0xff) == I_IRET)
+#define	inst_return(ins)	(((ins)&0xff) == I_RET)
+#define	inst_call(ins)		(((ins)&0xff) == I_CALL || \
+ (((ins)&0xff) == I_CALLI && \
+  ((ins)&0x3800) == 0x1000))
+#define inst_load(ins)		0
+#define inst_store(ins)		0
+
+typedef	int		kgdb_reg_t;
+#define	KGDB_NUMREGS	16
+#define	KGDB_BUFLEN	512
+
+/* copied here in verbatim to remove dependencies */
 #elif defined(__x86_64__)
 
 #define	DDB_EXPR_FMT	"l"	/* expression is long */

Index: src/sys/arch/usermode/include/ucontext.h
diff -u src/sys/arch/usermode/include/ucontext.h:1.1 src/sys/arch/usermode/include/ucontext.h:1.2
--- src/sys/arch/usermode/include/ucontext.h:1.1	Wed Aug  1 09:52:15 2018
+++ src/sys/arch/usermode/include/ucontext.h	Sun Aug  5 18:42:48 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ucontext.h,v 1.1 2018/08/01 09:52:15 reinoud Exp $ */
+/* $NetBSD: ucontext.h,v 1.2 2018/08/05 18:42:48 reinoud Exp $ */
 
 #ifndef _USERMODE_UCONTEXT_H
 #define _USERMODE_UCONTEXT_H
@@ -9,6 +9,8 @@
 
 #if defined(__i386__)
 
+#define _UC_MACHINE_EFLAGS(uc) ((uc)->uc_mcontext.__gregs[_REG_EFL])
+
 #elif defined(__x86_64__)
 
 #define _UC_MACHINE_RFLAGS(uc) ((uc)->uc_mcontext.__gregs[26])

Index: src/sys/arch/usermode/usermode/cpufunc.S
diff -u src/sys/arch/usermode/usermode/cpufunc.S:1.1 src/sys/arch/usermode/usermode/cpufunc.S:1.2
--- src/sys/arch/usermode/usermode/cpufunc.S:1.1	Wed Aug  1 10:22:20 2018
+++ src/sys/arch/usermode/usermode/cpufunc.S	Sun Aug  5 18:42:48 2018
@@ -5,10 +5,14 @@
 #if defined(__i386__)
 
 ENTRY(breakpoint)
-	.byte 0xcc	// BKPT_INST
+	pushl	%ebp
+	movl	%esp, %ebp
+	int	$0x03		/* paranoid, not 'int3' */
+	popl	%ebp
 	ret
+END(breakpoint)
 
-#error implement setjmp/longjmp for i386
+//#error TODO implement setjmp/longjmp for i386?
 
 #elif defined(__amd64__)
 ENTRY(breakpoint)

Index: src/sys/arch/usermode/usermode/kgdb_machdep.c
diff -u src/sys/arch/usermode/usermode/kgdb_machdep.c:1.3 src/sys/arch/usermode/usermode/kgdb_machdep.c:1.4
--- src/sys/arch/usermode/usermode/kgdb_machdep.c:1.3	Wed Aug  1 10:24:41 2018
+++ src/sys/arch/usermode/usermode/kgdb_machdep.c	Sun Aug  5 18:42:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kgdb_machdep.c,v 1.3 2018/08/01 10:24:41 reinoud Exp $	*/
+/*	$NetBSD: kgdb_machdep.c,v 1.4 2018/08/05 18:42:48 reinoud Exp $	*/
 
 /*
  * Copyright (c) 1996 Matthias Pfaller.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.3 2018/08/01 10:24:41 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.4 2018/08/05 18:42:48 reinoud Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -127,34 +127,25 @@ kgdb_getregs(db_regs_t *regs, kgdb_reg_t
 	gdb_regs[19] = gregs[_REG_SS];
 		
 #elif defined(__i386)
-	gdb_regs[ 0] = regs->tf_eax;
-	gdb_regs[ 1] = regs->tf_ecx;
-	gdb_regs[ 2] = regs->tf_edx;
-	gdb_regs[ 3] = regs->tf_ebx;
-	gdb_regs[ 4] = regs->tf_esp;
-	gdb_regs[ 5] = regs->tf_ebp;
-	gdb_regs[ 6] = regs->tf_esi;
-	gdb_regs[ 7] = regs->tf_edi;
-	gdb_regs[ 8] = regs->tf_eip;
-	gdb_regs[ 9] = 

CVS commit: src/sys/arch/usermode/usermode

2018-08-05 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Aug  5 16:51:59 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: pmap.c

Log Message:
To avoid possible collisions between the NetBSD/userland kernel and possible
host kernel memory allocation schemes, allocate two dedicated pages for page
copying and page zeroing.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/usermode/usermode/pmap.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/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.112 src/sys/arch/usermode/usermode/pmap.c:1.113
--- src/sys/arch/usermode/usermode/pmap.c:1.112	Fri Aug  3 11:18:22 2018
+++ src/sys/arch/usermode/usermode/pmap.c	Sun Aug  5 16:51:59 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.112 2018/08/03 11:18:22 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.113 2018/08/05 16:51:59 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.112 2018/08/03 11:18:22 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.113 2018/08/05 16:51:59 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -101,6 +101,8 @@ static int pm_nentries = 0;
 static int pm_nl1 = 0;
 static int pm_l1_size = 0;
 static uint64_t pm_entries_size = 0;
+static void *pm_tmp_p0;
+static void *pm_tmp_p1;
 
 static struct pool pmap_pool;
 static struct pool pmap_pventry_pool;
@@ -183,6 +185,11 @@ pmap_bootstrap(void)
 	kmem_kvm_end= kmem_k_start - barrier_len;
 	kmem_kvm_start  = kmem_kvm_end - KVMSIZE;
 
+	/* allow some pmap scratch space */
+	pm_tmp_p0 = (void *) (kmem_kvm_start);
+	pm_tmp_p1 = (void *) (kmem_kvm_start + PAGE_SIZE);
+	kmem_kvm_start += 2*PAGE_SIZE;
+
 	/* claim an area for userland (---/R--/RW-/RWX) */
 	kmem_user_start = vm_min_addr;
 	kmem_user_end   = kmem_kvm_start - barrier_len;
@@ -1227,14 +1234,12 @@ pmap_zero_page(paddr_t pa)
 	if (pa & (PAGE_SIZE-1))
 		panic("%s: unaligned address passed : %p\n", __func__, (void *) pa);
 
-	blob = thunk_mmap(NULL, PAGE_SIZE,
+	blob = thunk_mmap(pm_tmp_p0, PAGE_SIZE,
 		THUNK_PROT_READ | THUNK_PROT_WRITE,
-		THUNK_MAP_FILE | THUNK_MAP_SHARED,
+		THUNK_MAP_FILE | THUNK_MAP_FIXED | THUNK_MAP_SHARED,
 		mem_fh, pa);
-	if (!blob)
+	if (blob != pm_tmp_p0)
 		panic("%s: couldn't get mapping", __func__);
-	if (blob < (char *) kmem_k_end)
-		panic("%s: mmap in illegal memory range", __func__);
 
 	memset(blob, 0, PAGE_SIZE);
 
@@ -1254,25 +1259,21 @@ pmap_copy_page(paddr_t src_pa, paddr_t d
 	thunk_printf_debug("pmap_copy_page: pa src %p, pa dst %p\n",
 		(void *) src_pa, (void *) dst_pa);
 
-	/* XXX bug alart: can we allow the kernel to make a decision on this? */
-	sblob = thunk_mmap(NULL, PAGE_SIZE,
+	/* source */
+	sblob = thunk_mmap(pm_tmp_p0, PAGE_SIZE,
 		THUNK_PROT_READ,
-		THUNK_MAP_FILE | THUNK_MAP_SHARED,
+		THUNK_MAP_FILE | THUNK_MAP_FIXED | THUNK_MAP_SHARED,
 		mem_fh, src_pa);
-	if (!sblob)
+	if (sblob != pm_tmp_p0)
 		panic("%s: couldn't get src mapping", __func__);
-	if (sblob < (char *) kmem_k_end)
-		panic("%s: mmap in illegal memory range", __func__);
 
-	/* XXX bug alart: can we allow the kernel to make a decision on this? */
-	dblob = thunk_mmap(NULL, PAGE_SIZE,
+	/* destination */
+	dblob = thunk_mmap(pm_tmp_p1, PAGE_SIZE,
 		THUNK_PROT_READ | THUNK_PROT_WRITE,
-		THUNK_MAP_FILE | THUNK_MAP_SHARED,
+		THUNK_MAP_FILE | THUNK_MAP_FIXED | THUNK_MAP_SHARED,
 		mem_fh, dst_pa);
-	if (!dblob)
+	if (dblob != pm_tmp_p1)
 		panic("%s: couldn't get dst mapping", __func__);
-	if (dblob < (char *) kmem_k_end)
-		panic("%s: mmap in illegal memory range", __func__);
 
 	memcpy(dblob, sblob, PAGE_SIZE);
 



CVS commit: src/sys/arch/usermode

2018-08-03 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Aug  3 11:18:22 UTC 2018

Modified Files:
src/sys/arch/usermode/include: vmparam.h
src/sys/arch/usermode/usermode: db_memrw.c pmap.c

Log Message:
Allow for setting kernel breakpoints in our remote kgdb


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/usermode/include/vmparam.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/usermode/usermode/db_memrw.c
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/usermode/usermode/pmap.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/usermode/include/vmparam.h
diff -u src/sys/arch/usermode/include/vmparam.h:1.19 src/sys/arch/usermode/include/vmparam.h:1.20
--- src/sys/arch/usermode/include/vmparam.h:1.19	Wed Aug  1 12:09:02 2018
+++ src/sys/arch/usermode/include/vmparam.h	Fri Aug  3 11:18:22 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: vmparam.h,v 1.19 2018/08/01 12:09:02 reinoud Exp $ */
+/* $NetBSD: vmparam.h,v 1.20 2018/08/03 11:18:22 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -43,7 +43,7 @@ extern paddr_t kmem_user_start, kmem_use
 #define VM_MAX_ADDRESS		kmem_user_end
 #define VM_MAXUSER_ADDRESS	kmem_user_end
 #define VM_MIN_KERNEL_ADDRESS	kmem_kvm_start
-#define VM_MAX_KERNEL_ADDRESS 	kmem_kvm_end
+#define VM_MAX_KERNEL_ADDRESS 	kmem_k_end
 
 #define VM_PHYSSEG_STRAT	VM_PSTRAT_BIGFIRST
 #define VM_PHYSSEG_MAX		1

Index: src/sys/arch/usermode/usermode/db_memrw.c
diff -u src/sys/arch/usermode/usermode/db_memrw.c:1.2 src/sys/arch/usermode/usermode/db_memrw.c:1.3
--- src/sys/arch/usermode/usermode/db_memrw.c:1.2	Wed Aug  1 10:27:28 2018
+++ src/sys/arch/usermode/usermode/db_memrw.c	Fri Aug  3 11:18:22 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.2 2018/08/01 10:27:28 reinoud Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.3 2018/08/03 11:18:22 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -53,11 +53,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.2 2018/08/01 10:27:28 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.3 2018/08/03 11:18:22 reinoud Exp $");
 
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -211,29 +212,30 @@ db_write_text(vaddr_t addr, size_t size,
 void
 db_write_bytes(vaddr_t addr, size_t size, const char *data)
 {
-//	extern struct bootspace bootspace;
 	char *dst;
-//	size_t i;
+	int ret;
 
 	dst = (char *)addr;
 	thunk_printf_debug("\n%s : %p + %d\n", __func__, dst, (int) size);
-#if 0
-	// TODO: check if we in kernel range and if so, do the mmap dance
-	// ourselves?
 
-	/* If any part is in kernel text or rodata, use db_write_text() */
-	for (i = 0; i < BTSPACE_NSEGS; i++) {
-		if (bootspace.segs[i].type != BTSEG_TEXT &&
-		bootspace.segs[i].type != BTSEG_RODATA) {
-			continue;
-		}
-		if (addr >= bootspace.segs[i].va &&
-		addr < (bootspace.segs[i].va + bootspace.segs[i].sz)) {
-			db_write_text(addr, size, data);
-			return;
-		}
+	if (db_validate_address((vaddr_t)addr)) {
+		printf("address %p is invalid\n", (void *) addr);
+		return;
+	}
+
+	/*
+	 * if we are in the kernel range, just allow writing by using
+	 * mprotect(); Note that this needs an unprotected binary, set with
+	 * `paxctl -agm netbsd`
+	 */
+	if (addr > kmem_k_start) {
+		ret = thunk_mprotect((void *) trunc_page(addr), PAGE_SIZE,
+			PROT_READ | PROT_WRITE | PROT_EXEC);
+		if (ret != 0)
+			panic("please unprotect kernel binary with "
+			  "`paxctl -agm netbsd`");
+		assert(ret == 0);
 	}
-#endif
 
 	dst = (char *)addr;
 

Index: src/sys/arch/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.111 src/sys/arch/usermode/usermode/pmap.c:1.112
--- src/sys/arch/usermode/usermode/pmap.c:1.111	Fri Aug  3 06:52:50 2018
+++ src/sys/arch/usermode/usermode/pmap.c	Fri Aug  3 11:18:22 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.111 2018/08/03 06:52:50 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.112 2018/08/03 11:18:22 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.111 2018/08/03 06:52:50 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.112 2018/08/03 11:18:22 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -139,7 +139,7 @@ pmap_bootstrap(void)
 	struct pmap *pmap;
 	paddr_t DRAM_cfg;
 	paddr_t fpos, file_len;
-	paddr_t pv_fpos, tlb_fpos, pm_l1_fpos, pm_fpos;
+	paddr_t kernel_fpos, pv_fpos, tlb_fpos, pm_l1_fpos, pm_fpos;
 	paddr_t wlen;
 	paddr_t barrier_len;
 	paddr_t pv_table_size;
@@ -281,9 +281,11 @@ pmap_bootstrap(void)
 	assert(err == 0);
 
 	/* map the kernel at the start of the 'memory' file */
-	written = thunk_pwrite(mem_fh, (void *) kmem_k_start, kmem_k_length, 0);
+	kernel_fpos = 0;
+	written = thunk_p

CVS commit: src/sys/arch/usermode/usermode

2018-08-03 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Aug  3 06:52:50 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: pmap.c

Log Message:
Fix physical memory size issue. It will now happily run on more than one gb.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/usermode/usermode/pmap.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/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.110 src/sys/arch/usermode/usermode/pmap.c:1.111
--- src/sys/arch/usermode/usermode/pmap.c:1.110	Wed Aug  1 12:09:01 2018
+++ src/sys/arch/usermode/usermode/pmap.c	Fri Aug  3 06:52:50 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.110 2018/08/01 12:09:01 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.111 2018/08/03 06:52:50 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.110 2018/08/01 12:09:01 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.111 2018/08/03 06:52:50 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -76,6 +76,14 @@ struct pmap {
 	struct	pmap_l2 **pm_l1;
 };
 
+/*
+ * pv_table is list of pv_entry structs completely spanning the total memory.
+ * It is indexed on physical page number. Each entry will be daisy chained
+ * with pv_entry records for each usage in all the pmaps.
+ *
+ * kernel_pm_entries contains all kernel L2 pages for its complete map.
+ *
+ */
 
 static struct pv_entry **kernel_pm_entries;
 static struct pv_entry  *pv_table;	/* physical pages info (direct mapped) */
@@ -95,7 +103,6 @@ static int pm_l1_size = 0;
 static uint64_t pm_entries_size = 0;
 
 static struct pool pmap_pool;
-static struct pool pmap_l1_pool;
 static struct pool pmap_pventry_pool;
 
 /* forwards */
@@ -139,6 +146,7 @@ pmap_bootstrap(void)
 	vaddr_t free_start, free_end;
 	paddr_t pa;
 	vaddr_t va;
+	size_t  kmem_k_length, written;
 	uintptr_t pg, l1;
 	void *addr;
 	int err;
@@ -165,6 +173,7 @@ pmap_bootstrap(void)
 	/* calculate kernel section (R-X) */
 	kmem_k_start = (vaddr_t) PAGE_SIZE * (atop(_start));
 	kmem_k_end   = (vaddr_t) PAGE_SIZE * (atop() + 1);
+	kmem_k_length = kmem_k_end - kmem_k_start;
 
 	/* calculate total available memory space & available pages */
 	DRAM_cfg = (vaddr_t) TEXTADDR;
@@ -260,7 +269,7 @@ pmap_bootstrap(void)
 #endif
 
 	/* protect the current kernel section */
-	err = thunk_mprotect((void *) kmem_k_start, kmem_k_end - kmem_k_start,
+	err = thunk_mprotect((void *) kmem_k_start, kmem_k_length,
 		THUNK_PROT_READ | THUNK_PROT_EXEC);
 	assert(err == 0);
 
@@ -271,14 +280,18 @@ pmap_bootstrap(void)
 		THUNK_MADV_WILLNEED | THUNK_MADV_RANDOM);
 	assert(err == 0);
 
+	/* map the kernel at the start of the 'memory' file */
+	written = thunk_pwrite(mem_fh, (void *) kmem_k_start, kmem_k_length, 0);
+	assert(written == kmem_k_length);
+	fpos = kmem_k_length;
+
 	/* initialize counters */
-	fpos = 0;
 	free_start = fpos; /* in physical space ! */
 	free_end   = file_len; /* in physical space ! */
 	kmem_kvm_cur_start = kmem_kvm_start;
 
 	/* calculate pv table size */
-	phys_npages = (free_end - free_start) / PAGE_SIZE;
+	phys_npages = file_len / PAGE_SIZE;
 	pv_table_size = round_page(phys_npages * sizeof(struct pv_entry));
 	thunk_printf_debug("claiming %"PRIu64" KB of pv_table for "
 		"%"PRIdPTR" pages of physical memory\n",
@@ -292,7 +305,7 @@ pmap_bootstrap(void)
 
 	/* calculate how big the l1 tables are going to be */
 	pm_nl1 = pm_nentries / PMAP_L2_NENTRY;
-	pm_l1_size = pm_nl1 * sizeof(struct pmap_l1 *);
+	pm_l1_size = round_page(pm_nl1 * sizeof(struct pmap_l1 *));
 
 	/* claim pv table */
 	pv_fpos = fpos;
@@ -449,8 +462,6 @@ pmap_deferred_init(void)
 	/* create pmap pool */
 	pool_init(_pool, sizeof(struct pmap), 0, 0, 0,
 	"pmappool", NULL, IPL_NONE);
-	pool_init(_l1_pool, pm_l1_size, 0, 0, 0,
-	"pmapl1pool", NULL, IPL_NONE);
 	pool_init(_pventry_pool, sizeof(struct pv_entry), 0, 0, 0,
 	"pventry", NULL, IPL_HIGH);
 }
@@ -484,8 +495,8 @@ pmap_create(void)
 	pmap->pm_flags = 0;
 
 	/* claim l1 table */
-	pmap->pm_l1 = pool_get(_l1_pool, PR_WAITOK);
-	memset(pmap->pm_l1, 0, pm_l1_size);
+	pmap->pm_l1 = kmem_zalloc(pm_l1_size, KM_SLEEP);
+	assert(pmap->pm_l1);
 
 	thunk_printf_debug("\tpmap %p\n", pmap);
 
@@ -527,7 +538,7 @@ pmap_destroy(pmap_t pmap)
 			continue;
 		kmem_free(l2tbl, PMAP_L2_SIZE);
 	}
-	pool_put(_l1_pool, pmap->pm_l1);
+	kmem_free(pmap->pm_l1, pm_l1_size);
 	pool_put(_pool, pmap);
 }
 



CVS commit: src/sys/arch/usermode

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 12:09:02 UTC 2018

Modified Files:
src/sys/arch/usermode/include: vmparam.h
src/sys/arch/usermode/usermode: pmap.c

Log Message:
Revert to working state


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/usermode/include/vmparam.h
cvs rdiff -u -r1.109 -r1.110 src/sys/arch/usermode/usermode/pmap.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/usermode/include/vmparam.h
diff -u src/sys/arch/usermode/include/vmparam.h:1.18 src/sys/arch/usermode/include/vmparam.h:1.19
--- src/sys/arch/usermode/include/vmparam.h:1.18	Wed Aug  1 09:46:16 2018
+++ src/sys/arch/usermode/include/vmparam.h	Wed Aug  1 12:09:02 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: vmparam.h,v 1.18 2018/08/01 09:46:16 reinoud Exp $ */
+/* $NetBSD: vmparam.h,v 1.19 2018/08/01 12:09:02 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -43,7 +43,7 @@ extern paddr_t kmem_user_start, kmem_use
 #define VM_MAX_ADDRESS		kmem_user_end
 #define VM_MAXUSER_ADDRESS	kmem_user_end
 #define VM_MIN_KERNEL_ADDRESS	kmem_kvm_start
-#define VM_MAX_KERNEL_ADDRESS 	kmem_k_end
+#define VM_MAX_KERNEL_ADDRESS 	kmem_kvm_end
 
 #define VM_PHYSSEG_STRAT	VM_PSTRAT_BIGFIRST
 #define VM_PHYSSEG_MAX		1

Index: src/sys/arch/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.109 src/sys/arch/usermode/usermode/pmap.c:1.110
--- src/sys/arch/usermode/usermode/pmap.c:1.109	Wed Aug  1 09:44:31 2018
+++ src/sys/arch/usermode/usermode/pmap.c	Wed Aug  1 12:09:01 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.109 2018/08/01 09:44:31 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.110 2018/08/01 12:09:01 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.109 2018/08/01 09:44:31 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.110 2018/08/01 12:09:01 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -285,7 +285,7 @@ pmap_bootstrap(void)
 		(uint64_t) pv_table_size/1024, (uintptr_t) phys_npages);
 
 	/* calculate number of pmap entries needed for a complete map */
-	pm_nentries = (kmem_k_end - VM_MIN_ADDRESS) / PAGE_SIZE;
+	pm_nentries = (kmem_k_start - VM_MIN_ADDRESS) / PAGE_SIZE;
 	pm_entries_size = round_page(pm_nentries * sizeof(struct pv_entry *));
 	thunk_printf_debug("tlb va->pa lookup table is %"PRIu64" KB for "
 		"%d logical pages\n", pm_entries_size/1024, pm_nentries);
@@ -660,7 +660,8 @@ pmap_fault(pmap_t pmap, vaddr_t va, vm_p
 
 	/* not known! then it must be UVM's work */
 	if (pv == NULL) {
-		thunk_printf_debug("%s: no mapping yet\n", __func__);
+		//thunk_printf("%s: no mapping yet for %p\n",
+		//	__func__, (void *) va);
 		*atype = VM_PROT_READ;		/* assume it was a read */
 		return false;
 	}
@@ -1090,7 +1091,7 @@ pmap_extract(pmap_t pmap, vaddr_t va, pa
 	thunk_printf_debug("pmap_extract: extracting va %p\n", (void *) va);
 #ifdef DIAGNOSTIC
 	if ((va < VM_MIN_ADDRESS) || (va > VM_MAX_KERNEL_ADDRESS)) {
-		thunk_printf_debug("pmap_extract: invalid va issued\n");
+		thunk_printf_debug("pmap_extract: invalid va isued\n");
 		thunk_printf("%p not in [%p, %p]\n", (void *) va,
 		(void *) VM_MIN_ADDRESS, (void *) VM_MAX_KERNEL_ADDRESS);
 		return false;



CVS commit: src/sys/arch/usermode/usermode

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 10:27:28 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: db_memrw.c

Log Message:
Remove yet another debug printf()


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/usermode/usermode/db_memrw.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/usermode/usermode/db_memrw.c
diff -u src/sys/arch/usermode/usermode/db_memrw.c:1.1 src/sys/arch/usermode/usermode/db_memrw.c:1.2
--- src/sys/arch/usermode/usermode/db_memrw.c:1.1	Wed Aug  1 10:22:20 2018
+++ src/sys/arch/usermode/usermode/db_memrw.c	Wed Aug  1 10:27:28 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.1 2018/08/01 10:22:20 reinoud Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.2 2018/08/01 10:27:28 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.1 2018/08/01 10:22:20 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.2 2018/08/01 10:27:28 reinoud Exp $");
 
 #include 
 #include 
@@ -216,7 +216,7 @@ db_write_bytes(vaddr_t addr, size_t size
 //	size_t i;
 
 	dst = (char *)addr;
-thunk_printf("\n%s : %p + %d\n", __func__, dst, (int) size);
+	thunk_printf_debug("\n%s : %p + %d\n", __func__, dst, (int) size);
 #if 0
 	// TODO: check if we in kernel range and if so, do the mmap dance
 	// ourselves?



CVS commit: src/sys/arch/usermode/usermode

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 10:24:41 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: kgdb_machdep.c

Log Message:
Fix too long line


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/usermode/usermode/kgdb_machdep.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/usermode/usermode/kgdb_machdep.c
diff -u src/sys/arch/usermode/usermode/kgdb_machdep.c:1.2 src/sys/arch/usermode/usermode/kgdb_machdep.c:1.3
--- src/sys/arch/usermode/usermode/kgdb_machdep.c:1.2	Wed Aug  1 10:23:55 2018
+++ src/sys/arch/usermode/usermode/kgdb_machdep.c	Wed Aug  1 10:24:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kgdb_machdep.c,v 1.2 2018/08/01 10:23:55 reinoud Exp $	*/
+/*	$NetBSD: kgdb_machdep.c,v 1.3 2018/08/01 10:24:41 reinoud Exp $	*/
 
 /*
  * Copyright (c) 1996 Matthias Pfaller.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.2 2018/08/01 10:23:55 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.3 2018/08/01 10:24:41 reinoud Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -58,7 +58,8 @@ kgdb_acc(vaddr_t va, size_t len)
 	va  &= ~PGOFSET;
 	last_va &= ~PGOFSET;
 
-	thunk_printf_debug("%s: [%p .. %p]\n", __func__, (void *) va, (void *) last_va);
+	thunk_printf_debug("%s: [%p .. %p]\n", __func__,
+		(void *) va, (void *) last_va);
 	do {
 		if (db_validate_address(va))
 			return (0);



CVS commit: src/sys/arch/usermode/usermode

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 10:23:55 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: kgdb_machdep.c

Log Message:
Remove debugging printf()


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/usermode/usermode/kgdb_machdep.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/usermode/usermode/kgdb_machdep.c
diff -u src/sys/arch/usermode/usermode/kgdb_machdep.c:1.1 src/sys/arch/usermode/usermode/kgdb_machdep.c:1.2
--- src/sys/arch/usermode/usermode/kgdb_machdep.c:1.1	Wed Aug  1 10:22:20 2018
+++ src/sys/arch/usermode/usermode/kgdb_machdep.c	Wed Aug  1 10:23:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kgdb_machdep.c,v 1.1 2018/08/01 10:22:20 reinoud Exp $	*/
+/*	$NetBSD: kgdb_machdep.c,v 1.2 2018/08/01 10:23:55 reinoud Exp $	*/
 
 /*
  * Copyright (c) 1996 Matthias Pfaller.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.1 2018/08/01 10:22:20 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.2 2018/08/01 10:23:55 reinoud Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -58,7 +58,7 @@ kgdb_acc(vaddr_t va, size_t len)
 	va  &= ~PGOFSET;
 	last_va &= ~PGOFSET;
 
-thunk_printf("%s: [%p .. %p]\n", __func__, (void *) va, (void *) last_va);
+	thunk_printf_debug("%s: [%p .. %p]\n", __func__, (void *) va, (void *) last_va);
 	do {
 		if (db_validate_address(va))
 			return (0);



CVS commit: src/sys/arch/usermode/usermode

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 10:22:20 UTC 2018

Added Files:
src/sys/arch/usermode/usermode: cpufunc.S db_memrw.c kgdb_machdep.c

Log Message:
Add the kgdb meat


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/usermode/usermode/cpufunc.S \
src/sys/arch/usermode/usermode/db_memrw.c \
src/sys/arch/usermode/usermode/kgdb_machdep.c

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

Added files:

Index: src/sys/arch/usermode/usermode/cpufunc.S
diff -u /dev/null src/sys/arch/usermode/usermode/cpufunc.S:1.1
--- /dev/null	Wed Aug  1 10:22:20 2018
+++ src/sys/arch/usermode/usermode/cpufunc.S	Wed Aug  1 10:22:20 2018
@@ -0,0 +1,75 @@
+
+#include 
+#include "assym.h"
+
+#if defined(__i386__)
+
+ENTRY(breakpoint)
+	.byte 0xcc	// BKPT_INST
+	ret
+
+#error implement setjmp/longjmp for i386
+
+#elif defined(__amd64__)
+ENTRY(breakpoint)
+	.byte 0xcc	// BKPT_INST, int3
+	ret
+
+/*
+ * int setjmp(label_t *)
+ *
+ * Used primarily by DDB.
+ */
+ENTRY(setjmp)
+	/*
+	 * Only save registers that must be preserved across function
+	 * calls according to the ABI (%rbx, %rsp, %rbp, %r12-%r15)
+	 * and %rip.
+	 */
+	movq	%rdi,%rax
+	movq	%rbx,(%rax)
+	movq	%rsp,8(%rax)
+	movq	%rbp,16(%rax)
+	movq	%r12,24(%rax)
+	movq	%r13,32(%rax)
+	movq	%r14,40(%rax)
+	movq	%r15,48(%rax)
+	movq	(%rsp),%rdx
+	movq	%rdx,56(%rax)
+	xorl	%eax,%eax
+	ret
+END(setjmp)
+
+/*
+ * int longjmp(label_t *)
+ *
+ * Used primarily by DDB.
+ */
+ENTRY(longjmp)
+	movq	%rdi,%rax
+	movq	(%rax),%rbx
+	movq	8(%rax),%rsp
+	movq	16(%rax),%rbp
+	movq	24(%rax),%r12
+	movq	32(%rax),%r13
+	movq	40(%rax),%r14
+	movq	48(%rax),%r15
+	movq	56(%rax),%rdx
+	movq	%rdx,(%rsp)
+	movl	$1,%eax
+	ret
+END(longjmp)
+#elif defined(__arm__)
+
+ENTRY(breakpoint)
+	BKPT_ASM
+	mov pc, lr
+
+#error implement setjmp/longjmp for arm32
+
+#else
+
+#error port me 
+
+#endif
+
Index: src/sys/arch/usermode/usermode/db_memrw.c
diff -u /dev/null src/sys/arch/usermode/usermode/db_memrw.c:1.1
--- /dev/null	Wed Aug  1 10:22:20 2018
+++ src/sys/arch/usermode/usermode/db_memrw.c	Wed Aug  1 10:22:20 2018
@@ -0,0 +1,257 @@
+/*	$NetBSD: db_memrw.c,v 1.1 2018/08/01 10:22:20 reinoud Exp $	*/
+
+/*-
+ * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Gordon W. Ross and Jason R. Thorpe.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * Interface to the debugger for virtual memory read/write.
+ * This file is shared by DDB and KGDB, and must work even
+ * when only KGDB is included (thus no db_printf calls).
+ *
+ * To write in the text segment, we have to first make
+ * the page writable, do the write, then restore the PTE.
+ * For writes outside the text segment, and all reads,
+ * just do the access -- if it causes a fault, the debugger
+ * will recover with a longjmp to an appropriate place.
+ *
+ * ALERT!  If you want to access device registers with a
+ * specific size, then the read/write functions have to
+ * make sure to do the correct sized pointer access.
+ *
+ * Modified for i386 from hp300 version by
+ * Jason R. Thorpe .
+ *
+ * Basic copy to amd64 by fvdl.
+ * 
+ * i386 and amd64 merge by jym.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.1 2018/08/01 10:22:20 reinoud Exp $");
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+
+int
+db_validate_address(vaddr_t addr)
+{
+	struct proc *p = curproc;
+	struct pmap *pmap;
+
+	if (!p || !p->p_vmspace || !p->p_vmspace->vm_map.pmap ||
+	addr >= 

CVS commit: src/sys/arch/usermode/include

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 09:52:15 UTC 2018

Added Files:
src/sys/arch/usermode/include: cpufunc.h ucontext.h

Log Message:
Forgot the two header files


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/usermode/include/cpufunc.h \
src/sys/arch/usermode/include/ucontext.h

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

Added files:

Index: src/sys/arch/usermode/include/cpufunc.h
diff -u /dev/null src/sys/arch/usermode/include/cpufunc.h:1.1
--- /dev/null	Wed Aug  1 09:52:15 2018
+++ src/sys/arch/usermode/include/cpufunc.h	Wed Aug  1 09:52:15 2018
@@ -0,0 +1,20 @@
+/* $NetBSD: cpufunc.h,v 1.1 2018/08/01 09:52:15 reinoud Exp $ */
+
+/*
+ * Automatically generated by ./genheaders.sh on Wed May 16 14:39:02 CEST 2018
+ * Do not modify directly!
+ */
+#ifndef _USERMODE_INT_LIMITS_H
+#define _USERMODE_INT_LIMITS_H
+
+#if defined(__i386__)
+#include "../../i386/include/cpufunc.h"
+#elif defined(__x86_64__)
+#include "../../amd64/include/cpufunc.h"
+#elif defined(__arm__)
+#include "../../arm/include/cpufunc.h"
+#else
+#error port me
+#endif
+
+#endif
Index: src/sys/arch/usermode/include/ucontext.h
diff -u /dev/null src/sys/arch/usermode/include/ucontext.h:1.1
--- /dev/null	Wed Aug  1 09:52:15 2018
+++ src/sys/arch/usermode/include/ucontext.h	Wed Aug  1 09:52:15 2018
@@ -0,0 +1,23 @@
+/* $NetBSD: ucontext.h,v 1.1 2018/08/01 09:52:15 reinoud Exp $ */
+
+#ifndef _USERMODE_UCONTEXT_H
+#define _USERMODE_UCONTEXT_H
+
+#include 
+#include 
+#include 
+
+#if defined(__i386__)
+
+#elif defined(__x86_64__)
+
+#define _UC_MACHINE_RFLAGS(uc) ((uc)->uc_mcontext.__gregs[26])
+
+#elif defined(__arm__)
+#error port me
+#else
+#error port me
+#endif
+
+#endif /* _USERMODE_UCONTEXT_H */
+



CVS commit: src/sys/arch/usermode

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 09:50:57 UTC 2018

Modified Files:
src/sys/arch/usermode/conf: files.usermode
src/sys/arch/usermode/include: cpu.h db_machdep.h genheaders.sh pmap.h

Log Message:
Add preliminary KGDB support for NetBSD/usermode, currently only under amd64


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/usermode/conf/files.usermode
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/usermode/include/cpu.h \
src/sys/arch/usermode/include/genheaders.sh
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/usermode/include/db_machdep.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/usermode/include/pmap.h

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/usermode/conf/files.usermode
diff -u src/sys/arch/usermode/conf/files.usermode:1.17 src/sys/arch/usermode/conf/files.usermode:1.18
--- src/sys/arch/usermode/conf/files.usermode:1.17	Tue Jun  5 20:02:42 2018
+++ src/sys/arch/usermode/conf/files.usermode	Wed Aug  1 09:50:57 2018
@@ -1,4 +1,4 @@
-# $NetBSD: files.usermode,v 1.17 2018/06/05 20:02:42 reinoud Exp $
+# $NetBSD: files.usermode,v 1.18 2018/08/01 09:50:57 reinoud Exp $
 
 maxpartitions 8
 maxusers 8 16 64
@@ -62,6 +62,9 @@ file	arch/usermode/usermode/sys_machdep.
 file	arch/usermode/usermode/syscall.c
 file	arch/usermode/usermode/trap.c
 file	arch/usermode/usermode/vm_machdep.c
+file	arch/usermode/usermode/db_memrw.c	ddb | kgdb
+file	arch/usermode/usermode/kgdb_machdep.c	ddb | kgdb
+file	arch/usermode/usermode/cpufunc.S	ddb | kgdb
 file	dev/cons.c
 file	dev/md_root.cmemory_disk_hooks
 file	kern/subr_disk_mbr.c			disk

Index: src/sys/arch/usermode/include/cpu.h
diff -u src/sys/arch/usermode/include/cpu.h:1.10 src/sys/arch/usermode/include/cpu.h:1.11
--- src/sys/arch/usermode/include/cpu.h:1.10	Wed Feb  8 17:55:21 2012
+++ src/sys/arch/usermode/include/cpu.h	Wed Aug  1 09:50:57 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.10 2012/02/08 17:55:21 reinoud Exp $ */
+/* $NetBSD: cpu.h,v 1.11 2018/08/01 09:50:57 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -47,7 +47,7 @@ struct cpu_info;
 extern int	astpending;
 #define aston(ci) (astpending++)
 extern void cpu_need_resched(struct cpu_info *ci, int flags);
-
+extern void kgdb_port_init(void);
 
 struct cpu_info {
 	struct cpu_data	ci_data;		/* MI per-cpu data */
Index: src/sys/arch/usermode/include/genheaders.sh
diff -u src/sys/arch/usermode/include/genheaders.sh:1.10 src/sys/arch/usermode/include/genheaders.sh:1.11
--- src/sys/arch/usermode/include/genheaders.sh:1.10	Wed May 16 12:40:26 2018
+++ src/sys/arch/usermode/include/genheaders.sh	Wed Aug  1 09:50:57 2018
@@ -23,6 +23,7 @@ HDRS="$HDRS wchar_limits.h"
 HDRS="$HDRS cdefs.h"
 HDRS="$HDRS mcontext.h"
 HDRS="$HDRS frame_regs.h"
+HDRS="$HDRS cpufunc.h"
 
 for hdr in ${HDRS}; do
 	G="_USERMODE_$(echo ${hdr} | sed 's/\./_/g' | tr [a-z] [A-Z])"

Index: src/sys/arch/usermode/include/db_machdep.h
diff -u src/sys/arch/usermode/include/db_machdep.h:1.2 src/sys/arch/usermode/include/db_machdep.h:1.3
--- src/sys/arch/usermode/include/db_machdep.h:1.2	Wed Oct 21 16:06:59 2009
+++ src/sys/arch/usermode/include/db_machdep.h	Wed Aug  1 09:50:57 2018
@@ -1,32 +1,80 @@
-/* $NetBSD: db_machdep.h,v 1.2 2009/10/21 16:06:59 snj Exp $ */
+/* $NetBSD: db_machdep.h,v 1.3 2018/08/01 09:50:57 reinoud Exp $ */
 
-/*-
- * Copyright (c) 2007 Jared D. McNeill 
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
- */
+#ifndef _USERMODE_DB_MACHDEP_H
+#define _USERMODE_DB_MACHDEP_H
 
-#ifndef _ARCH_USERMODE_INCLUDE_DB_MACHDEP_H
-#define _ARCH_USERMODE_INCLUDE_DB_MACHDEP_H

CVS commit: src/sys/arch/usermode/include

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 09:46:46 UTC 2018

Modified Files:
src/sys/arch/usermode/include: thunk.h

Log Message:
Add headers for support functions for  kgdb


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/usermode/include/thunk.h

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/usermode/include/thunk.h
diff -u src/sys/arch/usermode/include/thunk.h:1.65 src/sys/arch/usermode/include/thunk.h:1.66
--- src/sys/arch/usermode/include/thunk.h:1.65	Mon Jun  4 19:53:01 2018
+++ src/sys/arch/usermode/include/thunk.h	Wed Aug  1 09:46:46 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.h,v 1.65 2018/06/04 19:53:01 reinoud Exp $ */
+/* $NetBSD: thunk.h,v 1.66 2018/08/01 09:46:46 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -127,6 +127,11 @@ int	thunk_mkstemp(char *);
 int	thunk_unlink(const char *);
 pid_t	thunk_getpid(void);
 
+int	thunk_gdb_open(void);
+int	thunk_gdb_accept(int sockfd);
+int	thunk_kgdb_getc(int fd, char *ch);
+int	thunk_kgdb_putc(int fd, char ch);
+
 int	thunk_sigaction(int, const struct sigaction *, struct sigaction *);
 int	thunk_sigaltstack(const stack_t *, stack_t *);
 void	thunk_signal(int, void (*)(int));



CVS commit: src/sys/arch/usermode/include

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 09:46:16 UTC 2018

Modified Files:
src/sys/arch/usermode/include: vmparam.h

Log Message:
Max kernel address is end of kernel


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/usermode/include/vmparam.h

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/usermode/include/vmparam.h
diff -u src/sys/arch/usermode/include/vmparam.h:1.17 src/sys/arch/usermode/include/vmparam.h:1.18
--- src/sys/arch/usermode/include/vmparam.h:1.17	Sun Nov 10 19:52:01 2013
+++ src/sys/arch/usermode/include/vmparam.h	Wed Aug  1 09:46:16 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: vmparam.h,v 1.17 2013/11/10 19:52:01 jmcneill Exp $ */
+/* $NetBSD: vmparam.h,v 1.18 2018/08/01 09:46:16 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -43,7 +43,7 @@ extern paddr_t kmem_user_start, kmem_use
 #define VM_MAX_ADDRESS		kmem_user_end
 #define VM_MAXUSER_ADDRESS	kmem_user_end
 #define VM_MIN_KERNEL_ADDRESS	kmem_kvm_start
-#define VM_MAX_KERNEL_ADDRESS 	kmem_kvm_end
+#define VM_MAX_KERNEL_ADDRESS 	kmem_k_end
 
 #define VM_PHYSSEG_STRAT	VM_PSTRAT_BIGFIRST
 #define VM_PHYSSEG_MAX		1



CVS commit: src/sys/arch/usermode/usermode

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 09:44:32 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: machdep.c pmap.c thunk.c trap.c

Log Message:
Oops, forgot a debug printf


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/usermode/usermode/machdep.c
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/usermode/usermode/pmap.c
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/usermode/usermode/thunk.c
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/usermode/usermode/trap.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/usermode/usermode/machdep.c
diff -u src/sys/arch/usermode/usermode/machdep.c:1.56 src/sys/arch/usermode/usermode/machdep.c:1.57
--- src/sys/arch/usermode/usermode/machdep.c:1.56	Mon Jun 11 19:35:56 2018
+++ src/sys/arch/usermode/usermode/machdep.c	Wed Aug  1 09:44:31 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.56 2018/06/11 19:35:56 reinoud Exp $ */
+/* $NetBSD: machdep.c,v 1.57 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -37,7 +37,7 @@
 #include "opt_memsize.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.56 2018/06/11 19:35:56 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.57 2018/08/01 09:44:31 reinoud Exp $");
 
 #include 
 #include 
@@ -59,6 +59,11 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 #include 
 #include 
 #include 
+#include 
+#include 
+
+#include "opt_ddb.h"
+#include "opt_kgdb.h"
 
 #ifndef MAX_DISK_IMAGES
 #define MAX_DISK_IMAGES	4
@@ -272,6 +277,18 @@ main(int argc, char *argv[])
 	splinit();
 	splraise(IPL_HIGH);
 
+#ifdef DDB
+	if (boothowto & RB_KDB)
+		Debugger();
+#endif
+#ifdef KGDB
+	if (boothowto & RB_KDB) {
+		kgdb_port_init();
+		kgdb_debug_init = 1;
+		kgdb_connect(1);
+	}
+#endif
+
 	kernmain();
 }
 
@@ -297,6 +314,7 @@ setstatclockrate(int arg)
 void
 consinit(void)
 {
+//	kgdb_connect(0);
 	printf("NetBSD/usermode startup\n");
 }
 

Index: src/sys/arch/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.108 src/sys/arch/usermode/usermode/pmap.c:1.109
--- src/sys/arch/usermode/usermode/pmap.c:1.108	Wed Aug  1 09:43:17 2018
+++ src/sys/arch/usermode/usermode/pmap.c	Wed Aug  1 09:44:31 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.108 2018/08/01 09:43:17 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.109 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.108 2018/08/01 09:43:17 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.109 2018/08/01 09:44:31 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -660,7 +660,6 @@ pmap_fault(pmap_t pmap, vaddr_t va, vm_p
 
 	/* not known! then it must be UVM's work */
 	if (pv == NULL) {
-thunk_printf("%s: no mapping yet for %p\n", __func__, (void *) va);
 		thunk_printf_debug("%s: no mapping yet\n", __func__);
 		*atype = VM_PROT_READ;		/* assume it was a read */
 		return false;

Index: src/sys/arch/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.90 src/sys/arch/usermode/usermode/thunk.c:1.91
--- src/sys/arch/usermode/usermode/thunk.c:1.90	Mon Jun  4 19:53:01 2018
+++ src/sys/arch/usermode/usermode/thunk.c	Wed Aug  1 09:44:31 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.90 2018/06/04 19:53:01 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.91 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.90 2018/06/04 19:53:01 reinoud Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.91 2018/08/01 09:44:31 reinoud Exp $");
 #endif
 
 #define _KMEMUSER
@@ -92,6 +92,9 @@ __RCSID("$NetBSD: thunk.c,v 1.90 2018/06
 
 //#define RFB_DEBUG
 
+static ssize_t safe_recv(int s, void *buf, int len);
+static ssize_t safe_send(int s, const void *msg, int len);
+
 extern int boothowto;
 
 void
@@ -1017,6 +1020,78 @@ thunk_rfb_open(thunk_rfb_t *rfb, uint16_
 	return 0;
 }
 
+int
+thunk_gdb_open(void)
+{
+	struct sockaddr_in sin;
+	int sockfd;
+	int portnr = 5001;	/* XXX configurable or random */
+
+	/* create socket */
+	sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+	if (sockfd < 0) {
+		warn("kgdb stub: couldn't create socket");
+		return 0;
+	}
+
+	/* bind to requested port */
+	memset(, 0, sizeof(sin));
+	sin.sin_family  = AF_INET;
+	sin.sin_addr.s_addr = htonl(INADDR_ANY);
+	sin.sin_port= htons(portnr);
+
+	if (bind(sockfd, (struct sockaddr *), sizeof(sin)) < 0) {
+		warn("kgdb stub: couldn't bind port %d", portnr);
+		close(sockfd);
+		return 0;
+	}
+
+	/* listen for connections */
+	if (listen(sockfd, 1) < 0) {
+		warn("kgdb stub: couldn't 

CVS commit: src/sys/arch/usermode/usermode

2018-08-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Aug  1 09:43:17 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: pmap.c

Log Message:
Allow the usermode pmaps to also contain the kernel itself. This is needed for
the kernel pmap.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/arch/usermode/usermode/pmap.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/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.107 src/sys/arch/usermode/usermode/pmap.c:1.108
--- src/sys/arch/usermode/usermode/pmap.c:1.107	Thu May 17 19:06:02 2018
+++ src/sys/arch/usermode/usermode/pmap.c	Wed Aug  1 09:43:17 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.107 2018/05/17 19:06:02 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.108 2018/08/01 09:43:17 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.107 2018/05/17 19:06:02 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.108 2018/08/01 09:43:17 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -285,7 +285,7 @@ pmap_bootstrap(void)
 		(uint64_t) pv_table_size/1024, (uintptr_t) phys_npages);
 
 	/* calculate number of pmap entries needed for a complete map */
-	pm_nentries = (kmem_k_start - VM_MIN_ADDRESS) / PAGE_SIZE;
+	pm_nentries = (kmem_k_end - VM_MIN_ADDRESS) / PAGE_SIZE;
 	pm_entries_size = round_page(pm_nentries * sizeof(struct pv_entry *));
 	thunk_printf_debug("tlb va->pa lookup table is %"PRIu64" KB for "
 		"%d logical pages\n", pm_entries_size/1024, pm_nentries);
@@ -660,6 +660,7 @@ pmap_fault(pmap_t pmap, vaddr_t va, vm_p
 
 	/* not known! then it must be UVM's work */
 	if (pv == NULL) {
+thunk_printf("%s: no mapping yet for %p\n", __func__, (void *) va);
 		thunk_printf_debug("%s: no mapping yet\n", __func__);
 		*atype = VM_PROT_READ;		/* assume it was a read */
 		return false;
@@ -1089,8 +1090,12 @@ pmap_extract(pmap_t pmap, vaddr_t va, pa
 
 	thunk_printf_debug("pmap_extract: extracting va %p\n", (void *) va);
 #ifdef DIAGNOSTIC
-	if ((va < VM_MIN_ADDRESS) || (va > VM_MAX_KERNEL_ADDRESS))
-		panic("pmap_extract: invalid va isued\n");
+	if ((va < VM_MIN_ADDRESS) || (va > VM_MAX_KERNEL_ADDRESS)) {
+		thunk_printf_debug("pmap_extract: invalid va issued\n");
+		thunk_printf("%p not in [%p, %p]\n", (void *) va,
+		(void *) VM_MIN_ADDRESS, (void *) VM_MAX_KERNEL_ADDRESS);
+		return false;
+	}
 #endif
 	lpn = atop(va - VM_MIN_ADDRESS);	/* V->L */
 	pv = pmap_lookup_pv(pmap, lpn);



CVS commit: src/sys/arch/usermode/include

2018-07-28 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jul 28 20:26:13 UTC 2018

Added Files:
src/sys/arch/usermode/include: trap.h

Log Message:
Provide hand-doctored redirection of trap.h in preparation for ddb/kgdb


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/usermode/include/trap.h

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

Added files:

Index: src/sys/arch/usermode/include/trap.h
diff -u /dev/null src/sys/arch/usermode/include/trap.h:1.1
--- /dev/null	Sat Jul 28 20:26:13 2018
+++ src/sys/arch/usermode/include/trap.h	Sat Jul 28 20:26:13 2018
@@ -0,0 +1,19 @@
+/* $NetBSD: trap.h,v 1.1 2018/07/28 20:26:13 reinoud Exp $ */
+
+/*
+ * Handcrafted redirect to prevent problems with i386 and x86_64 sharing x86
+ */
+#ifndef _USERMODE_TRAP_H
+#define _USERMODE_TRAP_H
+
+#if defined(__i386__)
+#include "../../x86/include/trap.h"
+#elif defined(__x86_64__)
+#include "../../x86/include/trap.h"
+#elif defined(__arm__)
+#include "../../arm/include/trap.h"
+#else
+#error port me
+#endif
+
+#endif



CVS commit: src/sys/arch/usermode/usermode

2018-07-28 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jul 28 17:17:38 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: trap.c

Log Message:
Fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/usermode/usermode/trap.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/usermode/usermode/trap.c
diff -u src/sys/arch/usermode/usermode/trap.c:1.68 src/sys/arch/usermode/usermode/trap.c:1.69
--- src/sys/arch/usermode/usermode/trap.c:1.68	Mon Jun 11 19:23:21 2018
+++ src/sys/arch/usermode/usermode/trap.c	Sat Jul 28 17:17:38 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.68 2018/06/11 19:23:21 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.69 2018/07/28 17:17:38 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.68 2018/06/11 19:23:21 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.69 2018/07/28 17:17:38 reinoud Exp $");
 
 #include 
 #include 
@@ -320,7 +320,7 @@ handle_signal(int sig, siginfo_t *info, 
 	l = curlwp; KASSERT(l);
 	pcb = lwp_getpcb(l); KASSERT(pcb);
 
-	/* get address of possible faulted memory access and page aligne it */
+	/* get address of possible faulted memory access and page align it */
 	va = (vaddr_t) info->si_addr;
 	va = trunc_page(va);
 



CVS commit: src/sys/fs/udf

2018-07-25 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jul 25 11:09:22 UTC 2018

Modified Files:
src/sys/fs/udf: udf_subr.c

Log Message:
Enhance logical volume integrity descriptor handling and provide
bug-compatibility for Linux mkudffs 1.3 images.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/fs/udf/udf_subr.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/fs/udf/udf_subr.c
diff -u src/sys/fs/udf/udf_subr.c:1.141 src/sys/fs/udf/udf_subr.c:1.142
--- src/sys/fs/udf/udf_subr.c:1.141	Wed Jun  6 01:49:09 2018
+++ src/sys/fs/udf/udf_subr.c	Wed Jul 25 11:09:22 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_subr.c,v 1.141 2018/06/06 01:49:09 maya Exp $ */
+/* $NetBSD: udf_subr.c,v 1.142 2018/07/25 11:09:22 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -29,7 +29,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.141 2018/06/06 01:49:09 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.142 2018/07/25 11:09:22 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -1233,7 +1233,7 @@ udf_retrieve_lvint(struct udf_mount *ump
 
 		/* are we linking to a new piece? */
 		if (dscr && lvint->next_extent.len) {
-			len= udf_rw32(lvint->next_extent.len);
+			len   = udf_rw32(lvint->next_extent.len);
 			lbnum = udf_rw32(lvint->next_extent.loc);
 
 			if (trace_len >= UDF_LVDINT_SEGMENTS-1) {
@@ -1279,7 +1279,7 @@ udf_loose_lvint_history(struct udf_mount
 	uint32_t out_ext, out_wpos, out_len;
 	uint32_t lb_num;
 	uint32_t len, start;
-	int ext, minext, extlen, cnt, cpy_len, dscr_type;
+	int ext, sumext, extlen, cnt, cpy_len, dscr_type;
 	int losing;
 	int error;
 
@@ -1287,18 +1287,29 @@ udf_loose_lvint_history(struct udf_mount
 
 	/* search smallest extent */
 	trace = >lvint_trace[0];
-	minext = trace->end - trace->start;
+	sumext = trace->end - trace->start;
 	for (ext = 1; ext < UDF_LVDINT_SEGMENTS; ext++) {
 		trace = >lvint_trace[ext];
 		extlen = trace->end - trace->start;
 		if (extlen == 0)
 			break;
-		minext = MIN(minext, extlen);
+		sumext += extlen;
 	}
-	losing = MIN(minext, UDF_LVINT_LOSSAGE);
-	/* no sense wiping all */
-	if (losing == minext)
-		losing--;
+
+	/* just one element? its not legal but be bug compatible */
+	if (sumext == 1) {
+		/* overwrite the only entry */
+		DPRINTF(VOLUMES, ("\tLinux bugcompat overwriting sole entry\n"));
+		trace = >lvint_trace[0];
+		trace->wpos = 0;
+		return 0;
+	}
+
+	losing = MIN(sumext, UDF_LVINT_LOSSAGE);
+
+	/* no sense wiping too much */
+	if (sumext == UDF_LVINT_LOSSAGE)
+		losing = UDF_LVINT_LOSSAGE/2;
 
 	DPRINTF(VOLUMES, ("\tlosing %d entries\n", losing));
 
@@ -1435,7 +1446,6 @@ udf_writeout_lvint(struct udf_mount *ump
 
 	DPRINTF(VOLUMES, ("writing out logvol integrity descriptor\n"));
 
-again:
 	/* get free space in last chunk */
 	trace = ump->lvint_trace;
 	while (trace->wpos > (trace->end - trace->start)) {
@@ -1463,11 +1473,20 @@ again:
 	if (space < 1) {
 		if (lvflag & UDF_APPENDONLY_LVINT)
 			return EROFS;
+
 		/* loose history by re-writing extents */
 		error = udf_loose_lvint_history(ump);
 		if (error)
 			return error;
-		goto again;
+
+		trace = ump->lvint_trace;
+		while (trace->wpos > (trace->end - trace->start))
+			trace++;
+		space = (trace->end - trace->start) - trace->wpos;
+		DPRINTF(VOLUMES, ("new try: write start = %d, end = %d, "
+  "pos = %d, wpos = %d, "
+  "space = %d\n", trace->start, trace->end,
+  trace->pos, trace->wpos, space));
 	}
 
 	/* update our integrity descriptor to identify us and timestamp it */
@@ -1671,6 +1690,14 @@ udf_write_physical_partition_spacetables
 		DPRINTF(VOLUMES, ("Write unalloc. space bitmap %d\n",
 			lb_num + ptov));
 		dscr = (union dscrptr *) ump->part_unalloc_dscr[phys_part];
+
+		/* force a sane minimum for descriptors CRC length */
+		/* see UDF 2.3.1.2 and 2.3.8.1 */
+		KASSERT(udf_rw16(dscr->sbd.tag.id) == TAGID_SPACE_BITMAP);
+		if (udf_rw16(dscr->sbd.tag.desc_crc_len) == 0)
+			dscr->sbd.tag.desc_crc_len = udf_rw16(8);
+
+		/* write out space bitmap */
 		error = udf_write_phys_dscr_sync(ump, NULL, UDF_C_DSCR,
 (union dscrptr *) dscr,
 ptov + lb_num, lb_num);
@@ -1697,6 +1724,14 @@ udf_write_physical_partition_spacetables
 		DPRINTF(VOLUMES, ("Write freed space bitmap %d\n",
 			lb_num + ptov));
 		dscr = (union dscrptr *) ump->part_freed_dscr[phys_part];
+
+		/* force a sane minimum for descriptors CRC length */
+		/* see UDF 2.3.1.2 and 2.3.8.1 */
+		KASSERT(udf_rw16(dscr->sbd.tag.id) == TAGID_SPACE_BITMAP);
+		if (udf_rw16(dscr->sbd.tag.desc_crc_len) == 0)
+			dscr->sbd.tag.desc_crc_len = udf_rw16(8);
+
+		/* write out space bitmap */
 		error = udf_write_phys_dscr_sync(ump, NULL, UDF_C_DSCR,
 (union dscrptr *) dscr,
 ptov + lb_num, lb_num);



CVS commit: src/usr.bin/make

2018-07-12 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu Jul 12 17:46:37 UTC 2018

Modified Files:
src/usr.bin/make: dir.c

Log Message:
Remove duplicate code in make(1)'s dir.c.

When the cached_stats() code was added, some old logic stayed around that
implements the cached_stats() too.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/make/dir.c

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

Modified files:

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.71 src/usr.bin/make/dir.c:1.72
--- src/usr.bin/make/dir.c:1.71	Sun Apr 16 21:14:47 2017
+++ src/usr.bin/make/dir.c	Thu Jul 12 17:46:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.71 2017/04/16 21:14:47 riastradh Exp $	*/
+/*	$NetBSD: dir.c,v 1.72 2018/07/12 17:46:37 reinoud Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.71 2017/04/16 21:14:47 riastradh Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.72 2018/07/12 17:46:37 reinoud Exp $";
 #else
 #include 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.71 2017/04/16 21:14:47 riastradh Exp $");
+__RCSID("$NetBSD: dir.c,v 1.72 2018/07/12 17:46:37 reinoud Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -268,15 +268,6 @@ struct cache_st {
 };
 
 /* minimize changes below */
-static time_t
-Hash_GetTimeValue(Hash_Entry *entry)
-{
-struct cache_st *cst;
-
-cst = entry->clientPtr;
-return cst->mtime;
-}
-
 #define CST_LSTAT 1
 #define CST_UPDATE 2
 
@@ -1134,7 +1125,6 @@ Dir_FindFile(const char *name, Lst path)
 Boolean	  hasLastDot = FALSE;	/* true we should search dot last */
 Boolean	  hasSlash;		/* true if 'name' contains a / */
 struct stat	  stb;			/* Buffer for stat, if necessary */
-Hash_Entry	  *entry;		/* Entry for mtimes table */
 const char   *trailing_dot = ".";
 
 /*
@@ -1395,13 +1385,7 @@ Dir_FindFile(const char *name, Lst path)
 }
 
 bigmisses += 1;
-entry = Hash_FindEntry(, name);
-if (entry != NULL) {
-	if (DEBUG(DIR)) {
-	fprintf(debug_file, "   got it (in mtime cache)\n");
-	}
-	return(bmake_strdup(name));
-} else if (cached_stat(name, ) == 0) {
+if (cached_stat(name, ) == 0) {
 	if (DEBUG(DIR)) {
 	fprintf(debug_file, "   Caching %s for %s\n", Targ_FmtTime(stb.st_mtime),
 		name);
@@ -1518,7 +1502,6 @@ Dir_MTime(GNode *gn, Boolean recheck)
 {
 char  *fullName;  /* the full pathname of name */
 struct stat	  stb;	  /* buffer for finding the mod time */
-Hash_Entry	  *entry;
 
 if (gn->type & OP_ARCHV) {
 	return Arch_MTime(gn);
@@ -1569,17 +1552,11 @@ Dir_MTime(GNode *gn, Boolean recheck)
 	fullName = bmake_strdup(gn->name);
 }
 
-if (!recheck)
-	entry = Hash_FindEntry(, fullName);
-else
-	entry = NULL;
-if (entry != NULL) {
-	stb.st_mtime = Hash_GetTimeValue(entry);
-	if (DEBUG(DIR)) {
-	fprintf(debug_file, "Using cached time %s for %s\n",
-		Targ_FmtTime(stb.st_mtime), fullName);
+if (cached_stats(, fullName, , recheck ? CST_UPDATE : 0) < 0) {
+if (DEBUG(DIR)) {
+fprintf(debug_file, "Using cached time %s for %s\n",
+		Targ_FmtTime(stb.st_mtime), fullName);
 	}
-} else if (cached_stats(, fullName, , recheck ? CST_UPDATE : 0) < 0) {
 	if (gn->type & OP_MEMBER) {
 	if (fullName != gn->path)
 		free(fullName);



CVS commit: src/sys/arch/usermode/dev

2018-06-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jun 13 19:59:14 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: vatapi.c

Log Message:
Split out error reporting and make it compile without SCSIVERBOSE


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/usermode/dev/vatapi.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/usermode/dev/vatapi.c
diff -u src/sys/arch/usermode/dev/vatapi.c:1.1 src/sys/arch/usermode/dev/vatapi.c:1.2
--- src/sys/arch/usermode/dev/vatapi.c:1.1	Tue Jun  5 20:02:43 2018
+++ src/sys/arch/usermode/dev/vatapi.c	Wed Jun 13 19:59:14 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: vatapi.c,v 1.1 2018/06/05 20:02:43 reinoud Exp $ */
+/* $NetBSD: vatapi.c,v 1.2 2018/06/13 19:59:14 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2018 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vatapi.c,v 1.1 2018/06/05 20:02:43 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vatapi.c,v 1.2 2018/06/13 19:59:14 reinoud Exp $");
 
 #include 
 #include 
@@ -48,6 +48,8 @@ __KERNEL_RCSID(0, "$NetBSD: vatapi.c,v 1
 #include 
 #include 
 
+#include "opt_scsi.h"
+
 /* parameter? */
 #define VDEV_ATAPI_DRIVE	0
 #define MAX_SIZE		((1<<16))
@@ -68,7 +70,9 @@ static void	vatapi_probe_device(struct a
 static void	vatapi_complete(void *arg);
 
 /* for debugging */
+#ifdef SCSIVERBOSE
 void	scsipi_print_sense_data_real(struct scsi_sense_data *sense, int verbosity);
+#endif
 
 
 /* Note its one vdev, one adapter, one channel for now */
@@ -279,6 +283,21 @@ vatapi_scsipi_request(struct scsipi_chan
 
 
 static void
+vatapi_report_problem(scsireq_t *kreq)
+{
+#ifdef SCSIVERBOSE
+	printf("vatapi cmd failed: ");
+	for (int i = 0; i < kreq->cmdlen; i++) {
+		printf("%02x ", kreq->cmd[i]);
+	}
+	printf("\n");
+	scsipi_print_sense_data_real(
+		(struct scsi_sense_data *) kreq->sense, 1);
+#endif
+}
+
+
+static void
 vatapi_complete(void *arg)
 {
 	struct vatapi_softc *sc = arg;
@@ -316,8 +335,7 @@ vatapi_complete(void *arg)
 			xs->error = XS_SHORTSENSE;	/* ATAPI */
 			memcpy(>sense.scsi_sense, kreq.sense,
 sizeof(struct scsi_sense_data));
-//			scsipi_print_sense_data_real(
-//(struct scsi_sense_data *) kreq.sense, 1);
+			vatapi_report_problem();
 			break;
 		default:
 			thunk_printf("unhandled/unknown retstst %d\n", kreq.retsts);



CVS commit: src/sys/arch/usermode/usermode

2018-06-11 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jun 11 19:35:56 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: machdep.c

Log Message:
Now we use timestamp info, use direct console output instead of kernel
timestamped output for usage() reporting


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/usermode/usermode/machdep.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/usermode/usermode/machdep.c
diff -u src/sys/arch/usermode/usermode/machdep.c:1.55 src/sys/arch/usermode/usermode/machdep.c:1.56
--- src/sys/arch/usermode/usermode/machdep.c:1.55	Tue Jun  5 20:02:43 2018
+++ src/sys/arch/usermode/usermode/machdep.c	Mon Jun 11 19:35:56 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.55 2018/06/05 20:02:43 reinoud Exp $ */
+/* $NetBSD: machdep.c,v 1.56 2018/06/11 19:35:56 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -37,7 +37,7 @@
 #include "opt_memsize.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.55 2018/06/05 20:02:43 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.56 2018/06/11 19:35:56 reinoud Exp $");
 
 #include 
 #include 
@@ -99,7 +99,7 @@ void	usermode_reboot(void);
 static void
 usage(const char *pn)
 {
-	printf("usage: %s [-acdqsvxz]"
+	thunk_printf("usage: %s [-acdqsvxz]"
 	" [net=,]"
 	" [audio=]"
 	" [disk= ...]"
@@ -107,7 +107,7 @@ usage(const char *pn)
 	" [vnc=x,]"
 	" [vdev=atapi,device]\n",
 	pn);
-	printf("   (ex. \"%s"
+	thunk_printf("   (ex. \"%s"
 	" net=tap0,00:00:be:ef:ca:fe"
 	" audio=audio0"
 	" disk=root.fs"
@@ -156,7 +156,7 @@ main(int argc, char *argv[])
 char *mac = strchr(tap, ',');
 char *p = usermode_tap_devicebuf;
 if (mac == NULL) {
-	printf("bad net= format\n");
+	thunk_printf("bad net= format\n");
 	return;
 }
 memset(usermode_tap_devicebuf, 0,
@@ -189,13 +189,13 @@ main(int argc, char *argv[])
 w = vnc;
 h = strchr(w, 'x');
 if (h == NULL) {
-	printf("bad vnc= format\n");
+	thunk_printf("bad vnc= format\n");
 	return;
 }
 *h++ = '\0';
 p = strchr(h, ',');
 if (p == NULL) {
-	printf("bad vnc= format\n");
+	thunk_printf("bad vnc= format\n");
 	return;
 }
 *p++ = '\0';
@@ -206,7 +206,7 @@ main(int argc, char *argv[])
 			strlen("disk=")) == 0) {
 if (usermode_disk_image_path_count ==
 MAX_DISK_IMAGES) {
-	printf("too many disk images "
+	thunk_printf("too many disk images "
 	"(increase MAX_DISK_IMAGES)\n");
 	usage(argv[0]);
 	return;
@@ -220,7 +220,7 @@ main(int argc, char *argv[])
 char *t, *p;
 if (usermode_disk_image_path_count ==
 MAX_VDEVS) {
-	printf("too many vdevs "
+	thunk_printf("too many vdevs "
 	"(increase MAX_VDEVS)\n");
 	usage(argv[0]);
 	return;
@@ -228,13 +228,13 @@ main(int argc, char *argv[])
 t = vdev;
 p = strchr(t, ',');
 if (p == NULL) {
-	printf("bad vdev= format\n");
+	thunk_printf("bad vdev= format\n");
 	return;
 }
 *p++ = '\0';
 type = vdev_type(t);
 if (type < 0) {
-	printf("unknown vdev device type\n");
+	thunk_printf("unknown vdev device type\n");
 	return;
 }
 usermode_vdev_type[usermode_vdev_count] = type;
@@ -245,7 +245,7 @@ main(int argc, char *argv[])
 usermode_root_device = argv[i] +
 strlen("root=");
 			} else {
-printf("%s: unknown parameter\n", argv[i]);
+thunk_printf("%s: unknown parameter\n", argv[i]);
 usage(argv[0]);
 return;
 			}
@@ -255,7 +255,7 @@ main(int argc, char *argv[])
 			r = 0;
 			BOOT_FLAG(argv[i][j], r);
 			if (r == 0) {
-printf("-%c: unknown flag\n", argv[i][j]);
+thunk_printf("unknown kernel boot flag '%c'\n", argv[i][j]);
 usage(argv[0]);
 return;
 			}



CVS commit: src/sys/arch/usermode/usermode

2018-06-11 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jun 11 19:23:21 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: trap.c

Log Message:
Prevent nested SIGIOs ruining the system stack


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/usermode/usermode/trap.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/usermode/usermode/trap.c
diff -u src/sys/arch/usermode/usermode/trap.c:1.67 src/sys/arch/usermode/usermode/trap.c:1.68
--- src/sys/arch/usermode/usermode/trap.c:1.67	Fri May 18 20:24:16 2018
+++ src/sys/arch/usermode/usermode/trap.c	Mon Jun 11 19:23:21 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.67 2018/05/18 20:24:16 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.68 2018/06/11 19:23:21 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.67 2018/05/18 20:24:16 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.68 2018/06/11 19:23:21 reinoud Exp $");
 
 #include 
 #include 
@@ -335,7 +335,9 @@ handle_signal(int sig, siginfo_t *info, 
 	if (sig == SIGILL)
 		print_illegal_instruction_siginfo(sig, info, ctx, pc, va, sp);
 
-	/* if we're running on a stack of our own, use the system stack */
+	/* currently running on the dedicated signal stack */
+
+	/* if we're running on a userland stack, switch to the system stack */
 	from_userland = 0;
 	if ((sp < (vaddr_t) pcb->sys_stack) ||
 	(sp > (vaddr_t) pcb->sys_stack_top)) {
@@ -361,7 +363,11 @@ handle_signal(int sig, siginfo_t *info, 
 	jump_ucp.uc_stack.ss_size = sp - (vaddr_t) pcb->sys_stack;
 	jump_ucp.uc_link = (void *) fp;	/* link to old frame on stack */
 
-	thunk_sigemptyset(_ucp.uc_sigmask);
+	/* prevent multiple nested SIGIOs */
+	if (sig == SIGIO)
+		thunk_sigfillset(_ucp.uc_sigmask);
+	else
+		thunk_sigemptyset(_ucp.uc_sigmask);
 	jump_ucp.uc_flags = _UC_STACK | _UC_CPU | _UC_SIGMASK;
 
 	thunk_makecontext(_ucp,



CVS commit: src/sys/arch/usermode

2018-06-05 Thread Reinoud Zandijk
g_found_ia(self, "thunkbus", , mainbus_print);
+	}
 }
 
 static int

Index: src/sys/arch/usermode/include/mainbus.h
diff -u src/sys/arch/usermode/include/mainbus.h:1.7 src/sys/arch/usermode/include/mainbus.h:1.8
--- src/sys/arch/usermode/include/mainbus.h:1.7	Thu Dec 29 21:22:49 2011
+++ src/sys/arch/usermode/include/mainbus.h	Tue Jun  5 20:02:43 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.h,v 1.7 2011/12/29 21:22:49 jmcneill Exp $ */
+/* $NetBSD: mainbus.h,v 1.8 2018/06/05 20:02:43 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -38,10 +38,15 @@ struct thunkbus_attach_args {
 #define THUNKBUS_TYPE_VNCFB	4
 #define THUNKBUS_TYPE_VETH	5
 #define THUNKBUS_TYPE_VAUDIO	6
+#define THUNKBUS_TYPE_VATAPI	7
+#define THUNKBUS_TYPE_VSCSI	8
 
 	union {
 		struct {
 			const char *path;
+		} vdev;
+		struct {
+			const char *path;
 		} diskimage;
 		struct {
 			const char *device;

Index: src/sys/arch/usermode/usermode/machdep.c
diff -u src/sys/arch/usermode/usermode/machdep.c:1.54 src/sys/arch/usermode/usermode/machdep.c:1.55
--- src/sys/arch/usermode/usermode/machdep.c:1.54	Thu Dec 22 14:47:59 2016
+++ src/sys/arch/usermode/usermode/machdep.c	Tue Jun  5 20:02:43 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.54 2016/12/22 14:47:59 cherry Exp $ */
+/* $NetBSD: machdep.c,v 1.55 2018/06/05 20:02:43 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -37,7 +37,7 @@
 #include "opt_memsize.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.54 2016/12/22 14:47:59 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.55 2018/06/05 20:02:43 reinoud Exp $");
 
 #include 
 #include 
@@ -57,12 +57,17 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #ifndef MAX_DISK_IMAGES
 #define MAX_DISK_IMAGES	4
 #endif
 
+#ifndef MAX_VDEVS
+#define MAX_VDEVS 4
+#endif
+
 char machine[_SYS_NMLN] = "";
 char machine_arch[_SYS_NMLN] = "";
 char module_machine_usermode[_SYS_NMLN] = "";
@@ -74,6 +79,10 @@ static char **saved_argv;
 char *usermode_disk_image_path[MAX_DISK_IMAGES];
 int usermode_disk_image_path_count = 0;
 
+int   usermode_vdev_type[MAX_VDEVS];
+char *usermode_vdev_path[MAX_VDEVS];
+int usermode_vdev_count = 0;
+
 static char usermode_tap_devicebuf[PATH_MAX] = "";
 char *usermode_tap_device = NULL;
 char *usermode_tap_eaddr = NULL;
@@ -95,23 +104,39 @@ usage(const char *pn)
 	" [audio=]"
 	" [disk= ...]"
 	" [root=]"
-	" [vnc=x,]\n",
+	" [vnc=x,]"
+	" [vdev=atapi,device]\n",
 	pn);
 	printf("   (ex. \"%s"
 	" net=tap0,00:00:be:ef:ca:fe"
 	" audio=audio0"
 	" disk=root.fs"
 	" root=ld0"
-	" vnc=640x480,5900\")\n", pn);
+	" vnc=640x480,5900"
+	" vdev=atapi,/dev/rcd0d\")\n", pn);
+}
+
+
+static int
+vdev_type(const char *type)
+{
+	if (strcasecmp(type, "atapi")==0)
+		return THUNKBUS_TYPE_VATAPI;
+#if 0
+	if (strcasecmp(type, "scsi")==0)
+		return THUNKBUS_TYPE_VSCSI;
+#endif
+	return -1;
 }
 
+
 void
 main(int argc, char *argv[])
 {
 	extern void ttycons_consinit(void);
 	extern void pmap_bootstrap(void);
 	extern void kernmain(void);
-	int i, j, r, tmpopt = 0;
+	int type, i, j, r, tmpopt = 0;
 
 	saved_argv = argv;
 
@@ -189,6 +214,32 @@ main(int argc, char *argv[])
 usermode_disk_image_path[
 usermode_disk_image_path_count++] =
 argv[i] + strlen("disk=");
+			} else if (strncmp(argv[i], "vdev=",
+			strlen("vdev=")) == 0) {
+char *vdev = argv[i] + strlen("vdev=");
+char *t, *p;
+if (usermode_disk_image_path_count ==
+MAX_VDEVS) {
+	printf("too many vdevs "
+	"(increase MAX_VDEVS)\n");
+	usage(argv[0]);
+	return;
+}
+t = vdev;
+p = strchr(t, ',');
+if (p == NULL) {
+	printf("bad vdev= format\n");
+	return;
+}
+*p++ = '\0';
+type = vdev_type(t);
+if (type < 0) {
+	printf("unknown vdev device type\n");
+	return;
+}
+usermode_vdev_type[usermode_vdev_count] = type;
+usermode_vdev_path[usermode_vdev_count] = p;
+usermode_vdev_count++;
 			} else if (strncmp(argv[i], "root=",
 			strlen("root=")) == 0) {
 usermode_root_device = argv[i] +

Added files:

Index: src/sys/arch/usermode/dev/vatapi.c
diff -u /dev/null src/sys/arch/usermode/dev/vatapi.c:1.1
--- /dev/null	Tue Jun  5 20:02:43 2018
+++ src/sys/arch/usermode/dev/vatapi.c	Tue Jun  5 20:02:43 2018
@@ -0,0 +1,345 @@
+/* $NetBSD: vatapi.c,v 1.1 2018/06/05 20:02:43 reinoud Exp $ */
+
+/*-
+ * Copyright (c) 2018 Reinoud Zandijk 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without

CVS commit: src/sys/arch/usermode/dev

2018-06-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jun  4 20:06:52 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: ld_thunkbus.c

Log Message:
Its a hack, but make sure the pages are paged in


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/usermode/dev/ld_thunkbus.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/usermode/dev/ld_thunkbus.c
diff -u src/sys/arch/usermode/dev/ld_thunkbus.c:1.32 src/sys/arch/usermode/dev/ld_thunkbus.c:1.33
--- src/sys/arch/usermode/dev/ld_thunkbus.c:1.32	Sat Jan 13 10:27:58 2018
+++ src/sys/arch/usermode/dev/ld_thunkbus.c	Mon Jun  4 20:06:52 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_thunkbus.c,v 1.32 2018/01/13 10:27:58 reinoud Exp $ */
+/* $NetBSD: ld_thunkbus.c,v 1.33 2018/06/04 20:06:52 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.32 2018/01/13 10:27:58 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.33 2018/06/04 20:06:52 reinoud Exp $");
 
 #include 
 #include 
@@ -271,6 +271,9 @@ ld_thunkbus_complete(void *arg)
 	//bp->b_flags & B_READ ? "read" : "write",
 	//(unsigned int)bp->b_bcount, (long long)offset, bp->b_data, bp->b_flags);
 
+	/* this is silly, but better make sure */
+	thunk_assert_presence((vaddr_t) bp->b_data, (size_t) bp->b_bcount);
+
 	/* read/write the request */
 	if (bp->b_flags & B_READ) {
 		ret = thunk_pread(sc->sc_fd, bp->b_data, bp->b_bcount, offset);
@@ -285,6 +288,7 @@ ld_thunkbus_complete(void *arg)
 	if ((ret >= 0) && (ret == bp->b_bcount)) {
 		bp->b_resid = 0;
 	} else {
+		// printf("ret = %d, errno %d?\n",(int) ret, thunk_geterrno());
 		bp->b_error = thunk_geterrno();
 		bp->b_resid = bp->b_bcount;
 	}



CVS commit: src/sys/arch/usermode

2018-06-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jun  4 19:53:01 UTC 2018

Modified Files:
src/sys/arch/usermode/include: thunk.h
src/sys/arch/usermode/usermode: thunk.c

Log Message:
Enhance the NetBSD/usermode thunk interface


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/usermode/include/thunk.h
cvs rdiff -u -r1.89 -r1.90 src/sys/arch/usermode/usermode/thunk.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/usermode/include/thunk.h
diff -u src/sys/arch/usermode/include/thunk.h:1.64 src/sys/arch/usermode/include/thunk.h:1.65
--- src/sys/arch/usermode/include/thunk.h:1.64	Fri Jun  1 08:04:57 2018
+++ src/sys/arch/usermode/include/thunk.h	Mon Jun  4 19:53:01 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.h,v 1.64 2018/06/01 08:04:57 reinoud Exp $ */
+/* $NetBSD: thunk.h,v 1.65 2018/06/04 19:53:01 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -92,6 +92,7 @@ timer_t	thunk_timer_attach(void);
 int	thunk_timer_start(timer_t, int);
 int	thunk_timer_getoverrun(timer_t);
 
+void	thunk_kill(pid_t pid, int sig);
 void	thunk_exit(int);
 void	thunk_abort(void);
 
@@ -136,6 +137,8 @@ int	thunk_sigfillset(sigset_t *sa_mask);
 void	thunk_sigaddset(sigset_t *sa_mask, int sig);
 int	thunk_sigprocmask(int how, const sigset_t * set, sigset_t *oset);
 int	thunk_atexit(void (*function)(void));
+pid_t	thunk_fork(void);
+int	thunk_ioctl(int fd, unsigned long request, void *opaque);
 
 int	thunk_aio_read(struct aiocb *);
 int	thunk_aio_write(struct aiocb *);
@@ -166,6 +169,8 @@ int	thunk_open_tap(const char *);
 int	thunk_pollin_tap(int, int);
 int	thunk_pollout_tap(int, int);
 
+int	thunk_assert_presence(vaddr_t from, size_t size);
+
 typedef struct {
 	unsigned int		sample_rate;
 	unsigned int		precision;

Index: src/sys/arch/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.89 src/sys/arch/usermode/usermode/thunk.c:1.90
--- src/sys/arch/usermode/usermode/thunk.c:1.89	Fri Jun  1 08:04:57 2018
+++ src/sys/arch/usermode/usermode/thunk.c	Mon Jun  4 19:53:01 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.89 2018/06/01 08:04:57 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.90 2018/06/04 19:53:01 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.89 2018/06/01 08:04:57 reinoud Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.90 2018/06/04 19:53:01 reinoud Exp $");
 #endif
 
 #define _KMEMUSER
@@ -36,6 +36,7 @@ __RCSID("$NetBSD: thunk.c,v 1.89 2018/06
 #define _I386_MACHTYPES_H_
 
 #include "../include/types.h"
+
 #include 
 #include 
 #include 
@@ -344,6 +345,12 @@ thunk_usleep(useconds_t microseconds)
 }
 
 void
+thunk_kill(pid_t pid, int sig)
+{
+	kill(pid, sig);
+}
+
+void
 thunk_exit(int status)
 {
 	return exit(status);
@@ -646,6 +653,18 @@ thunk_atexit(void (*function)(void))
 	return atexit(function);
 }
 
+pid_t
+thunk_fork(void)
+{
+	return fork();
+}
+
+int
+thunk_ioctl(int fd, unsigned long request, void *opaque)
+{
+	return ioctl(fd, request, opaque);
+}
+
 int
 thunk_aio_read(struct aiocb *aiocbp)
 {
@@ -862,6 +881,21 @@ thunk_pollout_tap(int fd, int timeout)
 	return poll(fds, __arraycount(fds), timeout);
 }
 
+
+/* simply make sure its present... yeah its silly */
+int
+thunk_assert_presence(vaddr_t from, size_t size)
+{
+	vaddr_t va;
+	int t = 0;
+
+	for (va = from; va < from + (vaddr_t) size; va += PAGE_SIZE) {
+		t += *(int *) va;
+	}
+	return t;
+}
+
+
 int
 thunk_audio_open(const char *path)
 {



CVS commit: src/sys/arch/usermode

2018-06-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Jun  1 08:04:57 UTC 2018

Modified Files:
src/sys/arch/usermode/include: thunk.h
src/sys/arch/usermode/usermode: thunk.c

Log Message:
Pretend we already included the 


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/usermode/include/thunk.h
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/usermode/usermode/thunk.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/usermode/include/thunk.h
diff -u src/sys/arch/usermode/include/thunk.h:1.63 src/sys/arch/usermode/include/thunk.h:1.64
--- src/sys/arch/usermode/include/thunk.h:1.63	Fri May 18 20:24:57 2018
+++ src/sys/arch/usermode/include/thunk.h	Fri Jun  1 08:04:57 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.h,v 1.63 2018/05/18 20:24:57 reinoud Exp $ */
+/* $NetBSD: thunk.h,v 1.64 2018/06/01 08:04:57 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -29,7 +29,7 @@
 #ifndef _ARCH_USERMODE_INCLUDE_THUNK_H
 #define _ARCH_USERMODE_INCLUDE_THUNK_H
 
-#include "types.h"
+#include 
 #include 
 #include 
 #include 

Index: src/sys/arch/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.88 src/sys/arch/usermode/usermode/thunk.c:1.89
--- src/sys/arch/usermode/usermode/thunk.c:1.88	Fri May 18 05:51:23 2018
+++ src/sys/arch/usermode/usermode/thunk.c	Fri Jun  1 08:04:57 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.88 2018/05/18 05:51:23 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.89 2018/06/01 08:04:57 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -28,9 +28,13 @@
 
 #include 
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.88 2018/05/18 05:51:23 reinoud Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.89 2018/06/01 08:04:57 reinoud Exp $");
 #endif
 
+#define _KMEMUSER
+#define _X86_64_MACHTYPES_H_
+#define _I386_MACHTYPES_H_
+
 #include "../include/types.h"
 #include 
 #include 
@@ -42,7 +46,6 @@ __RCSID("$NetBSD: thunk.c,v 1.88 2018/05
 #include 
 #include 
 
-#define _KMEMUSER
 #include 
 
 #include 
@@ -70,6 +73,7 @@ __RCSID("$NetBSD: thunk.c,v 1.88 2018/05
 #include 
 #include 
 #include 
+#include 
 
 #include "../include/thunk.h"
 



CVS commit: src/sys/arch/usermode/dev

2018-06-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Jun  1 07:26:15 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: cpu.c

Log Message:
Pass the address of the array, this fixes issues with i386 compilation


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/usermode/dev/cpu.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/usermode/dev/cpu.c
diff -u src/sys/arch/usermode/dev/cpu.c:1.79 src/sys/arch/usermode/dev/cpu.c:1.80
--- src/sys/arch/usermode/dev/cpu.c:1.79	Tue May 29 09:25:01 2018
+++ src/sys/arch/usermode/dev/cpu.c	Fri Jun  1 07:26:15 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.79 2018/05/29 09:25:01 reinoud Exp $ */
+/* $NetBSD: cpu.c,v 1.80 2018/06/01 07:26:15 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -30,7 +30,7 @@
 #include "opt_hz.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.79 2018/05/29 09:25:01 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.80 2018/06/01 07:26:15 reinoud Exp $");
 
 #include 
 #include 
@@ -353,9 +353,9 @@ cpu_setmcontext(struct lwp *l, const mco
 	thunk_printf_debug("cpu_setmcontext\n");
 #endif
 	if ((flags & _UC_CPU) != 0)
-		memcpy(>uc_mcontext.__gregs, mcp->__gregs, sizeof(__gregset_t));
+		memcpy(>uc_mcontext.__gregs, >__gregs, sizeof(__gregset_t));
 	if ((flags & _UC_FPU) != 0)
-		memcpy(>uc_mcontext.__fpregs, mcp->__fpregs, sizeof(__fpregset_t));
+		memcpy(>uc_mcontext.__fpregs, >__fpregs, sizeof(__fpregset_t));
 	if ((flags & _UC_TLSBASE) != 0)
 		lwp_setprivate(l, (void *) (uintptr_t) mcp->_mc_tlsbase);
 



CVS commit: src/sys/arch/usermode/conf

2018-06-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Jun  1 07:22:33 UTC 2018

Modified Files:
src/sys/arch/usermode/conf: Makefile.usermode

Log Message:
Compile NetBSD/userland without CTF for the linker doesn't allow for a single
file compiled without CTF


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/usermode/conf/Makefile.usermode

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/usermode/conf/Makefile.usermode
diff -u src/sys/arch/usermode/conf/Makefile.usermode:1.41 src/sys/arch/usermode/conf/Makefile.usermode:1.42
--- src/sys/arch/usermode/conf/Makefile.usermode:1.41	Sat Jan 13 16:20:33 2018
+++ src/sys/arch/usermode/conf/Makefile.usermode	Fri Jun  1 07:22:33 2018
@@ -1,5 +1,6 @@
-# $NetBSD: Makefile.usermode,v 1.41 2018/01/13 16:20:33 reinoud Exp $
+# $NetBSD: Makefile.usermode,v 1.42 2018/06/01 07:22:33 reinoud Exp $
 
+MKCTF?=no
 USETOOLS?=			no
 NEED_OWN_INSTALL_TARGET?=	no
 .include 



CVS commit: src/sys/arch/usermode/include

2018-06-01 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Jun  1 07:19:50 UTC 2018

Modified Files:
src/sys/arch/usermode/include: types.h

Log Message:
Fix compilation errors so NetBSD/usermode compiles under ./build.sh


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/usermode/include/types.h

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/usermode/include/types.h
diff -u src/sys/arch/usermode/include/types.h:1.13 src/sys/arch/usermode/include/types.h:1.14
--- src/sys/arch/usermode/include/types.h:1.13	Tue May 29 07:35:39 2018
+++ src/sys/arch/usermode/include/types.h	Fri Jun  1 07:19:50 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.13 2018/05/29 07:35:39 reinoud Exp $ */
+/* $NetBSD: types.h,v 1.14 2018/06/01 07:19:50 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -40,9 +40,31 @@ typedef struct label_t {
 #endif
 
 #if defined(_KERNEL) || defined(_KMEMUSER) || defined(_KERNTYPES) || defined(_STANDALONE)
+#if defined(__i386__) || defined(__arm__)
 typedef unsigned long	paddr_t;
 typedef unsigned long	psize_t;
-typedef unsigned long	vaddr_t;
+typedef unsigned long	__vaddr_t;
+typedef unsigned long	vsize_t;
+typedef int		register_t;
+
+#ifndef __x86_64__
+// XXX hack to allow for amd64->i386 crosscompile, why?
+#define	PRIxPADDR	"lx"
+#define	PRIxPSIZE	"lx"
+#define	PRIuPSIZE	"lu"
+#else
+#define	PRIxPADDR	"llx"
+#define	PRIxPSIZE	"llx"
+#define	PRIuPSIZE	"llu"
+#endif
+#define	PRIxVADDR	"lx"
+#define	PRIxVSIZE	"lx"
+#define	PRIuVSIZE	"lu"
+#define	PRIxREGISTER	"lx"
+#elif defined(__x86_64__)
+typedef unsigned long	paddr_t;
+typedef unsigned long	psize_t;
+typedef unsigned long	__vaddr_t;
 typedef unsigned long	vsize_t;
 typedef long int	register_t;
 #define	PRIxPADDR	"lx"
@@ -53,9 +75,11 @@ typedef long int	register_t;
 #define	PRIuVSIZE	"lu"
 #define	PRIxREGISTER	"lx"
 #endif
+#endif
 
+typedef __vaddr_t	vaddr_t;
 typedef unsigned char	__cpu_simple_lock_nv_t;
-typedef long int	__register_t;
+typedef register_t	__register_t;
 
 #define __CPU_SIMPLE_LOCK_PAD
 



CVS commit: src/sys/arch/usermode/dev

2018-05-29 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue May 29 09:25:01 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: cpu.c

Log Message:
Only report the things we've passed in the mcontext and leave out flags that
are not reported in the mcontext anyway!


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/usermode/dev/cpu.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/usermode/dev/cpu.c
diff -u src/sys/arch/usermode/dev/cpu.c:1.78 src/sys/arch/usermode/dev/cpu.c:1.79
--- src/sys/arch/usermode/dev/cpu.c:1.78	Tue May 29 07:35:40 2018
+++ src/sys/arch/usermode/dev/cpu.c	Tue May 29 09:25:01 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.78 2018/05/29 07:35:40 reinoud Exp $ */
+/* $NetBSD: cpu.c,v 1.79 2018/05/29 09:25:01 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -30,7 +30,7 @@
 #include "opt_hz.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.78 2018/05/29 07:35:40 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.79 2018/05/29 09:25:01 reinoud Exp $");
 
 #include 
 #include 
@@ -322,9 +322,9 @@ cpu_getmcontext(struct lwp *l, mcontext_
 #endif
 	memcpy(mcp, >uc_mcontext, sizeof(mcontext_t));
 
-	/* XXX be overzealous and provide all */
+	/* report we have the CPU FPU and TLSBASE registers */
 	mcp->_mc_tlsbase = (uintptr_t) l->l_private;
-	*flags = _UC_CPU | _UC_STACK | _UC_SIGMASK | _UC_FPU | _UC_TLSBASE;
+	*flags = _UC_CPU | _UC_FPU | _UC_TLSBASE;
 
 	return;
 }
@@ -338,7 +338,7 @@ cpu_mcontext_validate(struct lwp *l, con
 	 */
 	/* XXX NO CHECKING! XXX */
 #ifdef CPU_DEBUG
-	thunk_printf("cpu_mcontext_validate\n");
+	thunk_printf_debug("cpu_mcontext_validate\n");
 #endif
 	return 0;
 }



CVS commit: src/sys/arch/usermode

2018-05-29 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue May 29 07:35:40 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: cpu.c
src/sys/arch/usermode/include: types.h

Log Message:
Implement cpu_lwp_setprivate(). This removes the need for the cpu_switch()
hack.

Programs with TLS work fine now, including gdb!


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/usermode/dev/cpu.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/usermode/include/types.h

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/usermode/dev/cpu.c
diff -u src/sys/arch/usermode/dev/cpu.c:1.77 src/sys/arch/usermode/dev/cpu.c:1.78
--- src/sys/arch/usermode/dev/cpu.c:1.77	Tue May 29 07:09:21 2018
+++ src/sys/arch/usermode/dev/cpu.c	Tue May 29 07:35:40 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.77 2018/05/29 07:09:21 reinoud Exp $ */
+/* $NetBSD: cpu.c,v 1.78 2018/05/29 07:35:40 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -30,7 +30,7 @@
 #include "opt_hz.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.77 2018/05/29 07:09:21 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.78 2018/05/29 07:35:40 reinoud Exp $");
 
 #include 
 #include 
@@ -193,6 +193,22 @@ cpu_need_proftick(struct lwp *l)
 {
 }
 
+int
+cpu_lwp_setprivate(lwp_t *l, void *ptr)
+{
+	struct pcb *pcb = lwp_getpcb(l);
+
+	/* set both ucontexts up for TLS just in case */
+	pcb->pcb_ucp.uc_mcontext._mc_tlsbase =
+		(uintptr_t) ptr;
+	pcb->pcb_ucp.uc_flags |= _UC_TLSBASE;
+
+	pcb->pcb_userret_ucp.uc_mcontext._mc_tlsbase =
+		(uintptr_t) ptr;
+	pcb->pcb_userret_ucp.uc_flags |= _UC_TLSBASE;
+
+	return 0;
+}
 
 static
 void
@@ -214,18 +230,8 @@ cpu_switchto_atomic(lwp_t *oldlwp, lwp_t
 		oldpcb->pcb_errno = thunk_geterrno();
 
 	thunk_seterrno(newpcb->pcb_errno);
-
-	/* set both ucontexts up for TLS just in case */
-
-	newpcb->pcb_ucp.uc_mcontext._mc_tlsbase =
-		(uintptr_t) newlwp->l_private;
-	newpcb->pcb_ucp.uc_flags |= _UC_TLSBASE;
-
-	newpcb->pcb_userret_ucp.uc_mcontext._mc_tlsbase =
-		(uintptr_t) newlwp->l_private;
-	newpcb->pcb_userret_ucp.uc_flags |= _UC_TLSBASE;
-
 	curlwp = newlwp;
+
 	splx(s);
 
 	if (thunk_setcontext(>pcb_ucp))

Index: src/sys/arch/usermode/include/types.h
diff -u src/sys/arch/usermode/include/types.h:1.12 src/sys/arch/usermode/include/types.h:1.13
--- src/sys/arch/usermode/include/types.h:1.12	Thu Jan 26 15:55:10 2017
+++ src/sys/arch/usermode/include/types.h	Tue May 29 07:35:39 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.12 2017/01/26 15:55:10 christos Exp $ */
+/* $NetBSD: types.h,v 1.13 2018/05/29 07:35:39 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -67,6 +67,7 @@ typedef long int	__register_t;
 #endif
 
 #define __HAVE_CPU_DATA_FIRST
+#define __HAVE_CPU_LWP_SETPRIVATE
 #define __HAVE_MM_MD_KERNACC
 #define	__HAVE_COMPAT_NETBSD32
 



CVS commit: src/sys/arch/usermode/dev

2018-05-29 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue May 29 07:09:22 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: cpu.c

Log Message:
Only set requested parts of the mcontext in cpu_setmcontext()
Make the atomic switcher `atomic' by using splhigh()


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/usermode/dev/cpu.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/usermode/dev/cpu.c
diff -u src/sys/arch/usermode/dev/cpu.c:1.76 src/sys/arch/usermode/dev/cpu.c:1.77
--- src/sys/arch/usermode/dev/cpu.c:1.76	Thu May 24 19:39:04 2018
+++ src/sys/arch/usermode/dev/cpu.c	Tue May 29 07:09:21 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.76 2018/05/24 19:39:04 reinoud Exp $ */
+/* $NetBSD: cpu.c,v 1.77 2018/05/29 07:09:21 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -30,7 +30,7 @@
 #include "opt_hz.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.76 2018/05/24 19:39:04 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.77 2018/05/29 07:09:21 reinoud Exp $");
 
 #include 
 #include 
@@ -194,7 +194,6 @@ cpu_need_proftick(struct lwp *l)
 }
 
 
-/* XXX make sure this is atomic? */
 static
 void
 cpu_switchto_atomic(lwp_t *oldlwp, lwp_t *newlwp)
@@ -202,19 +201,22 @@ cpu_switchto_atomic(lwp_t *oldlwp, lwp_t
 	struct pcb *oldpcb;
 	struct pcb *newpcb;
 	struct cpu_info *ci;
+	int s;
 
 	oldpcb = oldlwp ? lwp_getpcb(oldlwp) : NULL;
 	newpcb = lwp_getpcb(newlwp);
 	ci = curcpu();
 
-	ci->ci_stash = oldlwp;
+	s = splhigh();
 
+	ci->ci_stash = oldlwp;
 	if (oldpcb)
 		oldpcb->pcb_errno = thunk_geterrno();
 
 	thunk_seterrno(newpcb->pcb_errno);
 
 	/* set both ucontexts up for TLS just in case */
+
 	newpcb->pcb_ucp.uc_mcontext._mc_tlsbase =
 		(uintptr_t) newlwp->l_private;
 	newpcb->pcb_ucp.uc_flags |= _UC_TLSBASE;
@@ -224,8 +226,11 @@ cpu_switchto_atomic(lwp_t *oldlwp, lwp_t
 	newpcb->pcb_userret_ucp.uc_flags |= _UC_TLSBASE;
 
 	curlwp = newlwp;
+	splx(s);
+
 	if (thunk_setcontext(>pcb_ucp))
 		panic("setcontext failed");
+
 	/* not reached */
 }
 
@@ -341,11 +346,28 @@ cpu_setmcontext(struct lwp *l, const mco
 #ifdef CPU_DEBUG
 	thunk_printf_debug("cpu_setmcontext\n");
 #endif
-	ucp->uc_flags = flags;
-	memcpy(>uc_mcontext, mcp, sizeof(mcontext_t));
+	if ((flags & _UC_CPU) != 0)
+		memcpy(>uc_mcontext.__gregs, mcp->__gregs, sizeof(__gregset_t));
+	if ((flags & _UC_FPU) != 0)
+		memcpy(>uc_mcontext.__fpregs, mcp->__fpregs, sizeof(__fpregset_t));
+	if ((flags & _UC_TLSBASE) != 0)
+		lwp_setprivate(l, (void *) (uintptr_t) mcp->_mc_tlsbase);
 
-	/* update our private, it might be altered in userland */
-	l->l_private = (void *) ucp->uc_mcontext._mc_tlsbase;
+#if 0
+	/*
+	 * XXX we ignore the set and clear stack since signals are done
+	 * slightly differently.
+	 */
+thunk_printf("%s: flags %x\n", __func__, flags);
+	mutex_enter(l->l_proc->p_lock);
+	if (flags & _UC_SETSTACK)
+		l->l_sigstk.ss_flags |= SS_ONSTACK;
+	if (flags & _UC_CLRSTACK)
+		l->l_sigstk.ss_flags &= ~SS_ONSTACK;
+	mutex_exit(l->l_proc->p_lock);
+#endif
+
+	ucp->uc_flags |= (flags & (_UC_CPU | _UC_FPU | _UC_TLSBASE));
 
 	return 0;
 }
@@ -410,7 +432,6 @@ cpu_lwp_fork(struct lwp *l1, struct lwp 
 	l2 ? l2->l_name : "none", l2,
 	stack, (int)stacksize);
 #endif
-
 	if (stack)
 		panic("%s: stack passed, can't handle\n", __func__);
 



CVS commit: src/sys/arch/usermode/dev

2018-05-24 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu May 24 19:39:04 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: cpu.c

Log Message:
First try at TLS support and getcontext/setcontext/swapcontext support.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/arch/usermode/dev/cpu.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/usermode/dev/cpu.c
diff -u src/sys/arch/usermode/dev/cpu.c:1.75 src/sys/arch/usermode/dev/cpu.c:1.76
--- src/sys/arch/usermode/dev/cpu.c:1.75	Thu May 17 19:00:39 2018
+++ src/sys/arch/usermode/dev/cpu.c	Thu May 24 19:39:04 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.75 2018/05/17 19:00:39 reinoud Exp $ */
+/* $NetBSD: cpu.c,v 1.76 2018/05/24 19:39:04 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -30,7 +30,7 @@
 #include "opt_hz.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.75 2018/05/17 19:00:39 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.76 2018/05/24 19:39:04 reinoud Exp $");
 
 #include 
 #include 
@@ -66,6 +66,11 @@ __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.75
 static int	cpu_match(device_t, cfdata_t, void *);
 static void	cpu_attach(device_t, device_t, void *);
 
+/* XXX */
+//extern void *_lwp_getprivate(void);
+//extern int _lwp_setprivate(void *);
+
+
 struct cpu_info cpu_info_primary = {
 	.ci_dev = 0,
 	.ci_self = _info_primary,
@@ -130,7 +135,6 @@ cpu_configure(void)
 	if (config_rootfound("mainbus", NULL) == NULL)
 		panic("configure: mainbus not configured");
 
-
 	spl0();
 }
 
@@ -189,6 +193,8 @@ cpu_need_proftick(struct lwp *l)
 {
 }
 
+
+/* XXX make sure this is atomic? */
 static
 void
 cpu_switchto_atomic(lwp_t *oldlwp, lwp_t *newlwp)
@@ -208,12 +214,22 @@ cpu_switchto_atomic(lwp_t *oldlwp, lwp_t
 
 	thunk_seterrno(newpcb->pcb_errno);
 
+	/* set both ucontexts up for TLS just in case */
+	newpcb->pcb_ucp.uc_mcontext._mc_tlsbase =
+		(uintptr_t) newlwp->l_private;
+	newpcb->pcb_ucp.uc_flags |= _UC_TLSBASE;
+
+	newpcb->pcb_userret_ucp.uc_mcontext._mc_tlsbase =
+		(uintptr_t) newlwp->l_private;
+	newpcb->pcb_userret_ucp.uc_flags |= _UC_TLSBASE;
+
 	curlwp = newlwp;
 	if (thunk_setcontext(>pcb_ucp))
 		panic("setcontext failed");
 	/* not reached */
 }
 
+
 lwp_t *
 cpu_switchto(lwp_t *oldlwp, lwp_t *newlwp, bool returning)
 {
@@ -232,17 +248,23 @@ cpu_switchto(lwp_t *oldlwp, lwp_t *newlw
 	newlwp ? newlwp->l_lid : -1);
 	if (oldpcb) {
 		thunk_printf_debug("oldpcb uc_link=%p, uc_stack.ss_sp=%p, "
-		"uc_stack.ss_size=%d\n",
+		"uc_stack.ss_size=%d, l_private %p, uc_mcontext._mc_tlsbase=%p(%s)\n",
 		oldpcb->pcb_ucp.uc_link,
 		oldpcb->pcb_ucp.uc_stack.ss_sp,
-		(int)oldpcb->pcb_ucp.uc_stack.ss_size);
+		(int)oldpcb->pcb_ucp.uc_stack.ss_size,
+		(void *) oldlwp->l_private,
+		(void *) oldpcb->pcb_ucp.uc_mcontext._mc_tlsbase,
+		oldpcb->pcb_ucp.uc_flags & _UC_TLSBASE? "ON":"off");
 	}
 	if (newpcb) {
-		thunk_printf_debug("newpcb uc_link=%p, uc_stack.ss_sp=%p, "
-		"uc_stack.ss_size=%d\n",
+		thunk_printf_debug("newpewcb uc_link=%p, uc_stack.ss_sp=%p, "
+		"uc_stack.ss_size=%d, l_private %p, uc_mcontext._mc_tlsbase=%p(%s)\n",
 		newpcb->pcb_ucp.uc_link,
 		newpcb->pcb_ucp.uc_stack.ss_sp,
-		(int)newpcb->pcb_ucp.uc_stack.ss_size);
+		(int)newpcb->pcb_ucp.uc_stack.ss_size,
+		(void *) newlwp->l_private,
+		(void *) newpcb->pcb_ucp.uc_mcontext._mc_tlsbase,
+		newpcb->pcb_ucp.uc_flags & _UC_TLSBASE? "ON":"off");
 	}
 #endif /* !CPU_DEBUG */
 
@@ -250,7 +272,6 @@ cpu_switchto(lwp_t *oldlwp, lwp_t *newlw
 	KASSERT(newlwp);
 	thunk_makecontext(>sc_ucp, (void (*)(void)) cpu_switchto_atomic,
 			2, oldlwp, newlwp, NULL, NULL);
-
 	KASSERT(sc);
 	if (oldpcb) {
 		thunk_swapcontext(>pcb_ucp, >sc_ucp);
@@ -284,11 +305,16 @@ cpu_getmcontext(struct lwp *l, mcontext_
 {
 	struct pcb *pcb = lwp_getpcb(l);
 	ucontext_t *ucp = >pcb_userret_ucp;
-	
+
 #ifdef CPU_DEBUG
 	thunk_printf_debug("cpu_getmcontext\n");
 #endif
 	memcpy(mcp, >uc_mcontext, sizeof(mcontext_t));
+
+	/* XXX be overzealous and provide all */
+	mcp->_mc_tlsbase = (uintptr_t) l->l_private;
+	*flags = _UC_CPU | _UC_STACK | _UC_SIGMASK | _UC_FPU | _UC_TLSBASE;
+
 	return;
 }
 
@@ -299,6 +325,10 @@ cpu_mcontext_validate(struct lwp *l, con
 	 * can we check here? or should that be done in the target
 	 * specific places?
 	 */
+	/* XXX NO CHECKING! XXX */
+#ifdef CPU_DEBUG
+	thunk_printf("cpu_mcontext_validate\n");
+#endif
 	return 0;
 }
 
@@ -311,7 +341,12 @@ cpu_setmcontext(struct lwp *l, const mco
 #ifdef CPU_DEBUG
 	thunk_printf_debug("cpu_setmcontext\n");
 #endif
+	ucp->uc_flags = flags;
 	memcpy(>uc_mcontext, mcp, sizeof(mcontext_t));
+
+	/* update our private, it might be altered in userland */
+	l->l_private = (void *) ucp->uc_mcontext._mc_tlsbase;
+
 	return 0;
 }
 
@@ -382,10 +417,14 @@ cpu_lwp_fork(struct lwp *l1, struct 

CVS commit: src/sys/arch/usermode/target

2018-05-22 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue May 22 14:38:10 UTC 2018

Modified Files:
src/sys/arch/usermode/target/i386: cpu_i386.c
src/sys/arch/usermode/target/x86_64: cpu_x86_64.c

Log Message:
Include  now its available


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/usermode/target/i386/cpu_i386.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/usermode/target/x86_64/cpu_x86_64.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/usermode/target/i386/cpu_i386.c
diff -u src/sys/arch/usermode/target/i386/cpu_i386.c:1.5 src/sys/arch/usermode/target/i386/cpu_i386.c:1.6
--- src/sys/arch/usermode/target/i386/cpu_i386.c:1.5	Fri May 18 20:21:14 2018
+++ src/sys/arch/usermode/target/i386/cpu_i386.c	Tue May 22 14:38:10 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_i386.c,v 1.5 2018/05/18 20:21:14 reinoud Exp $ */
+/* $NetBSD: cpu_i386.c,v 1.6 2018/05/22 14:38:10 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -29,7 +29,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_i386.c,v 1.5 2018/05/18 20:21:14 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_i386.c,v 1.6 2018/05/22 14:38:10 reinoud Exp $");
 
 #include 
 #include 
@@ -49,6 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: cpu_i386.c,v
 #include 
 #include 
 #include 
+#include 
 
 #include "opt_exec.h"
 
@@ -89,11 +90,6 @@ struct sigframe_siginfo {
 /*
  * mcontext extensions to handle signal delivery.
  */
-#define _UC_SETSTACK	0x0001
-#define _UC_CLRSTACK	0x0002
-#define _UC_VM		0x0004
-#define	_UC_TLSBASE	0x0008
-
 
 void
 sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)

Index: src/sys/arch/usermode/target/x86_64/cpu_x86_64.c
diff -u src/sys/arch/usermode/target/x86_64/cpu_x86_64.c:1.4 src/sys/arch/usermode/target/x86_64/cpu_x86_64.c:1.5
--- src/sys/arch/usermode/target/x86_64/cpu_x86_64.c:1.4	Fri May 18 21:05:10 2018
+++ src/sys/arch/usermode/target/x86_64/cpu_x86_64.c	Tue May 22 14:38:10 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_x86_64.c,v 1.4 2018/05/18 21:05:10 reinoud Exp $ */
+/* $NetBSD: cpu_x86_64.c,v 1.5 2018/05/22 14:38:10 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -29,7 +29,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_x86_64.c,v 1.4 2018/05/18 21:05:10 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_x86_64.c,v 1.5 2018/05/22 14:38:10 reinoud Exp $");
 
 #include 
 #include 
@@ -49,7 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: cpu_x86_64.c
 #include 
 #include 
 #include 
-
+#include 
 
 #if 0
 static void dump_regs(register_t *reg);;
@@ -84,16 +84,9 @@ struct sigframe_siginfo {
 };
 
 
-/* should be the same as i386 */
 /*
  * mcontext extensions to handle signal delivery.
  */
-#define _UC_SETSTACK	0x0001
-#define _UC_CLRSTACK	0x0002
-#define _UC_VM		0x0004
-#define	_UC_TLSBASE	0x0008
-
-
 void
 sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {



CVS commit: src/sys/arch/usermode/target/x86_64

2018-05-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri May 18 21:05:10 UTC 2018

Modified Files:
src/sys/arch/usermode/target/x86_64: cpu_x86_64.c

Log Message:
Remove outdated comment


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/usermode/target/x86_64/cpu_x86_64.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/usermode/target/x86_64/cpu_x86_64.c
diff -u src/sys/arch/usermode/target/x86_64/cpu_x86_64.c:1.3 src/sys/arch/usermode/target/x86_64/cpu_x86_64.c:1.4
--- src/sys/arch/usermode/target/x86_64/cpu_x86_64.c:1.3	Fri May 18 20:11:48 2018
+++ src/sys/arch/usermode/target/x86_64/cpu_x86_64.c	Fri May 18 21:05:10 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_x86_64.c,v 1.3 2018/05/18 20:11:48 reinoud Exp $ */
+/* $NetBSD: cpu_x86_64.c,v 1.4 2018/05/18 21:05:10 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -27,15 +27,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * Note that this machdep.c uses the `dummy' mcontext_t defined for usermode.
- * This is basicly a blob of PAGE_SIZE big. We might want to switch over to
- * non-generic mcontext_t's one day, but will this break non-NetBSD hosts?
- */
-
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_x86_64.c,v 1.3 2018/05/18 20:11:48 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_x86_64.c,v 1.4 2018/05/18 21:05:10 reinoud Exp $");
 
 #include 
 #include 



CVS commit: src/sys/arch/usermode/include

2018-05-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri May 18 20:24:57 UTC 2018

Modified Files:
src/sys/arch/usermode/include: thunk.h

Log Message:
Include OUR types.h and not the machine's. A small step to allow for
crosscompilation.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/usermode/include/thunk.h

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/usermode/include/thunk.h
diff -u src/sys/arch/usermode/include/thunk.h:1.62 src/sys/arch/usermode/include/thunk.h:1.63
--- src/sys/arch/usermode/include/thunk.h:1.62	Fri Feb  6 10:25:13 2015
+++ src/sys/arch/usermode/include/thunk.h	Fri May 18 20:24:57 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.h,v 1.62 2015/02/06 10:25:13 prlw1 Exp $ */
+/* $NetBSD: thunk.h,v 1.63 2018/05/18 20:24:57 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -29,7 +29,7 @@
 #ifndef _ARCH_USERMODE_INCLUDE_THUNK_H
 #define _ARCH_USERMODE_INCLUDE_THUNK_H
 
-#include 
+#include "types.h"
 #include 
 #include 
 #include 



CVS commit: src/sys/arch/usermode/usermode

2018-05-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri May 18 20:24:16 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: trap.c

Log Message:
Replace the dynamically allocated signal stack to a static claimed one and add
diagnostic messages that can be enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/usermode/usermode/trap.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/usermode/usermode/trap.c
diff -u src/sys/arch/usermode/usermode/trap.c:1.66 src/sys/arch/usermode/usermode/trap.c:1.67
--- src/sys/arch/usermode/usermode/trap.c:1.66	Sat Aug  4 14:53:32 2012
+++ src/sys/arch/usermode/usermode/trap.c	Fri May 18 20:24:16 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.66 2012/08/04 14:53:32 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.67 2018/05/18 20:24:16 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.66 2012/08/04 14:53:32 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.67 2018/05/18 20:24:16 reinoud Exp $");
 
 #include 
 #include 
@@ -62,6 +62,7 @@ static sigfunc_t sigio;
 static sigfunc_t pass_on;
 
 /* raw signal handlers */
+static charsig_stack[SIGSTKSZ];
 static stack_t sigstk;
 ucontext_t jump_ucp;
 
@@ -108,8 +109,7 @@ setup_signal_handlers(void)
 	 * effects. Especially ld.so and friends have such tiny stacks that
 	 * its not feasable.
 	 */
-	if ((sigstk.ss_sp = thunk_malloc(SIGSTKSZ)) == NULL)
-		panic("can't allocate signal stack space\n");
+	sigstk.ss_sp= sig_stack;
 	sigstk.ss_size  = SIGSTKSZ;
 	sigstk.ss_flags = 0;
 	if (thunk_sigaltstack(, 0) < 0)
@@ -293,8 +293,8 @@ print_illegal_instruction_siginfo(int si
 #endif
 }
 #else /* DEBUG */
-#define print_mem_access_siginfo(s, i, c, p, v, sp)
-#define print_illegal_instruction_siginfo(s, i, c, p, v, sp)
+#define print_mem_access_siginfo(s, i, c, p, v, sp) {}
+#define print_illegal_instruction_siginfo(s, i, c, p, v, sp) {}
 #endif /* DEBUG */
 
 
@@ -349,7 +349,7 @@ handle_signal(int sig, siginfo_t *info, 
 		sp = fp - sizeof(register_t);	/* slack */
 
 		/* sanity check before copying */
-		if (fp - 2*PAGE_SIZE < (vaddr_t) pcb->sys_stack)
+		if (fp - 4*PAGE_SIZE < (vaddr_t) pcb->sys_stack)
 			panic("%s: out of system stack", __func__);
 	}
 
@@ -431,6 +431,11 @@ pagefault(siginfo_t *info, vaddr_t from_
 	}
 
 	/* ask UVM */
+#if 0
+thunk_printf("%s: l %p, pcb %p, ", __func__, l, pcb);
+thunk_printf("pc %p, va %p ", (void *) pc, (void *) va);
+thunk_printf("derived atype %d\n", atype);
+#endif
 	thunk_printf_debug("pmap fault couldn't handle it! : "
 		"derived atype %d\n", atype);
 
@@ -452,10 +457,6 @@ pagefault(siginfo_t *info, vaddr_t from_
 		goto out;
 	}
 
-	/* something got wrong */
-	thunk_printf("%s: uvm fault %d, pc %p, va %p, from_kernel %d\n",
-		__func__, error, (void *) pc, (void *) va, from_kernel);
-
 	/* check if its from copyin/copyout */
 	if (onfault) {
 		panic("%s: can't call onfault yet\n", __func__);
@@ -468,11 +469,18 @@ pagefault(siginfo_t *info, vaddr_t from_
 		goto out;
 	}
 
-	if (from_kernel)
+	if (from_kernel) {
+		thunk_printf("%s: uvm fault %d, pc %p, va %p, from_kernel %d\n",
+			__func__, error, (void *) pc, (void *) va, from_kernel);
 		panic("Unhandled page fault in kernel mode");
+	}
 
 	/* send signal */
-	thunk_printf("giving signal to userland\n");
+	/* something got wrong */
+	thunk_printf_debug("%s: uvm fault %d, pc %p, va %p, from_kernel %d\n",
+		__func__, error, (void *) pc, (void *) va, from_kernel);
+
+	thunk_printf_debug("giving signal to userland\n");
 
 	KASSERT(from_userland);
 	KSI_INIT_TRAP();



CVS commit: src/sys/arch/usermode/target/i386

2018-05-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri May 18 20:21:14 UTC 2018

Modified Files:
src/sys/arch/usermode/target/i386: cpu_i386.c

Log Message:
Use knowledge of mcontext for i386 support


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/usermode/target/i386/cpu_i386.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/usermode/target/i386/cpu_i386.c
diff -u src/sys/arch/usermode/target/i386/cpu_i386.c:1.4 src/sys/arch/usermode/target/i386/cpu_i386.c:1.5
--- src/sys/arch/usermode/target/i386/cpu_i386.c:1.4	Sat Mar  3 21:15:16 2012
+++ src/sys/arch/usermode/target/i386/cpu_i386.c	Fri May 18 20:21:14 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_i386.c,v 1.4 2012/03/03 21:15:16 reinoud Exp $ */
+/* $NetBSD: cpu_i386.c,v 1.5 2018/05/18 20:21:14 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -27,14 +27,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * Note that this machdep.c uses the `dummy' mcontext_t defined for usermode.
- * This is basicly a blob of PAGE_SIZE big. We might want to switch over to
- * non-generic mcontext_t's one day, but will this break non-NetBSD hosts?
- */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_i386.c,v 1.4 2012/03/03 21:15:16 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_i386.c,v 1.5 2018/05/18 20:21:14 reinoud Exp $");
 
 #include 
 #include 
@@ -117,7 +112,7 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 	KASSERT(mutex_owned(p->p_lock));
 
 	ucp = >pcb_userret_ucp;
-	reg = (register_t *) >uc_mcontext;
+	reg = (register_t *) >uc_mcontext.__gregs;
 #if 0
 	thunk_printf("%s: ", __func__);
 	thunk_printf("flags %d, ", (int) ksi->ksi_flags);
@@ -198,7 +193,7 @@ setregs(struct lwp *l, struct exec_packa
 
 	/* set up the user context */
 	ucp = >pcb_userret_ucp;
-	reg = (int *) >uc_mcontext;
+	reg = (int *) >uc_mcontext.__gregs;
 	for (i = 4; i < 11; i++)
 		reg[i] = 0;
 
@@ -228,7 +223,7 @@ setregs(struct lwp *l, struct exec_packa
 void
 md_syscall_get_syscallnumber(ucontext_t *ucp, uint32_t *code)
 {
-	uint *reg = (int *) >uc_mcontext;
+	uint *reg = (int *) >uc_mcontext.__gregs;
 	*code = reg[11];			/* EAX */
 }
 
@@ -236,7 +231,7 @@ int
 md_syscall_getargs(lwp_t *l, ucontext_t *ucp, int nargs, int argsize,
 	register_t *args)
 {
-	uint *reg = (int *) >uc_mcontext;
+	uint *reg = (int *) >uc_mcontext.__gregs;
 	register_t *sp = (register_t *) reg[17];/* ESP */
 	int ret;
 
@@ -250,7 +245,7 @@ void
 md_syscall_set_returnargs(lwp_t *l, ucontext_t *ucp,
 	int error, register_t *rval)
 {
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 
 	reg[16] &= ~PSL_C;		/* EFL */
 	if (error > 0) {
@@ -270,7 +265,7 @@ register_t
 md_get_pc(ucontext_t *ucp)
 {
 	KASSERT(ucp);
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 
 	return reg[14];			/* EIP */
 }
@@ -279,7 +274,7 @@ register_t
 md_get_sp(ucontext_t *ucp)
 {
 	KASSERT(ucp);
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 
 	return reg[17];			/* ESP */
 }
@@ -307,7 +302,7 @@ void
 md_syscall_get_opcode(ucontext_t *ucp, uint32_t *opcode)
 {
 	KASSERT(ucp);
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 //	uint8_t  *p8  = (uint8_t *) (reg[14]);
 	uint16_t *p16 = (uint16_t*) (reg[14]);	/* EIP */
 
@@ -328,7 +323,7 @@ void
 md_syscall_inc_pc(ucontext_t *ucp, uint32_t opcode)
 {
 	KASSERT(ucp);
-	uint *reg = (int *) >uc_mcontext;
+	uint *reg = (int *) >uc_mcontext.__gregs;
 
 	/* advance program counter */
 	switch (opcode) {
@@ -349,7 +344,7 @@ void
 md_syscall_dec_pc(ucontext_t *ucp, uint32_t opcode)
 {
 	KASSERT(ucp);
-	uint *reg = (int *) >uc_mcontext;
+	uint *reg = (int *) >uc_mcontext.__gregs;
 
 	switch (opcode) {
 	case 0xff0f:	/* UD1  */



CVS commit: src/sys/arch/usermode/target/x86_64

2018-05-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri May 18 20:11:48 UTC 2018

Modified Files:
src/sys/arch/usermode/target/x86_64: cpu_x86_64.c

Log Message:
Use knowledge about the mcontext


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/usermode/target/x86_64/cpu_x86_64.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/usermode/target/x86_64/cpu_x86_64.c
diff -u src/sys/arch/usermode/target/x86_64/cpu_x86_64.c:1.2 src/sys/arch/usermode/target/x86_64/cpu_x86_64.c:1.3
--- src/sys/arch/usermode/target/x86_64/cpu_x86_64.c:1.2	Sat Jan 14 17:42:52 2012
+++ src/sys/arch/usermode/target/x86_64/cpu_x86_64.c	Fri May 18 20:11:48 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_x86_64.c,v 1.2 2012/01/14 17:42:52 reinoud Exp $ */
+/* $NetBSD: cpu_x86_64.c,v 1.3 2018/05/18 20:11:48 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -35,7 +35,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_x86_64.c,v 1.2 2012/01/14 17:42:52 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_x86_64.c,v 1.3 2018/05/18 20:11:48 reinoud Exp $");
 
 #include 
 #include 
@@ -118,7 +118,7 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 	KASSERT(mutex_owned(p->p_lock));
 
 	ucp = >pcb_userret_ucp;
-	reg = (register_t *) >uc_mcontext;
+	reg = (register_t *) >uc_mcontext.__gregs;
 #if 0
 	thunk_printf("%s: ", __func__);
 	thunk_printf("flags %d, ", (int) ksi->ksi_flags);
@@ -195,7 +195,7 @@ setregs(struct lwp *l, struct exec_packa
 
 	/* set up the user context */
 	ucp = >pcb_userret_ucp;
-	reg = (register_t *) >uc_mcontext;
+	reg = (register_t *) >uc_mcontext.__gregs;
 	for (i = 0; i < 15; i++)
 		reg[i] = 0;
 
@@ -213,7 +213,7 @@ setregs(struct lwp *l, struct exec_packa
 void
 md_syscall_get_syscallnumber(ucontext_t *ucp, uint32_t *code)
 {
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 	*code = reg[14];			/* RAX */
 }
 
@@ -221,7 +221,7 @@ int
 md_syscall_getargs(lwp_t *l, ucontext_t *ucp, int nargs, int argsize,
 	register_t *args)
 {
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 	register_t *sp = (register_t *) reg[24];/* RSP */
 	int ret;
 
@@ -251,7 +251,7 @@ void
 md_syscall_set_returnargs(lwp_t *l, ucontext_t *ucp,
 	int error, register_t *rval)
 {
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 
 	reg[23] &= ~PSL_C;		/* RFLAGS */
 	if (error > 0) {
@@ -270,7 +270,7 @@ md_syscall_set_returnargs(lwp_t *l, ucon
 register_t
 md_get_pc(ucontext_t *ucp)
 {
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 
 	return reg[21];			/* RIP */
 }
@@ -278,7 +278,7 @@ md_get_pc(ucontext_t *ucp)
 register_t
 md_get_sp(ucontext_t *ucp)
 {
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 
 	return reg[24];			/* RSP */
 }
@@ -306,7 +306,7 @@ md_syscall_check_opcode(ucontext_t *ucp)
 void
 md_syscall_get_opcode(ucontext_t *ucp, uint32_t *opcode)
 {
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 //	uint8_t  *p8  = (uint8_t *) (reg[21]);
 	uint16_t *p16 = (uint16_t*) (reg[21]);	/* RIP */
 
@@ -326,7 +326,7 @@ md_syscall_get_opcode(ucontext_t *ucp, u
 void
 md_syscall_inc_pc(ucontext_t *ucp, uint32_t opcode)
 {
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 
 	/* advance program counter */
 	switch (opcode) {
@@ -346,7 +346,7 @@ md_syscall_inc_pc(ucontext_t *ucp, uint3
 void
 md_syscall_dec_pc(ucontext_t *ucp, uint32_t opcode)
 {
-	register_t *reg = (register_t *) >uc_mcontext;
+	register_t *reg = (register_t *) >uc_mcontext.__gregs;
 
 	switch (opcode) {
 	case 0xff0f:	/* UD1  */



CVS commit: src/sys/arch/usermode/usermode

2018-05-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri May 18 20:10:25 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: process_machdep.c

Log Message:
Second part for creating sensible coredumps


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/usermode/usermode/process_machdep.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/usermode/usermode/process_machdep.c
diff -u src/sys/arch/usermode/usermode/process_machdep.c:1.4 src/sys/arch/usermode/usermode/process_machdep.c:1.5
--- src/sys/arch/usermode/usermode/process_machdep.c:1.4	Sat Jan 13 15:15:03 2018
+++ src/sys/arch/usermode/usermode/process_machdep.c	Fri May 18 20:10:25 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: process_machdep.c,v 1.4 2018/01/13 15:15:03 reinoud Exp $ */
+/* $NetBSD: process_machdep.c,v 1.5 2018/05/18 20:10:25 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -26,58 +26,135 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+
+/* from sys/arch/amd64/amd64/process_machdep.c */
+/*
+ * This file may seem a bit stylized, but that so that it's easier to port.
+ * Functions to be implemented here are:
+ *
+ * process_read_regs(proc, regs)
+ *	Get the current user-visible register set from the process
+ *	and copy it into the regs structure ().
+ *	The process is stopped at the time read_regs is called.
+ *
+ * process_write_regs(proc, regs)
+ *	Update the current register set from the passed in regs
+ *	structure.  Take care to avoid clobbering special CPU
+ *	registers or privileged bits in the PSL.
+ *	The process is stopped at the time write_regs is called.
+ *
+ * process_read_fpregs(proc, regs, sz)
+ *	Get the current user-visible register set from the process
+ *	and copy it into the regs structure ().
+ *	The process is stopped at the time read_fpregs is called.
+ *
+ * process_write_fpregs(proc, regs, sz)
+ *	Update the current register set from the passed in regs
+ *	structure.  Take care to avoid clobbering special CPU
+ *	registers or privileged bits in the PSL.
+ *	The process is stopped at the time write_fpregs is called.
+ *
+ * process_read_dbregs(proc, regs, sz)
+ *	Get the current user-visible register set from the process
+ *	and copy it into the regs structure ().
+ *	The process is stopped at the time read_dbregs is called.
+ *
+ * process_write_dbregs(proc, regs, sz)
+ *	Update the current register set from the passed in regs
+ *	structure.  Take care to avoid clobbering special CPU
+ *	registers or privileged bits in the PSL.
+ *	The process is stopped at the time write_dbregs is called.
+ *
+ * process_sstep(proc)
+ *	Arrange for the process to trap after executing a single instruction.
+ *
+ * process_set_pc(proc)
+ *	Set the process's program counter.
+ */
+
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.4 2018/01/13 15:15:03 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.5 2018/05/18 20:10:25 reinoud Exp $");
 
 #include 
 #include 
 #include 
 
+#include 
+#include 
+#include 
+
+#include 
+
 int
 process_read_regs(struct lwp *l, struct reg *regs)
 {
+ 	struct pcb *pcb = lwp_getpcb(l);
+	ucontext_t *ucp;
+ 	register_t *reg;
+
+	ucp = >pcb_userret_ucp;
+	reg = (register_t *) >uc_mcontext.__gregs;
+
+	memcpy(regs, reg, sizeof(__gregset_t));
+
 	return 0;
 }
 
 int
 process_read_fpregs(struct lwp *l, struct fpreg *regs, size_t *sz)
 {
+ 	struct pcb *pcb = lwp_getpcb(l);
+	ucontext_t *ucp;
+ 	register_t *reg;
+
+	ucp = >pcb_userret_ucp;
+	reg = (register_t *) >uc_mcontext.__fpregs;
+
+	*sz = sizeof(__fpregset_t);
+	memcpy(regs, reg, *sz);
+
 	return 0;
 }
 
 int
 process_write_regs(struct lwp *l, const struct reg *regs)
 {
+thunk_printf("%s called, not implemented\n", __func__);
 	return 0;
 }
 
 int
 process_write_fpregs(struct lwp *l, const struct fpreg *regs, size_t sz)
 {
+thunk_printf("%s called, not implemented\n", __func__);
 	return 0;
 }
 
 int
 process_sstep(struct lwp *l, int sstep)
 {
+thunk_printf("%s called, not implemented\n", __func__);
 	return 0;
 }
 
 int
 process_set_pc(struct lwp *l, void *addr)
 {
+thunk_printf("%s called, not implemented\n", __func__);
 	return 0;
 }
 
 int
 process_write_dbregs(struct lwp *l, const struct dbreg *regs, size_t sz)
 {
+thunk_printf("%s called, not implemented\n", __func__);
 	return 0;
 }
 
 int
 process_read_dbregs(struct lwp *l, struct dbreg *regs, size_t *sz)
 {
+thunk_printf("%s called, not implemented\n", __func__);
 	return 0;
 }
 



CVS commit: src/sys/arch/usermode/include

2018-05-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri May 18 20:09:33 UTC 2018

Modified Files:
src/sys/arch/usermode/include: reg.h

Log Message:
Implement own process register capture from userland.

NetBSD/usermode now creates readable and sensible coredumps


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/usermode/include/reg.h

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/usermode/include/reg.h
diff -u src/sys/arch/usermode/include/reg.h:1.3 src/sys/arch/usermode/include/reg.h:1.4
--- src/sys/arch/usermode/include/reg.h:1.3	Sat Jan 13 14:39:15 2018
+++ src/sys/arch/usermode/include/reg.h	Fri May 18 20:09:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: reg.h,v 1.3 2018/01/13 14:39:15 reinoud Exp $ */
+/* $NetBSD: reg.h,v 1.4 2018/05/18 20:09:32 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -29,10 +29,16 @@
 #ifndef _ARCH_USERMODE_INCLUDE_REG_H
 #define _ARCH_USERMODE_INCLUDE_REG_H
 
+#include "machine/mcontext.h"
+
+/* registers are already in the right order since they follow mcontext.h */
 struct reg {
+	__gregset_t regs;
 };
 
+/* registers are already in the right order since they follow mcontext.h */
 struct fpreg {
+__fpregset_t fpregs;
 };
 
 /* x86_64 only */



CVS commit: src/sys/arch/usermode/conf

2018-05-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri May 18 19:04:11 UTC 2018

Added Files:
src/sys/arch/usermode/conf: kern.ldscript

Log Message:
Where did kern.ldscript go?


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/usermode/conf/kern.ldscript

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

Added files:

Index: src/sys/arch/usermode/conf/kern.ldscript
diff -u /dev/null src/sys/arch/usermode/conf/kern.ldscript:1.1
--- /dev/null	Fri May 18 19:04:11 2018
+++ src/sys/arch/usermode/conf/kern.ldscript	Fri May 18 19:04:10 2018
@@ -0,0 +1,73 @@
+/*	$NetBSD: kern.ldscript,v 1.1 2018/05/18 19:04:10 reinoud Exp $	*/
+
+#include "assym.h"
+
+ENTRY(_start)
+SECTIONS
+{
+	/* Read-only sections, merged into text segment: */
+	.text :
+	{
+		*(.text)
+		*(.text.*)
+		*(.stub)
+	}
+	_etext = . ;
+	PROVIDE (etext = .) ;
+
+	.rodata :
+	{
+		*(.rodata)
+		*(.rodata.*)
+	}
+
+	/*
+	 * Adjust the address for the data segment.  We want to adjust up to
+	 * the same address within the page on the next page up.
+	 */
+	. = ALIGN(0x10) + (. & (0x10 - 1));
+	__data_start = . ;
+	.data :
+	{
+		*(.data)
+	}
+
+	. = ALIGN(COHERENCY_UNIT);
+	.data.cacheline_aligned :
+	{
+		*(.data.cacheline_aligned)
+	}
+	. = ALIGN(COHERENCY_UNIT);
+	.data.read_mostly :
+	{
+		*(.data.read_mostly)
+	}
+	. = ALIGN(COHERENCY_UNIT);
+
+	_edata = . ;
+	PROVIDE (edata = .) ;
+	__bss_start = . ;
+	.bss :
+	{
+		*(.bss)
+		*(.bss.*)
+		*(COMMON)
+		. = ALIGN(64 / 8);
+	}
+	. = ALIGN(64 / 8);
+	_end = . ;
+	PROVIDE (end = .) ;
+	.note.netbsd.ident :
+	{
+		KEEP(*(.note.netbsd.ident));
+	}
+}
+
+SECTIONS
+{
+	.text :
+	AT (ADDR(.text) & 0x0fff)
+	{
+		*(.text)
+	} = 0
+}



CVS commit: src/sys/arch/usermode/usermode

2018-05-17 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri May 18 05:51:24 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: thunk.c

Log Message:
Include our doctored types.h instead of the default


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/usermode/usermode/thunk.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/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.87 src/sys/arch/usermode/usermode/thunk.c:1.88
--- src/sys/arch/usermode/usermode/thunk.c:1.87	Mon Dec 21 20:44:54 2015
+++ src/sys/arch/usermode/usermode/thunk.c	Fri May 18 05:51:23 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.87 2015/12/21 20:44:54 christos Exp $ */
+/* $NetBSD: thunk.c,v 1.88 2018/05/18 05:51:23 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -28,10 +28,10 @@
 
 #include 
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.87 2015/12/21 20:44:54 christos Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.88 2018/05/18 05:51:23 reinoud Exp $");
 #endif
 
-#include 
+#include "../include/types.h"
 #include 
 #include 
 #include 



CVS commit: src/sys/arch/usermode/usermode

2018-05-17 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu May 17 19:06:02 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: pmap.c

Log Message:
Don't dynamically allocate memory we are only going to use once; so allocate
it on the stack.

While here, also include some more sanity checks.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/arch/usermode/usermode/pmap.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/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.106 src/sys/arch/usermode/usermode/pmap.c:1.107
--- src/sys/arch/usermode/usermode/pmap.c:1.106	Thu Jul  7 06:55:39 2016
+++ src/sys/arch/usermode/usermode/pmap.c	Thu May 17 19:06:02 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.106 2016/07/07 06:55:39 msaitoh Exp $ */
+/* $NetBSD: pmap.c,v 1.107 2018/05/17 19:06:02 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.106 2016/07/07 06:55:39 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.107 2018/05/17 19:06:02 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -230,6 +230,7 @@ pmap_bootstrap(void)
 	mem_fh = thunk_mkstemp(mem_name);
 	if (mem_fh < 0)
 		panic("pmap_bootstrap: can't create memory file\n");
+
 	/* unlink the file so space is freed when we quit */
 	if (thunk_unlink(mem_name) == -1)
 		panic("pmap_bootstrap: can't unlink %s", mem_name);
@@ -247,19 +248,14 @@ pmap_bootstrap(void)
 	}
 #else
 	{
-		void *block;
+		char block[PAGE_SIZE];
 
 		printf("Creating memory file\r");
-		block = thunk_malloc(PAGE_SIZE);
-		if (!block)
-			panic("pmap_bootstrap: can't malloc writeout block");
-
 		for (pg = 0; pg < file_len; pg += PAGE_SIZE) {
 			wlen = thunk_pwrite(mem_fh, block, PAGE_SIZE, pg);
 			if (wlen != PAGE_SIZE)
 panic("pmap_bootstrap: write fails, disc full?");
 		}
-		thunk_free(block);
 	}
 #endif
 
@@ -1204,13 +1200,14 @@ pmap_zero_page(paddr_t pa)
 	if (pa & (PAGE_SIZE-1))
 		panic("%s: unaligned address passed : %p\n", __func__, (void *) pa);
 
-	/* XXX bug alart: can we allow the kernel to make a decision on this? */
 	blob = thunk_mmap(NULL, PAGE_SIZE,
 		THUNK_PROT_READ | THUNK_PROT_WRITE,
 		THUNK_MAP_FILE | THUNK_MAP_SHARED,
 		mem_fh, pa);
 	if (!blob)
 		panic("%s: couldn't get mapping", __func__);
+	if (blob < (char *) kmem_k_end)
+		panic("%s: mmap in illegal memory range", __func__);
 
 	memset(blob, 0, PAGE_SIZE);
 
@@ -1237,6 +1234,8 @@ pmap_copy_page(paddr_t src_pa, paddr_t d
 		mem_fh, src_pa);
 	if (!sblob)
 		panic("%s: couldn't get src mapping", __func__);
+	if (sblob < (char *) kmem_k_end)
+		panic("%s: mmap in illegal memory range", __func__);
 
 	/* XXX bug alart: can we allow the kernel to make a decision on this? */
 	dblob = thunk_mmap(NULL, PAGE_SIZE,
@@ -1245,6 +1244,8 @@ pmap_copy_page(paddr_t src_pa, paddr_t d
 		mem_fh, dst_pa);
 	if (!dblob)
 		panic("%s: couldn't get dst mapping", __func__);
+	if (dblob < (char *) kmem_k_end)
+		panic("%s: mmap in illegal memory range", __func__);
 
 	memcpy(dblob, sblob, PAGE_SIZE);
 



CVS commit: src/sys/arch/usermode/dev

2018-05-17 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu May 17 19:00:39 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: cpu.c

Log Message:
Refactor for easier debugging and while here add some more signals


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/usermode/dev/cpu.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/usermode/dev/cpu.c
diff -u src/sys/arch/usermode/dev/cpu.c:1.74 src/sys/arch/usermode/dev/cpu.c:1.75
--- src/sys/arch/usermode/dev/cpu.c:1.74	Thu Jun  1 02:45:08 2017
+++ src/sys/arch/usermode/dev/cpu.c	Thu May 17 19:00:39 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.74 2017/06/01 02:45:08 chs Exp $ */
+/* $NetBSD: cpu.c,v 1.75 2018/05/17 19:00:39 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -30,7 +30,7 @@
 #include "opt_hz.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.74 2017/06/01 02:45:08 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.75 2018/05/17 19:00:39 reinoud Exp $");
 
 #include 
 #include 
@@ -119,6 +119,8 @@ cpu_attach(device_t parent, device_t sel
 	sc->sc_ucp.uc_flags = _UC_STACK | _UC_CPU | _UC_SIGMASK;
 	thunk_sigaddset(>sc_ucp.uc_sigmask, SIGALRM);
 	thunk_sigaddset(>sc_ucp.uc_sigmask, SIGIO);
+	thunk_sigaddset(>sc_ucp.uc_sigmask, SIGINT);
+	thunk_sigaddset(>sc_ucp.uc_sigmask, SIGTSTP);
 }
 
 void
@@ -191,9 +193,13 @@ static
 void
 cpu_switchto_atomic(lwp_t *oldlwp, lwp_t *newlwp)
 {
-	struct pcb *oldpcb = oldlwp ? lwp_getpcb(oldlwp) : NULL;
-	struct pcb *newpcb = lwp_getpcb(newlwp);
-	struct cpu_info *ci = curcpu();
+	struct pcb *oldpcb;
+	struct pcb *newpcb;
+	struct cpu_info *ci;
+
+	oldpcb = oldlwp ? lwp_getpcb(oldlwp) : NULL;
+	newpcb = lwp_getpcb(newlwp);
+	ci = curcpu();
 
 	ci->ci_stash = oldlwp;
 
@@ -241,6 +247,7 @@ cpu_switchto(lwp_t *oldlwp, lwp_t *newlw
 #endif /* !CPU_DEBUG */
 
 	/* create atomic switcher */
+	KASSERT(newlwp);
 	thunk_makecontext(>sc_ucp, (void (*)(void)) cpu_switchto_atomic,
 			2, oldlwp, newlwp, NULL, NULL);
 



CVS commit: src/sys/arch/usermode/include

2018-05-16 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed May 16 12:40:43 UTC 2018

Modified Files:
src/sys/arch/usermode/include: asm.h bswap.h byte_swap.h cdefs.h
disklabel.h elf_machdep.h endian.h endian_machdep.h int_const.h
int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h limits.h
mcontext.h netbsd32_machdep.h param.h ptrace.h wchar_limits.h
Added Files:
src/sys/arch/usermode/include: frame_regs.h

Log Message:
Regen usermode headers


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/usermode/include/asm.h \
src/sys/arch/usermode/include/bswap.h \
src/sys/arch/usermode/include/byte_swap.h \
src/sys/arch/usermode/include/elf_machdep.h \
src/sys/arch/usermode/include/endian.h \
src/sys/arch/usermode/include/endian_machdep.h \
src/sys/arch/usermode/include/int_const.h \
src/sys/arch/usermode/include/int_fmtio.h \
src/sys/arch/usermode/include/int_limits.h \
src/sys/arch/usermode/include/int_mwgwtypes.h \
src/sys/arch/usermode/include/int_types.h \
src/sys/arch/usermode/include/limits.h \
src/sys/arch/usermode/include/netbsd32_machdep.h \
src/sys/arch/usermode/include/wchar_limits.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/usermode/include/cdefs.h
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/usermode/include/disklabel.h \
src/sys/arch/usermode/include/ptrace.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/usermode/include/frame_regs.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/usermode/include/mcontext.h
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/usermode/include/param.h

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/usermode/include/asm.h
diff -u src/sys/arch/usermode/include/asm.h:1.11 src/sys/arch/usermode/include/asm.h:1.12
--- src/sys/arch/usermode/include/asm.h:1.11	Sun Nov 10 19:52:01 2013
+++ src/sys/arch/usermode/include/asm.h	Wed May 16 12:40:43 2018
@@ -1,7 +1,7 @@
-/* $NetBSD: asm.h,v 1.11 2013/11/10 19:52:01 jmcneill Exp $ */
+/* $NetBSD: asm.h,v 1.12 2018/05/16 12:40:43 reinoud Exp $ */
 
 /*
- * Automatically generated by genheaders.sh on Sun Nov 10 15:47:57 AST 2013
+ * Automatically generated by ./genheaders.sh on Wed May 16 14:39:02 CEST 2018
  * Do not modify directly!
  */
 #ifndef _USERMODE_ASM_H
Index: src/sys/arch/usermode/include/bswap.h
diff -u src/sys/arch/usermode/include/bswap.h:1.11 src/sys/arch/usermode/include/bswap.h:1.12
--- src/sys/arch/usermode/include/bswap.h:1.11	Sun Nov 10 19:52:01 2013
+++ src/sys/arch/usermode/include/bswap.h	Wed May 16 12:40:43 2018
@@ -1,7 +1,7 @@
-/* $NetBSD: bswap.h,v 1.11 2013/11/10 19:52:01 jmcneill Exp $ */
+/* $NetBSD: bswap.h,v 1.12 2018/05/16 12:40:43 reinoud Exp $ */
 
 /*
- * Automatically generated by genheaders.sh on Sun Nov 10 15:47:57 AST 2013
+ * Automatically generated by ./genheaders.sh on Wed May 16 14:39:02 CEST 2018
  * Do not modify directly!
  */
 #ifndef _USERMODE_BSWAP_H
Index: src/sys/arch/usermode/include/byte_swap.h
diff -u src/sys/arch/usermode/include/byte_swap.h:1.11 src/sys/arch/usermode/include/byte_swap.h:1.12
--- src/sys/arch/usermode/include/byte_swap.h:1.11	Sun Nov 10 19:52:01 2013
+++ src/sys/arch/usermode/include/byte_swap.h	Wed May 16 12:40:43 2018
@@ -1,7 +1,7 @@
-/* $NetBSD: byte_swap.h,v 1.11 2013/11/10 19:52:01 jmcneill Exp $ */
+/* $NetBSD: byte_swap.h,v 1.12 2018/05/16 12:40:43 reinoud Exp $ */
 
 /*
- * Automatically generated by genheaders.sh on Sun Nov 10 15:47:57 AST 2013
+ * Automatically generated by ./genheaders.sh on Wed May 16 14:39:02 CEST 2018
  * Do not modify directly!
  */
 #ifndef _USERMODE_BYTE_SWAP_H
Index: src/sys/arch/usermode/include/elf_machdep.h
diff -u src/sys/arch/usermode/include/elf_machdep.h:1.11 src/sys/arch/usermode/include/elf_machdep.h:1.12
--- src/sys/arch/usermode/include/elf_machdep.h:1.11	Sun Nov 10 19:52:01 2013
+++ src/sys/arch/usermode/include/elf_machdep.h	Wed May 16 12:40:43 2018
@@ -1,7 +1,7 @@
-/* $NetBSD: elf_machdep.h,v 1.11 2013/11/10 19:52:01 jmcneill Exp $ */
+/* $NetBSD: elf_machdep.h,v 1.12 2018/05/16 12:40:43 reinoud Exp $ */
 
 /*
- * Automatically generated by genheaders.sh on Sun Nov 10 15:47:57 AST 2013
+ * Automatically generated by ./genheaders.sh on Wed May 16 14:39:02 CEST 2018
  * Do not modify directly!
  */
 #ifndef _USERMODE_ELF_MACHDEP_H
Index: src/sys/arch/usermode/include/endian.h
diff -u src/sys/arch/usermode/include/endian.h:1.11 src/sys/arch/usermode/include/endian.h:1.12
--- src/sys/arch/usermode/include/endian.h:1.11	Sun Nov 10 19:52:01 2013
+++ src/sys/arch/usermode/include/endian.h	Wed May 16 12:40:43 2018
@@ -1,7 +1,7 @@
-/* $NetBSD: endian.h,v 1.11 2013/11/10 19:52:01 jmcneill Exp $ */
+/* $NetBSD: endian.h,v 1.12 2018/05/16 12:40:43 reinoud Exp $ */
 
 /*
- * Automatically generated by genheaders.sh on Sun Nov 10 15:47:57 AST 2013
+ * Automatically generated by ./genheaders.sh on Wed May 16 14:39:02 CEST 2018
  

CVS commit: src/sys/arch/usermode/include

2018-05-16 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed May 16 12:40:26 UTC 2018

Modified Files:
src/sys/arch/usermode/include: genheaders.sh

Log Message:
Add new mcontext and depends to the usermode generated headerfiles


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/usermode/include/genheaders.sh

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/usermode/include/genheaders.sh
diff -u src/sys/arch/usermode/include/genheaders.sh:1.9 src/sys/arch/usermode/include/genheaders.sh:1.10
--- src/sys/arch/usermode/include/genheaders.sh:1.9	Sun Nov 10 19:52:01 2013
+++ src/sys/arch/usermode/include/genheaders.sh	Wed May 16 12:40:26 2018
@@ -21,6 +21,8 @@ HDRS="$HDRS param.h"
 HDRS="$HDRS ptrace.h"
 HDRS="$HDRS wchar_limits.h"
 HDRS="$HDRS cdefs.h"
+HDRS="$HDRS mcontext.h"
+HDRS="$HDRS frame_regs.h"
 
 for hdr in ${HDRS}; do
 	G="_USERMODE_$(echo ${hdr} | sed 's/\./_/g' | tr [a-z] [A-Z])"



CVS commit: src/sys/arch/usermode/conf

2018-01-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan 13 16:20:33 UTC 2018

Modified Files:
src/sys/arch/usermode/conf: GENERIC.common Makefile.usermode

Log Message:
Make NetBSD/usermode link again!


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/usermode/conf/GENERIC.common
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/usermode/conf/Makefile.usermode

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/usermode/conf/GENERIC.common
diff -u src/sys/arch/usermode/conf/GENERIC.common:1.26 src/sys/arch/usermode/conf/GENERIC.common:1.27
--- src/sys/arch/usermode/conf/GENERIC.common:1.26	Thu Sep 14 07:58:44 2017
+++ src/sys/arch/usermode/conf/GENERIC.common	Sat Jan 13 16:20:33 2018
@@ -1,14 +1,14 @@
-# $NetBSD: GENERIC.common,v 1.26 2017/09/14 07:58:44 mrg Exp $
+# $NetBSD: GENERIC.common,v 1.27 2018/01/13 16:20:33 reinoud Exp $
 
 include "arch/usermode/conf/std.usermode"
 
 options 	INCLUDE_CONFIG_FILE
-#ident 		"GENERIC-$Revision: 1.26 $"
+#ident 		"GENERIC-$Revision: 1.27 $"
 maxusers 	32
 
 makeoptions	DEBUG="-O1 -g3"
 
-makeoptions	COPY_SYMTAB=1
+#makeoptions	COPY_SYMTAB=1
 
 options 	RTC_OFFSET=0
 options 	NTP

Index: src/sys/arch/usermode/conf/Makefile.usermode
diff -u src/sys/arch/usermode/conf/Makefile.usermode:1.40 src/sys/arch/usermode/conf/Makefile.usermode:1.41
--- src/sys/arch/usermode/conf/Makefile.usermode:1.40	Sun Dec 10 14:29:47 2017
+++ src/sys/arch/usermode/conf/Makefile.usermode	Sat Jan 13 16:20:33 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.usermode,v 1.40 2017/12/10 14:29:47 christos Exp $
+# $NetBSD: Makefile.usermode,v 1.41 2018/01/13 16:20:33 reinoud Exp $
 
 USETOOLS?=			no
 NEED_OWN_INSTALL_TARGET?=	no
@@ -71,12 +71,11 @@ LINKFLAGS_NORMAL=	-X
 KERNLDSCRIPT?=	${USERMODE}/conf/kern.ldscript
 
 SYSTEM_LD=	@do_system_ld() { \
-		target=$$1; shift; \
 		${_MKSHMSG} "   link  ${.CURDIR:T}/${.TARGET}"; \
 		${_MKSHECHO}\
-		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o $${target} ${LINKFORMAT} -Ttext ${TEXTADDR} '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o ${USERMODE_LIBS} $$@; \
+		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o ${.TARGET} ${LINKFORMAT} -Ttext ${TEXTADDR} '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o ${USERMODE_LIBS} $$@; \
 		${SYSTEM_LD_FIX} \
-		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o $${target} ${LINKFORMAT} -Ttext ${TEXTADDR} ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o ${USERMODE_LIBS} $$@; \
+		${CC} -static ${COPTS} -Wl,-Map,$${target}.map -o ${.TARGET} ${LINKFORMAT} -Ttext ${TEXTADDR} ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o ${USERMODE_LIBS} $$@; \
 		}; \
 		do_system_ld
 NVFLAGS=	-n



CVS commit: src/sys/arch/usermode/usermode

2018-01-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan 13 15:15:03 UTC 2018

Modified Files:
src/sys/arch/usermode/usermode: process_machdep.c

Log Message:
Implement dummy process_read_dbreg() and process_write_dbreg() used in x86


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/usermode/usermode/process_machdep.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/usermode/usermode/process_machdep.c
diff -u src/sys/arch/usermode/usermode/process_machdep.c:1.3 src/sys/arch/usermode/usermode/process_machdep.c:1.4
--- src/sys/arch/usermode/usermode/process_machdep.c:1.3	Sat Jan  4 00:10:03 2014
+++ src/sys/arch/usermode/usermode/process_machdep.c	Sat Jan 13 15:15:03 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: process_machdep.c,v 1.3 2014/01/04 00:10:03 dsl Exp $ */
+/* $NetBSD: process_machdep.c,v 1.4 2018/01/13 15:15:03 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.3 2014/01/04 00:10:03 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.4 2018/01/13 15:15:03 reinoud Exp $");
 
 #include 
 #include 
@@ -68,3 +68,16 @@ process_set_pc(struct lwp *l, void *addr
 {
 	return 0;
 }
+
+int
+process_write_dbregs(struct lwp *l, const struct dbreg *regs, size_t sz)
+{
+	return 0;
+}
+
+int
+process_read_dbregs(struct lwp *l, struct dbreg *regs, size_t *sz)
+{
+	return 0;
+}
+



CVS commit: src/sys/arch/usermode/include

2018-01-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan 13 14:39:15 UTC 2018

Modified Files:
src/sys/arch/usermode/include: reg.h

Log Message:
Add dbreg structure prototype needed for x86_64


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/usermode/include/reg.h

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/usermode/include/reg.h
diff -u src/sys/arch/usermode/include/reg.h:1.2 src/sys/arch/usermode/include/reg.h:1.3
--- src/sys/arch/usermode/include/reg.h:1.2	Wed Oct 21 16:06:59 2009
+++ src/sys/arch/usermode/include/reg.h	Sat Jan 13 14:39:15 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: reg.h,v 1.2 2009/10/21 16:06:59 snj Exp $ */
+/* $NetBSD: reg.h,v 1.3 2018/01/13 14:39:15 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -35,4 +35,8 @@ struct reg {
 struct fpreg {
 };
 
+/* x86_64 only */
+struct dbreg {
+};
+
 #endif /* !_ARCH_USERMODE_INCLUDE_REG_H */



CVS commit: src/sys/kern

2018-01-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan 13 13:53:36 UTC 2018

Modified Files:
src/sys/kern: subr_interrupt.c

Log Message:
Compilation of a kernel outside the build.sh framework exposed the
uninitialised usage of `error' in interrupt_avert_intr(). In theory it can
reach the `out' label without `error' initialized. No idea if that really ever
happens in practice.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/kern/subr_interrupt.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/kern/subr_interrupt.c
diff -u src/sys/kern/subr_interrupt.c:1.2 src/sys/kern/subr_interrupt.c:1.3
--- src/sys/kern/subr_interrupt.c:1.2	Thu Jun  1 02:45:13 2017
+++ src/sys/kern/subr_interrupt.c	Sat Jan 13 13:53:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_interrupt.c,v 1.2 2017/06/01 02:45:13 chs Exp $	*/
+/*	$NetBSD: subr_interrupt.c,v 1.3 2018/01/13 13:53:36 reinoud Exp $	*/
 
 /*
  * Copyright (c) 2015 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_interrupt.c,v 1.2 2017/06/01 02:45:13 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_interrupt.c,v 1.3 2018/01/13 13:53:36 reinoud Exp $");
 
 #include 
 #include 
@@ -126,7 +126,7 @@ interrupt_avert_intr(u_int cpu_idx)
 	kcpuset_t *cpuset;
 	struct intrids_handler *ii_handler;
 	intrid_t *ids;
-	int error, i, nids;
+	int error = 0, i, nids;
 
 	kcpuset_create(, true);
 	kcpuset_set(cpuset, cpu_idx);



CVS commit: src/sys/arch/usermode/dev

2018-01-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan 13 10:27:58 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: ld_thunkbus.c

Log Message:
Keep up with changes in ld(4): adding ioctl handling on the ld(4) instead of
using the old dedicated ldflush() function.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/usermode/dev/ld_thunkbus.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/usermode/dev/ld_thunkbus.c
diff -u src/sys/arch/usermode/dev/ld_thunkbus.c:1.31 src/sys/arch/usermode/dev/ld_thunkbus.c:1.32
--- src/sys/arch/usermode/dev/ld_thunkbus.c:1.31	Sat Jan 13 10:08:35 2018
+++ src/sys/arch/usermode/dev/ld_thunkbus.c	Sat Jan 13 10:27:58 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_thunkbus.c,v 1.31 2018/01/13 10:08:35 reinoud Exp $ */
+/* $NetBSD: ld_thunkbus.c,v 1.32 2018/01/13 10:27:58 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -27,13 +27,14 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.31 2018/01/13 10:08:35 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.32 2018/01/13 10:27:58 reinoud Exp $");
 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -48,7 +49,7 @@ static void	ld_thunkbus_attach(device_t,
 
 static int	ld_thunkbus_ldstart(struct ld_softc *, struct buf *);
 static int	ld_thunkbus_lddump(struct ld_softc *, void *, int, int);
-static int	ld_thunkbus_ldflush(struct ld_softc *, int);
+static int	ld_thunkbus_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
 
 //#define LD_USE_AIO
 
@@ -122,7 +123,7 @@ ld_thunkbus_attach(device_t parent, devi
 	ld->sc_maxqueuecnt = 1;
 	ld->sc_start = ld_thunkbus_ldstart;
 	ld->sc_dump = ld_thunkbus_lddump;
-	ld->sc_flush = ld_thunkbus_ldflush;
+	ld->sc_ioctl = ld_thunkbus_ioctl;
 
 	sc->sc_ih = softint_establish(SOFTINT_BIO,
 	ld_thunkbus_complete, ld);
@@ -315,13 +316,19 @@ ld_thunkbus_lddump(struct ld_softc *ld, 
 	return 0;
 }
 
+
 static int
-ld_thunkbus_ldflush(struct ld_softc *ld, int flags)
+ld_thunkbus_ioctl(struct ld_softc *ld, u_long cmd, void *addr, int32_t flag,
+bool poll)
 {
 	struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld;
 
-	if (thunk_fsync(sc->sc_fd) == -1)
-		return thunk_geterrno();
-
-	return 0;
+	switch (cmd) {
+	case DIOCCACHESYNC:
+		if (thunk_fsync(sc->sc_fd) == -1)
+			return thunk_geterrno();
+		return 0;
+	default:
+		return EPASSTHROUGH;
+	}
 }



CVS commit: src/sys/arch/usermode/dev

2018-01-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan 13 10:08:35 UTC 2018

Modified Files:
src/sys/arch/usermode/dev: ld_thunkbus.c

Log Message:
Add the missing strategy argument of ldattach()


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/usermode/dev/ld_thunkbus.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/usermode/dev/ld_thunkbus.c
diff -u src/sys/arch/usermode/dev/ld_thunkbus.c:1.30 src/sys/arch/usermode/dev/ld_thunkbus.c:1.31
--- src/sys/arch/usermode/dev/ld_thunkbus.c:1.30	Sat Jan 21 22:09:57 2012
+++ src/sys/arch/usermode/dev/ld_thunkbus.c	Sat Jan 13 10:08:35 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_thunkbus.c,v 1.30 2012/01/21 22:09:57 reinoud Exp $ */
+/* $NetBSD: ld_thunkbus.c,v 1.31 2018/01/13 10:08:35 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.30 2012/01/21 22:09:57 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.31 2018/01/13 10:08:35 reinoud Exp $");
 
 #include 
 #include 
@@ -135,7 +135,7 @@ ld_thunkbus_attach(device_t parent, devi
 
 	sc->busy = false;
 
-	ldattach(ld);
+	ldattach(ld, BUFQ_DISK_DEFAULT_STRAT);
 }
 
 #ifdef LD_USE_AIO
@@ -260,7 +260,7 @@ ld_thunkbus_complete(void *arg)
 	struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld;
 	struct ld_thunkbus_transfer *tt = >sc_tt;
 	struct buf *bp = tt->tt_bp;
-	off_t offset = bp->b_rawblkno * ld->sc_secsize;
+	off_t offset = (off_t) bp->b_rawblkno * ld->sc_secsize;
 	int64_t ret;
 
 	if (!sc->busy)



CVS commit: src/doc/roadmaps

2017-01-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Jan 13 13:40:44 UTC 2017

Modified Files:
src/doc/roadmaps: ports

Log Message:
The Cheri https:// link is not valid, replace by standard http://


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/doc/roadmaps/ports

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

Modified files:

Index: src/doc/roadmaps/ports
diff -u src/doc/roadmaps/ports:1.1 src/doc/roadmaps/ports:1.2
--- src/doc/roadmaps/ports:1.1	Fri Jan 13 10:14:58 2017
+++ src/doc/roadmaps/ports	Fri Jan 13 13:40:44 2017
@@ -1,4 +1,4 @@
-$NetBSD: ports,v 1.1 2017/01/13 10:14:58 dholland Exp $
+$NetBSD: ports,v 1.2 2017/01/13 13:40:44 reinoud Exp $
 
 NetBSD Ports Roadmap
 
@@ -85,7 +85,7 @@ We have some riscv code and a bit of or1
 
  6. cheri port
 
-https://cheri-cpu.org
+http://cheri-cpu.org
 There are a number of reasons to tackle this; it will serve as a code
 quality lever. Also there's already a FreeBSD port to steal from.
 



CVS commit: src/sys/fs/udf

2016-05-24 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue May 24 09:55:57 UTC 2016

Modified Files:
src/sys/fs/udf: udf.h udf_readwrite.c udf_strat_bootstrap.c
udf_strat_direct.c udf_strat_rmw.c udf_strat_sequential.c
udf_subr.c udf_subr.h

Log Message:
Cleanup VAT writout. To prevent issues with the sequential writing strategy
trying to write on blocks that are lost due to the synchronisation, don't just
bluntly do synchronize device caches, but split out on strategies.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/fs/udf/udf.h
cvs rdiff -u -r1.11 -r1.12 src/sys/fs/udf/udf_readwrite.c
cvs rdiff -u -r1.4 -r1.5 src/sys/fs/udf/udf_strat_bootstrap.c
cvs rdiff -u -r1.13 -r1.14 src/sys/fs/udf/udf_strat_direct.c
cvs rdiff -u -r1.27 -r1.28 src/sys/fs/udf/udf_strat_rmw.c
cvs rdiff -u -r1.14 -r1.15 src/sys/fs/udf/udf_strat_sequential.c
cvs rdiff -u -r1.137 -r1.138 src/sys/fs/udf/udf_subr.c
cvs rdiff -u -r1.19 -r1.20 src/sys/fs/udf/udf_subr.h

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

Modified files:

Index: src/sys/fs/udf/udf.h
diff -u src/sys/fs/udf/udf.h:1.51 src/sys/fs/udf/udf.h:1.52
--- src/sys/fs/udf/udf.h:1.51	Tue May 10 15:23:39 2016
+++ src/sys/fs/udf/udf.h	Tue May 24 09:55:57 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: udf.h,v 1.51 2016/05/10 15:23:39 reinoud Exp $ */
+/* $NetBSD: udf.h,v 1.52 2016/05/24 09:55:57 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -76,7 +76,7 @@ extern int udf_verbose;
 #define UDF_DEBUG_RESERVE	0x100
 
 /* initial value of udf_verbose */
-#define UDF_DEBUGGING		0
+#define UDF_DEBUGGING		(0)
 
 #ifdef UDF_DEBUG
 #define DPRINTF(name, arg) { \
@@ -252,6 +252,7 @@ struct udf_strategy {
 	int  (*read_logvol_dscr)(struct udf_strat_args *args);
 	int  (*write_logvol_dscr)   (struct udf_strat_args *args);
 	void (*queuebuf)	(struct udf_strat_args *args);
+	void (*sync_caches)	(struct udf_strat_args *args);
 	void (*discstrat_init)  (struct udf_strat_args *args);
 	void (*discstrat_finish)(struct udf_strat_args *args);
 };

Index: src/sys/fs/udf/udf_readwrite.c
diff -u src/sys/fs/udf/udf_readwrite.c:1.11 src/sys/fs/udf/udf_readwrite.c:1.12
--- src/sys/fs/udf/udf_readwrite.c:1.11	Sun Jun 12 03:35:55 2011
+++ src/sys/fs/udf/udf_readwrite.c	Tue May 24 09:55:57 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_readwrite.c,v 1.11 2011/06/12 03:35:55 rmind Exp $ */
+/* $NetBSD: udf_readwrite.c,v 1.12 2016/05/24 09:55:57 reinoud Exp $ */
 
 /*
  * Copyright (c) 2007, 2008 Reinoud Zandijk
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_readwrite.c,v 1.11 2011/06/12 03:35:55 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_readwrite.c,v 1.12 2016/05/24 09:55:57 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -696,6 +696,19 @@ udf_discstrat_queuebuf(struct udf_mount 
 
 
 void
+udf_synchronise_caches(struct udf_mount *ump)
+{
+	struct udf_strategy *strategy = ump->strategy;
+	struct udf_strat_args args;
+
+	KASSERT(strategy);
+	args.ump = ump;
+
+	(strategy->sync_caches)();
+}
+
+
+void
 udf_discstrat_init(struct udf_mount *ump)
 {
 	struct udf_strategy *strategy = ump->strategy;

Index: src/sys/fs/udf/udf_strat_bootstrap.c
diff -u src/sys/fs/udf/udf_strat_bootstrap.c:1.4 src/sys/fs/udf/udf_strat_bootstrap.c:1.5
--- src/sys/fs/udf/udf_strat_bootstrap.c:1.4	Mon Nov 10 18:46:33 2014
+++ src/sys/fs/udf/udf_strat_bootstrap.c	Tue May 24 09:55:57 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_strat_bootstrap.c,v 1.4 2014/11/10 18:46:33 maxv Exp $ */
+/* $NetBSD: udf_strat_bootstrap.c,v 1.5 2016/05/24 09:55:57 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_strat_bootstrap.c,v 1.4 2014/11/10 18:46:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_strat_bootstrap.c,v 1.5 2016/05/24 09:55:57 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -115,6 +115,14 @@ udf_queuebuf_bootstrap(struct udf_strat_
 	VOP_STRATEGY(ump->devvp, buf);
 }
 
+
+static void
+udf_sync_caches_bootstrap(struct udf_strat_args *args)
+{
+	/* empty */
+}
+
+
 static void
 udf_discstrat_init_bootstrap(struct udf_strat_args *args)
 {
@@ -137,6 +145,7 @@ struct udf_strategy udf_strat_bootstrap 
 	udf_read_logvol_dscr_bootstrap,
 	udf_write_logvol_dscr_bootstrap,
 	udf_queuebuf_bootstrap,
+	udf_sync_caches_bootstrap,
 	udf_discstrat_init_bootstrap,
 	udf_discstrat_finish_bootstrap
 };

Index: src/sys/fs/udf/udf_strat_direct.c
diff -u src/sys/fs/udf/udf_strat_direct.c:1.13 src/sys/fs/udf/udf_strat_direct.c:1.14
--- src/sys/fs/udf/udf_strat_direct.c:1.13	Tue Oct  6 08:57:34 2015
+++ src/sys/fs/udf/udf_strat_direct.c	Tue May 24 09:55:57 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_strat_direct.c,v 1.13 2015/10/06 08:57:34 hannken Exp $ */
+/* $NetBSD: udf_strat_direct.c,v 1.14 2016/05/24 09:55:57 reinoud Exp $ */
 
 /*
 

CVS commit: src/sys/dev/scsipi

2016-05-15 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun May 15 15:37:38 UTC 2016

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
Use _align(2) workaround for PR kern/51141. This fixes odd CD length
reporting.


To generate a diff of this commit:
cvs rdiff -u -r1.330 -r1.331 src/sys/dev/scsipi/cd.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/dev/scsipi/cd.c
diff -u src/sys/dev/scsipi/cd.c:1.330 src/sys/dev/scsipi/cd.c:1.331
--- src/sys/dev/scsipi/cd.c:1.330	Sun Apr 26 15:15:20 2015
+++ src/sys/dev/scsipi/cd.c	Sun May 15 15:37:38 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd.c,v 1.330 2015/04/26 15:15:20 mlelstv Exp $	*/
+/*	$NetBSD: cd.c,v 1.331 2016/05/15 15:37:38 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.330 2015/04/26 15:15:20 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.331 2016/05/15 15:37:38 reinoud Exp $");
 
 #include 
 #include 
@@ -1799,9 +1799,9 @@ read_cd_capacity(struct scsipi_periph *p
 	 */
 	struct scsipi_read_cd_cap_datacap __aligned(2);
 	struct scsipi_read_discinfo   di_cmd;
-	struct scsipi_read_discinfo_data  di;
+	struct scsipi_read_discinfo_data  di __aligned(2);
 	struct scsipi_read_trackinfo  ti_cmd;
-	struct scsipi_read_trackinfo_data ti;
+	struct scsipi_read_trackinfo_data ti __aligned(2);
 	uint32_t track_start, track_size;
 	int error, flags, msb, lsb, last_track;
 
@@ -2986,7 +2986,7 @@ mmc_getdiscinfo(struct scsipi_periph *pe
 	struct scsipi_get_conf_data  *gc;
 	struct scsipi_get_conf_feature   *gcf;
 	struct scsipi_read_discinfo   di_cmd;
-	struct scsipi_read_discinfo_data  di;
+	struct scsipi_read_discinfo_data  di __aligned(2);
 	const uint32_t buffer_size = 1024;
 	uint32_t feat_tbl_len, pos;
 	u_long   last_lba = 0;
@@ -3502,9 +3502,9 @@ mmc_gettrackinfo(struct scsipi_periph *p
 		 struct mmc_trackinfo *trackinfo)
 {
 	struct scsipi_read_trackinfo  ti_cmd;
-	struct scsipi_read_trackinfo_data ti;
+	struct scsipi_read_trackinfo_data ti __aligned(2);
 	struct scsipi_get_configuration   gc_cmd;
-	struct scsipi_get_conf_data   gc;
+	struct scsipi_get_conf_data   gc __aligned(2);
 	int error, flags;
 	int mmc_profile;
 



CVS commit: src/sys/fs/udf

2016-05-10 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue May 10 15:23:39 UTC 2016

Modified Files:
src/sys/fs/udf: udf.h udf_subr.c

Log Message:
Rework VAT searching on recordable media. It is now a lot more resilliant to
errors and it allows for VAT searching on crashed writeouts.

While here, make sure the node pointer is always initialised in
udf_get_node().


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/fs/udf/udf.h
cvs rdiff -u -r1.136 -r1.137 src/sys/fs/udf/udf_subr.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/fs/udf/udf.h
diff -u src/sys/fs/udf/udf.h:1.50 src/sys/fs/udf/udf.h:1.51
--- src/sys/fs/udf/udf.h:1.50	Mon Aug 24 08:31:56 2015
+++ src/sys/fs/udf/udf.h	Tue May 10 15:23:39 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: udf.h,v 1.50 2015/08/24 08:31:56 hannken Exp $ */
+/* $NetBSD: udf.h,v 1.51 2016/05/10 15:23:39 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -417,11 +417,12 @@ struct udf_node {
 #define	IN_SYNCED		0x0200	/* node is being used by sync */
 #define	IN_CALLBACK_ULK		0x0400	/* node will be unlocked by callback */
 #define	IN_NODE_REBUILD		0x0800	/* node is rebuild */
+#define IN_NO_DELETE		0x1000	/* node is not to be deleted */
 
 
 #define IN_FLAGBITS \
 	"\10\1IN_ACCESS\2IN_CHANGE\3IN_UPDATE\4IN_MODIFY\5IN_MODIFIED" \
 	"\6IN_ACCESSED\7IN_RENAME\10IN_DELETED\11IN_LOCKED\12IN_SYNCED" \
-	"\13IN_CALLBACK_ULK\14IN_NODE_REBUILD"
+	"\13IN_CALLBACK_ULK\14IN_NODE_REBUILD\15IN_NO_DELETE"
 
 #endif /* !_FS_UDF_UDF_H_ */

Index: src/sys/fs/udf/udf_subr.c
diff -u src/sys/fs/udf/udf_subr.c:1.136 src/sys/fs/udf/udf_subr.c:1.137
--- src/sys/fs/udf/udf_subr.c:1.136	Wed Jan 27 00:06:49 2016
+++ src/sys/fs/udf/udf_subr.c	Tue May 10 15:23:39 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_subr.c,v 1.136 2016/01/27 00:06:49 reinoud Exp $ */
+/* $NetBSD: udf_subr.c,v 1.137 2016/05/10 15:23:39 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -29,7 +29,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.136 2016/01/27 00:06:49 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.137 2016/05/10 15:23:39 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -946,7 +946,7 @@ udf_read_anchors(struct udf_mount *ump)
 
 	/* VATs are only recorded on sequential media, but initialise */
 	ump->first_possible_vat_location = track_start + 2;
-	ump->last_possible_vat_location  = track_end + last_track.packet_size;
+	ump->last_possible_vat_location  = track_end;
 
 	return ok;
 }
@@ -2995,6 +2995,10 @@ udf_check_for_vat(struct udf_node *vat_n
 	ump->logvol_integrity->integrity_type = udf_rw32(UDF_INTEGRITY_CLOSED);
 	ump->logvol_integrity->time   = *mtime;
 
+	/* if we're updating, free old allocated space */
+	if (ump->vat_table)
+		free(ump->vat_table, M_UDFVOLD);
+
 	ump->vat_table_len = vat_length;
 	ump->vat_table_alloc_len = vat_table_alloc_len;
 	ump->vat_table   = vat_table;
@@ -3017,49 +3021,70 @@ out:
 static int
 udf_search_vat(struct udf_mount *ump, union udf_pmap *mapping)
 {
-	struct udf_node *vat_node;
+	struct udf_node *vat_node, *accepted_vat_node;
 	struct long_ad	 icb_loc;
-	uint32_t early_vat_loc, vat_loc;
+	uint32_t early_vat_loc, late_vat_loc, vat_loc;
 	int error;
 
 	/* mapping info not needed */
 	mapping = mapping;
 
-	vat_loc = ump->last_possible_vat_location;
-	early_vat_loc = vat_loc - 256;	/* 8 blocks of 32 sectors */
-
-	DPRINTF(VOLUMES, ("1) last possible %d, early_vat_loc %d \n",
-		vat_loc, early_vat_loc));
-	early_vat_loc = MAX(early_vat_loc, ump->first_possible_vat_location);
-
-	DPRINTF(VOLUMES, ("2) last possible %d, early_vat_loc %d \n",
-		vat_loc, early_vat_loc));
-
-	/* start looking from the end of the range */
+	DPRINTF(VOLUMES, ("Searching VAT\n"));
+	
+	/*
+	 * Start reading forward in blocks from the first possible vat
+	 * location. If not found in this block, start again a bit before
+	 * until we get a hit.
+	 */
+	late_vat_loc = ump->last_possible_vat_location;
+	early_vat_loc = MAX(late_vat_loc - 64, ump->first_possible_vat_location);
+ 
+	DPRINTF(VOLUMES, ("\tfull range %d to %d\n", early_vat_loc, late_vat_loc));
+	accepted_vat_node = NULL;
 	do {
-		DPRINTF(VOLUMES, ("Checking for VAT at sector %d\n", vat_loc));
-		icb_loc.loc.part_num = udf_rw16(UDF_VTOP_RAWPART);
-		icb_loc.loc.lb_num   = udf_rw32(vat_loc);
+		vat_loc = early_vat_loc;
+		DPRINTF(VOLUMES, ("\tchecking range %d to %d\n",
+			early_vat_loc, late_vat_loc));
+		do {
+			DPRINTF(VOLUMES, ("\t\tChecking for VAT at sector %d\n",
+vat_loc));
+			icb_loc.loc.part_num = udf_rw16(UDF_VTOP_RAWPART);
+			icb_loc.loc.lb_num   = udf_rw32(vat_loc);
 
-		error = udf_get_node(ump, _loc, _node);
-		if (!error) {
-			error =

CVS commit: src/sys/fs/udf

2016-01-26 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan 27 00:06:49 UTC 2016

Modified Files:
src/sys/fs/udf: udf_subr.c

Log Message:
Fix filename creation and deleting with illegal file names. UDF has a
machanism for it but it allowed to create a file with a name it considered
illegal that then couldn't be deleted with the same name.

Fixes PR kern/50608. When confirmed, it can be closed.


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/sys/fs/udf/udf_subr.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/fs/udf/udf_subr.c
diff -u src/sys/fs/udf/udf_subr.c:1.135 src/sys/fs/udf/udf_subr.c:1.136
--- src/sys/fs/udf/udf_subr.c:1.135	Sat Dec 19 03:16:09 2015
+++ src/sys/fs/udf/udf_subr.c	Wed Jan 27 00:06:49 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_subr.c,v 1.135 2015/12/19 03:16:09 dholland Exp $ */
+/* $NetBSD: udf_subr.c,v 1.136 2016/01/27 00:06:49 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -29,7 +29,7 @@
 
 #include 
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.135 2015/12/19 03:16:09 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.136 2016/01/27 00:06:49 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -4486,7 +4486,8 @@ udf_lookup_name_in_dir(struct vnode *vp,
 	struct dirhash   *dirh;
 	struct dirhash_entry *dirh_ep;
 	struct fileid_desc *fid;
-	struct dirent *dirent;
+	struct dirent *dirent, *s_dirent;
+	struct charspec osta_charspec;
 	uint64_t diroffset;
 	uint32_t lb_size;
 	int hit, error;
@@ -4504,18 +4505,28 @@ udf_lookup_name_in_dir(struct vnode *vp,
 	dirh = dir_node->dir_hash;
 
 	/* allocate temporary space for fid */
-	lb_size = udf_rw32(dir_node->ump->logical_vol->lb_size);
-	fid = malloc(lb_size, M_UDFTEMP, M_WAITOK);
-	dirent  = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK);
+	lb_size  = udf_rw32(dir_node->ump->logical_vol->lb_size);
+	fid  = malloc(lb_size, M_UDFTEMP, M_WAITOK);
+	dirent   = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK);
+	s_dirent = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK);
 
 	DPRINTF(DIRHASH, ("dirhash_lookup looking for `%*.*s`\n",
 		namelen, namelen, name));
 
+	/* convert given unix name to canonical unix name */
+	udf_osta_charset(_charspec);
+	unix_to_udf_name((char *) fid->data, >l_fi,
+		name, namelen, _charspec);
+	udf_to_unix_name(s_dirent->d_name, NAME_MAX,
+		(char *) fid->data, fid->l_fi,
+		_charspec);
+	s_dirent->d_namlen = strlen(s_dirent->d_name);
+
 	/* search our dirhash hits */
 	memset(icb_loc, 0, sizeof(*icb_loc));
 	dirh_ep = NULL;
 	for (;;) {
-		hit = dirhash_lookup(dirh, name, namelen, _ep);
+		hit = dirhash_lookup(dirh, s_dirent->d_name, s_dirent->d_namlen, _ep);
 		/* if no hit, abort the search */
 		if (!hit)
 			break;
@@ -4532,16 +4543,7 @@ udf_lookup_name_in_dir(struct vnode *vp,
 			dirent->d_namlen, dirent->d_namlen, dirent->d_name));
 
 		/* see if its our entry */
-#ifdef DIAGNOSTIC
-		if (dirent->d_namlen != namelen) {
-			printf("WARNING: dirhash_lookup() returned wrong "
-"d_namelen: %d and ought to be %d\n",
-dirent->d_namlen, namelen);
-			printf("\tlooked for `%s' and got `%s'\n",
-name, dirent->d_name);
-		}
-#endif
-		if (strncmp(dirent->d_name, name, namelen) == 0) {
+		if (strncmp(dirent->d_name, s_dirent->d_name, s_dirent->d_namlen) == 0) {
 			*found = 1;
 			*icb_loc = fid->icb;
 			break;
@@ -4549,6 +4551,7 @@ udf_lookup_name_in_dir(struct vnode *vp,
 	}
 	free(fid, M_UDFTEMP);
 	free(dirent, M_UDFTEMP);
+	free(s_dirent, M_UDFTEMP);
 
 	dirhash_put(dir_node->dir_hash);
 
@@ -4718,12 +4721,11 @@ udf_dir_detach(struct udf_mount *ump, st
 	struct dirhash_entry *dirh_ep;
 	struct file_entry*fe  = dir_node->fe;
 	struct fileid_desc *fid;
-	struct dirent *dirent;
+	struct dirent *dirent, *s_dirent;
+	struct charspec osta_charspec;
 	uint64_t diroffset;
 	uint32_t lb_size, fidsize;
 	int found, error;
-	char const *name  = cnp->cn_nameptr;
-	int namelen = cnp->cn_namelen;
 	int hit, refcnt;
 
 	/* get our dirhash and make sure its read in */
@@ -4740,16 +4742,26 @@ udf_dir_detach(struct udf_mount *ump, st
 		assert(dir_node->efe);
 	}
 
-	/* allocate temporary space for fid */
-	lb_size = udf_rw32(dir_node->ump->logical_vol->lb_size);
-	fid = malloc(lb_size, M_UDFTEMP, M_WAITOK);
-	dirent  = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK);
+	/* allocate temporary space for fid and dirents */
+	lb_size  = udf_rw32(dir_node->ump->logical_vol->lb_size);
+	fid  = malloc(lb_size, M_UDFTEMP, M_WAITOK);
+	dirent   = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK);
+	s_dirent = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK);
+
+	/* convert given unix name to canonical unix name */
+	udf_osta_charset(_charspec);

CVS commit: src/include

2015-11-19 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu Nov 19 20:34:47 UTC 2015

Modified Files:
src/include: ucontext.h

Log Message:
Fix ANSI-C prototype error


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/include/ucontext.h

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

Modified files:

Index: src/include/ucontext.h
diff -u src/include/ucontext.h:1.7 src/include/ucontext.h:1.8
--- src/include/ucontext.h:1.7	Sat Nov  5 09:27:06 2011
+++ src/include/ucontext.h	Thu Nov 19 20:34:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucontext.h,v 1.7 2011/11/05 09:27:06 joerg Exp $	*/
+/*	$NetBSD: ucontext.h,v 1.8 2015/11/19 20:34:47 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 __BEGIN_DECLS
 int	getcontext(ucontext_t *) __returns_twice;
 int	setcontext(const ucontext_t *);
-void	makecontext(ucontext_t *, void (*)(), int, ...);
+void	makecontext(ucontext_t *, void (*)(void), int, ...);
 int	swapcontext(ucontext_t * __restrict, const ucontext_t * __restrict);
 __END_DECLS
 



CVS commit: src/include

2015-11-19 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu Nov 19 20:57:49 UTC 2015

Modified Files:
src/include: ucontext.h

Log Message:
Revert


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/include/ucontext.h

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

Modified files:

Index: src/include/ucontext.h
diff -u src/include/ucontext.h:1.8 src/include/ucontext.h:1.9
--- src/include/ucontext.h:1.8	Thu Nov 19 20:34:47 2015
+++ src/include/ucontext.h	Thu Nov 19 20:57:49 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucontext.h,v 1.8 2015/11/19 20:34:47 reinoud Exp $	*/
+/*	$NetBSD: ucontext.h,v 1.9 2015/11/19 20:57:49 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 __BEGIN_DECLS
 int	getcontext(ucontext_t *) __returns_twice;
 int	setcontext(const ucontext_t *);
-void	makecontext(ucontext_t *, void (*)(void), int, ...);
+void	makecontext(ucontext_t *, void (*)(), int, ...);
 int	swapcontext(ucontext_t * __restrict, const ucontext_t * __restrict);
 __END_DECLS
 



CVS commit: src/sys/arch/evbarm/conf

2015-07-16 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Thu Jul 16 13:10:37 UTC 2015

Modified Files:
src/sys/arch/evbarm/conf: MARVELL_NAS

Log Message:
Update MARVELL_NAS to allow it to execute 6.X userland and fix obvious
obmissions.

The config file itself would benefit from rewriting it to use GENERIC.common
but i haven't dug into that yet.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/evbarm/conf/MARVELL_NAS

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/evbarm/conf/MARVELL_NAS
diff -u src/sys/arch/evbarm/conf/MARVELL_NAS:1.21 src/sys/arch/evbarm/conf/MARVELL_NAS:1.22
--- src/sys/arch/evbarm/conf/MARVELL_NAS:1.21	Sat Aug 23 20:26:57 2014
+++ src/sys/arch/evbarm/conf/MARVELL_NAS	Thu Jul 16 13:10:37 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: MARVELL_NAS,v 1.21 2014/08/23 20:26:57 dholland Exp $
+#	$NetBSD: MARVELL_NAS,v 1.22 2015/07/16 13:10:37 reinoud Exp $
 #
 #  This configuration supports for generically Marvell NAS.
 
@@ -101,6 +101,9 @@ options 	COMPAT_16	# NetBSD 1.6,
 options 	COMPAT_20	# NetBSD 2.0,
 options 	COMPAT_30	# NetBSD 3.0, and
 options 	COMPAT_40	# NetBSD 4.0 binary compatibility.
+options 	COMPAT_50	# NetBSD 5.0,
+options 	COMPAT_60	# NetBSD 6.0, and
+options 	COMPAT_70	# NetBSD 7.0 binary compatibility.
 #options 	COMPAT_43	# 4.3BSD compatibility.
 #options 	TCP_COMPAT_42	# 4.2BSD TCP/IP bug compat. Not recommended.
 
@@ -109,9 +112,9 @@ options 	COMPAT_BSDPTY	# /dev/[pt]ty?? p
 
 # Shared memory options
 
-#options 	SYSVMSG		# System V-like message queues
-#options 	SYSVSEM		# System V-like semaphores
-#options 	SYSVSHM		# System V-like memory sharing
+options 	SYSVMSG		# System V-like message queues
+options 	SYSVSEM		# System V-like semaphores
+options 	SYSVSHM		# System V-like memory sharing
 
 # Device options
 
@@ -233,6 +236,31 @@ wd*	at umass?
 uplcom* at uhub? port ?			# I/O DATA USB-RSAQ2 serial adapter
 ucom*   at uplcom? portno ?
 
+# Wedge support   
+options 	DKWEDGE_AUTODISCOVER	# Automatically add dk(4) instances
+options 	DKWEDGE_METHOD_GPT	# Supports GPT partitions as wedges
+
+# Alternate buffer queue strategies for better responsiveness under high
+# disk I/O load.
+#options 	BUFQ_READPRIO
+options 	BUFQ_PRIOCSCAN
+
+# Development and Debugging options
+
+#options 	PERFCTRS	# performance counters
+#options 	DIAGNOSTIC	# internal consistency checks
+#options 	DEBUG
+#options 	LOCKDEBUG
+#options 	PMAP_DEBUG	# Enable pmap_debug_level code
+#options 	IPKDB		# remote kernel debugging
+#options 	VERBOSE_INIT_ARM # verbose bootstraping messages
+options 	DDB		# in-kernel debugger
+options 	DDB_ONPANIC=0
+options 	DDB_HISTORY_SIZE=100	# Enable history editing in DDB
+options 	DDB_COMMANDONENTER=bt
+#options 	KGDB
+#options		SYSCALL_DEBUG
+
 
 # Pseudo-Devices
 
@@ -271,7 +299,7 @@ pseudo-device	loop			# network loopback
 #pseudo-device	strip			# Starmode Radio IP (Metricom)
 #pseudo-device	irframetty		# IrDA frame line discipline
 #pseudo-device	tap			# virtual Ethernet
-#pseudo-device	tun			# network tunneling over tty
+pseudo-device	tun			# network tunneling over tty
 #pseudo-device	gre			# generic L3 over IP tunnel
 #pseudo-device	gif			# IPv[46] over IPv[46] tunnel (RFC 1933)
 #pseudo-device	faith			# IPv[46] TCP relay translation i/f
@@ -280,7 +308,7 @@ pseudo-device	loop			# network loopback
 #pseudo-device	bridge			# simple inter-network bridging
 #options	BRIDGE_IPF		# bridge uses IP/IPv6 pfil hooks too
 #pseudo-device	agr			# IEEE 802.3ad link aggregation
-#pseudo-device	pf			# PF packet filter
+pseudo-device	npf			# NPF packet filter
 #pseudo-device	pflog			# PF log if
 
 # miscellaneous pseudo-devices



CVS commit: src/sys/fs/udf

2015-01-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Jan  4 14:23:37 UTC 2015

Modified Files:
src/sys/fs/udf: udf_vnops.c

Log Message:
Add missing vrele() as found by the testsuite.

Thanks Jurgen Hannken for the patch.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/fs/udf/udf_vnops.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/fs/udf/udf_vnops.c
diff -u src/sys/fs/udf/udf_vnops.c:1.95 src/sys/fs/udf/udf_vnops.c:1.96
--- src/sys/fs/udf/udf_vnops.c:1.95	Wed Dec  3 21:37:55 2014
+++ src/sys/fs/udf/udf_vnops.c	Sun Jan  4 14:23:37 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_vnops.c,v 1.95 2014/12/03 21:37:55 reinoud Exp $ */
+/* $NetBSD: udf_vnops.c,v 1.96 2015/01/04 14:23:37 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -32,7 +32,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__KERNEL_RCSID(0, $NetBSD: udf_vnops.c,v 1.95 2014/12/03 21:37:55 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: udf_vnops.c,v 1.96 2015/01/04 14:23:37 reinoud Exp $);
 #endif /* not lint */
 
 
@@ -1742,6 +1742,8 @@ udf_symlink(void *v)
 			/* remove node */
 			udf_dir_detach(udf_node-ump, dir_node, udf_node, cnp);
 			udf_delete_node(udf_node);
+			vrele(*vpp);
+			*vpp = NULL;
 		}
 	}
 	return error;



  1   2   3   4   5   6   7   >