xref: /titanic_52/usr/src/uts/intel/ia32/ml/ia32.il (revision fdb8cf8c1b80da286f448f5e748b65f9115d7043)
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
5ae115bc7Smrj * Common Development and Distribution License (the "License").
6ae115bc7Smrj * 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 */
21ae115bc7Smrj
227c478bd9Sstevel@tonic-gate/*
2326a04d67SDave Plauger * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate/
28ae115bc7Smrj/ Inline functions for i386 kernels.
29ae115bc7Smrj/	Shared between all x86 platform variants.
307c478bd9Sstevel@tonic-gate/
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate/
337c478bd9Sstevel@tonic-gate/ return current thread pointer
347c478bd9Sstevel@tonic-gate/
357c478bd9Sstevel@tonic-gate/ NOTE: the "0x10" should be replaced by the computed value of the
367c478bd9Sstevel@tonic-gate/	offset of "cpu_thread" from the beginning of the struct cpu.
377c478bd9Sstevel@tonic-gate/	Including "assym.h" does not work, however, since that stuff
387c478bd9Sstevel@tonic-gate/	is PSM-specific and is only visible to the 'unix' build anyway.
397c478bd9Sstevel@tonic-gate/	Same with current cpu pointer, where "0xc" should be replaced
407c478bd9Sstevel@tonic-gate/	by the computed value of the offset of "cpu_self".
417c478bd9Sstevel@tonic-gate/	Ugh -- what a disaster.
427c478bd9Sstevel@tonic-gate/
437c478bd9Sstevel@tonic-gate	.inline	threadp,0
447c478bd9Sstevel@tonic-gate	movl	%gs:0x10, %eax
457c478bd9Sstevel@tonic-gate	.end
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate/
487c478bd9Sstevel@tonic-gate/ return current cpu pointer
497c478bd9Sstevel@tonic-gate/
507c478bd9Sstevel@tonic-gate	.inline	curcpup,0
517c478bd9Sstevel@tonic-gate	movl	%gs:0xc, %eax
527c478bd9Sstevel@tonic-gate	.end
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate/
557c478bd9Sstevel@tonic-gate/ return caller
567c478bd9Sstevel@tonic-gate/
577c478bd9Sstevel@tonic-gate	.inline caller,0
587c478bd9Sstevel@tonic-gate	movl	4(%ebp), %eax
597c478bd9Sstevel@tonic-gate	.end
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate/
627c478bd9Sstevel@tonic-gate/ convert ipl to spl.  This is the identity function for i86
637c478bd9Sstevel@tonic-gate/
647c478bd9Sstevel@tonic-gate	.inline	ipltospl,0
657c478bd9Sstevel@tonic-gate	movl	(%esp), %eax
667c478bd9Sstevel@tonic-gate	.end
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate/
697c478bd9Sstevel@tonic-gate/ Networking byte order functions (too bad, Intel has the wrong byte order)
707c478bd9Sstevel@tonic-gate/
714b56a003SDaniel Anderson	.inline	htonll,4
724b56a003SDaniel Anderson	movl	(%esp), %edx
734b56a003SDaniel Anderson	movl	4(%esp), %eax
744b56a003SDaniel Anderson	bswap	%edx
754b56a003SDaniel Anderson	bswap	%eax
764b56a003SDaniel Anderson	.end
774b56a003SDaniel Anderson
784b56a003SDaniel Anderson	.inline	ntohll,4
794b56a003SDaniel Anderson	movl	(%esp), %edx
804b56a003SDaniel Anderson	movl	4(%esp), %eax
814b56a003SDaniel Anderson	bswap	%edx
824b56a003SDaniel Anderson	bswap	%eax
834b56a003SDaniel Anderson	.end
844b56a003SDaniel Anderson
857c478bd9Sstevel@tonic-gate	.inline	htonl,4
867c478bd9Sstevel@tonic-gate	movl	(%esp), %eax
877c478bd9Sstevel@tonic-gate	bswap	%eax
887c478bd9Sstevel@tonic-gate	.end
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate	.inline	ntohl,4
917c478bd9Sstevel@tonic-gate	movl	(%esp), %eax
927c478bd9Sstevel@tonic-gate	bswap	%eax
937c478bd9Sstevel@tonic-gate	.end
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate	.inline	htons,4
967c478bd9Sstevel@tonic-gate	movl	(%esp), %eax
977c478bd9Sstevel@tonic-gate	bswap	%eax
987c478bd9Sstevel@tonic-gate	shrl	$16, %eax
997c478bd9Sstevel@tonic-gate	.end
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate	.inline	ntohs,4
1027c478bd9Sstevel@tonic-gate	movl	(%esp), %eax
1037c478bd9Sstevel@tonic-gate	bswap	%eax
1047c478bd9Sstevel@tonic-gate	shrl	$16, %eax
1057c478bd9Sstevel@tonic-gate	.end
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate/*
108ae115bc7Smrj * multiply two long numbers and yield a u_longlong_t result
1097c478bd9Sstevel@tonic-gate * Provided to manipulate hrtime_t values.
1107c478bd9Sstevel@tonic-gate */
1117c478bd9Sstevel@tonic-gate	.inline mul32, 8
1127c478bd9Sstevel@tonic-gate	movl	4(%esp), %eax
1137c478bd9Sstevel@tonic-gate	movl	(%esp), %ecx
1147c478bd9Sstevel@tonic-gate	mull	%ecx
1157c478bd9Sstevel@tonic-gate	.end
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate/*
1187c478bd9Sstevel@tonic-gate * Unlock hres_lock and increment the count value. (See clock.h)
1197c478bd9Sstevel@tonic-gate */
1207c478bd9Sstevel@tonic-gate	.inline unlock_hres_lock, 0
1217c478bd9Sstevel@tonic-gate	lock
1227c478bd9Sstevel@tonic-gate	incl	hres_lock
1237c478bd9Sstevel@tonic-gate	.end
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate	.inline	atomic_orb,8
1267c478bd9Sstevel@tonic-gate	movl	(%esp), %eax
1277c478bd9Sstevel@tonic-gate	movl    4(%esp), %edx
1287c478bd9Sstevel@tonic-gate	lock
1297c478bd9Sstevel@tonic-gate	orb	%dl,(%eax)
1307c478bd9Sstevel@tonic-gate	.end
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate	.inline	atomic_andb,8
1337c478bd9Sstevel@tonic-gate	movl	(%esp), %eax
1347c478bd9Sstevel@tonic-gate	movl    4(%esp), %edx
1357c478bd9Sstevel@tonic-gate	lock
1367c478bd9Sstevel@tonic-gate	andb	%dl,(%eax)
1377c478bd9Sstevel@tonic-gate	.end
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate/*
1407c478bd9Sstevel@tonic-gate * atomic inc/dec operations.
1417c478bd9Sstevel@tonic-gate *	void atomic_inc16(uint16_t *addr) { ++*addr; }
1427c478bd9Sstevel@tonic-gate *	void atomic_dec16(uint16_t *addr) { --*addr; }
1437c478bd9Sstevel@tonic-gate */
1447c478bd9Sstevel@tonic-gate	.inline	atomic_inc16,4
1457c478bd9Sstevel@tonic-gate	movl	(%esp), %eax
1467c478bd9Sstevel@tonic-gate	lock
1477c478bd9Sstevel@tonic-gate	incw	(%eax)
1487c478bd9Sstevel@tonic-gate	.end
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate	.inline	atomic_dec16,4
1517c478bd9Sstevel@tonic-gate	movl	(%esp), %eax
1527c478bd9Sstevel@tonic-gate	lock
1537c478bd9Sstevel@tonic-gate	decw	(%eax)
1547c478bd9Sstevel@tonic-gate	.end
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate/*
1577c478bd9Sstevel@tonic-gate * Call the pause instruction.  To the Pentium 4 Xeon processor, it acts as
1587c478bd9Sstevel@tonic-gate * a hint that the code sequence is a busy spin-wait loop.  Without a pause
1597c478bd9Sstevel@tonic-gate * instruction in these loops, the P4 Xeon processor may suffer a severe
1607c478bd9Sstevel@tonic-gate * penalty when exiting the loop because the processor detects a possible
1617c478bd9Sstevel@tonic-gate * memory violation.  Inserting the pause instruction significantly reduces
1627c478bd9Sstevel@tonic-gate * the likelihood of a memory order violation, improving performance.
1637c478bd9Sstevel@tonic-gate * The pause instruction is a NOP on all other IA-32 processors.
1647c478bd9Sstevel@tonic-gate */
1657c478bd9Sstevel@tonic-gate	.inline ht_pause, 0
1667c478bd9Sstevel@tonic-gate	rep			/ our compiler doesn't support "pause" yet,
1677c478bd9Sstevel@tonic-gate	nop			/ so we're using "F3 90" opcode directly
1687c478bd9Sstevel@tonic-gate	.end
1695c7544f7SDavid Plauger
170*94e7edb1Slucy wang - Sun Microsystems - Beijing China/*
171*94e7edb1Slucy wang - Sun Microsystems - Beijing China * prefetch 64 bytes
172*94e7edb1Slucy wang - Sun Microsystems - Beijing China *
173*94e7edb1Slucy wang - Sun Microsystems - Beijing China * prefetch is an SSE extension which is not supported on older 32-bit processors
174*94e7edb1Slucy wang - Sun Microsystems - Beijing China * so define this as a no-op for now
175*94e7edb1Slucy wang - Sun Microsystems - Beijing China */
176*94e7edb1Slucy wang - Sun Microsystems - Beijing China
177*94e7edb1Slucy wang - Sun Microsystems - Beijing China 	.inline	prefetch_read_many,4
17826a04d67SDave Plauger/	movl		(%esp), %eax
17926a04d67SDave Plauger/	prefetcht0	(%eax)
18026a04d67SDave Plauger/	prefetcht0	32(%eax)
1815c7544f7SDavid Plauger	.end
182*94e7edb1Slucy wang - Sun Microsystems - Beijing China
183*94e7edb1Slucy wang - Sun Microsystems - Beijing China 	.inline	prefetch_read_once,4
184*94e7edb1Slucy wang - Sun Microsystems - Beijing China/	movl		(%esp), %eax
185*94e7edb1Slucy wang - Sun Microsystems - Beijing China/	prefetchnta	(%eax)
186*94e7edb1Slucy wang - Sun Microsystems - Beijing China/	prefetchnta	32(%eax)
187*94e7edb1Slucy wang - Sun Microsystems - Beijing China	.end
188*94e7edb1Slucy wang - Sun Microsystems - Beijing China
189*94e7edb1Slucy wang - Sun Microsystems - Beijing China 	.inline	prefetch_write_many,4
190*94e7edb1Slucy wang - Sun Microsystems - Beijing China/	movl		(%esp), %eax
191*94e7edb1Slucy wang - Sun Microsystems - Beijing China/	prefetcht0	(%eax)
192*94e7edb1Slucy wang - Sun Microsystems - Beijing China/	prefetcht0	32(%eax)
193*94e7edb1Slucy wang - Sun Microsystems - Beijing China	.end
194*94e7edb1Slucy wang - Sun Microsystems - Beijing China
195*94e7edb1Slucy wang - Sun Microsystems - Beijing China 	.inline	prefetch_write_once,4
196*94e7edb1Slucy wang - Sun Microsystems - Beijing China/	movl		(%esp), %eax
197*94e7edb1Slucy wang - Sun Microsystems - Beijing China/	prefetcht0	(%eax)
198*94e7edb1Slucy wang - Sun Microsystems - Beijing China/	prefetcht0	32(%eax)
199*94e7edb1Slucy wang - Sun Microsystems - Beijing China	.end
200*94e7edb1Slucy wang - Sun Microsystems - Beijing China
201