1 `include "ARM_Constants.v"
10 output reg [31:0] op2,
11 output reg [31:0] cps_out,
21 wire [31:0] regs0, regs1, regs2, rpc;
22 wire [31:0] op1_res, new_cps;
25 wire [31:0] shift_oper;
26 wire [31:0] shift_res;
29 assign regs0 = (regsel0 == 4'b1111) ? rpc : iregs0;
30 assign regs1 = (regsel1 == 4'b1111) ? rpc : iregs1;
31 assign regs2 = iregs2; /* use regs2 for things that cannot be r15 */
33 IHATEARMSHIFT blowme(.insn(ansn),
36 .cflag_in(cps_in[`CPSR_C]),
38 .cflag_out(shift_cflag_out));
42 32'b????000000??????????????1001????: begin /* Multiply */
44 regsel0 = ansn[15:12]; /* Rn */
45 regsel1 = ansn[3:0]; /* Rm */
46 regsel2 = ansn[11:8]; /* Rs */
51 32'b????00001???????????????1001????: begin * Multiply long *
52 regsel0 = ansn[11:8]; * Rn *
53 regsel1 = ansn[3:0]; * Rm *
54 regsel2 = 4'b0; * anyus *
58 32'b????00010?001111????000000000000: begin /* MRS (Transfer PSR to register) */
62 32'b????00010?101001111100000000????: begin /* MSR (Transfer register to PSR) */
66 32'b????00?10?1010001111????????????: begin /* MSR (Transfer register or immediate to PSR, flag bits onry) */
70 32'b????00??????????????????????????: begin /* ALU */
71 rpc = inpc - (ansn[25] ? 8 : (ansn[4] ? 12 : 8));
72 regsel0 = ansn[19:16]; /* Rn */
73 regsel1 = ansn[3:0]; /* Rm */
74 regsel2 = ansn[11:8]; /* Rs for shift */
75 if(ansn[25]) begin /* the constant case */
77 op1_res = ({24'b0, ansn[7:0]} >> {ansn[11:8], 1'b0}) | ({24'b0, ansn[7:0]} << (5'b0 - {ansn[11:8], 1'b0}));
79 new_cps = {cps_in[31:30], shift_cflag_out, cps_in[28:0]};
83 32'b????00010?00????????00001001????: begin /* Atomic swap */
85 regsel0 = ansn[19:16]; /* Rn */
86 regsel1 = ansn[3:0]; /* Rm */
87 regsel2 = 4'b0; /* anyus */
90 32'b????000100101111111111110001????: begin /* Branch and exchange */
92 regsel0 = ansn[3:0]; /* Rn */
95 32'b????000??0??????????00001??1????: begin /* Halfword transfer - register offset */
97 regsel0 = ansn[19:16];
103 32'b????000??1??????????00001??1????: begin /* Halfword transfer - immediate offset */
105 regsel0 = ansn[19:16];
107 op1_res = {24'b0, ansn[11:8], ansn[3:0]};
110 32'b????011????????????????????1????: begin /* Undefined. I hate ARM */
113 32'b????01??????????????????????????: begin /* Single data transfer */
115 regsel0 = ansn[19:16]; /* Rn */
116 regsel1 = ansn[3:0]; /* Rm */
118 op1_res = {20'b0, ansn[11:0]};
122 new_cps = {cps_in[31:30], shift_cflag_out, cps_in[28:0]};
125 32'b????100?????????????????????????: begin /* Block data transfer */
127 regsel0 = ansn[19:16];
128 op1_res = {16'b0, ansn[15:0]};
131 32'b????101?????????????????????????: begin /* Branch */
133 op1_res = {{6{ansn[23]}}, ansn[23:0], 2'b0};
136 32'b????110?????????????????????????: begin /* Coprocessor data transfer */
138 regsel0 = ansn[19:16];
139 op1_res = {24'b0, ansn[7:0]};
142 32'b????1110???????????????????0????: begin /* Coprocessor data op */
146 32'b????1110???????????????????1????: begin /* Coprocessor register transfer */
150 32'b????1111????????????????????????: begin /* SWI */
158 always @ (posedge clk) begin
159 op0 <= regs0; /* Rn - always */
160 op1 <= op1_res; /* 'operand 2' - Rm */
161 op2 <= regs2; /* thirdedge - Rs */
167 module IHATEARMSHIFT(
169 input [31:0] operand,
170 input [31:0] reg_amt,
175 wire [5:0] shift_amt;
179 /* might want to write our own damn shifter that does arithmetic/logical efficiently and stuff */
182 shift_amt = {|reg_amt[7:5], reg_amt[4:0]};
185 shift_amt = {insn[11:7] == 5'b0, insn[11:7]};
189 case (insn[6:5]) /* shift type */
191 {cflag_out, res} = {cflag_in, operand} << {elanus & shift_amt[5], shift_amt[4:0]};
194 {res, cflag_out} = {operand, cflag_in} >> shift_amt;
197 {res, cflag_out} = {operand, cflag_in} >> shift_amt | (operand[31] ? ~(33'h1FFFFFFFF >> shift_amt) : 33'b0);
200 if(!elanus && shift_amt[4:0] == 5'b0) begin /* RRX x.x */
201 res = {cflag_in, operand[31:1]};
202 cflag_out = operand[0];
203 end else if(shift_amt == 6'b0) begin
205 cflag_out = cflag_in;
207 res = operand >> shift_amt[4:0] | operand << (5'b0 - shift_amt[4:0]);
208 cflag_out = operand[shift_amt[4:0] - 5'b1];