ld-insn.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /* The IGEN simulator generator for GDB, the GNU Debugger.
  2. Copyright 2002-2022 Free Software Foundation, Inc.
  3. Contributed by Andrew Cagney.
  4. This file is part of GDB.
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. typedef uint64_t insn_uint;
  16. /* Common among most entries:
  17. All non instruction records have the format:
  18. <...> ::=
  19. ":" <record-name>
  20. ":" <filter-flags>
  21. ":" <filter-models>
  22. ":" ...
  23. */
  24. enum
  25. {
  26. record_type_field = 1,
  27. old_record_type_field = 2,
  28. record_filter_flags_field = 2,
  29. record_filter_models_field = 3,
  30. };
  31. /* Include:
  32. Include the specified file.
  33. <include> ::=
  34. ":" "include"
  35. ":" <filter-flags>
  36. ":" <filter-models>
  37. ":" <filename>
  38. <nl>
  39. ;
  40. */
  41. enum
  42. {
  43. include_filename_field = 4,
  44. nr_include_fields,
  45. };
  46. /* Options:
  47. Valid options are: hi-bit-nr (default 0), insn-bit-size (default
  48. 32), insn-specifying-widths (default true), multi-sim (default false).
  49. <option> ::=
  50. ":" "option"
  51. ":" <filter-flags>
  52. ":" <filter-models>
  53. ":" <option-name>
  54. ":" <option-value>
  55. <nl>
  56. ;
  57. <option-name> ::=
  58. "insn-bit-size"
  59. | "insn-specifying-widths"
  60. | "hi-bit-nr"
  61. | "flags-filter"
  62. | "model-filter"
  63. | "multi-sim"
  64. | "format-names"
  65. ;
  66. <option-value> ::=
  67. "true"
  68. | "false"
  69. | <integer>
  70. | <list>
  71. ;
  72. These update the global options structure. */
  73. enum
  74. {
  75. option_name_field = 4,
  76. option_value_field,
  77. nr_option_fields,
  78. };
  79. /* Macro definitions:
  80. <insn-macro> ::=
  81. ":" "define"
  82. ":" <filter-flags>
  83. ":" <filter-models>
  84. ":" <name>
  85. ":" <arg-list>
  86. ":" <expression>
  87. <nl>
  88. ;
  89. <arg-list> ::=
  90. [ <name> { "," <arg-list> } ]
  91. ;
  92. */
  93. enum
  94. {
  95. macro_name_field = 4,
  96. macro_args_field,
  97. macro_expr_field,
  98. nr_macro_fields,
  99. };
  100. /* Functions and internal routins:
  101. NB: <filter-models> and <function-models> are equivalent.
  102. <function> ::=
  103. ":" "function"
  104. <function-spec>
  105. ;
  106. <internal> ::=
  107. ":" "internal"
  108. <function-spec>
  109. ;
  110. <format> ::=
  111. ":" ( "%s" | ... )
  112. <function-spec>
  113. ;
  114. <function-model> ::=
  115. "*" [ <processor-list> ]
  116. ":"
  117. <nl>
  118. ;
  119. <function-spec> ::=
  120. ":" <filter-flags>
  121. ":" <filter-models>
  122. ":" <typedef>
  123. ":" <name>
  124. [ ":" <parameter-list> ]
  125. <nl>
  126. [ <function-model> ]
  127. <code-block>
  128. ;
  129. */
  130. enum
  131. {
  132. function_typedef_field = 4,
  133. function_name_field,
  134. function_param_field,
  135. nr_function_fields,
  136. };
  137. enum
  138. {
  139. function_model_name_field = 0,
  140. nr_function_model_fields = 1,
  141. };
  142. enum
  143. {
  144. old_function_typedef_field = 0,
  145. old_function_type_field = 2,
  146. old_function_name_field = 4,
  147. old_function_param_field = 5,
  148. nr_old_function_fields = 5, /* parameter-list is optional */
  149. };
  150. typedef struct _function_entry function_entry;
  151. struct _function_entry
  152. {
  153. line_ref *line;
  154. filter *flags;
  155. filter *models;
  156. char *type;
  157. char *name;
  158. char *param;
  159. table_entry *code;
  160. int is_internal;
  161. function_entry *next;
  162. };
  163. typedef void function_entry_handler
  164. (lf *file, function_entry * function, void *data);
  165. extern void function_entry_traverse
  166. (lf *file,
  167. function_entry * functions, function_entry_handler * handler, void *data);
  168. /* cache-macro:
  169. <cache-macro> ::=
  170. ":" <macro-type>
  171. ":" <filter-flags>
  172. ":" <filter-models>
  173. ":" <typedef>
  174. ":" <name>
  175. ":" <field-name> { "," <field-name> }
  176. ":" <expression>
  177. <nl>
  178. ;
  179. <cache-macro-type> ::=
  180. "scratch"
  181. | "cache"
  182. | "compute"
  183. ;
  184. <name> ::=
  185. <ident>
  186. | <ident> "_is_" <integer>
  187. ;
  188. A cache entry is defined (for an instruction) when all
  189. <field-name>s are present as named opcode fields within the
  190. instructions format.
  191. SCRATCH and CACHE macros are defined during the cache fill stage
  192. while CACHE and COMPUTE macros are defined during the instruction
  193. execution stage.
  194. */
  195. enum
  196. {
  197. cache_typedef_field = 4,
  198. cache_name_field,
  199. cache_original_fields_field,
  200. cache_expression_field,
  201. nr_cache_fields,
  202. };
  203. typedef enum
  204. {
  205. scratch_value,
  206. cache_value,
  207. compute_value,
  208. }
  209. cache_entry_type;
  210. typedef struct _cache_entry cache_entry;
  211. struct _cache_entry
  212. {
  213. line_ref *line;
  214. filter *flags;
  215. filter *models;
  216. cache_entry_type entry_type;
  217. char *name;
  218. filter *original_fields;
  219. char *type;
  220. char *expression;
  221. cache_entry *next;
  222. };
  223. /* Model specs:
  224. <model-processor> ::=
  225. ":" "model"
  226. ":" <filter-flags>
  227. ":" <filter-models>
  228. ":" <processor>
  229. ":" <BFD-processor>
  230. ":" <function-unit-data>
  231. <nl>
  232. ;
  233. <model-macro> ::=
  234. ":" "model-macro"
  235. ":" <filter-flags>
  236. ":" <filter-models>
  237. <nl>
  238. <code-block>
  239. ;
  240. <model-data> ::=
  241. ":" "model-data"
  242. ":" <filter-flags>
  243. ":" <filter-models>
  244. <nl>
  245. <code-block>
  246. ;
  247. <model-static> ::=
  248. ":" "model-static"
  249. <function-spec>
  250. ;
  251. <model-internal> ::=
  252. ":" "model-internal"
  253. <function-spec>
  254. ;
  255. <model-function> ::=
  256. ":" "model-internal"
  257. <function-spec>
  258. ;
  259. */
  260. enum
  261. {
  262. nr_model_macro_fields = 4,
  263. nr_model_data_fields = 4,
  264. nr_model_static_fields = nr_function_fields,
  265. nr_model_internal_fields = nr_function_fields,
  266. nr_model_function_fields = nr_function_fields,
  267. };
  268. typedef struct _model_data model_data;
  269. struct _model_data
  270. {
  271. line_ref *line;
  272. filter *flags;
  273. table_entry *entry;
  274. table_entry *code;
  275. model_data *next;
  276. };
  277. enum
  278. {
  279. model_name_field = 4,
  280. model_full_name_field,
  281. model_unit_data_field,
  282. nr_model_processor_fields,
  283. };
  284. typedef struct _model_entry model_entry;
  285. struct _model_entry
  286. {
  287. line_ref *line;
  288. filter *flags;
  289. char *name;
  290. char *full_name;
  291. char *unit_data;
  292. model_entry *next;
  293. };
  294. typedef struct _model_table model_table;
  295. struct _model_table
  296. {
  297. filter *processors;
  298. int nr_models;
  299. model_entry *models;
  300. model_data *macros;
  301. model_data *data;
  302. function_entry *statics;
  303. function_entry *internals;
  304. function_entry *functions;
  305. };
  306. /* Instruction format:
  307. An instruction is composed of a sequence of N bit instruction
  308. words. Each word broken into a number of instruction fields.
  309. Those fields being constant (ex. an opcode) or variable (register
  310. spec).
  311. <insn-word> ::=
  312. <insn-field> { "," <insn-field> } ;
  313. <insn-field> ::=
  314. ( <binary-value-implying-width>
  315. | <field-name-implying-width>
  316. | [ <start-or-width> "." ] <field>
  317. )
  318. { [ "!" | "=" ] [ <value> | <field-name> ] }
  319. ;
  320. <field> ::=
  321. { "*" }+
  322. | { "/" }+
  323. | <field-name>
  324. | "0x" <hex-value>
  325. | "0b" <binary-value>
  326. | "0" <octal-value>
  327. | <integer-value> ;
  328. */
  329. typedef enum _insn_field_cond_type
  330. {
  331. insn_field_cond_value,
  332. insn_field_cond_field,
  333. }
  334. insn_field_cond_type;
  335. typedef enum _insn_field_cond_test
  336. {
  337. insn_field_cond_eq,
  338. insn_field_cond_ne,
  339. }
  340. insn_field_cond_test;
  341. typedef struct _insn_field_cond insn_field_cond;
  342. struct _insn_field_cond
  343. {
  344. insn_field_cond_type type;
  345. insn_field_cond_test test;
  346. insn_uint value;
  347. struct _insn_field_entry *field;
  348. char *string;
  349. insn_field_cond *next;
  350. };
  351. typedef enum _insn_field_type
  352. {
  353. insn_field_invalid,
  354. insn_field_int,
  355. insn_field_reserved,
  356. insn_field_wild,
  357. insn_field_string,
  358. }
  359. insn_field_type;
  360. typedef struct _insn_field_entry insn_field_entry;
  361. struct _insn_field_entry
  362. {
  363. int first;
  364. int last;
  365. int width;
  366. int word_nr;
  367. insn_field_type type;
  368. insn_uint val_int;
  369. char *pos_string;
  370. char *val_string;
  371. insn_field_cond *conditions;
  372. insn_field_entry *next;
  373. insn_field_entry *prev;
  374. };
  375. typedef struct _insn_bit_entry insn_bit_entry;
  376. struct _insn_bit_entry
  377. {
  378. int value;
  379. int mask;
  380. insn_field_entry *field;
  381. };
  382. typedef struct _insn_entry insn_entry; /* forward */
  383. typedef struct _insn_word_entry insn_word_entry;
  384. struct _insn_word_entry
  385. {
  386. /* list of sub-fields making up the instruction. bit provides
  387. faster access to the field data for bit N. */
  388. insn_field_entry *first;
  389. insn_field_entry *last;
  390. insn_bit_entry *bit[max_insn_bit_size];
  391. /* set of all the string fields */
  392. filter *field_names;
  393. /* For multi-word instructions, The Nth word (from zero). */
  394. insn_word_entry *next;
  395. };
  396. /* Instruction model:
  397. Provides scheduling and other data for the code modeling the
  398. instruction unit.
  399. <insn-model> ::=
  400. "*" [ <processor-list> ]
  401. ":" [ <function-unit-data> ]
  402. <nl>
  403. ;
  404. <processor-list> ::=
  405. <processor> { "," <processor>" }
  406. ;
  407. If the <processor-list> is empty, the model is made the default for
  408. this instruction.
  409. */
  410. enum
  411. {
  412. insn_model_name_field = 0,
  413. insn_model_unit_data_field = 1,
  414. nr_insn_model_fields = 1,
  415. };
  416. typedef struct _insn_model_entry insn_model_entry;
  417. struct _insn_model_entry
  418. {
  419. line_ref *line;
  420. insn_entry *insn;
  421. filter *names;
  422. char *full_name;
  423. char *unit_data;
  424. insn_model_entry *next;
  425. };
  426. /* Instruction mnemonic:
  427. List of assembler mnemonics for the instruction.
  428. <insn-mnenonic> ::=
  429. "\"" <assembler-mnemonic> "\""
  430. [ ":" <conditional-expression> ]
  431. <nl>
  432. ;
  433. An assembler mnemonic string has the syntax:
  434. <assembler-mnemonic> ::=
  435. ( [ "%" <format-spec> ] "<" <func> [ "#" <param-list> ] ">"
  436. | "%%"
  437. | <other-letter>
  438. )+
  439. Where, for instance, the text is translated into a printf format
  440. and argument pair:
  441. "<FUNC>" : "%ld", (long) FUNC
  442. "%<FUNC>..." : "%...", FUNC
  443. "%s<FUNC>" : "%s", <%s>FUNC (SD_, FUNC)
  444. "%s<FUNC#P1,P2>" : "%s", <%s>FUNC (SD_, P1,P2)
  445. "%lx<FUNC>" : "%lx", (unsigned long) FUNC
  446. "%08lx<FUNC>" : "%08lx", (unsigned long) FUNC
  447. And "<%s>FUNC" denotes a function declared using the "%s" record
  448. specifier.
  449. ;
  450. */
  451. enum
  452. {
  453. insn_mnemonic_format_field = 0,
  454. insn_mnemonic_condition_field = 1,
  455. nr_insn_mnemonic_fields = 1,
  456. };
  457. typedef struct _insn_mnemonic_entry insn_mnemonic_entry;
  458. struct _insn_mnemonic_entry
  459. {
  460. line_ref *line;
  461. insn_entry *insn;
  462. char *format;
  463. char *condition;
  464. insn_mnemonic_entry *next;
  465. };
  466. /* Instruction:
  467. <insn> ::=
  468. <insn-word> { "+" <insn-word> }
  469. ":" <format-name>
  470. ":" <filter-flags>
  471. ":" <options>
  472. ":" <name>
  473. <nl>
  474. { <insn-model> }
  475. { <insn-mnemonic> }
  476. <code-block>
  477. */
  478. enum
  479. {
  480. insn_word_field = 0,
  481. insn_format_name_field = 1,
  482. insn_filter_flags_field = 2,
  483. insn_options_field = 3,
  484. insn_name_field = 4,
  485. nr_insn_fields = 5,
  486. };
  487. /* typedef struct _insn_entry insn_entry; */
  488. struct _insn_entry
  489. {
  490. line_ref *line;
  491. filter *flags; /* filtered by options.filters */
  492. char *format_name;
  493. filter *options;
  494. char *name;
  495. /* the words that make up the instruction. Word provides direct
  496. access to word N. Pseudo instructions can be identified by
  497. nr_words == 0. */
  498. int nr_words;
  499. insn_word_entry *words;
  500. insn_word_entry **word;
  501. /* a set of all the fields from all the words */
  502. filter *field_names;
  503. /* an array of processor models, missing models are NULL! */
  504. int nr_models;
  505. insn_model_entry *models;
  506. insn_model_entry **model;
  507. filter *processors;
  508. /* list of assember formats */
  509. int nr_mnemonics;
  510. insn_mnemonic_entry *mnemonics;
  511. /* code body */
  512. table_entry *code;
  513. insn_entry *next;
  514. };
  515. /* Instruction table:
  516. */
  517. typedef struct _insn_table insn_table;
  518. struct _insn_table
  519. {
  520. cache_entry *caches;
  521. int max_nr_words;
  522. int nr_insns;
  523. insn_entry *insns;
  524. function_entry *functions;
  525. insn_entry *illegal_insn;
  526. model_table *model;
  527. filter *options;
  528. filter *flags;
  529. };
  530. extern insn_table *load_insn_table (char *file_name, cache_entry *cache);
  531. typedef void insn_entry_handler
  532. (lf *file, insn_table *isa, insn_entry * insn, void *data);
  533. extern void insn_table_traverse_insn
  534. (lf *file, insn_table *isa, insn_entry_handler * handler, void *data);
  535. /* Printing */
  536. extern void print_insn_words (lf *file, insn_entry * insn);
  537. /* Debugging */
  538. void
  539. dump_insn_field
  540. (lf *file, char *prefix, insn_field_entry *field, char *suffix);
  541. void
  542. dump_insn_word_entry
  543. (lf *file, char *prefix, insn_word_entry *word, char *suffix);
  544. void
  545. dump_insn_entry (lf *file, char *prefix, insn_entry * insn, char *suffix);
  546. void
  547. dump_cache_entries
  548. (lf *file, char *prefix, cache_entry *entry, char *suffix);
  549. void dump_insn_table (lf *file, char *prefix, insn_table *isa, char *suffix);