Skip to content

Commit bb0d05f

Browse files
nealfragereagerm
authored andcommitted
opcodes: microblaze: Add new bit-field instructions
This patches adds new bsefi and bsifi instructions. BSEFI- The instruction shall extract a bit field from a register and place it right-adjusted in the destination register. The other bits in the destination register shall be set to zero. BSIFI- The instruction shall insert a right-adjusted bit field from a register at another position in the destination register. The rest of the bits in the destination register shall be unchanged. Further documentation of these instructions can be found here: https://docs.xilinx.com/v/u/en-US/ug984-vivado-microblaze-ref With version 6 of the patch, no new relocation types are added as this was unnecessary for adding the bsefi and bsifi instructions. FIXED: Segfault caused by incorrect termination of microblaze_opcodes. Signed-off-by: nagaraju <[email protected]> Signed-off-by: Ibai Erkiaga <[email protected]> Signed-off-by: Neal Frager <[email protected]> Signed-off-by: Michael J. Eager <[email protected]>
1 parent 30ebc43 commit bb0d05f

File tree

4 files changed

+121
-4
lines changed

4 files changed

+121
-4
lines changed

gas/config/tc-microblaze.c

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ md_assemble (char * str)
915915
unsigned reg2;
916916
unsigned reg3;
917917
unsigned isize;
918-
unsigned int immed = 0, temp;
918+
unsigned int immed = 0, immed2 = 0, temp;
919919
expressionS exp;
920920
char name[20];
921921

@@ -1177,6 +1177,87 @@ md_assemble (char * str)
11771177
inst |= (immed << IMM_LOW) & IMM5_MASK;
11781178
break;
11791179

1180+
case INST_TYPE_RD_R1_IMMW_IMMS:
1181+
if (strcmp (op_end, ""))
1182+
op_end = parse_reg (op_end + 1, &reg1); /* Get rd. */
1183+
else
1184+
{
1185+
as_fatal (_("Error in statement syntax"));
1186+
reg1 = 0;
1187+
}
1188+
1189+
if (strcmp (op_end, ""))
1190+
op_end = parse_reg (op_end + 1, &reg2); /* Get r1. */
1191+
else
1192+
{
1193+
as_fatal (_("Error in statement syntax"));
1194+
reg2 = 0;
1195+
}
1196+
1197+
/* Check for spl registers. */
1198+
if (check_spl_reg (&reg1))
1199+
as_fatal (_("Cannot use special register with this instruction"));
1200+
if (check_spl_reg (&reg2))
1201+
as_fatal (_("Cannot use special register with this instruction"));
1202+
1203+
/* Width immediate value. */
1204+
if (strcmp (op_end, ""))
1205+
op_end = parse_imm (op_end + 1, &exp, MIN_IMM_WIDTH, MAX_IMM_WIDTH);
1206+
else
1207+
as_fatal (_("Error in statement syntax"));
1208+
1209+
if (exp.X_op != O_constant)
1210+
{
1211+
as_warn (_(
1212+
"Symbol used as immediate width value for bit field instruction"));
1213+
immed = 1;
1214+
}
1215+
else
1216+
immed = exp.X_add_number;
1217+
1218+
if (opcode->instr == bsefi && immed > 31)
1219+
as_fatal (_("Width value must be less than 32"));
1220+
1221+
/* Shift immediate value. */
1222+
if (strcmp (op_end, ""))
1223+
op_end = parse_imm (op_end + 1, &exp, MIN_IMM, MAX_IMM);
1224+
else
1225+
as_fatal (_("Error in statement syntax"));
1226+
1227+
if (exp.X_op != O_constant)
1228+
{
1229+
as_warn (_(
1230+
"Symbol used as immediate shift value for bit field instruction"));
1231+
immed2 = 0;
1232+
}
1233+
else
1234+
{
1235+
output = frag_more (isize);
1236+
immed2 = exp.X_add_number;
1237+
}
1238+
1239+
if (immed2 != (immed2 % 32))
1240+
{
1241+
as_warn (_("Shift value greater than 32. using <value %% 32>"));
1242+
immed2 = immed2 % 32;
1243+
}
1244+
1245+
/* Check combined value. */
1246+
if (immed + immed2 > 32)
1247+
as_fatal (_("Width value + shift value must not be greater than 32"));
1248+
1249+
inst |= (reg1 << RD_LOW) & RD_MASK;
1250+
inst |= (reg2 << RA_LOW) & RA_MASK;
1251+
1252+
if (opcode->instr == bsefi)
1253+
inst |= (immed & IMM5_MASK) << IMM_WIDTH_LOW; /* bsefi */
1254+
else
1255+
inst |= ((immed + immed2 - 1) & IMM5_MASK)
1256+
<< IMM_WIDTH_LOW; /* bsifi */
1257+
1258+
inst |= (immed2 << IMM_LOW) & IMM5_MASK;
1259+
break;
1260+
11801261
case INST_TYPE_R1_R2:
11811262
if (strcmp (op_end, ""))
11821263
op_end = parse_reg (op_end + 1, &reg1); /* Get r1. */

opcodes/microblaze-dis.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ get_field_imm5_mbar (struct string_buf *buf, long instr)
9090
return p;
9191
}
9292

93+
static char *
94+
get_field_immw (struct string_buf *buf, long instr)
95+
{
96+
char *p = strbuf (buf);
97+
98+
if (instr & 0x00004000)
99+
sprintf (p, "%d", (short)(((instr & IMM5_WIDTH_MASK)
100+
>> IMM_WIDTH_LOW))); /* bsefi */
101+
else
102+
sprintf (p, "%d", (short)(((instr & IMM5_WIDTH_MASK) >>
103+
IMM_WIDTH_LOW) - ((instr & IMM5_MASK) >>
104+
IMM_LOW) + 1)); /* bsifi */
105+
return p;
106+
}
107+
93108
static char *
94109
get_field_rfsl (struct string_buf *buf, long instr)
95110
{
@@ -427,6 +442,14 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
427442
/* For mbar 16 or sleep insn. */
428443
case INST_TYPE_NONE:
429444
break;
445+
/* For bit field insns. */
446+
case INST_TYPE_RD_R1_IMMW_IMMS:
447+
print_func (stream, "\t%s, %s, %s, %s",
448+
get_field_rd (&buf, inst),
449+
get_field_r1 (&buf, inst),
450+
get_field_immw (&buf, inst),
451+
get_field_imm5 (&buf, inst));
452+
break;
430453
/* For tuqula instruction */
431454
case INST_TYPE_RD:
432455
print_func (stream, "\t%s", get_field_rd (&buf, inst));

opcodes/microblaze-opc.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
/* For mbar. */
6060
#define INST_TYPE_IMM5 20
6161

62+
/* For bsefi and bsifi */
63+
#define INST_TYPE_RD_R1_IMMW_IMMS 21
64+
6265
#define INST_TYPE_NONE 25
6366

6467

@@ -90,6 +93,7 @@
9093
#define OPCODE_MASK_H1234 0xFFFFFFFF /* All 32 bits. */
9194
#define OPCODE_MASK_H3 0xFC000600 /* High 6 bits and bits 21, 22. */
9295
#define OPCODE_MASK_H32 0xFC00FC00 /* High 6 bits and bit 16-21. */
96+
#define OPCODE_MASK_H32B 0xFC00C000 /* High 6 bits and bit 16, 17. */
9397
#define OPCODE_MASK_H34B 0xFC0000FF /* High 6 bits and low 8 bits. */
9498
#define OPCODE_MASK_H35B 0xFC0004FF /* High 6 bits and low 9 bits. */
9599
#define OPCODE_MASK_H34C 0xFC0007E0 /* High 6 bits and bits 21-26. */
@@ -102,7 +106,7 @@
102106
#define DELAY_SLOT 1
103107
#define NO_DELAY_SLOT 0
104108

105-
#define MAX_OPCODES 300
109+
#define MAX_OPCODES 291
106110

107111
const struct op_code_struct
108112
{
@@ -159,6 +163,8 @@ const struct op_code_struct
159163
{"bslli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000400, OPCODE_MASK_H3, bslli, barrel_shift_inst },
160164
{"bsrai", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000200, OPCODE_MASK_H3, bsrai, barrel_shift_inst },
161165
{"bsrli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000000, OPCODE_MASK_H3, bsrli, barrel_shift_inst },
166+
{"bsefi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64004000, OPCODE_MASK_H32B, bsefi, barrel_shift_inst },
167+
{"bsifi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64008000, OPCODE_MASK_H32B, bsifi, barrel_shift_inst },
162168
{"or", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000000, OPCODE_MASK_H4, microblaze_or, logical_inst },
163169
{"and", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x84000000, OPCODE_MASK_H4, microblaze_and, logical_inst },
164170
{"xor", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000000, OPCODE_MASK_H4, microblaze_xor, logical_inst },
@@ -418,7 +424,7 @@ const struct op_code_struct
418424
{"suspend", INST_TYPE_NONE, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBB020004, OPCODE_MASK_HN, invalid_inst, special_inst }, /* translates to mbar 24. */
419425
{"swapb", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900001E0, OPCODE_MASK_H4, swapb, arithmetic_inst },
420426
{"swaph", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900001E2, OPCODE_MASK_H4, swaph, arithmetic_inst },
421-
{"", 0, 0, 0, 0, 0, 0, 0, 0},
427+
{NULL, 0, 0, 0, 0, 0, 0, 0, 0},
422428
};
423429

424430
/* Prefix for register names. */
@@ -438,5 +444,8 @@ char pvr_register_prefix[] = "rpvr";
438444
#define MIN_IMM5 ((int) 0x00000000)
439445
#define MAX_IMM5 ((int) 0x0000001f)
440446

447+
#define MIN_IMM_WIDTH ((int) 0x00000001)
448+
#define MAX_IMM_WIDTH ((int) 0x00000020)
449+
441450
#endif /* MICROBLAZE_OPC */
442451

opcodes/microblaze-opcm.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum microblaze_instr
2929
addi, rsubi, addic, rsubic, addik, rsubik, addikc, rsubikc, mul,
3030
mulh, mulhu, mulhsu, swapb, swaph,
3131
idiv, idivu, bsll, bsra, bsrl, get, put, nget, nput, cget, cput,
32-
ncget, ncput, muli, bslli, bsrai, bsrli, mului,
32+
ncget, ncput, muli, bslli, bsrai, bsrli, bsefi, bsifi, mului,
3333
/* 'or/and/xor' are C++ keywords. */
3434
microblaze_or, microblaze_and, microblaze_xor,
3535
andn, pcmpbf, pcmpbc, pcmpeq, pcmpne, sra, src, srl, sext8, sext16,
@@ -130,6 +130,7 @@ enum microblaze_instr_type
130130
#define RB_LOW 11 /* Low bit for RB. */
131131
#define IMM_LOW 0 /* Low bit for immediate. */
132132
#define IMM_MBAR 21 /* low bit for mbar instruction. */
133+
#define IMM_WIDTH_LOW 6 /* Low bit for immediate width */
133134

134135
#define RD_MASK 0x03E00000
135136
#define RA_MASK 0x001F0000
@@ -142,6 +143,9 @@ enum microblaze_instr_type
142143
/* Imm mask for mbar. */
143144
#define IMM5_MBAR_MASK 0x03E00000
144145

146+
/* Imm mask for extract/insert width. */
147+
#define IMM5_WIDTH_MASK 0x000007C0
148+
145149
/* FSL imm mask for get, put instructions. */
146150
#define RFSL_MASK 0x000000F
147151

0 commit comments

Comments
 (0)