]>
Commit | Line | Data |
---|---|---|
1f2f436a A |
1 | /* |
2 | * Copyright (c) 2003-2007 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #include <sys/appleapiopts.h> | |
30 | #include <machine/cpu_capabilities.h> | |
31 | ||
32 | /* | |
33 | * 64-bit version _mach_absolute_time. We return the 64-bit nanotime in %rax, | |
34 | */ | |
35 | .globl _mach_absolute_time | |
36 | _mach_absolute_time: | |
37 | pushq %rbp // set up a frame for backtraces | |
38 | movq %rsp,%rbp | |
39 | movq $(_COMM_PAGE_TIME_DATA_START),%rsi | |
40 | 1: | |
41 | movl _NT_GENERATION(%rsi),%r8d // get generation | |
42 | testl %r8d,%r8d // if 0, data is being changed... | |
43 | jz 1b // ...so loop until stable | |
44 | lfence | |
45 | rdtsc // edx:eax := tsc | |
46 | lfence | |
47 | shlq $32,%rdx // rax := ((edx << 32) | eax), ie 64-bit tsc | |
48 | orq %rdx,%rax | |
49 | subq _NT_TSC_BASE(%rsi), %rax // rax := (tsc - base_tsc) | |
50 | movl _NT_SCALE(%rsi),%ecx | |
51 | mulq %rcx // rdx:rax := (tsc - base_tsc) * scale | |
52 | shrdq $32,%rdx,%rax // _COMM_PAGE_NT_SHIFT is always 32 | |
53 | addq _NT_NS_BASE(%rsi),%rax // (((tsc - base_tsc) * scale) >> 32) + ns_base | |
54 | ||
55 | cmpl _NT_GENERATION(%rsi),%r8d // did the data change during computation? | |
56 | jne 1b | |
57 | popq %rbp | |
58 | ret |