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