]>
Commit | Line | Data |
---|---|---|
6601e61a | 1 | /* |
6d2010ae | 2 | * Copyright (c) 2010 Apple Inc. All rights reserved. |
6601e61a | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
6601e61a | 5 | * |
2d21ac55 A |
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. | |
6601e61a | 14 | * |
2d21ac55 A |
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 | |
6601e61a A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
6601e61a | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
6601e61a A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
0c530ab8 A |
31 | /* |
32 | * @APPLE_FREE_COPYRIGHT@ | |
33 | */ | |
34 | /* | |
6d2010ae A |
35 | * File: rtclock_asm_native.h |
36 | * Purpose: Native routines for reading nanotime | |
0c530ab8 A |
37 | */ |
38 | ||
6d2010ae A |
39 | #ifndef _PAL_RTCLOCK_ASM_NATIVE_H_ |
40 | #define _PAL_RTCLOCK_ASM_NATIVE_H_ | |
0c530ab8 | 41 | |
593a1d5f A |
42 | |
43 | #if defined(__i386__) | |
44 | /* | |
45 | * Assembly snippet included in exception handlers and rtc_nanotime_read() | |
46 | * %edi points to nanotime info struct | |
47 | * %edx:%eax returns nanotime | |
48 | */ | |
6d2010ae | 49 | #define PAL_RTC_NANOTIME_READ_FAST() \ |
593a1d5f A |
50 | 0: movl RNT_GENERATION(%edi),%esi /* being updated? */ ; \ |
51 | testl %esi,%esi ; \ | |
52 | jz 0b /* wait until done */ ; \ | |
c910b4d9 | 53 | lfence ; \ |
593a1d5f A |
54 | rdtsc ; \ |
55 | lfence ; \ | |
56 | subl RNT_TSC_BASE(%edi),%eax ; \ | |
57 | sbbl RNT_TSC_BASE+4(%edi),%edx /* tsc - tsc_base */ ; \ | |
58 | movl RNT_SCALE(%edi),%ecx /* * scale factor */ ; \ | |
59 | movl %edx,%ebx ; \ | |
60 | mull %ecx ; \ | |
61 | movl %ebx,%eax ; \ | |
62 | movl %edx,%ebx ; \ | |
63 | mull %ecx ; \ | |
64 | addl %ebx,%eax ; \ | |
65 | adcl $0,%edx ; \ | |
66 | addl RNT_NS_BASE(%edi),%eax /* + ns_base */ ; \ | |
67 | adcl RNT_NS_BASE+4(%edi),%edx ; \ | |
68 | cmpl RNT_GENERATION(%edi),%esi /* check for update */ ; \ | |
69 | jne 0b /* do it all again */ | |
70 | ||
71 | #elif defined(__x86_64__) | |
72 | ||
73 | /* | |
74 | * Assembly snippet included in exception handlers and rtc_nanotime_read() | |
75 | * %rdi points to nanotime info struct. | |
76 | * %rax returns nanotime | |
77 | */ | |
6d2010ae | 78 | #define PAL_RTC_NANOTIME_READ_FAST() \ |
593a1d5f | 79 | 0: movl RNT_GENERATION(%rdi),%esi ; \ |
6d2010ae A |
80 | test %esi,%esi /* info updating? */ ; \ |
81 | jz 0b /* - wait if so */ ; \ | |
c910b4d9 | 82 | lfence ; \ |
593a1d5f A |
83 | rdtsc ; \ |
84 | lfence ; \ | |
85 | shlq $32,%rdx ; \ | |
86 | orq %rdx,%rax /* %rax := tsc */ ; \ | |
87 | subq RNT_TSC_BASE(%rdi),%rax /* tsc - tsc_base */ ; \ | |
88 | xorq %rcx,%rcx ; \ | |
89 | movl RNT_SCALE(%rdi),%ecx ; \ | |
90 | mulq %rcx /* delta * scale */ ; \ | |
91 | shrdq $32,%rdx,%rax /* %rdx:%rax >>= 32 */ ; \ | |
92 | addq RNT_NS_BASE(%rdi),%rax /* add ns_base */ ; \ | |
93 | cmpl RNT_GENERATION(%rdi),%esi /* repeat if changed */ ; \ | |
94 | jne 0b | |
95 | ||
6d2010ae A |
96 | #endif /* !defined(x86_64) */ |
97 | ||
593a1d5f | 98 | |
6d2010ae | 99 | #endif /* _PAL_RTCLOCK_ASM_NATIVE_H_ */ |