2 * Copyright (c) 2000-2005 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@
24 #include <i386/proc_reg.h>
25 #include <i386/eflags.h>
27 #include <i386/postcode.h>
28 #include <i386/apic.h>
31 #define PA(addr) (addr)
32 #define VA(addr) (addr)
35 * GAS won't handle an intersegment jump with a relocatable offset.
37 #define LJMP(segment,address) \
45 ** Entry - %esp contains pointer to 64 bit structure.
47 ** Exit - 64 bit structure filled in.
50 ENTRY(ml_get_timebase)
63 * Convert between various timer units
65 * uint64_t tmrCvt(uint64_t time, uint64_t *conversion)
67 * This code converts 64-bit time units to other units.
68 * For example, the TSC is converted to HPET units.
70 * Time is a 64-bit integer that is some number of ticks.
71 * Conversion is 64-bit fixed point number which is composed
72 * of a 32 bit integer and a 32 bit fraction.
74 * The time ticks are multiplied by the conversion factor. The
75 * calculations are done as a 128-bit value but both the high
76 * and low words are dropped. The high word is overflow and the
77 * low word is the fraction part of the result.
79 * We return a 64-bit value.
81 * Note that we can use this function to multiply 2 conversion factors.
82 * We do this in order to calculate the multiplier used to convert
83 * directly between any two units.
92 pushl %ebp // Save a volatile
93 movl %esp,%ebp // Get the parameters - 8
94 pushl %ebx // Save a volatile
95 pushl %esi // Save a volatile
96 pushl %edi // Save a volatile
98 // %ebp + 8 - low-order ts
99 // %ebp + 12 - high-order ts
100 // %ebp + 16 - low-order cvt
101 // %ebp + 20 - high-order cvt
103 movl 8(%ebp),%eax // Get low-order ts
104 mull 16(%ebp) // Multiply by low-order conversion
105 movl %edx,%edi // Need to save only the high order part
107 movl 12(%ebp),%eax // Get the high-order ts
108 mull 16(%ebp) // Multiply by low-order conversion
109 addl %eax,%edi // Add in the overflow from the low x low calculation
110 adcl $0,%edx // Add in any overflow to high high part
111 movl %edx,%esi // Save high high part
113 // We now have the upper 64 bits of the 96 bit multiply of ts and the low half of cvt
116 movl 8(%ebp),%eax // Get low-order ts
117 mull 20(%ebp) // Multiply by high-order conversion
118 movl %eax,%ebx // Need to save the low order part
119 movl %edx,%ecx // Need to save the high order part
121 movl 12(%ebp),%eax // Get the high-order ts
122 mull 20(%ebp) // Multiply by high-order conversion
124 // Now have %ecx:%ebx as low part of high low and %edx:%eax as high part of high high
125 // We don't care about the highest word since it is overflow
127 addl %edi,%ebx // Add the low words
128 adcl %ecx,%esi // Add in the high plus carry from low
129 addl %eax,%esi // Add in the rest of the high
131 movl %ebx,%eax // Pass back low word
132 movl %esi,%edx // and the high word
134 popl %edi // Restore a volatile
135 popl %esi // Restore a volatile
136 popl %ebx // Restore a volatile
137 popl %ebp // Restore a volatile
141 .globl EXT(rtc_nanotime_store)
144 LEXT(rtc_nanotime_store)
151 mov %eax,RNT_TSC_BASE(%edx)
153 mov %eax,RNT_TSC_BASE+4(%edx)
156 mov %eax,RNT_SCALE(%edx)
159 mov %eax,RNT_SHIFT(%edx)
162 mov %eax,RNT_NS_BASE(%edx)
164 mov %eax,RNT_NS_BASE+4(%edx)
169 .globl EXT(rtc_nanotime_load)
172 LEXT(rtc_nanotime_load)
179 mov RNT_TSC_BASE(%ecx),%eax
180 mov %eax,RNT_TSC_BASE(%edx)
181 mov RNT_TSC_BASE+4(%ecx),%eax
182 mov %eax,RNT_TSC_BASE+4(%edx)
184 mov RNT_SCALE(%ecx),%eax
185 mov %eax,RNT_SCALE(%edx)
187 mov RNT_SHIFT(%ecx),%eax
188 mov %eax,RNT_SHIFT(%edx)
190 mov RNT_NS_BASE(%ecx),%eax
191 mov %eax,RNT_NS_BASE(%edx)
192 mov RNT_NS_BASE+4(%ecx),%eax
193 mov %eax,RNT_NS_BASE+4(%edx)