Ejemplo n.º 1
0
void sim_init()
{
    /* Create memory and register files */
    initialized = 1;
    mem = init_mem(MEM_SIZE);
    reg = init_reg();
    
    /* create 5 pipe registers */
    pc_state     = new_pipe(sizeof(pc_ele), (void *) &bubble_pc);
    if_id_state  = new_pipe(sizeof(if_id_ele), (void *) &bubble_if_id);
    id_ex_state  = new_pipe(sizeof(id_ex_ele), (void *) &bubble_id_ex);
    ex_mem_state = new_pipe(sizeof(ex_mem_ele), (void *) &bubble_ex_mem);
    mem_wb_state = new_pipe(sizeof(mem_wb_ele), (void *) &bubble_mem_wb);
  
    /* connect them to the pipeline stages */
    pc_next   = pc_state->next;
    pc_curr   = pc_state->current;
  
    if_id_next = if_id_state->next;
    if_id_curr = if_id_state->current;

    id_ex_next = id_ex_state->next;
    id_ex_curr = id_ex_state->current;

    ex_mem_next = ex_mem_state->next;
    ex_mem_curr = ex_mem_state->current;

    mem_wb_next = mem_wb_state->next;
    mem_wb_curr = mem_wb_state->current;

    sim_reset();
    clear_mem(mem);
}
Ejemplo n.º 2
0
void
assemble_intercode(struct intercode* ic_head, FILE *fout){


	assert(ic_head != NULL);
	struct intercode* func_start_ic = ic_head -> next;
	fp = fout;
		
	fprintf(fp,	
			".data\n"
			"_prompt: .asciiz \"Enter an integer:\"\n"
			"_ret: .asciiz \"\\n\"\n"
			".globl main\n"
			".text\n"
			"\nread:\n"
			"	li $v0, 4\n"
			"	la $a0, _prompt\n"
			"	syscall\n"
			"	li $v0, 5\n"
			"	syscall\n"
			"	jr $ra\n"
			"\nwrite:\n"
			"	li $v0, 1\n"
			"	syscall\n"
			"	li $v0, 4\n"
			"	la $a0, _ret\n"
			"	syscall\n"
			"	move $v0, $0\n"
			"	jr $ra\n");

	/*assembling*/
	while(func_start_ic != NULL){

		struct intercode* func_stop_ic = find_func_stop_ic(func_start_ic);

		/*init s_reg and t_reg per func*/
		int i;
		for (i = 0; i < S_REG_NUM; ++i)
			init_reg(&s_reg[i], S_REG, i);
		for (i = 0; i < T_REG_NUM; ++i)
			init_reg(&t_reg[i], T_REG, i);
		
		assemble_func(func_start_ic, func_stop_ic);
		func_start_ic = func_stop_ic -> next;

	}
}
Ejemplo n.º 3
0
/* create an y86 image with registers and memory */
y86sim_t *new_y86sim(int slen)
{
    y86sim_t *sim = (y86sim_t*)malloc(sizeof(y86sim_t));
    sim->pc = 0;
    sim->r = init_reg();
    sim->m = init_mem(slen);
    sim->cc = DEFAULT_CC;
    return sim;
}
Ejemplo n.º 4
0
state_ptr new_state(int memlen)
{
    state_ptr result = (state_ptr) malloc(sizeof(state_rec));
    result->pc = 0;
    result->r = init_reg();
    result->m = init_mem(memlen);
    result->cc = DEFAULT_CC;
    return result;
}
Ejemplo n.º 5
0
void main(void) {
    init_reg();
    unsigned int row, column;
    init_keyboard();
    while(1) {
        selectseg();
        writedec();
    }
}
Ejemplo n.º 6
0
void main(void){
    init_reg();
    
 	while(1) {
	toggle_shcp();
	write();
	toggle_stcp();
    }
}
Ejemplo n.º 7
0
void sim_init()
{

    /* Create memory and register files */
    initialized = 1;
    mem = init_mem(MEM_SIZE);
    reg = init_reg();
    sim_reset();
    clear_mem(mem);
}
Ejemplo n.º 8
0
static int		init_values_champions(t_champions *champions)
{
  while (champions)
  {
    if ((champions->reg = (int*)malloc(sizeof(int) * (REG_NUMBER + 1)))
	== NULL)
      return (my_putstr(ALLOC_FAILED, 2));
    init_reg(champions->reg, champions->prog_number);
    champions->pc = champions->load_address;
    champions->carry = 0;
    champions->last_live = 0;
    champions->cycle_to_wait = 0;
    champions = champions->next;
  }
  return (0);
}
Ejemplo n.º 9
0
void init_final_code() {
    int i;

    init_reg();

    final_tree_empty = MAX_NUM_OF_MODULES;

    for(i=0;i<MAX_NUM_OF_MODULES;i++)
        final_tree[i] = NULL;

#if (USE_PSEUDO_INSTR_LA==1)
    for (i=0; i<MAX_ALIVE_ADDR; i++)
        alive_base_addr[i] = NULL;
#endif

    final_tree_current = NULL;
}
Ejemplo n.º 10
0
void mainloop(void)
{
	char ch;

	init_reg();
	/* Involve all init routines.  */
	do_Init_call();

	while (!should_stop) {
		//TODO: handler interrupts

		/* use a register emulator to emulate one instruction */
		dispatch();

		/* Temporary for pause. */
		scanf("%c", &ch);
	}
}
Ejemplo n.º 11
0
int main(int argc,char** argv) {

    if (argc != 3) {
        fprintf(stderr,"usage: RE216_CLIENT hostname port\n");
        return 1;
    }
    
	// -----------------------------------------------------------------
	// ------------------------ Variables ------------------------------
	
	// Buffer
	char *input = NULL;		// Taille d'entrée dynamique
	char output[TAILLE_MSG];// Taille de réception fixée
    
	// Liste chaînée pour l'envoi de fichiers
	struct file fichiers;
		memset(&fichiers, 0, sizeof(struct file));

	// Récupération de la structure sockaddr_in6 pour l'adresse du serveur
	struct sockaddr_in6* server_add = get_addr_info(atoi(argv[2]), argv[1]);

	// Création de la socket
	int sckt = do_socket();  

	// Connexion de la socket à l'adresse server_add
	int conn = do_connect(sckt, *server_add);

	// Initialisation des tableaux pour utliser select ------------------
    
    fd_set fd_set_read; // Ici seront stockés les descripteurs de fichier
    
    int i, select_ret_val;
    
    // Socket du serveur quand elle existe
    int socket_fichier = -1;
    
    // Eventuellement : timeout du select
	//~ struct timeval tv;
	//~ tv.tv_sec = 5;
	//~ tv.tv_usec = 0;
	
	init_reg();
	// -----------------------------------------------------------------
	// -----------------------------------------------------------------
	
	start_line();

	// Boucle jusqu'à recevoir le "/quit" final
	do {
		
		// ------------------------ R.A.Z ------------------------------
		// clean the set before adding file descriptors
		FD_ZERO(&fd_set_read);
		
		// add the fd for server connection
		FD_SET(sckt, &fd_set_read);

		// add the fd for user-input
		FD_SET(fileno(stdin), &fd_set_read);
		// -------------------------------------------------------------
		 
		// we now wait for any file descriptor to be available for reading
        select_ret_val = select(sckt + 1, &fd_set_read, NULL, NULL, NULL);//&tv);
        
        if (select_ret_val == -1) {
			error("Erreur concernant le select ");
		}
        
        //printf("Le retour de la fonction select est : %i", select_ret_val);
		
		for (i = 0; i < (sckt+1) && select_ret_val > 0; i++) {
	
            // Le buffer est nettoyé avec memset directement dans les fonctions
            
            //printf("Bonjour je suis le i n°%i. Retour => %i\n", i, select_ret_val);

            // Si le file descripteur i est dans le set mis en écoute, c'est qu'il y a une activité
            if (FD_ISSET(i, &fd_set_read)) {
				
				// printf("Descripteur trouvé : %i\n", i);

                if (i == fileno(stdin)) // C'est une entrée utilisateur
					client_write(&input, sckt, &fichiers);
				
				else // Les données viennent du serveur
					if (!client_read(sckt, output, &fichiers, &socket_fichier))
						break;

                // Select_ret_val est le nombre de descripteurs où il y 
                // a eu une activité, on diminue donc sa valeur au fur
                // et à mesure.
                select_ret_val--;

            }
        }

	} while(notquit(input) && notquit(output));

	//printf("Extinction.\n");

	free(input);
	
	free_file(&fichiers);

	free_reg();

	// Fermeture de la socket
    close_socket(sckt);
    
	printf("Fin du tchat\n");
	
    return 0;
}
Ejemplo n.º 12
0
/*
 * interface, not static 
 */
void init_filter_tree(int argc) {
  char * exp;
  int exp_num = 0;
  
  init_op_stack(argc);


  filter_list_size = argc;
  filter_list_len = 0;
  filter_list = (Filter **)(malloc(sizeof(Filter) * argc));

  while((exp = get_exp()) != NULL) {
    exp_num++;
    char * optarg;
    //all the exps
    if (IS_EQUAL(exp, "-name")) {
      optarg = _get_arg("-name");
      init_fnmatch(optarg, true);
    } else if (IS_EQUAL(exp, "-iname")) {
      optarg = _get_arg("-iname");
      init_fnmatch(optarg, false);
    } else if (IS_EQUAL(exp, "-user")) {
      optarg = _get_arg("-user");
      init_user(optarg);
    } else if (IS_EQUAL(exp, "-group")) {
      optarg = _get_arg("-group");
      init_group(optarg);
    } else if (IS_EQUAL(exp, "-perm")) {
      optarg = _get_arg("-perm");
      init_perm(optarg);
    } else if (IS_EQUAL(exp, "-regex")) {
      optarg = _get_arg("-regex");
      init_reg(optarg);
    } else if (IS_EQUAL(exp, "-amin")) {
      optarg = _get_arg("-amin");
      init_time(AMIN, optarg);
    } else if (IS_EQUAL(exp, "-atime")) {
      optarg = _get_arg("-atime");
      init_time(ATIME, optarg);
    } else if (IS_EQUAL(exp, "-anewer")) {
      optarg = _get_arg("-anewer");
      init_time(ANEWER, optarg);
    } else if (IS_EQUAL(exp, "-cnewer")) {
      optarg = _get_arg("-cnewer");
      init_time(CNEWER, optarg);
    } else if (IS_EQUAL(exp, "-cmin")) {
      optarg = _get_arg("-cmin");
      init_time(CMIN, optarg);
    } else if (IS_EQUAL(exp, "-ctime")) {
      optarg = _get_arg("-ctime");
      init_time(CTIME, optarg);
    } else if (IS_EQUAL(exp, "-mtime")) {
      optarg = _get_arg("-mtime");
      init_time(MMIN, optarg);
    } else if (IS_EQUAL(exp, "-mnewer")) {
      optarg = _get_arg("-mnewer");
      init_time(MNEWER, optarg);
    } else if (IS_EQUAL(exp, "-type")) {
      optarg = _get_arg("-type");
      init_filetype(optarg);
    } else if (IS_EQUAL(exp, "-size")) {
      optarg = _get_arg("-size");
      init_filesize(optarg);
    } else if (IS_EQUAL(exp, "-not")) {
#ifdef DEBUG
      fprintf(stderr, "filter not adapter\n");
#endif
      filter_not();
    } else if (IS_EQUAL(exp, "-and")) {
#ifdef DEBUG
      fprintf(stderr, "filter and\n");
#endif
      filter_and();
    } else if (IS_EQUAL(exp, "-or")) {
#ifdef DEBUG
      fprintf(stderr, "filter or\n");
#endif
      filter_or();
    } else {
      //TODO
    }
  }
  if (exp_num == 0) {
    init_true(); 
  }
  filter_tree.passed = op_stack[0];
  free_op_stack();
}
Ejemplo n.º 13
0
/* FIXME: check every exception case (goto) */
static int __devinit mfc_probe(struct platform_device *pdev)
{
	struct resource *res;
	int ret;

	mfcdev = kzalloc(sizeof(struct mfc_dev), GFP_KERNEL);
	if (unlikely(mfcdev == NULL)) {
		dev_err(&pdev->dev, "failed to allocate control memory\n");
		return -ENOMEM;
	}

	/* init. control structure */
	sprintf(mfcdev->name, "%s", MFC_DEV_NAME);

	mutex_init(&mfcdev->lock);
	init_waitqueue_head(&mfcdev->wait_sys);
	init_waitqueue_head(&mfcdev->wait_codec[0]);
	init_waitqueue_head(&mfcdev->wait_codec[1]);
	atomic_set(&mfcdev->inst_cnt, 0);
#ifdef CONFIG_CPU_FREQ
	atomic_set(&mfcdev->busfreq_lock_cnt, 0);
	atomic_set(&mfcdev->cpufreq_lock_cnt, 0);
#endif

	mfcdev->device = &pdev->dev;

	platform_set_drvdata(pdev, mfcdev);

	/* get the memory region */
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (unlikely(res == NULL)) {
		dev_err(&pdev->dev, "no memory resource specified\n");
		ret = -ENOENT;
		goto err_mem_res;
	}

	mfcdev->reg.rsrc_start = res->start;
	mfcdev->reg.rsrc_len = resource_size(res);

	/* request mem region for MFC register (0x0000 ~ 0xE008) */
	res = request_mem_region(mfcdev->reg.rsrc_start,
			mfcdev->reg.rsrc_len, pdev->name);
	if (unlikely(res == NULL)) {
		dev_err(&pdev->dev, "failed to get memory region\n");
		ret = -ENOENT;
		goto err_mem_req;
	}

	/* ioremap for MFC register */
	mfcdev->reg.base = ioremap(mfcdev->reg.rsrc_start, mfcdev->reg.rsrc_len);

	if (unlikely(!mfcdev->reg.base)) {
		dev_err(&pdev->dev, "failed to ioremap memory region\n");
		ret = -EINVAL;
		goto err_mem_map;
	}

	init_reg(mfcdev->reg.base);

	mfcdev->irq = platform_get_irq(pdev, 0);
	if (unlikely(mfcdev->irq < 0)) {
		dev_err(&pdev->dev, "no irq resource specified\n");
		ret = -ENOENT;
		goto err_irq_res;
	}

	ret = request_irq(mfcdev->irq, mfc_irq, IRQF_DISABLED, mfcdev->name, mfcdev);
	if (ret) {
		dev_err(&pdev->dev, "failed to allocate irq (%d)\n", ret);
		goto err_irq_req;
	}

	/*
	 * initialize PM(power, clock) interface
	 */
	ret = mfc_init_pm(mfcdev);
	if (ret < 0) {
		printk(KERN_ERR "failed to init. MFC PM interface\n");
		goto err_pm_if;
	}

	/*
	 * initialize memory manager
	 */
	ret = mfc_init_mem_mgr(mfcdev);
	if (ret < 0) {
		printk(KERN_ERR "failed to init. MFC memory manager\n");
		goto err_mem_mgr;
	}

	/*
	 * loading firmware
	 */
	mfcdev->fw.requesting = 1;
	ret = request_firmware_nowait(THIS_MODULE,
				      FW_ACTION_HOTPLUG,
				      MFC_FW_NAME,
				      &pdev->dev,
				      GFP_KERNEL,
				      pdev,
				      mfc_firmware_request_complete_handler);
	if (ret) {
		mfcdev->fw.requesting = 0;
		dev_err(&pdev->dev, "could not load firmware (err=%d)\n", ret);
		goto err_fw_req;
	}

#if defined(SYSMMU_MFC_ON) && defined(CONFIG_VIDEO_MFC_VCM_UMP)
	ret = vcm_activate(mfcdev->vcm_info.sysmmu_vcm);
	if (ret < 0) {
		mfc_err("failed to activate VCM: %d", ret);

		goto err_act_vcm;
	}
#endif

	/*
	 * initialize buffer manager
	 */
	mfc_init_buf();

	/* FIXME: final dec & enc */
	mfc_init_decoders();
	mfc_init_encoders();

	ret = misc_register(&mfc_miscdev);

	if (ret) {
		mfc_err("MFC can't misc register on minor=%d\n", MFC_MINOR);
		goto err_misc_reg;
	}

	mfc_info("MFC(Multi Function Codec - FIMV v5.x) registered successfully\n");

	return 0;

err_misc_reg:
	mfc_final_buf();

#ifdef SYSMMU_MFC_ON
#ifdef CONFIG_VIDEO_MFC_VCM_UMP
	mfc_clock_on();

	vcm_deactivate(mfcdev->vcm_info.sysmmu_vcm);

	mfc_clock_off();

err_act_vcm:
#endif
	mfc_clock_on();

	sysmmu_off(SYSMMU_MFC_L);
	sysmmu_off(SYSMMU_MFC_R);

	mfc_clock_off();
#endif
	if (mfcdev->fw.info)
		release_firmware(mfcdev->fw.info);

err_fw_req:
	/* FIXME: make kenel dump when probe fail */
	mfc_clock_on();

	mfc_final_mem_mgr(mfcdev);

	mfc_clock_off();

err_mem_mgr:
	mfc_final_pm(mfcdev);

err_pm_if:
	free_irq(mfcdev->irq, mfcdev);

err_irq_req:
err_irq_res:
	iounmap(mfcdev->reg.base);

err_mem_map:
	release_mem_region(mfcdev->reg.rsrc_start, mfcdev->reg.rsrc_len);

err_mem_req:
err_mem_res:
	platform_set_drvdata(pdev, NULL);
	mutex_destroy(&mfcdev->lock);
	kfree(mfcdev);

	return ret;
}
Ejemplo n.º 14
0
/*
 * ServiceMain()
 *
 * Main routine for HIP service. Runs init_hip()
 */
void WINAPI ServiceMain (DWORD ac, char **av)
{
  char path[MAX_PATH];
  g_srv_status_handle = RegisterServiceCtrlHandler(SERVICE_NAME, Handler);
  if (!g_srv_status_handle)
    {
      return;
    }

  g_srv_status.dwCurrentState = SERVICE_START_PENDING;
  g_srv_status.dwCheckPoint = 0;
  g_srv_status.dwWaitHint = 1000;
  SetServiceStatus (g_srv_status_handle, &g_srv_status);

  /* initialization process */
  if (!GetModuleFileName (0, path, MAX_PATH))
    {
      return;
    }

  strip_filename(path);
  _chdir(path);

  if (freopen("hip_ipsec_error.log", "a", stderr) == NULL)
    {
      return;
    }
  if (freopen("hip_ipsec.log", "a", stdout) == NULL)
    {
      return;
    }
  init_reg();
  init_hip(ac, av);

  /* notify that the service has been started */
  g_srv_status.dwCurrentState = SERVICE_RUNNING;
  g_srv_status.dwCheckPoint = 0;
  g_srv_status.dwWaitHint = 0;
  SetServiceStatus(g_srv_status_handle, &g_srv_status);

  while (g_srv_status.dwCurrentState != SERVICE_STOPPED)
    {
      switch (g_srv_status.dwCurrentState)
        {
        case SERVICE_STOP_PENDING:
          g_srv_status.dwCurrentState = SERVICE_STOPPED;
          SetServiceStatus(g_srv_status_handle, &g_srv_status);
          g_state = 1;
          break;
        default:
          Sleep(1000);
          /* TODO: any HIP status updating here */
          /*ret = hip_check_status();
           *  if (ret >= 0 && ret != status) {
           *       status = ret;
           *       update_status(status);
           *  }*/
          break;
        }
    }

  WSACleanup();
  hip_sadb_deinit();
}
Ejemplo n.º 15
0
int segment(struct SigSet *S,	/* class parameters */
	    struct parms *parms, struct files *files)
{
    int block_size;		/* size of subregion blocks */
    int ml;			/* max likelihood? */
    
    DCELL ***img;		/* multispectral image, img[band][i][j] */
    int last_row;               
    int wd, ht;			/* image width and height */
    struct Region region;	/* specifies image subregion */
    int nbands;			/* number of bands */
    int nclasses;		/* number of classes */
    LIKELIHOOD ****ll_pym;	/* pyramid of log likelihoods */
    unsigned char ***sf_pym;	/* pyramid of segmentations */
    int D;			/* number of levels in pyramid */
    double *alpha_dec;		/* class transition probabilities */
    int i;

    ml = parms->ml;		/* use maxl? */
    block_size = parms->blocksize;

    wd = Rast_window_cols();	/* get width from GRASS */
    ht = Rast_window_rows();	/* get height from GRASS */

    /* make blocksize a power of 2 */
    if (block_size < 8)
	block_size = 8;
    for (i = 0; (block_size >> i) > 1; i++) {
    }
    block_size = 1 << i;

/**** this code may stay the same ******/
    nbands = S->nbands;
    nclasses = S->nclasses;

    /* Check for too many classes */
    if (nclasses > 256)
	G_fatal_error(_("Number of classes must be < 256"));

    /* allocate alpha_dec parameters */
    D = levels(block_size, block_size);
    alpha_dec = (double *)G_malloc(D * sizeof(double));

    /* allocate image block */
    img =
	(DCELL ***) multialloc(sizeof(DCELL), 3, nbands, block_size,
			       block_size);

    /* allocate memory for log likelihood pyramid */
    ll_pym =
	(LIKELIHOOD ****) get_cubic_pyramid(block_size, block_size, nclasses,
					    sizeof(LIKELIHOOD));

    /* allocate memory for segmentation pyramid */
    sf_pym = (unsigned char ***)get_pyramid(wd, ht, sizeof(char));

    /* tiled segmentation */
    init_reg(&region, wd, ht, block_size);
    extract_init(S);
    last_row = -1;
    do {
	if (last_row != region.ymin)
	    G_message(_("Processing rows %d-%d (of %d)..."),
		      region.ymin + 1, region.ymax, ht);
	last_row = region.ymin;
	shift_img(img, nbands, &region, block_size);
	/* this reads grass images into the block defined in region */
	read_block(img, &region, files);

	shift_ll(ll_pym, &region, block_size);
	extract(img, &region, ll_pym[0], S);

	if (ml)
	    MLE(sf_pym[0], ll_pym[0], &region, nclasses);
	else {
	    for (i = 0; i < D; i++)
		alpha_dec[i] = 1.0;
	    seq_MAP(sf_pym, &region, ll_pym, nclasses, alpha_dec);
	}


    } while (increment_reg(&region, wd, ht, block_size));

    write_img(sf_pym[0], wd, ht, S, parms, files);

    return 0;
}