Imported Upstream version 2.9.0
[debian/cc1111] / src / pic / ralloc.h
1 /*-------------------------------------------------------------------------
2
3   SDCCralloc.h - header file register allocation
4
5                 Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1998)
6     PIC port   - T. Scott Dattalo scott@dattalo.com (2000)
7
8    This program is free software; you can redistribute it and/or modify it
9    under the terms of the GNU General Public License as published by the
10    Free Software Foundation; either version 2, or (at your option) any
11    later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21    
22    In other words, you are welcome to use, share and improve this program.
23    You are forbidden to forbid anyone else to use, share and improve
24    what you give them.   Help stamp out software-hoarding!  
25 -------------------------------------------------------------------------*/
26
27 #ifndef SDCCRALLOC_H
28 #define SDCCRALLOC_H 1
29
30 #include "common.h"
31
32 #include "pcoderegs.h"
33
34
35 enum {
36   REG_PTR=1,
37   REG_GPR,
38   REG_CND,
39   REG_SFR,
40   REG_STK,
41   REG_TMP
42 };
43
44 /* definition for the registers */
45 typedef struct regs
46 {
47   short type;  /* can have value 
48                 * REG_GPR, REG_PTR or REG_CND 
49                 * This like the "meta-type" */
50   short pc_type; /* pcode type */
51   short rIdx;    /* index into register table */
52   char *name;    /* name */
53
54   unsigned isFree:1;          /* is currently unassigned  */
55   unsigned wasUsed:1;         /* becomes true if register has been used */
56   unsigned isFixed:1;         /* True if address can't change */
57   unsigned isMapped:1;        /* The Register's address has been mapped to physical RAM */
58   unsigned isBitField:1;      /* True if reg is type bit OR is holder for several bits */
59   unsigned isEmitted:1;       /* True if the reg has been written to a .asm file */
60   unsigned isPublic:1;        /* True if the reg is not static and can be modified in another module (ie a another c or asm file) */
61   unsigned isExtern:1;        /* True if the reg is in another module */
62   unsigned address;           /* reg's address if isFixed | isMapped is true */
63   unsigned size;              /* 0 for byte, 1 for int, 4 for long */
64   unsigned alias;             /* Alias mask if register appears in multiple banks */
65   struct regs *reg_alias;     /* If more than one register share the same address 
66                                * then they'll point to each other. (primarily for bits)*/
67   pCodeRegLives reglives;     /* live range mapping */
68 }
69 regs;
70 extern regs regspic14[];
71 extern int Gstack_base_addr;
72
73 /*
74   As registers are created, they're added to a set (based on the
75   register type). Here are the sets of registers that are supported
76   in the PIC port:
77 */
78 extern set *dynAllocRegs;
79 extern set *dynStackRegs;
80 extern set *dynProcessorRegs;
81 extern set *dynDirectRegs;
82 extern set *dynDirectBitRegs;
83 extern set *dynInternalRegs;
84
85
86 void initStack(int base_address, int size, int shared);
87 regs *pic14_regWithIdx (int);
88 regs *dirregWithName (char *name );
89 void pic14_assignRegisters (ebbIndex *ebbi);
90 regs *pic14_findFreeReg(short type);
91 regs *pic14_allocWithIdx (int idx);
92 regs *typeRegWithIdx (int idx, int type, int fixed);
93 regs *regFindWithName (const char *name);
94
95 void pic14_debugLogClose(void);
96 void writeUsedRegs(FILE *of);
97
98 regs *allocDirReg (operand *op );
99 regs *allocInternalRegister(int rIdx, char * name, PIC_OPTYPE po_type, int alias);
100 regs *allocProcessorRegister(int rIdx, char * name, short po_type, int alias);
101 regs *allocRegByName (char *name, int size );
102 regs *allocNewDirReg (sym_link *symlnk,const char *name);
103
104 /* Define register address that are constant across PIC family */
105 #define IDX_INDF    0
106 #define IDX_TMR0    1
107 #define IDX_PCL     2
108 #define IDX_STATUS  3
109 #define IDX_FSR     4
110 #define IDX_PORTA   5
111 #define IDX_PORTB   6
112 #define IDX_PCLATH  0x0a
113 #define IDX_INTCON  0x0b
114
115 #define IDX_KZ      0x7fff   /* Known zero - actually just a general purpose reg. */
116 #define IDX_WSAVE   0x7ffe
117 #define IDX_SSAVE   0x7ffd
118 #define IDX_PSAVE   0x7ffc
119
120 #define pic14_nRegs 128
121
122 #endif