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