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