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