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