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