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