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