xref: /illumos-gate/usr/src/uts/i86pc/ml/fast_trap_asm.S (revision 5d9d9091f564c198a760790b0bfa72c44e17912b)
1*5d9d9091SRichard Lowe/*
2*5d9d9091SRichard Lowe * CDDL HEADER START
3*5d9d9091SRichard Lowe *
4*5d9d9091SRichard Lowe * The contents of this file are subject to the terms of the
5*5d9d9091SRichard Lowe * Common Development and Distribution License (the "License").
6*5d9d9091SRichard Lowe * You may not use this file except in compliance with the License.
7*5d9d9091SRichard Lowe *
8*5d9d9091SRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5d9d9091SRichard Lowe * or http://www.opensolaris.org/os/licensing.
10*5d9d9091SRichard Lowe * See the License for the specific language governing permissions
11*5d9d9091SRichard Lowe * and limitations under the License.
12*5d9d9091SRichard Lowe *
13*5d9d9091SRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each
14*5d9d9091SRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5d9d9091SRichard Lowe * If applicable, add the following below this CDDL HEADER, with the
16*5d9d9091SRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
17*5d9d9091SRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
18*5d9d9091SRichard Lowe *
19*5d9d9091SRichard Lowe * CDDL HEADER END
20*5d9d9091SRichard Lowe */
21*5d9d9091SRichard Lowe/*
22*5d9d9091SRichard Lowe * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*5d9d9091SRichard Lowe * Use is subject to license terms.
24*5d9d9091SRichard Lowe * Copyright 2019 Joyent, Inc.
25*5d9d9091SRichard Lowe */
26*5d9d9091SRichard Lowe
27*5d9d9091SRichard Lowe#include <sys/asm_linkage.h>
28*5d9d9091SRichard Lowe#include <sys/asm_misc.h>
29*5d9d9091SRichard Lowe#include <sys/regset.h>
30*5d9d9091SRichard Lowe#include <sys/psw.h>
31*5d9d9091SRichard Lowe
32*5d9d9091SRichard Lowe#include <sys/pcb.h>
33*5d9d9091SRichard Lowe#include <sys/trap.h>
34*5d9d9091SRichard Lowe#include <sys/ftrace.h>
35*5d9d9091SRichard Lowe#include <sys/traptrace.h>
36*5d9d9091SRichard Lowe#include <sys/clock.h>
37*5d9d9091SRichard Lowe#include <sys/panic.h>
38*5d9d9091SRichard Lowe#include <sys/privregs.h>
39*5d9d9091SRichard Lowe
40*5d9d9091SRichard Lowe#include "assym.h"
41*5d9d9091SRichard Lowe
42*5d9d9091SRichard Lowe
43*5d9d9091SRichard Lowe/*
44*5d9d9091SRichard Lowe * XX64: We are assuming that libc continues to expect the 64-bit value being
45*5d9d9091SRichard Lowe * returned in %edx:%eax.  We further assume that it is safe to leave
46*5d9d9091SRichard Lowe * the top 32-bit intact in %rax as they will be ignored by libc.  In
47*5d9d9091SRichard Lowe * other words, if the 64-bit value is already in %rax, while we manually
48*5d9d9091SRichard Lowe * manufacture a 64-bit value in %edx:%eax by setting %edx to be the high
49*5d9d9091SRichard Lowe * 32 bits of %rax, we don't zero them out in %rax.
50*5d9d9091SRichard Lowe * The following amd64 versions will need to be changed if the above
51*5d9d9091SRichard Lowe * assumptions are not true.
52*5d9d9091SRichard Lowe */
53*5d9d9091SRichard Lowe
54*5d9d9091SRichard Lowe	.globl	gethrtimef
55*5d9d9091SRichard Lowe	ENTRY_NP(get_hrtime)
56*5d9d9091SRichard Lowe	FAST_INTR_PUSH
57*5d9d9091SRichard Lowe	movq	gethrtimef(%rip), %rax
58*5d9d9091SRichard Lowe	INDIRECT_CALL_REG(rax)
59*5d9d9091SRichard Lowe	movq	%rax, %rdx
60*5d9d9091SRichard Lowe	shrq	$32, %rdx			/* high 32-bit in %edx */
61*5d9d9091SRichard Lowe	FAST_INTR_POP
62*5d9d9091SRichard Lowe	FAST_INTR_RETURN
63*5d9d9091SRichard Lowe	SET_SIZE(get_hrtime)
64*5d9d9091SRichard Lowe
65*5d9d9091SRichard Lowe	.globl	gethrestimef
66*5d9d9091SRichard Lowe	ENTRY_NP(get_hrestime)
67*5d9d9091SRichard Lowe	FAST_INTR_PUSH
68*5d9d9091SRichard Lowe	subq	$TIMESPEC_SIZE, %rsp
69*5d9d9091SRichard Lowe	movq	%rsp, %rdi
70*5d9d9091SRichard Lowe	movq	gethrestimef(%rip), %rax
71*5d9d9091SRichard Lowe	INDIRECT_CALL_REG(rax)
72*5d9d9091SRichard Lowe	movl	(%rsp), %eax
73*5d9d9091SRichard Lowe	movl	CLONGSIZE(%rsp), %edx
74*5d9d9091SRichard Lowe	addq	$TIMESPEC_SIZE, %rsp
75*5d9d9091SRichard Lowe	FAST_INTR_POP
76*5d9d9091SRichard Lowe	FAST_INTR_RETURN
77*5d9d9091SRichard Lowe	SET_SIZE(get_hrestime)
78*5d9d9091SRichard Lowe
79*5d9d9091SRichard Lowe	/*
80*5d9d9091SRichard Lowe	 * In C this is
81*5d9d9091SRichard Lowe	 *
82*5d9d9091SRichard Lowe	 * klwp_t *lwp = ttolwp(curthread);
83*5d9d9091SRichard Lowe	 * struct mstate *ms = &lwp->lwp_mstate;
84*5d9d9091SRichard Lowe	 * return (gethrtime() - ms->ms_state_start + ms->ms_acct[LMS_USER]);
85*5d9d9091SRichard Lowe	 */
86*5d9d9091SRichard Lowe	ENTRY_NP(gethrvtime)
87*5d9d9091SRichard Lowe	FAST_INTR_PUSH
88*5d9d9091SRichard Lowe	call	gethrtime_unscaled		/* get time since boot */
89*5d9d9091SRichard Lowe	movq	%gs:CPU_LWP, %rcx		/* current lwp */
90*5d9d9091SRichard Lowe	subq	LWP_MS_STATE_START(%rcx), %rax	/* - ms->ms_state_start */
91*5d9d9091SRichard Lowe	addq	LWP_ACCT_USER(%rcx), %rax	/* add ms->ms_acct[LMS_USER] */
92*5d9d9091SRichard Lowe	subq	$16, %rsp
93*5d9d9091SRichard Lowe	movq	%rax, (%rsp)
94*5d9d9091SRichard Lowe	movq	%rsp, %rdi
95*5d9d9091SRichard Lowe	call	scalehrtime
96*5d9d9091SRichard Lowe	movq	(%rsp), %rax
97*5d9d9091SRichard Lowe	addq	$16, %rsp
98*5d9d9091SRichard Lowe	movq	%rax, %rdx
99*5d9d9091SRichard Lowe	shrq	$32, %rdx			/* high 32-bit in %rdx */
100*5d9d9091SRichard Lowe	FAST_INTR_POP
101*5d9d9091SRichard Lowe	FAST_INTR_RETURN
102*5d9d9091SRichard Lowe	SET_SIZE(gethrvtime)
103*5d9d9091SRichard Lowe
104*5d9d9091SRichard Lowe	/*
105*5d9d9091SRichard Lowe	 * In C this is:
106*5d9d9091SRichard Lowe	 *
107*5d9d9091SRichard Lowe	 * return (((uint64_t)(curthread->t_lpl->lpl_lgrpid) << 32) |
108*5d9d9091SRichard Lowe	 *     curthread->t_cpu->cpu_id);
109*5d9d9091SRichard Lowe	 */
110*5d9d9091SRichard Lowe	ENTRY_NP(getlgrp)
111*5d9d9091SRichard Lowe	FAST_INTR_PUSH
112*5d9d9091SRichard Lowe	movq	%gs:CPU_THREAD, %rcx
113*5d9d9091SRichard Lowe	movq	T_LPL(%rcx), %rcx
114*5d9d9091SRichard Lowe	movl	LPL_LGRPID(%rcx), %edx
115*5d9d9091SRichard Lowe	movl	%gs:CPU_ID, %eax
116*5d9d9091SRichard Lowe	FAST_INTR_POP
117*5d9d9091SRichard Lowe	FAST_INTR_RETURN
118*5d9d9091SRichard Lowe	SET_SIZE(getlgrp)
119*5d9d9091SRichard Lowe
120