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