2 * Copyright (c) 1992 Terrence R. Lambert.
3 * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
6 * This code is derived from software contributed to Berkeley by
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include "opt_atalk.h"
44 #include "opt_compat.h"
50 #include "opt_kstack_pages.h"
51 #include "opt_maxmem.h"
53 #include "opt_perfmon.h"
54 #include "opt_kdtrace.h"
56 #include <sys/param.h>
58 #include <sys/systm.h>
62 #include <sys/callout.h>
65 #include <sys/eventhandler.h>
67 #include <sys/imgact.h>
69 #include <sys/kernel.h>
71 #include <sys/linker.h>
73 #include <sys/malloc.h>
74 #include <sys/memrange.h>
75 #include <sys/msgbuf.h>
76 #include <sys/mutex.h>
78 #include <sys/ptrace.h>
79 #include <sys/reboot.h>
80 #include <sys/sched.h>
81 #include <sys/signalvar.h>
82 #include <sys/syscallsubr.h>
83 #include <sys/sysctl.h>
84 #include <sys/sysent.h>
85 #include <sys/sysproto.h>
86 #include <sys/ucontext.h>
87 #include <sys/vmmeter.h>
90 #include <vm/vm_extern.h>
91 #include <vm/vm_kern.h>
92 #include <vm/vm_page.h>
93 #include <vm/vm_map.h>
94 #include <vm/vm_object.h>
95 #include <vm/vm_pager.h>
96 #include <vm/vm_param.h>
100 #error KDB must be enabled in order for DDB to work!
103 #include <ddb/db_sym.h>
106 #include <pc98/pc98/pc98_machdep.h>
108 #include <net/netisr.h>
110 #include <machine/bootinfo.h>
111 #include <machine/clock.h>
112 #include <machine/cpu.h>
113 #include <machine/cputypes.h>
114 #include <machine/intr_machdep.h>
115 #include <machine/mca.h>
116 #include <machine/md_var.h>
117 #include <machine/pc/bios.h>
118 #include <machine/pcb.h>
119 #include <machine/pcb_ext.h>
120 #include <machine/proc.h>
121 #include <machine/reg.h>
122 #include <machine/sigframe.h>
123 #include <machine/specialreg.h>
124 #include <machine/vm86.h>
126 #include <machine/perfmon.h>
129 #include <machine/smp.h>
133 #include <i386/isa/icu.h>
136 /* Sanity check for __curthread() */
137 CTASSERT(offsetof(struct pcpu, pc_curthread) == 0);
139 extern void init386(int first);
140 extern void dblfault_handler(void);
142 extern void printcpuinfo(void); /* XXX header file */
143 extern void finishidentcpu(void);
144 extern void panicifcpuunsupported(void);
145 extern void initializecpu(void);
147 #define CS_SECURE(cs) (ISPL(cs) == SEL_UPL)
148 #define EFL_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
150 #if !defined(CPU_DISABLE_SSE) && defined(I686_CPU)
151 #define CPU_ENABLE_SSE
154 static void cpu_startup(void *);
155 static void fpstate_drop(struct thread *td);
156 static void get_fpcontext(struct thread *td, mcontext_t *mcp);
157 static int set_fpcontext(struct thread *td, const mcontext_t *mcp);
158 #ifdef CPU_ENABLE_SSE
159 static void set_fpregs_xmm(struct save87 *, struct savexmm *);
160 static void fill_fpregs_xmm(struct savexmm *, struct save87 *);
161 #endif /* CPU_ENABLE_SSE */
162 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
164 int need_pre_dma_flush; /* If 1, use wbinvd befor DMA transfer. */
165 int need_post_dma_flush; /* If 1, use invd after DMA transfer. */
168 extern vm_offset_t ksym_start, ksym_end;
171 int _udatasel, _ucodesel;
174 static int ispc98 = 1;
175 SYSCTL_INT(_machdep, OID_AUTO, ispc98, CTLFLAG_RD, &ispc98, 0, "");
180 static void osendsig(sig_t catcher, ksiginfo_t *, sigset_t *mask);
182 #ifdef COMPAT_FREEBSD4
183 static void freebsd4_sendsig(sig_t catcher, ksiginfo_t *, sigset_t *mask);
190 * The number of PHYSMAP entries must be one less than the number of
191 * PHYSSEG entries because the PHYSMAP entry that spans the largest
192 * physical address that is accessible by ISA DMA is split into two
195 #define PHYSMAP_SIZE (2 * (VM_PHYSSEG_MAX - 1))
197 vm_paddr_t phys_avail[PHYSMAP_SIZE + 2];
198 vm_paddr_t dump_avail[PHYSMAP_SIZE + 2];
200 /* must be 2 less so 0 0 can signal end of chunks */
201 #define PHYS_AVAIL_ARRAY_END ((sizeof(phys_avail) / sizeof(phys_avail[0])) - 2)
202 #define DUMP_AVAIL_ARRAY_END ((sizeof(dump_avail) / sizeof(dump_avail[0])) - 2)
204 struct kva_md_info kmi;
206 static struct trapframe proc0_tf;
207 struct pcpu __pcpu[MAXCPU];
211 struct mem_range_softc mem_range_softc;
220 * Good {morning,afternoon,evening,night}.
224 panicifcpuunsupported();
231 * Display physical memory.
233 memsize = ptoa((uintmax_t)Maxmem);
234 printf("real memory = %ju (%ju MB)\n", memsize, memsize >> 20);
237 * Display any holes after the first chunk of extended memory.
242 printf("Physical memory chunk(s):\n");
243 for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
246 size = phys_avail[indx + 1] - phys_avail[indx];
248 "0x%016jx - 0x%016jx, %ju bytes (%ju pages)\n",
249 (uintmax_t)phys_avail[indx],
250 (uintmax_t)phys_avail[indx + 1] - 1,
251 (uintmax_t)size, (uintmax_t)size / PAGE_SIZE);
255 vm_ksubmap_init(&kmi);
257 printf("avail memory = %ju (%ju MB)\n",
258 ptoa((uintmax_t)cnt.v_free_count),
259 ptoa((uintmax_t)cnt.v_free_count) / 1048576);
262 * Set up buffers, so they can be used to read disk labels.
265 vm_pager_bufferinit();
270 * Send an interrupt to process.
272 * Stack is set up to allow sigcode stored
273 * at top to call routine, followed by kcall
274 * to sigreturn routine below. After sigreturn
275 * resets the signal mask, the stack, and the
276 * frame pointer, it returns to the user
281 osendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
283 struct osigframe sf, *fp;
287 struct trapframe *regs;
293 PROC_LOCK_ASSERT(p, MA_OWNED);
294 sig = ksi->ksi_signo;
296 mtx_assert(&psp->ps_mtx, MA_OWNED);
298 oonstack = sigonstack(regs->tf_esp);
300 /* Allocate space for the signal handler context. */
301 if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
302 SIGISMEMBER(psp->ps_sigonstack, sig)) {
303 fp = (struct osigframe *)(td->td_sigstk.ss_sp +
304 td->td_sigstk.ss_size - sizeof(struct osigframe));
305 #if defined(COMPAT_43)
306 td->td_sigstk.ss_flags |= SS_ONSTACK;
309 fp = (struct osigframe *)regs->tf_esp - 1;
311 /* Translate the signal if appropriate. */
312 if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
313 sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
315 /* Build the argument list for the signal handler. */
317 sf.sf_scp = (register_t)&fp->sf_siginfo.si_sc;
318 bzero(&sf.sf_siginfo, sizeof(sf.sf_siginfo));
319 if (SIGISMEMBER(psp->ps_siginfo, sig)) {
320 /* Signal handler installed with SA_SIGINFO. */
321 sf.sf_arg2 = (register_t)&fp->sf_siginfo;
322 sf.sf_siginfo.si_signo = sig;
323 sf.sf_siginfo.si_code = ksi->ksi_code;
324 sf.sf_ahu.sf_action = (__osiginfohandler_t *)catcher;
327 /* Old FreeBSD-style arguments. */
328 sf.sf_arg2 = ksi->ksi_code;
329 sf.sf_addr = (register_t)ksi->ksi_addr;
330 sf.sf_ahu.sf_handler = catcher;
332 mtx_unlock(&psp->ps_mtx);
335 /* Save most if not all of trap frame. */
336 sf.sf_siginfo.si_sc.sc_eax = regs->tf_eax;
337 sf.sf_siginfo.si_sc.sc_ebx = regs->tf_ebx;
338 sf.sf_siginfo.si_sc.sc_ecx = regs->tf_ecx;
339 sf.sf_siginfo.si_sc.sc_edx = regs->tf_edx;
340 sf.sf_siginfo.si_sc.sc_esi = regs->tf_esi;
341 sf.sf_siginfo.si_sc.sc_edi = regs->tf_edi;
342 sf.sf_siginfo.si_sc.sc_cs = regs->tf_cs;
343 sf.sf_siginfo.si_sc.sc_ds = regs->tf_ds;
344 sf.sf_siginfo.si_sc.sc_ss = regs->tf_ss;
345 sf.sf_siginfo.si_sc.sc_es = regs->tf_es;
346 sf.sf_siginfo.si_sc.sc_fs = regs->tf_fs;
347 sf.sf_siginfo.si_sc.sc_gs = rgs();
348 sf.sf_siginfo.si_sc.sc_isp = regs->tf_isp;
350 /* Build the signal context to be used by osigreturn(). */
351 sf.sf_siginfo.si_sc.sc_onstack = (oonstack) ? 1 : 0;
352 SIG2OSIG(*mask, sf.sf_siginfo.si_sc.sc_mask);
353 sf.sf_siginfo.si_sc.sc_sp = regs->tf_esp;
354 sf.sf_siginfo.si_sc.sc_fp = regs->tf_ebp;
355 sf.sf_siginfo.si_sc.sc_pc = regs->tf_eip;
356 sf.sf_siginfo.si_sc.sc_ps = regs->tf_eflags;
357 sf.sf_siginfo.si_sc.sc_trapno = regs->tf_trapno;
358 sf.sf_siginfo.si_sc.sc_err = regs->tf_err;
361 * If we're a vm86 process, we want to save the segment registers.
362 * We also change eflags to be our emulated eflags, not the actual
365 if (regs->tf_eflags & PSL_VM) {
366 /* XXX confusing names: `tf' isn't a trapframe; `regs' is. */
367 struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
368 struct vm86_kernel *vm86 = &td->td_pcb->pcb_ext->ext_vm86;
370 sf.sf_siginfo.si_sc.sc_gs = tf->tf_vm86_gs;
371 sf.sf_siginfo.si_sc.sc_fs = tf->tf_vm86_fs;
372 sf.sf_siginfo.si_sc.sc_es = tf->tf_vm86_es;
373 sf.sf_siginfo.si_sc.sc_ds = tf->tf_vm86_ds;
375 if (vm86->vm86_has_vme == 0)
376 sf.sf_siginfo.si_sc.sc_ps =
377 (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) |
378 (vm86->vm86_eflags & (PSL_VIF | PSL_VIP));
380 /* See sendsig() for comments. */
381 tf->tf_eflags &= ~(PSL_VM | PSL_NT | PSL_VIF | PSL_VIP);
385 * Copy the sigframe out to the user's stack.
387 if (copyout(&sf, fp, sizeof(*fp)) != 0) {
389 printf("process %ld has trashed its stack\n", (long)p->p_pid);
395 regs->tf_esp = (int)fp;
396 regs->tf_eip = PS_STRINGS - szosigcode;
397 regs->tf_eflags &= ~(PSL_T | PSL_D);
398 regs->tf_cs = _ucodesel;
399 regs->tf_ds = _udatasel;
400 regs->tf_es = _udatasel;
401 regs->tf_fs = _udatasel;
403 regs->tf_ss = _udatasel;
405 mtx_lock(&psp->ps_mtx);
407 #endif /* COMPAT_43 */
409 #ifdef COMPAT_FREEBSD4
411 freebsd4_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
413 struct sigframe4 sf, *sfp;
417 struct trapframe *regs;
423 PROC_LOCK_ASSERT(p, MA_OWNED);
424 sig = ksi->ksi_signo;
426 mtx_assert(&psp->ps_mtx, MA_OWNED);
428 oonstack = sigonstack(regs->tf_esp);
430 /* Save user context. */
431 bzero(&sf, sizeof(sf));
432 sf.sf_uc.uc_sigmask = *mask;
433 sf.sf_uc.uc_stack = td->td_sigstk;
434 sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
435 ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
436 sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
437 sf.sf_uc.uc_mcontext.mc_gs = rgs();
438 bcopy(regs, &sf.sf_uc.uc_mcontext.mc_fs, sizeof(*regs));
439 bzero(sf.sf_uc.uc_mcontext.mc_fpregs,
440 sizeof(sf.sf_uc.uc_mcontext.mc_fpregs));
441 bzero(sf.sf_uc.uc_mcontext.__spare__,
442 sizeof(sf.sf_uc.uc_mcontext.__spare__));
443 bzero(sf.sf_uc.__spare__, sizeof(sf.sf_uc.__spare__));
445 /* Allocate space for the signal handler context. */
446 if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
447 SIGISMEMBER(psp->ps_sigonstack, sig)) {
448 sfp = (struct sigframe4 *)(td->td_sigstk.ss_sp +
449 td->td_sigstk.ss_size - sizeof(struct sigframe4));
450 #if defined(COMPAT_43)
451 td->td_sigstk.ss_flags |= SS_ONSTACK;
454 sfp = (struct sigframe4 *)regs->tf_esp - 1;
456 /* Translate the signal if appropriate. */
457 if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
458 sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
460 /* Build the argument list for the signal handler. */
462 sf.sf_ucontext = (register_t)&sfp->sf_uc;
463 bzero(&sf.sf_si, sizeof(sf.sf_si));
464 if (SIGISMEMBER(psp->ps_siginfo, sig)) {
465 /* Signal handler installed with SA_SIGINFO. */
466 sf.sf_siginfo = (register_t)&sfp->sf_si;
467 sf.sf_ahu.sf_action = (__siginfohandler_t *)catcher;
469 /* Fill in POSIX parts */
470 sf.sf_si.si_signo = sig;
471 sf.sf_si.si_code = ksi->ksi_code;
472 sf.sf_si.si_addr = ksi->ksi_addr;
474 /* Old FreeBSD-style arguments. */
475 sf.sf_siginfo = ksi->ksi_code;
476 sf.sf_addr = (register_t)ksi->ksi_addr;
477 sf.sf_ahu.sf_handler = catcher;
479 mtx_unlock(&psp->ps_mtx);
483 * If we're a vm86 process, we want to save the segment registers.
484 * We also change eflags to be our emulated eflags, not the actual
487 if (regs->tf_eflags & PSL_VM) {
488 struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
489 struct vm86_kernel *vm86 = &td->td_pcb->pcb_ext->ext_vm86;
491 sf.sf_uc.uc_mcontext.mc_gs = tf->tf_vm86_gs;
492 sf.sf_uc.uc_mcontext.mc_fs = tf->tf_vm86_fs;
493 sf.sf_uc.uc_mcontext.mc_es = tf->tf_vm86_es;
494 sf.sf_uc.uc_mcontext.mc_ds = tf->tf_vm86_ds;
496 if (vm86->vm86_has_vme == 0)
497 sf.sf_uc.uc_mcontext.mc_eflags =
498 (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) |
499 (vm86->vm86_eflags & (PSL_VIF | PSL_VIP));
502 * Clear PSL_NT to inhibit T_TSSFLT faults on return from
503 * syscalls made by the signal handler. This just avoids
504 * wasting time for our lazy fixup of such faults. PSL_NT
505 * does nothing in vm86 mode, but vm86 programs can set it
506 * almost legitimately in probes for old cpu types.
508 tf->tf_eflags &= ~(PSL_VM | PSL_NT | PSL_VIF | PSL_VIP);
512 * Copy the sigframe out to the user's stack.
514 if (copyout(&sf, sfp, sizeof(*sfp)) != 0) {
516 printf("process %ld has trashed its stack\n", (long)p->p_pid);
522 regs->tf_esp = (int)sfp;
523 regs->tf_eip = PS_STRINGS - szfreebsd4_sigcode;
524 regs->tf_eflags &= ~(PSL_T | PSL_D);
525 regs->tf_cs = _ucodesel;
526 regs->tf_ds = _udatasel;
527 regs->tf_es = _udatasel;
528 regs->tf_fs = _udatasel;
529 regs->tf_ss = _udatasel;
531 mtx_lock(&psp->ps_mtx);
533 #endif /* COMPAT_FREEBSD4 */
536 sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
538 struct sigframe sf, *sfp;
543 struct trapframe *regs;
544 struct segment_descriptor *sdp;
550 PROC_LOCK_ASSERT(p, MA_OWNED);
551 sig = ksi->ksi_signo;
553 mtx_assert(&psp->ps_mtx, MA_OWNED);
554 #ifdef COMPAT_FREEBSD4
555 if (SIGISMEMBER(psp->ps_freebsd4, sig)) {
556 freebsd4_sendsig(catcher, ksi, mask);
561 if (SIGISMEMBER(psp->ps_osigset, sig)) {
562 osendsig(catcher, ksi, mask);
567 oonstack = sigonstack(regs->tf_esp);
569 /* Save user context. */
570 bzero(&sf, sizeof(sf));
571 sf.sf_uc.uc_sigmask = *mask;
572 sf.sf_uc.uc_stack = td->td_sigstk;
573 sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
574 ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
575 sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
576 sf.sf_uc.uc_mcontext.mc_gs = rgs();
577 bcopy(regs, &sf.sf_uc.uc_mcontext.mc_fs, sizeof(*regs));
578 sf.sf_uc.uc_mcontext.mc_len = sizeof(sf.sf_uc.uc_mcontext); /* magic */
579 get_fpcontext(td, &sf.sf_uc.uc_mcontext);
582 * Unconditionally fill the fsbase and gsbase into the mcontext.
584 sdp = &td->td_pcb->pcb_fsd;
585 sf.sf_uc.uc_mcontext.mc_fsbase = sdp->sd_hibase << 24 |
587 sdp = &td->td_pcb->pcb_gsd;
588 sf.sf_uc.uc_mcontext.mc_gsbase = sdp->sd_hibase << 24 |
590 sf.sf_uc.uc_mcontext.mc_flags = 0;
591 bzero(sf.sf_uc.uc_mcontext.mc_spare2,
592 sizeof(sf.sf_uc.uc_mcontext.mc_spare2));
593 bzero(sf.sf_uc.__spare__, sizeof(sf.sf_uc.__spare__));
595 /* Allocate space for the signal handler context. */
596 if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
597 SIGISMEMBER(psp->ps_sigonstack, sig)) {
598 sp = td->td_sigstk.ss_sp +
599 td->td_sigstk.ss_size - sizeof(struct sigframe);
600 #if defined(COMPAT_43)
601 td->td_sigstk.ss_flags |= SS_ONSTACK;
604 sp = (char *)regs->tf_esp - sizeof(struct sigframe);
605 /* Align to 16 bytes. */
606 sfp = (struct sigframe *)((unsigned int)sp & ~0xF);
608 /* Translate the signal if appropriate. */
609 if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
610 sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
612 /* Build the argument list for the signal handler. */
614 sf.sf_ucontext = (register_t)&sfp->sf_uc;
615 bzero(&sf.sf_si, sizeof(sf.sf_si));
616 if (SIGISMEMBER(psp->ps_siginfo, sig)) {
617 /* Signal handler installed with SA_SIGINFO. */
618 sf.sf_siginfo = (register_t)&sfp->sf_si;
619 sf.sf_ahu.sf_action = (__siginfohandler_t *)catcher;
621 /* Fill in POSIX parts */
622 sf.sf_si = ksi->ksi_info;
623 sf.sf_si.si_signo = sig; /* maybe a translated signal */
625 /* Old FreeBSD-style arguments. */
626 sf.sf_siginfo = ksi->ksi_code;
627 sf.sf_addr = (register_t)ksi->ksi_addr;
628 sf.sf_ahu.sf_handler = catcher;
630 mtx_unlock(&psp->ps_mtx);
634 * If we're a vm86 process, we want to save the segment registers.
635 * We also change eflags to be our emulated eflags, not the actual
638 if (regs->tf_eflags & PSL_VM) {
639 struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
640 struct vm86_kernel *vm86 = &td->td_pcb->pcb_ext->ext_vm86;
642 sf.sf_uc.uc_mcontext.mc_gs = tf->tf_vm86_gs;
643 sf.sf_uc.uc_mcontext.mc_fs = tf->tf_vm86_fs;
644 sf.sf_uc.uc_mcontext.mc_es = tf->tf_vm86_es;
645 sf.sf_uc.uc_mcontext.mc_ds = tf->tf_vm86_ds;
647 if (vm86->vm86_has_vme == 0)
648 sf.sf_uc.uc_mcontext.mc_eflags =
649 (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) |
650 (vm86->vm86_eflags & (PSL_VIF | PSL_VIP));
653 * Clear PSL_NT to inhibit T_TSSFLT faults on return from
654 * syscalls made by the signal handler. This just avoids
655 * wasting time for our lazy fixup of such faults. PSL_NT
656 * does nothing in vm86 mode, but vm86 programs can set it
657 * almost legitimately in probes for old cpu types.
659 tf->tf_eflags &= ~(PSL_VM | PSL_NT | PSL_VIF | PSL_VIP);
663 * Copy the sigframe out to the user's stack.
665 if (copyout(&sf, sfp, sizeof(*sfp)) != 0) {
667 printf("process %ld has trashed its stack\n", (long)p->p_pid);
673 regs->tf_esp = (int)sfp;
674 regs->tf_eip = PS_STRINGS - *(p->p_sysent->sv_szsigcode);
675 regs->tf_eflags &= ~(PSL_T | PSL_D);
676 regs->tf_cs = _ucodesel;
677 regs->tf_ds = _udatasel;
678 regs->tf_es = _udatasel;
679 regs->tf_fs = _udatasel;
680 regs->tf_ss = _udatasel;
682 mtx_lock(&psp->ps_mtx);
686 * System call to cleanup state after a signal
687 * has been taken. Reset signal mask and
688 * stack state from context left by sendsig (above).
689 * Return to previous pc and psl as specified by
690 * context left by sendsig. Check carefully to
691 * make sure that the user has not modified the
692 * state to gain improper privileges.
700 struct osigreturn_args /* {
701 struct osigcontext *sigcntxp;
704 struct osigcontext sc;
705 struct trapframe *regs;
706 struct osigcontext *scp;
711 error = copyin(uap->sigcntxp, &sc, sizeof(sc));
716 if (eflags & PSL_VM) {
717 struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
718 struct vm86_kernel *vm86;
721 * if pcb_ext == 0 or vm86_inited == 0, the user hasn't
722 * set up the vm86 area, and we can't enter vm86 mode.
724 if (td->td_pcb->pcb_ext == 0)
726 vm86 = &td->td_pcb->pcb_ext->ext_vm86;
727 if (vm86->vm86_inited == 0)
730 /* Go back to user mode if both flags are set. */
731 if ((eflags & PSL_VIP) && (eflags & PSL_VIF)) {
732 ksiginfo_init_trap(&ksi);
733 ksi.ksi_signo = SIGBUS;
734 ksi.ksi_code = BUS_OBJERR;
735 ksi.ksi_addr = (void *)regs->tf_eip;
736 trapsignal(td, &ksi);
739 if (vm86->vm86_has_vme) {
740 eflags = (tf->tf_eflags & ~VME_USERCHANGE) |
741 (eflags & VME_USERCHANGE) | PSL_VM;
743 vm86->vm86_eflags = eflags; /* save VIF, VIP */
744 eflags = (tf->tf_eflags & ~VM_USERCHANGE) |
745 (eflags & VM_USERCHANGE) | PSL_VM;
747 tf->tf_vm86_ds = scp->sc_ds;
748 tf->tf_vm86_es = scp->sc_es;
749 tf->tf_vm86_fs = scp->sc_fs;
750 tf->tf_vm86_gs = scp->sc_gs;
751 tf->tf_ds = _udatasel;
752 tf->tf_es = _udatasel;
753 tf->tf_fs = _udatasel;
756 * Don't allow users to change privileged or reserved flags.
759 * XXX do allow users to change the privileged flag PSL_RF.
760 * The cpu sets PSL_RF in tf_eflags for faults. Debuggers
761 * should sometimes set it there too. tf_eflags is kept in
762 * the signal context during signal handling and there is no
763 * other place to remember it, so the PSL_RF bit may be
764 * corrupted by the signal handler without us knowing.
765 * Corruption of the PSL_RF bit at worst causes one more or
766 * one less debugger trap, so allowing it is fairly harmless.
768 if (!EFL_SECURE(eflags & ~PSL_RF, regs->tf_eflags & ~PSL_RF)) {
773 * Don't allow users to load a valid privileged %cs. Let the
774 * hardware check for invalid selectors, excess privilege in
775 * other selectors, invalid %eip's and invalid %esp's.
777 if (!CS_SECURE(scp->sc_cs)) {
778 ksiginfo_init_trap(&ksi);
779 ksi.ksi_signo = SIGBUS;
780 ksi.ksi_code = BUS_OBJERR;
781 ksi.ksi_trapno = T_PROTFLT;
782 ksi.ksi_addr = (void *)regs->tf_eip;
783 trapsignal(td, &ksi);
786 regs->tf_ds = scp->sc_ds;
787 regs->tf_es = scp->sc_es;
788 regs->tf_fs = scp->sc_fs;
791 /* Restore remaining registers. */
792 regs->tf_eax = scp->sc_eax;
793 regs->tf_ebx = scp->sc_ebx;
794 regs->tf_ecx = scp->sc_ecx;
795 regs->tf_edx = scp->sc_edx;
796 regs->tf_esi = scp->sc_esi;
797 regs->tf_edi = scp->sc_edi;
798 regs->tf_cs = scp->sc_cs;
799 regs->tf_ss = scp->sc_ss;
800 regs->tf_isp = scp->sc_isp;
801 regs->tf_ebp = scp->sc_fp;
802 regs->tf_esp = scp->sc_sp;
803 regs->tf_eip = scp->sc_pc;
804 regs->tf_eflags = eflags;
806 #if defined(COMPAT_43)
807 if (scp->sc_onstack & 1)
808 td->td_sigstk.ss_flags |= SS_ONSTACK;
810 td->td_sigstk.ss_flags &= ~SS_ONSTACK;
812 kern_sigprocmask(td, SIG_SETMASK, (sigset_t *)&scp->sc_mask, NULL,
814 return (EJUSTRETURN);
816 #endif /* COMPAT_43 */
818 #ifdef COMPAT_FREEBSD4
823 freebsd4_sigreturn(td, uap)
825 struct freebsd4_sigreturn_args /* {
826 const ucontext4 *sigcntxp;
830 struct trapframe *regs;
831 struct ucontext4 *ucp;
832 int cs, eflags, error;
835 error = copyin(uap->sigcntxp, &uc, sizeof(uc));
840 eflags = ucp->uc_mcontext.mc_eflags;
841 if (eflags & PSL_VM) {
842 struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
843 struct vm86_kernel *vm86;
846 * if pcb_ext == 0 or vm86_inited == 0, the user hasn't
847 * set up the vm86 area, and we can't enter vm86 mode.
849 if (td->td_pcb->pcb_ext == 0)
851 vm86 = &td->td_pcb->pcb_ext->ext_vm86;
852 if (vm86->vm86_inited == 0)
855 /* Go back to user mode if both flags are set. */
856 if ((eflags & PSL_VIP) && (eflags & PSL_VIF)) {
857 ksiginfo_init_trap(&ksi);
858 ksi.ksi_signo = SIGBUS;
859 ksi.ksi_code = BUS_OBJERR;
860 ksi.ksi_addr = (void *)regs->tf_eip;
861 trapsignal(td, &ksi);
863 if (vm86->vm86_has_vme) {
864 eflags = (tf->tf_eflags & ~VME_USERCHANGE) |
865 (eflags & VME_USERCHANGE) | PSL_VM;
867 vm86->vm86_eflags = eflags; /* save VIF, VIP */
868 eflags = (tf->tf_eflags & ~VM_USERCHANGE) |
869 (eflags & VM_USERCHANGE) | PSL_VM;
871 bcopy(&ucp->uc_mcontext.mc_fs, tf, sizeof(struct trapframe));
872 tf->tf_eflags = eflags;
873 tf->tf_vm86_ds = tf->tf_ds;
874 tf->tf_vm86_es = tf->tf_es;
875 tf->tf_vm86_fs = tf->tf_fs;
876 tf->tf_vm86_gs = ucp->uc_mcontext.mc_gs;
877 tf->tf_ds = _udatasel;
878 tf->tf_es = _udatasel;
879 tf->tf_fs = _udatasel;
882 * Don't allow users to change privileged or reserved flags.
885 * XXX do allow users to change the privileged flag PSL_RF.
886 * The cpu sets PSL_RF in tf_eflags for faults. Debuggers
887 * should sometimes set it there too. tf_eflags is kept in
888 * the signal context during signal handling and there is no
889 * other place to remember it, so the PSL_RF bit may be
890 * corrupted by the signal handler without us knowing.
891 * Corruption of the PSL_RF bit at worst causes one more or
892 * one less debugger trap, so allowing it is fairly harmless.
894 if (!EFL_SECURE(eflags & ~PSL_RF, regs->tf_eflags & ~PSL_RF)) {
895 uprintf("pid %d (%s): freebsd4_sigreturn eflags = 0x%x\n",
896 td->td_proc->p_pid, td->td_name, eflags);
901 * Don't allow users to load a valid privileged %cs. Let the
902 * hardware check for invalid selectors, excess privilege in
903 * other selectors, invalid %eip's and invalid %esp's.
905 cs = ucp->uc_mcontext.mc_cs;
906 if (!CS_SECURE(cs)) {
907 uprintf("pid %d (%s): freebsd4_sigreturn cs = 0x%x\n",
908 td->td_proc->p_pid, td->td_name, cs);
909 ksiginfo_init_trap(&ksi);
910 ksi.ksi_signo = SIGBUS;
911 ksi.ksi_code = BUS_OBJERR;
912 ksi.ksi_trapno = T_PROTFLT;
913 ksi.ksi_addr = (void *)regs->tf_eip;
914 trapsignal(td, &ksi);
918 bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(*regs));
921 #if defined(COMPAT_43)
922 if (ucp->uc_mcontext.mc_onstack & 1)
923 td->td_sigstk.ss_flags |= SS_ONSTACK;
925 td->td_sigstk.ss_flags &= ~SS_ONSTACK;
927 kern_sigprocmask(td, SIG_SETMASK, &ucp->uc_sigmask, NULL, 0);
928 return (EJUSTRETURN);
930 #endif /* COMPAT_FREEBSD4 */
938 struct sigreturn_args /* {
939 const struct __ucontext *sigcntxp;
943 struct trapframe *regs;
945 int cs, eflags, error, ret;
948 error = copyin(uap->sigcntxp, &uc, sizeof(uc));
953 eflags = ucp->uc_mcontext.mc_eflags;
954 if (eflags & PSL_VM) {
955 struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs;
956 struct vm86_kernel *vm86;
959 * if pcb_ext == 0 or vm86_inited == 0, the user hasn't
960 * set up the vm86 area, and we can't enter vm86 mode.
962 if (td->td_pcb->pcb_ext == 0)
964 vm86 = &td->td_pcb->pcb_ext->ext_vm86;
965 if (vm86->vm86_inited == 0)
968 /* Go back to user mode if both flags are set. */
969 if ((eflags & PSL_VIP) && (eflags & PSL_VIF)) {
970 ksiginfo_init_trap(&ksi);
971 ksi.ksi_signo = SIGBUS;
972 ksi.ksi_code = BUS_OBJERR;
973 ksi.ksi_addr = (void *)regs->tf_eip;
974 trapsignal(td, &ksi);
977 if (vm86->vm86_has_vme) {
978 eflags = (tf->tf_eflags & ~VME_USERCHANGE) |
979 (eflags & VME_USERCHANGE) | PSL_VM;
981 vm86->vm86_eflags = eflags; /* save VIF, VIP */
982 eflags = (tf->tf_eflags & ~VM_USERCHANGE) |
983 (eflags & VM_USERCHANGE) | PSL_VM;
985 bcopy(&ucp->uc_mcontext.mc_fs, tf, sizeof(struct trapframe));
986 tf->tf_eflags = eflags;
987 tf->tf_vm86_ds = tf->tf_ds;
988 tf->tf_vm86_es = tf->tf_es;
989 tf->tf_vm86_fs = tf->tf_fs;
990 tf->tf_vm86_gs = ucp->uc_mcontext.mc_gs;
991 tf->tf_ds = _udatasel;
992 tf->tf_es = _udatasel;
993 tf->tf_fs = _udatasel;
996 * Don't allow users to change privileged or reserved flags.
999 * XXX do allow users to change the privileged flag PSL_RF.
1000 * The cpu sets PSL_RF in tf_eflags for faults. Debuggers
1001 * should sometimes set it there too. tf_eflags is kept in
1002 * the signal context during signal handling and there is no
1003 * other place to remember it, so the PSL_RF bit may be
1004 * corrupted by the signal handler without us knowing.
1005 * Corruption of the PSL_RF bit at worst causes one more or
1006 * one less debugger trap, so allowing it is fairly harmless.
1008 if (!EFL_SECURE(eflags & ~PSL_RF, regs->tf_eflags & ~PSL_RF)) {
1009 uprintf("pid %d (%s): sigreturn eflags = 0x%x\n",
1010 td->td_proc->p_pid, td->td_name, eflags);
1015 * Don't allow users to load a valid privileged %cs. Let the
1016 * hardware check for invalid selectors, excess privilege in
1017 * other selectors, invalid %eip's and invalid %esp's.
1019 cs = ucp->uc_mcontext.mc_cs;
1020 if (!CS_SECURE(cs)) {
1021 uprintf("pid %d (%s): sigreturn cs = 0x%x\n",
1022 td->td_proc->p_pid, td->td_name, cs);
1023 ksiginfo_init_trap(&ksi);
1024 ksi.ksi_signo = SIGBUS;
1025 ksi.ksi_code = BUS_OBJERR;
1026 ksi.ksi_trapno = T_PROTFLT;
1027 ksi.ksi_addr = (void *)regs->tf_eip;
1028 trapsignal(td, &ksi);
1032 ret = set_fpcontext(td, &ucp->uc_mcontext);
1035 bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(*regs));
1038 #if defined(COMPAT_43)
1039 if (ucp->uc_mcontext.mc_onstack & 1)
1040 td->td_sigstk.ss_flags |= SS_ONSTACK;
1042 td->td_sigstk.ss_flags &= ~SS_ONSTACK;
1045 kern_sigprocmask(td, SIG_SETMASK, &ucp->uc_sigmask, NULL, 0);
1046 return (EJUSTRETURN);
1050 * Machine dependent boot() routine
1052 * I haven't seen anything to put here yet
1053 * Possibly some stuff might be grafted back here from boot()
1061 * Flush the D-cache for non-DMA I/O so that the I-cache can
1062 * be made coherent later.
1065 cpu_flush_dcache(void *ptr, size_t len)
1067 /* Not applicable */
1070 /* Get current clock frequency for the given cpu id. */
1072 cpu_est_clockrate(int cpu_id, uint64_t *rate)
1075 uint64_t tsc1, tsc2;
1077 if (pcpu_find(cpu_id) == NULL || rate == NULL)
1080 return (EOPNOTSUPP);
1082 /* If we're booting, trust the rate calibrated moments ago. */
1089 /* Schedule ourselves on the indicated cpu. */
1090 thread_lock(curthread);
1091 sched_bind(curthread, cpu_id);
1092 thread_unlock(curthread);
1095 /* Calibrate by measuring a short delay. */
1096 reg = intr_disable();
1103 thread_lock(curthread);
1104 sched_unbind(curthread);
1105 thread_unlock(curthread);
1109 * Calculate the difference in readings, convert to Mhz, and
1110 * subtract 0.5% of the total. Empirical testing has shown that
1111 * overhead in DELAY() works out to approximately this value.
1114 *rate = tsc2 * 1000 - tsc2 * 5;
1120 * Shutdown the CPU as much as possible
1129 static int idle_mwait = 1; /* Use MONITOR/MWAIT for short idle. */
1130 TUNABLE_INT("machdep.idle_mwait", &idle_mwait);
1131 SYSCTL_INT(_machdep, OID_AUTO, idle_mwait, CTLFLAG_RW, &idle_mwait,
1132 0, "Use MONITOR/MWAIT for short idle");
1134 #define STATE_RUNNING 0x0
1135 #define STATE_MWAIT 0x1
1136 #define STATE_SLEEPING 0x2
1139 cpu_idle_hlt(int busy)
1143 state = (int *)PCPU_PTR(monitorbuf);
1144 *state = STATE_SLEEPING;
1147 * Since we may be in a critical section from cpu_idle(), if
1148 * an interrupt fires during that critical section we may have
1149 * a pending preemption. If the CPU halts, then that thread
1150 * may not execute until a later interrupt awakens the CPU.
1151 * To handle this race, check for a runnable thread after
1152 * disabling interrupts and immediately return if one is
1153 * found. Also, we must absolutely guarentee that hlt is
1154 * the next instruction after sti. This ensures that any
1155 * interrupt that fires after the call to disable_intr() will
1156 * immediately awaken the CPU from hlt. Finally, please note
1157 * that on x86 this works fine because of interrupts enabled only
1158 * after the instruction following sti takes place, while IF is set
1159 * to 1 immediately, allowing hlt instruction to acknowledge the
1163 if (sched_runnable())
1166 __asm __volatile("sti; hlt");
1167 *state = STATE_RUNNING;
1171 * MWAIT cpu power states. Lower 4 bits are sub-states.
1173 #define MWAIT_C0 0xf0
1174 #define MWAIT_C1 0x00
1175 #define MWAIT_C2 0x10
1176 #define MWAIT_C3 0x20
1177 #define MWAIT_C4 0x30
1180 cpu_idle_mwait(int busy)
1184 state = (int *)PCPU_PTR(monitorbuf);
1185 *state = STATE_MWAIT;
1187 /* See comments in cpu_idle_hlt(). */
1189 if (sched_runnable()) {
1191 *state = STATE_RUNNING;
1194 cpu_monitor(state, 0, 0);
1195 if (*state == STATE_MWAIT)
1196 __asm __volatile("sti; mwait" : : "a" (MWAIT_C1), "c" (0));
1199 *state = STATE_RUNNING;
1203 cpu_idle_spin(int busy)
1208 state = (int *)PCPU_PTR(monitorbuf);
1209 *state = STATE_RUNNING;
1212 * The sched_runnable() call is racy but as long as there is
1213 * a loop missing it one time will have just a little impact if any
1214 * (and it is much better than missing the check at all).
1216 for (i = 0; i < 1000; i++) {
1217 if (sched_runnable())
1223 void (*cpu_idle_fn)(int) = cpu_idle_hlt;
1230 if (mp_grab_cpu_hlt())
1233 /* If we are busy - try to use fast methods. */
1235 if ((cpu_feature2 & CPUID2_MON) && idle_mwait) {
1236 cpu_idle_mwait(busy);
1241 /* Call main idle method. */
1246 cpu_idle_wakeup(int cpu)
1251 pcpu = pcpu_find(cpu);
1252 state = (int *)pcpu->pc_monitorbuf;
1254 * This doesn't need to be atomic since missing the race will
1255 * simply result in unnecessary IPIs.
1257 if (*state == STATE_SLEEPING)
1259 if (*state == STATE_MWAIT)
1260 *state = STATE_RUNNING;
1265 * Ordered by speed/power consumption.
1271 { cpu_idle_spin, "spin" },
1272 { cpu_idle_mwait, "mwait" },
1273 { cpu_idle_hlt, "hlt" },
1278 idle_sysctl_available(SYSCTL_HANDLER_ARGS)
1284 avail = malloc(256, M_TEMP, M_WAITOK);
1286 for (i = 0; idle_tbl[i].id_name != NULL; i++) {
1287 if (strstr(idle_tbl[i].id_name, "mwait") &&
1288 (cpu_feature2 & CPUID2_MON) == 0)
1290 p += sprintf(p, "%s, ", idle_tbl[i].id_name);
1292 error = sysctl_handle_string(oidp, avail, 0, req);
1293 free(avail, M_TEMP);
1297 SYSCTL_PROC(_machdep, OID_AUTO, idle_available, CTLTYPE_STRING | CTLFLAG_RD,
1298 0, 0, idle_sysctl_available, "A", "list of available idle functions");
1301 idle_sysctl(SYSCTL_HANDLER_ARGS)
1309 for (i = 0; idle_tbl[i].id_name != NULL; i++) {
1310 if (idle_tbl[i].id_fn == cpu_idle_fn) {
1311 p = idle_tbl[i].id_name;
1315 strncpy(buf, p, sizeof(buf));
1316 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1317 if (error != 0 || req->newptr == NULL)
1319 for (i = 0; idle_tbl[i].id_name != NULL; i++) {
1320 if (strstr(idle_tbl[i].id_name, "mwait") &&
1321 (cpu_feature2 & CPUID2_MON) == 0)
1323 if (strcmp(idle_tbl[i].id_name, buf))
1325 cpu_idle_fn = idle_tbl[i].id_fn;
1331 SYSCTL_PROC(_machdep, OID_AUTO, idle, CTLTYPE_STRING | CTLFLAG_RW, 0, 0,
1332 idle_sysctl, "A", "currently selected idle function");
1335 * Reset registers to default values on exec.
1338 exec_setregs(td, entry, stack, ps_strings)
1344 struct trapframe *regs = td->td_frame;
1345 struct pcb *pcb = td->td_pcb;
1347 /* Reset pc->pcb_gs and %gs before possibly invalidating it. */
1348 pcb->pcb_gs = _udatasel;
1351 mtx_lock_spin(&dt_lock);
1352 if (td->td_proc->p_md.md_ldt)
1355 mtx_unlock_spin(&dt_lock);
1357 bzero((char *)regs, sizeof(struct trapframe));
1358 regs->tf_eip = entry;
1359 regs->tf_esp = stack;
1360 regs->tf_eflags = PSL_USER | (regs->tf_eflags & PSL_T);
1361 regs->tf_ss = _udatasel;
1362 regs->tf_ds = _udatasel;
1363 regs->tf_es = _udatasel;
1364 regs->tf_fs = _udatasel;
1365 regs->tf_cs = _ucodesel;
1367 /* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */
1368 regs->tf_ebx = ps_strings;
1371 * Reset the hardware debug registers if they were in use.
1372 * They won't have any meaning for the newly exec'd process.
1374 if (pcb->pcb_flags & PCB_DBREGS) {
1381 if (pcb == PCPU_GET(curpcb)) {
1383 * Clear the debug registers on the running
1384 * CPU, otherwise they will end up affecting
1385 * the next process we switch to.
1389 pcb->pcb_flags &= ~PCB_DBREGS;
1393 * Initialize the math emulator (if any) for the current process.
1394 * Actually, just clear the bit that says that the emulator has
1395 * been initialized. Initialization is delayed until the process
1396 * traps to the emulator (if it is done at all) mainly because
1397 * emulators don't provide an entry point for initialization.
1399 td->td_pcb->pcb_flags &= ~FP_SOFTFP;
1400 pcb->pcb_initial_npxcw = __INITIAL_NPXCW__;
1403 * Drop the FP state if we hold it, so that the process gets a
1404 * clean FP state if it uses the FPU again.
1409 * XXX - Linux emulator
1410 * Make sure sure edx is 0x0 on entry. Linux binaries depend
1413 td->td_retval[1] = 0;
1424 * CR0_MP, CR0_NE and CR0_TS are set for NPX (FPU) support:
1426 * Prepare to trap all ESC (i.e., NPX) instructions and all WAIT
1427 * instructions. We must set the CR0_MP bit and use the CR0_TS
1428 * bit to control the trap, because setting the CR0_EM bit does
1429 * not cause WAIT instructions to trap. It's important to trap
1430 * WAIT instructions - otherwise the "wait" variants of no-wait
1431 * control instructions would degenerate to the "no-wait" variants
1432 * after FP context switches but work correctly otherwise. It's
1433 * particularly important to trap WAITs when there is no NPX -
1434 * otherwise the "wait" variants would always degenerate.
1436 * Try setting CR0_NE to get correct error reporting on 486DX's.
1437 * Setting it should fail or do nothing on lesser processors.
1439 cr0 |= CR0_MP | CR0_NE | CR0_TS | CR0_WP | CR0_AM;
1444 u_long bootdev; /* not a struct cdev *- encoding is different */
1445 SYSCTL_ULONG(_machdep, OID_AUTO, guessed_bootdev,
1446 CTLFLAG_RD, &bootdev, 0, "Maybe the Boot device (not in struct cdev *format)");
1449 * Initialize 386 and configure to run kernel
1453 * Initialize segments & interrupt table
1458 union descriptor gdt[NGDT * MAXCPU]; /* global descriptor table */
1459 union descriptor ldt[NLDT]; /* local descriptor table */
1460 static struct gate_descriptor idt0[NIDT];
1461 struct gate_descriptor *idt = &idt0[0]; /* interrupt descriptor table */
1462 struct region_descriptor r_gdt, r_idt; /* table descriptors */
1463 struct mtx dt_lock; /* lock for GDT and LDT */
1465 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
1466 extern int has_f00f_bug;
1469 static struct i386tss dblfault_tss;
1470 static char dblfault_stack[PAGE_SIZE];
1472 extern vm_offset_t proc0kstack;
1476 * software prototypes -- in more palatable form.
1478 * GCODE_SEL through GUDATA_SEL must be in this order for syscall/sysret
1479 * GUFS_SEL and GUGS_SEL must be in this order (swtch.s knows it)
1481 struct soft_segment_descriptor gdt_segs[] = {
1482 /* GNULL_SEL 0 Null Descriptor */
1488 .ssd_xx = 0, .ssd_xx1 = 0,
1491 /* GPRIV_SEL 1 SMP Per-Processor Private Data Descriptor */
1493 .ssd_limit = 0xfffff,
1494 .ssd_type = SDT_MEMRWA,
1497 .ssd_xx = 0, .ssd_xx1 = 0,
1500 /* GUFS_SEL 2 %fs Descriptor for user */
1502 .ssd_limit = 0xfffff,
1503 .ssd_type = SDT_MEMRWA,
1506 .ssd_xx = 0, .ssd_xx1 = 0,
1509 /* GUGS_SEL 3 %gs Descriptor for user */
1511 .ssd_limit = 0xfffff,
1512 .ssd_type = SDT_MEMRWA,
1515 .ssd_xx = 0, .ssd_xx1 = 0,
1518 /* GCODE_SEL 4 Code Descriptor for kernel */
1520 .ssd_limit = 0xfffff,
1521 .ssd_type = SDT_MEMERA,
1524 .ssd_xx = 0, .ssd_xx1 = 0,
1527 /* GDATA_SEL 5 Data Descriptor for kernel */
1529 .ssd_limit = 0xfffff,
1530 .ssd_type = SDT_MEMRWA,
1533 .ssd_xx = 0, .ssd_xx1 = 0,
1536 /* GUCODE_SEL 6 Code Descriptor for user */
1538 .ssd_limit = 0xfffff,
1539 .ssd_type = SDT_MEMERA,
1542 .ssd_xx = 0, .ssd_xx1 = 0,
1545 /* GUDATA_SEL 7 Data Descriptor for user */
1547 .ssd_limit = 0xfffff,
1548 .ssd_type = SDT_MEMRWA,
1551 .ssd_xx = 0, .ssd_xx1 = 0,
1554 /* GBIOSLOWMEM_SEL 8 BIOS access to realmode segment 0x40, must be #8 in GDT */
1555 { .ssd_base = 0x400,
1556 .ssd_limit = 0xfffff,
1557 .ssd_type = SDT_MEMRWA,
1560 .ssd_xx = 0, .ssd_xx1 = 0,
1563 /* GPROC0_SEL 9 Proc 0 Tss Descriptor */
1566 .ssd_limit = sizeof(struct i386tss)-1,
1567 .ssd_type = SDT_SYS386TSS,
1570 .ssd_xx = 0, .ssd_xx1 = 0,
1573 /* GLDT_SEL 10 LDT Descriptor */
1574 { .ssd_base = (int) ldt,
1575 .ssd_limit = sizeof(ldt)-1,
1576 .ssd_type = SDT_SYSLDT,
1579 .ssd_xx = 0, .ssd_xx1 = 0,
1582 /* GUSERLDT_SEL 11 User LDT Descriptor per process */
1583 { .ssd_base = (int) ldt,
1584 .ssd_limit = (512 * sizeof(union descriptor)-1),
1585 .ssd_type = SDT_SYSLDT,
1588 .ssd_xx = 0, .ssd_xx1 = 0,
1591 /* GPANIC_SEL 12 Panic Tss Descriptor */
1592 { .ssd_base = (int) &dblfault_tss,
1593 .ssd_limit = sizeof(struct i386tss)-1,
1594 .ssd_type = SDT_SYS386TSS,
1597 .ssd_xx = 0, .ssd_xx1 = 0,
1600 /* GBIOSCODE32_SEL 13 BIOS 32-bit interface (32bit Code) */
1602 .ssd_limit = 0xfffff,
1603 .ssd_type = SDT_MEMERA,
1606 .ssd_xx = 0, .ssd_xx1 = 0,
1609 /* GBIOSCODE16_SEL 14 BIOS 32-bit interface (16bit Code) */
1611 .ssd_limit = 0xfffff,
1612 .ssd_type = SDT_MEMERA,
1615 .ssd_xx = 0, .ssd_xx1 = 0,
1618 /* GBIOSDATA_SEL 15 BIOS 32-bit interface (Data) */
1620 .ssd_limit = 0xfffff,
1621 .ssd_type = SDT_MEMRWA,
1624 .ssd_xx = 0, .ssd_xx1 = 0,
1627 /* GBIOSUTIL_SEL 16 BIOS 16-bit interface (Utility) */
1629 .ssd_limit = 0xfffff,
1630 .ssd_type = SDT_MEMRWA,
1633 .ssd_xx = 0, .ssd_xx1 = 0,
1636 /* GBIOSARGS_SEL 17 BIOS 16-bit interface (Arguments) */
1638 .ssd_limit = 0xfffff,
1639 .ssd_type = SDT_MEMRWA,
1642 .ssd_xx = 0, .ssd_xx1 = 0,
1645 /* GNDIS_SEL 18 NDIS Descriptor */
1651 .ssd_xx = 0, .ssd_xx1 = 0,
1656 static struct soft_segment_descriptor ldt_segs[] = {
1657 /* Null Descriptor - overwritten by call gate */
1663 .ssd_xx = 0, .ssd_xx1 = 0,
1666 /* Null Descriptor - overwritten by call gate */
1672 .ssd_xx = 0, .ssd_xx1 = 0,
1675 /* Null Descriptor - overwritten by call gate */
1681 .ssd_xx = 0, .ssd_xx1 = 0,
1684 /* Code Descriptor for user */
1686 .ssd_limit = 0xfffff,
1687 .ssd_type = SDT_MEMERA,
1690 .ssd_xx = 0, .ssd_xx1 = 0,
1693 /* Null Descriptor - overwritten by call gate */
1699 .ssd_xx = 0, .ssd_xx1 = 0,
1702 /* Data Descriptor for user */
1704 .ssd_limit = 0xfffff,
1705 .ssd_type = SDT_MEMRWA,
1708 .ssd_xx = 0, .ssd_xx1 = 0,
1714 setidt(idx, func, typ, dpl, selec)
1721 struct gate_descriptor *ip;
1724 ip->gd_looffset = (int)func;
1725 ip->gd_selector = selec;
1731 ip->gd_hioffset = ((int)func)>>16 ;
1735 IDTVEC(div), IDTVEC(dbg), IDTVEC(nmi), IDTVEC(bpt), IDTVEC(ofl),
1736 IDTVEC(bnd), IDTVEC(ill), IDTVEC(dna), IDTVEC(fpusegm),
1737 IDTVEC(tss), IDTVEC(missing), IDTVEC(stk), IDTVEC(prot),
1738 IDTVEC(page), IDTVEC(mchk), IDTVEC(rsvd), IDTVEC(fpu), IDTVEC(align),
1740 #ifdef KDTRACE_HOOKS
1743 IDTVEC(lcall_syscall), IDTVEC(int0x80_syscall);
1747 * Display the index and function name of any IDT entries that don't use
1748 * the default 'rsvd' entry point.
1750 DB_SHOW_COMMAND(idt, db_show_idt)
1752 struct gate_descriptor *ip;
1757 for (idx = 0; idx < NIDT && !db_pager_quit; idx++) {
1758 func = (ip->gd_hioffset << 16 | ip->gd_looffset);
1759 if (func != (uintptr_t)&IDTVEC(rsvd)) {
1760 db_printf("%3d\t", idx);
1761 db_printsym(func, DB_STGY_PROC);
1768 /* Show privileged registers. */
1769 DB_SHOW_COMMAND(sysregs, db_show_sysregs)
1771 uint64_t idtr, gdtr;
1774 db_printf("idtr\t0x%08x/%04x\n",
1775 (u_int)(idtr >> 16), (u_int)idtr & 0xffff);
1777 db_printf("gdtr\t0x%08x/%04x\n",
1778 (u_int)(gdtr >> 16), (u_int)gdtr & 0xffff);
1779 db_printf("ldtr\t0x%04x\n", rldt());
1780 db_printf("tr\t0x%04x\n", rtr());
1781 db_printf("cr0\t0x%08x\n", rcr0());
1782 db_printf("cr2\t0x%08x\n", rcr2());
1783 db_printf("cr3\t0x%08x\n", rcr3());
1784 db_printf("cr4\t0x%08x\n", rcr4());
1790 struct segment_descriptor *sd;
1791 struct soft_segment_descriptor *ssd;
1793 ssd->ssd_base = (sd->sd_hibase << 24) | sd->sd_lobase;
1794 ssd->ssd_limit = (sd->sd_hilimit << 16) | sd->sd_lolimit;
1795 ssd->ssd_type = sd->sd_type;
1796 ssd->ssd_dpl = sd->sd_dpl;
1797 ssd->ssd_p = sd->sd_p;
1798 ssd->ssd_def32 = sd->sd_def32;
1799 ssd->ssd_gran = sd->sd_gran;
1809 if (basemem > 640) {
1810 printf("Preposterous BIOS basemem of %uK, truncating to 640K\n",
1816 * XXX if biosbasemem is now < 640, there is a `hole'
1817 * between the end of base memory and the start of
1818 * ISA memory. The hole may be empty or it may
1819 * contain BIOS code or data. Map it read/write so
1820 * that the BIOS can write to it. (Memory from 0 to
1821 * the physical end of the kernel is mapped read-only
1822 * to begin with and then parts of it are remapped.
1823 * The parts that aren't remapped form holes that
1824 * remain read-only and are unused by the kernel.
1825 * The base memory area is below the physical end of
1826 * the kernel and right now forms a read-only hole.
1827 * The part of it from PAGE_SIZE to
1828 * (trunc_page(biosbasemem * 1024) - 1) will be
1829 * remapped and used by the kernel later.)
1831 * This code is similar to the code used in
1832 * pmap_mapdev, but since no memory needs to be
1833 * allocated we simply change the mapping.
1835 for (pa = trunc_page(basemem * 1024);
1836 pa < ISA_HOLE_START; pa += PAGE_SIZE)
1837 pmap_kenter(KERNBASE + pa, pa);
1840 * Map pages between basemem and ISA_HOLE_START, if any, r/w into
1841 * the vm86 page table so that vm86 can scribble on them using
1842 * the vm86 map too. XXX: why 2 ways for this and only 1 way for
1843 * page 0, at least as initialized here?
1845 pte = (pt_entry_t *)vm86paddr;
1846 for (i = basemem / 4; i < 160; i++)
1847 pte[i] = (i << PAGE_SHIFT) | PG_V | PG_RW | PG_U;
1851 * Populate the (physmap) array with base/bound pairs describing the
1852 * available physical memory in the system, then test this memory and
1853 * build the phys_avail array describing the actually-available memory.
1855 * If we cannot accurately determine the physical memory map, then use
1856 * value from the 0xE801 call, and failing that, the RTC.
1858 * Total memory size may be set by the kernel environment variable
1859 * hw.physmem or the compile-time define MAXMEM.
1861 * XXX first should be vm_paddr_t.
1864 getmemsize(int first)
1866 int off, physmap_idx, pa_indx, da_indx;
1867 u_long physmem_tunable, memtest;
1868 vm_paddr_t physmap[PHYSMAP_SIZE];
1870 quad_t dcons_addr, dcons_size;
1877 bzero(physmap, sizeof(physmap));
1879 /* XXX - some of EPSON machines can't use PG_N */
1881 if (pc98_machine_type & M_EPSON_PC98) {
1882 switch (epson_machine_id) {
1886 case EPSON_PC486_HX:
1887 case EPSON_PC486_HG:
1888 case EPSON_PC486_HA:
1894 under16 = pc98_getmemsize(&basemem, &extmem);
1898 physmap[1] = basemem * 1024;
1900 physmap[physmap_idx] = 0x100000;
1901 physmap[physmap_idx + 1] = physmap[physmap_idx] + extmem * 1024;
1904 * Now, physmap contains a map of physical memory.
1908 /* make hole for AP bootstrap code */
1909 physmap[1] = mp_bootaddress(physmap[1]);
1913 * Maxmem isn't the "maximum memory", it's one larger than the
1914 * highest page of the physical address space. It should be
1915 * called something like "Maxphyspage". We may adjust this
1916 * based on ``hw.physmem'' and the results of the memory test.
1918 Maxmem = atop(physmap[physmap_idx + 1]);
1921 Maxmem = MAXMEM / 4;
1924 if (TUNABLE_ULONG_FETCH("hw.physmem", &physmem_tunable))
1925 Maxmem = atop(physmem_tunable);
1928 * By default keep the memtest enabled. Use a general name so that
1929 * one could eventually do more with the code than just disable it.
1932 TUNABLE_ULONG_FETCH("hw.memtest.tests", &memtest);
1934 if (atop(physmap[physmap_idx + 1]) != Maxmem &&
1935 (boothowto & RB_VERBOSE))
1936 printf("Physical memory use set to %ldK\n", Maxmem * 4);
1939 * If Maxmem has been increased beyond what the system has detected,
1940 * extend the last memory segment to the new limit.
1942 if (atop(physmap[physmap_idx + 1]) < Maxmem)
1943 physmap[physmap_idx + 1] = ptoa((vm_paddr_t)Maxmem);
1946 * We need to divide chunk if Maxmem is larger than 16MB and
1947 * under 16MB area is not full of memory.
1948 * (1) system area (15-16MB region) is cut off
1949 * (2) extended memory is only over 16MB area (ex. Melco "HYPERMEMORY")
1951 if ((under16 != 16 * 1024) && (extmem > 15 * 1024)) {
1952 /* 15M - 16M region is cut off, so need to divide chunk */
1953 physmap[physmap_idx + 1] = under16 * 1024;
1955 physmap[physmap_idx] = 0x1000000;
1956 physmap[physmap_idx + 1] = physmap[2] + extmem * 1024;
1959 /* call pmap initialization to make new kernel address space */
1960 pmap_bootstrap(first);
1963 * Size up each available chunk of physical memory.
1965 physmap[0] = PAGE_SIZE; /* mask off page 0 */
1968 phys_avail[pa_indx++] = physmap[0];
1969 phys_avail[pa_indx] = physmap[0];
1970 dump_avail[da_indx] = physmap[0];
1974 * Get dcons buffer address
1976 if (getenv_quad("dcons.addr", &dcons_addr) == 0 ||
1977 getenv_quad("dcons.size", &dcons_size) == 0)
1981 * physmap is in bytes, so when converting to page boundaries,
1982 * round up the start address and round down the end address.
1984 for (i = 0; i <= physmap_idx; i += 2) {
1987 end = ptoa((vm_paddr_t)Maxmem);
1988 if (physmap[i + 1] < end)
1989 end = trunc_page(physmap[i + 1]);
1990 for (pa = round_page(physmap[i]); pa < end; pa += PAGE_SIZE) {
1991 int tmp, page_bad, full;
1992 int *ptr = (int *)CADDR1;
1996 * block out kernel memory as not available.
1998 if (pa >= KERNLOAD && pa < first)
2002 * block out dcons buffer
2005 && pa >= trunc_page(dcons_addr)
2006 && pa < dcons_addr + dcons_size)
2014 * map page into kernel: valid, read/write,non-cacheable
2016 *pte = pa | PG_V | PG_RW | pg_n;
2021 * Test for alternating 1's and 0's
2023 *(volatile int *)ptr = 0xaaaaaaaa;
2024 if (*(volatile int *)ptr != 0xaaaaaaaa)
2027 * Test for alternating 0's and 1's
2029 *(volatile int *)ptr = 0x55555555;
2030 if (*(volatile int *)ptr != 0x55555555)
2035 *(volatile int *)ptr = 0xffffffff;
2036 if (*(volatile int *)ptr != 0xffffffff)
2041 *(volatile int *)ptr = 0x0;
2042 if (*(volatile int *)ptr != 0x0)
2045 * Restore original value.
2051 * Adjust array of valid/good pages.
2053 if (page_bad == TRUE)
2056 * If this good page is a continuation of the
2057 * previous set of good pages, then just increase
2058 * the end pointer. Otherwise start a new chunk.
2059 * Note that "end" points one higher than end,
2060 * making the range >= start and < end.
2061 * If we're also doing a speculative memory
2062 * test and we at or past the end, bump up Maxmem
2063 * so that we keep going. The first bad page
2064 * will terminate the loop.
2066 if (phys_avail[pa_indx] == pa) {
2067 phys_avail[pa_indx] += PAGE_SIZE;
2070 if (pa_indx == PHYS_AVAIL_ARRAY_END) {
2072 "Too many holes in the physical address space, giving up\n");
2077 phys_avail[pa_indx++] = pa; /* start */
2078 phys_avail[pa_indx] = pa + PAGE_SIZE; /* end */
2082 if (dump_avail[da_indx] == pa) {
2083 dump_avail[da_indx] += PAGE_SIZE;
2086 if (da_indx == DUMP_AVAIL_ARRAY_END) {
2090 dump_avail[da_indx++] = pa; /* start */
2091 dump_avail[da_indx] = pa + PAGE_SIZE; /* end */
2103 * The last chunk must contain at least one page plus the message
2104 * buffer to avoid complicating other code (message buffer address
2105 * calculation, etc.).
2107 while (phys_avail[pa_indx - 1] + PAGE_SIZE +
2108 round_page(msgbufsize) >= phys_avail[pa_indx]) {
2109 physmem -= atop(phys_avail[pa_indx] - phys_avail[pa_indx - 1]);
2110 phys_avail[pa_indx--] = 0;
2111 phys_avail[pa_indx--] = 0;
2114 Maxmem = atop(phys_avail[pa_indx]);
2116 /* Trim off space for the message buffer. */
2117 phys_avail[pa_indx] -= round_page(msgbufsize);
2119 /* Map the message buffer. */
2120 for (off = 0; off < round_page(msgbufsize); off += PAGE_SIZE)
2121 pmap_kenter((vm_offset_t)msgbufp + off, phys_avail[pa_indx] +
2131 struct gate_descriptor *gdp;
2132 int gsel_tss, metadata_missing, x, pa;
2136 thread0.td_kstack = proc0kstack;
2137 thread0.td_kstack_pages = KSTACK_PAGES;
2138 kstack0_sz = thread0.td_kstack_pages * PAGE_SIZE;
2139 thread0.td_pcb = (struct pcb *)(thread0.td_kstack + kstack0_sz) - 1;
2142 * This may be done better later if it gets more high level
2143 * components in it. If so just link td->td_proc here.
2145 proc_linkup0(&proc0, &thread0);
2152 metadata_missing = 0;
2153 if (bootinfo.bi_modulep) {
2154 preload_metadata = (caddr_t)bootinfo.bi_modulep + KERNBASE;
2155 preload_bootstrap_relocate(KERNBASE);
2157 metadata_missing = 1;
2160 kern_envp = static_env;
2161 else if (bootinfo.bi_envp)
2162 kern_envp = (caddr_t)bootinfo.bi_envp + KERNBASE;
2164 /* Init basic tunables, hz etc */
2168 * Make gdt memory segments. All segments cover the full 4GB
2169 * of address space and permissions are enforced at page level.
2171 gdt_segs[GCODE_SEL].ssd_limit = atop(0 - 1);
2172 gdt_segs[GDATA_SEL].ssd_limit = atop(0 - 1);
2173 gdt_segs[GUCODE_SEL].ssd_limit = atop(0 - 1);
2174 gdt_segs[GUDATA_SEL].ssd_limit = atop(0 - 1);
2175 gdt_segs[GUFS_SEL].ssd_limit = atop(0 - 1);
2176 gdt_segs[GUGS_SEL].ssd_limit = atop(0 - 1);
2179 gdt_segs[GPRIV_SEL].ssd_limit = atop(0 - 1);
2180 gdt_segs[GPRIV_SEL].ssd_base = (int) pc;
2181 gdt_segs[GPROC0_SEL].ssd_base = (int) &pc->pc_common_tss;
2183 for (x = 0; x < NGDT; x++)
2184 ssdtosd(&gdt_segs[x], &gdt[x].sd);
2186 r_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
2187 r_gdt.rd_base = (int) gdt;
2188 mtx_init(&dt_lock, "descriptor tables", NULL, MTX_SPIN);
2191 pcpu_init(pc, 0, sizeof(struct pcpu));
2192 for (pa = first; pa < first + DPCPU_SIZE; pa += PAGE_SIZE)
2193 pmap_kenter(pa + KERNBASE, pa);
2194 dpcpu_init((void *)(first + KERNBASE), 0);
2195 first += DPCPU_SIZE;
2196 PCPU_SET(prvspace, pc);
2197 PCPU_SET(curthread, &thread0);
2198 PCPU_SET(curpcb, thread0.td_pcb);
2201 * Initialize mutexes.
2203 * icu_lock: in order to allow an interrupt to occur in a critical
2204 * section, to set pcpu->ipending (etc...) properly, we
2205 * must be able to get the icu lock, so it can't be
2209 mtx_init(&icu_lock, "icu", NULL, MTX_SPIN | MTX_NOWITNESS | MTX_NOPROFILE);
2211 /* make ldt memory segments */
2212 ldt_segs[LUCODE_SEL].ssd_limit = atop(0 - 1);
2213 ldt_segs[LUDATA_SEL].ssd_limit = atop(0 - 1);
2214 for (x = 0; x < sizeof ldt_segs / sizeof ldt_segs[0]; x++)
2215 ssdtosd(&ldt_segs[x], &ldt[x].sd);
2217 _default_ldt = GSEL(GLDT_SEL, SEL_KPL);
2219 PCPU_SET(currentldt, _default_ldt);
2222 for (x = 0; x < NIDT; x++)
2223 setidt(x, &IDTVEC(rsvd), SDT_SYS386TGT, SEL_KPL,
2224 GSEL(GCODE_SEL, SEL_KPL));
2225 setidt(IDT_DE, &IDTVEC(div), SDT_SYS386TGT, SEL_KPL,
2226 GSEL(GCODE_SEL, SEL_KPL));
2227 setidt(IDT_DB, &IDTVEC(dbg), SDT_SYS386IGT, SEL_KPL,
2228 GSEL(GCODE_SEL, SEL_KPL));
2229 setidt(IDT_NMI, &IDTVEC(nmi), SDT_SYS386IGT, SEL_KPL,
2230 GSEL(GCODE_SEL, SEL_KPL));
2231 setidt(IDT_BP, &IDTVEC(bpt), SDT_SYS386IGT, SEL_UPL,
2232 GSEL(GCODE_SEL, SEL_KPL));
2233 setidt(IDT_OF, &IDTVEC(ofl), SDT_SYS386TGT, SEL_UPL,
2234 GSEL(GCODE_SEL, SEL_KPL));
2235 setidt(IDT_BR, &IDTVEC(bnd), SDT_SYS386TGT, SEL_KPL,
2236 GSEL(GCODE_SEL, SEL_KPL));
2237 setidt(IDT_UD, &IDTVEC(ill), SDT_SYS386TGT, SEL_KPL,
2238 GSEL(GCODE_SEL, SEL_KPL));
2239 setidt(IDT_NM, &IDTVEC(dna), SDT_SYS386TGT, SEL_KPL
2240 , GSEL(GCODE_SEL, SEL_KPL));
2241 setidt(IDT_DF, 0, SDT_SYSTASKGT, SEL_KPL, GSEL(GPANIC_SEL, SEL_KPL));
2242 setidt(IDT_FPUGP, &IDTVEC(fpusegm), SDT_SYS386TGT, SEL_KPL,
2243 GSEL(GCODE_SEL, SEL_KPL));
2244 setidt(IDT_TS, &IDTVEC(tss), SDT_SYS386TGT, SEL_KPL,
2245 GSEL(GCODE_SEL, SEL_KPL));
2246 setidt(IDT_NP, &IDTVEC(missing), SDT_SYS386TGT, SEL_KPL,
2247 GSEL(GCODE_SEL, SEL_KPL));
2248 setidt(IDT_SS, &IDTVEC(stk), SDT_SYS386TGT, SEL_KPL,
2249 GSEL(GCODE_SEL, SEL_KPL));
2250 setidt(IDT_GP, &IDTVEC(prot), SDT_SYS386TGT, SEL_KPL,
2251 GSEL(GCODE_SEL, SEL_KPL));
2252 setidt(IDT_PF, &IDTVEC(page), SDT_SYS386IGT, SEL_KPL,
2253 GSEL(GCODE_SEL, SEL_KPL));
2254 setidt(IDT_MF, &IDTVEC(fpu), SDT_SYS386TGT, SEL_KPL,
2255 GSEL(GCODE_SEL, SEL_KPL));
2256 setidt(IDT_AC, &IDTVEC(align), SDT_SYS386TGT, SEL_KPL,
2257 GSEL(GCODE_SEL, SEL_KPL));
2258 setidt(IDT_MC, &IDTVEC(mchk), SDT_SYS386TGT, SEL_KPL,
2259 GSEL(GCODE_SEL, SEL_KPL));
2260 setidt(IDT_XF, &IDTVEC(xmm), SDT_SYS386TGT, SEL_KPL,
2261 GSEL(GCODE_SEL, SEL_KPL));
2262 setidt(IDT_SYSCALL, &IDTVEC(int0x80_syscall), SDT_SYS386TGT, SEL_UPL,
2263 GSEL(GCODE_SEL, SEL_KPL));
2264 #ifdef KDTRACE_HOOKS
2265 setidt(IDT_DTRACE_RET, &IDTVEC(dtrace_ret), SDT_SYS386TGT, SEL_UPL,
2266 GSEL(GCODE_SEL, SEL_KPL));
2269 r_idt.rd_limit = sizeof(idt0) - 1;
2270 r_idt.rd_base = (int) idt;
2274 * Initialize the i8254 before the console so that console
2275 * initialization can use DELAY().
2280 * Initialize the console before we print anything out.
2284 if (metadata_missing)
2285 printf("WARNING: loader(8) metadata is missing!\n");
2292 ksym_start = bootinfo.bi_symtab;
2293 ksym_end = bootinfo.bi_esymtab;
2299 if (boothowto & RB_KDB)
2300 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
2303 finishidentcpu(); /* Final stage of CPU initialization */
2304 setidt(IDT_UD, &IDTVEC(ill), SDT_SYS386TGT, SEL_KPL,
2305 GSEL(GCODE_SEL, SEL_KPL));
2306 setidt(IDT_GP, &IDTVEC(prot), SDT_SYS386TGT, SEL_KPL,
2307 GSEL(GCODE_SEL, SEL_KPL));
2308 initializecpu(); /* Initialize CPU registers */
2310 /* make an initial tss so cpu can get interrupt stack on syscall! */
2311 /* Note: -16 is so we can grow the trapframe if we came from vm86 */
2312 PCPU_SET(common_tss.tss_esp0, thread0.td_kstack +
2313 kstack0_sz - sizeof(struct pcb) - 16);
2314 PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL));
2315 gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
2316 PCPU_SET(tss_gdt, &gdt[GPROC0_SEL].sd);
2317 PCPU_SET(common_tssd, *PCPU_GET(tss_gdt));
2318 PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16);
2321 /* pointer to selector slot for %fs/%gs */
2322 PCPU_SET(fsgs_gdt, &gdt[GUFS_SEL].sd);
2324 dblfault_tss.tss_esp = dblfault_tss.tss_esp0 = dblfault_tss.tss_esp1 =
2325 dblfault_tss.tss_esp2 = (int)&dblfault_stack[sizeof(dblfault_stack)];
2326 dblfault_tss.tss_ss = dblfault_tss.tss_ss0 = dblfault_tss.tss_ss1 =
2327 dblfault_tss.tss_ss2 = GSEL(GDATA_SEL, SEL_KPL);
2328 dblfault_tss.tss_cr3 = (int)IdlePTD;
2329 dblfault_tss.tss_eip = (int)dblfault_handler;
2330 dblfault_tss.tss_eflags = PSL_KERNEL;
2331 dblfault_tss.tss_ds = dblfault_tss.tss_es =
2332 dblfault_tss.tss_gs = GSEL(GDATA_SEL, SEL_KPL);
2333 dblfault_tss.tss_fs = GSEL(GPRIV_SEL, SEL_KPL);
2334 dblfault_tss.tss_cs = GSEL(GCODE_SEL, SEL_KPL);
2335 dblfault_tss.tss_ldt = GSEL(GLDT_SEL, SEL_KPL);
2339 init_param2(physmem);
2341 /* now running on new page tables, configured,and u/iom is accessible */
2343 msgbufinit(msgbufp, msgbufsize);
2345 /* make a call gate to reenter kernel with */
2346 gdp = &ldt[LSYS5CALLS_SEL].gd;
2348 x = (int) &IDTVEC(lcall_syscall);
2349 gdp->gd_looffset = x;
2350 gdp->gd_selector = GSEL(GCODE_SEL,SEL_KPL);
2352 gdp->gd_type = SDT_SYS386CGT;
2353 gdp->gd_dpl = SEL_UPL;
2355 gdp->gd_hioffset = x >> 16;
2357 /* XXX does this work? */
2359 ldt[LBSDICALLS_SEL] = ldt[LSYS5CALLS_SEL];
2360 ldt[LSOL26CALLS_SEL] = ldt[LSYS5CALLS_SEL];
2362 /* transfer to user mode */
2364 _ucodesel = GSEL(GUCODE_SEL, SEL_UPL);
2365 _udatasel = GSEL(GUDATA_SEL, SEL_UPL);
2367 /* setup proc 0's pcb */
2368 thread0.td_pcb->pcb_flags = 0;
2369 thread0.td_pcb->pcb_cr3 = (int)IdlePTD;
2370 thread0.td_pcb->pcb_ext = 0;
2371 thread0.td_frame = &proc0_tf;
2375 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
2381 spinlock_enter(void)
2387 if (td->td_md.md_spinlock_count == 0) {
2388 flags = intr_disable();
2389 td->td_md.md_spinlock_count = 1;
2390 td->td_md.md_saved_flags = flags;
2392 td->td_md.md_spinlock_count++;
2404 flags = td->td_md.md_saved_flags;
2405 td->td_md.md_spinlock_count--;
2406 if (td->td_md.md_spinlock_count == 0)
2407 intr_restore(flags);
2410 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
2411 static void f00f_hack(void *unused);
2412 SYSINIT(f00f_hack, SI_SUB_INTRINSIC, SI_ORDER_FIRST, f00f_hack, NULL);
2415 f00f_hack(void *unused)
2417 struct gate_descriptor *new_idt;
2425 printf("Intel Pentium detected, installing workaround for F00F bug\n");
2427 tmp = kmem_alloc(kernel_map, PAGE_SIZE * 2);
2429 panic("kmem_alloc returned 0");
2431 /* Put the problematic entry (#6) at the end of the lower page. */
2432 new_idt = (struct gate_descriptor*)
2433 (tmp + PAGE_SIZE - 7 * sizeof(struct gate_descriptor));
2434 bcopy(idt, new_idt, sizeof(idt0));
2435 r_idt.rd_base = (u_int)new_idt;
2438 if (vm_map_protect(kernel_map, tmp, tmp + PAGE_SIZE,
2439 VM_PROT_READ, FALSE) != KERN_SUCCESS)
2440 panic("vm_map_protect failed");
2442 #endif /* defined(I586_CPU) && !NO_F00F_HACK */
2445 * Construct a PCB from a trapframe. This is called from kdb_trap() where
2446 * we want to start a backtrace from the function that caused us to enter
2447 * the debugger. We have the context in the trapframe, but base the trace
2448 * on the PCB. The PCB doesn't have to be perfect, as long as it contains
2449 * enough for a backtrace.
2452 makectx(struct trapframe *tf, struct pcb *pcb)
2455 pcb->pcb_edi = tf->tf_edi;
2456 pcb->pcb_esi = tf->tf_esi;
2457 pcb->pcb_ebp = tf->tf_ebp;
2458 pcb->pcb_ebx = tf->tf_ebx;
2459 pcb->pcb_eip = tf->tf_eip;
2460 pcb->pcb_esp = (ISPL(tf->tf_cs)) ? tf->tf_esp : (int)(tf + 1) - 8;
2464 ptrace_set_pc(struct thread *td, u_long addr)
2467 td->td_frame->tf_eip = addr;
2472 ptrace_single_step(struct thread *td)
2474 td->td_frame->tf_eflags |= PSL_T;
2479 ptrace_clear_single_step(struct thread *td)
2481 td->td_frame->tf_eflags &= ~PSL_T;
2486 fill_regs(struct thread *td, struct reg *regs)
2489 struct trapframe *tp;
2493 regs->r_gs = pcb->pcb_gs;
2494 return (fill_frame_regs(tp, regs));
2498 fill_frame_regs(struct trapframe *tp, struct reg *regs)
2500 regs->r_fs = tp->tf_fs;
2501 regs->r_es = tp->tf_es;
2502 regs->r_ds = tp->tf_ds;
2503 regs->r_edi = tp->tf_edi;
2504 regs->r_esi = tp->tf_esi;
2505 regs->r_ebp = tp->tf_ebp;
2506 regs->r_ebx = tp->tf_ebx;
2507 regs->r_edx = tp->tf_edx;
2508 regs->r_ecx = tp->tf_ecx;
2509 regs->r_eax = tp->tf_eax;
2510 regs->r_eip = tp->tf_eip;
2511 regs->r_cs = tp->tf_cs;
2512 regs->r_eflags = tp->tf_eflags;
2513 regs->r_esp = tp->tf_esp;
2514 regs->r_ss = tp->tf_ss;
2519 set_regs(struct thread *td, struct reg *regs)
2522 struct trapframe *tp;
2525 if (!EFL_SECURE(regs->r_eflags, tp->tf_eflags) ||
2526 !CS_SECURE(regs->r_cs))
2529 tp->tf_fs = regs->r_fs;
2530 tp->tf_es = regs->r_es;
2531 tp->tf_ds = regs->r_ds;
2532 tp->tf_edi = regs->r_edi;
2533 tp->tf_esi = regs->r_esi;
2534 tp->tf_ebp = regs->r_ebp;
2535 tp->tf_ebx = regs->r_ebx;
2536 tp->tf_edx = regs->r_edx;
2537 tp->tf_ecx = regs->r_ecx;
2538 tp->tf_eax = regs->r_eax;
2539 tp->tf_eip = regs->r_eip;
2540 tp->tf_cs = regs->r_cs;
2541 tp->tf_eflags = regs->r_eflags;
2542 tp->tf_esp = regs->r_esp;
2543 tp->tf_ss = regs->r_ss;
2544 pcb->pcb_gs = regs->r_gs;
2548 #ifdef CPU_ENABLE_SSE
2550 fill_fpregs_xmm(sv_xmm, sv_87)
2551 struct savexmm *sv_xmm;
2552 struct save87 *sv_87;
2554 register struct env87 *penv_87 = &sv_87->sv_env;
2555 register struct envxmm *penv_xmm = &sv_xmm->sv_env;
2558 bzero(sv_87, sizeof(*sv_87));
2560 /* FPU control/status */
2561 penv_87->en_cw = penv_xmm->en_cw;
2562 penv_87->en_sw = penv_xmm->en_sw;
2563 penv_87->en_tw = penv_xmm->en_tw;
2564 penv_87->en_fip = penv_xmm->en_fip;
2565 penv_87->en_fcs = penv_xmm->en_fcs;
2566 penv_87->en_opcode = penv_xmm->en_opcode;
2567 penv_87->en_foo = penv_xmm->en_foo;
2568 penv_87->en_fos = penv_xmm->en_fos;
2571 for (i = 0; i < 8; ++i)
2572 sv_87->sv_ac[i] = sv_xmm->sv_fp[i].fp_acc;
2576 set_fpregs_xmm(sv_87, sv_xmm)
2577 struct save87 *sv_87;
2578 struct savexmm *sv_xmm;
2580 register struct env87 *penv_87 = &sv_87->sv_env;
2581 register struct envxmm *penv_xmm = &sv_xmm->sv_env;
2584 /* FPU control/status */
2585 penv_xmm->en_cw = penv_87->en_cw;
2586 penv_xmm->en_sw = penv_87->en_sw;
2587 penv_xmm->en_tw = penv_87->en_tw;
2588 penv_xmm->en_fip = penv_87->en_fip;
2589 penv_xmm->en_fcs = penv_87->en_fcs;
2590 penv_xmm->en_opcode = penv_87->en_opcode;
2591 penv_xmm->en_foo = penv_87->en_foo;
2592 penv_xmm->en_fos = penv_87->en_fos;
2595 for (i = 0; i < 8; ++i)
2596 sv_xmm->sv_fp[i].fp_acc = sv_87->sv_ac[i];
2598 #endif /* CPU_ENABLE_SSE */
2601 fill_fpregs(struct thread *td, struct fpreg *fpregs)
2604 KASSERT(td == curthread || TD_IS_SUSPENDED(td) ||
2605 P_SHOULDSTOP(td->td_proc),
2606 ("not suspended thread %p", td));
2610 bzero(fpregs, sizeof(*fpregs));
2612 #ifdef CPU_ENABLE_SSE
2614 fill_fpregs_xmm(&td->td_pcb->pcb_user_save.sv_xmm,
2615 (struct save87 *)fpregs);
2617 #endif /* CPU_ENABLE_SSE */
2618 bcopy(&td->td_pcb->pcb_user_save.sv_87, fpregs,
2624 set_fpregs(struct thread *td, struct fpreg *fpregs)
2627 #ifdef CPU_ENABLE_SSE
2629 set_fpregs_xmm((struct save87 *)fpregs,
2630 &td->td_pcb->pcb_user_save.sv_xmm);
2632 #endif /* CPU_ENABLE_SSE */
2633 bcopy(fpregs, &td->td_pcb->pcb_user_save.sv_87,
2642 * Get machine context.
2645 get_mcontext(struct thread *td, mcontext_t *mcp, int flags)
2647 struct trapframe *tp;
2648 struct segment_descriptor *sdp;
2652 PROC_LOCK(curthread->td_proc);
2653 mcp->mc_onstack = sigonstack(tp->tf_esp);
2654 PROC_UNLOCK(curthread->td_proc);
2655 mcp->mc_gs = td->td_pcb->pcb_gs;
2656 mcp->mc_fs = tp->tf_fs;
2657 mcp->mc_es = tp->tf_es;
2658 mcp->mc_ds = tp->tf_ds;
2659 mcp->mc_edi = tp->tf_edi;
2660 mcp->mc_esi = tp->tf_esi;
2661 mcp->mc_ebp = tp->tf_ebp;
2662 mcp->mc_isp = tp->tf_isp;
2663 mcp->mc_eflags = tp->tf_eflags;
2664 if (flags & GET_MC_CLEAR_RET) {
2667 mcp->mc_eflags &= ~PSL_C;
2669 mcp->mc_eax = tp->tf_eax;
2670 mcp->mc_edx = tp->tf_edx;
2672 mcp->mc_ebx = tp->tf_ebx;
2673 mcp->mc_ecx = tp->tf_ecx;
2674 mcp->mc_eip = tp->tf_eip;
2675 mcp->mc_cs = tp->tf_cs;
2676 mcp->mc_esp = tp->tf_esp;
2677 mcp->mc_ss = tp->tf_ss;
2678 mcp->mc_len = sizeof(*mcp);
2679 get_fpcontext(td, mcp);
2680 sdp = &td->td_pcb->pcb_fsd;
2681 mcp->mc_fsbase = sdp->sd_hibase << 24 | sdp->sd_lobase;
2682 sdp = &td->td_pcb->pcb_gsd;
2683 mcp->mc_gsbase = sdp->sd_hibase << 24 | sdp->sd_lobase;
2685 bzero(mcp->mc_spare2, sizeof(mcp->mc_spare2));
2690 * Set machine context.
2692 * However, we don't set any but the user modifiable flags, and we won't
2693 * touch the cs selector.
2696 set_mcontext(struct thread *td, const mcontext_t *mcp)
2698 struct trapframe *tp;
2702 if (mcp->mc_len != sizeof(*mcp))
2704 eflags = (mcp->mc_eflags & PSL_USERCHANGE) |
2705 (tp->tf_eflags & ~PSL_USERCHANGE);
2706 if ((ret = set_fpcontext(td, mcp)) == 0) {
2707 tp->tf_fs = mcp->mc_fs;
2708 tp->tf_es = mcp->mc_es;
2709 tp->tf_ds = mcp->mc_ds;
2710 tp->tf_edi = mcp->mc_edi;
2711 tp->tf_esi = mcp->mc_esi;
2712 tp->tf_ebp = mcp->mc_ebp;
2713 tp->tf_ebx = mcp->mc_ebx;
2714 tp->tf_edx = mcp->mc_edx;
2715 tp->tf_ecx = mcp->mc_ecx;
2716 tp->tf_eax = mcp->mc_eax;
2717 tp->tf_eip = mcp->mc_eip;
2718 tp->tf_eflags = eflags;
2719 tp->tf_esp = mcp->mc_esp;
2720 tp->tf_ss = mcp->mc_ss;
2721 td->td_pcb->pcb_gs = mcp->mc_gs;
2728 get_fpcontext(struct thread *td, mcontext_t *mcp)
2732 mcp->mc_fpformat = _MC_FPFMT_NODEV;
2733 mcp->mc_ownedfp = _MC_FPOWNED_NONE;
2734 bzero(mcp->mc_fpstate, sizeof(mcp->mc_fpstate));
2736 mcp->mc_ownedfp = npxgetregs(td);
2737 bcopy(&td->td_pcb->pcb_user_save, &mcp->mc_fpstate[0],
2738 sizeof(mcp->mc_fpstate));
2739 mcp->mc_fpformat = npxformat();
2744 set_fpcontext(struct thread *td, const mcontext_t *mcp)
2747 if (mcp->mc_fpformat == _MC_FPFMT_NODEV)
2749 else if (mcp->mc_fpformat != _MC_FPFMT_387 &&
2750 mcp->mc_fpformat != _MC_FPFMT_XMM)
2752 else if (mcp->mc_ownedfp == _MC_FPOWNED_NONE)
2753 /* We don't care what state is left in the FPU or PCB. */
2755 else if (mcp->mc_ownedfp == _MC_FPOWNED_FPU ||
2756 mcp->mc_ownedfp == _MC_FPOWNED_PCB) {
2758 #ifdef CPU_ENABLE_SSE
2760 ((union savefpu *)&mcp->mc_fpstate)->sv_xmm.sv_env.
2761 en_mxcsr &= cpu_mxcsr_mask;
2763 npxsetregs(td, (union savefpu *)&mcp->mc_fpstate);
2771 fpstate_drop(struct thread *td)
2774 KASSERT(PCB_USER_FPU(td->td_pcb), ("fpstate_drop: kernel-owned fpu"));
2777 if (PCPU_GET(fpcurthread) == td)
2781 * XXX force a full drop of the npx. The above only drops it if we
2782 * owned it. npxgetregs() has the same bug in the !cpu_fxsr case.
2784 * XXX I don't much like npxgetregs()'s semantics of doing a full
2785 * drop. Dropping only to the pcb matches fnsave's behaviour.
2786 * We only need to drop to !PCB_INITDONE in sendsig(). But
2787 * sendsig() is the only caller of npxgetregs()... perhaps we just
2788 * have too many layers.
2790 curthread->td_pcb->pcb_flags &= ~(PCB_NPXINITDONE |
2791 PCB_NPXUSERINITDONE);
2796 fill_dbregs(struct thread *td, struct dbreg *dbregs)
2801 dbregs->dr[0] = rdr0();
2802 dbregs->dr[1] = rdr1();
2803 dbregs->dr[2] = rdr2();
2804 dbregs->dr[3] = rdr3();
2805 dbregs->dr[4] = rdr4();
2806 dbregs->dr[5] = rdr5();
2807 dbregs->dr[6] = rdr6();
2808 dbregs->dr[7] = rdr7();
2811 dbregs->dr[0] = pcb->pcb_dr0;
2812 dbregs->dr[1] = pcb->pcb_dr1;
2813 dbregs->dr[2] = pcb->pcb_dr2;
2814 dbregs->dr[3] = pcb->pcb_dr3;
2817 dbregs->dr[6] = pcb->pcb_dr6;
2818 dbregs->dr[7] = pcb->pcb_dr7;
2824 set_dbregs(struct thread *td, struct dbreg *dbregs)
2830 load_dr0(dbregs->dr[0]);
2831 load_dr1(dbregs->dr[1]);
2832 load_dr2(dbregs->dr[2]);
2833 load_dr3(dbregs->dr[3]);
2834 load_dr4(dbregs->dr[4]);
2835 load_dr5(dbregs->dr[5]);
2836 load_dr6(dbregs->dr[6]);
2837 load_dr7(dbregs->dr[7]);
2840 * Don't let an illegal value for dr7 get set. Specifically,
2841 * check for undefined settings. Setting these bit patterns
2842 * result in undefined behaviour and can lead to an unexpected
2845 for (i = 0; i < 4; i++) {
2846 if (DBREG_DR7_ACCESS(dbregs->dr[7], i) == 0x02)
2848 if (DBREG_DR7_LEN(dbregs->dr[7], i) == 0x02)
2855 * Don't let a process set a breakpoint that is not within the
2856 * process's address space. If a process could do this, it
2857 * could halt the system by setting a breakpoint in the kernel
2858 * (if ddb was enabled). Thus, we need to check to make sure
2859 * that no breakpoints are being enabled for addresses outside
2860 * process's address space.
2862 * XXX - what about when the watched area of the user's
2863 * address space is written into from within the kernel
2864 * ... wouldn't that still cause a breakpoint to be generated
2865 * from within kernel mode?
2868 if (DBREG_DR7_ENABLED(dbregs->dr[7], 0)) {
2869 /* dr0 is enabled */
2870 if (dbregs->dr[0] >= VM_MAXUSER_ADDRESS)
2874 if (DBREG_DR7_ENABLED(dbregs->dr[7], 1)) {
2875 /* dr1 is enabled */
2876 if (dbregs->dr[1] >= VM_MAXUSER_ADDRESS)
2880 if (DBREG_DR7_ENABLED(dbregs->dr[7], 2)) {
2881 /* dr2 is enabled */
2882 if (dbregs->dr[2] >= VM_MAXUSER_ADDRESS)
2886 if (DBREG_DR7_ENABLED(dbregs->dr[7], 3)) {
2887 /* dr3 is enabled */
2888 if (dbregs->dr[3] >= VM_MAXUSER_ADDRESS)
2892 pcb->pcb_dr0 = dbregs->dr[0];
2893 pcb->pcb_dr1 = dbregs->dr[1];
2894 pcb->pcb_dr2 = dbregs->dr[2];
2895 pcb->pcb_dr3 = dbregs->dr[3];
2896 pcb->pcb_dr6 = dbregs->dr[6];
2897 pcb->pcb_dr7 = dbregs->dr[7];
2899 pcb->pcb_flags |= PCB_DBREGS;
2906 * Return > 0 if a hardware breakpoint has been hit, and the
2907 * breakpoint was in user space. Return 0, otherwise.
2910 user_dbreg_trap(void)
2912 u_int32_t dr7, dr6; /* debug registers dr6 and dr7 */
2913 u_int32_t bp; /* breakpoint bits extracted from dr6 */
2914 int nbp; /* number of breakpoints that triggered */
2915 caddr_t addr[4]; /* breakpoint addresses */
2919 if ((dr7 & 0x000000ff) == 0) {
2921 * all GE and LE bits in the dr7 register are zero,
2922 * thus the trap couldn't have been caused by the
2923 * hardware debug registers
2930 bp = dr6 & 0x0000000f;
2934 * None of the breakpoint bits are set meaning this
2935 * trap was not caused by any of the debug registers
2941 * at least one of the breakpoints were hit, check to see
2942 * which ones and if any of them are user space addresses
2946 addr[nbp++] = (caddr_t)rdr0();
2949 addr[nbp++] = (caddr_t)rdr1();
2952 addr[nbp++] = (caddr_t)rdr2();
2955 addr[nbp++] = (caddr_t)rdr3();
2958 for (i = 0; i < nbp; i++) {
2959 if (addr[i] < (caddr_t)VM_MAXUSER_ADDRESS) {
2961 * addr[i] is in user space
2968 * None of the breakpoints are in user space.
2976 * Provide inb() and outb() as functions. They are normally only available as
2977 * inline functions, thus cannot be called from the debugger.
2980 /* silence compiler warnings */
2981 u_char inb_(u_short);
2982 void outb_(u_short, u_char);
2991 outb_(u_short port, u_char data)