- updated sample code for user plugins

This commit is contained in:
Volker Ruppert 2009-01-05 17:02:25 +00:00
parent 8aa8b1a3db
commit 6fd3cf2ecf

View File

@ -9,6 +9,9 @@ Detailed description:
It contains enough code for testing the existing user plugin support
in Bochs and creates a device that installs a 32-bit r/w register at
i/o address 0x1000.
This example also show how to install and handle user-defined config
options for bochsrc, command line and the config interface. In this
demo it is used to specify the reset value.
For user plugin support Bochs must be configured with plugins enabled.
Compiling with plugin support is known to work on Linux and Windows
(Cygwin or MinGW/MSYS).
@ -16,7 +19,7 @@ Detailed description:
Patch was created with:
diff -u
Apply patch to what version:
cvs checked out on DATE
cvs checked out on 5 Jan 2009
Instructions:
To patch, go to main bochs directory.
Type "patch -p0 < THIS_PATCH_FILE".
@ -36,7 +39,7 @@ diff -urN ../bochs/configure.in ./configure.in
+ host/linux/pcidev/Makefile user-plugin/Makefile)
diff -urN ../bochs/user-plugin/Makefile.in ./user-plugin/Makefile.in
--- ../bochs/user-plugin/Makefile.in 1970-01-01 01:00:00.000000000 +0100
+++ ./user-plugin/Makefile.in 2009-01-03 12:16:40.000000000 +0100
+++ ./user-plugin/Makefile.in 2009-01-03 17:51:43.000000000 +0100
@@ -0,0 +1,108 @@
+# Copyright (C) 2009 Volker Ruppert
+#
@ -50,9 +53,9 @@ diff -urN ../bochs/user-plugin/Makefile.in ./user-plugin/Makefile.in
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+# Makefile for the user plugin example of bochs
+
@ -148,8 +151,8 @@ diff -urN ../bochs/user-plugin/Makefile.in ./user-plugin/Makefile.in
+ ../gui/keymap.h ../instrument/stubs/instrument.h testdev.h
diff -urN ../bochs/user-plugin/testdev.cc ./user-plugin/testdev.cc
--- ../bochs/user-plugin/testdev.cc 1970-01-01 01:00:00.000000000 +0100
+++ ./user-plugin/testdev.cc 2009-01-03 10:03:18.000000000 +0100
@@ -0,0 +1,93 @@
+++ ./user-plugin/testdev.cc 2009-01-05 17:43:53.000000000 +0100
@@ -0,0 +1,120 @@
+// Copyright (C) 2009 Volker Ruppert
+//
+// This library is free software; you can redistribute it and/or
@ -162,9 +165,9 @@ diff -urN ../bochs/user-plugin/testdev.cc ./user-plugin/testdev.cc
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+// User plugin example (see patch description for details)
+
@ -182,21 +185,51 @@ diff -urN ../bochs/user-plugin/testdev.cc ./user-plugin/testdev.cc
+#define LOG_THIS theTestDevice->
+
+bx_testdev_c *theTestDevice = NULL;
+char *options = NULL;
+
+Bit32s testdev_options_parser(const char *context, int num_params, char *params[]);
+Bit32s testdev_options_save(FILE *fp);
+
+int libuser_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
+{
+ theTestDevice = new bx_testdev_c();
+ BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theTestDevice, "testdev");
+ options = new char[strlen(argv[0])+1];
+ strcpy(options, argv[0]);
+ // add new configuration parameter for the config interface
+ bx_param_c *root_param = SIM->get_param("user");
+ bx_list_c *menu = new bx_list_c(root_param, "testdev", "Test Device");
+ menu->get_options()->set(bx_list_c::SHOW_PARENT);
+ new bx_param_num_c(menu, "test", "Test Parameter", "", 0, BX_MAX_BIT32U, 0);
+ // register user-defined option for bochsrc and command line
+ SIM->register_user_option("testdev", testdev_options_parser, testdev_options_save);
+
+ return(0); // Success
+}
+
+void libuser_LTX_plugin_fini(void)
+{
+ SIM->unregister_user_option("testdev");
+ bx_list_c *menu = (bx_list_c*)SIM->get_param("user");
+ menu->remove("testdev");
+ delete theTestDevice;
+ delete [] options;
+}
+
+Bit32s testdev_options_parser(const char *context, int num_params, char *params[])
+{
+ if (!strcmp(params[0], "testdev")) {
+ if (!strncmp(params[1], "test=", 5)) {
+ SIM->get_param_num("user.testdev.test")->set(atoi(&params[1][5]));
+ } else {
+ BX_ERROR(("%s: testdev: unknown parameter '%s'", context, params[1]));
+ }
+ } else {
+ BX_ERROR(("%s: unknown directive '%s'", context, params[0]));
+ }
+ return 0;
+}
+
+Bit32s testdev_options_save(FILE *fp)
+{
+ fprintf(fp, "testdev: test=%d\n", SIM->get_param_num("user.testdev.test")->get());
+ return 0;
+}
+
+bx_testdev_c::bx_testdev_c(void)
@ -212,16 +245,13 @@ diff -urN ../bochs/user-plugin/testdev.cc ./user-plugin/testdev.cc
+
+void bx_testdev_c::init(void)
+{
+ if (strlen(options) > 0) {
+ BX_INFO(("options not handled yet: %s", options));
+ }
+ DEV_register_ioread_handler(this, read_handler, 0x1000, "Test Device", 4);
+ DEV_register_iowrite_handler(this, write_handler, 0x1000, "Test Device", 4);
+}
+
+void bx_testdev_c::reset(unsigned type)
+{
+ BX_USER_THIS s.reg0 = 0;
+ BX_USER_THIS s.reg0 = SIM->get_param_num("user.testdev.test")->get();
+}
+
+void bx_testdev_c::register_state(void)
@ -245,7 +275,7 @@ diff -urN ../bochs/user-plugin/testdev.cc ./user-plugin/testdev.cc
+}
diff -urN ../bochs/user-plugin/testdev.h ./user-plugin/testdev.h
--- ../bochs/user-plugin/testdev.h 1970-01-01 01:00:00.000000000 +0100
+++ ./user-plugin/testdev.h 2009-01-02 18:03:31.000000000 +0100
+++ ./user-plugin/testdev.h 2009-01-03 17:51:43.000000000 +0100
@@ -0,0 +1,40 @@
+// Copyright (C) 2009 Volker Ruppert
+//
@ -259,9 +289,9 @@ diff -urN ../bochs/user-plugin/testdev.h ./user-plugin/testdev.h
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#ifndef BX_TESTDEV_H
+#define BX_TESTDEV_H