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