xserver/hw/xorg/os-support Makefile.am, NONE, 1.1 assyntax.h, NONE, 1.1 int10Defines.h, NONE, 1.1 xf86OSKbd.h, NONE, 1.1 xf86OSmouse.h, NONE, 1.1 xf86OSpriv.h, NONE, 1.1 xf86_OSlib.h, NONE, 1.1 xf86_OSproc.h, NONE, 1.1 xf86_ansic.h, NONE, 1.1 xf86_libc.h, NONE, 1.1 xf86drm.h, NONE, 1.1 xf86drmCompat.h, NONE, 1.1

Daniel Stone xserver-commit at pdx.freedesktop.org
Sun Apr 25 23:52:19 EST 2004


Committed by: daniel

Update of /cvs/xserver/xserver/hw/xorg/os-support
In directory pdx:/tmp/cvs-serv17025/hw/xorg/os-support

Added Files:
	Makefile.am assyntax.h int10Defines.h xf86OSKbd.h 
	xf86OSmouse.h xf86OSpriv.h xf86_OSlib.h xf86_OSproc.h 
	xf86_ansic.h xf86_libc.h xf86drm.h xf86drmCompat.h 
Log Message:
Xizzle is dead, long live Xorg.

Re-import the DDX from X11R6.7, complete with automakey goodness, and do the
requisite configure.ac, et al, updates; also import the XKB extension from the
6.7 DIX.

Currently it'll link and then hang solid in RADEONInitAccel(), or the next
function if you enable NoAccel.


--- NEW FILE: Makefile.am ---
SUBDIRS = bus $(XORG_OS_SUBDIR)

OS_TARGET = $(XORG_OS_SUBDIR)/libxorg$(XORG_OS_SUBDIR).a

DISTCLEANFILES = libxorgos.a

all: libxorgos.a

libxorgos.a: $(OS_TARGET)
	ln -s $(OS_TARGET) $@

sdk_INCLUDEDIR = $(includedir)/xorg
sdk_INCLUDES = xf86_OSproc.h xf86_OSlib.h xf86_ansic.h xf86_libc.h xf86drm.h \
               xf86drmCompat.h assyntax.h

--- NEW FILE: assyntax.h ---
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/assyntax.h,v 3.13 2003/08/24 17:37:03 dawes Exp $ */
#ifndef __ASSYNTAX_H__
#define	__ASSYNTAX_H__

/*
 * Copyright 1992 Vrije Universiteit, The Netherlands
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the Vrije Universiteit not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  The Vrije Universiteit makes no
 * representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 *
 * The Vrije Universiteit DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL The Vrije Universiteit BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */
/*
 * Copyright (c) 1993-1999 by The XFree86 Project, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of the copyright holder(s)
 * and author(s) shall not be used in advertising or otherwise to promote
 * the sale, use or other dealings in this Software without prior written
 * authorization from the copyright holder(s) and author(s).
 */

/* $XConsortium: assyntax.h /main/5 1996/02/21 17:50:49 kaleb $ */

 /*
 * assyntax.h
 *
 * Select the syntax appropriate to the 386 assembler being used
 * To add support for more assemblers add more columns to the CHOICE
 * macro.  Note that register names must also have uppercase names
 * to avoid macro recursion. e.g., #define ah %ah recurses!
 *
 * NB 1.  Some of the macros for certain assemblers imply that the code is to
 *	  run in protected mode!!  Caveat emptor.
 *
 * NB 2.  486 specific instructions are not included.  This is to discourage
 *	  their accidental use in code that is intended to run on 386 and 486
 *	  systems.
 *
 * Supported assemblers:
 *
 * (a) AT&T SysVr4 as(1):	default
 * (b) GNU Assembler gas:	define USE_GAS or GNU_ASSEMBLER
 * (c) Amsterdam Compiler kit:	define ACK_ASSEMBLER
 *
 * The following naming conventions have been used to identify the various
 * data types:
 *		_SR = segment register version
 *	Integer:
 *		_Q = quadword	= 64 bits
 *		_L = long	= 32 bits
 *		_W = short	= 16 bits
 *		_B = byte	=  8 bits
 *	Floating-point:
 *		_X = m80real	= 80 bits
 *		_D = double	= 64 bits
 *		_S = single	= 32 bits
 *
 * Author: Gregory J. Sharp, Sept 1992
 *         Vrije Universiteit, Amsterdam, The Netherlands
 */

#if defined(USE_GAS) && !defined(GNU_ASSEMBLER)
#define GNU_ASSEMBLER
#endif

#if (defined(__STDC__) && !defined(UNIXCPP)) || (defined (sun) && defined (i386) && defined (SVR4) && defined (__STDC__) && !defined (__GNUC__)) 
#define	CONCAT(x, y)	x ## y
#else
#define	CONCAT(x, y)	x/**/y
#endif

#ifdef ACK_ASSEMBLER

/* Assume we write code for 32-bit protected mode! */

/* Redefine register names for GAS & AT&T assemblers */
#define	AL	al
#define	AH	ah
#define	AX	ax
#define	EAX	ax
#define	BL	bl
#define	BH	bh
#define	BX	bx
#define	EBX	bx
#define	CL	cl
#define	CH	ch
#define	CX	cx
#define	ECX	cx
#define	DL	dl
#define	DH	dh
#define	DX	dx
#define	EDX	dx
#define	BP	bp
#define	EBP	bp
#define	SI	si
#define	ESI	si
#define	DI	di
#define	EDI	di
#define	SP	sp
#define	ESP	sp
#define	CS	cs
#define	SS	ss
#define	DS	ds
#define	ES	es
#define	FS	fs
#define	GS	gs
/* Control Registers */
#define	CR0	cr0
#define	CR1	cr1
#define	CR2	cr2
#define	CR3	cr3
/* Debug Registers */
#define	DR0	dr0
#define	DR1	dr1
#define	DR2	dr2
#define	DR3	dr3
#define	DR4	dr4
#define	DR5	dr5
#define	DR6	dr6
#define	DR7	dr7
/* Floating-point Stack */
#define	ST	st

#define	AS_BEGIN	.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text


#define	_WTOG		o16	/* word toggle for _W instructions */
#define	_LTOG			/* long toggle for _L instructions */
#define	ADDR_TOGGLE	a16
#define	OPSZ_TOGGLE	o16
#define	USE16		.use16
#define	USE32		.use32

#define	CHOICE(a,b,c)	c

#else /* AT&T or GAS */

/* Redefine register names for GAS & AT&T assemblers */
#define	AL	%al
#define	AH	%ah
#define	AX	%ax
#define	EAX	%eax
#define	BL	%bl
#define	BH	%bh
#define	BX	%bx
#define	EBX	%ebx
#define	CL	%cl
#define	CH	%ch
#define	CX	%cx
#define	ECX	%ecx
#define	DL	%dl
#define	DH	%dh
#define	DX	%dx
#define	EDX	%edx
#define	BP	%bp
#define	EBP	%ebp
#define	SI	%si
#define	ESI	%esi
#define	DI	%di
#define	EDI	%edi
#define	SP	%sp
#define	ESP	%esp
#define	CS	%cs
#define	SS	%ss
#define	DS	%ds
#define	ES	%es
#define	FS	%fs
#define	GS	%gs
/* Control Registers */
#define	CR0	%cr0
#define	CR1	%cr1
#define	CR2	%cr2
#define	CR3	%cr3
/* Debug Registers */
#define	DR0	%db0
#define	DR1	%db1
#define	DR2	%db2
#define	DR3	%db3
#define	DR4	%db4
#define	DR5	%db5
#define	DR6	%db6
#define	DR7	%db7
/* Floating-point Stack */
#define	ST	%st

#define	AS_BEGIN
#define	USE16
#define	USE32

#ifdef GNU_ASSEMBLER

#define	ADDR_TOGGLE	aword
#define	OPSZ_TOGGLE	word

#define	CHOICE(a,b,c)	b

#else
/*
 * AT&T ASSEMBLER SYNTAX
 * *********************
 */
#define	CHOICE(a,b,c)	a

#define	ADDR_TOGGLE	addr16
#define	OPSZ_TOGGLE	data16

#endif /* GNU_ASSEMBLER */
#endif /* ACK_ASSEMBLER */


#if defined(__QNX__) || defined(Lynx) || (defined(SYSV) || defined(SVR4)) && !defined(ACK_ASSEMBLER) || defined(__ELF__) || defined(__GNU__)
#define GLNAME(a)       a
#else
#define GLNAME(a)       CONCAT(_,a)
#endif


	/****************************************/
	/*					*/
	/*	Select the various choices	*/
	/*					*/
	/****************************************/


/* Redefine assembler directives */
/*********************************/
#define GLOBL		CHOICE(.globl, .globl, .extern)
#define	ALIGNTEXT4	CHOICE(.align 4, .align ARG2(2,0x90), .align 4)
#define	ALIGNTEXT2	CHOICE(.align 2, .align ARG2(1,0x90), .align 2)
/* ALIGNTEXT4ifNOP is the same as ALIGNTEXT4, but only if the space is
 * guaranteed to be filled with NOPs.  Otherwise it does nothing.
 */
#define	ALIGNTEXT4ifNOP	CHOICE(.align 4, .align ARG2(2,0x90), /*can't do it*/)
#define	ALIGNDATA4	CHOICE(.align 4, .align ARG2(2,0x0), .align 4)
#define	ALIGNDATA2	CHOICE(.align 2, .align ARG2(1,0x0), .align 2)
#define	FILE(s)		CHOICE(.file s, .file s, .file s)
#define	STRING(s)	CHOICE(.string s, .asciz s, .asciz s)
#define	D_LONG		CHOICE(.long, .long, .data4)
#define	D_WORD		CHOICE(.value, .short, .data2)
#define	D_BYTE		CHOICE(.byte, .byte, .data1)
#define	SPACE		CHOICE(.comm, .space, .space)
#define	COMM		CHOICE(.comm, .comm, .comm)
#define	SEG_DATA	CHOICE(.data, .data, .sect .data)
#define	SEG_TEXT	CHOICE(.text, .text, .sect .text)
#define	SEG_BSS		CHOICE(.bss, .bss, .sect .bss)

#ifdef GNU_ASSEMBLER
#define	D_SPACE(n)	. = . + n
#else
#define	D_SPACE(n)	.space n
#endif

/* Addressing Modes */
/* Immediate Mode */
#define	ADDR(a)		CHOICE(CONCAT($,a), CONCAT($,a), a)
#define	CONST(a)	CHOICE(CONCAT($,a), CONCAT($,a), a)

/* Indirect Mode */
#define	CONTENT(a)	CHOICE(a, a, (a))	 /* take contents of variable */
#define	REGIND(a)	CHOICE((a), (a), (a))	 /* Register a indirect */
/* Register b indirect plus displacement a */
#define	REGOFF(a, b)	CHOICE(a(b), a(b), a(b))
/* Reg indirect Base + Index + Displacement  - this is mainly for 16-bit mode
 * which has no scaling
 */
#define	REGBID(b,i,d)	CHOICE(d(b,i), d(b,i), d(b)(i))
/* Reg indirect Base + (Index * Scale) + Displacement */
#define	REGBISD(b,i,s,d) CHOICE(d(b,i,s), d(b,i,s), d(b)(i*s))
/* Displaced Scaled Index: */
#define REGDIS(d,i,s)	CHOICE(d(,i,s), d(,i,s), d(i * s))
/* Indexed Base: */
#define REGBI(b,i)	CHOICE((b,i), (b,i), (b)(i))
/* Displaced Base: */
#define REGDB(d,b)	CHOICE(d(b), d(b), d(b))
/* Variable indirect: */
#define VARINDIRECT(var) CHOICE(*var, *var, (var))
/* Use register contents as jump/call target: */
#define CODEPTR(reg)	CHOICE(*reg, *reg, reg)

/* For expressions requiring bracketing
 * eg. (CRT0_PM | CRT_EM)
 */

#define	EXPR(a)		CHOICE([a], (a), [a])
#define	ENOT(a)		CHOICE(0!a, ~a, ~a)
#define	EMUL(a,b)	CHOICE(a\*b, a*b, a*b)
#define	EDIV(a,b)	CHOICE(a\/b, a/b, a/b)

/*
 * We have to beat the problem of commas within arguments to choice.
 * eg. choice (add a,b, add b,a) will get argument mismatch.  Luckily ANSI
 * and other known cpp definitions evaluate arguments before substitution
 * so the following works.
 */
#define	ARG2(a, b)	a,b
#define	ARG3(a,b,c)	a,b,c

/* Redefine assembler commands */
#define	AAA		CHOICE(aaa, aaa, aaa)
#define	AAD		CHOICE(aad, aad, aad)
#define	AAM		CHOICE(aam, aam, aam)
#define	AAS		CHOICE(aas, aas, aas)
#define	ADC_L(a, b)	CHOICE(adcl ARG2(a,b), adcl ARG2(a,b), _LTOG adc ARG2(b,a))
#define	ADC_W(a, b)	CHOICE(adcw ARG2(a,b), adcw ARG2(a,b), _WTOG adc ARG2(b,a))
#define	ADC_B(a, b)	CHOICE(adcb ARG2(a,b), adcb ARG2(a,b), adcb ARG2(b,a))
#define	ADD_L(a, b)	CHOICE(addl ARG2(a,b), addl ARG2(a,b), _LTOG add ARG2(b,a))
#define	ADD_W(a, b)	CHOICE(addw ARG2(a,b), addw ARG2(a,b), _WTOG add ARG2(b,a))
#define	ADD_B(a, b)	CHOICE(addb ARG2(a,b), addb ARG2(a,b), addb ARG2(b,a))
#define	AND_L(a, b)	CHOICE(andl ARG2(a,b), andl ARG2(a,b), _LTOG and ARG2(b,a))
#define	AND_W(a, b)	CHOICE(andw ARG2(a,b), andw ARG2(a,b), _WTOG and ARG2(b,a))
#define	AND_B(a, b)	CHOICE(andb ARG2(a,b), andb ARG2(a,b), andb ARG2(b,a))
#define	ARPL(a,b)	CHOICE(arpl ARG2(a,b), arpl ARG2(a,b), arpl ARG2(b,a))
#define	BOUND_L(a, b)	CHOICE(boundl ARG2(a,b), boundl ARG2(b,a), _LTOG bound ARG2(b,a))
#define	BOUND_W(a, b)	CHOICE(boundw ARG2(a,b), boundw ARG2(b,a), _WTOG bound ARG2(b,a))
#define	BSF_L(a, b)	CHOICE(bsfl ARG2(a,b), bsfl ARG2(a,b), _LTOG bsf ARG2(b,a))
#define	BSF_W(a, b)	CHOICE(bsfw ARG2(a,b), bsfw ARG2(a,b), _WTOG bsf ARG2(b,a))
#define	BSR_L(a, b)	CHOICE(bsrl ARG2(a,b), bsrl ARG2(a,b), _LTOG bsr ARG2(b,a))
#define	BSR_W(a, b)	CHOICE(bsrw ARG2(a,b), bsrw ARG2(a,b), _WTOG bsr ARG2(b,a))
#define	BT_L(a, b)	CHOICE(btl ARG2(a,b), btl ARG2(a,b), _LTOG bt ARG2(b,a))
#define	BT_W(a, b)	CHOICE(btw ARG2(a,b), btw ARG2(a,b), _WTOG bt ARG2(b,a))
#define	BTC_L(a, b)	CHOICE(btcl ARG2(a,b), btcl ARG2(a,b), _LTOG btc ARG2(b,a))
#define	BTC_W(a, b)	CHOICE(btcw ARG2(a,b), btcw ARG2(a,b), _WTOG btc ARG2(b,a))
#define	BTR_L(a, b)	CHOICE(btrl ARG2(a,b), btrl ARG2(a,b), _LTOG btr ARG2(b,a))
#define	BTR_W(a, b)	CHOICE(btrw ARG2(a,b), btrw ARG2(a,b), _WTOG btr ARG2(b,a))
#define	BTS_L(a, b)	CHOICE(btsl ARG2(a,b), btsl ARG2(a,b), _LTOG bts ARG2(b,a))
#define	BTS_W(a, b)	CHOICE(btsw ARG2(a,b), btsw ARG2(a,b), _WTOG bts ARG2(b,a))
#define	CALL(a)		CHOICE(call a, call a, call a)
#define	CALLF(s,a)	CHOICE(lcall ARG2(s,a), lcall ARG2(s,a), callf s:a)
#define	CBW		CHOICE(cbtw, cbw, cbw)
#define	CWDE		CHOICE(cwtd, cwde, cwde)
#define	CLC		CHOICE(clc, clc, clc)
#define	CLD		CHOICE(cld, cld, cld)
#define	CLI		CHOICE(cli, cli, cli)
#define	CLTS		CHOICE(clts, clts, clts)
#define	CMC		CHOICE(cmc, cmc, cmc)
#define	CMP_L(a, b)	CHOICE(cmpl ARG2(a,b), cmpl ARG2(a,b), _LTOG cmp ARG2(b,a))
#define	CMP_W(a, b)	CHOICE(cmpw ARG2(a,b), cmpw ARG2(a,b), _WTOG cmp ARG2(b,a))
#define	CMP_B(a, b)	CHOICE(cmpb ARG2(a,b), cmpb ARG2(a,b), cmpb ARG2(b,a))
#define	CMPS_L		CHOICE(cmpsl, cmpsl, _LTOG cmps)
#define	CMPS_W		CHOICE(cmpsw, cmpsw, _WTOG cmps)
#define	CMPS_B		CHOICE(cmpsb, cmpsb, cmpsb)
#define	CWD		CHOICE(cwtl, cwd, cwd)
#define	CDQ		CHOICE(cltd, cdq, cdq)
#define	DAA		CHOICE(daa, daa, daa)
#define	DAS		CHOICE(das, das, das)
#define	DEC_L(a)	CHOICE(decl a, decl a, _LTOG dec a)
#define	DEC_W(a)	CHOICE(decw a, decw a, _WTOG dec a)
#define	DEC_B(a)	CHOICE(decb a, decb a, decb a)
#define	DIV_L(a)	CHOICE(divl a, divl a, div a)
#define	DIV_W(a)	CHOICE(divw a, divw a, div a)
#define	DIV_B(a)	CHOICE(divb a, divb a, divb a)
#define	ENTER(a,b)	CHOICE(enter ARG2(a,b), enter ARG2(a,b), enter ARG2(b,a))
#define	HLT		CHOICE(hlt, hlt, hlt)
#define	IDIV_L(a)	CHOICE(idivl a, idivl a, _LTOG idiv a)
#define	IDIV_W(a)	CHOICE(idivw a, idivw a, _WTOG idiv a)
#define	IDIV_B(a)	CHOICE(idivb a, idivb a, idivb a)
/* More forms than this for imul!! */
#define	IMUL_L(a, b)	CHOICE(imull ARG2(a,b), imull ARG2(a,b), _LTOG imul ARG2(b,a))
#define	IMUL_W(a, b)	CHOICE(imulw ARG2(a,b), imulw ARG2(a,b), _WTOG imul ARG2(b,a))
#define	IMUL_B(a)	CHOICE(imulb a, imulb a, imulb a)
#define	IN_L		CHOICE(inl (DX), inl ARG2(DX,EAX), _LTOG in DX)
#define	IN_W		CHOICE(inw (DX), inw ARG2(DX,AX), _WTOG in DX)
#define	IN_B		CHOICE(inb (DX), inb ARG2(DX,AL), inb DX)
/* Please AS code writer: use the following ONLY, if you refer to ports<256
 * directly, but not in IN1_W(DX), for instance, even if IN1_ looks nicer
 */
#if defined (sun)
#define IN1_L(a)    CHOICE(inl (a), inl ARG2(a,EAX), _LTOG in a)
#define IN1_W(a)    CHOICE(inw (a), inw ARG2(a,AX), _WTOG in a)
#define IN1_B(a)    CHOICE(inb (a), inb ARG2(a,AL), inb a)
#else
#define	IN1_L(a)	CHOICE(inl a, inl ARG2(a,EAX), _LTOG in a)
#define	IN1_W(a)	CHOICE(inw a, inw ARG2(a,AX), _WTOG in a)
#define	IN1_B(a)	CHOICE(inb a, inb ARG2(a,AL), inb a)
#endif
#define	INC_L(a)	CHOICE(incl a, incl a, _LTOG inc a)
#define	INC_W(a)	CHOICE(incw a, incw a, _WTOG inc a)
#define	INC_B(a)	CHOICE(incb a, incb a, incb a)
#define	INS_L		CHOICE(insl, insl, _LTOG ins)
#define	INS_W		CHOICE(insw, insw, _WTOG ins)
#define	INS_B		CHOICE(insb, insb, insb)
#define	INT(a)		CHOICE(int a, int a, int a)
#define	INT3		CHOICE(int CONST(3), int3, int CONST(3))
#define	INTO		CHOICE(into, into, into)
#define	IRET		CHOICE(iret, iret, iret)
#define	IRETD		CHOICE(iret, iret, iretd)
#define	JA(a)		CHOICE(ja a, ja a, ja a)
#define	JAE(a)		CHOICE(jae a, jae a, jae a)
#define	JB(a)		CHOICE(jb a, jb a, jb a)
#define	JBE(a)		CHOICE(jbe a, jbe a, jbe a)
#define	JC(a)		CHOICE(jc a, jc a, jc a)
#define	JE(a)		CHOICE(je a, je a, je a)
#define	JG(a)		CHOICE(jg a, jg a, jg a)
#define	JGE(a)		CHOICE(jge a, jge a, jge a)
#define	JL(a)		CHOICE(jl a, jl a, jl a)
#define	JLE(a)		CHOICE(jle a, jle a, jle a)
#define	JNA(a)		CHOICE(jna a, jna a, jna a)
#define	JNAE(a)		CHOICE(jnae a, jnae a, jnae a)
#define	JNB(a)		CHOICE(jnb a, jnb a, jnb a)
#define	JNBE(a)		CHOICE(jnbe a, jnbe a, jnbe a)
#define	JNC(a)		CHOICE(jnc a, jnc a, jnc a)
#define	JNE(a)		CHOICE(jne a, jne a, jne a)
#define	JNG(a)		CHOICE(jng a, jng a, jng a)
#define	JNGE(a)		CHOICE(jnge a, jnge a, jnge a)
#define	JNL(a)		CHOICE(jnl a, jnl a, jnl a)
#define	JNLE(a)		CHOICE(jnle a, jnle a, jnle a)
#define	JNO(a)		CHOICE(jno a, jno a, jno a)
#define	JNP(a)		CHOICE(jnp a, jnp a, jnp a)
#define	JNS(a)		CHOICE(jns a, jns a, jns a)
#define	JNZ(a)		CHOICE(jnz a, jnz a, jnz a)
#define	JO(a)		CHOICE(jo a, jo a, jo a)
#define	JP(a)		CHOICE(jp a, jp a, jp a)
#define	JPE(a)		CHOICE(jpe a, jpe a, jpe a)
#define	JPO(a)		CHOICE(jpo a, jpo a, jpo a)
#define	JS(a)		CHOICE(js a, js a, js a)
#define	JZ(a)		CHOICE(jz a, jz a, jz a)
#define	JMP(a)		CHOICE(jmp a, jmp a, jmp a)
#define	JMPF(s,a)	CHOICE(ljmp ARG2(s,a), ljmp ARG2(s,a), jmpf s:a)
#define	LAHF		CHOICE(lahf, lahf, lahf)
#if !defined(_REAL_MODE) && !defined(_V86_MODE)
#define	LAR(a, b)	CHOICE(lar ARG2(a, b), lar ARG2(a, b), lar ARG2(b, a))
#endif
#define	LEA_L(a, b)	CHOICE(leal ARG2(a,b), leal ARG2(a,b), _LTOG lea ARG2(b,a))
#define	LEA_W(a, b)	CHOICE(leaw ARG2(a,b), leaw ARG2(a,b), _WTOG lea ARG2(b,a))
#define	LEAVE		CHOICE(leave, leave, leave)
#define	LGDT(a)		CHOICE(lgdt a, lgdt a, lgdt a)
#define	LIDT(a)		CHOICE(lidt a, lidt a, lidt a)
#define	LDS(a, b)	CHOICE(ldsl ARG2(a,b), lds ARG2(a,b), lds ARG2(b,a))
#define	LES(a, b)	CHOICE(lesl ARG2(a,b), les ARG2(a,b), les ARG2(b,a))
#define	LFS(a, b)	CHOICE(lfsl ARG2(a,b), lfs ARG2(a,b), lfs ARG2(b,a))
#define	LGS(a, b)	CHOICE(lgsl ARG2(a,b), lgs ARG2(a,b), lgs ARG2(b,a))
#define	LSS(a, b)	CHOICE(lssl ARG2(a,b), lss ARG2(a,b), lss ARG2(b,a))
#define	LLDT(a)		CHOICE(lldt a, lldt a, lldt a)
#define	LMSW(a)		CHOICE(lmsw a, lmsw a, lmsw a)
#define LOCK		CHOICE(lock, lock, lock)
#define	LODS_L		CHOICE(lodsl, lodsl, _LTOG lods)
#define	LODS_W		CHOICE(lodsw, lodsw, _WTOG lods)
#define	LODS_B		CHOICE(lodsb, lodsb, lodsb)
#define	LOOP(a)		CHOICE(loop a, loop a, loop a)
#define	LOOPE(a)	CHOICE(loope a, loope a, loope a)
#define	LOOPZ(a)	CHOICE(loopz a, loopz a, loopz a)
#define	LOOPNE(a)	CHOICE(loopne a, loopne a, loopne a)
#define	LOOPNZ(a)	CHOICE(loopnz a, loopnz a, loopnz a)
#if !defined(_REAL_MODE) && !defined(_V86_MODE)
#define	LSL(a, b)	CHOICE(lsl ARG2(a,b), lsl ARG2(a,b), lsl ARG2(b,a))
#endif
#define	LTR(a)		CHOICE(ltr a, ltr a, ltr a)
#define	MOV_SR(a, b)	CHOICE(movw ARG2(a,b), mov ARG2(a,b), mov ARG2(b,a))
#define	MOV_L(a, b)	CHOICE(movl ARG2(a,b), movl ARG2(a,b), _LTOG mov ARG2(b,a))
#define	MOV_W(a, b)	CHOICE(movw ARG2(a,b), movw ARG2(a,b), _WTOG mov ARG2(b,a))
#define	MOV_B(a, b)	CHOICE(movb ARG2(a,b), movb ARG2(a,b), movb ARG2(b,a))
#define	MOVS_L		CHOICE(movsl, movsl, _LTOG movs)
#define	MOVS_W		CHOICE(movsw, movsw, _WTOG movs)
#define	MOVS_B		CHOICE(movsb, movsb, movsb)
#define	MOVSX_BL(a, b)	CHOICE(movsbl ARG2(a,b), movsbl ARG2(a,b), movsx ARG2(b,a))
#define	MOVSX_BW(a, b)	CHOICE(movsbw ARG2(a,b), movsbw ARG2(a,b), movsx ARG2(b,a))
#define	MOVSX_WL(a, b)	CHOICE(movswl ARG2(a,b), movswl ARG2(a,b), movsx ARG2(b,a))
#define	MOVZX_BL(a, b)	CHOICE(movzbl ARG2(a,b), movzbl ARG2(a,b), movzx ARG2(b,a))
#define	MOVZX_BW(a, b)	CHOICE(movzbw ARG2(a,b), movzbw ARG2(a,b), movzx ARG2(b,a))
#define	MOVZX_WL(a, b)	CHOICE(movzwl ARG2(a,b), movzwl ARG2(a,b), movzx ARG2(b,a))
#define	MUL_L(a)	CHOICE(mull a, mull a, _LTOG mul a)
#define	MUL_W(a)	CHOICE(mulw a, mulw a, _WTOG mul a)
#define	MUL_B(a)	CHOICE(mulb a, mulb a, mulb a)
#define	NEG_L(a)	CHOICE(negl a, negl a, _LTOG neg a)
#define	NEG_W(a)	CHOICE(negw a, negw a, _WTOG neg a)
#define	NEG_B(a)	CHOICE(negb a, negb a, negb a)
#define	NOP		CHOICE(nop, nop, nop)
#define	NOT_L(a)	CHOICE(notl a, notl a, _LTOG not a)
#define	NOT_W(a)	CHOICE(notw a, notw a, _WTOG not a)
#define	NOT_B(a)	CHOICE(notb a, notb a, notb a)
#define	OR_L(a,b)	CHOICE(orl ARG2(a,b), orl ARG2(a,b), _LTOG or ARG2(b,a))
#define	OR_W(a,b)	CHOICE(orw ARG2(a,b), orw ARG2(a,b), _WTOG or ARG2(b,a))
#define	OR_B(a,b)	CHOICE(orb ARG2(a,b), orb ARG2(a,b), orb ARG2(b,a))
#define	OUT_L		CHOICE(outl (DX), outl ARG2(EAX,DX), _LTOG out DX)
#define	OUT_W		CHOICE(outw (DX), outw ARG2(AX,DX), _WTOG out DX)
#define	OUT_B		CHOICE(outb (DX), outb ARG2(AL,DX), outb DX)
/* Please AS code writer: use the following ONLY, if you refer to ports<256
 * directly, but not in OUT1_W(DX), for instance, even if OUT1_ looks nicer
 */
#define	OUT1_L(a)	CHOICE(outl (a), outl ARG2(EAX,a), _LTOG out a)
#define	OUT1_W(a)	CHOICE(outw (a), outw ARG2(AX,a), _WTOG out a)
#define	OUT1_B(a)	CHOICE(outb (a), outb ARG2(AL,a), outb a)
#define	OUTS_L		CHOICE(outsl, outsl, _LTOG outs)
#define	OUTS_W		CHOICE(outsw, outsw, _WTOG outs)
#define	OUTS_B		CHOICE(outsb, outsb, outsb)
#define	POP_SR(a)	CHOICE(pop a, pop a, pop a)
#define	POP_L(a)	CHOICE(popl a, popl a, _LTOG pop a)
#define	POP_W(a)	CHOICE(popw a, popw a, _WTOG pop a)
#define	POPA_L		CHOICE(popal, popal, _LTOG popa)
#define	POPA_W		CHOICE(popaw, popaw, _WTOG popa)
#define	POPF_L		CHOICE(popfl, popfl, _LTOG popf)
#define	POPF_W		CHOICE(popfw, popfw, _WTOG popf)
#define	PUSH_SR(a)	CHOICE(push a, push a, push a)
#define	PUSH_L(a)	CHOICE(pushl a, pushl a, _LTOG push a)
#define	PUSH_W(a)	CHOICE(pushw a, pushw a, _WTOG push a)
#define	PUSH_B(a)	CHOICE(push a, pushb a, push a)
#define	PUSHA_L		CHOICE(pushal, pushal, _LTOG pusha)
#define	PUSHA_W		CHOICE(pushaw, pushaw, _WTOG pusha)
#define	PUSHF_L		CHOICE(pushfl, pushfl, _LTOG pushf)
#define	PUSHF_W		CHOICE(pushfw, pushfw, _WTOG pushf)
#define	RCL_L(a, b)	CHOICE(rcll ARG2(a,b), rcll ARG2(a,b), _LTOG rcl ARG2(b,a))
#define	RCL_W(a, b)	CHOICE(rclw ARG2(a,b), rclw ARG2(a,b), _WTOG rcl ARG2(b,a))
#define	RCL_B(a, b)	CHOICE(rclb ARG2(a,b), rclb ARG2(a,b), rclb ARG2(b,a))
#define	RCR_L(a, b)	CHOICE(rcrl ARG2(a,b), rcrl ARG2(a,b), _LTOG rcr ARG2(b,a))
#define	RCR_W(a, b)	CHOICE(rcrw ARG2(a,b), rcrw ARG2(a,b), _WTOG rcr ARG2(b,a))
#define	RCR_B(a, b)	CHOICE(rcrb ARG2(a,b), rcrb ARG2(a,b), rcrb ARG2(b,a))
#define	ROL_L(a, b)	CHOICE(roll ARG2(a,b), roll ARG2(a,b), _LTOG rol ARG2(b,a))
#define	ROL_W(a, b)	CHOICE(rolw ARG2(a,b), rolw ARG2(a,b), _WTOG rol ARG2(b,a))
#define	ROL_B(a, b)	CHOICE(rolb ARG2(a,b), rolb ARG2(a,b), rolb ARG2(b,a))
#define	ROR_L(a, b)	CHOICE(rorl ARG2(a,b), rorl ARG2(a,b), _LTOG ror ARG2(b,a))
#define	ROR_W(a, b)	CHOICE(rorw ARG2(a,b), rorw ARG2(a,b), _WTOG ror ARG2(b,a))
#define	ROR_B(a, b)	CHOICE(rorb ARG2(a,b), rorb ARG2(a,b), rorb ARG2(b,a))
#define	REP		CHOICE(rep ;, rep ;, repe)
#define	REPE		CHOICE(repz ;, repe ;, repe)
#define	REPNE		CHOICE(repnz ;, repne ;, repne)
#define	REPNZ		REPNE
#define	REPZ		REPE
#define	RET		CHOICE(ret, ret, ret)
#define	SAHF		CHOICE(sahf, sahf, sahf)
#define	SAL_L(a, b)	CHOICE(sall ARG2(a,b), sall ARG2(a,b), _LTOG sal ARG2(b,a))
#define	SAL_W(a, b)	CHOICE(salw ARG2(a,b), salw ARG2(a,b), _WTOG sal ARG2(b,a))
#define	SAL_B(a, b)	CHOICE(salb ARG2(a,b), salb ARG2(a,b), salb ARG2(b,a))
#define	SAR_L(a, b)	CHOICE(sarl ARG2(a,b), sarl ARG2(a,b), _LTOG sar ARG2(b,a))
#define	SAR_W(a, b)	CHOICE(sarw ARG2(a,b), sarw ARG2(a,b), _WTOG sar ARG2(b,a))
#define	SAR_B(a, b)	CHOICE(sarb ARG2(a,b), sarb ARG2(a,b), sarb ARG2(b,a))
#define	SBB_L(a, b)	CHOICE(sbbl ARG2(a,b), sbbl ARG2(a,b), _LTOG sbb ARG2(b,a))
#define	SBB_W(a, b)	CHOICE(sbbw ARG2(a,b), sbbw ARG2(a,b), _WTOG sbb ARG2(b,a))
#define	SBB_B(a, b)	CHOICE(sbbb ARG2(a,b), sbbb ARG2(a,b), sbbb ARG2(b,a))
#define	SCAS_L		CHOICE(scasl, scasl, _LTOG scas)
#define	SCAS_W		CHOICE(scasw, scasw, _WTOG scas)
#define	SCAS_B		CHOICE(scasb, scasb, scasb)
#define	SETA(a)		CHOICE(seta a, seta a, seta a)
#define	SETAE(a)	CHOICE(setae a, setae a, setae a)
#define	SETB(a)		CHOICE(setb a, setb a, setb a)
#define	SETBE(a)	CHOICE(setbe a, setbe a, setbe a)
#define	SETC(a)		CHOICE(setc a, setb a, setb a)
#define	SETE(a)		CHOICE(sete a, sete a, sete a)
#define	SETG(a)		CHOICE(setg a, setg a, setg a)
#define	SETGE(a)	CHOICE(setge a, setge a, setge a)
#define	SETL(a)		CHOICE(setl a, setl a, setl a)
#define	SETLE(a)	CHOICE(setle a, setle a, setle a)
#define	SETNA(a)	CHOICE(setna a, setna a, setna a)
#define	SETNAE(a)	CHOICE(setnae a, setnae a, setnae a)
#define	SETNB(a)	CHOICE(setnb a, setnb a, setnb a)
#define	SETNBE(a)	CHOICE(setnbe a, setnbe a, setnbe a)
#define	SETNC(a)	CHOICE(setnc a, setnb a, setnb a)
#define	SETNE(a)	CHOICE(setne a, setne a, setne a)
#define	SETNG(a)	CHOICE(setng a, setng a, setng a)
#define	SETNGE(a)	CHOICE(setnge a, setnge a, setnge a)
#define	SETNL(a)	CHOICE(setnl a, setnl a, setnl a)
#define	SETNLE(a)	CHOICE(setnle a, setnle a, setnle a)
#define	SETNO(a)	CHOICE(setno a, setno a, setno a)
#define	SETNP(a)	CHOICE(setnp a, setnp a, setnp a)
#define	SETNS(a)	CHOICE(setns a, setns a, setna a)
#define	SETNZ(a)	CHOICE(setnz a, setnz a, setnz a)
#define	SETO(a)		CHOICE(seto a, seto a, seto a)
#define	SETP(a)		CHOICE(setp a, setp a, setp a)
#define	SETPE(a)	CHOICE(setpe a, setpe a, setpe a)
#define	SETPO(a)	CHOICE(setpo a, setpo a, setpo a)
#define	SETS(a)		CHOICE(sets a, sets a, seta a)
#define	SETZ(a)		CHOICE(setz a, setz a, setz a)
#define	SGDT(a)		CHOICE(sgdt a, sgdt a, sgdt a)
#define	SIDT(a)		CHOICE(sidt a, sidt a, sidt a)
#define	SHL_L(a, b)	CHOICE(shll ARG2(a,b), shll ARG2(a,b), _LTOG shl ARG2(b,a))
#define	SHL_W(a, b)	CHOICE(shlw ARG2(a,b), shlw ARG2(a,b), _WTOG shl ARG2(b,a))
#define	SHL_B(a, b)	CHOICE(shlb ARG2(a,b), shlb ARG2(a,b), shlb ARG2(b,a))
#define	SHLD_L(a,b,c)	CHOICE(shldl ARG3(a,b,c), shldl ARG3(a,b,c), _LTOG shld ARG3(c,b,a))
#define	SHLD2_L(a,b)	CHOICE(shldl ARG2(a,b), shldl ARG3(CL,a,b), _LTOG shld ARG3(b,a,CL))
#define	SHLD_W(a,b,c)	CHOICE(shldw ARG3(a,b,c), shldw ARG3(a,b,c), _WTOG shld ARG3(c,b,a))
#define	SHLD2_W(a,b)	CHOICE(shldw ARG2(a,b), shldw ARG3(CL,a,b), _WTOG shld ARG3(b,a,CL))
#define	SHR_L(a, b)	CHOICE(shrl ARG2(a,b), shrl ARG2(a,b), _LTOG shr ARG2(b,a))
#define	SHR_W(a, b)	CHOICE(shrw ARG2(a,b), shrw ARG2(a,b), _WTOG shr ARG2(b,a))
#define	SHR_B(a, b)	CHOICE(shrb ARG2(a,b), shrb ARG2(a,b), shrb ARG2(b,a))
#define	SHRD_L(a,b,c)	CHOICE(shrdl ARG3(a,b,c), shrdl ARG3(a,b,c), _LTOG shrd ARG3(c,b,a))
#define	SHRD2_L(a,b)	CHOICE(shrdl ARG2(a,b), shrdl ARG3(CL,a,b), _LTOG shrd ARG3(b,a,CL))
#define	SHRD_W(a,b,c)	CHOICE(shrdw ARG3(a,b,c), shrdw ARG3(a,b,c), _WTOG shrd ARG3(c,b,a))
#define	SHRD2_W(a,b)	CHOICE(shrdw ARG2(a,b), shrdw ARG3(CL,a,b), _WTOG shrd ARG3(b,a,CL))
#define	SLDT(a)		CHOICE(sldt a, sldt a, sldt a)
#define	SMSW(a)		CHOICE(smsw a, smsw a, smsw a)
#define	STC		CHOICE(stc, stc, stc)
#define	STD		CHOICE(std, std, std)
#define	STI		CHOICE(sti, sti, sti)
#define	STOS_L		CHOICE(stosl, stosl, _LTOG stos)
#define	STOS_W		CHOICE(stosw, stosw, _WTOG stos)
#define	STOS_B		CHOICE(stosb, stosb, stosb)
#define	STR(a)		CHOICE(str a, str a, str a)
#define	SUB_L(a, b)	CHOICE(subl ARG2(a,b), subl ARG2(a,b), _LTOG sub ARG2(b,a))
#define	SUB_W(a, b)	CHOICE(subw ARG2(a,b), subw ARG2(a,b), _WTOG sub ARG2(b,a))
#define	SUB_B(a, b)	CHOICE(subb ARG2(a,b), subb ARG2(a,b), subb ARG2(b,a))
#define	TEST_L(a, b)	CHOICE(testl ARG2(a,b), testl ARG2(a,b), _LTOG test ARG2(b,a))
#define	TEST_W(a, b)	CHOICE(testw ARG2(a,b), testw ARG2(a,b), _WTOG test ARG2(b,a))
#define	TEST_B(a, b)	CHOICE(testb ARG2(a,b), testb ARG2(a,b), testb ARG2(b,a))
#define	VERR(a)		CHOICE(verr a, verr a, verr a)
#define	VERW(a)		CHOICE(verw a, verw a, verw a)
#define	WAIT		CHOICE(wait, wait, wait)
#define	XCHG_L(a, b)	CHOICE(xchgl ARG2(a,b), xchgl ARG2(a,b), _LTOG xchg ARG2(b,a))
#define	XCHG_W(a, b)	CHOICE(xchgw ARG2(a,b), xchgw ARG2(a,b), _WTOG xchg ARG2(b,a))
#define	XCHG_B(a, b)	CHOICE(xchgb ARG2(a,b), xchgb ARG2(a,b), xchgb ARG2(b,a))
#define	XLAT		CHOICE(xlat, xlat, xlat)
#define	XOR_L(a, b)	CHOICE(xorl ARG2(a,b), xorl ARG2(a,b), _LTOG xor ARG2(b,a))
#define	XOR_W(a, b)	CHOICE(xorw ARG2(a,b), xorw ARG2(a,b), _WTOG xor ARG2(b,a))
#define	XOR_B(a, b)	CHOICE(xorb ARG2(a,b), xorb ARG2(a,b), xorb ARG2(b,a))


/* Floating Point Instructions */
#define	F2XM1		CHOICE(f2xm1, f2xm1, f2xm1)
#define	FABS		CHOICE(fabs, fabs, fabs)
#define	FADD_D(a)	CHOICE(faddl a, faddl a, faddd a)
#define	FADD_S(a)	CHOICE(fadds a, fadds a, fadds a)
#define	FADD2(a, b)	CHOICE(fadd ARG2(a,b), fadd ARG2(a,b), fadd ARG2(b,a))
#define	FADDP(a, b)	CHOICE(faddp ARG2(a,b), faddp ARG2(a,b), faddp ARG2(b,a))
#define	FIADD_L(a)	CHOICE(fiaddl a, fiaddl a, fiaddl a)
#define	FIADD_W(a)	CHOICE(fiadd a, fiadds a, fiadds a)
#define	FBLD(a)		CHOICE(fbld a, fbld a, fbld a)
#define	FBSTP(a)	CHOICE(fbstp a, fbstp a, fbstp a)
#define	FCHS		CHOICE(fchs, fchs, fchs)
#define	FCLEX		CHOICE(fclex, wait; fnclex, wait; fclex)
#define	FNCLEX		CHOICE(fnclex, fnclex, fclex)
#define	FCOM(a)		CHOICE(fcom a, fcom a, fcom a)
#define	FCOM_D(a)	CHOICE(fcoml a, fcoml a, fcomd a)
#define	FCOM_S(a)	CHOICE(fcoms a, fcoms a, fcoms a)
#define	FCOMP(a)	CHOICE(fcomp a, fcomp a, fcomp a)
#define	FCOMP_D(a)	CHOICE(fcompl a, fcompl a, fcompd a)
#define	FCOMP_S(a)	CHOICE(fcomps a, fcomps a, fcomps a)
#define	FCOMPP		CHOICE(fcompp, fcompp, fcompp)
#define	FCOS		CHOICE(fcos, fcos, fcos)
#define	FDECSTP		CHOICE(fdecstp, fdecstp, fdecstp)
#define	FDIV_D(a)	CHOICE(fdivl a, fdivl a, fdivd a)
#define	FDIV_S(a)	CHOICE(fdivs a, fdivs a, fdivs a)
#define	FDIV2(a, b)	CHOICE(fdiv ARG2(a,b), fdiv ARG2(a,b), fdiv ARG2(b,a))
#define	FDIVP(a, b)	CHOICE(fdivp ARG2(a,b), fdivp ARG2(a,b), fdivp ARG2(b,a))
#define	FIDIV_L(a)	CHOICE(fidivl a, fidivl a, fidivl a)
#define	FIDIV_W(a)	CHOICE(fidiv a, fidivs a, fidivs a)
#define	FDIVR_D(a)	CHOICE(fdivrl a, fdivrl a, fdivrd a)
#define	FDIVR_S(a)	CHOICE(fdivrs a, fdivrs a, fdivrs a)
#define	FDIVR2(a, b)	CHOICE(fdivr ARG2(a,b), fdivr ARG2(a,b), fdivr ARG2(b,a))
#define	FDIVRP(a, b)	CHOICE(fdivrp ARG2(a,b), fdivrp ARG2(a,b), fdivrp ARG2(b,a))
#define	FIDIVR_L(a)	CHOICE(fidivrl a, fidivrl a, fidivrl a)
#define	FIDIVR_W(a)	CHOICE(fidivr a, fidivrs a, fidivrs a)
#define	FFREE(a)	CHOICE(ffree a, ffree a, ffree a)
#define	FICOM_L(a)	CHOICE(ficoml a, ficoml a, ficoml a)
#define	FICOM_W(a)	CHOICE(ficom a, ficoms a, ficoms a)
#define	FICOMP_L(a)	CHOICE(ficompl a, ficompl a, ficompl a)
#define	FICOMP_W(a)	CHOICE(ficomp a, ficomps a, ficomps a)
#define	FILD_Q(a)	CHOICE(fildll a, fildq a, fildq a)
#define	FILD_L(a)	CHOICE(fildl a, fildl a, fildl a)
#define	FILD_W(a)	CHOICE(fild a, filds a, filds a)
#define	FINCSTP		CHOICE(fincstp, fincstp, fincstp)
#define	FINIT		CHOICE(finit, wait; fninit, wait; finit)
#define	FNINIT		CHOICE(fninit, fninit, finit)
#define	FIST_L(a)	CHOICE(fistl a, fistl a, fistl a)
#define	FIST_W(a)	CHOICE(fist a, fists a, fists a)
#define	FISTP_Q(a)	CHOICE(fistpll a, fistpq a, fistpq a)
#define	FISTP_L(a)	CHOICE(fistpl a, fistpl a, fistpl a)
#define	FISTP_W(a)	CHOICE(fistp a, fistps a, fistps a)
#define	FLD_X(a)	CHOICE(fldt a, fldt a, fldx a) /* 80 bit data type! */
#define	FLD_D(a)	CHOICE(fldl a, fldl a, fldd a)
#define	FLD_S(a)	CHOICE(flds a, flds a, flds a)
#define	FLD1		CHOICE(fld1, fld1, fld1)
#define	FLDL2T		CHOICE(fldl2t, fldl2t, fldl2t)
#define	FLDL2E		CHOICE(fldl2e, fldl2e, fldl2e)
#define	FLDPI		CHOICE(fldpi, fldpi, fldpi)
#define	FLDLG2		CHOICE(fldlg2, fldlg2, fldlg2)
#define	FLDLN2		CHOICE(fldln2, fldln2, fldln2)
#define	FLDZ		CHOICE(fldz, fldz, fldz)
#define	FLDCW(a)	CHOICE(fldcw a, fldcw a, fldcw a)
#define	FLDENV(a)	CHOICE(fldenv a, fldenv a, fldenv a)
#define	FMUL_S(a)	CHOICE(fmuls a, fmuls a, fmuls a)
#define	FMUL_D(a)	CHOICE(fmull a, fmull a, fmuld a)
#define	FMUL2(a, b)	CHOICE(fmul ARG2(a,b), fmul ARG2(a,b), fmul ARG2(b,a))
#define	FMULP(a, b)	CHOICE(fmulp ARG2(a,b), fmulp ARG2(a,b), fmulp ARG2(b,a))
#define	FIMUL_L(a)	CHOICE(fimull a, fimull a, fimull a)
#define	FIMUL_W(a)	CHOICE(fimul a, fimuls a, fimuls a)
#define	FNOP		CHOICE(fnop, fnop, fnop)
#define	FPATAN		CHOICE(fpatan, fpatan, fpatan)
#define	FPREM		CHOICE(fprem, fprem, fprem)
#define	FPREM1		CHOICE(fprem1, fprem1, fprem1)
#define	FPTAN		CHOICE(fptan, fptan, fptan)
#define	FRNDINT		CHOICE(frndint, frndint, frndint)
#define	FRSTOR(a)	CHOICE(frstor a, frstor a, frstor a)
#define	FSAVE(a)	CHOICE(fsave a, wait; fnsave a, wait; fsave a)
#define	FNSAVE(a)	CHOICE(fnsave a, fnsave a, fsave a)
#define	FSCALE		CHOICE(fscale, fscale, fscale)
#define	FSIN		CHOICE(fsin, fsin, fsin)
#define	FSINCOS		CHOICE(fsincos, fsincos, fsincos)
#define	FSQRT		CHOICE(fsqrt, fsqrt, fsqrt)
#define	FST_D(a)	CHOICE(fstl a, fstl a, fstd a)
#define	FST_S(a)	CHOICE(fsts a, fsts a, fsts a)
#define	FSTP_X(a)	CHOICE(fstpt a, fstpt a, fstpx a)
#define	FSTP_D(a)	CHOICE(fstpl a, fstpl a, fstpd a)
#define	FSTP_S(a)	CHOICE(fstps a, fstps a, fstps a)
#define	FSTCW(a)	CHOICE(fstcw a, wait; fnstcw a, wait; fstcw a)
#define	FNSTCW(a)	CHOICE(fnstcw a, fnstcw a, fstcw a)
#define	FSTENV(a)	CHOICE(fstenv a, wait; fnstenv a, fstenv a)
#define	FNSTENV(a)	CHOICE(fnstenv a, fnstenv a, fstenv a)
#define	FSTSW(a)	CHOICE(fstsw a, wait; fnstsw a, wait; fstsw a)
#define	FNSTSW(a)	CHOICE(fnstsw a, fnstsw a, fstsw a)
#define	FSUB_S(a)	CHOICE(fsubs a, fsubs a, fsubs a)
#define	FSUB_D(a)	CHOICE(fsubl a, fsubl a, fsubd a)
#define	FSUB2(a, b)	CHOICE(fsub ARG2(a,b), fsub ARG2(a,b), fsub ARG2(b,a))
#define	FSUBP(a, b)	CHOICE(fsubp ARG2(a,b), fsubp ARG2(a,b), fsubp ARG2(b,a))
#define	FISUB_L(a)	CHOICE(fisubl a, fisubl a, fisubl a)
#define	FISUB_W(a)	CHOICE(fisub a, fisubs a, fisubs a)
#define	FSUBR_S(a)	CHOICE(fsubrs a, fsubrs a, fsubrs a)
#define	FSUBR_D(a)	CHOICE(fsubrl a, fsubrl a, fsubrd a)
#define	FSUBR2(a, b)	CHOICE(fsubr ARG2(a,b), fsubr ARG2(a,b), fsubr ARG2(b,a))
#define	FSUBRP(a, b)	CHOICE(fsubrp ARG2(a,b), fsubrp ARG2(a,b), fsubrp ARG2(b,a))
#define	FISUBR_L(a)	CHOICE(fisubrl a, fisubrl a, fisubrl a)
#define	FISUBR_W(a)	CHOICE(fisubr a, fisubrs a, fisubrs a)
#define	FTST		CHOICE(ftst, ftst, ftst)
#define	FUCOM(a)	CHOICE(fucom a, fucom a, fucom a)
#define	FUCOMP(a)	CHOICE(fucomp a, fucomp a, fucomp a)
#define	FUCOMPP		CHOICE(fucompp, fucompp, fucompp)
#define	FWAIT		CHOICE(wait, wait, wait)
#define	FXAM		CHOICE(fxam, fxam, fxam)
#define	FXCH(a)		CHOICE(fxch a, fxch a, fxch a)
#define	FXTRACT		CHOICE(fxtract, fxtract, fxtract)
#define	FYL2X		CHOICE(fyl2x, fyl2x, fyl2x)
#define	FYL2XP1		CHOICE(fyl2xp1, fyl2xp1, fyl2xp1)

#endif /* __ASSYNTAX_H__ */

--- NEW FILE: int10Defines.h ---
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/int10Defines.h,v 1.4 2003/08/24 17:37:03 dawes Exp $ */
/*
 * Copyright (c) 2000-2001 by The XFree86 Project, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of the copyright holder(s)
 * and author(s) shall not be used in advertising or otherwise to promote
 * the sale, use or other dealings in this Software without prior written
 * authorization from the copyright holder(s) and author(s).
 */

#ifndef _INT10DEFINES_H_
#define _INT10DEFINES_H_ 1

#ifdef _VM86_LINUX

#include <asm/vm86.h>

#define CPU_R(type,name,num) \
	(((type *)&(((struct vm86_struct *)REG->cpuRegs)->regs.name))[num])
#define CPU_RD(name,num) CPU_R(CARD32,name,num)
#define CPU_RW(name,num) CPU_R(CARD16,name,num)
#define CPU_RB(name,num) CPU_R(CARD8,name,num)

#define X86_EAX CPU_RD(eax,0)
#define X86_EBX CPU_RD(ebx,0)
#define X86_ECX CPU_RD(ecx,0)
#define X86_EDX CPU_RD(edx,0)
#define X86_ESI CPU_RD(esi,0)
#define X86_EDI CPU_RD(edi,0)
#define X86_EBP CPU_RD(ebp,0)
#define X86_EIP CPU_RD(eip,0)
#define X86_ESP CPU_RD(esp,0)
#define X86_EFLAGS CPU_RD(eflags,0)

#define X86_FLAGS CPU_RW(eflags,0)
#define X86_AX CPU_RW(eax,0)
#define X86_BX CPU_RW(ebx,0)
#define X86_CX CPU_RW(ecx,0)
#define X86_DX CPU_RW(edx,0)
#define X86_SI CPU_RW(esi,0)
#define X86_DI CPU_RW(edi,0)
#define X86_BP CPU_RW(ebp,0)
#define X86_IP CPU_RW(eip,0)
#define X86_SP CPU_RW(esp,0)
#define X86_CS CPU_RW(cs,0)
#define X86_DS CPU_RW(ds,0)
#define X86_ES CPU_RW(es,0)
#define X86_SS CPU_RW(ss,0)
#define X86_FS CPU_RW(fs,0)
#define X86_GS CPU_RW(gs,0)

#define X86_AL CPU_RB(eax,0)
#define X86_BL CPU_RB(ebx,0)
#define X86_CL CPU_RB(ecx,0)
#define X86_DL CPU_RB(edx,0)

#define X86_AH CPU_RB(eax,1)
#define X86_BH CPU_RB(ebx,1)
#define X86_CH CPU_RB(ecx,1)
#define X86_DH CPU_RB(edx,1)

#elif defined(_X86EMU)

#include "xf86x86emu.h"

#endif

#endif

--- NEW FILE: xf86OSKbd.h ---
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86OSKbd.h,v 1.5tsi Exp $ */
/*
 * Copyright (c) 2002-2003 by The XFree86 Project, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of the copyright holder(s)
 * and author(s) shall not be used in advertising or otherwise to promote
 * the sale, use or other dealings in this Software without prior written
 * authorization from the copyright holder(s) and author(s).
 *
 * Author: Ivan Pascal.
 */

#include "xf86Xinput.h"

Bool ATScancode(InputInfoPtr pInfo, int *scanCode);

/* Public interface to OS-specific keyboard support. */

typedef	int	(*KbdInitProc)(InputInfoPtr pInfo, int what);
typedef	int	(*KbdOnProc)(InputInfoPtr pInfo, int what);
typedef	int	(*KbdOffProc)(InputInfoPtr pInfo, int what);
typedef	void	(*BellProc)(InputInfoPtr pInfo,
                            int loudness, int pitch, int duration);
typedef	void	(*SetLedsProc)(InputInfoPtr pInfo, int leds);
typedef	int	(*GetLedsProc)(InputInfoPtr pInfo);
typedef	void	(*SetKbdRepeatProc)(InputInfoPtr pInfo, char rad);
typedef	void	(*KbdGetMappingProc)(InputInfoPtr pInfo,
                                     KeySymsPtr pKeySyms, CARD8* pModMap);
typedef	int	(*GetSpecialKeyProc)(InputInfoPtr pInfo, int scanCode);
typedef	Bool	(*SpecialKeyProc)(InputInfoPtr pInfo,
                                     int key, Bool down, int modifiers);
typedef	int	(*RemapScanCodeProc)(InputInfoPtr pInfo, int *scanCode);
typedef	Bool	(*OpenKeyboardProc)(InputInfoPtr pInfo);
typedef	void	(*PostEventProc)(InputInfoPtr pInfo,
                                 unsigned int key, Bool down);
typedef struct {
    int                 begin;
    int                 end;
    unsigned char       *map;
} TransMapRec, *TransMapPtr;

typedef struct {
    KbdInitProc		KbdInit;
    KbdOnProc		KbdOn;
    KbdOffProc		KbdOff;
    BellProc		Bell;
    SetLedsProc		SetLeds;
    GetLedsProc		GetLeds;
    SetKbdRepeatProc	SetKbdRepeat;
    KbdGetMappingProc	KbdGetMapping;
    RemapScanCodeProc	RemapScanCode;
    GetSpecialKeyProc	GetSpecialKey;
    SpecialKeyProc	SpecialKey;

    OpenKeyboardProc	OpenKeyboard;
    PostEventProc	PostEvent;

    int			rate;
    int			delay;
    int			bell_pitch;
    int			bell_duration;
    Bool		autoRepeat;
    unsigned long	leds;
    unsigned long	xledsMask;
    unsigned long	keyLeds;
    int			scanPrefix;
    Bool		vtSwitchSupported;
    Bool		CustomKeycodes;
    Bool		noXkb;
    Bool		isConsole;
    TransMapPtr         scancodeMap;
    TransMapPtr         specialMap;

    /* os specific */
    pointer		private;
    int			kbdType;
    int			consType;
    int			wsKbdType;
    Bool		sunKbd;
    Bool		Panix106;

} KbdDevRec, *KbdDevPtr;

typedef enum {
    PROT_STD,
    PROT_XQUEUE,
    PROT_WSCONS,
    PROT_USB,
    PROT_UNKNOWN_KBD
} KbdProtocolId;

typedef struct {
    const char		*name;
    KbdProtocolId	id;
} KbdProtocolRec;

Bool xf86OSKbdPreInit(InputInfoPtr pInfo);

/* Adjust this when the kbd interface changes. */

/*
 * History:
 *
 *  1.0.0 - Initial version.
 */

#define OS_KBD_VERSION_MAJOR 1
#define OS_KBD_VERSION_MINOR 0
#define OS_KBD_VERSION_PATCH 0

#define OS_KBD_VERSION_CURRENT						\
	BUILTIN_INTERFACE_VERSION_NUMERIC(OS_KBD_VERSION_MAJOR,		\
					  OS_KBD_VERSION_MINOR,		\
					  OS_KBD_VERSION_PATCH)


--- NEW FILE: xf86OSmouse.h ---
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86OSmouse.h,v 1.24 2003/11/03 05:11:51 tsi Exp $ */
/*
 * Copyright (c) 1999-2003 by The XFree86 Project, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of the copyright holder(s)
 * and author(s) shall not be used in advertising or otherwise to promote
 * the sale, use or other dealings in this Software without prior written
 * authorization from the copyright holder(s) and author(s).
 */

/* Public interface to OS-specific mouse support. */

#ifndef _XF86OSMOUSE_H_
#define _XF86OSMOUSE_H_

#include "xf86Xinput.h"

/* Mouse interface classes */
#define MSE_NONE	0x00
#define MSE_SERIAL	0x01		/* serial port */
#define MSE_BUS		0x02		/* old bus mouse */
#define MSE_PS2		0x04		/* standard read-only PS/2 */
#define MSE_XPS2	0x08		/* extended PS/2 */
#define MSE_AUTO	0x10		/* auto-detect (PnP) */
#define MSE_MISC	0x20		/* The OS layer will identify the
					 * specific protocol names that are
					 * supported for this class. */

/* Mouse Protocol IDs. */
typedef enum {
    PROT_UNKNOWN = -2,
    PROT_UNSUP = -1,		/* protocol is not supported */
    PROT_MS = 0,
    PROT_MSC,
    PROT_MM,
    PROT_LOGI,
    PROT_LOGIMAN,
    PROT_MMHIT,
    PROT_GLIDE,
    PROT_IMSERIAL,
    PROT_THINKING,
    PROT_ACECAD,
    PROT_VALUMOUSESCROLL,
    PROT_PS2,
    PROT_GENPS2,
    PROT_IMPS2,
    PROT_EXPPS2,
    PROT_THINKPS2,
    PROT_MMPS2,
    PROT_GLIDEPS2,
    PROT_NETPS2,
    PROT_NETSCPS2,
    PROT_BM,
    PROT_AUTO,
    PROT_SYSMOUSE,
    PROT_NUMPROTOS	/* This must always be last. */
} MouseProtocolID;

struct _MouseDevRec;

typedef int (*GetInterfaceTypesProc)(void);
typedef const char **(*BuiltinNamesProc)(void);
typedef Bool (*CheckProtocolProc)(const char *protocol);
typedef Bool (*BuiltinPreInitProc)(InputInfoPtr pInfo, const char *protocol,
				   int flags);
typedef const char *(*DefaultProtocolProc)(void);
typedef const char *(*SetupAutoProc)(InputInfoPtr pInfo, int *protoPara);
typedef void (*SetResProc)(InputInfoPtr pInfo, const char* protocol, int rate,
			   int res);
typedef const char *(*FindDeviceProc)(InputInfoPtr pInfo, const char *protocol,
				      int flags);
typedef const char *(*GuessProtocolProc)(InputInfoPtr pInfo, int flags);

/*
 * OSMouseInfoRec is used to pass information from the OSMouse layer to the
 * OS-independent mouse driver.
 */
typedef struct {
	GetInterfaceTypesProc	SupportedInterfaces;
	BuiltinNamesProc	BuiltinNames;
	CheckProtocolProc	CheckProtocol;
	BuiltinPreInitProc	PreInit;
	DefaultProtocolProc	DefaultProtocol;
	SetupAutoProc		SetupAuto;
	SetResProc		SetPS2Res;
	SetResProc		SetBMRes;
	SetResProc		SetMiscRes;
	FindDeviceProc		FindDevice;
	GuessProtocolProc	GuessProtocol;
} OSMouseInfoRec, *OSMouseInfoPtr;

/*
 * SupportedInterfaces: Returns the mouse interface types that the OS support.
 *		If MSE_MISC is returned, then the BuiltinNames and
 *		CheckProtocol should be set.
 *
 * BuiltinNames: Returns the names of the protocols that are fully handled
 *		in the OS-specific code.  These are names that don't appear
 *		directly in the main "mouse" driver.
 *
 * CheckProtocol: Checks if the protocol name given is supported by the
 *		OS.  It should return TRUE for both "builtin" protocols and
 *		protocols of type MSE_MISC that are supported by the OS.
 *
 * PreInit:	The PreInit function for protocols that are builtin.  This
 *		function is passed the protocol name.
 *
 * DefaultProtocol: Returns the name of a default protocol that should be used
 *		for the OS when none has been supplied in the config file.
 *		This should only be set when there is a reasonable default.
 *
 * SetupAuto:	This function can be used to do OS-specific protocol
 *		auto-detection.  It returns the name of the detected protocol,
 *		or NULL when detection fails.  It may also adjust one or more
 *		of the "protoPara" values for the detected protocol by setting
 *		then to something other than -1.  SetupAuto gets called in two
 *		ways.  The first is before any devices have been opened.  This
 *		can be used when the protocol "Auto" always maps to a single
 *		protocol type.  The second is with the device open, allowing
 *		OS-specific probing to be done.
 *
 * SetPS2Res:	Set the resolution and sample rate for MSE_PS2 and MSE_XPS2
 *		protocol types.
 *
 * SetBMRes:	Set the resolution and sample rate for MSE_BM protocol types.
 *
 * SetMiscRes:	Set the resolution and sample rate for MSE_MISC protocol types.
 *
 * FindDevice:	This function gets called when no Device has been specified
 *		in the config file.  OS-specific methods may be used to guess
 * 		which input device to use.  This function is called after the
 *		pre-open attempts at protocol discovery are done, but before
 * 		the device is open.  I.e., after the first SetupAuto() call,
 *		after the DefaultProtocol() call, but before the PreInit()
 *		call.  Available protocol information may be used in locating
 *		the default input device.
 *
 * GuessProtocol: A last resort attempt at guessing the mouse protocol by
 *		whatever OS-specific means might be available.  OS-independent
 *		things should be in the mouse driver.  This function gets
 *		called after the mouse driver's OS-independent methods have
 *		failed.
 */

extern OSMouseInfoPtr xf86OSMouseInit(int flags);

/* Adjust this when the mouse interface changes. */

/*
 * History:
 *
 *  1.0.0 - Everything up to when versioning was started.
 *  1.1.0 - FindDevice and GuessProtocol added to OSMouseInfoRec
 *
 */

#define OS_MOUSE_VERSION_MAJOR 1
#define OS_MOUSE_VERSION_MINOR 1
#define OS_MOUSE_VERSION_PATCH 0

#define OS_MOUSE_VERSION_CURRENT					\
	BUILTIN_INTERFACE_VERSION_NUMERIC(OS_MOUSE_VERSION_MAJOR,	\
					  OS_MOUSE_VERSION_MINOR,	\
					  OS_MOUSE_VERSION_PATCH)

#define HAVE_GUESS_PROTOCOL \
	(xf86GetBuiltinInterfaceVersion(BUILTIN_IF_OSMOUSE, 0) >= \
                BUILTIN_INTERFACE_VERSION_NUMERIC(1, 1, 0))

#define HAVE_FIND_DEVICE \
	(xf86GetBuiltinInterfaceVersion(BUILTIN_IF_OSMOUSE, 0) >= \
                BUILTIN_INTERFACE_VERSION_NUMERIC(1, 1, 0))

/*
 * Mouse device record.  This is shared by the mouse driver and the OSMouse
 * layer.
 */

typedef void (*checkMovementsProc)(InputInfoPtr,int, int);
typedef void (*autoProbeProc)(InputInfoPtr, Bool, Bool);
typedef Bool (*collectDataProc)(struct _MouseDevRec *, unsigned char);
typedef Bool (*dataGoodProc)(struct _MouseDevRec *);

typedef void (*PostMseEventProc)(InputInfoPtr pInfo, int buttons,
			      int dx, int dy, int dz, int dw);
typedef void (*MouseCommonOptProc)(InputInfoPtr pInfo);

typedef struct _MouseDevRec {
    PtrCtrlProcPtr	Ctrl;
    PostMseEventProc	PostEvent;
    MouseCommonOptProc	CommonOptions;
    DeviceIntPtr	device;
    const char *	mseDevice;
    const char *	protocol;
    MouseProtocolID	protocolID;
    MouseProtocolID	oldProtocolID; /* hack */
    int			class;
    int			mseModel;
    int			baudRate;
    int			oldBaudRate;
    int			sampleRate;
    int			lastButtons;
    int			threshold;	/* acceleration */
    int			num;
    int			den;
    int			buttons;	/* # of buttons */
    int			emulateState;	/* automata state for 2 button mode */
    Bool		emulate3Buttons;
    Bool		emulate3ButtonsSoft;
    int			emulate3Timeout;/* Timeout for 3 button emulation */
    Bool		chordMiddle;
    Bool                flipXY;
    int                 invX;
    int                 invY;
    int			mouseFlags;	/* Flags to Clear after opening
					 * mouse dev */
    int			truebuttons;	/* (not used)
					 * Arg to maintain before
					 * emulate3buttons timer callback */
    int			resolution;
    int			negativeZ;	/* button mask */
    int			positiveZ;	/* button mask */
    int			negativeW;	/* button mask */
    int			positiveW;	/* button mask */
    pointer		buffer;		/* usually an XISBuffer* */
    int			protoBufTail;
    unsigned char	protoBuf[8];
    unsigned char	protoPara[8];
    unsigned char	inSync;		/* driver in sync with datastream */
    pointer		mousePriv;	/* private area */
    InputInfoPtr	pInfo;
    int			origProtocolID;
    const char *	origProtocol;
    Bool		emulate3Pending;/* timer waiting */
    CARD32		emulate3Expires;/* time to fire emulation code */
    Bool		emulateWheel;
    int			wheelInertia;
    int			wheelButtonMask;
    int			negativeX;	/* Button values.  Unlike the Z and */
    int			positiveX;	/* W equivalents, these are button  */
    int			negativeY;	/* values rather than button masks. */
    int			positiveY;
    int			wheelYDistance;
    int			wheelXDistance;
    Bool		autoProbe;
    checkMovementsProc  checkMovements;
    autoProbeProc	autoProbeMouse;
    collectDataProc	collectData;
    dataGoodProc	dataGood;
    int			angleOffset;
    pointer		pDragLock;	/* drag lock area */
} MouseDevRec, *MouseDevPtr;

/* Z axis mapping */
#define MSE_NOZMAP	0
#define MSE_MAPTOX	-1
#define MSE_MAPTOY	-2
#define MSE_MAPTOZ	-3
#define MSE_MAPTOW	-4

/* Generalize for other axes. */
#define MSE_NOAXISMAP	MSE_NOZMAP

#define MSE_MAXBUTTONS	12
#define MSE_DFLTBUTTONS	 3

#endif /* _XF86OSMOUSE_H_ */

--- NEW FILE: xf86OSpriv.h ---
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86OSpriv.h,v 1.6 2003/08/24 17:37:03 dawes Exp $ */
/*
 * Copyright (c) 1999-2000 by The XFree86 Project, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of the copyright holder(s)
 * and author(s) shall not be used in advertising or otherwise to promote
 * the sale, use or other dealings in this Software without prior written
 * authorization from the copyright holder(s) and author(s).
 */

#ifndef _XF86OSPRIV_H
#define _XF86OSPRIV_H

typedef pointer (*MapMemProcPtr)(int, unsigned long, unsigned long, int);
typedef void (*UnmapMemProcPtr)(int, pointer, unsigned long);
typedef pointer (*SetWCProcPtr)(int, unsigned long, unsigned long, Bool,
				MessageType);
typedef void (*ProtectMemProcPtr)(int, pointer, unsigned long, Bool); 
typedef void (*UndoWCProcPtr)(int, pointer);
typedef void (*ReadSideEffectsProcPtr)(int, pointer, unsigned long);

typedef struct {
	Bool			initialised;
	MapMemProcPtr		mapMem;
	UnmapMemProcPtr		unmapMem;
	ProtectMemProcPtr	protectMem;
	SetWCProcPtr		setWC;
	UndoWCProcPtr		undoWC;
	ReadSideEffectsProcPtr	readSideEffects;
	Bool			linearSupported;
} VidMemInfo, *VidMemInfoPtr;

void xf86OSInitVidMem(VidMemInfoPtr);

#endif /* _XF86OSPRIV_H */

--- NEW FILE: xf86_OSlib.h ---
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86_OSlib.h,v 3.94 2003/11/03 05:11:51 tsi Exp $ */
/*
 * Copyright 1990, 1991 by Thomas Roell, Dinkelscherben, Germany
 * Copyright 1992 by David Dawes <dawes at XFree86.org>
 * Copyright 1992 by Jim Tsillas <jtsilla at damon.ccs.northeastern.edu>
 * Copyright 1992 by Rich Murphey <Rich at Rice.edu>
 * Copyright 1992 by Robert Baron <Robert.Baron at ernst.mach.cs.cmu.edu>
 * Copyright 1992 by Orest Zborowski <obz at eskimo.com>
 * Copyright 1993 by Vrije Universiteit, The Netherlands
 * Copyright 1993 by David Wexelblat <dwex at XFree86.org>
 * Copyright 1994, 1996 by Holger Veit <Holger.Veit at gmd.de>
 * Copyright 1997 by Takis Psarogiannakopoulos <takis at dpmms.cam.ac.uk>
 * Copyright 1994-2003 by The XFree86 Project, Inc
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the names of the above listed copyright holders 
 * not be used in advertising or publicity pertaining to distribution of 
 * the software without specific, written prior permission.  The above listed
 * copyright holders make no representations about the suitability of this 
 * software for any purpose.  It is provided "as is" without express or 
 * implied warranty.
 *
 * THE ABOVE LISTED COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD 
 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDERS BE 
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

/*
 * The ARM32 code here carries the following copyright:
 *
 * Copyright 1997
 * Digital Equipment Corporation. All rights reserved.
 * This software is furnished under license and may be used and copied only in 
 * accordance with the following terms and conditions.  Subject to these
 * conditions, you may download, copy, install, use, modify and distribute
 * this software in source and/or binary form. No title or ownership is
 * transferred hereby.
 *
 * 1) Any source code used, modified or distributed must reproduce and retain
 *    this copyright notice and list of conditions as they appear in the
 *    source file.
 *
 * 2) No right is granted to use any trade name, trademark, or logo of Digital 
 *    Equipment Corporation. Neither the "Digital Equipment Corporation"
 *    name nor any trademark or logo of Digital Equipment Corporation may be
 *    used to endorse or promote products derived from this software without
 *    the prior written permission of Digital Equipment Corporation.
 *
 * 3) This software is provided "AS-IS" and any express or implied warranties,
 *    including but not limited to, any implied warranties of merchantability,
 *    fitness for a particular purpose, or non-infringement are disclaimed.
 *    In no event shall DIGITAL be liable for any damages whatsoever, and in
 *    particular, DIGITAL shall not be liable for special, indirect,
 *    consequential, or incidental damages or damages for lost profits, loss
 *    of revenue or loss of use, whether such damages arise in contract, 
 *    negligence, tort, under statute, in equity, at law or otherwise, even
 *    if advised of the possibility of such damage. 
 *
 */

/* $XConsortium: xf86_OSlib.h /main/22 1996/10/27 11:06:31 kaleb $ */

/*
 * This is private, and should not be included by any drivers.  Drivers
 * may include xf86_OSproc.h to get prototypes for public interfaces.
 */

#ifndef _XF86_OSLIB_H
#define _XF86_OSLIB_H

#include <X11/Xos.h>
#include <X11/Xfuncproto.h>

/*
 * Define some things from the "ANSI" C wrappers that are needed in the
 * the core server.
 */
#ifndef HAVE_WRAPPER_DECLS
#define HAVE_WRAPPER_DECLS
#undef usleep
#define usleep(a) xf86usleep(a)
extern void xf86usleep(unsigned long);
extern int xf86getpagesize(void);
extern int xf86GetErrno(void);  
typedef unsigned long xf86size_t;
typedef signed long xf86ssize_t;
#endif

#include <stdio.h>
#include <ctype.h>
#include <stddef.h>

/**************************************************************************/
/* SYSV386 (SVR3, SVR4) - But not Solaris8                                */
/**************************************************************************/
#if (defined(SYSV) || defined(SVR4)) && \
    !defined(DGUX) && !defined(sgi) && \
    !defined(__SOL8__) && \
    (!defined(sun) || defined(i386))
# ifdef SCO325
#  ifndef _SVID3
#   define _SVID3
#  endif
#  ifndef _NO_STATIC
#   define _NO_STATIC
#  endif
# endif
# include <sys/ioctl.h>
# include <signal.h>
# include <termio.h>
# include <sys/stat.h>
# include <sys/types.h>
# if defined(SCO) || defined(ISC)
# include <sys/param.h>
# endif

# ifdef ISC
#  define TIOCMSET (TIOC|26)	/* set all modem bits */
#  define TIOCMBIS (TIOC|27)	/* bis modem bits */
#  define TIOCMBIC (TIOC|28)	/* bic modem bits */
#  define TIOCMGET (TIOC|29)	/* get all modem bits */
# endif

# include <errno.h>

# if defined(PowerMAX_OS)
#  define HAS_USL_VTS
#  include <sys/immu.h>
#  include <sys/sysmacros.h>
# elif defined(_NEED_SYSI86)
#  include <sys/immu.h>
#  if !(defined (sun) && defined (i386) && defined (SVR4))
#    include <sys/region.h>
#  endif
#  include <sys/proc.h>
#  include <sys/tss.h>
#  include <sys/sysi86.h>
#  if defined(SVR4) && !defined(sun)
#   include <sys/seg.h>
#  endif /* SVR4 && !sun */
#  if defined(sun) && defined (i386) && defined (SVR4) 	/* Solaris? */
#   if !defined(V86SC_IOPL)				/* Solaris 7? */
#    include <sys/v86.h>				/* Nope */
#   endif /* V86SC_IOPL */
#  else 
#   include <sys/v86.h>					/* Not solaris */
#  endif /* sun && i386 && SVR4 */
#  if defined(sun) && defined (i386) && defined (SVR4)
#    include <sys/psw.h>
#  endif
# endif /* _NEED_SYSI86 */

# if defined(HAS_SVR3_MMAPDRV)
#  include <sys/sysmacros.h>
#  if !defined(_NEED_SYSI86)
#   include <sys/immu.h>
#   include <sys/region.h>
#  endif
#  include <sys/mmap.h>		/* MMAP driver header */
# endif

# if !defined(sun) || !defined(sparc)
#  define HAS_USL_VTS
# endif
# if !defined(sun)
#  include <sys/emap.h>
# endif
# if defined(SCO)
#  include <sys/vtkd.h>
#  include <sys/console.h>
#  include <sys/scankbd.h>
#  include <sys/vid.h>
#  define LED_CAP CLKED
#  define LED_NUM NLKED
#  define LED_SCR SLKED
# elif defined(HAS_USL_VTS)
#  include <sys/at_ansi.h>
#  include <sys/kd.h>
#  include <sys/vt.h>
# endif /* SCO */

# if !defined(VT_ACKACQ)
#  define VT_ACKACQ 2
# endif /* !VT_ACKACQ */

# if defined(SCO)
#  include <sys/sysmacros.h>
#  define POSIX_TTY
# endif /* SCO */

# if defined(SVR4) || defined(SCO325)
#  include <sys/mman.h>
#  if !(defined(sun) && defined (i386) && defined (SVR4))
#    define DEV_MEM "/dev/pmem"
#  elif defined(PowerMAX_OS)
#    define DEV_MEM "/dev/iomem"
#  endif
#  ifdef SCO325
#   undef DEV_MEM
#   define DEV_MEM "/dev/mem"
#  endif
#  define CLEARDTR_SUPPORT
#  define POSIX_TTY
# endif /* SVR4 */

# ifdef ISC
#  include <termios.h>
#  define POSIX_TTY
# endif

# if defined(sun) && defined (i386) && defined (SVR4)
#  define USE_VT_SYSREQ
#  define VT_SYSREQ_DEFAULT TRUE
# endif

# if defined(ATT) && !defined(i386)
#  define i386 /* not defined in ANSI C mode */
# endif /* ATT && !i386 */

# if (defined(ATT) || defined(SVR4)) && !defined(sun) && !defined(SCO325)
#  ifndef XQUEUE
#   define XQUEUE
#  endif
#  include <sys/xque.h>
# endif /* ATT || SVR4 */

# ifdef SYSV
#  if !defined(ISC) || defined(ISC202) || defined(ISC22)
#   define NEED_STRERROR
#  endif
# endif

#endif /* (SYSV || SVR4) && !DGUX */

/**********
 * Good ol' Solaris8, and its lack of VT support 
 ***********/

#if defined(__SOL8__) || (defined(sun) && !defined(i386))
# include <sys/mman.h>
# include <errno.h>
# ifdef i386
#  include <sys/sysi86.h>
# endif
# include <sys/psw.h>

# include <termio.h>
# include <sys/fbio.h>
# include <sys/kbd.h>
# include <sys/kbio.h>

# define LED_CAP LED_CAPS_LOCK
# define LED_NUM LED_NUM_LOCK
# define LED_SCR LED_SCROLL_LOCK

# include <signal.h>

#endif /* __SOL8__ */



/**************************************************************************/
/* DG/ux R4.20MU03 Intel AViion Machines                                  */
/**************************************************************************/
#if defined(DGUX) && defined(SVR4)
#include <sys/ioctl.h>
#include <signal.h>
#include <ctype.h>
#include <termios.h>      /* Use termios for BSD Flavor ttys */
#include <sys/termios.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/param.h>
#include <errno.h>
#include <sys/sysi86.h>
#include <unistd.h>
#include <sys/proc.h>
#include <sys/map.h>
#include <sys/sysmacros.h>
#include <sys/mman.h>       /* Memory handling */
#include <sys/kd.h>       /* definitios for KDENABIO KDDISABIO needed for IOPL s */
#include <sys/kbd.h>
#include <fcntl.h>
#include <time.h>
#include <sys/stream.h>
#include <sys/ptms.h>

#include <sys/socket.h>
#include <sys/utsname.h>
#include <sys/stropts.h>
#include <sys/sockio.h>


#define POSIX_TTY

#undef HAS_USL_VTS
#undef USE_VT_SYSREQ
#undef VT_ACKACQ

#define LED_CAP KBD_LED_CAPS_LOCK
#define LED_NUM KBD_LED_NUM_LOCK
#define LED_SCR KBD_LED_SCROLL_LOCK

#define KDGKBTYPE KBD_GET_LANGUAGE


/* General keyboard types */
# define KB_84          2
# define KB_101         1  /* Because ioctl(dgkeybdFd,KBD_GET_LANGUAGE,&type) gives 1=US keyboard */
# define KB_OTHER       3

#define KDSETLED KBD_SET_LED
#define KDGETLED KBD_GET_STATE
#undef KDMKTONE
#define KDMKTONE KBD_TONE_HIGH


#undef DEV_MEM
#define DEV_MEM "/dev/mem"
#define CLEARDTR_SUPPORT

#undef  VT_SYSREQ_DEFAULT
#define VT_SYSREQ_DEFAULT FALSE        /* Make sure that we dont define any VTs since DG/ux has none */

#endif /* DGUX && SVR4 */

/**************************************************************************/
/* Linux                                                                  */
/**************************************************************************/
#if defined(linux)
# include <sys/ioctl.h>
# include <signal.h>
# include <termio.h>
# ifdef __sparc__
#  include <sys/param.h>
# endif

# include <errno.h>

# include <sys/stat.h>

# define HAS_USL_VTS
# include <sys/mman.h>
# include <sys/kd.h>
# include <sys/vt.h>
# define LDGMAP GIO_SCRNMAP
# define LDSMAP PIO_SCRNMAP
# define LDNMAP LDSMAP

# define CLEARDTR_SUPPORT
# define USE_VT_SYSREQ

# define POSIX_TTY

#endif /* linux */

/**************************************************************************/
/* LynxOS AT                                                              */
/**************************************************************************/
#if defined(Lynx)
 
# include <termio.h>
# include <sys/ioctl.h>
# include <param.h>
# include <signal.h>
# include <kd.h>
# include <vt.h>
# include <sys/stat.h>

# include <errno.h>
extern int errno;
 
/* smem_create et.al. to access physical memory */ 
# include <smem.h>
 
/* keyboard types */
# define KB_84		1
# define KB_101 	2
# define KB_OTHER	3

/* atc drivers ignores argument to VT_RELDISP ioctl */
# define VT_ACKACQ	2

# include <termios.h>
# define POSIX_TTY
# define CLEARDTR_SUPPORT

/* LynxOS 2.5.1 has these */
# ifdef LED_NUMLOCK
#  define LED_CAP	LED_CAPSLOCK
#  define LED_NUM	LED_NUMLOCK
#  define LED_SCR	LED_SCROLLOCK
# endif

#endif /* Lynx */

/**************************************************************************/
/* 386BSD and derivatives,  BSD/386                                       */
/**************************************************************************/

#if defined(__386BSD__) && (defined(__FreeBSD__) || defined(__NetBSD__))
# undef __386BSD__
#endif

#ifdef CSRG_BASED
# include <sys/ioctl.h>
# include <signal.h>

# include <termios.h>
# define termio termios
# define POSIX_TTY

# include <errno.h>

# if !defined(LINKKIT)
  /* Don't need this stuff for the Link Kit */
#  if defined(__bsdi__)
#   include <i386/isa/pcconsioctl.h>
#   define CONSOLE_X_MODE_ON PCCONIOCRAW
#   define CONSOLE_X_MODE_OFF PCCONIOCCOOK
#   define CONSOLE_X_BELL PCCONIOCBEEP
#  else /* __bsdi__ */
#   if defined(__OpenBSD__)
#     ifdef PCCONS_SUPPORT
#       include <machine/pccons.h>
#       undef CONSOLE_X_MODE_ON
#       undef CONSOLE_X_MODE_OFF
#       undef CONSOLE_X_BELL
#     endif
#   endif
#   ifdef SYSCONS_SUPPORT
#    define COMPAT_SYSCONS
#    if defined(__NetBSD__) || defined(__OpenBSD__)
#     include <machine/console.h>
#    else
#     if defined(__FreeBSD__)
#        include <osreldate.h>
#        if __FreeBSD_version >= 410000
#          include <sys/consio.h>
#          include <sys/kbio.h>
#        else
#          include <machine/console.h>
#        endif /* FreeBSD 4.1 RELEASE or lator */
#     else
#      include <sys/console.h>
#     endif
#    endif
#   endif /* SYSCONS_SUPPORT */
#   if defined(PCVT_SUPPORT)
#    if !defined(SYSCONS_SUPPORT)
      /* no syscons, so include pcvt specific header file */
#     if defined(__FreeBSD__)
#      include <machine/pcvt_ioctl.h>
#     else
#      if defined(__NetBSD__) || defined(__OpenBSD__)
#       if !defined(WSCONS_SUPPORT)
#        include <machine/pcvt_ioctl.h>
#       endif /* WSCONS_SUPPORT */
#      else
#       include <sys/pcvt_ioctl.h>
#      endif /* __NetBSD__ */
#     endif /* __FreeBSD__ || __OpenBSD__ */
#    else /* pcvt and syscons: hard-code the ID magic */
#     define VGAPCVTID _IOWR('V',113, struct pcvtid)
      struct pcvtid {
	char name[16];
	int rmajor, rminor;
      };
#    endif /* PCVT_SUPPORT && SYSCONS_SUPPORT */
#   endif /* PCVT_SUPPORT */
#   ifdef WSCONS_SUPPORT
#    include <dev/wscons/wsconsio.h>
#    include <dev/wscons/wsdisplay_usl_io.h>
#   endif /* WSCONS_SUPPORT */
#   if defined(__FreeBSD__)
#    include <osreldate.h>
#    if __FreeBSD_version >= 500013
#     include <sys/mouse.h>
#    else
#     undef MOUSE_GETINFO
#     include <machine/mouse.h>
#    endif
#   endif
    /* Include these definitions in case ioctl_pc.h didn't get included */
#   ifndef CONSOLE_X_MODE_ON
#    define CONSOLE_X_MODE_ON _IO('t',121)
#   endif
#   ifndef CONSOLE_X_MODE_OFF
#    define CONSOLE_X_MODE_OFF _IO('t',122)
#   endif
#   ifndef CONSOLE_X_BELL
#    define CONSOLE_X_BELL _IOW('t',123,int[2])
#   endif
#   ifndef CONSOLE_X_TV_ON
#    define CONSOLE_X_TV_ON _IOW('t',155,int)
#    define XMODE_RGB   0
#    define XMODE_NTSC  1
#    define XMODE_PAL   2
#    define XMODE_SECAM 3
#   endif
#   ifndef CONSOLE_X_TV_OFF
#    define CONSOLE_X_TV_OFF _IO('t',156)
#   endif
#ifndef CONSOLE_GET_LINEAR_INFO
#    define CONSOLE_GET_LINEAR_INFO         _IOR('t',157,struct map_info)
#endif
#ifndef CONSOLE_GET_IO_INFO 
#    define CONSOLE_GET_IO_INFO             _IOR('t',158,struct map_info)
#endif
#ifndef CONSOLE_GET_MEM_INFO 
#    define CONSOLE_GET_MEM_INFO            _IOR('t',159,struct map_info)
#endif
#  endif /* __bsdi__ */
# endif /* !LINKKIT */

# include <sys/types.h>
# include <sys/mman.h>
# include <sys/stat.h>

# if defined(__bsdi__)
#  include <sys/param.h>
# if (_BSDI_VERSION < 199510)
#  include <i386/isa/vgaioctl.h>
# endif
# endif /* __bsdi__ */

#ifdef USE_I386_IOPL
#include <machine/sysarch.h>
#endif

# define CLEARDTR_SUPPORT

# if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
#  define USE_VT_SYSREQ
# endif

#endif /* CSRG_BASED */

/**************************************************************************/
/* OS/2                                                                   */
/**************************************************************************/
/* currently OS/2 with a modified EMX/GCC compiler only */
#if defined(__UNIXOS2__) 
# include <signal.h>
# include <errno.h>
# include <sys/stat.h>

/* I would have liked to have this included here always, but
 * it causes clashes for BYTE and BOOL with Xmd.h, which is too dangerous. 
 * So I'll include it in place where I know it does no harm.
 */
#if defined(I_NEED_OS2_H)
# undef BOOL
# undef BYTE
# include <os2.h>
#endif

  /* keyboard types */
# define KB_84                   1
# define KB_101                  2
/* could detect more keyboards */
# define KB_OTHER                3

  /* LEDs */
#  define LED_CAP 0x40
#  define LED_NUM 0x20
#  define LED_SCR 0x10

  /* mouse driver */
# define OSMOUSE_ONLY
# define MOUSE_PROTOCOL_IN_KERNEL

extern char* __XOS2RedirRoot(char*);

#endif

/**************************************************************************/
/* QNX4                                                                   */
/**************************************************************************/
/* This is the QNX code for Watcom 10.6 and QNX 4.x */
#if defined(QNX4)
#include <signal.h>
#include <errno.h>
#include <sys/stat.h>
#include <termios.h>
#include <ioctl.h>
#include <sys/param.h>

/* Warning: by default, the fd_set size is 32 in QNX!  */
#define FD_SETSIZE 256
#include <sys/select.h>

  /* keyboard types */
# define KB_84                   1
# define KB_101                  2
# define KB_OTHER                3

  /* LEDs */
#  define LED_CAP 0x04
#  define LED_NUM 0x02
#  define LED_SCR 0x01

# define POSIX_TTY
# define OSMOUSE_ONLY
# define MOUSE_PROTOCOL_IN_KERNEL

#define TIOCM_DTR       0x0001            /* data terminal ready */
#define TIOCM_RTS       0x0002            /* request to send */
#define TIOCM_CTS       0x1000            /* clear to send */
#define TIOCM_DSR       0x2000            /* data set ready */
#define TIOCM_RI        0x4000            /* ring */
#define TIOCM_RNG       TIOCM_RI
#define TIOCM_CD        0x8000            /* carrier detect */
#define TIOCM_CAR       TIOCM_CD
#define TIOCM_LE        0x0100            /* line enable */
#define TIOCM_ST        0x0200            /* secondary transmit */
#define TIOCM_SR        0x0400            /* secondary receive */

#endif

/**************************************************************************/
/* QNX/Neutrino                                                           */
/**************************************************************************/
/* This is the Neutrino code for for NTO2.0 and GCC */
#if defined(__QNXNTO__)
#include <signal.h>
#include <errno.h>
#include <sys/stat.h>
#include <termios.h>
#include <ioctl.h>
#include <sys/param.h>

/* Warning: by default, the fd_set size is 32 in NTO!  */
#define FD_SETSIZE 256
#include <sys/select.h>

  /* keyboard types */
# define KB_84                   1
# define KB_101                  2
# define KB_OTHER                3

# define POSIX_TTY

#endif

/**************************************************************************/
/* GNU/Hurd								  */
/**************************************************************************/
#if defined(__GNU__)

#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <sys/stat.h>
#include <assert.h>

#define POSIX_TTY
#define USE_OSMOUSE

#endif /* __GNU__ */

/**************************************************************************/
/* IRIX                                                                   */
/**************************************************************************/
#if defined(sgi)

#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>

#endif

/**************************************************************************/
/* Generic                                                                */
/**************************************************************************/

#include <sys/wait.h>	/* May need to adjust this for other OSs */

/* 
 * Hack originally for ISC 2.2 POSIX headers, but may apply elsewhere,
 * and it's safe, so just do it.
 */
#if !defined(O_NDELAY) && defined(O_NONBLOCK)
# define O_NDELAY O_NONBLOCK
#endif /* !O_NDELAY && O_NONBLOCK */

#if !defined(MAXHOSTNAMELEN)
# define MAXHOSTNAMELEN 32
#endif /* !MAXHOSTNAMELEN */

#if !defined(X_NOT_POSIX)
# if defined(_POSIX_SOURCE)
#  include <limits.h>
# else
#  define _POSIX_SOURCE
#  include <limits.h>
#  undef _POSIX_SOURCE
# endif /* _POSIX_SOURCE */
#endif /* !X_NOT_POSIX */
#if !defined(PATH_MAX)
# if defined(MAXPATHLEN)
#  define PATH_MAX MAXPATHLEN
# else
#  define PATH_MAX 1024
# endif /* MAXPATHLEN */
#endif /* !PATH_MAX */

#ifdef NEED_STRERROR
# ifndef strerror
extern char *sys_errlist[];
extern int sys_nerr;
#  define strerror(n) \
     ((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error"
# endif /* !strerror */
#endif /* NEED_STRERROR */

#if defined(ISC) || defined(Lynx)
#define rint(x) RInt(x)
double RInt(
	double x
);
#endif

#ifndef DEV_MEM
#define DEV_MEM "/dev/mem"
#endif

#ifndef VT_SYSREQ_DEFAULT
#define VT_SYSREQ_DEFAULT FALSE
#endif

#ifdef OSMOUSE_ONLY
# ifndef MOUSE_PROTOCOL_IN_KERNEL
#  define MOUSE_PROTOCOL_IN_KERNEL
# endif
#endif

#define SYSCALL(call) while(((call) == -1) && (errno == EINTR))

#define XF86_OS_PRIVS
#include "xf86_OSproc.h"

#ifndef NO_COMPILER_H
#include "compiler.h"
#endif

#endif /* _XF86_OSLIB_H */

--- NEW FILE: xf86_OSproc.h ---
/*
 * Copyright 1990, 1991 by Thomas Roell, Dinkelscherben, Germany
 * Copyright 1992 by David Dawes <dawes at XFree86.org>
 * Copyright 1992 by Jim Tsillas <jtsilla at damon.ccs.northeastern.edu>
 * Copyright 1992 by Rich Murphey <Rich at Rice.edu>
 * Copyright 1992 by Robert Baron <Robert.Baron at ernst.mach.cs.cmu.edu>
 * Copyright 1992 by Orest Zborowski <obz at eskimo.com>
 * Copyright 1993 by Vrije Universiteit, The Netherlands
 * Copyright 1993 by David Wexelblat <dwex at XFree86.org>
 * Copyright 1994, 1996 by Holger Veit <Holger.Veit at gmd.de>
 * Copyright 1994-2003 by The XFree86 Project, Inc
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the names of the above listed copyright holders 
 * not be used in advertising or publicity pertaining to distribution of 
 * the software without specific, written prior permission.  The above listed
 * copyright holders make no representations about the suitability of this 
 * software for any purpose.  It is provided "as is" without express or 
 * implied warranty.
 *
 * THE ABOVE LISTED COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD 
 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDERS BE 
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

/*
 * The ARM32 code here carries the following copyright:
 *
 * Copyright 1997
 * Digital Equipment Corporation. All rights reserved.
 * This software is furnished under license and may be used and copied only in 
 * accordance with the following terms and conditions.  Subject to these
 * conditions, you may download, copy, install, use, modify and distribute
 * this software in source and/or binary form. No title or ownership is
 * transferred hereby.
 *
 * 1) Any source code used, modified or distributed must reproduce and retain
 *    this copyright notice and list of conditions as they appear in the
 *    source file.
 *
 * 2) No right is granted to use any trade name, trademark, or logo of Digital 
 *    Equipment Corporation. Neither the "Digital Equipment Corporation"
 *    name nor any trademark or logo of Digital Equipment Corporation may be
 *    used to endorse or promote products derived from this software without
 *    the prior written permission of Digital Equipment Corporation.
 *
 * 3) This software is provided "AS-IS" and any express or implied warranties,
 *    including but not limited to, any implied warranties of merchantability,
 *    fitness for a particular purpose, or non-infringement are disclaimed.
 *    In no event shall DIGITAL be liable for any damages whatsoever, and in
 *    particular, DIGITAL shall not be liable for special, indirect,
 *    consequential, or incidental damages or damages for lost profits, loss
 *    of revenue or loss of use, whether such damages arise in contract, 
 *    negligence, tort, under statute, in equity, at law or otherwise, even
 *    if advised of the possibility of such damage. 
 *
 */

/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h,v 3.56 2003/08/24 17:37:03 dawes Exp $ */

#ifndef _XF86_OSPROC_H
#define _XF86_OSPROC_H

#ifdef XF86_OS_PRIVS
#include "xf86Pci.h"
#endif

/*
 * The actual prototypes have been pulled into this seperate file so
 * that they can can be used without pulling in all of the OS specific
 * stuff like sys/stat.h, etc. This casues problem for loadable modules.
 */ 

/*
 * Flags for xf86MapVidMem().  Multiple flags can be or'd together.  The
 * flags may be used as hints.  For example it would be permissible to
 * enable write combining for memory marked only for framebuffer use.
 */

#define VIDMEM_FRAMEBUFFER	0x01	/* memory for framebuffer use */
#define VIDMEM_MMIO		0x02	/* memory for I/O use */
#define VIDMEM_MMIO_32BIT	0x04	/* memory accesses >= 32bit */
#define VIDMEM_READSIDEEFFECT	0x08	/* reads can have side-effects */
#define VIDMEM_SPARSE		0x10	/* sparse mapping required
					 * assumed when VIDMEM_MMIO is
					 * set. May be used with
					 * VIDMEM_FRAMEBUFFER) */
#define VIDMEM_READONLY		0x20	/* read-only mapping
					 * used when reading BIOS images
					 * through xf86MapVidMem() */

/*
 * OS-independent modem state flags for xf86SetSerialModemState() and
 * xf86GetSerialModemState().
 */
#define XF86_M_LE		0x001	/* line enable */
#define XF86_M_DTR		0x002	/* data terminal ready */
#define XF86_M_RTS		0x004	/* request to send */
#define XF86_M_ST		0x008	/* secondary transmit */
#define XF86_M_SR		0x010	/* secondary receive */
#define XF86_M_CTS		0x020	/* clear to send */
#define XF86_M_CAR		0x040	/* carrier detect */
#define XF86_M_RNG		0x080	/* ring */
#define XF86_M_DSR		0x100	/* data set ready */

#ifdef XF86_OS_PRIVS
extern void xf86WrapperInit(void);
#endif

#ifndef NO_OSLIB_PROTOTYPES
/*
 * This is to prevent re-entrancy to FatalError() when aborting.
 * Anything that can be called as a result of AbortDDX() should use this
 * instead of FatalError().
 */

#define xf86FatalError(a, b) \
	if (dispatchException & DE_TERMINATE) { \
		ErrorF(a, b); \
		ErrorF("\n"); \
		return; \
	} else FatalError(a, b)

/***************************************************************************/
/* Prototypes                                                              */
/***************************************************************************/

#include <X11/Xfuncproto.h>
#include "opaque.h"

_XFUNCPROTOBEGIN

/* public functions */
extern Bool xf86LinearVidMem(void);
extern Bool xf86CheckMTRR(int); 
extern pointer xf86MapVidMem(int, int, unsigned long, unsigned long);
extern void xf86UnMapVidMem(int, pointer, unsigned long);
extern void xf86MapReadSideEffects(int, int, pointer, unsigned long);
extern int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *, int);
extern void xf86EnableIO(void);
extern void xf86DisableIO(void);
extern Bool xf86DisableInterrupts(void);
extern void xf86EnableInterrupts(void);
extern void xf86SetTVOut(int);
extern void xf86SetRGBOut(void);
extern void xf86SoundKbdBell(int, int, int);
#if defined(QNX4)
#pragma aux xf86BusToMem modify [eax ebx ecx edx esi edi];
#pragma aux xf86MemToBus modify [eax ebx ecx edx esi edi];
#endif
extern void xf86BusToMem(unsigned char *, unsigned char *, int);
extern void xf86MemToBus(unsigned char *, unsigned char *, int);
extern void xf86IODelay(void);
extern void xf86UDelay(long usec);
extern void xf86SlowBcopy(unsigned char *, unsigned char *, int);
extern int xf86OpenSerial(pointer options);
extern int xf86SetSerial(int fd, pointer options);
extern int xf86SetSerialSpeed(int fd, int speed);
extern int xf86ReadSerial(int fd, void *buf, int count);
extern int xf86WriteSerial(int fd, const void *buf, int count);
extern int xf86CloseSerial(int fd);
extern int xf86FlushInput(int fd);
extern int xf86WaitForInput(int fd, int timeout);
extern int xf86SerialSendBreak(int fd, int duration);
extern int xf86SetSerialModemState(int fd, int state);
extern int xf86GetSerialModemState(int fd);
extern int xf86SerialModemSetBits(int fd, int bits);
extern int xf86SerialModemClearBits(int fd, int bits);
extern int xf86LoadKernelModule(const char *pathname);

/* AGP GART interface */

typedef struct _AgpInfo {
	CARD32		bridgeId;
	CARD32		agpMode;
	unsigned long	base;
	unsigned long	size;
	unsigned long	totalPages;
	unsigned long	systemPages;
	unsigned long	usedPages;
} AgpInfo, *AgpInfoPtr;

extern Bool xf86AgpGARTSupported(void);
extern AgpInfoPtr xf86GetAGPInfo(int screenNum);
extern Bool xf86AcquireGART(int screenNum);
extern Bool xf86ReleaseGART(int screenNum);
extern int xf86AllocateGARTMemory(int screenNum, unsigned long size, int type,
				  unsigned long *physical);
extern Bool xf86BindGARTMemory(int screenNum, int key, unsigned long offset);
extern Bool xf86UnbindGARTMemory(int screenNum, int key);
extern Bool xf86EnableAGP(int screenNum, CARD32 mode);
extern Bool xf86GARTCloseScreen(int screenNum);

/* These routines are in shared/sigio.c and are not loaded as part of the
   module.  These routines are small, and the code if very POSIX-signal (or
   OS-signal) specific, so it seemed better to provide more complex
   wrappers than to wrap each individual function called. */
extern int xf86InstallSIGIOHandler(int fd, void (*f)(int, void *), void *);
extern int xf86RemoveSIGIOHandler(int fd);
extern int xf86BlockSIGIO (void);
extern void xf86UnblockSIGIO (int);
#ifdef XFree86Server
extern void xf86AssertBlockedSIGIO (char *);
#endif
extern Bool xf86SIGIOSupported (void);

#ifdef XF86_OS_PRIVS
typedef void (*PMClose)(void);
extern void xf86OpenConsole(void);
extern void xf86CloseConsole(void);
extern Bool xf86VTSwitchPending(void);
extern Bool xf86VTSwitchAway(void);
extern Bool xf86VTSwitchTo(void);
extern void xf86VTRequest(int sig);
extern int xf86ProcessArgument(int, char **, int);
extern void xf86UseMsg(void);
extern void xf86SetKbdLeds(int);
extern int xf86GetKbdLeds(void);
extern void xf86SetKbdRepeat(char);
extern void xf86KbdInit(void);
extern int xf86KbdOn(void);
extern int xf86KbdOff(void);
extern void xf86KbdEvents(void);
#ifdef XQUEUE
extern int  xf86XqueKbdProc(DeviceIntPtr, int);
extern void xf86XqueEvents(void);
#endif
#ifdef WSCONS_SUPPORT
extern void xf86WSKbdEvents(void);
#endif
extern PMClose xf86OSPMOpen(void);

#ifdef NEED_OS_RAC_PROTOS
/* RAC-related privs */
/* internal to os-support layer */
resPtr xf86StdBusAccWindowsFromOS(void);
resPtr xf86StdPciAccWindowsFromOS(void);
resPtr xf86StdIsaAccWindowsFromOS(void);
resPtr xf86StdAccResFromOS(resPtr ret);

/* available to the common layer */
resPtr xf86BusAccWindowsFromOS(void);
resPtr xf86PciBusAccWindowsFromOS(void);
#ifdef INCLUDE_UNUSED
resPtr xf86IsaBusAccWindowsFromOS(void);
#endif
resPtr xf86AccResFromOS(resPtr ret);
#endif /* NEED_OS_RAC_PROTOS */

extern Bool xf86GetPciSizeFromOS(PCITAG tag, int indx, int* bits);

extern void xf86MakeNewMapping(int, int, unsigned long, unsigned long, pointer);
extern void xf86InitVidMem(void);

#endif /* XF86_OS_PRIVS */


_XFUNCPROTOEND
#endif /* NO_OSLIB_PROTOTYPES */

#endif /* _XF86_OSPROC_H */

--- NEW FILE: xf86_ansic.h ---
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h,v 3.53 2003/10/28 18:36:37 tsi Exp $ */
/*
 * Copyright 1997-2003 by The XFree86 Project, Inc
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the names of the above listed copyright holders 
 * not be used in advertising or publicity pertaining to distribution of 
 * the software without specific, written prior permission.  The above listed
 * copyright holders make no representations about the suitability of this 
 * software for any purpose.  It is provided "as is" without express or 
 * implied warranty.
 *
 * THE ABOVE LISTED COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD 
 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDERS BE 
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#ifndef _XF86_ANSIC_H
#define _XF86_ANSIC_H

/* Handle <stdarg.h> */

#ifndef IN_MODULE
# include <stdarg.h>
#else /* !IN_MODULE */
# ifndef __OS2ELF__
#  include <stdarg.h>
# else /* __OS2ELF__ */
   /* EMX/gcc_elf under OS/2 does not have native header files */
#  if !defined (_VA_LIST)
#   define _VA_LIST
    typedef char *va_list;
#  endif
#  define _VA_ROUND(t) ((sizeof (t) + 3) & -4)
#  if !defined (va_start)
#   define va_start(ap,v) ap = (va_list)&v + ((sizeof (v) + 3) & -4)
#   define va_end(ap) (ap = 0, (void)0)
#   define va_arg(ap,t) (ap += _VA_ROUND (t), *(t *)(ap - _VA_ROUND (t)))
#  endif
# endif /* __OS2ELF__ */
#endif /* IN_MODULE */

/*
 * The first set of definitions are required both for modules and
 * libc_wrapper.c.
 */

#if defined(XFree86LOADER) || defined(NEED_XF86_TYPES)

#if !defined(SYSV) && !defined(SVR4) && !defined(Lynx) || defined(SCO)  
#define HAVE_VSSCANF
#define HAVE_VFSCANF
#endif 

#ifndef NULL
#if (defined(SVR4) || defined(SYSV)) && !defined(__GNUC__)
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
#ifndef EOF
#define EOF (-1)
#endif

#ifndef PATH_MAX
#define PATH_MAX 1024
#endif

/* <limits.h> stuff */
#define x_BITSPERBYTE 8
#define x_BITS(type)  (x_BITSPERBYTE * (int)sizeof(type))
#define x_SHORTBITS x_BITS(short)
#define x_INTBITS x_BITS(int)
#define x_LONGBITS x_BITS(long)
#ifndef SHRT_MIN
#define SHRT_MIN ((short)(1 << (x_SHORTBITS - 1)))
#endif

#ifndef FONTMODULE
#include "misc.h"
#endif
#include "xf86_libc.h"
#ifndef SHRT_MAX
#define SHRT_MAX ((short)~SHRT_MIN)
#endif
#ifndef USHRT_MAX
#define USHRT_MAX ((unsigned short)~0)
#endif
#ifndef MINSHORT
#define MINSHORT SHRT_MIN
#endif
#ifndef MAXSHORT
#define MAXSHORT SHRT_MAX
#endif
#ifndef INT_MIN
#define INT_MIN (1 << (x_INTBITS - 1))
#endif
#ifndef INT_MAX
#define INT_MAX (~INT_MIN)
#endif
#ifndef UINT_MAX
#define UINT_MAX (~0)
#endif
#ifndef MININT
#define MININT INT_MIN
#endif
#ifndef MAXINT
#define MAXINT INT_MAX
#endif
#ifndef LONG_MIN
#define LONG_MIN ((long)(1 << (x_LONGBITS - 1)))
#endif
#ifndef LONG_MAX
#define LONG_MAX ((long)~LONG_MIN)
#endif
#ifndef ULONG_MAX
#define ULONG_MAX ((unsigned long)~0UL)
#endif
#ifndef MINLONG
#define MINLONG LONG_MIN
#endif
#ifndef MAXLONG
#define MAXLONG LONG_MAX
#endif

#endif /* XFree86LOADER || NEED_XF86_TYPES */

#if defined(XFree86LOADER) || defined(NEED_XF86_PROTOTYPES)
/*
 * ANSI C compilers only.
 */

/* ANSI C emulation library */

extern void xf86abort(void);
extern int xf86abs(int);
extern double xf86acos(double);
extern double xf86asin(double);
extern double xf86atan(double);
extern double xf86atan2(double,double);
extern double xf86atof(const char*);
extern int xf86atoi(const char*);
extern long xf86atol(const char*);
extern void *xf86bsearch(const void *, const void *, xf86size_t, xf86size_t,
			 int (*)(const void *, const void *));
extern double xf86ceil(double);
extern void* xf86calloc(xf86size_t,xf86size_t);
extern void xf86clearerr(XF86FILE*);
extern double xf86cos(double);
extern void xf86exit(int);
extern double xf86exp(double);
extern double xf86fabs(double);
extern int xf86fclose(XF86FILE*);
extern int xf86feof(XF86FILE*);
extern int xf86ferror(XF86FILE*);
extern int xf86fflush(XF86FILE*);
extern int xf86fgetc(XF86FILE*);
extern int xf86getc(XF86FILE*);
extern int xf86fgetpos(XF86FILE*,XF86fpos_t*);
extern char* xf86fgets(char*,INT32,XF86FILE*);
extern int xf86finite(double);
extern double xf86floor(double);
extern double xf86fmod(double,double);
extern XF86FILE* xf86fopen(const char*,const char*);
extern double xf86frexp(double, int*);
extern int xf86printf(const char*,...);
extern int xf86fprintf(XF86FILE*,const char*,...);
extern int xf86fputc(int,XF86FILE*);
extern int xf86fputs(const char*,XF86FILE*);
extern xf86size_t xf86fread(void*,xf86size_t,xf86size_t,XF86FILE*);
extern void xf86free(void*);
extern XF86FILE* xf86freopen(const char*,const char*,XF86FILE*);
#if defined(HAVE_VFSCANF) || !defined(NEED_XF86_PROTOTYPES)
extern int xf86fscanf(XF86FILE*,const char*,...);
#else
extern int xf86fscanf(/*XF86FILE*,const char*,char *,char *,char *,char *,
			char *,char *,char *,char *,char *,char * */);
#endif
extern int xf86fseek(XF86FILE*,long,int);
extern int xf86fsetpos(XF86FILE*,const XF86fpos_t*);
extern long xf86ftell(XF86FILE*);
extern xf86size_t xf86fwrite(const void*,xf86size_t,xf86size_t,XF86FILE*);
extern char* xf86getenv(const char*);
extern int xf86isalnum(int);
extern int xf86isalpha(int);
extern int xf86iscntrl(int);
extern int xf86isdigit(int);
extern int xf86isgraph(int);
extern int xf86islower(int);
extern int xf86isprint(int);
extern int xf86ispunct(int);
extern int xf86isspace(int);
extern int xf86isupper(int);
extern int xf86isxdigit(int);
extern long xf86labs(long);
extern double xf86ldexp(double,int);
extern double xf86log(double);
extern double xf86log10(double);
extern void* xf86malloc(xf86size_t);
extern void* xf86memchr(const void*,int,xf86size_t);
extern int xf86memcmp(const void*,const void*,xf86size_t);
extern void* xf86memcpy(void*,const void*,xf86size_t);
extern void* xf86memmove(void*,const void*,xf86size_t);
extern void* xf86memset(void*,int,xf86size_t);
extern double xf86modf(double,double*);
extern void xf86perror(const char*);
extern double xf86pow(double,double);
extern void xf86qsort(void*, xf86size_t, xf86size_t, 
                      int(*)(const void*, const void*));
extern void* xf86realloc(void*,xf86size_t);
extern int xf86remove(const char*);
extern int xf86rename(const char*,const char*);
extern void xf86rewind(XF86FILE*);
extern int xf86setbuf(XF86FILE*,char*);
extern int xf86setvbuf(XF86FILE*,char*,int,xf86size_t);
extern double xf86sin(double);
extern int xf86sprintf(char*,const char*,...);
extern int xf86snprintf(char*,xf86size_t,const char*,...);
extern double xf86sqrt(double);
#if defined(HAVE_VSSCANF) || !defined(NEED_XF86_PROTOTYPES)
extern int xf86sscanf(char*,const char*,...);
#else
extern int xf86sscanf(/*char*,const char*,char *,char *,char *,char *,
			char *,char *,char *,char *,char *,char * */);
#endif
extern char* xf86strcat(char*,const char*);
extern char* xf86strchr(const char*, int c);
extern int xf86strcmp(const char*,const char*);
extern int xf86strcasecmp(const char*,const char*);
extern char* xf86strcpy(char*,const char*);
extern xf86size_t xf86strcspn(const char*,const char*);
extern char* xf86strerror(int);
extern xf86size_t xf86strlcat(char*,const char*,xf86size_t);
extern xf86size_t xf86strlcpy(char*,const char*,xf86size_t);
extern xf86size_t xf86strlen(const char*);
extern char* xf86strncat(char *, const char *, xf86size_t);
extern int xf86strncmp(const char*,const char*,xf86size_t);
extern int xf86strncasecmp(const char*,const char*,xf86size_t);
extern char* xf86strncpy(char*,const char*,xf86size_t);
extern char* xf86strpbrk(const char*,const char*);
extern char* xf86strrchr(const char*,int);
extern xf86size_t xf86strspn(const char*,const char*);
extern char* xf86strstr(const char*,const char*);
extern double xf86strtod(const char*,char**);
extern char* xf86strtok(char*,const char*);
extern long xf86strtol(const char*,char**,int);
extern unsigned long xf86strtoul(const char*,char**,int);
extern double xf86tan(double);
extern XF86FILE* xf86tmpfile(void);
extern char* xf86tmpnam(char*);
extern int xf86tolower(int);
extern int xf86toupper(int);
extern int xf86ungetc(int,XF86FILE*);
extern int xf86vfprintf(XF86FILE*,const char*,va_list);
extern int xf86vsprintf(char*,const char*,va_list);
extern int xf86vsnprintf(char*,xf86size_t,const char*,va_list);

extern int xf86open(const char*, int,...);
extern int xf86close(int);
extern long xf86lseek(int, long, int);
extern int xf86ioctl(int, unsigned long, pointer);
extern xf86ssize_t xf86read(int, void *, xf86size_t);
extern xf86ssize_t xf86write(int, const void *, xf86size_t);
extern void* xf86mmap(void*, xf86size_t, int, int, int, xf86size_t /* off_t */);
extern int xf86munmap(void*, xf86size_t);
extern int xf86stat(const char *, struct xf86stat *);
extern int xf86fstat(int, struct xf86stat *);
extern int xf86access(const char *, int);
extern int xf86errno;
extern int xf86GetErrno(void);

extern double xf86HUGE_VAL;

extern double xf86hypot(double,double);

/* non-ANSI C functions */
extern XF86DIR* xf86opendir(const char*);
extern int xf86closedir(XF86DIR*);
extern XF86DIRENT* xf86readdir(XF86DIR*);
extern void xf86rewinddir(XF86DIR*);
extern void xf86bcopy(const void*,void*,xf86size_t);
extern int xf86ffs(int);
extern char* xf86strdup(const char*);
extern void xf86bzero(void*,unsigned int);
extern int xf86execl(const char *, const char *, ...);
extern long xf86fpossize(void);
extern int xf86chmod(const char *, xf86mode_t);
extern int xf86chown(const char *, xf86uid_t, xf86gid_t);
extern xf86uid_t xf86geteuid(void);
extern xf86gid_t xf86getegid(void);
extern int xf86getpid(void);
extern int xf86mknod(const char *, xf86mode_t, xf86dev_t);
extern int xf86mkdir(const char *, xf86mode_t);
unsigned int xf86sleep(unsigned int seconds);
/* sysv IPC */
extern int xf86shmget(xf86key_t key, int size, int xf86shmflg);
extern char * xf86shmat(int id, char *addr, int xf86shmflg);
extern int xf86shmdt(char *addr);
extern int xf86shmctl(int id, int xf86cmd, pointer buf);

extern int xf86setjmp(xf86jmp_buf env);
extern int xf86setjmp0(xf86jmp_buf env);
extern int xf86setjmp1(xf86jmp_buf env, int);
extern int xf86setjmp1_arg2(void);
extern int xf86setjmperror(xf86jmp_buf env);
extern int xf86getjmptype(void);
extern void xf86longjmp(xf86jmp_buf env, int val);
#define xf86setjmp_macro(env) \
	(xf86getjmptype() == 0 ? xf86setjmp0((env)) : \
	(xf86getjmptype() == 1 ? xf86setjmp1((env), xf86setjmp1_arg2()) : \
		xf86setjmperror((env))))

#else /* XFree86LOADER || NEED_XF86_PROTOTYPES */
#include <unistd.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#ifdef HAVE_SYSV_IPC
#include <sys/ipc.h>
#include <sys/shm.h>
#endif
#include <sys/stat.h>
#define stat_t struct stat
#endif /* XFree86LOADER || NEED_XF86_PROTOTYPES */

/*
 * These things are always required by drivers (but not by libc_wrapper.c),
 * even for a static server because some OSs don't provide them.
 */

extern int xf86getpagesize(void);
extern void xf86usleep(unsigned long);
extern void xf86getsecs(long *, long *);
#ifndef DONT_DEFINE_WRAPPERS
#undef getpagesize
#define getpagesize()		xf86getpagesize()
#undef usleep
#define usleep(ul)		xf86usleep(ul)
#undef getsecs
#define getsecs(a, b)		xf86getsecs(a, b)
#endif
#endif /* _XF86_ANSIC_H */

--- NEW FILE: xf86_libc.h ---
/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h,v 1.1.4.3 2003/12/20 00:28:30 kaleb Exp $ */
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h,v 3.63 2003/12/08 21:46:55 alanh Exp $ */
/*
 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of the copyright holder(s)
 * and author(s) shall not be used in advertising or otherwise to promote
 * the sale, use or other dealings in this Software without prior written
 * authorization from the copyright holder(s) and author(s).
 */

/*
 * This file is an attempt to make developing code for the new loadable module
 * architecure simpler. It tries to use macros to hide all libc wrappers so
 * that all that is needed to "port" a module to this architecture is to
 * include this one header file
 *
 * Revision history:
 *
 *
 * 0.4	Apr 12 1997	add the ANSI defines
 * 0.3	Feb 24 1997	handle getenv
 * 0.2	Feb 24 1997	hide few FILE functions
 * 0.1	Feb 24 1997	hide the trivial functions mem* str*
 */

#ifndef	XF86_LIBC_H
#define XF86_LIBC_H 1

#include <X11/Xfuncs.h>
#include <stddef.h>

/*
 * The first set of definitions are required both for modules and
 * libc_wrapper.c.
 */

#if defined(XFree86LOADER) || defined(NEED_XF86_TYPES)

/*
 * First, the new data types
 *
 * note: if some pointer is declared "opaque" here, pass it between
 * xf86* functions only, and don't rely on it having a whatever internal
 * structure, even if some source file might reveal the existence of
 * such a structure.
 */
typedef void XF86FILE;		/* opaque FILE replacement */
extern  XF86FILE* xf86stdin;
extern  XF86FILE* xf86stdout;
extern  XF86FILE* xf86stderr;

typedef void XF86fpos_t;	/* opaque fpos_t replacement */

#define _XF86NAMELEN	263	/* enough for a larger filename */
				/* (divisble by 8) */
typedef void XF86DIR;		/* opaque DIR replacement */

/* Note: the following is POSIX! POSIX only requires the d_name member. 
 * Normal Unix has often a number of other members, but don't rely on that
 */
struct _xf86dirent {		/* types in struct dirent/direct: */
	char	d_name[_XF86NAMELEN+1];	/* char [MAXNAMLEN]; might be smaller or unaligned */
};
typedef struct _xf86dirent XF86DIRENT;

typedef unsigned long xf86size_t;
typedef signed long xf86ssize_t;
typedef unsigned long xf86dev_t;
typedef unsigned int xf86mode_t;
typedef unsigned int xf86uid_t;
typedef unsigned int xf86gid_t;

struct xf86stat {
    xf86dev_t st_rdev;	/* This is incomplete, and makes assumptions */
};

/* sysv IPC */
typedef int xf86key_t;

/* setjmp/longjmp */
#if defined(__ia64__)
typedef int xf86jmp_buf[1024] __attribute__ ((aligned (16))); /* guarantees 128-bit alignment! */
#else
typedef int xf86jmp_buf[1024];
#endif

/* for setvbuf */
#define XF86_IONBF    1
#define XF86_IOFBF    2
#define XF86_IOLBF    3

/* for open (XXX not complete) */
#define XF86_O_RDONLY	0x0000
#define XF86_O_WRONLY	0x0001
#define XF86_O_RDWR	0x0002
#define XF86_O_CREAT	0x0200

/* for mmap */
#define XF86_PROT_EXEC		0x0001
#define XF86_PROT_READ		0x0002
#define XF86_PROT_WRITE		0x0004
#define XF86_PROT_NONE		0x0008
#define XF86_MAP_FIXED		0x0001
#define XF86_MAP_SHARED		0x0002
#define XF86_MAP_PRIVATE	0x0004
#define XF86_MAP_32BIT	        0x0040
#define XF86_MAP_FAILED		((void *)-1)

/* for fseek */
#define XF86_SEEK_SET	0
#define XF86_SEEK_CUR	1
#define XF86_SEEK_END	2

/* for access */
#define XF86_R_OK       0
#define XF86_W_OK       1
#define XF86_X_OK       2
#define XF86_F_OK       3

/* for chmod */
#define XF86_S_ISUID   04000 /* set user ID on execution */
#define XF86_S_ISGID   02000 /* set group ID on execution */
#define XF86_S_ISVTX   01000 /* sticky bit */
#define XF86_S_IRUSR   00400 /* read by owner */
#define XF86_S_IWUSR   00200 /* write by owner */
#define XF86_S_IXUSR   00100 /* execute/search by owner */
#define XF86_S_IRGRP   00040 /* read by group */
#define XF86_S_IWGRP   00020 /* write by group */
#define XF86_S_IXGRP   00010 /* execute/search by group */
#define XF86_S_IROTH   00004 /* read by others */
#define XF86_S_IWOTH   00002 /* write by others */
#define XF86_S_IXOTH   00001 /* execute/search by others */

/* for mknod */
#define XF86_S_IFREG 0010000
#define XF86_S_IFCHR 0020000
#define XF86_S_IFBLK 0040000
#define XF86_S_IFIFO 0100000

/*
 * errno values
 * They start at 1000 just so they don't match real errnos at all
 */
#define xf86_UNKNOWN		1000
#define xf86_EACCES		1001
#define xf86_EAGAIN		1002
#define xf86_EBADF		1003
#define xf86_EEXIST		1004
#define xf86_EFAULT		1005
#define xf86_EINTR		1006
#define xf86_EINVAL		1007
#define xf86_EISDIR		1008
#define xf86_ELOOP		1009
#define xf86_EMFILE		1010
#define xf86_ENAMETOOLONG	1011
#define xf86_ENFILE		1012
#define xf86_ENOENT		1013
#define xf86_ENOMEM		1014
#define xf86_ENOSPC		1015
#define xf86_ENOTDIR		1016
#define xf86_EPIPE		1017
#define xf86_EROFS		1018
#define xf86_ETXTBSY		1019
#define xf86_ENOTTY		1020
#define xf86_ENOSYS		1021
#define xf86_EBUSY		1022
#define xf86_ENODEV		1023
#define xf86_EIO		1024

/* sysv IPV */
/* xf86shmget() */
#define XF86IPC_CREAT  01000
#define XF86IPC_EXCL   02000
#define XF86IPC_NOWAIT 04000
#define XF86SHM_R           0400         
#define XF86SHM_W           0200            
#define XF86IPC_PRIVATE ((xf86key_t)0)
/* xf86shmat() */
#define XF86SHM_RDONLY      010000      /* attach read-only else read-write */
#define XF86SHM_RND         020000      /* round attach address to SHMLBA */
#define XF86SHM_REMAP       040000      /* take-over region on attach */
/* xf86shmclt() */
#define XF86IPC_RMID 0

#endif /* defined(XFree86LOADER) || defined(NEED_XF86_TYPES) */

/*
 * the rest of this file should only be included for code that is supposed
 * to go into modules
 */

#if defined(XFree86LOADER) && !defined(DONT_DEFINE_WRAPPERS)

#undef abort
#define abort()			xf86abort()
#undef abs
#define abs(i)			xf86abs(i)
#undef acos
#define acos(d)			xf86acos(d)
#undef asin
#define asin(d)			xf86asin(d)
#undef atan
#define atan(d)			xf86atan(d)
#undef atan2
#define atan2(d1,d2)		xf86atan2(d1,d2)
#undef atof
#define atof(ccp)		xf86atof(ccp)
#undef atoi
#define atoi(ccp)		xf86atoi(ccp)
#undef atol
#define atol(ccp)		xf86atol(ccp)
#undef bsearch
#define bsearch(a,b,c,d,e)	xf86bsearch(a,b,c,d,e)
#undef ceil
#define ceil(d)			xf86ceil(d)
#undef calloc
#define calloc(I1,I2)		xf86calloc(I1,I2)
#undef clearerr
#define clearerr(FP)		xf86clearerr(FP)
#undef cos
#define cos(d)			xf86cos(d)
#undef exit
#define exit(i)			xf86exit(i)
#undef exp
#define exp(d)			xf86exp(d)
#undef fabs
#define fabs(d)			xf86fabs(d)
#undef fclose
#define fclose(FP)		xf86fclose(FP)
#undef feof
#define feof(FP)		xf86feof(FP)
#undef ferror
#define ferror(FP)		xf86ferror(FP)
#undef fflush
#define fflush(FP)		xf86fflush(FP)
#undef fgetc
#define fgetc(FP)		xf86fgetc(FP)
#undef getc
#define getc(FP)		xf86getc(FP)
#undef fgetpos
#define fgetpos(FP,fpp)		xf86fgetpos(FP,fpp)
#undef fgets
#define fgets(cp,i,FP)		xf86fgets(cp,i,FP)
#undef finite
#define finite(d)		xf86finite(d)
#undef floor
#define floor(d)		xf86floor(d)
#undef fmod
#define fmod(d1,d2)		xf86fmod(d1,d2)
#undef fopen
#define fopen(ccp1,ccp2)	xf86fopen(ccp1,ccp2)
#undef printf
#define printf			xf86printf
#undef fprintf
#define fprintf			xf86fprintf
#undef fputc
#define fputc(i,FP)		xf86fputc(i,FP)
#undef fputs
#define fputs(ccp,FP)		xf86fputs(ccp,FP)
#undef fread
#define fread(vp,I1,I2,FP)	xf86fread(vp,I1,I2,FP)
#undef free
#define free(vp)		xf86free(vp)
#undef freopen
#define freopen(ccp1,ccp2,FP)	xf86freopen(ccp1,ccp2,FP)
#undef frexp
#define frexp(x,exp)            xf86frexp(x,exp)
#undef fscanf
#define fscanf			xf86fscanf
#undef fseek
#define fseek(FP,l,i)		xf86fseek(FP,l,i)
#undef fsetpos
#define fsetpos(FP,cfpp)	xf86fsetpos(FP,cfpp)
#undef ftell
#define ftell(FP)		xf86ftell(FP)
#undef fwrite
#define fwrite(cvp,I1,I2,FP)	xf86fwrite(cvp,I1,I2,FP)
#undef getenv
#define getenv(ccp)		xf86getenv(ccp)
#undef isalnum
#define isalnum(i)		xf86isalnum(i)
#undef isalpha
#define isalpha(i)		xf86isalpha(i)
#undef iscntrl
#define iscntrl(i)		xf86iscntrl(i)
#undef isdigit
#define isdigit(i)		xf86isdigit(i)
#undef isgraph
#define isgraph(i)		xf86isgraph(i)
#undef islower
#define islower(i)		xf86islower(i)
#undef isprint
#define isprint(i)		xf86isprint(i)
#undef ispunct
#define ispunct(i)		xf86ispunct(i)
#undef isspace
#define isspace(i)		xf86isspace(i)
#undef isupper
#define isupper(i)		xf86isupper(i)
#undef isxdigit
#define isxdigit(i)		xf86isxdigit(i)
#undef labs
#define labs(l)			xf86labs(l)
#undef ldexp
#define ldexp(x, exp)           xf86ldexp(x, exp)
#undef log
#define log(d)			xf86log(d)
#undef log10
#define log10(d)		xf86log10(d)
#undef malloc
#define malloc(I)		xf86malloc(I)
#undef memchr
#define memchr(cvp,i,I)		xf86memchr(cvp,i,I)
#undef memcmp
#define memcmp(cvp1,cvp2,I)	xf86memcmp(cvp1,cvp2,I)
#undef memcpy
#define memcpy(vp,cvp,I)	xf86memcpy(vp,cvp,I)
#undef memmove
#define memmove(vp,cvp,I)	xf86memmove(vp,cvp,I)
#undef memset
#define memset(vp,int,I)	xf86memset(vp,int,I)
#undef modf
#define modf(d,dp)		xf86modf(d,dp)
#undef perror
#define perror(ccp)		xf86perror(ccp)
#undef pow
#define pow(d1,d2)		xf86pow(d1,d2)
#undef realloc
#define realloc(vp,I)		xf86realloc(vp,I)
#undef remove
#define remove(ccp)		xf86remove(ccp)
#undef rename
#define rename(ccp1,ccp2)	xf86rename(ccp1,ccp2)
#undef rewind
#define rewind(FP)		xf86rewind(FP)
#undef setbuf
#define setbuf(FP,cp)		xf86setbuf(FP,cp)
#undef setvbuf
#define setvbuf(FP,cp,i,I)	xf86setvbuf(FP,cp,i,I)
#undef sin
#define sin(d)			xf86sin(d)
#undef snprintf
#define snprintf		xf86snprintf
#undef sprintf
#define sprintf			xf86sprintf
#undef sqrt
#define sqrt(d)			xf86sqrt(d)
#undef sscanf
#define sscanf			xf86sscanf
#undef strcat
#define strcat(cp,ccp)		xf86strcat(cp,ccp)
#undef strcmp
#define strcmp(ccp1,ccp2)	xf86strcmp(ccp1,ccp2)
#undef strcasecmp
#define strcasecmp(ccp1,ccp2)	xf86strcasecmp(ccp1,ccp2)
#undef strcpy
#define strcpy(cp,ccp)		xf86strcpy(cp,ccp)
#undef strcspn
#define strcspn(ccp1,ccp2)	xf86strcspn(ccp1,ccp2)
#undef strerror
#define strerror(i)		xf86strerror(i)
#undef strlcat
#define strlcat(cp,ccp,I)	xf86strlcat(cp,ccp,I)
#undef strlcpy
#define strlcpy(cp,ccp,I)	xf86strlcpy(cp,ccp,I)
#undef strlen
#define strlen(ccp)		xf86strlen(ccp)
#undef strncmp
#define strncmp(ccp1,ccp2,I)	xf86strncmp(ccp1,ccp2,I)
#undef strncasecmp
#define strncasecmp(ccp1,ccp2,I) xf86strncasecmp(ccp1,ccp2,I)
#undef strncpy
#define strncpy(cp,ccp,I)	xf86strncpy(cp,ccp,I)
#undef strpbrk
#define strpbrk(ccp1,ccp2)	xf86strpbrk(ccp1,ccp2)
#undef strchr
#define strchr(ccp,i)		xf86strchr(ccp,i)
#undef strrchr
#define strrchr(ccp,i)		xf86strrchr(ccp,i)
#undef strspn
#define strspn(ccp1,ccp2)	xf86strspn(ccp1,ccp2)
#undef strstr
#define strstr(ccp1,ccp2)	xf86strstr(ccp1,ccp2)
#undef srttod
#define strtod(ccp,cpp)		xf86strtod(ccp,cpp)
#undef strtok
#define strtok(cp,ccp)		xf86strtok(cp,ccp)
#undef strtol
#define strtol(ccp,cpp,i)	xf86strtol(ccp,cpp,i)
#undef strtoul
#define strtoul(ccp,cpp,i)	xf86strtoul(ccp,cpp,i)
#undef tan
#define tan(d)			xf86tan(d)
#undef tmpfile
#define tmpfile()		xf86tmpfile()
#undef tolower
#define tolower(i)		xf86tolower(i)
#undef toupper
#define toupper(i)		xf86toupper(i)
#undef ungetc
#define ungetc(i,FP)		xf86ungetc(i,FP)
#undef vfprinf
#define vfprintf(p,f,a)		xf86vfprintf(p,f,a)
#undef vsnprintf
#define vsnprintf(s,n,f,a)	xf86vsnprintf(s,n,f,a)
#undef vsprintf
#define vsprintf(s,f,a)		xf86vsprintf(s,f,a)
/* XXX Disable assert as if NDEBUG was defined */
/* Some X headers defined this away too */
#undef assert
#define assert(a)		((void)0)
#undef HUGE_VAL
#define HUGE_VAL		xf86HUGE_VAL

#undef hypot
#define hypot(x,y)		xf86hypot(x,y)

#undef qsort
#define qsort(b, n, s, f)	xf86qsort(b, n, s, f)

/* non-ANSI C functions */
#undef opendir
#define opendir(cp)		xf86opendir(cp)
#undef closedir
#define closedir(DP)		xf86closedir(DP)
#undef readdir
#define readdir(DP)		xf86readdir(DP)
#undef rewinddir
#define rewinddir(DP)		xf86rewinddir(DP)
#undef bcopy
#define bcopy(vp,cvp,I)		xf86memmove(cvp,vp,I)
#undef ffs
#define ffs(i)			xf86ffs(i)
#undef strdup
#define strdup(ccp)		xf86strdup(ccp)
#undef bzero
#define bzero(vp,ui)		xf86bzero(vp,ui)
#undef execl
#define execl	        	xf86execl
#undef chmod
#define chmod(a,b)              xf86chmod(a,b)
#undef chown
#define chown(a,b,c)            xf86chown(a,b,c)
#undef geteuid
#define geteuid                 xf86geteuid
#undef getegid
#define getegid                 xf86getegid
#undef getpid
#define getpid                  xf86getpid
#undef mknod
#define mknod(a,b,c)            xf86mknod(a,b,c)
#undef sleep
#define sleep(a)                xf86sleep(a)
#undef mkdir
#define mkdir(a,b)              xf86mkdir(a,b)
#undef getpagesize
#define getpagesize		xf86getpagesize
#undef shmget
#define shmget(a,b,c)		xf86shmget(a,b,c)
#undef shmat
#define shmat(a,b,c)		xf86shmat(a,b,c)
#undef shmdt
#define shmdt(a)		xf86shmdt(a)
#undef shmctl
#define shmctl(a,b,c)		xf86shmctl(a,b,c)

#undef S_ISUID
#define S_ISUID XF86_S_ISUID
#undef S_ISGID
#define S_ISGID XF86_S_ISGID
#undef S_ISVTX
#define S_ISVTX XF86_S_ISVTX
#undef S_IRUSR
#define S_IRUSR XF86_S_IRUSR
#undef S_IWUSR
#define S_IWUSR XF86_S_IWUSR
#undef S_IXUSR
#define S_IXUSR XF86_S_IXUSR
#undef S_IRGRP
#define S_IRGRP XF86_S_IRGRP
#undef S_IWGRP
#define S_IWGRP XF86_S_IWGRP
#undef S_IXGRP
#define S_IXGRP XF86_S_IXGRP
#undef S_IROTH
#define S_IROTH XF86_S_IROTH
#undef S_IWOTH
#define S_IWOTH XF86_S_IWOTH
#undef S_IXOTH
#define S_IXOTH XF86_S_IXOTH
#undef S_IFREG
#define S_IFREG XF86_S_IFREG
#undef S_IFCHR
#define S_IFCHR XF86_S_IFCHR
#undef S_IFBLK
#define S_IFBLK XF86_S_IFBLK
#undef S_IFIFO
#define S_IFIFO XF86_S_IFIFO

/* some types */
#undef FILE
#define FILE			XF86FILE
#undef fpos_t
#define fpos_t			XF86fpos_t
#undef DIR
#define DIR			XF86DIR
#undef DIRENT
#define DIRENT			XF86DIRENT
#undef size_t
#define size_t			xf86size_t
#undef ssize_t
#define ssize_t			xf86ssize_t
#undef dev_t
#define dev_t                   xf86dev_t
#undef mode_t
#define mode_t                  xf86mode_t
#undef uid_t
#define uid_t                   xf86uid_t
#undef gid_t
#define gid_t                   xf86gid_t
#undef stat_t
#define stat_t			struct xf86stat

#undef ulong
#define ulong			unsigned long

/*
 * There should be no need to #undef any of these.  If they are already
 * defined it is because some illegal header has been included.
 */

/* some vars */
#undef stdin
#define	stdin			xf86stdin
#undef stdout
#define stdout			xf86stdout
#undef stderr
#define stderr			xf86stderr

#undef SEEK_SET
#define SEEK_SET		XF86_SEEK_SET
#undef SEEK_CUR
#define SEEK_CUR		XF86_SEEK_CUR
#undef SEEK_END
#define SEEK_END		XF86_SEEK_END

/*
 * XXX Basic I/O functions BAD,BAD,BAD!
 */
#define open			xf86open
#define close(a)		xf86close(a)
#define lseek(a,b,c)		xf86lseek(a,b,c)
#define ioctl(a,b,c)		xf86ioctl(a,b,c)
#define read(a,b,c)		xf86read(a,b,c)
#define write(a,b,c)		xf86write(a,b,c)
#define mmap(a,b,c,d,e,f)	xf86mmap(a,b,c,d,e,f)
#define munmap(a,b)		xf86munmap(a,b)
#define stat(a,b)               xf86stat(a,b)
#define fstat(a,b)              xf86fstat(a,b)
#define access(a,b)             xf86access(a,b)
#undef O_RDONLY
#define O_RDONLY		XF86_O_RDONLY
#undef O_WRONLY
#define O_WRONLY		XF86_O_WRONLY
#undef O_RDWR
#define O_RDWR			XF86_O_RDWR
#undef O_CREAT
#define O_CREAT			XF86_O_CREAT
#undef PROT_EXEC
#define PROT_EXEC		XF86_PROT_EXEC
#undef PROT_READ
#define PROT_READ		XF86_PROT_READ
#undef PROT_WRITE
#define PROT_WRITE		XF86_PROT_WRITE
#undef PROT_NONE
#define PROT_NONE		XF86_PROT_NONE
#undef MAP_FIXED
#define MAP_FIXED		XF86_MAP_FIXED
#undef MAP_SHARED
#define MAP_SHARED		XF86_MAP_SHARED
#undef MAP_PRIVATE
#define MAP_PRIVATE		XF86_MAP_PRIVATE
#undef MAP_FAILED
#define MAP_FAILED		XF86_MAP_FAILED
#undef R_OK
#define R_OK                    XF86_R_OK
#undef W_OK
#define W_OK                    XF86_W_OK
#undef X_OK
#define X_OK                    XF86_X_OK
#undef F_OK
#define F_OK                    XF86_F_OK
#undef errno
#define errno			xf86errno
#undef putchar
#define putchar(i)		xf86fputc(i, xf86stdout)
#undef puts
#define puts(s)			xf86fputs(s, xf86stdout)

#undef EACCES
#define EACCES		xf86_EACCES
#undef EAGAIN
#define EAGAIN		xf86_EAGAIN
#undef EBADF
#define EBADF		xf86_EBADF
#undef EEXIST
#define EEXIST		xf86_EEXIST
#undef EFAULT
#define EFAULT		xf86_EFAULT
#undef EINTR
#define EINTR		xf86_EINTR
#undef EINVAL
#define EINVAL		xf86_EINVAL
#undef EISDIR
#define EISDIR		xf86_EISDIR
#undef ELOOP
#define ELOOP		xf86_ELOOP
#undef EMFILE
#define EMFILE		xf86_EMFILE
#undef ENAMETOOLONG
#define ENAMETOOLONG	xf86_ENAMETOOLONG
#undef ENFILE
#define ENFILE		xf86_ENFILE
#undef ENOENT
#define ENOENT		xf86_ENOENT
#undef ENOMEM
#define ENOMEM		xf86_ENOMEM
#undef ENOSPC
#define ENOSPC		xf86_ENOSPC
#undef ENOTDIR
#define ENOTDIR		xf86_ENOTDIR
#undef EPIPE
#define EPIPE		xf86_EPIPE
#undef EROFS
#define EROFS		xf86_EROFS
#undef ETXTBSY
#define ETXTBSY		xf86_ETXTBSY
#undef ENOTTY
#define ENOTTY		xf86_ENOTTY
#undef ENOSYS
#define ENOSYS		xf86_ENOSYS
#undef EBUSY
#define EBUSY		xf86_EBUSY
#undef ENODEV
#define ENODEV		xf86_ENODEV
#undef EIO
#define EIO		xf86_EIO

/* IPC stuff */
#undef SHM_RDONLY
#define SHM_RDONLY XF86SHM_RDONLY
#undef SHM_RND
#define SHM_RND XF86SHM_RND
#undef SHM_REMAP
#define SHM_REMAP XF86SHM_REMAP
#undef IPC_RMID
#define IPC_RMID XF86IPC_RMID
#undef IPC_CREAT
#define IPC_CREAT XF86IPC_CREAT
#undef IPC_EXCL
#define IPC_EXCL XF86IPC_EXCL
#undef PC_NOWAIT
#define IPC_NOWAIT XF86IPC_NOWAIT
#undef SHM_R
#define SHM_R XF86SHM_R
#undef SHM_W
#define SHM_W XF86SHM_W
#undef IPC_PRIVATE
#define IPC_PRIVATE XF86IPC_PRIVATE

/* Some ANSI macros */
#undef FILENAME_MAX
#define FILENAME_MAX		1024

#endif /* XFree86LOADER  && !DONT_DEFINE_WRAPPERS */

#if defined(XFree86LOADER) && \
    (!defined(DONT_DEFINE_WRAPPERS) || defined(DEFINE_SETJMP_WRAPPERS))
#undef setjmp
#define setjmp(a)               xf86setjmp_macro(a)
#undef longjmp
#define longjmp(a,b)            xf86longjmp(a,b) 
#undef jmp_buf
#define jmp_buf                 xf86jmp_buf
#endif

#endif /* XF86_LIBC_H */

--- NEW FILE: xf86drm.h ---
/**
 * \file xf86drm.h 
 * OS-independent header for DRM user-level library interface.
 *
 * \author Rickard E. (Rik) Faith <faith at valinux.com>
 */
 
/*
 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 */

/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86drm.h,v 1.26 2003/08/16 19:26:37 dawes Exp $ */

#ifndef _XF86DRM_H_
#define _XF86DRM_H_

				/* Defaults, if nothing set in xf86config */
#define DRM_DEV_UID	 0
#define DRM_DEV_GID	 0
/* Default /dev/dri directory permissions 0755 */
#define DRM_DEV_DIRMODE	 	\
	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
#define DRM_DEV_MODE	 (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)

#define DRM_DIR_NAME  "/dev/dri"
#define DRM_DEV_NAME  "%s/card%d"
#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */

#define DRM_ERR_NO_DEVICE  (-1001)
#define DRM_ERR_NO_ACCESS  (-1002)
#define DRM_ERR_NOT_ROOT   (-1003)
#define DRM_ERR_INVALID    (-1004)
#define DRM_ERR_NO_FD      (-1005)

#define DRM_AGP_NO_HANDLE 0

typedef unsigned long drmHandle,   *drmHandlePtr;   /**< To mapped regions */
typedef unsigned int  drmSize,     *drmSizePtr;	    /**< For mapped regions */
typedef void          *drmAddress, **drmAddressPtr; /**< For mapped regions */
typedef unsigned int  drmContext,  *drmContextPtr;  /**< GLXContext handle */
typedef unsigned int  drmDrawable, *drmDrawablePtr; /**< Unused */
typedef unsigned int  drmMagic,    *drmMagicPtr;    /**< Magic for authentication */

/**
 * Driver version information.
 *
 * \sa drmGetVersion() and drmSetVersion().
 */
typedef struct _drmVersion {
    int     version_major;        /**< Major version */
    int     version_minor;        /**< Minor version */
    int     version_patchlevel;   /**< Patch level */
    int     name_len; 	          /**< Length of name buffer */
    char    *name;	          /**< Name of driver */
    int     date_len;             /**< Length of date buffer */
    char    *date;                /**< User-space buffer to hold date */
    int     desc_len;	          /**< Length of desc buffer */
    char    *desc;                /**< User-space buffer to hold desc */
} drmVersion, *drmVersionPtr;

typedef struct _drmStats {
    unsigned long count;	     /**< Number of data */
    struct {
	unsigned long value;	     /**< Value from kernel */
	const char    *long_format;  /**< Suggested format for long_name */
	const char    *long_name;    /**< Long name for value */
	const char    *rate_format;  /**< Suggested format for rate_name */
	const char    *rate_name;    /**< Short name for value per second */
	int           isvalue;       /**< True if value (vs. counter) */
	const char    *mult_names;   /**< Multiplier names (e.g., "KGM") */
	int           mult;          /**< Multiplier value (e.g., 1024) */
	int           verbose;       /**< Suggest only in verbose output */
    } data[15];
} drmStatsT;


				/* All of these enums *MUST* match with the
                                   kernel implementation -- so do *NOT*
                                   change them!  (The drmlib implementation
                                   will just copy the flags instead of
                                   translating them.) */
typedef enum {
    DRM_FRAME_BUFFER    = 0,      /**< WC, no caching, no core dump */
    DRM_REGISTERS       = 1,      /**< no caching, no core dump */
    DRM_SHM             = 2,      /**< shared, cached */
    DRM_AGP             = 3,	  /**< AGP/GART */
    DRM_SCATTER_GATHER  = 4	  /**< PCI scatter/gather */
} drmMapType;

typedef enum {
    DRM_RESTRICTED      = 0x0001, /**< Cannot be mapped to client-virtual */
    DRM_READ_ONLY       = 0x0002, /**< Read-only in client-virtual */
    DRM_LOCKED          = 0x0004, /**< Physical pages locked */
    DRM_KERNEL          = 0x0008, /**< Kernel requires access */
    DRM_WRITE_COMBINING = 0x0010, /**< Use write-combining, if available */
    DRM_CONTAINS_LOCK   = 0x0020, /**< SHM page that contains lock */
    DRM_REMOVABLE	= 0x0040  /**< Removable mapping */
} drmMapFlags;

/**
 * \warning These values *MUST* match drm.h
 */
typedef enum {
    /** \name Flags for DMA buffer dispatch */
    /*@{*/
    DRM_DMA_BLOCK        = 0x01, /**< 
				  * Block until buffer dispatched.
				  * 
				  * \note the buffer may not yet have been
				  * processed by the hardware -- getting a
				  * hardware lock with the hardware quiescent
				  * will ensure that the buffer has been
				  * processed.
				  */
    DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
    DRM_DMA_PRIORITY     = 0x04, /**< High priority dispatch */
    /*@}*/

    /** \name Flags for DMA buffer request */
    /*@{*/
    DRM_DMA_WAIT         = 0x10, /**< Wait for free buffers */
    DRM_DMA_SMALLER_OK   = 0x20, /**< Smaller-than-requested buffers OK */
    DRM_DMA_LARGER_OK    = 0x40  /**< Larger-than-requested buffers OK */
    /*@}*/
} drmDMAFlags;

typedef enum {
    DRM_PAGE_ALIGN       = 0x01,
    DRM_AGP_BUFFER       = 0x02,
    DRM_SG_BUFFER        = 0x04
} drmBufDescFlags;

typedef enum {
    DRM_LOCK_READY      = 0x01, /**< Wait until hardware is ready for DMA */
    DRM_LOCK_QUIESCENT  = 0x02, /**< Wait until hardware quiescent */
    DRM_LOCK_FLUSH      = 0x04, /**< Flush this context's DMA queue first */
    DRM_LOCK_FLUSH_ALL  = 0x08, /**< Flush all DMA queues first */
				/* These *HALT* flags aren't supported yet
                                   -- they will be used to support the
                                   full-screen DGA-like mode. */
    DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
    DRM_HALT_CUR_QUEUES = 0x20  /**< Halt all current queues */
} drmLockFlags;

typedef enum {
    DRM_CONTEXT_PRESERVED = 0x01, /**< This context is preserved and
				     never swapped. */
    DRM_CONTEXT_2DONLY    = 0x02  /**< This context is for 2D rendering only. */
} drmContextFlags, *drmContextFlagsPtr;

typedef struct _drmBufDesc {
    int              count;	  /**< Number of buffers of this size */
    int              size;	  /**< Size in bytes */
    int              low_mark;	  /**< Low water mark */
    int              high_mark;	  /**< High water mark */
} drmBufDesc, *drmBufDescPtr;

typedef struct _drmBufInfo {
    int              count;	  /**< Number of buffers described in list */
    drmBufDescPtr    list;	  /**< List of buffer descriptions */
} drmBufInfo, *drmBufInfoPtr;

typedef struct _drmBuf {
    int              idx;	  /**< Index into the master buffer list */
    int              total;	  /**< Buffer size */
    int              used;	  /**< Amount of buffer in use (for DMA) */
    drmAddress       address;	  /**< Address */
} drmBuf, *drmBufPtr;

/**
 * Buffer mapping information.
 *
 * Used by drmMapBufs() and drmUnmapBufs() to store information about the
 * mapped buffers.
 */
typedef struct _drmBufMap {
    int              count;	  /**< Number of buffers mapped */
    drmBufPtr        list;	  /**< Buffers */
} drmBufMap, *drmBufMapPtr;

typedef struct _drmLock {
    volatile unsigned int lock;
    char                      padding[60];
    /* This is big enough for most current (and future?) architectures:
       DEC Alpha:              32 bytes
       Intel Merced:           ?
       Intel P5/PPro/PII/PIII: 32 bytes
       Intel StrongARM:        32 bytes
       Intel i386/i486:        16 bytes
       MIPS:                   32 bytes (?)
       Motorola 68k:           16 bytes
       Motorola PowerPC:       32 bytes
       Sun SPARC:              32 bytes
    */
} drmLock, *drmLockPtr;

/**
 * Indices here refer to the offset into
 * list in drmBufInfo
 */
typedef struct _drmDMAReq {
    drmContext    context;  	  /**< Context handle */
    int           send_count;     /**< Number of buffers to send */
    int           *send_list;     /**< List of handles to buffers */
    int           *send_sizes;    /**< Lengths of data to send, in bytes */
    drmDMAFlags   flags;          /**< Flags */
    int           request_count;  /**< Number of buffers requested */
    int           request_size;	  /**< Desired size of buffers requested */
    int           *request_list;  /**< Buffer information */
    int           *request_sizes; /**< Minimum acceptable sizes */
    int           granted_count;  /**< Number of buffers granted at this size */
} drmDMAReq, *drmDMAReqPtr;

typedef struct _drmRegion {
    drmHandle     handle;
    unsigned int  offset;
    drmSize       size;
    drmAddress    map;
} drmRegion, *drmRegionPtr;

typedef struct _drmTextureRegion {
    unsigned char next;
    unsigned char prev;
    unsigned char in_use;
    unsigned char padding;	/**< Explicitly pad this out */
    unsigned int  age;
} drmTextureRegion, *drmTextureRegionPtr;


typedef struct _drmClipRect {
    unsigned short	x1; /* Upper left: inclusive */
    unsigned short	y1;
    unsigned short	x2; /* Lower right: exclusive */
    unsigned short	y2;
} drmClipRect, *drmClipRectPtr;


typedef enum {
    DRM_VBLANK_ABSOLUTE = 0x0,	/**< Wait for specific vblank sequence number */
    DRM_VBLANK_RELATIVE = 0x1,	/**< Wait for given number of vblanks */
    DRM_VBLANK_SIGNAL   = 0x40000000	/* Send signal instead of blocking */
} drmVBlankSeqType;

typedef struct _drmVBlankReq {
	drmVBlankSeqType type;
	unsigned int sequence;
	unsigned long signal;
} drmVBlankReq, *drmVBlankReqPtr;

typedef struct _drmVBlankReply {
	drmVBlankSeqType type;
	unsigned int sequence;
	long tval_sec;
	long tval_usec;
} drmVBlankReply, *drmVBlankReplyPtr;

typedef union _drmVBlank {
	drmVBlankReq request;
	drmVBlankReply reply;
} drmVBlank, *drmVBlankPtr;



#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)

#define DRM_LOCK_HELD  0x80000000 /**< Hardware lock is held */
#define DRM_LOCK_CONT  0x40000000 /**< Hardware lock is contended */

#if defined(__GNUC__) && (__GNUC__ >= 2)
# if defined(__i386) || defined(__amd64__)
				/* Reflect changes here to drmP.h */
#define DRM_CAS(lock,old,new,__ret)                                    \
	do {                                                           \
                int __dummy;	/* Can't mark eax as clobbered */      \
		__asm__ __volatile__(                                  \
			"lock ; cmpxchg %4,%1\n\t"                     \
                        "setnz %0"                                     \
			: "=d" (__ret),                                \
   			  "=m" (__drm_dummy_lock(lock)),               \
                          "=a" (__dummy)                               \
			: "2" (old),                                   \
			  "r" (new));                                  \
	} while (0)

#elif defined(__alpha__)

#define	DRM_CAS(lock, old, new, ret) 		\
 	do {					\
 		int old32;                      \
 		int cur32;			\
 		__asm__ __volatile__(		\
 		"       mb\n"			\
 		"       zap   %4, 0xF0, %0\n"   \
 		"       ldl_l %1, %2\n"		\
 		"       zap   %1, 0xF0, %1\n"   \
                "       cmpeq %0, %1, %1\n"	\
                "       beq   %1, 1f\n"		\
 		"       bis   %5, %5, %1\n"	\
                "       stl_c %1, %2\n"		\
                "1:     xor   %1, 1, %1\n"	\
                "       stl   %1, %3"		\
                : "+r" (old32),                 \
		  "+&r" (cur32),		\
                   "=m" (__drm_dummy_lock(lock)),\
                   "=m" (ret)			\
 		: "r" (old),			\
 		  "r" (new));			\
 	} while(0)

#elif defined(__sparc__)

#define DRM_CAS(lock,old,new,__ret)				\
do {	register unsigned int __old __asm("o0");		\
	register unsigned int __new __asm("o1");		\
	register volatile unsigned int *__lock __asm("o2");	\
	__old = old;						\
	__new = new;						\
	__lock = (volatile unsigned int *)lock;			\
	__asm__ __volatile__(					\
		/*"cas [%2], %3, %0"*/				\
		".word 0xd3e29008\n\t"				\
		/*"membar #StoreStore | #StoreLoad"*/		\
		".word 0x8143e00a"				\
		: "=&r" (__new)					\
		: "0" (__new),					\
		  "r" (__lock),					\
		  "r" (__old)					\
		: "memory");					\
	__ret = (__new != __old);				\
} while(0)

#elif defined(__ia64__)

#ifdef __INTEL_COMPILER
/* this currently generates bad code (missing stop bits)... */
#include <ia64intrin.h>

#define DRM_CAS(lock,old,new,__ret)					      \
	do {								      \
		unsigned long __result, __old = (old) & 0xffffffff;		\
		__mf();							      	\
		__result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\
		__ret = (__result) != (__old);					\
/*		__ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \
						     (old), (new))	      \
			 != (old));					      */\
	} while (0)

#else
#define DRM_CAS(lock,old,new,__ret)					  \
	do {								  \
		unsigned int __result, __old = (old);			  \
		__asm__ __volatile__(					  \
			"mf\n"						  \
			"mov ar.ccv=%2\n"				  \
			";;\n"						  \
			"cmpxchg4.acq %0=%1,%3,ar.ccv"			  \
			: "=r" (__result), "=m" (__drm_dummy_lock(lock))  \
			: "r" ((unsigned long)__old), "r" (new)			  \
			: "memory");					  \
		__ret = (__result) != (__old);				  \
	} while (0)

#endif

#elif defined(__powerpc__)

#define DRM_CAS(lock,old,new,__ret)			\
	do {						\
		__asm__ __volatile__(			\
			"sync;"				\
			"0:    lwarx %0,0,%1;"		\
			"      xor. %0,%3,%0;"		\
			"      bne 1f;"			\
			"      stwcx. %2,0,%1;"		\
			"      bne- 0b;"		\
			"1:    "			\
			"sync;"				\
		: "=&r"(__ret)				\
		: "r"(lock), "r"(new), "r"(old)		\
		: "cr0", "memory");			\
	} while (0)

#endif /* architecture */
#endif /* __GNUC__ >= 2 */

#ifndef DRM_CAS
#define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
#endif

#if defined(__alpha__) || defined(__powerpc__)
#define DRM_CAS_RESULT(_result)		int _result
#else
#define DRM_CAS_RESULT(_result)		char _result
#endif

#define DRM_LIGHT_LOCK(fd,lock,context)                                \
	do {                                                           \
                DRM_CAS_RESULT(__ret);                                 \
		DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret);     \
                if (__ret) drmGetLock(fd,context,0);                   \
        } while(0)

				/* This one counts fast locks -- for
                                   benchmarking only. */
#define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count)                    \
	do {                                                           \
                DRM_CAS_RESULT(__ret);                                 \
		DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret);     \
                if (__ret) drmGetLock(fd,context,0);                   \
                else       ++count;                                    \
        } while(0)

#define DRM_LOCK(fd,lock,context,flags)                                \
	do {                                                           \
		if (flags) drmGetLock(fd,context,flags);               \
		else       DRM_LIGHT_LOCK(fd,lock,context);            \
	} while(0)

#define DRM_UNLOCK(fd,lock,context)                                    \
	do {                                                           \
                DRM_CAS_RESULT(__ret);                                 \
		DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret);     \
                if (__ret) drmUnlock(fd,context);                      \
        } while(0)

				/* Simple spin locks */
#define DRM_SPINLOCK(spin,val)                                         \
	do {                                                           \
            DRM_CAS_RESULT(__ret);                                     \
	    do {                                                       \
		DRM_CAS(spin,0,val,__ret);                             \
		if (__ret) while ((spin)->lock);                       \
	    } while (__ret);                                           \
	} while(0)

#define DRM_SPINLOCK_TAKE(spin,val)                                    \
	do {                                                           \
            DRM_CAS_RESULT(__ret);                                     \
            int  cur;                                                  \
	    do {                                                       \
                cur = (*spin).lock;                                    \
		DRM_CAS(spin,cur,val,__ret);                           \
	    } while (__ret);                                           \
	} while(0)

#define DRM_SPINLOCK_COUNT(spin,val,count,__ret)                       \
	do {                                                           \
            int  __i;                                                  \
            __ret = 1;                                                 \
            for (__i = 0; __ret && __i < count; __i++) {               \
		DRM_CAS(spin,0,val,__ret);                             \
		if (__ret) for (;__i < count && (spin)->lock; __i++);  \
	    }                                                          \
	} while(0)

#define DRM_SPINUNLOCK(spin,val)                                       \
	do {                                                           \
            DRM_CAS_RESULT(__ret);                                     \
            if ((*spin).lock == val) { /* else server stole lock */    \
	        do {                                                   \
		    DRM_CAS(spin,val,0,__ret);                         \
	        } while (__ret);                                       \
            }                                                          \
	} while(0)

/* General user-level programmer's API: unprivileged */
extern int           drmAvailable(void);
extern int           drmOpen(const char *name, const char *busid);
extern int           drmClose(int fd);
extern drmVersionPtr drmGetVersion(int fd);
extern drmVersionPtr drmGetLibVersion(int fd);
extern void          drmFreeVersion(drmVersionPtr);
extern int           drmGetMagic(int fd, drmMagicPtr magic);
extern char          *drmGetBusid(int fd);
extern int           drmGetInterruptFromBusID(int fd, int busnum, int devnum,
					      int funcnum);
extern int           drmGetMap(int fd, int idx, drmHandle *offset,
			       drmSize *size, drmMapType *type,
			       drmMapFlags *flags, drmHandle *handle,
			       int *mtrr);
extern int           drmGetClient(int fd, int idx, int *auth, int *pid,
				  int *uid, unsigned long *magic,
				  unsigned long *iocs);
extern int           drmGetStats(int fd, drmStatsT *stats);
extern int           drmCommandNone(int fd, unsigned long drmCommandIndex);
extern int           drmCommandRead(int fd, unsigned long drmCommandIndex,
                                    void *data, unsigned long size);
extern int           drmCommandWrite(int fd, unsigned long drmCommandIndex,
                                     void *data, unsigned long size);
extern int           drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
                                         void *data, unsigned long size);

/* General user-level programmer's API: X server (root) only  */
extern void          drmFreeBusid(const char *busid);
extern int           drmSetBusid(int fd, const char *busid);
extern int           drmAuthMagic(int fd, drmMagic magic);
extern int           drmAddMap(int fd,
			       drmHandle offset,
			       drmSize size,
			       drmMapType type,
			       drmMapFlags flags,
			       drmHandlePtr handle);
extern int	     drmRmMap(int fd, drmHandle handle);
extern int	     drmAddContextPrivateMapping(int fd, drmContext ctx_id,
						 drmHandle handle);

extern int           drmAddBufs(int fd, int count, int size,
				drmBufDescFlags flags,
				int agp_offset);
extern int           drmMarkBufs(int fd, double low, double high);
extern int           drmCreateContext(int fd, drmContextPtr handle);
extern int           drmSetContextFlags(int fd, drmContext context,
					drmContextFlags flags);
extern int           drmGetContextFlags(int fd, drmContext context,
					drmContextFlagsPtr flags);
extern int           drmAddContextTag(int fd, drmContext context, void *tag);
extern int           drmDelContextTag(int fd, drmContext context);
extern void          *drmGetContextTag(int fd, drmContext context);
extern drmContextPtr drmGetReservedContextList(int fd, int *count);
extern void          drmFreeReservedContextList(drmContextPtr);
extern int           drmSwitchToContext(int fd, drmContext context);
extern int           drmDestroyContext(int fd, drmContext handle);
extern int           drmCreateDrawable(int fd, drmDrawablePtr handle);
extern int           drmDestroyDrawable(int fd, drmDrawable handle);
extern int           drmCtlInstHandler(int fd, int irq);
extern int           drmCtlUninstHandler(int fd);
extern int           drmInstallSIGIOHandler(int fd,
					    void (*f)(int fd,
						      void *oldctx,
						      void *newctx));
extern int           drmRemoveSIGIOHandler(int fd);

/* General user-level programmer's API: authenticated client and/or X */
extern int           drmMap(int fd,
			    drmHandle handle,
			    drmSize size,
			    drmAddressPtr address);
extern int           drmUnmap(drmAddress address, drmSize size);
extern drmBufInfoPtr drmGetBufInfo(int fd);
extern drmBufMapPtr  drmMapBufs(int fd);
extern int           drmUnmapBufs(drmBufMapPtr bufs);
extern int           drmDMA(int fd, drmDMAReqPtr request);
extern int           drmFreeBufs(int fd, int count, int *list);
extern int           drmGetLock(int fd,
			        drmContext context,
			        drmLockFlags flags);
extern int           drmUnlock(int fd, drmContext context);
extern int           drmFinish(int fd, int context, drmLockFlags flags);
extern int	     drmGetContextPrivateMapping(int fd, drmContext ctx_id, 
						 drmHandlePtr handle);

/* AGP/GART support: X server (root) only */
extern int           drmAgpAcquire(int fd);
extern int           drmAgpRelease(int fd);
extern int           drmAgpEnable(int fd, unsigned long mode);
extern int           drmAgpAlloc(int fd, unsigned long size,
				 unsigned long type, unsigned long *address,
				 unsigned long *handle);
extern int           drmAgpFree(int fd, unsigned long handle);
extern int 	     drmAgpBind(int fd, unsigned long handle,
				unsigned long offset);
extern int           drmAgpUnbind(int fd, unsigned long handle);

/* AGP/GART info: authenticated client and/or X */
extern int           drmAgpVersionMajor(int fd);
extern int           drmAgpVersionMinor(int fd);
extern unsigned long drmAgpGetMode(int fd);
extern unsigned long drmAgpBase(int fd); /* Physical location */
extern unsigned long drmAgpSize(int fd); /* Bytes */
extern unsigned long drmAgpMemoryUsed(int fd);
extern unsigned long drmAgpMemoryAvail(int fd);
extern unsigned int  drmAgpVendorId(int fd);
extern unsigned int  drmAgpDeviceId(int fd);

/* PCI scatter/gather support: X server (root) only */
extern int           drmScatterGatherAlloc(int fd, unsigned long size,
					   unsigned long *handle);
extern int           drmScatterGatherFree(int fd, unsigned long handle);

extern int           drmWaitVBlank(int fd, drmVBlankPtr vbl);

/* Support routines */
extern int           drmError(int err, const char *label);
extern void          *drmMalloc(int size);
extern void          drmFree(void *pt);

/* Hash table routines */
extern void *drmHashCreate(void);
extern int  drmHashDestroy(void *t);
extern int  drmHashLookup(void *t, unsigned long key, void **value);
extern int  drmHashInsert(void *t, unsigned long key, void *value);
extern int  drmHashDelete(void *t, unsigned long key);
extern int  drmHashFirst(void *t, unsigned long *key, void **value);
extern int  drmHashNext(void *t, unsigned long *key, void **value);

/* PRNG routines */
extern void          *drmRandomCreate(unsigned long seed);
extern int           drmRandomDestroy(void *state);
extern unsigned long drmRandom(void *state);
extern double        drmRandomDouble(void *state);

/* Skip list routines */

extern void *drmSLCreate(void);
extern int  drmSLDestroy(void *l);
extern int  drmSLLookup(void *l, unsigned long key, void **value);
extern int  drmSLInsert(void *l, unsigned long key, void *value);
extern int  drmSLDelete(void *l, unsigned long key);
extern int  drmSLNext(void *l, unsigned long *key, void **value);
extern int  drmSLFirst(void *l, unsigned long *key, void **value);
extern void drmSLDump(void *l);
extern int  drmSLLookupNeighbors(void *l, unsigned long key,
				 unsigned long *prev_key, void **prev_value,
				 unsigned long *next_key, void **next_value);

#endif

--- NEW FILE: xf86drmCompat.h ---
/* xf86drmCompat.h -- OS-independent header for old device specific DRM user-level
 *                    library interface
 *
 * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
 * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *   Gareth Hughes <gareth at valinux.com>
 *   Kevin E. Martin <martin at valinux.com>
 *   Keith Whitwell <keith at tungstengraphics.com>
 *
 * Backwards compatability modules broken out by:
 *   Jens Owen <jens at tungstengraphics.com>
 *
 * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86drmRadeon.h,v 1.6 2001/04/16 15:02:13 tsi Exp $
 *
 */

#ifndef _XF86DRI_COMPAT_H_
#define _XF86DRI_COMPAT_H_

/* WARNING: Do not change, or add, anything to this file.  It is only provided
 * for binary backwards compatability with the old driver specific DRM 
 * extensions used before XFree86 4.3.
 */

/* I810 */

typedef struct {
   unsigned int start; 
   unsigned int end; 
   unsigned int size;
   unsigned int mmio_offset;
   unsigned int buffers_offset;
   int sarea_off;

   unsigned int front_offset;
   unsigned int back_offset;
   unsigned int depth_offset;
   unsigned int overlay_offset;
   unsigned int overlay_physical;
   unsigned int w;
   unsigned int h;
   unsigned int pitch;
   unsigned int pitch_bits;
} drmCompatI810Init;

extern Bool drmI810CleanupDma(int driSubFD);
extern Bool drmI810InitDma(int driSubFD, drmCompatI810Init *info );

/* Mga */

typedef struct {
   unsigned long sarea_priv_offset;
   int chipset;
   int sgram;
   unsigned int maccess;
   unsigned int fb_cpp;
   unsigned int front_offset, front_pitch;
   unsigned int back_offset, back_pitch;
   unsigned int depth_cpp;
   unsigned int depth_offset, depth_pitch;
   unsigned int texture_offset[2];
   unsigned int texture_size[2];
   unsigned long fb_offset;
   unsigned long mmio_offset;
   unsigned long status_offset;
   unsigned long warp_offset;
   unsigned long primary_offset;
   unsigned long buffers_offset;
} drmCompatMGAInit;

extern int drmMGAInitDMA( int fd, drmCompatMGAInit *info );
extern int drmMGACleanupDMA( int fd );
extern int drmMGAFlushDMA( int fd, drmLockFlags flags );
extern int drmMGAEngineReset( int fd );
extern int drmMGAFullScreen( int fd, int enable );
extern int drmMGASwapBuffers( int fd );
extern int drmMGAClear( int fd, unsigned int flags,
			unsigned int clear_color, unsigned int clear_depth,
			unsigned int color_mask, unsigned int depth_mask );
extern int drmMGAFlushVertexBuffer( int fd, int indx, int used, int discard );
extern int drmMGAFlushIndices( int fd, int indx,
			       int start, int end, int discard );
extern int drmMGATextureLoad( int fd, int indx,
			      unsigned int dstorg, unsigned int length );
extern int drmMGAAgpBlit( int fd, unsigned int planemask,
			  unsigned int src, int src_pitch,
			  unsigned int dst, int dst_pitch,
			  int delta_sx, int delta_sy,
			  int delta_dx, int delta_dy,
			  int height, int ydir );

/* R128 */

typedef struct {
   unsigned long sarea_priv_offset;
   int is_pci;
   int cce_mode;
   int cce_secure;
   int ring_size;
   int usec_timeout;
   unsigned int fb_bpp;
   unsigned int front_offset, front_pitch;
   unsigned int back_offset, back_pitch;
   unsigned int depth_bpp;
   unsigned int depth_offset, depth_pitch;
   unsigned int span_offset;
   unsigned long fb_offset;
   unsigned long mmio_offset;
   unsigned long ring_offset;
   unsigned long ring_rptr_offset;
   unsigned long buffers_offset;
   unsigned long agp_textures_offset;
} drmCompatR128Init;

extern int drmR128InitCCE( int fd, drmCompatR128Init *info );
extern int drmR128CleanupCCE( int fd );
extern int drmR128StartCCE( int fd );
extern int drmR128StopCCE( int fd );
extern int drmR128ResetCCE( int fd );
extern int drmR128WaitForIdleCCE( int fd );
extern int drmR128EngineReset( int fd );
extern int drmR128FullScreen( int fd, int enable );
extern int drmR128SwapBuffers( int fd );
extern int drmR128Clear( int fd, unsigned int flags,
			 unsigned int clear_color, unsigned int clear_depth,
			 unsigned int color_mask, unsigned int depth_mask );
extern int drmR128FlushVertexBuffer( int fd, int prim, int indx,
				     int count, int discard );
extern int drmR128FlushIndices( int fd, int prim, int indx,
				int start, int end, int discard );
extern int drmR128TextureBlit( int fd, int indx,
			       int offset, int pitch, int format,
			       int x, int y, int width, int height );
extern int drmR128WriteDepthSpan( int fd, int n, int x, int y,
				  const unsigned int depth[],
				  const unsigned char mask[] );
extern int drmR128WriteDepthPixels( int fd, int n,
				    const int x[], const int y[],
				    const unsigned int depth[],
				    const unsigned char mask[] );
extern int drmR128ReadDepthSpan( int fd, int n, int x, int y );
extern int drmR128ReadDepthPixels( int fd, int n,
				   const int x[], const int y[] );
extern int drmR128PolygonStipple( int fd, unsigned int *mask );
extern int drmR128FlushIndirectBuffer( int fd, int indx,
				       int start, int end, int discard );

/* Radeon */

typedef struct {
   unsigned long sarea_priv_offset;
   int is_pci;
   int cp_mode;
   int agp_size;
   int ring_size;
   int usec_timeout;

   unsigned int fb_bpp;
   unsigned int front_offset, front_pitch;
   unsigned int back_offset, back_pitch;
   unsigned int depth_bpp;
   unsigned int depth_offset, depth_pitch;

   unsigned long fb_offset;
   unsigned long mmio_offset;
   unsigned long ring_offset;
   unsigned long ring_rptr_offset;
   unsigned long buffers_offset;
   unsigned long agp_textures_offset;
} drmCompatRadeonInit;

typedef struct {
   unsigned int x;
   unsigned int y;
   unsigned int width;
   unsigned int height;
   void *data;
} drmCompatRadeonTexImage;

extern int drmRadeonInitCP( int fd, drmCompatRadeonInit *info );
extern int drmRadeonCleanupCP( int fd );
extern int drmRadeonStartCP( int fd );
extern int drmRadeonStopCP( int fd );
extern int drmRadeonResetCP( int fd );
extern int drmRadeonWaitForIdleCP( int fd );
extern int drmRadeonEngineReset( int fd );
extern int drmRadeonFullScreen( int fd, int enable );
extern int drmRadeonSwapBuffers( int fd );
extern int drmRadeonClear( int fd, unsigned int flags,
			   unsigned int clear_color, unsigned int clear_depth,
			   unsigned int color_mask, unsigned int stencil,
			   void *boxes, int nbox );
extern int drmRadeonFlushVertexBuffer( int fd, int prim, int indx,
				       int count, int discard );
extern int drmRadeonFlushIndices( int fd, int prim, int indx,
				  int start, int end, int discard );
extern int drmRadeonLoadTexture( int fd, int offset, int pitch, int format,
				 int width, int height,
				 drmCompatRadeonTexImage *image );
extern int drmRadeonPolygonStipple( int fd, unsigned int *mask );
extern int drmRadeonFlushIndirectBuffer( int fd, int indx,
					 int start, int end, int discard );

/* SiS */
extern Bool drmSiSAgpInit(int driSubFD, int offset, int size);

/* I830 */
typedef struct {
   unsigned int start;
   unsigned int end;
   unsigned int size;
   unsigned int mmio_offset;
   unsigned int buffers_offset;
   int sarea_off;
   unsigned int front_offset;
   unsigned int back_offset;
   unsigned int depth_offset;
   unsigned int w;
   unsigned int h;
   unsigned int pitch;
   unsigned int pitch_bits;
   unsigned int cpp;
} drmCompatI830Init;

extern Bool drmI830CleanupDma(int driSubFD);
extern Bool drmI830InitDma(int driSubFD, drmCompatI830Init *info );

#endif

/* WARNING: Do not change, or add, anything to this file.  It is only provided
 * for binary backwards compatability with the old driver specific DRM 
 * extensions used before XFree86 4.3.
 */




More information about the xserver-commit mailing list