- added basic user plugin support (TODO: add sample code)

This commit is contained in:
Volker Ruppert 2009-01-02 11:51:03 +00:00
parent a46cbc6e67
commit b23e7bf6a0
7 changed files with 110 additions and 11 deletions

View File

@ -784,6 +784,13 @@ i440fxsupport: enabled=1
#======================================================================= #=======================================================================
#gdbstub: enabled=0, port=1234, text_base=0, data_base=0, bss_base=0 #gdbstub: enabled=0, port=1234, text_base=0, data_base=0, bss_base=0
#=======================================================================
# USER_PLUGIN:
# Load user-defined plugin. This option is available only if Bochs is
# compiled with plugin support. Maximum 8 different plugins are supported.
#=======================================================================
#user_plugin: name=testdev, option=test
#======================================================================= #=======================================================================
# for Macintosh, use the style of pathnames in the following # for Macintosh, use the style of pathnames in the following
# examples. # examples.

View File

@ -1,4 +1,4 @@
$Id: PARAM_TREE.txt,v 1.16 2008-12-28 21:01:18 sshwarts Exp $ $Id: PARAM_TREE.txt,v 1.17 2009-01-02 11:51:02 vruppert Exp $
Starting from Bochs 2.3 the parameters are organized in a tree structure Starting from Bochs 2.3 the parameters are organized in a tree structure
instead of a huge flat list. The parameter tree was required for implementing instead of a huge flat list. The parameter tree was required for implementing
@ -217,6 +217,12 @@ misc
text_base text_base
data_base data_base
bss_base bss_base
user_plugin
1
name
options
2 ... 8
(same options as misc.user_plugin.1)
log log
filename filename

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: bochs.h,v 1.236 2008-12-05 22:34:42 sshwarts Exp $ // $Id: bochs.h,v 1.237 2009-01-02 11:51:03 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2002 MandrakeSoft S.A. // Copyright (C) 2002 MandrakeSoft S.A.
@ -519,6 +519,7 @@ extern bx_bool bx_gui_sighandler;
#define BX_N_PARALLEL_PORTS 2 #define BX_N_PARALLEL_PORTS 2
#define BX_N_USB_HUBS 1 #define BX_N_USB_HUBS 1
#define BX_N_PCI_SLOTS 5 #define BX_N_PCI_SLOTS 5
#define BX_N_USER_PLUGINS 8
void bx_center_print(FILE *file, const char *line, unsigned maxwidth); void bx_center_print(FILE *file, const char *line, unsigned maxwidth);

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: config.cc,v 1.144 2008-12-28 20:53:31 sshwarts Exp $ // $Id: config.cc,v 1.145 2009-01-02 11:51:03 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2002 MandrakeSoft S.A. // Copyright (C) 2002 MandrakeSoft S.A.
@ -41,6 +41,9 @@
int bochsrc_include_count = 0; int bochsrc_include_count = 0;
#if BX_PLUGINS
Bit8u bx_user_plugin_count = 0;
#endif
#define LOG_THIS genlog-> #define LOG_THIS genlog->
@ -1619,6 +1622,24 @@ void bx_init_options()
0); 0);
enabled->set_dependent_list(menu->clone()); enabled->set_dependent_list(menu->clone());
#if BX_PLUGINS
// user plugin options
menu = new bx_list_c(misc, "user_plugin", "User Plugin Options", BX_N_USER_PLUGINS);
menu->get_options()->set(bx_list_c::SHOW_PARENT | bx_list_c::USE_BOX_TITLE);
for (i=0; i<BX_N_USER_PLUGINS; i++) {
sprintf(name, "%d", i+1);
sprintf(descr, "User-defined plugin device #%d", i+1);
sprintf(label, "User Plugin #%d", i+1);
bx_list_c *plugin = new bx_list_c(menu, name, label, 2);
new bx_param_string_c(plugin, "name", "Plugin name",
"Name of user plugin to load",
"", BX_PATHNAME_LEN);
new bx_param_string_c(plugin, "options", "Plugin options",
"Configuration options for user plugin",
"", BX_PATHNAME_LEN);
}
#endif
// log options subtree // log options subtree
menu = new bx_list_c(root_param, "log", "Logfile Options"); menu = new bx_list_c(root_param, "log", "Logfile Options");
@ -1704,6 +1725,10 @@ void bx_reset_options()
// logfile // logfile
SIM->get_param("log")->reset(); SIM->get_param("log")->reset();
#if BX_PLUGINS
bx_user_plugin_count = 0;
#endif
} }
int bx_read_configuration(const char *rcfile) int bx_read_configuration(const char *rcfile)
@ -3156,6 +3181,26 @@ static int parse_line_formatted(const char *context, int num_params, char *param
} }
} }
} }
#if BX_PLUGINS
else if (!strcmp(params[0], "user_plugin")) {
char tmpname[80];
if (bx_user_plugin_count < BX_N_USER_PLUGINS) {
sprintf(tmpname, "misc.user_plugin.%d", ++bx_user_plugin_count);
base = (bx_list_c*) SIM->get_param(tmpname);
for (i=1; i<num_params; i++) {
if (!strncmp(params[i], "name=", 5)) {
SIM->get_param_string("name", base)->set(&params[i][5]);
} else if (!strncmp(params[i], "options=", 8)) {
SIM->get_param_string("options", base)->set(&params[i][8]);
} else {
PARSE_ERR(("%s: unknown user plugin parameter '%s'", context, params[i]));
}
}
} else {
PARSE_ERR(("%s: too many user plugins", context));
}
}
#endif
// user-defined options handled by registered functions // user-defined options handled by registered functions
else if ((i = SIM->find_user_option(params[0])) >= 0) else if ((i = SIM->find_user_option(params[0])) >= 0)
{ {
@ -3277,6 +3322,18 @@ int bx_write_usb_options(FILE *fp, bx_list_c *base, int n)
return 0; return 0;
} }
#if BX_PLUGINS
int bx_write_user_plugin_options(FILE *fp, bx_list_c *base)
{
if (strlen(SIM->get_param_string("name", base)->getptr()) > 0) {
fprintf(fp, "user_plugin: name=%s, options=%s\n",
SIM->get_param_string("name", base)->getptr(),
SIM->get_param_string("options", base)->getptr());
}
return 0;
}
#endif
int bx_write_pnic_options(FILE *fp, bx_list_c *base) int bx_write_pnic_options(FILE *fp, bx_list_c *base)
{ {
fprintf (fp, "pnic: enabled=%d", SIM->get_param_bool("enabled", base)->get()); fprintf (fp, "pnic: enabled=%d", SIM->get_param_bool("enabled", base)->get());
@ -3448,6 +3505,14 @@ int bx_write_configuration(const char *rc, int overwrite)
if (fp == NULL) return -1; if (fp == NULL) return -1;
// finally it's open and we can start writing. // finally it's open and we can start writing.
fprintf(fp, "# configuration file generated by Bochs\n"); fprintf(fp, "# configuration file generated by Bochs\n");
#if BX_PLUGINS
// user plugins
for (i=0; i<BX_N_USER_PLUGINS; i++) {
sprintf(tmpdev, "misc.user_plugin.%d", i+1);
base = (bx_list_c*) SIM->get_param(tmpdev);
bx_write_user_plugin_options(fp, base);
}
#endif
fprintf(fp, "config_interface: %s\n", SIM->get_param_enum(BXPN_SEL_CONFIG_INTERFACE)->get_selected()); fprintf(fp, "config_interface: %s\n", SIM->get_param_enum(BXPN_SEL_CONFIG_INTERFACE)->get_selected());
fprintf(fp, "display_library: %s", SIM->get_param_enum(BXPN_SEL_DISPLAY_LIBRARY)->get_selected()); fprintf(fp, "display_library: %s", SIM->get_param_enum(BXPN_SEL_DISPLAY_LIBRARY)->get_selected());
strptr = SIM->get_param_string(BXPN_DISPLAYLIB_OPTIONS)->getptr(); strptr = SIM->get_param_string(BXPN_DISPLAYLIB_OPTIONS)->getptr();

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: devices.cc,v 1.126 2008-12-30 18:11:13 vruppert Exp $ // $Id: devices.cc,v 1.127 2009-01-02 11:51:03 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2002 MandrakeSoft S.A. // Copyright (C) 2002 MandrakeSoft S.A.
@ -113,8 +113,12 @@ void bx_devices_c::init(BX_MEM_C *newmem)
{ {
unsigned i; unsigned i;
const char def_name[] = "Default"; const char def_name[] = "Default";
#if BX_PLUGINS
char tmpstr[80];
char *plugin;
#endif
BX_DEBUG(("Init $Id: devices.cc,v 1.126 2008-12-30 18:11:13 vruppert Exp $")); BX_DEBUG(("Init $Id: devices.cc,v 1.127 2009-01-02 11:51:03 vruppert Exp $"));
mem = newmem; mem = newmem;
/* set no-default handlers, will be overwritten by the real default handler */ /* set no-default handlers, will be overwritten by the real default handler */
@ -255,6 +259,18 @@ void bx_devices_c::init(BX_MEM_C *newmem)
PLUG_load_plugin(iodebug, PLUGTYPE_OPTIONAL); PLUG_load_plugin(iodebug, PLUGTYPE_OPTIONAL);
#endif #endif
#if BX_PLUGINS
// user plugins
for (i = 0; i < BX_N_USER_PLUGINS; i++) {
sprintf(tmpstr, "misc.user_plugin.%d.name", i+1);
plugin = SIM->get_param_string(tmpstr)->getptr();
if (strlen(plugin) > 0) {
sprintf(tmpstr, "misc.user_plugin.%d.options", i+1);
PLUG_load_user_plugin(plugin, SIM->get_param_string(tmpstr)->getptr());
}
}
#endif
#if BX_SUPPORT_PCI #if BX_SUPPORT_PCI
pluginPciBridge->init (); pluginPciBridge->init ();
pluginPci2IsaBridge->init (); pluginPci2IsaBridge->init ();

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: plugin.cc,v 1.26 2009-01-01 12:06:31 vruppert Exp $ // $Id: plugin.cc,v 1.27 2009-01-02 11:51:03 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// This file defines the plugin and plugin-device registration functions and // This file defines the plugin and plugin-device registration functions and
@ -326,6 +326,7 @@ plugin_t *plugin_unload(plugin_t *plugin)
lt_dlclose(plugin->handle); lt_dlclose(plugin->handle);
delete [] plugin->name; delete [] plugin->name;
delete [] plugin->args;
dead_plug = plugin; dead_plug = plugin;
plugin = plugin->next; plugin = plugin->next;
@ -561,11 +562,13 @@ bx_bool pluginDevicePresent(char *name)
/* Plugin system: Load one plugin */ /* Plugin system: Load one plugin */
/************************************************************************/ /************************************************************************/
int bx_load_plugin(const char *name, plugintype_t type) int bx_load_plugin(const char *name, const char *options, plugintype_t type)
{ {
char *namecopy = new char[1+strlen(name)]; char *namecopy = new char[1+strlen(name)];
char *optscopy = new char[1+strlen(options)];
strcpy(namecopy, name); strcpy(namecopy, name);
plugin_load(namecopy, "", type); strcpy(optscopy, options);
plugin_load(namecopy, optscopy, type);
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: plugin.h,v 1.65 2009-01-01 12:06:31 vruppert Exp $ // $Id: plugin.h,v 1.66 2009-01-02 11:51:03 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// This file provides macros and types needed for plugins. It is based on // This file provides macros and types needed for plugins. It is based on
@ -57,7 +57,8 @@ extern "C" {
#define DEV_reset_devices(type) {bx_devices.reset(type); } #define DEV_reset_devices(type) {bx_devices.reset(type); }
#define DEV_register_state() {bx_devices.register_state(); } #define DEV_register_state() {bx_devices.register_state(); }
#define DEV_after_restore_state() {bx_devices.after_restore_state(); } #define DEV_after_restore_state() {bx_devices.after_restore_state(); }
#define PLUG_load_plugin(name,type) {bx_load_plugin(#name,type);} #define PLUG_load_plugin(name,type) {bx_load_plugin(#name,"",type);}
#define PLUG_load_user_plugin(name,options) {bx_load_plugin(name,options,PLUGTYPE_USER);}
#define PLUG_unload_plugin(name) {bx_unload_plugin(#name);} #define PLUG_unload_plugin(name) {bx_unload_plugin(#name);}
#define DEV_register_ioread_handler(b,c,d,e,f) pluginRegisterIOReadHandler(b,c,d,e,f) #define DEV_register_ioread_handler(b,c,d,e,f) pluginRegisterIOReadHandler(b,c,d,e,f)
@ -337,7 +338,7 @@ BOCHSAPI extern Bit8u (*pluginWr_memType)(Bit32u addr);
void plugin_abort(void); void plugin_abort(void);
int bx_load_plugin(const char *name, plugintype_t type); int bx_load_plugin(const char *name, const char *options, plugintype_t type);
extern void bx_unload_plugin(const char *name); extern void bx_unload_plugin(const char *name);
extern void bx_init_plugins(void); extern void bx_init_plugins(void);
extern void bx_reset_plugins(unsigned); extern void bx_reset_plugins(unsigned);