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