tc-tilegx.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  1. /* tc-tilegx.c -- Assemble for a Tile-Gx chip.
  2. Copyright (C) 2011-2015 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "as.h"
  17. #include "struc-symbol.h"
  18. #include "subsegs.h"
  19. #include "elf/tilegx.h"
  20. #include "opcode/tilegx.h"
  21. #include "dwarf2dbg.h"
  22. #include "dw2gencfi.h"
  23. #include "safe-ctype.h"
  24. /* Special registers. */
  25. #define TREG_IDN0 57
  26. #define TREG_IDN1 58
  27. #define TREG_UDN0 59
  28. #define TREG_UDN1 60
  29. #define TREG_UDN2 61
  30. #define TREG_UDN3 62
  31. #define TREG_ZERO 63
  32. /* Generic assembler global variables which must be defined by all
  33. targets. */
  34. /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
  35. int tilegx_cie_data_alignment;
  36. /* Characters which always start a comment. */
  37. const char comment_chars[] = "#";
  38. /* Characters which start a comment at the beginning of a line. */
  39. const char line_comment_chars[] = "#";
  40. /* Characters which may be used to separate multiple commands on a
  41. single line. */
  42. const char line_separator_chars[] = ";";
  43. /* Characters which are used to indicate an exponent in a floating
  44. point number. */
  45. const char EXP_CHARS[] = "eE";
  46. /* Characters which mean that a number is a floating point constant,
  47. as in 0d1.0. */
  48. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  49. /* Either 32 or 64. */
  50. static int tilegx_arch_size = 64;
  51. const char *
  52. tilegx_target_format (void)
  53. {
  54. if (target_big_endian) {
  55. return tilegx_arch_size == 64 ? "elf64-tilegx-be" : "elf32-tilegx-be";
  56. } else {
  57. return tilegx_arch_size == 64 ? "elf64-tilegx-le" : "elf32-tilegx-le";
  58. }
  59. }
  60. #define OPTION_32 (OPTION_MD_BASE + 0)
  61. #define OPTION_64 (OPTION_MD_BASE + 1)
  62. #define OPTION_EB (OPTION_MD_BASE + 2)
  63. #define OPTION_EL (OPTION_MD_BASE + 3)
  64. const char *md_shortopts = "VQ:";
  65. struct option md_longopts[] =
  66. {
  67. {"32", no_argument, NULL, OPTION_32},
  68. {"64", no_argument, NULL, OPTION_64},
  69. {"EB", no_argument, NULL, OPTION_EB },
  70. {"EL", no_argument, NULL, OPTION_EL },
  71. {NULL, no_argument, NULL, 0}
  72. };
  73. size_t md_longopts_size = sizeof (md_longopts);
  74. int
  75. md_parse_option (int c, char *arg ATTRIBUTE_UNUSED)
  76. {
  77. switch (c)
  78. {
  79. /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
  80. should be emitted or not. FIXME: Not implemented. */
  81. case 'Q':
  82. break;
  83. /* -V: SVR4 argument to print version ID. */
  84. case 'V':
  85. print_version_id ();
  86. break;
  87. case OPTION_32:
  88. tilegx_arch_size = 32;
  89. break;
  90. case OPTION_64:
  91. tilegx_arch_size = 64;
  92. break;
  93. case OPTION_EB:
  94. target_big_endian = 1;
  95. break;
  96. case OPTION_EL:
  97. target_big_endian = 0;
  98. break;
  99. default:
  100. return 0;
  101. }
  102. return 1;
  103. }
  104. void
  105. md_show_usage (FILE *stream)
  106. {
  107. fprintf (stream, _("\
  108. -Q ignored\n\
  109. -V print assembler version number\n\
  110. -EB/-EL generate big-endian/little-endian code\n\
  111. --32/--64 generate 32bit/64bit code\n"));
  112. }
  113. /* Extra expression types. */
  114. #define O_hw0 O_md1
  115. #define O_hw1 O_md2
  116. #define O_hw2 O_md3
  117. #define O_hw3 O_md4
  118. #define O_hw0_last O_md5
  119. #define O_hw1_last O_md6
  120. #define O_hw2_last O_md7
  121. #define O_hw0_got O_md8
  122. #define O_hw0_last_got O_md9
  123. #define O_hw1_last_got O_md10
  124. #define O_plt O_md11
  125. #define O_hw0_tls_gd O_md12
  126. #define O_hw0_last_tls_gd O_md13
  127. #define O_hw1_last_tls_gd O_md14
  128. #define O_hw0_tls_ie O_md15
  129. #define O_hw0_last_tls_ie O_md16
  130. #define O_hw1_last_tls_ie O_md17
  131. #define O_hw0_tls_le O_md18
  132. #define O_hw0_last_tls_le O_md19
  133. #define O_hw1_last_tls_le O_md20
  134. #define O_tls_gd_call O_md21
  135. #define O_tls_gd_add O_md22
  136. #define O_tls_ie_load O_md23
  137. #define O_tls_add O_md24
  138. #define O_hw0_plt O_md25
  139. #define O_hw1_plt O_md26
  140. #define O_hw1_last_plt O_md27
  141. #define O_hw2_last_plt O_md28
  142. static struct hash_control *special_operator_hash;
  143. /* Hash tables for instruction mnemonic lookup. */
  144. static struct hash_control *op_hash;
  145. /* Hash table for spr lookup. */
  146. static struct hash_control *spr_hash;
  147. /* True temporarily while parsing an SPR expression. This changes the
  148. * namespace to include SPR names. */
  149. static int parsing_spr;
  150. /* Are we currently inside `{ ... }'? */
  151. static int inside_bundle;
  152. struct tilegx_instruction
  153. {
  154. const struct tilegx_opcode *opcode;
  155. tilegx_pipeline pipe;
  156. expressionS operand_values[TILEGX_MAX_OPERANDS];
  157. };
  158. /* This keeps track of the current bundle being built up. */
  159. static struct tilegx_instruction current_bundle[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE];
  160. /* Index in current_bundle for the next instruction to parse. */
  161. static int current_bundle_index;
  162. /* Allow 'r63' in addition to 'zero', etc. Normally we disallow this as
  163. 'zero' is not a real register, so using it accidentally would be a
  164. nasty bug. For other registers, such as 'sp', code using multiple names
  165. for the same physical register is excessively confusing.
  166. The '.require_canonical_reg_names' pseudo-op turns this error on,
  167. and the '.no_require_canonical_reg_names' pseudo-op turns this off.
  168. By default the error is on. */
  169. static int require_canonical_reg_names;
  170. /* Allow bundles that do undefined or suspicious things like write
  171. two different values to the same register at the same time.
  172. The '.no_allow_suspicious_bundles' pseudo-op turns this error on,
  173. and the '.allow_suspicious_bundles' pseudo-op turns this off. */
  174. static int allow_suspicious_bundles;
  175. /* A hash table of main processor registers, mapping each register name
  176. to its index.
  177. Furthermore, if the register number is greater than the number
  178. of registers for that processor, the user used an illegal alias
  179. for that register (e.g. r63 instead of zero), so we should generate
  180. a warning. The attempted register number can be found by clearing
  181. NONCANONICAL_REG_NAME_FLAG. */
  182. static struct hash_control *main_reg_hash;
  183. /* We cannot unambiguously store a 0 in a hash table and look it up,
  184. so we OR in this flag to every canonical register. */
  185. #define CANONICAL_REG_NAME_FLAG 0x1000
  186. /* By default we disallow register aliases like r63, but we record
  187. them in the hash table in case the .no_require_canonical_reg_names
  188. directive is used. Noncanonical names have this value added to them. */
  189. #define NONCANONICAL_REG_NAME_FLAG 0x2000
  190. /* Discards flags for register hash table entries and returns the
  191. reg number. */
  192. #define EXTRACT_REGNO(p) ((p) & 63)
  193. /* This function is called once, at assembler startup time. It should
  194. set up all the tables, etc., that the MD part of the assembler will
  195. need. */
  196. void
  197. md_begin (void)
  198. {
  199. const struct tilegx_opcode *op;
  200. int i;
  201. int mach = (tilegx_arch_size == 64) ? bfd_mach_tilegx : bfd_mach_tilegx32;
  202. if (! bfd_set_arch_mach (stdoutput, bfd_arch_tilegx, mach))
  203. as_warn (_("Could not set architecture and machine"));
  204. /* Guarantee text section is aligned. */
  205. bfd_set_section_alignment (stdoutput, text_section,
  206. TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES);
  207. require_canonical_reg_names = 1;
  208. allow_suspicious_bundles = 0;
  209. current_bundle_index = 0;
  210. inside_bundle = 0;
  211. tilegx_cie_data_alignment = (tilegx_arch_size == 64 ? -8 : -4);
  212. /* Initialize special operator hash table. */
  213. special_operator_hash = hash_new ();
  214. #define INSERT_SPECIAL_OP(name) \
  215. hash_insert (special_operator_hash, #name, (void *)O_##name)
  216. INSERT_SPECIAL_OP (hw0);
  217. INSERT_SPECIAL_OP (hw1);
  218. INSERT_SPECIAL_OP (hw2);
  219. INSERT_SPECIAL_OP (hw3);
  220. INSERT_SPECIAL_OP (hw0_last);
  221. INSERT_SPECIAL_OP (hw1_last);
  222. INSERT_SPECIAL_OP (hw2_last);
  223. /* hw3_last is a convenience alias for the equivalent hw3. */
  224. hash_insert (special_operator_hash, "hw3_last", (void*)O_hw3);
  225. INSERT_SPECIAL_OP (hw0_got);
  226. INSERT_SPECIAL_OP (hw0_last_got);
  227. INSERT_SPECIAL_OP (hw1_last_got);
  228. INSERT_SPECIAL_OP(plt);
  229. INSERT_SPECIAL_OP (hw0_tls_gd);
  230. INSERT_SPECIAL_OP (hw0_last_tls_gd);
  231. INSERT_SPECIAL_OP (hw1_last_tls_gd);
  232. INSERT_SPECIAL_OP (hw0_tls_ie);
  233. INSERT_SPECIAL_OP (hw0_last_tls_ie);
  234. INSERT_SPECIAL_OP (hw1_last_tls_ie);
  235. INSERT_SPECIAL_OP (hw0_tls_le);
  236. INSERT_SPECIAL_OP (hw0_last_tls_le);
  237. INSERT_SPECIAL_OP (hw1_last_tls_le);
  238. INSERT_SPECIAL_OP (tls_gd_call);
  239. INSERT_SPECIAL_OP (tls_gd_add);
  240. INSERT_SPECIAL_OP (tls_ie_load);
  241. INSERT_SPECIAL_OP (tls_add);
  242. INSERT_SPECIAL_OP (hw0_plt);
  243. INSERT_SPECIAL_OP (hw1_plt);
  244. INSERT_SPECIAL_OP (hw1_last_plt);
  245. INSERT_SPECIAL_OP (hw2_last_plt);
  246. #undef INSERT_SPECIAL_OP
  247. /* Initialize op_hash hash table. */
  248. op_hash = hash_new ();
  249. for (op = &tilegx_opcodes[0]; op->name != NULL; op++)
  250. {
  251. const char *hash_err = hash_insert (op_hash, op->name, (void *)op);
  252. if (hash_err != NULL)
  253. as_fatal (_("Internal Error: Can't hash %s: %s"), op->name, hash_err);
  254. }
  255. /* Initialize the spr hash table. */
  256. parsing_spr = 0;
  257. spr_hash = hash_new ();
  258. for (i = 0; i < tilegx_num_sprs; i++)
  259. hash_insert (spr_hash, tilegx_sprs[i].name,
  260. (void *) &tilegx_sprs[i]);
  261. /* Set up the main_reg_hash table. We use this instead of
  262. creating a symbol in the register section to avoid ambiguities
  263. with labels that have the same names as registers. */
  264. main_reg_hash = hash_new ();
  265. for (i = 0; i < TILEGX_NUM_REGISTERS; i++)
  266. {
  267. char buf[64];
  268. hash_insert (main_reg_hash, tilegx_register_names[i],
  269. (void *) (long) (i | CANONICAL_REG_NAME_FLAG));
  270. /* See if we should insert a noncanonical alias, like r63. */
  271. sprintf (buf, "r%d", i);
  272. if (strcmp (buf, tilegx_register_names[i]) != 0)
  273. hash_insert (main_reg_hash, xstrdup (buf),
  274. (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG));
  275. }
  276. }
  277. #define BUNDLE_TEMPLATE_MASK(p0, p1, p2) \
  278. ((p0) | ((p1) << 8) | ((p2) << 16))
  279. #define BUNDLE_TEMPLATE(p0, p1, p2) \
  280. { { (p0), (p1), (p2) }, \
  281. BUNDLE_TEMPLATE_MASK(1 << (p0), 1 << (p1), (1 << (p2))) \
  282. }
  283. #define NO_PIPELINE TILEGX_NUM_PIPELINE_ENCODINGS
  284. struct bundle_template
  285. {
  286. tilegx_pipeline pipe[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE];
  287. unsigned int pipe_mask;
  288. };
  289. static const struct bundle_template bundle_templates[] =
  290. {
  291. /* In Y format we must always have something in Y2, since it has
  292. no fnop, so this conveys that Y2 must always be used. */
  293. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0, TILEGX_PIPELINE_Y2, NO_PIPELINE),
  294. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1, TILEGX_PIPELINE_Y2, NO_PIPELINE),
  295. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2, TILEGX_PIPELINE_Y0, NO_PIPELINE),
  296. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2, TILEGX_PIPELINE_Y1, NO_PIPELINE),
  297. /* Y format has three instructions. */
  298. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0,TILEGX_PIPELINE_Y1,TILEGX_PIPELINE_Y2),
  299. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0,TILEGX_PIPELINE_Y2,TILEGX_PIPELINE_Y1),
  300. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1,TILEGX_PIPELINE_Y0,TILEGX_PIPELINE_Y2),
  301. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1,TILEGX_PIPELINE_Y2,TILEGX_PIPELINE_Y0),
  302. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2,TILEGX_PIPELINE_Y0,TILEGX_PIPELINE_Y1),
  303. BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2,TILEGX_PIPELINE_Y1,TILEGX_PIPELINE_Y0),
  304. /* X format has only two instructions. */
  305. BUNDLE_TEMPLATE(TILEGX_PIPELINE_X0, TILEGX_PIPELINE_X1, NO_PIPELINE),
  306. BUNDLE_TEMPLATE(TILEGX_PIPELINE_X1, TILEGX_PIPELINE_X0, NO_PIPELINE)
  307. };
  308. static void
  309. prepend_nop_to_bundle (tilegx_mnemonic mnemonic)
  310. {
  311. memmove (&current_bundle[1], &current_bundle[0],
  312. current_bundle_index * sizeof current_bundle[0]);
  313. current_bundle[0].opcode = &tilegx_opcodes[mnemonic];
  314. ++current_bundle_index;
  315. }
  316. static tilegx_bundle_bits
  317. insert_operand (tilegx_bundle_bits bits,
  318. const struct tilegx_operand *operand,
  319. int operand_value,
  320. char *file,
  321. unsigned lineno)
  322. {
  323. /* Range-check the immediate. */
  324. int num_bits = operand->num_bits;
  325. operand_value >>= operand->rightshift;
  326. if (bfd_check_overflow (operand->is_signed
  327. ? complain_overflow_signed
  328. : complain_overflow_unsigned,
  329. num_bits,
  330. 0,
  331. bfd_arch_bits_per_address (stdoutput),
  332. operand_value)
  333. != bfd_reloc_ok)
  334. {
  335. offsetT min, max;
  336. if (operand->is_signed)
  337. {
  338. min = -(1 << (num_bits - 1));
  339. max = (1 << (num_bits - 1)) - 1;
  340. }
  341. else
  342. {
  343. min = 0;
  344. max = (1 << num_bits) - 1;
  345. }
  346. as_bad_value_out_of_range (_("operand"), operand_value, min, max,
  347. file, lineno);
  348. }
  349. /* Write out the bits for the immediate. */
  350. return bits | operand->insert (operand_value);
  351. }
  352. static int
  353. apply_special_operator (operatorT op, offsetT num, char *file, unsigned lineno)
  354. {
  355. int ret;
  356. int check_shift = -1;
  357. switch (op)
  358. {
  359. case O_hw0_last:
  360. check_shift = 0;
  361. /* Fall through. */
  362. case O_hw0:
  363. ret = (signed short)num;
  364. break;
  365. case O_hw1_last:
  366. check_shift = 16;
  367. /* Fall through. */
  368. case O_hw1:
  369. ret = (signed short)(num >> 16);
  370. break;
  371. case O_hw2_last:
  372. check_shift = 32;
  373. /* Fall through. */
  374. case O_hw2:
  375. ret = (signed short)(num >> 32);
  376. break;
  377. case O_hw3:
  378. ret = (signed short)(num >> 48);
  379. break;
  380. default:
  381. abort ();
  382. break;
  383. }
  384. if (check_shift >= 0 && ret != (num >> check_shift))
  385. {
  386. as_bad_value_out_of_range (_("operand"), num,
  387. ~0ULL << (check_shift + 16 - 1),
  388. ~0ULL >> (64 - (check_shift + 16 - 1)),
  389. file, lineno);
  390. }
  391. return ret;
  392. }
  393. static tilegx_bundle_bits
  394. emit_tilegx_instruction (tilegx_bundle_bits bits,
  395. int num_operands,
  396. const unsigned char *operands,
  397. expressionS *operand_values,
  398. char *bundle_start)
  399. {
  400. int i;
  401. for (i = 0; i < num_operands; i++)
  402. {
  403. const struct tilegx_operand *operand =
  404. &tilegx_operands[operands[i]];
  405. expressionS *operand_exp = &operand_values[i];
  406. int is_pc_relative = operand->is_pc_relative;
  407. if (operand_exp->X_op == O_register
  408. || (operand_exp->X_op == O_constant && !is_pc_relative))
  409. {
  410. /* We know what the bits are right now, so insert them. */
  411. bits = insert_operand (bits, operand, operand_exp->X_add_number,
  412. NULL, 0);
  413. }
  414. else
  415. {
  416. bfd_reloc_code_real_type reloc = operand->default_reloc;
  417. expressionS subexp;
  418. int die = 0, use_subexp = 0, require_symbol = 0;
  419. fixS *fixP;
  420. /* Take an expression like hw0(x) and turn it into x with
  421. a different reloc type. */
  422. switch (operand_exp->X_op)
  423. {
  424. #define HANDLE_OP16(suffix) \
  425. switch (reloc) \
  426. { \
  427. case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST: \
  428. reloc = BFD_RELOC_TILEGX_IMM16_X0_##suffix; \
  429. break; \
  430. case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST: \
  431. reloc = BFD_RELOC_TILEGX_IMM16_X1_##suffix; \
  432. break; \
  433. default: \
  434. die = 1; \
  435. break; \
  436. } \
  437. use_subexp = 1
  438. case O_hw0:
  439. HANDLE_OP16 (HW0);
  440. break;
  441. case O_hw1:
  442. HANDLE_OP16 (HW1);
  443. break;
  444. case O_hw2:
  445. HANDLE_OP16 (HW2);
  446. break;
  447. case O_hw3:
  448. HANDLE_OP16 (HW3);
  449. break;
  450. case O_hw0_last:
  451. HANDLE_OP16 (HW0_LAST);
  452. break;
  453. case O_hw1_last:
  454. HANDLE_OP16 (HW1_LAST);
  455. break;
  456. case O_hw2_last:
  457. HANDLE_OP16 (HW2_LAST);
  458. break;
  459. case O_hw0_got:
  460. HANDLE_OP16 (HW0_GOT);
  461. require_symbol = 1;
  462. break;
  463. case O_hw0_last_got:
  464. HANDLE_OP16 (HW0_LAST_GOT);
  465. require_symbol = 1;
  466. break;
  467. case O_hw1_last_got:
  468. HANDLE_OP16 (HW1_LAST_GOT);
  469. require_symbol = 1;
  470. break;
  471. case O_hw0_tls_gd:
  472. HANDLE_OP16 (HW0_TLS_GD);
  473. require_symbol = 1;
  474. break;
  475. case O_hw0_last_tls_gd:
  476. HANDLE_OP16 (HW0_LAST_TLS_GD);
  477. require_symbol = 1;
  478. break;
  479. case O_hw1_last_tls_gd:
  480. HANDLE_OP16 (HW1_LAST_TLS_GD);
  481. require_symbol = 1;
  482. break;
  483. case O_hw0_tls_ie:
  484. HANDLE_OP16 (HW0_TLS_IE);
  485. require_symbol = 1;
  486. break;
  487. case O_hw0_last_tls_ie:
  488. HANDLE_OP16 (HW0_LAST_TLS_IE);
  489. require_symbol = 1;
  490. break;
  491. case O_hw1_last_tls_ie:
  492. HANDLE_OP16 (HW1_LAST_TLS_IE);
  493. require_symbol = 1;
  494. break;
  495. case O_hw0_tls_le:
  496. HANDLE_OP16 (HW0_TLS_LE);
  497. require_symbol = 1;
  498. break;
  499. case O_hw0_last_tls_le:
  500. HANDLE_OP16 (HW0_LAST_TLS_LE);
  501. require_symbol = 1;
  502. break;
  503. case O_hw1_last_tls_le:
  504. HANDLE_OP16 (HW1_LAST_TLS_LE);
  505. require_symbol = 1;
  506. break;
  507. case O_hw0_plt:
  508. HANDLE_OP16 (HW0_PLT_PCREL);
  509. break;
  510. case O_hw1_plt:
  511. HANDLE_OP16 (HW1_PLT_PCREL);
  512. break;
  513. case O_hw1_last_plt:
  514. HANDLE_OP16 (HW1_LAST_PLT_PCREL);
  515. break;
  516. case O_hw2_last_plt:
  517. HANDLE_OP16 (HW2_LAST_PLT_PCREL);
  518. break;
  519. #undef HANDLE_OP16
  520. case O_plt:
  521. switch (reloc)
  522. {
  523. case BFD_RELOC_TILEGX_JUMPOFF_X1:
  524. reloc = BFD_RELOC_TILEGX_JUMPOFF_X1_PLT;
  525. break;
  526. default:
  527. die = 1;
  528. break;
  529. }
  530. use_subexp = 1;
  531. require_symbol = 1;
  532. break;
  533. case O_tls_gd_call:
  534. switch (reloc)
  535. {
  536. case BFD_RELOC_TILEGX_JUMPOFF_X1:
  537. reloc = BFD_RELOC_TILEGX_TLS_GD_CALL;
  538. break;
  539. default:
  540. die = 1;
  541. break;
  542. }
  543. use_subexp = 1;
  544. require_symbol = 1;
  545. break;
  546. case O_tls_gd_add:
  547. switch (reloc)
  548. {
  549. case BFD_RELOC_TILEGX_IMM8_X0:
  550. reloc = BFD_RELOC_TILEGX_IMM8_X0_TLS_GD_ADD;
  551. break;
  552. case BFD_RELOC_TILEGX_IMM8_X1:
  553. reloc = BFD_RELOC_TILEGX_IMM8_X1_TLS_GD_ADD;
  554. break;
  555. case BFD_RELOC_TILEGX_IMM8_Y0:
  556. reloc = BFD_RELOC_TILEGX_IMM8_Y0_TLS_GD_ADD;
  557. break;
  558. case BFD_RELOC_TILEGX_IMM8_Y1:
  559. reloc = BFD_RELOC_TILEGX_IMM8_Y1_TLS_GD_ADD;
  560. break;
  561. default:
  562. die = 1;
  563. break;
  564. }
  565. use_subexp = 1;
  566. require_symbol = 1;
  567. break;
  568. case O_tls_ie_load:
  569. switch (reloc)
  570. {
  571. case BFD_RELOC_TILEGX_IMM8_X1:
  572. reloc = BFD_RELOC_TILEGX_TLS_IE_LOAD;
  573. break;
  574. default:
  575. die = 1;
  576. break;
  577. }
  578. use_subexp = 1;
  579. require_symbol = 1;
  580. break;
  581. case O_tls_add:
  582. switch (reloc)
  583. {
  584. case BFD_RELOC_TILEGX_IMM8_X0:
  585. reloc = BFD_RELOC_TILEGX_IMM8_X0_TLS_ADD;
  586. break;
  587. case BFD_RELOC_TILEGX_IMM8_X1:
  588. reloc = BFD_RELOC_TILEGX_IMM8_X1_TLS_ADD;
  589. break;
  590. case BFD_RELOC_TILEGX_IMM8_Y0:
  591. reloc = BFD_RELOC_TILEGX_IMM8_Y0_TLS_ADD;
  592. break;
  593. case BFD_RELOC_TILEGX_IMM8_Y1:
  594. reloc = BFD_RELOC_TILEGX_IMM8_Y1_TLS_ADD;
  595. break;
  596. default:
  597. die = 1;
  598. break;
  599. }
  600. use_subexp = 1;
  601. require_symbol = 1;
  602. break;
  603. default:
  604. /* Do nothing. */
  605. break;
  606. }
  607. if (die)
  608. {
  609. as_bad (_("Invalid operator for operand."));
  610. }
  611. else if (use_subexp)
  612. {
  613. /* Now that we've changed the reloc, change ha16(x) into x,
  614. etc. */
  615. if (!operand_exp->X_add_symbol->sy_flags.sy_local_symbol
  616. && operand_exp->X_add_symbol->sy_value.X_md)
  617. {
  618. /* HACK: We used X_md to mark this symbol as a fake wrapper
  619. around a real expression. To unwrap it, we just grab its
  620. value here. */
  621. operand_exp = &operand_exp->X_add_symbol->sy_value;
  622. if (require_symbol)
  623. {
  624. /* Look at the expression, and reject it if it's not a
  625. plain symbol. */
  626. if (operand_exp->X_op != O_symbol
  627. || operand_exp->X_add_number != 0)
  628. as_bad (_("Operator may only be applied to symbols."));
  629. }
  630. }
  631. else
  632. {
  633. /* The value of this expression is an actual symbol, so
  634. turn that into an expression. */
  635. memset (&subexp, 0, sizeof subexp);
  636. subexp.X_op = O_symbol;
  637. subexp.X_add_symbol = operand_exp->X_add_symbol;
  638. operand_exp = &subexp;
  639. }
  640. }
  641. /* Create a fixup to handle this later. */
  642. fixP = fix_new_exp (frag_now,
  643. bundle_start - frag_now->fr_literal,
  644. (operand->num_bits + 7) >> 3,
  645. operand_exp,
  646. is_pc_relative,
  647. reloc);
  648. fixP->tc_fix_data = operand;
  649. /* Don't do overflow checking if we are applying a function like
  650. ha16. */
  651. fixP->fx_no_overflow |= use_subexp;
  652. }
  653. }
  654. return bits;
  655. }
  656. /* Detects and complains if two instructions in current_bundle write
  657. to the same register, either implicitly or explicitly, or if a
  658. read-only register is written. */
  659. static void
  660. check_illegal_reg_writes (void)
  661. {
  662. BFD_HOST_U_64_BIT all_regs_written = 0;
  663. int j;
  664. for (j = 0; j < current_bundle_index; j++)
  665. {
  666. const struct tilegx_instruction *instr = &current_bundle[j];
  667. int k;
  668. BFD_HOST_U_64_BIT regs =
  669. ((BFD_HOST_U_64_BIT)1) << instr->opcode->implicitly_written_register;
  670. BFD_HOST_U_64_BIT conflict;
  671. for (k = 0; k < instr->opcode->num_operands; k++)
  672. {
  673. const struct tilegx_operand *operand =
  674. &tilegx_operands[instr->opcode->operands[instr->pipe][k]];
  675. if (operand->is_dest_reg)
  676. {
  677. int regno = instr->operand_values[k].X_add_number;
  678. BFD_HOST_U_64_BIT mask = ((BFD_HOST_U_64_BIT)1) << regno;
  679. if ((mask & ( (((BFD_HOST_U_64_BIT)1) << TREG_IDN1)
  680. | (((BFD_HOST_U_64_BIT)1) << TREG_UDN1)
  681. | (((BFD_HOST_U_64_BIT)1) << TREG_UDN2)
  682. | (((BFD_HOST_U_64_BIT)1) << TREG_UDN3))) != 0
  683. && !allow_suspicious_bundles)
  684. {
  685. as_bad (_("Writes to register '%s' are not allowed."),
  686. tilegx_register_names[regno]);
  687. }
  688. regs |= mask;
  689. }
  690. }
  691. /* Writing to the zero register doesn't count. */
  692. regs &= ~(((BFD_HOST_U_64_BIT)1) << TREG_ZERO);
  693. conflict = all_regs_written & regs;
  694. if (conflict != 0 && !allow_suspicious_bundles)
  695. {
  696. /* Find which register caused the conflict. */
  697. const char *conflicting_reg_name = "???";
  698. int i;
  699. for (i = 0; i < TILEGX_NUM_REGISTERS; i++)
  700. {
  701. if (((conflict >> i) & 1) != 0)
  702. {
  703. conflicting_reg_name = tilegx_register_names[i];
  704. break;
  705. }
  706. }
  707. as_bad (_("Two instructions in the same bundle both write "
  708. "to register %s, which is not allowed."),
  709. conflicting_reg_name);
  710. }
  711. all_regs_written |= regs;
  712. }
  713. }
  714. static void
  715. tilegx_flush_bundle (void)
  716. {
  717. unsigned i;
  718. int j;
  719. addressT addr_mod;
  720. unsigned compatible_pipes;
  721. const struct bundle_template *match;
  722. char *f;
  723. inside_bundle = 0;
  724. switch (current_bundle_index)
  725. {
  726. case 0:
  727. /* No instructions. */
  728. return;
  729. case 1:
  730. if (current_bundle[0].opcode->can_bundle)
  731. {
  732. /* Simplify later logic by adding an explicit fnop. */
  733. prepend_nop_to_bundle (TILEGX_OPC_FNOP);
  734. }
  735. else
  736. {
  737. /* This instruction cannot be bundled with anything else.
  738. Prepend an explicit 'nop', rather than an 'fnop', because
  739. fnops can be replaced by later binary-processing tools while
  740. nops cannot. */
  741. prepend_nop_to_bundle (TILEGX_OPC_NOP);
  742. }
  743. break;
  744. default:
  745. if (!allow_suspicious_bundles)
  746. {
  747. /* Make sure all instructions can be bundled with other
  748. instructions. */
  749. const struct tilegx_opcode *cannot_bundle = NULL;
  750. bfd_boolean seen_non_nop = FALSE;
  751. for (j = 0; j < current_bundle_index; j++)
  752. {
  753. const struct tilegx_opcode *op = current_bundle[j].opcode;
  754. if (!op->can_bundle && cannot_bundle == NULL)
  755. cannot_bundle = op;
  756. else if (op->mnemonic != TILEGX_OPC_NOP
  757. && op->mnemonic != TILEGX_OPC_INFO
  758. && op->mnemonic != TILEGX_OPC_INFOL)
  759. seen_non_nop = TRUE;
  760. }
  761. if (cannot_bundle != NULL && seen_non_nop)
  762. {
  763. current_bundle_index = 0;
  764. as_bad (_("'%s' may not be bundled with other instructions."),
  765. cannot_bundle->name);
  766. return;
  767. }
  768. }
  769. break;
  770. }
  771. compatible_pipes =
  772. BUNDLE_TEMPLATE_MASK(current_bundle[0].opcode->pipes,
  773. current_bundle[1].opcode->pipes,
  774. (current_bundle_index == 3
  775. ? current_bundle[2].opcode->pipes
  776. : (1 << NO_PIPELINE)));
  777. /* Find a template that works, if any. */
  778. match = NULL;
  779. for (i = 0; i < sizeof bundle_templates / sizeof bundle_templates[0]; i++)
  780. {
  781. const struct bundle_template *b = &bundle_templates[i];
  782. if ((b->pipe_mask & compatible_pipes) == b->pipe_mask)
  783. {
  784. match = b;
  785. break;
  786. }
  787. }
  788. if (match == NULL)
  789. {
  790. current_bundle_index = 0;
  791. as_bad (_("Invalid combination of instructions for bundle."));
  792. return;
  793. }
  794. /* If the section seems to have no alignment set yet, go ahead and
  795. make it large enough to hold code. */
  796. if (bfd_get_section_alignment (stdoutput, now_seg) == 0)
  797. bfd_set_section_alignment (stdoutput, now_seg,
  798. TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES);
  799. for (j = 0; j < current_bundle_index; j++)
  800. current_bundle[j].pipe = match->pipe[j];
  801. if (current_bundle_index == 2 && !tilegx_is_x_pipeline (match->pipe[0]))
  802. {
  803. /* We are in Y mode with only two instructions, so add an FNOP. */
  804. prepend_nop_to_bundle (TILEGX_OPC_FNOP);
  805. /* Figure out what pipe the fnop must be in via arithmetic.
  806. * p0 + p1 + p2 must sum to the sum of TILEGX_PIPELINE_Y[012]. */
  807. current_bundle[0].pipe =
  808. (tilegx_pipeline)((TILEGX_PIPELINE_Y0
  809. + TILEGX_PIPELINE_Y1
  810. + TILEGX_PIPELINE_Y2) -
  811. (current_bundle[1].pipe + current_bundle[2].pipe));
  812. }
  813. check_illegal_reg_writes ();
  814. f = frag_more (TILEGX_BUNDLE_SIZE_IN_BYTES);
  815. /* Check to see if this bundle is at an offset that is a multiple of 8-bytes
  816. from the start of the frag. */
  817. addr_mod = frag_now_fix () & (TILEGX_BUNDLE_ALIGNMENT_IN_BYTES - 1);
  818. if (frag_now->has_code && frag_now->insn_addr != addr_mod)
  819. as_bad (_("instruction address is not a multiple of 8"));
  820. frag_now->insn_addr = addr_mod;
  821. frag_now->has_code = 1;
  822. tilegx_bundle_bits bits = 0;
  823. for (j = 0; j < current_bundle_index; j++)
  824. {
  825. struct tilegx_instruction *instr = &current_bundle[j];
  826. tilegx_pipeline pipeline = instr->pipe;
  827. const struct tilegx_opcode *opcode = instr->opcode;
  828. bits |= emit_tilegx_instruction (opcode->fixed_bit_values[pipeline],
  829. opcode->num_operands,
  830. &opcode->operands[pipeline][0],
  831. instr->operand_values,
  832. f);
  833. }
  834. number_to_chars_littleendian (f, bits, 8);
  835. current_bundle_index = 0;
  836. /* Emit DWARF2 debugging information. */
  837. dwarf2_emit_insn (TILEGX_BUNDLE_SIZE_IN_BYTES);
  838. }
  839. /* Extend the expression parser to handle hw0(label), etc.
  840. as well as SPR names when in the context of parsing an SPR. */
  841. int
  842. tilegx_parse_name (char *name, expressionS *e, char *nextcharP)
  843. {
  844. operatorT op = O_illegal;
  845. if (parsing_spr)
  846. {
  847. void* val = hash_find (spr_hash, name);
  848. if (val == NULL)
  849. return 0;
  850. memset (e, 0, sizeof *e);
  851. e->X_op = O_constant;
  852. e->X_add_number = ((const struct tilegx_spr *)val)->number;
  853. return 1;
  854. }
  855. if (*nextcharP != '(')
  856. {
  857. /* hw0, etc. not followed by a paren is just a label with that name. */
  858. return 0;
  859. }
  860. else
  861. {
  862. /* Look up the operator in our table. */
  863. void* val = hash_find (special_operator_hash, name);
  864. if (val == 0)
  865. return 0;
  866. op = (operatorT)(long)val;
  867. }
  868. /* Restore old '(' and skip it. */
  869. *input_line_pointer = '(';
  870. ++input_line_pointer;
  871. expression (e);
  872. if (*input_line_pointer != ')')
  873. {
  874. as_bad (_("Missing ')'"));
  875. *nextcharP = *input_line_pointer;
  876. return 0;
  877. }
  878. /* Skip ')'. */
  879. ++input_line_pointer;
  880. if (e->X_op == O_register || e->X_op == O_absent)
  881. {
  882. as_bad (_("Invalid expression."));
  883. e->X_op = O_constant;
  884. e->X_add_number = 0;
  885. }
  886. else
  887. {
  888. /* Wrap subexpression with a unary operator. */
  889. symbolS *sym = make_expr_symbol (e);
  890. if (sym != e->X_add_symbol)
  891. {
  892. /* HACK: mark this symbol as a temporary wrapper around a proper
  893. expression, so we can unwrap it later once we have communicated
  894. the relocation type. */
  895. sym->sy_value.X_md = 1;
  896. }
  897. memset (e, 0, sizeof *e);
  898. e->X_op = op;
  899. e->X_add_symbol = sym;
  900. e->X_add_number = 0;
  901. }
  902. *nextcharP = *input_line_pointer;
  903. return 1;
  904. }
  905. /* Parses an expression which must be a register name. */
  906. static void
  907. parse_reg_expression (expressionS* expression)
  908. {
  909. char *regname;
  910. char terminating_char;
  911. void *pval;
  912. int regno_and_flags;
  913. int regno;
  914. /* Zero everything to make sure we don't miss any flags. */
  915. memset (expression, 0, sizeof *expression);
  916. terminating_char = get_symbol_name (&regname);
  917. pval = hash_find (main_reg_hash, regname);
  918. if (pval == NULL)
  919. as_bad (_("Expected register, got '%s'."), regname);
  920. regno_and_flags = (int)(size_t)pval;
  921. regno = EXTRACT_REGNO(regno_and_flags);
  922. if ((regno_and_flags & NONCANONICAL_REG_NAME_FLAG)
  923. && require_canonical_reg_names)
  924. as_warn (_("Found use of non-canonical register name %s; "
  925. "use %s instead."),
  926. regname, tilegx_register_names[regno]);
  927. /* Restore the old character following the register name. */
  928. (void) restore_line_pointer (terminating_char);
  929. /* Fill in the expression fields to indicate it's a register. */
  930. expression->X_op = O_register;
  931. expression->X_add_number = regno;
  932. }
  933. /* Parses and type-checks comma-separated operands in input_line_pointer. */
  934. static void
  935. parse_operands (const char *opcode_name,
  936. const unsigned char *operands,
  937. int num_operands,
  938. expressionS *operand_values)
  939. {
  940. int i;
  941. memset (operand_values, 0, num_operands * sizeof operand_values[0]);
  942. SKIP_WHITESPACE ();
  943. for (i = 0; i < num_operands; i++)
  944. {
  945. tilegx_operand_type type = tilegx_operands[operands[i]].type;
  946. SKIP_WHITESPACE ();
  947. if (type == TILEGX_OP_TYPE_REGISTER)
  948. {
  949. parse_reg_expression (&operand_values[i]);
  950. }
  951. else if (*input_line_pointer == '}')
  952. {
  953. operand_values[i].X_op = O_absent;
  954. }
  955. else if (type == TILEGX_OP_TYPE_SPR)
  956. {
  957. /* Modify the expression parser to add SPRs to the namespace. */
  958. parsing_spr = 1;
  959. expression (&operand_values[i]);
  960. parsing_spr = 0;
  961. }
  962. else
  963. {
  964. expression (&operand_values[i]);
  965. }
  966. SKIP_WHITESPACE ();
  967. if (i + 1 < num_operands)
  968. {
  969. int separator = (unsigned char)*input_line_pointer++;
  970. if (is_end_of_line[separator] || (separator == '}'))
  971. {
  972. as_bad (_("Too few operands to '%s'."), opcode_name);
  973. return;
  974. }
  975. else if (separator != ',')
  976. {
  977. as_bad (_("Unexpected character '%c' after operand %d to %s."),
  978. (char)separator, i + 1, opcode_name);
  979. return;
  980. }
  981. }
  982. /* Arbitrarily use the first valid pipe to get the operand type,
  983. since they are all the same. */
  984. switch (tilegx_operands[operands[i]].type)
  985. {
  986. case TILEGX_OP_TYPE_REGISTER:
  987. /* Handled in parse_reg_expression already. */
  988. break;
  989. case TILEGX_OP_TYPE_SPR:
  990. /* Fall through */
  991. case TILEGX_OP_TYPE_IMMEDIATE:
  992. /* Fall through */
  993. case TILEGX_OP_TYPE_ADDRESS:
  994. if ( operand_values[i].X_op == O_register
  995. || operand_values[i].X_op == O_illegal
  996. || operand_values[i].X_op == O_absent)
  997. as_bad (_("Expected immediate expression"));
  998. break;
  999. default:
  1000. abort();
  1001. }
  1002. }
  1003. if (!is_end_of_line[(unsigned char)*input_line_pointer])
  1004. {
  1005. switch (*input_line_pointer)
  1006. {
  1007. case '}':
  1008. if (!inside_bundle)
  1009. as_bad (_("Found '}' when not bundling."));
  1010. ++input_line_pointer;
  1011. inside_bundle = 0;
  1012. demand_empty_rest_of_line ();
  1013. break;
  1014. case ',':
  1015. as_bad (_("Too many operands"));
  1016. break;
  1017. default:
  1018. /* Use default error for unrecognized garbage. */
  1019. demand_empty_rest_of_line ();
  1020. break;
  1021. }
  1022. }
  1023. }
  1024. /* This is the guts of the machine-dependent assembler. STR points to a
  1025. machine dependent instruction. This function is supposed to emit the
  1026. frags/bytes it assembles to. */
  1027. void
  1028. md_assemble (char *str)
  1029. {
  1030. char old_char;
  1031. size_t opname_len;
  1032. char *old_input_line_pointer;
  1033. const struct tilegx_opcode *op;
  1034. int first_pipe;
  1035. /* Split off the opcode and look it up. */
  1036. opname_len = strcspn (str, " {}");
  1037. old_char = str[opname_len];
  1038. str[opname_len] = '\0';
  1039. op = hash_find(op_hash, str);
  1040. str[opname_len] = old_char;
  1041. if (op == NULL)
  1042. {
  1043. as_bad (_("Unknown opcode `%.*s'."), (int)opname_len, str);
  1044. return;
  1045. }
  1046. /* Prepare to parse the operands. */
  1047. old_input_line_pointer = input_line_pointer;
  1048. input_line_pointer = str + opname_len;
  1049. SKIP_WHITESPACE ();
  1050. if (current_bundle_index == TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE)
  1051. {
  1052. as_bad (_("Too many instructions for bundle."));
  1053. tilegx_flush_bundle ();
  1054. }
  1055. /* Make sure we have room for the upcoming bundle before we
  1056. create any fixups. Otherwise if we have to switch to a new
  1057. frag the fixup dot_value fields will be wrong. */
  1058. frag_grow (TILEGX_BUNDLE_SIZE_IN_BYTES);
  1059. /* Find a valid pipe for this opcode. */
  1060. for (first_pipe = 0; (op->pipes & (1 << first_pipe)) == 0; first_pipe++)
  1061. ;
  1062. /* Call the function that assembles this instruction. */
  1063. current_bundle[current_bundle_index].opcode = op;
  1064. parse_operands (op->name,
  1065. &op->operands[first_pipe][0],
  1066. op->num_operands,
  1067. current_bundle[current_bundle_index].operand_values);
  1068. ++current_bundle_index;
  1069. /* Restore the saved value of input_line_pointer. */
  1070. input_line_pointer = old_input_line_pointer;
  1071. /* If we weren't inside curly braces, go ahead and emit
  1072. this lone instruction as a bundle right now. */
  1073. if (!inside_bundle)
  1074. tilegx_flush_bundle ();
  1075. }
  1076. static void
  1077. s_require_canonical_reg_names (int require)
  1078. {
  1079. demand_empty_rest_of_line ();
  1080. require_canonical_reg_names = require;
  1081. }
  1082. static void
  1083. s_allow_suspicious_bundles (int allow)
  1084. {
  1085. demand_empty_rest_of_line ();
  1086. allow_suspicious_bundles = allow;
  1087. }
  1088. const pseudo_typeS md_pseudo_table[] =
  1089. {
  1090. {"align", s_align_bytes, 0}, /* Defaulting is invalid (0). */
  1091. {"word", cons, 4},
  1092. {"require_canonical_reg_names", s_require_canonical_reg_names, 1 },
  1093. {"no_require_canonical_reg_names", s_require_canonical_reg_names, 0 },
  1094. {"allow_suspicious_bundles", s_allow_suspicious_bundles, 1 },
  1095. {"no_allow_suspicious_bundles", s_allow_suspicious_bundles, 0 },
  1096. { NULL, 0, 0 }
  1097. };
  1098. /* Equal to MAX_PRECISION in atof-ieee.c */
  1099. #define MAX_LITTLENUMS 6
  1100. void
  1101. md_number_to_chars (char * buf, valueT val, int n)
  1102. {
  1103. if (target_big_endian)
  1104. number_to_chars_bigendian (buf, val, n);
  1105. else
  1106. number_to_chars_littleendian (buf, val, n);
  1107. }
  1108. /* Turn the string pointed to by litP into a floating point constant
  1109. of type TYPE, and emit the appropriate bytes. The number of
  1110. LITTLENUMS emitted is stored in *SIZEP. An error message is
  1111. returned, or NULL on OK. */
  1112. char *
  1113. md_atof (int type, char *litP, int *sizeP)
  1114. {
  1115. int prec;
  1116. LITTLENUM_TYPE words[MAX_LITTLENUMS];
  1117. LITTLENUM_TYPE *wordP;
  1118. char *t;
  1119. switch (type)
  1120. {
  1121. case 'f':
  1122. case 'F':
  1123. prec = 2;
  1124. break;
  1125. case 'd':
  1126. case 'D':
  1127. prec = 4;
  1128. break;
  1129. default:
  1130. *sizeP = 0;
  1131. return _("Bad call to md_atof ()");
  1132. }
  1133. t = atof_ieee (input_line_pointer, type, words);
  1134. if (t)
  1135. input_line_pointer = t;
  1136. *sizeP = prec * sizeof (LITTLENUM_TYPE);
  1137. /* This loops outputs the LITTLENUMs in REVERSE order; in accord with
  1138. the bigendian 386. */
  1139. for (wordP = words + prec - 1; prec--;)
  1140. {
  1141. md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE));
  1142. litP += sizeof (LITTLENUM_TYPE);
  1143. }
  1144. return 0;
  1145. }
  1146. /* We have no need to default values of symbols. */
  1147. symbolS *
  1148. md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
  1149. {
  1150. return NULL;
  1151. }
  1152. void
  1153. tilegx_cons_fix_new (fragS *frag,
  1154. int where,
  1155. int nbytes,
  1156. expressionS *exp)
  1157. {
  1158. expressionS subexp;
  1159. bfd_reloc_code_real_type reloc = BFD_RELOC_NONE;
  1160. int no_overflow = 0;
  1161. fixS *fixP;
  1162. /* See if it's one of our special functions. */
  1163. switch (exp->X_op)
  1164. {
  1165. case O_hw0:
  1166. reloc = BFD_RELOC_TILEGX_HW0;
  1167. no_overflow = 1;
  1168. break;
  1169. case O_hw1:
  1170. reloc = BFD_RELOC_TILEGX_HW1;
  1171. no_overflow = 1;
  1172. break;
  1173. case O_hw2:
  1174. reloc = BFD_RELOC_TILEGX_HW2;
  1175. no_overflow = 1;
  1176. break;
  1177. case O_hw3:
  1178. reloc = BFD_RELOC_TILEGX_HW3;
  1179. no_overflow = 1;
  1180. break;
  1181. case O_hw0_last:
  1182. reloc = BFD_RELOC_TILEGX_HW0_LAST;
  1183. break;
  1184. case O_hw1_last:
  1185. reloc = BFD_RELOC_TILEGX_HW1_LAST;
  1186. break;
  1187. case O_hw2_last:
  1188. reloc = BFD_RELOC_TILEGX_HW2_LAST;
  1189. break;
  1190. default:
  1191. /* Do nothing. */
  1192. break;
  1193. }
  1194. if (reloc != BFD_RELOC_NONE)
  1195. {
  1196. if (nbytes != 2)
  1197. {
  1198. as_bad (_("This operator only produces two byte values."));
  1199. nbytes = 2;
  1200. }
  1201. memset (&subexp, 0, sizeof subexp);
  1202. subexp.X_op = O_symbol;
  1203. subexp.X_add_symbol = exp->X_add_symbol;
  1204. exp = &subexp;
  1205. }
  1206. else
  1207. {
  1208. switch (nbytes)
  1209. {
  1210. case 1:
  1211. reloc = BFD_RELOC_8;
  1212. break;
  1213. case 2:
  1214. reloc = BFD_RELOC_16;
  1215. break;
  1216. case 4:
  1217. reloc = BFD_RELOC_32;
  1218. break;
  1219. case 8:
  1220. reloc = BFD_RELOC_64;
  1221. break;
  1222. default:
  1223. as_bad (_("unsupported BFD relocation size %d"), nbytes);
  1224. reloc = BFD_RELOC_64;
  1225. break;
  1226. }
  1227. }
  1228. fixP = fix_new_exp (frag, where, nbytes, exp, 0, reloc);
  1229. fixP->tc_fix_data = NULL;
  1230. fixP->fx_no_overflow |= no_overflow;
  1231. }
  1232. void
  1233. md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
  1234. {
  1235. const struct tilegx_operand *operand;
  1236. valueT value = *valP;
  1237. operatorT special;
  1238. char *p;
  1239. /* Leave these for the linker. */
  1240. if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
  1241. || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
  1242. return;
  1243. if (fixP->fx_subsy != (symbolS *) NULL)
  1244. {
  1245. /* We can't actually support subtracting a symbol. */
  1246. as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
  1247. }
  1248. /* Correct relocation types for pc-relativeness. */
  1249. switch (fixP->fx_r_type)
  1250. {
  1251. #define FIX_PCREL(rtype) \
  1252. case rtype: \
  1253. if (fixP->fx_pcrel) \
  1254. fixP->fx_r_type = rtype##_PCREL; \
  1255. break; \
  1256. \
  1257. case rtype##_PCREL: \
  1258. if (!fixP->fx_pcrel) \
  1259. fixP->fx_r_type = rtype; \
  1260. break
  1261. #define FIX_PLT_PCREL(rtype) \
  1262. case rtype##_PLT_PCREL: \
  1263. if (!fixP->fx_pcrel) \
  1264. fixP->fx_r_type = rtype; \
  1265. \
  1266. break;
  1267. FIX_PCREL (BFD_RELOC_8);
  1268. FIX_PCREL (BFD_RELOC_16);
  1269. FIX_PCREL (BFD_RELOC_32);
  1270. FIX_PCREL (BFD_RELOC_64);
  1271. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0);
  1272. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0);
  1273. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1);
  1274. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1);
  1275. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2);
  1276. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2);
  1277. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW3);
  1278. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW3);
  1279. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST);
  1280. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST);
  1281. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST);
  1282. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST);
  1283. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST);
  1284. FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST);
  1285. FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0);
  1286. FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0);
  1287. FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1);
  1288. FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1);
  1289. FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST);
  1290. FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST);
  1291. FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST);
  1292. FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST);
  1293. #undef FIX_PCREL
  1294. default:
  1295. /* Do nothing */
  1296. break;
  1297. }
  1298. if (fixP->fx_addsy != NULL)
  1299. {
  1300. #ifdef OBJ_ELF
  1301. switch (fixP->fx_r_type)
  1302. {
  1303. case BFD_RELOC_TILEGX_IMM8_X0_TLS_ADD:
  1304. case BFD_RELOC_TILEGX_IMM8_X1_TLS_ADD:
  1305. case BFD_RELOC_TILEGX_IMM8_Y0_TLS_ADD:
  1306. case BFD_RELOC_TILEGX_IMM8_Y1_TLS_ADD:
  1307. case BFD_RELOC_TILEGX_IMM8_X0_TLS_GD_ADD:
  1308. case BFD_RELOC_TILEGX_IMM8_X1_TLS_GD_ADD:
  1309. case BFD_RELOC_TILEGX_IMM8_Y0_TLS_GD_ADD:
  1310. case BFD_RELOC_TILEGX_IMM8_Y1_TLS_GD_ADD:
  1311. case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_GD:
  1312. case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_GD:
  1313. case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  1314. case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  1315. case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  1316. case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  1317. case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE:
  1318. case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE:
  1319. case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  1320. case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  1321. case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  1322. case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  1323. case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_LE:
  1324. case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_LE:
  1325. case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  1326. case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  1327. case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  1328. case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  1329. case BFD_RELOC_TILEGX_TLS_GD_CALL:
  1330. case BFD_RELOC_TILEGX_TLS_IE_LOAD:
  1331. case BFD_RELOC_TILEGX_TLS_DTPMOD64:
  1332. case BFD_RELOC_TILEGX_TLS_DTPOFF64:
  1333. case BFD_RELOC_TILEGX_TLS_TPOFF64:
  1334. case BFD_RELOC_TILEGX_TLS_DTPMOD32:
  1335. case BFD_RELOC_TILEGX_TLS_DTPOFF32:
  1336. case BFD_RELOC_TILEGX_TLS_TPOFF32:
  1337. S_SET_THREAD_LOCAL (fixP->fx_addsy);
  1338. break;
  1339. default:
  1340. /* Do nothing */
  1341. break;
  1342. }
  1343. #endif
  1344. return;
  1345. }
  1346. /* Apply hw0, etc. */
  1347. special = O_illegal;
  1348. switch (fixP->fx_r_type)
  1349. {
  1350. case BFD_RELOC_TILEGX_HW0:
  1351. case BFD_RELOC_TILEGX_IMM16_X0_HW0:
  1352. case BFD_RELOC_TILEGX_IMM16_X1_HW0:
  1353. case BFD_RELOC_TILEGX_IMM16_X0_HW0_PCREL:
  1354. case BFD_RELOC_TILEGX_IMM16_X1_HW0_PCREL:
  1355. case BFD_RELOC_TILEGX_IMM16_X0_HW0_PLT_PCREL:
  1356. case BFD_RELOC_TILEGX_IMM16_X1_HW0_PLT_PCREL:
  1357. special = O_hw0;
  1358. break;
  1359. case BFD_RELOC_TILEGX_HW0_LAST:
  1360. case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST:
  1361. case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST:
  1362. case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_PCREL:
  1363. case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_PCREL:
  1364. case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
  1365. case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
  1366. special = O_hw0_last;
  1367. break;
  1368. case BFD_RELOC_TILEGX_HW1:
  1369. case BFD_RELOC_TILEGX_IMM16_X0_HW1:
  1370. case BFD_RELOC_TILEGX_IMM16_X1_HW1:
  1371. case BFD_RELOC_TILEGX_IMM16_X0_HW1_PCREL:
  1372. case BFD_RELOC_TILEGX_IMM16_X1_HW1_PCREL:
  1373. case BFD_RELOC_TILEGX_IMM16_X0_HW1_PLT_PCREL:
  1374. case BFD_RELOC_TILEGX_IMM16_X1_HW1_PLT_PCREL:
  1375. special = O_hw1;
  1376. break;
  1377. case BFD_RELOC_TILEGX_HW1_LAST:
  1378. case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST:
  1379. case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST:
  1380. case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_PCREL:
  1381. case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_PCREL:
  1382. case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
  1383. case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
  1384. special = O_hw1_last;
  1385. break;
  1386. case BFD_RELOC_TILEGX_HW2:
  1387. case BFD_RELOC_TILEGX_IMM16_X0_HW2:
  1388. case BFD_RELOC_TILEGX_IMM16_X1_HW2:
  1389. case BFD_RELOC_TILEGX_IMM16_X0_HW2_PCREL:
  1390. case BFD_RELOC_TILEGX_IMM16_X1_HW2_PCREL:
  1391. case BFD_RELOC_TILEGX_IMM16_X0_HW2_PLT_PCREL:
  1392. case BFD_RELOC_TILEGX_IMM16_X1_HW2_PLT_PCREL:
  1393. special = O_hw2;
  1394. break;
  1395. case BFD_RELOC_TILEGX_HW2_LAST:
  1396. case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST:
  1397. case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST:
  1398. case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_PCREL:
  1399. case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_PCREL:
  1400. case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
  1401. case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
  1402. special = O_hw2_last;
  1403. break;
  1404. case BFD_RELOC_TILEGX_HW3:
  1405. case BFD_RELOC_TILEGX_IMM16_X0_HW3:
  1406. case BFD_RELOC_TILEGX_IMM16_X1_HW3:
  1407. case BFD_RELOC_TILEGX_IMM16_X0_HW3_PCREL:
  1408. case BFD_RELOC_TILEGX_IMM16_X1_HW3_PCREL:
  1409. case BFD_RELOC_TILEGX_IMM16_X0_HW3_PLT_PCREL:
  1410. case BFD_RELOC_TILEGX_IMM16_X1_HW3_PLT_PCREL:
  1411. special = O_hw3;
  1412. break;
  1413. default:
  1414. /* Do nothing */
  1415. break;
  1416. }
  1417. if (special != O_illegal)
  1418. {
  1419. *valP = value = apply_special_operator (special, value,
  1420. fixP->fx_file, fixP->fx_line);
  1421. }
  1422. p = fixP->fx_frag->fr_literal + fixP->fx_where;
  1423. operand = fixP->tc_fix_data;
  1424. if (operand != NULL)
  1425. {
  1426. /* It's an instruction operand. */
  1427. tilegx_bundle_bits bits =
  1428. insert_operand (0, operand, value, fixP->fx_file, fixP->fx_line);
  1429. /* Note that we might either be writing out bits for a bundle
  1430. or a static network instruction, which are different sizes, so it's
  1431. important to stop touching memory once we run out of bits.
  1432. ORing in values is OK since we know the existing bits for
  1433. this operand are zero. */
  1434. for (; bits != 0; bits >>= 8)
  1435. *p++ |= (char)bits;
  1436. }
  1437. else
  1438. {
  1439. /* Some other kind of relocation. */
  1440. switch (fixP->fx_r_type)
  1441. {
  1442. case BFD_RELOC_8:
  1443. case BFD_RELOC_8_PCREL:
  1444. md_number_to_chars (p, value, 1);
  1445. break;
  1446. case BFD_RELOC_16:
  1447. case BFD_RELOC_16_PCREL:
  1448. md_number_to_chars (p, value, 2);
  1449. break;
  1450. case BFD_RELOC_32:
  1451. case BFD_RELOC_32_PCREL:
  1452. md_number_to_chars (p, value, 4);
  1453. break;
  1454. case BFD_RELOC_64:
  1455. case BFD_RELOC_64_PCREL:
  1456. md_number_to_chars (p, value, 8);
  1457. break;
  1458. default:
  1459. /* Leave it for the linker. */
  1460. return;
  1461. }
  1462. }
  1463. fixP->fx_done = 1;
  1464. }
  1465. /* Generate the BFD reloc to be stuck in the object file from the
  1466. fixup used internally in the assembler. */
  1467. arelent *
  1468. tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixp)
  1469. {
  1470. arelent *reloc;
  1471. reloc = (arelent *) xmalloc (sizeof (arelent));
  1472. reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
  1473. *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  1474. reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1475. /* Make sure none of our internal relocations make it this far.
  1476. They'd better have been fully resolved by this point. */
  1477. gas_assert ((int) fixp->fx_r_type > 0);
  1478. reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
  1479. if (reloc->howto == NULL)
  1480. {
  1481. as_bad_where (fixp->fx_file, fixp->fx_line,
  1482. _("cannot represent `%s' relocation in object file"),
  1483. bfd_get_reloc_code_name (fixp->fx_r_type));
  1484. return NULL;
  1485. }
  1486. if (!fixp->fx_pcrel != !reloc->howto->pc_relative)
  1487. {
  1488. as_fatal (_("internal error? cannot generate `%s' relocation (%d, %d)"),
  1489. bfd_get_reloc_code_name (fixp->fx_r_type),
  1490. fixp->fx_pcrel, reloc->howto->pc_relative);
  1491. }
  1492. gas_assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
  1493. reloc->addend = fixp->fx_offset;
  1494. return reloc;
  1495. }
  1496. /* The location from which a PC relative jump should be calculated,
  1497. given a PC relative reloc. */
  1498. long
  1499. md_pcrel_from (fixS *fixP)
  1500. {
  1501. return fixP->fx_frag->fr_address + fixP->fx_where;
  1502. }
  1503. /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
  1504. a section symbol plus some offset. */
  1505. int
  1506. tilegx_fix_adjustable (fixS *fix)
  1507. {
  1508. /* Prevent all adjustments to global symbols */
  1509. if (S_IS_EXTERNAL (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
  1510. return 0;
  1511. return 1;
  1512. }
  1513. int
  1514. tilegx_unrecognized_line (int ch)
  1515. {
  1516. switch (ch)
  1517. {
  1518. case '{':
  1519. if (inside_bundle)
  1520. {
  1521. as_bad (_("Found '{' when already bundling."));
  1522. }
  1523. else
  1524. {
  1525. inside_bundle = 1;
  1526. current_bundle_index = 0;
  1527. }
  1528. return 1;
  1529. case '}':
  1530. if (!inside_bundle)
  1531. {
  1532. as_bad (_("Found '}' when not bundling."));
  1533. }
  1534. else
  1535. {
  1536. tilegx_flush_bundle ();
  1537. }
  1538. /* Allow '{' to follow on the same line. We also allow ";;", but that
  1539. happens automatically because ';' is an end of line marker. */
  1540. SKIP_WHITESPACE ();
  1541. if (input_line_pointer[0] == '{')
  1542. {
  1543. input_line_pointer++;
  1544. return tilegx_unrecognized_line ('{');
  1545. }
  1546. demand_empty_rest_of_line ();
  1547. return 1;
  1548. default:
  1549. break;
  1550. }
  1551. /* Not a valid line. */
  1552. return 0;
  1553. }
  1554. /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
  1555. of an rs_align_code fragment. */
  1556. void
  1557. tilegx_handle_align (fragS *fragp)
  1558. {
  1559. addressT bytes, fix;
  1560. char *p;
  1561. if (fragp->fr_type != rs_align_code)
  1562. return;
  1563. bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
  1564. p = fragp->fr_literal + fragp->fr_fix;
  1565. fix = 0;
  1566. /* Determine the bits for NOP. */
  1567. const struct tilegx_opcode *nop_opcode =
  1568. &tilegx_opcodes[TILEGX_OPC_NOP];
  1569. tilegx_bundle_bits nop =
  1570. ( nop_opcode->fixed_bit_values[TILEGX_PIPELINE_X0]
  1571. | nop_opcode->fixed_bit_values[TILEGX_PIPELINE_X1]);
  1572. if ((bytes & (TILEGX_BUNDLE_SIZE_IN_BYTES - 1)) != 0)
  1573. {
  1574. fix = bytes & (TILEGX_BUNDLE_SIZE_IN_BYTES - 1);
  1575. memset (p, 0, fix);
  1576. p += fix;
  1577. bytes -= fix;
  1578. }
  1579. number_to_chars_littleendian (p, nop, 8);
  1580. fragp->fr_fix += fix;
  1581. fragp->fr_var = TILEGX_BUNDLE_SIZE_IN_BYTES;
  1582. }
  1583. /* Standard calling conventions leave the CFA at SP on entry. */
  1584. void
  1585. tilegx_cfi_frame_initial_instructions (void)
  1586. {
  1587. cfi_add_CFA_def_cfa_register (54);
  1588. }
  1589. int
  1590. tc_tilegx_regname_to_dw2regnum (char *regname)
  1591. {
  1592. int i;
  1593. for (i = 0; i < TILEGX_NUM_REGISTERS; i++)
  1594. {
  1595. if (!strcmp (regname, tilegx_register_names[i]))
  1596. return i;
  1597. }
  1598. return -1;
  1599. }