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 #define CONFIGURATION_WORDS     20
34 #define IDLOCATION_BYTES        20
35 
36 typedef struct {
37   unsigned int mask;
38   int emit;
39   unsigned int value;
40   unsigned int andmask;
41 } configRegInfo_t;
42 
43 typedef struct {
44   int confAddrStart;      /* starting address */
45   int confAddrEnd;        /* ending address */
46   configRegInfo_t crInfo[ CONFIGURATION_WORDS ];
47 } configWordsInfo_t;
48 
49 typedef struct {
50   unsigned char emit;
51   unsigned char value;
52 } idRegInfo_t;
53 
54 typedef struct {
55   int idAddrStart;        /* starting ID address */
56   int idAddrEnd;          /* ending ID address */
57   idRegInfo_t irInfo[ IDLOCATION_BYTES ];
58 } idBytesInfo_t;
59 
60 
61 #define PROCESSOR_NAMES    4
62 /* Processor unique attributes */
63 typedef struct PIC16_device {
64   char *name[PROCESSOR_NAMES];  /* aliases for the processor name */
65   /* RAMsize *must* be the first item to copy for 'using' */
66   unsigned int RAMsize;         /* size of Data RAM - VR 031120 */
67   unsigned int acsSplitOfs;     /* access bank split offset */
68   configWordsInfo_t cwInfo;     /* configuration words info */
69   idBytesInfo_t idInfo;         /* ID Locations info */
70   int xinst;                    /* device supports XINST */
71   /* next *must* be the first field NOT being copied via 'using' */
72   struct PIC16_device *next;    /* linked list */
73 } PIC16_device;
74 
75 extern PIC16_device *pic16;
76 
77 /* Given a pointer to a register, this macro returns the bank that it is in */
78 #define REG_ADDR(r)        ((r)->isBitField ? (((r)->address)>>3) : (r)->address)
79 
80 #define OF_LR_SUPPORT           0x00000001
81 #define OF_NO_OPTIMIZE_GOTO     0x00000002
82 #define OF_OPTIMIZE_CMP         0x00000004
83 #define OF_OPTIMIZE_DF          0x00000008
84 
85 typedef struct {
86   int no_banksel;
87   int opt_banksel;
88   int omit_configw;
89   int omit_ivt;
90   int leave_reset;
91   int stack_model;
92   int ivt_loc;
93   int nodefaultlibs;
94   int dumpcalltree;
95   char *crt_name;
96   int no_crt;
97   int ip_stack;
98   unsigned long opt_flags;
99   int gstack;
100   unsigned int debgen;
101   int xinst;
102   int no_warn_non_free;
103 } pic16_options_t;
104 
105 extern pic16_options_t pic16_options;
106 
107 #define STACK_MODEL_SMALL       (pic16_options.stack_model == 0)
108 #define STACK_MODEL_LARGE       (pic16_options.stack_model == 1)
109 
110 extern set *fix_idataSymSet;
111 extern set *rel_idataSymSet;
112 
113 #if 0
114 /* This is an experimental code for #pragma inline
115    and is temporarily disabled for 2.5.0 release */
116 extern set *asmInlineMap;
117 #endif  /* 0 */
118 
119 typedef struct {
120   unsigned long isize;
121   unsigned long adsize;
122   unsigned long udsize;
123   unsigned long idsize;
124   unsigned long intsize;
125 } stats_t;
126 
127 extern stats_t statistics;
128 
129 typedef struct pic16_config_options_s {
130   char *config_str;
131   struct pic16_config_options_s *next;
132 } pic16_config_options_t;
133 
134 extern pic16_config_options_t *pic16_config_options;
135 
136 /****************************************/
137 const char *pic16_processor_base_name(void);
138 void pic16_assignConfigWordValue(int address, unsigned int value);
139 void pic16_assignIdByteValue(int address, char value);
140 int pic16_isREGinBank(reg_info *reg, int bank);
141 int pic16_REGallBanks(reg_info *reg);
142 
143 int checkAddReg(set **set, reg_info *reg);
144 int checkAddSym(set **set, symbol *reg);
145 int checkSym(set *set, symbol *reg);
146 
147 #endif  /* __DEVICE_H__ */
148