* doc/sdccman.lyx: updated SDCC version,
[fw/sdcc] / src / pic16 / device.h
1 /*-------------------------------------------------------------------------
2
3   device.c - Accomodates subtle variations in PIC16 devices
4
5    Written By -  Scott Dattalo scott@dattalo.com
6
7    This program is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by the
9    Free Software Foundation; either version 2, or (at your option) any
10    later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 -------------------------------------------------------------------------*/
21
22 /*
23   PIC device abstraction
24
25   There are dozens of variations of PIC microcontrollers. This include
26   file attempts to abstract those differences so that SDCC can easily
27   deal with them.
28 */
29
30 #ifndef  __DEVICE_H__
31 #define  __DEVICE_H__
32
33 #if defined(__BORLANDC__) || defined(_MSC_VER)
34 #define STRCASECMP stricmp
35 #else
36 #define STRCASECMP strcasecmp
37 #endif
38
39 #define CONFIGURATION_WORDS     20
40 #define IDLOCATION_BYTES        20
41
42 typedef struct {
43         int sfrLoAddr;
44         int sfrHiAddr;
45 } sfrRangeInfo_t;
46         
47
48 typedef struct {
49         unsigned int mask;
50         int emit;
51         unsigned int value;
52 } configRegInfo_t;
53
54 typedef struct {
55         int confAddrStart;      /* starting address */
56         int confAddrEnd;        /* ending address */
57         configRegInfo_t crInfo[ CONFIGURATION_WORDS ];
58 } configWordsInfo_t;
59
60 typedef struct {
61         unsigned char emit;
62         unsigned char value;
63 } idRegInfo_t;
64
65 typedef struct {
66         int idAddrStart;        /* starting ID address */
67         int idAddrEnd;          /* ending ID address */
68         idRegInfo_t irInfo[ IDLOCATION_BYTES ];
69 } idBytesInfo_t;
70
71
72 #define PROCESSOR_NAMES    4
73 /* Processor unique attributes */
74 typedef struct PIC16_device {
75   char *name[PROCESSOR_NAMES];/* aliases for the processor name */
76
77   int maxRAMaddress;            /* maximum value for a data address */
78   int RAMsize;                  /* size of Data RAM - VR 031120 */
79   int acsSplitOfs;              /* access bank split offset */
80   int extMIface;                /* device has external memory interface */
81   sfrRangeInfo_t sfrRange;      /* SFR range */
82   configWordsInfo_t cwInfo;     /* configuration words info */
83   idBytesInfo_t idInfo;         /* ID Locations info */
84 } PIC16_device;
85
86 /* Given a pointer to a register, this macro returns the bank that it is in */
87 #define REG_ADDR(r)        ((r)->isBitField ? (((r)->address)>>3) : (r)->address)
88
89 #define OF_LR_SUPPORT   0x00000001
90
91
92 typedef struct {
93   int no_banksel;
94   int opt_banksel;
95   int omit_configw;
96   int omit_ivt;
97   int leave_reset;
98   int stack_model;
99   int ivt_loc;
100   int nodefaultlibs;
101   int dumpcalltree;
102   char *crt_name;
103   int no_crt;
104   int ip_stack;
105   unsigned long opt_flags;
106   int gstack;
107 } pic16_options_t;
108
109 #define STACK_MODEL_SMALL       (pic16_options.stack_model == 0)
110 #define STACK_MODEL_LARGE       (pic16_options.stack_model == 1)
111
112 extern set *fix_idataSymSet;
113 extern set *rel_idataSymSet;
114
115 typedef struct {
116   unsigned long isize;
117   unsigned long adsize;
118   unsigned long udsize;
119   unsigned long idsize;
120   unsigned long intsize;
121 } stats_t;
122
123 extern stats_t statistics;
124
125 extern pic16_options_t pic16_options;
126 extern PIC16_device *pic16;
127
128 /****************************************/
129 void pic16_assignConfigWordValue(int address, unsigned int value);
130 void pic16_assignIdByteValue(int address, char value);
131 int pic16_isREGinBank(regs *reg, int bank);
132 int pic16_REGallBanks(regs *reg);
133 void pic16_setMaxRAM(int size);
134 int PIC16_IS_CONFIG_ADDRESS(int address);
135 int PIC16_IS_IDLOC_ADDRESS(int address);
136 int PIC16_IS_HWREG_ADDRESS(int address);
137
138 int checkAddReg(set **set, regs *reg);
139 int checkAddSym(set **set, symbol *reg);
140 int checkSym(set *set, symbol *reg);
141
142 #endif  /* __DEVICE_H__ */