-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Don't forget to add your plugin to config.panda! | ||
|
||
# If you need custom CFLAGS or LIBS, set them up here | ||
# CFLAGS+= | ||
# LIBS+= | ||
|
||
# Example: this plugin has runtime symbol dependencies on plugin_x: | ||
# LIBS+=-L$(PLUGIN_TARGET_DIR) -l:panda_plugin_x.so | ||
# Also create a plugin_plugin.d file in this directory to ensure plugin_x | ||
# gets compiled before this plugin, example contents: | ||
# plugin-this_plugins_name : plugin-plugin_x | ||
# or if you're using the extra plugins dir: | ||
# extra-plugin-this_plugins_name : extra-plugin-plugin_x | ||
|
||
# The main rule for your plugin. List all object-file dependencies. | ||
$(PLUGIN_TARGET_DIR)/panda_$(PLUGIN_NAME).so: \ | ||
$(PLUGIN_OBJ_DIR)/$(PLUGIN_NAME).o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Plugin: NAME | ||
=========== | ||
|
||
Summary | ||
------- | ||
|
||
Arguments | ||
--------- | ||
|
||
Dependencies | ||
------------ | ||
|
||
APIs and Callbacks | ||
------------------ | ||
|
||
Example | ||
------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* PANDABEGINCOMMENT | ||
* | ||
* Authors: | ||
* Luke Craig luke.craig@ll.mit.edu | ||
* | ||
* This work is licensed under the terms of the GNU GPL, version 2. | ||
* See the COPYING file in the top-level directory. | ||
* | ||
PANDAENDCOMMENT */ | ||
// This needs to be defined before anything is included in order to get | ||
// the PRIx64 macro | ||
#define __STDC_FORMAT_MACROS | ||
|
||
#include "panda/plugin.h" | ||
#include <unordered_map> | ||
|
||
// These need to be extern "C" so that the ABI is compatible with | ||
// QEMU/PANDA, which is written in C | ||
extern "C" { | ||
bool init_plugin(void *); | ||
void uninit_plugin(void *); | ||
bool hypercall(CPUState *cpu); | ||
#include "hypercaller.h" | ||
} | ||
|
||
std::unordered_map<target_ulong, hypercall_t> hypercalls; | ||
|
||
void register_hypercall(target_ulong magic, hypercall_t hyp){ | ||
if (hypercalls.find(magic) == hypercalls.end()){ | ||
hypercalls[magic] = hyp; | ||
}else{ | ||
assert(false && "Hypercall already registered"); | ||
} | ||
} | ||
|
||
void unregister_hypercall(target_ulong magic){ | ||
hypercalls.erase(magic); | ||
} | ||
|
||
target_ulong get_magic(CPUState *cpu){ | ||
target_ulong magic; | ||
CPUArchState * env = (CPUArchState *)cpu->env_ptr; | ||
#if defined(TARGET_ARM) | ||
// r0 | ||
magic =env->regs[0]; | ||
#elif defined(TARGET_MIPS) | ||
// a0 | ||
magic =env->active_tc.gpr[4]; | ||
#elif defined(TARGET_I386) | ||
// eax | ||
magic = env->regs[R_EAX]; | ||
#elif defined(TARGET_PPC) | ||
// r0 | ||
magic = env->gpr[0]; | ||
#else | ||
#error "Unsupported target architecture" | ||
#endif | ||
return magic; | ||
} | ||
|
||
bool guest_hypercall(CPUState *cpu) { | ||
target_ulong magic = get_magic(cpu); | ||
if (hypercalls.find(magic) != hypercalls.end()){ | ||
hypercalls[magic](cpu); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool init_plugin(void *self) { | ||
panda_cb pcb = { .guest_hypercall = guest_hypercall}; | ||
panda_register_callback(self, PANDA_CB_GUEST_HYPERCALL, pcb); | ||
return true; | ||
} | ||
|
||
void uninit_plugin(void *self) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef __HYPERCALLER_H | ||
#define __HYPERCALLER_H | ||
// BEGIN_PYPANDA_NEEDS_THIS -- do not delete this comment bc pypanda | ||
// api autogen needs it. And don't put any compiler directives | ||
// between this and END_PYPANDA_NEEDS_THIS except includes of other | ||
// files in this directory that contain subsections like this one. | ||
|
||
typedef void (*hypercall_t)(CPUState *cpu); | ||
void register_hypercall(target_ulong magic, hypercall_t); | ||
void unregister_hypercall(target_ulong magic); | ||
|
||
// END_PYPANDA_NEEDS_THIS -- do not delete this comment! | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters