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