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