tc-mn10300.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639
  1. /* tc-mn10300.c -- Assembler code for the Matsushita 10300
  2. Copyright (C) 1996-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
  14. the Free Software Foundation, 51 Franklin Street - Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. #include "as.h"
  17. #include "safe-ctype.h"
  18. #include "subsegs.h"
  19. #include "opcode/mn10300.h"
  20. #include "dwarf2dbg.h"
  21. #include "libiberty.h"
  22. /* Structure to hold information about predefined registers. */
  23. struct reg_name
  24. {
  25. const char *name;
  26. int value;
  27. };
  28. /* Generic assembler global variables which must be defined by all
  29. targets. */
  30. /* Characters which always start a comment. */
  31. const char comment_chars[] = "#";
  32. /* Characters which start a comment at the beginning of a line. */
  33. const char line_comment_chars[] = ";#";
  34. /* Characters which may be used to separate multiple commands on a
  35. single line. */
  36. const char line_separator_chars[] = ";";
  37. /* Characters which are used to indicate an exponent in a floating
  38. point number. */
  39. const char EXP_CHARS[] = "eE";
  40. /* Characters which mean that a number is a floating point constant,
  41. as in 0d1.0. */
  42. const char FLT_CHARS[] = "dD";
  43. const relax_typeS md_relax_table[] =
  44. {
  45. /* The plus values for the bCC and fBCC instructions in the table below
  46. are because the branch instruction is translated into a jump
  47. instruction that is now +2 or +3 bytes further on in memory, and the
  48. correct size of jump instruction must be selected. */
  49. /* bCC relaxing. */
  50. {0x7f, -0x80, 2, 1},
  51. {0x7fff + 2, -0x8000 + 2, 5, 2},
  52. {0x7fffffff, -0x80000000, 7, 0},
  53. /* bCC relaxing (uncommon cases for 3byte length instructions) */
  54. {0x7f, -0x80, 3, 4},
  55. {0x7fff + 3, -0x8000 + 3, 6, 5},
  56. {0x7fffffff, -0x80000000, 8, 0},
  57. /* call relaxing. */
  58. {0x7fff, -0x8000, 5, 7},
  59. {0x7fffffff, -0x80000000, 7, 0},
  60. /* calls relaxing. */
  61. {0x7fff, -0x8000, 4, 9},
  62. {0x7fffffff, -0x80000000, 6, 0},
  63. /* jmp relaxing. */
  64. {0x7f, -0x80, 2, 11},
  65. {0x7fff, -0x8000, 3, 12},
  66. {0x7fffffff, -0x80000000, 5, 0},
  67. /* fbCC relaxing. */
  68. {0x7f, -0x80, 3, 14},
  69. {0x7fff + 3, -0x8000 + 3, 6, 15},
  70. {0x7fffffff, -0x80000000, 8, 0},
  71. };
  72. /* Set linkrelax here to avoid fixups in most sections. */
  73. int linkrelax = 1;
  74. static int current_machine;
  75. /* Fixups. */
  76. #define MAX_INSN_FIXUPS 5
  77. struct mn10300_fixup
  78. {
  79. expressionS exp;
  80. int opindex;
  81. bfd_reloc_code_real_type reloc;
  82. };
  83. struct mn10300_fixup fixups[MAX_INSN_FIXUPS];
  84. static int fc;
  85. /* We must store the value of each register operand so that we can
  86. verify that certain registers do not match. */
  87. int mn10300_reg_operands[MN10300_MAX_OPERANDS];
  88. const char *md_shortopts = "";
  89. struct option md_longopts[] =
  90. {
  91. {NULL, no_argument, NULL, 0}
  92. };
  93. size_t md_longopts_size = sizeof (md_longopts);
  94. #define HAVE_AM33_2 (current_machine == AM33_2)
  95. #define HAVE_AM33 (current_machine == AM33 || HAVE_AM33_2)
  96. #define HAVE_AM30 (current_machine == AM30)
  97. /* Opcode hash table. */
  98. static struct hash_control *mn10300_hash;
  99. /* This table is sorted. Suitable for searching by a binary search. */
  100. static const struct reg_name data_registers[] =
  101. {
  102. { "d0", 0 },
  103. { "d1", 1 },
  104. { "d2", 2 },
  105. { "d3", 3 },
  106. };
  107. static const struct reg_name address_registers[] =
  108. {
  109. { "a0", 0 },
  110. { "a1", 1 },
  111. { "a2", 2 },
  112. { "a3", 3 },
  113. };
  114. static const struct reg_name r_registers[] =
  115. {
  116. { "a0", 8 },
  117. { "a1", 9 },
  118. { "a2", 10 },
  119. { "a3", 11 },
  120. { "d0", 12 },
  121. { "d1", 13 },
  122. { "d2", 14 },
  123. { "d3", 15 },
  124. { "e0", 0 },
  125. { "e1", 1 },
  126. { "e10", 10 },
  127. { "e11", 11 },
  128. { "e12", 12 },
  129. { "e13", 13 },
  130. { "e14", 14 },
  131. { "e15", 15 },
  132. { "e2", 2 },
  133. { "e3", 3 },
  134. { "e4", 4 },
  135. { "e5", 5 },
  136. { "e6", 6 },
  137. { "e7", 7 },
  138. { "e8", 8 },
  139. { "e9", 9 },
  140. { "r0", 0 },
  141. { "r1", 1 },
  142. { "r10", 10 },
  143. { "r11", 11 },
  144. { "r12", 12 },
  145. { "r13", 13 },
  146. { "r14", 14 },
  147. { "r15", 15 },
  148. { "r2", 2 },
  149. { "r3", 3 },
  150. { "r4", 4 },
  151. { "r5", 5 },
  152. { "r6", 6 },
  153. { "r7", 7 },
  154. { "r8", 8 },
  155. { "r9", 9 },
  156. };
  157. static const struct reg_name xr_registers[] =
  158. {
  159. { "mcrh", 2 },
  160. { "mcrl", 3 },
  161. { "mcvf", 4 },
  162. { "mdrq", 1 },
  163. { "sp", 0 },
  164. { "xr0", 0 },
  165. { "xr1", 1 },
  166. { "xr10", 10 },
  167. { "xr11", 11 },
  168. { "xr12", 12 },
  169. { "xr13", 13 },
  170. { "xr14", 14 },
  171. { "xr15", 15 },
  172. { "xr2", 2 },
  173. { "xr3", 3 },
  174. { "xr4", 4 },
  175. { "xr5", 5 },
  176. { "xr6", 6 },
  177. { "xr7", 7 },
  178. { "xr8", 8 },
  179. { "xr9", 9 },
  180. };
  181. static const struct reg_name float_registers[] =
  182. {
  183. { "fs0", 0 },
  184. { "fs1", 1 },
  185. { "fs10", 10 },
  186. { "fs11", 11 },
  187. { "fs12", 12 },
  188. { "fs13", 13 },
  189. { "fs14", 14 },
  190. { "fs15", 15 },
  191. { "fs16", 16 },
  192. { "fs17", 17 },
  193. { "fs18", 18 },
  194. { "fs19", 19 },
  195. { "fs2", 2 },
  196. { "fs20", 20 },
  197. { "fs21", 21 },
  198. { "fs22", 22 },
  199. { "fs23", 23 },
  200. { "fs24", 24 },
  201. { "fs25", 25 },
  202. { "fs26", 26 },
  203. { "fs27", 27 },
  204. { "fs28", 28 },
  205. { "fs29", 29 },
  206. { "fs3", 3 },
  207. { "fs30", 30 },
  208. { "fs31", 31 },
  209. { "fs4", 4 },
  210. { "fs5", 5 },
  211. { "fs6", 6 },
  212. { "fs7", 7 },
  213. { "fs8", 8 },
  214. { "fs9", 9 },
  215. };
  216. static const struct reg_name double_registers[] =
  217. {
  218. { "fd0", 0 },
  219. { "fd10", 10 },
  220. { "fd12", 12 },
  221. { "fd14", 14 },
  222. { "fd16", 16 },
  223. { "fd18", 18 },
  224. { "fd2", 2 },
  225. { "fd20", 20 },
  226. { "fd22", 22 },
  227. { "fd24", 24 },
  228. { "fd26", 26 },
  229. { "fd28", 28 },
  230. { "fd30", 30 },
  231. { "fd4", 4 },
  232. { "fd6", 6 },
  233. { "fd8", 8 },
  234. };
  235. /* We abuse the `value' field, that would be otherwise unused, to
  236. encode the architecture on which (access to) the register was
  237. introduced. FIXME: we should probably warn when we encounter a
  238. register name when assembling for an architecture that doesn't
  239. support it, before parsing it as a symbol name. */
  240. static const struct reg_name other_registers[] =
  241. {
  242. { "epsw", AM33 },
  243. { "mdr", 0 },
  244. { "pc", AM33 },
  245. { "psw", 0 },
  246. { "sp", 0 },
  247. { "ssp", 0 },
  248. { "usp", 0 },
  249. };
  250. #define OTHER_REG_NAME_CNT ARRAY_SIZE (other_registers)
  251. /* Perform a binary search of the given register table REGS to see
  252. if NAME is a valid regiter name. Returns the register number from
  253. the array on success, or -1 on failure. */
  254. static int
  255. reg_name_search (const struct reg_name *regs,
  256. int regcount,
  257. const char *name)
  258. {
  259. int low, high;
  260. low = 0;
  261. high = regcount - 1;
  262. do
  263. {
  264. int cmp, middle;
  265. middle = (low + high) / 2;
  266. cmp = strcasecmp (name, regs[middle].name);
  267. if (cmp < 0)
  268. high = middle - 1;
  269. else if (cmp > 0)
  270. low = middle + 1;
  271. else
  272. return regs[middle].value;
  273. }
  274. while (low <= high);
  275. return -1;
  276. }
  277. /* Looks at the current position in the input line to see if it is
  278. the name of a register in TABLE. If it is, then the name is
  279. converted into an expression returned in EXPRESSIONP (with X_op
  280. set to O_register and X_add_number set to the register number), the
  281. input pointer is left pointing at the first non-blank character after
  282. the name and the function returns TRUE. Otherwise the input pointer
  283. is left alone and the function returns FALSE. */
  284. static bfd_boolean
  285. get_register_name (expressionS * expressionP,
  286. const struct reg_name * table,
  287. size_t table_length)
  288. {
  289. int reg_number;
  290. char *name;
  291. char *start;
  292. char c;
  293. /* Find the spelling of the operand. */
  294. start = input_line_pointer;
  295. c = get_symbol_name (&name);
  296. reg_number = reg_name_search (table, table_length, name);
  297. /* Put back the delimiting char. */
  298. (void) restore_line_pointer (c);
  299. /* Look to see if it's in the register table. */
  300. if (reg_number >= 0)
  301. {
  302. expressionP->X_op = O_register;
  303. expressionP->X_add_number = reg_number;
  304. /* Make the rest nice. */
  305. expressionP->X_add_symbol = NULL;
  306. expressionP->X_op_symbol = NULL;
  307. return TRUE;
  308. }
  309. /* Reset the line as if we had not done anything. */
  310. input_line_pointer = start;
  311. return FALSE;
  312. }
  313. static bfd_boolean
  314. r_register_name (expressionS *expressionP)
  315. {
  316. return get_register_name (expressionP, r_registers, ARRAY_SIZE (r_registers));
  317. }
  318. static bfd_boolean
  319. xr_register_name (expressionS *expressionP)
  320. {
  321. return get_register_name (expressionP, xr_registers, ARRAY_SIZE (xr_registers));
  322. }
  323. static bfd_boolean
  324. data_register_name (expressionS *expressionP)
  325. {
  326. return get_register_name (expressionP, data_registers, ARRAY_SIZE (data_registers));
  327. }
  328. static bfd_boolean
  329. address_register_name (expressionS *expressionP)
  330. {
  331. return get_register_name (expressionP, address_registers, ARRAY_SIZE (address_registers));
  332. }
  333. static bfd_boolean
  334. float_register_name (expressionS *expressionP)
  335. {
  336. return get_register_name (expressionP, float_registers, ARRAY_SIZE (float_registers));
  337. }
  338. static bfd_boolean
  339. double_register_name (expressionS *expressionP)
  340. {
  341. return get_register_name (expressionP, double_registers, ARRAY_SIZE (double_registers));
  342. }
  343. static bfd_boolean
  344. other_register_name (expressionS *expressionP)
  345. {
  346. int reg_number;
  347. char *name;
  348. char *start;
  349. char c;
  350. /* Find the spelling of the operand. */
  351. start = input_line_pointer;
  352. c = get_symbol_name (&name);
  353. reg_number = reg_name_search (other_registers, ARRAY_SIZE (other_registers), name);
  354. /* Put back the delimiting char. */
  355. (void) restore_line_pointer (c);
  356. /* Look to see if it's in the register table. */
  357. if (reg_number == 0
  358. || (reg_number == AM33 && HAVE_AM33))
  359. {
  360. expressionP->X_op = O_register;
  361. expressionP->X_add_number = 0;
  362. /* Make the rest nice. */
  363. expressionP->X_add_symbol = NULL;
  364. expressionP->X_op_symbol = NULL;
  365. return TRUE;
  366. }
  367. /* Reset the line as if we had not done anything. */
  368. input_line_pointer = start;
  369. return FALSE;
  370. }
  371. void
  372. md_show_usage (FILE *stream)
  373. {
  374. fprintf (stream, _("MN10300 assembler options:\n\
  375. none yet\n"));
  376. }
  377. int
  378. md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
  379. {
  380. return 0;
  381. }
  382. symbolS *
  383. md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
  384. {
  385. return 0;
  386. }
  387. char *
  388. md_atof (int type, char *litp, int *sizep)
  389. {
  390. return ieee_md_atof (type, litp, sizep, FALSE);
  391. }
  392. void
  393. md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
  394. asection *sec,
  395. fragS *fragP)
  396. {
  397. static unsigned long label_count = 0;
  398. char buf[40];
  399. subseg_change (sec, 0);
  400. if (fragP->fr_subtype == 0)
  401. {
  402. fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
  403. fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
  404. fragP->fr_var = 0;
  405. fragP->fr_fix += 2;
  406. }
  407. else if (fragP->fr_subtype == 1)
  408. {
  409. /* Reverse the condition of the first branch. */
  410. int offset = fragP->fr_fix;
  411. int opcode = fragP->fr_literal[offset] & 0xff;
  412. switch (opcode)
  413. {
  414. case 0xc8:
  415. opcode = 0xc9;
  416. break;
  417. case 0xc9:
  418. opcode = 0xc8;
  419. break;
  420. case 0xc0:
  421. opcode = 0xc2;
  422. break;
  423. case 0xc2:
  424. opcode = 0xc0;
  425. break;
  426. case 0xc3:
  427. opcode = 0xc1;
  428. break;
  429. case 0xc1:
  430. opcode = 0xc3;
  431. break;
  432. case 0xc4:
  433. opcode = 0xc6;
  434. break;
  435. case 0xc6:
  436. opcode = 0xc4;
  437. break;
  438. case 0xc7:
  439. opcode = 0xc5;
  440. break;
  441. case 0xc5:
  442. opcode = 0xc7;
  443. break;
  444. default:
  445. abort ();
  446. }
  447. fragP->fr_literal[offset] = opcode;
  448. /* Create a fixup for the reversed conditional branch. */
  449. sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
  450. fix_new (fragP, fragP->fr_fix + 1, 1,
  451. symbol_new (buf, sec, 0, fragP->fr_next),
  452. fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
  453. /* Now create the unconditional branch + fixup to the
  454. final target. */
  455. fragP->fr_literal[offset + 2] = 0xcc;
  456. fix_new (fragP, fragP->fr_fix + 3, 2, fragP->fr_symbol,
  457. fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
  458. fragP->fr_var = 0;
  459. fragP->fr_fix += 5;
  460. }
  461. else if (fragP->fr_subtype == 2)
  462. {
  463. /* Reverse the condition of the first branch. */
  464. int offset = fragP->fr_fix;
  465. int opcode = fragP->fr_literal[offset] & 0xff;
  466. switch (opcode)
  467. {
  468. case 0xc8:
  469. opcode = 0xc9;
  470. break;
  471. case 0xc9:
  472. opcode = 0xc8;
  473. break;
  474. case 0xc0:
  475. opcode = 0xc2;
  476. break;
  477. case 0xc2:
  478. opcode = 0xc0;
  479. break;
  480. case 0xc3:
  481. opcode = 0xc1;
  482. break;
  483. case 0xc1:
  484. opcode = 0xc3;
  485. break;
  486. case 0xc4:
  487. opcode = 0xc6;
  488. break;
  489. case 0xc6:
  490. opcode = 0xc4;
  491. break;
  492. case 0xc7:
  493. opcode = 0xc5;
  494. break;
  495. case 0xc5:
  496. opcode = 0xc7;
  497. break;
  498. default:
  499. abort ();
  500. }
  501. fragP->fr_literal[offset] = opcode;
  502. /* Create a fixup for the reversed conditional branch. */
  503. sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
  504. fix_new (fragP, fragP->fr_fix + 1, 1,
  505. symbol_new (buf, sec, 0, fragP->fr_next),
  506. fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
  507. /* Now create the unconditional branch + fixup to the
  508. final target. */
  509. fragP->fr_literal[offset + 2] = 0xdc;
  510. fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
  511. fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
  512. fragP->fr_var = 0;
  513. fragP->fr_fix += 7;
  514. }
  515. else if (fragP->fr_subtype == 3)
  516. {
  517. fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
  518. fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
  519. fragP->fr_var = 0;
  520. fragP->fr_fix += 3;
  521. }
  522. else if (fragP->fr_subtype == 4)
  523. {
  524. /* Reverse the condition of the first branch. */
  525. int offset = fragP->fr_fix;
  526. int opcode = fragP->fr_literal[offset + 1] & 0xff;
  527. switch (opcode)
  528. {
  529. case 0xe8:
  530. opcode = 0xe9;
  531. break;
  532. case 0xe9:
  533. opcode = 0xe8;
  534. break;
  535. case 0xea:
  536. opcode = 0xeb;
  537. break;
  538. case 0xeb:
  539. opcode = 0xea;
  540. break;
  541. default:
  542. abort ();
  543. }
  544. fragP->fr_literal[offset + 1] = opcode;
  545. /* Create a fixup for the reversed conditional branch. */
  546. sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
  547. fix_new (fragP, fragP->fr_fix + 2, 1,
  548. symbol_new (buf, sec, 0, fragP->fr_next),
  549. fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
  550. /* Now create the unconditional branch + fixup to the
  551. final target. */
  552. fragP->fr_literal[offset + 3] = 0xcc;
  553. fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
  554. fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
  555. fragP->fr_var = 0;
  556. fragP->fr_fix += 6;
  557. }
  558. else if (fragP->fr_subtype == 5)
  559. {
  560. /* Reverse the condition of the first branch. */
  561. int offset = fragP->fr_fix;
  562. int opcode = fragP->fr_literal[offset + 1] & 0xff;
  563. switch (opcode)
  564. {
  565. case 0xe8:
  566. opcode = 0xe9;
  567. break;
  568. case 0xea:
  569. opcode = 0xeb;
  570. break;
  571. case 0xeb:
  572. opcode = 0xea;
  573. break;
  574. default:
  575. abort ();
  576. }
  577. fragP->fr_literal[offset + 1] = opcode;
  578. /* Create a fixup for the reversed conditional branch. */
  579. sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
  580. fix_new (fragP, fragP->fr_fix + 2, 1,
  581. symbol_new (buf, sec, 0, fragP->fr_next),
  582. fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
  583. /* Now create the unconditional branch + fixup to the
  584. final target. */
  585. fragP->fr_literal[offset + 3] = 0xdc;
  586. fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
  587. fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
  588. fragP->fr_var = 0;
  589. fragP->fr_fix += 8;
  590. }
  591. else if (fragP->fr_subtype == 6)
  592. {
  593. int offset = fragP->fr_fix;
  594. fragP->fr_literal[offset] = 0xcd;
  595. fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
  596. fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
  597. fragP->fr_var = 0;
  598. fragP->fr_fix += 5;
  599. }
  600. else if (fragP->fr_subtype == 7)
  601. {
  602. int offset = fragP->fr_fix;
  603. fragP->fr_literal[offset] = 0xdd;
  604. fragP->fr_literal[offset + 5] = fragP->fr_literal[offset + 3];
  605. fragP->fr_literal[offset + 6] = fragP->fr_literal[offset + 4];
  606. fragP->fr_literal[offset + 3] = 0;
  607. fragP->fr_literal[offset + 4] = 0;
  608. fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
  609. fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
  610. fragP->fr_var = 0;
  611. fragP->fr_fix += 7;
  612. }
  613. else if (fragP->fr_subtype == 8)
  614. {
  615. int offset = fragP->fr_fix;
  616. fragP->fr_literal[offset] = 0xfa;
  617. fragP->fr_literal[offset + 1] = 0xff;
  618. fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
  619. fragP->fr_offset + 2, 1, BFD_RELOC_16_PCREL);
  620. fragP->fr_var = 0;
  621. fragP->fr_fix += 4;
  622. }
  623. else if (fragP->fr_subtype == 9)
  624. {
  625. int offset = fragP->fr_fix;
  626. fragP->fr_literal[offset] = 0xfc;
  627. fragP->fr_literal[offset + 1] = 0xff;
  628. fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
  629. fragP->fr_offset + 2, 1, BFD_RELOC_32_PCREL);
  630. fragP->fr_var = 0;
  631. fragP->fr_fix += 6;
  632. }
  633. else if (fragP->fr_subtype == 10)
  634. {
  635. fragP->fr_literal[fragP->fr_fix] = 0xca;
  636. fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
  637. fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
  638. fragP->fr_var = 0;
  639. fragP->fr_fix += 2;
  640. }
  641. else if (fragP->fr_subtype == 11)
  642. {
  643. int offset = fragP->fr_fix;
  644. fragP->fr_literal[offset] = 0xcc;
  645. fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
  646. fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
  647. fragP->fr_var = 0;
  648. fragP->fr_fix += 3;
  649. }
  650. else if (fragP->fr_subtype == 12)
  651. {
  652. int offset = fragP->fr_fix;
  653. fragP->fr_literal[offset] = 0xdc;
  654. fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
  655. fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
  656. fragP->fr_var = 0;
  657. fragP->fr_fix += 5;
  658. }
  659. else if (fragP->fr_subtype == 13)
  660. {
  661. fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
  662. fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
  663. fragP->fr_var = 0;
  664. fragP->fr_fix += 3;
  665. }
  666. else if (fragP->fr_subtype == 14)
  667. {
  668. /* Reverse the condition of the first branch. */
  669. int offset = fragP->fr_fix;
  670. int opcode = fragP->fr_literal[offset + 1] & 0xff;
  671. switch (opcode)
  672. {
  673. case 0xd0:
  674. opcode = 0xd1;
  675. break;
  676. case 0xd1:
  677. opcode = 0xd0;
  678. break;
  679. case 0xd2:
  680. opcode = 0xdc;
  681. break;
  682. case 0xd3:
  683. opcode = 0xdb;
  684. break;
  685. case 0xd4:
  686. opcode = 0xda;
  687. break;
  688. case 0xd5:
  689. opcode = 0xd9;
  690. break;
  691. case 0xd6:
  692. opcode = 0xd8;
  693. break;
  694. case 0xd7:
  695. opcode = 0xdd;
  696. break;
  697. case 0xd8:
  698. opcode = 0xd6;
  699. break;
  700. case 0xd9:
  701. opcode = 0xd5;
  702. break;
  703. case 0xda:
  704. opcode = 0xd4;
  705. break;
  706. case 0xdb:
  707. opcode = 0xd3;
  708. break;
  709. case 0xdc:
  710. opcode = 0xd2;
  711. break;
  712. case 0xdd:
  713. opcode = 0xd7;
  714. break;
  715. default:
  716. abort ();
  717. }
  718. fragP->fr_literal[offset + 1] = opcode;
  719. /* Create a fixup for the reversed conditional branch. */
  720. sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
  721. fix_new (fragP, fragP->fr_fix + 2, 1,
  722. symbol_new (buf, sec, 0, fragP->fr_next),
  723. fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
  724. /* Now create the unconditional branch + fixup to the
  725. final target. */
  726. fragP->fr_literal[offset + 3] = 0xcc;
  727. fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
  728. fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
  729. fragP->fr_var = 0;
  730. fragP->fr_fix += 6;
  731. }
  732. else if (fragP->fr_subtype == 15)
  733. {
  734. /* Reverse the condition of the first branch. */
  735. int offset = fragP->fr_fix;
  736. int opcode = fragP->fr_literal[offset + 1] & 0xff;
  737. switch (opcode)
  738. {
  739. case 0xd0:
  740. opcode = 0xd1;
  741. break;
  742. case 0xd1:
  743. opcode = 0xd0;
  744. break;
  745. case 0xd2:
  746. opcode = 0xdc;
  747. break;
  748. case 0xd3:
  749. opcode = 0xdb;
  750. break;
  751. case 0xd4:
  752. opcode = 0xda;
  753. break;
  754. case 0xd5:
  755. opcode = 0xd9;
  756. break;
  757. case 0xd6:
  758. opcode = 0xd8;
  759. break;
  760. case 0xd7:
  761. opcode = 0xdd;
  762. break;
  763. case 0xd8:
  764. opcode = 0xd6;
  765. break;
  766. case 0xd9:
  767. opcode = 0xd5;
  768. break;
  769. case 0xda:
  770. opcode = 0xd4;
  771. break;
  772. case 0xdb:
  773. opcode = 0xd3;
  774. break;
  775. case 0xdc:
  776. opcode = 0xd2;
  777. break;
  778. case 0xdd:
  779. opcode = 0xd7;
  780. break;
  781. default:
  782. abort ();
  783. }
  784. fragP->fr_literal[offset + 1] = opcode;
  785. /* Create a fixup for the reversed conditional branch. */
  786. sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
  787. fix_new (fragP, fragP->fr_fix + 2, 1,
  788. symbol_new (buf, sec, 0, fragP->fr_next),
  789. fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
  790. /* Now create the unconditional branch + fixup to the
  791. final target. */
  792. fragP->fr_literal[offset + 3] = 0xdc;
  793. fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
  794. fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
  795. fragP->fr_var = 0;
  796. fragP->fr_fix += 8;
  797. }
  798. else
  799. abort ();
  800. }
  801. valueT
  802. md_section_align (asection *seg, valueT addr)
  803. {
  804. int align = bfd_get_section_alignment (stdoutput, seg);
  805. return ((addr + (1 << align) - 1) & (-1 << align));
  806. }
  807. void
  808. md_begin (void)
  809. {
  810. char *prev_name = "";
  811. const struct mn10300_opcode *op;
  812. mn10300_hash = hash_new ();
  813. /* Insert unique names into hash table. The MN10300 instruction set
  814. has many identical opcode names that have different opcodes based
  815. on the operands. This hash table then provides a quick index to
  816. the first opcode with a particular name in the opcode table. */
  817. op = mn10300_opcodes;
  818. while (op->name)
  819. {
  820. if (strcmp (prev_name, op->name))
  821. {
  822. prev_name = (char *) op->name;
  823. hash_insert (mn10300_hash, op->name, (char *) op);
  824. }
  825. op++;
  826. }
  827. /* Set the default machine type. */
  828. #ifdef TE_LINUX
  829. if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, AM33_2))
  830. as_warn (_("could not set architecture and machine"));
  831. current_machine = AM33_2;
  832. #else
  833. if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, MN103))
  834. as_warn (_("could not set architecture and machine"));
  835. current_machine = MN103;
  836. #endif
  837. }
  838. static symbolS *GOT_symbol;
  839. static inline int
  840. mn10300_PIC_related_p (symbolS *sym)
  841. {
  842. expressionS *exp;
  843. if (! sym)
  844. return 0;
  845. if (sym == GOT_symbol)
  846. return 1;
  847. exp = symbol_get_value_expression (sym);
  848. return (exp->X_op == O_PIC_reloc
  849. || mn10300_PIC_related_p (exp->X_add_symbol)
  850. || mn10300_PIC_related_p (exp->X_op_symbol));
  851. }
  852. static inline int
  853. mn10300_check_fixup (struct mn10300_fixup *fixup)
  854. {
  855. expressionS *exp = &fixup->exp;
  856. repeat:
  857. switch (exp->X_op)
  858. {
  859. case O_add:
  860. case O_subtract: /* If we're sufficiently unlucky that the label
  861. and the expression that references it happen
  862. to end up in different frags, the subtract
  863. won't be simplified within expression(). */
  864. /* The PIC-related operand must be the first operand of a sum. */
  865. if (exp != &fixup->exp || mn10300_PIC_related_p (exp->X_op_symbol))
  866. return 1;
  867. if (exp->X_add_symbol && exp->X_add_symbol == GOT_symbol)
  868. fixup->reloc = BFD_RELOC_32_GOT_PCREL;
  869. exp = symbol_get_value_expression (exp->X_add_symbol);
  870. goto repeat;
  871. case O_symbol:
  872. if (exp->X_add_symbol && exp->X_add_symbol == GOT_symbol)
  873. fixup->reloc = BFD_RELOC_32_GOT_PCREL;
  874. break;
  875. case O_PIC_reloc:
  876. fixup->reloc = exp->X_md;
  877. exp->X_op = O_symbol;
  878. if (fixup->reloc == BFD_RELOC_32_PLT_PCREL
  879. && fixup->opindex >= 0
  880. && (mn10300_operands[fixup->opindex].flags
  881. & MN10300_OPERAND_RELAX))
  882. return 1;
  883. break;
  884. default:
  885. return (mn10300_PIC_related_p (exp->X_add_symbol)
  886. || mn10300_PIC_related_p (exp->X_op_symbol));
  887. }
  888. return 0;
  889. }
  890. void
  891. mn10300_cons_fix_new (fragS *frag, int off, int size, expressionS *exp,
  892. bfd_reloc_code_real_type r ATTRIBUTE_UNUSED)
  893. {
  894. struct mn10300_fixup fixup;
  895. fixup.opindex = -1;
  896. fixup.exp = *exp;
  897. fixup.reloc = BFD_RELOC_UNUSED;
  898. mn10300_check_fixup (&fixup);
  899. if (fixup.reloc == BFD_RELOC_MN10300_GOT32)
  900. switch (size)
  901. {
  902. case 2:
  903. fixup.reloc = BFD_RELOC_MN10300_GOT16;
  904. break;
  905. case 3:
  906. fixup.reloc = BFD_RELOC_MN10300_GOT24;
  907. break;
  908. case 4:
  909. break;
  910. default:
  911. goto error;
  912. }
  913. else if (fixup.reloc == BFD_RELOC_UNUSED)
  914. switch (size)
  915. {
  916. case 1:
  917. fixup.reloc = BFD_RELOC_8;
  918. break;
  919. case 2:
  920. fixup.reloc = BFD_RELOC_16;
  921. break;
  922. case 3:
  923. fixup.reloc = BFD_RELOC_24;
  924. break;
  925. case 4:
  926. fixup.reloc = BFD_RELOC_32;
  927. break;
  928. default:
  929. goto error;
  930. }
  931. else if (size != 4)
  932. {
  933. error:
  934. as_bad (_("unsupported BFD relocation size %u"), size);
  935. fixup.reloc = BFD_RELOC_UNUSED;
  936. }
  937. fix_new_exp (frag, off, size, &fixup.exp, 0, fixup.reloc);
  938. }
  939. static bfd_boolean
  940. check_operand (const struct mn10300_operand *operand,
  941. offsetT val)
  942. {
  943. /* No need to check 32bit operands for a bit. Note that
  944. MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
  945. if (operand->bits != 32
  946. && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
  947. {
  948. long min, max;
  949. offsetT test;
  950. int bits;
  951. bits = operand->bits;
  952. if (operand->flags & MN10300_OPERAND_24BIT)
  953. bits = 24;
  954. if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
  955. {
  956. max = (1 << (bits - 1)) - 1;
  957. min = - (1 << (bits - 1));
  958. }
  959. else
  960. {
  961. max = (1 << bits) - 1;
  962. min = 0;
  963. }
  964. test = val;
  965. if (test < (offsetT) min || test > (offsetT) max)
  966. return FALSE;
  967. }
  968. return TRUE;
  969. }
  970. /* Insert an operand value into an instruction. */
  971. static void
  972. mn10300_insert_operand (unsigned long *insnp,
  973. unsigned long *extensionp,
  974. const struct mn10300_operand *operand,
  975. offsetT val,
  976. char *file,
  977. unsigned int line,
  978. unsigned int shift)
  979. {
  980. /* No need to check 32bit operands for a bit. Note that
  981. MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
  982. if (operand->bits != 32
  983. && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
  984. {
  985. long min, max;
  986. offsetT test;
  987. int bits;
  988. bits = operand->bits;
  989. if (operand->flags & MN10300_OPERAND_24BIT)
  990. bits = 24;
  991. if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
  992. {
  993. max = (1 << (bits - 1)) - 1;
  994. min = - (1 << (bits - 1));
  995. }
  996. else
  997. {
  998. max = (1 << bits) - 1;
  999. min = 0;
  1000. }
  1001. test = val;
  1002. if (test < (offsetT) min || test > (offsetT) max)
  1003. as_warn_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) max, file, line);
  1004. }
  1005. if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
  1006. {
  1007. *insnp |= (val >> (32 - operand->bits)) & ((1 << operand->bits) - 1);
  1008. *extensionp |= ((val & ((1 << (32 - operand->bits)) - 1))
  1009. << operand->shift);
  1010. }
  1011. else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
  1012. {
  1013. *insnp |= (val >> (24 - operand->bits)) & ((1 << operand->bits) - 1);
  1014. *extensionp |= ((val & ((1 << (24 - operand->bits)) - 1))
  1015. << operand->shift);
  1016. }
  1017. else if ((operand->flags & (MN10300_OPERAND_FSREG | MN10300_OPERAND_FDREG)))
  1018. {
  1019. /* See devo/opcodes/m10300-opc.c just before #define FSM0 for an
  1020. explanation of these variables. Note that FMT-implied shifts
  1021. are not taken into account for FP registers. */
  1022. unsigned long mask_low, mask_high;
  1023. int shl_low, shr_high, shl_high;
  1024. switch (operand->bits)
  1025. {
  1026. case 5:
  1027. /* Handle regular FP registers. */
  1028. if (operand->shift >= 0)
  1029. {
  1030. /* This is an `m' register. */
  1031. shl_low = operand->shift;
  1032. shl_high = 8 + (8 & shl_low) + (shl_low & 4) / 4;
  1033. }
  1034. else
  1035. {
  1036. /* This is an `n' register. */
  1037. shl_low = -operand->shift;
  1038. shl_high = shl_low / 4;
  1039. }
  1040. mask_low = 0x0f;
  1041. mask_high = 0x10;
  1042. shr_high = 4;
  1043. break;
  1044. case 3:
  1045. /* Handle accumulators. */
  1046. shl_low = -operand->shift;
  1047. shl_high = 0;
  1048. mask_low = 0x03;
  1049. mask_high = 0x04;
  1050. shr_high = 2;
  1051. break;
  1052. default:
  1053. abort ();
  1054. }
  1055. *insnp |= ((((val & mask_high) >> shr_high) << shl_high)
  1056. | ((val & mask_low) << shl_low));
  1057. }
  1058. else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0)
  1059. {
  1060. *insnp |= (((long) val & ((1 << operand->bits) - 1))
  1061. << (operand->shift + shift));
  1062. if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
  1063. *insnp |= (((long) val & ((1 << operand->bits) - 1))
  1064. << (operand->shift + shift + operand->bits));
  1065. }
  1066. else
  1067. {
  1068. *extensionp |= (((long) val & ((1 << operand->bits) - 1))
  1069. << (operand->shift + shift));
  1070. if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
  1071. *extensionp |= (((long) val & ((1 << operand->bits) - 1))
  1072. << (operand->shift + shift + operand->bits));
  1073. }
  1074. }
  1075. void
  1076. md_assemble (char *str)
  1077. {
  1078. char *s;
  1079. struct mn10300_opcode *opcode;
  1080. struct mn10300_opcode *next_opcode;
  1081. const unsigned char *opindex_ptr;
  1082. int next_opindex, relaxable;
  1083. unsigned long insn, extension, size = 0;
  1084. char *f;
  1085. int i;
  1086. int match;
  1087. /* Get the opcode. */
  1088. for (s = str; *s != '\0' && !ISSPACE (*s); s++)
  1089. ;
  1090. if (*s != '\0')
  1091. *s++ = '\0';
  1092. /* Find the first opcode with the proper name. */
  1093. opcode = (struct mn10300_opcode *) hash_find (mn10300_hash, str);
  1094. if (opcode == NULL)
  1095. {
  1096. as_bad (_("Unrecognized opcode: `%s'"), str);
  1097. return;
  1098. }
  1099. str = s;
  1100. while (ISSPACE (*str))
  1101. ++str;
  1102. input_line_pointer = str;
  1103. for (;;)
  1104. {
  1105. const char *errmsg;
  1106. int op_idx;
  1107. char *hold;
  1108. int extra_shift = 0;
  1109. errmsg = _("Invalid opcode/operands");
  1110. /* Reset the array of register operands. */
  1111. memset (mn10300_reg_operands, -1, sizeof (mn10300_reg_operands));
  1112. relaxable = 0;
  1113. fc = 0;
  1114. match = 0;
  1115. next_opindex = 0;
  1116. insn = opcode->opcode;
  1117. extension = 0;
  1118. /* If the instruction is not available on the current machine
  1119. then it can not possibly match. */
  1120. if (opcode->machine
  1121. && !(opcode->machine == AM33_2 && HAVE_AM33_2)
  1122. && !(opcode->machine == AM33 && HAVE_AM33)
  1123. && !(opcode->machine == AM30 && HAVE_AM30))
  1124. goto error;
  1125. for (op_idx = 1, opindex_ptr = opcode->operands;
  1126. *opindex_ptr != 0;
  1127. opindex_ptr++, op_idx++)
  1128. {
  1129. const struct mn10300_operand *operand;
  1130. expressionS ex;
  1131. if (next_opindex == 0)
  1132. {
  1133. operand = &mn10300_operands[*opindex_ptr];
  1134. }
  1135. else
  1136. {
  1137. operand = &mn10300_operands[next_opindex];
  1138. next_opindex = 0;
  1139. }
  1140. while (*str == ' ' || *str == ',')
  1141. ++str;
  1142. if (operand->flags & MN10300_OPERAND_RELAX)
  1143. relaxable = 1;
  1144. /* Gather the operand. */
  1145. hold = input_line_pointer;
  1146. input_line_pointer = str;
  1147. if (operand->flags & MN10300_OPERAND_PAREN)
  1148. {
  1149. if (*input_line_pointer != ')' && *input_line_pointer != '(')
  1150. {
  1151. input_line_pointer = hold;
  1152. str = hold;
  1153. goto error;
  1154. }
  1155. input_line_pointer++;
  1156. goto keep_going;
  1157. }
  1158. /* See if we can match the operands. */
  1159. else if (operand->flags & MN10300_OPERAND_DREG)
  1160. {
  1161. if (!data_register_name (&ex))
  1162. {
  1163. input_line_pointer = hold;
  1164. str = hold;
  1165. goto error;
  1166. }
  1167. }
  1168. else if (operand->flags & MN10300_OPERAND_AREG)
  1169. {
  1170. if (!address_register_name (&ex))
  1171. {
  1172. input_line_pointer = hold;
  1173. str = hold;
  1174. goto error;
  1175. }
  1176. }
  1177. else if (operand->flags & MN10300_OPERAND_SP)
  1178. {
  1179. char *start;
  1180. char c = get_symbol_name (&start);
  1181. if (strcasecmp (start, "sp") != 0)
  1182. {
  1183. (void) restore_line_pointer (c);
  1184. input_line_pointer = hold;
  1185. str = hold;
  1186. goto error;
  1187. }
  1188. (void) restore_line_pointer (c);
  1189. goto keep_going;
  1190. }
  1191. else if (operand->flags & MN10300_OPERAND_RREG)
  1192. {
  1193. if (!r_register_name (&ex))
  1194. {
  1195. input_line_pointer = hold;
  1196. str = hold;
  1197. goto error;
  1198. }
  1199. }
  1200. else if (operand->flags & MN10300_OPERAND_XRREG)
  1201. {
  1202. if (!xr_register_name (&ex))
  1203. {
  1204. input_line_pointer = hold;
  1205. str = hold;
  1206. goto error;
  1207. }
  1208. }
  1209. else if (operand->flags & MN10300_OPERAND_FSREG)
  1210. {
  1211. if (!float_register_name (&ex))
  1212. {
  1213. input_line_pointer = hold;
  1214. str = hold;
  1215. goto error;
  1216. }
  1217. }
  1218. else if (operand->flags & MN10300_OPERAND_FDREG)
  1219. {
  1220. if (!double_register_name (&ex))
  1221. {
  1222. input_line_pointer = hold;
  1223. str = hold;
  1224. goto error;
  1225. }
  1226. }
  1227. else if (operand->flags & MN10300_OPERAND_FPCR)
  1228. {
  1229. char *start;
  1230. char c = get_symbol_name (&start);
  1231. if (strcasecmp (start, "fpcr") != 0)
  1232. {
  1233. (void) restore_line_pointer (c);
  1234. input_line_pointer = hold;
  1235. str = hold;
  1236. goto error;
  1237. }
  1238. (void) restore_line_pointer (c);
  1239. goto keep_going;
  1240. }
  1241. else if (operand->flags & MN10300_OPERAND_USP)
  1242. {
  1243. char *start;
  1244. char c = get_symbol_name (&start);
  1245. if (strcasecmp (start, "usp") != 0)
  1246. {
  1247. (void) restore_line_pointer (c);
  1248. input_line_pointer = hold;
  1249. str = hold;
  1250. goto error;
  1251. }
  1252. (void) restore_line_pointer (c);
  1253. goto keep_going;
  1254. }
  1255. else if (operand->flags & MN10300_OPERAND_SSP)
  1256. {
  1257. char *start;
  1258. char c = get_symbol_name (&start);
  1259. if (strcasecmp (start, "ssp") != 0)
  1260. {
  1261. (void) restore_line_pointer (c);
  1262. input_line_pointer = hold;
  1263. str = hold;
  1264. goto error;
  1265. }
  1266. (void) restore_line_pointer (c);
  1267. goto keep_going;
  1268. }
  1269. else if (operand->flags & MN10300_OPERAND_MSP)
  1270. {
  1271. char *start;
  1272. char c = get_symbol_name (&start);
  1273. if (strcasecmp (start, "msp") != 0)
  1274. {
  1275. (void) restore_line_pointer (c);
  1276. input_line_pointer = hold;
  1277. str = hold;
  1278. goto error;
  1279. }
  1280. (void) restore_line_pointer (c);
  1281. goto keep_going;
  1282. }
  1283. else if (operand->flags & MN10300_OPERAND_PC)
  1284. {
  1285. char *start;
  1286. char c = get_symbol_name (&start);
  1287. if (strcasecmp (start, "pc") != 0)
  1288. {
  1289. (void) restore_line_pointer (c);
  1290. input_line_pointer = hold;
  1291. str = hold;
  1292. goto error;
  1293. }
  1294. (void) restore_line_pointer (c);
  1295. goto keep_going;
  1296. }
  1297. else if (operand->flags & MN10300_OPERAND_EPSW)
  1298. {
  1299. char *start;
  1300. char c = get_symbol_name (&start);
  1301. if (strcasecmp (start, "epsw") != 0)
  1302. {
  1303. (void) restore_line_pointer (c);
  1304. input_line_pointer = hold;
  1305. str = hold;
  1306. goto error;
  1307. }
  1308. (void) restore_line_pointer (c);
  1309. goto keep_going;
  1310. }
  1311. else if (operand->flags & MN10300_OPERAND_PLUS)
  1312. {
  1313. if (*input_line_pointer != '+')
  1314. {
  1315. input_line_pointer = hold;
  1316. str = hold;
  1317. goto error;
  1318. }
  1319. input_line_pointer++;
  1320. goto keep_going;
  1321. }
  1322. else if (operand->flags & MN10300_OPERAND_PSW)
  1323. {
  1324. char *start;
  1325. char c = get_symbol_name (&start);
  1326. if (strcasecmp (start, "psw") != 0)
  1327. {
  1328. (void) restore_line_pointer (c);
  1329. input_line_pointer = hold;
  1330. str = hold;
  1331. goto error;
  1332. }
  1333. (void) restore_line_pointer (c);
  1334. goto keep_going;
  1335. }
  1336. else if (operand->flags & MN10300_OPERAND_MDR)
  1337. {
  1338. char *start;
  1339. char c = get_symbol_name (&start);
  1340. if (strcasecmp (start, "mdr") != 0)
  1341. {
  1342. (void) restore_line_pointer (c);
  1343. input_line_pointer = hold;
  1344. str = hold;
  1345. goto error;
  1346. }
  1347. (void) restore_line_pointer (c);
  1348. goto keep_going;
  1349. }
  1350. else if (operand->flags & MN10300_OPERAND_REG_LIST)
  1351. {
  1352. unsigned int value = 0;
  1353. if (*input_line_pointer != '[')
  1354. {
  1355. input_line_pointer = hold;
  1356. str = hold;
  1357. goto error;
  1358. }
  1359. /* Eat the '['. */
  1360. input_line_pointer++;
  1361. /* We used to reject a null register list here; however,
  1362. we accept it now so the compiler can emit "call"
  1363. instructions for all calls to named functions.
  1364. The linker can then fill in the appropriate bits for the
  1365. register list and stack size or change the instruction
  1366. into a "calls" if using "call" is not profitable. */
  1367. while (*input_line_pointer != ']')
  1368. {
  1369. char *start;
  1370. char c;
  1371. if (*input_line_pointer == ',')
  1372. input_line_pointer++;
  1373. c = get_symbol_name (&start);
  1374. if (strcasecmp (start, "d2") == 0)
  1375. {
  1376. value |= 0x80;
  1377. (void) restore_line_pointer (c);
  1378. }
  1379. else if (strcasecmp (start, "d3") == 0)
  1380. {
  1381. value |= 0x40;
  1382. (void) restore_line_pointer (c);
  1383. }
  1384. else if (strcasecmp (start, "a2") == 0)
  1385. {
  1386. value |= 0x20;
  1387. (void) restore_line_pointer (c);
  1388. }
  1389. else if (strcasecmp (start, "a3") == 0)
  1390. {
  1391. value |= 0x10;
  1392. (void) restore_line_pointer (c);
  1393. }
  1394. else if (strcasecmp (start, "other") == 0)
  1395. {
  1396. value |= 0x08;
  1397. (void) restore_line_pointer (c);
  1398. }
  1399. else if (HAVE_AM33
  1400. && strcasecmp (start, "exreg0") == 0)
  1401. {
  1402. value |= 0x04;
  1403. (void) restore_line_pointer (c);
  1404. }
  1405. else if (HAVE_AM33
  1406. && strcasecmp (start, "exreg1") == 0)
  1407. {
  1408. value |= 0x02;
  1409. (void) restore_line_pointer (c);
  1410. }
  1411. else if (HAVE_AM33
  1412. && strcasecmp (start, "exother") == 0)
  1413. {
  1414. value |= 0x01;
  1415. (void) restore_line_pointer (c);
  1416. }
  1417. else if (HAVE_AM33
  1418. && strcasecmp (start, "all") == 0)
  1419. {
  1420. value |= 0xff;
  1421. (void) restore_line_pointer (c);
  1422. }
  1423. else
  1424. {
  1425. input_line_pointer = hold;
  1426. str = hold;
  1427. goto error;
  1428. }
  1429. }
  1430. input_line_pointer++;
  1431. mn10300_insert_operand (& insn, & extension, operand,
  1432. value, NULL, 0, 0);
  1433. goto keep_going;
  1434. }
  1435. else if (data_register_name (&ex))
  1436. {
  1437. input_line_pointer = hold;
  1438. str = hold;
  1439. goto error;
  1440. }
  1441. else if (address_register_name (&ex))
  1442. {
  1443. input_line_pointer = hold;
  1444. str = hold;
  1445. goto error;
  1446. }
  1447. else if (other_register_name (&ex))
  1448. {
  1449. input_line_pointer = hold;
  1450. str = hold;
  1451. goto error;
  1452. }
  1453. else if (HAVE_AM33 && r_register_name (&ex))
  1454. {
  1455. input_line_pointer = hold;
  1456. str = hold;
  1457. goto error;
  1458. }
  1459. else if (HAVE_AM33 && xr_register_name (&ex))
  1460. {
  1461. input_line_pointer = hold;
  1462. str = hold;
  1463. goto error;
  1464. }
  1465. else if (HAVE_AM33_2 && float_register_name (&ex))
  1466. {
  1467. input_line_pointer = hold;
  1468. str = hold;
  1469. goto error;
  1470. }
  1471. else if (HAVE_AM33_2 && double_register_name (&ex))
  1472. {
  1473. input_line_pointer = hold;
  1474. str = hold;
  1475. goto error;
  1476. }
  1477. else if (*str == ')' || *str == '(')
  1478. {
  1479. input_line_pointer = hold;
  1480. str = hold;
  1481. goto error;
  1482. }
  1483. else
  1484. {
  1485. expression (&ex);
  1486. }
  1487. switch (ex.X_op)
  1488. {
  1489. case O_illegal:
  1490. errmsg = _("illegal operand");
  1491. goto error;
  1492. case O_absent:
  1493. errmsg = _("missing operand");
  1494. goto error;
  1495. case O_register:
  1496. {
  1497. int mask;
  1498. mask = MN10300_OPERAND_DREG | MN10300_OPERAND_AREG;
  1499. if (HAVE_AM33)
  1500. mask |= MN10300_OPERAND_RREG | MN10300_OPERAND_XRREG;
  1501. if (HAVE_AM33_2)
  1502. mask |= MN10300_OPERAND_FSREG | MN10300_OPERAND_FDREG;
  1503. if ((operand->flags & mask) == 0)
  1504. {
  1505. input_line_pointer = hold;
  1506. str = hold;
  1507. goto error;
  1508. }
  1509. if (opcode->format == FMT_D1 || opcode->format == FMT_S1)
  1510. extra_shift = 8;
  1511. else if (opcode->format == FMT_D2
  1512. || opcode->format == FMT_D4
  1513. || opcode->format == FMT_S2
  1514. || opcode->format == FMT_S4
  1515. || opcode->format == FMT_S6
  1516. || opcode->format == FMT_D5)
  1517. extra_shift = 16;
  1518. else if (opcode->format == FMT_D7)
  1519. extra_shift = 8;
  1520. else if (opcode->format == FMT_D8 || opcode->format == FMT_D9)
  1521. extra_shift = 8;
  1522. else
  1523. extra_shift = 0;
  1524. mn10300_insert_operand (& insn, & extension, operand,
  1525. ex.X_add_number, NULL,
  1526. 0, extra_shift);
  1527. /* And note the register number in the register array. */
  1528. mn10300_reg_operands[op_idx - 1] = ex.X_add_number;
  1529. break;
  1530. }
  1531. case O_constant:
  1532. /* If this operand can be promoted, and it doesn't
  1533. fit into the allocated bitfield for this insn,
  1534. then promote it (ie this opcode does not match). */
  1535. if (operand->flags
  1536. & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX)
  1537. && !check_operand (operand, ex.X_add_number))
  1538. {
  1539. input_line_pointer = hold;
  1540. str = hold;
  1541. goto error;
  1542. }
  1543. mn10300_insert_operand (& insn, & extension, operand,
  1544. ex.X_add_number, NULL, 0, 0);
  1545. break;
  1546. default:
  1547. /* If this operand can be promoted, then this opcode didn't
  1548. match since we can't know if it needed promotion! */
  1549. if (operand->flags & MN10300_OPERAND_PROMOTE)
  1550. {
  1551. input_line_pointer = hold;
  1552. str = hold;
  1553. goto error;
  1554. }
  1555. /* We need to generate a fixup for this expression. */
  1556. if (fc >= MAX_INSN_FIXUPS)
  1557. as_fatal (_("too many fixups"));
  1558. fixups[fc].exp = ex;
  1559. fixups[fc].opindex = *opindex_ptr;
  1560. fixups[fc].reloc = BFD_RELOC_UNUSED;
  1561. if (mn10300_check_fixup (& fixups[fc]))
  1562. goto error;
  1563. ++fc;
  1564. break;
  1565. }
  1566. keep_going:
  1567. str = input_line_pointer;
  1568. input_line_pointer = hold;
  1569. while (*str == ' ' || *str == ',')
  1570. ++str;
  1571. }
  1572. /* Make sure we used all the operands! */
  1573. if (*str != ',')
  1574. match = 1;
  1575. /* If this instruction has registers that must not match, verify
  1576. that they do indeed not match. */
  1577. if (opcode->no_match_operands)
  1578. {
  1579. /* Look at each operand to see if it's marked. */
  1580. for (i = 0; i < MN10300_MAX_OPERANDS; i++)
  1581. {
  1582. if ((1 << i) & opcode->no_match_operands)
  1583. {
  1584. int j;
  1585. /* operand I is marked. Check that it does not match any
  1586. operands > I which are marked. */
  1587. for (j = i + 1; j < MN10300_MAX_OPERANDS; j++)
  1588. {
  1589. if (((1 << j) & opcode->no_match_operands)
  1590. && mn10300_reg_operands[i] == mn10300_reg_operands[j])
  1591. {
  1592. errmsg = _("Invalid register specification.");
  1593. match = 0;
  1594. goto error;
  1595. }
  1596. }
  1597. }
  1598. }
  1599. }
  1600. error:
  1601. if (match == 0)
  1602. {
  1603. next_opcode = opcode + 1;
  1604. if (!strcmp (next_opcode->name, opcode->name))
  1605. {
  1606. opcode = next_opcode;
  1607. continue;
  1608. }
  1609. as_bad ("%s", errmsg);
  1610. return;
  1611. }
  1612. break;
  1613. }
  1614. while (ISSPACE (*str))
  1615. ++str;
  1616. if (*str != '\0')
  1617. as_bad (_("junk at end of line: `%s'"), str);
  1618. input_line_pointer = str;
  1619. /* Determine the size of the instruction. */
  1620. if (opcode->format == FMT_S0)
  1621. size = 1;
  1622. if (opcode->format == FMT_S1 || opcode->format == FMT_D0)
  1623. size = 2;
  1624. if (opcode->format == FMT_S2 || opcode->format == FMT_D1)
  1625. size = 3;
  1626. if (opcode->format == FMT_D6)
  1627. size = 3;
  1628. if (opcode->format == FMT_D7 || opcode->format == FMT_D10)
  1629. size = 4;
  1630. if (opcode->format == FMT_D8)
  1631. size = 6;
  1632. if (opcode->format == FMT_D9)
  1633. size = 7;
  1634. if (opcode->format == FMT_S4)
  1635. size = 5;
  1636. if (opcode->format == FMT_S6 || opcode->format == FMT_D5)
  1637. size = 7;
  1638. if (opcode->format == FMT_D2)
  1639. size = 4;
  1640. if (opcode->format == FMT_D3)
  1641. size = 5;
  1642. if (opcode->format == FMT_D4)
  1643. size = 6;
  1644. if (relaxable && fc > 0)
  1645. {
  1646. /* On a 64-bit host the size of an 'int' is not the same
  1647. as the size of a pointer, so we need a union to convert
  1648. the opindex field of the fr_cgen structure into a char *
  1649. so that it can be stored in the frag. We do not have
  1650. to worry about loosing accuracy as we are not going to
  1651. be even close to the 32bit limit of the int. */
  1652. union
  1653. {
  1654. int opindex;
  1655. char * ptr;
  1656. }
  1657. opindex_converter;
  1658. int type;
  1659. /* We want to anchor the line info to the previous frag (if
  1660. there isn't one, create it), so that, when the insn is
  1661. resized, we still get the right address for the beginning of
  1662. the region. */
  1663. f = frag_more (0);
  1664. dwarf2_emit_insn (0);
  1665. /* bCC */
  1666. if (size == 2)
  1667. {
  1668. /* Handle bra specially. Basically treat it like jmp so
  1669. that we automatically handle 8, 16 and 32 bit offsets
  1670. correctly as well as jumps to an undefined address.
  1671. It is also important to not treat it like other bCC
  1672. instructions since the long forms of bra is different
  1673. from other bCC instructions. */
  1674. if (opcode->opcode == 0xca00)
  1675. type = 10;
  1676. else
  1677. type = 0;
  1678. }
  1679. /* call */
  1680. else if (size == 5)
  1681. type = 6;
  1682. /* calls */
  1683. else if (size == 4)
  1684. type = 8;
  1685. /* jmp */
  1686. else if (size == 3 && opcode->opcode == 0xcc0000)
  1687. type = 10;
  1688. else if (size == 3 && (opcode->opcode & 0xfff000) == 0xf8d000)
  1689. type = 13;
  1690. /* bCC (uncommon cases) */
  1691. else
  1692. type = 3;
  1693. opindex_converter.opindex = fixups[0].opindex;
  1694. f = frag_var (rs_machine_dependent, 8, 8 - size, type,
  1695. fixups[0].exp.X_add_symbol,
  1696. fixups[0].exp.X_add_number,
  1697. opindex_converter.ptr);
  1698. /* This is pretty hokey. We basically just care about the
  1699. opcode, so we have to write out the first word big endian.
  1700. The exception is "call", which has two operands that we
  1701. care about.
  1702. The first operand (the register list) happens to be in the
  1703. first instruction word, and will be in the right place if
  1704. we output the first word in big endian mode.
  1705. The second operand (stack size) is in the extension word,
  1706. and we want it to appear as the first character in the extension
  1707. word (as it appears in memory). Luckily, writing the extension
  1708. word in big endian format will do what we want. */
  1709. number_to_chars_bigendian (f, insn, size > 4 ? 4 : size);
  1710. if (size > 8)
  1711. {
  1712. number_to_chars_bigendian (f + 4, extension, 4);
  1713. number_to_chars_bigendian (f + 8, 0, size - 8);
  1714. }
  1715. else if (size > 4)
  1716. number_to_chars_bigendian (f + 4, extension, size - 4);
  1717. }
  1718. else
  1719. {
  1720. /* Allocate space for the instruction. */
  1721. f = frag_more (size);
  1722. /* Fill in bytes for the instruction. Note that opcode fields
  1723. are written big-endian, 16 & 32bit immediates are written
  1724. little endian. Egad. */
  1725. if (opcode->format == FMT_S0
  1726. || opcode->format == FMT_S1
  1727. || opcode->format == FMT_D0
  1728. || opcode->format == FMT_D6
  1729. || opcode->format == FMT_D7
  1730. || opcode->format == FMT_D10
  1731. || opcode->format == FMT_D1)
  1732. {
  1733. number_to_chars_bigendian (f, insn, size);
  1734. }
  1735. else if (opcode->format == FMT_S2
  1736. && opcode->opcode != 0xdf0000
  1737. && opcode->opcode != 0xde0000)
  1738. {
  1739. /* A format S2 instruction that is _not_ "ret" and "retf". */
  1740. number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1);
  1741. number_to_chars_littleendian (f + 1, insn & 0xffff, 2);
  1742. }
  1743. else if (opcode->format == FMT_S2)
  1744. {
  1745. /* This must be a ret or retf, which is written entirely in
  1746. big-endian format. */
  1747. number_to_chars_bigendian (f, insn, 3);
  1748. }
  1749. else if (opcode->format == FMT_S4
  1750. && opcode->opcode != 0xdc000000)
  1751. {
  1752. /* This must be a format S4 "call" instruction. What a pain. */
  1753. unsigned long temp = (insn >> 8) & 0xffff;
  1754. number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
  1755. number_to_chars_littleendian (f + 1, temp, 2);
  1756. number_to_chars_bigendian (f + 3, insn & 0xff, 1);
  1757. number_to_chars_bigendian (f + 4, extension & 0xff, 1);
  1758. }
  1759. else if (opcode->format == FMT_S4)
  1760. {
  1761. /* This must be a format S4 "jmp" instruction. */
  1762. unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff);
  1763. number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
  1764. number_to_chars_littleendian (f + 1, temp, 4);
  1765. }
  1766. else if (opcode->format == FMT_S6)
  1767. {
  1768. unsigned long temp = ((insn & 0xffffff) << 8)
  1769. | ((extension >> 16) & 0xff);
  1770. number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
  1771. number_to_chars_littleendian (f + 1, temp, 4);
  1772. number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1);
  1773. number_to_chars_bigendian (f + 6, extension & 0xff, 1);
  1774. }
  1775. else if (opcode->format == FMT_D2
  1776. && opcode->opcode != 0xfaf80000
  1777. && opcode->opcode != 0xfaf00000
  1778. && opcode->opcode != 0xfaf40000)
  1779. {
  1780. /* A format D2 instruction where the 16bit immediate is
  1781. really a single 16bit value, not two 8bit values. */
  1782. number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
  1783. number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
  1784. }
  1785. else if (opcode->format == FMT_D2)
  1786. {
  1787. /* A format D2 instruction where the 16bit immediate
  1788. is really two 8bit immediates. */
  1789. number_to_chars_bigendian (f, insn, 4);
  1790. }
  1791. else if (opcode->format == FMT_D3)
  1792. {
  1793. number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
  1794. number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
  1795. number_to_chars_bigendian (f + 4, extension & 0xff, 1);
  1796. }
  1797. else if (opcode->format == FMT_D4)
  1798. {
  1799. unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff);
  1800. number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
  1801. number_to_chars_littleendian (f + 2, temp, 4);
  1802. }
  1803. else if (opcode->format == FMT_D5)
  1804. {
  1805. unsigned long temp = (((insn & 0xffff) << 16)
  1806. | ((extension >> 8) & 0xffff));
  1807. number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
  1808. number_to_chars_littleendian (f + 2, temp, 4);
  1809. number_to_chars_bigendian (f + 6, extension & 0xff, 1);
  1810. }
  1811. else if (opcode->format == FMT_D8)
  1812. {
  1813. unsigned long temp = ((insn & 0xff) << 16) | (extension & 0xffff);
  1814. number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
  1815. number_to_chars_bigendian (f + 3, (temp & 0xff), 1);
  1816. number_to_chars_littleendian (f + 4, temp >> 8, 2);
  1817. }
  1818. else if (opcode->format == FMT_D9)
  1819. {
  1820. unsigned long temp = ((insn & 0xff) << 24) | (extension & 0xffffff);
  1821. number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
  1822. number_to_chars_littleendian (f + 3, temp, 4);
  1823. }
  1824. /* Create any fixups. */
  1825. for (i = 0; i < fc; i++)
  1826. {
  1827. const struct mn10300_operand *operand;
  1828. int reloc_size;
  1829. operand = &mn10300_operands[fixups[i].opindex];
  1830. if (fixups[i].reloc != BFD_RELOC_UNUSED
  1831. && fixups[i].reloc != BFD_RELOC_32_GOT_PCREL
  1832. && fixups[i].reloc != BFD_RELOC_32_GOTOFF
  1833. && fixups[i].reloc != BFD_RELOC_32_PLT_PCREL
  1834. && fixups[i].reloc != BFD_RELOC_MN10300_TLS_GD
  1835. && fixups[i].reloc != BFD_RELOC_MN10300_TLS_LD
  1836. && fixups[i].reloc != BFD_RELOC_MN10300_TLS_LDO
  1837. && fixups[i].reloc != BFD_RELOC_MN10300_TLS_GOTIE
  1838. && fixups[i].reloc != BFD_RELOC_MN10300_TLS_IE
  1839. && fixups[i].reloc != BFD_RELOC_MN10300_TLS_LE
  1840. && fixups[i].reloc != BFD_RELOC_MN10300_GOT32)
  1841. {
  1842. reloc_howto_type *reloc_howto;
  1843. int offset;
  1844. reloc_howto = bfd_reloc_type_lookup (stdoutput,
  1845. fixups[i].reloc);
  1846. if (!reloc_howto)
  1847. abort ();
  1848. reloc_size = bfd_get_reloc_size (reloc_howto);
  1849. if (reloc_size < 1 || reloc_size > 4)
  1850. abort ();
  1851. offset = 4 - size;
  1852. fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
  1853. reloc_size, &fixups[i].exp,
  1854. reloc_howto->pc_relative,
  1855. fixups[i].reloc);
  1856. }
  1857. else
  1858. {
  1859. int reloc, pcrel, offset;
  1860. fixS *fixP;
  1861. reloc = BFD_RELOC_NONE;
  1862. if (fixups[i].reloc != BFD_RELOC_UNUSED)
  1863. reloc = fixups[i].reloc;
  1864. /* How big is the reloc? Remember SPLIT relocs are
  1865. implicitly 32bits. */
  1866. if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
  1867. reloc_size = 32;
  1868. else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
  1869. reloc_size = 24;
  1870. else
  1871. reloc_size = operand->bits;
  1872. /* Is the reloc pc-relative? */
  1873. pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0;
  1874. if (reloc != BFD_RELOC_NONE)
  1875. pcrel = bfd_reloc_type_lookup (stdoutput, reloc)->pc_relative;
  1876. offset = size - (reloc_size + operand->shift) / 8;
  1877. /* Choose a proper BFD relocation type. */
  1878. if (reloc != BFD_RELOC_NONE)
  1879. ;
  1880. else if (pcrel)
  1881. {
  1882. if (reloc_size == 32)
  1883. reloc = BFD_RELOC_32_PCREL;
  1884. else if (reloc_size == 16)
  1885. reloc = BFD_RELOC_16_PCREL;
  1886. else if (reloc_size == 8)
  1887. reloc = BFD_RELOC_8_PCREL;
  1888. else
  1889. abort ();
  1890. }
  1891. else
  1892. {
  1893. if (reloc_size == 32)
  1894. reloc = BFD_RELOC_32;
  1895. else if (reloc_size == 16)
  1896. reloc = BFD_RELOC_16;
  1897. else if (reloc_size == 8)
  1898. reloc = BFD_RELOC_8;
  1899. else
  1900. abort ();
  1901. }
  1902. fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
  1903. reloc_size / 8, &fixups[i].exp, pcrel,
  1904. ((bfd_reloc_code_real_type) reloc));
  1905. if (pcrel)
  1906. fixP->fx_offset += offset;
  1907. }
  1908. }
  1909. dwarf2_emit_insn (size);
  1910. }
  1911. /* Label this frag as one that contains instructions. */
  1912. frag_now->tc_frag_data = TRUE;
  1913. }
  1914. /* If while processing a fixup, a reloc really needs to be created
  1915. then it is done here. */
  1916. arelent **
  1917. tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
  1918. {
  1919. static arelent * no_relocs = NULL;
  1920. static arelent * relocs[MAX_RELOC_EXPANSION + 1];
  1921. arelent *reloc;
  1922. reloc = xmalloc (sizeof (arelent));
  1923. reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
  1924. if (reloc->howto == NULL)
  1925. {
  1926. as_bad_where (fixp->fx_file, fixp->fx_line,
  1927. _("reloc %d not supported by object file format"),
  1928. (int) fixp->fx_r_type);
  1929. free (reloc);
  1930. return & no_relocs;
  1931. }
  1932. reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1933. relocs[0] = reloc;
  1934. relocs[1] = NULL;
  1935. if (fixp->fx_subsy
  1936. && S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
  1937. {
  1938. fixp->fx_offset -= S_GET_VALUE (fixp->fx_subsy);
  1939. fixp->fx_subsy = NULL;
  1940. }
  1941. if (fixp->fx_addsy && fixp->fx_subsy)
  1942. {
  1943. asection *asec, *ssec;
  1944. asec = S_GET_SEGMENT (fixp->fx_addsy);
  1945. ssec = S_GET_SEGMENT (fixp->fx_subsy);
  1946. /* If we have a difference between two (non-absolute) symbols we must
  1947. generate two relocs (one for each symbol) and allow the linker to
  1948. resolve them - relaxation may change the distances between symbols,
  1949. even local symbols defined in the same section. */
  1950. if (ssec != absolute_section || asec != absolute_section)
  1951. {
  1952. arelent * reloc2 = xmalloc (sizeof * reloc);
  1953. relocs[0] = reloc2;
  1954. relocs[1] = reloc;
  1955. reloc2->address = reloc->address;
  1956. reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_MN10300_SYM_DIFF);
  1957. reloc2->addend = - S_GET_VALUE (fixp->fx_subsy);
  1958. reloc2->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  1959. *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
  1960. reloc->addend = fixp->fx_offset;
  1961. if (asec == absolute_section)
  1962. {
  1963. reloc->addend += S_GET_VALUE (fixp->fx_addsy);
  1964. reloc->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
  1965. }
  1966. else
  1967. {
  1968. reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  1969. *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  1970. }
  1971. fixp->fx_pcrel = 0;
  1972. fixp->fx_done = 1;
  1973. return relocs;
  1974. }
  1975. else
  1976. {
  1977. char *fixpos = fixp->fx_where + fixp->fx_frag->fr_literal;
  1978. reloc->addend = (S_GET_VALUE (fixp->fx_addsy)
  1979. - S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset);
  1980. switch (fixp->fx_r_type)
  1981. {
  1982. case BFD_RELOC_8:
  1983. md_number_to_chars (fixpos, reloc->addend, 1);
  1984. break;
  1985. case BFD_RELOC_16:
  1986. md_number_to_chars (fixpos, reloc->addend, 2);
  1987. break;
  1988. case BFD_RELOC_24:
  1989. md_number_to_chars (fixpos, reloc->addend, 3);
  1990. break;
  1991. case BFD_RELOC_32:
  1992. md_number_to_chars (fixpos, reloc->addend, 4);
  1993. break;
  1994. default:
  1995. reloc->sym_ptr_ptr
  1996. = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
  1997. return relocs;
  1998. }
  1999. free (reloc);
  2000. return & no_relocs;
  2001. }
  2002. }
  2003. else
  2004. {
  2005. reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  2006. *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  2007. reloc->addend = fixp->fx_offset;
  2008. }
  2009. return relocs;
  2010. }
  2011. /* Returns true iff the symbol attached to the frag is at a known location
  2012. in the given section, (and hence the relocation to it can be relaxed by
  2013. the assembler). */
  2014. static inline bfd_boolean
  2015. has_known_symbol_location (fragS * fragp, asection * sec)
  2016. {
  2017. symbolS * sym = fragp->fr_symbol;
  2018. return sym != NULL
  2019. && S_IS_DEFINED (sym)
  2020. && ! S_IS_WEAK (sym)
  2021. && S_GET_SEGMENT (sym) == sec;
  2022. }
  2023. int
  2024. md_estimate_size_before_relax (fragS *fragp, asection *seg)
  2025. {
  2026. if (fragp->fr_subtype == 6
  2027. && ! has_known_symbol_location (fragp, seg))
  2028. fragp->fr_subtype = 7;
  2029. else if (fragp->fr_subtype == 8
  2030. && ! has_known_symbol_location (fragp, seg))
  2031. fragp->fr_subtype = 9;
  2032. else if (fragp->fr_subtype == 10
  2033. && ! has_known_symbol_location (fragp, seg))
  2034. fragp->fr_subtype = 12;
  2035. if (fragp->fr_subtype == 13)
  2036. return 3;
  2037. if (fragp->fr_subtype >= sizeof (md_relax_table) / sizeof (md_relax_table[0]))
  2038. abort ();
  2039. return md_relax_table[fragp->fr_subtype].rlx_length;
  2040. }
  2041. long
  2042. md_pcrel_from (fixS *fixp)
  2043. {
  2044. if (fixp->fx_addsy != (symbolS *) NULL
  2045. && (!S_IS_DEFINED (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
  2046. /* The symbol is undefined or weak. Let the linker figure it out. */
  2047. return 0;
  2048. return fixp->fx_frag->fr_address + fixp->fx_where;
  2049. }
  2050. void
  2051. md_apply_fix (fixS * fixP, valueT * valP, segT seg)
  2052. {
  2053. char * fixpos = fixP->fx_where + fixP->fx_frag->fr_literal;
  2054. int size = 0;
  2055. int value = (int) * valP;
  2056. gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
  2057. /* This should never happen. */
  2058. if (seg->flags & SEC_ALLOC)
  2059. abort ();
  2060. /* The value we are passed in *valuep includes the symbol values.
  2061. If we are doing this relocation the code in write.c is going to
  2062. call bfd_install_relocation, which is also going to use the symbol
  2063. value. That means that if the reloc is fully resolved we want to
  2064. use *valuep since bfd_install_relocation is not being used.
  2065. However, if the reloc is not fully resolved we do not want to use
  2066. *valuep, and must use fx_offset instead. However, if the reloc
  2067. is PC relative, we do want to use *valuep since it includes the
  2068. result of md_pcrel_from. */
  2069. if (fixP->fx_addsy != NULL && ! fixP->fx_pcrel)
  2070. value = fixP->fx_offset;
  2071. /* If the fix is relative to a symbol which is not defined, or not
  2072. in the same segment as the fix, we cannot resolve it here. */
  2073. if (fixP->fx_addsy != NULL
  2074. && (! S_IS_DEFINED (fixP->fx_addsy)
  2075. || (S_GET_SEGMENT (fixP->fx_addsy) != seg)))
  2076. {
  2077. fixP->fx_done = 0;
  2078. return;
  2079. }
  2080. switch (fixP->fx_r_type)
  2081. {
  2082. case BFD_RELOC_8:
  2083. case BFD_RELOC_8_PCREL:
  2084. size = 1;
  2085. break;
  2086. case BFD_RELOC_16:
  2087. case BFD_RELOC_16_PCREL:
  2088. size = 2;
  2089. break;
  2090. case BFD_RELOC_32:
  2091. case BFD_RELOC_32_PCREL:
  2092. size = 4;
  2093. break;
  2094. case BFD_RELOC_VTABLE_INHERIT:
  2095. case BFD_RELOC_VTABLE_ENTRY:
  2096. fixP->fx_done = 0;
  2097. return;
  2098. case BFD_RELOC_MN10300_ALIGN:
  2099. fixP->fx_done = 1;
  2100. return;
  2101. case BFD_RELOC_NONE:
  2102. default:
  2103. as_bad_where (fixP->fx_file, fixP->fx_line,
  2104. _("Bad relocation fixup type (%d)"), fixP->fx_r_type);
  2105. }
  2106. md_number_to_chars (fixpos, value, size);
  2107. /* If a symbol remains, pass the fixup, as a reloc, onto the linker. */
  2108. if (fixP->fx_addsy == NULL)
  2109. fixP->fx_done = 1;
  2110. }
  2111. /* Return zero if the fixup in fixp should be left alone and not
  2112. adjusted. */
  2113. bfd_boolean
  2114. mn10300_fix_adjustable (struct fix *fixp)
  2115. {
  2116. if (fixp->fx_pcrel)
  2117. {
  2118. if (TC_FORCE_RELOCATION_LOCAL (fixp))
  2119. return FALSE;
  2120. }
  2121. /* Non-relative relocs can (and must) be adjusted if they do
  2122. not meet the criteria below, or the generic criteria. */
  2123. else if (TC_FORCE_RELOCATION (fixp))
  2124. return FALSE;
  2125. /* Do not adjust relocations involving symbols in code sections,
  2126. because it breaks linker relaxations. This could be fixed in the
  2127. linker, but this fix is simpler, and it pretty much only affects
  2128. object size a little bit. */
  2129. if (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_CODE)
  2130. return FALSE;
  2131. /* Likewise, do not adjust symbols that won't be merged, or debug
  2132. symbols, because they too break relaxation. We do want to adjust
  2133. other mergable symbols, like .rodata, because code relaxations
  2134. need section-relative symbols to properly relax them. */
  2135. if (! (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE))
  2136. return FALSE;
  2137. if (strncmp (S_GET_SEGMENT (fixp->fx_addsy)->name, ".debug", 6) == 0)
  2138. return FALSE;
  2139. return TRUE;
  2140. }
  2141. static void
  2142. set_arch_mach (int mach)
  2143. {
  2144. if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, mach))
  2145. as_warn (_("could not set architecture and machine"));
  2146. current_machine = mach;
  2147. }
  2148. static inline char *
  2149. mn10300_end_of_match (char *cont, char *what)
  2150. {
  2151. int len = strlen (what);
  2152. if (strncmp (cont, what, strlen (what)) == 0
  2153. && ! is_part_of_name (cont[len]))
  2154. return cont + len;
  2155. return NULL;
  2156. }
  2157. int
  2158. mn10300_parse_name (char const *name,
  2159. expressionS *exprP,
  2160. enum expr_mode mode,
  2161. char *nextcharP)
  2162. {
  2163. char *next = input_line_pointer;
  2164. char *next_end;
  2165. int reloc_type;
  2166. segT segment;
  2167. exprP->X_op_symbol = NULL;
  2168. if (strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0)
  2169. {
  2170. if (! GOT_symbol)
  2171. GOT_symbol = symbol_find_or_make (name);
  2172. exprP->X_add_symbol = GOT_symbol;
  2173. no_suffix:
  2174. /* If we have an absolute symbol or a reg,
  2175. then we know its value now. */
  2176. segment = S_GET_SEGMENT (exprP->X_add_symbol);
  2177. if (mode != expr_defer && segment == absolute_section)
  2178. {
  2179. exprP->X_op = O_constant;
  2180. exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
  2181. exprP->X_add_symbol = NULL;
  2182. }
  2183. else if (mode != expr_defer && segment == reg_section)
  2184. {
  2185. exprP->X_op = O_register;
  2186. exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
  2187. exprP->X_add_symbol = NULL;
  2188. }
  2189. else
  2190. {
  2191. exprP->X_op = O_symbol;
  2192. exprP->X_add_number = 0;
  2193. }
  2194. return 1;
  2195. }
  2196. exprP->X_add_symbol = symbol_find_or_make (name);
  2197. if (*nextcharP != '@')
  2198. goto no_suffix;
  2199. else if ((next_end = mn10300_end_of_match (next + 1, "GOTOFF")))
  2200. reloc_type = BFD_RELOC_32_GOTOFF;
  2201. else if ((next_end = mn10300_end_of_match (next + 1, "GOT")))
  2202. reloc_type = BFD_RELOC_MN10300_GOT32;
  2203. else if ((next_end = mn10300_end_of_match (next + 1, "PLT")))
  2204. reloc_type = BFD_RELOC_32_PLT_PCREL;
  2205. else if ((next_end = mn10300_end_of_match (next + 1, "tlsgd")))
  2206. reloc_type = BFD_RELOC_MN10300_TLS_GD;
  2207. else if ((next_end = mn10300_end_of_match (next + 1, "tlsldm")))
  2208. reloc_type = BFD_RELOC_MN10300_TLS_LD;
  2209. else if ((next_end = mn10300_end_of_match (next + 1, "dtpoff")))
  2210. reloc_type = BFD_RELOC_MN10300_TLS_LDO;
  2211. else if ((next_end = mn10300_end_of_match (next + 1, "gotntpoff")))
  2212. reloc_type = BFD_RELOC_MN10300_TLS_GOTIE;
  2213. else if ((next_end = mn10300_end_of_match (next + 1, "indntpoff")))
  2214. reloc_type = BFD_RELOC_MN10300_TLS_IE;
  2215. else if ((next_end = mn10300_end_of_match (next + 1, "tpoff")))
  2216. reloc_type = BFD_RELOC_MN10300_TLS_LE;
  2217. else
  2218. goto no_suffix;
  2219. *input_line_pointer = *nextcharP;
  2220. input_line_pointer = next_end;
  2221. *nextcharP = *input_line_pointer;
  2222. *input_line_pointer = '\0';
  2223. exprP->X_op = O_PIC_reloc;
  2224. exprP->X_add_number = 0;
  2225. exprP->X_md = reloc_type;
  2226. return 1;
  2227. }
  2228. /* The target specific pseudo-ops which we support. */
  2229. const pseudo_typeS md_pseudo_table[] =
  2230. {
  2231. { "am30", set_arch_mach, AM30 },
  2232. { "am33", set_arch_mach, AM33 },
  2233. { "am33_2", set_arch_mach, AM33_2 },
  2234. { "mn10300", set_arch_mach, MN103 },
  2235. {NULL, 0, 0}
  2236. };
  2237. /* Returns FALSE if there is some mn10300 specific reason why the
  2238. subtraction of two same-section symbols cannot be computed by
  2239. the assembler. */
  2240. bfd_boolean
  2241. mn10300_allow_local_subtract (expressionS * left, expressionS * right, segT section)
  2242. {
  2243. bfd_boolean result;
  2244. fragS * left_frag;
  2245. fragS * right_frag;
  2246. fragS * frag;
  2247. /* If we are not performing linker relaxation then we have nothing
  2248. to worry about. */
  2249. if (linkrelax == 0)
  2250. return TRUE;
  2251. /* If the symbols are not in a code section then they are OK. */
  2252. if ((section->flags & SEC_CODE) == 0)
  2253. return TRUE;
  2254. /* Otherwise we have to scan the fragments between the two symbols.
  2255. If any instructions are found then we have to assume that linker
  2256. relaxation may change their size and so we must delay resolving
  2257. the subtraction until the final link. */
  2258. left_frag = symbol_get_frag (left->X_add_symbol);
  2259. right_frag = symbol_get_frag (right->X_add_symbol);
  2260. if (left_frag == right_frag)
  2261. return ! left_frag->tc_frag_data;
  2262. result = TRUE;
  2263. for (frag = left_frag; frag != NULL; frag = frag->fr_next)
  2264. {
  2265. if (frag->tc_frag_data)
  2266. result = FALSE;
  2267. if (frag == right_frag)
  2268. break;
  2269. }
  2270. if (frag == NULL)
  2271. for (frag = right_frag; frag != NULL; frag = frag->fr_next)
  2272. {
  2273. if (frag->tc_frag_data)
  2274. result = FALSE;
  2275. if (frag == left_frag)
  2276. break;
  2277. }
  2278. if (frag == NULL)
  2279. /* The two symbols are on disjoint fragment chains
  2280. - we cannot possibly compute their difference. */
  2281. return FALSE;
  2282. return result;
  2283. }
  2284. /* When relaxing, we need to output a reloc for any .align directive
  2285. that requests alignment to a two byte boundary or larger. */
  2286. void
  2287. mn10300_handle_align (fragS *frag)
  2288. {
  2289. if (linkrelax
  2290. && (frag->fr_type == rs_align
  2291. || frag->fr_type == rs_align_code)
  2292. && frag->fr_address + frag->fr_fix > 0
  2293. && frag->fr_offset > 1
  2294. && now_seg != bss_section
  2295. /* Do not create relocs for the merging sections - such
  2296. relocs will prevent the contents from being merged. */
  2297. && (bfd_get_section_flags (now_seg->owner, now_seg) & SEC_MERGE) == 0)
  2298. /* Create a new fixup to record the alignment request. The symbol is
  2299. irrelevent but must be present so we use the absolute section symbol.
  2300. The offset from the symbol is used to record the power-of-two alignment
  2301. value. The size is set to 0 because the frag may already be aligned,
  2302. thus causing cvt_frag_to_fill to reduce the size of the frag to zero. */
  2303. fix_new (frag, frag->fr_fix, 0, & abs_symbol, frag->fr_offset, FALSE,
  2304. BFD_RELOC_MN10300_ALIGN);
  2305. }
  2306. bfd_boolean
  2307. mn10300_force_relocation (struct fix * fixp)
  2308. {
  2309. if (linkrelax
  2310. && (fixp->fx_pcrel
  2311. || fixp->fx_r_type == BFD_RELOC_MN10300_ALIGN))
  2312. return TRUE;
  2313. return generic_force_reloc (fixp);
  2314. }