]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/munge.s
xnu-1228.15.4.tar.gz
[apple/xnu.git] / bsd / dev / i386 / munge.s
CommitLineData
0c530ab8
A
1/*
2 * Coyright (c) 2005-2006 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55
A
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
0c530ab8
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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@
0c530ab8
A
27 */
28
29/*
30 * Syscall argument mungers.
31 *
2d21ac55 32 * The data to be munged has been explicitly copied in to the argument area,
0c530ab8
A
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
76ENTRY(munge_w)
77 movl 8(%esp),%ecx // get &uu_args
78 movl $0,4(%ecx)
79 ret
80
81ENTRY(munge_ww)
82 movl 8(%esp),%ecx // get &uu_args
83 xorl %edx,%edx
84 jmp Lw2
85ENTRY(munge_www)
86 movl 8(%esp),%ecx // get &uu_args
87 xorl %edx,%edx
88 jmp Lw3
89ENTRY(munge_wwww)
90 movl 8(%esp),%ecx // get &uu_args
91 xorl %edx,%edx
92 jmp Lw4
93ENTRY(munge_wwwww)
94 movl 8(%esp),%ecx // get &uu_args
95 xorl %edx,%edx
96 jmp Lw5
97ENTRY(munge_wwwwww)
98 movl 8(%esp),%ecx // get &uu_args
99 xorl %edx,%edx
100 jmp Lw6
101ENTRY(munge_wwwwwww)
102 movl 8(%esp),%ecx // get &uu_args
103 xorl %edx,%edx
104 jmp Lw7
105ENTRY(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)
111Lw7:
112 movl 24(%ecx),%eax
113 movl %eax,48(%ecx)
114 movl %edx,52(%ecx)
115Lw6:
116 movl 20(%ecx),%eax
117 movl %eax,40(%ecx)
118 movl %edx,44(%ecx)
119Lw5:
120 movl 16(%ecx),%eax
121 movl %eax,32(%ecx)
122 movl %edx,36(%ecx)
123Lw4:
124 movl 12(%ecx),%eax
125 movl %eax,24(%ecx)
126 movl %edx,28(%ecx)
127Lw3:
128 movl 8(%ecx),%eax
129 movl %eax,16(%ecx)
130 movl %edx,20(%ecx)
131Lw2:
132 movl 4(%ecx),%eax
133 movl %eax,8(%ecx)
134 movl %edx,12(%ecx)
135 movl %edx,4(%ecx)
136 ret
137
138
139Entry(munge_wl) /* Costs an extra w move to do this */
140ENTRY(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
153ENTRY(munge_wwwl)
154 movl 8(%esp),%ecx // get &uu_args
155 xorl %edx,%edx
156 movl 12(%ecx),%eax
157 movl %eax,24(%ecx)
158 movl 16(%ecx),%eax
159 movl %eax,28(%ecx)
160 jmp Lw3
161
162ENTRY(munge_wwwwl)
163 movl 8(%esp),%ecx // get &uu_args
164 xorl %edx,%edx
165 movl 16(%ecx),%eax
166 movl %eax,32(%ecx)
167 movl 20(%ecx),%eax
168 movl %eax,36(%ecx)
169 jmp Lw4
170
171ENTRY(munge_wwwwwl)
172 movl 8(%esp),%ecx // get &uu_args
173 xorl %edx,%edx
174 movl 20(%ecx),%eax
175 movl %eax,40(%ecx)
176 movl 24(%ecx),%eax
177 movl %eax,44(%ecx)
178 jmp Lw5
179
180ENTRY(munge_wsw)
181 movl 8(%esp),%ecx // get &uu_args
182 movl 8(%ecx),%eax
183 movl %eax,16(%ecx)
184 movl $0,20(%ecx)
185 movl 4(%ecx),%eax
186 cltd
187 movl %eax,8(%ecx)
188 movl %edx,12(%ecx)
189 movl $0,4(%ecx)
190 ret
191
192ENTRY(munge_wws)
193 movl 8(%esp),%ecx // get &uu_args
194 movl 8(%ecx),%eax
195 cltd
196 movl %eax,16(%ecx)
197 movl %edx,20(%ecx)
198 xorl %edx,%edx
199 jmp Lw2
200
201ENTRY(munge_wwwsw)
202 movl 8(%esp),%ecx // get &uu_args
203 movl 16(%ecx),%eax
204 movl %eax,32(%ecx)
205 movl $0,36(%ecx)
206 movl 12(%ecx),%eax
207 cltd
208 movl %eax,24(%ecx)
209 movl %edx,28(%ecx)
210 xorl %edx,%edx
211 jmp Lw3