#include "ralloc.h"
#include "device.h"
+stats_t statistics = { 0, 0, 0, 0 };
-static PIC16_device Pics16[] = {
-// {
-// {"p18f242", "18f242", "pic18f242", "f242", "18F242"}, // aliases
-// 0,
-// 0x300, // RAMsize
-// 0,
-// { 0xf80, 0xfff }, /* PIC18F242 range of SFR's */
-// {
-// /* PIC18F242 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 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
-// { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
-// { 0x40, 0, 0xff } /* d */ }
-// }
-// },
-
- {
- {"p18f242", "18f242", "pic18f242", "f242"},
- 0,
- 0x300, /* 768 */
- 0x80,
- 0,
- { 0xf80, 0xfff }, /* PIC18F242 range of SFR's */
- {
- /* PIC18F242 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f248", "18f248", "pic18f248", "f248"},
- 0,
- 0x300, /* 768 */
- 0x60,
- 0,
- { 0xf00, 0xfff }, /* PIC18F248 range of SFR's */
- {
- /* PIC18F248 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { -1, 0, 0xff } /* 4 */ , { -1, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f252", "18f252", "pic18f252", "f252"},
- 0,
- 0x600, /* 1536 */
- 0x80,
- 0,
- { 0xf80, 0xfff }, /* PIC18F252 range of SFR's */
- {
- /* PIC18F252 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f258", "18f258", "pic18f258", "f258"},
- 0,
- 0x600, /* 1536 */
- 0x60,
- 0,
- { 0xf00, 0xfff }, /* PIC18F258 range of SFR's */
- {
- /* PIC18F258 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { -1, 0, 0xff } /* 4 */ , { -1, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f442", "18f442", "pic18f442", "f442"},
- 0,
- 0x300, /* 768 */
- 0x80,
- 0,
- { 0xf80, 0xfff }, /* PIC18F442 range of SFR's */
- {
- /* PIC18F442 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f448", "18f448", "pic18f448", "f448"},
- 0,
- 0x300, /* 768 */
- 0x60,
- 0,
- { 0xf00, 0xfff }, /* PIC18F448 range of SFR's */
- {
- /* PIC18F448 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { -1, 0, 0xff } /* 4 */ , { -1, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f452", "18f452", "pic18f452", "f452"},
- 0,
- 0x600, /* 1536 */
- 0x80,
- 0,
- { 0xf80, 0xfff }, /* PIC18F452 range of SFR's */
- {
- /* PIC18F452 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f458", "18f458", "pic18f458", "f458"},
- 0,
- 0x600, /* 1536 */
- 0x60,
- 0,
- { 0xf00, 0xfff }, /* PIC18F458 range of SFR's */
- {
- /* PIC18F458 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { -1, 0, 0xff } /* 4 */ , { -1, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f1220", "18f1220", "pic18f1220", "f1220"},
- 0,
- 0x100, /* 256 */
- 0x80,
- 0,
- { 0xf80, 0xfff }, /* PIC18F1220 range of SFR's */
- {
- /* PIC18F1220 configuration words */
- 0x300001,
- 0x30000d,
- { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
- { -1, 0, 0xff } /* 4 */ , { 0x80, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
- { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
- { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
- { 0x40, 0, 0xff } /* d */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f2220", "18f2220", "pic18f2220", "f2220"},
- 0,
- 0x200, /* 512 */
- 0x80,
- 0,
- { 0xf80, 0xfff }, /* PIC18F2220 range of SFR's */
- {
- /* PIC18F2220 configuration words */
- 0x300001,
- 0x30000d,
- { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
- { -1, 0, 0xff } /* 4 */ , { 0x83, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f2455", "18f2455", "pic18f2455", "f2455"},
- 0,
- 0x800, /* 2048 */
- 0x60,
- 0,
- { 0xf62, 0xfff }, /* PIC18F2455 range of SFR's */
- {
- /* PIC18F2455 configuration words */
- 0x300000,
- 0x30000d,
- { { 0x3f, 0, 0xff } /* 0 */ , { 0xcf, 0, 0xff } /* 1 */ , { 0x3f, 0, 0xff } /* 2 */ ,
- { 0x1f, 0, 0xff } /* 3 */ , { -1, 0, 0xff } /* 4 */ , { 0x87, 0, 0xff } /* 5 */ ,
- { 0xe5, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f2550", "18f2550", "pic18f2550", "f2550"},
- 0,
- 0x800, /* 2048 */
- 0x60,
- 0,
- { 0xf62, 0xfff }, /* PIC18F2550 range of SFR's */
- {
- /* PIC18F2550 configuration words */
- 0x300000,
- 0x30000d,
- { { 0x3f, 0, 0xff } /* 0 */ , { 0xcf, 0, 0xff } /* 1 */ , { 0x3f, 0, 0xff } /* 2 */ ,
- { 0x1f, 0, 0xff } /* 3 */ , { -1, 0, 0xff } /* 4 */ , { 0x87, 0, 0xff } /* 5 */ ,
- { 0xe5, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f4331", "18f4331", "pic18f4331", "f4331"},
- 0,
- 0x300, /* 768 */
- 0x60,
- 0,
- { 0xf60, 0xfff }, /* PIC18F4331 range of SFR's */
- {
- /* PIC18F4331 configuration words */
- 0x300001,
- 0x30000d,
- { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x3f, 0, 0xff } /* 3 */ ,
- { 0x3c, 0, 0xff } /* 4 */ , { 0x9d, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f4455", "18f4455", "pic18f4455", "f4455"},
- 0,
- 0x800, /* 2048 */
- 0x60,
- 0,
- { 0xf62, 0xfff }, /* PIC18F4455 range of SFR's */
- {
- /* PIC18F4455 configuration words */
- 0x300000,
- 0x30000d,
- { { 0x3f, 0, 0xff } /* 0 */ , { 0xcf, 0, 0xff } /* 1 */ , { 0x3f, 0, 0xff } /* 2 */ ,
- { 0x1f, 0, 0xff } /* 3 */ , { -1, 0, 0xff } /* 4 */ , { 0x87, 0, 0xff } /* 5 */ ,
- { 0xe5, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f4520", "18f4520", "pic18f4520", "f4520"},
- 0,
- 0x1000, /* 4096 */
+#define DEVICE_FILE_NAME "pic16devices.txt"
+
+static PIC16_device default_device = {
+ { "p18f452", "18f452", "pic18f452", "f452" },
+ 0x600,
0x80,
- 0,
- { 0xf80, 0xfff }, /* PIC18F4520 range of SFR's */
- {
- /* PIC18F4520 configuration words */
- 0x300000,
- 0x30000d,
- { { 0x3f, 0, 0xff } /* 0 */ , { 0xcf, 0, 0xff } /* 1 */ , { 0x1f, 0, 0xff } /* 2 */ ,
- { 0x1f, 0, 0xff } /* 3 */ , { -1, 0, 0xff } /* 4 */ , { 0x87, 0, 0xff } /* 5 */ ,
- { 0xc5, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f6520", "18f6520", "pic18f6520", "f6520"},
- 0,
- 0x800, /* 2048 */
- 0x60,
- 0,
- { 0xf6b, 0xfff }, /* PIC18F6520 range of SFR's */
- {
- /* PIC18F6520 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
- { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
- { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
- { 0x40, 0, 0xff } /* d */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f6620", "18f6620", "pic18f6620", "f6620"},
- 0,
- 0xf00, /* 3840 */
- 0x60,
- 0,
- { 0xf6b, 0xfff }, /* PIC18F6620 range of SFR's */
- {
- /* PIC18F6620 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
- { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
- { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
- { 0x40, 0, 0xff } /* d */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f6680", "18f6680", "pic18f6680", "f6680"},
- 0,
- 0xf00, /* 3840 */
- 0x60,
- 0,
- { 0xd60, 0xfff }, /* PIC18F6680 range of SFR's */
- {
- /* PIC18F6680 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
- { 0x83, 0, 0xff } /* 4 */ , { 0x81, 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 */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f6720", "18f6720", "pic18f6720", "f6720"},
- 0,
- 0xf00, /* 3840 */
- 0x60,
- 0,
- { 0xf6b, 0xfff }, /* PIC18F6720 range of SFR's */
- {
- /* PIC18F6720 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
- { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
- { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
- { 0x40, 0, 0xff } /* d */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f8520", "18f8520", "pic18f8520", "f8520"},
- 0,
- 0x800, /* 2048 */
- 0x60,
- 1,
- { 0xf6b, 0xfff }, /* PIC18F8520 range of SFR's */
- {
- /* PIC18F8520 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
- { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
- { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
- { 0x40, 0, 0xff } /* d */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f8620", "18f8620", "pic18f8620", "f8620"},
- 0,
- 0xf00, /* 3840 */
- 0x60,
- 1,
- { 0xf6b, 0xfff }, /* PIC18F8620 range of SFR's */
- {
- /* PIC18F8620 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
- { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
- { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
- { 0x40, 0, 0xff } /* d */ }
- },
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f8680", "18f8680", "pic18f8680", "f8680"},
- 0,
- 0xf00, /* 3840 */
- 0x60,
- 1,
- { 0xd60, 0xfff }, /* PIC18F8680 range of SFR's */
- {
- /* PIC18F8680 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ ,
- { 0x83, 0, 0xff } /* 4 */ , { 0x81, 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 */ }
+ { 0xf80, 0xfff },
+ { /* 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 */ }
},
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { /* ID locations */
+ 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
{ 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- },
- {
- {"p18f8720", "18f8720", "pic18f8720", "f8720"},
- 0,
- 0xf00, /* 3840 */
- 0x60,
- 1,
- { 0xf6b, 0xfff }, /* PIC18F8720 range of SFR's */
- {
- /* PIC18F8720 configuration words */
- 0x300001,
- 0x30000d,
- { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ ,
- { 0x83, 0, 0xff } /* 4 */ , { 0x03, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ ,
- { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
- { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
- { 0x40, 0, 0xff } /* d */ }
},
- { 0x200000, 0x200007,
- { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 } }
- }
- }
-
+ NULL
};
-static int num_of_supported_PICS = sizeof(Pics16)/sizeof(PIC16_device);
-
-stats_t statistics = { 0, 0, 0, 0 };
+PIC16_device *pic16 = &default_device;
+static PIC16_device *devices = NULL;
-#define DEFAULT_PIC "452"
-
-PIC16_device *pic16=NULL;
-unsigned int stackPos = 0;
-unsigned int stackLen = 0;
-
-extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
-
-void pic16_setMaxRAM(int size)
-{
- pic16->maxRAMaddress = size;
- stackPos = pic16->RAMsize-1;
-
- if (pic16->maxRAMaddress < 0) {
- fprintf(stderr, "invalid \"#pragma maxram 0x%x\" setting\n",
- pic16->maxRAMaddress);
- return;
- }
-}
+extern set *includeDirsSet;
+extern set *userIncDirsSet;
extern char *iComments2;
regs *r1;
/* put all symbols in an array */
+ if (!elementsInSet(section)) return;
rlist = Safe_calloc(elementsInSet(section), sizeof(regs *));
r = rlist[0]; i = 0;
for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) {
symbol **slist;
/* put all symbols in an array */
+ if (!elementsInSet(section)) return;
slist = Safe_calloc(elementsInSet(section), sizeof(symbol *));
s = slist[0]; i = 0;
for(sprev = setFirstItem(section); sprev; sprev = setNextItem(section)) {
regs **rlist;
/* put all symbols in an array */
+ if (!elementsInSet(section)) return;
rlist = Safe_calloc(elementsInSet(section), sizeof(regs *));
r = rlist[0]; i = 0;
for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) {
Safe_free(rlist);
}
-
-#ifdef WORDS_BIGENDIAN
- #define _ENDIAN(x) (3-x)
-#else
- #define _ENDIAN(x) (x)
-#endif
-
-#define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff)
-
-
-/*-----------------------------------------------------------------*
- * void pic16_list_valid_pics(int ncols, int list_alias)
- *
- * Print out a formatted list of valid PIC devices
- *
- * ncols - number of columns in the list.
+/**
+ * Find the device structure for the named device.
+ * Consider usind pic16_find_device() instead!
*
- * 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 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
+ */
+static PIC16_device *
+find_in_list(const char *name, PIC16_device *head)
{
- int col,longest;
- int i,j,k,l;
-
- if(list_alias)
- list_alias = sizeof(Pics16[0].name) / sizeof(Pics16[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(Pics16[i].name[j]);
- if(k>longest)
- longest = k;
- }
- }
-
- col = 0;
-
- for(i=0; i < num_of_supported_PICS; i++) {
- j = 0;
- do {
+ int i;
- fprintf(stderr,"%s", Pics16[i].name[j]);
- if(col<ncols) {
- l = longest + 2 - strlen(Pics16[i].name[j]);
- for(k=0; k<l; k++)
- fputc(' ',stderr);
+ while (head) {
+ for (i = 0; i < 4; i++) {
+ if (0 == strcmp(head->name[i], name)) {
+ return (head);
+ } // if
+ } // for
- col++;
-
- } else {
- fputc('\n',stderr);
- col = 0;
- }
-
- } while(++j<list_alias);
-
- }
- if(col != ncols)
- fputc('\n',stderr);
+ head = head->next;
+ } // while
+ return (NULL);
}
-/*-----------------------------------------------------------------*
- *
- *-----------------------------------------------------------------*/
-PIC16_device *pic16_find_device(char *name)
+/**
+ * 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)
{
-
- int i,j;
-
- if(!name)
- return NULL;
-
- for(i = 0; i<num_of_supported_PICS; i++) {
-
- for(j=0; j<PROCESSOR_NAMES; j++)
- if(!STRCASECMP(Pics16[i].name[j], name) )
- return &Pics16[i];
- }
-
- /* not found */
- return NULL;
+ int i = 0;
+
+ if (options.verbose) {
+ printf("device RAM split SFRs config words\n");
+ } // if
+ while (head) {
+ printf("%-10s ", head->name[0]);
+ if (options.verbose) {
+ printf("%5d 0x%02x 0x%03x..0x%03x 0x%06x..0x%06x\n",
+ head->RAMsize,
+ head->acsSplitOfs,
+ head->sfrRange.sfrLoAddr,
+ head->sfrRange.sfrHiAddr,
+ head->cwInfo.confAddrStart,
+ head->cwInfo.confAddrEnd);
+ } else {
+ i++;
+ if (0 == (i % 6)) {
+ printf("\n");
+ } // if
+ } // if
+ head = head->next;
+ } // while
+ printf("\n");
}
-/*-----------------------------------------------------------------*
- *
- *-----------------------------------------------------------------*/
-void pic16_init_pic(char *pic_type)
+/**
+ * Read a single line from the given file.
+ * The caller should free() the returned value!
+ *
+ * @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)
{
- pic16 = pic16_find_device(pic_type);
-
- if(!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");
-
- fprintf(stderr,"Valid devices are:\n");
+ char *line = NULL;
+ size_t len = 129;
+ size_t done = 0;
+ size_t got = 0;
+
+ while (!feof(file)) {
+ line = (char *) Safe_realloc(line, len);
+ got += fread(&line[done], 1, 128, file);
+ line[got] = 0;
+
+ /* find EOL */
+ while (done < got) {
+ if (('\r' == line[done]) || ('\n' == line[done])) {
+ line[done] = 0;
+ fseek(file, done + 1 - got, SEEK_CUR);
+ return (line);
+ } // if
+ done++;
+ } // while
+
+ len += 128;
+ } // while
+
+ return (line);
+}
- pic16_list_valid_pics(4,0);
- exit(1);
- }
+/**
+ * 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)
+{
+ 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);
+}
-// printf("PIC processor found and initialized: %s\n", pic_type);
- pic16_setMaxRAM( 0xfff );
+/**
+ * Report errors in the device specification.
+ *
+ * @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.
+ *
+ * @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)
+{
+ 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[3];
+
+ 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
+ } // while
+ } // if
+
+ if (devices) {
+ // list already set up, nothing to do
+ } 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, "sfrrange")) {
+ // sfrrange %<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->sfrRange.sfrLoAddr = val[0];
+ d->sfrRange.sfrHiAddr = val[1];
+ } // 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
+ res = sscanf(&line[1+strlen(key)], " %i %i %i",
+ &val[0], &val[1], &val[2]);
+ if (res < 3) {
+ SYNTAX("<address> <mask> <value> (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];
+ } // 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
+ free(line);
+ } // 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);
}
/*-----------------------------------------------------------------*
*
*-----------------------------------------------------------------*/
-int pic16_picIsInitialized(void)
+void pic16_init_pic(const char *pic_type)
{
- if(pic16 && pic16->maxRAMaddress > 0)
- return 1;
-
- return 0;
-
+ 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
}
/*-----------------------------------------------------------------*
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 != -1)
+ && (pic16->cwInfo.crInfo[i].mask != 0)) {
#if 0
fprintf(stderr, "setting location 0x%X to value 0x%x\tmask: 0x%x\ttest: 0x%x\n",