X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fpic16%2Fdevice.c;h=9420f969fc3feb439416df66f214cc1062c7e57e;hb=cc2423da79ce6f6eedb517fd5a14290e355e3529;hp=2364bd9e7cb67ecaa3f729dd4e3493eded9115a2;hpb=d3491be4f9bb4bd4201c032ac4277a2a3afc2c62;p=fw%2Fsdcc diff --git a/src/pic16/device.c b/src/pic16/device.c index 2364bd9e..9420f969 100644 --- a/src/pic16/device.c +++ b/src/pic16/device.c @@ -35,326 +35,439 @@ #include "newalloc.h" +#include "main.h" #include "pcode.h" #include "ralloc.h" #include "device.h" static PIC16_device Pics16[] = { +// { +// {"p18f242", "18f242", "pic18f242", "f242"}, // 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"}, // aliases + {"p18f242", "18f242", "pic18f242", "f242"}, 0, - 0x300, // bank mask - 0x300, // RAMsize + 0x300, /* 768 */ + 0x80, 0, - { - /* 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 */ } - } + { 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 */ } + }, + { 0x200000, 0x200007, + { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, { 0, 0 } } + } }, - { - {"p18f248", "18f248", "pic18f248", "f248"}, // aliases + {"p18f248", "18f248", "pic18f248", "f248"}, 0, - 0x300, // bank mask - 0x300, // RAMsize + 0x300, /* 768 */ + 0x60, 0, - { - /* 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 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 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 */ , { 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 } } + } }, - { - {"p18f252", "18f252", "pic18f252", "f252"}, // aliases + {"p18f252", "18f252", "pic18f252", "f252"}, 0, - 0x600, // bank mask - 0x600, // RAMsize + 0x600, /* 1536 */ + 0x80, 0, - { - /* 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 */ } - } + { 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"}, // aliases + {"p18f258", "18f258", "pic18f258", "f258"}, 0, - 0x600, // bank mask - 0x600, // RAMsize + 0x600, /* 1536 */ + 0x60, 0, - { - /* 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 */ } - } + { 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"}, // aliases + {"p18f442", "18f442", "pic18f442", "f442"}, 0, - 0x300, // bank mask - 0x300, // RAMsize + 0x300, /* 768 */ + 0x80, 0, - { - /* 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 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 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 */ , { 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 } } + } }, - { - {"p18f448", "18f448", "pic18f448", "f448"}, // aliases + {"p18f448", "18f448", "pic18f448", "f448"}, 0, - 0x300, // bank mask - 0x300, // RAMsize + 0x300, /* 768 */ + 0x60, 0, - { - /* 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 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 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 */ , { 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 } } + } }, - { - {"p18f452", "18f452", "pic18f452", "f452"}, // aliases + {"p18f452", "18f452", "pic18f452", "f452"}, 0, - 0x600, // bank mask - 0x600, // RAMsize + 0x600, /* 1536 */ + 0x80, 0, - { - /* 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 */ } - } + { 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"}, // aliases + {"p18f458", "18f458", "pic18f458", "f458"}, 0, - 0x600, // bank mask - 0x600, // RAMsize + 0x600, /* 1536 */ + 0x60, 0, - { - /* 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 */ } - } + { 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"}, // aliases + {"p18f1220", "18f1220", "pic18f1220", "f1220"}, 0, - 0x200, - 0x200, + 0x100, /* 256 */ + 0x80, 0, - { - /* 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 */ } - } + { 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 } } + } }, - - { - {"p18f6520", "18f6520", "pic18f6520", "f6520"}, // aliases + {"p18f2220", "18f2220", "pic18f2220", "f2220"}, 0, - 0x800, // bank mask - 0x800, // RAMsize - 1, - { - /* PIC18F6520 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { 0x80, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 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 */ } - } + 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 */ , { 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 } } + } }, - { - {"p18f6620", "18f6620", "pic18f6620", "f6620"}, // aliases + {"p18f6520", "18f6520", "pic18f6520", "f6520"}, 0, - 0xf00, // bank mask - 0xf00, // RAMsize - 1, - { - /* PIC18F6620 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 */ } - } + 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 */ , + { 0x80, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 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 } } + } }, - { - {"p18f6680", "18f6680", "pic18f6680", "f6680"}, // aliases + {"p18f6620", "18f6620", "pic18f6620", "f6620"}, 0, - 0xc00, // bank mask - 0xc00, // RAMsize - 1, - { - /* PIC18F6680 configuration words */ - 0x300001, - 0x30000d, - { { 0x2f, 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 */ } - } + 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 */ , + { -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 } } + } }, - { - {"p18f6720", "18f6720", "pic18f6720", "f6720"}, // aliases + {"p18f6680", "18f6680", "pic18f6680", "f6680"}, 0, - 0xf00, // bank mask - 0xf00, // RAMsize - 1, - { - /* PIC18F6720 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 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + 0xf00, /* 3840 */ + 0x60, + 0, + { 0xf00, 0xfff }, /* PIC18F6680 range of SFR's */ + { + /* PIC18F6680 configuration words */ + 0x300001, + 0x30000d, + { { 0x2f, 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 } } + } }, - { - {"p18f8520", "18f8520", "pic18f8520", "f8520"}, // aliases + {"p18f6720", "18f6720", "pic18f6720", "f6720"}, 0, - 0x800, // bank mask - 0x800, // RAMsize - 1, - { - /* PIC18F8520 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { 0x83, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 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 */ } - } + 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 */ , + { -1, 0, 0xff } /* 4 */ , { 0x01, 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"}, // aliases + {"p18f8520", "18f8520", "pic18f8520", "f8520"}, 0, - 0xf00, // bank mask - 0xf00, // RAMsize + 0x800, /* 2048 */ + 0x60, 1, - { - /* PIC18F8620 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { 0x83, 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 */ } - } + { 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 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 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 } } + } }, { - {"p18f8680", "18f8680", "pic18f8680", "f8680"}, // aliases + {"p18f8620", "18f8620", "pic18f8620", "f8620"}, 0, - 0xc00, // bank mask - 0x800, // RAMsize + 0xf00, /* 3840 */ + 0x60, 1, - { - /* PIC18F8680 configuration words */ - 0x300001, - 0x30000d, - { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , - { 0x83, 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 */ } - } + { 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 */ , { 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 } } + } + }, + { + {"p18f8680", "18f8680", "pic18f8680", "f8680"}, + 0, + 0xf00, /* 3840 */ + 0x60, + 0, + { 0xf00, 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 */ , { 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 } } + } }, - { - {"p18f8720", "18f8720", "pic18f8720", "f8720"}, // aliases + {"p18f8720", "18f8720", "pic18f8720", "f8720"}, 0, - 0xf00, // bank mask - 0xf00, // RAMsize + 0xf00, /* 3840 */ + 0x60, 1, - { - /* PIC18F8720 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { 0x83, 0, 0xff } /* 4 */ , { 0x01, 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 */ } - } + { 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 */ , { 0x01, 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 } } + } } }; static int num_of_supported_PICS = sizeof(Pics16)/sizeof(PIC16_device); +stats_t statistics = { 0, 0, 0, 0 }; + #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); @@ -389,6 +502,25 @@ void pic16_dump_equates(FILE *of, set *equs) } +void pic16_dump_access(FILE *of, set *section) +{ + regs *r; + + r = setFirstItem(section); + if(!r)return; + + fprintf(of, "%s", iComments2); + fprintf(of, ";\tAccess bank symbols\n"); + fprintf(of, "%s", iComments2); + + fprintf(of, "\tudata_acs\n"); + for(; r; r = setNextItem(section)) { + fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.adsize += r->size; + } +} + + int regCompare(const void *a, const void *b) { const regs *const *i = a; @@ -433,7 +565,7 @@ void pic16_dump_usection(FILE *of, set *section, int fix) { static int abs_usection_no=0; regs *r, *rprev; - int init_addr, i; + unsigned int init_addr, i; regs **rlist; regs *r1; @@ -453,12 +585,23 @@ void pic16_dump_usection(FILE *of, set *section, int fix) qsort(rlist, i /*elementsInSet(section)*/, sizeof(regs *), regCompare); if(!fix) { + +#define EMIT_SINGLE_UDATA_SECTION 0 +#if EMIT_SINGLE_UDATA_SECTION fprintf(of, "\n\n\tudata\n"); for(r = setFirstItem(section); r; r = setNextItem(section)) { fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.udsize += r->size; + } +#else + for(r = setFirstItem(section); r; r = setNextItem(section)) { + fprintf(of, "\nudata_%s_%s\tudata\n", moduleName, r->name); + fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.udsize += r->size; } +#endif } else { - int j=0; + unsigned int j=0; int deb_addr=0; rprev = NULL; @@ -482,6 +625,7 @@ void pic16_dump_usection(FILE *of, set *section, int fix) } else { fprintf(of, "%s\tres\t%d\n", r->name, r->size); deb_addr += r->size; + statistics.udsize += r->size; } rprev = r; @@ -490,15 +634,36 @@ void pic16_dump_usection(FILE *of, set *section, int fix) free(rlist); } +void pic16_dump_gsection(FILE *of, set *sections) +{ + regs *r; + sectName *sname; + + for(sname = setFirstItem(sections); sname; sname = setNextItem(sections)) { + if(!strcmp(sname->name, "access"))continue; + fprintf(of, "\n\n%s\tudata\n", sname->name); + + for(r=setFirstItem(sname->regsSet); r; r=setNextItem(sname->regsSet)) { +#if 0 + fprintf(stderr, "%s:%d emitting variable %s for section %s (%p)\n", __FILE__, __LINE__, + r->name, sname->name, sname); +#endif + fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.udsize += r->size; + } + } +} + /* forward declaration */ -void print_idata(FILE *of, symbol * sym, sym_link * type, initList * ilist); +void pic16_printIval(symbol * sym, sym_link * type, initList * ilist, char ptype, void *p); +extern void pic16_pCodeConstString(char *name, char *value); void pic16_dump_isection(FILE *of, set *section, int fix) { static int abs_isection_no=0; symbol *s, *sprev; - int init_addr, i; + unsigned int init_addr, i; symbol **slist; /* put all symbols in an array */ @@ -516,13 +681,30 @@ void pic16_dump_isection(FILE *of, set *section, int fix) /* sort symbols according to their address */ qsort(slist, i, sizeof(symbol *), symCompare); + pic16_initDB(); + if(!fix) { fprintf(of, "\n\n\tidata\n"); for(s = setFirstItem(section); s; s = setNextItem(section)) { - print_idata(of, s, s->type, s->ival); + + if(s->ival) { + fprintf(of, "%s", s->rname); + pic16_printIval(s, s->type, s->ival, 'f', (void *)of); + pic16_flushDB('f', (void *)of); + } else { + if (IS_ARRAY (s->type) && IS_CHAR (s->type->next) + && SPEC_CVAL (s->etype).v_char) { + +// fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname); + pic16_pCodeConstString(s->rname , SPEC_CVAL (s->etype).v_char); + } else { + assert(0); + } + } + } } else { - int j=0; + unsigned int j=0; symbol *s1; sprev = NULL; @@ -539,16 +721,22 @@ void pic16_dump_isection(FILE *of, set *section, int fix) fprintf(of, "\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr); } - print_idata(of, s, s->type, s->ival); - -#if 0 - if(r1 && (init_addr == r1->address)) { - fprintf(of, "%s\tres\t0\n\n", r->name); + if(s->ival) { + fprintf(of, "%s", s->rname); + pic16_printIval(s, s->type, s->ival, 'f', (void *)of); + pic16_flushDB('f', (void *)of); } else { - fprintf(of, "%s\tres\t%d\n", r->name, r->size); + if (IS_ARRAY (s->type) && IS_CHAR (s->type->next) + && SPEC_CVAL (s->etype).v_char) { + +// fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname); + pic16_pCodeConstString(s->rname , SPEC_CVAL (s->etype).v_char); + } else { + assert(0); + } } -#endif - + + sprev = s; } } @@ -580,8 +768,10 @@ void pic16_dump_int_registers(FILE *of, set *section) fprintf(of, "\n\n; Internal registers\n"); fprintf(of, "%s\tudata_ovr\t0x0000\n", ".registers"); - for(r = setFirstItem(section); r; r = setNextItem(section)) + for(r = setFirstItem(section); r; r = setNextItem(section)) { fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.intsize += r->size; + } free(rlist); } @@ -596,250 +786,6 @@ void pic16_dump_int_registers(FILE *of, set *section) #define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff) - -/*-----------------------------------------------------------------*/ -/* printIvalType - generates ival for int/char */ -/*-----------------------------------------------------------------*/ -void print_idataType (FILE *of, symbol *sym, sym_link * type, initList * ilist) -{ - value *val; - unsigned long ulval; - - //fprintf(stderr, "%s\n",__FUNCTION__); - - /* if initList is deep */ - if (ilist->type == INIT_DEEP) - ilist = ilist->init.deep; - - if (!IS_AGGREGATE(sym->type) && getNelements(type, ilist)>1) { - werror (W_EXCESS_INITIALIZERS, "scalar", sym->name, sym->lineDef); - } - - if (!(val = list2val (ilist))) { - // assuming a warning has been thrown - val=constVal("0"); - } - - if (val->type != type) { - val = valCastLiteral(type, floatFromVal(val)); - } - - if(val) - ulval = (unsigned long) floatFromVal (val); - else - ulval =0; - - switch (getSize (type)) { - case 1: - if(isprint(BYTE_IN_LONG(ulval, 0))) - fprintf(of, "%s\tdata\t\"%c\"\n", sym->rname, (unsigned char)BYTE_IN_LONG(ulval, 0)); - else - fprintf(of, "%s\tdata\t0x%02x\n", sym->rname, (unsigned char)BYTE_IN_LONG(ulval, 0)); -// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); - break; - - case 2: - fprintf(of, "%s\tdw\t0x%02x, 0x%02x\n", sym->rname, (unsigned int)(BYTE_IN_LONG(ulval, 0)), - (unsigned int)(BYTE_IN_LONG(ulval, 1))); -// fprintf(of, "%s\tdata\t0x%04x\n", sym->rname, (unsigned int)BYTE_IN_LONG(ulval, 0) + -// (unsigned int)(BYTE_IN_LONG(ulval, 1) << 8)); - break; - - case 4: - fprintf(of, "%s\tdw\t0x%04x,0x%04x\n", sym->rname, (unsigned int)(BYTE_IN_LONG(ulval, 0) - + (BYTE_IN_LONG(ulval, 1) << 8)), - (unsigned)(BYTE_IN_LONG(ulval, 2) - + (BYTE_IN_LONG(ulval, 3) << 8))); -// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); -// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1)))); -// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,2)))); -// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,3)))); - break; - } -} - - -/*-----------------------------------------------------------------*/ -/* print_idataChar - generates initital value for character array */ -/*-----------------------------------------------------------------*/ -static int -print_idataChar (FILE *of, symbol *sym, sym_link * type, initList * ilist, char *s) -{ - value *val; - int remain; - char old_ch=0, *vchar; - - // fprintf(stderr, "%s\n",__FUNCTION__); - if (!s) - { - - val = list2val (ilist); - /* if the value is a character string */ - if (IS_ARRAY (val->type) && IS_CHAR (val->etype)) - { - if (!DCL_ELEM (type)) - DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1; - - - fprintf(of, "%s\tdata\t", sym->rname); - vchar = SPEC_CVAL(val->etype).v_char; - for(remain=0; remainetype).v_char[ remain ], (remain==DCL_ELEM(type)-1?"":",")); - - - if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0) - { - while (remain--) - { - fprintf(of, "0x%02x%s", 0x00 /*SPEC_CVAL(val->etype).v_char[ remain ]*/ , (remain==DCL_ELEM(type)-1?"":",")); - } - } - fprintf(of, "\n"); - return 1; - } - else - return 0; - } - else { - fprintf(of, "%s\tdata\t", sym->rname); - vchar = s; old_ch = 0; - for(remain=0; remainnext)) { -// fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__); - if (!IS_LITERAL(list2val(ilist)->etype)) { - werror (W_INIT_WRONG); - return; - } - if (print_idataChar (of, sym, type, - (ilist->type == INIT_DEEP ? ilist->init.deep : ilist), - SPEC_CVAL (sym->etype).v_char)) - return; - } - /* not the special case */ - if (ilist->type != INIT_DEEP) - { - werror (E_INIT_STRUCT, sym->name); - return; - } - - iloop = ilist->init.deep; - lcnt = DCL_ELEM (type); - - for (;;) - { - //fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__); - size++; - print_idata (of, sym, type->next, iloop); - iloop = (iloop ? iloop->next : NULL); - - - /* if not array limits given & we */ - /* are out of initialisers then */ - if (!DCL_ELEM (type) && !iloop) - break; - - /* no of elements given and we */ - /* have generated for all of them */ - if (!--lcnt) { - /* if initializers left */ - if (iloop) { - werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef); - } - break; - } - } - - /* if we have not been given a size */ - if (!DCL_ELEM (type)) - DCL_ELEM (type) = size; - - return; -} - -/*-----------------------------------------------------------------*/ -/* print_idata - generates code for initial value */ -/*-----------------------------------------------------------------*/ -void print_idata(FILE *of, symbol * sym, sym_link * type, initList * ilist) -{ - if (!ilist) - return; - - /* if structure then */ - if (IS_STRUCT (type)) - { - //fprintf(stderr,"%s struct\n",__FUNCTION__); - //printIvalStruct (sym, type, ilist, oFile); - fprintf(stderr, "%s:%d: PIC16 port error: structure initialisation is not implemented yet.\n", - __FILE__, __LINE__); - abort(); - return; - } - - /* if this is a pointer */ - if (IS_PTR (type)) - { - //fprintf(stderr,"%s pointer\n",__FUNCTION__); - //printIvalPtr (sym, type, ilist, oFile); - fprintf(stderr, "%s:%d: PIC16 port error: pointer initialisation is not immplemented yet.\n", - __FILE__, __LINE__); - abort(); - return; - } - - /* if this is an array */ - if (IS_ARRAY (type)) - { - //fprintf(stderr,"%s array\n",__FUNCTION__); - print_idataArray (of, sym, type, ilist); - return; - } - - /* if type is SPECIFIER */ - if (IS_SPEC (type)) - { -// fprintf(stderr,"%s spec\n",__FUNCTION__); - print_idataType(of, sym, type, ilist); - return; - } -} - - - - /*-----------------------------------------------------------------* * void pic16_list_valid_pics(int ncols, int list_alias) * @@ -975,6 +921,8 @@ int checkAddReg(set **set, regs *reg) { regs *tmp; + + if(!reg)return 0; #if DEBUG_CHECK fprintf(stderr, "%s: about to insert REGister: %s ... ", __FUNCTION__, reg->name); #endif @@ -1001,6 +949,7 @@ int checkAddSym(set **set, symbol *sym) { symbol *tmp; + if(!sym)return 0; #if DEBUG_CHECK fprintf(stderr, "%s: about to add SYMbol: %s ... ", __FUNCTION__, sym->name); #endif @@ -1024,6 +973,33 @@ int checkAddSym(set **set, symbol *sym) return 0; } +int checkSym(set *set, symbol *sym) +{ + symbol *tmp; + + if(!sym)return 0; + +#if DEUG_CHECK + fprintf(stderr, "%s: about to search for SYMbol: %s ... ", __FUNCTION__, sym->name); +#endif + + for(tmp = setFirstItem( set ); tmp; tmp = setNextItem( set )) { + if(!strcmp(tmp->name, sym->name))break; + } + + if(!tmp) { +#if DEBUG_CHECK + fprintf(stderr, "not found\n"); +#endif + return 0; + } + +#if DEBUG_CHECK + fprintf(stderr, "found\n"); +#endif + + return 1; +} /*-----------------------------------------------------------------* * void pic16_groupRegistersInSection - add each register to its * @@ -1032,13 +1008,18 @@ int checkAddSym(set **set, symbol *sym) void pic16_groupRegistersInSection(set *regset) { regs *reg; + sectSym *ssym; + int docontinue=0; for(reg=setFirstItem(regset); reg; reg = setNextItem(regset)) { -// fprintf(stderr, "%s:%d group registers in section, reg: %s\n", __FILE__, __LINE__, reg->name); - - if(reg->wasUsed - && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop)))) { +#if 0 + fprintf(stderr, "%s:%d group registers in section, reg: %s (used: %d, %p)\n", + __FILE__, __LINE__, reg->name, reg->wasUsed, reg); +#endif + if((reg->wasUsed + && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop)))) + ) { /* avoid grouping registers that have an initial value, * they will be added later in idataSymSet */ @@ -1046,13 +1027,35 @@ void pic16_groupRegistersInSection(set *regset) continue; #if 0 - fprintf(stderr, "%s:%d register %s alias:%d fix:%d ival=%i level=%i\n", + fprintf(stderr, "%s:%d register %s alias:%d fix:%d ival=%i level=%i code=%i\n", __FILE__, __LINE__, reg->name, reg->alias, reg->isFixed, (reg->regop?(OP_SYMBOL(reg->regop)->ival?1:0):-1), - (reg->regop?(OP_SYMBOL(reg->regop)->level):-1) ); + (reg->regop?(OP_SYMBOL(reg->regop)->level):-1), + (reg->regop?(IS_CODE(OP_SYM_ETYPE(reg->regop))):-1) ); #endif + + docontinue=0; + for(ssym=setFirstItem(sectSyms);ssym;ssym=setNextItem(sectSyms)) { + if(!strcmp(ssym->name, reg->name)) { +// fprintf(stderr, "%s:%d section found %s (%p) with var %s\n", +// __FILE__, __LINE__, ssym->section->name, ssym->section, ssym->name); + if(strcmp(ssym->section->name, "access")) { + addSet(&ssym->section->regsSet, reg); + docontinue=1; + break; + } else { + docontinue=0; + reg->accessBank = 1; + break; + } + } + } - if(reg->alias) { + if(docontinue)continue; + +// fprintf(stderr, "%s:%d reg: %s\n", __FILE__, __LINE__, reg->name); + + if(reg->alias == 0x80) { checkAddReg(&pic16_equ_data, reg); } else if(reg->isFixed) { @@ -1061,8 +1064,13 @@ void pic16_groupRegistersInSection(set *regset) if(!reg->isFixed) { if(reg->pc_type == PO_GPR_TEMP) checkAddReg(&pic16_int_regs, reg); - else - checkAddReg(&pic16_rel_udata, reg); + else { + if(reg->accessBank) { + if(reg->alias != 0x40) + checkAddReg(&pic16_acs_udata, reg); + } else + checkAddReg(&pic16_rel_udata, reg); + } } } } @@ -1080,15 +1088,26 @@ void pic16_groupRegistersInSection(set *regset) * This routine will assign a value to that address. * *-----------------------------------------------------------------*/ -void pic16_assignConfigWordValue(int address, int value) +void pic16_assignConfigWordValue(int address, unsigned int value) { int i; - for(i=0;icwInfo.confAddrEnd-pic16->cwInfo.confAddrStart+1;i++) { if((address == pic16->cwInfo.confAddrStart+i) && (pic16->cwInfo.crInfo[i].mask != -1)) { -// fprintf(stderr, "setting location 0x%X to value 0x%x\n", /*address*/ pic16->cwInfo.confAddrStart+i, val + +#if 0 + fprintf(stderr, "setting location 0x%X to value 0x%x\tmask: 0x%x\ttest: 0x%x\n", + /*address*/ pic16->cwInfo.confAddrStart+i, (~value)&0xff, + pic16->cwInfo.crInfo[i].mask, + (pic16->cwInfo.crInfo[i].mask) & (~value)); +#endif + + if((((pic16->cwInfo.crInfo[i].mask) & (~value))&0xff) != ((~value)&0xff)) { + fprintf(stderr, "%s:%d a wrong value has been given for configuration register 0x%x\n", + __FILE__, __LINE__, address); + return; + } pic16->cwInfo.crInfo[i].value = value; pic16->cwInfo.crInfo[i].emit = 1; return; @@ -1096,3 +1115,14 @@ void pic16_assignConfigWordValue(int address, int value) } } +void pic16_assignIdByteValue(int address, char value) +{ + int i; + + for(i=0;iidInfo.idAddrEnd-pic16->idInfo.idAddrStart+1;i++) { + if(address == pic16->idInfo.idAddrStart+i) { + pic16->idInfo.irInfo[i].value = value; + pic16->idInfo.irInfo[i].emit = 1; + } + } +}