xref: /titanic_41/usr/src/uts/intel/amd64/ml/amd64.il (revision a2c1b589b71a94552a6e62f5dea344567007ddf3)
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 */
217c478bd9Sstevel@tonic-gate/*
22*94e7edb1Slucy wang - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate/
277c478bd9Sstevel@tonic-gate/ In-line functions for amd64 kernels.
287c478bd9Sstevel@tonic-gate/
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate/
317c478bd9Sstevel@tonic-gate/ return current thread pointer
327c478bd9Sstevel@tonic-gate/
337c478bd9Sstevel@tonic-gate/ NOTE: the "0x18" should be replaced by the computed value of the
347c478bd9Sstevel@tonic-gate/	offset of "cpu_thread" from the beginning of the struct cpu.
357c478bd9Sstevel@tonic-gate/	Including "assym.h" does not work, however, since that stuff
367c478bd9Sstevel@tonic-gate/	is PSM-specific and is only visible to the 'unix' build anyway.
377c478bd9Sstevel@tonic-gate/	Same with current cpu pointer, where "0xc" should be replaced
387c478bd9Sstevel@tonic-gate/	by the computed value of the offset of "cpu_self".
397c478bd9Sstevel@tonic-gate/	Ugh -- what a disaster.
407c478bd9Sstevel@tonic-gate/
417c478bd9Sstevel@tonic-gate	.inline	threadp,0
427c478bd9Sstevel@tonic-gate	movq	%gs:0x18, %rax
437c478bd9Sstevel@tonic-gate	.end
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate/
467c478bd9Sstevel@tonic-gate/ return current cpu pointer
477c478bd9Sstevel@tonic-gate/
487c478bd9Sstevel@tonic-gate	.inline	curcpup,0
497c478bd9Sstevel@tonic-gate	movq	%gs:0x10, %rax
507c478bd9Sstevel@tonic-gate	.end
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate/
537c478bd9Sstevel@tonic-gate/ return caller
547c478bd9Sstevel@tonic-gate/
557c478bd9Sstevel@tonic-gate	.inline caller,0
567c478bd9Sstevel@tonic-gate	movq	8(%rbp), %rax
577c478bd9Sstevel@tonic-gate	.end
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate/
607c478bd9Sstevel@tonic-gate/ convert ipl to spl.  This is the identity function for i86
617c478bd9Sstevel@tonic-gate/
627c478bd9Sstevel@tonic-gate	.inline	ipltospl,0
637c478bd9Sstevel@tonic-gate	movq	%rdi, %rax
647c478bd9Sstevel@tonic-gate	.end
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate/
677c478bd9Sstevel@tonic-gate/ Networking byte order functions (too bad, Intel has the wrong byte order)
687c478bd9Sstevel@tonic-gate/
697c478bd9Sstevel@tonic-gate
704b56a003SDaniel Anderson	.inline	htonll,4
714b56a003SDaniel Anderson	movq	%rdi, %rax
724b56a003SDaniel Anderson	bswapq	%rax
734b56a003SDaniel Anderson	.end
744b56a003SDaniel Anderson
754b56a003SDaniel Anderson	.inline	ntohll,4
764b56a003SDaniel Anderson	movq	%rdi, %rax
774b56a003SDaniel Anderson	bswapq	%rax
784b56a003SDaniel Anderson	.end
794b56a003SDaniel Anderson
807c478bd9Sstevel@tonic-gate	.inline	htonl,4
817c478bd9Sstevel@tonic-gate	movl	%edi, %eax
827c478bd9Sstevel@tonic-gate	bswap	%eax
837c478bd9Sstevel@tonic-gate	.end
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate	.inline	ntohl,4
867c478bd9Sstevel@tonic-gate	movl	%edi, %eax
877c478bd9Sstevel@tonic-gate	bswap	%eax
887c478bd9Sstevel@tonic-gate	.end
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate	.inline	htons,4
917c478bd9Sstevel@tonic-gate	movl	%edi, %eax
927c478bd9Sstevel@tonic-gate	bswap	%eax
937c478bd9Sstevel@tonic-gate	shrl	$16, %eax
947c478bd9Sstevel@tonic-gate	.end
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate	.inline	ntohs,4
977c478bd9Sstevel@tonic-gate	movl	%edi, %eax
987c478bd9Sstevel@tonic-gate	bswap	%eax
997c478bd9Sstevel@tonic-gate	shrl	$16, %eax
1007c478bd9Sstevel@tonic-gate	.end
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate/*
1037c478bd9Sstevel@tonic-gate * multiply two long numbers and yield a u_lonlong_t result
1047c478bd9Sstevel@tonic-gate * Provided to manipulate hrtime_t values.
1057c478bd9Sstevel@tonic-gate */
1067c478bd9Sstevel@tonic-gate	/* XX64 These don't work correctly with SOS9 build 13.0 yet
1077c478bd9Sstevel@tonic-gate	.inline mul32, 8
1087c478bd9Sstevel@tonic-gate	xorl	%edx, %edx
1097c478bd9Sstevel@tonic-gate	movl	%edi, %eax
1107c478bd9Sstevel@tonic-gate	mull	%esi
1117c478bd9Sstevel@tonic-gate	shlq	$32, %rdx
1127c478bd9Sstevel@tonic-gate	orq	%rdx, %rax
1137c478bd9Sstevel@tonic-gate	ret
1147c478bd9Sstevel@tonic-gate	.end
1157c478bd9Sstevel@tonic-gate	*/
1167c478bd9Sstevel@tonic-gate/*
1177c478bd9Sstevel@tonic-gate * Unlock hres_lock and increment the count value. (See clock.h)
1187c478bd9Sstevel@tonic-gate */
1197c478bd9Sstevel@tonic-gate	.inline unlock_hres_lock, 0
1207c478bd9Sstevel@tonic-gate	lock
1217c478bd9Sstevel@tonic-gate	incl	hres_lock
1227c478bd9Sstevel@tonic-gate	.end
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate	.inline	atomic_orb,8
1257c478bd9Sstevel@tonic-gate	movl	%esi, %eax
1267c478bd9Sstevel@tonic-gate	lock
1277c478bd9Sstevel@tonic-gate	orb	%al,(%rdi)
1287c478bd9Sstevel@tonic-gate	.end
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate	.inline	atomic_andb,8
1317c478bd9Sstevel@tonic-gate	movl	%esi, %eax
1327c478bd9Sstevel@tonic-gate	lock
1337c478bd9Sstevel@tonic-gate	andb	%al,(%rdi)
1347c478bd9Sstevel@tonic-gate	.end
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate/*
1377c478bd9Sstevel@tonic-gate * atomic inc/dec operations.
1387c478bd9Sstevel@tonic-gate *	void atomic_inc16(uint16_t *addr) { ++*addr; }
1397c478bd9Sstevel@tonic-gate *	void atomic_dec16(uint16_t *addr) { --*addr; }
1407c478bd9Sstevel@tonic-gate */
1417c478bd9Sstevel@tonic-gate	.inline	atomic_inc16,4
1427c478bd9Sstevel@tonic-gate	lock
1437c478bd9Sstevel@tonic-gate	incw	(%rdi)
1447c478bd9Sstevel@tonic-gate	.end
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate	.inline	atomic_dec16,4
1477c478bd9Sstevel@tonic-gate	lock
1487c478bd9Sstevel@tonic-gate	decw	(%rdi)
1497c478bd9Sstevel@tonic-gate	.end
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate/*
1527c478bd9Sstevel@tonic-gate * atomic bit clear
1537c478bd9Sstevel@tonic-gate */
1547c478bd9Sstevel@tonic-gate	.inline atomic_btr32,8
1557c478bd9Sstevel@tonic-gate	lock
1567c478bd9Sstevel@tonic-gate	btrl %esi, (%rdi)
1577c478bd9Sstevel@tonic-gate	setc %al
1587c478bd9Sstevel@tonic-gate	.end
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate/*
1617c478bd9Sstevel@tonic-gate * Call the pause instruction.  To the Pentium 4 Xeon processor, it acts as
1627c478bd9Sstevel@tonic-gate * a hint that the code sequence is a busy spin-wait loop.  Without a pause
1637c478bd9Sstevel@tonic-gate * instruction in these loops, the P4 Xeon processor may suffer a severe
1647c478bd9Sstevel@tonic-gate * penalty when exiting the loop because the processor detects a possible
1657c478bd9Sstevel@tonic-gate * memory violation.  Inserting the pause instruction significantly reduces
1667c478bd9Sstevel@tonic-gate * the likelihood of a memory order violation, improving performance.
1677c478bd9Sstevel@tonic-gate * The pause instruction is a NOP on all other IA-32 processors.
1687c478bd9Sstevel@tonic-gate */
1697c478bd9Sstevel@tonic-gate	.inline ht_pause, 0
1707c478bd9Sstevel@tonic-gate	pause
1717c478bd9Sstevel@tonic-gate	.end
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate/*
174ae115bc7Smrj * inlines for update_sregs().
1757c478bd9Sstevel@tonic-gate */
176ae115bc7Smrj        .inline __set_ds, 0
177ae115bc7Smrj        movw    %di, %ds
178ae115bc7Smrj        .end
179ae115bc7Smrj
180ae115bc7Smrj        .inline __set_es, 0
181ae115bc7Smrj        movw    %di, %es
182ae115bc7Smrj        .end
183ae115bc7Smrj
184ae115bc7Smrj        .inline __set_fs, 0
185ae115bc7Smrj        movw    %di, %fs
186ae115bc7Smrj        .end
187ae115bc7Smrj
188ae115bc7Smrj        .inline __set_gs, 0
189ae115bc7Smrj        movw    %di, %gs
190ae115bc7Smrj        .end
191ae115bc7Smrj
192ae115bc7Smrj	/*
193ae115bc7Smrj	 * OPTERON_ERRATUM_88 requires mfence
194ae115bc7Smrj	 */
195ae115bc7Smrj        .inline __swapgs, 0
196ae115bc7Smrj        mfence
197ae115bc7Smrj        swapgs
1987c478bd9Sstevel@tonic-gate	.end
1995c7544f7SDavid Plauger
200*94e7edb1Slucy wang - Sun Microsystems - Beijing China/*
201*94e7edb1Slucy wang - Sun Microsystems - Beijing China * prefetch 64 bytes
202*94e7edb1Slucy wang - Sun Microsystems - Beijing China */
203*94e7edb1Slucy wang - Sun Microsystems - Beijing China
204*94e7edb1Slucy wang - Sun Microsystems - Beijing China 	.inline	prefetch_read_many,8
205*94e7edb1Slucy wang - Sun Microsystems - Beijing China	prefetcht0	(%rdi)
206*94e7edb1Slucy wang - Sun Microsystems - Beijing China	prefetcht0	32(%rdi)
207*94e7edb1Slucy wang - Sun Microsystems - Beijing China	.end
208*94e7edb1Slucy wang - Sun Microsystems - Beijing China
209*94e7edb1Slucy wang - Sun Microsystems - Beijing China 	.inline	prefetch_read_once,8
210*94e7edb1Slucy wang - Sun Microsystems - Beijing China	prefetchnta	(%rdi)
211*94e7edb1Slucy wang - Sun Microsystems - Beijing China	prefetchnta	32(%rdi)
212*94e7edb1Slucy wang - Sun Microsystems - Beijing China	.end
213*94e7edb1Slucy wang - Sun Microsystems - Beijing China
214*94e7edb1Slucy wang - Sun Microsystems - Beijing China 	.inline	prefetch_write_many,8
215*94e7edb1Slucy wang - Sun Microsystems - Beijing China	prefetcht0	(%rdi)
216*94e7edb1Slucy wang - Sun Microsystems - Beijing China	prefetcht0	32(%rdi)
217*94e7edb1Slucy wang - Sun Microsystems - Beijing China	.end
218*94e7edb1Slucy wang - Sun Microsystems - Beijing China
219*94e7edb1Slucy wang - Sun Microsystems - Beijing China 	.inline	prefetch_write_once,8
2205c7544f7SDavid Plauger	prefetcht0	(%rdi)
2215c7544f7SDavid Plauger	prefetcht0	32(%rdi)
2225c7544f7SDavid Plauger	.end
223