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 enum 35 { 36 R2_IDX = 0, R3_IDX, R4_IDX, 37 R5_IDX, R6_IDX, R7_IDX, 38 R0_IDX, R1_IDX, X8_IDX, 39 X9_IDX, X10_IDX, X11_IDX, 40 X12_IDX, CND_IDX 41 }; 42 43 enum { 44 REG_PTR=1, 45 REG_GPR, 46 REG_CND, 47 REG_SFR, 48 REG_STK, 49 REG_TMP 50 }; 51 //#define REG_PTR 0x01 52 //#define REG_GPR 0x02 53 //#define REG_CND 0x04 54 //#define REG_SFR 0x08 55 //#define REG_STK 0x10 /* Use a register as a psuedo stack */ 56 //#define REG_TMP 0x20 57 58 /* definition for the registers */ 59 typedef struct reg_info 60 { 61 short type; /* can have value 62 * REG_GPR, REG_PTR or REG_CND 63 * This like the "meta-type" */ 64 short pc_type; /* pcode type */ 65 short rIdx; /* index into register table */ 66 // short otype; 67 char *name; /* name */ 68 69 unsigned isFree:1; /* is currently unassigned */ 70 unsigned wasUsed:1; /* becomes true if register has been used */ 71 unsigned isFixed:1; /* True if address can't change */ 72 // unsigned isMapped:1; /* The Register's address has been mapped to physical RAM */ 73 unsigned isBitField:1; /* True if reg is type bit OR is holder for several bits */ 74 unsigned isEmitted:1; /* True if the reg has been written to a .asm file */ 75 unsigned accessBank:1; /* True if the reg is explicit placed in access bank */ 76 unsigned isLocal:1; /* True if the reg is allocated in function's local frame */ 77 unsigned address; /* reg's address if isFixed | isMapped is true */ 78 unsigned size; /* 0 for byte, 1 for int, 4 for long */ 79 unsigned alias; /* Alias mask if register appears in multiple banks */ 80 struct reg_info *reg_alias; /* If more than one register share the same address 81 * then they'll point to each other. (primarily for bits)*/ 82 operand *regop; /* reference to the operand used to create the register */ 83 pCodeRegLives reglives; /* live range mapping */ 84 } 85 reg_info; 86 extern reg_info regspic16[]; 87 extern int pic16_nRegs; 88 extern int pic16_Gstack_base_addr; 89 90 /* 91 As registers are created, they're added to a set (based on the 92 register type). Here are the sets of registers that are supported 93 in the PIC port: 94 */ 95 extern set *pic16_dynAllocRegs; 96 extern set *pic16_dynStackRegs; 97 extern set *pic16_dynProcessorRegs; 98 extern set *pic16_dynDirectRegs; 99 extern set *pic16_dynDirectBitRegs; 100 extern set *pic16_dynInternalRegs; 101 102 extern set *pic16_builtin_functions; 103 104 extern set *pic16_rel_udata; 105 extern set *pic16_fix_udata; 106 extern set *pic16_equ_data; 107 extern set *pic16_int_regs; 108 extern set *pic16_acs_udata; 109 110 void pic16_assignRegisters(ebbIndex *ebbi); 111 reg_info *pic16_regWithIdx(int); 112 reg_info *pic16_typeRegWithIdx(int, int, int); 113 reg_info *pic16_dirregWithName(const char *name); 114 reg_info *pic16_allocregWithName(const char *name); 115 reg_info *pic16_regWithName(const char *name); 116 void pic16_freeAllRegs(void); 117 void pic16_deallocateAllRegs(void); 118 reg_info *pic16_findFreeReg(short type); 119 reg_info *pic16_findFreeRegNext(short type, reg_info *creg); 120 reg_info *pic16_allocWithIdx(int idx); 121 122 reg_info *pic16_allocDirReg (operand *op); 123 reg_info *pic16_allocRegByName (const char *name, int size, operand *op); 124 extern char *pic16_decodeOp(unsigned int op); 125 126 reg_info* newReg(int type, short pc_type, int rIdx, const char *name, unsigned size, int alias, operand *refop); 127 128 /* Define register address that are constant across PIC16 family */ 129 #define IDX_TMR0 0xfd6 130 #define IDX_STATUS 0xfd8 131 #define IDX_INTCON 0xff2 132 #define IDX_WREG 0xfe8 133 #define IDX_BSR 0xfe0 134 135 #define IDX_PCL 0xff9 136 #define IDX_PCLATH 0xffa 137 #define IDX_PCLATU 0xffb 138 139 #define IDX_TOSL 0xffd 140 #define IDX_TOSH 0xffe 141 #define IDX_TOSU 0xfff 142 143 #define IDX_TBLPTRL 0xff6 144 #define IDX_TBLPTRH 0xff7 145 #define IDX_TBLPTRU 0xff8 146 #define IDX_TABLAT 0xff5 147 148 #define IDX_FSR0 0xfe9 149 #define IDX_FSR0L 0xfe9 150 #define IDX_FSR0H 0xfea 151 152 #define IDX_FSR1 0xfe1 153 #define IDX_FSR1L 0xfe1 154 #define IDX_FSR1H 0xfe2 155 156 #define IDX_FSR2 0xfd9 157 #define IDX_FSR2L 0xfd9 158 #define IDX_FSR2H 0xfda 159 160 #define IDX_INDF0 0xfef 161 #define IDX_POSTINC0 0xfee 162 #define IDX_POSTDEC0 0xfed 163 #define IDX_PREINC0 0xfec 164 #define IDX_PLUSW0 0xfeb 165 166 #define IDX_INDF1 0xfe7 167 #define IDX_POSTINC1 0xfe6 168 #define IDX_POSTDEC1 0xfe5 169 #define IDX_PREINC1 0xfe4 170 #define IDX_PLUSW1 0xfe3 171 172 #define IDX_INDF2 0xfdf 173 #define IDX_POSTINC2 0xfde 174 #define IDX_POSTDEC2 0xfdd 175 #define IDX_PREINC2 0xfdc 176 #define IDX_PLUSW2 0xfdb 177 178 #define IDX_PRODL 0xff3 179 #define IDX_PRODH 0xff4 180 181 /* EEPROM registers */ 182 #define IDX_EECON1 0xfa6 183 #define IDX_EECON2 0xfa7 184 #define IDX_EEDATA 0xfa8 185 #define IDX_EEADR 0xfa9 186 187 #define IDX_KZ 0x7fff /* Known zero - actually just a general purpose reg. */ 188 #define IDX_WSAVE 0x7ffe 189 #define IDX_SSAVE 0x7ffd 190 191 #define IDX_GPSIMIO 0xf7f 192 #define IDX_GPSIMIO2 0xf7e 193 194 #endif 195