2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <i386/proc_reg.h>
31 #include <i386/eflags.h>
33 #include <i386/postcode.h>
34 #include <i386/apic.h>
37 #define PA(addr) (addr)
38 #define VA(addr) (addr)
41 * GAS won't handle an intersegment jump with a relocatable offset.
43 #define LJMP(segment,address) \
51 ** Entry - %esp contains pointer to 64 bit structure.
53 ** Exit - 64 bit structure filled in.
56 ENTRY(ml_get_timebase)
69 * Convert between various timer units
71 * uint64_t tmrCvt(uint64_t time, uint64_t *conversion)
73 * This code converts 64-bit time units to other units.
74 * For example, the TSC is converted to HPET units.
76 * Time is a 64-bit integer that is some number of ticks.
77 * Conversion is 64-bit fixed point number which is composed
78 * of a 32 bit integer and a 32 bit fraction.
80 * The time ticks are multiplied by the conversion factor. The
81 * calculations are done as a 128-bit value but both the high
82 * and low words are dropped. The high word is overflow and the
83 * low word is the fraction part of the result.
85 * We return a 64-bit value.
87 * Note that we can use this function to multiply 2 conversion factors.
88 * We do this in order to calculate the multiplier used to convert
89 * directly between any two units.
98 pushl %ebp // Save a volatile
99 movl %esp,%ebp // Get the parameters - 8
100 pushl %ebx // Save a volatile
101 pushl %esi // Save a volatile
102 pushl %edi // Save a volatile
104 // %ebp + 8 - low-order ts
105 // %ebp + 12 - high-order ts
106 // %ebp + 16 - low-order cvt
107 // %ebp + 20 - high-order cvt
109 movl 8(%ebp),%eax // Get low-order ts
110 mull 16(%ebp) // Multiply by low-order conversion
111 movl %edx,%edi // Need to save only the high order part
113 movl 12(%ebp),%eax // Get the high-order ts
114 mull 16(%ebp) // Multiply by low-order conversion
115 addl %eax,%edi // Add in the overflow from the low x low calculation
116 adcl $0,%edx // Add in any overflow to high high part
117 movl %edx,%esi // Save high high part
119 // We now have the upper 64 bits of the 96 bit multiply of ts and the low half of cvt
122 movl 8(%ebp),%eax // Get low-order ts
123 mull 20(%ebp) // Multiply by high-order conversion
124 movl %eax,%ebx // Need to save the low order part
125 movl %edx,%ecx // Need to save the high order part
127 movl 12(%ebp),%eax // Get the high-order ts
128 mull 20(%ebp) // Multiply by high-order conversion
130 // Now have %ecx:%ebx as low part of high low and %edx:%eax as high part of high high
131 // We don't care about the highest word since it is overflow
133 addl %edi,%ebx // Add the low words
134 adcl %ecx,%esi // Add in the high plus carry from low
135 addl %eax,%esi // Add in the rest of the high
137 movl %ebx,%eax // Pass back low word
138 movl %esi,%edx // and the high word
140 popl %edi // Restore a volatile
141 popl %esi // Restore a volatile
142 popl %ebx // Restore a volatile
143 popl %ebp // Restore a volatile
147 .globl EXT(rtc_nanotime_store)
150 LEXT(rtc_nanotime_store)
157 mov %eax,RNT_TSC_BASE(%edx)
159 mov %eax,RNT_TSC_BASE+4(%edx)
162 mov %eax,RNT_SCALE(%edx)
165 mov %eax,RNT_SHIFT(%edx)
168 mov %eax,RNT_NS_BASE(%edx)
170 mov %eax,RNT_NS_BASE+4(%edx)
175 .globl EXT(rtc_nanotime_load)
178 LEXT(rtc_nanotime_load)
185 mov RNT_TSC_BASE(%ecx),%eax
186 mov %eax,RNT_TSC_BASE(%edx)
187 mov RNT_TSC_BASE+4(%ecx),%eax
188 mov %eax,RNT_TSC_BASE+4(%edx)
190 mov RNT_SCALE(%ecx),%eax
191 mov %eax,RNT_SCALE(%edx)
193 mov RNT_SHIFT(%ecx),%eax
194 mov %eax,RNT_SHIFT(%edx)
196 mov RNT_NS_BASE(%ecx),%eax
197 mov %eax,RNT_NS_BASE(%edx)
198 mov RNT_NS_BASE+4(%ecx),%eax
199 mov %eax,RNT_NS_BASE+4(%edx)