]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/commpage/commpage_mach_absolute_time.s
xnu-792.13.8.tar.gz
[apple/xnu.git] / osfmk / i386 / commpage / commpage_mach_absolute_time.s
1 /*
2 * Copyright (c) 2003-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31 #include <sys/appleapiopts.h>
32 #include <machine/cpu_capabilities.h>
33 #include <machine/commpage.h>
34 #include <i386/asm.h>
35
36 #include <assym.s>
37
38 .text
39 .align 2, 0x90
40
41 Lmach_absolute_time:
42 int $0x3
43 ret
44
45 COMMPAGE_DESCRIPTOR(mach_absolute_time,_COMM_PAGE_ABSOLUTE_TIME,0,0)
46
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.
50 */
51
52 /* return nanotime in %edx:%eax */
53 Lold_nanotime:
54 Lnanotime:
55 push %ebp
56 mov %esp,%ebp
57 push %esi
58 push %edi
59 push %ebx
60
61 0:
62 mov _COMM_PAGE_NT_TSC_BASE,%esi
63 mov _COMM_PAGE_NT_TSC_BASE+4,%edi
64
65 rdtsc
66 sub %esi,%eax
67 sbb %edi,%edx
68
69 mov _COMM_PAGE_NT_SCALE,%ecx
70
71 mov %edx,%ebx
72 mull %ecx
73 mov %ebx,%eax
74 mov %edx,%ebx
75 mull %ecx
76 add %ebx,%eax
77 adc $0,%edx
78
79 add _COMM_PAGE_NT_NS_BASE,%eax
80 adc _COMM_PAGE_NT_NS_BASE+4,%edx
81
82 cmp _COMM_PAGE_NT_TSC_BASE,%esi
83 jne 0b
84 cmp _COMM_PAGE_NT_TSC_BASE+4,%edi
85 jne 0b
86
87 pop %ebx
88 pop %edi
89 pop %esi
90 pop %ebp
91 ret
92
93 COMMPAGE_DESCRIPTOR(nanotime,_COMM_PAGE_NANOTIME,0,0)
94 COMMPAGE_DESCRIPTOR(old_nanotime,_COMM_PAGE_OLD_NANOTIME,0,0)
95
96
97 /* The 64-bit version. We return the 64-bit nanotime in %rax,
98 * and by convention we must preserve %r9, %r10, and %r11.
99 */
100 .text
101 .align 2
102 .code64
103 Lold_nanotime_64:
104 Lnanotime_64: // NB: must preserve r9, r10, and r11
105 pushq %rbp // set up a frame for backtraces
106 movq %rsp,%rbp
107 movq $_COMM_PAGE_32_TO_64(_COMM_PAGE_NT_TSC_BASE),%rsi
108 1:
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
112 orq %rdx,%rax
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
118
119 cmpq _NT_TSC_BASE(%rsi),%r8 // did the data change during computation?
120 jne 1b
121 popq %rbp
122 ret
123
124 COMMPAGE_DESCRIPTOR(nanotime_64,_COMM_PAGE_NANOTIME,0,0)
125 COMMPAGE_DESCRIPTOR(old_nanotime_64,_COMM_PAGE_OLD_NANOTIME,0,0)