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