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