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

2023-04-03 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Apr  3 17:58:41 UTC 2023

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

Log Message:
usermode/syscall.c: s/fall trough/FALLTHROUGH/ (KNF)


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/usermode/usermode/syscall.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/syscall.c
diff -u src/sys/arch/usermode/usermode/syscall.c:1.25 src/sys/arch/usermode/usermode/syscall.c:1.26
--- src/sys/arch/usermode/usermode/syscall.c:1.25	Sat Apr  6 11:54:21 2019
+++ src/sys/arch/usermode/usermode/syscall.c	Mon Apr  3 17:58:41 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: syscall.c,v 1.25 2019/04/06 11:54:21 kamil Exp $ */
+/* $NetBSD: syscall.c,v 1.26 2023/04/03 17:58:41 gutteridge Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.25 2019/04/06 11:54:21 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.26 2023/04/03 17:58:41 gutteridge Exp $");
 
 #include 
 #include 
@@ -137,10 +137,10 @@ syscall(void)
 //out:
 	switch (error) {
 	default:
-		/* fall trough */
+		/* FALLTHROUGH */
 	case 0:
 		md_syscall_set_returnargs(l, ucp, error, rval);
-		/* fall trough */
+		/* FALLTHROUGH */
 	case EJUSTRETURN:
 		break;
 	case ERESTART:



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

2023-04-03 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Apr  3 17:58:41 UTC 2023

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

Log Message:
usermode/syscall.c: s/fall trough/FALLTHROUGH/ (KNF)


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/usermode/usermode/syscall.c

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



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

2022-03-20 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Mar 20 18:56:29 UTC 2022

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

Log Message:
fix typos in debug/panic messages: isued->issued, initialiased->initialised.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 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.116 src/sys/arch/usermode/usermode/pmap.c:1.117
--- src/sys/arch/usermode/usermode/pmap.c:1.116	Sat Jul 24 21:31:36 2021
+++ src/sys/arch/usermode/usermode/pmap.c	Sun Mar 20 18:56:29 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.116 2021/07/24 21:31:36 andvar Exp $ */
+/* $NetBSD: pmap.c,v 1.117 2022/03/20 18:56:29 andvar Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.116 2021/07/24 21:31:36 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.117 2022/03/20 18:56:29 andvar Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -328,7 +328,7 @@ pmap_bootstrap(void)
 
 	memset(pv_table, 0, pv_table_size);	/* test and clear */
 
-	thunk_printf_debug("pv_table initialiased correctly, mmap works\n");
+	thunk_printf_debug("pv_table initialised correctly, mmap works\n");
 
 	/* advance */
 	kmem_kvm_cur_start += pv_table_size;
@@ -369,7 +369,7 @@ pmap_bootstrap(void)
 
 	memset(pmap->pm_l1, 0, pm_l1_size);	/* test and clear */
 
-	thunk_printf_debug("kernel pmap l1 table initialiased correctly\n");
+	thunk_printf_debug("kernel pmap l1 table initialised correctly\n");
 
 	/* advance for l1 tables */
 	kmem_kvm_cur_start += round_page(pm_l1_size);
@@ -895,7 +895,7 @@ pmap_do_enter(pmap_t pmap, vaddr_t va, p
 	lpn = atop(va - VM_MIN_ADDRESS);	/* V->L */
 #ifdef DIAGNOSTIC
 	if ((va < VM_MIN_ADDRESS) || (va > VM_MAX_KERNEL_ADDRESS))
-		panic("pmap_do_enter: invalid va isued\n");
+		panic("pmap_do_enter: invalid va issued\n");
 #endif
 
 	/* raise interrupt level */
@@ -1121,7 +1121,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 isued\n");
+		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;



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

2022-03-20 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Mar 20 18:56:29 UTC 2022

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

Log Message:
fix typos in debug/panic messages: isued->issued, initialiased->initialised.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 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.



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

2019-11-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Nov 13 09:47:37 UTC 2019

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

Log Message:
Switch to the new PTE naming.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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.5 src/sys/arch/usermode/usermode/db_memrw.c:1.6
--- src/sys/arch/usermode/usermode/db_memrw.c:1.5	Sat Mar  9 08:42:26 2019
+++ src/sys/arch/usermode/usermode/db_memrw.c	Wed Nov 13 09:47:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.5 2019/03/09 08:42:26 maxv Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.6 2019/11/13 09:47:37 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.5 2019/03/09 08:42:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.6 2019/11/13 09:47:37 maxv Exp $");
 
 #include 
 #include 
@@ -162,7 +162,7 @@ db_write_text(vaddr_t addr, size_t size,
 		 * with this mapping and subtract it from the
 		 * total size.
 		 */
-		if (pte & PG_PS)
+		if (pte & PTE_PS)
 			limit = NBPD_L2 - (addr & (NBPD_L2 - 1));
 		else
 			limit = PAGE_SIZE - (addr & PGOFSET);



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

2019-11-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Nov 13 09:47:37 UTC 2019

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

Log Message:
Switch to the new PTE naming.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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.



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

2019-04-09 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Apr 10 03:39:34 UTC 2019

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

Log Message:
 Add missing semicolon.


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

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



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

2019-04-09 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Apr 10 03:39:34 UTC 2019

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

Log Message:
 Add missing semicolon.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/usermode/usermode/copy.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/copy.c
diff -u src/sys/arch/usermode/usermode/copy.c:1.9 src/sys/arch/usermode/usermode/copy.c:1.10
--- src/sys/arch/usermode/usermode/copy.c:1.9	Sat Apr  6 03:06:28 2019
+++ src/sys/arch/usermode/usermode/copy.c	Wed Apr 10 03:39:34 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: copy.c,v 1.9 2019/04/06 03:06:28 thorpej Exp $ */
+/* $NetBSD: copy.c,v 1.10 2019/04/10 03:39:34 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: copy.c,v 1.9 2019/04/06 03:06:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copy.c,v 1.10 2019/04/10 03:39:34 msaitoh Exp $");
 
 #define	__UFETCHSTORE_PRIVATE
 #define	__UCAS_PRIVATE
@@ -114,21 +114,21 @@ int
 _ufetch_8(const uint8_t *uaddr, uint8_t *valp)
 {
 	*valp = *uaddr;
-	return 0
+	return 0;
 }
 
 int
 _ufetch_16(const uint16_t *uaddr, uint16_t *valp)
 {
 	*valp = *uaddr;
-	return 0
+	return 0;
 }
 
 int
 _ufetch_32(const uint32_t *uaddr, uint32_t *valp)
 {
 	*valp = *uaddr;
-	return 0
+	return 0;
 }
 
 #ifdef _LP64
@@ -136,7 +136,7 @@ int
 _ufetch_64(const uint64_t *uaddr, uint64_t *valp)
 {
 	*valp = *uaddr;
-	return 0
+	return 0;
 }
 #endif /* _LP64 */
 
@@ -144,21 +144,21 @@ int
 _ustore_8(uint8_t *uaddr, uint8_t val)
 {
 	*uaddr = val;
-	return 0
+	return 0;
 }
 
 int
 _ustore_16(uint16_t *uaddr, uint16_t val)
 {
 	*uaddr = val;
-	return 0
+	return 0;
 }
 
 int
 _ustore_32(uint32_t *uaddr, uint32_t val)
 {
 	*uaddr = val;
-	return 0
+	return 0;
 }
 
 #ifdef _LP64
@@ -166,6 +166,6 @@ int
 _ustore_64(uint64_t *uaddr, uint64_t val)
 {
 	*uaddr = val;
-	return 0
+	return 0;
 }
 #endif /* _LP64 */



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.



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/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.



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/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.



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/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: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.



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: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.



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.



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/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.



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 listen on socket");
+		close(sockfd);
+		return 0;
+	}
+	printf("kgdb stub: accepting connections on port %d\n", portnr);
+
+	return sockfd;
+}
+
+int
+thunk_gdb_accept(int sockfd)
+{
+	struct 

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.



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/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.



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/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.



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: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.



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.



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/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 
@@ -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/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.



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/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.



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:   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.



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 
@@ -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/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.



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/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.



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

2015-12-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 21 19:54:35 UTC 2015

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

Log Message:
more checking


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 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.85 src/sys/arch/usermode/usermode/thunk.c:1.86
--- src/sys/arch/usermode/usermode/thunk.c:1.85	Fri Feb  6 05:25:13 2015
+++ src/sys/arch/usermode/usermode/thunk.c	Mon Dec 21 14:54:35 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.85 2015/02/06 10:25:13 prlw1 Exp $ */
+/* $NetBSD: thunk.c,v 1.86 2015/12/21 19:54:35 christos Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.85 2015/02/06 10:25:13 prlw1 Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.86 2015/12/21 19:54:35 christos Exp $");
 #endif
 
 #include 
@@ -761,15 +761,19 @@ thunk_getcpuinfo(char *cp, size_t *len)
 
 	fd = open("/proc/cpuinfo", O_RDONLY);
 	if (fd == -1)
-		return -1;
-	rlen = read(fd, cp, *len - 1);
+		goto out;
+	rlen = read(fd, cp, *len);
 	close(fd);
 
 	if (rlen == -1)
-		return -1;
+		goto out;
 
+	buf[rlen ? rlen - 1 : 0] = '\0';
 	*len = rlen;
 	return 0;
+bad:
+	*len = 0;
+	return -1;
 }
 
 int



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

2015-12-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 21 19:54:35 UTC 2015

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

Log Message:
more checking


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 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.



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

2015-12-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 21 20:44:54 UTC 2015

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

Log Message:
fix label and variable name.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 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.86 src/sys/arch/usermode/usermode/thunk.c:1.87
--- src/sys/arch/usermode/usermode/thunk.c:1.86	Mon Dec 21 14:54:35 2015
+++ src/sys/arch/usermode/usermode/thunk.c	Mon Dec 21 15:44:54 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.86 2015/12/21 19:54:35 christos Exp $ */
+/* $NetBSD: thunk.c,v 1.87 2015/12/21 20:44:54 christos Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.86 2015/12/21 19:54:35 christos Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.87 2015/12/21 20:44:54 christos Exp $");
 #endif
 
 #include 
@@ -768,10 +768,10 @@ thunk_getcpuinfo(char *cp, size_t *len)
 	if (rlen == -1)
 		goto out;
 
-	buf[rlen ? rlen - 1 : 0] = '\0';
+	cp[rlen ? rlen - 1 : 0] = '\0';
 	*len = rlen;
 	return 0;
-bad:
+out:
 	*len = 0;
 	return -1;
 }



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

2015-12-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 21 20:44:54 UTC 2015

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

Log Message:
fix label and variable name.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 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.



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

2013-11-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov 10 19:51:00 UTC 2013

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

Log Message:
define _KMEMUSER before including machine/vmparam.h


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 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.83 src/sys/arch/usermode/usermode/thunk.c:1.84
--- src/sys/arch/usermode/usermode/thunk.c:1.83	Wed May 22 13:34:31 2013
+++ src/sys/arch/usermode/usermode/thunk.c	Sun Nov 10 19:51:00 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.83 2013/05/22 13:34:31 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.84 2013/11/10 19:51:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill jmcne...@invisible.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifdef __NetBSD__
-__RCSID($NetBSD: thunk.c,v 1.83 2013/05/22 13:34:31 reinoud Exp $);
+__RCSID($NetBSD: thunk.c,v 1.84 2013/11/10 19:51:00 jmcneill Exp $);
 #endif
 
 #include sys/types.h
@@ -41,6 +41,8 @@ __RCSID($NetBSD: thunk.c,v 1.83 2013/05
 #include sys/audioio.h
 #include sys/shm.h
 #include sys/ioctl.h
+
+#define _KMEMUSER
 #include machine/vmparam.h
 
 #include net/if.h



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

2013-11-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov 10 19:51:00 UTC 2013

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

Log Message:
define _KMEMUSER before including machine/vmparam.h


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 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.



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

2013-06-26 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Wed Jun 26 15:11:30 UTC 2013

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

Log Message:
Use sy_invoke


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/usermode/usermode/syscall.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/syscall.c
diff -u src/sys/arch/usermode/usermode/syscall.c:1.23 src/sys/arch/usermode/usermode/syscall.c:1.24
--- src/sys/arch/usermode/usermode/syscall.c:1.23	Mon Feb 13 19:15:59 2012
+++ src/sys/arch/usermode/usermode/syscall.c	Wed Jun 26 15:11:30 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: syscall.c,v 1.23 2012/02/13 19:15:59 reinoud Exp $ */
+/* $NetBSD: syscall.c,v 1.24 2013/06/26 15:11:30 matt Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill jmcne...@invisible.ca
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: syscall.c,v 1.23 2012/02/13 19:15:59 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: syscall.c,v 1.24 2013/06/26 15:11:30 matt Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -131,16 +131,7 @@ syscall(void)
 	md_syscall_inc_pc(ucp, opcode);
 
 	if (!error) {
-		if (!__predict_false(p-p_trace_enabled)
-		|| __predict_false(callp-sy_flags  SYCALL_INDIRECT)
-		|| (error = trace_enter(code, args, callp-sy_narg)) == 0) {
-			error = (*callp-sy_call)(l, args, rval);
-		}
-
-		if (__predict_false(p-p_trace_enabled)
-		 !__predict_false(callp-sy_flags  SYCALL_INDIRECT)) {
-			trace_exit(code, rval, error);
-		}
+		error = sy_invoke(callp, l, args, rval, code);
 	}
 
 	syscall_retvals_print(l, curlwp, code, nargs, args, error, rval);



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

2013-06-26 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Wed Jun 26 15:11:30 UTC 2013

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

Log Message:
Use sy_invoke


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/usermode/usermode/syscall.c

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



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

2013-05-22 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed May 22 13:34:32 UTC 2013

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

Log Message:
Including missing include file sys/ioctl.h that broke compilation.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 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.82 src/sys/arch/usermode/usermode/thunk.c:1.83
--- src/sys/arch/usermode/usermode/thunk.c:1.82	Mon Jul  2 12:17:12 2012
+++ src/sys/arch/usermode/usermode/thunk.c	Wed May 22 13:34:31 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.82 2012/07/02 12:17:12 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.83 2013/05/22 13:34:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill jmcne...@invisible.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifdef __NetBSD__
-__RCSID($NetBSD: thunk.c,v 1.82 2012/07/02 12:17:12 reinoud Exp $);
+__RCSID($NetBSD: thunk.c,v 1.83 2013/05/22 13:34:31 reinoud Exp $);
 #endif
 
 #include sys/types.h
@@ -40,6 +40,7 @@ __RCSID($NetBSD: thunk.c,v 1.82 2012/07
 #include sys/socket.h
 #include sys/audioio.h
 #include sys/shm.h
+#include sys/ioctl.h
 #include machine/vmparam.h
 
 #include net/if.h



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

2013-05-22 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed May 22 13:34:32 UTC 2013

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

Log Message:
Including missing include file sys/ioctl.h that broke compilation.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 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.



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

2012-08-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Aug  4 14:53:32 UTC 2012

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

Log Message:
Fix IO lockups in NetBSD/usermode.

1) Don't block IO signals since the return path is not garanteed to enable the
signal again.
2) Since signals can get dropped, do a 2nd pass over the routines.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.65 src/sys/arch/usermode/usermode/trap.c:1.66
--- src/sys/arch/usermode/usermode/trap.c:1.65	Sat Mar  3 21:29:02 2012
+++ src/sys/arch/usermode/usermode/trap.c	Sat Aug  4 14:53:32 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.65 2012/03/03 21:29:02 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.66 2012/08/04 14:53:32 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.65 2012/03/03 21:29:02 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.66 2012/08/04 14:53:32 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -364,10 +364,6 @@ handle_signal(int sig, siginfo_t *info, 
 	thunk_sigemptyset(jump_ucp.uc_sigmask);
 	jump_ucp.uc_flags = _UC_STACK | _UC_CPU | _UC_SIGMASK;
 
-	/* prevent recursive IO signals */
-	if (sig == SIGIO)
-		thunk_sigaddset(jump_ucp.uc_sigmask, SIGIO);
-
 	thunk_makecontext(jump_ucp,
 			(void (*)(void)) f,
 		4, info, (void *) from_userland, (void *) pc, (void *) va);
@@ -612,13 +608,15 @@ sigio(siginfo_t *info, vaddr_t from_user
 	struct lwp *l = curlwp;
 	struct pcb *pcb = lwp_getpcb(l); KASSERT(pcb);
 	struct intr_handler *sih;
-	unsigned int n;
+	unsigned int n, pass;
 
 //	thunk_printf(%s: l %p, pcb %p\n, __func__, l, pcb);
-	for (n = 0; n  SIGIO_MAX_HANDLERS; n++) {
-		sih = sigio_intr_handler[n];
-		if (sih-func)
-			sih-func(sih-arg);
+	for (pass = 0; pass  2; pass++) {
+		for (n = 0; n  SIGIO_MAX_HANDLERS; n++) {
+			sih = sigio_intr_handler[n];
+			if (sih-func)
+sih-func(sih-arg);
+		}
 	}
 
 	KASSERT(l == curlwp);



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

2012-08-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Aug  4 14:53:32 UTC 2012

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

Log Message:
Fix IO lockups in NetBSD/usermode.

1) Don't block IO signals since the return path is not garanteed to enable the
signal again.
2) Since signals can get dropped, do a 2nd pass over the routines.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.



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

2012-07-24 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jul 24 13:59:26 UTC 2012

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

Log Message:
Adding an assert that checks for struct pmap_l2 not being bigger than
PAGE_SIZE.

While here, also add possible bug allerts of temporary mmaps that might screw
up memory.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 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.103 src/sys/arch/usermode/usermode/pmap.c:1.104
--- src/sys/arch/usermode/usermode/pmap.c:1.103	Fri Mar  2 16:56:32 2012
+++ src/sys/arch/usermode/usermode/pmap.c	Tue Jul 24 13:59:26 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.103 2012/03/02 16:56:32 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.104 2012/07/24 13:59:26 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.103 2012/03/02 16:56:32 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.104 2012/07/24 13:59:26 reinoud Exp $);
 
 #include opt_memsize.h
 #include opt_kmempages.h
@@ -204,6 +204,9 @@ pmap_bootstrap(void)
 	if (TRAPSTACKSIZE  4*PAGE_SIZE) {
 		panic(TRAPSTACKSIZE is too small, please increase UPAGES);
 	}
+	if (sizeof(struct pmap_l2)  PAGE_SIZE) {
+		panic(struct pmap_l2 bigger than one page?\n);
+	}
 
 	/* protect user memory UVM area (---) */
 	err = thunk_munmap((void *) kmem_user_start,
@@ -1202,6 +1205,7 @@ 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,
@@ -1227,6 +1231,7 @@ 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,
 		THUNK_PROT_READ,
 		THUNK_MAP_FILE | THUNK_MAP_SHARED,
@@ -1234,6 +1239,7 @@ pmap_copy_page(paddr_t src_pa, paddr_t d
 	if (!sblob)
 		panic(%s: couldn't get src mapping, __func__);
 
+	/* XXX bug alart: can we allow the kernel to make a decision on this? */
 	dblob = thunk_mmap(NULL, PAGE_SIZE,
 		THUNK_PROT_READ | THUNK_PROT_WRITE,
 		THUNK_MAP_FILE | THUNK_MAP_SHARED,



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

2012-07-24 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jul 24 13:59:26 UTC 2012

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

Log Message:
Adding an assert that checks for struct pmap_l2 not being bigger than
PAGE_SIZE.

While here, also add possible bug allerts of temporary mmaps that might screw
up memory.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 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.



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

2012-07-02 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jul  2 12:17:12 UTC 2012

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

Log Message:
Fix missing stdarg.h include that breaks the autobuild


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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.81 src/sys/arch/usermode/usermode/thunk.c:1.82
--- src/sys/arch/usermode/usermode/thunk.c:1.81	Sat Mar  3 21:15:16 2012
+++ src/sys/arch/usermode/usermode/thunk.c	Mon Jul  2 12:17:12 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.81 2012/03/03 21:15:16 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.82 2012/07/02 12:17:12 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill jmcne...@invisible.ca
@@ -28,11 +28,12 @@
 
 #include sys/cdefs.h
 #ifdef __NetBSD__
-__RCSID($NetBSD: thunk.c,v 1.81 2012/03/03 21:15:16 reinoud Exp $);
+__RCSID($NetBSD: thunk.c,v 1.82 2012/07/02 12:17:12 reinoud Exp $);
 #endif
 
 #include sys/types.h
 #include sys/mman.h
+#include stdarg.h
 #include sys/reboot.h
 #include sys/poll.h
 #include sys/sysctl.h



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

2012-07-02 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jul  2 12:17:12 UTC 2012

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

Log Message:
Fix missing stdarg.h include that breaks the autobuild


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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.



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

2012-03-03 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Mar  3 21:29:02 UTC 2012

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

Log Message:
Use the signal's signo instead of just returning SIGSEGV and add a comment


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 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.64 src/sys/arch/usermode/usermode/trap.c:1.65
--- src/sys/arch/usermode/usermode/trap.c:1.64	Sat Mar  3 21:15:16 2012
+++ src/sys/arch/usermode/usermode/trap.c	Sat Mar  3 21:29:02 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.64 2012/03/03 21:15:16 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.65 2012/03/03 21:29:02 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.64 2012/03/03 21:15:16 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.65 2012/03/03 21:29:02 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -480,7 +480,7 @@ pagefault(siginfo_t *info, vaddr_t from_
 
 	KASSERT(from_userland);
 	KSI_INIT_TRAP(ksi);
-	ksi.ksi_signo = SIGSEGV;
+	ksi.ksi_signo = info-si_signo;
 	ksi.ksi_trap = 0;	/* XXX */
 	ksi.ksi_code = (error == EPERM) ? SEGV_ACCERR : SEGV_MAPERR;
 	ksi.ksi_addr = (void *) va;
@@ -552,6 +552,11 @@ illegal_instruction(siginfo_t *info, vad
 }
 
 
+/*
+ * handle pass to userland signals
+ *
+ * arguments other than the origional siginfo_t are not used
+ */
 static void
 pass_on(siginfo_t *info, vaddr_t from_userland, vaddr_t pc, vaddr_t va)
 {



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

2012-03-03 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Mar  3 21:29:02 UTC 2012

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

Log Message:
Use the signal's signo instead of just returning SIGSEGV and add a comment


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 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.



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

2012-03-02 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Mar  2 16:56:33 UTC 2012

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

Log Message:
Move from pool(9) to kmem_zalloc(9) for L2 page tables. A pool with PAGE_SIZE
elements is accepted but seems to panic now and then claiming it can't find
the header info.

XXX should this be PR'd?


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 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.102 src/sys/arch/usermode/usermode/pmap.c:1.103
--- src/sys/arch/usermode/usermode/pmap.c:1.102	Sat Jan 14 17:42:52 2012
+++ src/sys/arch/usermode/usermode/pmap.c	Fri Mar  2 16:56:32 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.102 2012/01/14 17:42:52 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.103 2012/03/02 16:56:32 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.102 2012/01/14 17:42:52 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.103 2012/03/02 16:56:32 reinoud Exp $);
 
 #include opt_memsize.h
 #include opt_kmempages.h
@@ -37,6 +37,7 @@ __KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.1
 #include sys/param.h
 #include sys/mutex.h
 #include sys/buf.h
+#include sys/kmem.h
 #include sys/malloc.h
 #include sys/pool.h
 #include machine/thunk.h
@@ -95,7 +96,6 @@ static uint64_t pm_entries_size = 0;
 
 static struct pool pmap_pool;
 static struct pool pmap_l1_pool;
-static struct pool pmap_l2_pool;
 static struct pool pmap_pventry_pool;
 
 /* forwards */
@@ -451,8 +451,6 @@ pmap_deferred_init(void)
 	/* create pmap pool */
 	pool_init(pmap_pool, sizeof(struct pmap), 0, 0, 0,
 	pmappool, NULL, IPL_NONE);
-	pool_init(pmap_l2_pool, PMAP_L2_SIZE, 0, 0, 0,
-	pmapl2pool, NULL, IPL_HIGH);
 	pool_init(pmap_l1_pool, pm_l1_size, 0, 0, 0,
 	pmapl1pool, NULL, IPL_NONE);
 	pool_init(pmap_pventry_pool, sizeof(struct pv_entry), 0, 0, 0,
@@ -529,7 +527,7 @@ pmap_destroy(pmap_t pmap)
 		l2tbl = pmap-pm_l1[l1];
 		if (!l2tbl)
 			continue;
-		pool_put(pmap_l2_pool, l2tbl);
+		kmem_free(l2tbl, PMAP_L2_SIZE);
 	}
 	pool_put(pmap_l1_pool, pmap-pm_l1);
 	pool_put(pmap_pool, pmap);
@@ -623,8 +621,8 @@ pmap_set_pv(pmap_t pmap, uintptr_t lpn, 
 
 	l2tbl = pmap-pm_l1[l1];
 	if (!l2tbl) {
-		l2tbl = pmap-pm_l1[l1] = pool_get(pmap_l2_pool, PR_WAITOK);
-		memset(l2tbl, 0, PMAP_L2_SIZE);
+		l2tbl = pmap-pm_l1[l1] = kmem_zalloc(PMAP_L2_SIZE, KM_SLEEP);
+		/* should be zero filled */
 	}
 	l2tbl-pm_l2[l2] = pv;
 }



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

2012-03-02 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Mar  2 16:56:33 UTC 2012

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

Log Message:
Move from pool(9) to kmem_zalloc(9) for L2 page tables. A pool with PAGE_SIZE
elements is accepted but seems to panic now and then claiming it can't find
the header info.

XXX should this be PR'd?


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 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.



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

2012-02-15 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Feb 15 15:20:53 UTC 2012

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

Log Message:
Prevent recursive IO signals. This prevents crashes when pieces of text are
pasted in say an Xterm. Each char might create a SIGIO running out of
stackspace very quickly!


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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.62 src/sys/arch/usermode/usermode/trap.c:1.63
--- src/sys/arch/usermode/usermode/trap.c:1.62	Sun Jan 22 17:51:39 2012
+++ src/sys/arch/usermode/usermode/trap.c	Wed Feb 15 15:20:53 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.62 2012/01/22 17:51:39 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.63 2012/02/15 15:20:53 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.62 2012/01/22 17:51:39 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.63 2012/02/15 15:20:53 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -362,6 +362,11 @@ handle_signal(int sig, siginfo_t *info, 
 
 	thunk_sigemptyset(jump_ucp.uc_sigmask);
 	jump_ucp.uc_flags = _UC_STACK | _UC_CPU | _UC_SIGMASK;
+
+	/* prevent recursive IO signals */
+	if (sig == SIGIO)
+		thunk_sigaddset(jump_ucp.uc_sigmask, SIGIO);
+
 	thunk_makecontext(jump_ucp,
 			(void (*)(void)) f,
 		3, (void *) from_userland, (void *) pc, (void *) va);



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

2012-02-15 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Feb 15 15:20:53 UTC 2012

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

Log Message:
Prevent recursive IO signals. This prevents crashes when pieces of text are
pasted in say an Xterm. Each char might create a SIGIO running out of
stackspace very quickly!


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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.



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

2012-02-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Feb 13 19:15:59 UTC 2012

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

Log Message:
Add cpu_spawn_return() as per other archs to make it compile. No tests done
yet.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/usermode/usermode/syscall.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/syscall.c
diff -u src/sys/arch/usermode/usermode/syscall.c:1.22 src/sys/arch/usermode/usermode/syscall.c:1.23
--- src/sys/arch/usermode/usermode/syscall.c:1.22	Sat Jan 14 21:45:28 2012
+++ src/sys/arch/usermode/usermode/syscall.c	Mon Feb 13 19:15:59 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: syscall.c,v 1.22 2012/01/14 21:45:28 reinoud Exp $ */
+/* $NetBSD: syscall.c,v 1.23 2012/02/13 19:15:59 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill jmcne...@invisible.ca
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: syscall.c,v 1.22 2012/01/14 21:45:28 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: syscall.c,v 1.23 2012/02/13 19:15:59 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -63,6 +63,16 @@ child_return(void *arg)
 	ktrsysret(SYS_fork, 0, 0);
 }
 
+/*
+ * Process the tail end of a posix_spawn() for the child.
+ */
+void
+cpu_spawn_return(struct lwp *l)
+{
+
+	userret(l);
+}
+
 extern const char *const syscallnames[];
 
 static void syscall_args_print(lwp_t *l, int code, int nargs, int argsize,



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

2012-02-13 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Feb 13 19:15:59 UTC 2012

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

Log Message:
Add cpu_spawn_return() as per other archs to make it compile. No tests done
yet.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/usermode/usermode/syscall.c

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



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

2012-01-22 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Jan 22 17:51:39 UTC 2012

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

Log Message:
Fix compilation issue for target amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 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.61 src/sys/arch/usermode/usermode/trap.c:1.62
--- src/sys/arch/usermode/usermode/trap.c:1.61	Sat Jan 21 22:09:57 2012
+++ src/sys/arch/usermode/usermode/trap.c	Sun Jan 22 17:51:39 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.61 2012/01/21 22:09:57 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.62 2012/01/22 17:51:39 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.61 2012/01/21 22:09:57 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.62 2012/01/22 17:51:39 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -305,7 +305,7 @@ handle_signal(int sig, siginfo_t *info, 
 	struct lwp *l;
 	struct pcb *pcb;
 	vaddr_t va, sp, pc, fp;
-	int from_userland;
+	long from_userland;
 
 	if (sig == SIGBUS || sig == SIGSEGV || sig == SIGILL) {
 		if (info-si_code == SI_NOINFO)



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

2012-01-22 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sun Jan 22 17:51:39 UTC 2012

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

Log Message:
Fix compilation issue for target amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 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.



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

2012-01-18 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan 18 12:39:45 UTC 2012

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

Log Message:
Another step towards unification of the signal handers: separate the printing
of details usefull for debugging / porting from the main code.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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.59 src/sys/arch/usermode/usermode/trap.c:1.60
--- src/sys/arch/usermode/usermode/trap.c:1.59	Tue Jan 17 20:50:38 2012
+++ src/sys/arch/usermode/usermode/trap.c	Wed Jan 18 12:39:45 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.59 2012/01/17 20:50:38 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.60 2012/01/18 12:39:45 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.59 2012/01/17 20:50:38 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.60 2012/01/18 12:39:45 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -146,22 +146,15 @@ userret(struct lwp *l)
 }
 
 
-/* signal handler switching to a pagefault context */
+#ifdef DEBUG
+/*
+ * Uncomment the following if you want to receive information about what
+ * triggered the fault. Mainly for debugging and porting purposes
+ */
 static void
-mem_access_handler(int sig, siginfo_t *info, void *ctx)
+print_mem_access_siginfo(int sig, siginfo_t *info, void *ctx,
+	vaddr_t pc, vaddr_t va, vaddr_t sp)
 {
-	ucontext_t *ucp = ctx;
-	struct lwp *l;
-	struct pcb *pcb;
-	vaddr_t va, sp, pc, fp;
-	int from_userland;
-
-	assert((info-si_signo == SIGSEGV) || (info-si_signo == SIGBUS));
-
-	if (info-si_code == SI_NOINFO)
-		panic(received signal %d with no info,
-		info-si_signo);
-
 #if 0
 	thunk_printf_debug(SIGSEGV or SIGBUS!\n);
 	thunk_printf_debug(\tsi_signo = %d\n, info-si_signo);
@@ -181,6 +174,75 @@ mem_access_handler(int sig, siginfo_t *i
 	thunk_printf_debug(\tsi_trap = %d\n, info-si_trap);
 #endif
 
+#if 0
+	printf(memaccess error, pc %p, va %p, 
+		sys_stack %p, sp %p, stack top %p\n,
+		(void *) pc, (void *) va,
+		(void *) pcb-sys_stack, (void *) sp,
+		(void *) pcb-sys_stack_top);
+#endif
+}
+
+/*
+ * Uncomment the following if you want to receive information about what
+ * triggered the fault. Mainly for debugging and porting purposes
+ */
+static void
+print_illegal_instruction_siginfo(int sig, siginfo_t *info, void *ctx,
+	vaddr_t pc, vaddr_t va, vaddr_t sp)
+{
+#if 0
+	thunk_printf(SIGILL!\n);
+	thunk_printf(\tsi_signo = %d\n, info-si_signo);
+	thunk_printf(\tsi_errno = %d\n, info-si_errno);
+	thunk_printf(\tsi_code  = %d\n, info-si_code);
+	if (info-si_code == ILL_ILLOPC)
+		thunk_printf(\t\tIllegal opcode);
+	if (info-si_code == ILL_ILLOPN)
+		thunk_printf(\t\tIllegal operand);
+	if (info-si_code == ILL_ILLADR)
+		thunk_printf(\t\tIllegal addressing mode);
+	if (info-si_code == ILL_ILLTRP)
+		thunk_printf(\t\tIllegal trap);
+	if (info-si_code == ILL_PRVOPC)
+		thunk_printf(\t\tPrivileged opcode);
+	if (info-si_code == ILL_PRVREG)
+		thunk_printf(\t\tPrivileged register);
+	if (info-si_code == ILL_COPROC)
+		thunk_printf(\t\tCoprocessor error);
+	if (info-si_code == ILL_BADSTK)
+		thunk_printf(\t\tInternal stack error);
+	thunk_printf(\tsi_addr = %p\n, info-si_addr);
+	thunk_printf(\tsi_trap = %d\n, info-si_trap);
+
+	thunk_printf(%p : , info-si_addr);
+	for (int i = 0; i  10; i++)
+		thunk_printf(%02x , *((uint8_t *) info-si_addr + i));
+	thunk_printf(\n);
+#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)
+#endif /* DEBUG */
+
+
+/* signal handler switching to a pagefault context */
+static void
+mem_access_handler(int sig, siginfo_t *info, void *ctx)
+{
+	ucontext_t *ucp = ctx;
+	struct lwp *l;
+	struct pcb *pcb;
+	vaddr_t va, sp, pc, fp;
+	int from_userland;
+
+	assert((info-si_signo == SIGSEGV) || (info-si_signo == SIGBUS));
+
+	if (info-si_code == SI_NOINFO)
+		panic(received signal %d with no info,
+		info-si_signo);
+
 	l = curlwp;
 	pcb = lwp_getpcb(l);
 
@@ -194,13 +256,7 @@ mem_access_handler(int sig, siginfo_t *i
 	/* setup for pagefault context */
 	sp = md_get_sp(ctx);
 
-#if 0
-	printf(memaccess error, pc %p, va %p, 
-		sys_stack %p, sp %p, stack top %p\n,
-		(void *) pc, (void *) va,
-		(void *) pcb-sys_stack, (void *) sp,
-		(void *) pcb-sys_stack_top);
-#endif
+	print_mem_access_siginfo(sig, info, ctx, pc, va, sp);
 
 	/* if we're running on a stack of our own, use the system stack */
 	from_userland = 0;
@@ -246,35 +302,6 @@ illegal_instruction_handler(int sig, sig
 	int from_userland;
 
 	assert(info-si_signo == SIGILL);
-#if 0
-	thunk_printf(SIGILL!\n);
-	thunk_printf(\tsi_signo = 

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

2012-01-17 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jan 17 19:46:55 UTC 2012

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

Log Message:
Clean up userret/ast handling. Now called ONLY when its 100% clear that it is
returning to userland.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 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.57 src/sys/arch/usermode/usermode/trap.c:1.58
--- src/sys/arch/usermode/usermode/trap.c:1.57	Sat Jan 14 21:45:28 2012
+++ src/sys/arch/usermode/usermode/trap.c	Tue Jan 17 19:46:55 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.57 2012/01/14 21:45:28 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.58 2012/01/17 19:46:55 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.57 2012/01/14 21:45:28 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.58 2012/01/17 19:46:55 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -50,14 +50,13 @@ __KERNEL_RCSID(0, $NetBSD: trap.c,v 1.5
 /* forwards and externals */
 void setup_signal_handlers(void);
 void stop_all_signal_handlers(void);
-void userret(struct lwp *l);
 
 static void mem_access_handler(int sig, siginfo_t *info, void *ctx);
 static void illegal_instruction_handler(int sig, siginfo_t *info, void *ctx);
 extern int errno;
 
-static void pagefault(vaddr_t pc, vaddr_t va);
-static void illegal_instruction(void);
+static void pagefault(vaddr_t from_userland, vaddr_t pc, vaddr_t va);
+static void illegal_instruction(vaddr_t from_userland);
 
 bool pmap_fault(pmap_t pmap, vaddr_t va, vm_prot_t *atype);
 
@@ -120,6 +119,33 @@ stop_all_signal_handlers(void)
 }
 
 
+/* ast and userret */
+void
+userret(struct lwp *l)
+{
+	/* invoke MI userret code */
+	mi_userret(l);
+
+	while (astpending) {
+		astpending = 0;
+
+		curcpu()-ci_data.cpu_ntrap++;
+#if 0
+		/* profiling */
+		if (l-l_pflag  LP_OWEUPC) {
+			l-l_pflag = ~LP_OWEUPC;
+			ADDUPROF(l);
+		}
+#endif
+		/* allow a forced task switch */
+		if (l-l_cpu-ci_want_resched)
+			preempt();
+
+		mi_userret(l);
+	}
+}
+
+
 /* signal handler switching to a pagefault context */
 static void
 mem_access_handler(int sig, siginfo_t *info, void *ctx)
@@ -128,6 +154,7 @@ mem_access_handler(int sig, siginfo_t *i
 	struct lwp *l;
 	struct pcb *pcb;
 	vaddr_t va, sp, pc, fp;
+	int from_userland;
 
 	assert((info-si_signo == SIGSEGV) || (info-si_signo == SIGBUS));
 
@@ -176,9 +203,12 @@ mem_access_handler(int sig, siginfo_t *i
 #endif
 
 	/* if we're running on a stack of our own, use the system stack */
+	from_userland = 0;
 	if ((sp  (vaddr_t) pcb-sys_stack) || (sp  (vaddr_t) pcb-sys_stack_top)) {
 		sp = (vaddr_t) pcb-sys_stack_top - sizeof(register_t);
 		fp = (vaddr_t) pcb-pcb_userret_ucp;
+		if (pc  kmem_user_end)
+			from_userland = 1;
 	} else {
 		/* stack grows down */
 		fp = sp - sizeof(ucontext_t) - sizeof(register_t); /* slack */
@@ -198,56 +228,13 @@ mem_access_handler(int sig, siginfo_t *i
 
 	pcb-pcb_ucp.uc_flags = _UC_STACK | _UC_CPU;
 	thunk_makecontext(pcb-pcb_ucp, (void (*)(void)) pagefault,
-		2, (void *) pc, (void *) va, NULL);
+		3, (void *) from_userland, (void *) pc, (void *) va);
 
 	/* switch to the new pagefault entry on return from signal */
 	memcpy(ctx, pcb-pcb_ucp, sizeof(ucontext_t));
 }
 
 
-/* ast and userret */
-void
-userret(struct lwp *l)
-{
-	struct pcb *pcb;
-	ucontext_t ucp, *nucp;
-	vaddr_t pc;
-	
-	KASSERT(l);
-
-	/* are we going back to userland? */
-	pcb = lwp_getpcb(l);
-	KASSERT(pcb);
-
-	/* where are we going back to ? */
-	thunk_getcontext(ucp);
-	nucp = (ucontext_t *) ucp.uc_link;
-	pc = md_get_pc(nucp);
-
-	if (pc = kmem_k_start)
-		return;
-
-	/* ok, going to userland, proceed! */
-	if (astpending) {
-		astpending = 0;
-
-		curcpu()-ci_data.cpu_ntrap++;
-#if 0
-		/* profiling */
-		if (l-l_pflag  LP_OWEUPC) {
-			l-l_pflag = ~LP_OWEUPC;
-			ADDUPROF(l);
-		}
-#endif
-		/* allow a forced task switch */
-		if (l-l_cpu-ci_want_resched)
-			preempt();
-	}
-
-	/* invoke MI userret code */
-	mi_userret(l);
-}
-
 /* signal handler switching to a illegal instruction context */
 static void
 illegal_instruction_handler(int sig, siginfo_t *info, void *ctx)
@@ -255,7 +242,8 @@ illegal_instruction_handler(int sig, sig
 	ucontext_t *ucp = ctx;
 	struct lwp *l;
 	struct pcb *pcb;
-	vaddr_t sp, fp;
+	vaddr_t sp, pc, fp;
+	int from_userland;
 
 	assert(info-si_signo == SIGILL);
 #if 0
@@ -291,14 +279,21 @@ illegal_instruction_handler(int sig, sig
 	l = curlwp;
 	pcb = lwp_getpcb(l);
 
+	/* get PC address of faulted instruction */
+	pc = md_get_pc(ctx);
+
 	/* setup for illegal_instruction context */
 	sp = md_get_sp(ctx);
 
 	/* if we're running on a stack of our own, use the system stack 

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

2012-01-17 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jan 17 20:50:39 UTC 2012

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

Log Message:
Do init the astpending variable.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.58 src/sys/arch/usermode/usermode/trap.c:1.59
--- src/sys/arch/usermode/usermode/trap.c:1.58	Tue Jan 17 19:46:55 2012
+++ src/sys/arch/usermode/usermode/trap.c	Tue Jan 17 20:50:38 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.58 2012/01/17 19:46:55 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.59 2012/01/17 20:50:38 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.58 2012/01/17 19:46:55 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.59 2012/01/17 20:50:38 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -62,7 +62,7 @@ bool pmap_fault(pmap_t pmap, vaddr_t va,
 
 static stack_t sigstk;
 
-int astpending;
+int astpending = 0;
 
 void
 startlwp(void *arg)



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

2012-01-17 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jan 17 19:46:55 UTC 2012

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

Log Message:
Clean up userret/ast handling. Now called ONLY when its 100% clear that it is
returning to userland.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 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.



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

2012-01-17 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jan 17 20:50:39 UTC 2012

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

Log Message:
Do init the astpending variable.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.



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

2012-01-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jan 15 10:30:21 UTC 2012

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

Log Message:
don't modify command-line parameters


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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.51 src/sys/arch/usermode/usermode/machdep.c:1.52
--- src/sys/arch/usermode/usermode/machdep.c:1.51	Sun Jan 15 10:18:58 2012
+++ src/sys/arch/usermode/usermode/machdep.c	Sun Jan 15 10:30:21 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.51 2012/01/15 10:18:58 jmcneill Exp $ */
+/* $NetBSD: machdep.c,v 1.52 2012/01/15 10:30:21 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -37,7 +37,7 @@
 #include opt_memsize.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.51 2012/01/15 10:18:58 jmcneill Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.52 2012/01/15 10:30:21 jmcneill Exp $);
 
 #include sys/types.h
 #include sys/systm.h
@@ -128,21 +128,21 @@ main(int argc, char *argv[])
 			if (strncmp(argv[i], net=, strlen(net=)) == 0) {
 char *tap = argv[i] + strlen(net=);
 char *mac = strchr(tap, ',');
+char *p = usermode_tap_devicebuf;
 if (mac == NULL) {
 	printf(bad net= format\n);
 	return;
 }
-*mac++ = '\0';
-if (*tap != '/')
-	snprintf(usermode_tap_devicebuf,
-	sizeof(usermode_tap_devicebuf),
-	/dev/%s, tap);
-else
-	snprintf(usermode_tap_devicebuf,
-	sizeof(usermode_tap_devicebuf),
-	%s, tap);
+memset(usermode_tap_devicebuf, 0,
+sizeof(usermode_tap_devicebuf));
+if (*tap != '/') {
+	memcpy(p, /dev/, strlen(/dev/));
+	p += strlen(/dev/);
+}
+for (; *tap != ','; p++, tap++)
+	*p = *tap;
 usermode_tap_device = usermode_tap_devicebuf;
-usermode_tap_eaddr = mac;
+usermode_tap_eaddr = mac + 1;
 			} else if (strncmp(argv[i], audio=,
 			strlen(audio=)) == 0) {
 char *audio = argv[i] + strlen(audio=);



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

2012-01-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jan 15 10:35:08 UTC 2012

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

Log Message:
if syscallemu returns -1 and sets errno = EACCES, it means it's already
enabled for this pid. don't treat this as a failure.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 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.78 src/sys/arch/usermode/usermode/thunk.c:1.79
--- src/sys/arch/usermode/usermode/thunk.c:1.78	Sat Jan 14 17:42:52 2012
+++ src/sys/arch/usermode/usermode/thunk.c	Sun Jan 15 10:35:08 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.78 2012/01/14 17:42:52 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.79 2012/01/15 10:35:08 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill jmcne...@invisible.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifdef __NetBSD__
-__RCSID($NetBSD: thunk.c,v 1.78 2012/01/14 17:42:52 reinoud Exp $);
+__RCSID($NetBSD: thunk.c,v 1.79 2012/01/15 10:35:08 jmcneill Exp $);
 #endif
 
 #include sys/types.h
@@ -113,10 +113,12 @@ thunk_syscallemu_init(void *ustart, void
 {
 	int error;
 
-	fprintf(stdout, %s: syscall(%d, %p, %p)\n, __func__,
-	SYS_syscallemu, ustart, uend);
+	errno = 0;
 	error = syscall(SYS_syscallemu, (uintptr_t)ustart, (uintptr_t)uend);
-	fprintf(stdout, %s: returned %d\n, __func__, error);
+	if (error == -1  errno == EACCES) {
+		/* syscallemu already active for this pid */
+		error = 0;
+	}
 
 	return error;
 }



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

2012-01-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jan 15 10:30:21 UTC 2012

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

Log Message:
don't modify command-line parameters


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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.



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

2012-01-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jan 15 10:35:08 UTC 2012

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

Log Message:
if syscallemu returns -1 and sets errno = EACCES, it means it's already
enabled for this pid. don't treat this as a failure.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 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.



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

2012-01-11 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan 11 12:40:26 UTC 2012

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

Log Message:
Cleanup trap.c and add a stop_all_signal_handlers(void) i: bluntly stopping
all known usages of signal handlers, to be used in shutdown.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 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.54 src/sys/arch/usermode/usermode/trap.c:1.55
--- src/sys/arch/usermode/usermode/trap.c:1.54	Sat Jan  7 19:45:14 2012
+++ src/sys/arch/usermode/usermode/trap.c	Wed Jan 11 12:40:26 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.54 2012/01/07 19:45:14 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.55 2012/01/11 12:40:26 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.54 2012/01/07 19:45:14 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.55 2012/01/11 12:40:26 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -46,13 +46,10 @@ __KERNEL_RCSID(0, $NetBSD: trap.c,v 1.5
 #include machine/thunk.h
 
 
-//#include machine/ctlreg.h
-//#include machine/trap.h
-//#include machine/instr.h
-//#include machine/userret.h
-
 /* forwards and externals */
 void setup_signal_handlers(void);
+void stop_all_signal_handlers(void);
+
 static void mem_access_handler(int sig, siginfo_t *info, void *ctx);
 static void illegal_instruction_handler(int sig, siginfo_t *info, void *ctx);
 extern int errno;
@@ -61,11 +58,14 @@ bool pmap_fault(pmap_t pmap, vaddr_t va,
 
 static stack_t sigstk;
 
+
 void
 startlwp(void *arg)
 {
+	/* nothing here */
 }
 
+
 void
 setup_signal_handlers(void)
 {
@@ -102,6 +102,17 @@ setup_signal_handlers(void)
 }
 
 
+void
+stop_all_signal_handlers(void)
+{
+	thunk_sigblock(SIGALRM);
+	thunk_sigblock(SIGIO);
+	thunk_sigblock(SIGILL);
+	thunk_sigblock(SIGSEGV);
+	thunk_sigblock(SIGBUS);
+}
+
+
 static void
 mem_access_handler(int sig, siginfo_t *info, void *ctx)
 {
@@ -116,15 +127,6 @@ mem_access_handler(int sig, siginfo_t *i
 		panic(received signal %d with no info,
 		info-si_signo);
 
-//printf(sigsegv\n);
-#if 0
-	va = (vaddr_t) info-si_addr;
-	thunk_printf_debug(mem trap lwp = %p pid = %d lid = %d, va = %p\n,
-	curlwp,
-	curlwp-l_proc-p_pid,
-	curlwp-l_lid,
-	(void *) va);
-#endif
 #if 0
 	thunk_printf_debug(SIGSEGV or SIGBUS!\n);
 	thunk_printf_debug(\tsi_signo = %d\n, info-si_signo);
@@ -154,26 +156,15 @@ mem_access_handler(int sig, siginfo_t *i
 	/* get PC address of faulted memory instruction */
 	pc = md_get_pc(ctx);
 
-#if 0	/* disabled for now, these checks need to move */
-#ifdef DIAGNOSTIC
-	/* sanity */
-	if ((va  VM_MIN_ADDRESS) || (va = VM_MAX_KERNEL_ADDRESS))
-		panic(peeing outside the box! (va=%p), (void *)va);
-
-	/* extra debug for now - should issue signal */
-	if (va == 0)
-		panic(NULL deref\n);
-#endif
+#if 0
+	thunk_printf(memaccess error : pc = %p, va = %p\n,
+		(void *) pc, (void *) va);
 #endif
 
-//	thunk_printf(memaccess error : pc = %p, va = %p\n,
-//		(void *) pc, (void *) va);
-
 	/* copy this state to return to */
 	memcpy(pcb-pcb_trapret_ucp, uct, sizeof(ucontext_t));
 
 	/* remember our parameters */
-//	assert((void *) pcb-pcb_fault_addr == NULL);
 	pcb-pcb_fault_addr = va;
 	pcb-pcb_fault_pc   = pc;
 
@@ -191,21 +182,6 @@ illegal_instruction_handler(int sig, sig
 
 	assert(info-si_signo == SIGILL);
 #if 0
-	sigset_t ss;
-	thunk_sigemptyset(ss);
-	thunk_sigaddset(ss, SIGALRM);
-	thunk_sigaddset(ss, SIGILL);
-	thunk_sigprocmask(SIG_UNBLOCK, ss, NULL);
-#endif
-
-#if 0
-	printf(\nillegal instruction trap lwp = %p pid = %d lid = %d, va = %p\n,
-	curlwp,
-	curlwp-l_proc-p_pid,
-	curlwp-l_lid,
-	(void *) info-si_addr);
-#endif
-#if 0
 	thunk_printf(SIGILL!\n);
 	thunk_printf(\tsi_signo = %d\n, info-si_signo);
 	thunk_printf(\tsi_errno = %d\n, info-si_errno);
@@ -284,8 +260,10 @@ pagefault(void)
 	if (from_kernel  (va = VM_MIN_KERNEL_ADDRESS))
 		vm_map = kernel_map;
 
-//	thunk_printf_debug(pagefault : pc %p, va %p\n,
-//		(void *) pc, (void *) va);
+#if 0
+	thunk_printf_debug(pagefault : pc %p, va %p\n,
+		(void *) pc, (void *) va);
+#endif
 
 	/* can pmap handle it? on its own? (r/m) */
 	onfault = pcb-pcb_onfault;
@@ -312,6 +290,7 @@ pagefault(void)
 			if (!onfault)
 panic(kernel fault);
 			panic(%s: can't call onfault yet\n, __func__);
+			/* XXX implement me ? */
 			/* jump to given onfault */
 			// tf = kernel_tf;
 			// memset(tf, 0, sizeof(struct trapframe));



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

2012-01-11 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan 11 12:40:26 UTC 2012

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

Log Message:
Cleanup trap.c and add a stop_all_signal_handlers(void) i: bluntly stopping
all known usages of signal handlers, to be used in shutdown.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 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.



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

2012-01-10 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jan 10 12:07:18 UTC 2012

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

Log Message:
Use thunk_madvise() on the memory space hinting the kernel we are using it in
a random order and hint the kernel that we we need the memory.i

No measured effect on a memory file on tmpfs /tmp though.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 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.100 src/sys/arch/usermode/usermode/pmap.c:1.101
--- src/sys/arch/usermode/usermode/pmap.c:1.100	Tue Jan 10 10:09:49 2012
+++ src/sys/arch/usermode/usermode/pmap.c	Tue Jan 10 12:07:17 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.100 2012/01/10 10:09:49 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.101 2012/01/10 12:07:17 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.100 2012/01/10 10:09:49 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.101 2012/01/10 12:07:17 reinoud Exp $);
 
 #include opt_memsize.h
 #include opt_kmempages.h
@@ -255,6 +255,13 @@ pmap_bootstrap(void)
 		THUNK_PROT_READ | THUNK_PROT_EXEC);
 	assert(err == 0);
 
+	/* madvise the host kernel about our intentions with the memory */
+	/* no measured effect, but might make a difference on high load */
+	err = thunk_madvise((void *) kmem_user_start,
+		kmem_k_start - kmem_user_start,
+		THUNK_MADV_WILLNEED | THUNK_MADV_RANDOM);
+	assert(err == 0);
+
 	/* initialize counters */
 	fpos = 0;
 	free_start = fpos; /* in physical space ! */



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

2012-01-10 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jan 10 10:09:49 UTC 2012

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

Log Message:
Explicitly protect the kernel image against tampering by marking it R-X


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 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.99 src/sys/arch/usermode/usermode/pmap.c:1.100
--- src/sys/arch/usermode/usermode/pmap.c:1.99	Mon Jan  9 14:58:15 2012
+++ src/sys/arch/usermode/usermode/pmap.c	Tue Jan 10 10:09:49 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.99 2012/01/09 14:58:15 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.100 2012/01/10 10:09:49 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.99 2012/01/09 14:58:15 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.100 2012/01/10 10:09:49 reinoud Exp $);
 
 #include opt_memsize.h
 #include opt_kmempages.h
@@ -251,12 +251,9 @@ pmap_bootstrap(void)
 #endif
 
 	/* protect the current kernel section */
-#if 0
-	int err;
 	err = thunk_mprotect((void *) kmem_k_start, kmem_k_end - kmem_k_start,
 		THUNK_PROT_READ | THUNK_PROT_EXEC);
 	assert(err == 0);
-#endif
 
 	/* initialize counters */
 	fpos = 0;



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

2012-01-10 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jan 10 10:09:49 UTC 2012

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

Log Message:
Explicitly protect the kernel image against tampering by marking it R-X


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 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.



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

2012-01-10 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Jan 10 12:07:18 UTC 2012

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

Log Message:
Use thunk_madvise() on the memory space hinting the kernel we are using it in
a random order and hint the kernel that we we need the memory.i

No measured effect on a memory file on tmpfs /tmp though.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 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.



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

2012-01-09 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jan  9 14:58:15 UTC 2012

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

Log Message:
As ppn is a uintptr_t, it can never be negative so the check is invalid.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 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.98 src/sys/arch/usermode/usermode/pmap.c:1.99
--- src/sys/arch/usermode/usermode/pmap.c:1.98	Sat Jan  7 19:44:13 2012
+++ src/sys/arch/usermode/usermode/pmap.c	Mon Jan  9 14:58:15 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.98 2012/01/07 19:44:13 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.99 2012/01/09 14:58:15 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.98 2012/01/07 19:44:13 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.99 2012/01/09 14:58:15 reinoud Exp $);
 
 #include opt_memsize.h
 #include opt_kmempages.h
@@ -581,7 +581,6 @@ pv_get(pmap_t pmap, uintptr_t ppn, uintp
 
 	/* extra sanity */
 	assert(ppn  phys_npages);
-	assert(ppn = 0);
 
 	pv = pv_alloc();
 	if (pv == NULL)



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

2012-01-09 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jan  9 22:20:53 UTC 2012

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

Log Message:
If the spl list is full also notify on the ttycons since it might otherwise
not allways be possible to print the panic correctdue due to the spl level.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/usermode/usermode/intr.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/intr.c
diff -u src/sys/arch/usermode/usermode/intr.c:1.13 src/sys/arch/usermode/usermode/intr.c:1.14
--- src/sys/arch/usermode/usermode/intr.c:1.13	Sat Jan  7 18:07:57 2012
+++ src/sys/arch/usermode/usermode/intr.c	Mon Jan  9 22:20:53 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.c,v 1.13 2012/01/07 18:07:57 jmcneill Exp $ */
+/* $NetBSD: intr.c,v 1.14 2012/01/09 22:20:53 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill jmcne...@invisible.ca
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: intr.c,v 1.13 2012/01/07 18:07:57 jmcneill Exp $);
+__KERNEL_RCSID(0, $NetBSD: intr.c,v 1.14 2012/01/09 22:20:53 reinoud Exp $);
 
 #include sys/types.h
 
@@ -89,8 +89,10 @@ spl_intr(int x, void (*func)(void *), vo
 	spli-arg = arg;
 
 	spl_intr_wr[x] = (spl_intr_wr[x] + 1) % MAX_QUEUED_EVENTS;
-	if (spl_intr_wr[x] == spl_intr_rd[x])
+	if (spl_intr_wr[x] == spl_intr_rd[x]) {
+		thunk_printf(%s: spl list %d full!\n, __func__, x);
 		panic(%s: spl list %d full!\n, __func__, x);
+	}
 }
 
 int



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

2012-01-09 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jan  9 14:58:15 UTC 2012

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

Log Message:
As ppn is a uintptr_t, it can never be negative so the check is invalid.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 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.



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

2012-01-09 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Mon Jan  9 22:20:53 UTC 2012

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

Log Message:
If the spl list is full also notify on the ttycons since it might otherwise
not allways be possible to print the panic correctdue due to the spl level.


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

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



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

2012-01-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan  7 18:07:57 UTC 2012

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

Log Message:
increase the max # of sigio handlers


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/usermode/usermode/intr.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/intr.c
diff -u src/sys/arch/usermode/usermode/intr.c:1.12 src/sys/arch/usermode/usermode/intr.c:1.13
--- src/sys/arch/usermode/usermode/intr.c:1.12	Fri Dec 30 11:04:50 2011
+++ src/sys/arch/usermode/usermode/intr.c	Sat Jan  7 18:07:57 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.c,v 1.12 2011/12/30 11:04:50 jmcneill Exp $ */
+/* $NetBSD: intr.c,v 1.13 2012/01/07 18:07:57 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill jmcne...@invisible.ca
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: intr.c,v 1.12 2011/12/30 11:04:50 jmcneill Exp $);
+__KERNEL_RCSID(0, $NetBSD: intr.c,v 1.13 2012/01/07 18:07:57 jmcneill Exp $);
 
 #include sys/types.h
 
@@ -39,7 +39,7 @@ struct intr_handler {
 	void *arg;
 };
 
-#define SIGIO_MAX_HANDLERS	4
+#define SIGIO_MAX_HANDLERS	8
 
 static struct intr_handler sigio_intr_handler[SIGIO_MAX_HANDLERS];
 



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

2012-01-07 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan  7 19:44:13 UTC 2012

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

Log Message:
Change prototype of logical page number in pv_lookop and pv_enter and add
diagnostic checks to check for out-of-bounds.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 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.97 src/sys/arch/usermode/usermode/pmap.c:1.98
--- src/sys/arch/usermode/usermode/pmap.c:1.97	Thu Jan  5 12:12:58 2012
+++ src/sys/arch/usermode/usermode/pmap.c	Sat Jan  7 19:44:13 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.97 2012/01/05 12:12:58 jmcneill Exp $ */
+/* $NetBSD: pmap.c,v 1.98 2012/01/07 19:44:13 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.97 2012/01/05 12:12:58 jmcneill Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.98 2012/01/07 19:44:13 reinoud Exp $);
 
 #include opt_memsize.h
 #include opt_kmempages.h
@@ -595,13 +595,18 @@ pv_get(pmap_t pmap, uintptr_t ppn, uintp
 }
 
 static void
-pmap_set_pv(pmap_t pmap, uint lpn, struct pv_entry *pv)
+pmap_set_pv(pmap_t pmap, uintptr_t lpn, struct pv_entry *pv)
 {
 	struct pmap_l2 *l2tbl;
 	int l1 = lpn / PMAP_L2_NENTRY;
 	int l2 = lpn % PMAP_L2_NENTRY;
 
-if (lpn = pm_nentries) panic(peeing outside box\n);
+#ifdef DIAGNOSTIC
+	if (lpn = pm_nentries)
+		panic(peeing outside box : addr in page around %PRIx64\n,
+			(uint64_t) lpn*PAGE_SIZE);
+#endif
+
 	l2tbl = pmap-pm_l1[l1];
 	if (!l2tbl) {
 		l2tbl = pmap-pm_l1[l1] = pool_get(pmap_l2_pool, PR_WAITOK);
@@ -611,13 +616,18 @@ if (lpn = pm_nentries) panic(peeing ou
 }
 
 static struct pv_entry *
-pmap_lookup_pv(pmap_t pmap, uint lpn)
+pmap_lookup_pv(pmap_t pmap, uintptr_t lpn)
 {
 	struct pmap_l2 *l2tbl;
 	int l1 = lpn / PMAP_L2_NENTRY;
 	int l2 = lpn % PMAP_L2_NENTRY;
 
-if (lpn = pm_nentries) panic(peeing outside box\n);
+#ifdef DIAGNOSTIC
+	if (lpn = pm_nentries)
+		panic(peeing outside box : addr in page around %PRIx64\n,
+			(uint64_t) lpn*PAGE_SIZE);
+#endif
+
 	l2tbl = pmap-pm_l1[l1];
 	if (l2tbl)
 		return l2tbl-pm_l2[l2];



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

2012-01-07 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan  7 19:45:14 UTC 2012

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

Log Message:
Cleanup trap debug messages


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 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.53 src/sys/arch/usermode/usermode/trap.c:1.54
--- src/sys/arch/usermode/usermode/trap.c:1.53	Fri Jan  6 20:39:42 2012
+++ src/sys/arch/usermode/usermode/trap.c	Sat Jan  7 19:45:14 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.53 2012/01/06 20:39:42 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.54 2012/01/07 19:45:14 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.53 2012/01/06 20:39:42 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.54 2012/01/07 19:45:14 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -166,7 +166,9 @@ mem_access_handler(int sig, siginfo_t *i
 #endif
 #endif
 
-//printf(memaccess error : va = %p\n, (void *) va);
+//	thunk_printf(memaccess error : pc = %p, va = %p\n,
+//		(void *) pc, (void *) va);
+
 	/* copy this state to return to */
 	memcpy(pcb-pcb_trapret_ucp, uct, sizeof(ucontext_t));
 
@@ -282,7 +284,8 @@ pagefault(void)
 	if (from_kernel  (va = VM_MIN_KERNEL_ADDRESS))
 		vm_map = kernel_map;
 
-	thunk_printf_debug(pagefault : pc %p, va %p\n, (void *) pc, (void *) va);
+//	thunk_printf_debug(pagefault : pc %p, va %p\n,
+//		(void *) pc, (void *) va);
 
 	/* can pmap handle it? on its own? (r/m) */
 	onfault = pcb-pcb_onfault;



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

2012-01-07 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan  7 20:12:07 UTC 2012

Removed Files:
src/sys/arch/usermode/usermode: thunk_sdl.c

Log Message:
Remove unused thunk_sdl.c file


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

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



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

2012-01-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan  7 18:07:57 UTC 2012

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

Log Message:
increase the max # of sigio handlers


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/usermode/usermode/intr.c

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



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

2012-01-07 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan  7 19:44:13 UTC 2012

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

Log Message:
Change prototype of logical page number in pv_lookop and pv_enter and add
diagnostic checks to check for out-of-bounds.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 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.



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

2012-01-07 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan  7 19:45:14 UTC 2012

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

Log Message:
Cleanup trap debug messages


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 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.



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

2012-01-07 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Jan  7 20:12:07 UTC 2012

Removed Files:
src/sys/arch/usermode/usermode: thunk_sdl.c

Log Message:
Remove unused thunk_sdl.c file


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

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



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

2012-01-06 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Jan  6 20:39:42 UTC 2012

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

Log Message:
printf()-thunk_printf() since its for debugging and should be printed outside
the kernel's printing system.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 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.52 src/sys/arch/usermode/usermode/trap.c:1.53
--- src/sys/arch/usermode/usermode/trap.c:1.52	Tue Jan  3 21:28:50 2012
+++ src/sys/arch/usermode/usermode/trap.c	Fri Jan  6 20:39:42 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.52 2012/01/03 21:28:50 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.53 2012/01/06 20:39:42 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.52 2012/01/03 21:28:50 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.53 2012/01/06 20:39:42 reinoud Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -204,33 +204,33 @@ illegal_instruction_handler(int sig, sig
 	(void *) info-si_addr);
 #endif
 #if 0
-	printf(SIGILL!\n);
-	printf(\tsi_signo = %d\n, info-si_signo);
-	printf(\tsi_errno = %d\n, info-si_errno);
-	printf(\tsi_code  = %d\n, info-si_code);
+	thunk_printf(SIGILL!\n);
+	thunk_printf(\tsi_signo = %d\n, info-si_signo);
+	thunk_printf(\tsi_errno = %d\n, info-si_errno);
+	thunk_printf(\tsi_code  = %d\n, info-si_code);
 	if (info-si_code == ILL_ILLOPC)
-		printf(\t\tIllegal opcode);
+		thunk_printf(\t\tIllegal opcode);
 	if (info-si_code == ILL_ILLOPN)
-		printf(\t\tIllegal operand);
+		thunk_printf(\t\tIllegal operand);
 	if (info-si_code == ILL_ILLADR)
-		printf(\t\tIllegal addressing mode);
+		thunk_printf(\t\tIllegal addressing mode);
 	if (info-si_code == ILL_ILLTRP)
-		printf(\t\tIllegal trap);
+		thunk_printf(\t\tIllegal trap);
 	if (info-si_code == ILL_PRVOPC)
-		printf(\t\tPrivileged opcode);
+		thunk_printf(\t\tPrivileged opcode);
 	if (info-si_code == ILL_PRVREG)
-		printf(\t\tPrivileged register);
+		thunk_printf(\t\tPrivileged register);
 	if (info-si_code == ILL_COPROC)
-		printf(\t\tCoprocessor error);
+		thunk_printf(\t\tCoprocessor error);
 	if (info-si_code == ILL_BADSTK)
-		printf(\t\tInternal stack error);
-	printf(\tsi_addr = %p\n, info-si_addr);
-	printf(\tsi_trap = %d\n, info-si_trap);
+		thunk_printf(\t\tInternal stack error);
+	thunk_printf(\tsi_addr = %p\n, info-si_addr);
+	thunk_printf(\tsi_trap = %d\n, info-si_trap);
 
-	printf(%p : , info-si_addr);
+	thunk_printf(%p : , info-si_addr);
 	for (int i = 0; i  10; i++)
-		printf(%02x , *((uint8_t *) info-si_addr + i));
-	printf(\n);
+		thunk_printf(%02x , *((uint8_t *) info-si_addr + i));
+	thunk_printf(\n);
 #endif
 
 	l = curlwp;



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

2012-01-06 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Jan  6 20:39:42 UTC 2012

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

Log Message:
printf()-thunk_printf() since its for debugging and should be printed outside
the kernel's printing system.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 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.



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

2012-01-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan  4 11:53:09 UTC 2012

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

Log Message:
mmap ppl is always  16 so make it an uint8_t


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 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.92 src/sys/arch/usermode/usermode/pmap.c:1.93
--- src/sys/arch/usermode/usermode/pmap.c:1.92	Tue Jan  3 21:28:50 2012
+++ src/sys/arch/usermode/usermode/pmap.c	Wed Jan  4 11:53:09 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.92 2012/01/03 21:28:50 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.93 2012/01/04 11:53:09 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.92 2012/01/03 21:28:50 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.93 2012/01/04 11:53:09 reinoud Exp $);
 
 #include opt_memsize.h
 #include opt_kmempages.h
@@ -50,7 +50,7 @@ struct pv_entry {
 	uintptr_t	pv_ppn;		/* physical page number */
 	uintptr_t	pv_lpn;		/* logical page number  */
 	vm_prot_t	pv_prot;	/* logical protection */
-	int		pv_mmap_ppl;	/* programmed protection */
+	uint8_t		pv_mmap_ppl;	/* programmed protection */
 	uint8_t		pv_vflags;	/* per mapping flags */
 #define PV_WIRED	0x01		/* wired mapping */
 #define PV_UNMANAGED	0x02		/* entered by pmap_kenter_ */



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

2012-01-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan  4 11:56:58 UTC 2012

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

Log Message:
This uint shouldn't be there


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 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.93 src/sys/arch/usermode/usermode/pmap.c:1.94
--- src/sys/arch/usermode/usermode/pmap.c:1.93	Wed Jan  4 11:53:09 2012
+++ src/sys/arch/usermode/usermode/pmap.c	Wed Jan  4 11:56:58 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.93 2012/01/04 11:53:09 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.94 2012/01/04 11:56:58 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.93 2012/01/04 11:53:09 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.94 2012/01/04 11:56:58 reinoud Exp $);
 
 #include opt_memsize.h
 #include opt_kmempages.h
@@ -119,7 +119,7 @@ vaddr_t kmem_user_start, kmem_user_end;
 vaddr_t kmem_kvm_cur_start, kmem_kvm_cur_end;
 
 /* amount of physical memory */
-uint	physmem; 
+int	physmem; 
 int	num_pv_entries = 0;
 int	num_pmaps = 0;
 



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

2012-01-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Jan  4 15:10:45 UTC 2012

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

Log Message:
don't try to unmap pv entries with munmap() that are / were already unmapped


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 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.94 src/sys/arch/usermode/usermode/pmap.c:1.95
--- src/sys/arch/usermode/usermode/pmap.c:1.94	Wed Jan  4 11:56:58 2012
+++ src/sys/arch/usermode/usermode/pmap.c	Wed Jan  4 15:10:45 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.94 2012/01/04 11:56:58 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.95 2012/01/04 15:10:45 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk rein...@netbsd.org
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.94 2012/01/04 11:56:58 reinoud Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.95 2012/01/04 15:10:45 reinoud Exp $);
 
 #include opt_memsize.h
 #include opt_kmempages.h
@@ -758,6 +758,12 @@ pmap_page_deactivate(struct pv_entry *pv
 	uint32_t map_flags;
 	void *addr;
 
+	/* don't try to unmap pv entries that are already unmapped */
+	if (!tlb[pv-pv_lpn])
+		return;
+	if (tlb[pv-pv_lpn]-pv_mmap_ppl == THUNK_PROT_NONE)
+		return;
+
 	map_flags = THUNK_MAP_FILE | THUNK_MAP_FIXED | THUNK_MAP_SHARED;
 	addr = thunk_mmap((void *) va, PAGE_SIZE, THUNK_PROT_NONE,
 		map_flags, mem_fh, pa);



  1   2   3   4   5   >