xref: /illumos-gate/usr/src/uts/intel/asm/cpu.h (revision 42cd19316c818c8b8283fc48263a1b4ce99cf049)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56e541dddSmrj  * Common Development and Distribution License (the "License").
66e541dddSmrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2226a04d67SDave Plauger  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
25*a9cc46cfSRobert Mustacchi /*
26*a9cc46cfSRobert Mustacchi  * Copyright 2019 Joyent, Inc.
27*a9cc46cfSRobert Mustacchi  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef _ASM_CPU_H
307c478bd9Sstevel@tonic-gate #define	_ASM_CPU_H
317c478bd9Sstevel@tonic-gate 
326b7143d7SRichard Lowe #include <sys/ccompile.h>
336b7143d7SRichard Lowe 
347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #if !defined(__lint) && defined(__GNUC__)
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
417c478bd9Sstevel@tonic-gate 
426b7143d7SRichard Lowe extern __GNU_INLINE void
ht_pause(void)43aca118b7Slucy wang - Sun Microsystems - Beijing China ht_pause(void)
447c478bd9Sstevel@tonic-gate {
457c478bd9Sstevel@tonic-gate 	__asm__ __volatile__(
467c478bd9Sstevel@tonic-gate 	    "pause");
477c478bd9Sstevel@tonic-gate }
487c478bd9Sstevel@tonic-gate 
4994e7edb1Slucy wang - Sun Microsystems - Beijing China /*
5094e7edb1Slucy wang - Sun Microsystems - Beijing China  * prefetch 64 bytes
5194e7edb1Slucy wang - Sun Microsystems - Beijing China  *
5294e7edb1Slucy wang - Sun Microsystems - Beijing China  * prefetch is an SSE extension which is not supported on
5394e7edb1Slucy wang - Sun Microsystems - Beijing China  * older 32-bit processors, so define this as a no-op for now
5494e7edb1Slucy wang - Sun Microsystems - Beijing China  */
5594e7edb1Slucy wang - Sun Microsystems - Beijing China 
566b7143d7SRichard Lowe extern __GNU_INLINE void
prefetch_read_many(void * addr)57aca118b7Slucy wang - Sun Microsystems - Beijing China prefetch_read_many(void *addr)
5894e7edb1Slucy wang - Sun Microsystems - Beijing China {
5994e7edb1Slucy wang - Sun Microsystems - Beijing China #if defined(__amd64)
6094e7edb1Slucy wang - Sun Microsystems - Beijing China 	__asm__(
6194e7edb1Slucy wang - Sun Microsystems - Beijing China 	    "prefetcht0 (%0);"
6294e7edb1Slucy wang - Sun Microsystems - Beijing China 	    "prefetcht0 32(%0);"
6394e7edb1Slucy wang - Sun Microsystems - Beijing China 	    : /* no output */
6494e7edb1Slucy wang - Sun Microsystems - Beijing China 	    : "r" (addr));
6594e7edb1Slucy wang - Sun Microsystems - Beijing China #endif	/* __amd64 */
6694e7edb1Slucy wang - Sun Microsystems - Beijing China }
6794e7edb1Slucy wang - Sun Microsystems - Beijing China 
686b7143d7SRichard Lowe extern __GNU_INLINE void
prefetch_read_once(void * addr)69c540c555SRichard Lowe prefetch_read_once(void *addr)
7094e7edb1Slucy wang - Sun Microsystems - Beijing China {
7194e7edb1Slucy wang - Sun Microsystems - Beijing China #if defined(__amd64)
7294e7edb1Slucy wang - Sun Microsystems - Beijing China 	__asm__(
7394e7edb1Slucy wang - Sun Microsystems - Beijing China 	    "prefetchnta (%0);"
7494e7edb1Slucy wang - Sun Microsystems - Beijing China 	    "prefetchnta 32(%0);"
7594e7edb1Slucy wang - Sun Microsystems - Beijing China 	    : /* no output */
7694e7edb1Slucy wang - Sun Microsystems - Beijing China 	    : "r" (addr));
7794e7edb1Slucy wang - Sun Microsystems - Beijing China #endif	/* __amd64 */
7894e7edb1Slucy wang - Sun Microsystems - Beijing China }
7994e7edb1Slucy wang - Sun Microsystems - Beijing China 
806b7143d7SRichard Lowe extern __GNU_INLINE void
prefetch_write_many(void * addr)81aca118b7Slucy wang - Sun Microsystems - Beijing China prefetch_write_many(void *addr)
8294e7edb1Slucy wang - Sun Microsystems - Beijing China {
8394e7edb1Slucy wang - Sun Microsystems - Beijing China #if defined(__amd64)
8494e7edb1Slucy wang - Sun Microsystems - Beijing China 	__asm__(
8594e7edb1Slucy wang - Sun Microsystems - Beijing China 	    "prefetcht0 (%0);"
8694e7edb1Slucy wang - Sun Microsystems - Beijing China 	    "prefetcht0 32(%0);"
8794e7edb1Slucy wang - Sun Microsystems - Beijing China 	    : /* no output */
8894e7edb1Slucy wang - Sun Microsystems - Beijing China 	    : "r" (addr));
8994e7edb1Slucy wang - Sun Microsystems - Beijing China #endif	/* __amd64 */
9094e7edb1Slucy wang - Sun Microsystems - Beijing China }
9194e7edb1Slucy wang - Sun Microsystems - Beijing China 
926b7143d7SRichard Lowe extern __GNU_INLINE void
prefetch_write_once(void * addr)93aca118b7Slucy wang - Sun Microsystems - Beijing China prefetch_write_once(void *addr)
9494e7edb1Slucy wang - Sun Microsystems - Beijing China {
9594e7edb1Slucy wang - Sun Microsystems - Beijing China #if defined(__amd64)
9694e7edb1Slucy wang - Sun Microsystems - Beijing China 	__asm__(
9794e7edb1Slucy wang - Sun Microsystems - Beijing China 	    "prefetcht0 (%0);"
9894e7edb1Slucy wang - Sun Microsystems - Beijing China 	    "prefetcht0 32(%0);"
9994e7edb1Slucy wang - Sun Microsystems - Beijing China 	    : /* no output */
10094e7edb1Slucy wang - Sun Microsystems - Beijing China 	    : "r" (addr));
10194e7edb1Slucy wang - Sun Microsystems - Beijing China #endif	/* __amd64 */
10294e7edb1Slucy wang - Sun Microsystems - Beijing China }
10394e7edb1Slucy wang - Sun Microsystems - Beijing China 
104843e1988Sjohnlev #if !defined(__xpv)
105843e1988Sjohnlev 
1066b7143d7SRichard Lowe extern __GNU_INLINE void
cli(void)107aca118b7Slucy wang - Sun Microsystems - Beijing China cli(void)
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate 	__asm__ __volatile__(
1107c478bd9Sstevel@tonic-gate 	    "cli" : : : "memory");
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
1136b7143d7SRichard Lowe extern __GNU_INLINE void
sti(void)114aca118b7Slucy wang - Sun Microsystems - Beijing China sti(void)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	__asm__ __volatile__(
1177c478bd9Sstevel@tonic-gate 	    "sti");
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate 
120*a9cc46cfSRobert Mustacchi /*
121*a9cc46cfSRobert Mustacchi  * Any newer callers of halt need to make sure that they consider calling
122*a9cc46cfSRobert Mustacchi  * x86_md_clear() before calling this to deal with any potential issues with
123*a9cc46cfSRobert Mustacchi  * MDS. Because this version of hlt is also used in panic context, we do not
124*a9cc46cfSRobert Mustacchi  * unconditionally call x86_md_clear() here and require callers to do so.
125*a9cc46cfSRobert Mustacchi  */
1266b7143d7SRichard Lowe extern __GNU_INLINE void
i86_halt(void)127aca118b7Slucy wang - Sun Microsystems - Beijing China i86_halt(void)
1287c478bd9Sstevel@tonic-gate {
1297c478bd9Sstevel@tonic-gate 	__asm__ __volatile__(
1307c478bd9Sstevel@tonic-gate 	    "sti; hlt");
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate 
133843e1988Sjohnlev #endif /* !__xpv */
134843e1988Sjohnlev 
1357c478bd9Sstevel@tonic-gate #endif	/* __i386 || defined(__amd64) */
1367c478bd9Sstevel@tonic-gate 
1376e541dddSmrj #if defined(__amd64)
1386e541dddSmrj 
1396b7143d7SRichard Lowe extern __GNU_INLINE void
__set_ds(selector_t value)140aca118b7Slucy wang - Sun Microsystems - Beijing China __set_ds(selector_t value)
1416e541dddSmrj {
1426e541dddSmrj 	__asm__ __volatile__(
1436e541dddSmrj 	    "movw	%0, %%ds"
1446e541dddSmrj 	    : /* no output */
1456e541dddSmrj 	    : "r" (value));
1466e541dddSmrj }
1476e541dddSmrj 
1486b7143d7SRichard Lowe extern __GNU_INLINE void
__set_es(selector_t value)149aca118b7Slucy wang - Sun Microsystems - Beijing China __set_es(selector_t value)
1506e541dddSmrj {
1516e541dddSmrj 	__asm__ __volatile__(
1526e541dddSmrj 	    "movw	%0, %%es"
1536e541dddSmrj 	    : /* no output */
1546e541dddSmrj 	    : "r" (value));
1556e541dddSmrj }
1566e541dddSmrj 
1576b7143d7SRichard Lowe extern __GNU_INLINE void
__set_fs(selector_t value)158aca118b7Slucy wang - Sun Microsystems - Beijing China __set_fs(selector_t value)
1596e541dddSmrj {
1606e541dddSmrj 	__asm__ __volatile__(
1616e541dddSmrj 	    "movw	%0, %%fs"
1626e541dddSmrj 	    : /* no output */
1636e541dddSmrj 	    : "r" (value));
1646e541dddSmrj }
1656e541dddSmrj 
1666b7143d7SRichard Lowe extern __GNU_INLINE void
__set_gs(selector_t value)167aca118b7Slucy wang - Sun Microsystems - Beijing China __set_gs(selector_t value)
1686e541dddSmrj {
1696e541dddSmrj 	__asm__ __volatile__(
1706e541dddSmrj 	    "movw	%0, %%gs"
1716e541dddSmrj 	    : /* no output */
1726e541dddSmrj 	    : "r" (value));
1736e541dddSmrj }
1746e541dddSmrj 
1756e541dddSmrj #endif	/* __amd64 */
1766e541dddSmrj 
1777c478bd9Sstevel@tonic-gate #endif	/* !__lint && __GNUC__ */
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate #endif
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate #endif	/* _ASM_CPU_H */
184