diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 77de28b9c..fcbcd3f21 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,16 @@ +2002-07-02 Chris Demetriou + + * libc/include/sys/config.h (__IEEE_LITTLE_ENDIAN) + (__IEEE_BIG_ENDIAN): Define appropriately for MIPS. + Check that one of them is defined and error out if not. + Add any platforms defined in that are missing. + * libc/search/hash.h (DB_BYTE_ORDER, DB_BIG_ENDIAN) + (DB_LITTLE_ENDIAN): New defines. + * libc/search/hash.c: Replace all incorrect checks for + _IEEE_LITTLE_ENDIAN with tests of BYTE_ORDER, and all uses of + BYTE_ORDER, LITTLE_ENDIAN, and BIG_ENDIAN with DB_* versions. + * libc/search/hash_page.c: Likewise. + 2002-06-28 Thomas Fitzsimmons * libm/mathfp/sf_pow.c (powf): Change k from int to float. diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h index ae4fcdaa3..928927334 100644 --- a/newlib/libc/include/sys/config.h +++ b/newlib/libc/include/sys/config.h @@ -45,11 +45,23 @@ #define __IEEE_BIG_ENDIAN #endif +#ifdef __sh__ +#ifdef __LITTLE_ENDIAN__ +#define __IEEE_LITTLE_ENDIAN +#else +#define __IEEE_BIG_ENDIAN +#endif +#if defined(__SH3E__) || defined(__SH4_SINGLE_ONLY__) +#define _DOUBLE_IS_32BITS +#endif +#endif + #ifdef ___AM29K__ #define _FLOAT_RET double #endif #ifdef __i386__ +#define __IEEE_LITTLE_ENDIAN #ifndef __unix__ /* in other words, go32 */ #define _FLOAT_RET double @@ -82,6 +94,13 @@ #define __IEEE_LITTLE_ENDIAN #endif +#ifdef __MIPSEL__ +#define __IEEE_LITTLE_ENDIAN +#endif +#ifdef __MIPSEB__ +#define __IEEE_BIG_ENDIAN +#endif + #ifdef __MMIX__ #define __IEEE_BIG_ENDIAN #endif @@ -97,19 +116,57 @@ #define __IEEE_LITTLE_ENDIAN #endif +#ifdef __v800 +#define __IEEE_LITTLE_ENDIAN +#endif + #ifdef __v850 #define __IEEE_LITTLE_ENDIAN #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__sda__)) #endif +#ifdef __ia64__ +#ifdef __BIG_ENDIAN__ +#define __IEEE_BIG_ENDIAN +#else +#define __IEEE_LITTLE_ENDIAN +#endif +#endif + #ifdef __D30V__ #define __IEEE_BIG_ENDIAN #endif +#ifdef __m88k__ +#define __IEEE_BIG_ENDIAN +#endif + /* For the PowerPC eabi, force the _impure_ptr to be in .sdata */ -#if defined(__PPC__) && defined(_CALL_SYSV) +#if defined(__PPC__) +#if defined(_CALL_SYSV) #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__section__(".sdata"))) #endif +#if (defined(_BIG_ENDIAN) && _BIG_ENDIAN) || (defined(_AIX) && _AIX) +#define __IEEE_BIG_ENDIAN +#else +#if (defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN) || (defined(__sun__) && __sun__) || (defined(_WIN32) && _WIN32) +#define __IEEE_LITTLE_ENDIAN +#endif +#endif +#endif + +#if defined(__arm__) || defined(__thumb__) +/* ARM always has big-endian words. Within those words the byte ordering + will be big or little endian depending upon the target. */ +#define __IEEE_BIG_ENDIAN +#ifdef __ARMEL__ +#define __IEEE_BYTES_LITTLE_ENDIAN +#endif +#endif + +#ifdef __hppa__ +#define __IEEE_BIG_ENDIAN +#endif #ifdef __sparc__ #ifdef __LITTLE_ENDIAN_DATA__ @@ -119,6 +176,11 @@ #endif #endif +#if defined(__or32__) || defined(__or1k__) || defined(__or16__) +#define __IEEE_BIG_ENDIAN +#endif + + #ifdef __xstormy16__ #define __IEEE_LITTLE_ENDIAN #define __SMALL_BITFIELDS @@ -164,6 +226,22 @@ #define _POINTER_INT long #endif +#ifdef __arc__ +#ifdef __big_endian__ +#define __IEEE_BIG_ENDIAN +#else +#define __IEEE_LITTLE_ENDIAN +#endif +#endif + +#ifdef __fr30__ +#define __IEEE_BIG_ENDIAN +#endif + +#ifdef __mcore__ +#define __IEEE_BIG_ENDIAN +#endif + #ifdef __frv__ #define __IEEE_BIG_ENDIAN #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__section__(".sdata"))) @@ -202,4 +280,10 @@ #define _READ_WRITE_RETURN_TYPE int #endif +#ifndef __IEEE_BIG_ENDIAN +#ifndef __IEEE_LITTLE_ENDIAN +#error Endianess not declared!! +#endif /* not __IEEE_LITTLE_ENDIAN */ +#endif /* not __IEEE_BIG_ENDIAN */ + #endif /* __SYS_CONFIG_H__ */ diff --git a/newlib/libc/search/hash.c b/newlib/libc/search/hash.c index 5bd4fb77e..3aa3eb7ea 100644 --- a/newlib/libc/search/hash.c +++ b/newlib/libc/search/hash.c @@ -72,7 +72,7 @@ static int hash_sync(const DB *, __uint32_t); static int hdestroy(HTAB *); static HTAB *init_hash(HTAB *, const char *, HASHINFO *); static int init_htab(HTAB *, int); -#ifdef _IEEE_LITTLE_ENDIAN +#if (BYTE_ORDER == LITTLE_ENDIAN) static void swap_header(HTAB *); static void swap_header_copy(HASHHDR *, HASHHDR *); #endif @@ -156,7 +156,7 @@ __hash_open(file, flags, mode, info, dflags) hashp->hash = __default_hash; hdrsize = read(hashp->fp, &hashp->hdr, sizeof(HASHHDR)); -#ifdef _IEEE_LITTLE_ENDIAN +#if (BYTE_ORDER == LITTLE_ENDIAN) swap_header(hashp); #endif if (hdrsize == -1) @@ -299,7 +299,7 @@ init_hash(hashp, file, info) nelem = 1; hashp->NKEYS = 0; - hashp->LORDER = BYTE_ORDER; + hashp->LORDER = DB_BYTE_ORDER; hashp->BSIZE = DEF_BUCKET_SIZE; hashp->BSHIFT = DEF_BUCKET_SHIFT; hashp->SGSIZE = DEF_SEGSIZE; @@ -335,8 +335,8 @@ init_hash(hashp, file, info) if (info->nelem) nelem = info->nelem; if (info->lorder) { - if (info->lorder != BIG_ENDIAN && - info->lorder != LITTLE_ENDIAN) { + if (info->lorder != DB_BIG_ENDIAN && + info->lorder != DB_LITTLE_ENDIAN) { errno = EINVAL; return (NULL); } @@ -495,7 +495,7 @@ flush_meta(hashp) HTAB *hashp; { HASHHDR *whdrp; -#ifdef _IEEE_LITTLE_ENDIAN +#if (BYTE_ORDER == LITTLE_ENDIAN) HASHHDR whdr; #endif int fp, i, wsize; @@ -508,7 +508,7 @@ flush_meta(hashp) fp = hashp->fp; whdrp = &hashp->hdr; -#ifdef _IEEE_LITTLE_ENDIAN +#if (BYTE_ORDER == LITTLE_ENDIAN) whdrp = &whdr; swap_header_copy(&hashp->hdr, whdrp); #endif @@ -941,7 +941,7 @@ alloc_segs(hashp, nsegs) return (0); } -#ifdef _IEEE_LITTLE_ENDIAN +#if (BYTE_ORDER == LITTLE_ENDIAN) /* * Hashp->hdr needs to be byteswapped. */ diff --git a/newlib/libc/search/hash.h b/newlib/libc/search/hash.h index 8287eb7e5..db9e96dd8 100644 --- a/newlib/libc/search/hash.h +++ b/newlib/libc/search/hash.h @@ -39,18 +39,18 @@ #include +/* Check that newlib understands the byte order of its target system. */ #ifndef BYTE_ORDER -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN 1234 +#error BYTE_ORDER not defined by sys/param.h #endif -#ifndef BIG_ENDIAN -#define BIG_ENDIAN 4321 -#endif -#ifdef __IEEE_LITTLE_ENDIAN -#define BYTE_ORDER LITTLE_ENDIAN + +/* Define DB endianness constants based on target endianness. */ +#define DB_LITTLE_ENDIAN 1234 +#define DB_BIG_ENDIAN 4321 +#if (BYTE_ORDER == LITTLE_ENDIAN) +#define DB_BYTE_ORDER DB_LITTLE_ENDIAN #else -#define BYTE_ORDER BIG_ENDIAN -#endif +#define DB_BYTE_ORDER DB_BIG_ENDIAN #endif /* Operations */ diff --git a/newlib/libc/search/hash_page.c b/newlib/libc/search/hash_page.c index 896aee8d5..cffb20aa3 100644 --- a/newlib/libc/search/hash_page.c +++ b/newlib/libc/search/hash_page.c @@ -552,7 +552,7 @@ __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) if (!is_bitmap && !bp[0]) { PAGE_INIT(p); } else - if (hashp->LORDER != BYTE_ORDER) { + if (hashp->LORDER != DB_BYTE_ORDER) { int i, max; if (is_bitmap) { @@ -591,7 +591,7 @@ __put_page(hashp, p, bucket, is_bucket, is_bitmap) return (-1); fd = hashp->fp; - if (hashp->LORDER != BYTE_ORDER) { + if (hashp->LORDER != DB_BYTE_ORDER) { int i; int max;