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
44 static PIC16_device Pics16[] = {
46 // {"p18f242", "18f242", "pic18f242", "f242", "18F242"}, // aliases
50 // { 0xf80, 0xfff }, /* PIC18F242 range of SFR's */
52 // /* PIC18F242 configuration words */
55 // { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
56 // { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
57 // { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
58 // { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
59 // { 0x40, 0, 0xff } /* d */ }
64 {"p18f242", "18f242", "pic18f242", "f242"},
69 { 0xf80, 0xfff }, /* PIC18F242 range of SFR's */
71 /* PIC18F242 configuration words */
74 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
75 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
76 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
77 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
78 { 0x40, 0, 0xff } /* d */ }
81 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
82 { 0, 0 }, { 0, 0 }, { 0, 0 } }
86 {"p18f248", "18f248", "pic18f248", "f248"},
91 { 0xf00, 0xfff }, /* PIC18F248 range of SFR's */
93 /* PIC18F248 configuration words */
96 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
97 { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
98 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
99 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
100 { 0x40, 0, 0xff } /* d */ }
102 { 0x200000, 0x200007,
103 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
104 { 0, 0 }, { 0, 0 }, { 0, 0 } }
108 {"p18f252", "18f252", "pic18f252", "f252"},
113 { 0xf80, 0xfff }, /* PIC18F252 range of SFR's */
115 /* PIC18F252 configuration words */
118 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
119 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
120 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
121 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
122 { 0x40, 0, 0xff } /* d */ }
124 { 0x200000, 0x200007,
125 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
126 { 0, 0 }, { 0, 0 }, { 0, 0 } }
130 {"p18f258", "18f258", "pic18f258", "f258"},
135 { 0xf00, 0xfff }, /* PIC18F258 range of SFR's */
137 /* PIC18F258 configuration words */
140 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
141 { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
142 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
143 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
144 { 0x40, 0, 0xff } /* d */ }
146 { 0x200000, 0x200007,
147 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
148 { 0, 0 }, { 0, 0 }, { 0, 0 } }
152 {"p18f442", "18f442", "pic18f442", "f442"},
157 { 0xf80, 0xfff }, /* PIC18F442 range of SFR's */
159 /* PIC18F442 configuration words */
162 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
163 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
164 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
165 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
166 { 0x40, 0, 0xff } /* d */ }
168 { 0x200000, 0x200007,
169 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
170 { 0, 0 }, { 0, 0 }, { 0, 0 } }
174 {"p18f448", "18f448", "pic18f448", "f448"},
179 { 0xf00, 0xfff }, /* PIC18F448 range of SFR's */
181 /* PIC18F448 configuration words */
184 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
185 { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
186 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
187 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
188 { 0x40, 0, 0xff } /* d */ }
190 { 0x200000, 0x200007,
191 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
192 { 0, 0 }, { 0, 0 }, { 0, 0 } }
196 {"p18f452", "18f452", "pic18f452", "f452"},
201 { 0xf80, 0xfff }, /* PIC18F452 range of SFR's */
203 /* PIC18F452 configuration words */
206 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
207 { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
208 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
209 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
210 { 0x40, 0, 0xff } /* d */ }
212 { 0x200000, 0x200007,
213 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
214 { 0, 0 }, { 0, 0 }, { 0, 0 } }
218 {"p18f458", "18f458", "pic18f458", "f458"},
223 { 0xf00, 0xfff }, /* PIC18F458 range of SFR's */
225 /* PIC18F458 configuration words */
228 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
229 { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
230 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
231 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
232 { 0x40, 0, 0xff } /* d */ }
234 { 0x200000, 0x200007,
235 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
236 { 0, 0 }, { 0, 0 }, { 0, 0 } }
240 {"p18f1220", "18f1220", "pic18f1220", "f1220"},
245 { 0xf80, 0xfff }, /* PIC18F1220 range of SFR's */
247 /* PIC18F1220 configuration words */
250 { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
251 { -1, 0, 0xff } /* 4 */ , { 0x80, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
252 { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
253 { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
254 { 0x40, 0, 0xff } /* d */ }
256 { 0x200000, 0x200007,
257 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
258 { 0, 0 }, { 0, 0 }, { 0, 0 } }
262 {"p18f2220", "18f2220", "pic18f2220", "f2220"},
267 { 0xf80, 0xfff }, /* PIC18F2220 range of SFR's */
269 /* PIC18F2220 configuration words */
272 { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
273 { -1, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
274 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
275 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
276 { 0x40, 0, 0xff } /* d */ }
278 { 0x200000, 0x200007,
279 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
280 { 0, 0 }, { 0, 0 }, { 0, 0 } }
284 {"p18f2320", "18f2320", "pic18f2320", "f2320"},
289 { 0xf80, 0xfff }, /* PIC18F2320 range of SFR's */
291 /* PIC18F2320 configuration words */
294 { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
295 { -1, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
296 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
297 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
298 { 0x40, 0, 0xff } /* d */ }
300 { 0x200000, 0x200007,
301 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
302 { 0, 0 }, { 0, 0 }, { 0, 0 } }
306 {"p18f2455", "18f2455", "pic18f2455", "f2455"},
311 { 0xf62, 0xfff }, /* PIC18F2455 range of SFR's */
313 /* PIC18F2455 configuration words */
316 { { 0x3f, 0, 0xff } /* 0 */ , { 0xcf, 0, 0xff } /* 1 */ , { 0x3f, 0, 0xff } /* 2 */ ,
317 { 0x1f, 0, 0xff } /* 3 */ , { -1, 0, 0xff } /* 4 */ , { 0x87, 0, 0xff } /* 5 */ ,
318 { 0xe5, 0, 0xff } /* 6 */ , { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ ,
319 { 0xc0, 0, 0xff } /* 9 */ , { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ ,
320 { 0x0f, 0, 0xff } /* c */ , { 0x40, 0, 0xff } /* d */ }
322 { 0x200000, 0x200007,
323 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
324 { 0, 0 }, { 0, 0 }, { 0, 0 } }
328 {"p18f2550", "18f2550", "pic18f2550", "f2550"},
333 { 0xf62, 0xfff }, /* PIC18F2550 range of SFR's */
335 /* PIC18F2550 configuration words */
338 { { 0x3f, 0, 0xff } /* 0 */ , { 0xcf, 0, 0xff } /* 1 */ , { 0x3f, 0, 0xff } /* 2 */ ,
339 { 0x1f, 0, 0xff } /* 3 */ , { -1, 0, 0xff } /* 4 */ , { 0x87, 0, 0xff } /* 5 */ ,
340 { 0xe5, 0, 0xff } /* 6 */ , { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ ,
341 { 0xc0, 0, 0xff } /* 9 */ , { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ ,
342 { 0x0f, 0, 0xff } /* c */ , { 0x40, 0, 0xff } /* d */ }
344 { 0x200000, 0x200007,
345 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
346 { 0, 0 }, { 0, 0 }, { 0, 0 } }
350 {"p18f4220", "18f4220", "pic18f4220", "f4220"},
355 { 0xf80, 0xfff }, /* PIC18F4220 range of SFR's */
357 /* PIC18F4220 configuration words */
360 { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
361 { -1, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
362 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
363 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
364 { 0x40, 0, 0xff } /* d */ }
366 { 0x200000, 0x200007,
367 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
368 { 0, 0 }, { 0, 0 }, { 0, 0 } }
372 {"p18f4320", "18f4320", "pic18f4320", "f4320"},
377 { 0xf80, 0xfff }, /* PIC18F4320 range of SFR's */
379 /* PIC18F4320 configuration words */
382 { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
383 { -1, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
384 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
385 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
386 { 0x40, 0, 0xff } /* d */ }
388 { 0x200000, 0x200007,
389 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
390 { 0, 0 }, { 0, 0 }, { 0, 0 } }
394 {"p18f4331", "18f4331", "pic18f4331", "f4331"},
399 { 0xf60, 0xfff }, /* PIC18F4331 range of SFR's */
401 /* PIC18F4331 configuration words */
404 { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x3f, 0, 0xff } /* 3 */ ,
405 { 0x3c, 0, 0xff } /* 4 */ , { 0x9d, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
406 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
407 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
408 { 0x40, 0, 0xff } /* d */ }
410 { 0x200000, 0x200007,
411 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
412 { 0, 0 }, { 0, 0 }, { 0, 0 } }
416 {"p18f4455", "18f4455", "pic18f4455", "f4455"},
421 { 0xf62, 0xfff }, /* PIC18F4455 range of SFR's */
423 /* PIC18F4455 configuration words */
426 { { 0x3f, 0, 0xff } /* 0 */ , { 0xcf, 0, 0xff } /* 1 */ , { 0x3f, 0, 0xff } /* 2 */ ,
427 { 0x1f, 0, 0xff } /* 3 */ , { -1, 0, 0xff } /* 4 */ , { 0x87, 0, 0xff } /* 5 */ ,
428 { 0xe5, 0, 0xff } /* 6 */ , { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ ,
429 { 0xc0, 0, 0xff } /* 9 */ , { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ ,
430 { 0x0f, 0, 0xff } /* c */ , { 0x40, 0, 0xff } /* d */ }
432 { 0x200000, 0x200007,
433 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
434 { 0, 0 }, { 0, 0 }, { 0, 0 } }
438 {"p18f4520", "18f4520", "pic18f4520", "f4520"},
443 { 0xf80, 0xfff }, /* PIC18F4520 range of SFR's */
445 /* PIC18F4520 configuration words */
448 { { 0x3f, 0, 0xff } /* 0 */ , { 0xcf, 0, 0xff } /* 1 */ , { 0x1f, 0, 0xff } /* 2 */ ,
449 { 0x1f, 0, 0xff } /* 3 */ , { -1, 0, 0xff } /* 4 */ , { 0x87, 0, 0xff } /* 5 */ ,
450 { 0xc5, 0, 0xff } /* 6 */ , { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ ,
451 { 0xc0, 0, 0xff } /* 9 */ , { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ ,
452 { 0x0f, 0, 0xff } /* c */ , { 0x40, 0, 0xff } /* d */ }
454 { 0x200000, 0x200007,
455 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
456 { 0, 0 }, { 0, 0 }, { 0, 0 } }
460 {"p18f6520", "18f6520", "pic18f6520", "f6520"},
465 { 0xf6b, 0xfff }, /* PIC18F6520 range of SFR's */
467 /* PIC18F6520 configuration words */
470 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
471 { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
472 { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
473 { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
474 { 0x40, 0, 0xff } /* d */ }
476 { 0x200000, 0x200007,
477 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
478 { 0, 0 }, { 0, 0 }, { 0, 0 } }
482 {"p18f6620", "18f6620", "pic18f6620", "f6620"},
487 { 0xf6b, 0xfff }, /* PIC18F6620 range of SFR's */
489 /* PIC18F6620 configuration words */
492 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
493 { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
494 { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
495 { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
496 { 0x40, 0, 0xff } /* d */ }
498 { 0x200000, 0x200007,
499 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
500 { 0, 0 }, { 0, 0 }, { 0, 0 } }
504 {"p18f6680", "18f6680", "pic18f6680", "f6680"},
509 { 0xd60, 0xfff }, /* PIC18F6680 range of SFR's */
511 /* PIC18F6680 configuration words */
514 { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
515 { 0x83, 0, 0xff } /* 4 */ , { 0x81, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
516 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
517 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
518 { 0x40, 0, 0xff } /* d */ }
520 { 0x200000, 0x200007,
521 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
522 { 0, 0 }, { 0, 0 }, { 0, 0 } }
526 {"p18f6720", "18f6720", "pic18f6720", "f6720"},
531 { 0xf6b, 0xfff }, /* PIC18F6720 range of SFR's */
533 /* PIC18F6720 configuration words */
536 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
537 { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
538 { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
539 { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
540 { 0x40, 0, 0xff } /* d */ }
542 { 0x200000, 0x200007,
543 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
544 { 0, 0 }, { 0, 0 }, { 0, 0 } }
548 {"p18f8520", "18f8520", "pic18f8520", "f8520"},
553 { 0xf6b, 0xfff }, /* PIC18F8520 range of SFR's */
555 /* PIC18F8520 configuration words */
558 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
559 { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
560 { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
561 { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
562 { 0x40, 0, 0xff } /* d */ }
564 { 0x200000, 0x200007,
565 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
566 { 0, 0 }, { 0, 0 }, { 0, 0 } }
570 {"p18f8620", "18f8620", "pic18f8620", "f8620"},
575 { 0xf6b, 0xfff }, /* PIC18F8620 range of SFR's */
577 /* PIC18F8620 configuration words */
580 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
581 { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
582 { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
583 { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
584 { 0x40, 0, 0xff } /* d */ }
586 { 0x200000, 0x200007,
587 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
588 { 0, 0 }, { 0, 0 }, { 0, 0 } }
592 {"p18f8680", "18f8680", "pic18f8680", "f8680"},
597 { 0xd60, 0xfff }, /* PIC18F8680 range of SFR's */
599 /* PIC18F8680 configuration words */
602 { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
603 { 0x83, 0, 0xff } /* 4 */ , { 0x81, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
604 { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
605 { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
606 { 0x40, 0, 0xff } /* d */ }
608 { 0x200000, 0x200007,
609 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
610 { 0, 0 }, { 0, 0 }, { 0, 0 } }
614 {"p18f8720", "18f8720", "pic18f8720", "f8720"},
619 { 0xf6b, 0xfff }, /* PIC18F8720 range of SFR's */
621 /* PIC18F8720 configuration words */
624 { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
625 { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
626 { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
627 { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
628 { 0x40, 0, 0xff } /* d */ }
630 { 0x200000, 0x200007,
631 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
632 { 0, 0 }, { 0, 0 }, { 0, 0 } }
638 static int num_of_supported_PICS = sizeof(Pics16)/sizeof(PIC16_device);
640 stats_t statistics = { 0, 0, 0, 0 };
642 #define DEFAULT_PIC "452"
644 PIC16_device *pic16=NULL;
645 unsigned int stackPos = 0;
646 unsigned int stackLen = 0;
648 extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
650 void pic16_setMaxRAM(int size)
652 pic16->maxRAMaddress = size;
653 stackPos = pic16->RAMsize-1;
655 if (pic16->maxRAMaddress < 0) {
656 fprintf(stderr, "invalid \"#pragma maxram 0x%x\" setting\n",
657 pic16->maxRAMaddress);
662 extern char *iComments2;
664 void pic16_dump_equates(FILE *of, set *equs)
668 r = setFirstItem(equs);
671 fprintf(of, "%s", iComments2);
672 fprintf(of, ";\tEquates to used internal registers\n");
673 fprintf(of, "%s", iComments2);
675 for(; r; r = setNextItem(equs)) {
676 fprintf(of, "%s\tequ\t0x%02x\n", r->name, r->address);
681 void pic16_dump_access(FILE *of, set *section)
685 r = setFirstItem(section);
688 fprintf(of, "%s", iComments2);
689 fprintf(of, ";\tAccess bank symbols\n");
690 fprintf(of, "%s", iComments2);
692 fprintf(of, "\tudata_acs\n");
693 for(; r; r = setNextItem(section)) {
694 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
695 statistics.adsize += r->size;
700 int regCompare(const void *a, const void *b)
702 const regs *const *i = a;
703 const regs *const *j = b;
705 /* sort primarily by the address */
706 if( (*i)->address > (*j)->address)return 1;
707 if( (*i)->address < (*j)->address)return -1;
709 /* and secondarily by size */
710 /* register size sorting may have strange results use with care */
711 if( (*i)->size > (*j)->size)return 1;
712 if( (*i)->size < (*j)->size)return -1;
714 /* finally if in same address and same size sort by name */
715 return (strcmp( (*i)->name, (*j)->name));
720 int symCompare(const void *a, const void *b)
722 const symbol *const *i = a;
723 const symbol *const *j = b;
725 /* sort primarily by the address */
726 if( SPEC_ADDR((*i)->etype) > SPEC_ADDR((*j)->etype))return 1;
727 if( SPEC_ADDR((*i)->etype) < SPEC_ADDR((*j)->etype))return -1;
729 /* and secondarily by size */
730 /* register size sorting may have strange results use with care */
731 if( getSize((*i)->etype) > getSize((*j)->etype))return 1;
732 if( getSize((*i)->etype) < getSize((*j)->etype))return -1;
734 /* finally if in same address and same size sort by name */
735 return (strcmp( (*i)->rname, (*j)->rname));
740 void pic16_dump_usection(FILE *of, set *section, int fix)
742 static int abs_usection_no=0;
743 static unsigned int usection_no=0;
745 unsigned int init_addr, i;
749 /* put all symbols in an array */
750 if (!elementsInSet(section)) return;
751 rlist = Safe_calloc(elementsInSet(section), sizeof(regs *));
753 for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) {
754 rlist[i] = rprev; i++;
758 if(rlist)Safe_free(rlist);
762 /* sort symbols according to their address */
763 qsort(rlist, i /*elementsInSet(section)*/, sizeof(regs *), regCompare);
767 #define EMIT_SINGLE_UDATA_SECTION 0
768 #if EMIT_SINGLE_UDATA_SECTION
769 fprintf(of, "\n\n\tudata\n");
770 for(r = setFirstItem(section); r; r = setNextItem(section)) {
771 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
772 statistics.udsize += r->size;
775 for(r = setFirstItem(section); r; r = setNextItem(section)) {
776 //fprintf(of, "\nudata_%s_%s\tudata\n", moduleName, r->name);
777 fprintf(of, "\nudata_%s_%u\tudata\n", moduleName, usection_no++);
778 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
779 statistics.udsize += r->size;
787 init_addr = rlist[j]->address;
788 deb_addr = init_addr;
789 fprintf(of, "\n\nustat_%s_%02d\tudata\t0X%04X\n", moduleName, abs_usection_no++, init_addr);
793 if(j < i-1)r1 = rlist[j+1]; else r1 = NULL;
795 init_addr = r->address;
796 deb_addr = init_addr;
798 if((rprev && (init_addr > (rprev->address + rprev->size)))) {
799 fprintf(of, "\n\nustat_%s_%02d\tudata\t0X%04X\n", moduleName, abs_usection_no++, init_addr);
802 if(r1 && (init_addr == r1->address)) {
803 fprintf(of, "\n%s\tres\t0\n", r->name);
805 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
807 statistics.udsize += r->size;
816 void pic16_dump_gsection(FILE *of, set *sections)
821 for(sname = setFirstItem(sections); sname; sname = setNextItem(sections)) {
822 if(!strcmp(sname->name, "access"))continue;
823 fprintf(of, "\n\n%s\tudata\n", sname->name);
825 for(r=setFirstItem(sname->regsSet); r; r=setNextItem(sname->regsSet)) {
827 fprintf(stderr, "%s:%d emitting variable %s for section %s (%p)\n", __FILE__, __LINE__,
828 r->name, sname->name, sname);
830 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
831 statistics.udsize += r->size;
837 /* forward declaration */
838 void pic16_printIval(symbol * sym, sym_link * type, initList * ilist, char ptype, void *p);
839 extern void pic16_pCodeConstString(char *name, char *value);
841 void pic16_dump_isection(FILE *of, set *section, int fix)
843 static int abs_isection_no=0;
845 unsigned int init_addr, i;
848 /* put all symbols in an array */
849 if (!elementsInSet(section)) return;
850 slist = Safe_calloc(elementsInSet(section), sizeof(symbol *));
852 for(sprev = setFirstItem(section); sprev; sprev = setNextItem(section)) {
853 slist[i] = sprev; i++;
857 if(slist)Safe_free(slist);
861 /* sort symbols according to their address */
862 qsort(slist, i, sizeof(symbol *), symCompare);
867 fprintf(of, "\n\n\tidata\n");
868 for(s = setFirstItem(section); s; s = setNextItem(section)) {
871 fprintf(of, "%s", s->rname);
872 pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
873 pic16_flushDB('f', (void *)of);
875 if (IS_ARRAY (s->type) && IS_CHAR (s->type->next)
876 && SPEC_CVAL (s->etype).v_char) {
878 // fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname);
879 pic16_pCodeConstString(s->rname , SPEC_CVAL (s->etype).v_char);
891 init_addr = SPEC_ADDR(slist[j]->etype);
892 fprintf(of, "\n\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
896 if(j < i-1)s1 = slist[j+1]; else s1 = NULL;
898 init_addr = SPEC_ADDR(s->etype);
900 if(sprev && (init_addr > (SPEC_ADDR(sprev->etype) + getSize(sprev->etype)))) {
901 fprintf(of, "\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
905 fprintf(of, "%s", s->rname);
906 pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
907 pic16_flushDB('f', (void *)of);
909 if (IS_ARRAY (s->type) && IS_CHAR (s->type->next)
910 && SPEC_CVAL (s->etype).v_char) {
912 // fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname);
913 pic16_pCodeConstString(s->rname , SPEC_CVAL (s->etype).v_char);
927 void pic16_dump_int_registers(FILE *of, set *section)
933 /* put all symbols in an array */
934 if (!elementsInSet(section)) return;
935 rlist = Safe_calloc(elementsInSet(section), sizeof(regs *));
937 for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) {
938 rlist[i] = rprev; i++;
941 /* sort symbols according to their address */
942 qsort(rlist, elementsInSet(section), sizeof(regs *), regCompare);
945 if(rlist)Safe_free(rlist);
949 fprintf(of, "\n\n; Internal registers\n");
951 fprintf(of, "%s\tudata_ovr\t0x0000\n", ".registers");
952 for(r = setFirstItem(section); r; r = setNextItem(section)) {
953 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
954 statistics.intsize += r->size;
961 #ifdef WORDS_BIGENDIAN
962 #define _ENDIAN(x) (3-x)
964 #define _ENDIAN(x) (x)
967 #define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff)
970 /*-----------------------------------------------------------------*
971 * void pic16_list_valid_pics(int ncols, int list_alias)
973 * Print out a formatted list of valid PIC devices
975 * ncols - number of columns in the list.
977 * list_alias - if non-zero, print all of the supported aliases
978 * for a device (e.g. F84, 16F84, etc...)
979 *-----------------------------------------------------------------*/
980 void pic16_list_valid_pics(int ncols, int list_alias)
986 list_alias = sizeof(Pics16[0].name) / sizeof(Pics16[0].name[0]);
988 /* decrement the column number if it's greater than zero */
989 ncols = (ncols > 1) ? ncols-1 : 4;
991 /* Find the device with the longest name */
992 for(i=0,longest=0; i<num_of_supported_PICS; i++) {
993 for(j=0; j<=list_alias; j++) {
994 k = strlen(Pics16[i].name[j]);
1002 for(i=0; i < num_of_supported_PICS; i++) {
1006 fprintf(stderr,"%s", Pics16[i].name[j]);
1008 l = longest + 2 - strlen(Pics16[i].name[j]);
1019 } while(++j<list_alias);
1027 /*-----------------------------------------------------------------*
1029 *-----------------------------------------------------------------*/
1030 PIC16_device *pic16_find_device(char *name)
1038 for(i = 0; i<num_of_supported_PICS; i++) {
1040 for(j=0; j<PROCESSOR_NAMES; j++)
1041 if(!STRCASECMP(Pics16[i].name[j], name) )
1049 /*-----------------------------------------------------------------*
1051 *-----------------------------------------------------------------*/
1052 void pic16_init_pic(char *pic_type)
1054 pic16 = pic16_find_device(pic_type);
1058 fprintf(stderr, "'%s' was not found.\n", pic_type);
1060 fprintf(stderr, "No processor has been specified (use -pPROCESSOR_NAME)\n");
1062 fprintf(stderr,"Valid devices are:\n");
1064 pic16_list_valid_pics(4,0);
1068 // printf("PIC processor found and initialized: %s\n", pic_type);
1069 pic16_setMaxRAM( 0xfff );
1072 /*-----------------------------------------------------------------*
1074 *-----------------------------------------------------------------*/
1075 int pic16_picIsInitialized(void)
1077 if(pic16 && pic16->maxRAMaddress > 0)
1084 /*-----------------------------------------------------------------*
1085 * char *pic16_processor_base_name(void) - Include file is derived from this.
1086 *-----------------------------------------------------------------*/
1087 char *pic16_processor_base_name(void)
1093 return pic16->name[0];
1096 #define DEBUG_CHECK 0
1099 * return 1 if register wasn't found and added, 0 otherwise
1101 int checkAddReg(set **set, regs *reg)
1108 fprintf(stderr, "%s: about to insert REGister: %s ... ", __FUNCTION__, reg->name);
1111 for(tmp = setFirstItem(*set); tmp; tmp = setNextItem(*set)) {
1112 if(!strcmp(tmp->name, reg->name))break;
1118 fprintf(stderr, "added\n");
1124 fprintf(stderr, "already added\n");
1129 int checkAddSym(set **set, symbol *sym)
1135 fprintf(stderr, "%s: about to add SYMbol: %s ... ", __FUNCTION__, sym->name);
1138 for(tmp = setFirstItem( *set ); tmp; tmp = setNextItem(*set)) {
1139 if(!strcmp(tmp->name, sym->name))break;
1145 fprintf(stderr, "added\n");
1151 fprintf(stderr, "already added\n");
1157 int checkSym(set *set, symbol *sym)
1164 fprintf(stderr, "%s: about to search for SYMbol: %s ... ", __FUNCTION__, sym->name);
1167 for(tmp = setFirstItem( set ); tmp; tmp = setNextItem( set )) {
1168 if(!strcmp(tmp->name, sym->name))break;
1173 fprintf(stderr, "not found\n");
1179 fprintf(stderr, "found\n");
1185 /*-----------------------------------------------------------------*
1186 * void pic16_groupRegistersInSection - add each register to its *
1187 * corresponding section *
1188 *-----------------------------------------------------------------*/
1189 void pic16_groupRegistersInSection(set *regset)
1195 for(reg=setFirstItem(regset); reg; reg = setNextItem(regset)) {
1198 fprintf(stderr, "%s:%d group registers in section, reg: %s (used: %d, %p)\n",
1199 __FILE__, __LINE__, reg->name, reg->wasUsed, reg);
1202 && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop))))
1205 /* avoid grouping registers that have an initial value,
1206 * they will be added later in idataSymSet */
1207 if(reg->regop && (OP_SYMBOL(reg->regop)->ival && !OP_SYMBOL(reg->regop)->level))
1211 fprintf(stderr, "%s:%d register %s alias:%d fix:%d ival=%i level=%i code=%i\n",
1212 __FILE__, __LINE__, reg->name, reg->alias, reg->isFixed,
1213 (reg->regop?(OP_SYMBOL(reg->regop)->ival?1:0):-1),
1214 (reg->regop?(OP_SYMBOL(reg->regop)->level):-1),
1215 (reg->regop?(IS_CODE(OP_SYM_ETYPE(reg->regop))):-1) );
1219 for(ssym=setFirstItem(sectSyms);ssym;ssym=setNextItem(sectSyms)) {
1220 if(!strcmp(ssym->name, reg->name)) {
1221 // fprintf(stderr, "%s:%d section found %s (%p) with var %s\n",
1222 // __FILE__, __LINE__, ssym->section->name, ssym->section, ssym->name);
1223 if(strcmp(ssym->section->name, "access")) {
1224 addSet(&ssym->section->regsSet, reg);
1229 reg->accessBank = 1;
1235 if(docontinue)continue;
1237 // fprintf(stderr, "%s:%d reg: %s\n", __FILE__, __LINE__, reg->name);
1239 if(reg->alias == 0x80) {
1240 checkAddReg(&pic16_equ_data, reg);
1243 checkAddReg(&pic16_fix_udata, reg);
1246 if(reg->pc_type == PO_GPR_TEMP)
1247 checkAddReg(&pic16_int_regs, reg);
1249 if(reg->accessBank) {
1250 if(reg->alias != 0x40)
1251 checkAddReg(&pic16_acs_udata, reg);
1253 checkAddReg(&pic16_rel_udata, reg);
1264 /*-----------------------------------------------------------------*
1265 * void pic16_assignConfigWordValue(int address, int value)
1267 * All high performance RISC CPU PICs have seven config word starting
1268 * at address 0x300000.
1269 * This routine will assign a value to that address.
1271 *-----------------------------------------------------------------*/
1272 void pic16_assignConfigWordValue(int address, unsigned int value)
1276 for(i=0;i<pic16->cwInfo.confAddrEnd-pic16->cwInfo.confAddrStart+1;i++) {
1277 if((address == pic16->cwInfo.confAddrStart+i)
1278 && (pic16->cwInfo.crInfo[i].mask != -1)) {
1281 fprintf(stderr, "setting location 0x%X to value 0x%x\tmask: 0x%x\ttest: 0x%x\n",
1282 /*address*/ pic16->cwInfo.confAddrStart+i, (~value)&0xff,
1283 pic16->cwInfo.crInfo[i].mask,
1284 (pic16->cwInfo.crInfo[i].mask) & (~value));
1288 if((((pic16->cwInfo.crInfo[i].mask) & (~value))&0xff) != ((~value)&0xff)) {
1289 fprintf(stderr, "%s:%d a wrong value has been given for configuration register 0x%x\n",
1290 __FILE__, __LINE__, address);
1295 pic16->cwInfo.crInfo[i].value = value;
1296 pic16->cwInfo.crInfo[i].emit = 1;
1302 void pic16_assignIdByteValue(int address, char value)
1306 for(i=0;i<pic16->idInfo.idAddrEnd-pic16->idInfo.idAddrStart+1;i++) {
1307 if(address == pic16->idInfo.idAddrStart+i) {
1308 pic16->idInfo.irInfo[i].value = value;
1309 pic16->idInfo.irInfo[i].emit = 1;