* config/tc-hppa.c (pa_ip): Handle 'l' operand.
[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 ,l completer for new syntax branches. */
2694 case 'l':
2695 if (*s == ',' && strcasecmp (s + 1, "l") == 0)
2696 s += 2;
2697 else
2698 break;
2699 continue;
2700
2701 /* Handle a 11 bit immediate at 31. */
2702 case 'i':
2703 the_insn.field_selector = pa_chk_field_selector (&s);
2704 get_expression (s);
2705 s = expr_end;
2706 if (the_insn.exp.X_op == O_constant)
2707 {
2708 num = evaluate_absolute (&the_insn);
2709 CHECK_FIELD (num, 1023, -1024, 0);
2710 low_sign_unext (num, 11, &num);
2711 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2712 }
2713 else
2714 {
2715 if (is_DP_relative (the_insn.exp))
2716 the_insn.reloc = R_HPPA_GOTOFF;
2717 else if (is_PC_relative (the_insn.exp))
2718 the_insn.reloc = R_HPPA_PCREL_CALL;
2719 else
2720 the_insn.reloc = R_HPPA;
2721 the_insn.format = 11;
2722 continue;
2723 }
2724
2725
2726 /* Handle a 14 bit immediate at 31. */
2727 case 'j':
2728 the_insn.field_selector = pa_chk_field_selector (&s);
2729 get_expression (s);
2730 s = expr_end;
2731 if (the_insn.exp.X_op == O_constant)
2732 {
2733 num = evaluate_absolute (&the_insn);
2734 CHECK_FIELD (num, 8191, -8192, 0);
2735 low_sign_unext (num, 14, &num);
2736 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2737 }
2738 else
2739 {
2740 if (is_DP_relative (the_insn.exp))
2741 the_insn.reloc = R_HPPA_GOTOFF;
2742 else if (is_PC_relative (the_insn.exp))
2743 the_insn.reloc = R_HPPA_PCREL_CALL;
2744 else
2745 the_insn.reloc = R_HPPA;
2746 the_insn.format = 14;
2747 continue;
2748 }
2749
2750 /* Handle a 21 bit immediate at 31. */
2751 case 'k':
2752 the_insn.field_selector = pa_chk_field_selector (&s);
2753 get_expression (s);
2754 s = expr_end;
2755 if (the_insn.exp.X_op == O_constant)
2756 {
2757 num = evaluate_absolute (&the_insn);
2758 CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
2759 dis_assemble_21 (num, &num);
2760 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2761 }
2762 else
2763 {
2764 if (is_DP_relative (the_insn.exp))
2765 the_insn.reloc = R_HPPA_GOTOFF;
2766 else if (is_PC_relative (the_insn.exp))
2767 the_insn.reloc = R_HPPA_PCREL_CALL;
2768 else
2769 the_insn.reloc = R_HPPA;
2770 the_insn.format = 21;
2771 continue;
2772 }
2773
2774 /* Handle a 12 bit branch displacement. */
2775 case 'w':
2776 the_insn.field_selector = pa_chk_field_selector (&s);
2777 get_expression (s);
2778 s = expr_end;
2779 the_insn.pcrel = 1;
2780 if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001"))
2781 {
2782 unsigned int w1, w, result;
2783
2784 num = evaluate_absolute (&the_insn);
2785 if (num % 4)
2786 {
2787 as_bad (_("Branch to unaligned address"));
2788 break;
2789 }
2790 CHECK_FIELD (num, 8199, -8184, 0);
2791 sign_unext ((num - 8) >> 2, 12, &result);
2792 dis_assemble_12 (result, &w1, &w);
2793 INSERT_FIELD_AND_CONTINUE (opcode, ((w1 << 2) | w), 0);
2794 }
2795 else
2796 {
2797 the_insn.reloc = R_HPPA_PCREL_CALL;
2798 the_insn.format = 12;
2799 the_insn.arg_reloc = last_call_desc.arg_reloc;
2800 memset (&last_call_desc, 0, sizeof (struct call_desc));
2801 s = expr_end;
2802 continue;
2803 }
2804
2805 /* Handle a 17 bit branch displacement. */
2806 case 'W':
2807 the_insn.field_selector = pa_chk_field_selector (&s);
2808 get_expression (s);
2809 s = expr_end;
2810 the_insn.pcrel = 1;
2811 if (!the_insn.exp.X_add_symbol
2812 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2813 "L$0\001"))
2814 {
2815 unsigned int w2, w1, w, result;
2816
2817 num = evaluate_absolute (&the_insn);
2818 if (num % 4)
2819 {
2820 as_bad (_("Branch to unaligned address"));
2821 break;
2822 }
2823 CHECK_FIELD (num, 262143, -262144, 0);
2824
2825 if (the_insn.exp.X_add_symbol)
2826 num -= 8;
2827
2828 sign_unext (num >> 2, 17, &result);
2829 dis_assemble_17 (result, &w1, &w2, &w);
2830 INSERT_FIELD_AND_CONTINUE (opcode,
2831 ((w2 << 2) | (w1 << 16) | w), 0);
2832 }
2833 else
2834 {
2835 the_insn.reloc = R_HPPA_PCREL_CALL;
2836 the_insn.format = 17;
2837 the_insn.arg_reloc = last_call_desc.arg_reloc;
2838 memset (&last_call_desc, 0, sizeof (struct call_desc));
2839 continue;
2840 }
2841
2842 /* Handle an absolute 17 bit branch target. */
2843 case 'z':
2844 the_insn.field_selector = pa_chk_field_selector (&s);
2845 get_expression (s);
2846 s = expr_end;
2847 the_insn.pcrel = 0;
2848 if (!the_insn.exp.X_add_symbol
2849 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2850 "L$0\001"))
2851 {
2852 unsigned int w2, w1, w, result;
2853
2854 num = evaluate_absolute (&the_insn);
2855 if (num % 4)
2856 {
2857 as_bad (_("Branch to unaligned address"));
2858 break;
2859 }
2860 CHECK_FIELD (num, 262143, -262144, 0);
2861
2862 if (the_insn.exp.X_add_symbol)
2863 num -= 8;
2864
2865 sign_unext (num >> 2, 17, &result);
2866 dis_assemble_17 (result, &w1, &w2, &w);
2867 INSERT_FIELD_AND_CONTINUE (opcode,
2868 ((w2 << 2) | (w1 << 16) | w), 0);
2869 }
2870 else
2871 {
2872 the_insn.reloc = R_HPPA_ABS_CALL;
2873 the_insn.format = 17;
2874 the_insn.arg_reloc = last_call_desc.arg_reloc;
2875 memset (&last_call_desc, 0, sizeof (struct call_desc));
2876 continue;
2877 }
2878
2879 /* Handle '%r1' implicit operand of addil instruction. */
2880 case 'Z':
2881 if (*s == ',' && *(s + 1) == '%' && *(s + 3) == '1'
2882 && (*(s + 2) == 'r' || *(s + 2) == 'R'))
2883 {
2884 s += 4;
2885 continue;
2886 }
2887 else
2888 break;
2889
2890 /* Handle a 2 bit shift count at 25. */
2891 case '.':
2892 num = pa_get_absolute_expression (&the_insn, &s);
2893 if (strict && the_insn.exp.X_op != O_constant)
2894 break;
2895 s = expr_end;
2896 CHECK_FIELD (num, 3, 1, strict);
2897 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
2898
2899 /* Handle a 4 bit shift count at 25. */
2900 case '*':
2901 num = pa_get_absolute_expression (&the_insn, &s);
2902 if (strict && the_insn.exp.X_op != O_constant)
2903 break;
2904 s = expr_end;
2905 CHECK_FIELD (num, 15, 0, strict);
2906 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
2907
2908 /* Handle a 5 bit shift count at 26. */
2909 case 'p':
2910 num = pa_get_absolute_expression (&the_insn, &s);
2911 if (strict && the_insn.exp.X_op != O_constant)
2912 break;
2913 s = expr_end;
2914 CHECK_FIELD (num, 31, 0, strict);
2915 INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
2916
2917 /* Handle a 6 bit shift count at 20,22:26. */
2918 case '~':
2919 num = pa_get_absolute_expression (&the_insn, &s);
2920 if (strict && the_insn.exp.X_op != O_constant)
2921 break;
2922 s = expr_end;
2923 CHECK_FIELD (num, 63, 0, strict);
2924 num = 63 - num;
2925 opcode |= (num & 0x20) << 6;
2926 INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
2927
2928 /* Handle a 6 bit field length at 23,27:31. */
2929 case '%':
2930 flag = 0;
2931 num = pa_get_absolute_expression (&the_insn, &s);
2932 if (strict && the_insn.exp.X_op != O_constant)
2933 break;
2934 s = expr_end;
2935 CHECK_FIELD (num, 64, 1, strict);
2936 num--;
2937 opcode |= (num & 0x20) << 3;
2938 num = 31 - (num & 0x1f);
2939 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2940
2941 /* Handle a 6 bit field length at 19,27:31. */
2942 case '|':
2943 num = pa_get_absolute_expression (&the_insn, &s);
2944 if (strict && the_insn.exp.X_op != O_constant)
2945 break;
2946 s = expr_end;
2947 CHECK_FIELD (num, 64, 1, strict);
2948 num--;
2949 opcode |= (num & 0x20) << 7;
2950 num = 31 - (num & 0x1f);
2951 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2952
2953 /* Handle a 5 bit bit position at 26. */
2954 case 'P':
2955 num = pa_get_absolute_expression (&the_insn, &s);
2956 if (strict && the_insn.exp.X_op != O_constant)
2957 break;
2958 s = expr_end;
2959 CHECK_FIELD (num, 31, 0, strict);
2960 INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
2961
2962 /* Handle a 6 bit bit position at 20,22:26. */
2963 case 'q':
2964 num = pa_get_absolute_expression (&the_insn, &s);
2965 if (strict && the_insn.exp.X_op != O_constant)
2966 break;
2967 s = expr_end;
2968 CHECK_FIELD (num, 63, 0, strict);
2969 opcode |= (num & 0x20) << 6;
2970 INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
2971
2972 /* Handle a 5 bit immediate at 10. */
2973 case 'Q':
2974 num = pa_get_absolute_expression (&the_insn, &s);
2975 if (strict && the_insn.exp.X_op != O_constant)
2976 break;
2977 if (the_insn.exp.X_op != O_constant)
2978 break;
2979 s = expr_end;
2980 CHECK_FIELD (num, 31, 0, strict);
2981 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
2982
2983 /* Handle a 9 bit immediate at 28. */
2984 case '$':
2985 num = pa_get_absolute_expression (&the_insn, &s);
2986 if (strict && the_insn.exp.X_op != O_constant)
2987 break;
2988 s = expr_end;
2989 CHECK_FIELD (num, 511, 1, strict);
2990 INSERT_FIELD_AND_CONTINUE (opcode, num, 3);
2991
2992 /* Handle a 13 bit immediate at 18. */
2993 case 'A':
2994 num = pa_get_absolute_expression (&the_insn, &s);
2995 if (strict && the_insn.exp.X_op != O_constant)
2996 break;
2997 s = expr_end;
2998 CHECK_FIELD (num, 8191, 0, strict);
2999 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
3000
3001 /* Handle a 26 bit immediate at 31. */
3002 case 'D':
3003 num = pa_get_absolute_expression (&the_insn, &s);
3004 if (strict && the_insn.exp.X_op != O_constant)
3005 break;
3006 s = expr_end;
3007 CHECK_FIELD (num, 671108864, 0, strict);
3008 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3009
3010 /* Handle a 3 bit SFU identifier at 25. */
3011 case 'v':
3012 if (*s++ != ',')
3013 as_bad (_("Invalid SFU identifier"));
3014 num = pa_get_absolute_expression (&the_insn, &s);
3015 if (strict && the_insn.exp.X_op != O_constant)
3016 break;
3017 s = expr_end;
3018 CHECK_FIELD (num, 7, 0, strict);
3019 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
3020
3021 /* Handle a 20 bit SOP field for spop0. */
3022 case 'O':
3023 num = pa_get_absolute_expression (&the_insn, &s);
3024 if (strict && the_insn.exp.X_op != O_constant)
3025 break;
3026 s = expr_end;
3027 CHECK_FIELD (num, 1048575, 0, strict);
3028 num = (num & 0x1f) | ((num & 0x000fffe0) << 6);
3029 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3030
3031 /* Handle a 15bit SOP field for spop1. */
3032 case 'o':
3033 num = pa_get_absolute_expression (&the_insn, &s);
3034 if (strict && the_insn.exp.X_op != O_constant)
3035 break;
3036 s = expr_end;
3037 CHECK_FIELD (num, 32767, 0, strict);
3038 INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
3039
3040 /* Handle a 10bit SOP field for spop3. */
3041 case '0':
3042 num = pa_get_absolute_expression (&the_insn, &s);
3043 if (strict && the_insn.exp.X_op != O_constant)
3044 break;
3045 s = expr_end;
3046 CHECK_FIELD (num, 1023, 0, strict);
3047 num = (num & 0x1f) | ((num & 0x000003e0) << 6);
3048 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3049
3050 /* Handle a 15 bit SOP field for spop2. */
3051 case '1':
3052 num = pa_get_absolute_expression (&the_insn, &s);
3053 if (strict && the_insn.exp.X_op != O_constant)
3054 break;
3055 s = expr_end;
3056 CHECK_FIELD (num, 32767, 0, strict);
3057 num = (num & 0x1f) | ((num & 0x00007fe0) << 6);
3058 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3059
3060 /* Handle a 3-bit co-processor ID field. */
3061 case 'u':
3062 if (*s++ != ',')
3063 as_bad (_("Invalid COPR identifier"));
3064 num = pa_get_absolute_expression (&the_insn, &s);
3065 if (strict && the_insn.exp.X_op != O_constant)
3066 break;
3067 s = expr_end;
3068 CHECK_FIELD (num, 7, 0, strict);
3069 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
3070
3071 /* Handle a 22bit SOP field for copr. */
3072 case '2':
3073 num = pa_get_absolute_expression (&the_insn, &s);
3074 if (strict && the_insn.exp.X_op != O_constant)
3075 break;
3076 s = expr_end;
3077 CHECK_FIELD (num, 4194303, 0, strict);
3078 num = (num & 0x1f) | ((num & 0x003fffe0) << 4);
3079 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3080
3081
3082 /* Handle a source FP operand format completer. */
3083 case 'F':
3084 flag = pa_parse_fp_format (&s);
3085 the_insn.fpof1 = flag;
3086 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3087
3088 /* Handle a destination FP operand format completer. */
3089 case 'G':
3090 /* pa_parse_format needs the ',' prefix. */
3091 s--;
3092 flag = pa_parse_fp_format (&s);
3093 the_insn.fpof2 = flag;
3094 INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
3095
3096 /* Handle a source FP operand format completer at 20. */
3097 case 'I':
3098 flag = pa_parse_fp_format (&s);
3099 the_insn.fpof1 = flag;
3100 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3101
3102 /* Handle a floating point operand format at 26.
3103 Only allows single and double precision. */
3104 case 'H':
3105 flag = pa_parse_fp_format (&s);
3106 switch (flag)
3107 {
3108 case SGL:
3109 opcode |= 0x20;
3110 case DBL:
3111 the_insn.fpof1 = flag;
3112 continue;
3113
3114 case QUAD:
3115 case ILLEGAL_FMT:
3116 default:
3117 as_bad (_("Invalid Floating Point Operand Format."));
3118 }
3119 break;
3120
3121 /* Handle all floating point registers. */
3122 case 'f':
3123 switch (*++args)
3124 {
3125 /* Float target register. */
3126 case 't':
3127 /* This should be more strict. Small steps. */
3128 if (strict && *s != '%')
3129 break;
3130 num = pa_parse_number (&s, 0);
3131 CHECK_FIELD (num, 31, 0, 0);
3132 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3133
3134 /* Float target register with L/R selection. */
3135 case 'T':
3136 {
3137 struct pa_11_fp_reg_struct result;
3138
3139 /* This should be more strict. Small steps. */
3140 if (strict && *s != '%')
3141 break;
3142 pa_parse_number (&s, &result);
3143 CHECK_FIELD (result.number_part, 31, 0, 0);
3144 opcode |= result.number_part;
3145
3146 /* 0x30 opcodes are FP arithmetic operation opcodes
3147 and need to be turned into 0x38 opcodes. This
3148 is not necessary for loads/stores. */
3149 if (need_pa11_opcode (&the_insn, &result)
3150 && ((opcode & 0xfc000000) == 0x30000000))
3151 opcode |= 1 << 27;
3152
3153 INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6);
3154 }
3155
3156 /* Float operand 1. */
3157 case 'a':
3158 {
3159 struct pa_11_fp_reg_struct result;
3160
3161 /* This should be more strict. Small steps. */
3162 if (strict && *s != '%')
3163 break;
3164 pa_parse_number (&s, &result);
3165 CHECK_FIELD (result.number_part, 31, 0, 0);
3166 opcode |= result.number_part << 21;
3167 if (need_pa11_opcode (&the_insn, &result))
3168 {
3169 opcode |= (result.l_r_select & 1) << 7;
3170 opcode |= 1 << 27;
3171 }
3172 continue;
3173 }
3174
3175 /* Float operand 1 with L/R selection. */
3176 case 'X':
3177 case 'A':
3178 {
3179 struct pa_11_fp_reg_struct result;
3180
3181 /* This should be more strict. Small steps. */
3182 if (strict && *s != '%')
3183 break;
3184 pa_parse_number (&s, &result);
3185 CHECK_FIELD (result.number_part, 31, 0, 0);
3186 opcode |= result.number_part << 21;
3187 opcode |= (result.l_r_select & 1) << 7;
3188 continue;
3189 }
3190
3191 /* Float operand 2. */
3192 case 'b':
3193 {
3194 struct pa_11_fp_reg_struct result;
3195
3196 /* This should be more strict. Small steps. */
3197 if (strict && *s != '%')
3198 break;
3199 pa_parse_number (&s, &result);
3200 CHECK_FIELD (result.number_part, 31, 0, 0);
3201 opcode |= (result.number_part & 0x1f) << 16;
3202 if (need_pa11_opcode (&the_insn, &result))
3203 {
3204 opcode |= (result.l_r_select & 1) << 12;
3205 opcode |= 1 << 27;
3206 }
3207 continue;
3208 }
3209
3210 /* Float operand 2 with L/R selection. */
3211 case 'B':
3212 {
3213 struct pa_11_fp_reg_struct result;
3214
3215 /* This should be more strict. Small steps. */
3216 if (strict && *s != '%')
3217 break;
3218 pa_parse_number (&s, &result);
3219 CHECK_FIELD (result.number_part, 31, 0, 0);
3220 opcode |= (result.number_part & 0x1f) << 16;
3221 opcode |= (result.l_r_select & 1) << 12;
3222 continue;
3223 }
3224
3225 /* Float operand 3 for fmpyfadd, fmpynfadd. */
3226 case 'C':
3227 {
3228 struct pa_11_fp_reg_struct result;
3229 int regnum;
3230
3231 /* This should be more strict. Small steps. */
3232 if (strict && *s != '%')
3233 break;
3234 pa_parse_number (&s, &result);
3235 CHECK_FIELD (result.number_part, 31, 0, 0);
3236 opcode |= (result.number_part & 0x1c) << 11;
3237 opcode |= (result.number_part & 0x3) << 9;
3238 opcode |= (result.l_r_select & 1) << 8;
3239 continue;
3240 }
3241
3242 /* Float mult operand 1 for fmpyadd, fmpysub */
3243 case 'i':
3244 {
3245 struct pa_11_fp_reg_struct result;
3246
3247 /* This should be more strict. Small steps. */
3248 if (strict && *s != '%')
3249 break;
3250 pa_parse_number (&s, &result);
3251 CHECK_FIELD (result.number_part, 31, 0, 0);
3252 if (the_insn.fpof1 == SGL)
3253 {
3254 if (result.number_part < 16)
3255 {
3256 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3257 break;
3258 }
3259
3260 result.number_part &= 0xF;
3261 result.number_part |= (result.l_r_select & 1) << 4;
3262 }
3263 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21);
3264 }
3265
3266 /* Float mult operand 2 for fmpyadd, fmpysub */
3267 case 'j':
3268 {
3269 struct pa_11_fp_reg_struct result;
3270
3271 /* This should be more strict. Small steps. */
3272 if (strict && *s != '%')
3273 break;
3274 pa_parse_number (&s, &result);
3275 CHECK_FIELD (result.number_part, 31, 0, 0);
3276 if (the_insn.fpof1 == SGL)
3277 {
3278 if (result.number_part < 16)
3279 {
3280 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3281 break;
3282 }
3283 result.number_part &= 0xF;
3284 result.number_part |= (result.l_r_select & 1) << 4;
3285 }
3286 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16);
3287 }
3288
3289 /* Float mult target for fmpyadd, fmpysub */
3290 case 'k':
3291 {
3292 struct pa_11_fp_reg_struct result;
3293
3294 /* This should be more strict. Small steps. */
3295 if (strict && *s != '%')
3296 break;
3297 pa_parse_number (&s, &result);
3298 CHECK_FIELD (result.number_part, 31, 0, 0);
3299 if (the_insn.fpof1 == SGL)
3300 {
3301 if (result.number_part < 16)
3302 {
3303 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3304 break;
3305 }
3306 result.number_part &= 0xF;
3307 result.number_part |= (result.l_r_select & 1) << 4;
3308 }
3309 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0);
3310 }
3311
3312 /* Float add operand 1 for fmpyadd, fmpysub */
3313 case 'l':
3314 {
3315 struct pa_11_fp_reg_struct result;
3316
3317 /* This should be more strict. Small steps. */
3318 if (strict && *s != '%')
3319 break;
3320 pa_parse_number (&s, &result);
3321 CHECK_FIELD (result.number_part, 31, 0, 0);
3322 if (the_insn.fpof1 == SGL)
3323 {
3324 if (result.number_part < 16)
3325 {
3326 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3327 break;
3328 }
3329 result.number_part &= 0xF;
3330 result.number_part |= (result.l_r_select & 1) << 4;
3331 }
3332 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6);
3333 }
3334
3335 /* Float add target for fmpyadd, fmpysub */
3336 case 'm':
3337 {
3338 struct pa_11_fp_reg_struct result;
3339
3340 /* This should be more strict. Small steps. */
3341 if (strict && *s != '%')
3342 break;
3343 pa_parse_number (&s, &result);
3344 CHECK_FIELD (result.number_part, 31, 0, 0);
3345 if (the_insn.fpof1 == SGL)
3346 {
3347 if (result.number_part < 16)
3348 {
3349 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3350 break;
3351 }
3352 result.number_part &= 0xF;
3353 result.number_part |= (result.l_r_select & 1) << 4;
3354 }
3355 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11);
3356 }
3357
3358 default:
3359 abort ();
3360 }
3361 break;
3362
3363 /* Handle L/R register halves like 'x'. */
3364 case 'e':
3365 {
3366 struct pa_11_fp_reg_struct result;
3367
3368 /* This should be more strict. Small steps. */
3369 if (strict && *s != '%')
3370 break;
3371 pa_parse_number (&s, &result);
3372 CHECK_FIELD (result.number_part, 31, 0, 0);
3373 opcode |= (result.number_part & 0x1f) << 16;
3374 if (need_pa11_opcode (&the_insn, &result))
3375 {
3376 opcode |= (result.l_r_select & 1) << 1;
3377 }
3378 continue;
3379 }
3380
3381 default:
3382 abort ();
3383 }
3384 break;
3385 }
3386
3387 failed:
3388 /* Check if the args matched. */
3389 if (match == FALSE)
3390 {
3391 if (&insn[1] - pa_opcodes < (int) NUMOPCODES
3392 && !strcmp (insn->name, insn[1].name))
3393 {
3394 ++insn;
3395 s = argstart;
3396 continue;
3397 }
3398 else
3399 {
3400 as_bad (_("Invalid operands %s"), error_message);
3401 return;
3402 }
3403 }
3404 break;
3405 }
3406
3407 the_insn.opcode = opcode;
3408 }
3409
3410 /* Turn a string in input_line_pointer into a floating point constant of type
3411 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
3412 emitted is stored in *sizeP . An error message or NULL is returned. */
3413
3414 #define MAX_LITTLENUMS 6
3415
3416 char *
3417 md_atof (type, litP, sizeP)
3418 char type;
3419 char *litP;
3420 int *sizeP;
3421 {
3422 int prec;
3423 LITTLENUM_TYPE words[MAX_LITTLENUMS];
3424 LITTLENUM_TYPE *wordP;
3425 char *t;
3426
3427 switch (type)
3428 {
3429
3430 case 'f':
3431 case 'F':
3432 case 's':
3433 case 'S':
3434 prec = 2;
3435 break;
3436
3437 case 'd':
3438 case 'D':
3439 case 'r':
3440 case 'R':
3441 prec = 4;
3442 break;
3443
3444 case 'x':
3445 case 'X':
3446 prec = 6;
3447 break;
3448
3449 case 'p':
3450 case 'P':
3451 prec = 6;
3452 break;
3453
3454 default:
3455 *sizeP = 0;
3456 return _("Bad call to MD_ATOF()");
3457 }
3458 t = atof_ieee (input_line_pointer, type, words);
3459 if (t)
3460 input_line_pointer = t;
3461 *sizeP = prec * sizeof (LITTLENUM_TYPE);
3462 for (wordP = words; prec--;)
3463 {
3464 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
3465 litP += sizeof (LITTLENUM_TYPE);
3466 }
3467 return NULL;
3468 }
3469
3470 /* Write out big-endian. */
3471
3472 void
3473 md_number_to_chars (buf, val, n)
3474 char *buf;
3475 valueT val;
3476 int n;
3477 {
3478 number_to_chars_bigendian (buf, val, n);
3479 }
3480
3481 /* Translate internal representation of relocation info to BFD target
3482 format. */
3483
3484 arelent **
3485 tc_gen_reloc (section, fixp)
3486 asection *section;
3487 fixS *fixp;
3488 {
3489 arelent *reloc;
3490 struct hppa_fix_struct *hppa_fixp;
3491 bfd_reloc_code_real_type code;
3492 static arelent *no_relocs = NULL;
3493 arelent **relocs;
3494 bfd_reloc_code_real_type **codes;
3495 int n_relocs;
3496 int i;
3497
3498 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
3499 if (fixp->fx_addsy == 0)
3500 return &no_relocs;
3501 assert (hppa_fixp != 0);
3502 assert (section != 0);
3503
3504 reloc = (arelent *) xmalloc (sizeof (arelent));
3505
3506 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3507 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
3508 codes = (bfd_reloc_code_real_type **) hppa_gen_reloc_type (stdoutput,
3509 fixp->fx_r_type,
3510 hppa_fixp->fx_r_format,
3511 hppa_fixp->fx_r_field,
3512 fixp->fx_subsy != NULL,
3513 symbol_get_bfdsym (fixp->fx_addsy));
3514
3515 if (codes == NULL)
3516 abort ();
3517
3518 for (n_relocs = 0; codes[n_relocs]; n_relocs++)
3519 ;
3520
3521 relocs = (arelent **) xmalloc (sizeof (arelent *) * n_relocs + 1);
3522 reloc = (arelent *) xmalloc (sizeof (arelent) * n_relocs);
3523 for (i = 0; i < n_relocs; i++)
3524 relocs[i] = &reloc[i];
3525
3526 relocs[n_relocs] = NULL;
3527
3528 #ifdef OBJ_ELF
3529 switch (fixp->fx_r_type)
3530 {
3531 default:
3532 assert (n_relocs == 1);
3533
3534 code = *codes[0];
3535
3536 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3537 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
3538 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
3539 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
3540 reloc->addend = 0; /* default */
3541
3542 assert (reloc->howto && code == reloc->howto->type);
3543
3544 /* Now, do any processing that is dependent on the relocation type. */
3545 switch (code)
3546 {
3547 case R_PARISC_DLTREL21L:
3548 case R_PARISC_DLTREL14R:
3549 case R_PARISC_DLTREL14F:
3550 case R_PARISC_PLABEL32:
3551 case R_PARISC_PLABEL21L:
3552 case R_PARISC_PLABEL14R:
3553 /* For plabel relocations, the addend of the
3554 relocation should be either 0 (no static link) or 2
3555 (static link required).
3556
3557 FIXME: We always assume no static link!
3558
3559 We also slam a zero addend into the DLT relative relocs;
3560 it doesn't make a lot of sense to use any addend since
3561 it gets you a different (eg unknown) DLT entry. */
3562 reloc->addend = 0;
3563 break;
3564
3565 case R_PARISC_PCREL21L:
3566 case R_PARISC_PCREL17R:
3567 case R_PARISC_PCREL17F:
3568 case R_PARISC_PCREL17C:
3569 case R_PARISC_PCREL14R:
3570 case R_PARISC_PCREL14F:
3571 /* The constant is stored in the instruction. */
3572 reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
3573 break;
3574 default:
3575 reloc->addend = fixp->fx_offset;
3576 break;
3577 }
3578 break;
3579 }
3580 #else /* OBJ_SOM */
3581
3582 /* Walk over reach relocation returned by the BFD backend. */
3583 for (i = 0; i < n_relocs; i++)
3584 {
3585 code = *codes[i];
3586
3587 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3588 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
3589 relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code);
3590 relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
3591
3592 switch (code)
3593 {
3594 case R_COMP2:
3595 /* The only time we ever use a R_COMP2 fixup is for the difference
3596 of two symbols. With that in mind we fill in all four
3597 relocs now and break out of the loop. */
3598 assert (i == 1);
3599 relocs[0]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
3600 relocs[0]->howto = bfd_reloc_type_lookup (stdoutput, *codes[0]);
3601 relocs[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
3602 relocs[0]->addend = 0;
3603 relocs[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3604 *relocs[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
3605 relocs[1]->howto = bfd_reloc_type_lookup (stdoutput, *codes[1]);
3606 relocs[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
3607 relocs[1]->addend = 0;
3608 relocs[2]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3609 *relocs[2]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
3610 relocs[2]->howto = bfd_reloc_type_lookup (stdoutput, *codes[2]);
3611 relocs[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
3612 relocs[2]->addend = 0;
3613 relocs[3]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
3614 relocs[3]->howto = bfd_reloc_type_lookup (stdoutput, *codes[3]);
3615 relocs[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
3616 relocs[3]->addend = 0;
3617 relocs[4]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
3618 relocs[4]->howto = bfd_reloc_type_lookup (stdoutput, *codes[4]);
3619 relocs[4]->address = fixp->fx_frag->fr_address + fixp->fx_where;
3620 relocs[4]->addend = 0;
3621 goto done;
3622 case R_PCREL_CALL:
3623 case R_ABS_CALL:
3624 relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
3625 break;
3626
3627 case R_DLT_REL:
3628 case R_DATA_PLABEL:
3629 case R_CODE_PLABEL:
3630 /* For plabel relocations, the addend of the
3631 relocation should be either 0 (no static link) or 2
3632 (static link required).
3633
3634 FIXME: We always assume no static link!
3635
3636 We also slam a zero addend into the DLT relative relocs;
3637 it doesn't make a lot of sense to use any addend since
3638 it gets you a different (eg unknown) DLT entry. */
3639 relocs[i]->addend = 0;
3640 break;
3641
3642 case R_N_MODE:
3643 case R_S_MODE:
3644 case R_D_MODE:
3645 case R_R_MODE:
3646 case R_FSEL:
3647 case R_LSEL:
3648 case R_RSEL:
3649 case R_BEGIN_BRTAB:
3650 case R_END_BRTAB:
3651 case R_BEGIN_TRY:
3652 case R_N0SEL:
3653 case R_N1SEL:
3654 /* There is no symbol or addend associated with these fixups. */
3655 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3656 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
3657 relocs[i]->addend = 0;
3658 break;
3659
3660 case R_END_TRY:
3661 case R_ENTRY:
3662 case R_EXIT:
3663 /* There is no symbol associated with these fixups. */
3664 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3665 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
3666 relocs[i]->addend = fixp->fx_offset;
3667 break;
3668
3669 default:
3670 relocs[i]->addend = fixp->fx_offset;
3671 }
3672 }
3673
3674 done:
3675 #endif
3676
3677 return relocs;
3678 }
3679
3680 /* Process any machine dependent frag types. */
3681
3682 void
3683 md_convert_frag (abfd, sec, fragP)
3684 register bfd *abfd;
3685 register asection *sec;
3686 register fragS *fragP;
3687 {
3688 unsigned int address;
3689
3690 if (fragP->fr_type == rs_machine_dependent)
3691 {
3692 switch ((int) fragP->fr_subtype)
3693 {
3694 case 0:
3695 fragP->fr_type = rs_fill;
3696 know (fragP->fr_var == 1);
3697 know (fragP->fr_next);
3698 address = fragP->fr_address + fragP->fr_fix;
3699 if (address % fragP->fr_offset)
3700 {
3701 fragP->fr_offset =
3702 fragP->fr_next->fr_address
3703 - fragP->fr_address
3704 - fragP->fr_fix;
3705 }
3706 else
3707 fragP->fr_offset = 0;
3708 break;
3709 }
3710 }
3711 }
3712
3713 /* Round up a section size to the appropriate boundary. */
3714
3715 valueT
3716 md_section_align (segment, size)
3717 asection *segment;
3718 valueT size;
3719 {
3720 int align = bfd_get_section_alignment (stdoutput, segment);
3721 int align2 = (1 << align) - 1;
3722
3723 return (size + align2) & ~align2;
3724 }
3725
3726 /* Return the approximate size of a frag before relaxation has occurred. */
3727 int
3728 md_estimate_size_before_relax (fragP, segment)
3729 register fragS *fragP;
3730 asection *segment;
3731 {
3732 int size;
3733
3734 size = 0;
3735
3736 while ((fragP->fr_fix + size) % fragP->fr_offset)
3737 size++;
3738
3739 return size;
3740 }
3741 \f
3742 CONST char *md_shortopts = "";
3743 struct option md_longopts[] = {
3744 {NULL, no_argument, NULL, 0}
3745 };
3746 size_t md_longopts_size = sizeof(md_longopts);
3747
3748 int
3749 md_parse_option (c, arg)
3750 int c;
3751 char *arg;
3752 {
3753 return 0;
3754 }
3755
3756 void
3757 md_show_usage (stream)
3758 FILE *stream;
3759 {
3760 }
3761 \f
3762 /* We have no need to default values of symbols. */
3763
3764 symbolS *
3765 md_undefined_symbol (name)
3766 char *name;
3767 {
3768 return 0;
3769 }
3770
3771 /* Apply a fixup to an instruction. */
3772
3773 int
3774 md_apply_fix (fixP, valp)
3775 fixS *fixP;
3776 valueT *valp;
3777 {
3778 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
3779 struct hppa_fix_struct *hppa_fixP;
3780 long new_val, result = 0;
3781 unsigned int w1, w2, w, resulti;
3782
3783 hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data;
3784 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3785 never be "applied" (they are just markers). Likewise for
3786 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
3787 #ifdef OBJ_SOM
3788 if (fixP->fx_r_type == R_HPPA_ENTRY
3789 || fixP->fx_r_type == R_HPPA_EXIT
3790 || fixP->fx_r_type == R_HPPA_BEGIN_BRTAB
3791 || fixP->fx_r_type == R_HPPA_END_BRTAB
3792 || fixP->fx_r_type == R_HPPA_BEGIN_TRY)
3793 return 1;
3794
3795 /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
3796 fixups are considered not adjustable, which in turn causes
3797 adjust_reloc_syms to not set fx_offset. Ugh. */
3798 if (fixP->fx_r_type == R_HPPA_END_TRY)
3799 {
3800 fixP->fx_offset = *valp;
3801 return 1;
3802 }
3803 #endif
3804
3805 /* There should have been an HPPA specific fixup associated
3806 with the GAS fixup. */
3807 if (hppa_fixP)
3808 {
3809 unsigned long buf_wd = bfd_get_32 (stdoutput, buf);
3810 unsigned char fmt = bfd_hppa_insn2fmt (buf_wd);
3811
3812 /* If there is a symbol associated with this fixup, then it's something
3813 which will need a SOM relocation (except for some PC-relative relocs).
3814 In such cases we should treat the "val" or "addend" as zero since it
3815 will be added in as needed from fx_offset in tc_gen_reloc. */
3816 if ((fixP->fx_addsy != NULL
3817 || fixP->fx_r_type == R_HPPA_NONE)
3818 #ifdef OBJ_SOM
3819 && fmt != 32
3820 #endif
3821 )
3822 new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
3823 #ifdef OBJ_SOM
3824 /* These field selectors imply that we do not want an addend. */
3825 else if (hppa_fixP->fx_r_field == e_psel
3826 || hppa_fixP->fx_r_field == e_rpsel
3827 || hppa_fixP->fx_r_field == e_lpsel
3828 || hppa_fixP->fx_r_field == e_tsel
3829 || hppa_fixP->fx_r_field == e_rtsel
3830 || hppa_fixP->fx_r_field == e_ltsel)
3831 new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
3832 /* This is truely disgusting. The machine independent code blindly
3833 adds in the value of the symbol being relocated against. Damn! */
3834 else if (fmt == 32
3835 && fixP->fx_addsy != NULL
3836 && S_GET_SEGMENT (fixP->fx_addsy) != bfd_com_section_ptr)
3837 new_val = hppa_field_adjust (*valp - S_GET_VALUE (fixP->fx_addsy),
3838 0, hppa_fixP->fx_r_field);
3839 #endif
3840 else
3841 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
3842
3843 /* Handle pc-relative exceptions from above. */
3844 #define arg_reloc_stub_needed(CALLER, CALLEE) \
3845 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3846 if ((fmt == 12 || fmt == 17 || fmt == 22)
3847 && fixP->fx_addsy
3848 && fixP->fx_pcrel
3849 #ifdef OBJ_SOM
3850 && !arg_reloc_stub_needed ((long) ((obj_symbol_type *)
3851 symbol_get_bfdsym (fixP->fx_addsy))->tc_data.ap.hppa_arg_reloc,
3852 hppa_fixP->fx_arg_reloc)
3853 #endif
3854 && (((int)(*valp) > -262144 && (int)(*valp) < 262143) && fmt != 22)
3855 && S_GET_SEGMENT (fixP->fx_addsy) == hppa_fixP->segment
3856 && !(fixP->fx_subsy
3857 && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment))
3858
3859 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
3860 #undef arg_reloc_stub_needed
3861
3862 switch (fmt)
3863 {
3864 /* Handle all opcodes with the 'j' operand type. */
3865 case 14:
3866 CHECK_FIELD (new_val, 8191, -8192, 0);
3867
3868 /* Mask off 14 bits to be changed. */
3869 bfd_put_32 (stdoutput,
3870 bfd_get_32 (stdoutput, buf) & 0xffffc000,
3871 buf);
3872 low_sign_unext (new_val, 14, &resulti);
3873 result = resulti;
3874 break;
3875
3876 /* Handle all opcodes with the 'k' operand type. */
3877 case 21:
3878 CHECK_FIELD (new_val, 2097152, 0, 0);
3879
3880 /* Mask off 21 bits to be changed. */
3881 bfd_put_32 (stdoutput,
3882 bfd_get_32 (stdoutput, buf) & 0xffe00000,
3883 buf);
3884 dis_assemble_21 (new_val, &resulti);
3885 result = resulti;
3886 break;
3887
3888 /* Handle all the opcodes with the 'i' operand type. */
3889 case 11:
3890 CHECK_FIELD (new_val, 1023, -1023, 0);
3891
3892 /* Mask off 11 bits to be changed. */
3893 bfd_put_32 (stdoutput,
3894 bfd_get_32 (stdoutput, buf) & 0xffff800,
3895 buf);
3896 low_sign_unext (new_val, 11, &resulti);
3897 result = resulti;
3898 break;
3899
3900 /* Handle all the opcodes with the 'w' operand type. */
3901 case 12:
3902 CHECK_FIELD (new_val, 8199, -8184, 0);
3903
3904 /* Mask off 11 bits to be changed. */
3905 sign_unext ((new_val - 8) >> 2, 12, &resulti);
3906 bfd_put_32 (stdoutput,
3907 bfd_get_32 (stdoutput, buf) & 0xffffe002,
3908 buf);
3909
3910 dis_assemble_12 (resulti, &w1, &w);
3911 result = ((w1 << 2) | w);
3912 break;
3913
3914 /* Handle some of the opcodes with the 'W' operand type. */
3915 case 17:
3916 {
3917 int distance = *valp;
3918
3919 CHECK_FIELD (new_val, 262143, -262144, 0);
3920
3921 /* If this is an absolute branch (ie no link) with an out of
3922 range target, then we want to complain. */
3923 if (fixP->fx_r_type == R_HPPA_PCREL_CALL
3924 && (distance > 262143 || distance < -262144)
3925 && (bfd_get_32 (stdoutput, buf) & 0xffe00000) == 0xe8000000)
3926 CHECK_FIELD (distance, 262143, -262144, 0);
3927
3928 /* Mask off 17 bits to be changed. */
3929 bfd_put_32 (stdoutput,
3930 bfd_get_32 (stdoutput, buf) & 0xffe0e002,
3931 buf);
3932 sign_unext ((new_val - 8) >> 2, 17, &resulti);
3933 dis_assemble_17 (resulti, &w1, &w2, &w);
3934 result = ((w2 << 2) | (w1 << 16) | w);
3935 break;
3936 }
3937
3938 case 32:
3939 result = 0;
3940 bfd_put_32 (stdoutput, new_val, buf);
3941 break;
3942
3943 default:
3944 as_bad (_("Unknown relocation encountered in md_apply_fix."));
3945 return 0;
3946 }
3947
3948 /* Insert the relocation. */
3949 bfd_put_32 (stdoutput, bfd_get_32 (stdoutput, buf) | result, buf);
3950 return 1;
3951 }
3952 else
3953 {
3954 printf (_("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n"),
3955 (unsigned int) fixP, fixP->fx_r_type);
3956 return 0;
3957 }
3958 }
3959
3960 /* Exactly what point is a PC-relative offset relative TO?
3961 On the PA, they're relative to the address of the offset. */
3962
3963 long
3964 md_pcrel_from (fixP)
3965 fixS *fixP;
3966 {
3967 return fixP->fx_where + fixP->fx_frag->fr_address;
3968 }
3969
3970 /* Return nonzero if the input line pointer is at the end of
3971 a statement. */
3972
3973 static int
3974 is_end_of_statement ()
3975 {
3976 return ((*input_line_pointer == '\n')
3977 || (*input_line_pointer == ';')
3978 || (*input_line_pointer == '!'));
3979 }
3980
3981 /* Read a number from S. The number might come in one of many forms,
3982 the most common will be a hex or decimal constant, but it could be
3983 a pre-defined register (Yuk!), or an absolute symbol.
3984
3985 Return a number or -1 for failure.
3986
3987 When parsing PA-89 FP register numbers RESULT will be
3988 the address of a structure to return information about
3989 L/R half of FP registers, store results there as appropriate.
3990
3991 pa_parse_number can not handle negative constants and will fail
3992 horribly if it is passed such a constant. */
3993
3994 static int
3995 pa_parse_number (s, result)
3996 char **s;
3997 struct pa_11_fp_reg_struct *result;
3998 {
3999 int num;
4000 char *name;
4001 char c;
4002 symbolS *sym;
4003 int status;
4004 char *p = *s;
4005
4006 /* Skip whitespace before the number. */
4007 while (*p == ' ' || *p == '\t')
4008 p = p + 1;
4009
4010 /* Store info in RESULT if requested by caller. */
4011 if (result)
4012 {
4013 result->number_part = -1;
4014 result->l_r_select = -1;
4015 }
4016 num = -1;
4017
4018 if (isdigit (*p))
4019 {
4020 /* Looks like a number. */
4021 num = 0;
4022
4023 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
4024 {
4025 /* The number is specified in hex. */
4026 p += 2;
4027 while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f'))
4028 || ((*p >= 'A') && (*p <= 'F')))
4029 {
4030 if (isdigit (*p))
4031 num = num * 16 + *p - '0';
4032 else if (*p >= 'a' && *p <= 'f')
4033 num = num * 16 + *p - 'a' + 10;
4034 else
4035 num = num * 16 + *p - 'A' + 10;
4036 ++p;
4037 }
4038 }
4039 else
4040 {
4041 /* The number is specified in decimal. */
4042 while (isdigit (*p))
4043 {
4044 num = num * 10 + *p - '0';
4045 ++p;
4046 }
4047 }
4048
4049 /* Store info in RESULT if requested by the caller. */
4050 if (result)
4051 {
4052 result->number_part = num;
4053
4054 if (IS_R_SELECT (p))
4055 {
4056 result->l_r_select = 1;
4057 ++p;
4058 }
4059 else if (IS_L_SELECT (p))
4060 {
4061 result->l_r_select = 0;
4062 ++p;
4063 }
4064 else
4065 result->l_r_select = 0;
4066 }
4067 }
4068 else if (*p == '%')
4069 {
4070 /* The number might be a predefined register. */
4071 num = 0;
4072 name = p;
4073 p++;
4074 c = *p;
4075 /* Tege hack: Special case for general registers as the general
4076 code makes a binary search with case translation, and is VERY
4077 slow. */
4078 if (c == 'r')
4079 {
4080 p++;
4081 if (*p == 'e' && *(p + 1) == 't'
4082 && (*(p + 2) == '0' || *(p + 2) == '1'))
4083 {
4084 p += 2;
4085 num = *p - '0' + 28;
4086 p++;
4087 }
4088 else if (*p == 'p')
4089 {
4090 num = 2;
4091 p++;
4092 }
4093 else if (!isdigit (*p))
4094 {
4095 if (print_errors)
4096 as_bad (_("Undefined register: '%s'."), name);
4097 num = -1;
4098 }
4099 else
4100 {
4101 do
4102 num = num * 10 + *p++ - '0';
4103 while (isdigit (*p));
4104 }
4105 }
4106 else
4107 {
4108 /* Do a normal register search. */
4109 while (is_part_of_name (c))
4110 {
4111 p = p + 1;
4112 c = *p;
4113 }
4114 *p = 0;
4115 status = reg_name_search (name);
4116 if (status >= 0)
4117 num = status;
4118 else
4119 {
4120 if (print_errors)
4121 as_bad (_("Undefined register: '%s'."), name);
4122 num = -1;
4123 }
4124 *p = c;
4125 }
4126
4127 /* Store info in RESULT if requested by caller. */
4128 if (result)
4129 {
4130 result->number_part = num;
4131 if (IS_R_SELECT (p - 1))
4132 result->l_r_select = 1;
4133 else if (IS_L_SELECT (p - 1))
4134 result->l_r_select = 0;
4135 else
4136 result->l_r_select = 0;
4137 }
4138 }
4139 else
4140 {
4141 /* And finally, it could be a symbol in the absolute section which
4142 is effectively a constant. */
4143 num = 0;
4144 name = p;
4145 c = *p;
4146 while (is_part_of_name (c))
4147 {
4148 p = p + 1;
4149 c = *p;
4150 }
4151 *p = 0;
4152 if ((sym = symbol_find (name)) != NULL)
4153 {
4154 if (S_GET_SEGMENT (sym) == &bfd_abs_section)
4155 num = S_GET_VALUE (sym);
4156 else
4157 {
4158 if (print_errors)
4159 as_bad (_("Non-absolute symbol: '%s'."), name);
4160 num = -1;
4161 }
4162 }
4163 else
4164 {
4165 /* There is where we'd come for an undefined symbol
4166 or for an empty string. For an empty string we
4167 will return zero. That's a concession made for
4168 compatability with the braindamaged HP assemblers. */
4169 if (*name == 0)
4170 num = 0;
4171 else
4172 {
4173 if (print_errors)
4174 as_bad (_("Undefined absolute constant: '%s'."), name);
4175 num = -1;
4176 }
4177 }
4178 *p = c;
4179
4180 /* Store info in RESULT if requested by caller. */
4181 if (result)
4182 {
4183 result->number_part = num;
4184 if (IS_R_SELECT (p - 1))
4185 result->l_r_select = 1;
4186 else if (IS_L_SELECT (p - 1))
4187 result->l_r_select = 0;
4188 else
4189 result->l_r_select = 0;
4190 }
4191 }
4192
4193 *s = p;
4194 return num;
4195 }
4196
4197 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
4198
4199 /* Given NAME, find the register number associated with that name, return
4200 the integer value associated with the given name or -1 on failure. */
4201
4202 static int
4203 reg_name_search (name)
4204 char *name;
4205 {
4206 int middle, low, high;
4207 int cmp;
4208
4209 low = 0;
4210 high = REG_NAME_CNT - 1;
4211
4212 do
4213 {
4214 middle = (low + high) / 2;
4215 cmp = strcasecmp (name, pre_defined_registers[middle].name);
4216 if (cmp < 0)
4217 high = middle - 1;
4218 else if (cmp > 0)
4219 low = middle + 1;
4220 else
4221 return pre_defined_registers[middle].value;
4222 }
4223 while (low <= high);
4224
4225 return -1;
4226 }
4227
4228
4229 /* Return nonzero if the given INSN and L/R information will require
4230 a new PA-1.1 opcode. */
4231
4232 static int
4233 need_pa11_opcode (insn, result)
4234 struct pa_it *insn;
4235 struct pa_11_fp_reg_struct *result;
4236 {
4237 if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL))
4238 {
4239 /* If this instruction is specific to a particular architecture,
4240 then set a new architecture. */
4241 if (bfd_get_mach (stdoutput) < pa11)
4242 {
4243 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, pa11))
4244 as_warn (_("could not update architecture and machine"));
4245 }
4246 return TRUE;
4247 }
4248 else
4249 return FALSE;
4250 }
4251
4252 /* Parse a condition for a fcmp instruction. Return the numerical
4253 code associated with the condition. */
4254
4255 static int
4256 pa_parse_fp_cmp_cond (s)
4257 char **s;
4258 {
4259 int cond, i;
4260
4261 cond = 0;
4262
4263 for (i = 0; i < 32; i++)
4264 {
4265 if (strncasecmp (*s, fp_cond_map[i].string,
4266 strlen (fp_cond_map[i].string)) == 0)
4267 {
4268 cond = fp_cond_map[i].cond;
4269 *s += strlen (fp_cond_map[i].string);
4270 /* If not a complete match, back up the input string and
4271 report an error. */
4272 if (**s != ' ' && **s != '\t')
4273 {
4274 *s -= strlen (fp_cond_map[i].string);
4275 break;
4276 }
4277 while (**s == ' ' || **s == '\t')
4278 *s = *s + 1;
4279 return cond;
4280 }
4281 }
4282
4283 as_bad (_("Invalid FP Compare Condition: %s"), *s);
4284
4285 /* Advance over the bogus completer. */
4286 while (**s != ',' && **s != ' ' && **s != '\t')
4287 *s += 1;
4288
4289 return 0;
4290 }
4291
4292
4293 /* Parse an FP operand format completer returning the completer
4294 type. */
4295
4296 static fp_operand_format
4297 pa_parse_fp_format (s)
4298 char **s;
4299 {
4300 int format;
4301
4302 format = SGL;
4303 if (**s == ',')
4304 {
4305 *s += 1;
4306 if (strncasecmp (*s, "sgl", 3) == 0)
4307 {
4308 format = SGL;
4309 *s += 4;
4310 }
4311 else if (strncasecmp (*s, "dbl", 3) == 0)
4312 {
4313 format = DBL;
4314 *s += 4;
4315 }
4316 else if (strncasecmp (*s, "quad", 4) == 0)
4317 {
4318 format = QUAD;
4319 *s += 5;
4320 }
4321 else
4322 {
4323 format = ILLEGAL_FMT;
4324 as_bad (_("Invalid FP Operand Format: %3s"), *s);
4325 }
4326 }
4327
4328 return format;
4329 }
4330
4331 /* Convert from a selector string into a selector type. */
4332
4333 static int
4334 pa_chk_field_selector (str)
4335 char **str;
4336 {
4337 int middle, low, high;
4338 int cmp;
4339 char name[4];
4340
4341 /* Read past any whitespace. */
4342 /* FIXME: should we read past newlines and formfeeds??? */
4343 while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
4344 *str = *str + 1;
4345
4346 if ((*str)[1] == '\'' || (*str)[1] == '%')
4347 name[0] = tolower ((*str)[0]),
4348 name[1] = 0;
4349 else if ((*str)[2] == '\'' || (*str)[2] == '%')
4350 name[0] = tolower ((*str)[0]),
4351 name[1] = tolower ((*str)[1]),
4352 name[2] = 0;
4353 else if ((*str)[3] == '\'' || (*str)[3] == '%')
4354 name[0] = tolower ((*str)[0]),
4355 name[1] = tolower ((*str)[1]),
4356 name[2] = tolower ((*str)[2]),
4357 name[3] = 0;
4358 else
4359 return e_fsel;
4360
4361 low = 0;
4362 high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
4363
4364 do
4365 {
4366 middle = (low + high) / 2;
4367 cmp = strcmp (name, selector_table[middle].prefix);
4368 if (cmp < 0)
4369 high = middle - 1;
4370 else if (cmp > 0)
4371 low = middle + 1;
4372 else
4373 {
4374 *str += strlen (name) + 1;
4375 #ifndef OBJ_SOM
4376 if (selector_table[middle].field_selector == e_nsel)
4377 return e_fsel;
4378 #endif
4379 return selector_table[middle].field_selector;
4380 }
4381 }
4382 while (low <= high);
4383
4384 return e_fsel;
4385 }
4386
4387 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
4388
4389 static int
4390 get_expression (str)
4391 char *str;
4392 {
4393 char *save_in;
4394 asection *seg;
4395
4396 save_in = input_line_pointer;
4397 input_line_pointer = str;
4398 seg = expression (&the_insn.exp);
4399 if (!(seg == absolute_section
4400 || seg == undefined_section
4401 || SEG_NORMAL (seg)))
4402 {
4403 as_warn (_("Bad segment in expression."));
4404 expr_end = input_line_pointer;
4405 input_line_pointer = save_in;
4406 return 1;
4407 }
4408 expr_end = input_line_pointer;
4409 input_line_pointer = save_in;
4410 return 0;
4411 }
4412
4413 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
4414 static int
4415 pa_get_absolute_expression (insn, strp)
4416 struct pa_it *insn;
4417 char **strp;
4418 {
4419 char *save_in;
4420
4421 insn->field_selector = pa_chk_field_selector (strp);
4422 save_in = input_line_pointer;
4423 input_line_pointer = *strp;
4424 expression (&insn->exp);
4425 /* This is not perfect, but is a huge improvement over doing nothing.
4426
4427 The PA assembly syntax is ambigious in a variety of ways. Consider
4428 this string "4 %r5" Is that the number 4 followed by the register
4429 r5, or is that 4 MOD 5?
4430
4431 If we get a modulo expresion When looking for an absolute, we try
4432 again cutting off the input string at the first whitespace character. */
4433 if (insn->exp.X_op == O_modulus)
4434 {
4435 char *s, c;
4436 int retval;
4437
4438 input_line_pointer = *strp;
4439 s = *strp;
4440 while (*s != ',' && *s != ' ' && *s != '\t')
4441 s++;
4442
4443 c = *s;
4444 *s = 0;
4445
4446 retval = pa_get_absolute_expression (insn, strp);
4447
4448 input_line_pointer = save_in;
4449 *s = c;
4450 return evaluate_absolute (insn);
4451 }
4452 /* When in strict mode we have a non-match, fix up the pointers
4453 and return to our caller. */
4454 if (insn->exp.X_op != O_constant && strict)
4455 {
4456 expr_end = input_line_pointer;
4457 input_line_pointer = save_in;
4458 return 0;
4459 }
4460 if (insn->exp.X_op != O_constant)
4461 {
4462 as_bad (_("Bad segment (should be absolute)."));
4463 expr_end = input_line_pointer;
4464 input_line_pointer = save_in;
4465 return 0;
4466 }
4467 expr_end = input_line_pointer;
4468 input_line_pointer = save_in;
4469 return evaluate_absolute (insn);
4470 }
4471
4472 /* Evaluate an absolute expression EXP which may be modified by
4473 the selector FIELD_SELECTOR. Return the value of the expression. */
4474 static int
4475 evaluate_absolute (insn)
4476 struct pa_it *insn;
4477 {
4478 int value;
4479 expressionS exp;
4480 int field_selector = insn->field_selector;
4481
4482 exp = insn->exp;
4483 value = exp.X_add_number;
4484
4485 switch (field_selector)
4486 {
4487 /* No change. */
4488 case e_fsel:
4489 break;
4490
4491 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
4492 case e_lssel:
4493 if (value & 0x00000400)
4494 value += 0x800;
4495 value = (value & 0xfffff800) >> 11;
4496 break;
4497
4498 /* Sign extend from bit 21. */
4499 case e_rssel:
4500 if (value & 0x00000400)
4501 value |= 0xfffff800;
4502 else
4503 value &= 0x7ff;
4504 break;
4505
4506 /* Arithmetic shift right 11 bits. */
4507 case e_lsel:
4508 value = (value & 0xfffff800) >> 11;
4509 break;
4510
4511 /* Set bits 0-20 to zero. */
4512 case e_rsel:
4513 value = value & 0x7ff;
4514 break;
4515
4516 /* Add 0x800 and arithmetic shift right 11 bits. */
4517 case e_ldsel:
4518 value += 0x800;
4519 value = (value & 0xfffff800) >> 11;
4520 break;
4521
4522 /* Set bitgs 0-21 to one. */
4523 case e_rdsel:
4524 value |= 0xfffff800;
4525 break;
4526
4527 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
4528 case e_rrsel:
4529 value = (RSEL_ROUND (value) & 0x7ff) + (value - RSEL_ROUND (value));
4530 break;
4531
4532 case e_lrsel:
4533 value = (RSEL_ROUND (value) >> 11) & 0x1fffff;
4534 break;
4535 #undef RSEL_ROUND
4536
4537 default:
4538 BAD_CASE (field_selector);
4539 break;
4540 }
4541 return value;
4542 }
4543
4544 /* Given an argument location specification return the associated
4545 argument location number. */
4546
4547 static unsigned int
4548 pa_build_arg_reloc (type_name)
4549 char *type_name;
4550 {
4551
4552 if (strncasecmp (type_name, "no", 2) == 0)
4553 return 0;
4554 if (strncasecmp (type_name, "gr", 2) == 0)
4555 return 1;
4556 else if (strncasecmp (type_name, "fr", 2) == 0)
4557 return 2;
4558 else if (strncasecmp (type_name, "fu", 2) == 0)
4559 return 3;
4560 else
4561 as_bad (_("Invalid argument location: %s\n"), type_name);
4562
4563 return 0;
4564 }
4565
4566 /* Encode and return an argument relocation specification for
4567 the given register in the location specified by arg_reloc. */
4568
4569 static unsigned int
4570 pa_align_arg_reloc (reg, arg_reloc)
4571 unsigned int reg;
4572 unsigned int arg_reloc;
4573 {
4574 unsigned int new_reloc;
4575
4576 new_reloc = arg_reloc;
4577 switch (reg)
4578 {
4579 case 0:
4580 new_reloc <<= 8;
4581 break;
4582 case 1:
4583 new_reloc <<= 6;
4584 break;
4585 case 2:
4586 new_reloc <<= 4;
4587 break;
4588 case 3:
4589 new_reloc <<= 2;
4590 break;
4591 default:
4592 as_bad (_("Invalid argument description: %d"), reg);
4593 }
4594
4595 return new_reloc;
4596 }
4597
4598 /* Parse a PA nullification completer (,n). Return nonzero if the
4599 completer was found; return zero if no completer was found. */
4600
4601 static int
4602 pa_parse_nullif (s)
4603 char **s;
4604 {
4605 int nullif;
4606
4607 nullif = 0;
4608 if (**s == ',')
4609 {
4610 *s = *s + 1;
4611 if (strncasecmp (*s, "n", 1) == 0)
4612 nullif = 1;
4613 else
4614 {
4615 as_bad (_("Invalid Nullification: (%c)"), **s);
4616 nullif = 0;
4617 }
4618 *s = *s + 1;
4619 }
4620
4621 return nullif;
4622 }
4623
4624 /* Parse a non-negated compare/subtract completer returning the
4625 number (for encoding in instrutions) of the given completer.
4626
4627 ISBRANCH specifies whether or not this is parsing a condition
4628 completer for a branch (vs a nullification completer for a
4629 computational instruction. */
4630
4631 static int
4632 pa_parse_nonneg_cmpsub_cmpltr (s, isbranch)
4633 char **s;
4634 int isbranch;
4635 {
4636 int cmpltr;
4637 char *name = *s + 1;
4638 char c;
4639 char *save_s = *s;
4640 int nullify = 0;
4641
4642 cmpltr = 0;
4643 if (**s == ',')
4644 {
4645 *s += 1;
4646 while (**s != ',' && **s != ' ' && **s != '\t')
4647 *s += 1;
4648 c = **s;
4649 **s = 0x00;
4650
4651
4652 if (strcmp (name, "=") == 0)
4653 {
4654 cmpltr = 1;
4655 }
4656 else if (strcmp (name, "<") == 0)
4657 {
4658 cmpltr = 2;
4659 }
4660 else if (strcmp (name, "<=") == 0)
4661 {
4662 cmpltr = 3;
4663 }
4664 else if (strcmp (name, "<<") == 0)
4665 {
4666 cmpltr = 4;
4667 }
4668 else if (strcmp (name, "<<=") == 0)
4669 {
4670 cmpltr = 5;
4671 }
4672 else if (strcasecmp (name, "sv") == 0)
4673 {
4674 cmpltr = 6;
4675 }
4676 else if (strcasecmp (name, "od") == 0)
4677 {
4678 cmpltr = 7;
4679 }
4680 /* If we have something like addb,n then there is no condition
4681 completer. */
4682 else if (strcasecmp (name, "n") == 0 && isbranch)
4683 {
4684 cmpltr = 0;
4685 nullify = 1;
4686 }
4687 else
4688 {
4689 cmpltr = -1;
4690 }
4691 **s = c;
4692 }
4693
4694 /* Reset pointers if this was really a ,n for a branch instruction. */
4695 if (nullify)
4696 *s = save_s;
4697
4698
4699 return cmpltr;
4700 }
4701
4702 /* Parse a negated compare/subtract completer returning the
4703 number (for encoding in instrutions) of the given completer.
4704
4705 ISBRANCH specifies whether or not this is parsing a condition
4706 completer for a branch (vs a nullification completer for a
4707 computational instruction. */
4708
4709 static int
4710 pa_parse_neg_cmpsub_cmpltr (s, isbranch)
4711 char **s;
4712 int isbranch;
4713 {
4714 int cmpltr;
4715 char *name = *s + 1;
4716 char c;
4717 char *save_s = *s;
4718 int nullify = 0;
4719
4720 cmpltr = 0;
4721 if (**s == ',')
4722 {
4723 *s += 1;
4724 while (**s != ',' && **s != ' ' && **s != '\t')
4725 *s += 1;
4726 c = **s;
4727 **s = 0x00;
4728
4729
4730 if (strcasecmp (name, "tr") == 0)
4731 {
4732 cmpltr = 0;
4733 }
4734 else if (strcmp (name, "<>") == 0)
4735 {
4736 cmpltr = 1;
4737 }
4738 else if (strcmp (name, ">=") == 0)
4739 {
4740 cmpltr = 2;
4741 }
4742 else if (strcmp (name, ">") == 0)
4743 {
4744 cmpltr = 3;
4745 }
4746 else if (strcmp (name, ">>=") == 0)
4747 {
4748 cmpltr = 4;
4749 }
4750 else if (strcmp (name, ">>") == 0)
4751 {
4752 cmpltr = 5;
4753 }
4754 else if (strcasecmp (name, "nsv") == 0)
4755 {
4756 cmpltr = 6;
4757 }
4758 else if (strcasecmp (name, "ev") == 0)
4759 {
4760 cmpltr = 7;
4761 }
4762 /* If we have something like addb,n then there is no condition
4763 completer. */
4764 else if (strcasecmp (name, "n") == 0 && isbranch)
4765 {
4766 cmpltr = 0;
4767 nullify = 1;
4768 }
4769 else
4770 {
4771 cmpltr = -1;
4772 }
4773 **s = c;
4774 }
4775
4776 /* Reset pointers if this was really a ,n for a branch instruction. */
4777 if (nullify)
4778 *s = save_s;
4779
4780
4781 return cmpltr;
4782 }
4783
4784
4785 /* Parse a non-negated addition completer returning the number
4786 (for encoding in instrutions) of the given completer.
4787
4788 ISBRANCH specifies whether or not this is parsing a condition
4789 completer for a branch (vs a nullification completer for a
4790 computational instruction. */
4791
4792 static int
4793 pa_parse_nonneg_add_cmpltr (s, isbranch)
4794 char **s;
4795 int isbranch;
4796 {
4797 int cmpltr;
4798 char *name = *s + 1;
4799 char c;
4800 char *save_s = *s;
4801
4802 cmpltr = 0;
4803 if (**s == ',')
4804 {
4805 *s += 1;
4806 while (**s != ',' && **s != ' ' && **s != '\t')
4807 *s += 1;
4808 c = **s;
4809 **s = 0x00;
4810 if (strcmp (name, "=") == 0)
4811 {
4812 cmpltr = 1;
4813 }
4814 else if (strcmp (name, "<") == 0)
4815 {
4816 cmpltr = 2;
4817 }
4818 else if (strcmp (name, "<=") == 0)
4819 {
4820 cmpltr = 3;
4821 }
4822 else if (strcasecmp (name, "nuv") == 0)
4823 {
4824 cmpltr = 4;
4825 }
4826 else if (strcasecmp (name, "znv") == 0)
4827 {
4828 cmpltr = 5;
4829 }
4830 else if (strcasecmp (name, "sv") == 0)
4831 {
4832 cmpltr = 6;
4833 }
4834 else if (strcasecmp (name, "od") == 0)
4835 {
4836 cmpltr = 7;
4837 }
4838 /* If we have something like addb,n then there is no condition
4839 completer. */
4840 else if (strcasecmp (name, "n") == 0 && isbranch)
4841 {
4842 cmpltr = 0;
4843 }
4844 else
4845 {
4846 cmpltr = -1;
4847 }
4848 **s = c;
4849 }
4850
4851 /* Reset pointers if this was really a ,n for a branch instruction. */
4852 if (cmpltr == 0 && *name == 'n' && isbranch)
4853 *s = save_s;
4854
4855 return cmpltr;
4856 }
4857
4858 /* Parse a negated addition completer returning the number
4859 (for encoding in instrutions) of the given completer.
4860
4861 ISBRANCH specifies whether or not this is parsing a condition
4862 completer for a branch (vs a nullification completer for a
4863 computational instruction). */
4864
4865 static int
4866 pa_parse_neg_add_cmpltr (s, isbranch)
4867 char **s;
4868 int isbranch;
4869 {
4870 int cmpltr;
4871 char *name = *s + 1;
4872 char c;
4873 char *save_s = *s;
4874
4875 cmpltr = 0;
4876 if (**s == ',')
4877 {
4878 *s += 1;
4879 while (**s != ',' && **s != ' ' && **s != '\t')
4880 *s += 1;
4881 c = **s;
4882 **s = 0x00;
4883 if (strcasecmp (name, "tr") == 0)
4884 {
4885 cmpltr = 0;
4886 }
4887 else if (strcmp (name, "<>") == 0)
4888 {
4889 cmpltr = 1;
4890 }
4891 else if (strcmp (name, ">=") == 0)
4892 {
4893 cmpltr = 2;
4894 }
4895 else if (strcmp (name, ">") == 0)
4896 {
4897 cmpltr = 3;
4898 }
4899 else if (strcasecmp (name, "uv") == 0)
4900 {
4901 cmpltr = 4;
4902 }
4903 else if (strcasecmp (name, "vnz") == 0)
4904 {
4905 cmpltr = 5;
4906 }
4907 else if (strcasecmp (name, "nsv") == 0)
4908 {
4909 cmpltr = 6;
4910 }
4911 else if (strcasecmp (name, "ev") == 0)
4912 {
4913 cmpltr = 7;
4914 }
4915 /* If we have something like addb,n then there is no condition
4916 completer. */
4917 else if (strcasecmp (name, "n") == 0 && isbranch)
4918 {
4919 cmpltr = 0;
4920 }
4921 else
4922 {
4923 cmpltr = -1;
4924 }
4925 **s = c;
4926 }
4927
4928 /* Reset pointers if this was really a ,n for a branch instruction. */
4929 if (cmpltr == 0 && *name == 'n' && isbranch)
4930 *s = save_s;
4931
4932 return cmpltr;
4933 }
4934
4935 #ifdef OBJ_SOM
4936 /* Handle an alignment directive. Special so that we can update the
4937 alignment of the subspace if necessary. */
4938 static void
4939 pa_align (bytes)
4940 {
4941 /* We must have a valid space and subspace. */
4942 pa_check_current_space_and_subspace ();
4943
4944 /* Let the generic gas code do most of the work. */
4945 s_align_bytes (bytes);
4946
4947 /* If bytes is a power of 2, then update the current subspace's
4948 alignment if necessary. */
4949 if (log2 (bytes) != -1)
4950 record_alignment (current_subspace->ssd_seg, log2 (bytes));
4951 }
4952 #endif
4953
4954 /* Handle a .BLOCK type pseudo-op. */
4955
4956 static void
4957 pa_block (z)
4958 int z;
4959 {
4960 char *p;
4961 long int temp_fill;
4962 unsigned int temp_size;
4963 unsigned int i;
4964
4965 #ifdef OBJ_SOM
4966 /* We must have a valid space and subspace. */
4967 pa_check_current_space_and_subspace ();
4968 #endif
4969
4970 temp_size = get_absolute_expression ();
4971
4972 /* Always fill with zeros, that's what the HP assembler does. */
4973 temp_fill = 0;
4974
4975 p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
4976 (relax_substateT) 0, (symbolS *) 0, (offsetT) 1, NULL);
4977 memset (p, 0, temp_size);
4978
4979 /* Convert 2 bytes at a time. */
4980
4981 for (i = 0; i < temp_size; i += 2)
4982 {
4983 md_number_to_chars (p + i,
4984 (valueT) temp_fill,
4985 (int) ((temp_size - i) > 2 ? 2 : (temp_size - i)));
4986 }
4987
4988 pa_undefine_label ();
4989 demand_empty_rest_of_line ();
4990 }
4991
4992 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
4993
4994 static void
4995 pa_brtab (begin)
4996 int begin;
4997 {
4998
4999 #ifdef OBJ_SOM
5000 /* The BRTAB relocations are only availble in SOM (to denote
5001 the beginning and end of branch tables). */
5002 char *where = frag_more (0);
5003
5004 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
5005 NULL, (offsetT) 0, NULL,
5006 0, begin ? R_HPPA_BEGIN_BRTAB : R_HPPA_END_BRTAB,
5007 e_fsel, 0, 0, NULL);
5008 #endif
5009
5010 demand_empty_rest_of_line ();
5011 }
5012
5013 /* Handle a .begin_try and .end_try pseudo-op. */
5014
5015 static void
5016 pa_try (begin)
5017 int begin;
5018 {
5019 #ifdef OBJ_SOM
5020 expressionS exp;
5021 char *where = frag_more (0);
5022
5023 if (! begin)
5024 expression (&exp);
5025
5026 /* The TRY relocations are only availble in SOM (to denote
5027 the beginning and end of exception handling regions). */
5028
5029 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
5030 NULL, (offsetT) 0, begin ? NULL : &exp,
5031 0, begin ? R_HPPA_BEGIN_TRY : R_HPPA_END_TRY,
5032 e_fsel, 0, 0, NULL);
5033 #endif
5034
5035 demand_empty_rest_of_line ();
5036 }
5037
5038 /* Handle a .CALL pseudo-op. This involves storing away information
5039 about where arguments are to be found so the linker can detect
5040 (and correct) argument location mismatches between caller and callee. */
5041
5042 static void
5043 pa_call (unused)
5044 int unused;
5045 {
5046 #ifdef OBJ_SOM
5047 /* We must have a valid space and subspace. */
5048 pa_check_current_space_and_subspace ();
5049 #endif
5050
5051 pa_call_args (&last_call_desc);
5052 demand_empty_rest_of_line ();
5053 }
5054
5055 /* Do the dirty work of building a call descriptor which describes
5056 where the caller placed arguments to a function call. */
5057
5058 static void
5059 pa_call_args (call_desc)
5060 struct call_desc *call_desc;
5061 {
5062 char *name, c, *p;
5063 unsigned int temp, arg_reloc;
5064
5065 while (!is_end_of_statement ())
5066 {
5067 name = input_line_pointer;
5068 c = get_symbol_end ();
5069 /* Process a source argument. */
5070 if ((strncasecmp (name, "argw", 4) == 0))
5071 {
5072 temp = atoi (name + 4);
5073 p = input_line_pointer;
5074 *p = c;
5075 input_line_pointer++;
5076 name = input_line_pointer;
5077 c = get_symbol_end ();
5078 arg_reloc = pa_build_arg_reloc (name);
5079 call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
5080 }
5081 /* Process a return value. */
5082 else if ((strncasecmp (name, "rtnval", 6) == 0))
5083 {
5084 p = input_line_pointer;
5085 *p = c;
5086 input_line_pointer++;
5087 name = input_line_pointer;
5088 c = get_symbol_end ();
5089 arg_reloc = pa_build_arg_reloc (name);
5090 call_desc->arg_reloc |= (arg_reloc & 0x3);
5091 }
5092 else
5093 {
5094 as_bad (_("Invalid .CALL argument: %s"), name);
5095 }
5096 p = input_line_pointer;
5097 *p = c;
5098 if (!is_end_of_statement ())
5099 input_line_pointer++;
5100 }
5101 }
5102
5103 /* Return TRUE if FRAG1 and FRAG2 are the same. */
5104
5105 static int
5106 is_same_frag (frag1, frag2)
5107 fragS *frag1;
5108 fragS *frag2;
5109 {
5110
5111 if (frag1 == NULL)
5112 return (FALSE);
5113 else if (frag2 == NULL)
5114 return (FALSE);
5115 else if (frag1 == frag2)
5116 return (TRUE);
5117 else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0)
5118 return (is_same_frag (frag1, frag2->fr_next));
5119 else
5120 return (FALSE);
5121 }
5122
5123 #ifdef OBJ_ELF
5124 /* Build an entry in the UNWIND subspace from the given function
5125 attributes in CALL_INFO. This is not needed for SOM as using
5126 R_ENTRY and R_EXIT relocations allow the linker to handle building
5127 of the unwind spaces. */
5128
5129 static void
5130 pa_build_unwind_subspace (call_info)
5131 struct call_info *call_info;
5132 {
5133 char *unwind;
5134 asection *seg, *save_seg;
5135 asymbol *sym;
5136 subsegT subseg, save_subseg;
5137 int i, reloc;
5138 char c, *p;
5139
5140 if (now_seg != text_section)
5141 return;
5142
5143 if (bfd_get_arch_info (stdoutput)->bits_per_address == 32)
5144 reloc = R_PARISC_DIR32;
5145 else
5146 reloc = R_PARISC_SEGREL32;
5147
5148 /* Get into the right seg/subseg. This may involve creating
5149 the seg the first time through. Make sure to have the
5150 old seg/subseg so that we can reset things when we are done. */
5151 seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
5152 if (seg == ASEC_NULL)
5153 {
5154 seg = bfd_make_section_old_way (stdoutput, UNWIND_SECTION_NAME);
5155 bfd_set_section_flags (stdoutput, seg,
5156 SEC_READONLY | SEC_HAS_CONTENTS
5157 | SEC_LOAD | SEC_RELOC | SEC_ALLOC | SEC_DATA);
5158 bfd_set_section_alignment (stdoutput, seg, 2);
5159 }
5160
5161 save_seg = now_seg;
5162 save_subseg = now_subseg;
5163 subseg_set (seg, 0);
5164
5165
5166 /* Get some space to hold relocation information for the unwind
5167 descriptor. */
5168 p = frag_more (4);
5169 md_number_to_chars (p, 0, 4);
5170
5171 /* Relocation info. for start offset of the function. */
5172 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
5173 call_info->start_symbol, (offsetT) 0,
5174 (expressionS *) NULL, 0, reloc,
5175 e_fsel, 32, 0, NULL);
5176
5177 p = frag_more (4);
5178 md_number_to_chars (p, 0, 4);
5179
5180 /* Relocation info. for end offset of the function.
5181
5182 Because we allow reductions of 32bit relocations for ELF, this will be
5183 reduced to section_sym + offset which avoids putting the temporary
5184 symbol into the symbol table. It (should) end up giving the same
5185 value as call_info->start_symbol + function size once the linker is
5186 finished with its work. */
5187
5188 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
5189 call_info->end_symbol, (offsetT) 0,
5190 (expressionS *) NULL, 0, reloc,
5191 e_fsel, 32, 0, NULL);
5192
5193 /* Dump it. */
5194 unwind = (char *) &call_info->ci_unwind;
5195 for (i = 8; i < sizeof (struct unwind_table); i++)
5196 {
5197 c = *(unwind + i);
5198 {
5199 FRAG_APPEND_1_CHAR (c);
5200 }
5201 }
5202
5203 /* Return back to the original segment/subsegment. */
5204 subseg_set (save_seg, save_subseg);
5205 }
5206 #endif
5207
5208 /* Process a .CALLINFO pseudo-op. This information is used later
5209 to build unwind descriptors and maybe one day to support
5210 .ENTER and .LEAVE. */
5211
5212 static void
5213 pa_callinfo (unused)
5214 int unused;
5215 {
5216 char *name, c, *p;
5217 int temp;
5218
5219 #ifdef OBJ_SOM
5220 /* We must have a valid space and subspace. */
5221 pa_check_current_space_and_subspace ();
5222 #endif
5223
5224 /* .CALLINFO must appear within a procedure definition. */
5225 if (!within_procedure)
5226 as_bad (_(".callinfo is not within a procedure definition"));
5227
5228 /* Mark the fact that we found the .CALLINFO for the
5229 current procedure. */
5230 callinfo_found = TRUE;
5231
5232 /* Iterate over the .CALLINFO arguments. */
5233 while (!is_end_of_statement ())
5234 {
5235 name = input_line_pointer;
5236 c = get_symbol_end ();
5237 /* Frame size specification. */
5238 if ((strncasecmp (name, "frame", 5) == 0))
5239 {
5240 p = input_line_pointer;
5241 *p = c;
5242 input_line_pointer++;
5243 temp = get_absolute_expression ();
5244 if ((temp & 0x3) != 0)
5245 {
5246 as_bad (_("FRAME parameter must be a multiple of 8: %d\n"), temp);
5247 temp = 0;
5248 }
5249
5250 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
5251 last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
5252
5253 }
5254 /* Entry register (GR, GR and SR) specifications. */
5255 else if ((strncasecmp (name, "entry_gr", 8) == 0))
5256 {
5257 p = input_line_pointer;
5258 *p = c;
5259 input_line_pointer++;
5260 temp = get_absolute_expression ();
5261 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
5262 even though %r19 is caller saved. I think this is a bug in
5263 the HP assembler, and we are not going to emulate it. */
5264 if (temp < 3 || temp > 18)
5265 as_bad (_("Value for ENTRY_GR must be in the range 3..18\n"));
5266 last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
5267 }
5268 else if ((strncasecmp (name, "entry_fr", 8) == 0))
5269 {
5270 p = input_line_pointer;
5271 *p = c;
5272 input_line_pointer++;
5273 temp = get_absolute_expression ();
5274 /* Similarly the HP assembler takes 31 as the high bound even
5275 though %fr21 is the last callee saved floating point register. */
5276 if (temp < 12 || temp > 21)
5277 as_bad (_("Value for ENTRY_FR must be in the range 12..21\n"));
5278 last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
5279 }
5280 else if ((strncasecmp (name, "entry_sr", 8) == 0))
5281 {
5282 p = input_line_pointer;
5283 *p = c;
5284 input_line_pointer++;
5285 temp = get_absolute_expression ();
5286 if (temp != 3)
5287 as_bad (_("Value for ENTRY_SR must be 3\n"));
5288 }
5289 /* Note whether or not this function performs any calls. */
5290 else if ((strncasecmp (name, "calls", 5) == 0) ||
5291 (strncasecmp (name, "caller", 6) == 0))
5292 {
5293 p = input_line_pointer;
5294 *p = c;
5295 }
5296 else if ((strncasecmp (name, "no_calls", 8) == 0))
5297 {
5298 p = input_line_pointer;
5299 *p = c;
5300 }
5301 /* Should RP be saved into the stack. */
5302 else if ((strncasecmp (name, "save_rp", 7) == 0))
5303 {
5304 p = input_line_pointer;
5305 *p = c;
5306 last_call_info->ci_unwind.descriptor.save_rp = 1;
5307 }
5308 /* Likewise for SP. */
5309 else if ((strncasecmp (name, "save_sp", 7) == 0))
5310 {
5311 p = input_line_pointer;
5312 *p = c;
5313 last_call_info->ci_unwind.descriptor.save_sp = 1;
5314 }
5315 /* Is this an unwindable procedure. If so mark it so
5316 in the unwind descriptor. */
5317 else if ((strncasecmp (name, "no_unwind", 9) == 0))
5318 {
5319 p = input_line_pointer;
5320 *p = c;
5321 last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
5322 }
5323 /* Is this an interrupt routine. If so mark it in the
5324 unwind descriptor. */
5325 else if ((strncasecmp (name, "hpux_int", 7) == 0))
5326 {
5327 p = input_line_pointer;
5328 *p = c;
5329 last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
5330 }
5331 /* Is this a millicode routine. "millicode" isn't in my
5332 assembler manual, but my copy is old. The HP assembler
5333 accepts it, and there's a place in the unwind descriptor
5334 to drop the information, so we'll accept it too. */
5335 else if ((strncasecmp (name, "millicode", 9) == 0))
5336 {
5337 p = input_line_pointer;
5338 *p = c;
5339 last_call_info->ci_unwind.descriptor.millicode = 1;
5340 }
5341 else
5342 {
5343 as_bad (_("Invalid .CALLINFO argument: %s"), name);
5344 *input_line_pointer = c;
5345 }
5346 if (!is_end_of_statement ())
5347 input_line_pointer++;
5348 }
5349
5350 demand_empty_rest_of_line ();
5351 }
5352
5353 /* Switch into the code subspace. */
5354
5355 static void
5356 pa_code (unused)
5357 int unused;
5358 {
5359 #ifdef OBJ_SOM
5360 current_space = is_defined_space ("$TEXT$");
5361 current_subspace
5362 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
5363 #endif
5364 s_text (0);
5365 pa_undefine_label ();
5366 }
5367
5368 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
5369 the .comm pseudo-op has the following symtax:
5370
5371 <label> .comm <length>
5372
5373 where <label> is optional and is a symbol whose address will be the start of
5374 a block of memory <length> bytes long. <length> must be an absolute
5375 expression. <length> bytes will be allocated in the current space
5376 and subspace.
5377
5378 Also note the label may not even be on the same line as the .comm.
5379
5380 This difference in syntax means the colon function will be called
5381 on the symbol before we arrive in pa_comm. colon will set a number
5382 of attributes of the symbol that need to be fixed here. In particular
5383 the value, section pointer, fragment pointer, flags, etc. What
5384 a pain.
5385
5386 This also makes error detection all but impossible. */
5387
5388 static void
5389 pa_comm (unused)
5390 int unused;
5391 {
5392 unsigned int size;
5393 symbolS *symbol;
5394 label_symbol_struct *label_symbol = pa_get_label ();
5395
5396 if (label_symbol)
5397 symbol = label_symbol->lss_label;
5398 else
5399 symbol = NULL;
5400
5401 SKIP_WHITESPACE ();
5402 size = get_absolute_expression ();
5403
5404 if (symbol)
5405 {
5406 S_SET_VALUE (symbol, size);
5407 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
5408 S_SET_EXTERNAL (symbol);
5409
5410 /* colon() has already set the frag to the current location in the
5411 current subspace; we need to reset the fragment to the zero address
5412 fragment. We also need to reset the segment pointer. */
5413 symbol_set_frag (symbol, &zero_address_frag);
5414 }
5415 demand_empty_rest_of_line ();
5416 }
5417
5418 /* Process a .END pseudo-op. */
5419
5420 static void
5421 pa_end (unused)
5422 int unused;
5423 {
5424 demand_empty_rest_of_line ();
5425 }
5426
5427 /* Process a .ENTER pseudo-op. This is not supported. */
5428 static void
5429 pa_enter (unused)
5430 int unused;
5431 {
5432 #ifdef OBJ_SOM
5433 /* We must have a valid space and subspace. */
5434 pa_check_current_space_and_subspace ();
5435 #endif
5436
5437 as_bad (_("The .ENTER pseudo-op is not supported"));
5438 demand_empty_rest_of_line ();
5439 }
5440
5441 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
5442 procesure. */
5443 static void
5444 pa_entry (unused)
5445 int unused;
5446 {
5447 #ifdef OBJ_SOM
5448 /* We must have a valid space and subspace. */
5449 pa_check_current_space_and_subspace ();
5450 #endif
5451
5452 if (!within_procedure)
5453 as_bad (_("Misplaced .entry. Ignored."));
5454 else
5455 {
5456 if (!callinfo_found)
5457 as_bad (_("Missing .callinfo."));
5458 }
5459 demand_empty_rest_of_line ();
5460 within_entry_exit = TRUE;
5461
5462 #ifdef OBJ_SOM
5463 /* SOM defers building of unwind descriptors until the link phase.
5464 The assembler is responsible for creating an R_ENTRY relocation
5465 to mark the beginning of a region and hold the unwind bits, and
5466 for creating an R_EXIT relocation to mark the end of the region.
5467
5468 FIXME. ELF should be using the same conventions! The problem
5469 is an unwind requires too much relocation space. Hmmm. Maybe
5470 if we split the unwind bits up between the relocations which
5471 denote the entry and exit points. */
5472 if (last_call_info->start_symbol != NULL)
5473 {
5474 char *where = frag_more (0);
5475
5476 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
5477 NULL, (offsetT) 0, NULL,
5478 0, R_HPPA_ENTRY, e_fsel, 0, 0,
5479 (int *) &last_call_info->ci_unwind.descriptor);
5480 }
5481 #endif
5482 }
5483
5484 /* Handle a .EQU pseudo-op. */
5485
5486 static void
5487 pa_equ (reg)
5488 int reg;
5489 {
5490 label_symbol_struct *label_symbol = pa_get_label ();
5491 symbolS *symbol;
5492
5493 if (label_symbol)
5494 {
5495 symbol = label_symbol->lss_label;
5496 if (reg)
5497 S_SET_VALUE (symbol, pa_parse_number (&input_line_pointer, 0));
5498 else
5499 S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ());
5500 S_SET_SEGMENT (symbol, bfd_abs_section_ptr);
5501 }
5502 else
5503 {
5504 if (reg)
5505 as_bad (_(".REG must use a label"));
5506 else
5507 as_bad (_(".EQU must use a label"));
5508 }
5509
5510 pa_undefine_label ();
5511 demand_empty_rest_of_line ();
5512 }
5513
5514 /* Helper function. Does processing for the end of a function. This
5515 usually involves creating some relocations or building special
5516 symbols to mark the end of the function. */
5517
5518 static void
5519 process_exit ()
5520 {
5521 char *where;
5522
5523 where = frag_more (0);
5524
5525 #ifdef OBJ_ELF
5526 /* Mark the end of the function, stuff away the location of the frag
5527 for the end of the function, and finally call pa_build_unwind_subspace
5528 to add an entry in the unwind table. */
5529 hppa_elf_mark_end_of_function ();
5530 pa_build_unwind_subspace (last_call_info);
5531 #else
5532 /* SOM defers building of unwind descriptors until the link phase.
5533 The assembler is responsible for creating an R_ENTRY relocation
5534 to mark the beginning of a region and hold the unwind bits, and
5535 for creating an R_EXIT relocation to mark the end of the region.
5536
5537 FIXME. ELF should be using the same conventions! The problem
5538 is an unwind requires too much relocation space. Hmmm. Maybe
5539 if we split the unwind bits up between the relocations which
5540 denote the entry and exit points. */
5541 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
5542 NULL, (offsetT) 0,
5543 NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0,
5544 (int *) &last_call_info->ci_unwind.descriptor + 1);
5545 #endif
5546 }
5547
5548 /* Process a .EXIT pseudo-op. */
5549
5550 static void
5551 pa_exit (unused)
5552 int unused;
5553 {
5554 #ifdef OBJ_SOM
5555 /* We must have a valid space and subspace. */
5556 pa_check_current_space_and_subspace ();
5557 #endif
5558
5559 if (!within_procedure)
5560 as_bad (_(".EXIT must appear within a procedure"));
5561 else
5562 {
5563 if (!callinfo_found)
5564 as_bad (_("Missing .callinfo"));
5565 else
5566 {
5567 if (!within_entry_exit)
5568 as_bad (_("No .ENTRY for this .EXIT"));
5569 else
5570 {
5571 within_entry_exit = FALSE;
5572 process_exit ();
5573 }
5574 }
5575 }
5576 demand_empty_rest_of_line ();
5577 }
5578
5579 /* Process a .EXPORT directive. This makes functions external
5580 and provides information such as argument relocation entries
5581 to callers. */
5582
5583 static void
5584 pa_export (unused)
5585 int unused;
5586 {
5587 char *name, c, *p;
5588 symbolS *symbol;
5589
5590 name = input_line_pointer;
5591 c = get_symbol_end ();
5592 /* Make sure the given symbol exists. */
5593 if ((symbol = symbol_find_or_make (name)) == NULL)
5594 {
5595 as_bad (_("Cannot define export symbol: %s\n"), name);
5596 p = input_line_pointer;
5597 *p = c;
5598 input_line_pointer++;
5599 }
5600 else
5601 {
5602 /* OK. Set the external bits and process argument relocations. */
5603 S_SET_EXTERNAL (symbol);
5604 p = input_line_pointer;
5605 *p = c;
5606 if (!is_end_of_statement ())
5607 {
5608 input_line_pointer++;
5609 pa_type_args (symbol, 1);
5610 }
5611 }
5612
5613 demand_empty_rest_of_line ();
5614 }
5615
5616 /* Helper function to process arguments to a .EXPORT pseudo-op. */
5617
5618 static void
5619 pa_type_args (symbolP, is_export)
5620 symbolS *symbolP;
5621 int is_export;
5622 {
5623 char *name, c, *p;
5624 unsigned int temp, arg_reloc;
5625 pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
5626 obj_symbol_type *symbol = (obj_symbol_type *) symbol_get_bfdsym (symbolP);
5627
5628 if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
5629
5630 {
5631 input_line_pointer += 8;
5632 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
5633 S_SET_SEGMENT (symbolP, bfd_abs_section_ptr);
5634 type = SYMBOL_TYPE_ABSOLUTE;
5635 }
5636 else if (strncasecmp (input_line_pointer, "code", 4) == 0)
5637 {
5638 input_line_pointer += 4;
5639 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
5640 instead one should be IMPORTing/EXPORTing ENTRY types.
5641
5642 Complain if one tries to EXPORT a CODE type since that's never
5643 done. Both GCC and HP C still try to IMPORT CODE types, so
5644 silently fix them to be ENTRY types. */
5645 if (S_IS_FUNCTION (symbolP))
5646 {
5647 if (is_export)
5648 as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"),
5649 S_GET_NAME (symbolP));
5650
5651 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
5652 type = SYMBOL_TYPE_ENTRY;
5653 }
5654 else
5655 {
5656 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
5657 type = SYMBOL_TYPE_CODE;
5658 }
5659 }
5660 else if (strncasecmp (input_line_pointer, "data", 4) == 0)
5661 {
5662 input_line_pointer += 4;
5663 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
5664 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
5665 type = SYMBOL_TYPE_DATA;
5666 }
5667 else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
5668 {
5669 input_line_pointer += 5;
5670 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
5671 type = SYMBOL_TYPE_ENTRY;
5672 }
5673 else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
5674 {
5675 input_line_pointer += 9;
5676 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
5677 type = SYMBOL_TYPE_MILLICODE;
5678 }
5679 else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
5680 {
5681 input_line_pointer += 6;
5682 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
5683 type = SYMBOL_TYPE_PLABEL;
5684 }
5685 else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
5686 {
5687 input_line_pointer += 8;
5688 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
5689 type = SYMBOL_TYPE_PRI_PROG;
5690 }
5691 else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
5692 {
5693 input_line_pointer += 8;
5694 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
5695 type = SYMBOL_TYPE_SEC_PROG;
5696 }
5697
5698 /* SOM requires much more information about symbol types
5699 than BFD understands. This is how we get this information
5700 to the SOM BFD backend. */
5701 #ifdef obj_set_symbol_type
5702 obj_set_symbol_type (symbol_get_bfdsym (symbolP), (int) type);
5703 #endif
5704
5705 /* Now that the type of the exported symbol has been handled,
5706 handle any argument relocation information. */
5707 while (!is_end_of_statement ())
5708 {
5709 if (*input_line_pointer == ',')
5710 input_line_pointer++;
5711 name = input_line_pointer;
5712 c = get_symbol_end ();
5713 /* Argument sources. */
5714 if ((strncasecmp (name, "argw", 4) == 0))
5715 {
5716 p = input_line_pointer;
5717 *p = c;
5718 input_line_pointer++;
5719 temp = atoi (name + 4);
5720 name = input_line_pointer;
5721 c = get_symbol_end ();
5722 arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
5723 #ifdef OBJ_SOM
5724 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
5725 #endif
5726 *input_line_pointer = c;
5727 }
5728 /* The return value. */
5729 else if ((strncasecmp (name, "rtnval", 6)) == 0)
5730 {
5731 p = input_line_pointer;
5732 *p = c;
5733 input_line_pointer++;
5734 name = input_line_pointer;
5735 c = get_symbol_end ();
5736 arg_reloc = pa_build_arg_reloc (name);
5737 #ifdef OBJ_SOM
5738 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
5739 #endif
5740 *input_line_pointer = c;
5741 }
5742 /* Privelege level. */
5743 else if ((strncasecmp (name, "priv_lev", 8)) == 0)
5744 {
5745 p = input_line_pointer;
5746 *p = c;
5747 input_line_pointer++;
5748 temp = atoi (input_line_pointer);
5749 #ifdef OBJ_SOM
5750 symbol->tc_data.ap.hppa_priv_level = temp;
5751 #endif
5752 c = get_symbol_end ();
5753 *input_line_pointer = c;
5754 }
5755 else
5756 {
5757 as_bad (_("Undefined .EXPORT/.IMPORT argument (ignored): %s"), name);
5758 p = input_line_pointer;
5759 *p = c;
5760 }
5761 if (!is_end_of_statement ())
5762 input_line_pointer++;
5763 }
5764 }
5765
5766 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
5767 assembly file must either be defined in the assembly file, or
5768 explicitly IMPORTED from another. */
5769
5770 static void
5771 pa_import (unused)
5772 int unused;
5773 {
5774 char *name, c, *p;
5775 symbolS *symbol;
5776
5777 name = input_line_pointer;
5778 c = get_symbol_end ();
5779
5780 symbol = symbol_find (name);
5781 /* Ugh. We might be importing a symbol defined earlier in the file,
5782 in which case all the code below will really screw things up
5783 (set the wrong segment, symbol flags & type, etc). */
5784 if (symbol == NULL || !S_IS_DEFINED (symbol))
5785 {
5786 symbol = symbol_find_or_make (name);
5787 p = input_line_pointer;
5788 *p = c;
5789
5790 if (!is_end_of_statement ())
5791 {
5792 input_line_pointer++;
5793 pa_type_args (symbol, 0);
5794 }
5795 else
5796 {
5797 /* Sigh. To be compatable with the HP assembler and to help
5798 poorly written assembly code, we assign a type based on
5799 the the current segment. Note only BSF_FUNCTION really
5800 matters, we do not need to set the full SYMBOL_TYPE_* info. */
5801 if (now_seg == text_section)
5802 symbol_get_bfdsym (symbol)->flags |= BSF_FUNCTION;
5803
5804 /* If the section is undefined, then the symbol is undefined
5805 Since this is an import, leave the section undefined. */
5806 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
5807 }
5808 }
5809 else
5810 {
5811 /* The symbol was already defined. Just eat everything up to
5812 the end of the current statement. */
5813 while (!is_end_of_statement ())
5814 input_line_pointer++;
5815 }
5816
5817 demand_empty_rest_of_line ();
5818 }
5819
5820 /* Handle a .LABEL pseudo-op. */
5821
5822 static void
5823 pa_label (unused)
5824 int unused;
5825 {
5826 char *name, c, *p;
5827
5828 name = input_line_pointer;
5829 c = get_symbol_end ();
5830
5831 if (strlen (name) > 0)
5832 {
5833 colon (name);
5834 p = input_line_pointer;
5835 *p = c;
5836 }
5837 else
5838 {
5839 as_warn (_("Missing label name on .LABEL"));
5840 }
5841
5842 if (!is_end_of_statement ())
5843 {
5844 as_warn (_("extra .LABEL arguments ignored."));
5845 ignore_rest_of_line ();
5846 }
5847 demand_empty_rest_of_line ();
5848 }
5849
5850 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
5851
5852 static void
5853 pa_leave (unused)
5854 int unused;
5855 {
5856 #ifdef OBJ_SOM
5857 /* We must have a valid space and subspace. */
5858 pa_check_current_space_and_subspace ();
5859 #endif
5860
5861 as_bad (_("The .LEAVE pseudo-op is not supported"));
5862 demand_empty_rest_of_line ();
5863 }
5864
5865 /* Handle a .LEVEL pseudo-op. */
5866
5867 static void
5868 pa_level (unused)
5869 int unused;
5870 {
5871 char *level;
5872
5873 level = input_line_pointer;
5874 if (strncmp (level, "1.0", 3) == 0)
5875 {
5876 input_line_pointer += 3;
5877 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
5878 as_warn (_("could not set architecture and machine"));
5879 }
5880 else if (strncmp (level, "1.1", 3) == 0)
5881 {
5882 input_line_pointer += 3;
5883 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11))
5884 as_warn (_("could not set architecture and machine"));
5885 }
5886 else if (strncmp (level, "2.0w", 4) == 0)
5887 {
5888 input_line_pointer += 4;
5889 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 25))
5890 as_warn (_("could not set architecture and machine"));
5891 }
5892 else if (strncmp (level, "2.0", 3) == 0)
5893 {
5894 input_line_pointer += 3;
5895 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 20))
5896 as_warn (_("could not set architecture and machine"));
5897 }
5898 else
5899 {
5900 as_bad (_("Unrecognized .LEVEL argument\n"));
5901 ignore_rest_of_line ();
5902 }
5903 demand_empty_rest_of_line ();
5904 }
5905
5906 /* Handle a .ORIGIN pseudo-op. */
5907
5908 static void
5909 pa_origin (unused)
5910 int unused;
5911 {
5912 #ifdef OBJ_SOM
5913 /* We must have a valid space and subspace. */
5914 pa_check_current_space_and_subspace ();
5915 #endif
5916
5917 s_org (0);
5918 pa_undefine_label ();
5919 }
5920
5921 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
5922 is for static functions. FIXME. Should share more code with .EXPORT. */
5923
5924 static void
5925 pa_param (unused)
5926 int unused;
5927 {
5928 char *name, c, *p;
5929 symbolS *symbol;
5930
5931 name = input_line_pointer;
5932 c = get_symbol_end ();
5933
5934 if ((symbol = symbol_find_or_make (name)) == NULL)
5935 {
5936 as_bad (_("Cannot define static symbol: %s\n"), name);
5937 p = input_line_pointer;
5938 *p = c;
5939 input_line_pointer++;
5940 }
5941 else
5942 {
5943 S_CLEAR_EXTERNAL (symbol);
5944 p = input_line_pointer;
5945 *p = c;
5946 if (!is_end_of_statement ())
5947 {
5948 input_line_pointer++;
5949 pa_type_args (symbol, 0);
5950 }
5951 }
5952
5953 demand_empty_rest_of_line ();
5954 }
5955
5956 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5957 of a procedure from a syntatical point of view. */
5958
5959 static void
5960 pa_proc (unused)
5961 int unused;
5962 {
5963 struct call_info *call_info;
5964
5965 #ifdef OBJ_SOM
5966 /* We must have a valid space and subspace. */
5967 pa_check_current_space_and_subspace ();
5968 #endif
5969
5970 if (within_procedure)
5971 as_fatal (_("Nested procedures"));
5972
5973 /* Reset global variables for new procedure. */
5974 callinfo_found = FALSE;
5975 within_procedure = TRUE;
5976
5977 /* Create another call_info structure. */
5978 call_info = (struct call_info *) xmalloc (sizeof (struct call_info));
5979
5980 if (!call_info)
5981 as_fatal (_("Cannot allocate unwind descriptor\n"));
5982
5983 memset (call_info, 0, sizeof (struct call_info));
5984
5985 call_info->ci_next = NULL;
5986
5987 if (call_info_root == NULL)
5988 {
5989 call_info_root = call_info;
5990 last_call_info = call_info;
5991 }
5992 else
5993 {
5994 last_call_info->ci_next = call_info;
5995 last_call_info = call_info;
5996 }
5997
5998 /* set up defaults on call_info structure */
5999
6000 call_info->ci_unwind.descriptor.cannot_unwind = 0;
6001 call_info->ci_unwind.descriptor.region_desc = 1;
6002 call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
6003
6004 /* If we got a .PROC pseudo-op, we know that the function is defined
6005 locally. Make sure it gets into the symbol table. */
6006 {
6007 label_symbol_struct *label_symbol = pa_get_label ();
6008
6009 if (label_symbol)
6010 {
6011 if (label_symbol->lss_label)
6012 {
6013 last_call_info->start_symbol = label_symbol->lss_label;
6014 symbol_get_bfdsym (label_symbol->lss_label)->flags |= BSF_FUNCTION;
6015 }
6016 else
6017 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
6018 }
6019 else
6020 last_call_info->start_symbol = NULL;
6021 }
6022
6023 demand_empty_rest_of_line ();
6024 }
6025
6026 /* Process the syntatical end of a procedure. Make sure all the
6027 appropriate pseudo-ops were found within the procedure. */
6028
6029 static void
6030 pa_procend (unused)
6031 int unused;
6032 {
6033
6034 #ifdef OBJ_SOM
6035 /* We must have a valid space and subspace. */
6036 pa_check_current_space_and_subspace ();
6037 #endif
6038
6039 /* If we are within a procedure definition, make sure we've
6040 defined a label for the procedure; handle case where the
6041 label was defined after the .PROC directive.
6042
6043 Note there's not need to diddle with the segment or fragment
6044 for the label symbol in this case. We have already switched
6045 into the new $CODE$ subspace at this point. */
6046 if (within_procedure && last_call_info->start_symbol == NULL)
6047 {
6048 label_symbol_struct *label_symbol = pa_get_label ();
6049
6050 if (label_symbol)
6051 {
6052 if (label_symbol->lss_label)
6053 {
6054 last_call_info->start_symbol = label_symbol->lss_label;
6055 symbol_get_bfdsym (label_symbol->lss_label)->flags
6056 |= BSF_FUNCTION;
6057 #ifdef OBJ_SOM
6058 /* Also handle allocation of a fixup to hold the unwind
6059 information when the label appears after the proc/procend. */
6060 if (within_entry_exit)
6061 {
6062 char *where = frag_more (0);
6063
6064 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
6065 NULL, (offsetT) 0, NULL,
6066 0, R_HPPA_ENTRY, e_fsel, 0, 0,
6067 (int *) &last_call_info->ci_unwind.descriptor);
6068 }
6069 #endif
6070 }
6071 else
6072 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
6073 }
6074 else
6075 as_bad (_("Missing function name for .PROC"));
6076 }
6077
6078 if (!within_procedure)
6079 as_bad (_("misplaced .procend"));
6080
6081 if (!callinfo_found)
6082 as_bad (_("Missing .callinfo for this procedure"));
6083
6084 if (within_entry_exit)
6085 as_bad (_("Missing .EXIT for a .ENTRY"));
6086
6087 #ifdef OBJ_ELF
6088 /* ELF needs to mark the end of each function so that it can compute
6089 the size of the function (apparently its needed in the symbol table). */
6090 hppa_elf_mark_end_of_function ();
6091 #endif
6092
6093 within_procedure = FALSE;
6094 demand_empty_rest_of_line ();
6095 pa_undefine_label ();
6096 }
6097
6098 /* If VALUE is an exact power of two between zero and 2^31, then
6099 return log2 (VALUE). Else return -1. */
6100
6101 static int
6102 log2 (value)
6103 int value;
6104 {
6105 int shift = 0;
6106
6107 while ((1 << shift) != value && shift < 32)
6108 shift++;
6109
6110 if (shift >= 32)
6111 return -1;
6112 else
6113 return shift;
6114 }
6115
6116
6117 #ifdef OBJ_SOM
6118 /* Check to make sure we have a valid space and subspace. */
6119
6120 static void
6121 pa_check_current_space_and_subspace ()
6122 {
6123 if (current_space == NULL)
6124 as_fatal (_("Not in a space.\n"));
6125
6126 if (current_subspace == NULL)
6127 as_fatal (_("Not in a subspace.\n"));
6128 }
6129
6130 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
6131 then create a new space entry to hold the information specified
6132 by the parameters to the .SPACE directive. */
6133
6134 static sd_chain_struct *
6135 pa_parse_space_stmt (space_name, create_flag)
6136 char *space_name;
6137 int create_flag;
6138 {
6139 char *name, *ptemp, c;
6140 char loadable, defined, private, sort;
6141 int spnum, temp;
6142 asection *seg = NULL;
6143 sd_chain_struct *space;
6144
6145 /* load default values */
6146 spnum = 0;
6147 sort = 0;
6148 loadable = TRUE;
6149 defined = TRUE;
6150 private = FALSE;
6151 if (strcmp (space_name, "$TEXT$") == 0)
6152 {
6153 seg = pa_def_spaces[0].segment;
6154 defined = pa_def_spaces[0].defined;
6155 private = pa_def_spaces[0].private;
6156 sort = pa_def_spaces[0].sort;
6157 spnum = pa_def_spaces[0].spnum;
6158 }
6159 else if (strcmp (space_name, "$PRIVATE$") == 0)
6160 {
6161 seg = pa_def_spaces[1].segment;
6162 defined = pa_def_spaces[1].defined;
6163 private = pa_def_spaces[1].private;
6164 sort = pa_def_spaces[1].sort;
6165 spnum = pa_def_spaces[1].spnum;
6166 }
6167
6168 if (!is_end_of_statement ())
6169 {
6170 print_errors = FALSE;
6171 ptemp = input_line_pointer + 1;
6172 /* First see if the space was specified as a number rather than
6173 as a name. According to the PA assembly manual the rest of
6174 the line should be ignored. */
6175 temp = pa_parse_number (&ptemp, 0);
6176 if (temp >= 0)
6177 {
6178 spnum = temp;
6179 input_line_pointer = ptemp;
6180 }
6181 else
6182 {
6183 while (!is_end_of_statement ())
6184 {
6185 input_line_pointer++;
6186 name = input_line_pointer;
6187 c = get_symbol_end ();
6188 if ((strncasecmp (name, "spnum", 5) == 0))
6189 {
6190 *input_line_pointer = c;
6191 input_line_pointer++;
6192 spnum = get_absolute_expression ();
6193 }
6194 else if ((strncasecmp (name, "sort", 4) == 0))
6195 {
6196 *input_line_pointer = c;
6197 input_line_pointer++;
6198 sort = get_absolute_expression ();
6199 }
6200 else if ((strncasecmp (name, "unloadable", 10) == 0))
6201 {
6202 *input_line_pointer = c;
6203 loadable = FALSE;
6204 }
6205 else if ((strncasecmp (name, "notdefined", 10) == 0))
6206 {
6207 *input_line_pointer = c;
6208 defined = FALSE;
6209 }
6210 else if ((strncasecmp (name, "private", 7) == 0))
6211 {
6212 *input_line_pointer = c;
6213 private = TRUE;
6214 }
6215 else
6216 {
6217 as_bad (_("Invalid .SPACE argument"));
6218 *input_line_pointer = c;
6219 if (!is_end_of_statement ())
6220 input_line_pointer++;
6221 }
6222 }
6223 }
6224 print_errors = TRUE;
6225 }
6226
6227 if (create_flag && seg == NULL)
6228 seg = subseg_new (space_name, 0);
6229
6230 /* If create_flag is nonzero, then create the new space with
6231 the attributes computed above. Else set the values in
6232 an already existing space -- this can only happen for
6233 the first occurence of a built-in space. */
6234 if (create_flag)
6235 space = create_new_space (space_name, spnum, loadable, defined,
6236 private, sort, seg, 1);
6237 else
6238 {
6239 space = is_defined_space (space_name);
6240 SPACE_SPNUM (space) = spnum;
6241 SPACE_DEFINED (space) = defined & 1;
6242 SPACE_USER_DEFINED (space) = 1;
6243 }
6244
6245 #ifdef obj_set_section_attributes
6246 obj_set_section_attributes (seg, defined, private, sort, spnum);
6247 #endif
6248
6249 return space;
6250 }
6251
6252 /* Handle a .SPACE pseudo-op; this switches the current space to the
6253 given space, creating the new space if necessary. */
6254
6255 static void
6256 pa_space (unused)
6257 int unused;
6258 {
6259 char *name, c, *space_name, *save_s;
6260 int temp;
6261 sd_chain_struct *sd_chain;
6262
6263 if (within_procedure)
6264 {
6265 as_bad (_("Can\'t change spaces within a procedure definition. Ignored"));
6266 ignore_rest_of_line ();
6267 }
6268 else
6269 {
6270 /* Check for some of the predefined spaces. FIXME: most of the code
6271 below is repeated several times, can we extract the common parts
6272 and place them into a subroutine or something similar? */
6273 /* FIXME Is this (and the next IF stmt) really right?
6274 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
6275 if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
6276 {
6277 input_line_pointer += 6;
6278 sd_chain = is_defined_space ("$TEXT$");
6279 if (sd_chain == NULL)
6280 sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
6281 else if (SPACE_USER_DEFINED (sd_chain) == 0)
6282 sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
6283
6284 current_space = sd_chain;
6285 subseg_set (text_section, sd_chain->sd_last_subseg);
6286 current_subspace
6287 = pa_subsegment_to_subspace (text_section,
6288 sd_chain->sd_last_subseg);
6289 demand_empty_rest_of_line ();
6290 return;
6291 }
6292 if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
6293 {
6294 input_line_pointer += 9;
6295 sd_chain = is_defined_space ("$PRIVATE$");
6296 if (sd_chain == NULL)
6297 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
6298 else if (SPACE_USER_DEFINED (sd_chain) == 0)
6299 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
6300
6301 current_space = sd_chain;
6302 subseg_set (data_section, sd_chain->sd_last_subseg);
6303 current_subspace
6304 = pa_subsegment_to_subspace (data_section,
6305 sd_chain->sd_last_subseg);
6306 demand_empty_rest_of_line ();
6307 return;
6308 }
6309 if (!strncasecmp (input_line_pointer,
6310 GDB_DEBUG_SPACE_NAME,
6311 strlen (GDB_DEBUG_SPACE_NAME)))
6312 {
6313 input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
6314 sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
6315 if (sd_chain == NULL)
6316 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
6317 else if (SPACE_USER_DEFINED (sd_chain) == 0)
6318 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
6319
6320 current_space = sd_chain;
6321
6322 {
6323 asection *gdb_section
6324 = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
6325
6326 subseg_set (gdb_section, sd_chain->sd_last_subseg);
6327 current_subspace
6328 = pa_subsegment_to_subspace (gdb_section,
6329 sd_chain->sd_last_subseg);
6330 }
6331 demand_empty_rest_of_line ();
6332 return;
6333 }
6334
6335 /* It could be a space specified by number. */
6336 print_errors = 0;
6337 save_s = input_line_pointer;
6338 if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0)
6339 {
6340 if ((sd_chain = pa_find_space_by_number (temp)))
6341 {
6342 current_space = sd_chain;
6343
6344 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
6345 current_subspace
6346 = pa_subsegment_to_subspace (sd_chain->sd_seg,
6347 sd_chain->sd_last_subseg);
6348 demand_empty_rest_of_line ();
6349 return;
6350 }
6351 }
6352
6353 /* Not a number, attempt to create a new space. */
6354 print_errors = 1;
6355 input_line_pointer = save_s;
6356 name = input_line_pointer;
6357 c = get_symbol_end ();
6358 space_name = xmalloc (strlen (name) + 1);
6359 strcpy (space_name, name);
6360 *input_line_pointer = c;
6361
6362 sd_chain = pa_parse_space_stmt (space_name, 1);
6363 current_space = sd_chain;
6364
6365 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
6366 current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
6367 sd_chain->sd_last_subseg);
6368 demand_empty_rest_of_line ();
6369 }
6370 }
6371
6372 /* Switch to a new space. (I think). FIXME. */
6373
6374 static void
6375 pa_spnum (unused)
6376 int unused;
6377 {
6378 char *name;
6379 char c;
6380 char *p;
6381 sd_chain_struct *space;
6382
6383 name = input_line_pointer;
6384 c = get_symbol_end ();
6385 space = is_defined_space (name);
6386 if (space)
6387 {
6388 p = frag_more (4);
6389 md_number_to_chars (p, SPACE_SPNUM (space), 4);
6390 }
6391 else
6392 as_warn (_("Undefined space: '%s' Assuming space number = 0."), name);
6393
6394 *input_line_pointer = c;
6395 demand_empty_rest_of_line ();
6396 }
6397
6398 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
6399 given subspace, creating the new subspace if necessary.
6400
6401 FIXME. Should mirror pa_space more closely, in particular how
6402 they're broken up into subroutines. */
6403
6404 static void
6405 pa_subspace (create_new)
6406 int create_new;
6407 {
6408 char *name, *ss_name, c;
6409 char loadable, code_only, common, dup_common, zero, sort;
6410 int i, access, space_index, alignment, quadrant, applicable, flags;
6411 sd_chain_struct *space;
6412 ssd_chain_struct *ssd;
6413 asection *section;
6414
6415 if (current_space == NULL)
6416 as_fatal (_("Must be in a space before changing or declaring subspaces.\n"));
6417
6418 if (within_procedure)
6419 {
6420 as_bad (_("Can\'t change subspaces within a procedure definition. Ignored"));
6421 ignore_rest_of_line ();
6422 }
6423 else
6424 {
6425 name = input_line_pointer;
6426 c = get_symbol_end ();
6427 ss_name = xmalloc (strlen (name) + 1);
6428 strcpy (ss_name, name);
6429 *input_line_pointer = c;
6430
6431 /* Load default values. */
6432 sort = 0;
6433 access = 0x7f;
6434 loadable = 1;
6435 common = 0;
6436 dup_common = 0;
6437 code_only = 0;
6438 zero = 0;
6439 space_index = ~0;
6440 alignment = 1;
6441 quadrant = 0;
6442
6443 space = current_space;
6444 if (create_new)
6445 ssd = NULL;
6446 else
6447 ssd = is_defined_subspace (ss_name);
6448 /* Allow user to override the builtin attributes of subspaces. But
6449 only allow the attributes to be changed once! */
6450 if (ssd && SUBSPACE_DEFINED (ssd))
6451 {
6452 subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
6453 current_subspace = ssd;
6454 if (!is_end_of_statement ())
6455 as_warn (_("Parameters of an existing subspace can\'t be modified"));
6456 demand_empty_rest_of_line ();
6457 return;
6458 }
6459 else
6460 {
6461 /* A new subspace. Load default values if it matches one of
6462 the builtin subspaces. */
6463 i = 0;
6464 while (pa_def_subspaces[i].name)
6465 {
6466 if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
6467 {
6468 loadable = pa_def_subspaces[i].loadable;
6469 common = pa_def_subspaces[i].common;
6470 dup_common = pa_def_subspaces[i].dup_common;
6471 code_only = pa_def_subspaces[i].code_only;
6472 zero = pa_def_subspaces[i].zero;
6473 space_index = pa_def_subspaces[i].space_index;
6474 alignment = pa_def_subspaces[i].alignment;
6475 quadrant = pa_def_subspaces[i].quadrant;
6476 access = pa_def_subspaces[i].access;
6477 sort = pa_def_subspaces[i].sort;
6478 break;
6479 }
6480 i++;
6481 }
6482 }
6483
6484 /* We should be working with a new subspace now. Fill in
6485 any information as specified by the user. */
6486 if (!is_end_of_statement ())
6487 {
6488 input_line_pointer++;
6489 while (!is_end_of_statement ())
6490 {
6491 name = input_line_pointer;
6492 c = get_symbol_end ();
6493 if ((strncasecmp (name, "quad", 4) == 0))
6494 {
6495 *input_line_pointer = c;
6496 input_line_pointer++;
6497 quadrant = get_absolute_expression ();
6498 }
6499 else if ((strncasecmp (name, "align", 5) == 0))
6500 {
6501 *input_line_pointer = c;
6502 input_line_pointer++;
6503 alignment = get_absolute_expression ();
6504 if (log2 (alignment) == -1)
6505 {
6506 as_bad (_("Alignment must be a power of 2"));
6507 alignment = 1;
6508 }
6509 }
6510 else if ((strncasecmp (name, "access", 6) == 0))
6511 {
6512 *input_line_pointer = c;
6513 input_line_pointer++;
6514 access = get_absolute_expression ();
6515 }
6516 else if ((strncasecmp (name, "sort", 4) == 0))
6517 {
6518 *input_line_pointer = c;
6519 input_line_pointer++;
6520 sort = get_absolute_expression ();
6521 }
6522 else if ((strncasecmp (name, "code_only", 9) == 0))
6523 {
6524 *input_line_pointer = c;
6525 code_only = 1;
6526 }
6527 else if ((strncasecmp (name, "unloadable", 10) == 0))
6528 {
6529 *input_line_pointer = c;
6530 loadable = 0;
6531 }
6532 else if ((strncasecmp (name, "common", 6) == 0))
6533 {
6534 *input_line_pointer = c;
6535 common = 1;
6536 }
6537 else if ((strncasecmp (name, "dup_comm", 8) == 0))
6538 {
6539 *input_line_pointer = c;
6540 dup_common = 1;
6541 }
6542 else if ((strncasecmp (name, "zero", 4) == 0))
6543 {
6544 *input_line_pointer = c;
6545 zero = 1;
6546 }
6547 else if ((strncasecmp (name, "first", 5) == 0))
6548 as_bad (_("FIRST not supported as a .SUBSPACE argument"));
6549 else
6550 as_bad (_("Invalid .SUBSPACE argument"));
6551 if (!is_end_of_statement ())
6552 input_line_pointer++;
6553 }
6554 }
6555
6556 /* Compute a reasonable set of BFD flags based on the information
6557 in the .subspace directive. */
6558 applicable = bfd_applicable_section_flags (stdoutput);
6559 flags = 0;
6560 if (loadable)
6561 flags |= (SEC_ALLOC | SEC_LOAD);
6562 if (code_only)
6563 flags |= SEC_CODE;
6564 if (common || dup_common)
6565 flags |= SEC_IS_COMMON;
6566
6567 flags |= SEC_RELOC | SEC_HAS_CONTENTS;
6568
6569 /* This is a zero-filled subspace (eg BSS). */
6570 if (zero)
6571 flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
6572
6573 applicable &= flags;
6574
6575 /* If this is an existing subspace, then we want to use the
6576 segment already associated with the subspace.
6577
6578 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
6579 lots of sections. It might be a problem in the PA ELF
6580 code, I do not know yet. For now avoid creating anything
6581 but the "standard" sections for ELF. */
6582 if (create_new)
6583 section = subseg_force_new (ss_name, 0);
6584 else if (ssd)
6585 section = ssd->ssd_seg;
6586 else
6587 section = subseg_new (ss_name, 0);
6588
6589 if (zero)
6590 seg_info (section)->bss = 1;
6591
6592 /* Now set the flags. */
6593 bfd_set_section_flags (stdoutput, section, applicable);
6594
6595 /* Record any alignment request for this section. */
6596 record_alignment (section, log2 (alignment));
6597
6598 /* Set the starting offset for this section. */
6599 bfd_set_section_vma (stdoutput, section,
6600 pa_subspace_start (space, quadrant));
6601
6602 /* Now that all the flags are set, update an existing subspace,
6603 or create a new one. */
6604 if (ssd)
6605
6606 current_subspace = update_subspace (space, ss_name, loadable,
6607 code_only, common, dup_common,
6608 sort, zero, access, space_index,
6609 alignment, quadrant,
6610 section);
6611 else
6612 current_subspace = create_new_subspace (space, ss_name, loadable,
6613 code_only, common,
6614 dup_common, zero, sort,
6615 access, space_index,
6616 alignment, quadrant, section);
6617
6618 demand_empty_rest_of_line ();
6619 current_subspace->ssd_seg = section;
6620 subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
6621 }
6622 SUBSPACE_DEFINED (current_subspace) = 1;
6623 }
6624
6625
6626 /* Create default space and subspace dictionaries. */
6627
6628 static void
6629 pa_spaces_begin ()
6630 {
6631 int i;
6632
6633 space_dict_root = NULL;
6634 space_dict_last = NULL;
6635
6636 i = 0;
6637 while (pa_def_spaces[i].name)
6638 {
6639 char *name;
6640
6641 /* Pick the right name to use for the new section. */
6642 name = pa_def_spaces[i].name;
6643
6644 pa_def_spaces[i].segment = subseg_new (name, 0);
6645 create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
6646 pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
6647 pa_def_spaces[i].private, pa_def_spaces[i].sort,
6648 pa_def_spaces[i].segment, 0);
6649 i++;
6650 }
6651
6652 i = 0;
6653 while (pa_def_subspaces[i].name)
6654 {
6655 char *name;
6656 int applicable, subsegment;
6657 asection *segment = NULL;
6658 sd_chain_struct *space;
6659
6660 /* Pick the right name for the new section and pick the right
6661 subsegment number. */
6662 name = pa_def_subspaces[i].name;
6663 subsegment = 0;
6664
6665 /* Create the new section. */
6666 segment = subseg_new (name, subsegment);
6667
6668
6669 /* For SOM we want to replace the standard .text, .data, and .bss
6670 sections with our own. We also want to set BFD flags for
6671 all the built-in subspaces. */
6672 if (!strcmp (pa_def_subspaces[i].name, "$CODE$"))
6673 {
6674 text_section = segment;
6675 applicable = bfd_applicable_section_flags (stdoutput);
6676 bfd_set_section_flags (stdoutput, segment,
6677 applicable & (SEC_ALLOC | SEC_LOAD
6678 | SEC_RELOC | SEC_CODE
6679 | SEC_READONLY
6680 | SEC_HAS_CONTENTS));
6681 }
6682 else if (!strcmp (pa_def_subspaces[i].name, "$DATA$"))
6683 {
6684 data_section = segment;
6685 applicable = bfd_applicable_section_flags (stdoutput);
6686 bfd_set_section_flags (stdoutput, segment,
6687 applicable & (SEC_ALLOC | SEC_LOAD
6688 | SEC_RELOC
6689 | SEC_HAS_CONTENTS));
6690
6691
6692 }
6693 else if (!strcmp (pa_def_subspaces[i].name, "$BSS$"))
6694 {
6695 bss_section = segment;
6696 applicable = bfd_applicable_section_flags (stdoutput);
6697 bfd_set_section_flags (stdoutput, segment,
6698 applicable & SEC_ALLOC);
6699 }
6700 else if (!strcmp (pa_def_subspaces[i].name, "$LIT$"))
6701 {
6702 applicable = bfd_applicable_section_flags (stdoutput);
6703 bfd_set_section_flags (stdoutput, segment,
6704 applicable & (SEC_ALLOC | SEC_LOAD
6705 | SEC_RELOC
6706 | SEC_READONLY
6707 | SEC_HAS_CONTENTS));
6708 }
6709 else if (!strcmp (pa_def_subspaces[i].name, "$MILLICODE$"))
6710 {
6711 applicable = bfd_applicable_section_flags (stdoutput);
6712 bfd_set_section_flags (stdoutput, segment,
6713 applicable & (SEC_ALLOC | SEC_LOAD
6714 | SEC_RELOC
6715 | SEC_READONLY
6716 | SEC_HAS_CONTENTS));
6717 }
6718 else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$"))
6719 {
6720 applicable = bfd_applicable_section_flags (stdoutput);
6721 bfd_set_section_flags (stdoutput, segment,
6722 applicable & (SEC_ALLOC | SEC_LOAD
6723 | SEC_RELOC
6724 | SEC_READONLY
6725 | SEC_HAS_CONTENTS));
6726 }
6727
6728 /* Find the space associated with this subspace. */
6729 space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
6730 def_space_index].segment);
6731 if (space == NULL)
6732 {
6733 as_fatal (_("Internal error: Unable to find containing space for %s."),
6734 pa_def_subspaces[i].name);
6735 }
6736
6737 create_new_subspace (space, name,
6738 pa_def_subspaces[i].loadable,
6739 pa_def_subspaces[i].code_only,
6740 pa_def_subspaces[i].common,
6741 pa_def_subspaces[i].dup_common,
6742 pa_def_subspaces[i].zero,
6743 pa_def_subspaces[i].sort,
6744 pa_def_subspaces[i].access,
6745 pa_def_subspaces[i].space_index,
6746 pa_def_subspaces[i].alignment,
6747 pa_def_subspaces[i].quadrant,
6748 segment);
6749 i++;
6750 }
6751 }
6752
6753
6754
6755 /* Create a new space NAME, with the appropriate flags as defined
6756 by the given parameters. */
6757
6758 static sd_chain_struct *
6759 create_new_space (name, spnum, loadable, defined, private,
6760 sort, seg, user_defined)
6761 char *name;
6762 int spnum;
6763 int loadable;
6764 int defined;
6765 int private;
6766 int sort;
6767 asection *seg;
6768 int user_defined;
6769 {
6770 sd_chain_struct *chain_entry;
6771
6772 chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct));
6773 if (!chain_entry)
6774 as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"),
6775 name);
6776
6777 SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
6778 strcpy (SPACE_NAME (chain_entry), name);
6779 SPACE_DEFINED (chain_entry) = defined;
6780 SPACE_USER_DEFINED (chain_entry) = user_defined;
6781 SPACE_SPNUM (chain_entry) = spnum;
6782
6783 chain_entry->sd_seg = seg;
6784 chain_entry->sd_last_subseg = -1;
6785 chain_entry->sd_subspaces = NULL;
6786 chain_entry->sd_next = NULL;
6787
6788 /* Find spot for the new space based on its sort key. */
6789 if (!space_dict_last)
6790 space_dict_last = chain_entry;
6791
6792 if (space_dict_root == NULL)
6793 space_dict_root = chain_entry;
6794 else
6795 {
6796 sd_chain_struct *chain_pointer;
6797 sd_chain_struct *prev_chain_pointer;
6798
6799 chain_pointer = space_dict_root;
6800 prev_chain_pointer = NULL;
6801
6802 while (chain_pointer)
6803 {
6804 prev_chain_pointer = chain_pointer;
6805 chain_pointer = chain_pointer->sd_next;
6806 }
6807
6808 /* At this point we've found the correct place to add the new
6809 entry. So add it and update the linked lists as appropriate. */
6810 if (prev_chain_pointer)
6811 {
6812 chain_entry->sd_next = chain_pointer;
6813 prev_chain_pointer->sd_next = chain_entry;
6814 }
6815 else
6816 {
6817 space_dict_root = chain_entry;
6818 chain_entry->sd_next = chain_pointer;
6819 }
6820
6821 if (chain_entry->sd_next == NULL)
6822 space_dict_last = chain_entry;
6823 }
6824
6825 /* This is here to catch predefined spaces which do not get
6826 modified by the user's input. Another call is found at
6827 the bottom of pa_parse_space_stmt to handle cases where
6828 the user modifies a predefined space. */
6829 #ifdef obj_set_section_attributes
6830 obj_set_section_attributes (seg, defined, private, sort, spnum);
6831 #endif
6832
6833 return chain_entry;
6834 }
6835
6836 /* Create a new subspace NAME, with the appropriate flags as defined
6837 by the given parameters.
6838
6839 Add the new subspace to the subspace dictionary chain in numerical
6840 order as defined by the SORT entries. */
6841
6842 static ssd_chain_struct *
6843 create_new_subspace (space, name, loadable, code_only, common,
6844 dup_common, is_zero, sort, access, space_index,
6845 alignment, quadrant, seg)
6846 sd_chain_struct *space;
6847 char *name;
6848 int loadable, code_only, common, dup_common, is_zero;
6849 int sort;
6850 int access;
6851 int space_index;
6852 int alignment;
6853 int quadrant;
6854 asection *seg;
6855 {
6856 ssd_chain_struct *chain_entry;
6857
6858 chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct));
6859 if (!chain_entry)
6860 as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name);
6861
6862 SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
6863 strcpy (SUBSPACE_NAME (chain_entry), name);
6864
6865 /* Initialize subspace_defined. When we hit a .subspace directive
6866 we'll set it to 1 which "locks-in" the subspace attributes. */
6867 SUBSPACE_DEFINED (chain_entry) = 0;
6868
6869 chain_entry->ssd_subseg = 0;
6870 chain_entry->ssd_seg = seg;
6871 chain_entry->ssd_next = NULL;
6872
6873 /* Find spot for the new subspace based on its sort key. */
6874 if (space->sd_subspaces == NULL)
6875 space->sd_subspaces = chain_entry;
6876 else
6877 {
6878 ssd_chain_struct *chain_pointer;
6879 ssd_chain_struct *prev_chain_pointer;
6880
6881 chain_pointer = space->sd_subspaces;
6882 prev_chain_pointer = NULL;
6883
6884 while (chain_pointer)
6885 {
6886 prev_chain_pointer = chain_pointer;
6887 chain_pointer = chain_pointer->ssd_next;
6888 }
6889
6890 /* Now we have somewhere to put the new entry. Insert it and update
6891 the links. */
6892 if (prev_chain_pointer)
6893 {
6894 chain_entry->ssd_next = chain_pointer;
6895 prev_chain_pointer->ssd_next = chain_entry;
6896 }
6897 else
6898 {
6899 space->sd_subspaces = chain_entry;
6900 chain_entry->ssd_next = chain_pointer;
6901 }
6902 }
6903
6904 #ifdef obj_set_subsection_attributes
6905 obj_set_subsection_attributes (seg, space->sd_seg, access,
6906 sort, quadrant);
6907 #endif
6908
6909 return chain_entry;
6910 }
6911
6912 /* Update the information for the given subspace based upon the
6913 various arguments. Return the modified subspace chain entry. */
6914
6915 static ssd_chain_struct *
6916 update_subspace (space, name, loadable, code_only, common, dup_common, sort,
6917 zero, access, space_index, alignment, quadrant, section)
6918 sd_chain_struct *space;
6919 char *name;
6920 int loadable;
6921 int code_only;
6922 int common;
6923 int dup_common;
6924 int zero;
6925 int sort;
6926 int access;
6927 int space_index;
6928 int alignment;
6929 int quadrant;
6930 asection *section;
6931 {
6932 ssd_chain_struct *chain_entry;
6933
6934 chain_entry = is_defined_subspace (name);
6935
6936 #ifdef obj_set_subsection_attributes
6937 obj_set_subsection_attributes (section, space->sd_seg, access,
6938 sort, quadrant);
6939 #endif
6940
6941 return chain_entry;
6942 }
6943
6944 /* Return the space chain entry for the space with the name NAME or
6945 NULL if no such space exists. */
6946
6947 static sd_chain_struct *
6948 is_defined_space (name)
6949 char *name;
6950 {
6951 sd_chain_struct *chain_pointer;
6952
6953 for (chain_pointer = space_dict_root;
6954 chain_pointer;
6955 chain_pointer = chain_pointer->sd_next)
6956 {
6957 if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
6958 return chain_pointer;
6959 }
6960
6961 /* No mapping from segment to space was found. Return NULL. */
6962 return NULL;
6963 }
6964
6965 /* Find and return the space associated with the given seg. If no mapping
6966 from the given seg to a space is found, then return NULL.
6967
6968 Unlike subspaces, the number of spaces is not expected to grow much,
6969 so a linear exhaustive search is OK here. */
6970
6971 static sd_chain_struct *
6972 pa_segment_to_space (seg)
6973 asection *seg;
6974 {
6975 sd_chain_struct *space_chain;
6976
6977 /* Walk through each space looking for the correct mapping. */
6978 for (space_chain = space_dict_root;
6979 space_chain;
6980 space_chain = space_chain->sd_next)
6981 {
6982 if (space_chain->sd_seg == seg)
6983 return space_chain;
6984 }
6985
6986 /* Mapping was not found. Return NULL. */
6987 return NULL;
6988 }
6989
6990 /* Return the space chain entry for the subspace with the name NAME or
6991 NULL if no such subspace exists.
6992
6993 Uses a linear search through all the spaces and subspaces, this may
6994 not be appropriate if we ever being placing each function in its
6995 own subspace. */
6996
6997 static ssd_chain_struct *
6998 is_defined_subspace (name)
6999 char *name;
7000 {
7001 sd_chain_struct *space_chain;
7002 ssd_chain_struct *subspace_chain;
7003
7004 /* Walk through each space. */
7005 for (space_chain = space_dict_root;
7006 space_chain;
7007 space_chain = space_chain->sd_next)
7008 {
7009 /* Walk through each subspace looking for a name which matches. */
7010 for (subspace_chain = space_chain->sd_subspaces;
7011 subspace_chain;
7012 subspace_chain = subspace_chain->ssd_next)
7013 if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
7014 return subspace_chain;
7015 }
7016
7017 /* Subspace wasn't found. Return NULL. */
7018 return NULL;
7019 }
7020
7021 /* Find and return the subspace associated with the given seg. If no
7022 mapping from the given seg to a subspace is found, then return NULL.
7023
7024 If we ever put each procedure/function within its own subspace
7025 (to make life easier on the compiler and linker), then this will have
7026 to become more efficient. */
7027
7028 static ssd_chain_struct *
7029 pa_subsegment_to_subspace (seg, subseg)
7030 asection *seg;
7031 subsegT subseg;
7032 {
7033 sd_chain_struct *space_chain;
7034 ssd_chain_struct *subspace_chain;
7035
7036 /* Walk through each space. */
7037 for (space_chain = space_dict_root;
7038 space_chain;
7039 space_chain = space_chain->sd_next)
7040 {
7041 if (space_chain->sd_seg == seg)
7042 {
7043 /* Walk through each subspace within each space looking for
7044 the correct mapping. */
7045 for (subspace_chain = space_chain->sd_subspaces;
7046 subspace_chain;
7047 subspace_chain = subspace_chain->ssd_next)
7048 if (subspace_chain->ssd_subseg == (int) subseg)
7049 return subspace_chain;
7050 }
7051 }
7052
7053 /* No mapping from subsegment to subspace found. Return NULL. */
7054 return NULL;
7055 }
7056
7057 /* Given a number, try and find a space with the name number.
7058
7059 Return a pointer to a space dictionary chain entry for the space
7060 that was found or NULL on failure. */
7061
7062 static sd_chain_struct *
7063 pa_find_space_by_number (number)
7064 int number;
7065 {
7066 sd_chain_struct *space_chain;
7067
7068 for (space_chain = space_dict_root;
7069 space_chain;
7070 space_chain = space_chain->sd_next)
7071 {
7072 if (SPACE_SPNUM (space_chain) == (unsigned int) number)
7073 return space_chain;
7074 }
7075
7076 /* No appropriate space found. Return NULL. */
7077 return NULL;
7078 }
7079
7080 /* Return the starting address for the given subspace. If the starting
7081 address is unknown then return zero. */
7082
7083 static unsigned int
7084 pa_subspace_start (space, quadrant)
7085 sd_chain_struct *space;
7086 int quadrant;
7087 {
7088 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
7089 is not correct for the PA OSF1 port. */
7090 if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
7091 return 0x40000000;
7092 else if (space->sd_seg == data_section && quadrant == 1)
7093 return 0x40000000;
7094 else
7095 return 0;
7096 return 0;
7097 }
7098
7099 /* FIXME. Needs documentation. */
7100 static int
7101 pa_next_subseg (space)
7102 sd_chain_struct *space;
7103 {
7104
7105 space->sd_last_subseg++;
7106 return space->sd_last_subseg;
7107 }
7108 #endif
7109
7110 /* Helper function for pa_stringer. Used to find the end of
7111 a string. */
7112
7113 static unsigned int
7114 pa_stringer_aux (s)
7115 char *s;
7116 {
7117 unsigned int c = *s & CHAR_MASK;
7118
7119 #ifdef OBJ_SOM
7120 /* We must have a valid space and subspace. */
7121 pa_check_current_space_and_subspace ();
7122 #endif
7123
7124 switch (c)
7125 {
7126 case '\"':
7127 c = NOT_A_CHAR;
7128 break;
7129 default:
7130 break;
7131 }
7132 return c;
7133 }
7134
7135 /* Handle a .STRING type pseudo-op. */
7136
7137 static void
7138 pa_stringer (append_zero)
7139 int append_zero;
7140 {
7141 char *s, num_buf[4];
7142 unsigned int c;
7143 int i;
7144
7145 /* Preprocess the string to handle PA-specific escape sequences.
7146 For example, \xDD where DD is a hexidecimal number should be
7147 changed to \OOO where OOO is an octal number. */
7148
7149 /* Skip the opening quote. */
7150 s = input_line_pointer + 1;
7151
7152 while (is_a_char (c = pa_stringer_aux (s++)))
7153 {
7154 if (c == '\\')
7155 {
7156 c = *s;
7157 switch (c)
7158 {
7159 /* Handle \x<num>. */
7160 case 'x':
7161 {
7162 unsigned int number;
7163 int num_digit;
7164 char dg;
7165 char *s_start = s;
7166
7167 /* Get pas the 'x'. */
7168 s++;
7169 for (num_digit = 0, number = 0, dg = *s;
7170 num_digit < 2
7171 && (isdigit (dg) || (dg >= 'a' && dg <= 'f')
7172 || (dg >= 'A' && dg <= 'F'));
7173 num_digit++)
7174 {
7175 if (isdigit (dg))
7176 number = number * 16 + dg - '0';
7177 else if (dg >= 'a' && dg <= 'f')
7178 number = number * 16 + dg - 'a' + 10;
7179 else
7180 number = number * 16 + dg - 'A' + 10;
7181
7182 s++;
7183 dg = *s;
7184 }
7185 if (num_digit > 0)
7186 {
7187 switch (num_digit)
7188 {
7189 case 1:
7190 sprintf (num_buf, "%02o", number);
7191 break;
7192 case 2:
7193 sprintf (num_buf, "%03o", number);
7194 break;
7195 }
7196 for (i = 0; i <= num_digit; i++)
7197 s_start[i] = num_buf[i];
7198 }
7199 break;
7200 }
7201 /* This might be a "\"", skip over the escaped char. */
7202 default:
7203 s++;
7204 break;
7205 }
7206 }
7207 }
7208 stringer (append_zero);
7209 pa_undefine_label ();
7210 }
7211
7212 /* Handle a .VERSION pseudo-op. */
7213
7214 static void
7215 pa_version (unused)
7216 int unused;
7217 {
7218 obj_version (0);
7219 pa_undefine_label ();
7220 }
7221
7222 #ifdef OBJ_SOM
7223
7224 /* Handle a .COMPILER pseudo-op. */
7225
7226 static void
7227 pa_compiler (unused)
7228 int unused;
7229 {
7230 obj_som_compiler (0);
7231 pa_undefine_label ();
7232 }
7233
7234 #endif
7235
7236 /* Handle a .COPYRIGHT pseudo-op. */
7237
7238 static void
7239 pa_copyright (unused)
7240 int unused;
7241 {
7242 obj_copyright (0);
7243 pa_undefine_label ();
7244 }
7245
7246 /* Just like a normal cons, but when finished we have to undefine
7247 the latest space label. */
7248
7249 static void
7250 pa_cons (nbytes)
7251 int nbytes;
7252 {
7253 cons (nbytes);
7254 pa_undefine_label ();
7255 }
7256
7257 /* Switch to the data space. As usual delete our label. */
7258
7259 static void
7260 pa_data (unused)
7261 int unused;
7262 {
7263 #ifdef OBJ_SOM
7264 current_space = is_defined_space ("$PRIVATE$");
7265 current_subspace
7266 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
7267 #endif
7268 s_data (0);
7269 pa_undefine_label ();
7270 }
7271
7272 /* Like float_cons, but we need to undefine our label. */
7273
7274 static void
7275 pa_float_cons (float_type)
7276 int float_type;
7277 {
7278 float_cons (float_type);
7279 pa_undefine_label ();
7280 }
7281
7282 /* Like s_fill, but delete our label when finished. */
7283
7284 static void
7285 pa_fill (unused)
7286 int unused;
7287 {
7288 #ifdef OBJ_SOM
7289 /* We must have a valid space and subspace. */
7290 pa_check_current_space_and_subspace ();
7291 #endif
7292
7293 s_fill (0);
7294 pa_undefine_label ();
7295 }
7296
7297 /* Like lcomm, but delete our label when finished. */
7298
7299 static void
7300 pa_lcomm (needs_align)
7301 int needs_align;
7302 {
7303 #ifdef OBJ_SOM
7304 /* We must have a valid space and subspace. */
7305 pa_check_current_space_and_subspace ();
7306 #endif
7307
7308 s_lcomm (needs_align);
7309 pa_undefine_label ();
7310 }
7311
7312 /* Like lsym, but delete our label when finished. */
7313
7314 static void
7315 pa_lsym (unused)
7316 int unused;
7317 {
7318 #ifdef OBJ_SOM
7319 /* We must have a valid space and subspace. */
7320 pa_check_current_space_and_subspace ();
7321 #endif
7322
7323 s_lsym (0);
7324 pa_undefine_label ();
7325 }
7326
7327 /* Switch to the text space. Like s_text, but delete our
7328 label when finished. */
7329 static void
7330 pa_text (unused)
7331 int unused;
7332 {
7333 #ifdef OBJ_SOM
7334 current_space = is_defined_space ("$TEXT$");
7335 current_subspace
7336 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
7337 #endif
7338
7339 s_text (0);
7340 pa_undefine_label ();
7341 }
7342
7343 /* On the PA relocations which involve function symbols must not be
7344 adjusted. This so that the linker can know when/how to create argument
7345 relocation stubs for indirect calls and calls to static functions.
7346
7347 "T" field selectors create DLT relative fixups for accessing
7348 globals and statics in PIC code; each DLT relative fixup creates
7349 an entry in the DLT table. The entries contain the address of
7350 the final target (eg accessing "foo" would create a DLT entry
7351 with the address of "foo").
7352
7353 Unfortunately, the HP linker doesn't take into account any addend
7354 when generating the DLT; so accessing $LIT$+8 puts the address of
7355 $LIT$ into the DLT rather than the address of $LIT$+8.
7356
7357 The end result is we can't perform relocation symbol reductions for
7358 any fixup which creates entries in the DLT (eg they use "T" field
7359 selectors).
7360
7361 Reject reductions involving symbols with external scope; such
7362 reductions make life a living hell for object file editors.
7363
7364 FIXME. Also reject R_HPPA relocations which are 32bits wide in
7365 the code space. The SOM BFD backend doesn't know how to pull the
7366 right bits out of an instruction. */
7367
7368 int
7369 hppa_fix_adjustable (fixp)
7370 fixS *fixp;
7371 {
7372 struct hppa_fix_struct *hppa_fix;
7373
7374 hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data;
7375
7376 #ifdef OBJ_SOM
7377 /* Reject reductions of symbols in 32bit relocs. */
7378 if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32)
7379 return 0;
7380
7381 /* Reject reductions of symbols in sym1-sym2 expressions when
7382 the fixup will occur in a CODE subspace.
7383
7384 XXX FIXME: Long term we probably want to reject all of these;
7385 for example reducing in the debug section would lose if we ever
7386 supported using the optimizing hp linker. */
7387 if (fixp->fx_addsy
7388 && fixp->fx_subsy
7389 && (hppa_fix->segment->flags & SEC_CODE))
7390 {
7391 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
7392 symbol_mark_used_in_reloc (fixp->fx_subsy);
7393 return 0;
7394 }
7395
7396 /* We can't adjust any relocs that use LR% and RR% field selectors.
7397 That confuses the HP linker. */
7398 if (hppa_fix->fx_r_field == e_lrsel
7399 || hppa_fix->fx_r_field == e_rrsel
7400 || hppa_fix->fx_r_field == e_nlrsel)
7401 return 0;
7402 #endif
7403
7404 /* Reject reductions of symbols in DLT relative relocs,
7405 relocations with plabels. */
7406 if (hppa_fix->fx_r_field == e_tsel
7407 || hppa_fix->fx_r_field == e_ltsel
7408 || hppa_fix->fx_r_field == e_rtsel
7409 || hppa_fix->fx_r_field == e_psel
7410 || hppa_fix->fx_r_field == e_rpsel
7411 || hppa_fix->fx_r_field == e_lpsel)
7412 return 0;
7413
7414 if (fixp->fx_addsy && S_IS_EXTERNAL (fixp->fx_addsy))
7415 return 0;
7416
7417 /* Reject absolute calls (jumps). */
7418 if (hppa_fix->fx_r_type == R_HPPA_ABS_CALL)
7419 return 0;
7420
7421 /* Reject reductions of function symbols. */
7422 if (fixp->fx_addsy == 0 || ! S_IS_FUNCTION (fixp->fx_addsy))
7423 return 1;
7424
7425 return 0;
7426 }
7427
7428 /* Return nonzero if the fixup in FIXP will require a relocation,
7429 even it if appears that the fixup could be completely handled
7430 within GAS. */
7431
7432 int
7433 hppa_force_relocation (fixp)
7434 fixS *fixp;
7435 {
7436 struct hppa_fix_struct *hppa_fixp;
7437 int distance;
7438
7439 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
7440 #ifdef OBJ_SOM
7441 if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT
7442 || fixp->fx_r_type == R_HPPA_BEGIN_BRTAB
7443 || fixp->fx_r_type == R_HPPA_END_BRTAB
7444 || fixp->fx_r_type == R_HPPA_BEGIN_TRY
7445 || fixp->fx_r_type == R_HPPA_END_TRY
7446 || (fixp->fx_addsy != NULL && fixp->fx_subsy != NULL
7447 && (hppa_fixp->segment->flags & SEC_CODE) != 0))
7448 return 1;
7449 #endif
7450
7451 #define arg_reloc_stub_needed(CALLER, CALLEE) \
7452 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
7453
7454 #ifdef OBJ_SOM
7455 /* It is necessary to force PC-relative calls/jumps to have a relocation
7456 entry if they're going to need either a argument relocation or long
7457 call stub. FIXME. Can't we need the same for absolute calls? */
7458 if (fixp->fx_pcrel && fixp->fx_addsy
7459 && (arg_reloc_stub_needed ((long) ((obj_symbol_type *)
7460 symbol_get_bfdsym (fixp->fx_addsy))->tc_data.ap.hppa_arg_reloc,
7461 hppa_fixp->fx_arg_reloc)))
7462 return 1;
7463 #endif
7464 distance = (fixp->fx_offset + S_GET_VALUE (fixp->fx_addsy)
7465 - md_pcrel_from (fixp));
7466 /* Now check and see if we're going to need a long-branch stub. */
7467 if (fixp->fx_r_type == R_HPPA_PCREL_CALL
7468 && (distance > 262143 || distance < -262144))
7469 return 1;
7470
7471 if (fixp->fx_r_type == R_HPPA_ABS_CALL)
7472 return 1;
7473 #undef arg_reloc_stub_needed
7474
7475 /* No need (yet) to force another relocations to be emitted. */
7476 return 0;
7477 }
7478
7479 /* Now for some ELF specific code. FIXME. */
7480 #ifdef OBJ_ELF
7481 /* Mark the end of a function so that it's possible to compute
7482 the size of the function in hppa_elf_final_processing. */
7483
7484 static void
7485 hppa_elf_mark_end_of_function ()
7486 {
7487 /* ELF does not have EXIT relocations. All we do is create a
7488 temporary symbol marking the end of the function. */
7489 char *name = (char *)
7490 xmalloc (strlen ("L$\001end_") +
7491 strlen (S_GET_NAME (last_call_info->start_symbol)) + 1);
7492
7493 if (name)
7494 {
7495 symbolS *symbolP;
7496
7497 strcpy (name, "L$\001end_");
7498 strcat (name, S_GET_NAME (last_call_info->start_symbol));
7499
7500 /* If we have a .exit followed by a .procend, then the
7501 symbol will have already been defined. */
7502 symbolP = symbol_find (name);
7503 if (symbolP)
7504 {
7505 /* The symbol has already been defined! This can
7506 happen if we have a .exit followed by a .procend.
7507
7508 This is *not* an error. All we want to do is free
7509 the memory we just allocated for the name and continue. */
7510 xfree (name);
7511 }
7512 else
7513 {
7514 /* symbol value should be the offset of the
7515 last instruction of the function */
7516 symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
7517 frag_now);
7518
7519 assert (symbolP);
7520 S_CLEAR_EXTERNAL (symbolP);
7521 symbol_table_insert (symbolP);
7522 }
7523
7524 if (symbolP)
7525 last_call_info->end_symbol = symbolP;
7526 else
7527 as_bad (_("Symbol '%s' could not be created."), name);
7528
7529 }
7530 else
7531 as_bad (_("No memory for symbol name."));
7532
7533 }
7534
7535 /* For ELF, this function serves one purpose: to setup the st_size
7536 field of STT_FUNC symbols. To do this, we need to scan the
7537 call_info structure list, determining st_size in by taking the
7538 difference in the address of the beginning/end marker symbols. */
7539
7540 void
7541 elf_hppa_final_processing ()
7542 {
7543 struct call_info *call_info_pointer;
7544
7545 for (call_info_pointer = call_info_root;
7546 call_info_pointer;
7547 call_info_pointer = call_info_pointer->ci_next)
7548 {
7549 elf_symbol_type *esym
7550 = ((elf_symbol_type *)
7551 symbol_get_bfdsym (call_info_pointer->start_symbol));
7552 esym->internal_elf_sym.st_size =
7553 S_GET_VALUE (call_info_pointer->end_symbol)
7554 - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
7555 }
7556 }
7557 #endif
7558
7559 #ifdef OBJ_ELF
7560 pa_end_of_source ()
7561 {
7562 if (debug_type == DEBUG_DWARF2)
7563 dwarf2_finish ();
7564 }
7565 #endif
This page took 0.245805 seconds and 5 git commands to generate.