1 | ; $Id: EMAllA.asm 20278 2007-04-09 11:56:29Z sandervl $
|
---|
2 | ;; @file
|
---|
3 | ; EM Assembly Routines.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 | ; Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | ; Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | ; additional information or have any questions.
|
---|
20 | ;
|
---|
21 |
|
---|
22 | ;*******************************************************************************
|
---|
23 | ;* Header Files *
|
---|
24 | ;*******************************************************************************
|
---|
25 | %include "VBox/asmdefs.mac"
|
---|
26 | %include "VBox/err.mac"
|
---|
27 | %include "VBox/x86.mac"
|
---|
28 |
|
---|
29 | BEGINCODE
|
---|
30 |
|
---|
31 | ;;
|
---|
32 | ; Emulate LOCK CMPXCHG instruction, CDECL calling conv.
|
---|
33 | ; EMGCDECL(uint32_t) EMGCEmulateLockCmpXchg(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
|
---|
34 | ;
|
---|
35 | ; @returns eax=0 if data written, other code - invalid access, #PF was generated.
|
---|
36 | ; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter
|
---|
37 | ; @param [esp + 08h] Param 2 - Second parameter - pointer to second parameter (eax)
|
---|
38 | ; @param [esp + 0ch] Param 3 - Third parameter - third parameter
|
---|
39 | ; @param [esp + 10h] Param 4 - Size of parameters, only 1/2/4 is valid.
|
---|
40 | ; @param [esp + 14h] Param 4 - Pointer to eflags (out)
|
---|
41 | ; @uses eax, ecx, edx
|
---|
42 | ;
|
---|
43 | align 16
|
---|
44 | BEGINPROC EMGCEmulateLockCmpXchg
|
---|
45 | push ebx
|
---|
46 | mov ecx, [esp + 04h + 4] ; ecx = first parameter
|
---|
47 | mov ebx, [esp + 08h + 4] ; ebx = 2nd parameter (eax)
|
---|
48 | mov edx, [esp + 0ch + 4] ; edx = third parameter
|
---|
49 | mov eax, [esp + 10h + 4] ; eax = size of parameters
|
---|
50 |
|
---|
51 | cmp al, 4
|
---|
52 | je short .do_dword ; 4 bytes variant
|
---|
53 | cmp al, 2
|
---|
54 | je short .do_word ; 2 byte variant
|
---|
55 | cmp al, 1
|
---|
56 | je short .do_byte ; 1 bytes variant
|
---|
57 | int3
|
---|
58 |
|
---|
59 | .do_dword:
|
---|
60 | ; load 2nd parameter's value
|
---|
61 | mov eax, dword [ebx]
|
---|
62 |
|
---|
63 | lock cmpxchg dword [ecx], edx ; do 4 bytes CMPXCHG
|
---|
64 | mov dword [ebx], eax
|
---|
65 | jmp short .done
|
---|
66 |
|
---|
67 | .do_word:
|
---|
68 | ; load 2nd parameter's value
|
---|
69 | mov eax, dword [ebx]
|
---|
70 |
|
---|
71 | lock cmpxchg word [ecx], dx ; do 2 bytes CMPXCHG
|
---|
72 | mov word [ebx], ax
|
---|
73 | jmp short .done
|
---|
74 |
|
---|
75 | .do_byte:
|
---|
76 | ; load 2nd parameter's value
|
---|
77 | mov eax, dword [ebx]
|
---|
78 |
|
---|
79 | lock cmpxchg byte [ecx], dl ; do 1 bytes CMPXCHG
|
---|
80 | mov byte [ebx], al
|
---|
81 |
|
---|
82 | .done:
|
---|
83 | ; collect flags and return.
|
---|
84 | pushf
|
---|
85 | pop eax
|
---|
86 |
|
---|
87 | mov edx, [esp + 14h + 4] ; eflags pointer
|
---|
88 | mov dword [edx], eax
|
---|
89 |
|
---|
90 | pop ebx
|
---|
91 | mov eax, VINF_SUCCESS
|
---|
92 | retn
|
---|
93 |
|
---|
94 | ; Read error - we will be here after our page fault handler.
|
---|
95 | GLOBALNAME EMGCEmulateLockCmpXchg_Error
|
---|
96 | pop ebx
|
---|
97 | mov eax, VERR_ACCESS_DENIED
|
---|
98 | ret
|
---|
99 |
|
---|
100 | ENDPROC EMGCEmulateLockCmpXchg
|
---|
101 |
|
---|
102 | ;;
|
---|
103 | ; Emulate CMPXCHG instruction, CDECL calling conv.
|
---|
104 | ; EMGCDECL(uint32_t) EMGCEmulateCmpXchg(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
|
---|
105 | ;
|
---|
106 | ; @returns eax=0 if data written, other code - invalid access, #PF was generated.
|
---|
107 | ; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter
|
---|
108 | ; @param [esp + 08h] Param 2 - Second parameter - pointer to second parameter (eax)
|
---|
109 | ; @param [esp + 0ch] Param 3 - Third parameter - third parameter
|
---|
110 | ; @param [esp + 10h] Param 4 - Size of parameters, only 1/2/4 is valid.
|
---|
111 | ; @param [esp + 14h] Param 4 - Pointer to eflags (out)
|
---|
112 | ; @uses eax, ecx, edx
|
---|
113 | ;
|
---|
114 | align 16
|
---|
115 | BEGINPROC EMGCEmulateCmpXchg
|
---|
116 | push ebx
|
---|
117 | mov ecx, [esp + 04h + 4] ; ecx = first parameter
|
---|
118 | mov ebx, [esp + 08h + 4] ; ebx = 2nd parameter (eax)
|
---|
119 | mov edx, [esp + 0ch + 4] ; edx = third parameter
|
---|
120 | mov eax, [esp + 10h + 4] ; eax = size of parameters
|
---|
121 |
|
---|
122 | cmp al, 4
|
---|
123 | je short .do_dword ; 4 bytes variant
|
---|
124 | cmp al, 2
|
---|
125 | je short .do_word ; 2 byte variant
|
---|
126 | cmp al, 1
|
---|
127 | je short .do_byte ; 1 bytes variant
|
---|
128 | int3
|
---|
129 |
|
---|
130 | .do_dword:
|
---|
131 | ; load 2nd parameter's value
|
---|
132 | mov eax, dword [ebx]
|
---|
133 |
|
---|
134 | cmpxchg dword [ecx], edx ; do 4 bytes CMPXCHG
|
---|
135 | mov dword [ebx], eax
|
---|
136 | jmp short .done
|
---|
137 |
|
---|
138 | .do_word:
|
---|
139 | ; load 2nd parameter's value
|
---|
140 | mov eax, dword [ebx]
|
---|
141 |
|
---|
142 | cmpxchg word [ecx], dx ; do 2 bytes CMPXCHG
|
---|
143 | mov word [ebx], ax
|
---|
144 | jmp short .done
|
---|
145 |
|
---|
146 | .do_byte:
|
---|
147 | ; load 2nd parameter's value
|
---|
148 | mov eax, dword [ebx]
|
---|
149 |
|
---|
150 | cmpxchg byte [ecx], dl ; do 1 bytes CMPXCHG
|
---|
151 | mov byte [ebx], al
|
---|
152 |
|
---|
153 | .done:
|
---|
154 | ; collect flags and return.
|
---|
155 | pushf
|
---|
156 | pop eax
|
---|
157 |
|
---|
158 | mov edx, [esp + 14h + 4] ; eflags pointer
|
---|
159 | mov dword [edx], eax
|
---|
160 |
|
---|
161 | pop ebx
|
---|
162 | mov eax, VINF_SUCCESS
|
---|
163 | retn
|
---|
164 |
|
---|
165 | ; Read error - we will be here after our page fault handler.
|
---|
166 | GLOBALNAME EMGCEmulateCmpXchg_Error
|
---|
167 | pop ebx
|
---|
168 | mov eax, VERR_ACCESS_DENIED
|
---|
169 | ret
|
---|
170 | ENDPROC EMGCEmulateCmpXchg
|
---|
171 |
|
---|
172 | ;;
|
---|
173 | ; Emulate LOCK CMPXCHG8B instruction, CDECL calling conv.
|
---|
174 | ; EMGCDECL(uint32_t) EMGCEmulateLockCmpXchg8b(RTGCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX, uint32_t *pEflags);
|
---|
175 | ;
|
---|
176 | ; @returns eax=0 if data written, other code - invalid access, #PF was generated.
|
---|
177 | ; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter
|
---|
178 | ; @param [esp + 08h] Param 2 - Address of the eax register
|
---|
179 | ; @param [esp + 0ch] Param 3 - Address of the edx register
|
---|
180 | ; @param [esp + 10h] Param 4 - EBX
|
---|
181 | ; @param [esp + 14h] Param 5 - ECX
|
---|
182 | ; @param [esp + 18h] Param 6 - Pointer to eflags (out)
|
---|
183 | ; @uses eax, ecx, edx
|
---|
184 | ;
|
---|
185 | align 16
|
---|
186 | BEGINPROC EMGCEmulateLockCmpXchg8b
|
---|
187 | push ebp
|
---|
188 | push ebx
|
---|
189 | mov ebp, [esp + 04h + 8] ; ebp = first parameter
|
---|
190 | mov eax, [esp + 08h + 8] ; &EAX
|
---|
191 | mov eax, dword [eax]
|
---|
192 | mov edx, [esp + 0ch + 8] ; &EDX
|
---|
193 | mov edx, dword [edx]
|
---|
194 | mov ebx, [esp + 10h + 8] ; EBX
|
---|
195 | mov ecx, [esp + 14h + 8] ; ECX
|
---|
196 |
|
---|
197 | %ifdef RT_OS_OS2
|
---|
198 | lock cmpxchg8b [ebp] ; do CMPXCHG8B
|
---|
199 | %else
|
---|
200 | lock cmpxchg8b qword [ebp] ; do CMPXCHG8B
|
---|
201 | %endif
|
---|
202 | mov dword [esp + 08h + 8], eax
|
---|
203 | mov dword [esp + 0ch + 8], edx
|
---|
204 |
|
---|
205 | ; collect flags and return.
|
---|
206 | pushf
|
---|
207 | pop eax
|
---|
208 |
|
---|
209 | mov edx, [esp + 18h + 8] ; eflags pointer
|
---|
210 | mov dword [edx], eax
|
---|
211 |
|
---|
212 | pop ebx
|
---|
213 | pop ebp
|
---|
214 | mov eax, VINF_SUCCESS
|
---|
215 | retn
|
---|
216 |
|
---|
217 | ; Read error - we will be here after our page fault handler.
|
---|
218 | GLOBALNAME EMGCEmulateLockCmpXchg8b_Error
|
---|
219 | pop ebx
|
---|
220 | pop ebp
|
---|
221 | mov eax, VERR_ACCESS_DENIED
|
---|
222 | ret
|
---|
223 |
|
---|
224 | ENDPROC EMGCEmulateLockCmpXchg8b
|
---|
225 |
|
---|
226 | ;;
|
---|
227 | ; Emulate CMPXCHG8B instruction, CDECL calling conv.
|
---|
228 | ; EMGCDECL(uint32_t) EMGCEmulateCmpXchg8b(RTGCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX, uint32_t *pEflags);
|
---|
229 | ;
|
---|
230 | ; @returns eax=0 if data written, other code - invalid access, #PF was generated.
|
---|
231 | ; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter
|
---|
232 | ; @param [esp + 08h] Param 2 - Address of the eax register
|
---|
233 | ; @param [esp + 0ch] Param 3 - Address of the edx register
|
---|
234 | ; @param [esp + 10h] Param 4 - EBX
|
---|
235 | ; @param [esp + 14h] Param 5 - ECX
|
---|
236 | ; @param [esp + 18h] Param 6 - Pointer to eflags (out)
|
---|
237 | ; @uses eax, ecx, edx
|
---|
238 | ;
|
---|
239 | align 16
|
---|
240 | BEGINPROC EMGCEmulateCmpXchg8b
|
---|
241 | push ebp
|
---|
242 | push ebx
|
---|
243 | mov ebp, [esp + 04h + 8] ; ebp = first parameter
|
---|
244 | mov eax, [esp + 08h + 8] ; &EAX
|
---|
245 | mov eax, dword [eax]
|
---|
246 | mov edx, [esp + 0ch + 8] ; &EDX
|
---|
247 | mov edx, dword [edx]
|
---|
248 | mov ebx, [esp + 10h + 8] ; EBX
|
---|
249 | mov ecx, [esp + 14h + 8] ; ECX
|
---|
250 |
|
---|
251 | %ifdef RT_OS_OS2
|
---|
252 | cmpxchg8b [ebp] ; do CMPXCHG8B
|
---|
253 | %else
|
---|
254 | cmpxchg8b qword [ebp] ; do CMPXCHG8B
|
---|
255 | %endif
|
---|
256 | mov dword [esp + 08h + 8], eax
|
---|
257 | mov dword [esp + 0ch + 8], edx
|
---|
258 |
|
---|
259 | ; collect flags and return.
|
---|
260 | pushf
|
---|
261 | pop eax
|
---|
262 |
|
---|
263 | mov edx, [esp + 18h + 8] ; eflags pointer
|
---|
264 | mov dword [edx], eax
|
---|
265 |
|
---|
266 | pop ebx
|
---|
267 | pop ebp
|
---|
268 | mov eax, VINF_SUCCESS
|
---|
269 | retn
|
---|
270 |
|
---|
271 | ; Read error - we will be here after our page fault handler.
|
---|
272 | GLOBALNAME EMGCEmulateCmpXchg8b_Error
|
---|
273 | pop ebx
|
---|
274 | pop ebp
|
---|
275 | mov eax, VERR_ACCESS_DENIED
|
---|
276 | ret
|
---|
277 | ENDPROC EMGCEmulateCmpXchg8b
|
---|
278 |
|
---|
279 | ;;
|
---|
280 | ; Emulate LOCK XADD instruction, CDECL calling conv.
|
---|
281 | ; EMGCDECL(uint32_t) EMGCEmulateLockXAdd(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
|
---|
282 | ;
|
---|
283 | ; @returns eax=0 if data exchanged, other code - invalid access, #PF was generated.
|
---|
284 | ; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter
|
---|
285 | ; @param [esp + 08h] Param 2 - Second parameter - pointer to second parameter (general register)
|
---|
286 | ; @param [esp + 0ch] Param 3 - Size of parameters, only 1/2/4 is valid.
|
---|
287 | ; @param [esp + 10h] Param 4 - Pointer to eflags (out)
|
---|
288 | ; @uses eax, ecx, edx
|
---|
289 | ;
|
---|
290 | align 16
|
---|
291 | BEGINPROC EMGCEmulateLockXAdd
|
---|
292 | mov ecx, [esp + 04h + 0] ; ecx = first parameter
|
---|
293 | mov edx, [esp + 08h + 0] ; edx = 2nd parameter
|
---|
294 | mov eax, [esp + 0ch + 0] ; eax = size of parameters
|
---|
295 |
|
---|
296 | cmp al, 4
|
---|
297 | je short .do_dword ; 4 bytes variant
|
---|
298 | cmp al, 2
|
---|
299 | je short .do_word ; 2 byte variant
|
---|
300 | cmp al, 1
|
---|
301 | je short .do_byte ; 1 bytes variant
|
---|
302 | int3
|
---|
303 |
|
---|
304 | .do_dword:
|
---|
305 | ; load 2nd parameter's value
|
---|
306 | mov eax, dword [edx]
|
---|
307 | lock xadd dword [ecx], eax ; do 4 bytes XADD
|
---|
308 | mov dword [edx], eax
|
---|
309 | jmp short .done
|
---|
310 |
|
---|
311 | .do_word:
|
---|
312 | ; load 2nd parameter's value
|
---|
313 | mov eax, dword [edx]
|
---|
314 | lock xadd word [ecx], ax ; do 2 bytes XADD
|
---|
315 | mov word [edx], ax
|
---|
316 | jmp short .done
|
---|
317 |
|
---|
318 | .do_byte:
|
---|
319 | ; load 2nd parameter's value
|
---|
320 | mov eax, dword [edx]
|
---|
321 | lock xadd byte [ecx], al ; do 1 bytes XADD
|
---|
322 | mov byte [edx], al
|
---|
323 |
|
---|
324 | .done:
|
---|
325 | ; collect flags and return.
|
---|
326 | mov edx, [esp + 10h + 0] ; eflags pointer
|
---|
327 | pushf
|
---|
328 | pop dword [edx]
|
---|
329 |
|
---|
330 | mov eax, VINF_SUCCESS
|
---|
331 | retn
|
---|
332 |
|
---|
333 | ; Read error - we will be here after our page fault handler.
|
---|
334 | GLOBALNAME EMGCEmulateLockXAdd_Error
|
---|
335 | mov eax, VERR_ACCESS_DENIED
|
---|
336 | ret
|
---|
337 |
|
---|
338 | ENDPROC EMGCEmulateLockXAdd
|
---|
339 |
|
---|
340 | ;;
|
---|
341 | ; Emulate XADD instruction, CDECL calling conv.
|
---|
342 | ; EMGCDECL(uint32_t) EMGCEmulateXAdd(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
|
---|
343 | ;
|
---|
344 | ; @returns eax=0 if data written, other code - invalid access, #PF was generated.
|
---|
345 | ; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter
|
---|
346 | ; @param [esp + 08h] Param 2 - Second parameter - pointer to second parameter (general register)
|
---|
347 | ; @param [esp + 0ch] Param 3 - Size of parameters, only 1/2/4 is valid.
|
---|
348 | ; @param [esp + 10h] Param 4 - Pointer to eflags (out)
|
---|
349 | ; @uses eax, ecx, edx
|
---|
350 | ;
|
---|
351 | align 16
|
---|
352 | BEGINPROC EMGCEmulateXAdd
|
---|
353 | mov ecx, [esp + 04h + 0] ; ecx = first parameter
|
---|
354 | mov edx, [esp + 08h + 0] ; edx = 2nd parameter (eax)
|
---|
355 | mov eax, [esp + 0ch + 0] ; eax = size of parameters
|
---|
356 |
|
---|
357 | cmp al, 4
|
---|
358 | je short .do_dword ; 4 bytes variant
|
---|
359 | cmp al, 2
|
---|
360 | je short .do_word ; 2 byte variant
|
---|
361 | cmp al, 1
|
---|
362 | je short .do_byte ; 1 bytes variant
|
---|
363 | int3
|
---|
364 |
|
---|
365 | .do_dword:
|
---|
366 | ; load 2nd parameter's value
|
---|
367 | mov eax, dword [edx]
|
---|
368 | xadd dword [ecx], eax ; do 4 bytes XADD
|
---|
369 | mov dword [edx], eax
|
---|
370 | jmp short .done
|
---|
371 |
|
---|
372 | .do_word:
|
---|
373 | ; load 2nd parameter's value
|
---|
374 | mov eax, dword [edx]
|
---|
375 | xadd word [ecx], ax ; do 2 bytes XADD
|
---|
376 | mov word [edx], ax
|
---|
377 | jmp short .done
|
---|
378 |
|
---|
379 | .do_byte:
|
---|
380 | ; load 2nd parameter's value
|
---|
381 | mov eax, dword [edx]
|
---|
382 | xadd byte [ecx], al ; do 1 bytes XADD
|
---|
383 | mov byte [edx], al
|
---|
384 |
|
---|
385 | .done:
|
---|
386 | ; collect flags and return.
|
---|
387 | mov edx, [esp + 10h + 0] ; eflags pointer
|
---|
388 | pushf
|
---|
389 | pop dword [edx]
|
---|
390 |
|
---|
391 | mov eax, VINF_SUCCESS
|
---|
392 | retn
|
---|
393 |
|
---|
394 | ; Read error - we will be here after our page fault handler.
|
---|
395 | GLOBALNAME EMGCEmulateXAdd_Error
|
---|
396 | mov eax, VERR_ACCESS_DENIED
|
---|
397 | ret
|
---|
398 | ENDPROC EMGCEmulateXAdd
|
---|