/* * Load task image for boot task. * Return 0 on success, -1 on failure. */ int vm_load(vm_map_t map, struct module *mod, void **stack) { char *src; void *text, *data; DPRINTF(("Loading task: %s\n", mod->name)); /* * We have to switch VM mapping to touch the virtual * memory space of a target task without page fault. */ vm_switch(map); src = phys_to_virt(mod->phys); text = (void *)mod->text; data = (void *)mod->data; /* * Create text segment */ if (do_allocate(map, &text, mod->textsz, 0)) return -1; memcpy(text, src, mod->textsz); if (do_attribute(map, text, VMA_READ)) return -1; /* * Create data & BSS segment */ if (mod->datasz + mod->bsssz != 0) { if (do_allocate(map, &data, mod->datasz + mod->bsssz, 0)) return -1; src = src + (mod->data - mod->text); memcpy(data, src, mod->datasz); } /* * Create stack */ *stack = (void *)USTACK_BASE; if (do_allocate(map, stack, USTACK_SIZE, 0)) return -1; /* Free original pages */ page_free((void *)mod->phys, mod->size); return 0; }
void go(void) { for (;;) { GPtrArray *vms = list_vms(); if (vms) { dump_vms(vms); printf("press key 0-9 to switch\n"); int slot = (int) (fgetc(stdin) - '0'); if (slot >= 0 && slot <= 9) { const char *vm = vm_with_slot(vms, slot); if (!vm) { printf("NO SUCH VM!\n"); } else { vm_switch(vm); } } g_ptr_array_free( vms, TRUE ); } } }