1 /* tag: openbios plugin loader
3 * Copyright (C) 2003 Stefan Reinauer
5 * See the file "COPYING" for further information about
6 * the copyright and warranty status of this work.
9 /* This is a simple plugin loader. OpenBIOS duplicates some
10 * of this code in kernel/arch/unix/plugins.c. This code is
11 * here for reference and simple testing.
18 #include <unistd.h> // sleep
20 #include "unix/plugins.h"
22 #define PLUGINDIR "/usr/share/OpenBIOS/plugins"
27 typedef struct iorange iorange_t;
36 iorange_t *ioranges = NULL;
38 typedef struct plugin plugin_t;
44 plugin_t *plugins = NULL;
46 int register_iorange(const char *name, io_ops_t * ops, unsigned int rstart,
51 /* intersection check */
55 /* new section swallows old section */
56 if (newrange->start >= rstart && newrange->end <= rend)
58 /* new section start or end point are within range */
59 if (newrange->start <= rstart && newrange->end >= rstart)
61 if (newrange->start <= rend && newrange->end >= rend)
64 printf("Error: overlapping IO regions: %s and %s\n",
65 newrange->name, name);
68 newrange = newrange->next;
71 newrange = malloc(sizeof(iorange_t));
73 newrange->name = name;
75 newrange->start = rstart;
77 newrange->next = ioranges;
84 int is_loaded(const char *plugin_name)
86 plugin_t *p = plugins;
88 if (!strcmp(plugin_name, p->name))
95 int load_plugin(const char *plugin_name)
101 int (*init_plugin) (void);
106 if (is_loaded(plugin_name)) {
107 printf("Plugin %s already loaded.\n", plugin_name);
111 strncpy(path, PLUGINDIR, PATHSIZE);
112 strncat(path, "/plugin_", PATHSIZE);
113 strncat(path, plugin_name, PATHSIZE);
114 strncat(path, ".so", PATHSIZE);
117 printf("Opening plugin %s\n", path);
120 handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
123 printf("Error: Could not open plugin \"%s\": %s\n",
128 plugin_info = dlsym(handle, "plugin_author");
129 if ((error = dlerror()) == NULL)
130 printf("Plugin %s author: %s\n", plugin_name, *plugin_info);
131 plugin_info = dlsym(handle, "plugin_license");
132 if ((error = dlerror()) == NULL)
133 printf("Plugin %s license: %s\n", plugin_name, *plugin_info);
134 plugin_info = dlsym(handle, "plugin_description");
135 if ((error = dlerror()) == NULL)
136 printf("Plugin %s descr.: %s\n", plugin_name, *plugin_info);
138 p = malloc(sizeof(plugin_t));
140 p->name = plugin_name;
143 deps = dlsym(handle, "plugin_deps");
144 if ((error = dlerror()) != NULL)
148 strncpy(path, "plugin_", PATHSIZE);
149 strncat(path, plugin_name, PATHSIZE);
150 strncat(path, "_init", PATHSIZE);
152 init_plugin = dlsym(handle, path);
153 if ((error = dlerror()) != NULL) {
154 printf("error: %s\n", error);
160 char *walk = deps[0];
162 printf("\nPlugin %s dependencies:", plugin_name);
166 if (!is_loaded(walk)) {
168 printf("(loading)\n");
183 printf("Initializing module:\n");
186 return init_plugin();
188 // We don't dlclose the handle here since
189 // we want to keep our symbols for later use.
196 // load_plugin("kbd");
197 // load_plugin("pci");
200 printf("\nRegistered IO Ranges:\n");
203 printf(" %s: %x-%x\n", r->name, r->start, r->end);