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