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