]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-hppa.c
In the right ChangeLog now:
[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
KR
2017
2018 /* Handle a 11 bit immediate at 31. */
2019 case 'i':
2020 the_insn.field_selector = pa_chk_field_selector (&s);
2021 get_expression (s);
48153d49 2022 s = expr_end;
5cf4cd1b 2023 if (the_insn.exp.X_op == O_constant)
025b0302 2024 {
48153d49
JL
2025 num = evaluate_absolute (&the_insn);
2026 CHECK_FIELD (num, 1023, -1024, 0);
2027 low_sign_unext (num, 11, &num);
2028 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
025b0302
ME
2029 }
2030 else
2031 {
025b0302
ME
2032 if (is_DP_relative (the_insn.exp))
2033 the_insn.reloc = R_HPPA_GOTOFF;
2034 else if (is_PC_relative (the_insn.exp))
2035 the_insn.reloc = R_HPPA_PCREL_CALL;
2036 else if (is_complex (the_insn.exp))
2037 the_insn.reloc = R_HPPA_COMPLEX;
2038 else
2039 the_insn.reloc = R_HPPA;
2040 the_insn.format = 11;
48153d49 2041 continue;
025b0302 2042 }
8f78d0e9
KR
2043
2044 /* Handle a 14 bit immediate at 31. */
2045 case 'j':
025b0302 2046 the_insn.field_selector = pa_chk_field_selector (&s);
8f78d0e9 2047 get_expression (s);
48153d49 2048 s = expr_end;
5cf4cd1b 2049 if (the_insn.exp.X_op == O_constant)
025b0302 2050 {
48153d49
JL
2051 num = evaluate_absolute (&the_insn);
2052 CHECK_FIELD (num, 8191, -8192, 0);
2053 low_sign_unext (num, 14, &num);
2054 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
025b0302
ME
2055 }
2056 else
2057 {
2058 if (is_DP_relative (the_insn.exp))
2059 the_insn.reloc = R_HPPA_GOTOFF;
2060 else if (is_PC_relative (the_insn.exp))
2061 the_insn.reloc = R_HPPA_PCREL_CALL;
2062 else if (is_complex (the_insn.exp))
2063 the_insn.reloc = R_HPPA_COMPLEX;
2064 else
2065 the_insn.reloc = R_HPPA;
2066 the_insn.format = 14;
48153d49 2067 continue;
025b0302 2068 }
025b0302 2069
8f78d0e9
KR
2070 /* Handle a 21 bit immediate at 31. */
2071 case 'k':
2072 the_insn.field_selector = pa_chk_field_selector (&s);
2073 get_expression (s);
48153d49 2074 s = expr_end;
5cf4cd1b 2075 if (the_insn.exp.X_op == O_constant)
025b0302 2076 {
48153d49 2077 num = evaluate_absolute (&the_insn);
c5e9ccd0 2078 CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
48153d49
JL
2079 dis_assemble_21 (num, &num);
2080 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
025b0302
ME
2081 }
2082 else
2083 {
025b0302
ME
2084 if (is_DP_relative (the_insn.exp))
2085 the_insn.reloc = R_HPPA_GOTOFF;
2086 else if (is_PC_relative (the_insn.exp))
2087 the_insn.reloc = R_HPPA_PCREL_CALL;
2088 else if (is_complex (the_insn.exp))
2089 the_insn.reloc = R_HPPA_COMPLEX;
2090 else
2091 the_insn.reloc = R_HPPA;
2092 the_insn.format = 21;
48153d49 2093 continue;
025b0302 2094 }
8f78d0e9
KR
2095
2096 /* Handle a 12 bit branch displacement. */
2097 case 'w':
2098 the_insn.field_selector = pa_chk_field_selector (&s);
2099 get_expression (s);
48153d49 2100 s = expr_end;
025b0302 2101 the_insn.pcrel = 1;
48153d49 2102 if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001"))
025b0302
ME
2103 {
2104 unsigned int w1, w, result;
2105
48153d49
JL
2106 num = evaluate_absolute (&the_insn);
2107 if (num % 4)
2108 {
2109 as_bad ("Branch to unaligned address");
2110 break;
2111 }
2112 CHECK_FIELD (num, 8191, -8192, 0);
2113 sign_unext ((num - 8) >> 2, 12, &result);
025b0302 2114 dis_assemble_12 (result, &w1, &w);
48153d49 2115 INSERT_FIELD_AND_CONTINUE (opcode, ((w1 << 2) | w), 0);
025b0302
ME
2116 }
2117 else
2118 {
025b0302
ME
2119 if (is_complex (the_insn.exp))
2120 the_insn.reloc = R_HPPA_COMPLEX_PCREL_CALL;
2121 else
2122 the_insn.reloc = R_HPPA_PCREL_CALL;
2123 the_insn.format = 12;
2124 the_insn.arg_reloc = last_call_desc.arg_reloc;
8f78d0e9 2125 bzero (&last_call_desc, sizeof (struct call_desc));
48153d49
JL
2126 s = expr_end;
2127 continue;
025b0302 2128 }
8f78d0e9
KR
2129
2130 /* Handle a 17 bit branch displacement. */
2131 case 'W':
025b0302 2132 the_insn.field_selector = pa_chk_field_selector (&s);
8f78d0e9 2133 get_expression (s);
48153d49 2134 s = expr_end;
025b0302 2135 the_insn.pcrel = 1;
c5e9ccd0 2136 if (!the_insn.exp.X_add_symbol
48153d49
JL
2137 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2138 "L$0\001"))
025b0302 2139 {
48153d49 2140 unsigned int w2, w1, w, result;
025b0302 2141
48153d49
JL
2142 num = evaluate_absolute (&the_insn);
2143 if (num % 4)
025b0302 2144 {
48153d49
JL
2145 as_bad ("Branch to unaligned address");
2146 break;
025b0302 2147 }
48153d49
JL
2148 CHECK_FIELD (num, 262143, -262144, 0);
2149
2150 if (the_insn.exp.X_add_symbol)
2151 num -= 8;
2152
2153 sign_unext (num >> 2, 17, &result);
2154 dis_assemble_17 (result, &w1, &w2, &w);
2155 INSERT_FIELD_AND_CONTINUE (opcode,
c5e9ccd0 2156 ((w2 << 2) | (w1 << 16) | w), 0);
025b0302
ME
2157 }
2158 else
2159 {
48153d49
JL
2160 if (is_complex (the_insn.exp))
2161 the_insn.reloc = R_HPPA_COMPLEX_PCREL_CALL;
2162 else
2163 the_insn.reloc = R_HPPA_PCREL_CALL;
2164 the_insn.format = 17;
2165 the_insn.arg_reloc = last_call_desc.arg_reloc;
2166 bzero (&last_call_desc, sizeof (struct call_desc));
2167 continue;
025b0302 2168 }
8f78d0e9
KR
2169
2170 /* Handle an absolute 17 bit branch target. */
2171 case 'z':
025b0302 2172 the_insn.field_selector = pa_chk_field_selector (&s);
8f78d0e9 2173 get_expression (s);
48153d49 2174 s = expr_end;
025b0302 2175 the_insn.pcrel = 0;
c5e9ccd0 2176 if (!the_insn.exp.X_add_symbol
48153d49
JL
2177 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2178 "L$0\001"))
025b0302 2179 {
48153d49 2180 unsigned int w2, w1, w, result;
c5e9ccd0 2181
48153d49
JL
2182 num = evaluate_absolute (&the_insn);
2183 if (num % 4)
025b0302 2184 {
48153d49
JL
2185 as_bad ("Branch to unaligned address");
2186 break;
025b0302 2187 }
48153d49
JL
2188 CHECK_FIELD (num, 262143, -262144, 0);
2189
2190 if (the_insn.exp.X_add_symbol)
2191 num -= 8;
2192
2193 sign_unext (num >> 2, 17, &result);
2194 dis_assemble_17 (result, &w1, &w2, &w);
c5e9ccd0
JL
2195 INSERT_FIELD_AND_CONTINUE (opcode,
2196 ((w2 << 2) | (w1 << 16) | w), 0);
025b0302
ME
2197 }
2198 else
2199 {
48153d49
JL
2200 if (is_complex (the_insn.exp))
2201 the_insn.reloc = R_HPPA_COMPLEX_ABS_CALL;
2202 else
2203 the_insn.reloc = R_HPPA_ABS_CALL;
2204 the_insn.format = 17;
2205 continue;
025b0302 2206 }
8f78d0e9
KR
2207
2208 /* Handle a 5 bit shift count at 26. */
2209 case 'p':
48153d49 2210 num = pa_get_absolute_expression (&the_insn, &s);
025b0302 2211 s = expr_end;
48153d49
JL
2212 CHECK_FIELD (num, 31, 0, 0);
2213 INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
8f78d0e9
KR
2214
2215 /* Handle a 5 bit bit position at 26. */
2216 case 'P':
48153d49 2217 num = pa_get_absolute_expression (&the_insn, &s);
025b0302 2218 s = expr_end;
48153d49
JL
2219 CHECK_FIELD (num, 31, 0, 0);
2220 INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
8f78d0e9
KR
2221
2222 /* Handle a 5 bit immediate at 10. */
2223 case 'Q':
48153d49 2224 num = pa_get_absolute_expression (&the_insn, &s);
025b0302 2225 s = expr_end;
48153d49
JL
2226 CHECK_FIELD (num, 31, 0, 0);
2227 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
8f78d0e9
KR
2228
2229 /* Handle a 13 bit immediate at 18. */
2230 case 'A':
48153d49 2231 num = pa_get_absolute_expression (&the_insn, &s);
025b0302 2232 s = expr_end;
48153d49
JL
2233 CHECK_FIELD (num, 4095, -4096, 0);
2234 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
8f78d0e9
KR
2235
2236 /* Handle a 26 bit immediate at 31. */
2237 case 'D':
48153d49 2238 num = pa_get_absolute_expression (&the_insn, &s);
025b0302 2239 s = expr_end;
48153d49
JL
2240 CHECK_FIELD (num, 671108864, 0, 0);
2241 INSERT_FIELD_AND_CONTINUE (opcode, num, 1);
8f78d0e9
KR
2242
2243 /* Handle a 3 bit SFU identifier at 25. */
2244 case 'f':
48153d49
JL
2245 num = pa_get_absolute_expression (&the_insn, &s);
2246 s = expr_end;
2247 CHECK_FIELD (num, 7, 0, 0);
2248 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
8f78d0e9
KR
2249
2250 /* We don't support any of these. FIXME. */
2251 case 'O':
2252 get_expression (s);
025b0302 2253 s = expr_end;
8f78d0e9 2254 abort ();
025b0302 2255 continue;
8f78d0e9
KR
2256
2257 /* Handle a source FP operand format completer. */
2258 case 'F':
2259 flag = pa_parse_fp_format (&s);
8f78d0e9 2260 the_insn.fpof1 = flag;
48153d49 2261 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
8f78d0e9
KR
2262
2263 /* Handle a destination FP operand format completer. */
2264 case 'G':
8f78d0e9
KR
2265 /* pa_parse_format needs the ',' prefix. */
2266 s--;
2267 flag = pa_parse_fp_format (&s);
8f78d0e9 2268 the_insn.fpof2 = flag;
48153d49 2269 INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
8f78d0e9
KR
2270
2271 /* Handle FP compare conditions. */
2272 case 'M':
025b0302 2273 cond = pa_parse_fp_cmp_cond (&s);
48153d49 2274 INSERT_FIELD_AND_CONTINUE (opcode, cond, 0);
025b0302 2275
8f78d0e9
KR
2276 /* Handle L/R register halves like 't'. */
2277 case 'v':
025b0302
ME
2278 {
2279 struct pa_89_fp_reg_struct result;
025b0302 2280
8f78d0e9 2281 pa_parse_number (&s, &result);
48153d49
JL
2282 CHECK_FIELD (result.number_part, 31, 0, 0);
2283 opcode |= result.number_part;
025b0302 2284
48153d49
JL
2285 /* 0x30 opcodes are FP arithmetic operation opcodes
2286 and need to be turned into 0x38 opcodes. This
2287 is not necessary for loads/stores. */
2288 if (need_89_opcode (&the_insn, &result)
2289 && ((opcode & 0xfc000000) == 0x30000000))
2290 opcode |= 1 << 27;
2291
2292 INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6);
025b0302 2293 }
8f78d0e9
KR
2294
2295 /* Handle L/R register halves like 'b'. */
2296 case 'E':
025b0302
ME
2297 {
2298 struct pa_89_fp_reg_struct result;
025b0302 2299
8f78d0e9 2300 pa_parse_number (&s, &result);
48153d49
JL
2301 CHECK_FIELD (result.number_part, 31, 0, 0);
2302 opcode |= result.number_part << 21;
2303 if (need_89_opcode (&the_insn, &result))
025b0302 2304 {
48153d49
JL
2305 opcode |= (result.l_r_select & 1) << 7;
2306 opcode |= 1 << 27;
025b0302 2307 }
48153d49 2308 continue;
025b0302 2309 }
025b0302 2310
8f78d0e9
KR
2311 /* Handle L/R register halves like 'x'. */
2312 case 'X':
025b0302
ME
2313 {
2314 struct pa_89_fp_reg_struct result;
025b0302 2315
8f78d0e9 2316 pa_parse_number (&s, &result);
48153d49
JL
2317 CHECK_FIELD (result.number_part, 31, 0, 0);
2318 opcode |= (result.number_part & 0x1f) << 16;
2319 if (need_89_opcode (&the_insn, &result))
025b0302 2320 {
48153d49
JL
2321 opcode |= (result.l_r_select & 1) << 12;
2322 opcode |= 1 << 27;
025b0302 2323 }
48153d49 2324 continue;
025b0302 2325 }
025b0302 2326
8f78d0e9
KR
2327 /* Handle a 5 bit register field at 10. */
2328 case '4':
025b0302
ME
2329 {
2330 struct pa_89_fp_reg_struct result;
48153d49
JL
2331
2332 pa_parse_number (&s, &result);
2333 CHECK_FIELD (result.number_part, 31, 0, 0);
2334 if (the_insn.fpof1 == SGL)
025b0302 2335 {
48153d49
JL
2336 result.number_part &= 0xF;
2337 result.number_part |= (result.l_r_select & 1) << 4;
025b0302 2338 }
48153d49 2339 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21);
025b0302 2340 }
025b0302 2341
8f78d0e9
KR
2342 /* Handle a 5 bit register field at 15. */
2343 case '6':
025b0302
ME
2344 {
2345 struct pa_89_fp_reg_struct result;
025b0302 2346
48153d49
JL
2347 pa_parse_number (&s, &result);
2348 CHECK_FIELD (result.number_part, 31, 0, 0);
2349 if (the_insn.fpof1 == SGL)
025b0302 2350 {
48153d49
JL
2351 result.number_part &= 0xF;
2352 result.number_part |= (result.l_r_select & 1) << 4;
025b0302 2353 }
48153d49 2354 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16);
025b0302 2355 }
025b0302 2356
8f78d0e9
KR
2357 /* Handle a 5 bit register field at 31. */
2358 case '7':
025b0302
ME
2359 {
2360 struct pa_89_fp_reg_struct result;
025b0302 2361
48153d49
JL
2362 pa_parse_number (&s, &result);
2363 CHECK_FIELD (result.number_part, 31, 0, 0);
2364 if (the_insn.fpof1 == SGL)
025b0302 2365 {
48153d49
JL
2366 result.number_part &= 0xF;
2367 result.number_part |= (result.l_r_select & 1) << 4;
025b0302 2368 }
48153d49 2369 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0);
025b0302 2370 }
025b0302 2371
8f78d0e9
KR
2372 /* Handle a 5 bit register field at 20. */
2373 case '8':
025b0302
ME
2374 {
2375 struct pa_89_fp_reg_struct result;
025b0302 2376
48153d49
JL
2377 pa_parse_number (&s, &result);
2378 CHECK_FIELD (result.number_part, 31, 0, 0);
2379 if (the_insn.fpof1 == SGL)
025b0302 2380 {
48153d49
JL
2381 result.number_part &= 0xF;
2382 result.number_part |= (result.l_r_select & 1) << 4;
025b0302 2383 }
48153d49 2384 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11);
025b0302 2385 }
025b0302 2386
8f78d0e9
KR
2387 /* Handle a 5 bit register field at 25. */
2388 case '9':
025b0302
ME
2389 {
2390 struct pa_89_fp_reg_struct result;
025b0302 2391
48153d49
JL
2392 pa_parse_number (&s, &result);
2393 CHECK_FIELD (result.number_part, 31, 0, 0);
2394 if (the_insn.fpof1 == SGL)
025b0302 2395 {
48153d49
JL
2396 result.number_part &= 0xF;
2397 result.number_part |= (result.l_r_select & 1) << 4;
025b0302 2398 }
48153d49 2399 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6);
025b0302 2400 }
025b0302 2401
8f78d0e9
KR
2402 /* Handle a floating point operand format at 26.
2403 Only allows single and double precision. */
2404 case 'H':
2405 flag = pa_parse_fp_format (&s);
2406 switch (flag)
025b0302
ME
2407 {
2408 case SGL:
2409 opcode |= 0x20;
2410 case DBL:
8f78d0e9 2411 the_insn.fpof1 = flag;
025b0302
ME
2412 continue;
2413
2414 case QUAD:
2415 case ILLEGAL_FMT:
2416 default:
8f78d0e9 2417 as_bad ("Invalid Floating Point Operand Format.");
025b0302
ME
2418 }
2419 break;
2420
2421 default:
2422 abort ();
2423 }
2424 break;
2425 }
892a3ff1 2426
8f78d0e9 2427 /* Check if the args matched. */
025b0302
ME
2428 if (match == FALSE)
2429 {
025b0302
ME
2430 if (&insn[1] - pa_opcodes < NUMOPCODES
2431 && !strcmp (insn->name, insn[1].name))
2432 {
2433 ++insn;
8f78d0e9 2434 s = argstart;
025b0302
ME
2435 continue;
2436 }
2437 else
2438 {
8f78d0e9 2439 as_bad ("Invalid operands %s", error_message);
025b0302
ME
2440 return;
2441 }
2442 }
2443 break;
2444 }
2445
2446 the_insn.opcode = opcode;
025b0302
ME
2447}
2448
8f78d0e9 2449/* Turn a string in input_line_pointer into a floating point constant of type
025b0302 2450 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
8f78d0e9 2451 emitted is stored in *sizeP . An error message or NULL is returned. */
025b0302 2452
025b0302
ME
2453#define MAX_LITTLENUMS 6
2454
2455char *
2456md_atof (type, litP, sizeP)
2457 char type;
2458 char *litP;
2459 int *sizeP;
2460{
2461 int prec;
2462 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2463 LITTLENUM_TYPE *wordP;
2464 char *t;
025b0302
ME
2465
2466 switch (type)
2467 {
2468
2469 case 'f':
2470 case 'F':
2471 case 's':
2472 case 'S':
2473 prec = 2;
2474 break;
2475
2476 case 'd':
2477 case 'D':
2478 case 'r':
2479 case 'R':
2480 prec = 4;
2481 break;
2482
2483 case 'x':
2484 case 'X':
2485 prec = 6;
2486 break;
2487
2488 case 'p':
2489 case 'P':
2490 prec = 6;
2491 break;
2492
2493 default:
2494 *sizeP = 0;
2495 return "Bad call to MD_ATOF()";
2496 }
2497 t = atof_ieee (input_line_pointer, type, words);
2498 if (t)
2499 input_line_pointer = t;
2500 *sizeP = prec * sizeof (LITTLENUM_TYPE);
2501 for (wordP = words; prec--;)
2502 {
8f78d0e9 2503 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
025b0302
ME
2504 litP += sizeof (LITTLENUM_TYPE);
2505 }
aa8b30ed 2506 return NULL;
025b0302
ME
2507}
2508
8f78d0e9
KR
2509/* Write out big-endian. */
2510
025b0302
ME
2511void
2512md_number_to_chars (buf, val, n)
2513 char *buf;
2514 valueT val;
2515 int n;
2516{
bfbfba45 2517 number_to_chars_bigendian (buf, val, n);
025b0302
ME
2518}
2519
025b0302 2520/* Translate internal representation of relocation info to BFD target
62f0841b 2521 format. */
8f78d0e9 2522
025b0302
ME
2523arelent **
2524tc_gen_reloc (section, fixp)
2525 asection *section;
2526 fixS *fixp;
2527{
2528 arelent *reloc;
aa8b30ed 2529 struct hppa_fix_struct *hppa_fixp = fixp->tc_fix_data;
025b0302
ME
2530 bfd_reloc_code_real_type code;
2531 static int unwind_reloc_fixp_cnt = 0;
2532 static arelent *unwind_reloc_entryP = NULL;
2533 static arelent *no_relocs = NULL;
2534 arelent **relocs;
2535 bfd_reloc_code_real_type **codes;
2536 int n_relocs;
2537 int i;
2538
2539 if (fixp->fx_addsy == 0)
2540 return &no_relocs;
2541 assert (hppa_fixp != 0);
2542 assert (section != 0);
2543
62f0841b
JL
2544#ifdef OBJ_ELF
2545 /* Yuk. I would really like to push all this ELF specific unwind
2546 crud into BFD and the linker. That's how SOM does it -- and
2547 if we could make ELF emulate that then we could share more code
2548 in GAS (and potentially a gnu-linker later).
2549
2550 Unwind section relocations are handled in a special way.
8f78d0e9
KR
2551 The relocations for the .unwind section are originally
2552 built in the usual way. That is, for each unwind table
2553 entry there are two relocations: one for the beginning of
2554 the function and one for the end.
2555
2556 The first time we enter this function we create a
2557 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2558 of the relocation is initialized to 0. Each additional
2559 pair of times this function is called for the unwind
2560 section represents an additional unwind table entry. Thus,
2561 the addend of the relocation should end up to be the number
2562 of unwind table entries. */
025b0302
ME
2563 if (strcmp (UNWIND_SECTION_NAME, section->name) == 0)
2564 {
2565 if (unwind_reloc_entryP == NULL)
2566 {
c5e9ccd0 2567 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput,
8f78d0e9 2568 sizeof (arelent));
025b0302
ME
2569 assert (reloc != 0);
2570 unwind_reloc_entryP = reloc;
2571 unwind_reloc_fixp_cnt++;
8f78d0e9
KR
2572 unwind_reloc_entryP->address
2573 = fixp->fx_frag->fr_address + fixp->fx_where;
2574 /* A pointer to any function will do. We only
2575 need one to tell us what section the unwind
2576 relocations are for. */
025b0302 2577 unwind_reloc_entryP->sym_ptr_ptr = &fixp->fx_addsy->bsym;
8f78d0e9
KR
2578 hppa_fixp->fx_r_type = code = R_HPPA_UNWIND_ENTRIES;
2579 fixp->fx_r_type = R_HPPA_UNWIND;
025b0302
ME
2580 unwind_reloc_entryP->howto = bfd_reloc_type_lookup (stdoutput, code);
2581 unwind_reloc_entryP->addend = unwind_reloc_fixp_cnt / 2;
8f78d0e9
KR
2582 relocs = (arelent **) bfd_alloc_by_size_t (stdoutput,
2583 sizeof (arelent *) * 2);
025b0302
ME
2584 assert (relocs != 0);
2585 relocs[0] = unwind_reloc_entryP;
2586 relocs[1] = NULL;
2587 return relocs;
2588 }
2589 unwind_reloc_fixp_cnt++;
2590 unwind_reloc_entryP->addend = unwind_reloc_fixp_cnt / 2;
2591
2592 return &no_relocs;
2593 }
62f0841b 2594#endif
025b0302
ME
2595
2596 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2597 assert (reloc != 0);
2598
2599 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
aa8b30ed
JL
2600 codes = hppa_gen_reloc_type (stdoutput,
2601 fixp->fx_r_type,
2602 hppa_fixp->fx_r_format,
2603 hppa_fixp->fx_r_field);
025b0302
ME
2604
2605 for (n_relocs = 0; codes[n_relocs]; n_relocs++)
2606 ;
2607
8f78d0e9
KR
2608 relocs = (arelent **)
2609 bfd_alloc_by_size_t (stdoutput, sizeof (arelent *) * n_relocs + 1);
025b0302
ME
2610 assert (relocs != 0);
2611
8f78d0e9
KR
2612 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput,
2613 sizeof (arelent) * n_relocs);
025b0302
ME
2614 if (n_relocs > 0)
2615 assert (reloc != 0);
2616
2617 for (i = 0; i < n_relocs; i++)
2618 relocs[i] = &reloc[i];
2619
2620 relocs[n_relocs] = NULL;
2621
62f0841b 2622#ifdef OBJ_ELF
025b0302
ME
2623 switch (fixp->fx_r_type)
2624 {
2625 case R_HPPA_COMPLEX:
2626 case R_HPPA_COMPLEX_PCREL_CALL:
2627 case R_HPPA_COMPLEX_ABS_CALL:
2628 assert (n_relocs == 5);
2629
2630 for (i = 0; i < n_relocs; i++)
2631 {
2632 reloc[i].sym_ptr_ptr = NULL;
2633 reloc[i].address = 0;
2634 reloc[i].addend = 0;
2635 reloc[i].howto = bfd_reloc_type_lookup (stdoutput, *codes[i]);
2636 assert (reloc[i].howto && *codes[i] == reloc[i].howto->type);
2637 }
2638
2639 reloc[0].sym_ptr_ptr = &fixp->fx_addsy->bsym;
2640 reloc[1].sym_ptr_ptr = &fixp->fx_subsy->bsym;
2641 reloc[4].address = fixp->fx_frag->fr_address + fixp->fx_where;
2642
2643 if (fixp->fx_r_type == R_HPPA_COMPLEX)
2644 reloc[3].addend = fixp->fx_addnumber;
2645 else if (fixp->fx_r_type == R_HPPA_COMPLEX_PCREL_CALL ||
2646 fixp->fx_r_type == R_HPPA_COMPLEX_ABS_CALL)
2647 reloc[1].addend = fixp->fx_addnumber;
2648
2649 break;
2650
2651 default:
2652 assert (n_relocs == 1);
2653
2654 code = *codes[0];
2655
2656 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2657 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2658 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2659 reloc->addend = 0; /* default */
2660
2661 assert (reloc->howto && code == reloc->howto->type);
2662
8f78d0e9 2663 /* Now, do any processing that is dependent on the relocation type. */
025b0302
ME
2664 switch (code)
2665 {
2666 case R_HPPA_PLABEL_32:
2667 case R_HPPA_PLABEL_11:
2668 case R_HPPA_PLABEL_14:
2669 case R_HPPA_PLABEL_L21:
2670 case R_HPPA_PLABEL_R11:
2671 case R_HPPA_PLABEL_R14:
8f78d0e9
KR
2672 /* For plabel relocations, the addend of the
2673 relocation should be either 0 (no static link) or 2
2674 (static link required).
2675
7b624bf2
JL
2676 FIXME: We always assume no static link! */
2677 reloc->addend = 0;
025b0302
ME
2678 break;
2679
2680 case R_HPPA_ABS_CALL_11:
2681 case R_HPPA_ABS_CALL_14:
2682 case R_HPPA_ABS_CALL_17:
2683 case R_HPPA_ABS_CALL_L21:
2684 case R_HPPA_ABS_CALL_R11:
2685 case R_HPPA_ABS_CALL_R14:
2686 case R_HPPA_ABS_CALL_R17:
2687 case R_HPPA_ABS_CALL_LS21:
2688 case R_HPPA_ABS_CALL_RS11:
2689 case R_HPPA_ABS_CALL_RS14:
2690 case R_HPPA_ABS_CALL_RS17:
2691 case R_HPPA_ABS_CALL_LD21:
2692 case R_HPPA_ABS_CALL_RD11:
2693 case R_HPPA_ABS_CALL_RD14:
2694 case R_HPPA_ABS_CALL_RD17:
2695 case R_HPPA_ABS_CALL_LR21:
2696 case R_HPPA_ABS_CALL_RR14:
2697 case R_HPPA_ABS_CALL_RR17:
2698
2699 case R_HPPA_PCREL_CALL_11:
2700 case R_HPPA_PCREL_CALL_14:
2701 case R_HPPA_PCREL_CALL_17:
2702 case R_HPPA_PCREL_CALL_L21:
2703 case R_HPPA_PCREL_CALL_R11:
2704 case R_HPPA_PCREL_CALL_R14:
2705 case R_HPPA_PCREL_CALL_R17:
2706 case R_HPPA_PCREL_CALL_LS21:
2707 case R_HPPA_PCREL_CALL_RS11:
2708 case R_HPPA_PCREL_CALL_RS14:
2709 case R_HPPA_PCREL_CALL_RS17:
2710 case R_HPPA_PCREL_CALL_LD21:
2711 case R_HPPA_PCREL_CALL_RD11:
2712 case R_HPPA_PCREL_CALL_RD14:
2713 case R_HPPA_PCREL_CALL_RD17:
2714 case R_HPPA_PCREL_CALL_LR21:
2715 case R_HPPA_PCREL_CALL_RR14:
2716 case R_HPPA_PCREL_CALL_RR17:
8f78d0e9
KR
2717 /* The constant is stored in the instruction. */
2718 reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
025b0302
ME
2719 break;
2720 default:
2721 reloc->addend = fixp->fx_addnumber;
2722 break;
2723 }
2724 break;
2725 }
62f0841b 2726#else /* OBJ_SOM */
025b0302 2727
4165dcc2
JL
2728 /* Walk over reach relocation returned by the BFD backend. */
2729 for (i = 0; i < n_relocs; i++)
62f0841b 2730 {
4165dcc2 2731 code = *codes[i];
c5e9ccd0 2732
4165dcc2
JL
2733 relocs[i]->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2734 relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code);
2735 relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
025b0302 2736
62f0841b
JL
2737 switch (code)
2738 {
2739 case R_PCREL_CALL:
2740 case R_ABS_CALL:
4165dcc2 2741 relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
62f0841b 2742 break;
f2eed884
JL
2743
2744 case R_DATA_PLABEL:
2745 case R_CODE_PLABEL:
2746 /* For plabel relocations, the addend of the
2747 relocation should be either 0 (no static link) or 2
2748 (static link required).
2749
2750 FIXME: We always assume no static link! */
4165dcc2
JL
2751 relocs[i]->addend = 0;
2752 break;
2753
2754 case R_N_MODE:
2755 case R_S_MODE:
2756 case R_D_MODE:
2757 case R_R_MODE:
6868afe6
KR
2758 case R_EXIT:
2759 case R_FSEL:
2760 case R_LSEL:
2761 case R_RSEL:
4165dcc2 2762 /* There is no symbol or addend associated with these fixups. */
fca59f9d 2763 relocs[i]->sym_ptr_ptr = &dummy_symbol->bsym;
4165dcc2 2764 relocs[i]->addend = 0;
f2eed884
JL
2765 break;
2766
62f0841b 2767 default:
4165dcc2 2768 relocs[i]->addend = fixp->fx_addnumber;
62f0841b
JL
2769 break;
2770 }
62f0841b 2771 }
025b0302
ME
2772#endif
2773
62f0841b
JL
2774 return relocs;
2775}
2776
8f78d0e9
KR
2777/* Process any machine dependent frag types. */
2778
025b0302
ME
2779void
2780md_convert_frag (abfd, sec, fragP)
2781 register bfd *abfd;
2782 register asection *sec;
2783 register fragS *fragP;
2784{
2785 unsigned int address;
2786
2787 if (fragP->fr_type == rs_machine_dependent)
2788 {
2789 switch ((int) fragP->fr_subtype)
2790 {
2791 case 0:
2792 fragP->fr_type = rs_fill;
2793 know (fragP->fr_var == 1);
2794 know (fragP->fr_next);
2795 address = fragP->fr_address + fragP->fr_fix;
2796 if (address % fragP->fr_offset)
2797 {
2798 fragP->fr_offset =
2799 fragP->fr_next->fr_address
2800 - fragP->fr_address
2801 - fragP->fr_fix;
2802 }
2803 else
2804 fragP->fr_offset = 0;
2805 break;
2806 }
8f78d0e9
KR
2807 }
2808}
025b0302 2809
8f78d0e9 2810/* Round up a section size to the appropriate boundary. */
025b0302 2811
8f78d0e9
KR
2812valueT
2813md_section_align (segment, size)
2814 asection *segment;
2815 valueT size;
025b0302 2816{
8f78d0e9
KR
2817 int align = bfd_get_section_alignment (stdoutput, segment);
2818 int align2 = (1 << align) - 1;
025b0302 2819
8f78d0e9 2820 return (size + align2) & ~align2;
8f78d0e9 2821}
025b0302 2822
8f78d0e9
KR
2823/* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2824void
2825md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2826 char *ptr;
2827 addressT from_addr, to_addr;
2828 fragS *frag;
2829 symbolS *to_symbol;
2830{
2831 fprintf (stderr, "pa_create_short_jmp\n");
2832 abort ();
2833}
025b0302 2834
8f78d0e9
KR
2835/* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2836void
2837md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2838 char *ptr;
2839 addressT from_addr, to_addr;
2840 fragS *frag;
2841 symbolS *to_symbol;
2842{
2843 fprintf (stderr, "pa_create_long_jump\n");
2844 abort ();
025b0302
ME
2845}
2846
8f78d0e9
KR
2847/* Return the approximate size of a frag before relaxation has occurred. */
2848int
2849md_estimate_size_before_relax (fragP, segment)
2850 register fragS *fragP;
2851 asection *segment;
025b0302 2852{
8f78d0e9
KR
2853 int size;
2854
2855 size = 0;
2856
2857 while ((fragP->fr_fix + size) % fragP->fr_offset)
2858 size++;
2859
2860 return size;
025b0302
ME
2861}
2862
c5e9ccd0 2863/* Parse machine dependent options. There are none on the PA. */
8f78d0e9
KR
2864int
2865md_parse_option (argP, cntP, vecP)
2866 char **argP;
2867 int *cntP;
2868 char ***vecP;
025b0302 2869{
8f78d0e9
KR
2870 return 1;
2871}
025b0302 2872
8f78d0e9
KR
2873/* We have no need to default values of symbols. */
2874
2875symbolS *
2876md_undefined_symbol (name)
2877 char *name;
2878{
2879 return 0;
025b0302
ME
2880}
2881
8f78d0e9
KR
2882/* Parse an operand that is machine-specific.
2883 We just return without modifying the expression as we have nothing
2884 to do on the PA. */
2885
2886void
2887md_operand (expressionP)
2888 expressionS *expressionP;
025b0302 2889{
8f78d0e9 2890}
025b0302 2891
753dcbbd 2892/* Apply a fixup to an instruction. */
8f78d0e9 2893
753dcbbd
JL
2894int
2895md_apply_fix (fixP, valp)
8f78d0e9 2896 fixS *fixP;
753dcbbd 2897 valueT *valp;
025b0302 2898{
8f78d0e9 2899 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
aa8b30ed 2900 struct hppa_fix_struct *hppa_fixP = fixP->tc_fix_data;
8f78d0e9
KR
2901 long new_val, result;
2902 unsigned int w1, w2, w;
753dcbbd 2903 valueT val = *valp;
8f78d0e9 2904
ff852e11 2905 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
753dcbbd 2906 never be "applied" (they are just markers). */
ff852e11
JL
2907#ifdef OBJ_SOM
2908 if (fixP->fx_r_type == R_HPPA_ENTRY
2909 || fixP->fx_r_type == R_HPPA_EXIT)
753dcbbd 2910 return 1;
ff852e11
JL
2911#endif
2912
8f78d0e9
KR
2913 /* There should have been an HPPA specific fixup associated
2914 with the GAS fixup. */
2915 if (hppa_fixP)
2916 {
2917 unsigned long buf_wd = bfd_get_32 (stdoutput, buf);
aa8b30ed 2918 unsigned char fmt = bfd_hppa_insn2fmt (buf_wd);
8f78d0e9 2919
aa8b30ed
JL
2920 if (fixP->fx_r_type == R_HPPA_NONE)
2921 fmt = 0;
8f78d0e9
KR
2922
2923 /* Remember this value for emit_reloc. FIXME, is this braindamage
c5e9ccd0 2924 documented anywhere!?! */
8f78d0e9
KR
2925 fixP->fx_addnumber = val;
2926
2927 /* Check if this is an undefined symbol. No relocation can
fca59f9d
JL
2928 possibly be performed in this case.
2929
2930 Also avoid doing anything for pc-relative fixups in which the
2931 fixup is in a different space than the symbol it references. */
8f78d0e9
KR
2932 if ((fixP->fx_addsy && fixP->fx_addsy->bsym->section == &bfd_und_section)
2933 || (fixP->fx_subsy
fca59f9d 2934 && fixP->fx_subsy->bsym->section == &bfd_und_section)
86066d06
JL
2935 || (fixP->fx_pcrel
2936 && fixP->fx_addsy
fca59f9d 2937 && S_GET_SEGMENT (fixP->fx_addsy) != hppa_fixP->segment)
86066d06
JL
2938 || (fixP->fx_pcrel
2939 && fixP->fx_subsy
fca59f9d 2940 && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment))
753dcbbd 2941 return 1;
8f78d0e9 2942
753dcbbd 2943 /* PLABEL field selectors should not be passed to hppa_field_adjust. */
f2eed884
JL
2944 if (fmt != 0 && hppa_fixP->fx_r_field != R_HPPA_PSEL
2945 && hppa_fixP->fx_r_field != R_HPPA_LPSEL
9d5a9b20
JL
2946 && hppa_fixP->fx_r_field != R_HPPA_RPSEL
2947 && hppa_fixP->fx_r_field != R_HPPA_TSEL
2948 && hppa_fixP->fx_r_field != R_HPPA_LTSEL
2949 && hppa_fixP->fx_r_field != R_HPPA_RTSEL)
48153d49
JL
2950 new_val = hppa_field_adjust (val, 0, hppa_fixP->fx_r_field);
2951 else
2952 new_val = 0;
2953
8f78d0e9
KR
2954 switch (fmt)
2955 {
2956 /* Handle all opcodes with the 'j' operand type. */
2957 case 14:
48153d49 2958 CHECK_FIELD (new_val, 8191, -8192, 0);
8f78d0e9
KR
2959
2960 /* Mask off 14 bits to be changed. */
2961 bfd_put_32 (stdoutput,
2962 bfd_get_32 (stdoutput, buf) & 0xffffc000,
2963 buf);
2964 low_sign_unext (new_val, 14, &result);
2965 break;
2966
2967 /* Handle all opcodes with the 'k' operand type. */
2968 case 21:
48153d49 2969 CHECK_FIELD (new_val, 2097152, 0, 0);
8f78d0e9
KR
2970
2971 /* Mask off 21 bits to be changed. */
2972 bfd_put_32 (stdoutput,
2973 bfd_get_32 (stdoutput, buf) & 0xffe00000,
2974 buf);
2975 dis_assemble_21 (new_val, &result);
2976 break;
2977
2978 /* Handle all the opcodes with the 'i' operand type. */
2979 case 11:
48153d49 2980 CHECK_FIELD (new_val, 1023, -1023, 0);
8f78d0e9
KR
2981
2982 /* Mask off 11 bits to be changed. */
2983 bfd_put_32 (stdoutput,
2984 bfd_get_32 (stdoutput, buf) & 0xffff800,
2985 buf);
2986 low_sign_unext (new_val, 11, &result);
2987 break;
2988
2989 /* Handle all the opcodes with the 'w' operand type. */
2990 case 12:
48153d49 2991 CHECK_FIELD (new_val, 8191, -8192, 0)
8f78d0e9
KR
2992
2993 /* Mask off 11 bits to be changed. */
c5e9ccd0 2994 sign_unext ((new_val - 8) >> 2, 12, &result);
8f78d0e9
KR
2995 bfd_put_32 (stdoutput,
2996 bfd_get_32 (stdoutput, buf) & 0xffffe002,
2997 buf);
2998
2999 dis_assemble_12 (result, &w1, &w);
3000 result = ((w1 << 2) | w);
8f78d0e9
KR
3001 break;
3002
753dcbbd
JL
3003 /* Handle some of the opcodes with the 'W' operand type. */
3004 case 17:
3005
8f78d0e9
KR
3006#define stub_needed(CALLER, CALLEE) \
3007 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
753dcbbd
JL
3008 /* It is necessary to force PC-relative calls/jumps to have a
3009 relocation entry if they're going to need either a argument
3010 relocation or long call stub. FIXME. Can't we need the same
3011 for absolute calls? */
3012 if (fixP->fx_addsy
3013 && (stub_needed (((obj_symbol_type *)
3014 fixP->fx_addsy->bsym)->tc_data.hppa_arg_reloc,
3015 hppa_fixP->fx_arg_reloc)))
3016 return 1;
3017#undef stub_needed
8f78d0e9 3018
48153d49 3019 CHECK_FIELD (new_val, 262143, -262144, 0);
8f78d0e9
KR
3020
3021 /* Mask off 17 bits to be changed. */
3022 bfd_put_32 (stdoutput,
3023 bfd_get_32 (stdoutput, buf) & 0xffe0e002,
3024 buf);
3025 sign_unext ((new_val - 8) >> 2, 17, &result);
3026 dis_assemble_17 (result, &w1, &w2, &w);
3027 result = ((w2 << 2) | (w1 << 16) | w);
8f78d0e9
KR
3028 break;
3029
8f78d0e9 3030 case 32:
aa8b30ed 3031#ifdef OBJ_ELF
ff852e11
JL
3032 /* These are ELF specific relocations. ELF unfortunately
3033 handles unwinds in a completely different manner. */
8f78d0e9
KR
3034 if (hppa_fixP->fx_r_type == R_HPPA_UNWIND_ENTRY
3035 || hppa_fixP->fx_r_type == R_HPPA_UNWIND_ENTRIES)
3036 result = fixP->fx_addnumber;
3037 else
aa8b30ed 3038#endif
8f78d0e9
KR
3039 {
3040 result = 0;
3041 fixP->fx_addnumber = fixP->fx_offset;
551d2fd4
JL
3042 /* If we have a real relocation, then we want zero to
3043 be stored in the object file. If no relocation is going
3044 to be emitted, then we need to store new_val into the
3045 object file. */
3046 if (fixP->fx_addsy)
3047 bfd_put_32 (stdoutput, 0, buf);
3048 else
3049 bfd_put_32 (stdoutput, new_val, buf);
753dcbbd 3050 return 1;
8f78d0e9
KR
3051 }
3052 break;
3053
3054 case 0:
753dcbbd 3055 return 1;
8f78d0e9
KR
3056
3057 default:
48153d49 3058 as_bad ("Unknown relocation encountered in md_apply_fix.");
753dcbbd 3059 return 1;
8f78d0e9
KR
3060 }
3061
3062 /* Insert the relocation. */
48153d49 3063 bfd_put_32 (stdoutput, bfd_get_32 (stdoutput, buf) | result, buf);
753dcbbd 3064 return 1;
8f78d0e9 3065 }
025b0302 3066 else
753dcbbd
JL
3067 {
3068 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3069 (unsigned int) fixP, fixP->fx_r_type);
3070 return 0;
3071 }
8f78d0e9
KR
3072}
3073
3074/* Exactly what point is a PC-relative offset relative TO?
3075 On the PA, they're relative to the address of the offset. */
3076
3077long
3078md_pcrel_from (fixP)
3079 fixS *fixP;
3080{
3081 return fixP->fx_where + fixP->fx_frag->fr_address;
3082}
3083
3084/* Return nonzero if the input line pointer is at the end of
3085 a statement. */
3086
3087static int
3088is_end_of_statement ()
3089{
3090 return ((*input_line_pointer == '\n')
3091 || (*input_line_pointer == ';')
3092 || (*input_line_pointer == '!'));
3093}
3094
3095/* Read a number from S. The number might come in one of many forms,
3096 the most common will be a hex or decimal constant, but it could be
3097 a pre-defined register (Yuk!), or an absolute symbol.
3098
3099 Return a number or -1 for failure.
3100
3101 When parsing PA-89 FP register numbers RESULT will be
3102 the address of a structure to return information about
3103 L/R half of FP registers, store results there as appropriate.
3104
3105 pa_parse_number can not handle negative constants and will fail
3106 horribly if it is passed such a constant. */
3107
3108static int
3109pa_parse_number (s, result)
025b0302
ME
3110 char **s;
3111 struct pa_89_fp_reg_struct *result;
3112{
3113 int num;
3114 char *name;
3115 char c;
3116 symbolS *sym;
3117 int status;
3118 char *p = *s;
3119
8f78d0e9 3120 /* Skip whitespace before the number. */
025b0302
ME
3121 while (*p == ' ' || *p == '\t')
3122 p = p + 1;
8f78d0e9
KR
3123
3124 /* Store info in RESULT if requested by caller. */
3125 if (result)
3126 {
3127 result->number_part = -1;
3128 result->l_r_select = -1;
3129 }
3130 num = -1;
025b0302
ME
3131
3132 if (isdigit (*p))
3133 {
8f78d0e9
KR
3134 /* Looks like a number. */
3135 num = 0;
025b0302
ME
3136
3137 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
8f78d0e9
KR
3138 {
3139 /* The number is specified in hex. */
3140 p += 2;
025b0302
ME
3141 while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f'))
3142 || ((*p >= 'A') && (*p <= 'F')))
3143 {
3144 if (isdigit (*p))
3145 num = num * 16 + *p - '0';
3146 else if (*p >= 'a' && *p <= 'f')
3147 num = num * 16 + *p - 'a' + 10;
3148 else
3149 num = num * 16 + *p - 'A' + 10;
3150 ++p;
3151 }
3152 }
3153 else
3154 {
8f78d0e9 3155 /* The number is specified in decimal. */
025b0302
ME
3156 while (isdigit (*p))
3157 {
3158 num = num * 10 + *p - '0';
3159 ++p;
3160 }
3161 }
3162
8f78d0e9
KR
3163 /* Store info in RESULT if requested by the caller. */
3164 if (result)
025b0302 3165 {
8f78d0e9 3166 result->number_part = num;
025b0302 3167
8f78d0e9
KR
3168 if (IS_R_SELECT (p))
3169 {
3170 result->l_r_select = 1;
3171 ++p;
3172 }
3173 else if (IS_L_SELECT (p))
3174 {
3175 result->l_r_select = 0;
3176 ++p;
3177 }
3178 else
3179 result->l_r_select = 0;
3180 }
025b0302
ME
3181 }
3182 else if (*p == '%')
8f78d0e9
KR
3183 {
3184 /* The number might be a predefined register. */
025b0302
ME
3185 num = 0;
3186 name = p;
3187 p++;
3188 c = *p;
8f78d0e9
KR
3189 /* Tege hack: Special case for general registers as the general
3190 code makes a binary search with case translation, and is VERY
3191 slow. */
025b0302
ME
3192 if (c == 'r')
3193 {
3194 p++;
8f78d0e9
KR
3195 if (*p == 'e' && *(p + 1) == 't'
3196 && (*(p + 2) == '0' || *(p + 2) == '1'))
025b0302
ME
3197 {
3198 p += 2;
8f78d0e9 3199 num = *p - '0' + 28;
025b0302
ME
3200 p++;
3201 }
d6e524f3
JL
3202 else if (*p == 'p')
3203 {
3204 num = 2;
3205 p++;
3206 }
025b0302 3207 else if (!isdigit (*p))
d6e524f3
JL
3208 {
3209 if (print_errors)
3210 as_bad ("Undefined register: '%s'.", name);
3211 num = -1;
3212 }
025b0302
ME
3213 else
3214 {
3215 do
3216 num = num * 10 + *p++ - '0';
3217 while (isdigit (*p));
3218 }
3219 }
3220 else
3221 {
8f78d0e9 3222 /* Do a normal register search. */
025b0302
ME
3223 while (is_part_of_name (c))
3224 {
3225 p = p + 1;
3226 c = *p;
3227 }
3228 *p = 0;
3229 status = reg_name_search (name);
3230 if (status >= 0)
3231 num = status;
3232 else
3233 {
3234 if (print_errors)
d6e524f3
JL
3235 as_bad ("Undefined register: '%s'.", name);
3236 num = -1;
025b0302
ME
3237 }
3238 *p = c;
3239 }
3240
8f78d0e9
KR
3241 /* Store info in RESULT if requested by caller. */
3242 if (result)
3243 {
3244 result->number_part = num;
3245 if (IS_R_SELECT (p - 1))
3246 result->l_r_select = 1;
3247 else if (IS_L_SELECT (p - 1))
3248 result->l_r_select = 0;
3249 else
3250 result->l_r_select = 0;
3251 }
025b0302
ME
3252 }
3253 else
3254 {
8f78d0e9
KR
3255 /* And finally, it could be a symbol in the absolute section which
3256 is effectively a constant. */
025b0302
ME
3257 num = 0;
3258 name = p;
3259 c = *p;
3260 while (is_part_of_name (c))
3261 {
3262 p = p + 1;
3263 c = *p;
3264 }
3265 *p = 0;
3266 if ((sym = symbol_find (name)) != NULL)
3267 {
025b0302 3268 if (S_GET_SEGMENT (sym) == &bfd_abs_section)
8f78d0e9 3269 num = S_GET_VALUE (sym);
025b0302
ME
3270 else
3271 {
3272 if (print_errors)
d6e524f3
JL
3273 as_bad ("Non-absolute symbol: '%s'.", name);
3274 num = -1;
025b0302
ME
3275 }
3276 }
3277 else
3278 {
d6e524f3
JL
3279 /* There is where we'd come for an undefined symbol
3280 or for an empty string. For an empty string we
3281 will return zero. That's a concession made for
3282 compatability with the braindamaged HP assemblers. */
1cc248d2 3283 if (*name == 0)
d6e524f3 3284 num = 0;
025b0302 3285 else
d6e524f3
JL
3286 {
3287 if (print_errors)
3288 as_bad ("Undefined absolute constant: '%s'.", name);
3289 num = -1;
3290 }
025b0302
ME
3291 }
3292 *p = c;
025b0302 3293
8f78d0e9
KR
3294 /* Store info in RESULT if requested by caller. */
3295 if (result)
3296 {
3297 result->number_part = num;
3298 if (IS_R_SELECT (p - 1))
3299 result->l_r_select = 1;
3300 else if (IS_L_SELECT (p - 1))
3301 result->l_r_select = 0;
3302 else
3303 result->l_r_select = 0;
3304 }
025b0302
ME
3305 }
3306
3307 *s = p;
3308 return num;
8f78d0e9
KR
3309}
3310
3311#define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3312
3313/* Given NAME, find the register number associated with that name, return
3314 the integer value associated with the given name or -1 on failure. */
3315
3316static int
3317reg_name_search (name)
3318 char *name;
3319{
3320 int middle, low, high;
4047ff1d 3321 int cmp;
8f78d0e9
KR
3322
3323 low = 0;
3324 high = REG_NAME_CNT - 1;
3325
3326 do
3327 {
3328 middle = (low + high) / 2;
4047ff1d
JL
3329 cmp = strcasecmp (name, pre_defined_registers[middle].name);
3330 if (cmp < 0)
8f78d0e9 3331 high = middle - 1;
4047ff1d 3332 else if (cmp > 0)
8f78d0e9 3333 low = middle + 1;
4047ff1d
JL
3334 else
3335 return pre_defined_registers[middle].value;
8f78d0e9 3336 }
4047ff1d 3337 while (low <= high);
8f78d0e9 3338
4047ff1d 3339 return -1;
8f78d0e9
KR
3340}
3341
3342
3343/* Return nonzero if the given INSN and L/R information will require
3344 a new PA-89 opcode. */
025b0302 3345
8f78d0e9
KR
3346static int
3347need_89_opcode (insn, result)
3348 struct pa_it *insn;
3349 struct pa_89_fp_reg_struct *result;
3350{
3351 if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL))
3352 return TRUE;
3353 else
3354 return FALSE;
025b0302
ME
3355}
3356
8f78d0e9
KR
3357/* Parse a condition for a fcmp instruction. Return the numerical
3358 code associated with the condition. */
c5e9ccd0 3359
8f78d0e9 3360static int
025b0302
ME
3361pa_parse_fp_cmp_cond (s)
3362 char **s;
3363{
3364 int cond, i;
025b0302
ME
3365
3366 cond = 0;
3367
3368 for (i = 0; i < 32; i++)
3369 {
8f78d0e9
KR
3370 if (strncasecmp (*s, fp_cond_map[i].string,
3371 strlen (fp_cond_map[i].string)) == 0)
025b0302 3372 {
8f78d0e9
KR
3373 cond = fp_cond_map[i].cond;
3374 *s += strlen (fp_cond_map[i].string);
025b0302
ME
3375 while (**s == ' ' || **s == '\t')
3376 *s = *s + 1;
3377 return cond;
3378 }
3379 }
3380
8f78d0e9 3381 as_bad ("Invalid FP Compare Condition: %c", **s);
025b0302
ME
3382 return 0;
3383}
3384
8f78d0e9
KR
3385/* Parse an FP operand format completer returning the completer
3386 type. */
c5e9ccd0 3387
8f78d0e9 3388static fp_operand_format
025b0302
ME
3389pa_parse_fp_format (s)
3390 char **s;
3391{
8f78d0e9 3392 int format;
025b0302 3393
8f78d0e9 3394 format = SGL;
025b0302
ME
3395 if (**s == ',')
3396 {
3397 *s += 1;
3398 if (strncasecmp (*s, "sgl", 3) == 0)
3399 {
8f78d0e9 3400 format = SGL;
025b0302
ME
3401 *s += 4;
3402 }
3403 else if (strncasecmp (*s, "dbl", 3) == 0)
3404 {
8f78d0e9 3405 format = DBL;
025b0302
ME
3406 *s += 4;
3407 }
3408 else if (strncasecmp (*s, "quad", 4) == 0)
3409 {
8f78d0e9 3410 format = QUAD;
025b0302
ME
3411 *s += 5;
3412 }
3413 else
3414 {
8f78d0e9
KR
3415 format = ILLEGAL_FMT;
3416 as_bad ("Invalid FP Operand Format: %3s", *s);
025b0302
ME
3417 }
3418 }
025b0302 3419
8f78d0e9 3420 return format;
025b0302
ME
3421}
3422
8f78d0e9
KR
3423/* Convert from a selector string into a selector type. */
3424
3425static int
025b0302
ME
3426pa_chk_field_selector (str)
3427 char **str;
3428{
4047ff1d
JL
3429 int middle, low, high;
3430 int cmp;
3431 char name[3];
025b0302 3432
8f78d0e9 3433 /* Read past any whitespace. */
4047ff1d 3434 /* FIXME: should we read past newlines and formfeeds??? */
025b0302 3435 while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
8f78d0e9
KR
3436 *str = *str + 1;
3437
4047ff1d
JL
3438 if ((*str)[1] == '\'' || (*str)[1] == '%')
3439 name[0] = tolower ((*str)[0]),
3440 name[1] = 0;
3441 else if ((*str)[2] == '\'' || (*str)[2] == '%')
3442 name[0] = tolower ((*str)[0]),
3443 name[1] = tolower ((*str)[1]),
3444 name[2] = 0;
3445 else
3446 return e_fsel;
3447
3448 low = 0;
3449 high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
3450
3451 do
025b0302 3452 {
4047ff1d
JL
3453 middle = (low + high) / 2;
3454 cmp = strcmp (name, selector_table[middle].prefix);
3455 if (cmp < 0)
3456 high = middle - 1;
3457 else if (cmp > 0)
3458 low = middle + 1;
3459 else
025b0302 3460 {
4047ff1d
JL
3461 *str += strlen (name) + 1;
3462 return selector_table[middle].field_selector;
025b0302
ME
3463 }
3464 }
4047ff1d
JL
3465 while (low <= high);
3466
3467 return e_fsel;
025b0302
ME
3468}
3469
c5e9ccd0 3470/* Mark (via expr_end) the end of an expression (I think). FIXME. */
025b0302 3471
8f78d0e9
KR
3472static int
3473get_expression (str)
025b0302
ME
3474 char *str;
3475{
3476 char *save_in;
8f78d0e9 3477 asection *seg;
025b0302
ME
3478
3479 save_in = input_line_pointer;
3480 input_line_pointer = str;
5cf4cd1b
KR
3481 seg = expression (&the_insn.exp);
3482 if (!(seg == absolute_section
3483 || seg == undefined_section
3484 || SEG_NORMAL (seg)))
025b0302 3485 {
c5e9ccd0 3486 as_warn ("Bad segment in expression.");
025b0302
ME
3487 expr_end = input_line_pointer;
3488 input_line_pointer = save_in;
3489 return 1;
3490 }
3491 expr_end = input_line_pointer;
3492 input_line_pointer = save_in;
3493 return 0;
3494}
3495
8f78d0e9
KR
3496/* Mark (via expr_end) the end of an absolute expression. FIXME. */
3497static int
48153d49
JL
3498pa_get_absolute_expression (insn, strp)
3499 struct pa_it *insn;
3500 char **strp;
025b0302
ME
3501{
3502 char *save_in;
025b0302 3503
48153d49 3504 insn->field_selector = pa_chk_field_selector (strp);
025b0302 3505 save_in = input_line_pointer;
48153d49
JL
3506 input_line_pointer = *strp;
3507 expression (&insn->exp);
3508 if (insn->exp.X_op != O_constant)
025b0302 3509 {
48153d49 3510 as_bad ("Bad segment (should be absolute).");
025b0302
ME
3511 expr_end = input_line_pointer;
3512 input_line_pointer = save_in;
48153d49 3513 return 0;
025b0302
ME
3514 }
3515 expr_end = input_line_pointer;
3516 input_line_pointer = save_in;
48153d49 3517 return evaluate_absolute (insn);
025b0302
ME
3518}
3519
8f78d0e9
KR
3520/* Evaluate an absolute expression EXP which may be modified by
3521 the selector FIELD_SELECTOR. Return the value of the expression. */
3522static int
48153d49
JL
3523evaluate_absolute (insn)
3524 struct pa_it *insn;
025b0302
ME
3525{
3526 int value;
f41f3d72 3527 expressionS exp;
48153d49 3528 int field_selector = insn->field_selector;
025b0302 3529
f41f3d72 3530 exp = insn->exp;
025b0302
ME
3531 value = exp.X_add_number;
3532
025b0302
ME
3533 switch (field_selector)
3534 {
8f78d0e9
KR
3535 /* No change. */
3536 case e_fsel:
025b0302
ME
3537 break;
3538
8f78d0e9
KR
3539 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3540 case e_lssel:
025b0302
ME
3541 if (value & 0x00000400)
3542 value += 0x800;
3543 value = (value & 0xfffff800) >> 11;
3544 break;
3545
8f78d0e9
KR
3546 /* Sign extend from bit 21. */
3547 case e_rssel:
025b0302
ME
3548 if (value & 0x00000400)
3549 value |= 0xfffff800;
3550 else
3551 value &= 0x7ff;
3552 break;
3553
8f78d0e9
KR
3554 /* Arithmetic shift right 11 bits. */
3555 case e_lsel:
025b0302
ME
3556 value = (value & 0xfffff800) >> 11;
3557 break;
3558
8f78d0e9
KR
3559 /* Set bits 0-20 to zero. */
3560 case e_rsel:
025b0302
ME
3561 value = value & 0x7ff;
3562 break;
3563
8f78d0e9
KR
3564 /* Add 0x800 and arithmetic shift right 11 bits. */
3565 case e_ldsel:
025b0302 3566 value += 0x800;
025b0302
ME
3567 value = (value & 0xfffff800) >> 11;
3568 break;
3569
8f78d0e9
KR
3570 /* Set bitgs 0-21 to one. */
3571 case e_rdsel:
3572 value |= 0xfffff800;
025b0302
ME
3573 break;
3574
7b624bf2 3575#define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
8f78d0e9 3576 case e_rrsel:
7b624bf2
JL
3577 value = (RSEL_ROUND (value) & 0x7ff) + (value - RSEL_ROUND (value));
3578 break;
3579
8f78d0e9 3580 case e_lrsel:
7b624bf2
JL
3581 value = (RSEL_ROUND (value) >> 11) & 0x1fffff;
3582 break;
3583#undef RSEL_ROUND
8f78d0e9 3584
025b0302
ME
3585 default:
3586 BAD_CASE (field_selector);
3587 break;
3588 }
3589 return value;
3590}
3591
8f78d0e9
KR
3592/* Given an argument location specification return the associated
3593 argument location number. */
3594
3595static unsigned int
025b0302
ME
3596pa_build_arg_reloc (type_name)
3597 char *type_name;
3598{
3599
3600 if (strncasecmp (type_name, "no", 2) == 0)
8f78d0e9 3601 return 0;
025b0302 3602 if (strncasecmp (type_name, "gr", 2) == 0)
8f78d0e9 3603 return 1;
025b0302 3604 else if (strncasecmp (type_name, "fr", 2) == 0)
8f78d0e9 3605 return 2;
025b0302 3606 else if (strncasecmp (type_name, "fu", 2) == 0)
8f78d0e9 3607 return 3;
025b0302 3608 else
8f78d0e9 3609 as_bad ("Invalid argument location: %s\n", type_name);
025b0302
ME
3610
3611 return 0;
3612}
3613
8f78d0e9
KR
3614/* Encode and return an argument relocation specification for
3615 the given register in the location specified by arg_reloc. */
3616
3617static unsigned int
025b0302
ME
3618pa_align_arg_reloc (reg, arg_reloc)
3619 unsigned int reg;
3620 unsigned int arg_reloc;
3621{
3622 unsigned int new_reloc;
3623
3624 new_reloc = arg_reloc;
3625 switch (reg)
3626 {
3627 case 0:
3628 new_reloc <<= 8;
3629 break;
3630 case 1:
3631 new_reloc <<= 6;
3632 break;
3633 case 2:
3634 new_reloc <<= 4;
3635 break;
3636 case 3:
3637 new_reloc <<= 2;
3638 break;
3639 default:
8f78d0e9 3640 as_bad ("Invalid argument description: %d", reg);
025b0302
ME
3641 }
3642
3643 return new_reloc;
3644}
3645
8f78d0e9
KR
3646/* Parse a PA nullification completer (,n). Return nonzero if the
3647 completer was found; return zero if no completer was found. */
3648
3649static int
025b0302
ME
3650pa_parse_nullif (s)
3651 char **s;
3652{
3653 int nullif;
3654
3655 nullif = 0;
3656 if (**s == ',')
3657 {
3658 *s = *s + 1;
3659 if (strncasecmp (*s, "n", 1) == 0)
3660 nullif = 1;
3661 else
3662 {
8f78d0e9 3663 as_bad ("Invalid Nullification: (%c)", **s);
025b0302
ME
3664 nullif = 0;
3665 }
3666 *s = *s + 1;
3667 }
025b0302
ME
3668
3669 return nullif;
3670}
3671
8f78d0e9
KR
3672/* Parse a non-negated compare/subtract completer returning the
3673 number (for encoding in instrutions) of the given completer.
3674
3675 ISBRANCH specifies whether or not this is parsing a condition
3676 completer for a branch (vs a nullification completer for a
3677 computational instruction. */
3678
3679static int
5cf4cd1b 3680pa_parse_nonneg_cmpsub_cmpltr (s, isbranch)
025b0302 3681 char **s;
5cf4cd1b 3682 int isbranch;
025b0302
ME
3683{
3684 int cmpltr;
5cf4cd1b 3685 char *name = *s + 1;
025b0302 3686 char c;
5cf4cd1b 3687 char *save_s = *s;
025b0302 3688
5cf4cd1b 3689 cmpltr = 0;
025b0302
ME
3690 if (**s == ',')
3691 {
3692 *s += 1;
025b0302
ME
3693 while (**s != ',' && **s != ' ' && **s != '\t')
3694 *s += 1;
3695 c = **s;
3696 **s = 0x00;
3697 if (strcmp (name, "=") == 0)
3698 {
3699 cmpltr = 1;
3700 }
3701 else if (strcmp (name, "<") == 0)
3702 {
3703 cmpltr = 2;
3704 }
3705 else if (strcmp (name, "<=") == 0)
3706 {
3707 cmpltr = 3;
3708 }
3709 else if (strcmp (name, "<<") == 0)
3710 {
3711 cmpltr = 4;
3712 }
3713 else if (strcmp (name, "<<=") == 0)
3714 {
3715 cmpltr = 5;
3716 }
3717 else if (strcasecmp (name, "sv") == 0)
3718 {
3719 cmpltr = 6;
3720 }
3721 else if (strcasecmp (name, "od") == 0)
3722 {
3723 cmpltr = 7;
3724 }
5cf4cd1b 3725 /* If we have something like addb,n then there is no condition
8f78d0e9 3726 completer. */
5cf4cd1b 3727 else if (strcasecmp (name, "n") == 0 && isbranch)
025b0302 3728 {
5cf4cd1b 3729 cmpltr = 0;
025b0302 3730 }
8f78d0e9 3731 else
025b0302 3732 {
5cf4cd1b 3733 cmpltr = -1;
025b0302 3734 }
025b0302
ME
3735 **s = c;
3736 }
025b0302 3737
5cf4cd1b
KR
3738 /* Reset pointers if this was really a ,n for a branch instruction. */
3739 if (cmpltr == 0 && *name == 'n' && isbranch)
3740 *s = save_s;
3741
025b0302
ME
3742 return cmpltr;
3743}
3744
8f78d0e9
KR
3745/* Parse a negated compare/subtract completer returning the
3746 number (for encoding in instrutions) of the given completer.
3747
3748 ISBRANCH specifies whether or not this is parsing a condition
3749 completer for a branch (vs a nullification completer for a
3750 computational instruction. */
3751
3752static int
5cf4cd1b 3753pa_parse_neg_cmpsub_cmpltr (s, isbranch)
025b0302 3754 char **s;
5cf4cd1b 3755 int isbranch;
025b0302
ME
3756{
3757 int cmpltr;
5cf4cd1b 3758 char *name = *s + 1;
025b0302 3759 char c;
5cf4cd1b 3760 char *save_s = *s;
025b0302 3761
5cf4cd1b 3762 cmpltr = 0;
025b0302
ME
3763 if (**s == ',')
3764 {
3765 *s += 1;
025b0302
ME
3766 while (**s != ',' && **s != ' ' && **s != '\t')
3767 *s += 1;
3768 c = **s;
3769 **s = 0x00;
3770 if (strcasecmp (name, "tr") == 0)
3771 {
3772 cmpltr = 0;
3773 }
3774 else if (strcmp (name, "<>") == 0)
3775 {
3776 cmpltr = 1;
3777 }
3778 else if (strcmp (name, ">=") == 0)
3779 {
3780 cmpltr = 2;
3781 }
3782 else if (strcmp (name, ">") == 0)
3783 {
3784 cmpltr = 3;
3785 }
3786 else if (strcmp (name, ">>=") == 0)
3787 {
3788 cmpltr = 4;
3789 }
3790 else if (strcmp (name, ">>") == 0)
3791 {
3792 cmpltr = 5;
3793 }
3794 else if (strcasecmp (name, "nsv") == 0)
3795 {
3796 cmpltr = 6;
3797 }
3798 else if (strcasecmp (name, "ev") == 0)
3799 {
3800 cmpltr = 7;
3801 }
5cf4cd1b 3802 /* If we have something like addb,n then there is no condition
8f78d0e9 3803 completer. */
5cf4cd1b
KR
3804 else if (strcasecmp (name, "n") == 0 && isbranch)
3805 {
3806 cmpltr = 0;
3807 }
3808 else
3809 {
3810 cmpltr = -1;
3811 }
025b0302
ME
3812 **s = c;
3813 }
025b0302 3814
5cf4cd1b
KR
3815 /* Reset pointers if this was really a ,n for a branch instruction. */
3816 if (cmpltr == 0 && *name == 'n' && isbranch)
3817 *s = save_s;
3818
025b0302
ME
3819 return cmpltr;
3820}
3821
8f78d0e9
KR
3822/* Parse a non-negated addition completer returning the number
3823 (for encoding in instrutions) of the given completer.
3824
3825 ISBRANCH specifies whether or not this is parsing a condition
3826 completer for a branch (vs a nullification completer for a
3827 computational instruction. */
3828
3829static int
5cf4cd1b 3830pa_parse_nonneg_add_cmpltr (s, isbranch)
025b0302 3831 char **s;
5cf4cd1b 3832 int isbranch;
025b0302
ME
3833{
3834 int cmpltr;
5cf4cd1b 3835 char *name = *s + 1;
025b0302 3836 char c;
5cf4cd1b 3837 char *save_s = *s;
025b0302 3838
5cf4cd1b 3839 cmpltr = 0;
025b0302
ME
3840 if (**s == ',')
3841 {
3842 *s += 1;
025b0302
ME
3843 while (**s != ',' && **s != ' ' && **s != '\t')
3844 *s += 1;
3845 c = **s;
3846 **s = 0x00;
3847 if (strcmp (name, "=") == 0)
3848 {
3849 cmpltr = 1;
3850 }
3851 else if (strcmp (name, "<") == 0)
3852 {
3853 cmpltr = 2;
3854 }
3855 else if (strcmp (name, "<=") == 0)
3856 {
3857 cmpltr = 3;
3858 }
3859 else if (strcasecmp (name, "nuv") == 0)
3860 {
3861 cmpltr = 4;
3862 }
3863 else if (strcasecmp (name, "znv") == 0)
3864 {
3865 cmpltr = 5;
3866 }
3867 else if (strcasecmp (name, "sv") == 0)
3868 {
3869 cmpltr = 6;
3870 }
3871 else if (strcasecmp (name, "od") == 0)
3872 {
3873 cmpltr = 7;
3874 }
5cf4cd1b 3875 /* If we have something like addb,n then there is no condition
8f78d0e9 3876 completer. */
5cf4cd1b
KR
3877 else if (strcasecmp (name, "n") == 0 && isbranch)
3878 {
3879 cmpltr = 0;
3880 }
3881 else
3882 {
3883 cmpltr = -1;
3884 }
025b0302
ME
3885 **s = c;
3886 }
025b0302 3887
5cf4cd1b
KR
3888 /* Reset pointers if this was really a ,n for a branch instruction. */
3889 if (cmpltr == 0 && *name == 'n' && isbranch)
3890 *s = save_s;
3891
025b0302
ME
3892 return cmpltr;
3893}
3894
8f78d0e9
KR
3895/* Parse a negated addition completer returning the number
3896 (for encoding in instrutions) of the given completer.
3897
3898 ISBRANCH specifies whether or not this is parsing a condition
3899 completer for a branch (vs a nullification completer for a
3900 computational instruction. */
3901
3902static int
5cf4cd1b 3903pa_parse_neg_add_cmpltr (s, isbranch)
025b0302 3904 char **s;
5cf4cd1b 3905 int isbranch;
025b0302
ME
3906{
3907 int cmpltr;
5cf4cd1b 3908 char *name = *s + 1;
025b0302 3909 char c;
5cf4cd1b 3910 char *save_s = *s;
025b0302 3911
5cf4cd1b 3912 cmpltr = 0;
025b0302
ME
3913 if (**s == ',')
3914 {
3915 *s += 1;
025b0302
ME
3916 while (**s != ',' && **s != ' ' && **s != '\t')
3917 *s += 1;
3918 c = **s;
3919 **s = 0x00;
3920 if (strcasecmp (name, "tr") == 0)
3921 {
3922 cmpltr = 0;
3923 }
3924 else if (strcmp (name, "<>") == 0)
3925 {
3926 cmpltr = 1;
3927 }
3928 else if (strcmp (name, ">=") == 0)
3929 {
3930 cmpltr = 2;
3931 }
3932 else if (strcmp (name, ">") == 0)
3933 {
3934 cmpltr = 3;
3935 }
4047ff1d 3936 else if (strcasecmp (name, "uv") == 0)
025b0302
ME
3937 {
3938 cmpltr = 4;
3939 }
4047ff1d 3940 else if (strcasecmp (name, "vnz") == 0)
025b0302
ME
3941 {
3942 cmpltr = 5;
3943 }
3944 else if (strcasecmp (name, "nsv") == 0)
3945 {
3946 cmpltr = 6;
3947 }
3948 else if (strcasecmp (name, "ev") == 0)
3949 {
3950 cmpltr = 7;
3951 }
5cf4cd1b 3952 /* If we have something like addb,n then there is no condition
8f78d0e9 3953 completer. */
5cf4cd1b
KR
3954 else if (strcasecmp (name, "n") == 0 && isbranch)
3955 {
3956 cmpltr = 0;
3957 }
3958 else
3959 {
3960 cmpltr = -1;
3961 }
025b0302
ME
3962 **s = c;
3963 }
025b0302 3964
5cf4cd1b
KR
3965 /* Reset pointers if this was really a ,n for a branch instruction. */
3966 if (cmpltr == 0 && *name == 'n' && isbranch)
3967 *s = save_s;
3968
025b0302
ME
3969 return cmpltr;
3970}
3971
8f78d0e9 3972/* Handle a .BLOCK type pseudo-op. */
025b0302 3973
8f78d0e9 3974static void
025b0302
ME
3975pa_block (z)
3976 int z;
3977{
8f78d0e9
KR
3978 char *p;
3979 long int temp_fill;
3980 unsigned int temp_size;
3981 int i;
025b0302
ME
3982
3983 temp_size = get_absolute_expression ();
3984
8f78d0e9
KR
3985 /* Always fill with zeros, that's what the HP assembler does. */
3986 temp_fill = 0;
025b0302 3987
c5e9ccd0 3988 p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
8f78d0e9
KR
3989 (relax_substateT) 0, (symbolS *) 0, 1, NULL);
3990 bzero (p, temp_size);
025b0302 3991
8f78d0e9 3992 /* Convert 2 bytes at a time. */
025b0302
ME
3993
3994 for (i = 0; i < temp_size; i += 2)
3995 {
3996 md_number_to_chars (p + i,
8f78d0e9 3997 (valueT) temp_fill,
025b0302
ME
3998 (int) ((temp_size - i) > 2 ? 2 : (temp_size - i)));
3999 }
4000
4001 pa_undefine_label ();
4002 demand_empty_rest_of_line ();
025b0302
ME
4003}
4004
8f78d0e9
KR
4005/* Handle a .CALL pseudo-op. This involves storing away information
4006 about where arguments are to be found so the linker can detect
4007 (and correct) argument location mismatches between caller and callee. */
025b0302 4008
8f78d0e9
KR
4009static void
4010pa_call (unused)
4011 int unused;
4012{
025b0302
ME
4013 pa_call_args (&last_call_desc);
4014 demand_empty_rest_of_line ();
025b0302
ME
4015}
4016
8f78d0e9
KR
4017/* Do the dirty work of building a call descriptor which describes
4018 where the caller placed arguments to a function call. */
4019
4020static void
025b0302 4021pa_call_args (call_desc)
8f78d0e9 4022 struct call_desc *call_desc;
025b0302 4023{
8f78d0e9
KR
4024 char *name, c, *p;
4025 unsigned int temp, arg_reloc;
025b0302
ME
4026
4027 while (!is_end_of_statement ())
4028 {
4029 name = input_line_pointer;
4030 c = get_symbol_end ();
8f78d0e9 4031 /* Process a source argument. */
025b0302
ME
4032 if ((strncasecmp (name, "argw", 4) == 0))
4033 {
4034 temp = atoi (name + 4);
4035 p = input_line_pointer;
4036 *p = c;
4037 input_line_pointer++;
4038 name = input_line_pointer;
4039 c = get_symbol_end ();
4040 arg_reloc = pa_build_arg_reloc (name);
4041 call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
4042 }
8f78d0e9 4043 /* Process a return value. */
025b0302
ME
4044 else if ((strncasecmp (name, "rtnval", 6) == 0))
4045 {
4046 p = input_line_pointer;
4047 *p = c;
4048 input_line_pointer++;
4049 name = input_line_pointer;
4050 c = get_symbol_end ();
4051 arg_reloc = pa_build_arg_reloc (name);
4052 call_desc->arg_reloc |= (arg_reloc & 0x3);
4053 }
4054 else
4055 {
8f78d0e9 4056 as_bad ("Invalid .CALL argument: %s", name);
025b0302
ME
4057 }
4058 p = input_line_pointer;
4059 *p = c;
4060 if (!is_end_of_statement ())
4061 input_line_pointer++;
4062 }
4063}
4064
8f78d0e9
KR
4065/* Return TRUE if FRAG1 and FRAG2 are the same. */
4066
025b0302 4067static int
8f78d0e9
KR
4068is_same_frag (frag1, frag2)
4069 fragS *frag1;
4070 fragS *frag2;
025b0302
ME
4071{
4072
8f78d0e9 4073 if (frag1 == NULL)
025b0302 4074 return (FALSE);
8f78d0e9 4075 else if (frag2 == NULL)
025b0302 4076 return (FALSE);
8f78d0e9 4077 else if (frag1 == frag2)
025b0302 4078 return (TRUE);
8f78d0e9
KR
4079 else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0)
4080 return (is_same_frag (frag1, frag2->fr_next));
025b0302
ME
4081 else
4082 return (FALSE);
4083}
4084
ff852e11
JL
4085#ifdef OBJ_ELF
4086/* Build an entry in the UNWIND subspace from the given function
4087 attributes in CALL_INFO. This is not needed for SOM as using
4088 R_ENTRY and R_EXIT relocations allow the linker to handle building
4089 of the unwind spaces. */
c5e9ccd0 4090
025b0302
ME
4091static void
4092pa_build_unwind_subspace (call_info)
8f78d0e9 4093 struct call_info *call_info;
025b0302 4094{
8f78d0e9
KR
4095 char *unwind;
4096 asection *seg, *save_seg;
025b0302
ME
4097 subsegT subseg, save_subseg;
4098 int i;
8f78d0e9
KR
4099 char c, *p;
4100
4101 /* Get into the right seg/subseg. This may involve creating
4102 the seg the first time through. Make sure to have the
4103 old seg/subseg so that we can reset things when we are done. */
4104 subseg = SUBSEG_UNWIND;
4105 seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
4106 if (seg == ASEC_NULL)
025b0302 4107 {
8f78d0e9
KR
4108 seg = bfd_make_section_old_way (stdoutput, UNWIND_SECTION_NAME);
4109 bfd_set_section_flags (stdoutput, seg,
4110 SEC_READONLY | SEC_HAS_CONTENTS
4111 | SEC_LOAD | SEC_RELOC);
025b0302
ME
4112 }
4113
025b0302
ME
4114 save_seg = now_seg;
4115 save_subseg = now_subseg;
80aab579 4116 subseg_set (seg, subseg);
025b0302 4117
8f78d0e9
KR
4118
4119 /* Get some space to hold relocation information for the unwind
4120 descriptor. */
025b0302 4121 p = frag_more (4);
025b0302 4122
8f78d0e9 4123 /* Relocation info. for start offset of the function. */
8f78d0e9
KR
4124 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4125 call_info->start_symbol, (offsetT) 0,
4126 (expressionS *) NULL, 0, R_HPPA_UNWIND, e_fsel, 32, 0,
4127 (char *) 0);
025b0302 4128
025b0302 4129 p = frag_more (4);
025b0302 4130
8f78d0e9 4131 /* Relocation info. for end offset of the function. */
8f78d0e9
KR
4132 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4133 call_info->end_symbol, (offsetT) 0,
4134 (expressionS *) NULL, 0, R_HPPA_UNWIND, e_fsel, 32, 0,
4135 (char *) 0);
025b0302 4136
8f78d0e9
KR
4137 /* Dump it. */
4138 unwind = (char *) &call_info->ci_unwind;
4139 for (i = 8; i < sizeof (struct unwind_table); i++)
025b0302 4140 {
8f78d0e9 4141 c = *(unwind + i);
025b0302
ME
4142 {
4143 FRAG_APPEND_1_CHAR (c);
4144 }
4145 }
4146
8f78d0e9 4147 /* Return back to the original segment/subsegment. */
80aab579 4148 subseg_set (save_seg, save_subseg);
025b0302 4149}
ff852e11 4150#endif
025b0302 4151
8f78d0e9
KR
4152/* Process a .CALLINFO pseudo-op. This information is used later
4153 to build unwind descriptors and maybe one day to support
4154 .ENTER and .LEAVE. */
025b0302 4155
8f78d0e9
KR
4156static void
4157pa_callinfo (unused)
4158 int unused;
025b0302 4159{
8f78d0e9
KR
4160 char *name, c, *p;
4161 int temp;
025b0302 4162
8f78d0e9 4163 /* .CALLINFO must appear within a procedure definition. */
025b0302
ME
4164 if (!within_procedure)
4165 as_bad (".callinfo is not within a procedure definition");
4166
8f78d0e9
KR
4167 /* Mark the fact that we found the .CALLINFO for the
4168 current procedure. */
025b0302
ME
4169 callinfo_found = TRUE;
4170
8f78d0e9 4171 /* Iterate over the .CALLINFO arguments. */
025b0302
ME
4172 while (!is_end_of_statement ())
4173 {
4174 name = input_line_pointer;
4175 c = get_symbol_end ();
8f78d0e9 4176 /* Frame size specification. */
025b0302
ME
4177 if ((strncasecmp (name, "frame", 5) == 0))
4178 {
4179 p = input_line_pointer;
4180 *p = c;
4181 input_line_pointer++;
4182 temp = get_absolute_expression ();
4183 if ((temp & 0x3) != 0)
4184 {
4185 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp);
4186 temp = 0;
4187 }
49fc68a1 4188
c5e9ccd0 4189 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
49fc68a1
JL
4190 last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
4191
025b0302 4192 }
8f78d0e9 4193 /* Entry register (GR, GR and SR) specifications. */
025b0302
ME
4194 else if ((strncasecmp (name, "entry_gr", 8) == 0))
4195 {
4196 p = input_line_pointer;
4197 *p = c;
4198 input_line_pointer++;
4199 temp = get_absolute_expression ();
aa8b30ed
JL
4200 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4201 even though %r19 is caller saved. I think this is a bug in
4202 the HP assembler, and we are not going to emulate it. */
4203 if (temp < 3 || temp > 18)
4204 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4205 last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
025b0302
ME
4206 }
4207 else if ((strncasecmp (name, "entry_fr", 8) == 0))
4208 {
4209 p = input_line_pointer;
4210 *p = c;
4211 input_line_pointer++;
4212 temp = get_absolute_expression ();
aa8b30ed
JL
4213 /* Similarly the HP assembler takes 31 as the high bound even
4214 though %fr21 is the last callee saved floating point register. */
4215 if (temp < 12 || temp > 21)
4216 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4217 last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
025b0302
ME
4218 }
4219 else if ((strncasecmp (name, "entry_sr", 8) == 0))
4220 {
4221 p = input_line_pointer;
4222 *p = c;
4223 input_line_pointer++;
4224 temp = get_absolute_expression ();
aa8b30ed
JL
4225 if (temp != 3)
4226 as_bad ("Value for ENTRY_SR must be 3\n");
025b0302 4227 }
8f78d0e9 4228 /* Note whether or not this function performs any calls. */
025b0302
ME
4229 else if ((strncasecmp (name, "calls", 5) == 0) ||
4230 (strncasecmp (name, "caller", 6) == 0))
4231 {
4232 p = input_line_pointer;
4233 *p = c;
025b0302
ME
4234 }
4235 else if ((strncasecmp (name, "no_calls", 8) == 0))
4236 {
4237 p = input_line_pointer;
4238 *p = c;
025b0302 4239 }
8f78d0e9 4240 /* Should RP be saved into the stack. */
025b0302
ME
4241 else if ((strncasecmp (name, "save_rp", 7) == 0))
4242 {
4243 p = input_line_pointer;
4244 *p = c;
4245 last_call_info->ci_unwind.descriptor.save_rp = 1;
4246 }
8f78d0e9 4247 /* Likewise for SP. */
025b0302
ME
4248 else if ((strncasecmp (name, "save_sp", 7) == 0))
4249 {
4250 p = input_line_pointer;
4251 *p = c;
4252 last_call_info->ci_unwind.descriptor.save_sp = 1;
4253 }
8f78d0e9 4254 /* Is this an unwindable procedure. If so mark it so
c5e9ccd0 4255 in the unwind descriptor. */
025b0302
ME
4256 else if ((strncasecmp (name, "no_unwind", 9) == 0))
4257 {
4258 p = input_line_pointer;
4259 *p = c;
4260 last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
4261 }
8f78d0e9 4262 /* Is this an interrupt routine. If so mark it in the
c5e9ccd0 4263 unwind descriptor. */
025b0302
ME
4264 else if ((strncasecmp (name, "hpux_int", 7) == 0))
4265 {
4266 p = input_line_pointer;
4267 *p = c;
8f78d0e9 4268 last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
025b0302
ME
4269 }
4270 else
4271 {
8f78d0e9 4272 as_bad ("Invalid .CALLINFO argument: %s", name);
025b0302
ME
4273 }
4274 if (!is_end_of_statement ())
4275 input_line_pointer++;
4276 }
4277
4278 demand_empty_rest_of_line ();
025b0302
ME
4279}
4280
8f78d0e9
KR
4281/* Switch into the code subspace. */
4282
4283static void
4284pa_code (unused)
4285 int unused;
025b0302 4286{
8f78d0e9 4287 sd_chain_struct *sdchain;
025b0302 4288
8f78d0e9
KR
4289 /* First time through it might be necessary to create the
4290 $TEXT$ space. */
025b0302
ME
4291 if ((sdchain = is_defined_space ("$TEXT$")) == NULL)
4292 {
8f78d0e9
KR
4293 sdchain = create_new_space (pa_def_spaces[0].name,
4294 pa_def_spaces[0].spnum,
4295 pa_def_spaces[0].loadable,
4296 pa_def_spaces[0].defined,
4297 pa_def_spaces[0].private,
4298 pa_def_spaces[0].sort,
4299 pa_def_spaces[0].segment, 0);
025b0302
ME
4300 }
4301
4302 SPACE_DEFINED (sdchain) = 1;
80aab579 4303 subseg_set (text_section, SUBSEG_CODE);
025b0302 4304 demand_empty_rest_of_line ();
025b0302
ME
4305}
4306
8f78d0e9
KR
4307/* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4308 the .comm pseudo-op has the following symtax:
025b0302 4309
8f78d0e9
KR
4310 <label> .comm <length>
4311
4312 where <label> is optional and is a symbol whose address will be the start of
4313 a block of memory <length> bytes long. <length> must be an absolute
4314 expression. <length> bytes will be allocated in the current space
4315 and subspace. */
4316
4317static void
4318pa_comm (unused)
4319 int unused;
025b0302 4320{
8f78d0e9
KR
4321 unsigned int size;
4322 symbolS *symbol;
4323 label_symbol_struct *label_symbol = pa_get_label ();
025b0302 4324
8f78d0e9
KR
4325 if (label_symbol)
4326 symbol = label_symbol->lss_label;
025b0302 4327 else
8f78d0e9 4328 symbol = NULL;
025b0302
ME
4329
4330 SKIP_WHITESPACE ();
8f78d0e9 4331 size = get_absolute_expression ();
025b0302 4332
8f78d0e9 4333 if (symbol)
025b0302 4334 {
d56f45f5 4335 /* It is incorrect to check S_IS_DEFINED at this point as
c5e9ccd0
JL
4336 the symbol will *always* be defined. FIXME. How to
4337 correctly determine when this label really as been
4338 defined before. */
8f78d0e9 4339 if (S_GET_VALUE (symbol))
025b0302 4340 {
8f78d0e9 4341 if (S_GET_VALUE (symbol) != size)
025b0302 4342 {
8f78d0e9
KR
4343 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4344 S_GET_NAME (symbol), S_GET_VALUE (symbol));
025b0302
ME
4345 return;
4346 }
4347 }
4348 else
4349 {
8f78d0e9 4350 S_SET_VALUE (symbol, size);
aa8b30ed 4351 S_SET_SEGMENT (symbol, &bfd_und_section);
8f78d0e9 4352 S_SET_EXTERNAL (symbol);
025b0302 4353 }
025b0302 4354 }
025b0302
ME
4355 demand_empty_rest_of_line ();
4356}
4357
8f78d0e9 4358/* Process a .END pseudo-op. */
025b0302 4359
8f78d0e9
KR
4360static void
4361pa_end (unused)
4362 int unused;
4363{
025b0302 4364 demand_empty_rest_of_line ();
025b0302
ME
4365}
4366
c5e9ccd0 4367/* Process a .ENTER pseudo-op. This is not supported. */
8f78d0e9
KR
4368static void
4369pa_enter (unused)
4370 int unused;
025b0302 4371{
c5e9ccd0 4372 abort ();
025b0302
ME
4373}
4374
8f78d0e9
KR
4375/* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4376 procesure. */
4377static void
4378pa_entry (unused)
4379 int unused;
025b0302 4380{
025b0302
ME
4381 if (!within_procedure)
4382 as_bad ("Misplaced .entry. Ignored.");
4383 else
4384 {
4385 if (!callinfo_found)
4386 as_bad ("Missing .callinfo.");
025b0302
ME
4387 }
4388 demand_empty_rest_of_line ();
4389 within_entry_exit = TRUE;
8f78d0e9 4390
ff852e11
JL
4391#ifdef OBJ_SOM
4392 /* SOM defers building of unwind descriptors until the link phase.
4393 The assembler is responsible for creating an R_ENTRY relocation
4394 to mark the beginning of a region and hold the unwind bits, and
4395 for creating an R_EXIT relocation to mark the end of the region.
4396
4397 FIXME. ELF should be using the same conventions! The problem
4398 is an unwind requires too much relocation space. Hmmm. Maybe
4399 if we split the unwind bits up between the relocations which
4400 denote the entry and exit points. */
86066d06
JL
4401 if (last_call_info->start_symbol != NULL)
4402 {
4403 char *where = frag_more (0);
c5e9ccd0 4404
86066d06
JL
4405 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4406 last_call_info->start_symbol, (offsetT) 0, NULL,
4407 0, R_HPPA_ENTRY, e_fsel, 0, 0,
4408 (char *) &last_call_info->ci_unwind.descriptor);
4409 }
ff852e11 4410#endif
025b0302
ME
4411}
4412
8f78d0e9
KR
4413/* Handle a .EQU pseudo-op. */
4414
4415static void
025b0302
ME
4416pa_equ (reg)
4417 int reg;
4418{
8f78d0e9
KR
4419 label_symbol_struct *label_symbol = pa_get_label ();
4420 symbolS *symbol;
025b0302 4421
8f78d0e9 4422 if (label_symbol)
025b0302 4423 {
8f78d0e9
KR
4424 symbol = label_symbol->lss_label;
4425 S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ());
4426 S_SET_SEGMENT (symbol, &bfd_abs_section);
025b0302
ME
4427 }
4428 else
4429 {
4430 if (reg)
4431 as_bad (".REG must use a label");
4432 else
4433 as_bad (".EQU must use a label");
4434 }
4435
4436 pa_undefine_label ();
4437 demand_empty_rest_of_line ();
025b0302
ME
4438}
4439
8f78d0e9
KR
4440/* Helper function. Does processing for the end of a function. This
4441 usually involves creating some relocations or building special
4442 symbols to mark the end of the function. */
4443
4444static void
025b0302
ME
4445process_exit ()
4446{
4447 char *where;
4448
4449 where = frag_more (0);
aa8b30ed 4450
ff852e11 4451#ifdef OBJ_ELF
44c0de53
JL
4452 /* Mark the end of the function, stuff away the location of the frag
4453 for the end of the function, and finally call pa_build_unwind_subspace
4454 to add an entry in the unwind table. */
4455 hppa_elf_mark_end_of_function ();
025b0302 4456 pa_build_unwind_subspace (last_call_info);
ff852e11
JL
4457#else
4458 /* SOM defers building of unwind descriptors until the link phase.
4459 The assembler is responsible for creating an R_ENTRY relocation
4460 to mark the beginning of a region and hold the unwind bits, and
4461 for creating an R_EXIT relocation to mark the end of the region.
4462
4463 FIXME. ELF should be using the same conventions! The problem
4464 is an unwind requires too much relocation space. Hmmm. Maybe
4465 if we split the unwind bits up between the relocations which
4466 denote the entry and exit points. */
4467 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4468 last_call_info->start_symbol, (offsetT) 0,
4469 NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0, NULL);
4470#endif
025b0302
ME
4471}
4472
8f78d0e9 4473/* Process a .EXIT pseudo-op. */
025b0302 4474
8f78d0e9
KR
4475static void
4476pa_exit (unused)
4477 int unused;
4478{
025b0302
ME
4479 if (!within_procedure)
4480 as_bad (".EXIT must appear within a procedure");
4481 else
4482 {
4483 if (!callinfo_found)
4484 as_bad ("Missing .callinfo");
4485 else
4486 {
4487 if (!within_entry_exit)
4488 as_bad ("No .ENTRY for this .EXIT");
4489 else
4490 {
4491 within_entry_exit = FALSE;
4492 process_exit ();
4493 }
4494 }
4495 }
4496 demand_empty_rest_of_line ();
025b0302
ME
4497}
4498
8f78d0e9
KR
4499/* Process a .EXPORT directive. This makes functions external
4500 and provides information such as argument relocation entries
4501 to callers. */
5cf4cd1b 4502
8f78d0e9
KR
4503static void
4504pa_export (unused)
4505 int unused;
025b0302 4506{
8f78d0e9
KR
4507 char *name, c, *p;
4508 symbolS *symbol;
025b0302
ME
4509
4510 name = input_line_pointer;
4511 c = get_symbol_end ();
8f78d0e9
KR
4512 /* Make sure the given symbol exists. */
4513 if ((symbol = symbol_find_or_make (name)) == NULL)
025b0302
ME
4514 {
4515 as_bad ("Cannot define export symbol: %s\n", name);
4516 p = input_line_pointer;
4517 *p = c;
4518 input_line_pointer++;
4519 }
4520 else
4521 {
8f78d0e9
KR
4522 /* OK. Set the external bits and process argument relocations. */
4523 S_SET_EXTERNAL (symbol);
025b0302
ME
4524 p = input_line_pointer;
4525 *p = c;
4526 if (!is_end_of_statement ())
4527 {
4528 input_line_pointer++;
48153d49 4529 pa_type_args (symbol, 1);
5cf4cd1b 4530#ifdef OBJ_ELF
8f78d0e9 4531 pa_build_symextn_section ();
5cf4cd1b 4532#endif
025b0302
ME
4533 }
4534 }
4535
4536 demand_empty_rest_of_line ();
025b0302
ME
4537}
4538
8f78d0e9
KR
4539/* Helper function to process arguments to a .EXPORT pseudo-op. */
4540
4541static void
48153d49 4542pa_type_args (symbolP, is_export)
8f78d0e9 4543 symbolS *symbolP;
48153d49 4544 int is_export;
025b0302 4545{
8f78d0e9
KR
4546 char *name, c, *p;
4547 unsigned int temp, arg_reloc;
e75acd68 4548 pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
8f78d0e9 4549 obj_symbol_type *symbol = (obj_symbol_type *) symbolP->bsym;
025b0302
ME
4550
4551 if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
48153d49 4552
025b0302
ME
4553 {
4554 input_line_pointer += 8;
9a182533 4555 symbolP->bsym->flags &= ~BSF_FUNCTION;
025b0302 4556 S_SET_SEGMENT (symbolP, &bfd_abs_section);
e75acd68 4557 type = SYMBOL_TYPE_ABSOLUTE;
025b0302
ME
4558 }
4559 else if (strncasecmp (input_line_pointer, "code", 4) == 0)
9a182533
JL
4560 {
4561 input_line_pointer += 4;
a721c80b 4562 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
c5e9ccd0 4563 instead one should be IMPORTing/EXPORTing ENTRY types.
a721c80b 4564
c5e9ccd0
JL
4565 Complain if one tries to EXPORT a CODE type since that's never
4566 done. Both GCC and HP C still try to IMPORT CODE types, so
4567 silently fix them to be ENTRY types. */
a721c80b 4568 if (symbolP->bsym->flags & BSF_FUNCTION)
48153d49 4569 {
a721c80b
JL
4570 if (is_export)
4571 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP->bsym->name);
4572
48153d49
JL
4573 symbolP->bsym->flags |= BSF_FUNCTION;
4574 type = SYMBOL_TYPE_ENTRY;
4575 }
4576 else
4577 {
4578 symbolP->bsym->flags &= ~BSF_FUNCTION;
4579 type = SYMBOL_TYPE_CODE;
4580 }
9a182533 4581 }
025b0302 4582 else if (strncasecmp (input_line_pointer, "data", 4) == 0)
9a182533
JL
4583 {
4584 input_line_pointer += 4;
4585 symbolP->bsym->flags &= ~BSF_FUNCTION;
e75acd68 4586 type = SYMBOL_TYPE_DATA;
9a182533 4587 }
025b0302
ME
4588 else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
4589 {
4590 input_line_pointer += 5;
025b0302 4591 symbolP->bsym->flags |= BSF_FUNCTION;
e75acd68 4592 type = SYMBOL_TYPE_ENTRY;
025b0302
ME
4593 }
4594 else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
4595 {
4596 input_line_pointer += 9;
9a182533 4597 symbolP->bsym->flags |= BSF_FUNCTION;
e75acd68 4598 type = SYMBOL_TYPE_MILLICODE;
025b0302
ME
4599 }
4600 else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
4601 {
4602 input_line_pointer += 6;
9a182533 4603 symbolP->bsym->flags &= ~BSF_FUNCTION;
e75acd68 4604 type = SYMBOL_TYPE_PLABEL;
025b0302
ME
4605 }
4606 else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
4607 {
4608 input_line_pointer += 8;
9a182533 4609 symbolP->bsym->flags |= BSF_FUNCTION;
e75acd68 4610 type = SYMBOL_TYPE_PRI_PROG;
025b0302
ME
4611 }
4612 else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
4613 {
4614 input_line_pointer += 8;
9a182533 4615 symbolP->bsym->flags |= BSF_FUNCTION;
e75acd68 4616 type = SYMBOL_TYPE_SEC_PROG;
025b0302
ME
4617 }
4618
e75acd68
JL
4619 /* SOM requires much more information about symbol types
4620 than BFD understands. This is how we get this information
4621 to the SOM BFD backend. */
4622#ifdef obj_set_symbol_type
4623 obj_set_symbol_type (symbolP->bsym, (int) type);
4624#endif
4625
8f78d0e9
KR
4626 /* Now that the type of the exported symbol has been handled,
4627 handle any argument relocation information. */
025b0302
ME
4628 while (!is_end_of_statement ())
4629 {
4630 if (*input_line_pointer == ',')
4631 input_line_pointer++;
4632 name = input_line_pointer;
4633 c = get_symbol_end ();
8f78d0e9 4634 /* Argument sources. */
025b0302
ME
4635 if ((strncasecmp (name, "argw", 4) == 0))
4636 {
4637 p = input_line_pointer;
4638 *p = c;
4639 input_line_pointer++;
4640 temp = atoi (name + 4);
4641 name = input_line_pointer;
4642 c = get_symbol_end ();
4643 arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
8f78d0e9 4644 symbol->tc_data.hppa_arg_reloc |= arg_reloc;
025b0302
ME
4645 *input_line_pointer = c;
4646 }
8f78d0e9 4647 /* The return value. */
025b0302
ME
4648 else if ((strncasecmp (name, "rtnval", 6)) == 0)
4649 {
4650 p = input_line_pointer;
4651 *p = c;
4652 input_line_pointer++;
4653 name = input_line_pointer;
4654 c = get_symbol_end ();
4655 arg_reloc = pa_build_arg_reloc (name);
8f78d0e9 4656 symbol->tc_data.hppa_arg_reloc |= arg_reloc;
025b0302
ME
4657 *input_line_pointer = c;
4658 }
8f78d0e9 4659 /* Privelege level. */
025b0302
ME
4660 else if ((strncasecmp (name, "priv_lev", 8)) == 0)
4661 {
4662 p = input_line_pointer;
4663 *p = c;
4664 input_line_pointer++;
025b0302
ME
4665 temp = atoi (input_line_pointer);
4666 c = get_symbol_end ();
4667 *input_line_pointer = c;
025b0302
ME
4668 }
4669 else
4670 {
4671 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name);
4672 p = input_line_pointer;
4673 *p = c;
4674 }
4675 if (!is_end_of_statement ())
4676 input_line_pointer++;
4677 }
4678}
4679
8f78d0e9
KR
4680/* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4681 assembly file must either be defined in the assembly file, or
4682 explicitly IMPORTED from another. */
4683
4684static void
4685pa_import (unused)
4686 int unused;
025b0302 4687{
8f78d0e9
KR
4688 char *name, c, *p;
4689 symbolS *symbol;
025b0302
ME
4690
4691 name = input_line_pointer;
4692 c = get_symbol_end ();
025b0302 4693
8f78d0e9 4694 symbol = symbol_find_or_make (name);
025b0302
ME
4695 p = input_line_pointer;
4696 *p = c;
4697
4698 if (!is_end_of_statement ())
4699 {
4700 input_line_pointer++;
48153d49 4701 pa_type_args (symbol, 0);
025b0302
ME
4702 }
4703 else
4704 {
47f45d66 4705 /* Sigh. To be compatable with the HP assembler and to help
c5e9ccd0
JL
4706 poorly written assembly code, we assign a type based on
4707 the the current segment. Note only BSF_FUNCTION really
4708 matters, we do not need to set the full SYMBOL_TYPE_* info here. */
47f45d66
JL
4709 if (now_seg == text_section)
4710 symbol->bsym->flags |= BSF_FUNCTION;
4711
8f78d0e9
KR
4712 /* If the section is undefined, then the symbol is undefined
4713 Since this is an import, leave the section undefined. */
4714 S_SET_SEGMENT (symbol, &bfd_und_section);
025b0302
ME
4715 }
4716
025b0302 4717 demand_empty_rest_of_line ();
025b0302
ME
4718}
4719
8f78d0e9
KR
4720/* Handle a .LABEL pseudo-op. */
4721
4722static void
4723pa_label (unused)
4724 int unused;
025b0302 4725{
8f78d0e9 4726 char *name, c, *p;
025b0302
ME
4727
4728 name = input_line_pointer;
4729 c = get_symbol_end ();
025b0302
ME
4730
4731 if (strlen (name) > 0)
4732 {
4733 colon (name);
4734 p = input_line_pointer;
4735 *p = c;
4736 }
4737 else
4738 {
4739 as_warn ("Missing label name on .LABEL");
4740 }
4741
4742 if (!is_end_of_statement ())
4743 {
4744 as_warn ("extra .LABEL arguments ignored.");
4745 ignore_rest_of_line ();
4746 }
4747 demand_empty_rest_of_line ();
025b0302
ME
4748}
4749
8f78d0e9 4750/* Handle a .LEAVE pseudo-op. This is not supported yet. */
025b0302 4751
8f78d0e9
KR
4752static void
4753pa_leave (unused)
4754 int unused;
4755{
c5e9ccd0 4756 abort ();
025b0302
ME
4757}
4758
8f78d0e9
KR
4759/* Handle a .ORIGIN pseudo-op. */
4760
4761static void
4762pa_origin (unused)
4763 int unused;
025b0302 4764{
8f78d0e9 4765 s_org (0);
025b0302 4766 pa_undefine_label ();
025b0302
ME
4767}
4768
8f78d0e9
KR
4769/* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4770 is for static functions. FIXME. Should share more code with .EXPORT. */
5cf4cd1b 4771
8f78d0e9
KR
4772static void
4773pa_param (unused)
4774 int unused;
5cf4cd1b 4775{
8f78d0e9
KR
4776 char *name, c, *p;
4777 symbolS *symbol;
5cf4cd1b
KR
4778
4779 name = input_line_pointer;
4780 c = get_symbol_end ();
5cf4cd1b 4781
8f78d0e9 4782 if ((symbol = symbol_find_or_make (name)) == NULL)
5cf4cd1b
KR
4783 {
4784 as_bad ("Cannot define static symbol: %s\n", name);
4785 p = input_line_pointer;
4786 *p = c;
4787 input_line_pointer++;
4788 }
4789 else
4790 {
8f78d0e9 4791 S_CLEAR_EXTERNAL (symbol);
5cf4cd1b
KR
4792 p = input_line_pointer;
4793 *p = c;
4794 if (!is_end_of_statement ())
4795 {
4796 input_line_pointer++;
48153d49 4797 pa_type_args (symbol, 0);
5cf4cd1b
KR
4798 }
4799 }
4800
4801 demand_empty_rest_of_line ();
5cf4cd1b
KR
4802}
4803
8f78d0e9
KR
4804/* Handle a .PROC pseudo-op. It is used to mark the beginning
4805 of a procedure from a syntatical point of view. */
4806
4807static void
4808pa_proc (unused)
4809 int unused;
025b0302 4810{
8f78d0e9 4811 struct call_info *call_info;
86066d06 4812 segT seg;
025b0302
ME
4813
4814 if (within_procedure)
4815 as_fatal ("Nested procedures");
4816
8f78d0e9 4817 /* Reset global variables for new procedure. */
025b0302
ME
4818 callinfo_found = FALSE;
4819 within_procedure = TRUE;
025b0302 4820
86066d06
JL
4821 /* Create a new CODE subspace for each procedure if we are not
4822 using space/subspace aliases. */
4823 if (!USE_ALIASES && call_info_root != NULL)
4824 {
4825 /* Force creation of a new $CODE$ subspace; inherit attributes from
4826 the first $CODE$ subspace. */
4827 seg = subseg_force_new ("$CODE$", 0);
4828
4829 /* Now set the flags. */
4830 bfd_set_section_flags (stdoutput, seg,
4831 bfd_get_section_flags (abfd, text_section));
4832
4833 /* Record any alignment request for this section. */
4834 record_alignment (seg,
4835 bfd_get_section_alignment (stdoutput, text_section));
4836
4837 /* Change the "text_section" to be our new $CODE$ subspace. */
4838 text_section = seg;
4839 subseg_set (text_section, 0);
4840
4841#ifdef obj_set_subsection_attributes
4842 /* Need a way to inherit the the access bits, sort key and quadrant
4843 from the first $CODE$ subspace. FIXME. */
4844 obj_set_subsection_attributes (seg, current_space->sd_seg, 0x2c, 24, 0);
4845#endif
4846 }
4847
8f78d0e9
KR
4848 /* Create another call_info structure. */
4849 call_info = (struct call_info *) xmalloc (sizeof (struct call_info));
025b0302
ME
4850
4851 if (!call_info)
4852 as_fatal ("Cannot allocate unwind descriptor\n");
4853
8f78d0e9 4854 bzero (call_info, sizeof (struct call_info));
025b0302
ME
4855
4856 call_info->ci_next = NULL;
4857
4858 if (call_info_root == NULL)
4859 {
4860 call_info_root = call_info;
4861 last_call_info = call_info;
4862 }
4863 else
4864 {
4865 last_call_info->ci_next = call_info;
4866 last_call_info = call_info;
4867 }
4868
4869 /* set up defaults on call_info structure */
4870
4871 call_info->ci_unwind.descriptor.cannot_unwind = 0;
4872 call_info->ci_unwind.descriptor.region_desc = 1;
8f78d0e9 4873 call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
025b0302
ME
4874
4875 /* If we got a .PROC pseudo-op, we know that the function is defined
8f78d0e9 4876 locally. Make sure it gets into the symbol table. */
025b0302 4877 {
8f78d0e9 4878 label_symbol_struct *label_symbol = pa_get_label ();
025b0302 4879
8f78d0e9 4880 if (label_symbol)
025b0302 4881 {
8f78d0e9 4882 if (label_symbol->lss_label)
025b0302 4883 {
8f78d0e9
KR
4884 last_call_info->start_symbol = label_symbol->lss_label;
4885 label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
86066d06
JL
4886 if (! USE_ALIASES)
4887 {
4888 /* The label was defined in a different segment. Fix that
4889 along with the value and associated fragment. */
4890 S_SET_SEGMENT (last_call_info->start_symbol, now_seg);
4891 S_SET_VALUE (last_call_info->start_symbol,
4892 ((char*)obstack_next_free (&frags)
4893 - frag_now->fr_literal));
4894 last_call_info->start_symbol->sy_frag = frag_now;
4895 }
025b0302
ME
4896 }
4897 else
4047ff1d 4898 as_bad ("Missing function name for .PROC (corrupted label chain)");
025b0302
ME
4899 }
4900 else
4047ff1d 4901 last_call_info->start_symbol = NULL;
025b0302
ME
4902 }
4903
4904 demand_empty_rest_of_line ();
025b0302
ME
4905}
4906
8f78d0e9
KR
4907/* Process the syntatical end of a procedure. Make sure all the
4908 appropriate pseudo-ops were found within the procedure. */
4909
4910static void
4911pa_procend (unused)
4912 int unused;
025b0302
ME
4913{
4914
4915 if (!within_procedure)
4916 as_bad ("misplaced .procend");
4917
4918 if (!callinfo_found)
4919 as_bad ("Missing .callinfo for this procedure");
4920
4921 if (within_entry_exit)
4922 as_bad ("Missing .EXIT for a .ENTRY");
4923
44c0de53
JL
4924#ifdef OBJ_ELF
4925 /* ELF needs to mark the end of each function so that it can compute
4926 the size of the function (apparently its needed in the symbol table. */
4927 hppa_elf_mark_end_of_function ();
4928#endif
4929
025b0302
ME
4930 within_procedure = FALSE;
4931 demand_empty_rest_of_line ();
fca59f9d 4932 pa_undefine_label ();
025b0302
ME
4933}
4934
8f78d0e9
KR
4935/* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
4936 then create a new space entry to hold the information specified
4937 by the parameters to the .SPACE directive. */
4938
4939static sd_chain_struct *
025b0302
ME
4940pa_parse_space_stmt (space_name, create_flag)
4941 char *space_name;
4942 int create_flag;
4943{
8f78d0e9
KR
4944 char *name, *ptemp, c;
4945 char loadable, defined, private, sort;
025b0302 4946 int spnum;
3b9a72c5 4947 asection *seg = NULL;
8f78d0e9 4948 sd_chain_struct *space;
025b0302
ME
4949
4950 /* load default values */
4951 spnum = 0;
3b9a72c5 4952 sort = 0;
025b0302
ME
4953 loadable = TRUE;
4954 defined = TRUE;
4955 private = FALSE;
4047ff1d 4956 if (strcmp (space_name, "$TEXT$") == 0)
025b0302 4957 {
0f3b419c
JL
4958 seg = pa_def_spaces[0].segment;
4959 sort = pa_def_spaces[0].sort;
025b0302 4960 }
4047ff1d 4961 else if (strcmp (space_name, "$PRIVATE$") == 0)
025b0302 4962 {
0f3b419c
JL
4963 seg = pa_def_spaces[1].segment;
4964 sort = pa_def_spaces[1].sort;
025b0302
ME
4965 }
4966
4967 if (!is_end_of_statement ())
4968 {
4969 print_errors = FALSE;
4970 ptemp = input_line_pointer + 1;
8f78d0e9
KR
4971 /* First see if the space was specified as a number rather than
4972 as a name. According to the PA assembly manual the rest of
4973 the line should be ignored. */
4974 if ((spnum = pa_parse_number (&ptemp, 0)) >= 0)
4975 input_line_pointer = ptemp;
025b0302
ME
4976 else
4977 {
4978 while (!is_end_of_statement ())
4979 {
4980 input_line_pointer++;
4981 name = input_line_pointer;
4982 c = get_symbol_end ();
4047ff1d 4983 if ((strncasecmp (name, "spnum", 5) == 0))
025b0302 4984 {
8f78d0e9 4985 *input_line_pointer = c;
025b0302 4986 input_line_pointer++;
8f78d0e9 4987 spnum = get_absolute_expression ();
025b0302 4988 }
4047ff1d 4989 else if ((strncasecmp (name, "sort", 4) == 0))
025b0302 4990 {
8f78d0e9 4991 *input_line_pointer = c;
025b0302 4992 input_line_pointer++;
8f78d0e9 4993 sort = get_absolute_expression ();
025b0302 4994 }
4047ff1d 4995 else if ((strncasecmp (name, "unloadable", 10) == 0))
025b0302 4996 {
8f78d0e9 4997 *input_line_pointer = c;
025b0302
ME
4998 loadable = FALSE;
4999 }
4047ff1d 5000 else if ((strncasecmp (name, "notdefined", 10) == 0))
025b0302 5001 {
8f78d0e9 5002 *input_line_pointer = c;
025b0302
ME
5003 defined = FALSE;
5004 }
4047ff1d 5005 else if ((strncasecmp (name, "private", 7) == 0))
025b0302 5006 {
8f78d0e9 5007 *input_line_pointer = c;
025b0302
ME
5008 private = TRUE;
5009 }
5010 else
3515a504
JL
5011 {
5012 as_bad ("Invalid .SPACE argument");
5013 *input_line_pointer = c;
c5e9ccd0 5014 if (!is_end_of_statement ())
3515a504
JL
5015 input_line_pointer++;
5016 }
025b0302
ME
5017 }
5018 }
5019 print_errors = TRUE;
5020 }
8f78d0e9 5021
3b9a72c5
JL
5022 if (create_flag && seg == NULL)
5023 seg = subseg_new (space_name, 0);
c5e9ccd0 5024
8f78d0e9
KR
5025 /* If create_flag is nonzero, then create the new space with
5026 the attributes computed above. Else set the values in
5027 an already existing space -- this can only happen for
5028 the first occurence of a built-in space. */
025b0302 5029 if (create_flag)
8f78d0e9
KR
5030 space = create_new_space (space_name, spnum, loadable, defined,
5031 private, sort, seg, 1);
025b0302 5032 else
8f78d0e9 5033 {
025b0302
ME
5034 space = is_defined_space (space_name);
5035 SPACE_SPNUM (space) = spnum;
025b0302 5036 SPACE_DEFINED (space) = defined & 1;
8f78d0e9 5037 SPACE_USER_DEFINED (space) = 1;
025b0302
ME
5038 space->sd_seg = seg;
5039 }
548ea75b
JL
5040
5041#ifdef obj_set_section_attributes
5042 obj_set_section_attributes (seg, defined, private, sort, spnum);
5043#endif
5044
025b0302
ME
5045 return space;
5046}
5047
8f78d0e9
KR
5048/* Handle a .SPACE pseudo-op; this switches the current space to the
5049 given space, creating the new space if necessary. */
5050
5051static void
5052pa_space (unused)
5053 int unused;
025b0302 5054{
aa8b30ed 5055 char *name, c, *space_name, *save_s;
8f78d0e9
KR
5056 int temp;
5057 sd_chain_struct *sd_chain;
025b0302
ME
5058
5059 if (within_procedure)
5060 {
5061 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5062 ignore_rest_of_line ();
5063 }
5064 else
5065 {
8f78d0e9
KR
5066 /* Check for some of the predefined spaces. FIXME: most of the code
5067 below is repeated several times, can we extract the common parts
5068 and place them into a subroutine or something similar? */
4047ff1d
JL
5069 /* FIXME Is this (and the next IF stmt) really right?
5070 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5071 if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
025b0302
ME
5072 {
5073 input_line_pointer += 6;
5074 sd_chain = is_defined_space ("$TEXT$");
5075 if (sd_chain == NULL)
5076 sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
8f78d0e9 5077 else if (SPACE_USER_DEFINED (sd_chain) == 0)
025b0302
ME
5078 sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
5079
5080 current_space = sd_chain;
80aab579 5081 subseg_set (text_section, sd_chain->sd_last_subseg);
8f78d0e9
KR
5082 current_subspace
5083 = pa_subsegment_to_subspace (text_section,
5084 sd_chain->sd_last_subseg);
025b0302
ME
5085 demand_empty_rest_of_line ();
5086 return;
5087 }
4047ff1d 5088 if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
025b0302
ME
5089 {
5090 input_line_pointer += 9;
5091 sd_chain = is_defined_space ("$PRIVATE$");
5092 if (sd_chain == NULL)
5093 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
8f78d0e9 5094 else if (SPACE_USER_DEFINED (sd_chain) == 0)
025b0302
ME
5095 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
5096
5097 current_space = sd_chain;
80aab579 5098 subseg_set (data_section, sd_chain->sd_last_subseg);
8f78d0e9
KR
5099 current_subspace
5100 = pa_subsegment_to_subspace (data_section,
5101 sd_chain->sd_last_subseg);
025b0302
ME
5102 demand_empty_rest_of_line ();
5103 return;
5104 }
8f78d0e9
KR
5105 if (!strncasecmp (input_line_pointer,
5106 GDB_DEBUG_SPACE_NAME,
5107 strlen (GDB_DEBUG_SPACE_NAME)))
025b0302
ME
5108 {
5109 input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
5110 sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
5111 if (sd_chain == NULL)
5112 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
8f78d0e9 5113 else if (SPACE_USER_DEFINED (sd_chain) == 0)
025b0302
ME
5114 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
5115
5116 current_space = sd_chain;
80aab579 5117
5cf4cd1b 5118 {
8f78d0e9
KR
5119 asection *gdb_section
5120 = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
5121
8f78d0e9
KR
5122 subseg_set (gdb_section, sd_chain->sd_last_subseg);
5123 current_subspace
5124 = pa_subsegment_to_subspace (gdb_section,
5125 sd_chain->sd_last_subseg);
5cf4cd1b 5126 }
025b0302
ME
5127 demand_empty_rest_of_line ();
5128 return;
5129 }
5130
8f78d0e9 5131 /* It could be a space specified by number. */
aa8b30ed
JL
5132 print_errors = 0;
5133 save_s = input_line_pointer;
8f78d0e9 5134 if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0)
025b0302
ME
5135 {
5136 if (sd_chain = pa_find_space_by_number (temp))
5137 {
5138 current_space = sd_chain;
8f78d0e9 5139
80aab579 5140 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
8f78d0e9
KR
5141 current_subspace
5142 = pa_subsegment_to_subspace (sd_chain->sd_seg,
5143 sd_chain->sd_last_subseg);
025b0302
ME
5144 demand_empty_rest_of_line ();
5145 return;
5146 }
5147 }
5148
8f78d0e9 5149 /* Not a number, attempt to create a new space. */
aa8b30ed
JL
5150 print_errors = 1;
5151 input_line_pointer = save_s;
025b0302
ME
5152 name = input_line_pointer;
5153 c = get_symbol_end ();
8f78d0e9 5154 space_name = xmalloc (strlen (name) + 1);
025b0302
ME
5155 strcpy (space_name, name);
5156 *input_line_pointer = c;
5157
5158 sd_chain = pa_parse_space_stmt (space_name, 1);
5159 current_space = sd_chain;
8f78d0e9 5160
80aab579 5161 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
025b0302
ME
5162 current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
5163 sd_chain->sd_last_subseg);
5164 demand_empty_rest_of_line ();
5165 }
025b0302
ME
5166}
5167
c5e9ccd0 5168/* Switch to a new space. (I think). FIXME. */
8f78d0e9
KR
5169
5170static void
5171pa_spnum (unused)
5172 int unused;
025b0302 5173{
8f78d0e9
KR
5174 char *name;
5175 char c;
5176 char *p;
5177 sd_chain_struct *space;
025b0302
ME
5178
5179 name = input_line_pointer;
5180 c = get_symbol_end ();
5181 space = is_defined_space (name);
5182 if (space)
5183 {
5184 p = frag_more (4);
025b0302
ME
5185 md_number_to_chars (p, SPACE_SPNUM (space), 4);
5186 }
5187 else
5188 as_warn ("Undefined space: '%s' Assuming space number = 0.", name);
5189
5190 *input_line_pointer = c;
5191 demand_empty_rest_of_line ();
025b0302
ME
5192}
5193
8f78d0e9 5194/* If VALUE is an exact power of two between zero and 2^31, then
aa8b30ed 5195 return log2 (VALUE). Else return -1. */
8f78d0e9
KR
5196
5197static int
aa8b30ed 5198log2 (value)
025b0302
ME
5199 int value;
5200{
8f78d0e9 5201 int shift = 0;
025b0302 5202
025b0302
ME
5203 while ((1 << shift) != value && shift < 32)
5204 shift++;
5205
5206 if (shift >= 32)
aa8b30ed 5207 return -1;
8f78d0e9 5208 else
aa8b30ed 5209 return shift;
025b0302
ME
5210}
5211
3b9a72c5 5212/* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
8f78d0e9
KR
5213 given subspace, creating the new subspace if necessary.
5214
5215 FIXME. Should mirror pa_space more closely, in particular how
5216 they're broken up into subroutines. */
5217
5218static void
5219pa_subspace (unused)
5220 int unused;
025b0302 5221{
3b9a72c5 5222 char *name, *ss_name, *alias, c;
8f78d0e9 5223 char loadable, code_only, common, dup_common, zero, sort;
3b9a72c5 5224 int i, access, space_index, alignment, quadrant, applicable, flags;
8f78d0e9
KR
5225 sd_chain_struct *space;
5226 ssd_chain_struct *ssd;
3b9a72c5 5227 asection *section;
025b0302
ME
5228
5229 if (within_procedure)
5230 {
5231 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5232 ignore_rest_of_line ();
5233 }
5234 else
5235 {
5236 name = input_line_pointer;
5237 c = get_symbol_end ();
025b0302
ME
5238 ss_name = xmalloc (strlen (name) + 1);
5239 strcpy (ss_name, name);
025b0302
ME
5240 *input_line_pointer = c;
5241
8f78d0e9 5242 /* Load default values. */
025b0302
ME
5243 sort = 0;
5244 access = 0x7f;
5245 loadable = 1;
5246 common = 0;
5247 dup_common = 0;
5248 code_only = 0;
5249 zero = 0;
8f78d0e9
KR
5250 space_index = ~0;
5251 alignment = 0;
025b0302 5252 quadrant = 0;
3b9a72c5 5253 alias = NULL;
025b0302 5254
3b9a72c5 5255 space = current_space;
47f45d66
JL
5256 ssd = is_defined_subspace (ss_name);
5257 /* Allow user to override the builtin attributes of subspaces. But
c5e9ccd0 5258 only allow the attributes to be changed once! */
47f45d66 5259 if (ssd && SUBSPACE_DEFINED (ssd))
025b0302 5260 {
8f78d0e9
KR
5261 subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
5262 if (!is_end_of_statement ())
5263 as_warn ("Parameters of an existing subspace can\'t be modified");
5264 demand_empty_rest_of_line ();
5265 return;
025b0302
ME
5266 }
5267 else
5268 {
3b9a72c5
JL
5269 /* A new subspace. Load default values if it matches one of
5270 the builtin subspaces. */
025b0302
ME
5271 i = 0;
5272 while (pa_def_subspaces[i].name)
5273 {
5274 if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
5275 {
5276 loadable = pa_def_subspaces[i].loadable;
5277 common = pa_def_subspaces[i].common;
5278 dup_common = pa_def_subspaces[i].dup_common;
5279 code_only = pa_def_subspaces[i].code_only;
5280 zero = pa_def_subspaces[i].zero;
5281 space_index = pa_def_subspaces[i].space_index;
8f78d0e9 5282 alignment = pa_def_subspaces[i].alignment;
025b0302
ME
5283 quadrant = pa_def_subspaces[i].quadrant;
5284 access = pa_def_subspaces[i].access;
5285 sort = pa_def_subspaces[i].sort;
3b9a72c5
JL
5286 if (USE_ALIASES && pa_def_subspaces[i].alias)
5287 alias = pa_def_subspaces[i].alias;
025b0302
ME
5288 break;
5289 }
5290 i++;
5291 }
5292 }
5293
8f78d0e9
KR
5294 /* We should be working with a new subspace now. Fill in
5295 any information as specified by the user. */
025b0302
ME
5296 if (!is_end_of_statement ())
5297 {
5298 input_line_pointer++;
5299 while (!is_end_of_statement ())
5300 {
5301 name = input_line_pointer;
5302 c = get_symbol_end ();
4047ff1d 5303 if ((strncasecmp (name, "quad", 4) == 0))
025b0302
ME
5304 {
5305 *input_line_pointer = c;
5306 input_line_pointer++;
8f78d0e9 5307 quadrant = get_absolute_expression ();
025b0302 5308 }
4047ff1d 5309 else if ((strncasecmp (name, "align", 5) == 0))
025b0302
ME
5310 {
5311 *input_line_pointer = c;
5312 input_line_pointer++;
8f78d0e9 5313 alignment = get_absolute_expression ();
aa8b30ed 5314 if (log2 (alignment) == -1)
025b0302
ME
5315 {
5316 as_bad ("Alignment must be a power of 2");
5317 alignment = 1;
5318 }
5319 }
4047ff1d 5320 else if ((strncasecmp (name, "access", 6) == 0))
025b0302
ME
5321 {
5322 *input_line_pointer = c;
5323 input_line_pointer++;
8f78d0e9 5324 access = get_absolute_expression ();
025b0302 5325 }
4047ff1d 5326 else if ((strncasecmp (name, "sort", 4) == 0))
025b0302
ME
5327 {
5328 *input_line_pointer = c;
5329 input_line_pointer++;
8f78d0e9 5330 sort = get_absolute_expression ();
025b0302 5331 }
4047ff1d 5332 else if ((strncasecmp (name, "code_only", 9) == 0))
025b0302
ME
5333 {
5334 *input_line_pointer = c;
5335 code_only = 1;
5336 }
4047ff1d 5337 else if ((strncasecmp (name, "unloadable", 10) == 0))
025b0302
ME
5338 {
5339 *input_line_pointer = c;
5340 loadable = 0;
5341 }
4047ff1d 5342 else if ((strncasecmp (name, "common", 6) == 0))
025b0302
ME
5343 {
5344 *input_line_pointer = c;
5345 common = 1;
5346 }
4047ff1d 5347 else if ((strncasecmp (name, "dup_comm", 8) == 0))
025b0302
ME
5348 {
5349 *input_line_pointer = c;
5350 dup_common = 1;
5351 }
4047ff1d 5352 else if ((strncasecmp (name, "zero", 4) == 0))
025b0302
ME
5353 {
5354 *input_line_pointer = c;
5355 zero = 1;
5356 }
4047ff1d 5357 else if ((strncasecmp (name, "first", 5) == 0))
8f78d0e9 5358 as_bad ("FIRST not supported as a .SUBSPACE argument");
025b0302 5359 else
8f78d0e9 5360 as_bad ("Invalid .SUBSPACE argument");
025b0302
ME
5361 if (!is_end_of_statement ())
5362 input_line_pointer++;
5363 }
5364 }
8f78d0e9 5365
3b9a72c5 5366 /* Compute a reasonable set of BFD flags based on the information
c5e9ccd0 5367 in the .subspace directive. */
3b9a72c5
JL
5368 applicable = bfd_applicable_section_flags (stdoutput);
5369 flags = 0;
5370 if (loadable)
5371 flags |= (SEC_ALLOC | SEC_LOAD);
5372 if (code_only)
5373 flags |= SEC_CODE;
5374 if (common || dup_common)
5375 flags |= SEC_IS_COMMON;
5376
5377 /* This is a zero-filled subspace (eg BSS). */
5378 if (zero)
5379 flags &= ~SEC_LOAD;
5380
5381 flags |= SEC_RELOC | SEC_HAS_CONTENTS;
5382 applicable &= flags;
5383
5384 /* If this is an existing subspace, then we want to use the
c5e9ccd0 5385 segment already associated with the subspace.
3b9a72c5 5386
c5e9ccd0
JL
5387 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5388 lots of sections. It might be a problem in the PA ELF
5389 code, I do not know yet. For now avoid creating anything
5390 but the "standard" sections for ELF. */
3b9a72c5
JL
5391 if (ssd)
5392 section = ssd->ssd_seg;
47f45d66 5393 else if (alias)
3b9a72c5 5394 section = subseg_new (alias, 0);
c5e9ccd0 5395 else if (!alias && USE_ALIASES)
3b9a72c5
JL
5396 {
5397 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5398 demand_empty_rest_of_line ();
5399 return;
5400 }
c5e9ccd0 5401 else
3b9a72c5
JL
5402 section = subseg_new (ss_name, 0);
5403
5404 /* Now set the flags. */
5405 bfd_set_section_flags (stdoutput, section, applicable);
5406
5407 /* Record any alignment request for this section. */
5408 record_alignment (section, log2 (alignment));
5409
5410 /* Set the starting offset for this section. */
5411 bfd_set_section_vma (stdoutput, section,
5412 pa_subspace_start (space, quadrant));
c5e9ccd0 5413
8f78d0e9 5414 /* Now that all the flags are set, update an existing subspace,
3b9a72c5 5415 or create a new one. */
025b0302 5416 if (ssd)
3b9a72c5
JL
5417
5418 current_subspace = update_subspace (space, ss_name, loadable,
5419 code_only, common, dup_common,
5420 sort, zero, access, space_index,
c5e9ccd0 5421 alignment, quadrant,
47f45d66 5422 section);
025b0302 5423 else
8f78d0e9
KR
5424 current_subspace = create_new_subspace (space, ss_name, loadable,
5425 code_only, common,
5426 dup_common, zero, sort,
5427 access, space_index,
c5e9ccd0 5428 alignment, quadrant, section);
025b0302
ME
5429
5430 demand_empty_rest_of_line ();
3b9a72c5 5431 current_subspace->ssd_seg = section;
80aab579 5432 subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
025b0302 5433 }
47f45d66 5434 SUBSPACE_DEFINED (current_subspace) = 1;
025b0302
ME
5435}
5436
025b0302 5437
8f78d0e9 5438/* Create default space and subspace dictionaries. */
025b0302 5439
c5e9ccd0 5440static void
025b0302
ME
5441pa_spaces_begin ()
5442{
025b0302 5443 int i;
025b0302
ME
5444
5445 space_dict_root = NULL;
5446 space_dict_last = NULL;
5447
025b0302
ME
5448 i = 0;
5449 while (pa_def_spaces[i].name)
5450 {
3b9a72c5
JL
5451 char *name;
5452
5453 /* Pick the right name to use for the new section. */
5454 if (pa_def_spaces[i].alias && USE_ALIASES)
5455 name = pa_def_spaces[i].alias;
025b0302 5456 else
c5e9ccd0 5457 name = pa_def_spaces[i].name;
025b0302 5458
3b9a72c5 5459 pa_def_spaces[i].segment = subseg_new (name, 0);
025b0302
ME
5460 create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
5461 pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
8f78d0e9
KR
5462 pa_def_spaces[i].private, pa_def_spaces[i].sort,
5463 pa_def_spaces[i].segment, 0);
025b0302
ME
5464 i++;
5465 }
5466
5467 i = 0;
5468 while (pa_def_subspaces[i].name)
5469 {
3b9a72c5
JL
5470 char *name;
5471 int applicable, subsegment;
5472 asection *segment = NULL;
5473 sd_chain_struct *space;
5474
5475 /* Pick the right name for the new section and pick the right
c5e9ccd0 5476 subsegment number. */
3b9a72c5 5477 if (pa_def_subspaces[i].alias && USE_ALIASES)
025b0302 5478 {
3b9a72c5
JL
5479 name = pa_def_subspaces[i].alias;
5480 subsegment = pa_def_subspaces[i].subsegment;
025b0302
ME
5481 }
5482 else
3b9a72c5
JL
5483 {
5484 name = pa_def_subspaces[i].name;
5485 subsegment = 0;
5486 }
c5e9ccd0 5487
3b9a72c5
JL
5488 /* Create the new section. */
5489 segment = subseg_new (name, subsegment);
5490
5491
5492 /* For SOM we want to replace the standard .text, .data, and .bss
c5e9ccd0
JL
5493 sections with our own. */
5494 if (!strcmp (pa_def_subspaces[i].name, "$CODE$") && !USE_ALIASES)
3b9a72c5
JL
5495 {
5496 text_section = segment;
5497 applicable = bfd_applicable_section_flags (stdoutput);
5498 bfd_set_section_flags (stdoutput, text_section,
c5e9ccd0
JL
5499 applicable & (SEC_ALLOC | SEC_LOAD
5500 | SEC_RELOC | SEC_CODE
5501 | SEC_READONLY
3b9a72c5
JL
5502 | SEC_HAS_CONTENTS));
5503 }
c5e9ccd0 5504 else if (!strcmp (pa_def_subspaces[i].name, "$DATA$") && !USE_ALIASES)
3b9a72c5
JL
5505 {
5506 data_section = segment;
5507 applicable = bfd_applicable_section_flags (stdoutput);
5508 bfd_set_section_flags (stdoutput, data_section,
c5e9ccd0 5509 applicable & (SEC_ALLOC | SEC_LOAD
3b9a72c5
JL
5510 | SEC_RELOC
5511 | SEC_HAS_CONTENTS));
c5e9ccd0
JL
5512
5513
3b9a72c5 5514 }
c5e9ccd0 5515 else if (!strcmp (pa_def_subspaces[i].name, "$BSS$") && !USE_ALIASES)
3b9a72c5
JL
5516 {
5517 bss_section = segment;
5518 applicable = bfd_applicable_section_flags (stdoutput);
5519 bfd_set_section_flags (stdoutput, bss_section,
5520 applicable & SEC_ALLOC);
5521 }
5522
5523 /* Find the space associated with this subspace. */
5524 space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
5525 def_space_index].segment);
5526 if (space == NULL)
5527 {
5528 as_fatal ("Internal error: Unable to find containing space for %s.",
5529 pa_def_subspaces[i].name);
5530 }
5531
5532 create_new_subspace (space, name,
5533 pa_def_subspaces[i].loadable,
5534 pa_def_subspaces[i].code_only,
5535 pa_def_subspaces[i].common,
5536 pa_def_subspaces[i].dup_common,
5537 pa_def_subspaces[i].zero,
5538 pa_def_subspaces[i].sort,
5539 pa_def_subspaces[i].access,
5540 pa_def_subspaces[i].space_index,
5541 pa_def_subspaces[i].alignment,
5542 pa_def_subspaces[i].quadrant,
5543 segment);
025b0302
ME
5544 i++;
5545 }
5546}
5547
8f78d0e9
KR
5548
5549
5550/* Create a new space NAME, with the appropriate flags as defined
dd2f509f 5551 by the given parameters. */
8f78d0e9
KR
5552
5553static sd_chain_struct *
5554create_new_space (name, spnum, loadable, defined, private,
5555 sort, seg, user_defined)
025b0302
ME
5556 char *name;
5557 int spnum;
5558 char loadable;
5559 char defined;
5560 char private;
5561 char sort;
025b0302 5562 asection *seg;
8f78d0e9 5563 int user_defined;
025b0302 5564{
8f78d0e9
KR
5565 sd_chain_struct *chain_entry;
5566
5567 chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct));
025b0302 5568 if (!chain_entry)
8f78d0e9
KR
5569 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5570 name);
025b0302
ME
5571
5572 SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
5573 strcpy (SPACE_NAME (chain_entry), name);
8f78d0e9
KR
5574 SPACE_DEFINED (chain_entry) = defined;
5575 SPACE_USER_DEFINED (chain_entry) = user_defined;
8f78d0e9 5576 SPACE_SPNUM (chain_entry) = spnum;
025b0302 5577
025b0302
ME
5578 chain_entry->sd_seg = seg;
5579 chain_entry->sd_last_subseg = -1;
5580 chain_entry->sd_next = NULL;
5581
8f78d0e9 5582 /* Find spot for the new space based on its sort key. */
025b0302
ME
5583 if (!space_dict_last)
5584 space_dict_last = chain_entry;
5585
8f78d0e9 5586 if (space_dict_root == NULL)
025b0302
ME
5587 space_dict_root = chain_entry;
5588 else
5589 {
8f78d0e9
KR
5590 sd_chain_struct *chain_pointer;
5591 sd_chain_struct *prev_chain_pointer;
025b0302 5592
8f78d0e9
KR
5593 chain_pointer = space_dict_root;
5594 prev_chain_pointer = NULL;
025b0302 5595
8f78d0e9 5596 while (chain_pointer)
025b0302 5597 {
dd2f509f
JL
5598 prev_chain_pointer = chain_pointer;
5599 chain_pointer = chain_pointer->sd_next;
025b0302
ME
5600 }
5601
8f78d0e9
KR
5602 /* At this point we've found the correct place to add the new
5603 entry. So add it and update the linked lists as appropriate. */
5604 if (prev_chain_pointer)
025b0302 5605 {
8f78d0e9
KR
5606 chain_entry->sd_next = chain_pointer;
5607 prev_chain_pointer->sd_next = chain_entry;
025b0302
ME
5608 }
5609 else
5610 {
5611 space_dict_root = chain_entry;
8f78d0e9 5612 chain_entry->sd_next = chain_pointer;
025b0302
ME
5613 }
5614
5615 if (chain_entry->sd_next == NULL)
5616 space_dict_last = chain_entry;
5617 }
5618
548ea75b
JL
5619 /* This is here to catch predefined spaces which do not get
5620 modified by the user's input. Another call is found at
5621 the bottom of pa_parse_space_stmt to handle cases where
5622 the user modifies a predefined space. */
5623#ifdef obj_set_section_attributes
5624 obj_set_section_attributes (seg, defined, private, sort, spnum);
5625#endif
5626
025b0302
ME
5627 return chain_entry;
5628}
5629
8f78d0e9
KR
5630/* Create a new subspace NAME, with the appropriate flags as defined
5631 by the given parameters.
5632
5633 Add the new subspace to the subspace dictionary chain in numerical
5634 order as defined by the SORT entries. */
5635
5636static ssd_chain_struct *
5637create_new_subspace (space, name, loadable, code_only, common,
5638 dup_common, is_zero, sort, access, space_index,
5639 alignment, quadrant, seg)
5640 sd_chain_struct *space;
025b0302 5641 char *name;
8f78d0e9 5642 char loadable, code_only, common, dup_common, is_zero;
025b0302
ME
5643 char sort;
5644 int access;
5645 int space_index;
5646 int alignment;
5647 int quadrant;
5648 asection *seg;
5649{
8f78d0e9 5650 ssd_chain_struct *chain_entry;
025b0302 5651
8f78d0e9 5652 chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct));
025b0302
ME
5653 if (!chain_entry)
5654 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name);
5655
025b0302
ME
5656 SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
5657 strcpy (SUBSPACE_NAME (chain_entry), name);
5658
240cbc57
JL
5659 /* Initialize subspace_defined. When we hit a .subspace directive
5660 we'll set it to 1 which "locks-in" the subspace attributes. */
5661 SUBSPACE_DEFINED (chain_entry) = 0;
5662
3b9a72c5 5663 chain_entry->ssd_subseg = USE_ALIASES ? pa_next_subseg (space) : 0;
025b0302 5664 chain_entry->ssd_seg = seg;
025b0302
ME
5665 chain_entry->ssd_next = NULL;
5666
8f78d0e9
KR
5667 /* Find spot for the new subspace based on its sort key. */
5668 if (space->sd_subspaces == NULL)
025b0302
ME
5669 space->sd_subspaces = chain_entry;
5670 else
5671 {
8f78d0e9
KR
5672 ssd_chain_struct *chain_pointer;
5673 ssd_chain_struct *prev_chain_pointer;
025b0302 5674
8f78d0e9
KR
5675 chain_pointer = space->sd_subspaces;
5676 prev_chain_pointer = NULL;
025b0302 5677
8f78d0e9 5678 while (chain_pointer)
025b0302 5679 {
dd2f509f
JL
5680 prev_chain_pointer = chain_pointer;
5681 chain_pointer = chain_pointer->ssd_next;
025b0302
ME
5682 }
5683
8f78d0e9
KR
5684 /* Now we have somewhere to put the new entry. Insert it and update
5685 the links. */
5686 if (prev_chain_pointer)
025b0302 5687 {
8f78d0e9
KR
5688 chain_entry->ssd_next = chain_pointer;
5689 prev_chain_pointer->ssd_next = chain_entry;
025b0302
ME
5690 }
5691 else
5692 {
5693 space->sd_subspaces = chain_entry;
8f78d0e9 5694 chain_entry->ssd_next = chain_pointer;
025b0302
ME
5695 }
5696 }
5697
548ea75b 5698#ifdef obj_set_subsection_attributes
c5e9ccd0 5699 obj_set_subsection_attributes (seg, space->sd_seg, access,
548ea75b
JL
5700 sort, quadrant);
5701#endif
5702
025b0302 5703 return chain_entry;
025b0302
ME
5704}
5705
8f78d0e9
KR
5706/* Update the information for the given subspace based upon the
5707 various arguments. Return the modified subspace chain entry. */
5708
5709static ssd_chain_struct *
3b9a72c5 5710update_subspace (space, name, loadable, code_only, common, dup_common, sort,
18c4f112 5711 zero, access, space_index, alignment, quadrant, section)
3b9a72c5 5712 sd_chain_struct *space;
025b0302 5713 char *name;
8f78d0e9
KR
5714 char loadable;
5715 char code_only;
5716 char common;
5717 char dup_common;
5718 char zero;
025b0302
ME
5719 char sort;
5720 int access;
5721 int space_index;
5722 int alignment;
5723 int quadrant;
18c4f112 5724 asection *section;
025b0302 5725{
8f78d0e9 5726 ssd_chain_struct *chain_entry;
025b0302 5727
dd2f509f 5728 chain_entry = is_defined_subspace (name);
025b0302 5729
548ea75b 5730#ifdef obj_set_subsection_attributes
c5e9ccd0 5731 obj_set_subsection_attributes (section, space->sd_seg, access,
548ea75b
JL
5732 sort, quadrant);
5733#endif
5734
025b0302 5735 return chain_entry;
025b0302
ME
5736}
5737
8f78d0e9
KR
5738/* Return the space chain entry for the space with the name NAME or
5739 NULL if no such space exists. */
5740
5741static sd_chain_struct *
025b0302
ME
5742is_defined_space (name)
5743 char *name;
5744{
8f78d0e9 5745 sd_chain_struct *chain_pointer;
025b0302 5746
8f78d0e9
KR
5747 for (chain_pointer = space_dict_root;
5748 chain_pointer;
5749 chain_pointer = chain_pointer->sd_next)
025b0302 5750 {
8f78d0e9
KR
5751 if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
5752 return chain_pointer;
025b0302
ME
5753 }
5754
8f78d0e9 5755 /* No mapping from segment to space was found. Return NULL. */
025b0302
ME
5756 return NULL;
5757}
5758
8f78d0e9
KR
5759/* Find and return the space associated with the given seg. If no mapping
5760 from the given seg to a space is found, then return NULL.
5761
5762 Unlike subspaces, the number of spaces is not expected to grow much,
5763 so a linear exhaustive search is OK here. */
5764
5765static sd_chain_struct *
025b0302
ME
5766pa_segment_to_space (seg)
5767 asection *seg;
5768{
8f78d0e9 5769 sd_chain_struct *space_chain;
025b0302 5770
8f78d0e9
KR
5771 /* Walk through each space looking for the correct mapping. */
5772 for (space_chain = space_dict_root;
5773 space_chain;
5774 space_chain = space_chain->sd_next)
025b0302 5775 {
8f78d0e9
KR
5776 if (space_chain->sd_seg == seg)
5777 return space_chain;
025b0302
ME
5778 }
5779
8f78d0e9 5780 /* Mapping was not found. Return NULL. */
025b0302
ME
5781 return NULL;
5782}
5783
8f78d0e9
KR
5784/* Return the space chain entry for the subspace with the name NAME or
5785 NULL if no such subspace exists.
5786
5787 Uses a linear search through all the spaces and subspaces, this may
5788 not be appropriate if we ever being placing each function in its
5789 own subspace. */
5790
5791static ssd_chain_struct *
47f45d66 5792is_defined_subspace (name)
025b0302 5793 char *name;
025b0302 5794{
c5e9ccd0 5795 sd_chain_struct *space_chain;
8f78d0e9 5796 ssd_chain_struct *subspace_chain;
025b0302 5797
8f78d0e9
KR
5798 /* Walk through each space. */
5799 for (space_chain = space_dict_root;
5800 space_chain;
5801 space_chain = space_chain->sd_next)
025b0302 5802 {
8f78d0e9
KR
5803 /* Walk through each subspace looking for a name which matches. */
5804 for (subspace_chain = space_chain->sd_subspaces;
5805 subspace_chain;
5806 subspace_chain = subspace_chain->ssd_next)
5807 if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
5808 return subspace_chain;
025b0302 5809 }
8f78d0e9
KR
5810
5811 /* Subspace wasn't found. Return NULL. */
025b0302
ME
5812 return NULL;
5813}
5814
8f78d0e9
KR
5815/* Find and return the subspace associated with the given seg. If no
5816 mapping from the given seg to a subspace is found, then return NULL.
5817
5818 If we ever put each procedure/function within its own subspace
5819 (to make life easier on the compiler and linker), then this will have
5820 to become more efficient. */
5821
5822static ssd_chain_struct *
025b0302
ME
5823pa_subsegment_to_subspace (seg, subseg)
5824 asection *seg;
5825 subsegT subseg;
5826{
8f78d0e9
KR
5827 sd_chain_struct *space_chain;
5828 ssd_chain_struct *subspace_chain;
025b0302 5829
8f78d0e9
KR
5830 /* Walk through each space. */
5831 for (space_chain = space_dict_root;
5832 space_chain;
5833 space_chain = space_chain->sd_next)
025b0302 5834 {
8f78d0e9 5835 if (space_chain->sd_seg == seg)
025b0302 5836 {
8f78d0e9
KR
5837 /* Walk through each subspace within each space looking for
5838 the correct mapping. */
5839 for (subspace_chain = space_chain->sd_subspaces;
5840 subspace_chain;
5841 subspace_chain = subspace_chain->ssd_next)
5842 if (subspace_chain->ssd_subseg == (int) subseg)
5843 return subspace_chain;
025b0302
ME
5844 }
5845 }
5846
8f78d0e9 5847 /* No mapping from subsegment to subspace found. Return NULL. */
025b0302
ME
5848 return NULL;
5849}
5850
8f78d0e9
KR
5851/* Given a number, try and find a space with the name number.
5852
5853 Return a pointer to a space dictionary chain entry for the space
5854 that was found or NULL on failure. */
5855
5856static sd_chain_struct *
025b0302
ME
5857pa_find_space_by_number (number)
5858 int number;
5859{
8f78d0e9 5860 sd_chain_struct *space_chain;
025b0302 5861
8f78d0e9
KR
5862 for (space_chain = space_dict_root;
5863 space_chain;
5864 space_chain = space_chain->sd_next)
025b0302 5865 {
8f78d0e9
KR
5866 if (SPACE_SPNUM (space_chain) == number)
5867 return space_chain;
025b0302
ME
5868 }
5869
8f78d0e9 5870 /* No appropriate space found. Return NULL. */
025b0302
ME
5871 return NULL;
5872}
5873
8f78d0e9
KR
5874/* Return the starting address for the given subspace. If the starting
5875 address is unknown then return zero. */
5876
5877static unsigned int
025b0302 5878pa_subspace_start (space, quadrant)
8f78d0e9 5879 sd_chain_struct *space;
025b0302
ME
5880 int quadrant;
5881{
8f78d0e9
KR
5882 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5883 is not correct for the PA OSF1 port. */
4047ff1d 5884 if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
8f78d0e9 5885 return 0x40000000;
025b0302 5886 else if (space->sd_seg == data_section && quadrant == 1)
8f78d0e9 5887 return 0x40000000;
025b0302
ME
5888 else
5889 return 0;
5890}
5891
8f78d0e9
KR
5892/* FIXME. Needs documentation. */
5893static int
025b0302 5894pa_next_subseg (space)
8f78d0e9 5895 sd_chain_struct *space;
025b0302
ME
5896{
5897
5898 space->sd_last_subseg++;
5899 return space->sd_last_subseg;
5900}
5901
8f78d0e9
KR
5902/* Helper function for pa_stringer. Used to find the end of
5903 a string. */
5904
025b0302
ME
5905static unsigned int
5906pa_stringer_aux (s)
5907 char *s;
5908{
5909 unsigned int c = *s & CHAR_MASK;
5910 switch (c)
5911 {
5912 case '\"':
5913 c = NOT_A_CHAR;
5914 break;
5915 default:
5916 break;
5917 }
5918 return c;
5919}
5920
8f78d0e9
KR
5921/* Handle a .STRING type pseudo-op. */
5922
5923static void
5924pa_stringer (append_zero)
5925 int append_zero;
025b0302 5926{
8f78d0e9 5927 char *s, num_buf[4];
025b0302 5928 unsigned int c;
025b0302
ME
5929 int i;
5930
8f78d0e9
KR
5931 /* Preprocess the string to handle PA-specific escape sequences.
5932 For example, \xDD where DD is a hexidecimal number should be
5933 changed to \OOO where OOO is an octal number. */
025b0302 5934
8f78d0e9
KR
5935 /* Skip the opening quote. */
5936 s = input_line_pointer + 1;
025b0302
ME
5937
5938 while (is_a_char (c = pa_stringer_aux (s++)))
5939 {
5940 if (c == '\\')
5941 {
5942 c = *s;
5943 switch (c)
5944 {
8f78d0e9 5945 /* Handle \x<num>. */
025b0302
ME
5946 case 'x':
5947 {
5948 unsigned int number;
5949 int num_digit;
5950 char dg;
5951 char *s_start = s;
5952
8f78d0e9
KR
5953 /* Get pas the 'x'. */
5954 s++;
025b0302
ME
5955 for (num_digit = 0, number = 0, dg = *s;
5956 num_digit < 2
5957 && (isdigit (dg) || (dg >= 'a' && dg <= 'f')
5958 || (dg >= 'A' && dg <= 'F'));
5959 num_digit++)
5960 {
5961 if (isdigit (dg))
5962 number = number * 16 + dg - '0';
5963 else if (dg >= 'a' && dg <= 'f')
5964 number = number * 16 + dg - 'a' + 10;
5965 else
5966 number = number * 16 + dg - 'A' + 10;
5967
5968 s++;
5969 dg = *s;
5970 }
5971 if (num_digit > 0)
5972 {
5973 switch (num_digit)
5974 {
5975 case 1:
5976 sprintf (num_buf, "%02o", number);
5977 break;
5978 case 2:
5979 sprintf (num_buf, "%03o", number);
5980 break;
5981 }
5982 for (i = 0; i <= num_digit; i++)
5983 s_start[i] = num_buf[i];
5984 }
5cf4cd1b 5985 break;
025b0302 5986 }
8f78d0e9 5987 /* This might be a "\"", skip over the escaped char. */
5cf4cd1b
KR
5988 default:
5989 s++;
025b0302
ME
5990 break;
5991 }
5992 }
5993 }
5994 stringer (append_zero);
5995 pa_undefine_label ();
5996}
5997
8f78d0e9
KR
5998/* Handle a .VERSION pseudo-op. */
5999
6000static void
6001pa_version (unused)
6002 int unused;
025b0302 6003{
8f78d0e9 6004 obj_version (0);
025b0302
ME
6005 pa_undefine_label ();
6006}
6007
eb91665b
JL
6008/* Handle a .COPYRIGHT pseudo-op. */
6009
6010static void
6011pa_copyright (unused)
6012 int unused;
6013{
6014 obj_copyright (0);
6015 pa_undefine_label ();
6016}
6017
8f78d0e9
KR
6018/* Just like a normal cons, but when finished we have to undefine
6019 the latest space label. */
6020
6021static void
025b0302 6022pa_cons (nbytes)
8f78d0e9 6023 int nbytes;
025b0302
ME
6024{
6025 cons (nbytes);
6026 pa_undefine_label ();
6027}
6028
8f78d0e9
KR
6029/* Switch to the data space. As usual delete our label. */
6030
6031static void
6032pa_data (unused)
6033 int unused;
025b0302 6034{
80aab579 6035 s_data (0);
025b0302
ME
6036 pa_undefine_label ();
6037}
6038
8f78d0e9 6039/* Like float_cons, but we need to undefine our label. */
c5e9ccd0 6040
8f78d0e9 6041static void
025b0302 6042pa_float_cons (float_type)
8f78d0e9 6043 int float_type;
025b0302
ME
6044{
6045 float_cons (float_type);
6046 pa_undefine_label ();
6047}
6048
8f78d0e9
KR
6049/* Like s_fill, but delete our label when finished. */
6050
6051static void
6052pa_fill (unused)
6053 int unused;
025b0302 6054{
80aab579 6055 s_fill (0);
025b0302
ME
6056 pa_undefine_label ();
6057}
6058
8f78d0e9
KR
6059/* Like lcomm, but delete our label when finished. */
6060
6061static void
025b0302 6062pa_lcomm (needs_align)
025b0302
ME
6063 int needs_align;
6064{
6065 s_lcomm (needs_align);
6066 pa_undefine_label ();
6067}
6068
8f78d0e9
KR
6069/* Like lsym, but delete our label when finished. */
6070
6071static void
6072pa_lsym (unused)
6073 int unused;
025b0302 6074{
80aab579 6075 s_lsym (0);
025b0302
ME
6076 pa_undefine_label ();
6077}
6078
8f78d0e9
KR
6079/* Switch to the text space. Like s_text, but delete our
6080 label when finished. */
6081static void
6082pa_text (unused)
6083 int unused;
025b0302 6084{
80aab579 6085 s_text (0);
025b0302
ME
6086 pa_undefine_label ();
6087}
5cf4cd1b 6088
aa8b30ed
JL
6089/* On the PA relocations which involve function symbols must not be
6090 adjusted. This so that the linker can know when/how to create argument
6091 relocation stubs for indirect calls and calls to static functions.
6092
6093 FIXME. Also reject R_HPPA relocations which are 32 bits
6094 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6095 needs to generate relocations to push the addend and symbol value
6096 onto the stack, add them, then pop the value off the stack and
6097 use it in a relocation -- yuk. */
6098
6099int
c5e9ccd0 6100hppa_fix_adjustable (fixp)
aa8b30ed
JL
6101 fixS *fixp;
6102{
6103 struct hppa_fix_struct *hppa_fix;
6104
6105 hppa_fix = fixp->tc_fix_data;
6106
6107 if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32)
6108 return 0;
6109
c5e9ccd0 6110 if (fixp->fx_addsy == 0
aa8b30ed
JL
6111 || (fixp->fx_addsy->bsym->flags & BSF_FUNCTION) == 0)
6112 return 1;
6113
6114 return 0;
6115}
c5e9ccd0 6116
335d35c8
JL
6117/* Return nonzero if the fixup in FIXP will require a relocation,
6118 even it if appears that the fixup could be completely handled
6119 within GAS. */
6120
6121int
6122hppa_force_relocation (fixp)
6123 fixS *fixp;
6124{
6125 struct hppa_fix_struct *hppa_fixp = fixp->tc_fix_data;
6126
6127#ifdef OBJ_SOM
6128 if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT)
6129 return 1;
6130#endif
6131
6132#define stub_needed(CALLER, CALLEE) \
6133 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6134
6135 /* It is necessary to force PC-relative calls/jumps to have a relocation
6136 entry if they're going to need either a argument relocation or long
6137 call stub. FIXME. Can't we need the same for absolute calls? */
753dcbbd 6138 if (fixp->fx_pcrel && fixp->fx_addsy
335d35c8
JL
6139 && (stub_needed (((obj_symbol_type *)
6140 fixp->fx_addsy->bsym)->tc_data.hppa_arg_reloc,
6141 hppa_fixp->fx_arg_reloc)))
6142 return 1;
6143
6144#undef stub_needed
6145
6146 /* No need (yet) to force another relocations to be emitted. */
6147 return 0;
6148}
6149
8f78d0e9
KR
6150/* Now for some ELF specific code. FIXME. */
6151#ifdef OBJ_ELF
6152static symext_chainS *symext_rootP;
6153static symext_chainS *symext_lastP;
6154
44c0de53
JL
6155/* Mark the end of a function so that it's possible to compute
6156 the size of the function in hppa_elf_final_processing. */
6157
6158static void
6159hppa_elf_mark_end_of_function ()
6160{
6161 /* ELF does not have EXIT relocations. All we do is create a
6162 temporary symbol marking the end of the function. */
6163 char *name = (char *)
6164 xmalloc (strlen ("L$\001end_") +
6165 strlen (S_GET_NAME (last_call_info->start_symbol)) + 1);
6166
6167 if (name)
6168 {
6169 symbolS *symbolP;
6170
6171 strcpy (name, "L$\001end_");
6172 strcat (name, S_GET_NAME (last_call_info->start_symbol));
6173
6174 /* If we have a .exit followed by a .procend, then the
6175 symbol will have already been defined. */
6176 symbolP = symbol_find (name);
6177 if (symbolP)
6178 {
6179 /* The symbol has already been defined! This can
6180 happen if we have a .exit followed by a .procend.
6181
6182 This is *not* an error. All we want to do is free
6183 the memory we just allocated for the name and continue. */
6184 xfree (name);
6185 }
6186 else
6187 {
6188 /* symbol value should be the offset of the
6189 last instruction of the function */
6190 symbolP = symbol_new (name, now_seg,
6191 (valueT) (obstack_next_free (&frags)
6192 - frag_now->fr_literal - 4),
6193 frag_now);
6194
6195 assert (symbolP);
6196 symbolP->bsym->flags = BSF_LOCAL;
6197 symbol_table_insert (symbolP);
6198 }
6199
6200 if (symbolP)
6201 last_call_info->end_symbol = symbolP;
6202 else
6203 as_bad ("Symbol '%s' could not be created.", name);
6204
6205 }
6206 else
6207 as_bad ("No memory for symbol name.");
6208
44c0de53
JL
6209}
6210
8f78d0e9 6211/* Do any symbol processing requested by the target-cpu or target-format. */
5cf4cd1b
KR
6212
6213void
6214hppa_tc_symbol (abfd, symbolP, sym_idx)
8f78d0e9
KR
6215 bfd *abfd;
6216 elf_symbol_type *symbolP;
5cf4cd1b
KR
6217 int sym_idx;
6218{
6219 symext_chainS *symextP;
6220 unsigned int arg_reloc;
6221
8f78d0e9 6222 /* Only functions can have argument relocations. */
5cf4cd1b
KR
6223 if (!(symbolP->symbol.flags & BSF_FUNCTION))
6224 return;
6225
6226 arg_reloc = symbolP->tc_data.hppa_arg_reloc;
6227
8f78d0e9
KR
6228 /* If there are no argument relocation bits, then no relocation is
6229 necessary. Do not add this to the symextn section. */
6230 if (arg_reloc == 0)
6231 return;
6232
5cf4cd1b
KR
6233 symextP = (symext_chainS *) bfd_alloc (abfd, sizeof (symext_chainS) * 2);
6234
6235 symextP[0].entry = ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX, sym_idx);
6236 symextP[0].next = &symextP[1];
6237
6238 symextP[1].entry = ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC, arg_reloc);
6239 symextP[1].next = NULL;
6240
6241 if (symext_rootP == NULL)
6242 {
6243 symext_rootP = &symextP[0];
6244 symext_lastP = &symextP[1];
6245 }
6246 else
6247 {
6248 symext_lastP->next = &symextP[0];
6249 symext_lastP = &symextP[1];
6250 }
6251}
6252
8f78d0e9 6253/* Make sections needed by the target cpu and/or target format. */
5cf4cd1b
KR
6254void
6255hppa_tc_make_sections (abfd)
8f78d0e9 6256 bfd *abfd;
5cf4cd1b
KR
6257{
6258 symext_chainS *symextP;
5cf4cd1b
KR
6259 segT save_seg = now_seg;
6260 subsegT save_subseg = now_subseg;
6261
8f78d0e9
KR
6262 /* Build the symbol extension section. */
6263 hppa_tc_make_symextn_section ();
5cf4cd1b 6264
8f78d0e9
KR
6265 /* Force some calculation to occur. */
6266 bfd_set_section_contents (stdoutput, stdoutput->sections, "", 0, 0);
5cf4cd1b
KR
6267
6268 hppa_elf_stub_finish (abfd);
6269
8f78d0e9 6270 /* If no symbols for the symbol extension section, then stop now. */
5cf4cd1b
KR
6271 if (symext_rootP == NULL)
6272 return;
6273
8f78d0e9 6274 /* Switch to the symbol extension section. */
dd2f509f 6275 subseg_new (SYMEXTN_SECTION_NAME, 0);
5cf4cd1b
KR
6276
6277 frag_wane (frag_now);
6278 frag_new (0);
6279
6280 for (symextP = symext_rootP; symextP; symextP = symextP->next)
6281 {
6282 char *ptr;
8f78d0e9 6283 int *symtab_map = elf_sym_extra (abfd);
5cf4cd1b
KR
6284 int idx;
6285
8f78d0e9
KR
6286 /* First, patch the symbol extension record to reflect the true
6287 symbol table index. */
5cf4cd1b 6288
8f78d0e9 6289 if (ELF32_HPPA_SX_TYPE (symextP->entry) == HPPA_SXT_SYMNDX)
5cf4cd1b 6290 {
8f78d0e9 6291 idx = ELF32_HPPA_SX_VAL (symextP->entry) - 1;
5cf4cd1b 6292 symextP->entry = ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX,
8f78d0e9 6293 symtab_map[idx]);
5cf4cd1b
KR
6294 }
6295
8f78d0e9
KR
6296 ptr = frag_more (sizeof (symextP->entry));
6297 md_number_to_chars (ptr, symextP->entry, sizeof (symextP->entry));
5cf4cd1b
KR
6298 }
6299
6300 frag_now->fr_fix = obstack_next_free (&frags) - frag_now->fr_literal;
6301 frag_wane (frag_now);
6302
8f78d0e9
KR
6303 /* Switch back to the original segment. */
6304 subseg_set (save_seg, save_subseg);
5cf4cd1b
KR
6305}
6306
8f78d0e9
KR
6307/* Make the symbol extension section. */
6308
5cf4cd1b 6309static void
8f78d0e9 6310hppa_tc_make_symextn_section ()
5cf4cd1b 6311{
5cf4cd1b
KR
6312 if (symext_rootP)
6313 {
6314 symext_chainS *symextP;
6315 int n;
8f78d0e9 6316 unsigned int size;
5cf4cd1b
KR
6317 segT symextn_sec;
6318 segT save_seg = now_seg;
6319 subsegT save_subseg = now_subseg;
6320
6321 for (n = 0, symextP = symext_rootP; symextP; symextP = symextP->next, ++n)
6322 ;
6323
6324 size = sizeof (symext_entryS) * n;
6325
8f78d0e9 6326 symextn_sec = subseg_new (SYMEXTN_SECTION_NAME, 0);
5cf4cd1b 6327
8f78d0e9
KR
6328 bfd_set_section_flags (stdoutput, symextn_sec,
6329 SEC_LOAD | SEC_HAS_CONTENTS | SEC_DATA);
5cf4cd1b
KR
6330 bfd_set_section_size (stdoutput, symextn_sec, size);
6331
8f78d0e9
KR
6332 /* Now, switch back to the original segment. */
6333 subseg_set (save_seg, save_subseg);
6334 }
6335}
6336
6337/* Build the symbol extension section. */
6338
6339static void
6340pa_build_symextn_section ()
6341{
6342 segT seg;
6343 asection *save_seg = now_seg;
6344 subsegT subseg = (subsegT) 0;
6345 subsegT save_subseg = now_subseg;
6346
6347 seg = subseg_new (".hppa_symextn", subseg);
6348 bfd_set_section_flags (stdoutput,
6349 seg,
c5e9ccd0 6350 SEC_HAS_CONTENTS | SEC_READONLY
8f78d0e9
KR
6351 | SEC_ALLOC | SEC_LOAD);
6352
6353 subseg_set (save_seg, save_subseg);
8f78d0e9
KR
6354}
6355
6356/* For ELF, this function serves one purpose: to setup the st_size
6357 field of STT_FUNC symbols. To do this, we need to scan the
dd2f509f
JL
6358 call_info structure list, determining st_size in by taking the
6359 difference in the address of the beginning/end marker symbols. */
8f78d0e9
KR
6360
6361void
6362elf_hppa_final_processing ()
6363{
6364 struct call_info *call_info_pointer;
6365
6366 for (call_info_pointer = call_info_root;
6367 call_info_pointer;
6368 call_info_pointer = call_info_pointer->ci_next)
6369 {
6370 elf_symbol_type *esym
c5e9ccd0 6371 = (elf_symbol_type *) call_info_pointer->start_symbol->bsym;
8f78d0e9
KR
6372 esym->internal_elf_sym.st_size =
6373 S_GET_VALUE (call_info_pointer->end_symbol)
c5e9ccd0 6374 - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
5cf4cd1b
KR
6375 }
6376}
8f78d0e9 6377#endif