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