2004-01-06 Vangelis Rokas <vrokas@otenet.gr>
[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 /* memRange - a structure to define a range of valid memory addresses 
34  * 
35  * The Memory of most PICs (and other micros) is a collection of
36  * disjoint chunks. The memRange structure will define the start
37  * and end address of one of these chunks. The memory map of a
38  * particular device is a collection of memRange struct's.
39  */
40
41 typedef struct memRange {
42   int start_address;      /* first address in range */
43   int end_address;        /* last */
44   int alias;              /* bit mask defining how/if memory range is aliased 
45                            * e.g. alias = 0x80 means start_address is identical
46                            * to the memory location at (0x80 | start_address) */
47   int bank;               /* PIC memory bank this range occupies */
48
49 } memRange;
50
51 /* AssignedMemory - A structure to keep track of the memory that has been used.
52  *
53  * When a register gets assigned an address this struct is used to
54  * keep track of a few details about the register. There is one of
55  * these structures for each memory location in the device.
56  */
57
58 typedef struct AssignedMemory {
59   regs *reg;        /* Pointer to the register (NULL if this is an invalid address) */
60   int  instance;    /* the i'th byte of a multibyte register */
61   int  alias;       /* Bit mapping of aliased addresses (see memRange) */
62   int  bank;        /* Memory bank of this register */
63   int  isValid:1;   /* True if the address is legal */
64   int  isSFR:1;     /* True if the address is that of a Special Function reg */
65   int  isEmitted:1; /* True if the register has been written to a cBlock */
66
67 } AssignedMemory;
68
69
70 /*
71  * pic16_finalMapping - Dynamically allocated array that records the register assignments
72  */
73
74 //extern AssignedMemory *pic16_finalMapping;
75
76 /*
77  * pic16_finalMappingSize - Size of register assignments that pic16_finalMapping can hold
78  */
79
80 //extern int pic16_finalMappingSize;
81
82
83 #define PROCESSOR_NAMES    4
84 /* Processor unique attributes */
85 typedef struct PIC_device {
86   char *name[PROCESSOR_NAMES];/* aliases for the processor name */
87
88   memRange *ram;              /* RAM memory map */
89   memRange *sfr;              /* SFR memory map */
90
91   int maxRAMaddress;          /* maximum value for a data address */
92   int bankMask;               /* Bitmask that is ANDed with address to extract banking bits */
93   int RAMsize;                /* size of Data RAM - VR 031120 */
94   int extMIface;               /* device has external memory interface */
95 } PIC_device;
96
97 /* Given a pointer to a register, this macro returns the bank that it is in */
98 #define REG_ADDR(r)        ((r)->isBitField ? (((r)->address)>>3) : (r)->address)
99 //#define REG_BANK(r)        (pic16_finalMapping[REG_ADDR(r)].bank)
100 //#define REG_isALIASED(r)   (pic16_finalMapping[REG_ADDR(r)].alias != 0)
101 //#define REG_isVALID(r)     (pic16_finalMapping[REG_ADDR(r)].isValid)
102
103
104 typedef struct {
105         int gen_banksel;
106         int opt_banksel;
107         int omit_configw;
108         int omit_ivt;
109         int leave_reset;
110         int enable_stack;
111         int stack_model;
112 } pic16_options_t;
113
114 #define USE_STACK       (pic16_options.enable_stack)
115 #define STACK_MODEL_SMALL       (pic16_options.stack_model == 0)
116 #define STACK_MODEL_LARGE       (pic16_options.stack_model == 1)
117
118
119 extern pic16_options_t pic16_options;
120
121
122 /****************************************/
123 void pic16_assignConfigWordValue(int address, int value);
124 int pic16_getConfigWord(int address);
125 int pic16_isREGinBank(regs *reg, int bank);
126 int pic16_REGallBanks(regs *reg);
127 void pic16_addMemRange(memRange *r, int type);
128 void pic16_setMaxRAM(int size);
129
130 void checkAddReg(set **set, regs *reg);
131
132
133 #endif  /* __DEVICE_H__ */