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/* load the opcode stat structure */ 22 23#include "misc.h" 24#include "lf.h" 25#include "table.h" 26#include "ld-decode.h" 27 28#ifndef NULL 29#define NULL 0 30#endif 31 32enum { 33 op_options, 34 op_first, 35 op_last, 36 op_force_first, 37 op_force_last, 38 op_force_expansion, 39 op_special_mask, 40 op_special_value, 41 op_special_constant, 42 nr_decode_fields, 43}; 44 45static const name_map decode_type_map[] = { 46 { "normal", normal_decode_rule }, 47 { "expand-forced", expand_forced_rule }, 48 { "boolean", boolean_rule }, 49 { NULL, normal_decode_rule }, 50}; 51 52static const name_map decode_gen_map[] = { 53 { "array", array_gen }, 54 { "switch", switch_gen }, 55 { "padded-switch", padded_switch_gen }, 56 { "goto-switch", goto_switch_gen }, 57 { NULL, -1 }, 58}; 59 60static const name_map decode_slash_map[] = { 61 { "variable-slash", 0 }, 62 { "constant-slash", 1 }, 63 { NULL }, 64}; 65 66 67static decode_gen_type overriding_gen_type = invalid_gen; 68 69void 70force_decode_gen_type(const char *type) 71{ 72 overriding_gen_type = name2i(type, decode_gen_map); 73} 74 75 76decode_table * 77load_decode_table(char *file_name, 78 int hi_bit_nr) 79{ 80 table *file = table_open(file_name, nr_decode_fields, 0); 81 table_entry *entry; 82 decode_table *table = NULL; 83 decode_table **curr_rule = &table; 84 while ((entry = table_entry_read(file)) != NULL) { 85 decode_table *new_rule = ZALLOC(decode_table); 86 new_rule->type = name2i(entry->fields[op_options], decode_type_map); 87 new_rule->gen = (overriding_gen_type != invalid_gen 88 ? overriding_gen_type 89 : name2i(entry->fields[op_options], decode_gen_map)); 90 new_rule->force_slash = name2i(entry->fields[op_options], decode_slash_map); 91 new_rule->first = target_a2i(hi_bit_nr, entry->fields[op_first]); 92 new_rule->last = target_a2i(hi_bit_nr, entry->fields[op_last]); 93 new_rule->force_first = (strlen(entry->fields[op_force_first]) 94 ? target_a2i(hi_bit_nr, entry->fields[op_force_first]) 95 : new_rule->last + 1); 96 new_rule->force_last = (strlen(entry->fields[op_force_last]) 97 ? target_a2i(hi_bit_nr, entry->fields[op_force_last]) 98 : new_rule->first - 1); 99 new_rule->force_expansion = entry->fields[op_force_expansion]; 100 new_rule->special_mask = a2i(entry->fields[op_special_mask]); 101 new_rule->special_value = a2i(entry->fields[op_special_value]); 102 new_rule->special_constant = a2i(entry->fields[op_special_constant]); 103 *curr_rule = new_rule; 104 curr_rule = &new_rule->next; 105 } 106 return table; 107} 108 109 110void 111dump_decode_rule(decode_table *rule, 112 int indent) 113{ 114 dumpf(indent, "((decode_table*)%p\n", rule); 115 if (rule) { 116 dumpf(indent, " (type %s)\n", i2name(rule->type, decode_type_map)); 117 dumpf(indent, " (gen %s)\n", i2name(rule->gen, decode_gen_map)); 118 dumpf(indent, " (force_slash %d)\n", rule->force_slash); 119 dumpf(indent, " (first %d)\n", rule->first); 120 dumpf(indent, " (last %d)\n", rule->last); 121 dumpf(indent, " (force_first %d)\n", rule->force_first); 122 dumpf(indent, " (force_last %d)\n", rule->force_last); 123 dumpf(indent, " (force_expansion \"%s\")\n", rule->force_expansion); 124 dumpf(indent, " (special_mask 0x%x)\n", rule->special_mask); 125 dumpf(indent, " (special_value 0x%x)\n", rule->special_value); 126 dumpf(indent, " (special_constant 0x%x)\n", rule->special_constant); 127 dumpf(indent, " (next 0x%x)\n", rule->next); 128 } 129 dumpf(indent, " )\n"); 130} 131 132 133#ifdef MAIN 134 135static void 136dump_decode_rules(decode_table *rule, 137 int indent) 138{ 139 while (rule) { 140 dump_decode_rule(rule, indent); 141 rule = rule->next; 142 } 143} 144 145int 146main(int argc, char **argv) 147{ 148 decode_table *rules; 149 if (argc != 3) 150 error("Usage: decode <decode-file> <hi-bit-nr>\n"); 151 rules = load_decode_table(argv[1], a2i(argv[2])); 152 dump_decode_rules(rules, 0); 153 return 0; 154} 155#endif 156