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