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