~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201207201942

« back to all changes in this revision

Viewing changes to modules/solaris/vmhgfs/backdoorGcc64.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-03-20 10:19:00 UTC
  • mfrom: (1.1.4 upstream) (2.4.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090320101900-1o604camiubq2de8
Tags: 2009.03.18-154848-2
Correcting patch system depends (Closes: #520493).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2005 VMware, Inc. All rights reserved.
 
3
 *
 
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.
 
8
 *
 
9
 * You can obtain a copy of the License at
 
10
 *         http://www.opensource.org/licenses/cddl1.php
 
11
 *
 
12
 * See the License for the specific language governing permissions
 
13
 * and limitations under the License.
 
14
 *
 
15
 *********************************************************/
 
16
 
 
17
/*
 
18
 * backdoorGcc64.c --
 
19
 *
 
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.
 
24
 *
 
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.
 
30
 *      --rrdharan
 
31
 */
 
32
#ifdef __cplusplus
 
33
extern "C" {
 
34
#endif
 
35
 
 
36
#include "backdoor.h"
 
37
#include "backdoorInt.h"
 
38
 
 
39
 
 
40
/*
 
41
 *----------------------------------------------------------------------------
 
42
 *
 
43
 * Backdoor_InOut --
 
44
 *
 
45
 *      Send a low-bandwidth basic request (16 bytes) to vmware, and return its
 
46
 *      reply (24 bytes).
 
47
 *
 
48
 * Results:
 
49
 *      Host-side response returned in bp IN/OUT parameter.
 
50
 *
 
51
 * Side effects:
 
52
 *      Pokes the backdoor.
 
53
 *
 
54
 *----------------------------------------------------------------------------
 
55
 */
 
56
 
 
57
void
 
58
Backdoor_InOut(Backdoor_proto *myBp) // IN/OUT
 
59
{
 
60
   uint64 dummy;
 
61
 
 
62
   __asm__ __volatile__(
 
63
        "pushq %%rax"           "\n\t"
 
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"
 
77
        "popq          (%%rax)"
 
78
      : "=a" (dummy)
 
79
      : "0" (myBp)
 
80
      /*
 
81
       * vmware can modify the whole VM state without the compiler knowing
 
82
       * it. So far it does not modify EFLAGS. --hpreg
 
83
       */
 
84
      : "rbx", "rcx", "rdx", "rsi", "rdi", "memory"
 
85
   );
 
86
}
 
87
 
 
88
 
 
89
/*
 
90
 *-----------------------------------------------------------------------------
 
91
 *
 
92
 * BackdoorHbIn  --
 
93
 * BackdoorHbOut --
 
94
 *
 
95
 *      Send a high-bandwidth basic request to vmware, and return its
 
96
 *      reply.
 
97
 *
 
98
 * Results:
 
99
 *      Host-side response returned in bp IN/OUT parameter.
 
100
 *
 
101
 * Side-effects:
 
102
 *      Pokes the high-bandwidth backdoor port.
 
103
 *
 
104
 *-----------------------------------------------------------------------------
 
105
 */
 
106
 
 
107
void
 
108
BackdoorHbIn(Backdoor_proto_hb *myBp) // IN/OUT
 
109
{
 
110
   uint32 dummy;
 
111
 
 
112
   __asm__ __volatile__(
 
113
        "pushq %%rbp"           "\n\t"
 
114
 
 
115
        "pushq %%rax"           "\n\t"
 
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"
 
123
        "cld"                   "\n\t"
 
124
        "rep; insb"             "\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"
 
133
 
 
134
        "popq %%rbp"
 
135
      : "=a" (dummy)
 
136
      : "0" (myBp)
 
137
      /*
 
138
       * vmware can modify the whole VM state without the compiler knowing
 
139
       * it. --hpreg
 
140
       */
 
141
      : "rbx", "rcx", "rdx", "rsi", "rdi", "memory", "cc"
 
142
   );
 
143
}
 
144
 
 
145
 
 
146
void
 
147
BackdoorHbOut(Backdoor_proto_hb *myBp) // IN/OUT
 
148
{
 
149
   uint64 dummy;
 
150
 
 
151
   __asm__ __volatile__(
 
152
        "pushq %%rbp"           "\n\t"
 
153
 
 
154
        "pushq %%rax"           "\n\t"
 
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"
 
162
        "cld"                   "\n\t"
 
163
        "rep; outsb"            "\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"
 
172
 
 
173
        "popq %%rbp"
 
174
      : "=a" (dummy)
 
175
      : "0" (myBp)
 
176
      : "rbx", "rcx", "rdx", "rsi", "rdi", "memory", "cc"
 
177
   );
 
178
}
 
179
 
 
180
 
 
181
#ifdef __cplusplus
 
182
}
 
183
#endif