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