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