summaryrefslogtreecommitdiffstats
path: root/sys/boot/common/module.c
diff options
context:
space:
mode:
authormsmith <msmith@FreeBSD.org>1998-08-31 21:10:43 +0000
committermsmith <msmith@FreeBSD.org>1998-08-31 21:10:43 +0000
commit815f3686d0275b1e63d326042e37d5244e051121 (patch)
treea32c9c92f2b120f904fc9aa7d0755d8b8a74f6b0 /sys/boot/common/module.c
parentc3fa37d604772f443b31aa7d26c331bd64c2675d (diff)
downloadFreeBSD-src-815f3686d0275b1e63d326042e37d5244e051121.zip
FreeBSD-src-815f3686d0275b1e63d326042e37d5244e051121.tar.gz
Bootloader update.
- Implement a new copyin/readin interface for loading modules. This allows the module loaders to become MI, reducing code duplication. - Simplify the search for an image activator for the loaded kernel. - Use the common module management code for all module metadata. - Add an 'unload' command that throws everything away. - Move the a.out module loader to MI code, add support for a.out kld modules. Submitted by: Alpha changes fixed by Doug Rabson <dfr@freebsd.org>
Diffstat (limited to 'sys/boot/common/module.c')
-rw-r--r--sys/boot/common/module.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/sys/boot/common/module.c b/sys/boot/common/module.c
index 7f56e71..28c10dc 100644
--- a/sys/boot/common/module.c
+++ b/sys/boot/common/module.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: module.c,v 1.1.1.1 1998/08/21 03:17:41 msmith Exp $
*/
/*
@@ -38,7 +38,7 @@
#include "bootstrap.h"
-/* Initially determined from kernel load address */
+/* XXX load address should be tweaked by first module loaded (kernel) */
static vm_offset_t loadaddr = 0;
struct loaded_module *loaded_modules = NULL;
@@ -51,6 +51,32 @@ command_load(int argc, char *argv[])
return(mod_load(argv[1], argc - 2, argv + 2));
}
+COMMAND_SET(unload, "unload", "unload all modules", command_unload);
+
+static int
+command_unload(int argc, char *argv[])
+{
+ struct loaded_module *mp;
+ struct module_metadata *md;
+
+ while (loaded_modules != NULL) {
+ mp = loaded_modules;
+ loaded_modules = loaded_modules->m_next;
+ while (mp->m_metadata != NULL) {
+ md = mp->m_metadata;
+ mp->m_metadata = mp->m_metadata->md_next;
+ free(md);
+ }
+ free(mp->m_name);
+ free(mp->m_type);
+ if (mp->m_args != NULL)
+ free(mp->m_args);
+ free(mp);
+ }
+ loadaddr = 0;
+ return(CMD_OK);
+}
+
COMMAND_SET(lsmod, "lsmod", "list loaded modules", command_lsmod);
static int
@@ -61,7 +87,7 @@ command_lsmod(int argc, char *argv[])
pager_open();
for (am = loaded_modules; (am != NULL); am = am->m_next) {
- sprintf(lbuf, " %p: %s (%s, 0x%x)\n",
+ sprintf(lbuf, " %x: %s (%s, 0x%x)\n",
am->m_addr, am->m_name, am->m_type, am->m_size);
pager_output(lbuf);
if (am->m_args != NULL) {
@@ -91,6 +117,9 @@ mod_load(char *name, int argc, char *argv[])
/* Fatal error */
sprintf(command_errbuf, "can't load module '%s': %s", name, strerror(err));
return(CMD_ERROR);
+ } else {
+ /* remember the loader */
+ am->m_loader = i;
}
}
if (am == NULL) {
@@ -127,3 +156,27 @@ mod_findmodule(char *name, char *type)
}
return(mp);
}
+
+void
+mod_addmetadata(struct loaded_module *mp, int type, size_t size, void *p)
+{
+ struct module_metadata *md;
+
+ md = malloc(sizeof(struct module_metadata) + size);
+ md->md_size = size;
+ md->md_type = type;
+ bcopy(p, md->md_data, size);
+ md->md_next = mp->m_metadata;
+ mp->m_metadata = md;
+}
+
+struct module_metadata *
+mod_findmetadata(struct loaded_module *mp, int type)
+{
+ struct module_metadata *md;
+
+ for (md = mp->m_metadata; md != NULL; md = md->md_next)
+ if (md->md_type == type)
+ break;
+ return(md);
+}
OpenPOWER on IntegriCloud