1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, 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(file, 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");
57 lf_printf(file, "(%s)", SEMANTIC_FUNCTION_FORMAL);
58 if (is_function_definition)
59 lf_indent(file, -indent);
62 lf_printf(file, "\n");
66 print_semantic_declaration(insn_table *entry,
72 if (generate_expanded_instructions) {
73 ASSERT(entry->nr_insn == 1);
74 print_semantic_function_header(file,
75 instruction->file_entry->fields[insn_name],
77 0/* is not function definition*/);
80 print_semantic_function_header(file,
81 instruction->file_entry->fields[insn_name],
83 0/* is not function definition*/);
89 /* generate the semantics.c file */
93 print_idecode_illegal(lf *file,
96 if ((code & generate_jumps))
97 lf_printf(file, "goto %s_illegal;\n", (code & generate_with_icache) ? "icache" : "semantic");
98 else if ((code & generate_with_icache))
99 lf_printf(file, "%s icache_illegal(%s);\n", result, ICACHE_FUNCTION_ACTUAL);
101 lf_printf(file, "%s semantic_illegal(%s);\n", result, SEMANTIC_FUNCTION_ACTUAL);
106 print_semantic_body(lf *file,
108 insn_bits *expanded_bits,
109 opcode_field *opcodes)
111 print_itrace(file, instruction->file_entry, 0/*put_value_in_cache*/);
113 /* validate the instruction, if a cache this has already been done */
114 if (!(code & generate_with_icache))
115 print_idecode_validate(file, instruction, opcodes);
117 /* generate the profiling call - this is delayed until after the
118 instruction has been verified */
119 lf_printf(file, "\n");
120 lf_printf(file, "/* monitoring: */\n");
121 lf_printf(file, "if (WITH_MON & MONITOR_INSTRUCTION_ISSUE) {\n");
122 lf_printf(file, " mon_issue(");
123 print_function_name(file,
124 instruction->file_entry->fields[insn_name],
126 function_name_prefix_itable);
127 lf_printf(file, ", processor, cia);\n");
128 lf_printf(file, "}\n");
130 /* generate the code (or at least something */
131 lf_printf(file, "\n");
132 lf_printf(file, "/* semantics: */\n");
133 lf_printf(file, "nia = cia + %d;\n", insn_bit_size / 8);
134 if (instruction->file_entry->annex != NULL) {
136 table_entry_print_cpp_line_nr(file, instruction->file_entry);
137 lf_printf(file, "{\n");
139 lf_print__c_code(file, instruction->file_entry->annex);
141 lf_printf(file, "}\n");
142 lf_print__internal_reference(file);
144 else if (it_is("nop", instruction->file_entry->fields[insn_flags])) {
145 lf_print__internal_reference(file);
147 else if (it_is("f", instruction->file_entry->fields[insn_flags])) {
148 /* unimplemented floating point instruction - call for assistance */
149 lf_printf(file, "/* unimplemented floating point instruction - call for assistance */\n");
150 table_entry_print_cpp_line_nr(file, instruction->file_entry);
151 lf_putstr(file, "floating_point_assist_interrupt(processor, cia);\n");
152 lf_print__internal_reference(file);
155 /* abort so it is implemented now */
156 table_entry_print_cpp_line_nr(file, instruction->file_entry);
157 lf_putstr(file, "error(\"%s:%d:0x%08lx:%s unimplemented\\n\",\n");
158 lf_printf(file, " itable[MY_INDEX].file, itable[MY_INDEX].line_nr, (long)cia, itable[MY_INDEX].name);\n");
159 lf_print__internal_reference(file);
164 print_c_semantic(lf *file,
166 insn_bits *expanded_bits,
167 opcode_field *opcodes,
168 cache_table *cache_rules)
171 lf_printf(file, "{\n");
174 print_define_my_index(file, instruction->file_entry);
175 lf_printf(file, "\n");
176 print_icache_body(file,
180 (code & generate_with_direct_access_icache),
181 (code & generate_with_icache)/*get_value_from_cache*/,
182 0/*put_value_in_cache*/);
184 lf_printf(file, "unsigned_word nia;\n");
185 print_semantic_body(file,
189 lf_printf(file, "return nia;\n");
191 /* generate something to clean up any #defines created for the cache */
192 if ((code & generate_with_direct_access_icache))
193 print_icache_body(file,
198 0/*get_value_from_cache*/,
199 1/*put_value_in_cache*/);
202 lf_printf(file, "}\n");
206 print_c_semantic_function(lf *file,
208 insn_bits *expanded_bits,
209 opcode_field *opcodes,
210 cache_table *cache_rules)
212 /* build the semantic routine to execute the instruction */
213 print_semantic_function_header(file,
214 instruction->file_entry->fields[insn_name],
216 1/*is-function-definition*/);
217 print_c_semantic(file,
225 print_semantic_definition(insn_table *entry,
231 cache_table *cache_rules = (cache_table*)data;
232 if (generate_expanded_instructions) {
233 ASSERT(entry->nr_insn == 1
234 && entry->opcode == NULL
235 && entry->parent != NULL
236 && entry->parent->opcode != NULL);
237 ASSERT(entry->nr_insn == 1
238 && entry->opcode == NULL
239 && entry->parent != NULL
240 && entry->parent->opcode != NULL
241 && entry->parent->opcode_rule != NULL);
242 print_c_semantic_function(file,
244 entry->expanded_bits,
245 entry->parent->opcode,
249 print_c_semantic_function(file, instruction,