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