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