*** empty log message ***
[fw/sdcc] / src / pic16 / ralloc.h
1 /*-------------------------------------------------------------------------
2
3   ralloc.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         PIC16 port   - Martin Dubuc m.dubuc@rogers.com (2002)
8
9    This program is free software; you can redistribute it and/or modify it
10    under the terms of the GNU General Public License as published by the
11    Free Software Foundation; either version 2, or (at your option) any
12    later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22    
23    In other words, you are welcome to use, share and improve this program.
24    You are forbidden to forbid anyone else to use, share and improve
25    what you give them.   Help stamp out software-hoarding!  
26 -------------------------------------------------------------------------*/
27 #include "SDCCicode.h"
28 #include "SDCCBBlock.h"
29 #ifndef SDCCRALLOC_H
30 #define SDCCRALLOC_H 1
31
32 #include "pcoderegs.h"
33
34
35 enum
36   {
37     R2_IDX = 0, R3_IDX, R4_IDX,
38     R5_IDX, R6_IDX, R7_IDX,
39     R0_IDX, R1_IDX, X8_IDX,
40     X9_IDX, X10_IDX, X11_IDX,
41     X12_IDX, CND_IDX
42   };
43
44 enum {
45  REG_PTR=1,
46  REG_GPR,
47  REG_CND,
48  REG_SFR,
49  REG_STK,
50  REG_TMP
51 };
52 //#define REG_PTR 0x01
53 //#define REG_GPR 0x02
54 //#define REG_CND 0x04
55 //#define REG_SFR 0x08
56 //#define REG_STK 0x10  /* Use a register as a psuedo stack */
57 //#define REG_TMP 0x20  
58
59 /* definition for the registers */
60 typedef struct regs
61   {
62     short type;                 /* can have value 
63                                  * REG_GPR, REG_PTR or REG_CND 
64                                  * This like the "meta-type" */
65     short pc_type;              /* pcode type */
66     short rIdx;                 /* index into register table */
67     //    short otype;        
68     char *name;                 /* name */
69
70     unsigned isFree:1;          /* is currently unassigned  */
71     unsigned wasUsed:1;         /* becomes true if register has been used */
72     unsigned isFixed:1;         /* True if address can't change */
73     unsigned isMapped:1;        /* The Register's address has been mapped to physical RAM */
74     unsigned isBitField:1;      /* True if reg is type bit OR is holder for several bits */
75     unsigned isEmitted:1;       /* True if the reg has been written to a .asm file */
76     unsigned address;           /* reg's address if isFixed | isMapped is true */
77     unsigned size;              /* 0 for byte, 1 for int, 4 for long */
78     unsigned alias;             /* Alias mask if register appears in multiple banks */
79     struct regs *reg_alias;     /* If more than one register share the same address 
80                                  * then they'll point to each other. (primarily for bits)*/
81     pCodeRegLives reglives; /* live range mapping */
82   }
83 regs;
84 extern regs regspic16[];
85 extern int pic16_nRegs;
86 extern int pic16_Gstack_base_addr;
87
88 /*
89   As registers are created, they're added to a set (based on the
90   register type). Here are the sets of registers that are supported
91   in the PIC port:
92 */
93 extern set *pic16_dynAllocRegs;
94 extern set *pic16_dynStackRegs;
95 extern set *pic16_dynProcessorRegs;
96 extern set *pic16_dynDirectRegs;
97 extern set *pic16_dynDirectBitRegs;
98 extern set *pic16_dynInternalRegs;
99
100
101 regs *pic16_regWithIdx (int);
102 regs *pic16_dirregWithName (char *name );
103 void  pic16_freeAllRegs ();
104 void  pic16_deallocateAllRegs ();
105 regs *pic16_findFreeReg(short type);
106 regs *pic16_allocWithIdx (int idx);
107
108 regs *pic16_allocDirReg (operand *op );
109 regs *pic16_allocRegByName (char *name, int size );
110
111 /* Define register address that are constant across PIC16 family */
112 #define IDX_INDF0   0xfef
113 #define IDX_TMR0    0xfd6
114 #define IDX_PCL     0xff9
115 #define IDX_STATUS  0xfd8
116 #define IDX_FSR0    0xfe9
117 #define IDX_PORTA   0xf80
118 #define IDX_PORTB   0xf81
119 #define IDX_PCLATH  0xffa
120 #define IDX_INTCON  0xff2
121 #define IDX_WREG    0xfe8
122
123 #define IDX_KZ      0x7fff   /* Known zero - actually just a general purpose reg. */
124 #define IDX_WSAVE   0x7ffe
125 #define IDX_SSAVE   0x7ffd
126
127 #endif