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