2 * Copyright (c) 2003-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <sys/appleapiopts.h>
24 #include <machine/cpu_capabilities.h>
25 #include <machine/commpage.h>
37 COMMPAGE_DESCRIPTOR(mach_absolute_time,_COMM_PAGE_ABSOLUTE_TIME,0,0)
39 /* Nanotime is being moved out of the way of bcopy in the commpage.
40 * First we put it in both places, old and new. Then, when all the build
41 * trains have rebuilt libSystem, we can remove the deprecated instance.
44 /* return nanotime in %edx:%eax */
54 mov _COMM_PAGE_NT_TSC_BASE,%esi
55 mov _COMM_PAGE_NT_TSC_BASE+4,%edi
61 mov _COMM_PAGE_NT_SCALE,%ecx
71 add _COMM_PAGE_NT_NS_BASE,%eax
72 adc _COMM_PAGE_NT_NS_BASE+4,%edx
74 cmp _COMM_PAGE_NT_TSC_BASE,%esi
76 cmp _COMM_PAGE_NT_TSC_BASE+4,%edi
85 COMMPAGE_DESCRIPTOR(nanotime,_COMM_PAGE_NANOTIME,0,0)
86 COMMPAGE_DESCRIPTOR(old_nanotime,_COMM_PAGE_OLD_NANOTIME,0,0)
89 /* The 64-bit version. We return the 64-bit nanotime in %rax,
90 * and by convention we must preserve %r9, %r10, and %r11.
96 Lnanotime_64: // NB: must preserve r9, r10, and r11
97 pushq %rbp // set up a frame for backtraces
99 movq $_COMM_PAGE_32_TO_64(_COMM_PAGE_NT_TSC_BASE),%rsi
101 movq _NT_TSC_BASE(%rsi),%r8 // r8 := base_tsc
102 rdtsc // edx:eax := tsc
103 shlq $32,%rdx // rax := ((edx << 32) | eax), ie 64-bit tsc
105 subq %r8, %rax // rax := (tsc - base_tsc)
106 movl _NT_SCALE(%rsi),%ecx
107 mulq %rcx // rdx:rax := (tsc - base_tsc) * scale
108 shrdq $32,%rdx,%rax // _COMM_PAGE_NT_SHIFT is always 32
109 addq _NT_NS_BASE(%rsi),%rax // (((tsc - base_tsc) * scale) >> 32) + ns_base
111 cmpq _NT_TSC_BASE(%rsi),%r8 // did the data change during computation?
116 COMMPAGE_DESCRIPTOR(nanotime_64,_COMM_PAGE_NANOTIME,0,0)
117 COMMPAGE_DESCRIPTOR(old_nanotime_64,_COMM_PAGE_OLD_NANOTIME,0,0)