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