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