diff --git a/init/main.c b/init/main.c index 4d1531fcd4fea6e873a1a87cbee602fa142eb9fc..4db57e8b124fb37f9bf7bc734c84d439ddffbffe 100644 --- a/init/main.c +++ b/init/main.c @@ -19,7 +19,7 @@ void module_image_load_embedded(void); void *module_lookup_embedded(char *mod_name); void *module_lookup_symbol_embedded(char *sym_name); - +void *module_read_embedded(char *mod_name); static void kernel_init(void) { @@ -40,7 +40,6 @@ int main(void) module_image_load_embedded(); - /* look up a kernel symbol */ printk("%s at %p\n", "printk", lookup_symbol("printk")); @@ -48,7 +47,6 @@ int main(void) printk("%s at %p\n", "testmodule.ko", module_lookup_embedded("testmodule.ko")); - /* to load an arbitrary image, you may upload it via grmon, e.g. * load -binary kernel/test.ko 0xA0000000 * then load it: @@ -56,7 +54,13 @@ int main(void) */ /* lookup the module containing <symbol> */ - addr = module_lookup_symbol_embedded("somefunction"); + /* addr = module_lookup_symbol_embedded("somefunction"); */ + /* XXX the image is not necessary aligned properly, so we can't access + * it directly, until we have a MNA trap */ + + + addr = module_read_embedded("testmodule.ko"); + if (addr) module_load(&m, addr); diff --git a/init/modules-image.c b/init/modules-image.c index ae18f7f00d6304148e5d4b16797047a225dc6320..dec2c27a2790fda6590b2ccbee2cb6011f91bd18 100644 --- a/init/modules-image.c +++ b/init/modules-image.c @@ -4,6 +4,7 @@ #include <kernel/printk.h> #include <kernel/ar.h> +#include <kernel/kmem.h> extern unsigned char _binary_modules_image_start __attribute__((weak)); extern unsigned char _binary_modules_image_end __attribute__((weak)); @@ -31,3 +32,23 @@ void *module_lookup_embedded(char *mod_name) { return ar_find_file(&mod_ar, mod_name); } + +void *module_read_embedded(char *mod_name) +{ + unsigned int fsize; + + void *ptr; + + fsize = ar_read_file(&mod_ar, mod_name, NULL); + + ptr = kmalloc(fsize); + if (!ptr) + return NULL; + + if (!ar_read_file(&mod_ar, mod_name, ptr)) { + kfree(ptr); + return NULL; + } + + return ptr; +}