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