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