code:
/*	$OpenBSD: vm_machdep.c,v 1.33 2015/06/28 18:54:54 guenther Exp $	*/
/*	$NetBSD: vm_machdep.c,v 1.1 2003/04/26 18:39:33 fvdl Exp $	*/

/*-
 * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
 * Copyright (c) 1982, 1986 The Regents of the University of California.
 * Copyright (c) 1989, 1990 William Jolitz
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * the Systems Programming Group of the University of Utah Computer
 * Science Department, and William Jolitz.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
 */

/*
 *	Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/vnode.h>
#include <sys/buf.h>
#include <sys/user.h>
#include <sys/exec.h>
#include <sys/ptrace.h>
#include <sys/signalvar.h>

#include <uvm/uvm_extern.h>

#include <machine/cpu.h>
#include <machine/reg.h>
#include <machine/fpu.h>
#include <machine/tcb.h>

void setredzone(struct proc *);

/*
 * Finish a fork operation, with process p2 nearly set up.
 * Copy and update the kernel stack and pcb, making the child
 * ready to run, and marking it so that it can return differently
 * than the parent.  Returns 1 in the child process, 0 in the parent.
 */
void
cpu_fork(struct proc *p1, struct proc *p2, void *stack, size_t stacksize,
    void (*func)(void *), void *arg)
{
	struct pcb *pcb = &p2->p_addr->u_pcb;
	struct trapframe *tf;
	struct switchframe *sf;

	/*
	 * If fpuproc != p1, then the fpu h/w state is irrelevant and the
	 * state had better already be in the pcb.  This is true for forks
	 * but not for dumps.
	 *
	 * If fpuproc == p1, then we have to save the fpu h/w state to
	 * p1's pcb so that we can copy it.
	 */
	if (p1->p_addr->u_pcb.pcb_fpcpu != NULL)
		fpusave_proc(p1, 1);

	p2->p_md.md_flags = p1->p_md.md_flags;

	/* Copy pcb from proc p1 to p2. */
	if (p1 == curproc) {
		/* Sync the PCB before we copy it. */
		savectx(curpcb);
	}
#ifdef DIAGNOSTIC
	else if (p1 != &proc0)
		panic("cpu_fork: curproc");
#endif
	*pcb = p1->p_addr->u_pcb;

	/*
	 * Activate the address space.
	 */
	pmap_activate(p2);

	/* Record where this process's kernel stack is */
	pcb->pcb_kstack = (u_int64_t)p2->p_addr + USPACE - 16;

	/*
	 * Copy the trapframe.
	 */
	p2->p_md.md_regs = tf = (struct trapframe *)pcb->pcb_kstack - 1;
	*tf = *p1->p_md.md_regs;

	setredzone(p2);

	/*
	 * If specified, give the child a different stack.
	 */
	if (stack != NULL)
		tf->tf_rsp = (u_int64_t)stack + stacksize;

	sf = (struct switchframe *)tf - 1;
	sf->sf_r12 = (u_int64_t)func;
	sf->sf_r13 = (u_int64_t)arg;
	sf->sf_rip = (u_int64_t)proc_trampoline;
	pcb->pcb_rsp = (u_int64_t)sf;
	pcb->pcb_rbp = 0;
}

/*
 * cpu_exit is called as the last action during exit.
 *
 * We clean up a little and then call sched_exit() with the old proc as an
 * argument.
 */
void
cpu_exit(struct proc *p)
{

	/* If we were using the FPU, forget about it. */
	if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
		fpusave_proc(p, 0);

	pmap_deactivate(p);
	sched_exit(p);
}

/*
 * Set a red zone in the kernel stack after the u. area.
 */
void
setredzone(struct proc *p)
{
#if 0
	pmap_remove(pmap_kernel(), (vaddr_t)p->p_addr + PAGE_SIZE,
	    (vaddr_t)p->p_addr + 2 * PAGE_SIZE);
	pmap_update(pmap_kernel());
#endif
}

/*
 * Map a user I/O request into kernel virtual address space.
 * Note: the pages are already locked by uvm_vslock(), so we
 * do not need to pass an access_type to pmap_enter().
 */
void
vmapbuf(struct buf *bp, vsize_t len)
{
	vaddr_t faddr, taddr, off;
	paddr_t fpa;

	if ((bp->b_flags & B_PHYS) == 0)
		panic("vmapbuf");
	faddr = trunc_page((vaddr_t)(bp->b_saveaddr = bp->b_data));
	off = (vaddr_t)bp->b_data - faddr;
	len = round_page(off + len);
	taddr= uvm_km_valloc_wait(phys_map, len);
	bp->b_data = (caddr_t)(taddr + off);
	/*
	 * The region is locked, so we expect that pmap_pte() will return
	 * non-NULL.
	 * XXX: unwise to expect this in a multithreaded environment.
	 * anything can happen to a pmap between the time we lock a
	 * region, release the pmap lock, and then relock it for
	 * the pmap_extract().
	 *
	 * no need to flush TLB since we expect nothing to be mapped
	 * where we we just allocated (TLB will be flushed when our
	 * mapping is removed).
	 */
	while (len) {
		(void) pmap_extract(vm_map_pmap(&bp->b_proc->p_vmspace->vm_map),
		    faddr, &fpa);
		pmap_kenter_pa(taddr, fpa, PROT_READ | PROT_WRITE);
		faddr += PAGE_SIZE;
		taddr += PAGE_SIZE;
		len -= PAGE_SIZE;
	}
}

/*
 * Unmap a previously-mapped user I/O request.
 */
void
vunmapbuf(struct buf *bp, vsize_t len)
{
	vaddr_t addr, off;

	if ((bp->b_flags & B_PHYS) == 0)
		panic("vunmapbuf");
	addr = trunc_page((vaddr_t)bp->b_data);
	off = (vaddr_t)bp->b_data - addr;
	len = round_page(off + len);
	pmap_kremove(addr, len);
	pmap_update(pmap_kernel());
	uvm_km_free_wakeup(phys_map, addr, len);
	bp->b_data = bp->b_saveaddr;
	bp->b_saveaddr = 0;
}

void *
tcb_get(struct proc *p)
{
	return ((void *)p->p_addr->u_pcb.pcb_fsbase);
}

void
tcb_set(struct proc *p, void *tcb)
{
	KASSERT(p == curproc);
	reset_segs(&p->p_addr->u_pcb, (u_int64_t)tcb);
}


code:
/*	$OpenBSD: wscons_machdep.c,v 1.10 2011/06/28 20:19:18 matthieu Exp $ */

/*
 * Copyright (c) 2001 Aaron Campbell
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/extent.h>

#include <machine/bus.h>

#include <dev/cons.h>

#include "vga.h"
#include "pcdisplay.h"
#if (NVGA > 0) || (NPCDISPLAY > 0)
#include <dev/ic/mc6845reg.h>
#include <dev/ic/pcdisplayvar.h>
#if (NVGA > 0)
#include <dev/ic/vgareg.h>
#include <dev/ic/vgavar.h>
#endif
#if (NPCDISPLAY > 0)
#include <dev/isa/pcdisplayvar.h>
#endif
#endif

#include "wsdisplay.h"
#if NWSDISPLAY > 0
#include <dev/wscons/wsdisplayvar.h>
#endif

#include "pckbc.h"
#if (NPCKBC > 0)
#include <dev/isa/isareg.h>
#include <dev/ic/i8042reg.h>
#include <dev/ic/pckbcvar.h>
#endif
#include "pckbd.h"
#include "ukbd.h"
#if (NUKBD > 0)
#include <dev/usb/ukbdvar.h>
#endif
#include "wskbd.h"
#if NWSKBD > 0
#include <dev/wscons/wskbdvar.h>
#endif

void	wscn_video_init(void);
void	wscn_input_init(int);

cons_decl(ws);

void
wscnprobe(struct consdev *cp)
{
	int maj;

	/* locate the major number */
	for (maj = 0; maj < nchrdev; maj++) {
		if (cdevsw[maj].d_open == wsdisplayopen)
			break;
	}

	if (maj == nchrdev) {
		/* we are not in cdevsw[], give up */
		panic("wsdisplay is not in cdevsw[]");
	}

	cp->cn_dev = makedev(maj, 0);
	cp->cn_pri = CN_MIDPRI;
}

void
wscninit(struct consdev *cp)
{
	static int initted = 0;

	if (initted)
		return;
	initted = 1;

	wscn_video_init();
	wscn_input_init(0);
}

void
wscnputc(dev_t dev, int i)
{
	wsdisplay_cnputc(dev, i);
}

int
wscngetc(dev_t dev)
{
	return (wskbd_cngetc(dev));
}

void
wscnpollc(dev_t dev, int on)
{
	wskbd_cnpollc(dev, on);
}

/*
 * Configure the display part of the console.
 */
void
wscn_video_init()
{
#if (NVGA > 0)
	if (vga_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM, -1, 1) == 0)
		return;
#endif
#if (NPCDISPLAY > 0)
	if (pcdisplay_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM) == 0)
		return;
#endif
}

/*
 * Configure the keyboard part of the console.
 * This is tricky, because of the games USB controllers play.
 *
 * On a truly legacy-free design, no PS/2 keyboard controller will be
 * found, so we'll settle for the first USB keyboard as the console
 * input device.
 *
 * Otherwise, the PS/2 controller will claim console, even if no PS/2
 * keyboard is plugged into it.  This is intentional, so that a PS/2
 * keyboard can be plugged late (even though this is theoretically not
 * allowed, most PS/2 controllers survive this).
 *
 * However, if there isn't any PS/2 keyboard connector, but an USB
 * controller in Legacy mode, the kernel will detect a PS/2 keyboard
 * connected (while there really isn't any), until the USB controller
 * driver attaches. At that point the ghost of the legacy keyboard
 * flees away.
 *
 * The pckbc(4) driver will, however, detect that the keyboard is gone
 * missing, and will invoke this function again, allowing a new console
 * input device choice.
 */

void
wscn_input_init(int pass)
{
	if (pass != 0) {
#if NWSKBD > 0
		wskbd_cndetach();
#endif
	}

#if (NPCKBC > 0)
	if (pass == 0 &&
	    pckbc_cnattach(X86_BUS_SPACE_IO, IO_KBD, KBCMDP, 0) == 0)
			return;
#endif
#if (NUKBD > 0)
	if (ukbd_cnattach() == 0)
		return;
#endif
}

license: unknown


code:
GENERIC
GENERIC.MP
RAMDISK
RAMDISK_CD


code:
/.cvsignore/1.4/Fri Jun 25 11:03:28 2004//TOPENBSD_5_8_BASE
D


code:
#	$OpenBSD: GENERIC,v 1.392 2015/07/23 00:38:04 deraadt Exp $
#
# For further information on compiling OpenBSD kernels, see the config(8)
# man page.
#
# For further information on hardware support for this architecture, see
# the intro(4) man page.  For further information about kernel options
# for this architecture, see the options(4) man page.  For an explanation
# of each device driver in this file see the section 4 man page for the
# device.

machine		amd64
include		"../../../conf/GENERIC"
maxusers	80			# estimated number of users

option		USER_PCICONF	# user-space PCI configuration

#option		VM86		# Virtual 8086 emulation
option		APERTURE	# in-kernel aperture driver for XFree86
option		MTRR		# CPU memory range attributes control

#option		KGDB		# Remote debugger support; exclusive of DDB
#option		"KGDB_DEVNAME=\"com\"",KGDBADDR=0x2f8,KGDBRATE=9600

#option		GPT		# GPT partition table support
option		NTFS		# NTFS support
option		HIBERNATE	# Hibernate support

config		bsd	swap generic

mainbus0 at root

bios0	at mainbus?
cpu0	at mainbus?
ioapic*	at mainbus?
isa0	at mainbus0
isa0	at pcib?
isa0	at amdpcib?
isa0	at tcpcib?
pci*	at mainbus0
pvbus0	at mainbus0

acpi0		at bios0
acpitimer*	at acpi?
acpihpet*	at acpi?
acpiac*		at acpi?
acpibat*	at acpi?
acpibtn*	at acpi?
acpicpu*	at acpi?
acpidock*	at acpi?
acpiec*		at acpi?
acpiprt*	at acpi?
acpitz*		at acpi?
acpimadt0	at acpi?
acpimcfg*	at acpi?
acpiasus*	at acpi?
acpisony*	at acpi?
acpithinkpad*	at acpi?
acpitoshiba*	at acpi?
acpivideo*	at acpi?
acpivout*	at acpivideo?
acpipwrres*	at acpi?
aibs*		at acpi?

mpbios0		at bios0

ipmi0	at mainbus? disable	# IPMI

vmt0	at pvbus?		# VMware Tools

option		PCIVERBOSE
option		USBVERBOSE

pchb*	at pci?			# PCI-Host bridges
aapic*	at pci?			# AMD 8131 IO apic
ppb*	at pci?			# PCI-PCI bridges
pci*	at ppb?
pci*	at pchb?
pcib*	at pci?			# PCI-ISA bridge
amdpcib* at pci?		# AMD 8111 LPC bridge
tcpcib*	at pci?			# Intel Atom E600 LPC bridge
kate*	at pci?			# AMD K8 temperature sensor
km*	at pci?			# AMD K10 temperature sensor
amas*	at pci? disable		# AMD memory configuration

# National Semiconductor LM7[89] and compatible hardware monitors
lm0	at isa? port 0x290
#lm1	at isa? port 0x280
#lm2	at isa? port 0x310

it*	at isa? port 0x2e	# ITE IT8705F, IT8712F, IT8716F, IT8718F,
it*	at isa? port 0x4e	# IT8726F and SiS SiS950 monitors and
				# watchdog timer

schsio*	at isa? port 0x2e	# SMSC SCH311x Super I/O
schsio*	at isa? port 0x4e
schsio*	at isa? port 0x162e
schsio*	at isa? port 0x164e

#viasio* at isa? port 0x2e flags 0x0000	# VIA VT1211 LPC Super I/O
#viasio* at isa? port 0x4e flags 0x0000

wbsio*	at isa? port 0x2e	# Winbond LPC Super I/O
wbsio*	at isa? port 0x4e
lm*	at wbsio?
uguru0	at isa? disable port 0xe0	# ABIT uGuru

aps0	at isa? port 0x1600		# ThinkPad Active Protection System

piixpm*	at pci?			# Intel PIIX PM
iic*	at piixpm?
ichiic*	at pci?			# Intel ICH SMBus controller
iic*	at ichiic?
viapm*	at pci?			# VIA SMBus controller
iic*	at viapm?
amdiic* at pci?			# AMD-8111 SMBus controller
iic*	at amdiic?
nviic*	at pci?			# NVIDIA nForce2/3/4 SMBus controller
iic*	at nviic?
amdpm*	at pci?			# AMD-7xx/8111 and NForce SMBus controller
iic*	at amdpm?

itherm*	at pci?			# Intel 3400 Thermal Sensor
adc*	at iic?			# Analog Devices AD7416/AD7417/7418
adl*	at iic?			# Andigilog aSC7621
admtemp* at iic?		# Analog Devices ADM1021
admlc*	at iic?			# Analog Devices ADM1024
admtm*	at iic?			# Analog Devices ADM1025
admcts*	at iic?			# Analog Devices ADM1026
admtmp*	at iic?			# Analog Devices ADM1030
admtt*	at iic?			# Analog Devices ADM1031
adt*	at iic?			# Analog Devices ADT7460
andl*	at iic?			# Andigilog aSC7611
lisa*	at iic?			# STMicroelectronics LIS331DL motion sensor
lm*	at iic?			# National Semiconductor LM78/79
lmenv*	at iic?			# National Semiconductor LM87
lmtemp*	at iic?			# National Semiconductor LM75/LM77
lmn*	at iic?			# National Semiconductor LM93
maxds*	at iic?			# Maxim DS1631
maxtmp*	at iic?			# Maxim MAX6642/MAX6690
spdmem*	at iic?			# SPD memory eeproms
sdtemp*	at iic?			# SO-DIMM (JC-42.4) temperature
wbng*	at iic?			# Winbond W83793G
nvt*	at iic?			# Novoton W83795G

skgpio0 at isa? port 0x680	# Soekris net6501 GPIO and LEDs
gpio* at skgpio?

#option PCMCIAVERBOSE

# PCI PCMCIA controllers
#pcic*	at pci?

# PCMCIA bus support
#pcmcia*	at pcic?

# CardBus bus support
cbb*		at pci?
cardslot*	at cbb?
cardbus*	at cardslot?
pcmcia*		at cardslot?

# USB Controllers
xhci*	at pci?			# eXtensible Host Controller
ehci*	at pci?			# Enhanced Host Controller
ehci*	at cardbus?		# Enhanced Host Controller
uhci*	at pci?			# Universal Host Controller (Intel)
uhci*	at cardbus?		# Universal Host Controller (Intel)
ohci*	at pci?			# Open Host Controller
ohci*	at cardbus?		# Open Host Controller

# USB bus support
usb*	at xhci?
usb*	at ehci?
usb*	at uhci?
usb*	at ohci?

# USB devices
uhub*	at usb?			# USB Hubs
uhub*	at uhub?		# USB Hubs
ualea*	at uhub?		# Araneus Alea II TRNG
umodem*	at uhub?		# USB Modems/Serial
ucom*	at umodem?
uvisor*	at uhub?		# Handspring Visor
ucom*	at uvisor?
uvscom*	at uhub?		# SUNTAC Slipper U VS-10U serial
ucom*	at uvscom?
ubsa*	at uhub?		# Belkin serial adapter
ucom*	at ubsa?
uftdi*	at uhub?		# FTDI FT8U100AX serial adapter
ucom*	at uftdi?
uplcom* at uhub?		# I/O DATA USB-RSAQ2 serial adapter
ucom*	at uplcom?
umct*	at uhub?		# MCT USB-RS232 serial adapter
ucom*	at umct?
uslcom*	at uhub?		# Silicon Laboratories CP210x serial
ucom*	at uslcom?
uark*	at uhub?		# Arkmicro ARK3116 serial
ucom*	at uark?
moscom*	at uhub?		# MosChip MCS7703 serial
ucom*	at moscom?
umcs*	at uhub?		# MosChip MCS78x0 serial
ucom*	at umcs?
uipaq*	at uhub?		# iPAQ serial adapter
ucom*	at uipaq?
umsm*	at uhub?		# Qualcomm MSM EVDO
ucom*	at umsm?
uchcom*	at uhub?		# WinChipHead CH341/340 serial
ucom*	at uchcom?
uticom*	at uhub?		# TI serial
ucom*	at uticom?
uaudio* at uhub?		# USB Audio
audio*	at uaudio?
umidi*	at uhub?		# USB MIDI
midi*	at umidi?
ulpt*	at uhub?		# USB Printers
umass*	at uhub?		# USB Mass Storage devices
ubcmtp*	at uhub?		# Broadcom USB trackpad
wsmouse* at ubcmtp? mux 0
uhidev*	at uhub?		# Human Interface Devices
ums*	at uhidev?		# USB mouse
wsmouse* at ums? mux 0
uts*	at uhub?		# USB touchscreen
wsmouse* at uts? mux 0
ukbd*	at uhidev?		# USB keyboard
wskbd*	at ukbd? mux 1
ucycom*	at uhidev?			# Cypress serial
ucom*	at ucycom?
uslhcom* at uhidev?		# Silicon Labs CP2110 USB HID UART
ucom*	at uslhcom?
uhid*	at uhidev?		# USB generic HID support
upd*	at uhidev?		# USB Power Devices sensors
aue*	at uhub?		# ADMtek AN986 Pegasus Ethernet
atu*	at uhub?		# Atmel AT76c50x based 802.11b
axe*	at uhub?		# ASIX Electronics AX88172 USB Ethernet
axen*	at uhub?		# ASIX Electronics AX88179 USB Ethernet
cue*	at uhub?		# CATC USB-EL1201A based Ethernet
kue*	at uhub?		# Kawasaki KL5KUSB101B based Ethernet
smsc*	at uhub?		# SMSC LAN95xx Ethernet
cdce*	at uhub?		# CDC Ethernet
urndis*	at uhub?		# Remote NDIS Ethernet
upl*	at uhub?		# Prolific PL2301/PL2302 host-to-host `network'
ugl*	at uhub?		# Genesys Logic GL620USB-A host-to-host `network'
udav*	at uhub?		# Davicom DM9601 based Ethernet
mos*	at uhub?		# MOSCHIP MCS7730/7830 10/100 Ethernet
url*	at uhub?		# Realtek RTL8150L based adapters
wi*	at uhub?		# WaveLAN IEEE 802.11DS
udsbr*	at uhub?		# D-Link DSB-R100 radio
radio*	at udsbr?		# USB radio
uberry*	at uhub?		# Research In Motion BlackBerry
ugen*	at uhub?		# USB Generic driver
uath*	at uhub?		# Atheros AR5005UG/AR5005UX
ural*	at uhub?		# Ralink RT2500USB
rum*	at uhub?		# Ralink RT2501USB/RT2601USB
run*	at uhub?		# Ralink RT2700U/RT2800U/RT3000U
otus*	at uhub?		# Atheros AR9001U
athn*	at uhub?		# Atheros AR9002U
zyd*	at uhub?		# Zydas ZD1211
upgt*	at uhub?		# Conexant/Intersil PrismGT SoftMAC USB
urtw*	at uhub?		# Realtek 8187
rsu*	at uhub?		# Realtek RTL8188SU/RTL8191SU/RTL8192SU
urtwn*	at uhub?		# Realtek RTL8188CU/RTL8192CU
udcf*	at uhub?		# Gude Expert mouseCLOCK
uthum*	at uhidev?		# TEMPerHUM sensor
ugold*	at uhidev?		# gold TEMPer sensor
utrh*	at uhidev?		# USBRH sensor
utwitch* at uhidev?		# YUREX BBU sensor
uow*	at uhub?		# Maxim/Dallas DS2490 1-Wire adapter
uoakrh*	at uhidev?		# Toradex OAK temp and rel humidity
uoaklux* at uhidev?		# Toradex OAK LUX
uoakv*	at uhidev?		# Toradex OAK 10V sensor
onewire* at uow?
uvideo*	at uhub?		# USB Video
video*	at uvideo?
udl*	at uhub?		# DisplayLink USB displays
wsdisplay* at udl?

puc*	at pci?			# PCI "universal" communication device
com*	at cardbus?

sdhc*	at pci?			# SD Host Controller
sdmmc*	at sdhc?		# SD/MMC bus
rtsx*	at pci?			# Realtek SD Card Reader
sdmmc*	at rtsx?		# SD/MMC bus

isadma0	at isa?

option	WSDISPLAY_COMPAT_USL		# VT handling
option	WSDISPLAY_COMPAT_RAWKBD		# provide raw scancodes; needed for X11
option	WSDISPLAY_DEFAULTSCREENS=6	# initial number of text consoles
option	WSDISPLAY_COMPAT_PCVT		# emulate some ioctls; needed for X11

pckbc0		at isa? flags 0x00	# PC keyboard controller
pckbd*		at pckbc?		# PC keyboard
pms*		at pckbc?		# PS/2 mouse for wsmouse
vga0		at isa?
option		X86EMU			# to POST video cards
vga*		at pci?
wsdisplay0	at vga? console 1
wskbd*		at pckbd? mux 1
wsmouse*	at pms? mux 0

intagp*		at vga?		# intel integrated graphics
#mmuagp*	at pchb?	# amd64 mmu agp.

agp*		at intagp?
#agp*		at mmuagp?

inteldrm*	at vga? 	# Intel i915, i945 DRM driver
drm0		at inteldrm? console 1
drm*		at inteldrm?
radeondrm*	at pci? 	# ATI Radeon DRM driver
drm0		at radeondrm? console 1
drm*		at radeondrm?
wsdisplay0	at radeondrm? console 1
wsdisplay*	at radeondrm?

pcppi0		at isa?

com0	at isa? port 0x3f8 irq 4	# standard PC serial ports
com1	at isa? port 0x2f8 irq 3
com2	at isa? port 0x3e8 irq 5
com3	at isa? disable port 0x2e8 irq 9 # (conflicts with some video cards)

com*	at pcmcia?			# PCMCIA modems/serial ports
com*	at puc?

# options CY_HW_RTS
#cy*	at pci?				# PCI cyclom serial card
#cz*	at pci?				# Cyclades-Z multi-port serial boards

lpt0	at isa? port 0x378 irq 7	# standard PC parallel ports
#lpt1	at isa? port 0x278
#lpt2	at isa? port 0x3bc
lpt*	at puc?

#bha*	at pci?				# BusLogic [57]4X SCSI controllers
ahc*	at pci?				# Adaptec 2940 SCSI controllers
jmb*	at pci?				# JMicron JMB36x controllers
ahci*	at jmb? flags 0x0000		# flags 0x0001 to force SATA 1 (1.5Gb/s)
pciide*	at jmb?
ahci*	at pci? flags 0x0000		# AHCI SATA controllers
					# flags 0x0001 to force SATA 1 (1.5Gb/s)
sili*	at pci?				# Silicon Image 3124/3132/3531 SATA
ahd*	at pci?				# Adaptec 79?? SCSI controllers
arc*	at pci?				# Areca RAID Controller
mpi*	at pci?				# LSI Logic Message Passing Interface
mpii*	at pci?				# LSI Message Passing Interface II
gdt*	at pci?				# ICP Vortex GDT RAID controllers
twe*	at pci?				# 3ware Escalade RAID controllers
#aac*	at pci?				# Adaptec FSA RAID controllers
ami*	at pci?				# AMI MegaRAID controllers
mfi*	at pci?				# LSI MegaRAID SAS controllers
mfii*	at pci?				# LSI MegaRAID SAS Fusion controllers
#cac*	at pci?				# Compaq Smart ARRAY [234]* RAID controllers
ciss*	at pci?				# Compaq Smart ARRAY [56]* RAID controllers
iha*	at pci?				# Initio Ultra/UltraWide SCSI controllers
ips*	at pci?				# IBM ServeRAID controllers
qlw*	at pci?				# QLogic ISP SCSI
qla*	at pci?				# QLogic ISP 2[123]xx FibreChannel
qle*	at pci?				# QLogic ISP 2[45]xx FibreChannel
aic*	at pcmcia?			# PCMCIA Adaptec 152[02] SCSI
#esp*	at pcmcia?			# PCMCIA based NCR 53C9X SCSI
#siop*	at pci?				# NCR 538XX SCSI controllers
#adv*	at pci?				# AdvanSys 1200A/B and ULTRA SCSI
#adw*	at pci?				# AdvanSys ULTRA WIDE SCSI
pcscp*	at pci?				# AMD 53c974 PCscsi-PCI SCSI
#trm*	at pci?				# Tekram DC-3x5U SCSI Controllers
vmwpvs*	at pci?				# VMware ParaVirtual SCSI

scsibus* at scsi?
sd*	at scsibus?			# SCSI disk drives
st*	at scsibus?			# SCSI tape drives
cd*	at scsibus?			# SCSI CD-ROM drives
ch*	at scsibus?			# SCSI autochangers
safte*	at scsibus?			# SCSI accessed fault-tolerant encl
ses*	at scsibus?			# SCSI enclosure services
uk*	at scsibus?			# unknown SCSI

mpath0	at root
emc*	at scsibus?
hds*	at scsibus?
rdac*	at scsibus?
sym*	at scsibus?

fdc0	at isa? port 0x3f0 irq 6 drq 2	# standard PC floppy controllers
#fdc1	at isa? port 0x370
fd*	at fdc? flags 0x00

# IDE controllers
pciide* at pci? flags 0x0000

wdc0	at isa? disable port 0x1f0 irq 14 flags 0x00
wdc1	at isa? disable port 0x170 irq 15 flags 0x00
wdc*	at pcmcia?

# IDE hard drives
wd*	at wdc? flags 0x0000
wd*	at pciide? flags 0x0000

# ATAPI<->SCSI
atapiscsi* at wdc?
atapiscsi* at pciide?

# Networking devices
de*	at pci?				# DC21X4X-based ethernet
#fxp*	at pci?				# EtherExpress 10/100B ethernet
#fxp*	at cardbus?			# Intel PRO/100 ethernet
ne*	at pci?				# NE2000-compat ethernet
ep*	at pci?				# 3C59x ethernet
ne*	at pcmcia?			# PCMCIA based NE2000 ethernet
ep*	at pcmcia?			# PCMCIA based 3C5xx ethernet
sm*	at pcmcia?			# PCMCIA based sm ethernet
xe*	at pcmcia?			# Xircom ethernet
xl*	at pci?				# 3C9xx ethernet
xl*	at cardbus?			# 3C575/3C656 ethernet
rl*	at pci?				# Realtek 81[23]9 ethernet
rl*	at cardbus?			# Realtek 81[23]9 ethernet
#mtd*	at pci?				# Myson MTD800/803/891
epic*	at pci?				# SMC EPIC/100 ethernet
#tl*	at pci?				# Compaq Thunderlan ethernet
vr*	at pci?				# VIA Rhine ethernet
#wb*	at pci?				# Winbond W89C840F ethernet
sf*	at pci?				# Adaptec AIC-6915 ethernet
sis*	at pci?				# SiS 900/7016 ethernet
se*	at pci?				# SiS 190/191 ethernet
#ste*	at pci?				# Sundance ST201 ethernet BORKED
pcn*	at pci?				# AMD PCnet-PCI Ethernet
dc*	at pci?				# 21143, "tulip" clone ethernet
dc*	at cardbus?			# 21143, "tulip" clone ethernet
ti*	at pci?				# Alteon Tigon 1Gb ethernet
skc*	at pci?				# SysKonnect GEnesis 984x
sk*	at skc?				#  each port of above
mskc*	at pci?				# Marvell Yukon-2
msk*	at mskc?			#  each port of above
em*	at pci?				# Intel Pro/1000 ethernet
ixgb*	at pci?				# Intel Pro/10Gb ethernet
ix*	at pci?				# Intel 82598EB 10Gb ethernet
myx*	at pci?				# Myricom Myri-10G 10Gb ethernet
oce*	at pci?				# Emulex OneConnect 10Gb ethernet
txp*	at pci?				# 3com 3CR990
#nge*	at pci?				# NS DP83820/DP83821 GigE
bge*	at pci?				# Broadcom BCM57xx (aka Tigon3)
bnx*	at pci?				# Broadcom BCM5706/5708 GigE
re*	at pci?				# Realtek 8169/8169S/8110S
re*	at cardbus?			# Realtek 8169/8169S/8110S
stge*	at pci?				# Sundance TC9021 GigE
#lge*	at pci?				# Level1 LXT1001 GigE
hme*	at pci?				# Sun Happy Meal
vge*	at pci?				# VIA VT612x
nfe*	at pci?				# NVIDIA nForce Ethernet
xge*	at pci?				# Neterion Xframe-I/II 10Gb ethernet
thtc*	at pci?				# Tehuti Networks 10Gb ethernet
tht*	at thtc?
gem*	at pci?				# Sun GEM 10/100/Gigabit
cas*	at pci?				# Sun Cassini 100/Gigabit
bce*	at pci?				# Broadcom BCM4401
vic*	at pci?				# VMware VMXnet virtual interface
vmx*	at pci?				# VMware VMXNET3 virtual interface
et*	at pci?				# Agere/LSI ET1310
age*	at pci?				# Attansic L1 Ethernet
alc*	at pci?				# Attansic L1C/L1D/L2C Ethernet
ale*	at pci?				# Attansic L1E Ethernet
lii*	at pci?				# Attansic L2 Ethernet
jme*	at pci?				# JMicron JMC250/JMC260 Ethernet

# Wireless network cards
acx*	at pci?				# TI ACX100/ACX111 (802.11b/g)
acx*	at cardbus?			# TI ACX100/ACX111 (802.11b/g)
ath*	at pci?				# Atheros AR5k (802.11a/b/g)
ath*	at cardbus?			# Atheros AR5k (802.11a/b/g)
athn*	at pci?				# Atheros AR9k (802.11a/g/n)
athn*	at cardbus?			# Atheros AR9k (802.11a/g/n)
atw*	at pci?				# ADMtek ADM8211 (802.11)
atw*	at cardbus?			# ADMtek ADM8211 (802.11)
bwi*	at pci?				# Broadcom AirForce (802.11b/g)
bwi*	at cardbus?			# Broadcom AirForce (802.11b/g)
wi*	at pci?				# WaveLAN IEEE 802.11DS
wi*	at pcmcia?			# WaveLAN IEEE 802.11DS
an*	at pci?				# Aironet IEEE 802.11DS
an*	at pcmcia?			# Aironet IEEE 802.11DS
cnw*	at pcmcia?			# Xircom Netwave
iwi*	at pci?				# Intel PRO/Wireless 2200BG/2915ABG
wpi*	at pci?				# Intel PRO/Wireless 3945ABG
iwn*	at pci?				# Intel WiFi Link 4965/5000/1000/6000
iwm*	at pci?				# Intel WiFi Link 7xxx
ral*	at pci?				# Ralink RT2500/RT2501/RT2600
ral*	at cardbus?			# Ralink RT2500/RT2501/RT2600
rtw*	at pci?				# Realtek 8180
rtw*	at cardbus?			# Realtek 8180
rtwn*	at pci?				# Realtek 8188CE/8192CE
pgt*	at pci?				# Prism54 (only full-mac varients)
pgt*	at cardbus?			# Prism54 (only full-mac varients)
malo*	at pci?				# Marvell Libertas
malo*	at cardbus?			# Marvell Libertas
malo*	at pcmcia?			# Marvell 88W8385

# Media Independent Interface (mii) drivers
exphy*	at mii?				# 3Com internal PHYs
inphy*	at mii?				# Intel 82555 PHYs
iophy*	at mii?				# Intel 82553 PHYs
icsphy*	at mii?				# ICS 1890 PHYs
lxtphy*	at mii?				# Level1 LXT970 PHYs
nsphy*	at mii?				# NS and compatible PHYs
nsphyter*	at mii?			# NS and compatible PHYs
qsphy*	at mii?				# Quality Semi QS6612 PHYs
luphy*	at mii?				# Lucent LU6612 PHY
sqphy*	at mii?				# Seeq 8x220 PHYs
rlphy* at mii?				# Realtek 8139 internal PHYs
mtdphy* at mii?				# Myson MTD972 PHYs
dcphy*	at mii?				# Digital Clone PHYs
acphy*	at mii?				# Altima AC101 PHYs
amphy*	at mii?				# AMD 79C873 PHYs
tqphy*	at mii?				# TDK 78Q212x PHYs
bmtphy*	at mii?				# Broadcom 10/100 PHYs
brgphy*	at mii?				# Broadcom Gigabit PHYs
eephy* at mii?				# Marvell 88E1000 series PHY
xmphy*	at mii?				# XaQti XMAC-II PHYs
nsgphy*	at mii?				# NS gigabit PHYs
rgephy*	at mii?				# Realtek 8169S/8110S PHY
urlphy*	at mii?				# Realtek RTL8150L internal PHY
ciphy*	at mii?				# Cicada CS8201 10/100/1000 copper PHY
gentbi*	at mii?				# Generic 1000BASE-X ten-bit PHY
etphy*	at mii?				# Agere/LSI ET1011 TruePHY
jmphy*	at mii?				# JMicron JMP202/JMP211 PHYs
atphy*	at mii?				# Attansic F1 PHYs
ipgphy*	at mii?				# IC Plus IP1000A PHYs
ukphy*	at mii?				# "unknown" PHYs

eap*	at pci?				# Ensoniq AudioPCI S5016
envy*	at pci?				# VIA Envy24 (aka ICE1712)
#eso*	at pci?				# ESS Solo-1 PCI AudioDrive
#sv*	at pci?				# S3 SonicVibes (S3 617)
#neo*	at pci?				# NeoMagic 256AV/ZX
cmpci*	at pci?				# C-Media CMI8338/8738
auacer*	at pci?				# Acer Labs M5455
auich*	at pci? flags 0x0000		# i82801 ICH AC'97 audio
auixp*	at pci?				# ATI IXP AC'97 Audio
#autri*	at pci? flags 0x0000		# Trident 4D WAVE
auvia*	at pci?				# VIA VT82C686A
azalia*	at pci?				# High Definition Audio
clcs*	at pci?				# CS4280 CrystalClear audio
#clct*	at pci?				# CS4281 CrystalClear audio
#fms*	at pci?				# Forte Media FM801
#maestro* at pci?			# ESS Maestro PCI
#esa*	at pci?				# ESS Maestro3 PCI
yds*	at pci? flags 0x0000		# Yamaha YMF Audio
emu*	at pci?				# SB Live!
mpu*	at isa? port 0x330

# MIDI support
#midi*	at autri?
midi*	at eap?
midi*	at envy?
midi*	at mpu?

spkr0	at pcppi?		# PC speaker

# Audio Support
audio*	at eap?
audio*	at envy?
#audio*	at eso?
#audio*	at sv?
#audio*	at neo?
audio*	at cmpci?
audio*	at clcs?
#audio*	at clct?
audio*	at auacer?
audio*	at auich?
audio*	at auixp?
#audio*	at autri?
audio*	at auvia?
audio*	at azalia?
#audio*	at fms?
audio*	at uaudio?
#audio*	at maestro?
#audio*	at esa?
audio*	at yds?
audio*	at emu?

bktr0	at pci?

# FM-Radio devices
#gtp*	at pci?			# Gemtek/Guillemot Radio PCI Radio Card

# FM-Radio support
#radio*	at gtp?
radio*	at bktr?

#wdt0	at pci?			# Ind Computer Source PCI-WDT50x driver

# crypto support
hifn*	at pci?			# Hi/fn 7751 crypto card
ubsec*	at pci?			# Bluesteel Networks 5xxx crypto card
safe*	at pci?			# SafeNet SafeXcel 1141/1741

# 1-Wire devices
option ONEWIREVERBOSE
owid*	at onewire?		# ID
owsbm*	at onewire?		# Smart Battery Monitor
owtemp* at onewire?		# Temperature
owctr*	at onewire?		# Counter device

pseudo-device	pctr		1
pseudo-device	nvram		1
pseudo-device	hotplug		1	# devices hot plugging

# mouse & keyboard multiplexor pseudo-devices
pseudo-device	wsmux		2

# Virtio devices
virtio*		at pci?		# Virtio PCI device
vioblk*		at virtio?	# Virtio block device
vio*		at virtio?	# Virtio network device
viomb*		at virtio?	# Virtio memory ballooning device
viornd*		at virtio?	# Virtio entropy device
vioscsi*	at virtio?	# Virtio SCSI device


code:
#	$OpenBSD: GENERIC.MP,v 1.11 2014/09/03 07:44:33 blambert Exp $

include "arch/amd64/conf/GENERIC"

option	MULTIPROCESSOR
#option	MP_LOCKDEBUG

cpu*		at mainbus?


code:
#	$OpenBSD: Makefile.amd64,v 1.65 2015/01/13 01:12:49 deraadt Exp $

# For instructions on building kernels consult the config(8) and options(4)
# manual pages.
#
# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE
#	IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING
# DEBUG is set to -g by config if debugging is requested (config -g).
# PROF is set to -pg by config if profiling is requested (config -p).

.include <bsd.own.mk>

SIZE?=	size
STRIP?=	strip

# source tree is located via $S relative to the compilation directory
.ifndef S
S!=	cd ../../../..; pwd
.endif

_machdir?=	$S/arch/${_mach}
_archdir?=	$S/arch/${_arch}

INCLUDES=	-nostdinc -I$S -I. -I$S/arch
CPPFLAGS=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -MD -MP
CWARNFLAGS=	-Werror -Wall -Wimplicit-function-declaration \
		-Wno-main -Wno-uninitialized \
		-Wframe-larger-than=2047

CMACHFLAGS=	-mcmodel=kernel -mno-red-zone -mno-sse2 -mno-sse -mno-3dnow \
		-mno-mmx -msoft-float -fno-omit-frame-pointer
CMACHFLAGS+=	-fno-builtin-printf -fno-builtin-snprintf \
		-fno-builtin-vsnprintf -fno-builtin-log \
		-fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS}
.if ${IDENT:M-DNO_PROPOLICE}
CMACHFLAGS+=	-fno-stack-protector
.endif
.if ${IDENT:M-DSMALL_KERNEL}
CMACHFLAGS+=	-Wa,-n
.endif

COPTS?=		-O2
CFLAGS=		${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTS} ${PIPE}
AFLAGS=		-D_LOCORE -x assembler-with-cpp ${CWARNFLAGS} ${CMACHFLAGS}
LDSCRIPT=	${_machdir}/conf/ld.script
LINKFLAGS=	-T ${LDSCRIPT} -X --warn-common -nopie

.if ${IDENT:M-DDDB_STRUCT}
DB_STRUCTINFO=	db_structinfo.h
.else
DB_STRUCTINFO=
.endif

HOSTCC?=	${CC}
HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//}
HOSTED_CFLAGS=	${CFLAGS}
HOSTED_C=	${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $<

NORMAL_C_NOP=	${CC} ${CFLAGS} ${CPPFLAGS} -c $<
NORMAL_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
NORMAL_S=	${CC} ${AFLAGS} ${CPPFLAGS} -c $<

%OBJS

%CFILES

%SFILES

# load lines for config "xxx" will be emitted as:
# xxx: ${SYSTEM_DEP} swapxxx.o
#	${SYSTEM_LD_HEAD}
#	${SYSTEM_LD} swapxxx.o
#	${SYSTEM_LD_TAIL}
SYSTEM_HEAD=	locore.o param.o ioconf.o
SYSTEM_OBJ=	${SYSTEM_HEAD} ${OBJS}
SYSTEM_DEP=	Makefile ${SYSTEM_OBJ} ${LDSCRIPT}
SYSTEM_LD_HEAD=	@rm -f $@
SYSTEM_LD=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \
		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} vers.o ${OBJS}
SYSTEM_LD_TAIL=	@${SIZE} $@; chmod 755 $@

DEBUG?=
.if ${DEBUG} == "-g"
STRIPFLAGS=	-g -x
SYSTEM_LD_TAIL+=; \
		echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \
		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
.else
LINKFLAGS+=	-S -x
.endif

%LOAD

# cc's -MD puts the source and output paths in the dependency file;
# since those are temp files here we need to fix it up.  It also
# puts the file in /tmp, so we use -MF to put it in the current
# directory as assym.P and then generate assym.d from it with a
# good target name
assym.h: $S/kern/genassym.sh Makefile \
	 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf
	cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \
	    sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} -MF assym.P > assym.h.tmp
	sed '1s/.*/assym.h: \\/' assym.P > assym.d
	sort -u assym.h.tmp > assym.h

param.c: $S/conf/param.c
	rm -f param.c
	cp $S/conf/param.c .

param.o: param.c Makefile
	${NORMAL_C}

mcount.o: $S/lib/libkern/mcount.c Makefile
	${NORMAL_C_NOP}

ioconf.o: ioconf.c
	${NORMAL_C}

vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP}
	sh $S/conf/newvers.sh
	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c

clean::
	rm -f eddep *bsd *bsd.gdb tags *.[dio] [a-z]*.s \
	    [Ee]rrs linterrs assym.h ${DB_STRUCTINFO}

lint:
	@lint -hbxncez -Dvolatile= ${CPPFLAGS} -UKGDB \
	    ${CFILES} ioconf.c param.c | \
	    grep -v 'static function .* unused'

depend:
	@touch $@

tags:
	@echo "see $S/kern/Makefile for tags"

db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl
	${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c
	objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@
	rm -f db_structinfo.o

locore.o: ${_machdir}/${_mach}/locore.S assym.h
mutex.o vector.o copy.o spl.o mptramp.o acpi_wakecode.o: assym.h

# The install target can be redefined by putting a
# install-kernel-${MACHINE_NAME} target into /etc/mk.conf
MACHINE_NAME!=  uname -n
install: install-kernel-${MACHINE_NAME}
.if !target(install-kernel-${MACHINE_NAME}})
install-kernel-${MACHINE_NAME}:
	cmp -s bsd /bsd || ln -f /bsd /obsd
	cp bsd /nbsd
	mv /nbsd /bsd
.endif

# pull in the dependency information
.if !empty(DB_STRUCTINFO) && !exists(${DB_STRUCTINFO})
 ${SYSTEM_OBJ}: ${DB_STRUCTINFO}
.endif
.ifnmake clean
. for o in ${SYSTEM_OBJ} assym.h ${DB_STRUCTINFO}
.  if exists(${o:R}.d)
.   include "${o:R}.d"
.  elif exists($o)
    .PHONY: $o
.  endif
. endfor
.endif

%RULES


code:
#	$OpenBSD: RAMDISK,v 1.68 2015/07/17 22:52:28 tedu Exp $

machine		amd64
maxusers	4

option		TIMEZONE=0
option		DST=0
option		SMALL_KERNEL
option		NO_PROPOLICE
option		BOOT_CONFIG

option		RAMDISK_HOOKS
option		MINIROOTSIZE=4480

option		PCIVERBOSE
option		SCSITERSE

option		FFS

config		bsd root on rd0a swap on rd0b and wd0b and sd0b

mainbus0	at root
bios0		at mainbus?

acpi0		at bios?
#acpitimer*	at acpi?
#acpihpet*	at acpi?
#acpiac*	at acpi?
#acpibat*	at acpi?
#acpibtn*	at acpi?
#acpicpu*	at acpi?
acpiec*		at acpi?
acpiprt*	at acpi?
acpimadt0	at acpi?
#acpitz*	at acpi?

mpbios0		at bios0

cpu0		at mainbus0
ioapic*		at mainbus?
isa0		at mainbus0
#isa0		at pcib?
pci*		at mainbus0

pchb*		at pci?			# PCI-Host bridges
aapic*		at pci?			# AMD 8131 IO apic
ppb*		at pci?			# PCI-PCI bridges
pci*		at ppb?
pci*		at pchb?
#pcib*		at pci?			# PCI-ISA bridge

xhci*		at pci?
ehci*		at pci?
uhci*		at pci?
ohci*		at pci?
usb*		at xhci?
usb*		at ehci?
usb*		at uhci?
usb*		at ohci?

uhub*		at usb?
uhub*		at uhub?
uhidev*		at uhub?
ukbd*		at uhidev?
wskbd*		at ukbd? mux 1
umass*		at uhub?

pckbc0		at isa?		# PC keyboard controller
pckbd*		at pckbc?	# PC keyboard
wskbd*		at pckbd? mux 1
vga0		at isa?
vga*		at pci?
wsdisplay*	at vga?

com0		at isa? port 0x3f8 irq 4	# standard PC serial ports
com1		at isa? port 0x2f8 irq 3

mpi*		at pci?			# LSI Logic Message Passing Interface
mfi*		at pci?			# LSI MegaRAID SAS controllers

scsibus*	at scsi?
sd*		at scsibus?		# SCSI disk drives
cd*		at scsibus?		# SCSI CD-ROM drives

pciide*		at pci? flags 0x0000
wd*		at pciide? flags 0x0000
atapiscsi*	at pciide?

fxp*		at pci?			# EtherExpress 10/100B ethernet
rl*		at pci?			# Realtek 81[23]9 ethernet
re*		at pci?			# Realtek 8169/8169S/8110S
em*		at pci?			# Intel Pro/1000 ethernet
bge*		at pci?			# Broadcom BCM570x (aka Tigon3)

inphy*		at mii?			# Intel 82555 PHYs
iophy*		at mii?			# Intel 82553 PHYs
lxtphy*		at mii?			# Level1 LXT970 PHYs
nsphy*		at mii?			# NS and compatible PHYs
nsphyter*	at mii?			# NS and compatible PHYs
rlphy*		at mii?			# Realtek 8139 internal PHYs
brgphy*		at mii?			# Broadcom Gigabit PHYs
rgephy*		at mii?			# Realtek 8169S/8110S PHY
ciphy*		at mii?			# Cicada CS8201 10/100/1000 copper PHY
ukphy*		at mii?			# "unknown" PHYs

pseudo-device	loop 1
pseudo-device	bpfilter 1
pseudo-device	rd 1
pseudo-device	wsmux 2


code:
#	$OpenBSD: RAMDISK_CD,v 1.153 2015/07/17 22:52:28 tedu Exp $

machine		amd64
maxusers	4

option		TIMEZONE=0
option		DST=0
option		SMALL_KERNEL
option		NO_PROPOLICE
option		BOOT_CONFIG

option		PCIVERBOSE
option		SCSITERSE

option		FFS
option		FFS2
option		EXT2FS
option		NFSCLIENT
option		CD9660
option		UDF
option		MSDOSFS
option		INET6
option		CRYPTO

option		RAMDISK_HOOKS
option		MINIROOTSIZE=4480

config		bsd root on rd0a swap on rd0b and wd0b and sd0b

mainbus0	at root
bios0		at mainbus?

acpi0		at bios?
#acpitimer*	at acpi?
#acpihpet*	at acpi?
#acpiac*	at acpi?
#acpibat*	at acpi?
#acpibtn*	at acpi?
#acpicpu*	at acpi?
acpiec*		at acpi?
acpiprt*	at acpi?
acpimadt0	at acpi?
#acpitz*	at acpi?

mpbios0		at bios0

cpu0		at mainbus0
ioapic*		at mainbus?
isa0		at mainbus0
#isa0		at pcib?
pci*		at mainbus0

pchb*		at pci?			# PCI-Host bridges
aapic*		at pci?			# AMD 8131 IO apic
ppb*		at pci?			# PCI-PCI bridges
pci*		at ppb?
pci*		at pchb?
#pcib*		at pci?			# PCI-ISA bridge

cbb*		at pci?
cardslot*	at cbb?
cardbus*	at cardslot?
pcmcia*		at cardslot?

xhci*		at pci?
ehci*		at pci?
ehci*		at cardbus?
uhci*		at pci?
ohci*		at pci?
ohci*		at cardbus?
usb*		at xhci?
usb*		at ehci?
usb*		at uhci?
usb*		at ohci?

uhub*		at usb?
uhub*		at uhub?
uhidev*		at uhub?
ukbd*		at uhidev?
wskbd*		at ukbd? mux 1
umass*		at uhub?
aue*		at uhub?		# ADMtek AN986 Pegasus Ethernet
atu*		at uhub?		# Atmel AT76c50x based 802.11b
axe*		at uhub?		# ASIX Electronics AX88172 USB Ethernet
axen*		at uhub?		# ASIX Electronics AX88179 USB Ethernet
cue*		at uhub?		# CATC USB-EL1201A based Ethernet
kue*		at uhub?		# Kawasaki KL5KUSB101B based Ethernet
smsc*		at uhub?		# SMSC LAN95xx Ethernet
cdce*		at uhub?		# CDC Ethernet
udav*		at uhub?		# Davicom DM9601 based Ethernet
mos*		at uhub?		# MOSCHIP MCS7730/7830 10/100 Ethernet
url*		at uhub?		# Realtek RTL8150L based adapters
wi*		at uhub?		# WaveLAN IEEE 802.11DS
upl*		at uhub?		# Prolific PL2301/PL2302 host-to-host
ugl*		at uhub?		# Genesys Logic GL620USB-A host-to-host
ural*		at uhub?		# Ralink RT2500
rum*		at uhub?		# Ralink RT2501USB/RT2601USB
run*		at uhub?		# Ralink RT2700U/RT2800U/RT3000U
zyd*		at uhub?		# Zydas ZD1211/ZD1211B
upgt*		at uhub?		# Conexant/Intersil PrismGT SoftMAC USB
urtw*		at uhub?		# Realtek 8187
urtwn*		at uhub?		# Realtek RTL8188CU/RTL8192CU
rsu*		at uhub?		# Realtek RTL8188SU/RTL8191SU/RTL8192SU
uath*		at uhub?		# Atheros AR5005UG/AR5005UX
otus*		at uhub?		# Atheros AR9001U
athn*		at uhub?		# Atheros AR9002U

pckbc0		at isa?			# PC keyboard controller
pckbd*		at pckbc?		# PC keyboard
wskbd*		at pckbd? mux 1
vga0		at isa?
vga*		at pci?
wsdisplay*	at vga?

com0		at isa? port 0x3f8 irq 4	# standard PC serial ports
com1		at isa? port 0x2f8 irq 3
com2		at isa? port 0x3e8 irq 5

ahc*		at pci?			# Adaptec 2940 SCSI controllers
jmb*		at pci?			# JMicron JMB36x controllers
ahci*		at jmb?
pciide*		at jmb?
ahci*		at pci?			# AHCI SATA controllers
sili*		at pci?			# Silicon Image 3124/3132/3531 SATA controllers
ahd*		at pci?			# Adaptec 79?? SCSI controllers
arc*		at pci?			# Areca RAID Controller
mpi*		at pci?			# LSI Logic Message Passing Interface
mpii*		at pci?			# LSI Message Passing Interface II
gdt*		at pci?			# ICP Vortex GDT RAID controllers
ami*		at pci?			# AMI MegaRAID controllers
mfi*		at pci?			# LSI MegaRAID SAS controllers
mfii*		at pci?			# LSI MegaRAID SAS Fusion controllers
ciss*		at pci?			# Compaq Smart ARRAY [56]* RAID controllers
twe*		at pci?			# 3ware Escalade RAID controllers
iha*		at pci?			# Initio Ultra/UltraWide SCSI controllers
ips*		at pci?			# IBM ServeRAID controllers
qlw*		at pci?			# QLogic ISP SCSI
qla*		at pci?			# QLogic ISP 2[123]xx FibreChannel
qle*		at pci?			# QLogic ISP 2[45]xx FibreChannel
#siop*		at pci?			# NCR 538XX SCSI controllers(new)
#adw*		at pci?			# AdvanSys ULTRA WIDE SCSI
pcscp*		at pci?			# AMD 53c974 PCscsi-PCI SCSI
vmwpvs*		at pci?			# VMware ParaVirtual SCSI
softraid0	at root

scsibus*	at scsi?
sd*		at scsibus?		# SCSI disk drives
st*		at scsibus?		# SCSI tape drives
cd*		at scsibus?		# SCSI CD-ROM drives

pciide*		at pci? flags 0x0000
wdc0		at isa? disable port 0x1f0 irq 14 flags 0x00
wdc1		at isa? disable port 0x170 irq 15 flags 0x00
wdc*		at pcmcia?
wd*		at wdc? flags 0x0000
wd*		at pciide? flags 0x0000
atapiscsi*	at wdc?
atapiscsi*	at pciide?

sdhc*		at pci?			# SD Host Controller
sdmmc*		at sdhc?		# SD/MMC bus
rtsx*		at pci?			# Realtek SD Card Reader
sdmmc*		at rtsx?		# SD/MMC bus

de*		at pci?			# DC21X4X-based ethernet
fxp*		at pci?			# EtherExpress 10/100B ethernet
fxp*		at cardbus?		# Intel PRO/100 ethernet
ep*		at pci?			# 3C59x ethernet
ne*		at pci?			# NE2000-compat ethernet
ne*		at pcmcia?		# PCMCIA based NE2000 ethernet
ep*		at pcmcia?		# PCMCIA based 3C5xx ethernet
sm*		at pcmcia?		# PCMCIA based sm ethernet
xe*		at pcmcia?		# Xircom ethernet
xl*		at pci?			# 3C9xx ethernet
xl*		at cardbus?		# 3C575 ethernet
rl*		at pci?			# Realtek 81[23]9 ethernet
rl*		at cardbus?		# Realtek 81[23]9 ethernet
epic*		at pci?			# SMC EPIC/100 ethernet
vr*		at pci?			# VIA Rhine ethernet
pcn*		at pci?			# AMD PCnet-PCI Ethernet
dc*		at pci?			# 21143, "tulip" clone ethernet
dc*		at cardbus?		# 21143, "tulip" clone ethernet
sis*		at pci?			# SiS 900/7016 ethernet
se*		at pci?			# SiS 190/191 ethernet
skc*		at pci?			# SysKonnect GEnesis 984x
sk*		at skc?			#  each port of above
mskc*		at pci?			# Marvell Yukon-2
msk*		at mskc?		#  each port of above
em*		at pci?			# Intel Pro/1000 ethernet
ixgb*		at pci?			# Intel Pro/10Gb ethernet
ix*		at pci?			# Intel 82598EB 10Gb ethernet
oce*		at pci?			# Emulex OneConnect 10Gb ethernet
sf*		at pci?			# Adaptec AIC-6915 ethernet
bge*		at pci?			# Broadcom BCM57xx (aka Tigon3)
bnx*		at pci?			# Broadcom BCM5706/5708 GigE
re*		at pci?			# Realtek 8169/8169S/8110S
re*		at cardbus?		# Realtek 8169/8169S/8110S
stge*		at pci?			# Sundance TC9021 GigE
hme*		at pci?			# Sun Happy Meal
vge*		at pci?			# VIA VT612x
nfe*		at pci?			# NVIDIA nForce Ethernet
xge*		at pci?			# Neterion Xframe-I/II 10Gb ethernet
bce*		at pci?			# Broadcom BCM4401
vic*		at pci?			# VMware VMXnet virtual interface
vmx*		at pci?			# VMware VMXNET3 virtual interface
et*		at pci?			# Agere/LSI ET1310
age*		at pci?			# Attansic L1 Ethernet
alc*		at pci?			# Attansic L1C/L1D/L2C Ethernet
ale*		at pci?			# Attansic L1E Ethernet
lii*		at pci?			# Attansic L2 Ethernet
jme*		at pci?			# JMicron JMC250/JMC260 Ethernet

acx*		at pci?			# TI ACX100/ACX111 (802.11b/g)
acx*		at cardbus?		# TI ACX100/ACX111 (802.11b/g)
ath*		at pci?			# Atheros AR5k (802.11a/b/g)
ath*		at cardbus?		# Atheros AR5k (802.11a/b/g)
athn*		at pci?			# Atheros AR9k (802.11a/g/n)
athn*		at cardbus?		# Atheros AR9k (802.11a/g/n)
atw*		at pci?			# ADMtek ADM8211 (802.11)
atw*		at cardbus?		# ADMtek ADM8211 (802.11)
bwi*		at pci?			# Broadcom AirForce (802.11b/g)
bwi*		at cardbus?		# Broadcom AirForce (802.11b/g)
wi*		at pci?			# WaveLAN IEEE 802.11DS
wi*		at pcmcia?		# WaveLAN IEEE 802.11DS
an*		at pcmcia?		# Aironet IEEE 802.11DS
iwi*		at pci?			# Intel PRO/Wireless 2200BG/2915ABG
wpi*		at pci?			# Intel PRO/Wireless 3945ABG
iwn*		at pci?			# Intel Wireless WiFi Link 4965AGN
iwm*		at pci?			# Intel WiFi Link 7xxx
ral*		at pci?			# Ralink RT2500/RT2501/RT2600
ral*		at cardbus?		# Ralink RT2500/RT2501/RT2600
rtw*		at pci?			# Realtek 8180
rtw*		at cardbus?		# Realtek 8180
rtwn*		at pci?			# Realtek 8188CE/8192CE
pgt*		at pci?			# Prism54 (only full-mac varients)
pgt*		at cardbus?		# Prism54 (only full-mac varients)
malo*		at pci?			# Marvell 88W8385
malo*		at cardbus?		# Marvell Libertas
malo*		at pcmcia?		# Marvell 88W8385

exphy*		at mii?			# 3Com internal PHYs
inphy*		at mii?			# Intel 82555 PHYs
iophy*		at mii?			# Intel 82553 PHYs
icsphy*		at mii?			# ICS 1890 PHYs
lxtphy*		at mii?			# Level1 LXT970 PHYs
nsphy*		at mii?			# NS and compatible PHYs
nsphyter*	at mii?			# NS and compatible PHYs
qsphy*		at mii?			# Quality Semi QS6612 PHYs
luphy*		at mii?			# Lucent LU6612 PHY
sqphy*		at mii?			# Seeq 8x220 PHYs
rlphy*		at mii?			# Realtek 8139 internal PHYs
mtdphy*		at mii?			# Myson MTD972 PHYs
dcphy*		at mii?			# Digital Clone PHYs
acphy*		at mii?			# Altima AC101 PHYs
amphy*		at mii?			# AMD 79C873 PHYs
tqphy*		at mii?			# TDK 78Q212x PHYs
brgphy*		at mii?			# Broadcom Gigabit PHYs
eephy*		at mii?			# Marvell 88E1000 series PHY
xmphy*		at mii?			# XaQti XMAC-II PHYs
bmtphy*		at mii?			# Broadcom 10/100 PHYs
rgephy*		at mii?			# Realtek 8169S/8110S PHY
urlphy*		at mii?			# Realtek RTL8150L internal PHY
ciphy*		at mii?			# Cicada CS8201 10/100/1000 copper PHY
etphy*		at mii?			# Agere/LSI ET1011 TruePHY
jmphy*		at mii?			# JMicron JMP202/JMP211 PHYs
ipgphy*		at mii?			# IC Plus IP1000A PHYs
atphy*		at mii?			# Attansic F1 PHYs
ukphy*		at mii?			# "unknown" PHYs

virtio*		at pci?			# Virtio PCI device
vioblk*		at virtio?		# Virtio block device
vio*		at virtio?		# Virtio network device
vioscsi*	at virtio?		# Virtio SCSI device

pseudo-device	loop 1
pseudo-device	vlan
pseudo-device	trunk
pseudo-device	bpfilter 1
pseudo-device	rd 1
pseudo-device	wsmux 2
pseudo-device	bio 1


code:
#	$OpenBSD: files.amd64,v 1.79 2015/07/21 03:38:22 reyk Exp $

maxpartitions 16
maxusers 2 16 128

file	arch/amd64/amd64/autoconf.c
file	arch/amd64/amd64/conf.c
file	arch/amd64/amd64/disksubr.c		disk
file	arch/amd64/amd64/gdt.c			multiprocessor
file	arch/amd64/amd64/machdep.c
file	arch/amd64/amd64/hibernate_machdep.c	hibernate
file	arch/amd64/amd64/identcpu.c
file	arch/amd64/amd64/via.c
file	arch/amd64/amd64/aes_intel.S		crypto
file	arch/amd64/amd64/aesni.c		crypto
file	arch/amd64/amd64/amd64errata.c
file	arch/amd64/amd64/mem.c
file	arch/amd64/amd64/amd64_mem.c		mtrr
file	arch/amd64/amd64/mtrr.c			mtrr
file	arch/amd64/amd64/pmap.c
file	arch/amd64/amd64/process_machdep.c
file	arch/amd64/amd64/sys_machdep.c
file	arch/amd64/amd64/trap.c
file	arch/amd64/amd64/vm_machdep.c
file	arch/amd64/amd64/fpu.c
file	arch/amd64/amd64/softintr.c
file	arch/amd64/amd64/i8259.c
file	arch/amd64/amd64/cacheinfo.c
file	arch/amd64/amd64/mutex.S
file	arch/amd64/amd64/vector.S
file	arch/amd64/amd64/copy.S
file	arch/amd64/amd64/spl.S
file	arch/amd64/amd64/lock_machdep.c		multiprocessor

file	arch/amd64/amd64/intr.c
file	arch/amd64/amd64/bus_space.c
file	arch/amd64/amd64/bus_dma.c

file	arch/amd64/amd64/mptramp.S		multiprocessor
file	arch/amd64/amd64/ipifuncs.c		multiprocessor
file	arch/amd64/amd64/ipi.c			multiprocessor
file	arch/amd64/amd64/mp_setperf.c		multiprocessor

file	arch/amd64/amd64/apic.c			ioapic | lapic

file	arch/amd64/amd64/consinit.c
file	dev/cninit.c

file	arch/amd64/amd64/dkcsum.c		bios

file	arch/amd64/amd64/db_disasm.c		ddb
file	arch/amd64/amd64/db_interface.c		ddb
file	arch/amd64/amd64/db_memrw.c		ddb | kgdb
file	arch/amd64/amd64/db_trace.c		ddb

file	netinet/in_cksum.c
file	netinet/in4_cksum.c

file	arch/amd64/amd64/kgdb_machdep.c		kgdb

# Basic clock - required
file	arch/amd64/isa/clock.c

file	arch/amd64/amd64/powernow-k8.c		!small_kernel
file	arch/amd64/amd64/est.c			!small_kernel
file	arch/amd64/amd64/k1x-pstate.c		!small_kernel

include "dev/rasops/files.rasops"
include "dev/wsfont/files.wsfont"

include	"dev/mii/files.mii"

include	"scsi/files.scsi"

include	"dev/atapiscsi/files.atapiscsi"
include	"dev/ata/files.ata"

define	mainbus {[apid = -1]}
device	mainbus: isabus, pcibus, mainbus
attach	mainbus at root
file	arch/amd64/amd64/mainbus.c		mainbus

file	arch/amd64/amd64/codepatch.c

device	bios {}
attach	bios at mainbus
file	arch/amd64/amd64/bios.c			bios needs-flag

#Intel SMP specification 1.4
define	mpbios
device	mpbios
attach	mpbios at bios
file	arch/amd64/amd64/mpbios.c		mpbios needs-flag
file	arch/amd64/amd64/mpbios_intr_fixup.c	mpbios & pci

define	cpu {[apid = -1]}
device	cpu
attach	cpu at mainbus
file	arch/amd64/amd64/cpu.c	cpu

define	lapic
file	arch/amd64/amd64/lapic.c		lapic needs-flag

device	ioapic: mpbios, lapic
attach	ioapic at mainbus
file	arch/amd64/amd64/ioapic.c		ioapic needs-flag

#
# PCI drivers
#

include	"dev/pci/files.pci"
file	arch/amd64/pci/pci_machdep.c		pci
file	arch/amd64/pci/pciide_machdep.c		pciide
file	arch/amd64/pci/vga_post.c		vga_pci & x86emu

# PCI Host bridge chipsets
device	pchb: pcibus, agpbus
attach	pchb at pci
file	arch/amd64/pci/pchb.c			pchb

# AMAS AMD memory address switch
device	amas
attach	amas at pci
file	dev/pci/amas.c				amas

# AGP bridge support. most attach at pchb
file	arch/amd64/pci/agp_machdep.c		agp

#
# CARDBUS
#
include	"dev/cardbus/files.cardbus"
file	arch/amd64/amd64/rbus_machdep.c		cardbus

# PCIC pcmcia controller
device	pcic: pcmciabus
file	dev/ic/i82365.c				pcic

# PCIC pcmcia controller on PCI bus.
attach	pcic at pci with pcic_pci
file	dev/pci/i82365_pci.c			pcic_pci

include	"dev/pcmcia/files.pcmcia"

# PCI-ISA bridges
device	pcib: isabus
attach	pcib at pci
file	arch/amd64/pci/pcib.c			pcib | amdpcib | tcpcib

# AMD 8111 LPC bridge
device	amdpcib: isabus
attach	amdpcib at pci
file	dev/pci/amdpcib.c			amdpcib

# Intel Atom E600 LPC bridge
device	tcpcib: isabus
attach	tcpcib at pci
file	dev/pci/tcpcib.c			tcpcib

device	aapic
attach	aapic at pci
file	arch/amd64/pci/aapic.c			aapic

device	hme: ether, ifnet, mii, ifmedia
file	dev/ic/hme.c			hme
attach	hme at pci with hme_pci
file	dev/pci/if_hme_pci.c		hme_pci

#
# ISA drivers
#

include	"dev/isa/files.isa"
include	"dev/isa/files.isapnp"
file	arch/amd64/isa/isa_machdep.c		isa

# attribute used to represent the "keyboard controller"
# XXX should be a real device
define	pckbcport {[irq = -1], [port = -1]}

include	"dev/wscons/files.wscons"
include	"dev/pckbc/files.pckbc"

file	arch/amd64/amd64/wscons_machdep.c	wsdisplay

# Soekris GPIO & LEDs driver
device	skgpio: gpiobus
attach	skgpio at isa
file	dev/isa/skgpio.c			skgpio

pseudo-device	pctr
file	arch/amd64/amd64/pctr.c		pctr needs-flag

pseudo-device	nvram
file	arch/amd64/amd64/nvram.c	nvram needs-flag

#
# USB
#
include	"dev/usb/files.usb"

#
# I2C
#
include "dev/i2c/files.i2c"

#
# Machine-independent GPIO drivers
#
include "dev/gpio/files.gpio"

#
# ACPI
#
include "dev/acpi/files.acpi"
file	arch/amd64/amd64/acpi_machdep.c		acpi
file	arch/amd64/amd64/acpi_wakecode.S	acpi & !small_kernel

#
# Machine-independent SD/MMC drivers
#
include "dev/sdmmc/files.sdmmc"

#
# Machine-independent 1-Wire drivers
#
include "dev/onewire/files.onewire"

#
# IPMI
#
attach	ipmi at mainbus

#
# Paravirtual device bus
#
include "dev/pv/files.pv"

#
# device major numbers
#

major	{vnd = 14}
major	{sd = 4}
major	{st = 5}
major	{cd = 6}
major	{rd = 17}
major	{wd = 0}
major	{fd = 2}


code:
/*	$OpenBSD: ld.script,v 1.3 2015/04/28 22:29:24 kettenis Exp $	*/

/*
 * Copyright (c) 2009 Tobias Weingartner <weingart@tepid.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)

/* Define how we want out ELF binary to look like. */
PHDRS
{
	text PT_LOAD FILEHDR PHDRS;
	rodata PT_LOAD;
	data PT_LOAD;
	bss PT_LOAD;
	openbsd_randomize 0x65a3dbe6; /* PT_OPENBSD_RANDOMIZE */
}

/*
 * If we want the text/rodata/data sections aligned on 2M boundaries,
 * we could use the following instead.  Note, file size would increase
 * due to necessary padding.
 *
 *__ALIGN_SIZE = 0x200000;
 */
__ALIGN_SIZE = 0x1000;
__kernel_base_virt = 0xffffffff81000000 + SIZEOF_HEADERS;
__kernel_base_phys = __kernel_base_virt & 0x7fffffff;

/* We use physical address to jump to kernel */
start_phys = LOADADDR(.text) + (start - __kernel_base_virt);
ENTRY(start_phys)
SECTIONS
{
	__kernel_text_virt = __kernel_base_virt;
	__kernel_text_phys = __kernel_base_phys;
	.text (__kernel_text_virt) : AT (__kernel_text_phys)
	{
		__text_start = ABSOLUTE(.) & 0xfffffffffffff000;
		__text_size = SIZEOF(.text);
		__text_load = LOADADDR(.text);
		locore.o(.text)
		*(.text .text.*)
	} :text
	PROVIDE (__etext = .);
	PROVIDE (etext = .);
	_etext = .;

	/* Move rodata to the next page, so we can nuke X and W bit on them */
	. = ALIGN(__ALIGN_SIZE);
	__kernel_rodata_virt = .;
	__kernel_rodata_phys = . & 0x7fffffff;
	.rodata (__kernel_rodata_virt) : AT (__kernel_rodata_phys)
	{
		__rodata_start = ABSOLUTE(.);
		__rodata_size = SIZEOF(.rodata);
		__rodata_load = LOADADDR(.rodata);
		*(.rodata .rodata.*)
		*(.codepatch)
		*(.codepatchend)
	} :rodata
	PROVIDE (erodata = .);
	_erodata = .;

	/* Move data to the next page, so we can add W bit on them */
	. = ALIGN(__ALIGN_SIZE);
	__kernel_data_virt = .;
	__kernel_data_phys = . & 0x7fffffff;
	.data (__kernel_data_virt) : AT (__kernel_data_phys)
	{
		__data_start = ABSOLUTE(.);
		__data_size = SIZEOF(.data);
		__data_load = LOADADDR(.data);
		*(.data .data.*)
	} :data
	. = ALIGN(0x1000);
	__kernel_randomdata_phys = . & 0x7fffffff;
	.openbsd.randomdata : AT (__kernel_randomdata_phys)
	{
		*(.openbsd.randomdata)
	} :data :openbsd_randomize
	. = ALIGN(0x1000);
	PROVIDE (edata = .);
	_edata = .;

	/* BSS starts right after padded data */
	__kernel_bss_virt = .;
	__kernel_bss_phys = . & 0x7fffffff;
	.bss (__kernel_bss_virt) : AT (__kernel_bss_phys)
	{
		__bss_start = ABSOLUTE(.);
		__bss_size = SIZEOF(.bss);
		__bss_load = LOADADDR(.bss);
		*(.bss .bss.*)
		*(COMMON)
		/* Align after .bss to ensure correct alignment even if the
		 * .bss section disappears because there are no input sections.
		 */
		. = ALIGN(0x1000);
	} :bss
	__kernel_bss_end = .;
	. = ALIGN(0x200000);
	_end = .;
	PROVIDE (end = .);
	__kernel_end_phys = . & 0x7fffffff;

	/* XXX - hack alert, since we are not C++, nuke these */
	/DISCARD/ :
	{
		*(.note.GNU-stack)
		*(.eh_frame)
	}
}


code:
/*	$OpenBSD: _float.h,v 1.1 2012/06/26 16:12:43 deraadt Exp $	*/

/*
 * Copyright (c) 1989 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef _MACHINE__FLOAT_H_
#define _MACHINE__FLOAT_H_

#define __FLT_RADIX		2		/* b */
#define __FLT_ROUNDS		__flt_rounds()
#define __FLT_EVAL_METHOD	0		/* no promotions */

#define __FLT_MANT_DIG		24		/* p */
#define __FLT_EPSILON		1.19209290E-07F	/* b**(1-p) */
#define __FLT_DIG		6		/* floor((p-1)*log10(b))+(b == 10) */
#define __FLT_MIN_EXP		(-125)		/* emin */
#define __FLT_MIN		1.17549435E-38F	/* b**(emin-1) */
#define __FLT_MIN_10_EXP	(-37)		/* ceil(log10(b**(emin-1))) */
#define __FLT_MAX_EXP		128		/* emax */
#define __FLT_MAX		3.40282347E+38F	/* (1-b**(-p))*b**emax */
#define __FLT_MAX_10_EXP	38		/* floor(log10((1-b**(-p))*b**emax)) */

#define __DBL_MANT_DIG		53
#define __DBL_EPSILON		2.2204460492503131E-16
#define __DBL_DIG		15
#define __DBL_MIN_EXP		(-1021)
#define __DBL_MIN		2.2250738585072014E-308
#define __DBL_MIN_10_EXP	(-307)
#define __DBL_MAX_EXP		1024
#define __DBL_MAX		1.7976931348623157E+308
#define __DBL_MAX_10_EXP	308

#define __LDBL_MANT_DIG		64
#define __LDBL_EPSILON		1.08420217248550443401e-19L
#define __LDBL_DIG		18
#define __LDBL_MIN_EXP		(-16381)
#define __LDBL_MIN		3.36210314311209350626e-4932L
#define __LDBL_MIN_10_EXP	(-4931)
#define __LDBL_MAX_EXP		16384
#define __LDBL_MAX		1.18973149535723176502e+4932L
#define __LDBL_MAX_10_EXP	4932

#define __DECIMAL_DIG		21

#endif /* _MACHINE__FLOAT_H_ */


code:
/*	$OpenBSD: _types.h,v 1.15 2014/03/19 05:14:13 guenther Exp $	*/

/*-
 * Copyright (c) 1990, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)types.h	8.3 (Berkeley) 1/5/94
 *	@(#)ansi.h	8.2 (Berkeley) 1/4/94
 */

#ifndef _MACHINE__TYPES_H_
#define _MACHINE__TYPES_H_

/*
 * _ALIGN(p) rounds p (pointer or byte index) up to a correctly-aligned
 * value for all data types (int, long, ...).   The result is an
 * unsigned long and must be cast to any desired pointer type.
 *
 * _ALIGNED_POINTER is a boolean macro that checks whether an address
 * is valid to fetch data elements of type t from on this architecture.
 * This does not reflect the optimal alignment, just the possibility
 * (within reasonable limits).
 */
#define	_ALIGNBYTES		(sizeof(long) - 1)
#define	_STACKALIGNBYTES	15
#define	_ALIGN(p)		(((unsigned long)(p) + _ALIGNBYTES) &~_ALIGNBYTES)
#define	_ALIGNED_POINTER(p,t)	1

#if defined(_KERNEL)
typedef struct label_t {
	long val[8];
} label_t;
#endif

/* 7.18.1.1 Exact-width integer types */
typedef	signed char		__int8_t;
typedef	unsigned char		__uint8_t;
typedef	short			__int16_t;
typedef	unsigned short		__uint16_t;
typedef	int			__int32_t;
typedef	unsigned int		__uint32_t;
/* LONGLONG */
typedef	long long		__int64_t;
/* LONGLONG */
typedef	unsigned long long	__uint64_t;

/* 7.18.1.2 Minimum-width integer types */
typedef	__int8_t		__int_least8_t;
typedef	__uint8_t		__uint_least8_t;
typedef	__int16_t		__int_least16_t;
typedef	__uint16_t		__uint_least16_t;
typedef	__int32_t		__int_least32_t;
typedef	__uint32_t		__uint_least32_t;
typedef	__int64_t		__int_least64_t;
typedef	__uint64_t		__uint_least64_t;

/* 7.18.1.3 Fastest minimum-width integer types */
typedef	__int32_t		__int_fast8_t;
typedef	__uint32_t		__uint_fast8_t;
typedef	__int32_t		__int_fast16_t;
typedef	__uint32_t		__uint_fast16_t;
typedef	__int32_t		__int_fast32_t;
typedef	__uint32_t		__uint_fast32_t;
typedef	__int64_t		__int_fast64_t;
typedef	__uint64_t		__uint_fast64_t;
#define	__INT_FAST8_MIN		INT32_MIN
#define	__INT_FAST16_MIN	INT32_MIN
#define	__INT_FAST32_MIN	INT32_MIN
#define	__INT_FAST64_MIN	INT64_MIN
#define	__INT_FAST8_MAX		INT32_MAX
#define	__INT_FAST16_MAX	INT32_MAX
#define	__INT_FAST32_MAX	INT32_MAX
#define	__INT_FAST64_MAX	INT64_MAX
#define	__UINT_FAST8_MAX	UINT32_MAX
#define	__UINT_FAST16_MAX	UINT32_MAX
#define	__UINT_FAST32_MAX	UINT32_MAX
#define	__UINT_FAST64_MAX	UINT64_MAX

/* 7.18.1.4 Integer types capable of holding object pointers */
typedef	long			__intptr_t;
typedef	unsigned long		__uintptr_t;

/* 7.18.1.5 Greatest-width integer types */
typedef	__int64_t		__intmax_t;
typedef	__uint64_t		__uintmax_t;

/* Register size */
typedef long			__register_t;

/* VM system types */
typedef unsigned long		__vaddr_t;
typedef unsigned long		__paddr_t;
typedef unsigned long		__vsize_t;
typedef unsigned long		__psize_t;

/* Standard system types */
typedef	double			__double_t;
typedef	float			__float_t;
typedef long			__ptrdiff_t;
typedef	unsigned long		__size_t;
typedef	long			__ssize_t;
#if defined(__GNUC__) && __GNUC__ >= 3
typedef	__builtin_va_list	__va_list;
#else
typedef char *			__va_list;
#endif

/* Wide character support types */
#ifndef __cplusplus
typedef	int			__wchar_t;
#endif
typedef int			__wint_t;
typedef	int			__rune_t;
typedef	void *			__wctrans_t;
typedef	void *			__wctype_t;

#endif	/* _MACHINE__TYPES_H_ */


code:
/*	$OpenBSD: apicvar.h,v 1.3 2011/03/23 16:54:34 pirofti Exp $	*/
/* 	$NetBSD: apicvar.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */

/*-
 * Copyright (c) 2000 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by RedBack Networks Inc.
 *
 * Author: Bill Sommerfeld
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _MACHINE_APICVAR_H_
#define _MACHINE_APICVAR_H_

struct apic_attach_args {
	const char *aaa_name;
	int apic_id;
	int apic_version;
	int flags;
#define IOAPIC_PICMODE		0x01
#define IOAPIC_VWIRE		0x02
	paddr_t apic_address;
	int apic_vecbase;
};

void apic_format_redir(char *, char *, int, u_int32_t, u_int32_t);

#endif /* !_MACHINE_APICVAR_H_ */


code:
/* XXX - DSR */
/*	$OpenBSD: apmvar.h,v 1.6 2015/02/06 08:16:49 dcoppa Exp $	*/

/*
 *  Copyright (c) 1995 John T. Kohl
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *  1. Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *  3. The name of the author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
#ifndef _MACHINE_APMVAR_H_
#define _MACHINE_APMVAR_H_

#include <sys/ioccom.h>

/* Advanced Power Management (v1.0 and v1.1 specification)
 * functions/defines/etc.
 */

#define	APM_VERSION	0x0102

/*
 * APM info word from boot loader
 */
#define APM_16BIT_SUPPORTED	0x00010000
#define APM_32BIT_SUPPORTED	0x00020000
#define APM_IDLE_SLOWS		0x00040000
#define APM_BIOS_PM_DISABLED	0x00080000
#define APM_BIOS_PM_DISENGAGED	0x00100000
#define	APM_MAJOR(f)		(((f) >> 8) & 0xff)
#define	APM_MINOR(f)		((f) & 0xff)
#define	APM_VERMASK		0x0000ffff
#define	APM_NOCLI		0x00010000
#define	APM_BEBATT		0x00020000

/* APM error codes */
#define	APM_ERR_CODE(regs)	(((regs)->ax & 0xff00) >> 8)
#define	APM_ERR_PM_DISABLED	0x01
#define	APM_ERR_REALALREADY	0x02
#define	APM_ERR_NOTCONN		0x03
#define	APM_ERR_16ALREADY	0x05
#define	APM_ERR_16NOTSUPP	0x06
#define	APM_ERR_32ALREADY	0x07
#define	APM_ERR_32NOTSUPP	0x08
#define	APM_ERR_UNRECOG_DEV	0x09
#define	APM_ERR_ERANGE		0x0A
#define	APM_ERR_NOTENGAGED	0x0B
#define	APM_ERR_EOPNOSUPP	0x0C
#define	APM_ERR_RTIMER_DISABLED	0x0D
#define APM_ERR_UNABLE		0x60
#define APM_ERR_NOEVENTS	0x80
#define	APM_ERR_NOT_PRESENT	0x86

#define APM_DEV_APM_BIOS	0x0000
#define APM_DEV_ALLDEVS		0x0001
/* device classes are high byte; device IDs go in low byte */
#define		APM_DEV_DISPLAY(x)	(0x0100|((x)&0xff))
#define		APM_DEV_DISK(x)		(0x0200|((x)&0xff))
#define		APM_DEV_PARALLEL(x)	(0x0300|((x)&0xff))
#define		APM_DEV_SERIAL(x)	(0x0400|((x)&0xff))
#define		APM_DEV_NETWORK(x)	(0x0500|((x)&0xff))
#define		APM_DEV_PCMCIA(x)	(0x0600|((x)&0xff))
#define		APM_DEV_BATTERIES(x)	(0x8000|((x)&0xff))
#define		APM_DEV_ALLUNITS	0xff
/* 0x8100-0xDFFF - reserved	*/
/* 0xE000-0xEFFF - OEM-defined	*/
/* 0xF000-0xFFFF - reserved	*/

#define	APM_INSTCHECK		0x5300	/* int15 only */
#define		APM_16BIT_SUPPORT	0x01
#define		APM_32BIT_SUPPORT	0x02
#define		APM_CPUIDLE_SLOW	0x04
#define		APM_DISABLED		0x08
#define		APM_DISENGAGED		0x10

#define	APM_REAL_CONNECT	0x5301	/* int15 only */
#define	APM_PROT16_CONNECT	0x5302	/* int15 only */
#define	APM_PROT32_CONNECT	0x5303	/* int15 only */
#define APM_DISCONNECT		0x5304	/* %bx = APM_DEV_APM_BIOS */

#define APM_CPU_IDLE		0x5305
#define APM_CPU_BUSY		0x5306

#define APM_SET_PWR_STATE	0x5307
#define		APM_SYS_READY		0x0000	/* %cx */
#define		APM_SYS_STANDBY		0x0001
#define		APM_SYS_SUSPEND		0x0002
#define		APM_SYS_OFF		0x0003
#define		APM_LASTREQ_INPROG	0x0004
#define		APM_LASTREQ_REJECTED	0x0005
/* 0x0006 - 0x001f	Reserved system states    */
/* 0x0020 - 0x003f	OEM-defined system states */
/* 0x0040 - 0x007f	OEM-defined device states */
/* 0x0080 - 0xffff	Reserved device states    */

/* system standby is device ID (%bx) 0x0001, APM_SYS_STANDBY */
/* system suspend is device ID (%bx) 0x0001, APM_SYS_SUSPEND */

#define APM_PWR_MGT_ENABLE	0x5308
#define		APM_MGT_ALL	0xffff	/* %bx */
#define		APM_MGT_DISABLE	0x0	/* %cx */
#define		APM_MGT_ENABLE	0x1

#define APM_SYSTEM_DEFAULTS	0x5309
#define		APM_DEFAULTS_ALL	0xffff	/* %bx */

#define APM_POWER_STATUS	0x530a
#define		APM_AC_OFF		0x00
#define		APM_AC_ON		0x01
#define		APM_AC_BACKUP		0x02
#define		APM_AC_UNKNOWN		0xff
#define		APM_BATT_HIGH		0x00
#define		APM_BATT_LOW		0x01
#define		APM_BATT_CRITICAL	0x02
#define		APM_BATT_CHARGING	0x03
#define		APM_BATT_UNKNOWN	0xff
#define		APM_BATT_FLAG_HIGH	0x01
#define		APM_BATT_FLAG_LOW	0x02
#define		APM_BATT_FLAG_CRITICAL	0x04
#define		APM_BATT_FLAG_CHARGING	0x08
#define		APM_BATT_FLAG_NOBATTERY	0x10
#define		APM_BATT_FLAG_NOSYSBATT	0x80
#define		APM_BATT_LIFE_UNKNOWN	0xff
#define		BATT_STATE(regp) ((regp)->bx & 0xff)
#define		BATT_FLAGS(regp) (((regp)->cx & 0xff00) >> 8)
#define		AC_STATE(regp) (((regp)->bx & 0xff00) >> 8)
#define		BATT_LIFE(regp) ((regp)->cx & 0xff) /* in % */
/* Return time in minutes. According to the APM 1.2 spec:
	DX = Remaining battery life -- time units
		Bit 15 = 0	Time units are seconds
		       = 1 	Time units are minutes
		Bits 14-0 =	Number of seconds or minutes */
#define		BATT_REMAINING(regp) (((regp)->dx & 0x8000) ? \
				      ((regp)->dx & 0x7fff) : \
				      ((regp)->dx & 0x7fff)/60)
#define		BATT_REM_VALID(regp) (((regp)->dx & 0xffff) != 0xffff)
#define		BATT_COUNT(regp)	((regp)->si)

#define	APM_GET_PM_EVENT	0x530b
#define		APM_NOEVENT		0x0000
#define		APM_STANDBY_REQ		0x0001 /* %bx on return */
#define		APM_SUSPEND_REQ		0x0002
#define		APM_NORMAL_RESUME	0x0003
#define		APM_CRIT_RESUME		0x0004 /* suspend/resume happened
						  without us */
#define		APM_BATTERY_LOW		0x0005
#define		APM_POWER_CHANGE	0x0006
#define		APM_UPDATE_TIME		0x0007
#define		APM_CRIT_SUSPEND_REQ	0x0008
#define		APM_USER_STANDBY_REQ	0x0009
#define		APM_USER_SUSPEND_REQ	0x000A
#define		APM_SYS_STANDBY_RESUME	0x000B
#define		APM_CAPABILITY_CHANGE	0x000C	/* apm v1.2 */
/* 0x000d - 0x00ff	Reserved system events */
#define		APM_USER_HIBERNATE_REQ	0x000D
/* 0x0100 - 0x01ff	Reserved device events */
/* 0x0200 - 0x02ff	OEM-defined APM events */
/* 0x0300 - 0xffff	Reserved */
#define		APM_EVENT_MASK		0xffff

#define	APM_EVENT_COMPOSE(t,i)	((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK))
#define	APM_EVENT_TYPE(e)	((e) & APM_EVENT_MASK)
#define	APM_EVENT_INDEX(e)	((e) >> 16)

#define	APM_GET_POWER_STATE	0x530c
#define	APM_DEVICE_MGMT_ENABLE	0x530d

#define	APM_DRIVER_VERSION	0x530e
/* %bx should be DEV value (APM_DEV_APM_BIOS)
   %ch = driver major vno
   %cl = driver minor vno
   return: %ah = conn major; %al = conn minor
   */
#define		APM_CONN_MINOR(regp) ((regp)->ax & 0xff)
#define		APM_CONN_MAJOR(regp) (((regp)->ax & 0xff00) >> 8)

#define APM_PWR_MGT_ENGAGE	0x530F
#define		APM_MGT_DISENGAGE	0x0	/* %cx */
#define		APM_MGT_ENGAGE		0x1

/* %bx - APM_DEV_APM_BIOS
 * %bl - number of batteries
 * %cx - capabilities
 */
#define	APM_GET_CAPABILITIES	0x5310
#define		APM_NBATTERIES(regp)	((regp)->bx)
#define		APM_GLOBAL_STANDBY	0x0001
#define		APM_GLOBAL_SUSPEND	0x0002
#define		APM_RTIMER_STANDBY	0x0004	/* resume time wakes up */
#define		APM_RTIMER_SUSPEND	0x0008
#define		APM_IRRING_STANDBY	0x0010	/* internal ring wakes up */
#define		APM_IRRING_SUSPEND	0x0020
#define		APM_PCCARD_STANDBY	0x0040	/* pccard wakes up */
#define		APM_PCCARD_SUSPEND	0x0080

/* %bx - APM_DEV_APM_BIOS
 * %cl - function
 *	for %cl=2 (set resume timer)
 * %ch - seconds in BCD
 * %dh - hours in BCD
 * %dl - minutes in BCD
 * %si - month in BCD (high), day in BCD (low)
 * %di - year in BCD
 */
#define	APM_RESUME_TIMER	0x5311
#define		APM_RT_DISABLE	0x0
#define		APM_RT_GET	0x1
#define		APM_RT_SET	0x2

/* %bx - APM_DEV_APM_BIOS
 * %cx - function
 */
#define	APM_RESUME_ON_RING	0x5312
#define		APM_ROR_DISABLE	0x0
#define		APM_ROR_ENABLE	0x1
#define		APM_ROR_STATUS	0x2

/* %bx - APM_EDV_APM_BIOS
 * %cx - function
 */
#define	APM_INACTIVITY_TIMER	0x5313
#define		APM_IT_DISABLE	0x0
#define		APM_IT_ENABLE	0x1
#define		APM_IT_STATUS	0x2

/* %bh - function */
#define APM_OEM			0x5380
#define		APM_OEM_INSTCHECK	0x7f	/* %bx - OEM ID */

/*
 * LP (Laptop Package)
 *
 * Copyright (C) 1994 by HOSOKAWA Tatsumi <hosokawa@mt.cs.keio.ac.jp>
 *
 * This software may be used, modified, copied, and distributed, in
 * both source and binary form provided that the above copyright and
 * these terms are retained. Under no circumstances is the author
 * responsible for the proper functioning of this software, nor does
 * the author assume any responsibility for damages incurred with its
 * use.
 *
 * Sep., 1994	Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
 */

#define APM_BATTERY_ABSENT 4

struct apm_power_info {
	u_char battery_state;
	u_char ac_state;
	u_char battery_life;
	u_char spare1;
	u_int minutes_left;		/* estimate */
	u_int spare2[6];
};

struct apm_ctl {
	u_int dev;
	u_int mode;
};

#define	APM_IOC_REJECT	_IOW('A', 0, struct apm_event_info) /* reject request # */
#define	APM_IOC_STANDBY	_IO('A', 1)	/* put system into standby */
#define	APM_IOC_SUSPEND	_IO('A', 2)	/* put system into suspend */
#define	APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */
#define	APM_IOC_DEV_CTL	_IOW('A', 5, struct apm_ctl) /* put device into mode */
#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */
#define		APM_PRINT_ON	0	/* driver power status displayed */
#define		APM_PRINT_OFF	1	/* driver power status not displayed */
#define		APM_PRINT_PCT	2	/* driver power status only displayed
					   if the percentage changes */
#define	APM_IOC_STANDBY_REQ	_IO('A', 7)	/* request standby */
#define	APM_IOC_SUSPEND_REQ	_IO('A', 8)	/* request suspend */
#define	APM_IOC_HIBERNATE	_IO('A', 9)	/* put system into hibernate */

#ifdef _KERNEL
extern void apm_cpu_busy(void);
extern void apm_cpu_idle(void);
extern void apminit(void);
int apm_set_powstate(u_int devid, u_int powstate);
#endif /* _KERNEL */

#endif /* _MACHINE_APMVAR_H_ */


code:
/*	$OpenBSD: asm.h,v 1.6 2015/05/13 05:29:57 uebayasi Exp $	*/
/*	$NetBSD: asm.h,v 1.2 2003/05/02 18:05:47 yamt Exp $	*/

/*-
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * William Jolitz.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)asm.h	5.5 (Berkeley) 5/7/91
 */

#ifndef _MACHINE_ASM_H_
#define _MACHINE_ASM_H_

#ifdef __PIC__
#define PIC_PLT(x)	x@PLT
#define PIC_GOT(x)	x@GOTPCREL(%rip)
#else
#define PIC_PLT(x)	x
#define PIC_GOT(x)	x
#endif

# define _C_LABEL(x)	x
#define	_ASM_LABEL(x)	x

#define CVAROFF(x,y)		(_C_LABEL(x)+y)(%rip)

#ifdef __STDC__
# define __CONCAT(x,y)	x ## y
# define __STRING(x)	#x
#else
# define __CONCAT(x,y)	x/**/y
# define __STRING(x)	"x"
#endif

/* let kernels and others override entrypoint alignment */
#ifndef _ALIGN_TEXT
#define _ALIGN_TEXT .align 16, 0x90
#endif

#define _ENTRY(x) \
	.text; _ALIGN_TEXT; .globl x; .type x,@function; x:

#ifdef _KERNEL
/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
#ifdef __STDC__
#define	IDTVEC(name) \
	.text; ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
#else
#define	IDTVEC(name) \
	.text; ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
#endif /* __STDC__ */
#endif /* _KERNEL */

#ifdef __STDC__
#define CPUVAR(off)	%gs:CPU_INFO_ ## off
#else
#define CPUVAR(off)     %gs:CPU_INFO_/**/off
#endif

#ifdef GPROF
# define _PROF_PROLOGUE	\
	pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp
#else
# define _PROF_PROLOGUE
#endif

#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
#define	END(y)		.size y, . - y

#define	ASMSTR		.asciz

#define RCSID(x)	.text; .asciz x

#define	STRONG_ALIAS(alias,sym)						\
	.global alias;							\
	alias = sym
#define	WEAK_ALIAS(alias,sym)						\
	.weak alias;							\
	alias = sym

/* XXXfvdl do not use stabs here */
#ifdef __STDC__
#define	WARN_REFERENCES(sym,msg)					\
	.stabs msg ## ,30,0,0,0 ;					\
	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
#else
#define	WARN_REFERENCES(sym,msg)					\
	.stabs msg,30,0,0,0 ;						\
	.stabs __STRING(sym),1,0,0,0
#endif /* __STDC__ */

#endif /* !_MACHINE_ASM_H_ */


code:
/*	$OpenBSD: atomic.h,v 1.17 2015/01/06 00:38:32 dlg Exp $	*/
/*	$NetBSD: atomic.h,v 1.1 2003/04/26 18:39:37 fvdl Exp $	*/

/*
 * Copyright 2002 (c) Wasabi Systems, Inc.
 * All rights reserved.
 *
 * Written by Frank van der Linden for Wasabi Systems, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed for the NetBSD Project by
 *      Wasabi Systems, Inc.
 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _MACHINE_ATOMIC_H_
#define _MACHINE_ATOMIC_H_

/*
 * Perform atomic operations on memory. Should be atomic with respect
 * to interrupts and multiple processors.
 *
 * void atomic_setbits_int(volatile u_int *a, u_int mask) { *a |= mask; }
 * void atomic_clearbits_int(volatile u_int *a, u_int mas) { *a &= ~mask; }
 */

#if defined(_KERNEL) && !defined(_LOCORE)

#ifdef MULTIPROCESSOR
#define LOCK "lock"
#else
#define LOCK
#endif

static inline unsigned int
_atomic_cas_uint(volatile unsigned int *p, unsigned int e, unsigned int n)
{
	__asm volatile(LOCK " cmpxchgl %2, %1"
	    : "=a" (n), "=m" (*p)
	    : "r" (n), "a" (e), "m" (*p));

	return (n);
}
#define atomic_cas_uint(_p, _e, _n) _atomic_cas_uint((_p), (_e), (_n))

static inline unsigned long
_atomic_cas_ulong(volatile unsigned long *p, unsigned long e, unsigned long n)
{
	__asm volatile(LOCK " cmpxchgq %2, %1"
	    : "=a" (n), "=m" (*p)
	    : "r" (n), "a" (e), "m" (*p));

	return (n);
}
#define atomic_cas_ulong(_p, _e, _n) _atomic_cas_ulong((_p), (_e), (_n))

static inline void *
_atomic_cas_ptr(volatile void *p, void *e, void *n)
{
	__asm volatile(LOCK " cmpxchgq %2, %1"
	    : "=a" (n), "=m" (*(unsigned long *)p)
	    : "r" (n), "a" (e), "m" (*(unsigned long *)p));

	return (n);
}
#define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n))

static inline unsigned int
_atomic_swap_uint(volatile unsigned int *p, unsigned int n)
{
	__asm volatile("xchgl %0, %1"
	    : "=a" (n), "=m" (*p)
	    : "0" (n), "m" (*p));

	return (n);
}
#define atomic_swap_uint(_p, _n) _atomic_swap_uint((_p), (_n))
#define atomic_swap_32(_p, _n) _atomic_swap_uint((_p), (_n))

static inline unsigned long
_atomic_swap_ulong(volatile unsigned long *p, unsigned long n)
{
	__asm volatile("xchgq %0, %1"
	    : "=a" (n), "=m" (*p)
	    : "0" (n), "m" (*p));

	return (n);
}
#define atomic_swap_ulong(_p, _n) _atomic_swap_ulong((_p), (_n))

static inline uint64_t
_atomic_swap_64(volatile uint64_t *p, uint64_t n)
{
	__asm volatile("xchgq %0, %1"
	    : "=a" (n), "=m" (*p)
	    : "0" (n), "m" (*p));

	return (n);
}
#define atomic_swap_64(_p, _n) _atomic_swap_64((_p), (_n))

static inline void *
_atomic_swap_ptr(volatile void *p, void *n)
{
	__asm volatile("xchgq %0, %1"
	    : "=a" (n), "=m" (*(unsigned long *)p)
	    : "0" (n), "m" (*(unsigned long *)p));

	return (n);
}
#define atomic_swap_ptr(_p, _n) _atomic_swap_ptr((_p), (_n))

static inline void
_atomic_inc_int(volatile unsigned int *p)
{
	__asm volatile(LOCK " incl %0"
	    : "+m" (*p));
}
#define atomic_inc_int(_p) _atomic_inc_int(_p)

static inline void
_atomic_inc_long(volatile unsigned long *p)
{
	__asm volatile(LOCK " incq %0"
	    : "+m" (*p));
}
#define atomic_inc_long(_p) _atomic_inc_long(_p)

static inline void
_atomic_dec_int(volatile unsigned int *p)
{
	__asm volatile(LOCK " decl %0"
	    : "+m" (*p));
}
#define atomic_dec_int(_p) _atomic_dec_int(_p)

static inline void
_atomic_dec_long(volatile unsigned long *p)
{
	__asm volatile(LOCK " decq %0"
	    : "+m" (*p));
}
#define atomic_dec_long(_p) _atomic_dec_long(_p)

static inline void
_atomic_add_int(volatile unsigned int *p, unsigned int v)
{
	__asm volatile(LOCK " addl %1,%0"
	    : "+m" (*p)
	    : "a" (v));
}
#define atomic_add_int(_p, _v) _atomic_add_int(_p, _v)

static inline void
_atomic_add_long(volatile unsigned long *p, unsigned long v)
{
	__asm volatile(LOCK " addq %1,%0"
	    : "+m" (*p)
	    : "a" (v));
}
#define atomic_add_long(_p, _v) _atomic_add_long(_p, _v)

static inline void
_atomic_sub_int(volatile unsigned int *p, unsigned int v)
{
	__asm volatile(LOCK " subl %1,%0"
	    : "+m" (*p)
	    : "a" (v));
}
#define atomic_sub_int(_p, _v) _atomic_sub_int(_p, _v)

static inline void
_atomic_sub_long(volatile unsigned long *p, unsigned long v)
{
	__asm volatile(LOCK " subq %1,%0"
	    : "+m" (*p)
	    : "a" (v));
}
#define atomic_sub_long(_p, _v) _atomic_sub_long(_p, _v)

static inline unsigned long
_atomic_add_int_nv(volatile unsigned int *p, unsigned int v)
{
	unsigned int rv = v;

	__asm volatile(LOCK " xaddl %0,%1"
	    : "+a" (rv), "+m" (*p));

	return (rv + v);
}
#define atomic_add_int_nv(_p, _v) _atomic_add_int_nv(_p, _v)

static inline unsigned long
_atomic_add_long_nv(volatile unsigned long *p, unsigned long v)
{
	unsigned long rv = v;

	__asm volatile(LOCK " xaddq %0,%1"
	    : "+a" (rv), "+m" (*p));

	return (rv + v);
}
#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv(_p, _v)

static inline unsigned long
_atomic_sub_int_nv(volatile unsigned int *p, unsigned int v)
{
	unsigned int rv = 0 - v;

	__asm volatile(LOCK " xaddl %0,%1"
	    : "+a" (rv), "+m" (*p));

	return (rv - v);
}
#define atomic_sub_int_nv(_p, _v) _atomic_sub_int_nv(_p, _v)

static inline unsigned long
_atomic_sub_long_nv(volatile unsigned long *p, unsigned long v)
{
	unsigned long rv = 0 - v;

	__asm volatile(LOCK " xaddq %0,%1"
	    : "+a" (rv), "+m" (*p));

	return (rv - v);
}
#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv(_p, _v)

/*
 * The AMD64 architecture is rather strongly ordered.  When accessing
 * normal write-back cachable memory, only reads may be reordered with
 * older writes to different locations.  There are a few instructions
 * (clfush, non-temporal move instructions) that obey weaker ordering
 * rules, but those instructions will only be used in (inline)
 * assembly code where we can add the necessary fence instructions
 * ourselves.
 */

#define __membar(_f) do { __asm __volatile(_f ::: "memory"); } while (0)

#ifdef MULTIPROCESSOR
#define membar_enter()		__membar("mfence")
#define membar_exit()		__membar("")
#define membar_producer()	__membar("")
#define membar_consumer()	__membar("")
#define membar_sync()		__membar("mfence")
#else
#define membar_enter()		__membar("")
#define membar_exit()		__membar("")
#define membar_producer()	__membar("")
#define membar_consumer()	__membar("")
#define membar_sync()		__membar("")
#endif

/* virtio needs MP membars even on SP kernels */
#define virtio_membar_producer()	__membar("")
#define virtio_membar_consumer()	__membar("")
#define virtio_membar_sync()		__membar("mfence")

static __inline void
x86_atomic_setbits_u32(volatile u_int32_t *ptr, u_int32_t bits)
{
	__asm volatile(LOCK " orl %1,%0" :  "=m" (*ptr) : "ir" (bits));
}

static __inline void
x86_atomic_clearbits_u32(volatile u_int32_t *ptr, u_int32_t bits)
{
	__asm volatile(LOCK " andl %1,%0" :  "=m" (*ptr) : "ir" (~bits));
}

/*
 * XXX XXX XXX
 * theoretically 64bit cannot be used as
 * an "i" and thus if we ever try to give
 * these anything from the high dword there
 * is an asm error pending
 */
static __inline void
x86_atomic_setbits_u64(volatile u_int64_t *ptr, u_int64_t bits)
{
	__asm volatile(LOCK " orq %1,%0" :  "=m" (*ptr) : "ir" (bits));
}

static __inline void
x86_atomic_clearbits_u64(volatile u_int64_t *ptr, u_int64_t bits)
{
	__asm volatile(LOCK " andq %1,%0" :  "=m" (*ptr) : "ir" (~bits));
}

#define x86_atomic_testset_ul	x86_atomic_testset_u64
#define x86_atomic_setbits_ul	x86_atomic_setbits_u64
#define x86_atomic_clearbits_ul	x86_atomic_clearbits_u64

#define atomic_setbits_int x86_atomic_setbits_u32
#define atomic_clearbits_int x86_atomic_clearbits_u32

#undef LOCK

#endif /* defined(_KERNEL) && !defined(_LOCORE) */
#endif /* _MACHINE_ATOMIC_H_ */


code:
/*	$OpenBSD: biosvar.h,v 1.21 2015/07/17 21:53:56 mlarkin Exp $	*/

/*
 * Copyright (c) 1997-1999 Michael Shalayeff
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _MACHINE_BIOSVAR_H_
#define _MACHINE_BIOSVAR_H_

	/* some boxes put apm data seg in the 2nd page */
#define	BOOTARG_OFF	(PAGE_SIZE * 2)
#define	BOOTARG_LEN	(PAGE_SIZE * 1)
#define	BOOTBIOS_ADDR	(0x7c00)
#define	BOOTBIOS_MAXSEC	((1 << 28) - 1)

	/* BIOS configure flags */
#define	BIOSF_BIOS32	0x0001
#define	BIOSF_PCIBIOS	0x0002
#define	BIOSF_PROMSCAN	0x0004
#define BIOSF_SMBIOS	0x0006

/* BIOS media ID */
#define BIOSM_F320K	0xff	/* floppy ds/sd  8 spt */
#define	BIOSM_F160K	0xfe	/* floppy ss/sd  8 spt */
#define	BIOSM_F360K	0xfd	/* floppy ds/sd  9 spt */
#define	BIOSM_F180K	0xfc	/* floppy ss/sd  9 spt */
#define	BIOSM_ROMD	0xfa	/* ROM disk */
#define	BIOSM_F120M	0xf9	/* floppy ds/hd 15 spt 5.25" */
#define	BIOSM_F720K	0xf9	/* floppy ds/dd  9 spt 3.50" */
#define	BIOSM_HD	0xf8	/* hard drive */
#define	BIOSM_F144K	0xf0	/* floppy ds/hd 18 spt 3.50" */
#define	BIOSM_OTHER	0xf0	/* any other */

/*
 * BIOS memory maps
 */
#define	BIOS_MAP_END	0x00	/* End of array XXX - special */
#define	BIOS_MAP_FREE	0x01	/* Usable memory */
#define	BIOS_MAP_RES	0x02	/* Reserved memory */
#define	BIOS_MAP_ACPI	0x03	/* ACPI Reclaim memory */
#define	BIOS_MAP_NVS	0x04	/* ACPI NVS memory */

/*
 * Optional ROM header
 */
typedef
struct bios_romheader {
	u_int16_t	signature;	/* 0xaa55 */
	u_int8_t	len;		/* length in pages (512 bytes) */
	u_int32_t	entry;		/* initialization entry point */
	u_int8_t	reserved[19];
	u_int16_t	pnpheader;	/* offset to PnP expansion header */
} __packed *bios_romheader_t;

#define	BIOS32_MAKESIG(a, b, c, d) \
	((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
#define	SMBIOS_SIGNATURE	BIOS32_MAKESIG('_', 'S', 'M', '_')

/*
 * CTL_BIOS definitions.
 */
#define	BIOS_DEV		1	/* int: BIOS boot device */
#define	BIOS_DISKINFO		2	/* struct: BIOS boot device info */
#define BIOS_CKSUMLEN		3	/* int: disk cksum block count */
#define	BIOS_MAXID		4	/* number of valid machdep ids */

#define	CTL_BIOS_NAMES { \
	{ 0, 0 }, \
	{ "biosdev", CTLTYPE_INT }, \
	{ "diskinfo", CTLTYPE_STRUCT }, \
	{ "cksumlen", CTLTYPE_INT }, \
}

#define	BOOTARG_MEMMAP 0
typedef struct _bios_memmap {
	u_int64_t addr;		/* Beginning of block */
	u_int64_t size;		/* Size of block */
	u_int32_t type;		/* Type of block */
} __packed bios_memmap_t;

/* Info about disk from the bios, plus the mapping from
 * BIOS numbers to BSD major (driver?) number.
 *
 * Also, do not bother with BIOSN*() macros, just parcel
 * the info out, and use it like this.  This makes for less
 * of a dependance on BIOSN*() macros having to be the same
 * across /boot, /bsd, and userland.
 */
#define	BOOTARG_DISKINFO 1
typedef struct _bios_diskinfo {
	/* BIOS section */
	int bios_number;	/* BIOS number of drive (or -1) */
	u_int bios_cylinders;	/* BIOS cylinders */
	u_int bios_heads;	/* BIOS heads */
	u_int bios_sectors;	/* BIOS sectors */
	int bios_edd;		/* EDD support */

	/* BSD section */
	dev_t bsd_dev;		/* BSD device */

	/* Checksum section */
	u_int32_t checksum;	/* Checksum for drive */

	/* Misc. flags */
	u_int32_t flags;
#define BDI_INVALID	0x00000001	/* I/O error during checksumming */
#define BDI_GOODLABEL	0x00000002	/* Had SCSI or ST506/ESDI disklabel */
#define BDI_BADLABEL	0x00000004	/* Had another disklabel */
#define BDI_EL_TORITO	0x00000008	/* 2,048-byte sectors */
#define BDI_PICKED	0x80000000	/* kernel-only: cksum matched */

} __packed bios_diskinfo_t;

#define	BOOTARG_APMINFO 2
typedef struct _bios_apminfo {
	/* APM_CONNECT returned values */
	u_int	apm_detail;
	u_int	apm_code32_base;
	u_int	apm_code16_base;
	u_int	apm_code_len;
	u_int	apm_data_base;
	u_int	apm_data_len;
	u_int	apm_entry;
	u_int	apm_code16_len;
} __packed bios_apminfo_t;

#define	BOOTARG_CKSUMLEN 3		/* u_int32_t */

#define	BOOTARG_PCIINFO 4
typedef struct _bios_pciinfo {
	/* PCI BIOS v2.0+ - Installation check values */
	u_int32_t	pci_chars;	/* Characteristics (%eax) */
	u_int32_t	pci_rev;	/* BCD Revision (%ebx) */
	u_int32_t	pci_entry32;	/* PM entry point for PCI BIOS */
	u_int32_t	pci_lastbus;	/* Number of last PCI bus */
} __packed bios_pciinfo_t;

#define	BOOTARG_CONSDEV	5
typedef struct _bios_consdev {
	dev_t	consdev;
	int	conspeed;
	int	consaddr;
	int	consfreq;
} __packed bios_consdev_t;

#define BOOTARG_BOOTMAC	7
typedef struct _bios_bootmac {
	char	mac[6];
} __packed bios_bootmac_t;

#define BOOTARG_DDB 8
typedef struct _bios_ddb {
	int	db_console;
} __packed bios_ddb_t;

#define BOOTARG_BOOTDUID 9
typedef struct _bios_bootduid {
	u_char	duid[8];
} __packed bios_bootduid_t;

#define BOOTARG_BOOTSR 10
#define BOOTSR_UUID_MAX 16
#define BOOTSR_CRYPTO_MAXKEYBYTES 32
typedef struct _bios_bootsr {
	u_int8_t	uuid[BOOTSR_UUID_MAX];
	u_int8_t	maskkey[BOOTSR_CRYPTO_MAXKEYBYTES];
} __packed bios_bootsr_t;

#if defined(_KERNEL) || defined (_STANDALONE)

#ifdef _LOCORE
#define	DOINT(n)	int	$0x20+(n)
#else
#define	DOINT(n)	"int $0x20+(" #n ")"

extern volatile struct BIOS_regs {
	u_int32_t	biosr_ax;
	u_int32_t	biosr_cx;
	u_int32_t	biosr_dx;
	u_int32_t	biosr_bx;
	u_int32_t	biosr_bp;
	u_int32_t	biosr_si;
	u_int32_t	biosr_di;
	u_int32_t	biosr_ds;
	u_int32_t	biosr_es;
} __packed BIOS_regs;

#ifdef _KERNEL
#include <machine/bus.h>

struct bios_attach_args {
	char		*ba_name;
	u_int		ba_biosfunc;
	bus_space_tag_t	ba_iot;
	bus_space_tag_t	ba_memt;
	union {
		void		*_p;
		bios_apminfo_t	*_ba_apmp;
		paddr_t		_ba_acpipbase;
	} _;
};

#define	ba_apmp		_._ba_apmp
#define ba_acpipbase	_._ba_acpipbase

struct consdev;
struct proc;

int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *);

void bios_getopt(void);
bios_diskinfo_t *bios_getdiskinfo(dev_t);

extern u_int bootapiver;
extern bios_memmap_t *bios_memmap;

#endif /* _KERNEL */
#endif /* _LOCORE */
#endif /* _KERNEL || _STANDALONE */

#endif /* _MACHINE_BIOSVAR_H_ */