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