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