xref: /titanic_41/usr/src/uts/i86pc/ml/fast_trap_asm.s (revision 355b4669e025ff377602b6fc7caaf30dbc218371)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29#include <sys/asm_linkage.h>
30#include <sys/asm_misc.h>
31#include <sys/regset.h>
32#include <sys/psw.h>
33
34#if defined(__lint)
35
36#include <sys/types.h>
37#include <sys/thread.h>
38#include <sys/systm.h>
39#include <sys/lgrp.h>
40
41#else   /* __lint */
42
43#include <sys/pcb.h>
44#include <sys/trap.h>
45#include <sys/ftrace.h>
46#include <sys/traptrace.h>
47#include <sys/clock.h>
48#include <sys/panic.h>
49#include "assym.h"
50
51#endif	/* __lint */
52
53
54#if defined(__lint)
55
56hrtime_t
57get_hrtime(void)
58{ return (0); }
59
60hrtime_t
61get_hrestime(void)
62{
63	hrtime_t ts;
64
65	gethrestime((timespec_t *)&ts);
66	return (ts);
67}
68
69hrtime_t
70gethrvtime(void)
71{
72	klwp_t *lwp = ttolwp(curthread);
73	struct mstate *ms = &lwp->lwp_mstate;
74
75	return (gethrtime() - ms->ms_state_start + ms->ms_acct[LMS_USER]);
76}
77
78uint64_t
79getlgrp(void)
80{
81	return (((uint64_t)(curthread->t_lpl->lpl_lgrpid) << 32) |
82			curthread->t_cpu->cpu_id);
83}
84
85#else	/* __lint */
86
87/*
88 * XX64: We are assuming that libc continues to expect the 64-bit value being
89 * returned in %edx:%eax.  We further assume that it is safe to leave
90 * the top 32-bit intact in %rax as they will be ignored by libc.  In
91 * other words, if the 64-bit value is already in %rax, while we manually
92 * manufacture a 64-bit value in %edx:%eax by setting %edx to be the high
93 * 32 bits of %rax, we don't zero them out in %rax.
94 * The following amd64 versions will need to be changed if the above
95 * assumptions are not true.
96 */
97
98#if defined(__amd64)
99
100	.globl	gethrtimef
101	ENTRY_NP(get_hrtime)
102	FAST_INTR_PUSH
103	call	*gethrtimef(%rip)
104	movq	%rax, %rdx
105	shrq	$32, %rdx			/* high 32-bit in %edx */
106	FAST_INTR_POP
107	iretq
108	SET_SIZE(get_hrtime)
109
110#elif defined(__i386)
111
112	.globl	gethrtimef
113	ENTRY_NP(get_hrtime)
114	FAST_INTR_PUSH
115	call	*gethrtimef
116	FAST_INTR_POP
117	iret
118	SET_SIZE(get_hrtime)
119
120#endif	/* __i386 */
121
122#if defined(__amd64)
123
124	.globl	gethrestimef
125	ENTRY_NP(get_hrestime)
126	FAST_INTR_PUSH
127	subq	$TIMESPEC_SIZE, %rsp
128	movq	%rsp, %rdi
129	call	*gethrestimef(%rip)
130	movl	(%rsp), %eax
131	movl	CLONGSIZE(%rsp), %edx
132	addq	$TIMESPEC_SIZE, %rsp
133	FAST_INTR_POP
134	iretq
135	SET_SIZE(get_hrestime)
136
137#elif defined(__i386)
138
139	.globl	gethrestimef
140	ENTRY_NP(get_hrestime)
141	FAST_INTR_PUSH
142	subl	$TIMESPEC_SIZE, %esp
143	pushl	%esp
144	call	*gethrestimef
145	movl	_CONST(4 + 0)(%esp), %eax
146	movl	_CONST(4 + CLONGSIZE)(%esp), %edx
147	addl	$_CONST(4 + TIMESPEC_SIZE), %esp
148	FAST_INTR_POP
149	iret
150	SET_SIZE(get_hrestime)
151
152#endif	/* __i386 */
153
154#if defined(__amd64)
155
156	ENTRY_NP(gethrvtime)
157	FAST_INTR_PUSH
158	call	gethrtime_unscaled		/* get time since boot */
159	movq	%gs:CPU_LWP, %rcx		/* current lwp */
160	subq	LWP_MS_STATE_START(%rcx), %rax	/* - ms->ms_state_start */
161	addq	LWP_ACCT_USER(%rcx), %rax	/* add ms->ms_acct[LMS_USER] */
162	subq	$16, %rsp
163	movq	%rax, (%rsp)
164	movq	%rsp, %rdi
165	call	scalehrtime
166	movq	(%rsp), %rax
167	addq	$16, %rsp
168	movq	%rax, %rdx
169	shrq	$32, %rdx			/* high 32-bit in %rdx */
170	FAST_INTR_POP
171	iretq
172
173	SET_SIZE(gethrvtime)
174
175#elif defined(__i386)
176
177	ENTRY_NP(gethrvtime)
178	FAST_INTR_PUSH
179	call	gethrtime_unscaled		/* get time since boot */
180	movl	%gs:CPU_LWP, %ecx		/* current lwp */
181	subl	LWP_MS_STATE_START(%ecx), %eax	/* - ms->ms_state_start */
182	sbbl	LWP_MS_STATE_START+4(%ecx), %edx
183	addl	LWP_ACCT_USER(%ecx), %eax	/* add ms->ms_acct[LMS_USER] */
184	adcl	LWP_ACCT_USER+4(%ecx), %edx
185	subl	$0x8, %esp
186	leal	(%esp), %ecx
187	movl	%eax, (%ecx)
188	movl	%edx, 4(%ecx)
189	pushl	%ecx
190	call	scalehrtime
191	popl	%ecx
192	movl	(%ecx), %eax
193	movl	4(%ecx), %edx
194	addl	$0x8, %esp
195	FAST_INTR_POP
196	iret
197	SET_SIZE(gethrvtime)
198
199#endif	/* __i386 */
200
201#if defined(__amd64)
202
203	ENTRY_NP(getlgrp)
204	FAST_INTR_PUSH
205	movq	%gs:CPU_THREAD, %rcx
206	movq	T_LPL(%rcx), %rcx
207	movl	LPL_LGRPID(%rcx), %edx
208	movl	%gs:CPU_ID, %eax
209	FAST_INTR_POP
210	iretq
211	SET_SIZE(getlgrp)
212
213#elif defined(__i386)
214
215	ENTRY_NP(getlgrp)
216	FAST_INTR_PUSH
217	movl	%gs:CPU_THREAD, %ecx
218	movl	T_LPL(%ecx), %ecx
219	movl	LPL_LGRPID(%ecx), %edx
220	movl	%gs:CPU_ID, %eax
221	FAST_INTR_POP
222	iret
223	SET_SIZE(getlgrp)
224
225#endif	/* __i386 */
226
227#endif	/* __lint */
228