PageRenderTime 87ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/mingw-w64-v2.0.999/binutils/src/gas/config/tc-hppa.c

#
C | 8793 lines | 6692 code | 949 blank | 1152 comment | 2127 complexity | e37f474bfc1a5821e819997f4d82dff1 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, LGPL-3.0, Unlicense, GPL-2.0, LGPL-2.0, BSD-3-Clause, GPL-3.0
  1. /* tc-hppa.c -- Assemble for the PA
  2. Copyright 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
  3. 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012
  4. Free Software Foundation, Inc.
  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. /* HP PA-RISC support was contributed by the Center for Software Science
  19. at the University of Utah. */
  20. #include "as.h"
  21. #include "safe-ctype.h"
  22. #include "subsegs.h"
  23. #include "dw2gencfi.h"
  24. #include "bfd/libhppa.h"
  25. /* Be careful, this file includes data *declarations*. */
  26. #include "opcode/hppa.h"
  27. #if defined (OBJ_ELF) && defined (OBJ_SOM)
  28. error only one of OBJ_ELF and OBJ_SOM can be defined
  29. #endif
  30. /* If we are using ELF, then we probably can support dwarf2 debug
  31. records. Furthermore, if we are supporting dwarf2 debug records,
  32. then we want to use the assembler support for compact line numbers. */
  33. #ifdef OBJ_ELF
  34. #include "dwarf2dbg.h"
  35. /* A "convenient" place to put object file dependencies which do
  36. not need to be seen outside of tc-hppa.c. */
  37. /* Object file formats specify relocation types. */
  38. typedef enum elf_hppa_reloc_type reloc_type;
  39. /* Object file formats specify BFD symbol types. */
  40. typedef elf_symbol_type obj_symbol_type;
  41. #define symbol_arg_reloc_info(sym)\
  42. (((obj_symbol_type *) symbol_get_bfdsym (sym))->tc_data.hppa_arg_reloc)
  43. #if TARGET_ARCH_SIZE == 64
  44. /* How to generate a relocation. */
  45. #define hppa_gen_reloc_type _bfd_elf64_hppa_gen_reloc_type
  46. #define elf_hppa_reloc_final_type elf64_hppa_reloc_final_type
  47. #else
  48. #define hppa_gen_reloc_type _bfd_elf32_hppa_gen_reloc_type
  49. #define elf_hppa_reloc_final_type elf32_hppa_reloc_final_type
  50. #endif
  51. /* ELF objects can have versions, but apparently do not have anywhere
  52. to store a copyright string. */
  53. #define obj_version obj_elf_version
  54. #define obj_copyright obj_elf_version
  55. #define UNWIND_SECTION_NAME ".PARISC.unwind"
  56. #endif /* OBJ_ELF */
  57. #ifdef OBJ_SOM
  58. /* Names of various debugging spaces/subspaces. */
  59. #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
  60. #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
  61. #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
  62. #define UNWIND_SECTION_NAME "$UNWIND$"
  63. /* Object file formats specify relocation types. */
  64. typedef int reloc_type;
  65. /* SOM objects can have both a version string and a copyright string. */
  66. #define obj_version obj_som_version
  67. #define obj_copyright obj_som_copyright
  68. /* How to generate a relocation. */
  69. #define hppa_gen_reloc_type hppa_som_gen_reloc_type
  70. /* Object file formats specify BFD symbol types. */
  71. typedef som_symbol_type obj_symbol_type;
  72. #define symbol_arg_reloc_info(sym)\
  73. (((obj_symbol_type *) symbol_get_bfdsym (sym))->tc_data.ap.hppa_arg_reloc)
  74. /* This apparently isn't in older versions of hpux reloc.h. */
  75. #ifndef R_DLT_REL
  76. #define R_DLT_REL 0x78
  77. #endif
  78. #ifndef R_N0SEL
  79. #define R_N0SEL 0xd8
  80. #endif
  81. #ifndef R_N1SEL
  82. #define R_N1SEL 0xd9
  83. #endif
  84. #endif /* OBJ_SOM */
  85. #if TARGET_ARCH_SIZE == 64
  86. #define DEFAULT_LEVEL 25
  87. #else
  88. #define DEFAULT_LEVEL 10
  89. #endif
  90. /* Various structures and types used internally in tc-hppa.c. */
  91. /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
  92. struct unwind_desc
  93. {
  94. unsigned int cannot_unwind:1;
  95. unsigned int millicode:1;
  96. unsigned int millicode_save_rest:1;
  97. unsigned int region_desc:2;
  98. unsigned int save_sr:2;
  99. unsigned int entry_fr:4;
  100. unsigned int entry_gr:5;
  101. unsigned int args_stored:1;
  102. unsigned int call_fr:5;
  103. unsigned int call_gr:5;
  104. unsigned int save_sp:1;
  105. unsigned int save_rp:1;
  106. unsigned int save_rp_in_frame:1;
  107. unsigned int extn_ptr_defined:1;
  108. unsigned int cleanup_defined:1;
  109. unsigned int hpe_interrupt_marker:1;
  110. unsigned int hpux_interrupt_marker:1;
  111. unsigned int reserved:3;
  112. unsigned int frame_size:27;
  113. };
  114. /* We can't rely on compilers placing bitfields in any particular
  115. place, so use these macros when dumping unwind descriptors to
  116. object files. */
  117. #define UNWIND_LOW32(U) \
  118. (((U)->cannot_unwind << 31) \
  119. | ((U)->millicode << 30) \
  120. | ((U)->millicode_save_rest << 29) \
  121. | ((U)->region_desc << 27) \
  122. | ((U)->save_sr << 25) \
  123. | ((U)->entry_fr << 21) \
  124. | ((U)->entry_gr << 16) \
  125. | ((U)->args_stored << 15) \
  126. | ((U)->call_fr << 10) \
  127. | ((U)->call_gr << 5) \
  128. | ((U)->save_sp << 4) \
  129. | ((U)->save_rp << 3) \
  130. | ((U)->save_rp_in_frame << 2) \
  131. | ((U)->extn_ptr_defined << 1) \
  132. | ((U)->cleanup_defined << 0))
  133. #define UNWIND_HIGH32(U) \
  134. (((U)->hpe_interrupt_marker << 31) \
  135. | ((U)->hpux_interrupt_marker << 30) \
  136. | ((U)->frame_size << 0))
  137. struct unwind_table
  138. {
  139. /* Starting and ending offsets of the region described by
  140. descriptor. */
  141. unsigned int start_offset;
  142. unsigned int end_offset;
  143. struct unwind_desc descriptor;
  144. };
  145. /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
  146. control the entry and exit code they generate. It is also used in
  147. creation of the correct stack unwind descriptors.
  148. NOTE: GAS does not support .enter and .leave for the generation of
  149. prologues and epilogues. FIXME.
  150. The fields in structure roughly correspond to the arguments available on the
  151. .callinfo pseudo-op. */
  152. struct call_info
  153. {
  154. /* The unwind descriptor being built. */
  155. struct unwind_table ci_unwind;
  156. /* Name of this function. */
  157. symbolS *start_symbol;
  158. /* (temporary) symbol used to mark the end of this function. */
  159. symbolS *end_symbol;
  160. /* Next entry in the chain. */
  161. struct call_info *ci_next;
  162. };
  163. /* Operand formats for FP instructions. Note not all FP instructions
  164. allow all four formats to be used (for example fmpysub only allows
  165. SGL and DBL). */
  166. typedef enum
  167. {
  168. SGL, DBL, ILLEGAL_FMT, QUAD, W, UW, DW, UDW, QW, UQW
  169. }
  170. fp_operand_format;
  171. /* This fully describes the symbol types which may be attached to
  172. an EXPORT or IMPORT directive. Only SOM uses this formation
  173. (ELF has no need for it). */
  174. typedef enum
  175. {
  176. SYMBOL_TYPE_UNKNOWN,
  177. SYMBOL_TYPE_ABSOLUTE,
  178. SYMBOL_TYPE_CODE,
  179. SYMBOL_TYPE_DATA,
  180. SYMBOL_TYPE_ENTRY,
  181. SYMBOL_TYPE_MILLICODE,
  182. SYMBOL_TYPE_PLABEL,
  183. SYMBOL_TYPE_PRI_PROG,
  184. SYMBOL_TYPE_SEC_PROG,
  185. }
  186. pa_symbol_type;
  187. /* This structure contains information needed to assemble
  188. individual instructions. */
  189. struct pa_it
  190. {
  191. /* Holds the opcode after parsing by pa_ip. */
  192. unsigned long opcode;
  193. /* Holds an expression associated with the current instruction. */
  194. expressionS exp;
  195. /* Does this instruction use PC-relative addressing. */
  196. int pcrel;
  197. /* Floating point formats for operand1 and operand2. */
  198. fp_operand_format fpof1;
  199. fp_operand_format fpof2;
  200. /* Whether or not we saw a truncation request on an fcnv insn. */
  201. int trunc;
  202. /* Holds the field selector for this instruction
  203. (for example L%, LR%, etc). */
  204. long field_selector;
  205. /* Holds any argument relocation bits associated with this
  206. instruction. (instruction should be some sort of call). */
  207. unsigned int arg_reloc;
  208. /* The format specification for this instruction. */
  209. int format;
  210. /* The relocation (if any) associated with this instruction. */
  211. reloc_type reloc;
  212. };
  213. /* PA-89 floating point registers are arranged like this:
  214. +--------------+--------------+
  215. | 0 or 16L | 16 or 16R |
  216. +--------------+--------------+
  217. | 1 or 17L | 17 or 17R |
  218. +--------------+--------------+
  219. | | |
  220. . . .
  221. . . .
  222. . . .
  223. | | |
  224. +--------------+--------------+
  225. | 14 or 30L | 30 or 30R |
  226. +--------------+--------------+
  227. | 15 or 31L | 31 or 31R |
  228. +--------------+--------------+ */
  229. /* Additional information needed to build argument relocation stubs. */
  230. struct call_desc
  231. {
  232. /* The argument relocation specification. */
  233. unsigned int arg_reloc;
  234. /* Number of arguments. */
  235. unsigned int arg_count;
  236. };
  237. #ifdef OBJ_SOM
  238. /* This structure defines an entry in the subspace dictionary
  239. chain. */
  240. struct subspace_dictionary_chain
  241. {
  242. /* Nonzero if this space has been defined by the user code. */
  243. unsigned int ssd_defined;
  244. /* Name of this subspace. */
  245. char *ssd_name;
  246. /* GAS segment and subsegment associated with this subspace. */
  247. asection *ssd_seg;
  248. int ssd_subseg;
  249. /* Next space in the subspace dictionary chain. */
  250. struct subspace_dictionary_chain *ssd_next;
  251. };
  252. typedef struct subspace_dictionary_chain ssd_chain_struct;
  253. /* This structure defines an entry in the subspace dictionary
  254. chain. */
  255. struct space_dictionary_chain
  256. {
  257. /* Nonzero if this space has been defined by the user code or
  258. as a default space. */
  259. unsigned int sd_defined;
  260. /* Nonzero if this spaces has been defined by the user code. */
  261. unsigned int sd_user_defined;
  262. /* The space number (or index). */
  263. unsigned int sd_spnum;
  264. /* The name of this subspace. */
  265. char *sd_name;
  266. /* GAS segment to which this subspace corresponds. */
  267. asection *sd_seg;
  268. /* Current subsegment number being used. */
  269. int sd_last_subseg;
  270. /* The chain of subspaces contained within this space. */
  271. ssd_chain_struct *sd_subspaces;
  272. /* The next entry in the space dictionary chain. */
  273. struct space_dictionary_chain *sd_next;
  274. };
  275. typedef struct space_dictionary_chain sd_chain_struct;
  276. /* This structure defines attributes of the default subspace
  277. dictionary entries. */
  278. struct default_subspace_dict
  279. {
  280. /* Name of the subspace. */
  281. char *name;
  282. /* FIXME. Is this still needed? */
  283. char defined;
  284. /* Nonzero if this subspace is loadable. */
  285. char loadable;
  286. /* Nonzero if this subspace contains only code. */
  287. char code_only;
  288. /* Nonzero if this is a comdat subspace. */
  289. char comdat;
  290. /* Nonzero if this is a common subspace. */
  291. char common;
  292. /* Nonzero if this is a common subspace which allows symbols
  293. to be multiply defined. */
  294. char dup_common;
  295. /* Nonzero if this subspace should be zero filled. */
  296. char zero;
  297. /* Sort key for this subspace. */
  298. unsigned char sort;
  299. /* Access control bits for this subspace. Can represent RWX access
  300. as well as privilege level changes for gateways. */
  301. int access;
  302. /* Index of containing space. */
  303. int space_index;
  304. /* Alignment (in bytes) of this subspace. */
  305. int alignment;
  306. /* Quadrant within space where this subspace should be loaded. */
  307. int quadrant;
  308. /* An index into the default spaces array. */
  309. int def_space_index;
  310. /* Subsegment associated with this subspace. */
  311. subsegT subsegment;
  312. };
  313. /* This structure defines attributes of the default space
  314. dictionary entries. */
  315. struct default_space_dict
  316. {
  317. /* Name of the space. */
  318. char *name;
  319. /* Space number. It is possible to identify spaces within
  320. assembly code numerically! */
  321. int spnum;
  322. /* Nonzero if this space is loadable. */
  323. char loadable;
  324. /* Nonzero if this space is "defined". FIXME is still needed */
  325. char defined;
  326. /* Nonzero if this space can not be shared. */
  327. char private;
  328. /* Sort key for this space. */
  329. unsigned char sort;
  330. /* Segment associated with this space. */
  331. asection *segment;
  332. };
  333. #endif
  334. /* Structure for previous label tracking. Needed so that alignments,
  335. callinfo declarations, etc can be easily attached to a particular
  336. label. */
  337. typedef struct label_symbol_struct
  338. {
  339. struct symbol *lss_label;
  340. #ifdef OBJ_SOM
  341. sd_chain_struct *lss_space;
  342. #endif
  343. #ifdef OBJ_ELF
  344. segT lss_segment;
  345. #endif
  346. struct label_symbol_struct *lss_next;
  347. }
  348. label_symbol_struct;
  349. /* Extra information needed to perform fixups (relocations) on the PA. */
  350. struct hppa_fix_struct
  351. {
  352. /* The field selector. */
  353. enum hppa_reloc_field_selector_type_alt fx_r_field;
  354. /* Type of fixup. */
  355. int fx_r_type;
  356. /* Format of fixup. */
  357. int fx_r_format;
  358. /* Argument relocation bits. */
  359. unsigned int fx_arg_reloc;
  360. /* The segment this fixup appears in. */
  361. segT segment;
  362. };
  363. /* Structure to hold information about predefined registers. */
  364. struct pd_reg
  365. {
  366. char *name;
  367. int value;
  368. };
  369. /* This structure defines the mapping from a FP condition string
  370. to a condition number which can be recorded in an instruction. */
  371. struct fp_cond_map
  372. {
  373. char *string;
  374. int cond;
  375. };
  376. /* This structure defines a mapping from a field selector
  377. string to a field selector type. */
  378. struct selector_entry
  379. {
  380. char *prefix;
  381. int field_selector;
  382. };
  383. /* Prototypes for functions local to tc-hppa.c. */
  384. #ifdef OBJ_SOM
  385. static void pa_check_current_space_and_subspace (void);
  386. #endif
  387. #if !(defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD)))
  388. static void pa_text (int);
  389. static void pa_data (int);
  390. static void pa_comm (int);
  391. #endif
  392. #ifdef OBJ_SOM
  393. static int exact_log2 (int);
  394. static void pa_compiler (int);
  395. static void pa_align (int);
  396. static void pa_space (int);
  397. static void pa_spnum (int);
  398. static void pa_subspace (int);
  399. static sd_chain_struct *create_new_space (char *, int, int,
  400. int, int, int,
  401. asection *, int);
  402. static ssd_chain_struct *create_new_subspace (sd_chain_struct *,
  403. char *, int, int,
  404. int, int, int, int,
  405. int, int, int, int,
  406. int, asection *);
  407. static ssd_chain_struct *update_subspace (sd_chain_struct *,
  408. char *, int, int, int,
  409. int, int, int, int,
  410. int, int, int, int,
  411. asection *);
  412. static sd_chain_struct *is_defined_space (char *);
  413. static ssd_chain_struct *is_defined_subspace (char *);
  414. static sd_chain_struct *pa_segment_to_space (asection *);
  415. static ssd_chain_struct *pa_subsegment_to_subspace (asection *,
  416. subsegT);
  417. static sd_chain_struct *pa_find_space_by_number (int);
  418. static unsigned int pa_subspace_start (sd_chain_struct *, int);
  419. static sd_chain_struct *pa_parse_space_stmt (char *, int);
  420. #endif
  421. /* File and globally scoped variable declarations. */
  422. #ifdef OBJ_SOM
  423. /* Root and final entry in the space chain. */
  424. static sd_chain_struct *space_dict_root;
  425. static sd_chain_struct *space_dict_last;
  426. /* The current space and subspace. */
  427. static sd_chain_struct *current_space;
  428. static ssd_chain_struct *current_subspace;
  429. #endif
  430. /* Root of the call_info chain. */
  431. static struct call_info *call_info_root;
  432. /* The last call_info (for functions) structure
  433. seen so it can be associated with fixups and
  434. function labels. */
  435. static struct call_info *last_call_info;
  436. /* The last call description (for actual calls). */
  437. static struct call_desc last_call_desc;
  438. /* handle of the OPCODE hash table */
  439. static struct hash_control *op_hash = NULL;
  440. /* These characters can be suffixes of opcode names and they may be
  441. followed by meaningful whitespace. We don't include `,' and `!'
  442. as they never appear followed by meaningful whitespace. */
  443. const char hppa_symbol_chars[] = "*?=<>";
  444. /* This array holds the chars that only start a comment at the beginning of
  445. a line. If the line seems to have the form '# 123 filename'
  446. .line and .file directives will appear in the pre-processed output.
  447. Note that input_file.c hand checks for '#' at the beginning of the
  448. first line of the input file. This is because the compiler outputs
  449. #NO_APP at the beginning of its output.
  450. Also note that C style comments will always work. */
  451. const char line_comment_chars[] = "#";
  452. /* This array holds the chars that always start a comment. If the
  453. pre-processor is disabled, these aren't very useful. */
  454. const char comment_chars[] = ";";
  455. /* This array holds the characters which act as line separators. */
  456. const char line_separator_chars[] = "!";
  457. /* Chars that can be used to separate mant from exp in floating point nums. */
  458. const char EXP_CHARS[] = "eE";
  459. /* Chars that mean this number is a floating point constant.
  460. As in 0f12.456 or 0d1.2345e12.
  461. Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  462. changed in read.c. Ideally it shouldn't have to know about it
  463. at all, but nothing is ideal around here. */
  464. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  465. static struct pa_it the_insn;
  466. /* Points to the end of an expression just parsed by get_expression
  467. and friends. FIXME. This shouldn't be handled with a file-global
  468. variable. */
  469. static char *expr_end;
  470. /* Nonzero if a .callinfo appeared within the current procedure. */
  471. static int callinfo_found;
  472. /* Nonzero if the assembler is currently within a .entry/.exit pair. */
  473. static int within_entry_exit;
  474. /* Nonzero if the assembler is currently within a procedure definition. */
  475. static int within_procedure;
  476. /* Handle on structure which keep track of the last symbol
  477. seen in each subspace. */
  478. static label_symbol_struct *label_symbols_rootp = NULL;
  479. /* Holds the last field selector. */
  480. static int hppa_field_selector;
  481. /* Nonzero when strict matching is enabled. Zero otherwise.
  482. Each opcode in the table has a flag which indicates whether or
  483. not strict matching should be enabled for that instruction.
  484. Mainly, strict causes errors to be ignored when a match failure
  485. occurs. However, it also affects the parsing of register fields
  486. by pa_parse_number. */
  487. static int strict;
  488. /* pa_parse_number returns values in `pa_number'. Mostly
  489. pa_parse_number is used to return a register number, with floating
  490. point registers being numbered from FP_REG_BASE upwards.
  491. The bit specified with FP_REG_RSEL is set if the floating point
  492. register has a `r' suffix. */
  493. #define FP_REG_BASE 64
  494. #define FP_REG_RSEL 128
  495. static int pa_number;
  496. #ifdef OBJ_SOM
  497. /* A dummy bfd symbol so that all relocations have symbols of some kind. */
  498. static symbolS *dummy_symbol;
  499. #endif
  500. /* Nonzero if errors are to be printed. */
  501. static int print_errors = 1;
  502. /* List of registers that are pre-defined:
  503. Each general register has one predefined name of the form
  504. %r<REGNUM> which has the value <REGNUM>.
  505. Space and control registers are handled in a similar manner,
  506. but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
  507. Likewise for the floating point registers, but of the form
  508. %fr<REGNUM>. Floating point registers have additional predefined
  509. names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
  510. again have the value <REGNUM>.
  511. Many registers also have synonyms:
  512. %r26 - %r23 have %arg0 - %arg3 as synonyms
  513. %r28 - %r29 have %ret0 - %ret1 as synonyms
  514. %fr4 - %fr7 have %farg0 - %farg3 as synonyms
  515. %r30 has %sp as a synonym
  516. %r27 has %dp as a synonym
  517. %r2 has %rp as a synonym
  518. Almost every control register has a synonym; they are not listed
  519. here for brevity.
  520. The table is sorted. Suitable for searching by a binary search. */
  521. static const struct pd_reg pre_defined_registers[] =
  522. {
  523. {"%arg0", 26},
  524. {"%arg1", 25},
  525. {"%arg2", 24},
  526. {"%arg3", 23},
  527. {"%cr0", 0},
  528. {"%cr10", 10},
  529. {"%cr11", 11},
  530. {"%cr12", 12},
  531. {"%cr13", 13},
  532. {"%cr14", 14},
  533. {"%cr15", 15},
  534. {"%cr16", 16},
  535. {"%cr17", 17},
  536. {"%cr18", 18},
  537. {"%cr19", 19},
  538. {"%cr20", 20},
  539. {"%cr21", 21},
  540. {"%cr22", 22},
  541. {"%cr23", 23},
  542. {"%cr24", 24},
  543. {"%cr25", 25},
  544. {"%cr26", 26},
  545. {"%cr27", 27},
  546. {"%cr28", 28},
  547. {"%cr29", 29},
  548. {"%cr30", 30},
  549. {"%cr31", 31},
  550. {"%cr8", 8},
  551. {"%cr9", 9},
  552. {"%dp", 27},
  553. {"%eiem", 15},
  554. {"%eirr", 23},
  555. {"%farg0", 4 + FP_REG_BASE},
  556. {"%farg1", 5 + FP_REG_BASE},
  557. {"%farg2", 6 + FP_REG_BASE},
  558. {"%farg3", 7 + FP_REG_BASE},
  559. {"%fr0", 0 + FP_REG_BASE},
  560. {"%fr0l", 0 + FP_REG_BASE},
  561. {"%fr0r", 0 + FP_REG_BASE + FP_REG_RSEL},
  562. {"%fr1", 1 + FP_REG_BASE},
  563. {"%fr10", 10 + FP_REG_BASE},
  564. {"%fr10l", 10 + FP_REG_BASE},
  565. {"%fr10r", 10 + FP_REG_BASE + FP_REG_RSEL},
  566. {"%fr11", 11 + FP_REG_BASE},
  567. {"%fr11l", 11 + FP_REG_BASE},
  568. {"%fr11r", 11 + FP_REG_BASE + FP_REG_RSEL},
  569. {"%fr12", 12 + FP_REG_BASE},
  570. {"%fr12l", 12 + FP_REG_BASE},
  571. {"%fr12r", 12 + FP_REG_BASE + FP_REG_RSEL},
  572. {"%fr13", 13 + FP_REG_BASE},
  573. {"%fr13l", 13 + FP_REG_BASE},
  574. {"%fr13r", 13 + FP_REG_BASE + FP_REG_RSEL},
  575. {"%fr14", 14 + FP_REG_BASE},
  576. {"%fr14l", 14 + FP_REG_BASE},
  577. {"%fr14r", 14 + FP_REG_BASE + FP_REG_RSEL},
  578. {"%fr15", 15 + FP_REG_BASE},
  579. {"%fr15l", 15 + FP_REG_BASE},
  580. {"%fr15r", 15 + FP_REG_BASE + FP_REG_RSEL},
  581. {"%fr16", 16 + FP_REG_BASE},
  582. {"%fr16l", 16 + FP_REG_BASE},
  583. {"%fr16r", 16 + FP_REG_BASE + FP_REG_RSEL},
  584. {"%fr17", 17 + FP_REG_BASE},
  585. {"%fr17l", 17 + FP_REG_BASE},
  586. {"%fr17r", 17 + FP_REG_BASE + FP_REG_RSEL},
  587. {"%fr18", 18 + FP_REG_BASE},
  588. {"%fr18l", 18 + FP_REG_BASE},
  589. {"%fr18r", 18 + FP_REG_BASE + FP_REG_RSEL},
  590. {"%fr19", 19 + FP_REG_BASE},
  591. {"%fr19l", 19 + FP_REG_BASE},
  592. {"%fr19r", 19 + FP_REG_BASE + FP_REG_RSEL},
  593. {"%fr1l", 1 + FP_REG_BASE},
  594. {"%fr1r", 1 + FP_REG_BASE + FP_REG_RSEL},
  595. {"%fr2", 2 + FP_REG_BASE},
  596. {"%fr20", 20 + FP_REG_BASE},
  597. {"%fr20l", 20 + FP_REG_BASE},
  598. {"%fr20r", 20 + FP_REG_BASE + FP_REG_RSEL},
  599. {"%fr21", 21 + FP_REG_BASE},
  600. {"%fr21l", 21 + FP_REG_BASE},
  601. {"%fr21r", 21 + FP_REG_BASE + FP_REG_RSEL},
  602. {"%fr22", 22 + FP_REG_BASE},
  603. {"%fr22l", 22 + FP_REG_BASE},
  604. {"%fr22r", 22 + FP_REG_BASE + FP_REG_RSEL},
  605. {"%fr23", 23 + FP_REG_BASE},
  606. {"%fr23l", 23 + FP_REG_BASE},
  607. {"%fr23r", 23 + FP_REG_BASE + FP_REG_RSEL},
  608. {"%fr24", 24 + FP_REG_BASE},
  609. {"%fr24l", 24 + FP_REG_BASE},
  610. {"%fr24r", 24 + FP_REG_BASE + FP_REG_RSEL},
  611. {"%fr25", 25 + FP_REG_BASE},
  612. {"%fr25l", 25 + FP_REG_BASE},
  613. {"%fr25r", 25 + FP_REG_BASE + FP_REG_RSEL},
  614. {"%fr26", 26 + FP_REG_BASE},
  615. {"%fr26l", 26 + FP_REG_BASE},
  616. {"%fr26r", 26 + FP_REG_BASE + FP_REG_RSEL},
  617. {"%fr27", 27 + FP_REG_BASE},
  618. {"%fr27l", 27 + FP_REG_BASE},
  619. {"%fr27r", 27 + FP_REG_BASE + FP_REG_RSEL},
  620. {"%fr28", 28 + FP_REG_BASE},
  621. {"%fr28l", 28 + FP_REG_BASE},
  622. {"%fr28r", 28 + FP_REG_BASE + FP_REG_RSEL},
  623. {"%fr29", 29 + FP_REG_BASE},
  624. {"%fr29l", 29 + FP_REG_BASE},
  625. {"%fr29r", 29 + FP_REG_BASE + FP_REG_RSEL},
  626. {"%fr2l", 2 + FP_REG_BASE},
  627. {"%fr2r", 2 + FP_REG_BASE + FP_REG_RSEL},
  628. {"%fr3", 3 + FP_REG_BASE},
  629. {"%fr30", 30 + FP_REG_BASE},
  630. {"%fr30l", 30 + FP_REG_BASE},
  631. {"%fr30r", 30 + FP_REG_BASE + FP_REG_RSEL},
  632. {"%fr31", 31 + FP_REG_BASE},
  633. {"%fr31l", 31 + FP_REG_BASE},
  634. {"%fr31r", 31 + FP_REG_BASE + FP_REG_RSEL},
  635. {"%fr3l", 3 + FP_REG_BASE},
  636. {"%fr3r", 3 + FP_REG_BASE + FP_REG_RSEL},
  637. {"%fr4", 4 + FP_REG_BASE},
  638. {"%fr4l", 4 + FP_REG_BASE},
  639. {"%fr4r", 4 + FP_REG_BASE + FP_REG_RSEL},
  640. {"%fr5", 5 + FP_REG_BASE},
  641. {"%fr5l", 5 + FP_REG_BASE},
  642. {"%fr5r", 5 + FP_REG_BASE + FP_REG_RSEL},
  643. {"%fr6", 6 + FP_REG_BASE},
  644. {"%fr6l", 6 + FP_REG_BASE},
  645. {"%fr6r", 6 + FP_REG_BASE + FP_REG_RSEL},
  646. {"%fr7", 7 + FP_REG_BASE},
  647. {"%fr7l", 7 + FP_REG_BASE},
  648. {"%fr7r", 7 + FP_REG_BASE + FP_REG_RSEL},
  649. {"%fr8", 8 + FP_REG_BASE},
  650. {"%fr8l", 8 + FP_REG_BASE},
  651. {"%fr8r", 8 + FP_REG_BASE + FP_REG_RSEL},
  652. {"%fr9", 9 + FP_REG_BASE},
  653. {"%fr9l", 9 + FP_REG_BASE},
  654. {"%fr9r", 9 + FP_REG_BASE + FP_REG_RSEL},
  655. {"%fret", 4},
  656. {"%hta", 25},
  657. {"%iir", 19},
  658. {"%ior", 21},
  659. {"%ipsw", 22},
  660. {"%isr", 20},
  661. {"%itmr", 16},
  662. {"%iva", 14},
  663. #if TARGET_ARCH_SIZE == 64
  664. {"%mrp", 2},
  665. #else
  666. {"%mrp", 31},
  667. #endif
  668. {"%pcoq", 18},
  669. {"%pcsq", 17},
  670. {"%pidr1", 8},
  671. {"%pidr2", 9},
  672. {"%pidr3", 12},
  673. {"%pidr4", 13},
  674. {"%ppda", 24},
  675. {"%r0", 0},
  676. {"%r1", 1},
  677. {"%r10", 10},
  678. {"%r11", 11},
  679. {"%r12", 12},
  680. {"%r13", 13},
  681. {"%r14", 14},
  682. {"%r15", 15},
  683. {"%r16", 16},
  684. {"%r17", 17},
  685. {"%r18", 18},
  686. {"%r19", 19},
  687. {"%r2", 2},
  688. {"%r20", 20},
  689. {"%r21", 21},
  690. {"%r22", 22},
  691. {"%r23", 23},
  692. {"%r24", 24},
  693. {"%r25", 25},
  694. {"%r26", 26},
  695. {"%r27", 27},
  696. {"%r28", 28},
  697. {"%r29", 29},
  698. {"%r3", 3},
  699. {"%r30", 30},
  700. {"%r31", 31},
  701. {"%r4", 4},
  702. {"%r5", 5},
  703. {"%r6", 6},
  704. {"%r7", 7},
  705. {"%r8", 8},
  706. {"%r9", 9},
  707. {"%rctr", 0},
  708. {"%ret0", 28},
  709. {"%ret1", 29},
  710. {"%rp", 2},
  711. {"%sar", 11},
  712. {"%sp", 30},
  713. {"%sr0", 0},
  714. {"%sr1", 1},
  715. {"%sr2", 2},
  716. {"%sr3", 3},
  717. {"%sr4", 4},
  718. {"%sr5", 5},
  719. {"%sr6", 6},
  720. {"%sr7", 7},
  721. {"%t1", 22},
  722. {"%t2", 21},
  723. {"%t3", 20},
  724. {"%t4", 19},
  725. {"%tf1", 11},
  726. {"%tf2", 10},
  727. {"%tf3", 9},
  728. {"%tf4", 8},
  729. {"%tr0", 24},
  730. {"%tr1", 25},
  731. {"%tr2", 26},
  732. {"%tr3", 27},
  733. {"%tr4", 28},
  734. {"%tr5", 29},
  735. {"%tr6", 30},
  736. {"%tr7", 31}
  737. };
  738. /* This table is sorted by order of the length of the string. This is
  739. so we check for <> before we check for <. If we had a <> and checked
  740. for < first, we would get a false match. */
  741. static const struct fp_cond_map fp_cond_map[] =
  742. {
  743. {"false?", 0},
  744. {"false", 1},
  745. {"true?", 30},
  746. {"true", 31},
  747. {"!<=>", 3},
  748. {"!?>=", 8},
  749. {"!?<=", 16},
  750. {"!<>", 7},
  751. {"!>=", 11},
  752. {"!?>", 12},
  753. {"?<=", 14},
  754. {"!<=", 19},
  755. {"!?<", 20},
  756. {"?>=", 22},
  757. {"!?=", 24},
  758. {"!=t", 27},
  759. {"<=>", 29},
  760. {"=t", 5},
  761. {"?=", 6},
  762. {"?<", 10},
  763. {"<=", 13},
  764. {"!>", 15},
  765. {"?>", 18},
  766. {">=", 21},
  767. {"!<", 23},
  768. {"<>", 25},
  769. {"!=", 26},
  770. {"!?", 28},
  771. {"?", 2},
  772. {"=", 4},
  773. {"<", 9},
  774. {">", 17}
  775. };
  776. static const struct selector_entry selector_table[] =
  777. {
  778. {"f", e_fsel},
  779. {"l", e_lsel},
  780. {"ld", e_ldsel},
  781. {"lp", e_lpsel},
  782. {"lr", e_lrsel},
  783. {"ls", e_lssel},
  784. {"lt", e_ltsel},
  785. {"ltp", e_ltpsel},
  786. {"n", e_nsel},
  787. {"nl", e_nlsel},
  788. {"nlr", e_nlrsel},
  789. {"p", e_psel},
  790. {"r", e_rsel},
  791. {"rd", e_rdsel},
  792. {"rp", e_rpsel},
  793. {"rr", e_rrsel},
  794. {"rs", e_rssel},
  795. {"rt", e_rtsel},
  796. {"rtp", e_rtpsel},
  797. {"t", e_tsel},
  798. };
  799. #ifdef OBJ_SOM
  800. /* default space and subspace dictionaries */
  801. #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
  802. #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
  803. /* pre-defined subsegments (subspaces) for the HPPA. */
  804. #define SUBSEG_CODE 0
  805. #define SUBSEG_LIT 1
  806. #define SUBSEG_MILLI 2
  807. #define SUBSEG_DATA 0
  808. #define SUBSEG_BSS 2
  809. #define SUBSEG_UNWIND 3
  810. #define SUBSEG_GDB_STRINGS 0
  811. #define SUBSEG_GDB_SYMBOLS 1
  812. static struct default_subspace_dict pa_def_subspaces[] =
  813. {
  814. {"$CODE$", 1, 1, 1, 0, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, SUBSEG_CODE},
  815. {"$DATA$", 1, 1, 0, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, SUBSEG_DATA},
  816. {"$LIT$", 1, 1, 0, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, SUBSEG_LIT},
  817. {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, SUBSEG_MILLI},
  818. {"$BSS$", 1, 1, 0, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, SUBSEG_BSS},
  819. {NULL, 0, 1, 0, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
  820. };
  821. static struct default_space_dict pa_def_spaces[] =
  822. {
  823. {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL},
  824. {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL},
  825. {NULL, 0, 0, 0, 0, 0, ASEC_NULL}
  826. };
  827. /* Misc local definitions used by the assembler. */
  828. /* These macros are used to maintain spaces/subspaces. */
  829. #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
  830. #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
  831. #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
  832. #define SPACE_NAME(space_chain) (space_chain)->sd_name
  833. #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
  834. #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
  835. #endif
  836. /* Return nonzero if the string pointed to by S potentially represents
  837. a right or left half of a FP register */
  838. #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
  839. #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
  840. /* Store immediate values of shift/deposit/extract functions. */
  841. #define SAVE_IMMEDIATE(VALUE) \
  842. { \
  843. if (immediate_check) \
  844. { \
  845. if (pos == -1) \
  846. pos = (VALUE); \
  847. else if (len == -1) \
  848. len = (VALUE); \
  849. } \
  850. }
  851. /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
  852. main loop after insertion. */
  853. #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
  854. { \
  855. ((OPCODE) |= (FIELD) << (START)); \
  856. continue; \
  857. }
  858. /* Simple range checking for FIELD against HIGH and LOW bounds.
  859. IGNORE is used to suppress the error message. */
  860. #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
  861. { \
  862. if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
  863. { \
  864. if (! IGNORE) \
  865. as_bad (_("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
  866. (int) (FIELD));\
  867. break; \
  868. } \
  869. }
  870. /* Variant of CHECK_FIELD for use in md_apply_fix and other places where
  871. the current file and line number are not valid. */
  872. #define CHECK_FIELD_WHERE(FIELD, HIGH, LOW, FILENAME, LINE) \
  873. { \
  874. if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
  875. { \
  876. as_bad_where ((FILENAME), (LINE), \
  877. _("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
  878. (int) (FIELD));\
  879. break; \
  880. } \
  881. }
  882. /* Simple alignment checking for FIELD against ALIGN (a power of two).
  883. IGNORE is used to suppress the error message. */
  884. #define CHECK_ALIGN(FIELD, ALIGN, IGNORE) \
  885. { \
  886. if ((FIELD) & ((ALIGN) - 1)) \
  887. { \
  888. if (! IGNORE) \
  889. as_bad (_("Field not properly aligned [%d] (%d)."), (ALIGN), \
  890. (int) (FIELD));\
  891. break; \
  892. } \
  893. }
  894. #define is_DP_relative(exp) \
  895. ((exp).X_op == O_subtract \
  896. && strcmp (S_GET_NAME ((exp).X_op_symbol), "$global$") == 0)
  897. #define is_SB_relative(exp) \
  898. ((exp).X_op == O_subtract \
  899. && strcmp (S_GET_NAME ((exp).X_op_symbol), "$segrel$") == 0)
  900. #define is_PC_relative(exp) \
  901. ((exp).X_op == O_subtract \
  902. && strcmp (S_GET_NAME ((exp).X_op_symbol), "$PIC_pcrel$0") == 0)
  903. #define is_tls_gdidx(exp) \
  904. ((exp).X_op == O_subtract \
  905. && strcmp (S_GET_NAME ((exp).X_op_symbol), "$tls_gdidx$") == 0)
  906. #define is_tls_ldidx(exp) \
  907. ((exp).X_op == O_subtract \
  908. && strcmp (S_GET_NAME ((exp).X_op_symbol), "$tls_ldidx$") == 0)
  909. #define is_tls_dtpoff(exp) \
  910. ((exp).X_op == O_subtract \
  911. && strcmp (S_GET_NAME ((exp).X_op_symbol), "$tls_dtpoff$") == 0)
  912. #define is_tls_ieoff(exp) \
  913. ((exp).X_op == O_subtract \
  914. && strcmp (S_GET_NAME ((exp).X_op_symbol), "$tls_ieoff$") == 0)
  915. #define is_tls_leoff(exp) \
  916. ((exp).X_op == O_subtract \
  917. && strcmp (S_GET_NAME ((exp).X_op_symbol), "$tls_leoff$") == 0)
  918. /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
  919. always be able to reduce the expression to a constant, so we don't
  920. need real complex handling yet. */
  921. #define is_complex(exp) \
  922. ((exp).X_op != O_constant && (exp).X_op != O_symbol)
  923. /* Actual functions to implement the PA specific code for the assembler. */
  924. /* Called before writing the object file. Make sure entry/exit and
  925. proc/procend pairs match. */
  926. void
  927. pa_check_eof (void)
  928. {
  929. if (within_entry_exit)
  930. as_fatal (_("Missing .exit\n"));
  931. if (within_procedure)
  932. as_fatal (_("Missing .procend\n"));
  933. }
  934. /* Returns a pointer to the label_symbol_struct for the current space.
  935. or NULL if no label_symbol_struct exists for the current space. */
  936. static label_symbol_struct *
  937. pa_get_label (void)
  938. {
  939. label_symbol_struct *label_chain;
  940. for (label_chain = label_symbols_rootp;
  941. label_chain;
  942. label_chain = label_chain->lss_next)
  943. {
  944. #ifdef OBJ_SOM
  945. if (current_space == label_chain->lss_space && label_chain->lss_label)
  946. return label_chain;
  947. #endif
  948. #ifdef OBJ_ELF
  949. if (now_seg == label_chain->lss_segment && label_chain->lss_label)
  950. return label_chain;
  951. #endif
  952. }
  953. return NULL;
  954. }
  955. /* Defines a label for the current space. If one is already defined,
  956. this function will replace it with the new label. */
  957. void
  958. pa_define_label (symbolS *symbol)
  959. {
  960. label_symbol_struct *label_chain = pa_get_label ();
  961. if (label_chain)
  962. label_chain->lss_label = symbol;
  963. else
  964. {
  965. /* Create a new label entry and add it to the head of the chain. */
  966. label_chain = xmalloc (sizeof (label_symbol_struct));
  967. label_chain->lss_label = symbol;
  968. #ifdef OBJ_SOM
  969. label_chain->lss_space = current_space;
  970. #endif
  971. #ifdef OBJ_ELF
  972. label_chain->lss_segment = now_seg;
  973. #endif
  974. label_chain->lss_next = NULL;
  975. if (label_symbols_rootp)
  976. label_chain->lss_next = label_symbols_rootp;
  977. label_symbols_rootp = label_chain;
  978. }
  979. #ifdef OBJ_ELF
  980. dwarf2_emit_label (symbol);
  981. #endif
  982. }
  983. /* Removes a label definition for the current space.
  984. If there is no label_symbol_struct entry, then no action is taken. */
  985. static void
  986. pa_undefine_label (void)
  987. {
  988. label_symbol_struct *label_chain;
  989. label_symbol_struct *prev_label_chain = NULL;
  990. for (label_chain = label_symbols_rootp;
  991. label_chain;
  992. label_chain = label_chain->lss_next)
  993. {
  994. if (1
  995. #ifdef OBJ_SOM
  996. && current_space == label_chain->lss_space && label_chain->lss_label
  997. #endif
  998. #ifdef OBJ_ELF
  999. && now_seg == label_chain->lss_segment && label_chain->lss_label
  1000. #endif
  1001. )
  1002. {
  1003. /* Remove the label from the chain and free its memory. */
  1004. if (prev_label_chain)
  1005. prev_label_chain->lss_next = label_chain->lss_next;
  1006. else
  1007. label_symbols_rootp = label_chain->lss_next;
  1008. free (label_chain);
  1009. break;
  1010. }
  1011. prev_label_chain = label_chain;
  1012. }
  1013. }
  1014. /* An HPPA-specific version of fix_new. This is required because the HPPA
  1015. code needs to keep track of some extra stuff. Each call to fix_new_hppa
  1016. results in the creation of an instance of an hppa_fix_struct. An
  1017. hppa_fix_struct stores the extra information along with a pointer to the
  1018. original fixS. This is attached to the original fixup via the
  1019. tc_fix_data field. */
  1020. static void
  1021. fix_new_hppa (fragS *frag,
  1022. int where,
  1023. int size,
  1024. symbolS *add_symbol,
  1025. offsetT offset,
  1026. expressionS *exp,
  1027. int pcrel,
  1028. bfd_reloc_code_real_type r_type,
  1029. enum hppa_reloc_field_selector_type_alt r_field,
  1030. int r_format,
  1031. unsigned int arg_reloc,
  1032. int unwind_bits ATTRIBUTE_UNUSED)
  1033. {
  1034. fixS *new_fix;
  1035. struct hppa_fix_struct *hppa_fix = obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
  1036. if (exp != NULL)
  1037. new_fix = fix_new_exp (frag, where, size, exp, pcrel, r_type);
  1038. else
  1039. new_fix = fix_new (frag, where, size, add_symbol, offset, pcrel, r_type);
  1040. new_fix->tc_fix_data = (void *) hppa_fix;
  1041. hppa_fix->fx_r_type = r_type;
  1042. hppa_fix->fx_r_field = r_field;
  1043. hppa_fix->fx_r_format = r_format;
  1044. hppa_fix->fx_arg_reloc = arg_reloc;
  1045. hppa_fix->segment = now_seg;
  1046. #ifdef OBJ_SOM
  1047. if (r_type == R_ENTRY || r_type == R_EXIT)
  1048. new_fix->fx_offset = unwind_bits;
  1049. #endif
  1050. /* foo-$global$ is used to access non-automatic storage. $global$
  1051. is really just a marker and has served its purpose, so eliminate
  1052. it now so as not to confuse write.c. Ditto for $PIC_pcrel$0. */
  1053. if (new_fix->fx_subsy
  1054. && (strcmp (S_GET_NAME (new_fix->fx_subsy), "$global$") == 0
  1055. || strcmp (S_GET_NAME (new_fix->fx_subsy), "$segrel$") == 0
  1056. || strcmp (S_GET_NAME (new_fix->fx_subsy), "$PIC_pcrel$0") == 0
  1057. || strcmp (S_GET_NAME (new_fix->fx_subsy), "$tls_gdidx$") == 0
  1058. || strcmp (S_GET_NAME (new_fix->fx_subsy), "$tls_ldidx$") == 0
  1059. || strcmp (S_GET_NAME (new_fix->fx_subsy), "$tls_dtpoff$") == 0
  1060. || strcmp (S_GET_NAME (new_fix->fx_subsy), "$tls_ieoff$") == 0
  1061. || strcmp (S_GET_NAME (new_fix->fx_subsy), "$tls_leoff$") == 0))
  1062. new_fix->fx_subsy = NULL;
  1063. }
  1064. /* This fix_new is called by cons via TC_CONS_FIX_NEW.
  1065. hppa_field_selector is set by the parse_cons_expression_hppa. */
  1066. void
  1067. cons_fix_new_hppa (fragS *frag, int where, int size, expressionS *exp)
  1068. {
  1069. unsigned int rel_type;
  1070. /* Get a base relocation type. */
  1071. if (is_DP_relative (*exp))
  1072. rel_type = R_HPPA_GOTOFF;
  1073. else if (is_PC_relative (*exp))
  1074. rel_type = R_HPPA_PCREL_CALL;
  1075. #ifdef OBJ_ELF
  1076. else if (is_SB_relative (*exp))
  1077. rel_type = R_PARISC_SEGREL32;
  1078. else if (is_tls_gdidx (*exp))
  1079. rel_type = R_PARISC_TLS_GD21L;
  1080. else if (is_tls_ldidx (*exp))
  1081. rel_type = R_PARISC_TLS_LDM21L;
  1082. else if (is_tls_dtpoff (*exp))
  1083. rel_type = R_PARISC_TLS_LDO21L;
  1084. else if (is_tls_ieoff (*exp))
  1085. rel_type = R_PARISC_TLS_IE21L;
  1086. else if (is_tls_leoff (*exp))
  1087. rel_type = R_PARISC_TLS_LE21L;
  1088. #endif
  1089. else if (is_complex (*exp))
  1090. rel_type = R_HPPA_COMPLEX;
  1091. else
  1092. rel_type = R_HPPA;
  1093. if (hppa_field_selector != e_psel && hppa_field_selector != e_fsel)
  1094. {
  1095. as_warn (_("Invalid field selector. Assuming F%%."));
  1096. hppa_field_selector = e_fsel;
  1097. }
  1098. fix_new_hppa (frag, where, size,
  1099. (symbolS *) NULL, (offsetT) 0, exp, 0, rel_type,
  1100. hppa_field_selector, size * 8, 0, 0);
  1101. /* Reset field selector to its default state. */
  1102. hppa_field_selector = 0;
  1103. }
  1104. /* Mark (via expr_end) the end of an expression (I think). FIXME. */
  1105. static void
  1106. get_expression (char *str)
  1107. {
  1108. char *save_in;
  1109. asection *seg;
  1110. save_in = input_line_pointer;
  1111. input_line_pointer = str;
  1112. seg = expression (&the_insn.exp);
  1113. if (!(seg == absolute_section
  1114. || seg == undefined_section
  1115. || SEG_NORMAL (seg)))
  1116. {
  1117. as_warn (_("Bad segment in expression."));
  1118. expr_end = input_line_pointer;
  1119. input_line_pointer = save_in;
  1120. return;
  1121. }
  1122. expr_end = input_line_pointer;
  1123. input_line_pointer = save_in;
  1124. }
  1125. /* Parse a PA nullification completer (,n). Return nonzero if the
  1126. completer was found; return zero if no completer was found. */
  1127. static int
  1128. pa_parse_nullif (char **s)
  1129. {
  1130. int nullif;
  1131. nullif = 0;
  1132. if (**s == ',')
  1133. {
  1134. *s = *s + 1;
  1135. if (strncasecmp (*s, "n", 1) == 0)
  1136. nullif = 1;
  1137. else
  1138. {
  1139. as_bad (_("Invalid Nullification: (%c)"), **s);
  1140. nullif = 0;
  1141. }
  1142. *s = *s + 1;
  1143. }
  1144. return nullif;
  1145. }
  1146. char *
  1147. md_atof (int type, char *litP, int *sizeP)
  1148. {
  1149. return ieee_md_atof (type, litP, sizeP, TRUE);
  1150. }
  1151. /* Write out big-endian. */
  1152. void
  1153. md_number_to_chars (char *buf, valueT val, int n)
  1154. {
  1155. number_to_chars_bigendian (buf, val, n);
  1156. }
  1157. /* Translate internal representation of relocation info to BFD target
  1158. format. */
  1159. arelent **
  1160. tc_gen_reloc (asection *section, fixS *fixp)
  1161. {
  1162. arelent *reloc;
  1163. struct hppa_fix_struct *hppa_fixp;
  1164. static arelent *no_relocs = NULL;
  1165. arelent **relocs;
  1166. reloc_type **codes;
  1167. reloc_type code;
  1168. int n_relocs;
  1169. int i;
  1170. hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
  1171. if (fixp->fx_addsy == 0)
  1172. return &no_relocs;
  1173. gas_assert (hppa_fixp != 0);
  1174. gas_assert (section != 0);
  1175. reloc = xmalloc (sizeof (arelent));
  1176. reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  1177. *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  1178. /* Allow fixup_segment to recognize hand-written pc-relative relocations.
  1179. When we went through cons_fix_new_hppa, we classified them as complex. */
  1180. /* ??? It might be better to hide this +8 stuff in tc_cfi_emit_pcrel_expr,
  1181. undefine DIFF_EXPR_OK, and let these sorts of complex expressions fail
  1182. when R_HPPA_COMPLEX == R_PARISC_UNIMPLEMENTED. */
  1183. if (fixp->fx_r_type == (bfd_reloc_code_real_type) R_HPPA_COMPLEX
  1184. && fixp->fx_pcrel)
  1185. {
  1186. fixp->fx_r_type = R_HPPA_PCREL_CALL;
  1187. fixp->fx_offset += 8;
  1188. }
  1189. codes = hppa_gen_reloc_type (stdoutput,
  1190. fixp->fx_r_type,
  1191. hppa_fixp->fx_r_format,
  1192. hppa_fixp->fx_r_field,
  1193. fixp->fx_subsy != NULL,
  1194. symbol_get_bfdsym (fixp->fx_addsy));
  1195. if (codes == NULL)
  1196. {
  1197. as_bad_where (fixp->fx_file, fixp->fx_line, _("Cannot handle fixup"));
  1198. abort ();
  1199. }
  1200. for (n_relocs = 0; codes[n_relocs]; n_relocs++)
  1201. ;
  1202. relocs = xmalloc (sizeof (arelent *) * n_relocs + 1);
  1203. reloc = xmalloc (sizeof (arelent) * n_relocs);
  1204. for (i = 0; i < n_relocs; i++)
  1205. relocs[i] = &reloc[i];
  1206. relocs[n_relocs] = NULL;
  1207. #ifdef OBJ_ELF
  1208. switch (fixp->fx_r_type)
  1209. {
  1210. default:
  1211. gas_assert (n_relocs == 1);
  1212. code = *codes[0];
  1213. /* Now, do any processing that is dependent on the relocation type. */
  1214. switch (code)
  1215. {
  1216. case R_PARISC_DLTREL21L:
  1217. case R_PARISC_DLTREL14R:
  1218. case R_PARISC_DLTREL14F:
  1219. case R_PARISC_PLABEL32:
  1220. case R_PARISC_PLABEL21L:
  1221. case R_PARISC_PLABEL14R:
  1222. /* For plabel relocations, the addend of the
  1223. relocation should be either 0 (no static link) or 2
  1224. (static link required). This adjustment is done in
  1225. bfd/elf32-hppa.c:elf32_hppa_relocate_section.
  1226. We also slam a zero addend into the DLT relative relocs;
  1227. it doesn't make a lot of sense to use any addend since
  1228. it gets you a different (eg unknown) DLT entry. */
  1229. reloc->addend = 0;
  1230. break;
  1231. #ifdef ELF_ARG_RELOC
  1232. case R_PARISC_PCREL17R:
  1233. case R_PARISC_PCREL17F:
  1234. case R_PARISC_PCREL17C:
  1235. case R_PARISC_DIR17R:
  1236. case R_PARISC_DIR17F:
  1237. case R_PARISC_PCREL21L:
  1238. case R_PARISC_DIR21L:
  1239. reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc,
  1240. fixp->fx_offset);
  1241. break;
  1242. #endif
  1243. case R_PARISC_DIR32:
  1244. /* Facilitate hand-crafted unwind info. */
  1245. if (strcmp (section->name, UNWIND_SECTION_NAME) == 0)
  1246. code = R_PARISC_SEGREL32;
  1247. /* Fall thru */
  1248. default:
  1249. reloc->addend = fixp->fx_offset;
  1250. break;
  1251. }
  1252. reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  1253. *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  1254. reloc->howto = bfd_reloc_type_lookup (stdoutput,
  1255. (bfd_reloc_code_real_type) code);
  1256. reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1257. gas_assert (reloc->howto && (unsigned int) code == reloc->howto->type);
  1258. break;
  1259. }
  1260. #else /* OBJ_SOM */
  1261. /* Walk over reach relocation returned by the BFD backend. */
  1262. for (i = 0; i < n_relocs; i++)
  1263. {
  1264. code = *codes[i];
  1265. relocs[i]->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  1266. *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  1267. relocs[i]->howto =
  1268. bfd_reloc_type_lookup (stdoutput,
  1269. (bfd_reloc_code_real_type) code);
  1270. relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1271. switch (code)
  1272. {
  1273. case R_COMP2:
  1274. /* The only time we ever use a R_COMP2 fixup is for the difference
  1275. of two symbols. With that in mind we fill in all four
  1276. relocs now and break out of the loop. */
  1277. gas_assert (i == 1);
  1278. relocs[0]->sym_ptr_ptr
  1279. = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
  1280. relocs[0]->howto
  1281. = bfd_reloc_type_lookup (stdoutput,
  1282. (bfd_reloc_code_real_type) *codes[0]);
  1283. relocs[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1284. relocs[0]->addend = 0;
  1285. relocs[1]->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  1286. *relocs[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  1287. relocs[1]->howto
  1288. = bfd_reloc_type_lookup (stdoutput,
  1289. (bfd_reloc_code_real_type) *codes[1]);
  1290. relocs[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1291. relocs[1]->addend = 0;
  1292. relocs[2]->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  1293. *relocs[2]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
  1294. relocs[2]->howto
  1295. = bfd_reloc_type_lookup (stdoutput,
  1296. (bfd_reloc_code_real_type) *codes[2]);
  1297. relocs[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1298. relocs[2]->addend = 0;
  1299. relocs[3]->sym_ptr_ptr
  1300. = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
  1301. relocs[3]->howto
  1302. = bfd_reloc_type_lookup (stdoutput,
  1303. (bfd_reloc_code_real_type) *codes[3]);
  1304. relocs[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1305. relocs[3]->addend = 0;
  1306. relocs[4]->sym_ptr_ptr
  1307. = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
  1308. relocs[4]->howto
  1309. = bfd_reloc_type_lookup (stdoutput,
  1310. (bfd_reloc_code_real_type) *codes[4]);
  1311. relocs[4]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1312. relocs[4]->addend = 0;
  1313. goto done;
  1314. case R_PCREL_CALL:
  1315. case R_ABS_CALL:
  1316. relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
  1317. break;
  1318. case R_DLT_REL:
  1319. case R_DATA_PLABEL:
  1320. case R_CODE_PLABEL:
  1321. /* For plabel relocations, the addend of the
  1322. relocation should be either 0 (no static link) or 2
  1323. (static link required).
  1324. FIXME: We always assume no static link!
  1325. We also slam a zero addend into the DLT relative relocs;
  1326. it doesn't make a lot of sense to use any addend since
  1327. it gets you a different (eg unknown) DLT entry. */
  1328. relocs[i]->addend = 0;
  1329. break;
  1330. case R_N_MODE:
  1331. case R_S_MODE:
  1332. case R_D_MODE:
  1333. case R_R_MODE:
  1334. case R_FSEL:
  1335. case R_LSEL:
  1336. case R_RSEL:
  1337. case R_BEGIN_BRTAB:
  1338. case R_END_BRTAB:
  1339. case R_BEGIN_TRY:
  1340. case R_N0SEL:
  1341. case R_N1SEL:
  1342. /* There is no symbol or addend associated with these fixups. */
  1343. relocs[i]->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  1344. *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
  1345. relocs[i]->addend = 0;
  1346. break;
  1347. case R_END_TRY:
  1348. case R_ENTRY:
  1349. case R_EXIT:
  1350. /* There is no symbol associated with these fixups. */
  1351. relocs[i]->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  1352. *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
  1353. relocs[i]->addend = fixp->fx_offset;
  1354. break;
  1355. default:
  1356. relocs[i]->addend = fixp->fx_offset;
  1357. }
  1358. }
  1359. done:
  1360. #endif
  1361. return relocs;
  1362. }
  1363. /* Process any machine dependent frag types. */
  1364. void
  1365. md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
  1366. asection *sec ATTRIBUTE_UNUSED,
  1367. fragS *fragP)
  1368. {
  1369. unsigned int address;
  1370. if (fragP->fr_type == rs_machine_dependent)
  1371. {
  1372. switch ((int) fragP->fr_subtype)
  1373. {
  1374. case 0:
  1375. fragP->fr_type = rs_fill;
  1376. know (fragP->fr_var == 1);
  1377. know (fragP->fr_next);
  1378. address = fragP->fr_address + fragP->fr_fix;
  1379. if (address % fragP->fr_offset)
  1380. {
  1381. fragP->fr_offset =
  1382. fragP->fr_next->fr_address
  1383. - fragP->fr_address
  1384. - fragP->fr_fix;
  1385. }
  1386. else
  1387. fragP->fr_offset = 0;
  1388. break;
  1389. }
  1390. }
  1391. }
  1392. /* Round up a section size to the appropriate boundary. */
  1393. valueT
  1394. md_section_align (asection *segment, valueT size)
  1395. {
  1396. int align = bfd_get_section_alignment (stdoutput, segment);
  1397. int align2 = (1 << align) - 1;
  1398. return (size + align2) & ~align2;
  1399. }
  1400. /* Return the approximate size of a frag before relaxation has occurred. */
  1401. int
  1402. md_estimate_size_before_relax (fragS *fragP, asection *segment ATTRIBUTE_UNUSED)
  1403. {
  1404. int size;
  1405. size = 0;
  1406. while ((fragP->fr_fix + size) % fragP->fr_offset)
  1407. size++;
  1408. return size;
  1409. }
  1410. #ifdef OBJ_ELF
  1411. # ifdef WARN_COMMENTS
  1412. const char *md_shortopts = "Vc";
  1413. # else
  1414. const char *md_shortopts = "V";
  1415. # endif
  1416. #else
  1417. # ifdef WARN_COMMENTS
  1418. const char *md_shortopts = "c";
  1419. # else
  1420. const char *md_shortopts = "";
  1421. # endif
  1422. #endif
  1423. struct option md_longopts[] =
  1424. {
  1425. #ifdef WARN_COMMENTS
  1426. {"warn-comment", no_argument, NULL, 'c'},
  1427. #endif
  1428. {NULL, no_argument, NULL, 0}
  1429. };
  1430. size_t md_longopts_size = sizeof (md_longopts);
  1431. int
  1432. md_parse_option (int c, char *arg ATTRIBUTE_UNUSED)
  1433. {
  1434. switch (c)
  1435. {
  1436. default:
  1437. return 0;
  1438. #ifdef OBJ_ELF
  1439. case 'V':
  1440. print_version_id ();
  1441. break;
  1442. #endif
  1443. #ifdef WARN_COMMENTS
  1444. case 'c':
  1445. warn_comment = 1;
  1446. break;
  1447. #endif
  1448. }
  1449. return 1;
  1450. }
  1451. void
  1452. md_show_usage (FILE *stream ATTRIBUTE_UNUSED)
  1453. {
  1454. #ifdef OBJ_ELF
  1455. fprintf (stream, _("\
  1456. -Q ignored\n"));
  1457. #endif
  1458. #ifdef WARN_COMMENTS
  1459. fprintf (stream, _("\
  1460. -c print a warning if a comment is found\n"));
  1461. #endif
  1462. }
  1463. /* We have no need to default values of symbols. */
  1464. symbolS *
  1465. md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
  1466. {
  1467. return NULL;
  1468. }
  1469. #if defined (OBJ_SOM) || defined (ELF_ARG_RELOC)
  1470. #define nonzero_dibits(x) \
  1471. ((x) | (((x) & 0x55555555) << 1) | (((x) & 0xAAAAAAAA) >> 1))
  1472. #define arg_reloc_stub_needed(CALLER, CALLEE) \
  1473. (((CALLER) ^ (CALLEE)) & nonzero_dibits (CALLER) & nonzero_dibits (CALLEE))
  1474. #else
  1475. #define arg_reloc_stub_needed(CALLER, CALLEE) 0
  1476. #endif
  1477. /* Apply a fixup to an instruction. */
  1478. void
  1479. md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
  1480. {
  1481. char *fixpos;
  1482. struct hppa_fix_struct *hppa_fixP;
  1483. offsetT new_val;
  1484. int insn, val, fmt;
  1485. /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
  1486. never be "applied" (they are just markers). Likewise for
  1487. R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
  1488. #ifdef OBJ_SOM
  1489. if (fixP->fx_r_type == R_HPPA_ENTRY
  1490. || fixP->fx_r_type == R_HPPA_EXIT
  1491. || fixP->fx_r_type == R_HPPA_BEGIN_BRTAB
  1492. || fixP->fx_r_type == R_HPPA_END_BRTAB
  1493. || fixP->fx_r_type == R_HPPA_BEGIN_TRY)
  1494. return;
  1495. /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
  1496. fixups are considered not adjustable, which in turn causes
  1497. adjust_reloc_syms to not set fx_offset. Ugh. */
  1498. if (fixP->fx_r_type == R_HPPA_END_TRY)
  1499. {
  1500. fixP->fx_offset = * valP;
  1501. return;
  1502. }
  1503. #endif
  1504. #ifdef OBJ_ELF
  1505. if (fixP->fx_r_type == (int) R_PARISC_GNU_VTENTRY
  1506. || fixP->fx_r_type == (int) R_PARISC_GNU_VTINHERIT)
  1507. return;
  1508. #endif
  1509. if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
  1510. fixP->fx_done = 1;
  1511. /* There should be a HPPA specific fixup associated with the GAS fixup. */
  1512. hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data;
  1513. if (hppa_fixP == NULL)
  1514. {
  1515. as_bad_where (fixP->fx_file, fixP->fx_line,
  1516. _("no hppa_fixup entry for fixup type 0x%x"),
  1517. fixP->fx_r_type);
  1518. return;
  1519. }
  1520. fixpos = fixP->fx_frag->fr_literal + fixP->fx_where;
  1521. if (fixP->fx_size != 4 || hppa_fixP->fx_r_format == 32)
  1522. {
  1523. /* Handle constant output. */
  1524. number_to_chars_bigendian (fixpos, *valP, fixP->fx_size);
  1525. return;
  1526. }
  1527. insn = bfd_get_32 (stdoutput, fixpos);
  1528. fmt = bfd_hppa_insn2fmt (stdoutput, insn);
  1529. /* If there is a symbol associated with this fixup, then it's something
  1530. which will need a SOM relocation (except for some PC-relative relocs).
  1531. In such cases we should treat the "val" or "addend" as zero since it
  1532. will be added in as needed from fx_offset in tc_gen_reloc. */
  1533. if ((fixP->fx_addsy != NULL
  1534. || fixP->fx_r_type == (int) R_HPPA_NONE)
  1535. #ifdef OBJ_SOM
  1536. && fmt != 32
  1537. #endif
  1538. )
  1539. new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
  1540. #ifdef OBJ_SOM
  1541. /* These field selectors imply that we do not want an addend. */
  1542. else if (hppa_fixP->fx_r_field == e_psel
  1543. || hppa_fixP->fx_r_field == e_rpsel
  1544. || hppa_fixP->fx_r_field == e_lpsel
  1545. || hppa_fixP->fx_r_field == e_tsel
  1546. || hppa_fixP->fx_r_field == e_rtsel
  1547. || hppa_fixP->fx_r_field == e_ltsel)
  1548. new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
  1549. #endif
  1550. else
  1551. new_val = hppa_field_adjust (* valP, 0, hppa_fixP->fx_r_field);
  1552. /* Handle pc-relative exceptions from above. */
  1553. if ((fmt == 12 || fmt == 17 || fmt == 22)
  1554. && fixP->fx_addsy
  1555. && fixP->fx_pcrel
  1556. && !arg_reloc_stub_needed (symbol_arg_reloc_info (fixP->fx_addsy),
  1557. hppa_fixP->fx_arg_reloc)
  1558. #ifdef OBJ_ELF
  1559. && (* valP - 8 + 8192 < 16384
  1560. || (fmt == 17 && * valP - 8 + 262144 < 524288)
  1561. || (fmt == 22 && * valP - 8 + 8388608 < 16777216))
  1562. #endif
  1563. #ifdef OBJ_SOM
  1564. && (* valP - 8 + 262144 < 524288
  1565. || (fmt == 22 && * valP - 8 + 8388608 < 16777216))
  1566. #endif
  1567. && !S_IS_EXTERNAL (fixP->fx_addsy)
  1568. && !S_IS_WEAK (fixP->fx_addsy)
  1569. && S_GET_SEGMENT (fixP->fx_addsy) == hppa_fixP->segment
  1570. && !(fixP->fx_subsy
  1571. && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment))
  1572. {
  1573. new_val = hppa_field_adjust (* valP, 0, hppa_fixP->fx_r_field);
  1574. }
  1575. switch (fmt)
  1576. {
  1577. case 10:
  1578. CHECK_FIELD_WHERE (new_val, 8191, -8192,
  1579. fixP->fx_file, fixP->fx_line);
  1580. val = new_val;
  1581. insn = (insn & ~ 0x3ff1) | (((val & 0x1ff8) << 1)
  1582. | ((val & 0x2000) >> 13));
  1583. break;
  1584. case -11:
  1585. CHECK_FIELD_WHERE (new_val, 8191, -8192,
  1586. fixP->fx_file, fixP->fx_line);
  1587. val = new_val;
  1588. insn = (insn & ~ 0x3ff9) | (((val & 0x1ffc) << 1)
  1589. | ((val & 0x2000) >> 13));
  1590. break;
  1591. /* Handle all opcodes with the 'j' operand type. */
  1592. case 14:
  1593. CHECK_FIELD_WHERE (new_val, 8191, -8192,
  1594. fixP->fx_file, fixP->fx_line);
  1595. val = new_val;
  1596. insn = ((insn & ~ 0x3fff) | low_sign_unext (val, 14));
  1597. break;
  1598. /* Handle all opcodes with the 'k' operand type. */
  1599. case 21:
  1600. CHECK_FIELD_WHERE (new_val, 1048575, -1048576,
  1601. fixP->fx_file, fixP->fx_line);
  1602. val = new_val;
  1603. insn = (insn & ~ 0x1fffff) | re_assemble_21 (val);
  1604. break;
  1605. /* Handle all the opcodes with the 'i' operand type. */
  1606. case 11:
  1607. CHECK_FIELD_WHERE (new_val, 1023, -1024,
  1608. fixP->fx_file, fixP->fx_line);
  1609. val = new_val;
  1610. insn = (insn & ~ 0x7ff) | low_sign_unext (val, 11);
  1611. break;
  1612. /* Handle all the opcodes with the 'w' operand type. */
  1613. case 12:
  1614. CHECK_FIELD_WHERE (new_val - 8, 8191, -8192,
  1615. fixP->fx_file, fixP->fx_line);
  1616. val = new_val - 8;
  1617. insn = (insn & ~ 0x1ffd) | re_assemble_12 (val >> 2);
  1618. break;
  1619. /* Handle some of the opcodes with the 'W' operand type. */
  1620. case 17:
  1621. {
  1622. offsetT distance = * valP;
  1623. /* If this is an absolute branch (ie no link) with an out of
  1624. range target, then we want to complain. */
  1625. if (fixP->fx_r_type == (int) R_HPPA_PCREL_CALL
  1626. && (insn & 0xffe00000) == 0xe8000000)
  1627. CHECK_FIELD_WHERE (distance - 8, 262143, -262144,
  1628. fixP->fx_file, fixP->fx_line);
  1629. CHECK_FIELD_WHERE (new_val - 8, 262143, -262144,
  1630. fixP->fx_file, fixP->fx_line);
  1631. val = new_val - 8;
  1632. insn = (insn & ~ 0x1f1ffd) | re_assemble_17 (val >> 2);
  1633. break;
  1634. }
  1635. case 22:
  1636. {
  1637. offsetT distance = * valP;
  1638. /* If this is an absolute branch (ie no link) with an out of
  1639. range target, then we want to complain. */
  1640. if (fixP->fx_r_type == (int) R_HPPA_PCREL_CALL
  1641. && (insn & 0xffe00000) == 0xe8000000)
  1642. CHECK_FIELD_WHERE (distance - 8, 8388607, -8388608,
  1643. fixP->fx_file, fixP->fx_line);
  1644. CHECK_FIELD_WHERE (new_val - 8, 8388607, -8388608,
  1645. fixP->fx_file, fixP->fx_line);
  1646. val = new_val - 8;
  1647. insn = (insn & ~ 0x3ff1ffd) | re_assemble_22 (val >> 2);
  1648. break;
  1649. }
  1650. case -10:
  1651. val = new_val;
  1652. insn = (insn & ~ 0xfff1) | re_assemble_16 (val & -8);
  1653. break;
  1654. case -16:
  1655. val = new_val;
  1656. insn = (insn & ~ 0xfff9) | re_assemble_16 (val & -4);
  1657. break;
  1658. case 16:
  1659. val = new_val;
  1660. insn = (insn & ~ 0xffff) | re_assemble_16 (val);
  1661. break;
  1662. case 32:
  1663. insn = new_val;
  1664. break;
  1665. default:
  1666. as_bad_where (fixP->fx_file, fixP->fx_line,
  1667. _("Unknown relocation encountered in md_apply_fix."));
  1668. return;
  1669. }
  1670. #ifdef OBJ_ELF
  1671. switch (fixP->fx_r_type)
  1672. {
  1673. case R_PARISC_TLS_GD21L:
  1674. case R_PARISC_TLS_GD14R:
  1675. case R_PARISC_TLS_LDM21L:
  1676. case R_PARISC_TLS_LDM14R:
  1677. case R_PARISC_TLS_LE21L:
  1678. case R_PARISC_TLS_LE14R:
  1679. case R_PARISC_TLS_IE21L:
  1680. case R_PARISC_TLS_IE14R:
  1681. if (fixP->fx_addsy)
  1682. S_SET_THREAD_LOCAL (fixP->fx_addsy);
  1683. break;
  1684. default:
  1685. break;
  1686. }
  1687. #endif
  1688. /* Insert the relocation. */
  1689. bfd_put_32 (stdoutput, insn, fixpos);
  1690. }
  1691. /* Exactly what point is a PC-relative offset relative TO?
  1692. On the PA, they're relative to the address of the offset. */
  1693. long
  1694. md_pcrel_from (fixS *fixP)
  1695. {
  1696. return fixP->fx_where + fixP->fx_frag->fr_address;
  1697. }
  1698. /* Return nonzero if the input line pointer is at the end of
  1699. a statement. */
  1700. static int
  1701. is_end_of_statement (void)
  1702. {
  1703. return ((*input_line_pointer == '\n')
  1704. || (*input_line_pointer == ';')
  1705. || (*input_line_pointer == '!'));
  1706. }
  1707. #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
  1708. /* Given NAME, find the register number associated with that name, return
  1709. the integer value associated with the given name or -1 on failure. */
  1710. static int
  1711. reg_name_search (char *name)
  1712. {
  1713. int middle, low, high;
  1714. int cmp;
  1715. low = 0;
  1716. high = REG_NAME_CNT - 1;
  1717. do
  1718. {
  1719. middle = (low + high) / 2;
  1720. cmp = strcasecmp (name, pre_defined_registers[middle].name);
  1721. if (cmp < 0)
  1722. high = middle - 1;
  1723. else if (cmp > 0)
  1724. low = middle + 1;
  1725. else
  1726. return pre_defined_registers[middle].value;
  1727. }
  1728. while (low <= high);
  1729. return -1;
  1730. }
  1731. /* Read a number from S. The number might come in one of many forms,
  1732. the most common will be a hex or decimal constant, but it could be
  1733. a pre-defined register (Yuk!), or an absolute symbol.
  1734. Return 1 on success or 0 on failure. If STRICT, then a missing
  1735. register prefix will cause a failure. The number itself is
  1736. returned in `pa_number'.
  1737. IS_FLOAT indicates that a PA-89 FP register number should be
  1738. parsed; A `l' or `r' suffix is checked for if but 2 of IS_FLOAT is
  1739. not set.
  1740. pa_parse_number can not handle negative constants and will fail
  1741. horribly if it is passed such a constant. */
  1742. static int
  1743. pa_parse_number (char **s, int is_float)
  1744. {
  1745. int num;
  1746. char *name;
  1747. char c;
  1748. symbolS *sym;
  1749. int status;
  1750. char *p = *s;
  1751. bfd_boolean have_prefix;
  1752. /* Skip whitespace before the number. */
  1753. while (*p == ' ' || *p == '\t')
  1754. p = p + 1;
  1755. pa_number = -1;
  1756. have_prefix = 0;
  1757. num = 0;
  1758. if (!strict && ISDIGIT (*p))
  1759. {
  1760. /* Looks like a number. */
  1761. if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
  1762. {
  1763. /* The number is specified in hex. */
  1764. p += 2;
  1765. while (ISDIGIT (*p) || ((*p >= 'a') && (*p <= 'f'))
  1766. || ((*p >= 'A') && (*p <= 'F')))
  1767. {
  1768. if (ISDIGIT (*p))
  1769. num = num * 16 + *p - '0';
  1770. else if (*p >= 'a' && *p <= 'f')
  1771. num = num * 16 + *p - 'a' + 10;
  1772. else
  1773. num = num * 16 + *p - 'A' + 10;
  1774. ++p;
  1775. }
  1776. }
  1777. else
  1778. {
  1779. /* The number is specified in decimal. */
  1780. while (ISDIGIT (*p))
  1781. {
  1782. num = num * 10 + *p - '0';
  1783. ++p;
  1784. }
  1785. }
  1786. pa_number = num;
  1787. /* Check for a `l' or `r' suffix. */
  1788. if (is_float)
  1789. {
  1790. pa_number += FP_REG_BASE;
  1791. if (! (is_float & 2))
  1792. {
  1793. if (IS_R_SELECT (p))
  1794. {
  1795. pa_number += FP_REG_RSEL;
  1796. ++p;
  1797. }
  1798. else if (IS_L_SELECT (p))
  1799. {
  1800. ++p;
  1801. }
  1802. }
  1803. }
  1804. }
  1805. else if (*p == '%')
  1806. {
  1807. /* The number might be a predefined register. */
  1808. have_prefix = 1;
  1809. name = p;
  1810. p++;
  1811. c = *p;
  1812. /* Tege hack: Special case for general registers as the general
  1813. code makes a binary search with case translation, and is VERY
  1814. slow. */
  1815. if (c == 'r')
  1816. {
  1817. p++;
  1818. if (*p == 'e' && *(p + 1) == 't'
  1819. && (*(p + 2) == '0' || *(p + 2) == '1'))
  1820. {
  1821. p += 2;
  1822. num = *p - '0' + 28;
  1823. p++;
  1824. }
  1825. else if (*p == 'p')
  1826. {
  1827. num = 2;
  1828. p++;
  1829. }
  1830. else if (!ISDIGIT (*p))
  1831. {
  1832. if (print_errors)
  1833. as_bad (_("Undefined register: '%s'."), name);
  1834. num = -1;
  1835. }
  1836. else
  1837. {
  1838. do
  1839. num = num * 10 + *p++ - '0';
  1840. while (ISDIGIT (*p));
  1841. }
  1842. }
  1843. else
  1844. {
  1845. /* Do a normal register search. */
  1846. while (is_part_of_name (c))
  1847. {
  1848. p = p + 1;
  1849. c = *p;
  1850. }
  1851. *p = 0;
  1852. status = reg_name_search (name);
  1853. if (status >= 0)
  1854. num = status;
  1855. else
  1856. {
  1857. if (print_errors)
  1858. as_bad (_("Undefined register: '%s'."), name);
  1859. num = -1;
  1860. }
  1861. *p = c;
  1862. }
  1863. pa_number = num;
  1864. }
  1865. else
  1866. {
  1867. /* And finally, it could be a symbol in the absolute section which
  1868. is effectively a constant, or a register alias symbol. */
  1869. name = p;
  1870. c = *p;
  1871. while (is_part_of_name (c))
  1872. {
  1873. p = p + 1;
  1874. c = *p;
  1875. }
  1876. *p = 0;
  1877. if ((sym = symbol_find (name)) != NULL)
  1878. {
  1879. if (S_GET_SEGMENT (sym) == reg_section)
  1880. {
  1881. num = S_GET_VALUE (sym);
  1882. /* Well, we don't really have one, but we do have a
  1883. register, so... */
  1884. have_prefix = TRUE;
  1885. }
  1886. else if (S_GET_SEGMENT (sym) == bfd_abs_section_ptr)
  1887. num = S_GET_VALUE (sym);
  1888. else if (!strict)
  1889. {
  1890. if (print_errors)
  1891. as_bad (_("Non-absolute symbol: '%s'."), name);
  1892. num = -1;
  1893. }
  1894. }
  1895. else if (!strict)
  1896. {
  1897. /* There is where we'd come for an undefined symbol
  1898. or for an empty string. For an empty string we
  1899. will return zero. That's a concession made for
  1900. compatibility with the braindamaged HP assemblers. */
  1901. if (*name == 0)
  1902. num = 0;
  1903. else
  1904. {
  1905. if (print_errors)
  1906. as_bad (_("Undefined absolute constant: '%s'."), name);
  1907. num = -1;
  1908. }
  1909. }
  1910. *p = c;
  1911. pa_number = num;
  1912. }
  1913. if (!strict || have_prefix)
  1914. {
  1915. *s = p;
  1916. return 1;
  1917. }
  1918. return 0;
  1919. }
  1920. /* Return nonzero if the given INSN and L/R information will require
  1921. a new PA-1.1 opcode. */
  1922. static int
  1923. need_pa11_opcode (void)
  1924. {
  1925. if ((pa_number & FP_REG_RSEL) != 0
  1926. && !(the_insn.fpof1 == DBL && the_insn.fpof2 == DBL))
  1927. {
  1928. /* If this instruction is specific to a particular architecture,
  1929. then set a new architecture. */
  1930. if (bfd_get_mach (stdoutput) < pa11)
  1931. {
  1932. if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, pa11))
  1933. as_warn (_("could not update architecture and machine"));
  1934. }
  1935. return TRUE;
  1936. }
  1937. else
  1938. return FALSE;
  1939. }
  1940. /* Parse a condition for a fcmp instruction. Return the numerical
  1941. code associated with the condition. */
  1942. static int
  1943. pa_parse_fp_cmp_cond (char **s)
  1944. {
  1945. int cond, i;
  1946. cond = 0;
  1947. for (i = 0; i < 32; i++)
  1948. {
  1949. if (strncasecmp (*s, fp_cond_map[i].string,
  1950. strlen (fp_cond_map[i].string)) == 0)
  1951. {
  1952. cond = fp_cond_map[i].cond;
  1953. *s += strlen (fp_cond_map[i].string);
  1954. /* If not a complete match, back up the input string and
  1955. report an error. */
  1956. if (**s != ' ' && **s != '\t')
  1957. {
  1958. *s -= strlen (fp_cond_map[i].string);
  1959. break;
  1960. }
  1961. while (**s == ' ' || **s == '\t')
  1962. *s = *s + 1;
  1963. return cond;
  1964. }
  1965. }
  1966. as_bad (_("Invalid FP Compare Condition: %s"), *s);
  1967. /* Advance over the bogus completer. */
  1968. while (**s != ',' && **s != ' ' && **s != '\t')
  1969. *s += 1;
  1970. return 0;
  1971. }
  1972. /* Parse a graphics test complete for ftest. */
  1973. static int
  1974. pa_parse_ftest_gfx_completer (char **s)
  1975. {
  1976. int value;
  1977. value = 0;
  1978. if (strncasecmp (*s, "acc8", 4) == 0)
  1979. {
  1980. value = 5;
  1981. *s += 4;
  1982. }
  1983. else if (strncasecmp (*s, "acc6", 4) == 0)
  1984. {
  1985. value = 9;
  1986. *s += 4;
  1987. }
  1988. else if (strncasecmp (*s, "acc4", 4) == 0)
  1989. {
  1990. value = 13;
  1991. *s += 4;
  1992. }
  1993. else if (strncasecmp (*s, "acc2", 4) == 0)
  1994. {
  1995. value = 17;
  1996. *s += 4;
  1997. }
  1998. else if (strncasecmp (*s, "acc", 3) == 0)
  1999. {
  2000. value = 1;
  2001. *s += 3;
  2002. }
  2003. else if (strncasecmp (*s, "rej8", 4) == 0)
  2004. {
  2005. value = 6;
  2006. *s += 4;
  2007. }
  2008. else if (strncasecmp (*s, "rej", 3) == 0)
  2009. {
  2010. value = 2;
  2011. *s += 3;
  2012. }
  2013. else
  2014. {
  2015. value = 0;
  2016. as_bad (_("Invalid FTEST completer: %s"), *s);
  2017. }
  2018. return value;
  2019. }
  2020. /* Parse an FP operand format completer returning the completer
  2021. type. */
  2022. static fp_operand_format
  2023. pa_parse_fp_cnv_format (char **s)
  2024. {
  2025. int format;
  2026. format = SGL;
  2027. if (**s == ',')
  2028. {
  2029. *s += 1;
  2030. if (strncasecmp (*s, "sgl", 3) == 0)
  2031. {
  2032. format = SGL;
  2033. *s += 4;
  2034. }
  2035. else if (strncasecmp (*s, "dbl", 3) == 0)
  2036. {
  2037. format = DBL;
  2038. *s += 4;
  2039. }
  2040. else if (strncasecmp (*s, "quad", 4) == 0)
  2041. {
  2042. format = QUAD;
  2043. *s += 5;
  2044. }
  2045. else if (strncasecmp (*s, "w", 1) == 0)
  2046. {
  2047. format = W;
  2048. *s += 2;
  2049. }
  2050. else if (strncasecmp (*s, "uw", 2) == 0)
  2051. {
  2052. format = UW;
  2053. *s += 3;
  2054. }
  2055. else if (strncasecmp (*s, "dw", 2) == 0)
  2056. {
  2057. format = DW;
  2058. *s += 3;
  2059. }
  2060. else if (strncasecmp (*s, "udw", 3) == 0)
  2061. {
  2062. format = UDW;
  2063. *s += 4;
  2064. }
  2065. else if (strncasecmp (*s, "qw", 2) == 0)
  2066. {
  2067. format = QW;
  2068. *s += 3;
  2069. }
  2070. else if (strncasecmp (*s, "uqw", 3) == 0)
  2071. {
  2072. format = UQW;
  2073. *s += 4;
  2074. }
  2075. else
  2076. {
  2077. format = ILLEGAL_FMT;
  2078. as_bad (_("Invalid FP Operand Format: %3s"), *s);
  2079. }
  2080. }
  2081. return format;
  2082. }
  2083. /* Parse an FP operand format completer returning the completer
  2084. type. */
  2085. static fp_operand_format
  2086. pa_parse_fp_format (char **s)
  2087. {
  2088. int format;
  2089. format = SGL;
  2090. if (**s == ',')
  2091. {
  2092. *s += 1;
  2093. if (strncasecmp (*s, "sgl", 3) == 0)
  2094. {
  2095. format = SGL;
  2096. *s += 4;
  2097. }
  2098. else if (strncasecmp (*s, "dbl", 3) == 0)
  2099. {
  2100. format = DBL;
  2101. *s += 4;
  2102. }
  2103. else if (strncasecmp (*s, "quad", 4) == 0)
  2104. {
  2105. format = QUAD;
  2106. *s += 5;
  2107. }
  2108. else
  2109. {
  2110. format = ILLEGAL_FMT;
  2111. as_bad (_("Invalid FP Operand Format: %3s"), *s);
  2112. }
  2113. }
  2114. return format;
  2115. }
  2116. /* Convert from a selector string into a selector type. */
  2117. static int
  2118. pa_chk_field_selector (char **str)
  2119. {
  2120. int middle, low, high;
  2121. int cmp;
  2122. char name[4];
  2123. /* Read past any whitespace. */
  2124. /* FIXME: should we read past newlines and formfeeds??? */
  2125. while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
  2126. *str = *str + 1;
  2127. if ((*str)[1] == '\'' || (*str)[1] == '%')
  2128. name[0] = TOLOWER ((*str)[0]),
  2129. name[1] = 0;
  2130. else if ((*str)[2] == '\'' || (*str)[2] == '%')
  2131. name[0] = TOLOWER ((*str)[0]),
  2132. name[1] = TOLOWER ((*str)[1]),
  2133. name[2] = 0;
  2134. else if ((*str)[3] == '\'' || (*str)[3] == '%')
  2135. name[0] = TOLOWER ((*str)[0]),
  2136. name[1] = TOLOWER ((*str)[1]),
  2137. name[2] = TOLOWER ((*str)[2]),
  2138. name[3] = 0;
  2139. else
  2140. return e_fsel;
  2141. low = 0;
  2142. high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
  2143. do
  2144. {
  2145. middle = (low + high) / 2;
  2146. cmp = strcmp (name, selector_table[middle].prefix);
  2147. if (cmp < 0)
  2148. high = middle - 1;
  2149. else if (cmp > 0)
  2150. low = middle + 1;
  2151. else
  2152. {
  2153. *str += strlen (name) + 1;
  2154. #ifndef OBJ_SOM
  2155. if (selector_table[middle].field_selector == e_nsel)
  2156. return e_fsel;
  2157. #endif
  2158. return selector_table[middle].field_selector;
  2159. }
  2160. }
  2161. while (low <= high);
  2162. return e_fsel;
  2163. }
  2164. /* Parse a .byte, .word, .long expression for the HPPA. Called by
  2165. cons via the TC_PARSE_CONS_EXPRESSION macro. */
  2166. void
  2167. parse_cons_expression_hppa (expressionS *exp)
  2168. {
  2169. hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
  2170. expression (exp);
  2171. }
  2172. /* Evaluate an absolute expression EXP which may be modified by
  2173. the selector FIELD_SELECTOR. Return the value of the expression. */
  2174. static int
  2175. evaluate_absolute (struct pa_it *insn)
  2176. {
  2177. offsetT value;
  2178. expressionS exp;
  2179. int field_selector = insn->field_selector;
  2180. exp = insn->exp;
  2181. value = exp.X_add_number;
  2182. return hppa_field_adjust (0, value, field_selector);
  2183. }
  2184. /* Mark (via expr_end) the end of an absolute expression. FIXME. */
  2185. static int
  2186. pa_get_absolute_expression (struct pa_it *insn, char **strp)
  2187. {
  2188. char *save_in;
  2189. insn->field_selector = pa_chk_field_selector (strp);
  2190. save_in = input_line_pointer;
  2191. input_line_pointer = *strp;
  2192. expression (&insn->exp);
  2193. /* This is not perfect, but is a huge improvement over doing nothing.
  2194. The PA assembly syntax is ambiguous in a variety of ways. Consider
  2195. this string "4 %r5" Is that the number 4 followed by the register
  2196. r5, or is that 4 MOD r5?
  2197. If we get a modulo expression when looking for an absolute, we try
  2198. again cutting off the input string at the first whitespace character. */
  2199. if (insn->exp.X_op == O_modulus)
  2200. {
  2201. char *s, c;
  2202. input_line_pointer = *strp;
  2203. s = *strp;
  2204. while (*s != ',' && *s != ' ' && *s != '\t')
  2205. s++;
  2206. c = *s;
  2207. *s = 0;
  2208. pa_get_absolute_expression (insn, strp);
  2209. input_line_pointer = save_in;
  2210. *s = c;
  2211. return evaluate_absolute (insn);
  2212. }
  2213. /* When in strict mode we have a non-match, fix up the pointers
  2214. and return to our caller. */
  2215. if (insn->exp.X_op != O_constant && strict)
  2216. {
  2217. expr_end = input_line_pointer;
  2218. input_line_pointer = save_in;
  2219. return 0;
  2220. }
  2221. if (insn->exp.X_op != O_constant)
  2222. {
  2223. as_bad (_("Bad segment (should be absolute)."));
  2224. expr_end = input_line_pointer;
  2225. input_line_pointer = save_in;
  2226. return 0;
  2227. }
  2228. expr_end = input_line_pointer;
  2229. input_line_pointer = save_in;
  2230. return evaluate_absolute (insn);
  2231. }
  2232. /* Given an argument location specification return the associated
  2233. argument location number. */
  2234. static unsigned int
  2235. pa_build_arg_reloc (char *type_name)
  2236. {
  2237. if (strncasecmp (type_name, "no", 2) == 0)
  2238. return 0;
  2239. if (strncasecmp (type_name, "gr", 2) == 0)
  2240. return 1;
  2241. else if (strncasecmp (type_name, "fr", 2) == 0)
  2242. return 2;
  2243. else if (strncasecmp (type_name, "fu", 2) == 0)
  2244. return 3;
  2245. else
  2246. as_bad (_("Invalid argument location: %s\n"), type_name);
  2247. return 0;
  2248. }
  2249. /* Encode and return an argument relocation specification for
  2250. the given register in the location specified by arg_reloc. */
  2251. static unsigned int
  2252. pa_align_arg_reloc (unsigned int reg, unsigned int arg_reloc)
  2253. {
  2254. unsigned int new_reloc;
  2255. new_reloc = arg_reloc;
  2256. switch (reg)
  2257. {
  2258. case 0:
  2259. new_reloc <<= 8;
  2260. break;
  2261. case 1:
  2262. new_reloc <<= 6;
  2263. break;
  2264. case 2:
  2265. new_reloc <<= 4;
  2266. break;
  2267. case 3:
  2268. new_reloc <<= 2;
  2269. break;
  2270. default:
  2271. as_bad (_("Invalid argument description: %d"), reg);
  2272. }
  2273. return new_reloc;
  2274. }
  2275. /* Parse a non-negated compare/subtract completer returning the
  2276. number (for encoding in instructions) of the given completer. */
  2277. static int
  2278. pa_parse_nonneg_cmpsub_cmpltr (char **s)
  2279. {
  2280. int cmpltr;
  2281. char *name = *s + 1;
  2282. char c;
  2283. char *save_s = *s;
  2284. int nullify = 0;
  2285. cmpltr = 0;
  2286. if (**s == ',')
  2287. {
  2288. *s += 1;
  2289. while (**s != ',' && **s != ' ' && **s != '\t')
  2290. *s += 1;
  2291. c = **s;
  2292. **s = 0x00;
  2293. if (strcmp (name, "=") == 0)
  2294. {
  2295. cmpltr = 1;
  2296. }
  2297. else if (strcmp (name, "<") == 0)
  2298. {
  2299. cmpltr = 2;
  2300. }
  2301. else if (strcmp (name, "<=") == 0)
  2302. {
  2303. cmpltr = 3;
  2304. }
  2305. else if (strcmp (name, "<<") == 0)
  2306. {
  2307. cmpltr = 4;
  2308. }
  2309. else if (strcmp (name, "<<=") == 0)
  2310. {
  2311. cmpltr = 5;
  2312. }
  2313. else if (strcasecmp (name, "sv") == 0)
  2314. {
  2315. cmpltr = 6;
  2316. }
  2317. else if (strcasecmp (name, "od") == 0)
  2318. {
  2319. cmpltr = 7;
  2320. }
  2321. /* If we have something like addb,n then there is no condition
  2322. completer. */
  2323. else if (strcasecmp (name, "n") == 0)
  2324. {
  2325. cmpltr = 0;
  2326. nullify = 1;
  2327. }
  2328. else
  2329. {
  2330. cmpltr = -1;
  2331. }
  2332. **s = c;
  2333. }
  2334. /* Reset pointers if this was really a ,n for a branch instruction. */
  2335. if (nullify)
  2336. *s = save_s;
  2337. return cmpltr;
  2338. }
  2339. /* Parse a negated compare/subtract completer returning the
  2340. number (for encoding in instructions) of the given completer. */
  2341. static int
  2342. pa_parse_neg_cmpsub_cmpltr (char **s)
  2343. {
  2344. int cmpltr;
  2345. char *name = *s + 1;
  2346. char c;
  2347. char *save_s = *s;
  2348. int nullify = 0;
  2349. cmpltr = 0;
  2350. if (**s == ',')
  2351. {
  2352. *s += 1;
  2353. while (**s != ',' && **s != ' ' && **s != '\t')
  2354. *s += 1;
  2355. c = **s;
  2356. **s = 0x00;
  2357. if (strcasecmp (name, "tr") == 0)
  2358. {
  2359. cmpltr = 0;
  2360. }
  2361. else if (strcmp (name, "<>") == 0)
  2362. {
  2363. cmpltr = 1;
  2364. }
  2365. else if (strcmp (name, ">=") == 0)
  2366. {
  2367. cmpltr = 2;
  2368. }
  2369. else if (strcmp (name, ">") == 0)
  2370. {
  2371. cmpltr = 3;
  2372. }
  2373. else if (strcmp (name, ">>=") == 0)
  2374. {
  2375. cmpltr = 4;
  2376. }
  2377. else if (strcmp (name, ">>") == 0)
  2378. {
  2379. cmpltr = 5;
  2380. }
  2381. else if (strcasecmp (name, "nsv") == 0)
  2382. {
  2383. cmpltr = 6;
  2384. }
  2385. else if (strcasecmp (name, "ev") == 0)
  2386. {
  2387. cmpltr = 7;
  2388. }
  2389. /* If we have something like addb,n then there is no condition
  2390. completer. */
  2391. else if (strcasecmp (name, "n") == 0)
  2392. {
  2393. cmpltr = 0;
  2394. nullify = 1;
  2395. }
  2396. else
  2397. {
  2398. cmpltr = -1;
  2399. }
  2400. **s = c;
  2401. }
  2402. /* Reset pointers if this was really a ,n for a branch instruction. */
  2403. if (nullify)
  2404. *s = save_s;
  2405. return cmpltr;
  2406. }
  2407. /* Parse a 64 bit compare and branch completer returning the number (for
  2408. encoding in instructions) of the given completer.
  2409. Nonnegated comparisons are returned as 0-7, negated comparisons are
  2410. returned as 8-15. */
  2411. static int
  2412. pa_parse_cmpb_64_cmpltr (char **s)
  2413. {
  2414. int cmpltr;
  2415. char *name = *s + 1;
  2416. char c;
  2417. cmpltr = -1;
  2418. if (**s == ',')
  2419. {
  2420. *s += 1;
  2421. while (**s != ',' && **s != ' ' && **s != '\t')
  2422. *s += 1;
  2423. c = **s;
  2424. **s = 0x00;
  2425. if (strcmp (name, "*") == 0)
  2426. {
  2427. cmpltr = 0;
  2428. }
  2429. else if (strcmp (name, "*=") == 0)
  2430. {
  2431. cmpltr = 1;
  2432. }
  2433. else if (strcmp (name, "*<") == 0)
  2434. {
  2435. cmpltr = 2;
  2436. }
  2437. else if (strcmp (name, "*<=") == 0)
  2438. {
  2439. cmpltr = 3;
  2440. }
  2441. else if (strcmp (name, "*<<") == 0)
  2442. {
  2443. cmpltr = 4;
  2444. }
  2445. else if (strcmp (name, "*<<=") == 0)
  2446. {
  2447. cmpltr = 5;
  2448. }
  2449. else if (strcasecmp (name, "*sv") == 0)
  2450. {
  2451. cmpltr = 6;
  2452. }
  2453. else if (strcasecmp (name, "*od") == 0)
  2454. {
  2455. cmpltr = 7;
  2456. }
  2457. else if (strcasecmp (name, "*tr") == 0)
  2458. {
  2459. cmpltr = 8;
  2460. }
  2461. else if (strcmp (name, "*<>") == 0)
  2462. {
  2463. cmpltr = 9;
  2464. }
  2465. else if (strcmp (name, "*>=") == 0)
  2466. {
  2467. cmpltr = 10;
  2468. }
  2469. else if (strcmp (name, "*>") == 0)
  2470. {
  2471. cmpltr = 11;
  2472. }
  2473. else if (strcmp (name, "*>>=") == 0)
  2474. {
  2475. cmpltr = 12;
  2476. }
  2477. else if (strcmp (name, "*>>") == 0)
  2478. {
  2479. cmpltr = 13;
  2480. }
  2481. else if (strcasecmp (name, "*nsv") == 0)
  2482. {
  2483. cmpltr = 14;
  2484. }
  2485. else if (strcasecmp (name, "*ev") == 0)
  2486. {
  2487. cmpltr = 15;
  2488. }
  2489. else
  2490. {
  2491. cmpltr = -1;
  2492. }
  2493. **s = c;
  2494. }
  2495. return cmpltr;
  2496. }
  2497. /* Parse a 64 bit compare immediate and branch completer returning the number
  2498. (for encoding in instructions) of the given completer. */
  2499. static int
  2500. pa_parse_cmpib_64_cmpltr (char **s)
  2501. {
  2502. int cmpltr;
  2503. char *name = *s + 1;
  2504. char c;
  2505. cmpltr = -1;
  2506. if (**s == ',')
  2507. {
  2508. *s += 1;
  2509. while (**s != ',' && **s != ' ' && **s != '\t')
  2510. *s += 1;
  2511. c = **s;
  2512. **s = 0x00;
  2513. if (strcmp (name, "*<<") == 0)
  2514. {
  2515. cmpltr = 0;
  2516. }
  2517. else if (strcmp (name, "*=") == 0)
  2518. {
  2519. cmpltr = 1;
  2520. }
  2521. else if (strcmp (name, "*<") == 0)
  2522. {
  2523. cmpltr = 2;
  2524. }
  2525. else if (strcmp (name, "*<=") == 0)
  2526. {
  2527. cmpltr = 3;
  2528. }
  2529. else if (strcmp (name, "*>>=") == 0)
  2530. {
  2531. cmpltr = 4;
  2532. }
  2533. else if (strcmp (name, "*<>") == 0)
  2534. {
  2535. cmpltr = 5;
  2536. }
  2537. else if (strcasecmp (name, "*>=") == 0)
  2538. {
  2539. cmpltr = 6;
  2540. }
  2541. else if (strcasecmp (name, "*>") == 0)
  2542. {
  2543. cmpltr = 7;
  2544. }
  2545. else
  2546. {
  2547. cmpltr = -1;
  2548. }
  2549. **s = c;
  2550. }
  2551. return cmpltr;
  2552. }
  2553. /* Parse a non-negated addition completer returning the number
  2554. (for encoding in instructions) of the given completer. */
  2555. static int
  2556. pa_parse_nonneg_add_cmpltr (char **s)
  2557. {
  2558. int cmpltr;
  2559. char *name = *s + 1;
  2560. char c;
  2561. char *save_s = *s;
  2562. int nullify = 0;
  2563. cmpltr = 0;
  2564. if (**s == ',')
  2565. {
  2566. *s += 1;
  2567. while (**s != ',' && **s != ' ' && **s != '\t')
  2568. *s += 1;
  2569. c = **s;
  2570. **s = 0x00;
  2571. if (strcmp (name, "=") == 0)
  2572. {
  2573. cmpltr = 1;
  2574. }
  2575. else if (strcmp (name, "<") == 0)
  2576. {
  2577. cmpltr = 2;
  2578. }
  2579. else if (strcmp (name, "<=") == 0)
  2580. {
  2581. cmpltr = 3;
  2582. }
  2583. else if (strcasecmp (name, "nuv") == 0)
  2584. {
  2585. cmpltr = 4;
  2586. }
  2587. else if (strcasecmp (name, "znv") == 0)
  2588. {
  2589. cmpltr = 5;
  2590. }
  2591. else if (strcasecmp (name, "sv") == 0)
  2592. {
  2593. cmpltr = 6;
  2594. }
  2595. else if (strcasecmp (name, "od") == 0)
  2596. {
  2597. cmpltr = 7;
  2598. }
  2599. /* If we have something like addb,n then there is no condition
  2600. completer. */
  2601. else if (strcasecmp (name, "n") == 0)
  2602. {
  2603. cmpltr = 0;
  2604. nullify = 1;
  2605. }
  2606. else
  2607. {
  2608. cmpltr = -1;
  2609. }
  2610. **s = c;
  2611. }
  2612. /* Reset pointers if this was really a ,n for a branch instruction. */
  2613. if (nullify)
  2614. *s = save_s;
  2615. return cmpltr;
  2616. }
  2617. /* Parse a negated addition completer returning the number
  2618. (for encoding in instructions) of the given completer. */
  2619. static int
  2620. pa_parse_neg_add_cmpltr (char **s)
  2621. {
  2622. int cmpltr;
  2623. char *name = *s + 1;
  2624. char c;
  2625. char *save_s = *s;
  2626. int nullify = 0;
  2627. cmpltr = 0;
  2628. if (**s == ',')
  2629. {
  2630. *s += 1;
  2631. while (**s != ',' && **s != ' ' && **s != '\t')
  2632. *s += 1;
  2633. c = **s;
  2634. **s = 0x00;
  2635. if (strcasecmp (name, "tr") == 0)
  2636. {
  2637. cmpltr = 0;
  2638. }
  2639. else if (strcmp (name, "<>") == 0)
  2640. {
  2641. cmpltr = 1;
  2642. }
  2643. else if (strcmp (name, ">=") == 0)
  2644. {
  2645. cmpltr = 2;
  2646. }
  2647. else if (strcmp (name, ">") == 0)
  2648. {
  2649. cmpltr = 3;
  2650. }
  2651. else if (strcasecmp (name, "uv") == 0)
  2652. {
  2653. cmpltr = 4;
  2654. }
  2655. else if (strcasecmp (name, "vnz") == 0)
  2656. {
  2657. cmpltr = 5;
  2658. }
  2659. else if (strcasecmp (name, "nsv") == 0)
  2660. {
  2661. cmpltr = 6;
  2662. }
  2663. else if (strcasecmp (name, "ev") == 0)
  2664. {
  2665. cmpltr = 7;
  2666. }
  2667. /* If we have something like addb,n then there is no condition
  2668. completer. */
  2669. else if (strcasecmp (name, "n") == 0)
  2670. {
  2671. cmpltr = 0;
  2672. nullify = 1;
  2673. }
  2674. else
  2675. {
  2676. cmpltr = -1;
  2677. }
  2678. **s = c;
  2679. }
  2680. /* Reset pointers if this was really a ,n for a branch instruction. */
  2681. if (nullify)
  2682. *s = save_s;
  2683. return cmpltr;
  2684. }
  2685. /* Parse a 64 bit wide mode add and branch completer returning the number (for
  2686. encoding in instructions) of the given completer. */
  2687. static int
  2688. pa_parse_addb_64_cmpltr (char **s)
  2689. {
  2690. int cmpltr;
  2691. char *name = *s + 1;
  2692. char c;
  2693. char *save_s = *s;
  2694. int nullify = 0;
  2695. cmpltr = 0;
  2696. if (**s == ',')
  2697. {
  2698. *s += 1;
  2699. while (**s != ',' && **s != ' ' && **s != '\t')
  2700. *s += 1;
  2701. c = **s;
  2702. **s = 0x00;
  2703. if (strcmp (name, "=") == 0)
  2704. {
  2705. cmpltr = 1;
  2706. }
  2707. else if (strcmp (name, "<") == 0)
  2708. {
  2709. cmpltr = 2;
  2710. }
  2711. else if (strcmp (name, "<=") == 0)
  2712. {
  2713. cmpltr = 3;
  2714. }
  2715. else if (strcasecmp (name, "nuv") == 0)
  2716. {
  2717. cmpltr = 4;
  2718. }
  2719. else if (strcasecmp (name, "*=") == 0)
  2720. {
  2721. cmpltr = 5;
  2722. }
  2723. else if (strcasecmp (name, "*<") == 0)
  2724. {
  2725. cmpltr = 6;
  2726. }
  2727. else if (strcasecmp (name, "*<=") == 0)
  2728. {
  2729. cmpltr = 7;
  2730. }
  2731. else if (strcmp (name, "tr") == 0)
  2732. {
  2733. cmpltr = 8;
  2734. }
  2735. else if (strcmp (name, "<>") == 0)
  2736. {
  2737. cmpltr = 9;
  2738. }
  2739. else if (strcmp (name, ">=") == 0)
  2740. {
  2741. cmpltr = 10;
  2742. }
  2743. else if (strcmp (name, ">") == 0)
  2744. {
  2745. cmpltr = 11;
  2746. }
  2747. else if (strcasecmp (name, "uv") == 0)
  2748. {
  2749. cmpltr = 12;
  2750. }
  2751. else if (strcasecmp (name, "*<>") == 0)
  2752. {
  2753. cmpltr = 13;
  2754. }
  2755. else if (strcasecmp (name, "*>=") == 0)
  2756. {
  2757. cmpltr = 14;
  2758. }
  2759. else if (strcasecmp (name, "*>") == 0)
  2760. {
  2761. cmpltr = 15;
  2762. }
  2763. /* If we have something like addb,n then there is no condition
  2764. completer. */
  2765. else if (strcasecmp (name, "n") == 0)
  2766. {
  2767. cmpltr = 0;
  2768. nullify = 1;
  2769. }
  2770. else
  2771. {
  2772. cmpltr = -1;
  2773. }
  2774. **s = c;
  2775. }
  2776. /* Reset pointers if this was really a ,n for a branch instruction. */
  2777. if (nullify)
  2778. *s = save_s;
  2779. return cmpltr;
  2780. }
  2781. /* Do the real work for assembling a single instruction. Store results
  2782. into the global "the_insn" variable. */
  2783. static void
  2784. pa_ip (char *str)
  2785. {
  2786. char *error_message = "";
  2787. char *s, c, *argstart, *name, *save_s;
  2788. const char *args;
  2789. int match = FALSE;
  2790. int comma = 0;
  2791. int cmpltr, nullif, flag, cond, need_cond, num;
  2792. int immediate_check = 0, pos = -1, len = -1;
  2793. unsigned long opcode;
  2794. struct pa_opcode *insn;
  2795. #ifdef OBJ_SOM
  2796. /* We must have a valid space and subspace. */
  2797. pa_check_current_space_and_subspace ();
  2798. #endif
  2799. /* Convert everything up to the first whitespace character into lower
  2800. case. */
  2801. for (s = str; *s != ' ' && *s != '\t' && *s != '\n' && *s != '\0'; s++)
  2802. *s = TOLOWER (*s);
  2803. /* Skip to something interesting. */
  2804. for (s = str;
  2805. ISUPPER (*s) || ISLOWER (*s) || (*s >= '0' && *s <= '3');
  2806. ++s)
  2807. ;
  2808. switch (*s)
  2809. {
  2810. case '\0':
  2811. break;
  2812. case ',':
  2813. comma = 1;
  2814. /*FALLTHROUGH */
  2815. case ' ':
  2816. *s++ = '\0';
  2817. break;
  2818. default:
  2819. as_bad (_("Unknown opcode: `%s'"), str);
  2820. return;
  2821. }
  2822. /* Look up the opcode in the hash table. */
  2823. if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
  2824. {
  2825. as_bad (_("Unknown opcode: `%s'"), str);
  2826. return;
  2827. }
  2828. if (comma)
  2829. *--s = ',';
  2830. /* Mark the location where arguments for the instruction start, then
  2831. start processing them. */
  2832. argstart = s;
  2833. for (;;)
  2834. {
  2835. /* Do some initialization. */
  2836. opcode = insn->match;
  2837. strict = (insn->flags & FLAG_STRICT);
  2838. memset (&the_insn, 0, sizeof (the_insn));
  2839. need_cond = 1;
  2840. the_insn.reloc = R_HPPA_NONE;
  2841. if (insn->arch >= pa20
  2842. && bfd_get_mach (stdoutput) < insn->arch)
  2843. goto failed;
  2844. /* Build the opcode, checking as we go to make
  2845. sure that the operands match. */
  2846. for (args = insn->args;; ++args)
  2847. {
  2848. /* Absorb white space in instruction. */
  2849. while (*s == ' ' || *s == '\t')
  2850. s++;
  2851. switch (*args)
  2852. {
  2853. /* End of arguments. */
  2854. case '\0':
  2855. if (*s == '\0')
  2856. match = TRUE;
  2857. break;
  2858. case '+':
  2859. if (*s == '+')
  2860. {
  2861. ++s;
  2862. continue;
  2863. }
  2864. if (*s == '-')
  2865. continue;
  2866. break;
  2867. /* These must match exactly. */
  2868. case '(':
  2869. case ')':
  2870. case ',':
  2871. case ' ':
  2872. if (*s++ == *args)
  2873. continue;
  2874. break;
  2875. /* Handle a 5 bit register or control register field at 10. */
  2876. case 'b':
  2877. case '^':
  2878. if (!pa_parse_number (&s, 0))
  2879. break;
  2880. num = pa_number;
  2881. CHECK_FIELD (num, 31, 0, 0);
  2882. INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
  2883. /* Handle %sar or %cr11. No bits get set, we just verify that it
  2884. is there. */
  2885. case '!':
  2886. /* Skip whitespace before register. */
  2887. while (*s == ' ' || *s == '\t')
  2888. s = s + 1;
  2889. if (!strncasecmp (s, "%sar", 4))
  2890. {
  2891. s += 4;
  2892. continue;
  2893. }
  2894. else if (!strncasecmp (s, "%cr11", 5))
  2895. {
  2896. s += 5;
  2897. continue;
  2898. }
  2899. break;
  2900. /* Handle a 5 bit register field at 15. */
  2901. case 'x':
  2902. if (!pa_parse_number (&s, 0))
  2903. break;
  2904. num = pa_number;
  2905. CHECK_FIELD (num, 31, 0, 0);
  2906. INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  2907. /* Handle a 5 bit register field at 31. */
  2908. case 't':
  2909. if (!pa_parse_number (&s, 0))
  2910. break;
  2911. num = pa_number;
  2912. CHECK_FIELD (num, 31, 0, 0);
  2913. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2914. /* Handle a 5 bit register field at 10 and 15. */
  2915. case 'a':
  2916. if (!pa_parse_number (&s, 0))
  2917. break;
  2918. num = pa_number;
  2919. CHECK_FIELD (num, 31, 0, 0);
  2920. opcode |= num << 16;
  2921. INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
  2922. /* Handle a 5 bit field length at 31. */
  2923. case 'T':
  2924. num = pa_get_absolute_expression (&the_insn, &s);
  2925. if (strict && the_insn.exp.X_op != O_constant)
  2926. break;
  2927. s = expr_end;
  2928. CHECK_FIELD (num, 32, 1, 0);
  2929. SAVE_IMMEDIATE(num);
  2930. INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
  2931. /* Handle a 5 bit immediate at 15. */
  2932. case '5':
  2933. num = pa_get_absolute_expression (&the_insn, &s);
  2934. if (strict && the_insn.exp.X_op != O_constant)
  2935. break;
  2936. s = expr_end;
  2937. /* When in strict mode, we want to just reject this
  2938. match instead of giving an out of range error. */
  2939. CHECK_FIELD (num, 15, -16, strict);
  2940. num = low_sign_unext (num, 5);
  2941. INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  2942. /* Handle a 5 bit immediate at 31. */
  2943. case 'V':
  2944. num = pa_get_absolute_expression (&the_insn, &s);
  2945. if (strict && the_insn.exp.X_op != O_constant)
  2946. break;
  2947. s = expr_end;
  2948. /* When in strict mode, we want to just reject this
  2949. match instead of giving an out of range error. */
  2950. CHECK_FIELD (num, 15, -16, strict);
  2951. num = low_sign_unext (num, 5);
  2952. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2953. /* Handle an unsigned 5 bit immediate at 31. */
  2954. case 'r':
  2955. num = pa_get_absolute_expression (&the_insn, &s);
  2956. if (strict && the_insn.exp.X_op != O_constant)
  2957. break;
  2958. s = expr_end;
  2959. CHECK_FIELD (num, 31, 0, strict);
  2960. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2961. /* Handle an unsigned 5 bit immediate at 15. */
  2962. case 'R':
  2963. num = pa_get_absolute_expression (&the_insn, &s);
  2964. if (strict && the_insn.exp.X_op != O_constant)
  2965. break;
  2966. s = expr_end;
  2967. CHECK_FIELD (num, 31, 0, strict);
  2968. INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  2969. /* Handle an unsigned 10 bit immediate at 15. */
  2970. case 'U':
  2971. num = pa_get_absolute_expression (&the_insn, &s);
  2972. if (strict && the_insn.exp.X_op != O_constant)
  2973. break;
  2974. s = expr_end;
  2975. CHECK_FIELD (num, 1023, 0, strict);
  2976. INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  2977. /* Handle a 2 bit space identifier at 17. */
  2978. case 's':
  2979. if (!pa_parse_number (&s, 0))
  2980. break;
  2981. num = pa_number;
  2982. CHECK_FIELD (num, 3, 0, 1);
  2983. INSERT_FIELD_AND_CONTINUE (opcode, num, 14);
  2984. /* Handle a 3 bit space identifier at 18. */
  2985. case 'S':
  2986. if (!pa_parse_number (&s, 0))
  2987. break;
  2988. num = pa_number;
  2989. CHECK_FIELD (num, 7, 0, 1);
  2990. opcode |= re_assemble_3 (num);
  2991. continue;
  2992. /* Handle all completers. */
  2993. case 'c':
  2994. switch (*++args)
  2995. {
  2996. /* Handle a completer for an indexing load or store. */
  2997. case 'X':
  2998. case 'x':
  2999. {
  3000. int uu = 0;
  3001. int m = 0;
  3002. int i = 0;
  3003. while (*s == ',' && i < 2)
  3004. {
  3005. s++;
  3006. if (strncasecmp (s, "sm", 2) == 0)
  3007. {
  3008. uu = 1;
  3009. m = 1;
  3010. s++;
  3011. i++;
  3012. }
  3013. else if (strncasecmp (s, "m", 1) == 0)
  3014. m = 1;
  3015. else if ((strncasecmp (s, "s ", 2) == 0)
  3016. || (strncasecmp (s, "s,", 2) == 0))
  3017. uu = 1;
  3018. else if (strict)
  3019. {
  3020. /* This is a match failure. */
  3021. s--;
  3022. break;
  3023. }
  3024. else
  3025. as_bad (_("Invalid Indexed Load Completer."));
  3026. s++;
  3027. i++;
  3028. }
  3029. if (i > 2)
  3030. as_bad (_("Invalid Indexed Load Completer Syntax."));
  3031. opcode |= m << 5;
  3032. INSERT_FIELD_AND_CONTINUE (opcode, uu, 13);
  3033. }
  3034. /* Handle a short load/store completer. */
  3035. case 'M':
  3036. case 'm':
  3037. case 'q':
  3038. case 'J':
  3039. case 'e':
  3040. {
  3041. int a = 0;
  3042. int m = 0;
  3043. if (*s == ',')
  3044. {
  3045. s++;
  3046. if (strncasecmp (s, "ma", 2) == 0)
  3047. {
  3048. a = 0;
  3049. m = 1;
  3050. s += 2;
  3051. }
  3052. else if (strncasecmp (s, "mb", 2) == 0)
  3053. {
  3054. a = 1;
  3055. m = 1;
  3056. s += 2;
  3057. }
  3058. else if (strict)
  3059. /* This is a match failure. */
  3060. s--;
  3061. else
  3062. {
  3063. as_bad (_("Invalid Short Load/Store Completer."));
  3064. s += 2;
  3065. }
  3066. }
  3067. /* If we did not get a ma/mb completer, then we do not
  3068. consider this a positive match for 'ce'. */
  3069. else if (*args == 'e')
  3070. break;
  3071. /* 'J', 'm', 'M' and 'q' are the same, except for where they
  3072. encode the before/after field. */
  3073. if (*args == 'm' || *args == 'M')
  3074. {
  3075. opcode |= m << 5;
  3076. INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
  3077. }
  3078. else if (*args == 'q')
  3079. {
  3080. opcode |= m << 3;
  3081. INSERT_FIELD_AND_CONTINUE (opcode, a, 2);
  3082. }
  3083. else if (*args == 'J')
  3084. {
  3085. /* M bit is explicit in the major opcode. */
  3086. INSERT_FIELD_AND_CONTINUE (opcode, a, 2);
  3087. }
  3088. else if (*args == 'e')
  3089. {
  3090. /* Stash the ma/mb flag temporarily in the
  3091. instruction. We will use (and remove it)
  3092. later when handling 'J', 'K', '<' & '>'. */
  3093. opcode |= a;
  3094. continue;
  3095. }
  3096. }
  3097. /* Handle a stbys completer. */
  3098. case 'A':
  3099. case 's':
  3100. {
  3101. int a = 0;
  3102. int m = 0;
  3103. int i = 0;
  3104. while (*s == ',' && i < 2)
  3105. {
  3106. s++;
  3107. if (strncasecmp (s, "m", 1) == 0)
  3108. m = 1;
  3109. else if ((strncasecmp (s, "b ", 2) == 0)
  3110. || (strncasecmp (s, "b,", 2) == 0))
  3111. a = 0;
  3112. else if (strncasecmp (s, "e", 1) == 0)
  3113. a = 1;
  3114. /* In strict mode, this is a match failure. */
  3115. else if (strict)
  3116. {
  3117. s--;
  3118. break;
  3119. }
  3120. else
  3121. as_bad (_("Invalid Store Bytes Short Completer"));
  3122. s++;
  3123. i++;
  3124. }
  3125. if (i > 2)
  3126. as_bad (_("Invalid Store Bytes Short Completer"));
  3127. opcode |= m << 5;
  3128. INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
  3129. }
  3130. /* Handle load cache hint completer. */
  3131. case 'c':
  3132. cmpltr = 0;
  3133. if (!strncmp (s, ",sl", 3))
  3134. {
  3135. s += 3;
  3136. cmpltr = 2;
  3137. }
  3138. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 10);
  3139. /* Handle store cache hint completer. */
  3140. case 'C':
  3141. cmpltr = 0;
  3142. if (!strncmp (s, ",sl", 3))
  3143. {
  3144. s += 3;
  3145. cmpltr = 2;
  3146. }
  3147. else if (!strncmp (s, ",bc", 3))
  3148. {
  3149. s += 3;
  3150. cmpltr = 1;
  3151. }
  3152. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 10);
  3153. /* Handle load and clear cache hint completer. */
  3154. case 'd':
  3155. cmpltr = 0;
  3156. if (!strncmp (s, ",co", 3))
  3157. {
  3158. s += 3;
  3159. cmpltr = 1;
  3160. }
  3161. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 10);
  3162. /* Handle load ordering completer. */
  3163. case 'o':
  3164. if (strncmp (s, ",o", 2) != 0)
  3165. break;
  3166. s += 2;
  3167. continue;
  3168. /* Handle a branch gate completer. */
  3169. case 'g':
  3170. if (strncasecmp (s, ",gate", 5) != 0)
  3171. break;
  3172. s += 5;
  3173. continue;
  3174. /* Handle a branch link and push completer. */
  3175. case 'p':
  3176. if (strncasecmp (s, ",l,push", 7) != 0)
  3177. break;
  3178. s += 7;
  3179. continue;
  3180. /* Handle a branch link completer. */
  3181. case 'l':
  3182. if (strncasecmp (s, ",l", 2) != 0)
  3183. break;
  3184. s += 2;
  3185. continue;
  3186. /* Handle a branch pop completer. */
  3187. case 'P':
  3188. if (strncasecmp (s, ",pop", 4) != 0)
  3189. break;
  3190. s += 4;
  3191. continue;
  3192. /* Handle a local processor completer. */
  3193. case 'L':
  3194. if (strncasecmp (s, ",l", 2) != 0)
  3195. break;
  3196. s += 2;
  3197. continue;
  3198. /* Handle a PROBE read/write completer. */
  3199. case 'w':
  3200. flag = 0;
  3201. if (!strncasecmp (s, ",w", 2))
  3202. {
  3203. flag = 1;
  3204. s += 2;
  3205. }
  3206. else if (!strncasecmp (s, ",r", 2))
  3207. {
  3208. flag = 0;
  3209. s += 2;
  3210. }
  3211. INSERT_FIELD_AND_CONTINUE (opcode, flag, 6);
  3212. /* Handle MFCTL wide completer. */
  3213. case 'W':
  3214. if (strncasecmp (s, ",w", 2) != 0)
  3215. break;
  3216. s += 2;
  3217. continue;
  3218. /* Handle an RFI restore completer. */
  3219. case 'r':
  3220. flag = 0;
  3221. if (!strncasecmp (s, ",r", 2))
  3222. {
  3223. flag = 5;
  3224. s += 2;
  3225. }
  3226. INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
  3227. /* Handle a system control completer. */
  3228. case 'Z':
  3229. if (*s == ',' && (*(s + 1) == 'm' || *(s + 1) == 'M'))
  3230. {
  3231. flag = 1;
  3232. s += 2;
  3233. }
  3234. else
  3235. flag = 0;
  3236. INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
  3237. /* Handle intermediate/final completer for DCOR. */
  3238. case 'i':
  3239. flag = 0;
  3240. if (!strncasecmp (s, ",i", 2))
  3241. {
  3242. flag = 1;
  3243. s += 2;
  3244. }
  3245. INSERT_FIELD_AND_CONTINUE (opcode, flag, 6);
  3246. /* Handle zero/sign extension completer. */
  3247. case 'z':
  3248. flag = 1;
  3249. if (!strncasecmp (s, ",z", 2))
  3250. {
  3251. flag = 0;
  3252. s += 2;
  3253. }
  3254. INSERT_FIELD_AND_CONTINUE (opcode, flag, 10);
  3255. /* Handle add completer. */
  3256. case 'a':
  3257. flag = 1;
  3258. if (!strncasecmp (s, ",l", 2))
  3259. {
  3260. flag = 2;
  3261. s += 2;
  3262. }
  3263. else if (!strncasecmp (s, ",tsv", 4))
  3264. {
  3265. flag = 3;
  3266. s += 4;
  3267. }
  3268. INSERT_FIELD_AND_CONTINUE (opcode, flag, 10);
  3269. /* Handle 64 bit carry for ADD. */
  3270. case 'Y':
  3271. flag = 0;
  3272. if (!strncasecmp (s, ",dc,tsv", 7) ||
  3273. !strncasecmp (s, ",tsv,dc", 7))
  3274. {
  3275. flag = 1;
  3276. s += 7;
  3277. }
  3278. else if (!strncasecmp (s, ",dc", 3))
  3279. {
  3280. flag = 0;
  3281. s += 3;
  3282. }
  3283. else
  3284. break;
  3285. /* Condition is not required with "dc". */
  3286. need_cond = 0;
  3287. INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  3288. /* Handle 32 bit carry for ADD. */
  3289. case 'y':
  3290. flag = 0;
  3291. if (!strncasecmp (s, ",c,tsv", 6) ||
  3292. !strncasecmp (s, ",tsv,c", 6))
  3293. {
  3294. flag = 1;
  3295. s += 6;
  3296. }
  3297. else if (!strncasecmp (s, ",c", 2))
  3298. {
  3299. flag = 0;
  3300. s += 2;
  3301. }
  3302. else
  3303. break;
  3304. INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  3305. /* Handle trap on signed overflow. */
  3306. case 'v':
  3307. flag = 0;
  3308. if (!strncasecmp (s, ",tsv", 4))
  3309. {
  3310. flag = 1;
  3311. s += 4;
  3312. }
  3313. INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  3314. /* Handle trap on condition and overflow. */
  3315. case 't':
  3316. flag = 0;
  3317. if (!strncasecmp (s, ",tc,tsv", 7) ||
  3318. !strncasecmp (s, ",tsv,tc", 7))
  3319. {
  3320. flag = 1;
  3321. s += 7;
  3322. }
  3323. else if (!strncasecmp (s, ",tc", 3))
  3324. {
  3325. flag = 0;
  3326. s += 3;
  3327. }
  3328. else
  3329. break;
  3330. INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  3331. /* Handle 64 bit borrow for SUB. */
  3332. case 'B':
  3333. flag = 0;
  3334. if (!strncasecmp (s, ",db,tsv", 7) ||
  3335. !strncasecmp (s, ",tsv,db", 7))
  3336. {
  3337. flag = 1;
  3338. s += 7;
  3339. }
  3340. else if (!strncasecmp (s, ",db", 3))
  3341. {
  3342. flag = 0;
  3343. s += 3;
  3344. }
  3345. else
  3346. break;
  3347. /* Condition is not required with "db". */
  3348. need_cond = 0;
  3349. INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  3350. /* Handle 32 bit borrow for SUB. */
  3351. case 'b':
  3352. flag = 0;
  3353. if (!strncasecmp (s, ",b,tsv", 6) ||
  3354. !strncasecmp (s, ",tsv,b", 6))
  3355. {
  3356. flag = 1;
  3357. s += 6;
  3358. }
  3359. else if (!strncasecmp (s, ",b", 2))
  3360. {
  3361. flag = 0;
  3362. s += 2;
  3363. }
  3364. else
  3365. break;
  3366. INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  3367. /* Handle trap condition completer for UADDCM. */
  3368. case 'T':
  3369. flag = 0;
  3370. if (!strncasecmp (s, ",tc", 3))
  3371. {
  3372. flag = 1;
  3373. s += 3;
  3374. }
  3375. INSERT_FIELD_AND_CONTINUE (opcode, flag, 6);
  3376. /* Handle signed/unsigned at 21. */
  3377. case 'S':
  3378. {
  3379. int sign = 1;
  3380. if (strncasecmp (s, ",s", 2) == 0)
  3381. {
  3382. sign = 1;
  3383. s += 2;
  3384. }
  3385. else if (strncasecmp (s, ",u", 2) == 0)
  3386. {
  3387. sign = 0;
  3388. s += 2;
  3389. }
  3390. INSERT_FIELD_AND_CONTINUE (opcode, sign, 10);
  3391. }
  3392. /* Handle left/right combination at 17:18. */
  3393. case 'h':
  3394. if (*s++ == ',')
  3395. {
  3396. int lr = 0;
  3397. if (*s == 'r')
  3398. lr = 2;
  3399. else if (*s == 'l')
  3400. lr = 0;
  3401. else
  3402. as_bad (_("Invalid left/right combination completer"));
  3403. s++;
  3404. INSERT_FIELD_AND_CONTINUE (opcode, lr, 13);
  3405. }
  3406. else
  3407. as_bad (_("Invalid left/right combination completer"));
  3408. break;
  3409. /* Handle saturation at 24:25. */
  3410. case 'H':
  3411. {
  3412. int sat = 3;
  3413. if (strncasecmp (s, ",ss", 3) == 0)
  3414. {
  3415. sat = 1;
  3416. s += 3;
  3417. }
  3418. else if (strncasecmp (s, ",us", 3) == 0)
  3419. {
  3420. sat = 0;
  3421. s += 3;
  3422. }
  3423. INSERT_FIELD_AND_CONTINUE (opcode, sat, 6);
  3424. }
  3425. /* Handle permutation completer. */
  3426. case '*':
  3427. if (*s++ == ',')
  3428. {
  3429. int permloc[4];
  3430. int perm = 0;
  3431. int i = 0;
  3432. permloc[0] = 13;
  3433. permloc[1] = 10;
  3434. permloc[2] = 8;
  3435. permloc[3] = 6;
  3436. for (; i < 4; i++)
  3437. {
  3438. switch (*s++)
  3439. {
  3440. case '0':
  3441. perm = 0;
  3442. break;
  3443. case '1':
  3444. perm = 1;
  3445. break;
  3446. case '2':
  3447. perm = 2;
  3448. break;
  3449. case '3':
  3450. perm = 3;
  3451. break;
  3452. default:
  3453. as_bad (_("Invalid permutation completer"));
  3454. }
  3455. opcode |= perm << permloc[i];
  3456. }
  3457. continue;
  3458. }
  3459. else
  3460. as_bad (_("Invalid permutation completer"));
  3461. break;
  3462. default:
  3463. abort ();
  3464. }
  3465. break;
  3466. /* Handle all conditions. */
  3467. case '?':
  3468. {
  3469. args++;
  3470. switch (*args)
  3471. {
  3472. /* Handle FP compare conditions. */
  3473. case 'f':
  3474. cond = pa_parse_fp_cmp_cond (&s);
  3475. INSERT_FIELD_AND_CONTINUE (opcode, cond, 0);
  3476. /* Handle an add condition. */
  3477. case 'A':
  3478. case 'a':
  3479. cmpltr = 0;
  3480. flag = 0;
  3481. if (*s == ',')
  3482. {
  3483. s++;
  3484. /* 64 bit conditions. */
  3485. if (*args == 'A')
  3486. {
  3487. if (*s == '*')
  3488. s++;
  3489. else
  3490. break;
  3491. }
  3492. else if (*s == '*')
  3493. break;
  3494. name = s;
  3495. while (*s != ',' && *s != ' ' && *s != '\t')
  3496. s += 1;
  3497. c = *s;
  3498. *s = 0x00;
  3499. if (strcmp (name, "=") == 0)
  3500. cmpltr = 1;
  3501. else if (strcmp (name, "<") == 0)
  3502. cmpltr = 2;
  3503. else if (strcmp (name, "<=") == 0)
  3504. cmpltr = 3;
  3505. else if (strcasecmp (name, "nuv") == 0)
  3506. cmpltr = 4;
  3507. else if (strcasecmp (name, "znv") == 0)
  3508. cmpltr = 5;
  3509. else if (strcasecmp (name, "sv") == 0)
  3510. cmpltr = 6;
  3511. else if (strcasecmp (name, "od") == 0)
  3512. cmpltr = 7;
  3513. else if (strcasecmp (name, "tr") == 0)
  3514. {
  3515. cmpltr = 0;
  3516. flag = 1;
  3517. }
  3518. else if (strcmp (name, "<>") == 0)
  3519. {
  3520. cmpltr = 1;
  3521. flag = 1;
  3522. }
  3523. else if (strcmp (name, ">=") == 0)
  3524. {
  3525. cmpltr = 2;
  3526. flag = 1;
  3527. }
  3528. else if (strcmp (name, ">") == 0)
  3529. {
  3530. cmpltr = 3;
  3531. flag = 1;
  3532. }
  3533. else if (strcasecmp (name, "uv") == 0)
  3534. {
  3535. cmpltr = 4;
  3536. flag = 1;
  3537. }
  3538. else if (strcasecmp (name, "vnz") == 0)
  3539. {
  3540. cmpltr = 5;
  3541. flag = 1;
  3542. }
  3543. else if (strcasecmp (name, "nsv") == 0)
  3544. {
  3545. cmpltr = 6;
  3546. flag = 1;
  3547. }
  3548. else if (strcasecmp (name, "ev") == 0)
  3549. {
  3550. cmpltr = 7;
  3551. flag = 1;
  3552. }
  3553. /* ",*" is a valid condition. */
  3554. else if (*args == 'a' || *name)
  3555. as_bad (_("Invalid Add Condition: %s"), name);
  3556. *s = c;
  3557. }
  3558. /* Except with "dc", we have a match failure with
  3559. 'A' if we don't have a doubleword condition. */
  3560. else if (*args == 'A' && need_cond)
  3561. break;
  3562. opcode |= cmpltr << 13;
  3563. INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  3564. /* Handle non-negated add and branch condition. */
  3565. case 'd':
  3566. cmpltr = pa_parse_nonneg_add_cmpltr (&s);
  3567. if (cmpltr < 0)
  3568. {
  3569. as_bad (_("Invalid Add and Branch Condition"));
  3570. cmpltr = 0;
  3571. }
  3572. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  3573. /* Handle 64 bit wide-mode add and branch condition. */
  3574. case 'W':
  3575. cmpltr = pa_parse_addb_64_cmpltr (&s);
  3576. if (cmpltr < 0)
  3577. {
  3578. as_bad (_("Invalid Add and Branch Condition"));
  3579. cmpltr = 0;
  3580. }
  3581. else
  3582. {
  3583. /* Negated condition requires an opcode change. */
  3584. opcode |= (cmpltr & 8) << 24;
  3585. }
  3586. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr & 7, 13);
  3587. /* Handle a negated or non-negated add and branch
  3588. condition. */
  3589. case '@':
  3590. save_s = s;
  3591. cmpltr = pa_parse_nonneg_add_cmpltr (&s);
  3592. if (cmpltr < 0)
  3593. {
  3594. s = save_s;
  3595. cmpltr = pa_parse_neg_add_cmpltr (&s);
  3596. if (cmpltr < 0)
  3597. {
  3598. as_bad (_("Invalid Compare/Subtract Condition"));
  3599. cmpltr = 0;
  3600. }
  3601. else
  3602. {
  3603. /* Negated condition requires an opcode change. */
  3604. opcode |= 1 << 27;
  3605. }
  3606. }
  3607. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  3608. /* Handle branch on bit conditions. */
  3609. case 'B':
  3610. case 'b':
  3611. cmpltr = 0;
  3612. if (*s == ',')
  3613. {
  3614. s++;
  3615. if (*args == 'B')
  3616. {
  3617. if (*s == '*')
  3618. s++;
  3619. else
  3620. break;
  3621. }
  3622. else if (*s == '*')
  3623. break;
  3624. if (strncmp (s, "<", 1) == 0)
  3625. {
  3626. cmpltr = 0;
  3627. s++;
  3628. }
  3629. else if (strncmp (s, ">=", 2) == 0)
  3630. {
  3631. cmpltr = 1;
  3632. s += 2;
  3633. }
  3634. else
  3635. as_bad (_("Invalid Branch On Bit Condition: %c"), *s);
  3636. }
  3637. else
  3638. as_bad (_("Missing Branch On Bit Condition"));
  3639. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 15);
  3640. /* Handle a compare/subtract condition. */
  3641. case 'S':
  3642. case 's':
  3643. cmpltr = 0;
  3644. flag = 0;
  3645. if (*s == ',')
  3646. {
  3647. s++;
  3648. /* 64 bit conditions. */
  3649. if (*args == 'S')
  3650. {
  3651. if (*s == '*')
  3652. s++;
  3653. else
  3654. break;
  3655. }
  3656. else if (*s == '*')
  3657. break;
  3658. name = s;
  3659. while (*s != ',' && *s != ' ' && *s != '\t')
  3660. s += 1;
  3661. c = *s;
  3662. *s = 0x00;
  3663. if (strcmp (name, "=") == 0)
  3664. cmpltr = 1;
  3665. else if (strcmp (name, "<") == 0)
  3666. cmpltr = 2;
  3667. else if (strcmp (name, "<=") == 0)
  3668. cmpltr = 3;
  3669. else if (strcasecmp (name, "<<") == 0)
  3670. cmpltr = 4;
  3671. else if (strcasecmp (name, "<<=") == 0)
  3672. cmpltr = 5;
  3673. else if (strcasecmp (name, "sv") == 0)
  3674. cmpltr = 6;
  3675. else if (strcasecmp (name, "od") == 0)
  3676. cmpltr = 7;
  3677. else if (strcasecmp (name, "tr") == 0)
  3678. {
  3679. cmpltr = 0;
  3680. flag = 1;
  3681. }
  3682. else if (strcmp (name, "<>") == 0)
  3683. {
  3684. cmpltr = 1;
  3685. flag = 1;
  3686. }
  3687. else if (strcmp (name, ">=") == 0)
  3688. {
  3689. cmpltr = 2;
  3690. flag = 1;
  3691. }
  3692. else if (strcmp (name, ">") == 0)
  3693. {
  3694. cmpltr = 3;
  3695. flag = 1;
  3696. }
  3697. else if (strcasecmp (name, ">>=") == 0)
  3698. {
  3699. cmpltr = 4;
  3700. flag = 1;
  3701. }
  3702. else if (strcasecmp (name, ">>") == 0)
  3703. {
  3704. cmpltr = 5;
  3705. flag = 1;
  3706. }
  3707. else if (strcasecmp (name, "nsv") == 0)
  3708. {
  3709. cmpltr = 6;
  3710. flag = 1;
  3711. }
  3712. else if (strcasecmp (name, "ev") == 0)
  3713. {
  3714. cmpltr = 7;
  3715. flag = 1;
  3716. }
  3717. /* ",*" is a valid condition. */
  3718. else if (*args != 'S' || *name)
  3719. as_bad (_("Invalid Compare/Subtract Condition: %s"),
  3720. name);
  3721. *s = c;
  3722. }
  3723. /* Except with "db", we have a match failure with
  3724. 'S' if we don't have a doubleword condition. */
  3725. else if (*args == 'S' && need_cond)
  3726. break;
  3727. opcode |= cmpltr << 13;
  3728. INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  3729. /* Handle a non-negated compare condition. */
  3730. case 't':
  3731. cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s);
  3732. if (cmpltr < 0)
  3733. {
  3734. as_bad (_("Invalid Compare/Subtract Condition"));
  3735. cmpltr = 0;
  3736. }
  3737. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  3738. /* Handle a 32 bit compare and branch condition. */
  3739. case 'n':
  3740. save_s = s;
  3741. cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s);
  3742. if (cmpltr < 0)
  3743. {
  3744. s = save_s;
  3745. cmpltr = pa_parse_neg_cmpsub_cmpltr (&s);
  3746. if (cmpltr < 0)
  3747. {
  3748. as_bad (_("Invalid Compare and Branch Condition"));
  3749. cmpltr = 0;
  3750. }
  3751. else
  3752. {
  3753. /* Negated condition requires an opcode change. */
  3754. opcode |= 1 << 27;
  3755. }
  3756. }
  3757. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  3758. /* Handle a 64 bit compare and branch condition. */
  3759. case 'N':
  3760. cmpltr = pa_parse_cmpb_64_cmpltr (&s);
  3761. if (cmpltr >= 0)
  3762. {
  3763. /* Negated condition requires an opcode change. */
  3764. opcode |= (cmpltr & 8) << 26;
  3765. }
  3766. else
  3767. /* Not a 64 bit cond. Give 32 bit a chance. */
  3768. break;
  3769. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr & 7, 13);
  3770. /* Handle a 64 bit cmpib condition. */
  3771. case 'Q':
  3772. cmpltr = pa_parse_cmpib_64_cmpltr (&s);
  3773. if (cmpltr < 0)
  3774. /* Not a 64 bit cond. Give 32 bit a chance. */
  3775. break;
  3776. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  3777. /* Handle a logical instruction condition. */
  3778. case 'L':
  3779. case 'l':
  3780. cmpltr = 0;
  3781. flag = 0;
  3782. if (*s == ',')
  3783. {
  3784. s++;
  3785. /* 64 bit conditions. */
  3786. if (*args == 'L')
  3787. {
  3788. if (*s == '*')
  3789. s++;
  3790. else
  3791. break;
  3792. }
  3793. else if (*s == '*')
  3794. break;
  3795. name = s;
  3796. while (*s != ',' && *s != ' ' && *s != '\t')
  3797. s += 1;
  3798. c = *s;
  3799. *s = 0x00;
  3800. if (strcmp (name, "=") == 0)
  3801. cmpltr = 1;
  3802. else if (strcmp (name, "<") == 0)
  3803. cmpltr = 2;
  3804. else if (strcmp (name, "<=") == 0)
  3805. cmpltr = 3;
  3806. else if (strcasecmp (name, "od") == 0)
  3807. cmpltr = 7;
  3808. else if (strcasecmp (name, "tr") == 0)
  3809. {
  3810. cmpltr = 0;
  3811. flag = 1;
  3812. }
  3813. else if (strcmp (name, "<>") == 0)
  3814. {
  3815. cmpltr = 1;
  3816. flag = 1;
  3817. }
  3818. else if (strcmp (name, ">=") == 0)
  3819. {
  3820. cmpltr = 2;
  3821. flag = 1;
  3822. }
  3823. else if (strcmp (name, ">") == 0)
  3824. {
  3825. cmpltr = 3;
  3826. flag = 1;
  3827. }
  3828. else if (strcasecmp (name, "ev") == 0)
  3829. {
  3830. cmpltr = 7;
  3831. flag = 1;
  3832. }
  3833. /* ",*" is a valid condition. */
  3834. else if (*args != 'L' || *name)
  3835. as_bad (_("Invalid Logical Instruction Condition."));
  3836. *s = c;
  3837. }
  3838. /* 32-bit is default for no condition. */
  3839. else if (*args == 'L')
  3840. break;
  3841. opcode |= cmpltr << 13;
  3842. INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  3843. /* Handle a shift/extract/deposit condition. */
  3844. case 'X':
  3845. case 'x':
  3846. case 'y':
  3847. cmpltr = 0;
  3848. /* Check immediate values in shift/extract/deposit
  3849. * instructions if they will give undefined behaviour. */
  3850. immediate_check = 1;
  3851. if (*s == ',')
  3852. {
  3853. save_s = s++;
  3854. /* 64 bit conditions. */
  3855. if (*args == 'X')
  3856. {
  3857. if (*s == '*')
  3858. s++;
  3859. else
  3860. break;
  3861. }
  3862. else if (*s == '*')
  3863. break;
  3864. name = s;
  3865. while (*s != ',' && *s != ' ' && *s != '\t')
  3866. s += 1;
  3867. c = *s;
  3868. *s = 0x00;
  3869. if (strcmp (name, "=") == 0)
  3870. cmpltr = 1;
  3871. else if (strcmp (name, "<") == 0)
  3872. cmpltr = 2;
  3873. else if (strcasecmp (name, "od") == 0)
  3874. cmpltr = 3;
  3875. else if (strcasecmp (name, "tr") == 0)
  3876. cmpltr = 4;
  3877. else if (strcmp (name, "<>") == 0)
  3878. cmpltr = 5;
  3879. else if (strcmp (name, ">=") == 0)
  3880. cmpltr = 6;
  3881. else if (strcasecmp (name, "ev") == 0)
  3882. cmpltr = 7;
  3883. /* Handle movb,n. Put things back the way they were.
  3884. This includes moving s back to where it started. */
  3885. else if (strcasecmp (name, "n") == 0 && *args == 'y')
  3886. {
  3887. *s = c;
  3888. s = save_s;
  3889. continue;
  3890. }
  3891. /* ",*" is a valid condition. */
  3892. else if (*args != 'X' || *name)
  3893. as_bad (_("Invalid Shift/Extract/Deposit Condition."));
  3894. *s = c;
  3895. }
  3896. INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  3897. /* Handle a unit instruction condition. */
  3898. case 'U':
  3899. case 'u':
  3900. cmpltr = 0;
  3901. flag = 0;
  3902. if (*s == ',')
  3903. {
  3904. s++;
  3905. /* 64 bit conditions. */
  3906. if (*args == 'U')
  3907. {
  3908. if (*s == '*')
  3909. s++;
  3910. else
  3911. break;
  3912. }
  3913. else if (*s == '*')
  3914. break;
  3915. if (strncasecmp (s, "sbz", 3) == 0)
  3916. {
  3917. cmpltr = 2;
  3918. s += 3;
  3919. }
  3920. else if (strncasecmp (s, "shz", 3) == 0)
  3921. {
  3922. cmpltr = 3;
  3923. s += 3;
  3924. }
  3925. else if (strncasecmp (s, "sdc", 3) == 0)
  3926. {
  3927. cmpltr = 4;
  3928. s += 3;
  3929. }
  3930. else if (strncasecmp (s, "sbc", 3) == 0)
  3931. {
  3932. cmpltr = 6;
  3933. s += 3;
  3934. }
  3935. else if (strncasecmp (s, "shc", 3) == 0)
  3936. {
  3937. cmpltr = 7;
  3938. s += 3;
  3939. }
  3940. else if (strncasecmp (s, "tr", 2) == 0)
  3941. {
  3942. cmpltr = 0;
  3943. flag = 1;
  3944. s += 2;
  3945. }
  3946. else if (strncasecmp (s, "nbz", 3) == 0)
  3947. {
  3948. cmpltr = 2;
  3949. flag = 1;
  3950. s += 3;
  3951. }
  3952. else if (strncasecmp (s, "nhz", 3) == 0)
  3953. {
  3954. cmpltr = 3;
  3955. flag = 1;
  3956. s += 3;
  3957. }
  3958. else if (strncasecmp (s, "ndc", 3) == 0)
  3959. {
  3960. cmpltr = 4;
  3961. flag = 1;
  3962. s += 3;
  3963. }
  3964. else if (strncasecmp (s, "nbc", 3) == 0)
  3965. {
  3966. cmpltr = 6;
  3967. flag = 1;
  3968. s += 3;
  3969. }
  3970. else if (strncasecmp (s, "nhc", 3) == 0)
  3971. {
  3972. cmpltr = 7;
  3973. flag = 1;
  3974. s += 3;
  3975. }
  3976. else if (strncasecmp (s, "swz", 3) == 0)
  3977. {
  3978. cmpltr = 1;
  3979. flag = 0;
  3980. s += 3;
  3981. }
  3982. else if (strncasecmp (s, "swc", 3) == 0)
  3983. {
  3984. cmpltr = 5;
  3985. flag = 0;
  3986. s += 3;
  3987. }
  3988. else if (strncasecmp (s, "nwz", 3) == 0)
  3989. {
  3990. cmpltr = 1;
  3991. flag = 1;
  3992. s += 3;
  3993. }
  3994. else if (strncasecmp (s, "nwc", 3) == 0)
  3995. {
  3996. cmpltr = 5;
  3997. flag = 1;
  3998. s += 3;
  3999. }
  4000. /* ",*" is a valid condition. */
  4001. else if (*args != 'U' || (*s != ' ' && *s != '\t'))
  4002. as_bad (_("Invalid Unit Instruction Condition."));
  4003. }
  4004. /* 32-bit is default for no condition. */
  4005. else if (*args == 'U')
  4006. break;
  4007. opcode |= cmpltr << 13;
  4008. INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  4009. default:
  4010. abort ();
  4011. }
  4012. break;
  4013. }
  4014. /* Handle a nullification completer for branch instructions. */
  4015. case 'n':
  4016. nullif = pa_parse_nullif (&s);
  4017. INSERT_FIELD_AND_CONTINUE (opcode, nullif, 1);
  4018. /* Handle a nullification completer for copr and spop insns. */
  4019. case 'N':
  4020. nullif = pa_parse_nullif (&s);
  4021. INSERT_FIELD_AND_CONTINUE (opcode, nullif, 5);
  4022. /* Handle ,%r2 completer for new syntax branches. */
  4023. case 'L':
  4024. if (*s == ',' && strncasecmp (s + 1, "%r2", 3) == 0)
  4025. s += 4;
  4026. else if (*s == ',' && strncasecmp (s + 1, "%rp", 3) == 0)
  4027. s += 4;
  4028. else
  4029. break;
  4030. continue;
  4031. /* Handle 3 bit entry into the fp compare array. Valid values
  4032. are 0..6 inclusive. */
  4033. case 'h':
  4034. get_expression (s);
  4035. s = expr_end;
  4036. if (the_insn.exp.X_op == O_constant)
  4037. {
  4038. num = evaluate_absolute (&the_insn);
  4039. CHECK_FIELD (num, 6, 0, 0);
  4040. num++;
  4041. INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
  4042. }
  4043. else
  4044. break;
  4045. /* Handle 3 bit entry into the fp compare array. Valid values
  4046. are 0..6 inclusive. */
  4047. case 'm':
  4048. get_expression (s);
  4049. if (the_insn.exp.X_op == O_constant)
  4050. {
  4051. s = expr_end;
  4052. num = evaluate_absolute (&the_insn);
  4053. CHECK_FIELD (num, 6, 0, 0);
  4054. num = (num + 1) ^ 1;
  4055. INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
  4056. }
  4057. else
  4058. break;
  4059. /* Handle graphics test completers for ftest */
  4060. case '=':
  4061. {
  4062. num = pa_parse_ftest_gfx_completer (&s);
  4063. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4064. }
  4065. /* Handle a 11 bit immediate at 31. */
  4066. case 'i':
  4067. the_insn.field_selector = pa_chk_field_selector (&s);
  4068. get_expression (s);
  4069. s = expr_end;
  4070. if (the_insn.exp.X_op == O_constant)
  4071. {
  4072. num = evaluate_absolute (&the_insn);
  4073. CHECK_FIELD (num, 1023, -1024, 0);
  4074. num = low_sign_unext (num, 11);
  4075. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4076. }
  4077. else
  4078. {
  4079. if (is_DP_relative (the_insn.exp))
  4080. the_insn.reloc = R_HPPA_GOTOFF;
  4081. else if (is_PC_relative (the_insn.exp))
  4082. the_insn.reloc = R_HPPA_PCREL_CALL;
  4083. #ifdef OBJ_ELF
  4084. else if (is_tls_gdidx (the_insn.exp))
  4085. the_insn.reloc = R_PARISC_TLS_GD21L;
  4086. else if (is_tls_ldidx (the_insn.exp))
  4087. the_insn.reloc = R_PARISC_TLS_LDM21L;
  4088. else if (is_tls_dtpoff (the_insn.exp))
  4089. the_insn.reloc = R_PARISC_TLS_LDO21L;
  4090. else if (is_tls_ieoff (the_insn.exp))
  4091. the_insn.reloc = R_PARISC_TLS_IE21L;
  4092. else if (is_tls_leoff (the_insn.exp))
  4093. the_insn.reloc = R_PARISC_TLS_LE21L;
  4094. #endif
  4095. else
  4096. the_insn.reloc = R_HPPA;
  4097. the_insn.format = 11;
  4098. continue;
  4099. }
  4100. /* Handle a 14 bit immediate at 31. */
  4101. case 'J':
  4102. the_insn.field_selector = pa_chk_field_selector (&s);
  4103. get_expression (s);
  4104. s = expr_end;
  4105. if (the_insn.exp.X_op == O_constant)
  4106. {
  4107. int mb;
  4108. /* XXX the completer stored away tidbits of information
  4109. for us to extract. We need a cleaner way to do this.
  4110. Now that we have lots of letters again, it would be
  4111. good to rethink this. */
  4112. mb = opcode & 1;
  4113. opcode -= mb;
  4114. num = evaluate_absolute (&the_insn);
  4115. if (mb != (num < 0))
  4116. break;
  4117. CHECK_FIELD (num, 8191, -8192, 0);
  4118. num = low_sign_unext (num, 14);
  4119. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4120. }
  4121. break;
  4122. /* Handle a 14 bit immediate at 31. */
  4123. case 'K':
  4124. the_insn.field_selector = pa_chk_field_selector (&s);
  4125. get_expression (s);
  4126. s = expr_end;
  4127. if (the_insn.exp.X_op == O_constant)
  4128. {
  4129. int mb;
  4130. mb = opcode & 1;
  4131. opcode -= mb;
  4132. num = evaluate_absolute (&the_insn);
  4133. if (mb == (num < 0))
  4134. break;
  4135. if (num % 4)
  4136. break;
  4137. CHECK_FIELD (num, 8191, -8192, 0);
  4138. num = low_sign_unext (num, 14);
  4139. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4140. }
  4141. break;
  4142. /* Handle a 16 bit immediate at 31. */
  4143. case '<':
  4144. the_insn.field_selector = pa_chk_field_selector (&s);
  4145. get_expression (s);
  4146. s = expr_end;
  4147. if (the_insn.exp.X_op == O_constant)
  4148. {
  4149. int mb;
  4150. mb = opcode & 1;
  4151. opcode -= mb;
  4152. num = evaluate_absolute (&the_insn);
  4153. if (mb != (num < 0))
  4154. break;
  4155. CHECK_FIELD (num, 32767, -32768, 0);
  4156. num = re_assemble_16 (num);
  4157. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4158. }
  4159. break;
  4160. /* Handle a 16 bit immediate at 31. */
  4161. case '>':
  4162. the_insn.field_selector = pa_chk_field_selector (&s);
  4163. get_expression (s);
  4164. s = expr_end;
  4165. if (the_insn.exp.X_op == O_constant)
  4166. {
  4167. int mb;
  4168. mb = opcode & 1;
  4169. opcode -= mb;
  4170. num = evaluate_absolute (&the_insn);
  4171. if (mb == (num < 0))
  4172. break;
  4173. if (num % 4)
  4174. break;
  4175. CHECK_FIELD (num, 32767, -32768, 0);
  4176. num = re_assemble_16 (num);
  4177. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4178. }
  4179. break;
  4180. /* Handle 14 bit immediate, shifted left three times. */
  4181. case '#':
  4182. if (bfd_get_mach (stdoutput) != pa20)
  4183. break;
  4184. the_insn.field_selector = pa_chk_field_selector (&s);
  4185. get_expression (s);
  4186. s = expr_end;
  4187. if (the_insn.exp.X_op == O_constant)
  4188. {
  4189. num = evaluate_absolute (&the_insn);
  4190. if (num & 0x7)
  4191. break;
  4192. CHECK_FIELD (num, 8191, -8192, 0);
  4193. if (num < 0)
  4194. opcode |= 1;
  4195. num &= 0x1fff;
  4196. num >>= 3;
  4197. INSERT_FIELD_AND_CONTINUE (opcode, num, 4);
  4198. }
  4199. else
  4200. {
  4201. if (is_DP_relative (the_insn.exp))
  4202. the_insn.reloc = R_HPPA_GOTOFF;
  4203. else if (is_PC_relative (the_insn.exp))
  4204. the_insn.reloc = R_HPPA_PCREL_CALL;
  4205. #ifdef OBJ_ELF
  4206. else if (is_tls_gdidx (the_insn.exp))
  4207. the_insn.reloc = R_PARISC_TLS_GD21L;
  4208. else if (is_tls_ldidx (the_insn.exp))
  4209. the_insn.reloc = R_PARISC_TLS_LDM21L;
  4210. else if (is_tls_dtpoff (the_insn.exp))
  4211. the_insn.reloc = R_PARISC_TLS_LDO21L;
  4212. else if (is_tls_ieoff (the_insn.exp))
  4213. the_insn.reloc = R_PARISC_TLS_IE21L;
  4214. else if (is_tls_leoff (the_insn.exp))
  4215. the_insn.reloc = R_PARISC_TLS_LE21L;
  4216. #endif
  4217. else
  4218. the_insn.reloc = R_HPPA;
  4219. the_insn.format = 14;
  4220. continue;
  4221. }
  4222. break;
  4223. /* Handle 14 bit immediate, shifted left twice. */
  4224. case 'd':
  4225. the_insn.field_selector = pa_chk_field_selector (&s);
  4226. get_expression (s);
  4227. s = expr_end;
  4228. if (the_insn.exp.X_op == O_constant)
  4229. {
  4230. num = evaluate_absolute (&the_insn);
  4231. if (num & 0x3)
  4232. break;
  4233. CHECK_FIELD (num, 8191, -8192, 0);
  4234. if (num < 0)
  4235. opcode |= 1;
  4236. num &= 0x1fff;
  4237. num >>= 2;
  4238. INSERT_FIELD_AND_CONTINUE (opcode, num, 3);
  4239. }
  4240. else
  4241. {
  4242. if (is_DP_relative (the_insn.exp))
  4243. the_insn.reloc = R_HPPA_GOTOFF;
  4244. else if (is_PC_relative (the_insn.exp))
  4245. the_insn.reloc = R_HPPA_PCREL_CALL;
  4246. #ifdef OBJ_ELF
  4247. else if (is_tls_gdidx (the_insn.exp))
  4248. the_insn.reloc = R_PARISC_TLS_GD21L;
  4249. else if (is_tls_ldidx (the_insn.exp))
  4250. the_insn.reloc = R_PARISC_TLS_LDM21L;
  4251. else if (is_tls_dtpoff (the_insn.exp))
  4252. the_insn.reloc = R_PARISC_TLS_LDO21L;
  4253. else if (is_tls_ieoff (the_insn.exp))
  4254. the_insn.reloc = R_PARISC_TLS_IE21L;
  4255. else if (is_tls_leoff (the_insn.exp))
  4256. the_insn.reloc = R_PARISC_TLS_LE21L;
  4257. #endif
  4258. else
  4259. the_insn.reloc = R_HPPA;
  4260. the_insn.format = 14;
  4261. continue;
  4262. }
  4263. /* Handle a 14 bit immediate at 31. */
  4264. case 'j':
  4265. the_insn.field_selector = pa_chk_field_selector (&s);
  4266. get_expression (s);
  4267. s = expr_end;
  4268. if (the_insn.exp.X_op == O_constant)
  4269. {
  4270. num = evaluate_absolute (&the_insn);
  4271. CHECK_FIELD (num, 8191, -8192, 0);
  4272. num = low_sign_unext (num, 14);
  4273. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4274. }
  4275. else
  4276. {
  4277. if (is_DP_relative (the_insn.exp))
  4278. the_insn.reloc = R_HPPA_GOTOFF;
  4279. else if (is_PC_relative (the_insn.exp))
  4280. the_insn.reloc = R_HPPA_PCREL_CALL;
  4281. #ifdef OBJ_ELF
  4282. else if (is_tls_gdidx (the_insn.exp))
  4283. the_insn.reloc = R_PARISC_TLS_GD21L;
  4284. else if (is_tls_ldidx (the_insn.exp))
  4285. the_insn.reloc = R_PARISC_TLS_LDM21L;
  4286. else if (is_tls_dtpoff (the_insn.exp))
  4287. the_insn.reloc = R_PARISC_TLS_LDO21L;
  4288. else if (is_tls_ieoff (the_insn.exp))
  4289. the_insn.reloc = R_PARISC_TLS_IE21L;
  4290. else if (is_tls_leoff (the_insn.exp))
  4291. the_insn.reloc = R_PARISC_TLS_LE21L;
  4292. #endif
  4293. else
  4294. the_insn.reloc = R_HPPA;
  4295. the_insn.format = 14;
  4296. continue;
  4297. }
  4298. /* Handle a 21 bit immediate at 31. */
  4299. case 'k':
  4300. the_insn.field_selector = pa_chk_field_selector (&s);
  4301. get_expression (s);
  4302. s = expr_end;
  4303. if (the_insn.exp.X_op == O_constant)
  4304. {
  4305. num = evaluate_absolute (&the_insn);
  4306. CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
  4307. opcode |= re_assemble_21 (num);
  4308. continue;
  4309. }
  4310. else
  4311. {
  4312. if (is_DP_relative (the_insn.exp))
  4313. the_insn.reloc = R_HPPA_GOTOFF;
  4314. else if (is_PC_relative (the_insn.exp))
  4315. the_insn.reloc = R_HPPA_PCREL_CALL;
  4316. #ifdef OBJ_ELF
  4317. else if (is_tls_gdidx (the_insn.exp))
  4318. the_insn.reloc = R_PARISC_TLS_GD21L;
  4319. else if (is_tls_ldidx (the_insn.exp))
  4320. the_insn.reloc = R_PARISC_TLS_LDM21L;
  4321. else if (is_tls_dtpoff (the_insn.exp))
  4322. the_insn.reloc = R_PARISC_TLS_LDO21L;
  4323. else if (is_tls_ieoff (the_insn.exp))
  4324. the_insn.reloc = R_PARISC_TLS_IE21L;
  4325. else if (is_tls_leoff (the_insn.exp))
  4326. the_insn.reloc = R_PARISC_TLS_LE21L;
  4327. #endif
  4328. else
  4329. the_insn.reloc = R_HPPA;
  4330. the_insn.format = 21;
  4331. continue;
  4332. }
  4333. /* Handle a 16 bit immediate at 31 (PA 2.0 wide mode only). */
  4334. case 'l':
  4335. the_insn.field_selector = pa_chk_field_selector (&s);
  4336. get_expression (s);
  4337. s = expr_end;
  4338. if (the_insn.exp.X_op == O_constant)
  4339. {
  4340. num = evaluate_absolute (&the_insn);
  4341. CHECK_FIELD (num, 32767, -32768, 0);
  4342. opcode |= re_assemble_16 (num);
  4343. continue;
  4344. }
  4345. else
  4346. {
  4347. /* ??? Is this valid for wide mode? */
  4348. if (is_DP_relative (the_insn.exp))
  4349. the_insn.reloc = R_HPPA_GOTOFF;
  4350. else if (is_PC_relative (the_insn.exp))
  4351. the_insn.reloc = R_HPPA_PCREL_CALL;
  4352. #ifdef OBJ_ELF
  4353. else if (is_tls_gdidx (the_insn.exp))
  4354. the_insn.reloc = R_PARISC_TLS_GD21L;
  4355. else if (is_tls_ldidx (the_insn.exp))
  4356. the_insn.reloc = R_PARISC_TLS_LDM21L;
  4357. else if (is_tls_dtpoff (the_insn.exp))
  4358. the_insn.reloc = R_PARISC_TLS_LDO21L;
  4359. else if (is_tls_ieoff (the_insn.exp))
  4360. the_insn.reloc = R_PARISC_TLS_IE21L;
  4361. else if (is_tls_leoff (the_insn.exp))
  4362. the_insn.reloc = R_PARISC_TLS_LE21L;
  4363. #endif
  4364. else
  4365. the_insn.reloc = R_HPPA;
  4366. the_insn.format = 14;
  4367. continue;
  4368. }
  4369. /* Handle a word-aligned 16-bit imm. at 31 (PA2.0 wide). */
  4370. case 'y':
  4371. the_insn.field_selector = pa_chk_field_selector (&s);
  4372. get_expression (s);
  4373. s = expr_end;
  4374. if (the_insn.exp.X_op == O_constant)
  4375. {
  4376. num = evaluate_absolute (&the_insn);
  4377. CHECK_FIELD (num, 32767, -32768, 0);
  4378. CHECK_ALIGN (num, 4, 0);
  4379. opcode |= re_assemble_16 (num);
  4380. continue;
  4381. }
  4382. else
  4383. {
  4384. /* ??? Is this valid for wide mode? */
  4385. if (is_DP_relative (the_insn.exp))
  4386. the_insn.reloc = R_HPPA_GOTOFF;
  4387. else if (is_PC_relative (the_insn.exp))
  4388. the_insn.reloc = R_HPPA_PCREL_CALL;
  4389. #ifdef OBJ_ELF
  4390. else if (is_tls_gdidx (the_insn.exp))
  4391. the_insn.reloc = R_PARISC_TLS_GD21L;
  4392. else if (is_tls_ldidx (the_insn.exp))
  4393. the_insn.reloc = R_PARISC_TLS_LDM21L;
  4394. else if (is_tls_dtpoff (the_insn.exp))
  4395. the_insn.reloc = R_PARISC_TLS_LDO21L;
  4396. else if (is_tls_ieoff (the_insn.exp))
  4397. the_insn.reloc = R_PARISC_TLS_IE21L;
  4398. else if (is_tls_leoff (the_insn.exp))
  4399. the_insn.reloc = R_PARISC_TLS_LE21L;
  4400. #endif
  4401. else
  4402. the_insn.reloc = R_HPPA;
  4403. the_insn.format = 14;
  4404. continue;
  4405. }
  4406. /* Handle a dword-aligned 16-bit imm. at 31 (PA2.0 wide). */
  4407. case '&':
  4408. the_insn.field_selector = pa_chk_field_selector (&s);
  4409. get_expression (s);
  4410. s = expr_end;
  4411. if (the_insn.exp.X_op == O_constant)
  4412. {
  4413. num = evaluate_absolute (&the_insn);
  4414. CHECK_FIELD (num, 32767, -32768, 0);
  4415. CHECK_ALIGN (num, 8, 0);
  4416. opcode |= re_assemble_16 (num);
  4417. continue;
  4418. }
  4419. else
  4420. {
  4421. /* ??? Is this valid for wide mode? */
  4422. if (is_DP_relative (the_insn.exp))
  4423. the_insn.reloc = R_HPPA_GOTOFF;
  4424. else if (is_PC_relative (the_insn.exp))
  4425. the_insn.reloc = R_HPPA_PCREL_CALL;
  4426. #ifdef OBJ_ELF
  4427. else if (is_tls_gdidx (the_insn.exp))
  4428. the_insn.reloc = R_PARISC_TLS_GD21L;
  4429. else if (is_tls_ldidx (the_insn.exp))
  4430. the_insn.reloc = R_PARISC_TLS_LDM21L;
  4431. else if (is_tls_dtpoff (the_insn.exp))
  4432. the_insn.reloc = R_PARISC_TLS_LDO21L;
  4433. else if (is_tls_ieoff (the_insn.exp))
  4434. the_insn.reloc = R_PARISC_TLS_IE21L;
  4435. else if (is_tls_leoff (the_insn.exp))
  4436. the_insn.reloc = R_PARISC_TLS_LE21L;
  4437. #endif
  4438. else
  4439. the_insn.reloc = R_HPPA;
  4440. the_insn.format = 14;
  4441. continue;
  4442. }
  4443. /* Handle a 12 bit branch displacement. */
  4444. case 'w':
  4445. the_insn.field_selector = pa_chk_field_selector (&s);
  4446. get_expression (s);
  4447. s = expr_end;
  4448. the_insn.pcrel = 1;
  4449. if (!the_insn.exp.X_add_symbol
  4450. || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
  4451. FAKE_LABEL_NAME))
  4452. {
  4453. num = evaluate_absolute (&the_insn);
  4454. if (num % 4)
  4455. {
  4456. as_bad (_("Branch to unaligned address"));
  4457. break;
  4458. }
  4459. if (the_insn.exp.X_add_symbol)
  4460. num -= 8;
  4461. CHECK_FIELD (num, 8191, -8192, 0);
  4462. opcode |= re_assemble_12 (num >> 2);
  4463. continue;
  4464. }
  4465. else
  4466. {
  4467. the_insn.reloc = R_HPPA_PCREL_CALL;
  4468. the_insn.format = 12;
  4469. the_insn.arg_reloc = last_call_desc.arg_reloc;
  4470. memset (&last_call_desc, 0, sizeof (struct call_desc));
  4471. s = expr_end;
  4472. continue;
  4473. }
  4474. /* Handle a 17 bit branch displacement. */
  4475. case 'W':
  4476. the_insn.field_selector = pa_chk_field_selector (&s);
  4477. get_expression (s);
  4478. s = expr_end;
  4479. the_insn.pcrel = 1;
  4480. if (!the_insn.exp.X_add_symbol
  4481. || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
  4482. FAKE_LABEL_NAME))
  4483. {
  4484. num = evaluate_absolute (&the_insn);
  4485. if (num % 4)
  4486. {
  4487. as_bad (_("Branch to unaligned address"));
  4488. break;
  4489. }
  4490. if (the_insn.exp.X_add_symbol)
  4491. num -= 8;
  4492. CHECK_FIELD (num, 262143, -262144, 0);
  4493. opcode |= re_assemble_17 (num >> 2);
  4494. continue;
  4495. }
  4496. else
  4497. {
  4498. the_insn.reloc = R_HPPA_PCREL_CALL;
  4499. the_insn.format = 17;
  4500. the_insn.arg_reloc = last_call_desc.arg_reloc;
  4501. memset (&last_call_desc, 0, sizeof (struct call_desc));
  4502. continue;
  4503. }
  4504. /* Handle a 22 bit branch displacement. */
  4505. case 'X':
  4506. the_insn.field_selector = pa_chk_field_selector (&s);
  4507. get_expression (s);
  4508. s = expr_end;
  4509. the_insn.pcrel = 1;
  4510. if (!the_insn.exp.X_add_symbol
  4511. || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
  4512. FAKE_LABEL_NAME))
  4513. {
  4514. num = evaluate_absolute (&the_insn);
  4515. if (num % 4)
  4516. {
  4517. as_bad (_("Branch to unaligned address"));
  4518. break;
  4519. }
  4520. if (the_insn.exp.X_add_symbol)
  4521. num -= 8;
  4522. CHECK_FIELD (num, 8388607, -8388608, 0);
  4523. opcode |= re_assemble_22 (num >> 2);
  4524. }
  4525. else
  4526. {
  4527. the_insn.reloc = R_HPPA_PCREL_CALL;
  4528. the_insn.format = 22;
  4529. the_insn.arg_reloc = last_call_desc.arg_reloc;
  4530. memset (&last_call_desc, 0, sizeof (struct call_desc));
  4531. continue;
  4532. }
  4533. /* Handle an absolute 17 bit branch target. */
  4534. case 'z':
  4535. the_insn.field_selector = pa_chk_field_selector (&s);
  4536. get_expression (s);
  4537. s = expr_end;
  4538. the_insn.pcrel = 0;
  4539. if (!the_insn.exp.X_add_symbol
  4540. || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
  4541. FAKE_LABEL_NAME))
  4542. {
  4543. num = evaluate_absolute (&the_insn);
  4544. if (num % 4)
  4545. {
  4546. as_bad (_("Branch to unaligned address"));
  4547. break;
  4548. }
  4549. if (the_insn.exp.X_add_symbol)
  4550. num -= 8;
  4551. CHECK_FIELD (num, 262143, -262144, 0);
  4552. opcode |= re_assemble_17 (num >> 2);
  4553. continue;
  4554. }
  4555. else
  4556. {
  4557. the_insn.reloc = R_HPPA_ABS_CALL;
  4558. the_insn.format = 17;
  4559. the_insn.arg_reloc = last_call_desc.arg_reloc;
  4560. memset (&last_call_desc, 0, sizeof (struct call_desc));
  4561. continue;
  4562. }
  4563. /* Handle '%r1' implicit operand of addil instruction. */
  4564. case 'Z':
  4565. if (*s == ',' && *(s + 1) == '%' && *(s + 3) == '1'
  4566. && (*(s + 2) == 'r' || *(s + 2) == 'R'))
  4567. {
  4568. s += 4;
  4569. continue;
  4570. }
  4571. else
  4572. break;
  4573. /* Handle '%sr0,%r31' implicit operand of be,l instruction. */
  4574. case 'Y':
  4575. if (strncasecmp (s, "%sr0,%r31", 9) != 0)
  4576. break;
  4577. s += 9;
  4578. continue;
  4579. /* Handle immediate value of 0 for ordered load/store instructions. */
  4580. case '@':
  4581. if (*s != '0')
  4582. break;
  4583. s++;
  4584. continue;
  4585. /* Handle a 2 bit shift count at 25. */
  4586. case '.':
  4587. num = pa_get_absolute_expression (&the_insn, &s);
  4588. if (strict && the_insn.exp.X_op != O_constant)
  4589. break;
  4590. s = expr_end;
  4591. CHECK_FIELD (num, 3, 1, strict);
  4592. INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
  4593. /* Handle a 4 bit shift count at 25. */
  4594. case '*':
  4595. num = pa_get_absolute_expression (&the_insn, &s);
  4596. if (strict && the_insn.exp.X_op != O_constant)
  4597. break;
  4598. s = expr_end;
  4599. CHECK_FIELD (num, 15, 0, strict);
  4600. INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
  4601. /* Handle a 5 bit shift count at 26. */
  4602. case 'p':
  4603. num = pa_get_absolute_expression (&the_insn, &s);
  4604. if (strict && the_insn.exp.X_op != O_constant)
  4605. break;
  4606. s = expr_end;
  4607. CHECK_FIELD (num, 31, 0, strict);
  4608. SAVE_IMMEDIATE(num);
  4609. INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
  4610. /* Handle a 6 bit shift count at 20,22:26. */
  4611. case '~':
  4612. num = pa_get_absolute_expression (&the_insn, &s);
  4613. if (strict && the_insn.exp.X_op != O_constant)
  4614. break;
  4615. s = expr_end;
  4616. CHECK_FIELD (num, 63, 0, strict);
  4617. SAVE_IMMEDIATE(num);
  4618. num = 63 - num;
  4619. opcode |= (num & 0x20) << 6;
  4620. INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
  4621. /* Handle a 6 bit field length at 23,27:31. */
  4622. case '%':
  4623. flag = 0;
  4624. num = pa_get_absolute_expression (&the_insn, &s);
  4625. if (strict && the_insn.exp.X_op != O_constant)
  4626. break;
  4627. s = expr_end;
  4628. CHECK_FIELD (num, 64, 1, strict);
  4629. SAVE_IMMEDIATE(num);
  4630. num--;
  4631. opcode |= (num & 0x20) << 3;
  4632. num = 31 - (num & 0x1f);
  4633. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4634. /* Handle a 6 bit field length at 19,27:31. */
  4635. case '|':
  4636. num = pa_get_absolute_expression (&the_insn, &s);
  4637. if (strict && the_insn.exp.X_op != O_constant)
  4638. break;
  4639. s = expr_end;
  4640. CHECK_FIELD (num, 64, 1, strict);
  4641. SAVE_IMMEDIATE(num);
  4642. num--;
  4643. opcode |= (num & 0x20) << 7;
  4644. num = 31 - (num & 0x1f);
  4645. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4646. /* Handle a 5 bit bit position at 26. */
  4647. case 'P':
  4648. num = pa_get_absolute_expression (&the_insn, &s);
  4649. if (strict && the_insn.exp.X_op != O_constant)
  4650. break;
  4651. s = expr_end;
  4652. CHECK_FIELD (num, 31, 0, strict);
  4653. SAVE_IMMEDIATE(num);
  4654. INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
  4655. /* Handle a 6 bit bit position at 20,22:26. */
  4656. case 'q':
  4657. num = pa_get_absolute_expression (&the_insn, &s);
  4658. if (strict && the_insn.exp.X_op != O_constant)
  4659. break;
  4660. s = expr_end;
  4661. CHECK_FIELD (num, 63, 0, strict);
  4662. SAVE_IMMEDIATE(num);
  4663. opcode |= (num & 0x20) << 6;
  4664. INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
  4665. /* Handle a 5 bit immediate at 10 with 'd' as the complement
  4666. of the high bit of the immediate. */
  4667. case 'B':
  4668. num = pa_get_absolute_expression (&the_insn, &s);
  4669. if (strict && the_insn.exp.X_op != O_constant)
  4670. break;
  4671. s = expr_end;
  4672. CHECK_FIELD (num, 63, 0, strict);
  4673. if (num & 0x20)
  4674. ;
  4675. else
  4676. opcode |= (1 << 13);
  4677. INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 21);
  4678. /* Handle a 5 bit immediate at 10. */
  4679. case 'Q':
  4680. num = pa_get_absolute_expression (&the_insn, &s);
  4681. if (strict && the_insn.exp.X_op != O_constant)
  4682. break;
  4683. s = expr_end;
  4684. CHECK_FIELD (num, 31, 0, strict);
  4685. INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
  4686. /* Handle a 9 bit immediate at 28. */
  4687. case '$':
  4688. num = pa_get_absolute_expression (&the_insn, &s);
  4689. if (strict && the_insn.exp.X_op != O_constant)
  4690. break;
  4691. s = expr_end;
  4692. CHECK_FIELD (num, 511, 1, strict);
  4693. INSERT_FIELD_AND_CONTINUE (opcode, num, 3);
  4694. /* Handle a 13 bit immediate at 18. */
  4695. case 'A':
  4696. num = pa_get_absolute_expression (&the_insn, &s);
  4697. if (strict && the_insn.exp.X_op != O_constant)
  4698. break;
  4699. s = expr_end;
  4700. CHECK_FIELD (num, 8191, 0, strict);
  4701. INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
  4702. /* Handle a 26 bit immediate at 31. */
  4703. case 'D':
  4704. num = pa_get_absolute_expression (&the_insn, &s);
  4705. if (strict && the_insn.exp.X_op != O_constant)
  4706. break;
  4707. s = expr_end;
  4708. CHECK_FIELD (num, 67108863, 0, strict);
  4709. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4710. /* Handle a 3 bit SFU identifier at 25. */
  4711. case 'v':
  4712. if (*s++ != ',')
  4713. as_bad (_("Invalid SFU identifier"));
  4714. num = pa_get_absolute_expression (&the_insn, &s);
  4715. if (strict && the_insn.exp.X_op != O_constant)
  4716. break;
  4717. s = expr_end;
  4718. CHECK_FIELD (num, 7, 0, strict);
  4719. INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
  4720. /* Handle a 20 bit SOP field for spop0. */
  4721. case 'O':
  4722. num = pa_get_absolute_expression (&the_insn, &s);
  4723. if (strict && the_insn.exp.X_op != O_constant)
  4724. break;
  4725. s = expr_end;
  4726. CHECK_FIELD (num, 1048575, 0, strict);
  4727. num = (num & 0x1f) | ((num & 0x000fffe0) << 6);
  4728. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4729. /* Handle a 15bit SOP field for spop1. */
  4730. case 'o':
  4731. num = pa_get_absolute_expression (&the_insn, &s);
  4732. if (strict && the_insn.exp.X_op != O_constant)
  4733. break;
  4734. s = expr_end;
  4735. CHECK_FIELD (num, 32767, 0, strict);
  4736. INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
  4737. /* Handle a 10bit SOP field for spop3. */
  4738. case '0':
  4739. num = pa_get_absolute_expression (&the_insn, &s);
  4740. if (strict && the_insn.exp.X_op != O_constant)
  4741. break;
  4742. s = expr_end;
  4743. CHECK_FIELD (num, 1023, 0, strict);
  4744. num = (num & 0x1f) | ((num & 0x000003e0) << 6);
  4745. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4746. /* Handle a 15 bit SOP field for spop2. */
  4747. case '1':
  4748. num = pa_get_absolute_expression (&the_insn, &s);
  4749. if (strict && the_insn.exp.X_op != O_constant)
  4750. break;
  4751. s = expr_end;
  4752. CHECK_FIELD (num, 32767, 0, strict);
  4753. num = (num & 0x1f) | ((num & 0x00007fe0) << 6);
  4754. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4755. /* Handle a 3-bit co-processor ID field. */
  4756. case 'u':
  4757. if (*s++ != ',')
  4758. as_bad (_("Invalid COPR identifier"));
  4759. num = pa_get_absolute_expression (&the_insn, &s);
  4760. if (strict && the_insn.exp.X_op != O_constant)
  4761. break;
  4762. s = expr_end;
  4763. CHECK_FIELD (num, 7, 0, strict);
  4764. INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
  4765. /* Handle a 22bit SOP field for copr. */
  4766. case '2':
  4767. num = pa_get_absolute_expression (&the_insn, &s);
  4768. if (strict && the_insn.exp.X_op != O_constant)
  4769. break;
  4770. s = expr_end;
  4771. CHECK_FIELD (num, 4194303, 0, strict);
  4772. num = (num & 0x1f) | ((num & 0x003fffe0) << 4);
  4773. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4774. /* Handle a source FP operand format completer. */
  4775. case '{':
  4776. if (*s == ',' && *(s+1) == 't')
  4777. {
  4778. the_insn.trunc = 1;
  4779. s += 2;
  4780. }
  4781. else
  4782. the_insn.trunc = 0;
  4783. flag = pa_parse_fp_cnv_format (&s);
  4784. the_insn.fpof1 = flag;
  4785. if (flag == W || flag == UW)
  4786. flag = SGL;
  4787. if (flag == DW || flag == UDW)
  4788. flag = DBL;
  4789. if (flag == QW || flag == UQW)
  4790. flag = QUAD;
  4791. INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  4792. /* Handle a destination FP operand format completer. */
  4793. case '_':
  4794. /* pa_parse_format needs the ',' prefix. */
  4795. s--;
  4796. flag = pa_parse_fp_cnv_format (&s);
  4797. the_insn.fpof2 = flag;
  4798. if (flag == W || flag == UW)
  4799. flag = SGL;
  4800. if (flag == DW || flag == UDW)
  4801. flag = DBL;
  4802. if (flag == QW || flag == UQW)
  4803. flag = QUAD;
  4804. opcode |= flag << 13;
  4805. if (the_insn.fpof1 == SGL
  4806. || the_insn.fpof1 == DBL
  4807. || the_insn.fpof1 == QUAD)
  4808. {
  4809. if (the_insn.fpof2 == SGL
  4810. || the_insn.fpof2 == DBL
  4811. || the_insn.fpof2 == QUAD)
  4812. flag = 0;
  4813. else if (the_insn.fpof2 == W
  4814. || the_insn.fpof2 == DW
  4815. || the_insn.fpof2 == QW)
  4816. flag = 2;
  4817. else if (the_insn.fpof2 == UW
  4818. || the_insn.fpof2 == UDW
  4819. || the_insn.fpof2 == UQW)
  4820. flag = 6;
  4821. else
  4822. abort ();
  4823. }
  4824. else if (the_insn.fpof1 == W
  4825. || the_insn.fpof1 == DW
  4826. || the_insn.fpof1 == QW)
  4827. {
  4828. if (the_insn.fpof2 == SGL
  4829. || the_insn.fpof2 == DBL
  4830. || the_insn.fpof2 == QUAD)
  4831. flag = 1;
  4832. else
  4833. abort ();
  4834. }
  4835. else if (the_insn.fpof1 == UW
  4836. || the_insn.fpof1 == UDW
  4837. || the_insn.fpof1 == UQW)
  4838. {
  4839. if (the_insn.fpof2 == SGL
  4840. || the_insn.fpof2 == DBL
  4841. || the_insn.fpof2 == QUAD)
  4842. flag = 5;
  4843. else
  4844. abort ();
  4845. }
  4846. flag |= the_insn.trunc;
  4847. INSERT_FIELD_AND_CONTINUE (opcode, flag, 15);
  4848. /* Handle a source FP operand format completer. */
  4849. case 'F':
  4850. flag = pa_parse_fp_format (&s);
  4851. the_insn.fpof1 = flag;
  4852. INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  4853. /* Handle a destination FP operand format completer. */
  4854. case 'G':
  4855. /* pa_parse_format needs the ',' prefix. */
  4856. s--;
  4857. flag = pa_parse_fp_format (&s);
  4858. the_insn.fpof2 = flag;
  4859. INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
  4860. /* Handle a source FP operand format completer at 20. */
  4861. case 'I':
  4862. flag = pa_parse_fp_format (&s);
  4863. the_insn.fpof1 = flag;
  4864. INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  4865. /* Handle a floating point operand format at 26.
  4866. Only allows single and double precision. */
  4867. case 'H':
  4868. flag = pa_parse_fp_format (&s);
  4869. switch (flag)
  4870. {
  4871. case SGL:
  4872. opcode |= 0x20;
  4873. case DBL:
  4874. the_insn.fpof1 = flag;
  4875. continue;
  4876. case QUAD:
  4877. case ILLEGAL_FMT:
  4878. default:
  4879. as_bad (_("Invalid Floating Point Operand Format."));
  4880. }
  4881. break;
  4882. /* Handle all floating point registers. */
  4883. case 'f':
  4884. switch (*++args)
  4885. {
  4886. /* Float target register. */
  4887. case 't':
  4888. if (!pa_parse_number (&s, 3))
  4889. break;
  4890. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  4891. CHECK_FIELD (num, 31, 0, 0);
  4892. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  4893. /* Float target register with L/R selection. */
  4894. case 'T':
  4895. {
  4896. if (!pa_parse_number (&s, 1))
  4897. break;
  4898. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  4899. CHECK_FIELD (num, 31, 0, 0);
  4900. opcode |= num;
  4901. /* 0x30 opcodes are FP arithmetic operation opcodes
  4902. and need to be turned into 0x38 opcodes. This
  4903. is not necessary for loads/stores. */
  4904. if (need_pa11_opcode ()
  4905. && ((opcode & 0xfc000000) == 0x30000000))
  4906. opcode |= 1 << 27;
  4907. opcode |= (pa_number & FP_REG_RSEL ? 1 << 6 : 0);
  4908. continue;
  4909. }
  4910. /* Float operand 1. */
  4911. case 'a':
  4912. {
  4913. if (!pa_parse_number (&s, 1))
  4914. break;
  4915. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  4916. CHECK_FIELD (num, 31, 0, 0);
  4917. opcode |= num << 21;
  4918. if (need_pa11_opcode ())
  4919. {
  4920. opcode |= (pa_number & FP_REG_RSEL ? 1 << 7 : 0);
  4921. opcode |= 1 << 27;
  4922. }
  4923. continue;
  4924. }
  4925. /* Float operand 1 with L/R selection. */
  4926. case 'X':
  4927. case 'A':
  4928. {
  4929. if (!pa_parse_number (&s, 1))
  4930. break;
  4931. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  4932. CHECK_FIELD (num, 31, 0, 0);
  4933. opcode |= num << 21;
  4934. opcode |= (pa_number & FP_REG_RSEL ? 1 << 7 : 0);
  4935. continue;
  4936. }
  4937. /* Float operand 2. */
  4938. case 'b':
  4939. {
  4940. if (!pa_parse_number (&s, 1))
  4941. break;
  4942. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  4943. CHECK_FIELD (num, 31, 0, 0);
  4944. opcode |= num << 16;
  4945. if (need_pa11_opcode ())
  4946. {
  4947. opcode |= (pa_number & FP_REG_RSEL ? 1 << 12 : 0);
  4948. opcode |= 1 << 27;
  4949. }
  4950. continue;
  4951. }
  4952. /* Float operand 2 with L/R selection. */
  4953. case 'B':
  4954. {
  4955. if (!pa_parse_number (&s, 1))
  4956. break;
  4957. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  4958. CHECK_FIELD (num, 31, 0, 0);
  4959. opcode |= num << 16;
  4960. opcode |= (pa_number & FP_REG_RSEL ? 1 << 12 : 0);
  4961. continue;
  4962. }
  4963. /* Float operand 3 for fmpyfadd, fmpynfadd. */
  4964. case 'C':
  4965. {
  4966. if (!pa_parse_number (&s, 1))
  4967. break;
  4968. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  4969. CHECK_FIELD (num, 31, 0, 0);
  4970. opcode |= (num & 0x1c) << 11;
  4971. opcode |= (num & 0x03) << 9;
  4972. opcode |= (pa_number & FP_REG_RSEL ? 1 << 8 : 0);
  4973. continue;
  4974. }
  4975. /* Float mult operand 1 for fmpyadd, fmpysub */
  4976. case 'i':
  4977. {
  4978. if (!pa_parse_number (&s, 1))
  4979. break;
  4980. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  4981. CHECK_FIELD (num, 31, 0, 0);
  4982. if (the_insn.fpof1 == SGL)
  4983. {
  4984. if (num < 16)
  4985. {
  4986. as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
  4987. break;
  4988. }
  4989. num &= 0xF;
  4990. num |= (pa_number & FP_REG_RSEL ? 1 << 4 : 0);
  4991. }
  4992. INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
  4993. }
  4994. /* Float mult operand 2 for fmpyadd, fmpysub */
  4995. case 'j':
  4996. {
  4997. if (!pa_parse_number (&s, 1))
  4998. break;
  4999. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  5000. CHECK_FIELD (num, 31, 0, 0);
  5001. if (the_insn.fpof1 == SGL)
  5002. {
  5003. if (num < 16)
  5004. {
  5005. as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
  5006. break;
  5007. }
  5008. num &= 0xF;
  5009. num |= (pa_number & FP_REG_RSEL ? 1 << 4 : 0);
  5010. }
  5011. INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  5012. }
  5013. /* Float mult target for fmpyadd, fmpysub */
  5014. case 'k':
  5015. {
  5016. if (!pa_parse_number (&s, 1))
  5017. break;
  5018. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  5019. CHECK_FIELD (num, 31, 0, 0);
  5020. if (the_insn.fpof1 == SGL)
  5021. {
  5022. if (num < 16)
  5023. {
  5024. as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
  5025. break;
  5026. }
  5027. num &= 0xF;
  5028. num |= (pa_number & FP_REG_RSEL ? 1 << 4 : 0);
  5029. }
  5030. INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  5031. }
  5032. /* Float add operand 1 for fmpyadd, fmpysub */
  5033. case 'l':
  5034. {
  5035. if (!pa_parse_number (&s, 1))
  5036. break;
  5037. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  5038. CHECK_FIELD (num, 31, 0, 0);
  5039. if (the_insn.fpof1 == SGL)
  5040. {
  5041. if (num < 16)
  5042. {
  5043. as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
  5044. break;
  5045. }
  5046. num &= 0xF;
  5047. num |= (pa_number & FP_REG_RSEL ? 1 << 4 : 0);
  5048. }
  5049. INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
  5050. }
  5051. /* Float add target for fmpyadd, fmpysub */
  5052. case 'm':
  5053. {
  5054. if (!pa_parse_number (&s, 1))
  5055. break;
  5056. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  5057. CHECK_FIELD (num, 31, 0, 0);
  5058. if (the_insn.fpof1 == SGL)
  5059. {
  5060. if (num < 16)
  5061. {
  5062. as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
  5063. break;
  5064. }
  5065. num &= 0xF;
  5066. num |= (pa_number & FP_REG_RSEL ? 1 << 4 : 0);
  5067. }
  5068. INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
  5069. }
  5070. /* Handle L/R register halves like 'x'. */
  5071. case 'E':
  5072. case 'e':
  5073. {
  5074. if (!pa_parse_number (&s, 1))
  5075. break;
  5076. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  5077. CHECK_FIELD (num, 31, 0, 0);
  5078. opcode |= num << 16;
  5079. if (need_pa11_opcode ())
  5080. {
  5081. opcode |= (pa_number & FP_REG_RSEL ? 1 << 1 : 0);
  5082. }
  5083. continue;
  5084. }
  5085. /* Float target register (PA 2.0 wide). */
  5086. case 'x':
  5087. if (!pa_parse_number (&s, 3))
  5088. break;
  5089. num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
  5090. CHECK_FIELD (num, 31, 0, 0);
  5091. INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  5092. default:
  5093. abort ();
  5094. }
  5095. break;
  5096. default:
  5097. abort ();
  5098. }
  5099. break;
  5100. }
  5101. /* If this instruction is specific to a particular architecture,
  5102. then set a new architecture. This automatic promotion crud is
  5103. for compatibility with HP's old assemblers only. */
  5104. if (match == TRUE
  5105. && bfd_get_mach (stdoutput) < insn->arch
  5106. && !bfd_set_arch_mach (stdoutput, bfd_arch_hppa, insn->arch))
  5107. {
  5108. as_warn (_("could not update architecture and machine"));
  5109. match = FALSE;
  5110. }
  5111. failed:
  5112. /* Check if the args matched. */
  5113. if (!match)
  5114. {
  5115. if (&insn[1] - pa_opcodes < (int) NUMOPCODES
  5116. && !strcmp (insn->name, insn[1].name))
  5117. {
  5118. ++insn;
  5119. s = argstart;
  5120. continue;
  5121. }
  5122. else
  5123. {
  5124. as_bad (_("Invalid operands %s"), error_message);
  5125. return;
  5126. }
  5127. }
  5128. break;
  5129. }
  5130. if (immediate_check)
  5131. {
  5132. if (pos != -1 && len != -1 && pos < len - 1)
  5133. as_warn (_("Immediates %d and %d will give undefined behavior."),
  5134. pos, len);
  5135. }
  5136. the_insn.opcode = opcode;
  5137. }
  5138. /* Assemble a single instruction storing it into a frag. */
  5139. void
  5140. md_assemble (char *str)
  5141. {
  5142. char *to;
  5143. /* The had better be something to assemble. */
  5144. gas_assert (str);
  5145. /* If we are within a procedure definition, make sure we've
  5146. defined a label for the procedure; handle case where the
  5147. label was defined after the .PROC directive.
  5148. Note there's not need to diddle with the segment or fragment
  5149. for the label symbol in this case. We have already switched
  5150. into the new $CODE$ subspace at this point. */
  5151. if (within_procedure && last_call_info->start_symbol == NULL)
  5152. {
  5153. label_symbol_struct *label_symbol = pa_get_label ();
  5154. if (label_symbol)
  5155. {
  5156. if (label_symbol->lss_label)
  5157. {
  5158. last_call_info->start_symbol = label_symbol->lss_label;
  5159. symbol_get_bfdsym (label_symbol->lss_label)->flags
  5160. |= BSF_FUNCTION;
  5161. #ifdef OBJ_SOM
  5162. /* Also handle allocation of a fixup to hold the unwind
  5163. information when the label appears after the proc/procend. */
  5164. if (within_entry_exit)
  5165. {
  5166. char *where;
  5167. unsigned int u;
  5168. where = frag_more (0);
  5169. u = UNWIND_LOW32 (&last_call_info->ci_unwind.descriptor);
  5170. fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  5171. NULL, (offsetT) 0, NULL,
  5172. 0, R_HPPA_ENTRY, e_fsel, 0, 0, u);
  5173. }
  5174. #endif
  5175. }
  5176. else
  5177. as_bad (_("Missing function name for .PROC (corrupted label chain)"));
  5178. }
  5179. else
  5180. as_bad (_("Missing function name for .PROC"));
  5181. }
  5182. /* Assemble the instruction. Results are saved into "the_insn". */
  5183. pa_ip (str);
  5184. /* Get somewhere to put the assembled instruction. */
  5185. to = frag_more (4);
  5186. /* Output the opcode. */
  5187. md_number_to_chars (to, the_insn.opcode, 4);
  5188. /* If necessary output more stuff. */
  5189. if (the_insn.reloc != R_HPPA_NONE)
  5190. fix_new_hppa (frag_now, (to - frag_now->fr_literal), 4, NULL,
  5191. (offsetT) 0, &the_insn.exp, the_insn.pcrel,
  5192. the_insn.reloc, the_insn.field_selector,
  5193. the_insn.format, the_insn.arg_reloc, 0);
  5194. #ifdef OBJ_ELF
  5195. dwarf2_emit_insn (4);
  5196. #endif
  5197. }
  5198. #ifdef OBJ_SOM
  5199. /* Handle an alignment directive. Special so that we can update the
  5200. alignment of the subspace if necessary. */
  5201. static void
  5202. pa_align (int bytes)
  5203. {
  5204. /* We must have a valid space and subspace. */
  5205. pa_check_current_space_and_subspace ();
  5206. /* Let the generic gas code do most of the work. */
  5207. s_align_bytes (bytes);
  5208. /* If bytes is a power of 2, then update the current subspace's
  5209. alignment if necessary. */
  5210. if (exact_log2 (bytes) != -1)
  5211. record_alignment (current_subspace->ssd_seg, exact_log2 (bytes));
  5212. }
  5213. #endif
  5214. /* Handle a .BLOCK type pseudo-op. */
  5215. static void
  5216. pa_block (int z ATTRIBUTE_UNUSED)
  5217. {
  5218. unsigned int temp_size;
  5219. #ifdef OBJ_SOM
  5220. /* We must have a valid space and subspace. */
  5221. pa_check_current_space_and_subspace ();
  5222. #endif
  5223. temp_size = get_absolute_expression ();
  5224. if (temp_size > 0x3FFFFFFF)
  5225. {
  5226. as_bad (_("Argument to .BLOCK/.BLOCKZ must be between 0 and 0x3fffffff"));
  5227. temp_size = 0;
  5228. }
  5229. else
  5230. {
  5231. /* Always fill with zeros, that's what the HP assembler does. */
  5232. char *p = frag_var (rs_fill, 1, 1, 0, NULL, temp_size, NULL);
  5233. *p = 0;
  5234. }
  5235. pa_undefine_label ();
  5236. demand_empty_rest_of_line ();
  5237. }
  5238. /* Handle a .begin_brtab and .end_brtab pseudo-op. */
  5239. static void
  5240. pa_brtab (int begin ATTRIBUTE_UNUSED)
  5241. {
  5242. #ifdef OBJ_SOM
  5243. /* The BRTAB relocations are only available in SOM (to denote
  5244. the beginning and end of branch tables). */
  5245. char *where = frag_more (0);
  5246. fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  5247. NULL, (offsetT) 0, NULL,
  5248. 0, begin ? R_HPPA_BEGIN_BRTAB : R_HPPA_END_BRTAB,
  5249. e_fsel, 0, 0, 0);
  5250. #endif
  5251. demand_empty_rest_of_line ();
  5252. }
  5253. /* Handle a .begin_try and .end_try pseudo-op. */
  5254. static void
  5255. pa_try (int begin ATTRIBUTE_UNUSED)
  5256. {
  5257. #ifdef OBJ_SOM
  5258. expressionS exp;
  5259. char *where = frag_more (0);
  5260. if (! begin)
  5261. expression (&exp);
  5262. /* The TRY relocations are only available in SOM (to denote
  5263. the beginning and end of exception handling regions). */
  5264. fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  5265. NULL, (offsetT) 0, begin ? NULL : &exp,
  5266. 0, begin ? R_HPPA_BEGIN_TRY : R_HPPA_END_TRY,
  5267. e_fsel, 0, 0, 0);
  5268. #endif
  5269. demand_empty_rest_of_line ();
  5270. }
  5271. /* Do the dirty work of building a call descriptor which describes
  5272. where the caller placed arguments to a function call. */
  5273. static void
  5274. pa_call_args (struct call_desc *call_desc)
  5275. {
  5276. char *name, c, *p;
  5277. unsigned int temp, arg_reloc;
  5278. while (!is_end_of_statement ())
  5279. {
  5280. name = input_line_pointer;
  5281. c = get_symbol_end ();
  5282. /* Process a source argument. */
  5283. if ((strncasecmp (name, "argw", 4) == 0))
  5284. {
  5285. temp = atoi (name + 4);
  5286. p = input_line_pointer;
  5287. *p = c;
  5288. input_line_pointer++;
  5289. name = input_line_pointer;
  5290. c = get_symbol_end ();
  5291. arg_reloc = pa_build_arg_reloc (name);
  5292. call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
  5293. }
  5294. /* Process a return value. */
  5295. else if ((strncasecmp (name, "rtnval", 6) == 0))
  5296. {
  5297. p = input_line_pointer;
  5298. *p = c;
  5299. input_line_pointer++;
  5300. name = input_line_pointer;
  5301. c = get_symbol_end ();
  5302. arg_reloc = pa_build_arg_reloc (name);
  5303. call_desc->arg_reloc |= (arg_reloc & 0x3);
  5304. }
  5305. else
  5306. {
  5307. as_bad (_("Invalid .CALL argument: %s"), name);
  5308. }
  5309. p = input_line_pointer;
  5310. *p = c;
  5311. if (!is_end_of_statement ())
  5312. input_line_pointer++;
  5313. }
  5314. }
  5315. /* Handle a .CALL pseudo-op. This involves storing away information
  5316. about where arguments are to be found so the linker can detect
  5317. (and correct) argument location mismatches between caller and callee. */
  5318. static void
  5319. pa_call (int unused ATTRIBUTE_UNUSED)
  5320. {
  5321. #ifdef OBJ_SOM
  5322. /* We must have a valid space and subspace. */
  5323. pa_check_current_space_and_subspace ();
  5324. #endif
  5325. pa_call_args (&last_call_desc);
  5326. demand_empty_rest_of_line ();
  5327. }
  5328. #ifdef OBJ_ELF
  5329. /* Build an entry in the UNWIND subspace from the given function
  5330. attributes in CALL_INFO. This is not needed for SOM as using
  5331. R_ENTRY and R_EXIT relocations allow the linker to handle building
  5332. of the unwind spaces. */
  5333. static void
  5334. pa_build_unwind_subspace (struct call_info *call_info)
  5335. {
  5336. asection *seg, *save_seg;
  5337. subsegT save_subseg;
  5338. unsigned int unwind;
  5339. int reloc;
  5340. char *name, *p;
  5341. symbolS *symbolP;
  5342. if ((bfd_get_section_flags (stdoutput, now_seg)
  5343. & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
  5344. != (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
  5345. return;
  5346. if (call_info->start_symbol == NULL)
  5347. /* This can happen if there were errors earlier on in the assembly. */
  5348. return;
  5349. /* Replace the start symbol with a local symbol that will be reduced
  5350. to a section offset. This avoids problems with weak functions with
  5351. multiple definitions, etc. */
  5352. name = xmalloc (strlen ("L$\001start_")
  5353. + strlen (S_GET_NAME (call_info->start_symbol))
  5354. + 1);
  5355. strcpy (name, "L$\001start_");
  5356. strcat (name, S_GET_NAME (call_info->start_symbol));
  5357. /* If we have a .procend preceded by a .exit, then the symbol will have
  5358. already been defined. In that case, we don't want another unwind
  5359. entry. */
  5360. symbolP = symbol_find (name);
  5361. if (symbolP)
  5362. {
  5363. xfree (name);
  5364. return;
  5365. }
  5366. else
  5367. {
  5368. symbolP = symbol_new (name, now_seg,
  5369. S_GET_VALUE (call_info->start_symbol), frag_now);
  5370. gas_assert (symbolP);
  5371. S_CLEAR_EXTERNAL (symbolP);
  5372. symbol_table_insert (symbolP);
  5373. }
  5374. reloc = R_PARISC_SEGREL32;
  5375. save_seg = now_seg;
  5376. save_subseg = now_subseg;
  5377. /* Get into the right seg/subseg. This may involve creating
  5378. the seg the first time through. Make sure to have the
  5379. old seg/subseg so that we can reset things when we are done. */
  5380. seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
  5381. if (seg == ASEC_NULL)
  5382. {
  5383. seg = subseg_new (UNWIND_SECTION_NAME, 0);
  5384. bfd_set_section_flags (stdoutput, seg,
  5385. SEC_READONLY | SEC_HAS_CONTENTS
  5386. | SEC_LOAD | SEC_RELOC | SEC_ALLOC | SEC_DATA);
  5387. bfd_set_section_alignment (stdoutput, seg, 2);
  5388. }
  5389. subseg_set (seg, 0);
  5390. /* Get some space to hold relocation information for the unwind
  5391. descriptor. */
  5392. p = frag_more (16);
  5393. /* Relocation info. for start offset of the function. */
  5394. md_number_to_chars (p, 0, 4);
  5395. fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
  5396. symbolP, (offsetT) 0,
  5397. (expressionS *) NULL, 0, reloc,
  5398. e_fsel, 32, 0, 0);
  5399. /* Relocation info. for end offset of the function.
  5400. Because we allow reductions of 32bit relocations for ELF, this will be
  5401. reduced to section_sym + offset which avoids putting the temporary
  5402. symbol into the symbol table. It (should) end up giving the same
  5403. value as call_info->start_symbol + function size once the linker is
  5404. finished with its work. */
  5405. md_number_to_chars (p + 4, 0, 4);
  5406. fix_new_hppa (frag_now, p + 4 - frag_now->fr_literal, 4,
  5407. call_info->end_symbol, (offsetT) 0,
  5408. (expressionS *) NULL, 0, reloc,
  5409. e_fsel, 32, 0, 0);
  5410. /* Dump the descriptor. */
  5411. unwind = UNWIND_LOW32 (&call_info->ci_unwind.descriptor);
  5412. md_number_to_chars (p + 8, unwind, 4);
  5413. unwind = UNWIND_HIGH32 (&call_info->ci_unwind.descriptor);
  5414. md_number_to_chars (p + 12, unwind, 4);
  5415. /* Return back to the original segment/subsegment. */
  5416. subseg_set (save_seg, save_subseg);
  5417. }
  5418. #endif
  5419. /* Process a .CALLINFO pseudo-op. This information is used later
  5420. to build unwind descriptors and maybe one day to support
  5421. .ENTER and .LEAVE. */
  5422. static void
  5423. pa_callinfo (int unused ATTRIBUTE_UNUSED)
  5424. {
  5425. char *name, c, *p;
  5426. int temp;
  5427. #ifdef OBJ_SOM
  5428. /* We must have a valid space and subspace. */
  5429. pa_check_current_space_and_subspace ();
  5430. #endif
  5431. /* .CALLINFO must appear within a procedure definition. */
  5432. if (!within_procedure)
  5433. as_bad (_(".callinfo is not within a procedure definition"));
  5434. /* Mark the fact that we found the .CALLINFO for the
  5435. current procedure. */
  5436. callinfo_found = TRUE;
  5437. /* Iterate over the .CALLINFO arguments. */
  5438. while (!is_end_of_statement ())
  5439. {
  5440. name = input_line_pointer;
  5441. c = get_symbol_end ();
  5442. /* Frame size specification. */
  5443. if ((strncasecmp (name, "frame", 5) == 0))
  5444. {
  5445. p = input_line_pointer;
  5446. *p = c;
  5447. input_line_pointer++;
  5448. temp = get_absolute_expression ();
  5449. if ((temp & 0x3) != 0)
  5450. {
  5451. as_bad (_("FRAME parameter must be a multiple of 8: %d\n"), temp);
  5452. temp = 0;
  5453. }
  5454. /* callinfo is in bytes and unwind_desc is in 8 byte units. */
  5455. last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
  5456. }
  5457. /* Entry register (GR, GR and SR) specifications. */
  5458. else if ((strncasecmp (name, "entry_gr", 8) == 0))
  5459. {
  5460. p = input_line_pointer;
  5461. *p = c;
  5462. input_line_pointer++;
  5463. temp = get_absolute_expression ();
  5464. /* The HP assembler accepts 19 as the high bound for ENTRY_GR
  5465. even though %r19 is caller saved. I think this is a bug in
  5466. the HP assembler, and we are not going to emulate it. */
  5467. if (temp < 3 || temp > 18)
  5468. as_bad (_("Value for ENTRY_GR must be in the range 3..18\n"));
  5469. last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
  5470. }
  5471. else if ((strncasecmp (name, "entry_fr", 8) == 0))
  5472. {
  5473. p = input_line_pointer;
  5474. *p = c;
  5475. input_line_pointer++;
  5476. temp = get_absolute_expression ();
  5477. /* Similarly the HP assembler takes 31 as the high bound even
  5478. though %fr21 is the last callee saved floating point register. */
  5479. if (temp < 12 || temp > 21)
  5480. as_bad (_("Value for ENTRY_FR must be in the range 12..21\n"));
  5481. last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
  5482. }
  5483. else if ((strncasecmp (name, "entry_sr", 8) == 0))
  5484. {
  5485. p = input_line_pointer;
  5486. *p = c;
  5487. input_line_pointer++;
  5488. temp = get_absolute_expression ();
  5489. if (temp != 3)
  5490. as_bad (_("Value for ENTRY_SR must be 3\n"));
  5491. }
  5492. /* Note whether or not this function performs any calls. */
  5493. else if ((strncasecmp (name, "calls", 5) == 0) ||
  5494. (strncasecmp (name, "caller", 6) == 0))
  5495. {
  5496. p = input_line_pointer;
  5497. *p = c;
  5498. }
  5499. else if ((strncasecmp (name, "no_calls", 8) == 0))
  5500. {
  5501. p = input_line_pointer;
  5502. *p = c;
  5503. }
  5504. /* Should RP be saved into the stack. */
  5505. else if ((strncasecmp (name, "save_rp", 7) == 0))
  5506. {
  5507. p = input_line_pointer;
  5508. *p = c;
  5509. last_call_info->ci_unwind.descriptor.save_rp = 1;
  5510. }
  5511. /* Likewise for SP. */
  5512. else if ((strncasecmp (name, "save_sp", 7) == 0))
  5513. {
  5514. p = input_line_pointer;
  5515. *p = c;
  5516. last_call_info->ci_unwind.descriptor.save_sp = 1;
  5517. }
  5518. /* Is this an unwindable procedure. If so mark it so
  5519. in the unwind descriptor. */
  5520. else if ((strncasecmp (name, "no_unwind", 9) == 0))
  5521. {
  5522. p = input_line_pointer;
  5523. *p = c;
  5524. last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
  5525. }
  5526. /* Is this an interrupt routine. If so mark it in the
  5527. unwind descriptor. */
  5528. else if ((strncasecmp (name, "hpux_int", 7) == 0))
  5529. {
  5530. p = input_line_pointer;
  5531. *p = c;
  5532. last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
  5533. }
  5534. /* Is this a millicode routine. "millicode" isn't in my
  5535. assembler manual, but my copy is old. The HP assembler
  5536. accepts it, and there's a place in the unwind descriptor
  5537. to drop the information, so we'll accept it too. */
  5538. else if ((strncasecmp (name, "millicode", 9) == 0))
  5539. {
  5540. p = input_line_pointer;
  5541. *p = c;
  5542. last_call_info->ci_unwind.descriptor.millicode = 1;
  5543. }
  5544. else
  5545. {
  5546. as_bad (_("Invalid .CALLINFO argument: %s"), name);
  5547. *input_line_pointer = c;
  5548. }
  5549. if (!is_end_of_statement ())
  5550. input_line_pointer++;
  5551. }
  5552. demand_empty_rest_of_line ();
  5553. }
  5554. #if !(defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD)))
  5555. /* Switch to the text space. Like s_text, but delete our
  5556. label when finished. */
  5557. static void
  5558. pa_text (int unused ATTRIBUTE_UNUSED)
  5559. {
  5560. #ifdef OBJ_SOM
  5561. current_space = is_defined_space ("$TEXT$");
  5562. current_subspace
  5563. = pa_subsegment_to_subspace (current_space->sd_seg, 0);
  5564. #endif
  5565. s_text (0);
  5566. pa_undefine_label ();
  5567. }
  5568. /* Switch to the data space. As usual delete our label. */
  5569. static void
  5570. pa_data (int unused ATTRIBUTE_UNUSED)
  5571. {
  5572. #ifdef OBJ_SOM
  5573. current_space = is_defined_space ("$PRIVATE$");
  5574. current_subspace
  5575. = pa_subsegment_to_subspace (current_space->sd_seg, 0);
  5576. #endif
  5577. s_data (0);
  5578. pa_undefine_label ();
  5579. }
  5580. /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
  5581. the .comm pseudo-op has the following syntax:
  5582. <label> .comm <length>
  5583. where <label> is optional and is a symbol whose address will be the start of
  5584. a block of memory <length> bytes long. <length> must be an absolute
  5585. expression. <length> bytes will be allocated in the current space
  5586. and subspace.
  5587. Also note the label may not even be on the same line as the .comm.
  5588. This difference in syntax means the colon function will be called
  5589. on the symbol before we arrive in pa_comm. colon will set a number
  5590. of attributes of the symbol that need to be fixed here. In particular
  5591. the value, section pointer, fragment pointer, flags, etc. What
  5592. a pain.
  5593. This also makes error detection all but impossible. */
  5594. static void
  5595. pa_comm (int unused ATTRIBUTE_UNUSED)
  5596. {
  5597. unsigned int size;
  5598. symbolS *symbol;
  5599. label_symbol_struct *label_symbol = pa_get_label ();
  5600. if (label_symbol)
  5601. symbol = label_symbol->lss_label;
  5602. else
  5603. symbol = NULL;
  5604. SKIP_WHITESPACE ();
  5605. size = get_absolute_expression ();
  5606. if (symbol)
  5607. {
  5608. symbol_get_bfdsym (symbol)->flags |= BSF_OBJECT;
  5609. S_SET_VALUE (symbol, size);
  5610. S_SET_SEGMENT (symbol, bfd_com_section_ptr);
  5611. S_SET_EXTERNAL (symbol);
  5612. /* colon() has already set the frag to the current location in the
  5613. current subspace; we need to reset the fragment to the zero address
  5614. fragment. We also need to reset the segment pointer. */
  5615. symbol_set_frag (symbol, &zero_address_frag);
  5616. }
  5617. demand_empty_rest_of_line ();
  5618. }
  5619. #endif /* !(defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD))) */
  5620. /* Process a .END pseudo-op. */
  5621. static void
  5622. pa_end (int unused ATTRIBUTE_UNUSED)
  5623. {
  5624. demand_empty_rest_of_line ();
  5625. }
  5626. /* Process a .ENTER pseudo-op. This is not supported. */
  5627. static void
  5628. pa_enter (int unused ATTRIBUTE_UNUSED)
  5629. {
  5630. #ifdef OBJ_SOM
  5631. /* We must have a valid space and subspace. */
  5632. pa_check_current_space_and_subspace ();
  5633. #endif
  5634. as_bad (_("The .ENTER pseudo-op is not supported"));
  5635. demand_empty_rest_of_line ();
  5636. }
  5637. /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
  5638. procedure. */
  5639. static void
  5640. pa_entry (int unused ATTRIBUTE_UNUSED)
  5641. {
  5642. #ifdef OBJ_SOM
  5643. /* We must have a valid space and subspace. */
  5644. pa_check_current_space_and_subspace ();
  5645. #endif
  5646. if (!within_procedure)
  5647. as_bad (_("Misplaced .entry. Ignored."));
  5648. else
  5649. {
  5650. if (!callinfo_found)
  5651. as_bad (_("Missing .callinfo."));
  5652. }
  5653. demand_empty_rest_of_line ();
  5654. within_entry_exit = TRUE;
  5655. #ifdef OBJ_SOM
  5656. /* SOM defers building of unwind descriptors until the link phase.
  5657. The assembler is responsible for creating an R_ENTRY relocation
  5658. to mark the beginning of a region and hold the unwind bits, and
  5659. for creating an R_EXIT relocation to mark the end of the region.
  5660. FIXME. ELF should be using the same conventions! The problem
  5661. is an unwind requires too much relocation space. Hmmm. Maybe
  5662. if we split the unwind bits up between the relocations which
  5663. denote the entry and exit points. */
  5664. if (last_call_info->start_symbol != NULL)
  5665. {
  5666. char *where;
  5667. unsigned int u;
  5668. where = frag_more (0);
  5669. u = UNWIND_LOW32 (&last_call_info->ci_unwind.descriptor);
  5670. fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  5671. NULL, (offsetT) 0, NULL,
  5672. 0, R_HPPA_ENTRY, e_fsel, 0, 0, u);
  5673. }
  5674. #endif
  5675. }
  5676. /* Silly nonsense for pa_equ. The only half-sensible use for this is
  5677. being able to subtract two register symbols that specify a range of
  5678. registers, to get the size of the range. */
  5679. static int fudge_reg_expressions;
  5680. int
  5681. hppa_force_reg_syms_absolute (expressionS *resultP,
  5682. operatorT op ATTRIBUTE_UNUSED,
  5683. expressionS *rightP)
  5684. {
  5685. if (fudge_reg_expressions
  5686. && rightP->X_op == O_register
  5687. && resultP->X_op == O_register)
  5688. {
  5689. rightP->X_op = O_constant;
  5690. resultP->X_op = O_constant;
  5691. }
  5692. return 0; /* Continue normal expr handling. */
  5693. }
  5694. /* Handle a .EQU pseudo-op. */
  5695. static void
  5696. pa_equ (int reg)
  5697. {
  5698. label_symbol_struct *label_symbol = pa_get_label ();
  5699. symbolS *symbol;
  5700. if (label_symbol)
  5701. {
  5702. symbol = label_symbol->lss_label;
  5703. if (reg)
  5704. {
  5705. strict = 1;
  5706. if (!pa_parse_number (&input_line_pointer, 0))
  5707. as_bad (_(".REG expression must be a register"));
  5708. S_SET_VALUE (symbol, pa_number);
  5709. S_SET_SEGMENT (symbol, reg_section);
  5710. }
  5711. else
  5712. {
  5713. expressionS exp;
  5714. segT seg;
  5715. fudge_reg_expressions = 1;
  5716. seg = expression (&exp);
  5717. fudge_reg_expressions = 0;
  5718. if (exp.X_op != O_constant
  5719. && exp.X_op != O_register)
  5720. {
  5721. if (exp.X_op != O_absent)
  5722. as_bad (_("bad or irreducible absolute expression; zero assumed"));
  5723. exp.X_add_number = 0;
  5724. seg = absolute_section;
  5725. }
  5726. S_SET_VALUE (symbol, (unsigned int) exp.X_add_number);
  5727. S_SET_SEGMENT (symbol, seg);
  5728. }
  5729. }
  5730. else
  5731. {
  5732. if (reg)
  5733. as_bad (_(".REG must use a label"));
  5734. else
  5735. as_bad (_(".EQU must use a label"));
  5736. }
  5737. pa_undefine_label ();
  5738. demand_empty_rest_of_line ();
  5739. }
  5740. #ifdef OBJ_ELF
  5741. /* Mark the end of a function so that it's possible to compute
  5742. the size of the function in elf_hppa_final_processing. */
  5743. static void
  5744. hppa_elf_mark_end_of_function (void)
  5745. {
  5746. /* ELF does not have EXIT relocations. All we do is create a
  5747. temporary symbol marking the end of the function. */
  5748. char *name;
  5749. if (last_call_info == NULL || last_call_info->start_symbol == NULL)
  5750. {
  5751. /* We have already warned about a missing label,
  5752. or other problems. */
  5753. return;
  5754. }
  5755. name = xmalloc (strlen ("L$\001end_")
  5756. + strlen (S_GET_NAME (last_call_info->start_symbol))
  5757. + 1);
  5758. if (name)
  5759. {
  5760. symbolS *symbolP;
  5761. strcpy (name, "L$\001end_");
  5762. strcat (name, S_GET_NAME (last_call_info->start_symbol));
  5763. /* If we have a .exit followed by a .procend, then the
  5764. symbol will have already been defined. */
  5765. symbolP = symbol_find (name);
  5766. if (symbolP)
  5767. {
  5768. /* The symbol has already been defined! This can
  5769. happen if we have a .exit followed by a .procend.
  5770. This is *not* an error. All we want to do is free
  5771. the memory we just allocated for the name and continue. */
  5772. xfree (name);
  5773. }
  5774. else
  5775. {
  5776. /* symbol value should be the offset of the
  5777. last instruction of the function */
  5778. symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
  5779. frag_now);
  5780. gas_assert (symbolP);
  5781. S_CLEAR_EXTERNAL (symbolP);
  5782. symbol_table_insert (symbolP);
  5783. }
  5784. if (symbolP)
  5785. last_call_info->end_symbol = symbolP;
  5786. else
  5787. as_bad (_("Symbol '%s' could not be created."), name);
  5788. }
  5789. else
  5790. as_bad (_("No memory for symbol name."));
  5791. }
  5792. #endif
  5793. /* Helper function. Does processing for the end of a function. This
  5794. usually involves creating some relocations or building special
  5795. symbols to mark the end of the function. */
  5796. static void
  5797. process_exit (void)
  5798. {
  5799. char *where;
  5800. where = frag_more (0);
  5801. #ifdef OBJ_ELF
  5802. /* Mark the end of the function, stuff away the location of the frag
  5803. for the end of the function, and finally call pa_build_unwind_subspace
  5804. to add an entry in the unwind table. */
  5805. (void) where;
  5806. hppa_elf_mark_end_of_function ();
  5807. pa_build_unwind_subspace (last_call_info);
  5808. #else
  5809. /* SOM defers building of unwind descriptors until the link phase.
  5810. The assembler is responsible for creating an R_ENTRY relocation
  5811. to mark the beginning of a region and hold the unwind bits, and
  5812. for creating an R_EXIT relocation to mark the end of the region.
  5813. FIXME. ELF should be using the same conventions! The problem
  5814. is an unwind requires too much relocation space. Hmmm. Maybe
  5815. if we split the unwind bits up between the relocations which
  5816. denote the entry and exit points. */
  5817. fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  5818. NULL, (offsetT) 0,
  5819. NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0,
  5820. UNWIND_HIGH32 (&last_call_info->ci_unwind.descriptor));
  5821. #endif
  5822. }
  5823. /* Process a .EXIT pseudo-op. */
  5824. static void
  5825. pa_exit (int unused ATTRIBUTE_UNUSED)
  5826. {
  5827. #ifdef OBJ_SOM
  5828. /* We must have a valid space and subspace. */
  5829. pa_check_current_space_and_subspace ();
  5830. #endif
  5831. if (!within_procedure)
  5832. as_bad (_(".EXIT must appear within a procedure"));
  5833. else
  5834. {
  5835. if (!callinfo_found)
  5836. as_bad (_("Missing .callinfo"));
  5837. else
  5838. {
  5839. if (!within_entry_exit)
  5840. as_bad (_("No .ENTRY for this .EXIT"));
  5841. else
  5842. {
  5843. within_entry_exit = FALSE;
  5844. process_exit ();
  5845. }
  5846. }
  5847. }
  5848. demand_empty_rest_of_line ();
  5849. }
  5850. /* Helper function to process arguments to a .EXPORT pseudo-op. */
  5851. static void
  5852. pa_type_args (symbolS *symbolP, int is_export)
  5853. {
  5854. char *name, c, *p;
  5855. unsigned int temp, arg_reloc;
  5856. pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
  5857. asymbol *bfdsym = symbol_get_bfdsym (symbolP);
  5858. if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
  5859. {
  5860. input_line_pointer += 8;
  5861. bfdsym->flags &= ~BSF_FUNCTION;
  5862. S_SET_SEGMENT (symbolP, bfd_abs_section_ptr);
  5863. type = SYMBOL_TYPE_ABSOLUTE;
  5864. }
  5865. else if (strncasecmp (input_line_pointer, "code", 4) == 0)
  5866. {
  5867. input_line_pointer += 4;
  5868. /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
  5869. instead one should be IMPORTing/EXPORTing ENTRY types.
  5870. Complain if one tries to EXPORT a CODE type since that's never
  5871. done. Both GCC and HP C still try to IMPORT CODE types, so
  5872. silently fix them to be ENTRY types. */
  5873. if (S_IS_FUNCTION (symbolP))
  5874. {
  5875. if (is_export)
  5876. as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"),
  5877. S_GET_NAME (symbolP));
  5878. bfdsym->flags |= BSF_FUNCTION;
  5879. type = SYMBOL_TYPE_ENTRY;
  5880. }
  5881. else
  5882. {
  5883. bfdsym->flags &= ~BSF_FUNCTION;
  5884. type = SYMBOL_TYPE_CODE;
  5885. }
  5886. }
  5887. else if (strncasecmp (input_line_pointer, "data", 4) == 0)
  5888. {
  5889. input_line_pointer += 4;
  5890. bfdsym->flags &= ~BSF_FUNCTION;
  5891. bfdsym->flags |= BSF_OBJECT;
  5892. type = SYMBOL_TYPE_DATA;
  5893. }
  5894. else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
  5895. {
  5896. input_line_pointer += 5;
  5897. bfdsym->flags |= BSF_FUNCTION;
  5898. type = SYMBOL_TYPE_ENTRY;
  5899. }
  5900. else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
  5901. {
  5902. input_line_pointer += 9;
  5903. bfdsym->flags |= BSF_FUNCTION;
  5904. #ifdef OBJ_ELF
  5905. {
  5906. elf_symbol_type *elfsym = (elf_symbol_type *) bfdsym;
  5907. elfsym->internal_elf_sym.st_info =
  5908. ELF_ST_INFO (ELF_ST_BIND (elfsym->internal_elf_sym.st_info),
  5909. STT_PARISC_MILLI);
  5910. }
  5911. #endif
  5912. type = SYMBOL_TYPE_MILLICODE;
  5913. }
  5914. else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
  5915. {
  5916. input_line_pointer += 6;
  5917. bfdsym->flags &= ~BSF_FUNCTION;
  5918. type = SYMBOL_TYPE_PLABEL;
  5919. }
  5920. else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
  5921. {
  5922. input_line_pointer += 8;
  5923. bfdsym->flags |= BSF_FUNCTION;
  5924. type = SYMBOL_TYPE_PRI_PROG;
  5925. }
  5926. else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
  5927. {
  5928. input_line_pointer += 8;
  5929. bfdsym->flags |= BSF_FUNCTION;
  5930. type = SYMBOL_TYPE_SEC_PROG;
  5931. }
  5932. /* SOM requires much more information about symbol types
  5933. than BFD understands. This is how we get this information
  5934. to the SOM BFD backend. */
  5935. #ifdef obj_set_symbol_type
  5936. obj_set_symbol_type (bfdsym, (int) type);
  5937. #else
  5938. (void) type;
  5939. #endif
  5940. /* Now that the type of the exported symbol has been handled,
  5941. handle any argument relocation information. */
  5942. while (!is_end_of_statement ())
  5943. {
  5944. if (*input_line_pointer == ',')
  5945. input_line_pointer++;
  5946. name = input_line_pointer;
  5947. c = get_symbol_end ();
  5948. /* Argument sources. */
  5949. if ((strncasecmp (name, "argw", 4) == 0))
  5950. {
  5951. p = input_line_pointer;
  5952. *p = c;
  5953. input_line_pointer++;
  5954. temp = atoi (name + 4);
  5955. name = input_line_pointer;
  5956. c = get_symbol_end ();
  5957. arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
  5958. #if defined (OBJ_SOM) || defined (ELF_ARG_RELOC)
  5959. symbol_arg_reloc_info (symbolP) |= arg_reloc;
  5960. #else
  5961. (void) arg_reloc;
  5962. #endif
  5963. *input_line_pointer = c;
  5964. }
  5965. /* The return value. */
  5966. else if ((strncasecmp (name, "rtnval", 6)) == 0)
  5967. {
  5968. p = input_line_pointer;
  5969. *p = c;
  5970. input_line_pointer++;
  5971. name = input_line_pointer;
  5972. c = get_symbol_end ();
  5973. arg_reloc = pa_build_arg_reloc (name);
  5974. #if defined (OBJ_SOM) || defined (ELF_ARG_RELOC)
  5975. symbol_arg_reloc_info (symbolP) |= arg_reloc;
  5976. #else
  5977. (void) arg_reloc;
  5978. #endif
  5979. *input_line_pointer = c;
  5980. }
  5981. /* Privilege level. */
  5982. else if ((strncasecmp (name, "priv_lev", 8)) == 0)
  5983. {
  5984. p = input_line_pointer;
  5985. *p = c;
  5986. input_line_pointer++;
  5987. temp = atoi (input_line_pointer);
  5988. #ifdef OBJ_SOM
  5989. ((obj_symbol_type *) bfdsym)->tc_data.ap.hppa_priv_level = temp;
  5990. #endif
  5991. c = get_symbol_end ();
  5992. *input_line_pointer = c;
  5993. }
  5994. else
  5995. {
  5996. as_bad (_("Undefined .EXPORT/.IMPORT argument (ignored): %s"), name);
  5997. p = input_line_pointer;
  5998. *p = c;
  5999. }
  6000. if (!is_end_of_statement ())
  6001. input_line_pointer++;
  6002. }
  6003. }
  6004. /* Process a .EXPORT directive. This makes functions external
  6005. and provides information such as argument relocation entries
  6006. to callers. */
  6007. static void
  6008. pa_export (int unused ATTRIBUTE_UNUSED)
  6009. {
  6010. char *name, c, *p;
  6011. symbolS *symbol;
  6012. name = input_line_pointer;
  6013. c = get_symbol_end ();
  6014. /* Make sure the given symbol exists. */
  6015. if ((symbol = symbol_find_or_make (name)) == NULL)
  6016. {
  6017. as_bad (_("Cannot define export symbol: %s\n"), name);
  6018. p = input_line_pointer;
  6019. *p = c;
  6020. input_line_pointer++;
  6021. }
  6022. else
  6023. {
  6024. /* OK. Set the external bits and process argument relocations.
  6025. For the HP, weak and global are not mutually exclusive.
  6026. S_SET_EXTERNAL will not set BSF_GLOBAL if WEAK is set.
  6027. Call S_SET_EXTERNAL to get the other processing. Manually
  6028. set BSF_GLOBAL when we get back. */
  6029. S_SET_EXTERNAL (symbol);
  6030. symbol_get_bfdsym (symbol)->flags |= BSF_GLOBAL;
  6031. p = input_line_pointer;
  6032. *p = c;
  6033. if (!is_end_of_statement ())
  6034. {
  6035. input_line_pointer++;
  6036. pa_type_args (symbol, 1);
  6037. }
  6038. }
  6039. demand_empty_rest_of_line ();
  6040. }
  6041. /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
  6042. assembly file must either be defined in the assembly file, or
  6043. explicitly IMPORTED from another. */
  6044. static void
  6045. pa_import (int unused ATTRIBUTE_UNUSED)
  6046. {
  6047. char *name, c, *p;
  6048. symbolS *symbol;
  6049. name = input_line_pointer;
  6050. c = get_symbol_end ();
  6051. symbol = symbol_find (name);
  6052. /* Ugh. We might be importing a symbol defined earlier in the file,
  6053. in which case all the code below will really screw things up
  6054. (set the wrong segment, symbol flags & type, etc). */
  6055. if (symbol == NULL || !S_IS_DEFINED (symbol))
  6056. {
  6057. symbol = symbol_find_or_make (name);
  6058. p = input_line_pointer;
  6059. *p = c;
  6060. if (!is_end_of_statement ())
  6061. {
  6062. input_line_pointer++;
  6063. pa_type_args (symbol, 0);
  6064. }
  6065. else
  6066. {
  6067. /* Sigh. To be compatible with the HP assembler and to help
  6068. poorly written assembly code, we assign a type based on
  6069. the current segment. Note only BSF_FUNCTION really
  6070. matters, we do not need to set the full SYMBOL_TYPE_* info. */
  6071. if (now_seg == text_section)
  6072. symbol_get_bfdsym (symbol)->flags |= BSF_FUNCTION;
  6073. /* If the section is undefined, then the symbol is undefined
  6074. Since this is an import, leave the section undefined. */
  6075. S_SET_SEGMENT (symbol, bfd_und_section_ptr);
  6076. }
  6077. }
  6078. else
  6079. {
  6080. /* The symbol was already defined. Just eat everything up to
  6081. the end of the current statement. */
  6082. while (!is_end_of_statement ())
  6083. input_line_pointer++;
  6084. }
  6085. demand_empty_rest_of_line ();
  6086. }
  6087. /* Handle a .LABEL pseudo-op. */
  6088. static void
  6089. pa_label (int unused ATTRIBUTE_UNUSED)
  6090. {
  6091. char *name, c, *p;
  6092. name = input_line_pointer;
  6093. c = get_symbol_end ();
  6094. if (strlen (name) > 0)
  6095. {
  6096. colon (name);
  6097. p = input_line_pointer;
  6098. *p = c;
  6099. }
  6100. else
  6101. {
  6102. as_warn (_("Missing label name on .LABEL"));
  6103. }
  6104. if (!is_end_of_statement ())
  6105. {
  6106. as_warn (_("extra .LABEL arguments ignored."));
  6107. ignore_rest_of_line ();
  6108. }
  6109. demand_empty_rest_of_line ();
  6110. }
  6111. /* Handle a .LEAVE pseudo-op. This is not supported yet. */
  6112. static void
  6113. pa_leave (int unused ATTRIBUTE_UNUSED)
  6114. {
  6115. #ifdef OBJ_SOM
  6116. /* We must have a valid space and subspace. */
  6117. pa_check_current_space_and_subspace ();
  6118. #endif
  6119. as_bad (_("The .LEAVE pseudo-op is not supported"));
  6120. demand_empty_rest_of_line ();
  6121. }
  6122. /* Handle a .LEVEL pseudo-op. */
  6123. static void
  6124. pa_level (int unused ATTRIBUTE_UNUSED)
  6125. {
  6126. char *level;
  6127. level = input_line_pointer;
  6128. if (strncmp (level, "1.0", 3) == 0)
  6129. {
  6130. input_line_pointer += 3;
  6131. if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
  6132. as_warn (_("could not set architecture and machine"));
  6133. }
  6134. else if (strncmp (level, "1.1", 3) == 0)
  6135. {
  6136. input_line_pointer += 3;
  6137. if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11))
  6138. as_warn (_("could not set architecture and machine"));
  6139. }
  6140. else if (strncmp (level, "2.0w", 4) == 0)
  6141. {
  6142. input_line_pointer += 4;
  6143. if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 25))
  6144. as_warn (_("could not set architecture and machine"));
  6145. }
  6146. else if (strncmp (level, "2.0", 3) == 0)
  6147. {
  6148. input_line_pointer += 3;
  6149. if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 20))
  6150. as_warn (_("could not set architecture and machine"));
  6151. }
  6152. else
  6153. {
  6154. as_bad (_("Unrecognized .LEVEL argument\n"));
  6155. ignore_rest_of_line ();
  6156. }
  6157. demand_empty_rest_of_line ();
  6158. }
  6159. /* Handle a .ORIGIN pseudo-op. */
  6160. static void
  6161. pa_origin (int unused ATTRIBUTE_UNUSED)
  6162. {
  6163. #ifdef OBJ_SOM
  6164. /* We must have a valid space and subspace. */
  6165. pa_check_current_space_and_subspace ();
  6166. #endif
  6167. s_org (0);
  6168. pa_undefine_label ();
  6169. }
  6170. /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
  6171. is for static functions. FIXME. Should share more code with .EXPORT. */
  6172. static void
  6173. pa_param (int unused ATTRIBUTE_UNUSED)
  6174. {
  6175. char *name, c, *p;
  6176. symbolS *symbol;
  6177. name = input_line_pointer;
  6178. c = get_symbol_end ();
  6179. if ((symbol = symbol_find_or_make (name)) == NULL)
  6180. {
  6181. as_bad (_("Cannot define static symbol: %s\n"), name);
  6182. p = input_line_pointer;
  6183. *p = c;
  6184. input_line_pointer++;
  6185. }
  6186. else
  6187. {
  6188. S_CLEAR_EXTERNAL (symbol);
  6189. p = input_line_pointer;
  6190. *p = c;
  6191. if (!is_end_of_statement ())
  6192. {
  6193. input_line_pointer++;
  6194. pa_type_args (symbol, 0);
  6195. }
  6196. }
  6197. demand_empty_rest_of_line ();
  6198. }
  6199. /* Handle a .PROC pseudo-op. It is used to mark the beginning
  6200. of a procedure from a syntactical point of view. */
  6201. static void
  6202. pa_proc (int unused ATTRIBUTE_UNUSED)
  6203. {
  6204. struct call_info *call_info;
  6205. #ifdef OBJ_SOM
  6206. /* We must have a valid space and subspace. */
  6207. pa_check_current_space_and_subspace ();
  6208. #endif
  6209. if (within_procedure)
  6210. as_fatal (_("Nested procedures"));
  6211. /* Reset global variables for new procedure. */
  6212. callinfo_found = FALSE;
  6213. within_procedure = TRUE;
  6214. /* Create another call_info structure. */
  6215. call_info = xmalloc (sizeof (struct call_info));
  6216. if (!call_info)
  6217. as_fatal (_("Cannot allocate unwind descriptor\n"));
  6218. memset (call_info, 0, sizeof (struct call_info));
  6219. call_info->ci_next = NULL;
  6220. if (call_info_root == NULL)
  6221. {
  6222. call_info_root = call_info;
  6223. last_call_info = call_info;
  6224. }
  6225. else
  6226. {
  6227. last_call_info->ci_next = call_info;
  6228. last_call_info = call_info;
  6229. }
  6230. /* set up defaults on call_info structure */
  6231. call_info->ci_unwind.descriptor.cannot_unwind = 0;
  6232. call_info->ci_unwind.descriptor.region_desc = 1;
  6233. call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
  6234. /* If we got a .PROC pseudo-op, we know that the function is defined
  6235. locally. Make sure it gets into the symbol table. */
  6236. {
  6237. label_symbol_struct *label_symbol = pa_get_label ();
  6238. if (label_symbol)
  6239. {
  6240. if (label_symbol->lss_label)
  6241. {
  6242. last_call_info->start_symbol = label_symbol->lss_label;
  6243. symbol_get_bfdsym (label_symbol->lss_label)->flags |= BSF_FUNCTION;
  6244. }
  6245. else
  6246. as_bad (_("Missing function name for .PROC (corrupted label chain)"));
  6247. }
  6248. else
  6249. last_call_info->start_symbol = NULL;
  6250. }
  6251. demand_empty_rest_of_line ();
  6252. }
  6253. /* Process the syntactical end of a procedure. Make sure all the
  6254. appropriate pseudo-ops were found within the procedure. */
  6255. static void
  6256. pa_procend (int unused ATTRIBUTE_UNUSED)
  6257. {
  6258. #ifdef OBJ_SOM
  6259. /* We must have a valid space and subspace. */
  6260. pa_check_current_space_and_subspace ();
  6261. #endif
  6262. /* If we are within a procedure definition, make sure we've
  6263. defined a label for the procedure; handle case where the
  6264. label was defined after the .PROC directive.
  6265. Note there's not need to diddle with the segment or fragment
  6266. for the label symbol in this case. We have already switched
  6267. into the new $CODE$ subspace at this point. */
  6268. if (within_procedure && last_call_info->start_symbol == NULL)
  6269. {
  6270. label_symbol_struct *label_symbol = pa_get_label ();
  6271. if (label_symbol)
  6272. {
  6273. if (label_symbol->lss_label)
  6274. {
  6275. last_call_info->start_symbol = label_symbol->lss_label;
  6276. symbol_get_bfdsym (label_symbol->lss_label)->flags
  6277. |= BSF_FUNCTION;
  6278. #ifdef OBJ_SOM
  6279. /* Also handle allocation of a fixup to hold the unwind
  6280. information when the label appears after the proc/procend. */
  6281. if (within_entry_exit)
  6282. {
  6283. char *where;
  6284. unsigned int u;
  6285. where = frag_more (0);
  6286. u = UNWIND_LOW32 (&last_call_info->ci_unwind.descriptor);
  6287. fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  6288. NULL, (offsetT) 0, NULL,
  6289. 0, R_HPPA_ENTRY, e_fsel, 0, 0, u);
  6290. }
  6291. #endif
  6292. }
  6293. else
  6294. as_bad (_("Missing function name for .PROC (corrupted label chain)"));
  6295. }
  6296. else
  6297. as_bad (_("Missing function name for .PROC"));
  6298. }
  6299. if (!within_procedure)
  6300. as_bad (_("misplaced .procend"));
  6301. if (!callinfo_found)
  6302. as_bad (_("Missing .callinfo for this procedure"));
  6303. if (within_entry_exit)
  6304. as_bad (_("Missing .EXIT for a .ENTRY"));
  6305. #ifdef OBJ_ELF
  6306. /* ELF needs to mark the end of each function so that it can compute
  6307. the size of the function (apparently its needed in the symbol table). */
  6308. hppa_elf_mark_end_of_function ();
  6309. #endif
  6310. within_procedure = FALSE;
  6311. demand_empty_rest_of_line ();
  6312. pa_undefine_label ();
  6313. }
  6314. #ifdef OBJ_SOM
  6315. /* If VALUE is an exact power of two between zero and 2^31, then
  6316. return log2 (VALUE). Else return -1. */
  6317. static int
  6318. exact_log2 (int value)
  6319. {
  6320. int shift = 0;
  6321. while ((1 << shift) != value && shift < 32)
  6322. shift++;
  6323. if (shift >= 32)
  6324. return -1;
  6325. else
  6326. return shift;
  6327. }
  6328. /* Check to make sure we have a valid space and subspace. */
  6329. static void
  6330. pa_check_current_space_and_subspace (void)
  6331. {
  6332. if (current_space == NULL)
  6333. as_fatal (_("Not in a space.\n"));
  6334. if (current_subspace == NULL)
  6335. as_fatal (_("Not in a subspace.\n"));
  6336. }
  6337. /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
  6338. then create a new space entry to hold the information specified
  6339. by the parameters to the .SPACE directive. */
  6340. static sd_chain_struct *
  6341. pa_parse_space_stmt (char *space_name, int create_flag)
  6342. {
  6343. char *name, *ptemp, c;
  6344. char loadable, defined, private, sort;
  6345. int spnum;
  6346. asection *seg = NULL;
  6347. sd_chain_struct *space;
  6348. /* Load default values. */
  6349. spnum = 0;
  6350. sort = 0;
  6351. loadable = TRUE;
  6352. defined = TRUE;
  6353. private = FALSE;
  6354. if (strcmp (space_name, "$TEXT$") == 0)
  6355. {
  6356. seg = pa_def_spaces[0].segment;
  6357. defined = pa_def_spaces[0].defined;
  6358. private = pa_def_spaces[0].private;
  6359. sort = pa_def_spaces[0].sort;
  6360. spnum = pa_def_spaces[0].spnum;
  6361. }
  6362. else if (strcmp (space_name, "$PRIVATE$") == 0)
  6363. {
  6364. seg = pa_def_spaces[1].segment;
  6365. defined = pa_def_spaces[1].defined;
  6366. private = pa_def_spaces[1].private;
  6367. sort = pa_def_spaces[1].sort;
  6368. spnum = pa_def_spaces[1].spnum;
  6369. }
  6370. if (!is_end_of_statement ())
  6371. {
  6372. print_errors = FALSE;
  6373. ptemp = input_line_pointer + 1;
  6374. /* First see if the space was specified as a number rather than
  6375. as a name. According to the PA assembly manual the rest of
  6376. the line should be ignored. */
  6377. strict = 0;
  6378. pa_parse_number (&ptemp, 0);
  6379. if (pa_number >= 0)
  6380. {
  6381. spnum = pa_number;
  6382. input_line_pointer = ptemp;
  6383. }
  6384. else
  6385. {
  6386. while (!is_end_of_statement ())
  6387. {
  6388. input_line_pointer++;
  6389. name = input_line_pointer;
  6390. c = get_symbol_end ();
  6391. if ((strncasecmp (name, "spnum", 5) == 0))
  6392. {
  6393. *input_line_pointer = c;
  6394. input_line_pointer++;
  6395. spnum = get_absolute_expression ();
  6396. }
  6397. else if ((strncasecmp (name, "sort", 4) == 0))
  6398. {
  6399. *input_line_pointer = c;
  6400. input_line_pointer++;
  6401. sort = get_absolute_expression ();
  6402. }
  6403. else if ((strncasecmp (name, "unloadable", 10) == 0))
  6404. {
  6405. *input_line_pointer = c;
  6406. loadable = FALSE;
  6407. }
  6408. else if ((strncasecmp (name, "notdefined", 10) == 0))
  6409. {
  6410. *input_line_pointer = c;
  6411. defined = FALSE;
  6412. }
  6413. else if ((strncasecmp (name, "private", 7) == 0))
  6414. {
  6415. *input_line_pointer = c;
  6416. private = TRUE;
  6417. }
  6418. else
  6419. {
  6420. as_bad (_("Invalid .SPACE argument"));
  6421. *input_line_pointer = c;
  6422. if (!is_end_of_statement ())
  6423. input_line_pointer++;
  6424. }
  6425. }
  6426. }
  6427. print_errors = TRUE;
  6428. }
  6429. if (create_flag && seg == NULL)
  6430. seg = subseg_new (space_name, 0);
  6431. /* If create_flag is nonzero, then create the new space with
  6432. the attributes computed above. Else set the values in
  6433. an already existing space -- this can only happen for
  6434. the first occurrence of a built-in space. */
  6435. if (create_flag)
  6436. space = create_new_space (space_name, spnum, loadable, defined,
  6437. private, sort, seg, 1);
  6438. else
  6439. {
  6440. space = is_defined_space (space_name);
  6441. SPACE_SPNUM (space) = spnum;
  6442. SPACE_DEFINED (space) = defined & 1;
  6443. SPACE_USER_DEFINED (space) = 1;
  6444. }
  6445. #ifdef obj_set_section_attributes
  6446. obj_set_section_attributes (seg, defined, private, sort, spnum);
  6447. #endif
  6448. return space;
  6449. }
  6450. /* Handle a .SPACE pseudo-op; this switches the current space to the
  6451. given space, creating the new space if necessary. */
  6452. static void
  6453. pa_space (int unused ATTRIBUTE_UNUSED)
  6454. {
  6455. char *name, c, *space_name, *save_s;
  6456. sd_chain_struct *sd_chain;
  6457. if (within_procedure)
  6458. {
  6459. as_bad (_("Can\'t change spaces within a procedure definition. Ignored"));
  6460. ignore_rest_of_line ();
  6461. }
  6462. else
  6463. {
  6464. /* Check for some of the predefined spaces. FIXME: most of the code
  6465. below is repeated several times, can we extract the common parts
  6466. and place them into a subroutine or something similar? */
  6467. /* FIXME Is this (and the next IF stmt) really right?
  6468. What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
  6469. if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
  6470. {
  6471. input_line_pointer += 6;
  6472. sd_chain = is_defined_space ("$TEXT$");
  6473. if (sd_chain == NULL)
  6474. sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
  6475. else if (SPACE_USER_DEFINED (sd_chain) == 0)
  6476. sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
  6477. current_space = sd_chain;
  6478. subseg_set (text_section, sd_chain->sd_last_subseg);
  6479. current_subspace
  6480. = pa_subsegment_to_subspace (text_section,
  6481. sd_chain->sd_last_subseg);
  6482. demand_empty_rest_of_line ();
  6483. return;
  6484. }
  6485. if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
  6486. {
  6487. input_line_pointer += 9;
  6488. sd_chain = is_defined_space ("$PRIVATE$");
  6489. if (sd_chain == NULL)
  6490. sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
  6491. else if (SPACE_USER_DEFINED (sd_chain) == 0)
  6492. sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
  6493. current_space = sd_chain;
  6494. subseg_set (data_section, sd_chain->sd_last_subseg);
  6495. current_subspace
  6496. = pa_subsegment_to_subspace (data_section,
  6497. sd_chain->sd_last_subseg);
  6498. demand_empty_rest_of_line ();
  6499. return;
  6500. }
  6501. if (!strncasecmp (input_line_pointer,
  6502. GDB_DEBUG_SPACE_NAME,
  6503. strlen (GDB_DEBUG_SPACE_NAME)))
  6504. {
  6505. input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
  6506. sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
  6507. if (sd_chain == NULL)
  6508. sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
  6509. else if (SPACE_USER_DEFINED (sd_chain) == 0)
  6510. sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
  6511. current_space = sd_chain;
  6512. {
  6513. asection *gdb_section
  6514. = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
  6515. subseg_set (gdb_section, sd_chain->sd_last_subseg);
  6516. current_subspace
  6517. = pa_subsegment_to_subspace (gdb_section,
  6518. sd_chain->sd_last_subseg);
  6519. }
  6520. demand_empty_rest_of_line ();
  6521. return;
  6522. }
  6523. /* It could be a space specified by number. */
  6524. print_errors = 0;
  6525. save_s = input_line_pointer;
  6526. strict = 0;
  6527. pa_parse_number (&input_line_pointer, 0);
  6528. if (pa_number >= 0)
  6529. {
  6530. if ((sd_chain = pa_find_space_by_number (pa_number)))
  6531. {
  6532. current_space = sd_chain;
  6533. subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
  6534. current_subspace
  6535. = pa_subsegment_to_subspace (sd_chain->sd_seg,
  6536. sd_chain->sd_last_subseg);
  6537. demand_empty_rest_of_line ();
  6538. return;
  6539. }
  6540. }
  6541. /* Not a number, attempt to create a new space. */
  6542. print_errors = 1;
  6543. input_line_pointer = save_s;
  6544. name = input_line_pointer;
  6545. c = get_symbol_end ();
  6546. space_name = xmalloc (strlen (name) + 1);
  6547. strcpy (space_name, name);
  6548. *input_line_pointer = c;
  6549. sd_chain = pa_parse_space_stmt (space_name, 1);
  6550. current_space = sd_chain;
  6551. subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
  6552. current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
  6553. sd_chain->sd_last_subseg);
  6554. demand_empty_rest_of_line ();
  6555. }
  6556. }
  6557. /* Switch to a new space. (I think). FIXME. */
  6558. static void
  6559. pa_spnum (int unused ATTRIBUTE_UNUSED)
  6560. {
  6561. char *name;
  6562. char c;
  6563. char *p;
  6564. sd_chain_struct *space;
  6565. name = input_line_pointer;
  6566. c = get_symbol_end ();
  6567. space = is_defined_space (name);
  6568. if (space)
  6569. {
  6570. p = frag_more (4);
  6571. md_number_to_chars (p, SPACE_SPNUM (space), 4);
  6572. }
  6573. else
  6574. as_warn (_("Undefined space: '%s' Assuming space number = 0."), name);
  6575. *input_line_pointer = c;
  6576. demand_empty_rest_of_line ();
  6577. }
  6578. /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
  6579. given subspace, creating the new subspace if necessary.
  6580. FIXME. Should mirror pa_space more closely, in particular how
  6581. they're broken up into subroutines. */
  6582. static void
  6583. pa_subspace (int create_new)
  6584. {
  6585. char *name, *ss_name, c;
  6586. char loadable, code_only, comdat, common, dup_common, zero, sort;
  6587. int i, access_ctr, space_index, alignment, quadrant, applicable, flags;
  6588. sd_chain_struct *space;
  6589. ssd_chain_struct *ssd;
  6590. asection *section;
  6591. if (current_space == NULL)
  6592. as_fatal (_("Must be in a space before changing or declaring subspaces.\n"));
  6593. if (within_procedure)
  6594. {
  6595. as_bad (_("Can\'t change subspaces within a procedure definition. Ignored"));
  6596. ignore_rest_of_line ();
  6597. }
  6598. else
  6599. {
  6600. name = input_line_pointer;
  6601. c = get_symbol_end ();
  6602. ss_name = xmalloc (strlen (name) + 1);
  6603. strcpy (ss_name, name);
  6604. *input_line_pointer = c;
  6605. /* Load default values. */
  6606. sort = 0;
  6607. access_ctr = 0x7f;
  6608. loadable = 1;
  6609. comdat = 0;
  6610. common = 0;
  6611. dup_common = 0;
  6612. code_only = 0;
  6613. zero = 0;
  6614. space_index = ~0;
  6615. alignment = 1;
  6616. quadrant = 0;
  6617. space = current_space;
  6618. if (create_new)
  6619. ssd = NULL;
  6620. else
  6621. ssd = is_defined_subspace (ss_name);
  6622. /* Allow user to override the builtin attributes of subspaces. But
  6623. only allow the attributes to be changed once! */
  6624. if (ssd && SUBSPACE_DEFINED (ssd))
  6625. {
  6626. subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
  6627. current_subspace = ssd;
  6628. if (!is_end_of_statement ())
  6629. as_warn (_("Parameters of an existing subspace can\'t be modified"));
  6630. demand_empty_rest_of_line ();
  6631. return;
  6632. }
  6633. else
  6634. {
  6635. /* A new subspace. Load default values if it matches one of
  6636. the builtin subspaces. */
  6637. i = 0;
  6638. while (pa_def_subspaces[i].name)
  6639. {
  6640. if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
  6641. {
  6642. loadable = pa_def_subspaces[i].loadable;
  6643. comdat = pa_def_subspaces[i].comdat;
  6644. common = pa_def_subspaces[i].common;
  6645. dup_common = pa_def_subspaces[i].dup_common;
  6646. code_only = pa_def_subspaces[i].code_only;
  6647. zero = pa_def_subspaces[i].zero;
  6648. space_index = pa_def_subspaces[i].space_index;
  6649. alignment = pa_def_subspaces[i].alignment;
  6650. quadrant = pa_def_subspaces[i].quadrant;
  6651. access_ctr = pa_def_subspaces[i].access;
  6652. sort = pa_def_subspaces[i].sort;
  6653. break;
  6654. }
  6655. i++;
  6656. }
  6657. }
  6658. /* We should be working with a new subspace now. Fill in
  6659. any information as specified by the user. */
  6660. if (!is_end_of_statement ())
  6661. {
  6662. input_line_pointer++;
  6663. while (!is_end_of_statement ())
  6664. {
  6665. name = input_line_pointer;
  6666. c = get_symbol_end ();
  6667. if ((strncasecmp (name, "quad", 4) == 0))
  6668. {
  6669. *input_line_pointer = c;
  6670. input_line_pointer++;
  6671. quadrant = get_absolute_expression ();
  6672. }
  6673. else if ((strncasecmp (name, "align", 5) == 0))
  6674. {
  6675. *input_line_pointer = c;
  6676. input_line_pointer++;
  6677. alignment = get_absolute_expression ();
  6678. if (exact_log2 (alignment) == -1)
  6679. {
  6680. as_bad (_("Alignment must be a power of 2"));
  6681. alignment = 1;
  6682. }
  6683. }
  6684. else if ((strncasecmp (name, "access", 6) == 0))
  6685. {
  6686. *input_line_pointer = c;
  6687. input_line_pointer++;
  6688. access_ctr = get_absolute_expression ();
  6689. }
  6690. else if ((strncasecmp (name, "sort", 4) == 0))
  6691. {
  6692. *input_line_pointer = c;
  6693. input_line_pointer++;
  6694. sort = get_absolute_expression ();
  6695. }
  6696. else if ((strncasecmp (name, "code_only", 9) == 0))
  6697. {
  6698. *input_line_pointer = c;
  6699. code_only = 1;
  6700. }
  6701. else if ((strncasecmp (name, "unloadable", 10) == 0))
  6702. {
  6703. *input_line_pointer = c;
  6704. loadable = 0;
  6705. }
  6706. else if ((strncasecmp (name, "comdat", 6) == 0))
  6707. {
  6708. *input_line_pointer = c;
  6709. comdat = 1;
  6710. }
  6711. else if ((strncasecmp (name, "common", 6) == 0))
  6712. {
  6713. *input_line_pointer = c;
  6714. common = 1;
  6715. }
  6716. else if ((strncasecmp (name, "dup_comm", 8) == 0))
  6717. {
  6718. *input_line_pointer = c;
  6719. dup_common = 1;
  6720. }
  6721. else if ((strncasecmp (name, "zero", 4) == 0))
  6722. {
  6723. *input_line_pointer = c;
  6724. zero = 1;
  6725. }
  6726. else if ((strncasecmp (name, "first", 5) == 0))
  6727. as_bad (_("FIRST not supported as a .SUBSPACE argument"));
  6728. else
  6729. as_bad (_("Invalid .SUBSPACE argument"));
  6730. if (!is_end_of_statement ())
  6731. input_line_pointer++;
  6732. }
  6733. }
  6734. /* Compute a reasonable set of BFD flags based on the information
  6735. in the .subspace directive. */
  6736. applicable = bfd_applicable_section_flags (stdoutput);
  6737. flags = 0;
  6738. if (loadable)
  6739. flags |= (SEC_ALLOC | SEC_LOAD);
  6740. if (code_only)
  6741. flags |= SEC_CODE;
  6742. /* These flags are used to implement various flavors of initialized
  6743. common. The SOM linker discards duplicate subspaces when they
  6744. have the same "key" symbol name. This support is more like
  6745. GNU linkonce than BFD common. Further, pc-relative relocations
  6746. are converted to section relative relocations in BFD common
  6747. sections. This complicates the handling of relocations in
  6748. common sections containing text and isn't currently supported
  6749. correctly in the SOM BFD backend. */
  6750. if (comdat || common || dup_common)
  6751. flags |= SEC_LINK_ONCE;
  6752. flags |= SEC_RELOC | SEC_HAS_CONTENTS;
  6753. /* This is a zero-filled subspace (eg BSS). */
  6754. if (zero)
  6755. flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
  6756. applicable &= flags;
  6757. /* If this is an existing subspace, then we want to use the
  6758. segment already associated with the subspace.
  6759. FIXME NOW! ELF BFD doesn't appear to be ready to deal with
  6760. lots of sections. It might be a problem in the PA ELF
  6761. code, I do not know yet. For now avoid creating anything
  6762. but the "standard" sections for ELF. */
  6763. if (create_new)
  6764. section = subseg_force_new (ss_name, 0);
  6765. else if (ssd)
  6766. section = ssd->ssd_seg;
  6767. else
  6768. section = subseg_new (ss_name, 0);
  6769. if (zero)
  6770. seg_info (section)->bss = 1;
  6771. /* Now set the flags. */
  6772. bfd_set_section_flags (stdoutput, section, applicable);
  6773. /* Record any alignment request for this section. */
  6774. record_alignment (section, exact_log2 (alignment));
  6775. /* Set the starting offset for this section. */
  6776. bfd_set_section_vma (stdoutput, section,
  6777. pa_subspace_start (space, quadrant));
  6778. /* Now that all the flags are set, update an existing subspace,
  6779. or create a new one. */
  6780. if (ssd)
  6781. current_subspace = update_subspace (space, ss_name, loadable,
  6782. code_only, comdat, common,
  6783. dup_common, sort, zero, access_ctr,
  6784. space_index, alignment, quadrant,
  6785. section);
  6786. else
  6787. current_subspace = create_new_subspace (space, ss_name, loadable,
  6788. code_only, comdat, common,
  6789. dup_common, zero, sort,
  6790. access_ctr, space_index,
  6791. alignment, quadrant, section);
  6792. demand_empty_rest_of_line ();
  6793. current_subspace->ssd_seg = section;
  6794. subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
  6795. }
  6796. SUBSPACE_DEFINED (current_subspace) = 1;
  6797. }
  6798. /* Create default space and subspace dictionaries. */
  6799. static void
  6800. pa_spaces_begin (void)
  6801. {
  6802. int i;
  6803. space_dict_root = NULL;
  6804. space_dict_last = NULL;
  6805. i = 0;
  6806. while (pa_def_spaces[i].name)
  6807. {
  6808. char *name;
  6809. /* Pick the right name to use for the new section. */
  6810. name = pa_def_spaces[i].name;
  6811. pa_def_spaces[i].segment = subseg_new (name, 0);
  6812. create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
  6813. pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
  6814. pa_def_spaces[i].private, pa_def_spaces[i].sort,
  6815. pa_def_spaces[i].segment, 0);
  6816. i++;
  6817. }
  6818. i = 0;
  6819. while (pa_def_subspaces[i].name)
  6820. {
  6821. char *name;
  6822. int applicable, subsegment;
  6823. asection *segment = NULL;
  6824. sd_chain_struct *space;
  6825. /* Pick the right name for the new section and pick the right
  6826. subsegment number. */
  6827. name = pa_def_subspaces[i].name;
  6828. subsegment = 0;
  6829. /* Create the new section. */
  6830. segment = subseg_new (name, subsegment);
  6831. /* For SOM we want to replace the standard .text, .data, and .bss
  6832. sections with our own. We also want to set BFD flags for
  6833. all the built-in subspaces. */
  6834. if (!strcmp (pa_def_subspaces[i].name, "$CODE$"))
  6835. {
  6836. text_section = segment;
  6837. applicable = bfd_applicable_section_flags (stdoutput);
  6838. bfd_set_section_flags (stdoutput, segment,
  6839. applicable & (SEC_ALLOC | SEC_LOAD
  6840. | SEC_RELOC | SEC_CODE
  6841. | SEC_READONLY
  6842. | SEC_HAS_CONTENTS));
  6843. }
  6844. else if (!strcmp (pa_def_subspaces[i].name, "$DATA$"))
  6845. {
  6846. data_section = segment;
  6847. applicable = bfd_applicable_section_flags (stdoutput);
  6848. bfd_set_section_flags (stdoutput, segment,
  6849. applicable & (SEC_ALLOC | SEC_LOAD
  6850. | SEC_RELOC
  6851. | SEC_HAS_CONTENTS));
  6852. }
  6853. else if (!strcmp (pa_def_subspaces[i].name, "$BSS$"))
  6854. {
  6855. bss_section = segment;
  6856. applicable = bfd_applicable_section_flags (stdoutput);
  6857. bfd_set_section_flags (stdoutput, segment,
  6858. applicable & SEC_ALLOC);
  6859. }
  6860. else if (!strcmp (pa_def_subspaces[i].name, "$LIT$"))
  6861. {
  6862. applicable = bfd_applicable_section_flags (stdoutput);
  6863. bfd_set_section_flags (stdoutput, segment,
  6864. applicable & (SEC_ALLOC | SEC_LOAD
  6865. | SEC_RELOC
  6866. | SEC_READONLY
  6867. | SEC_HAS_CONTENTS));
  6868. }
  6869. else if (!strcmp (pa_def_subspaces[i].name, "$MILLICODE$"))
  6870. {
  6871. applicable = bfd_applicable_section_flags (stdoutput);
  6872. bfd_set_section_flags (stdoutput, segment,
  6873. applicable & (SEC_ALLOC | SEC_LOAD
  6874. | SEC_RELOC
  6875. | SEC_READONLY
  6876. | SEC_HAS_CONTENTS));
  6877. }
  6878. else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$"))
  6879. {
  6880. applicable = bfd_applicable_section_flags (stdoutput);
  6881. bfd_set_section_flags (stdoutput, segment,
  6882. applicable & (SEC_ALLOC | SEC_LOAD
  6883. | SEC_RELOC
  6884. | SEC_READONLY
  6885. | SEC_HAS_CONTENTS));
  6886. }
  6887. /* Find the space associated with this subspace. */
  6888. space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
  6889. def_space_index].segment);
  6890. if (space == NULL)
  6891. {
  6892. as_fatal (_("Internal error: Unable to find containing space for %s."),
  6893. pa_def_subspaces[i].name);
  6894. }
  6895. create_new_subspace (space, name,
  6896. pa_def_subspaces[i].loadable,
  6897. pa_def_subspaces[i].code_only,
  6898. pa_def_subspaces[i].comdat,
  6899. pa_def_subspaces[i].common,
  6900. pa_def_subspaces[i].dup_common,
  6901. pa_def_subspaces[i].zero,
  6902. pa_def_subspaces[i].sort,
  6903. pa_def_subspaces[i].access,
  6904. pa_def_subspaces[i].space_index,
  6905. pa_def_subspaces[i].alignment,
  6906. pa_def_subspaces[i].quadrant,
  6907. segment);
  6908. i++;
  6909. }
  6910. }
  6911. /* Create a new space NAME, with the appropriate flags as defined
  6912. by the given parameters. */
  6913. static sd_chain_struct *
  6914. create_new_space (char *name,
  6915. int spnum,
  6916. int loadable ATTRIBUTE_UNUSED,
  6917. int defined,
  6918. int private,
  6919. int sort,
  6920. asection *seg,
  6921. int user_defined)
  6922. {
  6923. sd_chain_struct *chain_entry;
  6924. chain_entry = xmalloc (sizeof (sd_chain_struct));
  6925. if (!chain_entry)
  6926. as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"),
  6927. name);
  6928. SPACE_NAME (chain_entry) = xmalloc (strlen (name) + 1);
  6929. strcpy (SPACE_NAME (chain_entry), name);
  6930. SPACE_DEFINED (chain_entry) = defined;
  6931. SPACE_USER_DEFINED (chain_entry) = user_defined;
  6932. SPACE_SPNUM (chain_entry) = spnum;
  6933. chain_entry->sd_seg = seg;
  6934. chain_entry->sd_last_subseg = -1;
  6935. chain_entry->sd_subspaces = NULL;
  6936. chain_entry->sd_next = NULL;
  6937. /* Find spot for the new space based on its sort key. */
  6938. if (!space_dict_last)
  6939. space_dict_last = chain_entry;
  6940. if (space_dict_root == NULL)
  6941. space_dict_root = chain_entry;
  6942. else
  6943. {
  6944. sd_chain_struct *chain_pointer;
  6945. sd_chain_struct *prev_chain_pointer;
  6946. chain_pointer = space_dict_root;
  6947. prev_chain_pointer = NULL;
  6948. while (chain_pointer)
  6949. {
  6950. prev_chain_pointer = chain_pointer;
  6951. chain_pointer = chain_pointer->sd_next;
  6952. }
  6953. /* At this point we've found the correct place to add the new
  6954. entry. So add it and update the linked lists as appropriate. */
  6955. if (prev_chain_pointer)
  6956. {
  6957. chain_entry->sd_next = chain_pointer;
  6958. prev_chain_pointer->sd_next = chain_entry;
  6959. }
  6960. else
  6961. {
  6962. space_dict_root = chain_entry;
  6963. chain_entry->sd_next = chain_pointer;
  6964. }
  6965. if (chain_entry->sd_next == NULL)
  6966. space_dict_last = chain_entry;
  6967. }
  6968. /* This is here to catch predefined spaces which do not get
  6969. modified by the user's input. Another call is found at
  6970. the bottom of pa_parse_space_stmt to handle cases where
  6971. the user modifies a predefined space. */
  6972. #ifdef obj_set_section_attributes
  6973. obj_set_section_attributes (seg, defined, private, sort, spnum);
  6974. #endif
  6975. return chain_entry;
  6976. }
  6977. /* Create a new subspace NAME, with the appropriate flags as defined
  6978. by the given parameters.
  6979. Add the new subspace to the subspace dictionary chain in numerical
  6980. order as defined by the SORT entries. */
  6981. static ssd_chain_struct *
  6982. create_new_subspace (sd_chain_struct *space,
  6983. char *name,
  6984. int loadable ATTRIBUTE_UNUSED,
  6985. int code_only ATTRIBUTE_UNUSED,
  6986. int comdat,
  6987. int common,
  6988. int dup_common,
  6989. int is_zero ATTRIBUTE_UNUSED,
  6990. int sort,
  6991. int access_ctr,
  6992. int space_index ATTRIBUTE_UNUSED,
  6993. int alignment ATTRIBUTE_UNUSED,
  6994. int quadrant,
  6995. asection *seg)
  6996. {
  6997. ssd_chain_struct *chain_entry;
  6998. chain_entry = xmalloc (sizeof (ssd_chain_struct));
  6999. if (!chain_entry)
  7000. as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name);
  7001. SUBSPACE_NAME (chain_entry) = xmalloc (strlen (name) + 1);
  7002. strcpy (SUBSPACE_NAME (chain_entry), name);
  7003. /* Initialize subspace_defined. When we hit a .subspace directive
  7004. we'll set it to 1 which "locks-in" the subspace attributes. */
  7005. SUBSPACE_DEFINED (chain_entry) = 0;
  7006. chain_entry->ssd_subseg = 0;
  7007. chain_entry->ssd_seg = seg;
  7008. chain_entry->ssd_next = NULL;
  7009. /* Find spot for the new subspace based on its sort key. */
  7010. if (space->sd_subspaces == NULL)
  7011. space->sd_subspaces = chain_entry;
  7012. else
  7013. {
  7014. ssd_chain_struct *chain_pointer;
  7015. ssd_chain_struct *prev_chain_pointer;
  7016. chain_pointer = space->sd_subspaces;
  7017. prev_chain_pointer = NULL;
  7018. while (chain_pointer)
  7019. {
  7020. prev_chain_pointer = chain_pointer;
  7021. chain_pointer = chain_pointer->ssd_next;
  7022. }
  7023. /* Now we have somewhere to put the new entry. Insert it and update
  7024. the links. */
  7025. if (prev_chain_pointer)
  7026. {
  7027. chain_entry->ssd_next = chain_pointer;
  7028. prev_chain_pointer->ssd_next = chain_entry;
  7029. }
  7030. else
  7031. {
  7032. space->sd_subspaces = chain_entry;
  7033. chain_entry->ssd_next = chain_pointer;
  7034. }
  7035. }
  7036. #ifdef obj_set_subsection_attributes
  7037. obj_set_subsection_attributes (seg, space->sd_seg, access_ctr, sort,
  7038. quadrant, comdat, common, dup_common);
  7039. #endif
  7040. return chain_entry;
  7041. }
  7042. /* Update the information for the given subspace based upon the
  7043. various arguments. Return the modified subspace chain entry. */
  7044. static ssd_chain_struct *
  7045. update_subspace (sd_chain_struct *space,
  7046. char *name,
  7047. int loadable ATTRIBUTE_UNUSED,
  7048. int code_only ATTRIBUTE_UNUSED,
  7049. int comdat,
  7050. int common,
  7051. int dup_common,
  7052. int sort,
  7053. int zero ATTRIBUTE_UNUSED,
  7054. int access_ctr,
  7055. int space_index ATTRIBUTE_UNUSED,
  7056. int alignment ATTRIBUTE_UNUSED,
  7057. int quadrant,
  7058. asection *section)
  7059. {
  7060. ssd_chain_struct *chain_entry;
  7061. chain_entry = is_defined_subspace (name);
  7062. #ifdef obj_set_subsection_attributes
  7063. obj_set_subsection_attributes (section, space->sd_seg, access_ctr, sort,
  7064. quadrant, comdat, common, dup_common);
  7065. #endif
  7066. return chain_entry;
  7067. }
  7068. /* Return the space chain entry for the space with the name NAME or
  7069. NULL if no such space exists. */
  7070. static sd_chain_struct *
  7071. is_defined_space (char *name)
  7072. {
  7073. sd_chain_struct *chain_pointer;
  7074. for (chain_pointer = space_dict_root;
  7075. chain_pointer;
  7076. chain_pointer = chain_pointer->sd_next)
  7077. if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
  7078. return chain_pointer;
  7079. /* No mapping from segment to space was found. Return NULL. */
  7080. return NULL;
  7081. }
  7082. /* Find and return the space associated with the given seg. If no mapping
  7083. from the given seg to a space is found, then return NULL.
  7084. Unlike subspaces, the number of spaces is not expected to grow much,
  7085. so a linear exhaustive search is OK here. */
  7086. static sd_chain_struct *
  7087. pa_segment_to_space (asection *seg)
  7088. {
  7089. sd_chain_struct *space_chain;
  7090. /* Walk through each space looking for the correct mapping. */
  7091. for (space_chain = space_dict_root;
  7092. space_chain;
  7093. space_chain = space_chain->sd_next)
  7094. if (space_chain->sd_seg == seg)
  7095. return space_chain;
  7096. /* Mapping was not found. Return NULL. */
  7097. return NULL;
  7098. }
  7099. /* Return the first space chain entry for the subspace with the name
  7100. NAME or NULL if no such subspace exists.
  7101. When there are multiple subspaces with the same name, switching to
  7102. the first (i.e., default) subspace is preferable in most situations.
  7103. For example, it wouldn't be desirable to merge COMDAT data with non
  7104. COMDAT data.
  7105. Uses a linear search through all the spaces and subspaces, this may
  7106. not be appropriate if we ever being placing each function in its
  7107. own subspace. */
  7108. static ssd_chain_struct *
  7109. is_defined_subspace (char *name)
  7110. {
  7111. sd_chain_struct *space_chain;
  7112. ssd_chain_struct *subspace_chain;
  7113. /* Walk through each space. */
  7114. for (space_chain = space_dict_root;
  7115. space_chain;
  7116. space_chain = space_chain->sd_next)
  7117. {
  7118. /* Walk through each subspace looking for a name which matches. */
  7119. for (subspace_chain = space_chain->sd_subspaces;
  7120. subspace_chain;
  7121. subspace_chain = subspace_chain->ssd_next)
  7122. if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
  7123. return subspace_chain;
  7124. }
  7125. /* Subspace wasn't found. Return NULL. */
  7126. return NULL;
  7127. }
  7128. /* Find and return the subspace associated with the given seg. If no
  7129. mapping from the given seg to a subspace is found, then return NULL.
  7130. If we ever put each procedure/function within its own subspace
  7131. (to make life easier on the compiler and linker), then this will have
  7132. to become more efficient. */
  7133. static ssd_chain_struct *
  7134. pa_subsegment_to_subspace (asection *seg, subsegT subseg)
  7135. {
  7136. sd_chain_struct *space_chain;
  7137. ssd_chain_struct *subspace_chain;
  7138. /* Walk through each space. */
  7139. for (space_chain = space_dict_root;
  7140. space_chain;
  7141. space_chain = space_chain->sd_next)
  7142. {
  7143. if (space_chain->sd_seg == seg)
  7144. {
  7145. /* Walk through each subspace within each space looking for
  7146. the correct mapping. */
  7147. for (subspace_chain = space_chain->sd_subspaces;
  7148. subspace_chain;
  7149. subspace_chain = subspace_chain->ssd_next)
  7150. if (subspace_chain->ssd_subseg == (int) subseg)
  7151. return subspace_chain;
  7152. }
  7153. }
  7154. /* No mapping from subsegment to subspace found. Return NULL. */
  7155. return NULL;
  7156. }
  7157. /* Given a number, try and find a space with the name number.
  7158. Return a pointer to a space dictionary chain entry for the space
  7159. that was found or NULL on failure. */
  7160. static sd_chain_struct *
  7161. pa_find_space_by_number (int number)
  7162. {
  7163. sd_chain_struct *space_chain;
  7164. for (space_chain = space_dict_root;
  7165. space_chain;
  7166. space_chain = space_chain->sd_next)
  7167. {
  7168. if (SPACE_SPNUM (space_chain) == (unsigned int) number)
  7169. return space_chain;
  7170. }
  7171. /* No appropriate space found. Return NULL. */
  7172. return NULL;
  7173. }
  7174. /* Return the starting address for the given subspace. If the starting
  7175. address is unknown then return zero. */
  7176. static unsigned int
  7177. pa_subspace_start (sd_chain_struct *space, int quadrant)
  7178. {
  7179. /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
  7180. is not correct for the PA OSF1 port. */
  7181. if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
  7182. return 0x40000000;
  7183. else if (space->sd_seg == data_section && quadrant == 1)
  7184. return 0x40000000;
  7185. else
  7186. return 0;
  7187. return 0;
  7188. }
  7189. #endif
  7190. /* Helper function for pa_stringer. Used to find the end of
  7191. a string. */
  7192. static unsigned int
  7193. pa_stringer_aux (char *s)
  7194. {
  7195. unsigned int c = *s & CHAR_MASK;
  7196. switch (c)
  7197. {
  7198. case '\"':
  7199. c = NOT_A_CHAR;
  7200. break;
  7201. default:
  7202. break;
  7203. }
  7204. return c;
  7205. }
  7206. /* Handle a .STRING type pseudo-op. */
  7207. static void
  7208. pa_stringer (int append_zero)
  7209. {
  7210. char *s, num_buf[4];
  7211. unsigned int c;
  7212. int i;
  7213. /* Preprocess the string to handle PA-specific escape sequences.
  7214. For example, \xDD where DD is a hexadecimal number should be
  7215. changed to \OOO where OOO is an octal number. */
  7216. #ifdef OBJ_SOM
  7217. /* We must have a valid space and subspace. */
  7218. pa_check_current_space_and_subspace ();
  7219. #endif
  7220. /* Skip the opening quote. */
  7221. s = input_line_pointer + 1;
  7222. while (is_a_char (c = pa_stringer_aux (s++)))
  7223. {
  7224. if (c == '\\')
  7225. {
  7226. c = *s;
  7227. switch (c)
  7228. {
  7229. /* Handle \x<num>. */
  7230. case 'x':
  7231. {
  7232. unsigned int number;
  7233. int num_digit;
  7234. char dg;
  7235. char *s_start = s;
  7236. /* Get past the 'x'. */
  7237. s++;
  7238. for (num_digit = 0, number = 0, dg = *s;
  7239. num_digit < 2
  7240. && (ISDIGIT (dg) || (dg >= 'a' && dg <= 'f')
  7241. || (dg >= 'A' && dg <= 'F'));
  7242. num_digit++)
  7243. {
  7244. if (ISDIGIT (dg))
  7245. number = number * 16 + dg - '0';
  7246. else if (dg >= 'a' && dg <= 'f')
  7247. number = number * 16 + dg - 'a' + 10;
  7248. else
  7249. number = number * 16 + dg - 'A' + 10;
  7250. s++;
  7251. dg = *s;
  7252. }
  7253. if (num_digit > 0)
  7254. {
  7255. switch (num_digit)
  7256. {
  7257. case 1:
  7258. sprintf (num_buf, "%02o", number);
  7259. break;
  7260. case 2:
  7261. sprintf (num_buf, "%03o", number);
  7262. break;
  7263. }
  7264. for (i = 0; i <= num_digit; i++)
  7265. s_start[i] = num_buf[i];
  7266. }
  7267. break;
  7268. }
  7269. /* This might be a "\"", skip over the escaped char. */
  7270. default:
  7271. s++;
  7272. break;
  7273. }
  7274. }
  7275. }
  7276. stringer (8 + append_zero);
  7277. pa_undefine_label ();
  7278. }
  7279. /* Handle a .VERSION pseudo-op. */
  7280. static void
  7281. pa_version (int unused ATTRIBUTE_UNUSED)
  7282. {
  7283. obj_version (0);
  7284. pa_undefine_label ();
  7285. }
  7286. #ifdef OBJ_SOM
  7287. /* Handle a .COMPILER pseudo-op. */
  7288. static void
  7289. pa_compiler (int unused ATTRIBUTE_UNUSED)
  7290. {
  7291. obj_som_compiler (0);
  7292. pa_undefine_label ();
  7293. }
  7294. #endif
  7295. /* Handle a .COPYRIGHT pseudo-op. */
  7296. static void
  7297. pa_copyright (int unused ATTRIBUTE_UNUSED)
  7298. {
  7299. obj_copyright (0);
  7300. pa_undefine_label ();
  7301. }
  7302. /* Just like a normal cons, but when finished we have to undefine
  7303. the latest space label. */
  7304. static void
  7305. pa_cons (int nbytes)
  7306. {
  7307. cons (nbytes);
  7308. pa_undefine_label ();
  7309. }
  7310. /* Like float_cons, but we need to undefine our label. */
  7311. static void
  7312. pa_float_cons (int float_type)
  7313. {
  7314. float_cons (float_type);
  7315. pa_undefine_label ();
  7316. }
  7317. /* Like s_fill, but delete our label when finished. */
  7318. static void
  7319. pa_fill (int unused ATTRIBUTE_UNUSED)
  7320. {
  7321. #ifdef OBJ_SOM
  7322. /* We must have a valid space and subspace. */
  7323. pa_check_current_space_and_subspace ();
  7324. #endif
  7325. s_fill (0);
  7326. pa_undefine_label ();
  7327. }
  7328. /* Like lcomm, but delete our label when finished. */
  7329. static void
  7330. pa_lcomm (int needs_align)
  7331. {
  7332. #ifdef OBJ_SOM
  7333. /* We must have a valid space and subspace. */
  7334. pa_check_current_space_and_subspace ();
  7335. #endif
  7336. s_lcomm (needs_align);
  7337. pa_undefine_label ();
  7338. }
  7339. /* Like lsym, but delete our label when finished. */
  7340. static void
  7341. pa_lsym (int unused ATTRIBUTE_UNUSED)
  7342. {
  7343. #ifdef OBJ_SOM
  7344. /* We must have a valid space and subspace. */
  7345. pa_check_current_space_and_subspace ();
  7346. #endif
  7347. s_lsym (0);
  7348. pa_undefine_label ();
  7349. }
  7350. /* This function is called once, at assembler startup time. It should
  7351. set up all the tables, etc. that the MD part of the assembler will need. */
  7352. void
  7353. md_begin (void)
  7354. {
  7355. const char *retval = NULL;
  7356. int lose = 0;
  7357. unsigned int i = 0;
  7358. last_call_info = NULL;
  7359. call_info_root = NULL;
  7360. /* Set the default machine type. */
  7361. if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, DEFAULT_LEVEL))
  7362. as_warn (_("could not set architecture and machine"));
  7363. /* Folding of text and data segments fails miserably on the PA.
  7364. Warn user and disable "-R" option. */
  7365. if (flag_readonly_data_in_text)
  7366. {
  7367. as_warn (_("-R option not supported on this target."));
  7368. flag_readonly_data_in_text = 0;
  7369. }
  7370. #ifdef OBJ_SOM
  7371. pa_spaces_begin ();
  7372. #endif
  7373. op_hash = hash_new ();
  7374. while (i < NUMOPCODES)
  7375. {
  7376. const char *name = pa_opcodes[i].name;
  7377. retval = hash_insert (op_hash, name, (struct pa_opcode *) &pa_opcodes[i]);
  7378. if (retval != NULL && *retval != '\0')
  7379. {
  7380. as_fatal (_("Internal error: can't hash `%s': %s\n"), name, retval);
  7381. lose = 1;
  7382. }
  7383. do
  7384. {
  7385. if ((pa_opcodes[i].match & pa_opcodes[i].mask)
  7386. != pa_opcodes[i].match)
  7387. {
  7388. fprintf (stderr, _("internal error: losing opcode: `%s' \"%s\"\n"),
  7389. pa_opcodes[i].name, pa_opcodes[i].args);
  7390. lose = 1;
  7391. }
  7392. ++i;
  7393. }
  7394. while (i < NUMOPCODES && !strcmp (pa_opcodes[i].name, name));
  7395. }
  7396. if (lose)
  7397. as_fatal (_("Broken assembler. No assembly attempted."));
  7398. #ifdef OBJ_SOM
  7399. /* SOM will change text_section. To make sure we never put
  7400. anything into the old one switch to the new one now. */
  7401. subseg_set (text_section, 0);
  7402. #endif
  7403. #ifdef OBJ_SOM
  7404. dummy_symbol = symbol_find_or_make ("L$dummy");
  7405. S_SET_SEGMENT (dummy_symbol, text_section);
  7406. /* Force the symbol to be converted to a real symbol. */
  7407. symbol_get_bfdsym (dummy_symbol)->flags |= BSF_KEEP;
  7408. #endif
  7409. }
  7410. /* On the PA relocations which involve function symbols must not be
  7411. adjusted. This so that the linker can know when/how to create argument
  7412. relocation stubs for indirect calls and calls to static functions.
  7413. "T" field selectors create DLT relative fixups for accessing
  7414. globals and statics in PIC code; each DLT relative fixup creates
  7415. an entry in the DLT table. The entries contain the address of
  7416. the final target (eg accessing "foo" would create a DLT entry
  7417. with the address of "foo").
  7418. Unfortunately, the HP linker doesn't take into account any addend
  7419. when generating the DLT; so accessing $LIT$+8 puts the address of
  7420. $LIT$ into the DLT rather than the address of $LIT$+8.
  7421. The end result is we can't perform relocation symbol reductions for
  7422. any fixup which creates entries in the DLT (eg they use "T" field
  7423. selectors).
  7424. ??? Reject reductions involving symbols with external scope; such
  7425. reductions make life a living hell for object file editors. */
  7426. int
  7427. hppa_fix_adjustable (fixS *fixp)
  7428. {
  7429. #ifdef OBJ_ELF
  7430. reloc_type code;
  7431. #endif
  7432. struct hppa_fix_struct *hppa_fix;
  7433. hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data;
  7434. #ifdef OBJ_ELF
  7435. /* LR/RR selectors are implicitly used for a number of different relocation
  7436. types. We must ensure that none of these types are adjusted (see below)
  7437. even if they occur with a different selector. */
  7438. code = elf_hppa_reloc_final_type (stdoutput, fixp->fx_r_type,
  7439. hppa_fix->fx_r_format,
  7440. hppa_fix->fx_r_field);
  7441. switch (code)
  7442. {
  7443. /* Relocation types which use e_lrsel. */
  7444. case R_PARISC_DIR21L:
  7445. case R_PARISC_DLTREL21L:
  7446. case R_PARISC_DPREL21L:
  7447. case R_PARISC_PLTOFF21L:
  7448. /* Relocation types which use e_rrsel. */
  7449. case R_PARISC_DIR14R:
  7450. case R_PARISC_DIR14DR:
  7451. case R_PARISC_DIR14WR:
  7452. case R_PARISC_DIR17R:
  7453. case R_PARISC_DLTREL14R:
  7454. case R_PARISC_DLTREL14DR:
  7455. case R_PARISC_DLTREL14WR:
  7456. case R_PARISC_DPREL14R:
  7457. case R_PARISC_DPREL14DR:
  7458. case R_PARISC_DPREL14WR:
  7459. case R_PARISC_PLTOFF14R:
  7460. case R_PARISC_PLTOFF14DR:
  7461. case R_PARISC_PLTOFF14WR:
  7462. /* Other types that we reject for reduction. */
  7463. case R_PARISC_GNU_VTENTRY:
  7464. case R_PARISC_GNU_VTINHERIT:
  7465. return 0;
  7466. default:
  7467. break;
  7468. }
  7469. #endif
  7470. /* Reject reductions of symbols in sym1-sym2 expressions when
  7471. the fixup will occur in a CODE subspace.
  7472. XXX FIXME: Long term we probably want to reject all of these;
  7473. for example reducing in the debug section would lose if we ever
  7474. supported using the optimizing hp linker. */
  7475. if (fixp->fx_addsy
  7476. && fixp->fx_subsy
  7477. && (hppa_fix->segment->flags & SEC_CODE))
  7478. return 0;
  7479. /* We can't adjust any relocs that use LR% and RR% field selectors.
  7480. If a symbol is reduced to a section symbol, the assembler will
  7481. adjust the addend unless the symbol happens to reside right at
  7482. the start of the section. Additionally, the linker has no choice
  7483. but to manipulate the addends when coalescing input sections for
  7484. "ld -r". Since an LR% field selector is defined to round the
  7485. addend, we can't change the addend without risking that a LR% and
  7486. it's corresponding (possible multiple) RR% field will no longer
  7487. sum to the right value.
  7488. eg. Suppose we have
  7489. . ldil LR%foo+0,%r21
  7490. . ldw RR%foo+0(%r21),%r26
  7491. . ldw RR%foo+4(%r21),%r25
  7492. If foo is at address 4092 (decimal) in section `sect', then after
  7493. reducing to the section symbol we get
  7494. . LR%sect+4092 == (L%sect)+0
  7495. . RR%sect+4092 == (R%sect)+4092
  7496. . RR%sect+4096 == (R%sect)-4096
  7497. and the last address loses because rounding the addend to 8k
  7498. multiples takes us up to 8192 with an offset of -4096.
  7499. In cases where the LR% expression is identical to the RR% one we
  7500. will never have a problem, but is so happens that gcc rounds
  7501. addends involved in LR% field selectors to work around a HP
  7502. linker bug. ie. We often have addresses like the last case
  7503. above where the LR% expression is offset from the RR% one. */
  7504. if (hppa_fix->fx_r_field == e_lrsel
  7505. || hppa_fix->fx_r_field == e_rrsel
  7506. || hppa_fix->fx_r_field == e_nlrsel)
  7507. return 0;
  7508. /* Reject reductions of symbols in DLT relative relocs,
  7509. relocations with plabels. */
  7510. if (hppa_fix->fx_r_field == e_tsel
  7511. || hppa_fix->fx_r_field == e_ltsel
  7512. || hppa_fix->fx_r_field == e_rtsel
  7513. || hppa_fix->fx_r_field == e_psel
  7514. || hppa_fix->fx_r_field == e_rpsel
  7515. || hppa_fix->fx_r_field == e_lpsel)
  7516. return 0;
  7517. /* Reject absolute calls (jumps). */
  7518. if (hppa_fix->fx_r_type == R_HPPA_ABS_CALL)
  7519. return 0;
  7520. /* Reject reductions of function symbols. */
  7521. if (fixp->fx_addsy != 0 && S_IS_FUNCTION (fixp->fx_addsy))
  7522. return 0;
  7523. return 1;
  7524. }
  7525. /* Return nonzero if the fixup in FIXP will require a relocation,
  7526. even it if appears that the fixup could be completely handled
  7527. within GAS. */
  7528. int
  7529. hppa_force_relocation (struct fix *fixp)
  7530. {
  7531. struct hppa_fix_struct *hppa_fixp;
  7532. hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
  7533. #ifdef OBJ_SOM
  7534. if (fixp->fx_r_type == (int) R_HPPA_ENTRY
  7535. || fixp->fx_r_type == (int) R_HPPA_EXIT
  7536. || fixp->fx_r_type == (int) R_HPPA_BEGIN_BRTAB
  7537. || fixp->fx_r_type == (int) R_HPPA_END_BRTAB
  7538. || fixp->fx_r_type == (int) R_HPPA_BEGIN_TRY
  7539. || fixp->fx_r_type == (int) R_HPPA_END_TRY
  7540. || (fixp->fx_addsy != NULL && fixp->fx_subsy != NULL
  7541. && (hppa_fixp->segment->flags & SEC_CODE) != 0))
  7542. return 1;
  7543. #endif
  7544. #ifdef OBJ_ELF
  7545. if (fixp->fx_r_type == (int) R_PARISC_GNU_VTINHERIT
  7546. || fixp->fx_r_type == (int) R_PARISC_GNU_VTENTRY)
  7547. return 1;
  7548. #endif
  7549. gas_assert (fixp->fx_addsy != NULL);
  7550. /* Ensure we emit a relocation for global symbols so that dynamic
  7551. linking works. */
  7552. if (S_FORCE_RELOC (fixp->fx_addsy, 1))
  7553. return 1;
  7554. /* It is necessary to force PC-relative calls/jumps to have a relocation
  7555. entry if they're going to need either an argument relocation or long
  7556. call stub. */
  7557. if (fixp->fx_pcrel
  7558. && arg_reloc_stub_needed (symbol_arg_reloc_info (fixp->fx_addsy),
  7559. hppa_fixp->fx_arg_reloc))
  7560. return 1;
  7561. /* Now check to see if we're going to need a long-branch stub. */
  7562. if (fixp->fx_r_type == (int) R_HPPA_PCREL_CALL)
  7563. {
  7564. long pc = md_pcrel_from (fixp);
  7565. valueT distance, min_stub_distance;
  7566. distance = fixp->fx_offset + S_GET_VALUE (fixp->fx_addsy) - pc - 8;
  7567. /* Distance to the closest possible stub. This will detect most
  7568. but not all circumstances where a stub will not work. */
  7569. min_stub_distance = pc + 16;
  7570. #ifdef OBJ_SOM
  7571. if (last_call_info != NULL)
  7572. min_stub_distance -= S_GET_VALUE (last_call_info->start_symbol);
  7573. #endif
  7574. if ((distance + 8388608 >= 16777216
  7575. && min_stub_distance <= 8388608)
  7576. || (hppa_fixp->fx_r_format == 17
  7577. && distance + 262144 >= 524288
  7578. && min_stub_distance <= 262144)
  7579. || (hppa_fixp->fx_r_format == 12
  7580. && distance + 8192 >= 16384
  7581. && min_stub_distance <= 8192)
  7582. )
  7583. return 1;
  7584. }
  7585. if (fixp->fx_r_type == (int) R_HPPA_ABS_CALL)
  7586. return 1;
  7587. /* No need (yet) to force another relocations to be emitted. */
  7588. return 0;
  7589. }
  7590. /* Now for some ELF specific code. FIXME. */
  7591. #ifdef OBJ_ELF
  7592. /* For ELF, this function serves one purpose: to setup the st_size
  7593. field of STT_FUNC symbols. To do this, we need to scan the
  7594. call_info structure list, determining st_size in by taking the
  7595. difference in the address of the beginning/end marker symbols. */
  7596. void
  7597. elf_hppa_final_processing (void)
  7598. {
  7599. struct call_info *call_info_pointer;
  7600. for (call_info_pointer = call_info_root;
  7601. call_info_pointer;
  7602. call_info_pointer = call_info_pointer->ci_next)
  7603. {
  7604. elf_symbol_type *esym
  7605. = ((elf_symbol_type *)
  7606. symbol_get_bfdsym (call_info_pointer->start_symbol));
  7607. esym->internal_elf_sym.st_size =
  7608. S_GET_VALUE (call_info_pointer->end_symbol)
  7609. - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
  7610. }
  7611. }
  7612. static void
  7613. pa_vtable_entry (int ignore ATTRIBUTE_UNUSED)
  7614. {
  7615. struct fix *new_fix;
  7616. new_fix = obj_elf_vtable_entry (0);
  7617. if (new_fix)
  7618. {
  7619. struct hppa_fix_struct * hppa_fix = obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
  7620. hppa_fix->fx_r_type = R_HPPA;
  7621. hppa_fix->fx_r_field = e_fsel;
  7622. hppa_fix->fx_r_format = 32;
  7623. hppa_fix->fx_arg_reloc = 0;
  7624. hppa_fix->segment = now_seg;
  7625. new_fix->tc_fix_data = (void *) hppa_fix;
  7626. new_fix->fx_r_type = (int) R_PARISC_GNU_VTENTRY;
  7627. }
  7628. }
  7629. static void
  7630. pa_vtable_inherit (int ignore ATTRIBUTE_UNUSED)
  7631. {
  7632. struct fix *new_fix;
  7633. new_fix = obj_elf_vtable_inherit (0);
  7634. if (new_fix)
  7635. {
  7636. struct hppa_fix_struct * hppa_fix = obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
  7637. hppa_fix->fx_r_type = R_HPPA;
  7638. hppa_fix->fx_r_field = e_fsel;
  7639. hppa_fix->fx_r_format = 32;
  7640. hppa_fix->fx_arg_reloc = 0;
  7641. hppa_fix->segment = now_seg;
  7642. new_fix->tc_fix_data = (void *) hppa_fix;
  7643. new_fix->fx_r_type = (int) R_PARISC_GNU_VTINHERIT;
  7644. }
  7645. }
  7646. #endif
  7647. /* Table of pseudo ops for the PA. FIXME -- how many of these
  7648. are now redundant with the overall GAS and the object file
  7649. dependent tables? */
  7650. const pseudo_typeS md_pseudo_table[] =
  7651. {
  7652. /* align pseudo-ops on the PA specify the actual alignment requested,
  7653. not the log2 of the requested alignment. */
  7654. #ifdef OBJ_SOM
  7655. {"align", pa_align, 8},
  7656. #endif
  7657. #ifdef OBJ_ELF
  7658. {"align", s_align_bytes, 8},
  7659. #endif
  7660. {"begin_brtab", pa_brtab, 1},
  7661. {"begin_try", pa_try, 1},
  7662. {"block", pa_block, 1},
  7663. {"blockz", pa_block, 0},
  7664. {"byte", pa_cons, 1},
  7665. {"call", pa_call, 0},
  7666. {"callinfo", pa_callinfo, 0},
  7667. #if defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD))
  7668. {"code", obj_elf_text, 0},
  7669. #else
  7670. {"code", pa_text, 0},
  7671. {"comm", pa_comm, 0},
  7672. #endif
  7673. #ifdef OBJ_SOM
  7674. {"compiler", pa_compiler, 0},
  7675. #endif
  7676. {"copyright", pa_copyright, 0},
  7677. #if !(defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD)))
  7678. {"data", pa_data, 0},
  7679. #endif
  7680. {"double", pa_float_cons, 'd'},
  7681. {"dword", pa_cons, 8},
  7682. {"end", pa_end, 0},
  7683. {"end_brtab", pa_brtab, 0},
  7684. #if !(defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD)))
  7685. {"end_try", pa_try, 0},
  7686. #endif
  7687. {"enter", pa_enter, 0},
  7688. {"entry", pa_entry, 0},
  7689. {"equ", pa_equ, 0},
  7690. {"exit", pa_exit, 0},
  7691. {"export", pa_export, 0},
  7692. {"fill", pa_fill, 0},
  7693. {"float", pa_float_cons, 'f'},
  7694. {"half", pa_cons, 2},
  7695. {"import", pa_import, 0},
  7696. {"int", pa_cons, 4},
  7697. {"label", pa_label, 0},
  7698. {"lcomm", pa_lcomm, 0},
  7699. {"leave", pa_leave, 0},
  7700. {"level", pa_level, 0},
  7701. {"long", pa_cons, 4},
  7702. {"lsym", pa_lsym, 0},
  7703. #ifdef OBJ_SOM
  7704. {"nsubspa", pa_subspace, 1},
  7705. #endif
  7706. {"octa", pa_cons, 16},
  7707. {"org", pa_origin, 0},
  7708. {"origin", pa_origin, 0},
  7709. {"param", pa_param, 0},
  7710. {"proc", pa_proc, 0},
  7711. {"procend", pa_procend, 0},
  7712. {"quad", pa_cons, 8},
  7713. {"reg", pa_equ, 1},
  7714. {"short", pa_cons, 2},
  7715. {"single", pa_float_cons, 'f'},
  7716. #ifdef OBJ_SOM
  7717. {"space", pa_space, 0},
  7718. {"spnum", pa_spnum, 0},
  7719. #endif
  7720. {"string", pa_stringer, 0},
  7721. {"stringz", pa_stringer, 1},
  7722. #ifdef OBJ_SOM
  7723. {"subspa", pa_subspace, 0},
  7724. #endif
  7725. #if !(defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD)))
  7726. {"text", pa_text, 0},
  7727. #endif
  7728. {"version", pa_version, 0},
  7729. #ifdef OBJ_ELF
  7730. {"vtable_entry", pa_vtable_entry, 0},
  7731. {"vtable_inherit", pa_vtable_inherit, 0},
  7732. #endif
  7733. {"word", pa_cons, 4},
  7734. {NULL, 0, 0}
  7735. };
  7736. #ifdef OBJ_ELF
  7737. void
  7738. hppa_cfi_frame_initial_instructions (void)
  7739. {
  7740. cfi_add_CFA_def_cfa (30, 0);
  7741. }
  7742. int
  7743. hppa_regname_to_dw2regnum (char *regname)
  7744. {
  7745. unsigned int regnum = -1;
  7746. unsigned int i;
  7747. const char *p;
  7748. char *q;
  7749. static struct { char *name; int dw2regnum; } regnames[] =
  7750. {
  7751. { "sp", 30 }, { "rp", 2 },
  7752. };
  7753. for (i = 0; i < ARRAY_SIZE (regnames); ++i)
  7754. if (strcmp (regnames[i].name, regname) == 0)
  7755. return regnames[i].dw2regnum;
  7756. if (regname[0] == 'r')
  7757. {
  7758. p = regname + 1;
  7759. regnum = strtoul (p, &q, 10);
  7760. if (p == q || *q || regnum >= 32)
  7761. return -1;
  7762. }
  7763. else if (regname[0] == 'f' && regname[1] == 'r')
  7764. {
  7765. p = regname + 2;
  7766. regnum = strtoul (p, &q, 10);
  7767. #if TARGET_ARCH_SIZE == 64
  7768. if (p == q || *q || regnum <= 4 || regnum >= 32)
  7769. return -1;
  7770. regnum += 32 - 4;
  7771. #else
  7772. if (p == q
  7773. || (*q && ((*q != 'L' && *q != 'R') || *(q + 1)))
  7774. || regnum <= 4 || regnum >= 32)
  7775. return -1;
  7776. regnum = (regnum - 4) * 2 + 32;
  7777. if (*q == 'R')
  7778. regnum++;
  7779. #endif
  7780. }
  7781. return regnum;
  7782. }
  7783. #endif