xref: /xnu-8796.121.2/libsyscall/custom/__gettimeofday.s (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1*c54f35caSApple OSS Distributions/*
2*c54f35caSApple OSS Distributions * Copyright (c) 1999-2016 Apple Inc. All rights reserved.
3*c54f35caSApple OSS Distributions *
4*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*c54f35caSApple OSS Distributions *
6*c54f35caSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*c54f35caSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*c54f35caSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*c54f35caSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*c54f35caSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*c54f35caSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*c54f35caSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*c54f35caSApple OSS Distributions * terms of an Apple operating system software license agreement.
14*c54f35caSApple OSS Distributions *
15*c54f35caSApple OSS Distributions * Please obtain a copy of the License at
16*c54f35caSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*c54f35caSApple OSS Distributions *
18*c54f35caSApple OSS Distributions * The Original Code and all software distributed under the License are
19*c54f35caSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*c54f35caSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*c54f35caSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*c54f35caSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*c54f35caSApple OSS Distributions * Please see the License for the specific language governing rights and
24*c54f35caSApple OSS Distributions * limitations under the License.
25*c54f35caSApple OSS Distributions *
26*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*c54f35caSApple OSS Distributions */
28*c54f35caSApple OSS Distributions
29*c54f35caSApple OSS Distributions#include "SYS.h"
30*c54f35caSApple OSS Distributions
31*c54f35caSApple OSS Distributions/*
32*c54f35caSApple OSS Distributions * A third argument, of type uint64_t*, was added to the gettimeofday syscall
33*c54f35caSApple OSS Distributions * for use cases that also want to know the mach_absolute_time that matches the
34*c54f35caSApple OSS Distributions * time value returned.
35*c54f35caSApple OSS Distributions *
36*c54f35caSApple OSS Distributions * __gettimeofday takes the traditional two arguments.  It will zero out the
37*c54f35caSApple OSS Distributions * third argument argument before entering the kernel, behaving like the old
38*c54f35caSApple OSS Distributions * call.
39*c54f35caSApple OSS Distributions *
40*c54f35caSApple OSS Distributions * __gettimeofday_with_mach will pass it through and supporting kernels will
41*c54f35caSApple OSS Distributions * copy-out the mach_absolute_time.  Old kernels will leave the pointed to
42*c54f35caSApple OSS Distributions * value alone.
43*c54f35caSApple OSS Distributions */
44*c54f35caSApple OSS Distributions
45*c54f35caSApple OSS Distributions.private_extern ___gettimeofday_with_mach
46*c54f35caSApple OSS Distributions
47*c54f35caSApple OSS Distributions#if defined(__i386__)
48*c54f35caSApple OSS Distributions
49*c54f35caSApple OSS DistributionsLABEL(___gettimeofday)
50*c54f35caSApple OSS Distributions    pushl	$0
51*c54f35caSApple OSS Distributions    pushl	12(%esp)
52*c54f35caSApple OSS Distributions    pushl	12(%esp)
53*c54f35caSApple OSS Distributions    calll	___gettimeofday_with_mach
54*c54f35caSApple OSS Distributions    addl	$12, %esp
55*c54f35caSApple OSS Distributions    ret
56*c54f35caSApple OSS Distributions
57*c54f35caSApple OSS DistributionsLABEL(___gettimeofday_with_mach)
58*c54f35caSApple OSS Distributions    UNIX_SYSCALL_INT_NONAME(gettimeofday,0)
59*c54f35caSApple OSS Distributions    /*
60*c54f35caSApple OSS Distributions     * <rdar://problem/26410029>
61*c54f35caSApple OSS Distributions     * If eax is 0, we're on a new kernel and timeval was written by the kernel.
62*c54f35caSApple OSS Distributions     * Otherwise, eax:edx contains the timeval and we marshal into timeval.
63*c54f35caSApple OSS Distributions     */
64*c54f35caSApple OSS Distributions    cmp     $0, %eax
65*c54f35caSApple OSS Distributions    je      2f
66*c54f35caSApple OSS Distributions    mov     4(%esp),%ecx
67*c54f35caSApple OSS Distributions    mov     %eax,(%ecx)
68*c54f35caSApple OSS Distributions    mov     %edx,4(%ecx)
69*c54f35caSApple OSS Distributions    xor     %eax,%eax
70*c54f35caSApple OSS Distributions2:
71*c54f35caSApple OSS Distributions    ret
72*c54f35caSApple OSS Distributions
73*c54f35caSApple OSS Distributions#elif defined(__x86_64__)
74*c54f35caSApple OSS Distributions
75*c54f35caSApple OSS Distributions__SYSCALL(___gettimeofday_with_mach, gettimeofday, 3)
76*c54f35caSApple OSS Distributions
77*c54f35caSApple OSS DistributionsLABEL(___gettimeofday)
78*c54f35caSApple OSS Distributions    movq   $0x0, %rdx // zero out third argument
79*c54f35caSApple OSS Distributions
80*c54f35caSApple OSS Distributions    UNIX_SYSCALL_NONAME(gettimeofday,0,cerror_nocancel)
81*c54f35caSApple OSS Distributions    /*
82*c54f35caSApple OSS Distributions     * <rdar://problem/26410029>
83*c54f35caSApple OSS Distributions     * If rax is 0, we're on a new kernel and timeval was written by the kernel.
84*c54f35caSApple OSS Distributions     * Otherwise, rax:rdx contains the timeval and we marshal into timeval.
85*c54f35caSApple OSS Distributions     */
86*c54f35caSApple OSS Distributions    cmp     $0, %rax
87*c54f35caSApple OSS Distributions    je      2f
88*c54f35caSApple OSS Distributions    movq    %rax, (%rdi)
89*c54f35caSApple OSS Distributions    movl    %edx, 8(%rdi)
90*c54f35caSApple OSS Distributions    xorl    %eax, %eax
91*c54f35caSApple OSS Distributions2:
92*c54f35caSApple OSS Distributions    ret
93*c54f35caSApple OSS Distributions
94*c54f35caSApple OSS Distributions#elif defined(__arm__)
95*c54f35caSApple OSS Distributions
96*c54f35caSApple OSS Distributions__SYSCALL2(___gettimeofday_with_mach, gettimeofday, 3, cerror_nocancel)
97*c54f35caSApple OSS Distributions
98*c54f35caSApple OSS Distributions.text
99*c54f35caSApple OSS Distributions.align  2
100*c54f35caSApple OSS Distributions.globl ___gettimeofday
101*c54f35caSApple OSS Distributions___gettimeofday:
102*c54f35caSApple OSS Distributions    mov    r2, #0x0
103*c54f35caSApple OSS Distributions    SYSCALL_NONAME(gettimeofday, 3, cerror_nocancel)
104*c54f35caSApple OSS Distributions    bx lr
105*c54f35caSApple OSS Distributions
106*c54f35caSApple OSS Distributions#elif defined(__arm64__)
107*c54f35caSApple OSS Distributions
108*c54f35caSApple OSS Distributions__SYSCALL2(___gettimeofday_with_mach, gettimeofday, 3, cerror_nocancel)
109*c54f35caSApple OSS Distributions
110*c54f35caSApple OSS Distributions.text
111*c54f35caSApple OSS Distributions.align  2
112*c54f35caSApple OSS Distributions.globl ___gettimeofday
113*c54f35caSApple OSS Distributions___gettimeofday:
114*c54f35caSApple OSS Distributions    movz   x2, #0x0
115*c54f35caSApple OSS Distributions    SYSCALL_NONAME(gettimeofday, 3, cerror_nocancel)
116*c54f35caSApple OSS Distributions    ret
117*c54f35caSApple OSS Distributions
118*c54f35caSApple OSS Distributions#else
119*c54f35caSApple OSS Distributions#error Unsupported architecture
120*c54f35caSApple OSS Distributions#endif
121