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