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