Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xfree86 / x86emu / x86emu / prim_x86_gcc.h
CommitLineData
a09e091a
JB
1/****************************************************************************
2*
3* Inline helpers for x86emu
4*
5* Copyright (C) 2008 Bart Trojanowski, Symbio Technologies, LLC
6*
7* ========================================================================
8*
9* Permission to use, copy, modify, distribute, and sell this software and
10* its documentation for any purpose is hereby granted without fee,
11* provided that the above copyright notice appear in all copies and that
12* both that copyright notice and this permission notice appear in
13* supporting documentation, and that the name of the authors not be used
14* in advertising or publicity pertaining to distribution of the software
15* without specific, written prior permission. The authors makes no
16* representations about the suitability of this software for any purpose.
17* It is provided "as is" without express or implied warranty.
18*
19* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
20* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
21* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
22* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
23* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25* PERFORMANCE OF THIS SOFTWARE.
26*
27* ========================================================================
28*
29* Language: GNU C
30* Environment: GCC on i386 or x86-64
31* Developer: Bart Trojanowski
32*
33* Description: This file defines a few x86 macros that can be used by the
34* emulator to execute native instructions.
35*
36* For PIC vs non-PIC code refer to:
37* http://sam.zoy.org/blog/2007-04-13-shlib-with-non-pic-code-have-inline-assembly-and-pic-mix-well
38*
39****************************************************************************/
40#ifndef __X86EMU_PRIM_X86_GCC_H
41#define __X86EMU_PRIM_X86_GCC_H
42
43#include "x86emu/types.h"
44
45#if !defined(__GNUC__) || !(defined (__i386__) || defined(__i386) || defined(__AMD64__) || defined(__amd64__))
46#error This file is intended to be used by gcc on i386 or x86-64 system
47#endif
48
49#if defined(__PIC__) && defined(__i386__)
50
51#define X86EMU_HAS_HW_CPUID 1
52static inline void
53hw_cpuid(u32 * a, u32 * b, u32 * c, u32 * d)
54{
55 __asm__ __volatile__("pushl %%ebx \n\t"
56 "cpuid \n\t"
57 "movl %%ebx, %1 \n\t"
58 "popl %%ebx \n\t":"=a"(*a), "=r"(*b),
59 "=c"(*c), "=d"(*d)
60 :"a"(*a), "c"(*c)
61 :"cc");
62}
63
64#else /* ! (__PIC__ && __i386__) */
65
66#define x86EMU_HAS_HW_CPUID 1
67static inline void
68hw_cpuid(u32 * a, u32 * b, u32 * c, u32 * d)
69{
70 __asm__ __volatile__("cpuid":"=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d)
71 :"a"(*a), "c"(*c)
72 :"cc");
73}
74
75#endif /* __PIC__ && __i386__ */
76
77#endif /* __X86EMU_PRIM_X86_GCC_H */