tc-visium.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309
  1. /* This is the machine dependent code of the Visium Assembler.
  2. Copyright (C) 2005-2015 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to
  14. the Free Software Foundation, 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #include "as.h"
  17. #include "safe-ctype.h"
  18. #include "subsegs.h"
  19. #include "obstack.h"
  20. #include "opcode/visium.h"
  21. #include "elf/visium.h"
  22. #include "dwarf2dbg.h"
  23. #include "dw2gencfi.h"
  24. /* Relocations and fixups:
  25. There are two different cases where an instruction or data
  26. directive operand requires relocation, or fixup.
  27. 1. Relative branch instructions, take an 16-bit signed word
  28. offset. The formula for computing the offset is this:
  29. offset = (destination - pc) / 4
  30. Branch instructions never branch to a label not declared
  31. locally, so the actual offset can always be computed by the assembler.
  32. However, we provide a relocation type to support this.
  33. 2. Load literal instructions, such as MOVIU, which take a 16-bit
  34. literal operand. The literal may be the top or bottom half of
  35. a 32-bit value computed by the assembler, or by the linker. We provide
  36. two relocation types here.
  37. 3. Data items (long, word and byte) preset with a value computed by
  38. the linker. */
  39. /* This string holds the chars that always start a comment. If the
  40. pre-processor is disabled, these aren't very useful. The macro
  41. tc_comment_chars points to this. */
  42. const char *visium_comment_chars = "!;";
  43. /* This array holds the chars that only start a comment at the beginning
  44. of a line. If the line seems to have the form '# 123 filename' .line
  45. and .file directives will appear in the pre-processed output. Note that
  46. input_file.c hand checks for '#' at the beginning of the first line of
  47. the input file. This is because the compiler outputs #NO_APP at the
  48. beginning of its output. Also note that comments like this one will
  49. always work. */
  50. const char line_comment_chars[] = "#!;";
  51. const char line_separator_chars[] = "";
  52. /* Chars that can be used to separate mantissa from exponent in floating point
  53. numbers. */
  54. const char EXP_CHARS[] = "eE";
  55. /* Chars that mean this number is a floating point constant, as in
  56. "0f12.456" or "0d1.2345e12".
  57. ...Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  58. changed in read.c. Ideally it shouldn't have to know about it at all,
  59. but nothing is ideal around here. */
  60. const char FLT_CHARS[] = "rRsSfFdDxXeE";
  61. /* The size of a relocation record. */
  62. const int md_reloc_size = 8;
  63. /* The architecture for which we are assembling. */
  64. enum visium_arch_val
  65. {
  66. VISIUM_ARCH_DEF,
  67. VISIUM_ARCH_MCM24,
  68. VISIUM_ARCH_MCM,
  69. VISIUM_ARCH_GR6
  70. };
  71. static enum visium_arch_val visium_arch = VISIUM_ARCH_DEF;
  72. /* The opcode architecture for which we are assembling. In contrast to the
  73. previous one, this only determines which instructions are supported. */
  74. static enum visium_opcode_arch_val visium_opcode_arch = VISIUM_OPCODE_ARCH_DEF;
  75. /* Flags to set in the ELF header e_flags field. */
  76. static flagword visium_flags = 0;
  77. /* More than this number of nops in an alignment op gets a branch instead. */
  78. static unsigned int nop_limit = 5;
  79. /* Translate internal representation of relocation info to BFD target
  80. format. */
  81. arelent *
  82. tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
  83. {
  84. arelent *reloc;
  85. bfd_reloc_code_real_type code;
  86. reloc = (arelent *) xmalloc (sizeof (arelent));
  87. reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
  88. *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  89. reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  90. switch (fixp->fx_r_type)
  91. {
  92. case BFD_RELOC_8:
  93. case BFD_RELOC_16:
  94. case BFD_RELOC_32:
  95. case BFD_RELOC_8_PCREL:
  96. case BFD_RELOC_16_PCREL:
  97. case BFD_RELOC_32_PCREL:
  98. case BFD_RELOC_VISIUM_HI16:
  99. case BFD_RELOC_VISIUM_LO16:
  100. case BFD_RELOC_VISIUM_IM16:
  101. case BFD_RELOC_VISIUM_REL16:
  102. case BFD_RELOC_VISIUM_HI16_PCREL:
  103. case BFD_RELOC_VISIUM_LO16_PCREL:
  104. case BFD_RELOC_VISIUM_IM16_PCREL:
  105. case BFD_RELOC_VTABLE_INHERIT:
  106. case BFD_RELOC_VTABLE_ENTRY:
  107. code = fixp->fx_r_type;
  108. break;
  109. default:
  110. as_bad_where (fixp->fx_file, fixp->fx_line,
  111. "internal error: unknown relocation type %d (`%s')",
  112. fixp->fx_r_type,
  113. bfd_get_reloc_code_name (fixp->fx_r_type));
  114. return 0;
  115. }
  116. reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  117. if (reloc->howto == 0)
  118. {
  119. as_bad_where (fixp->fx_file, fixp->fx_line,
  120. "internal error: can't export reloc type %d (`%s')",
  121. fixp->fx_r_type, bfd_get_reloc_code_name (code));
  122. return 0;
  123. }
  124. /* Write the addend. */
  125. if (reloc->howto->pc_relative == 0)
  126. reloc->addend = fixp->fx_addnumber;
  127. else
  128. reloc->addend = fixp->fx_offset;
  129. return reloc;
  130. }
  131. extern char *input_line_pointer;
  132. static void s_bss (int);
  133. static void visium_rdata (int);
  134. static void visium_update_parity_bit (char *);
  135. static char *parse_exp (char *, expressionS *);
  136. /* These are the back-ends for the various machine dependent pseudo-ops. */
  137. void demand_empty_rest_of_line (void);
  138. static void
  139. s_bss (int ignore ATTRIBUTE_UNUSED)
  140. {
  141. /* We don't support putting frags in the BSS segment, we fake it
  142. by marking in_bss, then looking at s_skip for clues. */
  143. subseg_set (bss_section, 0);
  144. demand_empty_rest_of_line ();
  145. }
  146. /* This table describes all the machine specific pseudo-ops the assembler
  147. has to support. The fields are:
  148. 1: Pseudo-op name without dot.
  149. 2: Function to call to execute this pseudo-op.
  150. 3: Integer arg to pass to the function. */
  151. const pseudo_typeS md_pseudo_table[] =
  152. {
  153. {"bss", s_bss, 0},
  154. {"skip", s_space, 0},
  155. {"align", s_align_bytes, 0},
  156. {"noopt", s_ignore, 0},
  157. {"optim", s_ignore, 0},
  158. {"rdata", visium_rdata, 0},
  159. {"rodata", visium_rdata, 0},
  160. {0, 0, 0}
  161. };
  162. static void
  163. visium_rdata (int xxx)
  164. {
  165. char *save_line = input_line_pointer;
  166. static char section[] = ".rodata\n";
  167. /* Just pretend this is .section .rodata */
  168. input_line_pointer = section;
  169. obj_elf_section (xxx);
  170. input_line_pointer = save_line;
  171. }
  172. /* Align a section. */
  173. valueT
  174. md_section_align (asection *seg, valueT addr)
  175. {
  176. int align = bfd_get_section_alignment (stdoutput, seg);
  177. return ((addr + (1 << align) - 1) & (-1 << align));
  178. }
  179. void
  180. md_number_to_chars (char *buf, valueT val, int n)
  181. {
  182. number_to_chars_bigendian (buf, val, n);
  183. }
  184. symbolS *
  185. md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
  186. {
  187. return 0;
  188. }
  189. /* The parse options. */
  190. const char *md_shortopts = "m:";
  191. struct option md_longopts[] =
  192. {
  193. {NULL, no_argument, NULL, 0}
  194. };
  195. size_t md_longopts_size = sizeof (md_longopts);
  196. struct visium_option_table
  197. {
  198. char *option; /* Option name to match. */
  199. char *help; /* Help information. */
  200. int *var; /* Variable to change. */
  201. int value; /* To what to change it. */
  202. char *deprecated; /* If non-null, print this message. */
  203. };
  204. static struct visium_option_table visium_opts[] =
  205. {
  206. {NULL, NULL, NULL, 0, NULL}
  207. };
  208. struct visium_arch_option_table
  209. {
  210. char *name;
  211. enum visium_arch_val value;
  212. };
  213. static struct visium_arch_option_table visium_archs[] =
  214. {
  215. {"mcm24", VISIUM_ARCH_MCM24},
  216. {"mcm", VISIUM_ARCH_MCM},
  217. {"gr5", VISIUM_ARCH_MCM},
  218. {"gr6", VISIUM_ARCH_GR6},
  219. {NULL, 0}
  220. };
  221. struct visium_long_option_table
  222. {
  223. char *option; /* Substring to match. */
  224. char *help; /* Help information. */
  225. int (*func) (char *subopt); /* Function to decode sub-option. */
  226. char *deprecated; /* If non-null, print this message. */
  227. };
  228. static int
  229. visium_parse_arch (char *str)
  230. {
  231. struct visium_arch_option_table *opt;
  232. if (strlen (str) == 0)
  233. {
  234. as_bad ("missing architecture name `%s'", str);
  235. return 0;
  236. }
  237. for (opt = visium_archs; opt->name != NULL; opt++)
  238. if (strcmp (opt->name, str) == 0)
  239. {
  240. visium_arch = opt->value;
  241. return 1;
  242. }
  243. as_bad ("unknown architecture `%s'\n", str);
  244. return 0;
  245. }
  246. static struct visium_long_option_table visium_long_opts[] =
  247. {
  248. {"mtune=", "<arch_name>\t assemble for architecture <arch name>",
  249. visium_parse_arch, NULL},
  250. {NULL, NULL, NULL, NULL}
  251. };
  252. int
  253. md_parse_option (int c, char *arg)
  254. {
  255. struct visium_option_table *opt;
  256. struct visium_long_option_table *lopt;
  257. switch (c)
  258. {
  259. case 'a':
  260. /* Listing option. Just ignore these, we don't support additional
  261. ones. */
  262. return 0;
  263. default:
  264. for (opt = visium_opts; opt->option != NULL; opt++)
  265. {
  266. if (c == opt->option[0]
  267. && ((arg == NULL && opt->option[1] == 0)
  268. || strcmp (arg, opt->option + 1) == 0))
  269. {
  270. /* If the option is deprecated, tell the user. */
  271. if (opt->deprecated != NULL)
  272. as_tsktsk ("option `-%c%s' is deprecated: %s", c,
  273. arg ? arg : "", opt->deprecated);
  274. if (opt->var != NULL)
  275. *opt->var = opt->value;
  276. return 1;
  277. }
  278. }
  279. for (lopt = visium_long_opts; lopt->option != NULL; lopt++)
  280. {
  281. /* These options are expected to have an argument. */
  282. if (c == lopt->option[0]
  283. && arg != NULL
  284. && strncmp (arg, lopt->option + 1,
  285. strlen (lopt->option + 1)) == 0)
  286. {
  287. /* If the option is deprecated, tell the user. */
  288. if (lopt->deprecated != NULL)
  289. as_tsktsk ("option `-%c%s' is deprecated: %s", c, arg,
  290. lopt->deprecated);
  291. /* Call the sup-option parser. */
  292. return lopt->func (arg + strlen (lopt->option) - 1);
  293. }
  294. }
  295. return 0;
  296. }
  297. return 1;
  298. }
  299. void
  300. md_show_usage (FILE * fp)
  301. {
  302. struct visium_option_table *opt;
  303. struct visium_long_option_table *lopt;
  304. fprintf (fp, " Visium-specific assembler options:\n");
  305. for (opt = visium_opts; opt->option != NULL; opt++)
  306. if (opt->help != NULL)
  307. fprintf (fp, " -%-23s%s\n", opt->option, opt->help);
  308. for (lopt = visium_long_opts; lopt->option != NULL; lopt++)
  309. if (lopt->help != NULL)
  310. fprintf (fp, " -%s%s\n", lopt->option, lopt->help);
  311. }
  312. /* Interface to relax_segment. */
  313. /* Return the estimate of the size of a machine dependent frag
  314. before any relaxing is done. It may also create any necessary
  315. relocations. */
  316. int
  317. md_estimate_size_before_relax (fragS * fragP,
  318. segT segment ATTRIBUTE_UNUSED)
  319. {
  320. fragP->fr_var = 4;
  321. return 4;
  322. }
  323. /* Get the address of a symbol during relaxation. From tc-arm.c. */
  324. static addressT
  325. relaxed_symbol_addr (fragS *fragp, long stretch)
  326. {
  327. fragS *sym_frag;
  328. addressT addr;
  329. symbolS *sym;
  330. sym = fragp->fr_symbol;
  331. sym_frag = symbol_get_frag (sym);
  332. know (S_GET_SEGMENT (sym) != absolute_section
  333. || sym_frag == &zero_address_frag);
  334. addr = S_GET_VALUE (sym) + fragp->fr_offset;
  335. /* If frag has yet to be reached on this pass, assume it will
  336. move by STRETCH just as we did. If this is not so, it will
  337. be because some frag between grows, and that will force
  338. another pass. */
  339. if (stretch != 0
  340. && sym_frag->relax_marker != fragp->relax_marker)
  341. {
  342. fragS *f;
  343. /* Adjust stretch for any alignment frag. Note that if have
  344. been expanding the earlier code, the symbol may be
  345. defined in what appears to be an earlier frag. FIXME:
  346. This doesn't handle the fr_subtype field, which specifies
  347. a maximum number of bytes to skip when doing an
  348. alignment. */
  349. for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
  350. {
  351. if (f->fr_type == rs_align || f->fr_type == rs_align_code)
  352. {
  353. if (stretch < 0)
  354. stretch = - ((- stretch)
  355. & ~ ((1 << (int) f->fr_offset) - 1));
  356. else
  357. stretch &= ~ ((1 << (int) f->fr_offset) - 1);
  358. if (stretch == 0)
  359. break;
  360. }
  361. }
  362. if (f != NULL)
  363. addr += stretch;
  364. }
  365. return addr;
  366. }
  367. /* Relax a machine dependent frag. This returns the amount by which
  368. the current size of the frag should change. */
  369. int
  370. visium_relax_frag (asection *sec, fragS *fragP, long stretch)
  371. {
  372. int old_size, new_size;
  373. addressT addr;
  374. /* We only handle relaxation for the BRR instruction. */
  375. gas_assert (fragP->fr_subtype == mode_ci);
  376. if (!S_IS_DEFINED (fragP->fr_symbol)
  377. || sec != S_GET_SEGMENT (fragP->fr_symbol)
  378. || S_IS_WEAK (fragP->fr_symbol))
  379. return 0;
  380. old_size = fragP->fr_var;
  381. addr = relaxed_symbol_addr (fragP, stretch);
  382. /* If the target is the address of the instruction, we'll insert a NOP. */
  383. if (addr == fragP->fr_address + fragP->fr_fix)
  384. new_size = 8;
  385. else
  386. new_size = 4;
  387. fragP->fr_var = new_size;
  388. return new_size - old_size;
  389. }
  390. /* Convert a machine dependent frag. */
  391. void
  392. md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
  393. fragS * fragP)
  394. {
  395. char *buf = fragP->fr_literal + fragP->fr_fix;
  396. expressionS exp;
  397. fixS *fixP;
  398. /* We only handle relaxation for the BRR instruction. */
  399. gas_assert (fragP->fr_subtype == mode_ci);
  400. /* Insert the NOP if requested. */
  401. if (fragP->fr_var == 8)
  402. {
  403. memcpy (buf + 4, buf, 4);
  404. memset (buf, 0, 4);
  405. fragP->fr_fix += 4;
  406. }
  407. exp.X_op = O_symbol;
  408. exp.X_add_symbol = fragP->fr_symbol;
  409. exp.X_add_number = fragP->fr_offset;
  410. /* Now we can create the relocation at the correct offset. */
  411. fixP = fix_new_exp (fragP, fragP->fr_fix, 4, &exp, 1, BFD_RELOC_VISIUM_REL16);
  412. fixP->fx_file = fragP->fr_file;
  413. fixP->fx_line = fragP->fr_line;
  414. fragP->fr_fix += 4;
  415. fragP->fr_var = 0;
  416. }
  417. /* The location from which a PC relative jump should be calculated,
  418. given a PC relative jump reloc. */
  419. long
  420. visium_pcrel_from_section (fixS *fixP, segT sec)
  421. {
  422. if (fixP->fx_addsy != (symbolS *) NULL
  423. && (!S_IS_DEFINED (fixP->fx_addsy)
  424. || S_GET_SEGMENT (fixP->fx_addsy) != sec))
  425. {
  426. /* The symbol is undefined (or is defined but not in this section).
  427. Let the linker figure it out. */
  428. return 0;
  429. }
  430. /* Return the address of the instruction. */
  431. return fixP->fx_where + fixP->fx_frag->fr_address;
  432. }
  433. /* Indicate whether a fixup against a locally defined
  434. symbol should be adjusted to be against the section
  435. symbol. */
  436. bfd_boolean
  437. visium_fix_adjustable (fixS *fix)
  438. {
  439. /* We need the symbol name for the VTABLE entries. */
  440. return (fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
  441. && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY);
  442. }
  443. /* Update the parity bit of the 4-byte instruction in BUF. */
  444. static void
  445. visium_update_parity_bit (char *buf)
  446. {
  447. int p1 = (buf[0] & 0x7f) ^ buf[1] ^ buf[2] ^ buf[3];
  448. int p2 = 0;
  449. int i;
  450. for (i = 1; i <= 8; i++)
  451. {
  452. p2 ^= (p1 & 1);
  453. p1 >>= 1;
  454. }
  455. buf[0] = (buf[0] & 0x7f) | ((p2 << 7) & 0x80);
  456. }
  457. /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
  458. of an rs_align_code fragment. */
  459. void
  460. visium_handle_align (fragS *fragP)
  461. {
  462. valueT count
  463. = fragP->fr_next->fr_address - (fragP->fr_address + fragP->fr_fix);
  464. valueT fix = count & 3;
  465. char *p = fragP->fr_literal + fragP->fr_fix;
  466. if (fix)
  467. {
  468. memset (p, 0, fix);
  469. p += fix;
  470. count -= fix;
  471. fragP->fr_fix += fix;
  472. }
  473. if (count == 0)
  474. return;
  475. fragP->fr_var = 4;
  476. if (count > 4 * nop_limit && count <= 131068)
  477. {
  478. struct frag *rest;
  479. /* Make a branch, then follow with nops. Insert another
  480. frag to handle the nops. */
  481. md_number_to_chars (p, 0x78000000 + (count >> 2), 4);
  482. visium_update_parity_bit (p);
  483. rest = xmalloc (SIZEOF_STRUCT_FRAG + 4);
  484. memcpy (rest, fragP, SIZEOF_STRUCT_FRAG);
  485. fragP->fr_next = rest;
  486. rest->fr_address += rest->fr_fix + 4;
  487. rest->fr_fix = 0;
  488. /* If we leave the next frag as rs_align_code we'll come here
  489. again, resulting in a bunch of branches rather than a
  490. branch followed by nops. */
  491. rest->fr_type = rs_align;
  492. p = rest->fr_literal;
  493. }
  494. memset (p, 0, 4);
  495. }
  496. /* Apply a fixS to the frags, now that we know the value it ought to
  497. hold. */
  498. void
  499. md_apply_fix (fixS * fixP, valueT * value, segT segment)
  500. {
  501. char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  502. offsetT val;
  503. long insn;
  504. val = *value;
  505. gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
  506. /* Remember value for tc_gen_reloc. */
  507. fixP->fx_addnumber = val;
  508. /* Since DIFF_EXPR_OK is defined, .-foo gets turned into PC
  509. relative relocs. If this has happened, a non-PC relative
  510. reloc must be reinstalled with its PC relative version here. */
  511. if (fixP->fx_pcrel)
  512. {
  513. switch (fixP->fx_r_type)
  514. {
  515. case BFD_RELOC_8:
  516. fixP->fx_r_type = BFD_RELOC_8_PCREL;
  517. break;
  518. case BFD_RELOC_16:
  519. fixP->fx_r_type = BFD_RELOC_16_PCREL;
  520. break;
  521. case BFD_RELOC_32:
  522. fixP->fx_r_type = BFD_RELOC_32_PCREL;
  523. break;
  524. case BFD_RELOC_VISIUM_HI16:
  525. fixP->fx_r_type = BFD_RELOC_VISIUM_HI16_PCREL;
  526. break;
  527. case BFD_RELOC_VISIUM_LO16:
  528. fixP->fx_r_type = BFD_RELOC_VISIUM_LO16_PCREL;
  529. break;
  530. case BFD_RELOC_VISIUM_IM16:
  531. fixP->fx_r_type = BFD_RELOC_VISIUM_IM16_PCREL;
  532. break;
  533. default:
  534. break;
  535. }
  536. }
  537. /* If this is a data relocation, just output VAL. */
  538. switch (fixP->fx_r_type)
  539. {
  540. case BFD_RELOC_8:
  541. case BFD_RELOC_8_PCREL:
  542. md_number_to_chars (buf, val, 1);
  543. break;
  544. case BFD_RELOC_16:
  545. case BFD_RELOC_16_PCREL:
  546. md_number_to_chars (buf, val, 2);
  547. break;
  548. case BFD_RELOC_32:
  549. case BFD_RELOC_32_PCREL:
  550. md_number_to_chars (buf, val, 4);
  551. break;
  552. case BFD_RELOC_VTABLE_INHERIT:
  553. case BFD_RELOC_VTABLE_ENTRY:
  554. fixP->fx_done = 0;
  555. break;
  556. default:
  557. /* It's a relocation against an instruction. */
  558. insn = bfd_getb32 ((unsigned char *) buf);
  559. switch (fixP->fx_r_type)
  560. {
  561. case BFD_RELOC_VISIUM_REL16:
  562. if (fixP->fx_addsy == NULL
  563. || (S_IS_DEFINED (fixP->fx_addsy)
  564. && S_GET_SEGMENT (fixP->fx_addsy) == segment))
  565. {
  566. if (val > 0x1fffc || val < -0x20000)
  567. as_bad_where
  568. (fixP->fx_file, fixP->fx_line,
  569. "16-bit word displacement out of range: value = %d",
  570. (int) val);
  571. val = (val >> 2);
  572. insn = (insn & 0xffff0000) | (val & 0x0000ffff);
  573. }
  574. break;
  575. case BFD_RELOC_VISIUM_HI16:
  576. case BFD_RELOC_VISIUM_HI16_PCREL:
  577. if (fixP->fx_addsy == NULL)
  578. insn = (insn & 0xffff0000) | ((val >> 16) & 0x0000ffff);
  579. break;
  580. case BFD_RELOC_VISIUM_LO16:
  581. case BFD_RELOC_VISIUM_LO16_PCREL:
  582. if (fixP->fx_addsy == NULL)
  583. insn = (insn & 0xffff0000) | (val & 0x0000ffff);
  584. break;
  585. case BFD_RELOC_VISIUM_IM16:
  586. case BFD_RELOC_VISIUM_IM16_PCREL:
  587. if (fixP->fx_addsy == NULL)
  588. {
  589. if ((val & 0xffff0000) != 0)
  590. as_bad_where (fixP->fx_file, fixP->fx_line,
  591. "16-bit immediate out of range: value = %d",
  592. (int) val);
  593. insn = (insn & 0xffff0000) | val;
  594. }
  595. break;
  596. case BFD_RELOC_NONE:
  597. default:
  598. as_bad_where (fixP->fx_file, fixP->fx_line,
  599. "bad or unhandled relocation type: 0x%02x",
  600. fixP->fx_r_type);
  601. break;
  602. }
  603. bfd_putb32 (insn, (unsigned char *) buf);
  604. visium_update_parity_bit (buf);
  605. break;
  606. }
  607. /* Are we finished with this relocation now? */
  608. if (fixP->fx_addsy == NULL)
  609. fixP->fx_done = 1;
  610. }
  611. char *
  612. parse_exp (char *s, expressionS * op)
  613. {
  614. char *save = input_line_pointer;
  615. char *new;
  616. if (!s)
  617. {
  618. return s;
  619. }
  620. input_line_pointer = s;
  621. expression (op);
  622. new = input_line_pointer;
  623. input_line_pointer = save;
  624. return new;
  625. }
  626. /* If the given string is a Visium opcode mnemonic return the code
  627. otherwise return -1. Use binary chop to find matching entry. */
  628. static int
  629. get_opcode (int *code, enum addressing_mode *mode, char *flags, char *mnem)
  630. {
  631. int l = 0;
  632. int r = sizeof (opcode_table) / sizeof (struct opcode_entry) - 1;
  633. do
  634. {
  635. int mid = (l + r) / 2;
  636. int ans = strcmp (mnem, opcode_table[mid].mnem);
  637. if (ans < 0)
  638. r = mid - 1;
  639. else if (ans > 0)
  640. l = mid + 1;
  641. else
  642. {
  643. *code = opcode_table[mid].code;
  644. *mode = opcode_table[mid].mode;
  645. *flags = opcode_table[mid].flags;
  646. return 0;
  647. }
  648. }
  649. while (l <= r);
  650. return -1;
  651. }
  652. /* This function is called when the assembler starts up. It is called
  653. after the options have been parsed and the output file has been
  654. opened. */
  655. void
  656. md_begin (void)
  657. {
  658. switch (visium_arch)
  659. {
  660. case VISIUM_ARCH_DEF:
  661. break;
  662. case VISIUM_ARCH_MCM24:
  663. visium_opcode_arch = VISIUM_OPCODE_ARCH_GR5;
  664. visium_flags |= EF_VISIUM_ARCH_MCM24;
  665. break;
  666. case VISIUM_ARCH_MCM:
  667. visium_opcode_arch = VISIUM_OPCODE_ARCH_GR5;
  668. visium_flags |= EF_VISIUM_ARCH_MCM;
  669. break;
  670. case VISIUM_ARCH_GR6:
  671. visium_opcode_arch = VISIUM_OPCODE_ARCH_GR6;
  672. visium_flags |= EF_VISIUM_ARCH_MCM | EF_VISIUM_ARCH_GR6;
  673. nop_limit = 2;
  674. break;
  675. default:
  676. gas_assert (0);
  677. }
  678. bfd_set_private_flags (stdoutput, visium_flags);
  679. }
  680. /* This is identical to the md_atof in m68k.c. I think this is right,
  681. but I'm not sure.
  682. Turn a string in input_line_pointer into a floating point constant of type
  683. type, and store the appropriate bytes in *litP. The number of LITTLENUMS
  684. emitted is stored in *sizeP . An error message is returned,
  685. or NULL on OK. */
  686. /* Equal to MAX_PRECISION in atof-ieee.c. */
  687. #define MAX_LITTLENUMS 6
  688. char *
  689. md_atof (int type, char *litP, int *sizeP)
  690. {
  691. int i, prec;
  692. LITTLENUM_TYPE words[MAX_LITTLENUMS];
  693. char *t;
  694. switch (type)
  695. {
  696. case 'f':
  697. case 'F':
  698. case 's':
  699. case 'S':
  700. prec = 2;
  701. break;
  702. case 'd':
  703. case 'D':
  704. case 'r':
  705. case 'R':
  706. prec = 4;
  707. break;
  708. case 'x':
  709. case 'X':
  710. prec = 6;
  711. break;
  712. case 'p':
  713. case 'P':
  714. prec = 6;
  715. break;
  716. default:
  717. *sizeP = 0;
  718. return "Bad call to MD_ATOF()";
  719. }
  720. t = atof_ieee (input_line_pointer, type, words);
  721. if (t)
  722. input_line_pointer = t;
  723. *sizeP = prec * sizeof (LITTLENUM_TYPE);
  724. if (target_big_endian)
  725. {
  726. for (i = 0; i < prec; i++)
  727. {
  728. md_number_to_chars (litP, (valueT) words[i],
  729. sizeof (LITTLENUM_TYPE));
  730. litP += sizeof (LITTLENUM_TYPE);
  731. }
  732. }
  733. else
  734. {
  735. for (i = prec - 1; i >= 0; i--)
  736. {
  737. md_number_to_chars (litP, (valueT) words[i],
  738. sizeof (LITTLENUM_TYPE));
  739. litP += sizeof (LITTLENUM_TYPE);
  740. }
  741. }
  742. return 0;
  743. }
  744. static inline char *
  745. skip_space (char *s)
  746. {
  747. while (*s == ' ' || *s == '\t')
  748. ++s;
  749. return s;
  750. }
  751. static int
  752. parse_gen_reg (char **sptr, int *rptr)
  753. {
  754. char *s = skip_space (*sptr);
  755. char buf[10];
  756. int cnt;
  757. int l, r;
  758. cnt = 0;
  759. memset (buf, '\0', 10);
  760. while ((ISALNUM (*s)) && cnt < 10)
  761. buf[cnt++] = TOLOWER (*s++);
  762. l = 0;
  763. r = sizeof (gen_reg_table) / sizeof (struct reg_entry) - 1;
  764. do
  765. {
  766. int mid = (l + r) / 2;
  767. int ans = strcmp (buf, gen_reg_table[mid].name);
  768. if (ans < 0)
  769. r = mid - 1;
  770. else if (ans > 0)
  771. l = mid + 1;
  772. else
  773. {
  774. *rptr = gen_reg_table[mid].code;
  775. *sptr = s;
  776. return 0;
  777. }
  778. }
  779. while (l <= r);
  780. return -1;
  781. }
  782. static int
  783. parse_fp_reg (char **sptr, int *rptr)
  784. {
  785. char *s = skip_space (*sptr);
  786. char buf[10];
  787. int cnt;
  788. int l, r;
  789. cnt = 0;
  790. memset (buf, '\0', 10);
  791. while ((ISALNUM (*s)) && cnt < 10)
  792. buf[cnt++] = TOLOWER (*s++);
  793. l = 0;
  794. r = sizeof (fp_reg_table) / sizeof (struct reg_entry) - 1;
  795. do
  796. {
  797. int mid = (l + r) / 2;
  798. int ans = strcmp (buf, fp_reg_table[mid].name);
  799. if (ans < 0)
  800. r = mid - 1;
  801. else if (ans > 0)
  802. l = mid + 1;
  803. else
  804. {
  805. *rptr = fp_reg_table[mid].code;
  806. *sptr = s;
  807. return 0;
  808. }
  809. }
  810. while (l <= r);
  811. return -1;
  812. }
  813. static int
  814. parse_cc (char **sptr, int *rptr)
  815. {
  816. char *s = skip_space (*sptr);
  817. char buf[10];
  818. int cnt;
  819. int l, r;
  820. cnt = 0;
  821. memset (buf, '\0', 10);
  822. while ((ISALNUM (*s)) && cnt < 10)
  823. buf[cnt++] = TOLOWER (*s++);
  824. l = 0;
  825. r = sizeof (cc_table) / sizeof (struct cc_entry) - 1;
  826. do
  827. {
  828. int mid = (l + r) / 2;
  829. int ans = strcmp (buf, cc_table[mid].name);
  830. if (ans < 0)
  831. r = mid - 1;
  832. else if (ans > 0)
  833. l = mid + 1;
  834. else
  835. {
  836. *rptr = cc_table[mid].code;
  837. *sptr = s;
  838. return 0;
  839. }
  840. }
  841. while (l <= r);
  842. return -1;
  843. }
  844. /* Previous dest is the destination register number of the instruction
  845. before the current one. */
  846. static int previous_dest = 0;
  847. static int previous_mode = 0;
  848. static int condition_code = 0;
  849. static int this_dest = 0;
  850. static int this_mode = 0;
  851. /* This is the main function in this file. It takes a line of assembly language
  852. source code and assembles it. Note, labels and pseudo ops have already
  853. been removed, so too has leading white space. */
  854. void
  855. md_assemble (char *str0)
  856. {
  857. char *str = str0;
  858. int cnt;
  859. char mnem[10];
  860. int opcode;
  861. enum addressing_mode amode;
  862. char arch_flags;
  863. int ans;
  864. char *output;
  865. int reloc = 0;
  866. relax_substateT relax = 0;
  867. expressionS e1;
  868. int r1, r2, r3;
  869. int cc;
  870. int indx;
  871. /* Initialize the expression. */
  872. e1.X_op = O_absent;
  873. /* Initialize destination register.
  874. If the instruction we just looked at is in the delay slot of an
  875. unconditional branch, then there is no index hazard. */
  876. if ((previous_mode == mode_cad || previous_mode == mode_ci)
  877. && condition_code == 15)
  878. this_dest = 0;
  879. previous_dest = this_dest;
  880. previous_mode = this_mode;
  881. this_dest = 0;
  882. /* Drop leading whitespace (probably not required). */
  883. while (*str == ' ')
  884. str++;
  885. /* Get opcode mnemonic and make sure it's in lower case. */
  886. cnt = 0;
  887. memset (mnem, '\0', 10);
  888. while ((ISALNUM (*str) || *str == '.' || *str == '_') && cnt < 10)
  889. mnem[cnt++] = TOLOWER (*str++);
  890. /* Look up mnemonic in opcode table, and get the code,
  891. the instruction format, and the flags that indicate
  892. which family members support this mnenonic. */
  893. if (get_opcode (&opcode, &amode, &arch_flags, mnem) < 0)
  894. {
  895. as_bad ("Unknown instruction mnenonic `%s'", mnem);
  896. return;
  897. }
  898. if ((VISIUM_OPCODE_ARCH_MASK (visium_opcode_arch) & arch_flags) == 0)
  899. {
  900. as_bad ("Architecture mismatch on `%s'", mnem);
  901. return;
  902. }
  903. this_mode = amode;
  904. switch (amode)
  905. {
  906. case mode_d:
  907. /* register :=
  908. Example:
  909. readmda r1 */
  910. ans = parse_gen_reg (&str, &r1);
  911. if (ans < 0)
  912. {
  913. as_bad ("Dest register required");
  914. return;
  915. }
  916. opcode |= (r1 << 10);
  917. this_dest = r1;
  918. break;
  919. case mode_a:
  920. /* op= register
  921. Example: asld r1 */
  922. ans = parse_gen_reg (&str, &r1);
  923. if (ans < 0)
  924. {
  925. as_bad ("SourceA register required");
  926. return;
  927. }
  928. opcode |= (r1 << 16);
  929. break;
  930. case mode_ab:
  931. /* register * register
  932. Example:
  933. mults r1,r2 */
  934. ans = parse_gen_reg (&str, &r1);
  935. if (ans < 0)
  936. {
  937. as_bad ("SourceA register required");
  938. return;
  939. }
  940. str = skip_space (str);
  941. if (*str == ',')
  942. {
  943. str++;
  944. ans = parse_gen_reg (&str, &r2);
  945. if (ans < 0)
  946. {
  947. as_bad ("SourceB register required");
  948. return;
  949. }
  950. opcode |= (r1 << 16) | (r2 << 4);
  951. }
  952. else
  953. {
  954. as_bad ("SourceB register required");
  955. return;
  956. }
  957. break;
  958. case mode_da:
  959. /* register := register
  960. Example:
  961. extb.l r1,r2 */
  962. ans = parse_gen_reg (&str, &r1);
  963. if (ans < 0)
  964. {
  965. as_bad ("Dest register required");
  966. return;
  967. }
  968. str = skip_space (str);
  969. if (*str == ',')
  970. {
  971. str++;
  972. ans = parse_gen_reg (&str, &r2);
  973. if (ans < 0)
  974. {
  975. as_bad ("SourceA register required");
  976. return;
  977. }
  978. opcode |= (r1 << 10) | (r2 << 16);
  979. }
  980. else
  981. {
  982. as_bad ("SourceB register required");
  983. return;
  984. }
  985. this_dest = r1;
  986. break;
  987. case mode_dab:
  988. /* register := register * register
  989. Example:
  990. add.l r1,r2,r3 */
  991. ans = parse_gen_reg (&str, &r1);
  992. if (ans < 0)
  993. {
  994. as_bad ("Dest register required");
  995. return;
  996. }
  997. str = skip_space (str);
  998. if (*str == ',')
  999. {
  1000. str++;
  1001. ans = parse_gen_reg (&str, &r2);
  1002. if (ans < 0)
  1003. {
  1004. as_bad ("SourceA register required");
  1005. return;
  1006. }
  1007. str = skip_space (str);
  1008. if (*str == ',')
  1009. {
  1010. str++;
  1011. ans = parse_gen_reg (&str, &r3);
  1012. if (ans < 0)
  1013. {
  1014. as_bad ("SourceB register required");
  1015. return;
  1016. }
  1017. /* Got three regs, assemble instruction. */
  1018. opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
  1019. }
  1020. else
  1021. {
  1022. as_bad ("SourceA register required");
  1023. return;
  1024. }
  1025. }
  1026. else
  1027. {
  1028. as_bad ("Dest register required");
  1029. return;
  1030. }
  1031. this_dest = r1;
  1032. break;
  1033. case mode_iab:
  1034. /* 5-bit immediate * register * register
  1035. Example:
  1036. eamwrite 3,r1,r2 */
  1037. str = parse_exp (str, &e1);
  1038. str = skip_space (str);
  1039. if (e1.X_op != O_absent && *str == ',')
  1040. {
  1041. int eam_op = e1.X_add_number;
  1042. str = skip_space (str + 1);
  1043. ans = parse_gen_reg (&str, &r2);
  1044. if (ans < 0)
  1045. {
  1046. as_bad ("SourceA register required");
  1047. return;
  1048. }
  1049. str = skip_space (str);
  1050. if (*str == ',')
  1051. {
  1052. str++;
  1053. ans = parse_gen_reg (&str, &r3);
  1054. if (ans < 0)
  1055. {
  1056. as_bad ("SourceB register required");
  1057. return;
  1058. }
  1059. /* Got three operands, assemble instruction. */
  1060. if (eam_op < 0 || eam_op > 31)
  1061. {
  1062. as_bad ("eam_op out of range");
  1063. }
  1064. opcode |= ((eam_op & 0x1f) << 10) | (r2 << 16) | (r3 << 4);
  1065. }
  1066. }
  1067. else
  1068. {
  1069. as_bad ("EAM_OP required");
  1070. return;
  1071. }
  1072. break;
  1073. case mode_0ab:
  1074. /* zero * register * register
  1075. Example:
  1076. cmp.l r1,r2 */
  1077. ans = parse_gen_reg (&str, &r1);
  1078. if (ans < 0)
  1079. {
  1080. as_bad ("SourceA register required");
  1081. return;
  1082. }
  1083. str = skip_space (str);
  1084. if (*str == ',')
  1085. {
  1086. str++;
  1087. ans = parse_gen_reg (&str, &r2);
  1088. if (ans < 0)
  1089. {
  1090. as_bad ("SourceB register required");
  1091. return;
  1092. }
  1093. opcode |= (r1 << 16) | (r2 << 4);
  1094. }
  1095. else
  1096. {
  1097. as_bad ("SourceB register required");
  1098. return;
  1099. }
  1100. break;
  1101. case mode_da0:
  1102. /* register * register * zero
  1103. Example:
  1104. move.l r1,r2 */
  1105. ans = parse_gen_reg (&str, &r1);
  1106. if (ans < 0)
  1107. {
  1108. as_bad ("Dest register required");
  1109. return;
  1110. }
  1111. str = skip_space (str);
  1112. if (*str == ',')
  1113. {
  1114. str++;
  1115. ans = parse_gen_reg (&str, &r2);
  1116. if (ans < 0)
  1117. {
  1118. as_bad ("SourceA register required");
  1119. return;
  1120. }
  1121. opcode |= (r1 << 10) | (r2 << 16);
  1122. }
  1123. else
  1124. {
  1125. as_bad ("SourceA register required");
  1126. return;
  1127. }
  1128. this_dest = r1;
  1129. break;
  1130. case mode_cad:
  1131. /* condition * register * register
  1132. Example:
  1133. bra tr,r1,r2 */
  1134. ans = parse_cc (&str, &cc);
  1135. if (ans < 0)
  1136. {
  1137. as_bad ("condition code required");
  1138. return;
  1139. }
  1140. str = skip_space (str);
  1141. if (*str == ',')
  1142. {
  1143. str = skip_space (str + 1);
  1144. ans = parse_gen_reg (&str, &r2);
  1145. if (ans < 0)
  1146. {
  1147. as_bad ("SourceA register required");
  1148. return;
  1149. }
  1150. str = skip_space (str);
  1151. if (*str == ',')
  1152. {
  1153. str++;
  1154. ans = parse_gen_reg (&str, &r3);
  1155. if (ans < 0)
  1156. {
  1157. as_bad ("Dest register required");
  1158. return;
  1159. }
  1160. /* Got three operands, assemble instruction. */
  1161. opcode |= (cc << 27) | (r2 << 16) | (r3 << 10);
  1162. }
  1163. else
  1164. {
  1165. as_bad ("Dest register required");
  1166. return;
  1167. }
  1168. }
  1169. else
  1170. {
  1171. as_bad ("SourceA register required");
  1172. return;
  1173. }
  1174. if (previous_mode == mode_cad || previous_mode == mode_ci)
  1175. as_bad ("branch instruction in delay slot");
  1176. this_dest = r3;
  1177. condition_code = cc;
  1178. break;
  1179. case mode_das:
  1180. /* register := register * 5-bit imediate/register shift count
  1181. Example:
  1182. asl.l r1,r2,4 */
  1183. ans = parse_gen_reg (&str, &r1);
  1184. if (ans < 0)
  1185. {
  1186. as_bad ("Dest register required");
  1187. return;
  1188. }
  1189. str = skip_space (str);
  1190. if (*str == ',')
  1191. {
  1192. str++;
  1193. ans = parse_gen_reg (&str, &r2);
  1194. if (ans < 0)
  1195. {
  1196. as_bad ("SourceA register required");
  1197. return;
  1198. }
  1199. str = skip_space (str);
  1200. if (*str == ',')
  1201. {
  1202. str++;
  1203. ans = parse_gen_reg (&str, &r3);
  1204. if (ans == 0)
  1205. {
  1206. opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
  1207. }
  1208. else
  1209. {
  1210. str = parse_exp (str, &e1);
  1211. if (e1.X_op == O_constant)
  1212. {
  1213. int imm = e1.X_add_number;
  1214. if (imm < 0 || imm > 31)
  1215. as_bad ("immediate value out of range");
  1216. opcode |=
  1217. (r1 << 10) | (r2 << 16) | (1 << 9) | ((imm & 0x1f) <<
  1218. 4);
  1219. }
  1220. else
  1221. {
  1222. as_bad ("immediate operand required");
  1223. return;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. else
  1229. {
  1230. as_bad ("SourceA register required");
  1231. return;
  1232. }
  1233. this_dest = r1;
  1234. break;
  1235. case mode_di:
  1236. /* register := 5-bit immediate
  1237. Example:
  1238. eamread r1,3 */
  1239. ans = parse_gen_reg (&str, &r1);
  1240. if (ans < 0)
  1241. {
  1242. as_bad ("Dest register required");
  1243. return;
  1244. }
  1245. str = skip_space (str);
  1246. if (*str == ',')
  1247. {
  1248. str++;
  1249. str = parse_exp (str, &e1);
  1250. if (e1.X_op == O_constant)
  1251. {
  1252. int opnd2 = e1.X_add_number;
  1253. if (opnd2 < 0 || opnd2 > 31)
  1254. {
  1255. as_bad ("immediate operand out of range");
  1256. return;
  1257. }
  1258. opcode |= (r1 << 10) | ((opnd2 & 0x1f) << 4);
  1259. }
  1260. else
  1261. {
  1262. as_bad ("immediate operand required");
  1263. return;
  1264. }
  1265. }
  1266. else
  1267. {
  1268. as_bad ("immediate operand required");
  1269. return;
  1270. }
  1271. this_dest = r1;
  1272. break;
  1273. case mode_ir:
  1274. /* 5-bit immediate * register, e.g. trace 1,r1 */
  1275. str = parse_exp (str, &e1);
  1276. str = skip_space (str);
  1277. if (e1.X_op == O_constant && *str == ',')
  1278. {
  1279. int opnd1 = e1.X_add_number;
  1280. str = skip_space (str + 1);
  1281. ans = parse_gen_reg (&str, &r2);
  1282. if (ans < 0)
  1283. {
  1284. as_bad ("SourceA register required");
  1285. return;
  1286. }
  1287. /* Got two operands, assemble instruction. */
  1288. if (opnd1 < 0 || opnd1 > 31)
  1289. {
  1290. as_bad ("1st operand out of range");
  1291. }
  1292. opcode |= ((opnd1 & 0x1f) << 10) | (r2 << 16);
  1293. }
  1294. else
  1295. {
  1296. as_bad ("Immediate operand required");
  1297. return;
  1298. }
  1299. break;
  1300. case mode_ai:
  1301. /* register *= 16-bit unsigned immediate
  1302. Example:
  1303. addi r1,123 */
  1304. ans = parse_gen_reg (&str, &r1);
  1305. if (ans < 0)
  1306. {
  1307. as_bad ("Dest register required");
  1308. return;
  1309. }
  1310. opcode |= (r1 << 16);
  1311. str = skip_space (str);
  1312. if (*str != ',')
  1313. {
  1314. as_bad ("immediate value missing");
  1315. return;
  1316. }
  1317. this_dest = r1;
  1318. /* fall through... */
  1319. case mode_i:
  1320. /* MOVIL/WRTL traditionally get an implicit "%l" applied
  1321. to their immediate value. For other opcodes, unless
  1322. the immediate value is decorated with "%u" or "%l"
  1323. it must be in the range 0 .. 65535. */
  1324. if ((opcode & 0x7fe00000) == 0x04800000
  1325. || (opcode & 0x7fe00000) == 0x05000000)
  1326. reloc = BFD_RELOC_VISIUM_LO16;
  1327. else
  1328. reloc = BFD_RELOC_VISIUM_IM16;
  1329. str = skip_space (str + 1);
  1330. if (*str == '%')
  1331. {
  1332. if (str[1] == 'u')
  1333. reloc = BFD_RELOC_VISIUM_HI16;
  1334. else if (str[1] == 'l')
  1335. reloc = BFD_RELOC_VISIUM_LO16;
  1336. else
  1337. {
  1338. as_bad ("bad char after %%");
  1339. return;
  1340. }
  1341. str += 2;
  1342. }
  1343. str = parse_exp (str, &e1);
  1344. if (e1.X_op != O_absent)
  1345. {
  1346. if (e1.X_op == O_constant)
  1347. {
  1348. int imm = e1.X_add_number;
  1349. if (reloc == BFD_RELOC_VISIUM_HI16)
  1350. opcode |= ((imm >> 16) & 0xffff);
  1351. else if (reloc == BFD_RELOC_VISIUM_LO16)
  1352. opcode |= (imm & 0xffff);
  1353. else
  1354. {
  1355. if (imm < 0 || imm > 0xffff)
  1356. as_bad ("immediate value out of range");
  1357. opcode |= (imm & 0xffff);
  1358. }
  1359. /* No relocation is needed. */
  1360. reloc = 0;
  1361. }
  1362. }
  1363. else
  1364. {
  1365. as_bad ("immediate value missing");
  1366. return;
  1367. }
  1368. break;
  1369. case mode_bax:
  1370. /* register * register * 5-bit immediate,
  1371. SourceB * SourceA * Index
  1372. Examples
  1373. write.l (r1),r2
  1374. write.l 3(r1),r2 */
  1375. str = skip_space (str);
  1376. indx = 0;
  1377. if (*str != '(')
  1378. {
  1379. str = parse_exp (str, &e1);
  1380. if (e1.X_op == O_constant)
  1381. {
  1382. indx = e1.X_add_number;
  1383. if (indx < 0 || indx > 31)
  1384. {
  1385. as_bad ("Index out of range");
  1386. return;
  1387. }
  1388. }
  1389. else
  1390. {
  1391. as_bad ("Index(SourceA) required");
  1392. return;
  1393. }
  1394. }
  1395. str = skip_space (str);
  1396. if (*str != '(')
  1397. {
  1398. as_bad ("Index(SourceA) required");
  1399. return;
  1400. }
  1401. str = skip_space (str + 1);
  1402. ans = parse_gen_reg (&str, &r1);
  1403. if (ans < 0)
  1404. {
  1405. as_bad ("SourceA register required");
  1406. return;
  1407. }
  1408. str = skip_space (str);
  1409. if (*str != ')')
  1410. {
  1411. as_bad ("(SourceA) required");
  1412. return;
  1413. }
  1414. str = skip_space (str + 1);
  1415. if (*str == ',')
  1416. {
  1417. str = skip_space (str + 1);
  1418. ans = parse_gen_reg (&str, &r2);
  1419. if (ans < 0)
  1420. {
  1421. as_bad ("SourceB register required");
  1422. return;
  1423. }
  1424. }
  1425. else
  1426. {
  1427. as_bad ("SourceB register required");
  1428. return;
  1429. }
  1430. opcode |= (r1 << 16) | (r2 << 4) | ((indx & 0x1f) << 10);
  1431. if (indx != 0 && previous_mode == mode_cad)
  1432. {
  1433. /* We're in a delay slot.
  1434. If the base reg is the destination of the branch, then issue
  1435. an error message.
  1436. Otherwise it is safe to use the base and index. */
  1437. if (previous_dest != 0 && r1 == previous_dest)
  1438. {
  1439. as_bad ("base register not ready");
  1440. return;
  1441. }
  1442. }
  1443. else if (previous_dest != 0
  1444. && r1 == previous_dest
  1445. && (visium_arch == VISIUM_ARCH_MCM
  1446. || visium_arch == VISIUM_ARCH_MCM24
  1447. || (visium_arch == VISIUM_ARCH_DEF && indx != 0)))
  1448. {
  1449. as_warn ("base register not ready, NOP inserted.");
  1450. /* Insert a NOP before the write instruction. */
  1451. output = frag_more (4);
  1452. memset (output, 0, 4);
  1453. }
  1454. break;
  1455. case mode_dax:
  1456. /* register := register * 5-bit immediate
  1457. Examples:
  1458. read.b r1,(r2)
  1459. read.w r1,3(r2) */
  1460. ans = parse_gen_reg (&str, &r1);
  1461. if (ans < 0)
  1462. {
  1463. as_bad ("Dest register required");
  1464. return;
  1465. }
  1466. str = skip_space (str);
  1467. if (*str != ',')
  1468. {
  1469. as_bad ("SourceA required");
  1470. return;
  1471. }
  1472. str = skip_space (str + 1);
  1473. indx = 0;
  1474. if (*str != '(')
  1475. {
  1476. str = parse_exp (str, &e1);
  1477. if (e1.X_op == O_constant)
  1478. {
  1479. indx = e1.X_add_number;
  1480. if (indx < 0 || indx > 31)
  1481. {
  1482. as_bad ("Index out of range");
  1483. return;
  1484. }
  1485. }
  1486. else
  1487. {
  1488. as_bad ("Immediate 0 to 31 required");
  1489. return;
  1490. }
  1491. }
  1492. if (*str != '(')
  1493. {
  1494. as_bad ("(SourceA) required");
  1495. return;
  1496. }
  1497. str++;
  1498. ans = parse_gen_reg (&str, &r2);
  1499. if (ans < 0)
  1500. {
  1501. as_bad ("SourceA register required");
  1502. return;
  1503. }
  1504. str = skip_space (str);
  1505. if (*str != ')')
  1506. {
  1507. as_bad ("(SourceA) required");
  1508. return;
  1509. }
  1510. str++;
  1511. opcode |= (r1 << 10) | (r2 << 16) | ((indx & 0x1f) << 4);
  1512. this_dest = r1;
  1513. if (indx != 0 && previous_mode == mode_cad)
  1514. {
  1515. /* We're in a delay slot.
  1516. If the base reg is the destination of the branch, then issue
  1517. an error message.
  1518. Otherwise it is safe to use the base and index. */
  1519. if (previous_dest != 0 && r2 == previous_dest)
  1520. {
  1521. as_bad ("base register not ready");
  1522. return;
  1523. }
  1524. }
  1525. else if (previous_dest != 0
  1526. && r2 == previous_dest
  1527. && (visium_arch == VISIUM_ARCH_MCM
  1528. || visium_arch == VISIUM_ARCH_MCM24
  1529. || (visium_arch == VISIUM_ARCH_DEF && indx != 0)))
  1530. {
  1531. as_warn ("base register not ready, NOP inserted.");
  1532. /* Insert a NOP before the read instruction. */
  1533. output = frag_more (4);
  1534. memset (output, 0, 4);
  1535. }
  1536. break;
  1537. case mode_s:
  1538. /* special mode
  1539. Example:
  1540. nop */
  1541. str = skip_space (str);
  1542. break;
  1543. case mode_ci:
  1544. /* condition * 16-bit signed word displacement
  1545. Example:
  1546. brr L1 */
  1547. ans = parse_cc (&str, &cc);
  1548. if (ans < 0)
  1549. {
  1550. as_bad ("condition code required");
  1551. return;
  1552. }
  1553. opcode |= (cc << 27);
  1554. str = skip_space (str);
  1555. if (*str == ',')
  1556. {
  1557. str = skip_space (str + 1);
  1558. str = parse_exp (str, &e1);
  1559. if (e1.X_op != O_absent)
  1560. {
  1561. if (e1.X_op == O_constant)
  1562. {
  1563. int imm = e1.X_add_number;
  1564. if (imm < -32768 || imm > 32767)
  1565. as_bad ("immediate value out of range");
  1566. /* The GR6 doesn't correctly handle a 0 displacement
  1567. so we insert a NOP and change it to -1. */
  1568. if (imm == 0 && cc != 0 && visium_arch == VISIUM_ARCH_GR6)
  1569. {
  1570. output = frag_more (4);
  1571. memset (output, 0, 4);
  1572. imm = -1;
  1573. }
  1574. opcode |= (imm & 0xffff);
  1575. }
  1576. else if (e1.X_op == O_symbol)
  1577. {
  1578. /* The GR6 doesn't correctly handle a 0 displacement
  1579. so the instruction requires relaxation. */
  1580. if (cc != 0 && visium_arch == VISIUM_ARCH_GR6)
  1581. relax = amode;
  1582. else
  1583. reloc = BFD_RELOC_VISIUM_REL16;
  1584. }
  1585. else
  1586. {
  1587. as_bad ("immediate value missing");
  1588. return;
  1589. }
  1590. }
  1591. else
  1592. {
  1593. as_bad ("immediate value missing");
  1594. return;
  1595. }
  1596. }
  1597. else
  1598. {
  1599. as_bad ("immediate value missing");
  1600. return;
  1601. }
  1602. if (previous_mode == mode_cad || previous_mode == mode_ci)
  1603. as_bad ("branch instruction in delay slot");
  1604. condition_code = cc;
  1605. break;
  1606. case mode_fdab:
  1607. /* float := float * float
  1608. Example
  1609. fadd f4,f3,f2 */
  1610. ans = parse_fp_reg (&str, &r1);
  1611. if (ans < 0)
  1612. {
  1613. as_bad ("floating point destination register required");
  1614. return;
  1615. }
  1616. str = skip_space (str);
  1617. if (*str == ',')
  1618. {
  1619. str++;
  1620. ans = parse_fp_reg (&str, &r2);
  1621. if (ans < 0)
  1622. {
  1623. as_bad ("floating point SourceA register required");
  1624. return;
  1625. }
  1626. str = skip_space (str);
  1627. if (*str == ',')
  1628. {
  1629. str++;
  1630. ans = parse_fp_reg (&str, &r3);
  1631. if (ans < 0)
  1632. {
  1633. as_bad ("floating point SourceB register required");
  1634. return;
  1635. }
  1636. /* Got 3 floating regs, assemble instruction. */
  1637. opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
  1638. }
  1639. else
  1640. {
  1641. as_bad ("floating point SourceB register required");
  1642. return;
  1643. }
  1644. }
  1645. else
  1646. {
  1647. as_bad ("floating point SourceA register required");
  1648. return;
  1649. }
  1650. break;
  1651. case mode_ifdab:
  1652. /* 4-bit immediate * float * float * float
  1653. Example
  1654. fpinst 10,f1,f2,f3 */
  1655. str = parse_exp (str, &e1);
  1656. str = skip_space (str);
  1657. if (e1.X_op != O_absent && *str == ',')
  1658. {
  1659. int finst = e1.X_add_number;
  1660. str = skip_space (str + 1);
  1661. ans = parse_fp_reg (&str, &r1);
  1662. if (ans < 0)
  1663. {
  1664. as_bad ("floating point destination register required");
  1665. return;
  1666. }
  1667. str = skip_space (str);
  1668. if (*str == ',')
  1669. {
  1670. str++;
  1671. ans = parse_fp_reg (&str, &r2);
  1672. if (ans < 0)
  1673. {
  1674. as_bad ("floating point SourceA register required");
  1675. return;
  1676. }
  1677. str = skip_space (str);
  1678. if (*str == ',')
  1679. {
  1680. str++;
  1681. ans = parse_fp_reg (&str, &r3);
  1682. if (ans < 0)
  1683. {
  1684. as_bad ("floating point SourceB register required");
  1685. return;
  1686. }
  1687. /* Got immediate and 3 floating regs,
  1688. assemble instruction. */
  1689. if (finst < 0 || finst > 15)
  1690. as_bad ("finst out of range");
  1691. opcode |=
  1692. ((finst & 0xf) << 27) | (r1 << 10) | (r2 << 16) | (r3 <<
  1693. 4);
  1694. }
  1695. else
  1696. {
  1697. as_bad ("floating point SourceB register required");
  1698. return;
  1699. }
  1700. }
  1701. else
  1702. {
  1703. as_bad ("floating point SourceA register required");
  1704. return;
  1705. }
  1706. }
  1707. else
  1708. {
  1709. as_bad ("finst missing");
  1710. return;
  1711. }
  1712. break;
  1713. case mode_idfab:
  1714. /* 4-bit immediate * register * float * float
  1715. Example
  1716. fpuread 4,r25,f2,f3 */
  1717. str = parse_exp (str, &e1);
  1718. str = skip_space (str);
  1719. if (e1.X_op != O_absent && *str == ',')
  1720. {
  1721. int finst = e1.X_add_number;
  1722. str = skip_space (str + 1);
  1723. ans = parse_gen_reg (&str, &r1);
  1724. if (ans < 0)
  1725. {
  1726. as_bad ("destination general register required");
  1727. return;
  1728. }
  1729. str = skip_space (str);
  1730. if (*str == ',')
  1731. {
  1732. str++;
  1733. ans = parse_fp_reg (&str, &r2);
  1734. if (ans < 0)
  1735. {
  1736. as_bad ("floating point SourceA register required");
  1737. return;
  1738. }
  1739. str = skip_space (str);
  1740. if (*str == ',')
  1741. {
  1742. str++;
  1743. ans = parse_fp_reg (&str, &r3);
  1744. if (ans < 0)
  1745. {
  1746. as_bad ("floating point SourceB register required");
  1747. return;
  1748. }
  1749. /* Got immediate and 3 floating regs,
  1750. assemble instruction. */
  1751. if (finst < 0 || finst > 15)
  1752. as_bad ("finst out of range");
  1753. opcode |=
  1754. ((finst & 0xf) << 27) | (r1 << 10) | (r2 << 16) | (r3 <<
  1755. 4);
  1756. }
  1757. else
  1758. {
  1759. as_bad ("floating point SourceB register required");
  1760. return;
  1761. }
  1762. }
  1763. else
  1764. {
  1765. as_bad ("floating point SourceA register required");
  1766. return;
  1767. }
  1768. }
  1769. else
  1770. {
  1771. as_bad ("finst missing");
  1772. return;
  1773. }
  1774. break;
  1775. case mode_fda:
  1776. /* float := float
  1777. Example
  1778. fsqrt f4,f3 */
  1779. ans = parse_fp_reg (&str, &r1);
  1780. if (ans < 0)
  1781. {
  1782. as_bad ("floating point destination register required");
  1783. return;
  1784. }
  1785. str = skip_space (str);
  1786. if (*str == ',')
  1787. {
  1788. str++;
  1789. ans = parse_fp_reg (&str, &r2);
  1790. if (ans < 0)
  1791. {
  1792. as_bad ("floating point source register required");
  1793. return;
  1794. }
  1795. /* Got 2 floating regs, assemble instruction. */
  1796. opcode |= (r1 << 10) | (r2 << 16);
  1797. }
  1798. else
  1799. {
  1800. as_bad ("floating point source register required");
  1801. return;
  1802. }
  1803. break;
  1804. case mode_fdra:
  1805. /* float := register
  1806. Example
  1807. fload f15,r6 */
  1808. ans = parse_fp_reg (&str, &r1);
  1809. if (ans < 0)
  1810. {
  1811. as_bad ("floating point destination register required");
  1812. return;
  1813. }
  1814. str = skip_space (str);
  1815. if (*str == ',')
  1816. {
  1817. str++;
  1818. ans = parse_gen_reg (&str, &r2);
  1819. if (ans < 0)
  1820. {
  1821. as_bad ("SourceA general register required");
  1822. return;
  1823. }
  1824. /* Got 2 regs, assemble instruction. */
  1825. opcode |= (r1 << 10) | (r2 << 16);
  1826. }
  1827. else
  1828. {
  1829. as_bad ("SourceA general register required");
  1830. return;
  1831. }
  1832. break;
  1833. case mode_rdfab:
  1834. /* register := float * float
  1835. Example
  1836. fcmp r0,f4,f8
  1837. For the GR6, register must be r0 and can be omitted. */
  1838. ans = parse_gen_reg (&str, &r1);
  1839. if (ans < 0)
  1840. {
  1841. if (visium_opcode_arch == VISIUM_OPCODE_ARCH_GR5)
  1842. {
  1843. as_bad ("Dest general register required");
  1844. return;
  1845. }
  1846. r1 = 0;
  1847. }
  1848. else
  1849. {
  1850. if (r1 != 0 && visium_opcode_arch != VISIUM_OPCODE_ARCH_GR5)
  1851. {
  1852. as_bad ("FCMP/FCMPE can only use r0 as Dest register");
  1853. return;
  1854. }
  1855. str = skip_space (str);
  1856. if (*str == ',')
  1857. str++;
  1858. else
  1859. {
  1860. as_bad ("floating point SourceA register required");
  1861. return;
  1862. }
  1863. }
  1864. ans = parse_fp_reg (&str, &r2);
  1865. if (ans < 0)
  1866. {
  1867. as_bad ("floating point SourceA register required");
  1868. return;
  1869. }
  1870. str = skip_space (str);
  1871. if (*str == ',')
  1872. {
  1873. str++;
  1874. ans = parse_fp_reg (&str, &r3);
  1875. if (ans < 0)
  1876. {
  1877. as_bad ("floating point SourceB register required");
  1878. return;
  1879. }
  1880. /* Got 3 regs, assemble instruction. */
  1881. opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
  1882. }
  1883. this_dest = r1;
  1884. break;
  1885. case mode_rdfa:
  1886. /* register := float
  1887. Example
  1888. fstore r5,f12 */
  1889. ans = parse_gen_reg (&str, &r1);
  1890. if (ans < 0)
  1891. {
  1892. as_bad ("Dest general register required");
  1893. return;
  1894. }
  1895. str = skip_space (str);
  1896. if (*str == ',')
  1897. {
  1898. str++;
  1899. ans = parse_fp_reg (&str, &r2);
  1900. if (ans < 0)
  1901. {
  1902. as_bad ("floating point source register required");
  1903. return;
  1904. }
  1905. /* Got 2 regs, assemble instruction. */
  1906. opcode |= (r1 << 10) | (r2 << 16);
  1907. }
  1908. else
  1909. {
  1910. as_bad ("floating point source register required");
  1911. return;
  1912. }
  1913. this_dest = r1;
  1914. break;
  1915. case mode_rrr:
  1916. /* register register register, all sources and destinations
  1917. Example:
  1918. bmd r1,r2,r3 */
  1919. ans = parse_gen_reg (&str, &r1);
  1920. if (ans < 0)
  1921. {
  1922. as_bad ("destination address register required");
  1923. return;
  1924. }
  1925. str = skip_space (str);
  1926. if (*str == ',')
  1927. {
  1928. str++;
  1929. ans = parse_gen_reg (&str, &r2);
  1930. if (ans < 0)
  1931. {
  1932. as_bad ("source address register required");
  1933. return;
  1934. }
  1935. str = skip_space (str);
  1936. if (*str == ',')
  1937. {
  1938. str++;
  1939. ans = parse_gen_reg (&str, &r3);
  1940. if (ans < 0)
  1941. {
  1942. as_bad ("count register required");
  1943. return;
  1944. }
  1945. /* We insist on three registers but the opcode can only use
  1946. r1,r2,r3. */
  1947. if (r1 != 1 || r2 != 2 || r3 != 3)
  1948. {
  1949. as_bad ("BMI/BMD can only use format op r1,r2,r3");
  1950. return;
  1951. }
  1952. /* Opcode is unmodified by what comes out of the table. */
  1953. }
  1954. else
  1955. {
  1956. as_bad ("register required");
  1957. return;
  1958. }
  1959. }
  1960. else
  1961. {
  1962. as_bad ("register required");
  1963. return;
  1964. }
  1965. this_dest = r1;
  1966. break;
  1967. default:
  1968. break;
  1969. }
  1970. if (relax)
  1971. output = frag_var (rs_machine_dependent, 8, 4, relax, e1.X_add_symbol,
  1972. e1.X_add_number, NULL);
  1973. else
  1974. output = frag_more (4);
  1975. /* Build the 32-bit instruction in a host-endian-neutral fashion. */
  1976. output[0] = (opcode >> 24) & 0xff;
  1977. output[1] = (opcode >> 16) & 0xff;
  1978. output[2] = (opcode >> 8) & 0xff;
  1979. output[3] = (opcode >> 0) & 0xff;
  1980. if (relax)
  1981. /* The size of the instruction is unknown, so tie the debug info to the
  1982. start of the instruction. */
  1983. dwarf2_emit_insn (0);
  1984. else
  1985. {
  1986. if (reloc)
  1987. fix_new_exp (frag_now, output - frag_now->fr_literal, 4, &e1,
  1988. reloc == BFD_RELOC_VISIUM_REL16, reloc);
  1989. else
  1990. visium_update_parity_bit (output);
  1991. dwarf2_emit_insn (4);
  1992. }
  1993. if (*str != '\0')
  1994. as_bad ("junk after instruction");
  1995. }
  1996. void
  1997. visium_cfi_frame_initial_instructions (void)
  1998. {
  1999. /* The CFA is in SP on function entry. */
  2000. cfi_add_CFA_def_cfa (23, 0);
  2001. }
  2002. int
  2003. visium_regname_to_dw2regnum (char *regname)
  2004. {
  2005. if (!regname[0])
  2006. return -1;
  2007. if (regname[0] == 'f' && regname[1] == 'p' && !regname[2])
  2008. return 22;
  2009. if (regname[0] == 's' && regname[1] == 'p' && !regname[2])
  2010. return 23;
  2011. if (regname[0] == 'm' && regname[1] == 'd' && !regname[3])
  2012. switch (regname[2])
  2013. {
  2014. case 'b': return 32;
  2015. case 'a': return 33;
  2016. case 'c': return 34;
  2017. default : return -1;
  2018. }
  2019. if (regname[0] == 'f' || regname[0] == 'r')
  2020. {
  2021. char *p;
  2022. unsigned int regnum = strtoul (regname + 1, &p, 10);
  2023. if (*p)
  2024. return -1;
  2025. if (regnum >= (regname[0] == 'f' ? 16 : 32))
  2026. return -1;
  2027. if (regname[0] == 'f')
  2028. regnum += 35;
  2029. return regnum;
  2030. }
  2031. return -1;
  2032. }