cpu.c revision 1.54 1 1.54 jmcneill /* $NetBSD: cpu.c,v 1.54 2011/12/15 02:09:15 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2007 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 jmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 jmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 jmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 jmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 jmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 jmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 jmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 jmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 jmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 jmcneill * POSSIBILITY OF SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.19 jmcneill #include "opt_cpu.h"
30 1.37 jmcneill #include "opt_hz.h"
31 1.19 jmcneill
32 1.1 jmcneill #include <sys/cdefs.h>
33 1.54 jmcneill __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.54 2011/12/15 02:09:15 jmcneill Exp $");
34 1.1 jmcneill
35 1.1 jmcneill #include <sys/param.h>
36 1.1 jmcneill #include <sys/conf.h>
37 1.1 jmcneill #include <sys/proc.h>
38 1.1 jmcneill #include <sys/systm.h>
39 1.1 jmcneill #include <sys/device.h>
40 1.1 jmcneill #include <sys/reboot.h>
41 1.1 jmcneill #include <sys/lwp.h>
42 1.1 jmcneill #include <sys/cpu.h>
43 1.1 jmcneill #include <sys/mbuf.h>
44 1.16 jmcneill #include <sys/msgbuf.h>
45 1.54 jmcneill #include <sys/kmem.h>
46 1.1 jmcneill
47 1.1 jmcneill #include <dev/cons.h>
48 1.1 jmcneill
49 1.1 jmcneill #include <machine/cpu.h>
50 1.1 jmcneill #include <machine/mainbus.h>
51 1.8 jmcneill #include <machine/pcb.h>
52 1.40 reinoud #include <machine/machdep.h>
53 1.10 jmcneill #include <machine/thunk.h>
54 1.1 jmcneill
55 1.1 jmcneill #include <uvm/uvm_extern.h>
56 1.1 jmcneill #include <uvm/uvm_page.h>
57 1.1 jmcneill
58 1.27 jmcneill #if __GNUC_PREREQ__(4,4)
59 1.27 jmcneill #define cpu_unreachable() __builtin_unreachable()
60 1.27 jmcneill #else
61 1.27 jmcneill #define cpu_unreachable() do { thunk_abort(); } while (0)
62 1.27 jmcneill #endif
63 1.27 jmcneill
64 1.1 jmcneill static int cpu_match(device_t, cfdata_t, void *);
65 1.1 jmcneill static void cpu_attach(device_t, device_t, void *);
66 1.1 jmcneill
67 1.13 jmcneill struct cpu_info cpu_info_primary = {
68 1.13 jmcneill .ci_dev = 0,
69 1.13 jmcneill .ci_self = &cpu_info_primary,
70 1.13 jmcneill .ci_idepth = -1,
71 1.13 jmcneill .ci_curlwp = &lwp0,
72 1.13 jmcneill };
73 1.13 jmcneill
74 1.1 jmcneill char cpu_model[48] = "virtual processor";
75 1.1 jmcneill
76 1.1 jmcneill typedef struct cpu_softc {
77 1.1 jmcneill device_t sc_dev;
78 1.1 jmcneill struct cpu_info *sc_ci;
79 1.1 jmcneill } cpu_softc_t;
80 1.1 jmcneill
81 1.15 jmcneill static struct pcb lwp0pcb;
82 1.54 jmcneill static void *um_msgbuf;
83 1.9 jmcneill
84 1.1 jmcneill CFATTACH_DECL_NEW(cpu, sizeof(cpu_softc_t), cpu_match, cpu_attach, NULL, NULL);
85 1.1 jmcneill
86 1.1 jmcneill static int
87 1.1 jmcneill cpu_match(device_t parent, cfdata_t match, void *opaque)
88 1.1 jmcneill {
89 1.1 jmcneill struct thunkbus_attach_args *taa = opaque;
90 1.1 jmcneill
91 1.1 jmcneill if (taa->taa_type != THUNKBUS_TYPE_CPU)
92 1.1 jmcneill return 0;
93 1.1 jmcneill
94 1.1 jmcneill return 1;
95 1.1 jmcneill }
96 1.1 jmcneill
97 1.1 jmcneill static void
98 1.1 jmcneill cpu_attach(device_t parent, device_t self, void *opaque)
99 1.1 jmcneill {
100 1.1 jmcneill cpu_softc_t *sc = device_private(self);
101 1.1 jmcneill
102 1.1 jmcneill aprint_naive("\n");
103 1.1 jmcneill aprint_normal("\n");
104 1.1 jmcneill
105 1.1 jmcneill sc->sc_dev = self;
106 1.1 jmcneill sc->sc_ci = &cpu_info_primary;
107 1.1 jmcneill }
108 1.1 jmcneill
109 1.1 jmcneill void
110 1.1 jmcneill cpu_configure(void)
111 1.1 jmcneill {
112 1.1 jmcneill if (config_rootfound("mainbus", NULL) == NULL)
113 1.1 jmcneill panic("configure: mainbus not configured");
114 1.1 jmcneill
115 1.1 jmcneill spl0();
116 1.1 jmcneill }
117 1.1 jmcneill
118 1.1 jmcneill void
119 1.1 jmcneill cpu_reboot(int howto, char *bootstr)
120 1.1 jmcneill {
121 1.11 jmcneill extern void usermode_reboot(void);
122 1.11 jmcneill
123 1.1 jmcneill splhigh();
124 1.1 jmcneill
125 1.1 jmcneill if ((howto & RB_POWERDOWN) == RB_POWERDOWN)
126 1.10 jmcneill thunk_exit(0);
127 1.1 jmcneill
128 1.22 jmcneill if (howto & RB_DUMP)
129 1.22 jmcneill thunk_abort();
130 1.22 jmcneill
131 1.1 jmcneill if (howto & RB_HALT) {
132 1.1 jmcneill printf("\n");
133 1.1 jmcneill printf("The operating system has halted.\n");
134 1.1 jmcneill printf("Please press any key to reboot.\n\n");
135 1.1 jmcneill cnpollc(1);
136 1.1 jmcneill cngetc();
137 1.1 jmcneill cnpollc(0);
138 1.1 jmcneill }
139 1.1 jmcneill
140 1.1 jmcneill printf("rebooting...\n");
141 1.1 jmcneill
142 1.11 jmcneill usermode_reboot();
143 1.1 jmcneill
144 1.1 jmcneill /* NOTREACHED */
145 1.27 jmcneill cpu_unreachable();
146 1.1 jmcneill }
147 1.1 jmcneill
148 1.1 jmcneill void
149 1.1 jmcneill cpu_need_resched(struct cpu_info *ci, int flags)
150 1.1 jmcneill {
151 1.9 jmcneill ci->ci_want_resched |= flags;
152 1.1 jmcneill }
153 1.1 jmcneill
154 1.1 jmcneill void
155 1.1 jmcneill cpu_need_proftick(struct lwp *l)
156 1.1 jmcneill {
157 1.1 jmcneill }
158 1.1 jmcneill
159 1.1 jmcneill lwp_t *
160 1.1 jmcneill cpu_switchto(lwp_t *oldlwp, lwp_t *newlwp, bool returning)
161 1.1 jmcneill {
162 1.5 rmind struct pcb *oldpcb = oldlwp ? lwp_getpcb(oldlwp) : NULL;
163 1.5 rmind struct pcb *newpcb = lwp_getpcb(newlwp);
164 1.1 jmcneill struct cpu_info *ci = curcpu();
165 1.1 jmcneill
166 1.1 jmcneill #ifdef CPU_DEBUG
167 1.47 reinoud dprintf_debug("cpu_switchto [%s,pid=%d,lid=%d] -> [%s,pid=%d,lid=%d]\n",
168 1.1 jmcneill oldlwp ? oldlwp->l_name : "none",
169 1.17 jmcneill oldlwp ? oldlwp->l_proc->p_pid : -1,
170 1.17 jmcneill oldlwp ? oldlwp->l_lid : -1,
171 1.17 jmcneill newlwp ? newlwp->l_name : "none",
172 1.17 jmcneill newlwp ? newlwp->l_proc->p_pid : -1,
173 1.17 jmcneill newlwp ? newlwp->l_lid : -1);
174 1.1 jmcneill if (oldpcb) {
175 1.47 reinoud dprintf_debug(" oldpcb uc_link=%p, uc_stack.ss_sp=%p, "
176 1.1 jmcneill "uc_stack.ss_size=%d\n",
177 1.1 jmcneill oldpcb->pcb_ucp.uc_link,
178 1.1 jmcneill oldpcb->pcb_ucp.uc_stack.ss_sp,
179 1.1 jmcneill (int)oldpcb->pcb_ucp.uc_stack.ss_size);
180 1.1 jmcneill }
181 1.1 jmcneill if (newpcb) {
182 1.47 reinoud dprintf_debug(" newpcb uc_link=%p, uc_stack.ss_sp=%p, "
183 1.1 jmcneill "uc_stack.ss_size=%d\n",
184 1.1 jmcneill newpcb->pcb_ucp.uc_link,
185 1.1 jmcneill newpcb->pcb_ucp.uc_stack.ss_sp,
186 1.1 jmcneill (int)newpcb->pcb_ucp.uc_stack.ss_size);
187 1.1 jmcneill }
188 1.1 jmcneill #endif /* !CPU_DEBUG */
189 1.1 jmcneill
190 1.1 jmcneill ci->ci_stash = oldlwp;
191 1.28 reinoud
192 1.1 jmcneill if (oldpcb) {
193 1.29 reinoud oldpcb->pcb_errno = thunk_geterrno();
194 1.32 reinoud thunk_seterrno(newpcb->pcb_errno);
195 1.45 reinoud curlwp = newlwp;
196 1.10 jmcneill if (thunk_swapcontext(&oldpcb->pcb_ucp, &newpcb->pcb_ucp))
197 1.26 jmcneill panic("swapcontext failed");
198 1.1 jmcneill } else {
199 1.32 reinoud thunk_seterrno(newpcb->pcb_errno);
200 1.45 reinoud curlwp = newlwp;
201 1.10 jmcneill if (thunk_setcontext(&newpcb->pcb_ucp))
202 1.26 jmcneill panic("setcontext failed");
203 1.1 jmcneill }
204 1.30 reinoud
205 1.1 jmcneill #ifdef CPU_DEBUG
206 1.47 reinoud dprintf_debug("cpu_switchto: returning %p (was %p)\n", ci->ci_stash, oldlwp);
207 1.1 jmcneill #endif
208 1.1 jmcneill return ci->ci_stash;
209 1.1 jmcneill }
210 1.1 jmcneill
211 1.1 jmcneill void
212 1.1 jmcneill cpu_dumpconf(void)
213 1.1 jmcneill {
214 1.1 jmcneill #ifdef CPU_DEBUG
215 1.47 reinoud dprintf_debug("cpu_dumpconf\n");
216 1.1 jmcneill #endif
217 1.1 jmcneill }
218 1.1 jmcneill
219 1.1 jmcneill void
220 1.1 jmcneill cpu_signotify(struct lwp *l)
221 1.1 jmcneill {
222 1.1 jmcneill }
223 1.1 jmcneill
224 1.1 jmcneill void
225 1.1 jmcneill cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flags)
226 1.1 jmcneill {
227 1.47 reinoud panic("cpu_getmcontext");
228 1.1 jmcneill #ifdef CPU_DEBUG
229 1.47 reinoud dprintf_debug("cpu_getmcontext\n");
230 1.1 jmcneill #endif
231 1.1 jmcneill }
232 1.1 jmcneill
233 1.1 jmcneill int
234 1.1 jmcneill cpu_setmcontext(struct lwp *l, const mcontext_t *mcp, unsigned int flags)
235 1.1 jmcneill {
236 1.47 reinoud panic("cpu_setmcontext");
237 1.1 jmcneill #ifdef CPU_DEBUG
238 1.47 reinoud dprintf_debug("cpu_setmcontext\n");
239 1.1 jmcneill #endif
240 1.1 jmcneill return 0;
241 1.1 jmcneill }
242 1.1 jmcneill
243 1.1 jmcneill void
244 1.1 jmcneill cpu_idle(void)
245 1.1 jmcneill {
246 1.1 jmcneill struct cpu_info *ci = curcpu();
247 1.1 jmcneill
248 1.1 jmcneill if (ci->ci_want_resched)
249 1.1 jmcneill return;
250 1.1 jmcneill
251 1.53 jmcneill thunk_idle();
252 1.1 jmcneill }
253 1.1 jmcneill
254 1.1 jmcneill void
255 1.1 jmcneill cpu_lwp_free(struct lwp *l, int proc)
256 1.1 jmcneill {
257 1.1 jmcneill #ifdef CPU_DEBUG
258 1.47 reinoud dprintf_debug("cpu_lwp_free (dummy)\n");
259 1.1 jmcneill #endif
260 1.1 jmcneill }
261 1.1 jmcneill
262 1.1 jmcneill void
263 1.1 jmcneill cpu_lwp_free2(struct lwp *l)
264 1.1 jmcneill {
265 1.5 rmind struct pcb *pcb = lwp_getpcb(l);
266 1.1 jmcneill
267 1.1 jmcneill #ifdef CPU_DEBUG
268 1.47 reinoud dprintf_debug("cpu_lwp_free2\n");
269 1.1 jmcneill #endif
270 1.1 jmcneill
271 1.1 jmcneill if (pcb == NULL)
272 1.1 jmcneill return;
273 1.1 jmcneill
274 1.1 jmcneill if (pcb->pcb_needfree) {
275 1.48 reinoud #if 0
276 1.1 jmcneill free(pcb->pcb_ucp.uc_stack.ss_sp, M_TEMP);
277 1.1 jmcneill pcb->pcb_ucp.uc_stack.ss_sp = NULL;
278 1.1 jmcneill pcb->pcb_ucp.uc_stack.ss_size = 0;
279 1.48 reinoud #endif
280 1.45 reinoud
281 1.45 reinoud free(pcb->pcb_syscall_ucp.uc_stack.ss_sp, M_TEMP);
282 1.45 reinoud pcb->pcb_syscall_ucp.uc_stack.ss_sp = NULL;
283 1.45 reinoud pcb->pcb_syscall_ucp.uc_stack.ss_size = 0;
284 1.45 reinoud
285 1.48 reinoud free(pcb->pcb_pagefault_ucp.uc_stack.ss_sp, M_TEMP);
286 1.48 reinoud pcb->pcb_pagefault_ucp.uc_stack.ss_sp = NULL;
287 1.48 reinoud pcb->pcb_pagefault_ucp.uc_stack.ss_size = 0;
288 1.48 reinoud
289 1.1 jmcneill pcb->pcb_needfree = false;
290 1.1 jmcneill }
291 1.1 jmcneill }
292 1.1 jmcneill
293 1.1 jmcneill static void
294 1.44 reinoud cpu_lwp_trampoline(ucontext_t *ucp, void (*func)(void *), void *arg)
295 1.1 jmcneill {
296 1.18 reinoud #ifdef CPU_DEBUG
297 1.47 reinoud dprintf_debug("cpu_lwp_trampoline called with func %p, arg %p\n", (void *) func, arg);
298 1.18 reinoud #endif
299 1.44 reinoud /* init lwp */
300 1.1 jmcneill lwp_startup(curcpu()->ci_stash, curlwp);
301 1.44 reinoud
302 1.45 reinoud /* actual jump */
303 1.44 reinoud thunk_makecontext(ucp, (void (*)(void)) func, 1, arg, NULL, NULL);
304 1.45 reinoud thunk_setcontext(ucp);
305 1.1 jmcneill }
306 1.1 jmcneill
307 1.1 jmcneill void
308 1.1 jmcneill cpu_lwp_fork(struct lwp *l1, struct lwp *l2, void *stack, size_t stacksize,
309 1.1 jmcneill void (*func)(void *), void *arg)
310 1.1 jmcneill {
311 1.23 reinoud struct pcb *pcb1 = lwp_getpcb(l1);
312 1.23 reinoud struct pcb *pcb2 = lwp_getpcb(l2);
313 1.47 reinoud void *stack_ucp, *stack_syscall_ucp, *stack_pagefault_ucp;
314 1.1 jmcneill
315 1.1 jmcneill #ifdef CPU_DEBUG
316 1.47 reinoud dprintf_debug("cpu_lwp_fork [%s/%p] -> [%s/%p] stack=%p stacksize=%d\n",
317 1.1 jmcneill l1 ? l1->l_name : "none", l1,
318 1.1 jmcneill l2 ? l2->l_name : "none", l2,
319 1.1 jmcneill stack, (int)stacksize);
320 1.1 jmcneill #endif
321 1.1 jmcneill
322 1.45 reinoud if (stack)
323 1.45 reinoud panic("%s: stack passed, can't handle\n", __func__);
324 1.45 reinoud
325 1.23 reinoud /* copy the PCB and its switchframes from parent */
326 1.23 reinoud memcpy(pcb2, pcb1, sizeof(struct pcb));
327 1.23 reinoud
328 1.50 reinoud stacksize = 2*PAGE_SIZE;
329 1.47 reinoud stack_ucp = malloc(stacksize, M_TEMP, M_NOWAIT);
330 1.47 reinoud stack_syscall_ucp = malloc(stacksize, M_TEMP, M_NOWAIT);
331 1.47 reinoud stack_pagefault_ucp = malloc(stacksize, M_TEMP, M_NOWAIT);
332 1.45 reinoud pcb2->pcb_needfree = true;
333 1.1 jmcneill
334 1.23 reinoud if (thunk_getcontext(&pcb2->pcb_ucp))
335 1.26 jmcneill panic("getcontext failed");
336 1.23 reinoud
337 1.43 reinoud /* set up the ucontext for the userland switch */
338 1.48 reinoud /* XXX BUG TODO when is this stack space freed? */
339 1.45 reinoud pcb2->pcb_ucp.uc_stack.ss_sp = stack_ucp;
340 1.23 reinoud pcb2->pcb_ucp.uc_stack.ss_size = stacksize;
341 1.23 reinoud pcb2->pcb_ucp.uc_flags = _UC_STACK | _UC_CPU;
342 1.47 reinoud pcb2->pcb_ucp.uc_link = &pcb2->pcb_userret_ucp;
343 1.45 reinoud thunk_makecontext(&pcb2->pcb_ucp,
344 1.45 reinoud (void (*)(void)) cpu_lwp_trampoline,
345 1.44 reinoud 3, &pcb2->pcb_ucp, func, arg);
346 1.35 reinoud
347 1.35 reinoud /* set up the ucontext for the syscall */
348 1.45 reinoud pcb2->pcb_syscall_ucp.uc_stack.ss_sp = stack_syscall_ucp;
349 1.45 reinoud pcb2->pcb_syscall_ucp.uc_stack.ss_size = stacksize;
350 1.47 reinoud pcb2->pcb_syscall_ucp.uc_flags = _UC_STACK | _UC_CPU;
351 1.47 reinoud pcb2->pcb_syscall_ucp.uc_link = &pcb2->pcb_userret_ucp;
352 1.42 reinoud thunk_makecontext(&pcb2->pcb_syscall_ucp, (void (*)(void)) syscall,
353 1.43 reinoud 0, NULL, NULL, NULL);
354 1.47 reinoud
355 1.47 reinoud /* set up the ucontext for the pagefault */
356 1.47 reinoud pcb2->pcb_pagefault_ucp.uc_stack.ss_sp = stack_pagefault_ucp;
357 1.47 reinoud pcb2->pcb_pagefault_ucp.uc_stack.ss_size = stacksize;
358 1.47 reinoud pcb2->pcb_pagefault_ucp.uc_flags = _UC_STACK | _UC_CPU;
359 1.47 reinoud pcb2->pcb_pagefault_ucp.uc_link = &pcb2->pcb_trapret_ucp;
360 1.47 reinoud thunk_makecontext(&pcb2->pcb_pagefault_ucp, (void (*)(void)) pagefault,
361 1.47 reinoud 0, NULL, NULL, NULL);
362 1.1 jmcneill }
363 1.1 jmcneill
364 1.1 jmcneill void
365 1.1 jmcneill cpu_initclocks(void)
366 1.1 jmcneill {
367 1.37 jmcneill struct thunk_itimerval itimer;
368 1.37 jmcneill
369 1.37 jmcneill itimer.it_interval.tv_sec = 0;
370 1.37 jmcneill itimer.it_interval.tv_usec = 1000000 / HZ;
371 1.37 jmcneill itimer.it_value = itimer.it_interval;
372 1.37 jmcneill thunk_setitimer(ITIMER_REAL, &itimer, NULL);
373 1.1 jmcneill }
374 1.1 jmcneill
375 1.1 jmcneill void
376 1.1 jmcneill cpu_startup(void)
377 1.1 jmcneill {
378 1.54 jmcneill size_t stacksize, msgbufsize = 32 * 1024;
379 1.47 reinoud void *stack_pagefault_ucp;
380 1.47 reinoud
381 1.54 jmcneill um_msgbuf = kmem_zalloc(msgbufsize, KM_SLEEP);
382 1.54 jmcneill if (um_msgbuf == NULL)
383 1.16 jmcneill panic("couldn't allocate msgbuf");
384 1.54 jmcneill initmsgbuf(um_msgbuf, msgbufsize);
385 1.16 jmcneill
386 1.13 jmcneill banner();
387 1.15 jmcneill
388 1.15 jmcneill memset(&lwp0pcb, 0, sizeof(lwp0pcb));
389 1.15 jmcneill if (thunk_getcontext(&lwp0pcb.pcb_ucp))
390 1.15 jmcneill panic("getcontext failed");
391 1.15 jmcneill uvm_lwp_setuarea(&lwp0, (vaddr_t)&lwp0pcb);
392 1.23 reinoud
393 1.47 reinoud /* init trapframes (going nowhere!), maybe a panic func? */
394 1.47 reinoud memcpy(&lwp0pcb.pcb_syscall_ucp, &lwp0pcb.pcb_ucp, sizeof(ucontext_t));
395 1.47 reinoud memcpy(&lwp0pcb.pcb_userret_ucp, &lwp0pcb.pcb_ucp, sizeof(ucontext_t));
396 1.47 reinoud memcpy(&lwp0pcb.pcb_pagefault_ucp, &lwp0pcb.pcb_ucp, sizeof(ucontext_t));
397 1.47 reinoud memcpy(&lwp0pcb.pcb_trapret_ucp, &lwp0pcb.pcb_ucp, sizeof(ucontext_t));
398 1.47 reinoud
399 1.47 reinoud /* set up the ucontext for the pagefault */
400 1.47 reinoud stacksize = 16*PAGE_SIZE;
401 1.47 reinoud stack_pagefault_ucp = malloc(stacksize, M_TEMP, M_NOWAIT);
402 1.47 reinoud
403 1.47 reinoud lwp0pcb.pcb_pagefault_ucp.uc_stack.ss_sp = stack_pagefault_ucp;
404 1.47 reinoud lwp0pcb.pcb_pagefault_ucp.uc_stack.ss_size = stacksize;
405 1.47 reinoud lwp0pcb.pcb_pagefault_ucp.uc_flags = _UC_STACK | _UC_CPU;
406 1.47 reinoud lwp0pcb.pcb_pagefault_ucp.uc_link = &lwp0pcb.pcb_userret_ucp;
407 1.47 reinoud thunk_makecontext(&lwp0pcb.pcb_pagefault_ucp, (void (*)(void)) pagefault,
408 1.47 reinoud 0, NULL, NULL, NULL);
409 1.1 jmcneill }
410 1.1 jmcneill
411 1.1 jmcneill void
412 1.1 jmcneill cpu_rootconf(void)
413 1.1 jmcneill {
414 1.2 joerg device_t rdev;
415 1.1 jmcneill
416 1.12 jmcneill rdev = device_find_by_xname("ld0");
417 1.12 jmcneill if (rdev == NULL)
418 1.12 jmcneill rdev = device_find_by_xname("md0");
419 1.1 jmcneill
420 1.12 jmcneill aprint_normal("boot device: %s\n",
421 1.12 jmcneill rdev ? device_xname(rdev) : "<unknown>");
422 1.1 jmcneill setroot(rdev, 0);
423 1.1 jmcneill }
424 1.1 jmcneill
425 1.1 jmcneill bool
426 1.1 jmcneill cpu_intr_p(void)
427 1.1 jmcneill {
428 1.13 jmcneill int idepth;
429 1.13 jmcneill
430 1.13 jmcneill kpreempt_disable();
431 1.13 jmcneill idepth = curcpu()->ci_idepth;
432 1.13 jmcneill kpreempt_enable();
433 1.13 jmcneill
434 1.13 jmcneill return (idepth >= 0);
435 1.1 jmcneill }
436