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