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