1 1.1 christos /* tc-s390.c -- Assemble for the S390 2 1.10 christos Copyright (C) 2000-2025 Free Software Foundation, Inc. 3 1.1 christos Contributed by Martin Schwidefsky (schwidefsky (at) de.ibm.com). 4 1.1 christos 5 1.1 christos This file is part of GAS, the GNU Assembler. 6 1.1 christos 7 1.1 christos GAS is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3, or (at your option) 10 1.1 christos any later version. 11 1.1 christos 12 1.1 christos GAS is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with GAS; see the file COPYING. If not, write to the Free 19 1.1 christos Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 20 1.1 christos 02110-1301, USA. */ 21 1.1 christos 22 1.1 christos #include "as.h" 23 1.1 christos #include "safe-ctype.h" 24 1.1 christos #include "subsegs.h" 25 1.1 christos #include "dwarf2dbg.h" 26 1.1 christos #include "dw2gencfi.h" 27 1.10 christos #include "sframe.h" 28 1.10 christos #include "gen-sframe.h" 29 1.1 christos 30 1.1 christos #include "opcode/s390.h" 31 1.1 christos #include "elf/s390.h" 32 1.1 christos 33 1.1 christos /* The default architecture. */ 34 1.1 christos #ifndef DEFAULT_ARCH 35 1.1 christos #define DEFAULT_ARCH "s390" 36 1.1 christos #endif 37 1.5 christos static const char *default_arch = DEFAULT_ARCH; 38 1.1 christos /* Either 32 or 64, selects file format. */ 39 1.1 christos static int s390_arch_size = 0; 40 1.1 christos 41 1.1 christos /* If no -march option was given default to the highest available CPU. 42 1.1 christos Since with S/390 a newer CPU always supports everything from its 43 1.1 christos predecessors this will accept every valid asm input. */ 44 1.1 christos static unsigned int current_cpu = S390_OPCODE_MAXCPU - 1; 45 1.6 christos /* All facilities are enabled by default. */ 46 1.6 christos static unsigned int current_flags = S390_INSTR_FLAG_FACILITY_MASK; 47 1.6 christos /* The mode mask default is picked in init_default_arch depending on 48 1.6 christos the current cpu. */ 49 1.1 christos static unsigned int current_mode_mask = 0; 50 1.3 christos 51 1.3 christos /* Set to TRUE if the highgprs flag in the ELF header needs to be set 52 1.10 christos for the output file. The default is picked in init_default_arch(). */ 53 1.8 christos static bool set_highgprs_p = false; 54 1.1 christos 55 1.1 christos /* Whether to use user friendly register names. Default is TRUE. */ 56 1.1 christos #ifndef TARGET_REG_NAMES_P 57 1.8 christos #define TARGET_REG_NAMES_P true 58 1.1 christos #endif 59 1.1 christos 60 1.8 christos static bool reg_names_p = TARGET_REG_NAMES_P; 61 1.1 christos 62 1.1 christos /* Set to TRUE if we want to warn about zero base/index registers. */ 63 1.8 christos static bool warn_areg_zero = false; 64 1.1 christos 65 1.10 christos /* Whether to warn about register name type check mismatches. */ 66 1.10 christos #ifndef S390_REGTYPE_CHECK 67 1.10 christos #define S390_REGTYPE_CHECK S390_REGTYPE_CHECK_RELAXED 68 1.10 christos #endif 69 1.10 christos 70 1.10 christos enum s390_regtype_check { 71 1.10 christos S390_REGTYPE_CHECK_NONE = 0, /* No register name type checks. */ 72 1.10 christos S390_REGTYPE_CHECK_RELAXED, /* Relaxed register name type checks. */ 73 1.10 christos S390_REGTYPE_CHECK_STRICT /* Strict register name type checks. */ 74 1.10 christos }; 75 1.10 christos 76 1.10 christos /* Whether to warn about register name type check mismatches. */ 77 1.10 christos static enum s390_regtype_check warn_regtype_mismatch = S390_REGTYPE_CHECK; 78 1.10 christos 79 1.1 christos /* Generic assembler global variables which must be defined by all 80 1.1 christos targets. */ 81 1.1 christos 82 1.1 christos const char comment_chars[] = "#"; 83 1.1 christos 84 1.1 christos /* Characters which start a comment at the beginning of a line. */ 85 1.1 christos const char line_comment_chars[] = "#"; 86 1.1 christos 87 1.1 christos /* Characters which may be used to separate multiple commands on a 88 1.1 christos single line. */ 89 1.1 christos const char line_separator_chars[] = ";"; 90 1.1 christos 91 1.1 christos /* Characters which are used to indicate an exponent in a floating 92 1.1 christos point number. */ 93 1.1 christos const char EXP_CHARS[] = "eE"; 94 1.1 christos 95 1.1 christos /* Characters which mean that a number is a floating point constant, 96 1.1 christos as in 0d1.0. */ 97 1.1 christos const char FLT_CHARS[] = "dD"; 98 1.1 christos 99 1.1 christos /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */ 100 1.1 christos int s390_cie_data_alignment; 101 1.1 christos 102 1.10 christos /* Register numbers used for SFrame stack trace info. */ 103 1.10 christos 104 1.10 christos /* Designated stack pointer DWARF register number according to s390x ELF ABI. */ 105 1.10 christos const unsigned int s390_sframe_cfa_sp_reg = 15; 106 1.10 christos 107 1.10 christos /* Preferred frame pointer DWARF register number according to s390x ELF ABI. */ 108 1.10 christos const unsigned int s390_sframe_cfa_fp_reg = 11; 109 1.10 christos 110 1.10 christos /* Designated return address DWARF register number according to s390x ELF ABI. */ 111 1.10 christos const unsigned int s390_sframe_cfa_ra_reg = DWARF2_DEFAULT_RETURN_COLUMN; 112 1.10 christos 113 1.1 christos /* The target specific pseudo-ops which we support. */ 114 1.1 christos 115 1.1 christos /* Define the prototypes for the pseudo-ops */ 116 1.1 christos static void s390_byte (int); 117 1.1 christos static void s390_elf_cons (int); 118 1.1 christos static void s390_insn (int); 119 1.1 christos static void s390_literals (int); 120 1.1 christos static void s390_machine (int); 121 1.3 christos static void s390_machinemode (int); 122 1.1 christos 123 1.1 christos const pseudo_typeS md_pseudo_table[] = 124 1.1 christos { 125 1.3 christos { "align", s_align_bytes, 0 }, 126 1.1 christos /* Pseudo-ops which must be defined. */ 127 1.3 christos { "insn", s390_insn, 0 }, 128 1.1 christos /* Pseudo-ops which must be overridden. */ 129 1.3 christos { "byte", s390_byte, 0 }, 130 1.3 christos { "short", s390_elf_cons, 2 }, 131 1.3 christos { "long", s390_elf_cons, 4 }, 132 1.3 christos { "quad", s390_elf_cons, 8 }, 133 1.3 christos { "ltorg", s390_literals, 0 }, 134 1.3 christos { "string", stringer, 8 + 1 }, 135 1.3 christos { "machine", s390_machine, 0 }, 136 1.3 christos { "machinemode", s390_machinemode, 0 }, 137 1.3 christos { NULL, NULL, 0 } 138 1.1 christos }; 139 1.1 christos 140 1.10 christos /* Register types. */ 141 1.10 christos enum s390_register_type 142 1.10 christos { 143 1.10 christos S390_REGTYPE_AR, /* Access register. */ 144 1.10 christos S390_REGTYPE_CR, /* Control register. */ 145 1.10 christos S390_REGTYPE_FPR, /* Floating-point register. */ 146 1.10 christos S390_REGTYPE_GR, /* General register. */ 147 1.10 christos S390_REGTYPE_VR, /* Vector register. */ 148 1.10 christos }; 149 1.10 christos 150 1.1 christos /* Given NAME, find the register number associated with that name, return 151 1.1 christos the integer value associated with the given name or -1 on failure. */ 152 1.1 christos 153 1.1 christos static int 154 1.3 christos reg_name_search (const char *name) 155 1.1 christos { 156 1.3 christos int val = -1; 157 1.3 christos 158 1.3 christos if (strcasecmp (name, "lit") == 0) 159 1.3 christos return 13; 160 1.1 christos 161 1.3 christos if (strcasecmp (name, "sp") == 0) 162 1.3 christos return 15; 163 1.3 christos 164 1.3 christos if (name[0] != 'a' && name[0] != 'c' && name[0] != 'f' 165 1.3 christos && name[0] != 'r' && name[0] != 'v') 166 1.3 christos return -1; 167 1.1 christos 168 1.3 christos if (ISDIGIT (name[1])) 169 1.1 christos { 170 1.3 christos val = name[1] - '0'; 171 1.3 christos if (ISDIGIT (name[2])) 172 1.3 christos val = val * 10 + name[2] - '0'; 173 1.1 christos } 174 1.1 christos 175 1.3 christos if ((name[0] != 'v' && val > 15) || val > 31) 176 1.3 christos val = -1; 177 1.3 christos 178 1.3 christos return val; 179 1.1 christos } 180 1.1 christos 181 1.1 christos 182 1.1 christos /* 183 1.1 christos * Summary of register_name(). 184 1.1 christos * 185 1.1 christos * in: Input_line_pointer points to 1st char of operand. 186 1.1 christos * 187 1.1 christos * out: A expressionS. 188 1.1 christos * The operand may have been a register: in this case, X_op == O_register, 189 1.1 christos * X_add_number is set to the register number, and truth is returned. 190 1.1 christos * Input_line_pointer->(next non-blank) char after operand, or is in its 191 1.1 christos * original state. 192 1.1 christos */ 193 1.1 christos 194 1.8 christos static bool 195 1.1 christos register_name (expressionS *expressionP) 196 1.1 christos { 197 1.1 christos int reg_number; 198 1.1 christos char *name; 199 1.1 christos char *start; 200 1.1 christos char c; 201 1.1 christos 202 1.1 christos /* Find the spelling of the operand. */ 203 1.1 christos start = name = input_line_pointer; 204 1.1 christos if (name[0] == '%' && ISALPHA (name[1])) 205 1.1 christos name = ++input_line_pointer; 206 1.1 christos else 207 1.8 christos return false; 208 1.1 christos 209 1.3 christos c = get_symbol_name (&name); 210 1.3 christos reg_number = reg_name_search (name); 211 1.1 christos 212 1.1 christos /* Put back the delimiting char. */ 213 1.3 christos (void) restore_line_pointer (c); 214 1.1 christos 215 1.1 christos /* Look to see if it's in the register table. */ 216 1.1 christos if (reg_number >= 0) 217 1.1 christos { 218 1.1 christos expressionP->X_op = O_register; 219 1.1 christos expressionP->X_add_number = reg_number; 220 1.10 christos switch (name[0]) 221 1.10 christos { 222 1.10 christos case 'a': 223 1.10 christos expressionP->X_md = S390_REGTYPE_AR; 224 1.10 christos break; 225 1.10 christos case 'c': 226 1.10 christos expressionP->X_md = S390_REGTYPE_CR; 227 1.10 christos break; 228 1.10 christos case 'f': 229 1.10 christos expressionP->X_md = S390_REGTYPE_FPR; 230 1.10 christos break; 231 1.10 christos case 'r': 232 1.10 christos expressionP->X_md = S390_REGTYPE_GR; 233 1.10 christos break; 234 1.10 christos case 'v': 235 1.10 christos expressionP->X_md = S390_REGTYPE_VR; 236 1.10 christos break; 237 1.10 christos default: 238 1.10 christos expressionP->X_md = 0; 239 1.10 christos } 240 1.1 christos 241 1.1 christos /* Make the rest nice. */ 242 1.1 christos expressionP->X_add_symbol = NULL; 243 1.1 christos expressionP->X_op_symbol = NULL; 244 1.8 christos return true; 245 1.1 christos } 246 1.1 christos 247 1.1 christos /* Reset the line as if we had not done anything. */ 248 1.1 christos input_line_pointer = start; 249 1.8 christos return false; 250 1.1 christos } 251 1.1 christos 252 1.1 christos /* Local variables. */ 253 1.1 christos 254 1.1 christos /* Opformat hash table. */ 255 1.8 christos static htab_t s390_opformat_hash; 256 1.1 christos 257 1.1 christos /* Opcode hash table. */ 258 1.8 christos static htab_t s390_opcode_hash = NULL; 259 1.1 christos 260 1.1 christos /* Flags to set in the elf header */ 261 1.1 christos static flagword s390_flags = 0; 262 1.1 christos 263 1.1 christos symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ 264 1.1 christos 265 1.1 christos #ifndef WORKING_DOT_WORD 266 1.1 christos int md_short_jump_size = 4; 267 1.1 christos int md_long_jump_size = 4; 268 1.1 christos #endif 269 1.1 christos 270 1.10 christos const char md_shortopts[] = "A:m:kVQ:"; 271 1.10 christos const struct option md_longopts[] = { 272 1.1 christos {NULL, no_argument, NULL, 0} 273 1.1 christos }; 274 1.10 christos const size_t md_longopts_size = sizeof (md_longopts); 275 1.1 christos 276 1.1 christos /* Initialize the default opcode arch and word size from the default 277 1.1 christos architecture name if not specified by an option. */ 278 1.1 christos static void 279 1.1 christos init_default_arch (void) 280 1.1 christos { 281 1.10 christos /* Default architecture size. */ 282 1.1 christos if (strcmp (default_arch, "s390") == 0) 283 1.1 christos { 284 1.1 christos if (s390_arch_size == 0) 285 1.1 christos s390_arch_size = 32; 286 1.1 christos } 287 1.1 christos else if (strcmp (default_arch, "s390x") == 0) 288 1.1 christos { 289 1.1 christos if (s390_arch_size == 0) 290 1.1 christos s390_arch_size = 64; 291 1.1 christos } 292 1.1 christos else 293 1.1 christos as_fatal (_("Invalid default architecture, broken assembler.")); 294 1.1 christos 295 1.10 christos /* Default current architecture mode. */ 296 1.1 christos if (current_mode_mask == 0) 297 1.1 christos { 298 1.1 christos /* Default to z/Architecture mode if the CPU supports it. */ 299 1.1 christos if (current_cpu < S390_OPCODE_Z900) 300 1.1 christos current_mode_mask = 1 << S390_OPCODE_ESA; 301 1.1 christos else 302 1.1 christos current_mode_mask = 1 << S390_OPCODE_ZARCH; 303 1.1 christos } 304 1.10 christos 305 1.10 christos /* Determine whether the highgprs flag in the ELF header needs to be set. */ 306 1.10 christos if ((s390_arch_size == 32) && (current_mode_mask & (1 << S390_OPCODE_ZARCH))) 307 1.10 christos set_highgprs_p = true; 308 1.1 christos } 309 1.1 christos 310 1.1 christos /* Called by TARGET_FORMAT. */ 311 1.1 christos const char * 312 1.1 christos s390_target_format (void) 313 1.1 christos { 314 1.1 christos /* We don't get a chance to initialize anything before we're called, 315 1.1 christos so handle that now. */ 316 1.1 christos init_default_arch (); 317 1.1 christos 318 1.1 christos return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390"; 319 1.1 christos } 320 1.1 christos 321 1.3 christos /* Map a cpu string ARG as given with -march= or .machine to the respective 322 1.3 christos enum s390_opcode_cpu_val value. If ALLOW_EXTENSIONS is TRUE, the cpu name 323 1.3 christos can be followed by a list of cpu facility flags each beginning with the 324 1.3 christos character '+'. The active cpu flags are returned through *RET_FLAGS. 325 1.3 christos In case of an error, S390_OPCODE_MAXCPU is returned. */ 326 1.1 christos 327 1.1 christos static unsigned int 328 1.8 christos s390_parse_cpu (const char *arg, 329 1.8 christos unsigned int *ret_flags, 330 1.8 christos bool allow_extensions) 331 1.1 christos { 332 1.3 christos static struct 333 1.3 christos { 334 1.3 christos const char * name; 335 1.6 christos unsigned int name_len; 336 1.6 christos const char * alt_name; 337 1.6 christos unsigned int alt_name_len; 338 1.3 christos unsigned int flags; 339 1.3 christos } cpu_table[S390_OPCODE_MAXCPU] = 340 1.3 christos { 341 1.6 christos { STRING_COMMA_LEN ("g5"), STRING_COMMA_LEN ("arch3"), 0 }, 342 1.6 christos { STRING_COMMA_LEN ("g6"), STRING_COMMA_LEN (""), 0 }, 343 1.6 christos { STRING_COMMA_LEN ("z900"), STRING_COMMA_LEN ("arch5"), 0 }, 344 1.6 christos { STRING_COMMA_LEN ("z990"), STRING_COMMA_LEN ("arch6"), 0 }, 345 1.6 christos { STRING_COMMA_LEN ("z9-109"), STRING_COMMA_LEN (""), 0 }, 346 1.6 christos { STRING_COMMA_LEN ("z9-ec"), STRING_COMMA_LEN ("arch7"), 0 }, 347 1.6 christos { STRING_COMMA_LEN ("z10"), STRING_COMMA_LEN ("arch8"), 0 }, 348 1.6 christos { STRING_COMMA_LEN ("z196"), STRING_COMMA_LEN ("arch9"), 0 }, 349 1.6 christos { STRING_COMMA_LEN ("zEC12"), STRING_COMMA_LEN ("arch10"), 350 1.6 christos S390_INSTR_FLAG_HTM }, 351 1.6 christos { STRING_COMMA_LEN ("z13"), STRING_COMMA_LEN ("arch11"), 352 1.6 christos S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX }, 353 1.6 christos { STRING_COMMA_LEN ("z14"), STRING_COMMA_LEN ("arch12"), 354 1.7 christos S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX }, 355 1.7 christos { STRING_COMMA_LEN ("z15"), STRING_COMMA_LEN ("arch13"), 356 1.8 christos S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX }, 357 1.8 christos { STRING_COMMA_LEN ("z16"), STRING_COMMA_LEN ("arch14"), 358 1.10 christos S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX }, 359 1.10 christos { STRING_COMMA_LEN ("z17"), STRING_COMMA_LEN ("arch15"), 360 1.6 christos S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX } 361 1.3 christos }; 362 1.3 christos static struct 363 1.3 christos { 364 1.8 christos const char *name; 365 1.3 christos unsigned int mask; 366 1.8 christos bool on; 367 1.3 christos } cpu_flags[] = 368 1.3 christos { 369 1.8 christos { "htm", S390_INSTR_FLAG_HTM, true }, 370 1.8 christos { "nohtm", S390_INSTR_FLAG_HTM, false }, 371 1.8 christos { "vx", S390_INSTR_FLAG_VX, true }, 372 1.8 christos { "novx", S390_INSTR_FLAG_VX, false } 373 1.3 christos }; 374 1.3 christos unsigned int icpu; 375 1.3 christos char *ilp_bak; 376 1.3 christos 377 1.3 christos icpu = S390_OPCODE_MAXCPU; 378 1.8 christos if (startswith (arg, "all") && (arg[3] == 0 || arg[3] == '+')) 379 1.3 christos { 380 1.3 christos icpu = S390_OPCODE_MAXCPU - 1; 381 1.3 christos arg += 3; 382 1.3 christos } 383 1.1 christos else 384 1.3 christos { 385 1.3 christos for (icpu = 0; icpu < S390_OPCODE_MAXCPU; icpu++) 386 1.3 christos { 387 1.6 christos unsigned int l, l_alt; 388 1.6 christos 389 1.6 christos l = cpu_table[icpu].name_len; 390 1.3 christos 391 1.3 christos if (strncmp (arg, cpu_table[icpu].name, l) == 0 392 1.3 christos && (arg[l] == 0 || arg[l] == '+')) 393 1.3 christos { 394 1.3 christos arg += l; 395 1.3 christos break; 396 1.3 christos } 397 1.6 christos 398 1.6 christos l_alt = cpu_table[icpu].alt_name_len; 399 1.6 christos 400 1.6 christos if (l_alt > 0 401 1.6 christos && strncmp (arg, cpu_table[icpu].alt_name, l_alt) == 0 402 1.6 christos && (arg[l_alt] == 0 || arg[l_alt] == '+')) 403 1.6 christos { 404 1.6 christos arg += l_alt; 405 1.6 christos break; 406 1.6 christos } 407 1.3 christos } 408 1.3 christos } 409 1.3 christos 410 1.6 christos if (icpu == S390_OPCODE_MAXCPU) 411 1.6 christos return S390_OPCODE_MAXCPU; 412 1.6 christos 413 1.3 christos ilp_bak = input_line_pointer; 414 1.3 christos if (icpu != S390_OPCODE_MAXCPU) 415 1.3 christos { 416 1.5 christos input_line_pointer = (char *) arg; 417 1.3 christos *ret_flags = (cpu_table[icpu].flags & S390_INSTR_FLAG_FACILITY_MASK); 418 1.3 christos 419 1.3 christos while (*input_line_pointer == '+' && allow_extensions) 420 1.3 christos { 421 1.3 christos unsigned int iflag; 422 1.3 christos char *sym; 423 1.3 christos char c; 424 1.3 christos 425 1.3 christos input_line_pointer++; 426 1.3 christos c = get_symbol_name (&sym); 427 1.3 christos for (iflag = 0; iflag < ARRAY_SIZE (cpu_flags); iflag++) 428 1.3 christos { 429 1.3 christos if (strcmp (sym, cpu_flags[iflag].name) == 0) 430 1.3 christos { 431 1.3 christos if (cpu_flags[iflag].on) 432 1.3 christos *ret_flags |= cpu_flags[iflag].mask; 433 1.3 christos else 434 1.3 christos *ret_flags &= ~cpu_flags[iflag].mask; 435 1.3 christos break; 436 1.3 christos } 437 1.3 christos } 438 1.3 christos if (iflag == ARRAY_SIZE (cpu_flags)) 439 1.3 christos as_bad (_("no such machine extension `%s'"), sym - 1); 440 1.3 christos *input_line_pointer = c; 441 1.3 christos if (iflag == ARRAY_SIZE (cpu_flags)) 442 1.3 christos break; 443 1.3 christos } 444 1.3 christos } 445 1.3 christos 446 1.3 christos SKIP_WHITESPACE (); 447 1.3 christos 448 1.3 christos if (*input_line_pointer != 0 && *input_line_pointer != '\n') 449 1.3 christos { 450 1.3 christos as_bad (_("junk at end of machine string, first unrecognized character" 451 1.3 christos " is `%c'"), *input_line_pointer); 452 1.3 christos icpu = S390_OPCODE_MAXCPU; 453 1.3 christos } 454 1.3 christos input_line_pointer = ilp_bak; 455 1.3 christos 456 1.3 christos return icpu; 457 1.1 christos } 458 1.1 christos 459 1.1 christos int 460 1.5 christos md_parse_option (int c, const char *arg) 461 1.1 christos { 462 1.1 christos switch (c) 463 1.1 christos { 464 1.1 christos /* -k: Ignore for FreeBSD compatibility. */ 465 1.1 christos case 'k': 466 1.1 christos break; 467 1.1 christos case 'm': 468 1.1 christos if (arg != NULL && strcmp (arg, "regnames") == 0) 469 1.8 christos reg_names_p = true; 470 1.1 christos 471 1.1 christos else if (arg != NULL && strcmp (arg, "no-regnames") == 0) 472 1.8 christos reg_names_p = false; 473 1.1 christos 474 1.1 christos else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0) 475 1.8 christos warn_areg_zero = true; 476 1.1 christos 477 1.10 christos else if (arg != NULL && strcmp (arg, "warn-regtype-mismatch=strict") == 0) 478 1.10 christos warn_regtype_mismatch = S390_REGTYPE_CHECK_STRICT; 479 1.10 christos 480 1.10 christos else if (arg != NULL && strcmp (arg, "warn-regtype-mismatch=relaxed") == 0) 481 1.10 christos warn_regtype_mismatch = S390_REGTYPE_CHECK_RELAXED; 482 1.10 christos 483 1.10 christos else if (arg != NULL && strcmp (arg, "warn-regtype-mismatch=no") == 0) 484 1.10 christos warn_regtype_mismatch = S390_REGTYPE_CHECK_NONE; 485 1.10 christos 486 1.10 christos else if (arg != NULL && strcmp (arg, "no-warn-regtype-mismatch") == 0) 487 1.10 christos warn_regtype_mismatch = S390_REGTYPE_CHECK_NONE; 488 1.10 christos 489 1.1 christos else if (arg != NULL && strcmp (arg, "31") == 0) 490 1.1 christos s390_arch_size = 32; 491 1.1 christos 492 1.1 christos else if (arg != NULL && strcmp (arg, "64") == 0) 493 1.1 christos s390_arch_size = 64; 494 1.1 christos 495 1.1 christos else if (arg != NULL && strcmp (arg, "esa") == 0) 496 1.1 christos current_mode_mask = 1 << S390_OPCODE_ESA; 497 1.1 christos 498 1.1 christos else if (arg != NULL && strcmp (arg, "zarch") == 0) 499 1.10 christos current_mode_mask = 1 << S390_OPCODE_ZARCH; 500 1.1 christos 501 1.8 christos else if (arg != NULL && startswith (arg, "arch=")) 502 1.1 christos { 503 1.8 christos current_cpu = s390_parse_cpu (arg + 5, ¤t_flags, false); 504 1.3 christos if (current_cpu == S390_OPCODE_MAXCPU) 505 1.1 christos { 506 1.1 christos as_bad (_("invalid switch -m%s"), arg); 507 1.1 christos return 0; 508 1.1 christos } 509 1.1 christos } 510 1.1 christos 511 1.1 christos else 512 1.1 christos { 513 1.1 christos as_bad (_("invalid switch -m%s"), arg); 514 1.1 christos return 0; 515 1.1 christos } 516 1.1 christos break; 517 1.1 christos 518 1.1 christos case 'A': 519 1.1 christos /* Option -A is deprecated. Still available for compatibility. */ 520 1.1 christos if (arg != NULL && strcmp (arg, "esa") == 0) 521 1.1 christos current_cpu = S390_OPCODE_G5; 522 1.1 christos else if (arg != NULL && strcmp (arg, "esame") == 0) 523 1.1 christos current_cpu = S390_OPCODE_Z900; 524 1.1 christos else 525 1.1 christos as_bad (_("invalid architecture -A%s"), arg); 526 1.1 christos break; 527 1.1 christos 528 1.1 christos /* -V: SVR4 argument to print version ID. */ 529 1.1 christos case 'V': 530 1.1 christos print_version_id (); 531 1.1 christos break; 532 1.1 christos 533 1.1 christos /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section 534 1.1 christos should be emitted or not. FIXME: Not implemented. */ 535 1.1 christos case 'Q': 536 1.1 christos break; 537 1.1 christos 538 1.1 christos default: 539 1.1 christos return 0; 540 1.1 christos } 541 1.1 christos 542 1.1 christos return 1; 543 1.1 christos } 544 1.1 christos 545 1.1 christos void 546 1.1 christos md_show_usage (FILE *stream) 547 1.1 christos { 548 1.1 christos fprintf (stream, _("\ 549 1.10 christos S390 options:\n\ 550 1.10 christos -m31 generate 31-bit file format (31/32 bit word size)\n\ 551 1.10 christos -m64 generate 64-bit file format (64 bit word size)\n\ 552 1.10 christos -mesa assemble for Enterprise System Architecture/390\n\ 553 1.10 christos -mzarch assemble for z/Architecture\n\ 554 1.10 christos -march=<processor> assemble for processor <processor>\n\ 555 1.10 christos -mregnames allow symbolic names for registers\n\ 556 1.10 christos -mno-regnames do not allow symbolic names for registers\n\ 557 1.10 christos -mwarn-areg-zero warn about base/index register zero\n\ 558 1.10 christos -mwarn-regtype-mismatch=strict\n\ 559 1.10 christos warn about register name type mismatches\n\ 560 1.10 christos -mwarn-regtype-mismatch=relaxed\n\ 561 1.10 christos warn about register name type mismatches,\n\ 562 1.10 christos but allow FPR and VR to be used interchangeably\n\ 563 1.10 christos -mno-warn-regtype-mismatch\n\ 564 1.10 christos do not warn about register name type mismatches\n\ 565 1.10 christos ")); 566 1.1 christos fprintf (stream, _("\ 567 1.10 christos -V print assembler version number\n\ 568 1.10 christos -Qy, -Qn ignored\n")); 569 1.10 christos fprintf (stream, _("\ 570 1.10 christos Deprecated S390 options:\n\ 571 1.10 christos -Aesa assemble for processor IBM S/390 G5 (g5/arch3)\n\ 572 1.10 christos -Aesame assemble for processor IBM zSeries 900 (z900/arch5)\n")); 573 1.1 christos } 574 1.1 christos 575 1.1 christos /* Generate the hash table mapping mnemonics to struct s390_opcode. 576 1.1 christos This table is built at startup and whenever the CPU level is 577 1.1 christos changed using .machine. */ 578 1.1 christos 579 1.1 christos static void 580 1.1 christos s390_setup_opcodes (void) 581 1.1 christos { 582 1.3 christos const struct s390_opcode *op; 583 1.1 christos const struct s390_opcode *op_end; 584 1.8 christos bool dup_insn = false; 585 1.1 christos 586 1.1 christos if (s390_opcode_hash != NULL) 587 1.8 christos htab_delete (s390_opcode_hash); 588 1.1 christos 589 1.1 christos /* Insert the opcodes into a hash table. */ 590 1.8 christos s390_opcode_hash = str_htab_create (); 591 1.1 christos 592 1.1 christos op_end = s390_opcodes + s390_num_opcodes; 593 1.1 christos for (op = s390_opcodes; op < op_end; op++) 594 1.1 christos { 595 1.3 christos int use_opcode; 596 1.3 christos 597 1.1 christos while (op < op_end - 1 && strcmp(op->name, op[1].name) == 0) 598 1.1 christos { 599 1.1 christos if (op->min_cpu <= current_cpu && (op->modes & current_mode_mask)) 600 1.1 christos break; 601 1.1 christos op++; 602 1.1 christos } 603 1.1 christos 604 1.3 christos if ((op->modes & current_mode_mask) == 0) 605 1.3 christos use_opcode = 0; 606 1.3 christos else if ((op->flags & S390_INSTR_FLAG_FACILITY_MASK) == 0) 607 1.3 christos { 608 1.3 christos /* Opcodes that do not belong to a specific facility are enabled if 609 1.3 christos present in the selected cpu. */ 610 1.3 christos use_opcode = (op->min_cpu <= current_cpu); 611 1.3 christos } 612 1.3 christos else 613 1.3 christos { 614 1.3 christos unsigned int f; 615 1.3 christos 616 1.3 christos /* Opcodes of a specific facility are enabled if the facility is 617 1.3 christos enabled. Note: only some facilities are represented as flags. */ 618 1.3 christos f = (op->flags & S390_INSTR_FLAG_FACILITY_MASK); 619 1.3 christos use_opcode = ((f & current_flags) == f); 620 1.3 christos } 621 1.8 christos if (use_opcode 622 1.8 christos && str_hash_insert (s390_opcode_hash, op->name, op, 0) != NULL) 623 1.1 christos { 624 1.8 christos as_bad (_("duplicate %s"), op->name); 625 1.8 christos dup_insn = true; 626 1.1 christos } 627 1.1 christos 628 1.1 christos while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0) 629 1.1 christos op++; 630 1.3 christos } 631 1.1 christos 632 1.1 christos if (dup_insn) 633 1.1 christos abort (); 634 1.1 christos } 635 1.1 christos 636 1.1 christos /* This function is called when the assembler starts up. It is called 637 1.1 christos after the options have been parsed and the output file has been 638 1.1 christos opened. */ 639 1.1 christos 640 1.1 christos void 641 1.1 christos md_begin (void) 642 1.1 christos { 643 1.3 christos const struct s390_opcode *op; 644 1.1 christos const struct s390_opcode *op_end; 645 1.1 christos 646 1.10 christos /* Give a warning if the combination -m64 and -Aesa is used. */ 647 1.1 christos if (s390_arch_size == 64 && current_cpu < S390_OPCODE_Z900) 648 1.10 christos as_warn (_("The 64-bit file format is used without z/Architecture instructions.")); 649 1.1 christos 650 1.1 christos s390_cie_data_alignment = -s390_arch_size / 8; 651 1.1 christos 652 1.1 christos /* Set the ELF flags if desired. */ 653 1.1 christos if (s390_flags) 654 1.1 christos bfd_set_private_flags (stdoutput, s390_flags); 655 1.1 christos 656 1.1 christos /* Insert the opcode formats into a hash table. */ 657 1.8 christos s390_opformat_hash = str_htab_create (); 658 1.1 christos 659 1.1 christos op_end = s390_opformats + s390_num_opformats; 660 1.1 christos for (op = s390_opformats; op < op_end; op++) 661 1.8 christos if (str_hash_insert (s390_opformat_hash, op->name, op, 0) != NULL) 662 1.8 christos as_fatal (_("duplicate %s"), op->name); 663 1.1 christos 664 1.1 christos s390_setup_opcodes (); 665 1.1 christos 666 1.1 christos record_alignment (text_section, 2); 667 1.1 christos record_alignment (data_section, 2); 668 1.1 christos record_alignment (bss_section, 2); 669 1.1 christos } 670 1.1 christos 671 1.1 christos /* Called after all assembly has been done. */ 672 1.1 christos void 673 1.9 christos s390_md_finish (void) 674 1.1 christos { 675 1.1 christos if (s390_arch_size == 64) 676 1.1 christos bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64); 677 1.1 christos else 678 1.1 christos bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31); 679 1.1 christos } 680 1.1 christos 681 1.10 christos static void 682 1.10 christos s390_bad_operand_out_of_range (int operand_number, 683 1.10 christos offsetT value, 684 1.10 christos offsetT min, 685 1.10 christos offsetT max, 686 1.10 christos const char *file, 687 1.10 christos unsigned line) 688 1.10 christos { 689 1.10 christos const char * err; 690 1.10 christos 691 1.10 christos if (operand_number > 0) 692 1.10 christos { 693 1.10 christos /* xgettext:c-format. */ 694 1.10 christos err =_("operand %d: operand out of range (%" PRId64 695 1.10 christos " is not between %" PRId64 " and %" PRId64 ")"); 696 1.10 christos if (file) 697 1.10 christos as_bad_where (file, line, err, operand_number, 698 1.10 christos (int64_t) value, (int64_t) min, (int64_t) max); 699 1.10 christos else 700 1.10 christos as_bad (err, operand_number, 701 1.10 christos (int64_t) value, (int64_t) min, (int64_t) max); 702 1.10 christos } 703 1.10 christos else 704 1.10 christos { 705 1.10 christos /* xgettext:c-format. */ 706 1.10 christos err = _("operand out of range (%" PRId64 707 1.10 christos " is not between %" PRId64 " and %" PRId64 ")"); 708 1.10 christos if (file) 709 1.10 christos as_bad_where (file, line, err, 710 1.10 christos (int64_t) value, (int64_t) min, (int64_t) max); 711 1.10 christos else 712 1.10 christos as_bad (err, (int64_t) value, (int64_t) min, (int64_t) max); 713 1.10 christos } 714 1.10 christos } 715 1.10 christos 716 1.1 christos /* Insert an operand value into an instruction. */ 717 1.1 christos 718 1.1 christos static void 719 1.1 christos s390_insert_operand (unsigned char *insn, 720 1.1 christos const struct s390_operand *operand, 721 1.1 christos offsetT val, 722 1.5 christos const char *file, 723 1.10 christos unsigned int line, 724 1.10 christos int operand_number) 725 1.1 christos { 726 1.1 christos addressT uval; 727 1.1 christos int offset; 728 1.1 christos 729 1.1 christos if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL)) 730 1.1 christos { 731 1.1 christos offsetT min, max; 732 1.1 christos 733 1.1 christos max = ((offsetT) 1 << (operand->bits - 1)) - 1; 734 1.1 christos min = - ((offsetT) 1 << (operand->bits - 1)); 735 1.1 christos /* Halve PCREL operands. */ 736 1.1 christos if (operand->flags & S390_OPERAND_PCREL) 737 1.1 christos val >>= 1; 738 1.1 christos /* Check for underflow / overflow. */ 739 1.1 christos if (val < min || val > max) 740 1.1 christos { 741 1.1 christos if (operand->flags & S390_OPERAND_PCREL) 742 1.1 christos { 743 1.10 christos val = (addressT) val << 1; 744 1.10 christos min = (addressT) min << 1; 745 1.10 christos max = (addressT) max << 1; 746 1.1 christos } 747 1.10 christos 748 1.10 christos s390_bad_operand_out_of_range (operand_number, val, min, max, 749 1.10 christos file, line); 750 1.10 christos 751 1.1 christos return; 752 1.1 christos } 753 1.1 christos /* val is ok, now restrict it to operand->bits bits. */ 754 1.10 christos uval = val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1); 755 1.1 christos /* val is restrict, now check for special case. */ 756 1.1 christos if (operand->bits == 20 && operand->shift == 20) 757 1.1 christos uval = (uval >> 12) | ((uval & 0xfff) << 8); 758 1.1 christos } 759 1.1 christos else 760 1.1 christos { 761 1.1 christos addressT min, max; 762 1.1 christos 763 1.1 christos max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1; 764 1.10 christos min = 0; 765 1.10 christos uval = val; 766 1.3 christos 767 1.3 christos /* Vector register operands have an additional bit in the RXB 768 1.3 christos field. */ 769 1.3 christos if (operand->flags & S390_OPERAND_VR) 770 1.3 christos max = (max << 1) | 1; 771 1.3 christos 772 1.1 christos /* Length x in an instructions has real length x+1. */ 773 1.1 christos if (operand->flags & S390_OPERAND_LENGTH) 774 1.1 christos uval--; 775 1.1 christos /* Check for underflow / overflow. */ 776 1.1 christos if (uval < min || uval > max) 777 1.1 christos { 778 1.1 christos if (operand->flags & S390_OPERAND_LENGTH) 779 1.1 christos { 780 1.1 christos uval++; 781 1.1 christos min++; 782 1.1 christos max++; 783 1.1 christos } 784 1.1 christos 785 1.10 christos s390_bad_operand_out_of_range (operand_number, val, min, max, 786 1.10 christos file, line); 787 1.1 christos 788 1.1 christos return; 789 1.1 christos } 790 1.1 christos } 791 1.1 christos 792 1.3 christos if (operand->flags & S390_OPERAND_VR) 793 1.3 christos { 794 1.3 christos /* Insert the extra bit into the RXB field. */ 795 1.3 christos switch (operand->shift) 796 1.3 christos { 797 1.3 christos case 8: 798 1.3 christos insn[4] |= (uval & 0x10) >> 1; 799 1.3 christos break; 800 1.3 christos case 12: 801 1.3 christos insn[4] |= (uval & 0x10) >> 2; 802 1.3 christos break; 803 1.3 christos case 16: 804 1.3 christos insn[4] |= (uval & 0x10) >> 3; 805 1.3 christos break; 806 1.3 christos case 32: 807 1.3 christos insn[4] |= (uval & 0x10) >> 4; 808 1.3 christos break; 809 1.3 christos } 810 1.3 christos uval &= 0xf; 811 1.3 christos } 812 1.3 christos 813 1.9 christos /* Duplicate the GPR/VR operand at bit pos 12 to 16. */ 814 1.3 christos if (operand->flags & S390_OPERAND_CP16) 815 1.3 christos { 816 1.9 christos /* Copy GPR/VR operand at bit pos 12 to bit pos 16. */ 817 1.3 christos insn[2] |= uval << 4; 818 1.9 christos 819 1.9 christos if (operand->flags & S390_OPERAND_VR) 820 1.9 christos { 821 1.9 christos /* Copy the VR flag in the RXB field. */ 822 1.9 christos insn[4] |= (insn[4] & 4) >> 1; 823 1.9 christos } 824 1.3 christos } 825 1.3 christos 826 1.1 christos /* Insert fragments of the operand byte for byte. */ 827 1.1 christos offset = operand->shift + operand->bits; 828 1.1 christos uval <<= (-offset) & 7; 829 1.1 christos insn += (offset - 1) / 8; 830 1.1 christos while (uval != 0) 831 1.1 christos { 832 1.1 christos *insn-- |= uval; 833 1.1 christos uval >>= 8; 834 1.1 christos } 835 1.1 christos } 836 1.1 christos 837 1.1 christos struct map_tls 838 1.1 christos { 839 1.5 christos const char *string; 840 1.1 christos int length; 841 1.1 christos bfd_reloc_code_real_type reloc; 842 1.1 christos }; 843 1.1 christos 844 1.1 christos /* Parse tls marker and return the desired relocation. */ 845 1.1 christos static bfd_reloc_code_real_type 846 1.1 christos s390_tls_suffix (char **str_p, expressionS *exp_p) 847 1.1 christos { 848 1.1 christos static struct map_tls mapping[] = 849 1.1 christos { 850 1.1 christos { "tls_load", 8, BFD_RELOC_390_TLS_LOAD }, 851 1.1 christos { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL }, 852 1.1 christos { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL }, 853 1.1 christos { NULL, 0, BFD_RELOC_UNUSED } 854 1.1 christos }; 855 1.1 christos struct map_tls *ptr; 856 1.1 christos char *orig_line; 857 1.1 christos char *str; 858 1.1 christos char *ident; 859 1.1 christos int len; 860 1.1 christos 861 1.1 christos str = *str_p; 862 1.1 christos if (*str++ != ':') 863 1.1 christos return BFD_RELOC_UNUSED; 864 1.1 christos 865 1.1 christos ident = str; 866 1.1 christos while (ISIDNUM (*str)) 867 1.1 christos str++; 868 1.1 christos len = str - ident; 869 1.1 christos if (*str++ != ':') 870 1.1 christos return BFD_RELOC_UNUSED; 871 1.1 christos 872 1.1 christos orig_line = input_line_pointer; 873 1.1 christos input_line_pointer = str; 874 1.1 christos expression (exp_p); 875 1.1 christos str = input_line_pointer; 876 1.1 christos if (&input_line_pointer != str_p) 877 1.1 christos input_line_pointer = orig_line; 878 1.1 christos 879 1.1 christos if (exp_p->X_op != O_symbol) 880 1.1 christos return BFD_RELOC_UNUSED; 881 1.1 christos 882 1.1 christos for (ptr = &mapping[0]; ptr->length > 0; ptr++) 883 1.1 christos if (len == ptr->length 884 1.1 christos && strncasecmp (ident, ptr->string, ptr->length) == 0) 885 1.1 christos { 886 1.1 christos /* Found a matching tls suffix. */ 887 1.1 christos *str_p = str; 888 1.1 christos return ptr->reloc; 889 1.1 christos } 890 1.1 christos return BFD_RELOC_UNUSED; 891 1.1 christos } 892 1.1 christos 893 1.1 christos /* Structure used to hold suffixes. */ 894 1.1 christos typedef enum 895 1.1 christos { 896 1.1 christos ELF_SUFFIX_NONE = 0, 897 1.1 christos ELF_SUFFIX_GOT, 898 1.1 christos ELF_SUFFIX_PLT, 899 1.1 christos ELF_SUFFIX_GOTENT, 900 1.1 christos ELF_SUFFIX_GOTOFF, 901 1.1 christos ELF_SUFFIX_GOTPLT, 902 1.1 christos ELF_SUFFIX_PLTOFF, 903 1.1 christos ELF_SUFFIX_TLS_GD, 904 1.1 christos ELF_SUFFIX_TLS_GOTIE, 905 1.1 christos ELF_SUFFIX_TLS_IE, 906 1.1 christos ELF_SUFFIX_TLS_LDM, 907 1.1 christos ELF_SUFFIX_TLS_LDO, 908 1.1 christos ELF_SUFFIX_TLS_LE 909 1.1 christos } 910 1.1 christos elf_suffix_type; 911 1.1 christos 912 1.1 christos struct map_bfd 913 1.1 christos { 914 1.5 christos const char *string; 915 1.1 christos int length; 916 1.1 christos elf_suffix_type suffix; 917 1.1 christos }; 918 1.1 christos 919 1.1 christos 920 1.1 christos /* Parse @got/@plt/@gotoff. and return the desired relocation. */ 921 1.1 christos static elf_suffix_type 922 1.1 christos s390_elf_suffix (char **str_p, expressionS *exp_p) 923 1.1 christos { 924 1.1 christos static struct map_bfd mapping[] = 925 1.1 christos { 926 1.1 christos { "got", 3, ELF_SUFFIX_GOT }, 927 1.1 christos { "got12", 5, ELF_SUFFIX_GOT }, 928 1.1 christos { "plt", 3, ELF_SUFFIX_PLT }, 929 1.1 christos { "gotent", 6, ELF_SUFFIX_GOTENT }, 930 1.1 christos { "gotoff", 6, ELF_SUFFIX_GOTOFF }, 931 1.1 christos { "gotplt", 6, ELF_SUFFIX_GOTPLT }, 932 1.1 christos { "pltoff", 6, ELF_SUFFIX_PLTOFF }, 933 1.1 christos { "tlsgd", 5, ELF_SUFFIX_TLS_GD }, 934 1.1 christos { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE }, 935 1.1 christos { "indntpoff", 9, ELF_SUFFIX_TLS_IE }, 936 1.1 christos { "tlsldm", 6, ELF_SUFFIX_TLS_LDM }, 937 1.1 christos { "dtpoff", 6, ELF_SUFFIX_TLS_LDO }, 938 1.1 christos { "ntpoff", 6, ELF_SUFFIX_TLS_LE }, 939 1.1 christos { NULL, 0, ELF_SUFFIX_NONE } 940 1.1 christos }; 941 1.1 christos 942 1.1 christos struct map_bfd *ptr; 943 1.1 christos char *str = *str_p; 944 1.1 christos char *ident; 945 1.1 christos int len; 946 1.1 christos 947 1.1 christos if (*str++ != '@') 948 1.1 christos return ELF_SUFFIX_NONE; 949 1.1 christos 950 1.1 christos ident = str; 951 1.1 christos while (ISALNUM (*str)) 952 1.1 christos str++; 953 1.1 christos len = str - ident; 954 1.1 christos 955 1.1 christos for (ptr = &mapping[0]; ptr->length > 0; ptr++) 956 1.1 christos if (len == ptr->length 957 1.1 christos && strncasecmp (ident, ptr->string, ptr->length) == 0) 958 1.1 christos { 959 1.1 christos if (exp_p->X_add_number != 0) 960 1.1 christos as_warn (_("identifier+constant@%s means identifier@%s+constant"), 961 1.1 christos ptr->string, ptr->string); 962 1.1 christos /* Now check for identifier@suffix+constant. */ 963 1.1 christos if (*str == '-' || *str == '+') 964 1.1 christos { 965 1.1 christos char *orig_line = input_line_pointer; 966 1.1 christos expressionS new_exp; 967 1.1 christos 968 1.1 christos input_line_pointer = str; 969 1.1 christos expression (&new_exp); 970 1.1 christos 971 1.1 christos switch (new_exp.X_op) 972 1.1 christos { 973 1.1 christos case O_constant: /* X_add_number (a constant expression). */ 974 1.1 christos exp_p->X_add_number += new_exp.X_add_number; 975 1.1 christos str = input_line_pointer; 976 1.1 christos break; 977 1.1 christos case O_symbol: /* X_add_symbol + X_add_number. */ 978 1.1 christos /* this case is used for e.g. xyz@PLT+.Label. */ 979 1.1 christos exp_p->X_add_number += new_exp.X_add_number; 980 1.1 christos exp_p->X_op_symbol = new_exp.X_add_symbol; 981 1.1 christos exp_p->X_op = O_add; 982 1.1 christos str = input_line_pointer; 983 1.1 christos break; 984 1.1 christos case O_uminus: /* (- X_add_symbol) + X_add_number. */ 985 1.1 christos /* this case is used for e.g. xyz (at) PLT-.Label. */ 986 1.1 christos exp_p->X_add_number += new_exp.X_add_number; 987 1.1 christos exp_p->X_op_symbol = new_exp.X_add_symbol; 988 1.1 christos exp_p->X_op = O_subtract; 989 1.1 christos str = input_line_pointer; 990 1.1 christos break; 991 1.1 christos default: 992 1.1 christos break; 993 1.1 christos } 994 1.1 christos 995 1.1 christos /* If s390_elf_suffix has not been called with 996 1.1 christos &input_line_pointer as first parameter, we have 997 1.1 christos clobbered the input_line_pointer. We have to 998 1.1 christos undo that. */ 999 1.1 christos if (&input_line_pointer != str_p) 1000 1.1 christos input_line_pointer = orig_line; 1001 1.1 christos } 1002 1.1 christos *str_p = str; 1003 1.1 christos return ptr->suffix; 1004 1.1 christos } 1005 1.1 christos 1006 1.7 christos return ELF_SUFFIX_NONE; 1007 1.1 christos } 1008 1.1 christos 1009 1.1 christos /* Structure used to hold a literal pool entry. */ 1010 1.1 christos struct s390_lpe 1011 1.1 christos { 1012 1.1 christos struct s390_lpe *next; 1013 1.1 christos expressionS ex; 1014 1.1 christos FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */ 1015 1.1 christos LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */ 1016 1.1 christos int nbytes; 1017 1.1 christos bfd_reloc_code_real_type reloc; 1018 1.1 christos symbolS *sym; 1019 1.1 christos }; 1020 1.1 christos 1021 1.1 christos static struct s390_lpe *lpe_free_list = NULL; 1022 1.1 christos static struct s390_lpe *lpe_list = NULL; 1023 1.1 christos static struct s390_lpe *lpe_list_tail = NULL; 1024 1.1 christos static symbolS *lp_sym = NULL; 1025 1.1 christos static int lp_count = 0; 1026 1.1 christos static int lpe_count = 0; 1027 1.1 christos 1028 1.1 christos static int 1029 1.1 christos s390_exp_compare (expressionS *exp1, expressionS *exp2) 1030 1.1 christos { 1031 1.1 christos if (exp1->X_op != exp2->X_op) 1032 1.1 christos return 0; 1033 1.1 christos 1034 1.1 christos switch (exp1->X_op) 1035 1.1 christos { 1036 1.1 christos case O_constant: /* X_add_number must be equal. */ 1037 1.1 christos case O_register: 1038 1.1 christos return exp1->X_add_number == exp2->X_add_number; 1039 1.1 christos 1040 1.1 christos case O_big: 1041 1.1 christos as_bad (_("Can't handle O_big in s390_exp_compare")); 1042 1.6 christos return 0; 1043 1.1 christos 1044 1.1 christos case O_symbol: /* X_add_symbol & X_add_number must be equal. */ 1045 1.1 christos case O_symbol_rva: 1046 1.1 christos case O_uminus: 1047 1.1 christos case O_bit_not: 1048 1.1 christos case O_logical_not: 1049 1.1 christos return (exp1->X_add_symbol == exp2->X_add_symbol) 1050 1.1 christos && (exp1->X_add_number == exp2->X_add_number); 1051 1.1 christos 1052 1.1 christos case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */ 1053 1.1 christos case O_divide: 1054 1.1 christos case O_modulus: 1055 1.1 christos case O_left_shift: 1056 1.1 christos case O_right_shift: 1057 1.1 christos case O_bit_inclusive_or: 1058 1.1 christos case O_bit_or_not: 1059 1.1 christos case O_bit_exclusive_or: 1060 1.1 christos case O_bit_and: 1061 1.1 christos case O_add: 1062 1.1 christos case O_subtract: 1063 1.1 christos case O_eq: 1064 1.1 christos case O_ne: 1065 1.1 christos case O_lt: 1066 1.1 christos case O_le: 1067 1.1 christos case O_ge: 1068 1.1 christos case O_gt: 1069 1.1 christos case O_logical_and: 1070 1.1 christos case O_logical_or: 1071 1.1 christos return (exp1->X_add_symbol == exp2->X_add_symbol) 1072 1.1 christos && (exp1->X_op_symbol == exp2->X_op_symbol) 1073 1.1 christos && (exp1->X_add_number == exp2->X_add_number); 1074 1.1 christos default: 1075 1.1 christos return 0; 1076 1.1 christos } 1077 1.1 christos } 1078 1.1 christos 1079 1.6 christos /* Test for @lit and if it's present make an entry in the literal pool and 1080 1.1 christos modify the current expression to be an offset into the literal pool. */ 1081 1.1 christos static elf_suffix_type 1082 1.1 christos s390_lit_suffix (char **str_p, expressionS *exp_p, elf_suffix_type suffix) 1083 1.1 christos { 1084 1.1 christos bfd_reloc_code_real_type reloc; 1085 1.1 christos char tmp_name[64]; 1086 1.1 christos char *str = *str_p; 1087 1.1 christos char *ident; 1088 1.1 christos struct s390_lpe *lpe; 1089 1.1 christos int nbytes, len; 1090 1.1 christos 1091 1.1 christos if (*str++ != ':') 1092 1.1 christos return suffix; /* No modification. */ 1093 1.1 christos 1094 1.1 christos /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */ 1095 1.1 christos ident = str; 1096 1.1 christos while (ISALNUM (*str)) 1097 1.1 christos str++; 1098 1.1 christos len = str - ident; 1099 1.1 christos if (len != 4 || strncasecmp (ident, "lit", 3) != 0 1100 1.1 christos || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8')) 1101 1.1 christos return suffix; /* no modification */ 1102 1.1 christos nbytes = ident[3] - '0'; 1103 1.1 christos 1104 1.1 christos reloc = BFD_RELOC_UNUSED; 1105 1.1 christos if (suffix == ELF_SUFFIX_GOT) 1106 1.1 christos { 1107 1.1 christos if (nbytes == 2) 1108 1.1 christos reloc = BFD_RELOC_390_GOT16; 1109 1.1 christos else if (nbytes == 4) 1110 1.1 christos reloc = BFD_RELOC_32_GOT_PCREL; 1111 1.1 christos else if (nbytes == 8) 1112 1.1 christos reloc = BFD_RELOC_390_GOT64; 1113 1.1 christos } 1114 1.1 christos else if (suffix == ELF_SUFFIX_PLT) 1115 1.1 christos { 1116 1.1 christos if (nbytes == 4) 1117 1.1 christos reloc = BFD_RELOC_390_PLT32; 1118 1.1 christos else if (nbytes == 8) 1119 1.1 christos reloc = BFD_RELOC_390_PLT64; 1120 1.1 christos } 1121 1.1 christos 1122 1.1 christos if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) 1123 1.1 christos as_bad (_("Invalid suffix for literal pool entry")); 1124 1.1 christos 1125 1.1 christos /* Search the pool if the new entry is a duplicate. */ 1126 1.1 christos if (exp_p->X_op == O_big) 1127 1.1 christos { 1128 1.1 christos /* Special processing for big numbers. */ 1129 1.1 christos for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) 1130 1.1 christos { 1131 1.1 christos if (lpe->ex.X_op == O_big) 1132 1.1 christos { 1133 1.1 christos if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0) 1134 1.1 christos { 1135 1.1 christos if (memcmp (&generic_floating_point_number, &lpe->floatnum, 1136 1.1 christos sizeof (FLONUM_TYPE)) == 0) 1137 1.1 christos break; 1138 1.1 christos } 1139 1.1 christos else if (exp_p->X_add_number == lpe->ex.X_add_number) 1140 1.1 christos { 1141 1.1 christos if (memcmp (generic_bignum, lpe->bignum, 1142 1.1 christos sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0) 1143 1.1 christos break; 1144 1.1 christos } 1145 1.1 christos } 1146 1.1 christos } 1147 1.1 christos } 1148 1.1 christos else 1149 1.1 christos { 1150 1.1 christos /* Processing for 'normal' data types. */ 1151 1.1 christos for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) 1152 1.1 christos if (lpe->nbytes == nbytes && lpe->reloc == reloc 1153 1.1 christos && s390_exp_compare (exp_p, &lpe->ex) != 0) 1154 1.1 christos break; 1155 1.1 christos } 1156 1.1 christos 1157 1.1 christos if (lpe == NULL) 1158 1.1 christos { 1159 1.1 christos /* A new literal. */ 1160 1.1 christos if (lpe_free_list != NULL) 1161 1.1 christos { 1162 1.1 christos lpe = lpe_free_list; 1163 1.1 christos lpe_free_list = lpe_free_list->next; 1164 1.1 christos } 1165 1.1 christos else 1166 1.1 christos { 1167 1.5 christos lpe = XNEW (struct s390_lpe); 1168 1.1 christos } 1169 1.1 christos 1170 1.1 christos lpe->ex = *exp_p; 1171 1.1 christos 1172 1.1 christos if (exp_p->X_op == O_big) 1173 1.1 christos { 1174 1.1 christos if (exp_p->X_add_number <= 0) 1175 1.1 christos lpe->floatnum = generic_floating_point_number; 1176 1.1 christos else if (exp_p->X_add_number <= 4) 1177 1.1 christos memcpy (lpe->bignum, generic_bignum, 1178 1.1 christos exp_p->X_add_number * sizeof (LITTLENUM_TYPE)); 1179 1.1 christos else 1180 1.1 christos as_bad (_("Big number is too big")); 1181 1.1 christos } 1182 1.1 christos 1183 1.1 christos lpe->nbytes = nbytes; 1184 1.1 christos lpe->reloc = reloc; 1185 1.1 christos /* Literal pool name defined ? */ 1186 1.1 christos if (lp_sym == NULL) 1187 1.1 christos { 1188 1.1 christos sprintf (tmp_name, ".L\001%i", lp_count); 1189 1.1 christos lp_sym = symbol_make (tmp_name); 1190 1.1 christos } 1191 1.1 christos 1192 1.1 christos /* Make name for literal pool entry. */ 1193 1.1 christos sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count); 1194 1.1 christos lpe_count++; 1195 1.1 christos lpe->sym = symbol_make (tmp_name); 1196 1.1 christos 1197 1.1 christos /* Add to literal pool list. */ 1198 1.1 christos lpe->next = NULL; 1199 1.1 christos if (lpe_list_tail != NULL) 1200 1.1 christos { 1201 1.1 christos lpe_list_tail->next = lpe; 1202 1.1 christos lpe_list_tail = lpe; 1203 1.1 christos } 1204 1.1 christos else 1205 1.1 christos lpe_list = lpe_list_tail = lpe; 1206 1.1 christos } 1207 1.1 christos 1208 1.1 christos /* Now change exp_p to the offset into the literal pool. 1209 1.6 christos That's the expression: .L^Ax^By-.L^Ax */ 1210 1.1 christos exp_p->X_add_symbol = lpe->sym; 1211 1.1 christos exp_p->X_op_symbol = lp_sym; 1212 1.1 christos exp_p->X_op = O_subtract; 1213 1.1 christos exp_p->X_add_number = 0; 1214 1.1 christos 1215 1.1 christos *str_p = str; 1216 1.1 christos 1217 1.1 christos /* We change the suffix type to ELF_SUFFIX_NONE, because 1218 1.1 christos the difference of two local labels is just a number. */ 1219 1.1 christos return ELF_SUFFIX_NONE; 1220 1.1 christos } 1221 1.1 christos 1222 1.1 christos /* Like normal .long/.short/.word, except support @got, etc. 1223 1.1 christos clobbers input_line_pointer, checks end-of-line. */ 1224 1.1 christos static void 1225 1.1 christos s390_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long */) 1226 1.1 christos { 1227 1.1 christos expressionS exp; 1228 1.1 christos elf_suffix_type suffix; 1229 1.1 christos 1230 1.1 christos if (is_it_end_of_statement ()) 1231 1.1 christos { 1232 1.1 christos demand_empty_rest_of_line (); 1233 1.1 christos return; 1234 1.1 christos } 1235 1.1 christos 1236 1.1 christos do 1237 1.1 christos { 1238 1.1 christos expression (&exp); 1239 1.1 christos 1240 1.1 christos if (exp.X_op == O_symbol 1241 1.1 christos && *input_line_pointer == '@' 1242 1.1 christos && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE) 1243 1.1 christos { 1244 1.1 christos bfd_reloc_code_real_type reloc; 1245 1.1 christos reloc_howto_type *reloc_howto; 1246 1.1 christos int size; 1247 1.1 christos char *where; 1248 1.1 christos 1249 1.1 christos if (nbytes == 2) 1250 1.1 christos { 1251 1.1 christos static bfd_reloc_code_real_type tab2[] = 1252 1.1 christos { 1253 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ 1254 1.1 christos BFD_RELOC_390_GOT16, /* ELF_SUFFIX_GOT */ 1255 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_PLT */ 1256 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ 1257 1.1 christos BFD_RELOC_16_GOTOFF, /* ELF_SUFFIX_GOTOFF */ 1258 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTPLT */ 1259 1.1 christos BFD_RELOC_390_PLTOFF16, /* ELF_SUFFIX_PLTOFF */ 1260 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GD */ 1261 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GOTIE */ 1262 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_IE */ 1263 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDM */ 1264 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDO */ 1265 1.1 christos BFD_RELOC_UNUSED /* ELF_SUFFIX_TLS_LE */ 1266 1.1 christos }; 1267 1.1 christos reloc = tab2[suffix]; 1268 1.1 christos } 1269 1.1 christos else if (nbytes == 4) 1270 1.1 christos { 1271 1.1 christos static bfd_reloc_code_real_type tab4[] = 1272 1.1 christos { 1273 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ 1274 1.1 christos BFD_RELOC_32_GOT_PCREL, /* ELF_SUFFIX_GOT */ 1275 1.1 christos BFD_RELOC_390_PLT32, /* ELF_SUFFIX_PLT */ 1276 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ 1277 1.1 christos BFD_RELOC_32_GOTOFF, /* ELF_SUFFIX_GOTOFF */ 1278 1.1 christos BFD_RELOC_390_GOTPLT32, /* ELF_SUFFIX_GOTPLT */ 1279 1.1 christos BFD_RELOC_390_PLTOFF32, /* ELF_SUFFIX_PLTOFF */ 1280 1.1 christos BFD_RELOC_390_TLS_GD32, /* ELF_SUFFIX_TLS_GD */ 1281 1.1 christos BFD_RELOC_390_TLS_GOTIE32, /* ELF_SUFFIX_TLS_GOTIE */ 1282 1.1 christos BFD_RELOC_390_TLS_IE32, /* ELF_SUFFIX_TLS_IE */ 1283 1.1 christos BFD_RELOC_390_TLS_LDM32, /* ELF_SUFFIX_TLS_LDM */ 1284 1.1 christos BFD_RELOC_390_TLS_LDO32, /* ELF_SUFFIX_TLS_LDO */ 1285 1.1 christos BFD_RELOC_390_TLS_LE32 /* ELF_SUFFIX_TLS_LE */ 1286 1.1 christos }; 1287 1.1 christos reloc = tab4[suffix]; 1288 1.1 christos } 1289 1.1 christos else if (nbytes == 8) 1290 1.1 christos { 1291 1.1 christos static bfd_reloc_code_real_type tab8[] = 1292 1.1 christos { 1293 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ 1294 1.1 christos BFD_RELOC_390_GOT64, /* ELF_SUFFIX_GOT */ 1295 1.1 christos BFD_RELOC_390_PLT64, /* ELF_SUFFIX_PLT */ 1296 1.1 christos BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ 1297 1.1 christos BFD_RELOC_390_GOTOFF64, /* ELF_SUFFIX_GOTOFF */ 1298 1.1 christos BFD_RELOC_390_GOTPLT64, /* ELF_SUFFIX_GOTPLT */ 1299 1.1 christos BFD_RELOC_390_PLTOFF64, /* ELF_SUFFIX_PLTOFF */ 1300 1.1 christos BFD_RELOC_390_TLS_GD64, /* ELF_SUFFIX_TLS_GD */ 1301 1.1 christos BFD_RELOC_390_TLS_GOTIE64, /* ELF_SUFFIX_TLS_GOTIE */ 1302 1.1 christos BFD_RELOC_390_TLS_IE64, /* ELF_SUFFIX_TLS_IE */ 1303 1.1 christos BFD_RELOC_390_TLS_LDM64, /* ELF_SUFFIX_TLS_LDM */ 1304 1.1 christos BFD_RELOC_390_TLS_LDO64, /* ELF_SUFFIX_TLS_LDO */ 1305 1.1 christos BFD_RELOC_390_TLS_LE64 /* ELF_SUFFIX_TLS_LE */ 1306 1.1 christos }; 1307 1.1 christos reloc = tab8[suffix]; 1308 1.1 christos } 1309 1.1 christos else 1310 1.1 christos reloc = BFD_RELOC_UNUSED; 1311 1.1 christos 1312 1.1 christos if (reloc != BFD_RELOC_UNUSED 1313 1.1 christos && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc))) 1314 1.1 christos { 1315 1.1 christos size = bfd_get_reloc_size (reloc_howto); 1316 1.1 christos if (size > nbytes) 1317 1.6 christos as_bad (ngettext ("%s relocations do not fit in %d byte", 1318 1.6 christos "%s relocations do not fit in %d bytes", 1319 1.6 christos nbytes), 1320 1.1 christos reloc_howto->name, nbytes); 1321 1.1 christos where = frag_more (nbytes); 1322 1.1 christos md_number_to_chars (where, 0, size); 1323 1.1 christos /* To make fixup_segment do the pc relative conversion the 1324 1.1 christos pcrel parameter on the fix_new_exp call needs to be FALSE. */ 1325 1.1 christos fix_new_exp (frag_now, where - frag_now->fr_literal, 1326 1.8 christos size, &exp, false, reloc); 1327 1.1 christos } 1328 1.1 christos else 1329 1.1 christos as_bad (_("relocation not applicable")); 1330 1.1 christos } 1331 1.1 christos else 1332 1.10 christos emit_expr (&exp, nbytes); 1333 1.1 christos } 1334 1.1 christos while (*input_line_pointer++ == ','); 1335 1.1 christos 1336 1.1 christos input_line_pointer--; /* Put terminator back into stream. */ 1337 1.1 christos demand_empty_rest_of_line (); 1338 1.1 christos } 1339 1.1 christos 1340 1.10 christos static const char * 1341 1.10 christos operand_type_str(const struct s390_operand * operand) 1342 1.10 christos { 1343 1.10 christos if (operand->flags & S390_OPERAND_BASE) 1344 1.10 christos return _("base register"); 1345 1.10 christos else if (operand->flags & S390_OPERAND_DISP) 1346 1.10 christos return _("displacement"); 1347 1.10 christos else if (operand->flags & S390_OPERAND_INDEX) 1348 1.10 christos { 1349 1.10 christos if (operand->flags & S390_OPERAND_VR) 1350 1.10 christos return _("vector index register"); 1351 1.10 christos else 1352 1.10 christos return _("index register"); 1353 1.10 christos } 1354 1.10 christos else if (operand->flags & S390_OPERAND_LENGTH) 1355 1.10 christos return _("length"); 1356 1.10 christos else if (operand->flags & S390_OPERAND_AR) 1357 1.10 christos return _("access register"); 1358 1.10 christos else if (operand->flags & S390_OPERAND_CR) 1359 1.10 christos return _("control register"); 1360 1.10 christos else if (operand->flags & S390_OPERAND_FPR) 1361 1.10 christos return _("floating-point register"); 1362 1.10 christos else if (operand->flags & S390_OPERAND_GPR) 1363 1.10 christos return _("general-purpose register"); 1364 1.10 christos else if (operand->flags & S390_OPERAND_VR) 1365 1.10 christos return _("vector register"); 1366 1.10 christos else 1367 1.10 christos { 1368 1.10 christos if (operand->flags & S390_OPERAND_SIGNED) 1369 1.10 christos return _("signed number"); 1370 1.10 christos else 1371 1.10 christos return _("unsigned number"); 1372 1.10 christos } 1373 1.10 christos } 1374 1.10 christos 1375 1.10 christos /* Return remaining operand count. */ 1376 1.10 christos 1377 1.10 christos static unsigned int 1378 1.10 christos operand_count (const unsigned char *opindex_ptr) 1379 1.10 christos { 1380 1.10 christos unsigned int count = 0; 1381 1.10 christos 1382 1.10 christos for (; *opindex_ptr != 0; opindex_ptr++) 1383 1.10 christos { 1384 1.10 christos /* Count D(X,B), D(B), and D(L,B) as one operand. Assuming correct 1385 1.10 christos instruction operand definitions simply do not count D, X, and L. */ 1386 1.10 christos if (!(s390_operands[*opindex_ptr].flags & (S390_OPERAND_DISP 1387 1.10 christos | S390_OPERAND_INDEX 1388 1.10 christos | S390_OPERAND_LENGTH))) 1389 1.10 christos count++; 1390 1.10 christos } 1391 1.10 christos 1392 1.10 christos return count; 1393 1.10 christos } 1394 1.10 christos 1395 1.10 christos /* Return true if all remaining instruction operands are optional. */ 1396 1.10 christos 1397 1.8 christos static bool 1398 1.7 christos skip_optargs_p (unsigned int opcode_flags, const unsigned char *opindex_ptr) 1399 1.7 christos { 1400 1.10 christos if ((opcode_flags & (S390_INSTR_FLAG_OPTPARM | S390_INSTR_FLAG_OPTPARM2))) 1401 1.10 christos { 1402 1.10 christos unsigned int opcount = operand_count (opindex_ptr); 1403 1.10 christos 1404 1.10 christos if (opcount == 1) 1405 1.10 christos return true; 1406 1.10 christos 1407 1.10 christos if ((opcode_flags & S390_INSTR_FLAG_OPTPARM2) && opcount == 2) 1408 1.10 christos return true; 1409 1.10 christos } 1410 1.10 christos 1411 1.8 christos return false; 1412 1.7 christos } 1413 1.7 christos 1414 1.1 christos /* We need to keep a list of fixups. We can't simply generate them as 1415 1.1 christos we go, because that would require us to first create the frag, and 1416 1.1 christos that would screw up references to ``.''. */ 1417 1.1 christos 1418 1.1 christos struct s390_fixup 1419 1.1 christos { 1420 1.1 christos expressionS exp; 1421 1.1 christos int opindex; 1422 1.1 christos bfd_reloc_code_real_type reloc; 1423 1.1 christos }; 1424 1.1 christos 1425 1.1 christos #define MAX_INSN_FIXUPS (4) 1426 1.1 christos 1427 1.1 christos /* This routine is called for each instruction to be assembled. */ 1428 1.1 christos 1429 1.1 christos static char * 1430 1.1 christos md_gather_operands (char *str, 1431 1.1 christos unsigned char *insn, 1432 1.1 christos const struct s390_opcode *opcode) 1433 1.1 christos { 1434 1.1 christos struct s390_fixup fixups[MAX_INSN_FIXUPS]; 1435 1.1 christos const struct s390_operand *operand; 1436 1.1 christos const unsigned char *opindex_ptr; 1437 1.1 christos expressionS ex; 1438 1.1 christos elf_suffix_type suffix; 1439 1.1 christos bfd_reloc_code_real_type reloc; 1440 1.10 christos int omitted_index; 1441 1.10 christos int operand_number; 1442 1.1 christos char *f; 1443 1.1 christos int fc, i; 1444 1.1 christos 1445 1.10 christos while (is_whitespace (*str)) 1446 1.1 christos str++; 1447 1.1 christos 1448 1.1 christos /* Gather the operands. */ 1449 1.10 christos omitted_index = 0; /* Whether X in D(X,B) was omitted. */ 1450 1.10 christos operand_number = 1; /* Current operand number in e.g. R1,I2,M3,D4(B4). */ 1451 1.1 christos fc = 0; 1452 1.1 christos for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) 1453 1.1 christos { 1454 1.1 christos char *hold; 1455 1.1 christos 1456 1.1 christos operand = s390_operands + *opindex_ptr; 1457 1.1 christos 1458 1.10 christos if (*str == '\0' && skip_optargs_p (opcode->flags, opindex_ptr)) 1459 1.3 christos { 1460 1.3 christos /* Optional parameters might need to be ORed with a 1461 1.3 christos value so calling s390_insert_operand is needed. */ 1462 1.10 christos s390_insert_operand (insn, operand, 0, NULL, 0, operand_number); 1463 1.3 christos break; 1464 1.3 christos } 1465 1.3 christos 1466 1.10 christos if (omitted_index && (operand->flags & S390_OPERAND_INDEX)) 1467 1.1 christos { 1468 1.10 christos /* Do not skip an omitted vector index register in D(VX,B). */ 1469 1.10 christos if (operand->flags & S390_OPERAND_VR) 1470 1.10 christos as_bad (_("operand %d: missing vector index register operand"), 1471 1.10 christos operand_number); 1472 1.10 christos 1473 1.10 christos /* Skip omitted optional index register operand in D(X,B) due to 1474 1.10 christos D(,B) or D(B). Skip comma, if D(,B). */ 1475 1.10 christos if (*str == ',') 1476 1.10 christos str++; 1477 1.10 christos omitted_index = 0; 1478 1.1 christos continue; 1479 1.1 christos } 1480 1.1 christos 1481 1.1 christos /* Gather the operand. */ 1482 1.1 christos hold = input_line_pointer; 1483 1.1 christos input_line_pointer = str; 1484 1.1 christos 1485 1.1 christos /* Parse the operand. */ 1486 1.1 christos if (! register_name (&ex)) 1487 1.9 christos { 1488 1.9 christos expression (&ex); 1489 1.9 christos resolve_register (&ex); 1490 1.9 christos } 1491 1.1 christos 1492 1.1 christos str = input_line_pointer; 1493 1.1 christos input_line_pointer = hold; 1494 1.1 christos 1495 1.1 christos /* Write the operand to the insn. */ 1496 1.1 christos if (ex.X_op == O_illegal) 1497 1.10 christos as_bad (_("operand %d: illegal operand"), operand_number); 1498 1.1 christos else if (ex.X_op == O_absent) 1499 1.1 christos { 1500 1.1 christos if (opindex_ptr[0] == '\0') 1501 1.1 christos break; 1502 1.10 christos as_bad (_("operand %d: missing %s operand"), operand_number, 1503 1.10 christos operand_type_str(operand)); 1504 1.1 christos } 1505 1.1 christos else if (ex.X_op == O_register || ex.X_op == O_constant) 1506 1.1 christos { 1507 1.1 christos s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE); 1508 1.1 christos 1509 1.1 christos if (ex.X_op != O_register && ex.X_op != O_constant) 1510 1.1 christos { 1511 1.1 christos /* We need to generate a fixup for the 1512 1.1 christos expression returned by s390_lit_suffix. */ 1513 1.1 christos if (fc >= MAX_INSN_FIXUPS) 1514 1.10 christos as_fatal (_("operand %d: too many fixups"), operand_number); 1515 1.1 christos fixups[fc].exp = ex; 1516 1.1 christos fixups[fc].opindex = *opindex_ptr; 1517 1.1 christos fixups[fc].reloc = BFD_RELOC_UNUSED; 1518 1.1 christos ++fc; 1519 1.1 christos } 1520 1.1 christos else 1521 1.1 christos { 1522 1.3 christos if ((operand->flags & S390_OPERAND_LENGTH) 1523 1.3 christos && ex.X_op != O_constant) 1524 1.10 christos as_bad (_("operand %d: invalid length field specified"), 1525 1.10 christos operand_number); 1526 1.1 christos if ((operand->flags & S390_OPERAND_INDEX) 1527 1.10 christos && !(operand->flags & S390_OPERAND_VR) 1528 1.1 christos && ex.X_add_number == 0 1529 1.1 christos && warn_areg_zero) 1530 1.10 christos as_warn (_("operand %d: index register specified but zero"), 1531 1.10 christos operand_number); 1532 1.1 christos if ((operand->flags & S390_OPERAND_BASE) 1533 1.1 christos && ex.X_add_number == 0 1534 1.1 christos && warn_areg_zero) 1535 1.10 christos as_warn (_("operand %d: base register specified but zero"), 1536 1.10 christos operand_number); 1537 1.1 christos if ((operand->flags & S390_OPERAND_GPR) 1538 1.1 christos && (operand->flags & S390_OPERAND_REG_PAIR) 1539 1.1 christos && (ex.X_add_number & 1)) 1540 1.10 christos as_bad (_("operand %d: odd numbered general purpose register " 1541 1.10 christos "specified as register pair"), operand_number); 1542 1.1 christos if ((operand->flags & S390_OPERAND_FPR) 1543 1.1 christos && (operand->flags & S390_OPERAND_REG_PAIR) 1544 1.1 christos && ex.X_add_number != 0 && ex.X_add_number != 1 1545 1.1 christos && ex.X_add_number != 4 && ex.X_add_number != 5 1546 1.1 christos && ex.X_add_number != 8 && ex.X_add_number != 9 1547 1.1 christos && ex.X_add_number != 12 && ex.X_add_number != 13) 1548 1.10 christos as_bad (_("operand %d: invalid floating-point register (FPR) " 1549 1.10 christos "pair (valid FPR pair operands are 0, 1, 4, 5, 8, 9, " 1550 1.10 christos "12 or 13)"), operand_number); 1551 1.10 christos if (warn_regtype_mismatch && ex.X_op == O_register 1552 1.10 christos && !(opcode->flags & S390_INSTR_FLAG_PSEUDO_MNEMONIC)) 1553 1.10 christos { 1554 1.10 christos const char *expected_regtype = NULL; 1555 1.10 christos 1556 1.10 christos if ((operand->flags & S390_OPERAND_AR) 1557 1.10 christos && ex.X_md != S390_REGTYPE_AR) 1558 1.10 christos expected_regtype = _("access register"); 1559 1.10 christos else if ((operand->flags & S390_OPERAND_CR) 1560 1.10 christos && ex.X_md != S390_REGTYPE_CR) 1561 1.10 christos expected_regtype = _("control register"); 1562 1.10 christos else if ((operand->flags & S390_OPERAND_FPR) 1563 1.10 christos && ex.X_md != S390_REGTYPE_FPR 1564 1.10 christos && (warn_regtype_mismatch == S390_REGTYPE_CHECK_STRICT 1565 1.10 christos || (ex.X_md != S390_REGTYPE_VR))) 1566 1.10 christos expected_regtype = _("floating-point register"); 1567 1.10 christos else if ((operand->flags & S390_OPERAND_GPR) 1568 1.10 christos && ex.X_md != S390_REGTYPE_GR) 1569 1.10 christos expected_regtype = _("general register"); 1570 1.10 christos else if ((operand->flags & S390_OPERAND_VR) 1571 1.10 christos && ex.X_md != S390_REGTYPE_VR 1572 1.10 christos && (warn_regtype_mismatch == S390_REGTYPE_CHECK_STRICT 1573 1.10 christos || (ex.X_md != S390_REGTYPE_FPR))) 1574 1.10 christos expected_regtype = _("vector register"); 1575 1.10 christos 1576 1.10 christos if (expected_regtype) 1577 1.10 christos { 1578 1.10 christos if (operand->flags & S390_OPERAND_BASE) 1579 1.10 christos as_warn (_("operand %d: expected %s name as base register"), 1580 1.10 christos operand_number, expected_regtype); 1581 1.10 christos else if (operand->flags & S390_OPERAND_INDEX) 1582 1.10 christos as_warn (_("operand %d: expected %s name as index register"), 1583 1.10 christos operand_number, expected_regtype); 1584 1.10 christos else 1585 1.10 christos as_warn (_("operand %d: expected %s name"), 1586 1.10 christos operand_number, expected_regtype); 1587 1.10 christos } 1588 1.10 christos } 1589 1.10 christos s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0, operand_number); 1590 1.1 christos } 1591 1.1 christos } 1592 1.1 christos else 1593 1.1 christos { 1594 1.1 christos suffix = s390_elf_suffix (&str, &ex); 1595 1.1 christos suffix = s390_lit_suffix (&str, &ex, suffix); 1596 1.1 christos reloc = BFD_RELOC_UNUSED; 1597 1.1 christos 1598 1.1 christos if (suffix == ELF_SUFFIX_GOT) 1599 1.1 christos { 1600 1.1 christos if ((operand->flags & S390_OPERAND_DISP) && 1601 1.1 christos (operand->bits == 12)) 1602 1.1 christos reloc = BFD_RELOC_390_GOT12; 1603 1.1 christos else if ((operand->flags & S390_OPERAND_DISP) && 1604 1.1 christos (operand->bits == 20)) 1605 1.1 christos reloc = BFD_RELOC_390_GOT20; 1606 1.1 christos else if ((operand->flags & S390_OPERAND_SIGNED) 1607 1.1 christos && (operand->bits == 16)) 1608 1.1 christos reloc = BFD_RELOC_390_GOT16; 1609 1.1 christos else if ((operand->flags & S390_OPERAND_PCREL) 1610 1.1 christos && (operand->bits == 32)) 1611 1.1 christos reloc = BFD_RELOC_390_GOTENT; 1612 1.1 christos } 1613 1.1 christos else if (suffix == ELF_SUFFIX_PLT) 1614 1.1 christos { 1615 1.1 christos if ((operand->flags & S390_OPERAND_PCREL) 1616 1.3 christos && (operand->bits == 12)) 1617 1.3 christos reloc = BFD_RELOC_390_PLT12DBL; 1618 1.3 christos else if ((operand->flags & S390_OPERAND_PCREL) 1619 1.3 christos && (operand->bits == 16)) 1620 1.1 christos reloc = BFD_RELOC_390_PLT16DBL; 1621 1.1 christos else if ((operand->flags & S390_OPERAND_PCREL) 1622 1.3 christos && (operand->bits == 24)) 1623 1.3 christos reloc = BFD_RELOC_390_PLT24DBL; 1624 1.3 christos else if ((operand->flags & S390_OPERAND_PCREL) 1625 1.1 christos && (operand->bits == 32)) 1626 1.1 christos reloc = BFD_RELOC_390_PLT32DBL; 1627 1.1 christos } 1628 1.1 christos else if (suffix == ELF_SUFFIX_GOTENT) 1629 1.1 christos { 1630 1.1 christos if ((operand->flags & S390_OPERAND_PCREL) 1631 1.1 christos && (operand->bits == 32)) 1632 1.1 christos reloc = BFD_RELOC_390_GOTENT; 1633 1.1 christos } 1634 1.1 christos else if (suffix == ELF_SUFFIX_GOTOFF) 1635 1.1 christos { 1636 1.1 christos if ((operand->flags & S390_OPERAND_SIGNED) 1637 1.1 christos && (operand->bits == 16)) 1638 1.1 christos reloc = BFD_RELOC_16_GOTOFF; 1639 1.1 christos } 1640 1.1 christos else if (suffix == ELF_SUFFIX_PLTOFF) 1641 1.1 christos { 1642 1.1 christos if ((operand->flags & S390_OPERAND_SIGNED) 1643 1.1 christos && (operand->bits == 16)) 1644 1.1 christos reloc = BFD_RELOC_390_PLTOFF16; 1645 1.1 christos } 1646 1.1 christos else if (suffix == ELF_SUFFIX_GOTPLT) 1647 1.1 christos { 1648 1.1 christos if ((operand->flags & S390_OPERAND_DISP) 1649 1.1 christos && (operand->bits == 12)) 1650 1.1 christos reloc = BFD_RELOC_390_GOTPLT12; 1651 1.1 christos else if ((operand->flags & S390_OPERAND_SIGNED) 1652 1.1 christos && (operand->bits == 16)) 1653 1.1 christos reloc = BFD_RELOC_390_GOTPLT16; 1654 1.1 christos else if ((operand->flags & S390_OPERAND_PCREL) 1655 1.1 christos && (operand->bits == 32)) 1656 1.1 christos reloc = BFD_RELOC_390_GOTPLTENT; 1657 1.1 christos } 1658 1.1 christos else if (suffix == ELF_SUFFIX_TLS_GOTIE) 1659 1.1 christos { 1660 1.1 christos if ((operand->flags & S390_OPERAND_DISP) 1661 1.1 christos && (operand->bits == 12)) 1662 1.1 christos reloc = BFD_RELOC_390_TLS_GOTIE12; 1663 1.1 christos else if ((operand->flags & S390_OPERAND_DISP) 1664 1.1 christos && (operand->bits == 20)) 1665 1.1 christos reloc = BFD_RELOC_390_TLS_GOTIE20; 1666 1.1 christos } 1667 1.1 christos else if (suffix == ELF_SUFFIX_TLS_IE) 1668 1.1 christos { 1669 1.1 christos if ((operand->flags & S390_OPERAND_PCREL) 1670 1.1 christos && (operand->bits == 32)) 1671 1.1 christos reloc = BFD_RELOC_390_TLS_IEENT; 1672 1.1 christos } 1673 1.1 christos 1674 1.1 christos if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) 1675 1.10 christos as_bad (_("operand %d: invalid operand suffix"), operand_number); 1676 1.1 christos /* We need to generate a fixup of type 'reloc' for this 1677 1.1 christos expression. */ 1678 1.1 christos if (fc >= MAX_INSN_FIXUPS) 1679 1.10 christos as_fatal (_("operand %d: too many fixups"), operand_number); 1680 1.1 christos fixups[fc].exp = ex; 1681 1.1 christos fixups[fc].opindex = *opindex_ptr; 1682 1.1 christos fixups[fc].reloc = reloc; 1683 1.1 christos ++fc; 1684 1.1 christos } 1685 1.1 christos 1686 1.1 christos /* Check the next character. The call to expression has advanced 1687 1.1 christos str past any whitespace. */ 1688 1.1 christos if (operand->flags & S390_OPERAND_DISP) 1689 1.1 christos { 1690 1.1 christos /* After a displacement a block in parentheses can start. */ 1691 1.1 christos if (*str != '(') 1692 1.1 christos { 1693 1.10 christos /* There is no opening parentheses. Check if operands of 1694 1.10 christos parenthesized block can be skipped. Only index and base 1695 1.10 christos register operands as well as optional operands may be 1696 1.10 christos skipped. Neither vector index nor length operands may 1697 1.10 christos be skipped. */ 1698 1.1 christos operand = s390_operands + *(++opindex_ptr); 1699 1.10 christos if (!(((operand->flags & S390_OPERAND_INDEX) && 1700 1.10 christos !(operand->flags & S390_OPERAND_VR)) 1701 1.10 christos || (operand->flags & S390_OPERAND_BASE))) 1702 1.10 christos as_bad (_("operand %d: syntax error; missing '(' after displacement"), 1703 1.10 christos operand_number); 1704 1.1 christos 1705 1.1 christos /* Ok, skip all operands until S390_OPERAND_BASE. */ 1706 1.1 christos while (!(operand->flags & S390_OPERAND_BASE)) 1707 1.1 christos operand = s390_operands + *(++opindex_ptr); 1708 1.1 christos 1709 1.10 christos /* If there is no further input and the remaining operands are 1710 1.10 christos optional then have these optional operands processed. */ 1711 1.7 christos if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1])) 1712 1.7 christos continue; 1713 1.7 christos 1714 1.1 christos /* If there is a next operand it must be separated by a comma. */ 1715 1.1 christos if (opindex_ptr[1] != '\0') 1716 1.1 christos { 1717 1.1 christos if (*str != ',') 1718 1.1 christos { 1719 1.10 christos /* There is no comma. Skip all operands and stop. */ 1720 1.1 christos while (opindex_ptr[1] != '\0') 1721 1.1 christos { 1722 1.1 christos operand = s390_operands + *(++opindex_ptr); 1723 1.10 christos as_bad (_("operand %d: syntax error; expected ','"), 1724 1.10 christos operand_number); 1725 1.1 christos break; 1726 1.1 christos } 1727 1.1 christos } 1728 1.1 christos else 1729 1.10 christos { 1730 1.10 christos /* Comma. */ 1731 1.10 christos str++; 1732 1.10 christos operand_number++; 1733 1.10 christos } 1734 1.1 christos } 1735 1.1 christos } 1736 1.1 christos else 1737 1.1 christos { 1738 1.1 christos /* We found an opening parentheses. */ 1739 1.1 christos str++; 1740 1.1 christos for (f = str; *f != '\0'; f++) 1741 1.1 christos if (*f == ',' || *f == ')') 1742 1.1 christos break; 1743 1.10 christos /* If there is no comma until the closing parenthesis ')' or 1744 1.10 christos there is a comma right after the opening parenthesis '(', 1745 1.10 christos we have to skip an omitted optional index register 1746 1.10 christos operand X in D(X,B), when D(,B) or D(B). */ 1747 1.10 christos omitted_index = ((*f == ',' && f == str) || (*f == ')')); 1748 1.1 christos } 1749 1.1 christos } 1750 1.1 christos else if (operand->flags & S390_OPERAND_BASE) 1751 1.1 christos { 1752 1.6 christos /* After the base register the parenthesised block ends. */ 1753 1.10 christos if (*str != ')') 1754 1.10 christos as_bad (_("operand %d: syntax error; missing ')' after base register"), 1755 1.10 christos operand_number); 1756 1.10 christos else 1757 1.10 christos str++; 1758 1.10 christos omitted_index = 0; 1759 1.7 christos 1760 1.10 christos /* If there is no further input and the remaining operands are 1761 1.10 christos optional then have these optional operands processed. */ 1762 1.7 christos if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1])) 1763 1.7 christos continue; 1764 1.7 christos 1765 1.1 christos /* If there is a next operand it must be separated by a comma. */ 1766 1.1 christos if (opindex_ptr[1] != '\0') 1767 1.1 christos { 1768 1.1 christos if (*str != ',') 1769 1.1 christos { 1770 1.10 christos /* There is no comma. Skip all operands and stop. */ 1771 1.1 christos while (opindex_ptr[1] != '\0') 1772 1.1 christos { 1773 1.1 christos operand = s390_operands + *(++opindex_ptr); 1774 1.10 christos as_bad (_("operand %d: syntax error; expected ','"), 1775 1.10 christos operand_number); 1776 1.1 christos break; 1777 1.1 christos } 1778 1.1 christos } 1779 1.1 christos else 1780 1.10 christos { 1781 1.10 christos /* Comma. */ 1782 1.10 christos str++; 1783 1.10 christos operand_number++; 1784 1.10 christos } 1785 1.1 christos } 1786 1.1 christos } 1787 1.1 christos else 1788 1.1 christos { 1789 1.1 christos /* We can find an 'early' closing parentheses in e.g. D(L) instead 1790 1.10 christos of D(L,B). In this case the base register has to be skipped. 1791 1.10 christos Same if the base register has been explicilty omitted in e.g. 1792 1.10 christos D(X,) or D(L,). */ 1793 1.10 christos if (*str == ')' || (str[0] == ',' && str[1] == ')')) 1794 1.1 christos { 1795 1.1 christos operand = s390_operands + *(++opindex_ptr); 1796 1.1 christos 1797 1.1 christos if (!(operand->flags & S390_OPERAND_BASE)) 1798 1.10 christos as_bad (_("operand %d: syntax error; '%c' not allowed here"), 1799 1.10 christos operand_number, *str); 1800 1.10 christos if (*str == ',') 1801 1.10 christos str++; 1802 1.1 christos str++; 1803 1.1 christos } 1804 1.3 christos 1805 1.10 christos /* If there is no further input and the remaining operands are 1806 1.10 christos optional then have these optional operands processed. */ 1807 1.7 christos if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1])) 1808 1.3 christos continue; 1809 1.3 christos 1810 1.1 christos /* If there is a next operand it must be separated by a comma. */ 1811 1.1 christos if (opindex_ptr[1] != '\0') 1812 1.1 christos { 1813 1.1 christos if (*str != ',') 1814 1.1 christos { 1815 1.10 christos /* There is no comma. Skip all operands and stop. */ 1816 1.1 christos while (opindex_ptr[1] != '\0') 1817 1.1 christos { 1818 1.1 christos operand = s390_operands + *(++opindex_ptr); 1819 1.10 christos as_bad (_("operand %d: syntax error; expected ','"), 1820 1.10 christos operand_number); 1821 1.1 christos break; 1822 1.1 christos } 1823 1.1 christos } 1824 1.1 christos else 1825 1.10 christos { 1826 1.10 christos /* Comma. */ 1827 1.10 christos str++; 1828 1.10 christos if (!(operand->flags & (S390_OPERAND_INDEX 1829 1.10 christos | S390_OPERAND_LENGTH))) 1830 1.10 christos operand_number++; 1831 1.10 christos } 1832 1.1 christos } 1833 1.1 christos } 1834 1.1 christos } 1835 1.1 christos 1836 1.10 christos while (is_whitespace (*str)) 1837 1.10 christos str++; 1838 1.1 christos 1839 1.1 christos /* Check for tls instruction marker. */ 1840 1.1 christos reloc = s390_tls_suffix (&str, &ex); 1841 1.1 christos if (reloc != BFD_RELOC_UNUSED) 1842 1.1 christos { 1843 1.1 christos /* We need to generate a fixup of type 'reloc' for this 1844 1.1 christos instruction. */ 1845 1.1 christos if (fc >= MAX_INSN_FIXUPS) 1846 1.1 christos as_fatal (_("too many fixups")); 1847 1.1 christos fixups[fc].exp = ex; 1848 1.1 christos fixups[fc].opindex = -1; 1849 1.1 christos fixups[fc].reloc = reloc; 1850 1.1 christos ++fc; 1851 1.1 christos } 1852 1.1 christos 1853 1.1 christos if (*str != '\0') 1854 1.1 christos { 1855 1.1 christos char *linefeed; 1856 1.1 christos 1857 1.1 christos if ((linefeed = strchr (str, '\n')) != NULL) 1858 1.1 christos *linefeed = '\0'; 1859 1.1 christos as_bad (_("junk at end of line: `%s'"), str); 1860 1.1 christos if (linefeed != NULL) 1861 1.1 christos *linefeed = '\n'; 1862 1.1 christos } 1863 1.1 christos 1864 1.1 christos /* Write out the instruction. */ 1865 1.1 christos f = frag_more (opcode->oplen); 1866 1.1 christos memcpy (f, insn, opcode->oplen); 1867 1.1 christos dwarf2_emit_insn (opcode->oplen); 1868 1.1 christos 1869 1.1 christos /* Create any fixups. At this point we do not use a 1870 1.1 christos bfd_reloc_code_real_type, but instead just use the 1871 1.1 christos BFD_RELOC_UNUSED plus the operand index. This lets us easily 1872 1.1 christos handle fixups for any operand type, although that is admittedly 1873 1.1 christos not a very exciting feature. We pick a BFD reloc type in 1874 1.1 christos md_apply_fix. */ 1875 1.1 christos for (i = 0; i < fc; i++) 1876 1.1 christos { 1877 1.8 christos fixS *fixP; 1878 1.1 christos 1879 1.1 christos if (fixups[i].opindex < 0) 1880 1.1 christos { 1881 1.1 christos /* Create tls instruction marker relocation. */ 1882 1.1 christos fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen, 1883 1.1 christos &fixups[i].exp, 0, fixups[i].reloc); 1884 1.1 christos continue; 1885 1.1 christos } 1886 1.1 christos 1887 1.1 christos operand = s390_operands + fixups[i].opindex; 1888 1.1 christos 1889 1.1 christos if (fixups[i].reloc != BFD_RELOC_UNUSED) 1890 1.1 christos { 1891 1.1 christos reloc_howto_type *reloc_howto; 1892 1.1 christos int size; 1893 1.1 christos 1894 1.1 christos reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc); 1895 1.1 christos if (!reloc_howto) 1896 1.1 christos abort (); 1897 1.1 christos 1898 1.3 christos size = ((reloc_howto->bitsize - 1) / 8) + 1; 1899 1.1 christos 1900 1.1 christos if (size < 1 || size > 4) 1901 1.1 christos abort (); 1902 1.1 christos 1903 1.1 christos fixP = fix_new_exp (frag_now, 1904 1.1 christos f - frag_now->fr_literal + (operand->shift/8), 1905 1.1 christos size, &fixups[i].exp, reloc_howto->pc_relative, 1906 1.1 christos fixups[i].reloc); 1907 1.1 christos /* Turn off overflow checking in fixup_segment. This is necessary 1908 1.1 christos because fixup_segment will signal an overflow for large 4 byte 1909 1.1 christos quantities for GOT12 relocations. */ 1910 1.1 christos if ( fixups[i].reloc == BFD_RELOC_390_GOT12 1911 1.1 christos || fixups[i].reloc == BFD_RELOC_390_GOT20 1912 1.1 christos || fixups[i].reloc == BFD_RELOC_390_GOT16) 1913 1.1 christos fixP->fx_no_overflow = 1; 1914 1.6 christos 1915 1.6 christos if (operand->flags & S390_OPERAND_PCREL) 1916 1.6 christos fixP->fx_pcrel_adjust = operand->shift / 8; 1917 1.1 christos } 1918 1.1 christos else 1919 1.8 christos fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, 4, 1920 1.8 christos &fixups[i].exp, 1921 1.8 christos (operand->flags & S390_OPERAND_PCREL) != 0, 1922 1.10 christos fixups[i].opindex + BFD_RELOC_UNUSED); 1923 1.8 christos /* s390_insert_operand () does the range checking. */ 1924 1.8 christos if (operand->flags & S390_OPERAND_PCREL) 1925 1.8 christos fixP->fx_no_overflow = 1; 1926 1.1 christos } 1927 1.1 christos return str; 1928 1.1 christos } 1929 1.1 christos 1930 1.1 christos /* This routine is called for each instruction to be assembled. */ 1931 1.1 christos 1932 1.1 christos void 1933 1.1 christos md_assemble (char *str) 1934 1.1 christos { 1935 1.1 christos const struct s390_opcode *opcode; 1936 1.1 christos unsigned char insn[6]; 1937 1.1 christos char *s; 1938 1.1 christos 1939 1.1 christos /* Get the opcode. */ 1940 1.10 christos for (s = str; ! is_end_of_stmt (*s) && ! is_whitespace (*s); s++) 1941 1.1 christos ; 1942 1.1 christos if (*s != '\0') 1943 1.1 christos *s++ = '\0'; 1944 1.1 christos 1945 1.1 christos /* Look up the opcode in the hash table. */ 1946 1.10 christos opcode = str_hash_find (s390_opcode_hash, str); 1947 1.10 christos if (opcode == NULL) 1948 1.1 christos { 1949 1.1 christos as_bad (_("Unrecognized opcode: `%s'"), str); 1950 1.1 christos return; 1951 1.1 christos } 1952 1.1 christos else if (!(opcode->modes & current_mode_mask)) 1953 1.1 christos { 1954 1.1 christos as_bad (_("Opcode %s not available in this mode"), str); 1955 1.1 christos return; 1956 1.1 christos } 1957 1.1 christos memcpy (insn, opcode->opcode, sizeof (insn)); 1958 1.1 christos md_gather_operands (s, insn, opcode); 1959 1.1 christos } 1960 1.1 christos 1961 1.1 christos #ifndef WORKING_DOT_WORD 1962 1.1 christos /* Handle long and short jumps. We don't support these */ 1963 1.1 christos void 1964 1.1 christos md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol) 1965 1.1 christos char *ptr; 1966 1.1 christos addressT from_addr, to_addr; 1967 1.1 christos fragS *frag; 1968 1.1 christos symbolS *to_symbol; 1969 1.1 christos { 1970 1.1 christos abort (); 1971 1.1 christos } 1972 1.1 christos 1973 1.1 christos void 1974 1.1 christos md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol) 1975 1.1 christos char *ptr; 1976 1.1 christos addressT from_addr, to_addr; 1977 1.1 christos fragS *frag; 1978 1.1 christos symbolS *to_symbol; 1979 1.1 christos { 1980 1.1 christos abort (); 1981 1.1 christos } 1982 1.1 christos #endif 1983 1.1 christos 1984 1.1 christos /* Pseudo-op handling. */ 1985 1.1 christos 1986 1.1 christos void 1987 1.1 christos s390_insn (int ignore ATTRIBUTE_UNUSED) 1988 1.1 christos { 1989 1.1 christos expressionS exp; 1990 1.1 christos const struct s390_opcode *opformat; 1991 1.1 christos unsigned char insn[6]; 1992 1.1 christos char *s; 1993 1.1 christos 1994 1.1 christos /* Get the opcode format. */ 1995 1.1 christos s = input_line_pointer; 1996 1.10 christos while (! is_end_of_stmt (*s) && *s != ',' && ! is_whitespace (*s)) 1997 1.1 christos s++; 1998 1.1 christos if (*s != ',') 1999 1.1 christos as_bad (_("Invalid .insn format\n")); 2000 1.1 christos *s++ = '\0'; 2001 1.1 christos 2002 1.1 christos /* Look up the opcode in the hash table. */ 2003 1.10 christos opformat = str_hash_find (s390_opformat_hash, input_line_pointer); 2004 1.10 christos if (opformat == NULL) 2005 1.1 christos { 2006 1.1 christos as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer); 2007 1.1 christos return; 2008 1.1 christos } 2009 1.1 christos input_line_pointer = s; 2010 1.1 christos expression (&exp); 2011 1.1 christos if (exp.X_op == O_constant) 2012 1.1 christos { 2013 1.1 christos if ( ( opformat->oplen == 6 2014 1.1 christos && (addressT) exp.X_add_number < (1ULL << 48)) 2015 1.1 christos || ( opformat->oplen == 4 2016 1.1 christos && (addressT) exp.X_add_number < (1ULL << 32)) 2017 1.1 christos || ( opformat->oplen == 2 2018 1.1 christos && (addressT) exp.X_add_number < (1ULL << 16))) 2019 1.1 christos md_number_to_chars ((char *) insn, exp.X_add_number, opformat->oplen); 2020 1.1 christos else 2021 1.1 christos as_bad (_("Invalid .insn format\n")); 2022 1.1 christos } 2023 1.1 christos else if (exp.X_op == O_big) 2024 1.1 christos { 2025 1.1 christos if (exp.X_add_number > 0 2026 1.1 christos && opformat->oplen == 6 2027 1.1 christos && generic_bignum[3] == 0) 2028 1.1 christos { 2029 1.1 christos md_number_to_chars ((char *) insn, generic_bignum[2], 2); 2030 1.1 christos md_number_to_chars ((char *) &insn[2], generic_bignum[1], 2); 2031 1.1 christos md_number_to_chars ((char *) &insn[4], generic_bignum[0], 2); 2032 1.1 christos } 2033 1.1 christos else 2034 1.1 christos as_bad (_("Invalid .insn format\n")); 2035 1.1 christos } 2036 1.1 christos else 2037 1.1 christos as_bad (_("second operand of .insn not a constant\n")); 2038 1.1 christos 2039 1.1 christos if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',') 2040 1.1 christos as_bad (_("missing comma after insn constant\n")); 2041 1.1 christos 2042 1.1 christos if ((s = strchr (input_line_pointer, '\n')) != NULL) 2043 1.1 christos *s = '\0'; 2044 1.1 christos input_line_pointer = md_gather_operands (input_line_pointer, insn, 2045 1.1 christos opformat); 2046 1.1 christos if (s != NULL) 2047 1.1 christos *s = '\n'; 2048 1.1 christos demand_empty_rest_of_line (); 2049 1.1 christos } 2050 1.1 christos 2051 1.1 christos /* The .byte pseudo-op. This is similar to the normal .byte 2052 1.1 christos pseudo-op, but it can also take a single ASCII string. */ 2053 1.1 christos 2054 1.1 christos static void 2055 1.1 christos s390_byte (int ignore ATTRIBUTE_UNUSED) 2056 1.1 christos { 2057 1.1 christos if (*input_line_pointer != '\"') 2058 1.1 christos { 2059 1.1 christos cons (1); 2060 1.1 christos return; 2061 1.1 christos } 2062 1.1 christos 2063 1.1 christos /* Gather characters. A real double quote is doubled. Unusual 2064 1.1 christos characters are not permitted. */ 2065 1.1 christos ++input_line_pointer; 2066 1.1 christos while (1) 2067 1.1 christos { 2068 1.1 christos char c; 2069 1.1 christos 2070 1.1 christos c = *input_line_pointer++; 2071 1.1 christos 2072 1.1 christos if (c == '\"') 2073 1.1 christos { 2074 1.1 christos if (*input_line_pointer != '\"') 2075 1.1 christos break; 2076 1.1 christos ++input_line_pointer; 2077 1.1 christos } 2078 1.1 christos 2079 1.1 christos FRAG_APPEND_1_CHAR (c); 2080 1.1 christos } 2081 1.1 christos 2082 1.1 christos demand_empty_rest_of_line (); 2083 1.1 christos } 2084 1.1 christos 2085 1.1 christos /* The .ltorg pseudo-op.This emits all literals defined since the last 2086 1.1 christos .ltorg or the invocation of gas. Literals are defined with the 2087 1.1 christos @lit suffix. */ 2088 1.1 christos 2089 1.1 christos static void 2090 1.1 christos s390_literals (int ignore ATTRIBUTE_UNUSED) 2091 1.1 christos { 2092 1.1 christos struct s390_lpe *lpe; 2093 1.1 christos 2094 1.1 christos if (lp_sym == NULL || lpe_count == 0) 2095 1.1 christos return; /* Nothing to be done. */ 2096 1.1 christos 2097 1.1 christos /* Emit symbol for start of literal pool. */ 2098 1.1 christos S_SET_SEGMENT (lp_sym, now_seg); 2099 1.10 christos S_SET_VALUE (lp_sym, frag_now_fix ()); 2100 1.7 christos symbol_set_frag (lp_sym, frag_now); 2101 1.1 christos 2102 1.1 christos while (lpe_list) 2103 1.1 christos { 2104 1.1 christos lpe = lpe_list; 2105 1.1 christos lpe_list = lpe_list->next; 2106 1.1 christos S_SET_SEGMENT (lpe->sym, now_seg); 2107 1.10 christos S_SET_VALUE (lpe->sym, frag_now_fix ()); 2108 1.7 christos symbol_set_frag (lpe->sym, frag_now); 2109 1.1 christos 2110 1.1 christos /* Emit literal pool entry. */ 2111 1.1 christos if (lpe->reloc != BFD_RELOC_UNUSED) 2112 1.1 christos { 2113 1.1 christos reloc_howto_type *reloc_howto = 2114 1.1 christos bfd_reloc_type_lookup (stdoutput, lpe->reloc); 2115 1.1 christos int size = bfd_get_reloc_size (reloc_howto); 2116 1.1 christos char *where; 2117 1.1 christos 2118 1.1 christos if (size > lpe->nbytes) 2119 1.6 christos as_bad (ngettext ("%s relocations do not fit in %d byte", 2120 1.6 christos "%s relocations do not fit in %d bytes", 2121 1.6 christos lpe->nbytes), 2122 1.1 christos reloc_howto->name, lpe->nbytes); 2123 1.1 christos where = frag_more (lpe->nbytes); 2124 1.1 christos md_number_to_chars (where, 0, size); 2125 1.1 christos fix_new_exp (frag_now, where - frag_now->fr_literal, 2126 1.1 christos size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc); 2127 1.1 christos } 2128 1.1 christos else 2129 1.1 christos { 2130 1.1 christos if (lpe->ex.X_op == O_big) 2131 1.1 christos { 2132 1.1 christos if (lpe->ex.X_add_number <= 0) 2133 1.1 christos generic_floating_point_number = lpe->floatnum; 2134 1.1 christos else 2135 1.1 christos memcpy (generic_bignum, lpe->bignum, 2136 1.1 christos lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE)); 2137 1.1 christos } 2138 1.1 christos emit_expr (&lpe->ex, lpe->nbytes); 2139 1.1 christos } 2140 1.1 christos 2141 1.1 christos lpe->next = lpe_free_list; 2142 1.1 christos lpe_free_list = lpe; 2143 1.1 christos } 2144 1.1 christos lpe_list_tail = NULL; 2145 1.1 christos lp_sym = NULL; 2146 1.1 christos lp_count++; 2147 1.1 christos lpe_count = 0; 2148 1.1 christos } 2149 1.1 christos 2150 1.3 christos #define MAX_HISTORY 100 2151 1.3 christos 2152 1.8 christos /* The .machine pseudo op allows one to switch to a different CPU level in 2153 1.1 christos the asm listing. The current CPU setting can be stored on a stack 2154 1.3 christos with .machine push and restored with .machine pop. */ 2155 1.1 christos 2156 1.1 christos static void 2157 1.1 christos s390_machine (int ignore ATTRIBUTE_UNUSED) 2158 1.1 christos { 2159 1.1 christos char *cpu_string; 2160 1.5 christos static struct cpu_history 2161 1.3 christos { 2162 1.3 christos unsigned int cpu; 2163 1.3 christos unsigned int flags; 2164 1.3 christos } *cpu_history; 2165 1.1 christos static int curr_hist; 2166 1.1 christos 2167 1.1 christos SKIP_WHITESPACE (); 2168 1.1 christos 2169 1.10 christos { 2170 1.10 christos char c; 2171 1.3 christos 2172 1.10 christos c = get_symbol_name (&cpu_string); 2173 1.10 christos while (c == '+') 2174 1.10 christos { 2175 1.10 christos char *str; 2176 1.3 christos 2177 1.10 christos c = restore_line_pointer (c); 2178 1.10 christos input_line_pointer++; 2179 1.10 christos c = get_symbol_name (&str); 2180 1.10 christos } 2181 1.10 christos cpu_string = xstrdup (cpu_string); 2182 1.10 christos (void) restore_line_pointer (c); 2183 1.10 christos } 2184 1.1 christos 2185 1.1 christos if (cpu_string != NULL) 2186 1.1 christos { 2187 1.3 christos unsigned int new_cpu = current_cpu; 2188 1.3 christos unsigned int new_flags = current_flags; 2189 1.1 christos 2190 1.1 christos if (strcmp (cpu_string, "push") == 0) 2191 1.1 christos { 2192 1.1 christos if (cpu_history == NULL) 2193 1.5 christos cpu_history = XNEWVEC (struct cpu_history, MAX_HISTORY); 2194 1.1 christos 2195 1.1 christos if (curr_hist >= MAX_HISTORY) 2196 1.1 christos as_bad (_(".machine stack overflow")); 2197 1.1 christos else 2198 1.3 christos { 2199 1.3 christos cpu_history[curr_hist].cpu = current_cpu; 2200 1.3 christos cpu_history[curr_hist].flags = current_flags; 2201 1.3 christos curr_hist++; 2202 1.3 christos } 2203 1.1 christos } 2204 1.1 christos else if (strcmp (cpu_string, "pop") == 0) 2205 1.1 christos { 2206 1.1 christos if (curr_hist <= 0) 2207 1.1 christos as_bad (_(".machine stack underflow")); 2208 1.1 christos else 2209 1.3 christos { 2210 1.3 christos curr_hist--; 2211 1.3 christos new_cpu = cpu_history[curr_hist].cpu; 2212 1.3 christos new_flags = cpu_history[curr_hist].flags; 2213 1.3 christos } 2214 1.1 christos } 2215 1.1 christos else 2216 1.8 christos new_cpu = s390_parse_cpu (cpu_string, &new_flags, true); 2217 1.3 christos 2218 1.3 christos if (new_cpu == S390_OPCODE_MAXCPU) 2219 1.1 christos as_bad (_("invalid machine `%s'"), cpu_string); 2220 1.1 christos 2221 1.3 christos if (new_cpu != current_cpu || new_flags != current_flags) 2222 1.3 christos { 2223 1.3 christos current_cpu = new_cpu; 2224 1.3 christos current_flags = new_flags; 2225 1.3 christos s390_setup_opcodes (); 2226 1.3 christos } 2227 1.3 christos } 2228 1.3 christos 2229 1.10 christos xfree (cpu_string); 2230 1.3 christos demand_empty_rest_of_line (); 2231 1.3 christos } 2232 1.3 christos 2233 1.8 christos /* The .machinemode pseudo op allows one to switch to a different 2234 1.3 christos architecture mode in the asm listing. The current architecture 2235 1.3 christos mode setting can be stored on a stack with .machinemode push and 2236 1.3 christos restored with .machinemode pop. */ 2237 1.3 christos 2238 1.3 christos static void 2239 1.3 christos s390_machinemode (int ignore ATTRIBUTE_UNUSED) 2240 1.3 christos { 2241 1.3 christos char *mode_string; 2242 1.3 christos static unsigned int *mode_history; 2243 1.3 christos static int curr_hist; 2244 1.3 christos 2245 1.3 christos SKIP_WHITESPACE (); 2246 1.3 christos 2247 1.3 christos { 2248 1.3 christos char c; 2249 1.3 christos 2250 1.3 christos c = get_symbol_name (&mode_string); 2251 1.3 christos mode_string = xstrdup (mode_string); 2252 1.3 christos (void) restore_line_pointer (c); 2253 1.3 christos } 2254 1.3 christos 2255 1.3 christos if (mode_string != NULL) 2256 1.3 christos { 2257 1.3 christos unsigned int old_mode_mask = current_mode_mask; 2258 1.3 christos char *p; 2259 1.3 christos 2260 1.3 christos for (p = mode_string; *p != 0; p++) 2261 1.3 christos *p = TOLOWER (*p); 2262 1.3 christos 2263 1.3 christos if (strcmp (mode_string, "push") == 0) 2264 1.3 christos { 2265 1.3 christos if (mode_history == NULL) 2266 1.5 christos mode_history = XNEWVEC (unsigned int, MAX_HISTORY); 2267 1.3 christos 2268 1.3 christos if (curr_hist >= MAX_HISTORY) 2269 1.3 christos as_bad (_(".machinemode stack overflow")); 2270 1.3 christos else 2271 1.3 christos mode_history[curr_hist++] = current_mode_mask; 2272 1.3 christos } 2273 1.3 christos else if (strcmp (mode_string, "pop") == 0) 2274 1.3 christos { 2275 1.3 christos if (curr_hist <= 0) 2276 1.3 christos as_bad (_(".machinemode stack underflow")); 2277 1.3 christos else 2278 1.3 christos current_mode_mask = mode_history[--curr_hist]; 2279 1.3 christos } 2280 1.3 christos else 2281 1.3 christos { 2282 1.3 christos if (strcmp (mode_string, "esa") == 0) 2283 1.3 christos current_mode_mask = 1 << S390_OPCODE_ESA; 2284 1.3 christos else if (strcmp (mode_string, "zarch") == 0) 2285 1.3 christos { 2286 1.3 christos if (s390_arch_size == 32) 2287 1.8 christos set_highgprs_p = true; 2288 1.3 christos current_mode_mask = 1 << S390_OPCODE_ZARCH; 2289 1.3 christos } 2290 1.3 christos else if (strcmp (mode_string, "zarch_nohighgprs") == 0) 2291 1.3 christos current_mode_mask = 1 << S390_OPCODE_ZARCH; 2292 1.3 christos else 2293 1.3 christos as_bad (_("invalid machine mode `%s'"), mode_string); 2294 1.3 christos } 2295 1.3 christos 2296 1.3 christos if (current_mode_mask != old_mode_mask) 2297 1.1 christos s390_setup_opcodes (); 2298 1.1 christos } 2299 1.1 christos 2300 1.10 christos xfree (mode_string); 2301 1.1 christos demand_empty_rest_of_line (); 2302 1.1 christos } 2303 1.1 christos 2304 1.3 christos #undef MAX_HISTORY 2305 1.3 christos 2306 1.5 christos const char * 2307 1.1 christos md_atof (int type, char *litp, int *sizep) 2308 1.1 christos { 2309 1.8 christos return ieee_md_atof (type, litp, sizep, true); 2310 1.1 christos } 2311 1.1 christos 2312 1.1 christos /* Align a section (I don't know why this is machine dependent). */ 2313 1.1 christos 2314 1.1 christos valueT 2315 1.1 christos md_section_align (asection *seg, valueT addr) 2316 1.1 christos { 2317 1.7 christos int align = bfd_section_alignment (seg); 2318 1.1 christos 2319 1.3 christos return ((addr + (1 << align) - 1) & -(1 << align)); 2320 1.1 christos } 2321 1.1 christos 2322 1.1 christos /* We don't have any form of relaxing. */ 2323 1.1 christos 2324 1.1 christos int 2325 1.1 christos md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED, 2326 1.1 christos asection *seg ATTRIBUTE_UNUSED) 2327 1.1 christos { 2328 1.1 christos abort (); 2329 1.1 christos return 0; 2330 1.1 christos } 2331 1.1 christos 2332 1.1 christos /* Convert a machine dependent frag. We never generate these. */ 2333 1.1 christos 2334 1.1 christos void 2335 1.1 christos md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, 2336 1.1 christos asection *sec ATTRIBUTE_UNUSED, 2337 1.1 christos fragS *fragp ATTRIBUTE_UNUSED) 2338 1.1 christos { 2339 1.1 christos abort (); 2340 1.1 christos } 2341 1.1 christos 2342 1.1 christos symbolS * 2343 1.1 christos md_undefined_symbol (char *name) 2344 1.1 christos { 2345 1.1 christos if (*name == '_' && *(name + 1) == 'G' 2346 1.1 christos && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0) 2347 1.1 christos { 2348 1.1 christos if (!GOT_symbol) 2349 1.1 christos { 2350 1.1 christos if (symbol_find (name)) 2351 1.1 christos as_bad (_("GOT already in symbol table")); 2352 1.1 christos GOT_symbol = symbol_new (name, undefined_section, 2353 1.8 christos &zero_address_frag, 0); 2354 1.1 christos } 2355 1.1 christos return GOT_symbol; 2356 1.1 christos } 2357 1.1 christos return 0; 2358 1.1 christos } 2359 1.1 christos 2360 1.1 christos /* Functions concerning relocs. */ 2361 1.1 christos 2362 1.1 christos /* The location from which a PC relative jump should be calculated, 2363 1.1 christos given a PC relative reloc. */ 2364 1.1 christos 2365 1.1 christos long 2366 1.1 christos md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED) 2367 1.1 christos { 2368 1.1 christos return fixp->fx_frag->fr_address + fixp->fx_where; 2369 1.1 christos } 2370 1.1 christos 2371 1.1 christos /* Here we decide which fixups can be adjusted to make them relative to 2372 1.1 christos the beginning of the section instead of the symbol. Basically we need 2373 1.1 christos to make sure that the dynamic relocations are done correctly, so in 2374 1.1 christos some cases we force the original symbol to be used. */ 2375 1.1 christos int 2376 1.1 christos tc_s390_fix_adjustable (fixS *fixP) 2377 1.1 christos { 2378 1.6 christos /* Don't adjust pc-relative references to merge sections. */ 2379 1.6 christos if (fixP->fx_pcrel 2380 1.6 christos && (S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0) 2381 1.1 christos return 0; 2382 1.6 christos 2383 1.1 christos /* adjust_reloc_syms doesn't know about the GOT. */ 2384 1.1 christos if ( fixP->fx_r_type == BFD_RELOC_16_GOTOFF 2385 1.1 christos || fixP->fx_r_type == BFD_RELOC_32_GOTOFF 2386 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64 2387 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16 2388 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32 2389 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64 2390 1.3 christos || fixP->fx_r_type == BFD_RELOC_390_PLT12DBL 2391 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL 2392 1.3 christos || fixP->fx_r_type == BFD_RELOC_390_PLT24DBL 2393 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_PLT32 2394 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL 2395 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_PLT64 2396 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOT12 2397 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOT20 2398 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOT16 2399 1.1 christos || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL 2400 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOT64 2401 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOTENT 2402 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12 2403 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16 2404 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20 2405 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32 2406 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64 2407 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT 2408 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD 2409 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL 2410 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL 2411 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32 2412 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64 2413 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12 2414 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20 2415 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32 2416 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64 2417 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32 2418 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64 2419 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32 2420 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64 2421 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT 2422 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32 2423 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64 2424 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32 2425 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64 2426 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD 2427 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF 2428 1.1 christos || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF 2429 1.1 christos || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT 2430 1.1 christos || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) 2431 1.1 christos return 0; 2432 1.1 christos return 1; 2433 1.1 christos } 2434 1.1 christos 2435 1.1 christos /* Return true if we must always emit a reloc for a type and false if 2436 1.1 christos there is some hope of resolving it at assembly time. */ 2437 1.1 christos int 2438 1.1 christos tc_s390_force_relocation (struct fix *fixp) 2439 1.1 christos { 2440 1.1 christos /* Ensure we emit a relocation for every reference to the global 2441 1.1 christos offset table or to the procedure link table. */ 2442 1.1 christos switch (fixp->fx_r_type) 2443 1.1 christos { 2444 1.1 christos case BFD_RELOC_390_GOT12: 2445 1.1 christos case BFD_RELOC_390_GOT20: 2446 1.1 christos case BFD_RELOC_32_GOT_PCREL: 2447 1.1 christos case BFD_RELOC_32_GOTOFF: 2448 1.1 christos case BFD_RELOC_390_GOTOFF64: 2449 1.1 christos case BFD_RELOC_390_PLTOFF16: 2450 1.1 christos case BFD_RELOC_390_PLTOFF32: 2451 1.1 christos case BFD_RELOC_390_PLTOFF64: 2452 1.1 christos case BFD_RELOC_390_GOTPC: 2453 1.1 christos case BFD_RELOC_390_GOT16: 2454 1.1 christos case BFD_RELOC_390_GOTPCDBL: 2455 1.1 christos case BFD_RELOC_390_GOT64: 2456 1.1 christos case BFD_RELOC_390_GOTENT: 2457 1.1 christos case BFD_RELOC_390_PLT32: 2458 1.3 christos case BFD_RELOC_390_PLT12DBL: 2459 1.1 christos case BFD_RELOC_390_PLT16DBL: 2460 1.3 christos case BFD_RELOC_390_PLT24DBL: 2461 1.1 christos case BFD_RELOC_390_PLT32DBL: 2462 1.1 christos case BFD_RELOC_390_PLT64: 2463 1.1 christos case BFD_RELOC_390_GOTPLT12: 2464 1.1 christos case BFD_RELOC_390_GOTPLT16: 2465 1.1 christos case BFD_RELOC_390_GOTPLT20: 2466 1.1 christos case BFD_RELOC_390_GOTPLT32: 2467 1.1 christos case BFD_RELOC_390_GOTPLT64: 2468 1.1 christos case BFD_RELOC_390_GOTPLTENT: 2469 1.1 christos return 1; 2470 1.1 christos default: 2471 1.3 christos break; 2472 1.1 christos } 2473 1.1 christos 2474 1.1 christos return generic_force_reloc (fixp); 2475 1.1 christos } 2476 1.1 christos 2477 1.1 christos /* Apply a fixup to the object code. This is called for all the 2478 1.1 christos fixups we generated by the call to fix_new_exp, above. In the call 2479 1.1 christos above we used a reloc code which was the largest legal reloc code 2480 1.1 christos plus the operand index. Here we undo that to recover the operand 2481 1.1 christos index. At this point all symbol values should be fully resolved, 2482 1.1 christos and we attempt to completely resolve the reloc. If we can not do 2483 1.1 christos that, we determine the correct reloc code and put it back in the 2484 1.1 christos fixup. */ 2485 1.1 christos 2486 1.1 christos void 2487 1.1 christos md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) 2488 1.1 christos { 2489 1.1 christos char *where; 2490 1.1 christos valueT value = *valP; 2491 1.1 christos 2492 1.1 christos where = fixP->fx_frag->fr_literal + fixP->fx_where; 2493 1.1 christos 2494 1.1 christos if (fixP->fx_subsy != NULL) 2495 1.8 christos as_bad_subtract (fixP); 2496 1.1 christos 2497 1.1 christos if (fixP->fx_addsy != NULL) 2498 1.1 christos { 2499 1.1 christos if (fixP->fx_pcrel) 2500 1.1 christos value += fixP->fx_frag->fr_address + fixP->fx_where; 2501 1.1 christos } 2502 1.1 christos else 2503 1.1 christos fixP->fx_done = 1; 2504 1.1 christos 2505 1.10 christos if (fixP->fx_r_type >= BFD_RELOC_UNUSED) 2506 1.1 christos { 2507 1.1 christos const struct s390_operand *operand; 2508 1.1 christos int opindex; 2509 1.1 christos 2510 1.10 christos opindex = fixP->fx_r_type - BFD_RELOC_UNUSED; 2511 1.1 christos operand = &s390_operands[opindex]; 2512 1.1 christos 2513 1.1 christos if (fixP->fx_done) 2514 1.1 christos { 2515 1.1 christos /* Insert the fully resolved operand value. */ 2516 1.1 christos s390_insert_operand ((unsigned char *) where, operand, 2517 1.10 christos value, fixP->fx_file, fixP->fx_line, 0); 2518 1.1 christos return; 2519 1.1 christos } 2520 1.1 christos 2521 1.1 christos /* Determine a BFD reloc value based on the operand information. 2522 1.1 christos We are only prepared to turn a few of the operands into 2523 1.1 christos relocs. */ 2524 1.1 christos fixP->fx_offset = value; 2525 1.9 christos if (operand->bits == 12 && operand->shift == 20 && !fixP->fx_pcrel) 2526 1.1 christos { 2527 1.1 christos fixP->fx_size = 2; 2528 1.1 christos fixP->fx_where += 2; 2529 1.1 christos fixP->fx_r_type = BFD_RELOC_390_12; 2530 1.1 christos } 2531 1.9 christos else if (operand->bits == 12 && operand->shift == 36 && !fixP->fx_pcrel) 2532 1.1 christos { 2533 1.1 christos fixP->fx_size = 2; 2534 1.1 christos fixP->fx_where += 4; 2535 1.1 christos fixP->fx_r_type = BFD_RELOC_390_12; 2536 1.1 christos } 2537 1.9 christos else if (operand->bits == 20 && operand->shift == 20 && !fixP->fx_pcrel) 2538 1.1 christos { 2539 1.7 christos fixP->fx_size = 4; 2540 1.1 christos fixP->fx_where += 2; 2541 1.1 christos fixP->fx_r_type = BFD_RELOC_390_20; 2542 1.1 christos } 2543 1.9 christos else if (operand->bits == 8 && operand->shift == 8 && !fixP->fx_pcrel) 2544 1.1 christos { 2545 1.1 christos fixP->fx_size = 1; 2546 1.1 christos fixP->fx_where += 1; 2547 1.1 christos fixP->fx_r_type = BFD_RELOC_8; 2548 1.1 christos } 2549 1.3 christos else if (operand->bits == 12 && operand->shift == 12 2550 1.3 christos && (operand->flags & S390_OPERAND_PCREL)) 2551 1.3 christos { 2552 1.3 christos fixP->fx_size = 2; 2553 1.3 christos fixP->fx_where += 1; 2554 1.3 christos fixP->fx_offset += 1; 2555 1.6 christos fixP->fx_pcrel_adjust = 1; 2556 1.3 christos fixP->fx_r_type = BFD_RELOC_390_PC12DBL; 2557 1.3 christos } 2558 1.1 christos else if (operand->bits == 16 && operand->shift == 16) 2559 1.1 christos { 2560 1.1 christos fixP->fx_size = 2; 2561 1.1 christos fixP->fx_where += 2; 2562 1.1 christos if (operand->flags & S390_OPERAND_PCREL) 2563 1.1 christos { 2564 1.1 christos fixP->fx_r_type = BFD_RELOC_390_PC16DBL; 2565 1.1 christos fixP->fx_offset += 2; 2566 1.6 christos fixP->fx_pcrel_adjust = 2; 2567 1.1 christos } 2568 1.9 christos else if (fixP->fx_pcrel) 2569 1.9 christos { 2570 1.9 christos fixP->fx_r_type = BFD_RELOC_16_PCREL; 2571 1.9 christos fixP->fx_offset += 2; 2572 1.9 christos fixP->fx_pcrel_adjust = 2; 2573 1.9 christos } 2574 1.1 christos else 2575 1.1 christos fixP->fx_r_type = BFD_RELOC_16; 2576 1.1 christos } 2577 1.6 christos else if (operand->bits == 16 && operand->shift == 32 2578 1.6 christos && (operand->flags & S390_OPERAND_PCREL)) 2579 1.6 christos { 2580 1.6 christos fixP->fx_size = 2; 2581 1.6 christos fixP->fx_where += 4; 2582 1.6 christos fixP->fx_offset += 4; 2583 1.6 christos fixP->fx_pcrel_adjust = 4; 2584 1.6 christos fixP->fx_r_type = BFD_RELOC_390_PC16DBL; 2585 1.6 christos } 2586 1.3 christos else if (operand->bits == 24 && operand->shift == 24 2587 1.3 christos && (operand->flags & S390_OPERAND_PCREL)) 2588 1.3 christos { 2589 1.3 christos fixP->fx_size = 3; 2590 1.3 christos fixP->fx_where += 3; 2591 1.3 christos fixP->fx_offset += 3; 2592 1.6 christos fixP->fx_pcrel_adjust = 3; 2593 1.3 christos fixP->fx_r_type = BFD_RELOC_390_PC24DBL; 2594 1.3 christos } 2595 1.1 christos else if (operand->bits == 32 && operand->shift == 16 2596 1.1 christos && (operand->flags & S390_OPERAND_PCREL)) 2597 1.1 christos { 2598 1.1 christos fixP->fx_size = 4; 2599 1.1 christos fixP->fx_where += 2; 2600 1.1 christos fixP->fx_offset += 2; 2601 1.6 christos fixP->fx_pcrel_adjust = 2; 2602 1.1 christos fixP->fx_r_type = BFD_RELOC_390_PC32DBL; 2603 1.1 christos } 2604 1.1 christos else 2605 1.1 christos { 2606 1.5 christos const char *sfile; 2607 1.1 christos unsigned int sline; 2608 1.1 christos 2609 1.1 christos /* Use expr_symbol_where to see if this is an expression 2610 1.1 christos symbol. */ 2611 1.1 christos if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline)) 2612 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 2613 1.1 christos _("unresolved expression that must be resolved")); 2614 1.1 christos else 2615 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 2616 1.1 christos _("unsupported relocation type")); 2617 1.1 christos fixP->fx_done = 1; 2618 1.1 christos return; 2619 1.1 christos } 2620 1.1 christos } 2621 1.1 christos else 2622 1.1 christos { 2623 1.1 christos switch (fixP->fx_r_type) 2624 1.1 christos { 2625 1.1 christos case BFD_RELOC_8: 2626 1.1 christos if (fixP->fx_pcrel) 2627 1.1 christos abort (); 2628 1.1 christos if (fixP->fx_done) 2629 1.1 christos md_number_to_chars (where, value, 1); 2630 1.1 christos break; 2631 1.1 christos case BFD_RELOC_390_12: 2632 1.1 christos case BFD_RELOC_390_GOT12: 2633 1.1 christos case BFD_RELOC_390_GOTPLT12: 2634 1.3 christos case BFD_RELOC_390_PC12DBL: 2635 1.3 christos case BFD_RELOC_390_PLT12DBL: 2636 1.3 christos if (fixP->fx_pcrel) 2637 1.6 christos value += fixP->fx_pcrel_adjust; 2638 1.3 christos 2639 1.1 christos if (fixP->fx_done) 2640 1.1 christos { 2641 1.1 christos unsigned short mop; 2642 1.1 christos 2643 1.3 christos if (fixP->fx_pcrel) 2644 1.3 christos value >>= 1; 2645 1.3 christos 2646 1.10 christos mop = bfd_getb16 (where); 2647 1.10 christos mop |= value & 0xfff; 2648 1.10 christos bfd_putb16 (mop, where); 2649 1.1 christos } 2650 1.1 christos break; 2651 1.1 christos 2652 1.1 christos case BFD_RELOC_390_20: 2653 1.1 christos case BFD_RELOC_390_GOT20: 2654 1.1 christos case BFD_RELOC_390_GOTPLT20: 2655 1.1 christos if (fixP->fx_done) 2656 1.1 christos { 2657 1.1 christos unsigned int mop; 2658 1.10 christos mop = bfd_getb32 (where); 2659 1.10 christos mop |= ((value & 0xfff) << 8 2660 1.10 christos | (value & 0xff000) >> 12); 2661 1.10 christos bfd_putb32 (mop, where); 2662 1.3 christos } 2663 1.1 christos break; 2664 1.1 christos 2665 1.1 christos case BFD_RELOC_16: 2666 1.1 christos case BFD_RELOC_GPREL16: 2667 1.1 christos case BFD_RELOC_16_GOT_PCREL: 2668 1.1 christos case BFD_RELOC_16_GOTOFF: 2669 1.1 christos if (fixP->fx_pcrel) 2670 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, 2671 1.1 christos _("cannot emit PC relative %s relocation%s%s"), 2672 1.1 christos bfd_get_reloc_code_name (fixP->fx_r_type), 2673 1.1 christos fixP->fx_addsy != NULL ? " against " : "", 2674 1.1 christos (fixP->fx_addsy != NULL 2675 1.1 christos ? S_GET_NAME (fixP->fx_addsy) 2676 1.1 christos : "")); 2677 1.1 christos if (fixP->fx_done) 2678 1.1 christos md_number_to_chars (where, value, 2); 2679 1.1 christos break; 2680 1.1 christos case BFD_RELOC_390_GOT16: 2681 1.1 christos case BFD_RELOC_390_PLTOFF16: 2682 1.1 christos case BFD_RELOC_390_GOTPLT16: 2683 1.1 christos if (fixP->fx_done) 2684 1.1 christos md_number_to_chars (where, value, 2); 2685 1.1 christos break; 2686 1.1 christos case BFD_RELOC_390_PC16DBL: 2687 1.1 christos case BFD_RELOC_390_PLT16DBL: 2688 1.6 christos value += fixP->fx_pcrel_adjust; 2689 1.1 christos if (fixP->fx_done) 2690 1.1 christos md_number_to_chars (where, (offsetT) value >> 1, 2); 2691 1.1 christos break; 2692 1.1 christos 2693 1.3 christos case BFD_RELOC_390_PC24DBL: 2694 1.3 christos case BFD_RELOC_390_PLT24DBL: 2695 1.6 christos value += fixP->fx_pcrel_adjust; 2696 1.3 christos if (fixP->fx_done) 2697 1.3 christos { 2698 1.3 christos unsigned int mop; 2699 1.3 christos value >>= 1; 2700 1.3 christos 2701 1.10 christos mop = bfd_getb32 (where - 1); 2702 1.10 christos mop |= value & 0xffffff; 2703 1.10 christos bfd_putb32 (mop, where - 1); 2704 1.3 christos } 2705 1.3 christos break; 2706 1.3 christos 2707 1.1 christos case BFD_RELOC_32: 2708 1.1 christos if (fixP->fx_pcrel) 2709 1.1 christos fixP->fx_r_type = BFD_RELOC_32_PCREL; 2710 1.1 christos else 2711 1.1 christos fixP->fx_r_type = BFD_RELOC_32; 2712 1.1 christos if (fixP->fx_done) 2713 1.1 christos md_number_to_chars (where, value, 4); 2714 1.1 christos break; 2715 1.1 christos case BFD_RELOC_32_PCREL: 2716 1.1 christos case BFD_RELOC_32_BASEREL: 2717 1.1 christos fixP->fx_r_type = BFD_RELOC_32_PCREL; 2718 1.1 christos if (fixP->fx_done) 2719 1.1 christos md_number_to_chars (where, value, 4); 2720 1.1 christos break; 2721 1.1 christos case BFD_RELOC_32_GOT_PCREL: 2722 1.1 christos case BFD_RELOC_390_PLTOFF32: 2723 1.1 christos case BFD_RELOC_390_PLT32: 2724 1.1 christos case BFD_RELOC_390_GOTPLT32: 2725 1.1 christos if (fixP->fx_done) 2726 1.1 christos md_number_to_chars (where, value, 4); 2727 1.1 christos break; 2728 1.1 christos case BFD_RELOC_390_PC32DBL: 2729 1.1 christos case BFD_RELOC_390_PLT32DBL: 2730 1.1 christos case BFD_RELOC_390_GOTPCDBL: 2731 1.1 christos case BFD_RELOC_390_GOTENT: 2732 1.1 christos case BFD_RELOC_390_GOTPLTENT: 2733 1.6 christos value += fixP->fx_pcrel_adjust; 2734 1.1 christos if (fixP->fx_done) 2735 1.1 christos md_number_to_chars (where, (offsetT) value >> 1, 4); 2736 1.1 christos break; 2737 1.1 christos 2738 1.1 christos case BFD_RELOC_32_GOTOFF: 2739 1.1 christos if (fixP->fx_done) 2740 1.1 christos md_number_to_chars (where, value, sizeof (int)); 2741 1.1 christos break; 2742 1.1 christos 2743 1.1 christos case BFD_RELOC_390_GOTOFF64: 2744 1.1 christos if (fixP->fx_done) 2745 1.1 christos md_number_to_chars (where, value, 8); 2746 1.1 christos break; 2747 1.1 christos 2748 1.1 christos case BFD_RELOC_390_GOT64: 2749 1.1 christos case BFD_RELOC_390_PLTOFF64: 2750 1.1 christos case BFD_RELOC_390_PLT64: 2751 1.1 christos case BFD_RELOC_390_GOTPLT64: 2752 1.1 christos if (fixP->fx_done) 2753 1.1 christos md_number_to_chars (where, value, 8); 2754 1.1 christos break; 2755 1.1 christos 2756 1.1 christos case BFD_RELOC_64: 2757 1.1 christos if (fixP->fx_pcrel) 2758 1.1 christos fixP->fx_r_type = BFD_RELOC_64_PCREL; 2759 1.1 christos else 2760 1.1 christos fixP->fx_r_type = BFD_RELOC_64; 2761 1.1 christos if (fixP->fx_done) 2762 1.1 christos md_number_to_chars (where, value, 8); 2763 1.1 christos break; 2764 1.1 christos 2765 1.1 christos case BFD_RELOC_64_PCREL: 2766 1.1 christos fixP->fx_r_type = BFD_RELOC_64_PCREL; 2767 1.1 christos if (fixP->fx_done) 2768 1.1 christos md_number_to_chars (where, value, 8); 2769 1.1 christos break; 2770 1.1 christos 2771 1.1 christos case BFD_RELOC_VTABLE_INHERIT: 2772 1.1 christos case BFD_RELOC_VTABLE_ENTRY: 2773 1.1 christos fixP->fx_done = 0; 2774 1.1 christos return; 2775 1.1 christos 2776 1.1 christos case BFD_RELOC_390_TLS_LOAD: 2777 1.1 christos case BFD_RELOC_390_TLS_GDCALL: 2778 1.1 christos case BFD_RELOC_390_TLS_LDCALL: 2779 1.1 christos case BFD_RELOC_390_TLS_GD32: 2780 1.1 christos case BFD_RELOC_390_TLS_GD64: 2781 1.1 christos case BFD_RELOC_390_TLS_GOTIE12: 2782 1.1 christos case BFD_RELOC_390_TLS_GOTIE20: 2783 1.1 christos case BFD_RELOC_390_TLS_GOTIE32: 2784 1.1 christos case BFD_RELOC_390_TLS_GOTIE64: 2785 1.1 christos case BFD_RELOC_390_TLS_LDM32: 2786 1.1 christos case BFD_RELOC_390_TLS_LDM64: 2787 1.1 christos case BFD_RELOC_390_TLS_IE32: 2788 1.1 christos case BFD_RELOC_390_TLS_IE64: 2789 1.1 christos case BFD_RELOC_390_TLS_LE32: 2790 1.1 christos case BFD_RELOC_390_TLS_LE64: 2791 1.1 christos case BFD_RELOC_390_TLS_LDO32: 2792 1.1 christos case BFD_RELOC_390_TLS_LDO64: 2793 1.1 christos case BFD_RELOC_390_TLS_DTPMOD: 2794 1.1 christos case BFD_RELOC_390_TLS_DTPOFF: 2795 1.1 christos case BFD_RELOC_390_TLS_TPOFF: 2796 1.1 christos S_SET_THREAD_LOCAL (fixP->fx_addsy); 2797 1.1 christos /* Fully resolved at link time. */ 2798 1.1 christos break; 2799 1.1 christos case BFD_RELOC_390_TLS_IEENT: 2800 1.1 christos /* Fully resolved at link time. */ 2801 1.1 christos S_SET_THREAD_LOCAL (fixP->fx_addsy); 2802 1.1 christos value += 2; 2803 1.1 christos break; 2804 1.1 christos 2805 1.1 christos default: 2806 1.1 christos { 2807 1.1 christos const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type); 2808 1.1 christos 2809 1.1 christos if (reloc_name != NULL) 2810 1.1 christos as_fatal (_("Gas failure, reloc type %s\n"), reloc_name); 2811 1.1 christos else 2812 1.1 christos as_fatal (_("Gas failure, reloc type #%i\n"), fixP->fx_r_type); 2813 1.1 christos } 2814 1.1 christos } 2815 1.1 christos 2816 1.1 christos fixP->fx_offset = value; 2817 1.1 christos } 2818 1.1 christos } 2819 1.1 christos 2820 1.1 christos /* Generate a reloc for a fixup. */ 2821 1.1 christos 2822 1.1 christos arelent * 2823 1.1 christos tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp) 2824 1.1 christos { 2825 1.1 christos bfd_reloc_code_real_type code; 2826 1.1 christos arelent *reloc; 2827 1.1 christos 2828 1.1 christos code = fixp->fx_r_type; 2829 1.1 christos if (GOT_symbol && fixp->fx_addsy == GOT_symbol) 2830 1.1 christos { 2831 1.1 christos if ( (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL) 2832 1.1 christos || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL)) 2833 1.1 christos code = BFD_RELOC_390_GOTPC; 2834 1.1 christos if (code == BFD_RELOC_390_PC32DBL) 2835 1.1 christos code = BFD_RELOC_390_GOTPCDBL; 2836 1.1 christos } 2837 1.1 christos 2838 1.10 christos reloc = notes_alloc (sizeof (arelent)); 2839 1.10 christos reloc->sym_ptr_ptr = notes_alloc (sizeof (asymbol *)); 2840 1.1 christos *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); 2841 1.1 christos reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; 2842 1.1 christos reloc->howto = bfd_reloc_type_lookup (stdoutput, code); 2843 1.1 christos if (reloc->howto == NULL) 2844 1.1 christos { 2845 1.1 christos as_bad_where (fixp->fx_file, fixp->fx_line, 2846 1.1 christos _("cannot represent relocation type %s"), 2847 1.1 christos bfd_get_reloc_code_name (code)); 2848 1.1 christos /* Set howto to a garbage value so that we can keep going. */ 2849 1.1 christos reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32); 2850 1.1 christos gas_assert (reloc->howto != NULL); 2851 1.1 christos } 2852 1.1 christos reloc->addend = fixp->fx_offset; 2853 1.1 christos 2854 1.1 christos return reloc; 2855 1.1 christos } 2856 1.1 christos 2857 1.1 christos void 2858 1.1 christos s390_cfi_frame_initial_instructions (void) 2859 1.1 christos { 2860 1.1 christos cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96); 2861 1.1 christos } 2862 1.1 christos 2863 1.1 christos int 2864 1.1 christos tc_s390_regname_to_dw2regnum (char *regname) 2865 1.1 christos { 2866 1.1 christos int regnum = -1; 2867 1.1 christos 2868 1.1 christos if (regname[0] != 'c' && regname[0] != 'a') 2869 1.1 christos { 2870 1.3 christos regnum = reg_name_search (regname); 2871 1.1 christos if (regname[0] == 'f' && regnum != -1) 2872 1.1 christos regnum += 16; 2873 1.1 christos } 2874 1.1 christos else if (strcmp (regname, "ap") == 0) 2875 1.1 christos regnum = 32; 2876 1.1 christos else if (strcmp (regname, "cc") == 0) 2877 1.1 christos regnum = 33; 2878 1.1 christos return regnum; 2879 1.1 christos } 2880 1.1 christos 2881 1.10 christos /* Whether SFrame stack trace info is supported. */ 2882 1.10 christos 2883 1.10 christos bool 2884 1.10 christos s390_support_sframe_p (void) 2885 1.10 christos { 2886 1.10 christos /* At this time, SFrame is supported for s390x (64-bit) only. */ 2887 1.10 christos return (s390_arch_size == 64); 2888 1.10 christos } 2889 1.10 christos 2890 1.10 christos /* Specify if RA tracking is needed. */ 2891 1.10 christos 2892 1.10 christos bool 2893 1.10 christos s390_sframe_ra_tracking_p (void) 2894 1.10 christos { 2895 1.10 christos return true; 2896 1.10 christos } 2897 1.10 christos 2898 1.10 christos /* Specify the fixed offset to recover RA from CFA. 2899 1.10 christos (useful only when RA tracking is not needed). */ 2900 1.10 christos 2901 1.10 christos offsetT 2902 1.10 christos s390_sframe_cfa_ra_offset (void) 2903 1.10 christos { 2904 1.10 christos return (offsetT) SFRAME_CFA_FIXED_RA_INVALID; 2905 1.10 christos } 2906 1.10 christos 2907 1.10 christos /* Get the abi/arch identifier for SFrame. */ 2908 1.10 christos 2909 1.10 christos unsigned char 2910 1.10 christos s390_sframe_get_abi_arch (void) 2911 1.10 christos { 2912 1.10 christos unsigned char sframe_abi_arch = 0; 2913 1.10 christos 2914 1.10 christos if (s390_support_sframe_p ()) 2915 1.10 christos { 2916 1.10 christos gas_assert (target_big_endian); 2917 1.10 christos sframe_abi_arch = SFRAME_ABI_S390X_ENDIAN_BIG; 2918 1.10 christos } 2919 1.10 christos 2920 1.10 christos return sframe_abi_arch; 2921 1.10 christos } 2922 1.10 christos 2923 1.1 christos void 2924 1.1 christos s390_elf_final_processing (void) 2925 1.1 christos { 2926 1.3 christos if (set_highgprs_p) 2927 1.1 christos elf_elfheader (stdoutput)->e_flags |= EF_S390_HIGH_GPRS; 2928 1.1 christos } 2929