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