xc16x-ibld.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  1. /* Instruction building/extraction support for xc16x. -*- C -*-
  2. THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator.
  3. - the resultant file is machine generated, cgen-ibld.in isn't
  4. Copyright (C) 1996-2015 Free Software Foundation, Inc.
  5. This file is part of libopcodes.
  6. This library is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3, or (at your option)
  9. any later version.
  10. It is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  13. License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software Foundation, Inc.,
  16. 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  17. /* ??? Eventually more and more of this stuff can go to cpu-independent files.
  18. Keep that in mind. */
  19. #include "sysdep.h"
  20. #include <stdio.h>
  21. #include "ansidecl.h"
  22. #include "dis-asm.h"
  23. #include "bfd.h"
  24. #include "symcat.h"
  25. #include "xc16x-desc.h"
  26. #include "xc16x-opc.h"
  27. #include "cgen/basic-modes.h"
  28. #include "opintl.h"
  29. #include "safe-ctype.h"
  30. #undef min
  31. #define min(a,b) ((a) < (b) ? (a) : (b))
  32. #undef max
  33. #define max(a,b) ((a) > (b) ? (a) : (b))
  34. /* Used by the ifield rtx function. */
  35. #define FLD(f) (fields->f)
  36. static const char * insert_normal
  37. (CGEN_CPU_DESC, long, unsigned int, unsigned int, unsigned int,
  38. unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR);
  39. static const char * insert_insn_normal
  40. (CGEN_CPU_DESC, const CGEN_INSN *,
  41. CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
  42. static int extract_normal
  43. (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
  44. unsigned int, unsigned int, unsigned int, unsigned int,
  45. unsigned int, unsigned int, bfd_vma, long *);
  46. static int extract_insn_normal
  47. (CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
  48. CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
  49. #if CGEN_INT_INSN_P
  50. static void put_insn_int_value
  51. (CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT);
  52. #endif
  53. #if ! CGEN_INT_INSN_P
  54. static CGEN_INLINE void insert_1
  55. (CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *);
  56. static CGEN_INLINE int fill_cache
  57. (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, bfd_vma);
  58. static CGEN_INLINE long extract_1
  59. (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int, unsigned char *, bfd_vma);
  60. #endif
  61. /* Operand insertion. */
  62. #if ! CGEN_INT_INSN_P
  63. /* Subroutine of insert_normal. */
  64. static CGEN_INLINE void
  65. insert_1 (CGEN_CPU_DESC cd,
  66. unsigned long value,
  67. int start,
  68. int length,
  69. int word_length,
  70. unsigned char *bufp)
  71. {
  72. unsigned long x,mask;
  73. int shift;
  74. x = cgen_get_insn_value (cd, bufp, word_length);
  75. /* Written this way to avoid undefined behaviour. */
  76. mask = (((1L << (length - 1)) - 1) << 1) | 1;
  77. if (CGEN_INSN_LSB0_P)
  78. shift = (start + 1) - length;
  79. else
  80. shift = (word_length - (start + length));
  81. x = (x & ~(mask << shift)) | ((value & mask) << shift);
  82. cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x);
  83. }
  84. #endif /* ! CGEN_INT_INSN_P */
  85. /* Default insertion routine.
  86. ATTRS is a mask of the boolean attributes.
  87. WORD_OFFSET is the offset in bits from the start of the insn of the value.
  88. WORD_LENGTH is the length of the word in bits in which the value resides.
  89. START is the starting bit number in the word, architecture origin.
  90. LENGTH is the length of VALUE in bits.
  91. TOTAL_LENGTH is the total length of the insn in bits.
  92. The result is an error message or NULL if success. */
  93. /* ??? This duplicates functionality with bfd's howto table and
  94. bfd_install_relocation. */
  95. /* ??? This doesn't handle bfd_vma's. Create another function when
  96. necessary. */
  97. static const char *
  98. insert_normal (CGEN_CPU_DESC cd,
  99. long value,
  100. unsigned int attrs,
  101. unsigned int word_offset,
  102. unsigned int start,
  103. unsigned int length,
  104. unsigned int word_length,
  105. unsigned int total_length,
  106. CGEN_INSN_BYTES_PTR buffer)
  107. {
  108. static char errbuf[100];
  109. /* Written this way to avoid undefined behaviour. */
  110. unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
  111. /* If LENGTH is zero, this operand doesn't contribute to the value. */
  112. if (length == 0)
  113. return NULL;
  114. if (word_length > 8 * sizeof (CGEN_INSN_INT))
  115. abort ();
  116. /* For architectures with insns smaller than the base-insn-bitsize,
  117. word_length may be too big. */
  118. if (cd->min_insn_bitsize < cd->base_insn_bitsize)
  119. {
  120. if (word_offset == 0
  121. && word_length > total_length)
  122. word_length = total_length;
  123. }
  124. /* Ensure VALUE will fit. */
  125. if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT))
  126. {
  127. long minval = - (1L << (length - 1));
  128. unsigned long maxval = mask;
  129. if ((value > 0 && (unsigned long) value > maxval)
  130. || value < minval)
  131. {
  132. /* xgettext:c-format */
  133. sprintf (errbuf,
  134. _("operand out of range (%ld not between %ld and %lu)"),
  135. value, minval, maxval);
  136. return errbuf;
  137. }
  138. }
  139. else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
  140. {
  141. unsigned long maxval = mask;
  142. unsigned long val = (unsigned long) value;
  143. /* For hosts with a word size > 32 check to see if value has been sign
  144. extended beyond 32 bits. If so then ignore these higher sign bits
  145. as the user is attempting to store a 32-bit signed value into an
  146. unsigned 32-bit field which is allowed. */
  147. if (sizeof (unsigned long) > 4 && ((value >> 32) == -1))
  148. val &= 0xFFFFFFFF;
  149. if (val > maxval)
  150. {
  151. /* xgettext:c-format */
  152. sprintf (errbuf,
  153. _("operand out of range (0x%lx not between 0 and 0x%lx)"),
  154. val, maxval);
  155. return errbuf;
  156. }
  157. }
  158. else
  159. {
  160. if (! cgen_signed_overflow_ok_p (cd))
  161. {
  162. long minval = - (1L << (length - 1));
  163. long maxval = (1L << (length - 1)) - 1;
  164. if (value < minval || value > maxval)
  165. {
  166. sprintf
  167. /* xgettext:c-format */
  168. (errbuf, _("operand out of range (%ld not between %ld and %ld)"),
  169. value, minval, maxval);
  170. return errbuf;
  171. }
  172. }
  173. }
  174. #if CGEN_INT_INSN_P
  175. {
  176. int shift;
  177. if (CGEN_INSN_LSB0_P)
  178. shift = (word_offset + start + 1) - length;
  179. else
  180. shift = total_length - (word_offset + start + length);
  181. *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
  182. }
  183. #else /* ! CGEN_INT_INSN_P */
  184. {
  185. unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
  186. insert_1 (cd, value, start, length, word_length, bufp);
  187. }
  188. #endif /* ! CGEN_INT_INSN_P */
  189. return NULL;
  190. }
  191. /* Default insn builder (insert handler).
  192. The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
  193. that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
  194. recorded in host byte order, otherwise BUFFER is an array of bytes
  195. and the value is recorded in target byte order).
  196. The result is an error message or NULL if success. */
  197. static const char *
  198. insert_insn_normal (CGEN_CPU_DESC cd,
  199. const CGEN_INSN * insn,
  200. CGEN_FIELDS * fields,
  201. CGEN_INSN_BYTES_PTR buffer,
  202. bfd_vma pc)
  203. {
  204. const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
  205. unsigned long value;
  206. const CGEN_SYNTAX_CHAR_TYPE * syn;
  207. CGEN_INIT_INSERT (cd);
  208. value = CGEN_INSN_BASE_VALUE (insn);
  209. /* If we're recording insns as numbers (rather than a string of bytes),
  210. target byte order handling is deferred until later. */
  211. #if CGEN_INT_INSN_P
  212. put_insn_int_value (cd, buffer, cd->base_insn_bitsize,
  213. CGEN_FIELDS_BITSIZE (fields), value);
  214. #else
  215. cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
  216. (unsigned) CGEN_FIELDS_BITSIZE (fields)),
  217. value);
  218. #endif /* ! CGEN_INT_INSN_P */
  219. /* ??? It would be better to scan the format's fields.
  220. Still need to be able to insert a value based on the operand though;
  221. e.g. storing a branch displacement that got resolved later.
  222. Needs more thought first. */
  223. for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
  224. {
  225. const char *errmsg;
  226. if (CGEN_SYNTAX_CHAR_P (* syn))
  227. continue;
  228. errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
  229. fields, buffer, pc);
  230. if (errmsg)
  231. return errmsg;
  232. }
  233. return NULL;
  234. }
  235. #if CGEN_INT_INSN_P
  236. /* Cover function to store an insn value into an integral insn. Must go here
  237. because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */
  238. static void
  239. put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  240. CGEN_INSN_BYTES_PTR buf,
  241. int length,
  242. int insn_length,
  243. CGEN_INSN_INT value)
  244. {
  245. /* For architectures with insns smaller than the base-insn-bitsize,
  246. length may be too big. */
  247. if (length > insn_length)
  248. *buf = value;
  249. else
  250. {
  251. int shift = insn_length - length;
  252. /* Written this way to avoid undefined behaviour. */
  253. CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1;
  254. *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift);
  255. }
  256. }
  257. #endif
  258. /* Operand extraction. */
  259. #if ! CGEN_INT_INSN_P
  260. /* Subroutine of extract_normal.
  261. Ensure sufficient bytes are cached in EX_INFO.
  262. OFFSET is the offset in bytes from the start of the insn of the value.
  263. BYTES is the length of the needed value.
  264. Returns 1 for success, 0 for failure. */
  265. static CGEN_INLINE int
  266. fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  267. CGEN_EXTRACT_INFO *ex_info,
  268. int offset,
  269. int bytes,
  270. bfd_vma pc)
  271. {
  272. /* It's doubtful that the middle part has already been fetched so
  273. we don't optimize that case. kiss. */
  274. unsigned int mask;
  275. disassemble_info *info = (disassemble_info *) ex_info->dis_info;
  276. /* First do a quick check. */
  277. mask = (1 << bytes) - 1;
  278. if (((ex_info->valid >> offset) & mask) == mask)
  279. return 1;
  280. /* Search for the first byte we need to read. */
  281. for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
  282. if (! (mask & ex_info->valid))
  283. break;
  284. if (bytes)
  285. {
  286. int status;
  287. pc += offset;
  288. status = (*info->read_memory_func)
  289. (pc, ex_info->insn_bytes + offset, bytes, info);
  290. if (status != 0)
  291. {
  292. (*info->memory_error_func) (status, pc, info);
  293. return 0;
  294. }
  295. ex_info->valid |= ((1 << bytes) - 1) << offset;
  296. }
  297. return 1;
  298. }
  299. /* Subroutine of extract_normal. */
  300. static CGEN_INLINE long
  301. extract_1 (CGEN_CPU_DESC cd,
  302. CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
  303. int start,
  304. int length,
  305. int word_length,
  306. unsigned char *bufp,
  307. bfd_vma pc ATTRIBUTE_UNUSED)
  308. {
  309. unsigned long x;
  310. int shift;
  311. x = cgen_get_insn_value (cd, bufp, word_length);
  312. if (CGEN_INSN_LSB0_P)
  313. shift = (start + 1) - length;
  314. else
  315. shift = (word_length - (start + length));
  316. return x >> shift;
  317. }
  318. #endif /* ! CGEN_INT_INSN_P */
  319. /* Default extraction routine.
  320. INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
  321. or sometimes less for cases like the m32r where the base insn size is 32
  322. but some insns are 16 bits.
  323. ATTRS is a mask of the boolean attributes. We only need `SIGNED',
  324. but for generality we take a bitmask of all of them.
  325. WORD_OFFSET is the offset in bits from the start of the insn of the value.
  326. WORD_LENGTH is the length of the word in bits in which the value resides.
  327. START is the starting bit number in the word, architecture origin.
  328. LENGTH is the length of VALUE in bits.
  329. TOTAL_LENGTH is the total length of the insn in bits.
  330. Returns 1 for success, 0 for failure. */
  331. /* ??? The return code isn't properly used. wip. */
  332. /* ??? This doesn't handle bfd_vma's. Create another function when
  333. necessary. */
  334. static int
  335. extract_normal (CGEN_CPU_DESC cd,
  336. #if ! CGEN_INT_INSN_P
  337. CGEN_EXTRACT_INFO *ex_info,
  338. #else
  339. CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
  340. #endif
  341. CGEN_INSN_INT insn_value,
  342. unsigned int attrs,
  343. unsigned int word_offset,
  344. unsigned int start,
  345. unsigned int length,
  346. unsigned int word_length,
  347. unsigned int total_length,
  348. #if ! CGEN_INT_INSN_P
  349. bfd_vma pc,
  350. #else
  351. bfd_vma pc ATTRIBUTE_UNUSED,
  352. #endif
  353. long *valuep)
  354. {
  355. long value, mask;
  356. /* If LENGTH is zero, this operand doesn't contribute to the value
  357. so give it a standard value of zero. */
  358. if (length == 0)
  359. {
  360. *valuep = 0;
  361. return 1;
  362. }
  363. if (word_length > 8 * sizeof (CGEN_INSN_INT))
  364. abort ();
  365. /* For architectures with insns smaller than the insn-base-bitsize,
  366. word_length may be too big. */
  367. if (cd->min_insn_bitsize < cd->base_insn_bitsize)
  368. {
  369. if (word_offset + word_length > total_length)
  370. word_length = total_length - word_offset;
  371. }
  372. /* Does the value reside in INSN_VALUE, and at the right alignment? */
  373. if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
  374. {
  375. if (CGEN_INSN_LSB0_P)
  376. value = insn_value >> ((word_offset + start + 1) - length);
  377. else
  378. value = insn_value >> (total_length - ( word_offset + start + length));
  379. }
  380. #if ! CGEN_INT_INSN_P
  381. else
  382. {
  383. unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
  384. if (word_length > 8 * sizeof (CGEN_INSN_INT))
  385. abort ();
  386. if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
  387. return 0;
  388. value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
  389. }
  390. #endif /* ! CGEN_INT_INSN_P */
  391. /* Written this way to avoid undefined behaviour. */
  392. mask = (((1L << (length - 1)) - 1) << 1) | 1;
  393. value &= mask;
  394. /* sign extend? */
  395. if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
  396. && (value & (1L << (length - 1))))
  397. value |= ~mask;
  398. *valuep = value;
  399. return 1;
  400. }
  401. /* Default insn extractor.
  402. INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
  403. The extracted fields are stored in FIELDS.
  404. EX_INFO is used to handle reading variable length insns.
  405. Return the length of the insn in bits, or 0 if no match,
  406. or -1 if an error occurs fetching data (memory_error_func will have
  407. been called). */
  408. static int
  409. extract_insn_normal (CGEN_CPU_DESC cd,
  410. const CGEN_INSN *insn,
  411. CGEN_EXTRACT_INFO *ex_info,
  412. CGEN_INSN_INT insn_value,
  413. CGEN_FIELDS *fields,
  414. bfd_vma pc)
  415. {
  416. const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
  417. const CGEN_SYNTAX_CHAR_TYPE *syn;
  418. CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
  419. CGEN_INIT_EXTRACT (cd);
  420. for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
  421. {
  422. int length;
  423. if (CGEN_SYNTAX_CHAR_P (*syn))
  424. continue;
  425. length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
  426. ex_info, insn_value, fields, pc);
  427. if (length <= 0)
  428. return length;
  429. }
  430. /* We recognized and successfully extracted this insn. */
  431. return CGEN_INSN_BITSIZE (insn);
  432. }
  433. /* Machine generated code added here. */
  434. const char * xc16x_cgen_insert_operand
  435. (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
  436. /* Main entry point for operand insertion.
  437. This function is basically just a big switch statement. Earlier versions
  438. used tables to look up the function to use, but
  439. - if the table contains both assembler and disassembler functions then
  440. the disassembler contains much of the assembler and vice-versa,
  441. - there's a lot of inlining possibilities as things grow,
  442. - using a switch statement avoids the function call overhead.
  443. This function could be moved into `parse_insn_normal', but keeping it
  444. separate makes clear the interface between `parse_insn_normal' and each of
  445. the handlers. It's also needed by GAS to insert operands that couldn't be
  446. resolved during parsing. */
  447. const char *
  448. xc16x_cgen_insert_operand (CGEN_CPU_DESC cd,
  449. int opindex,
  450. CGEN_FIELDS * fields,
  451. CGEN_INSN_BYTES_PTR buffer,
  452. bfd_vma pc ATTRIBUTE_UNUSED)
  453. {
  454. const char * errmsg = NULL;
  455. unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
  456. switch (opindex)
  457. {
  458. case XC16X_OPERAND_REGNAM :
  459. errmsg = insert_normal (cd, fields->f_reg8, 0, 0, 15, 8, 32, total_length, buffer);
  460. break;
  461. case XC16X_OPERAND_BIT01 :
  462. errmsg = insert_normal (cd, fields->f_op_1bit, 0, 0, 8, 1, 32, total_length, buffer);
  463. break;
  464. case XC16X_OPERAND_BIT1 :
  465. errmsg = insert_normal (cd, fields->f_op_bit1, 0, 0, 11, 1, 32, total_length, buffer);
  466. break;
  467. case XC16X_OPERAND_BIT2 :
  468. errmsg = insert_normal (cd, fields->f_op_bit2, 0, 0, 11, 2, 32, total_length, buffer);
  469. break;
  470. case XC16X_OPERAND_BIT4 :
  471. errmsg = insert_normal (cd, fields->f_op_bit4, 0, 0, 11, 4, 32, total_length, buffer);
  472. break;
  473. case XC16X_OPERAND_BIT8 :
  474. errmsg = insert_normal (cd, fields->f_op_bit8, 0, 0, 31, 8, 32, total_length, buffer);
  475. break;
  476. case XC16X_OPERAND_BITONE :
  477. errmsg = insert_normal (cd, fields->f_op_onebit, 0, 0, 9, 1, 32, total_length, buffer);
  478. break;
  479. case XC16X_OPERAND_CADDR :
  480. errmsg = insert_normal (cd, fields->f_offset16, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, buffer);
  481. break;
  482. case XC16X_OPERAND_COND :
  483. errmsg = insert_normal (cd, fields->f_condcode, 0, 0, 7, 4, 32, total_length, buffer);
  484. break;
  485. case XC16X_OPERAND_DATA8 :
  486. errmsg = insert_normal (cd, fields->f_data8, 0, 0, 23, 8, 32, total_length, buffer);
  487. break;
  488. case XC16X_OPERAND_DATAHI8 :
  489. errmsg = insert_normal (cd, fields->f_datahi8, 0, 0, 31, 8, 32, total_length, buffer);
  490. break;
  491. case XC16X_OPERAND_DOT :
  492. break;
  493. case XC16X_OPERAND_DR :
  494. errmsg = insert_normal (cd, fields->f_r1, 0, 0, 15, 4, 32, total_length, buffer);
  495. break;
  496. case XC16X_OPERAND_DRB :
  497. errmsg = insert_normal (cd, fields->f_r1, 0, 0, 15, 4, 32, total_length, buffer);
  498. break;
  499. case XC16X_OPERAND_DRI :
  500. errmsg = insert_normal (cd, fields->f_r4, 0, 0, 11, 4, 32, total_length, buffer);
  501. break;
  502. case XC16X_OPERAND_EXTCOND :
  503. errmsg = insert_normal (cd, fields->f_extccode, 0, 0, 15, 5, 32, total_length, buffer);
  504. break;
  505. case XC16X_OPERAND_GENREG :
  506. errmsg = insert_normal (cd, fields->f_regb8, 0, 0, 15, 8, 32, total_length, buffer);
  507. break;
  508. case XC16X_OPERAND_HASH :
  509. break;
  510. case XC16X_OPERAND_ICOND :
  511. errmsg = insert_normal (cd, fields->f_icondcode, 0, 0, 15, 4, 32, total_length, buffer);
  512. break;
  513. case XC16X_OPERAND_LBIT2 :
  514. errmsg = insert_normal (cd, fields->f_op_lbit2, 0, 0, 15, 2, 32, total_length, buffer);
  515. break;
  516. case XC16X_OPERAND_LBIT4 :
  517. errmsg = insert_normal (cd, fields->f_op_lbit4, 0, 0, 15, 4, 32, total_length, buffer);
  518. break;
  519. case XC16X_OPERAND_MASK8 :
  520. errmsg = insert_normal (cd, fields->f_mask8, 0, 0, 23, 8, 32, total_length, buffer);
  521. break;
  522. case XC16X_OPERAND_MASKLO8 :
  523. errmsg = insert_normal (cd, fields->f_datahi8, 0, 0, 31, 8, 32, total_length, buffer);
  524. break;
  525. case XC16X_OPERAND_MEMGR8 :
  526. errmsg = insert_normal (cd, fields->f_memgr8, 0, 0, 31, 16, 32, total_length, buffer);
  527. break;
  528. case XC16X_OPERAND_MEMORY :
  529. errmsg = insert_normal (cd, fields->f_memory, 0, 0, 31, 16, 32, total_length, buffer);
  530. break;
  531. case XC16X_OPERAND_PAG :
  532. break;
  533. case XC16X_OPERAND_PAGENUM :
  534. errmsg = insert_normal (cd, fields->f_pagenum, 0, 0, 25, 10, 32, total_length, buffer);
  535. break;
  536. case XC16X_OPERAND_POF :
  537. break;
  538. case XC16X_OPERAND_QBIT :
  539. errmsg = insert_normal (cd, fields->f_qbit, 0, 0, 7, 4, 32, total_length, buffer);
  540. break;
  541. case XC16X_OPERAND_QHIBIT :
  542. errmsg = insert_normal (cd, fields->f_qhibit, 0, 0, 27, 4, 32, total_length, buffer);
  543. break;
  544. case XC16X_OPERAND_QLOBIT :
  545. errmsg = insert_normal (cd, fields->f_qlobit, 0, 0, 31, 4, 32, total_length, buffer);
  546. break;
  547. case XC16X_OPERAND_REG8 :
  548. errmsg = insert_normal (cd, fields->f_reg8, 0, 0, 15, 8, 32, total_length, buffer);
  549. break;
  550. case XC16X_OPERAND_REGB8 :
  551. errmsg = insert_normal (cd, fields->f_regb8, 0, 0, 15, 8, 32, total_length, buffer);
  552. break;
  553. case XC16X_OPERAND_REGBMEM8 :
  554. errmsg = insert_normal (cd, fields->f_regmem8, 0, 0, 15, 8, 32, total_length, buffer);
  555. break;
  556. case XC16X_OPERAND_REGHI8 :
  557. errmsg = insert_normal (cd, fields->f_reghi8, 0, 0, 23, 8, 32, total_length, buffer);
  558. break;
  559. case XC16X_OPERAND_REGMEM8 :
  560. errmsg = insert_normal (cd, fields->f_regmem8, 0, 0, 15, 8, 32, total_length, buffer);
  561. break;
  562. case XC16X_OPERAND_REGOFF8 :
  563. errmsg = insert_normal (cd, fields->f_regoff8, 0, 0, 15, 8, 32, total_length, buffer);
  564. break;
  565. case XC16X_OPERAND_REL :
  566. errmsg = insert_normal (cd, fields->f_rel8, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 8, 32, total_length, buffer);
  567. break;
  568. case XC16X_OPERAND_RELHI :
  569. errmsg = insert_normal (cd, fields->f_relhi8, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 23, 8, 32, total_length, buffer);
  570. break;
  571. case XC16X_OPERAND_SEG :
  572. errmsg = insert_normal (cd, fields->f_seg8, 0, 0, 15, 8, 32, total_length, buffer);
  573. break;
  574. case XC16X_OPERAND_SEGHI8 :
  575. errmsg = insert_normal (cd, fields->f_segnum8, 0, 0, 23, 8, 32, total_length, buffer);
  576. break;
  577. case XC16X_OPERAND_SEGM :
  578. break;
  579. case XC16X_OPERAND_SOF :
  580. break;
  581. case XC16X_OPERAND_SR :
  582. errmsg = insert_normal (cd, fields->f_r2, 0, 0, 11, 4, 32, total_length, buffer);
  583. break;
  584. case XC16X_OPERAND_SR2 :
  585. errmsg = insert_normal (cd, fields->f_r0, 0, 0, 9, 2, 32, total_length, buffer);
  586. break;
  587. case XC16X_OPERAND_SRB :
  588. errmsg = insert_normal (cd, fields->f_r2, 0, 0, 11, 4, 32, total_length, buffer);
  589. break;
  590. case XC16X_OPERAND_SRC1 :
  591. errmsg = insert_normal (cd, fields->f_r1, 0, 0, 15, 4, 32, total_length, buffer);
  592. break;
  593. case XC16X_OPERAND_SRC2 :
  594. errmsg = insert_normal (cd, fields->f_r2, 0, 0, 11, 4, 32, total_length, buffer);
  595. break;
  596. case XC16X_OPERAND_SRDIV :
  597. errmsg = insert_normal (cd, fields->f_reg8, 0, 0, 15, 8, 32, total_length, buffer);
  598. break;
  599. case XC16X_OPERAND_U4 :
  600. errmsg = insert_normal (cd, fields->f_uimm4, 0, 0, 15, 4, 32, total_length, buffer);
  601. break;
  602. case XC16X_OPERAND_UIMM16 :
  603. errmsg = insert_normal (cd, fields->f_uimm16, 0, 0, 31, 16, 32, total_length, buffer);
  604. break;
  605. case XC16X_OPERAND_UIMM2 :
  606. errmsg = insert_normal (cd, fields->f_uimm2, 0, 0, 13, 2, 32, total_length, buffer);
  607. break;
  608. case XC16X_OPERAND_UIMM3 :
  609. errmsg = insert_normal (cd, fields->f_uimm3, 0, 0, 10, 3, 32, total_length, buffer);
  610. break;
  611. case XC16X_OPERAND_UIMM4 :
  612. errmsg = insert_normal (cd, fields->f_uimm4, 0, 0, 15, 4, 32, total_length, buffer);
  613. break;
  614. case XC16X_OPERAND_UIMM7 :
  615. errmsg = insert_normal (cd, fields->f_uimm7, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 7, 32, total_length, buffer);
  616. break;
  617. case XC16X_OPERAND_UIMM8 :
  618. errmsg = insert_normal (cd, fields->f_uimm8, 0, 0, 23, 8, 32, total_length, buffer);
  619. break;
  620. case XC16X_OPERAND_UPAG16 :
  621. errmsg = insert_normal (cd, fields->f_uimm16, 0, 0, 31, 16, 32, total_length, buffer);
  622. break;
  623. case XC16X_OPERAND_UPOF16 :
  624. errmsg = insert_normal (cd, fields->f_memory, 0, 0, 31, 16, 32, total_length, buffer);
  625. break;
  626. case XC16X_OPERAND_USEG16 :
  627. errmsg = insert_normal (cd, fields->f_offset16, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, buffer);
  628. break;
  629. case XC16X_OPERAND_USEG8 :
  630. errmsg = insert_normal (cd, fields->f_seg8, 0, 0, 15, 8, 32, total_length, buffer);
  631. break;
  632. case XC16X_OPERAND_USOF16 :
  633. errmsg = insert_normal (cd, fields->f_offset16, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, buffer);
  634. break;
  635. default :
  636. /* xgettext:c-format */
  637. fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
  638. opindex);
  639. abort ();
  640. }
  641. return errmsg;
  642. }
  643. int xc16x_cgen_extract_operand
  644. (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
  645. /* Main entry point for operand extraction.
  646. The result is <= 0 for error, >0 for success.
  647. ??? Actual values aren't well defined right now.
  648. This function is basically just a big switch statement. Earlier versions
  649. used tables to look up the function to use, but
  650. - if the table contains both assembler and disassembler functions then
  651. the disassembler contains much of the assembler and vice-versa,
  652. - there's a lot of inlining possibilities as things grow,
  653. - using a switch statement avoids the function call overhead.
  654. This function could be moved into `print_insn_normal', but keeping it
  655. separate makes clear the interface between `print_insn_normal' and each of
  656. the handlers. */
  657. int
  658. xc16x_cgen_extract_operand (CGEN_CPU_DESC cd,
  659. int opindex,
  660. CGEN_EXTRACT_INFO *ex_info,
  661. CGEN_INSN_INT insn_value,
  662. CGEN_FIELDS * fields,
  663. bfd_vma pc)
  664. {
  665. /* Assume success (for those operands that are nops). */
  666. int length = 1;
  667. unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
  668. switch (opindex)
  669. {
  670. case XC16X_OPERAND_REGNAM :
  671. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_reg8);
  672. break;
  673. case XC16X_OPERAND_BIT01 :
  674. length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 1, 32, total_length, pc, & fields->f_op_1bit);
  675. break;
  676. case XC16X_OPERAND_BIT1 :
  677. length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_op_bit1);
  678. break;
  679. case XC16X_OPERAND_BIT2 :
  680. length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 2, 32, total_length, pc, & fields->f_op_bit2);
  681. break;
  682. case XC16X_OPERAND_BIT4 :
  683. length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_op_bit4);
  684. break;
  685. case XC16X_OPERAND_BIT8 :
  686. length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 8, 32, total_length, pc, & fields->f_op_bit8);
  687. break;
  688. case XC16X_OPERAND_BITONE :
  689. length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 1, 32, total_length, pc, & fields->f_op_onebit);
  690. break;
  691. case XC16X_OPERAND_CADDR :
  692. length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, pc, & fields->f_offset16);
  693. break;
  694. case XC16X_OPERAND_COND :
  695. length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 4, 32, total_length, pc, & fields->f_condcode);
  696. break;
  697. case XC16X_OPERAND_DATA8 :
  698. length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_data8);
  699. break;
  700. case XC16X_OPERAND_DATAHI8 :
  701. length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 8, 32, total_length, pc, & fields->f_datahi8);
  702. break;
  703. case XC16X_OPERAND_DOT :
  704. break;
  705. case XC16X_OPERAND_DR :
  706. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_r1);
  707. break;
  708. case XC16X_OPERAND_DRB :
  709. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_r1);
  710. break;
  711. case XC16X_OPERAND_DRI :
  712. length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_r4);
  713. break;
  714. case XC16X_OPERAND_EXTCOND :
  715. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_extccode);
  716. break;
  717. case XC16X_OPERAND_GENREG :
  718. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regb8);
  719. break;
  720. case XC16X_OPERAND_HASH :
  721. break;
  722. case XC16X_OPERAND_ICOND :
  723. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_icondcode);
  724. break;
  725. case XC16X_OPERAND_LBIT2 :
  726. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 2, 32, total_length, pc, & fields->f_op_lbit2);
  727. break;
  728. case XC16X_OPERAND_LBIT4 :
  729. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_op_lbit4);
  730. break;
  731. case XC16X_OPERAND_MASK8 :
  732. length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_mask8);
  733. break;
  734. case XC16X_OPERAND_MASKLO8 :
  735. length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 8, 32, total_length, pc, & fields->f_datahi8);
  736. break;
  737. case XC16X_OPERAND_MEMGR8 :
  738. length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_memgr8);
  739. break;
  740. case XC16X_OPERAND_MEMORY :
  741. length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_memory);
  742. break;
  743. case XC16X_OPERAND_PAG :
  744. break;
  745. case XC16X_OPERAND_PAGENUM :
  746. length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 10, 32, total_length, pc, & fields->f_pagenum);
  747. break;
  748. case XC16X_OPERAND_POF :
  749. break;
  750. case XC16X_OPERAND_QBIT :
  751. length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 4, 32, total_length, pc, & fields->f_qbit);
  752. break;
  753. case XC16X_OPERAND_QHIBIT :
  754. length = extract_normal (cd, ex_info, insn_value, 0, 0, 27, 4, 32, total_length, pc, & fields->f_qhibit);
  755. break;
  756. case XC16X_OPERAND_QLOBIT :
  757. length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 4, 32, total_length, pc, & fields->f_qlobit);
  758. break;
  759. case XC16X_OPERAND_REG8 :
  760. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_reg8);
  761. break;
  762. case XC16X_OPERAND_REGB8 :
  763. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regb8);
  764. break;
  765. case XC16X_OPERAND_REGBMEM8 :
  766. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regmem8);
  767. break;
  768. case XC16X_OPERAND_REGHI8 :
  769. length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_reghi8);
  770. break;
  771. case XC16X_OPERAND_REGMEM8 :
  772. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regmem8);
  773. break;
  774. case XC16X_OPERAND_REGOFF8 :
  775. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regoff8);
  776. break;
  777. case XC16X_OPERAND_REL :
  778. length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 8, 32, total_length, pc, & fields->f_rel8);
  779. break;
  780. case XC16X_OPERAND_RELHI :
  781. length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 23, 8, 32, total_length, pc, & fields->f_relhi8);
  782. break;
  783. case XC16X_OPERAND_SEG :
  784. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_seg8);
  785. break;
  786. case XC16X_OPERAND_SEGHI8 :
  787. length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_segnum8);
  788. break;
  789. case XC16X_OPERAND_SEGM :
  790. break;
  791. case XC16X_OPERAND_SOF :
  792. break;
  793. case XC16X_OPERAND_SR :
  794. length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_r2);
  795. break;
  796. case XC16X_OPERAND_SR2 :
  797. length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 2, 32, total_length, pc, & fields->f_r0);
  798. break;
  799. case XC16X_OPERAND_SRB :
  800. length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_r2);
  801. break;
  802. case XC16X_OPERAND_SRC1 :
  803. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_r1);
  804. break;
  805. case XC16X_OPERAND_SRC2 :
  806. length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_r2);
  807. break;
  808. case XC16X_OPERAND_SRDIV :
  809. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_reg8);
  810. break;
  811. case XC16X_OPERAND_U4 :
  812. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_uimm4);
  813. break;
  814. case XC16X_OPERAND_UIMM16 :
  815. length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_uimm16);
  816. break;
  817. case XC16X_OPERAND_UIMM2 :
  818. length = extract_normal (cd, ex_info, insn_value, 0, 0, 13, 2, 32, total_length, pc, & fields->f_uimm2);
  819. break;
  820. case XC16X_OPERAND_UIMM3 :
  821. length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 3, 32, total_length, pc, & fields->f_uimm3);
  822. break;
  823. case XC16X_OPERAND_UIMM4 :
  824. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_uimm4);
  825. break;
  826. case XC16X_OPERAND_UIMM7 :
  827. length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 7, 32, total_length, pc, & fields->f_uimm7);
  828. break;
  829. case XC16X_OPERAND_UIMM8 :
  830. length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_uimm8);
  831. break;
  832. case XC16X_OPERAND_UPAG16 :
  833. length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_uimm16);
  834. break;
  835. case XC16X_OPERAND_UPOF16 :
  836. length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_memory);
  837. break;
  838. case XC16X_OPERAND_USEG16 :
  839. length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, pc, & fields->f_offset16);
  840. break;
  841. case XC16X_OPERAND_USEG8 :
  842. length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_seg8);
  843. break;
  844. case XC16X_OPERAND_USOF16 :
  845. length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, pc, & fields->f_offset16);
  846. break;
  847. default :
  848. /* xgettext:c-format */
  849. fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
  850. opindex);
  851. abort ();
  852. }
  853. return length;
  854. }
  855. cgen_insert_fn * const xc16x_cgen_insert_handlers[] =
  856. {
  857. insert_insn_normal,
  858. };
  859. cgen_extract_fn * const xc16x_cgen_extract_handlers[] =
  860. {
  861. extract_insn_normal,
  862. };
  863. int xc16x_cgen_get_int_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
  864. bfd_vma xc16x_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
  865. /* Getting values from cgen_fields is handled by a collection of functions.
  866. They are distinguished by the type of the VALUE argument they return.
  867. TODO: floating point, inlining support, remove cases where result type
  868. not appropriate. */
  869. int
  870. xc16x_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  871. int opindex,
  872. const CGEN_FIELDS * fields)
  873. {
  874. int value;
  875. switch (opindex)
  876. {
  877. case XC16X_OPERAND_REGNAM :
  878. value = fields->f_reg8;
  879. break;
  880. case XC16X_OPERAND_BIT01 :
  881. value = fields->f_op_1bit;
  882. break;
  883. case XC16X_OPERAND_BIT1 :
  884. value = fields->f_op_bit1;
  885. break;
  886. case XC16X_OPERAND_BIT2 :
  887. value = fields->f_op_bit2;
  888. break;
  889. case XC16X_OPERAND_BIT4 :
  890. value = fields->f_op_bit4;
  891. break;
  892. case XC16X_OPERAND_BIT8 :
  893. value = fields->f_op_bit8;
  894. break;
  895. case XC16X_OPERAND_BITONE :
  896. value = fields->f_op_onebit;
  897. break;
  898. case XC16X_OPERAND_CADDR :
  899. value = fields->f_offset16;
  900. break;
  901. case XC16X_OPERAND_COND :
  902. value = fields->f_condcode;
  903. break;
  904. case XC16X_OPERAND_DATA8 :
  905. value = fields->f_data8;
  906. break;
  907. case XC16X_OPERAND_DATAHI8 :
  908. value = fields->f_datahi8;
  909. break;
  910. case XC16X_OPERAND_DOT :
  911. value = 0;
  912. break;
  913. case XC16X_OPERAND_DR :
  914. value = fields->f_r1;
  915. break;
  916. case XC16X_OPERAND_DRB :
  917. value = fields->f_r1;
  918. break;
  919. case XC16X_OPERAND_DRI :
  920. value = fields->f_r4;
  921. break;
  922. case XC16X_OPERAND_EXTCOND :
  923. value = fields->f_extccode;
  924. break;
  925. case XC16X_OPERAND_GENREG :
  926. value = fields->f_regb8;
  927. break;
  928. case XC16X_OPERAND_HASH :
  929. value = 0;
  930. break;
  931. case XC16X_OPERAND_ICOND :
  932. value = fields->f_icondcode;
  933. break;
  934. case XC16X_OPERAND_LBIT2 :
  935. value = fields->f_op_lbit2;
  936. break;
  937. case XC16X_OPERAND_LBIT4 :
  938. value = fields->f_op_lbit4;
  939. break;
  940. case XC16X_OPERAND_MASK8 :
  941. value = fields->f_mask8;
  942. break;
  943. case XC16X_OPERAND_MASKLO8 :
  944. value = fields->f_datahi8;
  945. break;
  946. case XC16X_OPERAND_MEMGR8 :
  947. value = fields->f_memgr8;
  948. break;
  949. case XC16X_OPERAND_MEMORY :
  950. value = fields->f_memory;
  951. break;
  952. case XC16X_OPERAND_PAG :
  953. value = 0;
  954. break;
  955. case XC16X_OPERAND_PAGENUM :
  956. value = fields->f_pagenum;
  957. break;
  958. case XC16X_OPERAND_POF :
  959. value = 0;
  960. break;
  961. case XC16X_OPERAND_QBIT :
  962. value = fields->f_qbit;
  963. break;
  964. case XC16X_OPERAND_QHIBIT :
  965. value = fields->f_qhibit;
  966. break;
  967. case XC16X_OPERAND_QLOBIT :
  968. value = fields->f_qlobit;
  969. break;
  970. case XC16X_OPERAND_REG8 :
  971. value = fields->f_reg8;
  972. break;
  973. case XC16X_OPERAND_REGB8 :
  974. value = fields->f_regb8;
  975. break;
  976. case XC16X_OPERAND_REGBMEM8 :
  977. value = fields->f_regmem8;
  978. break;
  979. case XC16X_OPERAND_REGHI8 :
  980. value = fields->f_reghi8;
  981. break;
  982. case XC16X_OPERAND_REGMEM8 :
  983. value = fields->f_regmem8;
  984. break;
  985. case XC16X_OPERAND_REGOFF8 :
  986. value = fields->f_regoff8;
  987. break;
  988. case XC16X_OPERAND_REL :
  989. value = fields->f_rel8;
  990. break;
  991. case XC16X_OPERAND_RELHI :
  992. value = fields->f_relhi8;
  993. break;
  994. case XC16X_OPERAND_SEG :
  995. value = fields->f_seg8;
  996. break;
  997. case XC16X_OPERAND_SEGHI8 :
  998. value = fields->f_segnum8;
  999. break;
  1000. case XC16X_OPERAND_SEGM :
  1001. value = 0;
  1002. break;
  1003. case XC16X_OPERAND_SOF :
  1004. value = 0;
  1005. break;
  1006. case XC16X_OPERAND_SR :
  1007. value = fields->f_r2;
  1008. break;
  1009. case XC16X_OPERAND_SR2 :
  1010. value = fields->f_r0;
  1011. break;
  1012. case XC16X_OPERAND_SRB :
  1013. value = fields->f_r2;
  1014. break;
  1015. case XC16X_OPERAND_SRC1 :
  1016. value = fields->f_r1;
  1017. break;
  1018. case XC16X_OPERAND_SRC2 :
  1019. value = fields->f_r2;
  1020. break;
  1021. case XC16X_OPERAND_SRDIV :
  1022. value = fields->f_reg8;
  1023. break;
  1024. case XC16X_OPERAND_U4 :
  1025. value = fields->f_uimm4;
  1026. break;
  1027. case XC16X_OPERAND_UIMM16 :
  1028. value = fields->f_uimm16;
  1029. break;
  1030. case XC16X_OPERAND_UIMM2 :
  1031. value = fields->f_uimm2;
  1032. break;
  1033. case XC16X_OPERAND_UIMM3 :
  1034. value = fields->f_uimm3;
  1035. break;
  1036. case XC16X_OPERAND_UIMM4 :
  1037. value = fields->f_uimm4;
  1038. break;
  1039. case XC16X_OPERAND_UIMM7 :
  1040. value = fields->f_uimm7;
  1041. break;
  1042. case XC16X_OPERAND_UIMM8 :
  1043. value = fields->f_uimm8;
  1044. break;
  1045. case XC16X_OPERAND_UPAG16 :
  1046. value = fields->f_uimm16;
  1047. break;
  1048. case XC16X_OPERAND_UPOF16 :
  1049. value = fields->f_memory;
  1050. break;
  1051. case XC16X_OPERAND_USEG16 :
  1052. value = fields->f_offset16;
  1053. break;
  1054. case XC16X_OPERAND_USEG8 :
  1055. value = fields->f_seg8;
  1056. break;
  1057. case XC16X_OPERAND_USOF16 :
  1058. value = fields->f_offset16;
  1059. break;
  1060. default :
  1061. /* xgettext:c-format */
  1062. fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"),
  1063. opindex);
  1064. abort ();
  1065. }
  1066. return value;
  1067. }
  1068. bfd_vma
  1069. xc16x_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  1070. int opindex,
  1071. const CGEN_FIELDS * fields)
  1072. {
  1073. bfd_vma value;
  1074. switch (opindex)
  1075. {
  1076. case XC16X_OPERAND_REGNAM :
  1077. value = fields->f_reg8;
  1078. break;
  1079. case XC16X_OPERAND_BIT01 :
  1080. value = fields->f_op_1bit;
  1081. break;
  1082. case XC16X_OPERAND_BIT1 :
  1083. value = fields->f_op_bit1;
  1084. break;
  1085. case XC16X_OPERAND_BIT2 :
  1086. value = fields->f_op_bit2;
  1087. break;
  1088. case XC16X_OPERAND_BIT4 :
  1089. value = fields->f_op_bit4;
  1090. break;
  1091. case XC16X_OPERAND_BIT8 :
  1092. value = fields->f_op_bit8;
  1093. break;
  1094. case XC16X_OPERAND_BITONE :
  1095. value = fields->f_op_onebit;
  1096. break;
  1097. case XC16X_OPERAND_CADDR :
  1098. value = fields->f_offset16;
  1099. break;
  1100. case XC16X_OPERAND_COND :
  1101. value = fields->f_condcode;
  1102. break;
  1103. case XC16X_OPERAND_DATA8 :
  1104. value = fields->f_data8;
  1105. break;
  1106. case XC16X_OPERAND_DATAHI8 :
  1107. value = fields->f_datahi8;
  1108. break;
  1109. case XC16X_OPERAND_DOT :
  1110. value = 0;
  1111. break;
  1112. case XC16X_OPERAND_DR :
  1113. value = fields->f_r1;
  1114. break;
  1115. case XC16X_OPERAND_DRB :
  1116. value = fields->f_r1;
  1117. break;
  1118. case XC16X_OPERAND_DRI :
  1119. value = fields->f_r4;
  1120. break;
  1121. case XC16X_OPERAND_EXTCOND :
  1122. value = fields->f_extccode;
  1123. break;
  1124. case XC16X_OPERAND_GENREG :
  1125. value = fields->f_regb8;
  1126. break;
  1127. case XC16X_OPERAND_HASH :
  1128. value = 0;
  1129. break;
  1130. case XC16X_OPERAND_ICOND :
  1131. value = fields->f_icondcode;
  1132. break;
  1133. case XC16X_OPERAND_LBIT2 :
  1134. value = fields->f_op_lbit2;
  1135. break;
  1136. case XC16X_OPERAND_LBIT4 :
  1137. value = fields->f_op_lbit4;
  1138. break;
  1139. case XC16X_OPERAND_MASK8 :
  1140. value = fields->f_mask8;
  1141. break;
  1142. case XC16X_OPERAND_MASKLO8 :
  1143. value = fields->f_datahi8;
  1144. break;
  1145. case XC16X_OPERAND_MEMGR8 :
  1146. value = fields->f_memgr8;
  1147. break;
  1148. case XC16X_OPERAND_MEMORY :
  1149. value = fields->f_memory;
  1150. break;
  1151. case XC16X_OPERAND_PAG :
  1152. value = 0;
  1153. break;
  1154. case XC16X_OPERAND_PAGENUM :
  1155. value = fields->f_pagenum;
  1156. break;
  1157. case XC16X_OPERAND_POF :
  1158. value = 0;
  1159. break;
  1160. case XC16X_OPERAND_QBIT :
  1161. value = fields->f_qbit;
  1162. break;
  1163. case XC16X_OPERAND_QHIBIT :
  1164. value = fields->f_qhibit;
  1165. break;
  1166. case XC16X_OPERAND_QLOBIT :
  1167. value = fields->f_qlobit;
  1168. break;
  1169. case XC16X_OPERAND_REG8 :
  1170. value = fields->f_reg8;
  1171. break;
  1172. case XC16X_OPERAND_REGB8 :
  1173. value = fields->f_regb8;
  1174. break;
  1175. case XC16X_OPERAND_REGBMEM8 :
  1176. value = fields->f_regmem8;
  1177. break;
  1178. case XC16X_OPERAND_REGHI8 :
  1179. value = fields->f_reghi8;
  1180. break;
  1181. case XC16X_OPERAND_REGMEM8 :
  1182. value = fields->f_regmem8;
  1183. break;
  1184. case XC16X_OPERAND_REGOFF8 :
  1185. value = fields->f_regoff8;
  1186. break;
  1187. case XC16X_OPERAND_REL :
  1188. value = fields->f_rel8;
  1189. break;
  1190. case XC16X_OPERAND_RELHI :
  1191. value = fields->f_relhi8;
  1192. break;
  1193. case XC16X_OPERAND_SEG :
  1194. value = fields->f_seg8;
  1195. break;
  1196. case XC16X_OPERAND_SEGHI8 :
  1197. value = fields->f_segnum8;
  1198. break;
  1199. case XC16X_OPERAND_SEGM :
  1200. value = 0;
  1201. break;
  1202. case XC16X_OPERAND_SOF :
  1203. value = 0;
  1204. break;
  1205. case XC16X_OPERAND_SR :
  1206. value = fields->f_r2;
  1207. break;
  1208. case XC16X_OPERAND_SR2 :
  1209. value = fields->f_r0;
  1210. break;
  1211. case XC16X_OPERAND_SRB :
  1212. value = fields->f_r2;
  1213. break;
  1214. case XC16X_OPERAND_SRC1 :
  1215. value = fields->f_r1;
  1216. break;
  1217. case XC16X_OPERAND_SRC2 :
  1218. value = fields->f_r2;
  1219. break;
  1220. case XC16X_OPERAND_SRDIV :
  1221. value = fields->f_reg8;
  1222. break;
  1223. case XC16X_OPERAND_U4 :
  1224. value = fields->f_uimm4;
  1225. break;
  1226. case XC16X_OPERAND_UIMM16 :
  1227. value = fields->f_uimm16;
  1228. break;
  1229. case XC16X_OPERAND_UIMM2 :
  1230. value = fields->f_uimm2;
  1231. break;
  1232. case XC16X_OPERAND_UIMM3 :
  1233. value = fields->f_uimm3;
  1234. break;
  1235. case XC16X_OPERAND_UIMM4 :
  1236. value = fields->f_uimm4;
  1237. break;
  1238. case XC16X_OPERAND_UIMM7 :
  1239. value = fields->f_uimm7;
  1240. break;
  1241. case XC16X_OPERAND_UIMM8 :
  1242. value = fields->f_uimm8;
  1243. break;
  1244. case XC16X_OPERAND_UPAG16 :
  1245. value = fields->f_uimm16;
  1246. break;
  1247. case XC16X_OPERAND_UPOF16 :
  1248. value = fields->f_memory;
  1249. break;
  1250. case XC16X_OPERAND_USEG16 :
  1251. value = fields->f_offset16;
  1252. break;
  1253. case XC16X_OPERAND_USEG8 :
  1254. value = fields->f_seg8;
  1255. break;
  1256. case XC16X_OPERAND_USOF16 :
  1257. value = fields->f_offset16;
  1258. break;
  1259. default :
  1260. /* xgettext:c-format */
  1261. fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"),
  1262. opindex);
  1263. abort ();
  1264. }
  1265. return value;
  1266. }
  1267. void xc16x_cgen_set_int_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
  1268. void xc16x_cgen_set_vma_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
  1269. /* Stuffing values in cgen_fields is handled by a collection of functions.
  1270. They are distinguished by the type of the VALUE argument they accept.
  1271. TODO: floating point, inlining support, remove cases where argument type
  1272. not appropriate. */
  1273. void
  1274. xc16x_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  1275. int opindex,
  1276. CGEN_FIELDS * fields,
  1277. int value)
  1278. {
  1279. switch (opindex)
  1280. {
  1281. case XC16X_OPERAND_REGNAM :
  1282. fields->f_reg8 = value;
  1283. break;
  1284. case XC16X_OPERAND_BIT01 :
  1285. fields->f_op_1bit = value;
  1286. break;
  1287. case XC16X_OPERAND_BIT1 :
  1288. fields->f_op_bit1 = value;
  1289. break;
  1290. case XC16X_OPERAND_BIT2 :
  1291. fields->f_op_bit2 = value;
  1292. break;
  1293. case XC16X_OPERAND_BIT4 :
  1294. fields->f_op_bit4 = value;
  1295. break;
  1296. case XC16X_OPERAND_BIT8 :
  1297. fields->f_op_bit8 = value;
  1298. break;
  1299. case XC16X_OPERAND_BITONE :
  1300. fields->f_op_onebit = value;
  1301. break;
  1302. case XC16X_OPERAND_CADDR :
  1303. fields->f_offset16 = value;
  1304. break;
  1305. case XC16X_OPERAND_COND :
  1306. fields->f_condcode = value;
  1307. break;
  1308. case XC16X_OPERAND_DATA8 :
  1309. fields->f_data8 = value;
  1310. break;
  1311. case XC16X_OPERAND_DATAHI8 :
  1312. fields->f_datahi8 = value;
  1313. break;
  1314. case XC16X_OPERAND_DOT :
  1315. break;
  1316. case XC16X_OPERAND_DR :
  1317. fields->f_r1 = value;
  1318. break;
  1319. case XC16X_OPERAND_DRB :
  1320. fields->f_r1 = value;
  1321. break;
  1322. case XC16X_OPERAND_DRI :
  1323. fields->f_r4 = value;
  1324. break;
  1325. case XC16X_OPERAND_EXTCOND :
  1326. fields->f_extccode = value;
  1327. break;
  1328. case XC16X_OPERAND_GENREG :
  1329. fields->f_regb8 = value;
  1330. break;
  1331. case XC16X_OPERAND_HASH :
  1332. break;
  1333. case XC16X_OPERAND_ICOND :
  1334. fields->f_icondcode = value;
  1335. break;
  1336. case XC16X_OPERAND_LBIT2 :
  1337. fields->f_op_lbit2 = value;
  1338. break;
  1339. case XC16X_OPERAND_LBIT4 :
  1340. fields->f_op_lbit4 = value;
  1341. break;
  1342. case XC16X_OPERAND_MASK8 :
  1343. fields->f_mask8 = value;
  1344. break;
  1345. case XC16X_OPERAND_MASKLO8 :
  1346. fields->f_datahi8 = value;
  1347. break;
  1348. case XC16X_OPERAND_MEMGR8 :
  1349. fields->f_memgr8 = value;
  1350. break;
  1351. case XC16X_OPERAND_MEMORY :
  1352. fields->f_memory = value;
  1353. break;
  1354. case XC16X_OPERAND_PAG :
  1355. break;
  1356. case XC16X_OPERAND_PAGENUM :
  1357. fields->f_pagenum = value;
  1358. break;
  1359. case XC16X_OPERAND_POF :
  1360. break;
  1361. case XC16X_OPERAND_QBIT :
  1362. fields->f_qbit = value;
  1363. break;
  1364. case XC16X_OPERAND_QHIBIT :
  1365. fields->f_qhibit = value;
  1366. break;
  1367. case XC16X_OPERAND_QLOBIT :
  1368. fields->f_qlobit = value;
  1369. break;
  1370. case XC16X_OPERAND_REG8 :
  1371. fields->f_reg8 = value;
  1372. break;
  1373. case XC16X_OPERAND_REGB8 :
  1374. fields->f_regb8 = value;
  1375. break;
  1376. case XC16X_OPERAND_REGBMEM8 :
  1377. fields->f_regmem8 = value;
  1378. break;
  1379. case XC16X_OPERAND_REGHI8 :
  1380. fields->f_reghi8 = value;
  1381. break;
  1382. case XC16X_OPERAND_REGMEM8 :
  1383. fields->f_regmem8 = value;
  1384. break;
  1385. case XC16X_OPERAND_REGOFF8 :
  1386. fields->f_regoff8 = value;
  1387. break;
  1388. case XC16X_OPERAND_REL :
  1389. fields->f_rel8 = value;
  1390. break;
  1391. case XC16X_OPERAND_RELHI :
  1392. fields->f_relhi8 = value;
  1393. break;
  1394. case XC16X_OPERAND_SEG :
  1395. fields->f_seg8 = value;
  1396. break;
  1397. case XC16X_OPERAND_SEGHI8 :
  1398. fields->f_segnum8 = value;
  1399. break;
  1400. case XC16X_OPERAND_SEGM :
  1401. break;
  1402. case XC16X_OPERAND_SOF :
  1403. break;
  1404. case XC16X_OPERAND_SR :
  1405. fields->f_r2 = value;
  1406. break;
  1407. case XC16X_OPERAND_SR2 :
  1408. fields->f_r0 = value;
  1409. break;
  1410. case XC16X_OPERAND_SRB :
  1411. fields->f_r2 = value;
  1412. break;
  1413. case XC16X_OPERAND_SRC1 :
  1414. fields->f_r1 = value;
  1415. break;
  1416. case XC16X_OPERAND_SRC2 :
  1417. fields->f_r2 = value;
  1418. break;
  1419. case XC16X_OPERAND_SRDIV :
  1420. fields->f_reg8 = value;
  1421. break;
  1422. case XC16X_OPERAND_U4 :
  1423. fields->f_uimm4 = value;
  1424. break;
  1425. case XC16X_OPERAND_UIMM16 :
  1426. fields->f_uimm16 = value;
  1427. break;
  1428. case XC16X_OPERAND_UIMM2 :
  1429. fields->f_uimm2 = value;
  1430. break;
  1431. case XC16X_OPERAND_UIMM3 :
  1432. fields->f_uimm3 = value;
  1433. break;
  1434. case XC16X_OPERAND_UIMM4 :
  1435. fields->f_uimm4 = value;
  1436. break;
  1437. case XC16X_OPERAND_UIMM7 :
  1438. fields->f_uimm7 = value;
  1439. break;
  1440. case XC16X_OPERAND_UIMM8 :
  1441. fields->f_uimm8 = value;
  1442. break;
  1443. case XC16X_OPERAND_UPAG16 :
  1444. fields->f_uimm16 = value;
  1445. break;
  1446. case XC16X_OPERAND_UPOF16 :
  1447. fields->f_memory = value;
  1448. break;
  1449. case XC16X_OPERAND_USEG16 :
  1450. fields->f_offset16 = value;
  1451. break;
  1452. case XC16X_OPERAND_USEG8 :
  1453. fields->f_seg8 = value;
  1454. break;
  1455. case XC16X_OPERAND_USOF16 :
  1456. fields->f_offset16 = value;
  1457. break;
  1458. default :
  1459. /* xgettext:c-format */
  1460. fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"),
  1461. opindex);
  1462. abort ();
  1463. }
  1464. }
  1465. void
  1466. xc16x_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  1467. int opindex,
  1468. CGEN_FIELDS * fields,
  1469. bfd_vma value)
  1470. {
  1471. switch (opindex)
  1472. {
  1473. case XC16X_OPERAND_REGNAM :
  1474. fields->f_reg8 = value;
  1475. break;
  1476. case XC16X_OPERAND_BIT01 :
  1477. fields->f_op_1bit = value;
  1478. break;
  1479. case XC16X_OPERAND_BIT1 :
  1480. fields->f_op_bit1 = value;
  1481. break;
  1482. case XC16X_OPERAND_BIT2 :
  1483. fields->f_op_bit2 = value;
  1484. break;
  1485. case XC16X_OPERAND_BIT4 :
  1486. fields->f_op_bit4 = value;
  1487. break;
  1488. case XC16X_OPERAND_BIT8 :
  1489. fields->f_op_bit8 = value;
  1490. break;
  1491. case XC16X_OPERAND_BITONE :
  1492. fields->f_op_onebit = value;
  1493. break;
  1494. case XC16X_OPERAND_CADDR :
  1495. fields->f_offset16 = value;
  1496. break;
  1497. case XC16X_OPERAND_COND :
  1498. fields->f_condcode = value;
  1499. break;
  1500. case XC16X_OPERAND_DATA8 :
  1501. fields->f_data8 = value;
  1502. break;
  1503. case XC16X_OPERAND_DATAHI8 :
  1504. fields->f_datahi8 = value;
  1505. break;
  1506. case XC16X_OPERAND_DOT :
  1507. break;
  1508. case XC16X_OPERAND_DR :
  1509. fields->f_r1 = value;
  1510. break;
  1511. case XC16X_OPERAND_DRB :
  1512. fields->f_r1 = value;
  1513. break;
  1514. case XC16X_OPERAND_DRI :
  1515. fields->f_r4 = value;
  1516. break;
  1517. case XC16X_OPERAND_EXTCOND :
  1518. fields->f_extccode = value;
  1519. break;
  1520. case XC16X_OPERAND_GENREG :
  1521. fields->f_regb8 = value;
  1522. break;
  1523. case XC16X_OPERAND_HASH :
  1524. break;
  1525. case XC16X_OPERAND_ICOND :
  1526. fields->f_icondcode = value;
  1527. break;
  1528. case XC16X_OPERAND_LBIT2 :
  1529. fields->f_op_lbit2 = value;
  1530. break;
  1531. case XC16X_OPERAND_LBIT4 :
  1532. fields->f_op_lbit4 = value;
  1533. break;
  1534. case XC16X_OPERAND_MASK8 :
  1535. fields->f_mask8 = value;
  1536. break;
  1537. case XC16X_OPERAND_MASKLO8 :
  1538. fields->f_datahi8 = value;
  1539. break;
  1540. case XC16X_OPERAND_MEMGR8 :
  1541. fields->f_memgr8 = value;
  1542. break;
  1543. case XC16X_OPERAND_MEMORY :
  1544. fields->f_memory = value;
  1545. break;
  1546. case XC16X_OPERAND_PAG :
  1547. break;
  1548. case XC16X_OPERAND_PAGENUM :
  1549. fields->f_pagenum = value;
  1550. break;
  1551. case XC16X_OPERAND_POF :
  1552. break;
  1553. case XC16X_OPERAND_QBIT :
  1554. fields->f_qbit = value;
  1555. break;
  1556. case XC16X_OPERAND_QHIBIT :
  1557. fields->f_qhibit = value;
  1558. break;
  1559. case XC16X_OPERAND_QLOBIT :
  1560. fields->f_qlobit = value;
  1561. break;
  1562. case XC16X_OPERAND_REG8 :
  1563. fields->f_reg8 = value;
  1564. break;
  1565. case XC16X_OPERAND_REGB8 :
  1566. fields->f_regb8 = value;
  1567. break;
  1568. case XC16X_OPERAND_REGBMEM8 :
  1569. fields->f_regmem8 = value;
  1570. break;
  1571. case XC16X_OPERAND_REGHI8 :
  1572. fields->f_reghi8 = value;
  1573. break;
  1574. case XC16X_OPERAND_REGMEM8 :
  1575. fields->f_regmem8 = value;
  1576. break;
  1577. case XC16X_OPERAND_REGOFF8 :
  1578. fields->f_regoff8 = value;
  1579. break;
  1580. case XC16X_OPERAND_REL :
  1581. fields->f_rel8 = value;
  1582. break;
  1583. case XC16X_OPERAND_RELHI :
  1584. fields->f_relhi8 = value;
  1585. break;
  1586. case XC16X_OPERAND_SEG :
  1587. fields->f_seg8 = value;
  1588. break;
  1589. case XC16X_OPERAND_SEGHI8 :
  1590. fields->f_segnum8 = value;
  1591. break;
  1592. case XC16X_OPERAND_SEGM :
  1593. break;
  1594. case XC16X_OPERAND_SOF :
  1595. break;
  1596. case XC16X_OPERAND_SR :
  1597. fields->f_r2 = value;
  1598. break;
  1599. case XC16X_OPERAND_SR2 :
  1600. fields->f_r0 = value;
  1601. break;
  1602. case XC16X_OPERAND_SRB :
  1603. fields->f_r2 = value;
  1604. break;
  1605. case XC16X_OPERAND_SRC1 :
  1606. fields->f_r1 = value;
  1607. break;
  1608. case XC16X_OPERAND_SRC2 :
  1609. fields->f_r2 = value;
  1610. break;
  1611. case XC16X_OPERAND_SRDIV :
  1612. fields->f_reg8 = value;
  1613. break;
  1614. case XC16X_OPERAND_U4 :
  1615. fields->f_uimm4 = value;
  1616. break;
  1617. case XC16X_OPERAND_UIMM16 :
  1618. fields->f_uimm16 = value;
  1619. break;
  1620. case XC16X_OPERAND_UIMM2 :
  1621. fields->f_uimm2 = value;
  1622. break;
  1623. case XC16X_OPERAND_UIMM3 :
  1624. fields->f_uimm3 = value;
  1625. break;
  1626. case XC16X_OPERAND_UIMM4 :
  1627. fields->f_uimm4 = value;
  1628. break;
  1629. case XC16X_OPERAND_UIMM7 :
  1630. fields->f_uimm7 = value;
  1631. break;
  1632. case XC16X_OPERAND_UIMM8 :
  1633. fields->f_uimm8 = value;
  1634. break;
  1635. case XC16X_OPERAND_UPAG16 :
  1636. fields->f_uimm16 = value;
  1637. break;
  1638. case XC16X_OPERAND_UPOF16 :
  1639. fields->f_memory = value;
  1640. break;
  1641. case XC16X_OPERAND_USEG16 :
  1642. fields->f_offset16 = value;
  1643. break;
  1644. case XC16X_OPERAND_USEG8 :
  1645. fields->f_seg8 = value;
  1646. break;
  1647. case XC16X_OPERAND_USOF16 :
  1648. fields->f_offset16 = value;
  1649. break;
  1650. default :
  1651. /* xgettext:c-format */
  1652. fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"),
  1653. opindex);
  1654. abort ();
  1655. }
  1656. }
  1657. /* Function to call before using the instruction builder tables. */
  1658. void
  1659. xc16x_cgen_init_ibld_table (CGEN_CPU_DESC cd)
  1660. {
  1661. cd->insert_handlers = & xc16x_cgen_insert_handlers[0];
  1662. cd->extract_handlers = & xc16x_cgen_extract_handlers[0];
  1663. cd->insert_operand = xc16x_cgen_insert_operand;
  1664. cd->extract_operand = xc16x_cgen_extract_operand;
  1665. cd->get_int_operand = xc16x_cgen_get_int_operand;
  1666. cd->set_int_operand = xc16x_cgen_set_int_operand;
  1667. cd->get_vma_operand = xc16x_cgen_get_vma_operand;
  1668. cd->set_vma_operand = xc16x_cgen_set_vma_operand;
  1669. }