1
/*********************************************************
2
* Copyright (C) 2005 VMware, Inc. All rights reserved.
4
* The contents of this file are subject to the terms of the Common
5
* Development and Distribution License (the "License") version 1.0
6
* and no later version. You may not use this file except in
7
* compliance with the License.
9
* You can obtain a copy of the License at
10
* http://www.opensource.org/licenses/cddl1.php
12
* See the License for the specific language governing permissions
13
* and limitations under the License.
15
*********************************************************/
20
* Implements the real work for guest-side backdoor for GCC, 64-bit
21
* target (supports inline ASM, GAS syntax). The asm sections are marked
22
* volatile since vmware can change the registers content without the
23
* compiler knowing it.
25
* See backdoorGCC32.c (from which this code was mostly copied) for
26
* details on why the ASM is written this way. Also note that it might be
27
* possible to write the asm blocks using the symbolic operand specifiers
28
* in such a way that the same asm would generate correct code for both
29
* 32-bit and 64-bit targets, but I'm too lazy to figure it all out.
37
#include "backdoorInt.h"
41
*----------------------------------------------------------------------------
45
* Send a low-bandwidth basic request (16 bytes) to vmware, and return its
49
* Host-side response returned in bp IN/OUT parameter.
54
*----------------------------------------------------------------------------
58
Backdoor_InOut(Backdoor_proto *myBp) // IN/OUT
64
"movq 40(%%rax), %%rdi" "\n\t"
65
"movq 32(%%rax), %%rsi" "\n\t"
66
"movq 24(%%rax), %%rdx" "\n\t"
67
"movq 16(%%rax), %%rcx" "\n\t"
68
"movq 8(%%rax), %%rbx" "\n\t"
69
"movq (%%rax), %%rax" "\n\t"
70
"inl %%dx, %%eax" "\n\t" /* NB: There is no inq instruction */
71
"xchgq %%rax, (%%rsp)" "\n\t"
72
"movq %%rdi, 40(%%rax)" "\n\t"
73
"movq %%rsi, 32(%%rax)" "\n\t"
74
"movq %%rdx, 24(%%rax)" "\n\t"
75
"movq %%rcx, 16(%%rax)" "\n\t"
76
"movq %%rbx, 8(%%rax)" "\n\t"
81
* vmware can modify the whole VM state without the compiler knowing
82
* it. So far it does not modify EFLAGS. --hpreg
84
: "rbx", "rcx", "rdx", "rsi", "rdi", "memory"
90
*-----------------------------------------------------------------------------
95
* Send a high-bandwidth basic request to vmware, and return its
99
* Host-side response returned in bp IN/OUT parameter.
102
* Pokes the high-bandwidth backdoor port.
104
*-----------------------------------------------------------------------------
108
BackdoorHbIn(Backdoor_proto_hb *myBp) // IN/OUT
112
__asm__ __volatile__(
116
"movq 48(%%rax), %%rbp" "\n\t"
117
"movq 40(%%rax), %%rdi" "\n\t"
118
"movq 32(%%rax), %%rsi" "\n\t"
119
"movq 24(%%rax), %%rdx" "\n\t"
120
"movq 16(%%rax), %%rcx" "\n\t"
121
"movq 8(%%rax), %%rbx" "\n\t"
122
"movq (%%rax), %%rax" "\n\t"
125
"xchgq %%rax, (%%rsp)" "\n\t"
126
"movq %%rbp, 48(%%rax)" "\n\t"
127
"movq %%rdi, 40(%%rax)" "\n\t"
128
"movq %%rsi, 32(%%rax)" "\n\t"
129
"movq %%rdx, 24(%%rax)" "\n\t"
130
"movq %%rcx, 16(%%rax)" "\n\t"
131
"movq %%rbx, 8(%%rax)" "\n\t"
132
"popq (%%rax)" "\n\t"
138
* vmware can modify the whole VM state without the compiler knowing
141
: "rbx", "rcx", "rdx", "rsi", "rdi", "memory", "cc"
147
BackdoorHbOut(Backdoor_proto_hb *myBp) // IN/OUT
151
__asm__ __volatile__(
155
"movq 48(%%rax), %%rbp" "\n\t"
156
"movq 40(%%rax), %%rdi" "\n\t"
157
"movq 32(%%rax), %%rsi" "\n\t"
158
"movq 24(%%rax), %%rdx" "\n\t"
159
"movq 16(%%rax), %%rcx" "\n\t"
160
"movq 8(%%rax), %%rbx" "\n\t"
161
"movq (%%rax), %%rax" "\n\t"
164
"xchgq %%rax, (%%rsp)" "\n\t"
165
"movq %%rbp, 48(%%rax)" "\n\t"
166
"movq %%rdi, 40(%%rax)" "\n\t"
167
"movq %%rsi, 32(%%rax)" "\n\t"
168
"movq %%rdx, 24(%%rax)" "\n\t"
169
"movq %%rcx, 16(%%rax)" "\n\t"
170
"movq %%rbx, 8(%%rax)" "\n\t"
171
"popq (%%rax)" "\n\t"
176
: "rbx", "rcx", "rdx", "rsi", "rdi", "memory", "cc"