tc-frv.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832
  1. /* tc-frv.c -- Assembler for the Fujitsu FRV.
  2. Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS 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, or (at your option)
  7. any later version.
  8. GAS 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 GAS; see the file COPYING. If not, write to
  14. the Free Software Foundation, 51 Franklin Street - Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. #include "as.h"
  17. #include "subsegs.h"
  18. #include "symcat.h"
  19. #include "opcodes/frv-desc.h"
  20. #include "opcodes/frv-opc.h"
  21. #include "cgen.h"
  22. #include "elf/common.h"
  23. #include "elf/frv.h"
  24. #include "dwarf2dbg.h"
  25. /* Structure to hold all of the different components describing
  26. an individual instruction. */
  27. typedef struct
  28. {
  29. const CGEN_INSN * insn;
  30. const CGEN_INSN * orig_insn;
  31. CGEN_FIELDS fields;
  32. #if CGEN_INT_INSN_P
  33. CGEN_INSN_INT buffer [1];
  34. #define INSN_VALUE(buf) (*(buf))
  35. #else
  36. unsigned char buffer [CGEN_MAX_INSN_SIZE];
  37. #define INSN_VALUE(buf) (buf)
  38. #endif
  39. char * addr;
  40. fragS * frag;
  41. int num_fixups;
  42. fixS * fixups [GAS_CGEN_MAX_FIXUPS];
  43. int indices [MAX_OPERAND_INSTANCES];
  44. }
  45. frv_insn;
  46. enum vliw_insn_type
  47. {
  48. VLIW_GENERIC_TYPE, /* Don't care about this insn. */
  49. VLIW_BRANCH_TYPE, /* A Branch. */
  50. VLIW_LABEL_TYPE, /* A Label. */
  51. VLIW_NOP_TYPE, /* A NOP. */
  52. VLIW_BRANCH_HAS_NOPS /* A Branch that requires NOPS. */
  53. };
  54. /* We're going to use these in the fr_subtype field to mark
  55. whether to keep inserted nops. */
  56. #define NOP_KEEP 1 /* Keep these NOPS. */
  57. #define NOP_DELETE 2 /* Delete these NOPS. */
  58. #define DO_COUNT true
  59. #define DONT_COUNT false
  60. /* A list of insns within a VLIW insn. */
  61. struct vliw_insn_list
  62. {
  63. /* The type of this insn. */
  64. enum vliw_insn_type type;
  65. /* The corresponding gas insn information. */
  66. const CGEN_INSN *insn;
  67. /* For branches and labels, the symbol that is referenced. */
  68. symbolS *sym;
  69. /* For branches, the frag containing the single nop that was generated. */
  70. fragS *snop_frag;
  71. /* For branches, the frag containing the double nop that was generated. */
  72. fragS *dnop_frag;
  73. /* Pointer to raw data for this insn. */
  74. char *address;
  75. /* Next insn in list. */
  76. struct vliw_insn_list *next;
  77. };
  78. static struct vliw_insn_list single_nop_insn = {
  79. VLIW_NOP_TYPE, NULL, NULL, NULL, NULL, NULL, NULL };
  80. static struct vliw_insn_list double_nop_insn = {
  81. VLIW_NOP_TYPE, NULL, NULL, NULL, NULL, NULL, NULL };
  82. struct vliw_chain
  83. {
  84. int num;
  85. int insn_count;
  86. struct vliw_insn_list *insn_list;
  87. struct vliw_chain *next;
  88. };
  89. static struct vliw_chain *vliw_chain_top;
  90. static struct vliw_chain *current_vliw_chain;
  91. static struct vliw_chain *previous_vliw_chain;
  92. static struct vliw_insn_list *current_vliw_insn;
  93. const char comment_chars[] = ";";
  94. const char line_comment_chars[] = "#";
  95. const char line_separator_chars[] = "!";
  96. const char EXP_CHARS[] = "eE";
  97. const char FLT_CHARS[] = "dD";
  98. static FRV_VLIW vliw;
  99. /* Default machine */
  100. #ifdef DEFAULT_CPU_FRV
  101. #define DEFAULT_MACHINE bfd_mach_frv
  102. #define DEFAULT_FLAGS EF_FRV_CPU_GENERIC
  103. #else
  104. #ifdef DEFAULT_CPU_FR300
  105. #define DEFAULT_MACHINE bfd_mach_fr300
  106. #define DEFAULT_FLAGS EF_FRV_CPU_FR300
  107. #else
  108. #ifdef DEFAULT_CPU_SIMPLE
  109. #define DEFAULT_MACHINE bfd_mach_frvsimple
  110. #define DEFAULT_FLAGS EF_FRV_CPU_SIMPLE
  111. #else
  112. #ifdef DEFAULT_CPU_TOMCAT
  113. #define DEFAULT_MACHINE bfd_mach_frvtomcat
  114. #define DEFAULT_FLAGS EF_FRV_CPU_TOMCAT
  115. #else
  116. #ifdef DEFAULT_CPU_FR400
  117. #define DEFAULT_MACHINE bfd_mach_fr400
  118. #define DEFAULT_FLAGS EF_FRV_CPU_FR400
  119. #else
  120. #ifdef DEFAULT_CPU_FR550
  121. #define DEFAULT_MACHINE bfd_mach_fr550
  122. #define DEFAULT_FLAGS EF_FRV_CPU_FR550
  123. #else
  124. #define DEFAULT_MACHINE bfd_mach_fr500
  125. #define DEFAULT_FLAGS EF_FRV_CPU_FR500
  126. #endif
  127. #endif
  128. #endif
  129. #endif
  130. #endif
  131. #endif
  132. #ifdef TE_LINUX
  133. # define DEFAULT_FDPIC EF_FRV_FDPIC
  134. #else
  135. # define DEFAULT_FDPIC 0
  136. #endif
  137. static unsigned long frv_mach = bfd_mach_frv;
  138. static bool fr400_audio;
  139. /* Flags to set in the elf header */
  140. static flagword frv_flags = DEFAULT_FLAGS | DEFAULT_FDPIC;
  141. static int frv_user_set_flags_p = 0;
  142. static int frv_pic_p = 0;
  143. static const char *frv_pic_flag = DEFAULT_FDPIC ? "-mfdpic" : (const char *)0;
  144. /* Print tomcat-specific debugging info. */
  145. static int tomcat_debug = 0;
  146. /* Tomcat-specific NOP statistics. */
  147. static int tomcat_stats = 0;
  148. static int tomcat_doubles = 0;
  149. static int tomcat_singles = 0;
  150. /* Forward reference to static functions */
  151. static void frv_set_flags (int);
  152. static void frv_pic_ptr (int);
  153. /* The target specific pseudo-ops which we support. */
  154. const pseudo_typeS md_pseudo_table[] =
  155. {
  156. { "eflags", frv_set_flags, 0 },
  157. { "word", cons, 4 },
  158. { "picptr", frv_pic_ptr, 4 },
  159. { NULL, NULL, 0 }
  160. };
  161. #define FRV_SHORTOPTS "G:"
  162. const char * md_shortopts = FRV_SHORTOPTS;
  163. #define OPTION_GPR_32 (OPTION_MD_BASE)
  164. #define OPTION_GPR_64 (OPTION_MD_BASE + 1)
  165. #define OPTION_FPR_32 (OPTION_MD_BASE + 2)
  166. #define OPTION_FPR_64 (OPTION_MD_BASE + 3)
  167. #define OPTION_SOFT_FLOAT (OPTION_MD_BASE + 4)
  168. #define OPTION_DWORD_YES (OPTION_MD_BASE + 5)
  169. #define OPTION_DWORD_NO (OPTION_MD_BASE + 6)
  170. #define OPTION_DOUBLE (OPTION_MD_BASE + 7)
  171. #define OPTION_NO_DOUBLE (OPTION_MD_BASE + 8)
  172. #define OPTION_MEDIA (OPTION_MD_BASE + 9)
  173. #define OPTION_NO_MEDIA (OPTION_MD_BASE + 10)
  174. #define OPTION_CPU (OPTION_MD_BASE + 11)
  175. #define OPTION_PIC (OPTION_MD_BASE + 12)
  176. #define OPTION_BIGPIC (OPTION_MD_BASE + 13)
  177. #define OPTION_LIBPIC (OPTION_MD_BASE + 14)
  178. #define OPTION_MULADD (OPTION_MD_BASE + 15)
  179. #define OPTION_NO_MULADD (OPTION_MD_BASE + 16)
  180. #define OPTION_TOMCAT_DEBUG (OPTION_MD_BASE + 17)
  181. #define OPTION_TOMCAT_STATS (OPTION_MD_BASE + 18)
  182. #define OPTION_PACK (OPTION_MD_BASE + 19)
  183. #define OPTION_NO_PACK (OPTION_MD_BASE + 20)
  184. #define OPTION_FDPIC (OPTION_MD_BASE + 21)
  185. #define OPTION_NOPIC (OPTION_MD_BASE + 22)
  186. struct option md_longopts[] =
  187. {
  188. { "mgpr-32", no_argument, NULL, OPTION_GPR_32 },
  189. { "mgpr-64", no_argument, NULL, OPTION_GPR_64 },
  190. { "mfpr-32", no_argument, NULL, OPTION_FPR_32 },
  191. { "mfpr-64", no_argument, NULL, OPTION_FPR_64 },
  192. { "mhard-float", no_argument, NULL, OPTION_FPR_64 },
  193. { "msoft-float", no_argument, NULL, OPTION_SOFT_FLOAT },
  194. { "mdword", no_argument, NULL, OPTION_DWORD_YES },
  195. { "mno-dword", no_argument, NULL, OPTION_DWORD_NO },
  196. { "mdouble", no_argument, NULL, OPTION_DOUBLE },
  197. { "mno-double", no_argument, NULL, OPTION_NO_DOUBLE },
  198. { "mmedia", no_argument, NULL, OPTION_MEDIA },
  199. { "mno-media", no_argument, NULL, OPTION_NO_MEDIA },
  200. { "mcpu", required_argument, NULL, OPTION_CPU },
  201. { "mpic", no_argument, NULL, OPTION_PIC },
  202. { "mPIC", no_argument, NULL, OPTION_BIGPIC },
  203. { "mlibrary-pic", no_argument, NULL, OPTION_LIBPIC },
  204. { "mmuladd", no_argument, NULL, OPTION_MULADD },
  205. { "mno-muladd", no_argument, NULL, OPTION_NO_MULADD },
  206. { "mtomcat-debug", no_argument, NULL, OPTION_TOMCAT_DEBUG },
  207. { "mtomcat-stats", no_argument, NULL, OPTION_TOMCAT_STATS },
  208. { "mpack", no_argument, NULL, OPTION_PACK },
  209. { "mno-pack", no_argument, NULL, OPTION_NO_PACK },
  210. { "mfdpic", no_argument, NULL, OPTION_FDPIC },
  211. { "mnopic", no_argument, NULL, OPTION_NOPIC },
  212. { NULL, no_argument, NULL, 0 },
  213. };
  214. size_t md_longopts_size = sizeof (md_longopts);
  215. /* What value to give to bfd_set_gp_size. */
  216. static int g_switch_value = 8;
  217. int
  218. md_parse_option (int c, const char *arg)
  219. {
  220. switch (c)
  221. {
  222. default:
  223. return 0;
  224. case 'G':
  225. g_switch_value = atoi (arg);
  226. if (! g_switch_value)
  227. frv_flags |= EF_FRV_G0;
  228. break;
  229. case OPTION_GPR_32:
  230. frv_flags = (frv_flags & ~EF_FRV_GPR_MASK) | EF_FRV_GPR_32;
  231. break;
  232. case OPTION_GPR_64:
  233. frv_flags = (frv_flags & ~EF_FRV_GPR_MASK) | EF_FRV_GPR_64;
  234. break;
  235. case OPTION_FPR_32:
  236. frv_flags = (frv_flags & ~EF_FRV_FPR_MASK) | EF_FRV_FPR_32;
  237. break;
  238. case OPTION_FPR_64:
  239. frv_flags = (frv_flags & ~EF_FRV_FPR_MASK) | EF_FRV_FPR_64;
  240. break;
  241. case OPTION_SOFT_FLOAT:
  242. frv_flags = (frv_flags & ~EF_FRV_FPR_MASK) | EF_FRV_FPR_NONE;
  243. break;
  244. case OPTION_DWORD_YES:
  245. frv_flags = (frv_flags & ~EF_FRV_DWORD_MASK) | EF_FRV_DWORD_YES;
  246. break;
  247. case OPTION_DWORD_NO:
  248. frv_flags = (frv_flags & ~EF_FRV_DWORD_MASK) | EF_FRV_DWORD_NO;
  249. break;
  250. case OPTION_DOUBLE:
  251. frv_flags |= EF_FRV_DOUBLE;
  252. break;
  253. case OPTION_NO_DOUBLE:
  254. frv_flags &= ~EF_FRV_DOUBLE;
  255. break;
  256. case OPTION_MEDIA:
  257. frv_flags |= EF_FRV_MEDIA;
  258. break;
  259. case OPTION_NO_MEDIA:
  260. frv_flags &= ~EF_FRV_MEDIA;
  261. break;
  262. case OPTION_MULADD:
  263. frv_flags |= EF_FRV_MULADD;
  264. break;
  265. case OPTION_NO_MULADD:
  266. frv_flags &= ~EF_FRV_MULADD;
  267. break;
  268. case OPTION_PACK:
  269. frv_flags &= ~EF_FRV_NOPACK;
  270. break;
  271. case OPTION_NO_PACK:
  272. frv_flags |= EF_FRV_NOPACK;
  273. break;
  274. case OPTION_CPU:
  275. {
  276. const char *p;
  277. int cpu_flags = EF_FRV_CPU_GENERIC;
  278. /* Identify the processor type */
  279. p = arg;
  280. if (strcmp (p, "frv") == 0)
  281. {
  282. cpu_flags = EF_FRV_CPU_GENERIC;
  283. frv_mach = bfd_mach_frv;
  284. }
  285. else if (strcmp (p, "fr500") == 0)
  286. {
  287. cpu_flags = EF_FRV_CPU_FR500;
  288. frv_mach = bfd_mach_fr500;
  289. }
  290. else if (strcmp (p, "fr550") == 0)
  291. {
  292. cpu_flags = EF_FRV_CPU_FR550;
  293. frv_mach = bfd_mach_fr550;
  294. }
  295. else if (strcmp (p, "fr450") == 0)
  296. {
  297. cpu_flags = EF_FRV_CPU_FR450;
  298. frv_mach = bfd_mach_fr450;
  299. }
  300. else if (strcmp (p, "fr405") == 0)
  301. {
  302. cpu_flags = EF_FRV_CPU_FR405;
  303. frv_mach = bfd_mach_fr400;
  304. fr400_audio = true;
  305. }
  306. else if (strcmp (p, "fr400") == 0)
  307. {
  308. cpu_flags = EF_FRV_CPU_FR400;
  309. frv_mach = bfd_mach_fr400;
  310. fr400_audio = false;
  311. }
  312. else if (strcmp (p, "fr300") == 0)
  313. {
  314. cpu_flags = EF_FRV_CPU_FR300;
  315. frv_mach = bfd_mach_fr300;
  316. }
  317. else if (strcmp (p, "simple") == 0)
  318. {
  319. cpu_flags = EF_FRV_CPU_SIMPLE;
  320. frv_mach = bfd_mach_frvsimple;
  321. frv_flags |= EF_FRV_NOPACK;
  322. }
  323. else if (strcmp (p, "tomcat") == 0)
  324. {
  325. cpu_flags = EF_FRV_CPU_TOMCAT;
  326. frv_mach = bfd_mach_frvtomcat;
  327. }
  328. else
  329. {
  330. as_fatal (_("Unknown cpu -mcpu=%s"), arg);
  331. return 0;
  332. }
  333. frv_flags = (frv_flags & ~EF_FRV_CPU_MASK) | cpu_flags;
  334. }
  335. break;
  336. case OPTION_PIC:
  337. frv_flags |= EF_FRV_PIC;
  338. frv_pic_p = 1;
  339. frv_pic_flag = "-fpic";
  340. break;
  341. case OPTION_BIGPIC:
  342. frv_flags |= EF_FRV_BIGPIC;
  343. frv_pic_p = 1;
  344. frv_pic_flag = "-fPIC";
  345. break;
  346. case OPTION_LIBPIC:
  347. frv_flags |= (EF_FRV_LIBPIC | EF_FRV_G0);
  348. frv_pic_p = 1;
  349. frv_pic_flag = "-mlibrary-pic";
  350. g_switch_value = 0;
  351. break;
  352. case OPTION_FDPIC:
  353. frv_flags |= EF_FRV_FDPIC;
  354. frv_pic_flag = "-mfdpic";
  355. break;
  356. case OPTION_NOPIC:
  357. frv_flags &= ~(EF_FRV_FDPIC | EF_FRV_PIC
  358. | EF_FRV_BIGPIC | EF_FRV_LIBPIC);
  359. frv_pic_flag = 0;
  360. break;
  361. case OPTION_TOMCAT_DEBUG:
  362. tomcat_debug = 1;
  363. break;
  364. case OPTION_TOMCAT_STATS:
  365. tomcat_stats = 1;
  366. break;
  367. }
  368. return 1;
  369. }
  370. void
  371. md_show_usage (FILE * stream)
  372. {
  373. fprintf (stream, _("FRV specific command line options:\n"));
  374. fprintf (stream, _("-G n Put data <= n bytes in the small data area\n"));
  375. fprintf (stream, _("-mgpr-32 Mark generated file as only using 32 GPRs\n"));
  376. fprintf (stream, _("-mgpr-64 Mark generated file as using all 64 GPRs\n"));
  377. fprintf (stream, _("-mfpr-32 Mark generated file as only using 32 FPRs\n"));
  378. fprintf (stream, _("-mfpr-64 Mark generated file as using all 64 FPRs\n"));
  379. fprintf (stream, _("-msoft-float Mark generated file as using software FP\n"));
  380. fprintf (stream, _("-mdword Mark generated file as using a 8-byte stack alignment\n"));
  381. fprintf (stream, _("-mno-dword Mark generated file as using a 4-byte stack alignment\n"));
  382. fprintf (stream, _("-mdouble Mark generated file as using double precision FP insns\n"));
  383. fprintf (stream, _("-mmedia Mark generated file as using media insns\n"));
  384. fprintf (stream, _("-mmuladd Mark generated file as using multiply add/subtract insns\n"));
  385. fprintf (stream, _("-mpack Allow instructions to be packed\n"));
  386. fprintf (stream, _("-mno-pack Do not allow instructions to be packed\n"));
  387. fprintf (stream, _("-mpic Mark generated file as using small position independent code\n"));
  388. fprintf (stream, _("-mPIC Mark generated file as using large position independent code\n"));
  389. fprintf (stream, _("-mlibrary-pic Mark generated file as using position independent code for libraries\n"));
  390. fprintf (stream, _("-mfdpic Assemble for the FDPIC ABI\n"));
  391. fprintf (stream, _("-mnopic Disable -mpic, -mPIC, -mlibrary-pic and -mfdpic\n"));
  392. fprintf (stream, _("-mcpu={fr500|fr550|fr400|fr405|fr450|fr300|frv|simple|tomcat}\n"));
  393. fprintf (stream, _(" Record the cpu type\n"));
  394. fprintf (stream, _("-mtomcat-stats Print out stats for tomcat workarounds\n"));
  395. fprintf (stream, _("-mtomcat-debug Debug tomcat workarounds\n"));
  396. }
  397. void
  398. md_begin (void)
  399. {
  400. /* Initialize the `cgen' interface. */
  401. /* Set the machine number and endian. */
  402. gas_cgen_cpu_desc = frv_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0,
  403. CGEN_CPU_OPEN_ENDIAN,
  404. CGEN_ENDIAN_BIG,
  405. CGEN_CPU_OPEN_END);
  406. frv_cgen_init_asm (gas_cgen_cpu_desc);
  407. /* This is a callback from cgen to gas to parse operands. */
  408. cgen_set_parse_operand_fn (gas_cgen_cpu_desc, gas_cgen_parse_operand);
  409. /* Set the ELF flags if desired. */
  410. if (frv_flags)
  411. bfd_set_private_flags (stdoutput, frv_flags);
  412. /* Set the machine type */
  413. bfd_default_set_arch_mach (stdoutput, bfd_arch_frv, frv_mach);
  414. /* Set up gp size so we can put local common items in .sbss */
  415. bfd_set_gp_size (stdoutput, g_switch_value);
  416. frv_vliw_reset (& vliw, frv_mach, frv_flags);
  417. }
  418. bool
  419. frv_md_fdpic_enabled (void)
  420. {
  421. return (frv_flags & EF_FRV_FDPIC) != 0;
  422. }
  423. int chain_num = 0;
  424. static struct vliw_insn_list *
  425. frv_insert_vliw_insn (bool count)
  426. {
  427. struct vliw_insn_list *vliw_insn_list_entry;
  428. struct vliw_chain *vliw_chain_entry;
  429. if (current_vliw_chain == NULL)
  430. {
  431. vliw_chain_entry = XNEW (struct vliw_chain);
  432. vliw_chain_entry->insn_count = 0;
  433. vliw_chain_entry->insn_list = NULL;
  434. vliw_chain_entry->next = NULL;
  435. vliw_chain_entry->num = chain_num++;
  436. if (!vliw_chain_top)
  437. vliw_chain_top = vliw_chain_entry;
  438. current_vliw_chain = vliw_chain_entry;
  439. if (previous_vliw_chain)
  440. previous_vliw_chain->next = vliw_chain_entry;
  441. }
  442. vliw_insn_list_entry = XNEW (struct vliw_insn_list);
  443. vliw_insn_list_entry->type = VLIW_GENERIC_TYPE;
  444. vliw_insn_list_entry->insn = NULL;
  445. vliw_insn_list_entry->sym = NULL;
  446. vliw_insn_list_entry->snop_frag = NULL;
  447. vliw_insn_list_entry->dnop_frag = NULL;
  448. vliw_insn_list_entry->next = NULL;
  449. if (count)
  450. current_vliw_chain->insn_count++;
  451. if (current_vliw_insn)
  452. current_vliw_insn->next = vliw_insn_list_entry;
  453. current_vliw_insn = vliw_insn_list_entry;
  454. if (!current_vliw_chain->insn_list)
  455. current_vliw_chain->insn_list = current_vliw_insn;
  456. return vliw_insn_list_entry;
  457. }
  458. /* Identify the following cases:
  459. 1) A VLIW insn that contains both a branch and the branch destination.
  460. This requires the insertion of two vliw instructions before the
  461. branch. The first consists of two nops. The second consists of
  462. a single nop.
  463. 2) A single instruction VLIW insn which is the destination of a branch
  464. that is in the next VLIW insn. This requires the insertion of a vliw
  465. insn containing two nops before the branch.
  466. 3) A double instruction VLIW insn which contains the destination of a
  467. branch that is in the next VLIW insn. This requires the insertion of
  468. a VLIW insn containing a single nop before the branch.
  469. 4) A single instruction VLIW insn which contains branch destination (x),
  470. followed by a single instruction VLIW insn which does not contain
  471. the branch to (x), followed by a VLIW insn which does contain the branch
  472. to (x). This requires the insertion of a VLIW insn containing a single
  473. nop before the VLIW instruction containing the branch.
  474. */
  475. #define FRV_IS_NOP(insn) (insn.buffer[0] == FRV_NOP_PACK || insn.buffer[0] == FRV_NOP_NOPACK)
  476. #define FRV_NOP_PACK 0x00880000 /* ori.p gr0,0,gr0 */
  477. #define FRV_NOP_NOPACK 0x80880000 /* ori gr0,0,gr0 */
  478. /* Check a vliw insn for an insn of type containing the sym passed in label_sym. */
  479. static struct vliw_insn_list *
  480. frv_find_in_vliw (enum vliw_insn_type vliw_insn_type,
  481. struct vliw_chain *this_chain,
  482. symbolS *label_sym)
  483. {
  484. struct vliw_insn_list *the_insn;
  485. if (!this_chain)
  486. return NULL;
  487. for (the_insn = this_chain->insn_list; the_insn; the_insn = the_insn->next)
  488. {
  489. if (the_insn->type == vliw_insn_type
  490. && the_insn->sym == label_sym)
  491. return the_insn;
  492. }
  493. return NULL;
  494. }
  495. enum vliw_nop_type
  496. {
  497. /* A Vliw insn containing a single nop insn. */
  498. VLIW_SINGLE_NOP,
  499. /* A Vliw insn containing two nop insns. */
  500. VLIW_DOUBLE_NOP,
  501. /* Two vliw insns. The first containing two nop insns.
  502. The second contain a single nop insn. */
  503. VLIW_DOUBLE_THEN_SINGLE_NOP
  504. };
  505. static void
  506. frv_debug_tomcat (struct vliw_chain *start_chain)
  507. {
  508. struct vliw_chain *this_chain;
  509. struct vliw_insn_list *this_insn;
  510. int i = 1;
  511. for (this_chain = start_chain; this_chain; this_chain = this_chain->next, i++)
  512. {
  513. fprintf (stderr, "\nVliw Insn #%d, #insns: %d\n", i, this_chain->insn_count);
  514. for (this_insn = this_chain->insn_list; this_insn; this_insn = this_insn->next)
  515. {
  516. if (this_insn->type == VLIW_LABEL_TYPE)
  517. fprintf (stderr, "Label Value: %p\n", this_insn->sym);
  518. else if (this_insn->type == VLIW_BRANCH_TYPE)
  519. fprintf (stderr, "%s to %p\n", this_insn->insn->base->name, this_insn->sym);
  520. else if (this_insn->type == VLIW_BRANCH_HAS_NOPS)
  521. fprintf (stderr, "nop'd %s to %p\n", this_insn->insn->base->name, this_insn->sym);
  522. else if (this_insn->type == VLIW_NOP_TYPE)
  523. fprintf (stderr, "Nop\n");
  524. else
  525. fprintf (stderr, " %s\n", this_insn->insn->base->name);
  526. }
  527. }
  528. }
  529. static void
  530. frv_adjust_vliw_count (struct vliw_chain *this_chain)
  531. {
  532. struct vliw_insn_list *this_insn;
  533. this_chain->insn_count = 0;
  534. for (this_insn = this_chain->insn_list;
  535. this_insn;
  536. this_insn = this_insn->next)
  537. {
  538. if (this_insn->type != VLIW_LABEL_TYPE)
  539. this_chain->insn_count++;
  540. }
  541. }
  542. /* Insert the desired nop combination in the vliw chain before insert_before_insn.
  543. Rechain the vliw insn. */
  544. static struct vliw_chain *
  545. frv_tomcat_shuffle (enum vliw_nop_type this_nop_type,
  546. struct vliw_chain *vliw_to_split,
  547. struct vliw_insn_list *insert_before_insn)
  548. {
  549. bool pack_prev = false;
  550. struct vliw_chain *return_me = NULL;
  551. struct vliw_insn_list *prev_insn = NULL;
  552. struct vliw_insn_list *curr_insn = vliw_to_split->insn_list;
  553. struct vliw_chain *double_nop = XNEW (struct vliw_chain);
  554. struct vliw_chain *single_nop = XNEW (struct vliw_chain);
  555. struct vliw_chain *second_part = XNEW (struct vliw_chain);
  556. struct vliw_chain *curr_vliw = vliw_chain_top;
  557. struct vliw_chain *prev_vliw = NULL;
  558. while (curr_insn && curr_insn != insert_before_insn)
  559. {
  560. /* We can't set the packing bit on a label. If we have the case
  561. label 1:
  562. label 2:
  563. label 3:
  564. branch that needs nops
  565. Then don't set pack bit later. */
  566. if (curr_insn->type != VLIW_LABEL_TYPE)
  567. pack_prev = true;
  568. prev_insn = curr_insn;
  569. curr_insn = curr_insn->next;
  570. }
  571. while (curr_vliw && curr_vliw != vliw_to_split)
  572. {
  573. prev_vliw = curr_vliw;
  574. curr_vliw = curr_vliw->next;
  575. }
  576. switch (this_nop_type)
  577. {
  578. case VLIW_SINGLE_NOP:
  579. if (!prev_insn)
  580. {
  581. /* Branch is first, Insert the NOP prior to this vliw insn. */
  582. if (prev_vliw)
  583. prev_vliw->next = single_nop;
  584. else
  585. vliw_chain_top = single_nop;
  586. single_nop->next = vliw_to_split;
  587. vliw_to_split->insn_list->type = VLIW_BRANCH_HAS_NOPS;
  588. return_me = vliw_to_split;
  589. }
  590. else
  591. {
  592. /* Set the packing bit on the previous insn. */
  593. if (pack_prev)
  594. {
  595. char *buffer = prev_insn->address;
  596. buffer[0] |= 0x80;
  597. }
  598. /* The branch is in the middle. Split this vliw insn into first
  599. and second parts. Insert the NOP between. */
  600. second_part->insn_list = insert_before_insn;
  601. second_part->insn_list->type = VLIW_BRANCH_HAS_NOPS;
  602. second_part->next = vliw_to_split->next;
  603. frv_adjust_vliw_count (second_part);
  604. single_nop->next = second_part;
  605. vliw_to_split->next = single_nop;
  606. prev_insn->next = NULL;
  607. return_me = second_part;
  608. frv_adjust_vliw_count (vliw_to_split);
  609. }
  610. break;
  611. case VLIW_DOUBLE_NOP:
  612. if (!prev_insn)
  613. {
  614. /* Branch is first, Insert the NOP prior to this vliw insn. */
  615. if (prev_vliw)
  616. prev_vliw->next = double_nop;
  617. else
  618. vliw_chain_top = double_nop;
  619. double_nop->next = vliw_to_split;
  620. return_me = vliw_to_split;
  621. vliw_to_split->insn_list->type = VLIW_BRANCH_HAS_NOPS;
  622. }
  623. else
  624. {
  625. /* Set the packing bit on the previous insn. */
  626. if (pack_prev)
  627. {
  628. char *buffer = prev_insn->address;
  629. buffer[0] |= 0x80;
  630. }
  631. /* The branch is in the middle. Split this vliw insn into first
  632. and second parts. Insert the NOP in between. */
  633. second_part->insn_list = insert_before_insn;
  634. second_part->insn_list->type = VLIW_BRANCH_HAS_NOPS;
  635. second_part->next = vliw_to_split->next;
  636. frv_adjust_vliw_count (second_part);
  637. double_nop->next = second_part;
  638. vliw_to_split->next = single_nop;
  639. prev_insn->next = NULL;
  640. frv_adjust_vliw_count (vliw_to_split);
  641. return_me = second_part;
  642. }
  643. break;
  644. case VLIW_DOUBLE_THEN_SINGLE_NOP:
  645. double_nop->next = single_nop;
  646. double_nop->insn_count = 2;
  647. double_nop->insn_list = &double_nop_insn;
  648. single_nop->insn_count = 1;
  649. single_nop->insn_list = &single_nop_insn;
  650. if (!prev_insn)
  651. {
  652. /* The branch is the first insn in this vliw. Don't split the vliw. Insert
  653. the nops prior to this vliw. */
  654. if (prev_vliw)
  655. prev_vliw->next = double_nop;
  656. else
  657. vliw_chain_top = double_nop;
  658. single_nop->next = vliw_to_split;
  659. return_me = vliw_to_split;
  660. vliw_to_split->insn_list->type = VLIW_BRANCH_HAS_NOPS;
  661. }
  662. else
  663. {
  664. /* Set the packing bit on the previous insn. */
  665. if (pack_prev)
  666. {
  667. char *buffer = prev_insn->address;
  668. buffer[0] |= 0x80;
  669. }
  670. /* The branch is in the middle of this vliw insn. Split into first and
  671. second parts. Insert the nop vliws in between. */
  672. second_part->insn_list = insert_before_insn;
  673. second_part->insn_list->type = VLIW_BRANCH_HAS_NOPS;
  674. second_part->next = vliw_to_split->next;
  675. frv_adjust_vliw_count (second_part);
  676. single_nop->next = second_part;
  677. vliw_to_split->next = double_nop;
  678. prev_insn->next = NULL;
  679. frv_adjust_vliw_count (vliw_to_split);
  680. return_me = second_part;
  681. }
  682. break;
  683. }
  684. return return_me;
  685. }
  686. static void
  687. frv_tomcat_analyze_vliw_chains (void)
  688. {
  689. struct vliw_chain *vliw1 = NULL;
  690. struct vliw_chain *vliw2 = NULL;
  691. struct vliw_chain *vliw3 = NULL;
  692. struct vliw_insn_list *this_insn = NULL;
  693. struct vliw_insn_list *temp_insn = NULL;
  694. /* We potentially need to look at three VLIW insns to determine if the
  695. workaround is required. Set them up. Ignore existing nops during analysis. */
  696. #define FRV_SET_VLIW_WINDOW(VLIW1, VLIW2, VLIW3) \
  697. if (VLIW1 && VLIW1->next) \
  698. VLIW2 = VLIW1->next; \
  699. else \
  700. VLIW2 = NULL; \
  701. if (VLIW2 && VLIW2->next) \
  702. VLIW3 = VLIW2->next; \
  703. else \
  704. VLIW3 = NULL
  705. vliw1 = vliw_chain_top;
  706. workaround_top:
  707. FRV_SET_VLIW_WINDOW (vliw1, vliw2, vliw3);
  708. if (!vliw1)
  709. return;
  710. if (vliw1->insn_count == 1)
  711. {
  712. /* check vliw1 for a label. */
  713. if (vliw1->insn_list->type == VLIW_LABEL_TYPE)
  714. {
  715. temp_insn = frv_find_in_vliw (VLIW_BRANCH_TYPE, vliw2, vliw1->insn_list->sym);
  716. if (temp_insn)
  717. {
  718. vliw1 = frv_tomcat_shuffle (VLIW_DOUBLE_NOP, vliw2, vliw1->insn_list);
  719. temp_insn->dnop_frag->fr_subtype = NOP_KEEP;
  720. vliw1 = vliw1->next;
  721. if (tomcat_stats)
  722. tomcat_doubles++;
  723. goto workaround_top;
  724. }
  725. else if (vliw2
  726. && vliw2->insn_count == 1
  727. && (temp_insn = frv_find_in_vliw (VLIW_BRANCH_TYPE, vliw3, vliw1->insn_list->sym)) != NULL)
  728. {
  729. temp_insn->snop_frag->fr_subtype = NOP_KEEP;
  730. vliw1 = frv_tomcat_shuffle (VLIW_SINGLE_NOP, vliw3, vliw3->insn_list);
  731. if (tomcat_stats)
  732. tomcat_singles++;
  733. goto workaround_top;
  734. }
  735. }
  736. }
  737. if (vliw1->insn_count == 2)
  738. {
  739. /* Check vliw1 for a label. */
  740. for (this_insn = vliw1->insn_list; this_insn; this_insn = this_insn->next)
  741. {
  742. if (this_insn->type == VLIW_LABEL_TYPE)
  743. {
  744. if ((temp_insn = frv_find_in_vliw (VLIW_BRANCH_TYPE, vliw2, this_insn->sym)) != NULL)
  745. {
  746. temp_insn->snop_frag->fr_subtype = NOP_KEEP;
  747. vliw1 = frv_tomcat_shuffle (VLIW_SINGLE_NOP, vliw2, this_insn);
  748. if (tomcat_stats)
  749. tomcat_singles++;
  750. }
  751. else
  752. vliw1 = vliw1->next;
  753. goto workaround_top;
  754. }
  755. }
  756. }
  757. /* Examine each insn in this VLIW. Look for the workaround criteria. */
  758. for (this_insn = vliw1->insn_list; this_insn; this_insn = this_insn->next)
  759. {
  760. /* Don't look at labels or nops. */
  761. while (this_insn
  762. && (this_insn->type == VLIW_LABEL_TYPE
  763. || this_insn->type == VLIW_NOP_TYPE
  764. || this_insn->type == VLIW_BRANCH_HAS_NOPS))
  765. this_insn = this_insn->next;
  766. if (!this_insn)
  767. {
  768. vliw1 = vliw2;
  769. goto workaround_top;
  770. }
  771. if (frv_is_branch_insn (this_insn->insn))
  772. {
  773. if ((temp_insn = frv_find_in_vliw (VLIW_LABEL_TYPE, vliw1, this_insn->sym)) != NULL)
  774. {
  775. /* Insert [nop/nop] [nop] before branch. */
  776. this_insn->snop_frag->fr_subtype = NOP_KEEP;
  777. this_insn->dnop_frag->fr_subtype = NOP_KEEP;
  778. vliw1 = frv_tomcat_shuffle (VLIW_DOUBLE_THEN_SINGLE_NOP, vliw1, this_insn);
  779. goto workaround_top;
  780. }
  781. }
  782. }
  783. /* This vliw insn checks out okay. Take a look at the next one. */
  784. vliw1 = vliw1->next;
  785. goto workaround_top;
  786. }
  787. void
  788. frv_tomcat_workaround (void)
  789. {
  790. if (frv_mach != bfd_mach_frvtomcat)
  791. return;
  792. if (tomcat_debug)
  793. frv_debug_tomcat (vliw_chain_top);
  794. frv_tomcat_analyze_vliw_chains ();
  795. if (tomcat_stats)
  796. {
  797. fprintf (stderr, "Inserted %d Single Nops\n", tomcat_singles);
  798. fprintf (stderr, "Inserted %d Double Nops\n", tomcat_doubles);
  799. }
  800. }
  801. static int
  802. fr550_check_insn_acc_range (frv_insn *insn, int low, int hi)
  803. {
  804. int acc;
  805. switch (CGEN_INSN_NUM (insn->insn))
  806. {
  807. case FRV_INSN_MADDACCS:
  808. case FRV_INSN_MSUBACCS:
  809. case FRV_INSN_MDADDACCS:
  810. case FRV_INSN_MDSUBACCS:
  811. case FRV_INSN_MASACCS:
  812. case FRV_INSN_MDASACCS:
  813. acc = insn->fields.f_ACC40Si;
  814. if (acc < low || acc > hi)
  815. return 1; /* out of range */
  816. acc = insn->fields.f_ACC40Sk;
  817. if (acc < low || acc > hi)
  818. return 1; /* out of range */
  819. break;
  820. case FRV_INSN_MMULHS:
  821. case FRV_INSN_MMULHU:
  822. case FRV_INSN_MMULXHS:
  823. case FRV_INSN_MMULXHU:
  824. case FRV_INSN_CMMULHS:
  825. case FRV_INSN_CMMULHU:
  826. case FRV_INSN_MQMULHS:
  827. case FRV_INSN_MQMULHU:
  828. case FRV_INSN_MQMULXHS:
  829. case FRV_INSN_MQMULXHU:
  830. case FRV_INSN_CMQMULHS:
  831. case FRV_INSN_CMQMULHU:
  832. case FRV_INSN_MMACHS:
  833. case FRV_INSN_MMRDHS:
  834. case FRV_INSN_CMMACHS:
  835. case FRV_INSN_MQMACHS:
  836. case FRV_INSN_CMQMACHS:
  837. case FRV_INSN_MQXMACHS:
  838. case FRV_INSN_MQXMACXHS:
  839. case FRV_INSN_MQMACXHS:
  840. case FRV_INSN_MCPXRS:
  841. case FRV_INSN_MCPXIS:
  842. case FRV_INSN_CMCPXRS:
  843. case FRV_INSN_CMCPXIS:
  844. case FRV_INSN_MQCPXRS:
  845. case FRV_INSN_MQCPXIS:
  846. acc = insn->fields.f_ACC40Sk;
  847. if (acc < low || acc > hi)
  848. return 1; /* out of range */
  849. break;
  850. case FRV_INSN_MMACHU:
  851. case FRV_INSN_MMRDHU:
  852. case FRV_INSN_CMMACHU:
  853. case FRV_INSN_MQMACHU:
  854. case FRV_INSN_CMQMACHU:
  855. case FRV_INSN_MCPXRU:
  856. case FRV_INSN_MCPXIU:
  857. case FRV_INSN_CMCPXRU:
  858. case FRV_INSN_CMCPXIU:
  859. case FRV_INSN_MQCPXRU:
  860. case FRV_INSN_MQCPXIU:
  861. acc = insn->fields.f_ACC40Uk;
  862. if (acc < low || acc > hi)
  863. return 1; /* out of range */
  864. break;
  865. default:
  866. break;
  867. }
  868. return 0; /* all is ok */
  869. }
  870. static int
  871. fr550_check_acc_range (FRV_VLIW *vlw, frv_insn *insn)
  872. {
  873. switch ((*vlw->current_vliw)[vlw->next_slot - 1])
  874. {
  875. case UNIT_FM0:
  876. case UNIT_FM2:
  877. return fr550_check_insn_acc_range (insn, 0, 3);
  878. case UNIT_FM1:
  879. case UNIT_FM3:
  880. return fr550_check_insn_acc_range (insn, 4, 7);
  881. default:
  882. break;
  883. }
  884. return 0; /* all is ok */
  885. }
  886. /* Return true if the target implements instruction INSN. */
  887. static bool
  888. target_implements_insn_p (const CGEN_INSN *insn)
  889. {
  890. switch (frv_mach)
  891. {
  892. default:
  893. /* bfd_mach_frv or generic. */
  894. return true;
  895. case bfd_mach_fr300:
  896. case bfd_mach_frvsimple:
  897. return CGEN_INSN_MACH_HAS_P (insn, MACH_SIMPLE);
  898. case bfd_mach_fr400:
  899. return ((fr400_audio || !CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_AUDIO))
  900. && CGEN_INSN_MACH_HAS_P (insn, MACH_FR400));
  901. case bfd_mach_fr450:
  902. return CGEN_INSN_MACH_HAS_P (insn, MACH_FR450);
  903. case bfd_mach_fr500:
  904. return CGEN_INSN_MACH_HAS_P (insn, MACH_FR500);
  905. case bfd_mach_fr550:
  906. return CGEN_INSN_MACH_HAS_P (insn, MACH_FR550);
  907. }
  908. }
  909. void
  910. md_assemble (char *str)
  911. {
  912. frv_insn insn;
  913. char *errmsg;
  914. int packing_constraint;
  915. finished_insnS finished_insn;
  916. fragS *double_nop_frag = NULL;
  917. fragS *single_nop_frag = NULL;
  918. struct vliw_insn_list *vliw_insn_list_entry = NULL;
  919. /* Initialize GAS's cgen interface for a new instruction. */
  920. gas_cgen_init_parse ();
  921. memset (&insn, 0, sizeof (insn));
  922. insn.insn = frv_cgen_assemble_insn
  923. (gas_cgen_cpu_desc, str, & insn.fields, insn.buffer, &errmsg);
  924. if (!insn.insn)
  925. {
  926. as_bad ("%s", errmsg);
  927. return;
  928. }
  929. /* If the cpu is tomcat, then we need to insert nops to workaround
  930. hardware limitations. We need to keep track of each vliw unit
  931. and examine the length of the unit and the individual insns
  932. within the unit to determine the number and location of the
  933. required nops. */
  934. if (frv_mach == bfd_mach_frvtomcat)
  935. {
  936. /* If we've just finished a VLIW insn OR this is a branch,
  937. then start up a new frag. Fill it with nops. We will get rid
  938. of those that are not required after we've seen all of the
  939. instructions but before we start resolving fixups. */
  940. if ( !FRV_IS_NOP (insn)
  941. && (frv_is_branch_insn (insn.insn) || insn.fields.f_pack))
  942. {
  943. char *buffer;
  944. frag_wane (frag_now);
  945. frag_new (0);
  946. double_nop_frag = frag_now;
  947. buffer = frag_var (rs_machine_dependent, 8, 8, NOP_DELETE, NULL, 0, 0);
  948. md_number_to_chars (buffer, FRV_NOP_PACK, 4);
  949. md_number_to_chars (buffer+4, FRV_NOP_NOPACK, 4);
  950. frag_wane (frag_now);
  951. frag_new (0);
  952. single_nop_frag = frag_now;
  953. buffer = frag_var (rs_machine_dependent, 4, 4, NOP_DELETE, NULL, 0, 0);
  954. md_number_to_chars (buffer, FRV_NOP_NOPACK, 4);
  955. }
  956. vliw_insn_list_entry = frv_insert_vliw_insn (DO_COUNT);
  957. vliw_insn_list_entry->insn = insn.insn;
  958. if (frv_is_branch_insn (insn.insn))
  959. vliw_insn_list_entry->type = VLIW_BRANCH_TYPE;
  960. if ( !FRV_IS_NOP (insn)
  961. && (frv_is_branch_insn (insn.insn) || insn.fields.f_pack))
  962. {
  963. vliw_insn_list_entry->snop_frag = single_nop_frag;
  964. vliw_insn_list_entry->dnop_frag = double_nop_frag;
  965. }
  966. }
  967. /* Make sure that this insn does not violate the VLIW packing constraints. */
  968. /* -mno-pack disallows any packing whatsoever. */
  969. if (frv_flags & EF_FRV_NOPACK)
  970. {
  971. if (! insn.fields.f_pack)
  972. {
  973. as_bad (_("VLIW packing used for -mno-pack"));
  974. return;
  975. }
  976. }
  977. /* -mcpu=FRV is an idealized FR-V implementation that supports all of the
  978. instructions, don't do vliw checking. */
  979. else if (frv_mach != bfd_mach_frv)
  980. {
  981. if (!target_implements_insn_p (insn.insn))
  982. {
  983. as_bad (_("Instruction not supported by this architecture"));
  984. return;
  985. }
  986. packing_constraint = frv_vliw_add_insn (& vliw, insn.insn);
  987. if (frv_mach == bfd_mach_fr550 && ! packing_constraint)
  988. packing_constraint = fr550_check_acc_range (& vliw, & insn);
  989. if (insn.fields.f_pack)
  990. frv_vliw_reset (& vliw, frv_mach, frv_flags);
  991. if (packing_constraint)
  992. {
  993. as_bad (_("VLIW packing constraint violation"));
  994. return;
  995. }
  996. }
  997. /* Doesn't really matter what we pass for RELAX_P here. */
  998. gas_cgen_finish_insn (insn.insn, insn.buffer,
  999. CGEN_FIELDS_BITSIZE (& insn.fields), 1, &finished_insn);
  1000. /* If the cpu is tomcat, then we need to insert nops to workaround
  1001. hardware limitations. We need to keep track of each vliw unit
  1002. and examine the length of the unit and the individual insns
  1003. within the unit to determine the number and location of the
  1004. required nops. */
  1005. if (frv_mach == bfd_mach_frvtomcat)
  1006. {
  1007. if (vliw_insn_list_entry)
  1008. vliw_insn_list_entry->address = finished_insn.addr;
  1009. else
  1010. abort();
  1011. if (insn.fields.f_pack)
  1012. {
  1013. /* We've completed a VLIW insn. */
  1014. previous_vliw_chain = current_vliw_chain;
  1015. current_vliw_chain = NULL;
  1016. current_vliw_insn = NULL;
  1017. }
  1018. }
  1019. }
  1020. /* The syntax in the manual says constants begin with '#'.
  1021. We just ignore it. */
  1022. void
  1023. md_operand (expressionS *expressionP)
  1024. {
  1025. if (* input_line_pointer == '#')
  1026. {
  1027. input_line_pointer ++;
  1028. expression (expressionP);
  1029. }
  1030. }
  1031. valueT
  1032. md_section_align (segT segment, valueT size)
  1033. {
  1034. int align = bfd_section_alignment (segment);
  1035. return ((size + (1 << align) - 1) & -(1 << align));
  1036. }
  1037. symbolS *
  1038. md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
  1039. {
  1040. return 0;
  1041. }
  1042. /* Interface to relax_segment. */
  1043. /* FIXME: Build table by hand, get it working, then machine generate. */
  1044. const relax_typeS md_relax_table[] =
  1045. {
  1046. {1, 1, 0, 0},
  1047. {511 - 2 - 2, -512 - 2 + 2, 0, 2 },
  1048. {0x2000000 - 1 - 2, -0x2000000 - 2, 2, 0 },
  1049. {0x2000000 - 1 - 2, -0x2000000 - 2, 4, 0 }
  1050. };
  1051. long
  1052. frv_relax_frag (fragS *fragP ATTRIBUTE_UNUSED, long stretch ATTRIBUTE_UNUSED)
  1053. {
  1054. return 0;
  1055. }
  1056. /* Return an initial guess of the length by which a fragment must grow to
  1057. hold a branch to reach its destination.
  1058. Also updates fr_type/fr_subtype as necessary.
  1059. Called just before doing relaxation.
  1060. Any symbol that is now undefined will not become defined.
  1061. The guess for fr_var is ACTUALLY the growth beyond fr_fix.
  1062. Whatever we do to grow fr_fix or fr_var contributes to our returned value.
  1063. Although it may not be explicit in the frag, pretend fr_var starts with a
  1064. 0 value. */
  1065. int
  1066. md_estimate_size_before_relax (fragS *fragP, segT segment ATTRIBUTE_UNUSED)
  1067. {
  1068. switch (fragP->fr_subtype)
  1069. {
  1070. case NOP_KEEP:
  1071. return fragP->fr_var;
  1072. default:
  1073. case NOP_DELETE:
  1074. return 0;
  1075. }
  1076. }
  1077. /* *fragP has been relaxed to its final size, and now needs to have
  1078. the bytes inside it modified to conform to the new size.
  1079. Called after relaxation is finished.
  1080. fragP->fr_type == rs_machine_dependent.
  1081. fragP->fr_subtype is the subtype of what the address relaxed to. */
  1082. void
  1083. md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
  1084. segT sec ATTRIBUTE_UNUSED,
  1085. fragS *fragP)
  1086. {
  1087. switch (fragP->fr_subtype)
  1088. {
  1089. default:
  1090. case NOP_DELETE:
  1091. return;
  1092. case NOP_KEEP:
  1093. fragP->fr_fix = fragP->fr_var;
  1094. fragP->fr_var = 0;
  1095. return;
  1096. }
  1097. }
  1098. /* Functions concerning relocs. */
  1099. /* The location from which a PC relative jump should be calculated,
  1100. given a PC relative reloc. */
  1101. long
  1102. md_pcrel_from_section (fixS *fixP, segT sec)
  1103. {
  1104. if (TC_FORCE_RELOCATION (fixP)
  1105. || (fixP->fx_addsy != (symbolS *) NULL
  1106. && S_GET_SEGMENT (fixP->fx_addsy) != sec))
  1107. {
  1108. /* If we can't adjust this relocation, or if it references a
  1109. local symbol in a different section (which
  1110. TC_FORCE_RELOCATION can't check), let the linker figure it
  1111. out. */
  1112. return 0;
  1113. }
  1114. return (fixP->fx_frag->fr_address + fixP->fx_where) & ~1;
  1115. }
  1116. /* Return the bfd reloc type for OPERAND of INSN at fixup FIXP.
  1117. Returns BFD_RELOC_NONE if no reloc type can be found.
  1118. *FIXP may be modified if desired. */
  1119. bfd_reloc_code_real_type
  1120. md_cgen_lookup_reloc (const CGEN_INSN *insn ATTRIBUTE_UNUSED,
  1121. const CGEN_OPERAND *operand,
  1122. fixS *fixP)
  1123. {
  1124. switch (operand->type)
  1125. {
  1126. case FRV_OPERAND_LABEL16:
  1127. fixP->fx_pcrel = true;
  1128. return BFD_RELOC_FRV_LABEL16;
  1129. case FRV_OPERAND_LABEL24:
  1130. fixP->fx_pcrel = true;
  1131. if (fixP->fx_cgen.opinfo != 0)
  1132. return fixP->fx_cgen.opinfo;
  1133. return BFD_RELOC_FRV_LABEL24;
  1134. case FRV_OPERAND_UHI16:
  1135. case FRV_OPERAND_ULO16:
  1136. case FRV_OPERAND_SLO16:
  1137. case FRV_OPERAND_CALLANN:
  1138. case FRV_OPERAND_LDANN:
  1139. case FRV_OPERAND_LDDANN:
  1140. /* The relocation type should be recorded in opinfo */
  1141. if (fixP->fx_cgen.opinfo != 0)
  1142. return fixP->fx_cgen.opinfo;
  1143. break;
  1144. case FRV_OPERAND_D12:
  1145. case FRV_OPERAND_S12:
  1146. if (fixP->fx_cgen.opinfo != 0)
  1147. return fixP->fx_cgen.opinfo;
  1148. return BFD_RELOC_FRV_GPREL12;
  1149. case FRV_OPERAND_U12:
  1150. return BFD_RELOC_FRV_GPRELU12;
  1151. default:
  1152. break;
  1153. }
  1154. return BFD_RELOC_NONE;
  1155. }
  1156. /* See whether we need to force a relocation into the output file.
  1157. This is used to force out switch and PC relative relocations when
  1158. relaxing. */
  1159. int
  1160. frv_force_relocation (fixS *fix)
  1161. {
  1162. switch (fix->fx_r_type < BFD_RELOC_UNUSED
  1163. ? (int) fix->fx_r_type
  1164. : fix->fx_cgen.opinfo)
  1165. {
  1166. case BFD_RELOC_FRV_GPREL12:
  1167. case BFD_RELOC_FRV_GPRELU12:
  1168. case BFD_RELOC_FRV_GPREL32:
  1169. case BFD_RELOC_FRV_GPRELHI:
  1170. case BFD_RELOC_FRV_GPRELLO:
  1171. case BFD_RELOC_FRV_GOT12:
  1172. case BFD_RELOC_FRV_GOTHI:
  1173. case BFD_RELOC_FRV_GOTLO:
  1174. case BFD_RELOC_FRV_FUNCDESC_VALUE:
  1175. case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
  1176. case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
  1177. case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
  1178. case BFD_RELOC_FRV_GOTOFF12:
  1179. case BFD_RELOC_FRV_GOTOFFHI:
  1180. case BFD_RELOC_FRV_GOTOFFLO:
  1181. case BFD_RELOC_FRV_GETTLSOFF:
  1182. case BFD_RELOC_FRV_TLSDESC_VALUE:
  1183. case BFD_RELOC_FRV_GOTTLSDESC12:
  1184. case BFD_RELOC_FRV_GOTTLSDESCHI:
  1185. case BFD_RELOC_FRV_GOTTLSDESCLO:
  1186. case BFD_RELOC_FRV_TLSMOFF12:
  1187. case BFD_RELOC_FRV_TLSMOFFHI:
  1188. case BFD_RELOC_FRV_TLSMOFFLO:
  1189. case BFD_RELOC_FRV_GOTTLSOFF12:
  1190. case BFD_RELOC_FRV_GOTTLSOFFHI:
  1191. case BFD_RELOC_FRV_GOTTLSOFFLO:
  1192. case BFD_RELOC_FRV_TLSOFF:
  1193. case BFD_RELOC_FRV_TLSDESC_RELAX:
  1194. case BFD_RELOC_FRV_GETTLSOFF_RELAX:
  1195. case BFD_RELOC_FRV_TLSOFF_RELAX:
  1196. return 1;
  1197. default:
  1198. break;
  1199. }
  1200. return generic_force_reloc (fix);
  1201. }
  1202. /* Apply a fixup that could be resolved within the assembler. */
  1203. void
  1204. md_apply_fix (fixS *fixP, valueT *valP, segT seg)
  1205. {
  1206. if (fixP->fx_addsy == 0)
  1207. switch (fixP->fx_cgen.opinfo)
  1208. {
  1209. case BFD_RELOC_FRV_HI16:
  1210. *valP >>= 16;
  1211. /* Fall through. */
  1212. case BFD_RELOC_FRV_LO16:
  1213. *valP &= 0xffff;
  1214. break;
  1215. /* We need relocations for these, even if their symbols reduce
  1216. to constants. */
  1217. case BFD_RELOC_FRV_GPREL12:
  1218. case BFD_RELOC_FRV_GPRELU12:
  1219. case BFD_RELOC_FRV_GPREL32:
  1220. case BFD_RELOC_FRV_GPRELHI:
  1221. case BFD_RELOC_FRV_GPRELLO:
  1222. case BFD_RELOC_FRV_GOT12:
  1223. case BFD_RELOC_FRV_GOTHI:
  1224. case BFD_RELOC_FRV_GOTLO:
  1225. case BFD_RELOC_FRV_FUNCDESC_VALUE:
  1226. case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
  1227. case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
  1228. case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
  1229. case BFD_RELOC_FRV_GOTOFF12:
  1230. case BFD_RELOC_FRV_GOTOFFHI:
  1231. case BFD_RELOC_FRV_GOTOFFLO:
  1232. case BFD_RELOC_FRV_GETTLSOFF:
  1233. case BFD_RELOC_FRV_TLSDESC_VALUE:
  1234. case BFD_RELOC_FRV_GOTTLSDESC12:
  1235. case BFD_RELOC_FRV_GOTTLSDESCHI:
  1236. case BFD_RELOC_FRV_GOTTLSDESCLO:
  1237. case BFD_RELOC_FRV_TLSMOFF12:
  1238. case BFD_RELOC_FRV_TLSMOFFHI:
  1239. case BFD_RELOC_FRV_TLSMOFFLO:
  1240. case BFD_RELOC_FRV_GOTTLSOFF12:
  1241. case BFD_RELOC_FRV_GOTTLSOFFHI:
  1242. case BFD_RELOC_FRV_GOTTLSOFFLO:
  1243. case BFD_RELOC_FRV_TLSOFF:
  1244. case BFD_RELOC_FRV_TLSDESC_RELAX:
  1245. case BFD_RELOC_FRV_GETTLSOFF_RELAX:
  1246. case BFD_RELOC_FRV_TLSOFF_RELAX:
  1247. fixP->fx_addsy = abs_section_sym;
  1248. break;
  1249. }
  1250. else
  1251. switch (fixP->fx_cgen.opinfo)
  1252. {
  1253. case BFD_RELOC_FRV_GETTLSOFF:
  1254. case BFD_RELOC_FRV_TLSDESC_VALUE:
  1255. case BFD_RELOC_FRV_GOTTLSDESC12:
  1256. case BFD_RELOC_FRV_GOTTLSDESCHI:
  1257. case BFD_RELOC_FRV_GOTTLSDESCLO:
  1258. case BFD_RELOC_FRV_TLSMOFF12:
  1259. case BFD_RELOC_FRV_TLSMOFFHI:
  1260. case BFD_RELOC_FRV_TLSMOFFLO:
  1261. case BFD_RELOC_FRV_GOTTLSOFF12:
  1262. case BFD_RELOC_FRV_GOTTLSOFFHI:
  1263. case BFD_RELOC_FRV_GOTTLSOFFLO:
  1264. case BFD_RELOC_FRV_TLSOFF:
  1265. case BFD_RELOC_FRV_TLSDESC_RELAX:
  1266. case BFD_RELOC_FRV_GETTLSOFF_RELAX:
  1267. case BFD_RELOC_FRV_TLSOFF_RELAX:
  1268. /* Mark TLS symbols as such. */
  1269. if (S_GET_SEGMENT (fixP->fx_addsy) != absolute_section)
  1270. S_SET_THREAD_LOCAL (fixP->fx_addsy);
  1271. break;
  1272. }
  1273. gas_cgen_md_apply_fix (fixP, valP, seg);
  1274. return;
  1275. }
  1276. /* Write a value out to the object file, using the appropriate endianness. */
  1277. void
  1278. frv_md_number_to_chars (char *buf, valueT val, int n)
  1279. {
  1280. number_to_chars_bigendian (buf, val, n);
  1281. }
  1282. const char *
  1283. md_atof (int type, char *litP, int *sizeP)
  1284. {
  1285. return ieee_md_atof (type, litP, sizeP, true);
  1286. }
  1287. bool
  1288. frv_fix_adjustable (fixS *fixP)
  1289. {
  1290. bfd_reloc_code_real_type reloc_type;
  1291. if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
  1292. {
  1293. const CGEN_INSN *insn = NULL;
  1294. int opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
  1295. const CGEN_OPERAND *operand = cgen_operand_lookup_by_num(gas_cgen_cpu_desc, opindex);
  1296. reloc_type = md_cgen_lookup_reloc (insn, operand, fixP);
  1297. }
  1298. else
  1299. reloc_type = fixP->fx_r_type;
  1300. /* We need the symbol name for the VTABLE entries */
  1301. if ( reloc_type == BFD_RELOC_VTABLE_INHERIT
  1302. || reloc_type == BFD_RELOC_VTABLE_ENTRY
  1303. || reloc_type == BFD_RELOC_FRV_GPREL12
  1304. || reloc_type == BFD_RELOC_FRV_GPRELU12)
  1305. return 0;
  1306. return 1;
  1307. }
  1308. /* Allow user to set flags bits. */
  1309. void
  1310. frv_set_flags (int arg ATTRIBUTE_UNUSED)
  1311. {
  1312. flagword new_flags = get_absolute_expression ();
  1313. flagword new_mask = ~ (flagword)0;
  1314. frv_user_set_flags_p = 1;
  1315. if (*input_line_pointer == ',')
  1316. {
  1317. ++input_line_pointer;
  1318. new_mask = get_absolute_expression ();
  1319. }
  1320. frv_flags = (frv_flags & ~new_mask) | (new_flags & new_mask);
  1321. bfd_set_private_flags (stdoutput, frv_flags);
  1322. }
  1323. /* Frv specific function to handle 4 byte initializations for pointers that are
  1324. considered 'safe' for use with pic support. Until frv_frob_file{,_section}
  1325. is run, we encode it a BFD_RELOC_CTOR, and it is turned back into a normal
  1326. BFD_RELOC_32 at that time. */
  1327. void
  1328. frv_pic_ptr (int nbytes)
  1329. {
  1330. expressionS exp;
  1331. char *p;
  1332. if (nbytes != 4)
  1333. abort ();
  1334. #ifdef md_flush_pending_output
  1335. md_flush_pending_output ();
  1336. #endif
  1337. if (is_it_end_of_statement ())
  1338. {
  1339. demand_empty_rest_of_line ();
  1340. return;
  1341. }
  1342. #ifdef md_cons_align
  1343. md_cons_align (nbytes);
  1344. #endif
  1345. do
  1346. {
  1347. bfd_reloc_code_real_type reloc_type = BFD_RELOC_CTOR;
  1348. if (strncasecmp (input_line_pointer, "funcdesc(", 9) == 0)
  1349. {
  1350. input_line_pointer += 9;
  1351. expression (&exp);
  1352. if (*input_line_pointer == ')')
  1353. input_line_pointer++;
  1354. else
  1355. as_bad (_("missing ')'"));
  1356. reloc_type = BFD_RELOC_FRV_FUNCDESC;
  1357. }
  1358. else if (strncasecmp (input_line_pointer, "tlsmoff(", 8) == 0)
  1359. {
  1360. input_line_pointer += 8;
  1361. expression (&exp);
  1362. if (*input_line_pointer == ')')
  1363. input_line_pointer++;
  1364. else
  1365. as_bad (_("missing ')'"));
  1366. reloc_type = BFD_RELOC_FRV_TLSMOFF;
  1367. }
  1368. else
  1369. expression (&exp);
  1370. p = frag_more (4);
  1371. memset (p, 0, 4);
  1372. fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
  1373. reloc_type);
  1374. }
  1375. while (*input_line_pointer++ == ',');
  1376. input_line_pointer--; /* Put terminator back into stream. */
  1377. demand_empty_rest_of_line ();
  1378. }
  1379. #ifdef DEBUG
  1380. #define DPRINTF1(A) fprintf (stderr, A)
  1381. #define DPRINTF2(A,B) fprintf (stderr, A, B)
  1382. #define DPRINTF3(A,B,C) fprintf (stderr, A, B, C)
  1383. #else
  1384. #define DPRINTF1(A)
  1385. #define DPRINTF2(A,B)
  1386. #define DPRINTF3(A,B,C)
  1387. #endif
  1388. /* Go through a the sections looking for relocations that are problematical for
  1389. pic. If not pic, just note that this object can't be linked with pic. If
  1390. it is pic, see if it needs to be marked so that it will be fixed up, or if
  1391. not possible, issue an error. */
  1392. static void
  1393. frv_frob_file_section (bfd *abfd, asection *sec, void *ptr ATTRIBUTE_UNUSED)
  1394. {
  1395. segment_info_type *seginfo = seg_info (sec);
  1396. fixS *fixp;
  1397. CGEN_CPU_DESC cd = gas_cgen_cpu_desc;
  1398. flagword flags = bfd_section_flags (sec);
  1399. /* Skip relocations in known sections (.ctors, .dtors, and .gcc_except_table)
  1400. since we can fix those up by hand. */
  1401. int known_section_p = (sec->name
  1402. && sec->name[0] == '.'
  1403. && ((sec->name[1] == 'c'
  1404. && strcmp (sec->name, ".ctor") == 0)
  1405. || (sec->name[1] == 'd'
  1406. && strcmp (sec->name, ".dtor") == 0)
  1407. || (sec->name[1] == 'g'
  1408. && strcmp (sec->name, ".gcc_except_table") == 0)));
  1409. DPRINTF3 ("\nFrv section %s%s\n", sec->name, (known_section_p) ? ", known section" : "");
  1410. if ((flags & SEC_ALLOC) == 0)
  1411. {
  1412. DPRINTF1 ("\tSkipping non-loaded section\n");
  1413. return;
  1414. }
  1415. for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
  1416. {
  1417. symbolS *s = fixp->fx_addsy;
  1418. bfd_reloc_code_real_type reloc;
  1419. int non_pic_p;
  1420. int opindex;
  1421. const CGEN_OPERAND *operand;
  1422. const CGEN_INSN *insn = fixp->fx_cgen.insn;
  1423. if (fixp->fx_done)
  1424. {
  1425. DPRINTF1 ("\tSkipping reloc that has already been done\n");
  1426. continue;
  1427. }
  1428. if (fixp->fx_pcrel)
  1429. {
  1430. DPRINTF1 ("\tSkipping reloc that is PC relative\n");
  1431. continue;
  1432. }
  1433. if (! s)
  1434. {
  1435. DPRINTF1 ("\tSkipping reloc without symbol\n");
  1436. continue;
  1437. }
  1438. if (fixp->fx_r_type < BFD_RELOC_UNUSED)
  1439. {
  1440. opindex = -1;
  1441. reloc = fixp->fx_r_type;
  1442. }
  1443. else
  1444. {
  1445. opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
  1446. operand = cgen_operand_lookup_by_num (cd, opindex);
  1447. reloc = md_cgen_lookup_reloc (insn, operand, fixp);
  1448. }
  1449. DPRINTF3 ("\treloc %s\t%s", bfd_get_reloc_code_name (reloc), S_GET_NAME (s));
  1450. non_pic_p = 0;
  1451. switch (reloc)
  1452. {
  1453. default:
  1454. break;
  1455. case BFD_RELOC_32:
  1456. /* Skip relocations in known sections (.ctors, .dtors, and
  1457. .gcc_except_table) since we can fix those up by hand. Also
  1458. skip forward references to constants. Also skip a difference
  1459. of two symbols, which still uses the BFD_RELOC_32 at this
  1460. point. */
  1461. if (! known_section_p
  1462. && S_GET_SEGMENT (s) != absolute_section
  1463. && !fixp->fx_subsy
  1464. && (flags & (SEC_READONLY | SEC_CODE)) == 0)
  1465. {
  1466. non_pic_p = 1;
  1467. }
  1468. break;
  1469. /* FIXME -- should determine if any of the GP relocation really uses
  1470. gr16 (which is not pic safe) or not. Right now, assume if we
  1471. aren't being compiled with -mpic, the usage is non pic safe, but
  1472. is safe with -mpic. */
  1473. case BFD_RELOC_FRV_GPREL12:
  1474. case BFD_RELOC_FRV_GPRELU12:
  1475. case BFD_RELOC_FRV_GPREL32:
  1476. case BFD_RELOC_FRV_GPRELHI:
  1477. case BFD_RELOC_FRV_GPRELLO:
  1478. non_pic_p = ! frv_pic_p;
  1479. break;
  1480. case BFD_RELOC_FRV_LO16:
  1481. case BFD_RELOC_FRV_HI16:
  1482. if (S_GET_SEGMENT (s) != absolute_section)
  1483. non_pic_p = 1;
  1484. break;
  1485. case BFD_RELOC_VTABLE_INHERIT:
  1486. case BFD_RELOC_VTABLE_ENTRY:
  1487. non_pic_p = 1;
  1488. break;
  1489. /* If this is a blessed BFD_RELOC_32, convert it back to the normal
  1490. relocation. */
  1491. case BFD_RELOC_CTOR:
  1492. fixp->fx_r_type = BFD_RELOC_32;
  1493. break;
  1494. }
  1495. if (non_pic_p)
  1496. {
  1497. DPRINTF1 (" (Non-pic relocation)\n");
  1498. if (frv_pic_p)
  1499. as_warn_where (fixp->fx_file, fixp->fx_line,
  1500. _("Relocation %s is not safe for %s"),
  1501. bfd_get_reloc_code_name (reloc), frv_pic_flag);
  1502. else if ((frv_flags & EF_FRV_NON_PIC_RELOCS) == 0)
  1503. {
  1504. frv_flags |= EF_FRV_NON_PIC_RELOCS;
  1505. bfd_set_private_flags (abfd, frv_flags);
  1506. }
  1507. }
  1508. #ifdef DEBUG
  1509. else
  1510. DPRINTF1 ("\n");
  1511. #endif
  1512. }
  1513. }
  1514. /* After all of the symbols have been adjusted, go over the file looking
  1515. for any relocations that pic won't support. */
  1516. void
  1517. frv_frob_file (void)
  1518. {
  1519. bfd_map_over_sections (stdoutput, frv_frob_file_section, (void *) 0);
  1520. }
  1521. void
  1522. frv_frob_label (symbolS *this_label)
  1523. {
  1524. struct vliw_insn_list *vliw_insn_list_entry;
  1525. dwarf2_emit_label (this_label);
  1526. if (frv_mach != bfd_mach_frvtomcat)
  1527. return;
  1528. if (now_seg != text_section)
  1529. return;
  1530. vliw_insn_list_entry = frv_insert_vliw_insn(DONT_COUNT);
  1531. vliw_insn_list_entry->type = VLIW_LABEL_TYPE;
  1532. vliw_insn_list_entry->sym = this_label;
  1533. }
  1534. fixS *
  1535. frv_cgen_record_fixup_exp (fragS *frag,
  1536. int where,
  1537. const CGEN_INSN *insn,
  1538. int length,
  1539. const CGEN_OPERAND *operand,
  1540. int opinfo,
  1541. expressionS *exp)
  1542. {
  1543. fixS * fixP = gas_cgen_record_fixup_exp (frag, where, insn, length,
  1544. operand, opinfo, exp);
  1545. if (frv_mach == bfd_mach_frvtomcat
  1546. && current_vliw_insn
  1547. && current_vliw_insn->type == VLIW_BRANCH_TYPE
  1548. && exp != NULL)
  1549. current_vliw_insn->sym = exp->X_add_symbol;
  1550. return fixP;
  1551. }