diff options
Diffstat (limited to 'usr/src/lib/libc/i386/gen')
| -rw-r--r-- | usr/src/lib/libc/i386/gen/byteorder.s | 63 | ||||
| -rw-r--r-- | usr/src/lib/libc/i386/gen/byteorder64.c | 37 | ||||
| -rw-r--r-- | usr/src/lib/libc/i386/gen/endian.c | 57 |
3 files changed, 156 insertions, 1 deletions
diff --git a/usr/src/lib/libc/i386/gen/byteorder.s b/usr/src/lib/libc/i386/gen/byteorder.s index 9689b2b6bf..2b1204d1ba 100644 --- a/usr/src/lib/libc/i386/gen/byteorder.s +++ b/usr/src/lib/libc/i386/gen/byteorder.s @@ -21,6 +21,7 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2015, Joyent, Inc. */ .file "byteorder.s" @@ -32,7 +33,9 @@ * As such, they could be implemented as a single routine, using * multiple ALTENTRY/SET_SIZE definitions. We don't do this so * that they will have unique addresses, allowing DTrace and - * other debuggers to tell them apart. + * other debuggers to tell them apart. With the endian + * functions we do the same, even though it's similarly + * repetitive. */ / unsigned long htonl( hl ) @@ -70,3 +73,61 @@ shrl $16, %eax / moves high 16-bit to low 16-bit ret / return (%eax) SET_SIZE(ntohs) + +/ uint16_t htobe16(uint16_t in) +/ +/ Convert in to big endian, eg. htons() +/ + ENTRY(htobe16) + movl 4(%esp), %eax / %eax = hs + bswap %eax / reverses the byte order of %eax + shrl $16, %eax / moves high 16-bit to low 16-bit + ret / return (%eax) + SET_SIZE(htobe16) + +/ uint32_t htobe32(uint32_t in) +/ +/ Convert in to big endian, eg. htonl() +/ + ENTRY(htobe32) + movl 4(%esp), %eax / %eax = hl + bswap %eax / reverses the byte order of %eax + ret / return (%eax) + SET_SIZE(htobe32) + +/ uint16_t betoh16(uint16_t in) +/ uint16_t be16toh(uint16_t in) +/ +/ Convert in to little endian, eg. ntohs() +/ + ENTRY(betoh16) + movl 4(%esp), %eax / %eax = hs + bswap %eax / reverses the byte order of %eax + shrl $16, %eax / moves high 16-bit to low 16-bit + ret / return (%eax) + SET_SIZE(betoh16) + + ENTRY(be16toh) + movl 4(%esp), %eax / %eax = hs + bswap %eax / reverses the byte order of %eax + shrl $16, %eax / moves high 16-bit to low 16-bit + ret / return (%eax) + SET_SIZE(be16toh) + + +/ uint32_t be32toh(uint32_t in) +/ uint32_t betoh32(uint32_t in) +/ +/ Convert in to little endian, eg. ntohl() +/ + ENTRY(be32toh) + movl 4(%esp), %eax / %eax = hl + bswap %eax / reverses the byte order of %eax + ret / return (%eax) + SET_SIZE(be32toh) + + ENTRY(betoh32) + movl 4(%esp), %eax / %eax = hl + bswap %eax / reverses the byte order of %eax + ret / return (%eax) + SET_SIZE(betoh32) diff --git a/usr/src/lib/libc/i386/gen/byteorder64.c b/usr/src/lib/libc/i386/gen/byteorder64.c index 3806a62f34..00c37d2a1b 100644 --- a/usr/src/lib/libc/i386/gen/byteorder64.c +++ b/usr/src/lib/libc/i386/gen/byteorder64.c @@ -22,6 +22,7 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2015, Joyent, Inc. */ #include <sys/isa_defs.h> @@ -47,4 +48,40 @@ ntohll(uint64_t in) return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32); } +uint64_t +htobe64(uint64_t in) +{ + return (htonl(in >> 32) | ((uint64_t)htonl(in) << 32)); +} + +uint64_t +htole64(uint64_t in) +{ + return (in); +} + +uint64_t +betoh64(uint64_t in) +{ + return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32); +} + +uint64_t +letoh64(uint64_t in) +{ + return (in); +} + +uint64_t +be64toh(uint64_t in) +{ + return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32); +} + +uint64_t +le64toh(uint64_t in) +{ + return (in); +} + #endif /* (_BIG_ENDIAN) || _LP64) && !__lint */ diff --git a/usr/src/lib/libc/i386/gen/endian.c b/usr/src/lib/libc/i386/gen/endian.c new file mode 100644 index 0000000000..580c965406 --- /dev/null +++ b/usr/src/lib/libc/i386/gen/endian.c @@ -0,0 +1,57 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2015, Joyent, Inc. + */ + +#include <sys/isa_defs.h> +#include <endian.h> + +/* + * General endian(3C) functions that are basically no-ops. + */ + +uint16_t +letoh16(uint16_t in) +{ + return (in); +} + +uint16_t +le16toh(uint16_t in) +{ + return (in); +} + +uint32_t +letoh32(uint32_t in) +{ + return (in); +} + +uint32_t +le32toh(uint32_t in) +{ + return (in); +} + +uint16_t +htole16(uint16_t in) +{ + return (in); +} + +uint32_t +htole32(uint32_t in) +{ + return (in); +} |
