xref: /netbsd-src/external/bsd/pcc/dist/pcc/arch/pdp11/macdefs.h (revision 411dcbec990c8aa9c57d3bd2f4bcacadec0b1ab5)
1 /*	Id: macdefs.h,v 1.10 2015/11/24 17:35:12 ragge Exp 	*/
2 /*	$NetBSD: macdefs.h,v 1.1.1.5 2016/02/09 20:28:27 plunky Exp $	*/
3 /*
4  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * Machine-dependent defines for both passes.
32  */
33 
34 /*
35  * Convert (multi-)character constant to integer.
36  */
37 #define makecc(val,i)	lastcon = i ? (val<<8)|lastcon : val
38 
39 #define ARGINIT		32	/* # bits above r5 where arguments start */
40 #define AUTOINIT	64	/* # bits below r5 where automatics start */
41 
42 /*
43  * Storage space requirements
44  */
45 #define SZCHAR		8
46 #define SZBOOL		8
47 #define SZINT		16
48 #define SZFLOAT		32
49 #define SZDOUBLE	64
50 #define SZLDOUBLE	64
51 #define SZLONG		32
52 #define SZSHORT		16
53 #define SZLONGLONG	64
54 #define SZPOINT(t)	16
55 
56 /*
57  * Alignment constraints
58  */
59 #define ALCHAR		8
60 #define ALBOOL		8
61 #define ALINT		16
62 #define ALFLOAT		16
63 #define ALDOUBLE	16
64 #define ALLDOUBLE	16
65 #define ALLONG		16
66 #define ALLONGLONG	16
67 #define ALSHORT		16
68 #define ALPOINT		16
69 #define ALSTRUCT	16
70 #define ALSTACK		16
71 
72 /*
73  * Min/max values.
74  */
75 #define	MIN_CHAR	-128
76 #define	MAX_CHAR	127
77 #define	MAX_UCHAR	255
78 #define	MIN_SHORT	-32768
79 #define	MAX_SHORT	32767
80 #define	MAX_USHORT	65535
81 #define	MIN_INT		(-0x7fff-1)
82 #define	MAX_INT		0x7fff
83 #define	MAX_UNSIGNED	0xffff
84 #define	MIN_LONG	(-0x7fffffff-1)
85 #define	MAX_LONG	0x7fffffff
86 #define	MAX_ULONG	0xffffffff
87 #define	MIN_LONGLONG	0x8000000000000000LL
88 #define	MAX_LONGLONG	0x7fffffffffffffffLL
89 #define	MAX_ULONGLONG	0xffffffffffffffffULL
90 
91 /* Default char is signed */
92 #undef	CHAR_UNSIGNED
93 #define	BOOL_TYPE	CHAR	/* what used to store _Bool */
94 
95 /*
96  * Use large-enough types.
97  */
98 typedef	long long CONSZ;
99 typedef	unsigned long long U_CONSZ;
100 typedef long long OFFSZ;
101 
102 #define CONFMT	"%lld"		/* format for printing constants */
103 #define LABFMT	"L%d"		/* format for printing labels */
104 #ifdef LANG_F77
105 #define BLANKCOMMON "_BLNK_"
106 #define MSKIREG  (M(TYSHORT)|M(TYLONG))
107 #define TYIREG TYLONG
108 #define FSZLENG  FSZLONG
109 #define	AUTOREG	EBP
110 #define	ARGREG	EBP
111 #define ARGOFFSET 8
112 #endif
113 
114 #define BACKAUTO 		/* stack grows negatively for automatics */
115 #define BACKTEMP 		/* stack grows negatively for temporaries */
116 
117 #undef	FIELDOPS		/* no bit-field instructions */
118 #define TARGET_ENDIAN TARGET_LE /* XXX TARGET_PDP */
119 #define	MYINSTRING
120 #define	MYALIGN
121 
122 /* Definitions mostly used in pass2 */
123 
124 #define BYTEOFF(x)	((x)&01)
125 #define wdal(k)		(BYTEOFF(k)==0)
126 
127 #define STOARG(p)
128 #define STOFARG(p)
129 #define STOSTARG(p)
130 
131 #define	FINDMOPS	/* pdp11 has instructions that modifies memory */
132 
133 #define szty(t) ((t) == DOUBLE || (t) == LONGLONG || (t) == ULONGLONG ? 4 : \
134 	(t) == FLOAT || (t) == LONG || (t) == ULONG ? 2 : 1)
135 
136 /*
137  * The pdp11 has 3 register classes, 16-bit, 32-bit and floats.
138  * Class membership and overlaps are defined in the macros RSTATUS
139  * and ROVERLAP below.
140  *
141  * The classes used on pdp11 are:
142  *	A - 16-bit
143  *	B - 32-bit (concatenated 16-bit)
144  *	C - floating point
145  */
146 #define	R0	000	/* Scratch and return register */
147 #define	R1	001	/* Scratch and secondary return register */
148 #define	R2	002	/* Scratch register */
149 #define	R3	003	/* Scratch register */
150 #define	R4	004	/* Scratch register */
151 #define	R5	005	/* Frame pointer */
152 #define	SP	006	/* Stack pointer */
153 #define	PC	007	/* Program counter */
154 
155 #define	R01	010
156 #define	R12	011
157 #define	R23	012
158 #define	R34	013
159 
160 #define	FR0	020
161 #define	FR1	021
162 #define	FR2	022
163 #define	FR3	023
164 #define	FR4	024
165 #define	FR5	025
166 #define	FR6	026
167 #define	FR7	027
168 
169 #define	MAXREGS	030	/* 24 registers */
170 
171 #define	RSTATUS	\
172 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG, SAREG, SAREG, 0, 0, 0, \
173 	SBREG, SBREG, SBREG, SBREG, 0, 0, 0, 0,		\
174 	SCREG, SCREG, SCREG, SCREG, 0, 0, 0, 0
175 
176 #define	ROVERLAP \
177 	/* 8 basic registers */\
178 	{ R01, -1 },		\
179 	{ R01, R12, -1 },	\
180 	{ R12, R23, -1 },	\
181 	{ R23, R34, -1 },	\
182 	{ R34, -1 },		\
183 	{ -1 },			\
184 	{ -1 },			\
185 	{ -1 },			\
186 \
187 	/* 4 long registers */\
188 	{ R0, R1, R12, -1 },		\
189 	{ R1, R2, R01, R23, -1 },		\
190 	{ R2, R3, R12, R34, -1 },		\
191 	{ R3, R4, R23, -1 },		\
192 	{ -1 },			\
193 	{ -1 },			\
194 	{ -1 },			\
195 	{ -1 },			\
196 \
197 	/* The fp registers do not overlap with anything */\
198 	{ -1 },\
199 	{ -1 },\
200 	{ -1 },\
201 	{ -1 },\
202 	{ -1 },\
203 	{ -1 },\
204 	{ -1 },\
205 	{ -1 },
206 
207 
208 /* Return a register class based on the type of the node */
209 
210 #define PCLASS(p) (p->n_type < LONG || p->n_type > BTMASK ? SAREG : \
211 		  (p->n_type == LONG || p->n_type == ULONG ? SBREG : SCREG))
212 
213 #define	NUMCLASS 	3	/* highest number of reg classes used */
214 
215 int COLORMAP(int c, int *r);
216 #define	GCLASS(x) (x < 8 ? CLASSA : x < 16 ? CLASSB : CLASSC)
217 #define DECRA(x,y)	(((x) >> (y*5)) & 31)	/* decode encoded regs */
218 #define	ENCRD(x)	(x)		/* Encode dest reg in n_reg */
219 #define ENCRA1(x)	((x) << 5)	/* A1 */
220 #define ENCRA2(x)	((x) << 10)	/* A2 */
221 #define ENCRA(x,y)	((x) << (5+y*5))	/* encode regs in int */
222 #define	RETREG(x)	((x) == LONG || (x) == ULONG ? R01 : \
223 	(x) == FLOAT || (x) == DOUBLE ? FR0 : R0)
224 
225 //#define R2REGS	1	/* permit double indexing */
226 
227 /* XXX - to die */
228 #define FPREG	R5	/* frame pointer */
229 #define STKREG	SP	/* stack pointer */
230 
231 /* A bunch of specials to make life easier for pdp11 */
232 #define	SANDSCON	(MAXSPECIAL+1)
233 #define	SINCB		(MAXSPECIAL+2)	/* post-increment */
234 #define	SINCW		(MAXSPECIAL+3)	/* post-increment */
235 #define	SARGSUB		(MAXSPECIAL+4)	/* arg pointer to array */
236 #define	SARGINC		(MAXSPECIAL+5)	/* post-increment arg */
237 #define NATIVE_FLOATING_POINT
238