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