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