blob: 1612c11cbd1ad4c46dcbffc315bf89c1e52a561d [file] [log] [blame]
Andrew Geisslera9ff2b32020-10-16 10:11:54 -05001From 0034d6b5231a0a72c5f9fc47ba4c8eba0c35ff39 Mon Sep 17 00:00:00 2001
Brad Bishop26bdd442019-08-16 17:08:17 -04002From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Mon, 18 Jul 2016 12:24:28 +0530
Andrew Geisslera9ff2b32020-10-16 10:11:54 -05004Subject: [PATCH 10/40] Add new bit-field instructions
Brad Bishop286d45c2018-10-02 15:21:57 -04005
Brad Bishop26bdd442019-08-16 17:08:17 -04006This patches adds new bsefi and bsifi instructions.
7BSEFI- The instruction shall extract a bit field from a
8register and place it right-adjusted in the destination register.
9The other bits in the destination register shall be set to zero
10BSIFI- The instruction shall insert a right-adjusted bit field
11from a register at another position in the destination register.
12The rest of the bits in the destination register shall be unchanged
Brad Bishop286d45c2018-10-02 15:21:57 -040013
Brad Bishop26bdd442019-08-16 17:08:17 -040014Signed-off-by :Nagaraju Mekala <nmekala@xilix.com>
Brad Bishop286d45c2018-10-02 15:21:57 -040015---
Andrew Geissler84ad7c52020-06-27 00:00:16 -050016 gas/config/tc-microblaze.c | 71 +++++++++++++++++++++++++++++++++++++-
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050017 opcodes/microblaze-dis.c | 17 +++++++++
Andrew Geissler84ad7c52020-06-27 00:00:16 -050018 opcodes/microblaze-opc.h | 12 ++++++-
Brad Bishop286d45c2018-10-02 15:21:57 -040019 opcodes/microblaze-opcm.h | 6 +++-
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050020 4 files changed, 103 insertions(+), 3 deletions(-)
Brad Bishop286d45c2018-10-02 15:21:57 -040021
22diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050023index 74a63abeb0c..765abfb3885 100644
Brad Bishop286d45c2018-10-02 15:21:57 -040024--- a/gas/config/tc-microblaze.c
25+++ b/gas/config/tc-microblaze.c
Brad Bishop26bdd442019-08-16 17:08:17 -040026@@ -917,7 +917,7 @@ md_assemble (char * str)
Brad Bishop286d45c2018-10-02 15:21:57 -040027 unsigned reg2;
28 unsigned reg3;
29 unsigned isize;
30- unsigned int immed, temp;
31+ unsigned int immed, immed2, temp;
32 expressionS exp;
33 char name[20];
34
Brad Bishop26bdd442019-08-16 17:08:17 -040035@@ -1172,7 +1172,76 @@ md_assemble (char * str)
Brad Bishop286d45c2018-10-02 15:21:57 -040036 inst |= (reg2 << RA_LOW) & RA_MASK;
37 inst |= (immed << IMM_LOW) & IMM5_MASK;
38 break;
39+ case INST_TYPE_RD_R1_IMM5_IMM5:
40+ if (strcmp (op_end, ""))
41+ op_end = parse_reg (op_end + 1, &reg1); /* Get rd. */
42+ else
43+ {
44+ as_fatal (_("Error in statement syntax"));
45+ reg1 = 0;
46+ }
47+ if (strcmp (op_end, ""))
48+ op_end = parse_reg (op_end + 1, &reg2); /* Get r1. */
49+ else
50+ {
51+ as_fatal (_("Error in statement syntax"));
52+ reg2 = 0;
53+ }
54+
55+ /* Check for spl registers. */
56+ if (check_spl_reg (&reg1))
57+ as_fatal (_("Cannot use special register with this instruction"));
58+ if (check_spl_reg (&reg2))
59+ as_fatal (_("Cannot use special register with this instruction"));
60
61+ /* Width immediate value. */
62+ if (strcmp (op_end, ""))
63+ op_end = parse_imm (op_end + 1, &exp, MIN_IMM_WIDTH, MAX_IMM_WIDTH);
64+ else
65+ as_fatal (_("Error in statement syntax"));
66+ if (exp.X_op != O_constant)
67+ {
68+ as_warn (_("Symbol used as immediate width value for bit field instruction"));
69+ immed = 1;
70+ }
71+ else
72+ immed = exp.X_add_number;
73+ if (opcode->instr == bsefi && immed > 31)
74+ as_fatal (_("Width value must be less than 32"));
75+
76+ /* Shift immediate value. */
77+ if (strcmp (op_end, ""))
78+ op_end = parse_imm (op_end + 1, &exp, MIN_IMM, MAX_IMM);
79+ else
80+ as_fatal (_("Error in statement syntax"));
81+ if (exp.X_op != O_constant)
82+ {
83+ as_warn (_("Symbol used as immediate shift value for bit field instruction"));
84+ immed2 = 0;
85+ }
86+ else
87+ {
88+ output = frag_more (isize);
89+ immed2 = exp.X_add_number;
90+ }
91+ if (immed2 != (immed2 % 32))
92+ {
93+ as_warn (_("Shift value greater than 32. using <value %% 32>"));
94+ immed2 = immed2 % 32;
95+ }
96+
97+ /* Check combined value. */
98+ if (immed + immed2 > 32)
99+ as_fatal (_("Width value + shift value must not be greater than 32"));
100+
101+ inst |= (reg1 << RD_LOW) & RD_MASK;
102+ inst |= (reg2 << RA_LOW) & RA_MASK;
103+ if (opcode->instr == bsefi)
104+ inst |= (immed & IMM5_MASK) << IMM_WIDTH_LOW; /* bsefi */
105+ else
106+ inst |= ((immed + immed2 - 1) & IMM5_MASK) << IMM_WIDTH_LOW; /* bsifi */
107+ inst |= (immed2 << IMM_LOW) & IMM5_MASK;
108+ break;
109 case INST_TYPE_R1_R2:
110 if (strcmp (op_end, ""))
111 op_end = parse_reg (op_end + 1, &reg1); /* Get r1. */
112diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500113index be1534c257c..52c9068805f 100644
Brad Bishop286d45c2018-10-02 15:21:57 -0400114--- a/opcodes/microblaze-dis.c
115+++ b/opcodes/microblaze-dis.c
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500116@@ -90,6 +90,18 @@ get_field_imm5_mbar (struct string_buf *buf, long instr)
117 return p;
Brad Bishop286d45c2018-10-02 15:21:57 -0400118 }
119
Andrew Geissler84ad7c52020-06-27 00:00:16 -0500120+static char *
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500121+get_field_imm5width (struct string_buf *buf, long instr)
Brad Bishop286d45c2018-10-02 15:21:57 -0400122+{
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500123+ char *p = strbuf (buf);
Brad Bishop286d45c2018-10-02 15:21:57 -0400124+
125+ if (instr & 0x00004000)
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500126+ sprintf (p, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW))); /* bsefi */
Brad Bishop286d45c2018-10-02 15:21:57 -0400127+ else
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500128+ sprintf (p, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW) - ((instr & IMM5_MASK) >> IMM_LOW) + 1)); /* bsifi */
129+ return p;
Brad Bishop286d45c2018-10-02 15:21:57 -0400130+}
131+
Andrew Geissler84ad7c52020-06-27 00:00:16 -0500132 static char *
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500133 get_field_rfsl (struct string_buf *buf, long instr)
Brad Bishop286d45c2018-10-02 15:21:57 -0400134 {
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500135@@ -428,6 +440,11 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
136 case INST_TYPE_NONE:
137 break;
138 /* For tuqula instruction */
Brad Bishop286d45c2018-10-02 15:21:57 -0400139+ /* For bit field insns. */
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500140+ case INST_TYPE_RD_R1_IMM5_IMM5:
141+ print_func (stream, "\t%s, %s, %s, %s", get_field_rd (&buf, inst), get_field_r1(&buf, inst), get_field_imm5width (&buf, inst), get_field_imm5 (&buf, inst));
142+ break;
143+ /* For tuqula instruction */
Brad Bishop286d45c2018-10-02 15:21:57 -0400144 case INST_TYPE_RD:
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500145 print_func (stream, "\t%s", get_field_rd (&buf, inst));
146 break;
Brad Bishop286d45c2018-10-02 15:21:57 -0400147diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500148index c7a506b845a..f61f4ef66d9 100644
Brad Bishop286d45c2018-10-02 15:21:57 -0400149--- a/opcodes/microblaze-opc.h
150+++ b/opcodes/microblaze-opc.h
151@@ -59,6 +59,9 @@
152 /* For mbar. */
153 #define INST_TYPE_IMM5 20
154
155+/* For bsefi and bsifi */
156+#define INST_TYPE_RD_R1_IMM5_IMM5 21
157+
158 #define INST_TYPE_NONE 25
159
160
161@@ -89,7 +92,9 @@
162 #define OPCODE_MASK_H124 0xFFFF07FF /* High 16, and low 11 bits. */
163 #define OPCODE_MASK_H1234 0xFFFFFFFF /* All 32 bits. */
164 #define OPCODE_MASK_H3 0xFC000600 /* High 6 bits and bits 21, 22. */
165+#define OPCODE_MASK_H3B 0xFC00C600 /* High 6 bits and bits 16, 17, 21, 22. */
166 #define OPCODE_MASK_H32 0xFC00FC00 /* High 6 bits and bit 16-21. */
167+#define OPCODE_MASK_H32B 0xFC00C000 /* High 6 bits and bit 16, 17. */
168 #define OPCODE_MASK_H34B 0xFC0000FF /* High 6 bits and low 8 bits. */
169 #define OPCODE_MASK_H35B 0xFC0004FF /* High 6 bits and low 9 bits. */
170 #define OPCODE_MASK_H34C 0xFC0007E0 /* High 6 bits and bits 21-26. */
171@@ -102,7 +107,7 @@
172 #define DELAY_SLOT 1
173 #define NO_DELAY_SLOT 0
174
175-#define MAX_OPCODES 299
176+#define MAX_OPCODES 301
177
178 struct op_code_struct
179 {
180@@ -159,6 +164,8 @@ struct op_code_struct
181 {"bslli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000400, OPCODE_MASK_H3, bslli, barrel_shift_inst },
182 {"bsrai", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000200, OPCODE_MASK_H3, bsrai, barrel_shift_inst },
183 {"bsrli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000000, OPCODE_MASK_H3, bsrli, barrel_shift_inst },
184+ {"bsefi", INST_TYPE_RD_R1_IMM5_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64004000, OPCODE_MASK_H32B, bsefi, barrel_shift_inst },
185+ {"bsifi", INST_TYPE_RD_R1_IMM5_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64008000, OPCODE_MASK_H32B, bsifi, barrel_shift_inst },
186 {"or", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000000, OPCODE_MASK_H4, microblaze_or, logical_inst },
187 {"and", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x84000000, OPCODE_MASK_H4, microblaze_and, logical_inst },
188 {"xor", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000000, OPCODE_MASK_H4, microblaze_xor, logical_inst },
189@@ -438,5 +445,8 @@ char pvr_register_prefix[] = "rpvr";
190 #define MIN_IMM5 ((int) 0x00000000)
191 #define MAX_IMM5 ((int) 0x0000001f)
192
193+#define MIN_IMM_WIDTH ((int) 0x00000001)
194+#define MAX_IMM_WIDTH ((int) 0x00000020)
195+
196 #endif /* MICROBLAZE_OPC */
197
198diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500199index b05e319862e..fa921c90c98 100644
Brad Bishop286d45c2018-10-02 15:21:57 -0400200--- a/opcodes/microblaze-opcm.h
201+++ b/opcodes/microblaze-opcm.h
202@@ -29,7 +29,7 @@ enum microblaze_instr
203 addi, rsubi, addic, rsubic, addik, rsubik, addikc, rsubikc, mul,
204 mulh, mulhu, mulhsu,swapb,swaph,
205 idiv, idivu, bsll, bsra, bsrl, get, put, nget, nput, cget, cput,
206- ncget, ncput, muli, bslli, bsrai, bsrli, mului,
207+ ncget, ncput, muli, bslli, bsrai, bsrli, bsefi, bsifi, mului,
208 /* 'or/and/xor' are C++ keywords. */
209 microblaze_or, microblaze_and, microblaze_xor,
210 andn, pcmpbf, pcmpbc, pcmpeq, pcmpne, sra, src, srl, sext8, sext16,
211@@ -129,6 +129,7 @@ enum microblaze_instr_type
212 #define RB_LOW 11 /* Low bit for RB. */
213 #define IMM_LOW 0 /* Low bit for immediate. */
214 #define IMM_MBAR 21 /* low bit for mbar instruction. */
215+#define IMM_WIDTH_LOW 6 /* Low bit for immediate width */
216
217 #define RD_MASK 0x03E00000
218 #define RA_MASK 0x001F0000
219@@ -141,6 +142,9 @@ enum microblaze_instr_type
220 /* Imm mask for mbar. */
221 #define IMM5_MBAR_MASK 0x03E00000
222
223+/* Imm mask for extract/insert width. */
224+#define IMM5_WIDTH_MASK 0x000007C0
225+
226 /* FSL imm mask for get, put instructions. */
227 #define RFSL_MASK 0x000000F
228
Andrew Geissler84ad7c52020-06-27 00:00:16 -0500229--
2302.17.1
231