]>
Commit | Line | Data |
---|---|---|
15c16493 AC |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au> | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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. | |
18 | ||
19 | */ | |
20 | ||
21 | ||
22 | ||
23 | #include "misc.h" | |
24 | #include "lf.h" | |
25 | #include "table.h" | |
26 | #include "filter.h" | |
27 | ||
28 | #include "ld-decode.h" | |
29 | #include "ld-cache.h" | |
30 | #include "ld-insn.h" | |
31 | ||
32 | #include "igen.h" | |
33 | ||
34 | #include "gen-semantics.h" | |
35 | #include "gen-icache.h" | |
36 | #include "gen-idecode.h" | |
37 | ||
38 | ||
39 | static void | |
40 | print_semantic_function_header(lf *file, | |
41 | const char *basename, | |
42 | insn_bits *expanded_bits, | |
43 | int is_function_definition) | |
44 | { | |
45 | int indent; | |
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, | |
50 | basename, | |
51 | expanded_bits, | |
52 | function_name_prefix_semantics); | |
53 | if (is_function_definition) | |
54 | lf_indent(file, +indent); | |
55 | else | |
56 | lf_printf(file, "\n"); | |
57 | lf_printf(file, "("); | |
58 | print_semantic_function_formal(file); | |
59 | lf_printf(file, ")"); | |
60 | if (is_function_definition) | |
61 | lf_indent(file, -indent); | |
62 | else | |
63 | lf_printf(file, ";"); | |
64 | lf_printf(file, "\n"); | |
65 | } | |
66 | ||
67 | void | |
68 | print_semantic_declaration(insn_table *entry, | |
69 | lf *file, | |
70 | void *data, | |
71 | insn *instruction, | |
72 | int depth) | |
73 | { | |
74 | if (generate_expanded_instructions) { | |
75 | ASSERT(entry->nr_insn == 1); | |
76 | print_semantic_function_header(file, | |
77 | instruction->file_entry->fields[insn_name], | |
78 | entry->expanded_bits, | |
79 | 0/* is not function definition*/); | |
80 | } | |
81 | else { | |
82 | print_semantic_function_header(file, | |
83 | instruction->file_entry->fields[insn_name], | |
84 | NULL, | |
85 | 0/* is not function definition*/); | |
86 | } | |
87 | } | |
88 | ||
89 | ||
90 | \f | |
91 | /* generate the semantics.c file */ | |
92 | ||
93 | ||
94 | void | |
95 | print_idecode_invalid(lf *file, | |
96 | const char *result, | |
97 | invalid_type type) | |
98 | { | |
99 | const char *name; | |
100 | switch (type) { | |
d23af882 | 101 | default: name = "unknown"; break; |
15c16493 AC |
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; | |
105 | } | |
106 | if ((code & generate_jumps)) | |
107 | lf_printf(file, "goto %s_%s;\n", | |
108 | (code & generate_with_icache) ? "icache" : "semantic", | |
109 | name); | |
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"); | |
114 | } | |
115 | else { | |
116 | lf_printf(file, "%s %ssemantic_%s(", result, global_name_prefix, name); | |
117 | print_semantic_function_actual(file); | |
118 | lf_printf(file, ");\n"); | |
119 | } | |
120 | } | |
121 | ||
122 | ||
123 | void | |
124 | print_semantic_body(lf *file, | |
125 | insn *instruction, | |
126 | insn_bits *expanded_bits, | |
127 | opcode_field *opcodes) | |
128 | { | |
129 | print_itrace(file, instruction->file_entry, 0/*put_value_in_cache*/); | |
130 | ||
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); | |
134 | ||
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], | |
145 | NULL, | |
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"); | |
152 | ||
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"); | |
d23af882 | 159 | lf_printf(file, "nia.dp = cia.dp + %d; /* delayed-slot pointer */\n", |
15c16493 AC |
160 | insn_bit_size / 8); |
161 | } | |
162 | else | |
163 | lf_printf(file, "nia = cia + %d;\n", insn_bit_size / 8); | |
164 | ||
165 | /* if conditional, generate code to verify that the instruction | |
166 | should be issued */ | |
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"); | |
172 | lf_indent(file, +2); | |
173 | /* FIXME - need to log a conditional failure */ | |
174 | } | |
175 | ||
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) { | |
180 | /* true code */ | |
181 | table_entry_print_cpp_line_nr(file, instruction->file_entry); | |
182 | lf_printf(file, "{\n"); | |
183 | lf_indent(file, +2); | |
184 | lf_print__c_code(file, instruction->file_entry->annex); | |
185 | lf_indent(file, -2); | |
186 | lf_printf(file, "}\n"); | |
187 | lf_print__internal_reference(file); | |
188 | } | |
189 | else if (it_is("nop", instruction->file_entry->fields[insn_flags])) { | |
190 | lf_print__internal_reference(file); | |
191 | } | |
192 | else { | |
193 | /* abort so it is implemented now */ | |
194 | table_entry_print_cpp_line_nr(file, instruction->file_entry); | |
d23af882 | 195 | lf_printf(file, "engine_error (SD, CPU, cia, \"%s:%d:0x%%08lx:%%s unimplemented\\n\",\n", |
15c16493 AC |
196 | filter_filename(instruction->file_entry->file_name), |
197 | instruction->file_entry->line_nr); | |
d23af882 MM |
198 | if ((code & generate_with_semantic_delayed_branch)) |
199 | lf_printf(file, " (long)cia.ip,\n"); | |
200 | else | |
201 | lf_printf(file, " (long)cia,\n"); | |
202 | lf_printf(file, " itable[MY_INDEX].name);\n"); | |
15c16493 AC |
203 | lf_print__internal_reference(file); |
204 | } | |
205 | ||
206 | /* Close off the conditional execution */ | |
207 | if (it_is("c", instruction->file_entry->fields[insn_options]) | |
208 | || (code & generate_with_semantic_conditional_issue)) { | |
209 | lf_indent(file, -2); | |
210 | lf_printf(file, "}\n"); | |
211 | } | |
212 | } | |
213 | ||
214 | static void | |
215 | print_c_semantic(lf *file, | |
216 | insn *instruction, | |
217 | insn_bits *expanded_bits, | |
218 | opcode_field *opcodes, | |
219 | cache_table *cache_rules) | |
220 | { | |
221 | ||
222 | lf_printf(file, "{\n"); | |
223 | lf_indent(file, +2); | |
224 | ||
225 | print_my_defines(file, expanded_bits, instruction->file_entry); | |
226 | lf_printf(file, "\n"); | |
227 | print_icache_body(file, | |
228 | instruction, | |
229 | expanded_bits, | |
230 | cache_rules, | |
231 | ((code & generate_with_direct_access) | |
232 | ? define_variables | |
233 | : declare_variables), | |
234 | ((code & generate_with_icache) | |
235 | ? get_values_from_icache | |
236 | : do_not_use_icache)); | |
237 | ||
d23af882 | 238 | lf_printf(file, "%sinstruction_address nia;\n", global_name_prefix); |
15c16493 AC |
239 | print_semantic_body(file, |
240 | instruction, | |
241 | expanded_bits, | |
242 | opcodes); | |
243 | lf_printf(file, "return nia;\n"); | |
244 | ||
245 | /* generate something to clean up any #defines created for the cache */ | |
246 | if (code & generate_with_direct_access) | |
247 | print_icache_body(file, | |
248 | instruction, | |
249 | expanded_bits, | |
250 | cache_rules, | |
251 | undef_variables, | |
252 | ((code & generate_with_icache) | |
253 | ? get_values_from_icache | |
254 | : do_not_use_icache)); | |
255 | ||
256 | lf_indent(file, -2); | |
257 | lf_printf(file, "}\n"); | |
258 | } | |
259 | ||
260 | static void | |
261 | print_c_semantic_function(lf *file, | |
262 | insn *instruction, | |
263 | insn_bits *expanded_bits, | |
264 | opcode_field *opcodes, | |
265 | cache_table *cache_rules) | |
266 | { | |
267 | /* build the semantic routine to execute the instruction */ | |
268 | print_semantic_function_header(file, | |
269 | instruction->file_entry->fields[insn_name], | |
270 | expanded_bits, | |
271 | 1/*is-function-definition*/); | |
272 | print_c_semantic(file, | |
273 | instruction, | |
274 | expanded_bits, | |
275 | opcodes, | |
276 | cache_rules); | |
277 | } | |
278 | ||
279 | void | |
280 | print_semantic_definition(insn_table *entry, | |
281 | lf *file, | |
282 | void *data, | |
283 | insn *instruction, | |
284 | int depth) | |
285 | { | |
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, | |
298 | entry->insns, | |
299 | entry->expanded_bits, | |
300 | entry->parent->opcode, | |
301 | cache_rules); | |
302 | } | |
303 | else { | |
304 | print_c_semantic_function(file, instruction, | |
305 | NULL, NULL, | |
306 | cache_rules); | |
307 | } | |
308 | } |