Don't merge labels. Don't merge if the symbol isn't constant. Don't call
[deliverable/binutils-gdb.git] / gas / config / tc-ns32k.c
1 /* ns32k.c -- Assemble on the National Semiconductor 32k series
2 Copyright (C) 1987, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 /*#define SHOW_NUM 1*//* uncomment for debugging */
23
24 #include <stdio.h>
25 #include <ctype.h>
26
27 #include "as.h"
28 #include "opcode/ns32k.h"
29
30 #include "obstack.h"
31
32 /* Macros */
33 #define IIF_ENTRIES 13 /* number of entries in iif */
34 #define PRIVATE_SIZE 256 /* size of my garbage memory */
35 #define MAX_ARGS 4
36 #define DEFAULT -1 /* addr_mode returns this value when
37 plain constant or label is
38 encountered */
39
40 #define IIF(ptr,a1,c1,e1,g1,i1,k1,m1,o1,q1,s1,u1) \
41 iif.iifP[ptr].type= a1; \
42 iif.iifP[ptr].size= c1; \
43 iif.iifP[ptr].object= e1; \
44 iif.iifP[ptr].object_adjust= g1; \
45 iif.iifP[ptr].pcrel= i1; \
46 iif.iifP[ptr].pcrel_adjust= k1; \
47 iif.iifP[ptr].im_disp= m1; \
48 iif.iifP[ptr].relax_substate= o1; \
49 iif.iifP[ptr].bit_fixP= q1; \
50 iif.iifP[ptr].addr_mode= s1; \
51 iif.iifP[ptr].bsr= u1;
52
53 #ifdef SEQUENT_COMPATABILITY
54 #define LINE_COMMENT_CHARS "|"
55 #define ABSOLUTE_PREFIX '@'
56 #define IMMEDIATE_PREFIX '#'
57 #endif
58
59 #ifndef LINE_COMMENT_CHARS
60 #define LINE_COMMENT_CHARS "#"
61 #endif
62
63 const char comment_chars[] = "#";
64 const char line_comment_chars[] = LINE_COMMENT_CHARS;
65 const char line_separator_chars[] = ";";
66 #if !defined(ABSOLUTE_PREFIX) && !defined(IMMEDIATE_PREFIX)
67 #define ABSOLUTE_PREFIX '@' /* One or the other MUST be defined */
68 #endif
69
70 struct addr_mode
71 {
72 char mode; /* addressing mode of operand (0-31) */
73 char scaled_mode; /* mode combined with scaled mode */
74 char scaled_reg; /* register used in scaled+1 (1-8) */
75 char float_flag; /* set if R0..R7 was F0..F7 ie a
76 floating-point-register */
77 char am_size; /* estimated max size of general addr-mode
78 parts */
79 char im_disp; /* if im_disp==1 we have a displacement */
80 char pcrel; /* 1 if pcrel, this is really redundant info */
81 char disp_suffix[2]; /* length of displacement(s), 0=undefined */
82 char *disp[2]; /* pointer(s) at displacement(s)
83 or immediates(s) (ascii) */
84 char index_byte; /* index byte */
85 };
86 typedef struct addr_mode addr_modeS;
87
88
89 char *freeptr, *freeptr_static; /* points at some number of free bytes */
90 struct hash_control *inst_hash_handle;
91
92 struct ns32k_opcode *desc; /* pointer at description of instruction */
93 addr_modeS addr_modeP;
94 const char EXP_CHARS[] = "eE";
95 const char FLT_CHARS[] = "fd"; /* we don't want to support lowercase, do we */
96
97 /* UPPERCASE denotes live names when an instruction is built, IIF is
98 * used as an intermediate form to store the actual parts of the
99 * instruction. A ns32k machine instruction can be divided into a
100 * couple of sub PARTs. When an instruction is assembled the
101 * appropriate PART get an assignment. When an IIF has been completed
102 * it is converted to a FRAGment as specified in AS.H */
103
104 /* internal structs */
105 struct ns32k_option
106 {
107 char *pattern;
108 unsigned long or;
109 unsigned long and;
110 };
111
112 typedef struct
113 {
114 int type; /* how to interpret object */
115 int size; /* Estimated max size of object */
116 unsigned long object; /* binary data */
117 int object_adjust; /* number added to object */
118 int pcrel; /* True if object is pcrel */
119 int pcrel_adjust; /* length in bytes from the
120 instruction start to the
121 displacement */
122 int im_disp; /* True if the object is a displacement */
123 relax_substateT relax_substate; /* Initial relaxsubstate */
124 bit_fixS *bit_fixP; /* Pointer at bit_fix struct */
125 int addr_mode; /* What addrmode do we associate with this
126 iif-entry */
127 char bsr; /* Sequent hack */
128 } iif_entryT; /* Internal Instruction Format */
129
130 struct int_ins_form
131 {
132 int instr_size; /* Max size of instruction in bytes. */
133 iif_entryT iifP[IIF_ENTRIES + 1];
134 };
135 struct int_ins_form iif;
136 expressionS exprP;
137 char *input_line_pointer;
138 /* description of the PARTs in IIF
139 *object[n]:
140 * 0 total length in bytes of entries in iif
141 * 1 opcode
142 * 2 index_byte_a
143 * 3 index_byte_b
144 * 4 disp_a_1
145 * 5 disp_a_2
146 * 6 disp_b_1
147 * 7 disp_b_2
148 * 8 imm_a
149 * 9 imm_b
150 * 10 implied1
151 * 11 implied2
152 *
153 * For every entry there is a datalength in bytes. This is stored in size[n].
154 * 0, the objectlength is not explicitly given by the instruction
155 * and the operand is undefined. This is a case for relaxation.
156 * Reserve 4 bytes for the final object.
157 *
158 * 1, the entry contains one byte
159 * 2, the entry contains two bytes
160 * 3, the entry contains three bytes
161 * 4, the entry contains four bytes
162 * etc
163 *
164 * Furthermore, every entry has a data type identifier in type[n].
165 *
166 * 0, the entry is void, ignore it.
167 * 1, the entry is a binary number.
168 * 2, the entry is a pointer at an expression.
169 * Where expression may be as simple as a single '1',
170 * and as complicated as foo-bar+12,
171 * foo and bar may be undefined but suffixed by :{b|w|d} to
172 * control the length of the object.
173 *
174 * 3, the entry is a pointer at a bignum struct
175 *
176 *
177 * The low-order-byte coresponds to low physical memory.
178 * Obviously a FRAGment must be created for each valid disp in PART whose
179 * datalength is undefined (to bad) .
180 * The case where just the expression is undefined is less severe and is
181 * handled by fix. Here the number of bytes in the objectfile is known.
182 * With this representation we simplify the assembly and separates the
183 * machine dependent/independent parts in a more clean way (said OE)
184 */
185 \f
186 struct ns32k_option opt1[] = /* restore, exit */
187 {
188 {"r0", 0x80, 0xff},
189 {"r1", 0x40, 0xff},
190 {"r2", 0x20, 0xff},
191 {"r3", 0x10, 0xff},
192 {"r4", 0x08, 0xff},
193 {"r5", 0x04, 0xff},
194 {"r6", 0x02, 0xff},
195 {"r7", 0x01, 0xff},
196 {0, 0x00, 0xff}
197 };
198 struct ns32k_option opt2[] = /* save, enter */
199 {
200 {"r0", 0x01, 0xff},
201 {"r1", 0x02, 0xff},
202 {"r2", 0x04, 0xff},
203 {"r3", 0x08, 0xff},
204 {"r4", 0x10, 0xff},
205 {"r5", 0x20, 0xff},
206 {"r6", 0x40, 0xff},
207 {"r7", 0x80, 0xff},
208 {0, 0x00, 0xff}
209 };
210 struct ns32k_option opt3[] = /* setcfg */
211 {
212 {"c", 0x8, 0xff},
213 {"m", 0x4, 0xff},
214 {"f", 0x2, 0xff},
215 {"i", 0x1, 0xff},
216 {0, 0x0, 0xff}
217 };
218 struct ns32k_option opt4[] = /* cinv */
219 {
220 {"a", 0x4, 0xff},
221 {"i", 0x2, 0xff},
222 {"d", 0x1, 0xff},
223 {0, 0x0, 0xff}
224 };
225 struct ns32k_option opt5[] = /* string inst */
226 {
227 {"b", 0x2, 0xff},
228 {"u", 0xc, 0xff},
229 {"w", 0x4, 0xff},
230 {0, 0x0, 0xff}
231 };
232 struct ns32k_option opt6[] = /* plain reg ext,cvtp etc */
233 {
234 {"r0", 0x00, 0xff},
235 {"r1", 0x01, 0xff},
236 {"r2", 0x02, 0xff},
237 {"r3", 0x03, 0xff},
238 {"r4", 0x04, 0xff},
239 {"r5", 0x05, 0xff},
240 {"r6", 0x06, 0xff},
241 {"r7", 0x07, 0xff},
242 {0, 0x00, 0xff}
243 };
244
245 #if !defined(NS32032) && !defined(NS32532)
246 #define NS32532
247 #endif
248
249 struct ns32k_option cpureg_532[] = /* lpr spr */
250 {
251 {"us", 0x0, 0xff},
252 {"dcr", 0x1, 0xff},
253 {"bpc", 0x2, 0xff},
254 {"dsr", 0x3, 0xff},
255 {"car", 0x4, 0xff},
256 {"fp", 0x8, 0xff},
257 {"sp", 0x9, 0xff},
258 {"sb", 0xa, 0xff},
259 {"usp", 0xb, 0xff},
260 {"cfg", 0xc, 0xff},
261 {"psr", 0xd, 0xff},
262 {"intbase", 0xe, 0xff},
263 {"mod", 0xf, 0xff},
264 {0, 0x00, 0xff}
265 };
266 struct ns32k_option mmureg_532[] = /* lmr smr */
267 {
268 {"mcr", 0x9, 0xff},
269 {"msr", 0xa, 0xff},
270 {"tear", 0xb, 0xff},
271 {"ptb0", 0xc, 0xff},
272 {"ptb1", 0xd, 0xff},
273 {"ivar0", 0xe, 0xff},
274 {"ivar1", 0xf, 0xff},
275 {0, 0x0, 0xff}
276 };
277
278 struct ns32k_option cpureg_032[] = /* lpr spr */
279 {
280 {"upsr", 0x0, 0xff},
281 {"fp", 0x8, 0xff},
282 {"sp", 0x9, 0xff},
283 {"sb", 0xa, 0xff},
284 {"psr", 0xd, 0xff},
285 {"intbase", 0xe, 0xff},
286 {"mod", 0xf, 0xff},
287 {0, 0x0, 0xff}
288 };
289 struct ns32k_option mmureg_032[] = /* lmr smr */
290 {
291 {"bpr0", 0x0, 0xff},
292 {"bpr1", 0x1, 0xff},
293 {"pf0", 0x4, 0xff},
294 {"pf1", 0x5, 0xff},
295 {"sc", 0x8, 0xff},
296 {"msr", 0xa, 0xff},
297 {"bcnt", 0xb, 0xff},
298 {"ptb0", 0xc, 0xff},
299 {"ptb1", 0xd, 0xff},
300 {"eia", 0xf, 0xff},
301 {0, 0x0, 0xff}
302 };
303
304 #if defined(NS32532)
305 struct ns32k_option *cpureg = cpureg_532;
306 struct ns32k_option *mmureg = mmureg_532;
307 #else
308 struct ns32k_option *cpureg = cpureg_032;
309 struct ns32k_option *mmureg = mmureg_032;
310 #endif
311 \f
312
313 const pseudo_typeS md_pseudo_table[] =
314 { /* so far empty */
315 {0, 0, 0}
316 };
317
318 #define IND(x,y) (((x)<<2)+(y))
319
320 /* those are index's to relax groups in md_relax_table ie it must be
321 multiplied by 4 to point at a group start. Viz IND(x,y) Se function
322 relax_segment in write.c for more info */
323
324 #define BRANCH 1
325 #define PCREL 2
326
327 /* those are index's to entries in a relax group */
328
329 #define BYTE 0
330 #define WORD 1
331 #define DOUBLE 2
332 #define UNDEF 3
333 /* Those limits are calculated from the displacement start in memory.
334 The ns32k uses the begining of the instruction as displacement
335 base. This type of displacements could be handled here by moving
336 the limit window up or down. I choose to use an internal
337 displacement base-adjust as there are other routines that must
338 consider this. Also, as we have two various offset-adjusts in the
339 ns32k (acb versus br/brs/jsr/bcond), two set of limits would have
340 had to be used. Now we dont have to think about that. */
341
342
343 const relax_typeS md_relax_table[] =
344 {
345 {1, 1, 0, 0},
346 {1, 1, 0, 0},
347 {1, 1, 0, 0},
348 {1, 1, 0, 0},
349
350 {(63), (-64), 1, IND (BRANCH, WORD)},
351 {(8192), (-8192), 2, IND (BRANCH, DOUBLE)},
352 {0, 0, 4, 0},
353 {1, 1, 0, 0}
354 };
355
356 /* Array used to test if mode contains displacements.
357 Value is true if mode contains displacement. */
358
359 char disp_test[] =
360 {0, 0, 0, 0, 0, 0, 0, 0,
361 1, 1, 1, 1, 1, 1, 1, 1,
362 1, 1, 1, 0, 0, 1, 1, 0,
363 1, 1, 1, 1, 1, 1, 1, 1};
364
365 /* Array used to calculate max size of displacements */
366
367 char disp_size[] =
368 {4, 1, 2, 0, 4};
369 \f
370 static void evaluate_expr PARAMS ((expressionS * resultP, char *ptr));
371 static void md_number_to_disp PARAMS ((char *buf, long val, int n));
372 static void md_number_to_imm PARAMS ((char *buf, long val, int n));
373
374 /* Parses a general operand into an addressingmode struct
375
376 in: pointer at operand in ascii form
377 pointer at addr_mode struct for result
378 the level of recursion. (always 0 or 1)
379
380 out: data in addr_mode struct
381 */
382 int
383 addr_mode (operand, addr_modeP, recursive_level)
384 char *operand;
385 register addr_modeS *addr_modeP;
386 int recursive_level;
387 {
388 register char *str;
389 register int i;
390 register int strl;
391 register int mode;
392 int j;
393 mode = DEFAULT; /* default */
394 addr_modeP->scaled_mode = 0; /* why not */
395 addr_modeP->scaled_reg = 0; /* if 0, not scaled index */
396 addr_modeP->float_flag = 0;
397 addr_modeP->am_size = 0;
398 addr_modeP->im_disp = 0;
399 addr_modeP->pcrel = 0; /* not set in this function */
400 addr_modeP->disp_suffix[0] = 0;
401 addr_modeP->disp_suffix[1] = 0;
402 addr_modeP->disp[0] = NULL;
403 addr_modeP->disp[1] = NULL;
404 str = operand;
405 if (str[0] == 0)
406 {
407 return (0);
408 } /* we don't want this */
409 strl = strlen (str);
410 switch (str[0])
411 {
412 /* the following three case statements controls the mode-chars
413 this is the place to ed if you want to change them */
414 #ifdef ABSOLUTE_PREFIX
415 case ABSOLUTE_PREFIX:
416 if (str[strl - 1] == ']')
417 break;
418 addr_modeP->mode = 21; /* absolute */
419 addr_modeP->disp[0] = str + 1;
420 return (-1);
421 #endif
422 #ifdef IMMEDIATE_PREFIX
423 case IMMEDIATE_PREFIX:
424 if (str[strl - 1] == ']')
425 break;
426 addr_modeP->mode = 20; /* immediate */
427 addr_modeP->disp[0] = str + 1;
428 return (-1);
429 #endif
430 case '.':
431 if (str[strl - 1] != ']')
432 {
433 switch (str[1])
434 {
435 case '-':
436 case '+':
437 if (str[2] != '\000')
438 {
439 addr_modeP->mode = 27; /* pc-relativ */
440 addr_modeP->disp[0] = str + 2;
441 return (-1);
442 }
443 default:
444 as_warn (_("Invalid syntax in PC-relative addressing mode"));
445 return (0);
446 }
447 }
448 break;
449 case 'e':
450 if (str[strl - 1] != ']')
451 {
452 if ((!strncmp (str, "ext(", 4)) && strl > 7)
453 { /* external */
454 addr_modeP->disp[0] = str + 4;
455 i = 0;
456 j = 2;
457 do
458 { /* disp[0]'s termination point */
459 j += 1;
460 if (str[j] == '(')
461 i++;
462 if (str[j] == ')')
463 i--;
464 }
465 while (j < strl && i != 0);
466 if (i != 0 || !(str[j + 1] == '-' || str[j + 1] == '+'))
467 {
468 as_warn (_("Invalid syntax in External addressing mode"));
469 return (0);
470 }
471 str[j] = '\000'; /* null terminate disp[0] */
472 addr_modeP->disp[1] = str + j + 2;
473 addr_modeP->mode = 22;
474 return (-1);
475 }
476 }
477 break;
478 default:;
479 }
480 strl = strlen (str);
481 switch (strl)
482 {
483 case 2:
484 switch (str[0])
485 {
486 case 'f':
487 addr_modeP->float_flag = 1;
488 case 'r':
489 if (str[1] >= '0' && str[1] < '8')
490 {
491 addr_modeP->mode = str[1] - '0';
492 return (-1);
493 }
494 }
495 case 3:
496 if (!strncmp (str, "tos", 3))
497 {
498 addr_modeP->mode = 23; /* TopOfStack */
499 return (-1);
500 }
501 default:;
502 }
503 if (strl > 4)
504 {
505 if (str[strl - 1] == ')')
506 {
507 if (str[strl - 2] == ')')
508 {
509 if (!strncmp (&str[strl - 5], "(fp", 3))
510 {
511 mode = 16; /* Memory Relative */
512 }
513 if (!strncmp (&str[strl - 5], "(sp", 3))
514 {
515 mode = 17;
516 }
517 if (!strncmp (&str[strl - 5], "(sb", 3))
518 {
519 mode = 18;
520 }
521 if (mode != DEFAULT)
522 { /* memory relative */
523 addr_modeP->mode = mode;
524 j = strl - 5; /* temp for end of disp[0] */
525 i = 0;
526 do
527 {
528 strl -= 1;
529 if (str[strl] == ')')
530 i++;
531 if (str[strl] == '(')
532 i--;
533 }
534 while (strl > -1 && i != 0);
535 if (i != 0)
536 {
537 as_warn (_("Invalid syntax in Memory Relative addressing mode"));
538 return (0);
539 }
540 addr_modeP->disp[1] = str;
541 addr_modeP->disp[0] = str + strl + 1;
542 str[j] = '\000'; /* null terminate disp[0] */
543 str[strl] = '\000'; /* null terminate disp[1] */
544 return (-1);
545 }
546 }
547 switch (str[strl - 3])
548 {
549 case 'r':
550 case 'R':
551 if (str[strl - 2] >= '0'
552 && str[strl - 2] < '8'
553 && str[strl - 4] == '(')
554 {
555 addr_modeP->mode = str[strl - 2] - '0' + 8;
556 addr_modeP->disp[0] = str;
557 str[strl - 4] = 0;
558 return (-1); /* reg rel */
559 }
560 default:
561 if (!strncmp (&str[strl - 4], "(fp", 3))
562 {
563 mode = 24;
564 }
565 if (!strncmp (&str[strl - 4], "(sp", 3))
566 {
567 mode = 25;
568 }
569 if (!strncmp (&str[strl - 4], "(sb", 3))
570 {
571 mode = 26;
572 }
573 if (!strncmp (&str[strl - 4], "(pc", 3))
574 {
575 mode = 27;
576 }
577 if (mode != DEFAULT)
578 {
579 addr_modeP->mode = mode;
580 addr_modeP->disp[0] = str;
581 str[strl - 4] = '\0';
582 return (-1); /* memory space */
583 }
584 }
585 }
586 /* no trailing ')' do we have a ']' ? */
587 if (str[strl - 1] == ']')
588 {
589 switch (str[strl - 2])
590 {
591 case 'b':
592 mode = 28;
593 break;
594 case 'w':
595 mode = 29;
596 break;
597 case 'd':
598 mode = 30;
599 break;
600 case 'q':
601 mode = 31;
602 break;
603 default:;
604 as_warn (_("Invalid scaled-indexed mode, use (b,w,d,q)"));
605 if (str[strl - 3] != ':' || str[strl - 6] != '['
606 || str[strl - 5] == 'r' || str[strl - 4] < '0'
607 || str[strl - 4] > '7')
608 {
609 as_warn (_("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}"));
610 }
611 } /* scaled index */
612 {
613 if (recursive_level > 0)
614 {
615 as_warn (_("Scaled-indexed addressing mode combined with scaled-index"));
616 return (0);
617 }
618 addr_modeP->am_size += 1; /* scaled index byte */
619 j = str[strl - 4] - '0'; /* store temporary */
620 str[strl - 6] = '\000'; /* nullterminate for recursive call */
621 i = addr_mode (str, addr_modeP, 1);
622 if (!i || addr_modeP->mode == 20)
623 {
624 as_warn (_("Invalid or illegal addressing mode combined with scaled-index"));
625 return (0);
626 }
627 addr_modeP->scaled_mode = addr_modeP->mode; /* store the inferior
628 mode */
629 addr_modeP->mode = mode;
630 addr_modeP->scaled_reg = j + 1;
631 return (-1);
632 }
633 }
634 }
635 addr_modeP->mode = DEFAULT; /* default to whatever */
636 addr_modeP->disp[0] = str;
637 return (-1);
638 }
639 \f
640 /* ptr points at string addr_modeP points at struct with result This
641 routine calls addr_mode to determine the general addr.mode of the
642 operand. When this is ready it parses the displacements for size
643 specifying suffixes and determines size of immediate mode via
644 ns32k-opcode. Also builds index bytes if needed. */
645 int
646 get_addr_mode (ptr, addr_modeP)
647 char *ptr;
648 addr_modeS *addr_modeP;
649 {
650 int tmp;
651 addr_mode (ptr, addr_modeP, 0);
652 if (addr_modeP->mode == DEFAULT || addr_modeP->scaled_mode == -1)
653 {
654 /* resolve ambigious operands, this shouldn't be necessary if
655 one uses standard NSC operand syntax. But the sequent
656 compiler doesn't!!! This finds a proper addressinging mode
657 if it is implicitly stated. See ns32k-opcode.h */
658 (void) evaluate_expr (&exprP, ptr); /* this call takes time Sigh! */
659 if (addr_modeP->mode == DEFAULT)
660 {
661 if (exprP.X_add_symbol || exprP.X_op_symbol)
662 {
663 addr_modeP->mode = desc->default_model; /* we have a label */
664 }
665 else
666 {
667 addr_modeP->mode = desc->default_modec; /* we have a constant */
668 }
669 }
670 else
671 {
672 if (exprP.X_add_symbol || exprP.X_op_symbol)
673 {
674 addr_modeP->scaled_mode = desc->default_model;
675 }
676 else
677 {
678 addr_modeP->scaled_mode = desc->default_modec;
679 }
680 }
681 /* must put this mess down in addr_mode to handle the scaled
682 case better */
683 }
684 /* It appears as the sequent compiler wants an absolute when we have
685 a label without @. Constants becomes immediates besides the addr
686 case. Think it does so with local labels too, not optimum, pcrel
687 is better. When I have time I will make gas check this and
688 select pcrel when possible Actually that is trivial. */
689 if (tmp = addr_modeP->scaled_reg)
690 { /* build indexbyte */
691 tmp--; /* remember regnumber comes incremented for
692 flagpurpose */
693 tmp |= addr_modeP->scaled_mode << 3;
694 addr_modeP->index_byte = (char) tmp;
695 addr_modeP->am_size += 1;
696 }
697 if (disp_test[addr_modeP->mode])
698 { /* there was a displacement, probe for length
699 specifying suffix */
700 {
701 register char c;
702 register char suffix;
703 register char suffix_sub;
704 register int i;
705 register char *toP;
706 register char *fromP;
707
708 addr_modeP->pcrel = 0;
709 if (disp_test[addr_modeP->mode])
710 { /* there is a displacement */
711 if (addr_modeP->mode == 27 || addr_modeP->scaled_mode == 27)
712 { /* do we have pcrel. mode */
713 addr_modeP->pcrel = 1;
714 }
715 addr_modeP->im_disp = 1;
716 for (i = 0; i < 2; i++)
717 {
718 suffix_sub = suffix = 0;
719 if (toP = addr_modeP->disp[i])
720 { /* suffix of expression, the largest size
721 rules */
722 fromP = toP;
723 while (c = *fromP++)
724 {
725 *toP++ = c;
726 if (c == ':')
727 {
728 switch (*fromP)
729 {
730 case '\0':
731 as_warn (_("Premature end of suffix -- Defaulting to d"));
732 suffix = 4;
733 continue;
734 case 'b':
735 suffix_sub = 1;
736 break;
737 case 'w':
738 suffix_sub = 2;
739 break;
740 case 'd':
741 suffix_sub = 4;
742 break;
743 default:
744 as_warn (_("Bad suffix after ':' use {b|w|d} Defaulting to d"));
745 suffix = 4;
746 }
747 fromP++;
748 toP--; /* So we write over the ':' */
749 if (suffix < suffix_sub)
750 suffix = suffix_sub;
751 }
752 }
753 *toP = '\0';/* terminate properly */
754 addr_modeP->disp_suffix[i] = suffix;
755 addr_modeP->am_size += suffix ? suffix : 4;
756 }
757 }
758 }
759 }
760 }
761 else
762 {
763 if (addr_modeP->mode == 20)
764 { /* look in ns32k_opcode for size */
765 addr_modeP->disp_suffix[0] = addr_modeP->am_size = desc->im_size;
766 addr_modeP->im_disp = 0;
767 }
768 }
769 return addr_modeP->mode;
770 }
771
772
773 /* read an optionlist */
774 void
775 optlist (str, optionP, default_map)
776 char *str; /* the string to extract options from */
777 struct ns32k_option *optionP; /* how to search the string */
778 unsigned long *default_map; /* default pattern and output */
779 {
780 register int i, j, k, strlen1, strlen2;
781 register char *patternP, *strP;
782 strlen1 = strlen (str);
783 if (strlen1 < 1)
784 {
785 as_fatal (_("Very short instr to option, ie you can't do it on a NULLstr"));
786 }
787 for (i = 0; optionP[i].pattern != 0; i++)
788 {
789 strlen2 = strlen (optionP[i].pattern);
790 for (j = 0; j < strlen1; j++)
791 {
792 patternP = optionP[i].pattern;
793 strP = &str[j];
794 for (k = 0; k < strlen2; k++)
795 {
796 if (*(strP++) != *(patternP++))
797 break;
798 }
799 if (k == strlen2)
800 { /* match */
801 *default_map |= optionP[i].or;
802 *default_map &= optionP[i].and;
803 }
804 }
805 }
806 }
807
808 /* search struct for symbols
809 This function is used to get the short integer form of reg names in
810 the instructions lmr, smr, lpr, spr return true if str is found in
811 list */
812
813 int
814 list_search (str, optionP, default_map)
815 char *str; /* the string to match */
816 struct ns32k_option *optionP; /* list to search */
817 unsigned long *default_map; /* default pattern and output */
818 {
819 register int i;
820 for (i = 0; optionP[i].pattern != 0; i++)
821 {
822 if (!strncmp (optionP[i].pattern, str, 20))
823 { /* use strncmp to be safe */
824 *default_map |= optionP[i].or;
825 *default_map &= optionP[i].and;
826 return -1;
827 }
828 }
829 as_warn (_("No such entry in list. (cpu/mmu register)"));
830 return 0;
831 }
832
833 static void
834 evaluate_expr (resultP, ptr)
835 expressionS *resultP;
836 char *ptr;
837 {
838 register char *tmp_line;
839
840 tmp_line = input_line_pointer;
841 input_line_pointer = ptr;
842 expression (&exprP);
843 input_line_pointer = tmp_line;
844 }
845 \f
846 /* Convert operands to iif-format and adds bitfields to the opcode.
847 Operands are parsed in such an order that the opcode is updated from
848 its most significant bit, that is when the operand need to alter the
849 opcode.
850 Be carefull not to put to objects in the same iif-slot.
851 */
852
853 void
854 encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
855 int argc;
856 char **argv;
857 char *operandsP;
858 char *suffixP;
859 char im_size;
860 char opcode_bit_ptr;
861 {
862 register int i, j;
863 char d;
864 int pcrel, tmp, b, loop, pcrel_adjust;
865 for (loop = 0; loop < argc; loop++)
866 {
867 i = operandsP[loop << 1] - '1'; /* what operand are we supposed
868 to work on */
869 if (i > 3)
870 as_fatal (_("Internal consistency error. check ns32k-opcode.h"));
871 pcrel = 0;
872 pcrel_adjust = 0;
873 tmp = 0;
874 switch ((d = operandsP[(loop << 1) + 1]))
875 {
876 case 'f': /* operand of sfsr turns out to be a nasty
877 specialcase */
878 opcode_bit_ptr -= 5;
879 case 'Z': /* float not immediate */
880 case 'F': /* 32 bit float general form */
881 case 'L': /* 64 bit float */
882 case 'I': /* integer not immediate */
883 case 'B': /* byte */
884 case 'W': /* word */
885 case 'D': /* double-word */
886 case 'A': /* double-word gen-address-form ie no regs
887 allowed */
888 get_addr_mode (argv[i], &addr_modeP);
889 if((addr_modeP.mode == 20) &&
890 (d == 'I' || d == 'Z' || d == 'A')) {
891 as_fatal(d == 'A'? _("Address of immediate operand"):
892 _("Invalid immediate write operand."));
893 }
894
895 if (opcode_bit_ptr == desc->opcode_size)
896 b = 4;
897 else
898 b = 6;
899 for (j = b; j < (b + 2); j++)
900 {
901 if (addr_modeP.disp[j - b])
902 {
903 IIF (j,
904 2,
905 addr_modeP.disp_suffix[j - b],
906 (unsigned long) addr_modeP.disp[j - b],
907 0,
908 addr_modeP.pcrel,
909 iif.instr_size,
910 addr_modeP.im_disp,
911 IND (BRANCH, BYTE),
912 NULL,
913 (addr_modeP.scaled_reg ? addr_modeP.scaled_mode
914 : addr_modeP.mode),
915 0);
916 }
917 }
918 opcode_bit_ptr -= 5;
919 iif.iifP[1].object |= ((long) addr_modeP.mode) << opcode_bit_ptr;
920 if (addr_modeP.scaled_reg)
921 {
922 j = b / 2;
923 IIF (j, 1, 1, (unsigned long) addr_modeP.index_byte,
924 0, 0, 0, 0, 0, NULL, -1, 0);
925 }
926 break;
927 case 'b': /* multiple instruction disp */
928 freeptr++; /* OVE:this is an useful hack */
929 sprintf (freeptr, "((%s-1)*%d)\000", argv[i], desc->im_size);
930 argv[i] = freeptr;
931 pcrel -= 1; /* make pcrel 0 inspite of what case 'p':
932 wants */
933 /* fall thru */
934 case 'p': /* displacement - pc relative addressing */
935 pcrel += 1;
936 /* fall thru */
937 case 'd': /* displacement */
938 iif.instr_size += suffixP[i] ? suffixP[i] : 4;
939 IIF (12, 2, suffixP[i], (unsigned long) argv[i], 0,
940 pcrel, pcrel_adjust, 1, IND (BRANCH, BYTE), NULL, -1, 0);
941 break;
942 case 'H': /* sequent-hack: the linker wants a bit set
943 when bsr */
944 pcrel = 1;
945 iif.instr_size += suffixP[i] ? suffixP[i] : 4;
946 IIF (12, 2, suffixP[i], (unsigned long) argv[i], 0,
947 pcrel, pcrel_adjust, 1, IND (BRANCH, BYTE), NULL, -1, 1);
948 break;
949 case 'q': /* quick */
950 opcode_bit_ptr -= 4;
951 IIF (11, 2, 42, (unsigned long) argv[i], 0, 0, 0, 0, 0,
952 bit_fix_new (4, opcode_bit_ptr, -8, 7, 0, 1, 0), -1, 0);
953 break;
954 case 'r': /* register number (3 bits) */
955 list_search (argv[i], opt6, &tmp);
956 opcode_bit_ptr -= 3;
957 iif.iifP[1].object |= tmp << opcode_bit_ptr;
958 break;
959 case 'O': /* setcfg instruction optionslist */
960 optlist (argv[i], opt3, &tmp);
961 opcode_bit_ptr -= 4;
962 iif.iifP[1].object |= tmp << 15;
963 break;
964 case 'C': /* cinv instruction optionslist */
965 optlist (argv[i], opt4, &tmp);
966 opcode_bit_ptr -= 4;
967 iif.iifP[1].object |= tmp << 15; /* insert the regtype in opcode */
968 break;
969 case 'S': /* stringinstruction optionslist */
970 optlist (argv[i], opt5, &tmp);
971 opcode_bit_ptr -= 4;
972 iif.iifP[1].object |= tmp << 15;
973 break;
974 case 'u':
975 case 'U': /* registerlist */
976 IIF (10, 1, 1, 0, 0, 0, 0, 0, 0, NULL, -1, 0);
977 switch (operandsP[(i << 1) + 1])
978 {
979 case 'u': /* restore, exit */
980 optlist (argv[i], opt1, &iif.iifP[10].object);
981 break;
982 case 'U': /* save,enter */
983 optlist (argv[i], opt2, &iif.iifP[10].object);
984 break;
985 }
986 iif.instr_size += 1;
987 break;
988 case 'M': /* mmu register */
989 list_search (argv[i], mmureg, &tmp);
990 opcode_bit_ptr -= 4;
991 iif.iifP[1].object |= tmp << opcode_bit_ptr;
992 break;
993 case 'P': /* cpu register */
994 list_search (argv[i], cpureg, &tmp);
995 opcode_bit_ptr -= 4;
996 iif.iifP[1].object |= tmp << opcode_bit_ptr;
997 break;
998 case 'g': /* inss exts */
999 iif.instr_size += 1; /* 1 byte is allocated after the opcode */
1000 IIF (10, 2, 1,
1001 (unsigned long) argv[i], /* i always 2 here */
1002 0, 0, 0, 0, 0,
1003 bit_fix_new (3, 5, 0, 7, 0, 0, 0), /* a bit_fix is targeted to
1004 the byte */
1005 -1, 0);
1006 break;
1007 case 'G':
1008 IIF (11, 2, 42,
1009 (unsigned long) argv[i], /* i always 3 here */
1010 0, 0, 0, 0, 0,
1011 bit_fix_new (5, 0, 1, 32, -1, 0, -1), -1, 0);
1012 break;
1013 case 'i':
1014 iif.instr_size += 1;
1015 b = 2 + i; /* put the extension byte after opcode */
1016 IIF (b, 2, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0);
1017 break;
1018 default:
1019 as_fatal (_("Bad opcode-table-option, check in file ns32k-opcode.h"));
1020 }
1021 }
1022 }
1023 \f
1024 /* in: instruction line
1025 out: internal structure of instruction
1026 that has been prepared for direct conversion to fragment(s) and
1027 fixes in a systematical fashion
1028 Return-value = recursive_level
1029 */
1030 /* build iif of one assembly text line */
1031 int
1032 parse (line, recursive_level)
1033 char *line;
1034 int recursive_level;
1035 {
1036 register char *lineptr, c, suffix_separator;
1037 register int i;
1038 int argc, arg_type;
1039 char sqr, sep;
1040 char suffix[MAX_ARGS], *argv[MAX_ARGS]; /* no more than 4 operands */
1041 if (recursive_level <= 0)
1042 { /* called from md_assemble */
1043 for (lineptr = line; (*lineptr) != '\0' && (*lineptr) != ' '; lineptr++);
1044 c = *lineptr;
1045 *lineptr = '\0';
1046 if (!(desc = (struct ns32k_opcode *) hash_find (inst_hash_handle, line)))
1047 {
1048 as_fatal (_("No such opcode"));
1049 }
1050 *lineptr = c;
1051 }
1052 else
1053 {
1054 lineptr = line;
1055 }
1056 argc = 0;
1057 if (*desc->operands)
1058 {
1059 if (*lineptr++ != '\0')
1060 {
1061 sqr = '[';
1062 sep = ',';
1063 while (*lineptr != '\0')
1064 {
1065 if (desc->operands[argc << 1])
1066 {
1067 suffix[argc] = 0;
1068 arg_type = desc->operands[(argc << 1) + 1];
1069 switch (arg_type)
1070 {
1071 case 'd':
1072 case 'b':
1073 case 'p':
1074 case 'H': /* the operand is supposed to be a
1075 displacement */
1076 /* Hackwarning: do not forget to update the 4
1077 cases above when editing ns32k-opcode.h */
1078 suffix_separator = ':';
1079 break;
1080 default:
1081 suffix_separator = '\255'; /* if this char occurs we
1082 loose */
1083 }
1084 suffix[argc] = 0; /* 0 when no ':' is encountered */
1085 argv[argc] = freeptr;
1086 *freeptr = '\0';
1087 while ((c = *lineptr) != '\0' && c != sep)
1088 {
1089 if (c == sqr)
1090 {
1091 if (sqr == '[')
1092 {
1093 sqr = ']';
1094 sep = '\0';
1095 }
1096 else
1097 {
1098 sqr = '[';
1099 sep = ',';
1100 }
1101 }
1102 if (c == suffix_separator)
1103 { /* ':' - label/suffix separator */
1104 switch (lineptr[1])
1105 {
1106 case 'b':
1107 suffix[argc] = 1;
1108 break;
1109 case 'w':
1110 suffix[argc] = 2;
1111 break;
1112 case 'd':
1113 suffix[argc] = 4;
1114 break;
1115 default:
1116 as_warn (_("Bad suffix, defaulting to d"));
1117 suffix[argc] = 4;
1118 if (lineptr[1] == '\0' || lineptr[1] == sep)
1119 {
1120 lineptr += 1;
1121 continue;
1122 }
1123 }
1124 lineptr += 2;
1125 continue;
1126 }
1127 *freeptr++ = c;
1128 lineptr++;
1129 }
1130 *freeptr++ = '\0';
1131 argc += 1;
1132 if (*lineptr == '\0')
1133 continue;
1134 lineptr += 1;
1135 }
1136 else
1137 {
1138 as_fatal (_("Too many operands passed to instruction"));
1139 }
1140 }
1141 }
1142 }
1143 if (argc != strlen (desc->operands) / 2)
1144 {
1145 if (strlen (desc->default_args))
1146 { /* we can apply default, dont goof */
1147 if (parse (desc->default_args, 1) != 1)
1148 { /* check error in default */
1149 as_fatal (_("Wrong numbers of operands in default, check ns32k-opcodes.h"));
1150 }
1151 }
1152 else
1153 {
1154 as_fatal (_("Wrong number of operands"));
1155 }
1156
1157 }
1158 for (i = 0; i < IIF_ENTRIES; i++)
1159 {
1160 iif.iifP[i].type = 0; /* mark all entries as void*/
1161 }
1162
1163 /* build opcode iif-entry */
1164 iif.instr_size = desc->opcode_size / 8;
1165 IIF (1, 1, iif.instr_size, desc->opcode_seed, 0, 0, 0, 0, 0, 0, -1, 0);
1166
1167 /* this call encodes operands to iif format */
1168 if (argc)
1169 {
1170 encode_operand (argc,
1171 argv,
1172 &desc->operands[0],
1173 &suffix[0],
1174 desc->im_size,
1175 desc->opcode_size);
1176 }
1177 return recursive_level;
1178 }
1179 \f
1180
1181 /* Convert iif to fragments. From this point we start to dribble with
1182 * functions in other files than this one.(Except hash.c) So, if it's
1183 * possible to make an iif for an other CPU, you don't need to know
1184 * what frags, relax, obstacks, etc is in order to port this
1185 * assembler. You only need to know if it's possible to reduce your
1186 * cpu-instruction to iif-format (takes some work) and adopt the other
1187 * md_? parts according to given instructions Note that iif was
1188 * invented for the clean ns32k`s architecure.
1189 */
1190
1191 /* GAS for the ns32k has a problem. PC relative displacements are
1192 * relative to the address of the opcode, not the address of the
1193 * operand. We used to keep track of the offset between the operand
1194 * and the opcode in pcrel_adjust for each frag and each fix. However,
1195 * we get into trouble where there are two or more pc-relative
1196 * operands and the size of the first one can't be determined. Then in
1197 * the relax phase, the size of the first operand will change and
1198 * pcrel_adjust will no longer be correct. The current solution is
1199 * keep a pointer to the frag with the opcode in it and the offset in
1200 * that frag for each frag and each fix. Then, when needed, we can
1201 * always figure out how far it is between the opcode and the pcrel
1202 * object. See also md_pcrel_adjust and md_fix_pcrel_adjust. For
1203 * objects not part of an instruction, the pointer to the opcode frag
1204 * is always zero. */
1205
1206 void
1207 convert_iif ()
1208 {
1209 int i;
1210 bit_fixS *j;
1211 fragS *inst_frag;
1212 unsigned int inst_offset;
1213 char *inst_opcode;
1214 char *memP;
1215 int l;
1216 int k;
1217 char type;
1218 char size = 0;
1219 int size_so_far;
1220
1221 memP = frag_more (0);
1222 inst_opcode = memP;
1223 inst_offset = (memP - frag_now->fr_literal);
1224 inst_frag = frag_now;
1225
1226 for (i = 0; i < IIF_ENTRIES; i++)
1227 {
1228 if (type = iif.iifP[i].type)
1229 { /* the object exist, so handle it */
1230 switch (size = iif.iifP[i].size)
1231 {
1232 case 42:
1233 size = 0; /* it's a bitfix that operates on an existing
1234 object*/
1235 if (iif.iifP[i].bit_fixP->fx_bit_base)
1236 { /* expand fx_bit_base to point at opcode */
1237 iif.iifP[i].bit_fixP->fx_bit_base = (long) inst_opcode;
1238 }
1239 case 8: /* bignum or doublefloat */
1240 case 1:
1241 case 2:
1242 case 3:
1243 case 4: /* the final size in objectmemory is known */
1244 memP = frag_more(size);
1245 j = iif.iifP[i].bit_fixP;
1246 switch (type)
1247 {
1248 case 1: /* the object is pure binary */
1249 if (j || iif.iifP[i].pcrel)
1250 {
1251 fix_new_ns32k (frag_now,
1252 (long) (memP - frag_now->fr_literal),
1253 size,
1254 0,
1255 iif.iifP[i].object,
1256 iif.iifP[i].pcrel,
1257 iif.iifP[i].im_disp,
1258 j,
1259 iif.iifP[i].bsr, /* sequent hack */
1260 inst_frag, inst_offset);
1261 }
1262 else
1263 { /* good, just put them bytes out */
1264 switch (iif.iifP[i].im_disp)
1265 {
1266 case 0:
1267 md_number_to_chars (memP, iif.iifP[i].object, size);
1268 break;
1269 case 1:
1270 md_number_to_disp (memP, iif.iifP[i].object, size);
1271 break;
1272 default:
1273 as_fatal (_("iif convert internal pcrel/binary"));
1274 }
1275 }
1276 break;
1277 case 2:
1278 /* the object is a pointer at an expression, so
1279 unpack it, note that bignums may result from the
1280 expression */
1281 evaluate_expr (&exprP, (char *) iif.iifP[i].object);
1282 if (exprP.X_op == O_big || size == 8)
1283 {
1284 if ((k = exprP.X_add_number) > 0)
1285 {
1286 /* we have a bignum ie a quad. This can only
1287 happens in a long suffixed instruction */
1288 if (k * 2 > size)
1289 as_warn (_("Bignum too big for long"));
1290 if (k == 3)
1291 memP += 2;
1292 for (l = 0; k > 0; k--, l += 2)
1293 {
1294 md_number_to_chars (memP + l,
1295 generic_bignum[l >> 1],
1296 sizeof (LITTLENUM_TYPE));
1297 }
1298 }
1299 else
1300 { /* flonum */
1301 LITTLENUM_TYPE words[4];
1302
1303 switch (size)
1304 {
1305 case 4:
1306 gen_to_words (words, 2, 8);
1307 md_number_to_imm (memP, (long) words[0],
1308 sizeof (LITTLENUM_TYPE));
1309 md_number_to_imm (memP + sizeof (LITTLENUM_TYPE),
1310 (long) words[1],
1311 sizeof (LITTLENUM_TYPE));
1312 break;
1313 case 8:
1314 gen_to_words (words, 4, 11);
1315 md_number_to_imm (memP, (long) words[0],
1316 sizeof (LITTLENUM_TYPE));
1317 md_number_to_imm (memP + sizeof (LITTLENUM_TYPE),
1318 (long) words[1],
1319 sizeof (LITTLENUM_TYPE));
1320 md_number_to_imm ((memP + 2
1321 * sizeof (LITTLENUM_TYPE)),
1322 (long) words[2],
1323 sizeof (LITTLENUM_TYPE));
1324 md_number_to_imm ((memP + 3
1325 * sizeof (LITTLENUM_TYPE)),
1326 (long) words[3],
1327 sizeof (LITTLENUM_TYPE));
1328 break;
1329 }
1330 }
1331 break;
1332 }
1333 if (j ||
1334 exprP.X_add_symbol ||
1335 exprP.X_op_symbol ||
1336 iif.iifP[i].pcrel)
1337 {
1338 /* The expression was undefined due to an
1339 undefined label. Create a fix so we can fix
1340 the object later. */
1341 exprP.X_add_number += iif.iifP[i].object_adjust;
1342 fix_new_ns32k_exp (frag_now,
1343 (long) (memP - frag_now->fr_literal),
1344 size,
1345 &exprP,
1346 iif.iifP[i].pcrel,
1347 iif.iifP[i].im_disp,
1348 j,
1349 iif.iifP[i].bsr,
1350 inst_frag, inst_offset);
1351 }
1352 else
1353 {
1354 /* good, just put them bytes out */
1355 switch (iif.iifP[i].im_disp)
1356 {
1357 case 0:
1358 md_number_to_imm (memP, exprP.X_add_number, size);
1359 break;
1360 case 1:
1361 md_number_to_disp (memP, exprP.X_add_number, size);
1362 break;
1363 default:
1364 as_fatal (_("iif convert internal pcrel/pointer"));
1365 }
1366 }
1367 break;
1368 default:
1369 as_fatal (_("Internal logic error in iif.iifP[n].type"));
1370 }
1371 break;
1372 case 0:
1373 /* To bad, the object may be undefined as far as its
1374 final nsize in object memory is concerned. The size
1375 of the object in objectmemory is not explicitly
1376 given. If the object is defined its length can be
1377 determined and a fix can replace the frag. */
1378 {
1379 evaluate_expr (&exprP, (char *) iif.iifP[i].object);
1380 if ((exprP.X_add_symbol || exprP.X_op_symbol) &&
1381 !iif.iifP[i].pcrel)
1382 {
1383 /* Size is unknown until link time so have to
1384 allow 4 bytes. */
1385 size = 4;
1386 memP = frag_more(size);
1387 fix_new_ns32k_exp (frag_now,
1388 (long) (memP - frag_now->fr_literal),
1389 size,
1390 &exprP,
1391 0, /* never iif.iifP[i].pcrel, */
1392 1, /* always iif.iifP[i].im_disp */
1393 (bit_fixS *) 0, 0,
1394 inst_frag,
1395 inst_offset);
1396 break; /* exit this absolute hack */
1397 }
1398
1399 if (exprP.X_add_symbol || exprP.X_op_symbol)
1400 { /* frag it */
1401 if (exprP.X_op_symbol)
1402 { /* We cant relax this case */
1403 as_fatal (_("Can't relax difference"));
1404 }
1405 else
1406 {
1407
1408 /* Size is not important. This gets fixed by relax,
1409 * but we assume 0 in what follows
1410 */
1411 memP = frag_more(4); /* Max size */
1412 size = 0;
1413
1414 {
1415 fragS *old_frag = frag_now;
1416 frag_variant (rs_machine_dependent,
1417 4, /* Max size */
1418 0, /* size */
1419 IND (BRANCH, UNDEF), /* expecting the worst */
1420 exprP.X_add_symbol,
1421 exprP.X_add_number,
1422 inst_opcode);
1423 frag_opcode_frag(old_frag) = inst_frag;
1424 frag_opcode_offset(old_frag) = inst_offset;
1425 frag_bsr(old_frag) = iif.iifP[i].bsr;
1426 }
1427 }
1428 }
1429 else
1430 {
1431 /* This duplicates code in md_number_to_disp */
1432 if (-64 <= exprP.X_add_number && exprP.X_add_number <= 63)
1433 {
1434 size = 1;
1435 }
1436 else
1437 {
1438 if (-8192 <= exprP.X_add_number
1439 && exprP.X_add_number <= 8191)
1440 {
1441 size = 2;
1442 }
1443 else
1444 {
1445 if (-0x20000000<=exprP.X_add_number &&
1446 exprP.X_add_number<=0x1fffffff)
1447 {
1448 size = 4;
1449 }
1450 else
1451 {
1452 as_warn (_("Displacement to large for :d"));
1453 size = 4;
1454 }
1455 }
1456 }
1457 memP = frag_more(size);
1458 md_number_to_disp (memP, exprP.X_add_number, size);
1459 }
1460 }
1461 break;
1462 default:
1463 as_fatal (_("Internal logic error in iif.iifP[].type"));
1464 }
1465 }
1466 }
1467 }
1468 \f
1469 #ifdef BFD_ASSEMBLER
1470 /* This functionality should really be in the bfd library */
1471 static bfd_reloc_code_real_type
1472 reloc (int size, int pcrel, int type)
1473 {
1474 int length, index;
1475 bfd_reloc_code_real_type relocs[] = {
1476 BFD_RELOC_NS32K_IMM_8,
1477 BFD_RELOC_NS32K_IMM_16,
1478 BFD_RELOC_NS32K_IMM_32,
1479 BFD_RELOC_NS32K_IMM_8_PCREL,
1480 BFD_RELOC_NS32K_IMM_16_PCREL,
1481 BFD_RELOC_NS32K_IMM_32_PCREL,
1482
1483 /* ns32k displacements */
1484 BFD_RELOC_NS32K_DISP_8,
1485 BFD_RELOC_NS32K_DISP_16,
1486 BFD_RELOC_NS32K_DISP_32,
1487 BFD_RELOC_NS32K_DISP_8_PCREL,
1488 BFD_RELOC_NS32K_DISP_16_PCREL,
1489 BFD_RELOC_NS32K_DISP_32_PCREL,
1490
1491 /* Normal 2's complement */
1492 BFD_RELOC_8,
1493 BFD_RELOC_16,
1494 BFD_RELOC_32,
1495 BFD_RELOC_8_PCREL,
1496 BFD_RELOC_16_PCREL,
1497 BFD_RELOC_32_PCREL
1498 };
1499 switch (size)
1500 {
1501 case 1:
1502 length = 0;
1503 break;
1504 case 2:
1505 length = 1;
1506 break;
1507 case 4:
1508 length = 2;
1509 break;
1510 default:
1511 length = -1;
1512 break;
1513 }
1514 index = length + 3 * pcrel + 6 * type;
1515 if (index >= 0 && index < sizeof(relocs)/sizeof(relocs[0]))
1516 return relocs[index];
1517 if (pcrel)
1518 as_bad (_("Can not do %d byte pc-relative relocation for storage type %d"),
1519 size, type);
1520 else
1521 as_bad (_("Can not do %d byte relocation for storage type %d"),
1522 size, type);
1523 return BFD_RELOC_NONE;
1524
1525 }
1526
1527 #endif
1528
1529 void
1530 md_assemble (line)
1531 char *line;
1532 {
1533 freeptr = freeptr_static;
1534 parse (line, 0); /* explode line to more fix form in iif */
1535 convert_iif (); /* convert iif to frags, fix's etc */
1536 #ifdef SHOW_NUM
1537 printf (" \t\t\t%s\n", line);
1538 #endif
1539 }
1540
1541
1542 void
1543 md_begin ()
1544 {
1545 /* build a hashtable of the instructions */
1546 const struct ns32k_opcode *ptr;
1547 const char *stat;
1548 inst_hash_handle = hash_new ();
1549 for (ptr = ns32k_opcodes; ptr < endop; ptr++)
1550 {
1551 if ((stat = hash_insert (inst_hash_handle, ptr->name, (char *) ptr)))
1552 {
1553 as_fatal (_("Can't hash %s: %s"), ptr->name, stat); /*fatal*/
1554 }
1555 }
1556 freeptr_static = (char *) malloc (PRIVATE_SIZE); /* some private space
1557 please! */
1558 }
1559
1560 /* Must be equal to MAX_PRECISON in atof-ieee.c */
1561 #define MAX_LITTLENUMS 6
1562
1563 /* Turn the string pointed to by litP into a floating point constant
1564 of type TYPE, and emit the appropriate bytes. The number of
1565 LITTLENUMS emitted is stored in *SIZEP. An error message is
1566 returned, or NULL on OK. */
1567
1568 char *
1569 md_atof (type, litP, sizeP)
1570 char type;
1571 char *litP;
1572 int *sizeP;
1573 {
1574 int prec;
1575 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1576 LITTLENUM_TYPE *wordP;
1577 char *t;
1578
1579 switch (type)
1580 {
1581 case 'f':
1582 prec = 2;
1583 break;
1584
1585 case 'd':
1586 prec = 4;
1587 break;
1588 default:
1589 *sizeP = 0;
1590 return _("Bad call to MD_ATOF()");
1591 }
1592 t = atof_ieee (input_line_pointer, type, words);
1593 if (t)
1594 input_line_pointer = t;
1595
1596 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1597 for (wordP = words + prec; prec--;)
1598 {
1599 md_number_to_chars (litP, (long) (*--wordP), sizeof (LITTLENUM_TYPE));
1600 litP += sizeof (LITTLENUM_TYPE);
1601 }
1602 return 0;
1603 }
1604 \f
1605 /* Convert number to chars in correct order */
1606
1607 void
1608 md_number_to_chars (buf, value, nbytes)
1609 char *buf;
1610 valueT value;
1611 int nbytes;
1612 {
1613 number_to_chars_littleendian (buf, value, nbytes);
1614 }
1615
1616
1617 /* This is a variant of md_numbers_to_chars. The reason for its'
1618 existence is the fact that ns32k uses Huffman coded
1619 displacements. This implies that the bit order is reversed in
1620 displacements and that they are prefixed with a size-tag.
1621
1622 binary: msb -> lsb
1623 0xxxxxxx byte
1624 10xxxxxx xxxxxxxx word
1625 11xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx double word
1626
1627 This must be taken care of and we do it here! */
1628 static void
1629 md_number_to_disp (buf, val, n)
1630 char *buf;
1631 long val;
1632 char n;
1633 {
1634 switch (n)
1635 {
1636 case 1:
1637 if (val < -64 || val > 63)
1638 as_warn (_("Byte displacement out of range. line number not valid"));
1639 val &= 0x7f;
1640 #ifdef SHOW_NUM
1641 printf ("%x ", val & 0xff);
1642 #endif
1643 *buf++ = val;
1644 break;
1645 case 2:
1646 if (val < -8192 || val > 8191)
1647 as_warn (_("Word displacement out of range. line number not valid"));
1648 val &= 0x3fff;
1649 val |= 0x8000;
1650 #ifdef SHOW_NUM
1651 printf ("%x ", val >> 8 & 0xff);
1652 #endif
1653 *buf++ = (val >> 8);
1654 #ifdef SHOW_NUM
1655 printf ("%x ", val & 0xff);
1656 #endif
1657 *buf++ = val;
1658 break;
1659 case 4:
1660 if (val < -0x20000000 || val >= 0x20000000)
1661 as_warn (_("Double word displacement out of range"));
1662 val |= 0xc0000000;
1663 #ifdef SHOW_NUM
1664 printf ("%x ", val >> 24 & 0xff);
1665 #endif
1666 *buf++ = (val >> 24);
1667 #ifdef SHOW_NUM
1668 printf ("%x ", val >> 16 & 0xff);
1669 #endif
1670 *buf++ = (val >> 16);
1671 #ifdef SHOW_NUM
1672 printf ("%x ", val >> 8 & 0xff);
1673 #endif
1674 *buf++ = (val >> 8);
1675 #ifdef SHOW_NUM
1676 printf ("%x ", val & 0xff);
1677 #endif
1678 *buf++ = val;
1679 break;
1680 default:
1681 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1682 __LINE__, __FILE__);
1683 }
1684 }
1685
1686 static void
1687 md_number_to_imm (buf, val, n)
1688 char *buf;
1689 long val;
1690 char n;
1691 {
1692 switch (n)
1693 {
1694 case 1:
1695 #ifdef SHOW_NUM
1696 printf ("%x ", val & 0xff);
1697 #endif
1698 *buf++ = val;
1699 break;
1700 case 2:
1701 #ifdef SHOW_NUM
1702 printf ("%x ", val >> 8 & 0xff);
1703 #endif
1704 *buf++ = (val >> 8);
1705 #ifdef SHOW_NUM
1706 printf ("%x ", val & 0xff);
1707 #endif
1708 *buf++ = val;
1709 break;
1710 case 4:
1711 #ifdef SHOW_NUM
1712 printf ("%x ", val >> 24 & 0xff);
1713 #endif
1714 *buf++ = (val >> 24);
1715 #ifdef SHOW_NUM
1716 printf ("%x ", val >> 16 & 0xff);
1717 #endif
1718 *buf++ = (val >> 16);
1719 #ifdef SHOW_NUM
1720 printf ("%x ", val >> 8 & 0xff);
1721 #endif
1722 *buf++ = (val >> 8);
1723 #ifdef SHOW_NUM
1724 printf ("%x ", val & 0xff);
1725 #endif
1726 *buf++ = val;
1727 break;
1728 default:
1729 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1730 __LINE__, __FILE__);
1731 }
1732 }
1733
1734
1735 /* fast bitfiddling support */
1736 /* mask used to zero bitfield before oring in the true field */
1737
1738 static unsigned long l_mask[] =
1739 {
1740 0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
1741 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
1742 0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
1743 0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
1744 0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
1745 0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
1746 0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
1747 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
1748 };
1749 static unsigned long r_mask[] =
1750 {
1751 0x00000000, 0x00000001, 0x00000003, 0x00000007,
1752 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
1753 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
1754 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
1755 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
1756 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
1757 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
1758 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
1759 };
1760 #define MASK_BITS 31
1761 /* Insert bitfield described by field_ptr and val at buf
1762 This routine is written for modification of the first 4 bytes pointed
1763 to by buf, to yield speed.
1764 The ifdef stuff is for selection between a ns32k-dependent routine
1765 and a general version. (My advice: use the general version!)
1766 */
1767
1768 static void
1769 md_number_to_field (buf, val, field_ptr)
1770 register char *buf;
1771 register long val;
1772 register bit_fixS *field_ptr;
1773 {
1774 register unsigned long object;
1775 register unsigned long mask;
1776 /* define ENDIAN on a ns32k machine */
1777 #ifdef ENDIAN
1778 register unsigned long *mem_ptr;
1779 #else
1780 register char *mem_ptr;
1781 #endif
1782 if (field_ptr->fx_bit_min <= val && val <= field_ptr->fx_bit_max)
1783 {
1784 #ifdef ENDIAN
1785 if (field_ptr->fx_bit_base)
1786 { /* override buf */
1787 mem_ptr = (unsigned long *) field_ptr->fx_bit_base;
1788 }
1789 else
1790 {
1791 mem_ptr = (unsigned long *) buf;
1792 }
1793 mem_ptr = ((unsigned long *)
1794 ((char *) mem_ptr + field_ptr->fx_bit_base_adj));
1795 #else
1796 if (field_ptr->fx_bit_base)
1797 { /* override buf */
1798 mem_ptr = (char *) field_ptr->fx_bit_base;
1799 }
1800 else
1801 {
1802 mem_ptr = buf;
1803 }
1804 mem_ptr += field_ptr->fx_bit_base_adj;
1805 #endif
1806 #ifdef ENDIAN /* we have a nice ns32k machine with lowbyte
1807 at low-physical mem */
1808 object = *mem_ptr; /* get some bytes */
1809 #else /* OVE Goof! the machine is a m68k or dito */
1810 /* That takes more byte fiddling */
1811 object = 0;
1812 object |= mem_ptr[3] & 0xff;
1813 object <<= 8;
1814 object |= mem_ptr[2] & 0xff;
1815 object <<= 8;
1816 object |= mem_ptr[1] & 0xff;
1817 object <<= 8;
1818 object |= mem_ptr[0] & 0xff;
1819 #endif
1820 mask = 0;
1821 mask |= (r_mask[field_ptr->fx_bit_offset]);
1822 mask |= (l_mask[field_ptr->fx_bit_offset + field_ptr->fx_bit_size]);
1823 object &= mask;
1824 val += field_ptr->fx_bit_add;
1825 object |= ((val << field_ptr->fx_bit_offset) & (mask ^ 0xffffffff));
1826 #ifdef ENDIAN
1827 *mem_ptr = object;
1828 #else
1829 mem_ptr[0] = (char) object;
1830 object >>= 8;
1831 mem_ptr[1] = (char) object;
1832 object >>= 8;
1833 mem_ptr[2] = (char) object;
1834 object >>= 8;
1835 mem_ptr[3] = (char) object;
1836 #endif
1837 }
1838 else
1839 {
1840 as_warn (_("Bit field out of range"));
1841 }
1842 }
1843
1844 int md_pcrel_adjust (fragS *fragP)
1845 {
1846 fragS *opcode_frag;
1847 addressT opcode_address;
1848 unsigned int offset;
1849 opcode_frag = frag_opcode_frag(fragP);
1850 if (opcode_frag == 0)
1851 return 0;
1852 offset = frag_opcode_offset(fragP);
1853 opcode_address = offset + opcode_frag->fr_address;
1854 return fragP->fr_address + fragP->fr_fix - opcode_address;
1855 }
1856
1857 int md_fix_pcrel_adjust (fixS *fixP)
1858 {
1859 fragS *fragP = fixP->fx_frag;
1860 fragS *opcode_frag;
1861 addressT opcode_address;
1862 unsigned int offset;
1863 opcode_frag = fix_opcode_frag(fixP);
1864 if (opcode_frag == 0)
1865 return 0;
1866 offset = fix_opcode_offset(fixP);
1867 opcode_address = offset + opcode_frag->fr_address;
1868 return fixP->fx_where + fixP->fx_frag->fr_address - opcode_address;
1869 }
1870
1871 /* Apply a fixS (fixup of an instruction or data that we didn't have
1872 enough info to complete immediately) to the data in a frag.
1873
1874 On the ns32k, everything is in a different format, so we have broken
1875 out separate functions for each kind of thing we could be fixing.
1876 They all get called from here. */
1877
1878 #ifdef BFD_ASSEMBLER
1879 int
1880 md_apply_fix (fixP, valp)
1881 fixS *fixP;
1882 valueT *valp;
1883 #else
1884 void
1885 md_apply_fix (fixP, val)
1886 fixS *fixP;
1887 long val;
1888 #endif
1889 {
1890 #ifdef BFD_ASSEMBLER
1891 long val = *valp;
1892 #endif
1893 fragS *fragP = fixP->fx_frag;
1894
1895 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1896
1897 if (fix_bit_fixP(fixP))
1898 { /* Bitfields to fix, sigh */
1899 md_number_to_field (buf, val, fix_bit_fixP(fixP));
1900 }
1901 else
1902 switch (fix_im_disp(fixP))
1903 {
1904
1905 case 0: /* Immediate field */
1906 md_number_to_imm (buf, val, fixP->fx_size);
1907 break;
1908
1909 case 1: /* Displacement field */
1910 /* Calculate offset */
1911 {
1912 md_number_to_disp (buf,
1913 (fixP->fx_pcrel ? val + md_fix_pcrel_adjust(fixP)
1914 : val), fixP->fx_size);
1915 }
1916 break;
1917
1918 case 2: /* Pointer in a data object */
1919 md_number_to_chars (buf, val, fixP->fx_size);
1920 break;
1921 }
1922 #ifdef BSD_ASSEMBLER
1923 return 1;
1924 #endif
1925 }
1926 \f
1927 /* Convert a relaxed displacement to ditto in final output */
1928
1929 #ifndef BFD_ASSEMBLER
1930 void
1931 md_convert_frag (headers, sec, fragP)
1932 object_headers *headers;
1933 segT sec;
1934 register fragS *fragP;
1935 #else
1936 void
1937 md_convert_frag (abfd, sec, fragP)
1938 bfd *abfd;
1939 segT sec;
1940 register fragS *fragP;
1941 #endif
1942 {
1943 long disp;
1944 long ext = 0;
1945
1946 /* Address in gas core of the place to store the displacement. */
1947 register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
1948 /* Address in object code of the displacement. */
1949 int object_address;
1950
1951 fragS *opcode_frag;
1952
1953 switch (fragP->fr_subtype)
1954 {
1955 case IND (BRANCH, BYTE):
1956 ext = 1;
1957 break;
1958 case IND (BRANCH, WORD):
1959 ext = 2;
1960 break;
1961 case IND (BRANCH, DOUBLE):
1962 ext = 4;
1963 break;
1964 }
1965
1966 if(ext == 0)
1967 return;
1968
1969 know (fragP->fr_symbol);
1970
1971 object_address = fragP->fr_fix + fragP->fr_address;
1972 /* The displacement of the address, from current location. */
1973 disp = (S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset) - object_address;
1974 #ifdef BFD_ASSEMBLER
1975 disp += symbol_get_frag (fragP->fr_symbol)->fr_address;
1976 #endif
1977 disp += md_pcrel_adjust(fragP);
1978
1979 md_number_to_disp (buffer_address, (long) disp, (int) ext);
1980 fragP->fr_fix += ext;
1981 }
1982
1983 /* This function returns the estimated size a variable object will occupy,
1984 one can say that we tries to guess the size of the objects before we
1985 actually know it */
1986
1987 int
1988 md_estimate_size_before_relax (fragP, segment)
1989 register fragS *fragP;
1990 segT segment;
1991 {
1992 int old_fix;
1993 old_fix = fragP->fr_fix;
1994 switch (fragP->fr_subtype)
1995 {
1996 case IND (BRANCH, UNDEF):
1997 if (S_GET_SEGMENT (fragP->fr_symbol) == segment)
1998 {
1999 /* the symbol has been assigned a value */
2000 fragP->fr_subtype = IND (BRANCH, BYTE);
2001 }
2002 else
2003 {
2004 /* we don't relax symbols defined in an other segment the
2005 thing to do is to assume the object will occupy 4 bytes */
2006 fix_new_ns32k (fragP,
2007 (int) (fragP->fr_fix),
2008 4,
2009 fragP->fr_symbol,
2010 fragP->fr_offset,
2011 1,
2012 1,
2013 0,
2014 frag_bsr(fragP), /*sequent hack */
2015 frag_opcode_frag(fragP),
2016 frag_opcode_offset(fragP));
2017 fragP->fr_fix += 4;
2018 /* fragP->fr_opcode[1]=0xff; */
2019 frag_wane (fragP);
2020 break;
2021 }
2022 case IND (BRANCH, BYTE):
2023 fragP->fr_var += 1;
2024 break;
2025 default:
2026 break;
2027 }
2028 return fragP->fr_var + fragP->fr_fix - old_fix;
2029 }
2030
2031 int md_short_jump_size = 3;
2032 int md_long_jump_size = 5;
2033 const int md_reloc_size = 8; /* Size of relocation record */
2034
2035 void
2036 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2037 char *ptr;
2038 addressT from_addr, to_addr;
2039 fragS *frag;
2040 symbolS *to_symbol;
2041 {
2042 valueT offset;
2043
2044 offset = to_addr - from_addr;
2045 md_number_to_chars (ptr, (valueT) 0xEA, 1);
2046 md_number_to_disp (ptr + 1, (valueT) offset, 2);
2047 }
2048
2049 void
2050 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2051 char *ptr;
2052 addressT from_addr, to_addr;
2053 fragS *frag;
2054 symbolS *to_symbol;
2055 {
2056 valueT offset;
2057
2058 offset = to_addr - from_addr;
2059 md_number_to_chars (ptr, (valueT) 0xEA, 1);
2060 md_number_to_disp (ptr + 1, (valueT) offset, 4);
2061 }
2062 \f
2063 CONST char *md_shortopts = "m:";
2064 struct option md_longopts[] = {
2065 {NULL, no_argument, NULL, 0}
2066 };
2067 size_t md_longopts_size = sizeof(md_longopts);
2068
2069 int
2070 md_parse_option (c, arg)
2071 int c;
2072 char *arg;
2073 {
2074 switch (c)
2075 {
2076 case 'm':
2077 if (!strcmp (arg, "32032"))
2078 {
2079 cpureg = cpureg_032;
2080 mmureg = mmureg_032;
2081 }
2082 else if (!strcmp (arg, "32532"))
2083 {
2084 cpureg = cpureg_532;
2085 mmureg = mmureg_532;
2086 }
2087 else
2088 {
2089 as_bad (_("invalid architecture option -m%s"), arg);
2090 return 0;
2091 }
2092 break;
2093
2094 default:
2095 return 0;
2096 }
2097
2098 return 1;
2099 }
2100
2101 void
2102 md_show_usage (stream)
2103 FILE *stream;
2104 {
2105 fprintf(stream, _("\
2106 NS32K options:\n\
2107 -m32032 | -m32532 select variant of NS32K architecture\n"));
2108 }
2109
2110 \f
2111 /*
2112 * bit_fix_new()
2113 *
2114 * Create a bit_fixS in obstack 'notes'.
2115 * This struct is used to profile the normal fix. If the bit_fixP is a
2116 * valid pointer (not NULL) the bit_fix data will be used to format the fix.
2117 */
2118 bit_fixS *
2119 bit_fix_new (size, offset, min, max, add, base_type, base_adj)
2120 char size; /* Length of bitfield */
2121 char offset; /* Bit offset to bitfield */
2122 long min; /* Signextended min for bitfield */
2123 long max; /* Signextended max for bitfield */
2124 long add; /* Add mask, used for huffman prefix */
2125 long base_type; /* 0 or 1, if 1 it's exploded to opcode ptr */
2126 long base_adj;
2127 {
2128 register bit_fixS *bit_fixP;
2129
2130 bit_fixP = (bit_fixS *) obstack_alloc (&notes, sizeof (bit_fixS));
2131
2132 bit_fixP->fx_bit_size = size;
2133 bit_fixP->fx_bit_offset = offset;
2134 bit_fixP->fx_bit_base = base_type;
2135 bit_fixP->fx_bit_base_adj = base_adj;
2136 bit_fixP->fx_bit_max = max;
2137 bit_fixP->fx_bit_min = min;
2138 bit_fixP->fx_bit_add = add;
2139
2140 return (bit_fixP);
2141 }
2142
2143 void
2144 fix_new_ns32k (frag, where, size, add_symbol, offset, pcrel,
2145 im_disp, bit_fixP, bsr, opcode_frag, opcode_offset)
2146 fragS *frag; /* Which frag? */
2147 int where; /* Where in that frag? */
2148 int size; /* 1, 2 or 4 usually. */
2149 symbolS *add_symbol; /* X_add_symbol. */
2150 long offset; /* X_add_number. */
2151 int pcrel; /* TRUE if PC-relative relocation. */
2152 char im_disp; /* true if the value to write is a
2153 displacement */
2154 bit_fixS *bit_fixP; /* pointer at struct of bit_fix's, ignored if
2155 NULL */
2156 char bsr; /* sequent-linker-hack: 1 when relocobject is
2157 a bsr */
2158 fragS *opcode_frag;
2159 unsigned int opcode_offset;
2160
2161 {
2162 fixS *fixP = fix_new (frag, where, size, add_symbol,
2163 offset, pcrel,
2164 #ifdef BFD_ASSEMBLER
2165 bit_fixP? NO_RELOC: reloc(size, pcrel, im_disp)
2166 #else
2167 NO_RELOC
2168 #endif
2169 );
2170
2171 fix_opcode_frag(fixP) = opcode_frag;
2172 fix_opcode_offset(fixP) = opcode_offset;
2173 fix_im_disp(fixP) = im_disp;
2174 fix_bsr(fixP) = bsr;
2175 fix_bit_fixP(fixP) = bit_fixP;
2176 } /* fix_new_ns32k() */
2177
2178 void
2179 fix_new_ns32k_exp (frag, where, size, exp, pcrel,
2180 im_disp, bit_fixP, bsr, opcode_frag, opcode_offset)
2181 fragS *frag; /* Which frag? */
2182 int where; /* Where in that frag? */
2183 int size; /* 1, 2 or 4 usually. */
2184 expressionS *exp; /* Expression. */
2185 int pcrel; /* TRUE if PC-relative relocation. */
2186 char im_disp; /* true if the value to write is a
2187 displacement */
2188 bit_fixS *bit_fixP; /* pointer at struct of bit_fix's, ignored if
2189 NULL */
2190 char bsr; /* sequent-linker-hack: 1 when relocobject is
2191 a bsr */
2192 fragS *opcode_frag;
2193 unsigned int opcode_offset;
2194 {
2195 fixS *fixP = fix_new_exp (frag, where, size, exp, pcrel,
2196 #ifdef BFD_ASSEMBLER
2197 bit_fixP? NO_RELOC: reloc(size, pcrel, im_disp)
2198 #else
2199 NO_RELOC
2200 #endif
2201 );
2202
2203 fix_opcode_frag(fixP) = opcode_frag;
2204 fix_opcode_offset(fixP) = opcode_offset;
2205 fix_im_disp(fixP) = im_disp;
2206 fix_bsr(fixP) = bsr;
2207 fix_bit_fixP(fixP) = bit_fixP;
2208 } /* fix_new_ns32k() */
2209
2210 /* This is TC_CONS_FIX_NEW, called by emit_expr in read.c. */
2211
2212 void
2213 cons_fix_new_ns32k (frag, where, size, exp)
2214 fragS *frag; /* Which frag? */
2215 int where; /* Where in that frag? */
2216 int size; /* 1, 2 or 4 usually. */
2217 expressionS *exp; /* Expression. */
2218 {
2219 fix_new_ns32k_exp (frag, where, size, exp,
2220 0, 2, 0, 0, 0, 0);
2221 }
2222
2223 /* We have no need to default values of symbols. */
2224
2225 symbolS *
2226 md_undefined_symbol (name)
2227 char *name;
2228 {
2229 return 0;
2230 }
2231
2232 /* Round up a section size to the appropriate boundary. */
2233 valueT
2234 md_section_align (segment, size)
2235 segT segment;
2236 valueT size;
2237 {
2238 return size; /* Byte alignment is fine */
2239 }
2240
2241 /* Exactly what point is a PC-relative offset relative TO? On the
2242 ns32k, they're relative to the start of the instruction. */
2243 long
2244 md_pcrel_from (fixP)
2245 fixS *fixP;
2246 {
2247 long res;
2248 res = fixP->fx_where + fixP->fx_frag->fr_address;
2249 #ifdef SEQUENT_COMPATABILITY
2250 if (frag_bsr(fixP->fx_frag))
2251 res += 0x12 /* FOO Kludge alert! */
2252 #endif
2253 return res;
2254 }
2255
2256 #ifdef BFD_ASSEMBLER
2257
2258 arelent *
2259 tc_gen_reloc (section, fixp)
2260 asection *section;
2261 fixS *fixp;
2262 {
2263 arelent *rel;
2264 bfd_reloc_code_real_type code;
2265
2266 code = reloc(fixp->fx_size, fixp->fx_pcrel, fix_im_disp(fixp));
2267
2268 rel = (arelent *) xmalloc (sizeof (arelent));
2269 rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2270 *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2271 rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
2272 if (fixp->fx_pcrel)
2273 rel->addend = fixp->fx_addnumber;
2274 else
2275 rel->addend = 0;
2276
2277 rel->howto = bfd_reloc_type_lookup (stdoutput, code);
2278 if (!rel->howto)
2279 {
2280 const char *name;
2281
2282 name = S_GET_NAME (fixp->fx_addsy);
2283 if (name == NULL)
2284 name = _("<unknown>");
2285 as_fatal (_("Cannot find relocation type for symbol %s, code %d"),
2286 name, (int) code);
2287 }
2288
2289 return rel;
2290 }
2291 #else /* BFD_ASSEMBLER */
2292
2293 #ifdef OBJ_AOUT
2294 void
2295 cons_fix_new_ns32k (where, fixP, segment_address_in_file)
2296 char *where;
2297 struct fix *fixP;
2298 relax_addressT segment_address_in_file;
2299 {
2300 /*
2301 * In: length of relocation (or of address) in chars: 1, 2 or 4.
2302 * Out: GNU LD relocation length code: 0, 1, or 2.
2303 */
2304
2305 static unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
2306 long r_symbolnum;
2307
2308 know (fixP->fx_addsy != NULL);
2309
2310 md_number_to_chars (where,
2311 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
2312 4);
2313
2314 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
2315 ? S_GET_TYPE (fixP->fx_addsy)
2316 : fixP->fx_addsy->sy_number);
2317
2318 md_number_to_chars (where + 4,
2319 ((long) (r_symbolnum)
2320 | (long) (fixP->fx_pcrel << 24)
2321 | (long) (nbytes_r_length[fixP->fx_size] << 25)
2322 | (long) ((!S_IS_DEFINED (fixP->fx_addsy)) << 27)
2323 | (long) (fix_bsr(fixP) << 28)
2324 | (long) (fix_im_disp(fixP) << 29)),
2325 4);
2326 }
2327
2328 #endif /* OBJ_AOUT */
2329 #endif /* BFD_ASSMEBLER */
2330
2331 /* end of tc-ns32k.c */
This page took 0.077799 seconds and 4 git commands to generate.