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