Skip to content

Commit

Permalink
Kernel: Move the VMWare helpers out of the IO namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
supercomputer7 authored and awesomekling committed Feb 5, 2020
1 parent 8e8f5c2 commit f6ce24e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
45 changes: 39 additions & 6 deletions Kernel/Devices/VMWareBackdoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,41 @@
#define VMMOUSE_REQUEST_ABSOLUTE 0x53424152

#define VMMOUSE_QEMU_VERSION 0x3442554a

#define VMWARE_MAGIC 0x564D5868
#define VMWARE_PORT 0x5658
#define VMWARE_PORT_HIGHBANDWIDTH 0x5659

//#define VMWAREBACKDOOR_DEBUG

inline void vmware_out(VMWareCommand& command)
{
command.magic = VMWARE_MAGIC;
command.port = VMWARE_PORT;
command.si = 0;
command.di = 0;
asm volatile("in %%dx, %0"
: "+a"(command.ax), "+b"(command.bx), "+c"(command.cx), "+d"(command.dx), "+S"(command.si), "+D"(command.di));
}

inline void vmware_high_bandwidth_send(VMWareCommand& command)
{

command.magic = VMWARE_MAGIC;
command.port = VMWARE_PORT_HIGHBANDWIDTH;

asm volatile("cld; rep; outsb"
: "+a"(command.ax), "+b"(command.bx), "+c"(command.cx), "+d"(command.dx), "+S"(command.si), "+D"(command.di));
}

inline void vmware_high_bandwidth_get(VMWareCommand& command)
{
command.magic = VMWARE_MAGIC;
command.port = VMWARE_PORT_HIGHBANDWIDTH;
asm volatile("cld; rep; insb"
: "+a"(command.ax), "+b"(command.bx), "+c"(command.cx), "+d"(command.dx), "+S"(command.si), "+D"(command.di));
}

static VMWareBackdoor* s_vmware_backdoor;

static bool is_initialized()
Expand Down Expand Up @@ -74,7 +107,7 @@ bool VMWareBackdoor::detect_presence()
VMWareCommand command;
command.bx = ~VMWARE_MAGIC;
command.command = VMWARE_CMD_GETVERSION;
IO::vmware_out(command);
vmware_out(command);
if (command.bx != VMWARE_MAGIC || command.ax == 0xFFFFFFFF)
return false;
return true;
Expand Down Expand Up @@ -140,20 +173,20 @@ void VMWareBackdoor::disable_absolute_vmmouse()
m_vmmouse_absolute = false;
}

void VMWareBackdoor::send_highbandwidth(VMWareCommand& command)
void VMWareBackdoor::send_high_bandwidth(VMWareCommand& command)
{
if (supported()) {
IO::vmware_highbandwidth_send(command);
vmware_high_bandwidth_send(command);
#ifdef VMWAREBACKDOOR_DEBUG
dbg() << "VMWareBackdoor Command High bandwidth Send Results: EAX " << String::format("%x", command.ax) << " EBX " << String::format("%x", command.bx) << " ECX " << String::format("%x", command.cx) << " EDX " << String::format("%x", command.dx);
#endif
}
}

void VMWareBackdoor::get_highbandwidth(VMWareCommand& command)
void VMWareBackdoor::get_high_bandwidth(VMWareCommand& command)
{
if (supported()) {
IO::vmware_highbandwidth_get(command);
vmware_high_bandwidth_get(command);
#ifdef VMWAREBACKDOOR_DEBUG
dbg() << "VMWareBackdoor Command High bandwidth Get Results: EAX " << String::format("%x", command.ax) << " EBX " << String::format("%x", command.bx) << " ECX " << String::format("%x", command.cx) << " EDX " << String::format("%x", command.dx);
#endif
Expand All @@ -163,7 +196,7 @@ void VMWareBackdoor::get_highbandwidth(VMWareCommand& command)
void VMWareBackdoor::send(VMWareCommand& command)
{
if (supported()) {
IO::vmware_out(command);
vmware_out(command);
#ifdef VMWAREBACKDOOR_DEBUG
dbg() << "VMWareBackdoor Command Send Results: EAX " << String::format("%x", command.ax) << " EBX " << String::format("%x", command.bx) << " ECX " << String::format("%x", command.cx) << " EDX " << String::format("%x", command.dx);
#endif
Expand Down
8 changes: 2 additions & 6 deletions Kernel/Devices/VMWareBackdoor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@

#include <AK/Types.h>

#define VMWARE_MAGIC 0x564D5868
#define VMWARE_PORT 0x5658
#define VMWARE_PORT_HIGHBANDWIDTH 0x5659

#define VMMOUSE_GETVERSION 10
#define VMMOUSE_DATA 39
#define VMMOUSE_STATUS 40
Expand Down Expand Up @@ -69,8 +65,8 @@ class VMWareBackdoor {
void send(VMWareCommand& command);

private:
void send_highbandwidth(VMWareCommand& command);
void get_highbandwidth(VMWareCommand& command);
void send_high_bandwidth(VMWareCommand& command);
void get_high_bandwidth(VMWareCommand& command);
VMWareBackdoor();
bool detect_presence();
bool detect_vmmouse();
Expand Down
24 changes: 0 additions & 24 deletions Kernel/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,6 @@ inline void repeated_out16(u16 port, const u8* data, int data_size)
: "d"(port));
}

inline void vmware_out(VMWareCommand& command)
{
command.magic = VMWARE_MAGIC;
command.port = VMWARE_PORT;
command.si = 0;
command.di = 0;
asm volatile("in %%dx, %0"
: "+a"(command.ax), "+b"(command.bx), "+c"(command.cx), "+d"(command.dx), "+S"(command.si), "+D"(command.di));
}

inline void vmware_highbandwidth_send(VMWareCommand& command) {

command.magic = VMWARE_MAGIC;
command.port = VMWARE_PORT_HIGHBANDWIDTH;

asm volatile("cld; rep; outsb" : "+a"(command.ax), "+b"(command.bx), "+c"(command.cx), "+d"(command.dx), "+S"(command.si), "+D"(command.di));
}

inline void vmware_highbandwidth_get(VMWareCommand& command) {
command.magic = VMWARE_MAGIC;
command.port = VMWARE_PORT_HIGHBANDWIDTH;
asm volatile("cld; rep; insb" : "+a"(command.ax), "+b"(command.bx), "+c"(command.cx), "+d"(command.dx), "+S"(command.si), "+D"(command.di));
}

inline void delay()
{
// ~3 microsecs
Expand Down

0 comments on commit f6ce24e

Please sign in to comment.