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