~n-muench/ubuntu/quantal/open-vm-tools/open-vm-tools.may2.sid-sync

« back to all changes in this revision

Viewing changes to modules/linux/vmhgfs/backdoorGcc32.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-05-30 09:48:43 UTC
  • mfrom: (1.1.5 upstream) (2.4.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090530094843-gdpza57r5iqsf124
Tags: 2009.05.22-167859-1
MergingĀ upstreamĀ versionĀ 2009.05.22-167859.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*********************************************************
2
 
 * Copyright (C) 2005 VMware, Inc. All rights reserved.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify it
5
 
 * under the terms of the GNU General Public License as published by the
6
 
 * Free Software Foundation version 2 and no later version.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
 
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11
 
 * for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along
14
 
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
16
 
 *
17
 
 *********************************************************/
18
 
 
19
 
/*
20
 
 * backdoorGcc32.c --
21
 
 *
22
 
 *      Implements the real work for guest-side backdoor for GCC, 32-bit
23
 
 *      target (supports inline ASM, GAS syntax). The asm sections are marked
24
 
 *      volatile since vmware can change the registers content without the
25
 
 *      compiler knowing it.
26
 
 *
27
 
 *      XXX
28
 
 *      I tried to write this more cleanly, but:
29
 
 *        - There is no way to specify an "ebp" constraint
30
 
 *        - "ebp" is ignored when specified as cloberred register
31
 
 *        - gas barfs when there is more than 10 operands
32
 
 *        - gas 2.7.2.3, depending on the order of the operands, can
33
 
 *          mis-assemble without any warning
34
 
 *      --hpreg
35
 
 *
36
 
 *      Note that the problems with gas noted above might longer be relevant
37
 
 *      now that we've upgraded most of our compiler versions.
38
 
 *      --rrdharan
39
 
 */
40
 
 
41
 
#ifdef __cplusplus
42
 
extern "C" {
43
 
#endif
44
 
 
45
 
#include "backdoor.h"
46
 
#include "backdoorInt.h"
47
 
 
48
 
/*
49
 
 *----------------------------------------------------------------------------
50
 
 *
51
 
 * Backdoor_InOut --
52
 
 *
53
 
 *      Send a low-bandwidth basic request (16 bytes) to vmware, and return its
54
 
 *      reply (24 bytes).
55
 
 *
56
 
 * Results:
57
 
 *      Host-side response returned in bp IN/OUT parameter.
58
 
 *
59
 
 * Side effects:
60
 
 *      Pokes the backdoor.
61
 
 *
62
 
 *----------------------------------------------------------------------------
63
 
 */
64
 
 
65
 
void
66
 
Backdoor_InOut(Backdoor_proto *myBp) // IN/OUT
67
 
{
68
 
   uint32 dummy;
69
 
 
70
 
   __asm__ __volatile__(
71
 
#ifdef __PIC__
72
 
        "pushl %%ebx"           "\n\t"
73
 
#endif
74
 
        "pushl %%eax"           "\n\t"
75
 
        "movl 20(%%eax), %%edi" "\n\t"
76
 
        "movl 16(%%eax), %%esi" "\n\t"
77
 
        "movl 12(%%eax), %%edx" "\n\t"
78
 
        "movl  8(%%eax), %%ecx" "\n\t"
79
 
        "movl  4(%%eax), %%ebx" "\n\t"
80
 
        "movl   (%%eax), %%eax" "\n\t"
81
 
        "inl %%dx, %%eax"       "\n\t"
82
 
        "xchgl %%eax, (%%esp)"  "\n\t"
83
 
        "movl %%edi, 20(%%eax)" "\n\t"
84
 
        "movl %%esi, 16(%%eax)" "\n\t"
85
 
        "movl %%edx, 12(%%eax)" "\n\t"
86
 
        "movl %%ecx,  8(%%eax)" "\n\t"
87
 
        "movl %%ebx,  4(%%eax)" "\n\t"
88
 
        "popl          (%%eax)" "\n\t"
89
 
#ifdef __PIC__
90
 
        "popl %%ebx"            "\n\t"
91
 
#endif
92
 
      : "=a" (dummy)
93
 
      : "0" (myBp)
94
 
      /*
95
 
       * vmware can modify the whole VM state without the compiler knowing
96
 
       * it. So far it does not modify EFLAGS. --hpreg
97
 
       */
98
 
      :
99
 
#ifndef __PIC__
100
 
        "ebx",
101
 
#endif
102
 
        "ecx", "edx", "esi", "edi", "memory"
103
 
   );
104
 
}
105
 
 
106
 
 
107
 
/*
108
 
 *-----------------------------------------------------------------------------
109
 
 *
110
 
 * BackdoorHbIn  --
111
 
 * BackdoorHbOut --
112
 
 *
113
 
 *      Send a high-bandwidth basic request to vmware, and return its
114
 
 *      reply.
115
 
 *
116
 
 * Results:
117
 
 *      Host-side response returned in bp IN/OUT parameter.
118
 
 *
119
 
 * Side-effects:
120
 
 *      Pokes the high-bandwidth backdoor port.
121
 
 *
122
 
 *-----------------------------------------------------------------------------
123
 
 */
124
 
 
125
 
void
126
 
BackdoorHbIn(Backdoor_proto_hb *myBp) // IN/OUT
127
 
{
128
 
   uint32 dummy;
129
 
 
130
 
   __asm__ __volatile__(
131
 
#ifdef __PIC__
132
 
        "pushl %%ebx"           "\n\t"
133
 
#endif
134
 
        "pushl %%ebp"           "\n\t"
135
 
 
136
 
        "pushl %%eax"           "\n\t"
137
 
        "movl 24(%%eax), %%ebp" "\n\t"
138
 
        "movl 20(%%eax), %%edi" "\n\t"
139
 
        "movl 16(%%eax), %%esi" "\n\t"
140
 
        "movl 12(%%eax), %%edx" "\n\t"
141
 
        "movl  8(%%eax), %%ecx" "\n\t"
142
 
        "movl  4(%%eax), %%ebx" "\n\t"
143
 
        "movl   (%%eax), %%eax" "\n\t"
144
 
        "cld"                   "\n\t"
145
 
        "rep; insb"             "\n\t"
146
 
        "xchgl %%eax, (%%esp)"  "\n\t"
147
 
        "movl %%ebp, 24(%%eax)" "\n\t"
148
 
        "movl %%edi, 20(%%eax)" "\n\t"
149
 
        "movl %%esi, 16(%%eax)" "\n\t"
150
 
        "movl %%edx, 12(%%eax)" "\n\t"
151
 
        "movl %%ecx,  8(%%eax)" "\n\t"
152
 
        "movl %%ebx,  4(%%eax)" "\n\t"
153
 
        "popl          (%%eax)" "\n\t"
154
 
 
155
 
        "popl %%ebp"            "\n\t"
156
 
#ifdef __PIC__
157
 
        "popl %%ebx"            "\n\t"
158
 
#endif
159
 
      : "=a" (dummy)
160
 
      : "0" (myBp)
161
 
      /*
162
 
       * vmware can modify the whole VM state without the compiler knowing
163
 
       * it. --hpreg
164
 
       */
165
 
      : 
166
 
#ifndef __PIC__
167
 
        "ebx", 
168
 
#endif
169
 
        "ecx", "edx", "esi", "edi", "memory", "cc"
170
 
   );
171
 
}
172
 
 
173
 
 
174
 
void
175
 
BackdoorHbOut(Backdoor_proto_hb *myBp) // IN/OUT
176
 
{
177
 
   uint32 dummy;
178
 
 
179
 
   __asm__ __volatile__(
180
 
#ifdef __PIC__
181
 
        "pushl %%ebx"           "\n\t"
182
 
#endif
183
 
        "pushl %%ebp"           "\n\t"
184
 
 
185
 
        "pushl %%eax"           "\n\t"
186
 
        "movl 24(%%eax), %%ebp" "\n\t"
187
 
        "movl 20(%%eax), %%edi" "\n\t"
188
 
        "movl 16(%%eax), %%esi" "\n\t"
189
 
        "movl 12(%%eax), %%edx" "\n\t"
190
 
        "movl  8(%%eax), %%ecx" "\n\t"
191
 
        "movl  4(%%eax), %%ebx" "\n\t"
192
 
        "movl   (%%eax), %%eax" "\n\t"
193
 
        "cld"                   "\n\t"
194
 
        "rep; outsb"            "\n\t"
195
 
        "xchgl %%eax, (%%esp)"  "\n\t"
196
 
        "movl %%ebp, 24(%%eax)" "\n\t"
197
 
        "movl %%edi, 20(%%eax)" "\n\t"
198
 
        "movl %%esi, 16(%%eax)" "\n\t"
199
 
        "movl %%edx, 12(%%eax)" "\n\t"
200
 
        "movl %%ecx,  8(%%eax)" "\n\t"
201
 
        "movl %%ebx,  4(%%eax)" "\n\t"
202
 
        "popl          (%%eax)" "\n\t"
203
 
 
204
 
        "popl %%ebp"            "\n\t"
205
 
#ifdef __PIC__
206
 
        "popl %%ebx"            "\n\t"
207
 
#endif
208
 
      : "=a" (dummy)
209
 
      : "0" (myBp)
210
 
      :
211
 
#ifndef __PIC__
212
 
        "ebx",
213
 
#endif
214
 
        "ecx", "edx", "esi", "edi", "memory", "cc"
215
 
   );
216
 
}
217
 
 
218
 
#ifdef __cplusplus
219
 
}
220
 
#endif
221