2 * Copyright (c) 2003-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 #include <sys/appleapiopts.h>
32 #include <machine/cpu_capabilities.h>
33 #include <machine/commpage.h>
45 COMMPAGE_DESCRIPTOR(mach_absolute_time,_COMM_PAGE_ABSOLUTE_TIME,0,0)
47 /* Nanotime is being moved out of the way of bcopy in the commpage.
48 * First we put it in both places, old and new. Then, when all the build
49 * trains have rebuilt libSystem, we can remove the deprecated instance.
52 /* return nanotime in %edx:%eax */
62 mov _COMM_PAGE_NT_TSC_BASE,%esi
63 mov _COMM_PAGE_NT_TSC_BASE+4,%edi
69 mov _COMM_PAGE_NT_SCALE,%ecx
79 add _COMM_PAGE_NT_NS_BASE,%eax
80 adc _COMM_PAGE_NT_NS_BASE+4,%edx
82 cmp _COMM_PAGE_NT_TSC_BASE,%esi
84 cmp _COMM_PAGE_NT_TSC_BASE+4,%edi
93 COMMPAGE_DESCRIPTOR(nanotime,_COMM_PAGE_NANOTIME,0,0)
94 COMMPAGE_DESCRIPTOR(old_nanotime,_COMM_PAGE_OLD_NANOTIME,0,0)
97 /* The 64-bit version. We return the 64-bit nanotime in %rax,
98 * and by convention we must preserve %r9, %r10, and %r11.
104 Lnanotime_64: // NB: must preserve r9, r10, and r11
105 pushq %rbp // set up a frame for backtraces
107 movq $_COMM_PAGE_32_TO_64(_COMM_PAGE_NT_TSC_BASE),%rsi
109 movq _NT_TSC_BASE(%rsi),%r8 // r8 := base_tsc
110 rdtsc // edx:eax := tsc
111 shlq $32,%rdx // rax := ((edx << 32) | eax), ie 64-bit tsc
113 subq %r8, %rax // rax := (tsc - base_tsc)
114 movl _NT_SCALE(%rsi),%ecx
115 mulq %rcx // rdx:rax := (tsc - base_tsc) * scale
116 shrdq $32,%rdx,%rax // _COMM_PAGE_NT_SHIFT is always 32
117 addq _NT_NS_BASE(%rsi),%rax // (((tsc - base_tsc) * scale) >> 32) + ns_base
119 cmpq _NT_TSC_BASE(%rsi),%r8 // did the data change during computation?
124 COMMPAGE_DESCRIPTOR(nanotime_64,_COMM_PAGE_NANOTIME,0,0)
125 COMMPAGE_DESCRIPTOR(old_nanotime_64,_COMM_PAGE_OLD_NANOTIME,0,0)