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