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 /* Architecture expects r0 to be zero. Instead of having to check
177 every read to see if it is refering to r0 just zap the r0
179 if ((code
& generate_with_semantic_zero_r0
))
181 lf_printf (file
, "\n");
182 lf_printf (file
, "GPR(0) = 0;\n");
185 /* generate the code (or at least something */
186 lf_printf(file
, "\n");
187 lf_printf(file
, "/* semantics: */\n");
188 if (instruction
->file_entry
->annex
!= NULL
) {
190 table_entry_print_cpp_line_nr(file
, instruction
->file_entry
);
191 lf_printf(file
, "{\n");
193 lf_print__c_code(file
, instruction
->file_entry
->annex
);
195 lf_printf(file
, "}\n");
196 lf_print__internal_reference(file
);
198 else if (it_is("nop", instruction
->file_entry
->fields
[insn_flags
])) {
199 lf_print__internal_reference(file
);
202 /* abort so it is implemented now */
203 table_entry_print_cpp_line_nr(file
, instruction
->file_entry
);
204 lf_printf(file
, "sim_engine_abort (SD, CPU, cia, \"%s:%d:0x%%08lx:%%s unimplemented\\n\",\n",
205 filter_filename(instruction
->file_entry
->file_name
),
206 instruction
->file_entry
->line_nr
);
207 if ((code
& generate_with_semantic_delayed_branch
))
208 lf_printf(file
, " (long)cia.ip,\n");
210 lf_printf(file
, " (long)cia,\n");
211 lf_printf(file
, " itable[MY_INDEX].name);\n");
212 lf_print__internal_reference(file
);
215 /* Close off the conditional execution */
216 if (it_is("c", instruction
->file_entry
->fields
[insn_options
])
217 || (code
& generate_with_semantic_conditional_issue
)) {
219 lf_printf(file
, "}\n");
224 print_c_semantic(lf
*file
,
226 insn_bits
*expanded_bits
,
227 opcode_field
*opcodes
,
228 cache_table
*cache_rules
)
231 lf_printf(file
, "{\n");
234 print_my_defines(file
, expanded_bits
, instruction
->file_entry
);
235 lf_printf(file
, "\n");
236 print_icache_body(file
,
240 ((code
& generate_with_direct_access
)
242 : declare_variables
),
243 ((code
& generate_with_icache
)
244 ? get_values_from_icache
245 : do_not_use_icache
));
247 lf_printf(file
, "%sinstruction_address nia;\n", global_name_prefix
);
248 print_semantic_body(file
,
252 lf_printf(file
, "return nia;\n");
254 /* generate something to clean up any #defines created for the cache */
255 if (code
& generate_with_direct_access
)
256 print_icache_body(file
,
261 ((code
& generate_with_icache
)
262 ? get_values_from_icache
263 : do_not_use_icache
));
266 lf_printf(file
, "}\n");
270 print_c_semantic_function(lf
*file
,
272 insn_bits
*expanded_bits
,
273 opcode_field
*opcodes
,
274 cache_table
*cache_rules
)
276 /* build the semantic routine to execute the instruction */
277 print_semantic_function_header(file
,
278 instruction
->file_entry
->fields
[insn_name
],
280 1/*is-function-definition*/);
281 print_c_semantic(file
,
289 print_semantic_definition(insn_table
*entry
,
295 cache_table
*cache_rules
= (cache_table
*)data
;
296 if (generate_expanded_instructions
) {
297 ASSERT(entry
->nr_insn
== 1
298 && entry
->opcode
== NULL
299 && entry
->parent
!= NULL
300 && entry
->parent
->opcode
!= NULL
);
301 ASSERT(entry
->nr_insn
== 1
302 && entry
->opcode
== NULL
303 && entry
->parent
!= NULL
304 && entry
->parent
->opcode
!= NULL
305 && entry
->parent
->opcode_rule
!= NULL
);
306 print_c_semantic_function(file
,
308 entry
->expanded_bits
,
309 entry
->parent
->opcode
,
313 print_c_semantic_function(file
, instruction
,