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