debuggers.hg
changeset 13696:f8ddcb758117
Clean up libelf endian macros and includes.
Based on a patch from John Levon <john.levon@sun.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
Based on a patch from John Levon <john.levon@sun.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kaf24@localhost.localdomain |
---|---|
date | Sun Jan 28 19:02:00 2007 +0000 (2007-01-28) |
parents | bef8a8b1e400 |
children | b2c1eeee2dcf 7286802c9619 |
files | xen/common/libelf/libelf-private.h xen/common/libelf/libelf-tools.c xen/include/public/libelf.h |
line diff
1.1 --- a/xen/common/libelf/libelf-private.h Sun Jan 28 18:45:04 2007 +0000 1.2 +++ b/xen/common/libelf/libelf-private.h Sun Jan 28 19:02:00 2007 +0000 1.3 @@ -1,7 +1,13 @@ 1.4 +#ifndef __LIBELF_PRIVATE_H__ 1.5 +#define __LIBELF_PRIVATE_H_ 1.6 + 1.7 #ifdef __XEN__ 1.8 1.9 +#include <xen/config.h> 1.10 +#include <xen/types.h> 1.11 #include <xen/string.h> 1.12 #include <xen/lib.h> 1.13 +#include <asm/byteorder.h> 1.14 #include <public/elfnote.h> 1.15 #include <public/libelf.h> 1.16 1.17 @@ -11,29 +17,25 @@ 1.18 printk(fmt, ## args ) 1.19 1.20 #define strtoull(str, end, base) simple_strtoull(str, end, base) 1.21 -#define bswap_16(x) \ 1.22 - ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) 1.23 -#define bswap_32(x) \ 1.24 - ( (((x) & 0xff000000) >> 24) \ 1.25 - | (((x) & 0x00ff0000) >> 8) \ 1.26 - | (((x) & 0x0000ff00) << 8) \ 1.27 - | (((x) & 0x000000ff) << 24)) 1.28 -#define bswap_64(x) \ 1.29 - ( (((x) & 0xff00000000000000ull) >> 56) \ 1.30 - | (((x) & 0x00ff000000000000ull) >> 40) \ 1.31 - | (((x) & 0x0000ff0000000000ull) >> 24) \ 1.32 - | (((x) & 0x000000ff00000000ull) >> 8) \ 1.33 - | (((x) & 0x00000000ff000000ull) << 8) \ 1.34 - | (((x) & 0x0000000000ff0000ull) << 24) \ 1.35 - | (((x) & 0x000000000000ff00ull) << 40) \ 1.36 - | (((x) & 0x00000000000000ffull) << 56)) 1.37 +#define bswap_16(x) swab16(x) 1.38 +#define bswap_32(x) swab32(x) 1.39 +#define bswap_64(x) swab64(x) 1.40 1.41 #else /* !__XEN__ */ 1.42 1.43 #include <stdio.h> 1.44 #include <stdlib.h> 1.45 #include <string.h> 1.46 +#include <stddef.h> 1.47 +#include <inttypes.h> 1.48 +#ifdef __sun__ 1.49 +#include <sys/byteorder.h> 1.50 +#define bswap_16(x) BSWAP_16(x) 1.51 +#define bswap_32(x) BSWAP_32(x) 1.52 +#define bswap_64(x) BSWAP_64(x) 1.53 +#else 1.54 #include <byteswap.h> 1.55 +#endif 1.56 #include <xen/elfnote.h> 1.57 #include <xen/libelf.h> 1.58 1.59 @@ -49,3 +51,5 @@ 1.60 } while (0) 1.61 1.62 #endif 1.63 + 1.64 +#endif /* __LIBELF_PRIVATE_H_ */
2.1 --- a/xen/common/libelf/libelf-tools.c Sun Jan 28 18:45:04 2007 +0000 2.2 +++ b/xen/common/libelf/libelf-tools.c Sun Jan 28 19:02:00 2007 +0000 2.3 @@ -7,7 +7,7 @@ 2.4 /* ------------------------------------------------------------------------ */ 2.5 2.6 uint64_t elf_access_unsigned(struct elf_binary * elf, const void *ptr, 2.7 - off_t offset, size_t size) 2.8 + uint64_t offset, size_t size) 2.9 { 2.10 int need_swap = elf_swap(elf); 2.11 const uint8_t *u8; 2.12 @@ -35,7 +35,7 @@ uint64_t elf_access_unsigned(struct elf_ 2.13 } 2.14 2.15 int64_t elf_access_signed(struct elf_binary *elf, const void *ptr, 2.16 - off_t offset, size_t size) 2.17 + uint64_t offset, size_t size) 2.18 { 2.19 int need_swap = elf_swap(elf); 2.20 const int8_t *s8;
3.1 --- a/xen/include/public/libelf.h Sun Jan 28 18:45:04 2007 +0000 3.2 +++ b/xen/include/public/libelf.h Sun Jan 28 19:02:00 2007 +0000 3.3 @@ -1,25 +1,12 @@ 3.4 #ifndef __XC_LIBELF__ 3.5 #define __XC_LIBELF__ 1 3.6 3.7 -#ifdef __XEN__ 3.8 - 3.9 -#include <xen/inttypes.h> 3.10 -#include <public/features.h> 3.11 -typedef uint64_t off_t; 3.12 - 3.13 -#define LITTLE_ENDIAN 1234 3.14 -#define BIG_ENDIAN 4321 3.15 #if defined(__i386__) || defined(__x86_64) || defined(__ia64__) 3.16 -#define BYTE_ORDER LITTLE_ENDIAN 3.17 +#define XEN_ELF_LITTLE_ENDIAN 3.18 #elif defined(__powerpc__) 3.19 -#define BYTE_ORDER BIG_ENDIAN 3.20 -#endif 3.21 - 3.22 -#else /* !__XEN__ */ 3.23 - 3.24 -#include <stddef.h> 3.25 -#include <inttypes.h> 3.26 - 3.27 +#define XEN_ELF_BIG_ENDIAN 3.28 +#else 3.29 +#error define architectural endianness 3.30 #endif 3.31 3.32 #undef ELFSIZE 3.33 @@ -91,14 +78,10 @@ struct elf_binary { 3.34 /* ------------------------------------------------------------------------ */ 3.35 /* accessing elf header fields */ 3.36 3.37 -#if !defined(BYTE_ORDER) 3.38 -# error BYTE_ORDER not defined 3.39 -#elif BYTE_ORDER == BIG_ENDIAN 3.40 +#ifdef XEN_ELF_BIG_ENDIAN 3.41 # define NATIVE_ELFDATA ELFDATA2MSB 3.42 -#elif BYTE_ORDER == LITTLE_ENDIAN 3.43 +#else 3.44 # define NATIVE_ELFDATA ELFDATA2LSB 3.45 -#else 3.46 -# error BYTE_ORDER unknown 3.47 #endif 3.48 3.49 #define elf_32bit(elf) (ELFCLASS32 == (elf)->class) 3.50 @@ -131,9 +114,9 @@ struct elf_binary { 3.51 : sizeof((str)->e32)) 3.52 3.53 uint64_t elf_access_unsigned(struct elf_binary *elf, const void *ptr, 3.54 - off_t offset, size_t size); 3.55 + uint64_t offset, size_t size); 3.56 int64_t elf_access_signed(struct elf_binary *elf, const void *ptr, 3.57 - off_t offset, size_t size); 3.58 + uint64_t offset, size_t size); 3.59 3.60 uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr); 3.61