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