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