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