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