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