xref: /illumos-gate/usr/src/lib/libc/sparc/sys/gettimeofday.S (revision 55fea89dcaa64928bed4327112404dcb3e07b79f)
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/*
23*5d9d9091SRichard Lowe * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*5d9d9091SRichard Lowe * Use is subject to license terms.
25*5d9d9091SRichard Lowe */
26*5d9d9091SRichard Lowe
27*5d9d9091SRichard Lowe/*	Copyright (c) 1988 AT&T	*/
28*5d9d9091SRichard Lowe/*	  All Rights Reserved	*/
29*5d9d9091SRichard Lowe
30*5d9d9091SRichard Lowe	.file	"gettimeofday.s"
31*5d9d9091SRichard Lowe
32*5d9d9091SRichard Lowe/*
33*5d9d9091SRichard Lowe * C library -- gettimeofday
34*5d9d9091SRichard Lowe * int gettimeofday (struct timeval *tp);
35*5d9d9091SRichard Lowe */
36*5d9d9091SRichard Lowe
37*5d9d9091SRichard Lowe#include "SYS.h"
38*5d9d9091SRichard Lowe
39*5d9d9091SRichard Lowe	ANSI_PRAGMA_WEAK(gettimeofday,function)
40*5d9d9091SRichard Lowe
41*5d9d9091SRichard Lowe/*
42*5d9d9091SRichard Lowe * The interface below calls the trap (0x27) to get the timestamp in
43*5d9d9091SRichard Lowe * secs and nsecs. It than converts the nsecs value into usecs before
44*5d9d9091SRichard Lowe * it returns.
45*5d9d9091SRichard Lowe *
46*5d9d9091SRichard Lowe * The algorithm used to perform the division by 1000 is based upon
47*5d9d9091SRichard Lowe * algorithms for division based upon multiplication by invariant
48*5d9d9091SRichard Lowe * integers.  Relevant sources for these algorithms are:
49*5d9d9091SRichard Lowe *
50*5d9d9091SRichard Lowe * Granlund, T.; Montgomery, P.L.: "Division by Invariant Integers using
51*5d9d9091SRichard Lowe * Multiplication". SIGPLAN Notices, Vol. 29, June 1994, page 61.
52*5d9d9091SRichard Lowe *
53*5d9d9091SRichard Lowe * Magenheimer, D.J.; et al: "Integer Multiplication and Division on the HP
54*5d9d9091SRichard Lowe * Precision Architecture". IEEE Transactions on Computers, Vol 37, No. 8,
55*5d9d9091SRichard Lowe * August 1988, page 980.
56*5d9d9091SRichard Lowe *
57*5d9d9091SRichard Lowe * Steele G.; Warren H.: Hacker's Delight. 2002 Pearson Education, Ch 10
58*5d9d9091SRichard Lowe *
59*5d9d9091SRichard Lowe */
60*5d9d9091SRichard Lowe
61*5d9d9091SRichard Lowe	ENTRY(gettimeofday)
62*5d9d9091SRichard Lowe	brz,pn	%o0, 1f
63*5d9d9091SRichard Lowe	mov	%o0, %o5
64*5d9d9091SRichard Lowe	SYSFASTTRAP(GETHRESTIME)
65*5d9d9091SRichard Lowe	stn	%o0, [%o5]
66*5d9d9091SRichard Lowe	sethi	%hi(0x10624DD3), %o2
67*5d9d9091SRichard Lowe	or	%o2, %lo(0x10624DD3), %o2
68*5d9d9091SRichard Lowe	mulx	%o1, %o2, %o2
69*5d9d9091SRichard Lowe	srlx	%o2, 38, %o2
70*5d9d9091SRichard Lowe	stn	%o2, [%o5 + CLONGSIZE]
71*5d9d9091SRichard Lowe1:	RETC
72*5d9d9091SRichard Lowe	SET_SIZE(gettimeofday)
73