xref: /onnv-gate/usr/src/uts/intel/asm/cpu.h (revision 9171:ee979187414d)
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
53451Smrj  * Common Development and Distribution License (the "License").
63451Smrj  * 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 /*
228475SDave.Plauger@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _ASM_CPU_H
270Sstevel@tonic-gate #define	_ASM_CPU_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef	__cplusplus
300Sstevel@tonic-gate extern "C" {
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #if !defined(__lint) && defined(__GNUC__)
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
360Sstevel@tonic-gate 
370Sstevel@tonic-gate extern __inline__ void ht_pause(void)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate 	__asm__ __volatile__(
400Sstevel@tonic-gate 	    "pause");
410Sstevel@tonic-gate }
420Sstevel@tonic-gate 
43*9171Sxiuyan.wang@Sun.COM /*
44*9171Sxiuyan.wang@Sun.COM  * prefetch 64 bytes
45*9171Sxiuyan.wang@Sun.COM  *
46*9171Sxiuyan.wang@Sun.COM  * prefetch is an SSE extension which is not supported on
47*9171Sxiuyan.wang@Sun.COM  * older 32-bit processors, so define this as a no-op for now
48*9171Sxiuyan.wang@Sun.COM  */
49*9171Sxiuyan.wang@Sun.COM 
50*9171Sxiuyan.wang@Sun.COM extern __inline__ void prefetch_read_many(void *addr)
51*9171Sxiuyan.wang@Sun.COM {
52*9171Sxiuyan.wang@Sun.COM #if defined(__amd64)
53*9171Sxiuyan.wang@Sun.COM 	__asm__(
54*9171Sxiuyan.wang@Sun.COM 	    "prefetcht0 (%0);"
55*9171Sxiuyan.wang@Sun.COM 	    "prefetcht0 32(%0);"
56*9171Sxiuyan.wang@Sun.COM 	    : /* no output */
57*9171Sxiuyan.wang@Sun.COM 	    : "r" (addr));
58*9171Sxiuyan.wang@Sun.COM #endif	/* __amd64 */
59*9171Sxiuyan.wang@Sun.COM }
60*9171Sxiuyan.wang@Sun.COM 
61*9171Sxiuyan.wang@Sun.COM extern __inline__ void prefetch_read_once(void *addr)
62*9171Sxiuyan.wang@Sun.COM {
63*9171Sxiuyan.wang@Sun.COM #if defined(__amd64)
64*9171Sxiuyan.wang@Sun.COM 	__asm__(
65*9171Sxiuyan.wang@Sun.COM 	    "prefetchnta (%0);"
66*9171Sxiuyan.wang@Sun.COM 	    "prefetchnta 32(%0);"
67*9171Sxiuyan.wang@Sun.COM 	    : /* no output */
68*9171Sxiuyan.wang@Sun.COM 	    : "r" (addr));
69*9171Sxiuyan.wang@Sun.COM #endif	/* __amd64 */
70*9171Sxiuyan.wang@Sun.COM }
71*9171Sxiuyan.wang@Sun.COM 
72*9171Sxiuyan.wang@Sun.COM extern __inline__ void prefetch_write_many(void *addr)
73*9171Sxiuyan.wang@Sun.COM {
74*9171Sxiuyan.wang@Sun.COM #if defined(__amd64)
75*9171Sxiuyan.wang@Sun.COM 	__asm__(
76*9171Sxiuyan.wang@Sun.COM 	    "prefetcht0 (%0);"
77*9171Sxiuyan.wang@Sun.COM 	    "prefetcht0 32(%0);"
78*9171Sxiuyan.wang@Sun.COM 	    : /* no output */
79*9171Sxiuyan.wang@Sun.COM 	    : "r" (addr));
80*9171Sxiuyan.wang@Sun.COM #endif	/* __amd64 */
81*9171Sxiuyan.wang@Sun.COM }
82*9171Sxiuyan.wang@Sun.COM 
83*9171Sxiuyan.wang@Sun.COM extern __inline__ void prefetch_write_once(void *addr)
84*9171Sxiuyan.wang@Sun.COM {
85*9171Sxiuyan.wang@Sun.COM #if defined(__amd64)
86*9171Sxiuyan.wang@Sun.COM 	__asm__(
87*9171Sxiuyan.wang@Sun.COM 	    "prefetcht0 (%0);"
88*9171Sxiuyan.wang@Sun.COM 	    "prefetcht0 32(%0);"
89*9171Sxiuyan.wang@Sun.COM 	    : /* no output */
90*9171Sxiuyan.wang@Sun.COM 	    : "r" (addr));
91*9171Sxiuyan.wang@Sun.COM #endif	/* __amd64 */
92*9171Sxiuyan.wang@Sun.COM }
93*9171Sxiuyan.wang@Sun.COM 
945084Sjohnlev #if !defined(__xpv)
955084Sjohnlev 
960Sstevel@tonic-gate extern __inline__ void cli(void)
970Sstevel@tonic-gate {
980Sstevel@tonic-gate 	__asm__ __volatile__(
990Sstevel@tonic-gate 	    "cli" : : : "memory");
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate extern __inline__ void sti(void)
1030Sstevel@tonic-gate {
1040Sstevel@tonic-gate 	__asm__ __volatile__(
1050Sstevel@tonic-gate 	    "sti");
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate extern __inline__ void i86_halt(void)
1090Sstevel@tonic-gate {
1100Sstevel@tonic-gate 	__asm__ __volatile__(
1110Sstevel@tonic-gate 	    "sti; hlt");
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate 
1145084Sjohnlev #endif /* !__xpv */
1155084Sjohnlev 
1160Sstevel@tonic-gate #endif	/* __i386 || defined(__amd64) */
1170Sstevel@tonic-gate 
1183451Smrj #if defined(__amd64)
1193451Smrj 
1203451Smrj extern __inline__ void __set_ds(selector_t value)
1213451Smrj {
1223451Smrj 	__asm__ __volatile__(
1235084Sjohnlev 	    "movw	%0, %%ds"
1245084Sjohnlev 	    : /* no output */
1255084Sjohnlev 	    : "r" (value));
1263451Smrj }
1273451Smrj 
1283451Smrj extern __inline__ void __set_es(selector_t value)
1293451Smrj {
1303451Smrj 	__asm__ __volatile__(
1315084Sjohnlev 	    "movw	%0, %%es"
1325084Sjohnlev 	    : /* no output */
1335084Sjohnlev 	    : "r" (value));
1343451Smrj }
1353451Smrj 
1363451Smrj extern __inline__ void __set_fs(selector_t value)
1373451Smrj {
1383451Smrj 	__asm__ __volatile__(
1395084Sjohnlev 	    "movw	%0, %%fs"
1405084Sjohnlev 	    : /* no output */
1415084Sjohnlev 	    : "r" (value));
1423451Smrj }
1433451Smrj 
1443451Smrj extern __inline__ void __set_gs(selector_t value)
1453451Smrj {
1463451Smrj 	__asm__ __volatile__(
1475084Sjohnlev 	    "movw	%0, %%gs"
1485084Sjohnlev 	    : /* no output */
1495084Sjohnlev 	    : "r" (value));
1503451Smrj }
1513451Smrj 
1525084Sjohnlev #if !defined(__xpv)
1535084Sjohnlev 
1543451Smrj extern __inline__ void __swapgs(void)
1553451Smrj {
1563451Smrj 	__asm__ __volatile__(
1575084Sjohnlev 	    "mfence; swapgs");
1583451Smrj }
1593451Smrj 
1605084Sjohnlev #endif /* !__xpv */
1615084Sjohnlev 
1623451Smrj #endif	/* __amd64 */
1633451Smrj 
1640Sstevel@tonic-gate #endif	/* !__lint && __GNUC__ */
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate #ifdef	__cplusplus
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate #endif
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate #endif	/* _ASM_CPU_H */
171