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