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