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 case invalid_illegal
: name
= "illegal"; break;
102 case invalid_fp_unavailable
: name
= "fp_unavailable"; break;
103 case invalid_wrong_slot
: name
= "wrong_slot"; break;
105 if ((code
& generate_jumps
))
106 lf_printf(file
, "goto %s_%s;\n",
107 (code
& generate_with_icache
) ? "icache" : "semantic",
109 else if ((code
& generate_with_icache
)) {
110 lf_printf(file
, "%s %sicache_%s(", result
, global_name_prefix
, name
);
111 print_icache_function_actual(file
);
112 lf_printf(file
, ");\n");
115 lf_printf(file
, "%s %ssemantic_%s(", result
, global_name_prefix
, name
);
116 print_semantic_function_actual(file
);
117 lf_printf(file
, ");\n");
123 print_semantic_body(lf
*file
,
125 insn_bits
*expanded_bits
,
126 opcode_field
*opcodes
)
128 print_itrace(file
, instruction
->file_entry
, 0/*put_value_in_cache*/);
130 /* validate the instruction, if a cache this has already been done */
131 if (!(code
& generate_with_icache
))
132 print_idecode_validate(file
, instruction
, opcodes
);
134 /* generate the profiling call - this is delayed until after the
135 instruction has been verified */
136 lf_printf(file
, "\n");
137 lf_indent_suppress(file
);
138 lf_printf(file
, "#if defined(WITH_MON)\n");
139 lf_printf(file
, "/* monitoring: */\n");
140 lf_printf(file
, "if (WITH_MON & MONITOR_INSTRUCTION_ISSUE) {\n");
141 lf_printf(file
, " mon_issue(");
142 print_function_name(file
,
143 instruction
->file_entry
->fields
[insn_name
],
145 function_name_prefix_itable
);
146 lf_printf(file
, ", cpu, cia);\n");
147 lf_printf(file
, "}\n");
148 lf_indent_suppress(file
);
149 lf_printf(file
, "#endif\n");
150 lf_printf(file
, "\n");
152 /* determine the new instruction address */
153 lf_printf(file
, "/* keep the next instruction address handy */\n");
154 if ((code
& generate_with_semantic_returning_modified_nia_only
))
155 lf_printf(file
, "nia = -1;\n");
156 else if ((code
& generate_with_semantic_delayed_branch
)) {
157 lf_printf(file
, "nia.ip = cia.dp; /* instruction pointer */\n");
158 lf_printf(file
, "nia.dp = cia.dp + %d; /* delayed-slot pointer\n",
162 lf_printf(file
, "nia = cia + %d;\n", insn_bit_size
/ 8);
164 /* if conditional, generate code to verify that the instruction
166 if (it_is("c", instruction
->file_entry
->fields
[insn_options
])
167 || (code
& generate_with_semantic_conditional_issue
)) {
168 lf_printf(file
, "\n");
169 lf_printf(file
, "/* execute only if conditional passes */\n");
170 lf_printf(file
, "if (IS_CONDITION_OK) {\n");
172 /* FIXME - need to log a conditional failure */
175 /* generate the code (or at least something */
176 lf_printf(file
, "\n");
177 lf_printf(file
, "/* semantics: */\n");
178 if (instruction
->file_entry
->annex
!= NULL
) {
180 table_entry_print_cpp_line_nr(file
, instruction
->file_entry
);
181 lf_printf(file
, "{\n");
183 lf_print__c_code(file
, instruction
->file_entry
->annex
);
185 lf_printf(file
, "}\n");
186 lf_print__internal_reference(file
);
188 else if (it_is("nop", instruction
->file_entry
->fields
[insn_flags
])) {
189 lf_print__internal_reference(file
);
192 /* abort so it is implemented now */
193 table_entry_print_cpp_line_nr(file
, instruction
->file_entry
);
194 lf_printf(file
, "engine_error(system, \"%s:%d:0x%%08lx:%%s unimplemented\\n\",\n",
195 filter_filename(instruction
->file_entry
->file_name
),
196 instruction
->file_entry
->line_nr
);
197 lf_printf(file
, " (long)cia, itable[MY_INDEX].name);\n");
198 lf_print__internal_reference(file
);
201 /* Close off the conditional execution */
202 if (it_is("c", instruction
->file_entry
->fields
[insn_options
])
203 || (code
& generate_with_semantic_conditional_issue
)) {
205 lf_printf(file
, "}\n");
210 print_c_semantic(lf
*file
,
212 insn_bits
*expanded_bits
,
213 opcode_field
*opcodes
,
214 cache_table
*cache_rules
)
217 lf_printf(file
, "{\n");
220 print_my_defines(file
, expanded_bits
, instruction
->file_entry
);
221 lf_printf(file
, "\n");
222 print_icache_body(file
,
226 ((code
& generate_with_direct_access
)
228 : declare_variables
),
229 ((code
& generate_with_icache
)
230 ? get_values_from_icache
231 : do_not_use_icache
));
233 lf_printf(file
, "instruction_address nia;\n");
234 print_semantic_body(file
,
238 lf_printf(file
, "return nia;\n");
240 /* generate something to clean up any #defines created for the cache */
241 if (code
& generate_with_direct_access
)
242 print_icache_body(file
,
247 ((code
& generate_with_icache
)
248 ? get_values_from_icache
249 : do_not_use_icache
));
252 lf_printf(file
, "}\n");
256 print_c_semantic_function(lf
*file
,
258 insn_bits
*expanded_bits
,
259 opcode_field
*opcodes
,
260 cache_table
*cache_rules
)
262 /* build the semantic routine to execute the instruction */
263 print_semantic_function_header(file
,
264 instruction
->file_entry
->fields
[insn_name
],
266 1/*is-function-definition*/);
267 print_c_semantic(file
,
275 print_semantic_definition(insn_table
*entry
,
281 cache_table
*cache_rules
= (cache_table
*)data
;
282 if (generate_expanded_instructions
) {
283 ASSERT(entry
->nr_insn
== 1
284 && entry
->opcode
== NULL
285 && entry
->parent
!= NULL
286 && entry
->parent
->opcode
!= NULL
);
287 ASSERT(entry
->nr_insn
== 1
288 && entry
->opcode
== NULL
289 && entry
->parent
!= NULL
290 && entry
->parent
->opcode
!= NULL
291 && entry
->parent
->opcode_rule
!= NULL
);
292 print_c_semantic_function(file
,
294 entry
->expanded_bits
,
295 entry
->parent
->opcode
,
299 print_c_semantic_function(file
, instruction
,