*** empty log message ***
[fw/sdcc] / src / pic16 / device.c
1 /*-------------------------------------------------------------------------
2
3   device.c - Accomodates subtle variations in PIC16 devices
4
5    Written By -  Scott Dattalo scott@dattalo.com
6    Ported to PIC16 By -  Martin Dubuc m.dubuc@rogers.com
7
8    This program is free software; you can redistribute it and/or modify it
9    under the terms of the GNU General Public License as published by the
10    Free Software Foundation; either version 2, or (at your option) any
11    later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 -------------------------------------------------------------------------*/
22
23
24 /*
25         VR - Began writing code to make PIC16 C source files independent from
26         the header file (created by the inc2h.pl)
27
28         - adding maximum RAM memory into PIC_Device structure
29
30 */
31
32 #include <stdio.h>
33
34 #include "common.h"   // Include everything in the SDCC src directory
35 #include "newalloc.h"
36
37
38 #include "pcode.h"
39 #include "ralloc.h"
40 #include "device.h"
41
42 #if defined(__BORLANDC__) || defined(_MSC_VER)
43 #define STRCASECMP stricmp
44 #else
45 #define STRCASECMP strcasecmp
46 #endif
47
48 static PIC_device Pics[] = {
49   {
50     {"p18f242", "18f242", "pic18f242", "f242"},         // aliases
51     (memRange *)NULL,                                   // ram memory map
52     (memRange *)NULL,                                   // sfr memory map
53     0,
54     0x300,                                              // bank mask
55     0x300,                                              // RAMsize
56     0
57   },
58
59   {
60     {"p18f252", "18f252", "pic18f252", "f252"},         // aliases
61     (memRange *)NULL,                                   // ram memory map
62     (memRange *)NULL,                                   // sfr memory map
63     0,
64     0x600,                                              // bank mask
65     0x600,                                              // RAMsize
66     0
67   },
68
69   {
70     {"p18f442", "18f442", "pic18f442", "f442"},         // aliases
71     (memRange *)NULL,                                   // ram memory map
72     (memRange *)NULL,                                   // sfr memory map
73     0,
74     0x300,                                              // bank mask
75     0x300,                                              // RAMsize
76     0
77   },
78
79   {
80     {"p18f452", "18f452", "pic18f452", "f452"},         // aliases
81     (memRange *)NULL,                                   // ram memory map
82     (memRange *)NULL,                                   // sfr memory map
83     0,
84     0x600,                                              // bank mask
85     0x600,                                              // RAMsize
86     0
87   },
88
89   {
90     {"p18f248", "18f248", "pic18f248", "f248"},         // aliases
91     (memRange *)NULL,                                   // ram memory map
92     (memRange *)NULL,                                   // sfr memory map
93     0,
94     0x300,                                              // bank mask
95     0x300,                                              // RAMsize
96     0
97   },
98
99   {
100     {"p18f258", "18f258", "pic18f258", "f258"},         // aliases
101     (memRange *)NULL,                                   // ram memory map
102     (memRange *)NULL,                                   // sfr memory map
103     0,
104     0x600,                                              // bank mask
105     0x600,                                              // RAMsize
106     0
107   },
108
109   {
110     {"p18f448", "18f448", "pic18f448", "f448"},         // aliases
111     (memRange *)NULL,                                   // ram memory map
112     (memRange *)NULL,                                   // sfr memory map
113     0,
114     0x300,                                              // bank mask
115     0x300,                                              // RAMsize
116     0
117   },
118
119   {
120     {"p18f458", "18f458", "pic18f458", "f458"},         // aliases
121     (memRange *)NULL,                                   // ram memory map
122     (memRange *)NULL,                                   // sfr memory map
123     0,
124     0x600,                                              // bank mask
125     0x600,                                              // RAMsize
126     0
127   },
128
129   {
130     {"p18f6520", "18f6520", "pic18f6520", "f6520"},     // aliases
131     (memRange *)NULL,                                   // ram memory map
132     (memRange *)NULL,                                   // sfr memory map
133     0,
134     0x800,                                              // bank mask
135     0x800,                                              // RAMsize
136     1
137   },
138
139   {
140     {"p18f6620", "18f6620", "pic18f6620", "f6620"},     // aliases
141     (memRange *)NULL,                                   // ram memory map
142     (memRange *)NULL,                                   // sfr memory map
143     0,
144     0xf00,                                              // bank mask
145     0xf00,                                              // RAMsize
146     1
147   },
148   {
149     {"p18f6680", "18f6680", "pic18f6680", "f6680"},     // aliases
150     (memRange *)NULL,                                   // ram memory map
151     (memRange *)NULL,                                   // sfr memory map
152     0,
153     0xc00,                                              // bank mask
154     0xc00,                                              // RAMsize
155     1
156   },
157   {
158     {"p18f6720", "18f6720", "pic18f6720", "f6720"},     // aliases
159     (memRange *)NULL,                                   // ram memory map
160     (memRange *)NULL,                                   // sfr memory map
161     0,
162     0xf00,                                              // bank mask
163     0xf00,                                              // RAMsize
164     1
165   },
166   {
167     {"p18f8520", "18f8520", "pic18f8520", "f8520"},     // aliases
168     (memRange *)NULL,                                   // ram memory map
169     (memRange *)NULL,                                   // sfr memory map
170     0,
171     0x800,                                              // bank mask
172     0x800,                                              // RAMsize
173     1
174   },
175   {
176     {"p18f8620", "18f8620", "pic18f8620", "f8620"},     // aliases
177     (memRange *)NULL,                                   // ram memory map
178     (memRange *)NULL,                                   // sfr memory map
179     0,
180     0xf00,                                              // bank mask
181     0xf00,                                              // RAMsize
182     1
183   },
184   {
185     {"p18f8680", "18f8680", "pic18f8680", "f8680"},     // aliases
186     (memRange *)NULL,                                   // ram memory map
187     (memRange *)NULL,                                   // sfr memory map
188     0,
189     0xc00,                                              // bank mask
190     0x800,                                              // RAMsize
191     1
192   },
193   {
194     {"p18f8720", "18f8720", "pic18f8720", "f8720"},     // aliases
195     (memRange *)NULL,                                   // ram memory map
196     (memRange *)NULL,                                   // sfr memory map
197     0,
198     0xf00,                                              // bank mask
199     0xf00,                                              // RAMsize
200     1
201   },
202
203 };
204
205 static int num_of_supported_PICS = sizeof(Pics)/sizeof(PIC_device);
206
207 #define DEFAULT_PIC "452"
208
209 static PIC_device *pic=NULL;
210
211 AssignedMemory *pic16_finalMapping=NULL;
212 int pic16_finalMappingSize=0;
213
214 #define DEFAULT_CONFIG_BYTE 0xff
215
216 #define CONFIG1H_WORD_ADDRESS 0x300001
217 #define DEFAULT_CONFIG1H_WORD DEFAULT_CONFIG_BYTE
218
219 #define CONFIG2L_WORD_ADDRESS 0x300002
220 #define DEFAULT_CONFIG2L_WORD DEFAULT_CONFIG_BYTE
221
222 #define CONFIG2H_WORD_ADDRESS 0x300003
223 #define DEFAULT_CONFIG2H_WORD DEFAULT_CONFIG_BYTE
224
225 #define CONFIG3H_WORD_ADDRESS 0x300005
226 #define DEFAULT_CONFIG3H_WORD DEFAULT_CONFIG_BYTE
227
228 #define CONFIG4L_WORD_ADDRESS 0x300006
229 #define DEFAULT_CONFIG4L_WORD DEFAULT_CONFIG_BYTE
230
231 #define CONFIG5L_WORD_ADDRESS 0x300008
232 #define DEFAULT_CONFIG5L_WORD DEFAULT_CONFIG_BYTE
233
234 #define CONFIG5H_WORD_ADDRESS 0x300009
235 #define DEFAULT_CONFIG5H_WORD DEFAULT_CONFIG_BYTE
236
237 #define CONFIG6L_WORD_ADDRESS 0x30000a
238 #define DEFAULT_CONFIG6L_WORD DEFAULT_CONFIG_BYTE
239
240 #define CONFIG6H_WORD_ADDRESS 0x30000b
241 #define DEFAULT_CONFIG6H_WORD DEFAULT_CONFIG_BYTE
242
243 #define CONFIG7L_WORD_ADDRESS 0x30000c
244 #define DEFAULT_CONFIG7L_WORD DEFAULT_CONFIG_BYTE
245
246 #define CONFIG7H_WORD_ADDRESS 0x30000d
247 #define DEFAULT_CONFIG7H_WORD DEFAULT_CONFIG_BYTE
248
249 static unsigned int config1h_word = DEFAULT_CONFIG1H_WORD;
250 static unsigned int config2l_word = DEFAULT_CONFIG2L_WORD;
251 static unsigned int config2h_word = DEFAULT_CONFIG2H_WORD;
252 static unsigned int config3h_word = DEFAULT_CONFIG3H_WORD;
253 static unsigned int config4l_word = DEFAULT_CONFIG4L_WORD;
254 static unsigned int config5l_word = DEFAULT_CONFIG5L_WORD;
255 static unsigned int config5h_word = DEFAULT_CONFIG5H_WORD;
256 static unsigned int config6l_word = DEFAULT_CONFIG6L_WORD;
257 static unsigned int config6h_word = DEFAULT_CONFIG6H_WORD;
258 static unsigned int config7l_word = DEFAULT_CONFIG7L_WORD;
259 static unsigned int config7h_word = DEFAULT_CONFIG7H_WORD;
260
261 void pic16_addMemRange(memRange *r, int type)
262 {
263   int i;
264   int alias = r->alias;
265
266   if (pic->maxRAMaddress < 0) {
267     fprintf(stderr, "missing \"#pragma maxram\" setting\n");
268     return;
269   }
270
271 //      fprintf(stderr, "%s: adding memory range from 0x%x to 0x%x type= %d\n",
272 //              __FUNCTION__, r->start_address, r->end_address, type);
273
274   do {
275     for (i=r->start_address; i<= r->end_address; i++) {
276       if ((i|alias) <= pic->maxRAMaddress) {
277         pic16_finalMapping[i | alias].isValid = 1;
278         pic16_finalMapping[i | alias].alias = r->alias;
279         pic16_finalMapping[i | alias].bank  = r->bank;
280         if(type) {
281           /* hack for now */
282           pic16_finalMapping[i | alias].isSFR  = 1;
283         } else {
284           pic16_finalMapping[i | alias].isSFR  = 0;
285         }
286       } else {
287         fprintf(stderr, "WARNING: %s:%s memory at 0x%x is beyond max ram = 0x%x\n",
288                 __FILE__,__FUNCTION__,(i|alias), pic->maxRAMaddress);
289       }
290     }
291
292     /* Decrement alias */
293     if (alias) {
294       alias -= ((alias & (alias - 1)) ^ alias);
295     } else {
296       alias--;
297     }
298
299   } while (alias >= 0);
300 }
301
302 void pic16_setMaxRAM(int size)
303 {
304   int i;
305   pic->maxRAMaddress = size;
306
307   if (pic->maxRAMaddress < 0) {
308     fprintf(stderr, "invalid \"#pragma maxram 0x%x\" setting\n",
309             pic->maxRAMaddress);
310     return;
311   }
312
313   pic16_finalMapping = Safe_calloc(1+pic->maxRAMaddress,
314                              sizeof(AssignedMemory));
315
316   /* Now initialize the pic16_finalMapping array */
317
318   for(i=0; i<=pic->maxRAMaddress; i++) {
319     pic16_finalMapping[i].reg = NULL;
320     pic16_finalMapping[i].isValid = 0;
321   }
322 }
323
324 /*-----------------------------------------------------------------*
325  *-----------------------------------------------------------------*/
326
327 int pic16_isREGinBank(regs *reg, int bank)
328 {
329
330   if(!reg || !pic)
331     return 0;
332
333   if(pic16_finalMapping[reg->address].bank == bank)
334     return 1;
335
336   return 0;
337 }
338
339 /*-----------------------------------------------------------------*
340  *-----------------------------------------------------------------*/
341 int pic16_REGallBanks(regs *reg)
342 {
343
344   if(!reg || !pic)
345     return 0;
346
347   if (reg->address > pic->maxRAMaddress)
348     return 0;
349
350   return 1;
351
352 }
353
354 /*-----------------------------------------------------------------*
355  *-----------------------------------------------------------------*/
356
357 /*
358  *  pic16_dump_map -- debug stuff
359  */
360
361 void pic16_dump_map(void)
362 {
363   int i;
364
365   for(i=0; i<=pic->maxRAMaddress; i++) {
366     //fprintf(stdout , "addr 0x%02x is %s\n", i, ((pic16_finalMapping[i].isValid) ? "valid":"invalid"));
367
368     if(pic16_finalMapping[i].isValid) {
369       fprintf(stderr,"addr: 0x%02x",i);
370       if(pic16_finalMapping[i].isSFR)
371         fprintf(stderr," isSFR");
372       if(pic16_finalMapping[i].reg) 
373         fprintf( stderr, "  reg %s", pic16_finalMapping[i].reg->name);
374       fprintf(stderr, "\n");
375     }
376   }
377
378 }
379
380 void pic16_dump_cblock(FILE *of)
381 {
382   int start=-1;
383   int addr=0;
384   int bank_base;
385
386   //pic16_dump_map();   /* display the register map */
387
388   if (pic->maxRAMaddress < 0) {
389     fprintf(stderr, "missing \"#pragma maxram\" setting\n");
390     return;
391   }
392
393   do {
394
395     if(pic16_finalMapping[addr].reg && !pic16_finalMapping[addr].reg->isEmitted) {
396
397       if(start<0)
398         start = addr;
399     } else {
400       if(start>=0) {
401
402         /* clear the lower 7-bits of the start address of the first
403          * variable declared in this bank. The upper bits for the mid
404          * range pics are the bank select bits.
405          */
406
407         bank_base = start & 0xfff8;
408
409         /* The bank number printed in the cblock comment tacitly
410          * assumes that the first register in the contiguous group
411          * of registers represents the bank for the whole group */
412
413         if ((pic16_finalMapping[start].bank == 0 && start <= 0x7f) ||
414             pic16_finalMapping[start].isSFR)
415           fprintf(of,"  cblock  0X%04X\t; Access Bank\n",start);
416         else
417           fprintf(of,"  cblock  0X%04X\t; Bank %d\n",start,pic16_finalMapping[start].bank);
418
419         for( ; start < addr; start++) {
420           if((pic16_finalMapping[start].reg) && !pic16_finalMapping[start].reg->isEmitted ) {
421             fprintf(of,"\t%s",pic16_finalMapping[start].reg->name);
422
423             /* If this register is aliased in multiple banks, then
424              * mangle the variable name with the alias address: */
425             if(pic16_finalMapping[start].alias & start)
426               fprintf(of,"_%x",bank_base);
427
428             if(pic16_finalMapping[start].instance)
429               fprintf(of,"_%d",pic16_finalMapping[start].instance);
430
431             
432             fputc('\n',of);
433
434 //#warning why is the following line commented out?! (VR)
435 //          pic16_finalMapping[start].reg->isEmitted = 1;
436           }
437         }
438
439         fprintf(of,"  endc\n");
440
441         start = -1;
442       }
443
444     }
445
446     addr++;
447
448   } while(addr <= pic->maxRAMaddress);
449   
450
451 }
452
453 /*-----------------------------------------------------------------*
454  *  void pic16_list_valid_pics(int ncols, int list_alias)
455  *
456  * Print out a formatted list of valid PIC devices
457  *
458  * ncols - number of columns in the list.
459  *
460  * list_alias - if non-zero, print all of the supported aliases
461  *              for a device (e.g. F84, 16F84, etc...)
462  *-----------------------------------------------------------------*/
463 void pic16_list_valid_pics(int ncols, int list_alias)
464 {
465   int col,longest;
466   int i,j,k,l;
467
468   if(list_alias)
469     list_alias = sizeof(Pics[0].name) / sizeof(Pics[0].name[0]);
470
471   /* decrement the column number if it's greater than zero */
472   ncols = (ncols > 1) ? ncols-1 : 4;
473
474   /* Find the device with the longest name */
475   for(i=0,longest=0; i<num_of_supported_PICS; i++) {
476     for(j=0; j<=list_alias; j++) {
477       k = strlen(Pics[i].name[j]);
478       if(k>longest)
479         longest = k;
480     }
481   }
482
483   col = 0;
484
485   for(i=0;  i < num_of_supported_PICS; i++) {
486     j = 0;
487     do {
488
489       fprintf(stderr,"%s", Pics[i].name[j]);
490       if(col<ncols) {
491         l = longest + 2 - strlen(Pics[i].name[j]);
492         for(k=0; k<l; k++)
493           fputc(' ',stderr);
494
495         col++;
496
497       } else {
498         fputc('\n',stderr);
499         col = 0;
500       }
501
502     } while(++j<list_alias);
503
504   }
505   if(col != ncols)
506     fputc('\n',stderr);
507
508 }
509
510 /*-----------------------------------------------------------------*
511  *  
512  *-----------------------------------------------------------------*/
513 PIC_device *pic16_find_device(char *name)
514 {
515
516   int i,j;
517
518   if(!name)
519     return NULL;
520
521   for(i = 0; i<num_of_supported_PICS; i++) {
522
523     for(j=0; j<PROCESSOR_NAMES; j++)
524       if(!STRCASECMP(Pics[i].name[j], name) )
525         return &Pics[i];
526   }
527
528   /* not found */
529   return NULL; 
530 }
531
532 /*-----------------------------------------------------------------*
533  *  
534  *-----------------------------------------------------------------*/
535 void pic16_init_pic(char *pic_type)
536 {
537   pic = pic16_find_device(pic_type);
538
539   if(!pic) {
540     if(pic_type)
541       fprintf(stderr, "'%s' was not found.\n", pic_type);
542     else
543       fprintf(stderr, "No processor has been specified (use -pPROCESSOR_NAME)\n");
544
545     fprintf(stderr,"Valid devices are:\n");
546
547     pic16_list_valid_pics(4,0);
548     exit(1);
549   }
550
551   pic->maxRAMaddress = -1;
552 }
553
554 /*-----------------------------------------------------------------*
555  *  
556  *-----------------------------------------------------------------*/
557 int pic16_picIsInitialized(void)
558 {
559   if(pic && pic->maxRAMaddress > 0)
560     return 1;
561
562   return 0;
563
564 }
565
566 /*-----------------------------------------------------------------*
567  *  char *pic16_processor_base_name(void) - Include file is derived from this.
568  *-----------------------------------------------------------------*/
569 char *pic16_processor_base_name(void)
570 {
571
572   if(!pic)
573     return NULL;
574
575   return pic->name[0];
576 }
577
578 static int isSFR(int address)
579 {
580
581   if( (address > pic->maxRAMaddress) || !pic16_finalMapping[address].isSFR)
582     return 0;
583
584   return 1;
585
586 }
587
588 /*-----------------------------------------------------------------*
589  *-----------------------------------------------------------------*/
590 static int validAddress(int address, int reg_size)
591 {
592   int i;
593
594   if (pic->maxRAMaddress < 0) {
595     fprintf(stderr, "missing \"#pragma maxram\" setting\n");
596     return 0;
597   }
598 //  fprintf(stderr, "validAddress: Checking 0x%04x (max=0x%04x) (reg_size = %d)\n",address, pic->maxRAMaddress, reg_size);
599   if(address > pic->maxRAMaddress)
600     return 0;
601
602   for (i=0; i<reg_size; i++)
603     if(!pic16_finalMapping[address + i].isValid || 
604        pic16_finalMapping[address+i].reg ||
605        pic16_finalMapping[address+i].isSFR )
606       return 0;
607
608   return 1;
609 }
610
611 /*-----------------------------------------------------------------*
612  *-----------------------------------------------------------------*/
613 static void mapRegister(regs *reg)
614 {
615
616   int i;
617   int alias;
618
619   if(!reg || !reg->size) {
620     fprintf(stderr,"WARNING: %s:%s:%d Bad register\n",__FILE__,__FUNCTION__,__LINE__);
621     return;
622   }
623
624   if (pic->maxRAMaddress < 0) {
625     fprintf(stderr, "missing \"#pragma maxram\" setting\n");
626     return;
627   }
628
629   for(i=0; i<reg->size; i++) {
630
631     alias = pic16_finalMapping[reg->address].alias;
632     reg->alias = alias;
633
634     do {
635
636 //      fprintf(stdout,"mapping %s to address 0x%02x, reg size = %d\n",reg->name, (reg->address+alias+i),reg->size);
637
638       pic16_finalMapping[reg->address + alias + i].reg = reg;
639       pic16_finalMapping[reg->address + alias + i].instance = i;
640
641       /* Decrement alias */
642       if(alias)
643         alias -= ((alias & (alias - 1)) ^ alias);
644       else
645         alias--;
646
647     } while (alias>=0);
648   }
649
650   //  fprintf(stderr,"%s - %s addr = 0x%03x, size %d\n",__FUNCTION__,reg->name, reg->address,reg->size);
651
652   reg->isMapped = 1;
653
654 }
655
656 /*-----------------------------------------------------------------*
657  *-----------------------------------------------------------------*/
658 static int assignRegister(regs *reg, int start_address)
659 {
660   int i;
661
662 //      fprintf(stderr,"%s -  %s start_address = 0x%03x\t(max=0x%03x)\n",__FUNCTION__,reg->name, start_address, pic->maxRAMaddress);
663   if(reg->isFixed) {
664
665     if (validAddress(reg->address,reg->size)) {
666 //      fprintf(stderr,"fixed %s -  %s address = 0x%03x\n",__FUNCTION__,reg->name, reg->address);
667       mapRegister(reg);
668       return reg->address;
669     }
670
671     if( isSFR(reg->address)) {
672 //      fprintf(stderr,"sfr %s -  %s address = 0x%03x\n",__FUNCTION__,reg->name, reg->address);
673       mapRegister(reg);
674       return reg->address;
675     }
676
677     //fprintf(stderr, "WARNING: Ignoring Out of Range register assignment at fixed address %d, %s\n",
678     //    reg->address, reg->name);
679
680   } else {
681
682     /* This register does not have a fixed address requirement
683      * so we'll search through all availble ram address and
684      * assign the first one */
685
686     for (i=start_address; i<=pic->maxRAMaddress; i++) {
687
688       if (validAddress(i,reg->size)) {
689 //      fprintf(stderr, "found valid address = 0x%04x\n", i);
690         reg->address = i;
691         mapRegister(reg);
692         return i;
693       }
694     }
695
696     fprintf(stderr, "WARNING: No more RAM available for %s\n",reg->name);
697
698   }
699
700   return -1;
701 }
702
703 /*-----------------------------------------------------------------*
704  *-----------------------------------------------------------------*/
705 void pic16_assignFixedRegisters(set *regset)
706 {
707   regs *reg;
708
709   for (reg = setFirstItem(regset) ; reg ; 
710        reg = setNextItem(regset)) {
711
712     if(reg->isFixed) 
713       assignRegister(reg,0);
714   }
715
716 }
717
718 /*-----------------------------------------------------------------*
719  *-----------------------------------------------------------------*/
720 void pic16_assignRelocatableRegisters(set *regset, int used)
721 {
722
723   regs *reg;
724   int address = 0;
725
726   for (reg = setFirstItem(regset) ; reg ; 
727        reg = setNextItem(regset)) {
728
729     //fprintf(stdout,"assigning %s isFixed=%d, wasUsed=%d\n",reg->name,reg->isFixed,reg->wasUsed);
730
731     if((!reg->isFixed) && (used || reg->wasUsed))
732       address = assignRegister(reg,address);
733
734   }
735
736 }
737
738
739 /*-----------------------------------------------------------------*
740  *  void pic16_assignConfigWordValue(int address, int value)
741  *
742  * All high performance RISC CPU PICs have seven config word starting
743  * at address 0x300000.
744  * This routine will assign a value to that address.
745  *
746  *-----------------------------------------------------------------*/
747
748 void pic16_assignConfigWordValue(int address, int value)
749 {
750   switch(address) {
751   case CONFIG1H_WORD_ADDRESS:
752     config1h_word = value;
753     break;
754   case CONFIG2L_WORD_ADDRESS:
755     config2l_word = value;
756     break;
757   case CONFIG2H_WORD_ADDRESS:
758     config2h_word = value;
759     break;
760   case CONFIG3H_WORD_ADDRESS:
761     config3h_word = value;
762     break;
763   case CONFIG4L_WORD_ADDRESS:
764     config4l_word = value;
765     break;
766   case CONFIG5L_WORD_ADDRESS:
767     config5l_word = value;
768     break;
769   case CONFIG5H_WORD_ADDRESS:
770     config5h_word = value;
771     break;
772   case CONFIG6L_WORD_ADDRESS:
773     config6l_word = value;
774     break;
775   case CONFIG6H_WORD_ADDRESS:
776     config6h_word = value;
777     break;
778   case CONFIG7L_WORD_ADDRESS:
779     config7l_word = value;
780     break;
781   case CONFIG7H_WORD_ADDRESS:
782     config7h_word = value;
783     break;
784   }
785
786   //fprintf(stderr,"setting config word to 0x%x\n",value);
787
788 }
789 /*-----------------------------------------------------------------*
790  * int pic16_getConfigWord(int address)
791  *
792  * Get the current value of the config word.
793  *
794  *-----------------------------------------------------------------*/
795
796 int pic16_getConfigWord(int address)
797 {
798   switch(address) {
799   case CONFIG1H_WORD_ADDRESS:
800     return config1h_word;
801   case CONFIG2L_WORD_ADDRESS:
802     return config2l_word;
803   case CONFIG2H_WORD_ADDRESS:
804     return config2h_word;
805   case CONFIG3H_WORD_ADDRESS:
806     return config3h_word;
807   case CONFIG4L_WORD_ADDRESS:
808     return config4l_word;
809   case CONFIG5L_WORD_ADDRESS:
810     return config5l_word;
811   case CONFIG5H_WORD_ADDRESS:
812     return config5h_word;
813   case CONFIG6L_WORD_ADDRESS:
814     return config6l_word;
815   case CONFIG6H_WORD_ADDRESS:
816     return config6h_word;
817   case CONFIG7L_WORD_ADDRESS:
818     return config7l_word;
819   case CONFIG7H_WORD_ADDRESS:
820     return config7h_word;
821   default:
822     return 0;
823   }
824 }
825