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