From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Fioravante Subject: [PATCH mini-os enhancements for vtpm 3/8] add endian support to mini-os Date: Mon, 17 Sep 2012 17:57:11 -0400 Message-ID: <50579CB7.1010707@jhuapl.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7085357906659809616==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Samuel Thibault , "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a cryptographically signed message in MIME format. --===============7085357906659809616== Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; boundary="------------ms070602050804030406000602" This is a cryptographically signed message in MIME format. --------------ms070602050804030406000602 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable This patch addes byte swapping macros and endian support to mini-os Signed off by: Matthew Fioravante matthew.fioravante@jhuapl.edu diff --git a/extras/mini-os/include/byteorder.h b/extras/mini-os/include/byteorder.h --- /dev/null +++ b/extras/mini-os/include/byteorder.h @@ -0,0 +1,36 @@ +#ifndef MINIOS_BYTEORDER_H +#define MINIOS_BYTEORDER_H + +#include +#include + +#if __BYTE_ORDER =3D=3D __LITTLE_ENDIAN +#define be16_to_cpu(v) bswap_16(v) +#define be32_to_cpu(v) bswap_32(v) +#define be64_to_cpu(v) bswap_64(v) + +#define le16_to_cpu(v) (v) +#define le32_to_cpu(v) (v) +#define le64_to_cpu(v) (v) + +#else /*__BIG_ENDIAN*/ +#define be16_to_cpu(v) (v) +#define be32_to_cpu(v) (v) +#define be64_to_cpu(v) (v) + +#define le16_to_cpu(v) bswap_16(v) +#define le32_to_cpu(v) bswap_32(v) +#define le64_to_cpu(v) bswap_64(v) + +#endif + +#define cpu_to_be16(v) be16_to_cpu(v) +#define cpu_to_be32(v) be32_to_cpu(v) +#define cpu_to_be64(v) be64_to_cpu(v) + +#define cpu_to_le16(v) le16_to_cpu(v) +#define cpu_to_le32(v) le32_to_cpu(v) +#define cpu_to_le64(v) le64_to_cpu(v) + + +#endif diff --git a/extras/mini-os/include/byteswap.h b/extras/mini-os/include/byteswap.h --- a/extras/mini-os/include/byteswap.h +++ b/extras/mini-os/include/byteswap.h @@ -4,30 +4,36 @@ /* Unfortunately not provided by newlib. */ =20 #include -static inline uint16_t bswap_16(uint16_t x) -{ - return - ((((x) & 0xff00) >> 8) | (((x) & 0xff) << 8)); -} - -static inline uint32_t bswap_32(uint32_t x) -{ - return - ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | - (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); -} - -static inline uint64_t bswap_64(uint64_t x) -{ - return - ((((x) & 0xff00000000000000ULL) >> 56) | - (((x) & 0x00ff000000000000ULL) >> 40) | - (((x) & 0x0000ff0000000000ULL) >> 24) | - (((x) & 0x000000ff00000000ULL) >> 8) | - (((x) & 0x00000000ff000000ULL) << 8) | - (((x) & 0x0000000000ff0000ULL) << 24) | - (((x) & 0x000000000000ff00ULL) << 40) | - (((x) & 0x00000000000000ffULL) << 56)); -} + +#define bswap_16(x) ((uint16_t)( \ + (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \ + (((uint16_t)(x) & (uint16_t)0xff00U) >> 8))) + +/* Use gcc optimized versions if they exist */ +#if __GNUC__ > 4 || (__GNUC__ =3D=3D 4 && __GNUC_MINOR__ >=3D 3) +#define bswap_32(v) __builtin_bswap32(v) +#define bswap_64(v) __builtin_bswap64(v) +#else + +#define bswap_32(x) ((uint32_t)( \ + (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ + (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ + (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ + (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) + +#define bswap_64(x) ((uint64_t)( \ + (((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \ + (((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ + (((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ + (((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ + (((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ + (((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ + (((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ + (((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56)))= + +#endif + + + =20 #endif /* _BYTESWAP_H */ diff --git a/extras/mini-os/include/endian.h b/extras/mini-os/include/endian.h --- /dev/null +++ b/extras/mini-os/include/endian.h @@ -0,0 +1,15 @@ +#ifndef _ENDIAN_H_ +#define _ENDIAN_H_ + +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __PDP_ENDIAN 3412 + +#define ARCH_ENDIAN_H +/* This will define __BYTE_ORDER for the current arch */ +#include +#undef ARCH_ENDIAN_H + +#include + +#endif /* endian.h */ diff --git a/extras/mini-os/include/ia64/arch_endian.h b/extras/mini-os/include/ia64/arch_endian.h --- /dev/null +++ b/extras/mini-os/include/ia64/arch_endian.h @@ -0,0 +1,7 @@ +#ifndef ARCH_ENDIAN_H +#error "Do not include arch_endian by itself, include endian.h" +#else + +#define __BYTE_ORDER __LITTLE_ENDIAN + +#endif diff --git a/extras/mini-os/include/ia64/arch_wordsize.h b/extras/mini-os/include/ia64/arch_wordsize.h --- /dev/null +++ b/extras/mini-os/include/ia64/arch_wordsize.h @@ -0,0 +1 @@ +#define __WORDSIZE 64 diff --git a/extras/mini-os/include/x86/arch_endian.h b/extras/mini-os/include/x86/arch_endian.h --- /dev/null +++ b/extras/mini-os/include/x86/arch_endian.h @@ -0,0 +1,7 @@ +#ifndef ARCH_ENDIAN_H +#error "Do not include arch_endian by itself, include endian.h" +#else + +#define __BYTE_ORDER __LITTLE_ENDIAN + +#endif diff --git a/extras/mini-os/include/x86/x86_32/arch_wordsize.h b/extras/mini-os/include/x86/x86_32/arch_wordsize.h --- /dev/null +++ b/extras/mini-os/include/x86/x86_32/arch_wordsize.h @@ -0,0 +1 @@ +#define __WORDSIZE 32 diff --git a/extras/mini-os/include/x86/x86_64/arch_wordsize.h b/extras/mini-os/include/x86/x86_64/arch_wordsize.h --- /dev/null +++ b/extras/mini-os/include/x86/x86_64/arch_wordsize.h @@ -0,0 +1,2 @@ +#define __WORDSIZE 64 +#define __WORDSIZE_COMPAT32 1 --------------ms070602050804030406000602 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIDyjCC A8YwggMvoAMCAQICBD/xyf0wDQYJKoZIhvcNAQEFBQAwLzELMAkGA1UEBhMCVVMxDzANBgNV BAoTBkpIVUFQTDEPMA0GA1UECxMGQklTRENBMB4XDTEwMDYxMTE4MjIwNloXDTEzMDYxMTE4 NTIwNlowZjELMAkGA1UEBhMCVVMxDzANBgNVBAoTBkpIVUFQTDEPMA0GA1UECxMGUGVvcGxl MTUwFgYDVQQLEw9WUE5Hcm91cC1CSVNEQ0EwGwYDVQQDExRNYXR0aGV3IEUgRmlvcmF2YW50 ZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAnpbwVSP6o1Nb5lcW7dd3yTo9iBJdi7qz 4nANOMFPK7JOy5npKN1iiousl28U/scUJES55gPwAWYJK3uVyQAsA4adgDKi5DoD1UHDQEwp bY7iHLJeq0NPr4BqYNqnCFPbE6HC8zSJrr4qKn+gVUQT39SIFqdiIPJwZL8FYTRQ/zsCAwEA AaOCAbYwggGyMAsGA1UdDwQEAwIHgDArBgNVHRAEJDAigA8yMDEwMDYxMTE4MjIwNlqBDzIw MTIwNzE3MjI1MjA2WjAbBg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UAwBwYFKw4DAgcwDQYI KoZIhvcNAwICASgwDQYJKoZIhvcNAQEBBQAEgYAqblOP2cx9G6BI1vdDLUVHeo0C74TMyLrP dT556ICer89ge8gWVIqC6sihsxZOmJ5NnFJB3uqT4654Smeu1eloktAYLxWO3UhKZ0TyEOy4 sYggNBqo9Tr2/dCEqyFeHZEqoNFnlMZ6cv4ylCw51ZlYzFsyZ7pCqTR95804NuaMDwAAAAAA AA== --------------ms070602050804030406000602-- --===============7085357906659809616== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============7085357906659809616==--