1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include "ld-decode.h"
34 #include "gen-semantics.h"
35 #include "gen-icache.h"
36 #include "gen-idecode.h"
40 print_semantic_function_header(lf
*file
,
42 insn_bits
*expanded_bits
,
43 int is_function_definition
)
46 lf_printf(file
, "\n");
47 lf_print_function_type_function(file
, print_semantic_function_type
, "EXTERN_SEMANTICS",
48 (is_function_definition
? "\n" : " "));
49 indent
= print_function_name(file
,
52 function_name_prefix_semantics
);
53 if (is_function_definition
)
54 lf_indent(file
, +indent
);
56 lf_printf(file
, "\n");
58 print_semantic_function_formal(file
);
60 if (is_function_definition
)
61 lf_indent(file
, -indent
);
64 lf_printf(file
, "\n");
68 print_semantic_declaration(insn_table
*entry
,
74 if (generate_expanded_instructions
) {
75 ASSERT(entry
->nr_insn
== 1);
76 print_semantic_function_header(file
,
77 instruction
->file_entry
->fields
[insn_name
],
79 0/* is not function definition*/);
82 print_semantic_function_header(file
,
83 instruction
->file_entry
->fields
[insn_name
],
85 0/* is not function definition*/);
91 /* generate the semantics.c file */
95 print_idecode_invalid(lf
*file
,
101 default: name
= "unknown"; break;
102 case invalid_illegal
: name
= "illegal"; break;
103 case invalid_fp_unavailable
: name
= "fp_unavailable"; break;
104 case invalid_wrong_slot
: name
= "wrong_slot"; break;
106 if ((code
& generate_jumps
))
107 lf_printf(file
, "goto %s_%s;\n",
108 (code
& generate_with_icache
) ? "icache" : "semantic",
110 else if ((code
& generate_with_icache
)) {
111 lf_printf(file
, "%s %sicache_%s(", result
, global_name_prefix
, name
);
112 print_icache_function_actual(file
);
113 lf_printf(file
, ");\n");
116 lf_printf(file
, "%s %ssemantic_%s(", result
, global_name_prefix
, name
);
117 print_semantic_function_actual(file
);
118 lf_printf(file
, ");\n");
124 print_semantic_body(lf
*file
,
126 insn_bits
*expanded_bits
,
127 opcode_field
*opcodes
)
129 print_itrace(file
, instruction
->file_entry
, 0/*put_value_in_cache*/);
131 /* validate the instruction, if a cache this has already been done */
132 if (!(code
& generate_with_icache
))
133 print_idecode_validate(file
, instruction
, opcodes
);
135 /* generate the profiling call - this is delayed until after the
136 instruction has been verified */
137 lf_printf(file
, "\n");
138 lf_indent_suppress(file
);
139 lf_printf(file
, "#if defined(WITH_MON)\n");
140 lf_printf(file
, "/* monitoring: */\n");
141 lf_printf(file
, "if (WITH_MON & MONITOR_INSTRUCTION_ISSUE) {\n");
142 lf_printf(file
, " mon_issue(");
143 print_function_name(file
,
144 instruction
->file_entry
->fields
[insn_name
],
146 function_name_prefix_itable
);
147 lf_printf(file
, ", cpu, cia);\n");
148 lf_printf(file
, "}\n");
149 lf_indent_suppress(file
);
150 lf_printf(file
, "#endif\n");
151 lf_printf(file
, "\n");
153 /* determine the new instruction address */
154 lf_printf(file
, "/* keep the next instruction address handy */\n");
155 if ((code
& generate_with_semantic_returning_modified_nia_only
))
156 lf_printf(file
, "nia = -1;\n");
157 else if ((code
& generate_with_semantic_delayed_branch
)) {
158 lf_printf(file
, "nia.ip = cia.dp; /* instruction pointer */\n");
159 lf_printf(file
, "nia.dp = cia.dp + %d; /* delayed-slot pointer */\n",
163 lf_printf(file
, "nia = cia + %d;\n", insn_bit_size
/ 8);
165 /* if conditional, generate code to verify that the instruction
167 if (it_is("c", instruction
->file_entry
->fields
[insn_options
])
168 || (code
& generate_with_semantic_conditional_issue
)) {
169 lf_printf(file
, "\n");
170 lf_printf(file
, "/* execute only if conditional passes */\n");
171 lf_printf(file
, "if (IS_CONDITION_OK) {\n");
173 /* FIXME - need to log a conditional failure */
176 /* generate the code (or at least something */
177 lf_printf(file
, "\n");
178 lf_printf(file
, "/* semantics: */\n");
179 if (instruction
->file_entry
->annex
!= NULL
) {
181 table_entry_print_cpp_line_nr(file
, instruction
->file_entry
);
182 lf_printf(file
, "{\n");
184 lf_print__c_code(file
, instruction
->file_entry
->annex
);
186 lf_printf(file
, "}\n");
187 lf_print__internal_reference(file
);
189 else if (it_is("nop", instruction
->file_entry
->fields
[insn_flags
])) {
190 lf_print__internal_reference(file
);
193 /* abort so it is implemented now */
194 table_entry_print_cpp_line_nr(file
, instruction
->file_entry
);
195 lf_printf(file
, "engine_error (SD, CPU, cia, \"%s:%d:0x%%08lx:%%s unimplemented\\n\",\n",
196 filter_filename(instruction
->file_entry
->file_name
),
197 instruction
->file_entry
->line_nr
);
198 if ((code
& generate_with_semantic_delayed_branch
))
199 lf_printf(file
, " (long)cia.ip,\n");
201 lf_printf(file
, " (long)cia,\n");
202 lf_printf(file
, " itable[MY_INDEX].name);\n");
203 lf_print__internal_reference(file
);
206 /* Close off the conditional execution */
207 if (it_is("c", instruction
->file_entry
->fields
[insn_options
])
208 || (code
& generate_with_semantic_conditional_issue
)) {
210 lf_printf(file
, "}\n");
215 print_c_semantic(lf
*file
,
217 insn_bits
*expanded_bits
,
218 opcode_field
*opcodes
,
219 cache_table
*cache_rules
)
222 lf_printf(file
, "{\n");
225 print_my_defines(file
, expanded_bits
, instruction
->file_entry
);
226 lf_printf(file
, "\n");
227 print_icache_body(file
,
231 ((code
& generate_with_direct_access
)
233 : declare_variables
),
234 ((code
& generate_with_icache
)
235 ? get_values_from_icache
236 : do_not_use_icache
));
238 lf_printf(file
, "%sinstruction_address nia;\n", global_name_prefix
);
239 print_semantic_body(file
,
243 lf_printf(file
, "return nia;\n");
245 /* generate something to clean up any #defines created for the cache */
246 if (code
& generate_with_direct_access
)
247 print_icache_body(file
,
252 ((code
& generate_with_icache
)
253 ? get_values_from_icache
254 : do_not_use_icache
));
257 lf_printf(file
, "}\n");
261 print_c_semantic_function(lf
*file
,
263 insn_bits
*expanded_bits
,
264 opcode_field
*opcodes
,
265 cache_table
*cache_rules
)
267 /* build the semantic routine to execute the instruction */
268 print_semantic_function_header(file
,
269 instruction
->file_entry
->fields
[insn_name
],
271 1/*is-function-definition*/);
272 print_c_semantic(file
,
280 print_semantic_definition(insn_table
*entry
,
286 cache_table
*cache_rules
= (cache_table
*)data
;
287 if (generate_expanded_instructions
) {
288 ASSERT(entry
->nr_insn
== 1
289 && entry
->opcode
== NULL
290 && entry
->parent
!= NULL
291 && entry
->parent
->opcode
!= NULL
);
292 ASSERT(entry
->nr_insn
== 1
293 && entry
->opcode
== NULL
294 && entry
->parent
!= NULL
295 && entry
->parent
->opcode
!= NULL
296 && entry
->parent
->opcode_rule
!= NULL
);
297 print_c_semantic_function(file
,
299 entry
->expanded_bits
,
300 entry
->parent
->opcode
,
304 print_c_semantic_function(file
, instruction
,