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