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 5*843e1988Sjohnlev * Common Development and Distribution License (the "License"). 6*843e1988Sjohnlev * 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*843e1988Sjohnlev * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate#pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h> 297c478bd9Sstevel@tonic-gate#include <sys/asm_misc.h> 307c478bd9Sstevel@tonic-gate#include <sys/regset.h> 317c478bd9Sstevel@tonic-gate#include <sys/psw.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate#if defined(__lint) 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate#include <sys/types.h> 367c478bd9Sstevel@tonic-gate#include <sys/thread.h> 377c478bd9Sstevel@tonic-gate#include <sys/systm.h> 387c478bd9Sstevel@tonic-gate#include <sys/lgrp.h> 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate#else /* __lint */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate#include <sys/pcb.h> 437c478bd9Sstevel@tonic-gate#include <sys/trap.h> 447c478bd9Sstevel@tonic-gate#include <sys/ftrace.h> 457c478bd9Sstevel@tonic-gate#include <sys/traptrace.h> 467c478bd9Sstevel@tonic-gate#include <sys/clock.h> 477c478bd9Sstevel@tonic-gate#include <sys/panic.h> 48*843e1988Sjohnlev#include <sys/privregs.h> 49*843e1988Sjohnlev 507c478bd9Sstevel@tonic-gate#include "assym.h" 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate#endif /* __lint */ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate#if defined(__lint) 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gatehrtime_t 587c478bd9Sstevel@tonic-gateget_hrtime(void) 597c478bd9Sstevel@tonic-gate{ return (0); } 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gatehrtime_t 627c478bd9Sstevel@tonic-gateget_hrestime(void) 637c478bd9Sstevel@tonic-gate{ 647c478bd9Sstevel@tonic-gate hrtime_t ts; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate gethrestime((timespec_t *)&ts); 677c478bd9Sstevel@tonic-gate return (ts); 687c478bd9Sstevel@tonic-gate} 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gatehrtime_t 717c478bd9Sstevel@tonic-gategethrvtime(void) 727c478bd9Sstevel@tonic-gate{ 737c478bd9Sstevel@tonic-gate klwp_t *lwp = ttolwp(curthread); 747c478bd9Sstevel@tonic-gate struct mstate *ms = &lwp->lwp_mstate; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate return (gethrtime() - ms->ms_state_start + ms->ms_acct[LMS_USER]); 777c478bd9Sstevel@tonic-gate} 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gateuint64_t 807c478bd9Sstevel@tonic-gategetlgrp(void) 817c478bd9Sstevel@tonic-gate{ 827c478bd9Sstevel@tonic-gate return (((uint64_t)(curthread->t_lpl->lpl_lgrpid) << 32) | 837c478bd9Sstevel@tonic-gate curthread->t_cpu->cpu_id); 847c478bd9Sstevel@tonic-gate} 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate#else /* __lint */ 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate/* 897c478bd9Sstevel@tonic-gate * XX64: We are assuming that libc continues to expect the 64-bit value being 907c478bd9Sstevel@tonic-gate * returned in %edx:%eax. We further assume that it is safe to leave 917c478bd9Sstevel@tonic-gate * the top 32-bit intact in %rax as they will be ignored by libc. In 927c478bd9Sstevel@tonic-gate * other words, if the 64-bit value is already in %rax, while we manually 937c478bd9Sstevel@tonic-gate * manufacture a 64-bit value in %edx:%eax by setting %edx to be the high 947c478bd9Sstevel@tonic-gate * 32 bits of %rax, we don't zero them out in %rax. 957c478bd9Sstevel@tonic-gate * The following amd64 versions will need to be changed if the above 967c478bd9Sstevel@tonic-gate * assumptions are not true. 977c478bd9Sstevel@tonic-gate */ 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate#if defined(__amd64) 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate .globl gethrtimef 1027c478bd9Sstevel@tonic-gate ENTRY_NP(get_hrtime) 1037c478bd9Sstevel@tonic-gate FAST_INTR_PUSH 1047c478bd9Sstevel@tonic-gate call *gethrtimef(%rip) 1057c478bd9Sstevel@tonic-gate movq %rax, %rdx 1067c478bd9Sstevel@tonic-gate shrq $32, %rdx /* high 32-bit in %edx */ 1077c478bd9Sstevel@tonic-gate FAST_INTR_POP 108*843e1988Sjohnlev FAST_INTR_RETURN 1097c478bd9Sstevel@tonic-gate SET_SIZE(get_hrtime) 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate#elif defined(__i386) 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate .globl gethrtimef 1147c478bd9Sstevel@tonic-gate ENTRY_NP(get_hrtime) 1157c478bd9Sstevel@tonic-gate FAST_INTR_PUSH 1167c478bd9Sstevel@tonic-gate call *gethrtimef 1177c478bd9Sstevel@tonic-gate FAST_INTR_POP 118*843e1988Sjohnlev FAST_INTR_RETURN 1197c478bd9Sstevel@tonic-gate SET_SIZE(get_hrtime) 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate#endif /* __i386 */ 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate#if defined(__amd64) 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate .globl gethrestimef 1267c478bd9Sstevel@tonic-gate ENTRY_NP(get_hrestime) 1277c478bd9Sstevel@tonic-gate FAST_INTR_PUSH 1287c478bd9Sstevel@tonic-gate subq $TIMESPEC_SIZE, %rsp 1297c478bd9Sstevel@tonic-gate movq %rsp, %rdi 1307c478bd9Sstevel@tonic-gate call *gethrestimef(%rip) 1317c478bd9Sstevel@tonic-gate movl (%rsp), %eax 1327c478bd9Sstevel@tonic-gate movl CLONGSIZE(%rsp), %edx 1337c478bd9Sstevel@tonic-gate addq $TIMESPEC_SIZE, %rsp 1347c478bd9Sstevel@tonic-gate FAST_INTR_POP 135*843e1988Sjohnlev FAST_INTR_RETURN 1367c478bd9Sstevel@tonic-gate SET_SIZE(get_hrestime) 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate#elif defined(__i386) 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate .globl gethrestimef 1417c478bd9Sstevel@tonic-gate ENTRY_NP(get_hrestime) 1427c478bd9Sstevel@tonic-gate FAST_INTR_PUSH 1437c478bd9Sstevel@tonic-gate subl $TIMESPEC_SIZE, %esp 1447c478bd9Sstevel@tonic-gate pushl %esp 1457c478bd9Sstevel@tonic-gate call *gethrestimef 1467c478bd9Sstevel@tonic-gate movl _CONST(4 + 0)(%esp), %eax 1477c478bd9Sstevel@tonic-gate movl _CONST(4 + CLONGSIZE)(%esp), %edx 1487c478bd9Sstevel@tonic-gate addl $_CONST(4 + TIMESPEC_SIZE), %esp 1497c478bd9Sstevel@tonic-gate FAST_INTR_POP 150*843e1988Sjohnlev FAST_INTR_RETURN 1517c478bd9Sstevel@tonic-gate SET_SIZE(get_hrestime) 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate#endif /* __i386 */ 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate#if defined(__amd64) 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate ENTRY_NP(gethrvtime) 1587c478bd9Sstevel@tonic-gate FAST_INTR_PUSH 1597c478bd9Sstevel@tonic-gate call gethrtime_unscaled /* get time since boot */ 1607c478bd9Sstevel@tonic-gate movq %gs:CPU_LWP, %rcx /* current lwp */ 1617c478bd9Sstevel@tonic-gate subq LWP_MS_STATE_START(%rcx), %rax /* - ms->ms_state_start */ 1627c478bd9Sstevel@tonic-gate addq LWP_ACCT_USER(%rcx), %rax /* add ms->ms_acct[LMS_USER] */ 1637c478bd9Sstevel@tonic-gate subq $16, %rsp 1647c478bd9Sstevel@tonic-gate movq %rax, (%rsp) 1657c478bd9Sstevel@tonic-gate movq %rsp, %rdi 1667c478bd9Sstevel@tonic-gate call scalehrtime 1677c478bd9Sstevel@tonic-gate movq (%rsp), %rax 1687c478bd9Sstevel@tonic-gate addq $16, %rsp 1697c478bd9Sstevel@tonic-gate movq %rax, %rdx 1707c478bd9Sstevel@tonic-gate shrq $32, %rdx /* high 32-bit in %rdx */ 1717c478bd9Sstevel@tonic-gate FAST_INTR_POP 172*843e1988Sjohnlev FAST_INTR_RETURN 1737c478bd9Sstevel@tonic-gate SET_SIZE(gethrvtime) 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate#elif defined(__i386) 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate ENTRY_NP(gethrvtime) 1787c478bd9Sstevel@tonic-gate FAST_INTR_PUSH 1797c478bd9Sstevel@tonic-gate call gethrtime_unscaled /* get time since boot */ 1807c478bd9Sstevel@tonic-gate movl %gs:CPU_LWP, %ecx /* current lwp */ 1817c478bd9Sstevel@tonic-gate subl LWP_MS_STATE_START(%ecx), %eax /* - ms->ms_state_start */ 1827c478bd9Sstevel@tonic-gate sbbl LWP_MS_STATE_START+4(%ecx), %edx 1837c478bd9Sstevel@tonic-gate addl LWP_ACCT_USER(%ecx), %eax /* add ms->ms_acct[LMS_USER] */ 1847c478bd9Sstevel@tonic-gate adcl LWP_ACCT_USER+4(%ecx), %edx 1857c478bd9Sstevel@tonic-gate subl $0x8, %esp 1867c478bd9Sstevel@tonic-gate leal (%esp), %ecx 1877c478bd9Sstevel@tonic-gate movl %eax, (%ecx) 1887c478bd9Sstevel@tonic-gate movl %edx, 4(%ecx) 1897c478bd9Sstevel@tonic-gate pushl %ecx 1907c478bd9Sstevel@tonic-gate call scalehrtime 1917c478bd9Sstevel@tonic-gate popl %ecx 1927c478bd9Sstevel@tonic-gate movl (%ecx), %eax 1937c478bd9Sstevel@tonic-gate movl 4(%ecx), %edx 1947c478bd9Sstevel@tonic-gate addl $0x8, %esp 1957c478bd9Sstevel@tonic-gate FAST_INTR_POP 196*843e1988Sjohnlev FAST_INTR_RETURN 1977c478bd9Sstevel@tonic-gate SET_SIZE(gethrvtime) 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate#endif /* __i386 */ 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate#if defined(__amd64) 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate ENTRY_NP(getlgrp) 2047c478bd9Sstevel@tonic-gate FAST_INTR_PUSH 2057c478bd9Sstevel@tonic-gate movq %gs:CPU_THREAD, %rcx 2067c478bd9Sstevel@tonic-gate movq T_LPL(%rcx), %rcx 2077c478bd9Sstevel@tonic-gate movl LPL_LGRPID(%rcx), %edx 2087c478bd9Sstevel@tonic-gate movl %gs:CPU_ID, %eax 2097c478bd9Sstevel@tonic-gate FAST_INTR_POP 210*843e1988Sjohnlev FAST_INTR_RETURN 2117c478bd9Sstevel@tonic-gate SET_SIZE(getlgrp) 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate#elif defined(__i386) 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate ENTRY_NP(getlgrp) 2167c478bd9Sstevel@tonic-gate FAST_INTR_PUSH 2177c478bd9Sstevel@tonic-gate movl %gs:CPU_THREAD, %ecx 2187c478bd9Sstevel@tonic-gate movl T_LPL(%ecx), %ecx 2197c478bd9Sstevel@tonic-gate movl LPL_LGRPID(%ecx), %edx 2207c478bd9Sstevel@tonic-gate movl %gs:CPU_ID, %eax 2217c478bd9Sstevel@tonic-gate FAST_INTR_POP 222*843e1988Sjohnlev FAST_INTR_RETURN 2237c478bd9Sstevel@tonic-gate SET_SIZE(getlgrp) 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate#endif /* __i386 */ 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate#endif /* __lint */ 228