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