* src/pic/glue.c (emitInitVal): fixed #1659894 (SIGSEGV on arrays)
[fw/sdcc] / 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 #include "SDCCicode.h"
27 #include "SDCCBBlock.h"
28 #ifndef SDCCRALLOC_H
29 #define SDCCRALLOC_H 1
30
31 #include "pcoderegs.h"
32
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 regs
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   char *name;    /* name */
67
68   unsigned isFree:1;          /* is currently unassigned  */
69   unsigned wasUsed:1;         /* becomes true if register has been used */
70   unsigned isFixed:1;         /* True if address can't change */
71   unsigned isMapped:1;        /* The Register's address has been mapped to physical RAM */
72   unsigned isBitField:1;      /* True if reg is type bit OR is holder for several bits */
73   unsigned isEmitted:1;       /* True if the reg has been written to a .asm file */
74   unsigned isPublic:1;        /* True if the reg is not static and can be modified in another module (ie a another c or asm file) */
75   unsigned isExtern:1;        /* True if the reg is in another module */
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 regspic14[];
85 extern int pic14_nRegs;
86 extern int 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 *dynAllocRegs;
94 extern set *dynStackRegs;
95 extern set *dynProcessorRegs;
96 extern set *dynDirectRegs;
97 extern set *dynDirectBitRegs;
98 extern set *dynInternalRegs;
99
100
101 regs *pic14_regWithIdx (int);
102 regs *dirregWithName (char *name );
103 void  pic14_freeAllRegs ();
104 void  pic14_deallocateAllRegs ();
105 regs *pic14_findFreeReg(short type);
106 regs *pic14_allocWithIdx (int idx);
107 regs *typeRegWithIdx (int idx, int type, int fixed);
108 regs *regFindWithName (const char *name);
109
110 regs *allocDirReg (operand *op );
111 regs *allocRegByName (char *name, int size );
112 regs *allocNewDirReg (sym_link *symlnk,const char *name);
113
114 /* Define register address that are constant across PIC family */
115 #define IDX_INDF    0
116 #define IDX_TMR0    1
117 #define IDX_PCL     2
118 #define IDX_STATUS  3
119 #define IDX_FSR     4
120 #define IDX_PORTA   5
121 #define IDX_PORTB   6
122 #define IDX_PCLATH  0x0a
123 #define IDX_INTCON  0x0b
124
125 #define IDX_KZ      0x7fff   /* Known zero - actually just a general purpose reg. */
126 #define IDX_WSAVE   0x7ffe
127 #define IDX_SSAVE   0x7ffd
128 #define IDX_PSAVE   0x7ffc
129
130 #endif