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