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