-#if 0
- int start=-1;
- int bank_base;
- static int udata_flag=0;
-#endif
- int addr=0;
-
- //dump_map(); /* display the register map */
- //fprintf(stdout,";dump_sfr \n");
- if (maxRAMaddress < 0) {
- fprintf(stderr, "missing maxram setting in %s\n", DEVICE_FILE_NAME);
- return;
- }
-
- for (addr = 0; addr <= maxRAMaddress; addr++)
- {
- regs *reg = finalMapping[addr].reg;
-
- if (reg && !reg->isEmitted)
- {
- if (pic14_options.isLibrarySource && pic14_is_shared (reg))
- {
- /* rely on external declarations for the non-fixed stack */
- /* Update: We always emit the STACK symbols into a
- * udata_shr section, so no extern declaration is
- * required. */
- //fprintf (of, "\textern\t%s\n", reg->name);
- } else {
- emitSymbolToFile (of, reg->name, "udata", reg->size, reg->isFixed ? reg->address : -1, 0, pic14_is_shared (reg));
- }
-
- reg->isEmitted = 1;
- }
- } // for
-
-#if 0
- do {
-
- if(finalMapping[addr].reg && !finalMapping[addr].reg->isEmitted) {
-
- if(start<0)
- start = addr;
- } else {
- if(start>=0) {
-
- /* clear the lower 7-bits of the start address of the first
- * variable declared in this bank. The upper bits for the mid
- * range pics are the bank select bits.
- */
-
- bank_base = start & 0xfff8;
-
- /* The bank number printed in the cblock comment tacitly
- * assumes that the first register in the contiguous group
- * of registers represents the bank for the whole group */
-
- if ( (start != addr) && (!udata_flag) ) {
- udata_flag = 1;
- //fprintf(of,"\tudata\n");
- }
-
- for( ; start < addr; start++) {
- if((finalMapping[start].reg) &&
- (!finalMapping[start].reg->isEmitted) &&
- (!finalMapping[start].instance) &&
- (!finalMapping[start].isSFR)) {
-
- if (finalMapping[start].reg->isFixed) {
- unsigned i;
- for (i=0; i<finalMapping[start].reg->size; i++) {
- fprintf(of,"%s\tEQU\t0x%04x\n",
- finalMapping[start].reg->name,
- finalMapping[start].reg->address+i);
- }
- } else {
- emitSymbolToFile (of, finalMapping[start].reg->name, finalMapping[start].reg->size);
-#if 0
- fprintf(of,"%s\tres\t%i\n",
- finalMapping[start].reg->name,
- finalMapping[start].reg->size);
-#endif
- }
- finalMapping[start].reg->isEmitted = 1;
- }
- }
-
- start = -1;
- }
-
- }
-
- addr++;
-
- } while(addr <= maxRAMaddress);
-
-
-#endif
+ 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;