Bochs/bochs/README-plugins
Bryce Denney 227b565d91 - fix URL of documentation
- put off one more task until later
2002-12-13 19:44:26 +00:00

444 lines
22 KiB
Plaintext

README-plugins
This is the README file from the CVS branch called BRANCH_PLUGINS.
It will be hanging around in the main trunk for a short time while
we get things cleaned up. By version 2.0 it should be gone.
Anything that needs to be done, but cannot be done by 2.0 should
be written as a bug report/feature request on Source Forge.
-------------------------------------------------------------------------
BRANCH_PLUGINS
The branch is called BRANCH_PLUGINS. There is a normal tag called
BRANCH_PLUGINS_BASE that marks the point where the branch began. The
base marker will help at merge time.
This branch is a place to experiment with Bochs plugins. Bryce created
the branch on October 4, 2002, and he and Christophe began working on
Bochs plugins.
We started from Bryce's patch.plugins3, which was a patch from December 2001
that copied in some of the plugin architecture from plex86. Here are the
comments from that patch:
> Patch name: patch.plugins3
> Author: Bryce Denney
> Date: Wed Dec 12 17:56:11 EST 2001
>
> This patch replaces the Bochs keyboard with a slightly modified version
> of the plex86 keyboard device, which is implemented as a plugin. This
> is sort of a proof of concept, rather than anything that I'm about to
> check in. It uses GNU libtool to compile the plex86 keyboard code into
> a shared library, and installs that shared library in
> /tmp/bochslib/libplex-keyboard.so. Then the new code in plugin.cc (which
> is adapted from the plex86 plugin code) loads the libplex-keyboard library
> during initialization and installs the plex86 keyboard instead of the
> bochs keyboard.
>
> I chose the keyboard because it takes about 2 seconds to test that it's
> basically working, and because the bochs and plex86 implementations hadn't
> changed very much since they split.
>
> If you look at plex-keyboard.cc and plex-keyboard.h, it is fundamentally the
> same as the current plex86 code. I have changed lots of names from bx_* to
> plex_* just to reduce confusion and mayhem when I was compiling with both
> kbd implementations. I didn't change anything except to get it to compile.
Christophe had made a plugins5 patch, so he checked it in, with these
changes:
- plex86 keyboard device was marged with Bochs keyboard, as a plugin
- plugin.cc was cleaned up
- a device registration mechanism was set up
- the biosdev and unmapped devices were plugin-ized
TO DO BEFORE RELEASE 2.0:
- (LATER) some plugins, such as the GUI, PIT, SB, and NE2000, have several different
possible implementations. In this case, all implementations should be
children of a single stub class. The stub's methods produce errors or
panics if they are called, depending on the importance of the device.
There is always one instance of the stub class lying around, which will be
used if none of the implementation plugins is loaded. Either an optional
plugin or a user plugin can fill in these slots.
- platform specific issues
- (LATER) make sure LTDL works on VC++. It doesn't and won't without
significant work. Maybe it's easier to support VC++ with ifdefs in
plugin.cc rather than using ltdl at all. This will have to wait.
- (DONE) nmake build: we must use lib.exe, not $(LIBTOOL) $(CXX) stuff
- configure script work
- LTDL has a feature called dlpreload which sort of emulates dlopen
by linking all the modules statically and then emulating dlopen calls.
I don't see any value in this for plugins. If the platform cannot
support dlopen or some equivalent, let the configure script crash and
tell the user to configure without plugins instead.
- to support plugins on MacOSX, the user must install dlcompat. Otherwise
libtool's configure script will discover that no dlopen() or equivalent
function is found, and it will not be able to build/load plugins.
The configure script should bomb in this case, with an error that says
where to find dlcompat. dlcompat IS installed on SF compile farm in
/sw/include and /sw/lib.
- Understand/resolve simulation differences between CVS head and
BRANCH_PLUGINS. Simulation is slightly different.
- compare four versions
- BRANCH_PLUGINS with --enable-plugins
- BRANCH_PLUGINS without --enable-plugins
- BRANCH_PLUGINS_BASE
- CVS head
- these differences seem to be explained by a few things:
1. devices are initialized in a different order, so they are assigned
different timer id. For any events that occur at the same tick, the
timer handlers would get called in a different order. I believe I
have fixed the order of timer registration so that it matches, and
that cleaned up some simulation differences.
2. bx_gui->handle_events is now called from iodev/devices.cc instead of
from iodev/keyboard.cc.
3. bx_keyb_c::periodic() used to be called directly from devices.cc
but now the keyboard registers its own timer
- I have never seen any problems caused by the sim differences, but they
make me nervous. -Bryce
- (LATER) convert remaining devices
- (LATER) maybe the implementation class for each plugin device should go into
the .cc file instead of the header file. If all their methods are called
through the stub class virtual functions, and no external file has access to
the real non-stub class, then maybe there is no point in letting anybody
else see the real class at all? (If you do use the class you will get
undefined symbols when you compile for plugins anyway.) For the hard drive,
we could put bx_hard_drive_stub_c in harddrv.h, and any constants or types
that external files might need, and then put the real class, bx_hard_drive_c,
at the top of harddrv.cc.
- (LATER) eventually we need to clarify the connection between plugins and
devices. At the moment, each plugin creates exactly one device, but it does
not have to work that way.
- it would be more correct to mark the devices as core, optional, etc. than
to use a type field in the plugin struct. The reason that the type
(core,optional,user) is currently passed into the PLUG_load_plugin macro
and placed in the plugin struct instead of letting the device code decide
is: devices.cc is responsible for initting and resetting devices, so I
wanted devices.cc to decide whether the device would be managed by the
plugin infrastructure (init_all, reset_all) or not. This is not that
important yet, but when Volker wants to write a plugin with multiple
devices, we will need to sort it out.
- (LATER) make a way for users to replace a core plugin with one of their
choice.
- (LATER) implement user plugins. These are plugins that Bochs does not know
anything about at compile time. The user asks Bochs to load a plugin using
just its filename. It loads the plugin and registers any bx_params that
the user can configure, and either the text config interface or the
wxWindows interface can display this param list as a menu or dialog.
Then at simulation start time, we call init() on the user device and
it can be used like any other device.
- (LATER) make plugin CPU???
DONE:
- applied patch.plugins5
- updated makefile dependencies now that plugin.h is in there
- all guis converted to plugins
- 8 I/O devices are converted to plugins
- make the Makefile use libtool to build dynamic libraries
- use libtool's ltdl library to open and read dynamic libraries, since it
has cross platform support
- the Boolean/bx_bool thing will be resolved in the main branch. I have
made patch.replace-Boolean.gz which I will apply later, after the
plugins branch has been merged. This become more urgent because it
caused bug #623152 MacOSX: Triple Exception Booting win95
- take a look at the code generated by calls to virtual functions, to
check if there's huge overhead that I don't know about.
Answer: I don't believe there is that much extra overhead. If you call
a nonvirtual function, it must push all the args onto the stack, then
push the THIS pointer, then call the method using a known constant address.
With a virtual function, you push all the args onto the stack, then push
the THIS pointer, then do one extra memory reference to THIS+constant to read
the pointer to the virtual method, and call it. This is just what I
expected to find--no strange and magicial code was inserted by the
compiler in this case.
- wxWindows configuration interface and display works fine as a plugin now
- selection of config interface is controlled by the bochsrc line
"config_interface: NAME" and the parameter bx_options.Osel_config.
- selection of display library is controlled by the bochsrc line
"display_library: NAME" and the parameter bx_options.Osel_displaylib.
- renamed vga_library to display_library (Christophe's suggestion)
- add --with-all-libs option, which attempts to detect all the display
libraries that Bochs can compile with. You can use this with or without
plugins, compile with multiple guis in the same binary, and select between
them at runtime. If the detection fails, you can always write a bunch
of --with-PACKAGE options yourself.
- load plugins as they are needed, in main.cc and iodev/devices.cc.
- plugins are loaded using a macro PLUG_load_plugin(plugin_name, plugin_type).
When plugins are enabled, this macro calls bx_load_plugin() in plugin.cc,
which loads the plugin with lt_dlopen and calls its plugin_init method.
When plugins are disabled, the code is already linked into the binary so
the macro calls the plugin_init method directly.
- The plugin_init method for plugin ABC is called libABC_LTX_plugin_init()
and the same prefix is added before the plugin_fini method. This "name
mangling" makes the symbols unique so that they can all be linked
statically into the binary when plugins are turned off. This turned out
to be a very useful thing!
- The choice of lib*_LTX_* is not random... The libtool LTDL library
automatically searches for symbols of the form lib<module>_LTX_<symbol>
before looking for <symbol>. Libtool recommends making global symbols in
every plugin unique in some way, and in fact on MacOSX the dynamic linker
will not allow two libs to be linked in that both have plugin_init symbols,
so this sort of mangling is required.
- how do we know what plugins should be available when we start Bochs?
- we have core plugins, optional plugins, and user plugins.
- (V2.0) core plugin: These are so fundamental that Bochs won't even
initialize without them, for example the CMOS. The user can substitute
his own equivalent plugin to replace the CMOS, but he cannot say "Don't
load the CMOS at all." Core plugin devices are initialized and reset
explictly by code in iodev/devices.cc, since the initialization order for
some of them is critical. They are currently NOT added to the device
list in pluginRegisterDevice and pluginRegisterDeviceDevmodel, so that
the plugin system does not call init() and reset(). If a core plugin
cannot be found, Bochs will panic.
In the bochsrc we can provide a way for the user to REPLACE a core plugin
with a different plugin that implements the same C++ interface, but there
is no way to ask bochs to NOT load a core plugin. I'm not sure how to
configure the replacement plugin--this may have to be added later.
Bochsrc line:
replace_core_plugin: old=pic, new=mypic
- (V2.0) optional plugin: These can be loaded or not without affecting
Bochs's ability to start up and simulate. Initialization and reset for
all optional plugins are handled by bx_init_plugins() and
bx_reset_plugins(), which are now called from bx_devices_c::init() and
bx_devices_c::reset(). Bochs knows how to configure optional plugins at
compile time, and they are loaded only if the configuration settings
enables the device. Examples: serial, parallel, ne2k. See the call to
is_serial_enabled() in iodev/devices.cc. There are some plugins that you
wouldn't ever want to leave out, like vga. Maybe the term "optional" is
not clear and I need to think of a better name. Bochs will panic if an
optional plugin cannot be found. If the plugin was compiled, then
it should be available at runtime too!
- (NOT DONE) user plugin: These are plugins that Bochs does not know
anything about at compile time. The user asks Bochs to load a plugin
using just its filename. It loads the plugin and (somehow) gets
information about what settings the user can configure. The settings are
adjusted by either bochsrc lines or the user interface, and then the
device can be used. I'm missing some details here because I haven't
thought through it all the way. User plugins may not be supported until
after v2.0.
- list of plugins sorted into categories
- core plugins: unmapped, biosdev, cmos, dma, pic, vga
- optional: floppy, harddrv, keyboard, serial, parallel
- user: none yet
- clarify relationship of plugin and device
- a plugin is a shared object that you load that has a plugin_init() and
plugin_fini() function inside. The plugin_init() can create any number of
"devices" and register them. Devices are added to a global list so that we
can do operations on every registered device.
- There is (now) a pointer from each device to the plugin that created it.
- Devices created by core plugins are called core devices. These will not be
added to the device list because they are managed by existing code in
devices.cc and elsewhere. Instead of referring to them by their device_t
structure, we will use a global pointer to them, similar to the
bx_devices.pluginKeyboard pointer. (Alternative: maybe we should add
them to device list anyway, but exclude them in init_all and reset_all
functions.)
- MACOSX PLUGINS WORK! to support plugins on MacOSX, we must ensure that no
plugins have any global symbol names in common, including plugin_init! An
easy solution to this is to say that all plugin functions which can be
looked up with dlsym must follow a pattern like "%s_BXPLUG_%s", where the
first %s is the module name and the second is the plain symbol name, e.g.
pic_BXPLUG_plugin_init. Symbols that are used internally can be declared
static (file scope only).
- SOLARIS PLUGINS WORK! to support plugins on Solaris, we must not rely on
the use of global object constructors. In fact every global variable in a
module MUST BE set to a compile-time constant. We must declare object
pointers as globals, not actual objects.
- WIN32 PLUGINS WORK! to support plugins on win32, I added the
BOCHSAPI macro which expands to __declspec(dllexport) in the nonplugin
code and __declspec(dllimport) in the plugin code. Some makefile hacks
were required too. A few differences between win32 and other platforms:
- use semicolon to separate path names in LTDL_LIBRARY_PATH
- every path name in LTDL_LIBRARY_PATH should start with a drive letter,
for example: c:/cygwin/home/bryce/plugins.
- how do we locate plugins on the disk?
- make install copies the plugins into ${prefix}/lib
- if people install into a standard location, no action may be needed (?)
- we can tell people to set the LTDL_LIBRARY_PATH variable.
- if necessary we can implement a bochsrc command like
plugin_search_directory: /path/to/libs
which would call lt_dlsetsearchpath() to add the path to LTDL's list of
directories it will search.
- change log for BRANCH_PLUGINS is in patches/patch.plugins. It is
pretty complete now.
-----------------------------------------------
random notes:
class heirarchy:
logfunctions
- bx_devmodel_c
- bx_keyb_stub_c
- bx_keyb_c
bx_devmodel_c is an abstract class that defines standard functions that all
devices should define, like init and reset. Each method is defined as empty
in bx_devmodel_c so that child classes can choose to implement them or not.
bx_keyb_stub_c declares the methods that code outside the keyboard would need
to call, such as mouse_motion, gen_scancode, etc. It declares these methods
virtual, and provides a minimal definition for each that just does a panic. A
global variable pluginKeyboard initially points to an instance of
bx_keyb_stub_c so that if you forget/fail to load the load the keyboard plugin,
you will see these panics when the methods are called.
bx_keyb_c is the real keyboard code. In its constructor, it changes
pluginKeyboard to point to "this". This is equivalent to installing all
the plugin callbacks associated with the keyboard. It also works in
nonplugin code, which is a plus.
hard drive read_handler. Right now the read_handler
is a static method so it must get its object pointer from somewhere.
1) It can get it from global variable bx_hard_drive
2) The hard drive object can be passed in to it
We've always used #2, so every device has methods that look like this:
static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsi
If/when we switch over to using virtual methods, there will no longer be
any problem finding the this pointer. If we go that route, the this_ptr
can be eliminated. For now, we must use the this_ptr. Otherwise we could
never support more than one device of a given type.
------------------------------------------
References
From: Tero Pulkkinen (p150650@zori.cs.tut.fi)
Subject: Re: undefined reference to `pm virtual table'
Newsgroups: gnu.g++.help
Date: 1996/11/15
> The compile goes off OK, but I get this error at link time:
> pm.o(.text+0xa8): undefined reference to `pm virtual table'
This error comes from that the compiler didnt make virtual function
table for object even though there's implemented functions that use
objects of that type(constructor for example). Probably your pm-class
has all implemented member functions *inline* and you still have
(pure) virtual functions inside the class.
The creation point of virtual function table usually (dunno if g++ does that)
is at position of first seen noninline function body of that class.
Now if every of your function is inline, there's no place where compiler
could make virtual function table.
Fix is to move body of for example constructor(any member is fine) to the .cc
file instead of keeping it in .h-file and linking that .o file to your
executable.
Other sollution is to remove *all* implementations of functions from header
file. If all functions of a class are pure virtual, there's no need for
virtual function table. (Constructor must set pointer to virtual function
table to the object, so, if you have constructor, you'll need virtual
function table too, even in abstract classes...)
> Can someone help me? Thanks in advance.
Hope this helps....
------------------------------------------------
Bochs x86 Pentium Emulator
Updated: Wed Mar 27 20:02:41 2002
Version: 1.4
WHAT IS BOCHS?
Bochs is a highly portable open source IA-32 (x86) PC emulator
written in C++, that runs on most popular platforms. It includes
emulation of the Intel x86 CPU, common I/O devices, and a custom
BIOS. Currently, bochs can be compiled to emulate a 386, 486 or
Pentium CPU. Bochs is capable of running most Operating Systems
inside the emulation including Linux, Windows 95, DOS, and
Windows NT 4. Bochs was written by Kevin Lawton and is currently
maintained by the Bochs project at "http://bochs.sourceforge.net".
Bochs can be compiled and used in a variety of modes, some which are
still in development. The 'typical' use of bochs is to provide
complete x86 PC emulation, including the x86 processor, hardware
devices, and memory. This allows you to run OS's and software within
the emulator on your workstation, much like you have a machine
inside of a machine. Bochs will allow you to run Win '95
applications on a Solaris machine with X11, for example.
Bochs is distributed under the GNU LGPL. See COPYING for details.
GETTING CURRENT SOURCE CODE
Source code for Bochs is available from the Bochs home page at
http://bochs.sourceforge.net. You can download the most recent
release, use CVS to get the latest sources, or grab a CVS
snapshot which is updated nightly. The releases contain the most
stable code, but if you want the very newest features try the
CVS version instead.
WHERE ARE THE DOCS?
The Bochs documentation has been overhauled, and it is now
distributed in a separate package called bochsdoc-VERSION.tar.gz.
A copy is also online at
http://bochs.sf.net/doc/docbook/index.html
For now, the old documentation can still be found at
http://bochs.sf.net/docs-html
WHERE CAN I GET MORE INFORMATION? HOW DO I REPORT PROBLEMS?
Both the documentation and the Bochs website have instructions on how
to join the bochs-developers mailing list, which is the primary
forum for discussion of Bochs. The main page of the website also
has links to bug reports and feature requests. You can browse and
add to the content in these areas even if you do not have a (free)
SourceForge account. We need your feedback so that we know what
parts of Bochs to improve.
There is a patches section on the web site too, if you have made
some changes to Bochs that you want to share.
HOW CAN I HELP?
If you would like contribute to the Bochs project, a good first step
is to join the bochs-developers mailing list, and read the archive
of recent messages to see what's going on.
If you are a technical person (can follow hardware specs, can write
C/C++) take a look at the list of open bug reports and feature
requests to see if you are interested in working on any of the
problems that are mentioned in them. If you check out the CVS
sources, make some changes, and create a patch, one of the
developers will be very happy to apply it for you. Developers who
frequently submit patches, or who embark on major changes in the
source can get write access to CVS. Be sure to communicate with the
bochs-developers list to avoid several people working on the same
thing without realizing it.
If you are a Bochs user, not a hardware/C++ guru, there are still
many ways you could help out. For example:
- improving win32 binary releases
- building up a set of useful tools to include in those releases
- writing/cleaning up documentation
- testing out Bochs on every imaginable operating system and
reporting how it goes.