frv-asm.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  1. /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
  2. /* Assembler interface for targets using CGEN. -*- C -*-
  3. CGEN: Cpu tools GENerator
  4. THIS FILE IS MACHINE GENERATED WITH CGEN.
  5. - the resultant file is machine generated, cgen-asm.in isn't
  6. Copyright (C) 1996-2022 Free Software Foundation, Inc.
  7. This file is part of libopcodes.
  8. This library is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3, or (at your option)
  11. any later version.
  12. It is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  15. License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software Foundation, Inc.,
  18. 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  19. /* ??? Eventually more and more of this stuff can go to cpu-independent files.
  20. Keep that in mind. */
  21. #include "sysdep.h"
  22. #include <stdio.h>
  23. #include "ansidecl.h"
  24. #include "bfd.h"
  25. #include "symcat.h"
  26. #include "frv-desc.h"
  27. #include "frv-opc.h"
  28. #include "opintl.h"
  29. #include "xregex.h"
  30. #include "libiberty.h"
  31. #include "safe-ctype.h"
  32. #undef min
  33. #define min(a,b) ((a) < (b) ? (a) : (b))
  34. #undef max
  35. #define max(a,b) ((a) > (b) ? (a) : (b))
  36. static const char * parse_insn_normal
  37. (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
  38. /* -- assembler routines inserted here. */
  39. /* -- asm.c */
  40. inline static const char *
  41. parse_symbolic_address (CGEN_CPU_DESC cd,
  42. const char **strp,
  43. int opindex,
  44. int opinfo,
  45. enum cgen_parse_operand_result *resultp,
  46. bfd_vma *valuep)
  47. {
  48. enum cgen_parse_operand_result result_type;
  49. const char *errmsg = (* cd->parse_operand_fn)
  50. (cd, CGEN_PARSE_OPERAND_SYMBOLIC, strp, opindex, opinfo,
  51. &result_type, valuep);
  52. if (errmsg == NULL
  53. && result_type != CGEN_PARSE_OPERAND_RESULT_QUEUED)
  54. return "symbolic expression required";
  55. if (resultp)
  56. *resultp = result_type;
  57. return errmsg;
  58. }
  59. static const char *
  60. parse_ldd_annotation (CGEN_CPU_DESC cd,
  61. const char **strp,
  62. int opindex,
  63. unsigned long *valuep)
  64. {
  65. const char *errmsg;
  66. enum cgen_parse_operand_result result_type;
  67. bfd_vma value;
  68. if (**strp == '#' || **strp == '%')
  69. {
  70. if (strncasecmp (*strp + 1, "tlsdesc(", 8) == 0)
  71. {
  72. *strp += 9;
  73. errmsg = parse_symbolic_address (cd, strp, opindex,
  74. BFD_RELOC_FRV_TLSDESC_RELAX,
  75. &result_type, &value);
  76. if (**strp != ')')
  77. return "missing ')'";
  78. if (valuep)
  79. *valuep = value;
  80. ++*strp;
  81. if (errmsg)
  82. return errmsg;
  83. }
  84. }
  85. while (**strp == ' ' || **strp == '\t')
  86. ++*strp;
  87. if (**strp != '@')
  88. return "missing `@'";
  89. ++*strp;
  90. return NULL;
  91. }
  92. static const char *
  93. parse_call_annotation (CGEN_CPU_DESC cd,
  94. const char **strp,
  95. int opindex,
  96. unsigned long *valuep)
  97. {
  98. const char *errmsg;
  99. enum cgen_parse_operand_result result_type;
  100. bfd_vma value;
  101. if (**strp == '#' || **strp == '%')
  102. {
  103. if (strncasecmp (*strp + 1, "gettlsoff(", 10) == 0)
  104. {
  105. *strp += 11;
  106. errmsg = parse_symbolic_address (cd, strp, opindex,
  107. BFD_RELOC_FRV_GETTLSOFF_RELAX,
  108. &result_type, &value);
  109. if (**strp != ')')
  110. return "missing ')'";
  111. if (valuep)
  112. *valuep = value;
  113. ++*strp;
  114. if (errmsg)
  115. return errmsg;
  116. }
  117. }
  118. while (**strp == ' ' || **strp == '\t')
  119. ++*strp;
  120. if (**strp != '@')
  121. return "missing `@'";
  122. ++*strp;
  123. return NULL;
  124. }
  125. static const char *
  126. parse_ld_annotation (CGEN_CPU_DESC cd,
  127. const char **strp,
  128. int opindex,
  129. unsigned long *valuep)
  130. {
  131. const char *errmsg;
  132. enum cgen_parse_operand_result result_type;
  133. bfd_vma value;
  134. if (**strp == '#' || **strp == '%')
  135. {
  136. if (strncasecmp (*strp + 1, "tlsoff(", 7) == 0)
  137. {
  138. *strp += 8;
  139. errmsg = parse_symbolic_address (cd, strp, opindex,
  140. BFD_RELOC_FRV_TLSOFF_RELAX,
  141. &result_type, &value);
  142. if (**strp != ')')
  143. return "missing ')'";
  144. if (valuep)
  145. *valuep = value;
  146. ++*strp;
  147. if (errmsg)
  148. return errmsg;
  149. }
  150. }
  151. while (**strp == ' ' || **strp == '\t')
  152. ++*strp;
  153. if (**strp != '@')
  154. return "missing `@'";
  155. ++*strp;
  156. return NULL;
  157. }
  158. static const char *
  159. parse_ulo16 (CGEN_CPU_DESC cd,
  160. const char **strp,
  161. int opindex,
  162. unsigned long *valuep)
  163. {
  164. const char *errmsg;
  165. enum cgen_parse_operand_result result_type;
  166. bfd_vma value;
  167. if (**strp == '#' || **strp == '%')
  168. {
  169. if (strncasecmp (*strp + 1, "lo(", 3) == 0)
  170. {
  171. *strp += 4;
  172. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_FRV_LO16,
  173. & result_type, & value);
  174. if (**strp != ')')
  175. return "missing `)'";
  176. ++*strp;
  177. if (errmsg == NULL
  178. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  179. value &= 0xffff;
  180. *valuep = value;
  181. return errmsg;
  182. }
  183. if (strncasecmp (*strp + 1, "gprello(", 8) == 0)
  184. {
  185. *strp += 9;
  186. errmsg = parse_symbolic_address (cd, strp, opindex,
  187. BFD_RELOC_FRV_GPRELLO,
  188. & result_type, & value);
  189. if (**strp != ')')
  190. return "missing ')'";
  191. ++*strp;
  192. *valuep = value;
  193. return errmsg;
  194. }
  195. else if (strncasecmp (*strp + 1, "gotlo(", 6) == 0)
  196. {
  197. *strp += 7;
  198. errmsg = parse_symbolic_address (cd, strp, opindex,
  199. BFD_RELOC_FRV_GOTLO,
  200. & result_type, & value);
  201. if (**strp != ')')
  202. return "missing ')'";
  203. ++*strp;
  204. *valuep = value;
  205. return errmsg;
  206. }
  207. else if (strncasecmp (*strp + 1, "gotfuncdesclo(", 14) == 0)
  208. {
  209. *strp += 15;
  210. errmsg = parse_symbolic_address (cd, strp, opindex,
  211. BFD_RELOC_FRV_FUNCDESC_GOTLO,
  212. & result_type, & value);
  213. if (**strp != ')')
  214. return "missing ')'";
  215. ++*strp;
  216. *valuep = value;
  217. return errmsg;
  218. }
  219. else if (strncasecmp (*strp + 1, "gotofflo(", 9) == 0)
  220. {
  221. *strp += 10;
  222. errmsg = parse_symbolic_address (cd, strp, opindex,
  223. BFD_RELOC_FRV_GOTOFFLO,
  224. & result_type, & value);
  225. if (**strp != ')')
  226. return "missing ')'";
  227. ++*strp;
  228. *valuep = value;
  229. return errmsg;
  230. }
  231. else if (strncasecmp (*strp + 1, "gotofffuncdesclo(", 17) == 0)
  232. {
  233. *strp += 18;
  234. errmsg = parse_symbolic_address (cd, strp, opindex,
  235. BFD_RELOC_FRV_FUNCDESC_GOTOFFLO,
  236. & result_type, & value);
  237. if (**strp != ')')
  238. return "missing ')'";
  239. ++*strp;
  240. *valuep = value;
  241. return errmsg;
  242. }
  243. else if (strncasecmp (*strp + 1, "gottlsdesclo(", 13) == 0)
  244. {
  245. *strp += 14;
  246. errmsg = parse_symbolic_address (cd, strp, opindex,
  247. BFD_RELOC_FRV_GOTTLSDESCLO,
  248. & result_type, & value);
  249. if (**strp != ')')
  250. return "missing ')'";
  251. ++*strp;
  252. *valuep = value;
  253. return errmsg;
  254. }
  255. else if (strncasecmp (*strp + 1, "tlsmofflo(", 10) == 0)
  256. {
  257. *strp += 11;
  258. errmsg = parse_symbolic_address (cd, strp, opindex,
  259. BFD_RELOC_FRV_TLSMOFFLO,
  260. & result_type, & value);
  261. if (**strp != ')')
  262. return "missing ')'";
  263. ++*strp;
  264. *valuep = value;
  265. return errmsg;
  266. }
  267. else if (strncasecmp (*strp + 1, "gottlsofflo(", 12) == 0)
  268. {
  269. *strp += 13;
  270. errmsg = parse_symbolic_address (cd, strp, opindex,
  271. BFD_RELOC_FRV_GOTTLSOFFLO,
  272. & result_type, & value);
  273. if (**strp != ')')
  274. return "missing ')'";
  275. ++*strp;
  276. *valuep = value;
  277. return errmsg;
  278. }
  279. }
  280. return cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
  281. }
  282. static const char *
  283. parse_uslo16 (CGEN_CPU_DESC cd,
  284. const char **strp,
  285. int opindex,
  286. signed long *valuep)
  287. {
  288. const char *errmsg;
  289. enum cgen_parse_operand_result result_type;
  290. bfd_vma value;
  291. if (**strp == '#' || **strp == '%')
  292. {
  293. if (strncasecmp (*strp + 1, "lo(", 3) == 0)
  294. {
  295. *strp += 4;
  296. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_FRV_LO16,
  297. & result_type, & value);
  298. if (**strp != ')')
  299. return "missing `)'";
  300. ++*strp;
  301. if (errmsg == NULL
  302. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  303. value &= 0xffff;
  304. *valuep = value;
  305. return errmsg;
  306. }
  307. else if (strncasecmp (*strp + 1, "gprello(", 8) == 0)
  308. {
  309. *strp += 9;
  310. errmsg = parse_symbolic_address (cd, strp, opindex,
  311. BFD_RELOC_FRV_GPRELLO,
  312. & result_type, & value);
  313. if (**strp != ')')
  314. return "missing ')'";
  315. ++*strp;
  316. *valuep = value;
  317. return errmsg;
  318. }
  319. else if (strncasecmp (*strp + 1, "gotlo(", 6) == 0)
  320. {
  321. *strp += 7;
  322. errmsg = parse_symbolic_address (cd, strp, opindex,
  323. BFD_RELOC_FRV_GOTLO,
  324. & result_type, & value);
  325. if (**strp != ')')
  326. return "missing ')'";
  327. ++*strp;
  328. *valuep = value;
  329. return errmsg;
  330. }
  331. else if (strncasecmp (*strp + 1, "gotfuncdesclo(", 14) == 0)
  332. {
  333. *strp += 15;
  334. errmsg = parse_symbolic_address (cd, strp, opindex,
  335. BFD_RELOC_FRV_FUNCDESC_GOTLO,
  336. & result_type, & value);
  337. if (**strp != ')')
  338. return "missing ')'";
  339. ++*strp;
  340. *valuep = value;
  341. return errmsg;
  342. }
  343. else if (strncasecmp (*strp + 1, "gotofflo(", 9) == 0)
  344. {
  345. *strp += 10;
  346. errmsg = parse_symbolic_address (cd, strp, opindex,
  347. BFD_RELOC_FRV_GOTOFFLO,
  348. & result_type, & value);
  349. if (**strp != ')')
  350. return "missing ')'";
  351. ++*strp;
  352. *valuep = value;
  353. return errmsg;
  354. }
  355. else if (strncasecmp (*strp + 1, "gotofffuncdesclo(", 17) == 0)
  356. {
  357. *strp += 18;
  358. errmsg = parse_symbolic_address (cd, strp, opindex,
  359. BFD_RELOC_FRV_FUNCDESC_GOTOFFLO,
  360. & result_type, & value);
  361. if (**strp != ')')
  362. return "missing ')'";
  363. ++*strp;
  364. *valuep = value;
  365. return errmsg;
  366. }
  367. else if (strncasecmp (*strp + 1, "gottlsdesclo(", 13) == 0)
  368. {
  369. *strp += 14;
  370. errmsg = parse_symbolic_address (cd, strp, opindex,
  371. BFD_RELOC_FRV_GOTTLSDESCLO,
  372. & result_type, & value);
  373. if (**strp != ')')
  374. return "missing ')'";
  375. ++*strp;
  376. *valuep = value;
  377. return errmsg;
  378. }
  379. else if (strncasecmp (*strp + 1, "tlsmofflo(", 10) == 0)
  380. {
  381. *strp += 11;
  382. errmsg = parse_symbolic_address (cd, strp, opindex,
  383. BFD_RELOC_FRV_TLSMOFFLO,
  384. & result_type, & value);
  385. if (**strp != ')')
  386. return "missing ')'";
  387. ++*strp;
  388. *valuep = value;
  389. return errmsg;
  390. }
  391. else if (strncasecmp (*strp + 1, "gottlsofflo(", 12) == 0)
  392. {
  393. *strp += 13;
  394. errmsg = parse_symbolic_address (cd, strp, opindex,
  395. BFD_RELOC_FRV_GOTTLSOFFLO,
  396. & result_type, & value);
  397. if (**strp != ')')
  398. return "missing ')'";
  399. ++*strp;
  400. *valuep = value;
  401. return errmsg;
  402. }
  403. }
  404. return cgen_parse_signed_integer (cd, strp, opindex, valuep);
  405. }
  406. static const char *
  407. parse_uhi16 (CGEN_CPU_DESC cd,
  408. const char **strp,
  409. int opindex,
  410. unsigned long *valuep)
  411. {
  412. const char *errmsg;
  413. enum cgen_parse_operand_result result_type;
  414. bfd_vma value;
  415. if (**strp == '#' || **strp == '%')
  416. {
  417. if (strncasecmp (*strp + 1, "hi(", 3) == 0)
  418. {
  419. *strp += 4;
  420. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_FRV_HI16,
  421. & result_type, & value);
  422. if (**strp != ')')
  423. return "missing `)'";
  424. ++*strp;
  425. if (errmsg == NULL
  426. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  427. {
  428. /* If value is wider than 32 bits then be
  429. careful about how we extract bits 16-31. */
  430. if (sizeof (value) > 4)
  431. value &= (((bfd_vma)1 << 16) << 16) - 1;
  432. value >>= 16;
  433. }
  434. *valuep = value;
  435. return errmsg;
  436. }
  437. else if (strncasecmp (*strp + 1, "gprelhi(", 8) == 0)
  438. {
  439. *strp += 9;
  440. errmsg = parse_symbolic_address (cd, strp, opindex,
  441. BFD_RELOC_FRV_GPRELHI,
  442. & result_type, & value);
  443. if (**strp != ')')
  444. return "missing ')'";
  445. ++*strp;
  446. *valuep = value;
  447. return errmsg;
  448. }
  449. else if (strncasecmp (*strp + 1, "gothi(", 6) == 0)
  450. {
  451. *strp += 7;
  452. errmsg = parse_symbolic_address (cd, strp, opindex,
  453. BFD_RELOC_FRV_GOTHI,
  454. & result_type, & value);
  455. if (**strp != ')')
  456. return "missing ')'";
  457. ++*strp;
  458. *valuep = value;
  459. return errmsg;
  460. }
  461. else if (strncasecmp (*strp + 1, "gotfuncdeschi(", 14) == 0)
  462. {
  463. *strp += 15;
  464. errmsg = parse_symbolic_address (cd, strp, opindex,
  465. BFD_RELOC_FRV_FUNCDESC_GOTHI,
  466. & result_type, & value);
  467. if (**strp != ')')
  468. return "missing ')'";
  469. ++*strp;
  470. *valuep = value;
  471. return errmsg;
  472. }
  473. else if (strncasecmp (*strp + 1, "gotoffhi(", 9) == 0)
  474. {
  475. *strp += 10;
  476. errmsg = parse_symbolic_address (cd, strp, opindex,
  477. BFD_RELOC_FRV_GOTOFFHI,
  478. & result_type, & value);
  479. if (**strp != ')')
  480. return "missing ')'";
  481. ++*strp;
  482. *valuep = value;
  483. return errmsg;
  484. }
  485. else if (strncasecmp (*strp + 1, "gotofffuncdeschi(", 17) == 0)
  486. {
  487. *strp += 18;
  488. errmsg = parse_symbolic_address (cd, strp, opindex,
  489. BFD_RELOC_FRV_FUNCDESC_GOTOFFHI,
  490. & result_type, & value);
  491. if (**strp != ')')
  492. return "missing ')'";
  493. ++*strp;
  494. *valuep = value;
  495. return errmsg;
  496. }
  497. else if (strncasecmp (*strp + 1, "gottlsdeschi(", 13) == 0)
  498. {
  499. *strp += 14;
  500. errmsg = parse_symbolic_address (cd, strp, opindex,
  501. BFD_RELOC_FRV_GOTTLSDESCHI,
  502. &result_type, &value);
  503. if (**strp != ')')
  504. return "missing ')'";
  505. ++*strp;
  506. *valuep = value;
  507. return errmsg;
  508. }
  509. else if (strncasecmp (*strp + 1, "tlsmoffhi(", 10) == 0)
  510. {
  511. *strp += 11;
  512. errmsg = parse_symbolic_address (cd, strp, opindex,
  513. BFD_RELOC_FRV_TLSMOFFHI,
  514. & result_type, & value);
  515. if (**strp != ')')
  516. return "missing ')'";
  517. ++*strp;
  518. *valuep = value;
  519. return errmsg;
  520. }
  521. else if (strncasecmp (*strp + 1, "gottlsoffhi(", 12) == 0)
  522. {
  523. *strp += 13;
  524. errmsg = parse_symbolic_address (cd, strp, opindex,
  525. BFD_RELOC_FRV_GOTTLSOFFHI,
  526. & result_type, & value);
  527. if (**strp != ')')
  528. return "missing ')'";
  529. ++*strp;
  530. *valuep = value;
  531. return errmsg;
  532. }
  533. }
  534. return cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
  535. }
  536. static long
  537. parse_register_number (const char **strp)
  538. {
  539. int regno;
  540. if (**strp < '0' || **strp > '9')
  541. return -1; /* error */
  542. regno = **strp - '0';
  543. for (++*strp; **strp >= '0' && **strp <= '9'; ++*strp)
  544. regno = regno * 10 + (**strp - '0');
  545. return regno;
  546. }
  547. static const char *
  548. parse_spr (CGEN_CPU_DESC cd,
  549. const char **strp,
  550. CGEN_KEYWORD * table,
  551. long *valuep)
  552. {
  553. const char *save_strp;
  554. long regno;
  555. /* Check for spr index notation. */
  556. if (strncasecmp (*strp, "spr[", 4) == 0)
  557. {
  558. *strp += 4;
  559. regno = parse_register_number (strp);
  560. if (**strp != ']')
  561. return _("missing `]'");
  562. ++*strp;
  563. if (! spr_valid (regno))
  564. return _("Special purpose register number is out of range");
  565. *valuep = regno;
  566. return NULL;
  567. }
  568. save_strp = *strp;
  569. regno = parse_register_number (strp);
  570. if (regno != -1)
  571. {
  572. if (! spr_valid (regno))
  573. return _("Special purpose register number is out of range");
  574. *valuep = regno;
  575. return NULL;
  576. }
  577. *strp = save_strp;
  578. return cgen_parse_keyword (cd, strp, table, valuep);
  579. }
  580. static const char *
  581. parse_d12 (CGEN_CPU_DESC cd,
  582. const char **strp,
  583. int opindex,
  584. long *valuep)
  585. {
  586. const char *errmsg;
  587. enum cgen_parse_operand_result result_type;
  588. bfd_vma value;
  589. /* Check for small data reference. */
  590. if (**strp == '#' || **strp == '%')
  591. {
  592. if (strncasecmp (*strp + 1, "gprel12(", 8) == 0)
  593. {
  594. *strp += 9;
  595. errmsg = parse_symbolic_address (cd, strp, opindex,
  596. BFD_RELOC_FRV_GPREL12,
  597. & result_type, & value);
  598. if (**strp != ')')
  599. return "missing `)'";
  600. ++*strp;
  601. *valuep = value;
  602. return errmsg;
  603. }
  604. else if (strncasecmp (*strp + 1, "got12(", 6) == 0)
  605. {
  606. *strp += 7;
  607. errmsg = parse_symbolic_address (cd, strp, opindex,
  608. BFD_RELOC_FRV_GOT12,
  609. & result_type, & value);
  610. if (**strp != ')')
  611. return "missing ')'";
  612. ++*strp;
  613. *valuep = value;
  614. return errmsg;
  615. }
  616. else if (strncasecmp (*strp + 1, "gotfuncdesc12(", 14) == 0)
  617. {
  618. *strp += 15;
  619. errmsg = parse_symbolic_address (cd, strp, opindex,
  620. BFD_RELOC_FRV_FUNCDESC_GOT12,
  621. & result_type, & value);
  622. if (**strp != ')')
  623. return "missing ')'";
  624. ++*strp;
  625. *valuep = value;
  626. return errmsg;
  627. }
  628. else if (strncasecmp (*strp + 1, "gotoff12(", 9) == 0)
  629. {
  630. *strp += 10;
  631. errmsg = parse_symbolic_address (cd, strp, opindex,
  632. BFD_RELOC_FRV_GOTOFF12,
  633. & result_type, & value);
  634. if (**strp != ')')
  635. return "missing ')'";
  636. ++*strp;
  637. *valuep = value;
  638. return errmsg;
  639. }
  640. else if (strncasecmp (*strp + 1, "gotofffuncdesc12(", 17) == 0)
  641. {
  642. *strp += 18;
  643. errmsg = parse_symbolic_address (cd, strp, opindex,
  644. BFD_RELOC_FRV_FUNCDESC_GOTOFF12,
  645. & result_type, & value);
  646. if (**strp != ')')
  647. return "missing ')'";
  648. ++*strp;
  649. *valuep = value;
  650. return errmsg;
  651. }
  652. else if (strncasecmp (*strp + 1, "gottlsdesc12(", 13) == 0)
  653. {
  654. *strp += 14;
  655. errmsg = parse_symbolic_address (cd, strp, opindex,
  656. BFD_RELOC_FRV_GOTTLSDESC12,
  657. & result_type, & value);
  658. if (**strp != ')')
  659. return "missing ')'";
  660. ++*strp;
  661. *valuep = value;
  662. return errmsg;
  663. }
  664. else if (strncasecmp (*strp + 1, "tlsmoff12(", 10) == 0)
  665. {
  666. *strp += 11;
  667. errmsg = parse_symbolic_address (cd, strp, opindex,
  668. BFD_RELOC_FRV_TLSMOFF12,
  669. & result_type, & value);
  670. if (**strp != ')')
  671. return "missing ')'";
  672. ++*strp;
  673. *valuep = value;
  674. return errmsg;
  675. }
  676. else if (strncasecmp (*strp + 1, "gottlsoff12(", 12) == 0)
  677. {
  678. *strp += 13;
  679. errmsg = parse_symbolic_address (cd, strp, opindex,
  680. BFD_RELOC_FRV_GOTTLSOFF12,
  681. & result_type, & value);
  682. if (**strp != ')')
  683. return "missing ')'";
  684. ++*strp;
  685. *valuep = value;
  686. return errmsg;
  687. }
  688. }
  689. return cgen_parse_signed_integer (cd, strp, opindex, valuep);
  690. }
  691. static const char *
  692. parse_s12 (CGEN_CPU_DESC cd,
  693. const char **strp,
  694. int opindex,
  695. long *valuep)
  696. {
  697. const char *errmsg;
  698. enum cgen_parse_operand_result result_type;
  699. bfd_vma value;
  700. /* Check for small data reference. */
  701. if (**strp == '#' || **strp == '%')
  702. {
  703. if (strncasecmp (*strp + 1, "gprel12(", 8) == 0)
  704. {
  705. *strp += 9;
  706. errmsg = parse_symbolic_address (cd, strp, opindex,
  707. BFD_RELOC_FRV_GPREL12,
  708. & result_type, & value);
  709. if (**strp != ')')
  710. return "missing `)'";
  711. ++*strp;
  712. *valuep = value;
  713. return errmsg;
  714. }
  715. else if (strncasecmp (*strp + 1, "got12(", 6) == 0)
  716. {
  717. *strp += 7;
  718. errmsg = parse_symbolic_address (cd, strp, opindex,
  719. BFD_RELOC_FRV_GOT12,
  720. & result_type, & value);
  721. if (**strp != ')')
  722. return "missing ')'";
  723. ++*strp;
  724. *valuep = value;
  725. return errmsg;
  726. }
  727. else if (strncasecmp (*strp + 1, "gotfuncdesc12(", 14) == 0)
  728. {
  729. *strp += 15;
  730. errmsg = parse_symbolic_address (cd, strp, opindex,
  731. BFD_RELOC_FRV_FUNCDESC_GOT12,
  732. & result_type, & value);
  733. if (**strp != ')')
  734. return "missing ')'";
  735. ++*strp;
  736. *valuep = value;
  737. return errmsg;
  738. }
  739. else if (strncasecmp (*strp + 1, "gotoff12(", 9) == 0)
  740. {
  741. *strp += 10;
  742. errmsg = parse_symbolic_address (cd, strp, opindex,
  743. BFD_RELOC_FRV_GOTOFF12,
  744. & result_type, & value);
  745. if (**strp != ')')
  746. return "missing ')'";
  747. ++*strp;
  748. *valuep = value;
  749. return errmsg;
  750. }
  751. else if (strncasecmp (*strp + 1, "gotofffuncdesc12(", 17) == 0)
  752. {
  753. *strp += 18;
  754. errmsg = parse_symbolic_address (cd, strp, opindex,
  755. BFD_RELOC_FRV_FUNCDESC_GOTOFF12,
  756. & result_type, & value);
  757. if (**strp != ')')
  758. return "missing ')'";
  759. ++*strp;
  760. *valuep = value;
  761. return errmsg;
  762. }
  763. else if (strncasecmp (*strp + 1, "gottlsdesc12(", 13) == 0)
  764. {
  765. *strp += 14;
  766. errmsg = parse_symbolic_address (cd, strp, opindex,
  767. BFD_RELOC_FRV_GOTTLSDESC12,
  768. & result_type, & value);
  769. if (**strp != ')')
  770. return "missing ')'";
  771. ++*strp;
  772. *valuep = value;
  773. return errmsg;
  774. }
  775. else if (strncasecmp (*strp + 1, "tlsmoff12(", 10) == 0)
  776. {
  777. *strp += 11;
  778. errmsg = parse_symbolic_address (cd, strp, opindex,
  779. BFD_RELOC_FRV_TLSMOFF12,
  780. & result_type, & value);
  781. if (**strp != ')')
  782. return "missing ')'";
  783. ++*strp;
  784. *valuep = value;
  785. return errmsg;
  786. }
  787. else if (strncasecmp (*strp + 1, "gottlsoff12(", 12) == 0)
  788. {
  789. *strp += 13;
  790. errmsg = parse_symbolic_address (cd, strp, opindex,
  791. BFD_RELOC_FRV_GOTTLSOFF12,
  792. & result_type, & value);
  793. if (**strp != ')')
  794. return "missing ')'";
  795. ++*strp;
  796. *valuep = value;
  797. return errmsg;
  798. }
  799. }
  800. if (**strp == '#')
  801. ++*strp;
  802. return cgen_parse_signed_integer (cd, strp, opindex, valuep);
  803. }
  804. static const char *
  805. parse_u12 (CGEN_CPU_DESC cd,
  806. const char **strp,
  807. int opindex,
  808. long *valuep)
  809. {
  810. const char *errmsg;
  811. enum cgen_parse_operand_result result_type;
  812. bfd_vma value;
  813. /* Check for small data reference. */
  814. if ((**strp == '#' || **strp == '%')
  815. && strncasecmp (*strp + 1, "gprel12(", 8) == 0)
  816. {
  817. *strp += 9;
  818. errmsg = parse_symbolic_address (cd, strp, opindex,
  819. BFD_RELOC_FRV_GPRELU12,
  820. & result_type, & value);
  821. if (**strp != ')')
  822. return "missing `)'";
  823. ++*strp;
  824. *valuep = value;
  825. return errmsg;
  826. }
  827. else
  828. {
  829. if (**strp == '#')
  830. ++*strp;
  831. return cgen_parse_signed_integer (cd, strp, opindex, valuep);
  832. }
  833. }
  834. static const char *
  835. parse_A (CGEN_CPU_DESC cd,
  836. const char **strp,
  837. int opindex,
  838. unsigned long *valuep,
  839. unsigned long A)
  840. {
  841. const char *errmsg;
  842. if (**strp == '#')
  843. ++*strp;
  844. errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
  845. if (errmsg)
  846. return errmsg;
  847. if (*valuep != A)
  848. return _("Value of A operand must be 0 or 1");
  849. return NULL;
  850. }
  851. static const char *
  852. parse_A0 (CGEN_CPU_DESC cd,
  853. const char **strp,
  854. int opindex,
  855. unsigned long *valuep)
  856. {
  857. return parse_A (cd, strp, opindex, valuep, 0);
  858. }
  859. static const char *
  860. parse_A1 (CGEN_CPU_DESC cd,
  861. const char **strp,
  862. int opindex,
  863. unsigned long *valuep)
  864. {
  865. return parse_A (cd, strp, opindex, valuep, 1);
  866. }
  867. static const char *
  868. parse_even_register (CGEN_CPU_DESC cd,
  869. const char ** strP,
  870. CGEN_KEYWORD * tableP,
  871. long * valueP)
  872. {
  873. const char * errmsg;
  874. const char * saved_star_strP = * strP;
  875. errmsg = cgen_parse_keyword (cd, strP, tableP, valueP);
  876. if (errmsg == NULL && ((* valueP) & 1))
  877. {
  878. errmsg = _("register number must be even");
  879. * strP = saved_star_strP;
  880. }
  881. return errmsg;
  882. }
  883. static const char *
  884. parse_call_label (CGEN_CPU_DESC cd,
  885. const char **strp,
  886. int opindex,
  887. int opinfo,
  888. enum cgen_parse_operand_result *resultp,
  889. bfd_vma *valuep)
  890. {
  891. const char *errmsg;
  892. bfd_vma value;
  893. /* Check for small data reference. */
  894. if (opinfo == 0 && (**strp == '#' || **strp == '%'))
  895. {
  896. if (strncasecmp (*strp + 1, "gettlsoff(", 10) == 0)
  897. {
  898. *strp += 11;
  899. errmsg = parse_symbolic_address (cd, strp, opindex,
  900. BFD_RELOC_FRV_GETTLSOFF,
  901. resultp, &value);
  902. if (**strp != ')')
  903. return _("missing `)'");
  904. ++*strp;
  905. *valuep = value;
  906. return errmsg;
  907. }
  908. }
  909. return cgen_parse_address (cd, strp, opindex, opinfo, resultp, valuep);
  910. }
  911. /* -- */
  912. const char * frv_cgen_parse_operand
  913. (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
  914. /* Main entry point for operand parsing.
  915. This function is basically just a big switch statement. Earlier versions
  916. used tables to look up the function to use, but
  917. - if the table contains both assembler and disassembler functions then
  918. the disassembler contains much of the assembler and vice-versa,
  919. - there's a lot of inlining possibilities as things grow,
  920. - using a switch statement avoids the function call overhead.
  921. This function could be moved into `parse_insn_normal', but keeping it
  922. separate makes clear the interface between `parse_insn_normal' and each of
  923. the handlers. */
  924. const char *
  925. frv_cgen_parse_operand (CGEN_CPU_DESC cd,
  926. int opindex,
  927. const char ** strp,
  928. CGEN_FIELDS * fields)
  929. {
  930. const char * errmsg = NULL;
  931. /* Used by scalar operands that still need to be parsed. */
  932. long junk ATTRIBUTE_UNUSED;
  933. switch (opindex)
  934. {
  935. case FRV_OPERAND_A0 :
  936. errmsg = parse_A0 (cd, strp, FRV_OPERAND_A0, (unsigned long *) (& fields->f_A));
  937. break;
  938. case FRV_OPERAND_A1 :
  939. errmsg = parse_A1 (cd, strp, FRV_OPERAND_A1, (unsigned long *) (& fields->f_A));
  940. break;
  941. case FRV_OPERAND_ACC40SI :
  942. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Si);
  943. break;
  944. case FRV_OPERAND_ACC40SK :
  945. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Sk);
  946. break;
  947. case FRV_OPERAND_ACC40UI :
  948. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Ui);
  949. break;
  950. case FRV_OPERAND_ACC40UK :
  951. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_acc_names, & fields->f_ACC40Uk);
  952. break;
  953. case FRV_OPERAND_ACCGI :
  954. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_accg_names, & fields->f_ACCGi);
  955. break;
  956. case FRV_OPERAND_ACCGK :
  957. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_accg_names, & fields->f_ACCGk);
  958. break;
  959. case FRV_OPERAND_CCI :
  960. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CCi);
  961. break;
  962. case FRV_OPERAND_CPRDOUBLEK :
  963. errmsg = parse_even_register (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRk);
  964. break;
  965. case FRV_OPERAND_CPRI :
  966. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRi);
  967. break;
  968. case FRV_OPERAND_CPRJ :
  969. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRj);
  970. break;
  971. case FRV_OPERAND_CPRK :
  972. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cpr_names, & fields->f_CPRk);
  973. break;
  974. case FRV_OPERAND_CRI :
  975. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRi);
  976. break;
  977. case FRV_OPERAND_CRJ :
  978. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRj);
  979. break;
  980. case FRV_OPERAND_CRJ_FLOAT :
  981. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRj_float);
  982. break;
  983. case FRV_OPERAND_CRJ_INT :
  984. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRj_int);
  985. break;
  986. case FRV_OPERAND_CRK :
  987. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_cccr_names, & fields->f_CRk);
  988. break;
  989. case FRV_OPERAND_FCCI_1 :
  990. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCi_1);
  991. break;
  992. case FRV_OPERAND_FCCI_2 :
  993. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCi_2);
  994. break;
  995. case FRV_OPERAND_FCCI_3 :
  996. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCi_3);
  997. break;
  998. case FRV_OPERAND_FCCK :
  999. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fccr_names, & fields->f_FCCk);
  1000. break;
  1001. case FRV_OPERAND_FRDOUBLEI :
  1002. errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
  1003. break;
  1004. case FRV_OPERAND_FRDOUBLEJ :
  1005. errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
  1006. break;
  1007. case FRV_OPERAND_FRDOUBLEK :
  1008. errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
  1009. break;
  1010. case FRV_OPERAND_FRI :
  1011. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
  1012. break;
  1013. case FRV_OPERAND_FRINTI :
  1014. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
  1015. break;
  1016. case FRV_OPERAND_FRINTIEVEN :
  1017. errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRi);
  1018. break;
  1019. case FRV_OPERAND_FRINTJ :
  1020. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
  1021. break;
  1022. case FRV_OPERAND_FRINTJEVEN :
  1023. errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
  1024. break;
  1025. case FRV_OPERAND_FRINTK :
  1026. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
  1027. break;
  1028. case FRV_OPERAND_FRINTKEVEN :
  1029. errmsg = parse_even_register (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
  1030. break;
  1031. case FRV_OPERAND_FRJ :
  1032. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRj);
  1033. break;
  1034. case FRV_OPERAND_FRK :
  1035. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
  1036. break;
  1037. case FRV_OPERAND_FRKHI :
  1038. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
  1039. break;
  1040. case FRV_OPERAND_FRKLO :
  1041. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_fr_names, & fields->f_FRk);
  1042. break;
  1043. case FRV_OPERAND_GRDOUBLEK :
  1044. errmsg = parse_even_register (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
  1045. break;
  1046. case FRV_OPERAND_GRI :
  1047. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRi);
  1048. break;
  1049. case FRV_OPERAND_GRJ :
  1050. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRj);
  1051. break;
  1052. case FRV_OPERAND_GRK :
  1053. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
  1054. break;
  1055. case FRV_OPERAND_GRKHI :
  1056. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
  1057. break;
  1058. case FRV_OPERAND_GRKLO :
  1059. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_gr_names, & fields->f_GRk);
  1060. break;
  1061. case FRV_OPERAND_ICCI_1 :
  1062. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_iccr_names, & fields->f_ICCi_1);
  1063. break;
  1064. case FRV_OPERAND_ICCI_2 :
  1065. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_iccr_names, & fields->f_ICCi_2);
  1066. break;
  1067. case FRV_OPERAND_ICCI_3 :
  1068. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_iccr_names, & fields->f_ICCi_3);
  1069. break;
  1070. case FRV_OPERAND_LI :
  1071. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LI, (unsigned long *) (& fields->f_LI));
  1072. break;
  1073. case FRV_OPERAND_LRAD :
  1074. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LRAD, (unsigned long *) (& fields->f_LRAD));
  1075. break;
  1076. case FRV_OPERAND_LRAE :
  1077. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LRAE, (unsigned long *) (& fields->f_LRAE));
  1078. break;
  1079. case FRV_OPERAND_LRAS :
  1080. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LRAS, (unsigned long *) (& fields->f_LRAS));
  1081. break;
  1082. case FRV_OPERAND_TLBPRL :
  1083. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_TLBPRL, (unsigned long *) (& fields->f_TLBPRL));
  1084. break;
  1085. case FRV_OPERAND_TLBPROPX :
  1086. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_TLBPROPX, (unsigned long *) (& fields->f_TLBPRopx));
  1087. break;
  1088. case FRV_OPERAND_AE :
  1089. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_AE, (unsigned long *) (& fields->f_ae));
  1090. break;
  1091. case FRV_OPERAND_CALLANN :
  1092. errmsg = parse_call_annotation (cd, strp, FRV_OPERAND_CALLANN, (unsigned long *) (& fields->f_reloc_ann));
  1093. break;
  1094. case FRV_OPERAND_CCOND :
  1095. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_CCOND, (unsigned long *) (& fields->f_ccond));
  1096. break;
  1097. case FRV_OPERAND_COND :
  1098. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_COND, (unsigned long *) (& fields->f_cond));
  1099. break;
  1100. case FRV_OPERAND_D12 :
  1101. errmsg = parse_d12 (cd, strp, FRV_OPERAND_D12, (long *) (& fields->f_d12));
  1102. break;
  1103. case FRV_OPERAND_DEBUG :
  1104. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_DEBUG, (unsigned long *) (& fields->f_debug));
  1105. break;
  1106. case FRV_OPERAND_EIR :
  1107. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_EIR, (unsigned long *) (& fields->f_eir));
  1108. break;
  1109. case FRV_OPERAND_HINT :
  1110. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_HINT, (unsigned long *) (& fields->f_hint));
  1111. break;
  1112. case FRV_OPERAND_HINT_NOT_TAKEN :
  1113. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_hint_not_taken, & fields->f_hint);
  1114. break;
  1115. case FRV_OPERAND_HINT_TAKEN :
  1116. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_hint_taken, & fields->f_hint);
  1117. break;
  1118. case FRV_OPERAND_LABEL16 :
  1119. {
  1120. bfd_vma value = 0;
  1121. errmsg = cgen_parse_address (cd, strp, FRV_OPERAND_LABEL16, 0, NULL, & value);
  1122. fields->f_label16 = value;
  1123. }
  1124. break;
  1125. case FRV_OPERAND_LABEL24 :
  1126. {
  1127. bfd_vma value = 0;
  1128. errmsg = parse_call_label (cd, strp, FRV_OPERAND_LABEL24, 0, NULL, & value);
  1129. fields->f_label24 = value;
  1130. }
  1131. break;
  1132. case FRV_OPERAND_LDANN :
  1133. errmsg = parse_ld_annotation (cd, strp, FRV_OPERAND_LDANN, (unsigned long *) (& fields->f_reloc_ann));
  1134. break;
  1135. case FRV_OPERAND_LDDANN :
  1136. errmsg = parse_ldd_annotation (cd, strp, FRV_OPERAND_LDDANN, (unsigned long *) (& fields->f_reloc_ann));
  1137. break;
  1138. case FRV_OPERAND_LOCK :
  1139. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_LOCK, (unsigned long *) (& fields->f_lock));
  1140. break;
  1141. case FRV_OPERAND_PACK :
  1142. errmsg = cgen_parse_keyword (cd, strp, & frv_cgen_opval_h_pack, & fields->f_pack);
  1143. break;
  1144. case FRV_OPERAND_S10 :
  1145. errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S10, (long *) (& fields->f_s10));
  1146. break;
  1147. case FRV_OPERAND_S12 :
  1148. errmsg = parse_s12 (cd, strp, FRV_OPERAND_S12, (long *) (& fields->f_d12));
  1149. break;
  1150. case FRV_OPERAND_S16 :
  1151. errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S16, (long *) (& fields->f_s16));
  1152. break;
  1153. case FRV_OPERAND_S5 :
  1154. errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S5, (long *) (& fields->f_s5));
  1155. break;
  1156. case FRV_OPERAND_S6 :
  1157. errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S6, (long *) (& fields->f_s6));
  1158. break;
  1159. case FRV_OPERAND_S6_1 :
  1160. errmsg = cgen_parse_signed_integer (cd, strp, FRV_OPERAND_S6_1, (long *) (& fields->f_s6_1));
  1161. break;
  1162. case FRV_OPERAND_SLO16 :
  1163. errmsg = parse_uslo16 (cd, strp, FRV_OPERAND_SLO16, (long *) (& fields->f_s16));
  1164. break;
  1165. case FRV_OPERAND_SPR :
  1166. errmsg = parse_spr (cd, strp, & frv_cgen_opval_spr_names, & fields->f_spr);
  1167. break;
  1168. case FRV_OPERAND_U12 :
  1169. errmsg = parse_u12 (cd, strp, FRV_OPERAND_U12, (long *) (& fields->f_u12));
  1170. break;
  1171. case FRV_OPERAND_U16 :
  1172. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_U16, (unsigned long *) (& fields->f_u16));
  1173. break;
  1174. case FRV_OPERAND_U6 :
  1175. errmsg = cgen_parse_unsigned_integer (cd, strp, FRV_OPERAND_U6, (unsigned long *) (& fields->f_u6));
  1176. break;
  1177. case FRV_OPERAND_UHI16 :
  1178. errmsg = parse_uhi16 (cd, strp, FRV_OPERAND_UHI16, (unsigned long *) (& fields->f_u16));
  1179. break;
  1180. case FRV_OPERAND_ULO16 :
  1181. errmsg = parse_ulo16 (cd, strp, FRV_OPERAND_ULO16, (unsigned long *) (& fields->f_u16));
  1182. break;
  1183. default :
  1184. /* xgettext:c-format */
  1185. opcodes_error_handler
  1186. (_("internal error: unrecognized field %d while parsing"),
  1187. opindex);
  1188. abort ();
  1189. }
  1190. return errmsg;
  1191. }
  1192. cgen_parse_fn * const frv_cgen_parse_handlers[] =
  1193. {
  1194. parse_insn_normal,
  1195. };
  1196. void
  1197. frv_cgen_init_asm (CGEN_CPU_DESC cd)
  1198. {
  1199. frv_cgen_init_opcode_table (cd);
  1200. frv_cgen_init_ibld_table (cd);
  1201. cd->parse_handlers = & frv_cgen_parse_handlers[0];
  1202. cd->parse_operand = frv_cgen_parse_operand;
  1203. #ifdef CGEN_ASM_INIT_HOOK
  1204. CGEN_ASM_INIT_HOOK
  1205. #endif
  1206. }
  1207. /* Regex construction routine.
  1208. This translates an opcode syntax string into a regex string,
  1209. by replacing any non-character syntax element (such as an
  1210. opcode) with the pattern '.*'
  1211. It then compiles the regex and stores it in the opcode, for
  1212. later use by frv_cgen_assemble_insn
  1213. Returns NULL for success, an error message for failure. */
  1214. char *
  1215. frv_cgen_build_insn_regex (CGEN_INSN *insn)
  1216. {
  1217. CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
  1218. const char *mnem = CGEN_INSN_MNEMONIC (insn);
  1219. char rxbuf[CGEN_MAX_RX_ELEMENTS];
  1220. char *rx = rxbuf;
  1221. const CGEN_SYNTAX_CHAR_TYPE *syn;
  1222. int reg_err;
  1223. syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
  1224. /* Mnemonics come first in the syntax string. */
  1225. if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
  1226. return _("missing mnemonic in syntax string");
  1227. ++syn;
  1228. /* Generate a case sensitive regular expression that emulates case
  1229. insensitive matching in the "C" locale. We cannot generate a case
  1230. insensitive regular expression because in Turkish locales, 'i' and 'I'
  1231. are not equal modulo case conversion. */
  1232. /* Copy the literal mnemonic out of the insn. */
  1233. for (; *mnem; mnem++)
  1234. {
  1235. char c = *mnem;
  1236. if (ISALPHA (c))
  1237. {
  1238. *rx++ = '[';
  1239. *rx++ = TOLOWER (c);
  1240. *rx++ = TOUPPER (c);
  1241. *rx++ = ']';
  1242. }
  1243. else
  1244. *rx++ = c;
  1245. }
  1246. /* Copy any remaining literals from the syntax string into the rx. */
  1247. for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
  1248. {
  1249. if (CGEN_SYNTAX_CHAR_P (* syn))
  1250. {
  1251. char c = CGEN_SYNTAX_CHAR (* syn);
  1252. switch (c)
  1253. {
  1254. /* Escape any regex metacharacters in the syntax. */
  1255. case '.': case '[': case '\\':
  1256. case '*': case '^': case '$':
  1257. #ifdef CGEN_ESCAPE_EXTENDED_REGEX
  1258. case '?': case '{': case '}':
  1259. case '(': case ')': case '*':
  1260. case '|': case '+': case ']':
  1261. #endif
  1262. *rx++ = '\\';
  1263. *rx++ = c;
  1264. break;
  1265. default:
  1266. if (ISALPHA (c))
  1267. {
  1268. *rx++ = '[';
  1269. *rx++ = TOLOWER (c);
  1270. *rx++ = TOUPPER (c);
  1271. *rx++ = ']';
  1272. }
  1273. else
  1274. *rx++ = c;
  1275. break;
  1276. }
  1277. }
  1278. else
  1279. {
  1280. /* Replace non-syntax fields with globs. */
  1281. *rx++ = '.';
  1282. *rx++ = '*';
  1283. }
  1284. }
  1285. /* Trailing whitespace ok. */
  1286. * rx++ = '[';
  1287. * rx++ = ' ';
  1288. * rx++ = '\t';
  1289. * rx++ = ']';
  1290. * rx++ = '*';
  1291. /* But anchor it after that. */
  1292. * rx++ = '$';
  1293. * rx = '\0';
  1294. CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
  1295. reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
  1296. if (reg_err == 0)
  1297. return NULL;
  1298. else
  1299. {
  1300. static char msg[80];
  1301. regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
  1302. regfree ((regex_t *) CGEN_INSN_RX (insn));
  1303. free (CGEN_INSN_RX (insn));
  1304. (CGEN_INSN_RX (insn)) = NULL;
  1305. return msg;
  1306. }
  1307. }
  1308. /* Default insn parser.
  1309. The syntax string is scanned and operands are parsed and stored in FIELDS.
  1310. Relocs are queued as we go via other callbacks.
  1311. ??? Note that this is currently an all-or-nothing parser. If we fail to
  1312. parse the instruction, we return 0 and the caller will start over from
  1313. the beginning. Backtracking will be necessary in parsing subexpressions,
  1314. but that can be handled there. Not handling backtracking here may get
  1315. expensive in the case of the m68k. Deal with later.
  1316. Returns NULL for success, an error message for failure. */
  1317. static const char *
  1318. parse_insn_normal (CGEN_CPU_DESC cd,
  1319. const CGEN_INSN *insn,
  1320. const char **strp,
  1321. CGEN_FIELDS *fields)
  1322. {
  1323. /* ??? Runtime added insns not handled yet. */
  1324. const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
  1325. const char *str = *strp;
  1326. const char *errmsg;
  1327. const char *p;
  1328. const CGEN_SYNTAX_CHAR_TYPE * syn;
  1329. #ifdef CGEN_MNEMONIC_OPERANDS
  1330. /* FIXME: wip */
  1331. int past_opcode_p;
  1332. #endif
  1333. /* For now we assume the mnemonic is first (there are no leading operands).
  1334. We can parse it without needing to set up operand parsing.
  1335. GAS's input scrubber will ensure mnemonics are lowercase, but we may
  1336. not be called from GAS. */
  1337. p = CGEN_INSN_MNEMONIC (insn);
  1338. while (*p && TOLOWER (*p) == TOLOWER (*str))
  1339. ++p, ++str;
  1340. if (* p)
  1341. return _("unrecognized instruction");
  1342. #ifndef CGEN_MNEMONIC_OPERANDS
  1343. if (* str && ! ISSPACE (* str))
  1344. return _("unrecognized instruction");
  1345. #endif
  1346. CGEN_INIT_PARSE (cd);
  1347. cgen_init_parse_operand (cd);
  1348. #ifdef CGEN_MNEMONIC_OPERANDS
  1349. past_opcode_p = 0;
  1350. #endif
  1351. /* We don't check for (*str != '\0') here because we want to parse
  1352. any trailing fake arguments in the syntax string. */
  1353. syn = CGEN_SYNTAX_STRING (syntax);
  1354. /* Mnemonics come first for now, ensure valid string. */
  1355. if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
  1356. abort ();
  1357. ++syn;
  1358. while (* syn != 0)
  1359. {
  1360. /* Non operand chars must match exactly. */
  1361. if (CGEN_SYNTAX_CHAR_P (* syn))
  1362. {
  1363. /* FIXME: While we allow for non-GAS callers above, we assume the
  1364. first char after the mnemonic part is a space. */
  1365. /* FIXME: We also take inappropriate advantage of the fact that
  1366. GAS's input scrubber will remove extraneous blanks. */
  1367. if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
  1368. {
  1369. #ifdef CGEN_MNEMONIC_OPERANDS
  1370. if (CGEN_SYNTAX_CHAR(* syn) == ' ')
  1371. past_opcode_p = 1;
  1372. #endif
  1373. ++ syn;
  1374. ++ str;
  1375. }
  1376. else if (*str)
  1377. {
  1378. /* Syntax char didn't match. Can't be this insn. */
  1379. static char msg [80];
  1380. /* xgettext:c-format */
  1381. sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
  1382. CGEN_SYNTAX_CHAR(*syn), *str);
  1383. return msg;
  1384. }
  1385. else
  1386. {
  1387. /* Ran out of input. */
  1388. static char msg [80];
  1389. /* xgettext:c-format */
  1390. sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
  1391. CGEN_SYNTAX_CHAR(*syn));
  1392. return msg;
  1393. }
  1394. continue;
  1395. }
  1396. #ifdef CGEN_MNEMONIC_OPERANDS
  1397. (void) past_opcode_p;
  1398. #endif
  1399. /* We have an operand of some sort. */
  1400. errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), &str, fields);
  1401. if (errmsg)
  1402. return errmsg;
  1403. /* Done with this operand, continue with next one. */
  1404. ++ syn;
  1405. }
  1406. /* If we're at the end of the syntax string, we're done. */
  1407. if (* syn == 0)
  1408. {
  1409. /* FIXME: For the moment we assume a valid `str' can only contain
  1410. blanks now. IE: We needn't try again with a longer version of
  1411. the insn and it is assumed that longer versions of insns appear
  1412. before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
  1413. while (ISSPACE (* str))
  1414. ++ str;
  1415. if (* str != '\0')
  1416. return _("junk at end of line"); /* FIXME: would like to include `str' */
  1417. return NULL;
  1418. }
  1419. /* We couldn't parse it. */
  1420. return _("unrecognized instruction");
  1421. }
  1422. /* Main entry point.
  1423. This routine is called for each instruction to be assembled.
  1424. STR points to the insn to be assembled.
  1425. We assume all necessary tables have been initialized.
  1426. The assembled instruction, less any fixups, is stored in BUF.
  1427. Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
  1428. still needs to be converted to target byte order, otherwise BUF is an array
  1429. of bytes in target byte order.
  1430. The result is a pointer to the insn's entry in the opcode table,
  1431. or NULL if an error occured (an error message will have already been
  1432. printed).
  1433. Note that when processing (non-alias) macro-insns,
  1434. this function recurses.
  1435. ??? It's possible to make this cpu-independent.
  1436. One would have to deal with a few minor things.
  1437. At this point in time doing so would be more of a curiosity than useful
  1438. [for example this file isn't _that_ big], but keeping the possibility in
  1439. mind helps keep the design clean. */
  1440. const CGEN_INSN *
  1441. frv_cgen_assemble_insn (CGEN_CPU_DESC cd,
  1442. const char *str,
  1443. CGEN_FIELDS *fields,
  1444. CGEN_INSN_BYTES_PTR buf,
  1445. char **errmsg)
  1446. {
  1447. const char *start;
  1448. CGEN_INSN_LIST *ilist;
  1449. const char *parse_errmsg = NULL;
  1450. const char *insert_errmsg = NULL;
  1451. int recognized_mnemonic = 0;
  1452. /* Skip leading white space. */
  1453. while (ISSPACE (* str))
  1454. ++ str;
  1455. /* The instructions are stored in hashed lists.
  1456. Get the first in the list. */
  1457. ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
  1458. /* Keep looking until we find a match. */
  1459. start = str;
  1460. for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
  1461. {
  1462. const CGEN_INSN *insn = ilist->insn;
  1463. recognized_mnemonic = 1;
  1464. #ifdef CGEN_VALIDATE_INSN_SUPPORTED
  1465. /* Not usually needed as unsupported opcodes
  1466. shouldn't be in the hash lists. */
  1467. /* Is this insn supported by the selected cpu? */
  1468. if (! frv_cgen_insn_supported (cd, insn))
  1469. continue;
  1470. #endif
  1471. /* If the RELAXED attribute is set, this is an insn that shouldn't be
  1472. chosen immediately. Instead, it is used during assembler/linker
  1473. relaxation if possible. */
  1474. if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
  1475. continue;
  1476. str = start;
  1477. /* Skip this insn if str doesn't look right lexically. */
  1478. if (CGEN_INSN_RX (insn) != NULL &&
  1479. regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
  1480. continue;
  1481. /* Allow parse/insert handlers to obtain length of insn. */
  1482. CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
  1483. parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
  1484. if (parse_errmsg != NULL)
  1485. continue;
  1486. /* ??? 0 is passed for `pc'. */
  1487. insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
  1488. (bfd_vma) 0);
  1489. if (insert_errmsg != NULL)
  1490. continue;
  1491. /* It is up to the caller to actually output the insn and any
  1492. queued relocs. */
  1493. return insn;
  1494. }
  1495. {
  1496. static char errbuf[150];
  1497. const char *tmp_errmsg;
  1498. #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
  1499. #define be_verbose 1
  1500. #else
  1501. #define be_verbose 0
  1502. #endif
  1503. if (be_verbose)
  1504. {
  1505. /* If requesting verbose error messages, use insert_errmsg.
  1506. Failing that, use parse_errmsg. */
  1507. tmp_errmsg = (insert_errmsg ? insert_errmsg :
  1508. parse_errmsg ? parse_errmsg :
  1509. recognized_mnemonic ?
  1510. _("unrecognized form of instruction") :
  1511. _("unrecognized instruction"));
  1512. if (strlen (start) > 50)
  1513. /* xgettext:c-format */
  1514. sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
  1515. else
  1516. /* xgettext:c-format */
  1517. sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
  1518. }
  1519. else
  1520. {
  1521. if (strlen (start) > 50)
  1522. /* xgettext:c-format */
  1523. sprintf (errbuf, _("bad instruction `%.50s...'"), start);
  1524. else
  1525. /* xgettext:c-format */
  1526. sprintf (errbuf, _("bad instruction `%.50s'"), start);
  1527. }
  1528. *errmsg = errbuf;
  1529. return NULL;
  1530. }
  1531. }