]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/x86_64/munge.s
xnu-1699.22.73.tar.gz
[apple/xnu.git] / bsd / dev / x86_64 / munge.s
CommitLineData
b0d623f7
A
1/*
2 * Coyright (c) 2005-2008 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/*
30 * Syscall argument mungers.
31 *
32 * The data to be munged has been explicitly copied in to the argument area,
33 * and will be munged in place in the uu_arg[] array. Because of this, the
34 * functions all take the same arguments as their PPC equivalents, but the
35 * first argument is ignored. These mungers are for 32-bit app's syscalls,
36 * since 64-bit args are stored into the save area (which overlays the
37 * uu_args) in the order the syscall ABI calls for.
38 *
39 * The issue is that the incoming args are 32-bit, but we must expand
40 * them in place into 64-bit args, as if they were from a 64-bit process.
41 *
42 * There are several functions in this file. Each takes two parameters:
43 *
44 * void munge_XXXX(const void *regs, // %rdi
45 * void *uu_args); // %rsi
46 *
47 * The name of the function encodes the number and type of the parameters,
48 * as follows:
49 *
50 * w = a 32-bit value such as an int or a 32-bit ptr, that does not
51 * require sign extension. These are handled by zeroing a word
52 * of output, and copying a word from input to output.
53 *
54 * s = a 32-bit value such as a long, which must be sign-extended to
55 * a 64-bit long-long in the uu_args. These are handled by
56 * loading a word of input and sign extending it to a double,
57 * and storing two words of output.
58 *
59 * l = a 64-bit long-long. These are handled by copying two words
60 * of input to the output.
61 *
62 * For example, "munge_wls" takes a word, a long-long, and a word. This
63 * takes four words in the uu_arg[] area: the first word is in one, the
64 * long-long takes two, and the final word is in the fourth. We store six
65 * words: the low word is left in place, followed by a 0, followed by the
66 * two words of the long-long, followed by the low word and the sign extended
67 * high word of the preceeding low word.
68 *
69 * Because this is an in-place modification, we actually start at the end
70 * of uu_arg[] and work our way back to the beginning of the array.
71 *
72 * As you can see, we save a lot of code by collapsing mungers that are
73 * prefixes or suffixes of each other.
74 */
75#include <i386/asm.h>
76
77ENTRY(munge_w)
78 movl $0,4(%rsi)
79 ret
80
81ENTRY(munge_ww)
82 xorl %edx,%edx
83 jmp Lw2
84ENTRY(munge_www)
85 xorl %edx,%edx
86 jmp Lw3
87ENTRY(munge_wwww)
88 xorl %edx,%edx
89 jmp Lw4
90ENTRY(munge_wwwww)
91 xorl %edx,%edx
92 jmp Lw5
93ENTRY(munge_wwwwww)
94 xorl %edx,%edx
95 jmp Lw6
96ENTRY(munge_wwwwwww)
97 xorl %edx,%edx
98 jmp Lw7
99ENTRY(munge_wwwwwwww)
100 xorl %edx,%edx
101 movl 28(%rsi),%eax
102 movl %eax,56(%rsi)
103 movl %edx,60(%rsi)
104Lw7:
105 movl 24(%rsi),%eax
106 movl %eax,48(%rsi)
107 movl %edx,52(%rsi)
108Lw6:
109 movl 20(%rsi),%eax
110 movl %eax,40(%rsi)
111 movl %edx,44(%rsi)
112Lw5:
113 movl 16(%rsi),%eax
114 movl %eax,32(%rsi)
115 movl %edx,36(%rsi)
116Lw4:
117 movl 12(%rsi),%eax
118 movl %eax,24(%rsi)
119 movl %edx,28(%rsi)
120Lw3:
121 movl 8(%rsi),%eax
122 movl %eax,16(%rsi)
123 movl %edx,20(%rsi)
124Lw2:
125 movl 4(%rsi),%eax
126 movl %eax,8(%rsi)
127 movl %edx,12(%rsi)
128 movl %edx,4(%rsi)
129 ret
130
131
132Entry(munge_wl) /* Costs an extra w move to do this */
133ENTRY(munge_wlw)
134 xorl %edx,%edx
6d2010ae 135Lwlw:
b0d623f7
A
136 movl 12(%rsi),%eax
137 movl %eax,16(%rsi)
138 movl %edx,20(%rsi)
6d2010ae 139Lwl:
b0d623f7
A
140 movl 8(%rsi),%eax
141 movl %eax,12(%rsi)
142 movl 4(%rsi),%eax
143 movl %eax,8(%rsi)
6d2010ae 144
b0d623f7
A
145 movl %edx,4(%rsi)
146 ret
147
6d2010ae
A
148ENTRY(munge_wlwwwll)
149 xorl %edx,%edx
150Lwlwwwll:
151 movl 36(%rsi),%eax
152 movl %eax,52(%rsi)
153 movl 32(%rsi),%eax
154 movl %eax,48(%rsi)
155
156 movl 28(%rsi),%eax
157 movl %eax,44(%rsi)
158 movl 24(%rsi),%eax
159 movl %eax,40(%rsi)
160
161 movl 20(%rsi),%eax
162 movl %eax,32(%rsi)
163 movl %edx,36(%rsi)
164Lwlww:
165 movl 16(%rsi),%eax
166 movl %eax,24(%rsi)
167 movl %edx,28(%rsi)
168 jmp Lwlw
169
170ENTRY(munge_wlwwwllw)
171 xorl %edx,%edx
172 movl 40(%rsi),%eax
173 movl %eax,56(%rsi)
174 movl %edx,60(%rsi)
175 jmp Lwlwwwll
176
177ENTRY(munge_wlwwlwlw)
178 xorl %edx,%edx
179 movl 40(%rsi),%eax
180 movl %eax,56(%rsi)
181 movl %edx,60(%rsi)
182 movl 36(%rsi),%eax
183 movl %eax,52(%rsi)
184 movl 32(%rsi),%eax
185 movl %eax,48(%rsi)
186 movl 28(%rsi),%eax
187 movl %eax,40(%rsi)
188 movl %edx,44(%rsi)
189 movl 24(%rsi),%eax
190 movl %eax,36(%rsi)
191 movl 20(%rsi),%eax
192 movl %eax,32(%rsi)
193 jmp Lwlww
194
195
196ENTRY(munge_wllwwll)
197 xorl %edx,%edx
198
199 movl 40(%rsi),%eax //l
200 movl %eax,52(%rsi)
201 movl 36(%rsi),%eax
202 movl %eax,48(%rsi)
203 movl 32(%rsi),%eax //l
204 movl %eax,44(%rsi)
205 movl 28(%rsi),%eax
206 movl %eax,40(%rsi)
207 movl 24(%rsi),%eax //w
208 movl %eax,32(%rsi)
209 movl %edx,36(%rsi)
210 movl 20(%rsi),%eax //w
211 movl %eax,24(%rsi)
212 movl %edx,28(%rsi)
213 movl 16(%rsi),%eax //l
214 movl %eax,20(%rsi)
215 movl 12(%rsi),%eax
216 movl %eax,16(%rsi)
217
218 jmp Lwl
219
b0d623f7
A
220Entry(munge_wwwlw)
221 xorl %edx,%edx
222 movl 20(%rsi),%eax
223 movl %eax,32(%rsi)
224 movl %edx,36(%rsi)
225 jmp Lwwwl
226
227
228ENTRY(munge_wwwl)
229 xorl %edx,%edx
230Lwwwl:
231 movl 12(%rsi),%eax
232 movl %eax,24(%rsi)
233 movl 16(%rsi),%eax
234 movl %eax,28(%rsi)
235 jmp Lw3
236
237ENTRY(munge_wwwwlw)
238 xorl %edx,%edx
239 movl 24(%rsi),%eax
240 movl %eax,40(%rsi)
241 movl %edx,44(%rsi)
242 jmp Lwwwwl
243
244ENTRY(munge_wwwwl)
245 xorl %edx,%edx
246Lwwwwl:
247 movl 16(%rsi),%eax
248 movl %eax,32(%rsi)
249 movl 20(%rsi),%eax
250 movl %eax,36(%rsi)
251 jmp Lw4
252
253ENTRY(munge_wwwwwl)
254 xorl %edx,%edx
255 movl 20(%rsi),%eax
256 movl %eax,40(%rsi)
257 movl 24(%rsi),%eax
258 movl %eax,44(%rsi)
259 jmp Lw5
260
6d2010ae
A
261
262ENTRY(munge_wwwwwlww)
263 xorl %edx,%edx
264 movl 32(%rsi),%eax
265 movl %eax,56(%rsi)
266 movl %edx,60(%rsi)
267 movl 28(%rsi),%eax
268 movl %eax,48(%rsi)
269 movl %edx,52(%rsi)
270 movl 20(%rsi),%eax
271 movl %eax,40(%rsi)
272 movl 24(%rsi),%eax
273 movl %eax,44(%rsi)
274
275 jmp Lw5
276
277ENTRY(munge_wwwwwllw)
278 xorl %edx,%edx
279 movl 36(%rsi),%eax
280 movl %eax,56(%rsi)
281 movl %edx,60(%rsi)
282 movl 28(%rsi),%eax
283 movl %eax,48(%rsi)
284 movl 32(%rsi),%eax
285 movl %eax,52(%rsi)
286 movl 20(%rsi),%eax
287 movl %eax,40(%rsi)
288 movl 24(%rsi),%eax
289 movl %eax,44(%rsi)
290 jmp Lw5
291
292ENTRY(munge_wwwwwlll)
293 xorl %edx,%edx
294 movl 36(%rsi),%eax
295 movl %eax,56(%rsi)
296 movl 40(%rsi),%eax
297 movl %eax,60(%rsi)
298 movl 28(%rsi),%eax
299 movl %eax,48(%rsi)
300 movl 32(%rsi),%eax
301 movl %eax,52(%rsi)
302 movl 20(%rsi),%eax
303 movl %eax,40(%rsi)
304 movl 24(%rsi),%eax
305 movl %eax,44(%rsi)
306 jmp Lw5
307
308ENTRY(munge_wwwwwwl)
309 xorl %edx,%edx
310 movl 24(%rsi),%eax
311 movl %eax,48(%rsi)
312 movl 28(%rsi),%eax
313 movl %eax,52(%rsi)
314 jmp Lw6
315
b0d623f7
A
316ENTRY(munge_wwwwwwlw)
317 xorl %edx,%edx
318 movl 32(%rsi),%eax
319 movl %eax,56(%rsi)
320 movl %edx,60(%rsi)
321 movl 24(%rsi),%eax
322 movl %eax,48(%rsi)
323 movl 28(%rsi),%eax
324 movl %eax,52(%rsi)
325 jmp Lw6
326
327ENTRY(munge_wwwwwwll)
328 xorl %edx,%edx
329 movl 32(%rsi),%eax
330 movl %eax,56(%rsi)
331 movl 36(%rsi),%eax
332 movl %eax,60(%rsi)
333 movl 24(%rsi),%eax
334 movl %eax,48(%rsi)
335 movl 28(%rsi),%eax
336 movl %eax,52(%rsi)
337 jmp Lw6
338
339ENTRY(munge_wsw)
340 movl 8(%rsi),%eax
341 movl %eax,16(%rsi)
342 movl $0,20(%rsi)
343 movl 4(%rsi),%eax
344 cltd
345 movl %eax,8(%rsi)
346 movl %edx,12(%rsi)
347 movl $0,4(%rsi)
348 ret
349
350ENTRY(munge_wws)
351 movl 8(%rsi),%eax
352 cltd
353 movl %eax,16(%rsi)
354 movl %edx,20(%rsi)
355 xorl %edx,%edx
356 jmp Lw2
357
358ENTRY(munge_wwwsw)
359 movl 16(%rsi),%eax
360 movl %eax,32(%rsi)
361 movl $0,36(%rsi)
362 movl 12(%rsi),%eax
363 cltd
364 movl %eax,24(%rsi)
365 movl %edx,28(%rsi)
366 xorl %edx,%edx
367 jmp Lw3
368
369ENTRY(munge_llllll)
370 ret // nothing to do here, either - all args are already
371 // 64-bit and do not require sign/zero extension
372 // also, there is no mixing in of shorter args that
373 // do need extension