]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/commpage/commpage_mach_absolute_time.s
71592ec0e6f683b02049336334ce6c17e3c5ffeb
[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_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <sys/appleapiopts.h>
24 #include <machine/cpu_capabilities.h>
25 #include <machine/commpage.h>
26 #include <i386/asm.h>
27
28 #include <assym.s>
29
30 .text
31 .align 2, 0x90
32
33 Lmach_absolute_time:
34 int $0x3
35 ret
36
37 COMMPAGE_DESCRIPTOR(mach_absolute_time,_COMM_PAGE_ABSOLUTE_TIME,0,0)
38
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.
42 */
43
44 /* return nanotime in %edx:%eax */
45 Lold_nanotime:
46 Lnanotime:
47 push %ebp
48 mov %esp,%ebp
49 push %esi
50 push %edi
51 push %ebx
52
53 0:
54 mov _COMM_PAGE_NT_TSC_BASE,%esi
55 mov _COMM_PAGE_NT_TSC_BASE+4,%edi
56
57 rdtsc
58 sub %esi,%eax
59 sbb %edi,%edx
60
61 mov _COMM_PAGE_NT_SCALE,%ecx
62
63 mov %edx,%ebx
64 mull %ecx
65 mov %ebx,%eax
66 mov %edx,%ebx
67 mull %ecx
68 add %ebx,%eax
69 adc $0,%edx
70
71 add _COMM_PAGE_NT_NS_BASE,%eax
72 adc _COMM_PAGE_NT_NS_BASE+4,%edx
73
74 cmp _COMM_PAGE_NT_TSC_BASE,%esi
75 jne 0b
76 cmp _COMM_PAGE_NT_TSC_BASE+4,%edi
77 jne 0b
78
79 pop %ebx
80 pop %edi
81 pop %esi
82 pop %ebp
83 ret
84
85 COMMPAGE_DESCRIPTOR(nanotime,_COMM_PAGE_NANOTIME,0,0)
86 COMMPAGE_DESCRIPTOR(old_nanotime,_COMM_PAGE_OLD_NANOTIME,0,0)
87
88
89 /* The 64-bit version. We return the 64-bit nanotime in %rax,
90 * and by convention we must preserve %r9, %r10, and %r11.
91 */
92 .text
93 .align 2
94 .code64
95 Lold_nanotime_64:
96 Lnanotime_64: // NB: must preserve r9, r10, and r11
97 pushq %rbp // set up a frame for backtraces
98 movq %rsp,%rbp
99 movq $_COMM_PAGE_32_TO_64(_COMM_PAGE_NT_TSC_BASE),%rsi
100 1:
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
104 orq %rdx,%rax
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
110
111 cmpq _NT_TSC_BASE(%rsi),%r8 // did the data change during computation?
112 jne 1b
113 popq %rbp
114 ret
115
116 COMMPAGE_DESCRIPTOR(nanotime_64,_COMM_PAGE_NANOTIME,0,0)
117 COMMPAGE_DESCRIPTOR(old_nanotime_64,_COMM_PAGE_OLD_NANOTIME,0,0)