From: Ralph Campbell Date: Sun, 21 Jun 1992 03:40:07 +0000 (-0800) Subject: add bigendian support X-Git-Tag: BSD-4_4-Snapshot-Development~6663 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/3efc1bf9e2661973e5ef526ff9ee4985c995dd5c add bigendian support SCCS-vsn: lib/libc/mips/net/htonl.s 5.3 SCCS-vsn: lib/libc/mips/net/htons.s 5.3 SCCS-vsn: lib/libc/mips/string/bcmp.s 5.3 SCCS-vsn: lib/libc/mips/string/bcopy.s 5.3 --- diff --git a/usr/src/lib/libc/mips/net/htonl.s b/usr/src/lib/libc/mips/net/htonl.s index fa6d4903ce..f071ca1eac 100644 --- a/usr/src/lib/libc/mips/net/htonl.s +++ b/usr/src/lib/libc/mips/net/htonl.s @@ -11,15 +11,20 @@ #include "DEFS.h" #if defined(LIBC_SCCS) && !defined(lint) - ASMSTR("@(#)htonl.s 5.2 (Berkeley) %G%") + ASMSTR("@(#)htonl.s 5.3 (Berkeley) %G%") #endif /* LIBC_SCCS and not lint */ +#include +#undef htonl +#undef ntohl + /* * netorder = htonl(hostorder) * hostorder = ntohl(netorder) */ LEAF(htonl) # a0 = 0x11223344, return 0x44332211 ALEAF(ntohl) +#if BYTE_ORDER == LITTLE_ENDIAN srl v1, a0, 24 # v1 = 0x00000011 sll v0, a0, 24 # v0 = 0x44000000 or v0, v0, v1 @@ -29,5 +34,12 @@ ALEAF(ntohl) srl v1, a0, 8 and v1, v1, 0xff00 # v1 = 0x00002200 or v0, v0, v1 +#else +#if BYTE_ORDER == BIG_ENDIAN + move v0, a0 +#else + ERROR +#endif +#endif j ra END(htonl) diff --git a/usr/src/lib/libc/mips/net/htons.s b/usr/src/lib/libc/mips/net/htons.s index a63ea5448f..f330466922 100644 --- a/usr/src/lib/libc/mips/net/htons.s +++ b/usr/src/lib/libc/mips/net/htons.s @@ -11,19 +11,31 @@ #include "DEFS.h" #if defined(LIBC_SCCS) && !defined(lint) - ASMSTR("@(#)htons.s 5.2 (Berkeley) %G%") + ASMSTR("@(#)htons.s 5.3 (Berkeley) %G%") #endif /* LIBC_SCCS and not lint */ +#include +#undef htons +#undef ntohs + /* * netorder = htons(hostorder) * hostorder = ntohs(netorder) */ LEAF(htons) ALEAF(ntohs) +#if BYTE_ORDER == LITTLE_ENDIAN srl v0, a0, 8 and v0, v0, 0xff sll v1, a0, 8 and v1, v1, 0xff00 or v0, v0, v1 +#else +#if BYTE_ORDER == BIG_ENDIAN + move v0, a0 +#else + ERROR +#endif +#endif j ra END(htons) diff --git a/usr/src/lib/libc/mips/string/bcmp.s b/usr/src/lib/libc/mips/string/bcmp.s index 0d18276f72..5f620a54fd 100644 --- a/usr/src/lib/libc/mips/string/bcmp.s +++ b/usr/src/lib/libc/mips/string/bcmp.s @@ -11,11 +11,26 @@ #include "DEFS.h" #if defined(LIBC_SCCS) && !defined(lint) - ASMSTR("@(#)bcmp.s 5.2 (Berkeley) %G%") + ASMSTR("@(#)bcmp.s 5.3 (Berkeley) %G%") #endif /* LIBC_SCCS and not lint */ /* bcmp(s1, s2, n) */ +#include + +#if BYTE_ORDER == LITTLE_ENDIAN +# define LWHI lwr +# define LWLO lwl +# define SWHI swr +# define SWLO swl +#endif +#if BYTE_ORDER == BIG_ENDIAN +# define LWHI lwl +# define LWLO lwr +# define SWHI swl +# define SWLO swr +#endif + LEAF(bcmp) .set noreorder blt a2, 16, small # is it worth any trouble? @@ -28,8 +43,8 @@ LEAF(bcmp) beq a3, zero, 1f subu a2, a2, a3 # subtract from remaining count move v0, v1 # init v0,v1 so unmodified bytes match - lwr v0, 0(a0) # read 1, 2, or 3 bytes - lwr v1, 0(a1) + LWHI v0, 0(a0) # read 1, 2, or 3 bytes + LWHI v1, 0(a1) addu a1, a1, a3 bne v0, v1, nomatch addu a0, a0, a3 @@ -64,8 +79,8 @@ unaligned: subu a2, a2, a3 # which has to be >= (16-3) & ~3 addu a3, a3, a0 # compute ending address 3: - lwr v0, 0(a0) # compare words a0 unaligned, a1 aligned - lwl v0, 3(a0) + LWHI v0, 0(a0) # compare words a0 unaligned, a1 aligned + LWLO v0, 3(a0) lw v1, 0(a1) addu a0, a0, 4 bne v0, v1, nomatch diff --git a/usr/src/lib/libc/mips/string/bcopy.s b/usr/src/lib/libc/mips/string/bcopy.s index 51b7aaf031..e1801f9b36 100644 --- a/usr/src/lib/libc/mips/string/bcopy.s +++ b/usr/src/lib/libc/mips/string/bcopy.s @@ -11,11 +11,26 @@ #include "DEFS.h" #if defined(LIBC_SCCS) && !defined(lint) - ASMSTR("@(#)bcopy.s 5.2 (Berkeley) %G%") + ASMSTR("@(#)bcopy.s 5.3 (Berkeley) %G%") #endif /* LIBC_SCCS and not lint */ /* bcopy(s1, s2, n) */ +#include + +#if BYTE_ORDER == LITTLE_ENDIAN +# define LWHI lwr +# define LWLO lwl +# define SWHI swr +# define SWLO swl +#endif +#if BYTE_ORDER == BIG_ENDIAN +# define LWHI lwl +# define LWLO lwr +# define SWHI swl +# define SWLO swr +#endif + LEAF(bcopy) .set noreorder addu t0, a0, a2 # t0 = end of s1 region @@ -46,10 +61,10 @@ forward: beq a3, zero, 1f subu a2, a2, a3 # subtract from remaining count - lwr v0, 0(a0) # get next 4 bytes (unaligned) - lwl v0, 3(a0) + LWHI v0, 0(a0) # get next 4 bytes (unaligned) + LWLO v0, 3(a0) addu a0, a0, a3 - swr v0, 0(a1) # store 1, 2, or 3 bytes to align a1 + SWHI v0, 0(a1) # store 1, 2, or 3 bytes to align a1 addu a1, a1, a3 1: and v0, a2, 3 # compute number of words left @@ -57,8 +72,8 @@ forward: move a2, v0 addu a3, a3, a0 # compute ending address 2: - lwr v0, 0(a0) # copy words a0 unaligned, a1 aligned - lwl v0, 3(a0) + LWHI v0, 0(a0) # copy words a0 unaligned, a1 aligned + LWLO v0, 3(a0) addu a0, a0, 4 addu a1, a1, 4 bne a0, a3, 2b @@ -68,9 +83,9 @@ forward: aligned: beq a3, zero, 1f subu a2, a2, a3 # subtract from remaining count - lwr v0, 0(a0) # copy 1, 2, or 3 bytes to align + LWHI v0, 0(a0) # copy 1, 2, or 3 bytes to align addu a0, a0, a3 - swr v0, 0(a1) + SWHI v0, 0(a1) addu a1, a1, a3 1: and v0, a2, 3 # compute number of whole words left