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