* src/pic/pcode.c (register_reassign): do not crash on recursive code
[fw/sdcc] / src / pic / device.h
1 /*-------------------------------------------------------------------------
2
3    device.c - Accomodates subtle variations in PIC devices
4    Written By -  Scott Dattalo scott@dattalo.com
5
6    This program is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option) any
9    later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 -------------------------------------------------------------------------*/
20
21 /*
22   PIC device abstraction
23
24   There are dozens of variations of PIC microcontrollers. This include
25   file attempts to abstract those differences so that SDCC can easily
26   deal with them.
27 */
28
29 #ifndef  __DEVICE_H__
30 #define  __DEVICE_H__
31
32 /* memRange - a structure to define a range of valid memory addresses 
33  * 
34  * The Memory of most PICs (and other micros) is a collection of
35  * disjoint chunks. The memRange structure will define the start
36  * and end address of one of these chunks. The memory map of a
37  * particular device is a collection of memRange struct's.
38  */
39
40 typedef struct memRange {
41         int start_address;      /* first address in range */
42         int end_address;        /* last */
43         int alias;              /* bit mask defining how/if memory range is aliased 
44                                  * e.g. alias = 0x80 means start_address is identical
45                                  * to the memory location at (0x80 | start_address) */
46         int bank;               /* PIC memory bank this range occupies */
47         struct memRange *next;  /* linked list */
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  * finalMapping - Dynamically allocated array that records the register assignments
72  */
73
74 extern AssignedMemory *finalMapping;
75 /* Processor unique attributes */
76 typedef struct PIC_device {
77         char *name;                 /* the processor name */
78
79         memRange *ram;              /* RAM memory map */
80         memRange *sfr;              /* SFR memory map */
81
82         int maxRAMaddress;          /* maximum value for a data address */
83         int defMaxRAMaddrs;         /* default maximum value for a data address */
84         int bankMask;               /* Bitmask that is ANDed with address to extract banking bits */
85         //  int hasAliasedRAM:1;        /* True if there are bank independent registers */
86         int hasSecondConfigReg;     /* True if there is a second configuration register */
87         
88         int programMemSize;         /* program memory size in words - for device listing only */
89         int dataMemSize;            /* data (RAM) memory size in bytes - for device listing only */
90         int eepromMemSize;          /* EEPROM memory size in bytes - for device listing only */
91         int ioPins;                 /* number of I/O pins - for device listing only */
92
93 } PIC_device;
94
95 /* Given a pointer to a register, this macro returns the bank that it is in */
96 #define REG_ADDR(r)        ((r)->isBitField ? (((r)->address)>>3) : (r)->address)
97 #define REG_BANK(r)        (finalMapping[REG_ADDR(r)].bank)
98 #define REG_isALIASED(r)   (finalMapping[REG_ADDR(r)].alias != 0)
99 #define REG_isVALID(r)     (finalMapping[REG_ADDR(r)].isValid)
100
101
102 /****************************************/
103 void assignConfigWordValue(int address, int value);
104 int getConfigWord(int address);
105 int isREGinBank(regs *reg, int bank);
106 int REGallBanks(regs *reg);
107 void addMemRange(memRange *r, int type);
108 void setMaxRAM(int size);
109 void setDefMaxRam(void);
110
111 void pic14_assignConfigWordValue(int address, int value);
112 int pic14_emitConfigWord (FILE * vFile);
113 int pic14_getConfigWord(int address);
114
115 unsigned pic14_getMaxRam(void);
116 int pic14_getHasSecondConfigReg(void);
117 int pic14_allRAMShared(void);
118 int pic14_hasSharebank(int *low, int *high, int *size);
119 int pic14_getSharedStack(int *low, int *high, int *size);
120 PIC_device * pic14_getPIC(void);
121
122 #endif  /* __DEVICE_H__ */