]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/munge.s
xnu-792.13.8.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_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31 /*
32 * Syscall argument mungers.
33 *
34 * The data to be munged has been explicitly copied in to the arguement area,
35 * and will be munged in place in the uu_arg[] array. Because of this, the
36 * functions all take the same arguments as their PPC equivalents, but the
37 * first argument is ignored. These mungers are for 32-bit app's syscalls,
38 * since 64-bit args are stored into the save area (which overlays the
39 * uu_args) in the order the syscall ABI calls for.
40 *
41 * The issue is that the incoming args are 32-bit, but we must expand
42 * them in place into 64-bit args, as if they were from a 64-bit process.
43 *
44 * There are several functions in this file. Each takes two parameters:
45 *
46 * void munge_XXXX( const void *regs, void *uu_args);
47 *
48 * The name of the function encodes the number and type of the parameters,
49 * as follows:
50 *
51 * w = a 32-bit value such as an int or a 32-bit ptr, that does not
52 * require sign extension. These are handled by zeroing a word
53 * of output, and copying a word from input to output.
54 *
55 * s = a 32-bit value such as a long, which must be sign-extended to
56 * a 64-bit long-long in the uu_args. These are handled by
57 * loading a word of input and sign extending it to a double,
58 * and storing two words of output.
59 *
60 * l = a 64-bit long-long. These are handled by copying two words
61 * of input to the output.
62 *
63 * For example, "munge_wls" takes a word, a long-long, and a word. This
64 * takes four words in the uu_arg[] area: the first word is in one, the
65 * long-long takes two, and the final word is in the fourth. We store six
66 * words: the low word is left in place, followed by a 0, followed by the
67 * two words of the long-long, followed by the low word and the sign extended
68 * high word of the preceeding low word.
69 *
70 * Because this is an in-place modification, we actually start at the end
71 * of uu_arg[] and work our way back to the beginning of the array.
72 *
73 * As you can see, we save a lot of code by collapsing mungers that are
74 * prefixes or suffixes of each other.
75 */
76 #include <i386/asm.h>
77
78 ENTRY(munge_w)
79 movl 8(%esp),%ecx // get &uu_args
80 movl $0,4(%ecx)
81 ret
82
83 ENTRY(munge_ww)
84 movl 8(%esp),%ecx // get &uu_args
85 xorl %edx,%edx
86 jmp Lw2
87 ENTRY(munge_www)
88 movl 8(%esp),%ecx // get &uu_args
89 xorl %edx,%edx
90 jmp Lw3
91 ENTRY(munge_wwww)
92 movl 8(%esp),%ecx // get &uu_args
93 xorl %edx,%edx
94 jmp Lw4
95 ENTRY(munge_wwwww)
96 movl 8(%esp),%ecx // get &uu_args
97 xorl %edx,%edx
98 jmp Lw5
99 ENTRY(munge_wwwwww)
100 movl 8(%esp),%ecx // get &uu_args
101 xorl %edx,%edx
102 jmp Lw6
103 ENTRY(munge_wwwwwww)
104 movl 8(%esp),%ecx // get &uu_args
105 xorl %edx,%edx
106 jmp Lw7
107 ENTRY(munge_wwwwwwww)
108 movl 8(%esp),%ecx // get &uu_args
109 xorl %edx,%edx
110 movl 28(%ecx),%eax
111 movl %eax,56(%ecx)
112 movl %edx,60(%ecx)
113 Lw7:
114 movl 24(%ecx),%eax
115 movl %eax,48(%ecx)
116 movl %edx,52(%ecx)
117 Lw6:
118 movl 20(%ecx),%eax
119 movl %eax,40(%ecx)
120 movl %edx,44(%ecx)
121 Lw5:
122 movl 16(%ecx),%eax
123 movl %eax,32(%ecx)
124 movl %edx,36(%ecx)
125 Lw4:
126 movl 12(%ecx),%eax
127 movl %eax,24(%ecx)
128 movl %edx,28(%ecx)
129 Lw3:
130 movl 8(%ecx),%eax
131 movl %eax,16(%ecx)
132 movl %edx,20(%ecx)
133 Lw2:
134 movl 4(%ecx),%eax
135 movl %eax,8(%ecx)
136 movl %edx,12(%ecx)
137 movl %edx,4(%ecx)
138 ret
139
140
141 Entry(munge_wl) /* Costs an extra w move to do this */
142 ENTRY(munge_wlw)
143 movl 8(%esp),%ecx // get &uu_args
144 xorl %edx,%edx
145 movl 12(%ecx),%eax
146 movl %eax,16(%ecx)
147 movl %edx,20(%ecx)
148 movl 8(%ecx),%eax
149 movl %eax,12(%ecx)
150 movl 4(%ecx),%eax
151 movl %eax,8(%ecx)
152 movl %edx,4(%ecx)
153 ret
154
155 ENTRY(munge_wwwl)
156 movl 8(%esp),%ecx // get &uu_args
157 xorl %edx,%edx
158 movl 12(%ecx),%eax
159 movl %eax,24(%ecx)
160 movl 16(%ecx),%eax
161 movl %eax,28(%ecx)
162 jmp Lw3
163
164 ENTRY(munge_wwwwl)
165 movl 8(%esp),%ecx // get &uu_args
166 xorl %edx,%edx
167 movl 16(%ecx),%eax
168 movl %eax,32(%ecx)
169 movl 20(%ecx),%eax
170 movl %eax,36(%ecx)
171 jmp Lw4
172
173 ENTRY(munge_wwwwwl)
174 movl 8(%esp),%ecx // get &uu_args
175 xorl %edx,%edx
176 movl 20(%ecx),%eax
177 movl %eax,40(%ecx)
178 movl 24(%ecx),%eax
179 movl %eax,44(%ecx)
180 jmp Lw5
181
182 ENTRY(munge_wsw)
183 movl 8(%esp),%ecx // get &uu_args
184 movl 8(%ecx),%eax
185 movl %eax,16(%ecx)
186 movl $0,20(%ecx)
187 movl 4(%ecx),%eax
188 cltd
189 movl %eax,8(%ecx)
190 movl %edx,12(%ecx)
191 movl $0,4(%ecx)
192 ret
193
194 ENTRY(munge_wws)
195 movl 8(%esp),%ecx // get &uu_args
196 movl 8(%ecx),%eax
197 cltd
198 movl %eax,16(%ecx)
199 movl %edx,20(%ecx)
200 xorl %edx,%edx
201 jmp Lw2
202
203 ENTRY(munge_wwwsw)
204 movl 8(%esp),%ecx // get &uu_args
205 movl 16(%ecx),%eax
206 movl %eax,32(%ecx)
207 movl $0,36(%ecx)
208 movl 12(%ecx),%eax
209 cltd
210 movl %eax,24(%ecx)
211 movl %edx,28(%ecx)
212 xorl %edx,%edx
213 jmp Lw3