iq2000-ibld.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
  2. /* Instruction building/extraction support for iq2000. -*- C -*-
  3. THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator.
  4. - the resultant file is machine generated, cgen-ibld.in isn't
  5. Copyright (C) 1996-2022 Free Software Foundation, Inc.
  6. This file is part of libopcodes.
  7. This library is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 3, or (at your option)
  10. any later version.
  11. It is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  14. License for more details.
  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 Foundation, Inc.,
  17. 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  18. /* ??? Eventually more and more of this stuff can go to cpu-independent files.
  19. Keep that in mind. */
  20. #include "sysdep.h"
  21. #include <stdio.h>
  22. #include "ansidecl.h"
  23. #include "dis-asm.h"
  24. #include "bfd.h"
  25. #include "symcat.h"
  26. #include "iq2000-desc.h"
  27. #include "iq2000-opc.h"
  28. #include "cgen/basic-modes.h"
  29. #include "opintl.h"
  30. #include "safe-ctype.h"
  31. #undef min
  32. #define min(a,b) ((a) < (b) ? (a) : (b))
  33. #undef max
  34. #define max(a,b) ((a) > (b) ? (a) : (b))
  35. /* Used by the ifield rtx function. */
  36. #define FLD(f) (fields->f)
  37. static const char * insert_normal
  38. (CGEN_CPU_DESC, long, unsigned int, unsigned int, unsigned int,
  39. unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR);
  40. static const char * insert_insn_normal
  41. (CGEN_CPU_DESC, const CGEN_INSN *,
  42. CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
  43. static int extract_normal
  44. (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
  45. unsigned int, unsigned int, unsigned int, unsigned int,
  46. unsigned int, unsigned int, bfd_vma, long *);
  47. static int extract_insn_normal
  48. (CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
  49. CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
  50. #if CGEN_INT_INSN_P
  51. static void put_insn_int_value
  52. (CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT);
  53. #endif
  54. #if ! CGEN_INT_INSN_P
  55. static CGEN_INLINE void insert_1
  56. (CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *);
  57. static CGEN_INLINE int fill_cache
  58. (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, bfd_vma);
  59. static CGEN_INLINE long extract_1
  60. (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int, unsigned char *, bfd_vma);
  61. #endif
  62. /* Operand insertion. */
  63. #if ! CGEN_INT_INSN_P
  64. /* Subroutine of insert_normal. */
  65. static CGEN_INLINE void
  66. insert_1 (CGEN_CPU_DESC cd,
  67. unsigned long value,
  68. int start,
  69. int length,
  70. int word_length,
  71. unsigned char *bufp)
  72. {
  73. unsigned long x, mask;
  74. int shift;
  75. x = cgen_get_insn_value (cd, bufp, word_length, cd->endian);
  76. /* Written this way to avoid undefined behaviour. */
  77. mask = (1UL << (length - 1) << 1) - 1;
  78. if (CGEN_INSN_LSB0_P)
  79. shift = (start + 1) - length;
  80. else
  81. shift = (word_length - (start + length));
  82. x = (x & ~(mask << shift)) | ((value & mask) << shift);
  83. cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x, cd->endian);
  84. }
  85. #endif /* ! CGEN_INT_INSN_P */
  86. /* Default insertion routine.
  87. ATTRS is a mask of the boolean attributes.
  88. WORD_OFFSET is the offset in bits from the start of the insn of the value.
  89. WORD_LENGTH is the length of the word in bits in which the value resides.
  90. START is the starting bit number in the word, architecture origin.
  91. LENGTH is the length of VALUE in bits.
  92. TOTAL_LENGTH is the total length of the insn in bits.
  93. The result is an error message or NULL if success. */
  94. /* ??? This duplicates functionality with bfd's howto table and
  95. bfd_install_relocation. */
  96. /* ??? This doesn't handle bfd_vma's. Create another function when
  97. necessary. */
  98. static const char *
  99. insert_normal (CGEN_CPU_DESC cd,
  100. long value,
  101. unsigned int attrs,
  102. unsigned int word_offset,
  103. unsigned int start,
  104. unsigned int length,
  105. unsigned int word_length,
  106. unsigned int total_length,
  107. CGEN_INSN_BYTES_PTR buffer)
  108. {
  109. static char errbuf[100];
  110. unsigned long mask;
  111. /* If LENGTH is zero, this operand doesn't contribute to the value. */
  112. if (length == 0)
  113. return NULL;
  114. /* Written this way to avoid undefined behaviour. */
  115. mask = (1UL << (length - 1) << 1) - 1;
  116. if (word_length > 8 * sizeof (CGEN_INSN_INT))
  117. abort ();
  118. /* For architectures with insns smaller than the base-insn-bitsize,
  119. word_length may be too big. */
  120. if (cd->min_insn_bitsize < cd->base_insn_bitsize)
  121. {
  122. if (word_offset == 0
  123. && word_length > total_length)
  124. word_length = total_length;
  125. }
  126. /* Ensure VALUE will fit. */
  127. if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT))
  128. {
  129. long minval = - (1UL << (length - 1));
  130. unsigned long maxval = mask;
  131. if ((value > 0 && (unsigned long) value > maxval)
  132. || value < minval)
  133. {
  134. /* xgettext:c-format */
  135. sprintf (errbuf,
  136. _("operand out of range (%ld not between %ld and %lu)"),
  137. value, minval, maxval);
  138. return errbuf;
  139. }
  140. }
  141. else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
  142. {
  143. unsigned long maxval = mask;
  144. unsigned long val = (unsigned long) value;
  145. /* For hosts with a word size > 32 check to see if value has been sign
  146. extended beyond 32 bits. If so then ignore these higher sign bits
  147. as the user is attempting to store a 32-bit signed value into an
  148. unsigned 32-bit field which is allowed. */
  149. if (sizeof (unsigned long) > 4 && ((value >> 32) == -1))
  150. val &= 0xFFFFFFFF;
  151. if (val > maxval)
  152. {
  153. /* xgettext:c-format */
  154. sprintf (errbuf,
  155. _("operand out of range (0x%lx not between 0 and 0x%lx)"),
  156. val, maxval);
  157. return errbuf;
  158. }
  159. }
  160. else
  161. {
  162. if (! cgen_signed_overflow_ok_p (cd))
  163. {
  164. long minval = - (1UL << (length - 1));
  165. long maxval = (1UL << (length - 1)) - 1;
  166. if (value < minval || value > maxval)
  167. {
  168. sprintf
  169. /* xgettext:c-format */
  170. (errbuf, _("operand out of range (%ld not between %ld and %ld)"),
  171. value, minval, maxval);
  172. return errbuf;
  173. }
  174. }
  175. }
  176. #if CGEN_INT_INSN_P
  177. {
  178. int shift_within_word, shift_to_word, shift;
  179. /* How to shift the value to BIT0 of the word. */
  180. shift_to_word = total_length - (word_offset + word_length);
  181. /* How to shift the value to the field within the word. */
  182. if (CGEN_INSN_LSB0_P)
  183. shift_within_word = start + 1 - length;
  184. else
  185. shift_within_word = word_length - start - length;
  186. /* The total SHIFT, then mask in the value. */
  187. shift = shift_to_word + shift_within_word;
  188. *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
  189. }
  190. #else /* ! CGEN_INT_INSN_P */
  191. {
  192. unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
  193. insert_1 (cd, value, start, length, word_length, bufp);
  194. }
  195. #endif /* ! CGEN_INT_INSN_P */
  196. return NULL;
  197. }
  198. /* Default insn builder (insert handler).
  199. The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
  200. that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
  201. recorded in host byte order, otherwise BUFFER is an array of bytes
  202. and the value is recorded in target byte order).
  203. The result is an error message or NULL if success. */
  204. static const char *
  205. insert_insn_normal (CGEN_CPU_DESC cd,
  206. const CGEN_INSN * insn,
  207. CGEN_FIELDS * fields,
  208. CGEN_INSN_BYTES_PTR buffer,
  209. bfd_vma pc)
  210. {
  211. const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
  212. unsigned long value;
  213. const CGEN_SYNTAX_CHAR_TYPE * syn;
  214. CGEN_INIT_INSERT (cd);
  215. value = CGEN_INSN_BASE_VALUE (insn);
  216. /* If we're recording insns as numbers (rather than a string of bytes),
  217. target byte order handling is deferred until later. */
  218. #if CGEN_INT_INSN_P
  219. put_insn_int_value (cd, buffer, cd->base_insn_bitsize,
  220. CGEN_FIELDS_BITSIZE (fields), value);
  221. #else
  222. cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
  223. (unsigned) CGEN_FIELDS_BITSIZE (fields)),
  224. value, cd->insn_endian);
  225. #endif /* ! CGEN_INT_INSN_P */
  226. /* ??? It would be better to scan the format's fields.
  227. Still need to be able to insert a value based on the operand though;
  228. e.g. storing a branch displacement that got resolved later.
  229. Needs more thought first. */
  230. for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
  231. {
  232. const char *errmsg;
  233. if (CGEN_SYNTAX_CHAR_P (* syn))
  234. continue;
  235. errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
  236. fields, buffer, pc);
  237. if (errmsg)
  238. return errmsg;
  239. }
  240. return NULL;
  241. }
  242. #if CGEN_INT_INSN_P
  243. /* Cover function to store an insn value into an integral insn. Must go here
  244. because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */
  245. static void
  246. put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  247. CGEN_INSN_BYTES_PTR buf,
  248. int length,
  249. int insn_length,
  250. CGEN_INSN_INT value)
  251. {
  252. /* For architectures with insns smaller than the base-insn-bitsize,
  253. length may be too big. */
  254. if (length > insn_length)
  255. *buf = value;
  256. else
  257. {
  258. int shift = insn_length - length;
  259. /* Written this way to avoid undefined behaviour. */
  260. CGEN_INSN_INT mask = length == 0 ? 0 : (1UL << (length - 1) << 1) - 1;
  261. *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift);
  262. }
  263. }
  264. #endif
  265. /* Operand extraction. */
  266. #if ! CGEN_INT_INSN_P
  267. /* Subroutine of extract_normal.
  268. Ensure sufficient bytes are cached in EX_INFO.
  269. OFFSET is the offset in bytes from the start of the insn of the value.
  270. BYTES is the length of the needed value.
  271. Returns 1 for success, 0 for failure. */
  272. static CGEN_INLINE int
  273. fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  274. CGEN_EXTRACT_INFO *ex_info,
  275. int offset,
  276. int bytes,
  277. bfd_vma pc)
  278. {
  279. /* It's doubtful that the middle part has already been fetched so
  280. we don't optimize that case. kiss. */
  281. unsigned int mask;
  282. disassemble_info *info = (disassemble_info *) ex_info->dis_info;
  283. /* First do a quick check. */
  284. mask = (1 << bytes) - 1;
  285. if (((ex_info->valid >> offset) & mask) == mask)
  286. return 1;
  287. /* Search for the first byte we need to read. */
  288. for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
  289. if (! (mask & ex_info->valid))
  290. break;
  291. if (bytes)
  292. {
  293. int status;
  294. pc += offset;
  295. status = (*info->read_memory_func)
  296. (pc, ex_info->insn_bytes + offset, bytes, info);
  297. if (status != 0)
  298. {
  299. (*info->memory_error_func) (status, pc, info);
  300. return 0;
  301. }
  302. ex_info->valid |= ((1 << bytes) - 1) << offset;
  303. }
  304. return 1;
  305. }
  306. /* Subroutine of extract_normal. */
  307. static CGEN_INLINE long
  308. extract_1 (CGEN_CPU_DESC cd,
  309. CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
  310. int start,
  311. int length,
  312. int word_length,
  313. unsigned char *bufp,
  314. bfd_vma pc ATTRIBUTE_UNUSED)
  315. {
  316. unsigned long x;
  317. int shift;
  318. x = cgen_get_insn_value (cd, bufp, word_length, cd->endian);
  319. if (CGEN_INSN_LSB0_P)
  320. shift = (start + 1) - length;
  321. else
  322. shift = (word_length - (start + length));
  323. return x >> shift;
  324. }
  325. #endif /* ! CGEN_INT_INSN_P */
  326. /* Default extraction routine.
  327. INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
  328. or sometimes less for cases like the m32r where the base insn size is 32
  329. but some insns are 16 bits.
  330. ATTRS is a mask of the boolean attributes. We only need `SIGNED',
  331. but for generality we take a bitmask of all of them.
  332. WORD_OFFSET is the offset in bits from the start of the insn of the value.
  333. WORD_LENGTH is the length of the word in bits in which the value resides.
  334. START is the starting bit number in the word, architecture origin.
  335. LENGTH is the length of VALUE in bits.
  336. TOTAL_LENGTH is the total length of the insn in bits.
  337. Returns 1 for success, 0 for failure. */
  338. /* ??? The return code isn't properly used. wip. */
  339. /* ??? This doesn't handle bfd_vma's. Create another function when
  340. necessary. */
  341. static int
  342. extract_normal (CGEN_CPU_DESC cd,
  343. #if ! CGEN_INT_INSN_P
  344. CGEN_EXTRACT_INFO *ex_info,
  345. #else
  346. CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
  347. #endif
  348. CGEN_INSN_INT insn_value,
  349. unsigned int attrs,
  350. unsigned int word_offset,
  351. unsigned int start,
  352. unsigned int length,
  353. unsigned int word_length,
  354. unsigned int total_length,
  355. #if ! CGEN_INT_INSN_P
  356. bfd_vma pc,
  357. #else
  358. bfd_vma pc ATTRIBUTE_UNUSED,
  359. #endif
  360. long *valuep)
  361. {
  362. long value, mask;
  363. /* If LENGTH is zero, this operand doesn't contribute to the value
  364. so give it a standard value of zero. */
  365. if (length == 0)
  366. {
  367. *valuep = 0;
  368. return 1;
  369. }
  370. if (word_length > 8 * sizeof (CGEN_INSN_INT))
  371. abort ();
  372. /* For architectures with insns smaller than the insn-base-bitsize,
  373. word_length may be too big. */
  374. if (cd->min_insn_bitsize < cd->base_insn_bitsize)
  375. {
  376. if (word_offset + word_length > total_length)
  377. word_length = total_length - word_offset;
  378. }
  379. /* Does the value reside in INSN_VALUE, and at the right alignment? */
  380. if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
  381. {
  382. if (CGEN_INSN_LSB0_P)
  383. value = insn_value >> ((word_offset + start + 1) - length);
  384. else
  385. value = insn_value >> (total_length - ( word_offset + start + length));
  386. }
  387. #if ! CGEN_INT_INSN_P
  388. else
  389. {
  390. unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
  391. if (word_length > 8 * sizeof (CGEN_INSN_INT))
  392. abort ();
  393. if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
  394. {
  395. *valuep = 0;
  396. return 0;
  397. }
  398. value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
  399. }
  400. #endif /* ! CGEN_INT_INSN_P */
  401. /* Written this way to avoid undefined behaviour. */
  402. mask = (1UL << (length - 1) << 1) - 1;
  403. value &= mask;
  404. /* sign extend? */
  405. if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
  406. && (value & (1UL << (length - 1))))
  407. value |= ~mask;
  408. *valuep = value;
  409. return 1;
  410. }
  411. /* Default insn extractor.
  412. INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
  413. The extracted fields are stored in FIELDS.
  414. EX_INFO is used to handle reading variable length insns.
  415. Return the length of the insn in bits, or 0 if no match,
  416. or -1 if an error occurs fetching data (memory_error_func will have
  417. been called). */
  418. static int
  419. extract_insn_normal (CGEN_CPU_DESC cd,
  420. const CGEN_INSN *insn,
  421. CGEN_EXTRACT_INFO *ex_info,
  422. CGEN_INSN_INT insn_value,
  423. CGEN_FIELDS *fields,
  424. bfd_vma pc)
  425. {
  426. const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
  427. const CGEN_SYNTAX_CHAR_TYPE *syn;
  428. CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
  429. CGEN_INIT_EXTRACT (cd);
  430. for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
  431. {
  432. int length;
  433. if (CGEN_SYNTAX_CHAR_P (*syn))
  434. continue;
  435. length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
  436. ex_info, insn_value, fields, pc);
  437. if (length <= 0)
  438. return length;
  439. }
  440. /* We recognized and successfully extracted this insn. */
  441. return CGEN_INSN_BITSIZE (insn);
  442. }
  443. /* Machine generated code added here. */
  444. const char * iq2000_cgen_insert_operand
  445. (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
  446. /* Main entry point for operand insertion.
  447. This function is basically just a big switch statement. Earlier versions
  448. used tables to look up the function to use, but
  449. - if the table contains both assembler and disassembler functions then
  450. the disassembler contains much of the assembler and vice-versa,
  451. - there's a lot of inlining possibilities as things grow,
  452. - using a switch statement avoids the function call overhead.
  453. This function could be moved into `parse_insn_normal', but keeping it
  454. separate makes clear the interface between `parse_insn_normal' and each of
  455. the handlers. It's also needed by GAS to insert operands that couldn't be
  456. resolved during parsing. */
  457. const char *
  458. iq2000_cgen_insert_operand (CGEN_CPU_DESC cd,
  459. int opindex,
  460. CGEN_FIELDS * fields,
  461. CGEN_INSN_BYTES_PTR buffer,
  462. bfd_vma pc ATTRIBUTE_UNUSED)
  463. {
  464. const char * errmsg = NULL;
  465. unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
  466. switch (opindex)
  467. {
  468. case IQ2000_OPERAND__INDEX :
  469. errmsg = insert_normal (cd, fields->f_index, 0, 0, 8, 9, 32, total_length, buffer);
  470. break;
  471. case IQ2000_OPERAND_BASE :
  472. errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
  473. break;
  474. case IQ2000_OPERAND_BASEOFF :
  475. errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
  476. break;
  477. case IQ2000_OPERAND_BITNUM :
  478. errmsg = insert_normal (cd, fields->f_rt, 0, 0, 20, 5, 32, total_length, buffer);
  479. break;
  480. case IQ2000_OPERAND_BYTECOUNT :
  481. errmsg = insert_normal (cd, fields->f_bytecount, 0, 0, 7, 8, 32, total_length, buffer);
  482. break;
  483. case IQ2000_OPERAND_CAM_Y :
  484. errmsg = insert_normal (cd, fields->f_cam_y, 0, 0, 2, 3, 32, total_length, buffer);
  485. break;
  486. case IQ2000_OPERAND_CAM_Z :
  487. errmsg = insert_normal (cd, fields->f_cam_z, 0, 0, 5, 3, 32, total_length, buffer);
  488. break;
  489. case IQ2000_OPERAND_CM_3FUNC :
  490. errmsg = insert_normal (cd, fields->f_cm_3func, 0, 0, 5, 3, 32, total_length, buffer);
  491. break;
  492. case IQ2000_OPERAND_CM_3Z :
  493. errmsg = insert_normal (cd, fields->f_cm_3z, 0, 0, 1, 2, 32, total_length, buffer);
  494. break;
  495. case IQ2000_OPERAND_CM_4FUNC :
  496. errmsg = insert_normal (cd, fields->f_cm_4func, 0, 0, 5, 4, 32, total_length, buffer);
  497. break;
  498. case IQ2000_OPERAND_CM_4Z :
  499. errmsg = insert_normal (cd, fields->f_cm_4z, 0, 0, 2, 3, 32, total_length, buffer);
  500. break;
  501. case IQ2000_OPERAND_COUNT :
  502. errmsg = insert_normal (cd, fields->f_count, 0, 0, 15, 7, 32, total_length, buffer);
  503. break;
  504. case IQ2000_OPERAND_EXECODE :
  505. errmsg = insert_normal (cd, fields->f_excode, 0, 0, 25, 20, 32, total_length, buffer);
  506. break;
  507. case IQ2000_OPERAND_HI16 :
  508. errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
  509. break;
  510. case IQ2000_OPERAND_IMM :
  511. errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
  512. break;
  513. case IQ2000_OPERAND_JMPTARG :
  514. {
  515. long value = fields->f_jtarg;
  516. value = ((USI) (((value) & (262143))) >> (2));
  517. errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 16, 32, total_length, buffer);
  518. }
  519. break;
  520. case IQ2000_OPERAND_JMPTARGQ10 :
  521. {
  522. long value = fields->f_jtargq10;
  523. value = ((USI) (((value) & (8388607))) >> (2));
  524. errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 20, 21, 32, total_length, buffer);
  525. }
  526. break;
  527. case IQ2000_OPERAND_LO16 :
  528. errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
  529. break;
  530. case IQ2000_OPERAND_MASK :
  531. errmsg = insert_normal (cd, fields->f_mask, 0, 0, 9, 4, 32, total_length, buffer);
  532. break;
  533. case IQ2000_OPERAND_MASKL :
  534. errmsg = insert_normal (cd, fields->f_maskl, 0, 0, 4, 5, 32, total_length, buffer);
  535. break;
  536. case IQ2000_OPERAND_MASKQ10 :
  537. errmsg = insert_normal (cd, fields->f_maskq10, 0, 0, 10, 5, 32, total_length, buffer);
  538. break;
  539. case IQ2000_OPERAND_MASKR :
  540. errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
  541. break;
  542. case IQ2000_OPERAND_MLO16 :
  543. errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
  544. break;
  545. case IQ2000_OPERAND_OFFSET :
  546. {
  547. long value = fields->f_offset;
  548. value = ((SI) (((value) - (pc))) >> (2));
  549. errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 16, 32, total_length, buffer);
  550. }
  551. break;
  552. case IQ2000_OPERAND_RD :
  553. errmsg = insert_normal (cd, fields->f_rd, 0, 0, 15, 5, 32, total_length, buffer);
  554. break;
  555. case IQ2000_OPERAND_RD_RS :
  556. {
  557. {
  558. FLD (f_rd) = FLD (f_rd_rs);
  559. FLD (f_rs) = FLD (f_rd_rs);
  560. }
  561. errmsg = insert_normal (cd, fields->f_rd, 0, 0, 15, 5, 32, total_length, buffer);
  562. if (errmsg)
  563. break;
  564. errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
  565. if (errmsg)
  566. break;
  567. }
  568. break;
  569. case IQ2000_OPERAND_RD_RT :
  570. {
  571. {
  572. FLD (f_rd) = FLD (f_rd_rt);
  573. FLD (f_rt) = FLD (f_rd_rt);
  574. }
  575. errmsg = insert_normal (cd, fields->f_rd, 0, 0, 15, 5, 32, total_length, buffer);
  576. if (errmsg)
  577. break;
  578. errmsg = insert_normal (cd, fields->f_rt, 0, 0, 20, 5, 32, total_length, buffer);
  579. if (errmsg)
  580. break;
  581. }
  582. break;
  583. case IQ2000_OPERAND_RS :
  584. errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
  585. break;
  586. case IQ2000_OPERAND_RT :
  587. errmsg = insert_normal (cd, fields->f_rt, 0, 0, 20, 5, 32, total_length, buffer);
  588. break;
  589. case IQ2000_OPERAND_RT_RS :
  590. {
  591. {
  592. FLD (f_rt) = FLD (f_rt_rs);
  593. FLD (f_rs) = FLD (f_rt_rs);
  594. }
  595. errmsg = insert_normal (cd, fields->f_rt, 0, 0, 20, 5, 32, total_length, buffer);
  596. if (errmsg)
  597. break;
  598. errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
  599. if (errmsg)
  600. break;
  601. }
  602. break;
  603. case IQ2000_OPERAND_SHAMT :
  604. errmsg = insert_normal (cd, fields->f_shamt, 0, 0, 10, 5, 32, total_length, buffer);
  605. break;
  606. default :
  607. /* xgettext:c-format */
  608. opcodes_error_handler
  609. (_("internal error: unrecognized field %d while building insn"),
  610. opindex);
  611. abort ();
  612. }
  613. return errmsg;
  614. }
  615. int iq2000_cgen_extract_operand
  616. (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
  617. /* Main entry point for operand extraction.
  618. The result is <= 0 for error, >0 for success.
  619. ??? Actual values aren't well defined right now.
  620. This function is basically just a big switch statement. Earlier versions
  621. used tables to look up the function to use, but
  622. - if the table contains both assembler and disassembler functions then
  623. the disassembler contains much of the assembler and vice-versa,
  624. - there's a lot of inlining possibilities as things grow,
  625. - using a switch statement avoids the function call overhead.
  626. This function could be moved into `print_insn_normal', but keeping it
  627. separate makes clear the interface between `print_insn_normal' and each of
  628. the handlers. */
  629. int
  630. iq2000_cgen_extract_operand (CGEN_CPU_DESC cd,
  631. int opindex,
  632. CGEN_EXTRACT_INFO *ex_info,
  633. CGEN_INSN_INT insn_value,
  634. CGEN_FIELDS * fields,
  635. bfd_vma pc)
  636. {
  637. /* Assume success (for those operands that are nops). */
  638. int length = 1;
  639. unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
  640. switch (opindex)
  641. {
  642. case IQ2000_OPERAND__INDEX :
  643. length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 9, 32, total_length, pc, & fields->f_index);
  644. break;
  645. case IQ2000_OPERAND_BASE :
  646. length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
  647. break;
  648. case IQ2000_OPERAND_BASEOFF :
  649. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
  650. break;
  651. case IQ2000_OPERAND_BITNUM :
  652. length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_rt);
  653. break;
  654. case IQ2000_OPERAND_BYTECOUNT :
  655. length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 8, 32, total_length, pc, & fields->f_bytecount);
  656. break;
  657. case IQ2000_OPERAND_CAM_Y :
  658. length = extract_normal (cd, ex_info, insn_value, 0, 0, 2, 3, 32, total_length, pc, & fields->f_cam_y);
  659. break;
  660. case IQ2000_OPERAND_CAM_Z :
  661. length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 3, 32, total_length, pc, & fields->f_cam_z);
  662. break;
  663. case IQ2000_OPERAND_CM_3FUNC :
  664. length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 3, 32, total_length, pc, & fields->f_cm_3func);
  665. break;
  666. case IQ2000_OPERAND_CM_3Z :
  667. length = extract_normal (cd, ex_info, insn_value, 0, 0, 1, 2, 32, total_length, pc, & fields->f_cm_3z);
  668. break;
  669. case IQ2000_OPERAND_CM_4FUNC :
  670. length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 4, 32, total_length, pc, & fields->f_cm_4func);
  671. break;
  672. case IQ2000_OPERAND_CM_4Z :
  673. length = extract_normal (cd, ex_info, insn_value, 0, 0, 2, 3, 32, total_length, pc, & fields->f_cm_4z);
  674. break;
  675. case IQ2000_OPERAND_COUNT :
  676. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 7, 32, total_length, pc, & fields->f_count);
  677. break;
  678. case IQ2000_OPERAND_EXECODE :
  679. length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 20, 32, total_length, pc, & fields->f_excode);
  680. break;
  681. case IQ2000_OPERAND_HI16 :
  682. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
  683. break;
  684. case IQ2000_OPERAND_IMM :
  685. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
  686. break;
  687. case IQ2000_OPERAND_JMPTARG :
  688. {
  689. long value;
  690. length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 16, 32, total_length, pc, & value);
  691. value = ((((pc) & (0xf0000000))) | (((value) << (2))));
  692. fields->f_jtarg = value;
  693. }
  694. break;
  695. case IQ2000_OPERAND_JMPTARGQ10 :
  696. {
  697. long value;
  698. length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 20, 21, 32, total_length, pc, & value);
  699. value = ((((pc) & (0xf0000000))) | (((value) << (2))));
  700. fields->f_jtargq10 = value;
  701. }
  702. break;
  703. case IQ2000_OPERAND_LO16 :
  704. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
  705. break;
  706. case IQ2000_OPERAND_MASK :
  707. length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 4, 32, total_length, pc, & fields->f_mask);
  708. break;
  709. case IQ2000_OPERAND_MASKL :
  710. length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 5, 32, total_length, pc, & fields->f_maskl);
  711. break;
  712. case IQ2000_OPERAND_MASKQ10 :
  713. length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 5, 32, total_length, pc, & fields->f_maskq10);
  714. break;
  715. case IQ2000_OPERAND_MASKR :
  716. length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
  717. break;
  718. case IQ2000_OPERAND_MLO16 :
  719. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
  720. break;
  721. case IQ2000_OPERAND_OFFSET :
  722. {
  723. long value;
  724. length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 16, 32, total_length, pc, & value);
  725. value = ((((value) * (4))) + (((pc) + (4))));
  726. fields->f_offset = value;
  727. }
  728. break;
  729. case IQ2000_OPERAND_RD :
  730. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_rd);
  731. break;
  732. case IQ2000_OPERAND_RD_RS :
  733. {
  734. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_rd);
  735. if (length <= 0) break;
  736. length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
  737. if (length <= 0) break;
  738. {
  739. FLD (f_rd_rs) = FLD (f_rs);
  740. }
  741. }
  742. break;
  743. case IQ2000_OPERAND_RD_RT :
  744. {
  745. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_rd);
  746. if (length <= 0) break;
  747. length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_rt);
  748. if (length <= 0) break;
  749. {
  750. FLD (f_rd_rt) = FLD (f_rt);
  751. }
  752. }
  753. break;
  754. case IQ2000_OPERAND_RS :
  755. length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
  756. break;
  757. case IQ2000_OPERAND_RT :
  758. length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_rt);
  759. break;
  760. case IQ2000_OPERAND_RT_RS :
  761. {
  762. length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_rt);
  763. if (length <= 0) break;
  764. length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
  765. if (length <= 0) break;
  766. {
  767. FLD (f_rd_rs) = FLD (f_rs);
  768. }
  769. }
  770. break;
  771. case IQ2000_OPERAND_SHAMT :
  772. length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 5, 32, total_length, pc, & fields->f_shamt);
  773. break;
  774. default :
  775. /* xgettext:c-format */
  776. opcodes_error_handler
  777. (_("internal error: unrecognized field %d while decoding insn"),
  778. opindex);
  779. abort ();
  780. }
  781. return length;
  782. }
  783. cgen_insert_fn * const iq2000_cgen_insert_handlers[] =
  784. {
  785. insert_insn_normal,
  786. };
  787. cgen_extract_fn * const iq2000_cgen_extract_handlers[] =
  788. {
  789. extract_insn_normal,
  790. };
  791. int iq2000_cgen_get_int_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
  792. bfd_vma iq2000_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
  793. /* Getting values from cgen_fields is handled by a collection of functions.
  794. They are distinguished by the type of the VALUE argument they return.
  795. TODO: floating point, inlining support, remove cases where result type
  796. not appropriate. */
  797. int
  798. iq2000_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  799. int opindex,
  800. const CGEN_FIELDS * fields)
  801. {
  802. int value;
  803. switch (opindex)
  804. {
  805. case IQ2000_OPERAND__INDEX :
  806. value = fields->f_index;
  807. break;
  808. case IQ2000_OPERAND_BASE :
  809. value = fields->f_rs;
  810. break;
  811. case IQ2000_OPERAND_BASEOFF :
  812. value = fields->f_imm;
  813. break;
  814. case IQ2000_OPERAND_BITNUM :
  815. value = fields->f_rt;
  816. break;
  817. case IQ2000_OPERAND_BYTECOUNT :
  818. value = fields->f_bytecount;
  819. break;
  820. case IQ2000_OPERAND_CAM_Y :
  821. value = fields->f_cam_y;
  822. break;
  823. case IQ2000_OPERAND_CAM_Z :
  824. value = fields->f_cam_z;
  825. break;
  826. case IQ2000_OPERAND_CM_3FUNC :
  827. value = fields->f_cm_3func;
  828. break;
  829. case IQ2000_OPERAND_CM_3Z :
  830. value = fields->f_cm_3z;
  831. break;
  832. case IQ2000_OPERAND_CM_4FUNC :
  833. value = fields->f_cm_4func;
  834. break;
  835. case IQ2000_OPERAND_CM_4Z :
  836. value = fields->f_cm_4z;
  837. break;
  838. case IQ2000_OPERAND_COUNT :
  839. value = fields->f_count;
  840. break;
  841. case IQ2000_OPERAND_EXECODE :
  842. value = fields->f_excode;
  843. break;
  844. case IQ2000_OPERAND_HI16 :
  845. value = fields->f_imm;
  846. break;
  847. case IQ2000_OPERAND_IMM :
  848. value = fields->f_imm;
  849. break;
  850. case IQ2000_OPERAND_JMPTARG :
  851. value = fields->f_jtarg;
  852. break;
  853. case IQ2000_OPERAND_JMPTARGQ10 :
  854. value = fields->f_jtargq10;
  855. break;
  856. case IQ2000_OPERAND_LO16 :
  857. value = fields->f_imm;
  858. break;
  859. case IQ2000_OPERAND_MASK :
  860. value = fields->f_mask;
  861. break;
  862. case IQ2000_OPERAND_MASKL :
  863. value = fields->f_maskl;
  864. break;
  865. case IQ2000_OPERAND_MASKQ10 :
  866. value = fields->f_maskq10;
  867. break;
  868. case IQ2000_OPERAND_MASKR :
  869. value = fields->f_rs;
  870. break;
  871. case IQ2000_OPERAND_MLO16 :
  872. value = fields->f_imm;
  873. break;
  874. case IQ2000_OPERAND_OFFSET :
  875. value = fields->f_offset;
  876. break;
  877. case IQ2000_OPERAND_RD :
  878. value = fields->f_rd;
  879. break;
  880. case IQ2000_OPERAND_RD_RS :
  881. value = fields->f_rd_rs;
  882. break;
  883. case IQ2000_OPERAND_RD_RT :
  884. value = fields->f_rd_rt;
  885. break;
  886. case IQ2000_OPERAND_RS :
  887. value = fields->f_rs;
  888. break;
  889. case IQ2000_OPERAND_RT :
  890. value = fields->f_rt;
  891. break;
  892. case IQ2000_OPERAND_RT_RS :
  893. value = fields->f_rt_rs;
  894. break;
  895. case IQ2000_OPERAND_SHAMT :
  896. value = fields->f_shamt;
  897. break;
  898. default :
  899. /* xgettext:c-format */
  900. opcodes_error_handler
  901. (_("internal error: unrecognized field %d while getting int operand"),
  902. opindex);
  903. abort ();
  904. }
  905. return value;
  906. }
  907. bfd_vma
  908. iq2000_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  909. int opindex,
  910. const CGEN_FIELDS * fields)
  911. {
  912. bfd_vma value;
  913. switch (opindex)
  914. {
  915. case IQ2000_OPERAND__INDEX :
  916. value = fields->f_index;
  917. break;
  918. case IQ2000_OPERAND_BASE :
  919. value = fields->f_rs;
  920. break;
  921. case IQ2000_OPERAND_BASEOFF :
  922. value = fields->f_imm;
  923. break;
  924. case IQ2000_OPERAND_BITNUM :
  925. value = fields->f_rt;
  926. break;
  927. case IQ2000_OPERAND_BYTECOUNT :
  928. value = fields->f_bytecount;
  929. break;
  930. case IQ2000_OPERAND_CAM_Y :
  931. value = fields->f_cam_y;
  932. break;
  933. case IQ2000_OPERAND_CAM_Z :
  934. value = fields->f_cam_z;
  935. break;
  936. case IQ2000_OPERAND_CM_3FUNC :
  937. value = fields->f_cm_3func;
  938. break;
  939. case IQ2000_OPERAND_CM_3Z :
  940. value = fields->f_cm_3z;
  941. break;
  942. case IQ2000_OPERAND_CM_4FUNC :
  943. value = fields->f_cm_4func;
  944. break;
  945. case IQ2000_OPERAND_CM_4Z :
  946. value = fields->f_cm_4z;
  947. break;
  948. case IQ2000_OPERAND_COUNT :
  949. value = fields->f_count;
  950. break;
  951. case IQ2000_OPERAND_EXECODE :
  952. value = fields->f_excode;
  953. break;
  954. case IQ2000_OPERAND_HI16 :
  955. value = fields->f_imm;
  956. break;
  957. case IQ2000_OPERAND_IMM :
  958. value = fields->f_imm;
  959. break;
  960. case IQ2000_OPERAND_JMPTARG :
  961. value = fields->f_jtarg;
  962. break;
  963. case IQ2000_OPERAND_JMPTARGQ10 :
  964. value = fields->f_jtargq10;
  965. break;
  966. case IQ2000_OPERAND_LO16 :
  967. value = fields->f_imm;
  968. break;
  969. case IQ2000_OPERAND_MASK :
  970. value = fields->f_mask;
  971. break;
  972. case IQ2000_OPERAND_MASKL :
  973. value = fields->f_maskl;
  974. break;
  975. case IQ2000_OPERAND_MASKQ10 :
  976. value = fields->f_maskq10;
  977. break;
  978. case IQ2000_OPERAND_MASKR :
  979. value = fields->f_rs;
  980. break;
  981. case IQ2000_OPERAND_MLO16 :
  982. value = fields->f_imm;
  983. break;
  984. case IQ2000_OPERAND_OFFSET :
  985. value = fields->f_offset;
  986. break;
  987. case IQ2000_OPERAND_RD :
  988. value = fields->f_rd;
  989. break;
  990. case IQ2000_OPERAND_RD_RS :
  991. value = fields->f_rd_rs;
  992. break;
  993. case IQ2000_OPERAND_RD_RT :
  994. value = fields->f_rd_rt;
  995. break;
  996. case IQ2000_OPERAND_RS :
  997. value = fields->f_rs;
  998. break;
  999. case IQ2000_OPERAND_RT :
  1000. value = fields->f_rt;
  1001. break;
  1002. case IQ2000_OPERAND_RT_RS :
  1003. value = fields->f_rt_rs;
  1004. break;
  1005. case IQ2000_OPERAND_SHAMT :
  1006. value = fields->f_shamt;
  1007. break;
  1008. default :
  1009. /* xgettext:c-format */
  1010. opcodes_error_handler
  1011. (_("internal error: unrecognized field %d while getting vma operand"),
  1012. opindex);
  1013. abort ();
  1014. }
  1015. return value;
  1016. }
  1017. void iq2000_cgen_set_int_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
  1018. void iq2000_cgen_set_vma_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
  1019. /* Stuffing values in cgen_fields is handled by a collection of functions.
  1020. They are distinguished by the type of the VALUE argument they accept.
  1021. TODO: floating point, inlining support, remove cases where argument type
  1022. not appropriate. */
  1023. void
  1024. iq2000_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  1025. int opindex,
  1026. CGEN_FIELDS * fields,
  1027. int value)
  1028. {
  1029. switch (opindex)
  1030. {
  1031. case IQ2000_OPERAND__INDEX :
  1032. fields->f_index = value;
  1033. break;
  1034. case IQ2000_OPERAND_BASE :
  1035. fields->f_rs = value;
  1036. break;
  1037. case IQ2000_OPERAND_BASEOFF :
  1038. fields->f_imm = value;
  1039. break;
  1040. case IQ2000_OPERAND_BITNUM :
  1041. fields->f_rt = value;
  1042. break;
  1043. case IQ2000_OPERAND_BYTECOUNT :
  1044. fields->f_bytecount = value;
  1045. break;
  1046. case IQ2000_OPERAND_CAM_Y :
  1047. fields->f_cam_y = value;
  1048. break;
  1049. case IQ2000_OPERAND_CAM_Z :
  1050. fields->f_cam_z = value;
  1051. break;
  1052. case IQ2000_OPERAND_CM_3FUNC :
  1053. fields->f_cm_3func = value;
  1054. break;
  1055. case IQ2000_OPERAND_CM_3Z :
  1056. fields->f_cm_3z = value;
  1057. break;
  1058. case IQ2000_OPERAND_CM_4FUNC :
  1059. fields->f_cm_4func = value;
  1060. break;
  1061. case IQ2000_OPERAND_CM_4Z :
  1062. fields->f_cm_4z = value;
  1063. break;
  1064. case IQ2000_OPERAND_COUNT :
  1065. fields->f_count = value;
  1066. break;
  1067. case IQ2000_OPERAND_EXECODE :
  1068. fields->f_excode = value;
  1069. break;
  1070. case IQ2000_OPERAND_HI16 :
  1071. fields->f_imm = value;
  1072. break;
  1073. case IQ2000_OPERAND_IMM :
  1074. fields->f_imm = value;
  1075. break;
  1076. case IQ2000_OPERAND_JMPTARG :
  1077. fields->f_jtarg = value;
  1078. break;
  1079. case IQ2000_OPERAND_JMPTARGQ10 :
  1080. fields->f_jtargq10 = value;
  1081. break;
  1082. case IQ2000_OPERAND_LO16 :
  1083. fields->f_imm = value;
  1084. break;
  1085. case IQ2000_OPERAND_MASK :
  1086. fields->f_mask = value;
  1087. break;
  1088. case IQ2000_OPERAND_MASKL :
  1089. fields->f_maskl = value;
  1090. break;
  1091. case IQ2000_OPERAND_MASKQ10 :
  1092. fields->f_maskq10 = value;
  1093. break;
  1094. case IQ2000_OPERAND_MASKR :
  1095. fields->f_rs = value;
  1096. break;
  1097. case IQ2000_OPERAND_MLO16 :
  1098. fields->f_imm = value;
  1099. break;
  1100. case IQ2000_OPERAND_OFFSET :
  1101. fields->f_offset = value;
  1102. break;
  1103. case IQ2000_OPERAND_RD :
  1104. fields->f_rd = value;
  1105. break;
  1106. case IQ2000_OPERAND_RD_RS :
  1107. fields->f_rd_rs = value;
  1108. break;
  1109. case IQ2000_OPERAND_RD_RT :
  1110. fields->f_rd_rt = value;
  1111. break;
  1112. case IQ2000_OPERAND_RS :
  1113. fields->f_rs = value;
  1114. break;
  1115. case IQ2000_OPERAND_RT :
  1116. fields->f_rt = value;
  1117. break;
  1118. case IQ2000_OPERAND_RT_RS :
  1119. fields->f_rt_rs = value;
  1120. break;
  1121. case IQ2000_OPERAND_SHAMT :
  1122. fields->f_shamt = value;
  1123. break;
  1124. default :
  1125. /* xgettext:c-format */
  1126. opcodes_error_handler
  1127. (_("internal error: unrecognized field %d while setting int operand"),
  1128. opindex);
  1129. abort ();
  1130. }
  1131. }
  1132. void
  1133. iq2000_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  1134. int opindex,
  1135. CGEN_FIELDS * fields,
  1136. bfd_vma value)
  1137. {
  1138. switch (opindex)
  1139. {
  1140. case IQ2000_OPERAND__INDEX :
  1141. fields->f_index = value;
  1142. break;
  1143. case IQ2000_OPERAND_BASE :
  1144. fields->f_rs = value;
  1145. break;
  1146. case IQ2000_OPERAND_BASEOFF :
  1147. fields->f_imm = value;
  1148. break;
  1149. case IQ2000_OPERAND_BITNUM :
  1150. fields->f_rt = value;
  1151. break;
  1152. case IQ2000_OPERAND_BYTECOUNT :
  1153. fields->f_bytecount = value;
  1154. break;
  1155. case IQ2000_OPERAND_CAM_Y :
  1156. fields->f_cam_y = value;
  1157. break;
  1158. case IQ2000_OPERAND_CAM_Z :
  1159. fields->f_cam_z = value;
  1160. break;
  1161. case IQ2000_OPERAND_CM_3FUNC :
  1162. fields->f_cm_3func = value;
  1163. break;
  1164. case IQ2000_OPERAND_CM_3Z :
  1165. fields->f_cm_3z = value;
  1166. break;
  1167. case IQ2000_OPERAND_CM_4FUNC :
  1168. fields->f_cm_4func = value;
  1169. break;
  1170. case IQ2000_OPERAND_CM_4Z :
  1171. fields->f_cm_4z = value;
  1172. break;
  1173. case IQ2000_OPERAND_COUNT :
  1174. fields->f_count = value;
  1175. break;
  1176. case IQ2000_OPERAND_EXECODE :
  1177. fields->f_excode = value;
  1178. break;
  1179. case IQ2000_OPERAND_HI16 :
  1180. fields->f_imm = value;
  1181. break;
  1182. case IQ2000_OPERAND_IMM :
  1183. fields->f_imm = value;
  1184. break;
  1185. case IQ2000_OPERAND_JMPTARG :
  1186. fields->f_jtarg = value;
  1187. break;
  1188. case IQ2000_OPERAND_JMPTARGQ10 :
  1189. fields->f_jtargq10 = value;
  1190. break;
  1191. case IQ2000_OPERAND_LO16 :
  1192. fields->f_imm = value;
  1193. break;
  1194. case IQ2000_OPERAND_MASK :
  1195. fields->f_mask = value;
  1196. break;
  1197. case IQ2000_OPERAND_MASKL :
  1198. fields->f_maskl = value;
  1199. break;
  1200. case IQ2000_OPERAND_MASKQ10 :
  1201. fields->f_maskq10 = value;
  1202. break;
  1203. case IQ2000_OPERAND_MASKR :
  1204. fields->f_rs = value;
  1205. break;
  1206. case IQ2000_OPERAND_MLO16 :
  1207. fields->f_imm = value;
  1208. break;
  1209. case IQ2000_OPERAND_OFFSET :
  1210. fields->f_offset = value;
  1211. break;
  1212. case IQ2000_OPERAND_RD :
  1213. fields->f_rd = value;
  1214. break;
  1215. case IQ2000_OPERAND_RD_RS :
  1216. fields->f_rd_rs = value;
  1217. break;
  1218. case IQ2000_OPERAND_RD_RT :
  1219. fields->f_rd_rt = value;
  1220. break;
  1221. case IQ2000_OPERAND_RS :
  1222. fields->f_rs = value;
  1223. break;
  1224. case IQ2000_OPERAND_RT :
  1225. fields->f_rt = value;
  1226. break;
  1227. case IQ2000_OPERAND_RT_RS :
  1228. fields->f_rt_rs = value;
  1229. break;
  1230. case IQ2000_OPERAND_SHAMT :
  1231. fields->f_shamt = value;
  1232. break;
  1233. default :
  1234. /* xgettext:c-format */
  1235. opcodes_error_handler
  1236. (_("internal error: unrecognized field %d while setting vma operand"),
  1237. opindex);
  1238. abort ();
  1239. }
  1240. }
  1241. /* Function to call before using the instruction builder tables. */
  1242. void
  1243. iq2000_cgen_init_ibld_table (CGEN_CPU_DESC cd)
  1244. {
  1245. cd->insert_handlers = & iq2000_cgen_insert_handlers[0];
  1246. cd->extract_handlers = & iq2000_cgen_extract_handlers[0];
  1247. cd->insert_operand = iq2000_cgen_insert_operand;
  1248. cd->extract_operand = iq2000_cgen_extract_operand;
  1249. cd->get_int_operand = iq2000_cgen_get_int_operand;
  1250. cd->set_int_operand = iq2000_cgen_set_int_operand;
  1251. cd->get_vma_operand = iq2000_cgen_get_vma_operand;
  1252. cd->set_vma_operand = iq2000_cgen_set_vma_operand;
  1253. }