diff options
author | Richard Sandiford <rdsandiford@googlemail.com> | 2013-07-14 13:28:56 +0000 |
---|---|---|
committer | Richard Sandiford <rdsandiford@googlemail.com> | 2013-07-14 13:28:56 +0000 |
commit | ab90248154ba05dc800c480712c3cb03eb33b135 (patch) | |
tree | 111a36595f3d3ad10b07a5fc1b7c6a443ac757a0 /opcodes/micromips-opc.c | |
parent | 2f8b73cc2b2dd77e0f4cc772262c9ae0092d4e14 (diff) | |
download | gdb-ab90248154ba05dc800c480712c3cb03eb33b135.zip gdb-ab90248154ba05dc800c480712c3cb03eb33b135.tar.gz gdb-ab90248154ba05dc800c480712c3cb03eb33b135.tar.bz2 |
include/opcode/
* mips.h (mips_operand_type, mips_reg_operand_type): New enums.
(mips_operand, mips_int_operand, mips_mapped_int_operand)
(mips_msb_operand, mips_reg_operand, mips_reg_pair_operand)
(mips_pcrel_operand): New structures.
(mips_insert_operand, mips_extract_operand, mips_signed_operand)
(mips_decode_int_operand, mips_decode_pcrel_operand): New functions.
(decode_mips_operand, decode_micromips_operand): Declare.
opcodes/
* mips-formats.h: New file.
* mips-opc.c: Include mips-formats.h.
(reg_0_map): New static array.
(decode_mips_operand): New function.
* micromips-opc.c: Remove <stdio.h> include. Include mips-formats.h.
(reg_0_map, reg_28_map, reg_29_map, reg_31_map, reg_m16_map)
(reg_mn_map, reg_q_map, reg_h_map1, reg_h_map2, int_b_map)
(int_c_map): New static arrays.
(decode_micromips_operand): New function.
* mips-dis.c (micromips_to_32_reg_b_map, micromips_to_32_reg_c_map)
(micromips_to_32_reg_d_map, micromips_to_32_reg_e_map)
(micromips_to_32_reg_f_map, micromips_to_32_reg_g_map)
(micromips_to_32_reg_h_map1, micromips_to_32_reg_h_map2)
(micromips_to_32_reg_l_map, micromips_to_32_reg_m_map)
(micromips_to_32_reg_n_map, micromips_to_32_reg_q_map)
(micromips_imm_b_map, micromips_imm_c_map): Delete.
(print_reg): New function.
(mips_print_arg_state): New structure.
(init_print_arg_state, print_insn_arg): New functions.
(print_insn_args): Change interface and use mips_operand structures.
Delete GET_OP_S. Move GET_OP definition to...
(print_insn_mips): ...here. Update the call to print_insn_args.
(print_insn_micromips): Use print_insn_args.
gas/
* config/tc-mips.c (validate_mips_insn): Move further up file.
Add insn_bits and decode_operand arguments. Use the mips_operand
fields to work out which bits an operand occupies. Detect double
definitions.
(validate_micromips_insn): Move further up file. Call into
validate_mips_insn.
Diffstat (limited to 'opcodes/micromips-opc.c')
-rw-r--r-- | opcodes/micromips-opc.c | 149 |
1 files changed, 148 insertions, 1 deletions
diff --git a/opcodes/micromips-opc.c b/opcodes/micromips-opc.c index de8053c..8630769 100644 --- a/opcodes/micromips-opc.c +++ b/opcodes/micromips-opc.c @@ -20,8 +20,155 @@ MA 02110-1301, USA. */ #include "sysdep.h" -#include <stdio.h> #include "opcode/mips.h" +#include "mips-formats.h" + +static unsigned char reg_0_map[] = { 0 }; +static unsigned char reg_28_map[] = { 28 }; +static unsigned char reg_29_map[] = { 29 }; +static unsigned char reg_31_map[] = { 31 }; +static unsigned char reg_m16_map[] = { 16, 17, 2, 3, 4, 5, 6, 7 }; +static unsigned char reg_mn_map[] = { 0, 17, 2, 3, 16, 18, 19, 20 }; +static unsigned char reg_q_map[] = { 0, 17, 2, 3, 4, 5, 6, 7 }; + +static unsigned char reg_h_map1[] = { 5, 5, 6, 4, 4, 4, 4, 4 }; +static unsigned char reg_h_map2[] = { 6, 7, 7, 21, 22, 5, 6, 7 }; + +static int int_b_map[] = { + 1, 4, 8, 12, 16, 20, 24, -1 +}; +static int int_c_map[] = { + 128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 255, 32768, 65535 +}; + +/* Return the mips_operand structure for the operand at the beginning of P. */ + +const struct mips_operand * +decode_micromips_operand (const char *p) +{ + switch (p[0]) + { + case 'm': + switch (p[1]) + { + case 'a': MAPPED_REG (0, 0, GP, reg_28_map); + case 'b': MAPPED_REG (3, 23, GP, reg_m16_map); + case 'c': MAPPED_REG (3, 4, GP, reg_m16_map); + case 'd': MAPPED_REG (3, 7, GP, reg_m16_map); + case 'e': MAPPED_REG (3, 1, GP, reg_m16_map); + case 'f': MAPPED_REG (3, 3, GP, reg_m16_map); + case 'g': MAPPED_REG (3, 0, GP, reg_m16_map); + case 'h': REG_PAIR (3, 7, GP, reg_h_map); + case 'j': REG (5, 0, GP); + case 'l': MAPPED_REG (3, 4, GP, reg_m16_map); + case 'm': MAPPED_REG (3, 1, GP, reg_mn_map); + case 'n': MAPPED_REG (3, 4, GP, reg_mn_map); + case 'p': REG (5, 5, GP); + case 'q': MAPPED_REG (3, 7, GP, reg_q_map); + case 'r': SPECIAL (0, 0, PC); + case 's': MAPPED_REG (0, 0, GP, reg_29_map); + case 't': SPECIAL (0, 0, REPEAT_PREV_REG); + case 'x': SPECIAL (0, 0, REPEAT_DEST_REG); + case 'y': MAPPED_REG (0, 0, GP, reg_31_map); + case 'z': MAPPED_REG (0, 0, GP, reg_0_map); + + case 'A': INT_ADJ (7, 0, 63, 2, FALSE); /* (-64 .. 63) << 2 */ + case 'B': MAPPED_INT (3, 1, int_b_map, FALSE); + case 'C': MAPPED_INT (4, 0, int_c_map, TRUE); + case 'D': BRANCH (10, 0, 1); + case 'E': BRANCH (7, 0, 1); + case 'F': HINT (4, 0); + case 'G': INT_ADJ (4, 0, 14, 0, FALSE); /* (-1 .. 14) */ + case 'H': INT_ADJ (4, 0, 15, 1, FALSE); /* (0 .. 15) << 1 */ + case 'I': INT_ADJ (7, 0, 126, 0, FALSE); /* (-1 .. 126) */ + case 'J': INT_ADJ (4, 0, 15, 2, FALSE); /* (0 .. 15) << 2 */ + case 'L': INT_ADJ (4, 0, 15, 0, FALSE); /* (0 .. 15) */ + case 'M': INT_ADJ (3, 1, 8, 0, FALSE); /* (1 .. 8) */ + case 'N': SPECIAL (2, 4, LWM_SWM_LIST); + case 'O': HINT (4, 0); + case 'P': INT_ADJ (5, 0, 31, 2, FALSE); /* (0 .. 31) << 2 */ + case 'Q': INT_ADJ (23, 0, 4194303, 2, FALSE); + /* (-4194304 .. 4194303) */ + case 'U': INT_ADJ (5, 0, 31, 2, FALSE); /* (0 .. 31) << 2 */ + case 'W': INT_ADJ (6, 1, 63, 2, FALSE); /* (0 .. 63) << 2 */ + case 'X': SINT (4, 1); + case 'Y': SPECIAL (9, 1, ADDIUSP_INT); + case 'Z': UINT (0, 0); /* 0 only */ + } + break; + + case '+': + switch (p[1]) + { + case 'A': BIT (5, 6, 0); /* (0 .. 31) */ + case 'B': MSB (5, 11, 1, TRUE, 32); /* (1 .. 32), 32-bit op */ + case 'C': MSB (5, 11, 1, FALSE, 32); /* (1 .. 32), 32-bit op */ + case 'E': BIT (5, 6, 32); /* (32 .. 63) */ + case 'F': MSB (5, 11, 33, TRUE, 64); /* (33 .. 64), 64-bit op */ + case 'G': MSB (5, 11, 33, FALSE, 64); /* (33 .. 64), 64-bit op */ + case 'H': MSB (5, 11, 1, FALSE, 64); /* (1 .. 32), 64-bit op */ + + case 'i': JALX (26, 0, 2); + case 'j': SINT (9, 0); + } + break; + + case '.': SINT (10, 6); + case '<': BIT (5, 11, 0); /* (0 .. 31) */ + case '>': BIT (5, 11, 32); /* (32 .. 63) */ + case '\\': BIT (3, 21, 0); /* (0 .. 7) */ + case '|': HINT (4, 12); + case '~': SINT (12, 0); + case '@': SINT (10, 16); + case '^': HINT (5, 11); + + case '0': SINT (6, 16); + case '1': HINT (5, 16); + case '2': HINT (2, 14); + case '3': HINT (3, 13); + case '4': HINT (4, 12); + case '5': HINT (8, 13); + case '6': HINT (5, 16); + case '7': REG (2, 14, ACC); + case '8': HINT (6, 14); + + case 'B': HINT (10, 16); + case 'C': HINT (23, 3); + case 'D': REG (5, 11, FP); + case 'E': REG (5, 21, COPRO); + case 'G': REG (5, 16, COPRO); + case 'K': REG (5, 16, HW); + case 'H': UINT (3, 11); + case 'M': REG (3, 13, CCC); + case 'N': REG (3, 18, CCC); + case 'R': REG (5, 6, FP); + case 'S': REG (5, 16, FP); + case 'T': REG (5, 21, FP); + case 'V': REG (5, 16, FP); + + case 'a': JUMP (26, 0, 1); + case 'b': REG (5, 16, GP); + case 'c': HINT (10, 16); + case 'd': REG (5, 11, GP); + case 'h': HINT (5, 11); + case 'i': HINT (16, 0); + case 'j': SINT (16, 0); + case 'k': HINT (5, 21); + case 'n': SPECIAL (5, 21, LWM_SWM_LIST); + case 'o': SINT (16, 0); + case 'p': BRANCH (16, 0, 1); + case 'q': HINT (10, 6); + case 'r': REG (5, 16, GP); + case 's': REG (5, 16, GP); + case 't': REG (5, 21, GP); + case 'u': HINT (16, 0); + case 'v': REG (5, 16, GP); + case 'w': REG (5, 21, GP); + case 'y': REG (5, 6, GP); + case 'z': MAPPED_REG (0, 0, GP, reg_0_map); + } + return 0; +} #define UBD INSN_UNCOND_BRANCH_DELAY #define CBD INSN_COND_BRANCH_DELAY |