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