Fix /dev/kmem access and make vmstat(1) `work'. Not sure all the results are indeed valid or correct but at least it shows them without coredumping or coredumping the kernel.diff -r1.9 -r1.10 src/sys/arch/usermode/include/cpu.h
(reinoud)
--- src/sys/arch/usermode/include/cpu.h 2012/01/19 12:14:49 1.9
+++ src/sys/arch/usermode/include/cpu.h 2012/02/08 17:55:21 1.10
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cpu.h,v 1.9 2012/01/19 12:14:49 reinoud Exp $ */ | 1 | /* $NetBSD: cpu.h,v 1.10 2012/02/08 17:55:21 reinoud Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -40,30 +40,30 @@ extern void userret(struct lwp *); | @@ -40,30 +40,30 @@ extern void userret(struct lwp *); | |||
40 | 40 | |||
41 | #define curcpu() usermode_curcpu() | 41 | #define curcpu() usermode_curcpu() | |
42 | #define cpu_number() 0 | 42 | #define cpu_number() 0 | |
43 | 43 | |||
44 | #define cpu_proc_fork(p1, p2) | 44 | #define cpu_proc_fork(p1, p2) | |
45 | 45 | |||
46 | struct cpu_info; | 46 | struct cpu_info; | |
47 | extern int astpending; | 47 | extern int astpending; | |
48 | #define aston(ci) (astpending++) | 48 | #define aston(ci) (astpending++) | |
49 | extern void cpu_need_resched(struct cpu_info *ci, int flags); | 49 | extern void cpu_need_resched(struct cpu_info *ci, int flags); | |
50 | 50 | |||
51 | 51 | |||
52 | struct cpu_info { | 52 | struct cpu_info { | |
53 | device_t ci_dev; | 53 | struct cpu_data ci_data; /* MI per-cpu data */ | |
54 | device_t ci_dev; /* pointer to our device */ | |||
54 | struct cpu_info *ci_self; | 55 | struct cpu_info *ci_self; | |
55 | struct cpu_info *ci_next; | 56 | struct cpu_info *ci_next; | |
56 | struct cpu_data ci_data; | |||
57 | u_int ci_cpuid; | 57 | u_int ci_cpuid; | |
58 | int ci_want_resched; | 58 | int ci_want_resched; | |
59 | int ci_idepth; | 59 | int ci_idepth; | |
60 | volatile int ci_mtx_count; | 60 | volatile int ci_mtx_count; | |
61 | volatile int ci_mtx_oldspl; | 61 | volatile int ci_mtx_oldspl; | |
62 | lwp_t *ci_curlwp; | 62 | lwp_t *ci_curlwp; | |
63 | lwp_t *ci_stash; | 63 | lwp_t *ci_stash; | |
64 | }; | 64 | }; | |
65 | 65 | |||
66 | __inline static struct cpu_info * __attribute__((__unused__)) | 66 | __inline static struct cpu_info * __attribute__((__unused__)) | |
67 | usermode_curcpu(void) | 67 | usermode_curcpu(void) | |
68 | { | 68 | { | |
69 | extern struct cpu_info cpu_info_primary; | 69 | extern struct cpu_info cpu_info_primary; |
--- src/sys/arch/usermode/include/types.h 2012/01/08 18:06:00 1.7
+++ src/sys/arch/usermode/include/types.h 2012/02/08 17:55:21 1.8
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: types.h,v 1.7 2012/01/08 18:06:00 jmcneill Exp $ */ | 1 | /* $NetBSD: types.h,v 1.8 2012/02/08 17:55:21 reinoud Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -52,14 +52,17 @@ typedef long int register_t; | @@ -52,14 +52,17 @@ typedef long int register_t; | |||
52 | #define PRIuVSIZE "lu" | 52 | #define PRIuVSIZE "lu" | |
53 | #define PRIxREGISTER "lx" | 53 | #define PRIxREGISTER "lx" | |
54 | 54 | |||
55 | typedef volatile unsigned char __cpu_simple_lock_t; | 55 | typedef volatile unsigned char __cpu_simple_lock_t; | |
56 | #define __CPU_SIMPLE_LOCK_PAD | 56 | #define __CPU_SIMPLE_LOCK_PAD | |
57 | 57 | |||
58 | #define __SIMPLELOCK_LOCKED 1 | 58 | #define __SIMPLELOCK_LOCKED 1 | |
59 | #define __SIMPLELOCK_UNLOCKED 0 | 59 | #define __SIMPLELOCK_UNLOCKED 0 | |
60 | 60 | |||
61 | #if defined(__i386__) | 61 | #if defined(__i386__) | |
62 | #define __HAVE_OLD_DISKLABEL | 62 | #define __HAVE_OLD_DISKLABEL | |
63 | #endif | 63 | #endif | |
64 | 64 | |||
65 | #define __HAVE_CPU_DATA_FIRST | |||
66 | #define __HAVE_MM_MD_KERNACC | |||
67 | ||||
65 | #endif /* !_ARCH_USERMODE_INCLUDE_TYPES_H */ | 68 | #endif /* !_ARCH_USERMODE_INCLUDE_TYPES_H */ |
--- src/sys/arch/usermode/include/vmparam.h 2012/01/10 10:19:38 1.15
+++ src/sys/arch/usermode/include/vmparam.h 2012/02/08 17:55:21 1.16
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: vmparam.h,v 1.15 2012/01/10 10:19:38 reinoud Exp $ */ | 1 | /* $NetBSD: vmparam.h,v 1.16 2012/02/08 17:55:21 reinoud Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -26,26 +26,27 @@ | @@ -26,26 +26,27 @@ | |||
26 | * POSSIBILITY OF SUCH DAMAGE. | 26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #ifndef _ARCH_USERMODE_INCLUDE_VMPARAM_H | 29 | #ifndef _ARCH_USERMODE_INCLUDE_VMPARAM_H | |
30 | #define _ARCH_USERMODE_INCLUDE_VMPARAM_H | 30 | #define _ARCH_USERMODE_INCLUDE_VMPARAM_H | |
31 | 31 | |||
32 | #include <machine/pmap.h> | 32 | #include <machine/pmap.h> | |
33 | #include "opt_memsize.h" | 33 | #include "opt_memsize.h" | |
34 | 34 | |||
35 | #define __USE_TOPDOWN_VM | 35 | #define __USE_TOPDOWN_VM | |
36 | 36 | |||
37 | extern paddr_t kmem_k_start, kmem_k_end; | 37 | extern paddr_t kmem_k_start, kmem_k_end; | |
38 | extern paddr_t kmem_kvm_start, kmem_kvm_end; | 38 | extern paddr_t kmem_kvm_start, kmem_kvm_end; | |
39 | extern paddr_t kmem_kvm_cur_end; | |||
39 | extern paddr_t kmem_user_start, kmem_user_end; | 40 | extern paddr_t kmem_user_start, kmem_user_end; | |
40 | 41 | |||
41 | #define VM_MIN_ADDRESS kmem_user_start | 42 | #define VM_MIN_ADDRESS kmem_user_start | |
42 | #define VM_MAX_ADDRESS kmem_user_end | 43 | #define VM_MAX_ADDRESS kmem_user_end | |
43 | #define VM_MAXUSER_ADDRESS kmem_user_end | 44 | #define VM_MAXUSER_ADDRESS kmem_user_end | |
44 | #define VM_MIN_KERNEL_ADDRESS kmem_kvm_start | 45 | #define VM_MIN_KERNEL_ADDRESS kmem_kvm_start | |
45 | #define VM_MAX_KERNEL_ADDRESS kmem_kvm_end | 46 | #define VM_MAX_KERNEL_ADDRESS kmem_kvm_end | |
46 | 47 | |||
47 | #define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST | 48 | #define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST | |
48 | #define VM_PHYSSEG_MAX 1 | 49 | #define VM_PHYSSEG_MAX 1 | |
49 | #define VM_NFREELIST 1 | 50 | #define VM_NFREELIST 1 | |
50 | #define VM_FREELIST_DEFAULT 0 | 51 | #define VM_FREELIST_DEFAULT 0 | |
51 | 52 |
--- src/sys/arch/usermode/usermode/machdep.c 2012/01/15 10:30:21 1.52
+++ src/sys/arch/usermode/usermode/machdep.c 2012/02/08 17:55:21 1.53
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: machdep.c,v 1.52 2012/01/15 10:30:21 jmcneill Exp $ */ | 1 | /* $NetBSD: machdep.c,v 1.53 2012/02/08 17:55:21 reinoud Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org> | 4 | * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org> | |
5 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | 5 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -27,44 +27,45 @@ | @@ -27,44 +27,45 @@ | |||
27 | * POSSIBILITY OF SUCH DAMAGE. | 27 | * POSSIBILITY OF SUCH DAMAGE. | |
28 | */ | 28 | */ | |
29 | 29 | |||
30 | /* | 30 | /* | |
31 | * Note that this machdep.c uses the `dummy' mcontext_t defined for usermode. | 31 | * Note that this machdep.c uses the `dummy' mcontext_t defined for usermode. | |
32 | * This is basicly a blob of PAGE_SIZE big. We might want to switch over to | 32 | * This is basicly a blob of PAGE_SIZE big. We might want to switch over to | |
33 | * non-generic mcontext_t's one day, but will this break non-NetBSD hosts? | 33 | * non-generic mcontext_t's one day, but will this break non-NetBSD hosts? | |
34 | */ | 34 | */ | |
35 | 35 | |||
36 | 36 | |||
37 | #include "opt_memsize.h" | 37 | #include "opt_memsize.h" | |
38 | 38 | |||
39 | #include <sys/cdefs.h> | 39 | #include <sys/cdefs.h> | |
40 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.52 2012/01/15 10:30:21 jmcneill Exp $"); | 40 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.53 2012/02/08 17:55:21 reinoud Exp $"); | |
41 | 41 | |||
42 | #include <sys/types.h> | 42 | #include <sys/types.h> | |
43 | #include <sys/systm.h> | 43 | #include <sys/systm.h> | |
44 | #include <sys/param.h> | 44 | #include <sys/param.h> | |
45 | #include <sys/time.h> | 45 | #include <sys/time.h> | |
46 | #include <sys/exec.h> | 46 | #include <sys/exec.h> | |
47 | #include <sys/buf.h> | 47 | #include <sys/buf.h> | |
48 | #include <sys/boot_flag.h> | 48 | #include <sys/boot_flag.h> | |
49 | #include <sys/ucontext.h> | 49 | #include <sys/ucontext.h> | |
50 | #include <sys/utsname.h> | 50 | #include <sys/utsname.h> | |
51 | #include <machine/pcb.h> | 51 | #include <machine/pcb.h> | |
52 | #include <machine/psl.h> | 52 | #include <machine/psl.h> | |
53 | 53 | |||
54 | #include <uvm/uvm_extern.h> | 54 | #include <uvm/uvm_extern.h> | |
55 | #include <uvm/uvm_page.h> | 55 | #include <uvm/uvm_page.h> | |
56 | 56 | |||
57 | #include <dev/mm.h> | 57 | #include <dev/mm.h> | |
58 | #include <machine/vmparam.h> | |||
58 | #include <machine/machdep.h> | 59 | #include <machine/machdep.h> | |
59 | #include <machine/thunk.h> | 60 | #include <machine/thunk.h> | |
60 | 61 | |||
61 | #ifndef MAX_DISK_IMAGES | 62 | #ifndef MAX_DISK_IMAGES | |
62 | #define MAX_DISK_IMAGES 4 | 63 | #define MAX_DISK_IMAGES 4 | |
63 | #endif | 64 | #endif | |
64 | 65 | |||
65 | char machine[_SYS_NMLN] = ""; | 66 | char machine[_SYS_NMLN] = ""; | |
66 | char machine_arch[_SYS_NMLN] = ""; | 67 | char machine_arch[_SYS_NMLN] = ""; | |
67 | char module_machine_usermode[_SYS_NMLN] = ""; | 68 | char module_machine_usermode[_SYS_NMLN] = ""; | |
68 | 69 | |||
69 | struct vm_map *phys_map = NULL; | 70 | struct vm_map *phys_map = NULL; | |
70 | 71 | |||
@@ -239,18 +240,40 @@ usermode_reboot(void) | @@ -239,18 +240,40 @@ usermode_reboot(void) | |||
239 | 240 | |||
240 | void | 241 | void | |
241 | setstatclockrate(int arg) | 242 | setstatclockrate(int arg) | |
242 | { | 243 | { | |
243 | } | 244 | } | |
244 | 245 | |||
245 | void | 246 | void | |
246 | consinit(void) | 247 | consinit(void) | |
247 | { | 248 | { | |
248 | printf("NetBSD/usermode startup\n"); | 249 | printf("NetBSD/usermode startup\n"); | |
249 | } | 250 | } | |
250 | 251 | |||
251 | int | 252 | int | |
252 | mm_md_physacc(paddr_t pa, vm_prot_t prog) | 253 | mm_md_physacc(paddr_t pa, vm_prot_t prot) | |
253 | { | 254 | { | |
255 | // printf("%s: pa = %p, acc %d\n", __func__, (void *) pa, prot); | |||
256 | if (pa >= physmem * PAGE_SIZE) | |||
257 | return EFAULT; | |||
258 | return 0; | |||
259 | } | |||
260 | ||||
261 | ||||
262 | int | |||
263 | mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) | |||
264 | { | |||
265 | const vaddr_t va = (vaddr_t)ptr; | |||
266 | extern void *end; | |||
267 | ||||
268 | // printf("%s: ptr %p, acc %d\n", __func__, ptr, prot); | |||
269 | if (va < kmem_kvm_start) | |||
270 | return EFAULT; | |||
271 | if ((va >= kmem_kvm_cur_end) && (va < kmem_k_start)) | |||
272 | return EFAULT; | |||
273 | if (va > (vaddr_t) end) | |||
274 | return EFAULT; | |||
275 | ||||
276 | *handled = true; | |||
254 | return 0; | 277 | return 0; | |
255 | } | 278 | } | |
256 | 279 |