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