| OLD | NEW |
| 1 /* s390-mkopc.c -- Generates opcode table out of s390-opc.txt | 1 /* s390-mkopc.c -- Generates opcode table out of s390-opc.txt |
| 2 Copyright 2000, 2001, 2003, 2005, 2007, 2008 Free Software Foundation, Inc. | 2 Copyright 2000-2013 Free Software Foundation, Inc. |
| 3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). | 3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). |
| 4 | 4 |
| 5 This file is part of the GNU opcodes library. | 5 This file is part of the GNU opcodes library. |
| 6 | 6 |
| 7 This library is free software; you can redistribute it and/or modify | 7 This library is free software; you can redistribute it and/or modify |
| 8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
| 9 the Free Software Foundation; either version 3, or (at your option) | 9 the Free Software Foundation; either version 3, or (at your option) |
| 10 any later version. | 10 any later version. |
| 11 | 11 |
| 12 It is distributed in the hope that it will be useful, but WITHOUT | 12 It is distributed in the hope that it will be useful, but WITHOUT |
| (...skipping 19 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 enum s390_opcode_cpu_val | 33 enum s390_opcode_cpu_val |
| 34 { | 34 { |
| 35 S390_OPCODE_G5 = 0, | 35 S390_OPCODE_G5 = 0, |
| 36 S390_OPCODE_G6, | 36 S390_OPCODE_G6, |
| 37 S390_OPCODE_Z900, | 37 S390_OPCODE_Z900, |
| 38 S390_OPCODE_Z990, | 38 S390_OPCODE_Z990, |
| 39 S390_OPCODE_Z9_109, | 39 S390_OPCODE_Z9_109, |
| 40 S390_OPCODE_Z9_EC, | 40 S390_OPCODE_Z9_EC, |
| 41 S390_OPCODE_Z10, | 41 S390_OPCODE_Z10, |
| 42 S390_OPCODE_Z196 | 42 S390_OPCODE_Z196, |
| 43 S390_OPCODE_ZEC12 |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 struct op_struct | 46 struct op_struct |
| 46 { | 47 { |
| 47 char opcode[16]; | 48 char opcode[16]; |
| 48 char mnemonic[16]; | 49 char mnemonic[16]; |
| 49 char format[16]; | 50 char format[16]; |
| 50 int mode_bits; | 51 int mode_bits; |
| 51 int min_cpu; | 52 int min_cpu; |
| 52 | 53 |
| 53 unsigned long long sort_value; | 54 unsigned long long sort_value; |
| 54 int no_nibbles; | 55 int no_nibbles; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 struct op_struct *op_array; | 58 struct op_struct *op_array; |
| 58 int max_ops; | 59 int max_ops; |
| 59 int no_ops; | 60 int no_ops; |
| 60 | 61 |
| 61 static void | 62 static void |
| 62 createTable (void) | 63 createTable (void) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 strcat (new_mnemonic, ext_table[i].extension); | 269 strcat (new_mnemonic, ext_table[i].extension); |
| 269 strcat (new_mnemonic, suffix); | 270 strcat (new_mnemonic, suffix); |
| 270 insertOpcode (opcode, new_mnemonic, format, min_cpu, mode_bits); | 271 insertOpcode (opcode, new_mnemonic, format, min_cpu, mode_bits); |
| 271 } | 272 } |
| 272 return; | 273 return; |
| 273 | 274 |
| 274 malformed_mnemonic: | 275 malformed_mnemonic: |
| 275 fprintf (stderr, "Malformed mnemonic: %s\n", mnemonic); | 276 fprintf (stderr, "Malformed mnemonic: %s\n", mnemonic); |
| 276 } | 277 } |
| 277 | 278 |
| 278 static char file_header[] = | 279 static const char file_header[] = |
| 279 "/* The opcode table. This file was generated by s390-mkopc.\n\n" | 280 "/* The opcode table. This file was generated by s390-mkopc.\n\n" |
| 280 " The format of the opcode table is:\n\n" | 281 " The format of the opcode table is:\n\n" |
| 281 " NAME OPCODE MASK OPERANDS\n\n" | 282 " NAME OPCODE MASK OPERANDS\n\n" |
| 282 " Name is the name of the instruction.\n" | 283 " Name is the name of the instruction.\n" |
| 283 " OPCODE is the instruction opcode.\n" | 284 " OPCODE is the instruction opcode.\n" |
| 284 " MASK is the opcode mask; this is used to tell the disassembler\n" | 285 " MASK is the opcode mask; this is used to tell the disassembler\n" |
| 285 " which bits in the actual opcode must match OPCODE.\n" | 286 " which bits in the actual opcode must match OPCODE.\n" |
| 286 " OPERANDS is the list of operands.\n\n" | 287 " OPERANDS is the list of operands.\n\n" |
| 287 " The disassembler reads the table in order and prints the first\n" | 288 " The disassembler reads the table in order and prints the first\n" |
| 288 " instruction which matches. */\n\n" | 289 " instruction which matches. */\n\n" |
| 289 "const struct s390_opcode s390_opcodes[] =\n {\n"; | 290 "const struct s390_opcode s390_opcodes[] =\n {\n"; |
| 290 | 291 |
| 291 /* `dumpTable': write opcode table. */ | 292 /* `dumpTable': write opcode table. */ |
| 292 | 293 |
| 293 static void | 294 static void |
| 294 dumpTable (void) | 295 dumpTable (void) |
| 295 { | 296 { |
| 296 char *str; | 297 char *str; |
| 297 int ix; | 298 int ix; |
| 298 | 299 |
| 299 /* Write hash table entries (slots). */ | 300 /* Write hash table entries (slots). */ |
| 300 printf (file_header); | 301 printf ("%s", file_header); |
| 301 | 302 |
| 302 for (ix = 0; ix < no_ops; ix++) | 303 for (ix = 0; ix < no_ops; ix++) |
| 303 { | 304 { |
| 304 printf (" { \"%s\", ", op_array[ix].mnemonic); | 305 printf (" { \"%s\", ", op_array[ix].mnemonic); |
| 305 for (str = op_array[ix].opcode; *str != 0; str++) | 306 for (str = op_array[ix].opcode; *str != 0; str++) |
| 306 if (*str == '?') | 307 if (*str == '?') |
| 307 *str = '0'; | 308 *str = '0'; |
| 308 printf ("OP%i(0x%sLL), ", | 309 printf ("OP%i(0x%sLL), ", |
| 309 op_array[ix].no_nibbles*4, op_array[ix].opcode); | 310 op_array[ix].no_nibbles*4, op_array[ix].opcode); |
| 310 printf ("MASK_%s, INSTR_%s, ", | 311 printf ("MASK_%s, INSTR_%s, ", |
| 311 op_array[ix].format, op_array[ix].format); | 312 op_array[ix].format, op_array[ix].format); |
| 312 printf ("%i, ", op_array[ix].mode_bits); | 313 printf ("%i, ", op_array[ix].mode_bits); |
| 313 printf ("%i}", op_array[ix].min_cpu); | 314 printf ("%i}", op_array[ix].min_cpu); |
| 314 if (ix < no_ops-1) | 315 if (ix < no_ops-1) |
| 315 printf (",\n"); | 316 printf (",\n"); |
| 316 else | 317 else |
| 317 printf ("\n"); | 318 printf ("\n"); |
| 318 } | 319 } |
| 319 printf ("};\n\n"); | 320 printf ("};\n\n"); |
| 320 printf ("const int s390_num_opcodes =\n"); | 321 printf ("const int s390_num_opcodes =\n"); |
| 321 printf (" sizeof (s390_opcodes) / sizeof (s390_opcodes[0]);\n\n"); | 322 printf (" sizeof (s390_opcodes) / sizeof (s390_opcodes[0]);\n\n"); |
| 322 } | 323 } |
| 323 | 324 |
| 324 int | 325 int |
| 325 main (void) | 326 main (void) |
| 326 { | 327 { |
| 327 char currentLine[256]; | 328 char currentLine[256]; |
| 328 | 329 |
| 329 createTable (); | 330 createTable (); |
| 330 | 331 |
| 331 /* Read opcode descriptions from `stdin'. For each mnemonic, | 332 /* Read opcode descriptions from `stdin'. For each mnemonic, |
| 332 make an entry into the opcode table. */ | 333 make an entry into the opcode table. */ |
| 333 while (fgets (currentLine, sizeof (currentLine), stdin) != NULL) | 334 while (fgets (currentLine, sizeof (currentLine), stdin) != NULL) |
| 334 { | 335 { |
| 335 char opcode[16]; | 336 char opcode[16]; |
| 336 char mnemonic[16]; | 337 char mnemonic[16]; |
| 337 char format[16]; | 338 char format[16]; |
| 338 char description[80]; | 339 char description[80]; |
| 339 char cpu_string[16]; | 340 char cpu_string[16]; |
| 340 char modes_string[16]; | 341 char modes_string[16]; |
| 341 int min_cpu; | 342 int min_cpu; |
| 342 int mode_bits; | 343 int mode_bits; |
| 343 char *str; | 344 char *str; |
| 344 | 345 |
| 345 if (currentLine[0] == '#') | 346 if (currentLine[0] == '#' || currentLine[0] == '\n') |
| 346 continue; | 347 continue; |
| 347 memset (opcode, 0, 8); | 348 memset (opcode, 0, 8); |
| 348 if (sscanf (currentLine, "%15s %15s %15s \"%79[^\"]\" %15s %15s", | 349 if (sscanf (currentLine, "%15s %15s %15s \"%79[^\"]\" %15s %15s", |
| 349 opcode, mnemonic, format, description, | 350 opcode, mnemonic, format, description, |
| 350 cpu_string, modes_string) == 6) | 351 cpu_string, modes_string) == 6) |
| 351 { | 352 { |
| 352 if (strcmp (cpu_string, "g5") == 0) | 353 if (strcmp (cpu_string, "g5") == 0) |
| 353 min_cpu = S390_OPCODE_G5; | 354 min_cpu = S390_OPCODE_G5; |
| 354 else if (strcmp (cpu_string, "g6") == 0) | 355 else if (strcmp (cpu_string, "g6") == 0) |
| 355 min_cpu = S390_OPCODE_G6; | 356 min_cpu = S390_OPCODE_G6; |
| 356 else if (strcmp (cpu_string, "z900") == 0) | 357 else if (strcmp (cpu_string, "z900") == 0) |
| 357 min_cpu = S390_OPCODE_Z900; | 358 min_cpu = S390_OPCODE_Z900; |
| 358 else if (strcmp (cpu_string, "z990") == 0) | 359 else if (strcmp (cpu_string, "z990") == 0) |
| 359 min_cpu = S390_OPCODE_Z990; | 360 min_cpu = S390_OPCODE_Z990; |
| 360 else if (strcmp (cpu_string, "z9-109") == 0) | 361 else if (strcmp (cpu_string, "z9-109") == 0) |
| 361 min_cpu = S390_OPCODE_Z9_109; | 362 min_cpu = S390_OPCODE_Z9_109; |
| 362 else if (strcmp (cpu_string, "z9-ec") == 0) | 363 else if (strcmp (cpu_string, "z9-ec") == 0) |
| 363 min_cpu = S390_OPCODE_Z9_EC; | 364 min_cpu = S390_OPCODE_Z9_EC; |
| 364 else if (strcmp (cpu_string, "z10") == 0) | 365 else if (strcmp (cpu_string, "z10") == 0) |
| 365 min_cpu = S390_OPCODE_Z10; | 366 min_cpu = S390_OPCODE_Z10; |
| 366 else if (strcmp (cpu_string, "z196") == 0) | 367 else if (strcmp (cpu_string, "z196") == 0) |
| 367 min_cpu = S390_OPCODE_Z196; | 368 min_cpu = S390_OPCODE_Z196; |
| 369 else if (strcmp (cpu_string, "zEC12") == 0) |
| 370 min_cpu = S390_OPCODE_ZEC12; |
| 368 else { | 371 else { |
| 369 fprintf (stderr, "Couldn't parse cpu string %s\n", cpu_string); | 372 fprintf (stderr, "Couldn't parse cpu string %s\n", cpu_string); |
| 370 exit (1); | 373 exit (1); |
| 371 } | 374 } |
| 372 | 375 |
| 373 str = modes_string; | 376 str = modes_string; |
| 374 mode_bits = 0; | 377 mode_bits = 0; |
| 375 do { | 378 do { |
| 376 if (strncmp (str, "esa", 3) == 0 | 379 if (strncmp (str, "esa", 3) == 0 |
| 377 && (str[3] == 0 || str[3] == ',')) { | 380 && (str[3] == 0 || str[3] == ',')) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 395 else | 398 else |
| 396 { | 399 { |
| 397 fprintf (stderr, "Couldn't scan line %s\n", currentLine); | 400 fprintf (stderr, "Couldn't scan line %s\n", currentLine); |
| 398 exit (1); | 401 exit (1); |
| 399 } | 402 } |
| 400 } | 403 } |
| 401 | 404 |
| 402 dumpTable (); | 405 dumpTable (); |
| 403 return 0; | 406 return 0; |
| 404 } | 407 } |
| OLD | NEW |