]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/munge.s
xnu-1504.3.12.tar.gz
[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 movl 12(%ecx),%eax
144 movl %eax,16(%ecx)
145 movl %edx,20(%ecx)
146 movl 8(%ecx),%eax
147 movl %eax,12(%ecx)
148 movl 4(%ecx),%eax
149 movl %eax,8(%ecx)
150 movl %edx,4(%ecx)
151 ret
152
153 Entry(munge_wwwlw)
154 movl 8(%esp),%ecx // get &uu_args
155 xorl %edx,%edx
156 movl 20(%ecx),%eax
157 movl %eax,32(%ecx)
158 movl %edx,36(%ecx)
159 jmp Lwwwl
160
161 ENTRY(munge_wwwl)
162 movl 8(%esp),%ecx // get &uu_args
163 xorl %edx,%edx
164 Lwwwl:
165 movl 12(%ecx),%eax
166 movl %eax,24(%ecx)
167 movl 16(%ecx),%eax
168 movl %eax,28(%ecx)
169 jmp Lw3
170
171 ENTRY(munge_wwwwlw)
172 movl 8(%esp),%ecx // get &uu_args
173 xorl %edx,%edx
174 movl 24(%ecx),%eax
175 movl %eax,40(%ecx)
176 movl %edx,44(%ecx)
177 jmp Lwwwwl
178
179 ENTRY(munge_wwwwl)
180 movl 8(%esp),%ecx // get &uu_args
181 xorl %edx,%edx
182 Lwwwwl:
183 movl 16(%ecx),%eax
184 movl %eax,32(%ecx)
185 movl 20(%ecx),%eax
186 movl %eax,36(%ecx)
187 jmp Lw4
188
189 ENTRY(munge_wwwwwl)
190 movl 8(%esp),%ecx // get &uu_args
191 xorl %edx,%edx
192 movl 20(%ecx),%eax
193 movl %eax,40(%ecx)
194 movl 24(%ecx),%eax
195 movl %eax,44(%ecx)
196 jmp Lw5
197
198 ENTRY(munge_wwwwwwlw)
199 movl 8(%esp),%ecx // get &uu_args
200 xorl %edx,%edx
201 movl 32(%ecx),%eax
202 movl %eax,56(%ecx)
203 movl %edx,60(%ecx)
204 movl 24(%ecx),%eax
205 movl %eax,48(%ecx)
206 movl 28(%ecx),%eax
207 movl %eax,52(%ecx)
208 jmp Lw6
209
210
211 ENTRY(munge_wwwwwwll)
212 movl 8(%esp),%ecx // get &uu_args
213 xorl %edx,%edx
214 movl 32(%ecx),%eax
215 movl %eax,56(%ecx)
216 movl 36(%ecx),%eax
217 movl %eax,60(%ecx)
218 movl 24(%ecx),%eax
219 movl %eax,48(%ecx)
220 movl 28(%ecx),%eax
221 movl %eax,52(%ecx)
222 jmp Lw6
223
224 ENTRY(munge_wsw)
225 movl 8(%esp),%ecx // get &uu_args
226 movl 8(%ecx),%eax
227 movl %eax,16(%ecx)
228 movl $0,20(%ecx)
229 movl 4(%ecx),%eax
230 cltd
231 movl %eax,8(%ecx)
232 movl %edx,12(%ecx)
233 movl $0,4(%ecx)
234 ret
235
236 ENTRY(munge_wws)
237 movl 8(%esp),%ecx // get &uu_args
238 movl 8(%ecx),%eax
239 cltd
240 movl %eax,16(%ecx)
241 movl %edx,20(%ecx)
242 xorl %edx,%edx
243 jmp Lw2
244
245 ENTRY(munge_wwwsw)
246 movl 8(%esp),%ecx // get &uu_args
247 movl 16(%ecx),%eax
248 movl %eax,32(%ecx)
249 movl $0,36(%ecx)
250 movl 12(%ecx),%eax
251 cltd
252 movl %eax,24(%ecx)
253 movl %edx,28(%ecx)
254 xorl %edx,%edx
255 jmp Lw3
256
257 ENTRY(munge_llllll)
258 ret // actually, this method has nothing to do - all
259 // arguments are already 64-bits, with no mixing of
260 // args that need sign/zero extension