VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMGC/EMGCA.asm@ 2705

Last change on this file since 2705 was 2041, checked in by vboxsync, 18 years ago

export to OSE

File size: 4.8 KB
Line 
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 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13; in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14; distribution. VirtualBox OSE is distributed in the hope that it will
15; be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17; If you received this file as part of a commercial VirtualBox
18; distribution, then only the terms of your commercial VirtualBox
19; license agreement apply instead of the previous paragraph.
20;
21
22;*******************************************************************************
23;* Header Files *
24;*******************************************************************************
25%include "VBox/asmdefs.mac"
26%include "VBox/err.mac"
27%include "VBox/x86.mac"
28
29BEGINCODE
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);
34;
35; @returns EFLAGS after the operation, only arithmetic flags is valid.
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; @uses eax, ecx, edx
41;
42align 16
43BEGINPROC EMGCEmulateLockCmpXchg
44 push ebx
45 mov ecx, [esp + 04h + 4] ; ecx = first parameter
46 mov ebx, [esp + 08h + 4] ; ebx = 2nd parameter (eax)
47 mov edx, [esp + 0ch + 4] ; edx = third parameter
48 mov eax, [esp + 10h + 4] ; eax = size of parameters
49
50 cmp al, 4
51 je short .do_dword ; 4 bytes variant
52 cmp al, 2
53 je short .do_word ; 2 byte variant
54 cmp al, 1
55 je short .do_byte ; 1 bytes variant
56 int3
57
58.do_dword:
59 ; load 2nd parameter's value
60 mov eax, dword [ebx]
61
62 lock cmpxchg dword [ecx], edx ; do 4 bytes CMPXCHG
63 mov dword [ebx], eax
64 jmp short .done
65
66.do_word:
67 ; load 2nd parameter's value
68 mov eax, dword [ebx]
69
70 lock cmpxchg word [ecx], dx ; do 2 bytes CMPXCHG
71 mov word [ebx], ax
72 jmp short .done
73
74.do_byte:
75 ; load 2nd parameter's value
76 mov eax, dword [ebx]
77
78 lock cmpxchg byte [ecx], dl ; do 1 bytes CMPXCHG
79 mov byte [ebx], al
80
81.done:
82 ; collect flags and return.
83 pushf
84 pop eax
85
86 pop ebx
87 retn
88ENDPROC EMGCEmulateLockCmpXchg
89
90;;
91; Emulate CMPXCHG instruction, CDECL calling conv.
92; EMGCDECL(uint32_t) EMGCEmulateCmpXchg(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize);
93;
94; @returns EFLAGS after the operation, only arithmetic flags is valid.
95; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter
96; @param [esp + 08h] Param 2 - Second parameter - pointer to second parameter (eax)
97; @param [esp + 0ch] Param 3 - Third parameter - third parameter
98; @param [esp + 10h] Param 4 - Size of parameters, only 1/2/4 is valid.
99; @uses eax, ecx, edx
100;
101align 16
102BEGINPROC EMGCEmulateCmpXchg
103 push ebx
104 mov ecx, [esp + 04h + 4] ; ecx = first parameter
105 mov ebx, [esp + 08h + 4] ; ebx = 2nd parameter (eax)
106 mov edx, [esp + 0ch + 4] ; edx = third parameter
107 mov eax, [esp + 10h + 4] ; eax = size of parameters
108
109 cmp al, 4
110 je short .do_dword ; 4 bytes variant
111 cmp al, 2
112 je short .do_word ; 2 byte variant
113 cmp al, 1
114 je short .do_byte ; 1 bytes variant
115 int3
116
117.do_dword:
118 ; load 2nd parameter's value
119 mov eax, dword [ebx]
120
121 cmpxchg dword [ecx], edx ; do 4 bytes CMPXCHG
122 mov dword [ebx], eax
123 jmp short .done
124
125.do_word:
126 ; load 2nd parameter's value
127 mov eax, dword [ebx]
128
129 cmpxchg word [ecx], dx ; do 2 bytes CMPXCHG
130 mov word [ebx], ax
131 jmp short .done
132
133.do_byte:
134 ; load 2nd parameter's value
135 mov eax, dword [ebx]
136
137 cmpxchg byte [ecx], dl ; do 1 bytes CMPXCHG
138 mov byte [ebx], al
139
140.done:
141 ; collect flags and return.
142 pushf
143 pop eax
144
145 pop ebx
146 retn
147ENDPROC EMGCEmulateCmpXchg
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette