vendorcode/amd: Unify gcc-intrin.h

Most of these functions go unused most of the time, but in order
to not keep several copies around, let's make sure we are using
the same file everywhere first.

Change-Id: Ie121e67f3663410fd2860b7d619e8a679c57caba
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-on: https://review.coreboot.org/20325
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Stefan Reinauer
2017-06-24 21:50:10 +02:00
parent 82890928d3
commit 069c11e8b3
9 changed files with 572 additions and 1446 deletions

View File

@ -612,40 +612,4 @@ static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)
} }
#endif /* __SSE3__ */ #endif /* __SSE3__ */
static __inline__ __attribute__((always_inline)) void __stosb(unsigned char *dest, unsigned char data, size_t count)
{
__asm__ __volatile__ (
"rep ; stosb "
: "+D" (dest), "+c" (count)
: "a"(data)
);
}
static __inline__ __attribute__((always_inline)) void __movsb(unsigned char *dest, unsigned char *data, size_t count)
{
__asm__ __volatile__ (
"movsb "
: "+D" (dest), "+S"(data), "+c" (count)
);
}
static __inline__ __attribute__((always_inline))
void debug_point ( unsigned short Port, unsigned long Data )
{
__outdword (Port, Data);
__asm__ __volatile__ (".word 0xfeeb");
}
static __inline__ __attribute__((always_inline))
void delay_point ( unsigned short Port, unsigned long Data, unsigned long delayTime )
{
UINTN Index;
Index = 0;
__outdword (Port, Data);
while (Index < delayTime * 600000) {
__outdword (0xE0, 0);
Index ++;
}
}
#endif /* defined (__GNUC__) */ #endif /* defined (__GNUC__) */

View File

@ -612,40 +612,4 @@ static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)
} }
#endif /* __SSE3__ */ #endif /* __SSE3__ */
static __inline__ __attribute__((always_inline)) void __stosb(unsigned char *dest, unsigned char data, size_t count)
{
__asm__ __volatile__ (
"rep ; stosb "
: "+D" (dest), "+c" (count)
: "a"(data)
);
}
static __inline__ __attribute__((always_inline)) void __movsb(unsigned char *dest, unsigned char *data, size_t count)
{
__asm__ __volatile__ (
"movsb "
: "+D" (dest), "+S"(data), "+c" (count)
);
}
static __inline__ __attribute__((always_inline))
void debug_point ( unsigned short Port, unsigned long Data )
{
__outdword (Port, Data);
__asm__ __volatile__ (".word 0xfeeb");
}
static __inline__ __attribute__((always_inline))
void delay_point ( unsigned short Port, unsigned long Data, unsigned long delayTime )
{
UINTN Index;
Index = 0;
__outdword (Port, Data);
while (Index < delayTime * 600000) {
__outdword (0xE0, 0);
Index ++;
}
}
#endif /* defined (__GNUC__) */ #endif /* defined (__GNUC__) */

View File

@ -612,40 +612,4 @@ static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)
} }
#endif /* __SSE3__ */ #endif /* __SSE3__ */
static __inline__ __attribute__((always_inline)) void __stosb(unsigned char *dest, unsigned char data, size_t count)
{
__asm__ __volatile__ (
"rep ; stosb "
: "+D" (dest), "+c" (count)
: "a"(data)
);
}
static __inline__ __attribute__((always_inline)) void __movsb(unsigned char *dest, unsigned char *data, size_t count)
{
__asm__ __volatile__ (
"movsb "
: "+D" (dest), "+S"(data), "+c" (count)
);
}
static __inline__ __attribute__((always_inline))
void debug_point ( unsigned short Port, unsigned long Data )
{
__outdword (Port, Data);
__asm__ __volatile__ (".word 0xfeeb");
}
static __inline__ __attribute__((always_inline))
void delay_point ( unsigned short Port, unsigned long Data, unsigned long delayTime )
{
UINTN Index;
Index = 0;
__outdword (Port, Data);
while (Index < delayTime * 600000) {
__outdword (0xE0, 0);
Index ++;
}
}
#endif /* defined (__GNUC__) */ #endif /* defined (__GNUC__) */

View File

@ -612,40 +612,4 @@ static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)
} }
#endif /* __SSE3__ */ #endif /* __SSE3__ */
static __inline__ __attribute__((always_inline)) void __stosb(unsigned char *dest, unsigned char data, size_t count)
{
__asm__ __volatile__ (
"rep ; stosb "
: "+D" (dest), "+c" (count)
: "a"(data)
);
}
static __inline__ __attribute__((always_inline)) void __movsb(unsigned char *dest, unsigned char *data, size_t count)
{
__asm__ __volatile__ (
"movsb "
: "+D" (dest), "+S"(data), "+c" (count)
);
}
static __inline__ __attribute__((always_inline))
void debug_point ( unsigned short Port, unsigned long Data )
{
__outdword (Port, Data);
__asm__ __volatile__ (".word 0xfeeb");
}
static __inline__ __attribute__((always_inline))
void delay_point ( unsigned short Port, unsigned long Data, unsigned long delayTime )
{
UINTN Index;
Index = 0;
__outdword (Port, Data);
while (Index < delayTime * 600000) {
__outdword (0xE0, 0);
Index ++;
}
}
#endif /* defined (__GNUC__) */ #endif /* defined (__GNUC__) */

View File

@ -612,40 +612,4 @@ static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)
} }
#endif /* __SSE3__ */ #endif /* __SSE3__ */
static __inline__ __attribute__((always_inline)) void __stosb(unsigned char *dest, unsigned char data, size_t count)
{
__asm__ __volatile__ (
"rep ; stosb "
: "+D" (dest), "+c" (count)
: "a"(data)
);
}
static __inline__ __attribute__((always_inline)) void __movsb(unsigned char *dest, unsigned char *data, size_t count)
{
__asm__ __volatile__ (
"movsb "
: "+D" (dest), "+S"(data), "+c" (count)
);
}
static __inline__ __attribute__((always_inline))
void debug_point ( unsigned short Port, unsigned long Data )
{
__outdword (Port, Data);
__asm__ __volatile__ (".word 0xfeeb");
}
static __inline__ __attribute__((always_inline))
void delay_point ( unsigned short Port, unsigned long Data, unsigned long delayTime )
{
UINTN Index;
Index = 0;
__outdword (Port, Data);
while (Index < delayTime * 600000) {
__outdword (0xE0, 0);
Index ++;
}
}
#endif /* defined (__GNUC__) */ #endif /* defined (__GNUC__) */

View File

@ -1,46 +1,37 @@
/* /*
Compatibility <intrin_x86.h> header for GCC -- GCC equivalents of intrinsic * Copyright (c) 2011, Advanced Micro Devices, Inc. All rights reserved.
Microsoft Visual C++ functions. Originally developed for the ReactOS * Copyright (c) 2014, Edward O'Callaghan <eocallaghan@alterapraxis.com>
(<http://www.reactos.org/>) and TinyKrnl (<http://www.tinykrnl.org/>) *
projects. * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Copyright (c) 2006 KJK::Hyperion <hackbunny@reactos.com> * * Redistributions of source code must retain the above copyright
2014 Edward O'Callaghan <eocallaghan@alterapraxis.com> * notice, this list of conditions and the following disclaimer.
2014 Sage Electronic Engineering, LLC * * Redistributions in binary form must reproduce the above copyright
All rights reserved. * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
Permission is hereby granted, free of charge, to any person obtaining a * * Neither the name of Advanced Micro Devices, Inc. nor the names of
copy of this software and associated documentation files (the "Software"), * its contributors may be used to endorse or promote products derived
to deal in the Software without restriction, including without limitation * from this software without specific prior written permission.
the rights to use, copy, modify, merge, publish, distribute, sublicense, *
and/or sell copies of the Software, and to permit persons to whom the * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Software is furnished to do so, subject to the following conditions: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
The above copyright notice and this permission notice shall be included in * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
all copies or substantial portions of the Software. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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.
*/ */
#if defined (__GNUC__) #if defined (__GNUC__)
#include <stdint.h>
#if !defined(AMDLIB_OPTIMIZE)
#define AMDLIB_OPTIMIZE
#endif
/* I/O intrin functions. */ /* I/O intrin functions. */
static static __inline__ __attribute__((always_inline)) uint8_t __inbyte(uint16_t Port)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned char __inbyte(unsigned short Port)
{ {
unsigned char value; uint8_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %1, %0" "in %1, %0"
@ -51,12 +42,9 @@ unsigned char __inbyte(unsigned short Port)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint16_t __inword(uint16_t Port)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned short __inword(unsigned short Port)
{ {
unsigned short value; uint16_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %1, %0" "in %1, %0"
@ -67,12 +55,9 @@ unsigned short __inword(unsigned short Port)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint32_t __indword(uint16_t Port)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __indword(unsigned short Port)
{ {
unsigned long value; uint32_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %1, %0" "in %1, %0"
@ -83,10 +68,7 @@ unsigned long __indword(unsigned short Port)
} }
static static __inline__ __attribute__((always_inline)) void __outbyte(uint16_t Port,uint8_t Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outbyte(unsigned short Port,unsigned char Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %0, %1" "out %0, %1"
@ -95,10 +77,7 @@ void __outbyte(unsigned short Port,unsigned char Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outword(uint16_t Port,uint16_t Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outword(unsigned short Port,unsigned short Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %0, %1" "out %0, %1"
@ -107,10 +86,7 @@ void __outword(unsigned short Port,unsigned short Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outdword(uint16_t Port,uint32_t Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outdword(unsigned short Port,unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %0, %1" "out %0, %1"
@ -119,10 +95,7 @@ void __outdword(unsigned short Port,unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __inbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __inbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; insb" "rep ; insb"
@ -131,10 +104,7 @@ void __inbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Coun
); );
} }
static static __inline__ __attribute__((always_inline)) void __inwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __inwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; insw" "rep ; insw"
@ -143,10 +113,7 @@ void __inwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Cou
); );
} }
static static __inline__ __attribute__((always_inline)) void __indwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __indwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; insl" "rep ; insl"
@ -155,10 +122,7 @@ void __indwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Cou
); );
} }
static static __inline__ __attribute__((always_inline)) void __outbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; outsb" "rep ; outsb"
@ -167,10 +131,7 @@ void __outbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Cou
); );
} }
static static __inline__ __attribute__((always_inline)) void __outwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; outsw" "rep ; outsw"
@ -179,10 +140,7 @@ void __outwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Co
); );
} }
static static __inline__ __attribute__((always_inline)) void __outdwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outdwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; outsl" "rep ; outsl"
@ -191,10 +149,7 @@ void __outdwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Co
); );
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr0(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr0(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -204,10 +159,7 @@ unsigned long __readdr0(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr1(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr1(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -217,10 +169,7 @@ unsigned long __readdr1(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr2(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr2(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -230,10 +179,7 @@ unsigned long __readdr2(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr3(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr3(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -243,10 +189,7 @@ unsigned long __readdr3(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr7(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr7(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -256,10 +199,7 @@ unsigned long __readdr7(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr(unsigned long reg)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr(unsigned long reg)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -284,14 +224,10 @@ unsigned long __readdr(unsigned long reg)
default: default:
return -1; return -1;
break;
} }
} }
static static __inline__ __attribute__((always_inline)) void __writedr0(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr0(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr0" "mov %0, %%dr0"
@ -300,10 +236,7 @@ void __writedr0(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr1(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr1(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr1" "mov %0, %%dr1"
@ -312,10 +245,7 @@ void __writedr1(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr2(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr2(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr2" "mov %0, %%dr2"
@ -324,10 +254,7 @@ void __writedr2(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr3(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr3(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr3" "mov %0, %%dr3"
@ -336,10 +263,7 @@ void __writedr3(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr7(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr7(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr7" "mov %0, %%dr7"
@ -348,10 +272,7 @@ void __writedr7(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr(unsigned long reg, unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr(unsigned long reg, unsigned long Data)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -375,14 +296,11 @@ void __writedr(unsigned long reg, unsigned long Data)
break; break;
default: default:
break; ;
} }
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr0(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr0(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -391,10 +309,7 @@ unsigned long __readcr0(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr2(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr2(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -403,10 +318,7 @@ unsigned long __readcr2(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr3(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr3(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -415,10 +327,7 @@ unsigned long __readcr3(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr4(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr4(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -427,10 +336,7 @@ unsigned long __readcr4(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr8(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr8(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -439,10 +345,7 @@ unsigned long __readcr8(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr(unsigned long reg)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr(unsigned long reg)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -467,14 +370,10 @@ unsigned long __readcr(unsigned long reg)
default: default:
return -1; return -1;
break;
} }
} }
static static __inline__ __attribute__((always_inline)) void __writecr0(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr0(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr0" "mov %0, %%cr0"
@ -484,10 +383,7 @@ void __writecr0(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr2(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr2(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr2" "mov %0, %%cr2"
@ -496,10 +392,7 @@ void __writecr2(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr3(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr3(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr3" "mov %0, %%cr3"
@ -508,10 +401,7 @@ void __writecr3(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr4(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr4(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr4" "mov %0, %%cr4"
@ -520,10 +410,7 @@ void __writecr4(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr8(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr8(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr8" "mov %0, %%cr8"
@ -532,10 +419,7 @@ void __writecr8(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr(unsigned long reg, unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr(unsigned long reg, unsigned long Data)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -559,14 +443,11 @@ void __writecr(unsigned long reg, unsigned long Data)
break; break;
default: default:
break; ;
} }
} }
static static __inline__ __attribute__((always_inline)) UINT64 __readmsr(UINT32 msr)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
UINT64 __readmsr(UINT32 msr)
{ {
UINT64 retval; UINT64 retval;
__asm__ __volatile__( __asm__ __volatile__(
@ -577,10 +458,7 @@ UINT64 __readmsr(UINT32 msr)
return retval; return retval;
} }
static static __inline__ __attribute__((always_inline)) void __writemsr (UINT32 msr, UINT64 Value)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writemsr (UINT32 msr, UINT64 Value)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"wrmsr" "wrmsr"
@ -589,10 +467,7 @@ void __writemsr (UINT32 msr, UINT64 Value)
); );
} }
static static __inline__ __attribute__((always_inline)) UINT64 __rdtsc(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
UINT64 __rdtsc(void)
{ {
UINT64 retval; UINT64 retval;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -601,10 +476,7 @@ UINT64 __rdtsc(void)
return retval; return retval;
} }
static static __inline__ __attribute__((always_inline)) void __cpuid(int CPUInfo[], const int InfoType)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __cpuid(int CPUInfo[], const int InfoType)
{ {
__asm__ __volatile__( __asm__ __volatile__(
"cpuid" "cpuid"
@ -613,96 +485,71 @@ void __cpuid(int CPUInfo[], const int InfoType)
); );
} }
static
AMDLIB_OPTIMIZE static __inline__ __attribute__((always_inline)) void _disable(void)
__inline__ __attribute__((always_inline))
void _disable(void)
{ {
__asm__ __volatile__ ("cli"); __asm__ __volatile__ ("cli");
} }
static
AMDLIB_OPTIMIZE static __inline__ __attribute__((always_inline)) void _enable(void)
__inline__ __attribute__((always_inline))
void _enable(void)
{ {
__asm__ __volatile__ ("sti"); __asm__ __volatile__ ("sti");
} }
static
AMDLIB_OPTIMIZE static __inline__ __attribute__((always_inline)) void __halt(void)
__inline__ __attribute__((always_inline))
void __halt(void)
{ {
__asm__ __volatile__ ("hlt"); __asm__ __volatile__ ("hlt");
} }
static
AMDLIB_OPTIMIZE static __inline__ __attribute__((always_inline)) void __debugbreak(void)
__inline__ __attribute__((always_inline))
void __debugbreak(void)
{ {
__asm__ __volatile__ ("int3"); __asm__ __volatile__ ("int3");
} }
static static __inline__ __attribute__((always_inline)) void __invd(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __invd(void)
{ {
__asm__ __volatile__ ("invd"); __asm__ __volatile__ ("invd");
} }
static static __inline__ __attribute__((always_inline)) void __wbinvd(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __wbinvd(void)
{ {
__asm__ __volatile__ ("wbinvd"); __asm__ __volatile__ ("wbinvd");
} }
static static __inline__ __attribute__((always_inline)) void __lidt(void *Source)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __lidt(void *Source)
{ {
__asm__ __volatile__("lidt %0" : : "m"(*(short*)Source)); __asm__ __volatile__("lidt %0" : : "m"(*(short*)Source));
} }
static static __inline__ __attribute__((always_inline)) void
AMDLIB_OPTIMIZE __writefsbyte(const unsigned long Offset, const uint8_t Data)
__inline__ __attribute__((always_inline))
void __writefsbyte(const unsigned long Offset, const unsigned char Data)
{ {
__asm__ ("movb %[Data], %%fs:%a[Offset]" __asm__ ("movb %[Data], %%fs:%a[Offset]"
: :
: [Offset] "ir" (Offset), [Data] "iq" (Data)); : [Offset] "ir" (Offset), [Data] "iq" (Data));
} }
static static __inline__ __attribute__((always_inline)) void
AMDLIB_OPTIMIZE __writefsword(const unsigned long Offset, const uint16_t Data)
__inline__ __attribute__((always_inline))
void __writefsword(const unsigned long Offset, const unsigned short Data)
{ {
__asm__ ("movw %[Data], %%fs:%a[Offset]" __asm__ ("movw %[Data], %%fs:%a[Offset]"
: :
: [Offset] "ir" (Offset), [Data] "ir" (Data)); : [Offset] "ir" (Offset), [Data] "ir" (Data));
} }
static static __inline__ __attribute__((always_inline)) void
AMDLIB_OPTIMIZE __writefsdword(const unsigned long Offset, const uint32_t Data)
__inline__ __attribute__((always_inline))
void __writefsdword(const unsigned long Offset, const unsigned long Data)
{ {
__asm__ ("movl %[Data], %%fs:%a[Offset]" __asm__ ("movl %[Data], %%fs:%a[Offset]"
: :
: [Offset] "ir" (Offset), [Data] "ir" (Data)); : [Offset] "ir" (Offset), [Data] "ir" (Data));
} }
static static __inline__ __attribute__((always_inline)) uint8_t
AMDLIB_OPTIMIZE __readfsbyte(const unsigned long Offset)
__inline__ __attribute__((always_inline))
unsigned char __readfsbyte(const unsigned long Offset)
{ {
unsigned char value; unsigned char value;
__asm__ ("movb %%fs:%a[Offset], %[value]" __asm__ ("movb %%fs:%a[Offset], %[value]"
@ -711,10 +558,8 @@ unsigned char __readfsbyte(const unsigned long Offset)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint16_t
AMDLIB_OPTIMIZE __readfsword(const unsigned long Offset)
__inline__ __attribute__((always_inline))
unsigned short __readfsword(const unsigned long Offset)
{ {
unsigned short value; unsigned short value;
__asm__ ("movw %%fs:%a[Offset], %[value]" __asm__ ("movw %%fs:%a[Offset], %[value]"
@ -723,13 +568,11 @@ unsigned short __readfsword(const unsigned long Offset)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint32_t
AMDLIB_OPTIMIZE __readfsdword(unsigned long Offset)
__inline__ __attribute__((always_inline))
unsigned long __readfsdword(unsigned long Offset)
{ {
unsigned long value; unsigned long value;
__asm__ ("movl %%fs:%a[Offset], %[value]" __asm__ ("mov %%fs:%a[Offset], %[value]"
: [value] "=r" (value) : [value] "=r" (value)
: [Offset] "ir" (Offset)); : [Offset] "ir" (Offset));
return value; return value;
@ -739,95 +582,34 @@ unsigned long __readfsdword(unsigned long Offset)
typedef long long __v2di __attribute__ ((__vector_size__ (16))); typedef long long __v2di __attribute__ ((__vector_size__ (16)));
typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__)); typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
static static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs2 (void *__A, __m128i __B)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_stream_si128_fs2 (void *__A, __m128i __B)
{ {
__asm__(".byte 0x64"); // fs prefix __asm__(".byte 0x64"); // fs prefix
__builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B); __builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B);
} }
static static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs (void *__A, void *__B)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_stream_si128_fs (void *__A, void *__B)
{ {
__m128i data; __m128i data;
data = (__m128i) __builtin_ia32_lddqu ((char const *)__B); data = (__m128i) __builtin_ia32_lddqu ((char const *)__B);
_mm_stream_si128_fs2 (__A, data); _mm_stream_si128_fs2 (__A, data);
} }
static static __inline__ __attribute__((always_inline)) void _mm_clflush_fs (void *__A)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_clflush_fs (void *__A)
{ {
__asm__(".byte 0x64"); // fs prefix __asm__(".byte 0x64"); // fs prefix
__builtin_ia32_clflush (__A); __builtin_ia32_clflush (__A);
} }
static static __inline __attribute__(( __always_inline__)) void _mm_mfence (void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_mfence (void)
{ {
__builtin_ia32_mfence (); __builtin_ia32_mfence ();
} }
static static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_sfence (void)
{ {
__builtin_ia32_sfence (); __builtin_ia32_sfence ();
} }
#endif /* __SSE3__ */ #endif /* __SSE3__ */
static
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __stosb(unsigned char *dest, unsigned char data, size_t count)
{
__asm__ __volatile__ (
"rep ; stosb "
: "+D" (dest), "+c" (count)
: "a"(data)
);
}
static
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __movsb(unsigned char *dest, unsigned char *data, size_t count)
{
__asm__ __volatile__ (
"movsb "
: "+D" (dest), "+S"(data), "+c" (count)
);
}
static
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void debug_point ( unsigned short Port, unsigned long Data )
{
__outdword (Port, Data);
__asm__ __volatile__ (".word 0xfeeb");
}
static
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void delay_point ( unsigned short Port, unsigned long Data, unsigned long delayTime )
{
UINTN Index;
Index = 0;
__outdword (Port, Data);
while (Index < delayTime * 600000) {
__outdword (0xE0, 0);
Index ++;
}
}
#endif /* defined (__GNUC__) */ #endif /* defined (__GNUC__) */

View File

@ -1,241 +1,205 @@
/* /*
Compatibility <intrin_x86.h> header for GCC -- GCC equivalents of intrinsic * Copyright (c) 2011, Advanced Micro Devices, Inc. All rights reserved.
Microsoft Visual C++ functions. Originally developed for the ReactOS * Copyright (c) 2014, Edward O'Callaghan <eocallaghan@alterapraxis.com>
(<http://www.reactos.org/>) and TinyKrnl (<http://www.tinykrnl.org/>) *
projects. * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Copyright (c) 2006 KJK::Hyperion <hackbunny@reactos.com> * * Redistributions of source code must retain the above copyright
2014 Sage Electronic Engineering, LLC * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
Permission is hereby granted, free of charge, to any person obtaining a * notice, this list of conditions and the following disclaimer in the
copy of this software and associated documentation files (the "Software"), * documentation and/or other materials provided with the distribution.
to deal in the Software without restriction, including without limitation * * Neither the name of Advanced Micro Devices, Inc. nor the names of
the rights to use, copy, modify, merge, publish, distribute, sublicense, * its contributors may be used to endorse or promote products derived
and/or sell copies of the Software, and to permit persons to whom the * from this software without specific prior written permission.
Software is furnished to do so, subject to the following conditions: *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
The above copyright notice and this permission notice shall be included in * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
all copies or substantial portions of the Software. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
DEALINGS IN THE SOFTWARE. *
*/ */
#if defined (__GNUC__) #if defined (__GNUC__)
#include <stdint.h>
/* I/O intrin functions. */ /* I/O intrin functions. */
static static __inline__ __attribute__((always_inline)) uint8_t __inbyte(uint16_t Port)
__inline__ __attribute__((always_inline))
unsigned char __inbyte(unsigned short Port)
{ {
unsigned char value; uint8_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %%dx, %%al" "in %1, %0"
: "=a" (value) : "=a" (value)
: "d" (Port) : "Nd" (Port)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint16_t __inword(uint16_t Port)
__inline__ __attribute__((always_inline))
unsigned short __inword(unsigned short Port)
{ {
unsigned short value; uint16_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %%dx, %%ax" "in %1, %0"
: "=a" (value) : "=a" (value)
: "d" (Port) : "Nd" (Port)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint32_t __indword(uint16_t Port)
__inline__ __attribute__((always_inline))
unsigned long __indword(unsigned short Port)
{ {
unsigned long value; uint32_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %%dx, %%eax" "in %1, %0"
: "=a" (value) : "=a" (value)
: "d" (Port) : "Nd" (Port)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) void __outbyte(uint16_t Port,uint8_t Data)
__inline__ __attribute__((always_inline))
void __outbyte(unsigned short Port,unsigned char Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %%al, %%dx" "out %0, %1"
: :
: "a" (Data), "d" (Port) : "a" (Data), "Nd" (Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outword(uint16_t Port,uint16_t Data)
__inline__ __attribute__((always_inline))
void __outword(unsigned short Port,unsigned short Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %%ax, %%dx" "out %0, %1"
: :
: "a" (Data), "d" (Port) : "a" (Data), "Nd" (Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outdword(uint16_t Port,uint32_t Data)
__inline__ __attribute__((always_inline))
void __outdword(unsigned short Port,unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %%eax, %%dx" "out %0, %1"
: :
: "a" (Data), "d" (Port) : "a" (Data), "Nd" (Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __inbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __inbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; insb " "rep ; insb"
: "=D" (Buffer), "=c" (Count) : "+D" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __inwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __inwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; insw " "rep ; insw"
: "=D" (Buffer), "=c" (Count) : "+D" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __indwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __indwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; insl " "rep ; insl"
: "=D" (Buffer), "=c" (Count) : "+D" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __outbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; outsb " "rep ; outsb"
: "=S" (Buffer), "=c" (Count) : "+S" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __outwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; outsw " "rep ; outsw"
: "=S" (Buffer), "=c" (Count) : "+S" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outdwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __outdwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; outsl " "rep ; outsl"
: "=S" (Buffer), "=c" (Count) : "+S" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr0(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr0(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr0, %[value]" "mov %%dr0, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr1(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr1(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr1, %[value]" "mov %%dr1, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr2(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr2(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr2, %[value]" "mov %%dr2, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr3(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr3(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr3, %[value]" "mov %%dr3, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr7(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr7(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr7, %[value]" "mov %%dr7, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr(unsigned long reg)
__inline__ __attribute__((always_inline))
unsigned long __readdr(unsigned long reg)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -263,64 +227,52 @@ unsigned long __readdr(unsigned long reg)
} }
} }
static static __inline__ __attribute__((always_inline)) void __writedr0(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr0(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr0" "mov %0, %%dr0"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr1(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr1(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr1" "mov %0, %%dr1"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr2(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr2(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr2" "mov %0, %%dr2"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr3(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr3(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr3" "mov %0, %%dr3"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr7(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr7(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr7" "mov %0, %%dr7"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr(unsigned long reg, unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr(unsigned long reg, unsigned long Data)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -348,64 +300,52 @@ void __writedr(unsigned long reg, unsigned long Data)
} }
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr0(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr0(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr0, %[value]" "mov %%cr0, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr2(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr2(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr2, %[value]" "mov %%cr2, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr3(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr3(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr3, %[value]" "mov %%cr3, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr4(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr4(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr4, %[value]" "mov %%cr4, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr8(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr8(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr8, %[value]" "mov %%cr8, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr(unsigned long reg)
__inline__ __attribute__((always_inline))
unsigned long __readcr(unsigned long reg)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -433,64 +373,53 @@ unsigned long __readcr(unsigned long reg)
} }
} }
static static __inline__ __attribute__((always_inline)) void __writecr0(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr0(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr0" "mov %0, %%cr0"
: :
: "a" (Data) : "r" (Data)
: "memory"
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr2(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr2(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr2" "mov %0, %%cr2"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr3(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr3(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr3" "mov %0, %%cr3"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr4(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr4(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr4" "mov %0, %%cr4"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr8(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr8(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr8" "mov %0, %%cr8"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr(unsigned long reg, unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr(unsigned long reg, unsigned long Data)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -518,33 +447,27 @@ void __writecr(unsigned long reg, unsigned long Data)
} }
} }
static static __inline__ __attribute__((always_inline)) UINT64 __readmsr(UINT32 msr)
__inline__ __attribute__((always_inline))
UINT64 __readmsr(UINT32 msr)
{ {
UINT64 retval; UINT64 retval;
__asm__ __volatile__( __asm__ __volatile__(
"rdmsr\n\t" "rdmsr"
: "=A" (retval) : "=A" (retval)
: "c" (msr) : "c" (msr)
); );
return retval; return retval;
} }
static static __inline__ __attribute__((always_inline)) void __writemsr (UINT32 msr, UINT64 Value)
__inline__ __attribute__((always_inline))
void __writemsr (UINT32 msr, UINT64 Value)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"wrmsr\n\t" "wrmsr"
: :
: "c" (msr), "A" (Value) : "c" (msr), "A" (Value)
); );
} }
static static __inline__ __attribute__((always_inline)) UINT64 __rdtsc(void)
__inline__ __attribute__((always_inline))
UINT64 __rdtsc(void)
{ {
UINT64 retval; UINT64 retval;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -553,9 +476,7 @@ UINT64 __rdtsc(void)
return retval; return retval;
} }
static static __inline__ __attribute__((always_inline)) void __cpuid(int CPUInfo[], const int InfoType)
__inline__ __attribute__((always_inline))
void __cpuid(int CPUInfo[], const int InfoType)
{ {
__asm__ __volatile__( __asm__ __volatile__(
"cpuid" "cpuid"
@ -564,93 +485,96 @@ void __cpuid(int CPUInfo[], const int InfoType)
); );
} }
static
__inline__ __attribute__((always_inline)) static __inline__ __attribute__((always_inline)) void _disable(void)
void _disable(void)
{ {
__asm__ __volatile__ ("cli"); __asm__ __volatile__ ("cli");
} }
static
__inline__ __attribute__((always_inline)) static __inline__ __attribute__((always_inline)) void _enable(void)
void _enable(void)
{ {
__asm__ __volatile__ ("sti"); __asm__ __volatile__ ("sti");
} }
static
__inline__ __attribute__((always_inline)) static __inline__ __attribute__((always_inline)) void __halt(void)
void __halt(void)
{ {
__asm__ __volatile__ ("hlt"); __asm__ __volatile__ ("hlt");
} }
static
__inline__ __attribute__((always_inline)) static __inline__ __attribute__((always_inline)) void __debugbreak(void)
void __debugbreak(void)
{ {
__asm__ __volatile__ ("int3"); __asm__ __volatile__ ("int3");
} }
static static __inline__ __attribute__((always_inline)) void __invd(void)
__inline__ __attribute__((always_inline)) {
void __wbinvd(void) __asm__ __volatile__ ("invd");
}
static __inline__ __attribute__((always_inline)) void __wbinvd(void)
{ {
__asm__ __volatile__ ("wbinvd"); __asm__ __volatile__ ("wbinvd");
} }
static static __inline__ __attribute__((always_inline)) void __lidt(void *Source)
__inline__ __attribute__((always_inline))
void __lidt(void *Source)
{ {
__asm__ __volatile__("lidt %0" : : "m"(*(short*)Source)); __asm__ __volatile__("lidt %0" : : "m"(*(short*)Source));
} }
static static __inline__ __attribute__((always_inline)) void
__inline__ __attribute__((always_inline)) __writefsbyte(const unsigned long Offset, const uint8_t Data)
void __writefsbyte(const unsigned long Offset, const unsigned char Data)
{ {
__asm__("movb %b[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data)); __asm__ ("movb %[Data], %%fs:%a[Offset]"
:
: [Offset] "ir" (Offset), [Data] "iq" (Data));
} }
static static __inline__ __attribute__((always_inline)) void
__inline__ __attribute__((always_inline)) __writefsword(const unsigned long Offset, const uint16_t Data)
void __writefsword(const unsigned long Offset, const unsigned short Data)
{ {
__asm__("movw %w[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data)); __asm__ ("movw %[Data], %%fs:%a[Offset]"
:
: [Offset] "ir" (Offset), [Data] "ir" (Data));
} }
static static __inline__ __attribute__((always_inline)) void
__inline__ __attribute__((always_inline)) __writefsdword(const unsigned long Offset, const uint32_t Data)
void __writefsdword(const unsigned long Offset, const unsigned long Data)
{ {
__asm__("movl %k[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data)); __asm__ ("movl %[Data], %%fs:%a[Offset]"
:
: [Offset] "ir" (Offset), [Data] "ir" (Data));
} }
static static __inline__ __attribute__((always_inline)) uint8_t
__inline__ __attribute__((always_inline)) __readfsbyte(const unsigned long Offset)
unsigned char __readfsbyte(const unsigned long Offset)
{ {
unsigned char value; unsigned char value;
__asm__("movb %%fs:%a[Offset], %b[value]" : [value] "=q" (value) : [Offset] "irm" (Offset)); __asm__ ("movb %%fs:%a[Offset], %[value]"
: [value] "=q" (value)
: [Offset] "ir" (Offset));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint16_t
__inline__ __attribute__((always_inline)) __readfsword(const unsigned long Offset)
unsigned short __readfsword(const unsigned long Offset)
{ {
unsigned short value; unsigned short value;
__asm__("movw %%fs:%a[Offset], %w[value]" : [value] "=q" (value) : [Offset] "irm" (Offset)); __asm__ ("movw %%fs:%a[Offset], %[value]"
: [value] "=q" (value)
: [Offset] "ir" (Offset));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint32_t
__inline__ __attribute__((always_inline)) __readfsdword(unsigned long Offset)
unsigned long __readfsdword(const unsigned long Offset)
{ {
unsigned long value; unsigned long value;
__asm__("movl %%fs:%a[Offset], %k[value]" : [value] "=q" (value) : [Offset] "irm" (Offset)); __asm__ ("mov %%fs:%a[Offset], %[value]"
: [value] "=r" (value)
: [Offset] "ir" (Offset));
return value; return value;
} }
@ -658,87 +582,34 @@ unsigned long __readfsdword(const unsigned long Offset)
typedef long long __v2di __attribute__ ((__vector_size__ (16))); typedef long long __v2di __attribute__ ((__vector_size__ (16)));
typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__)); typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
static static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs2 (void *__A, __m128i __B)
__inline__ __attribute__((always_inline))
void _mm_stream_si128_fs2 (void *__A, __m128i __B)
{ {
__asm__(".byte 0x64"); // fs prefix __asm__(".byte 0x64"); // fs prefix
__builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B); __builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B);
} }
static static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs (void *__A, void *__B)
__inline__ __attribute__((always_inline))
void _mm_stream_si128_fs (void *__A, void *__B)
{ {
__m128i data; __m128i data;
data = (__m128i) __builtin_ia32_lddqu ((char const *)__B); data = (__m128i) __builtin_ia32_lddqu ((char const *)__B);
_mm_stream_si128_fs2 (__A, data); _mm_stream_si128_fs2 (__A, data);
} }
static static __inline__ __attribute__((always_inline)) void _mm_clflush_fs (void *__A)
__inline__ __attribute__((always_inline))
void _mm_clflush_fs (void *__A)
{ {
__asm__(".byte 0x64"); // fs prefix __asm__(".byte 0x64"); // fs prefix
__builtin_ia32_clflush (__A); __builtin_ia32_clflush (__A);
} }
static static __inline __attribute__(( __always_inline__)) void _mm_mfence (void)
__inline__ __attribute__((always_inline))
void _mm_mfence (void)
{ {
__builtin_ia32_mfence (); __builtin_ia32_mfence ();
} }
static static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)
__inline__ __attribute__((always_inline))
void _mm_sfence (void)
{ {
__builtin_ia32_sfence (); __builtin_ia32_sfence ();
} }
#endif #endif /* __SSE3__ */
static #endif /* defined (__GNUC__) */
__inline__ __attribute__((always_inline))
void __stosb(unsigned char *dest, unsigned char data, size_t count)
{
__asm__ __volatile__ (
"cld ; rep ; stosb "
: "=D" (dest), "=c" (count)
: "a"(data), "0"(dest), "1" (count)
);
}
static
__inline__ __attribute__((always_inline))
void __movsb(unsigned char *dest, unsigned char *data, size_t count)
{
__asm__ __volatile__ (
"cld ; rep ; movsb "
: "=D" (dest), "=S"(data), "=c" (count)
: "S"(data), "0"(dest), "1" (count)
);
}
static
__inline__ __attribute__((always_inline))
void debug_point ( unsigned short Port, unsigned long Data )
{
__outdword (Port, Data);
__asm__ __volatile__ (".word 0xfeeb");
}
static
__inline__ __attribute__((always_inline))
void delay_point ( unsigned short Port, unsigned long Data, unsigned long delayTime )
{
UINTN Index;
Index = 0;
__outdword (Port, Data);
while (Index < delayTime * 600000) {
__outdword (0xE0, 0);
Index ++;
}
}
#endif // defined (__GNUC__)

View File

@ -1,241 +1,205 @@
/* /*
Compatibility <intrin_x86.h> header for GCC -- GCC equivalents of intrinsic * Copyright (c) 2011, Advanced Micro Devices, Inc. All rights reserved.
Microsoft Visual C++ functions. Originally developed for the ReactOS * Copyright (c) 2014, Edward O'Callaghan <eocallaghan@alterapraxis.com>
(<http://www.reactos.org/>) and TinyKrnl (<http://www.tinykrnl.org/>) *
projects. * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Copyright (c) 2006 KJK::Hyperion <hackbunny@reactos.com> * * Redistributions of source code must retain the above copyright
2014 Sage Electronic Engineering, LLC * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
Permission is hereby granted, free of charge, to any person obtaining a * notice, this list of conditions and the following disclaimer in the
copy of this software and associated documentation files (the "Software"), * documentation and/or other materials provided with the distribution.
to deal in the Software without restriction, including without limitation * * Neither the name of Advanced Micro Devices, Inc. nor the names of
the rights to use, copy, modify, merge, publish, distribute, sublicense, * its contributors may be used to endorse or promote products derived
and/or sell copies of the Software, and to permit persons to whom the * from this software without specific prior written permission.
Software is furnished to do so, subject to the following conditions: *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
The above copyright notice and this permission notice shall be included in * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
all copies or substantial portions of the Software. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
DEALINGS IN THE SOFTWARE. *
*/ */
#if defined (__GNUC__) #if defined (__GNUC__)
#include <stdint.h>
/* I/O intrin functions. */ /* I/O intrin functions. */
static static __inline__ __attribute__((always_inline)) uint8_t __inbyte(uint16_t Port)
__inline__ __attribute__((always_inline))
unsigned char __inbyte(unsigned short Port)
{ {
unsigned char value; uint8_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %%dx, %%al" "in %1, %0"
: "=a" (value) : "=a" (value)
: "d" (Port) : "Nd" (Port)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint16_t __inword(uint16_t Port)
__inline__ __attribute__((always_inline))
unsigned short __inword(unsigned short Port)
{ {
unsigned short value; uint16_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %%dx, %%ax" "in %1, %0"
: "=a" (value) : "=a" (value)
: "d" (Port) : "Nd" (Port)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint32_t __indword(uint16_t Port)
__inline__ __attribute__((always_inline))
unsigned long __indword(unsigned short Port)
{ {
unsigned long value; uint32_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %%dx, %%eax" "in %1, %0"
: "=a" (value) : "=a" (value)
: "d" (Port) : "Nd" (Port)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) void __outbyte(uint16_t Port,uint8_t Data)
__inline__ __attribute__((always_inline))
void __outbyte(unsigned short Port,unsigned char Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %%al, %%dx" "out %0, %1"
: :
: "a" (Data), "d" (Port) : "a" (Data), "Nd" (Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outword(uint16_t Port,uint16_t Data)
__inline__ __attribute__((always_inline))
void __outword(unsigned short Port,unsigned short Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %%ax, %%dx" "out %0, %1"
: :
: "a" (Data), "d" (Port) : "a" (Data), "Nd" (Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outdword(uint16_t Port,uint32_t Data)
__inline__ __attribute__((always_inline))
void __outdword(unsigned short Port,unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %%eax, %%dx" "out %0, %1"
: :
: "a" (Data), "d" (Port) : "a" (Data), "Nd" (Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __inbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __inbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; insb " "rep ; insb"
: "=D" (Buffer), "=c" (Count) : "+D" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __inwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __inwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; insw " "rep ; insw"
: "=D" (Buffer), "=c" (Count) : "+D" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __indwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __indwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; insl " "rep ; insl"
: "=D" (Buffer), "=c" (Count) : "+D" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __outbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; outsb " "rep ; outsb"
: "=S" (Buffer), "=c" (Count) : "+S" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __outwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; outsw " "rep ; outsw"
: "=S" (Buffer), "=c" (Count) : "+S" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outdwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)
__inline__ __attribute__((always_inline))
void __outdwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"cld ; rep ; outsl " "rep ; outsl"
: "=S" (Buffer), "=c" (Count) : "+S" (Buffer), "+c" (Count)
: "d"(Port), "0"(Buffer), "1" (Count) : "d"(Port)
); );
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr0(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr0(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr0, %[value]" "mov %%dr0, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr1(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr1(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr1, %[value]" "mov %%dr1, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr2(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr2(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr2, %[value]" "mov %%dr2, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr3(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr3(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr3, %[value]" "mov %%dr3, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr7(void)
__inline__ __attribute__((always_inline))
unsigned long __readdr7(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%dr7, %[value]" "mov %%dr7, %[value]"
: [value] "=a" (value) : [value] "=r" (value)
); );
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr(unsigned long reg)
__inline__ __attribute__((always_inline))
unsigned long __readdr(unsigned long reg)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -263,64 +227,52 @@ unsigned long __readdr(unsigned long reg)
} }
} }
static static __inline__ __attribute__((always_inline)) void __writedr0(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr0(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr0" "mov %0, %%dr0"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr1(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr1(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr1" "mov %0, %%dr1"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr2(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr2(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr2" "mov %0, %%dr2"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr3(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr3(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr3" "mov %0, %%dr3"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr7(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr7(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%dr7" "mov %0, %%dr7"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr(unsigned long reg, unsigned long Data)
__inline__ __attribute__((always_inline))
void __writedr(unsigned long reg, unsigned long Data)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -348,64 +300,52 @@ void __writedr(unsigned long reg, unsigned long Data)
} }
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr0(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr0(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr0, %[value]" "mov %%cr0, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr2(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr2(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr2, %[value]" "mov %%cr2, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr3(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr3(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr3, %[value]" "mov %%cr3, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr4(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr4(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr4, %[value]" "mov %%cr4, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr8(void)
__inline__ __attribute__((always_inline))
unsigned long __readcr8(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%cr8, %[value]" "mov %%cr8, %[value]"
: [value] "=a" (value)); : [value] "=r" (value));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr(unsigned long reg)
__inline__ __attribute__((always_inline))
unsigned long __readcr(unsigned long reg)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -433,64 +373,53 @@ unsigned long __readcr(unsigned long reg)
} }
} }
static static __inline__ __attribute__((always_inline)) void __writecr0(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr0(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr0" "mov %0, %%cr0"
: :
: "a" (Data) : "r" (Data)
: "memory"
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr2(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr2(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr2" "mov %0, %%cr2"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr3(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr3(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr3" "mov %0, %%cr3"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr4(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr4(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr4" "mov %0, %%cr4"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr8(unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr8(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %%eax, %%cr8" "mov %0, %%cr8"
: :
: "a" (Data) : "r" (Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr(unsigned long reg, unsigned long Data)
__inline__ __attribute__((always_inline))
void __writecr(unsigned long reg, unsigned long Data)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -518,33 +447,27 @@ void __writecr(unsigned long reg, unsigned long Data)
} }
} }
static static __inline__ __attribute__((always_inline)) UINT64 __readmsr(UINT32 msr)
__inline__ __attribute__((always_inline))
UINT64 __readmsr(UINT32 msr)
{ {
UINT64 retval; UINT64 retval;
__asm__ __volatile__( __asm__ __volatile__(
"rdmsr\n\t" "rdmsr"
: "=A" (retval) : "=A" (retval)
: "c" (msr) : "c" (msr)
); );
return retval; return retval;
} }
static static __inline__ __attribute__((always_inline)) void __writemsr (UINT32 msr, UINT64 Value)
__inline__ __attribute__((always_inline))
void __writemsr (UINT32 msr, UINT64 Value)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"wrmsr\n\t" "wrmsr"
: :
: "c" (msr), "A" (Value) : "c" (msr), "A" (Value)
); );
} }
static static __inline__ __attribute__((always_inline)) UINT64 __rdtsc(void)
__inline__ __attribute__((always_inline))
UINT64 __rdtsc(void)
{ {
UINT64 retval; UINT64 retval;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -553,9 +476,7 @@ UINT64 __rdtsc(void)
return retval; return retval;
} }
static static __inline__ __attribute__((always_inline)) void __cpuid(int CPUInfo[], const int InfoType)
__inline__ __attribute__((always_inline))
void __cpuid(int CPUInfo[], const int InfoType)
{ {
__asm__ __volatile__( __asm__ __volatile__(
"cpuid" "cpuid"
@ -564,93 +485,96 @@ void __cpuid(int CPUInfo[], const int InfoType)
); );
} }
static
__inline__ __attribute__((always_inline)) static __inline__ __attribute__((always_inline)) void _disable(void)
void _disable(void)
{ {
__asm__ __volatile__ ("cli"); __asm__ __volatile__ ("cli");
} }
static
__inline__ __attribute__((always_inline)) static __inline__ __attribute__((always_inline)) void _enable(void)
void _enable(void)
{ {
__asm__ __volatile__ ("sti"); __asm__ __volatile__ ("sti");
} }
static
__inline__ __attribute__((always_inline)) static __inline__ __attribute__((always_inline)) void __halt(void)
void __halt(void)
{ {
__asm__ __volatile__ ("hlt"); __asm__ __volatile__ ("hlt");
} }
static
__inline__ __attribute__((always_inline)) static __inline__ __attribute__((always_inline)) void __debugbreak(void)
void __debugbreak(void)
{ {
__asm__ __volatile__ ("int3"); __asm__ __volatile__ ("int3");
} }
static static __inline__ __attribute__((always_inline)) void __invd(void)
__inline__ __attribute__((always_inline)) {
void __wbinvd(void) __asm__ __volatile__ ("invd");
}
static __inline__ __attribute__((always_inline)) void __wbinvd(void)
{ {
__asm__ __volatile__ ("wbinvd"); __asm__ __volatile__ ("wbinvd");
} }
static static __inline__ __attribute__((always_inline)) void __lidt(void *Source)
__inline__ __attribute__((always_inline))
void __lidt(void *Source)
{ {
__asm__ __volatile__("lidt %0" : : "m"(*(short*)Source)); __asm__ __volatile__("lidt %0" : : "m"(*(short*)Source));
} }
static static __inline__ __attribute__((always_inline)) void
__inline__ __attribute__((always_inline)) __writefsbyte(const unsigned long Offset, const uint8_t Data)
void __writefsbyte(const unsigned long Offset, const unsigned char Data)
{ {
__asm__("movb %b[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data)); __asm__ ("movb %[Data], %%fs:%a[Offset]"
:
: [Offset] "ir" (Offset), [Data] "iq" (Data));
} }
static static __inline__ __attribute__((always_inline)) void
__inline__ __attribute__((always_inline)) __writefsword(const unsigned long Offset, const uint16_t Data)
void __writefsword(const unsigned long Offset, const unsigned short Data)
{ {
__asm__("movw %w[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data)); __asm__ ("movw %[Data], %%fs:%a[Offset]"
:
: [Offset] "ir" (Offset), [Data] "ir" (Data));
} }
static static __inline__ __attribute__((always_inline)) void
__inline__ __attribute__((always_inline)) __writefsdword(const unsigned long Offset, const uint32_t Data)
void __writefsdword(const unsigned long Offset, const unsigned long Data)
{ {
__asm__("movl %k[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data)); __asm__ ("movl %[Data], %%fs:%a[Offset]"
:
: [Offset] "ir" (Offset), [Data] "ir" (Data));
} }
static static __inline__ __attribute__((always_inline)) uint8_t
__inline__ __attribute__((always_inline)) __readfsbyte(const unsigned long Offset)
unsigned char __readfsbyte(const unsigned long Offset)
{ {
unsigned char value; unsigned char value;
__asm__("movb %%fs:%a[Offset], %b[value]" : [value] "=q" (value) : [Offset] "irm" (Offset)); __asm__ ("movb %%fs:%a[Offset], %[value]"
: [value] "=q" (value)
: [Offset] "ir" (Offset));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint16_t
__inline__ __attribute__((always_inline)) __readfsword(const unsigned long Offset)
unsigned short __readfsword(const unsigned long Offset)
{ {
unsigned short value; unsigned short value;
__asm__("movw %%fs:%a[Offset], %w[value]" : [value] "=q" (value) : [Offset] "irm" (Offset)); __asm__ ("movw %%fs:%a[Offset], %[value]"
: [value] "=q" (value)
: [Offset] "ir" (Offset));
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint32_t
__inline__ __attribute__((always_inline)) __readfsdword(unsigned long Offset)
unsigned long __readfsdword(const unsigned long Offset)
{ {
unsigned long value; unsigned long value;
__asm__("movl %%fs:%a[Offset], %k[value]" : [value] "=q" (value) : [Offset] "irm" (Offset)); __asm__ ("mov %%fs:%a[Offset], %[value]"
: [value] "=r" (value)
: [Offset] "ir" (Offset));
return value; return value;
} }
@ -658,87 +582,34 @@ unsigned long __readfsdword(const unsigned long Offset)
typedef long long __v2di __attribute__ ((__vector_size__ (16))); typedef long long __v2di __attribute__ ((__vector_size__ (16)));
typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__)); typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
static static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs2 (void *__A, __m128i __B)
__inline__ __attribute__((always_inline))
void _mm_stream_si128_fs2 (void *__A, __m128i __B)
{ {
__asm__(".byte 0x64"); // fs prefix __asm__(".byte 0x64"); // fs prefix
__builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B); __builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B);
} }
static static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs (void *__A, void *__B)
__inline__ __attribute__((always_inline))
void _mm_stream_si128_fs (void *__A, void *__B)
{ {
__m128i data; __m128i data;
data = (__m128i) __builtin_ia32_lddqu ((char const *)__B); data = (__m128i) __builtin_ia32_lddqu ((char const *)__B);
_mm_stream_si128_fs2 (__A, data); _mm_stream_si128_fs2 (__A, data);
} }
static static __inline__ __attribute__((always_inline)) void _mm_clflush_fs (void *__A)
__inline__ __attribute__((always_inline))
void _mm_clflush_fs (void *__A)
{ {
__asm__(".byte 0x64"); // fs prefix __asm__(".byte 0x64"); // fs prefix
__builtin_ia32_clflush (__A); __builtin_ia32_clflush (__A);
} }
static static __inline __attribute__(( __always_inline__)) void _mm_mfence (void)
__inline__ __attribute__((always_inline))
void _mm_mfence (void)
{ {
__builtin_ia32_mfence (); __builtin_ia32_mfence ();
} }
static static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)
__inline__ __attribute__((always_inline))
void _mm_sfence (void)
{ {
__builtin_ia32_sfence (); __builtin_ia32_sfence ();
} }
#endif #endif /* __SSE3__ */
static #endif /* defined (__GNUC__) */
__inline__ __attribute__((always_inline))
void __stosb(unsigned char *dest, unsigned char data, size_t count)
{
__asm__ __volatile__ (
"cld ; rep ; stosb "
: "=D" (dest), "=c" (count)
: "a"(data), "0"(dest), "1" (count)
);
}
static
__inline__ __attribute__((always_inline))
void __movsb(unsigned char *dest, unsigned char *data, size_t count)
{
__asm__ __volatile__ (
"cld ; rep ; movsb "
: "=D" (dest), "=S"(data), "=c" (count)
: "S"(data), "0"(dest), "1" (count)
);
}
static
__inline__ __attribute__((always_inline))
void debug_point ( unsigned short Port, unsigned long Data )
{
__outdword (Port, Data);
__asm__ __volatile__ (".word 0xfeeb");
}
static
__inline__ __attribute__((always_inline))
void delay_point ( unsigned short Port, unsigned long Data, unsigned long delayTime )
{
UINTN Index;
Index = 0;
__outdword (Port, Data);
while (Index < delayTime * 600000) {
__outdword (0xE0, 0);
Index ++;
}
}
#endif // defined (__GNUC__)

View File

@ -1,46 +1,37 @@
/* /*
Compatibility <intrin_x86.h> header for GCC -- GCC equivalents of intrinsic * Copyright (c) 2011, Advanced Micro Devices, Inc. All rights reserved.
Microsoft Visual C++ functions. Originally developed for the ReactOS * Copyright (c) 2014, Edward O'Callaghan <eocallaghan@alterapraxis.com>
(<http://www.reactos.org/>) and TinyKrnl (<http://www.tinykrnl.org/>) *
projects. * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Copyright (c) 2006 KJK::Hyperion <hackbunny@reactos.com> * * Redistributions of source code must retain the above copyright
2014 Edward O'Callaghan <eocallaghan@alterapraxis.com> * notice, this list of conditions and the following disclaimer.
2014 Sage Electronic Engineering, LLC * * Redistributions in binary form must reproduce the above copyright
All rights reserved. * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
Permission is hereby granted, free of charge, to any person obtaining a * * Neither the name of Advanced Micro Devices, Inc. nor the names of
copy of this software and associated documentation files (the "Software"), * its contributors may be used to endorse or promote products derived
to deal in the Software without restriction, including without limitation * from this software without specific prior written permission.
the rights to use, copy, modify, merge, publish, distribute, sublicense, *
and/or sell copies of the Software, and to permit persons to whom the * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Software is furnished to do so, subject to the following conditions: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
The above copyright notice and this permission notice shall be included in * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
all copies or substantial portions of the Software. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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.
*/ */
#if defined (__GNUC__) #if defined (__GNUC__)
#include <stdint.h>
#if !defined(AMDLIB_OPTIMIZE)
#define AMDLIB_OPTIMIZE
#endif
/* I/O intrin functions. */ /* I/O intrin functions. */
static static __inline__ __attribute__((always_inline)) uint8_t __inbyte(uint16_t Port)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned char __inbyte(unsigned short Port)
{ {
unsigned char value; uint8_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %1, %0" "in %1, %0"
@ -51,12 +42,9 @@ unsigned char __inbyte(unsigned short Port)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint16_t __inword(uint16_t Port)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned short __inword(unsigned short Port)
{ {
unsigned short value; uint16_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %1, %0" "in %1, %0"
@ -67,12 +55,9 @@ unsigned short __inword(unsigned short Port)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint32_t __indword(uint16_t Port)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __indword(unsigned short Port)
{ {
unsigned long value; uint32_t value;
__asm__ __volatile__ ( __asm__ __volatile__ (
"in %1, %0" "in %1, %0"
@ -83,10 +68,7 @@ unsigned long __indword(unsigned short Port)
} }
static static __inline__ __attribute__((always_inline)) void __outbyte(uint16_t Port,uint8_t Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outbyte(unsigned short Port,unsigned char Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %0, %1" "out %0, %1"
@ -95,10 +77,7 @@ void __outbyte(unsigned short Port,unsigned char Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outword(uint16_t Port,uint16_t Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outword(unsigned short Port,unsigned short Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %0, %1" "out %0, %1"
@ -107,10 +86,7 @@ void __outword(unsigned short Port,unsigned short Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __outdword(uint16_t Port,uint32_t Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outdword(unsigned short Port,unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"out %0, %1" "out %0, %1"
@ -119,10 +95,7 @@ void __outdword(unsigned short Port,unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __inbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __inbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; insb" "rep ; insb"
@ -131,10 +104,7 @@ void __inbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Coun
); );
} }
static static __inline__ __attribute__((always_inline)) void __inwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __inwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; insw" "rep ; insw"
@ -143,10 +113,7 @@ void __inwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Cou
); );
} }
static static __inline__ __attribute__((always_inline)) void __indwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __indwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; insl" "rep ; insl"
@ -155,10 +122,7 @@ void __indwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Cou
); );
} }
static static __inline__ __attribute__((always_inline)) void __outbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; outsb" "rep ; outsb"
@ -167,10 +131,7 @@ void __outbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Cou
); );
} }
static static __inline__ __attribute__((always_inline)) void __outwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; outsw" "rep ; outsw"
@ -179,10 +140,7 @@ void __outwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Co
); );
} }
static static __inline__ __attribute__((always_inline)) void __outdwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __outdwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"rep ; outsl" "rep ; outsl"
@ -191,10 +149,7 @@ void __outdwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Co
); );
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr0(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr0(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -204,10 +159,7 @@ unsigned long __readdr0(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr1(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr1(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -217,10 +169,7 @@ unsigned long __readdr1(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr2(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr2(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -230,10 +179,7 @@ unsigned long __readdr2(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr3(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr3(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -243,10 +189,7 @@ unsigned long __readdr3(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr7(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr7(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -256,10 +199,7 @@ unsigned long __readdr7(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readdr(unsigned long reg)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readdr(unsigned long reg)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -284,14 +224,10 @@ unsigned long __readdr(unsigned long reg)
default: default:
return -1; return -1;
break;
} }
} }
static static __inline__ __attribute__((always_inline)) void __writedr0(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr0(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr0" "mov %0, %%dr0"
@ -300,10 +236,7 @@ void __writedr0(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr1(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr1(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr1" "mov %0, %%dr1"
@ -312,10 +245,7 @@ void __writedr1(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr2(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr2(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr2" "mov %0, %%dr2"
@ -324,10 +254,7 @@ void __writedr2(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr3(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr3(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr3" "mov %0, %%dr3"
@ -336,10 +263,7 @@ void __writedr3(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr7(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr7(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%dr7" "mov %0, %%dr7"
@ -348,10 +272,7 @@ void __writedr7(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writedr(unsigned long reg, unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writedr(unsigned long reg, unsigned long Data)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -375,14 +296,11 @@ void __writedr(unsigned long reg, unsigned long Data)
break; break;
default: default:
break; ;
} }
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr0(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr0(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -391,10 +309,7 @@ unsigned long __readcr0(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr2(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr2(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -403,10 +318,7 @@ unsigned long __readcr2(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr3(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr3(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -415,10 +327,7 @@ unsigned long __readcr3(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr4(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr4(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -427,10 +336,7 @@ unsigned long __readcr4(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr8(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr8(void)
{ {
unsigned long value; unsigned long value;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -439,10 +345,7 @@ unsigned long __readcr8(void)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) unsigned long __readcr(unsigned long reg)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
unsigned long __readcr(unsigned long reg)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -467,14 +370,10 @@ unsigned long __readcr(unsigned long reg)
default: default:
return -1; return -1;
break;
} }
} }
static static __inline__ __attribute__((always_inline)) void __writecr0(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr0(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr0" "mov %0, %%cr0"
@ -484,10 +383,7 @@ void __writecr0(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr2(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr2(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr2" "mov %0, %%cr2"
@ -496,10 +392,7 @@ void __writecr2(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr3(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr3(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr3" "mov %0, %%cr3"
@ -508,10 +401,7 @@ void __writecr3(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr4(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr4(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr4" "mov %0, %%cr4"
@ -520,10 +410,7 @@ void __writecr4(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr8(unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr8(unsigned long Data)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"mov %0, %%cr8" "mov %0, %%cr8"
@ -532,10 +419,7 @@ void __writecr8(unsigned long Data)
); );
} }
static static __inline__ __attribute__((always_inline)) void __writecr(unsigned long reg, unsigned long Data)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writecr(unsigned long reg, unsigned long Data)
{ {
switch (reg){ switch (reg){
case 0: case 0:
@ -559,14 +443,11 @@ void __writecr(unsigned long reg, unsigned long Data)
break; break;
default: default:
break; ;
} }
} }
static static __inline__ __attribute__((always_inline)) UINT64 __readmsr(UINT32 msr)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
UINT64 __readmsr(UINT32 msr)
{ {
UINT64 retval; UINT64 retval;
__asm__ __volatile__( __asm__ __volatile__(
@ -577,10 +458,7 @@ UINT64 __readmsr(UINT32 msr)
return retval; return retval;
} }
static static __inline__ __attribute__((always_inline)) void __writemsr (UINT32 msr, UINT64 Value)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __writemsr (UINT32 msr, UINT64 Value)
{ {
__asm__ __volatile__ ( __asm__ __volatile__ (
"wrmsr" "wrmsr"
@ -589,10 +467,7 @@ void __writemsr (UINT32 msr, UINT64 Value)
); );
} }
static static __inline__ __attribute__((always_inline)) UINT64 __rdtsc(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
UINT64 __rdtsc(void)
{ {
UINT64 retval; UINT64 retval;
__asm__ __volatile__ ( __asm__ __volatile__ (
@ -601,10 +476,7 @@ UINT64 __rdtsc(void)
return retval; return retval;
} }
static static __inline__ __attribute__((always_inline)) void __cpuid(int CPUInfo[], const int InfoType)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __cpuid(int CPUInfo[], const int InfoType)
{ {
__asm__ __volatile__( __asm__ __volatile__(
"cpuid" "cpuid"
@ -613,96 +485,71 @@ void __cpuid(int CPUInfo[], const int InfoType)
); );
} }
static
AMDLIB_OPTIMIZE static __inline__ __attribute__((always_inline)) void _disable(void)
__inline__ __attribute__((always_inline))
void _disable(void)
{ {
__asm__ __volatile__ ("cli"); __asm__ __volatile__ ("cli");
} }
static
AMDLIB_OPTIMIZE static __inline__ __attribute__((always_inline)) void _enable(void)
__inline__ __attribute__((always_inline))
void _enable(void)
{ {
__asm__ __volatile__ ("sti"); __asm__ __volatile__ ("sti");
} }
static
AMDLIB_OPTIMIZE static __inline__ __attribute__((always_inline)) void __halt(void)
__inline__ __attribute__((always_inline))
void __halt(void)
{ {
__asm__ __volatile__ ("hlt"); __asm__ __volatile__ ("hlt");
} }
static
AMDLIB_OPTIMIZE static __inline__ __attribute__((always_inline)) void __debugbreak(void)
__inline__ __attribute__((always_inline))
void __debugbreak(void)
{ {
__asm__ __volatile__ ("int3"); __asm__ __volatile__ ("int3");
} }
static static __inline__ __attribute__((always_inline)) void __invd(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __invd(void)
{ {
__asm__ __volatile__ ("invd"); __asm__ __volatile__ ("invd");
} }
static static __inline__ __attribute__((always_inline)) void __wbinvd(void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __wbinvd(void)
{ {
__asm__ __volatile__ ("wbinvd"); __asm__ __volatile__ ("wbinvd");
} }
static static __inline__ __attribute__((always_inline)) void __lidt(void *Source)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __lidt(void *Source)
{ {
__asm__ __volatile__("lidt %0" : : "m"(*(short*)Source)); __asm__ __volatile__("lidt %0" : : "m"(*(short*)Source));
} }
static static __inline__ __attribute__((always_inline)) void
AMDLIB_OPTIMIZE __writefsbyte(const unsigned long Offset, const uint8_t Data)
__inline__ __attribute__((always_inline))
void __writefsbyte(const unsigned long Offset, const unsigned char Data)
{ {
__asm__ ("movb %[Data], %%fs:%a[Offset]" __asm__ ("movb %[Data], %%fs:%a[Offset]"
: :
: [Offset] "ir" (Offset), [Data] "iq" (Data)); : [Offset] "ir" (Offset), [Data] "iq" (Data));
} }
static static __inline__ __attribute__((always_inline)) void
AMDLIB_OPTIMIZE __writefsword(const unsigned long Offset, const uint16_t Data)
__inline__ __attribute__((always_inline))
void __writefsword(const unsigned long Offset, const unsigned short Data)
{ {
__asm__ ("movw %[Data], %%fs:%a[Offset]" __asm__ ("movw %[Data], %%fs:%a[Offset]"
: :
: [Offset] "ir" (Offset), [Data] "ir" (Data)); : [Offset] "ir" (Offset), [Data] "ir" (Data));
} }
static static __inline__ __attribute__((always_inline)) void
AMDLIB_OPTIMIZE __writefsdword(const unsigned long Offset, const uint32_t Data)
__inline__ __attribute__((always_inline))
void __writefsdword(const unsigned long Offset, const unsigned long Data)
{ {
__asm__ ("movl %[Data], %%fs:%a[Offset]" __asm__ ("movl %[Data], %%fs:%a[Offset]"
: :
: [Offset] "ir" (Offset), [Data] "ir" (Data)); : [Offset] "ir" (Offset), [Data] "ir" (Data));
} }
static static __inline__ __attribute__((always_inline)) uint8_t
AMDLIB_OPTIMIZE __readfsbyte(const unsigned long Offset)
__inline__ __attribute__((always_inline))
unsigned char __readfsbyte(const unsigned long Offset)
{ {
unsigned char value; unsigned char value;
__asm__ ("movb %%fs:%a[Offset], %[value]" __asm__ ("movb %%fs:%a[Offset], %[value]"
@ -711,10 +558,8 @@ unsigned char __readfsbyte(const unsigned long Offset)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint16_t
AMDLIB_OPTIMIZE __readfsword(const unsigned long Offset)
__inline__ __attribute__((always_inline))
unsigned short __readfsword(const unsigned long Offset)
{ {
unsigned short value; unsigned short value;
__asm__ ("movw %%fs:%a[Offset], %[value]" __asm__ ("movw %%fs:%a[Offset], %[value]"
@ -723,13 +568,11 @@ unsigned short __readfsword(const unsigned long Offset)
return value; return value;
} }
static static __inline__ __attribute__((always_inline)) uint32_t
AMDLIB_OPTIMIZE __readfsdword(unsigned long Offset)
__inline__ __attribute__((always_inline))
unsigned long __readfsdword(unsigned long Offset)
{ {
unsigned long value; unsigned long value;
__asm__ ("movl %%fs:%a[Offset], %[value]" __asm__ ("mov %%fs:%a[Offset], %[value]"
: [value] "=r" (value) : [value] "=r" (value)
: [Offset] "ir" (Offset)); : [Offset] "ir" (Offset));
return value; return value;
@ -739,95 +582,34 @@ unsigned long __readfsdword(unsigned long Offset)
typedef long long __v2di __attribute__ ((__vector_size__ (16))); typedef long long __v2di __attribute__ ((__vector_size__ (16)));
typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__)); typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
static static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs2 (void *__A, __m128i __B)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_stream_si128_fs2 (void *__A, __m128i __B)
{ {
__asm__(".byte 0x64"); // fs prefix __asm__(".byte 0x64"); // fs prefix
__builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B); __builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B);
} }
static static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs (void *__A, void *__B)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_stream_si128_fs (void *__A, void *__B)
{ {
__m128i data; __m128i data;
data = (__m128i) __builtin_ia32_lddqu ((char const *)__B); data = (__m128i) __builtin_ia32_lddqu ((char const *)__B);
_mm_stream_si128_fs2 (__A, data); _mm_stream_si128_fs2 (__A, data);
} }
static static __inline__ __attribute__((always_inline)) void _mm_clflush_fs (void *__A)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_clflush_fs (void *__A)
{ {
__asm__(".byte 0x64"); // fs prefix __asm__(".byte 0x64"); // fs prefix
__builtin_ia32_clflush (__A); __builtin_ia32_clflush (__A);
} }
static static __inline __attribute__(( __always_inline__)) void _mm_mfence (void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_mfence (void)
{ {
__builtin_ia32_mfence (); __builtin_ia32_mfence ();
} }
static static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void _mm_sfence (void)
{ {
__builtin_ia32_sfence (); __builtin_ia32_sfence ();
} }
#endif /* __SSE3__ */ #endif /* __SSE3__ */
static
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __stosb(unsigned char *dest, unsigned char data, size_t count)
{
__asm__ __volatile__ (
"rep ; stosb "
: "+D" (dest), "+c" (count)
: "a"(data)
);
}
static
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void __movsb(unsigned char *dest, unsigned char *data, size_t count)
{
__asm__ __volatile__ (
"movsb "
: "+D" (dest), "+S"(data), "+c" (count)
);
}
static
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void debug_point ( unsigned short Port, unsigned long Data )
{
__outdword (Port, Data);
__asm__ __volatile__ (".word 0xfeeb");
}
static
AMDLIB_OPTIMIZE
__inline__ __attribute__((always_inline))
void delay_point ( unsigned short Port, unsigned long Data, unsigned long delayTime )
{
UINTN Index;
Index = 0;
__outdword (Port, Data);
while (Index < delayTime * 600000) {
__outdword (0xE0, 0);
Index ++;
}
}
#endif /* defined (__GNUC__) */ #endif /* defined (__GNUC__) */