tc-rx.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711
  1. /* tc-rx.c -- Assembler for the Renesas RX
  2. Copyright (C) 2008-2015 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 the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. #include "as.h"
  17. #include "struc-symbol.h"
  18. #include "safe-ctype.h"
  19. #include "dwarf2dbg.h"
  20. #include "libbfd.h"
  21. #include "elf/common.h"
  22. #include "elf/rx.h"
  23. #include "rx-defs.h"
  24. #include "filenames.h"
  25. #include "listing.h"
  26. #include "sb.h"
  27. #include "macro.h"
  28. #define RX_OPCODE_BIG_ENDIAN 0
  29. const char comment_chars[] = ";";
  30. /* Note that input_file.c hand checks for '#' at the beginning of the
  31. first line of the input file. This is because the compiler outputs
  32. #NO_APP at the beginning of its output. */
  33. const char line_comment_chars[] = "#";
  34. const char line_separator_chars[] = "!";
  35. const char EXP_CHARS[] = "eE";
  36. const char FLT_CHARS[] = "dD";
  37. /* ELF flags to set in the output file header. */
  38. static int elf_flags = E_FLAG_RX_ABI;
  39. bfd_boolean rx_use_conventional_section_names = FALSE;
  40. static bfd_boolean rx_use_small_data_limit = FALSE;
  41. static bfd_boolean rx_pid_mode = FALSE;
  42. static int rx_num_int_regs = 0;
  43. int rx_pid_register;
  44. int rx_gp_register;
  45. enum rx_cpu_types rx_cpu = RX600;
  46. static void rx_fetchalign (int ignore ATTRIBUTE_UNUSED);
  47. enum options
  48. {
  49. OPTION_BIG = OPTION_MD_BASE,
  50. OPTION_LITTLE,
  51. OPTION_32BIT_DOUBLES,
  52. OPTION_64BIT_DOUBLES,
  53. OPTION_CONVENTIONAL_SECTION_NAMES,
  54. OPTION_RENESAS_SECTION_NAMES,
  55. OPTION_SMALL_DATA_LIMIT,
  56. OPTION_RELAX,
  57. OPTION_PID,
  58. OPTION_INT_REGS,
  59. OPTION_USES_GCC_ABI,
  60. OPTION_USES_RX_ABI,
  61. OPTION_CPU,
  62. OPTION_DISALLOW_STRING_INSNS,
  63. };
  64. #define RX_SHORTOPTS ""
  65. const char * md_shortopts = RX_SHORTOPTS;
  66. /* Assembler options. */
  67. struct option md_longopts[] =
  68. {
  69. {"mbig-endian-data", no_argument, NULL, OPTION_BIG},
  70. {"mlittle-endian-data", no_argument, NULL, OPTION_LITTLE},
  71. /* The next two switches are here because the
  72. generic parts of the linker testsuite uses them. */
  73. {"EB", no_argument, NULL, OPTION_BIG},
  74. {"EL", no_argument, NULL, OPTION_LITTLE},
  75. {"m32bit-doubles", no_argument, NULL, OPTION_32BIT_DOUBLES},
  76. {"m64bit-doubles", no_argument, NULL, OPTION_64BIT_DOUBLES},
  77. /* This option is here mainly for the binutils testsuites,
  78. as many of their tests assume conventional section naming. */
  79. {"muse-conventional-section-names", no_argument, NULL, OPTION_CONVENTIONAL_SECTION_NAMES},
  80. {"muse-renesas-section-names", no_argument, NULL, OPTION_RENESAS_SECTION_NAMES},
  81. {"msmall-data-limit", no_argument, NULL, OPTION_SMALL_DATA_LIMIT},
  82. {"relax", no_argument, NULL, OPTION_RELAX},
  83. {"mpid", no_argument, NULL, OPTION_PID},
  84. {"mint-register", required_argument, NULL, OPTION_INT_REGS},
  85. {"mgcc-abi", no_argument, NULL, OPTION_USES_GCC_ABI},
  86. {"mrx-abi", no_argument, NULL, OPTION_USES_RX_ABI},
  87. {"mcpu", required_argument, NULL, OPTION_CPU},
  88. {"mno-allow-string-insns", no_argument, NULL, OPTION_DISALLOW_STRING_INSNS},
  89. {NULL, no_argument, NULL, 0}
  90. };
  91. size_t md_longopts_size = sizeof (md_longopts);
  92. int
  93. md_parse_option (int c ATTRIBUTE_UNUSED, char * arg ATTRIBUTE_UNUSED)
  94. {
  95. switch (c)
  96. {
  97. case OPTION_BIG:
  98. target_big_endian = 1;
  99. return 1;
  100. case OPTION_LITTLE:
  101. target_big_endian = 0;
  102. return 1;
  103. case OPTION_32BIT_DOUBLES:
  104. elf_flags &= ~ E_FLAG_RX_64BIT_DOUBLES;
  105. return 1;
  106. case OPTION_64BIT_DOUBLES:
  107. elf_flags |= E_FLAG_RX_64BIT_DOUBLES;
  108. return 1;
  109. case OPTION_CONVENTIONAL_SECTION_NAMES:
  110. rx_use_conventional_section_names = TRUE;
  111. return 1;
  112. case OPTION_RENESAS_SECTION_NAMES:
  113. rx_use_conventional_section_names = FALSE;
  114. return 1;
  115. case OPTION_SMALL_DATA_LIMIT:
  116. rx_use_small_data_limit = TRUE;
  117. return 1;
  118. case OPTION_RELAX:
  119. linkrelax = 1;
  120. return 1;
  121. case OPTION_PID:
  122. rx_pid_mode = TRUE;
  123. elf_flags |= E_FLAG_RX_PID;
  124. return 1;
  125. case OPTION_INT_REGS:
  126. rx_num_int_regs = atoi (optarg);
  127. return 1;
  128. case OPTION_USES_GCC_ABI:
  129. elf_flags &= ~ E_FLAG_RX_ABI;
  130. return 1;
  131. case OPTION_USES_RX_ABI:
  132. elf_flags |= E_FLAG_RX_ABI;
  133. return 1;
  134. case OPTION_CPU:
  135. if (strcasecmp (arg, "rx100") == 0)
  136. rx_cpu = RX100;
  137. else if (strcasecmp (arg, "rx200") == 0)
  138. rx_cpu = RX200;
  139. else if (strcasecmp (arg, "rx600") == 0)
  140. rx_cpu = RX600;
  141. else if (strcasecmp (arg, "rx610") == 0)
  142. rx_cpu = RX610;
  143. else
  144. {
  145. as_warn (_("unrecognised RX CPU type %s"), arg);
  146. break;
  147. }
  148. return 1;
  149. case OPTION_DISALLOW_STRING_INSNS:
  150. elf_flags |= E_FLAG_RX_SINSNS_SET | E_FLAG_RX_SINSNS_NO;
  151. return 1;
  152. }
  153. return 0;
  154. }
  155. void
  156. md_show_usage (FILE * stream)
  157. {
  158. fprintf (stream, _(" RX specific command line options:\n"));
  159. fprintf (stream, _(" --mbig-endian-data\n"));
  160. fprintf (stream, _(" --mlittle-endian-data [default]\n"));
  161. fprintf (stream, _(" --m32bit-doubles [default]\n"));
  162. fprintf (stream, _(" --m64bit-doubles\n"));
  163. fprintf (stream, _(" --muse-conventional-section-names\n"));
  164. fprintf (stream, _(" --muse-renesas-section-names [default]\n"));
  165. fprintf (stream, _(" --msmall-data-limit\n"));
  166. fprintf (stream, _(" --mrelax\n"));
  167. fprintf (stream, _(" --mpid\n"));
  168. fprintf (stream, _(" --mint-register=<value>\n"));
  169. fprintf (stream, _(" --mcpu=<rx100|rx200|rx600|rx610>\n"));
  170. fprintf (stream, _(" --mno-allow-string-insns"));
  171. }
  172. static void
  173. s_bss (int ignore ATTRIBUTE_UNUSED)
  174. {
  175. int temp;
  176. temp = get_absolute_expression ();
  177. subseg_set (bss_section, (subsegT) temp);
  178. demand_empty_rest_of_line ();
  179. }
  180. static void
  181. rx_float_cons (int ignore ATTRIBUTE_UNUSED)
  182. {
  183. if (elf_flags & E_FLAG_RX_64BIT_DOUBLES)
  184. return float_cons ('d');
  185. return float_cons ('f');
  186. }
  187. static char *
  188. rx_strcasestr (const char *string, const char *sub)
  189. {
  190. int subl;
  191. int strl;
  192. if (!sub || !sub[0])
  193. return (char *)string;
  194. subl = strlen (sub);
  195. strl = strlen (string);
  196. while (strl >= subl)
  197. {
  198. /* strncasecmp is in libiberty. */
  199. if (strncasecmp (string, sub, subl) == 0)
  200. return (char *)string;
  201. string ++;
  202. strl --;
  203. }
  204. return NULL;
  205. }
  206. static void
  207. rx_include (int ignore)
  208. {
  209. FILE * try;
  210. char * path;
  211. char * filename;
  212. char * current_filename;
  213. char * last_char;
  214. char * p;
  215. char * d;
  216. char * f;
  217. char end_char;
  218. size_t len;
  219. /* The RX version of the .INCLUDE pseudo-op does not
  220. have to have the filename inside double quotes. */
  221. SKIP_WHITESPACE ();
  222. if (*input_line_pointer == '"')
  223. {
  224. /* Treat as the normal GAS .include pseudo-op. */
  225. s_include (ignore);
  226. return;
  227. }
  228. /* Get the filename. Spaces are allowed, NUL characters are not. */
  229. filename = input_line_pointer;
  230. last_char = find_end_of_line (filename, FALSE);
  231. input_line_pointer = last_char;
  232. while (last_char >= filename && (* last_char == ' ' || * last_char == '\n'))
  233. -- last_char;
  234. end_char = *(++ last_char);
  235. * last_char = 0;
  236. if (last_char == filename)
  237. {
  238. as_bad (_("no filename following .INCLUDE pseudo-op"));
  239. * last_char = end_char;
  240. return;
  241. }
  242. as_where (& current_filename, NULL);
  243. f = (char *) xmalloc (strlen (current_filename) + strlen (filename) + 1);
  244. /* Check the filename. If [@]..FILE[@] is found then replace
  245. this with the current assembler source filename, stripped
  246. of any directory prefixes or extensions. */
  247. if ((p = rx_strcasestr (filename, "..file")) != NULL)
  248. {
  249. char * c;
  250. len = 6; /* strlen ("..file"); */
  251. if (p > filename && p[-1] == '@')
  252. -- p, ++len;
  253. if (p[len] == '@')
  254. len ++;
  255. for (d = c = current_filename; *c; c++)
  256. if (IS_DIR_SEPARATOR (* c))
  257. d = c + 1;
  258. for (c = d; *c; c++)
  259. if (*c == '.')
  260. break;
  261. sprintf (f, "%.*s%.*s%.*s", (int) (p - filename), filename,
  262. (int) (c - d), d,
  263. (int) (strlen (filename) - ((p + len) - filename)),
  264. p + len);
  265. }
  266. else
  267. strcpy (f, filename);
  268. /* RX .INCLUDE semantics say that 'filename' is located by:
  269. 1. If filename is absolute, just try that. Otherwise...
  270. 2. If the current source file includes a directory component
  271. then prepend that to the filename and try. Otherwise...
  272. 3. Try any directories specified by the -I command line
  273. option(s).
  274. 4 .Try a directory specifed by the INC100 environment variable. */
  275. if (IS_ABSOLUTE_PATH (f))
  276. try = fopen (path = f, FOPEN_RT);
  277. else
  278. {
  279. char * env = getenv ("INC100");
  280. try = NULL;
  281. len = strlen (current_filename);
  282. if ((size_t) include_dir_maxlen > len)
  283. len = include_dir_maxlen;
  284. if (env && strlen (env) > len)
  285. len = strlen (env);
  286. path = (char *) xmalloc (strlen (f) + len + 5);
  287. if (current_filename != NULL)
  288. {
  289. for (d = NULL, p = current_filename; *p; p++)
  290. if (IS_DIR_SEPARATOR (* p))
  291. d = p;
  292. if (d != NULL)
  293. {
  294. sprintf (path, "%.*s/%s", (int) (d - current_filename), current_filename,
  295. f);
  296. try = fopen (path, FOPEN_RT);
  297. }
  298. }
  299. if (try == NULL)
  300. {
  301. int i;
  302. for (i = 0; i < include_dir_count; i++)
  303. {
  304. sprintf (path, "%s/%s", include_dirs[i], f);
  305. if ((try = fopen (path, FOPEN_RT)) != NULL)
  306. break;
  307. }
  308. }
  309. if (try == NULL && env != NULL)
  310. {
  311. sprintf (path, "%s/%s", env, f);
  312. try = fopen (path, FOPEN_RT);
  313. }
  314. free (f);
  315. }
  316. if (try == NULL)
  317. {
  318. as_bad (_("unable to locate include file: %s"), filename);
  319. free (path);
  320. }
  321. else
  322. {
  323. fclose (try);
  324. register_dependency (path);
  325. input_scrub_insert_file (path);
  326. }
  327. * last_char = end_char;
  328. }
  329. static void
  330. parse_rx_section (char * name)
  331. {
  332. asection * sec;
  333. int type;
  334. int attr = SHF_ALLOC | SHF_EXECINSTR;
  335. int align = 2;
  336. char end_char;
  337. do
  338. {
  339. char * p;
  340. SKIP_WHITESPACE ();
  341. for (p = input_line_pointer; *p && strchr ("\n\t, =", *p) == NULL; p++)
  342. ;
  343. end_char = *p;
  344. *p = 0;
  345. if (strcasecmp (input_line_pointer, "ALIGN") == 0)
  346. {
  347. *p = end_char;
  348. if (end_char == ' ')
  349. while (ISSPACE (*p))
  350. p++;
  351. if (*p == '=')
  352. {
  353. ++ p;
  354. while (ISSPACE (*p))
  355. p++;
  356. switch (*p)
  357. {
  358. case '2': align = 2; break;
  359. case '4': align = 4; break;
  360. case '8': align = 8; break;
  361. default:
  362. as_bad (_("unrecognised alignment value in .SECTION directive: %s"), p);
  363. ignore_rest_of_line ();
  364. return;
  365. }
  366. ++ p;
  367. }
  368. end_char = *p;
  369. }
  370. else if (strcasecmp (input_line_pointer, "CODE") == 0)
  371. attr = SHF_ALLOC | SHF_EXECINSTR;
  372. else if (strcasecmp (input_line_pointer, "DATA") == 0)
  373. attr = SHF_ALLOC | SHF_WRITE;
  374. else if (strcasecmp (input_line_pointer, "ROMDATA") == 0)
  375. attr = SHF_ALLOC;
  376. else
  377. {
  378. as_bad (_("unknown parameter following .SECTION directive: %s"),
  379. input_line_pointer);
  380. *p = end_char;
  381. input_line_pointer = p + 1;
  382. ignore_rest_of_line ();
  383. return;
  384. }
  385. *p = end_char;
  386. input_line_pointer = p + 1;
  387. }
  388. while (end_char != '\n' && end_char != 0);
  389. if ((sec = bfd_get_section_by_name (stdoutput, name)) == NULL)
  390. {
  391. if (strcmp (name, "B") && strcmp (name, "B_1") && strcmp (name, "B_2"))
  392. type = SHT_NULL;
  393. else
  394. type = SHT_NOBITS;
  395. obj_elf_change_section (name, type, attr, 0, NULL, FALSE, FALSE);
  396. }
  397. else /* Try not to redefine a section, especially B_1. */
  398. {
  399. int flags = sec->flags;
  400. type = elf_section_type (sec);
  401. attr = ((flags & SEC_READONLY) ? 0 : SHF_WRITE)
  402. | ((flags & SEC_ALLOC) ? SHF_ALLOC : 0)
  403. | ((flags & SEC_CODE) ? SHF_EXECINSTR : 0)
  404. | ((flags & SEC_MERGE) ? SHF_MERGE : 0)
  405. | ((flags & SEC_STRINGS) ? SHF_STRINGS : 0)
  406. | ((flags & SEC_THREAD_LOCAL) ? SHF_TLS : 0);
  407. obj_elf_change_section (name, type, attr, 0, NULL, FALSE, FALSE);
  408. }
  409. bfd_set_section_alignment (stdoutput, now_seg, align);
  410. }
  411. static void
  412. rx_section (int ignore)
  413. {
  414. char * p;
  415. /* The as100 assembler supports a different syntax for the .section
  416. pseudo-op. So check for it and handle it here if necessary. */
  417. SKIP_WHITESPACE ();
  418. /* Peek past the section name to see if arguments follow. */
  419. for (p = input_line_pointer; *p; p++)
  420. if (*p == ',' || *p == '\n')
  421. break;
  422. if (*p == ',')
  423. {
  424. int len = p - input_line_pointer;
  425. while (ISSPACE (*++p))
  426. ;
  427. if (*p != '"' && *p != '#')
  428. {
  429. char * name = (char *) xmalloc (len + 1);
  430. strncpy (name, input_line_pointer, len);
  431. name[len] = 0;
  432. input_line_pointer = p;
  433. parse_rx_section (name);
  434. return;
  435. }
  436. }
  437. obj_elf_section (ignore);
  438. }
  439. static void
  440. rx_list (int ignore ATTRIBUTE_UNUSED)
  441. {
  442. SKIP_WHITESPACE ();
  443. if (strncasecmp (input_line_pointer, "OFF", 3))
  444. listing_list (0);
  445. else if (strncasecmp (input_line_pointer, "ON", 2))
  446. listing_list (1);
  447. else
  448. as_warn (_("expecting either ON or OFF after .list"));
  449. }
  450. /* Like the .rept pseudo op, but supports the
  451. use of ..MACREP inside the repeated region. */
  452. static void
  453. rx_rept (int ignore ATTRIBUTE_UNUSED)
  454. {
  455. int count = get_absolute_expression ();
  456. do_repeat_with_expander (count, "MREPEAT", "ENDR", "..MACREP");
  457. }
  458. /* Like cons() accept that strings are allowed. */
  459. static void
  460. rx_cons (int size)
  461. {
  462. SKIP_WHITESPACE ();
  463. if (* input_line_pointer == '"')
  464. stringer (8+0);
  465. else
  466. cons (size);
  467. }
  468. static void
  469. rx_nop (int ignore ATTRIBUTE_UNUSED)
  470. {
  471. ignore_rest_of_line ();
  472. }
  473. static void
  474. rx_unimp (int idx)
  475. {
  476. as_warn (_("The \".%s\" pseudo-op is not implemented\n"),
  477. md_pseudo_table[idx].poc_name);
  478. ignore_rest_of_line ();
  479. }
  480. /* The target specific pseudo-ops which we support. */
  481. const pseudo_typeS md_pseudo_table[] =
  482. {
  483. /* These are unimplemented. They're listed first so that we can use
  484. the poc_value as the index into this array, to get the name of
  485. the pseudo. So, keep these (1) first, and (2) in order, with (3)
  486. the poc_value's in sequence. */
  487. { "btglb", rx_unimp, 0 },
  488. { "call", rx_unimp, 1 },
  489. { "einsf", rx_unimp, 2 },
  490. { "fb", rx_unimp, 3 },
  491. { "fbsym", rx_unimp, 4 },
  492. { "id", rx_unimp, 5 },
  493. { "initsct", rx_unimp, 6 },
  494. { "insf", rx_unimp, 7 },
  495. { "instr", rx_unimp, 8 },
  496. { "lbba", rx_unimp, 9 },
  497. { "len", rx_unimp, 10 },
  498. { "optj", rx_unimp, 11 },
  499. { "rvector", rx_unimp, 12 },
  500. { "sb", rx_unimp, 13 },
  501. { "sbbit", rx_unimp, 14 },
  502. { "sbsym", rx_unimp, 15 },
  503. { "sbsym16", rx_unimp, 16 },
  504. /* These are the do-nothing pseudos. */
  505. { "stk", rx_nop, 0 },
  506. /* The manual documents ".stk" but the compiler emits ".stack". */
  507. { "stack", rx_nop, 0 },
  508. /* These are Renesas as100 assembler pseudo-ops that we do support. */
  509. { "addr", rx_cons, 3 },
  510. { "align", s_align_bytes, 2 },
  511. { "byte", rx_cons, 1 },
  512. { "fixed", float_cons, 'f' },
  513. { "form", listing_psize, 0 },
  514. { "glb", s_globl, 0 },
  515. { "include", rx_include, 0 },
  516. { "list", rx_list, 0 },
  517. { "lword", rx_cons, 4 },
  518. { "mrepeat", rx_rept, 0 },
  519. { "section", rx_section, 0 },
  520. /* FIXME: The following pseudo-ops place their values (and associated
  521. label if present) in the data section, regardless of whatever
  522. section we are currently in. At the moment this code does not
  523. implement that part of the semantics. */
  524. { "blka", s_space, 3 },
  525. { "blkb", s_space, 1 },
  526. { "blkd", s_space, 8 },
  527. { "blkf", s_space, 4 },
  528. { "blkl", s_space, 4 },
  529. { "blkw", s_space, 2 },
  530. /* Our "standard" pseudos. */
  531. { "double", rx_float_cons, 0 },
  532. { "bss", s_bss, 0 },
  533. { "3byte", cons, 3 },
  534. { "int", cons, 4 },
  535. { "word", cons, 4 },
  536. { "fetchalign", rx_fetchalign, 0 },
  537. /* End of list marker. */
  538. { NULL, NULL, 0 }
  539. };
  540. static asymbol * gp_symbol;
  541. static asymbol * rx_pid_symbol;
  542. static symbolS * rx_pidreg_symbol;
  543. static symbolS * rx_gpreg_symbol;
  544. void
  545. md_begin (void)
  546. {
  547. /* Make the __gp and __pid_base symbols now rather
  548. than after the symbol table is frozen. We only do this
  549. when supporting small data limits because otherwise we
  550. pollute the symbol table. */
  551. /* The meta-registers %pidreg and %gpreg depend on what other
  552. options are specified. The __rx_*_defined symbols exist so we
  553. can .ifdef asm code based on what options were passed to gas,
  554. without needing a preprocessor */
  555. if (rx_pid_mode)
  556. {
  557. rx_pid_register = 13 - rx_num_int_regs;
  558. rx_pid_symbol = symbol_get_bfdsym (symbol_find_or_make ("__pid_base"));
  559. rx_pidreg_symbol = symbol_find_or_make ("__rx_pidreg_defined");
  560. S_SET_VALUE (rx_pidreg_symbol, rx_pid_register);
  561. S_SET_SEGMENT (rx_pidreg_symbol, absolute_section);
  562. }
  563. if (rx_use_small_data_limit)
  564. {
  565. if (rx_pid_mode)
  566. rx_gp_register = rx_pid_register - 1;
  567. else
  568. rx_gp_register = 13 - rx_num_int_regs;
  569. gp_symbol = symbol_get_bfdsym (symbol_find_or_make ("__gp"));
  570. rx_gpreg_symbol = symbol_find_or_make ("__rx_gpreg_defined");
  571. S_SET_VALUE (rx_gpreg_symbol, rx_gp_register);
  572. S_SET_SEGMENT (rx_gpreg_symbol, absolute_section);
  573. }
  574. }
  575. char * rx_lex_start;
  576. char * rx_lex_end;
  577. /* These negative numbers are found in rx_bytesT.n_base for non-opcode
  578. md_frags */
  579. #define RX_NBASE_FETCHALIGN -1
  580. typedef struct rx_bytesT
  581. {
  582. char base[4];
  583. /* If this is negative, it's a special-purpose frag as per the defines above. */
  584. int n_base;
  585. char ops[8];
  586. int n_ops;
  587. struct
  588. {
  589. expressionS exp;
  590. char offset;
  591. char nbits;
  592. char type; /* RXREL_*. */
  593. int reloc;
  594. fixS * fixP;
  595. } fixups[2];
  596. int n_fixups;
  597. struct
  598. {
  599. char type;
  600. char field_pos;
  601. char val_ofs;
  602. } relax[2];
  603. int n_relax;
  604. int link_relax;
  605. fixS *link_relax_fixP;
  606. char times_grown;
  607. char times_shrank;
  608. } rx_bytesT;
  609. static rx_bytesT rx_bytes;
  610. /* We set n_ops to be "size of next opcode" if the next opcode doesn't relax. */
  611. static rx_bytesT *fetchalign_bytes = NULL;
  612. static void
  613. rx_fetchalign (int ignore ATTRIBUTE_UNUSED)
  614. {
  615. char * bytes;
  616. fragS * frag_then;
  617. memset (& rx_bytes, 0, sizeof (rx_bytes));
  618. rx_bytes.n_base = RX_NBASE_FETCHALIGN;
  619. bytes = frag_more (8);
  620. frag_then = frag_now;
  621. frag_variant (rs_machine_dependent,
  622. 0 /* max_chars */,
  623. 0 /* var */,
  624. 0 /* subtype */,
  625. 0 /* symbol */,
  626. 0 /* offset */,
  627. 0 /* opcode */);
  628. frag_then->fr_opcode = bytes;
  629. frag_then->fr_subtype = 0;
  630. fetchalign_bytes = frag_then->tc_frag_data;
  631. }
  632. void
  633. rx_relax (int type, int pos)
  634. {
  635. rx_bytes.relax[rx_bytes.n_relax].type = type;
  636. rx_bytes.relax[rx_bytes.n_relax].field_pos = pos;
  637. rx_bytes.relax[rx_bytes.n_relax].val_ofs = rx_bytes.n_base + rx_bytes.n_ops;
  638. rx_bytes.n_relax ++;
  639. }
  640. void
  641. rx_linkrelax_dsp (int pos)
  642. {
  643. switch (pos)
  644. {
  645. case 4:
  646. rx_bytes.link_relax |= RX_RELAXA_DSP4;
  647. break;
  648. case 6:
  649. rx_bytes.link_relax |= RX_RELAXA_DSP6;
  650. break;
  651. case 14:
  652. rx_bytes.link_relax |= RX_RELAXA_DSP14;
  653. break;
  654. }
  655. }
  656. void
  657. rx_linkrelax_imm (int pos)
  658. {
  659. switch (pos)
  660. {
  661. case 6:
  662. rx_bytes.link_relax |= RX_RELAXA_IMM6;
  663. break;
  664. case 12:
  665. rx_bytes.link_relax |= RX_RELAXA_IMM12;
  666. break;
  667. }
  668. }
  669. void
  670. rx_linkrelax_branch (void)
  671. {
  672. rx_bytes.link_relax |= RX_RELAXA_BRA;
  673. }
  674. static void
  675. rx_fixup (expressionS exp, int offsetbits, int nbits, int type)
  676. {
  677. rx_bytes.fixups[rx_bytes.n_fixups].exp = exp;
  678. rx_bytes.fixups[rx_bytes.n_fixups].offset = offsetbits;
  679. rx_bytes.fixups[rx_bytes.n_fixups].nbits = nbits;
  680. rx_bytes.fixups[rx_bytes.n_fixups].type = type;
  681. rx_bytes.fixups[rx_bytes.n_fixups].reloc = exp.X_md;
  682. rx_bytes.n_fixups ++;
  683. }
  684. #define rx_field_fixup(exp, offset, nbits, type) \
  685. rx_fixup (exp, offset, nbits, type)
  686. #define rx_op_fixup(exp, offset, nbits, type) \
  687. rx_fixup (exp, offset + 8 * rx_bytes.n_base, nbits, type)
  688. void
  689. rx_base1 (int b1)
  690. {
  691. rx_bytes.base[0] = b1;
  692. rx_bytes.n_base = 1;
  693. }
  694. void
  695. rx_base2 (int b1, int b2)
  696. {
  697. rx_bytes.base[0] = b1;
  698. rx_bytes.base[1] = b2;
  699. rx_bytes.n_base = 2;
  700. }
  701. void
  702. rx_base3 (int b1, int b2, int b3)
  703. {
  704. rx_bytes.base[0] = b1;
  705. rx_bytes.base[1] = b2;
  706. rx_bytes.base[2] = b3;
  707. rx_bytes.n_base = 3;
  708. }
  709. void
  710. rx_base4 (int b1, int b2, int b3, int b4)
  711. {
  712. rx_bytes.base[0] = b1;
  713. rx_bytes.base[1] = b2;
  714. rx_bytes.base[2] = b3;
  715. rx_bytes.base[3] = b4;
  716. rx_bytes.n_base = 4;
  717. }
  718. /* This gets complicated when the field spans bytes, because fields
  719. are numbered from the MSB of the first byte as zero, and bits are
  720. stored LSB towards the LSB of the byte. Thus, a simple four-bit
  721. insertion of 12 at position 4 of 0x00 yields: 0x0b. A three-bit
  722. insertion of b'MXL at position 7 is like this:
  723. - - - - - - - - - - - - - - - -
  724. M X L */
  725. void
  726. rx_field (int val, int pos, int sz)
  727. {
  728. int valm;
  729. int bytep, bitp;
  730. if (sz > 0)
  731. {
  732. if (val < 0 || val >= (1 << sz))
  733. as_bad (_("Value %d doesn't fit in unsigned %d-bit field"), val, sz);
  734. }
  735. else
  736. {
  737. sz = - sz;
  738. if (val < -(1 << (sz - 1)) || val >= (1 << (sz - 1)))
  739. as_bad (_("Value %d doesn't fit in signed %d-bit field"), val, sz);
  740. }
  741. /* This code points at 'M' in the above example. */
  742. bytep = pos / 8;
  743. bitp = pos % 8;
  744. while (bitp + sz > 8)
  745. {
  746. int ssz = 8 - bitp;
  747. int svalm;
  748. svalm = val >> (sz - ssz);
  749. svalm = svalm & ((1 << ssz) - 1);
  750. svalm = svalm << (8 - bitp - ssz);
  751. gas_assert (bytep < rx_bytes.n_base);
  752. rx_bytes.base[bytep] |= svalm;
  753. bitp = 0;
  754. sz -= ssz;
  755. bytep ++;
  756. }
  757. valm = val & ((1 << sz) - 1);
  758. valm = valm << (8 - bitp - sz);
  759. gas_assert (bytep < rx_bytes.n_base);
  760. rx_bytes.base[bytep] |= valm;
  761. }
  762. /* Special case of the above, for 3-bit displacements of 2..9. */
  763. void
  764. rx_disp3 (expressionS exp, int pos)
  765. {
  766. rx_field_fixup (exp, pos, 3, RXREL_PCREL);
  767. }
  768. /* Special case of the above, for split 5-bit displacements. Assumes
  769. the displacement has been checked with rx_disp5op. */
  770. /* ---- -432 1--- 0--- */
  771. void
  772. rx_field5s (expressionS exp)
  773. {
  774. int val;
  775. val = exp.X_add_number;
  776. rx_bytes.base[0] |= val >> 2;
  777. rx_bytes.base[1] |= (val << 6) & 0x80;
  778. rx_bytes.base[1] |= (val << 3) & 0x08;
  779. }
  780. /* ---- ---- 4--- 3210 */
  781. void
  782. rx_field5s2 (expressionS exp)
  783. {
  784. int val;
  785. val = exp.X_add_number;
  786. rx_bytes.base[1] |= (val << 3) & 0x80;
  787. rx_bytes.base[1] |= (val ) & 0x0f;
  788. }
  789. #define OP(x) rx_bytes.ops[rx_bytes.n_ops++] = (x)
  790. #define F_PRECISION 2
  791. void
  792. rx_op (expressionS exp, int nbytes, int type)
  793. {
  794. offsetT v = 0;
  795. if ((exp.X_op == O_constant || exp.X_op == O_big)
  796. && type != RXREL_PCREL)
  797. {
  798. if (exp.X_op == O_big)
  799. {
  800. if (exp.X_add_number == -1)
  801. {
  802. LITTLENUM_TYPE w[2];
  803. char * ip = rx_bytes.ops + rx_bytes.n_ops;
  804. gen_to_words (w, F_PRECISION, 8);
  805. #if RX_OPCODE_BIG_ENDIAN
  806. ip[0] = w[0] >> 8;
  807. ip[1] = w[0];
  808. ip[2] = w[1] >> 8;
  809. ip[3] = w[1];
  810. #else
  811. ip[3] = w[0] >> 8;
  812. ip[2] = w[0];
  813. ip[1] = w[1] >> 8;
  814. ip[0] = w[1];
  815. #endif
  816. rx_bytes.n_ops += 4;
  817. return;
  818. }
  819. v = ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
  820. | (generic_bignum[0] & LITTLENUM_MASK);
  821. }
  822. else
  823. v = exp.X_add_number;
  824. while (nbytes)
  825. {
  826. #if RX_OPCODE_BIG_ENDIAN
  827. OP ((v >> (8 * (nbytes - 1))) & 0xff);
  828. #else
  829. OP (v & 0xff);
  830. v >>= 8;
  831. #endif
  832. nbytes --;
  833. }
  834. }
  835. else
  836. {
  837. rx_op_fixup (exp, rx_bytes.n_ops * 8, nbytes * 8, type);
  838. memset (rx_bytes.ops + rx_bytes.n_ops, 0, nbytes);
  839. rx_bytes.n_ops += nbytes;
  840. }
  841. }
  842. int
  843. rx_wrap (void)
  844. {
  845. return 0;
  846. }
  847. #define APPEND(B, N_B) \
  848. if (rx_bytes.N_B) \
  849. { \
  850. memcpy (bytes + idx, rx_bytes.B, rx_bytes.N_B); \
  851. idx += rx_bytes.N_B; \
  852. }
  853. void
  854. rx_frag_init (fragS * fragP)
  855. {
  856. if (rx_bytes.n_relax || rx_bytes.link_relax || rx_bytes.n_base < 0)
  857. {
  858. fragP->tc_frag_data = malloc (sizeof (rx_bytesT));
  859. memcpy (fragP->tc_frag_data, & rx_bytes, sizeof (rx_bytesT));
  860. }
  861. else
  862. fragP->tc_frag_data = 0;
  863. }
  864. /* Handle the as100's version of the .equ pseudo-op. It has the syntax:
  865. <symbol_name> .equ <expression> */
  866. static void
  867. rx_equ (char * name, char * expression)
  868. {
  869. char saved_name_end_char;
  870. char * name_end;
  871. char * saved_ilp;
  872. while (ISSPACE (* name))
  873. name ++;
  874. for (name_end = name + 1; *name_end; name_end ++)
  875. if (! ISALNUM (* name_end))
  876. break;
  877. saved_name_end_char = * name_end;
  878. * name_end = 0;
  879. saved_ilp = input_line_pointer;
  880. input_line_pointer = expression;
  881. equals (name, 1);
  882. input_line_pointer = saved_ilp;
  883. * name_end = saved_name_end_char;
  884. }
  885. /* Look for Renesas as100 pseudo-ops that occur after a symbol name
  886. rather than at the start of a line. (eg .EQU or .DEFINE). If one
  887. is found, process it and return TRUE otherwise return FALSE. */
  888. static bfd_boolean
  889. scan_for_infix_rx_pseudo_ops (char * str)
  890. {
  891. char * p;
  892. char * pseudo_op;
  893. char * dot = strchr (str, '.');
  894. if (dot == NULL || dot == str)
  895. return FALSE;
  896. /* A real pseudo-op must be preceeded by whitespace. */
  897. if (dot[-1] != ' ' && dot[-1] != '\t')
  898. return FALSE;
  899. pseudo_op = dot + 1;
  900. if (!ISALNUM (* pseudo_op))
  901. return FALSE;
  902. for (p = pseudo_op + 1; ISALNUM (* p); p++)
  903. ;
  904. if (strncasecmp ("EQU", pseudo_op, p - pseudo_op) == 0)
  905. rx_equ (str, p);
  906. else if (strncasecmp ("DEFINE", pseudo_op, p - pseudo_op) == 0)
  907. as_warn (_("The .DEFINE pseudo-op is not implemented"));
  908. else if (strncasecmp ("MACRO", pseudo_op, p - pseudo_op) == 0)
  909. as_warn (_("The .MACRO pseudo-op is not implemented"));
  910. else if (strncasecmp ("BTEQU", pseudo_op, p - pseudo_op) == 0)
  911. as_warn (_("The .BTEQU pseudo-op is not implemented."));
  912. else
  913. return FALSE;
  914. return TRUE;
  915. }
  916. void
  917. md_assemble (char * str)
  918. {
  919. char * bytes;
  920. int idx = 0;
  921. int i, rel;
  922. fragS * frag_then = frag_now;
  923. expressionS *exp;
  924. memset (& rx_bytes, 0, sizeof (rx_bytes));
  925. rx_lex_init (str, str + strlen (str));
  926. if (scan_for_infix_rx_pseudo_ops (str))
  927. return;
  928. rx_parse ();
  929. /* This simplifies the relaxation code. */
  930. if (rx_bytes.n_relax || rx_bytes.link_relax)
  931. {
  932. /* We do it this way because we want the frag to have the
  933. rx_bytes in it, which we initialize above. */
  934. bytes = frag_more (12);
  935. frag_then = frag_now;
  936. frag_variant (rs_machine_dependent,
  937. 0 /* max_chars */,
  938. 0 /* var */,
  939. 0 /* subtype */,
  940. 0 /* symbol */,
  941. 0 /* offset */,
  942. 0 /* opcode */);
  943. frag_then->fr_opcode = bytes;
  944. frag_then->fr_fix += rx_bytes.n_base + rx_bytes.n_ops;
  945. frag_then->fr_subtype = rx_bytes.n_base + rx_bytes.n_ops;
  946. }
  947. else
  948. {
  949. bytes = frag_more (rx_bytes.n_base + rx_bytes.n_ops);
  950. frag_then = frag_now;
  951. if (fetchalign_bytes)
  952. fetchalign_bytes->n_ops = rx_bytes.n_base + rx_bytes.n_ops;
  953. }
  954. fetchalign_bytes = NULL;
  955. APPEND (base, n_base);
  956. APPEND (ops, n_ops);
  957. if (rx_bytes.link_relax && rx_bytes.n_fixups)
  958. {
  959. fixS * f;
  960. f = fix_new (frag_then,
  961. (char *) bytes - frag_then->fr_literal,
  962. 0,
  963. abs_section_sym,
  964. rx_bytes.link_relax | rx_bytes.n_fixups,
  965. 0,
  966. BFD_RELOC_RX_RELAX);
  967. frag_then->tc_frag_data->link_relax_fixP = f;
  968. }
  969. for (i = 0; i < rx_bytes.n_fixups; i ++)
  970. {
  971. /* index: [nbytes][type] */
  972. static int reloc_map[5][4] =
  973. {
  974. { 0, 0, 0, BFD_RELOC_RX_DIR3U_PCREL },
  975. { BFD_RELOC_8, BFD_RELOC_RX_8U, BFD_RELOC_RX_NEG8, BFD_RELOC_8_PCREL },
  976. { BFD_RELOC_RX_16_OP, BFD_RELOC_RX_16U, BFD_RELOC_RX_NEG16, BFD_RELOC_16_PCREL },
  977. { BFD_RELOC_RX_24_OP, BFD_RELOC_RX_24U, BFD_RELOC_RX_NEG24, BFD_RELOC_24_PCREL },
  978. { BFD_RELOC_RX_32_OP, BFD_RELOC_32, BFD_RELOC_RX_NEG32, BFD_RELOC_32_PCREL },
  979. };
  980. fixS * f;
  981. idx = rx_bytes.fixups[i].offset / 8;
  982. rel = reloc_map [rx_bytes.fixups[i].nbits / 8][(int) rx_bytes.fixups[i].type];
  983. if (rx_bytes.fixups[i].reloc)
  984. rel = rx_bytes.fixups[i].reloc;
  985. if (frag_then->tc_frag_data)
  986. exp = & frag_then->tc_frag_data->fixups[i].exp;
  987. else
  988. exp = & rx_bytes.fixups[i].exp;
  989. f = fix_new_exp (frag_then,
  990. (char *) bytes + idx - frag_then->fr_literal,
  991. rx_bytes.fixups[i].nbits / 8,
  992. exp,
  993. rx_bytes.fixups[i].type == RXREL_PCREL ? 1 : 0,
  994. rel);
  995. if (frag_then->tc_frag_data)
  996. frag_then->tc_frag_data->fixups[i].fixP = f;
  997. }
  998. dwarf2_emit_insn (idx);
  999. }
  1000. void
  1001. rx_md_end (void)
  1002. {
  1003. }
  1004. /* Write a value out to the object file, using the appropriate endianness. */
  1005. void
  1006. md_number_to_chars (char * buf, valueT val, int n)
  1007. {
  1008. if (target_big_endian)
  1009. number_to_chars_bigendian (buf, val, n);
  1010. else
  1011. number_to_chars_littleendian (buf, val, n);
  1012. }
  1013. static struct
  1014. {
  1015. char * fname;
  1016. int reloc;
  1017. }
  1018. reloc_functions[] =
  1019. {
  1020. { "gp", BFD_RELOC_GPREL16 },
  1021. { 0, 0 }
  1022. };
  1023. void
  1024. md_operand (expressionS * exp ATTRIBUTE_UNUSED)
  1025. {
  1026. int reloc = 0;
  1027. int i;
  1028. for (i = 0; reloc_functions[i].fname; i++)
  1029. {
  1030. int flen = strlen (reloc_functions[i].fname);
  1031. if (input_line_pointer[0] == '%'
  1032. && strncasecmp (input_line_pointer + 1, reloc_functions[i].fname, flen) == 0
  1033. && input_line_pointer[flen + 1] == '(')
  1034. {
  1035. reloc = reloc_functions[i].reloc;
  1036. input_line_pointer += flen + 2;
  1037. break;
  1038. }
  1039. }
  1040. if (reloc == 0)
  1041. return;
  1042. expression (exp);
  1043. if (* input_line_pointer == ')')
  1044. input_line_pointer ++;
  1045. exp->X_md = reloc;
  1046. }
  1047. valueT
  1048. md_section_align (segT segment, valueT size)
  1049. {
  1050. int align = bfd_get_section_alignment (stdoutput, segment);
  1051. return ((size + (1 << align) - 1) & (-1 << align));
  1052. }
  1053. /* NOP - 1 cycle */
  1054. static unsigned char nop_1[] = { 0x03};
  1055. /* MOV.L R0,R0 - 1 cycle */
  1056. static unsigned char nop_2[] = { 0xef, 0x00};
  1057. /* MAX R0,R0 - 1 cycle */
  1058. static unsigned char nop_3[] = { 0xfc, 0x13, 0x00 };
  1059. /* MUL #1,R0 - 1 cycle */
  1060. static unsigned char nop_4[] = { 0x76, 0x10, 0x01, 0x00 };
  1061. /* MUL #1,R0 - 1 cycle */
  1062. static unsigned char nop_5[] = { 0x77, 0x10, 0x01, 0x00, 0x00 };
  1063. /* MUL #1,R0 - 1 cycle */
  1064. static unsigned char nop_6[] = { 0x74, 0x10, 0x01, 0x00, 0x00, 0x00 };
  1065. /* MAX 0x80000000,R0 - 1 cycle */
  1066. static unsigned char nop_7[] = { 0xFD, 0x70, 0x40, 0x00, 0x00, 0x00, 0x80 };
  1067. static unsigned char *nops[] = { NULL, nop_1, nop_2, nop_3, nop_4, nop_5, nop_6, nop_7 };
  1068. #define BIGGEST_NOP 7
  1069. /* When relaxing, we need to output a reloc for any .align directive
  1070. so that we can retain this alignment as we adjust opcode sizes. */
  1071. void
  1072. rx_handle_align (fragS * frag)
  1073. {
  1074. /* If handling an alignment frag, use an optimal NOP pattern.
  1075. Only do this if a fill value has not already been provided.
  1076. FIXME: This test fails if the provided fill value is zero. */
  1077. if ((frag->fr_type == rs_align
  1078. || frag->fr_type == rs_align_code)
  1079. && subseg_text_p (now_seg))
  1080. {
  1081. int count = (frag->fr_next->fr_address
  1082. - frag->fr_address
  1083. - frag->fr_fix);
  1084. unsigned char *base = (unsigned char *)frag->fr_literal + frag->fr_fix;
  1085. if (* base == 0)
  1086. {
  1087. if (count > BIGGEST_NOP)
  1088. {
  1089. base[0] = 0x2e;
  1090. base[1] = count;
  1091. frag->fr_var = 2;
  1092. }
  1093. else if (count > 0)
  1094. {
  1095. memcpy (base, nops[count], count);
  1096. frag->fr_var = count;
  1097. }
  1098. }
  1099. }
  1100. if (linkrelax
  1101. && (frag->fr_type == rs_align
  1102. || frag->fr_type == rs_align_code)
  1103. && frag->fr_address + frag->fr_fix > 0
  1104. && frag->fr_offset > 0
  1105. && now_seg != bss_section)
  1106. {
  1107. fix_new (frag, frag->fr_fix, 0,
  1108. &abs_symbol, RX_RELAXA_ALIGN + frag->fr_offset,
  1109. 0, BFD_RELOC_RX_RELAX);
  1110. /* For the purposes of relaxation, this relocation is attached
  1111. to the byte *after* the alignment - i.e. the byte that must
  1112. remain aligned. */
  1113. fix_new (frag->fr_next, 0, 0,
  1114. &abs_symbol, RX_RELAXA_ELIGN + frag->fr_offset,
  1115. 0, BFD_RELOC_RX_RELAX);
  1116. }
  1117. }
  1118. char *
  1119. md_atof (int type, char * litP, int * sizeP)
  1120. {
  1121. return ieee_md_atof (type, litP, sizeP, target_big_endian);
  1122. }
  1123. symbolS *
  1124. md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
  1125. {
  1126. return NULL;
  1127. }
  1128. /*----------------------------------------------------------------------*/
  1129. /* To recap: we estimate everything based on md_estimate_size, then
  1130. adjust based on rx_relax_frag. When it all settles, we call
  1131. md_convert frag to update the bytes. The relaxation types and
  1132. relocations are in fragP->tc_frag_data, which is a copy of that
  1133. rx_bytes.
  1134. Our scheme is as follows: fr_fix has the size of the smallest
  1135. opcode (like BRA.S). We store the number of total bytes we need in
  1136. fr_subtype. When we're done relaxing, we use fr_subtype and the
  1137. existing opcode bytes to figure out what actual opcode we need to
  1138. put in there. If the fixup isn't resolvable now, we use the
  1139. maximal size. */
  1140. #define TRACE_RELAX 0
  1141. #define tprintf if (TRACE_RELAX) printf
  1142. typedef enum
  1143. {
  1144. OT_other,
  1145. OT_bra,
  1146. OT_beq,
  1147. OT_bne,
  1148. OT_bsr,
  1149. OT_bcc
  1150. } op_type_T;
  1151. /* We're looking for these types of relaxations:
  1152. BRA.S 00001dsp
  1153. BRA.B 00101110 dspppppp
  1154. BRA.W 00111000 dspppppp pppppppp
  1155. BRA.A 00000100 dspppppp pppppppp pppppppp
  1156. BEQ.S 00010dsp
  1157. BEQ.B 00100000 dspppppp
  1158. BEQ.W 00111010 dspppppp pppppppp
  1159. BNE.S 00011dsp
  1160. BNE.B 00100001 dspppppp
  1161. BNE.W 00111011 dspppppp pppppppp
  1162. BSR.W 00111001 dspppppp pppppppp
  1163. BSR.A 00000101 dspppppp pppppppp pppppppp
  1164. Bcc.B 0010cond dspppppp
  1165. Additionally, we can synthesize longer conditional branches using
  1166. pairs of opcodes, one with an inverted conditional (flip LSB):
  1167. Bcc.W 0010ncnd 00000110 00111000 dspppppp pppppppp
  1168. Bcc.A 0010ncnd 00000111 00000100 dspppppp pppppppp pppppppp
  1169. BEQ.A 00011100 00000100 dspppppp pppppppp pppppppp
  1170. BNE.A 00010100 00000100 dspppppp pppppppp pppppppp */
  1171. /* Given the opcode bytes at OP, figure out which opcode it is and
  1172. return the type of opcode. We use this to re-encode the opcode as
  1173. a different size later. */
  1174. static op_type_T
  1175. rx_opcode_type (char * op)
  1176. {
  1177. unsigned char b = (unsigned char) op[0];
  1178. switch (b & 0xf8)
  1179. {
  1180. case 0x08: return OT_bra;
  1181. case 0x10: return OT_beq;
  1182. case 0x18: return OT_bne;
  1183. }
  1184. switch (b)
  1185. {
  1186. case 0x2e: return OT_bra;
  1187. case 0x38: return OT_bra;
  1188. case 0x04: return OT_bra;
  1189. case 0x20: return OT_beq;
  1190. case 0x3a: return OT_beq;
  1191. case 0x21: return OT_bne;
  1192. case 0x3b: return OT_bne;
  1193. case 0x39: return OT_bsr;
  1194. case 0x05: return OT_bsr;
  1195. }
  1196. if ((b & 0xf0) == 0x20)
  1197. return OT_bcc;
  1198. return OT_other;
  1199. }
  1200. /* Returns zero if *addrP has the target address. Else returns nonzero
  1201. if we cannot compute the target address yet. */
  1202. static int
  1203. rx_frag_fix_value (fragS * fragP,
  1204. segT segment,
  1205. int which,
  1206. addressT * addrP,
  1207. int need_diff,
  1208. addressT * sym_addr)
  1209. {
  1210. addressT addr = 0;
  1211. rx_bytesT * b = fragP->tc_frag_data;
  1212. expressionS * exp = & b->fixups[which].exp;
  1213. if (need_diff && exp->X_op != O_subtract)
  1214. return 1;
  1215. if (exp->X_add_symbol)
  1216. {
  1217. if (S_FORCE_RELOC (exp->X_add_symbol, 1))
  1218. return 1;
  1219. if (S_GET_SEGMENT (exp->X_add_symbol) != segment)
  1220. return 1;
  1221. addr += S_GET_VALUE (exp->X_add_symbol);
  1222. }
  1223. if (exp->X_op_symbol)
  1224. {
  1225. if (exp->X_op != O_subtract)
  1226. return 1;
  1227. if (S_FORCE_RELOC (exp->X_op_symbol, 1))
  1228. return 1;
  1229. if (S_GET_SEGMENT (exp->X_op_symbol) != segment)
  1230. return 1;
  1231. addr -= S_GET_VALUE (exp->X_op_symbol);
  1232. }
  1233. if (sym_addr)
  1234. * sym_addr = addr;
  1235. addr += exp->X_add_number;
  1236. * addrP = addr;
  1237. return 0;
  1238. }
  1239. /* Estimate how big the opcode is after this relax pass. The return
  1240. value is the difference between fr_fix and the actual size. We
  1241. compute the total size in rx_relax_frag and store it in fr_subtype,
  1242. sowe only need to subtract fx_fix and return it. */
  1243. int
  1244. md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED, segT segment ATTRIBUTE_UNUSED)
  1245. {
  1246. int opfixsize;
  1247. int delta;
  1248. tprintf ("\033[32m est frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
  1249. (unsigned long) (fragP->fr_address
  1250. + (fragP->fr_opcode - fragP->fr_literal)),
  1251. (long) fragP->fr_fix, (long) fragP->fr_var, (long) fragP->fr_offset,
  1252. fragP->fr_literal, fragP->fr_opcode, fragP->fr_type, fragP->fr_subtype);
  1253. /* This is the size of the opcode that's accounted for in fr_fix. */
  1254. opfixsize = fragP->fr_fix - (fragP->fr_opcode - fragP->fr_literal);
  1255. /* This is the size of the opcode that isn't. */
  1256. delta = (fragP->fr_subtype - opfixsize);
  1257. tprintf (" -> opfixsize %d delta %d\n", opfixsize, delta);
  1258. return delta;
  1259. }
  1260. /* Given a frag FRAGP, return the "next" frag that contains an
  1261. opcode. Assumes the next opcode is relaxable, and thus rs_machine_dependent. */
  1262. static fragS *
  1263. rx_next_opcode (fragS *fragP)
  1264. {
  1265. do {
  1266. fragP = fragP->fr_next;
  1267. } while (fragP && fragP->fr_type != rs_machine_dependent);
  1268. return fragP;
  1269. }
  1270. /* Given the new addresses for this relax pass, figure out how big
  1271. each opcode must be. We store the total number of bytes needed in
  1272. fr_subtype. The return value is the difference between the size
  1273. after the last pass and the size after this pass, so we use the old
  1274. fr_subtype to calculate the difference. */
  1275. int
  1276. rx_relax_frag (segT segment ATTRIBUTE_UNUSED, fragS * fragP, long stretch)
  1277. {
  1278. addressT addr0, sym_addr;
  1279. addressT mypc;
  1280. int disp;
  1281. int oldsize = fragP->fr_subtype;
  1282. int newsize = oldsize;
  1283. op_type_T optype;
  1284. /* Index of relaxation we care about. */
  1285. int ri;
  1286. tprintf ("\033[36mrelax frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d str %ld\033[0m\n",
  1287. (unsigned long) (fragP->fr_address
  1288. + (fragP->fr_opcode - fragP->fr_literal)),
  1289. (long) fragP->fr_fix, (long) fragP->fr_var, (long) fragP->fr_offset,
  1290. fragP->fr_literal, fragP->fr_opcode, fragP->fr_type, fragP->fr_subtype, stretch);
  1291. mypc = fragP->fr_address + (fragP->fr_opcode - fragP->fr_literal);
  1292. if (fragP->tc_frag_data->n_base == RX_NBASE_FETCHALIGN)
  1293. {
  1294. unsigned int next_size;
  1295. if (fragP->fr_next == NULL)
  1296. return 0;
  1297. next_size = fragP->tc_frag_data->n_ops;
  1298. if (next_size == 0)
  1299. {
  1300. fragS *n = rx_next_opcode (fragP);
  1301. next_size = n->fr_subtype;
  1302. }
  1303. fragP->fr_subtype = (8-(mypc & 7)) & 7;
  1304. tprintf("subtype %u\n", fragP->fr_subtype);
  1305. if (fragP->fr_subtype >= next_size)
  1306. fragP->fr_subtype = 0;
  1307. tprintf ("\033[34m -> mypc %lu next_size %u new %d old %d delta %d (fetchalign)\033[0m\n",
  1308. mypc & 7,
  1309. next_size, fragP->fr_subtype, oldsize, fragP->fr_subtype-oldsize);
  1310. newsize = fragP->fr_subtype;
  1311. return newsize - oldsize;
  1312. }
  1313. optype = rx_opcode_type (fragP->fr_opcode);
  1314. /* In the one case where we have both a disp and imm relaxation, we want
  1315. the imm relaxation here. */
  1316. ri = 0;
  1317. if (fragP->tc_frag_data->n_relax > 1
  1318. && fragP->tc_frag_data->relax[0].type == RX_RELAX_DISP)
  1319. ri = 1;
  1320. /* Try to get the target address. */
  1321. if (rx_frag_fix_value (fragP, segment, ri, & addr0,
  1322. fragP->tc_frag_data->relax[ri].type != RX_RELAX_BRANCH,
  1323. & sym_addr))
  1324. {
  1325. /* If we don't, we must use the maximum size for the linker.
  1326. Note that we don't use synthetically expanded conditionals
  1327. for this. */
  1328. switch (fragP->tc_frag_data->relax[ri].type)
  1329. {
  1330. case RX_RELAX_BRANCH:
  1331. switch (optype)
  1332. {
  1333. case OT_bra:
  1334. case OT_bsr:
  1335. newsize = 4;
  1336. break;
  1337. case OT_beq:
  1338. case OT_bne:
  1339. newsize = 3;
  1340. break;
  1341. case OT_bcc:
  1342. newsize = 2;
  1343. break;
  1344. case OT_other:
  1345. newsize = oldsize;
  1346. break;
  1347. }
  1348. break;
  1349. case RX_RELAX_IMM:
  1350. newsize = fragP->tc_frag_data->relax[ri].val_ofs + 4;
  1351. break;
  1352. }
  1353. fragP->fr_subtype = newsize;
  1354. tprintf (" -> new %d old %d delta %d (external)\n", newsize, oldsize, newsize-oldsize);
  1355. return newsize - oldsize;
  1356. }
  1357. if (sym_addr > mypc)
  1358. addr0 += stretch;
  1359. switch (fragP->tc_frag_data->relax[ri].type)
  1360. {
  1361. case RX_RELAX_BRANCH:
  1362. tprintf ("branch, addr %08lx pc %08lx disp %ld\n",
  1363. (unsigned long) addr0, (unsigned long) mypc,
  1364. (long) (addr0 - mypc));
  1365. disp = (int) addr0 - (int) mypc;
  1366. switch (optype)
  1367. {
  1368. case OT_bcc:
  1369. if (disp >= -128 && (disp - (oldsize-2)) <= 127)
  1370. /* bcc.b */
  1371. newsize = 2;
  1372. else if (disp >= -32768 && (disp - (oldsize-5)) <= 32767)
  1373. /* bncc.b/bra.w */
  1374. newsize = 5;
  1375. else
  1376. /* bncc.b/bra.a */
  1377. newsize = 6;
  1378. break;
  1379. case OT_beq:
  1380. case OT_bne:
  1381. if ((disp - (oldsize-1)) >= 3 && (disp - (oldsize-1)) <= 10 && !linkrelax)
  1382. /* beq.s */
  1383. newsize = 1;
  1384. else if (disp >= -128 && (disp - (oldsize-2)) <= 127)
  1385. /* beq.b */
  1386. newsize = 2;
  1387. else if (disp >= -32768 && (disp - (oldsize-3)) <= 32767)
  1388. /* beq.w */
  1389. newsize = 3;
  1390. else
  1391. /* bne.s/bra.a */
  1392. newsize = 5;
  1393. break;
  1394. case OT_bra:
  1395. case OT_bsr:
  1396. if ((disp - (oldsize-1)) >= 3 && (disp - (oldsize-1)) <= 10 && !linkrelax)
  1397. /* bra.s */
  1398. newsize = 1;
  1399. else if (disp >= -128 && (disp - (oldsize-2)) <= 127)
  1400. /* bra.b */
  1401. newsize = 2;
  1402. else if (disp >= -32768 && (disp - (oldsize-3)) <= 32767)
  1403. /* bra.w */
  1404. newsize = 3;
  1405. else
  1406. /* bra.a */
  1407. newsize = 4;
  1408. break;
  1409. case OT_other:
  1410. break;
  1411. }
  1412. tprintf (" - newsize %d\n", newsize);
  1413. break;
  1414. case RX_RELAX_IMM:
  1415. tprintf ("other, addr %08lx pc %08lx LI %d OF %d\n",
  1416. (unsigned long) addr0, (unsigned long) mypc,
  1417. fragP->tc_frag_data->relax[ri].field_pos,
  1418. fragP->tc_frag_data->relax[ri].val_ofs);
  1419. newsize = fragP->tc_frag_data->relax[ri].val_ofs;
  1420. if ((long) addr0 >= -128 && (long) addr0 <= 127)
  1421. newsize += 1;
  1422. else if ((long) addr0 >= -32768 && (long) addr0 <= 32767)
  1423. newsize += 2;
  1424. else if ((long) addr0 >= -8388608 && (long) addr0 <= 8388607)
  1425. newsize += 3;
  1426. else
  1427. newsize += 4;
  1428. break;
  1429. default:
  1430. break;
  1431. }
  1432. if (fragP->tc_frag_data->relax[ri].type == RX_RELAX_BRANCH)
  1433. switch (optype)
  1434. {
  1435. case OT_bra:
  1436. case OT_bcc:
  1437. case OT_beq:
  1438. case OT_bne:
  1439. break;
  1440. case OT_bsr:
  1441. if (newsize < 3)
  1442. newsize = 3;
  1443. break;
  1444. case OT_other:
  1445. break;
  1446. }
  1447. /* This prevents infinite loops in align-heavy sources. */
  1448. if (newsize < oldsize)
  1449. {
  1450. if (fragP->tc_frag_data->times_shrank > 10
  1451. && fragP->tc_frag_data->times_grown > 10)
  1452. newsize = oldsize;
  1453. if (fragP->tc_frag_data->times_shrank < 20)
  1454. fragP->tc_frag_data->times_shrank ++;
  1455. }
  1456. else if (newsize > oldsize)
  1457. {
  1458. if (fragP->tc_frag_data->times_grown < 20)
  1459. fragP->tc_frag_data->times_grown ++;
  1460. }
  1461. fragP->fr_subtype = newsize;
  1462. tprintf (" -> new %d old %d delta %d\n", newsize, oldsize, newsize-oldsize);
  1463. return newsize - oldsize;
  1464. }
  1465. /* This lets us test for the opcode type and the desired size in a
  1466. switch statement. */
  1467. #define OPCODE(type,size) ((type) * 16 + (size))
  1468. /* Given the opcode stored in fr_opcode and the number of bytes we
  1469. think we need, encode a new opcode. We stored a pointer to the
  1470. fixup for this opcode in the tc_frag_data structure. If we can do
  1471. the fixup here, we change the relocation type to "none" (we test
  1472. for that in tc_gen_reloc) else we change it to the right type for
  1473. the new (biggest) opcode. */
  1474. void
  1475. md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED,
  1476. segT segment ATTRIBUTE_UNUSED,
  1477. fragS * fragP ATTRIBUTE_UNUSED)
  1478. {
  1479. rx_bytesT * rxb = fragP->tc_frag_data;
  1480. addressT addr0, mypc;
  1481. int disp;
  1482. int reloc_type, reloc_adjust;
  1483. char * op = fragP->fr_opcode;
  1484. int keep_reloc = 0;
  1485. int ri;
  1486. int fi = (rxb->n_fixups > 1) ? 1 : 0;
  1487. fixS * fix = rxb->fixups[fi].fixP;
  1488. tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
  1489. (unsigned long) (fragP->fr_address
  1490. + (fragP->fr_opcode - fragP->fr_literal)),
  1491. (long) fragP->fr_fix, (long) fragP->fr_var, (long) fragP->fr_offset,
  1492. fragP->fr_literal, fragP->fr_opcode, fragP->fr_type,
  1493. fragP->fr_subtype);
  1494. #if TRACE_RELAX
  1495. {
  1496. int i;
  1497. printf ("lit 0x%p opc 0x%p", fragP->fr_literal, fragP->fr_opcode);
  1498. for (i = 0; i < 10; i++)
  1499. printf (" %02x", (unsigned char) (fragP->fr_opcode[i]));
  1500. printf ("\n");
  1501. }
  1502. #endif
  1503. if (fragP->tc_frag_data->n_base == RX_NBASE_FETCHALIGN)
  1504. {
  1505. int count = fragP->fr_subtype;
  1506. if (count == 0)
  1507. ;
  1508. else if (count > BIGGEST_NOP)
  1509. {
  1510. op[0] = 0x2e;
  1511. op[1] = count;
  1512. }
  1513. else if (count > 0)
  1514. {
  1515. memcpy (op, nops[count], count);
  1516. }
  1517. }
  1518. /* In the one case where we have both a disp and imm relaxation, we want
  1519. the imm relaxation here. */
  1520. ri = 0;
  1521. if (fragP->tc_frag_data->n_relax > 1
  1522. && fragP->tc_frag_data->relax[0].type == RX_RELAX_DISP)
  1523. ri = 1;
  1524. /* We used a new frag for this opcode, so the opcode address should
  1525. be the frag address. */
  1526. mypc = fragP->fr_address + (fragP->fr_opcode - fragP->fr_literal);
  1527. /* Try to get the target address. If we fail here, we just use the
  1528. largest format. */
  1529. if (rx_frag_fix_value (fragP, segment, 0, & addr0,
  1530. fragP->tc_frag_data->relax[ri].type != RX_RELAX_BRANCH, 0))
  1531. {
  1532. /* We don't know the target address. */
  1533. keep_reloc = 1;
  1534. addr0 = 0;
  1535. disp = 0;
  1536. }
  1537. else
  1538. {
  1539. /* We know the target address, and it's in addr0. */
  1540. disp = (int) addr0 - (int) mypc;
  1541. }
  1542. if (linkrelax)
  1543. keep_reloc = 1;
  1544. reloc_type = BFD_RELOC_NONE;
  1545. reloc_adjust = 0;
  1546. tprintf ("convert, op is %d, disp %d (%lx-%lx)\n",
  1547. rx_opcode_type (fragP->fr_opcode), disp,
  1548. (unsigned long) addr0, (unsigned long) mypc);
  1549. switch (fragP->tc_frag_data->relax[ri].type)
  1550. {
  1551. case RX_RELAX_BRANCH:
  1552. switch (OPCODE (rx_opcode_type (fragP->fr_opcode), fragP->fr_subtype))
  1553. {
  1554. case OPCODE (OT_bra, 1): /* BRA.S - no change. */
  1555. op[0] = 0x08 + (disp & 7);
  1556. break;
  1557. case OPCODE (OT_bra, 2): /* BRA.B - 8 bit. */
  1558. op[0] = 0x2e;
  1559. op[1] = disp;
  1560. reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE;
  1561. reloc_adjust = 1;
  1562. break;
  1563. case OPCODE (OT_bra, 3): /* BRA.W - 16 bit. */
  1564. op[0] = 0x38;
  1565. #if RX_OPCODE_BIG_ENDIAN
  1566. op[1] = (disp >> 8) & 0xff;
  1567. op[2] = disp;
  1568. #else
  1569. op[2] = (disp >> 8) & 0xff;
  1570. op[1] = disp;
  1571. #endif
  1572. reloc_adjust = 1;
  1573. reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
  1574. break;
  1575. case OPCODE (OT_bra, 4): /* BRA.A - 24 bit. */
  1576. op[0] = 0x04;
  1577. #if RX_OPCODE_BIG_ENDIAN
  1578. op[1] = (disp >> 16) & 0xff;
  1579. op[2] = (disp >> 8) & 0xff;
  1580. op[3] = disp;
  1581. #else
  1582. op[3] = (disp >> 16) & 0xff;
  1583. op[2] = (disp >> 8) & 0xff;
  1584. op[1] = disp;
  1585. #endif
  1586. reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
  1587. reloc_adjust = 1;
  1588. break;
  1589. case OPCODE (OT_beq, 1): /* BEQ.S - no change. */
  1590. op[0] = 0x10 + (disp & 7);
  1591. break;
  1592. case OPCODE (OT_beq, 2): /* BEQ.B - 8 bit. */
  1593. op[0] = 0x20;
  1594. op[1] = disp;
  1595. reloc_adjust = 1;
  1596. reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE;
  1597. break;
  1598. case OPCODE (OT_beq, 3): /* BEQ.W - 16 bit. */
  1599. op[0] = 0x3a;
  1600. #if RX_OPCODE_BIG_ENDIAN
  1601. op[1] = (disp >> 8) & 0xff;
  1602. op[2] = disp;
  1603. #else
  1604. op[2] = (disp >> 8) & 0xff;
  1605. op[1] = disp;
  1606. #endif
  1607. reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
  1608. reloc_adjust = 1;
  1609. break;
  1610. case OPCODE (OT_beq, 5): /* BEQ.A - synthetic. */
  1611. op[0] = 0x1d; /* bne.s .+5. */
  1612. op[1] = 0x04; /* bra.a dsp:24. */
  1613. disp -= 1;
  1614. #if RX_OPCODE_BIG_ENDIAN
  1615. op[2] = (disp >> 16) & 0xff;
  1616. op[3] = (disp >> 8) & 0xff;
  1617. op[4] = disp;
  1618. #else
  1619. op[4] = (disp >> 16) & 0xff;
  1620. op[3] = (disp >> 8) & 0xff;
  1621. op[2] = disp;
  1622. #endif
  1623. reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
  1624. reloc_adjust = 2;
  1625. break;
  1626. case OPCODE (OT_bne, 1): /* BNE.S - no change. */
  1627. op[0] = 0x18 + (disp & 7);
  1628. break;
  1629. case OPCODE (OT_bne, 2): /* BNE.B - 8 bit. */
  1630. op[0] = 0x21;
  1631. op[1] = disp;
  1632. reloc_adjust = 1;
  1633. reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE;
  1634. break;
  1635. case OPCODE (OT_bne, 3): /* BNE.W - 16 bit. */
  1636. op[0] = 0x3b;
  1637. #if RX_OPCODE_BIG_ENDIAN
  1638. op[1] = (disp >> 8) & 0xff;
  1639. op[2] = disp;
  1640. #else
  1641. op[2] = (disp >> 8) & 0xff;
  1642. op[1] = disp;
  1643. #endif
  1644. reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
  1645. reloc_adjust = 1;
  1646. break;
  1647. case OPCODE (OT_bne, 5): /* BNE.A - synthetic. */
  1648. op[0] = 0x15; /* beq.s .+5. */
  1649. op[1] = 0x04; /* bra.a dsp:24. */
  1650. disp -= 1;
  1651. #if RX_OPCODE_BIG_ENDIAN
  1652. op[2] = (disp >> 16) & 0xff;
  1653. op[3] = (disp >> 8) & 0xff;
  1654. op[4] = disp;
  1655. #else
  1656. op[4] = (disp >> 16) & 0xff;
  1657. op[3] = (disp >> 8) & 0xff;
  1658. op[2] = disp;
  1659. #endif
  1660. reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
  1661. reloc_adjust = 2;
  1662. break;
  1663. case OPCODE (OT_bsr, 3): /* BSR.W - 16 bit. */
  1664. op[0] = 0x39;
  1665. #if RX_OPCODE_BIG_ENDIAN
  1666. op[1] = (disp >> 8) & 0xff;
  1667. op[2] = disp;
  1668. #else
  1669. op[2] = (disp >> 8) & 0xff;
  1670. op[1] = disp;
  1671. #endif
  1672. reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
  1673. reloc_adjust = 0;
  1674. break;
  1675. case OPCODE (OT_bsr, 4): /* BSR.A - 24 bit. */
  1676. op[0] = 0x05;
  1677. #if RX_OPCODE_BIG_ENDIAN
  1678. op[1] = (disp >> 16) & 0xff;
  1679. op[2] = (disp >> 8) & 0xff;
  1680. op[3] = disp;
  1681. #else
  1682. op[3] = (disp >> 16) & 0xff;
  1683. op[2] = (disp >> 8) & 0xff;
  1684. op[1] = disp;
  1685. #endif
  1686. reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
  1687. reloc_adjust = 0;
  1688. break;
  1689. case OPCODE (OT_bcc, 2): /* Bcond.B - 8 bit. */
  1690. op[1] = disp;
  1691. reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE;
  1692. break;
  1693. case OPCODE (OT_bcc, 5): /* Bcond.W - synthetic. */
  1694. op[0] ^= 1; /* Invert condition. */
  1695. op[1] = 5; /* Displacement. */
  1696. op[2] = 0x38;
  1697. disp -= 2;
  1698. #if RX_OPCODE_BIG_ENDIAN
  1699. op[3] = (disp >> 8) & 0xff;
  1700. op[4] = disp;
  1701. #else
  1702. op[4] = (disp >> 8) & 0xff;
  1703. op[3] = disp;
  1704. #endif
  1705. reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
  1706. reloc_adjust = 2;
  1707. break;
  1708. case OPCODE (OT_bcc, 6): /* Bcond.S - synthetic. */
  1709. op[0] ^= 1; /* Invert condition. */
  1710. op[1] = 6; /* Displacement. */
  1711. op[2] = 0x04;
  1712. disp -= 2;
  1713. #if RX_OPCODE_BIG_ENDIAN
  1714. op[3] = (disp >> 16) & 0xff;
  1715. op[4] = (disp >> 8) & 0xff;
  1716. op[5] = disp;
  1717. #else
  1718. op[5] = (disp >> 16) & 0xff;
  1719. op[4] = (disp >> 8) & 0xff;
  1720. op[3] = disp;
  1721. #endif
  1722. reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
  1723. reloc_adjust = 2;
  1724. break;
  1725. default:
  1726. /* These are opcodes we'll relax in th linker, later. */
  1727. if (rxb->n_fixups)
  1728. reloc_type = rxb->fixups[ri].fixP->fx_r_type;
  1729. break;
  1730. }
  1731. break;
  1732. case RX_RELAX_IMM:
  1733. {
  1734. int nbytes = fragP->fr_subtype - fragP->tc_frag_data->relax[ri].val_ofs;
  1735. int li;
  1736. char * imm = op + fragP->tc_frag_data->relax[ri].val_ofs;
  1737. switch (nbytes)
  1738. {
  1739. case 1:
  1740. li = 1;
  1741. imm[0] = addr0;
  1742. reloc_type = BFD_RELOC_8;
  1743. break;
  1744. case 2:
  1745. li = 2;
  1746. #if RX_OPCODE_BIG_ENDIAN
  1747. imm[1] = addr0;
  1748. imm[0] = addr0 >> 8;
  1749. #else
  1750. imm[0] = addr0;
  1751. imm[1] = addr0 >> 8;
  1752. #endif
  1753. reloc_type = BFD_RELOC_RX_16_OP;
  1754. break;
  1755. case 3:
  1756. li = 3;
  1757. #if RX_OPCODE_BIG_ENDIAN
  1758. imm[2] = addr0;
  1759. imm[1] = addr0 >> 8;
  1760. imm[0] = addr0 >> 16;
  1761. #else
  1762. imm[0] = addr0;
  1763. imm[1] = addr0 >> 8;
  1764. imm[2] = addr0 >> 16;
  1765. #endif
  1766. reloc_type = BFD_RELOC_RX_24_OP;
  1767. break;
  1768. case 4:
  1769. li = 0;
  1770. #if RX_OPCODE_BIG_ENDIAN
  1771. imm[3] = addr0;
  1772. imm[2] = addr0 >> 8;
  1773. imm[1] = addr0 >> 16;
  1774. imm[0] = addr0 >> 24;
  1775. #else
  1776. imm[0] = addr0;
  1777. imm[1] = addr0 >> 8;
  1778. imm[2] = addr0 >> 16;
  1779. imm[3] = addr0 >> 24;
  1780. #endif
  1781. reloc_type = BFD_RELOC_RX_32_OP;
  1782. break;
  1783. default:
  1784. as_bad (_("invalid immediate size"));
  1785. li = -1;
  1786. }
  1787. switch (fragP->tc_frag_data->relax[ri].field_pos)
  1788. {
  1789. case 6:
  1790. op[0] &= 0xfc;
  1791. op[0] |= li;
  1792. break;
  1793. case 12:
  1794. op[1] &= 0xf3;
  1795. op[1] |= li << 2;
  1796. break;
  1797. case 20:
  1798. op[2] &= 0xf3;
  1799. op[2] |= li << 2;
  1800. break;
  1801. default:
  1802. as_bad (_("invalid immediate field position"));
  1803. }
  1804. }
  1805. break;
  1806. default:
  1807. if (rxb->n_fixups)
  1808. {
  1809. reloc_type = fix->fx_r_type;
  1810. reloc_adjust = 0;
  1811. }
  1812. break;
  1813. }
  1814. if (rxb->n_fixups)
  1815. {
  1816. fix->fx_r_type = reloc_type;
  1817. fix->fx_where += reloc_adjust;
  1818. switch (reloc_type)
  1819. {
  1820. case BFD_RELOC_NONE:
  1821. fix->fx_size = 0;
  1822. break;
  1823. case BFD_RELOC_8:
  1824. fix->fx_size = 1;
  1825. break;
  1826. case BFD_RELOC_16_PCREL:
  1827. case BFD_RELOC_RX_16_OP:
  1828. fix->fx_size = 2;
  1829. break;
  1830. case BFD_RELOC_24_PCREL:
  1831. case BFD_RELOC_RX_24_OP:
  1832. fix->fx_size = 3;
  1833. break;
  1834. case BFD_RELOC_RX_32_OP:
  1835. fix->fx_size = 4;
  1836. break;
  1837. }
  1838. }
  1839. fragP->fr_fix = fragP->fr_subtype + (fragP->fr_opcode - fragP->fr_literal);
  1840. tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", (long) fragP->fr_fix,
  1841. fragP->fr_subtype, fragP->fr_opcode, fragP->fr_literal);
  1842. fragP->fr_var = 0;
  1843. if (fragP->fr_next != NULL
  1844. && ((offsetT) (fragP->fr_next->fr_address - fragP->fr_address)
  1845. != fragP->fr_fix))
  1846. as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP,
  1847. (long) fragP->fr_fix,
  1848. (long) fragP->fr_address, (long) fragP->fr_next->fr_address);
  1849. }
  1850. #undef OPCODE
  1851. int
  1852. rx_validate_fix_sub (struct fix * f)
  1853. {
  1854. /* We permit the subtraction of two symbols in a few cases. */
  1855. /* mov #sym1-sym2, R3 */
  1856. if (f->fx_r_type == BFD_RELOC_RX_32_OP)
  1857. return 1;
  1858. /* .long sym1-sym2 */
  1859. if (f->fx_r_type == BFD_RELOC_RX_DIFF
  1860. && ! f->fx_pcrel
  1861. && (f->fx_size == 4 || f->fx_size == 2 || f->fx_size == 1))
  1862. return 1;
  1863. return 0;
  1864. }
  1865. long
  1866. md_pcrel_from_section (fixS * fixP, segT sec)
  1867. {
  1868. long rv;
  1869. if (fixP->fx_addsy != NULL
  1870. && (! S_IS_DEFINED (fixP->fx_addsy)
  1871. || S_GET_SEGMENT (fixP->fx_addsy) != sec))
  1872. /* The symbol is undefined (or is defined but not in this section).
  1873. Let the linker figure it out. */
  1874. return 0;
  1875. rv = fixP->fx_frag->fr_address + fixP->fx_where;
  1876. switch (fixP->fx_r_type)
  1877. {
  1878. case BFD_RELOC_RX_DIR3U_PCREL:
  1879. return rv;
  1880. default:
  1881. return rv - 1;
  1882. }
  1883. }
  1884. void
  1885. rx_cons_fix_new (fragS * frag,
  1886. int where,
  1887. int size,
  1888. expressionS * exp,
  1889. bfd_reloc_code_real_type type)
  1890. {
  1891. switch (size)
  1892. {
  1893. case 1:
  1894. type = BFD_RELOC_8;
  1895. break;
  1896. case 2:
  1897. type = BFD_RELOC_16;
  1898. break;
  1899. case 3:
  1900. type = BFD_RELOC_24;
  1901. break;
  1902. case 4:
  1903. type = BFD_RELOC_32;
  1904. break;
  1905. default:
  1906. as_bad (_("unsupported constant size %d\n"), size);
  1907. return;
  1908. }
  1909. if (exp->X_op == O_subtract && exp->X_op_symbol)
  1910. {
  1911. if (size != 4 && size != 2 && size != 1)
  1912. as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
  1913. else
  1914. type = BFD_RELOC_RX_DIFF;
  1915. }
  1916. fix_new_exp (frag, where, (int) size, exp, 0, type);
  1917. }
  1918. void
  1919. md_apply_fix (struct fix * f ATTRIBUTE_UNUSED,
  1920. valueT * t ATTRIBUTE_UNUSED,
  1921. segT s ATTRIBUTE_UNUSED)
  1922. {
  1923. /* Instruction bytes are always little endian. */
  1924. char * op;
  1925. unsigned long val;
  1926. if (f->fx_addsy && S_FORCE_RELOC (f->fx_addsy, 1))
  1927. return;
  1928. if (f->fx_subsy && S_FORCE_RELOC (f->fx_subsy, 1))
  1929. return;
  1930. #define OP2(x) op[target_big_endian ? 1-x : x]
  1931. #define OP3(x) op[target_big_endian ? 2-x : x]
  1932. #define OP4(x) op[target_big_endian ? 3-x : x]
  1933. op = f->fx_frag->fr_literal + f->fx_where;
  1934. val = (unsigned long) * t;
  1935. /* Opcode words are always the same endian. Data words are either
  1936. big or little endian. */
  1937. switch (f->fx_r_type)
  1938. {
  1939. case BFD_RELOC_NONE:
  1940. break;
  1941. case BFD_RELOC_RX_RELAX:
  1942. f->fx_done = 1;
  1943. break;
  1944. case BFD_RELOC_RX_DIR3U_PCREL:
  1945. if (val < 3 || val > 10)
  1946. as_bad_where (f->fx_file, f->fx_line,
  1947. _("jump not 3..10 bytes away (is %d)"), (int) val);
  1948. op[0] &= 0xf8;
  1949. op[0] |= val & 0x07;
  1950. break;
  1951. case BFD_RELOC_8:
  1952. case BFD_RELOC_8_PCREL:
  1953. case BFD_RELOC_RX_8U:
  1954. op[0] = val;
  1955. break;
  1956. case BFD_RELOC_16:
  1957. OP2(1) = val & 0xff;
  1958. OP2(0) = (val >> 8) & 0xff;
  1959. break;
  1960. case BFD_RELOC_16_PCREL:
  1961. case BFD_RELOC_RX_16_OP:
  1962. case BFD_RELOC_RX_16U:
  1963. #if RX_OPCODE_BIG_ENDIAN
  1964. op[1] = val & 0xff;
  1965. op[0] = (val >> 8) & 0xff;
  1966. #else
  1967. op[0] = val & 0xff;
  1968. op[1] = (val >> 8) & 0xff;
  1969. #endif
  1970. break;
  1971. case BFD_RELOC_24:
  1972. OP3(0) = val & 0xff;
  1973. OP3(1) = (val >> 8) & 0xff;
  1974. OP3(2) = (val >> 16) & 0xff;
  1975. break;
  1976. case BFD_RELOC_24_PCREL:
  1977. case BFD_RELOC_RX_24_OP:
  1978. case BFD_RELOC_RX_24U:
  1979. #if RX_OPCODE_BIG_ENDIAN
  1980. op[2] = val & 0xff;
  1981. op[1] = (val >> 8) & 0xff;
  1982. op[0] = (val >> 16) & 0xff;
  1983. #else
  1984. op[0] = val & 0xff;
  1985. op[1] = (val >> 8) & 0xff;
  1986. op[2] = (val >> 16) & 0xff;
  1987. #endif
  1988. break;
  1989. case BFD_RELOC_RX_DIFF:
  1990. switch (f->fx_size)
  1991. {
  1992. case 1:
  1993. op[0] = val & 0xff;
  1994. break;
  1995. case 2:
  1996. OP2(0) = val & 0xff;
  1997. OP2(1) = (val >> 8) & 0xff;
  1998. break;
  1999. case 4:
  2000. OP4(0) = val & 0xff;
  2001. OP4(1) = (val >> 8) & 0xff;
  2002. OP4(2) = (val >> 16) & 0xff;
  2003. OP4(3) = (val >> 24) & 0xff;
  2004. break;
  2005. }
  2006. break;
  2007. case BFD_RELOC_32:
  2008. OP4(0) = val & 0xff;
  2009. OP4(1) = (val >> 8) & 0xff;
  2010. OP4(2) = (val >> 16) & 0xff;
  2011. OP4(3) = (val >> 24) & 0xff;
  2012. break;
  2013. case BFD_RELOC_RX_32_OP:
  2014. #if RX_OPCODE_BIG_ENDIAN
  2015. op[3] = val & 0xff;
  2016. op[2] = (val >> 8) & 0xff;
  2017. op[1] = (val >> 16) & 0xff;
  2018. op[0] = (val >> 24) & 0xff;
  2019. #else
  2020. op[0] = val & 0xff;
  2021. op[1] = (val >> 8) & 0xff;
  2022. op[2] = (val >> 16) & 0xff;
  2023. op[3] = (val >> 24) & 0xff;
  2024. #endif
  2025. break;
  2026. case BFD_RELOC_RX_NEG8:
  2027. op[0] = - val;
  2028. break;
  2029. case BFD_RELOC_RX_NEG16:
  2030. val = -val;
  2031. #if RX_OPCODE_BIG_ENDIAN
  2032. op[1] = val & 0xff;
  2033. op[0] = (val >> 8) & 0xff;
  2034. #else
  2035. op[0] = val & 0xff;
  2036. op[1] = (val >> 8) & 0xff;
  2037. #endif
  2038. break;
  2039. case BFD_RELOC_RX_NEG24:
  2040. val = -val;
  2041. #if RX_OPCODE_BIG_ENDIAN
  2042. op[2] = val & 0xff;
  2043. op[1] = (val >> 8) & 0xff;
  2044. op[0] = (val >> 16) & 0xff;
  2045. #else
  2046. op[0] = val & 0xff;
  2047. op[1] = (val >> 8) & 0xff;
  2048. op[2] = (val >> 16) & 0xff;
  2049. #endif
  2050. break;
  2051. case BFD_RELOC_RX_NEG32:
  2052. val = -val;
  2053. #if RX_OPCODE_BIG_ENDIAN
  2054. op[3] = val & 0xff;
  2055. op[2] = (val >> 8) & 0xff;
  2056. op[1] = (val >> 16) & 0xff;
  2057. op[0] = (val >> 24) & 0xff;
  2058. #else
  2059. op[0] = val & 0xff;
  2060. op[1] = (val >> 8) & 0xff;
  2061. op[2] = (val >> 16) & 0xff;
  2062. op[3] = (val >> 24) & 0xff;
  2063. #endif
  2064. break;
  2065. case BFD_RELOC_RX_GPRELL:
  2066. val >>= 1;
  2067. case BFD_RELOC_RX_GPRELW:
  2068. val >>= 1;
  2069. case BFD_RELOC_RX_GPRELB:
  2070. #if RX_OPCODE_BIG_ENDIAN
  2071. op[1] = val & 0xff;
  2072. op[0] = (val >> 8) & 0xff;
  2073. #else
  2074. op[0] = val & 0xff;
  2075. op[1] = (val >> 8) & 0xff;
  2076. #endif
  2077. break;
  2078. default:
  2079. as_bad (_("Unknown reloc in md_apply_fix: %s"),
  2080. bfd_get_reloc_code_name (f->fx_r_type));
  2081. break;
  2082. }
  2083. if (f->fx_addsy == NULL)
  2084. f->fx_done = 1;
  2085. }
  2086. arelent **
  2087. tc_gen_reloc (asection * sec ATTRIBUTE_UNUSED, fixS * fixp)
  2088. {
  2089. static arelent * reloc[5];
  2090. bfd_boolean is_opcode = FALSE;
  2091. if (fixp->fx_r_type == BFD_RELOC_NONE)
  2092. {
  2093. reloc[0] = NULL;
  2094. return reloc;
  2095. }
  2096. if (fixp->fx_subsy
  2097. && S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
  2098. {
  2099. fixp->fx_offset -= S_GET_VALUE (fixp->fx_subsy);
  2100. fixp->fx_subsy = NULL;
  2101. }
  2102. reloc[0] = (arelent *) xmalloc (sizeof (arelent));
  2103. reloc[0]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
  2104. * reloc[0]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  2105. reloc[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2106. reloc[0]->addend = fixp->fx_offset;
  2107. if (fixp->fx_r_type == BFD_RELOC_RX_32_OP
  2108. && fixp->fx_subsy)
  2109. {
  2110. fixp->fx_r_type = BFD_RELOC_RX_DIFF;
  2111. is_opcode = TRUE;
  2112. }
  2113. else if (sec)
  2114. is_opcode = sec->flags & SEC_CODE;
  2115. /* Certain BFD relocations cannot be translated directly into
  2116. a single (non-Red Hat) RX relocation, but instead need
  2117. multiple RX relocations - handle them here. */
  2118. switch (fixp->fx_r_type)
  2119. {
  2120. case BFD_RELOC_RX_DIFF:
  2121. reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
  2122. reloc[1] = (arelent *) xmalloc (sizeof (arelent));
  2123. reloc[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
  2124. * reloc[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
  2125. reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2126. reloc[1]->addend = 0;
  2127. reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
  2128. reloc[2] = (arelent *) xmalloc (sizeof (arelent));
  2129. reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_SUBTRACT);
  2130. reloc[2]->addend = 0;
  2131. reloc[2]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
  2132. reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2133. reloc[3] = (arelent *) xmalloc (sizeof (arelent));
  2134. switch (fixp->fx_size)
  2135. {
  2136. case 1:
  2137. reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS8);
  2138. break;
  2139. case 2:
  2140. if (!is_opcode && target_big_endian)
  2141. reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16_REV);
  2142. else if (is_opcode)
  2143. reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16UL);
  2144. else
  2145. reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16);
  2146. break;
  2147. case 4:
  2148. if (!is_opcode && target_big_endian)
  2149. reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS32_REV);
  2150. else
  2151. reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS32);
  2152. break;
  2153. }
  2154. reloc[3]->addend = 0;
  2155. reloc[3]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
  2156. reloc[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2157. reloc[4] = NULL;
  2158. break;
  2159. case BFD_RELOC_RX_GPRELL:
  2160. reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
  2161. reloc[1] = (arelent *) xmalloc (sizeof (arelent));
  2162. reloc[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
  2163. if (gp_symbol == NULL)
  2164. {
  2165. if (symbol_table_frozen)
  2166. {
  2167. symbolS * gp;
  2168. gp = symbol_find ("__gp");
  2169. if (gp == NULL)
  2170. as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
  2171. else
  2172. gp_symbol = symbol_get_bfdsym (gp);
  2173. }
  2174. else
  2175. gp_symbol = symbol_get_bfdsym (symbol_find_or_make ("__gp"));
  2176. }
  2177. * reloc[1]->sym_ptr_ptr = gp_symbol;
  2178. reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2179. reloc[1]->addend = 0;
  2180. reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
  2181. reloc[2] = (arelent *) xmalloc (sizeof (arelent));
  2182. reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_SUBTRACT);
  2183. reloc[2]->addend = 0;
  2184. reloc[2]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
  2185. reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2186. reloc[3] = (arelent *) xmalloc (sizeof (arelent));
  2187. reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16UL);
  2188. reloc[3]->addend = 0;
  2189. reloc[3]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
  2190. reloc[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2191. reloc[4] = NULL;
  2192. break;
  2193. case BFD_RELOC_RX_GPRELW:
  2194. reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
  2195. reloc[1] = (arelent *) xmalloc (sizeof (arelent));
  2196. reloc[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
  2197. if (gp_symbol == NULL)
  2198. {
  2199. if (symbol_table_frozen)
  2200. {
  2201. symbolS * gp;
  2202. gp = symbol_find ("__gp");
  2203. if (gp == NULL)
  2204. as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
  2205. else
  2206. gp_symbol = symbol_get_bfdsym (gp);
  2207. }
  2208. else
  2209. gp_symbol = symbol_get_bfdsym (symbol_find_or_make ("__gp"));
  2210. }
  2211. * reloc[1]->sym_ptr_ptr = gp_symbol;
  2212. reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2213. reloc[1]->addend = 0;
  2214. reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
  2215. reloc[2] = (arelent *) xmalloc (sizeof (arelent));
  2216. reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_SUBTRACT);
  2217. reloc[2]->addend = 0;
  2218. reloc[2]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
  2219. reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2220. reloc[3] = (arelent *) xmalloc (sizeof (arelent));
  2221. reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16UW);
  2222. reloc[3]->addend = 0;
  2223. reloc[3]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
  2224. reloc[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2225. reloc[4] = NULL;
  2226. break;
  2227. case BFD_RELOC_RX_GPRELB:
  2228. reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
  2229. reloc[1] = (arelent *) xmalloc (sizeof (arelent));
  2230. reloc[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
  2231. if (gp_symbol == NULL)
  2232. {
  2233. if (symbol_table_frozen)
  2234. {
  2235. symbolS * gp;
  2236. gp = symbol_find ("__gp");
  2237. if (gp == NULL)
  2238. as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
  2239. else
  2240. gp_symbol = symbol_get_bfdsym (gp);
  2241. }
  2242. else
  2243. gp_symbol = symbol_get_bfdsym (symbol_find_or_make ("__gp"));
  2244. }
  2245. * reloc[1]->sym_ptr_ptr = gp_symbol;
  2246. reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2247. reloc[1]->addend = 0;
  2248. reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
  2249. reloc[2] = (arelent *) xmalloc (sizeof (arelent));
  2250. reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_SUBTRACT);
  2251. reloc[2]->addend = 0;
  2252. reloc[2]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
  2253. reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2254. reloc[3] = (arelent *) xmalloc (sizeof (arelent));
  2255. reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16U);
  2256. reloc[3]->addend = 0;
  2257. reloc[3]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
  2258. reloc[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2259. reloc[4] = NULL;
  2260. break;
  2261. case BFD_RELOC_RX_NEG32:
  2262. reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
  2263. reloc[1] = (arelent *) xmalloc (sizeof (arelent));
  2264. reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_NEG);
  2265. reloc[1]->addend = 0;
  2266. reloc[1]->sym_ptr_ptr = reloc[0]->sym_ptr_ptr;
  2267. reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2268. reloc[2] = (arelent *) xmalloc (sizeof (arelent));
  2269. reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS32);
  2270. reloc[2]->addend = 0;
  2271. reloc[2]->sym_ptr_ptr = reloc[0]->sym_ptr_ptr;
  2272. reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2273. reloc[3] = NULL;
  2274. break;
  2275. default:
  2276. reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
  2277. reloc[1] = NULL;
  2278. break;
  2279. }
  2280. return reloc;
  2281. }
  2282. void
  2283. rx_note_string_insn_use (void)
  2284. {
  2285. if ((elf_flags & E_FLAG_RX_SINSNS_MASK) == (E_FLAG_RX_SINSNS_SET | E_FLAG_RX_SINSNS_NO))
  2286. as_bad (_("Use of an RX string instruction detected in a file being assembled without string instruction support"));
  2287. elf_flags |= E_FLAG_RX_SINSNS_SET | E_FLAG_RX_SINSNS_YES;
  2288. }
  2289. /* Set the ELF specific flags. */
  2290. void
  2291. rx_elf_final_processing (void)
  2292. {
  2293. elf_elfheader (stdoutput)->e_flags |= elf_flags;
  2294. }
  2295. /* Scan the current input line for occurances of Renesas
  2296. local labels and replace them with the GAS version. */
  2297. void
  2298. rx_start_line (void)
  2299. {
  2300. int in_double_quote = 0;
  2301. int in_single_quote = 0;
  2302. int done = 0;
  2303. char * p = input_line_pointer;
  2304. /* Scan the line looking for question marks. Skip past quote enclosed regions. */
  2305. do
  2306. {
  2307. switch (*p)
  2308. {
  2309. case '\n':
  2310. case 0:
  2311. done = 1;
  2312. break;
  2313. case '"':
  2314. in_double_quote = ! in_double_quote;
  2315. break;
  2316. case '\'':
  2317. in_single_quote = ! in_single_quote;
  2318. break;
  2319. case '?':
  2320. if (in_double_quote || in_single_quote)
  2321. break;
  2322. if (p[1] == ':')
  2323. *p = '1';
  2324. else if (p[1] == '+')
  2325. {
  2326. p[0] = '1';
  2327. p[1] = 'f';
  2328. }
  2329. else if (p[1] == '-')
  2330. {
  2331. p[0] = '1';
  2332. p[1] = 'b';
  2333. }
  2334. break;
  2335. default:
  2336. break;
  2337. }
  2338. p ++;
  2339. }
  2340. while (! done);
  2341. }