]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/machine_routines_asm.s
b017f473a41341e8d2b2b3c78429a46743f38a21
[apple/xnu.git] / osfmk / i386 / machine_routines_asm.s
1 /*
2 * Copyright (c) 2000-2005 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 <i386/asm.h>
24 #include <i386/proc_reg.h>
25 #include <i386/eflags.h>
26
27 #include <i386/postcode.h>
28 #include <i386/apic.h>
29 #include <assym.s>
30
31 #define PA(addr) (addr)
32 #define VA(addr) (addr)
33
34 /*
35 * GAS won't handle an intersegment jump with a relocatable offset.
36 */
37 #define LJMP(segment,address) \
38 .byte 0xea ;\
39 .long address ;\
40 .word segment
41
42 /*
43 ** ml_get_timebase()
44 **
45 ** Entry - %esp contains pointer to 64 bit structure.
46 **
47 ** Exit - 64 bit structure filled in.
48 **
49 */
50 ENTRY(ml_get_timebase)
51
52 movl S_ARG0, %ecx
53
54 rdtsc
55
56 movl %edx, 0(%ecx)
57 movl %eax, 4(%ecx)
58
59 ret
60
61
62 /*
63 * Convert between various timer units
64 *
65 * uint64_t tmrCvt(uint64_t time, uint64_t *conversion)
66 *
67 * This code converts 64-bit time units to other units.
68 * For example, the TSC is converted to HPET units.
69 *
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.
73 *
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.
78 *
79 * We return a 64-bit value.
80 *
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.
84 *
85 */
86
87 .globl EXT(tmrCvt)
88 .align FALIGN
89
90 LEXT(tmrCvt)
91
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
97
98 // %ebp + 8 - low-order ts
99 // %ebp + 12 - high-order ts
100 // %ebp + 16 - low-order cvt
101 // %ebp + 20 - high-order cvt
102
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
106
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
112
113 // We now have the upper 64 bits of the 96 bit multiply of ts and the low half of cvt
114 // in %esi:%edi
115
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
120
121 movl 12(%ebp),%eax // Get the high-order ts
122 mull 20(%ebp) // Multiply by high-order conversion
123
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
126
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
130
131 movl %ebx,%eax // Pass back low word
132 movl %esi,%edx // and the high word
133
134 popl %edi // Restore a volatile
135 popl %esi // Restore a volatile
136 popl %ebx // Restore a volatile
137 popl %ebp // Restore a volatile
138
139 ret // Leave...
140
141 .globl EXT(rtc_nanotime_store)
142 .align FALIGN
143
144 LEXT(rtc_nanotime_store)
145 push %ebp
146 mov %esp,%ebp
147
148 mov 32(%ebp),%edx
149
150 mov 8(%ebp),%eax
151 mov %eax,RNT_TSC_BASE(%edx)
152 mov 12(%ebp),%eax
153 mov %eax,RNT_TSC_BASE+4(%edx)
154
155 mov 24(%ebp),%eax
156 mov %eax,RNT_SCALE(%edx)
157
158 mov 28(%ebp),%eax
159 mov %eax,RNT_SHIFT(%edx)
160
161 mov 16(%ebp),%eax
162 mov %eax,RNT_NS_BASE(%edx)
163 mov 20(%ebp),%eax
164 mov %eax,RNT_NS_BASE+4(%edx)
165
166 pop %ebp
167 ret
168
169 .globl EXT(rtc_nanotime_load)
170 .align FALIGN
171
172 LEXT(rtc_nanotime_load)
173 push %ebp
174 mov %esp,%ebp
175
176 mov 8(%ebp),%ecx
177 mov 12(%ebp),%edx
178
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)
183
184 mov RNT_SCALE(%ecx),%eax
185 mov %eax,RNT_SCALE(%edx)
186
187 mov RNT_SHIFT(%ecx),%eax
188 mov %eax,RNT_SHIFT(%edx)
189
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)
194
195 pop %ebp
196 ret