under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-------------------------------------------------------------------------*/
-
-/*
- VR - Began writing code to make PIC16 C source files independent from
- the header file (created by the inc2h.pl)
-
- - adding maximum RAM memory into PIC_Device structure
-
-*/
-
#include <stdio.h>
#include "common.h" // Include everything in the SDCC src directory
#include "newalloc.h"
+#include "dbuf_string.h"
-
+#include "main.h"
#include "pcode.h"
#include "ralloc.h"
#include "device.h"
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
-static PIC_device Pics[] = {
- {
- {"p18f242", "18f242", "pic18f242", "f242"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x300, // bank mask
- 0x300, // RAMsize
- 0
+void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p);
+extern void pic16_pCodeConstString (char *name, char *value, unsigned length);
+
+stats_t statistics = { 0, 0, 0, 0 };
+
+#define DEVICE_FILE_NAME "pic16devices.txt"
+
+static PIC16_device default_device = {
+ { "p18f452", "18f452", "pic18f452", "f452" },
+ 0x600,
+ 0x80,
+ { /* configuration words */
+ 0x300001, 0x30000d,
+ { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ ,
+ { 0x0f, 0, 0xff } /* 3 */ , { -1 , 0, 0xff } /* 4 */ ,
+ { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
+ { -1 , 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ ,
+ { 0xc0, 0, 0xff } /* 9 */ , { 0x0f, 0, 0xff } /* a */ ,
+ { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
+ { 0x40, 0, 0xff } /* d */ }
},
-
- {
- {"p18f252", "18f252", "pic18f252", "f252"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x600, // bank mask
- 0x600, // RAMsize
- 0
- },
-
- {
- {"p18f442", "18f442", "pic18f442", "f442"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x300, // bank mask
- 0x300, // RAMsize
- 0
+ { /* ID locations */
+ 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
},
+ NULL
+};
- {
- {"p18f452", "18f452", "pic18f452", "f452"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x600, // bank mask
- 0x600, // RAMsize
- 0
- },
+PIC16_device *pic16 = &default_device;
+static PIC16_device *devices = NULL;
- {
- {"p18f248", "18f248", "pic18f248", "f248"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x300, // bank mask
- 0x300, // RAMsize
- 0
- },
+extern set *includeDirsSet;
+extern set *userIncDirsSet;
- {
- {"p18f258", "18f258", "pic18f258", "f258"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x600, // bank mask
- 0x600, // RAMsize
- 0
- },
+extern char *iComments2;
- {
- {"p18f448", "18f448", "pic18f448", "f448"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x300, // bank mask
- 0x300, // RAMsize
- 0
- },
+void
+pic16_dump_equates (FILE *of, set *equs)
+{
+ regs *r;
- {
- {"p18f458", "18f458", "pic18f458", "f458"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x600, // bank mask
- 0x600, // RAMsize
- 0
- },
+ r = setFirstItem (equs);
+ if (!r)
+ return;
- {
- {"p18f6520", "18f6520", "pic18f6520", "f6520"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x800, // bank mask
- 0x800, // RAMsize
- 1
- },
+ fprintf (of, "%s", iComments2);
+ fprintf (of, ";\tEquates to used internal registers\n");
+ fprintf (of, "%s", iComments2);
- {
- {"p18f6620", "18f6620", "pic18f6620", "f6620"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0xf00, // bank mask
- 0xf00, // RAMsize
- 1
- },
- {
- {"p18f6680", "18f6680", "pic18f6680", "f6680"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0xc00, // bank mask
- 0xc00, // RAMsize
- 1
- },
- {
- {"p18f6720", "18f6720", "pic18f6720", "f6720"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0xf00, // bank mask
- 0xf00, // RAMsize
- 1
- },
- {
- {"p18f8520", "18f8520", "pic18f8520", "f8520"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0x800, // bank mask
- 0x800, // RAMsize
- 1
- },
- {
- {"p18f8620", "18f8620", "pic18f8620", "f8620"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0xf00, // bank mask
- 0xf00, // RAMsize
- 1
- },
- {
- {"p18f8680", "18f8680", "pic18f8680", "f8680"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0xc00, // bank mask
- 0x800, // RAMsize
- 1
- },
- {
- {"p18f8720", "18f8720", "pic18f8720", "f8720"}, // aliases
- (memRange *)NULL, // ram memory map
- (memRange *)NULL, // sfr memory map
- 0,
- 0xf00, // bank mask
- 0xf00, // RAMsize
- 1
- },
+ for (; r; r = setNextItem (equs))
+ {
+ fprintf (of, "%s\tequ\t0x%02x\n", r->name, r->address);
+ } // for
+}
-};
-static int num_of_supported_PICS = sizeof(Pics)/sizeof(PIC_device);
+void
+pic16_dump_access (FILE *of, set *section)
+{
+ regs *r;
-#define DEFAULT_PIC "452"
+ r = setFirstItem (section);
+ if (!r)
+ return;
-static PIC_device *pic=NULL;
+ fprintf (of, "%s", iComments2);
+ fprintf (of, ";\tAccess bank symbols\n");
+ fprintf (of, "%s", iComments2);
-//AssignedMemory *pic16_finalMapping=NULL;
-//int pic16_finalMappingSize=0;
+ fprintf (of, "\tudata_acs\n");
+ for (; r; r = setNextItem (section))
+ {
+ fprintf (of, "%s\tres\t%d\n", r->name, r->size);
+ statistics.adsize += r->size;
+ } // for
+}
-#define DEFAULT_CONFIG_BYTE 0xff
+int
+regCompare (const void *a, const void *b)
+{
+ const regs *const *i = a;
+ const regs *const *j = b;
-#define CONFIG1H_WORD_ADDRESS 0x300001
-#define DEFAULT_CONFIG1H_WORD DEFAULT_CONFIG_BYTE
+ /* Sort primarily by the address ... */
+ if ((*i)->address > (*j)->address)
+ return (1);
-#define CONFIG2L_WORD_ADDRESS 0x300002
-#define DEFAULT_CONFIG2L_WORD DEFAULT_CONFIG_BYTE
+ if ((*i)->address < (*j)->address)
+ return (-1);
-#define CONFIG2H_WORD_ADDRESS 0x300003
-#define DEFAULT_CONFIG2H_WORD DEFAULT_CONFIG_BYTE
+ /* ... and secondarily by size. */
+ /* Register size sorting may have strange results, use with care! */
+ if ((*i)->size > (*j)->size)
+ return (1);
-#define CONFIG3H_WORD_ADDRESS 0x300005
-#define DEFAULT_CONFIG3H_WORD DEFAULT_CONFIG_BYTE
+ if ((*i)->size < (*j)->size)
+ return (-1);
-#define CONFIG4L_WORD_ADDRESS 0x300006
-#define DEFAULT_CONFIG4L_WORD DEFAULT_CONFIG_BYTE
+ /* Finally, if in same address and same size, sort by name. */
+ return (strcmp ((*i)->name, (*j)->name));
+}
-#define CONFIG5L_WORD_ADDRESS 0x300008
-#define DEFAULT_CONFIG5L_WORD DEFAULT_CONFIG_BYTE
+int
+symCompare (const void *a, const void *b)
+{
+ const symbol *const *i = a;
+ const symbol *const *j = b;
-#define CONFIG5H_WORD_ADDRESS 0x300009
-#define DEFAULT_CONFIG5H_WORD DEFAULT_CONFIG_BYTE
+ /* Sort primarily by the address ... */
+ if (SPEC_ADDR ((*i)->etype) > SPEC_ADDR ((*j)->etype))
+ return (1);
-#define CONFIG6L_WORD_ADDRESS 0x30000a
-#define DEFAULT_CONFIG6L_WORD DEFAULT_CONFIG_BYTE
+ if (SPEC_ADDR ((*i)->etype) < SPEC_ADDR ((*j)->etype))
+ return (-1);
-#define CONFIG6H_WORD_ADDRESS 0x30000b
-#define DEFAULT_CONFIG6H_WORD DEFAULT_CONFIG_BYTE
+ /* ... and secondarily by size. */
+ /* Register size sorting may have strange results, use with care! */
+ if (getSize ((*i)->etype) > getSize ((*j)->etype))
+ return (1);
-#define CONFIG7L_WORD_ADDRESS 0x30000c
-#define DEFAULT_CONFIG7L_WORD DEFAULT_CONFIG_BYTE
+ if (getSize ((*i)->etype) < getSize ((*j)->etype))
+ return (-1);
-#define CONFIG7H_WORD_ADDRESS 0x30000d
-#define DEFAULT_CONFIG7H_WORD DEFAULT_CONFIG_BYTE
+ /* Finally, if in same address and same size, sort by name. */
+ return (strcmp ((*i)->rname, (*j)->rname));
+}
-static unsigned int config1h_word = DEFAULT_CONFIG1H_WORD;
-static unsigned int config2l_word = DEFAULT_CONFIG2L_WORD;
-static unsigned int config2h_word = DEFAULT_CONFIG2H_WORD;
-static unsigned int config3h_word = DEFAULT_CONFIG3H_WORD;
-static unsigned int config4l_word = DEFAULT_CONFIG4L_WORD;
-static unsigned int config5l_word = DEFAULT_CONFIG5L_WORD;
-static unsigned int config5h_word = DEFAULT_CONFIG5H_WORD;
-static unsigned int config6l_word = DEFAULT_CONFIG6L_WORD;
-static unsigned int config6h_word = DEFAULT_CONFIG6H_WORD;
-static unsigned int config7l_word = DEFAULT_CONFIG7L_WORD;
-static unsigned int config7h_word = DEFAULT_CONFIG7H_WORD;
+void
+pic16_dump_usection (FILE *of, set *section, int fix)
+{
+ static int abs_usection_no = 0;
+ static unsigned int usection_no = 0;
+ regs *r, *rprev;
+ unsigned int init_addr, i;
+ regs **rlist;
+ regs *r1;
-unsigned int stackPos = 0;
+ /* put all symbols in an array */
+ if (!elementsInSet (section))
+ return;
-extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
+ rlist = Safe_calloc (elementsInSet (section), sizeof (regs *));
+ r = rlist[0];
+ i = 0;
+ for (rprev = setFirstItem (section); rprev; rprev = setNextItem (section))
+ {
+ rlist[i] = rprev;
+ i++;
+ } // for
+
+ if (!i)
+ {
+ if (rlist)
+ Safe_free (rlist);
+
+ return;
+ } // if
+
+ /* sort symbols according to their address */
+ qsort (rlist, i, sizeof (regs *), regCompare);
+
+ if (!fix)
+ {
+#define EMIT_SINGLE_UDATA_SECTION 0
+#if EMIT_SINGLE_UDATA_SECTION
+ fprintf (of, "\n\n\tudata\n");
+ for (r = setFirstItem (section); r; r = setNextItem (section))
+ {
+ fprintf (of, "%s\tres\t%d\n", r->name, r->size);
+ statistics.udsize += r->size;
+ } // for
+#else
+ for (r = setFirstItem (section); r; r = setNextItem (section))
+ {
+ //fprintf (of, "\nudata_%s_%s\tudata\n", moduleName, r->name);
+ fprintf (of, "\nudata_%s_%u\tudata\n", moduleName, usection_no++);
+ fprintf (of, "%s\tres\t%d\n", r->name, r->size);
+ statistics.udsize += r->size;
+ } // for
+#endif
+ }
+ else
+ {
+ unsigned int j = 0;
+ unsigned int prev_size = 0;
+
+ rprev = NULL;
+ init_addr = (rlist[j]->address & 0x0FFF); // warning(s) emitted below
+ fprintf (of, "\n\nustat_%s_%02d\tudata\t0X%04X\n", moduleName, abs_usection_no++, (init_addr & 0x0FFF));
+
+ for (j = 0; j < i; j++)
+ {
+ r = rlist[j];
+ r1 = NULL;
+ if (j < i - 1)
+ r1 = rlist[j + 1];
+
+ init_addr = (r->address & 0x0FFF);
+ if (init_addr != r->address)
+ {
+ fprintf (stderr, "%s: WARNING: Changed address of pinned variable %s from 0x%x to 0x%x\n",
+ moduleName, r->name, r->address, init_addr);
+ } // if
+
+ if ((rprev && (init_addr != ((rprev->address & 0x0FFF) + prev_size))))
+ fprintf (of, "\n\nustat_%s_%02d\tudata\t0X%04X\n", moduleName, abs_usection_no++, init_addr);
+
+ /* XXX: Does not handle partial overlap correctly. */
+ if (r1 && (init_addr == (r1->address & 0x0FFF)))
+ {
+ prev_size = 0;
+ fprintf (of, "%-15s\n", r->name);
+ }
+ else
+ {
+ prev_size = r->size;
+ fprintf (of, "%-15s\tres\t%d\n", r->name, prev_size);
+ statistics.udsize += prev_size;
+ }
+
+ rprev = r;
+ } // for
+ } // if
+
+ Safe_free (rlist);
+}
-void pic16_setMaxRAM(int size)
+void
+pic16_dump_gsection (FILE *of, set *sections)
{
- pic->maxRAMaddress = size;
- stackPos = pic->RAMsize-1;
- regs * reg;
+ regs *r;
+ sectName *sname;
- reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "stack", 1, 0, NULL);
- addSet(&pic16_fix_udata, reg);
+ for (sname = setFirstItem (sections); sname; sname = setNextItem (sections))
+ {
+ if (!strcmp (sname->name, "access"))
+ continue;
- if (pic->maxRAMaddress < 0) {
- fprintf(stderr, "invalid \"#pragma maxram 0x%x\" setting\n",
- pic->maxRAMaddress);
- return;
- }
+ fprintf (of, "\n\n%s\tudata\n", sname->name);
-// pic16_finalMapping = Safe_calloc(1+pic->maxRAMaddress,
-// sizeof(AssignedMemory));
+ for (r = setFirstItem (sname->regsSet); r; r = setNextItem (sname->regsSet))
+ {
+#if 0
+ fprintf (stderr, "%s:%d emitting variable %s for section %s (%p)\n",
+ __FILE__, __LINE__, r->name, sname->name, sname);
+#endif
+ fprintf (of, "%s\tres\t%d\n", r->name, r->size);
+ statistics.udsize += r->size;
+ } // for
+ } // for
+}
- /* Now initialize the pic16_finalMapping array */
+void
+pic16_dump_isection (FILE *of, set *section, int fix)
+{
+ static int abs_isection_no = 0;
+ symbol *s, *sprev;
+ unsigned int init_addr, i;
+ symbol **slist;
+
+ /* put all symbols in an array */
+ if (!elementsInSet (section))
+ return;
-// for(i=0; i<=pic->maxRAMaddress; i++) {
-// pic16_finalMapping[i].reg = NULL;
-// pic16_finalMapping[i].isValid = 0;
-// }
+ slist = Safe_calloc (elementsInSet (section), sizeof (symbol *));
+ s = slist[0];
+ i = 0;
+ for (sprev = setFirstItem (section); sprev; sprev = setNextItem (section))
+ {
+ slist[i] = sprev;
+ i++;
+ } // for
+
+ if (!i)
+ {
+ if (slist)
+ Safe_free (slist);
+
+ return;
+ } // if
+
+ /* sort symbols according to their address */
+ qsort (slist, i, sizeof (symbol *), symCompare);
+
+ pic16_initDB ();
+
+ if (!fix)
+ {
+ fprintf (of, "\n\n\tidata\n");
+ for (s = setFirstItem (section); s; s = setNextItem (section))
+ {
+ if (s->ival)
+ {
+ fprintf (of, "%s", s->rname);
+ pic16_printIval (s, s->type, s->ival, 'f', (void *)of);
+ pic16_flushDB ('f', (void *)of);
+ }
+ else
+ {
+ if (IS_ARRAY (s->type) && IS_CHAR (s->type->next)
+ && SPEC_CVAL (s->etype).v_char)
+ {
+ //fprintf (stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname);
+ pic16_pCodeConstString (s->rname , SPEC_CVAL (s->etype).v_char, getSize (s->type));
+ }
+ else
+ {
+ assert (0);
+ } // if
+ } // if
+ } // for
+ }
+ else
+ {
+ unsigned int j = 0;
+ symbol *s1;
+
+ sprev = NULL;
+ init_addr = SPEC_ADDR (slist[j]->etype);
+ fprintf (of, "\n\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
+
+ for (j = 0; j < i; j++)
+ {
+ s = slist[j];
+ s1 = NULL;
+ if (j < i - 1)
+ s1 = slist[j + 1];
+
+ init_addr = SPEC_ADDR (s->etype);
+
+ if (sprev && (init_addr > (SPEC_ADDR (sprev->etype) + getSize (sprev->etype))))
+ fprintf(of, "\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
+
+ if (s->ival)
+ {
+ fprintf (of, "%s", s->rname);
+ pic16_printIval (s, s->type, s->ival, 'f', (void *)of);
+ pic16_flushDB ('f', (void *)of);
+ }
+ else
+ {
+ if (IS_ARRAY (s->type) && IS_CHAR (s->type->next)
+ && SPEC_CVAL (s->etype).v_char)
+ {
+ //fprintf (stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname);
+ pic16_pCodeConstString (s->rname , SPEC_CVAL (s->etype).v_char, getSize (s->type));
+ }
+ else
+ {
+ assert (0);
+ } // if
+ } // if
+
+ sprev = s;
+ } // for
+ } // if
+
+ Safe_free (slist);
}
-/*-----------------------------------------------------------------*
- *-----------------------------------------------------------------*/
-#if 0
-int pic16_isREGinBank(regs *reg, int bank)
+void
+pic16_dump_int_registers (FILE *of, set *section)
{
+ regs *r, *rprev;
+ int i;
+ regs **rlist;
- if(!reg || !pic)
- return 0;
+ /* put all symbols in an array */
+ if (!elementsInSet (section))
+ return;
- if(pic16_finalMapping[reg->address].bank == bank)
- return 1;
+ rlist = Safe_calloc (elementsInSet (section), sizeof (regs *));
+ r = rlist[0];
+ i = 0;
+ for (rprev = setFirstItem (section); rprev; rprev = setNextItem (section))
+ {
+ rlist[i] = rprev;
+ i++;
+ } // for
- return 0;
-}
-#endif
-/*-----------------------------------------------------------------*
- *-----------------------------------------------------------------*/
-int pic16_REGallBanks(regs *reg)
-{
+ if (!i)
+ {
+ if (rlist)
+ Safe_free (rlist);
- if(!reg || !pic)
- return 0;
+ return;
+ } // if
- if ((int)reg->address > pic->maxRAMaddress)
- return 0;
+ /* sort symbols according to their address */
+ qsort (rlist, i, sizeof (regs *), regCompare);
- return 1;
+ fprintf (of, "\n\n; Internal registers\n");
-}
+ fprintf (of, "%s\tudata_ovr\t0x0000\n", ".registers");
+ for (r = setFirstItem (section); r; r = setNextItem (section))
+ {
+ fprintf (of, "%s\tres\t%d\n", r->name, r->size);
+ statistics.intsize += r->size;
+ } // for
-/*-----------------------------------------------------------------*
- *-----------------------------------------------------------------*/
+ Safe_free (rlist);
+}
-/*
- * pic16_dump_map -- debug stuff
+/**
+ * Find the device structure for the named device.
+ * Consider usind pic16_find_device() instead!
+ *
+ * @param name
+ * a name for the desired device
+ * @param head
+ * a pointer to the head of the list of devices
+ * @return
+ * a pointer to the structure for the desired
+ * device, or NULL
*/
-#if 0
-void pic16_dump_map(void)
+static PIC16_device *
+find_in_list(const char *name, PIC16_device *head)
{
- int i;
+ int i;
- for(i=0; i<=pic->maxRAMaddress; i++) {
- //fprintf(stdout , "addr 0x%02x is %s\n", i, ((pic16_finalMapping[i].isValid) ? "valid":"invalid"));
+ while (head) {
+ for (i = 0; i < 4; i++) {
+ if (0 == strcmp(head->name[i], name)) {
+ return (head);
+ } // if
+ } // for
- if(pic16_finalMapping[i].isValid) {
- fprintf(stderr,"addr: 0x%02x",i);
- if(pic16_finalMapping[i].isSFR)
- fprintf(stderr," isSFR");
- if(pic16_finalMapping[i].reg)
- fprintf( stderr, " reg %s", pic16_finalMapping[i].reg->name);
- fprintf(stderr, "\n");
- }
- }
+ head = head->next;
+ } // while
+ return (NULL);
}
-#endif
-extern char *iComments2;
-
-void pic16_dump_equates(FILE *of, set *equs)
+/**
+ * Print a list of supported devices.
+ * If --verbose was given, also emit key characteristics (memory size,
+ * access bank split point, address range of SFRs and config words).
+ *
+ * @param head
+ * a pointer to the head of the list of devices
+ */
+static void
+pic16_list_devices(PIC16_device *head)
{
- regs *r;
-
- r = setFirstItem(equs);
- if(!r)return;
-
- fprintf(of, "%s", iComments2);
- fprintf(of, ";\tEquates to used internal registers\n");
- fprintf(of, "%s", iComments2);
-
- for(; r; r = setNextItem(equs)) {
- fprintf(of, "%s\tequ\t0x%02x\n", r->name, r->address);
- }
+ int i = 0;
+
+ if (options.verbose) {
+ printf("device RAM split config words\n");
+ } // if
+ while (head) {
+ printf("%-10s ", head->name[0]);
+ if (options.verbose) {
+ printf("%5d 0x%02x 0x%06x..0x%06x\n",
+ head->RAMsize,
+ head->acsSplitOfs,
+ head->cwInfo.confAddrStart,
+ head->cwInfo.confAddrEnd);
+ } else {
+ i++;
+ if (0 == (i % 6)) {
+ printf("\n");
+ } // if
+ } // if
+ head = head->next;
+ } // while
+ printf("\n");
}
-
-int regCompare(const void *a, const void *b)
+/**
+ * Read a single line from the given file.
+ *
+ * @param file
+ * a pointer to the open file to read
+ * @return
+ * a pointer to a malloc'ed copy of the (next) line, or NULL
+ */
+static char *
+get_line (FILE *file)
{
- const regs *const *i = a;
- const regs *const *j = b;
+ static struct dbuf_s dbuf;
+ static int initialized = 0;
+
+ if (!initialized)
+ {
+ dbuf_init (&dbuf, 129);
+ initialized = 1;
+ }
+ else
+ dbuf_set_length (&dbuf, 0);
- if( (*i)->address > (*j)->address)return 1;
- if( (*i)->address < (*j)->address)return -1;
- return 0;
+ if (dbuf_getline (&dbuf, file) != 0)
+ {
+ dbuf_chomp (&dbuf);
+ /* (char *) type cast is an ugly hack since pic16_find_device() modifies the buffer */
+ return (char *)dbuf_get_buf (&dbuf);
+ }
+ else
+ {
+ dbuf_destroy(&dbuf);
+ initialized = 0;
+ return NULL;
+ }
}
-void pic16_dump_section(FILE *of, set *section, int fix)
+/**
+ * Truncate the given string in place (!) at the first '#' character (if any).
+ *
+ * @param line
+ * a pointer to the string to truncate
+ * @return
+ * a pointer to the truncated string (i.e., line)
+ */
+static char *
+strip_comment (char *line)
{
- static int abs_section_no=0;
- regs *r, *rprev;
- int init_addr, i;
- regs **rlist;
-
- /* put all symbols in an array */
- rlist = Safe_calloc(elementsInSet(section), sizeof(regs *));
- r = rlist[0]; i = 0;
- for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) {
- rlist[i] = rprev; i++;
- }
-
- /* sort symbols according to their address */
- qsort(rlist, elementsInSet(section), sizeof(regs *), regCompare);
-
- if(!i)return;
-
- if(!fix) {
- fprintf(of, "\n\n\tudata\n");
- for(r = setFirstItem(section); r; r = setNextItem(section)) {
- fprintf(of, "%s\tres\t%d\n", r->name, r->size);
- }
- } else {
- int j=0;
-
- rprev = NULL;
- init_addr = rlist[j]->address;
- fprintf(of, "\n\nstatic_%s_%02d\tudata\t0X%04X\n", moduleName, abs_section_no++, init_addr);
-
- for(j=0;j<i;j++) {
- r = rlist[j];
- init_addr = r->address;
- if(rprev && (init_addr != (rprev->address + rprev->size))) {
- fprintf(of, "\nstatic_%s_%02d\tudata\t0X%04X\n", moduleName, abs_section_no++, init_addr);
- }
-
- fprintf(of, "%s\tres\t%d\n", r->name, r->size);
- rprev = r;
- }
- }
- free(rlist);
+ char *l = line;
+ char c;
+
+ if (!line)
+ {
+ return (line);
+ } // if
+
+ while (0 != (c = *l))
+ {
+ if ('#' == c)
+ {
+ *l = 0;
+ return (line);
+ } // if
+ l++;
+ } // while
+
+ return (line);
}
-
-
-
-/*-----------------------------------------------------------------*
- * void pic16_list_valid_pics(int ncols, int list_alias)
+/**
+ * Report errors in the device specification.
*
- * Print out a formatted list of valid PIC devices
- *
- * ncols - number of columns in the list.
+ * @param msg
+ * a pointer to the detailed message
+ */
+#define SYNTAX(msg) do { \
+ fprintf(stderr, "%s:%d: Syntax error: %s\n", \
+ DEVICE_FILE_NAME, lineno, msg); \
+} while (0)
+
+/**
+ * Locate and read in the device specification (if required) and
+ * return the device structure for the named device.
*
- * list_alias - if non-zero, print all of the supported aliases
- * for a device (e.g. F84, 16F84, etc...)
- *-----------------------------------------------------------------*/
-void pic16_list_valid_pics(int ncols, int list_alias)
+ * @param name
+ * a pointer to the name of the desired device
+ * @return
+ * a pointer to the device structure, or NULL
+ */
+static PIC16_device *
+pic16_find_device(const char *name)
{
- int col,longest;
- int i,j,k,l;
-
- if(list_alias)
- list_alias = sizeof(Pics[0].name) / sizeof(Pics[0].name[0]);
-
- /* decrement the column number if it's greater than zero */
- ncols = (ncols > 1) ? ncols-1 : 4;
-
- /* Find the device with the longest name */
- for(i=0,longest=0; i<num_of_supported_PICS; i++) {
- for(j=0; j<=list_alias; j++) {
- k = strlen(Pics[i].name[j]);
- if(k>longest)
- longest = k;
+ const char *path;
+ char buffer[PATH_MAX];
+ char *line, *key;
+ const char *sep = " \t\n\r";
+ FILE *f = NULL;
+ PIC16_device *d = NULL, *template;
+ PIC16_device *head = NULL, *tail = NULL;
+ set *_sets[] = { userIncDirsSet, includeDirsSet };
+ set **sets = &_sets[0];
+ int lineno = 0;
+ int res, i;
+ int val[4];
+
+ if (!devices)
+ {
+ //printf("%s: searching %s\n", __func__, DEVICE_FILE_NAME);
+
+ // locate the specification file in the include search paths
+ for (i = 0; (NULL == f) && (i < 2); i++)
+ {
+ for (path = setFirstItem(sets[i]);
+ (NULL == f) && path;
+ path = setNextItem(sets[i]))
+ {
+ SNPRINTF(&buffer[0], PATH_MAX, "%s%s%s",
+ path, DIR_SEPARATOR_STRING, DEVICE_FILE_NAME);
+ //printf("%s: checking %s\n", __func__, &buffer[0]);
+ f = fopen(&buffer[0], "r");
+ } // for
+ } // for
+ } // if
+
+ if (devices)
+ {
+ // list already set up, nothing to do
}
- }
-
- col = 0;
-
- for(i=0; i < num_of_supported_PICS; i++) {
- j = 0;
- do {
-
- fprintf(stderr,"%s", Pics[i].name[j]);
- if(col<ncols) {
- l = longest + 2 - strlen(Pics[i].name[j]);
- for(k=0; k<l; k++)
- fputc(' ',stderr);
-
- col++;
-
- } else {
- fputc('\n',stderr);
- col = 0;
- }
-
- } while(++j<list_alias);
-
- }
- if(col != ncols)
- fputc('\n',stderr);
-
+ else if (NULL == f)
+ {
+ fprintf(stderr, "ERROR: device list %s not found, specify its path via -I<path>\n",
+ DEVICE_FILE_NAME);
+ d = &default_device;
+ }
+ else
+ {
+ // parse the specification file and construct a linked list of
+ // supported devices
+ d = NULL;
+ while (NULL != (line = get_line(f)))
+ {
+ strip_comment(line);
+ //printf("%s: read %s\n", __func__, line);
+ lineno++;
+ key = strtok(line, sep);
+ if (!key)
+ {
+ // empty line---ignore
+ }
+ else if (0 == strcmp(key, "name"))
+ {
+ // name %<name>s
+ if (d)
+ {
+ if (tail)
+ {
+ tail->next = d;
+ }
+ else
+ {
+ head = d;
+ } // if
+ tail = d;
+ d = NULL;
+ } // if
+
+ res = sscanf(&line[1 + strlen(key)], " %16s", &buffer[3]);
+ if ((1 < res) || (3 > strlen(&buffer[3])))
+ {
+ SYNTAX("<name> (e.g., 18f452) expected.");
+ }
+ else
+ {
+ d = Safe_calloc(1, sizeof(PIC16_device));
+
+ // { "p18f452", "18f452", "pic18f452", "f452" }
+ buffer[0] = 'p';
+ buffer[1] = 'i';
+ buffer[2] = 'c';
+ d->name[3] = Safe_strdup(&buffer[5]);
+ d->name[2] = Safe_strdup(&buffer[0]);
+ d->name[1] = Safe_strdup(&buffer[3]);
+ buffer[2] = 'p';
+ d->name[0] = Safe_strdup(&buffer[2]);
+ } // if
+ }
+ else if (0 == strcmp(key, "using"))
+ {
+ // using %<name>s
+ res = sscanf(&line[1 + strlen(key)], " %16s", &buffer[0]);
+ if ((1 < res) || (3 > strlen(&buffer[3])))
+ {
+ SYNTAX("<name> (e.g., 18f452) expected.");
+ }
+ else
+ {
+ template = find_in_list(&buffer[0], head);
+ if (!template)
+ {
+ SYNTAX("<name> (e.g., 18f452) expected.");
+ }
+ else
+ {
+ memcpy(&d->RAMsize, &template->RAMsize,
+ ((char *)&d->next) - ((char *)&d->RAMsize));
+ } // if
+ } // if
+ }
+ else if (0 == strcmp(key, "ramsize"))
+ {
+ // ramsize %<bytes>i
+ res = sscanf(&line[1 + strlen(key)], " %i", &val[0]);
+ if (res < 1)
+ {
+ SYNTAX("<bytes> (e.g., 256) expected.");
+ }
+ else
+ {
+ d->RAMsize = val[0];
+ } // if
+ }
+ else if (0 == strcmp(key, "split"))
+ {
+ // split %<offset>i
+ res = sscanf(&line[1 + strlen(key)], " %i", &val[0]);
+ if (res < 1)
+ {
+ SYNTAX("<offset> (e.g., 0x80) expected.");
+ }
+ else
+ {
+ d->acsSplitOfs = val[0];
+ } // if
+ }
+ else if (0 == strcmp(key, "configrange"))
+ {
+ // configrange %<first>i %<last>i
+ res = sscanf(&line[1 + strlen(key)], " %i %i",
+ &val[0], &val[1]);
+ if (res < 2)
+ {
+ SYNTAX("<first> <last> (e.g., 0xf60 0xfff) expected.");
+ }
+ else
+ {
+ d->cwInfo.confAddrStart = val[0];
+ d->cwInfo.confAddrEnd = val[1];
+ } // if
+ }
+ else if (0 == strcmp(key, "configword"))
+ {
+ // configword %<address>i %<mask>i %<value>i [%<and-mask>i]
+ res = sscanf(&line[1 + strlen(key)], " %i %i %i %i",
+ &val[0], &val[1], &val[2], &val[3]);
+ if (res < 3)
+ {
+ SYNTAX("<address> <mask> <value> [<and-mask>] (e.g., 0x200001 0x0f 0x07) expected.");
+ }
+ else
+ {
+ val[0] -= d->cwInfo.confAddrStart;
+ if ((val[0] < 0)
+ || (val[0] > (d->cwInfo.confAddrEnd - d->cwInfo.confAddrStart))
+ || (val[0] >= CONFIGURATION_WORDS))
+ {
+ SYNTAX("address out of bounds.");
+ }
+ else
+ {
+ d->cwInfo.crInfo[val[0]].mask = val[1];
+ d->cwInfo.crInfo[val[0]].value = val[2];
+ d->cwInfo.crInfo[val[0]].andmask = 0;
+ if (res >= 4)
+ {
+ // apply extra mask (e.g., to disable XINST)
+ d->cwInfo.crInfo[val[0]].andmask = val[3];
+ } // if
+ } // if
+ } // if
+ }
+ else if (0 == strcmp(key, "idlocrange"))
+ {
+ // idlocrange %<first>i %<last>i
+ res = sscanf(&line[1 + strlen(key)], " %i %i",
+ &val[0], &val[1]);
+ if (res < 2)
+ {
+ SYNTAX("<first> <last> (e.g., 0xf60 0xfff) expected.");
+ }
+ else
+ {
+ d->idInfo.idAddrStart = val[0];
+ d->idInfo.idAddrEnd = val[1];
+ } // if
+ }
+ else if (0 == strcmp(key, "idword"))
+ {
+ // idword %<address>i %<value>i
+ res = sscanf(&line[1 + strlen(key)], " %i %i",
+ &val[0], &val[1]);
+ if (res < 2)
+ {
+ SYNTAX("<address> <value> (e.g., 0x3fffff 0x00) expected.");
+ }
+ else
+ {
+ val[0] -= d->idInfo.idAddrStart;
+ if ((val[0] < 0)
+ || (val[0] > (d->idInfo.idAddrEnd - d->idInfo.idAddrStart))
+ || (val[0] >= IDLOCATION_BYTES))
+ {
+ SYNTAX("address out of bounds.");
+ }
+ else
+ {
+ d->idInfo.irInfo[val[0]].value = val[1];
+ } // if
+ } // if
+ }
+ else
+ {
+ printf("%s: Invalid keyword in %s ignored: %s\n",
+ __func__, DEVICE_FILE_NAME, key);
+ } // if
+ } // while
+
+ if (d)
+ {
+ if (tail)
+ {
+ tail->next = d;
+ }
+ else
+ {
+ head = d;
+ } // if
+ tail = d;
+ d = NULL;
+ } // if
+
+ devices = head;
+
+ fclose(f);
+ } // if
+
+ d = find_in_list(name, devices);
+ if (!d)
+ {
+ d = &default_device;
+ } // if
+
+ return (d);
}
/*-----------------------------------------------------------------*
- *
+ *
*-----------------------------------------------------------------*/
-PIC_device *pic16_find_device(char *name)
+void pic16_init_pic(const char *pic_type)
{
+ pic16 = pic16_find_device(pic_type);
+
+ if (&default_device == pic16) {
+ if (pic_type) {
+ fprintf(stderr, "'%s' was not found.\n", pic_type);
+ } else {
+ fprintf(stderr, "No processor has been specified (use -pPROCESSOR_NAME)\n");
+ } // if
+
+ if (devices) {
+ fprintf(stderr,"Valid devices are (use --verbose for more details):\n");
+ pic16_list_devices(devices);
+ } // if
+ exit(EXIT_FAILURE);
+ } // if
+}
- int i,j;
+/*-----------------------------------------------------------------*
+ * char *pic16_processor_base_name(void) - Include file is derived from this.
+ *-----------------------------------------------------------------*/
+char *pic16_processor_base_name(void)
+{
- if(!name)
+ if(!pic16)
return NULL;
- for(i = 0; i<num_of_supported_PICS; i++) {
-
- for(j=0; j<PROCESSOR_NAMES; j++)
- if(!STRCASECMP(Pics[i].name[j], name) )
- return &Pics[i];
- }
-
- /* not found */
- return NULL;
+ return pic16->name[0];
}
-/*-----------------------------------------------------------------*
- *
- *-----------------------------------------------------------------*/
-void pic16_init_pic(char *pic_type)
+#define DEBUG_CHECK 0
+
+/*
+ * return 1 if register wasn't found and added, 0 otherwise
+ */
+int checkAddReg(set **set, regs *reg)
{
- pic = pic16_find_device(pic_type);
+ regs *tmp;
- if(!pic) {
- if(pic_type)
- fprintf(stderr, "'%s' was not found.\n", pic_type);
- else
- fprintf(stderr, "No processor has been specified (use -pPROCESSOR_NAME)\n");
- fprintf(stderr,"Valid devices are:\n");
+ if(!reg)return 0;
+#if DEBUG_CHECK
+ fprintf(stderr, "%s: about to insert REGister: %s ... ", __FUNCTION__, reg->name);
+#endif
+
+ for(tmp = setFirstItem(*set); tmp; tmp = setNextItem(*set)) {
+ if(!strcmp(tmp->name, reg->name))break;
+ }
- pic16_list_valid_pics(4,0);
- exit(1);
- }
+ if(!tmp) {
+ addSet(set, reg);
+#if DEBUG_CHECK
+ fprintf(stderr, "added\n");
+#endif
+ return 1;
+ }
-// printf("PIC processor found and initialized: %s\n", pic_type);
- pic16_setMaxRAM( 0xfff );
+#if DEBUG_CHECK
+ fprintf(stderr, "already added\n");
+#endif
+ return 0;
}
-/*-----------------------------------------------------------------*
- *
- *-----------------------------------------------------------------*/
-int pic16_picIsInitialized(void)
+int checkAddSym(set **set, symbol *sym)
{
- if(pic && pic->maxRAMaddress > 0)
- return 1;
+ symbol *tmp;
- return 0;
+ if(!sym)return 0;
+#if DEBUG_CHECK
+ fprintf(stderr, "%s: about to add SYMbol: %s ... ", __FUNCTION__, sym->name);
+#endif
-}
+ for(tmp = setFirstItem( *set ); tmp; tmp = setNextItem(*set)) {
+ if(!strcmp(tmp->name, sym->name))break;
+ }
-/*-----------------------------------------------------------------*
- * char *pic16_processor_base_name(void) - Include file is derived from this.
- *-----------------------------------------------------------------*/
-char *pic16_processor_base_name(void)
-{
+ if(!tmp) {
+ addSet(set, sym);
+#if DEBUG_CHECK
+ fprintf(stderr, "added\n");
+#endif
+ return 1;
+ }
- if(!pic)
- return NULL;
+#if DEBUG_CHECK
+ fprintf(stderr, "already added\n");
+#endif
- return pic->name[0];
+ return 0;
}
-
-#if 0
-/*-----------------------------------------------------------------*
- *-----------------------------------------------------------------*/
-static int validAddress(int address, int reg_size)
+int checkSym(set *set, symbol *sym)
{
- int i;
+ symbol *tmp;
-#if 0
- if (pic->maxRAMaddress < 0) {
- fprintf(stderr, "missing \"#pragma maxram\" setting\n");
- return 0;
- }
-// fprintf(stderr, "validAddress: Checking 0x%04x (max=0x%04x) (reg_size = %d)\n",address, pic->maxRAMaddress, reg_size);
- if(address > pic->maxRAMaddress)
- return 0;
-
- for (i=0; i<reg_size; i++)
- if(!pic16_finalMapping[address + i].isValid ||
- pic16_finalMapping[address+i].reg ||
- pic16_finalMapping[address+i].isSFR )
- return 0;
-#endif
+ if(!sym)return 0;
- return 1;
-}
+#if DEUG_CHECK
+ fprintf(stderr, "%s: about to search for SYMbol: %s ... ", __FUNCTION__, sym->name);
#endif
-void checkAddReg(set **set, regs *reg)
-{
- regs *tmp;
+ for(tmp = setFirstItem( set ); tmp; tmp = setNextItem( set )) {
+ if(!strcmp(tmp->name, sym->name))break;
+ }
+
+ if(!tmp) {
+#if DEBUG_CHECK
+ fprintf(stderr, "not found\n");
+#endif
+ return 0;
+ }
+#if DEBUG_CHECK
+ fprintf(stderr, "found\n");
+#endif
- for(tmp = setFirstItem(*set); tmp; tmp = setNextItem(*set)) {
- if(!strcmp(tmp->name, reg->name))break;
- }
-
- if(!tmp)
- addSet(set, reg);
+ return 1;
}
/*-----------------------------------------------------------------*
* void pic16_groupRegistersInSection - add each register to its *
- * corresponding section *
+ * corresponding section *
*-----------------------------------------------------------------*/
void pic16_groupRegistersInSection(set *regset)
{
regs *reg;
+ sectSym *ssym;
+ int docontinue=0;
- for(reg=setFirstItem(regset); reg; reg = setNextItem(regset)) {
- if(reg->wasUsed
- && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop)))) {
-
-// fprintf(stderr, "%s:%d register %s\n", __FILE__, __LINE__, reg->name);
-
- if(reg->alias) {
- checkAddReg(&pic16_equ_data, reg);
- } else
- if(reg->isFixed) {
- checkAddReg(&pic16_fix_udata, reg);
- } else
- if(!reg->isFixed) {
-// fprintf(stderr, "%s:%d adding symbol %s in relocatable udata section\n",
-// __FILE__, __LINE__, reg->name);
- checkAddReg(&pic16_rel_udata, reg);
- }
- }
- }
+ for(reg=setFirstItem(regset); reg; reg = setNextItem(regset)) {
+
+#if 0
+ fprintf(stderr, "%s:%d group registers in section, reg: %s (used: %d, %p)\n",
+ __FILE__, __LINE__, reg->name, reg->wasUsed, reg);
+#endif
+ if((reg->wasUsed
+ && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop))))
+ ) {
+
+ /* avoid grouping registers that have an initial value,
+ * they will be added later in idataSymSet */
+ if(reg->regop && (OP_SYMBOL(reg->regop)->ival && !OP_SYMBOL(reg->regop)->level))
+ continue;
+
+#if 0
+ fprintf(stderr, "%s:%d register %s alias:%d fix:%d ival=%i level=%i code=%i\n",
+ __FILE__, __LINE__, reg->name, reg->alias, reg->isFixed,
+ (reg->regop?(OP_SYMBOL(reg->regop)->ival?1:0):-1),
+ (reg->regop?(OP_SYMBOL(reg->regop)->level):-1),
+ (reg->regop?(IS_CODE(OP_SYM_ETYPE(reg->regop))):-1) );
+#endif
+
+ docontinue=0;
+ for(ssym=setFirstItem(sectSyms);ssym;ssym=setNextItem(sectSyms)) {
+ if(!strcmp(ssym->name, reg->name)) {
+// fprintf(stderr, "%s:%d section found %s (%p) with var %s\n",
+// __FILE__, __LINE__, ssym->section->name, ssym->section, ssym->name);
+ if(strcmp(ssym->section->name, "access")) {
+ addSet(&ssym->section->regsSet, reg);
+ docontinue=1;
+ break;
+ } else {
+ docontinue=0;
+ reg->accessBank = 1;
+ break;
+ }
+ }
+ }
+
+ if(docontinue)continue;
+
+// fprintf(stderr, "%s:%d reg: %s\n", __FILE__, __LINE__, reg->name);
+
+ if(reg->alias == 0x80) {
+ checkAddReg(&pic16_equ_data, reg);
+ } else
+ if(reg->isFixed) {
+ checkAddReg(&pic16_fix_udata, reg);
+ } else
+ if(!reg->isFixed) {
+ if(reg->pc_type == PO_GPR_TEMP)
+ checkAddReg(&pic16_int_regs, reg);
+ else {
+ if(reg->accessBank) {
+ if(reg->alias != 0x40)
+ checkAddReg(&pic16_acs_udata, reg);
+ } else
+ checkAddReg(&pic16_rel_udata, reg);
+ }
+ }
+ }
+ }
}
* This routine will assign a value to that address.
*
*-----------------------------------------------------------------*/
-
-void pic16_assignConfigWordValue(int address, int value)
+void
+pic16_assignConfigWordValue(int address, unsigned int value)
{
- switch(address) {
- case CONFIG1H_WORD_ADDRESS:
- config1h_word = value;
- break;
- case CONFIG2L_WORD_ADDRESS:
- config2l_word = value;
- break;
- case CONFIG2H_WORD_ADDRESS:
- config2h_word = value;
- break;
- case CONFIG3H_WORD_ADDRESS:
- config3h_word = value;
- break;
- case CONFIG4L_WORD_ADDRESS:
- config4l_word = value;
- break;
- case CONFIG5L_WORD_ADDRESS:
- config5l_word = value;
- break;
- case CONFIG5H_WORD_ADDRESS:
- config5h_word = value;
- break;
- case CONFIG6L_WORD_ADDRESS:
- config6l_word = value;
- break;
- case CONFIG6H_WORD_ADDRESS:
- config6h_word = value;
- break;
- case CONFIG7L_WORD_ADDRESS:
- config7l_word = value;
- break;
- case CONFIG7H_WORD_ADDRESS:
- config7h_word = value;
- break;
- }
-
- fprintf(stderr,"setting config word to 0x%x\n",value);
+ int i;
+
+ for (i = 0; i < pic16->cwInfo.confAddrEnd - pic16->cwInfo.confAddrStart + 1; i++)
+ {
+ if ((address == pic16->cwInfo.confAddrStart + i)
+ && (pic16->cwInfo.crInfo[i].mask != -1)
+ && (pic16->cwInfo.crInfo[i].mask != 0))
+ {
+
+#if 0
+ fprintf(stderr, "setting location 0x%x to value 0x%x, mask: 0x%x, test: 0x%x\n",
+ pic16->cwInfo.confAddrStart + i,
+ (~value) & 0xff,
+ pic16->cwInfo.crInfo[i].mask,
+ (pic16->cwInfo.crInfo[i].mask) & (~value));
+#endif
+
+#if 0
+ if ((((pic16->cwInfo.crInfo[i].mask) & (~value)) & 0xff) != ((~value) & 0xff))
+ {
+ fprintf(stderr, "%s:%d a wrong value has been given for configuration register 0x%x\n",
+ __FILE__, __LINE__, address);
+ return;
+ } // if
+#endif
+ pic16->cwInfo.crInfo[i].value = (value & 0xff);
+ if (pic16->cwInfo.crInfo[i].andmask
+ && ((value & 0xff) != (value & 0xff & pic16->cwInfo.crInfo[i].andmask)))
+ {
+ // apply andmask if effective
+ printf ("INFO: changing configuration word at 0x%x from 0x%x to 0x%x due to %s\n",
+ address,
+ (value & 0xff),
+ (value & 0xff & pic16->cwInfo.crInfo[i].andmask),
+ DEVICE_FILE_NAME);
+ pic16->cwInfo.crInfo[i].value &= pic16->cwInfo.crInfo[i].andmask;
+ } // if
+ pic16->cwInfo.crInfo[i].emit = 1;
+ return;
+ } // if
+ } // for
}
-/*-----------------------------------------------------------------*
- * int pic16_getConfigWord(int address)
- *
- * Get the current value of the config word.
- *
- *-----------------------------------------------------------------*/
-int pic16_getConfigWord(int address)
+void
+pic16_assignIdByteValue(int address, char value)
{
- switch(address) {
- case CONFIG1H_WORD_ADDRESS:
- return config1h_word;
- case CONFIG2L_WORD_ADDRESS:
- return config2l_word;
- case CONFIG2H_WORD_ADDRESS:
- return config2h_word;
- case CONFIG3H_WORD_ADDRESS:
- return config3h_word;
- case CONFIG4L_WORD_ADDRESS:
- return config4l_word;
- case CONFIG5L_WORD_ADDRESS:
- return config5l_word;
- case CONFIG5H_WORD_ADDRESS:
- return config5h_word;
- case CONFIG6L_WORD_ADDRESS:
- return config6l_word;
- case CONFIG6H_WORD_ADDRESS:
- return config6h_word;
- case CONFIG7L_WORD_ADDRESS:
- return config7l_word;
- case CONFIG7H_WORD_ADDRESS:
- return config7h_word;
- default:
- return 0;
- }
+ int i;
+
+ for (i = 0; i < pic16->idInfo.idAddrEnd - pic16->idInfo.idAddrStart + 1; i++)
+ {
+ if (address == pic16->idInfo.idAddrStart + i)
+ {
+ pic16->idInfo.irInfo[i].value = value;
+ pic16->idInfo.irInfo[i].emit = 1;
+ } // if
+ } // for
}
+