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