xref: /onnv-gate/usr/src/uts/intel/ia32/ml/ia32.il (revision 9449:53d84bc6a35a)
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
53446Smrj * Common Development and Distribution License (the "License").
63446Smrj * 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 */
213446Smrj
220Sstevel@tonic-gate/*
238475SDave.Plauger@Sun.COM * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate/
283446Smrj/ Inline functions for i386 kernels.
293446Smrj/	Shared between all x86 platform variants.
300Sstevel@tonic-gate/
310Sstevel@tonic-gate
320Sstevel@tonic-gate/
330Sstevel@tonic-gate/ return current thread pointer
340Sstevel@tonic-gate/
350Sstevel@tonic-gate/ NOTE: the "0x10" should be replaced by the computed value of the
360Sstevel@tonic-gate/	offset of "cpu_thread" from the beginning of the struct cpu.
370Sstevel@tonic-gate/	Including "assym.h" does not work, however, since that stuff
380Sstevel@tonic-gate/	is PSM-specific and is only visible to the 'unix' build anyway.
390Sstevel@tonic-gate/	Same with current cpu pointer, where "0xc" should be replaced
400Sstevel@tonic-gate/	by the computed value of the offset of "cpu_self".
410Sstevel@tonic-gate/	Ugh -- what a disaster.
420Sstevel@tonic-gate/
430Sstevel@tonic-gate	.inline	threadp,0
440Sstevel@tonic-gate	movl	%gs:0x10, %eax
450Sstevel@tonic-gate	.end
460Sstevel@tonic-gate
470Sstevel@tonic-gate/
480Sstevel@tonic-gate/ return current cpu pointer
490Sstevel@tonic-gate/
500Sstevel@tonic-gate	.inline	curcpup,0
510Sstevel@tonic-gate	movl	%gs:0xc, %eax
520Sstevel@tonic-gate	.end
530Sstevel@tonic-gate
540Sstevel@tonic-gate/
550Sstevel@tonic-gate/ return caller
560Sstevel@tonic-gate/
570Sstevel@tonic-gate	.inline caller,0
580Sstevel@tonic-gate	movl	4(%ebp), %eax
590Sstevel@tonic-gate	.end
600Sstevel@tonic-gate
610Sstevel@tonic-gate/
620Sstevel@tonic-gate/ convert ipl to spl.  This is the identity function for i86
630Sstevel@tonic-gate/
640Sstevel@tonic-gate	.inline	ipltospl,0
650Sstevel@tonic-gate	movl	(%esp), %eax
660Sstevel@tonic-gate	.end
670Sstevel@tonic-gate
680Sstevel@tonic-gate/
690Sstevel@tonic-gate/ find the low order bit in a word
700Sstevel@tonic-gate/
710Sstevel@tonic-gate	.inline lowbit,4
720Sstevel@tonic-gate	movl	$-1, %eax
730Sstevel@tonic-gate	bsfl	(%esp), %eax
740Sstevel@tonic-gate	incl	%eax
750Sstevel@tonic-gate	.end
763446Smrj
770Sstevel@tonic-gate/
780Sstevel@tonic-gate/ find the high order bit in a word
790Sstevel@tonic-gate/
800Sstevel@tonic-gate	.inline highbit,4
810Sstevel@tonic-gate	movl	$-1, %eax
820Sstevel@tonic-gate	bsrl	(%esp), %eax
830Sstevel@tonic-gate	incl	%eax
840Sstevel@tonic-gate	.end
850Sstevel@tonic-gate
860Sstevel@tonic-gate/
870Sstevel@tonic-gate/ Networking byte order functions (too bad, Intel has the wrong byte order)
880Sstevel@tonic-gate/
897421SDaniel.Anderson@Sun.COM	.inline	htonll,4
907421SDaniel.Anderson@Sun.COM	movl	(%esp), %edx
917421SDaniel.Anderson@Sun.COM	movl	4(%esp), %eax
927421SDaniel.Anderson@Sun.COM	bswap	%edx
937421SDaniel.Anderson@Sun.COM	bswap	%eax
947421SDaniel.Anderson@Sun.COM	.end
957421SDaniel.Anderson@Sun.COM
967421SDaniel.Anderson@Sun.COM	.inline	ntohll,4
977421SDaniel.Anderson@Sun.COM	movl	(%esp), %edx
987421SDaniel.Anderson@Sun.COM	movl	4(%esp), %eax
997421SDaniel.Anderson@Sun.COM	bswap	%edx
1007421SDaniel.Anderson@Sun.COM	bswap	%eax
1017421SDaniel.Anderson@Sun.COM	.end
1027421SDaniel.Anderson@Sun.COM
1030Sstevel@tonic-gate	.inline	htonl,4
1040Sstevel@tonic-gate	movl	(%esp), %eax
1050Sstevel@tonic-gate	bswap	%eax
1060Sstevel@tonic-gate	.end
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate	.inline	ntohl,4
1090Sstevel@tonic-gate	movl	(%esp), %eax
1100Sstevel@tonic-gate	bswap	%eax
1110Sstevel@tonic-gate	.end
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate	.inline	htons,4
1140Sstevel@tonic-gate	movl	(%esp), %eax
1150Sstevel@tonic-gate	bswap	%eax
1160Sstevel@tonic-gate	shrl	$16, %eax
1170Sstevel@tonic-gate	.end
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate	.inline	ntohs,4
1200Sstevel@tonic-gate	movl	(%esp), %eax
1210Sstevel@tonic-gate	bswap	%eax
1220Sstevel@tonic-gate	shrl	$16, %eax
1230Sstevel@tonic-gate	.end
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate/*
1263446Smrj * multiply two long numbers and yield a u_longlong_t result
1270Sstevel@tonic-gate * Provided to manipulate hrtime_t values.
1280Sstevel@tonic-gate */
1290Sstevel@tonic-gate	.inline mul32, 8
1300Sstevel@tonic-gate	movl	4(%esp), %eax
1310Sstevel@tonic-gate	movl	(%esp), %ecx
1320Sstevel@tonic-gate	mull	%ecx
1330Sstevel@tonic-gate	.end
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate/*
1360Sstevel@tonic-gate * Unlock hres_lock and increment the count value. (See clock.h)
1370Sstevel@tonic-gate */
1380Sstevel@tonic-gate	.inline unlock_hres_lock, 0
1390Sstevel@tonic-gate	lock
1400Sstevel@tonic-gate	incl	hres_lock
1410Sstevel@tonic-gate	.end
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate	.inline	atomic_orb,8
1440Sstevel@tonic-gate	movl	(%esp), %eax
1450Sstevel@tonic-gate	movl    4(%esp), %edx
1460Sstevel@tonic-gate	lock
1470Sstevel@tonic-gate	orb	%dl,(%eax)
1480Sstevel@tonic-gate	.end
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate	.inline	atomic_andb,8
1510Sstevel@tonic-gate	movl	(%esp), %eax
1520Sstevel@tonic-gate	movl    4(%esp), %edx
1530Sstevel@tonic-gate	lock
1540Sstevel@tonic-gate	andb	%dl,(%eax)
1550Sstevel@tonic-gate	.end
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate/*
1580Sstevel@tonic-gate * atomic inc/dec operations.
1590Sstevel@tonic-gate *	void atomic_inc16(uint16_t *addr) { ++*addr; }
1600Sstevel@tonic-gate *	void atomic_dec16(uint16_t *addr) { --*addr; }
1610Sstevel@tonic-gate */
1620Sstevel@tonic-gate	.inline	atomic_inc16,4
1630Sstevel@tonic-gate	movl	(%esp), %eax
1640Sstevel@tonic-gate	lock
1650Sstevel@tonic-gate	incw	(%eax)
1660Sstevel@tonic-gate	.end
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate	.inline	atomic_dec16,4
1690Sstevel@tonic-gate	movl	(%esp), %eax
1700Sstevel@tonic-gate	lock
1710Sstevel@tonic-gate	decw	(%eax)
1720Sstevel@tonic-gate	.end
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate/*
1750Sstevel@tonic-gate * Call the pause instruction.  To the Pentium 4 Xeon processor, it acts as
1760Sstevel@tonic-gate * a hint that the code sequence is a busy spin-wait loop.  Without a pause
1770Sstevel@tonic-gate * instruction in these loops, the P4 Xeon processor may suffer a severe
1780Sstevel@tonic-gate * penalty when exiting the loop because the processor detects a possible
1790Sstevel@tonic-gate * memory violation.  Inserting the pause instruction significantly reduces
1800Sstevel@tonic-gate * the likelihood of a memory order violation, improving performance.
1810Sstevel@tonic-gate * The pause instruction is a NOP on all other IA-32 processors.
1820Sstevel@tonic-gate */
1830Sstevel@tonic-gate	.inline ht_pause, 0
1840Sstevel@tonic-gate	rep			/ our compiler doesn't support "pause" yet,
1850Sstevel@tonic-gate	nop			/ so we're using "F3 90" opcode directly
1860Sstevel@tonic-gate	.end
1878286SDave.Plauger@Sun.COM
1889171Sxiuyan.wang@Sun.COM/*
1899171Sxiuyan.wang@Sun.COM * prefetch 64 bytes
1909171Sxiuyan.wang@Sun.COM *
1919171Sxiuyan.wang@Sun.COM * prefetch is an SSE extension which is not supported on older 32-bit processors
1929171Sxiuyan.wang@Sun.COM * so define this as a no-op for now
1939171Sxiuyan.wang@Sun.COM */
1949171Sxiuyan.wang@Sun.COM
195*9449Sxiuyan.wang@Sun.COM 	.inline	prefetch_read_many,4
1969171Sxiuyan.wang@Sun.COM/	movl		(%esp), %eax
1979171Sxiuyan.wang@Sun.COM/	prefetcht0	(%eax)
1989171Sxiuyan.wang@Sun.COM/	prefetcht0	32(%eax)
1998286SDave.Plauger@Sun.COM	.end
2009171Sxiuyan.wang@Sun.COM
201*9449Sxiuyan.wang@Sun.COM 	.inline	prefetch_read_once,4
2029171Sxiuyan.wang@Sun.COM/	movl		(%esp), %eax
2039171Sxiuyan.wang@Sun.COM/	prefetchnta	(%eax)
2049171Sxiuyan.wang@Sun.COM/	prefetchnta	32(%eax)
2059171Sxiuyan.wang@Sun.COM	.end
2069171Sxiuyan.wang@Sun.COM
207*9449Sxiuyan.wang@Sun.COM 	.inline	prefetch_write_many,4
2089171Sxiuyan.wang@Sun.COM/	movl		(%esp), %eax
2099171Sxiuyan.wang@Sun.COM/	prefetcht0	(%eax)
2109171Sxiuyan.wang@Sun.COM/	prefetcht0	32(%eax)
2119171Sxiuyan.wang@Sun.COM	.end
2129171Sxiuyan.wang@Sun.COM
213*9449Sxiuyan.wang@Sun.COM 	.inline	prefetch_write_once,4
2149171Sxiuyan.wang@Sun.COM/	movl		(%esp), %eax
2159171Sxiuyan.wang@Sun.COM/	prefetcht0	(%eax)
2169171Sxiuyan.wang@Sun.COM/	prefetcht0	32(%eax)
2179171Sxiuyan.wang@Sun.COM	.end
2189171Sxiuyan.wang@Sun.COM
219