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