1
/*********************************************************
2
* Copyright (C) 2005 VMware, Inc. All rights reserved.
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.
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
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
17
*********************************************************/
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.
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
36
* Note that the problems with gas noted above might longer be relevant
37
* now that we've upgraded most of our compiler versions.
46
#include "backdoorInt.h"
49
*----------------------------------------------------------------------------
53
* Send a low-bandwidth basic request (16 bytes) to vmware, and return its
57
* Host-side response returned in bp IN/OUT parameter.
62
*----------------------------------------------------------------------------
66
Backdoor_InOut(Backdoor_proto *myBp) // IN/OUT
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"
95
* vmware can modify the whole VM state without the compiler knowing
96
* it. So far it does not modify EFLAGS. --hpreg
102
"ecx", "edx", "esi", "edi", "memory"
108
*-----------------------------------------------------------------------------
113
* Send a high-bandwidth basic request to vmware, and return its
117
* Host-side response returned in bp IN/OUT parameter.
120
* Pokes the high-bandwidth backdoor port.
122
*-----------------------------------------------------------------------------
126
BackdoorHbIn(Backdoor_proto_hb *myBp) // IN/OUT
130
__asm__ __volatile__(
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"
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"
162
* vmware can modify the whole VM state without the compiler knowing
169
"ecx", "edx", "esi", "edi", "memory", "cc"
175
BackdoorHbOut(Backdoor_proto_hb *myBp) // IN/OUT
179
__asm__ __volatile__(
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"
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"
214
"ecx", "edx", "esi", "edi", "memory", "cc"