/* Cria mapeapmento das VM com base em dados carregados na memoria pelo loader. */ void inMemoryLoad(){ static uint32_t *confaddr = (uint32_t*)0x80300000; /* Carrega configura a partir do endereço 0x80300000 */ while(*confaddr){ HF_Template[0][0] = *confaddr; HF_Template[1][0] = TLBIndex; HF_Template[1][1] = *confaddr/0x1000; HF_Template[1][2] = *confaddr/0x1000+0x10; HF_Template[2][0] = TLBIndex; switch ( *(confaddr+1)){ case HELLFIRE: HF_Template[0][3] = HELLFIRE; break; case BAREOS: HF_Template[0][3] = BAREOS; break; case BAREOS_RT: HF_Template[0][3] = BAREOS_RT; break; default: Warning("Undentified VM 0x%x.", *(confaddr+1)); } create_vm(HF_Template); confaddr += 2; TLBIndex++; } }
void gui_initialize() { /* create VM */ env = create_vm(&jvm); if(env == NULL) { printf("gui error: JVM environment is NULL!!.\n"); return; } /* Initialize JNI vars */ clsMain = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "blastit/Main")); printf("%s",clsMain); if(clsMain != NULL) { setLevelInfo = (*env)->GetStaticMethodID(env, clsMain,"setLevelInfo","(IIII)V"); drawBuffer = (*env)->GetStaticMethodID(env, clsMain,"drawBuffer","([Ljava/lang/String;)V"); startTimer = (*env)->GetStaticMethodID(env, clsMain,"startTimer","()V"); getTimerScore = (*env)->GetStaticMethodID(env, clsMain,"getTimerScore","()I"); setGameOver = (*env)->GetStaticMethodID(env, clsMain,"setGameOver","()V"); setFinishedLevel = (*env)->GetStaticMethodID(env, clsMain,"setFinishedLevel","(I)V"); isMovementKeyDown = (*env)->GetStaticMethodID(env, clsMain,"isMovementKeyDown","()I"); wasSpacePressed = (*env)->GetStaticMethodID(env, clsMain,"wasSpacePressed","()I"); isTerminated = (*env)->GetStaticMethodID(env, clsMain,"isTerminated","()I"); } else { printf("gui error: Unable to find main GUI class!!.\n"); return; } init_queue(&cmd_queue); ready = 1; }
int main(int argc, char **argv) { JNIEnv* env = create_vm(); addCommand("Add Rectangle 100 200 500 600"); addCommand("Add Oval 100 200 500 600"); addCommand("Add Line 100 200 500 600"); addCommand("Save Objective shape.obj"); addCommand("Save XML shape.xml"); addCommand("Draw"); startProgram(env); }
/** Initialize the RT VMs */ initializeRTMachines(void){ unsigned int i; Info("Initializing RT Virtual Machines"); if(vmconf_rt[0][0] != 0){ /* Create initialize the VM structure */ for(i=0; vmconf_rt[i][0]; i+=vmconf_rt[i][2]+1){ create_vm(&vmconf_rt[i]); } }else{ //inMemoryLoad(); } }
int main(int argc, char **argv) { JavaVM* pJVM = 0; JNIEnv* env = create_vm(&pJVM); jint ver = env->GetVersion(); printf("version is : %d\n", ver); initJavaReference(env); // check for exceptions checkException(env); // destroy pJVM->DestroyJavaVM(); pJVM = 0; }
int main(int argc, char** argv) { char* filename = ""; if(argc == 2) filename = argv[1]; virtual_machine* vm = create_vm(filename); if(vm != NULL) run_vm(vm); // Print the first memory address //if(vm) printf("%i\n", vm->pMemory->int32[0]); destroy_vm(vm); return 0; }
/** Initialize the VMs */ void initializeMachines(void) { unsigned int i; Info("Initializing Virtual Machines"); /* Pode carregar a tabela de VMs a partir do arquivo config.h ou de configuração carregada na memória a partir do endereço 0x80000500 */ if(vmconf[0][0] != 0){ /* Create initialize the VM structure */ for(i=0; vmconf[i][0]; i+=vmconf[i][2]+1){ create_vm(&vmconf[i]); } }else{ // inMemoryLoad(); } //create_vm(idleconf); }
/* Standard C main program */ int main(int argc, char **argv) { /* Make sure we have a program tape to run */ if (argc < 2) { fprintf(stderr, "Usage: %s $FileName\nWhere $FileName is the name of the paper tape of the program being run\n", argv[0]); return EXIT_FAILURE; } /* Perform all the essential stages in order */ struct lilith* vm; tape_01_name = "tape_01"; tape_02_name = "tape_02"; vm = create_vm(1 << 21); load_program(vm, argv); execute_vm(vm); destroy_vm(vm); return EXIT_SUCCESS; }
/* * Initializes the JNI structure */ JNI_struct* init_jni(MBSdataStruct *MBSdata) { JNI_struct *jni_struct; // - - - - - - - - - - - - - - - - - // declaration for 3D view with JNI jclass animFrameClass, PadModelClass, MbsModelJ3DClass; jmethodID constructor; jmethodID loadMethod, setLocMethod; jmethodID getModelMethod, getMbs3DMethod, setVpMethod; jobject model, model3D; jstring mbsFilename; jdoubleArray doubleArrayArg; JNIEnv* env; jmethodID updateJointMethod; jobject obj; // - - - - - - - - - - - - - - - - - - - - - - - // initialise jni variable for 3D visualisation env = create_vm(); animFrameClass = (*env)->FindClass(env, "be/robotran/test/LiveSimAnimFrame"); // get the reference to the constructor of this class constructor = (*env)->GetMethodID(env, animFrameClass, "<init>", "()V"); // get the reference to the load method which load the *.mbs file loadMethod = (*env)->GetMethodID(env, animFrameClass, "load", "(Ljava/lang/String;)V"); // get the reference to the updateJoints method which update the 3D view during simulation updateJointMethod = (*env)->GetMethodID(env, animFrameClass, "updateJoints", "([D)V"); // get the reference to the setLocation method setLocMethod = (*env)->GetMethodID(env, animFrameClass, "setLocation", "(II)V"); // create a jni string containing the path to the *.mbs file to load mbsFilename = (*env)->NewStringUTF(env, MBS_FILE); // create an instance of the 3D view obj = (*env)->NewObject(env, animFrameClass, constructor); // load the mbsfilename -> keyboard inputs problem !!! (*env)->CallObjectMethod(env, obj, loadMethod, mbsFilename); // Viewpoint // get the reference to the class PadModelClass = (*env)->FindClass(env, "be/robotran/mbsyspad/PadModel"); MbsModelJ3DClass = (*env)->FindClass(env, "be/robotran/mbs3Dviewer/j3Dviewer/MbsModelJ3D"); // get the reference to the methods getModelMethod = (*env)->GetMethodID(env, animFrameClass, "getModel", "()Lbe/robotran/mbsyspad/PadModel;"); getMbs3DMethod = (*env)->GetMethodID(env, PadModelClass, "getMbs3D", "()Lbe/robotran/mbs3Dviewer/viewerInterface/MbsModel3D;"); setVpMethod = (*env)->GetMethodID(env, MbsModelJ3DClass, "setViewpoint", "(I)V"); model = (*env)->CallObjectMethod(env, obj, getModelMethod); model3D = (*env)->CallObjectMethod(env, model, getMbs3DMethod); (*env)->CallObjectMethod(env, model3D, setVpMethod, -1); // move the frame (*env)->CallObjectMethod(env, obj, setLocMethod, 100,100); // instantiate a jni array of double doubleArrayArg = (*env)->NewDoubleArray(env, MBSdata->njoint); // copy the current values of MBSdata->q to the jni array (*env)->SetDoubleArrayRegion(env, doubleArrayArg, 0 , MBSdata->njoint, MBSdata->q+1); // update the 3D view (*env)->CallObjectMethod(env, obj, updateJointMethod, doubleArrayArg); // JNI structure jni_struct = (JNI_struct*) malloc(sizeof(JNI_struct)); jni_struct->env = env; jni_struct->updateJointMethod = updateJointMethod; jni_struct->obj = obj; jni_struct->setVpMethod = setVpMethod; jni_struct->model3D = model3D; return jni_struct; }
int main(int argc, char **argv) { JNIEnv* env = create_vm(); invoke_class (env); return 0; }
runtime(unsigned features = 0xffffffff, unsigned heap_size = 1*1024*1024, unsigned stack_size = 64*1024) { vm = create_vm(features, heap_size,stack_size); assert(vm); }
int main(int argc, char **argv) { int i = 0; int jvm_argc = 0; int main_argc = 0; int jvm_argv_index = 0; int main_argv_index = 0; char ** jvm_argv = (char**)malloc(argc*sizeof(char*)+1); /* plus one for classpath */ char ** main_argv = (char**)malloc(argc*sizeof(char*)); char *main_class_name = NULL; jobject main_class = NULL; char *p = NULL; int doexit = 1; int result = 0; JNIEnv* env = NULL; int classpath_index = -1; const char* classpath_from_env = getenv("CLASSPATH"); if(classpath_from_env != NULL) { int len = strlen("-Djava.class.path=") + strlen(classpath_from_env) + 1; jvm_argv[jvm_argv_index] = (char*)malloc(len); sprintf(jvm_argv[jvm_argv_index],"-Djava.class.path=%s", classpath_from_env); classpath_index = jvm_argv_index; jvm_argv_index++; jvm_argc++; } for(i=1; i < argc; i++) { if ( strcmp(argv[i], "-noexit") == 0 ) { doexit=0; } else if ( strncmp(argv[i], "-X", 2) == 0 ) { jvm_argc++; jvm_argv[jvm_argv_index++] = argv[i]+2; } else if (strcmp(argv[i],"-cp") == 0 ) { i++; if(i >= argc) { fprintf(stderr, "Missing classpath for -cp options\n"); exit(1); } if (classpath_index < 0) { int len = strlen("-Djava.class.path=") + strlen(argv[i]) + 1; jvm_argv[jvm_argv_index] = (char*)malloc(len); sprintf(jvm_argv[jvm_argv_index],"-Djava.class.path=%s", argv[i]); classpath_index = jvm_argv_index; jvm_argc++; jvm_argv_index++; } else { char *tmp = jvm_argv[classpath_index]; int len = strlen(tmp) + strlen(argv[i]) + 2; jvm_argv[classpath_index] = (char*)malloc(len); sprintf(jvm_argv[classpath_index],"%s:%s", tmp, argv[i]); free(tmp); } } else { if(main_class_name == NULL) { main_class_name = argv[i]; } else { main_argc++; main_argv[main_argv_index++] = argv[i]; } } } if(main_class_name == NULL) { fprintf(stderr,"no main class defined\n"); exit(1); } env = create_vm(jvm_argc, jvm_argv); if(env == NULL) { exit(1); } for(p= main_class_name; *p != '\0'; p++) { if(*p == '.') { *p = '/'; } } main_class = (*env)->FindClass(env, main_class_name); if (main_class == NULL) { fprintf(stderr,"class %s not found\n", main_class_name); exit(1); } main_class = (jclass)(*env)->NewGlobalRef(env, main_class); if (main_class == NULL) { fprintf(stderr,"Did not get a global ref on main class\n"); exit(1); } if(load_libs(env, main_class)) { exit(1); } result = invoke_main( env, main_class, main_argc, main_argv ); if(doexit) { exit(result); } return 0; }
static void restart() { int r; DPRINTF("Restarting from checkpoint.\n"); if (g_kvm_fd > 0 && g_vm_fd > 0 && g_vcpu_fd > 0) { r = create_vm(); if (r < 0) { DPRINTF("ERROR: Creating VMFD returned: %d\n", r); DPRINTF("WARNING: Please try checkpointing again\n"); exit(-1); } else if (r > 0) { int i = 0; int t = 0; r = restore_id_map_addr(); if (r < 0) { DPRINTF("ERROR: Restoring identity map addr returned: %d\n", r); DPRINTF("WARNING: Please try checkpointing again\n"); exit(-1); } r = restore_tss_addr(); if (r < 0) { DPRINTF("ERROR: Restoring tss addr returned: %d\n", r); DPRINTF("WARNING: Please try checkpointing again\n"); exit(-1); } r = create_irqchip(); if (r < 0) { DPRINTF("ERROR: Creating IRQCHIP returned: %d\n", r); DPRINTF("WARNING: Please try checkpointing again\n"); exit(-1); } r = create_vcpu(); if (r < 0) { DPRINTF("ERROR: Creating new VCPU returned: %d\n", r); DPRINTF("WARNING: Cannot continue\n"); exit(-1); } if (NEXT_FNC(mmap)(g_vcpu_mmap_addr, g_vcpu_mmap_length, g_vcpu_mmap_prot, g_vcpu_mmap_flags | MAP_FIXED, g_vcpu_fd, 0) == MAP_FAILED) { DPRINTF("ERROR: Mapping the new VCPU returned MAP_FAILED\n"); DPRINTF("WARNING: Cannot continue\n"); exit(-1); } r = NEXT_FNC(ioctl)(g_vcpu_fd, KVM_SET_SIGNAL_MASK, &g_kvm_sigmask); if (r < 0) { DPRINTF("ERROR: Setting VCPU Signal Mask returned: %d\n", r); exit(-1); } r = NEXT_FNC(ioctl)(g_vm_fd, KVM_IRQ_LINE_STATUS, &g_kvm_irq_level); if (r < 0) { DPRINTF("ERROR: Setting IRQ LINE status returned: %d\n", r); exit(-1); } r = NEXT_FNC(ioctl)(g_vm_fd, KVM_REGISTER_COALESCED_MMIO, &g_kvm_coalesced_mmio_zone); if (r < 0) { DPRINTF("ERROR: Setting Coalesced MMIO Zone returned: %d\n", r); exit(-1); } DPRINTF("Setting #%d memory regions\n", g_num_of_memory_regions); struct kvm_userspace_memory_region *mem; for (i = 0; i < g_num_of_memory_regions; i++) { mem = &g_kvm_mem_region[i]; DPRINTF("slot:%X, flags:%X, start:%llX, size:%llX, ram:%llX)\n", mem->slot, mem->flags, mem->guest_phys_addr, mem->memory_size, mem->userspace_addr); r = NEXT_FNC(ioctl)(g_vm_fd, KVM_SET_USER_MEMORY_REGION, &g_kvm_mem_region[i]); if (r < 0) { DPRINTF("ERROR: Creating memory region #%d returned: \n", i, r); perror("ioctl(KVM_SET_USER_MEMORY_REGION)"); } } /* See note in the ioctl() wrapper. */ DPRINTF("Setting routing tables. ptr: %p...\n", g_kvm_gsi_routing_table); r = NEXT_FNC(ioctl)(g_vm_fd, KVM_SET_GSI_ROUTING, g_kvm_gsi_routing_table); if (r < 0) { DPRINTF("ERROR: Setting routing table (#routes=%d) returned: " "%d\n", g_kvm_gsi_routing_table->nr, r); } r = create_pit2(); if (r < 0) { DPRINTF("Creating PIT2 returned: %d\n", r); } r = restore_pit2(); if (r < 0) { DPRINTF("ERROR: Restoring PIT2 returned: %d\n", r); DPRINTF("WARNING: Cannot continue\n"); exit(-1); } int array[] = { 0, 1, 4, 8, 12 }; g_kvm_irq_level.level = 0; for (i = 0; i < 5; i++) { g_kvm_irq_level.irq = array[i]; r = NEXT_FNC(ioctl)(g_vm_fd, KVM_IRQ_LINE_STATUS, &g_kvm_irq_level); if (r < 0) { DPRINTF("ERROR: Resetting IRQ#%d LINE returned: %d\n", g_kvm_irq_level.irq, r); exit(-1); } } r = restore_irqchip(); if (r < 0) { DPRINTF("ERROR: Restoring IRQCHIP returned: %d\n", r); DPRINTF("WARNING: Cannot continue\n"); exit(-1); } r = NEXT_FNC(ioctl)(g_vcpu_fd, KVM_TPR_ACCESS_REPORTING, &g_kvm_tpr_access_ctl); if (r < 0) { DPRINTF("ERROR: Restoring the tpr access reporting returned: %d\n", r); DPRINTF("WARNING: Cannot continue\n"); exit(-1); } r = NEXT_FNC(ioctl)(g_vcpu_fd, KVM_SET_VAPIC_ADDR, &g_kvm_vapic_addr); if (r < 0) { DPRINTF("ERROR: Restoring the vapic addr returned: %d\n", r); DPRINTF("WARNING: Cannot continue\n"); exit(-1); } r = restore_registers(); if (r < 0) { DPRINTF("ERROR: Restoring the registers returned: %d\n", r); DPRINTF("WARNING: Cannot continue\n"); exit(-1); } } } }