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