Exemple #1
0
app_frontend* add_app_lb(provider *pv, struct application *app){

    app_frontend *app_fe = malloc(sizeof(app_frontend));
    app_fe->active = 1;
    app_fe->id= app->id;
    app_fe->pv = pv;
    //app_fe->num_nodes_front_end = app->str.nodeslayer[0];
    //app_fe->num_nodes_read = app->str.nodeslayer[1];
    //app_fe->num_nodes_write = app->str.nodeslayer[2];
    app_fe->app = app;  
    app_fe->rr = 0; 
    app_fe->vm = init_vm(app);
    app_fe->next = NULL;
    app_fe->prev = NULL;
    
    if( pv->lb->app_num == 0){
	pv->lb->first = app_fe;
	pv->lb->last = app_fe;
    }
    else{
	pv->lb->last->next = app_fe;
	app_fe->prev =  pv->lb->last;
	pv->lb->last = app_fe;
    }
    pv->lb->app_num++;
    return(app_fe);
}
//**************************************************
// セットアップします
//**************************************************
void setup()
{
    pinMode(RB_LED, OUTPUT);

#if BOARD == BOARD_GR
    pinMode(PIN_LED0, OUTPUT);
    pinMode(PIN_LED1, OUTPUT);
    pinMode(PIN_LED2, OUTPUT);
    pinMode(PIN_LED3, OUTPUT);
#endif

	//ピンモードを入力に初期化します
	pinModeInit();
	
	//シリアル通信の初期化
	Serial.begin(115200);		//仮想USBシリアル
    //Serial.setDefault();
	//sci_convert_crlf_ex(Serial.get_handle(), CRLF_NONE, CRLF_NONE);	//バイナリを通せるようにする

	//vmの初期化
	init_vm();

	//Port 3-5がHIGHだったら、EEPROMファイルローダーに飛ぶ
	if( FILE_LOAD == 1 ){
		fileloader((const char*)ProgVer,MRUBY_VERSION);
	}
}
Exemple #3
0
int main(int argc, char **argv)
{
	if(argc == 1) {
		fprintf(stderr, "Usage: %s FILE\n", argv[0]);
		exit(1);
	}

	errno = 0;
	size_t size;
	int32_t *mem = read_file(argv[1], &size);
	if(!mem) {
		if(errno)
			perror(argv[0]);
		else
			fprintf(stderr, "%s: The file was invalid.\n", argv[0]);
		exit(1);
	}

	init_vm(mem, size);

	while(1) {
		run_vm();
		render_screen();
		process_events();
		delay();
	}
}
Exemple #4
0
static ErlDrvData
emonk_start(ErlDrvPort port, char *cmd)
{
    uint rt_max, gc_max, gc_last, ctx;
    emonk_drv_t* drv = NULL;
    ErlDrvData ret = ERL_DRV_ERROR_GENERAL;
    emonk_settings_t settings;
    
    if(parse_settings(cmd, &settings) < 0)
    {
        ret = ERL_DRV_ERROR_BADARG;
        goto error;
    }
    
    drv = (emonk_drv_t*) driver_alloc(sizeof(emonk_drv_t));
    if(drv == NULL) goto error;

    drv->port = port;
    drv->ok = driver_mk_atom("ok");
    drv->error = driver_mk_atom("error");
    drv->undefined = driver_mk_atom("undefined");
    drv->bad_cmd = driver_mk_atom("bad_command");
    
    drv->vm = init_vm(&settings);
    if(drv->vm == NULL) goto error;
    
    return (ErlDrvData) drv;

error:
    if(drv != NULL) driver_free(drv);
    return ret;
}
Exemple #5
0
/* Main ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int main(int argc, char **argv)
{
  int i;
  VM *vm = malloc(sizeof(VM));
  strcpy(vm->filename, "retroImage");

  init_vm(vm);
  dev_init_input();

  /* Parse the command line arguments */
  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "--with") == 0)
      dev_include(argv[++i]);
    if (strcmp(argv[i], "--image") == 0)
      strcpy(vm->filename, argv[++i]);
    if (strcmp(argv[i], "--shrink") == 0)
      vm->shrink = 1;
  }

  dev_init_output();

  if (vm_load_image(vm, vm->filename) == -1) {
    dev_cleanup();
    printf("Sorry, unable to find %s\n", vm->filename);
    exit(1);
  }

  for (vm->ip = 0; vm->ip < IMAGE_SIZE; vm->ip++)
    vm_process(vm);

  dev_cleanup();
  return 0;
}
Exemple #6
0
int main() {
    VM* vm = init_vm(100,100);

    do_main(vm, NULL);
    printf("%ld\n", GETINT(RVAL));    

    printf("%d %d %d\n", vm->valstack, vm->valstack_base, vm->valstack_top);
}
Exemple #7
0
VM* idris_vm() {
    VM* vm = init_vm(4096000, 4096000, 1);
    init_threadkeys();
    init_threaddata(vm);
    init_gmpalloc();
    init_nullaries();

    return vm;
}
Exemple #8
0
errcode_t init_test(test_t * test, const char * programfile, const char * testfile)
{
    errcode_t retval;
    FILE * in;
    uint16_t i;
    uint16_t next_gpio_value;
    char filename[256];

    retval = init_vm(&test->uut);
    CHECK_OK(retval, "Failed to init vm\n");
    retval = load_program(&test->uut, programfile);
    CHECK_OK(retval, "Failed to load program\n");
    
    in = fopen(testfile, "r");
    CHECK_NOT_NULL(in, IO, "Failed to open test file\n");
    fscanf(in, "%u", &test->test_length);
    CHECK_NOT_FERROR(in);

    /*
    test->uart_in = fopen("uartin.dat", "w");
    CHECK_NOT_NULL(test->uart_in, IO, "Failed to open UART in file\n");
    test->uart_out = fopen("uartout.dat", "w");
    CHECK_NOT_NULL(test->uart_out, IO, "Failed to open UART out file\n");
    */
    for (i = 0; i < TEST_PIN_COUNT; i++)
    {
        sprintf(filename, "gpio_%u.dat", i);
        test->gpio_files[i] = fopen(filename, "w");
        CHECK_NOT_NULL(test->gpio_files[i], IO, "Failed to open GPIO file\n");
    }

    test->input_size = 0;
    while (!feof(in))
    {
        fscanf(in, "%u %u %hu", &test->gpio_input[test->input_size].time, &test->gpio_input[test->input_size].pin, &next_gpio_value);
        test->gpio_input[test->input_size].value = (uint8_t)next_gpio_value;
        test->input_size++;
    }
    test->input_size--;  /* discard excessive read */
    fclose(in);

    for (i = 0; i < test->uut.proc_table_size; i++)
    {
        sprintf(filename, "sched_%u.dat", i);
        test->schedules[i] = fopen(filename, "w");
        CHECK_NOT_NULL(test->schedules[i], IO, "Failed to open schedule file\n");
    }
    return OK;
}
Exemple #9
0
int main(int argc, const char *argv[])
{
	init_vm();

	switch (argc)
	{
		case 1:
			repl();
			break;
		case 2:
			runFile(argv[1]);
			break;
		default:
			fprintf(stderr, "Usage: coil [path]\n");
			exit(64);
	}
	free_vm();
	return 0;
}
Exemple #10
0
int		main(int argc, char **argv)
{
	t_vm	*vm;
	int		dump;

	if (argc > 1)
	{
		if (!(vm = init_vm()))
			exit(write(2, "No memory\n", 10));
		dump = -1;
		parse_args(argc, argv, vm, &dump);
		if (vm->nb_players < 1)
			exit(write(2, "No players\n", 11));
		vm->last_player = vm->players[vm->nb_players - 1]->number;
		load_players_in_memory(vm);
		run_vm(vm, dump);
		print_winner(vm);
		free_vm(vm);
	}
	return (0);
}
Exemple #11
0
int main() {
    int argc;
    char **argv;
    win32_get_argv_utf8(&argc, &argv);
#else
int main(int argc, char **argv) {
#endif
    parse_shift_args(&opts, &argc, &argv);

    __idris_argc = argc;
    __idris_argv = argv;

    VM* vm = init_vm(opts.max_stack_size, opts.init_heap_size, 1);
    init_threadkeys();
    init_threaddata(vm);
    init_gmpalloc();

    init_nullaries();
    init_signals();

    _idris__123_runMain0_125_(vm, NULL);

#ifdef IDRIS_DEBUG
    if (opts.show_summary) {
        idris_gcInfo(vm, 1);
    }
#endif

    Stats stats = terminate(vm);

    if (opts.show_summary) {
        print_stats(&stats);
    }

    free_nullaries();
    return EXIT_SUCCESS;
}
Exemple #12
0
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
int main(void)
{
  message msg;
  int result, who_e, rcv_sts;
  int caller_slot;

  /* Initialize system so that all processes are runnable */
  init_vm();

  /* Register init callbacks. */
  sef_setcb_init_restart(sef_cb_init_fail);
  sef_setcb_signal_handler(sef_cb_signal_handler);

  /* Let SEF perform startup. */
  sef_startup();

  SANITYCHECK(SCL_TOP);

  /* This is VM's main loop. */
  while (TRUE) {
	int r, c;
	u32_t type, param;

	SANITYCHECK(SCL_TOP);
	if(missing_spares > 0) {
		alloc_cycle();	/* mem alloc code wants to be called */
	}

  	if ((r=sef_receive_status(ANY, &msg, &rcv_sts)) != OK)
		panic("sef_receive_status() error: %d", r);

	if (is_ipc_notify(rcv_sts)) {
		/* Unexpected notify(). */
		printf("VM: ignoring notify() from %d\n", msg.m_source);
		continue;
	}
	who_e = msg.m_source;
	if(vm_isokendpt(who_e, &caller_slot) != OK)
		panic("invalid caller %d", who_e);

	type = param = msg.m_type;
	type &= 0x0000FFFF;
	param >>= 16;
	c = CALLNUMBER(type);
	result = ENOSYS; /* Out of range or restricted calls return this. */
	
	if(msg.m_type == RS_INIT && msg.m_source == RS_PROC_NR) {
		result = do_rs_init(&msg);
	} else if (msg.m_type == VM_PAGEFAULT) {
		if (!IPC_STATUS_FLAGS_TEST(rcv_sts, IPC_FLG_MSG_FROM_KERNEL)) {
			printf("VM: process %d faked VM_PAGEFAULT "
					"message!\n", msg.m_source);
		}
		do_pagefaults(&msg);
		/*
		 * do not reply to this call, the caller is unblocked by
		 * a sys_vmctl() call in do_pagefaults if success. VM panics
		 * otherwise
		 */
		continue;
	} else if(c < 0 || !vm_calls[c].vmc_func) {
		/* out of range or missing callnr */
	} else {
		if (acl_check(&vmproc[caller_slot], c) != OK) {
			printf("VM: unauthorized %s by %d\n",
					vm_calls[c].vmc_name, who_e);
		} else {
			SANITYCHECK(SCL_FUNCTIONS);
			result = vm_calls[c].vmc_func(&msg);
			SANITYCHECK(SCL_FUNCTIONS);
		}
	}

	/* Send reply message, unless the return code is SUSPEND,
	 * which is a pseudo-result suppressing the reply message.
	 */
	if(result != SUSPEND) {
		msg.m_type = result;
		if((r=send(who_e, &msg)) != OK) {
			printf("VM: couldn't send %d to %d (err %d)\n",
				msg.m_type, who_e, r);
			panic("send() error");
		}
	}
  }
  return(OK);
}
Exemple #13
0
int main (int argc, char *argv[])
{
	char *fn;
	int f_ret, u_ret;

	prog_name	= argv[0]; 
	tvm_argc	= argc;
	tvm_argv	= argv;

	if (argc < 2) {
		usage (stderr);
		return 1;
	} else {
		fn = argv[1];
	}

	init_vm ();

	if (install_user_ctx (fn) < 0) {
		error_out_no_errno ("failed to load user bytecode");
		return 1;
	}
	if (install_firmware_ctx () < 0) {
		error_out_no_errno ("failed to install firmware");
		return 1;
	}

	kyb_channel = NOT_PROCESS_P;
	scr_channel = NOT_PROCESS_P;
	err_channel = NOT_PROCESS_P;

	for (;;) {
		f_ret = run_firmware ();
		u_ret = run_user ();

		if ((f_ret == ECTX_EMPTY || f_ret == ECTX_SLEEP) &&
			(u_ret == ECTX_EMPTY || u_ret == ECTX_SLEEP)) {
			if (firmware->fptr == NOT_PROCESS_P && user->fptr == NOT_PROCESS_P) {
				tvm_sleep ();
			}
		} else if (f_ret == ECTX_ERROR || u_ret == ECTX_ERROR) {
			break;
		} else if (u_ret == ECTX_SHUTDOWN) {
			/* Run firmware to clear buffers */
			run_firmware ();
			break;
		}
	}
	
	if (u_ret == ECTX_ERROR) {
		tbc_t *tbc = user->priv.bytecode->tbc;

		if (tbc->debug) {
			tbc_dbg_t	*dbg = tbc->debug;
			tbc_lnd_t	*ln;
			tenc_str_t 	*file;
			int offset = user->iptr - tbc->bytecode;
			int i = 0;

			while (i < dbg->n_lnd) {
				if (dbg->lnd[i].offset > offset) {
					break;
				}
				i++;
			}
			ln = &(dbg->lnd[i - 1]);

			file = dbg->files;
			for (i = 0; i < ln->file; ++i) {
				file = file->next;
			}

			fprintf (stderr,
				"Error at %s:%d\n",
				file->str, ln->line
			);
		}

		/* FIXME: more debugging */
		fprintf (stderr, 
			"Program failed, state = %c, eflags = %08x\n",
			user->state, user->eflags
		);

		return 1;
	}
	
	free_ectx (firmware);
	free_ectx (user);
	free_bytecode (fw_bc);
	free_bytecode (us_bc);

	#ifdef TVM_PROFILING
	output_profiling ();
	#endif

	return 0;
}
Exemple #14
0
/******************************************************
 * Main entry point into the VM
 ******************************************************/
int main(int argc, char **argv)
{
  int a, i, endian;
  char *opstat_path = 0;
  FILE *opstats = 0;

  VM *vm = malloc(sizeof(VM));

  endian = 0;

  strcpy(vm->filename, "retroImage");

  init_vm(vm);
  dev_init(INPUT);

  vm->shrink = 0;
  vm->trace = 0;
  vm->trace_stacks = 0;

  /* Parse the command line arguments */
  for (i = 1; i < argc; i++)
  {
    if (strcmp(argv[i], "--trace") == 0)
    {
      vm->trace = -1;
    }
    else if (strcmp(argv[i], "--trace-stacks") == 0)
    {
      vm->trace_stacks = -1;
    }
    else if (strcmp(argv[i], "--endian") == 0)
    {
      endian = -1;
    }
    else if (strcmp(argv[i], "--with") == 0)
    {
      i++; dev_include(argv[i]);
    }
    else if (strcmp(argv[i], "--opstats") == 0)
    {
      i++; opstat_path = argv[i];
      init_stats(&opstats, opstat_path, call_stats_please);
    }
    else if (strcmp(argv[i], "--callstats") == 0)
    {
      call_stats_please = 1;
      if (opstat_path)
      {
        init_stats(&opstats, opstat_path, call_stats_please);
      }
    }
    else if (strcmp(argv[i], "--shrink") == 0)
    {
      vm->shrink = 1;
    }
    else if ((strcmp(argv[i], "--help") == 0) ||
             (strcmp(argv[i], "-help") == 0)  ||
             (strcmp(argv[i], "/help") == 0)  ||
             (strcmp(argv[i], "/?") == 0)     ||
             (strcmp(argv[i], "/h") == 0)     ||
             (strcmp(argv[i], "-h") == 0))
    {
      fprintf(stderr, "%s [options] [imagename]\n", argv[0]);
      fprintf(stderr, "Valid options are:\n");
      fprintf(stderr, "   --about          Display some information about Ngaro\n");
      fprintf(stderr, "   --trace          Trace instructions being executed\n");
      fprintf(stderr, "     --trace-stacks Also trace data and return stack contents\n");
      fprintf(stderr, "   --endian         Load an image with a different endianness\n");
      fprintf(stderr, "   --shrink         Shrink the image to the current heap size when saving\n");
      fprintf(stderr, "   --with [file]    Treat [file] as an input source\n");
      fprintf(stderr, "   --opstats [file] Write statistics about VM operations to [file]\n");
      fprintf(stderr, "      --callstats      Include how many times each address is called (slow)\n");
      fprintf(stderr, "                       Also includes distribution of stack depths.\n");
      exit(0);
    }
    else if ((strcmp(argv[i], "--about") == 0) ||
             (strcmp(argv[i], "--version") == 0))
    {
      fprintf(stderr, "Retro Language  [VM: C, console]\n\n");
      exit(0);
    }
    else
    {
      strcpy(vm->filename, argv[i]);
    }
  }

  dev_init(OUTPUT);

  a = vm_load_image(vm, vm->filename);
  if (a == -1)
  {
    dev_cleanup();
    printf("Sorry, unable to find %s\n", vm->filename);
    exit(1);
  }

  /* Swap endian if --endian was passed */
  if (endian == -1)
    swapEndian(vm);

  /* Process the image */
  if (opstats == 0)
  {
    for (vm->ip = 0; vm->ip < IMAGE_SIZE; vm->ip++)
      vm_process(vm);
  }
  else
  {
    for (vm->ip = 0; vm->ip < IMAGE_SIZE; vm->ip++)
    {
      collect_stats(vm);
      vm_process(vm);
    }
    report_stats(opstats);
  }

  /* Once done, cleanup */
  dev_cleanup();
  return 0;
}
Exemple #15
0
int
start_live(struct radclock_handle *handle)
{
	/* Threads */
	void* thread_status;

	int have_fixed_point_thread = 0;
	int err;

	JDEBUG

	/*
	 * Handle first time run. If no time_server specified while we produce
	 * packets, we would be a nasty CPU hog. Better avoid creating problems and
	 * exit with an error message
	 */
	if ((handle->conf->synchro_type == SYNCTYPE_NTP) ||
			(handle->conf->synchro_type == SYNCTYPE_1588)) {
		if (strlen(handle->conf->time_server) == 0) {
			verbose(LOG_ERR, "No time server specified on command line "
					"or configuration file, attempting suicide.");
			return (1);
		}
	}

	/*
	 * This thread triggers the processing of data. It could be a dummy sleeping
	 * loop, an NTP client, a 1588 slave  ...
	 */
	if (!VM_SLAVE(handle)) {
		err = start_thread_TRIGGER(handle);
		if (err < 0)
			return (1);
	}

	/*
	 * This thread is in charge of processing the raw data collected, magically
	 * transform the data into stamps and give them to the sync algo for
	 * processing.
	 */
	if (handle->unix_signal == SIGHUP) {
		/*
		 * This is not start, but HUP, the algo thread is still running
		 * Simply clear the flag and bypass
		 */
		handle->unix_signal = 0;
	}
	else {
		if (VM_SLAVE(handle) || VM_MASTER(handle)) {
			err = init_vm(handle);
			if (err < 0){
				verbose(LOG_ERR, "Failed to initialise VM communication");
				return (1);
			}
		}
		if (!VM_SLAVE(handle)) {
			err = start_thread_DATA_PROC(handle);
			if (err < 0)
				return (1);
		}
	   
	}

	/* Are we running an NTP server for network clients ? */
	switch (handle->conf->server_ntp) {
	case BOOL_ON:
		err = start_thread_NTP_SERV(handle);
		if (err < 0)
			return (1);
		break;
	case BOOL_OFF:
	default:
		/* do nothing */
		break;
	}

	/* Are we running a VM UDP server for network guests ? */
	switch (handle->conf->server_vm_udp) {
	case BOOL_ON:
		err = start_thread_VM_UDP_SERV(handle);
		if (err < 0)
			return (1);
		break;
	case BOOL_OFF:
	default:
		/* do nothing */
		break;
	}

	/*
	 * To be able to provide the RADCLOCK timestamping mode, we need to refresh
	 * the fixed point data in the kernel.  That's this guy's job.
	 * XXX Update: with kernel version 2, the overflow problem is taking care of
	 * by the kernel. The fixedpoint thread is deprecated and should be removed
	 * in the future
	 */
	if ((handle->run_mode == RADCLOCK_SYNC_LIVE) &&
			(handle->clock->kernel_version < 2)) {
		err = start_thread_FIXEDPOINT(handle);
		if (err < 0)
			return (1);
		have_fixed_point_thread = 1;
	}
	else
		have_fixed_point_thread = 0;

	/*
	 * That's our main capture loop, it does not return until the end of
	 * input or if we explicitely break it
	 * XXX TODO XXX: a unique source is assumed !!
	 */
	err = capture_raw_data(handle);

	if (err == -1) {
		/* Yes, we abuse this a bit ... */
		handle->unix_signal = SIGTERM;
		verbose(LOG_NOTICE, "Reached end of input");
	}
	if (err == -2) {
		verbose(LOG_NOTICE, "Breaking current capture loop for rehash");
	}

	/*
	 * pcap_break_loop() has been called or end of input. In both cases kill the
	 * threads. If we rehash, they will be restarted anyway.
	 */
	verbose(LOG_NOTICE, "Send killing signal to threads. Wait for stop message.");
	handle->pthread_flag_stop = PTH_STOP_ALL;

	/* Do not stop sync algo thread if we HUP */
	if (handle->unix_signal == SIGHUP)
		handle->pthread_flag_stop &= ~PTH_DATA_PROC_STOP;

	if (handle->conf->server_ntp == BOOL_ON) {
		pthread_join(handle->threads[PTH_NTP_SERV], &thread_status);
		verbose(LOG_NOTICE, "NTP server thread is dead.");
	}

	pthread_join(handle->threads[PTH_TRIGGER], &thread_status);
	verbose(LOG_NOTICE, "Trigger thread is dead.");

	if (have_fixed_point_thread) {
		pthread_join(handle->threads[PTH_FIXEDPOINT], &thread_status);
		verbose(LOG_NOTICE, "Kernel fixedpoint thread is dead.");
	}
	
	/* Join on TERM since algo has been told to die */
	if (handle->unix_signal != SIGHUP) {
		pthread_join(handle->threads[PTH_DATA_PROC], &thread_status);
		verbose(LOG_NOTICE, "Data processing thread is dead.");
		/* Reinitialise flags */
		handle->pthread_flag_stop = 0;
		verbose(LOG_NOTICE, "Threads are dead.");
		/* We received a SIGTERM, we exit the loop. */
		return (1);
	}
	else {
		handle->pthread_flag_stop = 0;
	}

	return (0);
}
Exemple #16
0
int main(int argc, char *argv[])
{
	int c;
	int is_default_name = true;
	int has_obj_name = false;
	char fn_in[100];
	char fn_out[100];
	char temp_name[100];
//	printf("%d",sizeof(OpCode));
	
	if(!find_source_file(argc,argv,fn_in)){
		fprintf(stderr,"no input file\n");
	}
	
	while((c=getopt(argc,argv,"xVvHhS:s:o:")) != -1){
        
		switch (c) {
        	case 'S':
        	case 's':
        		strcpy(temp_name,fn_in);
        		str_find_replace(temp_name,'.','\0');
        		strcat(temp_name,".s");
        		strcpy(fn_out,temp_name);
        		gen_op_code = true;
        		goto end;
        		break;
        	case 'x':
        		break;
            case 'o':
            	if(!file_name_vaild(optarg,'o')){
        			fprintf(stderr,"input file name is invaild\n");
        			return 0;
        		}
        		strcpy(fn_out,optarg);
        		is_default_name = false;
            	break;
        	case 'V':
        	case 'v':
        		version();
             	break;
            case 'H':
            case 'h':
            	help();
            	break;
        	default:
            	break;
        }
    }
    
end:
	input_stream = fopen(fn_in,"r+");
	
	if(gen_op_code){
		output_stream = fopen(fn_out,"w+");
		compile();
	}else{
		if(is_default_name){
			//str_find_replace(fn_in,'.','\0');	
        	//strcat(fn_in,".out");
        	//use fn_in to write file
        	output_stream = fopen("a.out","w+");
        	
		}else{
			output_stream = fopen(fn_out,"w+");
		}
		compile();
		process_struct_code();
		//write_binary_struct_code();
		init_vm();
		start_vm();
		
	}
    
	return 0;
}
Exemple #17
0
int run_vm(void) {
#if !defined(VM_CLOCKINTERRUPTHANDLER_INTERRUPT)
	Object temp;
	int32* mainMethodJavaStack;
#endif

	int16 execp = 0;
	/* Required for certain compilers. */
	init_compiler_specifics();

	/* Function below allocates the initial heap. This is done in
	 * initDefaultRAMAllocationPoint in allocation_point.c
	 */
	init_vm();

#if defined(ENABLE_DEBUG)
	connectToDebugger();
	sendStartEvent();
	while (awaitCommandFromDebugger(0, 0, 0) != RESUME_EVENT) {;}
#endif

	/* Allocating the main stack is delegated to the target specific function
	 * 'get_java_stack_base'. On some architectures/environments it is located
	 * at fixed positions in certain compiler specific sections. The implementor
	 * can allocate the stack in the heap if so desired.
	 * */
	mainMethodJavaStack = get_java_stack_base(JAVA_STACK_SIZE);

#if defined(VM_CLOCKINTERRUPTHANDLER_INTERRUPT)
	/* If more threads are started we give the main thread a new C stack pointer.
	 * In case of no other threads running the main thread just inherits the
	 * current C stack.
	 *
	 * In this case we save the current C stack so we may restore it later. This
	 * is required to terminate the process properly.
	 */
	mainStackPointer = (pointer) get_stack_pointer();

	/* mainMethodJavaStack contains both Java and C stack. Java stack grows
	 * upwards from the beginning, C stack downwards from the end. */
	stackPointer = (pointer) &mainMethodJavaStack[JAVA_STACK_SIZE - 2];
	/* 'set_stack_pointer' sets the C stack */
	stackPointer = (pointer) & mainMethodJavaStack[JAVA_STACK_SIZE - 2];
	set_stack_pointer();
#endif

#if defined(REPORTCYCLES)
	papi_start();
	papi_mark();
	papi_mark();
	papi_mark();
	papi_mark();
	papi_mark();
	papi_mark();
#endif

#if defined(LDC2_W_OPCODE_USED) || defined(LDC_W_OPCODE_USED) || defined(LDC_OPCODE_USED) || defined(HANDLELDCWITHINDEX_USED)
	execp = initializeConstants(mainMethodJavaStack);
	if (execp == -1) {
#endif

		execp = initializeExceptions(mainMethodJavaStack);
		if (execp == -1) {

#if defined(INVOKECLASSINITIALIZERS)
			execp = invokeClassInitializers(mainMethodJavaStack);
			if (execp == -1) {
#endif
				/* This is only for testing. All tests will write 0 (null) to
				 * '*mainMethodJavaStack' if the test is successful.
				 */
				*mainMethodJavaStack = (int32) (pointer) &temp;

#if defined(VM_CLOCKINTERRUPTHANDLER_ENABLE_USED)
				start_system_tick();
#endif

#if defined(DEVICES_SYSTEM_INITIALIZESYSTEMCLASS)
				execp = enterMethodInterpreter(
				DEVICES_SYSTEM_INITIALIZESYSTEMCLASS, mainMethodJavaStack);
				if (execp == -1) {
#endif
						/* Start the VM */
						execp = enterMethodInterpreter(mainMethodIndex,
								mainMethodJavaStack);
#if defined(VM_CLOCKINTERRUPTHANDLER_ENABLE_USED)
						stop_system_tick();
#endif
#if defined(DEVICES_SYSTEM_INITIALIZESYSTEMCLASS)
				}
#endif
			}
			/* TODO: use executeWithStack instead */
#if defined(INVOKECLASSINITIALIZERS)
		}
#endif

#if defined(LDC2_W_OPCODE_USED) || defined(LDC_W_OPCODE_USED) || defined(LDC_OPCODE_USED) || defined(HANDLELDCWITHINDEX_USED)
	}
#endif

#if defined(REPORTCYCLES)
	papi_mark();
#endif

	mark_error();

	if (execp >= 0) {
#if defined(JAVA_LANG_THROWABLE_INIT_)
		handleException(execp);
#endif
#if defined(VM_CLOCKINTERRUPTHANDLER_INTERRUPT)
		/* Restore C stack pointer. Otherwise we could not return from here properly */
		stackPointer = (pointer) mainStackPointer;
		set_stack_pointer();
#endif
		return ERROR;
	}

#if defined(VM_CLOCKINTERRUPTHANDLER_INTERRUPT)
	/* Restore C stack pointer. Otherwise we could not return from here properly */
	stackPointer = (pointer) mainStackPointer;
	set_stack_pointer();
#endif

#if defined(ENABLE_DEBUG)
	disconnectFromDebugger();
#endif

	if (*mainMethodJavaStack) {
		return ERROR;
	} else {
		mark_success();
		return SUCCESS;
	}

	return 0;
}
Exemple #18
0
/******************************************************
 *|F| int main(int argc, char **argv)
 ******************************************************/
int main(int argc, char **argv)
{
  int a, i, trace, endian;

  printf("Video @ %i\n", VIDEO_BASE);

  trace = 0;
  endian = 0;

  strcpy(vm.filename, "retroImage");

  init_vm();
  init_devices();

  vm.shrink = 0;

  /* Parse the command line arguments */
  for (i = 1; i < argc; i++)
  {
    if (strcmp(argv[i], "--trace") == 0)
    {
      trace = 1;
    }
    else if (strcmp(argv[i], "--endian") == 0)
    {
      endian = 1;
    }
    else if (strcmp(argv[i], "--shrink") == 0)
    {
      vm.shrink = 1;
    }
    else if (strcmp(argv[i], "--help") == 0)
    {
      fprintf(stderr, "%s [options] [imagename]\n", argv[0]);
      fprintf(stderr, "Valid options are:\n");
      fprintf(stderr, "   --trace    Execution trace\n");
      fprintf(stderr, "   --endian   Load an image with a different endianness\n");
      fprintf(stderr, "   --shrink   Only save used heap during save operation\n");
      exit(0);
    }
    else
    {
      strcpy(vm.filename, argv[i]);
    }
  }


  /* Load the image */
  a = vm_load_image(vm.filename);

  /* Swap endian if --endian was passed */
  if (endian == 1)
    swapEndian();


  /* Process the image */
  if (trace == 0)
  {
    for (vm.ip = 0; vm.ip < IMAGE_SIZE; vm.ip++)
    {
      vm_process(vm.image[vm.ip]);
      update_display(0);
    }
  }
  else
  {
    for (vm.ip = 0; vm.ip < IMAGE_SIZE; vm.ip++)
    {
      display_instruction();
      vm_process(vm.image[vm.ip]);
      update_display(0);
    }
  }

  /* Once done, cleanup */
  cleanup_devices();
  return 0;
}
Exemple #19
0
PRIVATE void compile_main(FILE *conni, FILE *conno) {
  REPL_DATA rd = allocmem(sizeof(repl_data));
  VMstate vms;

  rd->h1 = rd->h2 = NULL;

  protect(&rd->h1);
  protect(&rd->h2);

  rd->vmregs = (VMREGS) newvector(NUM_VMREGS);	/* dodgy casting :-) */
  vms.r = rd->vmregs;
  protect((OBJ *)(&rd->vmregs));

  init_vm(&vms);
  vms.c.vm_state = VM_STATE_NOQUOTA;

  while (vms.c.vm_state != VM_STATE_DYING) {
    ScanInst si;
    char buf[16384];

    rd->h1 = (OBJ) newbvector(0);

    while (1) {
      char *result;

      result = fgets(buf, 256, conni);

      if (result == NULL)
	break;

      while (1) {
	int l = strlen(buf);
	if (buf[l-1] == '\r' || buf[l-1] == '\n')
	  buf[l-1] = '\0';
	else
	  break;
      }
      strcat(buf, "\n");

      if (!strcmp(buf, ".\n"))
	break;

      rd->h2 = (OBJ) newstring(buf);
      rd->h1 = (OBJ) bvector_concat((BVECTOR) rd->h1, (BVECTOR) rd->h2);
    }

    gc_reach_safepoint();

    rd->h2 = (OBJ) newstringconn((BVECTOR) rd->h1);
    fill_scaninst(&si, (OVECTOR) rd->h2);

    while (!conn_closed((OVECTOR) rd->h2)) {
      rd->h1 = (OBJ) parse(&vms, &si);
      gc_reach_safepoint();

      if (rd->h1 == NULL) {
	sprintf(buf, "-->! the compiler returned NULL.\n");
      } else {
	vms.c.vm_state = VM_STATE_NOQUOTA;

	ATPUT((OVECTOR) rd->h1, ME_OWNER, (OBJ) vms.r->vm_uid);
	vms.r->vm_effuid = vms.r->vm_uid;
	{
	  OVECTOR c = newovector_noinit(CL_MAXSLOTINDEX, T_CLOSURE);
	  ATPUT(c, CL_SELF, NULL);
	  ATPUT(c, CL_METHOD, rd->h1);
	  rd->h1 = (OBJ) c;
	}
	apply_closure(&vms, (OVECTOR) rd->h1, newvector_noinit(1));

	while (!run_vm(&vms)) ;

	rd->h1 = (OBJ) newvector(2);
	ATPUT((VECTOR) rd->h1, 0, NULL);
	ATPUT((VECTOR) rd->h1, 1, vms.r->vm_acc);
	rd->h1 = lookup_prim(0x00001, NULL)(&vms, (VECTOR) rd->h1);
	rd->h1 = (OBJ) bvector_concat((BVECTOR) rd->h1, newbvector(1));
      	/* terminates C-string */

	gc_reach_safepoint();

	sprintf(buf, "--> %s\n", ((BVECTOR) rd->h1)->vec);
      }

      fputs(buf, conno);
    }
  }

  unprotect((OBJ *)(&rd->vmregs));
  unprotect(&rd->h2);
  unprotect(&rd->h1);

  freemem(rd);
}