10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 54292Sab196087 * Common Development and Distribution License (the "License"). 64292Sab196087 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate/* 22*7421SDaniel.Anderson@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 267298SMark.J.Nelson@Sun.COM .file "byteorder.s" 270Sstevel@tonic-gate 28*7421SDaniel.Anderson@Sun.COM#include <sys/asm_linkage.h> 290Sstevel@tonic-gate 304292Sab196087 /* 31*7421SDaniel.Anderson@Sun.COM * NOTE: htonll/ntohll, htonl/ntohl, and htons/ntohs are identical 32*7421SDaniel.Anderson@Sun.COM * routines. As such, they could be implemented as a single routine, 33*7421SDaniel.Anderson@Sun.COM * using multiple ALTENTRY/SET_SIZE definitions. We don't do this so 344292Sab196087 * that they will have unique addresses, allowing DTrace and 35*7421SDaniel.Anderson@Sun.COM * other debuggers to tell them apart. 364292Sab196087 */ 374292Sab196087 38*7421SDaniel.Anderson@Sun.COM/* 39*7421SDaniel.Anderson@Sun.COM * unsigned long long htonll( hll ) 40*7421SDaniel.Anderson@Sun.COM * unsigned long long ntohll( hll ) 41*7421SDaniel.Anderson@Sun.COM * unsigned long long hll; 42*7421SDaniel.Anderson@Sun.COM * reverses the byte order of 'uint64_t hll' on little endian machines 43*7421SDaniel.Anderson@Sun.COM */ 44*7421SDaniel.Anderson@Sun.COM ENTRY(htonll) 45*7421SDaniel.Anderson@Sun.COM movq %rdi, %rax /* %rax = hll */ 46*7421SDaniel.Anderson@Sun.COM bswapq %rax /* reverses the byte order of %rax */ 47*7421SDaniel.Anderson@Sun.COM ret /* return (%rax) */ 48*7421SDaniel.Anderson@Sun.COM SET_SIZE(htonll) 49*7421SDaniel.Anderson@Sun.COM 50*7421SDaniel.Anderson@Sun.COM ENTRY(ntohll) 51*7421SDaniel.Anderson@Sun.COM movq %rdi, %rax /* %rax = hll */ 52*7421SDaniel.Anderson@Sun.COM bswapq %rax /* reverses the byte order of %rax */ 53*7421SDaniel.Anderson@Sun.COM ret /* return (%rax) */ 54*7421SDaniel.Anderson@Sun.COM SET_SIZE(ntohll) 55*7421SDaniel.Anderson@Sun.COM 564292Sab196087 570Sstevel@tonic-gate/* 580Sstevel@tonic-gate * unsigned long htonl( hl ) 590Sstevel@tonic-gate * unsigned long ntohl( hl ) 60*7421SDaniel.Anderson@Sun.COM * unsigned long hl; 61*7421SDaniel.Anderson@Sun.COM * reverses the byte order of 'uint32_t hl' on little endian machines 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate ENTRY(htonl) 640Sstevel@tonic-gate movl %edi, %eax /* %eax = hl */ 650Sstevel@tonic-gate bswap %eax /* reverses the byte order of %eax */ 660Sstevel@tonic-gate ret /* return (%eax) */ 670Sstevel@tonic-gate SET_SIZE(htonl) 684292Sab196087 694292Sab196087 ENTRY(ntohl) 704292Sab196087 movl %edi, %eax /* %eax = hl */ 714292Sab196087 bswap %eax /* reverses the byte order of %eax */ 724292Sab196087 ret /* return (%eax) */ 730Sstevel@tonic-gate SET_SIZE(ntohl) 740Sstevel@tonic-gate 750Sstevel@tonic-gate/* 760Sstevel@tonic-gate * unsigned short htons( hs ) 77*7421SDaniel.Anderson@Sun.COM * unsigned short hs; 78*7421SDaniel.Anderson@Sun.COM * reverses the byte order of 'uint16_t hs' on little endian machines. 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate ENTRY(htons) 810Sstevel@tonic-gate movl %edi, %eax /* %eax = hs */ 820Sstevel@tonic-gate bswap %eax /* reverses the byte order of %eax */ 830Sstevel@tonic-gate shrl $16, %eax /* moves high 16-bit to low 16-bit */ 840Sstevel@tonic-gate ret /* return (%eax) */ 850Sstevel@tonic-gate SET_SIZE(htons) 864292Sab196087 874292Sab196087 ENTRY(ntohs) 884292Sab196087 movl %edi, %eax /* %eax = hs */ 894292Sab196087 bswap %eax /* reverses the byte order of %eax */ 904292Sab196087 shrl $16, %eax /* moves high 16-bit to low 16-bit */ 914292Sab196087 ret /* return (%eax) */ 920Sstevel@tonic-gate SET_SIZE(ntohs) 93