1 `include "ARM_Constants.v"
10 output reg [31:0] op2,
11 output reg [31:0] outcpsr,
21 wire [31:0] regs0, regs1, regs2, rpc;
22 wire [31:0] op1_res, cpsr;
25 wire [31:0] shift_oper;
26 wire [31:0] shift_res;
29 assign regs0 = (read_0 == 4'b1111) ? rpc : rdata_0;
30 assign regs1 = (read_1 == 4'b1111) ? rpc : rdata_1;
31 assign regs2 = rdata_2; /* use regs2 for things that cannot be r15 */
33 IHATEARMSHIFT blowme(.insn(insn),
36 .cflag_in(incpsr[`CPSR_C]),
38 .cflag_out(shift_cflag_out));
42 32'b????000000??????????????1001????, /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
43 // 32'b????00001???????????????1001????, /* Multiply long */
44 32'b????00010?001111????000000000000, /* MRS (Transfer PSR to register) */
45 32'b????00010?101001111100000000????, /* MSR (Transfer register to PSR) */
46 32'b????00?10?1010001111????????????, /* MSR (Transfer register or immediate to PSR, flag bits only) */
47 32'b????00010?00????????00001001????, /* Atomic swap */
48 32'b????000100101111111111110001????, /* Branch */
49 32'b????000??0??????????00001??1????, /* Halfword transfer - register offset */
50 32'b????000??1??????????00001??1????, /* Halfword transfer - register offset */
51 32'b????011????????????????????1????, /* Undefined. I hate ARM */
52 32'b????01??????????????????????????, /* Single data transfer */
53 32'b????100?????????????????????????, /* Block data transfer */
54 32'b????101?????????????????????????, /* Branch */
55 32'b????110?????????????????????????, /* Coprocessor data transfer */
56 32'b????1110???????????????????0????, /* Coprocessor data op */
57 32'b????1110???????????????????1????, /* Coprocessor register transfer */
58 32'b????1111????????????????????????: /* SWI */
60 32'b????00??????????????????????????: /* ALU */
61 rpc = inpc - (insn[25] ? 8 : (insn[4] ? 12 : 8));
62 default: /* X everything else out */
68 32'b????000000??????????????1001????: begin /* Multiply */
69 read_0 = insn[15:12]; /* Rn */
70 read_1 = insn[3:0]; /* Rm */
71 read_2 = insn[11:8]; /* Rs */
76 32'b????00001???????????????1001????: begin * Multiply long *
77 read_0 = insn[11:8]; * Rn *
78 read_1 = insn[3:0]; * Rm *
79 read_2 = 4'b0; * anyus *
83 32'b????00010?001111????000000000000: begin /* MRS (Transfer PSR to register) */
86 32'b????00010?101001111100000000????: begin /* MSR (Transfer register to PSR) */
89 32'b????00?10?1010001111????????????: begin /* MSR (Transfer register or immediate to PSR, flag bits onry) */
92 32'b????00??????????????????????????: begin /* ALU */
93 read_0 = insn[19:16]; /* Rn */
94 read_1 = insn[3:0]; /* Rm */
95 read_2 = insn[11:8]; /* Rs for shift */
96 if(insn[25]) begin /* the constant case */
98 op1_res = ({24'b0, insn[7:0]} >> {insn[11:8], 1'b0}) | ({24'b0, insn[7:0]} << (5'b0 - {insn[11:8], 1'b0}));
100 cpsr = {incpsr[31:30], shift_cflag_out, incpsr[28:0]};
104 32'b????00010?00????????00001001????: begin /* Atomic swap */
105 read_0 = insn[19:16]; /* Rn */
106 read_1 = insn[3:0]; /* Rm */
107 read_2 = 4'b0; /* anyus */
110 32'b????000100101111111111110001????: begin /* Branch and exchange */
111 read_0 = insn[3:0]; /* Rn */
114 32'b????000??0??????????00001??1????: begin /* Halfword transfer - register offset */
115 read_0 = insn[19:16];
121 32'b????000??1??????????00001??1????: begin /* Halfword transfer - immediate offset */
122 read_0 = insn[19:16];
124 op1_res = {24'b0, insn[11:8], insn[3:0]};
127 32'b????011????????????????????1????: begin /* Undefined. I hate ARM */
130 32'b????01??????????????????????????: begin /* Single data transfer */
131 read_0 = insn[19:16]; /* Rn */
132 read_1 = insn[3:0]; /* Rm */
134 op1_res = {20'b0, insn[11:0]};
138 cpsr = {incpsr[31:30], shift_cflag_out, incpsr[28:0]};
141 32'b????100?????????????????????????: begin /* Block data transfer */
142 read_0 = insn[19:16];
143 op1_res = {16'b0, insn[15:0]};
146 32'b????101?????????????????????????: begin /* Branch */
147 op1_res = {{6{insn[23]}}, insn[23:0], 2'b0};
150 32'b????110?????????????????????????: begin /* Coprocessor data transfer */
151 read_0 = insn[19:16];
152 op1_res = {24'b0, insn[7:0]};
155 32'b????1110???????????????????0????: begin /* Coprocessor data op */
158 32'b????1110???????????????????1????: begin /* Coprocessor register transfer */
161 32'b????1111????????????????????????: begin /* SWI */
168 always @ (posedge clk) begin
169 op0 <= regs0; /* Rn - always */
170 op1 <= op1_res; /* 'operand 2' - Rm */
171 op2 <= regs2; /* thirdedge - Rs */
177 module IHATEARMSHIFT(
179 input [31:0] operand,
180 input [31:0] reg_amt,
185 wire [5:0] shift_amt;
189 /* might want to write our own damn shifter that does arithmetic/logical efficiently and stuff */
192 shift_amt = {|reg_amt[7:5], reg_amt[4:0]};
195 shift_amt = {insn[11:7] == 5'b0, insn[11:7]};
200 case (insn[6:5]) /* shift type */
202 {cflag_out, res} = {cflag_in, operand} << {elanus & shift_amt[5], shift_amt[4:0]};
205 {res, cflag_out} = {operand, cflag_in} >> shift_amt;
208 {res, cflag_out} = {operand, cflag_in} >> shift_amt | (operand[31] ? ~(33'h1FFFFFFFF >> shift_amt) : 33'b0);
211 if(!elanus && shift_amt[4:0] == 5'b0) begin /* RRX x.x */
212 res = {cflag_in, operand[31:1]};
213 cflag_out = operand[0];
214 end else if(shift_amt == 6'b0) begin
216 cflag_out = cflag_in;
218 res = operand >> shift_amt[4:0] | operand << (5'b0 - shift_amt[4:0]);
219 cflag_out = operand[shift_amt[4:0] - 5'b1];