code:
/*	$OpenBSD: zaurus_machdep.c,v 1.59 2015/05/10 15:56:28 jsg Exp $	*/
/*	$NetBSD: lubbock_machdep.c,v 1.2 2003/07/15 00:25:06 lukem Exp $ */

/*
 * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
 * Written by Hiroyuki Bessho for Genetec Corporation.
 *
 * 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 Genetec Corporation may not be used to endorse or
 *    promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``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 GENETEC CORPORATION
 * 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.
 *
 * Machine dependant functions for kernel setup for
 * Intel DBPXA250 evaluation board (a.k.a. Lubbock).
 * Based on iq80310_machhdep.c
 */
/*
 * Copyright (c) 2001 Wasabi Systems, Inc.
 * All rights reserved.
 *
 * Written by Jason R. Thorpe 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.
 */

/*
 * Copyright (c) 1997,1998 Mark Brinicombe.
 * Copyright (c) 1997,1998 Causality Limited.
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Mark Brinicombe
 *	for the NetBSD Project.
 * 4. The name of the company nor the name of the author may 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 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.
 *
 * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
 * boards using RedBoot firmware.
 */

/*
 * DIP switches:
 *
 * S19: no-dot: set RB_KDB.  enter kgdb session.
 * S20: no-dot: set RB_SINGLE. don't go multi user mode.
 */

#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/exec.h>
#include <sys/proc.h>
#include <sys/msgbuf.h>
#include <sys/reboot.h>
#include <sys/termios.h>
#include <sys/kcore.h>

#include <uvm/uvm_extern.h>

#include <sys/conf.h>
#include <sys/queue.h>
#include <dev/cons.h>
#include <sys/socket.h>

#include <machine/db_machdep.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#ifdef KGDB
#include <sys/kgdb.h>
#endif

#include <net/if.h>

#include <machine/bootconfig.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/frame.h>
#include <arm/kcore.h>
#include <arm/undefined.h>
#include <arm/machdep.h>

#include <arm/xscale/pxa2x0reg.h>
#include <arm/xscale/pxa2x0var.h>
#include <arm/xscale/pxa2x0_gpio.h>
#include <arm/sa11x0/sa1111_reg.h>
#include <machine/machine_reg.h>
#include <machine/zaurus_var.h>

#include <zaurus/dev/zaurus_scoopreg.h>

#include "apm.h"
#if NAPM > 0
#include <zaurus/dev/zaurus_apm.h>
#endif

#include "wsdisplay.h"

/* Kernel text starts 2MB in from the bottom of the kernel address space. */
#define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
#define	KERNEL_VM_BASE		(KERNEL_BASE + 0x04000000)
#define KERNEL_VM_SIZE		VM_KERNEL_SPACE_SIZE

/*
 * Address to call from cpu_reset() to reset the machine.
 * This is machine architecture dependant as it varies depending
 * on where the ROM appears when you turn the MMU off.
 */

u_int cpu_reset_address = 0;

/* Define various stack sizes in pages */
#define IRQ_STACK_SIZE	1
#define ABT_STACK_SIZE	1
#define UND_STACK_SIZE	1

int zaurusmod;

BootConfig bootconfig;		/* Boot config storage */
char *boot_args = NULL;
char *boot_file = NULL;

paddr_t physical_start;
paddr_t physical_freestart;
paddr_t physical_freeend;
paddr_t physical_end;
u_int free_pages;
int physmem = 0;

/*int debug_flags;*/
#ifndef PMAP_STATIC_L1S
int max_processes = 64;			/* Default number */
#endif	/* !PMAP_STATIC_L1S */

/* Physical and virtual addresses for some global pages */
pv_addr_t systempage;
pv_addr_t irqstack;
pv_addr_t undstack;
pv_addr_t abtstack;
extern pv_addr_t kernelstack;
pv_addr_t minidataclean;

paddr_t msgbufphys;

extern u_int data_abort_handler_address;
extern u_int prefetch_abort_handler_address;
extern u_int undefined_handler_address;

#ifdef PMAP_DEBUG
extern int pmap_debug_level;
#endif

#define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
#define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
#define	KERNEL_PT_KERNEL_NUM	32
#define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
				        /* Page tables for mapping kernel VM */
#define	KERNEL_PT_VMDATA_NUM	8	/* start with 32MB of KVM */
#define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)

pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];

extern struct user *proc0paddr;

/*
 * safepri is a safe priority for sleep to set for a spin-wait
 * during autoconfiguration or after a panic.
 */
int   safepri = 0;

/* Prototypes */

#define	BOOT_STRING_MAGIC 0x4f425344

char	bootargs[MAX_BOOT_STRING];
void	process_kernel_args(char *);

void	consinit(void);
void	early_clkman(u_int, int);
void	kgdb_port_init(void);
void	change_clock(uint32_t v);

bs_protos(bs_notimpl);

#include "com.h"
#if NCOM > 0
#include <dev/ic/comvar.h>
#include <dev/ic/comreg.h>
#endif

#ifndef CONSPEED
#define CONSPEED B9600	/* What RedBoot uses */
#endif
#ifndef CONMODE
#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
#endif

int comcnspeed = CONSPEED;
int comcnmode = CONMODE;

/*
 * void boot(int howto)
 *
 * Reboots the system
 *
 * Deal with any syncing, unmounting, dumping and shutdown hooks,
 * then reset the CPU.
 */
__dead void
boot(int howto)
{
	extern int lid_suspend;

	if ((howto & RB_POWERDOWN) != 0)
		lid_suspend = 0;

	if (cold) {
		if ((howto & RB_USERREQ) == 0)
			howto |= RB_HALT;
		goto haltsys;
	}

	/*
	 * If RB_NOSYNC was not specified sync the discs.
	 * Note: Unless cold is set to 1 here, syslogd will die during the
	 * unmount.  It looks like syslogd is getting woken up only to find
	 * that it cannot page part of the binary in as the filesystem has
	 * been unmounted.
	 */
	if ((howto & RB_NOSYNC) == 0)
		bootsync(howto);

	if_downall();

	uvm_shutdown();
	splhigh();
	cold = 1;

	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
		dumpsys();

haltsys:
	config_suspend_all(DVACT_POWERDOWN);

	/* Make sure IRQ's are disabled */
	IRQdisable;

	if ((howto & RB_HALT) != 0) {
#if NAPM > 0
		if ((howto & RB_POWERDOWN) != 0) {

			printf("\nAttempting to power down...\n");
			delay(6000000);
			zapm_poweroff();
		}
#endif

		printf("The operating system has halted.\n");
		printf("Please press any key to reboot.\n\n");
		cnpollc(1);
		cngetc();
		cnpollc(0);
	}

	printf("rebooting...\n");
	delay(6000000);
#if NAPM > 0
	zapm_restart();
#endif
	printf("reboot failed; spinning\n");
	for (;;) ;
	/* NOTREACHED */
}

static __inline
pd_entry_t *
read_ttb(void)
{
  long ttb;

  __asm volatile("mrc	p15, 0, %0, c2, c0, 0" : "=r" (ttb));

  return (pd_entry_t *)(ttb & ~((1<<14)-1));
}

/*
 * Mapping table for core kernel memory. These areas are mapped in
 * init time at fixed virtual address with section mappings.
 */
struct l1_sec_map {
	vaddr_t	va;
	vaddr_t	pa;
	vsize_t	size;
	int flags;
} l1_sec_table[] = {
    {
	    ZAURUS_GPIO_VBASE,
	    PXA2X0_GPIO_BASE,
	    PXA2X0_GPIO_SIZE,
	    PTE_NOCACHE,
    },
    {
	    ZAURUS_CLKMAN_VBASE,
	    PXA2X0_CLKMAN_BASE,
	    PXA2X0_CLKMAN_SIZE,
	    PTE_NOCACHE,
    },
    {
	    ZAURUS_INTCTL_VBASE,
	    PXA2X0_INTCTL_BASE,
	    PXA2X0_INTCTL_SIZE,
	    PTE_NOCACHE,
    },
    {
	    ZAURUS_SCOOP0_VBASE,
	    C3000_SCOOP0_BASE,
	    SCOOP_SIZE,
	    PTE_NOCACHE,
    },
    {
	    ZAURUS_SCOOP1_VBASE,
	    trunc_page(C3000_SCOOP1_BASE),
	    round_page(SCOOP_SIZE),
	    PTE_NOCACHE,
    },
    {0, 0, 0, 0,}
};

static void
map_io_area(paddr_t pagedir)
{
	int loop;

	/*
	 * Map devices we can map w/ section mappings.
	 */
	loop = 0;
	while (l1_sec_table[loop].size) {
		vsize_t sz;

#define VERBOSE_INIT_ARM
#ifdef VERBOSE_INIT_ARM
		printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
		    l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
		    l1_sec_table[loop].va);
#endif
		for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_S_SIZE)
			pmap_map_section(pagedir, l1_sec_table[loop].va + sz,
			    l1_sec_table[loop].pa + sz,
			    PROT_READ | PROT_WRITE,
			    l1_sec_table[loop].flags);
		++loop;
	}
}

/*
 * simple memory mapping function used in early bootstrap stage
 * before pmap is initialized.
 * size and cacheability are ignored and map one section with nocache.
 */
static vaddr_t section_free = ZAURUS_VBASE_FREE;

static int
bootstrap_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
    int flags, bus_space_handle_t *bshp)
{
	u_long startpa;
	vaddr_t va;
	pd_entry_t *pagedir = read_ttb();
	/* This assumes PA==VA for page directory */

	va = section_free;
	section_free += L1_S_SIZE;

	startpa = trunc_page(bpa);
	pmap_map_section((vaddr_t)pagedir, va, startpa,
	    PROT_READ | PROT_WRITE, PTE_NOCACHE);
	cpu_tlb_flushD();

	*bshp = (bus_space_handle_t)(va + (bpa - startpa));

	return(0);
}

static void
copy_io_area_map(pd_entry_t *new_pd)
{
	pd_entry_t *cur_pd = read_ttb();
	vaddr_t va;

	for (va = ZAURUS_IO_AREA_VBASE;
	     (cur_pd[va>>L1_S_SHIFT] & L1_TYPE_MASK) == L1_TYPE_S;
	     va += L1_S_SIZE) {

		new_pd[va>>L1_S_SHIFT] = cur_pd[va>>L1_S_SHIFT];
		if (va == (0 - L1_S_SIZE))
			break; /* STUPID */

	}
}

/* XXX tidy up! */
void green_on(int virt);
void
green_on(int virt)
{
	/* clobber green led p */
	volatile u_int16_t *p;
	if (virt)
		p = (u_int16_t *)(ZAURUS_SCOOP0_VBASE+SCOOP_GPWR);
	else
		p = (u_int16_t *)(C3000_SCOOP0_BASE+SCOOP_GPWR);

	*p = *p | (1<<SCOOP0_LED_GREEN);
}
void irda_on(int virt);
void
irda_on(int virt)
{
	/* clobber IrDA led p */
	volatile u_int16_t *p;
	/* XXX scoop1 registers are not page-aligned! */
	int ofs = C3000_SCOOP1_BASE - trunc_page(C3000_SCOOP1_BASE);

	if (virt)
		p = (u_int16_t *)(ZAURUS_SCOOP1_VBASE+ofs+SCOOP_GPWR);
	else
		p = (u_int16_t *)(C3000_SCOOP1_BASE+SCOOP_GPWR);

	*p = *p & ~(1<<SCOOP1_IR_ON);
}

#if 0
void sysprobe(void);
void
sysprobe(void)
{
	u_int32_t *p;

	p = (void *)0x48000014; /* MECR */
	printf("MECR %x\n", *p);

	p = (void *)0x48000028; /* MCMEM0 */
	printf("MCMEM0 %x\n", *p);
	p = (void *)0x4800002C; /* MCMEM1 */
	printf("MCMEM1 %x\n", *p);

	p = (void *)0x48000030; /* MCATTx */
	printf("MCATT0 %x\n", *p);
	p = (void *)0x48000034; /* MCATTx */
	printf("MCATT1 %x\n", *p);

	p = (void *)0x48000038; /* MCIOx */
	printf("MCIO0 %x\n", *p);
	p = (void *)0x4800003C; /* MCIOx */
	printf("MCIO1 %x\n", *p);
}
#endif

/*
 * u_int initarm(...)
 *
 * Initial entry point on startup. This gets called before main() is
 * entered.
 * It should be responsible for setting up everything that must be
 * in place when main is called.
 * This includes
 *   Taking a copy of the boot configuration structure.
 *   Initialising the physical console so characters can be printed.
 *   Setting up page tables for the kernel
 *   Relocating the kernel to the bottom of physical memory
 */
u_int
initarm(void *arg0, void *arg1, void *arg2)
{
	extern vaddr_t xscale_cache_clean_addr;
	extern cpu_kcore_hdr_t cpu_kcore_hdr;
	int loop;
	int loop1;
	u_int l1pagetable;
	pv_addr_t kernel_l1pt;
	paddr_t memstart;
	psize_t memsize;
	extern u_int32_t esym;	/* &_end if no symbols are loaded */

#if 0
	int led_data = 0;
#endif
#ifdef DIAGNOSTIC
	extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
#endif
	/* early bus_space_map support */
	struct bus_space tmp_bs_tag;
	int	(*map_func_save)(void *, bus_addr_t, bus_size_t, int,
	    bus_space_handle_t *);

#if 0
	/* XXX */
	/* start 32.768KHz OSC */
	ioreg_write(PXA2X0_CLKMAN_BASE + 0x08, 2);
#endif

	/*
	 * Heads up ... Setup the CPU / MMU / TLB functions
	 */
	if (set_cpufuncs())
		panic("cpu not recognized!");

	/* Get ready for splfoo() */
	pxa2x0_intr_bootstrap(PXA2X0_INTCTL_BASE);

#if 0
	/* Calibrate the delay loop. */
#endif

	/*
	 * Okay, RedBoot has provided us with the following memory map:
	 *
	 * Physical Address Range     Description
	 * -----------------------    ----------------------------------
	 * 0x00000000 - 0x01ffffff    flash Memory   (32MB)
	 * 0x04000000 - 0x05ffffff    Application flash Memory  (32MB)
	 * 0x08000000 - 0x080000ff    I/O baseboard registers
	 * 0x0a000000 - 0x0a0fffff    SRAM (1MB)
	 * 0x0c000000 - 0x0c0fffff    Ethernet Controller
	 * 0x0e000000 - 0x0e0fffff    Ethernet Controller (Attribute)
	 * 0x10000000 - 0x103fffff    SA-1111 Companion Chip
	 * 0x14000000 - 0x17ffffff    Expansion Card (64MB)
	 * 0x40000000 - 0x480fffff    Processor Registers
	 * 0xa0000000 - 0xa3ffffff    SDRAM Bank 0 (64MB)
	 *
	 *
	 * Virtual Address Range    X C B  Description
	 * -----------------------  - - -  ----------------------------------
	 * 0x00000000 - 0x00003fff  N Y Y  SDRAM
	 * 0x00004000 - 0x000fffff  N Y N  Boot ROM
	 * 0x00100000 - 0x01ffffff  N N N  Application Flash
	 * 0x04000000 - 0x05ffffff  N N N  Exp Application Flash
	 * 0x08000000 - 0x080fffff  N N N  I/O baseboard registers
	 * 0x0a000000 - 0x0a0fffff  N N N  SRAM
	 * 0x40000000 - 0x480fffff  N N N  Processor Registers
	 * 0xa0000000 - 0xa000ffff  N Y N  RedBoot SDRAM
	 * 0xa0017000 - 0xa3ffffff  Y Y Y  SDRAM
	 * 0xc0000000 - 0xcfffffff  Y Y Y  Cache Flush Region
	 * (done by this routine)
	 * 0xfd000000 - 0xfd0000ff  N N N  I/O baseboard registers
	 * 0xfd100000 - 0xfd2fffff  N N N  Processor Registers.
	 * 0xfd200000 - 0xfd2fffff  N N N  0x10800000 registers
	 *
	 * The first level page table is at 0xa0004000.  There are also
	 * 2 second-level tables at 0xa0008000 and 0xa0008400.
	 *
	 */

	{
		/*
		 * Tweak RedBoot's pagetable so that we can access to
		 * some registers at same VA before and after installing
		 * our page table.
		 */
		paddr_t ttb = (paddr_t)read_ttb();

		map_io_area(ttb);
		cpu_tlb_flushD();
	}

	/*
	 * Examine the boot args string for options we need to know about
	 * now.
	 */
	/* XXX should really be done after setting up the console, but we
	 * XXX need to parse the console selection flags right now. */
	process_kernel_args((char *)0xa0200000 - MAX_BOOT_STRING - 1);

	/*
	 * This test will work for now but has to be revised when support
	 * for other models is added.
	 */
	if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X)
		zaurusmod = ZAURUS_C3000;
	else
		zaurusmod = ZAURUS_C860;

	/* setup GPIO for BTUART, in case bootloader doesn't take care of it */
	pxa2x0_gpio_bootstrap(ZAURUS_GPIO_VBASE);
#if 0
	pxa2x0_gpio_set_function(42, GPIO_ALT_FN_1_IN);
	pxa2x0_gpio_set_function(43, GPIO_ALT_FN_2_OUT);
	pxa2x0_gpio_set_function(44, GPIO_ALT_FN_1_IN);
	pxa2x0_gpio_set_function(45, GPIO_ALT_FN_2_OUT);

	/* FFUART */
	pxa2x0_gpio_set_function(34, GPIO_ALT_FN_1_IN);
	pxa2x0_gpio_set_function(39, GPIO_ALT_FN_2_OUT);
	pxa2x0_gpio_set_function(35, GPIO_ALT_FN_1_IN);
	pxa2x0_gpio_set_function(40, GPIO_ALT_FN_2_OUT);
	pxa2x0_gpio_set_function(41, GPIO_ALT_FN_2_OUT);

	/* STUART */
	pxa2x0_gpio_set_function(46, GPIO_ALT_FN_2_IN);
	pxa2x0_gpio_set_function(47, GPIO_ALT_FN_1_OUT);
#endif

	/* tell com to drive STUART in slow infrared mode */
	comsiraddr = (bus_addr_t)PXA2X0_STUART_BASE;

#if 1
	/* turn on clock to UART block.
	   XXX this should not be necessary, consinit() will do it */
	early_clkman(CKEN_FFUART | CKEN_BTUART | CKEN_STUART, 1);
#endif

	green_on(0);

	/*
	 * Temporarily replace bus_space_map() functions so that
	 * console devices can get mapped.
	 *
	 * Note that this relies upon the fact that both regular
	 * and a4x bus_space tags use the same map function.
	 */
	tmp_bs_tag = pxa2x0_bs_tag;
	tmp_bs_tag.bs_map = bootstrap_bs_map;
	map_func_save = pxa2x0_bs_tag.bs_map;
	pxa2x0_a4x_bs_tag.bs_map = pxa2x0_bs_tag.bs_map = bootstrap_bs_map;

	/* setup a serial console for very early boot */
	consinit();
#ifdef KGDB
	kgdb_port_init();
#endif

	/* Talk to the user */
	printf("\nOpenBSD/zaurus booting ...\n");

	{
		/* XXX - all Zaurus have this for now, fix memory sizing */
		memstart = 0xa0000000;
		memsize =  0x04000000; /* 64MB */
	}

#if 0
	{
		volatile int *p;
		char *membase;
		char *memmax;
		int  chunksize = 0x02000000;
		printf("probing memory");

		membase = (char *)0xa0000000;
		memmax  = (char *)0xc0000000;
		for (p = (int *)membase;
		    p < (int *)memmax;
		    p = (int *) (((char *)p) + chunksize)) {
			printf ("cbase %p\n", p);
			p[0] = 0x12345678;
			p[1] = 0x12345678;
			if ((p[0] != 0x12345678) || (p[1] != 0x12345678))
				break;
		}
			memsize = ((char *)p) - membase;

		printf("probing memory done found memsize %d\n", memsize);
	}
#else
#endif

#define DEBUG
#ifdef DEBUG
	printf("initarm: Configuring system ...\n");
#endif

	/* Fake bootconfig structure for the benefit of pmap.c */
	/* XXX must make the memory description h/w independant */
	bootconfig.dramblocks = 1;
	bootconfig.dram[0].address = memstart;
	bootconfig.dram[0].pages = memsize / PAGE_SIZE;

	/*
	 * Set up the variables that define the availablilty of
	 * physical memory.  For now, we're going to set
	 * physical_freestart to 0xa0200000 (where the kernel
	 * was loaded), and allocate the memory we need downwards.
	 * If we get too close to the page tables that RedBoot
	 * set up, we will panic.  We will update physical_freestart
	 * and physical_freeend later to reflect what pmap_bootstrap()
	 * wants to see.
	 *
	 * XXX pmap_bootstrap() needs an enema.
	 */
	physical_start = bootconfig.dram[0].address;
	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);

	physical_freestart = 0xa0009000UL;
	physical_freeend = 0xa0200000UL;

	physmem = (physical_end - physical_start) / PAGE_SIZE;

#ifdef DEBUG
	/* Tell the user about the memory */
	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
	    physical_start, physical_end - 1);
#endif

	/*
	 * Okay, the kernel starts 2MB in from the bottom of physical
	 * memory.  We are going to allocate our bootstrap pages downwards
	 * from there.
	 *
	 * We need to allocate some fixed page tables to get the kernel
	 * going.  We allocate one page directory and a number of page
	 * tables and store the physical addresses in the kernel_pt_table
	 * array.
	 *
	 * The kernel page directory must be on a 16K boundary.  The page
	 * tables must be on 4K bounaries.  What we do is allocate the
	 * page directory on the first 16K boundary that we encounter, and
	 * the page tables on 4K boundaries otherwise.  Since we allocate
	 * at least 3 L2 page tables, we are guaranteed to encounter at
	 * least one 16K aligned region.
	 */

#ifdef VERBOSE_INIT_ARM
	printf("Allocating page tables\n");
#endif

	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;

#ifdef VERBOSE_INIT_ARM
	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
	       physical_freestart, free_pages, free_pages);
#endif

	/* Define a macro to simplify memory allocation */
#define	valloc_pages(var, np)				\
	alloc_pages((var).pv_pa, (np));			\
	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;

#define alloc_pages(var, np)				\
	physical_freeend -= ((np) * PAGE_SIZE);		\
	if (physical_freeend < physical_freestart)	\
		panic("initarm: out of memory");	\
	(var) = physical_freeend;			\
	free_pages -= (np);				\
	memset((char *)(var), 0, ((np) * PAGE_SIZE));

	loop1 = 0;
	kernel_l1pt.pv_pa = 0;
	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
		/* Are we 16KB aligned for an L1 ? */
		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
		    && kernel_l1pt.pv_pa == 0) {
			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
		} else {
			valloc_pages(kernel_pt_table[loop1],
			    L2_TABLE_SIZE / PAGE_SIZE);
			++loop1;
		}
	}

	/* This should never be able to happen but better confirm that. */
	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
		panic("initarm: Failed to align the kernel page directory");

	/*
	 * Allocate a page for the system page mapped to V0x00000000
	 * This page will just contain the system vectors and can be
	 * shared by all processes.
	 */
	alloc_pages(systempage.pv_pa, 1);

	/* Allocate stacks for all modes */
	valloc_pages(irqstack, IRQ_STACK_SIZE);
	valloc_pages(abtstack, ABT_STACK_SIZE);
	valloc_pages(undstack, UND_STACK_SIZE);
	valloc_pages(kernelstack, UPAGES);

	/* Allocate enough pages for cleaning the Mini-Data cache. */
	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
	valloc_pages(minidataclean, 1);

#ifdef VERBOSE_INIT_ARM
	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
	    irqstack.pv_va);
	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
	    abtstack.pv_va);
	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
	    undstack.pv_va);
	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
	    kernelstack.pv_va);
#endif

	/*
	 * XXX Defer this to later so that we can reclaim the memory
	 * XXX used by the RedBoot page tables.
	 */
	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);

	/*
	 * Ok we have allocated physical pages for the primary kernel
	 * page tables
	 */

#ifdef VERBOSE_INIT_ARM
	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
#endif

	/*
	 * Now we start construction of the L1 page table
	 * We start by mapping the L2 page tables into the L1.
	 * This means that we can replace L1 mappings later on if necessary
	 */
	l1pagetable = kernel_l1pt.pv_pa;

	/* Map the L2 pages tables in the L1 page table */
	pmap_link_l2pt(l1pagetable, 0x00000000,
	    &kernel_pt_table[KERNEL_PT_SYS]);

	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);

	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);

	/* update the top of the kernel VM */
	pmap_curmaxkvaddr =
	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);

#ifdef VERBOSE_INIT_ARM
	printf("Mapping kernel\n");
#endif

	/* Now we fill in the L2 pagetable for the kernel static code/data
	 * and the symbol table. */
	{
		extern char etext[];
		size_t textsize = (u_int32_t) etext - KERNEL_TEXT_BASE;
		size_t totalsize = esym - KERNEL_TEXT_BASE;
		u_int logical;

		textsize = (textsize + PGOFSET) & ~PGOFSET;
		totalsize = (totalsize + PGOFSET) & ~PGOFSET;

		logical = 0x00200000;	/* offset of kernel in RAM */

		/* Update dump information */
		cpu_kcore_hdr.kernelbase = KERNEL_BASE;
		cpu_kcore_hdr.kerneloffs = logical;
		cpu_kcore_hdr.staticsize = totalsize;

		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
		    physical_start + logical, textsize,
		    PROT_READ | PROT_WRITE, PTE_CACHE);
		pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
		    physical_start + logical, totalsize - textsize,
		    PROT_READ | PROT_WRITE, PTE_CACHE);
	}

#ifdef VERBOSE_INIT_ARM
	printf("Constructing L2 page tables\n");
#endif

	/* Map the stack pages */
	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
	    IRQ_STACK_SIZE * PAGE_SIZE, PROT_READ | PROT_WRITE, PTE_CACHE);
	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
	    ABT_STACK_SIZE * PAGE_SIZE, PROT_READ | PROT_WRITE, PTE_CACHE);
	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
	    UND_STACK_SIZE * PAGE_SIZE, PROT_READ | PROT_WRITE, PTE_CACHE);
	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
	    UPAGES * PAGE_SIZE, PROT_READ | PROT_WRITE, PTE_CACHE);

	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
	    L1_TABLE_SIZE, PROT_READ | PROT_WRITE, PTE_PAGETABLE);

	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
		    PROT_READ | PROT_WRITE, PTE_PAGETABLE);
	}

	/* Map the Mini-Data cache clean area. */
	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
	    minidataclean.pv_pa);

	/* Map the vector page. */
#if 1
	/* MULTI-ICE requires that page 0 is NC/NB so that it can download the
	 * cache-clean code there.  */
	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
	    PROT_READ | PROT_WRITE, PTE_NOCACHE);
#else
	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
	    PROT_READ | PROT_WRITE, PTE_CACHE);
#endif

	/*
	 * map integrated peripherals at same address in l1pagetable
	 * so that we can continue to use console.
	 */
	copy_io_area_map((pd_entry_t *)l1pagetable);

	/*
	 * Give the XScale global cache clean code an appropriately
	 * sized chunk of unmapped VA space starting at 0xff000000
	 * (our device mappings end before this address).
	 */
	xscale_cache_clean_addr = 0xff000000U;

	/*
	 * Now we have the real page tables in place so we can switch to them.
	 * Once this is done we will be running with the REAL kernel page
	 * tables.
	 */

	/*
	 * Update the physical_freestart/physical_freeend/free_pages
	 * variables.
	 */
	{
		physical_freestart = physical_start +
		    (((esym + PGOFSET) & ~PGOFSET) - KERNEL_BASE);
		physical_freeend = physical_end;
		free_pages =
		    (physical_freeend - physical_freestart) / PAGE_SIZE;
	}

	/* be a client to all domains */
	cpu_domains(0x55555555);
	/* Switch tables */
#ifdef VERBOSE_INIT_ARM
	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
	       physical_freestart, free_pages, free_pages);
	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
#endif

	/* set new intc register address so that splfoo() doesn't
	   touch illegal address.  */
	pxa2x0_intr_bootstrap(ZAURUS_INTCTL_VBASE);

	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
	setttb(kernel_l1pt.pv_pa);
	cpu_tlb_flushID();
	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));

	/*
	 * Moved from cpu_startup() as data_abort_handler() references
	 * this during uvm init
	 */
	proc0paddr = (struct user *)kernelstack.pv_va;
	proc0.p_addr = proc0paddr;

#ifdef VERBOSE_INIT_ARM
	printf("bootstrap done.\n");
#endif

	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);

	/*
	 * Pages were allocated during the secondary bootstrap for the
	 * stacks for different CPU modes.
	 * We must now set the r13 registers in the different CPU modes to
	 * point to these stacks.
	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
	 * of the stack memory.
	 */
#ifdef VERBOSE_INIT_ARM
	printf("init subsystems: stacks ");
#endif

	set_stackptr(PSR_IRQ32_MODE,
	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
	set_stackptr(PSR_ABT32_MODE,
	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
	set_stackptr(PSR_UND32_MODE,
	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);

	/*
	 * Well we should set a data abort handler.
	 * Once things get going this will change as we will need a proper
	 * handler.
	 * Until then we will use a handler that just panics but tells us
	 * why.
	 * Initialisation of the vectors will just panic on a data abort.
	 * This just fills in a slightly better one.
	 */
#ifdef VERBOSE_INIT_ARM
	printf("vectors ");
#endif
	data_abort_handler_address = (u_int)data_abort_handler;
	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
	undefined_handler_address = (u_int)undefinedinstruction_bounce;

	/* Initialise the undefined instruction handlers */
#ifdef VERBOSE_INIT_ARM
	printf("undefined ");
#endif
	undefined_init();

	/* Load memory into UVM. */
#ifdef VERBOSE_INIT_ARM
	printf("page ");
#endif
	uvm_setpagesize();        /* initialize PAGE_SIZE-dependent variables */
	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
	    atop(physical_freestart), atop(physical_freeend), 0);

	/* Boot strap pmap telling it where the kernel page table is */
#ifdef VERBOSE_INIT_ARM
	printf("pmap ");
#endif
	pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
	    KERNEL_VM_BASE + KERNEL_VM_SIZE);

	/* Update dump information */
	cpu_kcore_hdr.pmap_kernel_l1 = (u_int32_t)pmap_kernel()->pm_l1;
	cpu_kcore_hdr.pmap_kernel_l2 = (u_int32_t)&(pmap_kernel()->pm_l2);

#ifdef KGDB
	if (boothowto & RB_KDB) {
		kgdb_debug_init = 1;
		kgdb_connect(1);
	}
#endif

	/*
	 * Restore proper bus_space operation, now that pmap is initialized.
	 */
	pxa2x0_a4x_bs_tag.bs_map = pxa2x0_bs_tag.bs_map = map_func_save;

#ifdef DDB
	db_machine_init();

	/* Firmware doesn't load symbols. */
	ddb_init();

	if (boothowto & RB_KDB)
		Debugger();
#endif

	/* We return the new stack pointer address */
	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
}

const char *console = "glass";

void
process_kernel_args(char *args)
{
	char *cp = args;

	if (cp == NULL || *(int *)cp != BOOT_STRING_MAGIC) {
		boothowto = RB_AUTOBOOT;
		return;
	}

	/* Eat the cookie */
	*(int *)cp = 0;
	cp += sizeof(int);

	boothowto = 0;

	/* Make a local copy of the bootargs */
	strncpy(bootargs, cp, MAX_BOOT_STRING - sizeof(int));

	cp = bootargs;
	boot_file = bootargs;

	/* Skip the kernel image filename */
	while (*cp != ' ' && *cp != 0)
		++cp;

	if (*cp != 0)
		*cp++ = 0;

	while (*cp == ' ')
		++cp;

	boot_args = cp;

	printf("bootfile: %s\n", boot_file);
	printf("bootargs: %s\n", boot_args);

	/* Setup pointer to boot flags */
	while (*cp != '-')
		if (*cp++ == '\0')
			return;

	for (;*++cp;) {
		int fl;

		fl = 0;
		switch(*cp) {
		case 'a':
			fl |= RB_ASKNAME;
			break;
		case 'c':
			fl |= RB_CONFIG;
			break;
		case 'd':
			fl |= RB_KDB;
			break;
		case 's':
			fl |= RB_SINGLE;
			break;
		/* XXX undocumented console switching flags */
		case '0':
			console = "ffuart";
			break;
		case '1':
			console = "btuart";
			break;
		case '2':
			console = "stuart";
			break;
		default:
			printf("unknown option `%c'\n", *cp);
			break;
		}
		boothowto |= fl;
	}
}

#ifdef KGDB
#ifndef KGDB_DEVNAME
#define KGDB_DEVNAME "ffuart"
#endif
const char kgdb_devname[] = KGDB_DEVNAME;

#if (NCOM > 0)
#ifndef KGDB_DEVMODE
#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
#endif
int comkgdbmode = KGDB_DEVMODE;
#endif /* NCOM */

#endif /* KGDB */

void
consinit(void)
{
#if NCOM > 0
	static int consinit_called = 0;
	paddr_t paddr;
	u_int cken = 0;

	if (consinit_called != 0)
		return;

	consinit_called = 1;

#ifdef KGDB
	if (strcmp(kgdb_devname, console) == 0) {
		/* port is reserved for kgdb */
	} else
#endif
	if (strcmp(console, "ffuart") == 0) {
		paddr = PXA2X0_FFUART_BASE;
		cken = CKEN_FFUART;
	} else if (strcmp(console, "btuart") == 0) {
		paddr = PXA2X0_BTUART_BASE;
		cken = CKEN_BTUART;
	} else if (strcmp(console, "stuart") == 0) {
		paddr = PXA2X0_STUART_BASE;
		cken = CKEN_STUART;
		irda_on(0);
	}
	if (cken != 0 && comcnattach(&pxa2x0_a4x_bs_tag, paddr, comcnspeed,
	    PXA2X0_COM_FREQ, comcnmode) == 0) {
		early_clkman(cken, 1);
	}
#endif /* NCOM */
}

#ifdef KGDB
void
kgdb_port_init(void)
{
#if (NCOM > 0) && defined(COM_PXA2X0)
	paddr_t paddr;
	u_int cken;

	if (strcmp(kgdb_devname, "ffuart") == 0) {
		paddr = PXA2X0_FFUART_BASE;
		cken = CKEN_FFUART;
	} else if (strcmp(kgdb_devname, "btuart") == 0) {
		paddr = PXA2X0_BTUART_BASE;
		cken = CKEN_BTUART;
	} else if (strcmp(kgdb_devname, "stuart") == 0) {
		paddr = PXA2X0_STUART_BASE;
		cken = CKEN_STUART;
		irda_on(0);
	} else
		return;

	if (com_kgdb_attach_pxa2x0(&pxa2x0_a4x_bs_tag, paddr,
	    kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode) == 0) {
		early_clkman(cken, 1);
	}
#endif
}
#endif

/* same as pxa2x0_clkman, but before autoconf */
void
early_clkman(u_int clk, int enable)
{
	u_int32_t rv;

	rv = ioreg_read(ZAURUS_CLKMAN_VBASE + CLKMAN_CKEN);
	if (enable)
		rv |= clk;
	else
		rv &= ~clk;
	ioreg_write(ZAURUS_CLKMAN_VBASE + CLKMAN_CKEN, rv);
}

int glass_console = 0;

void
board_startup(void)
{
	extern int lcd_cnattach(void (*)(u_int, int));
	extern bus_addr_t comconsaddr;

#if NWSDISPLAY > 0
	/*
	 * Try to attach the display console now that VM services
	 * are available.
	 */

	if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X) {
		if (strcmp(console, "glass") == 0) {
			printf("attempting to switch console to lcd screen\n");
			glass_console = 1;
		}
		if (glass_console == 1 && lcd_cnattach(early_clkman) == 0) {
			/*
			 * Kill the existing serial console.
			 * XXX need to bus_space_unmap resources and disable
			 *     clocks...
			 */
			comconsaddr = 0;

			/*
			 * Display the copyright notice again on the new console
			 */
			extern const char copyright[];
			printf("%s\n", copyright);
		}
	}
#endif

        if (boothowto & RB_CONFIG) {
#ifdef BOOT_CONFIG
		user_config();
#else
		printf("kernel does not support -c; continuing..\n");
#endif
	}
}


code:
/*	$OpenBSD: zaurus_start.S,v 1.3 2014/02/12 05:31:58 miod Exp $	*/
/*	$NetBSD: lubbock_start.S,v 1.1 2003/06/18 10:51:15 bsh Exp $ */

/*
 * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
 * Written by Hiroyuki Bessho for Genetec Corporation.
 *
 * 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 Genetec Corporation may not be used to endorse or
 *    promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``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 GENETEC CORPORATION
 * 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.
 */

#include <machine/asm.h>
#include <arm/armreg.h>
#include <arm/pte.h>

#undef	DOMAIN_CLIENT	/* XXX */
#include "assym.h"

#ifndef SDRAM_START
#define SDRAM_START	0xa0000000
#endif

/*
 * CPWAIT -- Canonical method to wait for CP15 update.
 * NOTE: Clobbers the specified temp reg.
 * copied from arm/arm/cpufunc_asm_xscale.S
 * XXX: better be in a common header file.
 */
#define	CPWAIT_BRANCH							 \
	sub	pc, pc, #4

#define	CPWAIT(tmp)							 \
	mrc	p15, 0, tmp, c2, c0, 0	/* arbitrary read of CP15 */	;\
	mov	tmp, tmp		/* wait for it to complete */	;\
	CPWAIT_BRANCH			/* branch to next insn */

/*
 * Kernel start routine for DBPXA250 (Lubbock)
 * this code is excuted at the very first after the kernel is loaded
 * by RedBoot.
 */
	.text

	.global	_C_LABEL(zaurus_start)
_C_LABEL(zaurus_start):
	/* Are we running on ROM ? */
	cmp     pc, #0x06000000
	bhi     zaurus_start_ram

	/* move me to RAM
	 * XXX: we can use memcpy if it is PIC
	 */
	ldr r1, Lcopy_size
	adr r0, _C_LABEL(zaurus_start)
	add r1, r1, #3
	mov r1, r1, LSR #2
	mov r2, #SDRAM_START
	add r2, r2, #0x00200000
	mov r4, r2

5:	ldr r3,[r0],#4
	str r3,[r2],#4
	subs r1,r1,#1
	bhi 5b

	cmp	pc, r5
	/* Jump to RAM */
	ldr r0, Lstart_off

	blo 1f
	/* if we were running out of virtual mapped space, disable mmu */
	mov	r2, #0
	mov     r1, #(CPU_CONTROL_32BP_ENABLE | CPU_CONTROL_32BD_ENABLE)
	mcr     15, 0, r1, c1, c0, 0
	mcrne   15, 0, r2, c8, c7, 0    /* nail I+D TLB on ARMv4 and greater */

1:
	add pc, r4, r0

Lcopy_size:	.word _edata-_C_LABEL(zaurus_start)
Lstart_off:	.word zaurus_start_ram-_C_LABEL(zaurus_start)

zaurus_start_ram:
	/*
	 *  Kernel is loaded in SDRAM (0xa0200000..), and is expected to run
	 *  in VA 0xc0200000..
	 */

	mrc	p15, 0, r0, c2, c0, 0		/* get ttb prepared by redboot */
	adr	r4, mmu_init_table2

#define BUILD_STARTUP_PAGETABLE
#ifdef BUILD_STARTUP_PAGETABLE
	mrc	p15, 0, r2, c1, c0, 0
	mov	r2, #0
	tst	r2, #CPU_CONTROL_MMU_ENABLE		/* we already have a page table? */
	bne	3f

	/* build page table from scratch */
	ldr	r0, Lstartup_pagetable
	adr	r4, mmu_init_table
	b	3f

2:
	str	r3, [r0, r2]
	add	r2, r2, #4
	add	r3, r3, #(L1_S_SIZE)
	adds	r1, r1, #-1
	bhi	2b
3:
	ldmia	r4!, {r1,r2,r3}   /* # of sections, PA|attr, VA */
	cmp	r1, #0
	bne	2b
#endif

	mcr	p15, 0, r0, c2, c0, 0	/* Set TTB */
	mcr	p15, 0, r0, c8, c7, 0	/* Flush TLB */

	/* Set the Domain Access register.  Very important! */
        mov     r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
	mcr	p15, 0, r0, c3, c0, 0

	/* Enable MMU */
	mrc	p15, 0, r0, c1, c0, 0
	orr	r0, r0, #CPU_CONTROL_MMU_ENABLE
	mcr	p15, 0, r0, c1, c0, 0
	CPWAIT(r0)

	/* Jump to kernel code in TRUE VA */
	adr	r0, Lstart
	ldr	pc, [r0]

Lstart:
	.word	start

#define MMU_INIT(va,pa,n_sec,attr) \
	.word	n_sec					    ; \
	.word	4*((va)>>L1_S_SHIFT)			    ; \
	.word	(pa)|(attr)				    ;

#ifdef BUILD_STARTUP_PAGETABLE
#ifndef STARTUP_PAGETABLE_ADDR
#define STARTUP_PAGETABLE_ADDR 0xa0004000
#endif
Lstartup_pagetable:	.word	STARTUP_PAGETABLE_ADDR
mmu_init_table:
	/* fill all table VA==PA */
	MMU_INIT(0x00000000, 0x00000000, 1<<(32-L1_S_SHIFT), L1_TYPE_S|L1_S_AP(AP_KRW))
	/* map SDRAM VA==PA, WT cacheable */
	MMU_INIT(SDRAM_START, SDRAM_START, 64, L1_TYPE_S|L1_S_C|L1_S_AP(AP_KRW))
#endif
mmu_init_table2:
	/* map VA 0xc0000000..0xc3ffffff to PA 0xa0000000..0xa3ffffff */
	MMU_INIT(0xc0000000, SDRAM_START, 64, L1_TYPE_S|L1_S_C|L1_S_AP(AP_KRW))

	.word 0	/* end of table */

license: unknown


code:
D/common////
D/linux////

path: sys/compat/CVS/Entries


code: src/sys/compat

path: sys/compat/CVS/Repository


code: src/sys/compat/common

path: sys/compat/common/CVS/Repository


code:
/* 	$OpenBSD: compat_dir.c,v 1.11 2014/12/16 21:25:28 tedu Exp $	*/

/*
 * Copyright (c) 2000 Constantine Sapuntzakis
 * 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. 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.
 *
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/namei.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/filedesc.h>
#include <sys/ioctl.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/vnode.h>
#include <sys/lock.h>
#include <sys/dirent.h>

#include <compat/common/compat_dir.h>

int
readdir_with_callback(struct file *fp, off_t *off, u_long nbytes,
    int (*appendfunc)(void *, struct dirent *), void *arg)
{
	struct dirent *bdp;
	caddr_t inp, buf;
	int buflen;
	struct uio auio;
	struct iovec aiov;
	int eofflag = 0;
	int error, len, reclen;
	off_t newoff = *off;
	struct vnode *vp;
	struct vattr va;

	if ((fp->f_flag & FREAD) == 0)
		return (EBADF);

	vp = (struct vnode *)fp->f_data;

	if (vp->v_type != VDIR)
		return (EINVAL);

	if ((error = VOP_GETATTR(vp, &va, fp->f_cred, curproc)) != 0)
		return (error);

	buflen = min(MAXBSIZE, nbytes);
	buflen = max(buflen, va.va_blocksize);
	buf = malloc(buflen, M_TEMP, M_WAITOK);
	error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
	if (error) {
		free(buf, M_TEMP, 0);
		return (error);
	}

again:
	aiov.iov_base = buf;
	aiov.iov_len = buflen;
	auio.uio_iov = &aiov;
	auio.uio_iovcnt = 1;
	auio.uio_rw = UIO_READ;
	auio.uio_segflg = UIO_SYSSPACE;
	auio.uio_procp = curproc;
	auio.uio_resid = buflen;
	auio.uio_offset = newoff;

	error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag);
	*off = auio.uio_offset;
	if (error)
		goto out;

	if ((len = buflen - auio.uio_resid) <= 0)
		goto eof;

	inp = buf;

	for (; len > 0; len -= reclen, inp += reclen) {
		bdp = (struct dirent *)inp;
		reclen = bdp->d_reclen;

		if (len < reclen)
			break;

		if (reclen & 3) {
			error = EFAULT;
			goto out;
		}

		/* Skip holes */
		if (bdp->d_fileno != 0) {
			if ((error = (*appendfunc) (arg, bdp)) != 0) {
				if (error == ENOMEM)
					error = 0;
				break;
			}
		}
	}

	if (len <= 0 && !eofflag)
		goto again;

eof:
out:
	VOP_UNLOCK(vp, 0, curproc);
	free(buf, M_TEMP, 0);
	return (error);
}


code:
/* 	$OpenBSD: compat_dir.h,v 1.3 2013/08/13 05:52:21 guenther Exp $	*/

/*
 * Copyright (c) 2000 Constantine Sapuntzakis
 * 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. 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.
 *
 */

#ifdef _KERNEL

int readdir_with_callback(struct file *, off_t *, u_long,
    int (*append_func) (void *, struct dirent *), void *);

#endif


code:
/* 	$OpenBSD: compat_util.c,v 1.16 2015/03/14 03:38:46 jsg Exp $	*/
/* 	$NetBSD: compat_util.c,v 1.4 1996/03/14 19:31:45 christos Exp $	*/

/*
 * Copyright (c) 1994 Christos Zoulas
 * Copyright (c) 1995 Frank van der Linden
 * 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.
 *
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/namei.h>
#include <sys/proc.h>
#include <sys/stat.h>
#include <sys/filedesc.h>
#include <sys/ioctl.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/signalvar.h>
#include <sys/vnode.h>

#include <uvm/uvm_extern.h>

#include <compat/common/compat_util.h>

/*
 * Search an alternate path before passing pathname arguments on
 * to system calls. Useful for keeping a separate 'emulation tree'.
 *
 * If cflag is set, we check if an attempt can be made to create
 * the named file, i.e. we check if the directory it should
 * be in exists.
 */
int
emul_find(struct proc *p, caddr_t *sgp, const char *prefix,
    char *path, char **pbuf, int cflag)
{
	struct nameidata	 nd;
	struct nameidata	 ndroot;
	struct vattr		 vat;
	struct vattr		 vatroot;
	int			 error;
	char			*ptr, *buf, *cp;
	const char		*pr;
	size_t			 sz, len;

	buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
	*pbuf = path;

	for (ptr = buf, pr = prefix; (*ptr = *pr) != '\0'; ptr++, pr++)
		continue;

	sz = MAXPATHLEN - (ptr - buf);

	/*
	 * If sgp is not given then the path is already in kernel space
	 */
	if (sgp == NULL)
		error = copystr(path, ptr, sz, &len);
	else
		error = copyinstr(path, ptr, sz, &len);

	if (error)
		goto bad;

	if (*ptr != '/') {
		error = EINVAL;
		goto bad;
	}

	/*
	 * We know that there is a / somewhere in this pathname.
	 * Search backwards for it, to find the file's parent dir
	 * to see if it exists in the alternate tree. If it does,
	 * and we want to create a file (cflag is set). We don't
	 * need to worry about the root comparison in this case.
	 */

	if (cflag) {
		for (cp = &ptr[len] - 1; *cp != '/'; cp--)
			;
		*cp = '\0';

		NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, p);

		if ((error = namei(&nd)) != 0)
			goto bad;

		*cp = '/';
	} else {
		NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, p);

		if ((error = namei(&nd)) != 0)
			goto bad;

		/*
		 * We now compare the vnode of the emulation root to the one
		 * vnode asked. If they resolve to be the same, then we
		 * ignore the match so that the real root gets used.
		 * This avoids the problem of traversing "../.." to find the
		 * root directory and never finding it, because "/" resolves
		 * to the emulation root directory. This is expensive :-(
		 */
		/* XXX: prototype should have const here for NDINIT */
		NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, prefix, p);

		if ((error = namei(&ndroot)) != 0)
			goto bad2;

		if ((error = VOP_GETATTR(nd.ni_vp, &vat, p->p_ucred, p)) != 0)
			goto bad3;

		if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, p->p_ucred, p))
		    != 0)
			goto bad3;

		if (vat.va_fsid == vatroot.va_fsid &&
		    vat.va_fileid == vatroot.va_fileid) {
			error = ENOENT;
			goto bad3;
		}
	}
	if (sgp == NULL)
		*pbuf = buf;
	else {
		sz = &ptr[len] - buf;
		*pbuf = stackgap_alloc(sgp, sz + 1);
		if (*pbuf == NULL) {
			error = ENAMETOOLONG;
			goto bad;
		}
		if ((error = copyout(buf, *pbuf, sz)) != 0) {
			*pbuf = path;
			goto bad;
		}
		free(buf, M_TEMP, 0);
	}

	vrele(nd.ni_vp);
	if (!cflag)
		vrele(ndroot.ni_vp);
	return error;

bad3:
	vrele(ndroot.ni_vp);
bad2:
	vrele(nd.ni_vp);
bad:
	free(buf, M_TEMP, 0);
	return error;
}

caddr_t
stackgap_init(struct proc *p)
{
	struct process *pr = p->p_p;

	if (pr->ps_stackgap == 0) {
		if (uvm_map(&pr->ps_vmspace->vm_map, &pr->ps_stackgap,
		    round_page(STACKGAPLEN), NULL, 0, 0,
		    UVM_MAPFLAG(PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
		    MAP_INHERIT_COPY, MADV_RANDOM, UVM_FLAG_COPYONW)))
			sigexit(p, SIGILL);
	}

        return (caddr_t)pr->ps_stackgap;
}

void *
stackgap_alloc(caddr_t *sgp, size_t sz)
{
	void *n = (void *) *sgp;
	caddr_t nsgp;

	sz = ALIGN(sz);
	nsgp = *sgp + sz;
	if (nsgp > (caddr_t)trunc_page((vaddr_t)n) + STACKGAPLEN)
		return NULL;
	*sgp = nsgp;
	return n;
}


code:
/*	$OpenBSD: compat_util.h,v 1.9 2014/03/26 05:23:42 guenther Exp $	*/
/*	$NetBSD: compat_util.h,v 1.1 1995/06/24 20:16:05 christos Exp $	*/

/*
 * Copyright (c) 1994 Christos Zoulas
 * Copyright (c) 1995 Frank van der Linden
 * 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	_COMPAT_UTIL_H_
#define	_COMPAT_UTIL_H_

#include <sys/exec.h>

struct proc;

caddr_t stackgap_init(struct proc *);
void    *stackgap_alloc(caddr_t *, size_t);

int emul_find(struct proc *, caddr_t *, const char *, char *, char **, int);

#define CHECK_ALT_EXIST(p, sgp, root, path) \
    emul_find(p, sgp, root, path, &(path), 0)

#define CHECK_ALT_CREAT(p, sgp, root, path) \
    emul_find(p, sgp, root, path, &(path), 1)

#endif /* !_COMPAT_UTIL_H_ */


code: src/sys/compat/linux

path: sys/compat/linux/CVS/Repository


code:
#	$OpenBSD: Makefile,v 1.4 2014/09/01 05:20:54 guenther Exp $
#	$NetBSD: Makefile,v 1.1 1995/02/28 23:26:21 fvdl Exp $

DEP=	syscalls.conf syscalls.master ../../kern/makesyscalls.sh
OBJS=	linux_sysent.c linux_syscalls.c linux_syscall.h linux_syscallargs.h

all:
	@echo "Doing nothing.  Did you want make syscalls?"

syscalls:	linux_sysent.c

${OBJS}: ${DEP}
	sh ../../kern/makesyscalls.sh syscalls.conf syscalls.master

path: sys/compat/linux/Makefile


code:
#	$OpenBSD: files.linux,v 1.17 2011/09/18 02:23:18 pirofti Exp $
#	$NetBSD: files.linux,v 1.4 1996/03/08 04:55:59 mycroft Exp $
#
# Config.new file description for machine-independent Linux compat code.
# Included by ports that need it.

# ports should define any machine-specific files they need in their
# own file lists.

file	compat/linux/linux_blkio.c		compat_linux
file	compat/linux/linux_cdrom.c		compat_linux
file	compat/linux/linux_error.c		compat_linux
file	compat/linux/linux_exec.c		compat_linux
file	compat/linux/linux_fdio.c		compat_linux
file	compat/linux/linux_file.c		compat_linux
file	compat/linux/linux_file64.c		compat_linux
file	compat/linux/linux_hdio.c		compat_linux
file	compat/linux/linux_ioctl.c		compat_linux
file	compat/linux/linux_ipc.c		compat_linux
file	compat/linux/linux_misc.c		compat_linux
file	compat/linux/linux_mount.c		compat_linux
file	compat/linux/linux_resource.c		compat_linux
file	compat/linux/linux_sched.c		compat_linux
file	compat/linux/linux_signal.c		compat_linux
file	compat/linux/linux_socket.c		compat_linux
file	compat/linux/linux_syscalls.c		compat_linux & syscall_debug
file	compat/linux/linux_sysent.c		compat_linux
file	compat/linux/linux_termios.c		compat_linux
file	compat/linux/linux_time.c		compat_linux
file	compat/linux/linux_futex.c		compat_linux
file	compat/linux/linux_dummy.c		compat_linux


code:
/*	$OpenBSD: linux_blkio.c,v 1.9 2012/04/22 05:43:14 guenther Exp $	*/
/*	$NetBSD: linux_blkio.c,v 1.3 2001/01/18 17:48:04 tv Exp $	*/

/*
 * Copyright (c) 2001 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.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/disklabel.h>
#include <sys/dkio.h>

#include <sys/syscallargs.h>

#include <compat/linux/linux_types.h>
#include <compat/linux/linux_ioctl.h>
#include <compat/linux/linux_signal.h>
#include <compat/linux/linux_util.h>
#include <compat/linux/linux_blkio.h>

#include <compat/linux/linux_syscallargs.h>

int
linux_ioctl_blkio(struct proc *p, struct linux_sys_ioctl_args *uap,
		  register_t *retval)
{
	u_long com;
	long size;
	int error;
	struct filedesc *fdp;
	struct file *fp;
	int (*ioctlf)(struct file *, u_long, caddr_t, struct proc *);
	struct partinfo partp;
	struct disklabel label;

        fdp = p->p_fd;
	if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
		return (EBADF);
	FREF(fp);
	error = 0;
	ioctlf = fp->f_ops->fo_ioctl;
	com = SCARG(uap, com);

	switch (com) {
	case LINUX_BLKGETSIZE:
		/*
		 * Try to get the partition size of this device. If that
		 * fails, it may be a disk without label; try to get
		 * the default label and compute the size from it.
		 */
		error = ioctlf(fp, DIOCGPART, (caddr_t)&partp, p);
		if (error != 0) {
			error = ioctlf(fp, DIOCGDINFO, (caddr_t)&label, p);
			if (error != 0)
				break;
			size = label.d_nsectors * label.d_ntracks *
			    label.d_ncylinders;
		} else
			/* XXX ignores > 32bit blocks */
			size = DL_GETPSIZE(partp.part);
		error = copyout(&size, SCARG(uap, data), sizeof size);
		break;
	case LINUX_BLKSECTGET:
		error = ioctlf(fp, DIOCGDINFO, (caddr_t)&label, p);
		if (error != 0)
			break;
		error = copyout(&label.d_secsize, SCARG(uap, data),
		    sizeof label.d_secsize);
		break;
	case LINUX_BLKROSET:
	case LINUX_BLKROGET:
	case LINUX_BLKRRPART:
	case LINUX_BLKFLSBUF:
	case LINUX_BLKRASET:
	case LINUX_BLKRAGET:
	case LINUX_BLKFRASET:
	case LINUX_BLKFRAGET:
	case LINUX_BLKSECTSET:
	case LINUX_BLKSSZGET:
	case LINUX_BLKPG:
	default:
		error = ENOTTY;
	}

	FRELE(fp, p);
	return error;
}


code:
/*	$OpenBSD: linux_blkio.h,v 1.2 2011/04/05 22:54:30 pirofti Exp $	*/
/*	$NetBSD: linux_blkio.h,v 1.2 2001/01/18 17:48:04 tv Exp $	*/

/*
 * Copyright (c) 2001 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.
 */

/*
 * Definitions for ioctl calls that work on filesystems, as defined
 * in <linux/fs.h>
 */

#ifndef _LINUX_BLKIO_H_
#define _LINUX_BLKIO_H_

#define LINUX_BLKROSET		_LINUX_IO(0x12, 93)
#define LINUX_BLKROGET		_LINUX_IO(0x12, 94)
#define LINUX_BLKRRPART		_LINUX_IO(0x12, 95)
#define LINUX_BLKGETSIZE	_LINUX_IO(0x12, 96)
#define LINUX_BLKFLSBUF		_LINUX_IO(0x12, 97)
#define LINUX_BLKRASET		_LINUX_IO(0x12, 98)
#define LINUX_BLKRAGET		_LINUX_IO(0x12, 99)
#define LINUX_BLKFRASET		_LINUX_IO(0x12, 100)
#define LINUX_BLKFRAGET		_LINUX_IO(0x12, 101)
#define LINUX_BLKSECTSET	_LINUX_IO(0x12, 102)
#define LINUX_BLKSECTGET	_LINUX_IO(0x12, 103)
#define LINUX_BLKSSZGET		_LINUX_IO(0x12, 104)
#define LINUX_BLKPG		_LINUX_IO(0x12, 105)

#endif /* _LINUX_BLKIO_H_ */


code:
/*	$OpenBSD: linux_cdrom.c,v 1.12 2015/04/30 09:20:51 mpi Exp $	*/
/*
 * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Niels Provos.
 * 4. 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.
 */

#include <sys/param.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/cdio.h>

#include <sys/syscallargs.h>

#include <compat/linux/linux_types.h>
#include <compat/linux/linux_ioctl.h>
#include <compat/linux/linux_signal.h>
#include <compat/linux/linux_syscallargs.h>
#include <compat/linux/linux_util.h>
#include <compat/linux/linux_cdrom.h>

void bsd_addr_to_linux_addr(union msf_lba *bsd,
    union linux_cdrom_addr *linux, int format);

void
bsd_addr_to_linux_addr(bsd, linux, format)
        union msf_lba *bsd;
        union linux_cdrom_addr *linux;
        int format;
{
        if (format == CD_MSF_FORMAT) {
 	        linux->msf.minute = bsd->msf.minute;
		linux->msf.second = bsd->msf.second;
		linux->msf.frame = bsd->msf.frame;
	} else
	        linux->lba = bsd->lba;
}

int
linux_ioctl_cdrom(p, v, retval)
	struct proc *p;
	void *v;
	register_t *retval;
{
	struct linux_sys_ioctl_args /* {
		syscallarg(int) fd;
		syscallarg(u_long) com;
		syscallarg(caddr_t) data;
	} */ *uap = v;
	struct file *fp;
	struct filedesc *fdp;
	caddr_t sg;
	u_long com, arg;
	struct sys_ioctl_args ia;
	int error;

	union {
	        struct cd_toc_entry te;
	        struct cd_sub_channel_info scinfo;
	} data;
	union {
	        struct ioc_toc_header th;
	        struct ioc_read_toc_entry tes;
	        struct ioc_play_track ti;
		struct ioc_play_msf msf;
		struct ioc_play_blocks blk;
	        struct ioc_read_subchannel sc;
		struct ioc_vol vol;
	} tmpb;
	union {
	        struct linux_cdrom_tochdr th;
	        struct linux_cdrom_tocentry te;
	        struct linux_cdrom_ti ti;
		struct linux_cdrom_msf msf;
		struct linux_cdrom_blk blk;
	        struct linux_cdrom_subchnl sc;
		struct linux_cdrom_volctrl vol;
	} tmpl;

	fdp = p->p_fd;
	if ((fp = fd_getfile_mode(fdp, SCARG(uap, fd), FREAD|FWRITE)) == NULL)
		return (EBADF);
	FREF(fp);

	com = SCARG(uap, com);
	retval[0] = 0;

	switch (com) {
	case LINUX_CDROMREADTOCHDR:
	        error = (*fp->f_ops->fo_ioctl)(fp, CDIOREADTOCHEADER,
		    (caddr_t)&tmpb.th, p);
	        if (error)
			goto out;
		tmpl.th.cdth_trk0 = tmpb.th.starting_track;
		tmpl.th.cdth_trk1 = tmpb.th.ending_track;
		error = copyout(&tmpl, SCARG(uap, data), sizeof tmpl.th);
		goto out;
	case LINUX_CDROMREADTOCENTRY:
		error = copyin(SCARG(uap, data), &tmpl.te, sizeof tmpl.te);
		if (error)
		        goto out;

		sg = stackgap_init(p);

		memset(&tmpb.tes, 0, sizeof tmpb.tes);
		tmpb.tes.starting_track = tmpl.te.cdte_track;
		tmpb.tes.address_format = (tmpl.te.cdte_format == LINUX_CDROM_MSF)
		    ? CD_MSF_FORMAT : CD_LBA_FORMAT;
		tmpb.tes.data_len = sizeof(struct cd_toc_entry);
		tmpb.tes.data = stackgap_alloc(&sg, tmpb.tes.data_len);

	        error = (*fp->f_ops->fo_ioctl)(fp, CDIOREADTOCENTRYS,
		    (caddr_t)&tmpb.tes, p);
	        if (error)
			goto out;
		if ((error = copyin(tmpb.tes.data, &data.te, sizeof data.te)))
			goto out;

		tmpl.te.cdte_ctrl = data.te.control;
		tmpl.te.cdte_adr = data.te.addr_type;
		tmpl.te.cdte_track = data.te.track;
		tmpl.te.cdte_datamode = CD_TRACK_INFO;
		bsd_addr_to_linux_addr(&data.te.addr, &tmpl.te.cdte_addr,
		    tmpb.tes.address_format);
		error = copyout(&tmpl, SCARG(uap, data), sizeof tmpl.te);
		goto out;
	case LINUX_CDROMSUBCHNL:
		error = copyin(SCARG(uap, data), &tmpl.sc, sizeof tmpl.sc);
		if (error)
			goto out;

		sg = stackgap_init(p);

		memset(&tmpb.sc, 0, sizeof tmpb.sc);
		tmpb.sc.data_format = CD_CURRENT_POSITION;
		tmpb.sc.address_format = (tmpl.sc.cdsc_format == LINUX_CDROM_MSF)
		    ? CD_MSF_FORMAT : CD_LBA_FORMAT;
		tmpb.sc.data_len = sizeof(struct cd_sub_channel_info);
		tmpb.sc.data = stackgap_alloc(&sg, tmpb.sc.data_len);

	        error = (*fp->f_ops->fo_ioctl)(fp, CDIOCREADSUBCHANNEL,
		    (caddr_t)&tmpb.sc, p);
	        if (error)
			goto out;
		if ((error = copyin(tmpb.sc.data, &data.scinfo, sizeof data.scinfo)))
			goto out;

		tmpl.sc.cdsc_audiostatus = data.scinfo.header.audio_status;
		tmpl.sc.cdsc_adr = data.scinfo.what.position.addr_type;
		tmpl.sc.cdsc_ctrl = data.scinfo.what.position.control;
		tmpl.sc.cdsc_trk = data.scinfo.what.position.track_number;
		tmpl.sc.cdsc_ind = data.scinfo.what.position.index_number;
		bsd_addr_to_linux_addr(&data.scinfo.what.position.absaddr,
		    &tmpl.sc.cdsc_absaddr,
		    tmpb.sc.address_format);
		bsd_addr_to_linux_addr(&data.scinfo.what.position.reladdr,
		    &tmpl.sc.cdsc_reladdr,
		    tmpb.sc.address_format);

		error = copyout(&tmpl, SCARG(uap, data), sizeof tmpl.sc);
		goto out;
	case LINUX_CDROMPLAYTRKIND:
		error = copyin(SCARG(uap, data), &tmpl.ti, sizeof tmpl.ti);
		if (error)
			goto out;

		tmpb.ti.start_track = tmpl.ti.cdti_trk0;
		tmpb.ti.start_index = tmpl.ti.cdti_ind0;
		tmpb.ti.end_track = tmpl.ti.cdti_trk1;
		tmpb.ti.end_index = tmpl.ti.cdti_ind1;
	        error = (*fp->f_ops->fo_ioctl)(fp, CDIOCPLAYTRACKS,
		    (caddr_t)&tmpb.ti, p);
		goto out;
	case LINUX_CDROMPLAYMSF:
		error = copyin(SCARG(uap, data), &tmpl.msf, sizeof tmpl.msf);
		if (error)
			goto out;

		tmpb.msf.start_m = tmpl.msf.cdmsf_min0;
		tmpb.msf.start_s = tmpl.msf.cdmsf_sec0;
		tmpb.msf.start_f = tmpl.msf.cdmsf_frame0;
		tmpb.msf.end_m = tmpl.msf.cdmsf_min1;
		tmpb.msf.end_s = tmpl.msf.cdmsf_sec1;
		tmpb.msf.end_f = tmpl.msf.cdmsf_frame1;

		error = (*fp->f_ops->fo_ioctl)(fp, CDIOCPLAYMSF,
		    (caddr_t)&tmpb.msf, p);
		goto out;
	case LINUX_CDROMPLAYBLK:
		error = copyin(SCARG(uap, data), &tmpl.blk, sizeof tmpl.blk);
		if (error)
			goto out;

		tmpb.blk.blk = tmpl.blk.from;
		tmpb.blk.len = tmpl.blk.len;

		error = (*fp->f_ops->fo_ioctl)(fp, CDIOCPLAYBLOCKS,
		    (caddr_t)&tmpb.blk, p);
		goto out;
	case LINUX_CDROMVOLCTRL:
		error = copyin(SCARG(uap, data), &tmpl.vol, sizeof tmpl.vol);
		if (error)
			goto out;

		tmpb.vol.vol[0] = tmpl.vol.channel0;
		tmpb.vol.vol[1] = tmpl.vol.channel1;
		tmpb.vol.vol[2] = tmpl.vol.channel2;
		tmpb.vol.vol[3] = tmpl.vol.channel3;

		error = (*fp->f_ops->fo_ioctl)(fp, CDIOCSETVOL,
		    (caddr_t)&tmpb.vol, p);
		goto out;
	case LINUX_CDROMVOLREAD:
		error = (*fp->f_ops->fo_ioctl)(fp, CDIOCGETVOL,
		    (caddr_t)&tmpb.vol, p);
		if (error)
			goto out;

		tmpl.vol.channel0 = tmpb.vol.vol[0];
		tmpl.vol.channel1 = tmpb.vol.vol[1];
		tmpl.vol.channel2 = tmpb.vol.vol[2];
		tmpl.vol.channel3 = tmpb.vol.vol[3];

		error = copyout(&tmpl.vol, SCARG(uap, data), sizeof tmpl.vol);
		goto out;
	case LINUX_CDROMPAUSE:
		SCARG(&ia, com) = CDIOCPAUSE;
		break;
	case LINUX_CDROMRESUME:
		SCARG(&ia, com) = CDIOCRESUME;
		break;
	case LINUX_CDROMSTOP:
		SCARG(&ia, com) = CDIOCSTOP;
		break;
	case LINUX_CDROMSTART:
		SCARG(&ia, com) = CDIOCSTART;
		break;
	case LINUX_CDROMEJECT_SW:
		error = copyin(SCARG(uap, data), &arg, sizeof arg);
		if (error)
			goto out;
		SCARG(&ia, com) = arg ? CDIOCALLOW : CDIOCPREVENT;
		break;
	case LINUX_CDROMEJECT:
		SCARG(&ia, com) = CDIOCEJECT;
		break;
	case LINUX_CDROMRESET:
		SCARG(&ia, com) = CDIOCRESET;
		break;
	default:
	        printf("linux_ioctl_cdrom: invalid ioctl %08lx\n", com);
		error = EINVAL;
		goto out;
	}

	SCARG(&ia, fd) = SCARG(uap, fd);
	SCARG(&ia, data) = SCARG(uap, data);
	error = sys_ioctl(p, &ia, retval);

out:
	FRELE(fp, p);
	return (error);
}


code:
/*	$OpenBSD: linux_cdrom.h,v 1.2 1997/12/10 00:01:40 provos Exp $	*/
/*
 * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Niels Provos.
 * 4. 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.
 */

struct linux_cdrom_blk
{
	unsigned from;
	unsigned short len;
};

struct linux_cdrom_msf
{
	u_char	cdmsf_min0;	/* start */
	u_char	cdmsf_sec0;
	u_char	cdmsf_frame0;
	u_char	cdmsf_min1;	/* end */
	u_char	cdmsf_sec1;
	u_char	cdmsf_frame1;
};

struct linux_cdrom_ti
{
	u_char	cdti_trk0;	/* start */
	u_char	cdti_ind0;
	u_char	cdti_trk1;	/* end */
	u_char	cdti_ind1;
};

struct linux_cdrom_tochdr
{
	u_char	cdth_trk0;	/* start */
	u_char	cdth_trk1;	/* end */
};

struct linux_cdrom_msf0
{
	u_char	minute;
	u_char	second;
	u_char	frame;
};

union linux_cdrom_addr
{
	struct linux_cdrom_msf0	msf;
	int			lba;
};

struct linux_cdrom_tocentry
{
	u_char	cdte_track;
	u_char	cdte_adr	:4;
	u_char	cdte_ctrl	:4;
	u_char	cdte_format;
	union linux_cdrom_addr cdte_addr;
	u_char	cdte_datamode;
};

#define	LINUX_CDROM_LBA 0x01
#define	LINUX_CDROM_MSF 0x02

#define	LINUX_CDROM_DATA_TRACK	0x04

#define	LINUX_CDROM_LEADOUT	0xAA

struct linux_cdrom_subchnl
{
	u_char	cdsc_format;
	u_char	cdsc_audiostatus;
	u_char	cdsc_adr:	4;
	u_char	cdsc_ctrl:	4;
	u_char	cdsc_trk;
	u_char	cdsc_ind;
	union linux_cdrom_addr cdsc_absaddr;
	union linux_cdrom_addr cdsc_reladdr;
};

struct linux_cdrom_mcn {
  u_char medium_catalog_number[14];
};

struct linux_cdrom_volctrl
{
	u_char	channel0;
	u_char	channel1;
	u_char	channel2;
	u_char	channel3;
};

struct linux_cdrom_read
{
	int	cdread_lba;
	caddr_t	cdread_bufaddr;
	int	cdread_buflen;
};

#define LINUX_CDROMPAUSE		0x5301
#define LINUX_CDROMRESUME		0x5302
#define LINUX_CDROMPLAYMSF		0x5303
#define LINUX_CDROMPLAYTRKIND		0x5304

#define LINUX_CDROMREADTOCHDR		0x5305
#define LINUX_CDROMREADTOCENTRY	        0x5306

#define LINUX_CDROMSTOP		        0x5307
#define LINUX_CDROMSTART		0x5308

#define LINUX_CDROMEJECT		0x5309

#define LINUX_CDROMVOLCTRL		0x530a

#define LINUX_CDROMSUBCHNL		0x530b

#define LINUX_CDROMREADMODE2		0x530c
#define LINUX_CDROMREADMODE1		0x530d
#define LINUX_CDROMREADAUDIO		0x530e

#define LINUX_CDROMEJECT_SW		0x530f

#define LINUX_CDROMMULTISESSION	        0x5310

#define LINUX_CDROM_GET_UPC		0x5311

#define LINUX_CDROMRESET		0x5312
#define LINUX_CDROMVOLREAD		0x5313

#define LINUX_CDROMPLAYBLK		0x5317


code:
/*	$OpenBSD: linux_dirent.h,v 1.4 2011/04/05 22:54:30 pirofti Exp $	*/
/*	$NetBSD: linux_dirent.h,v 1.3 1995/10/07 06:26:59 mycroft Exp $	*/

/*
 * Copyright (c) 1995 Frank van der Linden
 * 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. 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 Frank van der Linden
 * 4. 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 _LINUX_DIRENT_H_
#define _LINUX_DIRENT_H_

#define LINUX_MAXNAMLEN	255

struct linux_dirent {
	linux_ino_t	d_ino;
	linux_off_t	d_off;
	u_short		d_reclen;
	char		d_name[LINUX_MAXNAMLEN + 1];
};

struct linux_dirent64 {
	linux_ino64_t	d_ino;
	linux_off64_t	d_off;
	u_short		d_reclen;
	u_char		d_type;
	char		d_name[LINUX_MAXNAMLEN + 1];
};

#define LINUX_NAMEOFF(dp)       ((char *)&(dp)->d_name - (char *)dp)
#define LINUX_RECLEN(de,namlen) ALIGN((LINUX_NAMEOFF(de) + (namlen) + 1))

#endif /* !_LINUX_DIRENT_H_ */


code:
/*	$OpenBSD: linux_dummy.c,v 1.20 2012/06/19 11:31:39 pirofti Exp $ */

/*-
 * Copyright (c) 1994-1995 S�ren Schmidt
 * 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
 *    in this position and unchanged.
 * 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.
 *
 * $FreeBSD: src/sys/i386/linux/linux_dummy.c,v 1.21 2000/01/29 12:45:35 peter Exp $
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>

#include <compat/linux/linux_types.h>
#include <compat/linux/linux_signal.h>
#include <compat/linux/linux_syscallargs.h>

#define DUMMY(s)							\
int									\
linux_sys_ ## s(p, v, retval)						\
	struct proc *p;							\
	void *v;							\
	register_t *retval;						\
{									\
	return (unsupported_msg(p, #s));				\
}

static int
unsupported_msg(struct proc *p, const char *fname)
{
	printf("linux: syscall %s is obsolete or not implemented (pid=%ld)\n",
	    fname, (long)p->p_p->ps_pid);
	return (ENOSYS);
}

DUMMY(ostat);			/* #18 */
#ifdef PTRACE
DUMMY(ptrace);			/* #26 */
#endif
DUMMY(ofstat);			/* #28 */
DUMMY(stty);			/* #31 */
DUMMY(gtty);			/* #32 */
DUMMY(ftime);			/* #35 */
DUMMY(prof);			/* #44 */
DUMMY(phys);			/* #52 */
DUMMY(lock);			/* #53 */
DUMMY(mpx);			/* #56 */
DUMMY(ulimit);			/* #58 */
DUMMY(ustat);			/* #62 */
#ifndef __i386__
DUMMY(ioperm);			/* #101 */
#endif
DUMMY(klog);			/* #103 */
#ifndef __i386__
DUMMY(iopl);			/* #110 */
#endif
DUMMY(vhangup);			/* #111 */
DUMMY(idle);			/* #112 */
DUMMY(vm86old);			/* #113 */
DUMMY(swapoff);			/* #115 */
#ifndef __i386__
DUMMY(modify_ldt);		/* #123 */
#endif
DUMMY(adjtimex);		/* #124 */
DUMMY(create_module);		/* #127 */
DUMMY(init_module);		/* #128 */
DUMMY(delete_module);		/* #129 */
DUMMY(get_kernel_syms);		/* #130 */
DUMMY(quotactl);		/* #131 */
DUMMY(bdflush);			/* #134 */
DUMMY(sysfs);			/* #135 */
DUMMY(afs_syscall);		/* #137 */
DUMMY(mlockall);		/* #152 */
DUMMY(munlockall);		/* #153 */
DUMMY(sched_rr_get_interval);	/* #161 */
DUMMY(vm86);			/* #166 */
DUMMY(query_module);		/* #167 */
DUMMY(nfsservctl);		/* #169 */
DUMMY(rt_sigtimedwait);		/* #177 */
DUMMY(rt_queueinfo);		/* #178 */
DUMMY(capget);			/* #184 */
DUMMY(capset);			/* #185 */
DUMMY(sendfile);		/* #187 */
DUMMY(getpmsg);			/* #188 */
DUMMY(putpmsg);			/* #189 */
DUMMY(lchown);			/* #198 */
DUMMY(fchown);			/* #207 */
DUMMY(setfsgid);		/* #216 */
DUMMY(pivot_root);		/* #217 */
DUMMY(mincore);			/* #218 */
DUMMY(fadvise64);		/* #250 */
DUMMY(epoll_create);		/* #254 */
DUMMY(epoll_ctl);		/* #255 */
DUMMY(epoll_wait);		/* #256 */
DUMMY(epoll_pwait);		/* #319 */
DUMMY(eventfd);			/* #323 */
DUMMY(eventfd2);		/* #328 */
DUMMY(epoll_create1);		/* #329 */

#define DUMMY_XATTR(s)							\
int									\
linux_sys_ ## s ## xattr(p, v, retval)						\
	struct proc *p;							\
	void *v;							\
	register_t *retval;						\
{									\
	return (ENOATTR);						\
}
DUMMY_XATTR(set);
DUMMY_XATTR(lset);
DUMMY_XATTR(fset);
DUMMY_XATTR(get);
DUMMY_XATTR(lget);
DUMMY_XATTR(fget);
DUMMY_XATTR(list);
DUMMY_XATTR(llist);
DUMMY_XATTR(flist);
DUMMY_XATTR(remove);
DUMMY_XATTR(lremove);
DUMMY_XATTR(fremove);


code:
/*	$OpenBSD: linux_emuldata.h,v 1.9 2012/05/24 01:19:16 guenther Exp $	*/
/*	$NetBSD: linux_emuldata.h,v 1.4 2002/02/15 16:48:02 christos Exp $	*/
/*-
 * Copyright (c) 1998,2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Eric Haszlakiewicz.
 *
 * 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 _LINUX_EMULDATA_H_
#define _LINUX_EMULDATA_H_

/*
 * This is auxiliary data the linux compat code
 * needs to do its work.  A pointer to it is
 * stored in the emuldata field of the proc
 * structure.
 */
struct linux_emuldata {
	caddr_t	p_break;	/* Cached per-process break value */

	void *child_set_tid;	/* Let the child set the thread ID at start */
	void *child_clear_tid;	/* Let the child clear the thread ID on exit */
	unsigned child_tls_base;/* Set the Thread Local Storage on clone */
	int set_tls_base;	/* boolean: should my_tls_base be used? */

	/* Same as above, passed by the parent when forking. */
	void *my_set_tid;
	void *my_clear_tid;
	unsigned my_tls_base;

	struct linux_robust_list_head *led_robust_head;

	int pdeath_signal;	/* parent death signal */
};
#endif /* !_LINUX_EMULDATA_H_ */


code:
/*	$OpenBSD: linux_errno.h,v 1.3 2011/04/05 22:54:30 pirofti Exp $	*/
/* 	$NetBSD: linux_errno.h,v 1.1 1995/02/28 23:25:34 fvdl Exp $	*/
/*
 * Copyright (c) 1995 Frank van der Linden
 * 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. 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 Frank van der Linden
 * 4. 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 _LINUX_ERRNO_H_
#define _LINUX_ERRNO_H_

#define LINUX_EPERM		 1
#define LINUX_ENOENT		 2
#define LINUX_ESRCH		 3
#define LINUX_EINTR		 4
#define LINUX_EIO		 5
#define LINUX_ENXIO		 6
#define LINUX_E2BIG		 7
#define LINUX_ENOEXEC		 8
#define LINUX_EBADF		 9
#define LINUX_ECHILD		10
#define LINUX_EAGAIN		11
#define LINUX_ENOMEM		12
#define LINUX_EACCES		13
#define LINUX_EFAULT		14
#define LINUX_ENOTBLK		15
#define LINUX_EBUSY		16
#define LINUX_EEXIST		17
#define LINUX_EXDEV		18
#define LINUX_ENODEV		19
#define LINUX_ENOTDIR		20
#define LINUX_EISDIR		21
#define LINUX_EINVAL		22
#define LINUX_ENFILE		23
#define LINUX_EMFILE		24
#define LINUX_ENOTTY		25
#define LINUX_ETXTBSY		26
#define LINUX_EFBIG		27
#define LINUX_ENOSPC		28
#define LINUX_ESPIPE		29
#define LINUX_EROFS		30
#define LINUX_EMLINK		31
#define LINUX_EPIPE		32
#define LINUX_EDOM		33
#define LINUX_ERANGE		34
#define LINUX_EDEADLK		35
#define LINUX_ENAMETOOLONG	36
#define LINUX_ENOLCK		37
#define LINUX_ENOSYS		38
#define LINUX_ENOTEMPTY		39
#define LINUX_ELOOP		40
#define LINUX_ENOMSG		42
#define LINUX_EIDRM		43
#define LINUX_ECHRNG		44
#define LINUX_EL2NSYNC		45
#define LINUX_EL3HLT		46
#define LINUX_EL3RST		47
#define LINUX_ELNRNG		48
#define LINUX_EUNATCH		49
#define LINUX_ENOCSI		50
#define LINUX_EL2HLT		51
#define LINUX_EBADE		52
#define LINUX_EBADR		53
#define LINUX_EXFULL		54
#define LINUX_ENOANO		55
#define LINUX_EBADRQC		56
#define LINUX_EBADSLT		57
#define LINUX_EDEADLOCK		58
#define LINUX_EBFONT		59
#define LINUX_ENOSTR		60
#define LINUX_ENODATA		61
#define LINUX_ETIME		62
#define LINUX_ENOSR		63
#define LINUX_ENONET		64
#define LINUX_ENOPKG		65
#define LINUX_EREMOTE		66
#define LINUX_ENOLINK		67
#define LINUX_EADV		68
#define LINUX_ESRMNT		69
#define LINUX_ECOMM		70
#define LINUX_EPROTO		71
#define LINUX_EMULTIHOP		72
#define LINUX_EDOTDOT		73
#define LINUX_EBADMSG		74
#define LINUX_EOVERFLOW		75
#define LINUX_ENOTUNIQ		76
#define LINUX_EBADFD		77
#define LINUX_EREMCHG		78
#define LINUX_ELIBACC		79
#define LINUX_ELIBBAD		80
#define LINUX_ELIBSCN		81
#define LINUX_ELIBMAX		82
#define LINUX_ELIBEXEC		83
#define LINUX_EILSEQ		84
#define LINUX_ERESTART		85
#define LINUX_ESTRPIPE		86
#define LINUX_EUSERS		87
#define LINUX_ENOTSOCK		88
#define LINUX_EDESTADDRREQ	89
#define LINUX_EMSGSIZE		90
#define LINUX_EPROTOTYPE	91
#define LINUX_ENOPROTOOPT	92
#define LINUX_EPROTONOSUPPORT	93
#define LINUX_ESOCKTNOSUPPORT	94
#define LINUX_EOPNOTSUPP	95
#define LINUX_EPFNOSUPPORT	96
#define LINUX_EAFNOSUPPORT	97
#define LINUX_EADDRINUSE	98
#define LINUX_EADDRNOTAVAIL	99
#define LINUX_ENETDOWN		100
#define LINUX_ENETUNREACH	101
#define LINUX_ENETRESET		102
#define LINUX_ECONNABORTED	103
#define LINUX_ECONNRESET	104
#define LINUX_ENOBUFS		105
#define LINUX_EISCONN		106
#define LINUX_ENOTCONN		107
#define LINUX_ESHUTDOWN		108
#define LINUX_ETOOMANYREFS	109
#define LINUX_ETIMEDOUT		110
#define LINUX_ECONNREFUSED	111
#define LINUX_EHOSTDOWN		112
#define LINUX_EHOSTUNREACH	113
#define LINUX_EALREADY		114
#define LINUX_EINPROGRESS	115
#define LINUX_ESTALE		116
#define LINUX_EUCLEAN		117
#define LINUX_ENOTNAM		118
#define LINUX_ENAVAIL		119
#define LINUX_EISNAM		120
#define LINUX_EREMOTEIO		121
#define LINUX_EDQUOT		122

#endif /* !_LINUX_ERRNO_H_ */


code:
/*	$OpenBSD: linux_error.c,v 1.5 2009/10/28 16:38:43 jsg Exp $	*/
/*	$NetBSD: linux_error.c,v 1.2 1995/04/22 19:48:32 christos Exp $	*/

/*
 * Copyright (c) 1995 Frank van der Linden
 * 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. 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 Frank van der Linden
 * 4. 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.
 */

#include <sys/errno.h>
#include <compat/linux/linux_errno.h>

int linux_error[1 + ELAST] = {
	0,
	-LINUX_EPERM,
	-LINUX_ENOENT,
	-LINUX_ESRCH,
	-LINUX_EINTR,
	-LINUX_EIO,
	-LINUX_ENXIO,
	-LINUX_E2BIG,
	-LINUX_ENOEXEC,
	-LINUX_EBADF,
	-LINUX_ECHILD,
	-LINUX_EDEADLK,
	-LINUX_ENOMEM,
	-LINUX_EACCES,
	-LINUX_EFAULT,
	-LINUX_ENOTBLK,
	-LINUX_EBUSY,
	-LINUX_EEXIST,
	-LINUX_EXDEV,
	-LINUX_ENODEV,
	-LINUX_ENOTDIR,
	-LINUX_EISDIR,
	-LINUX_EINVAL,
	-LINUX_ENFILE,
	-LINUX_EMFILE,
	-LINUX_ENOTTY,
	-LINUX_ETXTBSY,
	-LINUX_EFBIG,
	-LINUX_ENOSPC,
	-LINUX_ESPIPE,
	-LINUX_EROFS,
	-LINUX_EMLINK,
	-LINUX_EPIPE,
	-LINUX_EDOM,
	-LINUX_ERANGE,
	-LINUX_EAGAIN,
	-LINUX_EINPROGRESS,
	-LINUX_EALREADY,
	-LINUX_ENOTSOCK,
	-LINUX_EDESTADDRREQ,
	-LINUX_EMSGSIZE,
	-LINUX_EPROTOTYPE,
	-LINUX_ENOPROTOOPT,
	-LINUX_EPROTONOSUPPORT,
	-LINUX_ESOCKTNOSUPPORT,
	-LINUX_EOPNOTSUPP,
	-LINUX_EPFNOSUPPORT,
	-LINUX_EAFNOSUPPORT,
	-LINUX_EADDRINUSE,
	-LINUX_EADDRNOTAVAIL,
	-LINUX_ENETDOWN,
	-LINUX_ENETUNREACH,
	-LINUX_ENETRESET,
	-LINUX_ECONNABORTED,
	-LINUX_ECONNRESET,
	-LINUX_ENOBUFS,
	-LINUX_EISCONN,
	-LINUX_ENOTCONN,
	-LINUX_ESHUTDOWN,
	-LINUX_ETOOMANYREFS,
	-LINUX_ETIMEDOUT,
	-LINUX_ECONNREFUSED,
	-LINUX_ELOOP,
	-LINUX_ENAMETOOLONG,
	-LINUX_EHOSTDOWN,
	-LINUX_EHOSTUNREACH,
	-LINUX_ENOTEMPTY,
	-LINUX_ENOSYS,		/* not mapped (EPROCLIM) */
	-LINUX_EUSERS,
	-LINUX_EDQUOT,
	-LINUX_ESTALE,
	-LINUX_EREMOTE,
	-LINUX_ENOSYS,		/* not mapped (EBADRPC) */
	-LINUX_ENOSYS,		/* not mapped (ERPCMISMATCH) */
	-LINUX_ENOSYS,		/* not mapped (EPROGUNAVAIL) */
	-LINUX_ENOSYS,		/* not mapped (EPROGMISMATCH) */
	-LINUX_ENOSYS,		/* not mapped (EPROCUNAVAIL) */
	-LINUX_ENOLCK,
	-LINUX_ENOSYS,
	-LINUX_ENOSYS,		/* not mapped (EFTYPE) */
	-LINUX_ENOSYS,		/* not mapped (EAUTH) */
	-LINUX_ENOSYS,		/* not mapped (ENEEDAUTH) */
	-LINUX_ENOSYS,		/* not mapped (EIPSEC) */
	-LINUX_EOPNOTSUPP,	/* what is ENOATTR? */
	-LINUX_EILSEQ,
	-LINUX_ENOSYS,		/* not mapped (ENOMEDIUM) */
	-LINUX_ENOSYS,		/* not mapped (EMEDIUMTYPE) */
	-LINUX_EOVERFLOW,
	-LINUX_ENOSYS,		/* not mapped (ECANCELED) */
	-LINUX_EIDRM,
	-LINUX_ENOMSG,
	-LINUX_ENOSYS		/* not mapped (ENOTSUP) */
};