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