/* Map a device at the specified physical address */ int vm_map_device(vm_instance_t *vm,struct vdevice *dev,m_uint64_t base_addr) { #if 0 /* Suspend VM activity */ vm_suspend(vm); if (cpu_group_sync_state(vm->cpu_group) == -1) { fprintf(stderr,"VM%u: unable to sync with system CPUs.\n", vm->instance_id); return(-1); } #endif /* Unbind the device if it was already active */ vm_unbind_device(vm,dev); /* Map the device at the new base address and rebuild MTS */ dev->phys_addr = base_addr; vm_bind_device(vm,dev); cpu_group_rebuild_mts(vm->cpu_group); #if 0 vm_resume(vm); #endif return(0); }
/* Boot the ELF image */ static int ppc32_vmtest_boot_elf(vm_instance_t *vm) { m_uint32_t rom_entry_point; cpu_ppc_t *cpu; if (!vm->boot_cpu) return(-1); /* Suspend CPU activity since we will restart directly from ROM */ vm_suspend(vm); /* Check that CPU activity is really suspended */ if (cpu_group_sync_state(vm->cpu_group) == -1) { vm_error(vm,"unable to sync with system CPUs.\n"); return(-1); } /* Reset the boot CPU */ cpu = CPU_PPC32(vm->boot_cpu); ppc32_reset(cpu); /* Load ROM (ELF image or embedded) */ cpu = CPU_PPC32(vm->boot_cpu); rom_entry_point = (m_uint32_t)PPC32_ROM_START; if ((vm->rom_filename != NULL) && (ppc32_load_elf_image(cpu,vm->rom_filename,0,&rom_entry_point) < 0)) { vm_error(vm,"unable to load alternate ROM '%s', " "fallback to embedded ROM.\n\n",vm->rom_filename); vm->rom_filename = NULL; } /* Load ELF image */ if (ppc32_load_elf_image(cpu,vm->ios_image, (vm->ghost_status == VM_GHOST_RAM_USE), &vm->ios_entry_point) < 0) { vm_error(vm,"failed to load ELF image '%s'.\n",vm->ios_image); return(-1); } /* Launch the simulation */ printf("\nPPC32_VMTEST '%s': starting simulation (CPU0 IA=0x%8.8x), " "JIT %sabled.\n", vm->name,cpu->ia,vm->jit_use ? "en":"dis"); vm_log(vm,"PPC32_VMTEST_BOOT", "starting instance (CPU0 IA=0x%8.8x,JIT %s)\n", cpu->ia,vm->jit_use ? "on":"off"); /* Start main CPU */ if (vm->ghost_status != VM_GHOST_RAM_GENERATE) { vm->status = VM_STATUS_RUNNING; cpu_start(vm->boot_cpu); } else { vm->status = VM_STATUS_SHUTDOWN; } return(0); }
/* Free resources used by a router instance */ static int c3725_delete_instance(vm_instance_t *vm) { c3725_t *router = VM_C3725(vm); int i; /* Stop all CPUs */ if (vm->cpu_group != NULL) { vm_stop(vm); if (cpu_group_sync_state(vm->cpu_group) == -1) { vm_error(vm,"unable to sync with system CPUs.\n"); return(FALSE); } } /* Remove NIO bindings */ for(i=0;i<vm->nr_slots;i++) vm_slot_remove_all_nio_bindings(vm,i); /* Shutdown all Network Modules */ vm_slot_shutdown_all(vm); /* Free mainboard EEPROM */ cisco_eeprom_free(&router->mb_eeprom); /* Free all resources used by VM */ vm_free(vm); /* Free the router structure */ free(router); return(TRUE); }
/* Boot the IOS image */ static int c1700_boot_ios(c1700_t *router) { vm_instance_t *vm = router->vm; cpu_ppc_t *cpu; if (!vm->boot_cpu) return(-1); /* Suspend CPU activity since we will restart directly from ROM */ vm_suspend(vm); /* Check that CPU activity is really suspended */ if (cpu_group_sync_state(vm->cpu_group) == -1) { vm_error(vm,"unable to sync with system CPUs.\n"); return(-1); } /* Reset the boot CPU */ cpu = CPU_PPC32(vm->boot_cpu); ppc32_reset(cpu); /* Adjust stack pointer */ cpu->gpr[1] |= 0x80000000; /* Load BAT registers */ printf("Loading BAT registers\n"); ppc32_load_bat_array(cpu,bat_array); cpu->msr |= PPC32_MSR_IR|PPC32_MSR_DR; /* IRQ routing */ vm->set_irq = c1700_set_irq; vm->clear_irq = c1700_clear_irq; /* Load IOS image */ if (ppc32_load_elf_image(cpu,vm->ios_image, (vm->ghost_status == VM_GHOST_RAM_USE), &vm->ios_entry_point) < 0) { vm_error(vm,"failed to load Cisco IOS image '%s'.\n",vm->ios_image); return(-1); } /* Launch the simulation */ printf("\nC1700 '%s': starting simulation (CPU0 IA=0x%8.8x), " "JIT %sabled.\n", vm->name,cpu->ia,vm->jit_use ? "en":"dis"); vm_log(vm,"C1700_BOOT", "starting instance (CPU0 PC=0x%8.8x,idle_pc=0x%8.8x,JIT %s)\n", cpu->ia,cpu->idle_pc,vm->jit_use ? "on":"off"); /* Start main CPU */ if (vm->ghost_status != VM_GHOST_RAM_GENERATE) { vm->status = VM_STATUS_RUNNING; cpu_start(vm->boot_cpu); } else { vm->status = VM_STATUS_SHUTDOWN; } return(0); }
/* Boot the IOS image */ static int c3725_boot_ios(c3725_t *router) { vm_instance_t *vm = router->vm; cpu_mips_t *cpu; if (!vm->boot_cpu) return(-1); /* Suspend CPU activity since we will restart directly from ROM */ vm_suspend(vm); /* Check that CPU activity is really suspended */ if (cpu_group_sync_state(vm->cpu_group) == -1) { vm_error(vm,"unable to sync with system CPUs.\n"); return(-1); } /* Reset the boot CPU */ cpu = CPU_MIPS64(vm->boot_cpu); mips64_reset(cpu); /* Load IOS image */ if (mips64_load_elf_image(cpu,vm->ios_image, (vm->ghost_status == VM_GHOST_RAM_USE), &vm->ios_entry_point) < 0) { vm_error(vm,"failed to load Cisco IOS image '%s'.\n",vm->ios_image); return(-1); } /* Launch the simulation */ printf("\nC3725 '%s': starting simulation (CPU0 PC=0x%llx), " "JIT %sabled.\n", vm->name,cpu->pc,vm->jit_use ? "en":"dis"); vm_log(vm,"C3725_BOOT", "starting instance (CPU0 PC=0x%llx,idle_pc=0x%llx,JIT %s)\n", cpu->pc,cpu->idle_pc,vm->jit_use ? "on":"off"); /* Start main CPU */ if (vm->ghost_status != VM_GHOST_RAM_GENERATE) { vm->status = VM_STATUS_RUNNING; cpu_start(vm->boot_cpu); } else { vm->status = VM_STATUS_SHUTDOWN; } return(0); }
static int adm5120_boot (adm5120_t * adm5120) { vm_instance_t *vm = adm5120->vm; cpu_mips_t *cpu; m_va_t kernel_entry_point; if (!vm->boot_cpu) return (-1); vm_suspend (vm); /* Check that CPU activity is really suspended */ if (cpu_group_sync_state (vm->cpu_group) == -1) { vm_error (vm, "unable to sync with system CPUs.\n"); return (-1); } /* Reset the boot CPU */ cpu = (vm->boot_cpu); mips_reset (cpu); /*set configure register */ cpu->cp0.config_usable = 0x3; /*only configure sel 0 and 1 is valid */ cpu->cp0.config_reg[0] = ADM5120_CONFIG0; cpu->cp0.config_reg[1] = ADM5120_CONFIG1; /*set PC and PRID */ cpu->cp0.reg[MIPS_CP0_PRID] = ADM5120_PRID; cpu->cp0.tlb_entries = ADM5120_DEFAULT_TLB_ENTRYNO; cpu->pc = ADM5120_ROM_PC; /*If we boot from elf kernel image, load the image and set pc to elf entry */ if (vm->boot_method == BOOT_ELF) { if (mips_load_elf_image (cpu, vm->kernel_filename, &kernel_entry_point) == -1) return (-1); adm5120_reg_default_value (adm5120); cpu->pc = kernel_entry_point; } /* Launch the simulation */ printf ("\nADM5120 '%s': starting simulation (CPU0 PC=0x%" LL "x), " "JIT %sabled.\n", vm->name, cpu->pc, vm->jit_use ? "en" : "dis"); vm->status = VM_STATUS_RUNNING; cpu_start (vm->boot_cpu); return (0); }
/* Free resources used by a test instance */ static int ppc32_vmtest_delete_instance(vm_instance_t *vm) { /* Stop all CPUs */ if (vm->cpu_group != NULL) { vm_stop(vm); if (cpu_group_sync_state(vm->cpu_group) == -1) { vm_error(vm,"unable to sync with system CPUs.\n"); return(FALSE); } } /* Free all resources used by VM */ vm_free(vm); return(TRUE); }
/* Boot the RAW image */ _unused static int ppc32_vmtest_boot_raw(vm_instance_t *vm) { cpu_ppc_t *cpu; if (!vm->boot_cpu) return(-1); /* Suspend CPU activity since we will restart directly from ROM */ vm_suspend(vm); /* Check that CPU activity is really suspended */ if (cpu_group_sync_state(vm->cpu_group) == -1) { vm_error(vm,"unable to sync with system CPUs.\n"); return(-1); } /* Reset the boot CPU */ cpu = CPU_PPC32(vm->boot_cpu); ppc32_reset(cpu); /* Load RAW image */ if (ppc32_load_raw_image(cpu,vm->ios_image,0xFFF00000) < 0) { vm_error(vm,"failed to load RAW image '%s'.\n",vm->ios_image); return(-1); } cpu->ia = 0xFFF00100; cpu->gpr[1] = 0x2000; /* Launch the simulation */ printf("\nPPC32_VMTEST '%s': starting simulation (CPU0 IA=0x%8.8x), " "JIT %sabled.\n", vm->name,cpu->ia,vm->jit_use ? "en":"dis"); vm_log(vm,"PPC32_VMTEST_BOOT", "starting instance (CPU0 IA=0x%8.8x,JIT %s)\n", cpu->ia,vm->jit_use ? "on":"off"); /* Start main CPU */ if (vm->ghost_status != VM_GHOST_RAM_GENERATE) { vm->status = VM_STATUS_RUNNING; cpu_start(vm->boot_cpu); } else { vm->status = VM_STATUS_SHUTDOWN; } return(0); }
/* Stop a test instance */ static int ppc32_vmtest_stop_instance(vm_instance_t *vm) { printf("\nPPC32_VMTEST '%s': stopping simulation.\n",vm->name); vm_log(vm,"PPC32_VMTEST_STOP","stopping simulation.\n"); /* Stop all CPUs */ if (vm->cpu_group != NULL) { vm_stop(vm); if (cpu_group_sync_state(vm->cpu_group) == -1) { vm_error(vm,"unable to sync with system CPUs.\n"); return(-1); } } /* Free resources that were used during execution to emulate hardware */ vm_hardware_shutdown(vm); return(0); }
/* Stop a Cisco 3725 instance */ static int c3725_stop_instance(vm_instance_t *vm) { printf("\nC3725 '%s': stopping simulation.\n",vm->name); vm_log(vm,"C3725_STOP","stopping simulation.\n"); /* Stop all CPUs */ if (vm->cpu_group != NULL) { vm_stop(vm); if (cpu_group_sync_state(vm->cpu_group) == -1) { vm_error(vm,"unable to sync with system CPUs.\n"); return(-1); } } /* Free resources that were used during execution to emulate hardware */ vm_slot_shutdown_all(vm); vm_hardware_shutdown(vm); /* Cleanup */ VM_C3725(vm)->iofpga_data = NULL; VM_C3725(vm)->gt_data = NULL; return(0); }