ld-insn.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* This file is part of the program psim.
  2. Copyright 1994, 1995, 1996, 2003 Andrew Cagney
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /*
  15. # --
  16. #
  17. #
  18. # Fields:
  19. #
  20. # 1 Instruction format as a `start-bit,content' pairs.
  21. # the content is one of a digit, field name or `/' (aka.0)
  22. #
  23. # 2 Format specifier
  24. #
  25. # 3 Flags: 64 - 64bit only
  26. # f - floating point enabled required
  27. #
  28. # 4 short name
  29. #
  30. # 5 Description
  31. #
  32. #
  33. # For flags marked 'model', the fields are interpreted as follows:
  34. #
  35. # 1 Not used
  36. #
  37. # 2 Not used
  38. #
  39. # 3 "macro"
  40. #
  41. # 4 String name for model
  42. #
  43. # 5 Specific CPU model, must be an identifier
  44. #
  45. # 6 Comma separated list of functional units
  46. */
  47. /* Global constants */
  48. enum {
  49. max_insn_bit_size = 32,
  50. };
  51. typedef struct _insn_field insn_field;
  52. struct _insn_field {
  53. int first;
  54. int last;
  55. int width;
  56. int is_int;
  57. int is_slash;
  58. int is_string;
  59. int val_int;
  60. char *pos_string;
  61. char *val_string;
  62. insn_field *next;
  63. insn_field *prev;
  64. };
  65. typedef struct _insn_fields insn_fields;
  66. struct _insn_fields {
  67. insn_field *bits[max_insn_bit_size];
  68. insn_field *first;
  69. insn_field *last;
  70. unsigned value;
  71. };
  72. /****************************************************************/
  73. typedef struct _opcode_field opcode_field;
  74. struct _opcode_field {
  75. int first;
  76. int last;
  77. int is_boolean;
  78. unsigned boolean_constant;
  79. opcode_field *parent;
  80. };
  81. /****************************************************************/
  82. typedef struct _insn_bits insn_bits;
  83. struct _insn_bits {
  84. int is_expanded;
  85. int value;
  86. insn_field *field;
  87. opcode_field *opcode;
  88. insn_bits *last;
  89. };
  90. /****************************************************************/
  91. typedef enum {
  92. insn_format,
  93. insn_form,
  94. insn_flags,
  95. insn_mnemonic,
  96. insn_name,
  97. insn_comment,
  98. insn_field_6,
  99. insn_field_7,
  100. nr_insn_table_fields
  101. } insn_table_fields;
  102. typedef enum {
  103. function_type = insn_format,
  104. function_name = insn_name,
  105. function_param = insn_comment
  106. } function_table_fields;
  107. typedef enum {
  108. model_name = insn_mnemonic,
  109. model_identifer = insn_name,
  110. model_default = insn_comment,
  111. } model_table_fields;
  112. typedef enum {
  113. include_flags = insn_flags,
  114. include_path = insn_name,
  115. } model_include_fields;
  116. typedef enum {
  117. cache_type_def = insn_name,
  118. cache_derived_name = insn_comment,
  119. cache_name = insn_field_6,
  120. cache_expression = insn_field_7,
  121. } cache_fields;
  122. typedef struct _insn insn;
  123. struct _insn {
  124. table_entry *file_entry;
  125. insn_fields *fields;
  126. insn *next;
  127. };
  128. typedef struct _insn_undef insn_undef;
  129. struct _insn_undef {
  130. insn_undef *next;
  131. char *name;
  132. };
  133. typedef struct _model model;
  134. struct _model {
  135. model *next;
  136. char *name;
  137. char *printable_name;
  138. char *insn_default;
  139. table_model_entry *func_unit_start;
  140. table_model_entry *func_unit_end;
  141. };
  142. typedef struct _insn_table insn_table;
  143. struct _insn_table {
  144. int opcode_nr;
  145. insn_bits *expanded_bits;
  146. int nr_insn;
  147. insn *insns;
  148. insn *functions;
  149. insn *last_function;
  150. decode_table *opcode_rule;
  151. opcode_field *opcode;
  152. int nr_entries;
  153. insn_table *entries;
  154. insn_table *sibling;
  155. insn_table *parent;
  156. };
  157. typedef enum {
  158. insn_model_name,
  159. insn_model_fields,
  160. nr_insn_model_table_fields
  161. } insn_model_table_fields;
  162. extern insn_table *load_insn_table
  163. (const char *file_name,
  164. decode_table *decode_rules,
  165. filter *filters,
  166. table_include *includes,
  167. cache_table **cache_rules);
  168. extern model *models;
  169. extern insn *model_macros;
  170. extern insn *model_functions;
  171. extern insn *model_internal;
  172. extern insn *model_static;
  173. extern insn *model_data;
  174. extern int max_model_fields_len;
  175. extern void insn_table_insert_insn
  176. (insn_table *table,
  177. table_entry *file_entry,
  178. insn_fields *fields);
  179. /****************************************************************/
  180. /****************************************************************/
  181. typedef void leaf_handler
  182. (insn_table *entry,
  183. lf *file,
  184. void *data,
  185. int depth);
  186. typedef void insn_handler
  187. (insn_table *table,
  188. lf *file,
  189. void *data,
  190. insn *instruction,
  191. int depth);
  192. typedef void padding_handler
  193. (insn_table *table,
  194. lf *file,
  195. void *data,
  196. int depth,
  197. int opcode_nr);
  198. extern void insn_table_traverse_tree
  199. (insn_table *table,
  200. lf *file,
  201. void *data,
  202. int depth,
  203. leaf_handler *start,
  204. insn_handler *handler,
  205. leaf_handler *end,
  206. padding_handler *padding);
  207. extern void insn_table_traverse_insn
  208. (insn_table *table,
  209. lf *file,
  210. void *data,
  211. insn_handler *handler);
  212. /****************************************************************/
  213. typedef void function_handler
  214. (insn_table *table,
  215. lf *file,
  216. void *data,
  217. table_entry *function);
  218. extern void
  219. insn_table_traverse_function
  220. (insn_table *table,
  221. lf *file,
  222. void *data,
  223. function_handler *leaf);
  224. /****************************************************************/
  225. extern void insn_table_expand_insns
  226. (insn_table *table);
  227. extern int insn_table_depth
  228. (insn_table *table);