2 |
7u83 |
1 |
/*
|
7 |
7u83 |
2 |
* Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
|
|
|
3 |
* All rights reserved.
|
|
|
4 |
*
|
|
|
5 |
* Redistribution and use in source and binary forms, with or without
|
|
|
6 |
* modification, are permitted provided that the following conditions are met:
|
|
|
7 |
*
|
|
|
8 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
9 |
* this list of conditions and the following disclaimer.
|
|
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
11 |
* this list of conditions and the following disclaimer in the documentation
|
|
|
12 |
* and/or other materials provided with the distribution.
|
|
|
13 |
* 3. Neither the name of The TenDRA Project nor the names of its contributors
|
|
|
14 |
* may be used to endorse or promote products derived from this software
|
|
|
15 |
* without specific, prior written permission.
|
|
|
16 |
*
|
|
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
|
|
18 |
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
19 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
|
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
22 |
* EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
23 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
24 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
25 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
26 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
27 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
28 |
*
|
|
|
29 |
* $Id$
|
|
|
30 |
*/
|
|
|
31 |
/*
|
2 |
7u83 |
32 |
Copyright (c) 1993 Open Software Foundation, Inc.
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
All Rights Reserved
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
Permission to use, copy, modify, and distribute this software
|
|
|
39 |
and its documentation for any purpose and without fee is hereby
|
|
|
40 |
granted, provided that the above copyright notice appears in all
|
|
|
41 |
copies and that both the copyright notice and this permission
|
|
|
42 |
notice appear in supporting documentation.
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
|
|
|
46 |
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
47 |
PARTICULAR PURPOSE.
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
|
|
|
51 |
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
52 |
LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
|
|
|
53 |
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
54 |
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
55 |
*/
|
|
|
56 |
|
|
|
57 |
/*
|
|
|
58 |
Crown Copyright (c) 1997
|
7 |
7u83 |
59 |
|
2 |
7u83 |
60 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
61 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
62 |
acting through the Defence Evaluation and Research Agency
|
|
|
63 |
(DERA). It is made available to Recipients with a
|
|
|
64 |
royalty-free licence for its use, reproduction, transfer
|
|
|
65 |
to other parties and amendment for any purpose not excluding
|
|
|
66 |
product development provided that any such use et cetera
|
|
|
67 |
shall be deemed to be acceptance of the following conditions:-
|
7 |
7u83 |
68 |
|
2 |
7u83 |
69 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
70 |
reproduced upon any copies or amended versions of it;
|
7 |
7u83 |
71 |
|
2 |
7u83 |
72 |
(2) Any amended version of it shall be clearly marked to
|
|
|
73 |
show both the nature of and the organisation responsible
|
|
|
74 |
for the relevant amendment or amendments;
|
7 |
7u83 |
75 |
|
2 |
7u83 |
76 |
(3) Its onward transfer from a recipient to another
|
|
|
77 |
party shall be deemed to be that party's acceptance of
|
|
|
78 |
these conditions;
|
7 |
7u83 |
79 |
|
2 |
7u83 |
80 |
(4) DERA gives no warranty or assurance as to its
|
|
|
81 |
quality or suitability for any purpose and DERA accepts
|
|
|
82 |
no liability whatsoever in relation to any use to which
|
|
|
83 |
it may be put.
|
|
|
84 |
*/
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
/**********************************************************************
|
|
|
89 |
$Author: release $
|
|
|
90 |
$Date: 1998/02/04 15:48:55 $
|
|
|
91 |
$Revision: 1.2 $
|
|
|
92 |
$Log: macro.c,v $
|
|
|
93 |
* Revision 1.2 1998/02/04 15:48:55 release
|
|
|
94 |
* Added OSF copyright message.
|
|
|
95 |
*
|
|
|
96 |
* Revision 1.1.1.1 1998/01/17 15:55:57 release
|
|
|
97 |
* First version to be checked into rolling release.
|
|
|
98 |
*
|
|
|
99 |
* Revision 1.2 1996/10/04 16:02:08 pwe
|
|
|
100 |
* add banners and mod for PWE ownership
|
|
|
101 |
*
|
|
|
102 |
**********************************************************************/
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
#include "config.h"
|
|
|
106 |
#include "memtdf.h"
|
|
|
107 |
#include "codegen.h"
|
|
|
108 |
#include "macro.h"
|
|
|
109 |
#include "stack.h"
|
|
|
110 |
#include "stdio.h"
|
|
|
111 |
#include "translat.h"
|
|
|
112 |
#include "instruct.h"
|
|
|
113 |
#include "comment.h"
|
|
|
114 |
#ifdef SHOW_FRAME_POINTER
|
|
|
115 |
static char *frame_pointer = "FP";
|
|
|
116 |
static char *top_pointer = "TP";
|
|
|
117 |
#endif
|
|
|
118 |
static char * spr_mq = "SPR_MQ";
|
|
|
119 |
static char * spr_xer = "SPR_XER";
|
|
|
120 |
static char * spr_rtcu = "SPR_RTCU";
|
|
|
121 |
static char * spr_rtcl = "SPR_RTCL";
|
|
|
122 |
static char * spr_dec = "SPR_DEC";
|
|
|
123 |
static char * spr_lr = "SPR_LR";
|
|
|
124 |
static char * spr_ctr = "SPR_CTR";
|
|
|
125 |
|
7 |
7u83 |
126 |
static char * number_array[32] ={
|
2 |
7u83 |
127 |
"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14",
|
|
|
128 |
"15","16","17","18","19","20","21","22","23","24","25","26","27",
|
|
|
129 |
"28","29","30","31"
|
|
|
130 |
};
|
|
|
131 |
|
|
|
132 |
static char * reg_array[32] = {
|
|
|
133 |
"r0","SP","RTOC","r3","r4","r5","r6","r7","r8","r9","r10","r11",
|
|
|
134 |
"r12","r13","r14","r15","r16","r17","r18","r19","r20","r21","r22",
|
|
|
135 |
"r23","r24","r25","r26","r27","r28","r29","r30","r31"
|
|
|
136 |
};
|
|
|
137 |
|
|
|
138 |
static char * freg_array[32] = {
|
|
|
139 |
"fp0","fp1","fp2","fp3","fp4","fp5","fp6","fp7","fp8","fp9","fp10",
|
|
|
140 |
"fp11","fp12","fp13","fp14","fp15","fp16","fp17","fp18","fp19",
|
|
|
141 |
"fp20","fp21","fp22","fp23","fp24","fp25","fp26","fp27","fp28",
|
|
|
142 |
"fp29","fp30","fp31"
|
|
|
143 |
};
|
|
|
144 |
|
|
|
145 |
static char * cr_array[8] = {
|
|
|
146 |
"cr0","cr1","cr2","cr3","cr4","cr5","cr6","cr7"
|
|
|
147 |
};
|
|
|
148 |
|
7 |
7u83 |
149 |
static void init_spr_macros(void);
|
2 |
7u83 |
150 |
|
|
|
151 |
int do_macros = 0;
|
7 |
7u83 |
152 |
void init_macros(void)
|
2 |
7u83 |
153 |
{
|
|
|
154 |
int r;
|
|
|
155 |
int number_per_line =0;
|
|
|
156 |
fprintf(as_file,"#\tRegister macros for easier reading and debugging\n");
|
7 |
7u83 |
157 |
|
2 |
7u83 |
158 |
#define NUMBER_OF_MACROS_PER_LINE 5
|
|
|
159 |
for (r = 0;r<=31;r++)
|
|
|
160 |
{
|
|
|
161 |
fprintf(as_file,".set %s,%d",reg_array[r],r);
|
|
|
162 |
number_per_line ++;
|
7 |
7u83 |
163 |
if (number_per_line ==NUMBER_OF_MACROS_PER_LINE)
|
2 |
7u83 |
164 |
{
|
|
|
165 |
fprintf(as_file,"\n");
|
|
|
166 |
number_per_line = 0;
|
|
|
167 |
}
|
|
|
168 |
else
|
|
|
169 |
{
|
|
|
170 |
fprintf(as_file,";");
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
fprintf(as_file,"\n");
|
7 |
7u83 |
174 |
|
2 |
7u83 |
175 |
number_per_line=0;
|
7 |
7u83 |
176 |
|
|
|
177 |
for (r = 0;r<=31;r++)
|
2 |
7u83 |
178 |
{
|
|
|
179 |
fprintf(as_file,".set %s,%d",freg_array[r],r);
|
|
|
180 |
number_per_line ++;
|
7 |
7u83 |
181 |
if (number_per_line ==NUMBER_OF_MACROS_PER_LINE)
|
2 |
7u83 |
182 |
{
|
|
|
183 |
fprintf(as_file,"\n");
|
|
|
184 |
number_per_line = 0;
|
|
|
185 |
}
|
|
|
186 |
else
|
|
|
187 |
{
|
|
|
188 |
fprintf(as_file,";");
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
fprintf(as_file,"\n");
|
|
|
192 |
number_per_line=0;
|
7 |
7u83 |
193 |
|
|
|
194 |
for (r = 0;r<=7;r++)
|
2 |
7u83 |
195 |
{
|
|
|
196 |
fprintf(as_file,".set %s,%d",cr_array[r],r);
|
|
|
197 |
number_per_line ++;
|
7 |
7u83 |
198 |
if (number_per_line ==NUMBER_OF_MACROS_PER_LINE)
|
2 |
7u83 |
199 |
{
|
|
|
200 |
fprintf(as_file,"\n");
|
|
|
201 |
number_per_line = 0;
|
|
|
202 |
}
|
|
|
203 |
else
|
|
|
204 |
{
|
|
|
205 |
fprintf(as_file,";");
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
fprintf(as_file,"\n");
|
|
|
209 |
init_spr_macros();
|
|
|
210 |
#ifdef SHOW_FRAME_POINTER
|
|
|
211 |
fprintf(as_file,".set %s,31\n",frame_pointer);
|
|
|
212 |
fprintf(as_file,".set %s,30\n",top_pointer);
|
|
|
213 |
#endif
|
|
|
214 |
return;
|
|
|
215 |
}
|
|
|
216 |
|
7 |
7u83 |
217 |
char * reg_macro(int reg)
|
2 |
7u83 |
218 |
{
|
|
|
219 |
if (!do_macros)
|
|
|
220 |
return number_array[reg];
|
|
|
221 |
else
|
|
|
222 |
{
|
|
|
223 |
#ifdef SHOW_FRAME_POINTER
|
|
|
224 |
if (reg == 31 && p_has_fp)
|
|
|
225 |
return frame_pointer;
|
|
|
226 |
if (reg == 30 && p_has_tp)
|
|
|
227 |
return top_pointer;
|
|
|
228 |
#endif
|
|
|
229 |
return reg_array[reg];
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
|
7 |
7u83 |
233 |
char * freg_macro(int reg)
|
|
|
234 |
{
|
2 |
7u83 |
235 |
if (!do_macros)
|
|
|
236 |
return number_array[reg];
|
|
|
237 |
else
|
|
|
238 |
return freg_array[reg];
|
|
|
239 |
}
|
7 |
7u83 |
240 |
char * cr_macro(int creg)
|
|
|
241 |
{
|
2 |
7u83 |
242 |
if (!do_macros)
|
|
|
243 |
return number_array[creg];
|
|
|
244 |
else
|
|
|
245 |
return cr_array[creg];
|
|
|
246 |
}
|
7 |
7u83 |
247 |
char * spr_macro(int spr)
|
2 |
7u83 |
248 |
{
|
|
|
249 |
if (!do_macros)
|
|
|
250 |
return number_array[spr];
|
|
|
251 |
else
|
|
|
252 |
{
|
|
|
253 |
switch (spr)
|
|
|
254 |
{
|
|
|
255 |
case SPR_XER:return spr_xer;
|
|
|
256 |
case SPR_MQ:return spr_mq;
|
|
|
257 |
case SPR_RTCU:return spr_rtcu;
|
|
|
258 |
case SPR_RTCL:return spr_rtcl;
|
|
|
259 |
case SPR_DEC:return spr_dec;
|
|
|
260 |
case SPR_LR:return spr_lr;
|
|
|
261 |
case SPR_CTR:return spr_ctr;
|
|
|
262 |
default:
|
|
|
263 |
fail("Unknown spr code");
|
|
|
264 |
}
|
|
|
265 |
}
|
|
|
266 |
return 0;
|
|
|
267 |
}
|
|
|
268 |
|
7 |
7u83 |
269 |
static void init_spr_macros(void)
|
2 |
7u83 |
270 |
{
|
|
|
271 |
fprintf(as_file,".set %s,%d;",spr_mq,SPR_MQ);
|
|
|
272 |
fprintf(as_file,".set %s,%d;",spr_xer,SPR_XER);
|
|
|
273 |
fprintf(as_file,".set %s,%d;",spr_rtcu,SPR_RTCU);
|
|
|
274 |
fprintf(as_file,".set %s,%d\n",spr_rtcl,SPR_RTCL);
|
|
|
275 |
fprintf(as_file,".set %s,%d;",spr_dec,SPR_DEC);
|
|
|
276 |
fprintf(as_file,".set %s,%d;",spr_lr,SPR_LR);
|
|
|
277 |
fprintf(as_file,".set %s,%d\n",spr_ctr,SPR_CTR);
|
|
|
278 |
return;
|
|
|
279 |
}
|
|
|
280 |
|
7 |
7u83 |
281 |
|