Exemple #1
0
/*-----------------------------------------------------------------*/
bitVect *
newBitVect (int size)
{
  bitVect *bvp;
  int byteSize;

  bvp = Safe_calloc (1, sizeof (bitVect));

  bvp->size = size;
  bvp->bSize = byteSize = (size / 8) + 1;
  bvp->vect = Safe_calloc (1, byteSize);
  return bvp;
}
Exemple #2
0
char *
aopLiteralLong (value * val, int offset, int size)
{
	char *rs;
	union {
		float f;
		unsigned char c[4];
	}
	fl;

	if (!val) {
	  // assuming we have been warned before
	  val=constVal("0");
	}

	/* if it is a float then it gets tricky */
	/* otherwise it is fairly simple */
	if (!IS_FLOAT (val->type)) {
		unsigned long v = (unsigned long) floatFromVal (val);

		v >>= (offset * 8);
		switch (size) {
		case 1:
			tsprintf (buffer, "!immedbyte", (unsigned int) v & 0xff);
			break;
		case 2:
			tsprintf (buffer, "!immedword", (unsigned int) v & 0xffff);
			break;
		default:
			/* Hmm.  Too big for now. */
			assert (0);
		}
		rs = Safe_calloc (1, strlen (buffer) + 1);
		return strcpy (rs, buffer);
	}
Exemple #3
0
/* mark some registers as being duplicated across banks */
static void
register_map (int num_words, char **word)
{
    memRange *r;
    int pcount;

    if (num_words < 3)
    {
        fprintf (stderr, "WARNING: not enough values in %s regmap directive\n",
                 DEVICE_FILE_NAME);
        return;
    } // if

    for (pcount = 2; pcount < num_words; pcount++)
    {
        r = Safe_calloc (1, sizeof (memRange));

        r->start_address = parse_config_value (word[pcount]);
        r->end_address = parse_config_value (word[pcount]);
        r->alias = parse_config_value (word[1]);
        r->bank = (r->start_address >> 7) & 3;
        // add memRange to device entry for future lookup (sharebanks)
        r->next = rangeRAM;
        rangeRAM = r;
    } // for
}
Exemple #4
0
/* create a structure for a pic processor */
static PIC_device *
create_pic (char *pic_name, int maxram, int bankmsk, int confsiz,
            int program, int data, int eeprom, int io)
{
    PIC_device *new_pic;
    char *simple_pic_name = sanitise_processor_name (pic_name);

    new_pic = Safe_calloc (1, sizeof (PIC_device));
    new_pic->name = Safe_strdup (simple_pic_name);

    new_pic->defMaxRAMaddrs = maxram;
    new_pic->bankMask = bankmsk;
    new_pic->hasSecondConfigReg = confsiz > 1;

    new_pic->programMemSize = program;
    new_pic->dataMemSize = data;
    new_pic->eepromMemSize = eeprom;
    new_pic->ioPins = io;

    new_pic->ram = rangeRAM;

    Pics[num_of_supported_PICS] = new_pic;
    num_of_supported_PICS++;

    return new_pic;
}
Exemple #5
0
/* create a structure for a pic processor */
static PIC_device *
create_pic (char *pic_name, int maxram, int bankmsk, int confsiz,
            int config[MAX_NUM_CONFIGS], int program, int data, int eeprom,
            int io, int is_enhanced)
{
  PIC_device *new_pic;
  char *simple_pic_name = sanitise_processor_name (pic_name);

  new_pic = Safe_calloc (1, sizeof (PIC_device));
  new_pic->name = Safe_strdup (simple_pic_name);

  new_pic->defMaxRAMaddrs = maxram;
  new_pic->bankMask = bankmsk;
  new_pic->num_configs = confsiz;
  memcpy(new_pic->config, config, MAX_NUM_CONFIGS * sizeof(int));

  new_pic->programMemSize = program;
  new_pic->dataMemSize = data;
  new_pic->eepromMemSize = eeprom;
  new_pic->ioPins = io;
  new_pic->isEnhancedCore = is_enhanced;

  new_pic->ram = rangeRAM;

  Pics[num_of_supported_PICS] = new_pic;
  num_of_supported_PICS++;

  return new_pic;
}
Exemple #6
0
/*-----------------------------------------------------------------*/
int setBreakPoint (unsigned addr, char addrType, char bpType,
        int (*callBack)(unsigned,breakp *,context *) ,
        char *fileName, int lineno)
{
    breakp *bp, *bpl;

    Dprintf(D_break, ("setBreakPoint: addr:%x atype:%s bpType:%s [%s:%d]\n",
        addr,
        debug_bp_type_strings[(int)addrType],
        debug_bp_type_strings[(int)bpType],
        fileName, lineno+1));

    /* allocate & init a new bp */
    bp = Safe_calloc(1,sizeof(breakp));
    bp->addr = addr;
    bp->addrType = addrType;
    bp->bpType = bpType;
    bp->callBack = callBack;
    bp->bpnum = ((bpType == USER || bpType == TMPUSER)? ++bpnum : 0);
    bp->filename = fileName;
    bp->lineno = lineno;

    /* if this is an user break point then
       check if there already exists one for this address */
    if (bpType == USER || bpType == TMPUSER)
    {
        for ( bpl = hTabFirstItemWK(bptable,addr) ; bpl;
              bpl = hTabNextItemWK(bptable))
        {

            /* if also a user break point then issue Note : */
            if (bpl->bpType == USER || bpType == TMPUSER)
                fprintf(stderr,"Note: breakpoint %d also set at pc 0x%x\n",
                        bpl->bpnum,bpl->addr);
        }

        fprintf(stderr,"Breakpoint %d at 0x%x: file %s, line %d.\n",
                bp->bpnum, addr, fileName, lineno+1);

        userBpPresent++;
    }

    if (bpType != STEP && bpType != NEXT)
    {
        /* if a break point does not already exist then
           send command to simulator to add one */
        if (!hTabSearch(bptable,addr))
            /* send the break command to the simulator */
            simSetBP (addr);
    }

    /* now add the break point to list */
    hTabAddItem(&bptable,addr,bp);

    return bp->bpnum ;
}
Exemple #7
0
/* define ram areas - may be duplicated across banks */
static void
ram_map (int num_words, char **word)
{
    memRange *r;

    if (num_words < 4)
    {
        fprintf (stderr, "WARNING: not enough values in %s memmap directive\n",
                 DEVICE_FILE_NAME);
        return;
    } // if

    r = Safe_calloc (1, sizeof (memRange));
    //fprintf (stderr, "%s: %s %s %s\n", __FUNCTION__, word[1], word[2], word[3]);

    r->start_address = parse_config_value (word[1]);
    r->end_address = parse_config_value (word[2]);
    r->alias = parse_config_value (word[3]);
    r->bank = (r->start_address >> 7) & 3;

    // add memRange to device entry for future lookup (sharebanks)
    r->next = rangeRAM;
    rangeRAM = r;
}
Exemple #8
0
void *Safe_alloc(size_t Size)
{
  return Safe_calloc(1, Size);
}
Exemple #9
0
		}
		rs = Safe_calloc (1, strlen (buffer) + 1);
		return strcpy (rs, buffer);
	}

	/* PENDING: For now size must be 1 */
	assert (size == 1);

	/* it is type float */
	fl.f = (float) floatFromVal (val);
#ifdef _BIG_ENDIAN
	tsprintf (buffer, "!immedbyte", fl.c[3 - offset]);
#else
	tsprintf (buffer, "!immedbyte", fl.c[offset]);
#endif
	rs = Safe_calloc (1, strlen (buffer) + 1);
	return strcpy (rs, buffer);
}

/*-----------------------------------------------------------------*/
/* aopLiteral - string from a literal value                        */
/*-----------------------------------------------------------------*/
char *
aopLiteral (value * val, int offset)
{
	return aopLiteralLong (val, offset, 1);
}

/*-----------------------------------------------------------------*/
/* emitRegularMap - emit code for maps with no special cases       */
/*-----------------------------------------------------------------*/
Exemple #10
0
/* read the file with all the pic14 definitions and pick out the definition
 * for a processor if specified. if pic_name is NULL reads everything */
static PIC_device *
find_device (char *pic_name)
{
    FILE *pic_file;
    char pic_buf[PIC14_STRING_LEN];
    int found_processor = FALSE;
    int done = FALSE;
    char **processor_name;
    int num_processor_names = 0;
    int pic_maxram = 0;
    int pic_bankmsk = 0;
    int pic_confsiz = 0;
    int pic_program = 0;
    int pic_data = 0;
    int pic_eeprom = 0;
    int pic_io = 0;
    char *simple_pic_name;
    char *dir;
    char filename[512];
    int len = 512;
    char **pic_word;
    int num_pic_words;
    int wcount;

    pic_word = Safe_calloc (sizeof (char *), SPLIT_WORDS_MAX);
    processor_name = Safe_calloc (sizeof (char *), SPLIT_WORDS_MAX);

    /* allow abbreviations of the form "f877" - convert to "16f877" */
    simple_pic_name = sanitise_processor_name (pic_name);
    num_of_supported_PICS = 0;

    /* open the piclist file */
    /* first scan all include directories */
    pic_file = NULL;
    //fprintf (stderr, "%s: searching %s\n", __FUNCTION__, DEVICE_FILE_NAME);
    for (dir = setFirstItem (userIncDirsSet);
            !pic_file && dir;
            dir = setNextItem (userIncDirsSet))
    {
        //fprintf (stderr, "searching1 %s\n", dir);
        SNPRINTF (&filename[0], len, "%s%s", dir,
                  DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
        pic_file = fopen (filename, "rt");
        if (pic_file) break;
    } // for

    for (dir = setFirstItem (includeDirsSet);
            !pic_file && dir;
            dir = setNextItem (includeDirsSet))
    {
        //fprintf (stderr, "searching2 %s\n", dir);
        SNPRINTF (&filename[0], len, "%s%s", dir,
                  DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
        pic_file = fopen (filename, "rt");
        if (pic_file) break;
    } // for

    for (dir = setFirstItem (libDirsSet);
            !pic_file && dir;
            dir = setNextItem (libDirsSet))
    {
        //fprintf (stderr, "searching3 %s\n", dir);
        SNPRINTF (&filename[0], len, "%s%s", dir,
                  DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
        pic_file = fopen (filename, "rt");
        if (pic_file) break;
    } // for

    for (dir = setFirstItem (libPathsSet);
            !pic_file && dir;
            dir = setNextItem (libPathsSet))
    {
        //fprintf (stderr, "searching4 %s\n", dir);
        SNPRINTF (&filename[0], len, "%s%s", dir,
                  DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
        pic_file = fopen (filename, "rt");
        if (pic_file) break;
    } // for

    if (!pic_file)
    {
        SNPRINTF (&filename[0], len, "%s",
                  DATADIR LIB_DIR_SUFFIX
                  DIR_SEPARATOR_STRING "pic"
                  DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
        pic_file = fopen (filename, "rt");
    } // if

    if (pic_file == NULL)
    {
        fprintf (stderr, "can't find %s\n", DEVICE_FILE_NAME);
        return NULL;
    } // if

    if (options.verbose)
        printf ("Using devices from %s.\n", filename);

    /* read line by line */
    pic_buf[sizeof (pic_buf)-1] = '\0';
    while (fgets (pic_buf, sizeof (pic_buf)-1, pic_file) != NULL && !done)
    {
        /* strip comments */
        {
            char *comment = strchr (pic_buf, '#');
            if (comment)
                *comment = 0;
        }

        /* split into fields */
        num_pic_words = split_words (pic_word, pic_buf);

        /* ignore comment / empty lines */
        if (num_pic_words > 0)
        {

            if (STRCASECMP (pic_word[0], "processor") == 0)
            {
                if (pic_name == NULL)
                {
                    int dcount;

                    /* this is the mode where we read all the processors in - store the names for now */
                    if (num_processor_names > 0)
                    {
                        /* store away all the previous processor definitions */
                        for (dcount = 1; dcount < num_processor_names; dcount++)
                        {
                            create_pic (processor_name[dcount], pic_maxram,
                                        pic_bankmsk, pic_confsiz, pic_program,
                                        pic_data, pic_eeprom, pic_io);
                        } // for
                    } // if

                    /* copy processor names */
                    num_processor_names = num_pic_words;
                    for (dcount = 1; dcount < num_processor_names; dcount++)
                    {
                        processor_name[dcount] = pic_word[dcount];
                        pic_word[dcount] = NULL;
                    } // for
                } // if
                else
                {
                    /* if we've just completed reading a processor definition stop now */
                    if (found_processor)
                        done = TRUE;
                    else
                    {
                        /* check if this processor name is a match */
                        for (wcount = 1; wcount < num_pic_words; wcount++)
                        {
                            /* skip uninteresting prefixes */
                            char *found_name = sanitise_processor_name (pic_word[wcount]);

                            if (STRCASECMP (found_name, simple_pic_name) == 0)
                                found_processor = TRUE;
                        } // for
                    } // if
                } // if
            } // if
            else
            {
                if (found_processor || pic_name == NULL)
                {
                    /* only parse a processor section if we've found the one we want */
                    if (STRCASECMP (pic_word[0], "maxram") == 0 && num_pic_words > 1)
                    {
                        pic_maxram = parse_config_value (pic_word[1]);
                        setMaxRAM (pic_maxram);
                    } // if

                    else if (STRCASECMP (pic_word[0], "bankmsk") == 0 && num_pic_words > 1)
                        pic_bankmsk = parse_config_value (pic_word[1]);

                    else if (STRCASECMP (pic_word[0], "confsiz") == 0 && num_pic_words > 1)
                        pic_confsiz = parse_config_value (pic_word[1]);

                    else if (STRCASECMP (pic_word[0], "program") == 0 && num_pic_words > 1)
                        pic_program = parse_config_value (pic_word[1]);

                    else if (STRCASECMP (pic_word[0], "data") == 0 && num_pic_words > 1)
                        pic_data = parse_config_value (pic_word[1]);

                    else if (STRCASECMP (pic_word[0], "eeprom") == 0 && num_pic_words > 1)
                        pic_eeprom = parse_config_value (pic_word[1]);

                    else if (STRCASECMP (pic_word[0], "io") == 0 && num_pic_words > 1)
                        pic_io = parse_config_value (pic_word[1]);

                    else if (STRCASECMP (pic_word[0], "regmap") == 0 && num_pic_words > 2)
                    {
                        if (found_processor)
                            register_map (num_pic_words, pic_word);
                    } // if

                    else if (STRCASECMP (pic_word[0], "memmap") == 0 && num_pic_words > 2)
                    {
                        if (found_processor)
                            ram_map (num_pic_words, pic_word);
                    } // if

                    else
                    {
                        fprintf (stderr, "WARNING: %s: bad syntax `%s'\n",
                                 DEVICE_FILE_NAME, pic_word[0]);
                    } // if
                } // if
            } // if
        } // if
    } // while

    fclose (pic_file);

    split_words (pic_word, NULL);
    free (pic_word);

    /* if we're in read-the-lot mode then create the final processor definition */
    if (pic_name == NULL)
    {
        if (num_processor_names > 0)
        {
            /* store away all the previous processor definitions */
            int dcount;

            for (dcount = 1; dcount < num_processor_names; dcount++)
            {
                create_pic (processor_name[dcount], pic_maxram, pic_bankmsk,
                            pic_confsiz, pic_program, pic_data, pic_eeprom,
                            pic_io);
            } // for
        } // if
    } // if
    else
    {
        /* in search mode */
        if (found_processor)
        {
            split_words (processor_name, NULL);
            free (processor_name);

            /* create a new pic entry */
            return create_pic (pic_name, pic_maxram, pic_bankmsk,
                               pic_confsiz, pic_program, pic_data,
                               pic_eeprom, pic_io);
        } // if
    } // if

    split_words (processor_name, NULL);
    free (processor_name);

    return NULL;
}
void readModel(struct Fixed_Length_ICM_t *fixed, const char *path) 
  {
   FILE  * fp;
   char  line [ID_STRING_LEN];
   int  param [NUM_FIXED_LENGTH_PARAMS];
   int  i;

   if ((fp = fopen (path, "r"))==NULL) {
      fprintf(stderr, "Error: Could not open Glimmer model file for reading (%s).\n", path); 
      exit(1);
   }

   fread (line, sizeof (char), ID_STRING_LEN, fp); // skip the text header line

   if  (fread (param, sizeof (int), NUM_FIXED_LENGTH_PARAMS, fp)
          != NUM_FIXED_LENGTH_PARAMS)
       {
        fprintf (stderr, "ERROR reading file \"%s\"\n", path);
        exit (-1);
       }

   if  (ICM_VERSION_ID != param [0])
       {
        fprintf (stderr, "Bad ICM version = %d  should be %d\n",
                 param [0], ICM_VERSION_ID);
        exit (-1);
       }
   if  (ID_STRING_LEN != param [1])
       {
        fprintf (stderr, "Bad ID_STRING_LEN = %d  should be %d\n",
                 param [1], ID_STRING_LEN);
        exit (-1);
       }
   (*fixed).length = param [2];
   (*fixed).max_depth = param [3];
   (*fixed).special_position = param [4];
   (*fixed).model_type = param [5];

   (*fixed).permutation = (int *) Safe_malloc((*fixed).length*sizeof(int), __FILE__,__LINE__);

   for(i=0;i<(*fixed).length;i++) {
     (*fixed).permutation[i] = 0;
   }
   fread ((*fixed).permutation, sizeof (int), (*fixed).length, fp);

   (*fixed).sub_model = (struct ICM_t *) Safe_malloc
             ((*fixed).length * sizeof (struct ICM_t ), __FILE__, __LINE__);

   for  (i = 0;  i < (*fixed).length;  i ++) 
   {
      (*fixed).sub_model[i].score = (struct ICM_Score_Node_t * *)
          Safe_calloc (1, sizeof (struct ICM_Score_Node_t *), __FILE__, __LINE__);
//      for  (j = 0;  j < 1;  j ++) {
//        (*fixed).sub_model[i].score[j] = (struct ICM_Score_Node_t *)
//                   Safe_calloc (12, sizeof (struct ICM_Score_Node_t),
//                   __FILE__, __LINE__);
//        for(k=0;k<4;k++) {
//          (*fixed).sub_model[i].score[j][k].prob = (float *)
//             Safe_calloc (4, sizeof(float), __FILE__, __LINE__);
//        }
//      } 
//
   }

   for  (i = 0;  i < (*fixed).length;  i ++)
   {
      Input(&((*fixed).sub_model[i]), fp,1,0,1);
   }
}
void  Input(struct ICM_t *p, FILE *fp, int model_len,int model_depth, int periodicity)
{
 char  line [ID_STRING_LEN];
 int  param [NUM_FIXED_LENGTH_PARAMS];
 int  node_id;
 int  prev_node;
 int  period;
 int  i,j;
 (*p).model_len = model_len;
 (*p).model_depth = model_depth;
 (*p).periodicity = periodicity;

 (*p).empty = 1;

 // skip the text header line
 if  (fread (line, sizeof (char), ID_STRING_LEN, fp) != (unsigned) (ID_STRING_LEN))
 {
   fprintf (stderr, "ERROR reading ICM header\n");
   exit (-1);
 }

 if  (fread (param, sizeof (int), NUM_FIXED_LENGTH_PARAMS, fp) != NUM_FIXED_LENGTH_PARAMS)
 {
    fprintf (stderr, "ERROR reading parameters\n");
    exit (-1);
 }

 if  (ICM_VERSION_ID != param [0])
 {
   fprintf (stderr, "Bad ICM version = %d  should be %d\n", param [0], ICM_VERSION_ID);
   exit (-1);
 }
 if  (ID_STRING_LEN != param [1])
 {
    fprintf (stderr, "Bad ID_STRING_LEN = %d  should be %d\n",
             param [1], ID_STRING_LEN);
    exit (-1);
 }

 (*p).model_len   = param [2];
 (*p).model_depth = param [3];
 (*p).periodicity = param [4];
 (*p).num_nodes   = param [5];


 (*p).score = (struct ICM_Score_Node_t **) Safe_malloc
             ((*p).periodicity * sizeof (struct ICM_Score_Node_t *), __FILE__, __LINE__);
 for  (i = 0;  i < (*p).periodicity;  i ++) {
   (*p).score [i] = (struct ICM_Score_Node_t *) Safe_calloc
                 ((*p).num_nodes, sizeof (struct ICM_Score_Node_t), __FILE__, __LINE__);
   for(j=0;j<(*p).num_nodes;j++) {
     (*p).score[i][j].prob = (float *) Safe_malloc(ALPHABETSIZE*sizeof(float), __FILE__, __LINE__);
   }
 }


 period = -1;
 prev_node = 0;
 while  (fread (& node_id, sizeof (int), 1, fp) != 0)
 {
   if  (node_id < 0) break;
   if  (node_id == 0)  period++;

   // read in the probabilities
   if  (fread ((*p).score [period] [node_id] . prob, sizeof (float), ALPHABETSIZE, fp) != 
             (unsigned) (ALPHABETSIZE))
   {
      fprintf (stderr, "ERROR reading icm node = %d  period = %d\n", node_id, period);
      exit (-1);
   }


   // read in the max mutual information position
   if  (fread (& ((*p).score [period] [node_id] . mut_info_pos), sizeof (short int), 1, fp) != 1)
   {
      fprintf (stderr, "ERROR reading mut_info_pos for node = %d  period = %d\n", node_id, period);
      exit (-1);
   }

   // check for cut nodes
   if  (node_id != 0 && prev_node != node_id - 1)
      for  (i = prev_node + 1;  i < node_id;  i ++)
         (*p).score [period] [i] . mut_info_pos = -2;

   if  (node_id == 0 && period > 0)
      for  (i = prev_node + 1;  i < (*p).num_nodes;  i ++)
         (*p).score [period - 1] [i] . mut_info_pos = -2;

   prev_node = node_id;
 }

 if  (period != periodicity - 1)
 {
   fprintf (stderr, "ERROR:  Too few nodes for periodicity = %d\n", periodicity);
   exit (-1);
 }

 // check for cut nodes in last period
 if  (prev_node != (*p).num_nodes - 1)
     for  (i = prev_node + 1;  i < (*p).num_nodes;  i ++)
        (*p).score [period] [i] . mut_info_pos = -2;

 (*p).empty = 0;
}