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