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