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