]>
Commit | Line | Data |
---|---|---|
feaee4bd AC |
1 | /* The IGEN simulator generator for GDB, the GNU Debugger. |
2 | ||
6aba47ca | 3 | Copyright 2002, 2007 Free Software Foundation, Inc. |
feaee4bd AC |
4 | |
5 | Contributed by Andrew Cagney. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
21 | Foundation, Inc., 59 Temple Place - Suite 330, | |
22 | Boston, MA 02111-1307, USA. */ | |
23 | ||
c906108c SS |
24 | |
25 | #include "misc.h" | |
26 | #include "lf.h" | |
27 | #include "table.h" | |
28 | #include "filter.h" | |
29 | ||
30 | #include "igen.h" | |
31 | ||
32 | #include "ld-insn.h" | |
33 | #include "ld-decode.h" | |
34 | ||
35 | #include "gen.h" | |
36 | ||
37 | #include "gen-semantics.h" | |
38 | #include "gen-support.h" | |
39 | ||
40 | static void | |
41 | print_support_function_name (lf *file, | |
4e0bf4c4 | 42 | function_entry * function, |
c906108c SS |
43 | int is_function_definition) |
44 | { | |
45 | if (function->is_internal) | |
46 | { | |
47 | lf_print__function_type_function (file, print_semantic_function_type, | |
48 | "INLINE_SUPPORT", | |
4e0bf4c4 AC |
49 | (is_function_definition ? "\n" : |
50 | " ")); | |
51 | print_function_name (file, function->name, NULL, NULL, NULL, | |
c906108c SS |
52 | function_name_prefix_semantics); |
53 | lf_printf (file, "\n("); | |
54 | lf_indent (file, +1); | |
55 | print_semantic_function_formal (file, 0); | |
56 | lf_indent (file, -1); | |
57 | lf_printf (file, ")"); | |
58 | if (!is_function_definition) | |
59 | lf_printf (file, ";"); | |
60 | lf_printf (file, "\n"); | |
61 | } | |
62 | else | |
63 | { | |
64 | /* map the name onto a globally valid name */ | |
65 | if (!is_function_definition | |
66 | && strcmp (options.module.support.prefix.l, "") != 0) | |
67 | { | |
68 | lf_indent_suppress (file); | |
69 | lf_printf (file, "#define %s %s%s\n", | |
70 | function->name, | |
4e0bf4c4 | 71 | options.module.support.prefix.l, function->name); |
c906108c SS |
72 | } |
73 | lf_print__function_type (file, | |
74 | function->type, | |
75 | "INLINE_SUPPORT", | |
76 | (is_function_definition ? "\n" : " ")); | |
77 | lf_printf (file, "%s%s\n(", | |
4e0bf4c4 | 78 | options.module.support.prefix.l, function->name); |
c906108c SS |
79 | if (options.gen.smp) |
80 | lf_printf (file, | |
81 | "sim_cpu *cpu, %sinstruction_address cia, int MY_INDEX", | |
82 | options.module.support.prefix.l); | |
83 | else | |
84 | lf_printf (file, | |
85 | "SIM_DESC sd, %sinstruction_address cia, int MY_INDEX", | |
86 | options.module.support.prefix.l); | |
4e0bf4c4 | 87 | if (function->param != NULL && strlen (function->param) > 0) |
c906108c SS |
88 | lf_printf (file, ", %s", function->param); |
89 | lf_printf (file, ")%s", (is_function_definition ? "\n" : ";\n")); | |
90 | } | |
91 | } | |
92 | ||
93 | ||
94 | static void | |
4e0bf4c4 | 95 | support_h_function (lf *file, function_entry * function, void *data) |
c906108c SS |
96 | { |
97 | ASSERT (function->type != NULL); | |
4e0bf4c4 AC |
98 | print_support_function_name (file, function, 0 /*!is_definition */ ); |
99 | lf_printf (file, "\n"); | |
c906108c SS |
100 | } |
101 | ||
102 | ||
103 | extern void | |
4e0bf4c4 | 104 | gen_support_h (lf *file, insn_table *table) |
c906108c | 105 | { |
4e0bf4c4 AC |
106 | /* output the definition of `SD_' */ |
107 | if (options.gen.smp) | |
c906108c | 108 | { |
4e0bf4c4 AC |
109 | lf_printf (file, "#define SD CPU_STATE (cpu)\n"); |
110 | lf_printf (file, "#define CPU cpu\n"); | |
111 | lf_printf (file, "#define CPU_ cpu\n"); | |
c906108c SS |
112 | } |
113 | else | |
114 | { | |
4e0bf4c4 AC |
115 | lf_printf (file, "#define SD sd\n"); |
116 | lf_printf (file, "#define CPU (STATE_CPU (sd, 0))\n"); | |
117 | lf_printf (file, "#define CPU_ sd\n"); | |
c906108c SS |
118 | } |
119 | ||
4e0bf4c4 | 120 | lf_printf (file, "#define CIA_ cia\n"); |
c906108c SS |
121 | if (options.gen.delayed_branch) |
122 | { | |
4e0bf4c4 AC |
123 | lf_printf (file, "#define CIA cia.ip\n"); |
124 | lf_printf (file, | |
125 | "/* #define NIA nia.dp -- do not define, ambigious */\n"); | |
c906108c SS |
126 | } |
127 | else | |
128 | { | |
4e0bf4c4 AC |
129 | lf_printf (file, "#define CIA cia\n"); |
130 | lf_printf (file, "#define NIA nia\n"); | |
c906108c | 131 | } |
4e0bf4c4 | 132 | lf_printf (file, "\n"); |
c906108c | 133 | |
4e0bf4c4 AC |
134 | lf_printf (file, "#define SD_ CPU_, CIA_, MY_INDEX\n"); |
135 | lf_printf (file, "#define _SD SD_ /* deprecated */\n"); | |
136 | lf_printf (file, "\n"); | |
c906108c | 137 | |
051b807a DB |
138 | /* Map <PREFIX>_xxxx onto the shorter xxxx for the following names: |
139 | ||
4e0bf4c4 AC |
140 | instruction_word |
141 | idecode_issue | |
142 | semantic_illegal | |
051b807a DB |
143 | |
144 | Map defined here as name space problems are created when the name is | |
145 | defined in idecode.h */ | |
c906108c SS |
146 | if (strcmp (options.module.idecode.prefix.l, "") != 0) |
147 | { | |
148 | lf_indent_suppress (file); | |
149 | lf_printf (file, "#define %s %s%s\n", | |
150 | "instruction_word", | |
4e0bf4c4 | 151 | options.module.idecode.prefix.l, "instruction_word"); |
c906108c SS |
152 | lf_printf (file, "\n"); |
153 | lf_indent_suppress (file); | |
154 | lf_printf (file, "#define %s %s%s\n", | |
155 | "idecode_issue", | |
4e0bf4c4 | 156 | options.module.idecode.prefix.l, "idecode_issue"); |
c906108c | 157 | lf_printf (file, "\n"); |
051b807a DB |
158 | lf_indent_suppress (file); |
159 | lf_printf (file, "#define %s %s%s\n", | |
160 | "semantic_illegal", | |
4e0bf4c4 | 161 | options.module.idecode.prefix.l, "semantic_illegal"); |
051b807a | 162 | lf_printf (file, "\n"); |
c906108c SS |
163 | } |
164 | ||
165 | /* output a declaration for all functions */ | |
4e0bf4c4 AC |
166 | function_entry_traverse (file, table->functions, support_h_function, NULL); |
167 | lf_printf (file, "\n"); | |
168 | lf_printf (file, "#if defined(SUPPORT_INLINE)\n"); | |
169 | lf_printf (file, "# if ((SUPPORT_INLINE & INCLUDE_MODULE)\\\n"); | |
170 | lf_printf (file, " && (SUPPORT_INLINE & INCLUDED_BY_MODULE))\n"); | |
171 | lf_printf (file, "# include \"%ssupport.c\"\n", | |
172 | options.module.support.prefix.l); | |
173 | lf_printf (file, "# endif\n"); | |
174 | lf_printf (file, "#endif\n"); | |
c906108c SS |
175 | } |
176 | ||
177 | static void | |
4e0bf4c4 | 178 | support_c_function (lf *file, function_entry * function, void *data) |
c906108c SS |
179 | { |
180 | ASSERT (function->type != NULL); | |
4e0bf4c4 | 181 | print_support_function_name (file, function, 1 /*!is_definition */ ); |
c906108c SS |
182 | lf_printf (file, "{\n"); |
183 | lf_indent (file, +2); | |
184 | if (function->code == NULL) | |
4e0bf4c4 | 185 | error (function->line, "Function without body (or null statement)"); |
c906108c SS |
186 | lf_print__line_ref (file, function->code->line); |
187 | table_print_code (file, function->code); | |
188 | if (function->is_internal) | |
189 | { | |
4e0bf4c4 AC |
190 | lf_printf (file, |
191 | "sim_engine_abort (SD, CPU, cia, \"Internal function must longjump\\n\");\n"); | |
c906108c SS |
192 | lf_printf (file, "return cia;\n"); |
193 | } | |
194 | lf_indent (file, -2); | |
195 | lf_printf (file, "}\n"); | |
196 | lf_print__internal_ref (file); | |
197 | lf_printf (file, "\n"); | |
198 | } | |
199 | ||
200 | ||
201 | void | |
4e0bf4c4 | 202 | gen_support_c (lf *file, insn_table *table) |
c906108c | 203 | { |
4e0bf4c4 AC |
204 | lf_printf (file, "#include \"sim-main.h\"\n"); |
205 | lf_printf (file, "#include \"%sidecode.h\"\n", | |
206 | options.module.idecode.prefix.l); | |
207 | lf_printf (file, "#include \"%sitable.h\"\n", | |
208 | options.module.itable.prefix.l); | |
209 | lf_printf (file, "#include \"%ssupport.h\"\n", | |
210 | options.module.support.prefix.l); | |
211 | lf_printf (file, "\n"); | |
c906108c SS |
212 | |
213 | /* output a definition (c-code) for all functions */ | |
4e0bf4c4 | 214 | function_entry_traverse (file, table->functions, support_c_function, NULL); |
c906108c | 215 | } |