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