~ubuntu-branches/ubuntu/saucy/bochs/saucy-proposed

« back to all changes in this revision

Viewing changes to patches/patch.example-user-plugin

  • Committer: Bazaar Package Importer
  • Author(s): David Futcher
  • Date: 2009-04-30 07:46:11 UTC
  • mfrom: (1.1.11 upstream) (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090430074611-6dih80a5mk2uvxhk
Tags: 2.3.7+20090416-1ubuntu1
* Merge from debian unstable (LP: #370427), remaining changes:
  - debian/patches/12_no-ssp.patch: Build bios with -fno-stack-protector
  - Add Replaces/Conflicts for bochsbios-qemu (<< 2.3.6-2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
----------------------------------------------------------------------
 
2
Patch name: patch.example-user-plugin
 
3
Author:     Volker Ruppert
 
4
Date:       3 Jan 2009
 
5
Status:     Demo
 
6
 
 
7
Detailed description:
 
8
  This sample code can be used as a framework for writing user plugins.
 
9
  It contains enough code for testing the existing user plugin support
 
10
  in Bochs and creates a device that installs a 32-bit r/w register at
 
11
  i/o address 0x1000.
 
12
  This example also shows how to install and handle user-defined config
 
13
  options for bochsrc, command line and the config interface. In this
 
14
  demo it is used to specify the reset value.
 
15
  For user plugin support Bochs must be configured with plugins enabled.
 
16
  Compiling with plugin support is known to work on Linux and Windows
 
17
  (Cygwin or MinGW/MSYS). Bochs supports loading of up to 16 different
 
18
  user plugins when starting up. Loading / removing plugins at runtime
 
19
  is not yet supported.
 
20
 
 
21
Patch was created with:
 
22
  diff -u
 
23
Apply patch to what version:
 
24
  cvs checked out on 09 Feb 2009
 
25
Instructions:
 
26
  To patch, go to main bochs directory.
 
27
  Type "patch -p0 < THIS_PATCH_FILE".
 
28
  Regenerate the configure script and compile Bochs as usual
 
29
  cd user-plugin
 
30
  make
 
31
  make install
 
32
----------------------------------------------------------------------
 
33
diff -urN ../bochs/configure.in ./configure.in
 
34
--- ../bochs/configure.in       2009-02-02 14:02:47.000000000 +0100
 
35
+++ ./configure.in      2009-02-09 10:49:14.000000000 +0100
 
36
@@ -3126,4 +3126,4 @@
 
37
         build/linux/bochs-dlx \
 
38
         bxversion.h bxversion.rc build/macosx/Info.plist \
 
39
         build/win32/nsis/Makefile build/win32/nsis/bochs.nsi \
 
40
-        host/linux/pcidev/Makefile)
 
41
+        host/linux/pcidev/Makefile user-plugin/Makefile)
 
42
diff -urN ../bochs/user-plugin/Makefile.in ./user-plugin/Makefile.in
 
43
--- ../bochs/user-plugin/Makefile.in    1970-01-01 01:00:00.000000000 +0100
 
44
+++ ./user-plugin/Makefile.in   2009-02-09 10:49:14.000000000 +0100
 
45
@@ -0,0 +1,108 @@
 
46
+# Copyright (C) 2009  Volker Ruppert
 
47
+#
 
48
+# This library is free software; you can redistribute it and/or
 
49
+# modify it under the terms of the GNU Lesser General Public
 
50
+# License as published by the Free Software Foundation; either
 
51
+# version 2 of the License, or (at your option) any later version.
 
52
+#
 
53
+# This library is distributed in the hope that it will be useful,
 
54
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
55
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
56
+# Lesser General Public License for more details.
 
57
+#
 
58
+# You should have received a copy of the GNU Lesser General Public
 
59
+# License along with this library; if not, write to the Free Software
 
60
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
61
+
 
62
+# Makefile for the user plugin example of bochs
 
63
+
 
64
+
 
65
+@SUFFIX_LINE@
 
66
+
 
67
+prefix          = @prefix@
 
68
+exec_prefix     = @exec_prefix@
 
69
+srcdir          = @srcdir@
 
70
+VPATH = @srcdir@
 
71
+bindir          = @bindir@
 
72
+libdir          = @libdir@
 
73
+plugdir         = @libdir@/bochs/plugins
 
74
+datarootdir     = @datarootdir@
 
75
+mandir          = @mandir@
 
76
+man1dir         = $(mandir)/man1
 
77
+man5dir         = $(mandir)/man5
 
78
+docdir          = $(datarootdir)/doc/bochs
 
79
+sharedir        = $(datarootdir)/bochs
 
80
+top_builddir    = ..
 
81
+top_srcdir      = @top_srcdir@
 
82
+
 
83
+SHELL = /bin/sh
 
84
+
 
85
+@SET_MAKE@
 
86
+
 
87
+CXX = @CXX@
 
88
+CXXFLAGS = $(BX_INCDIRS) @CXXFLAGS@ @GUI_CXXFLAGS@
 
89
+
 
90
+LDFLAGS = @LDFLAGS@
 
91
+LIBS = @LIBS@
 
92
+RANLIB = @RANLIB@
 
93
+PLUGIN_PATH=@libdir@
 
94
+top_builddir    = ..
 
95
+LIBTOOL=@LIBTOOL@
 
96
+WIN32_DLL_IMPORT_LIBRARY=../dllexports.a
 
97
+
 
98
+BX_INCDIRS = -I.. -I$(srcdir)/.. -I../iodev -I$(srcdir)/../iodev -I../@INSTRUMENT_DIR@ -I$(srcdir)/../@INSTRUMENT_DIR@
 
99
+
 
100
+PLUGIN_OBJS = testdev.o
 
101
+
 
102
+plugins: $(PLUGIN_OBJS:@PLUGIN_LIBNAME_TRANSFORMATION@)
 
103
+
 
104
+install: @INSTALL_PLUGINS_VAR@
 
105
+
 
106
+install_libtool_plugins::
 
107
+       list=`echo *.la`; for i in $$list; do $(LIBTOOL) --mode=install install $$i $(DESTDIR)$(plugdir); done
 
108
+       $(LIBTOOL) --finish $(DESTDIR)$(plugdir)
 
109
+
 
110
+install_dll_plugins::
 
111
+       list=`echo *.dll`; for i in $$list; do cp $$i $(DESTDIR)$(plugdir); done
 
112
+
 
113
+# standard compile rule for C++ files
 
114
+.@CPP_SUFFIX@.o:
 
115
+       $(CXX) @DASH@c  $(CXXFLAGS) $(LOCAL_CXXFLAGS) @CXXFP@$< @OFP@$@
 
116
+
 
117
+##### building plugins with libtool
 
118
+%.lo: %.@CPP_SUFFIX@
 
119
+       $(LIBTOOL) --mode=compile $(CXX) -c $(CXXFLAGS) $(LOCAL_CXXFLAGS) $< -o $@
 
120
+
 
121
+libbx_%.la: %.lo
 
122
+       $(LIBTOOL) --mode=link $(CXX) -module $< -o $@ -rpath $(PLUGIN_PATH)
 
123
+
 
124
+#### building DLLs for win32  (tested on cygwin only)
 
125
+bx_%.dll: %.o
 
126
+       $(CXX) $(CXXFLAGS) -shared -o $@ $< $(WIN32_DLL_IMPORT_LIBRARY)
 
127
+
 
128
+clean:
 
129
+       @RMCOMMAND@ -rf .libs *.lo *.o *.la *.a *.dll
 
130
+
 
131
+dist-clean: clean
 
132
+       @RMCOMMAND@ Makefile
 
133
+
 
134
+###########################################
 
135
+# dependencies generated by
 
136
+#  gcc -MM -I.. -I../instrument/stubs *.cc | sed -e 's/\.cc/.@CPP_SUFFIX@/g'
 
137
+#  gcc -MM -I.. -I../instrument/stubs *.cc | \
 
138
+#     sed -e 's/\.cc/.@CPP_SUFFIX@/g' -e 's/\.o:/.lo:/g'
 
139
+#
 
140
+# This means that every source file is listed twice, once with a .o rule
 
141
+# and then again with an identical .lo rule.  The .lo rules are used when
 
142
+# building plugins.
 
143
+###########################################
 
144
+testdev.o: testdev.@CPP_SUFFIX@ ../iodev/iodev.h ../bochs.h ../config.h ../osdep.h \
 
145
+  ../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
 
146
+  ../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
 
147
+  ../extplugin.h ../ltdl.h ../gui/gui.h ../gui/textconfig.h \
 
148
+  ../gui/keymap.h ../instrument/stubs/instrument.h testdev.h
 
149
+testdev.lo: testdev.@CPP_SUFFIX@ ../iodev/iodev.h ../bochs.h ../config.h ../osdep.h \
 
150
+  ../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
 
151
+  ../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
 
152
+  ../extplugin.h ../ltdl.h ../gui/gui.h ../gui/textconfig.h \
 
153
+  ../gui/keymap.h ../instrument/stubs/instrument.h testdev.h
 
154
diff -urN ../bochs/user-plugin/testdev.cc ./user-plugin/testdev.cc
 
155
--- ../bochs/user-plugin/testdev.cc     1970-01-01 01:00:00.000000000 +0100
 
156
+++ ./user-plugin/testdev.cc    2009-02-09 10:49:14.000000000 +0100
 
157
@@ -0,0 +1,118 @@
 
158
+// Copyright (C) 2009  Volker Ruppert
 
159
+//
 
160
+// This library is free software; you can redistribute it and/or
 
161
+// modify it under the terms of the GNU Lesser General Public
 
162
+// License as published by the Free Software Foundation; either
 
163
+// version 2 of the License, or (at your option) any later version.
 
164
+//
 
165
+// This library is distributed in the hope that it will be useful,
 
166
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
167
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
168
+// Lesser General Public License for more details.
 
169
+//
 
170
+// You should have received a copy of the GNU Lesser General Public
 
171
+// License along with this library; if not, write to the Free Software
 
172
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
173
+
 
174
+// User plugin example (see patch description for details)
 
175
+
 
176
+// Define BX_PLUGGABLE in files that can be compiled into plugins.  For
 
177
+// platforms that require a special tag on exported symbols, BX_PLUGGABLE
 
178
+// is used to know when we are exporting symbols and when we are importing.
 
179
+#define BX_PLUGGABLE
 
180
+
 
181
+// Don't include other devices headers
 
182
+#define NO_DEVICE_INCLUDES
 
183
+
 
184
+#include "iodev.h"
 
185
+#include "testdev.h"
 
186
+
 
187
+#define LOG_THIS theTestDevice->
 
188
+
 
189
+bx_testdev_c *theTestDevice = NULL;
 
190
+
 
191
+Bit32s testdev_options_parser(const char *context, int num_params, char *params[]);
 
192
+Bit32s testdev_options_save(FILE *fp);
 
193
+
 
194
+int libuser_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
 
195
+{
 
196
+  theTestDevice = new bx_testdev_c();
 
197
+  BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theTestDevice, "testdev");
 
198
+  // add new configuration parameter for the config interface
 
199
+  bx_param_c *root_param = SIM->get_param("user");
 
200
+  bx_list_c *menu = new bx_list_c(root_param, "testdev", "Test Device");
 
201
+  menu->get_options()->set(bx_list_c::SHOW_PARENT);
 
202
+  new bx_param_num_c(menu, "test", "Test Parameter", "", 0, BX_MAX_BIT32U, 0);
 
203
+  // register user-defined option for bochsrc and command line
 
204
+  SIM->register_user_option("testdev", testdev_options_parser, testdev_options_save);
 
205
+  return(0); // Success
 
206
+}
 
207
+
 
208
+void libuser_LTX_plugin_fini(void)
 
209
+{
 
210
+  SIM->unregister_user_option("testdev");
 
211
+  bx_list_c *menu = (bx_list_c*)SIM->get_param("user");
 
212
+  menu->remove("testdev");
 
213
+  delete theTestDevice;
 
214
+}
 
215
+
 
216
+Bit32s testdev_options_parser(const char *context, int num_params, char *params[])
 
217
+{
 
218
+  if (!strcmp(params[0], "testdev")) {
 
219
+    if (!strncmp(params[1], "test=", 5)) {
 
220
+      SIM->get_param_num("user.testdev.test")->set(atoi(&params[1][5]));
 
221
+    } else {
 
222
+      BX_PANIC(("%s: testdev: unknown parameter '%s'", context, params[1]));
 
223
+    }
 
224
+  } else {
 
225
+    BX_PANIC(("%s: unknown directive '%s'", context, params[0]));
 
226
+  }
 
227
+  return 0;
 
228
+}
 
229
+
 
230
+Bit32s testdev_options_save(FILE *fp)
 
231
+{
 
232
+  fprintf(fp, "testdev: test=%d\n", SIM->get_param_num("user.testdev.test")->get());
 
233
+  return 0;
 
234
+}
 
235
+
 
236
+bx_testdev_c::bx_testdev_c(void)
 
237
+{
 
238
+  put("USER");
 
239
+}
 
240
+
 
241
+bx_testdev_c::~bx_testdev_c(void)
 
242
+{
 
243
+  // nothing here yet
 
244
+}
 
245
+
 
246
+void bx_testdev_c::init(void)
 
247
+{
 
248
+  DEV_register_ioread_handler(this, read_handler, 0x1000, "Test Device", 4);
 
249
+  DEV_register_iowrite_handler(this, write_handler, 0x1000, "Test Device", 4);
 
250
+}
 
251
+
 
252
+void bx_testdev_c::reset(unsigned type)
 
253
+{
 
254
+  BX_USER_THIS s.reg0 = SIM->get_param_num("user.testdev.test")->get();
 
255
+}
 
256
+
 
257
+void bx_testdev_c::register_state(void)
 
258
+{
 
259
+  bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "testdev", "Test Device", 1);
 
260
+  BXRS_HEX_PARAM_FIELD(list, reg0, BX_USER_THIS s.reg0);
 
261
+}
 
262
+
 
263
+Bit32u bx_testdev_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
 
264
+{
 
265
+  UNUSED(this_ptr);
 
266
+
 
267
+  return BX_USER_THIS s.reg0;
 
268
+}
 
269
+
 
270
+void bx_testdev_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
 
271
+{
 
272
+  UNUSED(this_ptr);
 
273
+
 
274
+  BX_USER_THIS s.reg0 = value;
 
275
+}
 
276
diff -urN ../bochs/user-plugin/testdev.h ./user-plugin/testdev.h
 
277
--- ../bochs/user-plugin/testdev.h      1970-01-01 01:00:00.000000000 +0100
 
278
+++ ./user-plugin/testdev.h     2009-02-09 10:49:14.000000000 +0100
 
279
@@ -0,0 +1,40 @@
 
280
+// Copyright (C) 2009  Volker Ruppert
 
281
+//
 
282
+// This library is free software; you can redistribute it and/or
 
283
+// modify it under the terms of the GNU Lesser General Public
 
284
+// License as published by the Free Software Foundation; either
 
285
+// version 2 of the License, or (at your option) any later version.
 
286
+//
 
287
+// This library is distributed in the hope that it will be useful,
 
288
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
289
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
290
+// Lesser General Public License for more details.
 
291
+//
 
292
+// You should have received a copy of the GNU Lesser General Public
 
293
+// License along with this library; if not, write to the Free Software
 
294
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
295
+
 
296
+#ifndef BX_TESTDEV_H
 
297
+#define BX_TESTDEV_H
 
298
+
 
299
+#define BX_USER_THIS theTestDevice->
 
300
+
 
301
+class bx_testdev_c : public bx_devmodel_c {
 
302
+public:
 
303
+  bx_testdev_c();
 
304
+  virtual ~bx_testdev_c();
 
305
+
 
306
+  virtual void init(void);
 
307
+  virtual void reset(unsigned type);
 
308
+  virtual void register_state(void);
 
309
+
 
310
+private:
 
311
+  static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
 
312
+  static void   write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
 
313
+
 
314
+  struct {
 
315
+    Bit32u reg0;
 
316
+  } s;
 
317
+};
 
318
+
 
319
+#endif