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