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