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