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