]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/x86_64/munge.s
xnu-1504.3.12.tar.gz
[apple/xnu.git] / bsd / dev / x86_64 / munge.s
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
77 ENTRY(munge_w)
78 movl $0,4(%rsi)
79 ret
80
81 ENTRY(munge_ww)
82 xorl %edx,%edx
83 jmp Lw2
84 ENTRY(munge_www)
85 xorl %edx,%edx
86 jmp Lw3
87 ENTRY(munge_wwww)
88 xorl %edx,%edx
89 jmp Lw4
90 ENTRY(munge_wwwww)
91 xorl %edx,%edx
92 jmp Lw5
93 ENTRY(munge_wwwwww)
94 xorl %edx,%edx
95 jmp Lw6
96 ENTRY(munge_wwwwwww)
97 xorl %edx,%edx
98 jmp Lw7
99 ENTRY(munge_wwwwwwww)
100 xorl %edx,%edx
101 movl 28(%rsi),%eax
102 movl %eax,56(%rsi)
103 movl %edx,60(%rsi)
104 Lw7:
105 movl 24(%rsi),%eax
106 movl %eax,48(%rsi)
107 movl %edx,52(%rsi)
108 Lw6:
109 movl 20(%rsi),%eax
110 movl %eax,40(%rsi)
111 movl %edx,44(%rsi)
112 Lw5:
113 movl 16(%rsi),%eax
114 movl %eax,32(%rsi)
115 movl %edx,36(%rsi)
116 Lw4:
117 movl 12(%rsi),%eax
118 movl %eax,24(%rsi)
119 movl %edx,28(%rsi)
120 Lw3:
121 movl 8(%rsi),%eax
122 movl %eax,16(%rsi)
123 movl %edx,20(%rsi)
124 Lw2:
125 movl 4(%rsi),%eax
126 movl %eax,8(%rsi)
127 movl %edx,12(%rsi)
128 movl %edx,4(%rsi)
129 ret
130
131
132 Entry(munge_wl) /* Costs an extra w move to do this */
133 ENTRY(munge_wlw)
134 xorl %edx,%edx
135 movl 12(%rsi),%eax
136 movl %eax,16(%rsi)
137 movl %edx,20(%rsi)
138 movl 8(%rsi),%eax
139 movl %eax,12(%rsi)
140 movl 4(%rsi),%eax
141 movl %eax,8(%rsi)
142 movl %edx,4(%rsi)
143 ret
144
145 Entry(munge_wwwlw)
146 xorl %edx,%edx
147 movl 20(%rsi),%eax
148 movl %eax,32(%rsi)
149 movl %edx,36(%rsi)
150 jmp Lwwwl
151
152
153 ENTRY(munge_wwwl)
154 xorl %edx,%edx
155 Lwwwl:
156 movl 12(%rsi),%eax
157 movl %eax,24(%rsi)
158 movl 16(%rsi),%eax
159 movl %eax,28(%rsi)
160 jmp Lw3
161
162 ENTRY(munge_wwwwlw)
163 xorl %edx,%edx
164 movl 24(%rsi),%eax
165 movl %eax,40(%rsi)
166 movl %edx,44(%rsi)
167 jmp Lwwwwl
168
169 ENTRY(munge_wwwwl)
170 xorl %edx,%edx
171 Lwwwwl:
172 movl 16(%rsi),%eax
173 movl %eax,32(%rsi)
174 movl 20(%rsi),%eax
175 movl %eax,36(%rsi)
176 jmp Lw4
177
178 ENTRY(munge_wwwwwl)
179 xorl %edx,%edx
180 movl 20(%rsi),%eax
181 movl %eax,40(%rsi)
182 movl 24(%rsi),%eax
183 movl %eax,44(%rsi)
184 jmp Lw5
185
186 ENTRY(munge_wwwwwwlw)
187 xorl %edx,%edx
188 movl 32(%rsi),%eax
189 movl %eax,56(%rsi)
190 movl %edx,60(%rsi)
191 movl 24(%rsi),%eax
192 movl %eax,48(%rsi)
193 movl 28(%rsi),%eax
194 movl %eax,52(%rsi)
195 jmp Lw6
196
197 ENTRY(munge_wwwwwwll)
198 xorl %edx,%edx
199 movl 32(%rsi),%eax
200 movl %eax,56(%rsi)
201 movl 36(%rsi),%eax
202 movl %eax,60(%rsi)
203 movl 24(%rsi),%eax
204 movl %eax,48(%rsi)
205 movl 28(%rsi),%eax
206 movl %eax,52(%rsi)
207 jmp Lw6
208
209 ENTRY(munge_wsw)
210 movl 8(%rsi),%eax
211 movl %eax,16(%rsi)
212 movl $0,20(%rsi)
213 movl 4(%rsi),%eax
214 cltd
215 movl %eax,8(%rsi)
216 movl %edx,12(%rsi)
217 movl $0,4(%rsi)
218 ret
219
220 ENTRY(munge_wws)
221 movl 8(%rsi),%eax
222 cltd
223 movl %eax,16(%rsi)
224 movl %edx,20(%rsi)
225 xorl %edx,%edx
226 jmp Lw2
227
228 ENTRY(munge_wwwsw)
229 movl 16(%rsi),%eax
230 movl %eax,32(%rsi)
231 movl $0,36(%rsi)
232 movl 12(%rsi),%eax
233 cltd
234 movl %eax,24(%rsi)
235 movl %edx,28(%rsi)
236 xorl %edx,%edx
237 jmp Lw3
238
239 ENTRY(munge_llllll)
240 ret // nothing to do here, either - all args are already
241 // 64-bit and do not require sign/zero extension
242 // also, there is no mixing in of shorter args that
243 // do need extension