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;
30 assign regs0 = (read_0 == 4'b1111) ? rpc : rdata_0;
31 assign regs1 = (read_1 == 4'b1111) ? rpc : rdata_1;
32 assign regs2 = rdata_2; /* use regs2 for things that cannot be r15 */
34 IREALLYHATEARMSHIFT blowme(.insn(insn),
37 .cflag_in(incpsr[`CPSR_C]),
39 .cflag_out(shift_cflag_out));
43 32'b????000000??????????????1001????, /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
44 // 32'b????00001???????????????1001????, /* Multiply long */
45 32'b????00010?001111????000000000000, /* MRS (Transfer PSR to register) */
46 32'b????00010?101001111100000000????, /* MSR (Transfer register to PSR) */
47 32'b????00?10?1010001111????????????, /* MSR (Transfer register or immediate to PSR, flag bits only) */
48 32'b????00010?00????????00001001????, /* Atomic swap */
49 32'b????000100101111111111110001????, /* Branch and exchange */
50 32'b????000??0??????????00001??1????, /* Halfword transfer - register offset */
51 32'b????000??1??????????00001??1????, /* Halfword transfer - register offset */
52 32'b????011????????????????????1????, /* Undefined. I hate ARM */
53 32'b????01??????????????????????????, /* Single data transfer */
54 32'b????100?????????????????????????, /* Block data transfer */
55 32'b????101?????????????????????????, /* Branch */
56 32'b????110?????????????????????????, /* Coprocessor data transfer */
57 32'b????1110???????????????????0????, /* Coprocessor data op */
58 32'b????1110???????????????????1????, /* Coprocessor register transfer */
59 32'b????1111????????????????????????: /* SWI */
61 32'b????00??????????????????????????: /* ALU */
62 rpc = inpc - (insn[25] ? 8 : (insn[4] ? 12 : 8));
63 default: /* X everything else out */
73 32'b????000000??????????????1001????: /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
75 read_0 = insn[15:12]; /* Rn */
76 read_1 = insn[3:0]; /* Rm */
77 read_2 = insn[11:8]; /* Rs */
79 // 32'b????00001???????????????1001????, /* Multiply long */
80 // read_0 = insn[11:8]; /* Rn */
81 // read_1 = insn[3:0]; /* Rm */
82 // read_2 = 4'b0; /* anyus */
83 32'b????00010?001111????000000000000: /* MRS (Transfer PSR to register) */
85 32'b????00010?101001111100000000????, /* MSR (Transfer register to PSR) */
86 32'b????00?10?1010001111????????????: /* MSR (Transfer register or immediate to PSR, flag bits only) */
87 read_0 = insn[3:0]; /* Rm */
88 32'b????00??????????????????????????: /* ALU */
90 read_0 = insn[19:16]; /* Rn */
91 read_1 = insn[3:0]; /* Rm */
92 read_2 = insn[11:8]; /* Rs for shift */
94 32'b????00010?00????????00001001????: /* Atomic swap */
96 read_0 = insn[19:16]; /* Rn */
97 read_1 = insn[3:0]; /* Rm */
99 32'b????000100101111111111110001????: /* Branch and exchange */
100 read_0 = insn[3:0]; /* Rn */
101 32'b????000??0??????????00001??1????: /* Halfword transfer - register offset */
103 read_0 = insn[19:16];
106 32'b????000??1??????????00001??1????: /* Halfword transfer - immediate offset */
108 read_0 = insn[19:16];
110 32'b????011????????????????????1????: /* Undefined. I hate ARM */
112 32'b????01??????????????????????????: /* Single data transfer */
114 read_0 = insn[19:16]; /* Rn */
115 read_1 = insn[3:0]; /* Rm */
117 32'b????100?????????????????????????: /* Block data transfer */
118 read_0 = insn[19:16];
119 32'b????101?????????????????????????: /* Branch */
121 32'b????110?????????????????????????: /* Coprocessor data transfer */
122 read_0 = insn[19:16];
123 32'b????1110???????????????????0????: /* Coprocessor data op */
125 32'b????1110???????????????????1????: /* Coprocessor register transfer */
126 read_0 = insn[15:12];
127 32'b????1111????????????????????????: /* SWI */
130 $display("Undecoded instruction");
135 op0_out = 32'hxxxxxxxx;
136 op1_out = 32'hxxxxxxxx;
137 op2_out = 32'hxxxxxxxx;
140 32'b????000000??????????????1001????: begin /* Multiply */
145 // 32'b????00001???????????????1001????: begin /* Multiply long */
148 32'b????00010?001111????000000000000: begin /* MRS (Transfer PSR to register) */
150 32'b????00010?101001111100000000????: begin /* MSR (Transfer register to PSR) */
153 32'b????00?10?1010001111????????????: begin /* MSR (Transfer register or immediate to PSR, flag bits only) */
154 if(insn[25]) begin /* the constant case */
155 op0_out = ({24'b0, insn[7:0]} >> {insn[11:8], 1'b0}) | ({24'b0, insn[7:0]} << (5'b0 - {insn[11:8], 1'b0}));
160 32'b????00??????????????????????????: begin /* ALU */
162 if(insn[25]) begin /* the constant case */
163 carry_out = incpsr[`CPSR_C];
164 op1_out = ({24'b0, insn[7:0]} >> {insn[11:8], 1'b0}) | ({24'b0, insn[7:0]} << (5'b0 - {insn[11:8], 1'b0}));
166 carry_out = shift_cflag_out;
170 32'b????00010?00????????00001001????: begin /* Atomic swap */
174 32'b????000100101111111111110001????: begin /* Branch and exchange */
177 32'b????000??0??????????00001??1????: begin /* Halfword transfer - register offset */
181 32'b????000??1??????????00001??1????: begin /* Halfword transfer - immediate offset */
183 op1_out = {24'b0, insn[11:8], insn[3:0]};
185 32'b????011????????????????????1????: begin /* Undefined. I hate ARM */
188 32'b????01??????????????????????????: begin /* Single data transfer */
191 op1_out = {20'b0, insn[11:0]};
192 carry_out = incpsr[`CPSR_C];
195 carry_out = shift_cflag_out;
198 32'b????100?????????????????????????: begin /* Block data transfer */
200 op1_out = {16'b0, insn[15:0]};
202 32'b????101?????????????????????????: begin /* Branch */
203 op0_out = {{6{insn[23]}}, insn[23:0], 2'b0};
205 32'b????110?????????????????????????: begin /* Coprocessor data transfer */
207 op1_out = {24'b0, insn[7:0]};
209 32'b????1110???????????????????0????: begin /* Coprocessor data op */
211 32'b????1110???????????????????1????: begin /* Coprocessor register transfer */
214 32'b????1111????????????????????????: begin /* SWI */
220 always @ (posedge clk) begin
221 op0 <= op0_out; /* Rn - always */
222 op1 <= op1_out; /* 'operand 2' - Rm */
223 op2 <= op2_out; /* thirdedge - Rs */
229 module IREALLYHATEARMSHIFT(
231 input [31:0] operand,
232 input [31:0] reg_amt,
237 wire [5:0] shift_amt;
238 wire rshift_cout, is_arith, is_rot;
239 wire [31:0] rshift_res;
241 assign shift_amt = insn[4] ? {|reg_amt[7:5], reg_amt[4:0]} /* reg-specified shift */
242 : {insn[11:7] == 5'b0, insn[11:7]}; /* immediate shift */
244 SuckLessShifter biteme(.oper(operand),
250 .carryout(rshift_cout));
274 case (insn[6:5]) /* shift type */
276 {cflag_out, res} = {cflag_in, operand} << {insn[4] & shift_amt[5], shift_amt[4:0]};
279 cflag_out = rshift_cout;
283 cflag_out = rshift_cout;
286 if(!insn[4] && shift_amt[4:0] == 5'b0) begin /* RRX x.x */
287 res = {cflag_in, operand[31:1]};
288 cflag_out = operand[0];
291 cflag_out = rshift_cout;
297 module SuckLessShifter(
307 wire [32:0] stage1, stage2, stage3, stage4, stage5;
309 wire pushbits = is_arith & oper[31];
311 /* do a barrel shift */
312 assign stage1 = amt[5] ? {is_rot ? oper : {32{pushbits}}, oper[31]} : {oper, carryin};
313 assign stage2 = amt[4] ? {is_rot ? stage1[15:0] : {16{pushbits}}, stage1[31:16], stage1[15]} : stage1;
314 assign stage3 = amt[3] ? {is_rot ? stage2[7:0] : {8{pushbits}}, stage2[31:8], stage2[7]} : stage2;
315 assign stage4 = amt[2] ? {is_rot ? stage3[3:0] : {4{pushbits}}, stage3[31:4], stage3[3]} : stage3;
316 assign stage5 = amt[1] ? {is_rot ? stage4[1:0] : {2{pushbits}}, stage4[31:2], stage4[1]} : stage4;
317 assign {res, carryout} = amt[0] ? {is_rot ? stage5[0] : pushbits, stage5[31:1], stage5[0]} : stage5;