xref: /onnv-gate/usr/src/uts/i86pc/ml/fast_trap_asm.s (revision 5084:7d838c5c0eed)
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
5*5084Sjohnlev * Common Development and Distribution License (the "License").
6*5084Sjohnlev * 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/*
22*5084Sjohnlev * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate#include <sys/asm_linkage.h>
290Sstevel@tonic-gate#include <sys/asm_misc.h>
300Sstevel@tonic-gate#include <sys/regset.h>
310Sstevel@tonic-gate#include <sys/psw.h>
320Sstevel@tonic-gate
330Sstevel@tonic-gate#if defined(__lint)
340Sstevel@tonic-gate
350Sstevel@tonic-gate#include <sys/types.h>
360Sstevel@tonic-gate#include <sys/thread.h>
370Sstevel@tonic-gate#include <sys/systm.h>
380Sstevel@tonic-gate#include <sys/lgrp.h>
390Sstevel@tonic-gate
400Sstevel@tonic-gate#else   /* __lint */
410Sstevel@tonic-gate
420Sstevel@tonic-gate#include <sys/pcb.h>
430Sstevel@tonic-gate#include <sys/trap.h>
440Sstevel@tonic-gate#include <sys/ftrace.h>
450Sstevel@tonic-gate#include <sys/traptrace.h>
460Sstevel@tonic-gate#include <sys/clock.h>
470Sstevel@tonic-gate#include <sys/panic.h>
48*5084Sjohnlev#include <sys/privregs.h>
49*5084Sjohnlev
500Sstevel@tonic-gate#include "assym.h"
510Sstevel@tonic-gate
520Sstevel@tonic-gate#endif	/* __lint */
530Sstevel@tonic-gate
540Sstevel@tonic-gate
550Sstevel@tonic-gate#if defined(__lint)
560Sstevel@tonic-gate
570Sstevel@tonic-gatehrtime_t
580Sstevel@tonic-gateget_hrtime(void)
590Sstevel@tonic-gate{ return (0); }
600Sstevel@tonic-gate
610Sstevel@tonic-gatehrtime_t
620Sstevel@tonic-gateget_hrestime(void)
630Sstevel@tonic-gate{
640Sstevel@tonic-gate	hrtime_t ts;
650Sstevel@tonic-gate
660Sstevel@tonic-gate	gethrestime((timespec_t *)&ts);
670Sstevel@tonic-gate	return (ts);
680Sstevel@tonic-gate}
690Sstevel@tonic-gate
700Sstevel@tonic-gatehrtime_t
710Sstevel@tonic-gategethrvtime(void)
720Sstevel@tonic-gate{
730Sstevel@tonic-gate	klwp_t *lwp = ttolwp(curthread);
740Sstevel@tonic-gate	struct mstate *ms = &lwp->lwp_mstate;
750Sstevel@tonic-gate
760Sstevel@tonic-gate	return (gethrtime() - ms->ms_state_start + ms->ms_acct[LMS_USER]);
770Sstevel@tonic-gate}
780Sstevel@tonic-gate
790Sstevel@tonic-gateuint64_t
800Sstevel@tonic-gategetlgrp(void)
810Sstevel@tonic-gate{
820Sstevel@tonic-gate	return (((uint64_t)(curthread->t_lpl->lpl_lgrpid) << 32) |
830Sstevel@tonic-gate			curthread->t_cpu->cpu_id);
840Sstevel@tonic-gate}
850Sstevel@tonic-gate
860Sstevel@tonic-gate#else	/* __lint */
870Sstevel@tonic-gate
880Sstevel@tonic-gate/*
890Sstevel@tonic-gate * XX64: We are assuming that libc continues to expect the 64-bit value being
900Sstevel@tonic-gate * returned in %edx:%eax.  We further assume that it is safe to leave
910Sstevel@tonic-gate * the top 32-bit intact in %rax as they will be ignored by libc.  In
920Sstevel@tonic-gate * other words, if the 64-bit value is already in %rax, while we manually
930Sstevel@tonic-gate * manufacture a 64-bit value in %edx:%eax by setting %edx to be the high
940Sstevel@tonic-gate * 32 bits of %rax, we don't zero them out in %rax.
950Sstevel@tonic-gate * The following amd64 versions will need to be changed if the above
960Sstevel@tonic-gate * assumptions are not true.
970Sstevel@tonic-gate */
980Sstevel@tonic-gate
990Sstevel@tonic-gate#if defined(__amd64)
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate	.globl	gethrtimef
1020Sstevel@tonic-gate	ENTRY_NP(get_hrtime)
1030Sstevel@tonic-gate	FAST_INTR_PUSH
1040Sstevel@tonic-gate	call	*gethrtimef(%rip)
1050Sstevel@tonic-gate	movq	%rax, %rdx
1060Sstevel@tonic-gate	shrq	$32, %rdx			/* high 32-bit in %edx */
1070Sstevel@tonic-gate	FAST_INTR_POP
108*5084Sjohnlev	FAST_INTR_RETURN
1090Sstevel@tonic-gate	SET_SIZE(get_hrtime)
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate#elif defined(__i386)
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate	.globl	gethrtimef
1140Sstevel@tonic-gate	ENTRY_NP(get_hrtime)
1150Sstevel@tonic-gate	FAST_INTR_PUSH
1160Sstevel@tonic-gate	call	*gethrtimef
1170Sstevel@tonic-gate	FAST_INTR_POP
118*5084Sjohnlev	FAST_INTR_RETURN
1190Sstevel@tonic-gate	SET_SIZE(get_hrtime)
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate#endif	/* __i386 */
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate#if defined(__amd64)
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate	.globl	gethrestimef
1260Sstevel@tonic-gate	ENTRY_NP(get_hrestime)
1270Sstevel@tonic-gate	FAST_INTR_PUSH
1280Sstevel@tonic-gate	subq	$TIMESPEC_SIZE, %rsp
1290Sstevel@tonic-gate	movq	%rsp, %rdi
1300Sstevel@tonic-gate	call	*gethrestimef(%rip)
1310Sstevel@tonic-gate	movl	(%rsp), %eax
1320Sstevel@tonic-gate	movl	CLONGSIZE(%rsp), %edx
1330Sstevel@tonic-gate	addq	$TIMESPEC_SIZE, %rsp
1340Sstevel@tonic-gate	FAST_INTR_POP
135*5084Sjohnlev	FAST_INTR_RETURN
1360Sstevel@tonic-gate	SET_SIZE(get_hrestime)
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate#elif defined(__i386)
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate	.globl	gethrestimef
1410Sstevel@tonic-gate	ENTRY_NP(get_hrestime)
1420Sstevel@tonic-gate	FAST_INTR_PUSH
1430Sstevel@tonic-gate	subl	$TIMESPEC_SIZE, %esp
1440Sstevel@tonic-gate	pushl	%esp
1450Sstevel@tonic-gate	call	*gethrestimef
1460Sstevel@tonic-gate	movl	_CONST(4 + 0)(%esp), %eax
1470Sstevel@tonic-gate	movl	_CONST(4 + CLONGSIZE)(%esp), %edx
1480Sstevel@tonic-gate	addl	$_CONST(4 + TIMESPEC_SIZE), %esp
1490Sstevel@tonic-gate	FAST_INTR_POP
150*5084Sjohnlev	FAST_INTR_RETURN
1510Sstevel@tonic-gate	SET_SIZE(get_hrestime)
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate#endif	/* __i386 */
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate#if defined(__amd64)
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate	ENTRY_NP(gethrvtime)
1580Sstevel@tonic-gate	FAST_INTR_PUSH
1590Sstevel@tonic-gate	call	gethrtime_unscaled		/* get time since boot */
1600Sstevel@tonic-gate	movq	%gs:CPU_LWP, %rcx		/* current lwp */
1610Sstevel@tonic-gate	subq	LWP_MS_STATE_START(%rcx), %rax	/* - ms->ms_state_start */
1620Sstevel@tonic-gate	addq	LWP_ACCT_USER(%rcx), %rax	/* add ms->ms_acct[LMS_USER] */
1630Sstevel@tonic-gate	subq	$16, %rsp
1640Sstevel@tonic-gate	movq	%rax, (%rsp)
1650Sstevel@tonic-gate	movq	%rsp, %rdi
1660Sstevel@tonic-gate	call	scalehrtime
1670Sstevel@tonic-gate	movq	(%rsp), %rax
1680Sstevel@tonic-gate	addq	$16, %rsp
1690Sstevel@tonic-gate	movq	%rax, %rdx
1700Sstevel@tonic-gate	shrq	$32, %rdx			/* high 32-bit in %rdx */
1710Sstevel@tonic-gate	FAST_INTR_POP
172*5084Sjohnlev	FAST_INTR_RETURN
1730Sstevel@tonic-gate	SET_SIZE(gethrvtime)
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate#elif defined(__i386)
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate	ENTRY_NP(gethrvtime)
1780Sstevel@tonic-gate	FAST_INTR_PUSH
1790Sstevel@tonic-gate	call	gethrtime_unscaled		/* get time since boot */
1800Sstevel@tonic-gate	movl	%gs:CPU_LWP, %ecx		/* current lwp */
1810Sstevel@tonic-gate	subl	LWP_MS_STATE_START(%ecx), %eax	/* - ms->ms_state_start */
1820Sstevel@tonic-gate	sbbl	LWP_MS_STATE_START+4(%ecx), %edx
1830Sstevel@tonic-gate	addl	LWP_ACCT_USER(%ecx), %eax	/* add ms->ms_acct[LMS_USER] */
1840Sstevel@tonic-gate	adcl	LWP_ACCT_USER+4(%ecx), %edx
1850Sstevel@tonic-gate	subl	$0x8, %esp
1860Sstevel@tonic-gate	leal	(%esp), %ecx
1870Sstevel@tonic-gate	movl	%eax, (%ecx)
1880Sstevel@tonic-gate	movl	%edx, 4(%ecx)
1890Sstevel@tonic-gate	pushl	%ecx
1900Sstevel@tonic-gate	call	scalehrtime
1910Sstevel@tonic-gate	popl	%ecx
1920Sstevel@tonic-gate	movl	(%ecx), %eax
1930Sstevel@tonic-gate	movl	4(%ecx), %edx
1940Sstevel@tonic-gate	addl	$0x8, %esp
1950Sstevel@tonic-gate	FAST_INTR_POP
196*5084Sjohnlev	FAST_INTR_RETURN
1970Sstevel@tonic-gate	SET_SIZE(gethrvtime)
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate#endif	/* __i386 */
2000Sstevel@tonic-gate
2010Sstevel@tonic-gate#if defined(__amd64)
2020Sstevel@tonic-gate
2030Sstevel@tonic-gate	ENTRY_NP(getlgrp)
2040Sstevel@tonic-gate	FAST_INTR_PUSH
2050Sstevel@tonic-gate	movq	%gs:CPU_THREAD, %rcx
2060Sstevel@tonic-gate	movq	T_LPL(%rcx), %rcx
2070Sstevel@tonic-gate	movl	LPL_LGRPID(%rcx), %edx
2080Sstevel@tonic-gate	movl	%gs:CPU_ID, %eax
2090Sstevel@tonic-gate	FAST_INTR_POP
210*5084Sjohnlev	FAST_INTR_RETURN
2110Sstevel@tonic-gate	SET_SIZE(getlgrp)
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate#elif defined(__i386)
2140Sstevel@tonic-gate
2150Sstevel@tonic-gate	ENTRY_NP(getlgrp)
2160Sstevel@tonic-gate	FAST_INTR_PUSH
2170Sstevel@tonic-gate	movl	%gs:CPU_THREAD, %ecx
2180Sstevel@tonic-gate	movl	T_LPL(%ecx), %ecx
2190Sstevel@tonic-gate	movl	LPL_LGRPID(%ecx), %edx
2200Sstevel@tonic-gate	movl	%gs:CPU_ID, %eax
2210Sstevel@tonic-gate	FAST_INTR_POP
222*5084Sjohnlev	FAST_INTR_RETURN
2230Sstevel@tonic-gate	SET_SIZE(getlgrp)
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate#endif	/* __i386 */
2260Sstevel@tonic-gate
2270Sstevel@tonic-gate#endif	/* __lint */
228