tc-i960.c 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666
  1. /* tc-i960.c - All the i80960-specific stuff
  2. Copyright (C) 1989-2015 Free Software Foundation, Inc.
  3. This file is part of GAS.
  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. /* See comment on md_parse_option for 80960-specific invocation options. */
  17. /* There are 4 different lengths of (potentially) symbol-based displacements
  18. in the 80960 instruction set, each of which could require address fix-ups
  19. and (in the case of external symbols) emission of relocation directives:
  20. 32-bit (MEMB)
  21. This is a standard length for the base assembler and requires no
  22. special action.
  23. 13-bit (COBR)
  24. This is a non-standard length, but the base assembler has a
  25. hook for bit field address fixups: the fixS structure can
  26. point to a descriptor of the field, in which case our
  27. md_number_to_field() routine gets called to process it.
  28. I made the hook a little cleaner by having fix_new() (in the base
  29. assembler) return a pointer to the fixS in question. And I made it a
  30. little simpler by storing the field size (in this case 13) instead of
  31. of a pointer to another structure: 80960 displacements are ALWAYS
  32. stored in the low-order bits of a 4-byte word.
  33. Since the target of a COBR cannot be external, no relocation
  34. directives for this size displacement have to be generated.
  35. But the base assembler had to be modified to issue error
  36. messages if the symbol did turn out to be external.
  37. 24-bit (CTRL)
  38. Fixups are handled as for the 13-bit case (except that 24 is stored
  39. in the fixS).
  40. The relocation directive generated is the same as that for the 32-bit
  41. displacement, except that it's PC-relative (the 32-bit displacement
  42. never is). The i80960 version of the linker needs a mod to
  43. distinguish and handle the 24-bit case.
  44. 12-bit (MEMA)
  45. MEMA formats are always promoted to MEMB (32-bit) if the displacement
  46. is based on a symbol, because it could be relocated at link time.
  47. The only time we use the 12-bit format is if an absolute value of
  48. less than 4096 is specified, in which case we need neither a fixup nor
  49. a relocation directive. */
  50. #include "as.h"
  51. #include "safe-ctype.h"
  52. #include "opcode/i960.h"
  53. #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
  54. #define TC_S_IS_SYSPROC(s) ((1 <= S_GET_OTHER (s)) && (S_GET_OTHER (s) <= 32))
  55. #define TC_S_IS_BALNAME(s) (S_GET_OTHER (s) == N_BALNAME)
  56. #define TC_S_IS_CALLNAME(s) (S_GET_OTHER (s) == N_CALLNAME)
  57. #define TC_S_IS_BADPROC(s) ((S_GET_OTHER (s) != 0) && !TC_S_IS_CALLNAME (s) && !TC_S_IS_BALNAME (s) && !TC_S_IS_SYSPROC (s))
  58. #define TC_S_SET_SYSPROC(s, p) (S_SET_OTHER ((s), (p) + 1))
  59. #define TC_S_GET_SYSPROC(s) (S_GET_OTHER (s) - 1)
  60. #define TC_S_FORCE_TO_BALNAME(s) (S_SET_OTHER ((s), N_BALNAME))
  61. #define TC_S_FORCE_TO_CALLNAME(s) (S_SET_OTHER ((s), N_CALLNAME))
  62. #define TC_S_FORCE_TO_SYSPROC(s) {;}
  63. #else /* ! OBJ_A/BOUT */
  64. #ifdef OBJ_COFF
  65. #define TC_S_IS_SYSPROC(s) (S_GET_STORAGE_CLASS (s) == C_SCALL)
  66. #define TC_S_IS_BALNAME(s) (SF_GET_BALNAME (s))
  67. #define TC_S_IS_CALLNAME(s) (SF_GET_CALLNAME (s))
  68. #define TC_S_IS_BADPROC(s) (TC_S_IS_SYSPROC (s) && TC_S_GET_SYSPROC (s) < 0 && 31 < TC_S_GET_SYSPROC (s))
  69. #define TC_S_SET_SYSPROC(s, p) ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx = (p))
  70. #define TC_S_GET_SYSPROC(s) ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx)
  71. #define TC_S_FORCE_TO_BALNAME(s) (SF_SET_BALNAME (s))
  72. #define TC_S_FORCE_TO_CALLNAME(s) (SF_SET_CALLNAME (s))
  73. #define TC_S_FORCE_TO_SYSPROC(s) (S_SET_STORAGE_CLASS ((s), C_SCALL))
  74. #else /* ! OBJ_COFF */
  75. #ifdef OBJ_ELF
  76. #define TC_S_IS_SYSPROC(s) 0
  77. #define TC_S_IS_BALNAME(s) 0
  78. #define TC_S_IS_CALLNAME(s) 0
  79. #define TC_S_IS_BADPROC(s) 0
  80. #define TC_S_SET_SYSPROC(s, p)
  81. #define TC_S_GET_SYSPROC(s) 0
  82. #define TC_S_FORCE_TO_BALNAME(s)
  83. #define TC_S_FORCE_TO_CALLNAME(s)
  84. #define TC_S_FORCE_TO_SYSPROC(s)
  85. #else
  86. #error COFF, a.out, b.out, and ELF are the only supported formats.
  87. #endif /* ! OBJ_ELF */
  88. #endif /* ! OBJ_COFF */
  89. #endif /* ! OBJ_A/BOUT */
  90. extern char *input_line_pointer;
  91. /* Local i80960 routines. */
  92. struct memS;
  93. struct regop;
  94. /* See md_parse_option() for meanings of these options. */
  95. static char norelax; /* True if -norelax switch seen. */
  96. static char instrument_branches; /* True if -b switch seen. */
  97. /* Characters that always start a comment.
  98. If the pre-processor is disabled, these aren't very useful. */
  99. const char comment_chars[] = "#";
  100. /* Characters that only start a comment at the beginning of
  101. a line. If the line seems to have the form '# 123 filename'
  102. .line and .file directives will appear in the pre-processed output.
  103. Note that input_file.c hand checks for '#' at the beginning of the
  104. first line of the input file. This is because the compiler outputs
  105. #NO_APP at the beginning of its output. */
  106. /* Also note that comments started like this one will always work. */
  107. const char line_comment_chars[] = "#";
  108. const char line_separator_chars[] = ";";
  109. /* Chars that can be used to separate mant from exp in floating point nums. */
  110. const char EXP_CHARS[] = "eE";
  111. /* Chars that mean this number is a floating point constant,
  112. as in 0f12.456 or 0d1.2345e12. */
  113. const char FLT_CHARS[] = "fFdDtT";
  114. /* Table used by base assembler to relax addresses based on varying length
  115. instructions. The fields are:
  116. 1) most positive reach of this state,
  117. 2) most negative reach of this state,
  118. 3) how many bytes this mode will add to the size of the current frag
  119. 4) which index into the table to try if we can't fit into this one.
  120. For i80960, the only application is the (de-)optimization of cobr
  121. instructions into separate compare and branch instructions when a 13-bit
  122. displacement won't hack it. */
  123. const relax_typeS md_relax_table[] =
  124. {
  125. {0, 0, 0, 0}, /* State 0 => no more relaxation possible. */
  126. {4088, -4096, 0, 2}, /* State 1: conditional branch (cobr). */
  127. {0x800000 - 8, -0x800000, 4, 0}, /* State 2: compare (reg) & branch (ctrl). */
  128. };
  129. /* These are the machine dependent pseudo-ops.
  130. This table describes all the machine specific pseudo-ops the assembler
  131. has to support. The fields are:
  132. pseudo-op name without dot
  133. function to call to execute this pseudo-op
  134. integer arg to pass to the function. */
  135. #define S_LEAFPROC 1
  136. #define S_SYSPROC 2
  137. /* Macros to extract info from an 'expressionS' structure 'e'. */
  138. #define adds(e) e.X_add_symbol
  139. #define offs(e) e.X_add_number
  140. /* Branch-prediction bits for CTRL/COBR format opcodes. */
  141. #define BP_MASK 0x00000002 /* Mask for branch-prediction bit. */
  142. #define BP_TAKEN 0x00000000 /* Value to OR in to predict branch. */
  143. #define BP_NOT_TAKEN 0x00000002 /* Value to OR in to predict no branch. */
  144. /* Some instruction opcodes that we need explicitly. */
  145. #define BE 0x12000000
  146. #define BG 0x11000000
  147. #define BGE 0x13000000
  148. #define BL 0x14000000
  149. #define BLE 0x16000000
  150. #define BNE 0x15000000
  151. #define BNO 0x10000000
  152. #define BO 0x17000000
  153. #define CHKBIT 0x5a002700
  154. #define CMPI 0x5a002080
  155. #define CMPO 0x5a002000
  156. #define B 0x08000000
  157. #define BAL 0x0b000000
  158. #define CALL 0x09000000
  159. #define CALLS 0x66003800
  160. #define RET 0x0a000000
  161. /* These masks are used to build up a set of MEMB mode bits. */
  162. #define A_BIT 0x0400
  163. #define I_BIT 0x0800
  164. #define MEMB_BIT 0x1000
  165. #define D_BIT 0x2000
  166. /* Mask for the only mode bit in a MEMA instruction (if set, abase reg is
  167. used). */
  168. #define MEMA_ABASE 0x2000
  169. /* Info from which a MEMA or MEMB format instruction can be generated. */
  170. typedef struct memS
  171. {
  172. /* (First) 32 bits of instruction. */
  173. long opcode;
  174. /* 0-(none), 12- or, 32-bit displacement needed. */
  175. int disp;
  176. /* The expression in the source instruction from which the
  177. displacement should be determined. */
  178. char *e;
  179. }
  180. memS;
  181. /* The two pieces of info we need to generate a register operand. */
  182. struct regop
  183. {
  184. int mode; /* 0 =>local/global/spec reg; 1=> literal or fp reg. */
  185. int special; /* 0 =>not a sfr; 1=> is a sfr (not valid w/mode=0). */
  186. int n; /* Register number or literal value. */
  187. };
  188. /* Number and assembler mnemonic for all registers that can appear in
  189. operands. */
  190. static const struct
  191. {
  192. char *reg_name;
  193. int reg_num;
  194. }
  195. regnames[] =
  196. {
  197. { "pfp", 0 },
  198. { "sp", 1 },
  199. { "rip", 2 },
  200. { "r3", 3 },
  201. { "r4", 4 },
  202. { "r5", 5 },
  203. { "r6", 6 },
  204. { "r7", 7 },
  205. { "r8", 8 },
  206. { "r9", 9 },
  207. { "r10", 10 },
  208. { "r11", 11 },
  209. { "r12", 12 },
  210. { "r13", 13 },
  211. { "r14", 14 },
  212. { "r15", 15 },
  213. { "g0", 16 },
  214. { "g1", 17 },
  215. { "g2", 18 },
  216. { "g3", 19 },
  217. { "g4", 20 },
  218. { "g5", 21 },
  219. { "g6", 22 },
  220. { "g7", 23 },
  221. { "g8", 24 },
  222. { "g9", 25 },
  223. { "g10", 26 },
  224. { "g11", 27 },
  225. { "g12", 28 },
  226. { "g13", 29 },
  227. { "g14", 30 },
  228. { "fp", 31 },
  229. /* Numbers for special-function registers are for assembler internal
  230. use only: they are scaled back to range [0-31] for binary output. */
  231. #define SF0 32
  232. { "sf0", 32 },
  233. { "sf1", 33 },
  234. { "sf2", 34 },
  235. { "sf3", 35 },
  236. { "sf4", 36 },
  237. { "sf5", 37 },
  238. { "sf6", 38 },
  239. { "sf7", 39 },
  240. { "sf8", 40 },
  241. { "sf9", 41 },
  242. { "sf10", 42 },
  243. { "sf11", 43 },
  244. { "sf12", 44 },
  245. { "sf13", 45 },
  246. { "sf14", 46 },
  247. { "sf15", 47 },
  248. { "sf16", 48 },
  249. { "sf17", 49 },
  250. { "sf18", 50 },
  251. { "sf19", 51 },
  252. { "sf20", 52 },
  253. { "sf21", 53 },
  254. { "sf22", 54 },
  255. { "sf23", 55 },
  256. { "sf24", 56 },
  257. { "sf25", 57 },
  258. { "sf26", 58 },
  259. { "sf27", 59 },
  260. { "sf28", 60 },
  261. { "sf29", 61 },
  262. { "sf30", 62 },
  263. { "sf31", 63 },
  264. /* Numbers for floating point registers are for assembler internal
  265. use only: they are scaled back to [0-3] for binary output. */
  266. #define FP0 64
  267. { "fp0", 64 },
  268. { "fp1", 65 },
  269. { "fp2", 66 },
  270. { "fp3", 67 },
  271. { NULL, 0 }, /* END OF LIST */
  272. };
  273. #define IS_RG_REG(n) ((0 <= (n)) && ((n) < SF0))
  274. #define IS_SF_REG(n) ((SF0 <= (n)) && ((n) < FP0))
  275. #define IS_FP_REG(n) ((n) >= FP0)
  276. /* Number and assembler mnemonic for all registers that can appear as
  277. 'abase' (indirect addressing) registers. */
  278. static const struct
  279. {
  280. char *areg_name;
  281. int areg_num;
  282. }
  283. aregs[] =
  284. {
  285. { "(pfp)", 0 },
  286. { "(sp)", 1 },
  287. { "(rip)", 2 },
  288. { "(r3)", 3 },
  289. { "(r4)", 4 },
  290. { "(r5)", 5 },
  291. { "(r6)", 6 },
  292. { "(r7)", 7 },
  293. { "(r8)", 8 },
  294. { "(r9)", 9 },
  295. { "(r10)", 10 },
  296. { "(r11)", 11 },
  297. { "(r12)", 12 },
  298. { "(r13)", 13 },
  299. { "(r14)", 14 },
  300. { "(r15)", 15 },
  301. { "(g0)", 16 },
  302. { "(g1)", 17 },
  303. { "(g2)", 18 },
  304. { "(g3)", 19 },
  305. { "(g4)", 20 },
  306. { "(g5)", 21 },
  307. { "(g6)", 22 },
  308. { "(g7)", 23 },
  309. { "(g8)", 24 },
  310. { "(g9)", 25 },
  311. { "(g10)", 26 },
  312. { "(g11)", 27 },
  313. { "(g12)", 28 },
  314. { "(g13)", 29 },
  315. { "(g14)", 30 },
  316. { "(fp)", 31 },
  317. #define IPREL 32
  318. /* For assembler internal use only: this number never appears in binary
  319. output. */
  320. { "(ip)", IPREL },
  321. { NULL, 0 }, /* END OF LIST */
  322. };
  323. /* Hash tables. */
  324. static struct hash_control *op_hash; /* Opcode mnemonics. */
  325. static struct hash_control *reg_hash; /* Register name hash table. */
  326. static struct hash_control *areg_hash; /* Abase register hash table. */
  327. /* Architecture for which we are assembling. */
  328. #define ARCH_ANY 0 /* Default: no architecture checking done. */
  329. #define ARCH_KA 1
  330. #define ARCH_KB 2
  331. #define ARCH_MC 3
  332. #define ARCH_CA 4
  333. #define ARCH_JX 5
  334. #define ARCH_HX 6
  335. int architecture = ARCH_ANY; /* Architecture requested on invocation line. */
  336. int iclasses_seen; /* OR of instruction classes (I_* constants)
  337. for which we've actually assembled
  338. instructions. */
  339. /* BRANCH-PREDICTION INSTRUMENTATION
  340. The following supports generation of branch-prediction instrumentation
  341. (turned on by -b switch). The instrumentation collects counts
  342. of branches taken/not-taken for later input to a utility that will
  343. set the branch prediction bits of the instructions in accordance with
  344. the behavior observed. (Note that the KX series does not have
  345. brach-prediction.)
  346. The instrumentation consists of:
  347. (1) before and after each conditional branch, a call to an external
  348. routine that increments and steps over an inline counter. The
  349. counter itself, initialized to 0, immediately follows the call
  350. instruction. For each branch, the counter following the branch
  351. is the number of times the branch was not taken, and the difference
  352. between the counters is the number of times it was taken. An
  353. example of an instrumented conditional branch:
  354. call BR_CNT_FUNC
  355. .word 0
  356. LBRANCH23: be label
  357. call BR_CNT_FUNC
  358. .word 0
  359. (2) a table of pointers to the instrumented branches, so that an
  360. external postprocessing routine can locate all of the counters.
  361. the table begins with a 2-word header: a pointer to the next in
  362. a linked list of such tables (initialized to 0); and a count
  363. of the number of entries in the table (exclusive of the header.
  364. Note that input source code is expected to already contain calls
  365. an external routine that will link the branch local table into a
  366. list of such tables. */
  367. /* Number of branches instrumented so far. Also used to generate
  368. unique local labels for each instrumented branch. */
  369. static int br_cnt;
  370. #define BR_LABEL_BASE "LBRANCH"
  371. /* Basename of local labels on instrumented branches, to avoid
  372. conflict with compiler- generated local labels. */
  373. #define BR_CNT_FUNC "__inc_branch"
  374. /* Name of the external routine that will increment (and step over) an
  375. inline counter. */
  376. #define BR_TAB_NAME "__BRANCH_TABLE__"
  377. /* Name of the table of pointers to branches. A local (i.e.,
  378. non-external) symbol. */
  379. static void ctrl_fmt (char *, long, int);
  380. void
  381. md_begin (void)
  382. {
  383. int i; /* Loop counter. */
  384. const struct i960_opcode *oP; /* Pointer into opcode table. */
  385. const char *retval; /* Value returned by hash functions. */
  386. op_hash = hash_new ();
  387. reg_hash = hash_new ();
  388. areg_hash = hash_new ();
  389. /* For some reason, the base assembler uses an empty string for "no
  390. error message", instead of a NULL pointer. */
  391. retval = 0;
  392. for (oP = i960_opcodes; oP->name && !retval; oP++)
  393. retval = hash_insert (op_hash, oP->name, (void *) oP);
  394. for (i = 0; regnames[i].reg_name && !retval; i++)
  395. retval = hash_insert (reg_hash, regnames[i].reg_name,
  396. (char *) &regnames[i].reg_num);
  397. for (i = 0; aregs[i].areg_name && !retval; i++)
  398. retval = hash_insert (areg_hash, aregs[i].areg_name,
  399. (char *) &aregs[i].areg_num);
  400. if (retval)
  401. as_fatal (_("Hashing returned \"%s\"."), retval);
  402. }
  403. /* parse_expr: parse an expression
  404. Use base assembler's expression parser to parse an expression.
  405. It, unfortunately, runs off a global which we have to save/restore
  406. in order to make it work for us.
  407. An empty expression string is treated as an absolute 0.
  408. Sets O_illegal regardless of expression evaluation if entire input
  409. string is not consumed in the evaluation -- tolerate no dangling junk! */
  410. static void
  411. parse_expr (char *textP, /* Text of expression to be parsed. */
  412. expressionS *expP) /* Where to put the results of parsing. */
  413. {
  414. char *save_in; /* Save global here. */
  415. symbolS *symP;
  416. know (textP);
  417. if (*textP == '\0')
  418. {
  419. /* Treat empty string as absolute 0. */
  420. expP->X_add_symbol = expP->X_op_symbol = NULL;
  421. expP->X_add_number = 0;
  422. expP->X_op = O_constant;
  423. }
  424. else
  425. {
  426. save_in = input_line_pointer; /* Save global. */
  427. input_line_pointer = textP; /* Make parser work for us. */
  428. (void) expression (expP);
  429. if ((size_t) (input_line_pointer - textP) != strlen (textP))
  430. /* Did not consume all of the input. */
  431. expP->X_op = O_illegal;
  432. symP = expP->X_add_symbol;
  433. if (symP && (hash_find (reg_hash, S_GET_NAME (symP))))
  434. /* Register name in an expression. */
  435. /* FIXME: this isn't much of a check any more. */
  436. expP->X_op = O_illegal;
  437. input_line_pointer = save_in; /* Restore global. */
  438. }
  439. }
  440. /* emit: output instruction binary
  441. Output instruction binary, in target byte order, 4 bytes at a time.
  442. Return pointer to where it was placed. */
  443. static char *
  444. emit (long instr) /* Word to be output, host byte order. */
  445. {
  446. char *toP; /* Where to output it. */
  447. toP = frag_more (4); /* Allocate storage. */
  448. md_number_to_chars (toP, instr, 4); /* Convert to target byte order. */
  449. return toP;
  450. }
  451. /* get_cdisp: handle displacement for a COBR or CTRL instruction.
  452. Parse displacement for a COBR or CTRL instruction.
  453. If successful, output the instruction opcode and set up for it,
  454. depending on the arg 'var_frag', either:
  455. o an address fixup to be done when all symbol values are known, or
  456. o a varying length code fragment, with address fixup info. This
  457. will be done for cobr instructions that may have to be relaxed
  458. in to compare/branch instructions (8 bytes) if the final
  459. address displacement is greater than 13 bits. */
  460. static void
  461. get_cdisp (char *dispP, /* Displacement as specified in source instruction. */
  462. char *ifmtP, /* "COBR" or "CTRL" (for use in error message). */
  463. long instr, /* Instruction needing the displacement. */
  464. int numbits, /* # bits of displacement (13 for COBR, 24 for CTRL). */
  465. int var_frag,/* 1 if varying length code fragment should be emitted;
  466. 0 if an address fix should be emitted. */
  467. int callj) /* 1 if callj relocation should be done; else 0. */
  468. {
  469. expressionS e; /* Parsed expression. */
  470. fixS *fixP; /* Structure describing needed address fix. */
  471. char *outP; /* Where instruction binary is output to. */
  472. fixP = NULL;
  473. parse_expr (dispP, &e);
  474. switch (e.X_op)
  475. {
  476. case O_illegal:
  477. as_bad (_("expression syntax error"));
  478. case O_symbol:
  479. if (S_GET_SEGMENT (e.X_add_symbol) == now_seg
  480. || S_GET_SEGMENT (e.X_add_symbol) == undefined_section)
  481. {
  482. if (var_frag)
  483. {
  484. outP = frag_more (8); /* Allocate worst-case storage. */
  485. md_number_to_chars (outP, instr, 4);
  486. frag_variant (rs_machine_dependent, 4, 4, 1,
  487. adds (e), offs (e), outP);
  488. }
  489. else
  490. {
  491. /* Set up a new fix structure, so address can be updated
  492. when all symbol values are known. */
  493. outP = emit (instr);
  494. fixP = fix_new (frag_now,
  495. outP - frag_now->fr_literal,
  496. 4,
  497. adds (e),
  498. offs (e),
  499. 1,
  500. NO_RELOC);
  501. fixP->fx_tcbit = callj;
  502. /* We want to modify a bit field when the address is
  503. known. But we don't need all the garbage in the
  504. bit_fix structure. So we're going to lie and store
  505. the number of bits affected instead of a pointer. */
  506. fixP->fx_bit_fixP = (bit_fixS *) (size_t) numbits;
  507. }
  508. }
  509. else
  510. as_bad (_("attempt to branch into different segment"));
  511. break;
  512. default:
  513. as_bad (_("target of %s instruction must be a label"), ifmtP);
  514. break;
  515. }
  516. }
  517. static int
  518. md_chars_to_number (char * val, /* Value in target byte order. */
  519. int n) /* Number of bytes in the input. */
  520. {
  521. int retval;
  522. for (retval = 0; n--;)
  523. {
  524. retval <<= 8;
  525. retval |= (unsigned char) val[n];
  526. }
  527. return retval;
  528. }
  529. /* mema_to_memb: convert a MEMA-format opcode to a MEMB-format opcode.
  530. There are 2 possible MEMA formats:
  531. - displacement only
  532. - displacement + abase
  533. They are distinguished by the setting of the MEMA_ABASE bit. */
  534. static void
  535. mema_to_memb (char * opcodeP) /* Where to find the opcode, in target byte order. */
  536. {
  537. long opcode; /* Opcode in host byte order. */
  538. long mode; /* Mode bits for MEMB instruction. */
  539. opcode = md_chars_to_number (opcodeP, 4);
  540. know (!(opcode & MEMB_BIT));
  541. mode = MEMB_BIT | D_BIT;
  542. if (opcode & MEMA_ABASE)
  543. mode |= A_BIT;
  544. opcode &= 0xffffc000; /* Clear MEMA offset and mode bits. */
  545. opcode |= mode; /* Set MEMB mode bits. */
  546. md_number_to_chars (opcodeP, opcode, 4);
  547. }
  548. /* targ_has_sfr:
  549. Return TRUE iff the target architecture supports the specified
  550. special-function register (sfr). */
  551. static int
  552. targ_has_sfr (int n) /* Number (0-31) of sfr. */
  553. {
  554. switch (architecture)
  555. {
  556. case ARCH_KA:
  557. case ARCH_KB:
  558. case ARCH_MC:
  559. case ARCH_JX:
  560. return 0;
  561. case ARCH_HX:
  562. return ((0 <= n) && (n <= 4));
  563. case ARCH_CA:
  564. default:
  565. return ((0 <= n) && (n <= 2));
  566. }
  567. }
  568. /* Look up a (suspected) register name in the register table and return the
  569. associated register number (or -1 if not found). */
  570. static int
  571. get_regnum (char *regname) /* Suspected register name. */
  572. {
  573. int *rP;
  574. rP = (int *) hash_find (reg_hash, regname);
  575. return (rP == NULL) ? -1 : *rP;
  576. }
  577. /* syntax: Issue a syntax error. */
  578. static void
  579. syntax (void)
  580. {
  581. as_bad (_("syntax error"));
  582. }
  583. /* parse_regop: parse a register operand.
  584. In case of illegal operand, issue a message and return some valid
  585. information so instruction processing can continue. */
  586. static void
  587. parse_regop (struct regop *regopP, /* Where to put description of register operand. */
  588. char *optext, /* Text of operand. */
  589. char opdesc) /* Descriptor byte: what's legal for this operand. */
  590. {
  591. int n; /* Register number. */
  592. expressionS e; /* Parsed expression. */
  593. /* See if operand is a register. */
  594. n = get_regnum (optext);
  595. if (n >= 0)
  596. {
  597. if (IS_RG_REG (n))
  598. {
  599. /* Global or local register. */
  600. if (!REG_ALIGN (opdesc, n))
  601. as_bad (_("unaligned register"));
  602. regopP->n = n;
  603. regopP->mode = 0;
  604. regopP->special = 0;
  605. return;
  606. }
  607. else if (IS_FP_REG (n) && FP_OK (opdesc))
  608. {
  609. /* Floating point register, and it's allowed. */
  610. regopP->n = n - FP0;
  611. regopP->mode = 1;
  612. regopP->special = 0;
  613. return;
  614. }
  615. else if (IS_SF_REG (n) && SFR_OK (opdesc))
  616. {
  617. /* Special-function register, and it's allowed. */
  618. regopP->n = n - SF0;
  619. regopP->mode = 0;
  620. regopP->special = 1;
  621. if (!targ_has_sfr (regopP->n))
  622. as_bad (_("no such sfr in this architecture"));
  623. return;
  624. }
  625. }
  626. else if (LIT_OK (opdesc))
  627. {
  628. /* How about a literal? */
  629. regopP->mode = 1;
  630. regopP->special = 0;
  631. if (FP_OK (opdesc))
  632. {
  633. /* Floating point literal acceptable. */
  634. /* Skip over 0f, 0d, or 0e prefix. */
  635. if ((optext[0] == '0')
  636. && (optext[1] >= 'd')
  637. && (optext[1] <= 'f'))
  638. optext += 2;
  639. if (!strcmp (optext, "0.0") || !strcmp (optext, "0"))
  640. {
  641. regopP->n = 0x10;
  642. return;
  643. }
  644. if (!strcmp (optext, "1.0") || !strcmp (optext, "1"))
  645. {
  646. regopP->n = 0x16;
  647. return;
  648. }
  649. }
  650. else
  651. {
  652. /* Fixed point literal acceptable. */
  653. parse_expr (optext, &e);
  654. if (e.X_op != O_constant
  655. || (offs (e) < 0) || (offs (e) > 31))
  656. {
  657. as_bad (_("illegal literal"));
  658. offs (e) = 0;
  659. }
  660. regopP->n = offs (e);
  661. return;
  662. }
  663. }
  664. /* Nothing worked. */
  665. syntax ();
  666. regopP->mode = 0; /* Register r0 is always a good one. */
  667. regopP->n = 0;
  668. regopP->special = 0;
  669. }
  670. /* get_ispec: parse a memory operand for an index specification
  671. Here, an "index specification" is taken to be anything surrounded
  672. by square brackets and NOT followed by anything else.
  673. If it's found, detach it from the input string, remove the surrounding
  674. square brackets, and return a pointer to it. Otherwise, return NULL. */
  675. static char *
  676. get_ispec (char *textP) /* Pointer to memory operand from source instruction, no white space. */
  677. {
  678. /* Points to start of index specification. */
  679. char *start;
  680. /* Points to end of index specification. */
  681. char *end;
  682. /* Find opening square bracket, if any. */
  683. start = strchr (textP, '[');
  684. if (start != NULL)
  685. {
  686. /* Eliminate '[', detach from rest of operand. */
  687. *start++ = '\0';
  688. end = strchr (start, ']');
  689. if (end == NULL)
  690. as_bad (_("unmatched '['"));
  691. else
  692. {
  693. /* Eliminate ']' and make sure it was the last thing
  694. in the string. */
  695. *end = '\0';
  696. if (*(end + 1) != '\0')
  697. as_bad (_("garbage after index spec ignored"));
  698. }
  699. }
  700. return start;
  701. }
  702. /* parse_memop: parse a memory operand
  703. This routine is based on the observation that the 4 mode bits of the
  704. MEMB format, taken individually, have fairly consistent meaning:
  705. M3 (bit 13): 1 if displacement is present (D_BIT)
  706. M2 (bit 12): 1 for MEMB instructions (MEMB_BIT)
  707. M1 (bit 11): 1 if index is present (I_BIT)
  708. M0 (bit 10): 1 if abase is present (A_BIT)
  709. So we parse the memory operand and set bits in the mode as we find
  710. things. Then at the end, if we go to MEMB format, we need only set
  711. the MEMB bit (M2) and our mode is built for us.
  712. Unfortunately, I said "fairly consistent". The exceptions:
  713. DBIA
  714. 0100 Would seem illegal, but means "abase-only".
  715. 0101 Would seem to mean "abase-only" -- it means IP-relative.
  716. Must be converted to 0100.
  717. 0110 Would seem to mean "index-only", but is reserved.
  718. We turn on the D bit and provide a 0 displacement.
  719. The other thing to observe is that we parse from the right, peeling
  720. things * off as we go: first any index spec, then any abase, then
  721. the displacement. */
  722. static void
  723. parse_memop (memS *memP, /* Where to put the results. */
  724. char *argP, /* Text of the operand to be parsed. */
  725. int optype) /* MEM1, MEM2, MEM4, MEM8, MEM12, or MEM16. */
  726. {
  727. char *indexP; /* Pointer to index specification with "[]" removed. */
  728. char *p; /* Temp char pointer. */
  729. char iprel_flag; /* True if this is an IP-relative operand. */
  730. int regnum; /* Register number. */
  731. /* Scale factor: 1,2,4,8, or 16. Later converted to internal format
  732. (0,1,2,3,4 respectively). */
  733. int scale;
  734. int mode; /* MEMB mode bits. */
  735. int *intP; /* Pointer to register number. */
  736. /* The following table contains the default scale factors for each
  737. type of memory instruction. It is accessed using (optype-MEM1)
  738. as an index -- thus it assumes the 'optype' constants are
  739. assigned consecutive values, in the order they appear in this
  740. table. */
  741. static const int def_scale[] =
  742. {
  743. 1, /* MEM1 */
  744. 2, /* MEM2 */
  745. 4, /* MEM4 */
  746. 8, /* MEM8 */
  747. -1, /* MEM12 -- no valid default */
  748. 16 /* MEM16 */
  749. };
  750. iprel_flag = mode = 0;
  751. /* Any index present? */
  752. indexP = get_ispec (argP);
  753. if (indexP)
  754. {
  755. p = strchr (indexP, '*');
  756. if (p == NULL)
  757. {
  758. /* No explicit scale -- use default for this instruction
  759. type and assembler mode. */
  760. if (flag_mri)
  761. scale = 1;
  762. else
  763. /* GNU960 compatibility */
  764. scale = def_scale[optype - MEM1];
  765. }
  766. else
  767. {
  768. *p++ = '\0'; /* Eliminate '*' */
  769. /* Now indexP->a '\0'-terminated register name,
  770. and p->a scale factor. */
  771. if (!strcmp (p, "16"))
  772. scale = 16;
  773. else if (strchr ("1248", *p) && (p[1] == '\0'))
  774. scale = *p - '0';
  775. else
  776. scale = -1;
  777. }
  778. regnum = get_regnum (indexP); /* Get index reg. # */
  779. if (!IS_RG_REG (regnum))
  780. {
  781. as_bad (_("invalid index register"));
  782. return;
  783. }
  784. /* Convert scale to its binary encoding. */
  785. switch (scale)
  786. {
  787. case 1:
  788. scale = 0 << 7;
  789. break;
  790. case 2:
  791. scale = 1 << 7;
  792. break;
  793. case 4:
  794. scale = 2 << 7;
  795. break;
  796. case 8:
  797. scale = 3 << 7;
  798. break;
  799. case 16:
  800. scale = 4 << 7;
  801. break;
  802. default:
  803. as_bad (_("invalid scale factor"));
  804. return;
  805. };
  806. memP->opcode |= scale | regnum; /* Set index bits in opcode. */
  807. mode |= I_BIT; /* Found a valid index spec. */
  808. }
  809. /* Any abase (Register Indirect) specification present? */
  810. if ((p = strrchr (argP, '(')) != NULL)
  811. {
  812. /* "(" is there -- does it start a legal abase spec? If not, it
  813. could be part of a displacement expression. */
  814. intP = (int *) hash_find (areg_hash, p);
  815. if (intP != NULL)
  816. {
  817. /* Got an abase here. */
  818. regnum = *intP;
  819. *p = '\0'; /* Discard register spec. */
  820. if (regnum == IPREL)
  821. /* We have to specialcase ip-rel mode. */
  822. iprel_flag = 1;
  823. else
  824. {
  825. memP->opcode |= regnum << 14;
  826. mode |= A_BIT;
  827. }
  828. }
  829. }
  830. /* Any expression present? */
  831. memP->e = argP;
  832. if (*argP != '\0')
  833. mode |= D_BIT;
  834. /* Special-case ip-relative addressing. */
  835. if (iprel_flag)
  836. {
  837. if (mode & I_BIT)
  838. syntax ();
  839. else
  840. {
  841. memP->opcode |= 5 << 10; /* IP-relative mode. */
  842. memP->disp = 32;
  843. }
  844. return;
  845. }
  846. /* Handle all other modes. */
  847. switch (mode)
  848. {
  849. case D_BIT | A_BIT:
  850. /* Go with MEMA instruction format for now (grow to MEMB later
  851. if 12 bits is not enough for the displacement). MEMA format
  852. has a single mode bit: set it to indicate that abase is
  853. present. */
  854. memP->opcode |= MEMA_ABASE;
  855. memP->disp = 12;
  856. break;
  857. case D_BIT:
  858. /* Go with MEMA instruction format for now (grow to MEMB later
  859. if 12 bits is not enough for the displacement). */
  860. memP->disp = 12;
  861. break;
  862. case A_BIT:
  863. /* For some reason, the bit string for this mode is not
  864. consistent: it should be 0 (exclusive of the MEMB bit), so we
  865. set it "by hand" here. */
  866. memP->opcode |= MEMB_BIT;
  867. break;
  868. case A_BIT | I_BIT:
  869. /* set MEMB bit in mode, and OR in mode bits. */
  870. memP->opcode |= mode | MEMB_BIT;
  871. break;
  872. case I_BIT:
  873. /* Treat missing displacement as displacement of 0. */
  874. mode |= D_BIT;
  875. /* Fall into next case. */
  876. case D_BIT | A_BIT | I_BIT:
  877. case D_BIT | I_BIT:
  878. /* Set MEMB bit in mode, and OR in mode bits. */
  879. memP->opcode |= mode | MEMB_BIT;
  880. memP->disp = 32;
  881. break;
  882. default:
  883. syntax ();
  884. break;
  885. }
  886. }
  887. /* Generate a MEMA- or MEMB-format instruction. */
  888. static void
  889. mem_fmt (char *args[], /* args[0]->opcode mnemonic, args[1-3]->operands. */
  890. struct i960_opcode *oP,/* Pointer to description of instruction. */
  891. int callx) /* Is this a callx opcode. */
  892. {
  893. int i; /* Loop counter. */
  894. struct regop regop; /* Description of register operand. */
  895. char opdesc; /* Operand descriptor byte. */
  896. memS instr; /* Description of binary to be output. */
  897. char *outP; /* Where the binary was output to. */
  898. expressionS exp; /* Parsed expression. */
  899. /* ->description of deferred address fixup. */
  900. fixS *fixP;
  901. #ifdef OBJ_COFF
  902. /* COFF support isn't in place yet for callx relaxing. */
  903. callx = 0;
  904. #endif
  905. memset (&instr, '\0', sizeof (memS));
  906. instr.opcode = oP->opcode;
  907. /* Process operands. */
  908. for (i = 1; i <= oP->num_ops; i++)
  909. {
  910. opdesc = oP->operand[i - 1];
  911. if (MEMOP (opdesc))
  912. parse_memop (&instr, args[i], oP->format);
  913. else
  914. {
  915. parse_regop (&regop, args[i], opdesc);
  916. instr.opcode |= regop.n << 19;
  917. }
  918. }
  919. /* Parse the displacement; this must be done before emitting the
  920. opcode, in case it is an expression using `.'. */
  921. parse_expr (instr.e, &exp);
  922. /* Output opcode. */
  923. outP = emit (instr.opcode);
  924. if (instr.disp == 0)
  925. return;
  926. /* Process the displacement. */
  927. switch (exp.X_op)
  928. {
  929. case O_illegal:
  930. as_bad (_("expression syntax error"));
  931. break;
  932. case O_constant:
  933. if (instr.disp == 32)
  934. (void) emit (offs (exp)); /* Output displacement. */
  935. else
  936. {
  937. /* 12-bit displacement. */
  938. if (offs (exp) & ~0xfff)
  939. {
  940. /* Won't fit in 12 bits: convert already-output
  941. instruction to MEMB format, output
  942. displacement. */
  943. mema_to_memb (outP);
  944. (void) emit (offs (exp));
  945. }
  946. else
  947. {
  948. /* WILL fit in 12 bits: OR into opcode and
  949. overwrite the binary we already put out. */
  950. instr.opcode |= offs (exp);
  951. md_number_to_chars (outP, instr.opcode, 4);
  952. }
  953. }
  954. break;
  955. default:
  956. if (instr.disp == 12)
  957. /* Displacement is dependent on a symbol, whose value
  958. may change at link time. We HAVE to reserve 32 bits.
  959. Convert already-output opcode to MEMB format. */
  960. mema_to_memb (outP);
  961. /* Output 0 displacement and set up address fixup for when
  962. this symbol's value becomes known. */
  963. outP = emit ((long) 0);
  964. fixP = fix_new_exp (frag_now,
  965. outP - frag_now->fr_literal,
  966. 4, &exp, 0, NO_RELOC);
  967. /* Steve's linker relaxing hack. Mark this 32-bit relocation as
  968. being in the instruction stream, specifically as part of a callx
  969. instruction. */
  970. fixP->fx_bsr = callx;
  971. break;
  972. }
  973. }
  974. /* targ_has_iclass:
  975. Return TRUE iff the target architecture supports the indicated
  976. class of instructions. */
  977. static int
  978. targ_has_iclass (int ic) /* Instruction class; one of:
  979. I_BASE, I_CX, I_DEC, I_KX, I_FP, I_MIL, I_CASIM, I_CX2, I_HX, I_HX2. */
  980. {
  981. iclasses_seen |= ic;
  982. switch (architecture)
  983. {
  984. case ARCH_KA:
  985. return ic & (I_BASE | I_KX);
  986. case ARCH_KB:
  987. return ic & (I_BASE | I_KX | I_FP | I_DEC);
  988. case ARCH_MC:
  989. return ic & (I_BASE | I_KX | I_FP | I_DEC | I_MIL);
  990. case ARCH_CA:
  991. return ic & (I_BASE | I_CX | I_CX2 | I_CASIM);
  992. case ARCH_JX:
  993. return ic & (I_BASE | I_CX2 | I_JX);
  994. case ARCH_HX:
  995. return ic & (I_BASE | I_CX2 | I_JX | I_HX);
  996. default:
  997. if ((iclasses_seen & (I_KX | I_FP | I_DEC | I_MIL))
  998. && (iclasses_seen & (I_CX | I_CX2)))
  999. {
  1000. as_warn (_("architecture of opcode conflicts with that of earlier instruction(s)"));
  1001. iclasses_seen &= ~ic;
  1002. }
  1003. return 1;
  1004. }
  1005. }
  1006. /* shift_ok:
  1007. Determine if a "shlo" instruction can be used to implement a "ldconst".
  1008. This means that some number X < 32 can be shifted left to produce the
  1009. constant of interest.
  1010. Return the shift count, or 0 if we can't do it.
  1011. Caller calculates X by shifting original constant right 'shift' places. */
  1012. static int
  1013. shift_ok (int n) /* The constant of interest. */
  1014. {
  1015. int shift; /* The shift count. */
  1016. if (n <= 0)
  1017. /* Can't do it for negative numbers. */
  1018. return 0;
  1019. /* Shift 'n' right until a 1 is about to be lost. */
  1020. for (shift = 0; (n & 1) == 0; shift++)
  1021. n >>= 1;
  1022. if (n >= 32)
  1023. return 0;
  1024. return shift;
  1025. }
  1026. /* parse_ldcont:
  1027. Parse and replace a 'ldconst' pseudo-instruction with an appropriate
  1028. i80960 instruction.
  1029. Assumes the input consists of:
  1030. arg[0] opcode mnemonic ('ldconst')
  1031. arg[1] first operand (constant)
  1032. arg[2] name of register to be loaded
  1033. Replaces opcode and/or operands as appropriate.
  1034. Returns the new number of arguments, or -1 on failure. */
  1035. static int
  1036. parse_ldconst (char *arg[]) /* See above. */
  1037. {
  1038. int n; /* Constant to be loaded. */
  1039. int shift; /* Shift count for "shlo" instruction. */
  1040. static char buf[5]; /* Literal for first operand. */
  1041. static char buf2[5]; /* Literal for second operand. */
  1042. expressionS e; /* Parsed expression. */
  1043. arg[3] = NULL; /* So we can tell at the end if it got used or not. */
  1044. parse_expr (arg[1], &e);
  1045. switch (e.X_op)
  1046. {
  1047. default:
  1048. /* We're dependent on one or more symbols -- use "lda". */
  1049. arg[0] = "lda";
  1050. break;
  1051. case O_constant:
  1052. /* Try the following mappings:
  1053. ldconst 0,<reg> -> mov 0,<reg>
  1054. ldconst 31,<reg> -> mov 31,<reg>
  1055. ldconst 32,<reg> -> addo 1,31,<reg>
  1056. ldconst 62,<reg> -> addo 31,31,<reg>
  1057. ldconst 64,<reg> -> shlo 8,3,<reg>
  1058. ldconst -1,<reg> -> subo 1,0,<reg>
  1059. ldconst -31,<reg> -> subo 31,0,<reg>
  1060. Anything else becomes:
  1061. lda xxx,<reg>. */
  1062. n = offs (e);
  1063. if ((0 <= n) && (n <= 31))
  1064. arg[0] = "mov";
  1065. else if ((-31 <= n) && (n <= -1))
  1066. {
  1067. arg[0] = "subo";
  1068. arg[3] = arg[2];
  1069. sprintf (buf, "%d", -n);
  1070. arg[1] = buf;
  1071. arg[2] = "0";
  1072. }
  1073. else if ((32 <= n) && (n <= 62))
  1074. {
  1075. arg[0] = "addo";
  1076. arg[3] = arg[2];
  1077. arg[1] = "31";
  1078. sprintf (buf, "%d", n - 31);
  1079. arg[2] = buf;
  1080. }
  1081. else if ((shift = shift_ok (n)) != 0)
  1082. {
  1083. arg[0] = "shlo";
  1084. arg[3] = arg[2];
  1085. sprintf (buf, "%d", shift);
  1086. arg[1] = buf;
  1087. sprintf (buf2, "%d", n >> shift);
  1088. arg[2] = buf2;
  1089. }
  1090. else
  1091. arg[0] = "lda";
  1092. break;
  1093. case O_illegal:
  1094. as_bad (_("invalid constant"));
  1095. return -1;
  1096. break;
  1097. }
  1098. return (arg[3] == 0) ? 2 : 3;
  1099. }
  1100. /* reg_fmt: generate a REG-format instruction. */
  1101. static void
  1102. reg_fmt (char *args[], /* args[0]->opcode mnemonic, args[1-3]->operands. */
  1103. struct i960_opcode *oP)/* Pointer to description of instruction. */
  1104. {
  1105. long instr; /* Binary to be output. */
  1106. struct regop regop; /* Description of register operand. */
  1107. int n_ops; /* Number of operands. */
  1108. instr = oP->opcode;
  1109. n_ops = oP->num_ops;
  1110. if (n_ops >= 1)
  1111. {
  1112. parse_regop (&regop, args[1], oP->operand[0]);
  1113. if ((n_ops == 1) && !(instr & M3))
  1114. {
  1115. /* 1-operand instruction in which the dst field should
  1116. be used (instead of src1). */
  1117. regop.n <<= 19;
  1118. if (regop.special)
  1119. regop.mode = regop.special;
  1120. regop.mode <<= 13;
  1121. regop.special = 0;
  1122. }
  1123. else
  1124. {
  1125. /* regop.n goes in bit 0, needs no shifting. */
  1126. regop.mode <<= 11;
  1127. regop.special <<= 5;
  1128. }
  1129. instr |= regop.n | regop.mode | regop.special;
  1130. }
  1131. if (n_ops >= 2)
  1132. {
  1133. parse_regop (&regop, args[2], oP->operand[1]);
  1134. if ((n_ops == 2) && !(instr & M3))
  1135. {
  1136. /* 2-operand instruction in which the dst field should
  1137. be used instead of src2). */
  1138. regop.n <<= 19;
  1139. if (regop.special)
  1140. regop.mode = regop.special;
  1141. regop.mode <<= 13;
  1142. regop.special = 0;
  1143. }
  1144. else
  1145. {
  1146. regop.n <<= 14;
  1147. regop.mode <<= 12;
  1148. regop.special <<= 6;
  1149. }
  1150. instr |= regop.n | regop.mode | regop.special;
  1151. }
  1152. if (n_ops == 3)
  1153. {
  1154. parse_regop (&regop, args[3], oP->operand[2]);
  1155. if (regop.special)
  1156. regop.mode = regop.special;
  1157. instr |= (regop.n <<= 19) | (regop.mode <<= 13);
  1158. }
  1159. emit (instr);
  1160. }
  1161. /* get_args: break individual arguments out of comma-separated list
  1162. Input assumptions:
  1163. - all comments and labels have been removed
  1164. - all strings of whitespace have been collapsed to a single blank.
  1165. - all character constants ('x') have been replaced with decimal
  1166. Output:
  1167. args[0] is untouched. args[1] points to first operand, etc. All args:
  1168. - are NULL-terminated
  1169. - contain no whitespace
  1170. Return value:
  1171. Number of operands (0,1,2, or 3) or -1 on error. */
  1172. static int
  1173. get_args (char *p, /* Pointer to comma-separated operands; Mucked by us. */
  1174. char *args[]) /* Output arg: pointers to operands placed in args[1-3].
  1175. Must accommodate 4 entries (args[0-3]). */
  1176. {
  1177. int n; /* Number of operands. */
  1178. char *to;
  1179. /* Skip lead white space. */
  1180. while (*p == ' ')
  1181. p++;
  1182. if (*p == '\0')
  1183. return 0;
  1184. n = 1;
  1185. args[1] = p;
  1186. /* Squeze blanks out by moving non-blanks toward start of string.
  1187. Isolate operands, whenever comma is found. */
  1188. to = p;
  1189. while (*p != '\0')
  1190. {
  1191. if (*p == ' '
  1192. && (! ISALNUM (p[1])
  1193. || ! ISALNUM (p[-1])))
  1194. p++;
  1195. else if (*p == ',')
  1196. {
  1197. /* Start of operand. */
  1198. if (n == 3)
  1199. {
  1200. as_bad (_("too many operands"));
  1201. return -1;
  1202. }
  1203. *to++ = '\0'; /* Terminate argument. */
  1204. args[++n] = to; /* Start next argument. */
  1205. p++;
  1206. }
  1207. else
  1208. *to++ = *p++;
  1209. }
  1210. *to = '\0';
  1211. return n;
  1212. }
  1213. /* i_scan: perform lexical scan of ascii assembler instruction.
  1214. Input assumptions:
  1215. - input string is an i80960 instruction (not a pseudo-op)
  1216. - all comments and labels have been removed
  1217. - all strings of whitespace have been collapsed to a single blank.
  1218. Output:
  1219. args[0] points to opcode, other entries point to operands. All strings:
  1220. - are NULL-terminated
  1221. - contain no whitespace
  1222. - have character constants ('x') replaced with a decimal number
  1223. Return value:
  1224. Number of operands (0,1,2, or 3) or -1 on error. */
  1225. static int
  1226. i_scan (char *iP, /* Pointer to ascii instruction; Mucked by us. */
  1227. char *args[]) /* Output arg: pointers to opcode and operands placed here.
  1228. Must accommodate 4 entries. */
  1229. {
  1230. /* Isolate opcode. */
  1231. if (*(iP) == ' ')
  1232. iP++;
  1233. args[0] = iP;
  1234. for (; *iP != ' '; iP++)
  1235. {
  1236. if (*iP == '\0')
  1237. {
  1238. /* There are no operands. */
  1239. if (args[0] == iP)
  1240. {
  1241. /* We never moved: there was no opcode either! */
  1242. as_bad (_("missing opcode"));
  1243. return -1;
  1244. }
  1245. return 0;
  1246. }
  1247. }
  1248. *iP++ = '\0';
  1249. return (get_args (iP, args));
  1250. }
  1251. static void
  1252. brcnt_emit (void)
  1253. {
  1254. /* Emit call to "increment" routine. */
  1255. ctrl_fmt (BR_CNT_FUNC, CALL, 1);
  1256. /* Emit inline counter to be incremented. */
  1257. emit (0);
  1258. }
  1259. static char *
  1260. brlab_next (void)
  1261. {
  1262. static char buf[20];
  1263. sprintf (buf, "%s%d", BR_LABEL_BASE, br_cnt++);
  1264. return buf;
  1265. }
  1266. static void
  1267. ctrl_fmt (char *targP, /* Pointer to text of lone operand (if any). */
  1268. long opcode, /* Template of instruction. */
  1269. int num_ops) /* Number of operands. */
  1270. {
  1271. int instrument; /* TRUE iff we should add instrumentation to track
  1272. how often the branch is taken. */
  1273. if (num_ops == 0)
  1274. emit (opcode); /* Output opcode. */
  1275. else
  1276. {
  1277. instrument = instrument_branches && (opcode != CALL)
  1278. && (opcode != B) && (opcode != RET) && (opcode != BAL);
  1279. if (instrument)
  1280. {
  1281. brcnt_emit ();
  1282. colon (brlab_next ());
  1283. }
  1284. /* The operand MUST be an ip-relative displacement. Parse it
  1285. and set up address fix for the instruction we just output. */
  1286. get_cdisp (targP, "CTRL", opcode, 24, 0, 0);
  1287. if (instrument)
  1288. brcnt_emit ();
  1289. }
  1290. }
  1291. static void
  1292. cobr_fmt (/* arg[0]->opcode mnemonic, arg[1-3]->operands (ascii) */
  1293. char *arg[],
  1294. /* Opcode, with branch-prediction bits already set if necessary. */
  1295. long opcode,
  1296. /* Pointer to description of instruction. */
  1297. struct i960_opcode *oP)
  1298. {
  1299. long instr; /* 32-bit instruction. */
  1300. struct regop regop; /* Description of register operand. */
  1301. int n; /* Number of operands. */
  1302. int var_frag; /* 1 if varying length code fragment should
  1303. be emitted; 0 if an address fix
  1304. should be emitted. */
  1305. instr = opcode;
  1306. n = oP->num_ops;
  1307. if (n >= 1)
  1308. {
  1309. /* First operand (if any) of a COBR is always a register
  1310. operand. Parse it. */
  1311. parse_regop (&regop, arg[1], oP->operand[0]);
  1312. instr |= (regop.n << 19) | (regop.mode << 13);
  1313. }
  1314. if (n >= 2)
  1315. {
  1316. /* Second operand (if any) of a COBR is always a register
  1317. operand. Parse it. */
  1318. parse_regop (&regop, arg[2], oP->operand[1]);
  1319. instr |= (regop.n << 14) | regop.special;
  1320. }
  1321. if (n < 3)
  1322. emit (instr);
  1323. else
  1324. {
  1325. if (instrument_branches)
  1326. {
  1327. brcnt_emit ();
  1328. colon (brlab_next ());
  1329. }
  1330. /* A third operand to a COBR is always a displacement. Parse
  1331. it; if it's relaxable (a cobr "j" directive, or any cobr
  1332. other than bbs/bbc when the "-norelax" option is not in use)
  1333. set up a variable code fragment; otherwise set up an address
  1334. fix. */
  1335. var_frag = !norelax || (oP->format == COJ); /* TRUE or FALSE */
  1336. get_cdisp (arg[3], "COBR", instr, 13, var_frag, 0);
  1337. if (instrument_branches)
  1338. brcnt_emit ();
  1339. }
  1340. }
  1341. /* Assumptions about the passed-in text:
  1342. - all comments, labels removed
  1343. - text is an instruction
  1344. - all white space compressed to single blanks
  1345. - all character constants have been replaced with decimal. */
  1346. void
  1347. md_assemble (char *textP)
  1348. {
  1349. /* Parsed instruction text, containing NO whitespace: arg[0]->opcode
  1350. mnemonic arg[1-3]->operands, with char constants replaced by
  1351. decimal numbers. */
  1352. char *args[4];
  1353. /* Number of instruction operands. */
  1354. int n_ops;
  1355. /* Pointer to instruction description. */
  1356. struct i960_opcode *oP;
  1357. /* TRUE iff opcode mnemonic included branch-prediction suffix (".f"
  1358. or ".t"). */
  1359. int branch_predict;
  1360. /* Setting of branch-prediction bit(s) to be OR'd into instruction
  1361. opcode of CTRL/COBR format instructions. */
  1362. long bp_bits;
  1363. /* Offset of last character in opcode mnemonic. */
  1364. int n;
  1365. const char *bp_error_msg = _("branch prediction invalid on this opcode");
  1366. /* Parse instruction into opcode and operands. */
  1367. memset (args, '\0', sizeof (args));
  1368. n_ops = i_scan (textP, args);
  1369. if (n_ops == -1)
  1370. return; /* Error message already issued. */
  1371. /* Do "macro substitution" (sort of) on 'ldconst' pseudo-instruction. */
  1372. if (!strcmp (args[0], "ldconst"))
  1373. {
  1374. n_ops = parse_ldconst (args);
  1375. if (n_ops == -1)
  1376. return;
  1377. }
  1378. /* Check for branch-prediction suffix on opcode mnemonic, strip it off. */
  1379. n = strlen (args[0]) - 1;
  1380. branch_predict = 0;
  1381. bp_bits = 0;
  1382. if (args[0][n - 1] == '.' && (args[0][n] == 't' || args[0][n] == 'f'))
  1383. {
  1384. /* We could check here to see if the target architecture
  1385. supports branch prediction, but why bother? The bit will
  1386. just be ignored by processors that don't use it. */
  1387. branch_predict = 1;
  1388. bp_bits = (args[0][n] == 't') ? BP_TAKEN : BP_NOT_TAKEN;
  1389. args[0][n - 1] = '\0'; /* Strip suffix from opcode mnemonic */
  1390. }
  1391. /* Look up opcode mnemonic in table and check number of operands.
  1392. Check that opcode is legal for the target architecture. If all
  1393. looks good, assemble instruction. */
  1394. oP = (struct i960_opcode *) hash_find (op_hash, args[0]);
  1395. if (!oP || !targ_has_iclass (oP->iclass))
  1396. as_bad (_("invalid opcode, \"%s\"."), args[0]);
  1397. else if (n_ops != oP->num_ops)
  1398. as_bad (_("improper number of operands. expecting %d, got %d"),
  1399. oP->num_ops, n_ops);
  1400. else
  1401. {
  1402. switch (oP->format)
  1403. {
  1404. case FBRA:
  1405. case CTRL:
  1406. ctrl_fmt (args[1], oP->opcode | bp_bits, oP->num_ops);
  1407. if (oP->format == FBRA)
  1408. /* Now generate a 'bno' to same arg */
  1409. ctrl_fmt (args[1], BNO | bp_bits, 1);
  1410. break;
  1411. case COBR:
  1412. case COJ:
  1413. cobr_fmt (args, oP->opcode | bp_bits, oP);
  1414. break;
  1415. case REG:
  1416. if (branch_predict)
  1417. as_warn ("%s", bp_error_msg);
  1418. reg_fmt (args, oP);
  1419. break;
  1420. case MEM1:
  1421. if (args[0][0] == 'c' && args[0][1] == 'a')
  1422. {
  1423. if (branch_predict)
  1424. as_warn ("%s", bp_error_msg);
  1425. mem_fmt (args, oP, 1);
  1426. break;
  1427. }
  1428. case MEM2:
  1429. case MEM4:
  1430. case MEM8:
  1431. case MEM12:
  1432. case MEM16:
  1433. if (branch_predict)
  1434. as_warn ("%s", bp_error_msg);
  1435. mem_fmt (args, oP, 0);
  1436. break;
  1437. case CALLJ:
  1438. if (branch_predict)
  1439. as_warn ("%s", bp_error_msg);
  1440. /* Output opcode & set up "fixup" (relocation); flag
  1441. relocation as 'callj' type. */
  1442. know (oP->num_ops == 1);
  1443. get_cdisp (args[1], "CTRL", oP->opcode, 24, 0, 1);
  1444. break;
  1445. default:
  1446. BAD_CASE (oP->format);
  1447. break;
  1448. }
  1449. }
  1450. }
  1451. void
  1452. md_number_to_chars (char *buf,
  1453. valueT value,
  1454. int n)
  1455. {
  1456. number_to_chars_littleendian (buf, value, n);
  1457. }
  1458. char *
  1459. md_atof (int type, char *litP, int *sizeP)
  1460. {
  1461. return ieee_md_atof (type, litP, sizeP, FALSE);
  1462. }
  1463. static void
  1464. md_number_to_imm (char *buf, long val, int n)
  1465. {
  1466. md_number_to_chars (buf, val, n);
  1467. }
  1468. static void
  1469. md_number_to_field (char *instrP, /* Pointer to instruction to be fixed. */
  1470. long val, /* Address fixup value. */
  1471. bit_fixS *bfixP) /* Description of bit field to be fixed up. */
  1472. {
  1473. int numbits; /* Length of bit field to be fixed. */
  1474. long instr; /* 32-bit instruction to be fixed-up. */
  1475. long sign; /* 0 or -1, according to sign bit of 'val'. */
  1476. /* Convert instruction back to host byte order. */
  1477. instr = md_chars_to_number (instrP, 4);
  1478. /* Surprise! -- we stored the number of bits to be modified rather
  1479. than a pointer to a structure. */
  1480. numbits = (int) (size_t) bfixP;
  1481. if (numbits == 1)
  1482. /* This is a no-op, stuck here by reloc_callj(). */
  1483. return;
  1484. know ((numbits == 13) || (numbits == 24));
  1485. /* Propagate sign bit of 'val' for the given number of bits. Result
  1486. should be all 0 or all 1. */
  1487. sign = val >> ((int) numbits - 1);
  1488. if (((val < 0) && (sign != -1))
  1489. || ((val > 0) && (sign != 0)))
  1490. as_bad (_("Fixup of %ld too large for field width of %d"),
  1491. val, numbits);
  1492. else
  1493. {
  1494. /* Put bit field into instruction and write back in target
  1495. * byte order. */
  1496. val &= ~(-1 << (int) numbits); /* Clear unused sign bits. */
  1497. instr |= val;
  1498. md_number_to_chars (instrP, instr, 4);
  1499. }
  1500. }
  1501. /* md_parse_option
  1502. Invocation line includes a switch not recognized by the base assembler.
  1503. See if it's a processor-specific option. For the 960, these are:
  1504. -norelax:
  1505. Conditional branch instructions that require displacements
  1506. greater than 13 bits (or that have external targets) should
  1507. generate errors. The default is to replace each such
  1508. instruction with the corresponding compare (or chkbit) and
  1509. branch instructions. Note that the Intel "j" cobr directives
  1510. are ALWAYS "de-optimized" in this way when necessary,
  1511. regardless of the setting of this option.
  1512. -b:
  1513. Add code to collect information about branches taken, for
  1514. later optimization of branch prediction bits by a separate
  1515. tool. COBR and CNTL format instructions have branch
  1516. prediction bits (in the CX architecture); if "BR" represents
  1517. an instruction in one of these classes, the following rep-
  1518. resents the code generated by the assembler:
  1519. call <increment routine>
  1520. .word 0 # pre-counter
  1521. Label: BR
  1522. call <increment routine>
  1523. .word 0 # post-counter
  1524. A table of all such "Labels" is also generated.
  1525. -AKA, -AKB, -AKC, -ASA, -ASB, -AMC, -ACA:
  1526. Select the 80960 architecture. Instructions or features not
  1527. supported by the selected architecture cause fatal errors.
  1528. The default is to generate code for any instruction or feature
  1529. that is supported by SOME version of the 960 (even if this
  1530. means mixing architectures!). */
  1531. const char *md_shortopts = "A:b";
  1532. struct option md_longopts[] =
  1533. {
  1534. #define OPTION_LINKRELAX (OPTION_MD_BASE)
  1535. {"linkrelax", no_argument, NULL, OPTION_LINKRELAX},
  1536. {"link-relax", no_argument, NULL, OPTION_LINKRELAX},
  1537. #define OPTION_NORELAX (OPTION_MD_BASE + 1)
  1538. {"norelax", no_argument, NULL, OPTION_NORELAX},
  1539. {"no-relax", no_argument, NULL, OPTION_NORELAX},
  1540. {NULL, no_argument, NULL, 0}
  1541. };
  1542. size_t md_longopts_size = sizeof (md_longopts);
  1543. struct tabentry
  1544. {
  1545. char *flag;
  1546. int arch;
  1547. };
  1548. static const struct tabentry arch_tab[] =
  1549. {
  1550. {"KA", ARCH_KA},
  1551. {"KB", ARCH_KB},
  1552. {"SA", ARCH_KA}, /* Synonym for KA. */
  1553. {"SB", ARCH_KB}, /* Synonym for KB. */
  1554. {"KC", ARCH_MC}, /* Synonym for MC. */
  1555. {"MC", ARCH_MC},
  1556. {"CA", ARCH_CA},
  1557. {"JX", ARCH_JX},
  1558. {"HX", ARCH_HX},
  1559. {NULL, 0}
  1560. };
  1561. int
  1562. md_parse_option (int c, char *arg)
  1563. {
  1564. switch (c)
  1565. {
  1566. case OPTION_LINKRELAX:
  1567. linkrelax = 1;
  1568. flag_keep_locals = 1;
  1569. break;
  1570. case OPTION_NORELAX:
  1571. norelax = 1;
  1572. break;
  1573. case 'b':
  1574. instrument_branches = 1;
  1575. break;
  1576. case 'A':
  1577. {
  1578. const struct tabentry *tp;
  1579. char *p = arg;
  1580. for (tp = arch_tab; tp->flag != NULL; tp++)
  1581. if (!strcmp (p, tp->flag))
  1582. break;
  1583. if (tp->flag == NULL)
  1584. {
  1585. as_bad (_("invalid architecture %s"), p);
  1586. return 0;
  1587. }
  1588. else
  1589. architecture = tp->arch;
  1590. }
  1591. break;
  1592. default:
  1593. return 0;
  1594. }
  1595. return 1;
  1596. }
  1597. void
  1598. md_show_usage (FILE *stream)
  1599. {
  1600. int i;
  1601. fprintf (stream, _("I960 options:\n"));
  1602. for (i = 0; arch_tab[i].flag; i++)
  1603. fprintf (stream, "%s-A%s", i ? " | " : "", arch_tab[i].flag);
  1604. fprintf (stream, _("\n\
  1605. specify variant of 960 architecture\n\
  1606. -b add code to collect statistics about branches taken\n\
  1607. -link-relax preserve individual alignment directives so linker\n\
  1608. can do relaxing (b.out format only)\n\
  1609. -no-relax don't alter compare-and-branch instructions for\n\
  1610. long displacements\n"));
  1611. }
  1612. /* relax_cobr:
  1613. Replace cobr instruction in a code fragment with equivalent branch and
  1614. compare instructions, so it can reach beyond a 13-bit displacement.
  1615. Set up an address fix/relocation for the new branch instruction. */
  1616. /* This "conditional jump" table maps cobr instructions into
  1617. equivalent compare and branch opcodes. */
  1618. static const
  1619. struct
  1620. {
  1621. long compare;
  1622. long branch;
  1623. }
  1624. coj[] =
  1625. { /* COBR OPCODE: */
  1626. { CHKBIT, BNO }, /* 0x30 - bbc */
  1627. { CMPO, BG }, /* 0x31 - cmpobg */
  1628. { CMPO, BE }, /* 0x32 - cmpobe */
  1629. { CMPO, BGE }, /* 0x33 - cmpobge */
  1630. { CMPO, BL }, /* 0x34 - cmpobl */
  1631. { CMPO, BNE }, /* 0x35 - cmpobne */
  1632. { CMPO, BLE }, /* 0x36 - cmpoble */
  1633. { CHKBIT, BO }, /* 0x37 - bbs */
  1634. { CMPI, BNO }, /* 0x38 - cmpibno */
  1635. { CMPI, BG }, /* 0x39 - cmpibg */
  1636. { CMPI, BE }, /* 0x3a - cmpibe */
  1637. { CMPI, BGE }, /* 0x3b - cmpibge */
  1638. { CMPI, BL }, /* 0x3c - cmpibl */
  1639. { CMPI, BNE }, /* 0x3d - cmpibne */
  1640. { CMPI, BLE }, /* 0x3e - cmpible */
  1641. { CMPI, BO }, /* 0x3f - cmpibo */
  1642. };
  1643. static void
  1644. relax_cobr (fragS *fragP) /* fragP->fr_opcode is assumed to point to
  1645. the cobr instruction, which comes at the
  1646. end of the code fragment. */
  1647. {
  1648. int opcode, src1, src2, m1, s2;
  1649. /* Bit fields from cobr instruction. */
  1650. long bp_bits; /* Branch prediction bits from cobr instruction. */
  1651. long instr; /* A single i960 instruction. */
  1652. /* ->instruction to be replaced. */
  1653. char *iP;
  1654. fixS *fixP; /* Relocation that can be done at assembly time. */
  1655. /* Pick up & parse cobr instruction. */
  1656. iP = fragP->fr_opcode;
  1657. instr = md_chars_to_number (iP, 4);
  1658. opcode = ((instr >> 24) & 0xff) - 0x30; /* "-0x30" for table index. */
  1659. src1 = (instr >> 19) & 0x1f;
  1660. m1 = (instr >> 13) & 1;
  1661. s2 = instr & 1;
  1662. src2 = (instr >> 14) & 0x1f;
  1663. bp_bits = instr & BP_MASK;
  1664. /* Generate and output compare instruction. */
  1665. instr = coj[opcode].compare
  1666. | src1 | (m1 << 11) | (s2 << 6) | (src2 << 14);
  1667. md_number_to_chars (iP, instr, 4);
  1668. /* Output branch instruction. */
  1669. md_number_to_chars (iP + 4, coj[opcode].branch | bp_bits, 4);
  1670. /* Set up address fixup/relocation. */
  1671. fixP = fix_new (fragP,
  1672. iP + 4 - fragP->fr_literal,
  1673. 4,
  1674. fragP->fr_symbol,
  1675. fragP->fr_offset,
  1676. 1,
  1677. NO_RELOC);
  1678. fixP->fx_bit_fixP = (bit_fixS *) 24; /* Store size of bit field. */
  1679. fragP->fr_fix += 4;
  1680. frag_wane (fragP);
  1681. }
  1682. /* md_convert_frag:
  1683. Called by base assembler after address relaxation is finished: modify
  1684. variable fragments according to how much relaxation was done.
  1685. If the fragment substate is still 1, a 13-bit displacement was enough
  1686. to reach the symbol in question. Set up an address fixup, but otherwise
  1687. leave the cobr instruction alone.
  1688. If the fragment substate is 2, a 13-bit displacement was not enough.
  1689. Replace the cobr with a two instructions (a compare and a branch). */
  1690. void
  1691. md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
  1692. segT sec ATTRIBUTE_UNUSED,
  1693. fragS *fragP)
  1694. {
  1695. /* Structure describing needed address fix. */
  1696. fixS *fixP;
  1697. switch (fragP->fr_subtype)
  1698. {
  1699. case 1:
  1700. /* Leave single cobr instruction. */
  1701. fixP = fix_new (fragP,
  1702. fragP->fr_opcode - fragP->fr_literal,
  1703. 4,
  1704. fragP->fr_symbol,
  1705. fragP->fr_offset,
  1706. 1,
  1707. NO_RELOC);
  1708. fixP->fx_bit_fixP = (bit_fixS *) 13; /* Size of bit field. */
  1709. break;
  1710. case 2:
  1711. /* Replace cobr with compare/branch instructions. */
  1712. relax_cobr (fragP);
  1713. break;
  1714. default:
  1715. BAD_CASE (fragP->fr_subtype);
  1716. break;
  1717. }
  1718. }
  1719. /* md_estimate_size_before_relax: How much does it look like *fragP will grow?
  1720. Called by base assembler just before address relaxation.
  1721. Return the amount by which the fragment will grow.
  1722. Any symbol that is now undefined will not become defined; cobr's
  1723. based on undefined symbols will have to be replaced with a compare
  1724. instruction and a branch instruction, and the code fragment will grow
  1725. by 4 bytes. */
  1726. int
  1727. md_estimate_size_before_relax (fragS *fragP, segT segment_type)
  1728. {
  1729. /* If symbol is undefined in this segment, go to "relaxed" state
  1730. (compare and branch instructions instead of cobr) right now. */
  1731. if (S_GET_SEGMENT (fragP->fr_symbol) != segment_type)
  1732. {
  1733. relax_cobr (fragP);
  1734. return 4;
  1735. }
  1736. return md_relax_table[fragP->fr_subtype].rlx_length;
  1737. }
  1738. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  1739. /* md_ri_to_chars:
  1740. This routine exists in order to overcome machine byte-order problems
  1741. when dealing with bit-field entries in the relocation_info struct.
  1742. But relocation info will be used on the host machine only (only
  1743. executable code is actually downloaded to the i80960). Therefore,
  1744. we leave it in host byte order. */
  1745. static void
  1746. md_ri_to_chars (char *where, struct relocation_info *ri)
  1747. {
  1748. host_number_to_chars (where, ri->r_address, 4);
  1749. host_number_to_chars (where + 4, ri->r_index, 3);
  1750. #if WORDS_BIGENDIAN
  1751. where[7] = (ri->r_pcrel << 7
  1752. | ri->r_length << 5
  1753. | ri->r_extern << 4
  1754. | ri->r_bsr << 3
  1755. | ri->r_disp << 2
  1756. | ri->r_callj << 1
  1757. | ri->nuthin << 0);
  1758. #else
  1759. where[7] = (ri->r_pcrel << 0
  1760. | ri->r_length << 1
  1761. | ri->r_extern << 3
  1762. | ri->r_bsr << 4
  1763. | ri->r_disp << 5
  1764. | ri->r_callj << 6
  1765. | ri->nuthin << 7);
  1766. #endif
  1767. }
  1768. #endif /* defined(OBJ_AOUT) | defined(OBJ_BOUT) */
  1769. /* brtab_emit: generate the fetch-prediction branch table.
  1770. See the comments above the declaration of 'br_cnt' for details on
  1771. branch-prediction instrumentation.
  1772. The code emitted here would be functionally equivalent to the following
  1773. example assembler source.
  1774. .data
  1775. .align 2
  1776. BR_TAB_NAME:
  1777. .word 0 # link to next table
  1778. .word 3 # length of table
  1779. .word LBRANCH0 # 1st entry in table proper
  1780. .word LBRANCH1
  1781. .word LBRANCH2 */
  1782. void
  1783. brtab_emit (void)
  1784. {
  1785. int i;
  1786. char buf[20];
  1787. /* Where the binary was output to. */
  1788. char *p;
  1789. if (!instrument_branches)
  1790. return;
  1791. subseg_set (data_section, 0); /* .data */
  1792. frag_align (2, 0, 0); /* .align 2 */
  1793. record_alignment (now_seg, 2);
  1794. colon (BR_TAB_NAME); /* BR_TAB_NAME: */
  1795. emit (0); /* .word 0 #link to next table */
  1796. emit (br_cnt); /* .word n #length of table */
  1797. for (i = 0; i < br_cnt; i++)
  1798. {
  1799. sprintf (buf, "%s%d", BR_LABEL_BASE, i);
  1800. p = emit (0);
  1801. fix_new (frag_now,
  1802. p - frag_now->fr_literal,
  1803. 4, symbol_find (buf), 0, 0, NO_RELOC);
  1804. }
  1805. }
  1806. /* s_leafproc: process .leafproc pseudo-op
  1807. .leafproc takes two arguments, the second one is optional:
  1808. arg[1]: name of 'call' entry point to leaf procedure
  1809. arg[2]: name of 'bal' entry point to leaf procedure
  1810. If the two arguments are identical, or if the second one is missing,
  1811. the first argument is taken to be the 'bal' entry point.
  1812. If there are 2 distinct arguments, we must make sure that the 'bal'
  1813. entry point immediately follows the 'call' entry point in the linked
  1814. list of symbols. */
  1815. static void
  1816. s_leafproc (int n_ops, /* Number of operands. */
  1817. char *args[]) /* args[1]->1st operand, args[2]->2nd operand. */
  1818. {
  1819. symbolS *callP; /* Pointer to leafproc 'call' entry point symbol. */
  1820. symbolS *balP; /* Pointer to leafproc 'bal' entry point symbol. */
  1821. if ((n_ops != 1) && (n_ops != 2))
  1822. {
  1823. as_bad (_("should have 1 or 2 operands"));
  1824. return;
  1825. }
  1826. /* Find or create symbol for 'call' entry point. */
  1827. callP = symbol_find_or_make (args[1]);
  1828. if (TC_S_IS_CALLNAME (callP))
  1829. as_warn (_("Redefining leafproc %s"), S_GET_NAME (callP));
  1830. /* If that was the only argument, use it as the 'bal' entry point.
  1831. Otherwise, mark it as the 'call' entry point and find or create
  1832. another symbol for the 'bal' entry point. */
  1833. if ((n_ops == 1) || !strcmp (args[1], args[2]))
  1834. {
  1835. TC_S_FORCE_TO_BALNAME (callP);
  1836. }
  1837. else
  1838. {
  1839. TC_S_FORCE_TO_CALLNAME (callP);
  1840. balP = symbol_find_or_make (args[2]);
  1841. if (TC_S_IS_CALLNAME (balP))
  1842. as_warn (_("Redefining leafproc %s"), S_GET_NAME (balP));
  1843. TC_S_FORCE_TO_BALNAME (balP);
  1844. #ifndef OBJ_ELF
  1845. tc_set_bal_of_call (callP, balP);
  1846. #endif
  1847. }
  1848. }
  1849. /* s_sysproc: process .sysproc pseudo-op
  1850. .sysproc takes two arguments:
  1851. arg[1]: name of entry point to system procedure
  1852. arg[2]: 'entry_num' (index) of system procedure in the range
  1853. [0,31] inclusive.
  1854. For [ab].out, we store the 'entrynum' in the 'n_other' field of
  1855. the symbol. Since that entry is normally 0, we bias 'entrynum'
  1856. by adding 1 to it. It must be unbiased before it is used. */
  1857. static void
  1858. s_sysproc (int n_ops, /* Number of operands. */
  1859. char *args[]) /* args[1]->1st operand, args[2]->2nd operand. */
  1860. {
  1861. expressionS exp;
  1862. symbolS *symP;
  1863. if (n_ops != 2)
  1864. {
  1865. as_bad (_("should have two operands"));
  1866. return;
  1867. }
  1868. /* Parse "entry_num" argument and check it for validity. */
  1869. parse_expr (args[2], &exp);
  1870. if (exp.X_op != O_constant
  1871. || (offs (exp) < 0)
  1872. || (offs (exp) > 31))
  1873. {
  1874. as_bad (_("'entry_num' must be absolute number in [0,31]"));
  1875. return;
  1876. }
  1877. /* Find/make symbol and stick entry number (biased by +1) into it. */
  1878. symP = symbol_find_or_make (args[1]);
  1879. if (TC_S_IS_SYSPROC (symP))
  1880. as_warn (_("Redefining entrynum for sysproc %s"), S_GET_NAME (symP));
  1881. TC_S_SET_SYSPROC (symP, offs (exp)); /* Encode entry number. */
  1882. TC_S_FORCE_TO_SYSPROC (symP);
  1883. }
  1884. /* parse_po: parse machine-dependent pseudo-op
  1885. This is a top-level routine for machine-dependent pseudo-ops. It slurps
  1886. up the rest of the input line, breaks out the individual arguments,
  1887. and dispatches them to the correct handler. */
  1888. static void
  1889. parse_po (int po_num) /* Pseudo-op number: currently S_LEAFPROC or S_SYSPROC. */
  1890. {
  1891. /* Pointers operands, with no embedded whitespace.
  1892. arg[0] unused, arg[1-3]->operands. */
  1893. char *args[4];
  1894. int n_ops; /* Number of operands. */
  1895. char *p; /* Pointer to beginning of unparsed argument string. */
  1896. char eol; /* Character that indicated end of line. */
  1897. extern char is_end_of_line[];
  1898. /* Advance input pointer to end of line. */
  1899. p = input_line_pointer;
  1900. while (!is_end_of_line[(unsigned char) *input_line_pointer])
  1901. input_line_pointer++;
  1902. eol = *input_line_pointer; /* Save end-of-line char. */
  1903. *input_line_pointer = '\0'; /* Terminate argument list. */
  1904. /* Parse out operands. */
  1905. n_ops = get_args (p, args);
  1906. if (n_ops == -1)
  1907. return;
  1908. /* Dispatch to correct handler. */
  1909. switch (po_num)
  1910. {
  1911. case S_SYSPROC:
  1912. s_sysproc (n_ops, args);
  1913. break;
  1914. case S_LEAFPROC:
  1915. s_leafproc (n_ops, args);
  1916. break;
  1917. default:
  1918. BAD_CASE (po_num);
  1919. break;
  1920. }
  1921. /* Restore eol, so line numbers get updated correctly. Base
  1922. assembler assumes we leave input pointer pointing at char
  1923. following the eol. */
  1924. *input_line_pointer++ = eol;
  1925. }
  1926. /* reloc_callj: Relocate a 'callj' instruction
  1927. This is a "non-(GNU)-standard" machine-dependent hook. The base
  1928. assembler calls it when it decides it can relocate an address at
  1929. assembly time instead of emitting a relocation directive.
  1930. Check to see if the relocation involves a 'callj' instruction to a:
  1931. sysproc: Replace the default 'call' instruction with a 'calls'
  1932. leafproc: Replace the default 'call' instruction with a 'bal'.
  1933. other proc: Do nothing.
  1934. See b.out.h for details on the 'n_other' field in a symbol structure.
  1935. IMPORTANT!:
  1936. Assumes the caller has already figured out, in the case of a leafproc,
  1937. to use the 'bal' entry point, and has substituted that symbol into the
  1938. passed fixup structure. */
  1939. int
  1940. reloc_callj (fixS *fixP) /* Relocation that can be done at assembly time. */
  1941. {
  1942. /* Points to the binary for the instruction being relocated. */
  1943. char *where;
  1944. if (!fixP->fx_tcbit)
  1945. /* This wasn't a callj instruction in the first place. */
  1946. return 0;
  1947. where = fixP->fx_frag->fr_literal + fixP->fx_where;
  1948. if (TC_S_IS_SYSPROC (fixP->fx_addsy))
  1949. {
  1950. /* Symbol is a .sysproc: replace 'call' with 'calls'. System
  1951. procedure number is (other-1). */
  1952. md_number_to_chars (where, CALLS | TC_S_GET_SYSPROC (fixP->fx_addsy), 4);
  1953. /* Nothing else needs to be done for this instruction. Make
  1954. sure 'md_number_to_field()' will perform a no-op. */
  1955. fixP->fx_bit_fixP = (bit_fixS *) 1;
  1956. }
  1957. else if (TC_S_IS_CALLNAME (fixP->fx_addsy))
  1958. {
  1959. /* Should not happen: see block comment above. */
  1960. as_fatal (_("Trying to 'bal' to %s"), S_GET_NAME (fixP->fx_addsy));
  1961. }
  1962. else if (TC_S_IS_BALNAME (fixP->fx_addsy))
  1963. {
  1964. /* Replace 'call' with 'bal'; both instructions have the same
  1965. format, so calling code should complete relocation as if
  1966. nothing happened here. */
  1967. md_number_to_chars (where, BAL, 4);
  1968. }
  1969. else if (TC_S_IS_BADPROC (fixP->fx_addsy))
  1970. as_bad (_("Looks like a proc, but can't tell what kind.\n"));
  1971. /* Otherwise Symbol is neither a sysproc nor a leafproc. */
  1972. return 0;
  1973. }
  1974. /* Handle the MRI .endian pseudo-op. */
  1975. static void
  1976. s_endian (int ignore ATTRIBUTE_UNUSED)
  1977. {
  1978. char *name;
  1979. char c;
  1980. c = get_symbol_name (&name);
  1981. if (strcasecmp (name, "little") == 0)
  1982. ;
  1983. else if (strcasecmp (name, "big") == 0)
  1984. as_bad (_("big endian mode is not supported"));
  1985. else
  1986. as_warn (_("ignoring unrecognized .endian type `%s'"), name);
  1987. (void) restore_line_pointer (c);
  1988. demand_empty_rest_of_line ();
  1989. }
  1990. /* We have no need to default values of symbols. */
  1991. symbolS *
  1992. md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
  1993. {
  1994. return 0;
  1995. }
  1996. /* Exactly what point is a PC-relative offset relative TO?
  1997. On the i960, they're relative to the address of the instruction,
  1998. which we have set up as the address of the fixup too. */
  1999. long
  2000. md_pcrel_from (fixS *fixP)
  2001. {
  2002. return fixP->fx_where + fixP->fx_frag->fr_address;
  2003. }
  2004. void
  2005. md_apply_fix (fixS *fixP,
  2006. valueT *valP,
  2007. segT seg ATTRIBUTE_UNUSED)
  2008. {
  2009. long val = *valP;
  2010. char *place = fixP->fx_where + fixP->fx_frag->fr_literal;
  2011. if (!fixP->fx_bit_fixP)
  2012. {
  2013. md_number_to_imm (place, val, fixP->fx_size);
  2014. }
  2015. else if ((int) (size_t) fixP->fx_bit_fixP == 13
  2016. && fixP->fx_addsy != NULL
  2017. && S_GET_SEGMENT (fixP->fx_addsy) == undefined_section)
  2018. {
  2019. /* This is a COBR instruction. They have only a
  2020. 13-bit displacement and are only to be used
  2021. for local branches: flag as error, don't generate
  2022. relocation. */
  2023. as_bad_where (fixP->fx_file, fixP->fx_line,
  2024. _("can't use COBR format with external label"));
  2025. fixP->fx_addsy = NULL;
  2026. }
  2027. else
  2028. md_number_to_field (place, val, fixP->fx_bit_fixP);
  2029. if (fixP->fx_addsy == NULL)
  2030. fixP->fx_done = 1;
  2031. }
  2032. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  2033. void
  2034. tc_bout_fix_to_chars (char *where,
  2035. fixS *fixP,
  2036. relax_addressT segment_address_in_file)
  2037. {
  2038. static const unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
  2039. struct relocation_info ri;
  2040. symbolS *symbolP;
  2041. memset ((char *) &ri, '\0', sizeof (ri));
  2042. symbolP = fixP->fx_addsy;
  2043. know (symbolP != 0 || fixP->fx_r_type != NO_RELOC);
  2044. ri.r_bsr = fixP->fx_bsr; /*SAC LD RELAX HACK */
  2045. /* These two 'cuz of NS32K */
  2046. ri.r_callj = fixP->fx_tcbit;
  2047. if (fixP->fx_bit_fixP)
  2048. ri.r_length = 2;
  2049. else
  2050. ri.r_length = nbytes_r_length[fixP->fx_size];
  2051. ri.r_pcrel = fixP->fx_pcrel;
  2052. ri.r_address = fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file;
  2053. if (fixP->fx_r_type != NO_RELOC)
  2054. {
  2055. switch (fixP->fx_r_type)
  2056. {
  2057. case rs_align:
  2058. ri.r_index = -2;
  2059. ri.r_pcrel = 1;
  2060. ri.r_length = fixP->fx_size - 1;
  2061. break;
  2062. case rs_org:
  2063. ri.r_index = -2;
  2064. ri.r_pcrel = 0;
  2065. break;
  2066. case rs_fill:
  2067. ri.r_index = -1;
  2068. break;
  2069. default:
  2070. abort ();
  2071. }
  2072. ri.r_extern = 0;
  2073. }
  2074. else if (linkrelax || !S_IS_DEFINED (symbolP) || fixP->fx_bsr)
  2075. {
  2076. ri.r_extern = 1;
  2077. ri.r_index = symbolP->sy_number;
  2078. }
  2079. else
  2080. {
  2081. ri.r_extern = 0;
  2082. ri.r_index = S_GET_TYPE (symbolP);
  2083. }
  2084. /* Output the relocation information in machine-dependent form. */
  2085. md_ri_to_chars (where, &ri);
  2086. }
  2087. #endif /* OBJ_AOUT or OBJ_BOUT */
  2088. /* Align an address by rounding it up to the specified boundary. */
  2089. valueT
  2090. md_section_align (segT seg,
  2091. valueT addr) /* Address to be rounded up. */
  2092. {
  2093. int align;
  2094. align = bfd_get_section_alignment (stdoutput, seg);
  2095. return (addr + (1 << align) - 1) & (-1 << align);
  2096. }
  2097. extern int coff_flags;
  2098. /* For aout or bout, the bal immediately follows the call.
  2099. For coff, we cheat and store a pointer to the bal symbol in the
  2100. second aux entry of the call. */
  2101. #undef OBJ_ABOUT
  2102. #ifdef OBJ_AOUT
  2103. #define OBJ_ABOUT
  2104. #endif
  2105. #ifdef OBJ_BOUT
  2106. #define OBJ_ABOUT
  2107. #endif
  2108. void
  2109. tc_set_bal_of_call (symbolS *callP ATTRIBUTE_UNUSED,
  2110. symbolS *balP ATTRIBUTE_UNUSED)
  2111. {
  2112. know (TC_S_IS_CALLNAME (callP));
  2113. know (TC_S_IS_BALNAME (balP));
  2114. #ifdef OBJ_COFF
  2115. callP->sy_tc = balP;
  2116. S_SET_NUMBER_AUXILIARY (callP, 2);
  2117. #else /* ! OBJ_COFF */
  2118. #ifdef OBJ_ABOUT
  2119. /* If the 'bal' entry doesn't immediately follow the 'call'
  2120. symbol, unlink it from the symbol list and re-insert it. */
  2121. if (symbol_next (callP) != balP)
  2122. {
  2123. symbol_remove (balP, &symbol_rootP, &symbol_lastP);
  2124. symbol_append (balP, callP, &symbol_rootP, &symbol_lastP);
  2125. } /* if not in order */
  2126. #else /* ! OBJ_ABOUT */
  2127. as_fatal ("Only supported for a.out, b.out, or COFF");
  2128. #endif /* ! OBJ_ABOUT */
  2129. #endif /* ! OBJ_COFF */
  2130. }
  2131. symbolS *
  2132. tc_get_bal_of_call (symbolS *callP ATTRIBUTE_UNUSED)
  2133. {
  2134. symbolS *retval;
  2135. know (TC_S_IS_CALLNAME (callP));
  2136. #ifdef OBJ_COFF
  2137. retval = callP->sy_tc;
  2138. #else
  2139. #ifdef OBJ_ABOUT
  2140. retval = symbol_next (callP);
  2141. #else
  2142. as_fatal ("Only supported for a.out, b.out, or COFF");
  2143. #endif /* ! OBJ_ABOUT */
  2144. #endif /* ! OBJ_COFF */
  2145. know (TC_S_IS_BALNAME (retval));
  2146. return retval;
  2147. }
  2148. #ifdef OBJ_COFF
  2149. void
  2150. tc_coff_symbol_emit_hook (symbolS *symbolP ATTRIBUTE_UNUSED)
  2151. {
  2152. if (TC_S_IS_CALLNAME (symbolP))
  2153. {
  2154. symbolS *balP = tc_get_bal_of_call (symbolP);
  2155. symbolP->sy_symbol.ost_auxent[1].x_bal.x_balntry = S_GET_VALUE (balP);
  2156. if (S_GET_STORAGE_CLASS (symbolP) == C_EXT)
  2157. S_SET_STORAGE_CLASS (symbolP, C_LEAFEXT);
  2158. else
  2159. S_SET_STORAGE_CLASS (symbolP, C_LEAFSTAT);
  2160. S_SET_DATA_TYPE (symbolP, S_GET_DATA_TYPE (symbolP) | (DT_FCN << N_BTSHFT));
  2161. /* Fix up the bal symbol. */
  2162. S_SET_STORAGE_CLASS (balP, C_LABEL);
  2163. }
  2164. }
  2165. #endif /* OBJ_COFF */
  2166. void
  2167. i960_handle_align (fragS *fragp ATTRIBUTE_UNUSED)
  2168. {
  2169. if (!linkrelax)
  2170. return;
  2171. #ifndef OBJ_BOUT
  2172. as_bad (_("option --link-relax is only supported in b.out format"));
  2173. linkrelax = 0;
  2174. return;
  2175. #else
  2176. /* The text section "ends" with another alignment reloc, to which we
  2177. aren't adding padding. */
  2178. if (fragp->fr_next == text_last_frag
  2179. || fragp->fr_next == data_last_frag)
  2180. return;
  2181. /* alignment directive */
  2182. fix_new (fragp, fragp->fr_fix, fragp->fr_offset, 0, 0, 0,
  2183. (int) fragp->fr_type);
  2184. #endif /* OBJ_BOUT */
  2185. }
  2186. int
  2187. i960_validate_fix (fixS *fixP, segT this_segment_type ATTRIBUTE_UNUSED)
  2188. {
  2189. if (fixP->fx_tcbit && TC_S_IS_CALLNAME (fixP->fx_addsy))
  2190. {
  2191. /* Relocation should be done via the associated 'bal'
  2192. entry point symbol. */
  2193. if (!TC_S_IS_BALNAME (tc_get_bal_of_call (fixP->fx_addsy)))
  2194. {
  2195. as_bad_where (fixP->fx_file, fixP->fx_line,
  2196. _("No 'bal' entry point for leafproc %s"),
  2197. S_GET_NAME (fixP->fx_addsy));
  2198. return 0;
  2199. }
  2200. fixP->fx_addsy = tc_get_bal_of_call (fixP->fx_addsy);
  2201. }
  2202. return 1;
  2203. }
  2204. /* From cgen.c: */
  2205. static short
  2206. tc_bfd_fix2rtype (fixS *fixP)
  2207. {
  2208. if (fixP->fx_pcrel == 0 && fixP->fx_size == 4)
  2209. return BFD_RELOC_32;
  2210. if (fixP->fx_pcrel != 0 && fixP->fx_size == 4)
  2211. return BFD_RELOC_24_PCREL;
  2212. abort ();
  2213. return 0;
  2214. }
  2215. /* Translate internal representation of relocation info to BFD target
  2216. format.
  2217. FIXME: To what extent can we get all relevant targets to use this? */
  2218. arelent *
  2219. tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
  2220. {
  2221. arelent * reloc;
  2222. reloc = xmalloc (sizeof (arelent));
  2223. /* HACK: Is this right? */
  2224. fixP->fx_r_type = tc_bfd_fix2rtype (fixP);
  2225. reloc->howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
  2226. if (reloc->howto == NULL)
  2227. {
  2228. as_bad_where (fixP->fx_file, fixP->fx_line,
  2229. _("internal error: can't export reloc type %d (`%s')"),
  2230. fixP->fx_r_type,
  2231. bfd_get_reloc_code_name (fixP->fx_r_type));
  2232. return NULL;
  2233. }
  2234. gas_assert (!fixP->fx_pcrel == !reloc->howto->pc_relative);
  2235. reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  2236. *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
  2237. reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;
  2238. reloc->addend = fixP->fx_addnumber;
  2239. return reloc;
  2240. }
  2241. /* end from cgen.c */
  2242. const pseudo_typeS md_pseudo_table[] =
  2243. {
  2244. {"bss", s_lcomm, 1},
  2245. {"endian", s_endian, 0},
  2246. {"extended", float_cons, 't'},
  2247. {"leafproc", parse_po, S_LEAFPROC},
  2248. {"sysproc", parse_po, S_SYSPROC},
  2249. {"word", cons, 4},
  2250. {"quad", cons, 16},
  2251. {0, 0, 0}
  2252. };