1 /*-------------------------------------------------------------------------
3 device.c - Accomodates subtle variations in PIC16 devices
5 Written By - Scott Dattalo scott@dattalo.com
6 Ported to PIC16 By - Martin Dubuc m.dubuc@rogers.com
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
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.
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 -------------------------------------------------------------------------*/
25 VR - Began writing code to make PIC16 C source files independent from
26 the header file (created by the inc2h.pl)
28 - adding maximum RAM memory into PIC_Device structure
34 #include "common.h" // Include everything in the SDCC src directory
43 static PIC16_device Pics16[] = {
45 // {"p18f242", "18f242", "pic18f242", "f242"}, // aliases
49 // { 0xf80, 0xfff }, /* PIC18F242 range of SFR's */
51 // /* PIC18F242 configuration words */
54 // { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
55 // { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
56 // { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
57 // { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
58 // { 0x40, 0, 0xff } /* d */ }
63 {"p18f242", "18f242", "pic18f242", "f242"},
68 { 0xf80, 0xfff }, /* PIC18F242 range of SFR's */
70 /* PIC18F242 configuration words */
73 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
74 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
75 { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
76 { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
77 { 0x40, 0, 0xff } /* d */ }
81 {"p18f248", "18f248", "pic18f248", "f248"},
86 { 0xf00, 0xfff }, /* PIC18F248 range of SFR's */
88 /* PIC18F248 configuration words */
91 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
92 { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
93 { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
94 { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
95 { 0x40, 0, 0xff } /* d */ }
99 {"p18f252", "18f252", "pic18f252", "f252"},
104 { 0xf80, 0xfff }, /* PIC18F252 range of SFR's */
106 /* PIC18F252 configuration words */
109 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
110 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
111 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
112 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
113 { 0x40, 0, 0xff } /* d */ }
117 {"p18f258", "18f258", "pic18f258", "f258"},
122 { 0xf00, 0xfff }, /* PIC18F258 range of SFR's */
124 /* PIC18F258 configuration words */
127 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
128 { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
129 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
130 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
131 { 0x40, 0, 0xff } /* d */ }
135 {"p18f442", "18f442", "pic18f442", "f442"},
140 { 0xf80, 0xfff }, /* PIC18F442 range of SFR's */
142 /* PIC18F442 configuration words */
145 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
146 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
147 { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
148 { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
149 { 0x40, 0, 0xff } /* d */ }
153 {"p18f448", "18f448", "pic18f448", "f448"},
158 { 0xf00, 0xfff }, /* PIC18F448 range of SFR's */
160 /* PIC18F448 configuration words */
163 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
164 { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
165 { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
166 { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
167 { 0x40, 0, 0xff } /* d */ }
171 {"p18f452", "18f452", "pic18f452", "f452"},
176 { 0xf80, 0xfff }, /* PIC18F452 range of SFR's */
178 /* PIC18F452 configuration words */
181 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
182 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
183 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
184 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
185 { 0x40, 0, 0xff } /* d */ }
189 {"p18f458", "18f458", "pic18f458", "f458"},
194 { 0xf00, 0xfff }, /* PIC18F458 range of SFR's */
196 /* PIC18F458 configuration words */
199 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
200 { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
201 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
202 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
203 { 0x40, 0, 0xff } /* d */ }
207 {"p18f1220", "18f1220", "pic18f1220", "f1220"},
212 { 0xf80, 0xfff }, /* PIC18F1220 range of SFR's */
214 /* PIC18F1220 configuration words */
217 { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
218 { -1, 0, 0xff } /* 4 */ , { 0x80, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
219 { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
220 { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
221 { 0x40, 0, 0xff } /* d */ }
225 {"p18f6520", "18f6520", "pic18f6520", "f6520"},
230 { 0xf6b, 0xfff }, /* PIC18F6520 range of SFR's */
232 /* PIC18F6520 configuration words */
235 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
236 { 0x80, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 0, 0xff } /* 6 */ ,
237 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
238 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
239 { 0x40, 0, 0xff } /* d */ }
243 {"p18f6620", "18f6620", "pic18f6620", "f6620"},
248 { 0xf6b, 0xfff }, /* PIC18F6620 range of SFR's */
250 /* PIC18F6620 configuration words */
253 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
254 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
255 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
256 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
257 { 0x40, 0, 0xff } /* d */ }
261 {"p18f6680", "18f6680", "pic18f6680", "f6680"},
266 { 0xf00, 0xfff }, /* PIC18F6680 range of SFR's */
268 /* PIC18F6680 configuration words */
271 { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
272 { -1, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
273 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
274 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
275 { 0x40, 0, 0xff } /* d */ }
279 {"p18f6720", "18f6720", "pic18f6720", "f6720"},
284 { 0xf6b, 0xfff }, /* PIC18F6720 range of SFR's */
286 /* PIC18F6720 configuration words */
289 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
290 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
291 { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
292 { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
293 { 0x40, 0, 0xff } /* d */ }
297 {"p18f8520", "18f8520", "pic18f8520", "f8520"},
302 { 0xf6b, 0xfff }, /* PIC18F8520 range of SFR's */
304 /* PIC18F8520 configuration words */
307 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
308 { 0x83, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 0, 0xff } /* 6 */ ,
309 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
310 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
311 { 0x40, 0, 0xff } /* d */ }
315 {"p18f8620", "18f8620", "pic18f8620", "f8620"},
320 { 0xf6b, 0xfff }, /* PIC18F8620 range of SFR's */
322 /* PIC18F8620 configuration words */
325 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
326 { 0x83, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
327 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
328 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
329 { 0x40, 0, 0xff } /* d */ }
333 {"p18f8680", "18f8680", "pic18f8680", "f8680"},
338 { 0xf00, 0xfff }, /* PIC18F8680 range of SFR's */
340 /* PIC18F8680 configuration words */
343 { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
344 { 0x83, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
345 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
346 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
347 { 0x40, 0, 0xff } /* d */ }
351 {"p18f8720", "18f8720", "pic18f8720", "f8720"},
356 { 0xf6b, 0xfff }, /* PIC18F8720 range of SFR's */
358 /* PIC18F8720 configuration words */
361 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
362 { 0x83, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
363 { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
364 { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
365 { 0x40, 0, 0xff } /* d */ }
371 static int num_of_supported_PICS = sizeof(Pics16)/sizeof(PIC16_device);
373 #define DEFAULT_PIC "452"
375 PIC16_device *pic16=NULL;
376 unsigned int stackPos = 0;
378 extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
380 void pic16_setMaxRAM(int size)
382 pic16->maxRAMaddress = size;
383 stackPos = pic16->RAMsize-1;
385 if (pic16->maxRAMaddress < 0) {
386 fprintf(stderr, "invalid \"#pragma maxram 0x%x\" setting\n",
387 pic16->maxRAMaddress);
392 extern char *iComments2;
394 void pic16_dump_equates(FILE *of, set *equs)
398 r = setFirstItem(equs);
401 fprintf(of, "%s", iComments2);
402 fprintf(of, ";\tEquates to used internal registers\n");
403 fprintf(of, "%s", iComments2);
405 for(; r; r = setNextItem(equs)) {
406 fprintf(of, "%s\tequ\t0x%02x\n", r->name, r->address);
411 int regCompare(const void *a, const void *b)
413 const regs *const *i = a;
414 const regs *const *j = b;
416 /* sort primarily by the address */
417 if( (*i)->address > (*j)->address)return 1;
418 if( (*i)->address < (*j)->address)return -1;
420 /* and secondarily by size */
421 /* register size sorting may have strange results use with care */
422 if( (*i)->size > (*j)->size)return 1;
423 if( (*i)->size < (*j)->size)return -1;
425 /* finally if in same address and same size sort by name */
426 return (strcmp( (*i)->name, (*j)->name));
431 int symCompare(const void *a, const void *b)
433 const symbol *const *i = a;
434 const symbol *const *j = b;
436 /* sort primarily by the address */
437 if( SPEC_ADDR((*i)->etype) > SPEC_ADDR((*j)->etype))return 1;
438 if( SPEC_ADDR((*i)->etype) < SPEC_ADDR((*j)->etype))return -1;
440 /* and secondarily by size */
441 /* register size sorting may have strange results use with care */
442 if( getSize((*i)->etype) > getSize((*j)->etype))return 1;
443 if( getSize((*i)->etype) < getSize((*j)->etype))return -1;
445 /* finally if in same address and same size sort by name */
446 return (strcmp( (*i)->rname, (*j)->rname));
451 void pic16_dump_usection(FILE *of, set *section, int fix)
453 static int abs_usection_no=0;
459 /* put all symbols in an array */
460 rlist = Safe_calloc(elementsInSet(section), sizeof(regs *));
462 for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) {
463 rlist[i] = rprev; i++;
467 if(rlist)free(rlist);
471 /* sort symbols according to their address */
472 qsort(rlist, i /*elementsInSet(section)*/, sizeof(regs *), regCompare);
475 fprintf(of, "\n\n\tudata\n");
476 for(r = setFirstItem(section); r; r = setNextItem(section)) {
477 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
484 init_addr = rlist[j]->address;
485 deb_addr = init_addr;
486 fprintf(of, "\n\nustat_%s_%02d\tudata\t0X%04X\n", moduleName, abs_usection_no++, init_addr);
490 if(j < i-1)r1 = rlist[j+1]; else r1 = NULL;
492 init_addr = r->address;
493 deb_addr = init_addr;
495 if((rprev && (init_addr > (rprev->address + rprev->size)))) {
496 fprintf(of, "\n\nustat_%s_%02d\tudata\t0X%04X\n", moduleName, abs_usection_no++, init_addr);
499 if(r1 && (init_addr == r1->address)) {
500 fprintf(of, "\n%s\tres\t0\n", r->name);
502 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
513 /* forward declaration */
514 void pic16_printIval(symbol * sym, sym_link * type, initList * ilist, char ptype, void *p);
516 void pic16_dump_isection(FILE *of, set *section, int fix)
518 static int abs_isection_no=0;
523 /* put all symbols in an array */
524 slist = Safe_calloc(elementsInSet(section), sizeof(symbol *));
526 for(sprev = setFirstItem(section); sprev; sprev = setNextItem(section)) {
527 slist[i] = sprev; i++;
531 if(slist)free(slist);
535 /* sort symbols according to their address */
536 qsort(slist, i, sizeof(symbol *), symCompare);
541 fprintf(of, "\n\n\tidata\n");
542 for(s = setFirstItem(section); s; s = setNextItem(section)) {
543 fprintf(of, "%s", s->rname);
544 pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
545 pic16_flushDB('f', (void *)of);
552 init_addr = SPEC_ADDR(slist[j]->etype);
553 fprintf(of, "\n\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
557 if(j < i-1)s1 = slist[j+1]; else s1 = NULL;
559 init_addr = SPEC_ADDR(s->etype);
561 if(sprev && (init_addr > (SPEC_ADDR(sprev->etype) + getSize(sprev->etype)))) {
562 fprintf(of, "\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
565 fprintf(of, "%s", s->rname);
566 pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
567 pic16_flushDB('f', (void *)of);
576 void pic16_dump_int_registers(FILE *of, set *section)
582 /* put all symbols in an array */
583 rlist = Safe_calloc(elementsInSet(section), sizeof(regs *));
585 for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) {
586 rlist[i] = rprev; i++;
589 /* sort symbols according to their address */
590 qsort(rlist, elementsInSet(section), sizeof(regs *), regCompare);
593 if(rlist)free(rlist);
597 fprintf(of, "\n\n; Internal registers\n");
599 fprintf(of, "%s\tudata_ovr\t0x0000\n", ".registers");
600 for(r = setFirstItem(section); r; r = setNextItem(section))
601 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
607 #ifdef WORDS_BIGENDIAN
608 #define _ENDIAN(x) (3-x)
610 #define _ENDIAN(x) (x)
613 #define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff)
616 /*-----------------------------------------------------------------*
617 * void pic16_list_valid_pics(int ncols, int list_alias)
619 * Print out a formatted list of valid PIC devices
621 * ncols - number of columns in the list.
623 * list_alias - if non-zero, print all of the supported aliases
624 * for a device (e.g. F84, 16F84, etc...)
625 *-----------------------------------------------------------------*/
626 void pic16_list_valid_pics(int ncols, int list_alias)
632 list_alias = sizeof(Pics16[0].name) / sizeof(Pics16[0].name[0]);
634 /* decrement the column number if it's greater than zero */
635 ncols = (ncols > 1) ? ncols-1 : 4;
637 /* Find the device with the longest name */
638 for(i=0,longest=0; i<num_of_supported_PICS; i++) {
639 for(j=0; j<=list_alias; j++) {
640 k = strlen(Pics16[i].name[j]);
648 for(i=0; i < num_of_supported_PICS; i++) {
652 fprintf(stderr,"%s", Pics16[i].name[j]);
654 l = longest + 2 - strlen(Pics16[i].name[j]);
665 } while(++j<list_alias);
673 /*-----------------------------------------------------------------*
675 *-----------------------------------------------------------------*/
676 PIC16_device *pic16_find_device(char *name)
684 for(i = 0; i<num_of_supported_PICS; i++) {
686 for(j=0; j<PROCESSOR_NAMES; j++)
687 if(!STRCASECMP(Pics16[i].name[j], name) )
695 /*-----------------------------------------------------------------*
697 *-----------------------------------------------------------------*/
698 void pic16_init_pic(char *pic_type)
700 pic16 = pic16_find_device(pic_type);
704 fprintf(stderr, "'%s' was not found.\n", pic_type);
706 fprintf(stderr, "No processor has been specified (use -pPROCESSOR_NAME)\n");
708 fprintf(stderr,"Valid devices are:\n");
710 pic16_list_valid_pics(4,0);
714 // printf("PIC processor found and initialized: %s\n", pic_type);
715 pic16_setMaxRAM( 0xfff );
718 /*-----------------------------------------------------------------*
720 *-----------------------------------------------------------------*/
721 int pic16_picIsInitialized(void)
723 if(pic16 && pic16->maxRAMaddress > 0)
730 /*-----------------------------------------------------------------*
731 * char *pic16_processor_base_name(void) - Include file is derived from this.
732 *-----------------------------------------------------------------*/
733 char *pic16_processor_base_name(void)
739 return pic16->name[0];
742 #define DEBUG_CHECK 0
745 * return 1 if register wasn't found and added, 0 otherwise
747 int checkAddReg(set **set, regs *reg)
752 fprintf(stderr, "%s: about to insert REGister: %s ... ", __FUNCTION__, reg->name);
755 for(tmp = setFirstItem(*set); tmp; tmp = setNextItem(*set)) {
756 if(!strcmp(tmp->name, reg->name))break;
762 fprintf(stderr, "added\n");
768 fprintf(stderr, "already added\n");
773 int checkAddSym(set **set, symbol *sym)
778 fprintf(stderr, "%s: about to add SYMbol: %s ... ", __FUNCTION__, sym->name);
781 for(tmp = setFirstItem( *set ); tmp; tmp = setNextItem(*set)) {
782 if(!strcmp(tmp->name, sym->name))break;
788 fprintf(stderr, "added\n");
794 fprintf(stderr, "already added\n");
801 /*-----------------------------------------------------------------*
802 * void pic16_groupRegistersInSection - add each register to its *
803 * corresponding section *
804 *-----------------------------------------------------------------*/
805 void pic16_groupRegistersInSection(set *regset)
809 for(reg=setFirstItem(regset); reg; reg = setNextItem(regset)) {
811 // fprintf(stderr, "%s:%d group registers in section, reg: %s\n", __FILE__, __LINE__, reg->name);
814 && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop)))) {
816 /* avoid grouping registers that have an initial value,
817 * they will be added later in idataSymSet */
818 if(reg->regop && (OP_SYMBOL(reg->regop)->ival && !OP_SYMBOL(reg->regop)->level))
822 fprintf(stderr, "%s:%d register %s alias:%d fix:%d ival=%i level=%i\n",
823 __FILE__, __LINE__, reg->name, reg->alias, reg->isFixed,
824 (reg->regop?(OP_SYMBOL(reg->regop)->ival?1:0):-1),
825 (reg->regop?(OP_SYMBOL(reg->regop)->level):-1) );
828 if(reg->alias == 0x80) {
829 checkAddReg(&pic16_equ_data, reg);
832 checkAddReg(&pic16_fix_udata, reg);
835 if(reg->pc_type == PO_GPR_TEMP)
836 checkAddReg(&pic16_int_regs, reg);
838 checkAddReg(&pic16_rel_udata, reg);
848 /*-----------------------------------------------------------------*
849 * void pic16_assignConfigWordValue(int address, int value)
851 * All high performance RISC CPU PICs have seven config word starting
852 * at address 0x300000.
853 * This routine will assign a value to that address.
855 *-----------------------------------------------------------------*/
856 void pic16_assignConfigWordValue(int address, int value)
860 for(i=0;i<pic16->cwInfo.confAddrEnd-pic16->cwInfo.confAddrStart+1;i++) {
861 if((address == pic16->cwInfo.confAddrStart+i)
862 && (pic16->cwInfo.crInfo[i].mask != -1)) {
863 // fprintf(stderr, "setting location 0x%X to value 0x%x\n", /*address*/ pic16->cwInfo.confAddrStart+i, val
864 pic16->cwInfo.crInfo[i].value = value;
865 pic16->cwInfo.crInfo[i].emit = 1;