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