xref: /illumos-gate/usr/src/uts/i86pc/dboot/dboot_asm.S (revision 5d9d9091f564c198a760790b0bfa72c44e17912b)
1*5d9d9091SRichard Lowe/*
2*5d9d9091SRichard Lowe * CDDL HEADER START
3*5d9d9091SRichard Lowe *
4*5d9d9091SRichard Lowe * The contents of this file are subject to the terms of the
5*5d9d9091SRichard Lowe * Common Development and Distribution License (the "License").
6*5d9d9091SRichard Lowe * You may not use this file except in compliance with the License.
7*5d9d9091SRichard Lowe *
8*5d9d9091SRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5d9d9091SRichard Lowe * or http://www.opensolaris.org/os/licensing.
10*5d9d9091SRichard Lowe * See the License for the specific language governing permissions
11*5d9d9091SRichard Lowe * and limitations under the License.
12*5d9d9091SRichard Lowe *
13*5d9d9091SRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each
14*5d9d9091SRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5d9d9091SRichard Lowe * If applicable, add the following below this CDDL HEADER, with the
16*5d9d9091SRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
17*5d9d9091SRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
18*5d9d9091SRichard Lowe *
19*5d9d9091SRichard Lowe * CDDL HEADER END
20*5d9d9091SRichard Lowe */
21*5d9d9091SRichard Lowe
22*5d9d9091SRichard Lowe/*
23*5d9d9091SRichard Lowe * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24*5d9d9091SRichard Lowe * Use is subject to license terms.
25*5d9d9091SRichard Lowe */
26*5d9d9091SRichard Lowe
27*5d9d9091SRichard Lowe#include <sys/asm_linkage.h>
28*5d9d9091SRichard Lowe#include <sys/asm_misc.h>
29*5d9d9091SRichard Lowe
30*5d9d9091SRichard Lowe#if defined(__amd64)
31*5d9d9091SRichard Lowe
32*5d9d9091SRichard Lowe	/*
33*5d9d9091SRichard Lowe	 * do a cpuid instruction, returning the eax/edx values
34*5d9d9091SRichard Lowe	 *
35*5d9d9091SRichard Lowe	 * uint32_t get_cpuid_edx(uint32_t *eax)
36*5d9d9091SRichard Lowe	 */
37*5d9d9091SRichard Lowe	ENTRY_NP(get_cpuid_edx)
38*5d9d9091SRichard Lowe	pushq	%rbx
39*5d9d9091SRichard Lowe	movl	(%rdi), %eax
40*5d9d9091SRichard Lowe	cpuid
41*5d9d9091SRichard Lowe	movl	%eax, (%rdi)
42*5d9d9091SRichard Lowe	movl	%edx, %eax
43*5d9d9091SRichard Lowe	popq	%rbx
44*5d9d9091SRichard Lowe	ret
45*5d9d9091SRichard Lowe	SET_SIZE(get_cpuid_edx)
46*5d9d9091SRichard Lowe
47*5d9d9091SRichard Lowe	/*
48*5d9d9091SRichard Lowe	 * void outb(int port, uint8_t value)
49*5d9d9091SRichard Lowe	 */
50*5d9d9091SRichard Lowe	ENTRY(outb)
51*5d9d9091SRichard Lowe	movw	%di, %dx
52*5d9d9091SRichard Lowe	movb	%sil, %al
53*5d9d9091SRichard Lowe	outb	(%dx)
54*5d9d9091SRichard Lowe	ret
55*5d9d9091SRichard Lowe	SET_SIZE(outb)
56*5d9d9091SRichard Lowe
57*5d9d9091SRichard Lowe	/*
58*5d9d9091SRichard Lowe	 * uint8_t inb(int port)
59*5d9d9091SRichard Lowe	 */
60*5d9d9091SRichard Lowe	ENTRY(inb)
61*5d9d9091SRichard Lowe	xorl	%eax, %eax
62*5d9d9091SRichard Lowe	movw	%di, %dx
63*5d9d9091SRichard Lowe	inb	(%dx)
64*5d9d9091SRichard Lowe	ret
65*5d9d9091SRichard Lowe	SET_SIZE(inb)
66*5d9d9091SRichard Lowe
67*5d9d9091SRichard Lowe	ENTRY(htonl)
68*5d9d9091SRichard Lowe	movl    %edi, %eax
69*5d9d9091SRichard Lowe	bswap   %eax
70*5d9d9091SRichard Lowe	ret
71*5d9d9091SRichard Lowe	SET_SIZE(htonl)
72*5d9d9091SRichard Lowe
73*5d9d9091SRichard Lowe#elif defined(__i386)
74*5d9d9091SRichard Lowe
75*5d9d9091SRichard Lowe	.code32
76*5d9d9091SRichard Lowe
77*5d9d9091SRichard Lowe	/*
78*5d9d9091SRichard Lowe	 * do a cpuid instruction, returning the eax/edx values
79*5d9d9091SRichard Lowe	 *
80*5d9d9091SRichard Lowe	 * uint32_t get_cpuid_edx(uint32_t *eax)
81*5d9d9091SRichard Lowe	 */
82*5d9d9091SRichard Lowe	ENTRY_NP(get_cpuid_edx)
83*5d9d9091SRichard Lowe	movl	4(%esp), %ecx
84*5d9d9091SRichard Lowe	movl	(%ecx), %eax
85*5d9d9091SRichard Lowe	pushl	%ebx
86*5d9d9091SRichard Lowe	cpuid
87*5d9d9091SRichard Lowe	popl	%ebx
88*5d9d9091SRichard Lowe	movl	4(%esp), %ecx
89*5d9d9091SRichard Lowe	movl	%eax, (%ecx)
90*5d9d9091SRichard Lowe	movl	%edx, %eax
91*5d9d9091SRichard Lowe	ret
92*5d9d9091SRichard Lowe	SET_SIZE(get_cpuid_edx)
93*5d9d9091SRichard Lowe
94*5d9d9091SRichard Lowe	/*
95*5d9d9091SRichard Lowe	 * void outb(int port, uint8_t value)
96*5d9d9091SRichard Lowe	 */
97*5d9d9091SRichard Lowe	ENTRY_NP(outb)
98*5d9d9091SRichard Lowe	movl	4(%esp), %edx
99*5d9d9091SRichard Lowe	movl	8(%esp), %eax
100*5d9d9091SRichard Lowe	outb	(%dx)
101*5d9d9091SRichard Lowe	ret
102*5d9d9091SRichard Lowe	SET_SIZE(outb)
103*5d9d9091SRichard Lowe
104*5d9d9091SRichard Lowe	/*
105*5d9d9091SRichard Lowe	 * uint8_t inb(int port)
106*5d9d9091SRichard Lowe	 */
107*5d9d9091SRichard Lowe	ENTRY_NP(inb)
108*5d9d9091SRichard Lowe	movl	4(%esp), %edx
109*5d9d9091SRichard Lowe	inb	(%dx)
110*5d9d9091SRichard Lowe	andl	$0xff, %eax
111*5d9d9091SRichard Lowe	ret
112*5d9d9091SRichard Lowe	SET_SIZE(inb)
113*5d9d9091SRichard Lowe
114*5d9d9091SRichard Lowe	ENTRY(htonl)
115*5d9d9091SRichard Lowe	movl    4(%esp), %eax
116*5d9d9091SRichard Lowe	bswap   %eax
117*5d9d9091SRichard Lowe	ret
118*5d9d9091SRichard Lowe	SET_SIZE(htonl)
119*5d9d9091SRichard Lowe
120*5d9d9091SRichard Lowe#endif	/* __i386 */
121*5d9d9091SRichard Lowe
122