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