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