1 /*
   2  * CDDL HEADER START
   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 #include <sys/asm_linkage.h>
  28 #include <sys/asm_misc.h>
  29 
  30 #if defined(__amd64)
  31 
  32         /*
  33          * do a cpuid instruction, returning the eax/edx values
  34          *
  35          * uint32_t get_cpuid_edx(uint32_t *eax)
  36          */
  37         ENTRY_NP(get_cpuid_edx)
  38         pushq   %rbx
  39         movl    (%rdi), %eax
  40         cpuid
  41         movl    %eax, (%rdi)
  42         movl    %edx, %eax
  43         popq    %rbx
  44         ret
  45         SET_SIZE(get_cpuid_edx)
  46 
  47         /*
  48          * void outb(int port, uint8_t value)
  49          */
  50         ENTRY(outb)
  51         movw    %di, %dx
  52         movb    %sil, %al
  53         outb    (%dx)
  54         ret
  55         SET_SIZE(outb)
  56 
  57         /*
  58          * uint8_t inb(int port)
  59          */
  60         ENTRY(inb)
  61         xorl    %eax, %eax
  62         movw    %di, %dx
  63         inb     (%dx)
  64         ret
  65         SET_SIZE(inb)
  66 
  67         ENTRY(htonl)
  68         movl    %edi, %eax
  69         bswap   %eax
  70         ret
  71         SET_SIZE(htonl)
  72 
  73 #elif defined(__i386)
  74 
  75         .code32
  76 
  77         /*
  78          * do a cpuid instruction, returning the eax/edx values
  79          *
  80          * uint32_t get_cpuid_edx(uint32_t *eax)
  81          */
  82         ENTRY_NP(get_cpuid_edx)
  83         movl    4(%esp), %ecx
  84         movl    (%ecx), %eax
  85         pushl   %ebx
  86         cpuid
  87         popl    %ebx
  88         movl    4(%esp), %ecx
  89         movl    %eax, (%ecx)
  90         movl    %edx, %eax
  91         ret
  92         SET_SIZE(get_cpuid_edx)
  93 
  94         /*
  95          * void outb(int port, uint8_t value)
  96          */
  97         ENTRY_NP(outb)
  98         movl    4(%esp), %edx
  99         movl    8(%esp), %eax
 100         outb    (%dx)
 101         ret
 102         SET_SIZE(outb)
 103 
 104         /*
 105          * uint8_t inb(int port)
 106          */
 107         ENTRY_NP(inb)
 108         movl    4(%esp), %edx
 109         inb     (%dx)
 110         andl    $0xff, %eax
 111         ret
 112         SET_SIZE(inb)
 113 
 114         ENTRY(htonl)
 115         movl    4(%esp), %eax
 116         bswap   %eax
 117         ret
 118         SET_SIZE(htonl)
 119 
 120 #endif  /* __i386 */
 121