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