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