Print this page
5007142 Add ntohll and htonll to sys/byteorder.h
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
PSARC 2008/474


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 /
  30 / Inline functions for i386 kernels.
  31 /       Shared between all x86 platform variants.
  32 /
  33 
  34 /
  35 / return current thread pointer
  36 /
  37 / NOTE: the "0x10" should be replaced by the computed value of the
  38 /       offset of "cpu_thread" from the beginning of the struct cpu.
  39 /       Including "assym.h" does not work, however, since that stuff
  40 /       is PSM-specific and is only visible to the 'unix' build anyway.
  41 /       Same with current cpu pointer, where "0xc" should be replaced
  42 /       by the computed value of the offset of "cpu_self".
  43 /       Ugh -- what a disaster.
  44 /
  45         .inline threadp,0
  46         movl    %gs:0x10, %eax
  47         .end
  48 


  71 / find the low order bit in a word
  72 /
  73         .inline lowbit,4
  74         movl    $-1, %eax
  75         bsfl    (%esp), %eax
  76         incl    %eax
  77         .end
  78 
  79 /
  80 / find the high order bit in a word
  81 /
  82         .inline highbit,4
  83         movl    $-1, %eax
  84         bsrl    (%esp), %eax
  85         incl    %eax
  86         .end
  87 
  88 /
  89 / Networking byte order functions (too bad, Intel has the wrong byte order)
  90 /














  91         .inline htonl,4
  92         movl    (%esp), %eax
  93         bswap   %eax
  94         .end
  95 
  96         .inline ntohl,4
  97         movl    (%esp), %eax
  98         bswap   %eax
  99         .end
 100 
 101         .inline htons,4
 102         movl    (%esp), %eax
 103         bswap   %eax
 104         shrl    $16, %eax
 105         .end
 106 
 107         .inline ntohs,4
 108         movl    (%esp), %eax
 109         bswap   %eax
 110         shrl    $16, %eax




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 


  27 /
  28 / Inline functions for i386 kernels.
  29 /       Shared between all x86 platform variants.
  30 /
  31 
  32 /
  33 / return current thread pointer
  34 /
  35 / NOTE: the "0x10" should be replaced by the computed value of the
  36 /       offset of "cpu_thread" from the beginning of the struct cpu.
  37 /       Including "assym.h" does not work, however, since that stuff
  38 /       is PSM-specific and is only visible to the 'unix' build anyway.
  39 /       Same with current cpu pointer, where "0xc" should be replaced
  40 /       by the computed value of the offset of "cpu_self".
  41 /       Ugh -- what a disaster.
  42 /
  43         .inline threadp,0
  44         movl    %gs:0x10, %eax
  45         .end
  46 


  69 / find the low order bit in a word
  70 /
  71         .inline lowbit,4
  72         movl    $-1, %eax
  73         bsfl    (%esp), %eax
  74         incl    %eax
  75         .end
  76 
  77 /
  78 / find the high order bit in a word
  79 /
  80         .inline highbit,4
  81         movl    $-1, %eax
  82         bsrl    (%esp), %eax
  83         incl    %eax
  84         .end
  85 
  86 /
  87 / Networking byte order functions (too bad, Intel has the wrong byte order)
  88 /
  89         .inline htonll,4
  90         movl    (%esp), %edx
  91         movl    4(%esp), %eax
  92         bswap   %edx
  93         bswap   %eax
  94         .end
  95 
  96         .inline ntohll,4
  97         movl    (%esp), %edx
  98         movl    4(%esp), %eax
  99         bswap   %edx
 100         bswap   %eax
 101         .end
 102 
 103         .inline htonl,4
 104         movl    (%esp), %eax
 105         bswap   %eax
 106         .end
 107 
 108         .inline ntohl,4
 109         movl    (%esp), %eax
 110         bswap   %eax
 111         .end
 112 
 113         .inline htons,4
 114         movl    (%esp), %eax
 115         bswap   %eax
 116         shrl    $16, %eax
 117         .end
 118 
 119         .inline ntohs,4
 120         movl    (%esp), %eax
 121         bswap   %eax
 122         shrl    $16, %eax