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