blob: 0188629db2d650aa0234e2a902e15afded9c2998 [file] [log] [blame]
Andrew Geissler10fa1492020-12-11 16:25:29 -06001From cea8d524fca305c2878374433d9745b938e4c78f 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 Geissler10fa1492020-12-11 16:25:29 -06004Subject: [PATCH 09/52] 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>
Andrew Geissler10fa1492020-12-11 16:25:29 -060015
16Conflicts:
17 opcodes/microblaze-dis.c
Brad Bishop286d45c2018-10-02 15:21:57 -040018---
Andrew Geissler84ad7c52020-06-27 00:00:16 -050019 gas/config/tc-microblaze.c | 71 +++++++++++++++++++++++++++++++++++++-
Andrew Geissler10fa1492020-12-11 16:25:29 -060020 opcodes/microblaze-dis.c | 20 +++++++++--
Andrew Geissler84ad7c52020-06-27 00:00:16 -050021 opcodes/microblaze-opc.h | 12 ++++++-
Brad Bishop286d45c2018-10-02 15:21:57 -040022 opcodes/microblaze-opcm.h | 6 +++-
Andrew Geissler10fa1492020-12-11 16:25:29 -060023 4 files changed, 104 insertions(+), 5 deletions(-)
Brad Bishop286d45c2018-10-02 15:21:57 -040024
25diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
Andrew Geissler10fa1492020-12-11 16:25:29 -060026index 74a63abeb0..765abfb388 100644
Brad Bishop286d45c2018-10-02 15:21:57 -040027--- a/gas/config/tc-microblaze.c
28+++ b/gas/config/tc-microblaze.c
Brad Bishop26bdd442019-08-16 17:08:17 -040029@@ -917,7 +917,7 @@ md_assemble (char * str)
Brad Bishop286d45c2018-10-02 15:21:57 -040030 unsigned reg2;
31 unsigned reg3;
32 unsigned isize;
33- unsigned int immed, temp;
34+ unsigned int immed, immed2, temp;
35 expressionS exp;
36 char name[20];
37
Brad Bishop26bdd442019-08-16 17:08:17 -040038@@ -1172,7 +1172,76 @@ md_assemble (char * str)
Brad Bishop286d45c2018-10-02 15:21:57 -040039 inst |= (reg2 << RA_LOW) & RA_MASK;
40 inst |= (immed << IMM_LOW) & IMM5_MASK;
41 break;
42+ case INST_TYPE_RD_R1_IMM5_IMM5:
43+ if (strcmp (op_end, ""))
44+ op_end = parse_reg (op_end + 1, &reg1); /* Get rd. */
45+ else
46+ {
47+ as_fatal (_("Error in statement syntax"));
48+ reg1 = 0;
49+ }
50+ if (strcmp (op_end, ""))
51+ op_end = parse_reg (op_end + 1, &reg2); /* Get r1. */
52+ else
53+ {
54+ as_fatal (_("Error in statement syntax"));
55+ reg2 = 0;
56+ }
57+
58+ /* Check for spl registers. */
59+ if (check_spl_reg (&reg1))
60+ as_fatal (_("Cannot use special register with this instruction"));
61+ if (check_spl_reg (&reg2))
62+ as_fatal (_("Cannot use special register with this instruction"));
63
64+ /* Width immediate value. */
65+ if (strcmp (op_end, ""))
66+ op_end = parse_imm (op_end + 1, &exp, MIN_IMM_WIDTH, MAX_IMM_WIDTH);
67+ else
68+ as_fatal (_("Error in statement syntax"));
69+ if (exp.X_op != O_constant)
70+ {
71+ as_warn (_("Symbol used as immediate width value for bit field instruction"));
72+ immed = 1;
73+ }
74+ else
75+ immed = exp.X_add_number;
76+ if (opcode->instr == bsefi && immed > 31)
77+ as_fatal (_("Width value must be less than 32"));
78+
79+ /* Shift immediate value. */
80+ if (strcmp (op_end, ""))
81+ op_end = parse_imm (op_end + 1, &exp, MIN_IMM, MAX_IMM);
82+ else
83+ as_fatal (_("Error in statement syntax"));
84+ if (exp.X_op != O_constant)
85+ {
86+ as_warn (_("Symbol used as immediate shift value for bit field instruction"));
87+ immed2 = 0;
88+ }
89+ else
90+ {
91+ output = frag_more (isize);
92+ immed2 = exp.X_add_number;
93+ }
94+ if (immed2 != (immed2 % 32))
95+ {
96+ as_warn (_("Shift value greater than 32. using <value %% 32>"));
97+ immed2 = immed2 % 32;
98+ }
99+
100+ /* Check combined value. */
101+ if (immed + immed2 > 32)
102+ as_fatal (_("Width value + shift value must not be greater than 32"));
103+
104+ inst |= (reg1 << RD_LOW) & RD_MASK;
105+ inst |= (reg2 << RA_LOW) & RA_MASK;
106+ if (opcode->instr == bsefi)
107+ inst |= (immed & IMM5_MASK) << IMM_WIDTH_LOW; /* bsefi */
108+ else
109+ inst |= ((immed + immed2 - 1) & IMM5_MASK) << IMM_WIDTH_LOW; /* bsifi */
110+ inst |= (immed2 << IMM_LOW) & IMM5_MASK;
111+ break;
112 case INST_TYPE_R1_R2:
113 if (strcmp (op_end, ""))
114 op_end = parse_reg (op_end + 1, &reg1); /* Get r1. */
115diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
Andrew Geissler10fa1492020-12-11 16:25:29 -0600116index be1534c257..315c6e9350 100644
Brad Bishop286d45c2018-10-02 15:21:57 -0400117--- a/opcodes/microblaze-dis.c
118+++ b/opcodes/microblaze-dis.c
Andrew Geissler10fa1492020-12-11 16:25:29 -0600119@@ -91,7 +91,19 @@ get_field_imm5_mbar (struct string_buf *buf, long instr)
Brad Bishop286d45c2018-10-02 15:21:57 -0400120 }
121
Andrew Geissler10fa1492020-12-11 16:25:29 -0600122 static char *
123-get_field_rfsl (struct string_buf *buf, long instr)
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500124+get_field_imm5width (struct string_buf *buf, long instr)
Brad Bishop286d45c2018-10-02 15:21:57 -0400125+{
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500126+ char *p = strbuf (buf);
Brad Bishop286d45c2018-10-02 15:21:57 -0400127+
128+ if (instr & 0x00004000)
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500129+ sprintf (p, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW))); /* bsefi */
Brad Bishop286d45c2018-10-02 15:21:57 -0400130+ else
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500131+ sprintf (p, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW) - ((instr & IMM5_MASK) >> IMM_LOW) + 1)); /* bsifi */
132+ return p;
Brad Bishop286d45c2018-10-02 15:21:57 -0400133+}
134+
Andrew Geissler10fa1492020-12-11 16:25:29 -0600135+static char *
136+get_field_rfsl (struct string_buf *buf,long instr)
Brad Bishop286d45c2018-10-02 15:21:57 -0400137 {
Andrew Geissler10fa1492020-12-11 16:25:29 -0600138 char *p = strbuf (buf);
139
140@@ -427,7 +439,11 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
141 /* For mbar 16 or sleep insn. */
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500142 case INST_TYPE_NONE:
143 break;
Andrew Geissler10fa1492020-12-11 16:25:29 -0600144- /* For tuqula instruction */
Brad Bishop286d45c2018-10-02 15:21:57 -0400145+ /* For bit field insns. */
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500146+ case INST_TYPE_RD_R1_IMM5_IMM5:
Andrew Geissler10fa1492020-12-11 16:25:29 -0600147+ 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));
148+ break;
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500149+ /* For tuqula instruction */
Brad Bishop286d45c2018-10-02 15:21:57 -0400150 case INST_TYPE_RD:
Andrew Geisslera9ff2b32020-10-16 10:11:54 -0500151 print_func (stream, "\t%s", get_field_rd (&buf, inst));
152 break;
Brad Bishop286d45c2018-10-02 15:21:57 -0400153diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
Andrew Geissler10fa1492020-12-11 16:25:29 -0600154index c7a506b845..f61f4ef66d 100644
Brad Bishop286d45c2018-10-02 15:21:57 -0400155--- a/opcodes/microblaze-opc.h
156+++ b/opcodes/microblaze-opc.h
157@@ -59,6 +59,9 @@
158 /* For mbar. */
159 #define INST_TYPE_IMM5 20
160
161+/* For bsefi and bsifi */
162+#define INST_TYPE_RD_R1_IMM5_IMM5 21
163+
164 #define INST_TYPE_NONE 25
165
166
167@@ -89,7 +92,9 @@
168 #define OPCODE_MASK_H124 0xFFFF07FF /* High 16, and low 11 bits. */
169 #define OPCODE_MASK_H1234 0xFFFFFFFF /* All 32 bits. */
170 #define OPCODE_MASK_H3 0xFC000600 /* High 6 bits and bits 21, 22. */
171+#define OPCODE_MASK_H3B 0xFC00C600 /* High 6 bits and bits 16, 17, 21, 22. */
172 #define OPCODE_MASK_H32 0xFC00FC00 /* High 6 bits and bit 16-21. */
173+#define OPCODE_MASK_H32B 0xFC00C000 /* High 6 bits and bit 16, 17. */
174 #define OPCODE_MASK_H34B 0xFC0000FF /* High 6 bits and low 8 bits. */
175 #define OPCODE_MASK_H35B 0xFC0004FF /* High 6 bits and low 9 bits. */
176 #define OPCODE_MASK_H34C 0xFC0007E0 /* High 6 bits and bits 21-26. */
177@@ -102,7 +107,7 @@
178 #define DELAY_SLOT 1
179 #define NO_DELAY_SLOT 0
180
181-#define MAX_OPCODES 299
182+#define MAX_OPCODES 301
183
184 struct op_code_struct
185 {
186@@ -159,6 +164,8 @@ struct op_code_struct
187 {"bslli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000400, OPCODE_MASK_H3, bslli, barrel_shift_inst },
188 {"bsrai", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000200, OPCODE_MASK_H3, bsrai, barrel_shift_inst },
189 {"bsrli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000000, OPCODE_MASK_H3, bsrli, barrel_shift_inst },
190+ {"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 },
191+ {"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 },
192 {"or", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000000, OPCODE_MASK_H4, microblaze_or, logical_inst },
193 {"and", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x84000000, OPCODE_MASK_H4, microblaze_and, logical_inst },
194 {"xor", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000000, OPCODE_MASK_H4, microblaze_xor, logical_inst },
195@@ -438,5 +445,8 @@ char pvr_register_prefix[] = "rpvr";
196 #define MIN_IMM5 ((int) 0x00000000)
197 #define MAX_IMM5 ((int) 0x0000001f)
198
199+#define MIN_IMM_WIDTH ((int) 0x00000001)
200+#define MAX_IMM_WIDTH ((int) 0x00000020)
201+
202 #endif /* MICROBLAZE_OPC */
203
204diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
Andrew Geissler10fa1492020-12-11 16:25:29 -0600205index b05e319862..fa921c90c9 100644
Brad Bishop286d45c2018-10-02 15:21:57 -0400206--- a/opcodes/microblaze-opcm.h
207+++ b/opcodes/microblaze-opcm.h
208@@ -29,7 +29,7 @@ enum microblaze_instr
209 addi, rsubi, addic, rsubic, addik, rsubik, addikc, rsubikc, mul,
210 mulh, mulhu, mulhsu,swapb,swaph,
211 idiv, idivu, bsll, bsra, bsrl, get, put, nget, nput, cget, cput,
212- ncget, ncput, muli, bslli, bsrai, bsrli, mului,
213+ ncget, ncput, muli, bslli, bsrai, bsrli, bsefi, bsifi, mului,
214 /* 'or/and/xor' are C++ keywords. */
215 microblaze_or, microblaze_and, microblaze_xor,
216 andn, pcmpbf, pcmpbc, pcmpeq, pcmpne, sra, src, srl, sext8, sext16,
217@@ -129,6 +129,7 @@ enum microblaze_instr_type
218 #define RB_LOW 11 /* Low bit for RB. */
219 #define IMM_LOW 0 /* Low bit for immediate. */
220 #define IMM_MBAR 21 /* low bit for mbar instruction. */
221+#define IMM_WIDTH_LOW 6 /* Low bit for immediate width */
222
223 #define RD_MASK 0x03E00000
224 #define RA_MASK 0x001F0000
225@@ -141,6 +142,9 @@ enum microblaze_instr_type
226 /* Imm mask for mbar. */
227 #define IMM5_MBAR_MASK 0x03E00000
228
229+/* Imm mask for extract/insert width. */
230+#define IMM5_WIDTH_MASK 0x000007C0
231+
232 /* FSL imm mask for get, put instructions. */
233 #define RFSL_MASK 0x000000F
234
Andrew Geissler84ad7c52020-06-27 00:00:16 -0500235--
2362.17.1
237