blob: 0bc01177980dfe7cec11fadf4cb792725806e375 [file] [log] [blame]
Brad Bishop286d45c2018-10-02 15:21:57 -04001From 5c4dacaae2ba93569c1d37cda9859c57d6649dc0 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nagaraju.mekala@xilinx.com>
3Date: Mon, 28 Aug 2017 19:54:01 -0700
4Subject: [PATCH] Add new MicroBlaze bit-field instructions
5
6This patches adds new bsefi and bsifi instructions. BSEFI- The
7instruction shall extract a bit field from a register and place it
8right-adjusted in the destination register. The other bits in the
9destination register shall be set to zero BSIFI- The instruction shall
10insert a right-adjusted bit field from a register at another position in
11the destination register. The rest of the bits in the destination
12register shall be unchanged
13
14Signed-off-by: Nagaraju Mekala <nagaraju.mekala@xilinx.com>
15Signed-off-by: Manjukumar Matha <manjukumar.harthikote-matha@xilinx.com>
16Upstream-Status: Pending
17---
18 gas/config/tc-microblaze.c | 71 +++++++++++++++++++++++++++++++++++++++++++++-
19 opcodes/microblaze-dis.c | 16 +++++++++++
20 opcodes/microblaze-opc.h | 12 +++++++-
21 opcodes/microblaze-opcm.h | 6 +++-
22 4 files changed, 102 insertions(+), 3 deletions(-)
23
24diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
25index e135547e62..34cb80fac2 100644
26--- a/gas/config/tc-microblaze.c
27+++ b/gas/config/tc-microblaze.c
28@@ -909,7 +909,7 @@ md_assemble (char * str)
29 unsigned reg2;
30 unsigned reg3;
31 unsigned isize;
32- unsigned int immed, temp;
33+ unsigned int immed, immed2, temp;
34 expressionS exp;
35 char name[20];
36
37@@ -1164,7 +1164,76 @@ md_assemble (char * str)
38 inst |= (reg2 << RA_LOW) & RA_MASK;
39 inst |= (immed << IMM_LOW) & IMM5_MASK;
40 break;
41+ case INST_TYPE_RD_R1_IMM5_IMM5:
42+ if (strcmp (op_end, ""))
43+ op_end = parse_reg (op_end + 1, &reg1); /* Get rd. */
44+ else
45+ {
46+ as_fatal (_("Error in statement syntax"));
47+ reg1 = 0;
48+ }
49+ if (strcmp (op_end, ""))
50+ op_end = parse_reg (op_end + 1, &reg2); /* Get r1. */
51+ else
52+ {
53+ as_fatal (_("Error in statement syntax"));
54+ reg2 = 0;
55+ }
56+
57+ /* Check for spl registers. */
58+ if (check_spl_reg (&reg1))
59+ as_fatal (_("Cannot use special register with this instruction"));
60+ if (check_spl_reg (&reg2))
61+ as_fatal (_("Cannot use special register with this instruction"));
62
63+ /* Width immediate value. */
64+ if (strcmp (op_end, ""))
65+ op_end = parse_imm (op_end + 1, &exp, MIN_IMM_WIDTH, MAX_IMM_WIDTH);
66+ else
67+ as_fatal (_("Error in statement syntax"));
68+ if (exp.X_op != O_constant)
69+ {
70+ as_warn (_("Symbol used as immediate width value for bit field instruction"));
71+ immed = 1;
72+ }
73+ else
74+ immed = exp.X_add_number;
75+ if (opcode->instr == bsefi && immed > 31)
76+ as_fatal (_("Width value must be less than 32"));
77+
78+ /* Shift immediate value. */
79+ if (strcmp (op_end, ""))
80+ op_end = parse_imm (op_end + 1, &exp, MIN_IMM, MAX_IMM);
81+ else
82+ as_fatal (_("Error in statement syntax"));
83+ if (exp.X_op != O_constant)
84+ {
85+ as_warn (_("Symbol used as immediate shift value for bit field instruction"));
86+ immed2 = 0;
87+ }
88+ else
89+ {
90+ output = frag_more (isize);
91+ immed2 = exp.X_add_number;
92+ }
93+ if (immed2 != (immed2 % 32))
94+ {
95+ as_warn (_("Shift value greater than 32. using <value %% 32>"));
96+ immed2 = immed2 % 32;
97+ }
98+
99+ /* Check combined value. */
100+ if (immed + immed2 > 32)
101+ as_fatal (_("Width value + shift value must not be greater than 32"));
102+
103+ inst |= (reg1 << RD_LOW) & RD_MASK;
104+ inst |= (reg2 << RA_LOW) & RA_MASK;
105+ if (opcode->instr == bsefi)
106+ inst |= (immed & IMM5_MASK) << IMM_WIDTH_LOW; /* bsefi */
107+ else
108+ inst |= ((immed + immed2 - 1) & IMM5_MASK) << IMM_WIDTH_LOW; /* bsifi */
109+ inst |= (immed2 << IMM_LOW) & IMM5_MASK;
110+ break;
111 case INST_TYPE_R1_R2:
112 if (strcmp (op_end, ""))
113 op_end = parse_reg (op_end + 1, &reg1); /* Get r1. */
114diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
115index 6a174b0eb9..80a47ad2fc 100644
116--- a/opcodes/microblaze-dis.c
117+++ b/opcodes/microblaze-dis.c
118@@ -73,6 +73,18 @@ get_field_imm5_mbar (long instr)
119 return(strdup(tmpstr));
120 }
121
122+static char *
123+get_field_imm5width (long instr)
124+{
125+ char tmpstr[25];
126+
127+ if (instr & 0x00004000)
128+ sprintf (tmpstr, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW))); /* bsefi */
129+ else
130+ sprintf (tmpstr, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW) - ((instr & IMM5_MASK) >> IMM_LOW) + 1)); /* bsifi */
131+ return (strdup (tmpstr));
132+}
133+
134 static char *
135 get_field_rfsl (long instr)
136 {
137@@ -396,6 +408,10 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
138 /* For mbar 16 or sleep insn. */
139 case INST_TYPE_NONE:
140 break;
141+ /* For bit field insns. */
142+ case INST_TYPE_RD_R1_IMM5_IMM5:
143+ print_func (stream, "\t%s, %s, %s, %s", get_field_rd (inst),get_field_r1(inst),get_field_imm5width (inst), get_field_imm5 (inst));
144+ break;
145 /* For tuqula instruction */
146 case INST_TYPE_RD:
147 print_func (stream, "\t%s", get_field_rd (inst));
148diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
149index a64f8362da..afb34989d9 100644
150--- a/opcodes/microblaze-opc.h
151+++ b/opcodes/microblaze-opc.h
152@@ -59,6 +59,9 @@
153 /* For mbar. */
154 #define INST_TYPE_IMM5 20
155
156+/* For bsefi and bsifi */
157+#define INST_TYPE_RD_R1_IMM5_IMM5 21
158+
159 #define INST_TYPE_NONE 25
160
161
162@@ -89,7 +92,9 @@
163 #define OPCODE_MASK_H124 0xFFFF07FF /* High 16, and low 11 bits. */
164 #define OPCODE_MASK_H1234 0xFFFFFFFF /* All 32 bits. */
165 #define OPCODE_MASK_H3 0xFC000600 /* High 6 bits and bits 21, 22. */
166+#define OPCODE_MASK_H3B 0xFC00C600 /* High 6 bits and bits 16, 17, 21, 22. */
167 #define OPCODE_MASK_H32 0xFC00FC00 /* High 6 bits and bit 16-21. */
168+#define OPCODE_MASK_H32B 0xFC00C000 /* High 6 bits and bit 16, 17. */
169 #define OPCODE_MASK_H34B 0xFC0000FF /* High 6 bits and low 8 bits. */
170 #define OPCODE_MASK_H35B 0xFC0004FF /* High 6 bits and low 9 bits. */
171 #define OPCODE_MASK_H34C 0xFC0007E0 /* High 6 bits and bits 21-26. */
172@@ -102,7 +107,7 @@
173 #define DELAY_SLOT 1
174 #define NO_DELAY_SLOT 0
175
176-#define MAX_OPCODES 299
177+#define MAX_OPCODES 301
178
179 struct op_code_struct
180 {
181@@ -159,6 +164,8 @@ struct op_code_struct
182 {"bslli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000400, OPCODE_MASK_H3, bslli, barrel_shift_inst },
183 {"bsrai", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000200, OPCODE_MASK_H3, bsrai, barrel_shift_inst },
184 {"bsrli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000000, OPCODE_MASK_H3, bsrli, barrel_shift_inst },
185+ {"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 },
186+ {"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 },
187 {"or", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000000, OPCODE_MASK_H4, microblaze_or, logical_inst },
188 {"and", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x84000000, OPCODE_MASK_H4, microblaze_and, logical_inst },
189 {"xor", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000000, OPCODE_MASK_H4, microblaze_xor, logical_inst },
190@@ -438,5 +445,8 @@ char pvr_register_prefix[] = "rpvr";
191 #define MIN_IMM5 ((int) 0x00000000)
192 #define MAX_IMM5 ((int) 0x0000001f)
193
194+#define MIN_IMM_WIDTH ((int) 0x00000001)
195+#define MAX_IMM_WIDTH ((int) 0x00000020)
196+
197 #endif /* MICROBLAZE_OPC */
198
199diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
200index 21a3dc8d76..dd6be7f65c 100644
201--- a/opcodes/microblaze-opcm.h
202+++ b/opcodes/microblaze-opcm.h
203@@ -29,7 +29,7 @@ enum microblaze_instr
204 addi, rsubi, addic, rsubic, addik, rsubik, addikc, rsubikc, mul,
205 mulh, mulhu, mulhsu,swapb,swaph,
206 idiv, idivu, bsll, bsra, bsrl, get, put, nget, nput, cget, cput,
207- ncget, ncput, muli, bslli, bsrai, bsrli, mului,
208+ ncget, ncput, muli, bslli, bsrai, bsrli, bsefi, bsifi, mului,
209 /* 'or/and/xor' are C++ keywords. */
210 microblaze_or, microblaze_and, microblaze_xor,
211 andn, pcmpbf, pcmpbc, pcmpeq, pcmpne, sra, src, srl, sext8, sext16,
212@@ -129,6 +129,7 @@ enum microblaze_instr_type
213 #define RB_LOW 11 /* Low bit for RB. */
214 #define IMM_LOW 0 /* Low bit for immediate. */
215 #define IMM_MBAR 21 /* low bit for mbar instruction. */
216+#define IMM_WIDTH_LOW 6 /* Low bit for immediate width */
217
218 #define RD_MASK 0x03E00000
219 #define RA_MASK 0x001F0000
220@@ -141,6 +142,9 @@ enum microblaze_instr_type
221 /* Imm mask for mbar. */
222 #define IMM5_MBAR_MASK 0x03E00000
223
224+/* Imm mask for extract/insert width. */
225+#define IMM5_WIDTH_MASK 0x000007C0
226+
227 /* FSL imm mask for get, put instructions. */
228 #define RFSL_MASK 0x000000F
229
230--
2312.15.0
232