1 `include "ARM_Constants.v"
10 output reg [31:0] op2,
21 wire [31:0] regs0, regs1, regs2, rpc;
22 wire [31:0] op0_out, op1_out, op2_out;
26 wire [31:0] shift_oper;
27 wire [31:0] shift_res;
29 wire [31:0] rotate_res;
31 assign regs0 = (read_0 == 4'b1111) ? rpc : rdata_0;
32 assign regs1 = (read_1 == 4'b1111) ? rpc : rdata_1;
33 assign regs2 = rdata_2; /* use regs2 for things that cannot be r15 */
35 IREALLYHATEARMSHIFT blowme(.insn(insn),
38 .cflag_in(incpsr[`CPSR_C]),
40 .cflag_out(shift_cflag_out));
42 SuckLessRotator whirr(.oper({24'b0, insn[7:0]}),
48 32'b????000000??????????????1001????, /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
49 // 32'b????00001???????????????1001????, /* Multiply long */
50 32'b????00010?001111????000000000000, /* MRS (Transfer PSR to register) */
51 32'b????00010?101001111100000000????, /* MSR (Transfer register to PSR) */
52 32'b????00?10?1010001111????????????, /* MSR (Transfer register or immediate to PSR, flag bits only) */
53 32'b????00010?00????????00001001????, /* Atomic swap */
54 32'b????000100101111111111110001????, /* Branch and exchange */
55 32'b????000??0??????????00001??1????, /* Halfword transfer - register offset */
56 32'b????000??1??????????00001??1????, /* Halfword transfer - register offset */
57 32'b????011????????????????????1????, /* Undefined. I hate ARM */
58 32'b????01??????????????????????????, /* Single data transfer */
59 32'b????100?????????????????????????, /* Block data transfer */
60 32'b????101?????????????????????????, /* Branch */
61 32'b????110?????????????????????????, /* Coprocessor data transfer */
62 32'b????1110???????????????????0????, /* Coprocessor data op */
63 32'b????1110???????????????????1????, /* Coprocessor register transfer */
64 32'b????1111????????????????????????: /* SWI */
66 32'b????00??????????????????????????: /* ALU */
67 rpc = inpc - (insn[25] ? 8 : (insn[4] ? 12 : 8));
68 default: /* X everything else out */
78 32'b????000000??????????????1001????: /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
80 read_0 = insn[15:12]; /* Rn */
81 read_1 = insn[3:0]; /* Rm */
82 read_2 = insn[11:8]; /* Rs */
84 // 32'b????00001???????????????1001????, /* Multiply long */
85 // read_0 = insn[11:8]; /* Rn */
86 // read_1 = insn[3:0]; /* Rm */
87 // read_2 = 4'b0; /* anyus */
88 32'b????00010?001111????000000000000: /* MRS (Transfer PSR to register) */
90 32'b????00010?101001111100000000????, /* MSR (Transfer register to PSR) */
91 32'b????00?10?1010001111????????????: /* MSR (Transfer register or immediate to PSR, flag bits only) */
92 read_0 = insn[3:0]; /* Rm */
93 32'b????00??????????????????????????: /* ALU */
95 read_0 = insn[19:16]; /* Rn */
96 read_1 = insn[3:0]; /* Rm */
97 read_2 = insn[11:8]; /* Rs for shift */
99 32'b????00010?00????????00001001????: /* Atomic swap */
101 read_0 = insn[19:16]; /* Rn */
102 read_1 = insn[3:0]; /* Rm */
104 32'b????000100101111111111110001????: /* Branch and exchange */
105 read_0 = insn[3:0]; /* Rn */
106 32'b????000??0??????????00001??1????: /* Halfword transfer - register offset */
108 read_0 = insn[19:16];
111 32'b????000??1??????????00001??1????: /* Halfword transfer - immediate offset */
113 read_0 = insn[19:16];
115 32'b????011????????????????????1????: /* Undefined. I hate ARM */
117 32'b????01??????????????????????????: /* Single data transfer */
119 read_0 = insn[19:16]; /* Rn */
120 read_1 = insn[3:0]; /* Rm */
122 32'b????100?????????????????????????: /* Block data transfer */
123 read_0 = insn[19:16];
124 32'b????101?????????????????????????: /* Branch */
126 32'b????110?????????????????????????: /* Coprocessor data transfer */
127 read_0 = insn[19:16];
128 32'b????1110???????????????????0????: /* Coprocessor data op */
130 32'b????1110???????????????????1????: /* Coprocessor register transfer */
131 read_0 = insn[15:12];
132 32'b????1111????????????????????????: /* SWI */
135 $display("Undecoded instruction");
140 op0_out = 32'hxxxxxxxx;
141 op1_out = 32'hxxxxxxxx;
142 op2_out = 32'hxxxxxxxx;
145 32'b????000000??????????????1001????: begin /* Multiply */
150 // 32'b????00001???????????????1001????: begin /* Multiply long */
153 32'b????00010?001111????000000000000: begin /* MRS (Transfer PSR to register) */
155 32'b????00010?101001111100000000????: begin /* MSR (Transfer register to PSR) */
158 32'b????00?10?1010001111????????????: begin /* MSR (Transfer register or immediate to PSR, flag bits only) */
159 if(insn[25]) begin /* the constant case */
160 op0_out = rotate_res;
165 32'b????00??????????????????????????: begin /* ALU */
167 if(insn[25]) begin /* the constant case */
168 carry_out = incpsr[`CPSR_C];
169 op1_out = rotate_res;
171 carry_out = shift_cflag_out;
175 32'b????00010?00????????00001001????: begin /* Atomic swap */
179 32'b????000100101111111111110001????: begin /* Branch and exchange */
182 32'b????000??0??????????00001??1????: begin /* Halfword transfer - register offset */
186 32'b????000??1??????????00001??1????: begin /* Halfword transfer - immediate offset */
188 op1_out = {24'b0, insn[11:8], insn[3:0]};
190 32'b????011????????????????????1????: begin /* Undefined. I hate ARM */
193 32'b????01??????????????????????????: begin /* Single data transfer */
196 op1_out = {20'b0, insn[11:0]};
197 carry_out = incpsr[`CPSR_C];
200 carry_out = shift_cflag_out;
203 32'b????100?????????????????????????: begin /* Block data transfer */
205 op1_out = {16'b0, insn[15:0]};
207 32'b????101?????????????????????????: begin /* Branch */
208 op0_out = {{6{insn[23]}}, insn[23:0], 2'b0};
210 32'b????110?????????????????????????: begin /* Coprocessor data transfer */
212 op1_out = {24'b0, insn[7:0]};
214 32'b????1110???????????????????0????: begin /* Coprocessor data op */
216 32'b????1110???????????????????1????: begin /* Coprocessor register transfer */
219 32'b????1111????????????????????????: begin /* SWI */
225 always @ (posedge clk) begin
226 op0 <= op0_out; /* Rn - always */
227 op1 <= op1_out; /* 'operand 2' - Rm */
228 op2 <= op2_out; /* thirdedge - Rs */
234 module IREALLYHATEARMSHIFT(
236 input [31:0] operand,
237 input [31:0] reg_amt,
242 wire [5:0] shift_amt;
243 wire rshift_cout, is_arith, is_rot;
244 wire [31:0] rshift_res;
246 assign shift_amt = insn[4] ? {|reg_amt[7:5], reg_amt[4:0]} /* reg-specified shift */
247 : {insn[11:7] == 5'b0, insn[11:7]}; /* immediate shift */
249 SuckLessShifter biteme(.oper(operand),
255 .carryout(rshift_cout));
279 case (insn[6:5]) /* shift type */
281 {cflag_out, res} = {cflag_in, operand} << {insn[4] & shift_amt[5], shift_amt[4:0]};
284 cflag_out = rshift_cout;
288 cflag_out = rshift_cout;
291 if(!insn[4] && shift_amt[4:0] == 5'b0) begin /* RRX x.x */
292 res = {cflag_in, operand[31:1]};
293 cflag_out = operand[0];
296 cflag_out = rshift_cout;
302 module SuckLessShifter(
312 wire [32:0] stage1, stage2, stage3, stage4, stage5;
314 wire pushbits = is_arith & oper[31];
316 /* do a barrel shift */
317 assign stage1 = amt[5] ? {is_rot ? oper : {32{pushbits}}, oper[31]} : {oper, carryin};
318 assign stage2 = amt[4] ? {is_rot ? stage1[15:0] : {16{pushbits}}, stage1[31:16], stage1[15]} : stage1;
319 assign stage3 = amt[3] ? {is_rot ? stage2[7:0] : {8{pushbits}}, stage2[31:8], stage2[7]} : stage2;
320 assign stage4 = amt[2] ? {is_rot ? stage3[3:0] : {4{pushbits}}, stage3[31:4], stage3[3]} : stage3;
321 assign stage5 = amt[1] ? {is_rot ? stage4[1:0] : {2{pushbits}}, stage4[31:2], stage4[1]} : stage4;
322 assign {res, carryout} = amt[0] ? {is_rot ? stage5[0] : pushbits, stage5[31:1], stage5[0]} : stage5;
326 module SuckLessRotator(
332 wire [31:0] stage1, stage2, stage3;
333 assign stage1 = amt[3] ? {oper[15:0], oper[31:16]} : oper;
334 assign stage2 = amt[2] ? {stage1[7:0], stage1[31:8]} : stage1;
335 assign stage3 = amt[1] ? {stage2[3:0], stage2[31:4]} : stage2;
336 assign res = amt[0] ? {stage3[1:0], stage3[31:2]} : stage3;