Some cleanup in the plugins code and related documentation additions.

This commit is contained in:
Volker Ruppert 2021-04-01 19:36:59 +00:00
parent 5406c037ec
commit 8e8414aae4
5 changed files with 45 additions and 23 deletions

View File

@ -112,7 +112,7 @@ static Bit64s bx_param_handler(bx_param_c *param, bool set, Bit64s val)
if (val != oldval) {
vga_ext_id = (Bit8u)((bx_param_enum_c*)param)->get();
PLUG_unload_opt_plugin(vga_extension_plugins[vga_ext_id]);
PLUG_load_vga_plugin(vga_extension_plugins[(Bit8u)val]);
PLUG_load_plugin_var(vga_extension_plugins[(Bit8u)val], PLUGTYPE_VGA);
}
}
} else if ((!strcmp(pname, BXPN_FLOPPYA_DEVTYPE)) ||

View File

@ -3129,21 +3129,21 @@ description:
<entry>Device plugin depending on normal config option</entry>
<entry>lib<emphasis>module</emphasis>_plugin_entry</entry>
<entry>bx_devmodel_c</entry>
<entry>Network plugins can create up to 4 devices</entry>
<entry>Network device plugins can create up to 4 instances</entry>
</row>
<row>
<entry>PLUGTYPE_VGA</entry>
<entry>VGA-compatible device plugin selected with vga extension option</entry>
<entry>VGA-compatible device plugin selected with <option>vga: extension=X</option> option</entry>
<entry>lib<emphasis>module</emphasis>_plugin_entry</entry>
<entry>bx_vgacore_c</entry>
<entry>One plugin per type only</entry>
<entry>One plugin of type required / supported</entry>
</row>
<row>
<entry>PLUGTYPE_USB</entry>
<entry>USB device plugin selected with the port<replaceable>X</replaceable> parameter of the host controller option</entry>
<entry>lib<emphasis>module</emphasis>_plugin_entry</entry>
<entry>usb_device_c</entry>
<entry>Number of devices per plugin not limited</entry>
<entry>Number of instances not limited</entry>
</row>
<row>
<entry>PLUGTYPE_CI</entry>
@ -3164,7 +3164,7 @@ description:
<entry>Additional disk image format selected with the "mode" parameter when setting up a disk image</entry>
<entry>lib<emphasis>module</emphasis>_img_plugin_entry</entry>
<entry>device_image_t</entry>
<entry>Usage of all modules not limited</entry>
<entry>Number of instances not limited</entry>
</row>
<row>
<entry>PLUGTYPE_NET</entry>
@ -3178,7 +3178,7 @@ description:
<entry>Sound driver selected with the sound option</entry>
<entry>libsound<emphasis>module</emphasis>_plugin_entry</entry>
<entry>bx_sound_lowlevel_c</entry>
<entry>Up to 4 plugins supported</entry>
<entry>One plugin of type required / max. 4 different plugins supported</entry>
</row>
</tbody>
</tgroup>
@ -3247,8 +3247,30 @@ PLUGIN_ENTRY_FOR_MODULE(unmapped)
}
</screen>
</para>
</section>
<section><title>Compatibility with "monolithic" Bochs compilation</title>
<para>
&FIXME; To be continued
To ensure compatibility between both compilation modes a bunch of macros have
been defined in <filename>plugin.h</filename>. If required the specific functions
are implemented in <filename>plugin.cc</filename>. That's why the code for the
modules that can be plugins doesn't need special cases for "plugin" and
"non-plugin" mode. For the plugin types PLUGTYPE_CORE and PLUGTYPE_STANDARD the
macros for loading / unloading plugin directly call the entry function. For the
other types a static list is created at compile time using a modified version
of the <emphasis>plugin_t</emphasis> structure. This is the counterpart to the
dynamic list in plugin mode created at startup. The load / unload functions are
similar in both modes, except that the "non-plugin" version of these functions
finally just call the entry function. These macros are defined for both modes,
but calling mode specific code:
<screen>
PLUG_load_plugin(name,type)
PLUG_get_plugins_count(type)
PLUG_get_plugin_name(type,index)
PLUG_get_plugin_flags(type,index)
PLUG_load_plugin_var(name,type)
PLUG_load_opt_plugin(name)
PLUG_unload_opt_plugin(name)
</screen>
</para>
</section>
</section>

View File

@ -240,7 +240,7 @@ void bx_devices_c::init(BX_MEM_C *newmem)
PLUG_load_plugin(pic, PLUGTYPE_CORE);
PLUG_load_plugin(pit, PLUGTYPE_CORE);
if (pluginVgaDevice == &stubVga) {
PLUG_load_vga_plugin(BX_PLUGIN_VGA);
PLUG_load_plugin_var(BX_PLUGIN_VGA, PLUGTYPE_VGA);
}
PLUG_load_plugin(floppy, PLUGTYPE_CORE);

View File

@ -451,7 +451,7 @@ Bit8u bx_get_plugin_flags(Bit16u type, Bit8u index)
bool plugin_init_one(plugin_t *plugin)
{
/* initialize the plugin */
if (plugin->plugin_entry(plugin, plugin->loadtype, 1))
if (plugin->plugin_entry(plugin, plugin->loadtype, PLUGIN_INIT))
{
pluginlog->info("Plugin initialization failed for %s", plugin->name);
plugin_abort(plugin);
@ -466,7 +466,7 @@ bool plugin_unload(plugin_t *plugin)
{
if (plugin->loadtype != PLUGTYPE_NULL) {
if (plugin->initialized)
plugin->plugin_entry(plugin, plugin->type, 0);
plugin->plugin_entry(plugin, plugin->type, PLUGIN_FINI);
#if defined(WIN32)
FreeLibrary(plugin->handle);
#else
@ -1124,7 +1124,7 @@ plugin_t bx_builtin_plugins[] = {
BUILTIN_IMG_PLUGIN_ENTRY(vbox),
BUILTIN_IMG_PLUGIN_ENTRY(vpc),
BUILTIN_IMG_PLUGIN_ENTRY(vvfat),
{"NULL", PLUGTYPE_GUI, 0, NULL, 0}
{"NULL", PLUGTYPE_NULL, 0, NULL, 0}
};
Bit8u bx_get_plugins_count_np(Bit16u type)
@ -1180,7 +1180,7 @@ int bx_load_plugin_np(const char *name, Bit16u type)
((type & bx_builtin_plugins[i].type) != 0)) {
if (bx_builtin_plugins[i].initialized == 0) {
bx_builtin_plugins[i].loadtype = type;
bx_builtin_plugins[i].plugin_entry(NULL, type, 1);
bx_builtin_plugins[i].plugin_entry(NULL, type, PLUGIN_INIT);
bx_builtin_plugins[i].initialized = 1;
}
return 1;
@ -1202,7 +1202,7 @@ int bx_unload_opt_plugin(const char *name, bool devflag)
pluginUnregisterDeviceDevmodel(bx_builtin_plugins[i].name,
bx_builtin_plugins[i].type);
}
bx_builtin_plugins[i].plugin_entry(NULL, bx_builtin_plugins[i].loadtype, 0);
bx_builtin_plugins[i].plugin_entry(NULL, bx_builtin_plugins[i].loadtype, PLUGIN_FINI);
bx_builtin_plugins[i].loadtype = PLUGTYPE_NULL;
bx_builtin_plugins[i].initialized = 0;
}

View File

@ -83,13 +83,14 @@ extern "C" {
#if BX_PLUGINS
#define PLUG_get_plugins_count(a) bx_get_plugins_count(a)
#define PLUG_get_plugin_name(a,b) bx_get_plugin_name(a,b)
#define PLUG_get_plugin_flags(a,b) bx_get_plugin_flags(a,b)
// hardcoded load plugin macro for PLUGTYPE_CORE and PLUGTYPE_STANDARD
#define PLUG_load_plugin(name,type) {bx_load_plugin(#name,type);}
// newer plugin macros for variable plugin handling
#define PLUG_get_plugins_count(type) bx_get_plugins_count(type)
#define PLUG_get_plugin_name(type,index) bx_get_plugin_name(type,index)
#define PLUG_get_plugin_flags(type,index) bx_get_plugin_flags(type,index)
#define PLUG_load_plugin_var(name,type) {bx_load_plugin(name,type);}
#define PLUG_load_opt_plugin(name) bx_load_plugin(name,PLUGTYPE_OPTIONAL)
#define PLUG_load_vga_plugin(name) bx_load_plugin(name,PLUGTYPE_VGA)
#define PLUG_unload_opt_plugin(name) bx_unload_plugin(name,1)
#define PLUG_unload_plugin_type(name,type) {bx_unload_plugin_type(name,type);}
@ -111,14 +112,13 @@ extern "C" {
// When plugins are off, PLUG_load_plugin will call the plugin_entry function
// directly (PLUGTYPE_CORE and PLUGTYPE_STANDARD only).
#define PLUG_load_plugin(name,type) {lib##name##_plugin_entry(NULL,type,1);}
#define PLUG_load_plugin(name,type) {lib##name##_plugin_entry(NULL,type,PLUGIN_INIT);}
// Builtin plugins macros
#define PLUG_get_plugins_count(a) bx_get_plugins_count_np(a)
#define PLUG_get_plugin_name(a,b) bx_get_plugin_name_np(a,b)
#define PLUG_get_plugin_flags(a,b) bx_get_plugin_flags_np(a,b)
#define PLUG_get_plugins_count(type) bx_get_plugins_count_np(type)
#define PLUG_get_plugin_name(type,index) bx_get_plugin_name_np(type,index)
#define PLUG_get_plugin_flags(type,index) bx_get_plugin_flags_np(type,index)
#define PLUG_load_plugin_var(name,type) bx_load_plugin_np(name,type)
#define PLUG_load_opt_plugin(name) bx_load_plugin_np(name,PLUGTYPE_OPTIONAL)
#define PLUG_load_vga_plugin(name) bx_load_plugin_np(name,PLUGTYPE_VGA)
#define PLUG_unload_opt_plugin(name) bx_unload_opt_plugin(name,1)
#define DEV_register_ioread_handler(b,c,d,e,f) bx_devices.register_io_read_handler(b,c,d,e,f)