tc-i370.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666
  1. /* tc-i370.c -- Assembler for the IBM 360/370/390 instruction set.
  2. Loosely based on the ppc files by Linas Vepstas <linas@linas.org> 1998, 99
  3. Copyright (C) 1994-2015 Free Software Foundation, Inc.
  4. Written by Ian Lance Taylor, Cygnus Support.
  5. This file is part of GAS, the GNU Assembler.
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3, or (at your option)
  9. any later version.
  10. GAS is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GAS; see the file COPYING. If not, write to the Free
  16. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  17. 02110-1301, USA. */
  18. /* This assembler implements a very hacked version of an elf-like thing
  19. that gcc emits (when gcc is suitably hacked). To make it behave more
  20. HLASM-like, try turning on the -M or --mri flag (as there are various
  21. similarities between HLASM and the MRI assemblers, such as section
  22. names, lack of leading . in pseudo-ops, DC and DS, etc. */
  23. #include "as.h"
  24. #include "safe-ctype.h"
  25. #include "subsegs.h"
  26. #include "struc-symbol.h"
  27. #include "opcode/i370.h"
  28. #ifdef OBJ_ELF
  29. #include "elf/i370.h"
  30. #endif
  31. /* This is the assembler for the System/390 Architecture. */
  32. /* Tell the main code what the endianness is. */
  33. extern int target_big_endian;
  34. /* Generic assembler global variables which must be defined by all
  35. targets. */
  36. #ifdef OBJ_ELF
  37. /* This string holds the chars that always start a comment. If the
  38. pre-processor is disabled, these aren't very useful. The macro
  39. tc_comment_chars points to this. We use this, rather than the
  40. usual comment_chars, so that we can switch for Solaris conventions. */
  41. static const char i370_eabi_comment_chars[] = "#";
  42. const char *i370_comment_chars = i370_eabi_comment_chars;
  43. #else
  44. const char comment_chars[] = "#";
  45. #endif
  46. /* Characters which start a comment at the beginning of a line. */
  47. const char line_comment_chars[] = "#*";
  48. /* Characters which may be used to separate multiple commands on a
  49. single line. */
  50. const char line_separator_chars[] = ";";
  51. /* Characters which are used to indicate an exponent in a floating
  52. point number. */
  53. const char EXP_CHARS[] = "eE";
  54. /* Characters which mean that a number is a floating point constant,
  55. as in 0d1.0. */
  56. const char FLT_CHARS[] = "dD";
  57. void
  58. md_show_usage (FILE *stream)
  59. {
  60. fprintf (stream, "\
  61. S/370 options: (these have not yet been tested and may not work) \n\
  62. -u ignored\n\
  63. -mregnames Allow symbolic names for registers\n\
  64. -mno-regnames Do not allow symbolic names for registers\n");
  65. #ifdef OBJ_ELF
  66. fprintf (stream, "\
  67. -mrelocatable support for GCC's -mrelocatble option\n\
  68. -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
  69. -V print assembler version number\n");
  70. #endif
  71. }
  72. /* Whether to use user friendly register names. */
  73. #define TARGET_REG_NAMES_P TRUE
  74. static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
  75. /* Predefined register names if -mregnames
  76. In general, there are lots of them, in an attempt to be compatible
  77. with a number of assemblers. */
  78. /* Structure to hold information about predefined registers. */
  79. struct pd_reg
  80. {
  81. char *name;
  82. int value;
  83. };
  84. /* List of registers that are pre-defined:
  85. Each general register has predefined names of the form:
  86. 1. r<reg_num> which has the value <reg_num>.
  87. 2. r.<reg_num> which has the value <reg_num>.
  88. Each floating point register has predefined names of the form:
  89. 1. f<reg_num> which has the value <reg_num>.
  90. 2. f.<reg_num> which has the value <reg_num>.
  91. There are only four floating point registers, and these are
  92. commonly labelled 0,2,4 and 6. Thus, there is no f1, f3, etc.
  93. There are individual registers as well:
  94. rbase or r.base has the value 3 (base register)
  95. rpgt or r.pgt has the value 4 (page origin table pointer)
  96. rarg or r.arg has the value 11 (argument pointer)
  97. rtca or r.tca has the value 12 (table of contents pointer)
  98. rtoc or r.toc has the value 12 (table of contents pointer)
  99. sp or r.sp has the value 13 (stack pointer)
  100. dsa or r.dsa has the value 13 (stack pointer)
  101. lr has the value 14 (link reg)
  102. The table is sorted. Suitable for searching by a binary search. */
  103. static const struct pd_reg pre_defined_registers[] =
  104. {
  105. { "arg", 11 }, /* Argument Pointer. */
  106. { "base", 3 }, /* Base Reg. */
  107. { "f.0", 0 }, /* Floating point registers. */
  108. { "f.2", 2 },
  109. { "f.4", 4 },
  110. { "f.6", 6 },
  111. { "f0", 0 },
  112. { "f2", 2 },
  113. { "f4", 4 },
  114. { "f6", 6 },
  115. { "dsa",13 }, /* Stack pointer. */
  116. { "lr", 14 }, /* Link Register. */
  117. { "pgt", 4 }, /* Page Origin Table Pointer. */
  118. { "r.0", 0 }, /* General Purpose Registers. */
  119. { "r.1", 1 },
  120. { "r.10", 10 },
  121. { "r.11", 11 },
  122. { "r.12", 12 },
  123. { "r.13", 13 },
  124. { "r.14", 14 },
  125. { "r.15", 15 },
  126. { "r.2", 2 },
  127. { "r.3", 3 },
  128. { "r.4", 4 },
  129. { "r.5", 5 },
  130. { "r.6", 6 },
  131. { "r.7", 7 },
  132. { "r.8", 8 },
  133. { "r.9", 9 },
  134. { "r.arg", 11 }, /* Argument Pointer. */
  135. { "r.base", 3 }, /* Base Reg. */
  136. { "r.dsa", 13 }, /* Stack Pointer. */
  137. { "r.pgt", 4 }, /* Page Origin Table Pointer. */
  138. { "r.sp", 13 }, /* Stack Pointer. */
  139. { "r.tca", 12 }, /* Pointer to the table of contents. */
  140. { "r.toc", 12 }, /* Pointer to the table of contents. */
  141. { "r0", 0 }, /* More general purpose registers. */
  142. { "r1", 1 },
  143. { "r10", 10 },
  144. { "r11", 11 },
  145. { "r12", 12 },
  146. { "r13", 13 },
  147. { "r14", 14 },
  148. { "r15", 15 },
  149. { "r2", 2 },
  150. { "r3", 3 },
  151. { "r4", 4 },
  152. { "r5", 5 },
  153. { "r6", 6 },
  154. { "r7", 7 },
  155. { "r8", 8 },
  156. { "r9", 9 },
  157. { "rbase", 3 }, /* Base Reg. */
  158. { "rtca", 12 }, /* Pointer to the table of contents. */
  159. { "rtoc", 12 }, /* Pointer to the table of contents. */
  160. { "sp", 13 }, /* Stack Pointer. */
  161. };
  162. #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
  163. /* Given NAME, find the register number associated with that name, return
  164. the integer value associated with the given name or -1 on failure. */
  165. static int
  166. reg_name_search (const struct pd_reg *regs,
  167. int regcount,
  168. const char *name)
  169. {
  170. int middle, low, high;
  171. int cmp;
  172. low = 0;
  173. high = regcount - 1;
  174. do
  175. {
  176. middle = (low + high) / 2;
  177. cmp = strcasecmp (name, regs[middle].name);
  178. if (cmp < 0)
  179. high = middle - 1;
  180. else if (cmp > 0)
  181. low = middle + 1;
  182. else
  183. return regs[middle].value;
  184. }
  185. while (low <= high);
  186. return -1;
  187. }
  188. /* Summary of register_name().
  189. in: Input_line_pointer points to 1st char of operand.
  190. out: An expressionS.
  191. The operand may have been a register: in this case, X_op == O_register,
  192. X_add_number is set to the register number, and truth is returned.
  193. Input_line_pointer->(next non-blank) char after operand, or is in its
  194. original state. */
  195. static bfd_boolean
  196. register_name (expressionS *expressionP)
  197. {
  198. int reg_number;
  199. char *name;
  200. char *start;
  201. char c;
  202. /* Find the spelling of the operand. */
  203. start = name = input_line_pointer;
  204. if (name[0] == '%' && ISALPHA (name[1]))
  205. name = ++input_line_pointer;
  206. else if (!reg_names_p)
  207. return FALSE;
  208. while (' ' == *name)
  209. name = ++input_line_pointer;
  210. /* If it's a number, treat it as a number. If it's alpha, look to
  211. see if it's in the register table. */
  212. if (!ISALPHA (name[0]))
  213. reg_number = get_single_number ();
  214. else
  215. {
  216. c = get_symbol_name (&name);
  217. reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
  218. /* Put back the delimiting char. */
  219. (void) restore_line_pointer (c);
  220. }
  221. /* If numeric, make sure its not out of bounds. */
  222. if ((0 <= reg_number) && (16 >= reg_number))
  223. {
  224. expressionP->X_op = O_register;
  225. expressionP->X_add_number = reg_number;
  226. /* Make the rest nice. */
  227. expressionP->X_add_symbol = NULL;
  228. expressionP->X_op_symbol = NULL;
  229. return TRUE;
  230. }
  231. /* Reset the line as if we had not done anything. */
  232. input_line_pointer = start;
  233. return FALSE;
  234. }
  235. /* Local variables. */
  236. /* The type of processor we are assembling for. This is one or more
  237. of the I370_OPCODE flags defined in opcode/i370.h. */
  238. static int i370_cpu = 0;
  239. /* The base register to use for opcode with optional operands.
  240. We define two of these: "text" and "other". Normally, "text"
  241. would get used in the .text section for branches, while "other"
  242. gets used in the .data section for address constants.
  243. The idea of a second base register in a different section
  244. is foreign to the usual HLASM-style semantics; however, it
  245. allows us to provide support for dynamically loaded libraries,
  246. by allowing us to place address constants in a section other
  247. than the text section. The "other" section need not be the
  248. .data section, it can be any section that isn't the .text section.
  249. Note that HLASM defines a multiple, concurrent .using semantic
  250. that we do not: in calculating offsets, it uses either the most
  251. recent .using directive, or the one with the smallest displacement.
  252. This allows HLASM to support a quasi-block-scope-like behaviour.
  253. Handy for people writing assembly by hand ... but not supported
  254. by us. */
  255. static int i370_using_text_regno = -1;
  256. static int i370_using_other_regno = -1;
  257. /* The base address for address literals. */
  258. static expressionS i370_using_text_baseaddr;
  259. static expressionS i370_using_other_baseaddr;
  260. /* the "other" section, used only for syntax error detection. */
  261. static segT i370_other_section = undefined_section;
  262. /* Opcode hash table. */
  263. static struct hash_control *i370_hash;
  264. /* Macro hash table. */
  265. static struct hash_control *i370_macro_hash;
  266. #ifdef OBJ_ELF
  267. /* What type of shared library support to use. */
  268. static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE;
  269. #endif
  270. /* Flags to set in the elf header. */
  271. static flagword i370_flags = 0;
  272. #ifndef WORKING_DOT_WORD
  273. int md_short_jump_size = 4;
  274. int md_long_jump_size = 4;
  275. #endif
  276. #ifdef OBJ_ELF
  277. const char *md_shortopts = "l:um:K:VQ:";
  278. #else
  279. const char *md_shortopts = "um:";
  280. #endif
  281. struct option md_longopts[] =
  282. {
  283. {NULL, no_argument, NULL, 0}
  284. };
  285. size_t md_longopts_size = sizeof (md_longopts);
  286. int
  287. md_parse_option (int c, char *arg)
  288. {
  289. switch (c)
  290. {
  291. case 'u':
  292. /* -u means that any undefined symbols should be treated as
  293. external, which is the default for gas anyhow. */
  294. break;
  295. #ifdef OBJ_ELF
  296. case 'K':
  297. /* Recognize -K PIC */
  298. if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
  299. {
  300. shlib = SHLIB_PIC;
  301. i370_flags |= EF_I370_RELOCATABLE_LIB;
  302. }
  303. else
  304. return 0;
  305. break;
  306. #endif
  307. case 'm':
  308. /* -m360 mean to assemble for the ancient 360 architecture. */
  309. if (strcmp (arg, "360") == 0 || strcmp (arg, "i360") == 0)
  310. i370_cpu = I370_OPCODE_360;
  311. /* -mxa means to assemble for the IBM 370 XA. */
  312. else if (strcmp (arg, "xa") == 0)
  313. i370_cpu = I370_OPCODE_370_XA;
  314. /* -many means to assemble for any architecture (370/XA). */
  315. else if (strcmp (arg, "any") == 0)
  316. i370_cpu = I370_OPCODE_370;
  317. else if (strcmp (arg, "regnames") == 0)
  318. reg_names_p = TRUE;
  319. else if (strcmp (arg, "no-regnames") == 0)
  320. reg_names_p = FALSE;
  321. #ifdef OBJ_ELF
  322. /* -mrelocatable/-mrelocatable-lib -- warn about
  323. initializations that require relocation. */
  324. else if (strcmp (arg, "relocatable") == 0)
  325. {
  326. shlib = SHILB_MRELOCATABLE;
  327. i370_flags |= EF_I370_RELOCATABLE;
  328. }
  329. else if (strcmp (arg, "relocatable-lib") == 0)
  330. {
  331. shlib = SHILB_MRELOCATABLE;
  332. i370_flags |= EF_I370_RELOCATABLE_LIB;
  333. }
  334. #endif
  335. else
  336. {
  337. as_bad (_("invalid switch -m%s"), arg);
  338. return 0;
  339. }
  340. break;
  341. #ifdef OBJ_ELF
  342. /* -V: SVR4 argument to print version ID. */
  343. case 'V':
  344. print_version_id ();
  345. break;
  346. /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
  347. should be emitted or not. FIXME: Not implemented. */
  348. case 'Q':
  349. break;
  350. #endif
  351. default:
  352. return 0;
  353. }
  354. return 1;
  355. }
  356. /* Set i370_cpu if it is not already set.
  357. Currently defaults to the reasonable superset;
  358. but can be made more fine grained if desred. */
  359. static void
  360. i370_set_cpu (void)
  361. {
  362. const char *default_os = TARGET_OS;
  363. const char *default_cpu = TARGET_CPU;
  364. /* Override with the superset for the moment. */
  365. i370_cpu = I370_OPCODE_ESA390_SUPERSET;
  366. if (i370_cpu == 0)
  367. {
  368. if (strcmp (default_cpu, "i360") == 0)
  369. i370_cpu = I370_OPCODE_360;
  370. else if (strcmp (default_cpu, "i370") == 0)
  371. i370_cpu = I370_OPCODE_370;
  372. else if (strcmp (default_cpu, "XA") == 0)
  373. i370_cpu = I370_OPCODE_370_XA;
  374. else
  375. as_fatal ("Unknown default cpu = %s, os = %s", default_cpu, default_os);
  376. }
  377. }
  378. /* Figure out the BFD architecture to use.
  379. FIXME: specify the different 370 architectures. */
  380. enum bfd_architecture
  381. i370_arch (void)
  382. {
  383. return bfd_arch_i370;
  384. }
  385. /* This function is called when the assembler starts up. It is called
  386. after the options have been parsed and the output file has been
  387. opened. */
  388. void
  389. md_begin (void)
  390. {
  391. const struct i370_opcode *op;
  392. const struct i370_opcode *op_end;
  393. const struct i370_macro *macro;
  394. const struct i370_macro *macro_end;
  395. bfd_boolean dup_insn = FALSE;
  396. i370_set_cpu ();
  397. #ifdef OBJ_ELF
  398. /* Set the ELF flags if desired. */
  399. if (i370_flags)
  400. bfd_set_private_flags (stdoutput, i370_flags);
  401. #endif
  402. /* Insert the opcodes into a hash table. */
  403. i370_hash = hash_new ();
  404. op_end = i370_opcodes + i370_num_opcodes;
  405. for (op = i370_opcodes; op < op_end; op++)
  406. {
  407. know ((op->opcode.i[0] & op->mask.i[0]) == op->opcode.i[0]
  408. && (op->opcode.i[1] & op->mask.i[1]) == op->opcode.i[1]);
  409. if ((op->flags & i370_cpu) != 0)
  410. {
  411. const char *retval;
  412. retval = hash_insert (i370_hash, op->name, (void *) op);
  413. if (retval != (const char *) NULL)
  414. {
  415. as_bad (_("Internal assembler error for instruction %s"), op->name);
  416. dup_insn = TRUE;
  417. }
  418. }
  419. }
  420. /* Insert the macros into a hash table. */
  421. i370_macro_hash = hash_new ();
  422. macro_end = i370_macros + i370_num_macros;
  423. for (macro = i370_macros; macro < macro_end; macro++)
  424. {
  425. if ((macro->flags & i370_cpu) != 0)
  426. {
  427. const char *retval;
  428. retval = hash_insert (i370_macro_hash, macro->name, (void *) macro);
  429. if (retval != (const char *) NULL)
  430. {
  431. as_bad (_("Internal assembler error for macro %s"), macro->name);
  432. dup_insn = TRUE;
  433. }
  434. }
  435. }
  436. if (dup_insn)
  437. abort ();
  438. }
  439. /* Insert an operand value into an instruction. */
  440. static i370_insn_t
  441. i370_insert_operand (i370_insn_t insn,
  442. const struct i370_operand *operand,
  443. offsetT val)
  444. {
  445. if (operand->insert)
  446. {
  447. const char *errmsg;
  448. /* Used for 48-bit insn's. */
  449. errmsg = NULL;
  450. insn = (*operand->insert) (insn, (long) val, &errmsg);
  451. if (errmsg)
  452. as_bad ("%s", errmsg);
  453. }
  454. else
  455. /* This is used only for 16, 32 bit insn's. */
  456. insn.i[0] |= (((long) val & ((1 << operand->bits) - 1))
  457. << operand->shift);
  458. return insn;
  459. }
  460. #ifdef OBJ_ELF
  461. /* Parse @got, etc. and return the desired relocation.
  462. Currently, i370 does not support (don't really need to support) any
  463. of these fancier markups ... for example, no one is going to
  464. write 'L 6,=V(bogus)@got' it just doesn't make sense (at least to me).
  465. So basically, we could get away with this routine returning
  466. BFD_RELOC_UNUSED in all circumstances. However, I'll leave
  467. in for now in case someone ambitious finds a good use for this stuff ...
  468. this routine was pretty much just copied from the powerpc code ... */
  469. static bfd_reloc_code_real_type
  470. i370_elf_suffix (char **str_p, expressionS *exp_p)
  471. {
  472. struct map_bfd
  473. {
  474. char *string;
  475. int length;
  476. bfd_reloc_code_real_type reloc;
  477. };
  478. char ident[20];
  479. char *str = *str_p;
  480. char *str2;
  481. int ch;
  482. int len;
  483. struct map_bfd *ptr;
  484. #define MAP(str,reloc) { str, sizeof (str) - 1, reloc }
  485. static struct map_bfd mapping[] =
  486. {
  487. /* warnings with -mrelocatable. */
  488. MAP ("fixup", BFD_RELOC_CTOR),
  489. { (char *)0, 0, BFD_RELOC_UNUSED }
  490. };
  491. if (*str++ != '@')
  492. return BFD_RELOC_UNUSED;
  493. for (ch = *str, str2 = ident;
  494. (str2 < ident + sizeof (ident) - 1
  495. && (ISALNUM (ch) || ch == '@'));
  496. ch = *++str)
  497. *str2++ = TOLOWER (ch);
  498. *str2 = '\0';
  499. len = str2 - ident;
  500. ch = ident[0];
  501. for (ptr = &mapping[0]; ptr->length > 0; ptr++)
  502. if (ch == ptr->string[0]
  503. && len == ptr->length
  504. && memcmp (ident, ptr->string, ptr->length) == 0)
  505. {
  506. if (exp_p->X_add_number != 0
  507. && (ptr->reloc == BFD_RELOC_16_GOTOFF
  508. || ptr->reloc == BFD_RELOC_LO16_GOTOFF
  509. || ptr->reloc == BFD_RELOC_HI16_GOTOFF
  510. || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
  511. as_warn (_("identifier+constant@got means identifier@got+constant"));
  512. /* Now check for identifier@suffix+constant */
  513. if (*str == '-' || *str == '+')
  514. {
  515. char *orig_line = input_line_pointer;
  516. expressionS new_exp;
  517. input_line_pointer = str;
  518. expression (&new_exp);
  519. if (new_exp.X_op == O_constant)
  520. {
  521. exp_p->X_add_number += new_exp.X_add_number;
  522. str = input_line_pointer;
  523. }
  524. if (&input_line_pointer != str_p)
  525. input_line_pointer = orig_line;
  526. }
  527. *str_p = str;
  528. return ptr->reloc;
  529. }
  530. return BFD_RELOC_UNUSED;
  531. }
  532. /* Like normal .long/.short/.word, except support @got, etc.
  533. Clobbers input_line_pointer, checks end-of-line. */
  534. static void
  535. i370_elf_cons (int nbytes) /* 1=.byte, 2=.word, 4=.long. */
  536. {
  537. expressionS exp;
  538. bfd_reloc_code_real_type reloc;
  539. if (is_it_end_of_statement ())
  540. {
  541. demand_empty_rest_of_line ();
  542. return;
  543. }
  544. do
  545. {
  546. expression (&exp);
  547. if (exp.X_op == O_symbol
  548. && *input_line_pointer == '@'
  549. && (reloc = i370_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED)
  550. {
  551. reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
  552. int size = bfd_get_reloc_size (reloc_howto);
  553. if (size > nbytes)
  554. as_bad (_("%s relocations do not fit in %d bytes\n"),
  555. reloc_howto->name, nbytes);
  556. else
  557. {
  558. char *p = frag_more ((int) nbytes);
  559. int offset = nbytes - size;
  560. fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
  561. }
  562. }
  563. else
  564. emit_expr (&exp, (unsigned int) nbytes);
  565. }
  566. while (*input_line_pointer++ == ',');
  567. input_line_pointer--; /* Put terminator back into stream. */
  568. demand_empty_rest_of_line ();
  569. }
  570. /* ASCII to EBCDIC conversion table. */
  571. static unsigned char ascebc[256] =
  572. {
  573. /*00 NL SH SX EX ET NQ AK BL */
  574. 0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,
  575. /*08 BS HT LF VT FF CR SO SI */
  576. 0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  577. /*10 DL D1 D2 D3 D4 NK SN EB */
  578. 0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,
  579. /*18 CN EM SB EC FS GS RS US */
  580. 0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F,
  581. /*20 SP ! " # $ % & ' */
  582. 0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
  583. /*28 ( ) * + , - . / */
  584. 0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
  585. /*30 0 1 2 3 4 5 6 7 */
  586. 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
  587. /*38 8 9 : ; < = > ? */
  588. 0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
  589. /*40 @ A B C D E F G */
  590. 0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
  591. /*48 H I J K L M N O */
  592. 0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
  593. /*50 P Q R S T U V W */
  594. 0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
  595. /*58 X Y Z [ \ ] ^ _ */
  596. 0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,
  597. /*60 ` a b c d e f g */
  598. 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  599. /*68 h i j k l m n o */
  600. 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
  601. /*70 p q r s t u v w */
  602. 0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
  603. /*78 x y z { | } ~ DL */
  604. 0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07,
  605. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  606. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  607. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  608. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  609. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  610. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  611. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  612. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  613. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  614. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  615. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  616. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  617. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  618. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  619. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
  620. 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF
  621. };
  622. /* EBCDIC to ASCII conversion table. */
  623. unsigned char ebcasc[256] =
  624. {
  625. /*00 NU SH SX EX PF HT LC DL */
  626. 0x00, 0x01, 0x02, 0x03, 0x00, 0x09, 0x00, 0x7F,
  627. /*08 SM VT FF CR SO SI */
  628. 0x00, 0x00, 0x00, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  629. /*10 DE D1 D2 TM RS NL BS IL */
  630. 0x10, 0x11, 0x12, 0x13, 0x14, 0x0A, 0x08, 0x00,
  631. /*18 CN EM CC C1 FS GS RS US */
  632. 0x18, 0x19, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F,
  633. /*20 DS SS FS BP LF EB EC */
  634. 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x17, 0x1B,
  635. /*28 SM C2 EQ AK BL */
  636. 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00,
  637. /*30 SY PN RS UC ET */
  638. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  639. /*38 C3 D4 NK SU */
  640. 0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x00, 0x1A,
  641. /*40 SP */
  642. 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  643. /*48 . < ( + | */
  644. 0x00, 0x00, 0x00, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
  645. /*50 & */
  646. 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  647. /*58 ! $ * ) ; ^ */
  648. 0x00, 0x00, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
  649. /*60 - / */
  650. 0x2D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  651. /*68 , % _ > ? */
  652. 0x00, 0x00, 0x00, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
  653. /*70 */
  654. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  655. /*78 ` : # @ ' = " */
  656. 0x00, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
  657. /*80 a b c d e f g */
  658. 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
  659. /*88 h i { */
  660. 0x68, 0x69, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00,
  661. /*90 j k l m n o p */
  662. 0x00, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
  663. /*98 q r } */
  664. 0x71, 0x72, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00,
  665. /*A0 ~ s t u v w x */
  666. 0x00, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  667. /*A8 y z [ */
  668. 0x79, 0x7A, 0x00, 0x00, 0x00, 0x5B, 0x00, 0x00,
  669. /*B0 */
  670. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  671. /*B8 ] */
  672. 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00,
  673. /*C0 { A B C D E F G */
  674. 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  675. /*C8 H I */
  676. 0x48, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  677. /*D0 } J K L M N O P */
  678. 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
  679. /*D8 Q R */
  680. 0x51, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  681. /*E0 \ S T U V W X */
  682. 0x5C, 0x00, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  683. /*E8 Y Z */
  684. 0x59, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  685. /*F0 0 1 2 3 4 5 6 7 */
  686. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  687. /*F8 8 9 */
  688. 0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
  689. };
  690. /* EBCDIC translation tables needed for 3270 support. */
  691. static void
  692. i370_ebcdic (int unused ATTRIBUTE_UNUSED)
  693. {
  694. char *p, *end;
  695. char delim = 0;
  696. size_t nbytes;
  697. nbytes = strlen (input_line_pointer);
  698. end = input_line_pointer + nbytes;
  699. while ('\r' == *end) end --;
  700. while ('\n' == *end) end --;
  701. delim = *input_line_pointer;
  702. if (('\'' == delim) || ('\"' == delim))
  703. {
  704. input_line_pointer ++;
  705. end = rindex (input_line_pointer, delim);
  706. }
  707. if (end > input_line_pointer)
  708. {
  709. nbytes = end - input_line_pointer +1;
  710. p = frag_more (nbytes);
  711. while (end > input_line_pointer)
  712. {
  713. *p = ascebc [(unsigned char) (*input_line_pointer)];
  714. ++p; ++input_line_pointer;
  715. }
  716. *p = '\0';
  717. }
  718. if (delim == *input_line_pointer) ++input_line_pointer;
  719. }
  720. /* Stub out a couple of routines. */
  721. static void
  722. i370_rmode (int unused ATTRIBUTE_UNUSED)
  723. {
  724. as_tsktsk ("rmode ignored");
  725. }
  726. static void
  727. i370_dsect (int sect)
  728. {
  729. char *save_line = input_line_pointer;
  730. static char section[] = ".data\n";
  731. /* Just pretend this is .section .data. */
  732. input_line_pointer = section;
  733. obj_elf_section (sect);
  734. input_line_pointer = save_line;
  735. }
  736. static void
  737. i370_csect (int unused ATTRIBUTE_UNUSED)
  738. {
  739. as_tsktsk ("csect not supported");
  740. }
  741. /* DC Define Const is only partially supported.
  742. For samplecode on what to do, look at i370_elf_cons() above.
  743. This code handles pseudoops of the style
  744. DC D'3.141592653' # in sysv4, .double 3.14159265
  745. DC F'1' # in sysv4, .long 1. */
  746. static void
  747. i370_dc (int unused ATTRIBUTE_UNUSED)
  748. {
  749. char * p, tmp[50];
  750. int nbytes=0;
  751. expressionS exp;
  752. char type=0;
  753. char * clse;
  754. if (is_it_end_of_statement ())
  755. {
  756. demand_empty_rest_of_line ();
  757. return;
  758. }
  759. /* Figure out the size. */
  760. type = *input_line_pointer++;
  761. switch (type)
  762. {
  763. case 'H': /* 16-bit */
  764. nbytes = 2;
  765. break;
  766. case 'E': /* 32-bit */
  767. case 'F': /* 32-bit */
  768. nbytes = 4;
  769. break;
  770. case 'D': /* 64-bit */
  771. nbytes = 8;
  772. break;
  773. default:
  774. as_bad (_("unsupported DC type"));
  775. return;
  776. }
  777. /* Get rid of pesky quotes. */
  778. if ('\'' == *input_line_pointer)
  779. {
  780. ++input_line_pointer;
  781. clse = strchr (input_line_pointer, '\'');
  782. if (clse)
  783. *clse= ' ';
  784. else
  785. as_bad (_("missing end-quote"));
  786. }
  787. if ('\"' == *input_line_pointer)
  788. {
  789. ++input_line_pointer;
  790. clse = strchr (input_line_pointer, '\"');
  791. if (clse)
  792. *clse= ' ';
  793. else
  794. as_bad (_("missing end-quote"));
  795. }
  796. switch (type)
  797. {
  798. case 'H': /* 16-bit */
  799. case 'F': /* 32-bit */
  800. expression (&exp);
  801. emit_expr (&exp, nbytes);
  802. break;
  803. case 'E': /* 32-bit */
  804. type = 'f';
  805. case 'D': /* 64-bit */
  806. md_atof (type, tmp, &nbytes);
  807. p = frag_more (nbytes);
  808. memcpy (p, tmp, nbytes);
  809. break;
  810. default:
  811. as_bad (_("unsupported DC type"));
  812. return;
  813. }
  814. demand_empty_rest_of_line ();
  815. }
  816. /* Provide minimal support for DS Define Storage. */
  817. static void
  818. i370_ds (int unused ATTRIBUTE_UNUSED)
  819. {
  820. /* DS 0H or DS 0F or DS 0D. */
  821. if ('0' == *input_line_pointer)
  822. {
  823. int alignment = 0; /* Left shift 1 << align. */
  824. input_line_pointer ++;
  825. switch (*input_line_pointer++)
  826. {
  827. case 'H': /* 16-bit */
  828. alignment = 1;
  829. break;
  830. case 'F': /* 32-bit */
  831. alignment = 2;
  832. break;
  833. case 'D': /* 64-bit */
  834. alignment = 3;
  835. break;
  836. default:
  837. as_bad (_("unsupported alignment"));
  838. return;
  839. }
  840. frag_align (alignment, 0, 0);
  841. record_alignment (now_seg, alignment);
  842. }
  843. else
  844. as_bad (_("this DS form not yet supported"));
  845. }
  846. /* Solaris pseudo op to change to the .rodata section. */
  847. static void
  848. i370_elf_rdata (int sect)
  849. {
  850. char *save_line = input_line_pointer;
  851. static char section[] = ".rodata\n";
  852. /* Just pretend this is .section .rodata. */
  853. input_line_pointer = section;
  854. obj_elf_section (sect);
  855. input_line_pointer = save_line;
  856. }
  857. /* Pseudo op to make file scope bss items. */
  858. static void
  859. i370_elf_lcomm (int unused ATTRIBUTE_UNUSED)
  860. {
  861. char *name;
  862. char c;
  863. char *p;
  864. offsetT size;
  865. symbolS *symbolP;
  866. offsetT align;
  867. segT old_sec;
  868. int old_subsec;
  869. char *pfrag;
  870. int align2;
  871. c = get_symbol_name (&name);
  872. /* Just after name is now '\0'. */
  873. p = input_line_pointer;
  874. (void) restore_line_pointer (c);
  875. SKIP_WHITESPACE ();
  876. if (*input_line_pointer != ',')
  877. {
  878. as_bad (_("Expected comma after symbol-name: rest of line ignored."));
  879. ignore_rest_of_line ();
  880. return;
  881. }
  882. /* Skip ','. */
  883. input_line_pointer++;
  884. if ((size = get_absolute_expression ()) < 0)
  885. {
  886. as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
  887. ignore_rest_of_line ();
  888. return;
  889. }
  890. /* The third argument to .lcomm is the alignment. */
  891. if (*input_line_pointer != ',')
  892. align = 8;
  893. else
  894. {
  895. ++input_line_pointer;
  896. align = get_absolute_expression ();
  897. if (align <= 0)
  898. {
  899. as_warn (_("ignoring bad alignment"));
  900. align = 8;
  901. }
  902. }
  903. *p = 0;
  904. symbolP = symbol_find_or_make (name);
  905. *p = c;
  906. if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
  907. {
  908. as_bad (_("Ignoring attempt to re-define symbol `%s'."),
  909. S_GET_NAME (symbolP));
  910. ignore_rest_of_line ();
  911. return;
  912. }
  913. if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
  914. {
  915. as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
  916. S_GET_NAME (symbolP),
  917. (long) S_GET_VALUE (symbolP),
  918. (long) size);
  919. ignore_rest_of_line ();
  920. return;
  921. }
  922. /* Allocate_bss: */
  923. old_sec = now_seg;
  924. old_subsec = now_subseg;
  925. if (align)
  926. {
  927. /* Convert to a power of 2 alignment. */
  928. for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2)
  929. ;
  930. if (align != 1)
  931. {
  932. as_bad (_("Common alignment not a power of 2"));
  933. ignore_rest_of_line ();
  934. return;
  935. }
  936. }
  937. else
  938. align2 = 0;
  939. record_alignment (bss_section, align2);
  940. subseg_set (bss_section, 0);
  941. if (align2)
  942. frag_align (align2, 0, 0);
  943. if (S_GET_SEGMENT (symbolP) == bss_section)
  944. symbol_get_frag (symbolP)->fr_symbol = 0;
  945. symbol_set_frag (symbolP, frag_now);
  946. pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
  947. (char *) 0);
  948. *pfrag = 0;
  949. S_SET_SIZE (symbolP, size);
  950. S_SET_SEGMENT (symbolP, bss_section);
  951. subseg_set (old_sec, old_subsec);
  952. demand_empty_rest_of_line ();
  953. }
  954. /* Validate any relocations emitted for -mrelocatable, possibly adding
  955. fixups for word relocations in writable segments, so we can adjust
  956. them at runtime. */
  957. static void
  958. i370_elf_validate_fix (fixS *fixp, segT seg)
  959. {
  960. if (fixp->fx_done || fixp->fx_pcrel)
  961. return;
  962. switch (shlib)
  963. {
  964. case SHLIB_NONE:
  965. case SHLIB_PIC:
  966. return;
  967. case SHILB_MRELOCATABLE:
  968. if (fixp->fx_r_type <= BFD_RELOC_UNUSED
  969. && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
  970. && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
  971. && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
  972. && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
  973. && fixp->fx_r_type != BFD_RELOC_32_BASEREL
  974. && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
  975. && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
  976. && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
  977. && strcmp (segment_name (seg), ".got2") != 0
  978. && strcmp (segment_name (seg), ".dtors") != 0
  979. && strcmp (segment_name (seg), ".ctors") != 0
  980. && strcmp (segment_name (seg), ".fixup") != 0
  981. && strcmp (segment_name (seg), ".stab") != 0
  982. && strcmp (segment_name (seg), ".gcc_except_table") != 0
  983. && strcmp (segment_name (seg), ".ex_shared") != 0)
  984. {
  985. if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
  986. || fixp->fx_r_type != BFD_RELOC_CTOR)
  987. as_bad_where (fixp->fx_file, fixp->fx_line,
  988. "Relocation cannot be done when using -mrelocatable");
  989. }
  990. return;
  991. default:
  992. break;
  993. }
  994. }
  995. #endif /* OBJ_ELF */
  996. #define LITERAL_POOL_SUPPORT
  997. #ifdef LITERAL_POOL_SUPPORT
  998. /* Provide support for literal pools within the text section.
  999. Loosely based on similar code from tc-arm.c.
  1000. We will use four symbols to locate four parts of the literal pool.
  1001. These four sections contain 64,32,16 and 8-bit constants; we use
  1002. four sections so that all memory access can be appropriately aligned.
  1003. That is, we want to avoid mixing these together so that we don't
  1004. waste space padding out to alignments. The four pointers
  1005. longlong_poolP, word_poolP, etc. point to a symbol labeling the
  1006. start of each pool part.
  1007. lit_pool_num increments from zero to infinity and uniquely id's
  1008. -- its used to generate the *_poolP symbol name. */
  1009. #define MAX_LITERAL_POOL_SIZE 1024
  1010. typedef struct literalS
  1011. {
  1012. struct expressionS exp;
  1013. char * sym_name;
  1014. char size; /* 1,2,4 or 8 */
  1015. short offset;
  1016. } literalT;
  1017. literalT literals[MAX_LITERAL_POOL_SIZE];
  1018. int next_literal_pool_place = 0; /* Next free entry in the pool. */
  1019. static symbolS *longlong_poolP = NULL; /* 64-bit pool entries. */
  1020. static symbolS *word_poolP = NULL; /* 32-bit pool entries. */
  1021. static symbolS *short_poolP = NULL; /* 16-bit pool entries. */
  1022. static symbolS *byte_poolP = NULL; /* 8-bit pool entries. */
  1023. static int lit_pool_num = 1;
  1024. /* Create a new, empty symbol. */
  1025. static symbolS *
  1026. symbol_make_empty (void)
  1027. {
  1028. return symbol_create (FAKE_LABEL_NAME, undefined_section,
  1029. (valueT) 0, &zero_address_frag);
  1030. }
  1031. /* Make the first argument an address-relative expression
  1032. by subtracting the second argument. */
  1033. static void
  1034. i370_make_relative (expressionS *exx, expressionS *baseaddr)
  1035. {
  1036. if (O_constant == baseaddr->X_op)
  1037. {
  1038. exx->X_op = O_symbol;
  1039. exx->X_add_number -= baseaddr->X_add_number;
  1040. }
  1041. else if (O_symbol == baseaddr->X_op)
  1042. {
  1043. exx->X_op = O_subtract;
  1044. exx->X_op_symbol = baseaddr->X_add_symbol;
  1045. exx->X_add_number -= baseaddr->X_add_number;
  1046. }
  1047. else if (O_uminus == baseaddr->X_op)
  1048. {
  1049. exx->X_op = O_add;
  1050. exx->X_op_symbol = baseaddr->X_add_symbol;
  1051. exx->X_add_number += baseaddr->X_add_number;
  1052. }
  1053. else
  1054. as_bad (_("Missing or bad .using directive"));
  1055. }
  1056. /* Add an expression to the literal pool. */
  1057. static void
  1058. add_to_lit_pool (expressionS *exx, char *name, int sz)
  1059. {
  1060. int lit_count = 0;
  1061. int offset_in_pool = 0;
  1062. /* Start a new pool, if necessary. */
  1063. if (8 == sz && NULL == longlong_poolP)
  1064. longlong_poolP = symbol_make_empty ();
  1065. else if (4 == sz && NULL == word_poolP)
  1066. word_poolP = symbol_make_empty ();
  1067. else if (2 == sz && NULL == short_poolP)
  1068. short_poolP = symbol_make_empty ();
  1069. else if (1 == sz && NULL == byte_poolP)
  1070. byte_poolP = symbol_make_empty ();
  1071. /* Check if this literal value is already in the pool.
  1072. FIXME: We should probably be checking expressions
  1073. of type O_symbol as well.
  1074. FIXME: This is probably(certainly?) broken for O_big,
  1075. which includes 64-bit long-longs. */
  1076. while (lit_count < next_literal_pool_place)
  1077. {
  1078. if (exx->X_op == O_constant
  1079. && literals[lit_count].exp.X_op == exx->X_op
  1080. && literals[lit_count].exp.X_add_number == exx->X_add_number
  1081. && literals[lit_count].exp.X_unsigned == exx->X_unsigned
  1082. && literals[lit_count].size == sz)
  1083. break;
  1084. else if (literals[lit_count].sym_name
  1085. && name
  1086. && !strcmp (name, literals[lit_count].sym_name))
  1087. break;
  1088. if (sz == literals[lit_count].size)
  1089. offset_in_pool += sz;
  1090. lit_count ++;
  1091. }
  1092. if (lit_count == next_literal_pool_place) /* new entry */
  1093. {
  1094. if (next_literal_pool_place > MAX_LITERAL_POOL_SIZE)
  1095. as_bad (_("Literal Pool Overflow"));
  1096. literals[next_literal_pool_place].exp = *exx;
  1097. literals[next_literal_pool_place].size = sz;
  1098. literals[next_literal_pool_place].offset = offset_in_pool;
  1099. if (name)
  1100. literals[next_literal_pool_place].sym_name = strdup (name);
  1101. else
  1102. literals[next_literal_pool_place].sym_name = NULL;
  1103. next_literal_pool_place++;
  1104. }
  1105. /* ???_poolP points to the beginning of the literal pool.
  1106. X_add_number is the offset from the beginning of the
  1107. literal pool to this expr minus the location of the most
  1108. recent .using directive. Thus, the grand total value of the
  1109. expression is the distance from .using to the literal. */
  1110. if (8 == sz)
  1111. exx->X_add_symbol = longlong_poolP;
  1112. else if (4 == sz)
  1113. exx->X_add_symbol = word_poolP;
  1114. else if (2 == sz)
  1115. exx->X_add_symbol = short_poolP;
  1116. else if (1 == sz)
  1117. exx->X_add_symbol = byte_poolP;
  1118. exx->X_add_number = offset_in_pool;
  1119. exx->X_op_symbol = NULL;
  1120. /* If the user has set up a base reg in another section,
  1121. use that; otherwise use the text section. */
  1122. if (0 < i370_using_other_regno)
  1123. i370_make_relative (exx, &i370_using_other_baseaddr);
  1124. else
  1125. i370_make_relative (exx, &i370_using_text_baseaddr);
  1126. }
  1127. /* The symbol setup for the literal pool is done in two steps. First,
  1128. a symbol that represents the start of the literal pool is created,
  1129. above, in the add_to_pool() routine. This sym ???_poolP.
  1130. However, we don't know what fragment its in until a bit later.
  1131. So we defer the frag_now thing, and the symbol name, until .ltorg time. */
  1132. /* Can't use symbol_new here, so have to create a symbol and then at
  1133. a later date assign it a value. Thats what these functions do. */
  1134. static void
  1135. symbol_locate (symbolS *symbolP,
  1136. const char *name, /* It is copied, the caller can modify. */
  1137. segT segment, /* Segment identifier (SEG_<something>). */
  1138. valueT valu, /* Symbol value. */
  1139. fragS *frag) /* Associated fragment. */
  1140. {
  1141. size_t name_length;
  1142. char *preserved_copy_of_name;
  1143. name_length = strlen (name) + 1; /* +1 for \0 */
  1144. obstack_grow (&notes, name, name_length);
  1145. preserved_copy_of_name = obstack_finish (&notes);
  1146. S_SET_NAME (symbolP, preserved_copy_of_name);
  1147. S_SET_SEGMENT (symbolP, segment);
  1148. S_SET_VALUE (symbolP, valu);
  1149. symbol_clear_list_pointers (symbolP);
  1150. symbol_set_frag (symbolP, frag);
  1151. /* Link to end of symbol chain. */
  1152. {
  1153. extern int symbol_table_frozen;
  1154. if (symbol_table_frozen)
  1155. abort ();
  1156. }
  1157. symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
  1158. obj_symbol_new_hook (symbolP);
  1159. #ifdef tc_symbol_new_hook
  1160. tc_symbol_new_hook (symbolP);
  1161. #endif
  1162. #define DEBUG_SYMS
  1163. #ifdef DEBUG_SYMS
  1164. verify_symbol_chain(symbol_rootP, symbol_lastP);
  1165. #endif /* DEBUG_SYMS */
  1166. }
  1167. /* i370_addr_offset() will convert operand expressions
  1168. that appear to be absolute into thier base-register
  1169. relative form. These expressions come in two types:
  1170. (1) of the form "* + const" * where "*" means
  1171. relative offset since the last using
  1172. i.e. "*" means ".-using_baseaddr"
  1173. (2) labels, which are never absolute, but are always
  1174. relative to the last "using". Anything with an alpha
  1175. character is considered to be a label (since symbols
  1176. can never be operands), and since we've already handled
  1177. register operands. For example, "BL .L33" branch low
  1178. to .L33 RX form insn frequently terminates for-loops. */
  1179. static bfd_boolean
  1180. i370_addr_offset (expressionS *exx)
  1181. {
  1182. char *dot, *lab;
  1183. int islabel = 0;
  1184. int all_digits = 0;
  1185. /* Search for a label; anything with an alpha char will do.
  1186. Local labels consist of N digits followed by either b or f. */
  1187. lab = input_line_pointer;
  1188. while (*lab && (',' != *lab) && ('(' != *lab))
  1189. {
  1190. if (ISDIGIT (*lab))
  1191. all_digits = 1;
  1192. else if (ISALPHA (*lab))
  1193. {
  1194. if (!all_digits)
  1195. {
  1196. islabel = 1;
  1197. break;
  1198. }
  1199. else if (('f' == *lab) || ('b' == *lab))
  1200. {
  1201. islabel = 1;
  1202. break;
  1203. }
  1204. if (all_digits)
  1205. break;
  1206. }
  1207. else if ('.' != *lab)
  1208. break;
  1209. ++lab;
  1210. }
  1211. /* See if operand has a * in it. */
  1212. dot = strchr (input_line_pointer, '*');
  1213. if (!dot && !islabel)
  1214. return FALSE;
  1215. /* Replace * with . and let expr munch on it. */
  1216. if (dot)
  1217. *dot = '.';
  1218. expression (exx);
  1219. /* OK, now we have to subtract the "using" location.
  1220. Normally branches appear in the text section only. */
  1221. if (0 == strncmp (now_seg->name, ".text", 5) || 0 > i370_using_other_regno)
  1222. i370_make_relative (exx, &i370_using_text_baseaddr);
  1223. else
  1224. i370_make_relative (exx, &i370_using_other_baseaddr);
  1225. /* Put the * back. */
  1226. if (dot)
  1227. *dot = '*';
  1228. return TRUE;
  1229. }
  1230. /* Handle address constants of various sorts. */
  1231. /* The currently supported types are
  1232. =A(some_symb)
  1233. =V(some_extern)
  1234. =X'deadbeef' hexadecimal
  1235. =F'1234' 32-bit const int
  1236. =H'1234' 16-bit const int. */
  1237. static bfd_boolean
  1238. i370_addr_cons (expressionS *exp)
  1239. {
  1240. char *name;
  1241. char *sym_name, delim;
  1242. int name_len;
  1243. int hex_len = 0;
  1244. int cons_len = 0;
  1245. name = input_line_pointer;
  1246. sym_name = input_line_pointer;
  1247. /* Find the spelling of the operand. */
  1248. if (name[0] == '=' && ISALPHA (name[1]))
  1249. name = ++input_line_pointer;
  1250. else
  1251. return FALSE;
  1252. switch (name[0])
  1253. {
  1254. case 'A': /* A == address-of. */
  1255. case 'V': /* V == extern. */
  1256. ++input_line_pointer;
  1257. expression (exp);
  1258. /* We use a simple string name to collapse together
  1259. multiple refrences to the same address literal. */
  1260. name_len = strcspn (sym_name, ", ");
  1261. delim = *(sym_name + name_len);
  1262. *(sym_name + name_len) = 0x0;
  1263. add_to_lit_pool (exp, sym_name, 4);
  1264. *(sym_name + name_len) = delim;
  1265. break;
  1266. case 'H':
  1267. case 'F':
  1268. case 'X':
  1269. case 'E': /* Single-precision float point. */
  1270. case 'D': /* Double-precision float point. */
  1271. /* H == 16-bit fixed-point const; expression must be const. */
  1272. /* F == fixed-point const; expression must be const. */
  1273. /* X == fixed-point const; expression must be const. */
  1274. if ('H' == name[0]) cons_len = 2;
  1275. else if ('F' == name[0]) cons_len = 4;
  1276. else if ('X' == name[0]) cons_len = -1;
  1277. else if ('E' == name[0]) cons_len = 4;
  1278. else if ('D' == name[0]) cons_len = 8;
  1279. /* Extract length, if it is present;
  1280. FIXME: assume single-digit length. */
  1281. if ('L' == name[1])
  1282. {
  1283. /* Should work for ASCII and EBCDIC. */
  1284. cons_len = name[2] - '0';
  1285. input_line_pointer += 2;
  1286. }
  1287. ++input_line_pointer;
  1288. /* Get rid of pesky quotes. */
  1289. if ('\'' == *input_line_pointer)
  1290. {
  1291. char * clse;
  1292. ++input_line_pointer;
  1293. clse = strchr (input_line_pointer, '\'');
  1294. if (clse)
  1295. *clse= ' ';
  1296. else
  1297. as_bad (_("missing end-quote"));
  1298. }
  1299. if ('\"' == *input_line_pointer)
  1300. {
  1301. char * clse;
  1302. ++input_line_pointer;
  1303. clse = strchr (input_line_pointer, '\"');
  1304. if (clse)
  1305. *clse= ' ';
  1306. else
  1307. as_bad (_("missing end-quote"));
  1308. }
  1309. if (('X' == name[0]) || ('E' == name[0]) || ('D' == name[0]))
  1310. {
  1311. char tmp[50];
  1312. char *save;
  1313. /* The length of hex constants is specified directly with L,
  1314. or implied through the number of hex digits. For example:
  1315. =X'AB' one byte
  1316. =X'abcd' two bytes
  1317. =X'000000AB' four bytes
  1318. =XL4'AB' four bytes, left-padded withn zero. */
  1319. if (('X' == name[0]) && (0 > cons_len))
  1320. {
  1321. save = input_line_pointer;
  1322. while (*save)
  1323. {
  1324. if (ISXDIGIT (*save))
  1325. hex_len++;
  1326. save++;
  1327. }
  1328. cons_len = (hex_len+1) /2;
  1329. }
  1330. /* I believe this works even for =XL8'dada0000beeebaaa'
  1331. which should parse out to X_op == O_big
  1332. Note that floats and doubles get represented as
  1333. 0d3.14159265358979 or 0f 2.7. */
  1334. tmp[0] = '0';
  1335. tmp[1] = name[0];
  1336. tmp[2] = 0;
  1337. strcat (tmp, input_line_pointer);
  1338. save = input_line_pointer;
  1339. input_line_pointer = tmp;
  1340. expression (exp);
  1341. input_line_pointer = save + (input_line_pointer-tmp-2);
  1342. /* Fix up lengths for floats and doubles. */
  1343. if (O_big == exp->X_op)
  1344. exp->X_add_number = cons_len / CHARS_PER_LITTLENUM;
  1345. }
  1346. else
  1347. expression (exp);
  1348. /* O_big occurs when more than 4 bytes worth gets parsed. */
  1349. if ((exp->X_op != O_constant) && (exp->X_op != O_big))
  1350. {
  1351. as_bad (_("expression not a constant"));
  1352. return FALSE;
  1353. }
  1354. add_to_lit_pool (exp, 0x0, cons_len);
  1355. break;
  1356. default:
  1357. as_bad (_("Unknown/unsupported address literal type"));
  1358. return FALSE;
  1359. }
  1360. return TRUE;
  1361. }
  1362. /* Dump the contents of the literal pool that we've accumulated so far.
  1363. This aligns the pool to the size of the largest literal in the pool. */
  1364. static void
  1365. i370_ltorg (int ignore ATTRIBUTE_UNUSED)
  1366. {
  1367. int litsize;
  1368. int lit_count = 0;
  1369. int biggest_literal_size = 0;
  1370. int biggest_align = 0;
  1371. char pool_name[20];
  1372. if (strncmp (now_seg->name, ".text", 5))
  1373. {
  1374. if (i370_other_section == undefined_section)
  1375. as_bad (_(".ltorg without prior .using in section %s"),
  1376. now_seg->name);
  1377. if (i370_other_section != now_seg)
  1378. as_bad (_(".ltorg in section %s paired to .using in section %s"),
  1379. now_seg->name, i370_other_section->name);
  1380. }
  1381. if (! longlong_poolP
  1382. && ! word_poolP
  1383. && ! short_poolP
  1384. && ! byte_poolP)
  1385. /* Nothing to do. */
  1386. return;
  1387. /* Find largest literal .. 2 4 or 8. */
  1388. lit_count = 0;
  1389. while (lit_count < next_literal_pool_place)
  1390. {
  1391. if (biggest_literal_size < literals[lit_count].size)
  1392. biggest_literal_size = literals[lit_count].size;
  1393. lit_count ++;
  1394. }
  1395. if (1 == biggest_literal_size) biggest_align = 0;
  1396. else if (2 == biggest_literal_size) biggest_align = 1;
  1397. else if (4 == biggest_literal_size) biggest_align = 2;
  1398. else if (8 == biggest_literal_size) biggest_align = 3;
  1399. else as_bad (_("bad alignment of %d bytes in literal pool"), biggest_literal_size);
  1400. if (0 == biggest_align) biggest_align = 1;
  1401. /* Align pool for short, word, double word accesses. */
  1402. frag_align (biggest_align, 0, 0);
  1403. record_alignment (now_seg, biggest_align);
  1404. /* Note that the gas listing will print only the first five
  1405. entries in the pool .... wonder how to make it print more. */
  1406. /* Output largest literals first, then the smaller ones. */
  1407. for (litsize=8; litsize; litsize /=2)
  1408. {
  1409. symbolS *current_poolP = NULL;
  1410. switch (litsize)
  1411. {
  1412. case 8:
  1413. current_poolP = longlong_poolP; break;
  1414. case 4:
  1415. current_poolP = word_poolP; break;
  1416. case 2:
  1417. current_poolP = short_poolP; break;
  1418. case 1:
  1419. current_poolP = byte_poolP; break;
  1420. default:
  1421. as_bad (_("bad literal size\n"));
  1422. }
  1423. if (NULL == current_poolP)
  1424. continue;
  1425. sprintf (pool_name, ".LITP%01d%06d", litsize, lit_pool_num);
  1426. symbol_locate (current_poolP, pool_name, now_seg,
  1427. (valueT) frag_now_fix (), frag_now);
  1428. symbol_table_insert (current_poolP);
  1429. lit_count = 0;
  1430. while (lit_count < next_literal_pool_place)
  1431. {
  1432. if (litsize == literals[lit_count].size)
  1433. {
  1434. #define EMIT_ADDR_CONS_SYMBOLS
  1435. #ifdef EMIT_ADDR_CONS_SYMBOLS
  1436. /* Create a bogus symbol, add it to the pool ...
  1437. For the most part, I think this is a useless exercise,
  1438. except that having these symbol names in the objects
  1439. is vaguely useful for debugging. */
  1440. if (literals[lit_count].sym_name)
  1441. {
  1442. symbolS * symP = symbol_make_empty ();
  1443. symbol_locate (symP, literals[lit_count].sym_name, now_seg,
  1444. (valueT) frag_now_fix (), frag_now);
  1445. symbol_table_insert (symP);
  1446. }
  1447. #endif /* EMIT_ADDR_CONS_SYMBOLS */
  1448. emit_expr (&(literals[lit_count].exp), literals[lit_count].size);
  1449. }
  1450. lit_count ++;
  1451. }
  1452. }
  1453. next_literal_pool_place = 0;
  1454. longlong_poolP = NULL;
  1455. word_poolP = NULL;
  1456. short_poolP = NULL;
  1457. byte_poolP = NULL;
  1458. lit_pool_num++;
  1459. }
  1460. #endif /* LITERAL_POOL_SUPPORT */
  1461. /* Add support for the HLASM-like USING directive to indicate
  1462. the base register to use ... we don't support the full
  1463. hlasm semantics for this ... we merely pluck a base address
  1464. and a register number out. We print a warning if using is
  1465. called multiple times. I suppose we should check to see
  1466. if the regno is valid. */
  1467. static void
  1468. i370_using (int ignore ATTRIBUTE_UNUSED)
  1469. {
  1470. expressionS ex, baseaddr;
  1471. int iregno;
  1472. char *star;
  1473. /* If "*" appears in a using, it means "."
  1474. replace it with "." so that expr doesn't get confused. */
  1475. star = strchr (input_line_pointer, '*');
  1476. if (star)
  1477. *star = '.';
  1478. /* The first arg to using will usually be ".", but it can
  1479. be a more complex expression too. */
  1480. expression (&baseaddr);
  1481. if (star)
  1482. *star = '*';
  1483. if (O_constant != baseaddr.X_op
  1484. && O_symbol != baseaddr.X_op
  1485. && O_uminus != baseaddr.X_op)
  1486. as_bad (_(".using: base address expression illegal or too complex"));
  1487. if (*input_line_pointer != '\0') ++input_line_pointer;
  1488. /* The second arg to using had better be a register. */
  1489. register_name (&ex);
  1490. demand_empty_rest_of_line ();
  1491. iregno = ex.X_add_number;
  1492. if (0 == strncmp (now_seg->name, ".text", 5))
  1493. {
  1494. i370_using_text_baseaddr = baseaddr;
  1495. i370_using_text_regno = iregno;
  1496. }
  1497. else
  1498. {
  1499. i370_using_other_baseaddr = baseaddr;
  1500. i370_using_other_regno = iregno;
  1501. i370_other_section = now_seg;
  1502. }
  1503. }
  1504. static void
  1505. i370_drop (int ignore ATTRIBUTE_UNUSED)
  1506. {
  1507. expressionS ex;
  1508. int iregno;
  1509. register_name (&ex);
  1510. demand_empty_rest_of_line ();
  1511. iregno = ex.X_add_number;
  1512. if (0 == strncmp (now_seg->name, ".text", 5))
  1513. {
  1514. if (iregno != i370_using_text_regno)
  1515. as_bad (_("droping register %d in section %s does not match using register %d"),
  1516. iregno, now_seg->name, i370_using_text_regno);
  1517. i370_using_text_regno = -1;
  1518. i370_using_text_baseaddr.X_op = O_absent;
  1519. }
  1520. else
  1521. {
  1522. if (iregno != i370_using_other_regno)
  1523. as_bad (_("droping register %d in section %s does not match using register %d"),
  1524. iregno, now_seg->name, i370_using_other_regno);
  1525. if (i370_other_section != now_seg)
  1526. as_bad (_("droping register %d in section %s previously used in section %s"),
  1527. iregno, now_seg->name, i370_other_section->name);
  1528. i370_using_other_regno = -1;
  1529. i370_using_other_baseaddr.X_op = O_absent;
  1530. i370_other_section = undefined_section;
  1531. }
  1532. }
  1533. /* We need to keep a list of fixups. We can't simply generate them as
  1534. we go, because that would require us to first create the frag, and
  1535. that would screw up references to ``.''. */
  1536. struct i370_fixup
  1537. {
  1538. expressionS exp;
  1539. int opindex;
  1540. bfd_reloc_code_real_type reloc;
  1541. };
  1542. #define MAX_INSN_FIXUPS 5
  1543. /* Handle a macro. Gather all the operands, transform them as
  1544. described by the macro, and call md_assemble recursively. All the
  1545. operands are separated by commas; we don't accept parentheses
  1546. around operands here. */
  1547. static void
  1548. i370_macro (char *str, const struct i370_macro *macro)
  1549. {
  1550. char *operands[10];
  1551. unsigned int count;
  1552. char *s;
  1553. unsigned int len;
  1554. const char *format;
  1555. int arg;
  1556. char *send;
  1557. char *complete;
  1558. /* Gather the users operands into the operands array. */
  1559. count = 0;
  1560. s = str;
  1561. while (1)
  1562. {
  1563. if (count >= sizeof operands / sizeof operands[0])
  1564. break;
  1565. operands[count++] = s;
  1566. s = strchr (s, ',');
  1567. if (s == (char *) NULL)
  1568. break;
  1569. *s++ = '\0';
  1570. }
  1571. if (count != macro->operands)
  1572. {
  1573. as_bad (_("wrong number of operands"));
  1574. return;
  1575. }
  1576. /* Work out how large the string must be (the size is unbounded
  1577. because it includes user input). */
  1578. len = 0;
  1579. format = macro->format;
  1580. while (*format != '\0')
  1581. {
  1582. if (*format != '%')
  1583. {
  1584. ++len;
  1585. ++format;
  1586. }
  1587. else
  1588. {
  1589. arg = strtol (format + 1, &send, 10);
  1590. know (send != format && arg >= 0 && (unsigned) arg < count);
  1591. len += strlen (operands[arg]);
  1592. format = send;
  1593. }
  1594. }
  1595. /* Put the string together. */
  1596. complete = s = alloca (len + 1);
  1597. format = macro->format;
  1598. while (*format != '\0')
  1599. {
  1600. if (*format != '%')
  1601. *s++ = *format++;
  1602. else
  1603. {
  1604. arg = strtol (format + 1, &send, 10);
  1605. strcpy (s, operands[arg]);
  1606. s += strlen (s);
  1607. format = send;
  1608. }
  1609. }
  1610. *s = '\0';
  1611. /* Assemble the constructed instruction. */
  1612. md_assemble (complete);
  1613. }
  1614. /* This routine is called for each instruction to be assembled. */
  1615. void
  1616. md_assemble (char *str)
  1617. {
  1618. char *s;
  1619. const struct i370_opcode *opcode;
  1620. i370_insn_t insn;
  1621. const unsigned char *opindex_ptr;
  1622. int have_optional_index, have_optional_basereg, have_optional_reg;
  1623. int skip_optional_index, skip_optional_basereg, skip_optional_reg;
  1624. int use_text=0, use_other=0;
  1625. int off_by_one;
  1626. struct i370_fixup fixups[MAX_INSN_FIXUPS];
  1627. int fc;
  1628. char *f;
  1629. int i;
  1630. #ifdef OBJ_ELF
  1631. bfd_reloc_code_real_type reloc;
  1632. #endif
  1633. /* Get the opcode. */
  1634. for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
  1635. ;
  1636. if (*s != '\0')
  1637. *s++ = '\0';
  1638. /* Look up the opcode in the hash table. */
  1639. opcode = (const struct i370_opcode *) hash_find (i370_hash, str);
  1640. if (opcode == (const struct i370_opcode *) NULL)
  1641. {
  1642. const struct i370_macro *macro;
  1643. gas_assert (i370_macro_hash);
  1644. macro = (const struct i370_macro *) hash_find (i370_macro_hash, str);
  1645. if (macro == (const struct i370_macro *) NULL)
  1646. as_bad (_("Unrecognized opcode: `%s'"), str);
  1647. else
  1648. i370_macro (s, macro);
  1649. return;
  1650. }
  1651. insn = opcode->opcode;
  1652. str = s;
  1653. while (ISSPACE (*str))
  1654. ++str;
  1655. /* I370 operands are either expressions or address constants.
  1656. Many operand types are optional. The optional operands
  1657. are always surrounded by parens, and are used to denote the base
  1658. register ... e.g. "A R1, D2" or "A R1, D2(,B2) as opposed to
  1659. the fully-formed "A R1, D2(X2,B2)". Note also the = sign,
  1660. such as A R1,=A(i) where the address-of operator =A implies
  1661. use of both a base register, and a missing index register.
  1662. So, before we start seriously parsing the operands, we check
  1663. to see if we have an optional operand, and, if we do, we count
  1664. the number of commas to see which operand should be omitted. */
  1665. have_optional_index = have_optional_basereg = have_optional_reg = 0;
  1666. for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
  1667. {
  1668. const struct i370_operand *operand;
  1669. operand = &i370_operands[*opindex_ptr];
  1670. if ((operand->flags & I370_OPERAND_INDEX) != 0)
  1671. have_optional_index = 1;
  1672. if ((operand->flags & I370_OPERAND_BASE) != 0)
  1673. have_optional_basereg = 1;
  1674. if ((operand->flags & I370_OPERAND_OPTIONAL) != 0)
  1675. have_optional_reg = 1;
  1676. }
  1677. skip_optional_index = skip_optional_basereg = skip_optional_reg = 0;
  1678. if (have_optional_index || have_optional_basereg)
  1679. {
  1680. unsigned int opcount, nwanted;
  1681. /* There is an optional operand. Count the number of
  1682. commas and open-parens in the input line. */
  1683. if (*str == '\0')
  1684. opcount = 0;
  1685. else
  1686. {
  1687. opcount = 1;
  1688. s = str;
  1689. while ((s = strpbrk (s, ",(=")) != (char *) NULL)
  1690. {
  1691. ++opcount;
  1692. ++s;
  1693. if (',' == *s) ++s; /* avoid counting things like (, */
  1694. if ('=' == *s) { ++s; --opcount; }
  1695. }
  1696. }
  1697. /* If there are fewer operands in the line then are called
  1698. for by the instruction, we want to skip the optional
  1699. operand. */
  1700. nwanted = strlen ((char *) opcode->operands);
  1701. if (have_optional_index)
  1702. {
  1703. if (opcount < nwanted)
  1704. skip_optional_index = 1;
  1705. if (have_optional_basereg && ((opcount+1) < nwanted))
  1706. skip_optional_basereg = 1;
  1707. if (have_optional_reg && ((opcount+1) < nwanted))
  1708. skip_optional_reg = 1;
  1709. }
  1710. else
  1711. {
  1712. if (have_optional_basereg && (opcount < nwanted))
  1713. skip_optional_basereg = 1;
  1714. if (have_optional_reg && (opcount < nwanted))
  1715. skip_optional_reg = 1;
  1716. }
  1717. }
  1718. /* Perform some off-by-one hacks on the length field of certain instructions.
  1719. Its such a shame to have to do this, but the problem is that HLASM got
  1720. defined so that the lengths differ by one from the actual machine instructions.
  1721. this code should probably be moved to a special inster-operand routine.
  1722. Sigh. Affected instructions are Compare Logical, Move and Exclusive OR
  1723. hack alert -- aren't *all* SS instructions affected ?? */
  1724. off_by_one = 0;
  1725. if (0 == strcasecmp ("CLC", opcode->name)
  1726. || 0 == strcasecmp ("ED", opcode->name)
  1727. || 0 == strcasecmp ("EDMK", opcode->name)
  1728. || 0 == strcasecmp ("MVC", opcode->name)
  1729. || 0 == strcasecmp ("MVCIN", opcode->name)
  1730. || 0 == strcasecmp ("MVN", opcode->name)
  1731. || 0 == strcasecmp ("MVZ", opcode->name)
  1732. || 0 == strcasecmp ("NC", opcode->name)
  1733. || 0 == strcasecmp ("OC", opcode->name)
  1734. || 0 == strcasecmp ("XC", opcode->name))
  1735. off_by_one = 1;
  1736. /* Gather the operands. */
  1737. fc = 0;
  1738. for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
  1739. {
  1740. const struct i370_operand *operand;
  1741. char *hold;
  1742. expressionS ex;
  1743. operand = &i370_operands[*opindex_ptr];
  1744. /* If this is an index operand, and we are skipping it,
  1745. just insert a zero. */
  1746. if (skip_optional_index &&
  1747. ((operand->flags & I370_OPERAND_INDEX) != 0))
  1748. {
  1749. insn = i370_insert_operand (insn, operand, 0);
  1750. continue;
  1751. }
  1752. /* If this is the base operand, and we are skipping it,
  1753. just insert the current using basreg. */
  1754. if (skip_optional_basereg &&
  1755. ((operand->flags & I370_OPERAND_BASE) != 0))
  1756. {
  1757. int basereg = -1;
  1758. if (use_text)
  1759. {
  1760. if (0 == strncmp (now_seg->name, ".text", 5)
  1761. || 0 > i370_using_other_regno)
  1762. basereg = i370_using_text_regno;
  1763. else
  1764. basereg = i370_using_other_regno;
  1765. }
  1766. else if (use_other)
  1767. {
  1768. if (0 > i370_using_other_regno)
  1769. basereg = i370_using_text_regno;
  1770. else
  1771. basereg = i370_using_other_regno;
  1772. }
  1773. if (0 > basereg)
  1774. as_bad (_("not using any base register"));
  1775. insn = i370_insert_operand (insn, operand, basereg);
  1776. continue;
  1777. }
  1778. /* If this is an optional operand, and we are skipping it,
  1779. Use zero (since a non-zero value would denote a register) */
  1780. if (skip_optional_reg
  1781. && ((operand->flags & I370_OPERAND_OPTIONAL) != 0))
  1782. {
  1783. insn = i370_insert_operand (insn, operand, 0);
  1784. continue;
  1785. }
  1786. /* Gather the operand. */
  1787. hold = input_line_pointer;
  1788. input_line_pointer = str;
  1789. /* Register names are only allowed where there are registers. */
  1790. if ((operand->flags & I370_OPERAND_GPR) != 0)
  1791. {
  1792. /* Quickie hack to get past things like (,r13). */
  1793. if (skip_optional_index && (',' == *input_line_pointer))
  1794. {
  1795. *input_line_pointer = ' ';
  1796. input_line_pointer ++;
  1797. }
  1798. if (! register_name (&ex))
  1799. as_bad (_("expecting a register for operand %d"),
  1800. (int) (opindex_ptr - opcode->operands + 1));
  1801. }
  1802. /* Check for an address constant expression. */
  1803. /* We will put PSW-relative addresses in the text section,
  1804. and address literals in the .data (or other) section. */
  1805. else if (i370_addr_cons (&ex))
  1806. use_other = 1;
  1807. else if (i370_addr_offset (&ex))
  1808. use_text = 1;
  1809. else expression (&ex);
  1810. str = input_line_pointer;
  1811. input_line_pointer = hold;
  1812. /* Perform some off-by-one hacks on the length field of certain instructions.
  1813. Its such a shame to have to do this, but the problem is that HLASM got
  1814. defined so that the programmer specifies a length that is one greater
  1815. than what the machine instruction wants. Sigh. */
  1816. if (off_by_one && (0 == strcasecmp ("SS L", operand->name)))
  1817. ex.X_add_number --;
  1818. if (ex.X_op == O_illegal)
  1819. as_bad (_("illegal operand"));
  1820. else if (ex.X_op == O_absent)
  1821. as_bad (_("missing operand"));
  1822. else if (ex.X_op == O_register)
  1823. insn = i370_insert_operand (insn, operand, ex.X_add_number);
  1824. else if (ex.X_op == O_constant)
  1825. {
  1826. #ifdef OBJ_ELF
  1827. /* Allow @HA, @L, @H on constants.
  1828. Well actually, no we don't; there really don't make sense
  1829. (at least not to me) for the i370. However, this code is
  1830. left here for any dubious future expansion reasons. */
  1831. char *orig_str = str;
  1832. if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
  1833. switch (reloc)
  1834. {
  1835. default:
  1836. str = orig_str;
  1837. break;
  1838. case BFD_RELOC_LO16:
  1839. /* X_unsigned is the default, so if the user has done
  1840. something which cleared it, we always produce a
  1841. signed value. */
  1842. ex.X_add_number = (((ex.X_add_number & 0xffff)
  1843. ^ 0x8000)
  1844. - 0x8000);
  1845. break;
  1846. case BFD_RELOC_HI16:
  1847. ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
  1848. break;
  1849. case BFD_RELOC_HI16_S:
  1850. ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff)
  1851. + ((ex.X_add_number >> 15) & 1));
  1852. break;
  1853. }
  1854. #endif
  1855. insn = i370_insert_operand (insn, operand, ex.X_add_number);
  1856. }
  1857. #ifdef OBJ_ELF
  1858. else if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
  1859. {
  1860. as_tsktsk ("md_assemble(): suffixed relocations not supported\n");
  1861. /* We need to generate a fixup for this expression. */
  1862. if (fc >= MAX_INSN_FIXUPS)
  1863. as_fatal ("too many fixups");
  1864. fixups[fc].exp = ex;
  1865. fixups[fc].opindex = 0;
  1866. fixups[fc].reloc = reloc;
  1867. ++fc;
  1868. }
  1869. #endif /* OBJ_ELF */
  1870. else
  1871. {
  1872. /* We need to generate a fixup for this expression. */
  1873. /* Typically, the expression will just be a symbol ...
  1874. printf ("insn %s needs fixup for %s \n",
  1875. opcode->name, ex.X_add_symbol->bsym->name); */
  1876. if (fc >= MAX_INSN_FIXUPS)
  1877. as_fatal ("too many fixups");
  1878. fixups[fc].exp = ex;
  1879. fixups[fc].opindex = *opindex_ptr;
  1880. fixups[fc].reloc = BFD_RELOC_UNUSED;
  1881. ++fc;
  1882. }
  1883. /* Skip over delimiter (close paren, or comma). */
  1884. if ((')' == *str) && (',' == *(str+1)))
  1885. ++str;
  1886. if (*str != '\0')
  1887. ++str;
  1888. }
  1889. while (ISSPACE (*str))
  1890. ++str;
  1891. if (*str != '\0')
  1892. as_bad (_("junk at end of line: `%s'"), str);
  1893. /* Write out the instruction. */
  1894. f = frag_more (opcode->len);
  1895. if (4 >= opcode->len)
  1896. md_number_to_chars (f, insn.i[0], opcode->len);
  1897. else
  1898. {
  1899. md_number_to_chars (f, insn.i[0], 4);
  1900. if (6 == opcode->len)
  1901. md_number_to_chars ((f + 4), ((insn.i[1])>>16), 2);
  1902. else
  1903. {
  1904. /* Not used --- don't have any 8 byte instructions. */
  1905. as_bad (_("Internal Error: bad instruction length"));
  1906. md_number_to_chars ((f + 4), insn.i[1], opcode->len -4);
  1907. }
  1908. }
  1909. /* Create any fixups. At this point we do not use a
  1910. bfd_reloc_code_real_type, but instead just use the
  1911. BFD_RELOC_UNUSED plus the operand index. This lets us easily
  1912. handle fixups for any operand type, although that is admittedly
  1913. not a very exciting feature. We pick a BFD reloc type in
  1914. md_apply_fix. */
  1915. for (i = 0; i < fc; i++)
  1916. {
  1917. const struct i370_operand *operand;
  1918. operand = &i370_operands[fixups[i].opindex];
  1919. if (fixups[i].reloc != BFD_RELOC_UNUSED)
  1920. {
  1921. reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
  1922. int size;
  1923. fixS *fixP;
  1924. if (!reloc_howto)
  1925. abort ();
  1926. size = bfd_get_reloc_size (reloc_howto);
  1927. if (size < 1 || size > 4)
  1928. abort ();
  1929. printf (" gwana doo fixup %d \n", i);
  1930. fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, size,
  1931. &fixups[i].exp, reloc_howto->pc_relative,
  1932. fixups[i].reloc);
  1933. /* Turn off complaints that the addend is too large for things like
  1934. foo+100000@ha. */
  1935. switch (fixups[i].reloc)
  1936. {
  1937. case BFD_RELOC_16_GOTOFF:
  1938. case BFD_RELOC_LO16:
  1939. case BFD_RELOC_HI16:
  1940. case BFD_RELOC_HI16_S:
  1941. fixP->fx_no_overflow = 1;
  1942. break;
  1943. default:
  1944. break;
  1945. }
  1946. }
  1947. else
  1948. {
  1949. fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->len,
  1950. &fixups[i].exp,
  1951. (operand->flags & I370_OPERAND_RELATIVE) != 0,
  1952. ((bfd_reloc_code_real_type)
  1953. (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
  1954. }
  1955. }
  1956. }
  1957. /* Pseudo-op handling. */
  1958. /* The .byte pseudo-op. This is similar to the normal .byte
  1959. pseudo-op, but it can also take a single ASCII string. */
  1960. static void
  1961. i370_byte (int ignore ATTRIBUTE_UNUSED)
  1962. {
  1963. if (*input_line_pointer != '\"')
  1964. {
  1965. cons (1);
  1966. return;
  1967. }
  1968. /* Gather characters. A real double quote is doubled. Unusual
  1969. characters are not permitted. */
  1970. ++input_line_pointer;
  1971. while (1)
  1972. {
  1973. char c;
  1974. c = *input_line_pointer++;
  1975. if (c == '\"')
  1976. {
  1977. if (*input_line_pointer != '\"')
  1978. break;
  1979. ++input_line_pointer;
  1980. }
  1981. FRAG_APPEND_1_CHAR (c);
  1982. }
  1983. demand_empty_rest_of_line ();
  1984. }
  1985. /* The .tc pseudo-op. This is used when generating XCOFF and ELF.
  1986. This takes two or more arguments.
  1987. When generating XCOFF output, the first argument is the name to
  1988. give to this location in the toc; this will be a symbol with class
  1989. TC. The rest of the arguments are 4 byte values to actually put at
  1990. this location in the TOC; often there is just one more argument, a
  1991. relocatable symbol reference.
  1992. When not generating XCOFF output, the arguments are the same, but
  1993. the first argument is simply ignored. */
  1994. static void
  1995. i370_tc (int ignore ATTRIBUTE_UNUSED)
  1996. {
  1997. /* Skip the TOC symbol name. */
  1998. while (is_part_of_name (*input_line_pointer)
  1999. || *input_line_pointer == '['
  2000. || *input_line_pointer == ']'
  2001. || *input_line_pointer == '{'
  2002. || *input_line_pointer == '}')
  2003. ++input_line_pointer;
  2004. /* Align to a four byte boundary. */
  2005. frag_align (2, 0, 0);
  2006. record_alignment (now_seg, 2);
  2007. if (*input_line_pointer != ',')
  2008. demand_empty_rest_of_line ();
  2009. else
  2010. {
  2011. ++input_line_pointer;
  2012. cons (4);
  2013. }
  2014. }
  2015. char *
  2016. md_atof (int type, char *litp, int *sizep)
  2017. {
  2018. /* 360/370/390 have two float formats: an old, funky 360 single-precision
  2019. format, and the ieee format. Support only the ieee format. */
  2020. return ieee_md_atof (type, litp, sizep, TRUE);
  2021. }
  2022. /* Write a value out to the object file, using the appropriate
  2023. endianness. */
  2024. void
  2025. md_number_to_chars (char *buf, valueT val, int n)
  2026. {
  2027. number_to_chars_bigendian (buf, val, n);
  2028. }
  2029. /* Align a section (I don't know why this is machine dependent). */
  2030. valueT
  2031. md_section_align (asection *seg, valueT addr)
  2032. {
  2033. int align = bfd_get_section_alignment (stdoutput, seg);
  2034. return (addr + (1 << align) - 1) & (-1 << align);
  2035. }
  2036. /* We don't have any form of relaxing. */
  2037. int
  2038. md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
  2039. asection *seg ATTRIBUTE_UNUSED)
  2040. {
  2041. abort ();
  2042. return 0;
  2043. }
  2044. /* Convert a machine dependent frag. We never generate these. */
  2045. void
  2046. md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
  2047. asection *sec ATTRIBUTE_UNUSED,
  2048. fragS *fragp ATTRIBUTE_UNUSED)
  2049. {
  2050. abort ();
  2051. }
  2052. /* We have no need to default values of symbols. */
  2053. symbolS *
  2054. md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
  2055. {
  2056. return 0;
  2057. }
  2058. /* Functions concerning relocs. */
  2059. /* The location from which a PC relative jump should be calculated,
  2060. given a PC relative reloc. */
  2061. long
  2062. md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
  2063. {
  2064. return fixp->fx_frag->fr_address + fixp->fx_where;
  2065. }
  2066. /* Apply a fixup to the object code. This is called for all the
  2067. fixups we generated by the call to fix_new_exp, above. In the call
  2068. above we used a reloc code which was the largest legal reloc code
  2069. plus the operand index. Here we undo that to recover the operand
  2070. index. At this point all symbol values should be fully resolved,
  2071. and we attempt to completely resolve the reloc. If we can not do
  2072. that, we determine the correct reloc code and put it back in the
  2073. fixup.
  2074. See gas/cgen.c for more sample code and explanations of what's
  2075. going on here. */
  2076. void
  2077. md_apply_fix (fixS *fixP, valueT * valP, segT seg)
  2078. {
  2079. valueT value = * valP;
  2080. if (fixP->fx_addsy != NULL)
  2081. {
  2082. #ifdef DEBUG
  2083. printf ("\nmd_apply_fix: symbol %s at 0x%x (%s:%d) val=0x%x addend=0x%x\n",
  2084. S_GET_NAME (fixP->fx_addsy),
  2085. fixP->fx_frag->fr_address + fixP->fx_where,
  2086. fixP->fx_file, fixP->fx_line,
  2087. S_GET_VALUE (fixP->fx_addsy), value);
  2088. #endif
  2089. }
  2090. else
  2091. fixP->fx_done = 1;
  2092. /* Apply fixups to operands. Note that there should be no relocations
  2093. for any operands, since no instruction ever takes an operand
  2094. that requires reloc. */
  2095. if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
  2096. {
  2097. int opindex;
  2098. const struct i370_operand *operand;
  2099. char *where;
  2100. i370_insn_t insn;
  2101. opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
  2102. operand = &i370_operands[opindex];
  2103. #ifdef DEBUG
  2104. printf ("\nmd_apply_fix: fixup operand %s at 0x%x in %s:%d addend=0x%x\n",
  2105. operand->name,
  2106. fixP->fx_frag->fr_address + fixP->fx_where,
  2107. fixP->fx_file, fixP->fx_line,
  2108. value);
  2109. #endif
  2110. /* Fetch the instruction, insert the fully resolved operand
  2111. value, and stuff the instruction back again.
  2112. fisxp->fx_size is the length of the instruction. */
  2113. where = fixP->fx_frag->fr_literal + fixP->fx_where;
  2114. insn.i[0] = bfd_getb32 ((unsigned char *) where);
  2115. if (6 <= fixP->fx_size)
  2116. /* Deal with 48-bit insn's. */
  2117. insn.i[1] = bfd_getb32 (((unsigned char *) where)+4);
  2118. insn = i370_insert_operand (insn, operand, (offsetT) value);
  2119. bfd_putb32 ((bfd_vma) insn.i[0], (unsigned char *) where);
  2120. if (6 <= fixP->fx_size)
  2121. /* Deal with 48-bit insn's. */
  2122. bfd_putb32 ((bfd_vma) insn.i[1], (((unsigned char *) where)+4));
  2123. /* We are done, right? right !! */
  2124. fixP->fx_done = 1;
  2125. if (fixP->fx_done)
  2126. /* Nothing else to do here. */
  2127. return;
  2128. /* Determine a BFD reloc value based on the operand information.
  2129. We are only prepared to turn a few of the operands into
  2130. relocs. In fact, we support *zero* operand relocations ...
  2131. Why? Because we are not expecting the compiler to generate
  2132. any operands that need relocation. Due to the 12-bit naturew of
  2133. i370 addressing, this would be unusual. */
  2134. {
  2135. char *sfile;
  2136. unsigned int sline;
  2137. /* Use expr_symbol_where to see if this is an expression
  2138. symbol. */
  2139. if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
  2140. as_bad_where (fixP->fx_file, fixP->fx_line,
  2141. "unresolved expression that must be resolved");
  2142. else
  2143. as_bad_where (fixP->fx_file, fixP->fx_line,
  2144. "unsupported relocation type");
  2145. fixP->fx_done = 1;
  2146. return;
  2147. }
  2148. }
  2149. else
  2150. {
  2151. /* We branch to here if the fixup is not to a symbol that
  2152. appears in an instruction operand, but is rather some
  2153. declared storage. */
  2154. #ifdef OBJ_ELF
  2155. i370_elf_validate_fix (fixP, seg);
  2156. #endif
  2157. #ifdef DEBUG
  2158. printf ("md_apply_fix: reloc case %d in segment %s %s:%d\n",
  2159. fixP->fx_r_type, segment_name (seg), fixP->fx_file, fixP->fx_line);
  2160. printf ("\tcurrent fixup value is 0x%x \n", value);
  2161. #endif
  2162. switch (fixP->fx_r_type)
  2163. {
  2164. case BFD_RELOC_32:
  2165. case BFD_RELOC_CTOR:
  2166. if (fixP->fx_pcrel)
  2167. fixP->fx_r_type = BFD_RELOC_32_PCREL;
  2168. /* Fall through. */
  2169. case BFD_RELOC_RVA:
  2170. case BFD_RELOC_32_PCREL:
  2171. case BFD_RELOC_32_BASEREL:
  2172. #ifdef DEBUG
  2173. printf ("\t32 bit relocation at 0x%x\n",
  2174. fixP->fx_frag->fr_address + fixP->fx_where);
  2175. #endif
  2176. md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
  2177. value, 4);
  2178. break;
  2179. case BFD_RELOC_LO16:
  2180. case BFD_RELOC_16:
  2181. if (fixP->fx_pcrel)
  2182. as_bad_where (fixP->fx_file, fixP->fx_line,
  2183. "cannot emit PC relative %s relocation%s%s",
  2184. bfd_get_reloc_code_name (fixP->fx_r_type),
  2185. fixP->fx_addsy != NULL ? " against " : "",
  2186. (fixP->fx_addsy != NULL
  2187. ? S_GET_NAME (fixP->fx_addsy)
  2188. : ""));
  2189. md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
  2190. value, 2);
  2191. break;
  2192. /* This case happens when you write, for example,
  2193. lis %r3,(L1-L2)@ha
  2194. where L1 and L2 are defined later. */
  2195. case BFD_RELOC_HI16:
  2196. if (fixP->fx_pcrel)
  2197. abort ();
  2198. md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
  2199. value >> 16, 2);
  2200. break;
  2201. case BFD_RELOC_HI16_S:
  2202. if (fixP->fx_pcrel)
  2203. abort ();
  2204. md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
  2205. (value + 0x8000) >> 16, 2);
  2206. break;
  2207. case BFD_RELOC_8:
  2208. if (fixP->fx_pcrel)
  2209. abort ();
  2210. md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
  2211. value, 1);
  2212. break;
  2213. default:
  2214. fprintf (stderr,
  2215. "Gas failure, reloc value %d\n", fixP->fx_r_type);
  2216. fflush (stderr);
  2217. abort ();
  2218. }
  2219. }
  2220. fixP->fx_addnumber = value;
  2221. }
  2222. /* Generate a reloc for a fixup. */
  2223. arelent *
  2224. tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
  2225. {
  2226. arelent *reloc;
  2227. reloc = xmalloc (sizeof (arelent));
  2228. reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  2229. *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  2230. reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2231. reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
  2232. if (reloc->howto == (reloc_howto_type *) NULL)
  2233. {
  2234. as_bad_where (fixp->fx_file, fixp->fx_line,
  2235. "reloc %d not supported by object file format", (int)fixp->fx_r_type);
  2236. return NULL;
  2237. }
  2238. reloc->addend = fixp->fx_addnumber;
  2239. #ifdef DEBUG
  2240. printf ("\ngen_reloc(): sym %s (%s:%d) at addr 0x%x addend=0x%x\n",
  2241. fixp->fx_addsy->bsym->name,
  2242. fixp->fx_file, fixp->fx_line,
  2243. reloc->address, reloc->addend);
  2244. #endif
  2245. return reloc;
  2246. }
  2247. /* The target specific pseudo-ops which we support. */
  2248. const pseudo_typeS md_pseudo_table[] =
  2249. {
  2250. /* Pseudo-ops which must be overridden. */
  2251. { "byte", i370_byte, 0 },
  2252. { "dc", i370_dc, 0 },
  2253. { "ds", i370_ds, 0 },
  2254. { "rmode", i370_rmode, 0 },
  2255. { "csect", i370_csect, 0 },
  2256. { "dsect", i370_dsect, 0 },
  2257. /* enable ebcdic strings e.g. for 3270 support */
  2258. { "ebcdic", i370_ebcdic, 0 },
  2259. #ifdef OBJ_ELF
  2260. { "long", i370_elf_cons, 4 },
  2261. { "word", i370_elf_cons, 4 },
  2262. { "short", i370_elf_cons, 2 },
  2263. { "rdata", i370_elf_rdata, 0 },
  2264. { "rodata", i370_elf_rdata, 0 },
  2265. { "lcomm", i370_elf_lcomm, 0 },
  2266. #endif
  2267. /* This pseudo-op is used even when not generating XCOFF output. */
  2268. { "tc", i370_tc, 0 },
  2269. /* dump the literal pool */
  2270. { "ltorg", i370_ltorg, 0 },
  2271. /* support the hlasm-style USING directive */
  2272. { "using", i370_using, 0 },
  2273. { "drop", i370_drop, 0 },
  2274. { NULL, NULL, 0 }
  2275. };