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