* config/tc-vax.c (tc_aout_fix_to_chars): Local variable NBYTES_R_LENGTH now
[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
1326 while (i < NUMOPCODES)
1327 {
1328 const char *name = pa_opcodes[i].name;
1329 retval = hash_insert (op_hash, name, (struct pa_opcode *) &pa_opcodes[i]);
1330 if (retval != NULL && *retval != '\0')
1331 {
1332 as_fatal ("Internal error: can't hash `%s': %s\n", name, retval);
1333 lose = 1;
1334 }
1335 do
1336 {
1337 if ((pa_opcodes[i].match & pa_opcodes[i].mask)
1338 != pa_opcodes[i].match)
1339 {
1340 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
1341 pa_opcodes[i].name, pa_opcodes[i].args);
1342 lose = 1;
1343 }
1344 ++i;
1345 }
1346 while (i < NUMOPCODES && !strcmp (pa_opcodes[i].name, name));
1347 }
1348
1349 if (lose)
1350 as_fatal ("Broken assembler. No assembly attempted.");
1351
1352 /* SOM will change text_section. To make sure we never put
1353 anything into the old one switch to the new one now. */
1354 subseg_set (text_section, 0);
1355 }
1356
1357 /* Called at the end of assembling a source file. Nothing to do
1358 at this point on the PA. */
1359
1360 void
1361 md_end ()
1362 {
1363 }
1364
1365 /* Assemble a single instruction storing it into a frag. */
1366 void
1367 md_assemble (str)
1368 char *str;
1369 {
1370 char *to;
1371
1372 /* The had better be something to assemble. */
1373 assert (str);
1374
1375 /* Assemble the instruction. Results are saved into "the_insn". */
1376 pa_ip (str);
1377
1378 /* Get somewhere to put the assembled instrution. */
1379 to = frag_more (4);
1380
1381 /* Output the opcode. */
1382 md_number_to_chars (to, the_insn.opcode, 4);
1383
1384 /* If necessary output more stuff. */
1385 if (the_insn.reloc != R_HPPA_NONE)
1386 fix_new_hppa (frag_now, (to - frag_now->fr_literal), 4, NULL,
1387 (offsetT) 0, &the_insn.exp, the_insn.pcrel,
1388 the_insn.reloc, the_insn.field_selector,
1389 the_insn.format, the_insn.arg_reloc, NULL);
1390
1391 }
1392
1393 /* Do the real work for assembling a single instruction. Store results
1394 into the global "the_insn" variable. */
1395
1396 static void
1397 pa_ip (str)
1398 char *str;
1399 {
1400 char *error_message = "";
1401 char *s, c, *argstart, *name, *save_s;
1402 const char *args;
1403 int match = FALSE;
1404 int comma = 0;
1405 int cmpltr, nullif, flag, cond, num;
1406 unsigned long opcode;
1407 struct pa_opcode *insn;
1408
1409 /* Skip to something interesting. */
1410 for (s = str; isupper (*s) || islower (*s) || (*s >= '0' && *s <= '3'); ++s)
1411 ;
1412
1413 switch (*s)
1414 {
1415
1416 case '\0':
1417 break;
1418
1419 case ',':
1420 comma = 1;
1421
1422 /*FALLTHROUGH */
1423
1424 case ' ':
1425 *s++ = '\0';
1426 break;
1427
1428 default:
1429 as_bad ("Unknown opcode: `%s'", str);
1430 exit (1);
1431 }
1432
1433 save_s = str;
1434
1435 /* Convert everything into lower case. */
1436 while (*save_s)
1437 {
1438 if (isupper (*save_s))
1439 *save_s = tolower (*save_s);
1440 save_s++;
1441 }
1442
1443 /* Look up the opcode in the has table. */
1444 if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
1445 {
1446 as_bad ("Unknown opcode: `%s'", str);
1447 return;
1448 }
1449
1450 if (comma)
1451 {
1452 *--s = ',';
1453 }
1454
1455 /* Mark the location where arguments for the instruction start, then
1456 start processing them. */
1457 argstart = s;
1458 for (;;)
1459 {
1460 /* Do some initialization. */
1461 opcode = insn->match;
1462 bzero (&the_insn, sizeof (the_insn));
1463
1464 the_insn.reloc = R_HPPA_NONE;
1465
1466 /* Build the opcode, checking as we go to make
1467 sure that the operands match. */
1468 for (args = insn->args;; ++args)
1469 {
1470 switch (*args)
1471 {
1472
1473 /* End of arguments. */
1474 case '\0':
1475 if (*s == '\0')
1476 match = TRUE;
1477 break;
1478
1479 case '+':
1480 if (*s == '+')
1481 {
1482 ++s;
1483 continue;
1484 }
1485 if (*s == '-')
1486 continue;
1487 break;
1488
1489 /* These must match exactly. */
1490 case '(':
1491 case ')':
1492 case ',':
1493 case ' ':
1494 if (*s++ == *args)
1495 continue;
1496 break;
1497
1498 /* Handle a 5 bit register or control register field at 10. */
1499 case 'b':
1500 case '^':
1501 num = pa_parse_number (&s, 0);
1502 CHECK_FIELD (num, 31, 0, 0);
1503 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
1504
1505 /* Handle a 5 bit register field at 15. */
1506 case 'x':
1507 num = pa_parse_number (&s, 0);
1508 CHECK_FIELD (num, 31, 0, 0);
1509 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1510
1511 /* Handle a 5 bit register field at 31. */
1512 case 'y':
1513 case 't':
1514 num = pa_parse_number (&s, 0);
1515 CHECK_FIELD (num, 31, 0, 0);
1516 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1517
1518 /* Handle a 5 bit field length at 31. */
1519 case 'T':
1520 num = pa_get_absolute_expression (&the_insn, &s);
1521 s = expr_end;
1522 CHECK_FIELD (num, 32, 1, 0);
1523 INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
1524
1525 /* Handle a 5 bit immediate at 15. */
1526 case '5':
1527 num = pa_get_absolute_expression (&the_insn, &s);
1528 s = expr_end;
1529 CHECK_FIELD (num, 15, -16, 0);
1530 low_sign_unext (num, 5, &num);
1531 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1532
1533 /* Handle a 5 bit immediate at 31. */
1534 case 'V':
1535 num = pa_get_absolute_expression (&the_insn, &s);
1536 s = expr_end;
1537 CHECK_FIELD (num, 15, -16, 0)
1538 low_sign_unext (num, 5, &num);
1539 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1540
1541 /* Handle an unsigned 5 bit immediate at 31. */
1542 case 'r':
1543 num = pa_get_absolute_expression (&the_insn, &s);
1544 s = expr_end;
1545 CHECK_FIELD (num, 31, 0, 0);
1546 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1547
1548 /* Handle an unsigned 5 bit immediate at 15. */
1549 case 'R':
1550 num = pa_get_absolute_expression (&the_insn, &s);
1551 s = expr_end;
1552 CHECK_FIELD (num, 31, 0, 0);
1553 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1554
1555 /* Handle a 2 bit space identifier at 17. */
1556 case 's':
1557 num = pa_parse_number (&s, 0);
1558 CHECK_FIELD (num, 3, 0, 1);
1559 INSERT_FIELD_AND_CONTINUE (opcode, num, 14);
1560
1561 /* Handle a 3 bit space identifier at 18. */
1562 case 'S':
1563 num = pa_parse_number (&s, 0);
1564 CHECK_FIELD (num, 7, 0, 1);
1565 dis_assemble_3 (num, &num);
1566 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
1567
1568 /* Handle a completer for an indexing load or store. */
1569 case 'c':
1570 {
1571 int uu = 0;
1572 int m = 0;
1573 int i = 0;
1574 while (*s == ',' && i < 2)
1575 {
1576 s++;
1577 if (strncasecmp (s, "sm", 2) == 0)
1578 {
1579 uu = 1;
1580 m = 1;
1581 s++;
1582 i++;
1583 }
1584 else if (strncasecmp (s, "m", 1) == 0)
1585 m = 1;
1586 else if (strncasecmp (s, "s", 1) == 0)
1587 uu = 1;
1588 else
1589 as_bad ("Invalid Indexed Load Completer.");
1590 s++;
1591 i++;
1592 }
1593 if (i > 2)
1594 as_bad ("Invalid Indexed Load Completer Syntax.");
1595 opcode |= m << 5;
1596 INSERT_FIELD_AND_CONTINUE (opcode, uu, 13);
1597 }
1598
1599 /* Handle a short load/store completer. */
1600 case 'C':
1601 {
1602 int a = 0;
1603 int m = 0;
1604 if (*s == ',')
1605 {
1606 s++;
1607 if (strncasecmp (s, "ma", 2) == 0)
1608 {
1609 a = 0;
1610 m = 1;
1611 }
1612 else if (strncasecmp (s, "mb", 2) == 0)
1613 {
1614 a = 1;
1615 m = 1;
1616 }
1617 else
1618 as_bad ("Invalid Short Load/Store Completer.");
1619 s += 2;
1620 }
1621 opcode |= m << 5;
1622 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1623 }
1624
1625 /* Handle a stbys completer. */
1626 case 'Y':
1627 {
1628 int a = 0;
1629 int m = 0;
1630 int i = 0;
1631 while (*s == ',' && i < 2)
1632 {
1633 s++;
1634 if (strncasecmp (s, "m", 1) == 0)
1635 m = 1;
1636 else if (strncasecmp (s, "b", 1) == 0)
1637 a = 0;
1638 else if (strncasecmp (s, "e", 1) == 0)
1639 a = 1;
1640 else
1641 as_bad ("Invalid Store Bytes Short Completer");
1642 s++;
1643 i++;
1644 }
1645 if (i > 2)
1646 as_bad ("Invalid Store Bytes Short Completer");
1647 opcode |= m << 5;
1648 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1649 }
1650
1651 /* Handle a non-negated compare/stubtract condition. */
1652 case '<':
1653 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
1654 if (cmpltr < 0)
1655 {
1656 as_bad ("Invalid Compare/Subtract Condition: %c", *s);
1657 cmpltr = 0;
1658 }
1659 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1660
1661 /* Handle a negated or non-negated compare/subtract condition. */
1662 case '?':
1663 save_s = s;
1664 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
1665 if (cmpltr < 0)
1666 {
1667 s = save_s;
1668 cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 1);
1669 if (cmpltr < 0)
1670 {
1671 as_bad ("Invalid Compare/Subtract Condition.");
1672 cmpltr = 0;
1673 }
1674 else
1675 {
1676 /* Negated condition requires an opcode change. */
1677 opcode |= 1 << 27;
1678 }
1679 }
1680 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1681
1682 /* Handle a negated or non-negated add condition. */
1683 case '!':
1684 save_s = s;
1685 cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
1686 if (cmpltr < 0)
1687 {
1688 s = save_s;
1689 cmpltr = pa_parse_neg_add_cmpltr (&s, 1);
1690 if (cmpltr < 0)
1691 {
1692 as_bad ("Invalid Compare/Subtract Condition");
1693 cmpltr = 0;
1694 }
1695 else
1696 {
1697 /* Negated condition requires an opcode change. */
1698 opcode |= 1 << 27;
1699 }
1700 }
1701 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1702
1703 /* Handle a compare/subtract condition. */
1704 case 'a':
1705 cmpltr = 0;
1706 flag = 0;
1707 save_s = s;
1708 if (*s == ',')
1709 {
1710 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 0);
1711 if (cmpltr < 0)
1712 {
1713 flag = 1;
1714 s = save_s;
1715 cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 0);
1716 if (cmpltr < 0)
1717 {
1718 as_bad ("Invalid Compare/Subtract Condition");
1719 }
1720 }
1721 }
1722 opcode |= cmpltr << 13;
1723 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1724
1725 /* Handle a non-negated add condition. */
1726 case 'd':
1727 cmpltr = 0;
1728 nullif = 0;
1729 flag = 0;
1730 if (*s == ',')
1731 {
1732 s++;
1733 name = s;
1734 while (*s != ',' && *s != ' ' && *s != '\t')
1735 s += 1;
1736 c = *s;
1737 *s = 0x00;
1738 if (strcmp (name, "=") == 0)
1739 cmpltr = 1;
1740 else if (strcmp (name, "<") == 0)
1741 cmpltr = 2;
1742 else if (strcmp (name, "<=") == 0)
1743 cmpltr = 3;
1744 else if (strcasecmp (name, "nuv") == 0)
1745 cmpltr = 4;
1746 else if (strcasecmp (name, "znv") == 0)
1747 cmpltr = 5;
1748 else if (strcasecmp (name, "sv") == 0)
1749 cmpltr = 6;
1750 else if (strcasecmp (name, "od") == 0)
1751 cmpltr = 7;
1752 else if (strcasecmp (name, "n") == 0)
1753 nullif = 1;
1754 else if (strcasecmp (name, "tr") == 0)
1755 {
1756 cmpltr = 0;
1757 flag = 1;
1758 }
1759 else if (strcasecmp (name, "<>") == 0)
1760 {
1761 cmpltr = 1;
1762 flag = 1;
1763 }
1764 else if (strcasecmp (name, ">=") == 0)
1765 {
1766 cmpltr = 2;
1767 flag = 1;
1768 }
1769 else if (strcasecmp (name, ">") == 0)
1770 {
1771 cmpltr = 3;
1772 flag = 1;
1773 }
1774 else if (strcasecmp (name, "uv") == 0)
1775 {
1776 cmpltr = 4;
1777 flag = 1;
1778 }
1779 else if (strcasecmp (name, "vnz") == 0)
1780 {
1781 cmpltr = 5;
1782 flag = 1;
1783 }
1784 else if (strcasecmp (name, "nsv") == 0)
1785 {
1786 cmpltr = 6;
1787 flag = 1;
1788 }
1789 else if (strcasecmp (name, "ev") == 0)
1790 {
1791 cmpltr = 7;
1792 flag = 1;
1793 }
1794 else
1795 as_bad ("Invalid Add Condition: %s", name);
1796 *s = c;
1797 }
1798 nullif = pa_parse_nullif (&s);
1799 opcode |= nullif << 1;
1800 opcode |= cmpltr << 13;
1801 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1802
1803 /* HANDLE a logical instruction condition. */
1804 case '&':
1805 cmpltr = 0;
1806 flag = 0;
1807 if (*s == ',')
1808 {
1809 s++;
1810 name = s;
1811 while (*s != ',' && *s != ' ' && *s != '\t')
1812 s += 1;
1813 c = *s;
1814 *s = 0x00;
1815 if (strcmp (name, "=") == 0)
1816 cmpltr = 1;
1817 else if (strcmp (name, "<") == 0)
1818 cmpltr = 2;
1819 else if (strcmp (name, "<=") == 0)
1820 cmpltr = 3;
1821 else if (strcasecmp (name, "od") == 0)
1822 cmpltr = 7;
1823 else if (strcasecmp (name, "tr") == 0)
1824 {
1825 cmpltr = 0;
1826 flag = 1;
1827 }
1828 else if (strcmp (name, "<>") == 0)
1829 {
1830 cmpltr = 1;
1831 flag = 1;
1832 }
1833 else if (strcmp (name, ">=") == 0)
1834 {
1835 cmpltr = 2;
1836 flag = 1;
1837 }
1838 else if (strcmp (name, ">") == 0)
1839 {
1840 cmpltr = 3;
1841 flag = 1;
1842 }
1843 else if (strcasecmp (name, "ev") == 0)
1844 {
1845 cmpltr = 7;
1846 flag = 1;
1847 }
1848 else
1849 as_bad ("Invalid Logical Instruction Condition.");
1850 *s = c;
1851 }
1852 opcode |= cmpltr << 13;
1853 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1854
1855 /* Handle a unit instruction condition. */
1856 case 'U':
1857 cmpltr = 0;
1858 flag = 0;
1859 if (*s == ',')
1860 {
1861 s++;
1862 if (strncasecmp (s, "sbz", 3) == 0)
1863 {
1864 cmpltr = 2;
1865 s += 3;
1866 }
1867 else if (strncasecmp (s, "shz", 3) == 0)
1868 {
1869 cmpltr = 3;
1870 s += 3;
1871 }
1872 else if (strncasecmp (s, "sdc", 3) == 0)
1873 {
1874 cmpltr = 4;
1875 s += 3;
1876 }
1877 else if (strncasecmp (s, "sbc", 3) == 0)
1878 {
1879 cmpltr = 6;
1880 s += 3;
1881 }
1882 else if (strncasecmp (s, "shc", 3) == 0)
1883 {
1884 cmpltr = 7;
1885 s += 3;
1886 }
1887 else if (strncasecmp (s, "tr", 2) == 0)
1888 {
1889 cmpltr = 0;
1890 flag = 1;
1891 s += 2;
1892 }
1893 else if (strncasecmp (s, "nbz", 3) == 0)
1894 {
1895 cmpltr = 2;
1896 flag = 1;
1897 s += 3;
1898 }
1899 else if (strncasecmp (s, "nhz", 3) == 0)
1900 {
1901 cmpltr = 3;
1902 flag = 1;
1903 s += 3;
1904 }
1905 else if (strncasecmp (s, "ndc", 3) == 0)
1906 {
1907 cmpltr = 4;
1908 flag = 1;
1909 s += 3;
1910 }
1911 else if (strncasecmp (s, "nbc", 3) == 0)
1912 {
1913 cmpltr = 6;
1914 flag = 1;
1915 s += 3;
1916 }
1917 else if (strncasecmp (s, "nhc", 3) == 0)
1918 {
1919 cmpltr = 7;
1920 flag = 1;
1921 s += 3;
1922 }
1923 else
1924 as_bad ("Invalid Logical Instruction Condition.");
1925 }
1926 opcode |= cmpltr << 13;
1927 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1928
1929 /* Handle a shift/extract/deposit condition. */
1930 case '|':
1931 case '>':
1932 cmpltr = 0;
1933 if (*s == ',')
1934 {
1935 save_s = s++;
1936 name = s;
1937 while (*s != ',' && *s != ' ' && *s != '\t')
1938 s += 1;
1939 c = *s;
1940 *s = 0x00;
1941 if (strcmp (name, "=") == 0)
1942 cmpltr = 1;
1943 else if (strcmp (name, "<") == 0)
1944 cmpltr = 2;
1945 else if (strcasecmp (name, "od") == 0)
1946 cmpltr = 3;
1947 else if (strcasecmp (name, "tr") == 0)
1948 cmpltr = 4;
1949 else if (strcmp (name, "<>") == 0)
1950 cmpltr = 5;
1951 else if (strcmp (name, ">=") == 0)
1952 cmpltr = 6;
1953 else if (strcasecmp (name, "ev") == 0)
1954 cmpltr = 7;
1955 /* Handle movb,n. Put things back the way they were.
1956 This includes moving s back to where it started. */
1957 else if (strcasecmp (name, "n") == 0 && *args == '|')
1958 {
1959 *s = c;
1960 s = save_s;
1961 continue;
1962 }
1963 else
1964 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1965 *s = c;
1966 }
1967 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1968
1969 /* Handle bvb and bb conditions. */
1970 case '~':
1971 cmpltr = 0;
1972 if (*s == ',')
1973 {
1974 s++;
1975 if (strncmp (s, "<", 1) == 0)
1976 {
1977 cmpltr = 2;
1978 s++;
1979 }
1980 else if (strncmp (s, ">=", 2) == 0)
1981 {
1982 cmpltr = 6;
1983 s += 2;
1984 }
1985 else
1986 as_bad ("Invalid Bit Branch Condition: %c", *s);
1987 }
1988 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1989
1990 /* Handle a system control completer. */
1991 case 'Z':
1992 if (*s == ',' && (*(s + 1) == 'm' || *(s + 1) == 'M'))
1993 {
1994 flag = 1;
1995 s += 2;
1996 }
1997 else
1998 flag = 0;
1999
2000 INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
2001
2002 /* Handle a nullification completer for branch instructions. */
2003 case 'n':
2004 nullif = pa_parse_nullif (&s);
2005 INSERT_FIELD_AND_CONTINUE (opcode, nullif, 1);
2006
2007 /* Handle a 11 bit immediate at 31. */
2008 case 'i':
2009 the_insn.field_selector = pa_chk_field_selector (&s);
2010 get_expression (s);
2011 s = expr_end;
2012 if (the_insn.exp.X_op == O_constant)
2013 {
2014 num = evaluate_absolute (&the_insn);
2015 CHECK_FIELD (num, 1023, -1024, 0);
2016 low_sign_unext (num, 11, &num);
2017 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2018 }
2019 else
2020 {
2021 if (is_DP_relative (the_insn.exp))
2022 the_insn.reloc = R_HPPA_GOTOFF;
2023 else if (is_PC_relative (the_insn.exp))
2024 the_insn.reloc = R_HPPA_PCREL_CALL;
2025 else if (is_complex (the_insn.exp))
2026 the_insn.reloc = R_HPPA_COMPLEX;
2027 else
2028 the_insn.reloc = R_HPPA;
2029 the_insn.format = 11;
2030 continue;
2031 }
2032
2033 /* Handle a 14 bit immediate at 31. */
2034 case 'j':
2035 the_insn.field_selector = pa_chk_field_selector (&s);
2036 get_expression (s);
2037 s = expr_end;
2038 if (the_insn.exp.X_op == O_constant)
2039 {
2040 num = evaluate_absolute (&the_insn);
2041 CHECK_FIELD (num, 8191, -8192, 0);
2042 low_sign_unext (num, 14, &num);
2043 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2044 }
2045 else
2046 {
2047 if (is_DP_relative (the_insn.exp))
2048 the_insn.reloc = R_HPPA_GOTOFF;
2049 else if (is_PC_relative (the_insn.exp))
2050 the_insn.reloc = R_HPPA_PCREL_CALL;
2051 else if (is_complex (the_insn.exp))
2052 the_insn.reloc = R_HPPA_COMPLEX;
2053 else
2054 the_insn.reloc = R_HPPA;
2055 the_insn.format = 14;
2056 continue;
2057 }
2058
2059 /* Handle a 21 bit immediate at 31. */
2060 case 'k':
2061 the_insn.field_selector = pa_chk_field_selector (&s);
2062 get_expression (s);
2063 s = expr_end;
2064 if (the_insn.exp.X_op == O_constant)
2065 {
2066 num = evaluate_absolute (&the_insn);
2067 CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
2068 dis_assemble_21 (num, &num);
2069 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2070 }
2071 else
2072 {
2073 if (is_DP_relative (the_insn.exp))
2074 the_insn.reloc = R_HPPA_GOTOFF;
2075 else if (is_PC_relative (the_insn.exp))
2076 the_insn.reloc = R_HPPA_PCREL_CALL;
2077 else if (is_complex (the_insn.exp))
2078 the_insn.reloc = R_HPPA_COMPLEX;
2079 else
2080 the_insn.reloc = R_HPPA;
2081 the_insn.format = 21;
2082 continue;
2083 }
2084
2085 /* Handle a 12 bit branch displacement. */
2086 case 'w':
2087 the_insn.field_selector = pa_chk_field_selector (&s);
2088 get_expression (s);
2089 s = expr_end;
2090 the_insn.pcrel = 1;
2091 if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001"))
2092 {
2093 unsigned int w1, w, result;
2094
2095 num = evaluate_absolute (&the_insn);
2096 if (num % 4)
2097 {
2098 as_bad ("Branch to unaligned address");
2099 break;
2100 }
2101 CHECK_FIELD (num, 8191, -8192, 0);
2102 sign_unext ((num - 8) >> 2, 12, &result);
2103 dis_assemble_12 (result, &w1, &w);
2104 INSERT_FIELD_AND_CONTINUE (opcode, ((w1 << 2) | w), 0);
2105 }
2106 else
2107 {
2108 if (is_complex (the_insn.exp))
2109 the_insn.reloc = R_HPPA_COMPLEX_PCREL_CALL;
2110 else
2111 the_insn.reloc = R_HPPA_PCREL_CALL;
2112 the_insn.format = 12;
2113 the_insn.arg_reloc = last_call_desc.arg_reloc;
2114 bzero (&last_call_desc, sizeof (struct call_desc));
2115 s = expr_end;
2116 continue;
2117 }
2118
2119 /* Handle a 17 bit branch displacement. */
2120 case 'W':
2121 the_insn.field_selector = pa_chk_field_selector (&s);
2122 get_expression (s);
2123 s = expr_end;
2124 the_insn.pcrel = 1;
2125 if (!the_insn.exp.X_add_symbol
2126 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2127 "L$0\001"))
2128 {
2129 unsigned int w2, w1, w, result;
2130
2131 num = evaluate_absolute (&the_insn);
2132 if (num % 4)
2133 {
2134 as_bad ("Branch to unaligned address");
2135 break;
2136 }
2137 CHECK_FIELD (num, 262143, -262144, 0);
2138
2139 if (the_insn.exp.X_add_symbol)
2140 num -= 8;
2141
2142 sign_unext (num >> 2, 17, &result);
2143 dis_assemble_17 (result, &w1, &w2, &w);
2144 INSERT_FIELD_AND_CONTINUE (opcode,
2145 ((w2 << 2) | (w1 << 16) | w), 0);
2146 }
2147 else
2148 {
2149 if (is_complex (the_insn.exp))
2150 the_insn.reloc = R_HPPA_COMPLEX_PCREL_CALL;
2151 else
2152 the_insn.reloc = R_HPPA_PCREL_CALL;
2153 the_insn.format = 17;
2154 the_insn.arg_reloc = last_call_desc.arg_reloc;
2155 bzero (&last_call_desc, sizeof (struct call_desc));
2156 continue;
2157 }
2158
2159 /* Handle an absolute 17 bit branch target. */
2160 case 'z':
2161 the_insn.field_selector = pa_chk_field_selector (&s);
2162 get_expression (s);
2163 s = expr_end;
2164 the_insn.pcrel = 0;
2165 if (!the_insn.exp.X_add_symbol
2166 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2167 "L$0\001"))
2168 {
2169 unsigned int w2, w1, w, result;
2170
2171 num = evaluate_absolute (&the_insn);
2172 if (num % 4)
2173 {
2174 as_bad ("Branch to unaligned address");
2175 break;
2176 }
2177 CHECK_FIELD (num, 262143, -262144, 0);
2178
2179 if (the_insn.exp.X_add_symbol)
2180 num -= 8;
2181
2182 sign_unext (num >> 2, 17, &result);
2183 dis_assemble_17 (result, &w1, &w2, &w);
2184 INSERT_FIELD_AND_CONTINUE (opcode,
2185 ((w2 << 2) | (w1 << 16) | w), 0);
2186 }
2187 else
2188 {
2189 if (is_complex (the_insn.exp))
2190 the_insn.reloc = R_HPPA_COMPLEX_ABS_CALL;
2191 else
2192 the_insn.reloc = R_HPPA_ABS_CALL;
2193 the_insn.format = 17;
2194 continue;
2195 }
2196
2197 /* Handle a 5 bit shift count at 26. */
2198 case 'p':
2199 num = pa_get_absolute_expression (&the_insn, &s);
2200 s = expr_end;
2201 CHECK_FIELD (num, 31, 0, 0);
2202 INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
2203
2204 /* Handle a 5 bit bit position at 26. */
2205 case 'P':
2206 num = pa_get_absolute_expression (&the_insn, &s);
2207 s = expr_end;
2208 CHECK_FIELD (num, 31, 0, 0);
2209 INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
2210
2211 /* Handle a 5 bit immediate at 10. */
2212 case 'Q':
2213 num = pa_get_absolute_expression (&the_insn, &s);
2214 s = expr_end;
2215 CHECK_FIELD (num, 31, 0, 0);
2216 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
2217
2218 /* Handle a 13 bit immediate at 18. */
2219 case 'A':
2220 num = pa_get_absolute_expression (&the_insn, &s);
2221 s = expr_end;
2222 CHECK_FIELD (num, 4095, -4096, 0);
2223 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
2224
2225 /* Handle a 26 bit immediate at 31. */
2226 case 'D':
2227 num = pa_get_absolute_expression (&the_insn, &s);
2228 s = expr_end;
2229 CHECK_FIELD (num, 671108864, 0, 0);
2230 INSERT_FIELD_AND_CONTINUE (opcode, num, 1);
2231
2232 /* Handle a 3 bit SFU identifier at 25. */
2233 case 'f':
2234 num = pa_get_absolute_expression (&the_insn, &s);
2235 s = expr_end;
2236 CHECK_FIELD (num, 7, 0, 0);
2237 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
2238
2239 /* We don't support any of these. FIXME. */
2240 case 'O':
2241 get_expression (s);
2242 s = expr_end;
2243 abort ();
2244 continue;
2245
2246 /* Handle a source FP operand format completer. */
2247 case 'F':
2248 flag = pa_parse_fp_format (&s);
2249 the_insn.fpof1 = flag;
2250 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2251
2252 /* Handle a destination FP operand format completer. */
2253 case 'G':
2254 /* pa_parse_format needs the ',' prefix. */
2255 s--;
2256 flag = pa_parse_fp_format (&s);
2257 the_insn.fpof2 = flag;
2258 INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
2259
2260 /* Handle FP compare conditions. */
2261 case 'M':
2262 cond = pa_parse_fp_cmp_cond (&s);
2263 INSERT_FIELD_AND_CONTINUE (opcode, cond, 0);
2264
2265 /* Handle L/R register halves like 't'. */
2266 case 'v':
2267 {
2268 struct pa_89_fp_reg_struct result;
2269
2270 pa_parse_number (&s, &result);
2271 CHECK_FIELD (result.number_part, 31, 0, 0);
2272 opcode |= result.number_part;
2273
2274 /* 0x30 opcodes are FP arithmetic operation opcodes
2275 and need to be turned into 0x38 opcodes. This
2276 is not necessary for loads/stores. */
2277 if (need_89_opcode (&the_insn, &result)
2278 && ((opcode & 0xfc000000) == 0x30000000))
2279 opcode |= 1 << 27;
2280
2281 INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6);
2282 }
2283
2284 /* Handle L/R register halves like 'b'. */
2285 case 'E':
2286 {
2287 struct pa_89_fp_reg_struct result;
2288
2289 pa_parse_number (&s, &result);
2290 CHECK_FIELD (result.number_part, 31, 0, 0);
2291 opcode |= result.number_part << 21;
2292 if (need_89_opcode (&the_insn, &result))
2293 {
2294 opcode |= (result.l_r_select & 1) << 7;
2295 opcode |= 1 << 27;
2296 }
2297 continue;
2298 }
2299
2300 /* Handle L/R register halves like 'x'. */
2301 case 'X':
2302 {
2303 struct pa_89_fp_reg_struct result;
2304
2305 pa_parse_number (&s, &result);
2306 CHECK_FIELD (result.number_part, 31, 0, 0);
2307 opcode |= (result.number_part & 0x1f) << 16;
2308 if (need_89_opcode (&the_insn, &result))
2309 {
2310 opcode |= (result.l_r_select & 1) << 12;
2311 opcode |= 1 << 27;
2312 }
2313 continue;
2314 }
2315
2316 /* Handle a 5 bit register field at 10. */
2317 case '4':
2318 {
2319 struct pa_89_fp_reg_struct result;
2320
2321 pa_parse_number (&s, &result);
2322 CHECK_FIELD (result.number_part, 31, 0, 0);
2323 if (the_insn.fpof1 == SGL)
2324 {
2325 result.number_part &= 0xF;
2326 result.number_part |= (result.l_r_select & 1) << 4;
2327 }
2328 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21);
2329 }
2330
2331 /* Handle a 5 bit register field at 15. */
2332 case '6':
2333 {
2334 struct pa_89_fp_reg_struct result;
2335
2336 pa_parse_number (&s, &result);
2337 CHECK_FIELD (result.number_part, 31, 0, 0);
2338 if (the_insn.fpof1 == SGL)
2339 {
2340 result.number_part &= 0xF;
2341 result.number_part |= (result.l_r_select & 1) << 4;
2342 }
2343 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16);
2344 }
2345
2346 /* Handle a 5 bit register field at 31. */
2347 case '7':
2348 {
2349 struct pa_89_fp_reg_struct result;
2350
2351 pa_parse_number (&s, &result);
2352 CHECK_FIELD (result.number_part, 31, 0, 0);
2353 if (the_insn.fpof1 == SGL)
2354 {
2355 result.number_part &= 0xF;
2356 result.number_part |= (result.l_r_select & 1) << 4;
2357 }
2358 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0);
2359 }
2360
2361 /* Handle a 5 bit register field at 20. */
2362 case '8':
2363 {
2364 struct pa_89_fp_reg_struct result;
2365
2366 pa_parse_number (&s, &result);
2367 CHECK_FIELD (result.number_part, 31, 0, 0);
2368 if (the_insn.fpof1 == SGL)
2369 {
2370 result.number_part &= 0xF;
2371 result.number_part |= (result.l_r_select & 1) << 4;
2372 }
2373 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11);
2374 }
2375
2376 /* Handle a 5 bit register field at 25. */
2377 case '9':
2378 {
2379 struct pa_89_fp_reg_struct result;
2380
2381 pa_parse_number (&s, &result);
2382 CHECK_FIELD (result.number_part, 31, 0, 0);
2383 if (the_insn.fpof1 == SGL)
2384 {
2385 result.number_part &= 0xF;
2386 result.number_part |= (result.l_r_select & 1) << 4;
2387 }
2388 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6);
2389 }
2390
2391 /* Handle a floating point operand format at 26.
2392 Only allows single and double precision. */
2393 case 'H':
2394 flag = pa_parse_fp_format (&s);
2395 switch (flag)
2396 {
2397 case SGL:
2398 opcode |= 0x20;
2399 case DBL:
2400 the_insn.fpof1 = flag;
2401 continue;
2402
2403 case QUAD:
2404 case ILLEGAL_FMT:
2405 default:
2406 as_bad ("Invalid Floating Point Operand Format.");
2407 }
2408 break;
2409
2410 default:
2411 abort ();
2412 }
2413 break;
2414 }
2415
2416 /* Check if the args matched. */
2417 if (match == FALSE)
2418 {
2419 if (&insn[1] - pa_opcodes < NUMOPCODES
2420 && !strcmp (insn->name, insn[1].name))
2421 {
2422 ++insn;
2423 s = argstart;
2424 continue;
2425 }
2426 else
2427 {
2428 as_bad ("Invalid operands %s", error_message);
2429 return;
2430 }
2431 }
2432 break;
2433 }
2434
2435 the_insn.opcode = opcode;
2436 }
2437
2438 /* Turn a string in input_line_pointer into a floating point constant of type
2439 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2440 emitted is stored in *sizeP . An error message or NULL is returned. */
2441
2442 #define MAX_LITTLENUMS 6
2443
2444 char *
2445 md_atof (type, litP, sizeP)
2446 char type;
2447 char *litP;
2448 int *sizeP;
2449 {
2450 int prec;
2451 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2452 LITTLENUM_TYPE *wordP;
2453 char *t;
2454
2455 switch (type)
2456 {
2457
2458 case 'f':
2459 case 'F':
2460 case 's':
2461 case 'S':
2462 prec = 2;
2463 break;
2464
2465 case 'd':
2466 case 'D':
2467 case 'r':
2468 case 'R':
2469 prec = 4;
2470 break;
2471
2472 case 'x':
2473 case 'X':
2474 prec = 6;
2475 break;
2476
2477 case 'p':
2478 case 'P':
2479 prec = 6;
2480 break;
2481
2482 default:
2483 *sizeP = 0;
2484 return "Bad call to MD_ATOF()";
2485 }
2486 t = atof_ieee (input_line_pointer, type, words);
2487 if (t)
2488 input_line_pointer = t;
2489 *sizeP = prec * sizeof (LITTLENUM_TYPE);
2490 for (wordP = words; prec--;)
2491 {
2492 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
2493 litP += sizeof (LITTLENUM_TYPE);
2494 }
2495 return NULL;
2496 }
2497
2498 /* Write out big-endian. */
2499
2500 void
2501 md_number_to_chars (buf, val, n)
2502 char *buf;
2503 valueT val;
2504 int n;
2505 {
2506 number_to_chars_bigendian (buf, val, n);
2507 }
2508
2509 /* Translate internal representation of relocation info to BFD target
2510 format. */
2511
2512 arelent **
2513 tc_gen_reloc (section, fixp)
2514 asection *section;
2515 fixS *fixp;
2516 {
2517 arelent *reloc;
2518 struct hppa_fix_struct *hppa_fixp = fixp->tc_fix_data;
2519 bfd_reloc_code_real_type code;
2520 static int unwind_reloc_fixp_cnt = 0;
2521 static arelent *unwind_reloc_entryP = NULL;
2522 static arelent *no_relocs = NULL;
2523 arelent **relocs;
2524 bfd_reloc_code_real_type **codes;
2525 int n_relocs;
2526 int i;
2527
2528 if (fixp->fx_addsy == 0)
2529 return &no_relocs;
2530 assert (hppa_fixp != 0);
2531 assert (section != 0);
2532
2533 #ifdef OBJ_ELF
2534 /* Yuk. I would really like to push all this ELF specific unwind
2535 crud into BFD and the linker. That's how SOM does it -- and
2536 if we could make ELF emulate that then we could share more code
2537 in GAS (and potentially a gnu-linker later).
2538
2539 Unwind section relocations are handled in a special way.
2540 The relocations for the .unwind section are originally
2541 built in the usual way. That is, for each unwind table
2542 entry there are two relocations: one for the beginning of
2543 the function and one for the end.
2544
2545 The first time we enter this function we create a
2546 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2547 of the relocation is initialized to 0. Each additional
2548 pair of times this function is called for the unwind
2549 section represents an additional unwind table entry. Thus,
2550 the addend of the relocation should end up to be the number
2551 of unwind table entries. */
2552 if (strcmp (UNWIND_SECTION_NAME, section->name) == 0)
2553 {
2554 if (unwind_reloc_entryP == NULL)
2555 {
2556 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput,
2557 sizeof (arelent));
2558 assert (reloc != 0);
2559 unwind_reloc_entryP = reloc;
2560 unwind_reloc_fixp_cnt++;
2561 unwind_reloc_entryP->address
2562 = fixp->fx_frag->fr_address + fixp->fx_where;
2563 /* A pointer to any function will do. We only
2564 need one to tell us what section the unwind
2565 relocations are for. */
2566 unwind_reloc_entryP->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2567 hppa_fixp->fx_r_type = code = R_HPPA_UNWIND_ENTRIES;
2568 fixp->fx_r_type = R_HPPA_UNWIND;
2569 unwind_reloc_entryP->howto = bfd_reloc_type_lookup (stdoutput, code);
2570 unwind_reloc_entryP->addend = unwind_reloc_fixp_cnt / 2;
2571 relocs = (arelent **) bfd_alloc_by_size_t (stdoutput,
2572 sizeof (arelent *) * 2);
2573 assert (relocs != 0);
2574 relocs[0] = unwind_reloc_entryP;
2575 relocs[1] = NULL;
2576 return relocs;
2577 }
2578 unwind_reloc_fixp_cnt++;
2579 unwind_reloc_entryP->addend = unwind_reloc_fixp_cnt / 2;
2580
2581 return &no_relocs;
2582 }
2583 #endif
2584
2585 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2586 assert (reloc != 0);
2587
2588 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2589 codes = hppa_gen_reloc_type (stdoutput,
2590 fixp->fx_r_type,
2591 hppa_fixp->fx_r_format,
2592 hppa_fixp->fx_r_field);
2593
2594 for (n_relocs = 0; codes[n_relocs]; n_relocs++)
2595 ;
2596
2597 relocs = (arelent **)
2598 bfd_alloc_by_size_t (stdoutput, sizeof (arelent *) * n_relocs + 1);
2599 assert (relocs != 0);
2600
2601 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput,
2602 sizeof (arelent) * n_relocs);
2603 if (n_relocs > 0)
2604 assert (reloc != 0);
2605
2606 for (i = 0; i < n_relocs; i++)
2607 relocs[i] = &reloc[i];
2608
2609 relocs[n_relocs] = NULL;
2610
2611 #ifdef OBJ_ELF
2612 switch (fixp->fx_r_type)
2613 {
2614 case R_HPPA_COMPLEX:
2615 case R_HPPA_COMPLEX_PCREL_CALL:
2616 case R_HPPA_COMPLEX_ABS_CALL:
2617 assert (n_relocs == 5);
2618
2619 for (i = 0; i < n_relocs; i++)
2620 {
2621 reloc[i].sym_ptr_ptr = NULL;
2622 reloc[i].address = 0;
2623 reloc[i].addend = 0;
2624 reloc[i].howto = bfd_reloc_type_lookup (stdoutput, *codes[i]);
2625 assert (reloc[i].howto && *codes[i] == reloc[i].howto->type);
2626 }
2627
2628 reloc[0].sym_ptr_ptr = &fixp->fx_addsy->bsym;
2629 reloc[1].sym_ptr_ptr = &fixp->fx_subsy->bsym;
2630 reloc[4].address = fixp->fx_frag->fr_address + fixp->fx_where;
2631
2632 if (fixp->fx_r_type == R_HPPA_COMPLEX)
2633 reloc[3].addend = fixp->fx_addnumber;
2634 else if (fixp->fx_r_type == R_HPPA_COMPLEX_PCREL_CALL ||
2635 fixp->fx_r_type == R_HPPA_COMPLEX_ABS_CALL)
2636 reloc[1].addend = fixp->fx_addnumber;
2637
2638 break;
2639
2640 default:
2641 assert (n_relocs == 1);
2642
2643 code = *codes[0];
2644
2645 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2646 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2647 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2648 reloc->addend = 0; /* default */
2649
2650 assert (reloc->howto && code == reloc->howto->type);
2651
2652 /* Now, do any processing that is dependent on the relocation type. */
2653 switch (code)
2654 {
2655 case R_HPPA_PLABEL_32:
2656 case R_HPPA_PLABEL_11:
2657 case R_HPPA_PLABEL_14:
2658 case R_HPPA_PLABEL_L21:
2659 case R_HPPA_PLABEL_R11:
2660 case R_HPPA_PLABEL_R14:
2661 /* For plabel relocations, the addend of the
2662 relocation should be either 0 (no static link) or 2
2663 (static link required).
2664
2665 FIXME: We always assume no static link! */
2666 reloc->addend = 0;
2667 break;
2668
2669 case R_HPPA_ABS_CALL_11:
2670 case R_HPPA_ABS_CALL_14:
2671 case R_HPPA_ABS_CALL_17:
2672 case R_HPPA_ABS_CALL_L21:
2673 case R_HPPA_ABS_CALL_R11:
2674 case R_HPPA_ABS_CALL_R14:
2675 case R_HPPA_ABS_CALL_R17:
2676 case R_HPPA_ABS_CALL_LS21:
2677 case R_HPPA_ABS_CALL_RS11:
2678 case R_HPPA_ABS_CALL_RS14:
2679 case R_HPPA_ABS_CALL_RS17:
2680 case R_HPPA_ABS_CALL_LD21:
2681 case R_HPPA_ABS_CALL_RD11:
2682 case R_HPPA_ABS_CALL_RD14:
2683 case R_HPPA_ABS_CALL_RD17:
2684 case R_HPPA_ABS_CALL_LR21:
2685 case R_HPPA_ABS_CALL_RR14:
2686 case R_HPPA_ABS_CALL_RR17:
2687
2688 case R_HPPA_PCREL_CALL_11:
2689 case R_HPPA_PCREL_CALL_14:
2690 case R_HPPA_PCREL_CALL_17:
2691 case R_HPPA_PCREL_CALL_L21:
2692 case R_HPPA_PCREL_CALL_R11:
2693 case R_HPPA_PCREL_CALL_R14:
2694 case R_HPPA_PCREL_CALL_R17:
2695 case R_HPPA_PCREL_CALL_LS21:
2696 case R_HPPA_PCREL_CALL_RS11:
2697 case R_HPPA_PCREL_CALL_RS14:
2698 case R_HPPA_PCREL_CALL_RS17:
2699 case R_HPPA_PCREL_CALL_LD21:
2700 case R_HPPA_PCREL_CALL_RD11:
2701 case R_HPPA_PCREL_CALL_RD14:
2702 case R_HPPA_PCREL_CALL_RD17:
2703 case R_HPPA_PCREL_CALL_LR21:
2704 case R_HPPA_PCREL_CALL_RR14:
2705 case R_HPPA_PCREL_CALL_RR17:
2706 /* The constant is stored in the instruction. */
2707 reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
2708 break;
2709 default:
2710 reloc->addend = fixp->fx_addnumber;
2711 break;
2712 }
2713 break;
2714 }
2715 #else /* OBJ_SOM */
2716
2717 /* Walk over reach relocation returned by the BFD backend. */
2718 for (i = 0; i < n_relocs; i++)
2719 {
2720 code = *codes[i];
2721
2722 relocs[i]->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2723 relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code);
2724 relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2725
2726 switch (code)
2727 {
2728 case R_PCREL_CALL:
2729 case R_ABS_CALL:
2730 relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
2731 break;
2732
2733 case R_DATA_PLABEL:
2734 case R_CODE_PLABEL:
2735 /* For plabel relocations, the addend of the
2736 relocation should be either 0 (no static link) or 2
2737 (static link required).
2738
2739 FIXME: We always assume no static link! */
2740 relocs[i]->addend = 0;
2741 break;
2742
2743 case R_N_MODE:
2744 case R_S_MODE:
2745 case R_D_MODE:
2746 case R_R_MODE:
2747 /* There is no symbol or addend associated with these fixups. */
2748 relocs[i]->sym_ptr_ptr = 0;
2749 relocs[i]->addend = 0;
2750 break;
2751
2752 default:
2753 relocs[i]->addend = fixp->fx_addnumber;
2754 break;
2755 }
2756 }
2757 #endif
2758
2759 return relocs;
2760 }
2761
2762 /* Process any machine dependent frag types. */
2763
2764 void
2765 md_convert_frag (abfd, sec, fragP)
2766 register bfd *abfd;
2767 register asection *sec;
2768 register fragS *fragP;
2769 {
2770 unsigned int address;
2771
2772 if (fragP->fr_type == rs_machine_dependent)
2773 {
2774 switch ((int) fragP->fr_subtype)
2775 {
2776 case 0:
2777 fragP->fr_type = rs_fill;
2778 know (fragP->fr_var == 1);
2779 know (fragP->fr_next);
2780 address = fragP->fr_address + fragP->fr_fix;
2781 if (address % fragP->fr_offset)
2782 {
2783 fragP->fr_offset =
2784 fragP->fr_next->fr_address
2785 - fragP->fr_address
2786 - fragP->fr_fix;
2787 }
2788 else
2789 fragP->fr_offset = 0;
2790 break;
2791 }
2792 }
2793 }
2794
2795 /* Round up a section size to the appropriate boundary. */
2796
2797 valueT
2798 md_section_align (segment, size)
2799 asection *segment;
2800 valueT size;
2801 {
2802 int align = bfd_get_section_alignment (stdoutput, segment);
2803 int align2 = (1 << align) - 1;
2804
2805 return (size + align2) & ~align2;
2806
2807 }
2808
2809 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2810 void
2811 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2812 char *ptr;
2813 addressT from_addr, to_addr;
2814 fragS *frag;
2815 symbolS *to_symbol;
2816 {
2817 fprintf (stderr, "pa_create_short_jmp\n");
2818 abort ();
2819 }
2820
2821 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2822 void
2823 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2824 char *ptr;
2825 addressT from_addr, to_addr;
2826 fragS *frag;
2827 symbolS *to_symbol;
2828 {
2829 fprintf (stderr, "pa_create_long_jump\n");
2830 abort ();
2831 }
2832
2833 /* Return the approximate size of a frag before relaxation has occurred. */
2834 int
2835 md_estimate_size_before_relax (fragP, segment)
2836 register fragS *fragP;
2837 asection *segment;
2838 {
2839 int size;
2840
2841 size = 0;
2842
2843 while ((fragP->fr_fix + size) % fragP->fr_offset)
2844 size++;
2845
2846 return size;
2847 }
2848
2849 /* Parse machine dependent options. There are none on the PA. */
2850 int
2851 md_parse_option (argP, cntP, vecP)
2852 char **argP;
2853 int *cntP;
2854 char ***vecP;
2855 {
2856 return 1;
2857 }
2858
2859 /* We have no need to default values of symbols. */
2860
2861 symbolS *
2862 md_undefined_symbol (name)
2863 char *name;
2864 {
2865 return 0;
2866 }
2867
2868 /* Parse an operand that is machine-specific.
2869 We just return without modifying the expression as we have nothing
2870 to do on the PA. */
2871
2872 void
2873 md_operand (expressionP)
2874 expressionS *expressionP;
2875 {
2876 }
2877
2878 /* Apply a fixup to an instruction. */
2879
2880 int
2881 md_apply_fix (fixP, valp)
2882 fixS *fixP;
2883 valueT *valp;
2884 {
2885 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2886 struct hppa_fix_struct *hppa_fixP = fixP->tc_fix_data;
2887 long new_val, result;
2888 unsigned int w1, w2, w;
2889 valueT val = *valp;
2890
2891 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2892 never be "applied" (they are just markers). */
2893 #ifdef OBJ_SOM
2894 if (fixP->fx_r_type == R_HPPA_ENTRY
2895 || fixP->fx_r_type == R_HPPA_EXIT)
2896 return 1;
2897 #endif
2898
2899 /* There should have been an HPPA specific fixup associated
2900 with the GAS fixup. */
2901 if (hppa_fixP)
2902 {
2903 unsigned long buf_wd = bfd_get_32 (stdoutput, buf);
2904 unsigned char fmt = bfd_hppa_insn2fmt (buf_wd);
2905
2906 if (fixP->fx_r_type == R_HPPA_NONE)
2907 fmt = 0;
2908
2909 /* Remember this value for emit_reloc. FIXME, is this braindamage
2910 documented anywhere!?! */
2911 fixP->fx_addnumber = val;
2912
2913 /* Check if this is an undefined symbol. No relocation can
2914 possibly be performed in this case. */
2915 if ((fixP->fx_addsy && fixP->fx_addsy->bsym->section == &bfd_und_section)
2916 || (fixP->fx_subsy
2917 && fixP->fx_subsy->bsym->section == &bfd_und_section))
2918 return 1;
2919
2920 /* PLABEL field selectors should not be passed to hppa_field_adjust. */
2921 if (fmt != 0 && hppa_fixP->fx_r_field != R_HPPA_PSEL
2922 && hppa_fixP->fx_r_field != R_HPPA_LPSEL
2923 && hppa_fixP->fx_r_field != R_HPPA_RPSEL
2924 && hppa_fixP->fx_r_field != R_HPPA_TSEL
2925 && hppa_fixP->fx_r_field != R_HPPA_LTSEL
2926 && hppa_fixP->fx_r_field != R_HPPA_RTSEL)
2927 new_val = hppa_field_adjust (val, 0, hppa_fixP->fx_r_field);
2928 else
2929 new_val = 0;
2930
2931 switch (fmt)
2932 {
2933 /* Handle all opcodes with the 'j' operand type. */
2934 case 14:
2935 CHECK_FIELD (new_val, 8191, -8192, 0);
2936
2937 /* Mask off 14 bits to be changed. */
2938 bfd_put_32 (stdoutput,
2939 bfd_get_32 (stdoutput, buf) & 0xffffc000,
2940 buf);
2941 low_sign_unext (new_val, 14, &result);
2942 break;
2943
2944 /* Handle all opcodes with the 'k' operand type. */
2945 case 21:
2946 CHECK_FIELD (new_val, 2097152, 0, 0);
2947
2948 /* Mask off 21 bits to be changed. */
2949 bfd_put_32 (stdoutput,
2950 bfd_get_32 (stdoutput, buf) & 0xffe00000,
2951 buf);
2952 dis_assemble_21 (new_val, &result);
2953 break;
2954
2955 /* Handle all the opcodes with the 'i' operand type. */
2956 case 11:
2957 CHECK_FIELD (new_val, 1023, -1023, 0);
2958
2959 /* Mask off 11 bits to be changed. */
2960 bfd_put_32 (stdoutput,
2961 bfd_get_32 (stdoutput, buf) & 0xffff800,
2962 buf);
2963 low_sign_unext (new_val, 11, &result);
2964 break;
2965
2966 /* Handle all the opcodes with the 'w' operand type. */
2967 case 12:
2968 CHECK_FIELD (new_val, 8191, -8192, 0)
2969
2970 /* Mask off 11 bits to be changed. */
2971 sign_unext ((new_val - 8) >> 2, 12, &result);
2972 bfd_put_32 (stdoutput,
2973 bfd_get_32 (stdoutput, buf) & 0xffffe002,
2974 buf);
2975
2976 dis_assemble_12 (result, &w1, &w);
2977 result = ((w1 << 2) | w);
2978 break;
2979
2980 /* Handle some of the opcodes with the 'W' operand type. */
2981 case 17:
2982
2983 #define stub_needed(CALLER, CALLEE) \
2984 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2985 /* It is necessary to force PC-relative calls/jumps to have a
2986 relocation entry if they're going to need either a argument
2987 relocation or long call stub. FIXME. Can't we need the same
2988 for absolute calls? */
2989 if (fixP->fx_addsy
2990 && (stub_needed (((obj_symbol_type *)
2991 fixP->fx_addsy->bsym)->tc_data.hppa_arg_reloc,
2992 hppa_fixP->fx_arg_reloc)))
2993 return 1;
2994 #undef stub_needed
2995
2996 CHECK_FIELD (new_val, 262143, -262144, 0);
2997
2998 /* Mask off 17 bits to be changed. */
2999 bfd_put_32 (stdoutput,
3000 bfd_get_32 (stdoutput, buf) & 0xffe0e002,
3001 buf);
3002 sign_unext ((new_val - 8) >> 2, 17, &result);
3003 dis_assemble_17 (result, &w1, &w2, &w);
3004 result = ((w2 << 2) | (w1 << 16) | w);
3005 break;
3006
3007 case 32:
3008 #ifdef OBJ_ELF
3009 /* These are ELF specific relocations. ELF unfortunately
3010 handles unwinds in a completely different manner. */
3011 if (hppa_fixP->fx_r_type == R_HPPA_UNWIND_ENTRY
3012 || hppa_fixP->fx_r_type == R_HPPA_UNWIND_ENTRIES)
3013 result = fixP->fx_addnumber;
3014 else
3015 #endif
3016 {
3017 result = 0;
3018 fixP->fx_addnumber = fixP->fx_offset;
3019 /* If we have a real relocation, then we want zero to
3020 be stored in the object file. If no relocation is going
3021 to be emitted, then we need to store new_val into the
3022 object file. */
3023 if (fixP->fx_addsy)
3024 bfd_put_32 (stdoutput, 0, buf);
3025 else
3026 bfd_put_32 (stdoutput, new_val, buf);
3027 return 1;
3028 }
3029 break;
3030
3031 case 0:
3032 return 1;
3033
3034 default:
3035 as_bad ("Unknown relocation encountered in md_apply_fix.");
3036 return 1;
3037 }
3038
3039 /* Insert the relocation. */
3040 bfd_put_32 (stdoutput, bfd_get_32 (stdoutput, buf) | result, buf);
3041 return 1;
3042 }
3043 else
3044 {
3045 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3046 (unsigned int) fixP, fixP->fx_r_type);
3047 return 0;
3048 }
3049 }
3050
3051 /* Exactly what point is a PC-relative offset relative TO?
3052 On the PA, they're relative to the address of the offset. */
3053
3054 long
3055 md_pcrel_from (fixP)
3056 fixS *fixP;
3057 {
3058 return fixP->fx_where + fixP->fx_frag->fr_address;
3059 }
3060
3061 /* Return nonzero if the input line pointer is at the end of
3062 a statement. */
3063
3064 static int
3065 is_end_of_statement ()
3066 {
3067 return ((*input_line_pointer == '\n')
3068 || (*input_line_pointer == ';')
3069 || (*input_line_pointer == '!'));
3070 }
3071
3072 /* Read a number from S. The number might come in one of many forms,
3073 the most common will be a hex or decimal constant, but it could be
3074 a pre-defined register (Yuk!), or an absolute symbol.
3075
3076 Return a number or -1 for failure.
3077
3078 When parsing PA-89 FP register numbers RESULT will be
3079 the address of a structure to return information about
3080 L/R half of FP registers, store results there as appropriate.
3081
3082 pa_parse_number can not handle negative constants and will fail
3083 horribly if it is passed such a constant. */
3084
3085 static int
3086 pa_parse_number (s, result)
3087 char **s;
3088 struct pa_89_fp_reg_struct *result;
3089 {
3090 int num;
3091 char *name;
3092 char c;
3093 symbolS *sym;
3094 int status;
3095 char *p = *s;
3096
3097 /* Skip whitespace before the number. */
3098 while (*p == ' ' || *p == '\t')
3099 p = p + 1;
3100
3101 /* Store info in RESULT if requested by caller. */
3102 if (result)
3103 {
3104 result->number_part = -1;
3105 result->l_r_select = -1;
3106 }
3107 num = -1;
3108
3109 if (isdigit (*p))
3110 {
3111 /* Looks like a number. */
3112 num = 0;
3113
3114 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
3115 {
3116 /* The number is specified in hex. */
3117 p += 2;
3118 while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f'))
3119 || ((*p >= 'A') && (*p <= 'F')))
3120 {
3121 if (isdigit (*p))
3122 num = num * 16 + *p - '0';
3123 else if (*p >= 'a' && *p <= 'f')
3124 num = num * 16 + *p - 'a' + 10;
3125 else
3126 num = num * 16 + *p - 'A' + 10;
3127 ++p;
3128 }
3129 }
3130 else
3131 {
3132 /* The number is specified in decimal. */
3133 while (isdigit (*p))
3134 {
3135 num = num * 10 + *p - '0';
3136 ++p;
3137 }
3138 }
3139
3140 /* Store info in RESULT if requested by the caller. */
3141 if (result)
3142 {
3143 result->number_part = num;
3144
3145 if (IS_R_SELECT (p))
3146 {
3147 result->l_r_select = 1;
3148 ++p;
3149 }
3150 else if (IS_L_SELECT (p))
3151 {
3152 result->l_r_select = 0;
3153 ++p;
3154 }
3155 else
3156 result->l_r_select = 0;
3157 }
3158 }
3159 else if (*p == '%')
3160 {
3161 /* The number might be a predefined register. */
3162 num = 0;
3163 name = p;
3164 p++;
3165 c = *p;
3166 /* Tege hack: Special case for general registers as the general
3167 code makes a binary search with case translation, and is VERY
3168 slow. */
3169 if (c == 'r')
3170 {
3171 p++;
3172 if (*p == 'e' && *(p + 1) == 't'
3173 && (*(p + 2) == '0' || *(p + 2) == '1'))
3174 {
3175 p += 2;
3176 num = *p - '0' + 28;
3177 p++;
3178 }
3179 else if (*p == 'p')
3180 {
3181 num = 2;
3182 p++;
3183 }
3184 else if (!isdigit (*p))
3185 {
3186 if (print_errors)
3187 as_bad ("Undefined register: '%s'.", name);
3188 num = -1;
3189 }
3190 else
3191 {
3192 do
3193 num = num * 10 + *p++ - '0';
3194 while (isdigit (*p));
3195 }
3196 }
3197 else
3198 {
3199 /* Do a normal register search. */
3200 while (is_part_of_name (c))
3201 {
3202 p = p + 1;
3203 c = *p;
3204 }
3205 *p = 0;
3206 status = reg_name_search (name);
3207 if (status >= 0)
3208 num = status;
3209 else
3210 {
3211 if (print_errors)
3212 as_bad ("Undefined register: '%s'.", name);
3213 num = -1;
3214 }
3215 *p = c;
3216 }
3217
3218 /* Store info in RESULT if requested by caller. */
3219 if (result)
3220 {
3221 result->number_part = num;
3222 if (IS_R_SELECT (p - 1))
3223 result->l_r_select = 1;
3224 else if (IS_L_SELECT (p - 1))
3225 result->l_r_select = 0;
3226 else
3227 result->l_r_select = 0;
3228 }
3229 }
3230 else
3231 {
3232 /* And finally, it could be a symbol in the absolute section which
3233 is effectively a constant. */
3234 num = 0;
3235 name = p;
3236 c = *p;
3237 while (is_part_of_name (c))
3238 {
3239 p = p + 1;
3240 c = *p;
3241 }
3242 *p = 0;
3243 if ((sym = symbol_find (name)) != NULL)
3244 {
3245 if (S_GET_SEGMENT (sym) == &bfd_abs_section)
3246 num = S_GET_VALUE (sym);
3247 else
3248 {
3249 if (print_errors)
3250 as_bad ("Non-absolute symbol: '%s'.", name);
3251 num = -1;
3252 }
3253 }
3254 else
3255 {
3256 /* There is where we'd come for an undefined symbol
3257 or for an empty string. For an empty string we
3258 will return zero. That's a concession made for
3259 compatability with the braindamaged HP assemblers. */
3260 if (*name == 0)
3261 num = 0;
3262 else
3263 {
3264 if (print_errors)
3265 as_bad ("Undefined absolute constant: '%s'.", name);
3266 num = -1;
3267 }
3268 }
3269 *p = c;
3270
3271 /* Store info in RESULT if requested by caller. */
3272 if (result)
3273 {
3274 result->number_part = num;
3275 if (IS_R_SELECT (p - 1))
3276 result->l_r_select = 1;
3277 else if (IS_L_SELECT (p - 1))
3278 result->l_r_select = 0;
3279 else
3280 result->l_r_select = 0;
3281 }
3282 }
3283
3284 *s = p;
3285 return num;
3286 }
3287
3288 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3289
3290 /* Given NAME, find the register number associated with that name, return
3291 the integer value associated with the given name or -1 on failure. */
3292
3293 static int
3294 reg_name_search (name)
3295 char *name;
3296 {
3297 int middle, low, high;
3298
3299 low = 0;
3300 high = REG_NAME_CNT - 1;
3301
3302 do
3303 {
3304 middle = (low + high) / 2;
3305 if (strcasecmp (name, pre_defined_registers[middle].name) < 0)
3306 high = middle - 1;
3307 else
3308 low = middle + 1;
3309 }
3310 while (!((strcasecmp (name, pre_defined_registers[middle].name) == 0) ||
3311 (low > high)));
3312
3313 if (strcasecmp (name, pre_defined_registers[middle].name) == 0)
3314 return (pre_defined_registers[middle].value);
3315 else
3316 return (-1);
3317 }
3318
3319
3320 /* Return nonzero if the given INSN and L/R information will require
3321 a new PA-89 opcode. */
3322
3323 static int
3324 need_89_opcode (insn, result)
3325 struct pa_it *insn;
3326 struct pa_89_fp_reg_struct *result;
3327 {
3328 if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL))
3329 return TRUE;
3330 else
3331 return FALSE;
3332 }
3333
3334 /* Parse a condition for a fcmp instruction. Return the numerical
3335 code associated with the condition. */
3336
3337 static int
3338 pa_parse_fp_cmp_cond (s)
3339 char **s;
3340 {
3341 int cond, i;
3342
3343 cond = 0;
3344
3345 for (i = 0; i < 32; i++)
3346 {
3347 if (strncasecmp (*s, fp_cond_map[i].string,
3348 strlen (fp_cond_map[i].string)) == 0)
3349 {
3350 cond = fp_cond_map[i].cond;
3351 *s += strlen (fp_cond_map[i].string);
3352 while (**s == ' ' || **s == '\t')
3353 *s = *s + 1;
3354 return cond;
3355 }
3356 }
3357
3358 as_bad ("Invalid FP Compare Condition: %c", **s);
3359 return 0;
3360 }
3361
3362 /* Parse an FP operand format completer returning the completer
3363 type. */
3364
3365 static fp_operand_format
3366 pa_parse_fp_format (s)
3367 char **s;
3368 {
3369 int format;
3370
3371 format = SGL;
3372 if (**s == ',')
3373 {
3374 *s += 1;
3375 if (strncasecmp (*s, "sgl", 3) == 0)
3376 {
3377 format = SGL;
3378 *s += 4;
3379 }
3380 else if (strncasecmp (*s, "dbl", 3) == 0)
3381 {
3382 format = DBL;
3383 *s += 4;
3384 }
3385 else if (strncasecmp (*s, "quad", 4) == 0)
3386 {
3387 format = QUAD;
3388 *s += 5;
3389 }
3390 else
3391 {
3392 format = ILLEGAL_FMT;
3393 as_bad ("Invalid FP Operand Format: %3s", *s);
3394 }
3395 }
3396
3397 return format;
3398 }
3399
3400 /* Convert from a selector string into a selector type. */
3401
3402 static int
3403 pa_chk_field_selector (str)
3404 char **str;
3405 {
3406 int selector;
3407 const struct selector_entry *tablep;
3408
3409 selector = e_fsel;
3410
3411 /* Read past any whitespace. */
3412 while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
3413 *str = *str + 1;
3414
3415 /* Yuk. Looks like a linear search through the table. With the
3416 frequence of some selectors it might make sense to sort the
3417 table by usage. */
3418 for (tablep = selector_table; tablep->prefix; tablep++)
3419 {
3420 if (strncasecmp (tablep->prefix, *str, strlen (tablep->prefix)) == 0)
3421 {
3422 *str += strlen (tablep->prefix);
3423 selector = tablep->field_selector;
3424 break;
3425 }
3426 }
3427 return selector;
3428 }
3429
3430 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3431
3432 static int
3433 get_expression (str)
3434 char *str;
3435 {
3436 char *save_in;
3437 asection *seg;
3438
3439 save_in = input_line_pointer;
3440 input_line_pointer = str;
3441 seg = expression (&the_insn.exp);
3442 if (!(seg == absolute_section
3443 || seg == undefined_section
3444 || SEG_NORMAL (seg)))
3445 {
3446 as_warn ("Bad segment in expression.");
3447 expr_end = input_line_pointer;
3448 input_line_pointer = save_in;
3449 return 1;
3450 }
3451 expr_end = input_line_pointer;
3452 input_line_pointer = save_in;
3453 return 0;
3454 }
3455
3456 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3457 static int
3458 pa_get_absolute_expression (insn, strp)
3459 struct pa_it *insn;
3460 char **strp;
3461 {
3462 char *save_in;
3463
3464 insn->field_selector = pa_chk_field_selector (strp);
3465 save_in = input_line_pointer;
3466 input_line_pointer = *strp;
3467 expression (&insn->exp);
3468 if (insn->exp.X_op != O_constant)
3469 {
3470 as_bad ("Bad segment (should be absolute).");
3471 expr_end = input_line_pointer;
3472 input_line_pointer = save_in;
3473 return 0;
3474 }
3475 expr_end = input_line_pointer;
3476 input_line_pointer = save_in;
3477 return evaluate_absolute (insn);
3478 }
3479
3480 /* Evaluate an absolute expression EXP which may be modified by
3481 the selector FIELD_SELECTOR. Return the value of the expression. */
3482 static int
3483 evaluate_absolute (insn)
3484 struct pa_it *insn;
3485 {
3486 int value;
3487 expressionS exp;
3488 int field_selector = insn->field_selector;
3489
3490 exp = insn->exp;
3491 value = exp.X_add_number;
3492
3493 switch (field_selector)
3494 {
3495 /* No change. */
3496 case e_fsel:
3497 break;
3498
3499 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3500 case e_lssel:
3501 if (value & 0x00000400)
3502 value += 0x800;
3503 value = (value & 0xfffff800) >> 11;
3504 break;
3505
3506 /* Sign extend from bit 21. */
3507 case e_rssel:
3508 if (value & 0x00000400)
3509 value |= 0xfffff800;
3510 else
3511 value &= 0x7ff;
3512 break;
3513
3514 /* Arithmetic shift right 11 bits. */
3515 case e_lsel:
3516 value = (value & 0xfffff800) >> 11;
3517 break;
3518
3519 /* Set bits 0-20 to zero. */
3520 case e_rsel:
3521 value = value & 0x7ff;
3522 break;
3523
3524 /* Add 0x800 and arithmetic shift right 11 bits. */
3525 case e_ldsel:
3526 value += 0x800;
3527 value = (value & 0xfffff800) >> 11;
3528 break;
3529
3530 /* Set bitgs 0-21 to one. */
3531 case e_rdsel:
3532 value |= 0xfffff800;
3533 break;
3534
3535 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3536 case e_rrsel:
3537 value = (RSEL_ROUND (value) & 0x7ff) + (value - RSEL_ROUND (value));
3538 break;
3539
3540 case e_lrsel:
3541 value = (RSEL_ROUND (value) >> 11) & 0x1fffff;
3542 break;
3543 #undef RSEL_ROUND
3544
3545 default:
3546 BAD_CASE (field_selector);
3547 break;
3548 }
3549 return value;
3550 }
3551
3552 /* Given an argument location specification return the associated
3553 argument location number. */
3554
3555 static unsigned int
3556 pa_build_arg_reloc (type_name)
3557 char *type_name;
3558 {
3559
3560 if (strncasecmp (type_name, "no", 2) == 0)
3561 return 0;
3562 if (strncasecmp (type_name, "gr", 2) == 0)
3563 return 1;
3564 else if (strncasecmp (type_name, "fr", 2) == 0)
3565 return 2;
3566 else if (strncasecmp (type_name, "fu", 2) == 0)
3567 return 3;
3568 else
3569 as_bad ("Invalid argument location: %s\n", type_name);
3570
3571 return 0;
3572 }
3573
3574 /* Encode and return an argument relocation specification for
3575 the given register in the location specified by arg_reloc. */
3576
3577 static unsigned int
3578 pa_align_arg_reloc (reg, arg_reloc)
3579 unsigned int reg;
3580 unsigned int arg_reloc;
3581 {
3582 unsigned int new_reloc;
3583
3584 new_reloc = arg_reloc;
3585 switch (reg)
3586 {
3587 case 0:
3588 new_reloc <<= 8;
3589 break;
3590 case 1:
3591 new_reloc <<= 6;
3592 break;
3593 case 2:
3594 new_reloc <<= 4;
3595 break;
3596 case 3:
3597 new_reloc <<= 2;
3598 break;
3599 default:
3600 as_bad ("Invalid argument description: %d", reg);
3601 }
3602
3603 return new_reloc;
3604 }
3605
3606 /* Parse a PA nullification completer (,n). Return nonzero if the
3607 completer was found; return zero if no completer was found. */
3608
3609 static int
3610 pa_parse_nullif (s)
3611 char **s;
3612 {
3613 int nullif;
3614
3615 nullif = 0;
3616 if (**s == ',')
3617 {
3618 *s = *s + 1;
3619 if (strncasecmp (*s, "n", 1) == 0)
3620 nullif = 1;
3621 else
3622 {
3623 as_bad ("Invalid Nullification: (%c)", **s);
3624 nullif = 0;
3625 }
3626 *s = *s + 1;
3627 }
3628
3629 return nullif;
3630 }
3631
3632 /* Parse a non-negated compare/subtract completer returning the
3633 number (for encoding in instrutions) of the given completer.
3634
3635 ISBRANCH specifies whether or not this is parsing a condition
3636 completer for a branch (vs a nullification completer for a
3637 computational instruction. */
3638
3639 static int
3640 pa_parse_nonneg_cmpsub_cmpltr (s, isbranch)
3641 char **s;
3642 int isbranch;
3643 {
3644 int cmpltr;
3645 char *name = *s + 1;
3646 char c;
3647 char *save_s = *s;
3648
3649 cmpltr = 0;
3650 if (**s == ',')
3651 {
3652 *s += 1;
3653 while (**s != ',' && **s != ' ' && **s != '\t')
3654 *s += 1;
3655 c = **s;
3656 **s = 0x00;
3657 if (strcmp (name, "=") == 0)
3658 {
3659 cmpltr = 1;
3660 }
3661 else if (strcmp (name, "<") == 0)
3662 {
3663 cmpltr = 2;
3664 }
3665 else if (strcmp (name, "<=") == 0)
3666 {
3667 cmpltr = 3;
3668 }
3669 else if (strcmp (name, "<<") == 0)
3670 {
3671 cmpltr = 4;
3672 }
3673 else if (strcmp (name, "<<=") == 0)
3674 {
3675 cmpltr = 5;
3676 }
3677 else if (strcasecmp (name, "sv") == 0)
3678 {
3679 cmpltr = 6;
3680 }
3681 else if (strcasecmp (name, "od") == 0)
3682 {
3683 cmpltr = 7;
3684 }
3685 /* If we have something like addb,n then there is no condition
3686 completer. */
3687 else if (strcasecmp (name, "n") == 0 && isbranch)
3688 {
3689 cmpltr = 0;
3690 }
3691 else
3692 {
3693 cmpltr = -1;
3694 }
3695 **s = c;
3696 }
3697
3698 /* Reset pointers if this was really a ,n for a branch instruction. */
3699 if (cmpltr == 0 && *name == 'n' && isbranch)
3700 *s = save_s;
3701
3702 return cmpltr;
3703 }
3704
3705 /* Parse a negated compare/subtract completer returning the
3706 number (for encoding in instrutions) of the given completer.
3707
3708 ISBRANCH specifies whether or not this is parsing a condition
3709 completer for a branch (vs a nullification completer for a
3710 computational instruction. */
3711
3712 static int
3713 pa_parse_neg_cmpsub_cmpltr (s, isbranch)
3714 char **s;
3715 int isbranch;
3716 {
3717 int cmpltr;
3718 char *name = *s + 1;
3719 char c;
3720 char *save_s = *s;
3721
3722 cmpltr = 0;
3723 if (**s == ',')
3724 {
3725 *s += 1;
3726 while (**s != ',' && **s != ' ' && **s != '\t')
3727 *s += 1;
3728 c = **s;
3729 **s = 0x00;
3730 if (strcasecmp (name, "tr") == 0)
3731 {
3732 cmpltr = 0;
3733 }
3734 else if (strcmp (name, "<>") == 0)
3735 {
3736 cmpltr = 1;
3737 }
3738 else if (strcmp (name, ">=") == 0)
3739 {
3740 cmpltr = 2;
3741 }
3742 else if (strcmp (name, ">") == 0)
3743 {
3744 cmpltr = 3;
3745 }
3746 else if (strcmp (name, ">>=") == 0)
3747 {
3748 cmpltr = 4;
3749 }
3750 else if (strcmp (name, ">>") == 0)
3751 {
3752 cmpltr = 5;
3753 }
3754 else if (strcasecmp (name, "nsv") == 0)
3755 {
3756 cmpltr = 6;
3757 }
3758 else if (strcasecmp (name, "ev") == 0)
3759 {
3760 cmpltr = 7;
3761 }
3762 /* If we have something like addb,n then there is no condition
3763 completer. */
3764 else if (strcasecmp (name, "n") == 0 && isbranch)
3765 {
3766 cmpltr = 0;
3767 }
3768 else
3769 {
3770 cmpltr = -1;
3771 }
3772 **s = c;
3773 }
3774
3775 /* Reset pointers if this was really a ,n for a branch instruction. */
3776 if (cmpltr == 0 && *name == 'n' && isbranch)
3777 *s = save_s;
3778
3779 return cmpltr;
3780 }
3781
3782 /* Parse a non-negated addition completer returning the number
3783 (for encoding in instrutions) of the given completer.
3784
3785 ISBRANCH specifies whether or not this is parsing a condition
3786 completer for a branch (vs a nullification completer for a
3787 computational instruction. */
3788
3789 static int
3790 pa_parse_nonneg_add_cmpltr (s, isbranch)
3791 char **s;
3792 int isbranch;
3793 {
3794 int cmpltr;
3795 char *name = *s + 1;
3796 char c;
3797 char *save_s = *s;
3798
3799 cmpltr = 0;
3800 if (**s == ',')
3801 {
3802 *s += 1;
3803 while (**s != ',' && **s != ' ' && **s != '\t')
3804 *s += 1;
3805 c = **s;
3806 **s = 0x00;
3807 if (strcmp (name, "=") == 0)
3808 {
3809 cmpltr = 1;
3810 }
3811 else if (strcmp (name, "<") == 0)
3812 {
3813 cmpltr = 2;
3814 }
3815 else if (strcmp (name, "<=") == 0)
3816 {
3817 cmpltr = 3;
3818 }
3819 else if (strcasecmp (name, "nuv") == 0)
3820 {
3821 cmpltr = 4;
3822 }
3823 else if (strcasecmp (name, "znv") == 0)
3824 {
3825 cmpltr = 5;
3826 }
3827 else if (strcasecmp (name, "sv") == 0)
3828 {
3829 cmpltr = 6;
3830 }
3831 else if (strcasecmp (name, "od") == 0)
3832 {
3833 cmpltr = 7;
3834 }
3835 /* If we have something like addb,n then there is no condition
3836 completer. */
3837 else if (strcasecmp (name, "n") == 0 && isbranch)
3838 {
3839 cmpltr = 0;
3840 }
3841 else
3842 {
3843 cmpltr = -1;
3844 }
3845 **s = c;
3846 }
3847
3848 /* Reset pointers if this was really a ,n for a branch instruction. */
3849 if (cmpltr == 0 && *name == 'n' && isbranch)
3850 *s = save_s;
3851
3852 return cmpltr;
3853 }
3854
3855 /* Parse a negated addition completer returning the number
3856 (for encoding in instrutions) of the given completer.
3857
3858 ISBRANCH specifies whether or not this is parsing a condition
3859 completer for a branch (vs a nullification completer for a
3860 computational instruction. */
3861
3862 static int
3863 pa_parse_neg_add_cmpltr (s, isbranch)
3864 char **s;
3865 int isbranch;
3866 {
3867 int cmpltr;
3868 char *name = *s + 1;
3869 char c;
3870 char *save_s = *s;
3871
3872 cmpltr = 0;
3873 if (**s == ',')
3874 {
3875 *s += 1;
3876 while (**s != ',' && **s != ' ' && **s != '\t')
3877 *s += 1;
3878 c = **s;
3879 **s = 0x00;
3880 if (strcasecmp (name, "tr") == 0)
3881 {
3882 cmpltr = 0;
3883 }
3884 else if (strcmp (name, "<>") == 0)
3885 {
3886 cmpltr = 1;
3887 }
3888 else if (strcmp (name, ">=") == 0)
3889 {
3890 cmpltr = 2;
3891 }
3892 else if (strcmp (name, ">") == 0)
3893 {
3894 cmpltr = 3;
3895 }
3896 else if (strcmp (name, "uv") == 0)
3897 {
3898 cmpltr = 4;
3899 }
3900 else if (strcmp (name, "vnz") == 0)
3901 {
3902 cmpltr = 5;
3903 }
3904 else if (strcasecmp (name, "nsv") == 0)
3905 {
3906 cmpltr = 6;
3907 }
3908 else if (strcasecmp (name, "ev") == 0)
3909 {
3910 cmpltr = 7;
3911 }
3912 /* If we have something like addb,n then there is no condition
3913 completer. */
3914 else if (strcasecmp (name, "n") == 0 && isbranch)
3915 {
3916 cmpltr = 0;
3917 }
3918 else
3919 {
3920 cmpltr = -1;
3921 }
3922 **s = c;
3923 }
3924
3925 /* Reset pointers if this was really a ,n for a branch instruction. */
3926 if (cmpltr == 0 && *name == 'n' && isbranch)
3927 *s = save_s;
3928
3929 return cmpltr;
3930 }
3931
3932 /* Handle a .BLOCK type pseudo-op. */
3933
3934 static void
3935 pa_block (z)
3936 int z;
3937 {
3938 char *p;
3939 long int temp_fill;
3940 unsigned int temp_size;
3941 int i;
3942
3943 temp_size = get_absolute_expression ();
3944
3945 /* Always fill with zeros, that's what the HP assembler does. */
3946 temp_fill = 0;
3947
3948 p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
3949 (relax_substateT) 0, (symbolS *) 0, 1, NULL);
3950 bzero (p, temp_size);
3951
3952 /* Convert 2 bytes at a time. */
3953
3954 for (i = 0; i < temp_size; i += 2)
3955 {
3956 md_number_to_chars (p + i,
3957 (valueT) temp_fill,
3958 (int) ((temp_size - i) > 2 ? 2 : (temp_size - i)));
3959 }
3960
3961 pa_undefine_label ();
3962 demand_empty_rest_of_line ();
3963 }
3964
3965 /* Handle a .CALL pseudo-op. This involves storing away information
3966 about where arguments are to be found so the linker can detect
3967 (and correct) argument location mismatches between caller and callee. */
3968
3969 static void
3970 pa_call (unused)
3971 int unused;
3972 {
3973 pa_call_args (&last_call_desc);
3974 demand_empty_rest_of_line ();
3975 }
3976
3977 /* Do the dirty work of building a call descriptor which describes
3978 where the caller placed arguments to a function call. */
3979
3980 static void
3981 pa_call_args (call_desc)
3982 struct call_desc *call_desc;
3983 {
3984 char *name, c, *p;
3985 unsigned int temp, arg_reloc;
3986
3987 while (!is_end_of_statement ())
3988 {
3989 name = input_line_pointer;
3990 c = get_symbol_end ();
3991 /* Process a source argument. */
3992 if ((strncasecmp (name, "argw", 4) == 0))
3993 {
3994 temp = atoi (name + 4);
3995 p = input_line_pointer;
3996 *p = c;
3997 input_line_pointer++;
3998 name = input_line_pointer;
3999 c = get_symbol_end ();
4000 arg_reloc = pa_build_arg_reloc (name);
4001 call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
4002 }
4003 /* Process a return value. */
4004 else if ((strncasecmp (name, "rtnval", 6) == 0))
4005 {
4006 p = input_line_pointer;
4007 *p = c;
4008 input_line_pointer++;
4009 name = input_line_pointer;
4010 c = get_symbol_end ();
4011 arg_reloc = pa_build_arg_reloc (name);
4012 call_desc->arg_reloc |= (arg_reloc & 0x3);
4013 }
4014 else
4015 {
4016 as_bad ("Invalid .CALL argument: %s", name);
4017 }
4018 p = input_line_pointer;
4019 *p = c;
4020 if (!is_end_of_statement ())
4021 input_line_pointer++;
4022 }
4023 }
4024
4025 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4026
4027 static int
4028 is_same_frag (frag1, frag2)
4029 fragS *frag1;
4030 fragS *frag2;
4031 {
4032
4033 if (frag1 == NULL)
4034 return (FALSE);
4035 else if (frag2 == NULL)
4036 return (FALSE);
4037 else if (frag1 == frag2)
4038 return (TRUE);
4039 else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0)
4040 return (is_same_frag (frag1, frag2->fr_next));
4041 else
4042 return (FALSE);
4043 }
4044
4045 #ifdef OBJ_ELF
4046 /* Build an entry in the UNWIND subspace from the given function
4047 attributes in CALL_INFO. This is not needed for SOM as using
4048 R_ENTRY and R_EXIT relocations allow the linker to handle building
4049 of the unwind spaces. */
4050
4051 static void
4052 pa_build_unwind_subspace (call_info)
4053 struct call_info *call_info;
4054 {
4055 char *unwind;
4056 asection *seg, *save_seg;
4057 subsegT subseg, save_subseg;
4058 int i;
4059 char c, *p;
4060
4061 /* Get into the right seg/subseg. This may involve creating
4062 the seg the first time through. Make sure to have the
4063 old seg/subseg so that we can reset things when we are done. */
4064 subseg = SUBSEG_UNWIND;
4065 seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
4066 if (seg == ASEC_NULL)
4067 {
4068 seg = bfd_make_section_old_way (stdoutput, UNWIND_SECTION_NAME);
4069 bfd_set_section_flags (stdoutput, seg,
4070 SEC_READONLY | SEC_HAS_CONTENTS
4071 | SEC_LOAD | SEC_RELOC);
4072 }
4073
4074 save_seg = now_seg;
4075 save_subseg = now_subseg;
4076 subseg_set (seg, subseg);
4077
4078
4079 /* Get some space to hold relocation information for the unwind
4080 descriptor. */
4081 p = frag_more (4);
4082
4083 /* Relocation info. for start offset of the function. */
4084 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4085 call_info->start_symbol, (offsetT) 0,
4086 (expressionS *) NULL, 0, R_HPPA_UNWIND, e_fsel, 32, 0,
4087 (char *) 0);
4088
4089 p = frag_more (4);
4090
4091 /* Relocation info. for end offset of the function. */
4092 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4093 call_info->end_symbol, (offsetT) 0,
4094 (expressionS *) NULL, 0, R_HPPA_UNWIND, e_fsel, 32, 0,
4095 (char *) 0);
4096
4097 /* Dump it. */
4098 unwind = (char *) &call_info->ci_unwind;
4099 for (i = 8; i < sizeof (struct unwind_table); i++)
4100 {
4101 c = *(unwind + i);
4102 {
4103 FRAG_APPEND_1_CHAR (c);
4104 }
4105 }
4106
4107 /* Return back to the original segment/subsegment. */
4108 subseg_set (save_seg, save_subseg);
4109 }
4110 #endif
4111
4112 /* Process a .CALLINFO pseudo-op. This information is used later
4113 to build unwind descriptors and maybe one day to support
4114 .ENTER and .LEAVE. */
4115
4116 static void
4117 pa_callinfo (unused)
4118 int unused;
4119 {
4120 char *name, c, *p;
4121 int temp;
4122
4123 /* .CALLINFO must appear within a procedure definition. */
4124 if (!within_procedure)
4125 as_bad (".callinfo is not within a procedure definition");
4126
4127 /* Mark the fact that we found the .CALLINFO for the
4128 current procedure. */
4129 callinfo_found = TRUE;
4130
4131 /* Iterate over the .CALLINFO arguments. */
4132 while (!is_end_of_statement ())
4133 {
4134 name = input_line_pointer;
4135 c = get_symbol_end ();
4136 /* Frame size specification. */
4137 if ((strncasecmp (name, "frame", 5) == 0))
4138 {
4139 p = input_line_pointer;
4140 *p = c;
4141 input_line_pointer++;
4142 temp = get_absolute_expression ();
4143 if ((temp & 0x3) != 0)
4144 {
4145 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp);
4146 temp = 0;
4147 }
4148
4149 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4150 last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
4151
4152 }
4153 /* Entry register (GR, GR and SR) specifications. */
4154 else if ((strncasecmp (name, "entry_gr", 8) == 0))
4155 {
4156 p = input_line_pointer;
4157 *p = c;
4158 input_line_pointer++;
4159 temp = get_absolute_expression ();
4160 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4161 even though %r19 is caller saved. I think this is a bug in
4162 the HP assembler, and we are not going to emulate it. */
4163 if (temp < 3 || temp > 18)
4164 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4165 last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
4166 }
4167 else if ((strncasecmp (name, "entry_fr", 8) == 0))
4168 {
4169 p = input_line_pointer;
4170 *p = c;
4171 input_line_pointer++;
4172 temp = get_absolute_expression ();
4173 /* Similarly the HP assembler takes 31 as the high bound even
4174 though %fr21 is the last callee saved floating point register. */
4175 if (temp < 12 || temp > 21)
4176 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4177 last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
4178 }
4179 else if ((strncasecmp (name, "entry_sr", 8) == 0))
4180 {
4181 p = input_line_pointer;
4182 *p = c;
4183 input_line_pointer++;
4184 temp = get_absolute_expression ();
4185 if (temp != 3)
4186 as_bad ("Value for ENTRY_SR must be 3\n");
4187 }
4188 /* Note whether or not this function performs any calls. */
4189 else if ((strncasecmp (name, "calls", 5) == 0) ||
4190 (strncasecmp (name, "caller", 6) == 0))
4191 {
4192 p = input_line_pointer;
4193 *p = c;
4194 }
4195 else if ((strncasecmp (name, "no_calls", 8) == 0))
4196 {
4197 p = input_line_pointer;
4198 *p = c;
4199 }
4200 /* Should RP be saved into the stack. */
4201 else if ((strncasecmp (name, "save_rp", 7) == 0))
4202 {
4203 p = input_line_pointer;
4204 *p = c;
4205 last_call_info->ci_unwind.descriptor.save_rp = 1;
4206 }
4207 /* Likewise for SP. */
4208 else if ((strncasecmp (name, "save_sp", 7) == 0))
4209 {
4210 p = input_line_pointer;
4211 *p = c;
4212 last_call_info->ci_unwind.descriptor.save_sp = 1;
4213 }
4214 /* Is this an unwindable procedure. If so mark it so
4215 in the unwind descriptor. */
4216 else if ((strncasecmp (name, "no_unwind", 9) == 0))
4217 {
4218 p = input_line_pointer;
4219 *p = c;
4220 last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
4221 }
4222 /* Is this an interrupt routine. If so mark it in the
4223 unwind descriptor. */
4224 else if ((strncasecmp (name, "hpux_int", 7) == 0))
4225 {
4226 p = input_line_pointer;
4227 *p = c;
4228 last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
4229 }
4230 else
4231 {
4232 as_bad ("Invalid .CALLINFO argument: %s", name);
4233 }
4234 if (!is_end_of_statement ())
4235 input_line_pointer++;
4236 }
4237
4238 demand_empty_rest_of_line ();
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 }
4266
4267 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4268 the .comm pseudo-op has the following symtax:
4269
4270 <label> .comm <length>
4271
4272 where <label> is optional and is a symbol whose address will be the start of
4273 a block of memory <length> bytes long. <length> must be an absolute
4274 expression. <length> bytes will be allocated in the current space
4275 and subspace. */
4276
4277 static void
4278 pa_comm (unused)
4279 int unused;
4280 {
4281 unsigned int size;
4282 symbolS *symbol;
4283 label_symbol_struct *label_symbol = pa_get_label ();
4284
4285 if (label_symbol)
4286 symbol = label_symbol->lss_label;
4287 else
4288 symbol = NULL;
4289
4290 SKIP_WHITESPACE ();
4291 size = get_absolute_expression ();
4292
4293 if (symbol)
4294 {
4295 /* It is incorrect to check S_IS_DEFINED at this point as
4296 the symbol will *always* be defined. FIXME. How to
4297 correctly determine when this label really as been
4298 defined before. */
4299 if (S_GET_VALUE (symbol))
4300 {
4301 if (S_GET_VALUE (symbol) != size)
4302 {
4303 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4304 S_GET_NAME (symbol), S_GET_VALUE (symbol));
4305 return;
4306 }
4307 }
4308 else
4309 {
4310 S_SET_VALUE (symbol, size);
4311 S_SET_SEGMENT (symbol, &bfd_und_section);
4312 S_SET_EXTERNAL (symbol);
4313 }
4314 }
4315 demand_empty_rest_of_line ();
4316 }
4317
4318 /* Process a .END pseudo-op. */
4319
4320 static void
4321 pa_end (unused)
4322 int unused;
4323 {
4324 demand_empty_rest_of_line ();
4325 }
4326
4327 /* Process a .ENTER pseudo-op. This is not supported. */
4328 static void
4329 pa_enter (unused)
4330 int unused;
4331 {
4332 abort ();
4333 }
4334
4335 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4336 procesure. */
4337 static void
4338 pa_entry (unused)
4339 int unused;
4340 {
4341 if (!within_procedure)
4342 as_bad ("Misplaced .entry. Ignored.");
4343 else
4344 {
4345 if (!callinfo_found)
4346 as_bad ("Missing .callinfo.");
4347 }
4348 demand_empty_rest_of_line ();
4349 within_entry_exit = TRUE;
4350
4351 /* Go back to the last symbol and turn on the BSF_FUNCTION flag.
4352 It will not be on if no .EXPORT pseudo-op exists (static function). */
4353 last_call_info->start_symbol->bsym->flags |= BSF_FUNCTION;
4354
4355 #ifdef OBJ_SOM
4356 /* SOM defers building of unwind descriptors until the link phase.
4357 The assembler is responsible for creating an R_ENTRY relocation
4358 to mark the beginning of a region and hold the unwind bits, and
4359 for creating an R_EXIT relocation to mark the end of the region.
4360
4361 FIXME. ELF should be using the same conventions! The problem
4362 is an unwind requires too much relocation space. Hmmm. Maybe
4363 if we split the unwind bits up between the relocations which
4364 denote the entry and exit points. */
4365 {
4366 char *where = frag_more (0);
4367
4368 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4369 last_call_info->start_symbol, (offsetT) 0, NULL,
4370 0, R_HPPA_ENTRY, e_fsel, 0, 0,
4371 (char *) &last_call_info->ci_unwind.descriptor);
4372 }
4373 #endif
4374 }
4375
4376 /* Handle a .EQU pseudo-op. */
4377
4378 static void
4379 pa_equ (reg)
4380 int reg;
4381 {
4382 label_symbol_struct *label_symbol = pa_get_label ();
4383 symbolS *symbol;
4384
4385 if (label_symbol)
4386 {
4387 symbol = label_symbol->lss_label;
4388 S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ());
4389 S_SET_SEGMENT (symbol, &bfd_abs_section);
4390 }
4391 else
4392 {
4393 if (reg)
4394 as_bad (".REG must use a label");
4395 else
4396 as_bad (".EQU must use a label");
4397 }
4398
4399 pa_undefine_label ();
4400 demand_empty_rest_of_line ();
4401 }
4402
4403 /* Helper function. Does processing for the end of a function. This
4404 usually involves creating some relocations or building special
4405 symbols to mark the end of the function. */
4406
4407 static void
4408 process_exit ()
4409 {
4410 char *where;
4411
4412 where = frag_more (0);
4413
4414 #ifdef OBJ_ELF
4415 /* Mark the end of the function, stuff away the location of the frag
4416 for the end of the function, and finally call pa_build_unwind_subspace
4417 to add an entry in the unwind table. */
4418 hppa_elf_mark_end_of_function ();
4419 pa_build_unwind_subspace (last_call_info);
4420 #else
4421 /* SOM defers building of unwind descriptors until the link phase.
4422 The assembler is responsible for creating an R_ENTRY relocation
4423 to mark the beginning of a region and hold the unwind bits, and
4424 for creating an R_EXIT relocation to mark the end of the region.
4425
4426 FIXME. ELF should be using the same conventions! The problem
4427 is an unwind requires too much relocation space. Hmmm. Maybe
4428 if we split the unwind bits up between the relocations which
4429 denote the entry and exit points. */
4430 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4431 last_call_info->start_symbol, (offsetT) 0,
4432 NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0, NULL);
4433 #endif
4434
4435 }
4436
4437 /* Process a .EXIT pseudo-op. */
4438
4439 static void
4440 pa_exit (unused)
4441 int unused;
4442 {
4443 if (!within_procedure)
4444 as_bad (".EXIT must appear within a procedure");
4445 else
4446 {
4447 if (!callinfo_found)
4448 as_bad ("Missing .callinfo");
4449 else
4450 {
4451 if (!within_entry_exit)
4452 as_bad ("No .ENTRY for this .EXIT");
4453 else
4454 {
4455 within_entry_exit = FALSE;
4456 process_exit ();
4457 }
4458 }
4459 }
4460 demand_empty_rest_of_line ();
4461 }
4462
4463 /* Process a .EXPORT directive. This makes functions external
4464 and provides information such as argument relocation entries
4465 to callers. */
4466
4467 static void
4468 pa_export (unused)
4469 int unused;
4470 {
4471 char *name, c, *p;
4472 symbolS *symbol;
4473
4474 name = input_line_pointer;
4475 c = get_symbol_end ();
4476 /* Make sure the given symbol exists. */
4477 if ((symbol = symbol_find_or_make (name)) == NULL)
4478 {
4479 as_bad ("Cannot define export symbol: %s\n", name);
4480 p = input_line_pointer;
4481 *p = c;
4482 input_line_pointer++;
4483 }
4484 else
4485 {
4486 /* OK. Set the external bits and process argument relocations. */
4487 S_SET_EXTERNAL (symbol);
4488 p = input_line_pointer;
4489 *p = c;
4490 if (!is_end_of_statement ())
4491 {
4492 input_line_pointer++;
4493 pa_type_args (symbol, 1);
4494 #ifdef OBJ_ELF
4495 pa_build_symextn_section ();
4496 #endif
4497 }
4498 }
4499
4500 demand_empty_rest_of_line ();
4501 }
4502
4503 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4504
4505 static void
4506 pa_type_args (symbolP, is_export)
4507 symbolS *symbolP;
4508 int is_export;
4509 {
4510 char *name, c, *p;
4511 unsigned int temp, arg_reloc;
4512 pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
4513 obj_symbol_type *symbol = (obj_symbol_type *) symbolP->bsym;
4514
4515 if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
4516
4517 {
4518 input_line_pointer += 8;
4519 symbolP->bsym->flags &= ~BSF_FUNCTION;
4520 S_SET_SEGMENT (symbolP, &bfd_abs_section);
4521 type = SYMBOL_TYPE_ABSOLUTE;
4522 }
4523 else if (strncasecmp (input_line_pointer, "code", 4) == 0)
4524 {
4525 input_line_pointer += 4;
4526 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4527 instead one should be IMPORTing/EXPORTing ENTRY types.
4528
4529 Complain if one tries to EXPORT a CODE type since that's never
4530 done. Both GCC and HP C still try to IMPORT CODE types, so
4531 silently fix them to be ENTRY types. */
4532 if (symbolP->bsym->flags & BSF_FUNCTION)
4533 {
4534 if (is_export)
4535 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP->bsym->name);
4536
4537 symbolP->bsym->flags |= BSF_FUNCTION;
4538 type = SYMBOL_TYPE_ENTRY;
4539 }
4540 else
4541 {
4542 symbolP->bsym->flags &= ~BSF_FUNCTION;
4543 type = SYMBOL_TYPE_CODE;
4544 }
4545 }
4546 else if (strncasecmp (input_line_pointer, "data", 4) == 0)
4547 {
4548 input_line_pointer += 4;
4549 symbolP->bsym->flags &= ~BSF_FUNCTION;
4550 type = SYMBOL_TYPE_DATA;
4551 }
4552 else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
4553 {
4554 input_line_pointer += 5;
4555 symbolP->bsym->flags |= BSF_FUNCTION;
4556 type = SYMBOL_TYPE_ENTRY;
4557 }
4558 else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
4559 {
4560 input_line_pointer += 9;
4561 symbolP->bsym->flags |= BSF_FUNCTION;
4562 type = SYMBOL_TYPE_MILLICODE;
4563 }
4564 else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
4565 {
4566 input_line_pointer += 6;
4567 symbolP->bsym->flags &= ~BSF_FUNCTION;
4568 type = SYMBOL_TYPE_PLABEL;
4569 }
4570 else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
4571 {
4572 input_line_pointer += 8;
4573 symbolP->bsym->flags |= BSF_FUNCTION;
4574 type = SYMBOL_TYPE_PRI_PROG;
4575 }
4576 else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
4577 {
4578 input_line_pointer += 8;
4579 symbolP->bsym->flags |= BSF_FUNCTION;
4580 type = SYMBOL_TYPE_SEC_PROG;
4581 }
4582
4583 /* SOM requires much more information about symbol types
4584 than BFD understands. This is how we get this information
4585 to the SOM BFD backend. */
4586 #ifdef obj_set_symbol_type
4587 obj_set_symbol_type (symbolP->bsym, (int) type);
4588 #endif
4589
4590 /* Now that the type of the exported symbol has been handled,
4591 handle any argument relocation information. */
4592 while (!is_end_of_statement ())
4593 {
4594 if (*input_line_pointer == ',')
4595 input_line_pointer++;
4596 name = input_line_pointer;
4597 c = get_symbol_end ();
4598 /* Argument sources. */
4599 if ((strncasecmp (name, "argw", 4) == 0))
4600 {
4601 p = input_line_pointer;
4602 *p = c;
4603 input_line_pointer++;
4604 temp = atoi (name + 4);
4605 name = input_line_pointer;
4606 c = get_symbol_end ();
4607 arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
4608 symbol->tc_data.hppa_arg_reloc |= arg_reloc;
4609 *input_line_pointer = c;
4610 }
4611 /* The return value. */
4612 else if ((strncasecmp (name, "rtnval", 6)) == 0)
4613 {
4614 p = input_line_pointer;
4615 *p = c;
4616 input_line_pointer++;
4617 name = input_line_pointer;
4618 c = get_symbol_end ();
4619 arg_reloc = pa_build_arg_reloc (name);
4620 symbol->tc_data.hppa_arg_reloc |= arg_reloc;
4621 *input_line_pointer = c;
4622 }
4623 /* Privelege level. */
4624 else if ((strncasecmp (name, "priv_lev", 8)) == 0)
4625 {
4626 p = input_line_pointer;
4627 *p = c;
4628 input_line_pointer++;
4629 temp = atoi (input_line_pointer);
4630 c = get_symbol_end ();
4631 *input_line_pointer = c;
4632 }
4633 else
4634 {
4635 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name);
4636 p = input_line_pointer;
4637 *p = c;
4638 }
4639 if (!is_end_of_statement ())
4640 input_line_pointer++;
4641 }
4642 }
4643
4644 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4645 assembly file must either be defined in the assembly file, or
4646 explicitly IMPORTED from another. */
4647
4648 static void
4649 pa_import (unused)
4650 int unused;
4651 {
4652 char *name, c, *p;
4653 symbolS *symbol;
4654
4655 name = input_line_pointer;
4656 c = get_symbol_end ();
4657
4658 symbol = symbol_find_or_make (name);
4659 p = input_line_pointer;
4660 *p = c;
4661
4662 if (!is_end_of_statement ())
4663 {
4664 input_line_pointer++;
4665 pa_type_args (symbol, 0);
4666 }
4667 else
4668 {
4669 /* Sigh. To be compatable with the HP assembler and to help
4670 poorly written assembly code, we assign a type based on
4671 the the current segment. Note only BSF_FUNCTION really
4672 matters, we do not need to set the full SYMBOL_TYPE_* info here. */
4673 if (now_seg == text_section)
4674 symbol->bsym->flags |= BSF_FUNCTION;
4675
4676 /* If the section is undefined, then the symbol is undefined
4677 Since this is an import, leave the section undefined. */
4678 S_SET_SEGMENT (symbol, &bfd_und_section);
4679 }
4680
4681 demand_empty_rest_of_line ();
4682 }
4683
4684 /* Handle a .LABEL pseudo-op. */
4685
4686 static void
4687 pa_label (unused)
4688 int unused;
4689 {
4690 char *name, c, *p;
4691
4692 name = input_line_pointer;
4693 c = get_symbol_end ();
4694
4695 if (strlen (name) > 0)
4696 {
4697 colon (name);
4698 p = input_line_pointer;
4699 *p = c;
4700 }
4701 else
4702 {
4703 as_warn ("Missing label name on .LABEL");
4704 }
4705
4706 if (!is_end_of_statement ())
4707 {
4708 as_warn ("extra .LABEL arguments ignored.");
4709 ignore_rest_of_line ();
4710 }
4711 demand_empty_rest_of_line ();
4712 }
4713
4714 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4715
4716 static void
4717 pa_leave (unused)
4718 int unused;
4719 {
4720 abort ();
4721 }
4722
4723 /* Handle a .ORIGIN pseudo-op. */
4724
4725 static void
4726 pa_origin (unused)
4727 int unused;
4728 {
4729 s_org (0);
4730 pa_undefine_label ();
4731 }
4732
4733 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4734 is for static functions. FIXME. Should share more code with .EXPORT. */
4735
4736 static void
4737 pa_param (unused)
4738 int unused;
4739 {
4740 char *name, c, *p;
4741 symbolS *symbol;
4742
4743 name = input_line_pointer;
4744 c = get_symbol_end ();
4745
4746 if ((symbol = symbol_find_or_make (name)) == NULL)
4747 {
4748 as_bad ("Cannot define static symbol: %s\n", name);
4749 p = input_line_pointer;
4750 *p = c;
4751 input_line_pointer++;
4752 }
4753 else
4754 {
4755 S_CLEAR_EXTERNAL (symbol);
4756 p = input_line_pointer;
4757 *p = c;
4758 if (!is_end_of_statement ())
4759 {
4760 input_line_pointer++;
4761 pa_type_args (symbol, 0);
4762 }
4763 }
4764
4765 demand_empty_rest_of_line ();
4766 }
4767
4768 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4769 of a procedure from a syntatical point of view. */
4770
4771 static void
4772 pa_proc (unused)
4773 int unused;
4774 {
4775 struct call_info *call_info;
4776
4777 if (within_procedure)
4778 as_fatal ("Nested procedures");
4779
4780 /* Reset global variables for new procedure. */
4781 callinfo_found = FALSE;
4782 within_procedure = TRUE;
4783
4784 /* Create another call_info structure. */
4785 call_info = (struct call_info *) xmalloc (sizeof (struct call_info));
4786
4787 if (!call_info)
4788 as_fatal ("Cannot allocate unwind descriptor\n");
4789
4790 bzero (call_info, sizeof (struct call_info));
4791
4792 call_info->ci_next = NULL;
4793
4794 if (call_info_root == NULL)
4795 {
4796 call_info_root = call_info;
4797 last_call_info = call_info;
4798 }
4799 else
4800 {
4801 last_call_info->ci_next = call_info;
4802 last_call_info = call_info;
4803 }
4804
4805 /* set up defaults on call_info structure */
4806
4807 call_info->ci_unwind.descriptor.cannot_unwind = 0;
4808 call_info->ci_unwind.descriptor.region_desc = 1;
4809 call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
4810
4811 /* If we got a .PROC pseudo-op, we know that the function is defined
4812 locally. Make sure it gets into the symbol table. */
4813 {
4814 label_symbol_struct *label_symbol = pa_get_label ();
4815
4816 if (label_symbol)
4817 {
4818 if (label_symbol->lss_label)
4819 {
4820 last_call_info->start_symbol = label_symbol->lss_label;
4821 label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
4822 }
4823 else
4824 as_bad ("Missing function name for .PROC (corrupted label)");
4825 }
4826 else
4827 as_bad ("Missing function name for .PROC");
4828 }
4829
4830 demand_empty_rest_of_line ();
4831 }
4832
4833 /* Process the syntatical end of a procedure. Make sure all the
4834 appropriate pseudo-ops were found within the procedure. */
4835
4836 static void
4837 pa_procend (unused)
4838 int unused;
4839 {
4840
4841 if (!within_procedure)
4842 as_bad ("misplaced .procend");
4843
4844 if (!callinfo_found)
4845 as_bad ("Missing .callinfo for this procedure");
4846
4847 if (within_entry_exit)
4848 as_bad ("Missing .EXIT for a .ENTRY");
4849
4850 #ifdef OBJ_ELF
4851 /* ELF needs to mark the end of each function so that it can compute
4852 the size of the function (apparently its needed in the symbol table. */
4853 hppa_elf_mark_end_of_function ();
4854 #endif
4855
4856 within_procedure = FALSE;
4857 demand_empty_rest_of_line ();
4858 }
4859
4860 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
4861 then create a new space entry to hold the information specified
4862 by the parameters to the .SPACE directive. */
4863
4864 static sd_chain_struct *
4865 pa_parse_space_stmt (space_name, create_flag)
4866 char *space_name;
4867 int create_flag;
4868 {
4869 char *name, *ptemp, c;
4870 char loadable, defined, private, sort;
4871 int spnum;
4872 asection *seg = NULL;
4873 sd_chain_struct *space;
4874
4875 /* load default values */
4876 spnum = 0;
4877 sort = 0;
4878 loadable = TRUE;
4879 defined = TRUE;
4880 private = FALSE;
4881 if (strcasecmp (space_name, "$TEXT$") == 0)
4882 {
4883 seg = pa_def_spaces[0].segment;
4884 sort = pa_def_spaces[0].sort;
4885 }
4886 else if (strcasecmp (space_name, "$PRIVATE$") == 0)
4887 {
4888 seg = pa_def_spaces[1].segment;
4889 sort = pa_def_spaces[1].sort;
4890 }
4891
4892 if (!is_end_of_statement ())
4893 {
4894 print_errors = FALSE;
4895 ptemp = input_line_pointer + 1;
4896 /* First see if the space was specified as a number rather than
4897 as a name. According to the PA assembly manual the rest of
4898 the line should be ignored. */
4899 if ((spnum = pa_parse_number (&ptemp, 0)) >= 0)
4900 input_line_pointer = ptemp;
4901 else
4902 {
4903 while (!is_end_of_statement ())
4904 {
4905 input_line_pointer++;
4906 name = input_line_pointer;
4907 c = get_symbol_end ();
4908 if ((strncasecmp (name, "SPNUM", 5) == 0))
4909 {
4910 *input_line_pointer = c;
4911 input_line_pointer++;
4912 spnum = get_absolute_expression ();
4913 }
4914 else if ((strncasecmp (name, "SORT", 4) == 0))
4915 {
4916 *input_line_pointer = c;
4917 input_line_pointer++;
4918 sort = get_absolute_expression ();
4919 }
4920 else if ((strncasecmp (name, "UNLOADABLE", 10) == 0))
4921 {
4922 *input_line_pointer = c;
4923 loadable = FALSE;
4924 }
4925 else if ((strncasecmp (name, "NOTDEFINED", 10) == 0))
4926 {
4927 *input_line_pointer = c;
4928 defined = FALSE;
4929 }
4930 else if ((strncasecmp (name, "PRIVATE", 7) == 0))
4931 {
4932 *input_line_pointer = c;
4933 private = TRUE;
4934 }
4935 else
4936 {
4937 as_bad ("Invalid .SPACE argument");
4938 *input_line_pointer = c;
4939 if (!is_end_of_statement ())
4940 input_line_pointer++;
4941 }
4942 }
4943 }
4944 print_errors = TRUE;
4945 }
4946
4947 if (create_flag && seg == NULL)
4948 seg = subseg_new (space_name, 0);
4949
4950 /* If create_flag is nonzero, then create the new space with
4951 the attributes computed above. Else set the values in
4952 an already existing space -- this can only happen for
4953 the first occurence of a built-in space. */
4954 if (create_flag)
4955 space = create_new_space (space_name, spnum, loadable, defined,
4956 private, sort, seg, 1);
4957 else
4958 {
4959 space = is_defined_space (space_name);
4960 SPACE_SPNUM (space) = spnum;
4961 SPACE_DEFINED (space) = defined & 1;
4962 SPACE_USER_DEFINED (space) = 1;
4963 space->sd_seg = seg;
4964 }
4965
4966 #ifdef obj_set_section_attributes
4967 obj_set_section_attributes (seg, defined, private, sort, spnum);
4968 #endif
4969
4970 return space;
4971 }
4972
4973 /* Handle a .SPACE pseudo-op; this switches the current space to the
4974 given space, creating the new space if necessary. */
4975
4976 static void
4977 pa_space (unused)
4978 int unused;
4979 {
4980 char *name, c, *space_name, *save_s;
4981 int temp;
4982 sd_chain_struct *sd_chain;
4983
4984 if (within_procedure)
4985 {
4986 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
4987 ignore_rest_of_line ();
4988 }
4989 else
4990 {
4991 /* Check for some of the predefined spaces. FIXME: most of the code
4992 below is repeated several times, can we extract the common parts
4993 and place them into a subroutine or something similar? */
4994 if (strncasecmp (input_line_pointer, "$text$", 6) == 0)
4995 {
4996 input_line_pointer += 6;
4997 sd_chain = is_defined_space ("$TEXT$");
4998 if (sd_chain == NULL)
4999 sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
5000 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5001 sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
5002
5003 current_space = sd_chain;
5004 subseg_set (text_section, sd_chain->sd_last_subseg);
5005 current_subspace
5006 = pa_subsegment_to_subspace (text_section,
5007 sd_chain->sd_last_subseg);
5008 demand_empty_rest_of_line ();
5009 return;
5010 }
5011 if (strncasecmp (input_line_pointer, "$private$", 9) == 0)
5012 {
5013 input_line_pointer += 9;
5014 sd_chain = is_defined_space ("$PRIVATE$");
5015 if (sd_chain == NULL)
5016 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
5017 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5018 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
5019
5020 current_space = sd_chain;
5021 subseg_set (data_section, sd_chain->sd_last_subseg);
5022 current_subspace
5023 = pa_subsegment_to_subspace (data_section,
5024 sd_chain->sd_last_subseg);
5025 demand_empty_rest_of_line ();
5026 return;
5027 }
5028 if (!strncasecmp (input_line_pointer,
5029 GDB_DEBUG_SPACE_NAME,
5030 strlen (GDB_DEBUG_SPACE_NAME)))
5031 {
5032 input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
5033 sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
5034 if (sd_chain == NULL)
5035 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
5036 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5037 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
5038
5039 current_space = sd_chain;
5040
5041 {
5042 asection *gdb_section
5043 = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
5044
5045 subseg_set (gdb_section, sd_chain->sd_last_subseg);
5046 current_subspace
5047 = pa_subsegment_to_subspace (gdb_section,
5048 sd_chain->sd_last_subseg);
5049 }
5050 demand_empty_rest_of_line ();
5051 return;
5052 }
5053
5054 /* It could be a space specified by number. */
5055 print_errors = 0;
5056 save_s = input_line_pointer;
5057 if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0)
5058 {
5059 if (sd_chain = pa_find_space_by_number (temp))
5060 {
5061 current_space = sd_chain;
5062
5063 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
5064 current_subspace
5065 = pa_subsegment_to_subspace (sd_chain->sd_seg,
5066 sd_chain->sd_last_subseg);
5067 demand_empty_rest_of_line ();
5068 return;
5069 }
5070 }
5071
5072 /* Not a number, attempt to create a new space. */
5073 print_errors = 1;
5074 input_line_pointer = save_s;
5075 name = input_line_pointer;
5076 c = get_symbol_end ();
5077 space_name = xmalloc (strlen (name) + 1);
5078 strcpy (space_name, name);
5079 *input_line_pointer = c;
5080
5081 sd_chain = pa_parse_space_stmt (space_name, 1);
5082 current_space = sd_chain;
5083
5084 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
5085 current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
5086 sd_chain->sd_last_subseg);
5087 demand_empty_rest_of_line ();
5088 }
5089 }
5090
5091 /* Switch to a new space. (I think). FIXME. */
5092
5093 static void
5094 pa_spnum (unused)
5095 int unused;
5096 {
5097 char *name;
5098 char c;
5099 char *p;
5100 sd_chain_struct *space;
5101
5102 name = input_line_pointer;
5103 c = get_symbol_end ();
5104 space = is_defined_space (name);
5105 if (space)
5106 {
5107 p = frag_more (4);
5108 md_number_to_chars (p, SPACE_SPNUM (space), 4);
5109 }
5110 else
5111 as_warn ("Undefined space: '%s' Assuming space number = 0.", name);
5112
5113 *input_line_pointer = c;
5114 demand_empty_rest_of_line ();
5115 }
5116
5117 /* If VALUE is an exact power of two between zero and 2^31, then
5118 return log2 (VALUE). Else return -1. */
5119
5120 static int
5121 log2 (value)
5122 int value;
5123 {
5124 int shift = 0;
5125
5126 while ((1 << shift) != value && shift < 32)
5127 shift++;
5128
5129 if (shift >= 32)
5130 return -1;
5131 else
5132 return shift;
5133 }
5134
5135 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5136 given subspace, creating the new subspace if necessary.
5137
5138 FIXME. Should mirror pa_space more closely, in particular how
5139 they're broken up into subroutines. */
5140
5141 static void
5142 pa_subspace (unused)
5143 int unused;
5144 {
5145 char *name, *ss_name, *alias, c;
5146 char loadable, code_only, common, dup_common, zero, sort;
5147 int i, access, space_index, alignment, quadrant, applicable, flags;
5148 sd_chain_struct *space;
5149 ssd_chain_struct *ssd;
5150 asection *section;
5151
5152 if (within_procedure)
5153 {
5154 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5155 ignore_rest_of_line ();
5156 }
5157 else
5158 {
5159 name = input_line_pointer;
5160 c = get_symbol_end ();
5161 ss_name = xmalloc (strlen (name) + 1);
5162 strcpy (ss_name, name);
5163 *input_line_pointer = c;
5164
5165 /* Load default values. */
5166 sort = 0;
5167 access = 0x7f;
5168 loadable = 1;
5169 common = 0;
5170 dup_common = 0;
5171 code_only = 0;
5172 zero = 0;
5173 space_index = ~0;
5174 alignment = 0;
5175 quadrant = 0;
5176 alias = NULL;
5177
5178 space = current_space;
5179 ssd = is_defined_subspace (ss_name);
5180 /* Allow user to override the builtin attributes of subspaces. But
5181 only allow the attributes to be changed once! */
5182 if (ssd && SUBSPACE_DEFINED (ssd))
5183 {
5184 subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
5185 if (!is_end_of_statement ())
5186 as_warn ("Parameters of an existing subspace can\'t be modified");
5187 demand_empty_rest_of_line ();
5188 return;
5189 }
5190 else
5191 {
5192 /* A new subspace. Load default values if it matches one of
5193 the builtin subspaces. */
5194 i = 0;
5195 while (pa_def_subspaces[i].name)
5196 {
5197 if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
5198 {
5199 loadable = pa_def_subspaces[i].loadable;
5200 common = pa_def_subspaces[i].common;
5201 dup_common = pa_def_subspaces[i].dup_common;
5202 code_only = pa_def_subspaces[i].code_only;
5203 zero = pa_def_subspaces[i].zero;
5204 space_index = pa_def_subspaces[i].space_index;
5205 alignment = pa_def_subspaces[i].alignment;
5206 quadrant = pa_def_subspaces[i].quadrant;
5207 access = pa_def_subspaces[i].access;
5208 sort = pa_def_subspaces[i].sort;
5209 if (USE_ALIASES && pa_def_subspaces[i].alias)
5210 alias = pa_def_subspaces[i].alias;
5211 break;
5212 }
5213 i++;
5214 }
5215 }
5216
5217 /* We should be working with a new subspace now. Fill in
5218 any information as specified by the user. */
5219 if (!is_end_of_statement ())
5220 {
5221 input_line_pointer++;
5222 while (!is_end_of_statement ())
5223 {
5224 name = input_line_pointer;
5225 c = get_symbol_end ();
5226 if ((strncasecmp (name, "QUAD", 4) == 0))
5227 {
5228 *input_line_pointer = c;
5229 input_line_pointer++;
5230 quadrant = get_absolute_expression ();
5231 }
5232 else if ((strncasecmp (name, "ALIGN", 5) == 0))
5233 {
5234 *input_line_pointer = c;
5235 input_line_pointer++;
5236 alignment = get_absolute_expression ();
5237 if (log2 (alignment) == -1)
5238 {
5239 as_bad ("Alignment must be a power of 2");
5240 alignment = 1;
5241 }
5242 }
5243 else if ((strncasecmp (name, "ACCESS", 6) == 0))
5244 {
5245 *input_line_pointer = c;
5246 input_line_pointer++;
5247 access = get_absolute_expression ();
5248 }
5249 else if ((strncasecmp (name, "SORT", 4) == 0))
5250 {
5251 *input_line_pointer = c;
5252 input_line_pointer++;
5253 sort = get_absolute_expression ();
5254 }
5255 else if ((strncasecmp (name, "CODE_ONLY", 9) == 0))
5256 {
5257 *input_line_pointer = c;
5258 code_only = 1;
5259 }
5260 else if ((strncasecmp (name, "UNLOADABLE", 10) == 0))
5261 {
5262 *input_line_pointer = c;
5263 loadable = 0;
5264 }
5265 else if ((strncasecmp (name, "COMMON", 6) == 0))
5266 {
5267 *input_line_pointer = c;
5268 common = 1;
5269 }
5270 else if ((strncasecmp (name, "DUP_COMM", 8) == 0))
5271 {
5272 *input_line_pointer = c;
5273 dup_common = 1;
5274 }
5275 else if ((strncasecmp (name, "ZERO", 4) == 0))
5276 {
5277 *input_line_pointer = c;
5278 zero = 1;
5279 }
5280 else if ((strncasecmp (name, "FIRST", 5) == 0))
5281 as_bad ("FIRST not supported as a .SUBSPACE argument");
5282 else
5283 as_bad ("Invalid .SUBSPACE argument");
5284 if (!is_end_of_statement ())
5285 input_line_pointer++;
5286 }
5287 }
5288
5289 /* Compute a reasonable set of BFD flags based on the information
5290 in the .subspace directive. */
5291 applicable = bfd_applicable_section_flags (stdoutput);
5292 flags = 0;
5293 if (loadable)
5294 flags |= (SEC_ALLOC | SEC_LOAD);
5295 if (code_only)
5296 flags |= SEC_CODE;
5297 if (common || dup_common)
5298 flags |= SEC_IS_COMMON;
5299
5300 /* This is a zero-filled subspace (eg BSS). */
5301 if (zero)
5302 flags &= ~SEC_LOAD;
5303
5304 flags |= SEC_RELOC | SEC_HAS_CONTENTS;
5305 applicable &= flags;
5306
5307 /* If this is an existing subspace, then we want to use the
5308 segment already associated with the subspace.
5309
5310 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5311 lots of sections. It might be a problem in the PA ELF
5312 code, I do not know yet. For now avoid creating anything
5313 but the "standard" sections for ELF. */
5314 if (ssd)
5315 section = ssd->ssd_seg;
5316 else if (alias)
5317 section = subseg_new (alias, 0);
5318 else if (!alias && USE_ALIASES)
5319 {
5320 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5321 demand_empty_rest_of_line ();
5322 return;
5323 }
5324 else
5325 section = subseg_new (ss_name, 0);
5326
5327 /* Now set the flags. */
5328 bfd_set_section_flags (stdoutput, section, applicable);
5329
5330 /* Record any alignment request for this section. */
5331 record_alignment (section, log2 (alignment));
5332
5333 /* Set the starting offset for this section. */
5334 bfd_set_section_vma (stdoutput, section,
5335 pa_subspace_start (space, quadrant));
5336
5337 /* Now that all the flags are set, update an existing subspace,
5338 or create a new one. */
5339 if (ssd)
5340
5341 current_subspace = update_subspace (space, ss_name, loadable,
5342 code_only, common, dup_common,
5343 sort, zero, access, space_index,
5344 alignment, quadrant,
5345 section);
5346 else
5347 current_subspace = create_new_subspace (space, ss_name, loadable,
5348 code_only, common,
5349 dup_common, zero, sort,
5350 access, space_index,
5351 alignment, quadrant, section);
5352
5353 demand_empty_rest_of_line ();
5354 current_subspace->ssd_seg = section;
5355 subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
5356 }
5357 SUBSPACE_DEFINED (current_subspace) = 1;
5358 }
5359
5360
5361 /* Create default space and subspace dictionaries. */
5362
5363 static void
5364 pa_spaces_begin ()
5365 {
5366 int i;
5367
5368 space_dict_root = NULL;
5369 space_dict_last = NULL;
5370
5371 i = 0;
5372 while (pa_def_spaces[i].name)
5373 {
5374 char *name;
5375
5376 /* Pick the right name to use for the new section. */
5377 if (pa_def_spaces[i].alias && USE_ALIASES)
5378 name = pa_def_spaces[i].alias;
5379 else
5380 name = pa_def_spaces[i].name;
5381
5382 pa_def_spaces[i].segment = subseg_new (name, 0);
5383 create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
5384 pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
5385 pa_def_spaces[i].private, pa_def_spaces[i].sort,
5386 pa_def_spaces[i].segment, 0);
5387 i++;
5388 }
5389
5390 i = 0;
5391 while (pa_def_subspaces[i].name)
5392 {
5393 char *name;
5394 int applicable, subsegment;
5395 asection *segment = NULL;
5396 sd_chain_struct *space;
5397
5398 /* Pick the right name for the new section and pick the right
5399 subsegment number. */
5400 if (pa_def_subspaces[i].alias && USE_ALIASES)
5401 {
5402 name = pa_def_subspaces[i].alias;
5403 subsegment = pa_def_subspaces[i].subsegment;
5404 }
5405 else
5406 {
5407 name = pa_def_subspaces[i].name;
5408 subsegment = 0;
5409 }
5410
5411 /* Create the new section. */
5412 segment = subseg_new (name, subsegment);
5413
5414
5415 /* For SOM we want to replace the standard .text, .data, and .bss
5416 sections with our own. */
5417 if (!strcmp (pa_def_subspaces[i].name, "$CODE$") && !USE_ALIASES)
5418 {
5419 text_section = segment;
5420 applicable = bfd_applicable_section_flags (stdoutput);
5421 bfd_set_section_flags (stdoutput, text_section,
5422 applicable & (SEC_ALLOC | SEC_LOAD
5423 | SEC_RELOC | SEC_CODE
5424 | SEC_READONLY
5425 | SEC_HAS_CONTENTS));
5426 }
5427 else if (!strcmp (pa_def_subspaces[i].name, "$DATA$") && !USE_ALIASES)
5428 {
5429 data_section = segment;
5430 applicable = bfd_applicable_section_flags (stdoutput);
5431 bfd_set_section_flags (stdoutput, data_section,
5432 applicable & (SEC_ALLOC | SEC_LOAD
5433 | SEC_RELOC
5434 | SEC_HAS_CONTENTS));
5435
5436
5437 }
5438 else if (!strcmp (pa_def_subspaces[i].name, "$BSS$") && !USE_ALIASES)
5439 {
5440 bss_section = segment;
5441 applicable = bfd_applicable_section_flags (stdoutput);
5442 bfd_set_section_flags (stdoutput, bss_section,
5443 applicable & SEC_ALLOC);
5444 }
5445
5446 /* Find the space associated with this subspace. */
5447 space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
5448 def_space_index].segment);
5449 if (space == NULL)
5450 {
5451 as_fatal ("Internal error: Unable to find containing space for %s.",
5452 pa_def_subspaces[i].name);
5453 }
5454
5455 create_new_subspace (space, name,
5456 pa_def_subspaces[i].loadable,
5457 pa_def_subspaces[i].code_only,
5458 pa_def_subspaces[i].common,
5459 pa_def_subspaces[i].dup_common,
5460 pa_def_subspaces[i].zero,
5461 pa_def_subspaces[i].sort,
5462 pa_def_subspaces[i].access,
5463 pa_def_subspaces[i].space_index,
5464 pa_def_subspaces[i].alignment,
5465 pa_def_subspaces[i].quadrant,
5466 segment);
5467 i++;
5468 }
5469 }
5470
5471
5472
5473 /* Create a new space NAME, with the appropriate flags as defined
5474 by the given parameters. */
5475
5476 static sd_chain_struct *
5477 create_new_space (name, spnum, loadable, defined, private,
5478 sort, seg, user_defined)
5479 char *name;
5480 int spnum;
5481 char loadable;
5482 char defined;
5483 char private;
5484 char sort;
5485 asection *seg;
5486 int user_defined;
5487 {
5488 sd_chain_struct *chain_entry;
5489
5490 chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct));
5491 if (!chain_entry)
5492 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5493 name);
5494
5495 SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
5496 strcpy (SPACE_NAME (chain_entry), name);
5497 SPACE_DEFINED (chain_entry) = defined;
5498 SPACE_USER_DEFINED (chain_entry) = user_defined;
5499 SPACE_SPNUM (chain_entry) = spnum;
5500
5501 chain_entry->sd_seg = seg;
5502 chain_entry->sd_last_subseg = -1;
5503 chain_entry->sd_next = NULL;
5504
5505 /* Find spot for the new space based on its sort key. */
5506 if (!space_dict_last)
5507 space_dict_last = chain_entry;
5508
5509 if (space_dict_root == NULL)
5510 space_dict_root = chain_entry;
5511 else
5512 {
5513 sd_chain_struct *chain_pointer;
5514 sd_chain_struct *prev_chain_pointer;
5515
5516 chain_pointer = space_dict_root;
5517 prev_chain_pointer = NULL;
5518
5519 while (chain_pointer)
5520 {
5521 prev_chain_pointer = chain_pointer;
5522 chain_pointer = chain_pointer->sd_next;
5523 }
5524
5525 /* At this point we've found the correct place to add the new
5526 entry. So add it and update the linked lists as appropriate. */
5527 if (prev_chain_pointer)
5528 {
5529 chain_entry->sd_next = chain_pointer;
5530 prev_chain_pointer->sd_next = chain_entry;
5531 }
5532 else
5533 {
5534 space_dict_root = chain_entry;
5535 chain_entry->sd_next = chain_pointer;
5536 }
5537
5538 if (chain_entry->sd_next == NULL)
5539 space_dict_last = chain_entry;
5540 }
5541
5542 /* This is here to catch predefined spaces which do not get
5543 modified by the user's input. Another call is found at
5544 the bottom of pa_parse_space_stmt to handle cases where
5545 the user modifies a predefined space. */
5546 #ifdef obj_set_section_attributes
5547 obj_set_section_attributes (seg, defined, private, sort, spnum);
5548 #endif
5549
5550 return chain_entry;
5551 }
5552
5553 /* Create a new subspace NAME, with the appropriate flags as defined
5554 by the given parameters.
5555
5556 Add the new subspace to the subspace dictionary chain in numerical
5557 order as defined by the SORT entries. */
5558
5559 static ssd_chain_struct *
5560 create_new_subspace (space, name, loadable, code_only, common,
5561 dup_common, is_zero, sort, access, space_index,
5562 alignment, quadrant, seg)
5563 sd_chain_struct *space;
5564 char *name;
5565 char loadable, code_only, common, dup_common, is_zero;
5566 char sort;
5567 int access;
5568 int space_index;
5569 int alignment;
5570 int quadrant;
5571 asection *seg;
5572 {
5573 ssd_chain_struct *chain_entry;
5574
5575 chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct));
5576 if (!chain_entry)
5577 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name);
5578
5579 SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
5580 strcpy (SUBSPACE_NAME (chain_entry), name);
5581
5582 /* Initialize subspace_defined. When we hit a .subspace directive
5583 we'll set it to 1 which "locks-in" the subspace attributes. */
5584 SUBSPACE_DEFINED (chain_entry) = 0;
5585
5586 chain_entry->ssd_subseg = USE_ALIASES ? pa_next_subseg (space) : 0;
5587 chain_entry->ssd_seg = seg;
5588 chain_entry->ssd_next = NULL;
5589
5590 /* Find spot for the new subspace based on its sort key. */
5591 if (space->sd_subspaces == NULL)
5592 space->sd_subspaces = chain_entry;
5593 else
5594 {
5595 ssd_chain_struct *chain_pointer;
5596 ssd_chain_struct *prev_chain_pointer;
5597
5598 chain_pointer = space->sd_subspaces;
5599 prev_chain_pointer = NULL;
5600
5601 while (chain_pointer)
5602 {
5603 prev_chain_pointer = chain_pointer;
5604 chain_pointer = chain_pointer->ssd_next;
5605 }
5606
5607 /* Now we have somewhere to put the new entry. Insert it and update
5608 the links. */
5609 if (prev_chain_pointer)
5610 {
5611 chain_entry->ssd_next = chain_pointer;
5612 prev_chain_pointer->ssd_next = chain_entry;
5613 }
5614 else
5615 {
5616 space->sd_subspaces = chain_entry;
5617 chain_entry->ssd_next = chain_pointer;
5618 }
5619 }
5620
5621 #ifdef obj_set_subsection_attributes
5622 obj_set_subsection_attributes (seg, space->sd_seg, access,
5623 sort, quadrant);
5624 #endif
5625
5626 return chain_entry;
5627
5628 }
5629
5630 /* Update the information for the given subspace based upon the
5631 various arguments. Return the modified subspace chain entry. */
5632
5633 static ssd_chain_struct *
5634 update_subspace (space, name, loadable, code_only, common, dup_common, sort,
5635 zero, access, space_index, alignment, quadrant, section)
5636 sd_chain_struct *space;
5637 char *name;
5638 char loadable;
5639 char code_only;
5640 char common;
5641 char dup_common;
5642 char zero;
5643 char sort;
5644 int access;
5645 int space_index;
5646 int alignment;
5647 int quadrant;
5648 asection *section;
5649 {
5650 ssd_chain_struct *chain_entry;
5651
5652 chain_entry = is_defined_subspace (name);
5653
5654 #ifdef obj_set_subsection_attributes
5655 obj_set_subsection_attributes (section, space->sd_seg, access,
5656 sort, quadrant);
5657 #endif
5658
5659 return chain_entry;
5660
5661 }
5662
5663 /* Return the space chain entry for the space with the name NAME or
5664 NULL if no such space exists. */
5665
5666 static sd_chain_struct *
5667 is_defined_space (name)
5668 char *name;
5669 {
5670 sd_chain_struct *chain_pointer;
5671
5672 for (chain_pointer = space_dict_root;
5673 chain_pointer;
5674 chain_pointer = chain_pointer->sd_next)
5675 {
5676 if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
5677 return chain_pointer;
5678 }
5679
5680 /* No mapping from segment to space was found. Return NULL. */
5681 return NULL;
5682 }
5683
5684 /* Find and return the space associated with the given seg. If no mapping
5685 from the given seg to a space is found, then return NULL.
5686
5687 Unlike subspaces, the number of spaces is not expected to grow much,
5688 so a linear exhaustive search is OK here. */
5689
5690 static sd_chain_struct *
5691 pa_segment_to_space (seg)
5692 asection *seg;
5693 {
5694 sd_chain_struct *space_chain;
5695
5696 /* Walk through each space looking for the correct mapping. */
5697 for (space_chain = space_dict_root;
5698 space_chain;
5699 space_chain = space_chain->sd_next)
5700 {
5701 if (space_chain->sd_seg == seg)
5702 return space_chain;
5703 }
5704
5705 /* Mapping was not found. Return NULL. */
5706 return NULL;
5707 }
5708
5709 /* Return the space chain entry for the subspace with the name NAME or
5710 NULL if no such subspace exists.
5711
5712 Uses a linear search through all the spaces and subspaces, this may
5713 not be appropriate if we ever being placing each function in its
5714 own subspace. */
5715
5716 static ssd_chain_struct *
5717 is_defined_subspace (name)
5718 char *name;
5719 {
5720 sd_chain_struct *space_chain;
5721 ssd_chain_struct *subspace_chain;
5722
5723 /* Walk through each space. */
5724 for (space_chain = space_dict_root;
5725 space_chain;
5726 space_chain = space_chain->sd_next)
5727 {
5728 /* Walk through each subspace looking for a name which matches. */
5729 for (subspace_chain = space_chain->sd_subspaces;
5730 subspace_chain;
5731 subspace_chain = subspace_chain->ssd_next)
5732 if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
5733 return subspace_chain;
5734 }
5735
5736 /* Subspace wasn't found. Return NULL. */
5737 return NULL;
5738 }
5739
5740 /* Find and return the subspace associated with the given seg. If no
5741 mapping from the given seg to a subspace is found, then return NULL.
5742
5743 If we ever put each procedure/function within its own subspace
5744 (to make life easier on the compiler and linker), then this will have
5745 to become more efficient. */
5746
5747 static ssd_chain_struct *
5748 pa_subsegment_to_subspace (seg, subseg)
5749 asection *seg;
5750 subsegT subseg;
5751 {
5752 sd_chain_struct *space_chain;
5753 ssd_chain_struct *subspace_chain;
5754
5755 /* Walk through each space. */
5756 for (space_chain = space_dict_root;
5757 space_chain;
5758 space_chain = space_chain->sd_next)
5759 {
5760 if (space_chain->sd_seg == seg)
5761 {
5762 /* Walk through each subspace within each space looking for
5763 the correct mapping. */
5764 for (subspace_chain = space_chain->sd_subspaces;
5765 subspace_chain;
5766 subspace_chain = subspace_chain->ssd_next)
5767 if (subspace_chain->ssd_subseg == (int) subseg)
5768 return subspace_chain;
5769 }
5770 }
5771
5772 /* No mapping from subsegment to subspace found. Return NULL. */
5773 return NULL;
5774 }
5775
5776 /* Given a number, try and find a space with the name number.
5777
5778 Return a pointer to a space dictionary chain entry for the space
5779 that was found or NULL on failure. */
5780
5781 static sd_chain_struct *
5782 pa_find_space_by_number (number)
5783 int number;
5784 {
5785 sd_chain_struct *space_chain;
5786
5787 for (space_chain = space_dict_root;
5788 space_chain;
5789 space_chain = space_chain->sd_next)
5790 {
5791 if (SPACE_SPNUM (space_chain) == number)
5792 return space_chain;
5793 }
5794
5795 /* No appropriate space found. Return NULL. */
5796 return NULL;
5797 }
5798
5799 /* Return the starting address for the given subspace. If the starting
5800 address is unknown then return zero. */
5801
5802 static unsigned int
5803 pa_subspace_start (space, quadrant)
5804 sd_chain_struct *space;
5805 int quadrant;
5806 {
5807 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5808 is not correct for the PA OSF1 port. */
5809 if ((strcasecmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
5810 return 0x40000000;
5811 else if (space->sd_seg == data_section && quadrant == 1)
5812 return 0x40000000;
5813 else
5814 return 0;
5815 }
5816
5817 /* FIXME. Needs documentation. */
5818 static int
5819 pa_next_subseg (space)
5820 sd_chain_struct *space;
5821 {
5822
5823 space->sd_last_subseg++;
5824 return space->sd_last_subseg;
5825 }
5826
5827 /* Helper function for pa_stringer. Used to find the end of
5828 a string. */
5829
5830 static unsigned int
5831 pa_stringer_aux (s)
5832 char *s;
5833 {
5834 unsigned int c = *s & CHAR_MASK;
5835 switch (c)
5836 {
5837 case '\"':
5838 c = NOT_A_CHAR;
5839 break;
5840 default:
5841 break;
5842 }
5843 return c;
5844 }
5845
5846 /* Handle a .STRING type pseudo-op. */
5847
5848 static void
5849 pa_stringer (append_zero)
5850 int append_zero;
5851 {
5852 char *s, num_buf[4];
5853 unsigned int c;
5854 int i;
5855
5856 /* Preprocess the string to handle PA-specific escape sequences.
5857 For example, \xDD where DD is a hexidecimal number should be
5858 changed to \OOO where OOO is an octal number. */
5859
5860 /* Skip the opening quote. */
5861 s = input_line_pointer + 1;
5862
5863 while (is_a_char (c = pa_stringer_aux (s++)))
5864 {
5865 if (c == '\\')
5866 {
5867 c = *s;
5868 switch (c)
5869 {
5870 /* Handle \x<num>. */
5871 case 'x':
5872 {
5873 unsigned int number;
5874 int num_digit;
5875 char dg;
5876 char *s_start = s;
5877
5878 /* Get pas the 'x'. */
5879 s++;
5880 for (num_digit = 0, number = 0, dg = *s;
5881 num_digit < 2
5882 && (isdigit (dg) || (dg >= 'a' && dg <= 'f')
5883 || (dg >= 'A' && dg <= 'F'));
5884 num_digit++)
5885 {
5886 if (isdigit (dg))
5887 number = number * 16 + dg - '0';
5888 else if (dg >= 'a' && dg <= 'f')
5889 number = number * 16 + dg - 'a' + 10;
5890 else
5891 number = number * 16 + dg - 'A' + 10;
5892
5893 s++;
5894 dg = *s;
5895 }
5896 if (num_digit > 0)
5897 {
5898 switch (num_digit)
5899 {
5900 case 1:
5901 sprintf (num_buf, "%02o", number);
5902 break;
5903 case 2:
5904 sprintf (num_buf, "%03o", number);
5905 break;
5906 }
5907 for (i = 0; i <= num_digit; i++)
5908 s_start[i] = num_buf[i];
5909 }
5910 break;
5911 }
5912 /* This might be a "\"", skip over the escaped char. */
5913 default:
5914 s++;
5915 break;
5916 }
5917 }
5918 }
5919 stringer (append_zero);
5920 pa_undefine_label ();
5921 }
5922
5923 /* Handle a .VERSION pseudo-op. */
5924
5925 static void
5926 pa_version (unused)
5927 int unused;
5928 {
5929 obj_version (0);
5930 pa_undefine_label ();
5931 }
5932
5933 /* Handle a .COPYRIGHT pseudo-op. */
5934
5935 static void
5936 pa_copyright (unused)
5937 int unused;
5938 {
5939 obj_copyright (0);
5940 pa_undefine_label ();
5941 }
5942
5943 /* Just like a normal cons, but when finished we have to undefine
5944 the latest space label. */
5945
5946 static void
5947 pa_cons (nbytes)
5948 int nbytes;
5949 {
5950 cons (nbytes);
5951 pa_undefine_label ();
5952 }
5953
5954 /* Switch to the data space. As usual delete our label. */
5955
5956 static void
5957 pa_data (unused)
5958 int unused;
5959 {
5960 s_data (0);
5961 pa_undefine_label ();
5962 }
5963
5964 /* Like float_cons, but we need to undefine our label. */
5965
5966 static void
5967 pa_float_cons (float_type)
5968 int float_type;
5969 {
5970 float_cons (float_type);
5971 pa_undefine_label ();
5972 }
5973
5974 /* Like s_fill, but delete our label when finished. */
5975
5976 static void
5977 pa_fill (unused)
5978 int unused;
5979 {
5980 s_fill (0);
5981 pa_undefine_label ();
5982 }
5983
5984 /* Like lcomm, but delete our label when finished. */
5985
5986 static void
5987 pa_lcomm (needs_align)
5988 int needs_align;
5989 {
5990 s_lcomm (needs_align);
5991 pa_undefine_label ();
5992 }
5993
5994 /* Like lsym, but delete our label when finished. */
5995
5996 static void
5997 pa_lsym (unused)
5998 int unused;
5999 {
6000 s_lsym (0);
6001 pa_undefine_label ();
6002 }
6003
6004 /* Switch to the text space. Like s_text, but delete our
6005 label when finished. */
6006 static void
6007 pa_text (unused)
6008 int unused;
6009 {
6010 s_text (0);
6011 pa_undefine_label ();
6012 }
6013
6014 /* On the PA relocations which involve function symbols must not be
6015 adjusted. This so that the linker can know when/how to create argument
6016 relocation stubs for indirect calls and calls to static functions.
6017
6018 FIXME. Also reject R_HPPA relocations which are 32 bits
6019 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6020 needs to generate relocations to push the addend and symbol value
6021 onto the stack, add them, then pop the value off the stack and
6022 use it in a relocation -- yuk. */
6023
6024 int
6025 hppa_fix_adjustable (fixp)
6026 fixS *fixp;
6027 {
6028 struct hppa_fix_struct *hppa_fix;
6029
6030 hppa_fix = fixp->tc_fix_data;
6031
6032 if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32)
6033 return 0;
6034
6035 if (fixp->fx_addsy == 0
6036 || (fixp->fx_addsy->bsym->flags & BSF_FUNCTION) == 0)
6037 return 1;
6038
6039 return 0;
6040 }
6041
6042 /* Return nonzero if the fixup in FIXP will require a relocation,
6043 even it if appears that the fixup could be completely handled
6044 within GAS. */
6045
6046 int
6047 hppa_force_relocation (fixp)
6048 fixS *fixp;
6049 {
6050 struct hppa_fix_struct *hppa_fixp = fixp->tc_fix_data;
6051
6052 #ifdef OBJ_SOM
6053 if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT)
6054 return 1;
6055 #endif
6056
6057 #define stub_needed(CALLER, CALLEE) \
6058 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6059
6060 /* It is necessary to force PC-relative calls/jumps to have a relocation
6061 entry if they're going to need either a argument relocation or long
6062 call stub. FIXME. Can't we need the same for absolute calls? */
6063 if (fixp->fx_pcrel && fixp->fx_addsy
6064 && (stub_needed (((obj_symbol_type *)
6065 fixp->fx_addsy->bsym)->tc_data.hppa_arg_reloc,
6066 hppa_fixp->fx_arg_reloc)))
6067 return 1;
6068
6069 #undef stub_needed
6070
6071 /* No need (yet) to force another relocations to be emitted. */
6072 return 0;
6073 }
6074
6075 /* Now for some ELF specific code. FIXME. */
6076 #ifdef OBJ_ELF
6077 static symext_chainS *symext_rootP;
6078 static symext_chainS *symext_lastP;
6079
6080 /* Mark the end of a function so that it's possible to compute
6081 the size of the function in hppa_elf_final_processing. */
6082
6083 static void
6084 hppa_elf_mark_end_of_function ()
6085 {
6086 /* ELF does not have EXIT relocations. All we do is create a
6087 temporary symbol marking the end of the function. */
6088 char *name = (char *)
6089 xmalloc (strlen ("L$\001end_") +
6090 strlen (S_GET_NAME (last_call_info->start_symbol)) + 1);
6091
6092 if (name)
6093 {
6094 symbolS *symbolP;
6095
6096 strcpy (name, "L$\001end_");
6097 strcat (name, S_GET_NAME (last_call_info->start_symbol));
6098
6099 /* If we have a .exit followed by a .procend, then the
6100 symbol will have already been defined. */
6101 symbolP = symbol_find (name);
6102 if (symbolP)
6103 {
6104 /* The symbol has already been defined! This can
6105 happen if we have a .exit followed by a .procend.
6106
6107 This is *not* an error. All we want to do is free
6108 the memory we just allocated for the name and continue. */
6109 xfree (name);
6110 }
6111 else
6112 {
6113 /* symbol value should be the offset of the
6114 last instruction of the function */
6115 symbolP = symbol_new (name, now_seg,
6116 (valueT) (obstack_next_free (&frags)
6117 - frag_now->fr_literal - 4),
6118 frag_now);
6119
6120 assert (symbolP);
6121 symbolP->bsym->flags = BSF_LOCAL;
6122 symbol_table_insert (symbolP);
6123 }
6124
6125 if (symbolP)
6126 last_call_info->end_symbol = symbolP;
6127 else
6128 as_bad ("Symbol '%s' could not be created.", name);
6129
6130 }
6131 else
6132 as_bad ("No memory for symbol name.");
6133
6134 }
6135
6136 /* Do any symbol processing requested by the target-cpu or target-format. */
6137
6138 void
6139 hppa_tc_symbol (abfd, symbolP, sym_idx)
6140 bfd *abfd;
6141 elf_symbol_type *symbolP;
6142 int sym_idx;
6143 {
6144 symext_chainS *symextP;
6145 unsigned int arg_reloc;
6146
6147 /* Only functions can have argument relocations. */
6148 if (!(symbolP->symbol.flags & BSF_FUNCTION))
6149 return;
6150
6151 arg_reloc = symbolP->tc_data.hppa_arg_reloc;
6152
6153 /* If there are no argument relocation bits, then no relocation is
6154 necessary. Do not add this to the symextn section. */
6155 if (arg_reloc == 0)
6156 return;
6157
6158 symextP = (symext_chainS *) bfd_alloc (abfd, sizeof (symext_chainS) * 2);
6159
6160 symextP[0].entry = ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX, sym_idx);
6161 symextP[0].next = &symextP[1];
6162
6163 symextP[1].entry = ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC, arg_reloc);
6164 symextP[1].next = NULL;
6165
6166 if (symext_rootP == NULL)
6167 {
6168 symext_rootP = &symextP[0];
6169 symext_lastP = &symextP[1];
6170 }
6171 else
6172 {
6173 symext_lastP->next = &symextP[0];
6174 symext_lastP = &symextP[1];
6175 }
6176 }
6177
6178 /* Make sections needed by the target cpu and/or target format. */
6179 void
6180 hppa_tc_make_sections (abfd)
6181 bfd *abfd;
6182 {
6183 symext_chainS *symextP;
6184 segT save_seg = now_seg;
6185 subsegT save_subseg = now_subseg;
6186
6187 /* Build the symbol extension section. */
6188 hppa_tc_make_symextn_section ();
6189
6190 /* Force some calculation to occur. */
6191 bfd_set_section_contents (stdoutput, stdoutput->sections, "", 0, 0);
6192
6193 hppa_elf_stub_finish (abfd);
6194
6195 /* If no symbols for the symbol extension section, then stop now. */
6196 if (symext_rootP == NULL)
6197 return;
6198
6199 /* Switch to the symbol extension section. */
6200 subseg_new (SYMEXTN_SECTION_NAME, 0);
6201
6202 frag_wane (frag_now);
6203 frag_new (0);
6204
6205 for (symextP = symext_rootP; symextP; symextP = symextP->next)
6206 {
6207 char *ptr;
6208 int *symtab_map = elf_sym_extra (abfd);
6209 int idx;
6210
6211 /* First, patch the symbol extension record to reflect the true
6212 symbol table index. */
6213
6214 if (ELF32_HPPA_SX_TYPE (symextP->entry) == HPPA_SXT_SYMNDX)
6215 {
6216 idx = ELF32_HPPA_SX_VAL (symextP->entry) - 1;
6217 symextP->entry = ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX,
6218 symtab_map[idx]);
6219 }
6220
6221 ptr = frag_more (sizeof (symextP->entry));
6222 md_number_to_chars (ptr, symextP->entry, sizeof (symextP->entry));
6223 }
6224
6225 frag_now->fr_fix = obstack_next_free (&frags) - frag_now->fr_literal;
6226 frag_wane (frag_now);
6227
6228 /* Switch back to the original segment. */
6229 subseg_set (save_seg, save_subseg);
6230 }
6231
6232 /* Make the symbol extension section. */
6233
6234 static void
6235 hppa_tc_make_symextn_section ()
6236 {
6237 if (symext_rootP)
6238 {
6239 symext_chainS *symextP;
6240 int n;
6241 unsigned int size;
6242 segT symextn_sec;
6243 segT save_seg = now_seg;
6244 subsegT save_subseg = now_subseg;
6245
6246 for (n = 0, symextP = symext_rootP; symextP; symextP = symextP->next, ++n)
6247 ;
6248
6249 size = sizeof (symext_entryS) * n;
6250
6251 symextn_sec = subseg_new (SYMEXTN_SECTION_NAME, 0);
6252
6253 bfd_set_section_flags (stdoutput, symextn_sec,
6254 SEC_LOAD | SEC_HAS_CONTENTS | SEC_DATA);
6255 bfd_set_section_size (stdoutput, symextn_sec, size);
6256
6257 /* Now, switch back to the original segment. */
6258 subseg_set (save_seg, save_subseg);
6259 }
6260 }
6261
6262 /* Build the symbol extension section. */
6263
6264 static void
6265 pa_build_symextn_section ()
6266 {
6267 segT seg;
6268 asection *save_seg = now_seg;
6269 subsegT subseg = (subsegT) 0;
6270 subsegT save_subseg = now_subseg;
6271
6272 seg = subseg_new (".hppa_symextn", subseg);
6273 bfd_set_section_flags (stdoutput,
6274 seg,
6275 SEC_HAS_CONTENTS | SEC_READONLY
6276 | SEC_ALLOC | SEC_LOAD);
6277
6278 subseg_set (save_seg, save_subseg);
6279
6280 }
6281
6282 /* For ELF, this function serves one purpose: to setup the st_size
6283 field of STT_FUNC symbols. To do this, we need to scan the
6284 call_info structure list, determining st_size in by taking the
6285 difference in the address of the beginning/end marker symbols. */
6286
6287 void
6288 elf_hppa_final_processing ()
6289 {
6290 struct call_info *call_info_pointer;
6291
6292 for (call_info_pointer = call_info_root;
6293 call_info_pointer;
6294 call_info_pointer = call_info_pointer->ci_next)
6295 {
6296 elf_symbol_type *esym
6297 = (elf_symbol_type *) call_info_pointer->start_symbol->bsym;
6298 esym->internal_elf_sym.st_size =
6299 S_GET_VALUE (call_info_pointer->end_symbol)
6300 - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
6301 }
6302 }
6303 #endif