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