2002-10-25 01:07:56 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2007-10-25 03:29:40 +04:00
|
|
|
// $Id: plugin.cc,v 1.23 2007-10-24 23:28:40 sshwarts Exp $
|
2002-10-25 01:07:56 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// This file defines the plugin and plugin-device registration functions and
|
|
|
|
// the device registration functions. It handles dynamic loading of modules,
|
|
|
|
// using the LTDL library for cross-platform support.
|
|
|
|
//
|
|
|
|
// This file is based on the plugin.c file from plex86, but with significant
|
|
|
|
// changes to make it work in Bochs.
|
|
|
|
// Plex86 is Copyright (C) 1999-2000 The plex86 developers team
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "bochs.h"
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev/iodev.h"
|
2002-10-25 01:07:56 +04:00
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
#define LOG_THIS genlog->
|
|
|
|
|
|
|
|
#define PLUGIN_INIT_FMT_STRING "lib%s_LTX_plugin_init"
|
|
|
|
#define PLUGIN_FINI_FMT_STRING "lib%s_LTX_plugin_fini"
|
|
|
|
#define PLUGIN_PATH ""
|
|
|
|
|
|
|
|
#ifndef WIN32
|
2002-11-14 21:45:49 +03:00
|
|
|
#define PLUGIN_FILENAME_FORMAT "libbx_%s.la"
|
2002-10-25 01:07:56 +04:00
|
|
|
#else
|
2002-11-14 21:45:49 +03:00
|
|
|
#define PLUGIN_FILENAME_FORMAT "bx_%s.dll"
|
2002-10-25 01:07:56 +04:00
|
|
|
#endif
|
|
|
|
|
2004-08-11 15:09:01 +04:00
|
|
|
extern "C" {
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
void (*pluginRegisterIRQ)(unsigned irq, const char* name) = 0;
|
|
|
|
void (*pluginUnregisterIRQ)(unsigned irq, const char* name) = 0;
|
|
|
|
|
|
|
|
void (*pluginSetHRQ)(unsigned val) = 0;
|
|
|
|
void (*pluginSetHRQHackCallback)( void (*callback)(void) ) = 0;
|
|
|
|
|
|
|
|
int (*pluginRegisterIOReadHandler)(void *thisPtr, ioReadHandler_t callback,
|
2003-07-31 16:04:48 +04:00
|
|
|
unsigned base, const char *name, Bit8u mask) = 0;
|
2002-10-25 01:07:56 +04:00
|
|
|
int (*pluginRegisterIOWriteHandler)(void *thisPtr, ioWriteHandler_t callback,
|
2003-07-31 16:04:48 +04:00
|
|
|
unsigned base, const char *name, Bit8u mask) = 0;
|
2004-01-15 05:08:37 +03:00
|
|
|
int (*pluginUnregisterIOReadHandler)(void *thisPtr, ioReadHandler_t callback,
|
|
|
|
unsigned base, Bit8u mask) = 0;
|
|
|
|
int (*pluginUnregisterIOWriteHandler)(void *thisPtr, ioWriteHandler_t callback,
|
|
|
|
unsigned base, Bit8u mask) = 0;
|
|
|
|
int (*pluginRegisterIOReadHandlerRange)(void *thisPtr, ioReadHandler_t callback,
|
|
|
|
unsigned base, unsigned end, const char *name, Bit8u mask) = 0;
|
|
|
|
int (*pluginRegisterIOWriteHandlerRange)(void *thisPtr, ioWriteHandler_t callback,
|
|
|
|
unsigned base, unsigned end, const char *name, Bit8u mask) = 0;
|
|
|
|
int (*pluginUnregisterIOReadHandlerRange)(void *thisPtr, ioReadHandler_t callback,
|
|
|
|
unsigned begin, unsigned end, Bit8u mask) = 0;
|
|
|
|
int (*pluginUnregisterIOWriteHandlerRange)(void *thisPtr, ioWriteHandler_t callback,
|
|
|
|
unsigned begin, unsigned end, Bit8u mask) = 0;
|
2002-10-25 01:07:56 +04:00
|
|
|
int (*pluginRegisterDefaultIOReadHandler)(void *thisPtr, ioReadHandler_t callback,
|
2003-07-31 16:04:48 +04:00
|
|
|
const char *name, Bit8u mask) = 0;
|
2002-10-25 01:07:56 +04:00
|
|
|
int (*pluginRegisterDefaultIOWriteHandler)(void *thisPtr, ioWriteHandler_t callback,
|
2003-07-31 16:04:48 +04:00
|
|
|
const char *name, Bit8u mask) = 0;
|
2002-10-25 01:07:56 +04:00
|
|
|
int (*pluginRegisterTimer)(void *this_ptr, void (*funct)(void *),
|
2004-01-20 00:43:50 +03:00
|
|
|
Bit32u useconds, bx_bool continuous,
|
|
|
|
bx_bool active, const char* name) = 0;
|
|
|
|
void (*pluginActivateTimer)(unsigned id, Bit32u usec, bx_bool continuous) = 0;
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
void (*pluginHRQHackCallback)(void);
|
|
|
|
unsigned pluginHRQ = 0;
|
|
|
|
|
|
|
|
plugin_t *plugins = NULL; /* Head of the linked list of plugins */
|
2003-05-02 16:22:48 +04:00
|
|
|
#if BX_PLUGINS
|
2002-10-25 01:07:56 +04:00
|
|
|
static void plugin_init_one(plugin_t *plugin);
|
2003-05-02 16:22:48 +04:00
|
|
|
#endif
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
device_t *devices = NULL; /* Head of the linked list of registered devices */
|
|
|
|
|
|
|
|
plugin_t *current_plugin_context = NULL;
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Builtins declarations */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
builtinRegisterIRQ(unsigned irq, const char* name)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
pluginlog->panic("builtinRegisterIRQ called, no pic plugin loaded?");
|
|
|
|
#else
|
|
|
|
bx_devices.register_irq(irq, name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
builtinUnregisterIRQ(unsigned irq, const char* name)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
pluginlog->panic("builtinUnregisterIRQ called, no pic plugin loaded?");
|
|
|
|
#else
|
|
|
|
bx_devices.unregister_irq(irq, name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
builtinSetHRQ(unsigned val)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
pluginlog->panic("builtinSetHRQ called, no plugin loaded?");
|
|
|
|
#else
|
|
|
|
pluginHRQ = val;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
builtinSetHRQHackCallback( void (*callback)(void) )
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
pluginlog->panic("builtinSetHRQHackCallback called, no plugin loaded?");
|
|
|
|
#else
|
|
|
|
pluginHRQHackCallback = callback;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinRegisterIOReadHandler(void *thisPtr, ioReadHandler_t callback,
|
2003-07-31 16:04:48 +04:00
|
|
|
unsigned base, const char *name, Bit8u mask)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2004-01-15 05:08:37 +03:00
|
|
|
int ret;
|
2003-07-31 16:04:48 +04:00
|
|
|
BX_ASSERT (mask<8);
|
2004-01-15 05:08:37 +03:00
|
|
|
ret = bx_devices.register_io_read_handler (thisPtr, callback, base, name, mask);
|
2002-10-25 01:07:56 +04:00
|
|
|
pluginlog->ldebug("plugin %s registered I/O read address at %04x", name, base);
|
2004-01-15 05:08:37 +03:00
|
|
|
return ret;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinRegisterIOWriteHandler(void *thisPtr, ioWriteHandler_t callback,
|
2003-07-31 16:04:48 +04:00
|
|
|
unsigned base, const char *name, Bit8u mask)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2004-01-15 05:08:37 +03:00
|
|
|
int ret;
|
2003-07-31 16:04:48 +04:00
|
|
|
BX_ASSERT (mask<8);
|
2004-01-15 05:08:37 +03:00
|
|
|
ret = bx_devices.register_io_write_handler (thisPtr, callback, base, name, mask);
|
2002-10-25 01:07:56 +04:00
|
|
|
pluginlog->ldebug("plugin %s registered I/O write address at %04x", name, base);
|
2004-01-15 05:08:37 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinUnregisterIOReadHandler(void *thisPtr, ioReadHandler_t callback,
|
|
|
|
unsigned base, Bit8u mask)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
BX_ASSERT (mask<8);
|
|
|
|
ret = bx_devices.unregister_io_read_handler (thisPtr, callback, base, mask);
|
|
|
|
pluginlog->ldebug("plugin unregistered I/O read address at %04x", base);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinUnregisterIOWriteHandler(void *thisPtr, ioWriteHandler_t callback,
|
|
|
|
unsigned base, Bit8u mask)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
BX_ASSERT (mask<8);
|
|
|
|
ret = bx_devices.unregister_io_write_handler (thisPtr, callback, base, mask);
|
|
|
|
pluginlog->ldebug("plugin unregistered I/O write address at %04x", base);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinRegisterIOReadHandlerRange(void *thisPtr, ioReadHandler_t callback,
|
|
|
|
unsigned base, unsigned end, const char *name, Bit8u mask)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
BX_ASSERT (mask<8);
|
|
|
|
ret = bx_devices.register_io_read_handler_range (thisPtr, callback, base, end, name, mask);
|
|
|
|
pluginlog->ldebug("plugin %s registered I/O read addresses %04x to %04x", name, base, end);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinRegisterIOWriteHandlerRange(void *thisPtr, ioWriteHandler_t callback,
|
|
|
|
unsigned base, unsigned end, const char *name, Bit8u mask)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
BX_ASSERT (mask<8);
|
|
|
|
ret = bx_devices.register_io_write_handler_range (thisPtr, callback, base, end, name, mask);
|
|
|
|
pluginlog->ldebug("plugin %s registered I/O write addresses %04x to %04x", name, base, end);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinUnregisterIOReadHandlerRange(void *thisPtr, ioReadHandler_t callback,
|
|
|
|
unsigned begin, unsigned end, Bit8u mask)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
BX_ASSERT (mask<8);
|
|
|
|
ret = bx_devices.unregister_io_read_handler_range (thisPtr, callback, begin, end, mask);
|
|
|
|
pluginlog->ldebug("plugin unregistered I/O read addresses %04x to %04x", begin, end);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinUnregisterIOWriteHandlerRange(void *thisPtr, ioWriteHandler_t callback,
|
|
|
|
unsigned begin, unsigned end, Bit8u mask)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
BX_ASSERT (mask<8);
|
|
|
|
ret = bx_devices.unregister_io_write_handler_range (thisPtr, callback, begin, end, mask);
|
|
|
|
pluginlog->ldebug("plugin unregistered I/O write addresses %04x to %04x", begin, end);
|
|
|
|
return ret;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinRegisterDefaultIOReadHandler(void *thisPtr, ioReadHandler_t callback,
|
2003-07-31 16:04:48 +04:00
|
|
|
const char *name, Bit8u mask)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2003-07-31 16:04:48 +04:00
|
|
|
BX_ASSERT (mask<8);
|
|
|
|
bx_devices.register_default_io_read_handler (thisPtr, callback, name, mask);
|
2002-10-25 01:07:56 +04:00
|
|
|
pluginlog->ldebug("plugin %s registered default I/O read ", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinRegisterDefaultIOWriteHandler(void *thisPtr, ioWriteHandler_t callback,
|
2003-07-31 16:04:48 +04:00
|
|
|
const char *name, Bit8u mask)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2003-07-31 16:04:48 +04:00
|
|
|
BX_ASSERT (mask<8);
|
|
|
|
bx_devices.register_default_io_write_handler (thisPtr, callback, name, mask);
|
2002-10-25 01:07:56 +04:00
|
|
|
pluginlog->ldebug("plugin %s registered default I/O write ", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
builtinRegisterTimer(void *this_ptr, void (*funct)(void *),
|
2004-01-20 00:43:50 +03:00
|
|
|
Bit32u useconds, bx_bool continuous,
|
|
|
|
bx_bool active, const char* name)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
int id = bx_pc_system.register_timer (this_ptr, funct, useconds, continuous, active, name);
|
|
|
|
pluginlog->ldebug("plugin %s registered timer %d", name, id);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-25 15:44:41 +04:00
|
|
|
builtinActivateTimer(unsigned id, Bit32u usec, bx_bool continuous)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
bx_pc_system.activate_timer (id, usec, continuous);
|
|
|
|
pluginlog->ldebug("plugin activated timer %d", id);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_PLUGINS
|
|
|
|
/************************************************************************/
|
|
|
|
/* Plugin initialization / deinitialization */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
plugin_init_all (void)
|
|
|
|
{
|
|
|
|
plugin_t *plugin;
|
|
|
|
|
|
|
|
pluginlog->info("Initializing plugins");
|
|
|
|
|
|
|
|
for (plugin = plugins; plugin; plugin = plugin->next)
|
|
|
|
{
|
|
|
|
char *arg_ptr = plugin->args;
|
|
|
|
|
|
|
|
/* process the command line */
|
|
|
|
plugin->argc = 0;
|
|
|
|
while (plugin->argc < MAX_ARGC)
|
|
|
|
{
|
|
|
|
while (*arg_ptr && isspace (*arg_ptr))
|
|
|
|
arg_ptr++;
|
|
|
|
|
|
|
|
if (!*arg_ptr)
|
|
|
|
break;
|
|
|
|
plugin->argv[plugin->argc++] = arg_ptr;
|
|
|
|
|
|
|
|
while (*arg_ptr && !isspace (*arg_ptr))
|
|
|
|
arg_ptr++;
|
|
|
|
|
|
|
|
if (!*arg_ptr)
|
|
|
|
break;
|
|
|
|
*arg_ptr++ = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the plugin */
|
|
|
|
if (plugin->plugin_init (plugin, plugin->type, plugin->argc, plugin->argv))
|
|
|
|
{
|
|
|
|
pluginlog->panic("Plugin initialization failed for %s", plugin->name);
|
|
|
|
plugin_abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin->initialized = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
plugin_init_one(plugin_t *plugin)
|
|
|
|
{
|
|
|
|
char *arg_ptr = plugin->args;
|
|
|
|
|
|
|
|
/* process the command line */
|
|
|
|
plugin->argc = 0;
|
|
|
|
while (plugin->argc < MAX_ARGC)
|
|
|
|
{
|
|
|
|
while (*arg_ptr && isspace (*arg_ptr))
|
|
|
|
arg_ptr++;
|
|
|
|
|
|
|
|
if (!*arg_ptr)
|
|
|
|
break;
|
|
|
|
plugin->argv[plugin->argc++] = arg_ptr;
|
|
|
|
|
|
|
|
while (*arg_ptr && !isspace (*arg_ptr))
|
|
|
|
arg_ptr++;
|
|
|
|
|
|
|
|
if (!*arg_ptr)
|
|
|
|
break;
|
|
|
|
*arg_ptr++ = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the plugin */
|
|
|
|
if (plugin->plugin_init (plugin, plugin->type, plugin->argc, plugin->argv))
|
|
|
|
{
|
|
|
|
pluginlog->info("Plugin initialization failed for %s", plugin->name);
|
|
|
|
plugin_abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin->initialized = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-10 13:13:47 +04:00
|
|
|
plugin_t *plugin_unload(plugin_t *plugin)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
plugin_t *dead_plug;
|
|
|
|
|
|
|
|
if (plugin->initialized)
|
2006-09-10 13:13:47 +04:00
|
|
|
plugin->plugin_fini();
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2006-09-10 13:13:47 +04:00
|
|
|
lt_dlclose(plugin->handle);
|
|
|
|
delete [] plugin->name;
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
dead_plug = plugin;
|
|
|
|
plugin = plugin->next;
|
2006-09-10 13:13:47 +04:00
|
|
|
free(dead_plug);
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-10 13:13:47 +04:00
|
|
|
void plugin_fini_all (void)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
plugin_t *plugin;
|
|
|
|
|
2006-09-10 13:13:47 +04:00
|
|
|
for (plugin = plugins; plugin; plugin = plugin_unload(plugin));
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-10 13:13:47 +04:00
|
|
|
void plugin_load(char *name, char *args, plugintype_t type)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
plugin_t *plugin;
|
|
|
|
|
2006-09-10 13:13:47 +04:00
|
|
|
plugin = (plugin_t *)malloc (sizeof(plugin_t));
|
2002-10-25 01:07:56 +04:00
|
|
|
if (!plugin)
|
|
|
|
{
|
2006-09-10 13:13:47 +04:00
|
|
|
BX_PANIC(("malloc plugin_t failed"));
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin->type = type;
|
|
|
|
plugin->name = name;
|
|
|
|
plugin->args = args;
|
|
|
|
plugin->initialized = 0;
|
2004-01-20 00:43:50 +03:00
|
|
|
|
|
|
|
char plugin_filename[BX_PATHNAME_LEN], buf[BX_PATHNAME_LEN];
|
2006-09-10 13:13:47 +04:00
|
|
|
sprintf(buf, PLUGIN_FILENAME_FORMAT, name);
|
2004-01-20 00:43:50 +03:00
|
|
|
sprintf(plugin_filename, "%s%s", PLUGIN_PATH, buf);
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
// Set context so that any devices that the plugin registers will
|
|
|
|
// be able to see which plugin created them. The registration will
|
|
|
|
// be called from either dlopen (global constructors) or plugin_init.
|
|
|
|
BX_ASSERT (current_plugin_context == NULL);
|
|
|
|
current_plugin_context = plugin;
|
|
|
|
plugin->handle = lt_dlopen (plugin_filename);
|
|
|
|
BX_INFO (("lt_dlhandle is %p", plugin->handle));
|
|
|
|
if (!plugin->handle)
|
|
|
|
{
|
|
|
|
current_plugin_context = NULL;
|
|
|
|
BX_PANIC (("dlopen failed for module '%s': %s", name, lt_dlerror ()));
|
|
|
|
free (plugin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-01-21 12:28:49 +03:00
|
|
|
sprintf(buf, PLUGIN_INIT_FMT_STRING, name);
|
2002-10-25 01:07:56 +04:00
|
|
|
plugin->plugin_init =
|
|
|
|
(int (*)(struct _plugin_t *, enum plugintype_t, int, char *[])) /* monster typecast */
|
|
|
|
lt_dlsym (plugin->handle, buf);
|
|
|
|
if (plugin->plugin_init == NULL) {
|
|
|
|
pluginlog->panic("could not find plugin_init: %s", lt_dlerror ());
|
|
|
|
plugin_abort ();
|
|
|
|
}
|
|
|
|
|
2006-01-21 12:28:49 +03:00
|
|
|
sprintf(buf, PLUGIN_FINI_FMT_STRING, name);
|
2002-10-25 01:07:56 +04:00
|
|
|
plugin->plugin_fini = (void (*)(void)) lt_dlsym (plugin->handle, buf);
|
|
|
|
if (plugin->plugin_init == NULL) {
|
|
|
|
pluginlog->panic("could not find plugin_fini: %s", lt_dlerror ());
|
|
|
|
plugin_abort ();
|
|
|
|
}
|
|
|
|
pluginlog->info("loaded plugin %s",plugin_filename);
|
|
|
|
|
|
|
|
|
|
|
|
/* Insert plugin at the _end_ of the plugin linked list. */
|
|
|
|
plugin->next = NULL;
|
|
|
|
|
|
|
|
if (!plugins)
|
|
|
|
{
|
|
|
|
/* Empty list, this become the first entry. */
|
|
|
|
plugins = plugin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Non-empty list. Add to end. */
|
|
|
|
plugin_t *temp = plugins;
|
|
|
|
|
|
|
|
while (temp->next)
|
|
|
|
temp = temp->next;
|
|
|
|
|
|
|
|
temp->next = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin_init_one(plugin);
|
|
|
|
|
|
|
|
// check that context didn't change. This should only happen if we
|
|
|
|
// need a reentrant plugin_load.
|
|
|
|
BX_ASSERT (current_plugin_context == plugin);
|
|
|
|
current_plugin_context = NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-10 13:13:47 +04:00
|
|
|
void plugin_abort(void)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
pluginlog->panic("plugin load aborted");
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* end of #if BX_PLUGINS */
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Plugin system: initialisation of plugins entry points */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
plugin_startup(void)
|
|
|
|
{
|
|
|
|
pluginRegisterIRQ = builtinRegisterIRQ;
|
|
|
|
pluginUnregisterIRQ = builtinUnregisterIRQ;
|
|
|
|
|
|
|
|
pluginSetHRQHackCallback = builtinSetHRQHackCallback;
|
|
|
|
pluginSetHRQ = builtinSetHRQ;
|
|
|
|
|
|
|
|
pluginRegisterIOReadHandler = builtinRegisterIOReadHandler;
|
|
|
|
pluginRegisterIOWriteHandler = builtinRegisterIOWriteHandler;
|
2004-01-15 05:08:37 +03:00
|
|
|
|
|
|
|
pluginUnregisterIOReadHandler = builtinUnregisterIOReadHandler;
|
|
|
|
pluginUnregisterIOWriteHandler = builtinUnregisterIOWriteHandler;
|
|
|
|
|
|
|
|
pluginRegisterIOReadHandlerRange = builtinRegisterIOReadHandlerRange;
|
|
|
|
pluginRegisterIOWriteHandlerRange = builtinRegisterIOWriteHandlerRange;
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
pluginUnregisterIOReadHandlerRange = builtinUnregisterIOReadHandlerRange;
|
|
|
|
pluginUnregisterIOWriteHandlerRange = builtinUnregisterIOWriteHandlerRange;
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
pluginRegisterDefaultIOReadHandler = builtinRegisterDefaultIOReadHandler;
|
|
|
|
pluginRegisterDefaultIOWriteHandler = builtinRegisterDefaultIOWriteHandler;
|
|
|
|
|
|
|
|
pluginRegisterTimer = builtinRegisterTimer;
|
|
|
|
pluginActivateTimer = builtinActivateTimer;
|
|
|
|
|
|
|
|
#if BX_PLUGINS
|
2003-07-11 00:26:05 +04:00
|
|
|
pluginlog = new logfunctions();
|
|
|
|
pluginlog->put("PLGIN");
|
|
|
|
pluginlog->settype(PLUGINLOG);
|
2002-10-25 01:07:56 +04:00
|
|
|
int status = lt_dlinit ();
|
|
|
|
if (status != 0) {
|
|
|
|
BX_ERROR (("initialization error in ltdl library (for loading plugins)"));
|
|
|
|
BX_PANIC (("error message was: %s", lt_dlerror ()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Plugin system: Device registration */
|
|
|
|
/************************************************************************/
|
|
|
|
|
2007-10-25 03:29:40 +04:00
|
|
|
void pluginRegisterDeviceDevmodel(plugin_t *plugin, plugintype_t type, bx_devmodel_c *devmodel, const char *name)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
device_t *device;
|
|
|
|
|
|
|
|
device = (device_t *)malloc (sizeof (device_t));
|
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
pluginlog->panic("can't allocate device_t");
|
|
|
|
}
|
|
|
|
|
|
|
|
device->name = name;
|
|
|
|
BX_ASSERT (devmodel != NULL);
|
|
|
|
device->devmodel = devmodel;
|
|
|
|
device->plugin = plugin; // this can be NULL
|
|
|
|
device->next = NULL;
|
|
|
|
|
|
|
|
// Don't add every kind of device to the list.
|
|
|
|
switch (type) {
|
|
|
|
case PLUGTYPE_CORE:
|
2004-01-20 00:43:50 +03:00
|
|
|
// Core devices are present whether or not we are using plugins, so
|
|
|
|
// they are managed by the same code in iodev/devices.cc whether
|
|
|
|
// plugins are on or off.
|
2006-04-14 17:27:17 +04:00
|
|
|
free(device);
|
2004-01-20 00:43:50 +03:00
|
|
|
return; // Do not add core devices to the devices list.
|
2002-10-25 01:07:56 +04:00
|
|
|
case PLUGTYPE_OPTIONAL:
|
|
|
|
case PLUGTYPE_USER:
|
|
|
|
default:
|
2004-01-20 00:43:50 +03:00
|
|
|
// The plugin system will manage optional and user devices only.
|
|
|
|
break;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!devices)
|
|
|
|
{
|
|
|
|
/* Empty list, this become the first entry. */
|
|
|
|
devices = device;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Non-empty list. Add to end. */
|
|
|
|
device_t *temp = devices;
|
|
|
|
|
|
|
|
while (temp->next)
|
|
|
|
temp = temp->next;
|
|
|
|
|
|
|
|
temp->next = device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Plugin system: Check if a plugin is loaded */
|
|
|
|
/************************************************************************/
|
|
|
|
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool pluginDevicePresent(char *name)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
device_t *device;
|
|
|
|
|
|
|
|
for (device = devices; device; device = device->next)
|
|
|
|
{
|
|
|
|
if (strcmp(device->name,name)==0) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_PLUGINS
|
|
|
|
/************************************************************************/
|
|
|
|
/* Plugin system: Load one plugin */
|
|
|
|
/************************************************************************/
|
|
|
|
|
2006-09-10 13:13:47 +04:00
|
|
|
int bx_load_plugin(const char *name, plugintype_t type)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
char *namecopy = new char[1+strlen(name)];
|
2006-09-10 13:13:47 +04:00
|
|
|
strcpy(namecopy, name);
|
|
|
|
plugin_load(namecopy, "", type);
|
2002-10-25 01:07:56 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2006-09-10 13:13:47 +04:00
|
|
|
|
|
|
|
void bx_unload_plugin(const char *name)
|
|
|
|
{
|
|
|
|
plugin_t *plugin, *prev = NULL;
|
|
|
|
|
|
|
|
for (plugin = plugins; plugin; plugin = plugin->next) {
|
|
|
|
if (!strcmp(plugin->name, name)) {
|
|
|
|
plugin = plugin_unload(plugin);
|
|
|
|
if (prev == NULL) {
|
|
|
|
plugins = plugin;
|
|
|
|
} else {
|
|
|
|
prev->next = plugin;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
prev = plugin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
#endif /* end of #if BX_PLUGINS */
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Plugin system: Execute init function of all registered plugin-devices */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
void bx_init_plugins()
|
|
|
|
{
|
|
|
|
device_t *device;
|
|
|
|
|
|
|
|
// two loops
|
|
|
|
for (device = devices; device; device = device->next)
|
|
|
|
{
|
2006-01-20 22:12:03 +03:00
|
|
|
pluginlog->info("init_mem of '%s' plugin device by virtual method",device->name);
|
|
|
|
device->devmodel->init_mem(BX_MEM(0));
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (device = devices; device; device = device->next)
|
|
|
|
{
|
2006-01-20 22:12:03 +03:00
|
|
|
pluginlog->info("init_dev of '%s' plugin device by virtual method",device->name);
|
|
|
|
device->devmodel->init();
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Plugin system: Execute reset function of all registered plugin-devices */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
void bx_reset_plugins(unsigned signal)
|
|
|
|
{
|
|
|
|
device_t *device;
|
|
|
|
for (device = devices; device; device = device->next)
|
|
|
|
{
|
2006-01-20 22:12:03 +03:00
|
|
|
pluginlog->info("reset of '%s' plugin device by virtual method",device->name);
|
|
|
|
device->devmodel->reset(signal);
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
}
|
2004-08-11 15:09:01 +04:00
|
|
|
|
2006-09-10 13:13:47 +04:00
|
|
|
/*******************************************************/
|
|
|
|
/* Plugin system: Unload all registered plugin-devices */
|
|
|
|
/*******************************************************/
|
|
|
|
|
|
|
|
void bx_unload_plugins()
|
|
|
|
{
|
|
|
|
device_t *device, *next;
|
|
|
|
|
|
|
|
device = devices;
|
2006-09-12 17:05:07 +04:00
|
|
|
while (device != NULL) {
|
2006-09-10 13:13:47 +04:00
|
|
|
if (device->plugin != NULL) {
|
|
|
|
#if BX_PLUGINS
|
|
|
|
bx_unload_plugin(device->name);
|
|
|
|
#endif
|
|
|
|
} else {
|
2006-09-16 18:47:40 +04:00
|
|
|
delete device->devmodel;
|
2006-09-10 13:13:47 +04:00
|
|
|
}
|
|
|
|
next = device->next;
|
|
|
|
free(device);
|
|
|
|
device = next;
|
2006-09-12 17:05:07 +04:00
|
|
|
};
|
2006-09-10 13:13:47 +04:00
|
|
|
devices = NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-15 21:03:59 +04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Plugin system: Register device state of all registered plugin-devices */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
void bx_plugins_register_state()
|
|
|
|
{
|
|
|
|
device_t *device;
|
|
|
|
for (device = devices; device; device = device->next)
|
|
|
|
{
|
|
|
|
pluginlog->info("register state of '%s' plugin device by virtual method",device->name);
|
|
|
|
device->devmodel->register_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* Plugin system: Execute code after restoring state of all plugin devices */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
void bx_plugins_after_restore_state()
|
|
|
|
{
|
|
|
|
device_t *device;
|
|
|
|
for (device = devices; device; device = device->next)
|
|
|
|
{
|
|
|
|
device->devmodel->after_restore_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 15:09:01 +04:00
|
|
|
}
|