1 /*-
2 * Copyright (c) 1982, 1986 The Regents of the University of California.
3 * Copyright (c) 1989, 1990 William Jolitz
4 * Copyright (c) 1994 John Dyson
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
9 * Science Department, and William Jolitz.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * from: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91
40 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
41 */
42
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD: releng/11.1/sys/amd64/amd64/vm_machdep.c 330908 2018-03-14 04:00:00Z gordon $");
45
46 #include "opt_isa.h"
47 #include "opt_cpu.h"
48 #include "opt_compat.h"
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/bio.h>
53 #include <sys/buf.h>
54 #include <sys/kernel.h>
55 #include <sys/ktr.h>
56 #include <sys/lock.h>
57 #include <sys/malloc.h>
58 #include <sys/mbuf.h>
59 #include <sys/mutex.h>
60 #include <sys/pioctl.h>
61 #include <sys/proc.h>
62 #include <sys/smp.h>
63 #include <sys/sysctl.h>
64 #include <sys/sysent.h>
65 #include <sys/unistd.h>
66 #include <sys/vnode.h>
67 #include <sys/vmmeter.h>
68
69 #include <machine/cpu.h>
70 #include <machine/md_var.h>
71 #include <machine/pcb.h>
72 #include <machine/smp.h>
73 #include <machine/specialreg.h>
74 #include <machine/tss.h>
75
76 #include <vm/vm.h>
77 #include <vm/vm_extern.h>
78 #include <vm/vm_kern.h>
79 #include <vm/vm_page.h>
80 #include <vm/vm_map.h>
81 #include <vm/vm_param.h>
82
83 #include <isa/isareg.h>
84
85 static void cpu_reset_real(void);
86 #ifdef SMP
87 static void cpu_reset_proxy(void);
88 static u_int cpu_reset_proxyid;
89 static volatile u_int cpu_reset_proxy_active;
90 #endif
91
92 _Static_assert(OFFSETOF_CURTHREAD == offsetof(struct pcpu, pc_curthread),
93 "OFFSETOF_CURTHREAD does not correspond with offset of pc_curthread.");
94 _Static_assert(OFFSETOF_CURPCB == offsetof(struct pcpu, pc_curpcb),
95 "OFFSETOF_CURPCB does not correspond with offset of pc_curpcb.");
96 _Static_assert(OFFSETOF_MONITORBUF == offsetof(struct pcpu, pc_monitorbuf),
97 "OFFSETOF_MONINORBUF does not correspond with offset of pc_monitorbuf.");
98
99 struct savefpu *
100 get_pcb_user_save_td(struct thread *td)
101 {
102 vm_offset_t p;
103
104 p = td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
105 roundup2(cpu_max_ext_state_size, XSAVE_AREA_ALIGN);
106 KASSERT((p % XSAVE_AREA_ALIGN) == 0, ("Unaligned pcb_user_save area"));
107 return ((struct savefpu *)p);
108 }
109
110 struct savefpu *
111 get_pcb_user_save_pcb(struct pcb *pcb)
112 {
113 vm_offset_t p;
114
115 p = (vm_offset_t)(pcb + 1);
116 return ((struct savefpu *)p);
117 }
118
119 struct pcb *
120 get_pcb_td(struct thread *td)
121 {
122 vm_offset_t p;
123
124 p = td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
125 roundup2(cpu_max_ext_state_size, XSAVE_AREA_ALIGN) -
126 sizeof(struct pcb);
127 return ((struct pcb *)p);
128 }
129
130 void *
131 alloc_fpusave(int flags)
132 {
133 void *res;
134 struct savefpu_ymm *sf;
135
136 res = malloc(cpu_max_ext_state_size, M_DEVBUF, flags);
137 if (use_xsave) {
138 sf = (struct savefpu_ymm *)res;
139 bzero(&sf->sv_xstate.sx_hd, sizeof(sf->sv_xstate.sx_hd));
140 sf->sv_xstate.sx_hd.xstate_bv = xsave_mask;
141 }
142 return (res);
143 }
144
145 /*
146 * Finish a fork operation, with process p2 nearly set up.
147 * Copy and update the pcb, set up the stack so that the child
148 * ready to run and return to user mode.
149 */
150 void
151 cpu_fork(td1, p2, td2, flags)
152 register struct thread *td1;
153 register struct proc *p2;
154 struct thread *td2;
155 int flags;
156 {
157 register struct proc *p1;
158 struct pcb *pcb2;
159 struct mdproc *mdp1, *mdp2;
160 struct proc_ldt *pldt;
161
162 p1 = td1->td_proc;
163 if ((flags & RFPROC) == 0) {
164 if ((flags & RFMEM) == 0) {
165 /* unshare user LDT */
166 mdp1 = &p1->p_md;
167 mtx_lock(&dt_lock);
168 if ((pldt = mdp1->md_ldt) != NULL &&
169 pldt->ldt_refcnt > 1 &&
170 user_ldt_alloc(p1, 1) == NULL)
171 panic("could not copy LDT");
172 mtx_unlock(&dt_lock);
173 }
174 return;
175 }
176
177 /* Ensure that td1's pcb is up to date. */
178 fpuexit(td1);
179
180 /* Point the pcb to the top of the stack */
181 pcb2 = get_pcb_td(td2);
182 td2->td_pcb = pcb2;
183
184 /* Copy td1's pcb */
185 bcopy(td1->td_pcb, pcb2, sizeof(*pcb2));
186
187 /* Properly initialize pcb_save */
188 pcb2->pcb_save = get_pcb_user_save_pcb(pcb2);
189 bcopy(get_pcb_user_save_td(td1), get_pcb_user_save_pcb(pcb2),
190 cpu_max_ext_state_size);
191
192 /* Point mdproc and then copy over td1's contents */
193 mdp2 = &p2->p_md;
194 bcopy(&p1->p_md, mdp2, sizeof(*mdp2));
195
196 /*
197 * Create a new fresh stack for the new process.
198 * Copy the trap frame for the return to user mode as if from a
199 * syscall. This copies most of the user mode register values.
200 */
201 td2->td_frame = (struct trapframe *)td2->td_pcb - 1;
202 bcopy(td1->td_frame, td2->td_frame, sizeof(struct trapframe));
203
204 td2->td_frame->tf_rax = 0; /* Child returns zero */
205 td2->td_frame->tf_rflags &= ~PSL_C; /* success */
206 td2->td_frame->tf_rdx = 1;
207
208 /*
209 * If the parent process has the trap bit set (i.e. a debugger had
210 * single stepped the process to the system call), we need to clear
211 * the trap flag from the new frame unless the debugger had set PF_FORK
212 * on the parent. Otherwise, the child will receive a (likely
213 * unexpected) SIGTRAP when it executes the first instruction after
214 * returning to userland.
215 */
216 if ((p1->p_pfsflags & PF_FORK) == 0)
217 td2->td_frame->tf_rflags &= ~PSL_T;
218
219 /*
220 * Set registers for trampoline to user mode. Leave space for the
221 * return address on stack. These are the kernel mode register values.
222 */
223 pcb2->pcb_r12 = (register_t)fork_return; /* fork_trampoline argument */
224 pcb2->pcb_rbp = 0;
225 pcb2->pcb_rsp = (register_t)td2->td_frame - sizeof(void *);
226 pcb2->pcb_rbx = (register_t)td2; /* fork_trampoline argument */
227 pcb2->pcb_rip = (register_t)fork_trampoline;
228 /*-
229 * pcb2->pcb_dr*: cloned above.
230 * pcb2->pcb_savefpu: cloned above.
231 * pcb2->pcb_flags: cloned above.
232 * pcb2->pcb_onfault: cloned above (always NULL here?).
233 * pcb2->pcb_[fg]sbase: cloned above
234 */
235
236 /* Setup to release spin count in fork_exit(). */
237 td2->td_md.md_spinlock_count = 1;
238 td2->td_md.md_saved_flags = PSL_KERNEL | PSL_I;
239 td2->td_md.md_invl_gen.gen = 0;
240
241 /* As an i386, do not copy io permission bitmap. */
242 pcb2->pcb_tssp = NULL;
243
244 /* New segment registers. */
245 set_pcb_flags(pcb2, PCB_FULL_IRET);
246
247 /* Copy the LDT, if necessary. */
248 mdp1 = &td1->td_proc->p_md;
249 mdp2 = &p2->p_md;
250 mtx_lock(&dt_lock);
251 if (mdp1->md_ldt != NULL) {
252 if (flags & RFMEM) {
253 mdp1->md_ldt->ldt_refcnt++;
254 mdp2->md_ldt = mdp1->md_ldt;
255 bcopy(&mdp1->md_ldt_sd, &mdp2->md_ldt_sd, sizeof(struct
256 system_segment_descriptor));
257 } else {
258 mdp2->md_ldt = NULL;
259 mdp2->md_ldt = user_ldt_alloc(p2, 0);
260 if (mdp2->md_ldt == NULL)
261 panic("could not copy LDT");
262 amd64_set_ldt_data(td2, 0, max_ldt_segment,
263 (struct user_segment_descriptor *)
264 mdp1->md_ldt->ldt_base);
265 }
266 } else
267 mdp2->md_ldt = NULL;
268 mtx_unlock(&dt_lock);
269
270 /*
271 * Now, cpu_switch() can schedule the new process.
272 * pcb_rsp is loaded pointing to the cpu_switch() stack frame
273 * containing the return address when exiting cpu_switch.
274 * This will normally be to fork_trampoline(), which will have
275 * %ebx loaded with the new proc's pointer. fork_trampoline()
276 * will set up a stack to call fork_return(p, frame); to complete
277 * the return to user-mode.
278 */
279 }
280
281 /*
282 * Intercept the return address from a freshly forked process that has NOT
283 * been scheduled yet.
284 *
285 * This is needed to make kernel threads stay in kernel mode.
286 */
287 void
288 cpu_fork_kthread_handler(struct thread *td, void (*func)(void *), void *arg)
289 {
290 /*
291 * Note that the trap frame follows the args, so the function
292 * is really called like this: func(arg, frame);
293 */
294 td->td_pcb->pcb_r12 = (long) func; /* function */
295 td->td_pcb->pcb_rbx = (long) arg; /* first arg */
296 }
297
298 void
299 cpu_exit(struct thread *td)
300 {
301
302 /*
303 * If this process has a custom LDT, release it.
304 */
305 mtx_lock(&dt_lock);
306 if (td->td_proc->p_md.md_ldt != 0)
307 user_ldt_free(td);
308 else
309 mtx_unlock(&dt_lock);
310 }
311
312 void
313 cpu_thread_exit(struct thread *td)
314 {
315 struct pcb *pcb;
316
317 critical_enter();
318 if (td == PCPU_GET(fpcurthread))
319 fpudrop();
320 critical_exit();
321
322 pcb = td->td_pcb;
323
324 /* Disable any hardware breakpoints. */
325 if (pcb->pcb_flags & PCB_DBREGS) {
326 reset_dbregs();
327 clear_pcb_flags(pcb, PCB_DBREGS);
328 }
329 }
330
331 void
332 cpu_thread_clean(struct thread *td)
333 {
334 struct pcb *pcb;
335
336 pcb = td->td_pcb;
337
338 /*
339 * Clean TSS/iomap
340 */
341 if (pcb->pcb_tssp != NULL) {
342 pmap_pti_remove_kva((vm_offset_t)pcb->pcb_tssp,
343 (vm_offset_t)pcb->pcb_tssp + ctob(IOPAGES + 1));
344 kmem_free(kernel_arena, (vm_offset_t)pcb->pcb_tssp,
345 ctob(IOPAGES + 1));
346 pcb->pcb_tssp = NULL;
347 }
348 }
349
350 void
351 cpu_thread_swapin(struct thread *td)
352 {
353 }
354
355 void
356 cpu_thread_swapout(struct thread *td)
357 {
358 }
359
360 void
361 cpu_thread_alloc(struct thread *td)
362 {
363 struct pcb *pcb;
364 struct xstate_hdr *xhdr;
365
366 td->td_pcb = pcb = get_pcb_td(td);
367 td->td_frame = (struct trapframe *)pcb - 1;
368 pcb->pcb_save = get_pcb_user_save_pcb(pcb);
369 if (use_xsave) {
370 xhdr = (struct xstate_hdr *)(pcb->pcb_save + 1);
371 bzero(xhdr, sizeof(*xhdr));
372 xhdr->xstate_bv = xsave_mask;
373 }
374 }
375
376 void
377 cpu_thread_free(struct thread *td)
378 {
379
380 cpu_thread_clean(td);
381 }
382
383 void
384 cpu_set_syscall_retval(struct thread *td, int error)
385 {
386
387 switch (error) {
388 case 0:
389 td->td_frame->tf_rax = td->td_retval[0];
390 td->td_frame->tf_rdx = td->td_retval[1];
391 td->td_frame->tf_rflags &= ~PSL_C;
392 break;
393
394 case ERESTART:
395 /*
396 * Reconstruct pc, we know that 'syscall' is 2 bytes,
397 * lcall $X,y is 7 bytes, int 0x80 is 2 bytes.
398 * We saved this in tf_err.
399 * %r10 (which was holding the value of %rcx) is restored
400 * for the next iteration.
401 * %r10 restore is only required for freebsd/amd64 processes,
402 * but shall be innocent for any ia32 ABI.
403 *
404 * Require full context restore to get the arguments
405 * in the registers reloaded at return to usermode.
406 */
407 td->td_frame->tf_rip -= td->td_frame->tf_err;
408 td->td_frame->tf_r10 = td->td_frame->tf_rcx;
409 set_pcb_flags(td->td_pcb, PCB_FULL_IRET);
410 break;
411
412 case EJUSTRETURN:
413 break;
414
415 default:
416 td->td_frame->tf_rax = SV_ABI_ERRNO(td->td_proc, error);
417 td->td_frame->tf_rflags |= PSL_C;
418 break;
419 }
420 }
421
422 /*
423 * Initialize machine state, mostly pcb and trap frame for a new
424 * thread, about to return to userspace. Put enough state in the new
425 * thread's PCB to get it to go back to the fork_return(), which
426 * finalizes the thread state and handles peculiarities of the first
427 * return to userspace for the new thread.
428 */
429 void
430 cpu_copy_thread(struct thread *td, struct thread *td0)
431 {
432 struct pcb *pcb2;
433
434 /* Point the pcb to the top of the stack. */
435 pcb2 = td->td_pcb;
436
437 /*
438 * Copy the upcall pcb. This loads kernel regs.
439 * Those not loaded individually below get their default
440 * values here.
441 */
442 bcopy(td0->td_pcb, pcb2, sizeof(*pcb2));
443 clear_pcb_flags(pcb2, PCB_FPUINITDONE | PCB_USERFPUINITDONE |
444 PCB_KERNFPU);
445 pcb2->pcb_save = get_pcb_user_save_pcb(pcb2);
446 bcopy(get_pcb_user_save_td(td0), pcb2->pcb_save,
447 cpu_max_ext_state_size);
448 set_pcb_flags(pcb2, PCB_FULL_IRET);
449
450 /*
451 * Create a new fresh stack for the new thread.
452 */
453 bcopy(td0->td_frame, td->td_frame, sizeof(struct trapframe));
454
455 /* If the current thread has the trap bit set (i.e. a debugger had
456 * single stepped the process to the system call), we need to clear
457 * the trap flag from the new frame. Otherwise, the new thread will
458 * receive a (likely unexpected) SIGTRAP when it executes the first
459 * instruction after returning to userland.
460 */
461 td->td_frame->tf_rflags &= ~PSL_T;
462
463 /*
464 * Set registers for trampoline to user mode. Leave space for the
465 * return address on stack. These are the kernel mode register values.
466 */
467 pcb2->pcb_r12 = (register_t)fork_return; /* trampoline arg */
468 pcb2->pcb_rbp = 0;
469 pcb2->pcb_rsp = (register_t)td->td_frame - sizeof(void *); /* trampoline arg */
470 pcb2->pcb_rbx = (register_t)td; /* trampoline arg */
471 pcb2->pcb_rip = (register_t)fork_trampoline;
472 /*
473 * If we didn't copy the pcb, we'd need to do the following registers:
474 * pcb2->pcb_dr*: cloned above.
475 * pcb2->pcb_savefpu: cloned above.
476 * pcb2->pcb_onfault: cloned above (always NULL here?).
477 * pcb2->pcb_[fg]sbase: cloned above
478 */
479
480 /* Setup to release spin count in fork_exit(). */
481 td->td_md.md_spinlock_count = 1;
482 td->td_md.md_saved_flags = PSL_KERNEL | PSL_I;
483 }
484
485 /*
486 * Set that machine state for performing an upcall that starts
487 * the entry function with the given argument.
488 */
489 void
490 cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg,
491 stack_t *stack)
492 {
493
494 /*
495 * Do any extra cleaning that needs to be done.
496 * The thread may have optional components
497 * that are not present in a fresh thread.
498 * This may be a recycled thread so make it look
499 * as though it's newly allocated.
500 */
501 cpu_thread_clean(td);
502
503 #ifdef COMPAT_FREEBSD32
504 if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
505 /*
506 * Set the trap frame to point at the beginning of the entry
507 * function.
508 */
509 td->td_frame->tf_rbp = 0;
510 td->td_frame->tf_rsp =
511 (((uintptr_t)stack->ss_sp + stack->ss_size - 4) & ~0x0f) - 4;
512 td->td_frame->tf_rip = (uintptr_t)entry;
513
514 /* Pass the argument to the entry point. */
515 suword32((void *)(td->td_frame->tf_rsp + sizeof(int32_t)),
516 (uint32_t)(uintptr_t)arg);
517
518 return;
519 }
520 #endif
521
522 /*
523 * Set the trap frame to point at the beginning of the uts
524 * function.
525 */
526 td->td_frame->tf_rbp = 0;
527 td->td_frame->tf_rsp =
528 ((register_t)stack->ss_sp + stack->ss_size) & ~0x0f;
529 td->td_frame->tf_rsp -= 8;
530 td->td_frame->tf_rip = (register_t)entry;
531 td->td_frame->tf_ds = _udatasel;
532 td->td_frame->tf_es = _udatasel;
533 td->td_frame->tf_fs = _ufssel;
534 td->td_frame->tf_gs = _ugssel;
535 td->td_frame->tf_flags = TF_HASSEGS;
536
537 /* Pass the argument to the entry point. */
538 td->td_frame->tf_rdi = (register_t)arg;
539 }
540
541 int
542 cpu_set_user_tls(struct thread *td, void *tls_base)
543 {
544 struct pcb *pcb;
545
546 if ((u_int64_t)tls_base >= VM_MAXUSER_ADDRESS)
547 return (EINVAL);
548
549 pcb = td->td_pcb;
550 set_pcb_flags(pcb, PCB_FULL_IRET);
551 #ifdef COMPAT_FREEBSD32
552 if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
553 pcb->pcb_gsbase = (register_t)tls_base;
554 return (0);
555 }
556 #endif
557 pcb->pcb_fsbase = (register_t)tls_base;
558 return (0);
559 }
560
561 #ifdef SMP
562 static void
563 cpu_reset_proxy()
564 {
565 cpuset_t tcrp;
566
567 cpu_reset_proxy_active = 1;
568 while (cpu_reset_proxy_active == 1)
569 ia32_pause(); /* Wait for other cpu to see that we've started */
570
571 CPU_SETOF(cpu_reset_proxyid, &tcrp);
572 stop_cpus(tcrp);
573 printf("cpu_reset_proxy: Stopped CPU %d\n", cpu_reset_proxyid);
574 DELAY(1000000);
575 cpu_reset_real();
576 }
577 #endif
578
579 void
580 cpu_reset()
581 {
582 #ifdef SMP
583 cpuset_t map;
584 u_int cnt;
585
586 if (smp_started) {
587 map = all_cpus;
588 CPU_CLR(PCPU_GET(cpuid), &map);
589 CPU_NAND(&map, &stopped_cpus);
590 if (!CPU_EMPTY(&map)) {
591 printf("cpu_reset: Stopping other CPUs\n");
592 stop_cpus(map);
593 }
594
595 if (PCPU_GET(cpuid) != 0) {
596 cpu_reset_proxyid = PCPU_GET(cpuid);
597 cpustop_restartfunc = cpu_reset_proxy;
598 cpu_reset_proxy_active = 0;
599 printf("cpu_reset: Restarting BSP\n");
600
601 /* Restart CPU #0. */
602 CPU_SETOF(0, &started_cpus);
603 wmb();
604
605 cnt = 0;
606 while (cpu_reset_proxy_active == 0 && cnt < 10000000) {
607 ia32_pause();
608 cnt++; /* Wait for BSP to announce restart */
609 }
610 if (cpu_reset_proxy_active == 0)
611 printf("cpu_reset: Failed to restart BSP\n");
612 enable_intr();
613 cpu_reset_proxy_active = 2;
614
615 while (1)
616 ia32_pause();
617 /* NOTREACHED */
618 }
619
620 DELAY(1000000);
621 }
622 #endif
623 cpu_reset_real();
624 /* NOTREACHED */
625 }
626
627 static void
628 cpu_reset_real()
629 {
630 struct region_descriptor null_idt;
631 int b;
632
633 disable_intr();
634
635 /*
636 * Attempt to do a CPU reset via the keyboard controller,
637 * do not turn off GateA20, as any machine that fails
638 * to do the reset here would then end up in no man's land.
639 */
640 outb(IO_KBD + 4, 0xFE);
641 DELAY(500000); /* wait 0.5 sec to see if that did it */
642
643 /*
644 * Attempt to force a reset via the Reset Control register at
645 * I/O port 0xcf9. Bit 2 forces a system reset when it
646 * transitions from 0 to 1. Bit 1 selects the type of reset
647 * to attempt: 0 selects a "soft" reset, and 1 selects a
648 * "hard" reset. We try a "hard" reset. The first write sets
649 * bit 1 to select a "hard" reset and clears bit 2. The
650 * second write forces a 0 -> 1 transition in bit 2 to trigger
651 * a reset.
652 */
653 outb(0xcf9, 0x2);
654 outb(0xcf9, 0x6);
655 DELAY(500000); /* wait 0.5 sec to see if that did it */
656
657 /*
658 * Attempt to force a reset via the Fast A20 and Init register
659 * at I/O port 0x92. Bit 1 serves as an alternate A20 gate.
660 * Bit 0 asserts INIT# when set to 1. We are careful to only
661 * preserve bit 1 while setting bit 0. We also must clear bit
662 * 0 before setting it if it isn't already clear.
663 */
664 b = inb(0x92);
665 if (b != 0xff) {
666 if ((b & 0x1) != 0)
667 outb(0x92, b & 0xfe);
668 outb(0x92, b | 0x1);
669 DELAY(500000); /* wait 0.5 sec to see if that did it */
670 }
671
672 printf("No known reset method worked, attempting CPU shutdown\n");
673 DELAY(1000000); /* wait 1 sec for printf to complete */
674
675 /* Wipe the IDT. */
676 null_idt.rd_limit = 0;
677 null_idt.rd_base = 0;
678 lidt(&null_idt);
679
680 /* "good night, sweet prince .... <THUNK!>" */
681 breakpoint();
682
683 /* NOTREACHED */
684 while(1);
685 }
686
687 /*
688 * Software interrupt handler for queued VM system processing.
689 */
690 void
691 swi_vm(void *dummy)
692 {
693 if (busdma_swi_pending != 0)
694 busdma_swi();
695 }
696
697 /*
698 * Tell whether this address is in some physical memory region.
699 * Currently used by the kernel coredump code in order to avoid
700 * dumping the ``ISA memory hole'' which could cause indefinite hangs,
701 * or other unpredictable behaviour.
702 */
703
704 int
705 is_physical_memory(vm_paddr_t addr)
706 {
707
708 #ifdef DEV_ISA
709 /* The ISA ``memory hole''. */
710 if (addr >= 0xa0000 && addr < 0x100000)
711 return 0;
712 #endif
713
714 /*
715 * stuff other tests for known memory-mapped devices (PCI?)
716 * here
717 */
718
719 return 1;
720 }
Cache object: 0a60c208e5720f36457ca3a86337bfff
|