]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/machine_routines_asm.s
xnu-792.22.5.tar.gz
[apple/xnu.git] / osfmk / i386 / machine_routines_asm.s
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_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 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.
14 *
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
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #include <i386/asm.h>
30 #include <i386/proc_reg.h>
31 #include <i386/eflags.h>
32
33 #include <i386/postcode.h>
34 #include <i386/apic.h>
35 #include <assym.s>
36
37 #define PA(addr) (addr)
38 #define VA(addr) (addr)
39
40 /*
41 * GAS won't handle an intersegment jump with a relocatable offset.
42 */
43 #define LJMP(segment,address) \
44 .byte 0xea ;\
45 .long address ;\
46 .word segment
47
48 /*
49 ** ml_get_timebase()
50 **
51 ** Entry - %esp contains pointer to 64 bit structure.
52 **
53 ** Exit - 64 bit structure filled in.
54 **
55 */
56 ENTRY(ml_get_timebase)
57
58 movl S_ARG0, %ecx
59
60 rdtsc
61
62 movl %edx, 0(%ecx)
63 movl %eax, 4(%ecx)
64
65 ret
66
67
68 /*
69 * Convert between various timer units
70 *
71 * uint64_t tmrCvt(uint64_t time, uint64_t *conversion)
72 *
73 * This code converts 64-bit time units to other units.
74 * For example, the TSC is converted to HPET units.
75 *
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.
79 *
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.
84 *
85 * We return a 64-bit value.
86 *
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.
90 *
91 */
92
93 .globl EXT(tmrCvt)
94 .align FALIGN
95
96 LEXT(tmrCvt)
97
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
103
104 // %ebp + 8 - low-order ts
105 // %ebp + 12 - high-order ts
106 // %ebp + 16 - low-order cvt
107 // %ebp + 20 - high-order cvt
108
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
112
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
118
119 // We now have the upper 64 bits of the 96 bit multiply of ts and the low half of cvt
120 // in %esi:%edi
121
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
126
127 movl 12(%ebp),%eax // Get the high-order ts
128 mull 20(%ebp) // Multiply by high-order conversion
129
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
132
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
136
137 movl %ebx,%eax // Pass back low word
138 movl %esi,%edx // and the high word
139
140 popl %edi // Restore a volatile
141 popl %esi // Restore a volatile
142 popl %ebx // Restore a volatile
143 popl %ebp // Restore a volatile
144
145 ret // Leave...
146
147 .globl EXT(rtc_nanotime_store)
148 .align FALIGN
149
150 LEXT(rtc_nanotime_store)
151 push %ebp
152 mov %esp,%ebp
153
154 mov 32(%ebp),%edx
155
156 mov 8(%ebp),%eax
157 mov %eax,RNT_TSC_BASE(%edx)
158 mov 12(%ebp),%eax
159 mov %eax,RNT_TSC_BASE+4(%edx)
160
161 mov 24(%ebp),%eax
162 mov %eax,RNT_SCALE(%edx)
163
164 mov 28(%ebp),%eax
165 mov %eax,RNT_SHIFT(%edx)
166
167 mov 16(%ebp),%eax
168 mov %eax,RNT_NS_BASE(%edx)
169 mov 20(%ebp),%eax
170 mov %eax,RNT_NS_BASE+4(%edx)
171
172 pop %ebp
173 ret
174
175 .globl EXT(rtc_nanotime_load)
176 .align FALIGN
177
178 LEXT(rtc_nanotime_load)
179 push %ebp
180 mov %esp,%ebp
181
182 mov 8(%ebp),%ecx
183 mov 12(%ebp),%edx
184
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)
189
190 mov RNT_SCALE(%ecx),%eax
191 mov %eax,RNT_SCALE(%edx)
192
193 mov RNT_SHIFT(%ecx),%eax
194 mov %eax,RNT_SHIFT(%edx)
195
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)
200
201 pop %ebp
202 ret