X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_symmod.c;h=193f511b55e73f5baa261a868bfd110d7de8aef6;hb=1b72cd1ffc37529af00e7e0a04034a67dad0c786;hp=41767ff35007b6146baa9368d3e833cc2ea9471b;hpb=4cc3e8965ada59e7f5a9e55e8ccbc9563d997b93;p=palacios.git diff --git a/palacios/src/palacios/vmm_symmod.c b/palacios/src/palacios/vmm_symmod.c index 41767ff..193f511 100644 --- a/palacios/src/palacios/vmm_symmod.c +++ b/palacios/src/palacios/vmm_symmod.c @@ -21,45 +21,65 @@ #include #include -static struct v3_sym_module test_module; +static struct hashtable * master_mod_table = NULL; -int V3_init_symmod() { - return -1; +static uint_t mod_hash_fn(addr_t key) { + char * name = (char *)key; + return v3_hash_buffer((uchar_t *)name, strlen(name)); } - - -int v3_init_symmod_vm(struct v3_vm_info * info, v3_cfg_tree_t * cfg) { - return 0; +static int mod_eq_fn(addr_t key1, addr_t key2) { + char * name1 = (char *)key1; + char * name2 = (char *)key2; + + return (strcmp(name1, name2) == 0); } -int v3_set_symmod_loader(struct v3_vm_info * vm, struct v3_symmod_loader_ops * ops, void * priv_data) { - struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state); - extern uint8_t symmod_start[]; - extern uint8_t symmod_end[]; +int V3_init_symmod() { + extern struct v3_sym_module __start__v3_modules[]; + extern struct v3_sym_module __stop__v3_modules[]; + struct v3_sym_module * tmp_mod = __start__v3_modules; + int i = 0; + + master_mod_table = v3_create_htable(0, mod_hash_fn, mod_eq_fn); + + while (tmp_mod != __stop__v3_modules) { + if (v3_htable_search(master_mod_table, (addr_t)(tmp_mod->name))) { + PrintError("Multiple instances of Module (%s)\n", tmp_mod->name); + return -1; + } + PrintDebug("Registering Symbiotic Module (%s)\n", tmp_mod->name); + + if (v3_htable_insert(master_mod_table, + (addr_t)(tmp_mod->name), + (addr_t)(tmp_mod)) == 0) { + PrintError("Could not insert module %s to master list\n", tmp_mod->name); + return -1; + } + tmp_mod = &(__start__v3_modules[++i]); + } + + return 0; +} +int v3_init_symmod_vm(struct v3_vm_info * info, v3_cfg_tree_t * cfg) { + return 0; +} - struct v3_sym_module tmp_mod = { - .name = "test", - .num_bytes = symmod_end - symmod_start, - .data = symmod_start, - }; - - - test_module = tmp_mod; +int v3_set_symmod_loader(struct v3_vm_info * vm, struct v3_symmod_loader_ops * ops, void * priv_data) { + struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state); + symmod_state->loader_ops = ops; symmod_state->loader_data = priv_data; - - + return 0; - } @@ -68,15 +88,28 @@ int v3_set_symmod_loader(struct v3_vm_info * vm, struct v3_symmod_loader_ops * o int v3_load_sym_module(struct v3_vm_info * vm, char * mod_name) { struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state); + struct v3_sym_module * mod = (struct v3_sym_module *)v3_htable_search(master_mod_table, (addr_t)mod_name); + + if (!mod) { + PrintError("Could not find module %s\n", mod_name); + return -1; + } PrintDebug("Loading Module (%s)\n", mod_name); - return symmod_state->loader_ops->load_module(vm, test_module.name, test_module.num_bytes, symmod_state->loader_data); + return symmod_state->loader_ops->load_module(vm, mod->name, mod->end_addr - mod->start_addr, symmod_state->loader_data); } struct v3_sym_module * v3_get_sym_module(struct v3_vm_info * vm, char * name) { - return &test_module; + struct v3_sym_module * mod = (struct v3_sym_module *)v3_htable_search(master_mod_table, (addr_t)name); + + if (!mod) { + PrintError("Could not find module %s\n", name); + return NULL; + } + + return mod; }