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