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