<p>Martin Roth has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/22498">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vendorcode/amd/pi/00670F00: Remove dependency on amd/include dir<br><br>Copy the two headers used by the Stoney BinaryPI implementation into<br>the 00670F00 directory so that any changes that are made to them don't<br>affect other platforms.<br><br>BUG=b:67299330<br>TEST=Build<br><br>Change-Id: I5d37fac72871f2617c4be45c151741436cbfce96<br>Signed-off-by: Martin Roth <martinroth@google.com><br>---<br>M src/vendorcode/amd/pi/00670F00/Makefile.inc<br>A src/vendorcode/amd/pi/00670F00/Porting.h<br>M src/vendorcode/amd/pi/00670F00/agesa_headers.h<br>A src/vendorcode/amd/pi/00670F00/gcc-intrin.h<br>4 files changed, 933 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/98/22498/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/vendorcode/amd/pi/00670F00/Makefile.inc b/src/vendorcode/amd/pi/00670F00/Makefile.inc<br>index bd00ea3..3fb7870 100644<br>--- a/src/vendorcode/amd/pi/00670F00/Makefile.inc<br>+++ b/src/vendorcode/amd/pi/00670F00/Makefile.inc<br>@@ -33,7 +33,7 @@<br> <br> AGESA_ROOT = $(call strip_quotes,$(CONFIG_AGESA_BINARY_PI_VENDORCODE_PATH))<br> <br>-AGESA_INC = -I$(obj) -I$(src)/vendorcode/amd/include<br>+AGESA_INC = -I$(obj)<br> <br> AGESA_INC += -I$(src)/mainboard/$(MAINBOARDDIR)<br> AGESA_INC += -I$(AGESA_ROOT)/binaryPI<br>diff --git a/src/vendorcode/amd/pi/00670F00/Porting.h b/src/vendorcode/amd/pi/00670F00/Porting.h<br>new file mode 100644<br>index 0000000..ed1a9c7<br>--- /dev/null<br>+++ b/src/vendorcode/amd/pi/00670F00/Porting.h<br>@@ -0,0 +1,302 @@<br>+/* $NoKeywords:$ */<br>+/**<br>+ * @file<br>+ *<br>+ * Describes compiler dependencies - to support several compile time environments<br>+ *<br>+ * Contains compiler environment porting descriptions<br>+ *<br>+ * @xrefitem bom "File Content Label" "Release Content"<br>+ * @e project: AGESA<br>+ * @e sub-project: Includes<br>+ * @e \$Revision: 44324 $ @e \$Date: 2010-12-22 03:16:51 -0600 (Wed, 22 Dec 2010) $<br>+ */<br>+/*****************************************************************************<br>+ *<br>+ * Copyright (c) 2008 - 2013, Advanced Micro Devices, Inc.<br>+ * All rights reserved.<br>+ *<br>+ * Redistribution and use in source and binary forms, with or without<br>+ * modification, are permitted provided that the following conditions are met:<br>+ * * Redistributions of source code must retain the above copyright<br>+ * notice, this list of conditions and the following disclaimer.<br>+ * * Redistributions in binary form must reproduce the above copyright<br>+ * notice, this list of conditions and the following disclaimer in the<br>+ * documentation and/or other materials provided with the distribution.<br>+ * * Neither the name of Advanced Micro Devices, Inc. nor the names of<br>+ * its contributors may be used to endorse or promote products derived<br>+ * from this software without specific prior written permission.<br>+ *<br>+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND<br>+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED<br>+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE<br>+ * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY<br>+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES<br>+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;<br>+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND<br>+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT<br>+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS<br>+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<br>+ *<br>+ ***************************************************************************/<br>+<br>+#ifndef _PORTING_H_<br>+#define _PORTING_H_<br>+<br>+#if defined (_MSC_VER)<br>+ #include <intrin.h><br>+ void _disable (void);<br>+ void _enable (void);<br>+ #pragma warning(disable: 4103 4001 4733)<br>+ #pragma intrinsic (_disable, _enable)<br>+ #pragma warning(push)<br>+ // -----------------------------------------------------------------------<br>+ // Define a code_seg MACRO<br>+ //<br>+ #define MAKE_AS_A_STRING(arg) #arg<br>+<br>+ #define CODE_GROUP(arg) __pragma (code_seg (MAKE_AS_A_STRING (.t##arg)))<br>+<br>+ #define RDATA_GROUP(arg) __pragma (const_seg (MAKE_AS_A_STRING (.d##arg)))<br>+ #define FUNC_ATTRIBUTE(arg) __declspec(arg)<br>+ //#include <intrin.h> // MS has built-in functions<br>+<br>+ #if _MSC_VER < 900<br>+ // -----------------------------------------------------------------------<br>+ // Assume MSVC 1.52C (16-bit)<br>+ //<br>+ // NOTE: When using MSVC 1.52C use the following command line:<br>+ //<br>+ // CL.EXE /G3 /AL /O1i /Fa <FILENAME.C><br>+ //<br>+ // This will produce 32-bit code in USE16 segment that is optimized for code<br>+ // size.<br>+ typedef void VOID;<br>+<br>+ // Create the universal 32, 16, and 8-bit data types<br>+ typedef unsigned long UINTN;<br>+ typedef long INT32;<br>+ typedef unsigned long UINT32;<br>+ typedef int INT16;<br>+ typedef unsigned int UINT16;<br>+ typedef char INT8;<br>+ typedef unsigned char UINT8;<br>+ typedef char CHAR8;<br>+ typedef unsigned short CHAR16;<br>+<br>+ /// struct for 16-bit environment handling of 64-bit value<br>+ typedef struct _UINT64 {<br>+ IN OUT UINT32 lo; ///< lower 32-bits of 64-bit value<br>+ IN OUT UINT32 hi; ///< highest 32-bits of 64-bit value<br>+ } UINT64;<br>+<br>+ // Create the Boolean type<br>+ #define TRUE 1<br>+ #define FALSE 0<br>+ typedef unsigned char BOOLEAN;<br>+<br>+ #define CONST const<br>+ #define STATIC static<br>+ #define VOLATILE volatile<br>+ #define CALLCONV __pascal<br>+ #define ROMDATA __based( __segname( "_CODE" ) )<br>+ #define _16BYTE_ALIGN __declspec(align(16))<br>+ #define _8BYTE_ALIGN __declspec(align(8))<br>+ #define _4BYTE_ALIGN __declspec(align(4))<br>+ #define _2BYTE_ALIGN __declspec(align(2))<br>+ #define _1BYTE_ALIGN __declspec(align(1))<br>+<br>+ // Force tight packing of structures<br>+ // Note: Entire AGESA (Project / Solution) will be using pragma pack 1<br>+ #pragma warning( disable : 4103 ) // Disable '#pragma pack' in .h warning<br>+ #pragma pack(1)<br>+<br>+ // Disable WORD->BYTE automatic conversion warnings. Example:<br>+ // BYTE LocalByte;<br>+ // void MyFunc(BYTE val);<br>+ //<br>+ // MyFunc(LocalByte*2+1); // Warning, automatic conversion<br>+ //<br>+ // The problem is any time math is performed on a BYTE, it is converted to a<br>+ // WORD by MSVC 1.52c, and then when it is converted back to a BYTE, a warning<br>+ // is generated. Disable warning C4761<br>+ #pragma warning( disable : 4761 )<br>+<br>+ #else<br>+ // -----------------------------------------------------------------------<br>+ // Assume a 32-bit MSVC++<br>+ //<br>+ // Disable the following warnings:<br>+ // 4100 - 'identifier' : unreferenced formal parameter<br>+ // 4276 - 'function' : no prototype provided; assumed no parameters<br>+ // 4214 - non standard extension used : bit field types other than int<br>+ // 4001 - nonstandard extension 'single line comment' was used<br>+ // 4142 - benign redefinition of type for following declaration<br>+ // - typedef char INT8<br>+ #if defined (_M_IX86)<br>+ #pragma warning (disable: 4100 4276 4214 4001 4142 4305 4306)<br>+<br>+ #ifndef VOID<br>+ typedef void VOID;<br>+ #endif<br>+ // Create the universal 32, 16, and 8-bit data types<br>+ #ifndef UINTN<br>+ typedef unsigned __w64 UINTN;<br>+ #endif<br>+ typedef __int64 INT64;<br>+ typedef unsigned __int64 UINT64;<br>+ typedef int INT32;<br>+ typedef unsigned int UINT32;<br>+ typedef short INT16;<br>+ typedef unsigned short UINT16;<br>+ typedef char INT8;<br>+ typedef unsigned char UINT8;<br>+ typedef char CHAR8;<br>+ typedef unsigned short CHAR16;<br>+<br>+ // Create the Boolean type<br>+ #ifndef TRUE<br>+ #define TRUE 1<br>+ #endif<br>+ #ifndef FALSE<br>+ #define FALSE 0<br>+ #endif<br>+ typedef unsigned char BOOLEAN;<br>+<br>+ // Force tight packing of structures<br>+ // Note: Entire AGESA (Project / Solution) will be using pragma pack 1<br>+ #pragma pack(1)<br>+<br>+ #define CONST const<br>+ #define STATIC static<br>+ #define VOLATILE volatile<br>+ #define CALLCONV<br>+ #define ROMDATA<br>+ #define _16BYTE_ALIGN __declspec(align(64))<br>+ #define _8BYTE_ALIGN __declspec(align(8))<br>+ #define _4BYTE_ALIGN __declspec(align(4))<br>+ #define _2BYTE_ALIGN __declspec(align(2))<br>+ #define _1BYTE_ALIGN __declspec(align(1))<br>+ //Support for variadic macros was introduced in Visual C++ 2005.<br>+ #if _MSC_VER >= 1400<br>+ #define VA_ARGS_SUPPORTED<br>+ #endif<br>+ // 64 bit of compiler<br>+ #else<br>+ #pragma warning (disable: 4100 4276 4214 4001 4142 4305 4306 4366)<br>+<br>+ #ifndef VOID<br>+ typedef void VOID;<br>+ #endif<br>+ // Create the universal 32, 16, and 8-bit data types<br>+ #ifndef UINTN<br>+ typedef unsigned __int64 UINTN;<br>+ #endif<br>+ typedef __int64 INT64;<br>+ typedef unsigned __int64 UINT64;<br>+ typedef int INT32;<br>+ typedef unsigned int UINT32;<br>+ typedef short INT16;<br>+ typedef unsigned short UINT16;<br>+ typedef char INT8;<br>+ typedef unsigned char UINT8;<br>+ typedef char CHAR8;<br>+ typedef unsigned short CHAR16;<br>+<br>+ // Create the Boolean type<br>+ #ifndef TRUE<br>+ #define TRUE 1<br>+ #endif<br>+ #ifndef FALSE<br>+ #define FALSE 0<br>+ #endif<br>+ typedef unsigned char BOOLEAN;<br>+ #define _16BYTE_ALIGN __declspec(align(16))<br>+ #define _8BYTE_ALIGN __declspec(align(8))<br>+ #define _4BYTE_ALIGN __declspec(align(4))<br>+ #define _2BYTE_ALIGN __declspec(align(2))<br>+ #define _1BYTE_ALIGN __declspec(align(1))<br>+ // Force tight packing of structures<br>+ // Note: Entire AGESA (Project / Solution) will be using pragma pack 1<br>+ #pragma pack(1)<br>+<br>+ #define CONST const<br>+ #define STATIC static<br>+ #define VOLATILE volatile<br>+ #define CALLCONV<br>+ #define ROMDATA<br>+ #endif<br>+ #endif<br>+ // -----------------------------------------------------------------------<br>+ // End of MS compiler versions<br>+<br>+#elif defined __GNUC__<br>+<br>+ #include <stdint.h><br>+<br>+ #define IN<br>+ #define OUT<br>+ #define STATIC static<br>+ #define VOLATILE volatile<br>+ #define TRUE 1<br>+ #define FALSE 0<br>+ #define CONST const<br>+ #define ROMDATA<br>+ #define CALLCONV<br>+ #define _16BYTE_ALIGN __attribute__((aligned (16)))<br>+ #define _8BYTE_ALIGN __attribute__((aligned (8)))<br>+ #define _4BYTE_ALIGN __attribute__((aligned (4)))<br>+ #define _2BYTE_ALIGN __attribute__((aligned (2)))<br>+ #define _1BYTE_ALIGN __attribute__((aligned (1)))<br>+<br>+ typedef uintptr_t UINTN;<br>+ typedef int64_t INT64;<br>+ typedef uint64_t UINT64;<br>+ typedef int32_t INT32;<br>+ typedef uint32_t UINT32;<br>+ typedef int16_t INT16;<br>+ typedef uint16_t UINT16;<br>+ typedef int8_t INT8;<br>+ typedef uint8_t UINT8;<br>+ typedef char CHAR8;<br>+ typedef unsigned short CHAR16;<br>+ typedef unsigned char BOOLEAN;<br>+ typedef void VOID;<br>+<br>+#define CODE_GROUP(arg)<br>+#define RDATA_GROUP(arg)<br>+<br>+#pragma pack(1)<br>+<br>+#define FUNC_ATTRIBUTE(arg) __attribute__((arg))<br>+#define MAKE_AS_A_STRING(arg) #arg<br>+#include <stddef.h><br>+#include <gcc-intrin.h><br>+<br>+#include <assert.h><br>+//#include <console/console.h><br>+//#include <commonlib/loglevel.h><br>+<br>+#ifndef NULL<br>+ #define NULL ((void *)0)<br>+#endif<br>+<br>+#else<br>+ // -----------------------------------------------------------------------<br>+ // Unknown or unsupported compiler<br>+ //<br>+ #error "Unknown compiler in use"<br>+#endif<br>+<br>+// -----------------------------------------------------------------------<br>+// Common definitions for all compilers<br>+//<br>+<br>+//Support forward reference construct<br>+#define AGESA_FORWARD_DECLARATION(x) typedef struct _##x x<br>+<br>+// The following are use in conformance to the UEFI style guide<br>+#define IN<br>+#define OUT<br>+<br>+#endif // _PORTING_H_<br>diff --git a/src/vendorcode/amd/pi/00670F00/agesa_headers.h b/src/vendorcode/amd/pi/00670F00/agesa_headers.h<br>index d93b73f..721da3f 100644<br>--- a/src/vendorcode/amd/pi/00670F00/agesa_headers.h<br>+++ b/src/vendorcode/amd/pi/00670F00/agesa_headers.h<br>@@ -17,7 +17,7 @@<br> #define __AGESA_HEADERS_H__<br> <br> #pragma pack(push)<br>-#include <Porting.h><br>+#include "Porting.h"<br> #include "AGESA.h"<br> #include "AMD.h"<br> <br>diff --git a/src/vendorcode/amd/pi/00670F00/gcc-intrin.h b/src/vendorcode/amd/pi/00670F00/gcc-intrin.h<br>new file mode 100644<br>index 0000000..44e91d2<br>--- /dev/null<br>+++ b/src/vendorcode/amd/pi/00670F00/gcc-intrin.h<br>@@ -0,0 +1,629 @@<br>+/*<br>+ * Copyright (c) 2011, Advanced Micro Devices, Inc. All rights reserved.<br>+ * Copyright (c) 2014, Edward O'Callaghan <eocallaghan@alterapraxis.com><br>+ *<br>+ * Redistribution and use in source and binary forms, with or without<br>+ * modification, are permitted provided that the following conditions are met:<br>+ * * Redistributions of source code must retain the above copyright<br>+ * notice, this list of conditions and the following disclaimer.<br>+ * * Redistributions in binary form must reproduce the above copyright<br>+ * notice, this list of conditions and the following disclaimer in the<br>+ * documentation and/or other materials provided with the distribution.<br>+ * * Neither the name of Advanced Micro Devices, Inc. nor the names of<br>+ * its contributors may be used to endorse or promote products derived<br>+ * from this software without specific prior written permission.<br>+ *<br>+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND<br>+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED<br>+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE<br>+ * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY<br>+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES<br>+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;<br>+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND<br>+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT<br>+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS<br>+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<br>+ *<br>+ */<br>+<br>+#if defined (__GNUC__)<br>+#include <stdint.h><br>+/* I/O intrin functions. */<br>+static __inline__ __attribute__((always_inline)) uint8_t __inbyte(uint16_t Port)<br>+{<br>+ uint8_t value;<br>+<br>+ __asm__ __volatile__ (<br>+ "in %1, %0"<br>+ : "=a" (value)<br>+ : "Nd" (Port)<br>+ );<br>+<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) uint16_t __inword(uint16_t Port)<br>+{<br>+ uint16_t value;<br>+<br>+ __asm__ __volatile__ (<br>+ "in %1, %0"<br>+ : "=a" (value)<br>+ : "Nd" (Port)<br>+ );<br>+<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) uint32_t __indword(uint16_t Port)<br>+{<br>+ uint32_t value;<br>+<br>+ __asm__ __volatile__ (<br>+ "in %1, %0"<br>+ : "=a" (value)<br>+ : "Nd" (Port)<br>+ );<br>+ return value;<br>+<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __outbyte(uint16_t Port,uint8_t Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "out %0, %1"<br>+ :<br>+ : "a" (Data), "Nd" (Port)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __outword(uint16_t Port,uint16_t Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "out %0, %1"<br>+ :<br>+ : "a" (Data), "Nd" (Port)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __outdword(uint16_t Port,uint32_t Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "out %0, %1"<br>+ :<br>+ : "a" (Data), "Nd" (Port)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __inbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)<br>+{<br>+ __asm__ __volatile__ (<br>+ "rep ; insb"<br>+ : "+D" (Buffer), "+c" (Count)<br>+ : "d"(Port)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __inwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)<br>+{<br>+ __asm__ __volatile__ (<br>+ "rep ; insw"<br>+ : "+D" (Buffer), "+c" (Count)<br>+ : "d"(Port)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __indwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)<br>+{<br>+ __asm__ __volatile__ (<br>+ "rep ; insl"<br>+ : "+D" (Buffer), "+c" (Count)<br>+ : "d"(Port)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __outbytestring(uint16_t Port,uint8_t *Buffer,unsigned long Count)<br>+{<br>+ __asm__ __volatile__ (<br>+ "rep ; outsb"<br>+ : "+S" (Buffer), "+c" (Count)<br>+ : "d"(Port)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __outwordstring(uint16_t Port,uint16_t *Buffer,unsigned long Count)<br>+{<br>+ __asm__ __volatile__ (<br>+ "rep ; outsw"<br>+ : "+S" (Buffer), "+c" (Count)<br>+ : "d"(Port)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __outdwordstring(uint16_t Port,unsigned long *Buffer,unsigned long Count)<br>+{<br>+ __asm__ __volatile__ (<br>+ "rep ; outsl"<br>+ : "+S" (Buffer), "+c" (Count)<br>+ : "d"(Port)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readdr0(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%dr0, %[value]"<br>+ : [value] "=r" (value)<br>+ );<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readdr1(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%dr1, %[value]"<br>+ : [value] "=r" (value)<br>+ );<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readdr2(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%dr2, %[value]"<br>+ : [value] "=r" (value)<br>+ );<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readdr3(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%dr3, %[value]"<br>+ : [value] "=r" (value)<br>+ );<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readdr7(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%dr7, %[value]"<br>+ : [value] "=r" (value)<br>+ );<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readdr(unsigned long reg)<br>+{<br>+ switch (reg){<br>+ case 0:<br>+ return __readdr0 ();<br>+ break;<br>+<br>+ case 1:<br>+ return __readdr1 ();<br>+ break;<br>+<br>+ case 2:<br>+ return __readdr2 ();<br>+ break;<br>+<br>+ case 3:<br>+ return __readdr3 ();<br>+ break;<br>+<br>+ case 7:<br>+ return __readdr7 ();<br>+ break;<br>+<br>+ default:<br>+ return -1;<br>+ }<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writedr0(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%dr0"<br>+ :<br>+ : "r" (Data)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writedr1(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%dr1"<br>+ :<br>+ : "r" (Data)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writedr2(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%dr2"<br>+ :<br>+ : "r" (Data)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writedr3(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%dr3"<br>+ :<br>+ : "r" (Data)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writedr7(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%dr7"<br>+ :<br>+ : "r" (Data)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writedr(unsigned long reg, unsigned long Data)<br>+{<br>+ switch (reg){<br>+ case 0:<br>+ __writedr0 (Data);<br>+ break;<br>+<br>+ case 1:<br>+ __writedr1 (Data);<br>+ break;<br>+<br>+ case 2:<br>+ __writedr2 (Data);<br>+ break;<br>+<br>+ case 3:<br>+ __writedr3 (Data);<br>+ break;<br>+<br>+ case 7:<br>+ __writedr7 (Data);<br>+ break;<br>+<br>+ default:<br>+ ;<br>+ }<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readcr0(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%cr0, %[value]"<br>+ : [value] "=r" (value));<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readcr2(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%cr2, %[value]"<br>+ : [value] "=r" (value));<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readcr3(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%cr3, %[value]"<br>+ : [value] "=r" (value));<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readcr4(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%cr4, %[value]"<br>+ : [value] "=r" (value));<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readcr8(void)<br>+{<br>+ unsigned long value;<br>+ __asm__ __volatile__ (<br>+ "mov %%cr8, %[value]"<br>+ : [value] "=r" (value));<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) unsigned long __readcr(unsigned long reg)<br>+{<br>+ switch (reg){<br>+ case 0:<br>+ return __readcr0 ();<br>+ break;<br>+<br>+ case 2:<br>+ return __readcr2 ();<br>+ break;<br>+<br>+ case 3:<br>+ return __readcr3 ();<br>+ break;<br>+<br>+ case 4:<br>+ return __readcr4 ();<br>+ break;<br>+<br>+ case 8:<br>+ return __readcr8 ();<br>+ break;<br>+<br>+ default:<br>+ return -1;<br>+ }<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writecr0(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%cr0"<br>+ :<br>+ : "r" (Data)<br>+ : "memory"<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writecr2(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%cr2"<br>+ :<br>+ : "r" (Data)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writecr3(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%cr3"<br>+ :<br>+ : "r" (Data)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writecr4(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%cr4"<br>+ :<br>+ : "r" (Data)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writecr8(unsigned long Data)<br>+{<br>+ __asm__ __volatile__ (<br>+ "mov %0, %%cr8"<br>+ :<br>+ : "r" (Data)<br>+ );<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writecr(unsigned long reg, unsigned long Data)<br>+{<br>+ switch (reg){<br>+ case 0:<br>+ __writecr0 (Data);<br>+ break;<br>+<br>+ case 2:<br>+ __writecr2 (Data);<br>+ break;<br>+<br>+ case 3:<br>+ __writecr3 (Data);<br>+ break;<br>+<br>+ case 4:<br>+ __writecr4 (Data);<br>+ break;<br>+<br>+ case 8:<br>+ __writecr8 (Data);<br>+ break;<br>+<br>+ default:<br>+ ;<br>+ }<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) UINT64 __readmsr(UINT32 msr)<br>+{<br>+ UINT64 retval;<br>+ __asm__ __volatile__(<br>+ "rdmsr"<br>+ : "=A" (retval)<br>+ : "c" (msr)<br>+ );<br>+ return retval;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __writemsr (UINT32 msr, UINT64 Value)<br>+{<br>+ __asm__ __volatile__ (<br>+ "wrmsr"<br>+ :<br>+ : "c" (msr), "A" (Value)<br>+ );<br>+}<br>+<br>+#if !defined(__clang__)<br>+static __inline__ __attribute__((always_inline)) UINT64 __rdtsc(void)<br>+{<br>+ UINT64 retval;<br>+ __asm__ __volatile__ (<br>+ "rdtsc"<br>+ : "=A" (retval));<br>+ return retval;<br>+}<br>+#endif<br>+<br>+static __inline__ __attribute__((always_inline)) void __cpuid(int CPUInfo[], const int InfoType)<br>+{<br>+ __asm__ __volatile__(<br>+ "cpuid"<br>+ :"=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3])<br>+ : "a" (InfoType)<br>+ );<br>+}<br>+<br>+<br>+static __inline__ __attribute__((always_inline)) void _disable(void)<br>+{<br>+ __asm__ __volatile__ ("cli");<br>+}<br>+<br>+<br>+static __inline__ __attribute__((always_inline)) void _enable(void)<br>+{<br>+ __asm__ __volatile__ ("sti");<br>+}<br>+<br>+<br>+static __inline__ __attribute__((always_inline)) void __halt(void)<br>+{<br>+ __asm__ __volatile__ ("hlt");<br>+}<br>+<br>+<br>+static __inline__ __attribute__((always_inline)) void __debugbreak(void)<br>+{<br>+ __asm__ __volatile__ ("int3");<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __invd(void)<br>+{<br>+ __asm__ __volatile__ ("invd");<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __wbinvd(void)<br>+{<br>+ __asm__ __volatile__ ("wbinvd");<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void __lidt(void *Source)<br>+{<br>+ __asm__ __volatile__("lidt %0" : : "m"(*(short*)Source));<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void<br>+__writefsbyte(const unsigned long Offset, const uint8_t Data)<br>+{<br>+ __asm__ ("movb %[Data], %%fs:%a[Offset]"<br>+ :<br>+ : [Offset] "ir" (Offset), [Data] "iq" (Data));<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void<br>+__writefsword(const unsigned long Offset, const uint16_t Data)<br>+{<br>+ __asm__ ("movw %[Data], %%fs:%a[Offset]"<br>+ :<br>+ : [Offset] "ir" (Offset), [Data] "ir" (Data));<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void<br>+__writefsdword(const unsigned long Offset, const uint32_t Data)<br>+{<br>+ __asm__ ("movl %[Data], %%fs:%a[Offset]"<br>+ :<br>+ : [Offset] "ir" (Offset), [Data] "ir" (Data));<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) uint8_t<br>+__readfsbyte(const unsigned long Offset)<br>+{<br>+ unsigned char value;<br>+ __asm__ ("movb %%fs:%a[Offset], %[value]"<br>+ : [value] "=q" (value)<br>+ : [Offset] "ir" (Offset));<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) uint16_t<br>+__readfsword(const unsigned long Offset)<br>+{<br>+ unsigned short value;<br>+ __asm__ ("movw %%fs:%a[Offset], %[value]"<br>+ : [value] "=q" (value)<br>+ : [Offset] "ir" (Offset));<br>+ return value;<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) uint32_t<br>+__readfsdword(unsigned long Offset)<br>+{<br>+ unsigned long value;<br>+ __asm__ ("mov %%fs:%a[Offset], %[value]"<br>+ : [value] "=r" (value)<br>+ : [Offset] "ir" (Offset));<br>+ return value;<br>+}<br>+<br>+#ifdef __SSE3__<br>+typedef long long __v2di __attribute__((__vector_size__ (16)));<br>+typedef long long __m128i __attribute__((__vector_size__ (16), __may_alias__));<br>+<br>+static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs2 (void *__A, __m128i __B)<br>+{<br>+ __asm__(".byte 0x64"); // fs prefix<br>+#if defined(__clang__)<br>+ __builtin_nontemporal_store((__v2di)__B, (__v2di *)__A);<br>+#else<br>+ __builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B);<br>+#endif<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void _mm_stream_si128_fs (void *__A, void *__B)<br>+{<br>+ __m128i data;<br>+ data = (__m128i) __builtin_ia32_lddqu ((char const *)__B);<br>+ _mm_stream_si128_fs2 (__A, data);<br>+}<br>+<br>+static __inline__ __attribute__((always_inline)) void _mm_clflush_fs (void *__A)<br>+{<br>+ __asm__(".byte 0x64"); // fs prefix<br>+ __builtin_ia32_clflush (__A);<br>+}<br>+<br>+#if !defined(__clang__)<br>+static __inline __attribute__(( __always_inline__)) void _mm_mfence (void)<br>+{<br>+ __builtin_ia32_mfence ();<br>+}<br>+#else<br>+void _mm_mfence(void);<br>+#endif<br>+<br>+#if !defined(__clang__)<br>+static __inline __attribute__(( __always_inline__)) void _mm_sfence (void)<br>+{<br>+ __builtin_ia32_sfence ();<br>+}<br>+#else<br>+void _mm_sfence(void);<br>+#endif<br>+#endif /* __SSE3__ */<br>+<br>+#endif /* defined (__GNUC__) */<br></pre><p>To view, visit <a href="https://review.coreboot.org/22498">change 22498</a>. To unsubscribe, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/22498"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I5d37fac72871f2617c4be45c151741436cbfce96 </div>
<div style="display:none"> Gerrit-Change-Number: 22498 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Martin Roth <martinroth@google.com> </div>