| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: cpu.c,v 1.15 2011/08/13 14:06:54 jmcneill Exp $ */ | | 1 | /* $NetBSD: cpu.c,v 1.16 2011/08/24 19:55:35 jmcneill 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. |
| @@ -17,37 +17,38 @@ | | | @@ -17,37 +17,38 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.15 2011/08/13 14:06:54 jmcneill Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.16 2011/08/24 19:55:35 jmcneill Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/conf.h> | | 33 | #include <sys/conf.h> |
34 | #include <sys/proc.h> | | 34 | #include <sys/proc.h> |
35 | #include <sys/systm.h> | | 35 | #include <sys/systm.h> |
36 | #include <sys/device.h> | | 36 | #include <sys/device.h> |
37 | #include <sys/reboot.h> | | 37 | #include <sys/reboot.h> |
38 | #include <sys/lwp.h> | | 38 | #include <sys/lwp.h> |
39 | #include <sys/cpu.h> | | 39 | #include <sys/cpu.h> |
40 | #include <sys/mbuf.h> | | 40 | #include <sys/mbuf.h> |
| | | 41 | #include <sys/msgbuf.h> |
41 | | | 42 | |
42 | #include <dev/cons.h> | | 43 | #include <dev/cons.h> |
43 | | | 44 | |
44 | #include <machine/cpu.h> | | 45 | #include <machine/cpu.h> |
45 | #include <machine/mainbus.h> | | 46 | #include <machine/mainbus.h> |
46 | #include <machine/pcb.h> | | 47 | #include <machine/pcb.h> |
47 | #include <machine/thunk.h> | | 48 | #include <machine/thunk.h> |
48 | | | 49 | |
49 | #include <uvm/uvm_extern.h> | | 50 | #include <uvm/uvm_extern.h> |
50 | #include <uvm/uvm_page.h> | | 51 | #include <uvm/uvm_page.h> |
51 | | | 52 | |
52 | /* #define CPU_DEBUG */ | | 53 | /* #define CPU_DEBUG */ |
53 | | | 54 | |
| @@ -59,26 +60,27 @@ struct cpu_info cpu_info_primary = { | | | @@ -59,26 +60,27 @@ struct cpu_info cpu_info_primary = { |
59 | .ci_self = &cpu_info_primary, | | 60 | .ci_self = &cpu_info_primary, |
60 | .ci_idepth = -1, | | 61 | .ci_idepth = -1, |
61 | .ci_curlwp = &lwp0, | | 62 | .ci_curlwp = &lwp0, |
62 | }; | | 63 | }; |
63 | | | 64 | |
64 | char cpu_model[48] = "virtual processor"; | | 65 | char cpu_model[48] = "virtual processor"; |
65 | | | 66 | |
66 | typedef struct cpu_softc { | | 67 | typedef struct cpu_softc { |
67 | device_t sc_dev; | | 68 | device_t sc_dev; |
68 | struct cpu_info *sc_ci; | | 69 | struct cpu_info *sc_ci; |
69 | } cpu_softc_t; | | 70 | } cpu_softc_t; |
70 | | | 71 | |
71 | static struct pcb lwp0pcb; | | 72 | static struct pcb lwp0pcb; |
| | | 73 | static void *msgbuf; |
72 | | | 74 | |
73 | CFATTACH_DECL_NEW(cpu, sizeof(cpu_softc_t), cpu_match, cpu_attach, NULL, NULL); | | 75 | CFATTACH_DECL_NEW(cpu, sizeof(cpu_softc_t), cpu_match, cpu_attach, NULL, NULL); |
74 | | | 76 | |
75 | static int | | 77 | static int |
76 | cpu_match(device_t parent, cfdata_t match, void *opaque) | | 78 | cpu_match(device_t parent, cfdata_t match, void *opaque) |
77 | { | | 79 | { |
78 | struct thunkbus_attach_args *taa = opaque; | | 80 | struct thunkbus_attach_args *taa = opaque; |
79 | | | 81 | |
80 | if (taa->taa_type != THUNKBUS_TYPE_CPU) | | 82 | if (taa->taa_type != THUNKBUS_TYPE_CPU) |
81 | return 0; | | 83 | return 0; |
82 | | | 84 | |
83 | return 1; | | 85 | return 1; |
84 | } | | 86 | } |
| @@ -301,26 +303,32 @@ cpu_lwp_fork(struct lwp *l1, struct lwp | | | @@ -301,26 +303,32 @@ cpu_lwp_fork(struct lwp *l1, struct lwp |
301 | pcb->pcb_ucp.uc_flags = _UC_STACK | _UC_CPU; | | 303 | pcb->pcb_ucp.uc_flags = _UC_STACK | _UC_CPU; |
302 | thunk_makecontext(&pcb->pcb_ucp, (void (*)(void))cpu_lwp_trampoline, | | 304 | thunk_makecontext(&pcb->pcb_ucp, (void (*)(void))cpu_lwp_trampoline, |
303 | 2, func, arg); | | 305 | 2, func, arg); |
304 | } | | 306 | } |
305 | | | 307 | |
306 | void | | 308 | void |
307 | cpu_initclocks(void) | | 309 | cpu_initclocks(void) |
308 | { | | 310 | { |
309 | } | | 311 | } |
310 | | | 312 | |
311 | void | | 313 | void |
312 | cpu_startup(void) | | 314 | cpu_startup(void) |
313 | { | | 315 | { |
| | | 316 | |
| | | 317 | msgbuf = thunk_malloc(PAGE_SIZE); |
| | | 318 | if (msgbuf == NULL) |
| | | 319 | panic("couldn't allocate msgbuf"); |
| | | 320 | initmsgbuf(msgbuf, PAGE_SIZE); |
| | | 321 | |
314 | banner(); | | 322 | banner(); |
315 | | | 323 | |
316 | memset(&lwp0pcb, 0, sizeof(lwp0pcb)); | | 324 | memset(&lwp0pcb, 0, sizeof(lwp0pcb)); |
317 | if (thunk_getcontext(&lwp0pcb.pcb_ucp)) | | 325 | if (thunk_getcontext(&lwp0pcb.pcb_ucp)) |
318 | panic("getcontext failed"); | | 326 | panic("getcontext failed"); |
319 | uvm_lwp_setuarea(&lwp0, (vaddr_t)&lwp0pcb); | | 327 | uvm_lwp_setuarea(&lwp0, (vaddr_t)&lwp0pcb); |
320 | } | | 328 | } |
321 | | | 329 | |
322 | void | | 330 | void |
323 | cpu_rootconf(void) | | 331 | cpu_rootconf(void) |
324 | { | | 332 | { |
325 | device_t rdev; | | 333 | device_t rdev; |
326 | | | 334 | |